konva 8.4.3 → 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 -16989
- package/konva.min.js +3 -3
- package/lib/Animation.js +11 -7
- package/lib/BezierFunctions.d.ts +6 -0
- package/lib/BezierFunctions.js +791 -0
- package/lib/Canvas.d.ts +1 -0
- package/lib/Canvas.js +26 -18
- package/lib/Container.js +16 -12
- package/lib/Context.d.ts +3 -1
- package/lib/Context.js +18 -10
- package/lib/Core.js +7 -3
- package/lib/DragAndDrop.js +25 -22
- package/lib/Factory.js +27 -24
- package/lib/FastLayer.js +10 -6
- package/lib/Global.js +16 -12
- package/lib/Group.js +10 -6
- package/lib/Layer.js +37 -33
- package/lib/Node.js +95 -90
- package/lib/PointerEvents.js +15 -7
- package/lib/Shape.js +90 -86
- package/lib/Stage.js +51 -47
- package/lib/Tween.js +26 -22
- package/lib/Util.js +29 -25
- package/lib/Validators.js +58 -44
- package/lib/_CoreInternals.js +36 -33
- package/lib/_FullInternals.js +78 -75
- package/lib/filters/Blur.js +9 -5
- package/lib/filters/Brighten.js +9 -5
- package/lib/filters/Contrast.js +9 -5
- package/lib/filters/Emboss.js +14 -10
- package/lib/filters/Enhance.js +9 -5
- package/lib/filters/Grayscale.js +5 -1
- package/lib/filters/HSL.js +11 -7
- package/lib/filters/HSV.js +11 -7
- package/lib/filters/Invert.js +5 -1
- package/lib/filters/Kaleidoscope.js +13 -9
- package/lib/filters/Mask.js +9 -5
- package/lib/filters/Noise.js +9 -5
- package/lib/filters/Pixelate.js +11 -7
- package/lib/filters/Posterize.js +9 -5
- package/lib/filters/RGB.js +11 -7
- package/lib/filters/RGBA.js +12 -8
- package/lib/filters/Sepia.js +5 -1
- package/lib/filters/Solarize.js +5 -1
- package/lib/filters/Threshold.js +9 -5
- package/lib/index-node.js +7 -5
- package/lib/index.js +4 -2
- package/lib/shapes/Arc.js +17 -13
- package/lib/shapes/Arrow.js +17 -13
- package/lib/shapes/Circle.js +11 -7
- package/lib/shapes/Ellipse.js +13 -9
- package/lib/shapes/Image.js +21 -17
- package/lib/shapes/Label.js +18 -13
- package/lib/shapes/Line.js +14 -10
- package/lib/shapes/Path.d.ts +5 -2
- package/lib/shapes/Path.js +44 -43
- package/lib/shapes/Rect.js +13 -9
- package/lib/shapes/RegularPolygon.js +12 -8
- package/lib/shapes/Ring.js +12 -8
- package/lib/shapes/Sprite.js +19 -15
- package/lib/shapes/Star.js +13 -9
- package/lib/shapes/Text.js +31 -26
- package/lib/shapes/TextPath.d.ts +5 -1
- package/lib/shapes/TextPath.js +82 -188
- package/lib/shapes/Transformer.js +85 -81
- 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 -85
- 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 -186
- 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 -26
- package/cmj/shapes/Arc.js +0 -59
- package/cmj/shapes/Arrow.d.ts +0 -26
- package/cmj/shapes/Arrow.js +0 -103
- package/cmj/shapes/Circle.d.ts +0 -14
- package/cmj/shapes/Circle.js +0 -37
- package/cmj/shapes/Ellipse.d.ts +0 -17
- 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 -36
- 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 -23
- package/cmj/shapes/RegularPolygon.js +0 -69
- package/cmj/shapes/Ring.d.ts +0 -16
- package/cmj/shapes/Ring.js +0 -37
- package/cmj/shapes/Sprite.d.ts +0 -31
- package/cmj/shapes/Sprite.js +0 -112
- package/cmj/shapes/Star.d.ts +0 -18
- package/cmj/shapes/Star.js +0 -42
- package/cmj/shapes/Text.d.ts +0 -63
- package/cmj/shapes/Text.js +0 -373
- package/cmj/shapes/TextPath.d.ts +0 -56
- package/cmj/shapes/TextPath.js +0 -351
- package/cmj/shapes/Transformer.d.ts +0 -116
- package/cmj/shapes/Transformer.js +0 -971
- package/cmj/shapes/Wedge.d.ts +0 -18
- package/cmj/shapes/Wedge.js +0 -42
- package/cmj/types.d.ts +0 -50
- package/cmj/types.js +0 -25
package/lib/Node.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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");
|
|
7
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 = [
|
|
8
11
|
'xChange.konva',
|
|
9
12
|
'yChange.konva',
|
|
@@ -17,7 +20,7 @@ var ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', A
|
|
|
17
20
|
'transformsEnabledChange.konva',
|
|
18
21
|
].join(SPACE);
|
|
19
22
|
let idCounter = 1;
|
|
20
|
-
|
|
23
|
+
class Node {
|
|
21
24
|
constructor(config) {
|
|
22
25
|
this._id = idCounter++;
|
|
23
26
|
this.eventListeners = {};
|
|
@@ -84,7 +87,7 @@ export class Node {
|
|
|
84
87
|
clearCache() {
|
|
85
88
|
if (this._cache.has(CANVAS)) {
|
|
86
89
|
const { scene, filter, hit } = this._cache.get(CANVAS);
|
|
87
|
-
Util.releaseCanvas(scene, filter, hit);
|
|
90
|
+
Util_1.Util.releaseCanvas(scene, filter, hit);
|
|
88
91
|
this._cache.delete(CANVAS);
|
|
89
92
|
}
|
|
90
93
|
this._clearSelfAndDescendantCache();
|
|
@@ -105,22 +108,23 @@ export class Node {
|
|
|
105
108
|
}
|
|
106
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;
|
|
107
110
|
if (!width || !height) {
|
|
108
|
-
Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
|
|
111
|
+
Util_1.Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
|
|
109
112
|
return;
|
|
110
113
|
}
|
|
111
114
|
width += offset * 2 + 1;
|
|
112
115
|
height += offset * 2 + 1;
|
|
113
116
|
x -= offset;
|
|
114
117
|
y -= offset;
|
|
115
|
-
var cachedSceneCanvas = new SceneCanvas({
|
|
118
|
+
var cachedSceneCanvas = new Canvas_1.SceneCanvas({
|
|
116
119
|
pixelRatio: pixelRatio,
|
|
117
120
|
width: width,
|
|
118
121
|
height: height,
|
|
119
|
-
}), cachedFilterCanvas = new SceneCanvas({
|
|
122
|
+
}), cachedFilterCanvas = new Canvas_1.SceneCanvas({
|
|
120
123
|
pixelRatio: pixelRatio,
|
|
121
124
|
width: 0,
|
|
122
125
|
height: 0,
|
|
123
|
-
|
|
126
|
+
willReadFrequently: true,
|
|
127
|
+
}), cachedHitCanvas = new Canvas_1.HitCanvas({
|
|
124
128
|
pixelRatio: hitCanvasPixelRatio,
|
|
125
129
|
width: width,
|
|
126
130
|
height: height,
|
|
@@ -230,7 +234,7 @@ export class Node {
|
|
|
230
234
|
for (n = 0; n < len; n++) {
|
|
231
235
|
filter = filters[n];
|
|
232
236
|
if (typeof filter !== 'function') {
|
|
233
|
-
Util.error('Filter should be type of function, but got ' +
|
|
237
|
+
Util_1.Util.error('Filter should be type of function, but got ' +
|
|
234
238
|
typeof filter +
|
|
235
239
|
' instead. Please check correct filters');
|
|
236
240
|
continue;
|
|
@@ -240,7 +244,7 @@ export class Node {
|
|
|
240
244
|
}
|
|
241
245
|
}
|
|
242
246
|
catch (e) {
|
|
243
|
-
Util.error('Unable to apply filter. ' +
|
|
247
|
+
Util_1.Util.error('Unable to apply filter. ' +
|
|
244
248
|
e.message +
|
|
245
249
|
' This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.');
|
|
246
250
|
}
|
|
@@ -321,7 +325,7 @@ export class Node {
|
|
|
321
325
|
this.on(event, function (evt) {
|
|
322
326
|
var targets = evt.target.findAncestors(selector, true, stopNode);
|
|
323
327
|
for (var i = 0; i < targets.length; i++) {
|
|
324
|
-
evt = Util.cloneObject(evt);
|
|
328
|
+
evt = Util_1.Util.cloneObject(evt);
|
|
325
329
|
evt.currentTarget = targets[i];
|
|
326
330
|
handler.call(targets[i], evt);
|
|
327
331
|
}
|
|
@@ -331,7 +335,7 @@ export class Node {
|
|
|
331
335
|
if (this.isDragging()) {
|
|
332
336
|
this.stopDrag();
|
|
333
337
|
}
|
|
334
|
-
DD._dragElements.delete(this._id);
|
|
338
|
+
DragAndDrop_1.DD._dragElements.delete(this._id);
|
|
335
339
|
this._remove();
|
|
336
340
|
return this;
|
|
337
341
|
}
|
|
@@ -358,8 +362,8 @@ export class Node {
|
|
|
358
362
|
return this;
|
|
359
363
|
}
|
|
360
364
|
getAttr(attr) {
|
|
361
|
-
var method = 'get' + Util._capitalize(attr);
|
|
362
|
-
if (Util._isFunction(this[method])) {
|
|
365
|
+
var method = 'get' + Util_1.Util._capitalize(attr);
|
|
366
|
+
if (Util_1.Util._isFunction(this[method])) {
|
|
363
367
|
return this[method]();
|
|
364
368
|
}
|
|
365
369
|
return this.attrs[attr];
|
|
@@ -385,8 +389,8 @@ export class Node {
|
|
|
385
389
|
if (key === CHILDREN) {
|
|
386
390
|
continue;
|
|
387
391
|
}
|
|
388
|
-
method = SET + Util._capitalize(key);
|
|
389
|
-
if (Util._isFunction(this[method])) {
|
|
392
|
+
method = SET + Util_1.Util._capitalize(key);
|
|
393
|
+
if (Util_1.Util._isFunction(this[method])) {
|
|
390
394
|
this[method](config[key]);
|
|
391
395
|
}
|
|
392
396
|
else {
|
|
@@ -434,7 +438,7 @@ export class Node {
|
|
|
434
438
|
}
|
|
435
439
|
var layer = this.getLayer();
|
|
436
440
|
var layerUnderDrag = false;
|
|
437
|
-
DD._dragElements.forEach((elem) => {
|
|
441
|
+
DragAndDrop_1.DD._dragElements.forEach((elem) => {
|
|
438
442
|
if (elem.dragStatus !== 'dragging') {
|
|
439
443
|
return;
|
|
440
444
|
}
|
|
@@ -445,7 +449,7 @@ export class Node {
|
|
|
445
449
|
layerUnderDrag = true;
|
|
446
450
|
}
|
|
447
451
|
});
|
|
448
|
-
var dragSkip = !skipDragCheck && !Konva.hitOnDragEnabled && layerUnderDrag;
|
|
452
|
+
var dragSkip = !skipDragCheck && !Global_1.Konva.hitOnDragEnabled && layerUnderDrag;
|
|
449
453
|
return this.isListening() && this.isVisible() && !dragSkip;
|
|
450
454
|
}
|
|
451
455
|
show() {
|
|
@@ -539,7 +543,7 @@ export class Node {
|
|
|
539
543
|
if (haveCachedParent && !top) {
|
|
540
544
|
top = true;
|
|
541
545
|
}
|
|
542
|
-
var absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Transform(), offset = this.offset();
|
|
546
|
+
var absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Util_1.Transform(), offset = this.offset();
|
|
543
547
|
absoluteTransform.m = absoluteMatrix.slice();
|
|
544
548
|
absoluteTransform.translate(offset.x, offset.y);
|
|
545
549
|
return absoluteTransform.getTranslation();
|
|
@@ -625,7 +629,7 @@ export class Node {
|
|
|
625
629
|
}
|
|
626
630
|
moveToTop() {
|
|
627
631
|
if (!this.parent) {
|
|
628
|
-
Util.warn('Node has no parent. moveToTop function is ignored.');
|
|
632
|
+
Util_1.Util.warn('Node has no parent. moveToTop function is ignored.');
|
|
629
633
|
return false;
|
|
630
634
|
}
|
|
631
635
|
var index = this.index, len = this.parent.getChildren().length;
|
|
@@ -639,7 +643,7 @@ export class Node {
|
|
|
639
643
|
}
|
|
640
644
|
moveUp() {
|
|
641
645
|
if (!this.parent) {
|
|
642
|
-
Util.warn('Node has no parent. moveUp function is ignored.');
|
|
646
|
+
Util_1.Util.warn('Node has no parent. moveUp function is ignored.');
|
|
643
647
|
return false;
|
|
644
648
|
}
|
|
645
649
|
var index = this.index, len = this.parent.getChildren().length;
|
|
@@ -653,7 +657,7 @@ export class Node {
|
|
|
653
657
|
}
|
|
654
658
|
moveDown() {
|
|
655
659
|
if (!this.parent) {
|
|
656
|
-
Util.warn('Node has no parent. moveDown function is ignored.');
|
|
660
|
+
Util_1.Util.warn('Node has no parent. moveDown function is ignored.');
|
|
657
661
|
return false;
|
|
658
662
|
}
|
|
659
663
|
var index = this.index;
|
|
@@ -667,7 +671,7 @@ export class Node {
|
|
|
667
671
|
}
|
|
668
672
|
moveToBottom() {
|
|
669
673
|
if (!this.parent) {
|
|
670
|
-
Util.warn('Node has no parent. moveToBottom function is ignored.');
|
|
674
|
+
Util_1.Util.warn('Node has no parent. moveToBottom function is ignored.');
|
|
671
675
|
return false;
|
|
672
676
|
}
|
|
673
677
|
var index = this.index;
|
|
@@ -681,11 +685,11 @@ export class Node {
|
|
|
681
685
|
}
|
|
682
686
|
setZIndex(zIndex) {
|
|
683
687
|
if (!this.parent) {
|
|
684
|
-
Util.warn('Node has no parent. zIndex parameter is ignored.');
|
|
688
|
+
Util_1.Util.warn('Node has no parent. zIndex parameter is ignored.');
|
|
685
689
|
return this;
|
|
686
690
|
}
|
|
687
691
|
if (zIndex < 0 || zIndex >= this.parent.children.length) {
|
|
688
|
-
Util.warn('Unexpected value ' +
|
|
692
|
+
Util_1.Util.warn('Unexpected value ' +
|
|
689
693
|
zIndex +
|
|
690
694
|
' for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to ' +
|
|
691
695
|
(this.parent.children.length - 1) +
|
|
@@ -721,7 +725,7 @@ export class Node {
|
|
|
721
725
|
for (key in attrs) {
|
|
722
726
|
val = attrs[key];
|
|
723
727
|
nonPlainObject =
|
|
724
|
-
Util.isObject(val) && !Util._isPlainObject(val) && !Util._isArray(val);
|
|
728
|
+
Util_1.Util.isObject(val) && !Util_1.Util._isPlainObject(val) && !Util_1.Util._isArray(val);
|
|
725
729
|
if (nonPlainObject) {
|
|
726
730
|
continue;
|
|
727
731
|
}
|
|
@@ -734,7 +738,7 @@ export class Node {
|
|
|
734
738
|
}
|
|
735
739
|
}
|
|
736
740
|
obj.className = this.getClassName();
|
|
737
|
-
return Util._prepareToStringify(obj);
|
|
741
|
+
return Util_1.Util._prepareToStringify(obj);
|
|
738
742
|
}
|
|
739
743
|
toJSON() {
|
|
740
744
|
return JSON.stringify(this.toObject());
|
|
@@ -775,12 +779,12 @@ export class Node {
|
|
|
775
779
|
var selectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel;
|
|
776
780
|
for (n = 0; n < len; n++) {
|
|
777
781
|
sel = selectorArr[n];
|
|
778
|
-
if (!Util.isValidSelector(sel)) {
|
|
779
|
-
Util.warn('Selector "' +
|
|
782
|
+
if (!Util_1.Util.isValidSelector(sel)) {
|
|
783
|
+
Util_1.Util.warn('Selector "' +
|
|
780
784
|
sel +
|
|
781
785
|
'" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".');
|
|
782
|
-
Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".');
|
|
783
|
-
Util.warn('Konva is awesome, right?');
|
|
786
|
+
Util_1.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".');
|
|
787
|
+
Util_1.Util.warn('Konva is awesome, right?');
|
|
784
788
|
}
|
|
785
789
|
if (sel.charAt(0) === '#') {
|
|
786
790
|
if (this.id() === sel.slice(1)) {
|
|
@@ -835,7 +839,7 @@ export class Node {
|
|
|
835
839
|
_getAbsoluteTransform(top) {
|
|
836
840
|
var at;
|
|
837
841
|
if (top) {
|
|
838
|
-
at = new Transform();
|
|
842
|
+
at = new Util_1.Transform();
|
|
839
843
|
this._eachAncestorReverse(function (node) {
|
|
840
844
|
var transformsEnabled = node.transformsEnabled();
|
|
841
845
|
if (transformsEnabled === 'all') {
|
|
@@ -848,7 +852,7 @@ export class Node {
|
|
|
848
852
|
return at;
|
|
849
853
|
}
|
|
850
854
|
else {
|
|
851
|
-
at = this._cache.get(ABSOLUTE_TRANSFORM) || new Transform();
|
|
855
|
+
at = this._cache.get(ABSOLUTE_TRANSFORM) || new Util_1.Transform();
|
|
852
856
|
if (this.parent) {
|
|
853
857
|
this.parent.getAbsoluteTransform().copyInto(at);
|
|
854
858
|
}
|
|
@@ -893,9 +897,9 @@ export class Node {
|
|
|
893
897
|
}
|
|
894
898
|
_getTransform() {
|
|
895
899
|
var _a, _b;
|
|
896
|
-
var m = this._cache.get(TRANSFORM) || new Transform();
|
|
900
|
+
var m = this._cache.get(TRANSFORM) || new Util_1.Transform();
|
|
897
901
|
m.reset();
|
|
898
|
-
var x = this.x(), y = this.y(), rotation = 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
|
+
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;
|
|
899
903
|
if (x !== 0 || y !== 0) {
|
|
900
904
|
m.translate(x, y);
|
|
901
905
|
}
|
|
@@ -915,7 +919,7 @@ export class Node {
|
|
|
915
919
|
return m;
|
|
916
920
|
}
|
|
917
921
|
clone(obj) {
|
|
918
|
-
var attrs = Util.cloneObject(this.attrs), key, allListeners, len, n, listener;
|
|
922
|
+
var attrs = Util_1.Util.cloneObject(this.attrs), key, allListeners, len, n, listener;
|
|
919
923
|
for (key in obj) {
|
|
920
924
|
attrs[key] = obj[key];
|
|
921
925
|
}
|
|
@@ -938,7 +942,7 @@ export class Node {
|
|
|
938
942
|
_toKonvaCanvas(config) {
|
|
939
943
|
config = config || {};
|
|
940
944
|
var box = this.getClientRect();
|
|
941
|
-
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 SceneCanvas({
|
|
945
|
+
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({
|
|
942
946
|
width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0),
|
|
943
947
|
height: config.height ||
|
|
944
948
|
Math.ceil(box.height) ||
|
|
@@ -974,7 +978,7 @@ export class Node {
|
|
|
974
978
|
const callback = config === null || config === void 0 ? void 0 : config.callback;
|
|
975
979
|
if (callback)
|
|
976
980
|
delete config.callback;
|
|
977
|
-
Util._urlToImage(this.toDataURL(config), function (img) {
|
|
981
|
+
Util_1.Util._urlToImage(this.toDataURL(config), function (img) {
|
|
978
982
|
resolve(img);
|
|
979
983
|
callback === null || callback === void 0 ? void 0 : callback(img);
|
|
980
984
|
});
|
|
@@ -1025,7 +1029,7 @@ export class Node {
|
|
|
1025
1029
|
return this.parent.getDragDistance();
|
|
1026
1030
|
}
|
|
1027
1031
|
else {
|
|
1028
|
-
return Konva.dragDistance;
|
|
1032
|
+
return Global_1.Konva.dragDistance;
|
|
1029
1033
|
}
|
|
1030
1034
|
}
|
|
1031
1035
|
_off(type, name, callback) {
|
|
@@ -1080,8 +1084,8 @@ export class Node {
|
|
|
1080
1084
|
return this;
|
|
1081
1085
|
}
|
|
1082
1086
|
setAttr(attr, val) {
|
|
1083
|
-
var func = this[SET + Util._capitalize(attr)];
|
|
1084
|
-
if (Util._isFunction(func)) {
|
|
1087
|
+
var func = this[SET + Util_1.Util._capitalize(attr)];
|
|
1088
|
+
if (Util_1.Util._isFunction(func)) {
|
|
1085
1089
|
func.call(this, val);
|
|
1086
1090
|
}
|
|
1087
1091
|
else {
|
|
@@ -1090,14 +1094,14 @@ export class Node {
|
|
|
1090
1094
|
return this;
|
|
1091
1095
|
}
|
|
1092
1096
|
_requestDraw() {
|
|
1093
|
-
if (Konva.autoDrawEnabled) {
|
|
1097
|
+
if (Global_1.Konva.autoDrawEnabled) {
|
|
1094
1098
|
const drawNode = this.getLayer() || this.getStage();
|
|
1095
1099
|
drawNode === null || drawNode === void 0 ? void 0 : drawNode.batchDraw();
|
|
1096
1100
|
}
|
|
1097
1101
|
}
|
|
1098
1102
|
_setAttr(key, val) {
|
|
1099
1103
|
var oldVal = this.attrs[key];
|
|
1100
|
-
if (oldVal === val && !Util.isObject(val)) {
|
|
1104
|
+
if (oldVal === val && !Util_1.Util.isObject(val)) {
|
|
1101
1105
|
return;
|
|
1102
1106
|
}
|
|
1103
1107
|
if (val === undefined || val === null) {
|
|
@@ -1201,7 +1205,7 @@ export class Node {
|
|
|
1201
1205
|
var pos = stage._getPointerById(pointerId) ||
|
|
1202
1206
|
stage._changedPointerPositions[0] ||
|
|
1203
1207
|
ap;
|
|
1204
|
-
DD._dragElements.set(this._id, {
|
|
1208
|
+
DragAndDrop_1.DD._dragElements.set(this._id, {
|
|
1205
1209
|
node: this,
|
|
1206
1210
|
startPointerPos: pos,
|
|
1207
1211
|
offset: {
|
|
@@ -1213,10 +1217,10 @@ export class Node {
|
|
|
1213
1217
|
});
|
|
1214
1218
|
}
|
|
1215
1219
|
startDrag(evt, bubbleEvent = true) {
|
|
1216
|
-
if (!DD._dragElements.has(this._id)) {
|
|
1220
|
+
if (!DragAndDrop_1.DD._dragElements.has(this._id)) {
|
|
1217
1221
|
this._createDragElement(evt);
|
|
1218
1222
|
}
|
|
1219
|
-
const elem = DD._dragElements.get(this._id);
|
|
1223
|
+
const elem = DragAndDrop_1.DD._dragElements.get(this._id);
|
|
1220
1224
|
elem.dragStatus = 'dragging';
|
|
1221
1225
|
this.fire('dragstart', {
|
|
1222
1226
|
type: 'dragstart',
|
|
@@ -1237,7 +1241,7 @@ export class Node {
|
|
|
1237
1241
|
if (dbf !== undefined) {
|
|
1238
1242
|
const bounded = dbf.call(this, newNodePos, evt);
|
|
1239
1243
|
if (!bounded) {
|
|
1240
|
-
Util.warn('dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.');
|
|
1244
|
+
Util_1.Util.warn('dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.');
|
|
1241
1245
|
}
|
|
1242
1246
|
else {
|
|
1243
1247
|
newNodePos = bounded;
|
|
@@ -1252,26 +1256,26 @@ export class Node {
|
|
|
1252
1256
|
this._lastPos = newNodePos;
|
|
1253
1257
|
}
|
|
1254
1258
|
stopDrag(evt) {
|
|
1255
|
-
const elem = DD._dragElements.get(this._id);
|
|
1259
|
+
const elem = DragAndDrop_1.DD._dragElements.get(this._id);
|
|
1256
1260
|
if (elem) {
|
|
1257
1261
|
elem.dragStatus = 'stopped';
|
|
1258
1262
|
}
|
|
1259
|
-
DD._endDragBefore(evt);
|
|
1260
|
-
DD._endDragAfter(evt);
|
|
1263
|
+
DragAndDrop_1.DD._endDragBefore(evt);
|
|
1264
|
+
DragAndDrop_1.DD._endDragAfter(evt);
|
|
1261
1265
|
}
|
|
1262
1266
|
setDraggable(draggable) {
|
|
1263
1267
|
this._setAttr('draggable', draggable);
|
|
1264
1268
|
this._dragChange();
|
|
1265
1269
|
}
|
|
1266
1270
|
isDragging() {
|
|
1267
|
-
const elem = DD._dragElements.get(this._id);
|
|
1271
|
+
const elem = DragAndDrop_1.DD._dragElements.get(this._id);
|
|
1268
1272
|
return elem ? elem.dragStatus === 'dragging' : false;
|
|
1269
1273
|
}
|
|
1270
1274
|
_listenDrag() {
|
|
1271
1275
|
this._dragCleanup();
|
|
1272
1276
|
this.on('mousedown.konva touchstart.konva', function (evt) {
|
|
1273
1277
|
var shouldCheckButton = evt.evt['button'] !== undefined;
|
|
1274
|
-
var canDrag = !shouldCheckButton || Konva.dragButtons.indexOf(evt.evt['button']) >= 0;
|
|
1278
|
+
var canDrag = !shouldCheckButton || Global_1.Konva.dragButtons.indexOf(evt.evt['button']) >= 0;
|
|
1275
1279
|
if (!canDrag) {
|
|
1276
1280
|
return;
|
|
1277
1281
|
}
|
|
@@ -1279,7 +1283,7 @@ export class Node {
|
|
|
1279
1283
|
return;
|
|
1280
1284
|
}
|
|
1281
1285
|
var hasDraggingChild = false;
|
|
1282
|
-
DD._dragElements.forEach((elem) => {
|
|
1286
|
+
DragAndDrop_1.DD._dragElements.forEach((elem) => {
|
|
1283
1287
|
if (this.isAncestorOf(elem.node)) {
|
|
1284
1288
|
hasDraggingChild = true;
|
|
1285
1289
|
}
|
|
@@ -1299,14 +1303,14 @@ export class Node {
|
|
|
1299
1303
|
if (!stage) {
|
|
1300
1304
|
return;
|
|
1301
1305
|
}
|
|
1302
|
-
const dragElement = DD._dragElements.get(this._id);
|
|
1306
|
+
const dragElement = DragAndDrop_1.DD._dragElements.get(this._id);
|
|
1303
1307
|
const isDragging = dragElement && dragElement.dragStatus === 'dragging';
|
|
1304
1308
|
const isReady = dragElement && dragElement.dragStatus === 'ready';
|
|
1305
1309
|
if (isDragging) {
|
|
1306
1310
|
this.stopDrag();
|
|
1307
1311
|
}
|
|
1308
1312
|
else if (isReady) {
|
|
1309
|
-
DD._dragElements.delete(this._id);
|
|
1313
|
+
DragAndDrop_1.DD._dragElements.delete(this._id);
|
|
1310
1314
|
}
|
|
1311
1315
|
}
|
|
1312
1316
|
}
|
|
@@ -1325,10 +1329,10 @@ export class Node {
|
|
|
1325
1329
|
width: stage.width() + 2 * margin.x,
|
|
1326
1330
|
height: stage.height() + 2 * margin.y,
|
|
1327
1331
|
};
|
|
1328
|
-
return Util.haveIntersection(screenRect, this.getClientRect());
|
|
1332
|
+
return Util_1.Util.haveIntersection(screenRect, this.getClientRect());
|
|
1329
1333
|
}
|
|
1330
1334
|
static create(data, container) {
|
|
1331
|
-
if (Util._isString(data)) {
|
|
1335
|
+
if (Util_1.Util._isString(data)) {
|
|
1332
1336
|
data = JSON.parse(data);
|
|
1333
1337
|
}
|
|
1334
1338
|
return this._createNode(data, container);
|
|
@@ -1338,13 +1342,13 @@ export class Node {
|
|
|
1338
1342
|
if (container) {
|
|
1339
1343
|
obj.attrs.container = container;
|
|
1340
1344
|
}
|
|
1341
|
-
if (!Konva[className]) {
|
|
1342
|
-
Util.warn('Can not find a node with class name "' +
|
|
1345
|
+
if (!Global_1.Konva[className]) {
|
|
1346
|
+
Util_1.Util.warn('Can not find a node with class name "' +
|
|
1343
1347
|
className +
|
|
1344
1348
|
'". Fallback to "Shape".');
|
|
1345
1349
|
className = 'Shape';
|
|
1346
1350
|
}
|
|
1347
|
-
const Class = Konva[className];
|
|
1351
|
+
const Class = Global_1.Konva[className];
|
|
1348
1352
|
no = new Class(obj.attrs);
|
|
1349
1353
|
if (children) {
|
|
1350
1354
|
len = children.length;
|
|
@@ -1355,6 +1359,7 @@ export class Node {
|
|
|
1355
1359
|
return no;
|
|
1356
1360
|
}
|
|
1357
1361
|
}
|
|
1362
|
+
exports.Node = Node;
|
|
1358
1363
|
Node.prototype.nodeType = 'Node';
|
|
1359
1364
|
Node.prototype._attrsAffectingSize = [];
|
|
1360
1365
|
Node.prototype.eventListeners = {};
|
|
@@ -1375,41 +1380,41 @@ Node.prototype.on.call(Node.prototype, 'listeningChange.konva', function () {
|
|
|
1375
1380
|
Node.prototype.on.call(Node.prototype, 'opacityChange.konva', function () {
|
|
1376
1381
|
this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
|
1377
1382
|
});
|
|
1378
|
-
const addGetterSetter = Factory.addGetterSetter;
|
|
1383
|
+
const addGetterSetter = Factory_1.Factory.addGetterSetter;
|
|
1379
1384
|
addGetterSetter(Node, 'zIndex');
|
|
1380
1385
|
addGetterSetter(Node, 'absolutePosition');
|
|
1381
1386
|
addGetterSetter(Node, 'position');
|
|
1382
|
-
addGetterSetter(Node, 'x', 0, getNumberValidator());
|
|
1383
|
-
addGetterSetter(Node, 'y', 0, getNumberValidator());
|
|
1384
|
-
addGetterSetter(Node, 'globalCompositeOperation', 'source-over', getStringValidator());
|
|
1385
|
-
addGetterSetter(Node, 'opacity', 1, getNumberValidator());
|
|
1386
|
-
addGetterSetter(Node, 'name', '', getStringValidator());
|
|
1387
|
-
addGetterSetter(Node, 'id', '', getStringValidator());
|
|
1388
|
-
addGetterSetter(Node, 'rotation', 0, getNumberValidator());
|
|
1389
|
-
Factory.addComponentsGetterSetter(Node, 'scale', ['x', 'y']);
|
|
1390
|
-
addGetterSetter(Node, 'scaleX', 1, getNumberValidator());
|
|
1391
|
-
addGetterSetter(Node, 'scaleY', 1, getNumberValidator());
|
|
1392
|
-
Factory.addComponentsGetterSetter(Node, 'skew', ['x', 'y']);
|
|
1393
|
-
addGetterSetter(Node, 'skewX', 0, getNumberValidator());
|
|
1394
|
-
addGetterSetter(Node, 'skewY', 0, getNumberValidator());
|
|
1395
|
-
Factory.addComponentsGetterSetter(Node, 'offset', ['x', 'y']);
|
|
1396
|
-
addGetterSetter(Node, 'offsetX', 0, getNumberValidator());
|
|
1397
|
-
addGetterSetter(Node, 'offsetY', 0, getNumberValidator());
|
|
1398
|
-
addGetterSetter(Node, 'dragDistance', null, getNumberValidator());
|
|
1399
|
-
addGetterSetter(Node, 'width', 0, getNumberValidator());
|
|
1400
|
-
addGetterSetter(Node, 'height', 0, getNumberValidator());
|
|
1401
|
-
addGetterSetter(Node, 'listening', true, getBooleanValidator());
|
|
1402
|
-
addGetterSetter(Node, 'preventDefault', true, getBooleanValidator());
|
|
1387
|
+
addGetterSetter(Node, 'x', 0, (0, Validators_1.getNumberValidator)());
|
|
1388
|
+
addGetterSetter(Node, 'y', 0, (0, Validators_1.getNumberValidator)());
|
|
1389
|
+
addGetterSetter(Node, 'globalCompositeOperation', 'source-over', (0, Validators_1.getStringValidator)());
|
|
1390
|
+
addGetterSetter(Node, 'opacity', 1, (0, Validators_1.getNumberValidator)());
|
|
1391
|
+
addGetterSetter(Node, 'name', '', (0, Validators_1.getStringValidator)());
|
|
1392
|
+
addGetterSetter(Node, 'id', '', (0, Validators_1.getStringValidator)());
|
|
1393
|
+
addGetterSetter(Node, 'rotation', 0, (0, Validators_1.getNumberValidator)());
|
|
1394
|
+
Factory_1.Factory.addComponentsGetterSetter(Node, 'scale', ['x', 'y']);
|
|
1395
|
+
addGetterSetter(Node, 'scaleX', 1, (0, Validators_1.getNumberValidator)());
|
|
1396
|
+
addGetterSetter(Node, 'scaleY', 1, (0, Validators_1.getNumberValidator)());
|
|
1397
|
+
Factory_1.Factory.addComponentsGetterSetter(Node, 'skew', ['x', 'y']);
|
|
1398
|
+
addGetterSetter(Node, 'skewX', 0, (0, Validators_1.getNumberValidator)());
|
|
1399
|
+
addGetterSetter(Node, 'skewY', 0, (0, Validators_1.getNumberValidator)());
|
|
1400
|
+
Factory_1.Factory.addComponentsGetterSetter(Node, 'offset', ['x', 'y']);
|
|
1401
|
+
addGetterSetter(Node, 'offsetX', 0, (0, Validators_1.getNumberValidator)());
|
|
1402
|
+
addGetterSetter(Node, 'offsetY', 0, (0, Validators_1.getNumberValidator)());
|
|
1403
|
+
addGetterSetter(Node, 'dragDistance', null, (0, Validators_1.getNumberValidator)());
|
|
1404
|
+
addGetterSetter(Node, 'width', 0, (0, Validators_1.getNumberValidator)());
|
|
1405
|
+
addGetterSetter(Node, 'height', 0, (0, Validators_1.getNumberValidator)());
|
|
1406
|
+
addGetterSetter(Node, 'listening', true, (0, Validators_1.getBooleanValidator)());
|
|
1407
|
+
addGetterSetter(Node, 'preventDefault', true, (0, Validators_1.getBooleanValidator)());
|
|
1403
1408
|
addGetterSetter(Node, 'filters', null, function (val) {
|
|
1404
1409
|
this._filterUpToDate = false;
|
|
1405
1410
|
return val;
|
|
1406
1411
|
});
|
|
1407
|
-
addGetterSetter(Node, 'visible', true, getBooleanValidator());
|
|
1408
|
-
addGetterSetter(Node, 'transformsEnabled', 'all', getStringValidator());
|
|
1412
|
+
addGetterSetter(Node, 'visible', true, (0, Validators_1.getBooleanValidator)());
|
|
1413
|
+
addGetterSetter(Node, 'transformsEnabled', 'all', (0, Validators_1.getStringValidator)());
|
|
1409
1414
|
addGetterSetter(Node, 'size');
|
|
1410
1415
|
addGetterSetter(Node, 'dragBoundFunc');
|
|
1411
|
-
addGetterSetter(Node, 'draggable', false, getBooleanValidator());
|
|
1412
|
-
Factory.backCompat(Node, {
|
|
1416
|
+
addGetterSetter(Node, 'draggable', false, (0, Validators_1.getBooleanValidator)());
|
|
1417
|
+
Factory_1.Factory.backCompat(Node, {
|
|
1413
1418
|
rotateDeg: 'rotate',
|
|
1414
1419
|
setRotationDeg: 'setRotation',
|
|
1415
1420
|
getRotationDeg: 'getRotation',
|
package/lib/PointerEvents.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseCapture = exports.setPointerCapture = exports.hasPointerCapture = exports.createEvent = exports.getCapturedShape = void 0;
|
|
4
|
+
const Global_1 = require("./Global");
|
|
2
5
|
const Captures = new Map();
|
|
3
|
-
const SUPPORT_POINTER_EVENTS = Konva._global['PointerEvent'] !== undefined;
|
|
4
|
-
|
|
6
|
+
const SUPPORT_POINTER_EVENTS = Global_1.Konva._global['PointerEvent'] !== undefined;
|
|
7
|
+
function getCapturedShape(pointerId) {
|
|
5
8
|
return Captures.get(pointerId);
|
|
6
9
|
}
|
|
7
|
-
|
|
10
|
+
exports.getCapturedShape = getCapturedShape;
|
|
11
|
+
function createEvent(evt) {
|
|
8
12
|
return {
|
|
9
13
|
evt,
|
|
10
14
|
pointerId: evt.pointerId,
|
|
11
15
|
};
|
|
12
16
|
}
|
|
13
|
-
|
|
17
|
+
exports.createEvent = createEvent;
|
|
18
|
+
function hasPointerCapture(pointerId, shape) {
|
|
14
19
|
return Captures.get(pointerId) === shape;
|
|
15
20
|
}
|
|
16
|
-
|
|
21
|
+
exports.hasPointerCapture = hasPointerCapture;
|
|
22
|
+
function setPointerCapture(pointerId, shape) {
|
|
17
23
|
releaseCapture(pointerId);
|
|
18
24
|
const stage = shape.getStage();
|
|
19
25
|
if (!stage)
|
|
@@ -23,7 +29,8 @@ export function setPointerCapture(pointerId, shape) {
|
|
|
23
29
|
shape._fire('gotpointercapture', createEvent(new PointerEvent('gotpointercapture')));
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
|
-
|
|
32
|
+
exports.setPointerCapture = setPointerCapture;
|
|
33
|
+
function releaseCapture(pointerId, target) {
|
|
27
34
|
const shape = Captures.get(pointerId);
|
|
28
35
|
if (!shape)
|
|
29
36
|
return;
|
|
@@ -35,3 +42,4 @@ export function releaseCapture(pointerId, target) {
|
|
|
35
42
|
shape._fire('lostpointercapture', createEvent(new PointerEvent('lostpointercapture')));
|
|
36
43
|
}
|
|
37
44
|
}
|
|
45
|
+
exports.releaseCapture = releaseCapture;
|