konva 8.4.2 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -9
- package/konva.js +17669 -16968
- package/konva.min.js +3 -3
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +11 -7
- package/lib/BezierFunctions.d.ts +6 -0
- package/lib/BezierFunctions.js +791 -0
- package/lib/Canvas.d.ts +2 -1
- package/lib/Canvas.js +26 -18
- package/lib/Container.d.ts +4 -4
- package/lib/Container.js +16 -12
- package/lib/Context.d.ts +16 -13
- package/lib/Context.js +27 -19
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +7 -3
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +25 -22
- package/lib/Factory.js +27 -24
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +10 -6
- package/lib/Global.js +16 -12
- package/lib/Group.d.ts +3 -3
- package/lib/Group.js +10 -6
- package/lib/Layer.d.ts +9 -9
- package/lib/Layer.js +37 -33
- package/lib/Node.d.ts +8 -8
- package/lib/Node.js +95 -90
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +15 -7
- package/lib/Shape.d.ts +6 -4
- package/lib/Shape.js +90 -86
- package/lib/Stage.d.ts +7 -7
- package/lib/Stage.js +51 -47
- package/lib/Tween.d.ts +2 -2
- package/lib/Tween.js +26 -22
- package/lib/Util.d.ts +2 -2
- package/lib/Util.js +29 -25
- package/lib/Validators.js +58 -44
- package/lib/_CoreInternals.d.ts +29 -29
- package/lib/_CoreInternals.js +36 -33
- package/lib/_FullInternals.d.ts +67 -67
- package/lib/_FullInternals.js +78 -75
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +9 -5
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +9 -5
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +9 -5
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +14 -10
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +9 -5
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +5 -1
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +11 -7
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +11 -7
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +5 -1
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +13 -9
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +9 -5
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +9 -5
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +11 -7
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +9 -5
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +11 -7
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +12 -8
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +5 -1
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +5 -1
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +9 -5
- package/lib/index-node.d.ts +1 -1
- package/lib/index-node.js +7 -5
- package/lib/index-types.d.ts +124 -124
- package/lib/index.d.ts +1 -1
- package/lib/index.js +4 -2
- package/lib/shapes/Arc.d.ts +6 -5
- package/lib/shapes/Arc.js +17 -13
- package/lib/shapes/Arrow.d.ts +5 -4
- package/lib/shapes/Arrow.js +17 -13
- package/lib/shapes/Circle.d.ts +6 -5
- package/lib/shapes/Circle.js +11 -7
- package/lib/shapes/Ellipse.d.ts +6 -5
- package/lib/shapes/Ellipse.js +13 -9
- package/lib/shapes/Image.d.ts +5 -5
- package/lib/shapes/Image.js +21 -17
- package/lib/shapes/Label.d.ts +8 -7
- package/lib/shapes/Label.js +18 -13
- package/lib/shapes/Line.d.ts +3 -3
- package/lib/shapes/Line.js +14 -10
- package/lib/shapes/Path.d.ts +6 -3
- package/lib/shapes/Path.js +44 -43
- package/lib/shapes/Rect.d.ts +3 -3
- package/lib/shapes/Rect.js +13 -9
- package/lib/shapes/RegularPolygon.d.ts +6 -5
- package/lib/shapes/RegularPolygon.js +12 -8
- package/lib/shapes/Ring.d.ts +6 -5
- package/lib/shapes/Ring.js +12 -8
- package/lib/shapes/Sprite.d.ts +7 -6
- package/lib/shapes/Sprite.js +19 -15
- package/lib/shapes/Star.d.ts +6 -5
- package/lib/shapes/Star.js +13 -9
- package/lib/shapes/Text.d.ts +8 -7
- package/lib/shapes/Text.js +31 -26
- package/lib/shapes/TextPath.d.ts +12 -7
- package/lib/shapes/TextPath.js +82 -188
- package/lib/shapes/Transformer.d.ts +10 -10
- package/lib/shapes/Transformer.js +92 -81
- package/lib/shapes/Wedge.d.ts +6 -5
- package/lib/shapes/Wedge.js +16 -12
- package/lib/types.d.ts +6 -0
- package/lib/types.js +5 -2
- package/package.json +13 -42
- package/cmj/Animation.d.ts +0 -24
- package/cmj/Animation.js +0 -145
- package/cmj/Canvas.d.ts +0 -32
- package/cmj/Canvas.js +0 -114
- package/cmj/Container.d.ts +0 -47
- package/cmj/Container.js +0 -325
- package/cmj/Context.d.ts +0 -84
- package/cmj/Context.js +0 -538
- package/cmj/Core.d.ts +0 -3
- package/cmj/Core.js +0 -7
- package/cmj/DragAndDrop.d.ts +0 -17
- package/cmj/DragAndDrop.js +0 -111
- package/cmj/Factory.d.ts +0 -11
- package/cmj/Factory.js +0 -125
- package/cmj/FastLayer.d.ts +0 -4
- package/cmj/FastLayer.js +0 -16
- package/cmj/Global.d.ts +0 -34
- package/cmj/Global.js +0 -61
- package/cmj/Group.d.ts +0 -8
- package/cmj/Group.js +0 -17
- package/cmj/Layer.d.ts +0 -61
- package/cmj/Layer.js +0 -309
- package/cmj/Node.d.ts +0 -328
- package/cmj/Node.js +0 -1420
- package/cmj/PointerEvents.d.ts +0 -11
- package/cmj/PointerEvents.js +0 -45
- package/cmj/Shape.d.ts +0 -184
- package/cmj/Shape.js +0 -521
- package/cmj/Stage.d.ts +0 -85
- package/cmj/Stage.js +0 -692
- package/cmj/Tween.d.ts +0 -86
- package/cmj/Tween.js +0 -520
- package/cmj/Util.d.ts +0 -91
- package/cmj/Util.js +0 -801
- package/cmj/Validators.d.ts +0 -11
- package/cmj/Validators.js +0 -192
- package/cmj/_CoreInternals.d.ts +0 -152
- package/cmj/_CoreInternals.js +0 -37
- package/cmj/_FullInternals.d.ts +0 -196
- package/cmj/_FullInternals.js +0 -81
- package/cmj/filters/Blur.d.ts +0 -2
- package/cmj/filters/Blur.js +0 -701
- package/cmj/filters/Brighten.d.ts +0 -2
- package/cmj/filters/Brighten.js +0 -16
- package/cmj/filters/Contrast.d.ts +0 -2
- package/cmj/filters/Contrast.js +0 -38
- package/cmj/filters/Emboss.d.ts +0 -2
- package/cmj/filters/Emboss.js +0 -106
- package/cmj/filters/Enhance.d.ts +0 -2
- package/cmj/filters/Enhance.js +0 -87
- package/cmj/filters/Grayscale.d.ts +0 -2
- package/cmj/filters/Grayscale.js +0 -13
- package/cmj/filters/HSL.d.ts +0 -2
- package/cmj/filters/HSL.js +0 -28
- package/cmj/filters/HSV.d.ts +0 -2
- package/cmj/filters/HSV.js +0 -28
- package/cmj/filters/Invert.d.ts +0 -2
- package/cmj/filters/Invert.js +0 -12
- package/cmj/filters/Kaleidoscope.d.ts +0 -2
- package/cmj/filters/Kaleidoscope.js +0 -137
- package/cmj/filters/Mask.d.ts +0 -2
- package/cmj/filters/Mask.js +0 -144
- package/cmj/filters/Noise.d.ts +0 -2
- package/cmj/filters/Noise.js +0 -16
- package/cmj/filters/Pixelate.d.ts +0 -2
- package/cmj/filters/Pixelate.js +0 -64
- package/cmj/filters/Posterize.d.ts +0 -2
- package/cmj/filters/Posterize.js +0 -14
- package/cmj/filters/RGB.d.ts +0 -2
- package/cmj/filters/RGB.js +0 -43
- package/cmj/filters/RGBA.d.ts +0 -2
- package/cmj/filters/RGBA.js +0 -53
- package/cmj/filters/Sepia.d.ts +0 -2
- package/cmj/filters/Sepia.js +0 -15
- package/cmj/filters/Solarize.d.ts +0 -2
- package/cmj/filters/Solarize.js +0 -29
- package/cmj/filters/Threshold.d.ts +0 -2
- package/cmj/filters/Threshold.js +0 -14
- package/cmj/index-node.d.ts +0 -2
- package/cmj/index-node.js +0 -21
- package/cmj/index-types.d.ts +0 -181
- package/cmj/index.d.ts +0 -2
- package/cmj/index.js +0 -4
- package/cmj/package.json +0 -6
- package/cmj/shapes/Arc.d.ts +0 -25
- package/cmj/shapes/Arc.js +0 -59
- package/cmj/shapes/Arrow.d.ts +0 -25
- package/cmj/shapes/Arrow.js +0 -103
- package/cmj/shapes/Circle.d.ts +0 -13
- package/cmj/shapes/Circle.js +0 -37
- package/cmj/shapes/Ellipse.d.ts +0 -16
- package/cmj/shapes/Ellipse.js +0 -41
- package/cmj/shapes/Image.d.ts +0 -25
- package/cmj/shapes/Image.js +0 -117
- package/cmj/shapes/Label.d.ts +0 -35
- package/cmj/shapes/Label.js +0 -178
- package/cmj/shapes/Line.d.ts +0 -28
- package/cmj/shapes/Line.js +0 -159
- package/cmj/shapes/Path.d.ts +0 -37
- package/cmj/shapes/Path.js +0 -631
- package/cmj/shapes/Rect.d.ts +0 -10
- package/cmj/shapes/Rect.js +0 -26
- package/cmj/shapes/RegularPolygon.d.ts +0 -22
- package/cmj/shapes/RegularPolygon.js +0 -69
- package/cmj/shapes/Ring.d.ts +0 -15
- package/cmj/shapes/Ring.js +0 -37
- package/cmj/shapes/Sprite.d.ts +0 -30
- package/cmj/shapes/Sprite.js +0 -112
- package/cmj/shapes/Star.d.ts +0 -17
- package/cmj/shapes/Star.js +0 -42
- package/cmj/shapes/Text.d.ts +0 -62
- package/cmj/shapes/Text.js +0 -373
- package/cmj/shapes/TextPath.d.ts +0 -55
- package/cmj/shapes/TextPath.js +0 -351
- package/cmj/shapes/Transformer.d.ts +0 -116
- package/cmj/shapes/Transformer.js +0 -964
- package/cmj/shapes/Wedge.d.ts +0 -17
- package/cmj/shapes/Wedge.js +0 -42
- package/cmj/types.d.ts +0 -50
- package/cmj/types.js +0 -25
package/cmj/Node.js
DELETED
|
@@ -1,1420 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Node = void 0;
|
|
4
|
-
const Util_1 = require("./Util");
|
|
5
|
-
const Factory_1 = require("./Factory");
|
|
6
|
-
const Canvas_1 = require("./Canvas");
|
|
7
|
-
const Global_1 = require("./Global");
|
|
8
|
-
const DragAndDrop_1 = require("./DragAndDrop");
|
|
9
|
-
const Validators_1 = require("./Validators");
|
|
10
|
-
var ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', NAME = 'name', SET = 'set', SHAPE = 'Shape', SPACE = ' ', STAGE = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR = [
|
|
11
|
-
'xChange.konva',
|
|
12
|
-
'yChange.konva',
|
|
13
|
-
'scaleXChange.konva',
|
|
14
|
-
'scaleYChange.konva',
|
|
15
|
-
'skewXChange.konva',
|
|
16
|
-
'skewYChange.konva',
|
|
17
|
-
'rotationChange.konva',
|
|
18
|
-
'offsetXChange.konva',
|
|
19
|
-
'offsetYChange.konva',
|
|
20
|
-
'transformsEnabledChange.konva',
|
|
21
|
-
].join(SPACE);
|
|
22
|
-
let idCounter = 1;
|
|
23
|
-
class Node {
|
|
24
|
-
constructor(config) {
|
|
25
|
-
this._id = idCounter++;
|
|
26
|
-
this.eventListeners = {};
|
|
27
|
-
this.attrs = {};
|
|
28
|
-
this.index = 0;
|
|
29
|
-
this._allEventListeners = null;
|
|
30
|
-
this.parent = null;
|
|
31
|
-
this._cache = new Map();
|
|
32
|
-
this._attachedDepsListeners = new Map();
|
|
33
|
-
this._lastPos = null;
|
|
34
|
-
this._batchingTransformChange = false;
|
|
35
|
-
this._needClearTransformCache = false;
|
|
36
|
-
this._filterUpToDate = false;
|
|
37
|
-
this._isUnderCache = false;
|
|
38
|
-
this._dragEventId = null;
|
|
39
|
-
this._shouldFireChangeEvents = false;
|
|
40
|
-
this.setAttrs(config);
|
|
41
|
-
this._shouldFireChangeEvents = true;
|
|
42
|
-
}
|
|
43
|
-
hasChildren() {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
_clearCache(attr) {
|
|
47
|
-
if ((attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM) &&
|
|
48
|
-
this._cache.get(attr)) {
|
|
49
|
-
this._cache.get(attr).dirty = true;
|
|
50
|
-
}
|
|
51
|
-
else if (attr) {
|
|
52
|
-
this._cache.delete(attr);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
this._cache.clear();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
_getCache(attr, privateGetter) {
|
|
59
|
-
var cache = this._cache.get(attr);
|
|
60
|
-
var isTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM;
|
|
61
|
-
var invalid = cache === undefined || (isTransform && cache.dirty === true);
|
|
62
|
-
if (invalid) {
|
|
63
|
-
cache = privateGetter.call(this);
|
|
64
|
-
this._cache.set(attr, cache);
|
|
65
|
-
}
|
|
66
|
-
return cache;
|
|
67
|
-
}
|
|
68
|
-
_calculate(name, deps, getter) {
|
|
69
|
-
if (!this._attachedDepsListeners.get(name)) {
|
|
70
|
-
const depsString = deps.map((dep) => dep + 'Change.konva').join(SPACE);
|
|
71
|
-
this.on(depsString, () => {
|
|
72
|
-
this._clearCache(name);
|
|
73
|
-
});
|
|
74
|
-
this._attachedDepsListeners.set(name, true);
|
|
75
|
-
}
|
|
76
|
-
return this._getCache(name, getter);
|
|
77
|
-
}
|
|
78
|
-
_getCanvasCache() {
|
|
79
|
-
return this._cache.get(CANVAS);
|
|
80
|
-
}
|
|
81
|
-
_clearSelfAndDescendantCache(attr) {
|
|
82
|
-
this._clearCache(attr);
|
|
83
|
-
if (attr === ABSOLUTE_TRANSFORM) {
|
|
84
|
-
this.fire('absoluteTransformChange');
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
clearCache() {
|
|
88
|
-
if (this._cache.has(CANVAS)) {
|
|
89
|
-
const { scene, filter, hit } = this._cache.get(CANVAS);
|
|
90
|
-
Util_1.Util.releaseCanvas(scene, filter, hit);
|
|
91
|
-
this._cache.delete(CANVAS);
|
|
92
|
-
}
|
|
93
|
-
this._clearSelfAndDescendantCache();
|
|
94
|
-
this._requestDraw();
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
cache(config) {
|
|
98
|
-
var conf = config || {};
|
|
99
|
-
var rect = {};
|
|
100
|
-
if (conf.x === undefined ||
|
|
101
|
-
conf.y === undefined ||
|
|
102
|
-
conf.width === undefined ||
|
|
103
|
-
conf.height === undefined) {
|
|
104
|
-
rect = this.getClientRect({
|
|
105
|
-
skipTransform: true,
|
|
106
|
-
relativeTo: this.getParent(),
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
var width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? Math.floor(rect.x) : conf.x, y = conf.y === undefined ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
|
|
110
|
-
if (!width || !height) {
|
|
111
|
-
Util_1.Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
width += offset * 2 + 1;
|
|
115
|
-
height += offset * 2 + 1;
|
|
116
|
-
x -= offset;
|
|
117
|
-
y -= offset;
|
|
118
|
-
var cachedSceneCanvas = new Canvas_1.SceneCanvas({
|
|
119
|
-
pixelRatio: pixelRatio,
|
|
120
|
-
width: width,
|
|
121
|
-
height: height,
|
|
122
|
-
}), cachedFilterCanvas = new Canvas_1.SceneCanvas({
|
|
123
|
-
pixelRatio: pixelRatio,
|
|
124
|
-
width: 0,
|
|
125
|
-
height: 0,
|
|
126
|
-
}), cachedHitCanvas = new Canvas_1.HitCanvas({
|
|
127
|
-
pixelRatio: hitCanvasPixelRatio,
|
|
128
|
-
width: width,
|
|
129
|
-
height: height,
|
|
130
|
-
}), sceneContext = cachedSceneCanvas.getContext(), hitContext = cachedHitCanvas.getContext();
|
|
131
|
-
cachedHitCanvas.isCache = true;
|
|
132
|
-
cachedSceneCanvas.isCache = true;
|
|
133
|
-
this._cache.delete(CANVAS);
|
|
134
|
-
this._filterUpToDate = false;
|
|
135
|
-
if (conf.imageSmoothingEnabled === false) {
|
|
136
|
-
cachedSceneCanvas.getContext()._context.imageSmoothingEnabled = false;
|
|
137
|
-
cachedFilterCanvas.getContext()._context.imageSmoothingEnabled = false;
|
|
138
|
-
}
|
|
139
|
-
sceneContext.save();
|
|
140
|
-
hitContext.save();
|
|
141
|
-
sceneContext.translate(-x, -y);
|
|
142
|
-
hitContext.translate(-x, -y);
|
|
143
|
-
this._isUnderCache = true;
|
|
144
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
|
145
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_SCALE);
|
|
146
|
-
this.drawScene(cachedSceneCanvas, this);
|
|
147
|
-
this.drawHit(cachedHitCanvas, this);
|
|
148
|
-
this._isUnderCache = false;
|
|
149
|
-
sceneContext.restore();
|
|
150
|
-
hitContext.restore();
|
|
151
|
-
if (drawBorder) {
|
|
152
|
-
sceneContext.save();
|
|
153
|
-
sceneContext.beginPath();
|
|
154
|
-
sceneContext.rect(0, 0, width, height);
|
|
155
|
-
sceneContext.closePath();
|
|
156
|
-
sceneContext.setAttr('strokeStyle', 'red');
|
|
157
|
-
sceneContext.setAttr('lineWidth', 5);
|
|
158
|
-
sceneContext.stroke();
|
|
159
|
-
sceneContext.restore();
|
|
160
|
-
}
|
|
161
|
-
this._cache.set(CANVAS, {
|
|
162
|
-
scene: cachedSceneCanvas,
|
|
163
|
-
filter: cachedFilterCanvas,
|
|
164
|
-
hit: cachedHitCanvas,
|
|
165
|
-
x: x,
|
|
166
|
-
y: y,
|
|
167
|
-
});
|
|
168
|
-
this._requestDraw();
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
isCached() {
|
|
172
|
-
return this._cache.has(CANVAS);
|
|
173
|
-
}
|
|
174
|
-
getClientRect(config) {
|
|
175
|
-
throw new Error('abstract "getClientRect" method call');
|
|
176
|
-
}
|
|
177
|
-
_transformedRect(rect, top) {
|
|
178
|
-
var points = [
|
|
179
|
-
{ x: rect.x, y: rect.y },
|
|
180
|
-
{ x: rect.x + rect.width, y: rect.y },
|
|
181
|
-
{ x: rect.x + rect.width, y: rect.y + rect.height },
|
|
182
|
-
{ x: rect.x, y: rect.y + rect.height },
|
|
183
|
-
];
|
|
184
|
-
var minX, minY, maxX, maxY;
|
|
185
|
-
var trans = this.getAbsoluteTransform(top);
|
|
186
|
-
points.forEach(function (point) {
|
|
187
|
-
var transformed = trans.point(point);
|
|
188
|
-
if (minX === undefined) {
|
|
189
|
-
minX = maxX = transformed.x;
|
|
190
|
-
minY = maxY = transformed.y;
|
|
191
|
-
}
|
|
192
|
-
minX = Math.min(minX, transformed.x);
|
|
193
|
-
minY = Math.min(minY, transformed.y);
|
|
194
|
-
maxX = Math.max(maxX, transformed.x);
|
|
195
|
-
maxY = Math.max(maxY, transformed.y);
|
|
196
|
-
});
|
|
197
|
-
return {
|
|
198
|
-
x: minX,
|
|
199
|
-
y: minY,
|
|
200
|
-
width: maxX - minX,
|
|
201
|
-
height: maxY - minY,
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
_drawCachedSceneCanvas(context) {
|
|
205
|
-
context.save();
|
|
206
|
-
context._applyOpacity(this);
|
|
207
|
-
context._applyGlobalCompositeOperation(this);
|
|
208
|
-
const canvasCache = this._getCanvasCache();
|
|
209
|
-
context.translate(canvasCache.x, canvasCache.y);
|
|
210
|
-
var cacheCanvas = this._getCachedSceneCanvas();
|
|
211
|
-
var ratio = cacheCanvas.pixelRatio;
|
|
212
|
-
context.drawImage(cacheCanvas._canvas, 0, 0, cacheCanvas.width / ratio, cacheCanvas.height / ratio);
|
|
213
|
-
context.restore();
|
|
214
|
-
}
|
|
215
|
-
_drawCachedHitCanvas(context) {
|
|
216
|
-
var canvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit;
|
|
217
|
-
context.save();
|
|
218
|
-
context.translate(canvasCache.x, canvasCache.y);
|
|
219
|
-
context.drawImage(hitCanvas._canvas, 0, 0, hitCanvas.width / hitCanvas.pixelRatio, hitCanvas.height / hitCanvas.pixelRatio);
|
|
220
|
-
context.restore();
|
|
221
|
-
}
|
|
222
|
-
_getCachedSceneCanvas() {
|
|
223
|
-
var filters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter;
|
|
224
|
-
if (filters) {
|
|
225
|
-
if (!this._filterUpToDate) {
|
|
226
|
-
var ratio = sceneCanvas.pixelRatio;
|
|
227
|
-
filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio);
|
|
228
|
-
try {
|
|
229
|
-
len = filters.length;
|
|
230
|
-
filterContext.clear();
|
|
231
|
-
filterContext.drawImage(sceneCanvas._canvas, 0, 0, sceneCanvas.getWidth() / ratio, sceneCanvas.getHeight() / ratio);
|
|
232
|
-
imageData = filterContext.getImageData(0, 0, filterCanvas.getWidth(), filterCanvas.getHeight());
|
|
233
|
-
for (n = 0; n < len; n++) {
|
|
234
|
-
filter = filters[n];
|
|
235
|
-
if (typeof filter !== 'function') {
|
|
236
|
-
Util_1.Util.error('Filter should be type of function, but got ' +
|
|
237
|
-
typeof filter +
|
|
238
|
-
' instead. Please check correct filters');
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
filter.call(this, imageData);
|
|
242
|
-
filterContext.putImageData(imageData, 0, 0);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
catch (e) {
|
|
246
|
-
Util_1.Util.error('Unable to apply filter. ' +
|
|
247
|
-
e.message +
|
|
248
|
-
' This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.');
|
|
249
|
-
}
|
|
250
|
-
this._filterUpToDate = true;
|
|
251
|
-
}
|
|
252
|
-
return filterCanvas;
|
|
253
|
-
}
|
|
254
|
-
return sceneCanvas;
|
|
255
|
-
}
|
|
256
|
-
on(evtStr, handler) {
|
|
257
|
-
this._cache && this._cache.delete(ALL_LISTENERS);
|
|
258
|
-
if (arguments.length === 3) {
|
|
259
|
-
return this._delegate.apply(this, arguments);
|
|
260
|
-
}
|
|
261
|
-
var events = evtStr.split(SPACE), len = events.length, n, event, parts, baseEvent, name;
|
|
262
|
-
for (n = 0; n < len; n++) {
|
|
263
|
-
event = events[n];
|
|
264
|
-
parts = event.split('.');
|
|
265
|
-
baseEvent = parts[0];
|
|
266
|
-
name = parts[1] || '';
|
|
267
|
-
if (!this.eventListeners[baseEvent]) {
|
|
268
|
-
this.eventListeners[baseEvent] = [];
|
|
269
|
-
}
|
|
270
|
-
this.eventListeners[baseEvent].push({
|
|
271
|
-
name: name,
|
|
272
|
-
handler: handler,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
return this;
|
|
276
|
-
}
|
|
277
|
-
off(evtStr, callback) {
|
|
278
|
-
var events = (evtStr || '').split(SPACE), len = events.length, n, t, event, parts, baseEvent, name;
|
|
279
|
-
this._cache && this._cache.delete(ALL_LISTENERS);
|
|
280
|
-
if (!evtStr) {
|
|
281
|
-
for (t in this.eventListeners) {
|
|
282
|
-
this._off(t);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
for (n = 0; n < len; n++) {
|
|
286
|
-
event = events[n];
|
|
287
|
-
parts = event.split('.');
|
|
288
|
-
baseEvent = parts[0];
|
|
289
|
-
name = parts[1];
|
|
290
|
-
if (baseEvent) {
|
|
291
|
-
if (this.eventListeners[baseEvent]) {
|
|
292
|
-
this._off(baseEvent, name, callback);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
for (t in this.eventListeners) {
|
|
297
|
-
this._off(t, name, callback);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return this;
|
|
302
|
-
}
|
|
303
|
-
dispatchEvent(evt) {
|
|
304
|
-
var e = {
|
|
305
|
-
target: this,
|
|
306
|
-
type: evt.type,
|
|
307
|
-
evt: evt,
|
|
308
|
-
};
|
|
309
|
-
this.fire(evt.type, e);
|
|
310
|
-
return this;
|
|
311
|
-
}
|
|
312
|
-
addEventListener(type, handler) {
|
|
313
|
-
this.on(type, function (evt) {
|
|
314
|
-
handler.call(this, evt.evt);
|
|
315
|
-
});
|
|
316
|
-
return this;
|
|
317
|
-
}
|
|
318
|
-
removeEventListener(type) {
|
|
319
|
-
this.off(type);
|
|
320
|
-
return this;
|
|
321
|
-
}
|
|
322
|
-
_delegate(event, selector, handler) {
|
|
323
|
-
var stopNode = this;
|
|
324
|
-
this.on(event, function (evt) {
|
|
325
|
-
var targets = evt.target.findAncestors(selector, true, stopNode);
|
|
326
|
-
for (var i = 0; i < targets.length; i++) {
|
|
327
|
-
evt = Util_1.Util.cloneObject(evt);
|
|
328
|
-
evt.currentTarget = targets[i];
|
|
329
|
-
handler.call(targets[i], evt);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
remove() {
|
|
334
|
-
if (this.isDragging()) {
|
|
335
|
-
this.stopDrag();
|
|
336
|
-
}
|
|
337
|
-
DragAndDrop_1.DD._dragElements.delete(this._id);
|
|
338
|
-
this._remove();
|
|
339
|
-
return this;
|
|
340
|
-
}
|
|
341
|
-
_clearCaches() {
|
|
342
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
343
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
|
344
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_SCALE);
|
|
345
|
-
this._clearSelfAndDescendantCache(STAGE);
|
|
346
|
-
this._clearSelfAndDescendantCache(VISIBLE);
|
|
347
|
-
this._clearSelfAndDescendantCache(LISTENING);
|
|
348
|
-
}
|
|
349
|
-
_remove() {
|
|
350
|
-
this._clearCaches();
|
|
351
|
-
var parent = this.getParent();
|
|
352
|
-
if (parent && parent.children) {
|
|
353
|
-
parent.children.splice(this.index, 1);
|
|
354
|
-
parent._setChildrenIndices();
|
|
355
|
-
this.parent = null;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
destroy() {
|
|
359
|
-
this.remove();
|
|
360
|
-
this.clearCache();
|
|
361
|
-
return this;
|
|
362
|
-
}
|
|
363
|
-
getAttr(attr) {
|
|
364
|
-
var method = 'get' + Util_1.Util._capitalize(attr);
|
|
365
|
-
if (Util_1.Util._isFunction(this[method])) {
|
|
366
|
-
return this[method]();
|
|
367
|
-
}
|
|
368
|
-
return this.attrs[attr];
|
|
369
|
-
}
|
|
370
|
-
getAncestors() {
|
|
371
|
-
var parent = this.getParent(), ancestors = [];
|
|
372
|
-
while (parent) {
|
|
373
|
-
ancestors.push(parent);
|
|
374
|
-
parent = parent.getParent();
|
|
375
|
-
}
|
|
376
|
-
return ancestors;
|
|
377
|
-
}
|
|
378
|
-
getAttrs() {
|
|
379
|
-
return this.attrs || {};
|
|
380
|
-
}
|
|
381
|
-
setAttrs(config) {
|
|
382
|
-
this._batchTransformChanges(() => {
|
|
383
|
-
var key, method;
|
|
384
|
-
if (!config) {
|
|
385
|
-
return this;
|
|
386
|
-
}
|
|
387
|
-
for (key in config) {
|
|
388
|
-
if (key === CHILDREN) {
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
method = SET + Util_1.Util._capitalize(key);
|
|
392
|
-
if (Util_1.Util._isFunction(this[method])) {
|
|
393
|
-
this[method](config[key]);
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
this._setAttr(key, config[key]);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
return this;
|
|
401
|
-
}
|
|
402
|
-
isListening() {
|
|
403
|
-
return this._getCache(LISTENING, this._isListening);
|
|
404
|
-
}
|
|
405
|
-
_isListening(relativeTo) {
|
|
406
|
-
const listening = this.listening();
|
|
407
|
-
if (!listening) {
|
|
408
|
-
return false;
|
|
409
|
-
}
|
|
410
|
-
const parent = this.getParent();
|
|
411
|
-
if (parent && parent !== relativeTo && this !== relativeTo) {
|
|
412
|
-
return parent._isListening(relativeTo);
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
return true;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
isVisible() {
|
|
419
|
-
return this._getCache(VISIBLE, this._isVisible);
|
|
420
|
-
}
|
|
421
|
-
_isVisible(relativeTo) {
|
|
422
|
-
const visible = this.visible();
|
|
423
|
-
if (!visible) {
|
|
424
|
-
return false;
|
|
425
|
-
}
|
|
426
|
-
const parent = this.getParent();
|
|
427
|
-
if (parent && parent !== relativeTo && this !== relativeTo) {
|
|
428
|
-
return parent._isVisible(relativeTo);
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
return true;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
shouldDrawHit(top, skipDragCheck = false) {
|
|
435
|
-
if (top) {
|
|
436
|
-
return this._isVisible(top) && this._isListening(top);
|
|
437
|
-
}
|
|
438
|
-
var layer = this.getLayer();
|
|
439
|
-
var layerUnderDrag = false;
|
|
440
|
-
DragAndDrop_1.DD._dragElements.forEach((elem) => {
|
|
441
|
-
if (elem.dragStatus !== 'dragging') {
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
else if (elem.node.nodeType === 'Stage') {
|
|
445
|
-
layerUnderDrag = true;
|
|
446
|
-
}
|
|
447
|
-
else if (elem.node.getLayer() === layer) {
|
|
448
|
-
layerUnderDrag = true;
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
var dragSkip = !skipDragCheck && !Global_1.Konva.hitOnDragEnabled && layerUnderDrag;
|
|
452
|
-
return this.isListening() && this.isVisible() && !dragSkip;
|
|
453
|
-
}
|
|
454
|
-
show() {
|
|
455
|
-
this.visible(true);
|
|
456
|
-
return this;
|
|
457
|
-
}
|
|
458
|
-
hide() {
|
|
459
|
-
this.visible(false);
|
|
460
|
-
return this;
|
|
461
|
-
}
|
|
462
|
-
getZIndex() {
|
|
463
|
-
return this.index || 0;
|
|
464
|
-
}
|
|
465
|
-
getAbsoluteZIndex() {
|
|
466
|
-
var depth = this.getDepth(), that = this, index = 0, nodes, len, n, child;
|
|
467
|
-
function addChildren(children) {
|
|
468
|
-
nodes = [];
|
|
469
|
-
len = children.length;
|
|
470
|
-
for (n = 0; n < len; n++) {
|
|
471
|
-
child = children[n];
|
|
472
|
-
index++;
|
|
473
|
-
if (child.nodeType !== SHAPE) {
|
|
474
|
-
nodes = nodes.concat(child.getChildren().slice());
|
|
475
|
-
}
|
|
476
|
-
if (child._id === that._id) {
|
|
477
|
-
n = len;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
if (nodes.length > 0 && nodes[0].getDepth() <= depth) {
|
|
481
|
-
addChildren(nodes);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
if (that.nodeType !== UPPER_STAGE) {
|
|
485
|
-
addChildren(that.getStage().getChildren());
|
|
486
|
-
}
|
|
487
|
-
return index;
|
|
488
|
-
}
|
|
489
|
-
getDepth() {
|
|
490
|
-
var depth = 0, parent = this.parent;
|
|
491
|
-
while (parent) {
|
|
492
|
-
depth++;
|
|
493
|
-
parent = parent.parent;
|
|
494
|
-
}
|
|
495
|
-
return depth;
|
|
496
|
-
}
|
|
497
|
-
_batchTransformChanges(func) {
|
|
498
|
-
this._batchingTransformChange = true;
|
|
499
|
-
func();
|
|
500
|
-
this._batchingTransformChange = false;
|
|
501
|
-
if (this._needClearTransformCache) {
|
|
502
|
-
this._clearCache(TRANSFORM);
|
|
503
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
504
|
-
}
|
|
505
|
-
this._needClearTransformCache = false;
|
|
506
|
-
}
|
|
507
|
-
setPosition(pos) {
|
|
508
|
-
this._batchTransformChanges(() => {
|
|
509
|
-
this.x(pos.x);
|
|
510
|
-
this.y(pos.y);
|
|
511
|
-
});
|
|
512
|
-
return this;
|
|
513
|
-
}
|
|
514
|
-
getPosition() {
|
|
515
|
-
return {
|
|
516
|
-
x: this.x(),
|
|
517
|
-
y: this.y(),
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
getRelativePointerPosition() {
|
|
521
|
-
if (!this.getStage()) {
|
|
522
|
-
return null;
|
|
523
|
-
}
|
|
524
|
-
var pos = this.getStage().getPointerPosition();
|
|
525
|
-
if (!pos) {
|
|
526
|
-
return null;
|
|
527
|
-
}
|
|
528
|
-
var transform = this.getAbsoluteTransform().copy();
|
|
529
|
-
transform.invert();
|
|
530
|
-
return transform.point(pos);
|
|
531
|
-
}
|
|
532
|
-
getAbsolutePosition(top) {
|
|
533
|
-
let haveCachedParent = false;
|
|
534
|
-
let parent = this.parent;
|
|
535
|
-
while (parent) {
|
|
536
|
-
if (parent.isCached()) {
|
|
537
|
-
haveCachedParent = true;
|
|
538
|
-
break;
|
|
539
|
-
}
|
|
540
|
-
parent = parent.parent;
|
|
541
|
-
}
|
|
542
|
-
if (haveCachedParent && !top) {
|
|
543
|
-
top = true;
|
|
544
|
-
}
|
|
545
|
-
var absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Util_1.Transform(), offset = this.offset();
|
|
546
|
-
absoluteTransform.m = absoluteMatrix.slice();
|
|
547
|
-
absoluteTransform.translate(offset.x, offset.y);
|
|
548
|
-
return absoluteTransform.getTranslation();
|
|
549
|
-
}
|
|
550
|
-
setAbsolutePosition(pos) {
|
|
551
|
-
var origTrans = this._clearTransform();
|
|
552
|
-
this.attrs.x = origTrans.x;
|
|
553
|
-
this.attrs.y = origTrans.y;
|
|
554
|
-
delete origTrans.x;
|
|
555
|
-
delete origTrans.y;
|
|
556
|
-
this._clearCache(TRANSFORM);
|
|
557
|
-
var it = this._getAbsoluteTransform().copy();
|
|
558
|
-
it.invert();
|
|
559
|
-
it.translate(pos.x, pos.y);
|
|
560
|
-
pos = {
|
|
561
|
-
x: this.attrs.x + it.getTranslation().x,
|
|
562
|
-
y: this.attrs.y + it.getTranslation().y,
|
|
563
|
-
};
|
|
564
|
-
this._setTransform(origTrans);
|
|
565
|
-
this.setPosition({ x: pos.x, y: pos.y });
|
|
566
|
-
this._clearCache(TRANSFORM);
|
|
567
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
568
|
-
return this;
|
|
569
|
-
}
|
|
570
|
-
_setTransform(trans) {
|
|
571
|
-
var key;
|
|
572
|
-
for (key in trans) {
|
|
573
|
-
this.attrs[key] = trans[key];
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
_clearTransform() {
|
|
577
|
-
var trans = {
|
|
578
|
-
x: this.x(),
|
|
579
|
-
y: this.y(),
|
|
580
|
-
rotation: this.rotation(),
|
|
581
|
-
scaleX: this.scaleX(),
|
|
582
|
-
scaleY: this.scaleY(),
|
|
583
|
-
offsetX: this.offsetX(),
|
|
584
|
-
offsetY: this.offsetY(),
|
|
585
|
-
skewX: this.skewX(),
|
|
586
|
-
skewY: this.skewY(),
|
|
587
|
-
};
|
|
588
|
-
this.attrs.x = 0;
|
|
589
|
-
this.attrs.y = 0;
|
|
590
|
-
this.attrs.rotation = 0;
|
|
591
|
-
this.attrs.scaleX = 1;
|
|
592
|
-
this.attrs.scaleY = 1;
|
|
593
|
-
this.attrs.offsetX = 0;
|
|
594
|
-
this.attrs.offsetY = 0;
|
|
595
|
-
this.attrs.skewX = 0;
|
|
596
|
-
this.attrs.skewY = 0;
|
|
597
|
-
return trans;
|
|
598
|
-
}
|
|
599
|
-
move(change) {
|
|
600
|
-
var changeX = change.x, changeY = change.y, x = this.x(), y = this.y();
|
|
601
|
-
if (changeX !== undefined) {
|
|
602
|
-
x += changeX;
|
|
603
|
-
}
|
|
604
|
-
if (changeY !== undefined) {
|
|
605
|
-
y += changeY;
|
|
606
|
-
}
|
|
607
|
-
this.setPosition({ x: x, y: y });
|
|
608
|
-
return this;
|
|
609
|
-
}
|
|
610
|
-
_eachAncestorReverse(func, top) {
|
|
611
|
-
var family = [], parent = this.getParent(), len, n;
|
|
612
|
-
if (top && top._id === this._id) {
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
family.unshift(this);
|
|
616
|
-
while (parent && (!top || parent._id !== top._id)) {
|
|
617
|
-
family.unshift(parent);
|
|
618
|
-
parent = parent.parent;
|
|
619
|
-
}
|
|
620
|
-
len = family.length;
|
|
621
|
-
for (n = 0; n < len; n++) {
|
|
622
|
-
func(family[n]);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
rotate(theta) {
|
|
626
|
-
this.rotation(this.rotation() + theta);
|
|
627
|
-
return this;
|
|
628
|
-
}
|
|
629
|
-
moveToTop() {
|
|
630
|
-
if (!this.parent) {
|
|
631
|
-
Util_1.Util.warn('Node has no parent. moveToTop function is ignored.');
|
|
632
|
-
return false;
|
|
633
|
-
}
|
|
634
|
-
var index = this.index, len = this.parent.getChildren().length;
|
|
635
|
-
if (index < len - 1) {
|
|
636
|
-
this.parent.children.splice(index, 1);
|
|
637
|
-
this.parent.children.push(this);
|
|
638
|
-
this.parent._setChildrenIndices();
|
|
639
|
-
return true;
|
|
640
|
-
}
|
|
641
|
-
return false;
|
|
642
|
-
}
|
|
643
|
-
moveUp() {
|
|
644
|
-
if (!this.parent) {
|
|
645
|
-
Util_1.Util.warn('Node has no parent. moveUp function is ignored.');
|
|
646
|
-
return false;
|
|
647
|
-
}
|
|
648
|
-
var index = this.index, len = this.parent.getChildren().length;
|
|
649
|
-
if (index < len - 1) {
|
|
650
|
-
this.parent.children.splice(index, 1);
|
|
651
|
-
this.parent.children.splice(index + 1, 0, this);
|
|
652
|
-
this.parent._setChildrenIndices();
|
|
653
|
-
return true;
|
|
654
|
-
}
|
|
655
|
-
return false;
|
|
656
|
-
}
|
|
657
|
-
moveDown() {
|
|
658
|
-
if (!this.parent) {
|
|
659
|
-
Util_1.Util.warn('Node has no parent. moveDown function is ignored.');
|
|
660
|
-
return false;
|
|
661
|
-
}
|
|
662
|
-
var index = this.index;
|
|
663
|
-
if (index > 0) {
|
|
664
|
-
this.parent.children.splice(index, 1);
|
|
665
|
-
this.parent.children.splice(index - 1, 0, this);
|
|
666
|
-
this.parent._setChildrenIndices();
|
|
667
|
-
return true;
|
|
668
|
-
}
|
|
669
|
-
return false;
|
|
670
|
-
}
|
|
671
|
-
moveToBottom() {
|
|
672
|
-
if (!this.parent) {
|
|
673
|
-
Util_1.Util.warn('Node has no parent. moveToBottom function is ignored.');
|
|
674
|
-
return false;
|
|
675
|
-
}
|
|
676
|
-
var index = this.index;
|
|
677
|
-
if (index > 0) {
|
|
678
|
-
this.parent.children.splice(index, 1);
|
|
679
|
-
this.parent.children.unshift(this);
|
|
680
|
-
this.parent._setChildrenIndices();
|
|
681
|
-
return true;
|
|
682
|
-
}
|
|
683
|
-
return false;
|
|
684
|
-
}
|
|
685
|
-
setZIndex(zIndex) {
|
|
686
|
-
if (!this.parent) {
|
|
687
|
-
Util_1.Util.warn('Node has no parent. zIndex parameter is ignored.');
|
|
688
|
-
return this;
|
|
689
|
-
}
|
|
690
|
-
if (zIndex < 0 || zIndex >= this.parent.children.length) {
|
|
691
|
-
Util_1.Util.warn('Unexpected value ' +
|
|
692
|
-
zIndex +
|
|
693
|
-
' for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to ' +
|
|
694
|
-
(this.parent.children.length - 1) +
|
|
695
|
-
'.');
|
|
696
|
-
}
|
|
697
|
-
var index = this.index;
|
|
698
|
-
this.parent.children.splice(index, 1);
|
|
699
|
-
this.parent.children.splice(zIndex, 0, this);
|
|
700
|
-
this.parent._setChildrenIndices();
|
|
701
|
-
return this;
|
|
702
|
-
}
|
|
703
|
-
getAbsoluteOpacity() {
|
|
704
|
-
return this._getCache(ABSOLUTE_OPACITY, this._getAbsoluteOpacity);
|
|
705
|
-
}
|
|
706
|
-
_getAbsoluteOpacity() {
|
|
707
|
-
var absOpacity = this.opacity();
|
|
708
|
-
var parent = this.getParent();
|
|
709
|
-
if (parent && !parent._isUnderCache) {
|
|
710
|
-
absOpacity *= parent.getAbsoluteOpacity();
|
|
711
|
-
}
|
|
712
|
-
return absOpacity;
|
|
713
|
-
}
|
|
714
|
-
moveTo(newContainer) {
|
|
715
|
-
if (this.getParent() !== newContainer) {
|
|
716
|
-
this._remove();
|
|
717
|
-
newContainer.add(this);
|
|
718
|
-
}
|
|
719
|
-
return this;
|
|
720
|
-
}
|
|
721
|
-
toObject() {
|
|
722
|
-
var obj = {}, attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;
|
|
723
|
-
obj.attrs = {};
|
|
724
|
-
for (key in attrs) {
|
|
725
|
-
val = attrs[key];
|
|
726
|
-
nonPlainObject =
|
|
727
|
-
Util_1.Util.isObject(val) && !Util_1.Util._isPlainObject(val) && !Util_1.Util._isArray(val);
|
|
728
|
-
if (nonPlainObject) {
|
|
729
|
-
continue;
|
|
730
|
-
}
|
|
731
|
-
getter = typeof this[key] === 'function' && this[key];
|
|
732
|
-
delete attrs[key];
|
|
733
|
-
defaultValue = getter ? getter.call(this) : null;
|
|
734
|
-
attrs[key] = val;
|
|
735
|
-
if (defaultValue !== val) {
|
|
736
|
-
obj.attrs[key] = val;
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
obj.className = this.getClassName();
|
|
740
|
-
return Util_1.Util._prepareToStringify(obj);
|
|
741
|
-
}
|
|
742
|
-
toJSON() {
|
|
743
|
-
return JSON.stringify(this.toObject());
|
|
744
|
-
}
|
|
745
|
-
getParent() {
|
|
746
|
-
return this.parent;
|
|
747
|
-
}
|
|
748
|
-
findAncestors(selector, includeSelf, stopNode) {
|
|
749
|
-
var res = [];
|
|
750
|
-
if (includeSelf && this._isMatch(selector)) {
|
|
751
|
-
res.push(this);
|
|
752
|
-
}
|
|
753
|
-
var ancestor = this.parent;
|
|
754
|
-
while (ancestor) {
|
|
755
|
-
if (ancestor === stopNode) {
|
|
756
|
-
return res;
|
|
757
|
-
}
|
|
758
|
-
if (ancestor._isMatch(selector)) {
|
|
759
|
-
res.push(ancestor);
|
|
760
|
-
}
|
|
761
|
-
ancestor = ancestor.parent;
|
|
762
|
-
}
|
|
763
|
-
return res;
|
|
764
|
-
}
|
|
765
|
-
isAncestorOf(node) {
|
|
766
|
-
return false;
|
|
767
|
-
}
|
|
768
|
-
findAncestor(selector, includeSelf, stopNode) {
|
|
769
|
-
return this.findAncestors(selector, includeSelf, stopNode)[0];
|
|
770
|
-
}
|
|
771
|
-
_isMatch(selector) {
|
|
772
|
-
if (!selector) {
|
|
773
|
-
return false;
|
|
774
|
-
}
|
|
775
|
-
if (typeof selector === 'function') {
|
|
776
|
-
return selector(this);
|
|
777
|
-
}
|
|
778
|
-
var selectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel;
|
|
779
|
-
for (n = 0; n < len; n++) {
|
|
780
|
-
sel = selectorArr[n];
|
|
781
|
-
if (!Util_1.Util.isValidSelector(sel)) {
|
|
782
|
-
Util_1.Util.warn('Selector "' +
|
|
783
|
-
sel +
|
|
784
|
-
'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".');
|
|
785
|
-
Util_1.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".');
|
|
786
|
-
Util_1.Util.warn('Konva is awesome, right?');
|
|
787
|
-
}
|
|
788
|
-
if (sel.charAt(0) === '#') {
|
|
789
|
-
if (this.id() === sel.slice(1)) {
|
|
790
|
-
return true;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
else if (sel.charAt(0) === '.') {
|
|
794
|
-
if (this.hasName(sel.slice(1))) {
|
|
795
|
-
return true;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
else if (this.className === sel || this.nodeType === sel) {
|
|
799
|
-
return true;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
return false;
|
|
803
|
-
}
|
|
804
|
-
getLayer() {
|
|
805
|
-
var parent = this.getParent();
|
|
806
|
-
return parent ? parent.getLayer() : null;
|
|
807
|
-
}
|
|
808
|
-
getStage() {
|
|
809
|
-
return this._getCache(STAGE, this._getStage);
|
|
810
|
-
}
|
|
811
|
-
_getStage() {
|
|
812
|
-
var parent = this.getParent();
|
|
813
|
-
if (parent) {
|
|
814
|
-
return parent.getStage();
|
|
815
|
-
}
|
|
816
|
-
else {
|
|
817
|
-
return undefined;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
fire(eventType, evt = {}, bubble) {
|
|
821
|
-
evt.target = evt.target || this;
|
|
822
|
-
if (bubble) {
|
|
823
|
-
this._fireAndBubble(eventType, evt);
|
|
824
|
-
}
|
|
825
|
-
else {
|
|
826
|
-
this._fire(eventType, evt);
|
|
827
|
-
}
|
|
828
|
-
return this;
|
|
829
|
-
}
|
|
830
|
-
getAbsoluteTransform(top) {
|
|
831
|
-
if (top) {
|
|
832
|
-
return this._getAbsoluteTransform(top);
|
|
833
|
-
}
|
|
834
|
-
else {
|
|
835
|
-
return this._getCache(ABSOLUTE_TRANSFORM, this._getAbsoluteTransform);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
_getAbsoluteTransform(top) {
|
|
839
|
-
var at;
|
|
840
|
-
if (top) {
|
|
841
|
-
at = new Util_1.Transform();
|
|
842
|
-
this._eachAncestorReverse(function (node) {
|
|
843
|
-
var transformsEnabled = node.transformsEnabled();
|
|
844
|
-
if (transformsEnabled === 'all') {
|
|
845
|
-
at.multiply(node.getTransform());
|
|
846
|
-
}
|
|
847
|
-
else if (transformsEnabled === 'position') {
|
|
848
|
-
at.translate(node.x() - node.offsetX(), node.y() - node.offsetY());
|
|
849
|
-
}
|
|
850
|
-
}, top);
|
|
851
|
-
return at;
|
|
852
|
-
}
|
|
853
|
-
else {
|
|
854
|
-
at = this._cache.get(ABSOLUTE_TRANSFORM) || new Util_1.Transform();
|
|
855
|
-
if (this.parent) {
|
|
856
|
-
this.parent.getAbsoluteTransform().copyInto(at);
|
|
857
|
-
}
|
|
858
|
-
else {
|
|
859
|
-
at.reset();
|
|
860
|
-
}
|
|
861
|
-
var transformsEnabled = this.transformsEnabled();
|
|
862
|
-
if (transformsEnabled === 'all') {
|
|
863
|
-
at.multiply(this.getTransform());
|
|
864
|
-
}
|
|
865
|
-
else if (transformsEnabled === 'position') {
|
|
866
|
-
const x = this.attrs.x || 0;
|
|
867
|
-
const y = this.attrs.y || 0;
|
|
868
|
-
const offsetX = this.attrs.offsetX || 0;
|
|
869
|
-
const offsetY = this.attrs.offsetY || 0;
|
|
870
|
-
at.translate(x - offsetX, y - offsetY);
|
|
871
|
-
}
|
|
872
|
-
at.dirty = false;
|
|
873
|
-
return at;
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
getAbsoluteScale(top) {
|
|
877
|
-
var parent = this;
|
|
878
|
-
while (parent) {
|
|
879
|
-
if (parent._isUnderCache) {
|
|
880
|
-
top = parent;
|
|
881
|
-
}
|
|
882
|
-
parent = parent.getParent();
|
|
883
|
-
}
|
|
884
|
-
const transform = this.getAbsoluteTransform(top);
|
|
885
|
-
const attrs = transform.decompose();
|
|
886
|
-
return {
|
|
887
|
-
x: attrs.scaleX,
|
|
888
|
-
y: attrs.scaleY,
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
getAbsoluteRotation() {
|
|
892
|
-
return this.getAbsoluteTransform().decompose().rotation;
|
|
893
|
-
}
|
|
894
|
-
getTransform() {
|
|
895
|
-
return this._getCache(TRANSFORM, this._getTransform);
|
|
896
|
-
}
|
|
897
|
-
_getTransform() {
|
|
898
|
-
var _a, _b;
|
|
899
|
-
var m = this._cache.get(TRANSFORM) || new Util_1.Transform();
|
|
900
|
-
m.reset();
|
|
901
|
-
var x = this.x(), y = this.y(), rotation = Global_1.Konva.getAngle(this.rotation()), scaleX = (_a = this.attrs.scaleX) !== null && _a !== void 0 ? _a : 1, scaleY = (_b = this.attrs.scaleY) !== null && _b !== void 0 ? _b : 1, skewX = this.attrs.skewX || 0, skewY = this.attrs.skewY || 0, offsetX = this.attrs.offsetX || 0, offsetY = this.attrs.offsetY || 0;
|
|
902
|
-
if (x !== 0 || y !== 0) {
|
|
903
|
-
m.translate(x, y);
|
|
904
|
-
}
|
|
905
|
-
if (rotation !== 0) {
|
|
906
|
-
m.rotate(rotation);
|
|
907
|
-
}
|
|
908
|
-
if (skewX !== 0 || skewY !== 0) {
|
|
909
|
-
m.skew(skewX, skewY);
|
|
910
|
-
}
|
|
911
|
-
if (scaleX !== 1 || scaleY !== 1) {
|
|
912
|
-
m.scale(scaleX, scaleY);
|
|
913
|
-
}
|
|
914
|
-
if (offsetX !== 0 || offsetY !== 0) {
|
|
915
|
-
m.translate(-1 * offsetX, -1 * offsetY);
|
|
916
|
-
}
|
|
917
|
-
m.dirty = false;
|
|
918
|
-
return m;
|
|
919
|
-
}
|
|
920
|
-
clone(obj) {
|
|
921
|
-
var attrs = Util_1.Util.cloneObject(this.attrs), key, allListeners, len, n, listener;
|
|
922
|
-
for (key in obj) {
|
|
923
|
-
attrs[key] = obj[key];
|
|
924
|
-
}
|
|
925
|
-
var node = new this.constructor(attrs);
|
|
926
|
-
for (key in this.eventListeners) {
|
|
927
|
-
allListeners = this.eventListeners[key];
|
|
928
|
-
len = allListeners.length;
|
|
929
|
-
for (n = 0; n < len; n++) {
|
|
930
|
-
listener = allListeners[n];
|
|
931
|
-
if (listener.name.indexOf(KONVA) < 0) {
|
|
932
|
-
if (!node.eventListeners[key]) {
|
|
933
|
-
node.eventListeners[key] = [];
|
|
934
|
-
}
|
|
935
|
-
node.eventListeners[key].push(listener);
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
return node;
|
|
940
|
-
}
|
|
941
|
-
_toKonvaCanvas(config) {
|
|
942
|
-
config = config || {};
|
|
943
|
-
var box = this.getClientRect();
|
|
944
|
-
var stage = this.getStage(), x = config.x !== undefined ? config.x : Math.floor(box.x), y = config.y !== undefined ? config.y : Math.floor(box.y), pixelRatio = config.pixelRatio || 1, canvas = new Canvas_1.SceneCanvas({
|
|
945
|
-
width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0),
|
|
946
|
-
height: config.height ||
|
|
947
|
-
Math.ceil(box.height) ||
|
|
948
|
-
(stage ? stage.height() : 0),
|
|
949
|
-
pixelRatio: pixelRatio,
|
|
950
|
-
}), context = canvas.getContext();
|
|
951
|
-
if (config.imageSmoothingEnabled === false) {
|
|
952
|
-
context._context.imageSmoothingEnabled = false;
|
|
953
|
-
}
|
|
954
|
-
context.save();
|
|
955
|
-
if (x || y) {
|
|
956
|
-
context.translate(-1 * x, -1 * y);
|
|
957
|
-
}
|
|
958
|
-
this.drawScene(canvas);
|
|
959
|
-
context.restore();
|
|
960
|
-
return canvas;
|
|
961
|
-
}
|
|
962
|
-
toCanvas(config) {
|
|
963
|
-
return this._toKonvaCanvas(config)._canvas;
|
|
964
|
-
}
|
|
965
|
-
toDataURL(config) {
|
|
966
|
-
config = config || {};
|
|
967
|
-
var mimeType = config.mimeType || null, quality = config.quality || null;
|
|
968
|
-
var url = this._toKonvaCanvas(config).toDataURL(mimeType, quality);
|
|
969
|
-
if (config.callback) {
|
|
970
|
-
config.callback(url);
|
|
971
|
-
}
|
|
972
|
-
return url;
|
|
973
|
-
}
|
|
974
|
-
toImage(config) {
|
|
975
|
-
return new Promise((resolve, reject) => {
|
|
976
|
-
try {
|
|
977
|
-
const callback = config === null || config === void 0 ? void 0 : config.callback;
|
|
978
|
-
if (callback)
|
|
979
|
-
delete config.callback;
|
|
980
|
-
Util_1.Util._urlToImage(this.toDataURL(config), function (img) {
|
|
981
|
-
resolve(img);
|
|
982
|
-
callback === null || callback === void 0 ? void 0 : callback(img);
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
catch (err) {
|
|
986
|
-
reject(err);
|
|
987
|
-
}
|
|
988
|
-
});
|
|
989
|
-
}
|
|
990
|
-
toBlob(config) {
|
|
991
|
-
return new Promise((resolve, reject) => {
|
|
992
|
-
try {
|
|
993
|
-
const callback = config === null || config === void 0 ? void 0 : config.callback;
|
|
994
|
-
if (callback)
|
|
995
|
-
delete config.callback;
|
|
996
|
-
this.toCanvas(config).toBlob((blob) => {
|
|
997
|
-
resolve(blob);
|
|
998
|
-
callback === null || callback === void 0 ? void 0 : callback(blob);
|
|
999
|
-
});
|
|
1000
|
-
}
|
|
1001
|
-
catch (err) {
|
|
1002
|
-
reject(err);
|
|
1003
|
-
}
|
|
1004
|
-
});
|
|
1005
|
-
}
|
|
1006
|
-
setSize(size) {
|
|
1007
|
-
this.width(size.width);
|
|
1008
|
-
this.height(size.height);
|
|
1009
|
-
return this;
|
|
1010
|
-
}
|
|
1011
|
-
getSize() {
|
|
1012
|
-
return {
|
|
1013
|
-
width: this.width(),
|
|
1014
|
-
height: this.height(),
|
|
1015
|
-
};
|
|
1016
|
-
}
|
|
1017
|
-
getClassName() {
|
|
1018
|
-
return this.className || this.nodeType;
|
|
1019
|
-
}
|
|
1020
|
-
getType() {
|
|
1021
|
-
return this.nodeType;
|
|
1022
|
-
}
|
|
1023
|
-
getDragDistance() {
|
|
1024
|
-
if (this.attrs.dragDistance !== undefined) {
|
|
1025
|
-
return this.attrs.dragDistance;
|
|
1026
|
-
}
|
|
1027
|
-
else if (this.parent) {
|
|
1028
|
-
return this.parent.getDragDistance();
|
|
1029
|
-
}
|
|
1030
|
-
else {
|
|
1031
|
-
return Global_1.Konva.dragDistance;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
_off(type, name, callback) {
|
|
1035
|
-
var evtListeners = this.eventListeners[type], i, evtName, handler;
|
|
1036
|
-
for (i = 0; i < evtListeners.length; i++) {
|
|
1037
|
-
evtName = evtListeners[i].name;
|
|
1038
|
-
handler = evtListeners[i].handler;
|
|
1039
|
-
if ((evtName !== 'konva' || name === 'konva') &&
|
|
1040
|
-
(!name || evtName === name) &&
|
|
1041
|
-
(!callback || callback === handler)) {
|
|
1042
|
-
evtListeners.splice(i, 1);
|
|
1043
|
-
if (evtListeners.length === 0) {
|
|
1044
|
-
delete this.eventListeners[type];
|
|
1045
|
-
break;
|
|
1046
|
-
}
|
|
1047
|
-
i--;
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
_fireChangeEvent(attr, oldVal, newVal) {
|
|
1052
|
-
this._fire(attr + CHANGE, {
|
|
1053
|
-
oldVal: oldVal,
|
|
1054
|
-
newVal: newVal,
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
addName(name) {
|
|
1058
|
-
if (!this.hasName(name)) {
|
|
1059
|
-
var oldName = this.name();
|
|
1060
|
-
var newName = oldName ? oldName + ' ' + name : name;
|
|
1061
|
-
this.name(newName);
|
|
1062
|
-
}
|
|
1063
|
-
return this;
|
|
1064
|
-
}
|
|
1065
|
-
hasName(name) {
|
|
1066
|
-
if (!name) {
|
|
1067
|
-
return false;
|
|
1068
|
-
}
|
|
1069
|
-
const fullName = this.name();
|
|
1070
|
-
if (!fullName) {
|
|
1071
|
-
return false;
|
|
1072
|
-
}
|
|
1073
|
-
var names = (fullName || '').split(/\s/g);
|
|
1074
|
-
return names.indexOf(name) !== -1;
|
|
1075
|
-
}
|
|
1076
|
-
removeName(name) {
|
|
1077
|
-
var names = (this.name() || '').split(/\s/g);
|
|
1078
|
-
var index = names.indexOf(name);
|
|
1079
|
-
if (index !== -1) {
|
|
1080
|
-
names.splice(index, 1);
|
|
1081
|
-
this.name(names.join(' '));
|
|
1082
|
-
}
|
|
1083
|
-
return this;
|
|
1084
|
-
}
|
|
1085
|
-
setAttr(attr, val) {
|
|
1086
|
-
var func = this[SET + Util_1.Util._capitalize(attr)];
|
|
1087
|
-
if (Util_1.Util._isFunction(func)) {
|
|
1088
|
-
func.call(this, val);
|
|
1089
|
-
}
|
|
1090
|
-
else {
|
|
1091
|
-
this._setAttr(attr, val);
|
|
1092
|
-
}
|
|
1093
|
-
return this;
|
|
1094
|
-
}
|
|
1095
|
-
_requestDraw() {
|
|
1096
|
-
if (Global_1.Konva.autoDrawEnabled) {
|
|
1097
|
-
const drawNode = this.getLayer() || this.getStage();
|
|
1098
|
-
drawNode === null || drawNode === void 0 ? void 0 : drawNode.batchDraw();
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
_setAttr(key, val) {
|
|
1102
|
-
var oldVal = this.attrs[key];
|
|
1103
|
-
if (oldVal === val && !Util_1.Util.isObject(val)) {
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
if (val === undefined || val === null) {
|
|
1107
|
-
delete this.attrs[key];
|
|
1108
|
-
}
|
|
1109
|
-
else {
|
|
1110
|
-
this.attrs[key] = val;
|
|
1111
|
-
}
|
|
1112
|
-
if (this._shouldFireChangeEvents) {
|
|
1113
|
-
this._fireChangeEvent(key, oldVal, val);
|
|
1114
|
-
}
|
|
1115
|
-
this._requestDraw();
|
|
1116
|
-
}
|
|
1117
|
-
_setComponentAttr(key, component, val) {
|
|
1118
|
-
var oldVal;
|
|
1119
|
-
if (val !== undefined) {
|
|
1120
|
-
oldVal = this.attrs[key];
|
|
1121
|
-
if (!oldVal) {
|
|
1122
|
-
this.attrs[key] = this.getAttr(key);
|
|
1123
|
-
}
|
|
1124
|
-
this.attrs[key][component] = val;
|
|
1125
|
-
this._fireChangeEvent(key, oldVal, val);
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
_fireAndBubble(eventType, evt, compareShape) {
|
|
1129
|
-
if (evt && this.nodeType === SHAPE) {
|
|
1130
|
-
evt.target = this;
|
|
1131
|
-
}
|
|
1132
|
-
var shouldStop = (eventType === MOUSEENTER || eventType === MOUSELEAVE) &&
|
|
1133
|
-
((compareShape &&
|
|
1134
|
-
(this === compareShape ||
|
|
1135
|
-
(this.isAncestorOf && this.isAncestorOf(compareShape)))) ||
|
|
1136
|
-
(this.nodeType === 'Stage' && !compareShape));
|
|
1137
|
-
if (!shouldStop) {
|
|
1138
|
-
this._fire(eventType, evt);
|
|
1139
|
-
var stopBubble = (eventType === MOUSEENTER || eventType === MOUSELEAVE) &&
|
|
1140
|
-
compareShape &&
|
|
1141
|
-
compareShape.isAncestorOf &&
|
|
1142
|
-
compareShape.isAncestorOf(this) &&
|
|
1143
|
-
!compareShape.isAncestorOf(this.parent);
|
|
1144
|
-
if (((evt && !evt.cancelBubble) || !evt) &&
|
|
1145
|
-
this.parent &&
|
|
1146
|
-
this.parent.isListening() &&
|
|
1147
|
-
!stopBubble) {
|
|
1148
|
-
if (compareShape && compareShape.parent) {
|
|
1149
|
-
this._fireAndBubble.call(this.parent, eventType, evt, compareShape);
|
|
1150
|
-
}
|
|
1151
|
-
else {
|
|
1152
|
-
this._fireAndBubble.call(this.parent, eventType, evt);
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
_getProtoListeners(eventType) {
|
|
1158
|
-
let listeners = this._cache.get(ALL_LISTENERS);
|
|
1159
|
-
if (!listeners) {
|
|
1160
|
-
listeners = {};
|
|
1161
|
-
let obj = Object.getPrototypeOf(this);
|
|
1162
|
-
while (obj) {
|
|
1163
|
-
if (!obj.eventListeners) {
|
|
1164
|
-
obj = Object.getPrototypeOf(obj);
|
|
1165
|
-
continue;
|
|
1166
|
-
}
|
|
1167
|
-
for (var event in obj.eventListeners) {
|
|
1168
|
-
const newEvents = obj.eventListeners[event];
|
|
1169
|
-
const oldEvents = listeners[event] || [];
|
|
1170
|
-
listeners[event] = newEvents.concat(oldEvents);
|
|
1171
|
-
}
|
|
1172
|
-
obj = Object.getPrototypeOf(obj);
|
|
1173
|
-
}
|
|
1174
|
-
this._cache.set(ALL_LISTENERS, listeners);
|
|
1175
|
-
}
|
|
1176
|
-
return listeners[eventType];
|
|
1177
|
-
}
|
|
1178
|
-
_fire(eventType, evt) {
|
|
1179
|
-
evt = evt || {};
|
|
1180
|
-
evt.currentTarget = this;
|
|
1181
|
-
evt.type = eventType;
|
|
1182
|
-
const topListeners = this._getProtoListeners(eventType);
|
|
1183
|
-
if (topListeners) {
|
|
1184
|
-
for (var i = 0; i < topListeners.length; i++) {
|
|
1185
|
-
topListeners[i].handler.call(this, evt);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
const selfListeners = this.eventListeners[eventType];
|
|
1189
|
-
if (selfListeners) {
|
|
1190
|
-
for (var i = 0; i < selfListeners.length; i++) {
|
|
1191
|
-
selfListeners[i].handler.call(this, evt);
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
draw() {
|
|
1196
|
-
this.drawScene();
|
|
1197
|
-
this.drawHit();
|
|
1198
|
-
return this;
|
|
1199
|
-
}
|
|
1200
|
-
_createDragElement(evt) {
|
|
1201
|
-
var pointerId = evt ? evt.pointerId : undefined;
|
|
1202
|
-
var stage = this.getStage();
|
|
1203
|
-
var ap = this.getAbsolutePosition();
|
|
1204
|
-
var pos = stage._getPointerById(pointerId) ||
|
|
1205
|
-
stage._changedPointerPositions[0] ||
|
|
1206
|
-
ap;
|
|
1207
|
-
DragAndDrop_1.DD._dragElements.set(this._id, {
|
|
1208
|
-
node: this,
|
|
1209
|
-
startPointerPos: pos,
|
|
1210
|
-
offset: {
|
|
1211
|
-
x: pos.x - ap.x,
|
|
1212
|
-
y: pos.y - ap.y,
|
|
1213
|
-
},
|
|
1214
|
-
dragStatus: 'ready',
|
|
1215
|
-
pointerId,
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
startDrag(evt, bubbleEvent = true) {
|
|
1219
|
-
if (!DragAndDrop_1.DD._dragElements.has(this._id)) {
|
|
1220
|
-
this._createDragElement(evt);
|
|
1221
|
-
}
|
|
1222
|
-
const elem = DragAndDrop_1.DD._dragElements.get(this._id);
|
|
1223
|
-
elem.dragStatus = 'dragging';
|
|
1224
|
-
this.fire('dragstart', {
|
|
1225
|
-
type: 'dragstart',
|
|
1226
|
-
target: this,
|
|
1227
|
-
evt: evt && evt.evt,
|
|
1228
|
-
}, bubbleEvent);
|
|
1229
|
-
}
|
|
1230
|
-
_setDragPosition(evt, elem) {
|
|
1231
|
-
const pos = this.getStage()._getPointerById(elem.pointerId);
|
|
1232
|
-
if (!pos) {
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
var newNodePos = {
|
|
1236
|
-
x: pos.x - elem.offset.x,
|
|
1237
|
-
y: pos.y - elem.offset.y,
|
|
1238
|
-
};
|
|
1239
|
-
var dbf = this.dragBoundFunc();
|
|
1240
|
-
if (dbf !== undefined) {
|
|
1241
|
-
const bounded = dbf.call(this, newNodePos, evt);
|
|
1242
|
-
if (!bounded) {
|
|
1243
|
-
Util_1.Util.warn('dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.');
|
|
1244
|
-
}
|
|
1245
|
-
else {
|
|
1246
|
-
newNodePos = bounded;
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
if (!this._lastPos ||
|
|
1250
|
-
this._lastPos.x !== newNodePos.x ||
|
|
1251
|
-
this._lastPos.y !== newNodePos.y) {
|
|
1252
|
-
this.setAbsolutePosition(newNodePos);
|
|
1253
|
-
this._requestDraw();
|
|
1254
|
-
}
|
|
1255
|
-
this._lastPos = newNodePos;
|
|
1256
|
-
}
|
|
1257
|
-
stopDrag(evt) {
|
|
1258
|
-
const elem = DragAndDrop_1.DD._dragElements.get(this._id);
|
|
1259
|
-
if (elem) {
|
|
1260
|
-
elem.dragStatus = 'stopped';
|
|
1261
|
-
}
|
|
1262
|
-
DragAndDrop_1.DD._endDragBefore(evt);
|
|
1263
|
-
DragAndDrop_1.DD._endDragAfter(evt);
|
|
1264
|
-
}
|
|
1265
|
-
setDraggable(draggable) {
|
|
1266
|
-
this._setAttr('draggable', draggable);
|
|
1267
|
-
this._dragChange();
|
|
1268
|
-
}
|
|
1269
|
-
isDragging() {
|
|
1270
|
-
const elem = DragAndDrop_1.DD._dragElements.get(this._id);
|
|
1271
|
-
return elem ? elem.dragStatus === 'dragging' : false;
|
|
1272
|
-
}
|
|
1273
|
-
_listenDrag() {
|
|
1274
|
-
this._dragCleanup();
|
|
1275
|
-
this.on('mousedown.konva touchstart.konva', function (evt) {
|
|
1276
|
-
var shouldCheckButton = evt.evt['button'] !== undefined;
|
|
1277
|
-
var canDrag = !shouldCheckButton || Global_1.Konva.dragButtons.indexOf(evt.evt['button']) >= 0;
|
|
1278
|
-
if (!canDrag) {
|
|
1279
|
-
return;
|
|
1280
|
-
}
|
|
1281
|
-
if (this.isDragging()) {
|
|
1282
|
-
return;
|
|
1283
|
-
}
|
|
1284
|
-
var hasDraggingChild = false;
|
|
1285
|
-
DragAndDrop_1.DD._dragElements.forEach((elem) => {
|
|
1286
|
-
if (this.isAncestorOf(elem.node)) {
|
|
1287
|
-
hasDraggingChild = true;
|
|
1288
|
-
}
|
|
1289
|
-
});
|
|
1290
|
-
if (!hasDraggingChild) {
|
|
1291
|
-
this._createDragElement(evt);
|
|
1292
|
-
}
|
|
1293
|
-
});
|
|
1294
|
-
}
|
|
1295
|
-
_dragChange() {
|
|
1296
|
-
if (this.attrs.draggable) {
|
|
1297
|
-
this._listenDrag();
|
|
1298
|
-
}
|
|
1299
|
-
else {
|
|
1300
|
-
this._dragCleanup();
|
|
1301
|
-
var stage = this.getStage();
|
|
1302
|
-
if (!stage) {
|
|
1303
|
-
return;
|
|
1304
|
-
}
|
|
1305
|
-
const dragElement = DragAndDrop_1.DD._dragElements.get(this._id);
|
|
1306
|
-
const isDragging = dragElement && dragElement.dragStatus === 'dragging';
|
|
1307
|
-
const isReady = dragElement && dragElement.dragStatus === 'ready';
|
|
1308
|
-
if (isDragging) {
|
|
1309
|
-
this.stopDrag();
|
|
1310
|
-
}
|
|
1311
|
-
else if (isReady) {
|
|
1312
|
-
DragAndDrop_1.DD._dragElements.delete(this._id);
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
_dragCleanup() {
|
|
1317
|
-
this.off('mousedown.konva');
|
|
1318
|
-
this.off('touchstart.konva');
|
|
1319
|
-
}
|
|
1320
|
-
isClientRectOnScreen(margin = { x: 0, y: 0 }) {
|
|
1321
|
-
const stage = this.getStage();
|
|
1322
|
-
if (!stage) {
|
|
1323
|
-
return false;
|
|
1324
|
-
}
|
|
1325
|
-
const screenRect = {
|
|
1326
|
-
x: -margin.x,
|
|
1327
|
-
y: -margin.y,
|
|
1328
|
-
width: stage.width() + 2 * margin.x,
|
|
1329
|
-
height: stage.height() + 2 * margin.y,
|
|
1330
|
-
};
|
|
1331
|
-
return Util_1.Util.haveIntersection(screenRect, this.getClientRect());
|
|
1332
|
-
}
|
|
1333
|
-
static create(data, container) {
|
|
1334
|
-
if (Util_1.Util._isString(data)) {
|
|
1335
|
-
data = JSON.parse(data);
|
|
1336
|
-
}
|
|
1337
|
-
return this._createNode(data, container);
|
|
1338
|
-
}
|
|
1339
|
-
static _createNode(obj, container) {
|
|
1340
|
-
var className = Node.prototype.getClassName.call(obj), children = obj.children, no, len, n;
|
|
1341
|
-
if (container) {
|
|
1342
|
-
obj.attrs.container = container;
|
|
1343
|
-
}
|
|
1344
|
-
if (!Global_1.Konva[className]) {
|
|
1345
|
-
Util_1.Util.warn('Can not find a node with class name "' +
|
|
1346
|
-
className +
|
|
1347
|
-
'". Fallback to "Shape".');
|
|
1348
|
-
className = 'Shape';
|
|
1349
|
-
}
|
|
1350
|
-
const Class = Global_1.Konva[className];
|
|
1351
|
-
no = new Class(obj.attrs);
|
|
1352
|
-
if (children) {
|
|
1353
|
-
len = children.length;
|
|
1354
|
-
for (n = 0; n < len; n++) {
|
|
1355
|
-
no.add(Node._createNode(children[n]));
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
return no;
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
exports.Node = Node;
|
|
1362
|
-
Node.prototype.nodeType = 'Node';
|
|
1363
|
-
Node.prototype._attrsAffectingSize = [];
|
|
1364
|
-
Node.prototype.eventListeners = {};
|
|
1365
|
-
Node.prototype.on.call(Node.prototype, TRANSFORM_CHANGE_STR, function () {
|
|
1366
|
-
if (this._batchingTransformChange) {
|
|
1367
|
-
this._needClearTransformCache = true;
|
|
1368
|
-
return;
|
|
1369
|
-
}
|
|
1370
|
-
this._clearCache(TRANSFORM);
|
|
1371
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
1372
|
-
});
|
|
1373
|
-
Node.prototype.on.call(Node.prototype, 'visibleChange.konva', function () {
|
|
1374
|
-
this._clearSelfAndDescendantCache(VISIBLE);
|
|
1375
|
-
});
|
|
1376
|
-
Node.prototype.on.call(Node.prototype, 'listeningChange.konva', function () {
|
|
1377
|
-
this._clearSelfAndDescendantCache(LISTENING);
|
|
1378
|
-
});
|
|
1379
|
-
Node.prototype.on.call(Node.prototype, 'opacityChange.konva', function () {
|
|
1380
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
|
1381
|
-
});
|
|
1382
|
-
const addGetterSetter = Factory_1.Factory.addGetterSetter;
|
|
1383
|
-
addGetterSetter(Node, 'zIndex');
|
|
1384
|
-
addGetterSetter(Node, 'absolutePosition');
|
|
1385
|
-
addGetterSetter(Node, 'position');
|
|
1386
|
-
addGetterSetter(Node, 'x', 0, (0, Validators_1.getNumberValidator)());
|
|
1387
|
-
addGetterSetter(Node, 'y', 0, (0, Validators_1.getNumberValidator)());
|
|
1388
|
-
addGetterSetter(Node, 'globalCompositeOperation', 'source-over', (0, Validators_1.getStringValidator)());
|
|
1389
|
-
addGetterSetter(Node, 'opacity', 1, (0, Validators_1.getNumberValidator)());
|
|
1390
|
-
addGetterSetter(Node, 'name', '', (0, Validators_1.getStringValidator)());
|
|
1391
|
-
addGetterSetter(Node, 'id', '', (0, Validators_1.getStringValidator)());
|
|
1392
|
-
addGetterSetter(Node, 'rotation', 0, (0, Validators_1.getNumberValidator)());
|
|
1393
|
-
Factory_1.Factory.addComponentsGetterSetter(Node, 'scale', ['x', 'y']);
|
|
1394
|
-
addGetterSetter(Node, 'scaleX', 1, (0, Validators_1.getNumberValidator)());
|
|
1395
|
-
addGetterSetter(Node, 'scaleY', 1, (0, Validators_1.getNumberValidator)());
|
|
1396
|
-
Factory_1.Factory.addComponentsGetterSetter(Node, 'skew', ['x', 'y']);
|
|
1397
|
-
addGetterSetter(Node, 'skewX', 0, (0, Validators_1.getNumberValidator)());
|
|
1398
|
-
addGetterSetter(Node, 'skewY', 0, (0, Validators_1.getNumberValidator)());
|
|
1399
|
-
Factory_1.Factory.addComponentsGetterSetter(Node, 'offset', ['x', 'y']);
|
|
1400
|
-
addGetterSetter(Node, 'offsetX', 0, (0, Validators_1.getNumberValidator)());
|
|
1401
|
-
addGetterSetter(Node, 'offsetY', 0, (0, Validators_1.getNumberValidator)());
|
|
1402
|
-
addGetterSetter(Node, 'dragDistance', null, (0, Validators_1.getNumberValidator)());
|
|
1403
|
-
addGetterSetter(Node, 'width', 0, (0, Validators_1.getNumberValidator)());
|
|
1404
|
-
addGetterSetter(Node, 'height', 0, (0, Validators_1.getNumberValidator)());
|
|
1405
|
-
addGetterSetter(Node, 'listening', true, (0, Validators_1.getBooleanValidator)());
|
|
1406
|
-
addGetterSetter(Node, 'preventDefault', true, (0, Validators_1.getBooleanValidator)());
|
|
1407
|
-
addGetterSetter(Node, 'filters', null, function (val) {
|
|
1408
|
-
this._filterUpToDate = false;
|
|
1409
|
-
return val;
|
|
1410
|
-
});
|
|
1411
|
-
addGetterSetter(Node, 'visible', true, (0, Validators_1.getBooleanValidator)());
|
|
1412
|
-
addGetterSetter(Node, 'transformsEnabled', 'all', (0, Validators_1.getStringValidator)());
|
|
1413
|
-
addGetterSetter(Node, 'size');
|
|
1414
|
-
addGetterSetter(Node, 'dragBoundFunc');
|
|
1415
|
-
addGetterSetter(Node, 'draggable', false, (0, Validators_1.getBooleanValidator)());
|
|
1416
|
-
Factory_1.Factory.backCompat(Node, {
|
|
1417
|
-
rotateDeg: 'rotate',
|
|
1418
|
-
setRotationDeg: 'setRotation',
|
|
1419
|
-
getRotationDeg: 'getRotation',
|
|
1420
|
-
});
|