Initial commit
This commit is contained in:
24
node_modules/konva/cmj/Animation.d.ts
generated
vendored
Normal file
24
node_modules/konva/cmj/Animation.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Layer } from './Layer';
|
||||
import { IFrame, AnimationFn } from './types';
|
||||
export declare class Animation {
|
||||
func: AnimationFn;
|
||||
id: number;
|
||||
layers: Layer[];
|
||||
frame: IFrame;
|
||||
constructor(func: AnimationFn, layers?: any);
|
||||
setLayers(layers: any): this;
|
||||
getLayers(): Layer[];
|
||||
addLayer(layer: any): boolean;
|
||||
isRunning(): boolean;
|
||||
start(): this;
|
||||
stop(): this;
|
||||
_updateFrameObject(time: any): void;
|
||||
static animations: any[];
|
||||
static animIdCounter: number;
|
||||
static animRunning: boolean;
|
||||
static _addAnimation(anim: any): void;
|
||||
static _removeAnimation(anim: any): void;
|
||||
static _runFrames(): void;
|
||||
static _animationLoop(): void;
|
||||
static _handleAnimation(): void;
|
||||
}
|
||||
145
node_modules/konva/cmj/Animation.js
generated
vendored
Normal file
145
node_modules/konva/cmj/Animation.js
generated
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Animation = void 0;
|
||||
const Global_1 = require("./Global");
|
||||
const Util_1 = require("./Util");
|
||||
var now = (function () {
|
||||
if (Global_1.glob.performance && Global_1.glob.performance.now) {
|
||||
return function () {
|
||||
return Global_1.glob.performance.now();
|
||||
};
|
||||
}
|
||||
return function () {
|
||||
return new Date().getTime();
|
||||
};
|
||||
})();
|
||||
class Animation {
|
||||
constructor(func, layers) {
|
||||
this.id = Animation.animIdCounter++;
|
||||
this.frame = {
|
||||
time: 0,
|
||||
timeDiff: 0,
|
||||
lastTime: now(),
|
||||
frameRate: 0,
|
||||
};
|
||||
this.func = func;
|
||||
this.setLayers(layers);
|
||||
}
|
||||
setLayers(layers) {
|
||||
var lays = [];
|
||||
if (!layers) {
|
||||
lays = [];
|
||||
}
|
||||
else if (layers.length > 0) {
|
||||
lays = layers;
|
||||
}
|
||||
else {
|
||||
lays = [layers];
|
||||
}
|
||||
this.layers = lays;
|
||||
return this;
|
||||
}
|
||||
getLayers() {
|
||||
return this.layers;
|
||||
}
|
||||
addLayer(layer) {
|
||||
var layers = this.layers, len = layers.length, n;
|
||||
for (n = 0; n < len; n++) {
|
||||
if (layers[n]._id === layer._id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.layers.push(layer);
|
||||
return true;
|
||||
}
|
||||
isRunning() {
|
||||
var a = Animation, animations = a.animations, len = animations.length, n;
|
||||
for (n = 0; n < len; n++) {
|
||||
if (animations[n].id === this.id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
start() {
|
||||
this.stop();
|
||||
this.frame.timeDiff = 0;
|
||||
this.frame.lastTime = now();
|
||||
Animation._addAnimation(this);
|
||||
return this;
|
||||
}
|
||||
stop() {
|
||||
Animation._removeAnimation(this);
|
||||
return this;
|
||||
}
|
||||
_updateFrameObject(time) {
|
||||
this.frame.timeDiff = time - this.frame.lastTime;
|
||||
this.frame.lastTime = time;
|
||||
this.frame.time += this.frame.timeDiff;
|
||||
this.frame.frameRate = 1000 / this.frame.timeDiff;
|
||||
}
|
||||
static _addAnimation(anim) {
|
||||
this.animations.push(anim);
|
||||
this._handleAnimation();
|
||||
}
|
||||
static _removeAnimation(anim) {
|
||||
var id = anim.id, animations = this.animations, len = animations.length, n;
|
||||
for (n = 0; n < len; n++) {
|
||||
if (animations[n].id === id) {
|
||||
this.animations.splice(n, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
static _runFrames() {
|
||||
var layerHash = {}, animations = this.animations, anim, layers, func, n, i, layersLen, layer, key, needRedraw;
|
||||
for (n = 0; n < animations.length; n++) {
|
||||
anim = animations[n];
|
||||
layers = anim.layers;
|
||||
func = anim.func;
|
||||
anim._updateFrameObject(now());
|
||||
layersLen = layers.length;
|
||||
if (func) {
|
||||
needRedraw = func.call(anim, anim.frame) !== false;
|
||||
}
|
||||
else {
|
||||
needRedraw = true;
|
||||
}
|
||||
if (!needRedraw) {
|
||||
continue;
|
||||
}
|
||||
for (i = 0; i < layersLen; i++) {
|
||||
layer = layers[i];
|
||||
if (layer._id !== undefined) {
|
||||
layerHash[layer._id] = layer;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (key in layerHash) {
|
||||
if (!layerHash.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
layerHash[key].batchDraw();
|
||||
}
|
||||
}
|
||||
static _animationLoop() {
|
||||
var Anim = Animation;
|
||||
if (Anim.animations.length) {
|
||||
Anim._runFrames();
|
||||
Util_1.Util.requestAnimFrame(Anim._animationLoop);
|
||||
}
|
||||
else {
|
||||
Anim.animRunning = false;
|
||||
}
|
||||
}
|
||||
static _handleAnimation() {
|
||||
if (!this.animRunning) {
|
||||
this.animRunning = true;
|
||||
Util_1.Util.requestAnimFrame(this._animationLoop);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Animation = Animation;
|
||||
Animation.animations = [];
|
||||
Animation.animIdCounter = 0;
|
||||
Animation.animRunning = false;
|
||||
32
node_modules/konva/cmj/Canvas.d.ts
generated
vendored
Normal file
32
node_modules/konva/cmj/Canvas.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Context } from './Context';
|
||||
interface ICanvasConfig {
|
||||
width?: number;
|
||||
height?: number;
|
||||
pixelRatio?: number;
|
||||
}
|
||||
export declare class Canvas {
|
||||
pixelRatio: number;
|
||||
_canvas: HTMLCanvasElement;
|
||||
context: Context;
|
||||
width: number;
|
||||
height: number;
|
||||
isCache: boolean;
|
||||
constructor(config: ICanvasConfig);
|
||||
getContext(): Context;
|
||||
getPixelRatio(): number;
|
||||
setPixelRatio(pixelRatio: any): void;
|
||||
setWidth(width: any): void;
|
||||
setHeight(height: any): void;
|
||||
getWidth(): number;
|
||||
getHeight(): number;
|
||||
setSize(width: any, height: any): void;
|
||||
toDataURL(mimeType: any, quality: any): string;
|
||||
}
|
||||
export declare class SceneCanvas extends Canvas {
|
||||
constructor(config?: ICanvasConfig);
|
||||
}
|
||||
export declare class HitCanvas extends Canvas {
|
||||
hitCanvas: boolean;
|
||||
constructor(config?: ICanvasConfig);
|
||||
}
|
||||
export {};
|
||||
113
node_modules/konva/cmj/Canvas.js
generated
vendored
Normal file
113
node_modules/konva/cmj/Canvas.js
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HitCanvas = exports.SceneCanvas = exports.Canvas = void 0;
|
||||
const Util_1 = require("./Util");
|
||||
const Context_1 = require("./Context");
|
||||
const Global_1 = require("./Global");
|
||||
const Factory_1 = require("./Factory");
|
||||
const Validators_1 = require("./Validators");
|
||||
var _pixelRatio;
|
||||
function getDevicePixelRatio() {
|
||||
if (_pixelRatio) {
|
||||
return _pixelRatio;
|
||||
}
|
||||
var canvas = Util_1.Util.createCanvasElement();
|
||||
var context = canvas.getContext('2d');
|
||||
_pixelRatio = (function () {
|
||||
var devicePixelRatio = Global_1.Konva._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
|
||||
context.mozBackingStorePixelRatio ||
|
||||
context.msBackingStorePixelRatio ||
|
||||
context.oBackingStorePixelRatio ||
|
||||
context.backingStorePixelRatio ||
|
||||
1;
|
||||
return devicePixelRatio / backingStoreRatio;
|
||||
})();
|
||||
return _pixelRatio;
|
||||
}
|
||||
class Canvas {
|
||||
constructor(config) {
|
||||
this.pixelRatio = 1;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.isCache = false;
|
||||
var conf = config || {};
|
||||
var pixelRatio = conf.pixelRatio || Global_1.Konva.pixelRatio || getDevicePixelRatio();
|
||||
this.pixelRatio = pixelRatio;
|
||||
this._canvas = Util_1.Util.createCanvasElement();
|
||||
this._canvas.style.padding = '0';
|
||||
this._canvas.style.margin = '0';
|
||||
this._canvas.style.border = '0';
|
||||
this._canvas.style.background = 'transparent';
|
||||
this._canvas.style.position = 'absolute';
|
||||
this._canvas.style.top = '0';
|
||||
this._canvas.style.left = '0';
|
||||
}
|
||||
getContext() {
|
||||
return this.context;
|
||||
}
|
||||
getPixelRatio() {
|
||||
return this.pixelRatio;
|
||||
}
|
||||
setPixelRatio(pixelRatio) {
|
||||
var previousRatio = this.pixelRatio;
|
||||
this.pixelRatio = pixelRatio;
|
||||
this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio);
|
||||
}
|
||||
setWidth(width) {
|
||||
this.width = this._canvas.width = width * this.pixelRatio;
|
||||
this._canvas.style.width = width + 'px';
|
||||
var pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
||||
_context.scale(pixelRatio, pixelRatio);
|
||||
}
|
||||
setHeight(height) {
|
||||
this.height = this._canvas.height = height * this.pixelRatio;
|
||||
this._canvas.style.height = height + 'px';
|
||||
var pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
||||
_context.scale(pixelRatio, pixelRatio);
|
||||
}
|
||||
getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
setSize(width, height) {
|
||||
this.setWidth(width || 0);
|
||||
this.setHeight(height || 0);
|
||||
}
|
||||
toDataURL(mimeType, quality) {
|
||||
try {
|
||||
return this._canvas.toDataURL(mimeType, quality);
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
return this._canvas.toDataURL();
|
||||
}
|
||||
catch (err) {
|
||||
Util_1.Util.error('Unable to get data URL. ' +
|
||||
err.message +
|
||||
' For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html.');
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Canvas = Canvas;
|
||||
Factory_1.Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, (0, Validators_1.getNumberValidator)());
|
||||
class SceneCanvas extends Canvas {
|
||||
constructor(config = { width: 0, height: 0 }) {
|
||||
super(config);
|
||||
this.context = new Context_1.SceneContext(this);
|
||||
this.setSize(config.width, config.height);
|
||||
}
|
||||
}
|
||||
exports.SceneCanvas = SceneCanvas;
|
||||
class HitCanvas extends Canvas {
|
||||
constructor(config = { width: 0, height: 0 }) {
|
||||
super(config);
|
||||
this.hitCanvas = true;
|
||||
this.context = new Context_1.HitContext(this);
|
||||
this.setSize(config.width, config.height);
|
||||
}
|
||||
}
|
||||
exports.HitCanvas = HitCanvas;
|
||||
47
node_modules/konva/cmj/Container.d.ts
generated
vendored
Normal file
47
node_modules/konva/cmj/Container.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Node, NodeConfig } from './Node';
|
||||
import { GetSet, IRect } from './types';
|
||||
import { HitCanvas, SceneCanvas } from './Canvas';
|
||||
import { SceneContext } from './Context';
|
||||
export interface ContainerConfig extends NodeConfig {
|
||||
clearBeforeDraw?: boolean;
|
||||
clipFunc?: (ctx: SceneContext) => void;
|
||||
clipX?: number;
|
||||
clipY?: number;
|
||||
clipWidth?: number;
|
||||
clipHeight?: number;
|
||||
}
|
||||
export declare abstract class Container<ChildType extends Node = Node> extends Node<ContainerConfig> {
|
||||
children: Array<ChildType> | undefined;
|
||||
getChildren(filterFunc?: (item: Node) => boolean): ChildType[];
|
||||
hasChildren(): boolean;
|
||||
removeChildren(): this;
|
||||
destroyChildren(): this;
|
||||
abstract _validateAdd(node: Node): void;
|
||||
add(...children: ChildType[]): this;
|
||||
destroy(): this;
|
||||
find<ChildNode extends Node = Node>(selector: any): Array<ChildNode>;
|
||||
findOne<ChildNode extends Node = Node>(selector: string | Function): ChildNode;
|
||||
_generalFind<ChildNode extends Node = Node>(selector: string | Function, findOne: boolean): ChildNode[];
|
||||
private _descendants;
|
||||
toObject(): any;
|
||||
isAncestorOf(node: Node): boolean;
|
||||
clone(obj?: any): this;
|
||||
getAllIntersections(pos: any): any[];
|
||||
_clearSelfAndDescendantCache(attr?: string): void;
|
||||
_setChildrenIndices(): void;
|
||||
drawScene(can?: SceneCanvas, top?: Node): this;
|
||||
drawHit(can?: HitCanvas, top?: Node): this;
|
||||
_drawChildren(drawMethod: any, canvas: any, top: any): void;
|
||||
getClientRect(config?: {
|
||||
skipTransform?: boolean;
|
||||
skipShadow?: boolean;
|
||||
skipStroke?: boolean;
|
||||
relativeTo?: Container<Node>;
|
||||
}): IRect;
|
||||
clip: GetSet<IRect, this>;
|
||||
clipX: GetSet<number, this>;
|
||||
clipY: GetSet<number, this>;
|
||||
clipWidth: GetSet<number, this>;
|
||||
clipHeight: GetSet<number, this>;
|
||||
clipFunc: GetSet<(ctx: CanvasRenderingContext2D, shape: Container<ChildType>) => void, this>;
|
||||
}
|
||||
322
node_modules/konva/cmj/Container.js
generated
vendored
Normal file
322
node_modules/konva/cmj/Container.js
generated
vendored
Normal file
@@ -0,0 +1,322 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Container = void 0;
|
||||
const Factory_1 = require("./Factory");
|
||||
const Node_1 = require("./Node");
|
||||
const Validators_1 = require("./Validators");
|
||||
class Container extends Node_1.Node {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.children = [];
|
||||
}
|
||||
getChildren(filterFunc) {
|
||||
if (!filterFunc) {
|
||||
return this.children || [];
|
||||
}
|
||||
const children = this.children || [];
|
||||
var results = [];
|
||||
children.forEach(function (child) {
|
||||
if (filterFunc(child)) {
|
||||
results.push(child);
|
||||
}
|
||||
});
|
||||
return results;
|
||||
}
|
||||
hasChildren() {
|
||||
return this.getChildren().length > 0;
|
||||
}
|
||||
removeChildren() {
|
||||
this.getChildren().forEach((child) => {
|
||||
child.parent = null;
|
||||
child.index = 0;
|
||||
child.remove();
|
||||
});
|
||||
this.children = [];
|
||||
this._requestDraw();
|
||||
return this;
|
||||
}
|
||||
destroyChildren() {
|
||||
this.getChildren().forEach((child) => {
|
||||
child.parent = null;
|
||||
child.index = 0;
|
||||
child.destroy();
|
||||
});
|
||||
this.children = [];
|
||||
this._requestDraw();
|
||||
return this;
|
||||
}
|
||||
add(...children) {
|
||||
if (arguments.length > 1) {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
this.add(arguments[i]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
var child = children[0];
|
||||
if (child.getParent()) {
|
||||
child.moveTo(this);
|
||||
return this;
|
||||
}
|
||||
this._validateAdd(child);
|
||||
child.index = this.getChildren().length;
|
||||
child.parent = this;
|
||||
child._clearCaches();
|
||||
this.getChildren().push(child);
|
||||
this._fire('add', {
|
||||
child: child,
|
||||
});
|
||||
this._requestDraw();
|
||||
return this;
|
||||
}
|
||||
destroy() {
|
||||
if (this.hasChildren()) {
|
||||
this.destroyChildren();
|
||||
}
|
||||
super.destroy();
|
||||
return this;
|
||||
}
|
||||
find(selector) {
|
||||
return this._generalFind(selector, false);
|
||||
}
|
||||
findOne(selector) {
|
||||
var result = this._generalFind(selector, true);
|
||||
return result.length > 0 ? result[0] : undefined;
|
||||
}
|
||||
_generalFind(selector, findOne) {
|
||||
var retArr = [];
|
||||
this._descendants((node) => {
|
||||
const valid = node._isMatch(selector);
|
||||
if (valid) {
|
||||
retArr.push(node);
|
||||
}
|
||||
if (valid && findOne) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return retArr;
|
||||
}
|
||||
_descendants(fn) {
|
||||
let shouldStop = false;
|
||||
const children = this.getChildren();
|
||||
for (const child of children) {
|
||||
shouldStop = fn(child);
|
||||
if (shouldStop) {
|
||||
return true;
|
||||
}
|
||||
if (!child.hasChildren()) {
|
||||
continue;
|
||||
}
|
||||
shouldStop = child._descendants(fn);
|
||||
if (shouldStop) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
toObject() {
|
||||
var obj = Node_1.Node.prototype.toObject.call(this);
|
||||
obj.children = [];
|
||||
this.getChildren().forEach((child) => {
|
||||
obj.children.push(child.toObject());
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
isAncestorOf(node) {
|
||||
var parent = node.getParent();
|
||||
while (parent) {
|
||||
if (parent._id === this._id) {
|
||||
return true;
|
||||
}
|
||||
parent = parent.getParent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
clone(obj) {
|
||||
var node = Node_1.Node.prototype.clone.call(this, obj);
|
||||
this.getChildren().forEach(function (no) {
|
||||
node.add(no.clone());
|
||||
});
|
||||
return node;
|
||||
}
|
||||
getAllIntersections(pos) {
|
||||
var arr = [];
|
||||
this.find('Shape').forEach(function (shape) {
|
||||
if (shape.isVisible() && shape.intersects(pos)) {
|
||||
arr.push(shape);
|
||||
}
|
||||
});
|
||||
return arr;
|
||||
}
|
||||
_clearSelfAndDescendantCache(attr) {
|
||||
var _a;
|
||||
super._clearSelfAndDescendantCache(attr);
|
||||
if (this.isCached()) {
|
||||
return;
|
||||
}
|
||||
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
|
||||
node._clearSelfAndDescendantCache(attr);
|
||||
});
|
||||
}
|
||||
_setChildrenIndices() {
|
||||
var _a;
|
||||
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child, n) {
|
||||
child.index = n;
|
||||
});
|
||||
this._requestDraw();
|
||||
}
|
||||
drawScene(can, top) {
|
||||
var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
|
||||
var caching = canvas && canvas.isCache;
|
||||
if (!this.isVisible() && !caching) {
|
||||
return this;
|
||||
}
|
||||
if (cachedSceneCanvas) {
|
||||
context.save();
|
||||
var m = this.getAbsoluteTransform(top).getMatrix();
|
||||
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
this._drawCachedSceneCanvas(context);
|
||||
context.restore();
|
||||
}
|
||||
else {
|
||||
this._drawChildren('drawScene', canvas, top);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
drawHit(can, top) {
|
||||
if (!this.shouldDrawHit(top)) {
|
||||
return this;
|
||||
}
|
||||
var layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
||||
if (cachedHitCanvas) {
|
||||
context.save();
|
||||
var m = this.getAbsoluteTransform(top).getMatrix();
|
||||
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
this._drawCachedHitCanvas(context);
|
||||
context.restore();
|
||||
}
|
||||
else {
|
||||
this._drawChildren('drawHit', canvas, top);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
_drawChildren(drawMethod, canvas, top) {
|
||||
var _a;
|
||||
var context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (clipWidth && clipHeight) || clipFunc;
|
||||
const selfCache = top === this;
|
||||
if (hasClip) {
|
||||
context.save();
|
||||
var transform = this.getAbsoluteTransform(top);
|
||||
var m = transform.getMatrix();
|
||||
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
context.beginPath();
|
||||
if (clipFunc) {
|
||||
clipFunc.call(this, context, this);
|
||||
}
|
||||
else {
|
||||
var clipX = this.clipX();
|
||||
var clipY = this.clipY();
|
||||
context.rect(clipX, clipY, clipWidth, clipHeight);
|
||||
}
|
||||
context.clip();
|
||||
m = transform.copy().invert().getMatrix();
|
||||
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
}
|
||||
var hasComposition = !selfCache &&
|
||||
this.globalCompositeOperation() !== 'source-over' &&
|
||||
drawMethod === 'drawScene';
|
||||
if (hasComposition) {
|
||||
context.save();
|
||||
context._applyGlobalCompositeOperation(this);
|
||||
}
|
||||
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
|
||||
child[drawMethod](canvas, top);
|
||||
});
|
||||
if (hasComposition) {
|
||||
context.restore();
|
||||
}
|
||||
if (hasClip) {
|
||||
context.restore();
|
||||
}
|
||||
}
|
||||
getClientRect(config) {
|
||||
var _a;
|
||||
config = config || {};
|
||||
var skipTransform = config.skipTransform;
|
||||
var relativeTo = config.relativeTo;
|
||||
var minX, minY, maxX, maxY;
|
||||
var selfRect = {
|
||||
x: Infinity,
|
||||
y: Infinity,
|
||||
width: 0,
|
||||
height: 0,
|
||||
};
|
||||
var that = this;
|
||||
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
|
||||
if (!child.visible()) {
|
||||
return;
|
||||
}
|
||||
var rect = child.getClientRect({
|
||||
relativeTo: that,
|
||||
skipShadow: config.skipShadow,
|
||||
skipStroke: config.skipStroke,
|
||||
});
|
||||
if (rect.width === 0 && rect.height === 0) {
|
||||
return;
|
||||
}
|
||||
if (minX === undefined) {
|
||||
minX = rect.x;
|
||||
minY = rect.y;
|
||||
maxX = rect.x + rect.width;
|
||||
maxY = rect.y + rect.height;
|
||||
}
|
||||
else {
|
||||
minX = Math.min(minX, rect.x);
|
||||
minY = Math.min(minY, rect.y);
|
||||
maxX = Math.max(maxX, rect.x + rect.width);
|
||||
maxY = Math.max(maxY, rect.y + rect.height);
|
||||
}
|
||||
});
|
||||
var shapes = this.find('Shape');
|
||||
var hasVisible = false;
|
||||
for (var i = 0; i < shapes.length; i++) {
|
||||
var shape = shapes[i];
|
||||
if (shape._isVisible(this)) {
|
||||
hasVisible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasVisible && minX !== undefined) {
|
||||
selfRect = {
|
||||
x: minX,
|
||||
y: minY,
|
||||
width: maxX - minX,
|
||||
height: maxY - minY,
|
||||
};
|
||||
}
|
||||
else {
|
||||
selfRect = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
};
|
||||
}
|
||||
if (!skipTransform) {
|
||||
return this._transformedRect(selfRect, relativeTo);
|
||||
}
|
||||
return selfRect;
|
||||
}
|
||||
}
|
||||
exports.Container = Container;
|
||||
Factory_1.Factory.addComponentsGetterSetter(Container, 'clip', [
|
||||
'x',
|
||||
'y',
|
||||
'width',
|
||||
'height',
|
||||
]);
|
||||
Factory_1.Factory.addGetterSetter(Container, 'clipX', undefined, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Container, 'clipY', undefined, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Container, 'clipWidth', undefined, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Container, 'clipHeight', undefined, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Container, 'clipFunc');
|
||||
76
node_modules/konva/cmj/Context.d.ts
generated
vendored
Normal file
76
node_modules/konva/cmj/Context.d.ts
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import { Canvas } from './Canvas';
|
||||
import { Shape } from './Shape';
|
||||
export declare class Context {
|
||||
canvas: Canvas;
|
||||
_context: CanvasRenderingContext2D;
|
||||
traceArr: Array<String>;
|
||||
constructor(canvas: Canvas);
|
||||
fillShape(shape: Shape): void;
|
||||
_fill(shape: any): void;
|
||||
strokeShape(shape: Shape): void;
|
||||
_stroke(shape: any): void;
|
||||
fillStrokeShape(shape: Shape): void;
|
||||
getTrace(relaxed?: any, rounded?: any): string;
|
||||
clearTrace(): void;
|
||||
_trace(str: any): void;
|
||||
reset(): void;
|
||||
getCanvas(): Canvas;
|
||||
clear(bounds?: any): void;
|
||||
_applyLineCap(shape: any): void;
|
||||
_applyOpacity(shape: any): void;
|
||||
_applyLineJoin(shape: Shape): void;
|
||||
setAttr(attr: any, val: any): void;
|
||||
arc(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
|
||||
arcTo(a0: any, a1: any, a2: any, a3: any, a4: any): void;
|
||||
beginPath(): void;
|
||||
bezierCurveTo(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
|
||||
clearRect(a0: any, a1: any, a2: any, a3: any): void;
|
||||
clip(): void;
|
||||
closePath(): void;
|
||||
createImageData(a0: any, a1: any): ImageData;
|
||||
createLinearGradient(a0: any, a1: any, a2: any, a3: any): CanvasGradient;
|
||||
createPattern(a0: any, a1: any): CanvasPattern;
|
||||
createRadialGradient(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): CanvasGradient;
|
||||
drawImage(a0: CanvasImageSource, a1: number, a2: number, a3?: number, a4?: number, a5?: number, a6?: number, a7?: number, a8?: number): void;
|
||||
ellipse(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, a7?: boolean): void;
|
||||
isPointInPath(x: any, y: any): boolean;
|
||||
fill(path2d?: Path2D): void;
|
||||
fillRect(x: any, y: any, width: any, height: any): void;
|
||||
strokeRect(x: any, y: any, width: any, height: any): void;
|
||||
fillText(text: string, x: number, y: number, maxWidth?: number): void;
|
||||
measureText(text: any): TextMetrics;
|
||||
getImageData(a0: any, a1: any, a2: any, a3: any): ImageData;
|
||||
lineTo(a0: any, a1: any): void;
|
||||
moveTo(a0: any, a1: any): void;
|
||||
rect(a0: any, a1: any, a2: any, a3: any): void;
|
||||
putImageData(a0: any, a1: any, a2: any): void;
|
||||
quadraticCurveTo(a0: any, a1: any, a2: any, a3: any): void;
|
||||
restore(): void;
|
||||
rotate(a0: any): void;
|
||||
save(): void;
|
||||
scale(a0: any, a1: any): void;
|
||||
setLineDash(a0: any): void;
|
||||
getLineDash(): number[];
|
||||
setTransform(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
|
||||
stroke(path2d?: Path2D): void;
|
||||
strokeText(a0: any, a1: any, a2: any, a3: any): void;
|
||||
transform(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
|
||||
translate(a0: any, a1: any): void;
|
||||
_enableTrace(): void;
|
||||
_applyGlobalCompositeOperation(node: any): void;
|
||||
}
|
||||
export declare class SceneContext extends Context {
|
||||
_fillColor(shape: Shape): void;
|
||||
_fillPattern(shape: any): void;
|
||||
_fillLinearGradient(shape: any): void;
|
||||
_fillRadialGradient(shape: any): void;
|
||||
_fill(shape: any): void;
|
||||
_strokeLinearGradient(shape: any): void;
|
||||
_stroke(shape: any): void;
|
||||
_applyShadow(shape: any): void;
|
||||
}
|
||||
export declare class HitContext extends Context {
|
||||
_fill(shape: any): void;
|
||||
strokeShape(shape: Shape): void;
|
||||
_stroke(shape: any): void;
|
||||
}
|
||||
526
node_modules/konva/cmj/Context.js
generated
vendored
Normal file
526
node_modules/konva/cmj/Context.js
generated
vendored
Normal file
@@ -0,0 +1,526 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HitContext = exports.SceneContext = exports.Context = void 0;
|
||||
const Util_1 = require("./Util");
|
||||
const Global_1 = require("./Global");
|
||||
function simplifyArray(arr) {
|
||||
var retArr = [], len = arr.length, util = Util_1.Util, n, val;
|
||||
for (n = 0; n < len; n++) {
|
||||
val = arr[n];
|
||||
if (util._isNumber(val)) {
|
||||
val = Math.round(val * 1000) / 1000;
|
||||
}
|
||||
else if (!util._isString(val)) {
|
||||
val = val + '';
|
||||
}
|
||||
retArr.push(val);
|
||||
}
|
||||
return retArr;
|
||||
}
|
||||
var COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([', CLOSE_BRACKET_PAREN = '])', SEMICOLON = ';', DOUBLE_PAREN = '()', EQUALS = '=', CONTEXT_METHODS = [
|
||||
'arc',
|
||||
'arcTo',
|
||||
'beginPath',
|
||||
'bezierCurveTo',
|
||||
'clearRect',
|
||||
'clip',
|
||||
'closePath',
|
||||
'createLinearGradient',
|
||||
'createPattern',
|
||||
'createRadialGradient',
|
||||
'drawImage',
|
||||
'ellipse',
|
||||
'fill',
|
||||
'fillText',
|
||||
'getImageData',
|
||||
'createImageData',
|
||||
'lineTo',
|
||||
'moveTo',
|
||||
'putImageData',
|
||||
'quadraticCurveTo',
|
||||
'rect',
|
||||
'restore',
|
||||
'rotate',
|
||||
'save',
|
||||
'scale',
|
||||
'setLineDash',
|
||||
'setTransform',
|
||||
'stroke',
|
||||
'strokeText',
|
||||
'transform',
|
||||
'translate',
|
||||
];
|
||||
var CONTEXT_PROPERTIES = [
|
||||
'fillStyle',
|
||||
'strokeStyle',
|
||||
'shadowColor',
|
||||
'shadowBlur',
|
||||
'shadowOffsetX',
|
||||
'shadowOffsetY',
|
||||
'lineCap',
|
||||
'lineDashOffset',
|
||||
'lineJoin',
|
||||
'lineWidth',
|
||||
'miterLimit',
|
||||
'font',
|
||||
'textAlign',
|
||||
'textBaseline',
|
||||
'globalAlpha',
|
||||
'globalCompositeOperation',
|
||||
'imageSmoothingEnabled',
|
||||
];
|
||||
const traceArrMax = 100;
|
||||
class Context {
|
||||
constructor(canvas) {
|
||||
this.canvas = canvas;
|
||||
this._context = canvas._canvas.getContext('2d');
|
||||
if (Global_1.Konva.enableTrace) {
|
||||
this.traceArr = [];
|
||||
this._enableTrace();
|
||||
}
|
||||
}
|
||||
fillShape(shape) {
|
||||
if (shape.fillEnabled()) {
|
||||
this._fill(shape);
|
||||
}
|
||||
}
|
||||
_fill(shape) {
|
||||
}
|
||||
strokeShape(shape) {
|
||||
if (shape.hasStroke()) {
|
||||
this._stroke(shape);
|
||||
}
|
||||
}
|
||||
_stroke(shape) {
|
||||
}
|
||||
fillStrokeShape(shape) {
|
||||
if (shape.attrs.fillAfterStrokeEnabled) {
|
||||
this.strokeShape(shape);
|
||||
this.fillShape(shape);
|
||||
}
|
||||
else {
|
||||
this.fillShape(shape);
|
||||
this.strokeShape(shape);
|
||||
}
|
||||
}
|
||||
getTrace(relaxed, rounded) {
|
||||
var traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args;
|
||||
for (n = 0; n < len; n++) {
|
||||
trace = traceArr[n];
|
||||
method = trace.method;
|
||||
if (method) {
|
||||
args = trace.args;
|
||||
str += method;
|
||||
if (relaxed) {
|
||||
str += DOUBLE_PAREN;
|
||||
}
|
||||
else {
|
||||
if (Util_1.Util._isArray(args[0])) {
|
||||
str += OPEN_PAREN_BRACKET + args.join(COMMA) + CLOSE_BRACKET_PAREN;
|
||||
}
|
||||
else {
|
||||
if (rounded) {
|
||||
args = args.map((a) => typeof a === 'number' ? Math.floor(a) : a);
|
||||
}
|
||||
str += OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
str += trace.property;
|
||||
if (!relaxed) {
|
||||
str += EQUALS + trace.val;
|
||||
}
|
||||
}
|
||||
str += SEMICOLON;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
clearTrace() {
|
||||
this.traceArr = [];
|
||||
}
|
||||
_trace(str) {
|
||||
var traceArr = this.traceArr, len;
|
||||
traceArr.push(str);
|
||||
len = traceArr.length;
|
||||
if (len >= traceArrMax) {
|
||||
traceArr.shift();
|
||||
}
|
||||
}
|
||||
reset() {
|
||||
var pixelRatio = this.getCanvas().getPixelRatio();
|
||||
this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0);
|
||||
}
|
||||
getCanvas() {
|
||||
return this.canvas;
|
||||
}
|
||||
clear(bounds) {
|
||||
var canvas = this.getCanvas();
|
||||
if (bounds) {
|
||||
this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0);
|
||||
}
|
||||
else {
|
||||
this.clearRect(0, 0, canvas.getWidth() / canvas.pixelRatio, canvas.getHeight() / canvas.pixelRatio);
|
||||
}
|
||||
}
|
||||
_applyLineCap(shape) {
|
||||
var lineCap = shape.getLineCap();
|
||||
if (lineCap) {
|
||||
this.setAttr('lineCap', lineCap);
|
||||
}
|
||||
}
|
||||
_applyOpacity(shape) {
|
||||
var absOpacity = shape.getAbsoluteOpacity();
|
||||
if (absOpacity !== 1) {
|
||||
this.setAttr('globalAlpha', absOpacity);
|
||||
}
|
||||
}
|
||||
_applyLineJoin(shape) {
|
||||
var lineJoin = shape.attrs.lineJoin;
|
||||
if (lineJoin) {
|
||||
this.setAttr('lineJoin', lineJoin);
|
||||
}
|
||||
}
|
||||
setAttr(attr, val) {
|
||||
this._context[attr] = val;
|
||||
}
|
||||
arc(a0, a1, a2, a3, a4, a5) {
|
||||
this._context.arc(a0, a1, a2, a3, a4, a5);
|
||||
}
|
||||
arcTo(a0, a1, a2, a3, a4) {
|
||||
this._context.arcTo(a0, a1, a2, a3, a4);
|
||||
}
|
||||
beginPath() {
|
||||
this._context.beginPath();
|
||||
}
|
||||
bezierCurveTo(a0, a1, a2, a3, a4, a5) {
|
||||
this._context.bezierCurveTo(a0, a1, a2, a3, a4, a5);
|
||||
}
|
||||
clearRect(a0, a1, a2, a3) {
|
||||
this._context.clearRect(a0, a1, a2, a3);
|
||||
}
|
||||
clip() {
|
||||
this._context.clip();
|
||||
}
|
||||
closePath() {
|
||||
this._context.closePath();
|
||||
}
|
||||
createImageData(a0, a1) {
|
||||
var a = arguments;
|
||||
if (a.length === 2) {
|
||||
return this._context.createImageData(a0, a1);
|
||||
}
|
||||
else if (a.length === 1) {
|
||||
return this._context.createImageData(a0);
|
||||
}
|
||||
}
|
||||
createLinearGradient(a0, a1, a2, a3) {
|
||||
return this._context.createLinearGradient(a0, a1, a2, a3);
|
||||
}
|
||||
createPattern(a0, a1) {
|
||||
return this._context.createPattern(a0, a1);
|
||||
}
|
||||
createRadialGradient(a0, a1, a2, a3, a4, a5) {
|
||||
return this._context.createRadialGradient(a0, a1, a2, a3, a4, a5);
|
||||
}
|
||||
drawImage(a0, a1, a2, a3, a4, a5, a6, a7, a8) {
|
||||
var a = arguments, _context = this._context;
|
||||
if (a.length === 3) {
|
||||
_context.drawImage(a0, a1, a2);
|
||||
}
|
||||
else if (a.length === 5) {
|
||||
_context.drawImage(a0, a1, a2, a3, a4);
|
||||
}
|
||||
else if (a.length === 9) {
|
||||
_context.drawImage(a0, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
}
|
||||
}
|
||||
ellipse(a0, a1, a2, a3, a4, a5, a6, a7) {
|
||||
this._context.ellipse(a0, a1, a2, a3, a4, a5, a6, a7);
|
||||
}
|
||||
isPointInPath(x, y) {
|
||||
return this._context.isPointInPath(x, y);
|
||||
}
|
||||
fill(path2d) {
|
||||
if (path2d) {
|
||||
this._context.fill(path2d);
|
||||
}
|
||||
else {
|
||||
this._context.fill();
|
||||
}
|
||||
}
|
||||
fillRect(x, y, width, height) {
|
||||
this._context.fillRect(x, y, width, height);
|
||||
}
|
||||
strokeRect(x, y, width, height) {
|
||||
this._context.strokeRect(x, y, width, height);
|
||||
}
|
||||
fillText(text, x, y, maxWidth) {
|
||||
if (maxWidth) {
|
||||
this._context.fillText(text, x, y, maxWidth);
|
||||
}
|
||||
else {
|
||||
this._context.fillText(text, x, y);
|
||||
}
|
||||
}
|
||||
measureText(text) {
|
||||
return this._context.measureText(text);
|
||||
}
|
||||
getImageData(a0, a1, a2, a3) {
|
||||
return this._context.getImageData(a0, a1, a2, a3);
|
||||
}
|
||||
lineTo(a0, a1) {
|
||||
this._context.lineTo(a0, a1);
|
||||
}
|
||||
moveTo(a0, a1) {
|
||||
this._context.moveTo(a0, a1);
|
||||
}
|
||||
rect(a0, a1, a2, a3) {
|
||||
this._context.rect(a0, a1, a2, a3);
|
||||
}
|
||||
putImageData(a0, a1, a2) {
|
||||
this._context.putImageData(a0, a1, a2);
|
||||
}
|
||||
quadraticCurveTo(a0, a1, a2, a3) {
|
||||
this._context.quadraticCurveTo(a0, a1, a2, a3);
|
||||
}
|
||||
restore() {
|
||||
this._context.restore();
|
||||
}
|
||||
rotate(a0) {
|
||||
this._context.rotate(a0);
|
||||
}
|
||||
save() {
|
||||
this._context.save();
|
||||
}
|
||||
scale(a0, a1) {
|
||||
this._context.scale(a0, a1);
|
||||
}
|
||||
setLineDash(a0) {
|
||||
if (this._context.setLineDash) {
|
||||
this._context.setLineDash(a0);
|
||||
}
|
||||
else if ('mozDash' in this._context) {
|
||||
this._context['mozDash'] = a0;
|
||||
}
|
||||
else if ('webkitLineDash' in this._context) {
|
||||
this._context['webkitLineDash'] = a0;
|
||||
}
|
||||
}
|
||||
getLineDash() {
|
||||
return this._context.getLineDash();
|
||||
}
|
||||
setTransform(a0, a1, a2, a3, a4, a5) {
|
||||
this._context.setTransform(a0, a1, a2, a3, a4, a5);
|
||||
}
|
||||
stroke(path2d) {
|
||||
if (path2d) {
|
||||
this._context.stroke(path2d);
|
||||
}
|
||||
else {
|
||||
this._context.stroke();
|
||||
}
|
||||
}
|
||||
strokeText(a0, a1, a2, a3) {
|
||||
this._context.strokeText(a0, a1, a2, a3);
|
||||
}
|
||||
transform(a0, a1, a2, a3, a4, a5) {
|
||||
this._context.transform(a0, a1, a2, a3, a4, a5);
|
||||
}
|
||||
translate(a0, a1) {
|
||||
this._context.translate(a0, a1);
|
||||
}
|
||||
_enableTrace() {
|
||||
var that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;
|
||||
var func = function (methodName) {
|
||||
var origMethod = that[methodName], ret;
|
||||
that[methodName] = function () {
|
||||
args = simplifyArray(Array.prototype.slice.call(arguments, 0));
|
||||
ret = origMethod.apply(that, arguments);
|
||||
that._trace({
|
||||
method: methodName,
|
||||
args: args,
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
};
|
||||
for (n = 0; n < len; n++) {
|
||||
func(CONTEXT_METHODS[n]);
|
||||
}
|
||||
that.setAttr = function () {
|
||||
origSetter.apply(that, arguments);
|
||||
var prop = arguments[0];
|
||||
var val = arguments[1];
|
||||
if (prop === 'shadowOffsetX' ||
|
||||
prop === 'shadowOffsetY' ||
|
||||
prop === 'shadowBlur') {
|
||||
val = val / this.canvas.getPixelRatio();
|
||||
}
|
||||
that._trace({
|
||||
property: prop,
|
||||
val: val,
|
||||
});
|
||||
};
|
||||
}
|
||||
_applyGlobalCompositeOperation(node) {
|
||||
const op = node.attrs.globalCompositeOperation;
|
||||
var def = !op || op === 'source-over';
|
||||
if (!def) {
|
||||
this.setAttr('globalCompositeOperation', op);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Context = Context;
|
||||
CONTEXT_PROPERTIES.forEach(function (prop) {
|
||||
Object.defineProperty(Context.prototype, prop, {
|
||||
get() {
|
||||
return this._context[prop];
|
||||
},
|
||||
set(val) {
|
||||
this._context[prop] = val;
|
||||
},
|
||||
});
|
||||
});
|
||||
class SceneContext extends Context {
|
||||
_fillColor(shape) {
|
||||
var fill = shape.fill();
|
||||
this.setAttr('fillStyle', fill);
|
||||
shape._fillFunc(this);
|
||||
}
|
||||
_fillPattern(shape) {
|
||||
this.setAttr('fillStyle', shape._getFillPattern());
|
||||
shape._fillFunc(this);
|
||||
}
|
||||
_fillLinearGradient(shape) {
|
||||
var grd = shape._getLinearGradient();
|
||||
if (grd) {
|
||||
this.setAttr('fillStyle', grd);
|
||||
shape._fillFunc(this);
|
||||
}
|
||||
}
|
||||
_fillRadialGradient(shape) {
|
||||
var grd = shape._getRadialGradient();
|
||||
if (grd) {
|
||||
this.setAttr('fillStyle', grd);
|
||||
shape._fillFunc(this);
|
||||
}
|
||||
}
|
||||
_fill(shape) {
|
||||
var hasColor = shape.fill(), fillPriority = shape.getFillPriority();
|
||||
if (hasColor && fillPriority === 'color') {
|
||||
this._fillColor(shape);
|
||||
return;
|
||||
}
|
||||
var hasPattern = shape.getFillPatternImage();
|
||||
if (hasPattern && fillPriority === 'pattern') {
|
||||
this._fillPattern(shape);
|
||||
return;
|
||||
}
|
||||
var hasLinearGradient = shape.getFillLinearGradientColorStops();
|
||||
if (hasLinearGradient && fillPriority === 'linear-gradient') {
|
||||
this._fillLinearGradient(shape);
|
||||
return;
|
||||
}
|
||||
var hasRadialGradient = shape.getFillRadialGradientColorStops();
|
||||
if (hasRadialGradient && fillPriority === 'radial-gradient') {
|
||||
this._fillRadialGradient(shape);
|
||||
return;
|
||||
}
|
||||
if (hasColor) {
|
||||
this._fillColor(shape);
|
||||
}
|
||||
else if (hasPattern) {
|
||||
this._fillPattern(shape);
|
||||
}
|
||||
else if (hasLinearGradient) {
|
||||
this._fillLinearGradient(shape);
|
||||
}
|
||||
else if (hasRadialGradient) {
|
||||
this._fillRadialGradient(shape);
|
||||
}
|
||||
}
|
||||
_strokeLinearGradient(shape) {
|
||||
var start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
|
||||
if (colorStops) {
|
||||
for (var n = 0; n < colorStops.length; n += 2) {
|
||||
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
||||
}
|
||||
this.setAttr('strokeStyle', grd);
|
||||
}
|
||||
}
|
||||
_stroke(shape) {
|
||||
var dash = shape.dash(), strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
||||
if (shape.hasStroke()) {
|
||||
if (!strokeScaleEnabled) {
|
||||
this.save();
|
||||
var pixelRatio = this.getCanvas().getPixelRatio();
|
||||
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
||||
}
|
||||
this._applyLineCap(shape);
|
||||
if (dash && shape.dashEnabled()) {
|
||||
this.setLineDash(dash);
|
||||
this.setAttr('lineDashOffset', shape.dashOffset());
|
||||
}
|
||||
this.setAttr('lineWidth', shape.strokeWidth());
|
||||
if (!shape.getShadowForStrokeEnabled()) {
|
||||
this.setAttr('shadowColor', 'rgba(0,0,0,0)');
|
||||
}
|
||||
var hasLinearGradient = shape.getStrokeLinearGradientColorStops();
|
||||
if (hasLinearGradient) {
|
||||
this._strokeLinearGradient(shape);
|
||||
}
|
||||
else {
|
||||
this.setAttr('strokeStyle', shape.stroke());
|
||||
}
|
||||
shape._strokeFunc(this);
|
||||
if (!strokeScaleEnabled) {
|
||||
this.restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
_applyShadow(shape) {
|
||||
var _a, _b, _c;
|
||||
var color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : 'black', blur = (_b = shape.getShadowBlur()) !== null && _b !== void 0 ? _b : 5, offset = (_c = shape.getShadowOffset()) !== null && _c !== void 0 ? _c : {
|
||||
x: 0,
|
||||
y: 0,
|
||||
}, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
|
||||
this.setAttr('shadowColor', color);
|
||||
this.setAttr('shadowBlur', blur * Math.min(Math.abs(scaleX), Math.abs(scaleY)));
|
||||
this.setAttr('shadowOffsetX', offset.x * scaleX);
|
||||
this.setAttr('shadowOffsetY', offset.y * scaleY);
|
||||
}
|
||||
}
|
||||
exports.SceneContext = SceneContext;
|
||||
class HitContext extends Context {
|
||||
_fill(shape) {
|
||||
this.save();
|
||||
this.setAttr('fillStyle', shape.colorKey);
|
||||
shape._fillFuncHit(this);
|
||||
this.restore();
|
||||
}
|
||||
strokeShape(shape) {
|
||||
if (shape.hasHitStroke()) {
|
||||
this._stroke(shape);
|
||||
}
|
||||
}
|
||||
_stroke(shape) {
|
||||
if (shape.hasHitStroke()) {
|
||||
var strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
||||
if (!strokeScaleEnabled) {
|
||||
this.save();
|
||||
var pixelRatio = this.getCanvas().getPixelRatio();
|
||||
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
||||
}
|
||||
this._applyLineCap(shape);
|
||||
var hitStrokeWidth = shape.hitStrokeWidth();
|
||||
var strokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth;
|
||||
this.setAttr('lineWidth', strokeWidth);
|
||||
this.setAttr('strokeStyle', shape.colorKey);
|
||||
shape._strokeFuncHit(this);
|
||||
if (!strokeScaleEnabled) {
|
||||
this.restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.HitContext = HitContext;
|
||||
3
node_modules/konva/cmj/Core.d.ts
generated
vendored
Normal file
3
node_modules/konva/cmj/Core.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export { Konva } from './_CoreInternals';
|
||||
import { Konva } from './_CoreInternals';
|
||||
export default Konva;
|
||||
7
node_modules/konva/cmj/Core.js
generated
vendored
Normal file
7
node_modules/konva/cmj/Core.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Konva = void 0;
|
||||
var _CoreInternals_1 = require("./_CoreInternals");
|
||||
Object.defineProperty(exports, "Konva", { enumerable: true, get: function () { return _CoreInternals_1.Konva; } });
|
||||
const _CoreInternals_2 = require("./_CoreInternals");
|
||||
exports.default = _CoreInternals_2.Konva;
|
||||
17
node_modules/konva/cmj/DragAndDrop.d.ts
generated
vendored
Normal file
17
node_modules/konva/cmj/DragAndDrop.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Node } from './Node';
|
||||
import { Vector2d } from './types';
|
||||
export declare const DD: {
|
||||
readonly isDragging: boolean;
|
||||
justDragged: boolean;
|
||||
readonly node: Node<import("./Node").NodeConfig>;
|
||||
_dragElements: Map<number, {
|
||||
node: Node;
|
||||
startPointerPos: Vector2d;
|
||||
offset: Vector2d;
|
||||
pointerId?: number;
|
||||
dragStatus: 'ready' | 'dragging' | 'stopped';
|
||||
}>;
|
||||
_drag(evt: any): void;
|
||||
_endDragBefore(evt?: any): void;
|
||||
_endDragAfter(evt: any): void;
|
||||
};
|
||||
107
node_modules/konva/cmj/DragAndDrop.js
generated
vendored
Normal file
107
node_modules/konva/cmj/DragAndDrop.js
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DD = void 0;
|
||||
const Global_1 = require("./Global");
|
||||
const Util_1 = require("./Util");
|
||||
exports.DD = {
|
||||
get isDragging() {
|
||||
var flag = false;
|
||||
exports.DD._dragElements.forEach((elem) => {
|
||||
if (elem.dragStatus === 'dragging') {
|
||||
flag = true;
|
||||
}
|
||||
});
|
||||
return flag;
|
||||
},
|
||||
justDragged: false,
|
||||
get node() {
|
||||
var node;
|
||||
exports.DD._dragElements.forEach((elem) => {
|
||||
node = elem.node;
|
||||
});
|
||||
return node;
|
||||
},
|
||||
_dragElements: new Map(),
|
||||
_drag(evt) {
|
||||
const nodesToFireEvents = [];
|
||||
exports.DD._dragElements.forEach((elem, key) => {
|
||||
const { node } = elem;
|
||||
const stage = node.getStage();
|
||||
stage.setPointersPositions(evt);
|
||||
if (elem.pointerId === undefined) {
|
||||
elem.pointerId = Util_1.Util._getFirstPointerId(evt);
|
||||
}
|
||||
const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
|
||||
if (!pos) {
|
||||
return;
|
||||
}
|
||||
if (elem.dragStatus !== 'dragging') {
|
||||
var dragDistance = node.dragDistance();
|
||||
var distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));
|
||||
if (distance < dragDistance) {
|
||||
return;
|
||||
}
|
||||
node.startDrag({ evt });
|
||||
if (!node.isDragging()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
node._setDragPosition(evt, elem);
|
||||
nodesToFireEvents.push(node);
|
||||
});
|
||||
nodesToFireEvents.forEach((node) => {
|
||||
node.fire('dragmove', {
|
||||
type: 'dragmove',
|
||||
target: node,
|
||||
evt: evt,
|
||||
}, true);
|
||||
});
|
||||
},
|
||||
_endDragBefore(evt) {
|
||||
exports.DD._dragElements.forEach((elem) => {
|
||||
const { node } = elem;
|
||||
const stage = node.getStage();
|
||||
if (evt) {
|
||||
stage.setPointersPositions(evt);
|
||||
}
|
||||
const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
|
||||
if (!pos) {
|
||||
return;
|
||||
}
|
||||
if (elem.dragStatus === 'dragging' || elem.dragStatus === 'stopped') {
|
||||
exports.DD.justDragged = true;
|
||||
Global_1.Konva._mouseListenClick = false;
|
||||
Global_1.Konva._touchListenClick = false;
|
||||
Global_1.Konva._pointerListenClick = false;
|
||||
elem.dragStatus = 'stopped';
|
||||
}
|
||||
const drawNode = elem.node.getLayer() ||
|
||||
(elem.node instanceof Global_1.Konva['Stage'] && elem.node);
|
||||
if (drawNode) {
|
||||
drawNode.batchDraw();
|
||||
}
|
||||
});
|
||||
},
|
||||
_endDragAfter(evt) {
|
||||
exports.DD._dragElements.forEach((elem, key) => {
|
||||
if (elem.dragStatus === 'stopped') {
|
||||
elem.node.fire('dragend', {
|
||||
type: 'dragend',
|
||||
target: elem.node,
|
||||
evt: evt,
|
||||
}, true);
|
||||
}
|
||||
if (elem.dragStatus !== 'dragging') {
|
||||
exports.DD._dragElements.delete(key);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
if (Global_1.Konva.isBrowser) {
|
||||
window.addEventListener('mouseup', exports.DD._endDragBefore, true);
|
||||
window.addEventListener('touchend', exports.DD._endDragBefore, true);
|
||||
window.addEventListener('mousemove', exports.DD._drag);
|
||||
window.addEventListener('touchmove', exports.DD._drag);
|
||||
window.addEventListener('mouseup', exports.DD._endDragAfter, false);
|
||||
window.addEventListener('touchend', exports.DD._endDragAfter, false);
|
||||
}
|
||||
11
node_modules/konva/cmj/Factory.d.ts
generated
vendored
Normal file
11
node_modules/konva/cmj/Factory.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export declare const Factory: {
|
||||
addGetterSetter(constructor: any, attr: any, def?: any, validator?: any, after?: any): void;
|
||||
addGetter(constructor: any, attr: any, def?: any): void;
|
||||
addSetter(constructor: any, attr: any, validator?: any, after?: any): void;
|
||||
overWriteSetter(constructor: any, attr: any, validator?: any, after?: any): void;
|
||||
addComponentsGetterSetter(constructor: any, attr: any, components: any, validator?: any, after?: any): void;
|
||||
addOverloadedGetterSetter(constructor: any, attr: any): void;
|
||||
addDeprecatedGetterSetter(constructor: any, attr: any, def: any, validator: any): void;
|
||||
backCompat(constructor: any, methods: any): void;
|
||||
afterSetFilter(): void;
|
||||
};
|
||||
120
node_modules/konva/cmj/Factory.js
generated
vendored
Normal file
120
node_modules/konva/cmj/Factory.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Factory = void 0;
|
||||
const Util_1 = require("./Util");
|
||||
const Validators_1 = require("./Validators");
|
||||
var GET = 'get', SET = 'set';
|
||||
exports.Factory = {
|
||||
addGetterSetter(constructor, attr, def, validator, after) {
|
||||
exports.Factory.addGetter(constructor, attr, def);
|
||||
exports.Factory.addSetter(constructor, attr, validator, after);
|
||||
exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
||||
},
|
||||
addGetter(constructor, attr, def) {
|
||||
var method = GET + Util_1.Util._capitalize(attr);
|
||||
constructor.prototype[method] =
|
||||
constructor.prototype[method] ||
|
||||
function () {
|
||||
var val = this.attrs[attr];
|
||||
return val === undefined ? def : val;
|
||||
};
|
||||
},
|
||||
addSetter(constructor, attr, validator, after) {
|
||||
var method = SET + Util_1.Util._capitalize(attr);
|
||||
if (!constructor.prototype[method]) {
|
||||
exports.Factory.overWriteSetter(constructor, attr, validator, after);
|
||||
}
|
||||
},
|
||||
overWriteSetter(constructor, attr, validator, after) {
|
||||
var method = SET + Util_1.Util._capitalize(attr);
|
||||
constructor.prototype[method] = function (val) {
|
||||
if (validator && val !== undefined && val !== null) {
|
||||
val = validator.call(this, val, attr);
|
||||
}
|
||||
this._setAttr(attr, val);
|
||||
if (after) {
|
||||
after.call(this);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
},
|
||||
addComponentsGetterSetter(constructor, attr, components, validator, after) {
|
||||
var len = components.length, capitalize = Util_1.Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr), n, component;
|
||||
constructor.prototype[getter] = function () {
|
||||
var ret = {};
|
||||
for (n = 0; n < len; n++) {
|
||||
component = components[n];
|
||||
ret[component] = this.getAttr(attr + capitalize(component));
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
var basicValidator = (0, Validators_1.getComponentValidator)(components);
|
||||
constructor.prototype[setter] = function (val) {
|
||||
var oldVal = this.attrs[attr], key;
|
||||
if (validator) {
|
||||
val = validator.call(this, val);
|
||||
}
|
||||
if (basicValidator) {
|
||||
basicValidator.call(this, val, attr);
|
||||
}
|
||||
for (key in val) {
|
||||
if (!val.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
this._setAttr(attr + capitalize(key), val[key]);
|
||||
}
|
||||
this._fireChangeEvent(attr, oldVal, val);
|
||||
if (after) {
|
||||
after.call(this);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
||||
},
|
||||
addOverloadedGetterSetter(constructor, attr) {
|
||||
var capitalizedAttr = Util_1.Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
|
||||
constructor.prototype[attr] = function () {
|
||||
if (arguments.length) {
|
||||
this[setter](arguments[0]);
|
||||
return this;
|
||||
}
|
||||
return this[getter]();
|
||||
};
|
||||
},
|
||||
addDeprecatedGetterSetter(constructor, attr, def, validator) {
|
||||
Util_1.Util.error('Adding deprecated ' + attr);
|
||||
var method = GET + Util_1.Util._capitalize(attr);
|
||||
var message = attr +
|
||||
' property is deprecated and will be removed soon. Look at Konva change log for more information.';
|
||||
constructor.prototype[method] = function () {
|
||||
Util_1.Util.error(message);
|
||||
var val = this.attrs[attr];
|
||||
return val === undefined ? def : val;
|
||||
};
|
||||
exports.Factory.addSetter(constructor, attr, validator, function () {
|
||||
Util_1.Util.error(message);
|
||||
});
|
||||
exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
||||
},
|
||||
backCompat(constructor, methods) {
|
||||
Util_1.Util.each(methods, function (oldMethodName, newMethodName) {
|
||||
var method = constructor.prototype[newMethodName];
|
||||
var oldGetter = GET + Util_1.Util._capitalize(oldMethodName);
|
||||
var oldSetter = SET + Util_1.Util._capitalize(oldMethodName);
|
||||
function deprecated() {
|
||||
method.apply(this, arguments);
|
||||
Util_1.Util.error('"' +
|
||||
oldMethodName +
|
||||
'" method is deprecated and will be removed soon. Use ""' +
|
||||
newMethodName +
|
||||
'" instead.');
|
||||
}
|
||||
constructor.prototype[oldMethodName] = deprecated;
|
||||
constructor.prototype[oldGetter] = deprecated;
|
||||
constructor.prototype[oldSetter] = deprecated;
|
||||
});
|
||||
},
|
||||
afterSetFilter() {
|
||||
this._filterUpToDate = false;
|
||||
},
|
||||
};
|
||||
4
node_modules/konva/cmj/FastLayer.d.ts
generated
vendored
Normal file
4
node_modules/konva/cmj/FastLayer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { Layer } from './Layer';
|
||||
export declare class FastLayer extends Layer {
|
||||
constructor(attrs: any);
|
||||
}
|
||||
16
node_modules/konva/cmj/FastLayer.js
generated
vendored
Normal file
16
node_modules/konva/cmj/FastLayer.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FastLayer = void 0;
|
||||
const Util_1 = require("./Util");
|
||||
const Layer_1 = require("./Layer");
|
||||
const Global_1 = require("./Global");
|
||||
class FastLayer extends Layer_1.Layer {
|
||||
constructor(attrs) {
|
||||
super(attrs);
|
||||
this.listening(false);
|
||||
Util_1.Util.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.');
|
||||
}
|
||||
}
|
||||
exports.FastLayer = FastLayer;
|
||||
FastLayer.prototype.nodeType = 'FastLayer';
|
||||
(0, Global_1._registerNode)(FastLayer);
|
||||
33
node_modules/konva/cmj/Global.d.ts
generated
vendored
Normal file
33
node_modules/konva/cmj/Global.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
export declare const glob: any;
|
||||
export declare const Konva: {
|
||||
_global: any;
|
||||
version: string;
|
||||
isBrowser: boolean;
|
||||
isUnminified: boolean;
|
||||
dblClickWindow: number;
|
||||
getAngle(angle: number): number;
|
||||
enableTrace: boolean;
|
||||
pointerEventsEnabled: boolean;
|
||||
autoDrawEnabled: boolean;
|
||||
hitOnDragEnabled: boolean;
|
||||
capturePointerEventsEnabled: boolean;
|
||||
_mouseListenClick: boolean;
|
||||
_touchListenClick: boolean;
|
||||
_pointerListenClick: boolean;
|
||||
_mouseInDblClickWindow: boolean;
|
||||
_touchInDblClickWindow: boolean;
|
||||
_pointerInDblClickWindow: boolean;
|
||||
_mouseDblClickPointerId: any;
|
||||
_touchDblClickPointerId: any;
|
||||
_pointerDblClickPointerId: any;
|
||||
pixelRatio: number;
|
||||
dragDistance: number;
|
||||
angleDeg: boolean;
|
||||
showWarnings: boolean;
|
||||
dragButtons: number[];
|
||||
isDragging(): any;
|
||||
isDragReady(): boolean;
|
||||
document: any;
|
||||
_injectGlobal(Konva: any): void;
|
||||
};
|
||||
export declare const _registerNode: (NodeClass: any) => void;
|
||||
60
node_modules/konva/cmj/Global.js
generated
vendored
Normal file
60
node_modules/konva/cmj/Global.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports._registerNode = exports.Konva = exports.glob = void 0;
|
||||
var PI_OVER_180 = Math.PI / 180;
|
||||
function detectBrowser() {
|
||||
return (typeof window !== 'undefined' &&
|
||||
({}.toString.call(window) === '[object Window]' ||
|
||||
{}.toString.call(window) === '[object global]'));
|
||||
}
|
||||
exports.glob = typeof global !== 'undefined'
|
||||
? global
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof WorkerGlobalScope !== 'undefined'
|
||||
? self
|
||||
: {};
|
||||
exports.Konva = {
|
||||
_global: exports.glob,
|
||||
version: '@@version',
|
||||
isBrowser: detectBrowser(),
|
||||
isUnminified: /param/.test(function (param) { }.toString()),
|
||||
dblClickWindow: 400,
|
||||
getAngle(angle) {
|
||||
return exports.Konva.angleDeg ? angle * PI_OVER_180 : angle;
|
||||
},
|
||||
enableTrace: false,
|
||||
pointerEventsEnabled: true,
|
||||
autoDrawEnabled: true,
|
||||
hitOnDragEnabled: false,
|
||||
capturePointerEventsEnabled: false,
|
||||
_mouseListenClick: false,
|
||||
_touchListenClick: false,
|
||||
_pointerListenClick: false,
|
||||
_mouseInDblClickWindow: false,
|
||||
_touchInDblClickWindow: false,
|
||||
_pointerInDblClickWindow: false,
|
||||
_mouseDblClickPointerId: null,
|
||||
_touchDblClickPointerId: null,
|
||||
_pointerDblClickPointerId: null,
|
||||
pixelRatio: (typeof window !== 'undefined' && window.devicePixelRatio) || 1,
|
||||
dragDistance: 3,
|
||||
angleDeg: true,
|
||||
showWarnings: true,
|
||||
dragButtons: [0, 1],
|
||||
isDragging() {
|
||||
return exports.Konva['DD'].isDragging;
|
||||
},
|
||||
isDragReady() {
|
||||
return !!exports.Konva['DD'].node;
|
||||
},
|
||||
document: exports.glob.document,
|
||||
_injectGlobal(Konva) {
|
||||
exports.glob.Konva = Konva;
|
||||
},
|
||||
};
|
||||
const _registerNode = (NodeClass) => {
|
||||
exports.Konva[NodeClass.prototype.getClassName()] = NodeClass;
|
||||
};
|
||||
exports._registerNode = _registerNode;
|
||||
exports.Konva._injectGlobal(exports.Konva);
|
||||
6
node_modules/konva/cmj/Group.d.ts
generated
vendored
Normal file
6
node_modules/konva/cmj/Group.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Container } from './Container';
|
||||
import { Node } from './Node';
|
||||
import { Shape } from './Shape';
|
||||
export declare class Group extends Container<Group | Shape> {
|
||||
_validateAdd(child: Node): void;
|
||||
}
|
||||
17
node_modules/konva/cmj/Group.js
generated
vendored
Normal file
17
node_modules/konva/cmj/Group.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Group = void 0;
|
||||
const Util_1 = require("./Util");
|
||||
const Container_1 = require("./Container");
|
||||
const Global_1 = require("./Global");
|
||||
class Group extends Container_1.Container {
|
||||
_validateAdd(child) {
|
||||
var type = child.getType();
|
||||
if (type !== 'Group' && type !== 'Shape') {
|
||||
Util_1.Util.throw('You may only add groups and shapes to groups.');
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Group = Group;
|
||||
Group.prototype.nodeType = 'Group';
|
||||
(0, Global_1._registerNode)(Group);
|
||||
60
node_modules/konva/cmj/Layer.d.ts
generated
vendored
Normal file
60
node_modules/konva/cmj/Layer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Container, ContainerConfig } from './Container';
|
||||
import { Node } from './Node';
|
||||
import { SceneCanvas, HitCanvas } from './Canvas';
|
||||
import { Stage } from './Stage';
|
||||
import { GetSet, Vector2d } from './types';
|
||||
import { Group } from './Group';
|
||||
import { Shape } from './Shape';
|
||||
export interface LayerConfig extends ContainerConfig {
|
||||
clearBeforeDraw?: boolean;
|
||||
hitGraphEnabled?: boolean;
|
||||
imageSmoothingEnabled?: boolean;
|
||||
}
|
||||
export declare class Layer extends Container<Group | Shape> {
|
||||
canvas: SceneCanvas;
|
||||
hitCanvas: HitCanvas;
|
||||
_waitingForDraw: boolean;
|
||||
constructor(config?: LayerConfig);
|
||||
createPNGStream(): any;
|
||||
getCanvas(): SceneCanvas;
|
||||
getNativeCanvasElement(): HTMLCanvasElement;
|
||||
getHitCanvas(): HitCanvas;
|
||||
getContext(): import("./Context").Context;
|
||||
clear(bounds?: any): this;
|
||||
setZIndex(index: any): this;
|
||||
moveToTop(): boolean;
|
||||
moveUp(): boolean;
|
||||
moveDown(): boolean;
|
||||
moveToBottom(): boolean;
|
||||
getLayer(): this;
|
||||
remove(): this;
|
||||
getStage(): Stage;
|
||||
setSize({ width, height }: {
|
||||
width: any;
|
||||
height: any;
|
||||
}): this;
|
||||
_validateAdd(child: any): void;
|
||||
_toKonvaCanvas(config: any): any;
|
||||
_checkVisibility(): void;
|
||||
_setSmoothEnabled(): void;
|
||||
getWidth(): number;
|
||||
setWidth(): void;
|
||||
getHeight(): number;
|
||||
setHeight(): void;
|
||||
batchDraw(): this;
|
||||
getIntersection(pos: Vector2d): Shape<import("./Shape").ShapeConfig>;
|
||||
_getIntersection(pos: Vector2d): {
|
||||
shape?: Shape;
|
||||
antialiased?: boolean;
|
||||
};
|
||||
drawScene(can?: SceneCanvas, top?: Node): this;
|
||||
drawHit(can?: HitCanvas, top?: Node): this;
|
||||
enableHitGraph(): this;
|
||||
disableHitGraph(): this;
|
||||
setHitGraphEnabled(val: any): void;
|
||||
getHitGraphEnabled(val: any): boolean;
|
||||
toggleHitCanvas(): void;
|
||||
hitGraphEnabled: GetSet<boolean, this>;
|
||||
clearBeforeDraw: GetSet<boolean, this>;
|
||||
imageSmoothingEnabled: GetSet<boolean, this>;
|
||||
}
|
||||
305
node_modules/konva/cmj/Layer.js
generated
vendored
Normal file
305
node_modules/konva/cmj/Layer.js
generated
vendored
Normal file
@@ -0,0 +1,305 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Layer = void 0;
|
||||
const Util_1 = require("./Util");
|
||||
const Container_1 = require("./Container");
|
||||
const Node_1 = require("./Node");
|
||||
const Factory_1 = require("./Factory");
|
||||
const Canvas_1 = require("./Canvas");
|
||||
const Validators_1 = require("./Validators");
|
||||
const Shape_1 = require("./Shape");
|
||||
const Global_1 = require("./Global");
|
||||
var HASH = '#', BEFORE_DRAW = 'beforeDraw', DRAW = 'draw', INTERSECTION_OFFSETS = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: -1, y: -1 },
|
||||
{ x: 1, y: -1 },
|
||||
{ x: 1, y: 1 },
|
||||
{ x: -1, y: 1 },
|
||||
], INTERSECTION_OFFSETS_LEN = INTERSECTION_OFFSETS.length;
|
||||
class Layer extends Container_1.Container {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
this.canvas = new Canvas_1.SceneCanvas();
|
||||
this.hitCanvas = new Canvas_1.HitCanvas({
|
||||
pixelRatio: 1,
|
||||
});
|
||||
this._waitingForDraw = false;
|
||||
this.on('visibleChange.konva', this._checkVisibility);
|
||||
this._checkVisibility();
|
||||
this.on('imageSmoothingEnabledChange.konva', this._setSmoothEnabled);
|
||||
this._setSmoothEnabled();
|
||||
}
|
||||
createPNGStream() {
|
||||
const c = this.canvas._canvas;
|
||||
return c.createPNGStream();
|
||||
}
|
||||
getCanvas() {
|
||||
return this.canvas;
|
||||
}
|
||||
getNativeCanvasElement() {
|
||||
return this.canvas._canvas;
|
||||
}
|
||||
getHitCanvas() {
|
||||
return this.hitCanvas;
|
||||
}
|
||||
getContext() {
|
||||
return this.getCanvas().getContext();
|
||||
}
|
||||
clear(bounds) {
|
||||
this.getContext().clear(bounds);
|
||||
this.getHitCanvas().getContext().clear(bounds);
|
||||
return this;
|
||||
}
|
||||
setZIndex(index) {
|
||||
super.setZIndex(index);
|
||||
var stage = this.getStage();
|
||||
if (stage && stage.content) {
|
||||
stage.content.removeChild(this.getNativeCanvasElement());
|
||||
if (index < stage.children.length - 1) {
|
||||
stage.content.insertBefore(this.getNativeCanvasElement(), stage.children[index + 1].getCanvas()._canvas);
|
||||
}
|
||||
else {
|
||||
stage.content.appendChild(this.getNativeCanvasElement());
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
moveToTop() {
|
||||
Node_1.Node.prototype.moveToTop.call(this);
|
||||
var stage = this.getStage();
|
||||
if (stage && stage.content) {
|
||||
stage.content.removeChild(this.getNativeCanvasElement());
|
||||
stage.content.appendChild(this.getNativeCanvasElement());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
moveUp() {
|
||||
var moved = Node_1.Node.prototype.moveUp.call(this);
|
||||
if (!moved) {
|
||||
return false;
|
||||
}
|
||||
var stage = this.getStage();
|
||||
if (!stage || !stage.content) {
|
||||
return false;
|
||||
}
|
||||
stage.content.removeChild(this.getNativeCanvasElement());
|
||||
if (this.index < stage.children.length - 1) {
|
||||
stage.content.insertBefore(this.getNativeCanvasElement(), stage.children[this.index + 1].getCanvas()._canvas);
|
||||
}
|
||||
else {
|
||||
stage.content.appendChild(this.getNativeCanvasElement());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
moveDown() {
|
||||
if (Node_1.Node.prototype.moveDown.call(this)) {
|
||||
var stage = this.getStage();
|
||||
if (stage) {
|
||||
var children = stage.children;
|
||||
if (stage.content) {
|
||||
stage.content.removeChild(this.getNativeCanvasElement());
|
||||
stage.content.insertBefore(this.getNativeCanvasElement(), children[this.index + 1].getCanvas()._canvas);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
moveToBottom() {
|
||||
if (Node_1.Node.prototype.moveToBottom.call(this)) {
|
||||
var stage = this.getStage();
|
||||
if (stage) {
|
||||
var children = stage.children;
|
||||
if (stage.content) {
|
||||
stage.content.removeChild(this.getNativeCanvasElement());
|
||||
stage.content.insertBefore(this.getNativeCanvasElement(), children[1].getCanvas()._canvas);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
getLayer() {
|
||||
return this;
|
||||
}
|
||||
remove() {
|
||||
var _canvas = this.getNativeCanvasElement();
|
||||
Node_1.Node.prototype.remove.call(this);
|
||||
if (_canvas && _canvas.parentNode && Util_1.Util._isInDocument(_canvas)) {
|
||||
_canvas.parentNode.removeChild(_canvas);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
getStage() {
|
||||
return this.parent;
|
||||
}
|
||||
setSize({ width, height }) {
|
||||
this.canvas.setSize(width, height);
|
||||
this.hitCanvas.setSize(width, height);
|
||||
this._setSmoothEnabled();
|
||||
return this;
|
||||
}
|
||||
_validateAdd(child) {
|
||||
var type = child.getType();
|
||||
if (type !== 'Group' && type !== 'Shape') {
|
||||
Util_1.Util.throw('You may only add groups and shapes to a layer.');
|
||||
}
|
||||
}
|
||||
_toKonvaCanvas(config) {
|
||||
config = config || {};
|
||||
config.width = config.width || this.getWidth();
|
||||
config.height = config.height || this.getHeight();
|
||||
config.x = config.x !== undefined ? config.x : this.x();
|
||||
config.y = config.y !== undefined ? config.y : this.y();
|
||||
return Node_1.Node.prototype._toKonvaCanvas.call(this, config);
|
||||
}
|
||||
_checkVisibility() {
|
||||
const visible = this.visible();
|
||||
if (visible) {
|
||||
this.canvas._canvas.style.display = 'block';
|
||||
}
|
||||
else {
|
||||
this.canvas._canvas.style.display = 'none';
|
||||
}
|
||||
}
|
||||
_setSmoothEnabled() {
|
||||
this.getContext()._context.imageSmoothingEnabled =
|
||||
this.imageSmoothingEnabled();
|
||||
}
|
||||
getWidth() {
|
||||
if (this.parent) {
|
||||
return this.parent.width();
|
||||
}
|
||||
}
|
||||
setWidth() {
|
||||
Util_1.Util.warn('Can not change width of layer. Use "stage.width(value)" function instead.');
|
||||
}
|
||||
getHeight() {
|
||||
if (this.parent) {
|
||||
return this.parent.height();
|
||||
}
|
||||
}
|
||||
setHeight() {
|
||||
Util_1.Util.warn('Can not change height of layer. Use "stage.height(value)" function instead.');
|
||||
}
|
||||
batchDraw() {
|
||||
if (!this._waitingForDraw) {
|
||||
this._waitingForDraw = true;
|
||||
Util_1.Util.requestAnimFrame(() => {
|
||||
this.draw();
|
||||
this._waitingForDraw = false;
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
getIntersection(pos) {
|
||||
if (!this.isListening() || !this.isVisible()) {
|
||||
return null;
|
||||
}
|
||||
var spiralSearchDistance = 1;
|
||||
var continueSearch = false;
|
||||
while (true) {
|
||||
for (let i = 0; i < INTERSECTION_OFFSETS_LEN; i++) {
|
||||
const intersectionOffset = INTERSECTION_OFFSETS[i];
|
||||
const obj = this._getIntersection({
|
||||
x: pos.x + intersectionOffset.x * spiralSearchDistance,
|
||||
y: pos.y + intersectionOffset.y * spiralSearchDistance,
|
||||
});
|
||||
const shape = obj.shape;
|
||||
if (shape) {
|
||||
return shape;
|
||||
}
|
||||
continueSearch = !!obj.antialiased;
|
||||
if (!obj.antialiased) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (continueSearch) {
|
||||
spiralSearchDistance += 1;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
_getIntersection(pos) {
|
||||
const ratio = this.hitCanvas.pixelRatio;
|
||||
const p = this.hitCanvas.context.getImageData(Math.round(pos.x * ratio), Math.round(pos.y * ratio), 1, 1).data;
|
||||
const p3 = p[3];
|
||||
if (p3 === 255) {
|
||||
const colorKey = Util_1.Util._rgbToHex(p[0], p[1], p[2]);
|
||||
const shape = Shape_1.shapes[HASH + colorKey];
|
||||
if (shape) {
|
||||
return {
|
||||
shape: shape,
|
||||
};
|
||||
}
|
||||
return {
|
||||
antialiased: true,
|
||||
};
|
||||
}
|
||||
else if (p3 > 0) {
|
||||
return {
|
||||
antialiased: true,
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
drawScene(can, top) {
|
||||
var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
|
||||
this._fire(BEFORE_DRAW, {
|
||||
node: this,
|
||||
});
|
||||
if (this.clearBeforeDraw()) {
|
||||
canvas.getContext().clear();
|
||||
}
|
||||
Container_1.Container.prototype.drawScene.call(this, canvas, top);
|
||||
this._fire(DRAW, {
|
||||
node: this,
|
||||
});
|
||||
return this;
|
||||
}
|
||||
drawHit(can, top) {
|
||||
var layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas);
|
||||
if (layer && layer.clearBeforeDraw()) {
|
||||
layer.getHitCanvas().getContext().clear();
|
||||
}
|
||||
Container_1.Container.prototype.drawHit.call(this, canvas, top);
|
||||
return this;
|
||||
}
|
||||
enableHitGraph() {
|
||||
this.hitGraphEnabled(true);
|
||||
return this;
|
||||
}
|
||||
disableHitGraph() {
|
||||
this.hitGraphEnabled(false);
|
||||
return this;
|
||||
}
|
||||
setHitGraphEnabled(val) {
|
||||
Util_1.Util.warn('hitGraphEnabled method is deprecated. Please use layer.listening() instead.');
|
||||
this.listening(val);
|
||||
}
|
||||
getHitGraphEnabled(val) {
|
||||
Util_1.Util.warn('hitGraphEnabled method is deprecated. Please use layer.listening() instead.');
|
||||
return this.listening();
|
||||
}
|
||||
toggleHitCanvas() {
|
||||
if (!this.parent || !this.parent['content']) {
|
||||
return;
|
||||
}
|
||||
var parent = this.parent;
|
||||
var added = !!this.hitCanvas._canvas.parentNode;
|
||||
if (added) {
|
||||
parent.content.removeChild(this.hitCanvas._canvas);
|
||||
}
|
||||
else {
|
||||
parent.content.appendChild(this.hitCanvas._canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Layer = Layer;
|
||||
Layer.prototype.nodeType = 'Layer';
|
||||
(0, Global_1._registerNode)(Layer);
|
||||
Factory_1.Factory.addGetterSetter(Layer, 'imageSmoothingEnabled', true);
|
||||
Factory_1.Factory.addGetterSetter(Layer, 'clearBeforeDraw', true);
|
||||
Factory_1.Factory.addGetterSetter(Layer, 'hitGraphEnabled', true, (0, Validators_1.getBooleanValidator)());
|
||||
318
node_modules/konva/cmj/Node.d.ts
generated
vendored
Normal file
318
node_modules/konva/cmj/Node.d.ts
generated
vendored
Normal file
@@ -0,0 +1,318 @@
|
||||
import { Transform } from './Util';
|
||||
import { SceneCanvas, Canvas } from './Canvas';
|
||||
import { Container } from './Container';
|
||||
import { GetSet, Vector2d, IRect } from './types';
|
||||
import { Stage } from './Stage';
|
||||
import { Context } from './Context';
|
||||
import { Shape } from './Shape';
|
||||
import { Layer } from './Layer';
|
||||
export declare type Filter = (this: Node, imageData: ImageData) => void;
|
||||
declare type globalCompositeOperationType = '' | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
|
||||
export interface NodeConfig {
|
||||
[index: string]: any;
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
visible?: boolean;
|
||||
listening?: boolean;
|
||||
id?: string;
|
||||
name?: string;
|
||||
opacity?: Number;
|
||||
scale?: Vector2d;
|
||||
scaleX?: number;
|
||||
scaleY?: number;
|
||||
rotation?: number;
|
||||
rotationDeg?: number;
|
||||
offset?: Vector2d;
|
||||
offsetX?: number;
|
||||
offsetY?: number;
|
||||
draggable?: boolean;
|
||||
dragDistance?: number;
|
||||
dragBoundFunc?: (this: Node, pos: Vector2d) => Vector2d;
|
||||
preventDefault?: boolean;
|
||||
globalCompositeOperation?: globalCompositeOperationType;
|
||||
filters?: Array<Filter>;
|
||||
}
|
||||
declare type NodeEventMap = GlobalEventHandlersEventMap & {
|
||||
[index: string]: any;
|
||||
};
|
||||
export interface KonvaEventObject<EventType> {
|
||||
type: string;
|
||||
target: Shape | Stage;
|
||||
evt: EventType;
|
||||
currentTarget: Node;
|
||||
cancelBubble: boolean;
|
||||
child?: Node;
|
||||
}
|
||||
export declare type KonvaEventListener<This, EventType> = (this: This, ev: KonvaEventObject<EventType>) => void;
|
||||
export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
_id: number;
|
||||
eventListeners: {
|
||||
[index: string]: Array<{
|
||||
name: string;
|
||||
handler: Function;
|
||||
}>;
|
||||
};
|
||||
attrs: any;
|
||||
index: number;
|
||||
_allEventListeners: null | Array<Function>;
|
||||
parent: Container<Node> | null;
|
||||
_cache: Map<string, any>;
|
||||
_attachedDepsListeners: Map<string, boolean>;
|
||||
_lastPos: Vector2d;
|
||||
_attrsAffectingSize: string[];
|
||||
_batchingTransformChange: boolean;
|
||||
_needClearTransformCache: boolean;
|
||||
_filterUpToDate: boolean;
|
||||
_isUnderCache: boolean;
|
||||
nodeType: string;
|
||||
className: string;
|
||||
_dragEventId: number | null;
|
||||
_shouldFireChangeEvents: boolean;
|
||||
constructor(config?: Config);
|
||||
hasChildren(): boolean;
|
||||
_clearCache(attr?: string): void;
|
||||
_getCache(attr: string, privateGetter: Function): any;
|
||||
_calculate(name: string, deps: Array<string>, getter: Function): any;
|
||||
_getCanvasCache(): any;
|
||||
_clearSelfAndDescendantCache(attr?: string): void;
|
||||
clearCache(): this;
|
||||
cache(config?: {
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
drawBorder?: boolean;
|
||||
offset?: number;
|
||||
pixelRatio?: number;
|
||||
imageSmoothingEnabled?: boolean;
|
||||
hitCanvasPixelRatio?: number;
|
||||
}): this;
|
||||
isCached(): boolean;
|
||||
abstract drawScene(canvas?: Canvas, top?: Node): void;
|
||||
abstract drawHit(canvas?: Canvas, top?: Node): void;
|
||||
getClientRect(config?: {
|
||||
skipTransform?: boolean;
|
||||
skipShadow?: boolean;
|
||||
skipStroke?: boolean;
|
||||
relativeTo?: Container<Node>;
|
||||
}): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
_transformedRect(rect: IRect, top: Node): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
_drawCachedSceneCanvas(context: Context): void;
|
||||
_drawCachedHitCanvas(context: Context): void;
|
||||
_getCachedSceneCanvas(): any;
|
||||
on<K extends keyof NodeEventMap>(evtStr: K, handler: KonvaEventListener<this, NodeEventMap[K]>): any;
|
||||
off(evtStr?: string, callback?: Function): this;
|
||||
dispatchEvent(evt: any): this;
|
||||
addEventListener(type: string, handler: (e: Event) => void): this;
|
||||
removeEventListener(type: string): this;
|
||||
_delegate(event: string, selector: string, handler: (e: Event) => void): void;
|
||||
remove(): this;
|
||||
_clearCaches(): void;
|
||||
_remove(): void;
|
||||
destroy(): this;
|
||||
getAttr(attr: string): any;
|
||||
getAncestors(): Node<NodeConfig>[];
|
||||
getAttrs(): any;
|
||||
setAttrs(config: any): this;
|
||||
isListening(): any;
|
||||
_isListening(relativeTo?: Node): boolean;
|
||||
isVisible(): any;
|
||||
_isVisible(relativeTo?: Node): boolean;
|
||||
shouldDrawHit(top?: Node, skipDragCheck?: boolean): boolean;
|
||||
show(): this;
|
||||
hide(): this;
|
||||
getZIndex(): number;
|
||||
getAbsoluteZIndex(): number;
|
||||
getDepth(): number;
|
||||
_batchTransformChanges(func: any): void;
|
||||
setPosition(pos: Vector2d): this;
|
||||
getPosition(): {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
getRelativePointerPosition(): {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
getAbsolutePosition(top?: Node): {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
setAbsolutePosition(pos: Vector2d): this;
|
||||
_setTransform(trans: any): void;
|
||||
_clearTransform(): {
|
||||
x: number;
|
||||
y: number;
|
||||
rotation: number;
|
||||
scaleX: number;
|
||||
scaleY: number;
|
||||
offsetX: number;
|
||||
offsetY: number;
|
||||
skewX: number;
|
||||
skewY: number;
|
||||
};
|
||||
move(change: Vector2d): this;
|
||||
_eachAncestorReverse(func: any, top: any): void;
|
||||
rotate(theta: number): this;
|
||||
moveToTop(): boolean;
|
||||
moveUp(): boolean;
|
||||
moveDown(): boolean;
|
||||
moveToBottom(): boolean;
|
||||
setZIndex(zIndex: any): this;
|
||||
getAbsoluteOpacity(): any;
|
||||
_getAbsoluteOpacity(): number;
|
||||
moveTo(newContainer: any): this;
|
||||
toObject(): any;
|
||||
toJSON(): string;
|
||||
getParent(): Container<Node<NodeConfig>>;
|
||||
findAncestors(selector: string, includeSelf?: boolean, stopNode?: Node): Node<NodeConfig>[];
|
||||
isAncestorOf(node: Node): boolean;
|
||||
findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container): any;
|
||||
_isMatch(selector: string | Function): any;
|
||||
getLayer(): Layer | null;
|
||||
getStage(): Stage | null;
|
||||
_getStage(): Stage | undefined;
|
||||
fire(eventType: string, evt?: any, bubble?: boolean): this;
|
||||
getAbsoluteTransform(top?: Node): Transform;
|
||||
_getAbsoluteTransform(top?: Node): Transform;
|
||||
getAbsoluteScale(top?: Node): {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
getAbsoluteRotation(): number;
|
||||
getTransform(): Transform;
|
||||
_getTransform(): Transform;
|
||||
clone(obj?: any): any;
|
||||
_toKonvaCanvas(config: any): SceneCanvas;
|
||||
toCanvas(config?: any): HTMLCanvasElement;
|
||||
toDataURL(config?: {
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
pixelRatio?: number;
|
||||
mimeType?: string;
|
||||
quality?: number;
|
||||
callback?: (str: string) => void;
|
||||
}): string;
|
||||
toImage(config?: {
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
pixelRatio?: number;
|
||||
mimeType?: string;
|
||||
quality?: number;
|
||||
callback?: (img: HTMLImageElement) => void;
|
||||
}): void;
|
||||
setSize(size: any): this;
|
||||
getSize(): {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
getClassName(): string;
|
||||
getType(): string;
|
||||
getDragDistance(): number;
|
||||
_off(type: any, name?: any, callback?: any): void;
|
||||
_fireChangeEvent(attr: any, oldVal: any, newVal: any): void;
|
||||
addName(name: any): this;
|
||||
hasName(name: any): boolean;
|
||||
removeName(name: any): this;
|
||||
setAttr(attr: any, val: any): this;
|
||||
_requestDraw(): void;
|
||||
_setAttr(key: any, val: any): void;
|
||||
_setComponentAttr(key: any, component: any, val: any): void;
|
||||
_fireAndBubble(eventType: any, evt: any, compareShape?: any): void;
|
||||
_getProtoListeners(eventType: any): any;
|
||||
_fire(eventType: any, evt: any): void;
|
||||
draw(): this;
|
||||
_createDragElement(evt: any): void;
|
||||
startDrag(evt?: any, bubbleEvent?: boolean): void;
|
||||
_setDragPosition(evt: any, elem: any): void;
|
||||
stopDrag(evt?: any): void;
|
||||
setDraggable(draggable: any): void;
|
||||
isDragging(): boolean;
|
||||
_listenDrag(): void;
|
||||
_dragChange(): void;
|
||||
_dragCleanup(): void;
|
||||
isClientRectOnScreen(margin?: {
|
||||
x: number;
|
||||
y: number;
|
||||
}): boolean;
|
||||
preventDefault: GetSet<boolean, this>;
|
||||
blue: GetSet<number, this>;
|
||||
brightness: GetSet<number, this>;
|
||||
contrast: GetSet<number, this>;
|
||||
blurRadius: GetSet<number, this>;
|
||||
luminance: GetSet<number, this>;
|
||||
green: GetSet<number, this>;
|
||||
alpha: GetSet<number, this>;
|
||||
hue: GetSet<number, this>;
|
||||
kaleidoscopeAngle: GetSet<number, this>;
|
||||
kaleidoscopePower: GetSet<number, this>;
|
||||
levels: GetSet<number, this>;
|
||||
noise: GetSet<number, this>;
|
||||
pixelSize: GetSet<number, this>;
|
||||
red: GetSet<number, this>;
|
||||
saturation: GetSet<number, this>;
|
||||
threshold: GetSet<number, this>;
|
||||
value: GetSet<number, this>;
|
||||
dragBoundFunc: GetSet<(this: Node, pos: Vector2d) => Vector2d, this>;
|
||||
draggable: GetSet<boolean, this>;
|
||||
dragDistance: GetSet<number, this>;
|
||||
embossBlend: GetSet<boolean, this>;
|
||||
embossDirection: GetSet<string, this>;
|
||||
embossStrength: GetSet<number, this>;
|
||||
embossWhiteLevel: GetSet<number, this>;
|
||||
enhance: GetSet<number, this>;
|
||||
filters: GetSet<Filter[], this>;
|
||||
position: GetSet<Vector2d, this>;
|
||||
absolutePosition: GetSet<Vector2d, this>;
|
||||
size: GetSet<{
|
||||
width: number;
|
||||
height: number;
|
||||
}, this>;
|
||||
id: GetSet<string, this>;
|
||||
listening: GetSet<boolean, this>;
|
||||
name: GetSet<string, this>;
|
||||
offset: GetSet<Vector2d, this>;
|
||||
offsetX: GetSet<number, this>;
|
||||
offsetY: GetSet<number, this>;
|
||||
opacity: GetSet<number, this>;
|
||||
rotation: GetSet<number, this>;
|
||||
zIndex: GetSet<number, this>;
|
||||
scale: GetSet<Vector2d, this>;
|
||||
scaleX: GetSet<number, this>;
|
||||
scaleY: GetSet<number, this>;
|
||||
skew: GetSet<Vector2d, this>;
|
||||
skewX: GetSet<number, this>;
|
||||
skewY: GetSet<number, this>;
|
||||
to: (params: AnimTo) => void;
|
||||
transformsEnabled: GetSet<string, this>;
|
||||
visible: GetSet<boolean, this>;
|
||||
width: GetSet<number, this>;
|
||||
height: GetSet<number, this>;
|
||||
x: GetSet<number, this>;
|
||||
y: GetSet<number, this>;
|
||||
globalCompositeOperation: GetSet<globalCompositeOperationType, this>;
|
||||
static create(data: any, container?: any): any;
|
||||
static _createNode(obj: any, container?: any): any;
|
||||
}
|
||||
interface AnimTo extends NodeConfig {
|
||||
onFinish?: Function;
|
||||
onUpdate?: Function;
|
||||
duration?: number;
|
||||
}
|
||||
export {};
|
||||
1385
node_modules/konva/cmj/Node.js
generated
vendored
Normal file
1385
node_modules/konva/cmj/Node.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
node_modules/konva/cmj/PointerEvents.d.ts
generated
vendored
Normal file
11
node_modules/konva/cmj/PointerEvents.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { KonvaEventObject } from './Node';
|
||||
import { Shape } from './Shape';
|
||||
import { Stage } from './Stage';
|
||||
export interface KonvaPointerEvent extends KonvaEventObject<PointerEvent> {
|
||||
pointerId: number;
|
||||
}
|
||||
export declare function getCapturedShape(pointerId: number): Stage | Shape<import("./Shape").ShapeConfig>;
|
||||
export declare function createEvent(evt: PointerEvent): KonvaPointerEvent;
|
||||
export declare function hasPointerCapture(pointerId: number, shape: Shape | Stage): boolean;
|
||||
export declare function setPointerCapture(pointerId: number, shape: Shape | Stage): void;
|
||||
export declare function releaseCapture(pointerId: number, target?: Shape | Stage): void;
|
||||
45
node_modules/konva/cmj/PointerEvents.js
generated
vendored
Normal file
45
node_modules/konva/cmj/PointerEvents.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.releaseCapture = exports.setPointerCapture = exports.hasPointerCapture = exports.createEvent = exports.getCapturedShape = void 0;
|
||||
const Global_1 = require("./Global");
|
||||
const Captures = new Map();
|
||||
const SUPPORT_POINTER_EVENTS = Global_1.Konva._global['PointerEvent'] !== undefined;
|
||||
function getCapturedShape(pointerId) {
|
||||
return Captures.get(pointerId);
|
||||
}
|
||||
exports.getCapturedShape = getCapturedShape;
|
||||
function createEvent(evt) {
|
||||
return {
|
||||
evt,
|
||||
pointerId: evt.pointerId,
|
||||
};
|
||||
}
|
||||
exports.createEvent = createEvent;
|
||||
function hasPointerCapture(pointerId, shape) {
|
||||
return Captures.get(pointerId) === shape;
|
||||
}
|
||||
exports.hasPointerCapture = hasPointerCapture;
|
||||
function setPointerCapture(pointerId, shape) {
|
||||
releaseCapture(pointerId);
|
||||
const stage = shape.getStage();
|
||||
if (!stage)
|
||||
return;
|
||||
Captures.set(pointerId, shape);
|
||||
if (SUPPORT_POINTER_EVENTS) {
|
||||
shape._fire('gotpointercapture', createEvent(new PointerEvent('gotpointercapture')));
|
||||
}
|
||||
}
|
||||
exports.setPointerCapture = setPointerCapture;
|
||||
function releaseCapture(pointerId, target) {
|
||||
const shape = Captures.get(pointerId);
|
||||
if (!shape)
|
||||
return;
|
||||
const stage = shape.getStage();
|
||||
if (stage && stage.content) {
|
||||
}
|
||||
Captures.delete(pointerId);
|
||||
if (SUPPORT_POINTER_EVENTS) {
|
||||
shape._fire('lostpointercapture', createEvent(new PointerEvent('lostpointercapture')));
|
||||
}
|
||||
}
|
||||
exports.releaseCapture = releaseCapture;
|
||||
184
node_modules/konva/cmj/Shape.d.ts
generated
vendored
Normal file
184
node_modules/konva/cmj/Shape.d.ts
generated
vendored
Normal file
@@ -0,0 +1,184 @@
|
||||
import { Node, NodeConfig } from './Node';
|
||||
import { Context } from './Context';
|
||||
import { GetSet, Vector2d } from './types';
|
||||
import { HitCanvas, SceneCanvas } from './Canvas';
|
||||
export declare type ShapeConfigHandler<TTarget> = {
|
||||
bivarianceHack(ctx: Context, shape: TTarget): void;
|
||||
}['bivarianceHack'];
|
||||
export declare type LineJoin = 'round' | 'bevel' | 'miter';
|
||||
export declare type LineCap = 'butt' | 'round' | 'square';
|
||||
export interface ShapeConfig extends NodeConfig {
|
||||
fill?: string;
|
||||
fillPatternImage?: HTMLImageElement;
|
||||
fillPatternX?: number;
|
||||
fillPatternY?: number;
|
||||
fillPatternOffset?: Vector2d;
|
||||
fillPatternOffsetX?: number;
|
||||
fillPatternOffsetY?: number;
|
||||
fillPatternScale?: Vector2d;
|
||||
fillPatternScaleX?: number;
|
||||
fillPatternScaleY?: number;
|
||||
fillPatternRotation?: number;
|
||||
fillPatternRepeat?: string;
|
||||
fillLinearGradientStartPoint?: Vector2d;
|
||||
fillLinearGradientStartPointX?: number;
|
||||
fillLinearGradientStartPointY?: number;
|
||||
fillLinearGradientEndPoint?: Vector2d;
|
||||
fillLinearGradientEndPointX?: number;
|
||||
fillLinearGradientEndPointY?: number;
|
||||
fillLinearGradientColorStops?: Array<number | string>;
|
||||
fillRadialGradientStartPoint?: Vector2d;
|
||||
fillRadialGradientStartPointX?: number;
|
||||
fillRadialGradientStartPointY?: number;
|
||||
fillRadialGradientEndPoint?: Vector2d;
|
||||
fillRadialGradientEndPointX?: number;
|
||||
fillRadialGradientEndPointY?: number;
|
||||
fillRadialGradientStartRadius?: number;
|
||||
fillRadialGradientEndRadius?: number;
|
||||
fillRadialGradientColorStops?: Array<number | string>;
|
||||
fillEnabled?: boolean;
|
||||
fillPriority?: string;
|
||||
stroke?: string | CanvasGradient;
|
||||
strokeWidth?: number;
|
||||
fillAfterStrokeEnabled?: boolean;
|
||||
hitStrokeWidth?: number | string;
|
||||
strokeScaleEnabled?: boolean;
|
||||
strokeHitEnabled?: boolean;
|
||||
strokeEnabled?: boolean;
|
||||
lineJoin?: LineJoin;
|
||||
lineCap?: LineCap;
|
||||
sceneFunc?: (con: Context, shape: Shape) => void;
|
||||
hitFunc?: (con: Context, shape: Shape) => void;
|
||||
shadowColor?: string;
|
||||
shadowBlur?: number;
|
||||
shadowOffset?: Vector2d;
|
||||
shadowOffsetX?: number;
|
||||
shadowOffsetY?: number;
|
||||
shadowOpacity?: number;
|
||||
shadowEnabled?: boolean;
|
||||
shadowForStrokeEnabled?: boolean;
|
||||
dash?: number[];
|
||||
dashOffset?: number;
|
||||
dashEnabled?: boolean;
|
||||
perfectDrawEnabled?: boolean;
|
||||
}
|
||||
export interface ShapeGetClientRectConfig {
|
||||
skipTransform?: boolean;
|
||||
skipShadow?: boolean;
|
||||
skipStroke?: boolean;
|
||||
relativeTo?: Node;
|
||||
}
|
||||
export declare const shapes: {
|
||||
[key: string]: Shape;
|
||||
};
|
||||
export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Node<Config> {
|
||||
_centroid: boolean;
|
||||
colorKey: string;
|
||||
_fillFunc: (ctx: Context) => void;
|
||||
_strokeFunc: (ctx: Context) => void;
|
||||
_fillFuncHit: (ctx: Context) => void;
|
||||
_strokeFuncHit: (ctx: Context) => void;
|
||||
constructor(config?: Config);
|
||||
getContext(): Context;
|
||||
getCanvas(): SceneCanvas;
|
||||
getSceneFunc(): any;
|
||||
getHitFunc(): any;
|
||||
hasShadow(): any;
|
||||
_hasShadow(): boolean;
|
||||
_getFillPattern(): any;
|
||||
__getFillPattern(): CanvasPattern;
|
||||
_getLinearGradient(): any;
|
||||
__getLinearGradient(): CanvasGradient;
|
||||
_getRadialGradient(): any;
|
||||
__getRadialGradient(): CanvasGradient;
|
||||
getShadowRGBA(): any;
|
||||
_getShadowRGBA(): string;
|
||||
hasFill(): any;
|
||||
hasStroke(): any;
|
||||
hasHitStroke(): any;
|
||||
intersects(point: any): boolean;
|
||||
destroy(): this;
|
||||
_useBufferCanvas(forceFill?: boolean): boolean;
|
||||
setStrokeHitEnabled(val: number): void;
|
||||
getStrokeHitEnabled(): boolean;
|
||||
getSelfRect(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
getClientRect(config?: ShapeGetClientRectConfig): {
|
||||
width: number;
|
||||
height: number;
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
drawScene(can?: SceneCanvas, top?: Node): this;
|
||||
drawHit(can?: HitCanvas, top?: Node, skipDragCheck?: boolean): this;
|
||||
drawHitFromCache(alphaThreshold?: number): this;
|
||||
hasPointerCapture(pointerId: number): boolean;
|
||||
setPointerCapture(pointerId: number): void;
|
||||
releaseCapture(pointerId: number): void;
|
||||
draggable: GetSet<boolean, this>;
|
||||
embossBlend: GetSet<boolean, this>;
|
||||
dash: GetSet<number[], this>;
|
||||
dashEnabled: GetSet<boolean, this>;
|
||||
dashOffset: GetSet<number, this>;
|
||||
fill: GetSet<string, this>;
|
||||
fillEnabled: GetSet<boolean, this>;
|
||||
fillLinearGradientColorStops: GetSet<Array<number | string>, this>;
|
||||
fillLinearGradientStartPoint: GetSet<Vector2d, this>;
|
||||
fillLinearGradientStartPointX: GetSet<number, this>;
|
||||
fillLinearGradientStartPointY: GetSet<number, this>;
|
||||
fillLinearGradientEndPoint: GetSet<Vector2d, this>;
|
||||
fillLinearGradientEndPointX: GetSet<number, this>;
|
||||
fillLinearGradientEndPointY: GetSet<number, this>;
|
||||
fillLinearRadialStartPoint: GetSet<Vector2d, this>;
|
||||
fillLinearRadialStartPointX: GetSet<number, this>;
|
||||
fillLinearRadialStartPointY: GetSet<number, this>;
|
||||
fillLinearRadialEndPoint: GetSet<Vector2d, this>;
|
||||
fillLinearRadialEndPointX: GetSet<number, this>;
|
||||
fillLinearRadialEndPointY: GetSet<number, this>;
|
||||
fillPatternImage: GetSet<HTMLImageElement | HTMLCanvasElement, this>;
|
||||
fillRadialGradientStartRadius: GetSet<number, this>;
|
||||
fillRadialGradientEndRadius: GetSet<number, this>;
|
||||
fillRadialGradientColorStops: GetSet<Array<number | string>, this>;
|
||||
fillRadialGradientStartPoint: GetSet<Vector2d, this>;
|
||||
fillRadialGradientStartPointX: GetSet<number, this>;
|
||||
fillRadialGradientStartPointY: GetSet<number, this>;
|
||||
fillRadialGradientEndPoint: GetSet<Vector2d, this>;
|
||||
fillRadialGradientEndPointX: GetSet<number, this>;
|
||||
fillRadialGradientEndPointY: GetSet<number, this>;
|
||||
fillPatternOffset: GetSet<Vector2d, this>;
|
||||
fillPatternOffsetX: GetSet<number, this>;
|
||||
fillPatternOffsetY: GetSet<number, this>;
|
||||
fillPatternRepeat: GetSet<string, this>;
|
||||
fillPatternRotation: GetSet<number, this>;
|
||||
fillPatternScale: GetSet<Vector2d, this>;
|
||||
fillPatternScaleX: GetSet<number, this>;
|
||||
fillPatternScaleY: GetSet<number, this>;
|
||||
fillPatternX: GetSet<number, this>;
|
||||
fillPatternY: GetSet<number, this>;
|
||||
fillPriority: GetSet<string, this>;
|
||||
hitFunc: GetSet<ShapeConfigHandler<this>, this>;
|
||||
lineCap: GetSet<LineCap, this>;
|
||||
lineJoin: GetSet<LineJoin, this>;
|
||||
perfectDrawEnabled: GetSet<boolean, this>;
|
||||
sceneFunc: GetSet<ShapeConfigHandler<this>, this>;
|
||||
shadowColor: GetSet<string, this>;
|
||||
shadowEnabled: GetSet<boolean, this>;
|
||||
shadowForStrokeEnabled: GetSet<boolean, this>;
|
||||
shadowOffset: GetSet<Vector2d, this>;
|
||||
shadowOffsetX: GetSet<number, this>;
|
||||
shadowOffsetY: GetSet<number, this>;
|
||||
shadowOpacity: GetSet<number, this>;
|
||||
shadowBlur: GetSet<number, this>;
|
||||
stroke: GetSet<string, this>;
|
||||
strokeEnabled: GetSet<boolean, this>;
|
||||
fillAfterStrokeEnabled: GetSet<boolean, this>;
|
||||
strokeScaleEnabled: GetSet<boolean, this>;
|
||||
strokeHitEnabled: GetSet<boolean, this>;
|
||||
strokeWidth: GetSet<number, this>;
|
||||
hitStrokeWidth: GetSet<number | 'auto', this>;
|
||||
strokeLinearGradientColorStops: GetSet<Array<number | string>, this>;
|
||||
}
|
||||
519
node_modules/konva/cmj/Shape.js
generated
vendored
Normal file
519
node_modules/konva/cmj/Shape.js
generated
vendored
Normal file
@@ -0,0 +1,519 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Shape = exports.shapes = void 0;
|
||||
const Global_1 = require("./Global");
|
||||
const Util_1 = require("./Util");
|
||||
const Factory_1 = require("./Factory");
|
||||
const Node_1 = require("./Node");
|
||||
const Validators_1 = require("./Validators");
|
||||
const Global_2 = require("./Global");
|
||||
const PointerEvents = require("./PointerEvents");
|
||||
var HAS_SHADOW = 'hasShadow';
|
||||
var SHADOW_RGBA = 'shadowRGBA';
|
||||
var patternImage = 'patternImage';
|
||||
var linearGradient = 'linearGradient';
|
||||
var radialGradient = 'radialGradient';
|
||||
let dummyContext;
|
||||
function getDummyContext() {
|
||||
if (dummyContext) {
|
||||
return dummyContext;
|
||||
}
|
||||
dummyContext = Util_1.Util.createCanvasElement().getContext('2d');
|
||||
return dummyContext;
|
||||
}
|
||||
exports.shapes = {};
|
||||
function _fillFunc(context) {
|
||||
context.fill();
|
||||
}
|
||||
function _strokeFunc(context) {
|
||||
context.stroke();
|
||||
}
|
||||
function _fillFuncHit(context) {
|
||||
context.fill();
|
||||
}
|
||||
function _strokeFuncHit(context) {
|
||||
context.stroke();
|
||||
}
|
||||
function _clearHasShadowCache() {
|
||||
this._clearCache(HAS_SHADOW);
|
||||
}
|
||||
function _clearGetShadowRGBACache() {
|
||||
this._clearCache(SHADOW_RGBA);
|
||||
}
|
||||
function _clearFillPatternCache() {
|
||||
this._clearCache(patternImage);
|
||||
}
|
||||
function _clearLinearGradientCache() {
|
||||
this._clearCache(linearGradient);
|
||||
}
|
||||
function _clearRadialGradientCache() {
|
||||
this._clearCache(radialGradient);
|
||||
}
|
||||
class Shape extends Node_1.Node {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
let key;
|
||||
while (true) {
|
||||
key = Util_1.Util.getRandomColor();
|
||||
if (key && !(key in exports.shapes)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.colorKey = key;
|
||||
exports.shapes[key] = this;
|
||||
}
|
||||
getContext() {
|
||||
Util_1.Util.warn('shape.getContext() method is deprecated. Please do not use it.');
|
||||
return this.getLayer().getContext();
|
||||
}
|
||||
getCanvas() {
|
||||
Util_1.Util.warn('shape.getCanvas() method is deprecated. Please do not use it.');
|
||||
return this.getLayer().getCanvas();
|
||||
}
|
||||
getSceneFunc() {
|
||||
return this.attrs.sceneFunc || this['_sceneFunc'];
|
||||
}
|
||||
getHitFunc() {
|
||||
return this.attrs.hitFunc || this['_hitFunc'];
|
||||
}
|
||||
hasShadow() {
|
||||
return this._getCache(HAS_SHADOW, this._hasShadow);
|
||||
}
|
||||
_hasShadow() {
|
||||
return (this.shadowEnabled() &&
|
||||
this.shadowOpacity() !== 0 &&
|
||||
!!(this.shadowColor() ||
|
||||
this.shadowBlur() ||
|
||||
this.shadowOffsetX() ||
|
||||
this.shadowOffsetY()));
|
||||
}
|
||||
_getFillPattern() {
|
||||
return this._getCache(patternImage, this.__getFillPattern);
|
||||
}
|
||||
__getFillPattern() {
|
||||
if (this.fillPatternImage()) {
|
||||
var ctx = getDummyContext();
|
||||
const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat');
|
||||
if (pattern && pattern.setTransform) {
|
||||
const tr = new Util_1.Transform();
|
||||
tr.translate(this.fillPatternX(), this.fillPatternY());
|
||||
tr.rotate(Global_1.Konva.getAngle(this.fillPatternRotation()));
|
||||
tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
|
||||
tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
|
||||
const m = tr.getMatrix();
|
||||
pattern.setTransform({
|
||||
a: m[0],
|
||||
b: m[1],
|
||||
c: m[2],
|
||||
d: m[3],
|
||||
e: m[4],
|
||||
f: m[5],
|
||||
});
|
||||
}
|
||||
return pattern;
|
||||
}
|
||||
}
|
||||
_getLinearGradient() {
|
||||
return this._getCache(linearGradient, this.__getLinearGradient);
|
||||
}
|
||||
__getLinearGradient() {
|
||||
var colorStops = this.fillLinearGradientColorStops();
|
||||
if (colorStops) {
|
||||
var ctx = getDummyContext();
|
||||
var start = this.fillLinearGradientStartPoint();
|
||||
var end = this.fillLinearGradientEndPoint();
|
||||
var grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
|
||||
for (var n = 0; n < colorStops.length; n += 2) {
|
||||
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
||||
}
|
||||
return grd;
|
||||
}
|
||||
}
|
||||
_getRadialGradient() {
|
||||
return this._getCache(radialGradient, this.__getRadialGradient);
|
||||
}
|
||||
__getRadialGradient() {
|
||||
var colorStops = this.fillRadialGradientColorStops();
|
||||
if (colorStops) {
|
||||
var ctx = getDummyContext();
|
||||
var start = this.fillRadialGradientStartPoint();
|
||||
var end = this.fillRadialGradientEndPoint();
|
||||
var grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
|
||||
for (var n = 0; n < colorStops.length; n += 2) {
|
||||
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
||||
}
|
||||
return grd;
|
||||
}
|
||||
}
|
||||
getShadowRGBA() {
|
||||
return this._getCache(SHADOW_RGBA, this._getShadowRGBA);
|
||||
}
|
||||
_getShadowRGBA() {
|
||||
if (this.hasShadow()) {
|
||||
var rgba = Util_1.Util.colorToRGBA(this.shadowColor());
|
||||
return ('rgba(' +
|
||||
rgba.r +
|
||||
',' +
|
||||
rgba.g +
|
||||
',' +
|
||||
rgba.b +
|
||||
',' +
|
||||
rgba.a * (this.shadowOpacity() || 1) +
|
||||
')');
|
||||
}
|
||||
}
|
||||
hasFill() {
|
||||
return this._calculate('hasFill', [
|
||||
'fillEnabled',
|
||||
'fill',
|
||||
'fillPatternImage',
|
||||
'fillLinearGradientColorStops',
|
||||
'fillRadialGradientColorStops',
|
||||
], () => {
|
||||
return (this.fillEnabled() &&
|
||||
!!(this.fill() ||
|
||||
this.fillPatternImage() ||
|
||||
this.fillLinearGradientColorStops() ||
|
||||
this.fillRadialGradientColorStops()));
|
||||
});
|
||||
}
|
||||
hasStroke() {
|
||||
return this._calculate('hasStroke', [
|
||||
'strokeEnabled',
|
||||
'strokeWidth',
|
||||
'stroke',
|
||||
'strokeLinearGradientColorStops',
|
||||
], () => {
|
||||
return (this.strokeEnabled() &&
|
||||
this.strokeWidth() &&
|
||||
!!(this.stroke() || this.strokeLinearGradientColorStops()));
|
||||
});
|
||||
}
|
||||
hasHitStroke() {
|
||||
const width = this.hitStrokeWidth();
|
||||
if (width === 'auto') {
|
||||
return this.hasStroke();
|
||||
}
|
||||
return this.strokeEnabled() && !!width;
|
||||
}
|
||||
intersects(point) {
|
||||
var stage = this.getStage(), bufferHitCanvas = stage.bufferHitCanvas, p;
|
||||
bufferHitCanvas.getContext().clear();
|
||||
this.drawHit(bufferHitCanvas, null, true);
|
||||
p = bufferHitCanvas.context.getImageData(Math.round(point.x), Math.round(point.y), 1, 1).data;
|
||||
return p[3] > 0;
|
||||
}
|
||||
destroy() {
|
||||
Node_1.Node.prototype.destroy.call(this);
|
||||
delete exports.shapes[this.colorKey];
|
||||
delete this.colorKey;
|
||||
return this;
|
||||
}
|
||||
_useBufferCanvas(forceFill) {
|
||||
var _a;
|
||||
if (!this.getStage()) {
|
||||
return false;
|
||||
}
|
||||
const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true;
|
||||
if (!perfectDrawEnabled) {
|
||||
return false;
|
||||
}
|
||||
const hasFill = forceFill || this.hasFill();
|
||||
const hasStroke = this.hasStroke();
|
||||
const isTransparent = this.getAbsoluteOpacity() !== 1;
|
||||
if (hasFill && hasStroke && isTransparent) {
|
||||
return true;
|
||||
}
|
||||
const hasShadow = this.hasShadow();
|
||||
const strokeForShadow = this.shadowForStrokeEnabled();
|
||||
if (hasFill && hasStroke && hasShadow && strokeForShadow) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
setStrokeHitEnabled(val) {
|
||||
Util_1.Util.warn('strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead.');
|
||||
if (val) {
|
||||
this.hitStrokeWidth('auto');
|
||||
}
|
||||
else {
|
||||
this.hitStrokeWidth(0);
|
||||
}
|
||||
}
|
||||
getStrokeHitEnabled() {
|
||||
if (this.hitStrokeWidth() === 0) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
getSelfRect() {
|
||||
var size = this.size();
|
||||
return {
|
||||
x: this._centroid ? -size.width / 2 : 0,
|
||||
y: this._centroid ? -size.height / 2 : 0,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
};
|
||||
}
|
||||
getClientRect(config = {}) {
|
||||
const skipTransform = config.skipTransform;
|
||||
const relativeTo = config.relativeTo;
|
||||
const fillRect = this.getSelfRect();
|
||||
const applyStroke = !config.skipStroke && this.hasStroke();
|
||||
const strokeWidth = (applyStroke && this.strokeWidth()) || 0;
|
||||
const fillAndStrokeWidth = fillRect.width + strokeWidth;
|
||||
const fillAndStrokeHeight = fillRect.height + strokeWidth;
|
||||
const applyShadow = !config.skipShadow && this.hasShadow();
|
||||
const shadowOffsetX = applyShadow ? this.shadowOffsetX() : 0;
|
||||
const shadowOffsetY = applyShadow ? this.shadowOffsetY() : 0;
|
||||
const preWidth = fillAndStrokeWidth + Math.abs(shadowOffsetX);
|
||||
const preHeight = fillAndStrokeHeight + Math.abs(shadowOffsetY);
|
||||
const blurRadius = (applyShadow && this.shadowBlur()) || 0;
|
||||
const width = preWidth + blurRadius * 2;
|
||||
const height = preHeight + blurRadius * 2;
|
||||
let roundingOffset = 0;
|
||||
if (Math.round(strokeWidth / 2) !== strokeWidth / 2) {
|
||||
roundingOffset = 1;
|
||||
}
|
||||
const rect = {
|
||||
width: width + roundingOffset,
|
||||
height: height + roundingOffset,
|
||||
x: -Math.round(strokeWidth / 2 + blurRadius) +
|
||||
Math.min(shadowOffsetX, 0) +
|
||||
fillRect.x,
|
||||
y: -Math.round(strokeWidth / 2 + blurRadius) +
|
||||
Math.min(shadowOffsetY, 0) +
|
||||
fillRect.y,
|
||||
};
|
||||
if (!skipTransform) {
|
||||
return this._transformedRect(rect, relativeTo);
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
drawScene(can, top) {
|
||||
var layer = this.getLayer(), canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferCanvas, bufferContext;
|
||||
var skipBuffer = canvas.isCache;
|
||||
var cachingSelf = top === this;
|
||||
if (!this.isVisible() && !cachingSelf) {
|
||||
return this;
|
||||
}
|
||||
if (cachedCanvas) {
|
||||
context.save();
|
||||
var m = this.getAbsoluteTransform(top).getMatrix();
|
||||
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
this._drawCachedSceneCanvas(context);
|
||||
context.restore();
|
||||
return this;
|
||||
}
|
||||
if (!drawFunc) {
|
||||
return this;
|
||||
}
|
||||
context.save();
|
||||
if (this._useBufferCanvas() && !skipBuffer) {
|
||||
stage = this.getStage();
|
||||
bufferCanvas = stage.bufferCanvas;
|
||||
bufferContext = bufferCanvas.getContext();
|
||||
bufferContext.clear();
|
||||
bufferContext.save();
|
||||
bufferContext._applyLineJoin(this);
|
||||
var o = this.getAbsoluteTransform(top).getMatrix();
|
||||
bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
||||
drawFunc.call(this, bufferContext, this);
|
||||
bufferContext.restore();
|
||||
var ratio = bufferCanvas.pixelRatio;
|
||||
if (hasShadow) {
|
||||
context._applyShadow(this);
|
||||
}
|
||||
context._applyOpacity(this);
|
||||
context._applyGlobalCompositeOperation(this);
|
||||
context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
|
||||
}
|
||||
else {
|
||||
context._applyLineJoin(this);
|
||||
if (!cachingSelf) {
|
||||
var o = this.getAbsoluteTransform(top).getMatrix();
|
||||
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
||||
context._applyOpacity(this);
|
||||
context._applyGlobalCompositeOperation(this);
|
||||
}
|
||||
if (hasShadow) {
|
||||
context._applyShadow(this);
|
||||
}
|
||||
drawFunc.call(this, context, this);
|
||||
}
|
||||
context.restore();
|
||||
return this;
|
||||
}
|
||||
drawHit(can, top, skipDragCheck = false) {
|
||||
if (!this.shouldDrawHit(top, skipDragCheck)) {
|
||||
return this;
|
||||
}
|
||||
var layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
||||
if (!this.colorKey) {
|
||||
Util_1.Util.warn('Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()');
|
||||
}
|
||||
if (cachedHitCanvas) {
|
||||
context.save();
|
||||
var m = this.getAbsoluteTransform(top).getMatrix();
|
||||
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
this._drawCachedHitCanvas(context);
|
||||
context.restore();
|
||||
return this;
|
||||
}
|
||||
if (!drawFunc) {
|
||||
return this;
|
||||
}
|
||||
context.save();
|
||||
context._applyLineJoin(this);
|
||||
const selfCache = this === top;
|
||||
if (!selfCache) {
|
||||
var o = this.getAbsoluteTransform(top).getMatrix();
|
||||
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
||||
}
|
||||
drawFunc.call(this, context, this);
|
||||
context.restore();
|
||||
return this;
|
||||
}
|
||||
drawHitFromCache(alphaThreshold = 0) {
|
||||
var cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha;
|
||||
hitContext.clear();
|
||||
hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight);
|
||||
try {
|
||||
hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
|
||||
hitData = hitImageData.data;
|
||||
len = hitData.length;
|
||||
rgbColorKey = Util_1.Util._hexToRgb(this.colorKey);
|
||||
for (i = 0; i < len; i += 4) {
|
||||
alpha = hitData[i + 3];
|
||||
if (alpha > alphaThreshold) {
|
||||
hitData[i] = rgbColorKey.r;
|
||||
hitData[i + 1] = rgbColorKey.g;
|
||||
hitData[i + 2] = rgbColorKey.b;
|
||||
hitData[i + 3] = 255;
|
||||
}
|
||||
else {
|
||||
hitData[i + 3] = 0;
|
||||
}
|
||||
}
|
||||
hitContext.putImageData(hitImageData, 0, 0);
|
||||
}
|
||||
catch (e) {
|
||||
Util_1.Util.error('Unable to draw hit graph from cached scene canvas. ' + e.message);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
hasPointerCapture(pointerId) {
|
||||
return PointerEvents.hasPointerCapture(pointerId, this);
|
||||
}
|
||||
setPointerCapture(pointerId) {
|
||||
PointerEvents.setPointerCapture(pointerId, this);
|
||||
}
|
||||
releaseCapture(pointerId) {
|
||||
PointerEvents.releaseCapture(pointerId, this);
|
||||
}
|
||||
}
|
||||
exports.Shape = Shape;
|
||||
Shape.prototype._fillFunc = _fillFunc;
|
||||
Shape.prototype._strokeFunc = _strokeFunc;
|
||||
Shape.prototype._fillFuncHit = _fillFuncHit;
|
||||
Shape.prototype._strokeFuncHit = _strokeFuncHit;
|
||||
Shape.prototype._centroid = false;
|
||||
Shape.prototype.nodeType = 'Shape';
|
||||
(0, Global_2._registerNode)(Shape);
|
||||
Shape.prototype.eventListeners = {};
|
||||
Shape.prototype.on.call(Shape.prototype, 'shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearHasShadowCache);
|
||||
Shape.prototype.on.call(Shape.prototype, 'shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearGetShadowRGBACache);
|
||||
Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva', _clearFillPatternCache);
|
||||
Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva', _clearLinearGradientCache);
|
||||
Shape.prototype.on.call(Shape.prototype, 'fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva', _clearRadialGradientCache);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'stroke', undefined, (0, Validators_1.getStringOrGradientValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'strokeWidth', 2, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillAfterStrokeEnabled', false);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'hitStrokeWidth', 'auto', (0, Validators_1.getNumberOrAutoValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'strokeHitEnabled', true, (0, Validators_1.getBooleanValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'perfectDrawEnabled', true, (0, Validators_1.getBooleanValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'shadowForStrokeEnabled', true, (0, Validators_1.getBooleanValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'lineJoin');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'lineCap');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'sceneFunc');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'hitFunc');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'dash');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'dashOffset', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'shadowColor', undefined, (0, Validators_1.getStringValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'shadowBlur', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'shadowOpacity', 1, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addComponentsGetterSetter(Shape, 'shadowOffset', ['x', 'y']);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'shadowOffsetX', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'shadowOffsetY', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPatternImage');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fill', undefined, (0, Validators_1.getStringOrGradientValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPatternX', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPatternY', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientColorStops');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientColorStops');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientStartRadius', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndRadius', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientColorStops');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPatternRepeat', 'repeat');
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillEnabled', true);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'strokeEnabled', true);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'shadowEnabled', true);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'dashEnabled', true);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'strokeScaleEnabled', true);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPriority', 'color');
|
||||
Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillPatternOffset', ['x', 'y']);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPatternOffsetX', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPatternOffsetY', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillPatternScale', ['x', 'y']);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPatternScaleX', 1, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPatternScaleY', 1, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillLinearGradientStartPoint', [
|
||||
'x',
|
||||
'y',
|
||||
]);
|
||||
Factory_1.Factory.addComponentsGetterSetter(Shape, 'strokeLinearGradientStartPoint', [
|
||||
'x',
|
||||
'y',
|
||||
]);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientStartPointX', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientStartPointX', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientStartPointY', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientStartPointY', 0);
|
||||
Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillLinearGradientEndPoint', [
|
||||
'x',
|
||||
'y',
|
||||
]);
|
||||
Factory_1.Factory.addComponentsGetterSetter(Shape, 'strokeLinearGradientEndPoint', [
|
||||
'x',
|
||||
'y',
|
||||
]);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientEndPointX', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientEndPointX', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillLinearGradientEndPointY', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'strokeLinearGradientEndPointY', 0);
|
||||
Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillRadialGradientStartPoint', [
|
||||
'x',
|
||||
'y',
|
||||
]);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientStartPointX', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientStartPointY', 0);
|
||||
Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillRadialGradientEndPoint', [
|
||||
'x',
|
||||
'y',
|
||||
]);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointX', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointY', 0);
|
||||
Factory_1.Factory.addGetterSetter(Shape, 'fillPatternRotation', 0);
|
||||
Factory_1.Factory.backCompat(Shape, {
|
||||
dashArray: 'dash',
|
||||
getDashArray: 'getDash',
|
||||
setDashArray: 'getDash',
|
||||
drawFunc: 'sceneFunc',
|
||||
getDrawFunc: 'getSceneFunc',
|
||||
setDrawFunc: 'setSceneFunc',
|
||||
drawHitFunc: 'hitFunc',
|
||||
getDrawHitFunc: 'getHitFunc',
|
||||
setDrawHitFunc: 'setHitFunc',
|
||||
});
|
||||
85
node_modules/konva/cmj/Stage.d.ts
generated
vendored
Normal file
85
node_modules/konva/cmj/Stage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
import { Container, ContainerConfig } from './Container';
|
||||
import { SceneCanvas, HitCanvas } from './Canvas';
|
||||
import { GetSet, Vector2d } from './types';
|
||||
import { Shape } from './Shape';
|
||||
import { Layer } from './Layer';
|
||||
export interface StageConfig extends ContainerConfig {
|
||||
container: HTMLDivElement | string;
|
||||
}
|
||||
export declare const stages: Stage[];
|
||||
export declare class Stage extends Container<Layer> {
|
||||
content: HTMLDivElement;
|
||||
pointerPos: Vector2d | null;
|
||||
_pointerPositions: (Vector2d & {
|
||||
id?: number;
|
||||
})[];
|
||||
_changedPointerPositions: (Vector2d & {
|
||||
id: number;
|
||||
})[];
|
||||
bufferCanvas: SceneCanvas;
|
||||
bufferHitCanvas: HitCanvas;
|
||||
_mouseTargetShape: Shape;
|
||||
_touchTargetShape: Shape;
|
||||
_pointerTargetShape: Shape;
|
||||
_mouseClickStartShape: Shape;
|
||||
_touchClickStartShape: Shape;
|
||||
_pointerClickStartShape: Shape;
|
||||
_mouseClickEndShape: Shape;
|
||||
_touchClickEndShape: Shape;
|
||||
_pointerClickEndShape: Shape;
|
||||
_mouseDblTimeout: any;
|
||||
_touchDblTimeout: any;
|
||||
_pointerDblTimeout: any;
|
||||
constructor(config: StageConfig);
|
||||
_validateAdd(child: any): void;
|
||||
_checkVisibility(): void;
|
||||
setContainer(container: any): this;
|
||||
shouldDrawHit(): boolean;
|
||||
clear(): this;
|
||||
clone(obj?: any): any;
|
||||
destroy(): this;
|
||||
getPointerPosition(): Vector2d | null;
|
||||
_getPointerById(id?: number): Vector2d & {
|
||||
id?: number;
|
||||
};
|
||||
getPointersPositions(): (Vector2d & {
|
||||
id?: number;
|
||||
})[];
|
||||
getStage(): this;
|
||||
getContent(): HTMLDivElement;
|
||||
_toKonvaCanvas(config: any): SceneCanvas;
|
||||
getIntersection(pos: Vector2d): Shape<import("./Shape").ShapeConfig>;
|
||||
_resizeDOM(): void;
|
||||
add(layer: Layer, ...rest: any[]): this;
|
||||
getParent(): any;
|
||||
getLayer(): any;
|
||||
hasPointerCapture(pointerId: number): boolean;
|
||||
setPointerCapture(pointerId: number): void;
|
||||
releaseCapture(pointerId: number): void;
|
||||
getLayers(): Layer[];
|
||||
_bindContentEvents(): void;
|
||||
_pointerenter(evt: any): void;
|
||||
_pointerover(evt: any): void;
|
||||
_getTargetShape(evenType: any): Shape<import("./Shape").ShapeConfig>;
|
||||
_pointerleave(evt: any): void;
|
||||
_pointerdown(evt: TouchEvent | MouseEvent | PointerEvent): void;
|
||||
_pointermove(evt: TouchEvent | MouseEvent | PointerEvent): void;
|
||||
_pointerup(evt: any): void;
|
||||
_contextmenu(evt: any): void;
|
||||
_wheel(evt: any): void;
|
||||
_pointercancel(evt: PointerEvent): void;
|
||||
_lostpointercapture(evt: PointerEvent): void;
|
||||
setPointersPositions(evt: any): void;
|
||||
_setPointerPosition(evt: any): void;
|
||||
_getContentPosition(): {
|
||||
top: number;
|
||||
left: number;
|
||||
scaleX: number;
|
||||
scaleY: number;
|
||||
};
|
||||
_buildDOM(): void;
|
||||
cache(): this;
|
||||
clearCache(): this;
|
||||
batchDraw(): this;
|
||||
container: GetSet<HTMLDivElement, this>;
|
||||
}
|
||||
693
node_modules/konva/cmj/Stage.js
generated
vendored
Normal file
693
node_modules/konva/cmj/Stage.js
generated
vendored
Normal file
@@ -0,0 +1,693 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Stage = exports.stages = void 0;
|
||||
const Util_1 = require("./Util");
|
||||
const Factory_1 = require("./Factory");
|
||||
const Container_1 = require("./Container");
|
||||
const Global_1 = require("./Global");
|
||||
const Canvas_1 = require("./Canvas");
|
||||
const DragAndDrop_1 = require("./DragAndDrop");
|
||||
const Global_2 = require("./Global");
|
||||
const PointerEvents = require("./PointerEvents");
|
||||
var STAGE = 'Stage', STRING = 'string', PX = 'px', MOUSEOUT = 'mouseout', MOUSELEAVE = 'mouseleave', MOUSEOVER = 'mouseover', MOUSEENTER = 'mouseenter', MOUSEMOVE = 'mousemove', MOUSEDOWN = 'mousedown', MOUSEUP = 'mouseup', POINTERMOVE = 'pointermove', POINTERDOWN = 'pointerdown', POINTERUP = 'pointerup', POINTERCANCEL = 'pointercancel', LOSTPOINTERCAPTURE = 'lostpointercapture', POINTEROUT = 'pointerout', POINTERLEAVE = 'pointerleave', POINTEROVER = 'pointerover', POINTERENTER = 'pointerenter', CONTEXTMENU = 'contextmenu', TOUCHSTART = 'touchstart', TOUCHEND = 'touchend', TOUCHMOVE = 'touchmove', TOUCHCANCEL = 'touchcancel', WHEEL = 'wheel', MAX_LAYERS_NUMBER = 5, EVENTS = [
|
||||
[MOUSEENTER, '_pointerenter'],
|
||||
[MOUSEDOWN, '_pointerdown'],
|
||||
[MOUSEMOVE, '_pointermove'],
|
||||
[MOUSEUP, '_pointerup'],
|
||||
[MOUSELEAVE, '_pointerleave'],
|
||||
[TOUCHSTART, '_pointerdown'],
|
||||
[TOUCHMOVE, '_pointermove'],
|
||||
[TOUCHEND, '_pointerup'],
|
||||
[TOUCHCANCEL, '_pointercancel'],
|
||||
[MOUSEOVER, '_pointerover'],
|
||||
[WHEEL, '_wheel'],
|
||||
[CONTEXTMENU, '_contextmenu'],
|
||||
[POINTERDOWN, '_pointerdown'],
|
||||
[POINTERMOVE, '_pointermove'],
|
||||
[POINTERUP, '_pointerup'],
|
||||
[POINTERCANCEL, '_pointercancel'],
|
||||
[LOSTPOINTERCAPTURE, '_lostpointercapture'],
|
||||
];
|
||||
const EVENTS_MAP = {
|
||||
mouse: {
|
||||
[POINTEROUT]: MOUSEOUT,
|
||||
[POINTERLEAVE]: MOUSELEAVE,
|
||||
[POINTEROVER]: MOUSEOVER,
|
||||
[POINTERENTER]: MOUSEENTER,
|
||||
[POINTERMOVE]: MOUSEMOVE,
|
||||
[POINTERDOWN]: MOUSEDOWN,
|
||||
[POINTERUP]: MOUSEUP,
|
||||
[POINTERCANCEL]: 'mousecancel',
|
||||
pointerclick: 'click',
|
||||
pointerdblclick: 'dblclick',
|
||||
},
|
||||
touch: {
|
||||
[POINTEROUT]: 'touchout',
|
||||
[POINTERLEAVE]: 'touchleave',
|
||||
[POINTEROVER]: 'touchover',
|
||||
[POINTERENTER]: 'touchenter',
|
||||
[POINTERMOVE]: TOUCHMOVE,
|
||||
[POINTERDOWN]: TOUCHSTART,
|
||||
[POINTERUP]: TOUCHEND,
|
||||
[POINTERCANCEL]: TOUCHCANCEL,
|
||||
pointerclick: 'tap',
|
||||
pointerdblclick: 'dbltap',
|
||||
},
|
||||
pointer: {
|
||||
[POINTEROUT]: POINTEROUT,
|
||||
[POINTERLEAVE]: POINTERLEAVE,
|
||||
[POINTEROVER]: POINTEROVER,
|
||||
[POINTERENTER]: POINTERENTER,
|
||||
[POINTERMOVE]: POINTERMOVE,
|
||||
[POINTERDOWN]: POINTERDOWN,
|
||||
[POINTERUP]: POINTERUP,
|
||||
[POINTERCANCEL]: POINTERCANCEL,
|
||||
pointerclick: 'pointerclick',
|
||||
pointerdblclick: 'pointerdblclick',
|
||||
},
|
||||
};
|
||||
const getEventType = (type) => {
|
||||
if (type.indexOf('pointer') >= 0) {
|
||||
return 'pointer';
|
||||
}
|
||||
if (type.indexOf('touch') >= 0) {
|
||||
return 'touch';
|
||||
}
|
||||
return 'mouse';
|
||||
};
|
||||
const getEventsMap = (eventType) => {
|
||||
const type = getEventType(eventType);
|
||||
if (type === 'pointer') {
|
||||
return Global_1.Konva.pointerEventsEnabled && EVENTS_MAP.pointer;
|
||||
}
|
||||
if (type === 'touch') {
|
||||
return EVENTS_MAP.touch;
|
||||
}
|
||||
if (type === 'mouse') {
|
||||
return EVENTS_MAP.mouse;
|
||||
}
|
||||
};
|
||||
function checkNoClip(attrs = {}) {
|
||||
if (attrs.clipFunc || attrs.clipWidth || attrs.clipHeight) {
|
||||
Util_1.Util.warn('Stage does not support clipping. Please use clip for Layers or Groups.');
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
const NO_POINTERS_MESSAGE = `Pointer position is missing and not registered by the stage. Looks like it is outside of the stage container. You can set it manually from event: stage.setPointersPositions(event);`;
|
||||
exports.stages = [];
|
||||
class Stage extends Container_1.Container {
|
||||
constructor(config) {
|
||||
super(checkNoClip(config));
|
||||
this._pointerPositions = [];
|
||||
this._changedPointerPositions = [];
|
||||
this._buildDOM();
|
||||
this._bindContentEvents();
|
||||
exports.stages.push(this);
|
||||
this.on('widthChange.konva heightChange.konva', this._resizeDOM);
|
||||
this.on('visibleChange.konva', this._checkVisibility);
|
||||
this.on('clipWidthChange.konva clipHeightChange.konva clipFuncChange.konva', () => {
|
||||
checkNoClip(this.attrs);
|
||||
});
|
||||
this._checkVisibility();
|
||||
}
|
||||
_validateAdd(child) {
|
||||
const isLayer = child.getType() === 'Layer';
|
||||
const isFastLayer = child.getType() === 'FastLayer';
|
||||
const valid = isLayer || isFastLayer;
|
||||
if (!valid) {
|
||||
Util_1.Util.throw('You may only add layers to the stage.');
|
||||
}
|
||||
}
|
||||
_checkVisibility() {
|
||||
if (!this.content) {
|
||||
return;
|
||||
}
|
||||
const style = this.visible() ? '' : 'none';
|
||||
this.content.style.display = style;
|
||||
}
|
||||
setContainer(container) {
|
||||
if (typeof container === STRING) {
|
||||
if (container.charAt(0) === '.') {
|
||||
var className = container.slice(1);
|
||||
container = document.getElementsByClassName(className)[0];
|
||||
}
|
||||
else {
|
||||
var id;
|
||||
if (container.charAt(0) !== '#') {
|
||||
id = container;
|
||||
}
|
||||
else {
|
||||
id = container.slice(1);
|
||||
}
|
||||
container = document.getElementById(id);
|
||||
}
|
||||
if (!container) {
|
||||
throw 'Can not find container in document with id ' + id;
|
||||
}
|
||||
}
|
||||
this._setAttr('container', container);
|
||||
if (this.content) {
|
||||
if (this.content.parentElement) {
|
||||
this.content.parentElement.removeChild(this.content);
|
||||
}
|
||||
container.appendChild(this.content);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
shouldDrawHit() {
|
||||
return true;
|
||||
}
|
||||
clear() {
|
||||
var layers = this.children, len = layers.length, n;
|
||||
for (n = 0; n < len; n++) {
|
||||
layers[n].clear();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
clone(obj) {
|
||||
if (!obj) {
|
||||
obj = {};
|
||||
}
|
||||
obj.container =
|
||||
typeof document !== 'undefined' && document.createElement('div');
|
||||
return Container_1.Container.prototype.clone.call(this, obj);
|
||||
}
|
||||
destroy() {
|
||||
super.destroy();
|
||||
var content = this.content;
|
||||
if (content && Util_1.Util._isInDocument(content)) {
|
||||
this.container().removeChild(content);
|
||||
}
|
||||
var index = exports.stages.indexOf(this);
|
||||
if (index > -1) {
|
||||
exports.stages.splice(index, 1);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
getPointerPosition() {
|
||||
const pos = this._pointerPositions[0] || this._changedPointerPositions[0];
|
||||
if (!pos) {
|
||||
Util_1.Util.warn(NO_POINTERS_MESSAGE);
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
};
|
||||
}
|
||||
_getPointerById(id) {
|
||||
return this._pointerPositions.find((p) => p.id === id);
|
||||
}
|
||||
getPointersPositions() {
|
||||
return this._pointerPositions;
|
||||
}
|
||||
getStage() {
|
||||
return this;
|
||||
}
|
||||
getContent() {
|
||||
return this.content;
|
||||
}
|
||||
_toKonvaCanvas(config) {
|
||||
config = config || {};
|
||||
config.x = config.x || 0;
|
||||
config.y = config.y || 0;
|
||||
config.width = config.width || this.width();
|
||||
config.height = config.height || this.height();
|
||||
var canvas = new Canvas_1.SceneCanvas({
|
||||
width: config.width,
|
||||
height: config.height,
|
||||
pixelRatio: config.pixelRatio || 1,
|
||||
});
|
||||
var _context = canvas.getContext()._context;
|
||||
var layers = this.children;
|
||||
if (config.x || config.y) {
|
||||
_context.translate(-1 * config.x, -1 * config.y);
|
||||
}
|
||||
layers.forEach(function (layer) {
|
||||
if (!layer.isVisible()) {
|
||||
return;
|
||||
}
|
||||
var layerCanvas = layer._toKonvaCanvas(config);
|
||||
_context.drawImage(layerCanvas._canvas, config.x, config.y, layerCanvas.getWidth() / layerCanvas.getPixelRatio(), layerCanvas.getHeight() / layerCanvas.getPixelRatio());
|
||||
});
|
||||
return canvas;
|
||||
}
|
||||
getIntersection(pos) {
|
||||
if (!pos) {
|
||||
return null;
|
||||
}
|
||||
var layers = this.children, len = layers.length, end = len - 1, n;
|
||||
for (n = end; n >= 0; n--) {
|
||||
const shape = layers[n].getIntersection(pos);
|
||||
if (shape) {
|
||||
return shape;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
_resizeDOM() {
|
||||
var width = this.width();
|
||||
var height = this.height();
|
||||
if (this.content) {
|
||||
this.content.style.width = width + PX;
|
||||
this.content.style.height = height + PX;
|
||||
}
|
||||
this.bufferCanvas.setSize(width, height);
|
||||
this.bufferHitCanvas.setSize(width, height);
|
||||
this.children.forEach((layer) => {
|
||||
layer.setSize({ width, height });
|
||||
layer.draw();
|
||||
});
|
||||
}
|
||||
add(layer, ...rest) {
|
||||
if (arguments.length > 1) {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
this.add(arguments[i]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
super.add(layer);
|
||||
var length = this.children.length;
|
||||
if (length > MAX_LAYERS_NUMBER) {
|
||||
Util_1.Util.warn('The stage has ' +
|
||||
length +
|
||||
' layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group.');
|
||||
}
|
||||
layer.setSize({ width: this.width(), height: this.height() });
|
||||
layer.draw();
|
||||
if (Global_1.Konva.isBrowser) {
|
||||
this.content.appendChild(layer.canvas._canvas);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
getParent() {
|
||||
return null;
|
||||
}
|
||||
getLayer() {
|
||||
return null;
|
||||
}
|
||||
hasPointerCapture(pointerId) {
|
||||
return PointerEvents.hasPointerCapture(pointerId, this);
|
||||
}
|
||||
setPointerCapture(pointerId) {
|
||||
PointerEvents.setPointerCapture(pointerId, this);
|
||||
}
|
||||
releaseCapture(pointerId) {
|
||||
PointerEvents.releaseCapture(pointerId, this);
|
||||
}
|
||||
getLayers() {
|
||||
return this.children;
|
||||
}
|
||||
_bindContentEvents() {
|
||||
if (!Global_1.Konva.isBrowser) {
|
||||
return;
|
||||
}
|
||||
EVENTS.forEach(([event, methodName]) => {
|
||||
this.content.addEventListener(event, (evt) => {
|
||||
this[methodName](evt);
|
||||
});
|
||||
});
|
||||
}
|
||||
_pointerenter(evt) {
|
||||
this.setPointersPositions(evt);
|
||||
const events = getEventsMap(evt.type);
|
||||
this._fire(events.pointerenter, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
});
|
||||
}
|
||||
_pointerover(evt) {
|
||||
this.setPointersPositions(evt);
|
||||
const events = getEventsMap(evt.type);
|
||||
this._fire(events.pointerover, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
});
|
||||
}
|
||||
_getTargetShape(evenType) {
|
||||
let shape = this[evenType + 'targetShape'];
|
||||
if (shape && !shape.getStage()) {
|
||||
shape = null;
|
||||
}
|
||||
return shape;
|
||||
}
|
||||
_pointerleave(evt) {
|
||||
const events = getEventsMap(evt.type);
|
||||
const eventType = getEventType(evt.type);
|
||||
if (!events) {
|
||||
return;
|
||||
}
|
||||
this.setPointersPositions(evt);
|
||||
var targetShape = this._getTargetShape(eventType);
|
||||
var eventsEnabled = !DragAndDrop_1.DD.isDragging || Global_1.Konva.hitOnDragEnabled;
|
||||
if (targetShape && eventsEnabled) {
|
||||
targetShape._fireAndBubble(events.pointerout, { evt: evt });
|
||||
targetShape._fireAndBubble(events.pointerleave, { evt: evt });
|
||||
this._fire(events.pointerleave, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
});
|
||||
this[eventType + 'targetShape'] = null;
|
||||
}
|
||||
else if (eventsEnabled) {
|
||||
this._fire(events.pointerleave, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
});
|
||||
this._fire(events.pointerout, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
});
|
||||
}
|
||||
this.pointerPos = undefined;
|
||||
this._pointerPositions = [];
|
||||
}
|
||||
_pointerdown(evt) {
|
||||
const events = getEventsMap(evt.type);
|
||||
const eventType = getEventType(evt.type);
|
||||
if (!events) {
|
||||
return;
|
||||
}
|
||||
this.setPointersPositions(evt);
|
||||
var triggeredOnShape = false;
|
||||
this._changedPointerPositions.forEach((pos) => {
|
||||
var shape = this.getIntersection(pos);
|
||||
DragAndDrop_1.DD.justDragged = false;
|
||||
Global_1.Konva['_' + eventType + 'ListenClick'] = true;
|
||||
const hasShape = shape && shape.isListening();
|
||||
if (!hasShape) {
|
||||
return;
|
||||
}
|
||||
if (Global_1.Konva.capturePointerEventsEnabled) {
|
||||
shape.setPointerCapture(pos.id);
|
||||
}
|
||||
this[eventType + 'ClickStartShape'] = shape;
|
||||
shape._fireAndBubble(events.pointerdown, {
|
||||
evt: evt,
|
||||
pointerId: pos.id,
|
||||
});
|
||||
triggeredOnShape = true;
|
||||
const isTouch = evt.type.indexOf('touch') >= 0;
|
||||
if (shape.preventDefault() && evt.cancelable && isTouch) {
|
||||
evt.preventDefault();
|
||||
}
|
||||
});
|
||||
if (!triggeredOnShape) {
|
||||
this._fire(events.pointerdown, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
pointerId: this._pointerPositions[0].id,
|
||||
});
|
||||
}
|
||||
}
|
||||
_pointermove(evt) {
|
||||
const events = getEventsMap(evt.type);
|
||||
const eventType = getEventType(evt.type);
|
||||
if (!events) {
|
||||
return;
|
||||
}
|
||||
if (DragAndDrop_1.DD.isDragging && DragAndDrop_1.DD.node.preventDefault() && evt.cancelable) {
|
||||
evt.preventDefault();
|
||||
}
|
||||
this.setPointersPositions(evt);
|
||||
var eventsEnabled = !DragAndDrop_1.DD.isDragging || Global_1.Konva.hitOnDragEnabled;
|
||||
if (!eventsEnabled) {
|
||||
return;
|
||||
}
|
||||
var processedShapesIds = {};
|
||||
let triggeredOnShape = false;
|
||||
var targetShape = this._getTargetShape(eventType);
|
||||
this._changedPointerPositions.forEach((pos) => {
|
||||
const shape = (PointerEvents.getCapturedShape(pos.id) ||
|
||||
this.getIntersection(pos));
|
||||
const pointerId = pos.id;
|
||||
const event = { evt: evt, pointerId };
|
||||
var differentTarget = targetShape !== shape;
|
||||
if (differentTarget && targetShape) {
|
||||
targetShape._fireAndBubble(events.pointerout, Object.assign({}, event), shape);
|
||||
targetShape._fireAndBubble(events.pointerleave, Object.assign({}, event), shape);
|
||||
}
|
||||
if (shape) {
|
||||
if (processedShapesIds[shape._id]) {
|
||||
return;
|
||||
}
|
||||
processedShapesIds[shape._id] = true;
|
||||
}
|
||||
if (shape && shape.isListening()) {
|
||||
triggeredOnShape = true;
|
||||
if (differentTarget) {
|
||||
shape._fireAndBubble(events.pointerover, Object.assign({}, event), targetShape);
|
||||
shape._fireAndBubble(events.pointerenter, Object.assign({}, event), targetShape);
|
||||
this[eventType + 'targetShape'] = shape;
|
||||
}
|
||||
shape._fireAndBubble(events.pointermove, Object.assign({}, event));
|
||||
}
|
||||
else {
|
||||
if (targetShape) {
|
||||
this._fire(events.pointerover, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
pointerId,
|
||||
});
|
||||
this[eventType + 'targetShape'] = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!triggeredOnShape) {
|
||||
this._fire(events.pointermove, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
pointerId: this._changedPointerPositions[0].id,
|
||||
});
|
||||
}
|
||||
}
|
||||
_pointerup(evt) {
|
||||
const events = getEventsMap(evt.type);
|
||||
const eventType = getEventType(evt.type);
|
||||
if (!events) {
|
||||
return;
|
||||
}
|
||||
this.setPointersPositions(evt);
|
||||
const clickStartShape = this[eventType + 'ClickStartShape'];
|
||||
const clickEndShape = this[eventType + 'ClickEndShape'];
|
||||
var processedShapesIds = {};
|
||||
let triggeredOnShape = false;
|
||||
this._changedPointerPositions.forEach((pos) => {
|
||||
const shape = (PointerEvents.getCapturedShape(pos.id) ||
|
||||
this.getIntersection(pos));
|
||||
if (shape) {
|
||||
shape.releaseCapture(pos.id);
|
||||
if (processedShapesIds[shape._id]) {
|
||||
return;
|
||||
}
|
||||
processedShapesIds[shape._id] = true;
|
||||
}
|
||||
const pointerId = pos.id;
|
||||
const event = { evt: evt, pointerId };
|
||||
let fireDblClick = false;
|
||||
if (Global_1.Konva['_' + eventType + 'InDblClickWindow'] &&
|
||||
Global_1.Konva['_' + eventType + 'InDblClickWindowId'] === pointerId) {
|
||||
fireDblClick = true;
|
||||
clearTimeout(this[eventType + 'DblTimeout']);
|
||||
}
|
||||
else if (!DragAndDrop_1.DD.justDragged) {
|
||||
Global_1.Konva['_' + eventType + 'InDblClickWindow'] = true;
|
||||
Global_1.Konva['_' + eventType + 'InDblClickWindowId'] = pointerId;
|
||||
clearTimeout(this[eventType + 'DblTimeout']);
|
||||
}
|
||||
this[eventType + 'DblTimeout'] = setTimeout(function () {
|
||||
Global_1.Konva['_' + eventType + 'InDblClickWindow'] = false;
|
||||
}, Global_1.Konva.dblClickWindow);
|
||||
if (shape && shape.isListening()) {
|
||||
triggeredOnShape = true;
|
||||
this[eventType + 'ClickEndShape'] = shape;
|
||||
shape._fireAndBubble(events.pointerup, Object.assign({}, event));
|
||||
if (Global_1.Konva['_' + eventType + 'ListenClick'] &&
|
||||
clickStartShape &&
|
||||
clickStartShape === shape) {
|
||||
shape._fireAndBubble(events.pointerclick, Object.assign({}, event));
|
||||
if (fireDblClick && clickEndShape && clickEndShape === shape) {
|
||||
shape._fireAndBubble(events.pointerdblclick, Object.assign({}, event));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this[eventType + 'ClickEndShape'] = null;
|
||||
if (Global_1.Konva['_' + eventType + 'ListenClick']) {
|
||||
this._fire(events.pointerclick, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
pointerId,
|
||||
});
|
||||
}
|
||||
if (fireDblClick) {
|
||||
this._fire(events.pointerdblclick, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
pointerId,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!triggeredOnShape) {
|
||||
this._fire(events.pointerup, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
pointerId: this._changedPointerPositions[0].id,
|
||||
});
|
||||
}
|
||||
Global_1.Konva['_' + eventType + 'ListenClick'] = false;
|
||||
if (evt.cancelable) {
|
||||
evt.preventDefault();
|
||||
}
|
||||
}
|
||||
_contextmenu(evt) {
|
||||
this.setPointersPositions(evt);
|
||||
var shape = this.getIntersection(this.getPointerPosition());
|
||||
if (shape && shape.isListening()) {
|
||||
shape._fireAndBubble(CONTEXTMENU, { evt: evt });
|
||||
}
|
||||
else {
|
||||
this._fire(CONTEXTMENU, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
});
|
||||
}
|
||||
}
|
||||
_wheel(evt) {
|
||||
this.setPointersPositions(evt);
|
||||
var shape = this.getIntersection(this.getPointerPosition());
|
||||
if (shape && shape.isListening()) {
|
||||
shape._fireAndBubble(WHEEL, { evt: evt });
|
||||
}
|
||||
else {
|
||||
this._fire(WHEEL, {
|
||||
evt: evt,
|
||||
target: this,
|
||||
currentTarget: this,
|
||||
});
|
||||
}
|
||||
}
|
||||
_pointercancel(evt) {
|
||||
this.setPointersPositions(evt);
|
||||
const shape = PointerEvents.getCapturedShape(evt.pointerId) ||
|
||||
this.getIntersection(this.getPointerPosition());
|
||||
if (shape) {
|
||||
shape._fireAndBubble(POINTERUP, PointerEvents.createEvent(evt));
|
||||
}
|
||||
PointerEvents.releaseCapture(evt.pointerId);
|
||||
}
|
||||
_lostpointercapture(evt) {
|
||||
PointerEvents.releaseCapture(evt.pointerId);
|
||||
}
|
||||
setPointersPositions(evt) {
|
||||
var contentPosition = this._getContentPosition(), x = null, y = null;
|
||||
evt = evt ? evt : window.event;
|
||||
if (evt.touches !== undefined) {
|
||||
this._pointerPositions = [];
|
||||
this._changedPointerPositions = [];
|
||||
Array.prototype.forEach.call(evt.touches, (touch) => {
|
||||
this._pointerPositions.push({
|
||||
id: touch.identifier,
|
||||
x: (touch.clientX - contentPosition.left) / contentPosition.scaleX,
|
||||
y: (touch.clientY - contentPosition.top) / contentPosition.scaleY,
|
||||
});
|
||||
});
|
||||
Array.prototype.forEach.call(evt.changedTouches || evt.touches, (touch) => {
|
||||
this._changedPointerPositions.push({
|
||||
id: touch.identifier,
|
||||
x: (touch.clientX - contentPosition.left) / contentPosition.scaleX,
|
||||
y: (touch.clientY - contentPosition.top) / contentPosition.scaleY,
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
x = (evt.clientX - contentPosition.left) / contentPosition.scaleX;
|
||||
y = (evt.clientY - contentPosition.top) / contentPosition.scaleY;
|
||||
this.pointerPos = {
|
||||
x: x,
|
||||
y: y,
|
||||
};
|
||||
this._pointerPositions = [{ x, y, id: Util_1.Util._getFirstPointerId(evt) }];
|
||||
this._changedPointerPositions = [
|
||||
{ x, y, id: Util_1.Util._getFirstPointerId(evt) },
|
||||
];
|
||||
}
|
||||
}
|
||||
_setPointerPosition(evt) {
|
||||
Util_1.Util.warn('Method _setPointerPosition is deprecated. Use "stage.setPointersPositions(event)" instead.');
|
||||
this.setPointersPositions(evt);
|
||||
}
|
||||
_getContentPosition() {
|
||||
if (!this.content || !this.content.getBoundingClientRect) {
|
||||
return {
|
||||
top: 0,
|
||||
left: 0,
|
||||
scaleX: 1,
|
||||
scaleY: 1,
|
||||
};
|
||||
}
|
||||
var rect = this.content.getBoundingClientRect();
|
||||
return {
|
||||
top: rect.top,
|
||||
left: rect.left,
|
||||
scaleX: rect.width / this.content.clientWidth || 1,
|
||||
scaleY: rect.height / this.content.clientHeight || 1,
|
||||
};
|
||||
}
|
||||
_buildDOM() {
|
||||
this.bufferCanvas = new Canvas_1.SceneCanvas({
|
||||
width: this.width(),
|
||||
height: this.height(),
|
||||
});
|
||||
this.bufferHitCanvas = new Canvas_1.HitCanvas({
|
||||
pixelRatio: 1,
|
||||
width: this.width(),
|
||||
height: this.height(),
|
||||
});
|
||||
if (!Global_1.Konva.isBrowser) {
|
||||
return;
|
||||
}
|
||||
var container = this.container();
|
||||
if (!container) {
|
||||
throw 'Stage has no container. A container is required.';
|
||||
}
|
||||
container.innerHTML = '';
|
||||
this.content = document.createElement('div');
|
||||
this.content.style.position = 'relative';
|
||||
this.content.style.userSelect = 'none';
|
||||
this.content.className = 'konvajs-content';
|
||||
this.content.setAttribute('role', 'presentation');
|
||||
container.appendChild(this.content);
|
||||
this._resizeDOM();
|
||||
}
|
||||
cache() {
|
||||
Util_1.Util.warn('Cache function is not allowed for stage. You may use cache only for layers, groups and shapes.');
|
||||
return this;
|
||||
}
|
||||
clearCache() {
|
||||
return this;
|
||||
}
|
||||
batchDraw() {
|
||||
this.getChildren().forEach(function (layer) {
|
||||
layer.batchDraw();
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
exports.Stage = Stage;
|
||||
Stage.prototype.nodeType = STAGE;
|
||||
(0, Global_2._registerNode)(Stage);
|
||||
Factory_1.Factory.addGetterSetter(Stage, 'container');
|
||||
86
node_modules/konva/cmj/Tween.d.ts
generated
vendored
Normal file
86
node_modules/konva/cmj/Tween.d.ts
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
import { Animation } from './Animation';
|
||||
import { Node, NodeConfig } from './Node';
|
||||
declare class TweenEngine {
|
||||
prop: string;
|
||||
propFunc: Function;
|
||||
begin: number;
|
||||
_pos: number;
|
||||
duration: number;
|
||||
prevPos: number;
|
||||
yoyo: boolean;
|
||||
_time: number;
|
||||
_position: number;
|
||||
_startTime: number;
|
||||
_finish: number;
|
||||
func: Function;
|
||||
_change: number;
|
||||
state: number;
|
||||
onPlay: Function;
|
||||
onReverse: Function;
|
||||
onPause: Function;
|
||||
onReset: Function;
|
||||
onFinish: Function;
|
||||
onUpdate: Function;
|
||||
constructor(prop: any, propFunc: any, func: any, begin: any, finish: any, duration: any, yoyo: any);
|
||||
fire(str: any): void;
|
||||
setTime(t: any): void;
|
||||
getTime(): number;
|
||||
setPosition(p: any): void;
|
||||
getPosition(t: any): any;
|
||||
play(): void;
|
||||
reverse(): void;
|
||||
seek(t: any): void;
|
||||
reset(): void;
|
||||
finish(): void;
|
||||
update(): void;
|
||||
onEnterFrame(): void;
|
||||
pause(): void;
|
||||
getTimer(): number;
|
||||
}
|
||||
export interface TweenConfig extends NodeConfig {
|
||||
onFinish?: Function;
|
||||
onUpdate?: Function;
|
||||
duration?: number;
|
||||
node: Node;
|
||||
}
|
||||
export declare class Tween {
|
||||
static attrs: {};
|
||||
static tweens: {};
|
||||
node: Node;
|
||||
anim: Animation;
|
||||
tween: TweenEngine;
|
||||
_id: number;
|
||||
onFinish: Function;
|
||||
onReset: Function;
|
||||
onUpdate: Function;
|
||||
constructor(config: TweenConfig);
|
||||
_addAttr(key: any, end: any): void;
|
||||
_tweenFunc(i: any): void;
|
||||
_addListeners(): void;
|
||||
play(): this;
|
||||
reverse(): this;
|
||||
reset(): this;
|
||||
seek(t: any): this;
|
||||
pause(): this;
|
||||
finish(): this;
|
||||
destroy(): void;
|
||||
}
|
||||
export declare const Easings: {
|
||||
BackEaseIn(t: any, b: any, c: any, d: any): any;
|
||||
BackEaseOut(t: any, b: any, c: any, d: any): any;
|
||||
BackEaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
ElasticEaseIn(t: any, b: any, c: any, d: any, a: any, p: any): any;
|
||||
ElasticEaseOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
|
||||
ElasticEaseInOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
|
||||
BounceEaseOut(t: any, b: any, c: any, d: any): any;
|
||||
BounceEaseIn(t: any, b: any, c: any, d: any): any;
|
||||
BounceEaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
EaseIn(t: any, b: any, c: any, d: any): any;
|
||||
EaseOut(t: any, b: any, c: any, d: any): any;
|
||||
EaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
StrongEaseIn(t: any, b: any, c: any, d: any): any;
|
||||
StrongEaseOut(t: any, b: any, c: any, d: any): any;
|
||||
StrongEaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
Linear(t: any, b: any, c: any, d: any): any;
|
||||
};
|
||||
export {};
|
||||
520
node_modules/konva/cmj/Tween.js
generated
vendored
Normal file
520
node_modules/konva/cmj/Tween.js
generated
vendored
Normal file
@@ -0,0 +1,520 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Easings = exports.Tween = void 0;
|
||||
const Util_1 = require("./Util");
|
||||
const Animation_1 = require("./Animation");
|
||||
const Node_1 = require("./Node");
|
||||
const Global_1 = require("./Global");
|
||||
var blacklist = {
|
||||
node: 1,
|
||||
duration: 1,
|
||||
easing: 1,
|
||||
onFinish: 1,
|
||||
yoyo: 1,
|
||||
}, PAUSED = 1, PLAYING = 2, REVERSING = 3, idCounter = 0, colorAttrs = ['fill', 'stroke', 'shadowColor'];
|
||||
class TweenEngine {
|
||||
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
||||
this.prop = prop;
|
||||
this.propFunc = propFunc;
|
||||
this.begin = begin;
|
||||
this._pos = begin;
|
||||
this.duration = duration;
|
||||
this._change = 0;
|
||||
this.prevPos = 0;
|
||||
this.yoyo = yoyo;
|
||||
this._time = 0;
|
||||
this._position = 0;
|
||||
this._startTime = 0;
|
||||
this._finish = 0;
|
||||
this.func = func;
|
||||
this._change = finish - this.begin;
|
||||
this.pause();
|
||||
}
|
||||
fire(str) {
|
||||
var handler = this[str];
|
||||
if (handler) {
|
||||
handler();
|
||||
}
|
||||
}
|
||||
setTime(t) {
|
||||
if (t > this.duration) {
|
||||
if (this.yoyo) {
|
||||
this._time = this.duration;
|
||||
this.reverse();
|
||||
}
|
||||
else {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
else if (t < 0) {
|
||||
if (this.yoyo) {
|
||||
this._time = 0;
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._time = t;
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
getTime() {
|
||||
return this._time;
|
||||
}
|
||||
setPosition(p) {
|
||||
this.prevPos = this._pos;
|
||||
this.propFunc(p);
|
||||
this._pos = p;
|
||||
}
|
||||
getPosition(t) {
|
||||
if (t === undefined) {
|
||||
t = this._time;
|
||||
}
|
||||
return this.func(t, this.begin, this._change, this.duration);
|
||||
}
|
||||
play() {
|
||||
this.state = PLAYING;
|
||||
this._startTime = this.getTimer() - this._time;
|
||||
this.onEnterFrame();
|
||||
this.fire('onPlay');
|
||||
}
|
||||
reverse() {
|
||||
this.state = REVERSING;
|
||||
this._time = this.duration - this._time;
|
||||
this._startTime = this.getTimer() - this._time;
|
||||
this.onEnterFrame();
|
||||
this.fire('onReverse');
|
||||
}
|
||||
seek(t) {
|
||||
this.pause();
|
||||
this._time = t;
|
||||
this.update();
|
||||
this.fire('onSeek');
|
||||
}
|
||||
reset() {
|
||||
this.pause();
|
||||
this._time = 0;
|
||||
this.update();
|
||||
this.fire('onReset');
|
||||
}
|
||||
finish() {
|
||||
this.pause();
|
||||
this._time = this.duration;
|
||||
this.update();
|
||||
this.fire('onFinish');
|
||||
}
|
||||
update() {
|
||||
this.setPosition(this.getPosition(this._time));
|
||||
this.fire('onUpdate');
|
||||
}
|
||||
onEnterFrame() {
|
||||
var t = this.getTimer() - this._startTime;
|
||||
if (this.state === PLAYING) {
|
||||
this.setTime(t);
|
||||
}
|
||||
else if (this.state === REVERSING) {
|
||||
this.setTime(this.duration - t);
|
||||
}
|
||||
}
|
||||
pause() {
|
||||
this.state = PAUSED;
|
||||
this.fire('onPause');
|
||||
}
|
||||
getTimer() {
|
||||
return new Date().getTime();
|
||||
}
|
||||
}
|
||||
class Tween {
|
||||
constructor(config) {
|
||||
var that = this, node = config.node, nodeId = node._id, duration, easing = config.easing || exports.Easings.Linear, yoyo = !!config.yoyo, key;
|
||||
if (typeof config.duration === 'undefined') {
|
||||
duration = 0.3;
|
||||
}
|
||||
else if (config.duration === 0) {
|
||||
duration = 0.001;
|
||||
}
|
||||
else {
|
||||
duration = config.duration;
|
||||
}
|
||||
this.node = node;
|
||||
this._id = idCounter++;
|
||||
var layers = node.getLayer() ||
|
||||
(node instanceof Global_1.Konva['Stage'] ? node.getLayers() : null);
|
||||
if (!layers) {
|
||||
Util_1.Util.error('Tween constructor have `node` that is not in a layer. Please add node into layer first.');
|
||||
}
|
||||
this.anim = new Animation_1.Animation(function () {
|
||||
that.tween.onEnterFrame();
|
||||
}, layers);
|
||||
this.tween = new TweenEngine(key, function (i) {
|
||||
that._tweenFunc(i);
|
||||
}, easing, 0, 1, duration * 1000, yoyo);
|
||||
this._addListeners();
|
||||
if (!Tween.attrs[nodeId]) {
|
||||
Tween.attrs[nodeId] = {};
|
||||
}
|
||||
if (!Tween.attrs[nodeId][this._id]) {
|
||||
Tween.attrs[nodeId][this._id] = {};
|
||||
}
|
||||
if (!Tween.tweens[nodeId]) {
|
||||
Tween.tweens[nodeId] = {};
|
||||
}
|
||||
for (key in config) {
|
||||
if (blacklist[key] === undefined) {
|
||||
this._addAttr(key, config[key]);
|
||||
}
|
||||
}
|
||||
this.reset();
|
||||
this.onFinish = config.onFinish;
|
||||
this.onReset = config.onReset;
|
||||
this.onUpdate = config.onUpdate;
|
||||
}
|
||||
_addAttr(key, end) {
|
||||
var node = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA;
|
||||
tweenId = Tween.tweens[nodeId][key];
|
||||
if (tweenId) {
|
||||
delete Tween.attrs[nodeId][tweenId][key];
|
||||
}
|
||||
start = node.getAttr(key);
|
||||
if (Util_1.Util._isArray(end)) {
|
||||
diff = [];
|
||||
len = Math.max(end.length, start.length);
|
||||
if (key === 'points' && end.length !== start.length) {
|
||||
if (end.length > start.length) {
|
||||
trueStart = start;
|
||||
start = Util_1.Util._prepareArrayForTween(start, end, node.closed());
|
||||
}
|
||||
else {
|
||||
trueEnd = end;
|
||||
end = Util_1.Util._prepareArrayForTween(end, start, node.closed());
|
||||
}
|
||||
}
|
||||
if (key.indexOf('fill') === 0) {
|
||||
for (n = 0; n < len; n++) {
|
||||
if (n % 2 === 0) {
|
||||
diff.push(end[n] - start[n]);
|
||||
}
|
||||
else {
|
||||
var startRGBA = Util_1.Util.colorToRGBA(start[n]);
|
||||
endRGBA = Util_1.Util.colorToRGBA(end[n]);
|
||||
start[n] = startRGBA;
|
||||
diff.push({
|
||||
r: endRGBA.r - startRGBA.r,
|
||||
g: endRGBA.g - startRGBA.g,
|
||||
b: endRGBA.b - startRGBA.b,
|
||||
a: endRGBA.a - startRGBA.a,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (n = 0; n < len; n++) {
|
||||
diff.push(end[n] - start[n]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (colorAttrs.indexOf(key) !== -1) {
|
||||
start = Util_1.Util.colorToRGBA(start);
|
||||
endRGBA = Util_1.Util.colorToRGBA(end);
|
||||
diff = {
|
||||
r: endRGBA.r - start.r,
|
||||
g: endRGBA.g - start.g,
|
||||
b: endRGBA.b - start.b,
|
||||
a: endRGBA.a - start.a,
|
||||
};
|
||||
}
|
||||
else {
|
||||
diff = end - start;
|
||||
}
|
||||
Tween.attrs[nodeId][this._id][key] = {
|
||||
start: start,
|
||||
diff: diff,
|
||||
end: end,
|
||||
trueEnd: trueEnd,
|
||||
trueStart: trueStart,
|
||||
};
|
||||
Tween.tweens[nodeId][key] = this._id;
|
||||
}
|
||||
_tweenFunc(i) {
|
||||
var node = this.node, attrs = Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end;
|
||||
for (key in attrs) {
|
||||
attr = attrs[key];
|
||||
start = attr.start;
|
||||
diff = attr.diff;
|
||||
end = attr.end;
|
||||
if (Util_1.Util._isArray(start)) {
|
||||
newVal = [];
|
||||
len = Math.max(start.length, end.length);
|
||||
if (key.indexOf('fill') === 0) {
|
||||
for (n = 0; n < len; n++) {
|
||||
if (n % 2 === 0) {
|
||||
newVal.push((start[n] || 0) + diff[n] * i);
|
||||
}
|
||||
else {
|
||||
newVal.push('rgba(' +
|
||||
Math.round(start[n].r + diff[n].r * i) +
|
||||
',' +
|
||||
Math.round(start[n].g + diff[n].g * i) +
|
||||
',' +
|
||||
Math.round(start[n].b + diff[n].b * i) +
|
||||
',' +
|
||||
(start[n].a + diff[n].a * i) +
|
||||
')');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (n = 0; n < len; n++) {
|
||||
newVal.push((start[n] || 0) + diff[n] * i);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (colorAttrs.indexOf(key) !== -1) {
|
||||
newVal =
|
||||
'rgba(' +
|
||||
Math.round(start.r + diff.r * i) +
|
||||
',' +
|
||||
Math.round(start.g + diff.g * i) +
|
||||
',' +
|
||||
Math.round(start.b + diff.b * i) +
|
||||
',' +
|
||||
(start.a + diff.a * i) +
|
||||
')';
|
||||
}
|
||||
else {
|
||||
newVal = start + diff * i;
|
||||
}
|
||||
node.setAttr(key, newVal);
|
||||
}
|
||||
}
|
||||
_addListeners() {
|
||||
this.tween.onPlay = () => {
|
||||
this.anim.start();
|
||||
};
|
||||
this.tween.onReverse = () => {
|
||||
this.anim.start();
|
||||
};
|
||||
this.tween.onPause = () => {
|
||||
this.anim.stop();
|
||||
};
|
||||
this.tween.onFinish = () => {
|
||||
var node = this.node;
|
||||
var attrs = Tween.attrs[node._id][this._id];
|
||||
if (attrs.points && attrs.points.trueEnd) {
|
||||
node.setAttr('points', attrs.points.trueEnd);
|
||||
}
|
||||
if (this.onFinish) {
|
||||
this.onFinish.call(this);
|
||||
}
|
||||
};
|
||||
this.tween.onReset = () => {
|
||||
var node = this.node;
|
||||
var attrs = Tween.attrs[node._id][this._id];
|
||||
if (attrs.points && attrs.points.trueStart) {
|
||||
node.points(attrs.points.trueStart);
|
||||
}
|
||||
if (this.onReset) {
|
||||
this.onReset();
|
||||
}
|
||||
};
|
||||
this.tween.onUpdate = () => {
|
||||
if (this.onUpdate) {
|
||||
this.onUpdate.call(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
play() {
|
||||
this.tween.play();
|
||||
return this;
|
||||
}
|
||||
reverse() {
|
||||
this.tween.reverse();
|
||||
return this;
|
||||
}
|
||||
reset() {
|
||||
this.tween.reset();
|
||||
return this;
|
||||
}
|
||||
seek(t) {
|
||||
this.tween.seek(t * 1000);
|
||||
return this;
|
||||
}
|
||||
pause() {
|
||||
this.tween.pause();
|
||||
return this;
|
||||
}
|
||||
finish() {
|
||||
this.tween.finish();
|
||||
return this;
|
||||
}
|
||||
destroy() {
|
||||
var nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId], key;
|
||||
this.pause();
|
||||
for (key in attrs) {
|
||||
delete Tween.tweens[nodeId][key];
|
||||
}
|
||||
delete Tween.attrs[nodeId][thisId];
|
||||
}
|
||||
}
|
||||
exports.Tween = Tween;
|
||||
Tween.attrs = {};
|
||||
Tween.tweens = {};
|
||||
Node_1.Node.prototype.to = function (params) {
|
||||
var onFinish = params.onFinish;
|
||||
params.node = this;
|
||||
params.onFinish = function () {
|
||||
this.destroy();
|
||||
if (onFinish) {
|
||||
onFinish();
|
||||
}
|
||||
};
|
||||
var tween = new Tween(params);
|
||||
tween.play();
|
||||
};
|
||||
exports.Easings = {
|
||||
BackEaseIn(t, b, c, d) {
|
||||
var s = 1.70158;
|
||||
return c * (t /= d) * t * ((s + 1) * t - s) + b;
|
||||
},
|
||||
BackEaseOut(t, b, c, d) {
|
||||
var s = 1.70158;
|
||||
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
|
||||
},
|
||||
BackEaseInOut(t, b, c, d) {
|
||||
var s = 1.70158;
|
||||
if ((t /= d / 2) < 1) {
|
||||
return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
|
||||
}
|
||||
return (c / 2) * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
|
||||
},
|
||||
ElasticEaseIn(t, b, c, d, a, p) {
|
||||
var s = 0;
|
||||
if (t === 0) {
|
||||
return b;
|
||||
}
|
||||
if ((t /= d) === 1) {
|
||||
return b + c;
|
||||
}
|
||||
if (!p) {
|
||||
p = d * 0.3;
|
||||
}
|
||||
if (!a || a < Math.abs(c)) {
|
||||
a = c;
|
||||
s = p / 4;
|
||||
}
|
||||
else {
|
||||
s = (p / (2 * Math.PI)) * Math.asin(c / a);
|
||||
}
|
||||
return (-(a *
|
||||
Math.pow(2, 10 * (t -= 1)) *
|
||||
Math.sin(((t * d - s) * (2 * Math.PI)) / p)) + b);
|
||||
},
|
||||
ElasticEaseOut(t, b, c, d, a, p) {
|
||||
var s = 0;
|
||||
if (t === 0) {
|
||||
return b;
|
||||
}
|
||||
if ((t /= d) === 1) {
|
||||
return b + c;
|
||||
}
|
||||
if (!p) {
|
||||
p = d * 0.3;
|
||||
}
|
||||
if (!a || a < Math.abs(c)) {
|
||||
a = c;
|
||||
s = p / 4;
|
||||
}
|
||||
else {
|
||||
s = (p / (2 * Math.PI)) * Math.asin(c / a);
|
||||
}
|
||||
return (a * Math.pow(2, -10 * t) * Math.sin(((t * d - s) * (2 * Math.PI)) / p) +
|
||||
c +
|
||||
b);
|
||||
},
|
||||
ElasticEaseInOut(t, b, c, d, a, p) {
|
||||
var s = 0;
|
||||
if (t === 0) {
|
||||
return b;
|
||||
}
|
||||
if ((t /= d / 2) === 2) {
|
||||
return b + c;
|
||||
}
|
||||
if (!p) {
|
||||
p = d * (0.3 * 1.5);
|
||||
}
|
||||
if (!a || a < Math.abs(c)) {
|
||||
a = c;
|
||||
s = p / 4;
|
||||
}
|
||||
else {
|
||||
s = (p / (2 * Math.PI)) * Math.asin(c / a);
|
||||
}
|
||||
if (t < 1) {
|
||||
return (-0.5 *
|
||||
(a *
|
||||
Math.pow(2, 10 * (t -= 1)) *
|
||||
Math.sin(((t * d - s) * (2 * Math.PI)) / p)) +
|
||||
b);
|
||||
}
|
||||
return (a *
|
||||
Math.pow(2, -10 * (t -= 1)) *
|
||||
Math.sin(((t * d - s) * (2 * Math.PI)) / p) *
|
||||
0.5 +
|
||||
c +
|
||||
b);
|
||||
},
|
||||
BounceEaseOut(t, b, c, d) {
|
||||
if ((t /= d) < 1 / 2.75) {
|
||||
return c * (7.5625 * t * t) + b;
|
||||
}
|
||||
else if (t < 2 / 2.75) {
|
||||
return c * (7.5625 * (t -= 1.5 / 2.75) * t + 0.75) + b;
|
||||
}
|
||||
else if (t < 2.5 / 2.75) {
|
||||
return c * (7.5625 * (t -= 2.25 / 2.75) * t + 0.9375) + b;
|
||||
}
|
||||
else {
|
||||
return c * (7.5625 * (t -= 2.625 / 2.75) * t + 0.984375) + b;
|
||||
}
|
||||
},
|
||||
BounceEaseIn(t, b, c, d) {
|
||||
return c - exports.Easings.BounceEaseOut(d - t, 0, c, d) + b;
|
||||
},
|
||||
BounceEaseInOut(t, b, c, d) {
|
||||
if (t < d / 2) {
|
||||
return exports.Easings.BounceEaseIn(t * 2, 0, c, d) * 0.5 + b;
|
||||
}
|
||||
else {
|
||||
return exports.Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
|
||||
}
|
||||
},
|
||||
EaseIn(t, b, c, d) {
|
||||
return c * (t /= d) * t + b;
|
||||
},
|
||||
EaseOut(t, b, c, d) {
|
||||
return -c * (t /= d) * (t - 2) + b;
|
||||
},
|
||||
EaseInOut(t, b, c, d) {
|
||||
if ((t /= d / 2) < 1) {
|
||||
return (c / 2) * t * t + b;
|
||||
}
|
||||
return (-c / 2) * (--t * (t - 2) - 1) + b;
|
||||
},
|
||||
StrongEaseIn(t, b, c, d) {
|
||||
return c * (t /= d) * t * t * t * t + b;
|
||||
},
|
||||
StrongEaseOut(t, b, c, d) {
|
||||
return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
|
||||
},
|
||||
StrongEaseInOut(t, b, c, d) {
|
||||
if ((t /= d / 2) < 1) {
|
||||
return (c / 2) * t * t * t * t * t + b;
|
||||
}
|
||||
return (c / 2) * ((t -= 2) * t * t * t * t + 2) + b;
|
||||
},
|
||||
Linear(t, b, c, d) {
|
||||
return (c * t) / d + b;
|
||||
},
|
||||
};
|
||||
87
node_modules/konva/cmj/Util.d.ts
generated
vendored
Normal file
87
node_modules/konva/cmj/Util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
import { IRect, RGB, RGBA, Vector2d } from './types';
|
||||
export declare class Transform {
|
||||
m: Array<number>;
|
||||
dirty: boolean;
|
||||
constructor(m?: number[]);
|
||||
reset(): void;
|
||||
copy(): Transform;
|
||||
copyInto(tr: Transform): void;
|
||||
point(point: Vector2d): {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
translate(x: number, y: number): this;
|
||||
scale(sx: number, sy: number): this;
|
||||
rotate(rad: number): this;
|
||||
getTranslation(): {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
skew(sx: number, sy: number): this;
|
||||
multiply(matrix: Transform): this;
|
||||
invert(): this;
|
||||
getMatrix(): number[];
|
||||
setAbsolutePosition(x: number, y: number): this;
|
||||
decompose(): {
|
||||
x: number;
|
||||
y: number;
|
||||
rotation: number;
|
||||
scaleX: number;
|
||||
scaleY: number;
|
||||
skewX: number;
|
||||
skewY: number;
|
||||
};
|
||||
}
|
||||
export declare const Util: {
|
||||
_isElement(obj: any): obj is Element;
|
||||
_isFunction(obj: any): boolean;
|
||||
_isPlainObject(obj: any): boolean;
|
||||
_isArray(obj: any): obj is any[];
|
||||
_isNumber(obj: any): obj is number;
|
||||
_isString(obj: any): obj is string;
|
||||
_isBoolean(obj: any): obj is boolean;
|
||||
isObject(val: any): val is Object;
|
||||
isValidSelector(selector: any): boolean;
|
||||
_sign(number: number): 1 | -1;
|
||||
requestAnimFrame(callback: Function): void;
|
||||
createCanvasElement(): HTMLCanvasElement;
|
||||
createImageElement(): HTMLImageElement;
|
||||
_isInDocument(el: any): boolean;
|
||||
_urlToImage(url: string, callback: Function): void;
|
||||
_rgbToHex(r: number, g: number, b: number): string;
|
||||
_hexToRgb(hex: string): RGB;
|
||||
getRandomColor(): string;
|
||||
getRGB(color: string): RGB;
|
||||
colorToRGBA(str: string): RGBA;
|
||||
_namedColorToRBA(str: string): {
|
||||
r: any;
|
||||
g: any;
|
||||
b: any;
|
||||
a: number;
|
||||
};
|
||||
_rgbColorToRGBA(str: string): RGBA;
|
||||
_rgbaColorToRGBA(str: string): RGBA;
|
||||
_hex6ColorToRGBA(str: string): RGBA;
|
||||
_hex3ColorToRGBA(str: string): RGBA;
|
||||
_hslColorToRGBA(str: string): RGBA;
|
||||
haveIntersection(r1: IRect, r2: IRect): boolean;
|
||||
cloneObject<Any>(obj: Any): Any;
|
||||
cloneArray(arr: Array<any>): any[];
|
||||
degToRad(deg: number): number;
|
||||
radToDeg(rad: number): number;
|
||||
_degToRad(deg: number): number;
|
||||
_radToDeg(rad: number): number;
|
||||
_getRotation(radians: any): any;
|
||||
_capitalize(str: string): string;
|
||||
throw(str: string): never;
|
||||
error(str: string): void;
|
||||
warn(str: string): void;
|
||||
each(obj: any, func: any): void;
|
||||
_inRange(val: any, left: any, right: any): boolean;
|
||||
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
||||
_getProjectionToLine(pt: Vector2d, line: any, isClosed: any): Vector2d;
|
||||
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): any[];
|
||||
_prepareToStringify(obj: any): any;
|
||||
_assign<T, U>(target: T, source: U): T & U;
|
||||
_getFirstPointerId(evt: any): any;
|
||||
};
|
||||
746
node_modules/konva/cmj/Util.js
generated
vendored
Normal file
746
node_modules/konva/cmj/Util.js
generated
vendored
Normal file
@@ -0,0 +1,746 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Util = exports.Transform = void 0;
|
||||
const Global_1 = require("./Global");
|
||||
class Transform {
|
||||
constructor(m = [1, 0, 0, 1, 0, 0]) {
|
||||
this.dirty = false;
|
||||
this.m = (m && m.slice()) || [1, 0, 0, 1, 0, 0];
|
||||
}
|
||||
reset() {
|
||||
this.m[0] = 1;
|
||||
this.m[1] = 0;
|
||||
this.m[2] = 0;
|
||||
this.m[3] = 1;
|
||||
this.m[4] = 0;
|
||||
this.m[5] = 0;
|
||||
}
|
||||
copy() {
|
||||
return new Transform(this.m);
|
||||
}
|
||||
copyInto(tr) {
|
||||
tr.m[0] = this.m[0];
|
||||
tr.m[1] = this.m[1];
|
||||
tr.m[2] = this.m[2];
|
||||
tr.m[3] = this.m[3];
|
||||
tr.m[4] = this.m[4];
|
||||
tr.m[5] = this.m[5];
|
||||
}
|
||||
point(point) {
|
||||
var m = this.m;
|
||||
return {
|
||||
x: m[0] * point.x + m[2] * point.y + m[4],
|
||||
y: m[1] * point.x + m[3] * point.y + m[5],
|
||||
};
|
||||
}
|
||||
translate(x, y) {
|
||||
this.m[4] += this.m[0] * x + this.m[2] * y;
|
||||
this.m[5] += this.m[1] * x + this.m[3] * y;
|
||||
return this;
|
||||
}
|
||||
scale(sx, sy) {
|
||||
this.m[0] *= sx;
|
||||
this.m[1] *= sx;
|
||||
this.m[2] *= sy;
|
||||
this.m[3] *= sy;
|
||||
return this;
|
||||
}
|
||||
rotate(rad) {
|
||||
var c = Math.cos(rad);
|
||||
var s = Math.sin(rad);
|
||||
var m11 = this.m[0] * c + this.m[2] * s;
|
||||
var m12 = this.m[1] * c + this.m[3] * s;
|
||||
var m21 = this.m[0] * -s + this.m[2] * c;
|
||||
var m22 = this.m[1] * -s + this.m[3] * c;
|
||||
this.m[0] = m11;
|
||||
this.m[1] = m12;
|
||||
this.m[2] = m21;
|
||||
this.m[3] = m22;
|
||||
return this;
|
||||
}
|
||||
getTranslation() {
|
||||
return {
|
||||
x: this.m[4],
|
||||
y: this.m[5],
|
||||
};
|
||||
}
|
||||
skew(sx, sy) {
|
||||
var m11 = this.m[0] + this.m[2] * sy;
|
||||
var m12 = this.m[1] + this.m[3] * sy;
|
||||
var m21 = this.m[2] + this.m[0] * sx;
|
||||
var m22 = this.m[3] + this.m[1] * sx;
|
||||
this.m[0] = m11;
|
||||
this.m[1] = m12;
|
||||
this.m[2] = m21;
|
||||
this.m[3] = m22;
|
||||
return this;
|
||||
}
|
||||
multiply(matrix) {
|
||||
var m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];
|
||||
var m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];
|
||||
var m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];
|
||||
var m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];
|
||||
var dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];
|
||||
var dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];
|
||||
this.m[0] = m11;
|
||||
this.m[1] = m12;
|
||||
this.m[2] = m21;
|
||||
this.m[3] = m22;
|
||||
this.m[4] = dx;
|
||||
this.m[5] = dy;
|
||||
return this;
|
||||
}
|
||||
invert() {
|
||||
var d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);
|
||||
var m0 = this.m[3] * d;
|
||||
var m1 = -this.m[1] * d;
|
||||
var m2 = -this.m[2] * d;
|
||||
var m3 = this.m[0] * d;
|
||||
var m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);
|
||||
var m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
|
||||
this.m[0] = m0;
|
||||
this.m[1] = m1;
|
||||
this.m[2] = m2;
|
||||
this.m[3] = m3;
|
||||
this.m[4] = m4;
|
||||
this.m[5] = m5;
|
||||
return this;
|
||||
}
|
||||
getMatrix() {
|
||||
return this.m;
|
||||
}
|
||||
setAbsolutePosition(x, y) {
|
||||
var m0 = this.m[0], m1 = this.m[1], m2 = this.m[2], m3 = this.m[3], m4 = this.m[4], m5 = this.m[5], yt = (m0 * (y - m5) - m1 * (x - m4)) / (m0 * m3 - m1 * m2), xt = (x - m4 - m2 * yt) / m0;
|
||||
return this.translate(xt, yt);
|
||||
}
|
||||
decompose() {
|
||||
var a = this.m[0];
|
||||
var b = this.m[1];
|
||||
var c = this.m[2];
|
||||
var d = this.m[3];
|
||||
var e = this.m[4];
|
||||
var f = this.m[5];
|
||||
var delta = a * d - b * c;
|
||||
let result = {
|
||||
x: e,
|
||||
y: f,
|
||||
rotation: 0,
|
||||
scaleX: 0,
|
||||
scaleY: 0,
|
||||
skewX: 0,
|
||||
skewY: 0,
|
||||
};
|
||||
if (a != 0 || b != 0) {
|
||||
var r = Math.sqrt(a * a + b * b);
|
||||
result.rotation = b > 0 ? Math.acos(a / r) : -Math.acos(a / r);
|
||||
result.scaleX = r;
|
||||
result.scaleY = delta / r;
|
||||
result.skewX = (a * c + b * d) / delta;
|
||||
result.skewY = 0;
|
||||
}
|
||||
else if (c != 0 || d != 0) {
|
||||
var s = Math.sqrt(c * c + d * d);
|
||||
result.rotation =
|
||||
Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
|
||||
result.scaleX = delta / s;
|
||||
result.scaleY = s;
|
||||
result.skewX = 0;
|
||||
result.skewY = (a * c + b * d) / delta;
|
||||
}
|
||||
else {
|
||||
}
|
||||
result.rotation = exports.Util._getRotation(result.rotation);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
exports.Transform = Transform;
|
||||
var OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH = '#', EMPTY_STRING = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = {
|
||||
aliceblue: [240, 248, 255],
|
||||
antiquewhite: [250, 235, 215],
|
||||
aqua: [0, 255, 255],
|
||||
aquamarine: [127, 255, 212],
|
||||
azure: [240, 255, 255],
|
||||
beige: [245, 245, 220],
|
||||
bisque: [255, 228, 196],
|
||||
black: [0, 0, 0],
|
||||
blanchedalmond: [255, 235, 205],
|
||||
blue: [0, 0, 255],
|
||||
blueviolet: [138, 43, 226],
|
||||
brown: [165, 42, 42],
|
||||
burlywood: [222, 184, 135],
|
||||
cadetblue: [95, 158, 160],
|
||||
chartreuse: [127, 255, 0],
|
||||
chocolate: [210, 105, 30],
|
||||
coral: [255, 127, 80],
|
||||
cornflowerblue: [100, 149, 237],
|
||||
cornsilk: [255, 248, 220],
|
||||
crimson: [220, 20, 60],
|
||||
cyan: [0, 255, 255],
|
||||
darkblue: [0, 0, 139],
|
||||
darkcyan: [0, 139, 139],
|
||||
darkgoldenrod: [184, 132, 11],
|
||||
darkgray: [169, 169, 169],
|
||||
darkgreen: [0, 100, 0],
|
||||
darkgrey: [169, 169, 169],
|
||||
darkkhaki: [189, 183, 107],
|
||||
darkmagenta: [139, 0, 139],
|
||||
darkolivegreen: [85, 107, 47],
|
||||
darkorange: [255, 140, 0],
|
||||
darkorchid: [153, 50, 204],
|
||||
darkred: [139, 0, 0],
|
||||
darksalmon: [233, 150, 122],
|
||||
darkseagreen: [143, 188, 143],
|
||||
darkslateblue: [72, 61, 139],
|
||||
darkslategray: [47, 79, 79],
|
||||
darkslategrey: [47, 79, 79],
|
||||
darkturquoise: [0, 206, 209],
|
||||
darkviolet: [148, 0, 211],
|
||||
deeppink: [255, 20, 147],
|
||||
deepskyblue: [0, 191, 255],
|
||||
dimgray: [105, 105, 105],
|
||||
dimgrey: [105, 105, 105],
|
||||
dodgerblue: [30, 144, 255],
|
||||
firebrick: [178, 34, 34],
|
||||
floralwhite: [255, 255, 240],
|
||||
forestgreen: [34, 139, 34],
|
||||
fuchsia: [255, 0, 255],
|
||||
gainsboro: [220, 220, 220],
|
||||
ghostwhite: [248, 248, 255],
|
||||
gold: [255, 215, 0],
|
||||
goldenrod: [218, 165, 32],
|
||||
gray: [128, 128, 128],
|
||||
green: [0, 128, 0],
|
||||
greenyellow: [173, 255, 47],
|
||||
grey: [128, 128, 128],
|
||||
honeydew: [240, 255, 240],
|
||||
hotpink: [255, 105, 180],
|
||||
indianred: [205, 92, 92],
|
||||
indigo: [75, 0, 130],
|
||||
ivory: [255, 255, 240],
|
||||
khaki: [240, 230, 140],
|
||||
lavender: [230, 230, 250],
|
||||
lavenderblush: [255, 240, 245],
|
||||
lawngreen: [124, 252, 0],
|
||||
lemonchiffon: [255, 250, 205],
|
||||
lightblue: [173, 216, 230],
|
||||
lightcoral: [240, 128, 128],
|
||||
lightcyan: [224, 255, 255],
|
||||
lightgoldenrodyellow: [250, 250, 210],
|
||||
lightgray: [211, 211, 211],
|
||||
lightgreen: [144, 238, 144],
|
||||
lightgrey: [211, 211, 211],
|
||||
lightpink: [255, 182, 193],
|
||||
lightsalmon: [255, 160, 122],
|
||||
lightseagreen: [32, 178, 170],
|
||||
lightskyblue: [135, 206, 250],
|
||||
lightslategray: [119, 136, 153],
|
||||
lightslategrey: [119, 136, 153],
|
||||
lightsteelblue: [176, 196, 222],
|
||||
lightyellow: [255, 255, 224],
|
||||
lime: [0, 255, 0],
|
||||
limegreen: [50, 205, 50],
|
||||
linen: [250, 240, 230],
|
||||
magenta: [255, 0, 255],
|
||||
maroon: [128, 0, 0],
|
||||
mediumaquamarine: [102, 205, 170],
|
||||
mediumblue: [0, 0, 205],
|
||||
mediumorchid: [186, 85, 211],
|
||||
mediumpurple: [147, 112, 219],
|
||||
mediumseagreen: [60, 179, 113],
|
||||
mediumslateblue: [123, 104, 238],
|
||||
mediumspringgreen: [0, 250, 154],
|
||||
mediumturquoise: [72, 209, 204],
|
||||
mediumvioletred: [199, 21, 133],
|
||||
midnightblue: [25, 25, 112],
|
||||
mintcream: [245, 255, 250],
|
||||
mistyrose: [255, 228, 225],
|
||||
moccasin: [255, 228, 181],
|
||||
navajowhite: [255, 222, 173],
|
||||
navy: [0, 0, 128],
|
||||
oldlace: [253, 245, 230],
|
||||
olive: [128, 128, 0],
|
||||
olivedrab: [107, 142, 35],
|
||||
orange: [255, 165, 0],
|
||||
orangered: [255, 69, 0],
|
||||
orchid: [218, 112, 214],
|
||||
palegoldenrod: [238, 232, 170],
|
||||
palegreen: [152, 251, 152],
|
||||
paleturquoise: [175, 238, 238],
|
||||
palevioletred: [219, 112, 147],
|
||||
papayawhip: [255, 239, 213],
|
||||
peachpuff: [255, 218, 185],
|
||||
peru: [205, 133, 63],
|
||||
pink: [255, 192, 203],
|
||||
plum: [221, 160, 203],
|
||||
powderblue: [176, 224, 230],
|
||||
purple: [128, 0, 128],
|
||||
rebeccapurple: [102, 51, 153],
|
||||
red: [255, 0, 0],
|
||||
rosybrown: [188, 143, 143],
|
||||
royalblue: [65, 105, 225],
|
||||
saddlebrown: [139, 69, 19],
|
||||
salmon: [250, 128, 114],
|
||||
sandybrown: [244, 164, 96],
|
||||
seagreen: [46, 139, 87],
|
||||
seashell: [255, 245, 238],
|
||||
sienna: [160, 82, 45],
|
||||
silver: [192, 192, 192],
|
||||
skyblue: [135, 206, 235],
|
||||
slateblue: [106, 90, 205],
|
||||
slategray: [119, 128, 144],
|
||||
slategrey: [119, 128, 144],
|
||||
snow: [255, 255, 250],
|
||||
springgreen: [0, 255, 127],
|
||||
steelblue: [70, 130, 180],
|
||||
tan: [210, 180, 140],
|
||||
teal: [0, 128, 128],
|
||||
thistle: [216, 191, 216],
|
||||
transparent: [255, 255, 255, 0],
|
||||
tomato: [255, 99, 71],
|
||||
turquoise: [64, 224, 208],
|
||||
violet: [238, 130, 238],
|
||||
wheat: [245, 222, 179],
|
||||
white: [255, 255, 255],
|
||||
whitesmoke: [245, 245, 245],
|
||||
yellow: [255, 255, 0],
|
||||
yellowgreen: [154, 205, 5],
|
||||
}, RGB_REGEX = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/, animQueue = [];
|
||||
const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
|
||||
function (f) {
|
||||
setTimeout(f, 60);
|
||||
};
|
||||
exports.Util = {
|
||||
_isElement(obj) {
|
||||
return !!(obj && obj.nodeType == 1);
|
||||
},
|
||||
_isFunction(obj) {
|
||||
return !!(obj && obj.constructor && obj.call && obj.apply);
|
||||
},
|
||||
_isPlainObject(obj) {
|
||||
return !!obj && obj.constructor === Object;
|
||||
},
|
||||
_isArray(obj) {
|
||||
return Object.prototype.toString.call(obj) === OBJECT_ARRAY;
|
||||
},
|
||||
_isNumber(obj) {
|
||||
return (Object.prototype.toString.call(obj) === OBJECT_NUMBER &&
|
||||
!isNaN(obj) &&
|
||||
isFinite(obj));
|
||||
},
|
||||
_isString(obj) {
|
||||
return Object.prototype.toString.call(obj) === OBJECT_STRING;
|
||||
},
|
||||
_isBoolean(obj) {
|
||||
return Object.prototype.toString.call(obj) === OBJECT_BOOLEAN;
|
||||
},
|
||||
isObject(val) {
|
||||
return val instanceof Object;
|
||||
},
|
||||
isValidSelector(selector) {
|
||||
if (typeof selector !== 'string') {
|
||||
return false;
|
||||
}
|
||||
var firstChar = selector[0];
|
||||
return (firstChar === '#' ||
|
||||
firstChar === '.' ||
|
||||
firstChar === firstChar.toUpperCase());
|
||||
},
|
||||
_sign(number) {
|
||||
if (number === 0) {
|
||||
return 1;
|
||||
}
|
||||
if (number > 0) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
},
|
||||
requestAnimFrame(callback) {
|
||||
animQueue.push(callback);
|
||||
if (animQueue.length === 1) {
|
||||
req(function () {
|
||||
const queue = animQueue;
|
||||
animQueue = [];
|
||||
queue.forEach(function (cb) {
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
createCanvasElement() {
|
||||
var canvas = document.createElement('canvas');
|
||||
try {
|
||||
canvas.style = canvas.style || {};
|
||||
}
|
||||
catch (e) { }
|
||||
return canvas;
|
||||
},
|
||||
createImageElement() {
|
||||
return document.createElement('img');
|
||||
},
|
||||
_isInDocument(el) {
|
||||
while ((el = el.parentNode)) {
|
||||
if (el == document) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
_urlToImage(url, callback) {
|
||||
var imageObj = exports.Util.createImageElement();
|
||||
imageObj.onload = function () {
|
||||
callback(imageObj);
|
||||
};
|
||||
imageObj.src = url;
|
||||
},
|
||||
_rgbToHex(r, g, b) {
|
||||
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
||||
},
|
||||
_hexToRgb(hex) {
|
||||
hex = hex.replace(HASH, EMPTY_STRING);
|
||||
var bigint = parseInt(hex, 16);
|
||||
return {
|
||||
r: (bigint >> 16) & 255,
|
||||
g: (bigint >> 8) & 255,
|
||||
b: bigint & 255,
|
||||
};
|
||||
},
|
||||
getRandomColor() {
|
||||
var randColor = ((Math.random() * 0xffffff) << 0).toString(16);
|
||||
while (randColor.length < 6) {
|
||||
randColor = ZERO + randColor;
|
||||
}
|
||||
return HASH + randColor;
|
||||
},
|
||||
getRGB(color) {
|
||||
var rgb;
|
||||
if (color in COLORS) {
|
||||
rgb = COLORS[color];
|
||||
return {
|
||||
r: rgb[0],
|
||||
g: rgb[1],
|
||||
b: rgb[2],
|
||||
};
|
||||
}
|
||||
else if (color[0] === HASH) {
|
||||
return this._hexToRgb(color.substring(1));
|
||||
}
|
||||
else if (color.substr(0, 4) === RGB_PAREN) {
|
||||
rgb = RGB_REGEX.exec(color.replace(/ /g, ''));
|
||||
return {
|
||||
r: parseInt(rgb[1], 10),
|
||||
g: parseInt(rgb[2], 10),
|
||||
b: parseInt(rgb[3], 10),
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
};
|
||||
}
|
||||
},
|
||||
colorToRGBA(str) {
|
||||
str = str || 'black';
|
||||
return (exports.Util._namedColorToRBA(str) ||
|
||||
exports.Util._hex3ColorToRGBA(str) ||
|
||||
exports.Util._hex6ColorToRGBA(str) ||
|
||||
exports.Util._rgbColorToRGBA(str) ||
|
||||
exports.Util._rgbaColorToRGBA(str) ||
|
||||
exports.Util._hslColorToRGBA(str));
|
||||
},
|
||||
_namedColorToRBA(str) {
|
||||
var c = COLORS[str.toLowerCase()];
|
||||
if (!c) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
r: c[0],
|
||||
g: c[1],
|
||||
b: c[2],
|
||||
a: 1,
|
||||
};
|
||||
},
|
||||
_rgbColorToRGBA(str) {
|
||||
if (str.indexOf('rgb(') === 0) {
|
||||
str = str.match(/rgb\(([^)]+)\)/)[1];
|
||||
var parts = str.split(/ *, */).map(Number);
|
||||
return {
|
||||
r: parts[0],
|
||||
g: parts[1],
|
||||
b: parts[2],
|
||||
a: 1,
|
||||
};
|
||||
}
|
||||
},
|
||||
_rgbaColorToRGBA(str) {
|
||||
if (str.indexOf('rgba(') === 0) {
|
||||
str = str.match(/rgba\(([^)]+)\)/)[1];
|
||||
var parts = str.split(/ *, */).map(Number);
|
||||
return {
|
||||
r: parts[0],
|
||||
g: parts[1],
|
||||
b: parts[2],
|
||||
a: parts[3],
|
||||
};
|
||||
}
|
||||
},
|
||||
_hex6ColorToRGBA(str) {
|
||||
if (str[0] === '#' && str.length === 7) {
|
||||
return {
|
||||
r: parseInt(str.slice(1, 3), 16),
|
||||
g: parseInt(str.slice(3, 5), 16),
|
||||
b: parseInt(str.slice(5, 7), 16),
|
||||
a: 1,
|
||||
};
|
||||
}
|
||||
},
|
||||
_hex3ColorToRGBA(str) {
|
||||
if (str[0] === '#' && str.length === 4) {
|
||||
return {
|
||||
r: parseInt(str[1] + str[1], 16),
|
||||
g: parseInt(str[2] + str[2], 16),
|
||||
b: parseInt(str[3] + str[3], 16),
|
||||
a: 1,
|
||||
};
|
||||
}
|
||||
},
|
||||
_hslColorToRGBA(str) {
|
||||
if (/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(str)) {
|
||||
const [_, ...hsl] = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(str);
|
||||
const h = Number(hsl[0]) / 360;
|
||||
const s = Number(hsl[1]) / 100;
|
||||
const l = Number(hsl[2]) / 100;
|
||||
let t2;
|
||||
let t3;
|
||||
let val;
|
||||
if (s === 0) {
|
||||
val = l * 255;
|
||||
return {
|
||||
r: Math.round(val),
|
||||
g: Math.round(val),
|
||||
b: Math.round(val),
|
||||
a: 1,
|
||||
};
|
||||
}
|
||||
if (l < 0.5) {
|
||||
t2 = l * (1 + s);
|
||||
}
|
||||
else {
|
||||
t2 = l + s - l * s;
|
||||
}
|
||||
const t1 = 2 * l - t2;
|
||||
const rgb = [0, 0, 0];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
t3 = h + (1 / 3) * -(i - 1);
|
||||
if (t3 < 0) {
|
||||
t3++;
|
||||
}
|
||||
if (t3 > 1) {
|
||||
t3--;
|
||||
}
|
||||
if (6 * t3 < 1) {
|
||||
val = t1 + (t2 - t1) * 6 * t3;
|
||||
}
|
||||
else if (2 * t3 < 1) {
|
||||
val = t2;
|
||||
}
|
||||
else if (3 * t3 < 2) {
|
||||
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
||||
}
|
||||
else {
|
||||
val = t1;
|
||||
}
|
||||
rgb[i] = val * 255;
|
||||
}
|
||||
return {
|
||||
r: Math.round(rgb[0]),
|
||||
g: Math.round(rgb[1]),
|
||||
b: Math.round(rgb[2]),
|
||||
a: 1,
|
||||
};
|
||||
}
|
||||
},
|
||||
haveIntersection(r1, r2) {
|
||||
return !(r2.x > r1.x + r1.width ||
|
||||
r2.x + r2.width < r1.x ||
|
||||
r2.y > r1.y + r1.height ||
|
||||
r2.y + r2.height < r1.y);
|
||||
},
|
||||
cloneObject(obj) {
|
||||
var retObj = {};
|
||||
for (var key in obj) {
|
||||
if (this._isPlainObject(obj[key])) {
|
||||
retObj[key] = this.cloneObject(obj[key]);
|
||||
}
|
||||
else if (this._isArray(obj[key])) {
|
||||
retObj[key] = this.cloneArray(obj[key]);
|
||||
}
|
||||
else {
|
||||
retObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return retObj;
|
||||
},
|
||||
cloneArray(arr) {
|
||||
return arr.slice(0);
|
||||
},
|
||||
degToRad(deg) {
|
||||
return deg * PI_OVER_DEG180;
|
||||
},
|
||||
radToDeg(rad) {
|
||||
return rad * DEG180_OVER_PI;
|
||||
},
|
||||
_degToRad(deg) {
|
||||
exports.Util.warn('Util._degToRad is removed. Please use public Util.degToRad instead.');
|
||||
return exports.Util.degToRad(deg);
|
||||
},
|
||||
_radToDeg(rad) {
|
||||
exports.Util.warn('Util._radToDeg is removed. Please use public Util.radToDeg instead.');
|
||||
return exports.Util.radToDeg(rad);
|
||||
},
|
||||
_getRotation(radians) {
|
||||
return Global_1.Konva.angleDeg ? exports.Util.radToDeg(radians) : radians;
|
||||
},
|
||||
_capitalize(str) {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
},
|
||||
throw(str) {
|
||||
throw new Error(KONVA_ERROR + str);
|
||||
},
|
||||
error(str) {
|
||||
console.error(KONVA_ERROR + str);
|
||||
},
|
||||
warn(str) {
|
||||
if (!Global_1.Konva.showWarnings) {
|
||||
return;
|
||||
}
|
||||
console.warn(KONVA_WARNING + str);
|
||||
},
|
||||
each(obj, func) {
|
||||
for (var key in obj) {
|
||||
func(key, obj[key]);
|
||||
}
|
||||
},
|
||||
_inRange(val, left, right) {
|
||||
return left <= val && val < right;
|
||||
},
|
||||
_getProjectionToSegment(x1, y1, x2, y2, x3, y3) {
|
||||
var x, y, dist;
|
||||
var pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
|
||||
if (pd2 == 0) {
|
||||
x = x1;
|
||||
y = y1;
|
||||
dist = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
|
||||
}
|
||||
else {
|
||||
var u = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2;
|
||||
if (u < 0) {
|
||||
x = x1;
|
||||
y = y1;
|
||||
dist = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
|
||||
}
|
||||
else if (u > 1.0) {
|
||||
x = x2;
|
||||
y = y2;
|
||||
dist = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
|
||||
}
|
||||
else {
|
||||
x = x1 + u * (x2 - x1);
|
||||
y = y1 + u * (y2 - y1);
|
||||
dist = (x - x3) * (x - x3) + (y - y3) * (y - y3);
|
||||
}
|
||||
}
|
||||
return [x, y, dist];
|
||||
},
|
||||
_getProjectionToLine(pt, line, isClosed) {
|
||||
var pc = exports.Util.cloneObject(pt);
|
||||
var dist = Number.MAX_VALUE;
|
||||
line.forEach(function (p1, i) {
|
||||
if (!isClosed && i === line.length - 1) {
|
||||
return;
|
||||
}
|
||||
var p2 = line[(i + 1) % line.length];
|
||||
var proj = exports.Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y);
|
||||
var px = proj[0], py = proj[1], pdist = proj[2];
|
||||
if (pdist < dist) {
|
||||
pc.x = px;
|
||||
pc.y = py;
|
||||
dist = pdist;
|
||||
}
|
||||
});
|
||||
return pc;
|
||||
},
|
||||
_prepareArrayForTween(startArray, endArray, isClosed) {
|
||||
var n, start = [], end = [];
|
||||
if (startArray.length > endArray.length) {
|
||||
var temp = endArray;
|
||||
endArray = startArray;
|
||||
startArray = temp;
|
||||
}
|
||||
for (n = 0; n < startArray.length; n += 2) {
|
||||
start.push({
|
||||
x: startArray[n],
|
||||
y: startArray[n + 1],
|
||||
});
|
||||
}
|
||||
for (n = 0; n < endArray.length; n += 2) {
|
||||
end.push({
|
||||
x: endArray[n],
|
||||
y: endArray[n + 1],
|
||||
});
|
||||
}
|
||||
var newStart = [];
|
||||
end.forEach(function (point) {
|
||||
var pr = exports.Util._getProjectionToLine(point, start, isClosed);
|
||||
newStart.push(pr.x);
|
||||
newStart.push(pr.y);
|
||||
});
|
||||
return newStart;
|
||||
},
|
||||
_prepareToStringify(obj) {
|
||||
var desc;
|
||||
obj.visitedByCircularReferenceRemoval = true;
|
||||
for (var key in obj) {
|
||||
if (!(obj.hasOwnProperty(key) && obj[key] && typeof obj[key] == 'object')) {
|
||||
continue;
|
||||
}
|
||||
desc = Object.getOwnPropertyDescriptor(obj, key);
|
||||
if (obj[key].visitedByCircularReferenceRemoval ||
|
||||
exports.Util._isElement(obj[key])) {
|
||||
if (desc.configurable) {
|
||||
delete obj[key];
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (exports.Util._prepareToStringify(obj[key]) === null) {
|
||||
if (desc.configurable) {
|
||||
delete obj[key];
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete obj.visitedByCircularReferenceRemoval;
|
||||
return obj;
|
||||
},
|
||||
_assign(target, source) {
|
||||
for (var key in source) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
return target;
|
||||
},
|
||||
_getFirstPointerId(evt) {
|
||||
if (!evt.touches) {
|
||||
return 999;
|
||||
}
|
||||
else {
|
||||
return evt.changedTouches[0].identifier;
|
||||
}
|
||||
},
|
||||
};
|
||||
11
node_modules/konva/cmj/Validators.d.ts
generated
vendored
Normal file
11
node_modules/konva/cmj/Validators.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export declare function RGBComponent(val: number): number;
|
||||
export declare function alphaComponent(val: number): number;
|
||||
export declare function getNumberValidator(): <T>(val: T, attr: string) => void | T;
|
||||
export declare function getNumberOrArrayOfNumbersValidator(noOfElements: number): <T>(val: T, attr: string) => void | T;
|
||||
export declare function getNumberOrAutoValidator(): <T extends string>(val: T, attr: string) => void | T;
|
||||
export declare function getStringValidator(): (val: any, attr: string) => any;
|
||||
export declare function getStringOrGradientValidator(): (val: any, attr: string) => any;
|
||||
export declare function getFunctionValidator(): (val: any, attr: string) => any;
|
||||
export declare function getNumberArrayValidator(): (val: any, attr: string) => any;
|
||||
export declare function getBooleanValidator(): (val: any, attr: string) => any;
|
||||
export declare function getComponentValidator(components: any): (val: any, attr: string) => any;
|
||||
185
node_modules/konva/cmj/Validators.js
generated
vendored
Normal file
185
node_modules/konva/cmj/Validators.js
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getComponentValidator = exports.getBooleanValidator = exports.getNumberArrayValidator = exports.getFunctionValidator = exports.getStringOrGradientValidator = exports.getStringValidator = exports.getNumberOrAutoValidator = exports.getNumberOrArrayOfNumbersValidator = exports.getNumberValidator = exports.alphaComponent = exports.RGBComponent = void 0;
|
||||
const Global_1 = require("./Global");
|
||||
const Util_1 = require("./Util");
|
||||
function _formatValue(val) {
|
||||
if (Util_1.Util._isString(val)) {
|
||||
return '"' + val + '"';
|
||||
}
|
||||
if (Object.prototype.toString.call(val) === '[object Number]') {
|
||||
return val;
|
||||
}
|
||||
if (Util_1.Util._isBoolean(val)) {
|
||||
return val;
|
||||
}
|
||||
return Object.prototype.toString.call(val);
|
||||
}
|
||||
function RGBComponent(val) {
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
}
|
||||
else if (val < 0) {
|
||||
return 0;
|
||||
}
|
||||
return Math.round(val);
|
||||
}
|
||||
exports.RGBComponent = RGBComponent;
|
||||
function alphaComponent(val) {
|
||||
if (val > 1) {
|
||||
return 1;
|
||||
}
|
||||
else if (val < 0.0001) {
|
||||
return 0.0001;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
exports.alphaComponent = alphaComponent;
|
||||
function getNumberValidator() {
|
||||
if (Global_1.Konva.isUnminified) {
|
||||
return function (val, attr) {
|
||||
if (!Util_1.Util._isNumber(val)) {
|
||||
Util_1.Util.warn(_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be a number.');
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getNumberValidator = getNumberValidator;
|
||||
function getNumberOrArrayOfNumbersValidator(noOfElements) {
|
||||
if (Global_1.Konva.isUnminified) {
|
||||
return function (val, attr) {
|
||||
let isNumber = Util_1.Util._isNumber(val);
|
||||
let isValidArray = Util_1.Util._isArray(val) && val.length == noOfElements;
|
||||
if (!isNumber && !isValidArray) {
|
||||
Util_1.Util.warn(_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be a number or Array<number>(' +
|
||||
noOfElements +
|
||||
')');
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getNumberOrArrayOfNumbersValidator = getNumberOrArrayOfNumbersValidator;
|
||||
function getNumberOrAutoValidator() {
|
||||
if (Global_1.Konva.isUnminified) {
|
||||
return function (val, attr) {
|
||||
var isNumber = Util_1.Util._isNumber(val);
|
||||
var isAuto = val === 'auto';
|
||||
if (!(isNumber || isAuto)) {
|
||||
Util_1.Util.warn(_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be a number or "auto".');
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getNumberOrAutoValidator = getNumberOrAutoValidator;
|
||||
function getStringValidator() {
|
||||
if (Global_1.Konva.isUnminified) {
|
||||
return function (val, attr) {
|
||||
if (!Util_1.Util._isString(val)) {
|
||||
Util_1.Util.warn(_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be a string.');
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getStringValidator = getStringValidator;
|
||||
function getStringOrGradientValidator() {
|
||||
if (Global_1.Konva.isUnminified) {
|
||||
return function (val, attr) {
|
||||
const isString = Util_1.Util._isString(val);
|
||||
const isGradient = Object.prototype.toString.call(val) === '[object CanvasGradient]' ||
|
||||
(val && val.addColorStop);
|
||||
if (!(isString || isGradient)) {
|
||||
Util_1.Util.warn(_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be a string or a native gradient.');
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getStringOrGradientValidator = getStringOrGradientValidator;
|
||||
function getFunctionValidator() {
|
||||
if (Global_1.Konva.isUnminified) {
|
||||
return function (val, attr) {
|
||||
if (!Util_1.Util._isFunction(val)) {
|
||||
Util_1.Util.warn(_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be a function.');
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getFunctionValidator = getFunctionValidator;
|
||||
function getNumberArrayValidator() {
|
||||
if (Global_1.Konva.isUnminified) {
|
||||
return function (val, attr) {
|
||||
if (!Util_1.Util._isArray(val)) {
|
||||
Util_1.Util.warn(_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be a array of numbers.');
|
||||
}
|
||||
else {
|
||||
val.forEach(function (item) {
|
||||
if (!Util_1.Util._isNumber(item)) {
|
||||
Util_1.Util.warn('"' +
|
||||
attr +
|
||||
'" attribute has non numeric element ' +
|
||||
item +
|
||||
'. Make sure that all elements are numbers.');
|
||||
}
|
||||
});
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getNumberArrayValidator = getNumberArrayValidator;
|
||||
function getBooleanValidator() {
|
||||
if (Global_1.Konva.isUnminified) {
|
||||
return function (val, attr) {
|
||||
var isBool = val === true || val === false;
|
||||
if (!isBool) {
|
||||
Util_1.Util.warn(_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be a boolean.');
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getBooleanValidator = getBooleanValidator;
|
||||
function getComponentValidator(components) {
|
||||
if (Global_1.Konva.isUnminified) {
|
||||
return function (val, attr) {
|
||||
if (!Util_1.Util.isObject(val)) {
|
||||
Util_1.Util.warn(_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be an object with properties ' +
|
||||
components);
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.getComponentValidator = getComponentValidator;
|
||||
147
node_modules/konva/cmj/_CoreInternals.d.ts
generated
vendored
Normal file
147
node_modules/konva/cmj/_CoreInternals.d.ts
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
import { Transform } from './Util';
|
||||
import { Node } from './Node';
|
||||
import { Container } from './Container';
|
||||
import { Stage } from './Stage';
|
||||
import { Layer } from './Layer';
|
||||
import { FastLayer } from './FastLayer';
|
||||
import { Group } from './Group';
|
||||
import { Shape } from './Shape';
|
||||
import { Animation } from './Animation';
|
||||
import { Tween } from './Tween';
|
||||
import { Context } from './Context';
|
||||
import { Canvas } from './Canvas';
|
||||
export declare const Konva: {
|
||||
_global: any;
|
||||
version: string;
|
||||
isBrowser: boolean;
|
||||
isUnminified: boolean;
|
||||
dblClickWindow: number;
|
||||
getAngle(angle: number): number;
|
||||
enableTrace: boolean;
|
||||
pointerEventsEnabled: boolean;
|
||||
autoDrawEnabled: boolean;
|
||||
hitOnDragEnabled: boolean;
|
||||
capturePointerEventsEnabled: boolean;
|
||||
_mouseListenClick: boolean;
|
||||
_touchListenClick: boolean;
|
||||
_pointerListenClick: boolean;
|
||||
_mouseInDblClickWindow: boolean;
|
||||
_touchInDblClickWindow: boolean;
|
||||
_pointerInDblClickWindow: boolean;
|
||||
_mouseDblClickPointerId: any;
|
||||
_touchDblClickPointerId: any;
|
||||
_pointerDblClickPointerId: any;
|
||||
pixelRatio: number;
|
||||
dragDistance: number;
|
||||
angleDeg: boolean;
|
||||
showWarnings: boolean;
|
||||
dragButtons: number[];
|
||||
isDragging(): any;
|
||||
isDragReady(): boolean;
|
||||
document: any;
|
||||
_injectGlobal(Konva: any): void;
|
||||
} & {
|
||||
Util: {
|
||||
_isElement(obj: any): obj is Element;
|
||||
_isFunction(obj: any): boolean;
|
||||
_isPlainObject(obj: any): boolean;
|
||||
_isArray(obj: any): obj is any[];
|
||||
_isNumber(obj: any): obj is number;
|
||||
_isString(obj: any): obj is string;
|
||||
_isBoolean(obj: any): obj is boolean;
|
||||
isObject(val: any): val is Object;
|
||||
isValidSelector(selector: any): boolean;
|
||||
_sign(number: number): 1 | -1;
|
||||
requestAnimFrame(callback: Function): void;
|
||||
createCanvasElement(): HTMLCanvasElement;
|
||||
createImageElement(): HTMLImageElement;
|
||||
_isInDocument(el: any): boolean;
|
||||
_urlToImage(url: string, callback: Function): void;
|
||||
_rgbToHex(r: number, g: number, b: number): string;
|
||||
_hexToRgb(hex: string): import("./types").RGB;
|
||||
getRandomColor(): string;
|
||||
getRGB(color: string): import("./types").RGB;
|
||||
colorToRGBA(str: string): import("./types").RGBA;
|
||||
_namedColorToRBA(str: string): {
|
||||
r: any;
|
||||
g: any;
|
||||
b: any;
|
||||
a: number;
|
||||
};
|
||||
_rgbColorToRGBA(str: string): import("./types").RGBA;
|
||||
_rgbaColorToRGBA(str: string): import("./types").RGBA;
|
||||
_hex6ColorToRGBA(str: string): import("./types").RGBA;
|
||||
_hex3ColorToRGBA(str: string): import("./types").RGBA;
|
||||
_hslColorToRGBA(str: string): import("./types").RGBA;
|
||||
haveIntersection(r1: import("./types").IRect, r2: import("./types").IRect): boolean;
|
||||
cloneObject<Any>(obj: Any): Any;
|
||||
cloneArray(arr: any[]): any[];
|
||||
degToRad(deg: number): number;
|
||||
radToDeg(rad: number): number;
|
||||
_degToRad(deg: number): number;
|
||||
_radToDeg(rad: number): number;
|
||||
_getRotation(radians: any): any;
|
||||
_capitalize(str: string): string;
|
||||
throw(str: string): never;
|
||||
error(str: string): void;
|
||||
warn(str: string): void;
|
||||
each(obj: any, func: any): void;
|
||||
_inRange(val: any, left: any, right: any): boolean;
|
||||
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
||||
_getProjectionToLine(pt: import("./types").Vector2d, line: any, isClosed: any): import("./types").Vector2d;
|
||||
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): any[];
|
||||
_prepareToStringify(obj: any): any;
|
||||
_assign<T, U>(target: T, source: U): T & U;
|
||||
_getFirstPointerId(evt: any): any;
|
||||
};
|
||||
Transform: typeof Transform;
|
||||
Node: typeof Node;
|
||||
Container: typeof Container;
|
||||
Stage: typeof Stage;
|
||||
stages: Stage[];
|
||||
Layer: typeof Layer;
|
||||
FastLayer: typeof FastLayer;
|
||||
Group: typeof Group;
|
||||
DD: {
|
||||
readonly isDragging: boolean;
|
||||
justDragged: boolean;
|
||||
readonly node: Node<import("./Node").NodeConfig>;
|
||||
_dragElements: Map<number, {
|
||||
node: Node<import("./Node").NodeConfig>;
|
||||
startPointerPos: import("./types").Vector2d;
|
||||
offset: import("./types").Vector2d;
|
||||
pointerId?: number;
|
||||
dragStatus: "ready" | "dragging" | "stopped";
|
||||
}>;
|
||||
_drag(evt: any): void;
|
||||
_endDragBefore(evt?: any): void;
|
||||
_endDragAfter(evt: any): void;
|
||||
};
|
||||
Shape: typeof Shape;
|
||||
shapes: {
|
||||
[key: string]: Shape<import("./Shape").ShapeConfig>;
|
||||
};
|
||||
Animation: typeof Animation;
|
||||
Tween: typeof Tween;
|
||||
Easings: {
|
||||
BackEaseIn(t: any, b: any, c: any, d: any): any;
|
||||
BackEaseOut(t: any, b: any, c: any, d: any): any;
|
||||
BackEaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
ElasticEaseIn(t: any, b: any, c: any, d: any, a: any, p: any): any;
|
||||
ElasticEaseOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
|
||||
ElasticEaseInOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
|
||||
BounceEaseOut(t: any, b: any, c: any, d: any): any;
|
||||
BounceEaseIn(t: any, b: any, c: any, d: any): any;
|
||||
BounceEaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
EaseIn(t: any, b: any, c: any, d: any): any;
|
||||
EaseOut(t: any, b: any, c: any, d: any): any;
|
||||
EaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
StrongEaseIn(t: any, b: any, c: any, d: any): any;
|
||||
StrongEaseOut(t: any, b: any, c: any, d: any): any;
|
||||
StrongEaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
Linear(t: any, b: any, c: any, d: any): any;
|
||||
};
|
||||
Context: typeof Context;
|
||||
Canvas: typeof Canvas;
|
||||
};
|
||||
export default Konva;
|
||||
37
node_modules/konva/cmj/_CoreInternals.js
generated
vendored
Normal file
37
node_modules/konva/cmj/_CoreInternals.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Konva = void 0;
|
||||
const Global_1 = require("./Global");
|
||||
const Util_1 = require("./Util");
|
||||
const Node_1 = require("./Node");
|
||||
const Container_1 = require("./Container");
|
||||
const Stage_1 = require("./Stage");
|
||||
const Layer_1 = require("./Layer");
|
||||
const FastLayer_1 = require("./FastLayer");
|
||||
const Group_1 = require("./Group");
|
||||
const DragAndDrop_1 = require("./DragAndDrop");
|
||||
const Shape_1 = require("./Shape");
|
||||
const Animation_1 = require("./Animation");
|
||||
const Tween_1 = require("./Tween");
|
||||
const Context_1 = require("./Context");
|
||||
const Canvas_1 = require("./Canvas");
|
||||
exports.Konva = Util_1.Util._assign(Global_1.Konva, {
|
||||
Util: Util_1.Util,
|
||||
Transform: Util_1.Transform,
|
||||
Node: Node_1.Node,
|
||||
Container: Container_1.Container,
|
||||
Stage: Stage_1.Stage,
|
||||
stages: Stage_1.stages,
|
||||
Layer: Layer_1.Layer,
|
||||
FastLayer: FastLayer_1.FastLayer,
|
||||
Group: Group_1.Group,
|
||||
DD: DragAndDrop_1.DD,
|
||||
Shape: Shape_1.Shape,
|
||||
shapes: Shape_1.shapes,
|
||||
Animation: Animation_1.Animation,
|
||||
Tween: Tween_1.Tween,
|
||||
Easings: Tween_1.Easings,
|
||||
Context: Context_1.Context,
|
||||
Canvas: Canvas_1.Canvas,
|
||||
});
|
||||
exports.default = exports.Konva;
|
||||
191
node_modules/konva/cmj/_FullInternals.d.ts
generated
vendored
Normal file
191
node_modules/konva/cmj/_FullInternals.d.ts
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
import { Arc } from './shapes/Arc';
|
||||
import { Arrow } from './shapes/Arrow';
|
||||
import { Circle } from './shapes/Circle';
|
||||
import { Ellipse } from './shapes/Ellipse';
|
||||
import { Image } from './shapes/Image';
|
||||
import { Label, Tag } from './shapes/Label';
|
||||
import { Line } from './shapes/Line';
|
||||
import { Path } from './shapes/Path';
|
||||
import { Rect } from './shapes/Rect';
|
||||
import { RegularPolygon } from './shapes/RegularPolygon';
|
||||
import { Ring } from './shapes/Ring';
|
||||
import { Sprite } from './shapes/Sprite';
|
||||
import { Star } from './shapes/Star';
|
||||
import { Text } from './shapes/Text';
|
||||
import { TextPath } from './shapes/TextPath';
|
||||
import { Transformer } from './shapes/Transformer';
|
||||
import { Wedge } from './shapes/Wedge';
|
||||
export declare const Konva: {
|
||||
_global: any;
|
||||
version: string;
|
||||
isBrowser: boolean;
|
||||
isUnminified: boolean;
|
||||
dblClickWindow: number;
|
||||
getAngle(angle: number): number;
|
||||
enableTrace: boolean;
|
||||
pointerEventsEnabled: boolean;
|
||||
autoDrawEnabled: boolean;
|
||||
hitOnDragEnabled: boolean;
|
||||
capturePointerEventsEnabled: boolean;
|
||||
_mouseListenClick: boolean;
|
||||
_touchListenClick: boolean;
|
||||
_pointerListenClick: boolean;
|
||||
_mouseInDblClickWindow: boolean;
|
||||
_touchInDblClickWindow: boolean;
|
||||
_pointerInDblClickWindow: boolean;
|
||||
_mouseDblClickPointerId: any;
|
||||
_touchDblClickPointerId: any;
|
||||
_pointerDblClickPointerId: any;
|
||||
pixelRatio: number;
|
||||
dragDistance: number;
|
||||
angleDeg: boolean;
|
||||
showWarnings: boolean;
|
||||
dragButtons: number[];
|
||||
isDragging(): any;
|
||||
isDragReady(): boolean;
|
||||
document: any;
|
||||
_injectGlobal(Konva: any): void;
|
||||
} & {
|
||||
Util: {
|
||||
_isElement(obj: any): obj is Element;
|
||||
_isFunction(obj: any): boolean;
|
||||
_isPlainObject(obj: any): boolean;
|
||||
_isArray(obj: any): obj is any[];
|
||||
_isNumber(obj: any): obj is number;
|
||||
_isString(obj: any): obj is string;
|
||||
_isBoolean(obj: any): obj is boolean;
|
||||
isObject(val: any): val is Object;
|
||||
isValidSelector(selector: any): boolean;
|
||||
_sign(number: number): 1 | -1;
|
||||
requestAnimFrame(callback: Function): void;
|
||||
createCanvasElement(): HTMLCanvasElement;
|
||||
createImageElement(): HTMLImageElement;
|
||||
_isInDocument(el: any): boolean;
|
||||
_urlToImage(url: string, callback: Function): void;
|
||||
_rgbToHex(r: number, g: number, b: number): string;
|
||||
_hexToRgb(hex: string): import("./types").RGB;
|
||||
getRandomColor(): string;
|
||||
getRGB(color: string): import("./types").RGB;
|
||||
colorToRGBA(str: string): import("./types").RGBA;
|
||||
_namedColorToRBA(str: string): {
|
||||
r: any;
|
||||
g: any;
|
||||
b: any;
|
||||
a: number;
|
||||
};
|
||||
_rgbColorToRGBA(str: string): import("./types").RGBA;
|
||||
_rgbaColorToRGBA(str: string): import("./types").RGBA;
|
||||
_hex6ColorToRGBA(str: string): import("./types").RGBA;
|
||||
_hex3ColorToRGBA(str: string): import("./types").RGBA;
|
||||
_hslColorToRGBA(str: string): import("./types").RGBA;
|
||||
haveIntersection(r1: import("./types").IRect, r2: import("./types").IRect): boolean;
|
||||
cloneObject<Any>(obj: Any): Any;
|
||||
cloneArray(arr: any[]): any[];
|
||||
degToRad(deg: number): number;
|
||||
radToDeg(rad: number): number;
|
||||
_degToRad(deg: number): number;
|
||||
_radToDeg(rad: number): number;
|
||||
_getRotation(radians: any): any;
|
||||
_capitalize(str: string): string;
|
||||
throw(str: string): never;
|
||||
error(str: string): void;
|
||||
warn(str: string): void;
|
||||
each(obj: any, func: any): void;
|
||||
_inRange(val: any, left: any, right: any): boolean;
|
||||
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
||||
_getProjectionToLine(pt: import("./types").Vector2d, line: any, isClosed: any): import("./types").Vector2d;
|
||||
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): any[];
|
||||
_prepareToStringify(obj: any): any;
|
||||
_assign<T, U>(target: T, source: U): T & U;
|
||||
_getFirstPointerId(evt: any): any;
|
||||
};
|
||||
Transform: typeof import("./Util").Transform;
|
||||
Node: typeof import("./Node").Node;
|
||||
Container: typeof import("./Container").Container;
|
||||
Stage: typeof import("./Stage").Stage;
|
||||
stages: import("./Stage").Stage[];
|
||||
Layer: typeof import("./Layer").Layer;
|
||||
FastLayer: typeof import("./FastLayer").FastLayer;
|
||||
Group: typeof import("./Group").Group;
|
||||
DD: {
|
||||
readonly isDragging: boolean;
|
||||
justDragged: boolean;
|
||||
readonly node: import("./Node").Node<import("./Node").NodeConfig>;
|
||||
_dragElements: Map<number, {
|
||||
node: import("./Node").Node<import("./Node").NodeConfig>;
|
||||
startPointerPos: import("./types").Vector2d;
|
||||
offset: import("./types").Vector2d;
|
||||
pointerId?: number;
|
||||
dragStatus: "ready" | "dragging" | "stopped";
|
||||
}>;
|
||||
_drag(evt: any): void;
|
||||
_endDragBefore(evt?: any): void;
|
||||
_endDragAfter(evt: any): void;
|
||||
};
|
||||
Shape: typeof import("./Shape").Shape;
|
||||
shapes: {
|
||||
[key: string]: import("./Shape").Shape<import("./Shape").ShapeConfig>;
|
||||
};
|
||||
Animation: typeof import("./Animation").Animation;
|
||||
Tween: typeof import("./Tween").Tween;
|
||||
Easings: {
|
||||
BackEaseIn(t: any, b: any, c: any, d: any): any;
|
||||
BackEaseOut(t: any, b: any, c: any, d: any): any;
|
||||
BackEaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
ElasticEaseIn(t: any, b: any, c: any, d: any, a: any, p: any): any;
|
||||
ElasticEaseOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
|
||||
ElasticEaseInOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
|
||||
BounceEaseOut(t: any, b: any, c: any, d: any): any;
|
||||
BounceEaseIn(t: any, b: any, c: any, d: any): any;
|
||||
BounceEaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
EaseIn(t: any, b: any, c: any, d: any): any;
|
||||
EaseOut(t: any, b: any, c: any, d: any): any;
|
||||
EaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
StrongEaseIn(t: any, b: any, c: any, d: any): any;
|
||||
StrongEaseOut(t: any, b: any, c: any, d: any): any;
|
||||
StrongEaseInOut(t: any, b: any, c: any, d: any): any;
|
||||
Linear(t: any, b: any, c: any, d: any): any;
|
||||
};
|
||||
Context: typeof import("./Context").Context;
|
||||
Canvas: typeof import("./Canvas").Canvas;
|
||||
} & {
|
||||
Arc: typeof Arc;
|
||||
Arrow: typeof Arrow;
|
||||
Circle: typeof Circle;
|
||||
Ellipse: typeof Ellipse;
|
||||
Image: typeof Image;
|
||||
Label: typeof Label;
|
||||
Tag: typeof Tag;
|
||||
Line: typeof Line;
|
||||
Path: typeof Path;
|
||||
Rect: typeof Rect;
|
||||
RegularPolygon: typeof RegularPolygon;
|
||||
Ring: typeof Ring;
|
||||
Sprite: typeof Sprite;
|
||||
Star: typeof Star;
|
||||
Text: typeof Text;
|
||||
TextPath: typeof TextPath;
|
||||
Transformer: typeof Transformer;
|
||||
Wedge: typeof Wedge;
|
||||
Filters: {
|
||||
Blur: import("./Node").Filter;
|
||||
Brighten: import("./Node").Filter;
|
||||
Contrast: import("./Node").Filter;
|
||||
Emboss: import("./Node").Filter;
|
||||
Enhance: import("./Node").Filter;
|
||||
Grayscale: import("./Node").Filter;
|
||||
HSL: import("./Node").Filter;
|
||||
HSV: import("./Node").Filter;
|
||||
Invert: import("./Node").Filter;
|
||||
Kaleidoscope: import("./Node").Filter;
|
||||
Mask: import("./Node").Filter;
|
||||
Noise: import("./Node").Filter;
|
||||
Pixelate: import("./Node").Filter;
|
||||
Posterize: import("./Node").Filter;
|
||||
RGB: import("./Node").Filter;
|
||||
RGBA: import("./Node").Filter;
|
||||
Sepia: import("./Node").Filter;
|
||||
Solarize: import("./Node").Filter;
|
||||
Threshold: import("./Node").Filter;
|
||||
};
|
||||
};
|
||||
81
node_modules/konva/cmj/_FullInternals.js
generated
vendored
Normal file
81
node_modules/konva/cmj/_FullInternals.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Konva = void 0;
|
||||
const _CoreInternals_1 = require("./_CoreInternals");
|
||||
const Arc_1 = require("./shapes/Arc");
|
||||
const Arrow_1 = require("./shapes/Arrow");
|
||||
const Circle_1 = require("./shapes/Circle");
|
||||
const Ellipse_1 = require("./shapes/Ellipse");
|
||||
const Image_1 = require("./shapes/Image");
|
||||
const Label_1 = require("./shapes/Label");
|
||||
const Line_1 = require("./shapes/Line");
|
||||
const Path_1 = require("./shapes/Path");
|
||||
const Rect_1 = require("./shapes/Rect");
|
||||
const RegularPolygon_1 = require("./shapes/RegularPolygon");
|
||||
const Ring_1 = require("./shapes/Ring");
|
||||
const Sprite_1 = require("./shapes/Sprite");
|
||||
const Star_1 = require("./shapes/Star");
|
||||
const Text_1 = require("./shapes/Text");
|
||||
const TextPath_1 = require("./shapes/TextPath");
|
||||
const Transformer_1 = require("./shapes/Transformer");
|
||||
const Wedge_1 = require("./shapes/Wedge");
|
||||
const Blur_1 = require("./filters/Blur");
|
||||
const Brighten_1 = require("./filters/Brighten");
|
||||
const Contrast_1 = require("./filters/Contrast");
|
||||
const Emboss_1 = require("./filters/Emboss");
|
||||
const Enhance_1 = require("./filters/Enhance");
|
||||
const Grayscale_1 = require("./filters/Grayscale");
|
||||
const HSL_1 = require("./filters/HSL");
|
||||
const HSV_1 = require("./filters/HSV");
|
||||
const Invert_1 = require("./filters/Invert");
|
||||
const Kaleidoscope_1 = require("./filters/Kaleidoscope");
|
||||
const Mask_1 = require("./filters/Mask");
|
||||
const Noise_1 = require("./filters/Noise");
|
||||
const Pixelate_1 = require("./filters/Pixelate");
|
||||
const Posterize_1 = require("./filters/Posterize");
|
||||
const RGB_1 = require("./filters/RGB");
|
||||
const RGBA_1 = require("./filters/RGBA");
|
||||
const Sepia_1 = require("./filters/Sepia");
|
||||
const Solarize_1 = require("./filters/Solarize");
|
||||
const Threshold_1 = require("./filters/Threshold");
|
||||
exports.Konva = _CoreInternals_1.Konva.Util._assign(_CoreInternals_1.Konva, {
|
||||
Arc: Arc_1.Arc,
|
||||
Arrow: Arrow_1.Arrow,
|
||||
Circle: Circle_1.Circle,
|
||||
Ellipse: Ellipse_1.Ellipse,
|
||||
Image: Image_1.Image,
|
||||
Label: Label_1.Label,
|
||||
Tag: Label_1.Tag,
|
||||
Line: Line_1.Line,
|
||||
Path: Path_1.Path,
|
||||
Rect: Rect_1.Rect,
|
||||
RegularPolygon: RegularPolygon_1.RegularPolygon,
|
||||
Ring: Ring_1.Ring,
|
||||
Sprite: Sprite_1.Sprite,
|
||||
Star: Star_1.Star,
|
||||
Text: Text_1.Text,
|
||||
TextPath: TextPath_1.TextPath,
|
||||
Transformer: Transformer_1.Transformer,
|
||||
Wedge: Wedge_1.Wedge,
|
||||
Filters: {
|
||||
Blur: Blur_1.Blur,
|
||||
Brighten: Brighten_1.Brighten,
|
||||
Contrast: Contrast_1.Contrast,
|
||||
Emboss: Emboss_1.Emboss,
|
||||
Enhance: Enhance_1.Enhance,
|
||||
Grayscale: Grayscale_1.Grayscale,
|
||||
HSL: HSL_1.HSL,
|
||||
HSV: HSV_1.HSV,
|
||||
Invert: Invert_1.Invert,
|
||||
Kaleidoscope: Kaleidoscope_1.Kaleidoscope,
|
||||
Mask: Mask_1.Mask,
|
||||
Noise: Noise_1.Noise,
|
||||
Pixelate: Pixelate_1.Pixelate,
|
||||
Posterize: Posterize_1.Posterize,
|
||||
RGB: RGB_1.RGB,
|
||||
RGBA: RGBA_1.RGBA,
|
||||
Sepia: Sepia_1.Sepia,
|
||||
Solarize: Solarize_1.Solarize,
|
||||
Threshold: Threshold_1.Threshold,
|
||||
},
|
||||
});
|
||||
2
node_modules/konva/cmj/filters/Blur.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Blur.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Blur: Filter;
|
||||
701
node_modules/konva/cmj/filters/Blur.js
generated
vendored
Normal file
701
node_modules/konva/cmj/filters/Blur.js
generated
vendored
Normal file
@@ -0,0 +1,701 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Blur = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
function BlurStack() {
|
||||
this.r = 0;
|
||||
this.g = 0;
|
||||
this.b = 0;
|
||||
this.a = 0;
|
||||
this.next = null;
|
||||
}
|
||||
var mul_table = [
|
||||
512,
|
||||
512,
|
||||
456,
|
||||
512,
|
||||
328,
|
||||
456,
|
||||
335,
|
||||
512,
|
||||
405,
|
||||
328,
|
||||
271,
|
||||
456,
|
||||
388,
|
||||
335,
|
||||
292,
|
||||
512,
|
||||
454,
|
||||
405,
|
||||
364,
|
||||
328,
|
||||
298,
|
||||
271,
|
||||
496,
|
||||
456,
|
||||
420,
|
||||
388,
|
||||
360,
|
||||
335,
|
||||
312,
|
||||
292,
|
||||
273,
|
||||
512,
|
||||
482,
|
||||
454,
|
||||
428,
|
||||
405,
|
||||
383,
|
||||
364,
|
||||
345,
|
||||
328,
|
||||
312,
|
||||
298,
|
||||
284,
|
||||
271,
|
||||
259,
|
||||
496,
|
||||
475,
|
||||
456,
|
||||
437,
|
||||
420,
|
||||
404,
|
||||
388,
|
||||
374,
|
||||
360,
|
||||
347,
|
||||
335,
|
||||
323,
|
||||
312,
|
||||
302,
|
||||
292,
|
||||
282,
|
||||
273,
|
||||
265,
|
||||
512,
|
||||
497,
|
||||
482,
|
||||
468,
|
||||
454,
|
||||
441,
|
||||
428,
|
||||
417,
|
||||
405,
|
||||
394,
|
||||
383,
|
||||
373,
|
||||
364,
|
||||
354,
|
||||
345,
|
||||
337,
|
||||
328,
|
||||
320,
|
||||
312,
|
||||
305,
|
||||
298,
|
||||
291,
|
||||
284,
|
||||
278,
|
||||
271,
|
||||
265,
|
||||
259,
|
||||
507,
|
||||
496,
|
||||
485,
|
||||
475,
|
||||
465,
|
||||
456,
|
||||
446,
|
||||
437,
|
||||
428,
|
||||
420,
|
||||
412,
|
||||
404,
|
||||
396,
|
||||
388,
|
||||
381,
|
||||
374,
|
||||
367,
|
||||
360,
|
||||
354,
|
||||
347,
|
||||
341,
|
||||
335,
|
||||
329,
|
||||
323,
|
||||
318,
|
||||
312,
|
||||
307,
|
||||
302,
|
||||
297,
|
||||
292,
|
||||
287,
|
||||
282,
|
||||
278,
|
||||
273,
|
||||
269,
|
||||
265,
|
||||
261,
|
||||
512,
|
||||
505,
|
||||
497,
|
||||
489,
|
||||
482,
|
||||
475,
|
||||
468,
|
||||
461,
|
||||
454,
|
||||
447,
|
||||
441,
|
||||
435,
|
||||
428,
|
||||
422,
|
||||
417,
|
||||
411,
|
||||
405,
|
||||
399,
|
||||
394,
|
||||
389,
|
||||
383,
|
||||
378,
|
||||
373,
|
||||
368,
|
||||
364,
|
||||
359,
|
||||
354,
|
||||
350,
|
||||
345,
|
||||
341,
|
||||
337,
|
||||
332,
|
||||
328,
|
||||
324,
|
||||
320,
|
||||
316,
|
||||
312,
|
||||
309,
|
||||
305,
|
||||
301,
|
||||
298,
|
||||
294,
|
||||
291,
|
||||
287,
|
||||
284,
|
||||
281,
|
||||
278,
|
||||
274,
|
||||
271,
|
||||
268,
|
||||
265,
|
||||
262,
|
||||
259,
|
||||
257,
|
||||
507,
|
||||
501,
|
||||
496,
|
||||
491,
|
||||
485,
|
||||
480,
|
||||
475,
|
||||
470,
|
||||
465,
|
||||
460,
|
||||
456,
|
||||
451,
|
||||
446,
|
||||
442,
|
||||
437,
|
||||
433,
|
||||
428,
|
||||
424,
|
||||
420,
|
||||
416,
|
||||
412,
|
||||
408,
|
||||
404,
|
||||
400,
|
||||
396,
|
||||
392,
|
||||
388,
|
||||
385,
|
||||
381,
|
||||
377,
|
||||
374,
|
||||
370,
|
||||
367,
|
||||
363,
|
||||
360,
|
||||
357,
|
||||
354,
|
||||
350,
|
||||
347,
|
||||
344,
|
||||
341,
|
||||
338,
|
||||
335,
|
||||
332,
|
||||
329,
|
||||
326,
|
||||
323,
|
||||
320,
|
||||
318,
|
||||
315,
|
||||
312,
|
||||
310,
|
||||
307,
|
||||
304,
|
||||
302,
|
||||
299,
|
||||
297,
|
||||
294,
|
||||
292,
|
||||
289,
|
||||
287,
|
||||
285,
|
||||
282,
|
||||
280,
|
||||
278,
|
||||
275,
|
||||
273,
|
||||
271,
|
||||
269,
|
||||
267,
|
||||
265,
|
||||
263,
|
||||
261,
|
||||
259,
|
||||
];
|
||||
var shg_table = [
|
||||
9,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
13,
|
||||
14,
|
||||
14,
|
||||
15,
|
||||
15,
|
||||
15,
|
||||
15,
|
||||
16,
|
||||
16,
|
||||
16,
|
||||
16,
|
||||
17,
|
||||
17,
|
||||
17,
|
||||
17,
|
||||
17,
|
||||
17,
|
||||
17,
|
||||
18,
|
||||
18,
|
||||
18,
|
||||
18,
|
||||
18,
|
||||
18,
|
||||
18,
|
||||
18,
|
||||
18,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
19,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
21,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
22,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
23,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
];
|
||||
function filterGaussBlurRGBA(imageData, radius) {
|
||||
var pixels = imageData.data, width = imageData.width, height = imageData.height;
|
||||
var x, y, i, p, yp, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs;
|
||||
var div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(), stackEnd = null, stack = stackStart, stackIn = null, stackOut = null, mul_sum = mul_table[radius], shg_sum = shg_table[radius];
|
||||
for (i = 1; i < div; i++) {
|
||||
stack = stack.next = new BlurStack();
|
||||
if (i === radiusPlus1) {
|
||||
stackEnd = stack;
|
||||
}
|
||||
}
|
||||
stack.next = stackStart;
|
||||
yw = yi = 0;
|
||||
for (y = 0; y < height; y++) {
|
||||
r_in_sum = g_in_sum = b_in_sum = a_in_sum = r_sum = g_sum = b_sum = a_sum = 0;
|
||||
r_out_sum = radiusPlus1 * (pr = pixels[yi]);
|
||||
g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]);
|
||||
b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]);
|
||||
a_out_sum = radiusPlus1 * (pa = pixels[yi + 3]);
|
||||
r_sum += sumFactor * pr;
|
||||
g_sum += sumFactor * pg;
|
||||
b_sum += sumFactor * pb;
|
||||
a_sum += sumFactor * pa;
|
||||
stack = stackStart;
|
||||
for (i = 0; i < radiusPlus1; i++) {
|
||||
stack.r = pr;
|
||||
stack.g = pg;
|
||||
stack.b = pb;
|
||||
stack.a = pa;
|
||||
stack = stack.next;
|
||||
}
|
||||
for (i = 1; i < radiusPlus1; i++) {
|
||||
p = yi + ((widthMinus1 < i ? widthMinus1 : i) << 2);
|
||||
r_sum += (stack.r = pr = pixels[p]) * (rbs = radiusPlus1 - i);
|
||||
g_sum += (stack.g = pg = pixels[p + 1]) * rbs;
|
||||
b_sum += (stack.b = pb = pixels[p + 2]) * rbs;
|
||||
a_sum += (stack.a = pa = pixels[p + 3]) * rbs;
|
||||
r_in_sum += pr;
|
||||
g_in_sum += pg;
|
||||
b_in_sum += pb;
|
||||
a_in_sum += pa;
|
||||
stack = stack.next;
|
||||
}
|
||||
stackIn = stackStart;
|
||||
stackOut = stackEnd;
|
||||
for (x = 0; x < width; x++) {
|
||||
pixels[yi + 3] = pa = (a_sum * mul_sum) >> shg_sum;
|
||||
if (pa !== 0) {
|
||||
pa = 255 / pa;
|
||||
pixels[yi] = ((r_sum * mul_sum) >> shg_sum) * pa;
|
||||
pixels[yi + 1] = ((g_sum * mul_sum) >> shg_sum) * pa;
|
||||
pixels[yi + 2] = ((b_sum * mul_sum) >> shg_sum) * pa;
|
||||
}
|
||||
else {
|
||||
pixels[yi] = pixels[yi + 1] = pixels[yi + 2] = 0;
|
||||
}
|
||||
r_sum -= r_out_sum;
|
||||
g_sum -= g_out_sum;
|
||||
b_sum -= b_out_sum;
|
||||
a_sum -= a_out_sum;
|
||||
r_out_sum -= stackIn.r;
|
||||
g_out_sum -= stackIn.g;
|
||||
b_out_sum -= stackIn.b;
|
||||
a_out_sum -= stackIn.a;
|
||||
p = (yw + ((p = x + radius + 1) < widthMinus1 ? p : widthMinus1)) << 2;
|
||||
r_in_sum += stackIn.r = pixels[p];
|
||||
g_in_sum += stackIn.g = pixels[p + 1];
|
||||
b_in_sum += stackIn.b = pixels[p + 2];
|
||||
a_in_sum += stackIn.a = pixels[p + 3];
|
||||
r_sum += r_in_sum;
|
||||
g_sum += g_in_sum;
|
||||
b_sum += b_in_sum;
|
||||
a_sum += a_in_sum;
|
||||
stackIn = stackIn.next;
|
||||
r_out_sum += pr = stackOut.r;
|
||||
g_out_sum += pg = stackOut.g;
|
||||
b_out_sum += pb = stackOut.b;
|
||||
a_out_sum += pa = stackOut.a;
|
||||
r_in_sum -= pr;
|
||||
g_in_sum -= pg;
|
||||
b_in_sum -= pb;
|
||||
a_in_sum -= pa;
|
||||
stackOut = stackOut.next;
|
||||
yi += 4;
|
||||
}
|
||||
yw += width;
|
||||
}
|
||||
for (x = 0; x < width; x++) {
|
||||
g_in_sum = b_in_sum = a_in_sum = r_in_sum = g_sum = b_sum = a_sum = r_sum = 0;
|
||||
yi = x << 2;
|
||||
r_out_sum = radiusPlus1 * (pr = pixels[yi]);
|
||||
g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]);
|
||||
b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]);
|
||||
a_out_sum = radiusPlus1 * (pa = pixels[yi + 3]);
|
||||
r_sum += sumFactor * pr;
|
||||
g_sum += sumFactor * pg;
|
||||
b_sum += sumFactor * pb;
|
||||
a_sum += sumFactor * pa;
|
||||
stack = stackStart;
|
||||
for (i = 0; i < radiusPlus1; i++) {
|
||||
stack.r = pr;
|
||||
stack.g = pg;
|
||||
stack.b = pb;
|
||||
stack.a = pa;
|
||||
stack = stack.next;
|
||||
}
|
||||
yp = width;
|
||||
for (i = 1; i <= radius; i++) {
|
||||
yi = (yp + x) << 2;
|
||||
r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i);
|
||||
g_sum += (stack.g = pg = pixels[yi + 1]) * rbs;
|
||||
b_sum += (stack.b = pb = pixels[yi + 2]) * rbs;
|
||||
a_sum += (stack.a = pa = pixels[yi + 3]) * rbs;
|
||||
r_in_sum += pr;
|
||||
g_in_sum += pg;
|
||||
b_in_sum += pb;
|
||||
a_in_sum += pa;
|
||||
stack = stack.next;
|
||||
if (i < heightMinus1) {
|
||||
yp += width;
|
||||
}
|
||||
}
|
||||
yi = x;
|
||||
stackIn = stackStart;
|
||||
stackOut = stackEnd;
|
||||
for (y = 0; y < height; y++) {
|
||||
p = yi << 2;
|
||||
pixels[p + 3] = pa = (a_sum * mul_sum) >> shg_sum;
|
||||
if (pa > 0) {
|
||||
pa = 255 / pa;
|
||||
pixels[p] = ((r_sum * mul_sum) >> shg_sum) * pa;
|
||||
pixels[p + 1] = ((g_sum * mul_sum) >> shg_sum) * pa;
|
||||
pixels[p + 2] = ((b_sum * mul_sum) >> shg_sum) * pa;
|
||||
}
|
||||
else {
|
||||
pixels[p] = pixels[p + 1] = pixels[p + 2] = 0;
|
||||
}
|
||||
r_sum -= r_out_sum;
|
||||
g_sum -= g_out_sum;
|
||||
b_sum -= b_out_sum;
|
||||
a_sum -= a_out_sum;
|
||||
r_out_sum -= stackIn.r;
|
||||
g_out_sum -= stackIn.g;
|
||||
b_out_sum -= stackIn.b;
|
||||
a_out_sum -= stackIn.a;
|
||||
p =
|
||||
(x +
|
||||
((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * width) <<
|
||||
2;
|
||||
r_sum += r_in_sum += stackIn.r = pixels[p];
|
||||
g_sum += g_in_sum += stackIn.g = pixels[p + 1];
|
||||
b_sum += b_in_sum += stackIn.b = pixels[p + 2];
|
||||
a_sum += a_in_sum += stackIn.a = pixels[p + 3];
|
||||
stackIn = stackIn.next;
|
||||
r_out_sum += pr = stackOut.r;
|
||||
g_out_sum += pg = stackOut.g;
|
||||
b_out_sum += pb = stackOut.b;
|
||||
a_out_sum += pa = stackOut.a;
|
||||
r_in_sum -= pr;
|
||||
g_in_sum -= pg;
|
||||
b_in_sum -= pb;
|
||||
a_in_sum -= pa;
|
||||
stackOut = stackOut.next;
|
||||
yi += width;
|
||||
}
|
||||
}
|
||||
}
|
||||
const Blur = function Blur(imageData) {
|
||||
var radius = Math.round(this.blurRadius());
|
||||
if (radius > 0) {
|
||||
filterGaussBlurRGBA(imageData, radius);
|
||||
}
|
||||
};
|
||||
exports.Blur = Blur;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'blurRadius', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Brighten.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Brighten.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Brighten: Filter;
|
||||
16
node_modules/konva/cmj/filters/Brighten.js
generated
vendored
Normal file
16
node_modules/konva/cmj/filters/Brighten.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Brighten = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Brighten = function (imageData) {
|
||||
var brightness = this.brightness() * 255, data = imageData.data, len = data.length, i;
|
||||
for (i = 0; i < len; i += 4) {
|
||||
data[i] += brightness;
|
||||
data[i + 1] += brightness;
|
||||
data[i + 2] += brightness;
|
||||
}
|
||||
};
|
||||
exports.Brighten = Brighten;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'brightness', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Contrast.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Contrast.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Contrast: Filter;
|
||||
38
node_modules/konva/cmj/filters/Contrast.js
generated
vendored
Normal file
38
node_modules/konva/cmj/filters/Contrast.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Contrast = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Contrast = function (imageData) {
|
||||
var adjust = Math.pow((this.contrast() + 100) / 100, 2);
|
||||
var data = imageData.data, nPixels = data.length, red = 150, green = 150, blue = 150, i;
|
||||
for (i = 0; i < nPixels; i += 4) {
|
||||
red = data[i];
|
||||
green = data[i + 1];
|
||||
blue = data[i + 2];
|
||||
red /= 255;
|
||||
red -= 0.5;
|
||||
red *= adjust;
|
||||
red += 0.5;
|
||||
red *= 255;
|
||||
green /= 255;
|
||||
green -= 0.5;
|
||||
green *= adjust;
|
||||
green += 0.5;
|
||||
green *= 255;
|
||||
blue /= 255;
|
||||
blue -= 0.5;
|
||||
blue *= adjust;
|
||||
blue += 0.5;
|
||||
blue *= 255;
|
||||
red = red < 0 ? 0 : red > 255 ? 255 : red;
|
||||
green = green < 0 ? 0 : green > 255 ? 255 : green;
|
||||
blue = blue < 0 ? 0 : blue > 255 ? 255 : blue;
|
||||
data[i] = red;
|
||||
data[i + 1] = green;
|
||||
data[i + 2] = blue;
|
||||
}
|
||||
};
|
||||
exports.Contrast = Contrast;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'contrast', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Emboss.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Emboss.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Emboss: Filter;
|
||||
106
node_modules/konva/cmj/filters/Emboss.js
generated
vendored
Normal file
106
node_modules/konva/cmj/filters/Emboss.js
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Emboss = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Util_1 = require("../Util");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Emboss = function (imageData) {
|
||||
var strength = this.embossStrength() * 10, greyLevel = this.embossWhiteLevel() * 255, direction = this.embossDirection(), blend = this.embossBlend(), dirY = 0, dirX = 0, data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4, y = h;
|
||||
switch (direction) {
|
||||
case 'top-left':
|
||||
dirY = -1;
|
||||
dirX = -1;
|
||||
break;
|
||||
case 'top':
|
||||
dirY = -1;
|
||||
dirX = 0;
|
||||
break;
|
||||
case 'top-right':
|
||||
dirY = -1;
|
||||
dirX = 1;
|
||||
break;
|
||||
case 'right':
|
||||
dirY = 0;
|
||||
dirX = 1;
|
||||
break;
|
||||
case 'bottom-right':
|
||||
dirY = 1;
|
||||
dirX = 1;
|
||||
break;
|
||||
case 'bottom':
|
||||
dirY = 1;
|
||||
dirX = 0;
|
||||
break;
|
||||
case 'bottom-left':
|
||||
dirY = 1;
|
||||
dirX = -1;
|
||||
break;
|
||||
case 'left':
|
||||
dirY = 0;
|
||||
dirX = -1;
|
||||
break;
|
||||
default:
|
||||
Util_1.Util.error('Unknown emboss direction: ' + direction);
|
||||
}
|
||||
do {
|
||||
var offsetY = (y - 1) * w4;
|
||||
var otherY = dirY;
|
||||
if (y + otherY < 1) {
|
||||
otherY = 0;
|
||||
}
|
||||
if (y + otherY > h) {
|
||||
otherY = 0;
|
||||
}
|
||||
var offsetYOther = (y - 1 + otherY) * w * 4;
|
||||
var x = w;
|
||||
do {
|
||||
var offset = offsetY + (x - 1) * 4;
|
||||
var otherX = dirX;
|
||||
if (x + otherX < 1) {
|
||||
otherX = 0;
|
||||
}
|
||||
if (x + otherX > w) {
|
||||
otherX = 0;
|
||||
}
|
||||
var offsetOther = offsetYOther + (x - 1 + otherX) * 4;
|
||||
var dR = data[offset] - data[offsetOther];
|
||||
var dG = data[offset + 1] - data[offsetOther + 1];
|
||||
var dB = data[offset + 2] - data[offsetOther + 2];
|
||||
var dif = dR;
|
||||
var absDif = dif > 0 ? dif : -dif;
|
||||
var absG = dG > 0 ? dG : -dG;
|
||||
var absB = dB > 0 ? dB : -dB;
|
||||
if (absG > absDif) {
|
||||
dif = dG;
|
||||
}
|
||||
if (absB > absDif) {
|
||||
dif = dB;
|
||||
}
|
||||
dif *= strength;
|
||||
if (blend) {
|
||||
var r = data[offset] + dif;
|
||||
var g = data[offset + 1] + dif;
|
||||
var b = data[offset + 2] + dif;
|
||||
data[offset] = r > 255 ? 255 : r < 0 ? 0 : r;
|
||||
data[offset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
|
||||
data[offset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
|
||||
}
|
||||
else {
|
||||
var grey = greyLevel - dif;
|
||||
if (grey < 0) {
|
||||
grey = 0;
|
||||
}
|
||||
else if (grey > 255) {
|
||||
grey = 255;
|
||||
}
|
||||
data[offset] = data[offset + 1] = data[offset + 2] = grey;
|
||||
}
|
||||
} while (--x);
|
||||
} while (--y);
|
||||
};
|
||||
exports.Emboss = Emboss;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'embossStrength', 0.5, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'embossWhiteLevel', 0.5, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'embossDirection', 'top-left', null, Factory_1.Factory.afterSetFilter);
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'embossBlend', false, null, Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Enhance.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Enhance.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Enhance: Filter;
|
||||
87
node_modules/konva/cmj/filters/Enhance.js
generated
vendored
Normal file
87
node_modules/konva/cmj/filters/Enhance.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Enhance = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
||||
var fromRange = fromMax - fromMin, toRange = toMax - toMin, toValue;
|
||||
if (fromRange === 0) {
|
||||
return toMin + toRange / 2;
|
||||
}
|
||||
if (toRange === 0) {
|
||||
return toMin;
|
||||
}
|
||||
toValue = (fromValue - fromMin) / fromRange;
|
||||
toValue = toRange * toValue + toMin;
|
||||
return toValue;
|
||||
}
|
||||
const Enhance = function (imageData) {
|
||||
var data = imageData.data, nSubPixels = data.length, rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b, i;
|
||||
var enhanceAmount = this.enhance();
|
||||
if (enhanceAmount === 0) {
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < nSubPixels; i += 4) {
|
||||
r = data[i + 0];
|
||||
if (r < rMin) {
|
||||
rMin = r;
|
||||
}
|
||||
else if (r > rMax) {
|
||||
rMax = r;
|
||||
}
|
||||
g = data[i + 1];
|
||||
if (g < gMin) {
|
||||
gMin = g;
|
||||
}
|
||||
else if (g > gMax) {
|
||||
gMax = g;
|
||||
}
|
||||
b = data[i + 2];
|
||||
if (b < bMin) {
|
||||
bMin = b;
|
||||
}
|
||||
else if (b > bMax) {
|
||||
bMax = b;
|
||||
}
|
||||
}
|
||||
if (rMax === rMin) {
|
||||
rMax = 255;
|
||||
rMin = 0;
|
||||
}
|
||||
if (gMax === gMin) {
|
||||
gMax = 255;
|
||||
gMin = 0;
|
||||
}
|
||||
if (bMax === bMin) {
|
||||
bMax = 255;
|
||||
bMin = 0;
|
||||
}
|
||||
var rMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin;
|
||||
if (enhanceAmount > 0) {
|
||||
rGoalMax = rMax + enhanceAmount * (255 - rMax);
|
||||
rGoalMin = rMin - enhanceAmount * (rMin - 0);
|
||||
gGoalMax = gMax + enhanceAmount * (255 - gMax);
|
||||
gGoalMin = gMin - enhanceAmount * (gMin - 0);
|
||||
bGoalMax = bMax + enhanceAmount * (255 - bMax);
|
||||
bGoalMin = bMin - enhanceAmount * (bMin - 0);
|
||||
}
|
||||
else {
|
||||
rMid = (rMax + rMin) * 0.5;
|
||||
rGoalMax = rMax + enhanceAmount * (rMax - rMid);
|
||||
rGoalMin = rMin + enhanceAmount * (rMin - rMid);
|
||||
gMid = (gMax + gMin) * 0.5;
|
||||
gGoalMax = gMax + enhanceAmount * (gMax - gMid);
|
||||
gGoalMin = gMin + enhanceAmount * (gMin - gMid);
|
||||
bMid = (bMax + bMin) * 0.5;
|
||||
bGoalMax = bMax + enhanceAmount * (bMax - bMid);
|
||||
bGoalMin = bMin + enhanceAmount * (bMin - bMid);
|
||||
}
|
||||
for (i = 0; i < nSubPixels; i += 4) {
|
||||
data[i + 0] = remap(data[i + 0], rMin, rMax, rGoalMin, rGoalMax);
|
||||
data[i + 1] = remap(data[i + 1], gMin, gMax, gGoalMin, gGoalMax);
|
||||
data[i + 2] = remap(data[i + 2], bMin, bMax, bGoalMin, bGoalMax);
|
||||
}
|
||||
};
|
||||
exports.Enhance = Enhance;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'enhance', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Grayscale.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Grayscale.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Grayscale: Filter;
|
||||
13
node_modules/konva/cmj/filters/Grayscale.js
generated
vendored
Normal file
13
node_modules/konva/cmj/filters/Grayscale.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Grayscale = void 0;
|
||||
const Grayscale = function (imageData) {
|
||||
var data = imageData.data, len = data.length, i, brightness;
|
||||
for (i = 0; i < len; i += 4) {
|
||||
brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
|
||||
data[i] = brightness;
|
||||
data[i + 1] = brightness;
|
||||
data[i + 2] = brightness;
|
||||
}
|
||||
};
|
||||
exports.Grayscale = Grayscale;
|
||||
2
node_modules/konva/cmj/filters/HSL.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/HSL.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const HSL: Filter;
|
||||
28
node_modules/konva/cmj/filters/HSL.js
generated
vendored
Normal file
28
node_modules/konva/cmj/filters/HSL.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HSL = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'hue', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'saturation', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'luminance', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
const HSL = function (imageData) {
|
||||
var data = imageData.data, nPixels = data.length, v = 1, s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360, l = this.luminance() * 127, i;
|
||||
var vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
|
||||
var rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
|
||||
var gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;
|
||||
var br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;
|
||||
var r, g, b, a;
|
||||
for (i = 0; i < nPixels; i += 4) {
|
||||
r = data[i + 0];
|
||||
g = data[i + 1];
|
||||
b = data[i + 2];
|
||||
a = data[i + 3];
|
||||
data[i + 0] = rr * r + rg * g + rb * b + l;
|
||||
data[i + 1] = gr * r + gg * g + gb * b + l;
|
||||
data[i + 2] = br * r + bg * g + bb * b + l;
|
||||
data[i + 3] = a;
|
||||
}
|
||||
};
|
||||
exports.HSL = HSL;
|
||||
2
node_modules/konva/cmj/filters/HSV.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/HSV.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const HSV: Filter;
|
||||
28
node_modules/konva/cmj/filters/HSV.js
generated
vendored
Normal file
28
node_modules/konva/cmj/filters/HSV.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HSV = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
const HSV = function (imageData) {
|
||||
var data = imageData.data, nPixels = data.length, v = Math.pow(2, this.value()), s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360, i;
|
||||
var vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
|
||||
var rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
|
||||
var gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;
|
||||
var br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;
|
||||
var r, g, b, a;
|
||||
for (i = 0; i < nPixels; i += 4) {
|
||||
r = data[i + 0];
|
||||
g = data[i + 1];
|
||||
b = data[i + 2];
|
||||
a = data[i + 3];
|
||||
data[i + 0] = rr * r + rg * g + rb * b;
|
||||
data[i + 1] = gr * r + gg * g + gb * b;
|
||||
data[i + 2] = br * r + bg * g + bb * b;
|
||||
data[i + 3] = a;
|
||||
}
|
||||
};
|
||||
exports.HSV = HSV;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'hue', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'saturation', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'value', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Invert.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Invert.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Invert: Filter;
|
||||
12
node_modules/konva/cmj/filters/Invert.js
generated
vendored
Normal file
12
node_modules/konva/cmj/filters/Invert.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Invert = void 0;
|
||||
const Invert = function (imageData) {
|
||||
var data = imageData.data, len = data.length, i;
|
||||
for (i = 0; i < len; i += 4) {
|
||||
data[i] = 255 - data[i];
|
||||
data[i + 1] = 255 - data[i + 1];
|
||||
data[i + 2] = 255 - data[i + 2];
|
||||
}
|
||||
};
|
||||
exports.Invert = Invert;
|
||||
2
node_modules/konva/cmj/filters/Kaleidoscope.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Kaleidoscope.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Kaleidoscope: Filter;
|
||||
136
node_modules/konva/cmj/filters/Kaleidoscope.js
generated
vendored
Normal file
136
node_modules/konva/cmj/filters/Kaleidoscope.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Kaleidoscope = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Util_1 = require("../Util");
|
||||
const Validators_1 = require("../Validators");
|
||||
var ToPolar = function (src, dst, opt) {
|
||||
var srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, r = 0, g = 0, b = 0, a = 0;
|
||||
var rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
||||
x = xSize - xMid;
|
||||
y = ySize - yMid;
|
||||
rad = Math.sqrt(x * x + y * y);
|
||||
rMax = rad > rMax ? rad : rMax;
|
||||
var rSize = ySize, tSize = xSize, radius, theta;
|
||||
var conversion = ((360 / tSize) * Math.PI) / 180, sin, cos;
|
||||
for (theta = 0; theta < tSize; theta += 1) {
|
||||
sin = Math.sin(theta * conversion);
|
||||
cos = Math.cos(theta * conversion);
|
||||
for (radius = 0; radius < rSize; radius += 1) {
|
||||
x = Math.floor(xMid + ((rMax * radius) / rSize) * cos);
|
||||
y = Math.floor(yMid + ((rMax * radius) / rSize) * sin);
|
||||
i = (y * xSize + x) * 4;
|
||||
r = srcPixels[i + 0];
|
||||
g = srcPixels[i + 1];
|
||||
b = srcPixels[i + 2];
|
||||
a = srcPixels[i + 3];
|
||||
i = (theta + radius * xSize) * 4;
|
||||
dstPixels[i + 0] = r;
|
||||
dstPixels[i + 1] = g;
|
||||
dstPixels[i + 2] = b;
|
||||
dstPixels[i + 3] = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
var FromPolar = function (src, dst, opt) {
|
||||
var srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, dx, dy, r = 0, g = 0, b = 0, a = 0;
|
||||
var rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
||||
x = xSize - xMid;
|
||||
y = ySize - yMid;
|
||||
rad = Math.sqrt(x * x + y * y);
|
||||
rMax = rad > rMax ? rad : rMax;
|
||||
var rSize = ySize, tSize = xSize, radius, theta, phaseShift = opt.polarRotation || 0;
|
||||
var x1, y1;
|
||||
for (x = 0; x < xSize; x += 1) {
|
||||
for (y = 0; y < ySize; y += 1) {
|
||||
dx = x - xMid;
|
||||
dy = y - yMid;
|
||||
radius = (Math.sqrt(dx * dx + dy * dy) * rSize) / rMax;
|
||||
theta = ((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
|
||||
theta = (theta * tSize) / 360;
|
||||
x1 = Math.floor(theta);
|
||||
y1 = Math.floor(radius);
|
||||
i = (y1 * xSize + x1) * 4;
|
||||
r = srcPixels[i + 0];
|
||||
g = srcPixels[i + 1];
|
||||
b = srcPixels[i + 2];
|
||||
a = srcPixels[i + 3];
|
||||
i = (y * xSize + x) * 4;
|
||||
dstPixels[i + 0] = r;
|
||||
dstPixels[i + 1] = g;
|
||||
dstPixels[i + 2] = b;
|
||||
dstPixels[i + 3] = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
const Kaleidoscope = function (imageData) {
|
||||
var xSize = imageData.width, ySize = imageData.height;
|
||||
var x, y, xoff, i, r, g, b, a, srcPos, dstPos;
|
||||
var power = Math.round(this.kaleidoscopePower());
|
||||
var angle = Math.round(this.kaleidoscopeAngle());
|
||||
var offset = Math.floor((xSize * (angle % 360)) / 360);
|
||||
if (power < 1) {
|
||||
return;
|
||||
}
|
||||
var tempCanvas = Util_1.Util.createCanvasElement();
|
||||
tempCanvas.width = xSize;
|
||||
tempCanvas.height = ySize;
|
||||
var scratchData = tempCanvas
|
||||
.getContext('2d')
|
||||
.getImageData(0, 0, xSize, ySize);
|
||||
ToPolar(imageData, scratchData, {
|
||||
polarCenterX: xSize / 2,
|
||||
polarCenterY: ySize / 2,
|
||||
});
|
||||
var minSectionSize = xSize / Math.pow(2, power);
|
||||
while (minSectionSize <= 8) {
|
||||
minSectionSize = minSectionSize * 2;
|
||||
power -= 1;
|
||||
}
|
||||
minSectionSize = Math.ceil(minSectionSize);
|
||||
var sectionSize = minSectionSize;
|
||||
var xStart = 0, xEnd = sectionSize, xDelta = 1;
|
||||
if (offset + minSectionSize > xSize) {
|
||||
xStart = sectionSize;
|
||||
xEnd = 0;
|
||||
xDelta = -1;
|
||||
}
|
||||
for (y = 0; y < ySize; y += 1) {
|
||||
for (x = xStart; x !== xEnd; x += xDelta) {
|
||||
xoff = Math.round(x + offset) % xSize;
|
||||
srcPos = (xSize * y + xoff) * 4;
|
||||
r = scratchData.data[srcPos + 0];
|
||||
g = scratchData.data[srcPos + 1];
|
||||
b = scratchData.data[srcPos + 2];
|
||||
a = scratchData.data[srcPos + 3];
|
||||
dstPos = (xSize * y + x) * 4;
|
||||
scratchData.data[dstPos + 0] = r;
|
||||
scratchData.data[dstPos + 1] = g;
|
||||
scratchData.data[dstPos + 2] = b;
|
||||
scratchData.data[dstPos + 3] = a;
|
||||
}
|
||||
}
|
||||
for (y = 0; y < ySize; y += 1) {
|
||||
sectionSize = Math.floor(minSectionSize);
|
||||
for (i = 0; i < power; i += 1) {
|
||||
for (x = 0; x < sectionSize + 1; x += 1) {
|
||||
srcPos = (xSize * y + x) * 4;
|
||||
r = scratchData.data[srcPos + 0];
|
||||
g = scratchData.data[srcPos + 1];
|
||||
b = scratchData.data[srcPos + 2];
|
||||
a = scratchData.data[srcPos + 3];
|
||||
dstPos = (xSize * y + sectionSize * 2 - x - 1) * 4;
|
||||
scratchData.data[dstPos + 0] = r;
|
||||
scratchData.data[dstPos + 1] = g;
|
||||
scratchData.data[dstPos + 2] = b;
|
||||
scratchData.data[dstPos + 3] = a;
|
||||
}
|
||||
sectionSize *= 2;
|
||||
}
|
||||
}
|
||||
FromPolar(scratchData, imageData, { polarRotation: 0 });
|
||||
};
|
||||
exports.Kaleidoscope = Kaleidoscope;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'kaleidoscopePower', 2, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'kaleidoscopeAngle', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Mask.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Mask.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Mask: Filter;
|
||||
144
node_modules/konva/cmj/filters/Mask.js
generated
vendored
Normal file
144
node_modules/konva/cmj/filters/Mask.js
generated
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Mask = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
function pixelAt(idata, x, y) {
|
||||
var idx = (y * idata.width + x) * 4;
|
||||
var d = [];
|
||||
d.push(idata.data[idx++], idata.data[idx++], idata.data[idx++], idata.data[idx++]);
|
||||
return d;
|
||||
}
|
||||
function rgbDistance(p1, p2) {
|
||||
return Math.sqrt(Math.pow(p1[0] - p2[0], 2) +
|
||||
Math.pow(p1[1] - p2[1], 2) +
|
||||
Math.pow(p1[2] - p2[2], 2));
|
||||
}
|
||||
function rgbMean(pTab) {
|
||||
var m = [0, 0, 0];
|
||||
for (var i = 0; i < pTab.length; i++) {
|
||||
m[0] += pTab[i][0];
|
||||
m[1] += pTab[i][1];
|
||||
m[2] += pTab[i][2];
|
||||
}
|
||||
m[0] /= pTab.length;
|
||||
m[1] /= pTab.length;
|
||||
m[2] /= pTab.length;
|
||||
return m;
|
||||
}
|
||||
function backgroundMask(idata, threshold) {
|
||||
var rgbv_no = pixelAt(idata, 0, 0);
|
||||
var rgbv_ne = pixelAt(idata, idata.width - 1, 0);
|
||||
var rgbv_so = pixelAt(idata, 0, idata.height - 1);
|
||||
var rgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1);
|
||||
var thres = threshold || 10;
|
||||
if (rgbDistance(rgbv_no, rgbv_ne) < thres &&
|
||||
rgbDistance(rgbv_ne, rgbv_se) < thres &&
|
||||
rgbDistance(rgbv_se, rgbv_so) < thres &&
|
||||
rgbDistance(rgbv_so, rgbv_no) < thres) {
|
||||
var mean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]);
|
||||
var mask = [];
|
||||
for (var i = 0; i < idata.width * idata.height; i++) {
|
||||
var d = rgbDistance(mean, [
|
||||
idata.data[i * 4],
|
||||
idata.data[i * 4 + 1],
|
||||
idata.data[i * 4 + 2],
|
||||
]);
|
||||
mask[i] = d < thres ? 0 : 255;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
function applyMask(idata, mask) {
|
||||
for (var i = 0; i < idata.width * idata.height; i++) {
|
||||
idata.data[4 * i + 3] = mask[i];
|
||||
}
|
||||
}
|
||||
function erodeMask(mask, sw, sh) {
|
||||
var weights = [1, 1, 1, 1, 0, 1, 1, 1, 1];
|
||||
var side = Math.round(Math.sqrt(weights.length));
|
||||
var halfSide = Math.floor(side / 2);
|
||||
var maskResult = [];
|
||||
for (var y = 0; y < sh; y++) {
|
||||
for (var x = 0; x < sw; x++) {
|
||||
var so = y * sw + x;
|
||||
var a = 0;
|
||||
for (var cy = 0; cy < side; cy++) {
|
||||
for (var cx = 0; cx < side; cx++) {
|
||||
var scy = y + cy - halfSide;
|
||||
var scx = x + cx - halfSide;
|
||||
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
|
||||
var srcOff = scy * sw + scx;
|
||||
var wt = weights[cy * side + cx];
|
||||
a += mask[srcOff] * wt;
|
||||
}
|
||||
}
|
||||
}
|
||||
maskResult[so] = a === 255 * 8 ? 255 : 0;
|
||||
}
|
||||
}
|
||||
return maskResult;
|
||||
}
|
||||
function dilateMask(mask, sw, sh) {
|
||||
var weights = [1, 1, 1, 1, 1, 1, 1, 1, 1];
|
||||
var side = Math.round(Math.sqrt(weights.length));
|
||||
var halfSide = Math.floor(side / 2);
|
||||
var maskResult = [];
|
||||
for (var y = 0; y < sh; y++) {
|
||||
for (var x = 0; x < sw; x++) {
|
||||
var so = y * sw + x;
|
||||
var a = 0;
|
||||
for (var cy = 0; cy < side; cy++) {
|
||||
for (var cx = 0; cx < side; cx++) {
|
||||
var scy = y + cy - halfSide;
|
||||
var scx = x + cx - halfSide;
|
||||
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
|
||||
var srcOff = scy * sw + scx;
|
||||
var wt = weights[cy * side + cx];
|
||||
a += mask[srcOff] * wt;
|
||||
}
|
||||
}
|
||||
}
|
||||
maskResult[so] = a >= 255 * 4 ? 255 : 0;
|
||||
}
|
||||
}
|
||||
return maskResult;
|
||||
}
|
||||
function smoothEdgeMask(mask, sw, sh) {
|
||||
var weights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9];
|
||||
var side = Math.round(Math.sqrt(weights.length));
|
||||
var halfSide = Math.floor(side / 2);
|
||||
var maskResult = [];
|
||||
for (var y = 0; y < sh; y++) {
|
||||
for (var x = 0; x < sw; x++) {
|
||||
var so = y * sw + x;
|
||||
var a = 0;
|
||||
for (var cy = 0; cy < side; cy++) {
|
||||
for (var cx = 0; cx < side; cx++) {
|
||||
var scy = y + cy - halfSide;
|
||||
var scx = x + cx - halfSide;
|
||||
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
|
||||
var srcOff = scy * sw + scx;
|
||||
var wt = weights[cy * side + cx];
|
||||
a += mask[srcOff] * wt;
|
||||
}
|
||||
}
|
||||
}
|
||||
maskResult[so] = a;
|
||||
}
|
||||
}
|
||||
return maskResult;
|
||||
}
|
||||
const Mask = function (imageData) {
|
||||
var threshold = this.threshold(), mask = backgroundMask(imageData, threshold);
|
||||
if (mask) {
|
||||
mask = erodeMask(mask, imageData.width, imageData.height);
|
||||
mask = dilateMask(mask, imageData.width, imageData.height);
|
||||
mask = smoothEdgeMask(mask, imageData.width, imageData.height);
|
||||
applyMask(imageData, mask);
|
||||
}
|
||||
return imageData;
|
||||
};
|
||||
exports.Mask = Mask;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'threshold', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Noise.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Noise.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Noise: Filter;
|
||||
16
node_modules/konva/cmj/filters/Noise.js
generated
vendored
Normal file
16
node_modules/konva/cmj/filters/Noise.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Noise = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Noise = function (imageData) {
|
||||
var amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2, i;
|
||||
for (i = 0; i < nPixels; i += 4) {
|
||||
data[i + 0] += half - 2 * half * Math.random();
|
||||
data[i + 1] += half - 2 * half * Math.random();
|
||||
data[i + 2] += half - 2 * half * Math.random();
|
||||
}
|
||||
};
|
||||
exports.Noise = Noise;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'noise', 0.2, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Pixelate.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Pixelate.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Pixelate: Filter;
|
||||
64
node_modules/konva/cmj/filters/Pixelate.js
generated
vendored
Normal file
64
node_modules/konva/cmj/filters/Pixelate.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Pixelate = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Util_1 = require("../Util");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Pixelate = function (imageData) {
|
||||
var pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i, red, green, blue, alpha, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), xBinStart, xBinEnd, yBinStart, yBinEnd, xBin, yBin, pixelsInBin, data = imageData.data;
|
||||
if (pixelSize <= 0) {
|
||||
Util_1.Util.error('pixelSize value can not be <= 0');
|
||||
return;
|
||||
}
|
||||
for (xBin = 0; xBin < nBinsX; xBin += 1) {
|
||||
for (yBin = 0; yBin < nBinsY; yBin += 1) {
|
||||
red = 0;
|
||||
green = 0;
|
||||
blue = 0;
|
||||
alpha = 0;
|
||||
xBinStart = xBin * pixelSize;
|
||||
xBinEnd = xBinStart + pixelSize;
|
||||
yBinStart = yBin * pixelSize;
|
||||
yBinEnd = yBinStart + pixelSize;
|
||||
pixelsInBin = 0;
|
||||
for (x = xBinStart; x < xBinEnd; x += 1) {
|
||||
if (x >= width) {
|
||||
continue;
|
||||
}
|
||||
for (y = yBinStart; y < yBinEnd; y += 1) {
|
||||
if (y >= height) {
|
||||
continue;
|
||||
}
|
||||
i = (width * y + x) * 4;
|
||||
red += data[i + 0];
|
||||
green += data[i + 1];
|
||||
blue += data[i + 2];
|
||||
alpha += data[i + 3];
|
||||
pixelsInBin += 1;
|
||||
}
|
||||
}
|
||||
red = red / pixelsInBin;
|
||||
green = green / pixelsInBin;
|
||||
blue = blue / pixelsInBin;
|
||||
alpha = alpha / pixelsInBin;
|
||||
for (x = xBinStart; x < xBinEnd; x += 1) {
|
||||
if (x >= width) {
|
||||
continue;
|
||||
}
|
||||
for (y = yBinStart; y < yBinEnd; y += 1) {
|
||||
if (y >= height) {
|
||||
continue;
|
||||
}
|
||||
i = (width * y + x) * 4;
|
||||
data[i + 0] = red;
|
||||
data[i + 1] = green;
|
||||
data[i + 2] = blue;
|
||||
data[i + 3] = alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.Pixelate = Pixelate;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'pixelSize', 8, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/Posterize.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Posterize.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Posterize: Filter;
|
||||
14
node_modules/konva/cmj/filters/Posterize.js
generated
vendored
Normal file
14
node_modules/konva/cmj/filters/Posterize.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Posterize = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Posterize = function (imageData) {
|
||||
var levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i;
|
||||
for (i = 0; i < len; i += 1) {
|
||||
data[i] = Math.floor(data[i] / scale) * scale;
|
||||
}
|
||||
};
|
||||
exports.Posterize = Posterize;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'levels', 0.5, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/RGB.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/RGB.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const RGB: Filter;
|
||||
43
node_modules/konva/cmj/filters/RGB.js
generated
vendored
Normal file
43
node_modules/konva/cmj/filters/RGB.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RGB = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
const RGB = function (imageData) {
|
||||
var data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness;
|
||||
for (i = 0; i < nPixels; i += 4) {
|
||||
brightness =
|
||||
(0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
|
||||
data[i] = brightness * red;
|
||||
data[i + 1] = brightness * green;
|
||||
data[i + 2] = brightness * blue;
|
||||
data[i + 3] = data[i + 3];
|
||||
}
|
||||
};
|
||||
exports.RGB = RGB;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'red', 0, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
}
|
||||
else if (val < 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return Math.round(val);
|
||||
}
|
||||
});
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'green', 0, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
}
|
||||
else if (val < 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return Math.round(val);
|
||||
}
|
||||
});
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'blue', 0, Validators_1.RGBComponent, Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/filters/RGBA.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/RGBA.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const RGBA: Filter;
|
||||
53
node_modules/konva/cmj/filters/RGBA.js
generated
vendored
Normal file
53
node_modules/konva/cmj/filters/RGBA.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RGBA = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
const RGBA = function (imageData) {
|
||||
var data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha(), i, ia;
|
||||
for (i = 0; i < nPixels; i += 4) {
|
||||
ia = 1 - alpha;
|
||||
data[i] = red * alpha + data[i] * ia;
|
||||
data[i + 1] = green * alpha + data[i + 1] * ia;
|
||||
data[i + 2] = blue * alpha + data[i + 2] * ia;
|
||||
}
|
||||
};
|
||||
exports.RGBA = RGBA;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'red', 0, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
}
|
||||
else if (val < 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return Math.round(val);
|
||||
}
|
||||
});
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'green', 0, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
}
|
||||
else if (val < 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return Math.round(val);
|
||||
}
|
||||
});
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'blue', 0, Validators_1.RGBComponent, Factory_1.Factory.afterSetFilter);
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'alpha', 1, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 1) {
|
||||
return 1;
|
||||
}
|
||||
else if (val < 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return val;
|
||||
}
|
||||
});
|
||||
2
node_modules/konva/cmj/filters/Sepia.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Sepia.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Sepia: Filter;
|
||||
15
node_modules/konva/cmj/filters/Sepia.js
generated
vendored
Normal file
15
node_modules/konva/cmj/filters/Sepia.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Sepia = void 0;
|
||||
const Sepia = function (imageData) {
|
||||
var data = imageData.data, nPixels = data.length, i, r, g, b;
|
||||
for (i = 0; i < nPixels; i += 4) {
|
||||
r = data[i + 0];
|
||||
g = data[i + 1];
|
||||
b = data[i + 2];
|
||||
data[i + 0] = Math.min(255, r * 0.393 + g * 0.769 + b * 0.189);
|
||||
data[i + 1] = Math.min(255, r * 0.349 + g * 0.686 + b * 0.168);
|
||||
data[i + 2] = Math.min(255, r * 0.272 + g * 0.534 + b * 0.131);
|
||||
}
|
||||
};
|
||||
exports.Sepia = Sepia;
|
||||
2
node_modules/konva/cmj/filters/Solarize.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Solarize.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Solarize: Filter;
|
||||
29
node_modules/konva/cmj/filters/Solarize.js
generated
vendored
Normal file
29
node_modules/konva/cmj/filters/Solarize.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Solarize = void 0;
|
||||
const Solarize = function (imageData) {
|
||||
var data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4, y = h;
|
||||
do {
|
||||
var offsetY = (y - 1) * w4;
|
||||
var x = w;
|
||||
do {
|
||||
var offset = offsetY + (x - 1) * 4;
|
||||
var r = data[offset];
|
||||
var g = data[offset + 1];
|
||||
var b = data[offset + 2];
|
||||
if (r > 127) {
|
||||
r = 255 - r;
|
||||
}
|
||||
if (g > 127) {
|
||||
g = 255 - g;
|
||||
}
|
||||
if (b > 127) {
|
||||
b = 255 - b;
|
||||
}
|
||||
data[offset] = r;
|
||||
data[offset + 1] = g;
|
||||
data[offset + 2] = b;
|
||||
} while (--x);
|
||||
} while (--y);
|
||||
};
|
||||
exports.Solarize = Solarize;
|
||||
2
node_modules/konva/cmj/filters/Threshold.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/filters/Threshold.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Filter } from '../Node';
|
||||
export declare const Threshold: Filter;
|
||||
14
node_modules/konva/cmj/filters/Threshold.js
generated
vendored
Normal file
14
node_modules/konva/cmj/filters/Threshold.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Threshold = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Node_1 = require("../Node");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Threshold = function (imageData) {
|
||||
var level = this.threshold() * 255, data = imageData.data, len = data.length, i;
|
||||
for (i = 0; i < len; i += 1) {
|
||||
data[i] = data[i] < level ? 0 : 255;
|
||||
}
|
||||
};
|
||||
exports.Threshold = Threshold;
|
||||
Factory_1.Factory.addGetterSetter(Node_1.Node, 'threshold', 0.5, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
||||
2
node_modules/konva/cmj/index-node.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/index-node.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Konva } from './_FullInternals';
|
||||
export default Konva;
|
||||
20
node_modules/konva/cmj/index-node.js
generated
vendored
Normal file
20
node_modules/konva/cmj/index-node.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _FullInternals_1 = require("./_FullInternals");
|
||||
const Canvas = require("canvas");
|
||||
const canvas = Canvas['default'] || Canvas;
|
||||
const isNode = typeof global.document === 'undefined';
|
||||
if (isNode) {
|
||||
_FullInternals_1.Konva.Util['createCanvasElement'] = () => {
|
||||
const node = canvas.createCanvas(300, 300);
|
||||
if (!node['style']) {
|
||||
node['style'] = {};
|
||||
}
|
||||
return node;
|
||||
};
|
||||
_FullInternals_1.Konva.Util.createImageElement = () => {
|
||||
const node = new canvas.Image();
|
||||
return node;
|
||||
};
|
||||
}
|
||||
exports.default = _FullInternals_1.Konva;
|
||||
179
node_modules/konva/cmj/index-types.d.ts
generated
vendored
Normal file
179
node_modules/konva/cmj/index-types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
// the purpose of that file is very stupid
|
||||
// I was not able to generate correct typescript declarations from the main source code
|
||||
// because right now Konva is an object. Typescript can not define types from object like this:
|
||||
// const stage : Konva.Stage = new Konva.Stage();
|
||||
// we can convert Konva to namespace
|
||||
// but I was not able to find a way to extend it
|
||||
// so here we just need to define full API of Konva manually
|
||||
|
||||
// filters
|
||||
import { Blur } from './filters/Blur';
|
||||
import { Brighten } from './filters/Brighten';
|
||||
import { Contrast } from './filters/Contrast';
|
||||
import { Emboss } from './filters/Emboss';
|
||||
import { Enhance } from './filters/Enhance';
|
||||
import { Grayscale } from './filters/Grayscale';
|
||||
import { HSL } from './filters/HSL';
|
||||
import { HSV } from './filters/HSV';
|
||||
import { Invert } from './filters/Invert';
|
||||
import { Kaleidoscope } from './filters/Kaleidoscope';
|
||||
import { Mask } from './filters/Mask';
|
||||
import { Noise } from './filters/Noise';
|
||||
import { Pixelate } from './filters/Pixelate';
|
||||
import { Posterize } from './filters/Posterize';
|
||||
import { RGB } from './filters/RGB';
|
||||
import { RGBA } from './filters/RGBA';
|
||||
import { Sepia } from './filters/Sepia';
|
||||
import { Solarize } from './filters/Solarize';
|
||||
import { Threshold } from './filters/Threshold';
|
||||
|
||||
declare namespace Konva {
|
||||
export let enableTrace: number;
|
||||
export let pixelRatio: number;
|
||||
export let autoDrawEnabled: boolean;
|
||||
export let dragDistance: number;
|
||||
export let angleDeg: boolean;
|
||||
export let showWarnings: boolean;
|
||||
export let capturePointerEventsEnabled: boolean;
|
||||
export let dragButtons: Array<number>;
|
||||
export let hitOnDragEnabled: boolean;
|
||||
export const isDragging: () => boolean;
|
||||
export const isDragReady: () => boolean;
|
||||
|
||||
export type Vector2d = import('./types').Vector2d;
|
||||
|
||||
export const Node: typeof import('./Node').Node;
|
||||
export type Node = import('./Node').Node;
|
||||
export type NodeConfig = import('./Node').NodeConfig;
|
||||
|
||||
export type KonvaEventObject<
|
||||
EventType
|
||||
> = import('./Node').KonvaEventObject<EventType>;
|
||||
|
||||
export type KonvaPointerEvent = import('./PointerEvents').KonvaPointerEvent;
|
||||
|
||||
export type KonvaEventListener<
|
||||
This,
|
||||
EventType
|
||||
> = import('./Node').KonvaEventListener<This, EventType>;
|
||||
|
||||
export const Container: typeof import('./Container').Container;
|
||||
export type Container = import('./Container').Container<Node>;
|
||||
export type ContainerConfig = import('./Container').ContainerConfig;
|
||||
|
||||
export const Transform: typeof import('./Util').Transform;
|
||||
export type Transform = import('./Util').Transform;
|
||||
|
||||
export const Util: typeof import('./Util').Util;
|
||||
|
||||
export const Context: typeof import('./Context').Context;
|
||||
export type Context = import('./Context').Context;
|
||||
|
||||
export const Stage: typeof import('./Stage').Stage;
|
||||
export type Stage = import('./Stage').Stage;
|
||||
export const stages: typeof import('./Stage').stages;
|
||||
|
||||
export const Layer: typeof import('./Layer').Layer;
|
||||
export type Layer = import('./Layer').Layer;
|
||||
export type LayerConfig = import('./Layer').LayerConfig;
|
||||
|
||||
export const FastLayer: typeof import('./FastLayer').FastLayer;
|
||||
export type FastLayer = import('./FastLayer').FastLayer;
|
||||
|
||||
export const Group: typeof import('./Group').Group;
|
||||
export type Group = import('./Group').Group;
|
||||
|
||||
export const DD: typeof import('./DragAndDrop').DD;
|
||||
|
||||
export const Shape: typeof import('./Shape').Shape;
|
||||
export type Shape = import('./Shape').Shape;
|
||||
export type ShapeConfig = import('./Shape').ShapeConfig;
|
||||
export const shapes: typeof import('./Shape').shapes;
|
||||
|
||||
export const Animation: typeof import('./Animation').Animation;
|
||||
export type Animation = import('./Animation').Animation;
|
||||
|
||||
export const Tween: typeof import('./Tween').Tween;
|
||||
export type Tween = import('./Tween').Tween;
|
||||
export type TweenConfig = import('./Tween').TweenConfig;
|
||||
export const Easings: typeof import('./Tween').Easings;
|
||||
|
||||
export const Arc: typeof import('./shapes/Arc').Arc;
|
||||
export type Arc = import('./shapes/Arc').Arc;
|
||||
export type ArcConfig = import('./shapes/Arc').ArcConfig;
|
||||
export const Arrow: typeof import('./shapes/Arrow').Arrow;
|
||||
export type Arrow = import('./shapes/Arrow').Arrow;
|
||||
export type ArrowConfig = import('./shapes/Arrow').ArrowConfig;
|
||||
export const Circle: typeof import('./shapes/Circle').Circle;
|
||||
export type Circle = import('./shapes/Circle').Circle;
|
||||
export type CircleConfig = import('./shapes/Circle').CircleConfig;
|
||||
export const Ellipse: typeof import('./shapes/Ellipse').Ellipse;
|
||||
export type Ellipse = import('./shapes/Ellipse').Ellipse;
|
||||
export type EllipseConfig = import('./shapes/Ellipse').EllipseConfig;
|
||||
export const Image: typeof import('./shapes/Image').Image;
|
||||
export type Image = import('./shapes/Image').Image;
|
||||
export type ImageConfig = import('./shapes/Image').ImageConfig;
|
||||
export const Label: typeof import('./shapes/Label').Label;
|
||||
export type Label = import('./shapes/Label').Label;
|
||||
export type LabelConfig = import('./shapes/Label').LabelConfig;
|
||||
export const Tag: typeof import('./shapes/Label').Tag;
|
||||
export type Tag = import('./shapes/Label').Tag;
|
||||
export type TagConfig = import('./shapes/Label').TagConfig;
|
||||
export const Line: typeof import('./shapes/Line').Line;
|
||||
export type Line = import('./shapes/Line').Line;
|
||||
export type LineConfig = import('./shapes/Line').LineConfig;
|
||||
export const Path: typeof import('./shapes/Path').Path;
|
||||
export type Path = import('./shapes/Path').Path;
|
||||
export type PathConfig = import('./shapes/Path').PathConfig;
|
||||
export const Rect: typeof import('./shapes/Rect').Rect;
|
||||
export type Rect = import('./shapes/Rect').Rect;
|
||||
export type RectConfig = import('./shapes/Rect').RectConfig;
|
||||
export const RegularPolygon: typeof import('./shapes/RegularPolygon').RegularPolygon;
|
||||
export type RegularPolygon = import('./shapes/RegularPolygon').RegularPolygon;
|
||||
export type RegularPolygonConfig = import('./shapes/RegularPolygon').RegularPolygonConfig;
|
||||
export const Ring: typeof import('./shapes/Ring').Ring;
|
||||
export type Ring = import('./shapes/Ring').Ring;
|
||||
export type RingConfig = import('./shapes/Ring').RingConfig;
|
||||
export const Sprite: typeof import('./shapes/Sprite').Sprite;
|
||||
export type Sprite = import('./shapes/Sprite').Sprite;
|
||||
export type SpriteConfig = import('./shapes/Sprite').SpriteConfig;
|
||||
export const Star: typeof import('./shapes/Star').Star;
|
||||
export type Star = import('./shapes/Star').Star;
|
||||
export type StarConfig = import('./shapes/Star').StarConfig;
|
||||
export const Text: typeof import('./shapes/Text').Text;
|
||||
export type Text = import('./shapes/Text').Text;
|
||||
export type TextConfig = import('./shapes/Text').TextConfig;
|
||||
export const TextPath: typeof import('./shapes/TextPath').TextPath;
|
||||
export type TextPath = import('./shapes/TextPath').TextPath;
|
||||
export type TextPathConfig = import('./shapes/TextPath').TextPathConfig;
|
||||
export const Transformer: typeof import('./shapes/Transformer').Transformer;
|
||||
export type Transformer = import('./shapes/Transformer').Transformer;
|
||||
export type TransformerConfig = import('./shapes/Transformer').TransformerConfig;
|
||||
export const Wedge: typeof import('./shapes/Wedge').Wedge;
|
||||
export type Wedge = import('./shapes/Wedge').Wedge;
|
||||
export type WedgeConfig = import('./shapes/Wedge').WedgeConfig;
|
||||
|
||||
export const Filters: {
|
||||
Blur: typeof Blur;
|
||||
Brighten: typeof Brighten;
|
||||
Contrast: typeof Contrast;
|
||||
Emboss: typeof Emboss;
|
||||
Enhance: typeof Enhance;
|
||||
Grayscale: typeof Grayscale;
|
||||
HSL: typeof HSL;
|
||||
HSV: typeof HSV;
|
||||
Invert: typeof Invert;
|
||||
Kaleidoscope: typeof Kaleidoscope;
|
||||
Mask: typeof Mask;
|
||||
Noise: typeof Noise;
|
||||
Pixelate: typeof Pixelate;
|
||||
Posterize: typeof Posterize;
|
||||
RGB: typeof RGB;
|
||||
RGBA: typeof RGBA;
|
||||
Sepia: typeof Sepia;
|
||||
Solarize: typeof Solarize;
|
||||
Threshold: typeof Threshold;
|
||||
};
|
||||
}
|
||||
|
||||
export default Konva;
|
||||
2
node_modules/konva/cmj/index.d.ts
generated
vendored
Normal file
2
node_modules/konva/cmj/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Konva } from './_FullInternals';
|
||||
export default Konva;
|
||||
4
node_modules/konva/cmj/index.js
generated
vendored
Normal file
4
node_modules/konva/cmj/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _FullInternals_1 = require("./_FullInternals");
|
||||
exports.default = _FullInternals_1.Konva;
|
||||
6
node_modules/konva/cmj/package.json
generated
vendored
Normal file
6
node_modules/konva/cmj/package.json
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"type": "commonjs",
|
||||
"main": "./index-node.js",
|
||||
"browser": "./index.js",
|
||||
"typings": "./index-types.d.ts"
|
||||
}
|
||||
19
node_modules/konva/cmj/shapes/Arc.d.ts
generated
vendored
Normal file
19
node_modules/konva/cmj/shapes/Arc.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { GetSet } from '../types';
|
||||
export interface ArcConfig extends ShapeConfig {
|
||||
angle: number;
|
||||
innerRadius: number;
|
||||
outerRadius: number;
|
||||
clockwise?: boolean;
|
||||
}
|
||||
export declare class Arc extends Shape<ArcConfig> {
|
||||
_sceneFunc(context: any): void;
|
||||
getWidth(): number;
|
||||
getHeight(): number;
|
||||
setWidth(width: any): void;
|
||||
setHeight(height: any): void;
|
||||
innerRadius: GetSet<number, this>;
|
||||
outerRadius: GetSet<number, this>;
|
||||
angle: GetSet<number, this>;
|
||||
clockwise: GetSet<boolean, this>;
|
||||
}
|
||||
39
node_modules/konva/cmj/shapes/Arc.js
generated
vendored
Normal file
39
node_modules/konva/cmj/shapes/Arc.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Arc = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Shape_1 = require("../Shape");
|
||||
const Global_1 = require("../Global");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Global_2 = require("../Global");
|
||||
class Arc extends Shape_1.Shape {
|
||||
_sceneFunc(context) {
|
||||
var angle = Global_1.Konva.getAngle(this.angle()), clockwise = this.clockwise();
|
||||
context.beginPath();
|
||||
context.arc(0, 0, this.outerRadius(), 0, angle, clockwise);
|
||||
context.arc(0, 0, this.innerRadius(), angle, 0, !clockwise);
|
||||
context.closePath();
|
||||
context.fillStrokeShape(this);
|
||||
}
|
||||
getWidth() {
|
||||
return this.outerRadius() * 2;
|
||||
}
|
||||
getHeight() {
|
||||
return this.outerRadius() * 2;
|
||||
}
|
||||
setWidth(width) {
|
||||
this.outerRadius(width / 2);
|
||||
}
|
||||
setHeight(height) {
|
||||
this.outerRadius(height / 2);
|
||||
}
|
||||
}
|
||||
exports.Arc = Arc;
|
||||
Arc.prototype._centroid = true;
|
||||
Arc.prototype.className = 'Arc';
|
||||
Arc.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
||||
(0, Global_2._registerNode)(Arc);
|
||||
Factory_1.Factory.addGetterSetter(Arc, 'innerRadius', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Arc, 'outerRadius', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Arc, 'angle', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Arc, 'clockwise', false, (0, Validators_1.getBooleanValidator)());
|
||||
25
node_modules/konva/cmj/shapes/Arrow.d.ts
generated
vendored
Normal file
25
node_modules/konva/cmj/shapes/Arrow.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Line, LineConfig } from './Line';
|
||||
import { GetSet } from '../types';
|
||||
export interface ArrowConfig extends LineConfig {
|
||||
points: number[];
|
||||
tension?: number;
|
||||
closed?: boolean;
|
||||
pointerLength?: number;
|
||||
pointerWidth?: number;
|
||||
pointerAtBeginning?: boolean;
|
||||
pointerAtEnding?: boolean;
|
||||
}
|
||||
export declare class Arrow extends Line<ArrowConfig> {
|
||||
_sceneFunc(ctx: any): void;
|
||||
__fillStroke(ctx: any): void;
|
||||
getSelfRect(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
pointerLength: GetSet<number, this>;
|
||||
pointerWidth: GetSet<number, this>;
|
||||
pointerAtEnding: GetSet<boolean, this>;
|
||||
pointerAtBeginning: GetSet<boolean, this>;
|
||||
}
|
||||
103
node_modules/konva/cmj/shapes/Arrow.js
generated
vendored
Normal file
103
node_modules/konva/cmj/shapes/Arrow.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Arrow = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Line_1 = require("./Line");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Global_1 = require("../Global");
|
||||
const Path_1 = require("./Path");
|
||||
class Arrow extends Line_1.Line {
|
||||
_sceneFunc(ctx) {
|
||||
super._sceneFunc(ctx);
|
||||
var PI2 = Math.PI * 2;
|
||||
var points = this.points();
|
||||
var tp = points;
|
||||
var fromTension = this.tension() !== 0 && points.length > 4;
|
||||
if (fromTension) {
|
||||
tp = this.getTensionPoints();
|
||||
}
|
||||
var length = this.pointerLength();
|
||||
var n = points.length;
|
||||
var dx, dy;
|
||||
if (fromTension) {
|
||||
const lp = [
|
||||
tp[tp.length - 4],
|
||||
tp[tp.length - 3],
|
||||
tp[tp.length - 2],
|
||||
tp[tp.length - 1],
|
||||
points[n - 2],
|
||||
points[n - 1],
|
||||
];
|
||||
const lastLength = Path_1.Path.calcLength(tp[tp.length - 4], tp[tp.length - 3], 'C', lp);
|
||||
const previous = Path_1.Path.getPointOnQuadraticBezier(Math.min(1, 1 - length / lastLength), lp[0], lp[1], lp[2], lp[3], lp[4], lp[5]);
|
||||
dx = points[n - 2] - previous.x;
|
||||
dy = points[n - 1] - previous.y;
|
||||
}
|
||||
else {
|
||||
dx = points[n - 2] - points[n - 4];
|
||||
dy = points[n - 1] - points[n - 3];
|
||||
}
|
||||
var radians = (Math.atan2(dy, dx) + PI2) % PI2;
|
||||
var width = this.pointerWidth();
|
||||
if (this.pointerAtEnding()) {
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.translate(points[n - 2], points[n - 1]);
|
||||
ctx.rotate(radians);
|
||||
ctx.moveTo(0, 0);
|
||||
ctx.lineTo(-length, width / 2);
|
||||
ctx.lineTo(-length, -width / 2);
|
||||
ctx.closePath();
|
||||
ctx.restore();
|
||||
this.__fillStroke(ctx);
|
||||
}
|
||||
if (this.pointerAtBeginning()) {
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.translate(points[0], points[1]);
|
||||
if (fromTension) {
|
||||
dx = (tp[0] + tp[2]) / 2 - points[0];
|
||||
dy = (tp[1] + tp[3]) / 2 - points[1];
|
||||
}
|
||||
else {
|
||||
dx = points[2] - points[0];
|
||||
dy = points[3] - points[1];
|
||||
}
|
||||
ctx.rotate((Math.atan2(-dy, -dx) + PI2) % PI2);
|
||||
ctx.moveTo(0, 0);
|
||||
ctx.lineTo(-length, width / 2);
|
||||
ctx.lineTo(-length, -width / 2);
|
||||
ctx.closePath();
|
||||
ctx.restore();
|
||||
this.__fillStroke(ctx);
|
||||
}
|
||||
}
|
||||
__fillStroke(ctx) {
|
||||
var isDashEnabled = this.dashEnabled();
|
||||
if (isDashEnabled) {
|
||||
this.attrs.dashEnabled = false;
|
||||
ctx.setLineDash([]);
|
||||
}
|
||||
ctx.fillStrokeShape(this);
|
||||
if (isDashEnabled) {
|
||||
this.attrs.dashEnabled = true;
|
||||
}
|
||||
}
|
||||
getSelfRect() {
|
||||
const lineRect = super.getSelfRect();
|
||||
const offset = this.pointerWidth() / 2;
|
||||
return {
|
||||
x: lineRect.x - offset,
|
||||
y: lineRect.y - offset,
|
||||
width: lineRect.width + offset * 2,
|
||||
height: lineRect.height + offset * 2,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.Arrow = Arrow;
|
||||
Arrow.prototype.className = 'Arrow';
|
||||
(0, Global_1._registerNode)(Arrow);
|
||||
Factory_1.Factory.addGetterSetter(Arrow, 'pointerLength', 10, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Arrow, 'pointerWidth', 10, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Arrow, 'pointerAtBeginning', false);
|
||||
Factory_1.Factory.addGetterSetter(Arrow, 'pointerAtEnding', true);
|
||||
13
node_modules/konva/cmj/shapes/Circle.d.ts
generated
vendored
Normal file
13
node_modules/konva/cmj/shapes/Circle.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { GetSet } from '../types';
|
||||
export interface CircleConfig extends ShapeConfig {
|
||||
radius?: number;
|
||||
}
|
||||
export declare class Circle extends Shape<CircleConfig> {
|
||||
_sceneFunc(context: any): void;
|
||||
getWidth(): number;
|
||||
getHeight(): number;
|
||||
setWidth(width: any): void;
|
||||
setHeight(height: any): void;
|
||||
radius: GetSet<number, this>;
|
||||
}
|
||||
37
node_modules/konva/cmj/shapes/Circle.js
generated
vendored
Normal file
37
node_modules/konva/cmj/shapes/Circle.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Circle = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Shape_1 = require("../Shape");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Global_1 = require("../Global");
|
||||
class Circle extends Shape_1.Shape {
|
||||
_sceneFunc(context) {
|
||||
context.beginPath();
|
||||
context.arc(0, 0, this.attrs.radius || 0, 0, Math.PI * 2, false);
|
||||
context.closePath();
|
||||
context.fillStrokeShape(this);
|
||||
}
|
||||
getWidth() {
|
||||
return this.radius() * 2;
|
||||
}
|
||||
getHeight() {
|
||||
return this.radius() * 2;
|
||||
}
|
||||
setWidth(width) {
|
||||
if (this.radius() !== width / 2) {
|
||||
this.radius(width / 2);
|
||||
}
|
||||
}
|
||||
setHeight(height) {
|
||||
if (this.radius() !== height / 2) {
|
||||
this.radius(height / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Circle = Circle;
|
||||
Circle.prototype._centroid = true;
|
||||
Circle.prototype.className = 'Circle';
|
||||
Circle.prototype._attrsAffectingSize = ['radius'];
|
||||
(0, Global_1._registerNode)(Circle);
|
||||
Factory_1.Factory.addGetterSetter(Circle, 'radius', 0, (0, Validators_1.getNumberValidator)());
|
||||
16
node_modules/konva/cmj/shapes/Ellipse.d.ts
generated
vendored
Normal file
16
node_modules/konva/cmj/shapes/Ellipse.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { GetSet, Vector2d } from '../types';
|
||||
export interface EllipseConfig extends ShapeConfig {
|
||||
radiusX: number;
|
||||
radiusY: number;
|
||||
}
|
||||
export declare class Ellipse extends Shape<EllipseConfig> {
|
||||
_sceneFunc(context: any): void;
|
||||
getWidth(): number;
|
||||
getHeight(): number;
|
||||
setWidth(width: any): void;
|
||||
setHeight(height: any): void;
|
||||
radius: GetSet<Vector2d, this>;
|
||||
radiusX: GetSet<number, this>;
|
||||
radiusY: GetSet<number, this>;
|
||||
}
|
||||
41
node_modules/konva/cmj/shapes/Ellipse.js
generated
vendored
Normal file
41
node_modules/konva/cmj/shapes/Ellipse.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Ellipse = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Shape_1 = require("../Shape");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Global_1 = require("../Global");
|
||||
class Ellipse extends Shape_1.Shape {
|
||||
_sceneFunc(context) {
|
||||
var rx = this.radiusX(), ry = this.radiusY();
|
||||
context.beginPath();
|
||||
context.save();
|
||||
if (rx !== ry) {
|
||||
context.scale(1, ry / rx);
|
||||
}
|
||||
context.arc(0, 0, rx, 0, Math.PI * 2, false);
|
||||
context.restore();
|
||||
context.closePath();
|
||||
context.fillStrokeShape(this);
|
||||
}
|
||||
getWidth() {
|
||||
return this.radiusX() * 2;
|
||||
}
|
||||
getHeight() {
|
||||
return this.radiusY() * 2;
|
||||
}
|
||||
setWidth(width) {
|
||||
this.radiusX(width / 2);
|
||||
}
|
||||
setHeight(height) {
|
||||
this.radiusY(height / 2);
|
||||
}
|
||||
}
|
||||
exports.Ellipse = Ellipse;
|
||||
Ellipse.prototype.className = 'Ellipse';
|
||||
Ellipse.prototype._centroid = true;
|
||||
Ellipse.prototype._attrsAffectingSize = ['radiusX', 'radiusY'];
|
||||
(0, Global_1._registerNode)(Ellipse);
|
||||
Factory_1.Factory.addComponentsGetterSetter(Ellipse, 'radius', ['x', 'y']);
|
||||
Factory_1.Factory.addGetterSetter(Ellipse, 'radiusX', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Ellipse, 'radiusY', 0, (0, Validators_1.getNumberValidator)());
|
||||
23
node_modules/konva/cmj/shapes/Image.d.ts
generated
vendored
Normal file
23
node_modules/konva/cmj/shapes/Image.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { GetSet, IRect } from '../types';
|
||||
import { Context } from '../Context';
|
||||
export interface ImageConfig extends ShapeConfig {
|
||||
image: CanvasImageSource | undefined;
|
||||
crop?: IRect;
|
||||
}
|
||||
export declare class Image extends Shape<ImageConfig> {
|
||||
constructor(attrs: ImageConfig);
|
||||
_setImageLoad(): void;
|
||||
_useBufferCanvas(): boolean;
|
||||
_sceneFunc(context: Context): void;
|
||||
_hitFunc(context: any): void;
|
||||
getWidth(): any;
|
||||
getHeight(): any;
|
||||
static fromURL(url: any, callback: any): void;
|
||||
image: GetSet<CanvasImageSource | undefined, this>;
|
||||
crop: GetSet<IRect, this>;
|
||||
cropX: GetSet<number, this>;
|
||||
cropY: GetSet<number, this>;
|
||||
cropWidth: GetSet<number, this>;
|
||||
cropHeight: GetSet<number, this>;
|
||||
}
|
||||
104
node_modules/konva/cmj/shapes/Image.js
generated
vendored
Normal file
104
node_modules/konva/cmj/shapes/Image.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Image = void 0;
|
||||
const Util_1 = require("../Util");
|
||||
const Factory_1 = require("../Factory");
|
||||
const Shape_1 = require("../Shape");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Global_1 = require("../Global");
|
||||
class Image extends Shape_1.Shape {
|
||||
constructor(attrs) {
|
||||
super(attrs);
|
||||
this.on('imageChange.konva', () => {
|
||||
this._setImageLoad();
|
||||
});
|
||||
this._setImageLoad();
|
||||
}
|
||||
_setImageLoad() {
|
||||
const image = this.image();
|
||||
if (image && image.complete) {
|
||||
return;
|
||||
}
|
||||
if (image && image.readyState === 4) {
|
||||
return;
|
||||
}
|
||||
if (image && image['addEventListener']) {
|
||||
image['addEventListener']('load', () => {
|
||||
this._requestDraw();
|
||||
});
|
||||
}
|
||||
}
|
||||
_useBufferCanvas() {
|
||||
return super._useBufferCanvas(true);
|
||||
}
|
||||
_sceneFunc(context) {
|
||||
const width = this.getWidth();
|
||||
const height = this.getHeight();
|
||||
const image = this.attrs.image;
|
||||
let params;
|
||||
if (image) {
|
||||
const cropWidth = this.attrs.cropWidth;
|
||||
const cropHeight = this.attrs.cropHeight;
|
||||
if (cropWidth && cropHeight) {
|
||||
params = [
|
||||
image,
|
||||
this.cropX(),
|
||||
this.cropY(),
|
||||
cropWidth,
|
||||
cropHeight,
|
||||
0,
|
||||
0,
|
||||
width,
|
||||
height,
|
||||
];
|
||||
}
|
||||
else {
|
||||
params = [image, 0, 0, width, height];
|
||||
}
|
||||
}
|
||||
if (this.hasFill() || this.hasStroke()) {
|
||||
context.beginPath();
|
||||
context.rect(0, 0, width, height);
|
||||
context.closePath();
|
||||
context.fillStrokeShape(this);
|
||||
}
|
||||
if (image) {
|
||||
context.drawImage.apply(context, params);
|
||||
}
|
||||
}
|
||||
_hitFunc(context) {
|
||||
var width = this.width(), height = this.height();
|
||||
context.beginPath();
|
||||
context.rect(0, 0, width, height);
|
||||
context.closePath();
|
||||
context.fillStrokeShape(this);
|
||||
}
|
||||
getWidth() {
|
||||
var _a, _b;
|
||||
return (_a = this.attrs.width) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.width;
|
||||
}
|
||||
getHeight() {
|
||||
var _a, _b;
|
||||
return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
|
||||
}
|
||||
static fromURL(url, callback) {
|
||||
var img = Util_1.Util.createImageElement();
|
||||
img.onload = function () {
|
||||
var image = new Image({
|
||||
image: img,
|
||||
});
|
||||
callback(image);
|
||||
};
|
||||
img.crossOrigin = 'Anonymous';
|
||||
img.src = url;
|
||||
}
|
||||
}
|
||||
exports.Image = Image;
|
||||
Image.prototype.className = 'Image';
|
||||
(0, Global_1._registerNode)(Image);
|
||||
Factory_1.Factory.addGetterSetter(Image, 'image');
|
||||
Factory_1.Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
|
||||
Factory_1.Factory.addGetterSetter(Image, 'cropX', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Image, 'cropY', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Image, 'cropWidth', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Image, 'cropHeight', 0, (0, Validators_1.getNumberValidator)());
|
||||
35
node_modules/konva/cmj/shapes/Label.d.ts
generated
vendored
Normal file
35
node_modules/konva/cmj/shapes/Label.d.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Group } from '../Group';
|
||||
import { ContainerConfig } from '../Container';
|
||||
import { GetSet } from '../types';
|
||||
import { Text } from './Text';
|
||||
export interface LabelConfig extends ContainerConfig {
|
||||
}
|
||||
export declare class Label extends Group {
|
||||
constructor(config?: any);
|
||||
getText(): Text;
|
||||
getTag(): Tag;
|
||||
_addListeners(text: any): void;
|
||||
getWidth(): number;
|
||||
getHeight(): number;
|
||||
_sync(): void;
|
||||
}
|
||||
export interface TagConfig extends ShapeConfig {
|
||||
pointerDirection?: string;
|
||||
pointerWidth?: number;
|
||||
pointerHeight?: number;
|
||||
cornerRadius?: number | Array<number>;
|
||||
}
|
||||
export declare class Tag extends Shape<TagConfig> {
|
||||
_sceneFunc(context: any): void;
|
||||
getSelfRect(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
pointerDirection: GetSet<'left' | 'top' | 'right' | 'bottom', this>;
|
||||
pointerWidth: GetSet<number, this>;
|
||||
pointerHeight: GetSet<number, this>;
|
||||
cornerRadius: GetSet<number, this>;
|
||||
}
|
||||
171
node_modules/konva/cmj/shapes/Label.js
generated
vendored
Normal file
171
node_modules/konva/cmj/shapes/Label.js
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Tag = exports.Label = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Shape_1 = require("../Shape");
|
||||
const Group_1 = require("../Group");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Global_1 = require("../Global");
|
||||
var ATTR_CHANGE_LIST = [
|
||||
'fontFamily',
|
||||
'fontSize',
|
||||
'fontStyle',
|
||||
'padding',
|
||||
'lineHeight',
|
||||
'text',
|
||||
'width',
|
||||
'height',
|
||||
], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left', attrChangeListLen = ATTR_CHANGE_LIST.length;
|
||||
class Label extends Group_1.Group {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
this.on('add.konva', function (evt) {
|
||||
this._addListeners(evt.child);
|
||||
this._sync();
|
||||
});
|
||||
}
|
||||
getText() {
|
||||
return this.find('Text')[0];
|
||||
}
|
||||
getTag() {
|
||||
return this.find('Tag')[0];
|
||||
}
|
||||
_addListeners(text) {
|
||||
var that = this, n;
|
||||
var func = function () {
|
||||
that._sync();
|
||||
};
|
||||
for (n = 0; n < attrChangeListLen; n++) {
|
||||
text.on(ATTR_CHANGE_LIST[n] + CHANGE_KONVA, func);
|
||||
}
|
||||
}
|
||||
getWidth() {
|
||||
return this.getText().width();
|
||||
}
|
||||
getHeight() {
|
||||
return this.getText().height();
|
||||
}
|
||||
_sync() {
|
||||
var text = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight;
|
||||
if (text && tag) {
|
||||
width = text.width();
|
||||
height = text.height();
|
||||
pointerDirection = tag.pointerDirection();
|
||||
pointerWidth = tag.pointerWidth();
|
||||
pointerHeight = tag.pointerHeight();
|
||||
x = 0;
|
||||
y = 0;
|
||||
switch (pointerDirection) {
|
||||
case UP:
|
||||
x = width / 2;
|
||||
y = -1 * pointerHeight;
|
||||
break;
|
||||
case RIGHT:
|
||||
x = width + pointerWidth;
|
||||
y = height / 2;
|
||||
break;
|
||||
case DOWN:
|
||||
x = width / 2;
|
||||
y = height + pointerHeight;
|
||||
break;
|
||||
case LEFT:
|
||||
x = -1 * pointerWidth;
|
||||
y = height / 2;
|
||||
break;
|
||||
}
|
||||
tag.setAttrs({
|
||||
x: -1 * x,
|
||||
y: -1 * y,
|
||||
width: width,
|
||||
height: height,
|
||||
});
|
||||
text.setAttrs({
|
||||
x: -1 * x,
|
||||
y: -1 * y,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Label = Label;
|
||||
Label.prototype.className = 'Label';
|
||||
(0, Global_1._registerNode)(Label);
|
||||
class Tag extends Shape_1.Shape {
|
||||
_sceneFunc(context) {
|
||||
var width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
|
||||
let topLeft = 0;
|
||||
let topRight = 0;
|
||||
let bottomLeft = 0;
|
||||
let bottomRight = 0;
|
||||
if (typeof cornerRadius === 'number') {
|
||||
topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
|
||||
}
|
||||
else {
|
||||
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
||||
topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
||||
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
||||
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
||||
}
|
||||
context.beginPath();
|
||||
context.moveTo(topLeft, 0);
|
||||
if (pointerDirection === UP) {
|
||||
context.lineTo((width - pointerWidth) / 2, 0);
|
||||
context.lineTo(width / 2, -1 * pointerHeight);
|
||||
context.lineTo((width + pointerWidth) / 2, 0);
|
||||
}
|
||||
context.lineTo(width - topRight, 0);
|
||||
context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
||||
if (pointerDirection === RIGHT) {
|
||||
context.lineTo(width, (height - pointerHeight) / 2);
|
||||
context.lineTo(width + pointerWidth, height / 2);
|
||||
context.lineTo(width, (height + pointerHeight) / 2);
|
||||
}
|
||||
context.lineTo(width, height - bottomRight);
|
||||
context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
||||
if (pointerDirection === DOWN) {
|
||||
context.lineTo((width + pointerWidth) / 2, height);
|
||||
context.lineTo(width / 2, height + pointerHeight);
|
||||
context.lineTo((width - pointerWidth) / 2, height);
|
||||
}
|
||||
context.lineTo(bottomLeft, height);
|
||||
context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
||||
if (pointerDirection === LEFT) {
|
||||
context.lineTo(0, (height + pointerHeight) / 2);
|
||||
context.lineTo(-1 * pointerWidth, height / 2);
|
||||
context.lineTo(0, (height - pointerHeight) / 2);
|
||||
}
|
||||
context.lineTo(0, topLeft);
|
||||
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
||||
context.closePath();
|
||||
context.fillStrokeShape(this);
|
||||
}
|
||||
getSelfRect() {
|
||||
var x = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();
|
||||
if (direction === UP) {
|
||||
y -= pointerHeight;
|
||||
height += pointerHeight;
|
||||
}
|
||||
else if (direction === DOWN) {
|
||||
height += pointerHeight;
|
||||
}
|
||||
else if (direction === LEFT) {
|
||||
x -= pointerWidth * 1.5;
|
||||
width += pointerWidth;
|
||||
}
|
||||
else if (direction === RIGHT) {
|
||||
width += pointerWidth * 1.5;
|
||||
}
|
||||
return {
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.Tag = Tag;
|
||||
Tag.prototype.className = 'Tag';
|
||||
(0, Global_1._registerNode)(Tag);
|
||||
Factory_1.Factory.addGetterSetter(Tag, 'pointerDirection', NONE);
|
||||
Factory_1.Factory.addGetterSetter(Tag, 'pointerWidth', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Tag, 'pointerHeight', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Tag, 'cornerRadius', 0, (0, Validators_1.getNumberOrArrayOfNumbersValidator)(4));
|
||||
28
node_modules/konva/cmj/shapes/Line.d.ts
generated
vendored
Normal file
28
node_modules/konva/cmj/shapes/Line.d.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { GetSet } from '../types';
|
||||
import { Context } from '../Context';
|
||||
export interface LineConfig extends ShapeConfig {
|
||||
points?: number[];
|
||||
tension?: number;
|
||||
closed?: boolean;
|
||||
bezier?: boolean;
|
||||
}
|
||||
export declare class Line<Config extends LineConfig = LineConfig> extends Shape<Config> {
|
||||
constructor(config?: Config);
|
||||
_sceneFunc(context: Context): void;
|
||||
getTensionPoints(): any;
|
||||
_getTensionPoints(): any[];
|
||||
_getTensionPointsClosed(): any[];
|
||||
getWidth(): number;
|
||||
getHeight(): number;
|
||||
getSelfRect(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
closed: GetSet<boolean, this>;
|
||||
bezier: GetSet<boolean, this>;
|
||||
tension: GetSet<number, this>;
|
||||
points: GetSet<number[], this>;
|
||||
}
|
||||
159
node_modules/konva/cmj/shapes/Line.js
generated
vendored
Normal file
159
node_modules/konva/cmj/shapes/Line.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Line = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Shape_1 = require("../Shape");
|
||||
const Validators_1 = require("../Validators");
|
||||
const Global_1 = require("../Global");
|
||||
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
|
||||
var d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = (t * d01) / (d01 + d12), fb = (t * d12) / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);
|
||||
return [p1x, p1y, p2x, p2y];
|
||||
}
|
||||
function expandPoints(p, tension) {
|
||||
var len = p.length, allPoints = [], n, cp;
|
||||
for (n = 2; n < len - 2; n += 2) {
|
||||
cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
|
||||
if (isNaN(cp[0])) {
|
||||
continue;
|
||||
}
|
||||
allPoints.push(cp[0]);
|
||||
allPoints.push(cp[1]);
|
||||
allPoints.push(p[n]);
|
||||
allPoints.push(p[n + 1]);
|
||||
allPoints.push(cp[2]);
|
||||
allPoints.push(cp[3]);
|
||||
}
|
||||
return allPoints;
|
||||
}
|
||||
class Line extends Shape_1.Shape {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
this.on('pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva', function () {
|
||||
this._clearCache('tensionPoints');
|
||||
});
|
||||
}
|
||||
_sceneFunc(context) {
|
||||
var points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n;
|
||||
if (!length) {
|
||||
return;
|
||||
}
|
||||
context.beginPath();
|
||||
context.moveTo(points[0], points[1]);
|
||||
if (tension !== 0 && length > 4) {
|
||||
tp = this.getTensionPoints();
|
||||
len = tp.length;
|
||||
n = closed ? 0 : 4;
|
||||
if (!closed) {
|
||||
context.quadraticCurveTo(tp[0], tp[1], tp[2], tp[3]);
|
||||
}
|
||||
while (n < len - 2) {
|
||||
context.bezierCurveTo(tp[n++], tp[n++], tp[n++], tp[n++], tp[n++], tp[n++]);
|
||||
}
|
||||
if (!closed) {
|
||||
context.quadraticCurveTo(tp[len - 2], tp[len - 1], points[length - 2], points[length - 1]);
|
||||
}
|
||||
}
|
||||
else if (bezier) {
|
||||
n = 2;
|
||||
while (n < length) {
|
||||
context.bezierCurveTo(points[n++], points[n++], points[n++], points[n++], points[n++], points[n++]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (n = 2; n < length; n += 2) {
|
||||
context.lineTo(points[n], points[n + 1]);
|
||||
}
|
||||
}
|
||||
if (closed) {
|
||||
context.closePath();
|
||||
context.fillStrokeShape(this);
|
||||
}
|
||||
else {
|
||||
context.strokeShape(this);
|
||||
}
|
||||
}
|
||||
getTensionPoints() {
|
||||
return this._getCache('tensionPoints', this._getTensionPoints);
|
||||
}
|
||||
_getTensionPoints() {
|
||||
if (this.closed()) {
|
||||
return this._getTensionPointsClosed();
|
||||
}
|
||||
else {
|
||||
return expandPoints(this.points(), this.tension());
|
||||
}
|
||||
}
|
||||
_getTensionPointsClosed() {
|
||||
var p = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]]
|
||||
.concat(middle)
|
||||
.concat([
|
||||
lastControlPoints[0],
|
||||
lastControlPoints[1],
|
||||
p[len - 2],
|
||||
p[len - 1],
|
||||
lastControlPoints[2],
|
||||
lastControlPoints[3],
|
||||
firstControlPoints[0],
|
||||
firstControlPoints[1],
|
||||
p[0],
|
||||
p[1],
|
||||
]);
|
||||
return tp;
|
||||
}
|
||||
getWidth() {
|
||||
return this.getSelfRect().width;
|
||||
}
|
||||
getHeight() {
|
||||
return this.getSelfRect().height;
|
||||
}
|
||||
getSelfRect() {
|
||||
var points = this.points();
|
||||
if (points.length < 4) {
|
||||
return {
|
||||
x: points[0] || 0,
|
||||
y: points[1] || 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
};
|
||||
}
|
||||
if (this.tension() !== 0) {
|
||||
points = [
|
||||
points[0],
|
||||
points[1],
|
||||
...this._getTensionPoints(),
|
||||
points[points.length - 2],
|
||||
points[points.length - 1],
|
||||
];
|
||||
}
|
||||
else {
|
||||
points = this.points();
|
||||
}
|
||||
var minX = points[0];
|
||||
var maxX = points[0];
|
||||
var minY = points[1];
|
||||
var maxY = points[1];
|
||||
var x, y;
|
||||
for (var i = 0; i < points.length / 2; i++) {
|
||||
x = points[i * 2];
|
||||
y = points[i * 2 + 1];
|
||||
minX = Math.min(minX, x);
|
||||
maxX = Math.max(maxX, x);
|
||||
minY = Math.min(minY, y);
|
||||
maxY = Math.max(maxY, y);
|
||||
}
|
||||
return {
|
||||
x: minX,
|
||||
y: minY,
|
||||
width: maxX - minX,
|
||||
height: maxY - minY,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.Line = Line;
|
||||
Line.prototype.className = 'Line';
|
||||
Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension'];
|
||||
(0, Global_1._registerNode)(Line);
|
||||
Factory_1.Factory.addGetterSetter(Line, 'closed', false);
|
||||
Factory_1.Factory.addGetterSetter(Line, 'bezier', false);
|
||||
Factory_1.Factory.addGetterSetter(Line, 'tension', 0, (0, Validators_1.getNumberValidator)());
|
||||
Factory_1.Factory.addGetterSetter(Line, 'points', [], (0, Validators_1.getNumberArrayValidator)());
|
||||
37
node_modules/konva/cmj/shapes/Path.d.ts
generated
vendored
Normal file
37
node_modules/konva/cmj/shapes/Path.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { GetSet } from '../types';
|
||||
export interface PathConfig extends ShapeConfig {
|
||||
data?: string;
|
||||
}
|
||||
export declare class Path extends Shape<PathConfig> {
|
||||
dataArray: any[];
|
||||
pathLength: number;
|
||||
constructor(config?: PathConfig);
|
||||
_sceneFunc(context: any): void;
|
||||
getSelfRect(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
getLength(): number;
|
||||
getPointAtLength(length: any): any;
|
||||
data: GetSet<string, this>;
|
||||
static getLineLength(x1: any, y1: any, x2: any, y2: any): number;
|
||||
static getPointOnLine(dist: any, P1x: any, P1y: any, P2x: any, P2y: any, fromX?: any, fromY?: any): any;
|
||||
static getPointOnCubicBezier(pct: any, P1x: any, P1y: any, P2x: any, P2y: any, P3x: any, P3y: any, P4x: any, P4y: any): {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
static getPointOnQuadraticBezier(pct: any, P1x: any, P1y: any, P2x: any, P2y: any, P3x: any, P3y: any): {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
static getPointOnEllipticalArc(cx: any, cy: any, rx: any, ry: any, theta: any, psi: any): {
|
||||
x: any;
|
||||
y: any;
|
||||
};
|
||||
static parsePathData(data: any): any[];
|
||||
static calcLength(x: any, y: any, cmd: any, points: any): any;
|
||||
static convertEndpointToCenterParameterization(x1: any, y1: any, x2: any, y2: any, fa: any, fs: any, rx: any, ry: any, psiDeg: any): any[];
|
||||
}
|
||||
631
node_modules/konva/cmj/shapes/Path.js
generated
vendored
Normal file
631
node_modules/konva/cmj/shapes/Path.js
generated
vendored
Normal file
@@ -0,0 +1,631 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Path = void 0;
|
||||
const Factory_1 = require("../Factory");
|
||||
const Shape_1 = require("../Shape");
|
||||
const Global_1 = require("../Global");
|
||||
class Path extends Shape_1.Shape {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
this.dataArray = [];
|
||||
this.pathLength = 0;
|
||||
this.dataArray = Path.parsePathData(this.data());
|
||||
this.pathLength = 0;
|
||||
for (var i = 0; i < this.dataArray.length; ++i) {
|
||||
this.pathLength += this.dataArray[i].pathLength;
|
||||
}
|
||||
this.on('dataChange.konva', function () {
|
||||
this.dataArray = Path.parsePathData(this.data());
|
||||
this.pathLength = 0;
|
||||
for (var i = 0; i < this.dataArray.length; ++i) {
|
||||
this.pathLength += this.dataArray[i].pathLength;
|
||||
}
|
||||
});
|
||||
}
|
||||
_sceneFunc(context) {
|
||||
var ca = this.dataArray;
|
||||
context.beginPath();
|
||||
var isClosed = false;
|
||||
for (var n = 0; n < ca.length; n++) {
|
||||
var c = ca[n].command;
|
||||
var p = ca[n].points;
|
||||
switch (c) {
|
||||
case 'L':
|
||||
context.lineTo(p[0], p[1]);
|
||||
break;
|
||||
case 'M':
|
||||
context.moveTo(p[0], p[1]);
|
||||
break;
|
||||
case 'C':
|
||||
context.bezierCurveTo(p[0], p[1], p[2], p[3], p[4], p[5]);
|
||||
break;
|
||||
case 'Q':
|
||||
context.quadraticCurveTo(p[0], p[1], p[2], p[3]);
|
||||
break;
|
||||
case 'A':
|
||||
var cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6], fs = p[7];
|
||||
var r = rx > ry ? rx : ry;
|
||||
var scaleX = rx > ry ? 1 : rx / ry;
|
||||
var scaleY = rx > ry ? ry / rx : 1;
|
||||
context.translate(cx, cy);
|
||||
context.rotate(psi);
|
||||
context.scale(scaleX, scaleY);
|
||||
context.arc(0, 0, r, theta, theta + dTheta, 1 - fs);
|
||||
context.scale(1 / scaleX, 1 / scaleY);
|
||||
context.rotate(-psi);
|
||||
context.translate(-cx, -cy);
|
||||
break;
|
||||
case 'z':
|
||||
isClosed = true;
|
||||
context.closePath();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isClosed && !this.hasFill()) {
|
||||
context.strokeShape(this);
|
||||
}
|
||||
else {
|
||||
context.fillStrokeShape(this);
|
||||
}
|
||||
}
|
||||
getSelfRect() {
|
||||
var points = [];
|
||||
this.dataArray.forEach(function (data) {
|
||||
if (data.command === 'A') {
|
||||
var start = data.points[4];
|
||||
var dTheta = data.points[5];
|
||||
var end = data.points[4] + dTheta;
|
||||
var inc = Math.PI / 180.0;
|
||||
if (Math.abs(start - end) < inc) {
|
||||
inc = Math.abs(start - end);
|
||||
}
|
||||
if (dTheta < 0) {
|
||||
for (let t = start - inc; t > end; t -= inc) {
|
||||
const point = Path.getPointOnEllipticalArc(data.points[0], data.points[1], data.points[2], data.points[3], t, 0);
|
||||
points.push(point.x, point.y);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let t = start + inc; t < end; t += inc) {
|
||||
const point = Path.getPointOnEllipticalArc(data.points[0], data.points[1], data.points[2], data.points[3], t, 0);
|
||||
points.push(point.x, point.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (data.command === 'C') {
|
||||
for (let t = 0.0; t <= 1; t += 0.01) {
|
||||
const point = Path.getPointOnCubicBezier(t, data.start.x, data.start.y, data.points[0], data.points[1], data.points[2], data.points[3], data.points[4], data.points[5]);
|
||||
points.push(point.x, point.y);
|
||||
}
|
||||
}
|
||||
else {
|
||||
points = points.concat(data.points);
|
||||
}
|
||||
});
|
||||
var minX = points[0];
|
||||
var maxX = points[0];
|
||||
var minY = points[1];
|
||||
var maxY = points[1];
|
||||
var x, y;
|
||||
for (var i = 0; i < points.length / 2; i++) {
|
||||
x = points[i * 2];
|
||||
y = points[i * 2 + 1];
|
||||
if (!isNaN(x)) {
|
||||
minX = Math.min(minX, x);
|
||||
maxX = Math.max(maxX, x);
|
||||
}
|
||||
if (!isNaN(y)) {
|
||||
minY = Math.min(minY, y);
|
||||
maxY = Math.max(maxY, y);
|
||||
}
|
||||
}
|
||||
return {
|
||||
x: Math.round(minX),
|
||||
y: Math.round(minY),
|
||||
width: Math.round(maxX - minX),
|
||||
height: Math.round(maxY - minY),
|
||||
};
|
||||
}
|
||||
getLength() {
|
||||
return this.pathLength;
|
||||
}
|
||||
getPointAtLength(length) {
|
||||
var point, i = 0, ii = this.dataArray.length;
|
||||
if (!ii) {
|
||||
return null;
|
||||
}
|
||||
while (i < ii && length > this.dataArray[i].pathLength) {
|
||||
length -= this.dataArray[i].pathLength;
|
||||
++i;
|
||||
}
|
||||
if (i === ii) {
|
||||
point = this.dataArray[i - 1].points.slice(-2);
|
||||
return {
|
||||
x: point[0],
|
||||
y: point[1],
|
||||
};
|
||||
}
|
||||
if (length < 0.01) {
|
||||
point = this.dataArray[i].points.slice(0, 2);
|
||||
return {
|
||||
x: point[0],
|
||||
y: point[1],
|
||||
};
|
||||
}
|
||||
var cp = this.dataArray[i];
|
||||
var p = cp.points;
|
||||
switch (cp.command) {
|
||||
case 'L':
|
||||
return Path.getPointOnLine(length, cp.start.x, cp.start.y, p[0], p[1]);
|
||||
case 'C':
|
||||
return Path.getPointOnCubicBezier(length / cp.pathLength, cp.start.x, cp.start.y, p[0], p[1], p[2], p[3], p[4], p[5]);
|
||||
case 'Q':
|
||||
return Path.getPointOnQuadraticBezier(length / cp.pathLength, cp.start.x, cp.start.y, p[0], p[1], p[2], p[3]);
|
||||
case 'A':
|
||||
var cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6];
|
||||
theta += (dTheta * length) / cp.pathLength;
|
||||
return Path.getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static getLineLength(x1, y1, x2, y2) {
|
||||
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
||||
}
|
||||
static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
|
||||
if (fromX === undefined) {
|
||||
fromX = P1x;
|
||||
}
|
||||
if (fromY === undefined) {
|
||||
fromY = P1y;
|
||||
}
|
||||
var m = (P2y - P1y) / (P2x - P1x + 0.00000001);
|
||||
var run = Math.sqrt((dist * dist) / (1 + m * m));
|
||||
if (P2x < P1x) {
|
||||
run *= -1;
|
||||
}
|
||||
var rise = m * run;
|
||||
var pt;
|
||||
if (P2x === P1x) {
|
||||
pt = {
|
||||
x: fromX,
|
||||
y: fromY + rise,
|
||||
};
|
||||
}
|
||||
else if ((fromY - P1y) / (fromX - P1x + 0.00000001) === m) {
|
||||
pt = {
|
||||
x: fromX + run,
|
||||
y: fromY + rise,
|
||||
};
|
||||
}
|
||||
else {
|
||||
var ix, iy;
|
||||
var len = this.getLineLength(P1x, P1y, P2x, P2y);
|
||||
var u = (fromX - P1x) * (P2x - P1x) + (fromY - P1y) * (P2y - P1y);
|
||||
u = u / (len * len);
|
||||
ix = P1x + u * (P2x - P1x);
|
||||
iy = P1y + u * (P2y - P1y);
|
||||
var pRise = this.getLineLength(fromX, fromY, ix, iy);
|
||||
var pRun = Math.sqrt(dist * dist - pRise * pRise);
|
||||
run = Math.sqrt((pRun * pRun) / (1 + m * m));
|
||||
if (P2x < P1x) {
|
||||
run *= -1;
|
||||
}
|
||||
rise = m * run;
|
||||
pt = {
|
||||
x: ix + run,
|
||||
y: iy + rise,
|
||||
};
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
static getPointOnCubicBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y) {
|
||||
function CB1(t) {
|
||||
return t * t * t;
|
||||
}
|
||||
function CB2(t) {
|
||||
return 3 * t * t * (1 - t);
|
||||
}
|
||||
function CB3(t) {
|
||||
return 3 * t * (1 - t) * (1 - t);
|
||||
}
|
||||
function CB4(t) {
|
||||
return (1 - t) * (1 - t) * (1 - t);
|
||||
}
|
||||
var x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
|
||||
var y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
|
||||
return {
|
||||
x: x,
|
||||
y: y,
|
||||
};
|
||||
}
|
||||
static getPointOnQuadraticBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y) {
|
||||
function QB1(t) {
|
||||
return t * t;
|
||||
}
|
||||
function QB2(t) {
|
||||
return 2 * t * (1 - t);
|
||||
}
|
||||
function QB3(t) {
|
||||
return (1 - t) * (1 - t);
|
||||
}
|
||||
var x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
|
||||
var y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
|
||||
return {
|
||||
x: x,
|
||||
y: y,
|
||||
};
|
||||
}
|
||||
static getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) {
|
||||
var cosPsi = Math.cos(psi), sinPsi = Math.sin(psi);
|
||||
var pt = {
|
||||
x: rx * Math.cos(theta),
|
||||
y: ry * Math.sin(theta),
|
||||
};
|
||||
return {
|
||||
x: cx + (pt.x * cosPsi - pt.y * sinPsi),
|
||||
y: cy + (pt.x * sinPsi + pt.y * cosPsi),
|
||||
};
|
||||
}
|
||||
static parsePathData(data) {
|
||||
if (!data) {
|
||||
return [];
|
||||
}
|
||||
var cs = data;
|
||||
var cc = [
|
||||
'm',
|
||||
'M',
|
||||
'l',
|
||||
'L',
|
||||
'v',
|
||||
'V',
|
||||
'h',
|
||||
'H',
|
||||
'z',
|
||||
'Z',
|
||||
'c',
|
||||
'C',
|
||||
'q',
|
||||
'Q',
|
||||
't',
|
||||
'T',
|
||||
's',
|
||||
'S',
|
||||
'a',
|
||||
'A',
|
||||
];
|
||||
cs = cs.replace(new RegExp(' ', 'g'), ',');
|
||||
for (var n = 0; n < cc.length; n++) {
|
||||
cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
|
||||
}
|
||||
var arr = cs.split('|');
|
||||
var ca = [];
|
||||
var coords = [];
|
||||
var cpx = 0;
|
||||
var cpy = 0;
|
||||
var re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
|
||||
var match;
|
||||
for (n = 1; n < arr.length; n++) {
|
||||
var str = arr[n];
|
||||
var c = str.charAt(0);
|
||||
str = str.slice(1);
|
||||
coords.length = 0;
|
||||
while ((match = re.exec(str))) {
|
||||
coords.push(match[0]);
|
||||
}
|
||||
var p = [];
|
||||
for (var j = 0, jlen = coords.length; j < jlen; j++) {
|
||||
if (coords[j] === '00') {
|
||||
p.push(0, 0);
|
||||
continue;
|
||||
}
|
||||
var parsed = parseFloat(coords[j]);
|
||||
if (!isNaN(parsed)) {
|
||||
p.push(parsed);
|
||||
}
|
||||
else {
|
||||
p.push(0);
|
||||
}
|
||||
}
|
||||
while (p.length > 0) {
|
||||
if (isNaN(p[0])) {
|
||||
break;
|
||||
}
|
||||
var cmd = null;
|
||||
var points = [];
|
||||
var startX = cpx, startY = cpy;
|
||||
var prevCmd, ctlPtx, ctlPty;
|
||||
var rx, ry, psi, fa, fs, x1, y1;
|
||||
switch (c) {
|
||||
case 'l':
|
||||
cpx += p.shift();
|
||||
cpy += p.shift();
|
||||
cmd = 'L';
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'L':
|
||||
cpx = p.shift();
|
||||
cpy = p.shift();
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'm':
|
||||
var dx = p.shift();
|
||||
var dy = p.shift();
|
||||
cpx += dx;
|
||||
cpy += dy;
|
||||
cmd = 'M';
|
||||
if (ca.length > 2 && ca[ca.length - 1].command === 'z') {
|
||||
for (var idx = ca.length - 2; idx >= 0; idx--) {
|
||||
if (ca[idx].command === 'M') {
|
||||
cpx = ca[idx].points[0] + dx;
|
||||
cpy = ca[idx].points[1] + dy;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
points.push(cpx, cpy);
|
||||
c = 'l';
|
||||
break;
|
||||
case 'M':
|
||||
cpx = p.shift();
|
||||
cpy = p.shift();
|
||||
cmd = 'M';
|
||||
points.push(cpx, cpy);
|
||||
c = 'L';
|
||||
break;
|
||||
case 'h':
|
||||
cpx += p.shift();
|
||||
cmd = 'L';
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'H':
|
||||
cpx = p.shift();
|
||||
cmd = 'L';
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'v':
|
||||
cpy += p.shift();
|
||||
cmd = 'L';
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'V':
|
||||
cpy = p.shift();
|
||||
cmd = 'L';
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'C':
|
||||
points.push(p.shift(), p.shift(), p.shift(), p.shift());
|
||||
cpx = p.shift();
|
||||
cpy = p.shift();
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'c':
|
||||
points.push(cpx + p.shift(), cpy + p.shift(), cpx + p.shift(), cpy + p.shift());
|
||||
cpx += p.shift();
|
||||
cpy += p.shift();
|
||||
cmd = 'C';
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'S':
|
||||
ctlPtx = cpx;
|
||||
ctlPty = cpy;
|
||||
prevCmd = ca[ca.length - 1];
|
||||
if (prevCmd.command === 'C') {
|
||||
ctlPtx = cpx + (cpx - prevCmd.points[2]);
|
||||
ctlPty = cpy + (cpy - prevCmd.points[3]);
|
||||
}
|
||||
points.push(ctlPtx, ctlPty, p.shift(), p.shift());
|
||||
cpx = p.shift();
|
||||
cpy = p.shift();
|
||||
cmd = 'C';
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 's':
|
||||
ctlPtx = cpx;
|
||||
ctlPty = cpy;
|
||||
prevCmd = ca[ca.length - 1];
|
||||
if (prevCmd.command === 'C') {
|
||||
ctlPtx = cpx + (cpx - prevCmd.points[2]);
|
||||
ctlPty = cpy + (cpy - prevCmd.points[3]);
|
||||
}
|
||||
points.push(ctlPtx, ctlPty, cpx + p.shift(), cpy + p.shift());
|
||||
cpx += p.shift();
|
||||
cpy += p.shift();
|
||||
cmd = 'C';
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'Q':
|
||||
points.push(p.shift(), p.shift());
|
||||
cpx = p.shift();
|
||||
cpy = p.shift();
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'q':
|
||||
points.push(cpx + p.shift(), cpy + p.shift());
|
||||
cpx += p.shift();
|
||||
cpy += p.shift();
|
||||
cmd = 'Q';
|
||||
points.push(cpx, cpy);
|
||||
break;
|
||||
case 'T':
|
||||
ctlPtx = cpx;
|
||||
ctlPty = cpy;
|
||||
prevCmd = ca[ca.length - 1];
|
||||
if (prevCmd.command === 'Q') {
|
||||
ctlPtx = cpx + (cpx - prevCmd.points[0]);
|
||||
ctlPty = cpy + (cpy - prevCmd.points[1]);
|
||||
}
|
||||
cpx = p.shift();
|
||||
cpy = p.shift();
|
||||
cmd = 'Q';
|
||||
points.push(ctlPtx, ctlPty, cpx, cpy);
|
||||
break;
|
||||
case 't':
|
||||
ctlPtx = cpx;
|
||||
ctlPty = cpy;
|
||||
prevCmd = ca[ca.length - 1];
|
||||
if (prevCmd.command === 'Q') {
|
||||
ctlPtx = cpx + (cpx - prevCmd.points[0]);
|
||||
ctlPty = cpy + (cpy - prevCmd.points[1]);
|
||||
}
|
||||
cpx += p.shift();
|
||||
cpy += p.shift();
|
||||
cmd = 'Q';
|
||||
points.push(ctlPtx, ctlPty, cpx, cpy);
|
||||
break;
|
||||
case 'A':
|
||||
rx = p.shift();
|
||||
ry = p.shift();
|
||||
psi = p.shift();
|
||||
fa = p.shift();
|
||||
fs = p.shift();
|
||||
x1 = cpx;
|
||||
y1 = cpy;
|
||||
cpx = p.shift();
|
||||
cpy = p.shift();
|
||||
cmd = 'A';
|
||||
points = this.convertEndpointToCenterParameterization(x1, y1, cpx, cpy, fa, fs, rx, ry, psi);
|
||||
break;
|
||||
case 'a':
|
||||
rx = p.shift();
|
||||
ry = p.shift();
|
||||
psi = p.shift();
|
||||
fa = p.shift();
|
||||
fs = p.shift();
|
||||
x1 = cpx;
|
||||
y1 = cpy;
|
||||
cpx += p.shift();
|
||||
cpy += p.shift();
|
||||
cmd = 'A';
|
||||
points = this.convertEndpointToCenterParameterization(x1, y1, cpx, cpy, fa, fs, rx, ry, psi);
|
||||
break;
|
||||
}
|
||||
ca.push({
|
||||
command: cmd || c,
|
||||
points: points,
|
||||
start: {
|
||||
x: startX,
|
||||
y: startY,
|
||||
},
|
||||
pathLength: this.calcLength(startX, startY, cmd || c, points),
|
||||
});
|
||||
}
|
||||
if (c === 'z' || c === 'Z') {
|
||||
ca.push({
|
||||
command: 'z',
|
||||
points: [],
|
||||
start: undefined,
|
||||
pathLength: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
return ca;
|
||||
}
|
||||
static calcLength(x, y, cmd, points) {
|
||||
var len, p1, p2, t;
|
||||
var path = Path;
|
||||
switch (cmd) {
|
||||
case 'L':
|
||||
return path.getLineLength(x, y, points[0], points[1]);
|
||||
case 'C':
|
||||
len = 0.0;
|
||||
p1 = path.getPointOnCubicBezier(0, x, y, points[0], points[1], points[2], points[3], points[4], points[5]);
|
||||
for (t = 0.01; t <= 1; t += 0.01) {
|
||||
p2 = path.getPointOnCubicBezier(t, x, y, points[0], points[1], points[2], points[3], points[4], points[5]);
|
||||
len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
|
||||
p1 = p2;
|
||||
}
|
||||
return len;
|
||||
case 'Q':
|
||||
len = 0.0;
|
||||
p1 = path.getPointOnQuadraticBezier(0, x, y, points[0], points[1], points[2], points[3]);
|
||||
for (t = 0.01; t <= 1; t += 0.01) {
|
||||
p2 = path.getPointOnQuadraticBezier(t, x, y, points[0], points[1], points[2], points[3]);
|
||||
len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
|
||||
p1 = p2;
|
||||
}
|
||||
return len;
|
||||
case 'A':
|
||||
len = 0.0;
|
||||
var start = points[4];
|
||||
var dTheta = points[5];
|
||||
var end = points[4] + dTheta;
|
||||
var inc = Math.PI / 180.0;
|
||||
if (Math.abs(start - end) < inc) {
|
||||
inc = Math.abs(start - end);
|
||||
}
|
||||
p1 = path.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], start, 0);
|
||||
if (dTheta < 0) {
|
||||
for (t = start - inc; t > end; t -= inc) {
|
||||
p2 = path.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], t, 0);
|
||||
len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
|
||||
p1 = p2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (t = start + inc; t < end; t += inc) {
|
||||
p2 = path.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], t, 0);
|
||||
len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
|
||||
p1 = p2;
|
||||
}
|
||||
}
|
||||
p2 = path.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], end, 0);
|
||||
len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
|
||||
return len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static convertEndpointToCenterParameterization(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg) {
|
||||
var psi = psiDeg * (Math.PI / 180.0);
|
||||
var xp = (Math.cos(psi) * (x1 - x2)) / 2.0 + (Math.sin(psi) * (y1 - y2)) / 2.0;
|
||||
var yp = (-1 * Math.sin(psi) * (x1 - x2)) / 2.0 +
|
||||
(Math.cos(psi) * (y1 - y2)) / 2.0;
|
||||
var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
|
||||
if (lambda > 1) {
|
||||
rx *= Math.sqrt(lambda);
|
||||
ry *= Math.sqrt(lambda);
|
||||
}
|
||||
var f = Math.sqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) /
|
||||
(rx * rx * (yp * yp) + ry * ry * (xp * xp)));
|
||||
if (fa === fs) {
|
||||
f *= -1;
|
||||
}
|
||||
if (isNaN(f)) {
|
||||
f = 0;
|
||||
}
|
||||
var cxp = (f * rx * yp) / ry;
|
||||
var cyp = (f * -ry * xp) / rx;
|
||||
var cx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp;
|
||||
var cy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp;
|
||||
var vMag = function (v) {
|
||||
return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
|
||||
};
|
||||
var vRatio = function (u, v) {
|
||||
return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
|
||||
};
|
||||
var vAngle = function (u, v) {
|
||||
return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
|
||||
};
|
||||
var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
|
||||
var u = [(xp - cxp) / rx, (yp - cyp) / ry];
|
||||
var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
|
||||
var dTheta = vAngle(u, v);
|
||||
if (vRatio(u, v) <= -1) {
|
||||
dTheta = Math.PI;
|
||||
}
|
||||
if (vRatio(u, v) >= 1) {
|
||||
dTheta = 0;
|
||||
}
|
||||
if (fs === 0 && dTheta > 0) {
|
||||
dTheta = dTheta - 2 * Math.PI;
|
||||
}
|
||||
if (fs === 1 && dTheta < 0) {
|
||||
dTheta = dTheta + 2 * Math.PI;
|
||||
}
|
||||
return [cx, cy, rx, ry, theta, dTheta, psi, fs];
|
||||
}
|
||||
}
|
||||
exports.Path = Path;
|
||||
Path.prototype.className = 'Path';
|
||||
Path.prototype._attrsAffectingSize = ['data'];
|
||||
(0, Global_1._registerNode)(Path);
|
||||
Factory_1.Factory.addGetterSetter(Path, 'data');
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user