konva 9.3.21 → 10.0.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 -1
- package/konva.js +664 -226
- package/konva.min.js +46 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +7 -11
- package/lib/BezierFunctions.js +9 -15
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +14 -20
- package/lib/Container.d.ts +7 -6
- package/lib/Container.js +12 -16
- package/lib/Context.d.ts +7 -5
- package/lib/Context.js +34 -14
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +3 -7
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +24 -27
- package/lib/Factory.d.ts +2 -2
- package/lib/Factory.js +24 -27
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +6 -10
- package/lib/Global.d.ts +4 -3
- package/lib/Global.js +19 -19
- package/lib/Group.d.ts +4 -3
- package/lib/Group.js +6 -10
- package/lib/Layer.d.ts +10 -9
- package/lib/Layer.js +33 -37
- package/lib/Node.d.ts +16 -13
- package/lib/Node.js +207 -123
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +7 -14
- package/lib/Shape.d.ts +7 -4
- package/lib/Shape.js +91 -91
- package/lib/Stage.d.ts +8 -7
- package/lib/Stage.js +66 -56
- package/lib/Tween.d.ts +3 -2
- package/lib/Tween.js +29 -31
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +98 -38
- package/lib/Validators.js +44 -57
- package/lib/_CoreInternals.d.ts +49 -23
- package/lib/_CoreInternals.js +33 -36
- package/lib/_FullInternals.d.ts +126 -62
- package/lib/_FullInternals.js +77 -78
- package/lib/canvas-backend.d.ts +2 -0
- package/lib/canvas-backend.js +27 -0
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +5 -9
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +5 -9
- package/lib/filters/Brightness.d.ts +2 -0
- package/lib/filters/Brightness.js +8 -0
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +5 -9
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +95 -101
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +5 -9
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +1 -5
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +7 -11
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +7 -11
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +1 -5
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +9 -13
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +16 -10
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +5 -9
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +7 -11
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +5 -9
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +7 -11
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +8 -12
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +1 -5
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +13 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +5 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -4
- package/lib/shapes/Arc.d.ts +4 -3
- package/lib/shapes/Arc.js +13 -17
- package/lib/shapes/Arrow.d.ts +4 -3
- package/lib/shapes/Arrow.js +13 -17
- package/lib/shapes/Circle.d.ts +4 -3
- package/lib/shapes/Circle.js +7 -11
- package/lib/shapes/Ellipse.d.ts +4 -3
- package/lib/shapes/Ellipse.js +9 -13
- package/lib/shapes/Image.d.ts +4 -3
- package/lib/shapes/Image.js +17 -21
- package/lib/shapes/Label.d.ts +7 -6
- package/lib/shapes/Label.js +13 -18
- package/lib/shapes/Line.d.ts +4 -3
- package/lib/shapes/Line.js +10 -14
- package/lib/shapes/Path.d.ts +3 -2
- package/lib/shapes/Path.js +83 -23
- package/lib/shapes/Rect.d.ts +4 -3
- package/lib/shapes/Rect.js +9 -13
- package/lib/shapes/RegularPolygon.d.ts +6 -3
- package/lib/shapes/RegularPolygon.js +19 -16
- package/lib/shapes/Ring.d.ts +4 -3
- package/lib/shapes/Ring.js +8 -12
- package/lib/shapes/Sprite.d.ts +5 -4
- package/lib/shapes/Sprite.js +15 -19
- package/lib/shapes/Star.d.ts +4 -3
- package/lib/shapes/Star.js +9 -13
- package/lib/shapes/Text.d.ts +16 -3
- package/lib/shapes/Text.js +73 -53
- package/lib/shapes/TextPath.d.ts +5 -4
- package/lib/shapes/TextPath.js +48 -41
- package/lib/shapes/Transformer.d.ts +8 -8
- package/lib/shapes/Transformer.js +90 -90
- package/lib/shapes/Wedge.d.ts +4 -3
- package/lib/shapes/Wedge.js +12 -16
- package/lib/skia-backend.d.ts +2 -0
- package/lib/skia-backend.js +24 -0
- package/lib/types.d.ts +22 -22
- package/lib/types.js +21 -25
- package/package.json +53 -25
- package/lib/index-node.d.ts +0 -2
- package/lib/index-node.js +0 -21
- package/lib/index-types.d.ts +0 -181
package/lib/Util.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Konva } from "./Global.js";
|
|
2
|
+
const NODE_ERROR = `Konva.js unsupported environment.
|
|
3
|
+
|
|
4
|
+
Looks like you are trying to use Konva.js in Node.js environment. because "document" object is undefined.
|
|
5
|
+
|
|
6
|
+
To use Konva.js in Node.js environment, you need to use the "canvas-backend" or "skia-backend" module.
|
|
7
|
+
|
|
8
|
+
bash: npm install canvas
|
|
9
|
+
js: import "konva/canvas-backend";
|
|
10
|
+
|
|
11
|
+
or
|
|
12
|
+
|
|
13
|
+
bash: npm install skia-canvas
|
|
14
|
+
js: import "konva/skia-backend";
|
|
15
|
+
`;
|
|
16
|
+
const ensureBrowser = () => {
|
|
17
|
+
if (typeof document === 'undefined') {
|
|
18
|
+
throw new Error(NODE_ERROR);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export class Transform {
|
|
6
22
|
constructor(m = [1, 0, 0, 1, 0, 0]) {
|
|
7
23
|
this.dirty = false;
|
|
8
24
|
this.m = (m && m.slice()) || [1, 0, 0, 1, 0, 0];
|
|
@@ -145,11 +161,10 @@ class Transform {
|
|
|
145
161
|
}
|
|
146
162
|
else {
|
|
147
163
|
}
|
|
148
|
-
result.rotation =
|
|
164
|
+
result.rotation = Util._getRotation(result.rotation);
|
|
149
165
|
return result;
|
|
150
166
|
}
|
|
151
167
|
}
|
|
152
|
-
exports.Transform = Transform;
|
|
153
168
|
const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH = '#', EMPTY_STRING = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = {
|
|
154
169
|
aliceblue: [240, 248, 255],
|
|
155
170
|
antiquewhite: [250, 235, 215],
|
|
@@ -306,7 +321,7 @@ const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFra
|
|
|
306
321
|
function (f) {
|
|
307
322
|
setTimeout(f, 60);
|
|
308
323
|
};
|
|
309
|
-
|
|
324
|
+
export const Util = {
|
|
310
325
|
_isElement(obj) {
|
|
311
326
|
return !!(obj && obj.nodeType == 1);
|
|
312
327
|
},
|
|
@@ -366,6 +381,7 @@ exports.Util = {
|
|
|
366
381
|
}
|
|
367
382
|
},
|
|
368
383
|
createCanvasElement() {
|
|
384
|
+
ensureBrowser();
|
|
369
385
|
const canvas = document.createElement('canvas');
|
|
370
386
|
try {
|
|
371
387
|
canvas.style = canvas.style || {};
|
|
@@ -374,6 +390,7 @@ exports.Util = {
|
|
|
374
390
|
return canvas;
|
|
375
391
|
},
|
|
376
392
|
createImageElement() {
|
|
393
|
+
ensureBrowser();
|
|
377
394
|
return document.createElement('img');
|
|
378
395
|
},
|
|
379
396
|
_isInDocument(el) {
|
|
@@ -385,7 +402,7 @@ exports.Util = {
|
|
|
385
402
|
return false;
|
|
386
403
|
},
|
|
387
404
|
_urlToImage(url, callback) {
|
|
388
|
-
const imageObj =
|
|
405
|
+
const imageObj = Util.createImageElement();
|
|
389
406
|
imageObj.onload = function () {
|
|
390
407
|
callback(imageObj);
|
|
391
408
|
};
|
|
@@ -441,14 +458,14 @@ exports.Util = {
|
|
|
441
458
|
},
|
|
442
459
|
colorToRGBA(str) {
|
|
443
460
|
str = str || 'black';
|
|
444
|
-
return (
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
461
|
+
return (Util._namedColorToRBA(str) ||
|
|
462
|
+
Util._hex3ColorToRGBA(str) ||
|
|
463
|
+
Util._hex4ColorToRGBA(str) ||
|
|
464
|
+
Util._hex6ColorToRGBA(str) ||
|
|
465
|
+
Util._hex8ColorToRGBA(str) ||
|
|
466
|
+
Util._rgbColorToRGBA(str) ||
|
|
467
|
+
Util._rgbaColorToRGBA(str) ||
|
|
468
|
+
Util._hslColorToRGBA(str));
|
|
452
469
|
},
|
|
453
470
|
_namedColorToRBA(str) {
|
|
454
471
|
const c = COLORS[str.toLowerCase()];
|
|
@@ -618,15 +635,15 @@ exports.Util = {
|
|
|
618
635
|
return rad * DEG180_OVER_PI;
|
|
619
636
|
},
|
|
620
637
|
_degToRad(deg) {
|
|
621
|
-
|
|
622
|
-
return
|
|
638
|
+
Util.warn('Util._degToRad is removed. Please use public Util.degToRad instead.');
|
|
639
|
+
return Util.degToRad(deg);
|
|
623
640
|
},
|
|
624
641
|
_radToDeg(rad) {
|
|
625
|
-
|
|
626
|
-
return
|
|
642
|
+
Util.warn('Util._radToDeg is removed. Please use public Util.radToDeg instead.');
|
|
643
|
+
return Util.radToDeg(rad);
|
|
627
644
|
},
|
|
628
645
|
_getRotation(radians) {
|
|
629
|
-
return
|
|
646
|
+
return Konva.angleDeg ? Util.radToDeg(radians) : radians;
|
|
630
647
|
},
|
|
631
648
|
_capitalize(str) {
|
|
632
649
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -638,7 +655,7 @@ exports.Util = {
|
|
|
638
655
|
console.error(KONVA_ERROR + str);
|
|
639
656
|
},
|
|
640
657
|
warn(str) {
|
|
641
|
-
if (!
|
|
658
|
+
if (!Konva.showWarnings) {
|
|
642
659
|
return;
|
|
643
660
|
}
|
|
644
661
|
console.warn(KONVA_WARNING + str);
|
|
@@ -680,14 +697,14 @@ exports.Util = {
|
|
|
680
697
|
return [x, y, dist];
|
|
681
698
|
},
|
|
682
699
|
_getProjectionToLine(pt, line, isClosed) {
|
|
683
|
-
const pc =
|
|
700
|
+
const pc = Util.cloneObject(pt);
|
|
684
701
|
let dist = Number.MAX_VALUE;
|
|
685
702
|
line.forEach(function (p1, i) {
|
|
686
703
|
if (!isClosed && i === line.length - 1) {
|
|
687
704
|
return;
|
|
688
705
|
}
|
|
689
706
|
const p2 = line[(i + 1) % line.length];
|
|
690
|
-
const proj =
|
|
707
|
+
const proj = Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y);
|
|
691
708
|
const px = proj[0], py = proj[1], pdist = proj[2];
|
|
692
709
|
if (pdist < dist) {
|
|
693
710
|
pc.x = px;
|
|
@@ -718,7 +735,7 @@ exports.Util = {
|
|
|
718
735
|
}
|
|
719
736
|
const newStart = [];
|
|
720
737
|
end.forEach(function (point) {
|
|
721
|
-
const pr =
|
|
738
|
+
const pr = Util._getProjectionToLine(point, start, isClosed);
|
|
722
739
|
newStart.push(pr.x);
|
|
723
740
|
newStart.push(pr.y);
|
|
724
741
|
});
|
|
@@ -733,7 +750,7 @@ exports.Util = {
|
|
|
733
750
|
}
|
|
734
751
|
desc = Object.getOwnPropertyDescriptor(obj, key);
|
|
735
752
|
if (obj[key].visitedByCircularReferenceRemoval ||
|
|
736
|
-
|
|
753
|
+
Util._isElement(obj[key])) {
|
|
737
754
|
if (desc.configurable) {
|
|
738
755
|
delete obj[key];
|
|
739
756
|
}
|
|
@@ -741,7 +758,7 @@ exports.Util = {
|
|
|
741
758
|
return null;
|
|
742
759
|
}
|
|
743
760
|
}
|
|
744
|
-
else if (
|
|
761
|
+
else if (Util._prepareToStringify(obj[key]) === null) {
|
|
745
762
|
if (desc.configurable) {
|
|
746
763
|
delete obj[key];
|
|
747
764
|
}
|
|
@@ -768,7 +785,7 @@ exports.Util = {
|
|
|
768
785
|
}
|
|
769
786
|
},
|
|
770
787
|
releaseCanvas(...canvases) {
|
|
771
|
-
if (!
|
|
788
|
+
if (!Konva.releaseCanvasOnDestroy)
|
|
772
789
|
return;
|
|
773
790
|
canvases.forEach((c) => {
|
|
774
791
|
c.width = 0;
|
|
@@ -776,6 +793,10 @@ exports.Util = {
|
|
|
776
793
|
});
|
|
777
794
|
},
|
|
778
795
|
drawRoundedRectPath(context, width, height, cornerRadius) {
|
|
796
|
+
let xOrigin = width < 0 ? width : 0;
|
|
797
|
+
let yOrigin = height < 0 ? height : 0;
|
|
798
|
+
width = Math.abs(width);
|
|
799
|
+
height = Math.abs(height);
|
|
779
800
|
let topLeft = 0;
|
|
780
801
|
let topRight = 0;
|
|
781
802
|
let bottomLeft = 0;
|
|
@@ -793,14 +814,53 @@ exports.Util = {
|
|
|
793
814
|
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
|
794
815
|
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
|
795
816
|
}
|
|
796
|
-
context.moveTo(topLeft,
|
|
797
|
-
context.lineTo(width - topRight,
|
|
798
|
-
context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
799
|
-
context.lineTo(width, height - bottomRight);
|
|
800
|
-
context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
801
|
-
context.lineTo(bottomLeft, height);
|
|
802
|
-
context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
803
|
-
context.lineTo(
|
|
804
|
-
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
817
|
+
context.moveTo(xOrigin + topLeft, yOrigin);
|
|
818
|
+
context.lineTo(xOrigin + width - topRight, yOrigin);
|
|
819
|
+
context.arc(xOrigin + width - topRight, yOrigin + topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
820
|
+
context.lineTo(xOrigin + width, yOrigin + height - bottomRight);
|
|
821
|
+
context.arc(xOrigin + width - bottomRight, yOrigin + height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
822
|
+
context.lineTo(xOrigin + bottomLeft, yOrigin + height);
|
|
823
|
+
context.arc(xOrigin + bottomLeft, yOrigin + height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
824
|
+
context.lineTo(xOrigin, yOrigin + topLeft);
|
|
825
|
+
context.arc(xOrigin + topLeft, yOrigin + topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
826
|
+
},
|
|
827
|
+
drawRoundedPolygonPath(context, points, sides, radius, cornerRadius) {
|
|
828
|
+
radius = Math.abs(radius);
|
|
829
|
+
for (let i = 0; i < sides; i++) {
|
|
830
|
+
const prev = points[(i - 1 + sides) % sides];
|
|
831
|
+
const curr = points[i];
|
|
832
|
+
const next = points[(i + 1) % sides];
|
|
833
|
+
const vec1 = { x: curr.x - prev.x, y: curr.y - prev.y };
|
|
834
|
+
const vec2 = { x: next.x - curr.x, y: next.y - curr.y };
|
|
835
|
+
const len1 = Math.hypot(vec1.x, vec1.y);
|
|
836
|
+
const len2 = Math.hypot(vec2.x, vec2.y);
|
|
837
|
+
let currCornerRadius;
|
|
838
|
+
if (typeof cornerRadius === 'number') {
|
|
839
|
+
currCornerRadius = cornerRadius;
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
currCornerRadius = i < cornerRadius.length ? cornerRadius[i] : 0;
|
|
843
|
+
}
|
|
844
|
+
const maxCornerRadius = radius * Math.cos(Math.PI / sides);
|
|
845
|
+
currCornerRadius =
|
|
846
|
+
maxCornerRadius * Math.min(1, (currCornerRadius / radius) * 2);
|
|
847
|
+
const normalVec1 = { x: vec1.x / len1, y: vec1.y / len1 };
|
|
848
|
+
const normalVec2 = { x: vec2.x / len2, y: vec2.y / len2 };
|
|
849
|
+
const p1 = {
|
|
850
|
+
x: curr.x - normalVec1.x * currCornerRadius,
|
|
851
|
+
y: curr.y - normalVec1.y * currCornerRadius,
|
|
852
|
+
};
|
|
853
|
+
const p2 = {
|
|
854
|
+
x: curr.x + normalVec2.x * currCornerRadius,
|
|
855
|
+
y: curr.y + normalVec2.y * currCornerRadius,
|
|
856
|
+
};
|
|
857
|
+
if (i === 0) {
|
|
858
|
+
context.moveTo(p1.x, p1.y);
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
context.lineTo(p1.x, p1.y);
|
|
862
|
+
}
|
|
863
|
+
context.arcTo(curr.x, curr.y, p2.x, p2.y, currCornerRadius);
|
|
864
|
+
}
|
|
805
865
|
},
|
|
806
866
|
};
|
package/lib/Validators.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.RGBComponent = RGBComponent;
|
|
4
|
-
exports.alphaComponent = alphaComponent;
|
|
5
|
-
exports.getNumberValidator = getNumberValidator;
|
|
6
|
-
exports.getNumberOrArrayOfNumbersValidator = getNumberOrArrayOfNumbersValidator;
|
|
7
|
-
exports.getNumberOrAutoValidator = getNumberOrAutoValidator;
|
|
8
|
-
exports.getStringValidator = getStringValidator;
|
|
9
|
-
exports.getStringOrGradientValidator = getStringOrGradientValidator;
|
|
10
|
-
exports.getFunctionValidator = getFunctionValidator;
|
|
11
|
-
exports.getNumberArrayValidator = getNumberArrayValidator;
|
|
12
|
-
exports.getBooleanValidator = getBooleanValidator;
|
|
13
|
-
exports.getComponentValidator = getComponentValidator;
|
|
14
|
-
const Global_1 = require("./Global");
|
|
15
|
-
const Util_1 = require("./Util");
|
|
1
|
+
import { Konva } from "./Global.js";
|
|
2
|
+
import { Util } from "./Util.js";
|
|
16
3
|
function _formatValue(val) {
|
|
17
|
-
if (
|
|
4
|
+
if (Util._isString(val)) {
|
|
18
5
|
return '"' + val + '"';
|
|
19
6
|
}
|
|
20
7
|
if (Object.prototype.toString.call(val) === '[object Number]') {
|
|
21
8
|
return val;
|
|
22
9
|
}
|
|
23
|
-
if (
|
|
10
|
+
if (Util._isBoolean(val)) {
|
|
24
11
|
return val;
|
|
25
12
|
}
|
|
26
13
|
return Object.prototype.toString.call(val);
|
|
27
14
|
}
|
|
28
|
-
function RGBComponent(val) {
|
|
15
|
+
export function RGBComponent(val) {
|
|
29
16
|
if (val > 255) {
|
|
30
17
|
return 255;
|
|
31
18
|
}
|
|
@@ -34,7 +21,7 @@ function RGBComponent(val) {
|
|
|
34
21
|
}
|
|
35
22
|
return Math.round(val);
|
|
36
23
|
}
|
|
37
|
-
function alphaComponent(val) {
|
|
24
|
+
export function alphaComponent(val) {
|
|
38
25
|
if (val > 1) {
|
|
39
26
|
return 1;
|
|
40
27
|
}
|
|
@@ -43,11 +30,11 @@ function alphaComponent(val) {
|
|
|
43
30
|
}
|
|
44
31
|
return val;
|
|
45
32
|
}
|
|
46
|
-
function getNumberValidator() {
|
|
47
|
-
if (
|
|
33
|
+
export function getNumberValidator() {
|
|
34
|
+
if (Konva.isUnminified) {
|
|
48
35
|
return function (val, attr) {
|
|
49
|
-
if (!
|
|
50
|
-
|
|
36
|
+
if (!Util._isNumber(val)) {
|
|
37
|
+
Util.warn(_formatValue(val) +
|
|
51
38
|
' is a not valid value for "' +
|
|
52
39
|
attr +
|
|
53
40
|
'" attribute. The value should be a number.');
|
|
@@ -56,13 +43,13 @@ function getNumberValidator() {
|
|
|
56
43
|
};
|
|
57
44
|
}
|
|
58
45
|
}
|
|
59
|
-
function getNumberOrArrayOfNumbersValidator(noOfElements) {
|
|
60
|
-
if (
|
|
46
|
+
export function getNumberOrArrayOfNumbersValidator(noOfElements) {
|
|
47
|
+
if (Konva.isUnminified) {
|
|
61
48
|
return function (val, attr) {
|
|
62
|
-
let isNumber =
|
|
63
|
-
let isValidArray =
|
|
49
|
+
let isNumber = Util._isNumber(val);
|
|
50
|
+
let isValidArray = Util._isArray(val) && val.length == noOfElements;
|
|
64
51
|
if (!isNumber && !isValidArray) {
|
|
65
|
-
|
|
52
|
+
Util.warn(_formatValue(val) +
|
|
66
53
|
' is a not valid value for "' +
|
|
67
54
|
attr +
|
|
68
55
|
'" attribute. The value should be a number or Array<number>(' +
|
|
@@ -73,13 +60,13 @@ function getNumberOrArrayOfNumbersValidator(noOfElements) {
|
|
|
73
60
|
};
|
|
74
61
|
}
|
|
75
62
|
}
|
|
76
|
-
function getNumberOrAutoValidator() {
|
|
77
|
-
if (
|
|
63
|
+
export function getNumberOrAutoValidator() {
|
|
64
|
+
if (Konva.isUnminified) {
|
|
78
65
|
return function (val, attr) {
|
|
79
|
-
const isNumber =
|
|
66
|
+
const isNumber = Util._isNumber(val);
|
|
80
67
|
const isAuto = val === 'auto';
|
|
81
68
|
if (!(isNumber || isAuto)) {
|
|
82
|
-
|
|
69
|
+
Util.warn(_formatValue(val) +
|
|
83
70
|
' is a not valid value for "' +
|
|
84
71
|
attr +
|
|
85
72
|
'" attribute. The value should be a number or "auto".');
|
|
@@ -88,11 +75,11 @@ function getNumberOrAutoValidator() {
|
|
|
88
75
|
};
|
|
89
76
|
}
|
|
90
77
|
}
|
|
91
|
-
function getStringValidator() {
|
|
92
|
-
if (
|
|
78
|
+
export function getStringValidator() {
|
|
79
|
+
if (Konva.isUnminified) {
|
|
93
80
|
return function (val, attr) {
|
|
94
|
-
if (!
|
|
95
|
-
|
|
81
|
+
if (!Util._isString(val)) {
|
|
82
|
+
Util.warn(_formatValue(val) +
|
|
96
83
|
' is a not valid value for "' +
|
|
97
84
|
attr +
|
|
98
85
|
'" attribute. The value should be a string.');
|
|
@@ -101,14 +88,14 @@ function getStringValidator() {
|
|
|
101
88
|
};
|
|
102
89
|
}
|
|
103
90
|
}
|
|
104
|
-
function getStringOrGradientValidator() {
|
|
105
|
-
if (
|
|
91
|
+
export function getStringOrGradientValidator() {
|
|
92
|
+
if (Konva.isUnminified) {
|
|
106
93
|
return function (val, attr) {
|
|
107
|
-
const isString =
|
|
94
|
+
const isString = Util._isString(val);
|
|
108
95
|
const isGradient = Object.prototype.toString.call(val) === '[object CanvasGradient]' ||
|
|
109
96
|
(val && val['addColorStop']);
|
|
110
97
|
if (!(isString || isGradient)) {
|
|
111
|
-
|
|
98
|
+
Util.warn(_formatValue(val) +
|
|
112
99
|
' is a not valid value for "' +
|
|
113
100
|
attr +
|
|
114
101
|
'" attribute. The value should be a string or a native gradient.');
|
|
@@ -117,11 +104,11 @@ function getStringOrGradientValidator() {
|
|
|
117
104
|
};
|
|
118
105
|
}
|
|
119
106
|
}
|
|
120
|
-
function getFunctionValidator() {
|
|
121
|
-
if (
|
|
107
|
+
export function getFunctionValidator() {
|
|
108
|
+
if (Konva.isUnminified) {
|
|
122
109
|
return function (val, attr) {
|
|
123
|
-
if (!
|
|
124
|
-
|
|
110
|
+
if (!Util._isFunction(val)) {
|
|
111
|
+
Util.warn(_formatValue(val) +
|
|
125
112
|
' is a not valid value for "' +
|
|
126
113
|
attr +
|
|
127
114
|
'" attribute. The value should be a function.');
|
|
@@ -130,23 +117,23 @@ function getFunctionValidator() {
|
|
|
130
117
|
};
|
|
131
118
|
}
|
|
132
119
|
}
|
|
133
|
-
function getNumberArrayValidator() {
|
|
134
|
-
if (
|
|
120
|
+
export function getNumberArrayValidator() {
|
|
121
|
+
if (Konva.isUnminified) {
|
|
135
122
|
return function (val, attr) {
|
|
136
123
|
const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
|
|
137
124
|
if (TypedArray && val instanceof TypedArray) {
|
|
138
125
|
return val;
|
|
139
126
|
}
|
|
140
|
-
if (!
|
|
141
|
-
|
|
127
|
+
if (!Util._isArray(val)) {
|
|
128
|
+
Util.warn(_formatValue(val) +
|
|
142
129
|
' is a not valid value for "' +
|
|
143
130
|
attr +
|
|
144
131
|
'" attribute. The value should be a array of numbers.');
|
|
145
132
|
}
|
|
146
133
|
else {
|
|
147
134
|
val.forEach(function (item) {
|
|
148
|
-
if (!
|
|
149
|
-
|
|
135
|
+
if (!Util._isNumber(item)) {
|
|
136
|
+
Util.warn('"' +
|
|
150
137
|
attr +
|
|
151
138
|
'" attribute has non numeric element ' +
|
|
152
139
|
item +
|
|
@@ -158,12 +145,12 @@ function getNumberArrayValidator() {
|
|
|
158
145
|
};
|
|
159
146
|
}
|
|
160
147
|
}
|
|
161
|
-
function getBooleanValidator() {
|
|
162
|
-
if (
|
|
148
|
+
export function getBooleanValidator() {
|
|
149
|
+
if (Konva.isUnminified) {
|
|
163
150
|
return function (val, attr) {
|
|
164
151
|
const isBool = val === true || val === false;
|
|
165
152
|
if (!isBool) {
|
|
166
|
-
|
|
153
|
+
Util.warn(_formatValue(val) +
|
|
167
154
|
' is a not valid value for "' +
|
|
168
155
|
attr +
|
|
169
156
|
'" attribute. The value should be a boolean.');
|
|
@@ -172,14 +159,14 @@ function getBooleanValidator() {
|
|
|
172
159
|
};
|
|
173
160
|
}
|
|
174
161
|
}
|
|
175
|
-
function getComponentValidator(components) {
|
|
176
|
-
if (
|
|
162
|
+
export function getComponentValidator(components) {
|
|
163
|
+
if (Konva.isUnminified) {
|
|
177
164
|
return function (val, attr) {
|
|
178
165
|
if (val === undefined || val === null) {
|
|
179
166
|
return val;
|
|
180
167
|
}
|
|
181
|
-
if (!
|
|
182
|
-
|
|
168
|
+
if (!Util.isObject(val)) {
|
|
169
|
+
Util.warn(_formatValue(val) +
|
|
183
170
|
' is a not valid value for "' +
|
|
184
171
|
attr +
|
|
185
172
|
'" attribute. The value should be an object with properties ' +
|
package/lib/_CoreInternals.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Transform } from './Util.
|
|
2
|
-
import { Node } from './Node.
|
|
3
|
-
import { Container } from './Container.
|
|
4
|
-
import { Stage } from './Stage.
|
|
5
|
-
import { Layer } from './Layer.
|
|
6
|
-
import { FastLayer } from './FastLayer.
|
|
7
|
-
import { Group } from './Group.
|
|
8
|
-
import { Shape } from './Shape.
|
|
9
|
-
import { Animation } from './Animation.
|
|
10
|
-
import { Tween } from './Tween.
|
|
11
|
-
import { Context } from './Context.
|
|
12
|
-
import { Canvas } from './Canvas.
|
|
1
|
+
import { Transform } from './Util.ts';
|
|
2
|
+
import { Node } from './Node.ts';
|
|
3
|
+
import { Container } from './Container.ts';
|
|
4
|
+
import { Stage } from './Stage.ts';
|
|
5
|
+
import { Layer } from './Layer.ts';
|
|
6
|
+
import { FastLayer } from './FastLayer.ts';
|
|
7
|
+
import { Group } from './Group.ts';
|
|
8
|
+
import { Shape } from './Shape.ts';
|
|
9
|
+
import { Animation } from './Animation.ts';
|
|
10
|
+
import { Tween } from './Tween.ts';
|
|
11
|
+
import { Context } from './Context.ts';
|
|
12
|
+
import { Canvas } from './Canvas.ts';
|
|
13
13
|
export declare const Konva: {
|
|
14
14
|
_global: any;
|
|
15
15
|
version: string;
|
|
@@ -31,14 +31,15 @@ export declare const Konva: {
|
|
|
31
31
|
_mouseDblClickPointerId: null;
|
|
32
32
|
_touchDblClickPointerId: null;
|
|
33
33
|
_pointerDblClickPointerId: null;
|
|
34
|
-
|
|
34
|
+
_renderBackend: string;
|
|
35
|
+
legacyTextRendering: boolean;
|
|
35
36
|
pixelRatio: number;
|
|
36
37
|
dragDistance: number;
|
|
37
38
|
angleDeg: boolean;
|
|
38
39
|
showWarnings: boolean;
|
|
39
40
|
dragButtons: number[];
|
|
40
|
-
isDragging():
|
|
41
|
-
isTransforming():
|
|
41
|
+
isDragging(): boolean;
|
|
42
|
+
isTransforming(): boolean;
|
|
42
43
|
isDragReady(): boolean;
|
|
43
44
|
releaseCanvasOnDestroy: boolean;
|
|
44
45
|
document: any;
|
|
@@ -61,9 +62,9 @@ export declare const Konva: {
|
|
|
61
62
|
_isInDocument(el: any): boolean;
|
|
62
63
|
_urlToImage(url: string, callback: Function): void;
|
|
63
64
|
_rgbToHex(r: number, g: number, b: number): string;
|
|
64
|
-
_hexToRgb(hex: string): import("./types.
|
|
65
|
+
_hexToRgb(hex: string): import("./types.ts").RGB;
|
|
65
66
|
getRandomColor(): string;
|
|
66
|
-
getRGB(color: string): import("./types.
|
|
67
|
+
getRGB(color: string): import("./types.ts").RGB;
|
|
67
68
|
colorToRGBA(str: string): {
|
|
68
69
|
r: number;
|
|
69
70
|
g: number;
|
|
@@ -118,7 +119,7 @@ export declare const Konva: {
|
|
|
118
119
|
b: number;
|
|
119
120
|
a: number;
|
|
120
121
|
} | undefined;
|
|
121
|
-
haveIntersection(r1: import("./types").IRect, r2: import("./types.
|
|
122
|
+
haveIntersection(r1: import("./types.ts").IRect, r2: import("./types.ts").IRect): boolean;
|
|
122
123
|
cloneObject<Any>(obj: Any): Any;
|
|
123
124
|
cloneArray(arr: Array<any>): any[];
|
|
124
125
|
degToRad(deg: number): number;
|
|
@@ -133,13 +134,14 @@ export declare const Konva: {
|
|
|
133
134
|
each(obj: object, func: Function): void;
|
|
134
135
|
_inRange(val: number, left: number, right: number): boolean;
|
|
135
136
|
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
|
136
|
-
_getProjectionToLine(pt: import("./types").Vector2d, line: Array<import("./types").Vector2d>, isClosed: boolean): import("./types.
|
|
137
|
+
_getProjectionToLine(pt: import("./types.ts").Vector2d, line: Array<import("./types.ts").Vector2d>, isClosed: boolean): import("./types.ts").Vector2d;
|
|
137
138
|
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
|
|
138
139
|
_prepareToStringify<T>(obj: any): T | null;
|
|
139
140
|
_assign<T, U>(target: T, source: U): T & U;
|
|
140
141
|
_getFirstPointerId(evt: any): any;
|
|
141
142
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
142
143
|
drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
|
|
144
|
+
drawRoundedPolygonPath(context: Context, points: import("./types.ts").Vector2d[], sides: number, radius: number, cornerRadius: number | number[]): void;
|
|
143
145
|
};
|
|
144
146
|
Transform: typeof Transform;
|
|
145
147
|
Node: typeof Node;
|
|
@@ -152,11 +154,11 @@ export declare const Konva: {
|
|
|
152
154
|
DD: {
|
|
153
155
|
readonly isDragging: boolean;
|
|
154
156
|
justDragged: boolean;
|
|
155
|
-
readonly node: Node<import("./Node.
|
|
157
|
+
readonly node: Node<import("./Node.ts").NodeConfig> | undefined;
|
|
156
158
|
_dragElements: Map<number, {
|
|
157
159
|
node: Node;
|
|
158
|
-
startPointerPos: import("./types.
|
|
159
|
-
offset: import("./types.
|
|
160
|
+
startPointerPos: import("./types.ts").Vector2d;
|
|
161
|
+
offset: import("./types.ts").Vector2d;
|
|
160
162
|
pointerId?: number;
|
|
161
163
|
dragStatus: "ready" | "dragging" | "stopped";
|
|
162
164
|
}>;
|
|
@@ -166,7 +168,7 @@ export declare const Konva: {
|
|
|
166
168
|
};
|
|
167
169
|
Shape: typeof Shape;
|
|
168
170
|
shapes: {
|
|
169
|
-
[key: string]: Shape<import("./Shape.
|
|
171
|
+
[key: string]: Shape<import("./Shape.ts").ShapeConfig>;
|
|
170
172
|
};
|
|
171
173
|
Animation: typeof Animation;
|
|
172
174
|
Tween: typeof Tween;
|
|
@@ -191,4 +193,28 @@ export declare const Konva: {
|
|
|
191
193
|
Context: typeof Context;
|
|
192
194
|
Canvas: typeof Canvas;
|
|
193
195
|
};
|
|
196
|
+
export declare namespace Konva {
|
|
197
|
+
type Vector2d = import('./types.ts').Vector2d;
|
|
198
|
+
type Node = import('./Node.ts').Node;
|
|
199
|
+
type NodeConfig = import('./Node.ts').NodeConfig;
|
|
200
|
+
type KonvaEventObject<EventType> = import('./Node.ts').KonvaEventObject<EventType>;
|
|
201
|
+
type KonvaPointerEvent = import('./PointerEvents.ts').KonvaPointerEvent;
|
|
202
|
+
type KonvaEventListener<This, EventType> = import('./Node.ts').KonvaEventListener<This, EventType>;
|
|
203
|
+
type Container = import('./Container.ts').Container<Node>;
|
|
204
|
+
type ContainerConfig = import('./Container.ts').ContainerConfig;
|
|
205
|
+
type Transform = import('./Util.ts').Transform;
|
|
206
|
+
type Context = import('./Context.ts').Context;
|
|
207
|
+
type Stage = import('./Stage.ts').Stage;
|
|
208
|
+
type StageConfig = import('./Stage.ts').StageConfig;
|
|
209
|
+
type Layer = import('./Layer.ts').Layer;
|
|
210
|
+
type LayerConfig = import('./Layer.ts').LayerConfig;
|
|
211
|
+
type FastLayer = import('./FastLayer.ts').FastLayer;
|
|
212
|
+
type Group = import('./Group.ts').Group;
|
|
213
|
+
type GroupConfig = import('./Group.ts').GroupConfig;
|
|
214
|
+
type Shape = import('./Shape.ts').Shape;
|
|
215
|
+
type ShapeConfig = import('./Shape.ts').ShapeConfig;
|
|
216
|
+
type Animation = import('./Animation.ts').Animation;
|
|
217
|
+
type Tween = import('./Tween.ts').Tween;
|
|
218
|
+
type TweenConfig = import('./Tween.ts').TweenConfig;
|
|
219
|
+
}
|
|
194
220
|
export default Konva;
|
package/lib/_CoreInternals.js
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Easings: Tween_1.Easings,
|
|
34
|
-
Context: Context_1.Context,
|
|
35
|
-
Canvas: Canvas_1.Canvas,
|
|
1
|
+
import { Konva as Global } from "./Global.js";
|
|
2
|
+
import { Util, Transform } from "./Util.js";
|
|
3
|
+
import { Node } from "./Node.js";
|
|
4
|
+
import { Container } from "./Container.js";
|
|
5
|
+
import { Stage, stages } from "./Stage.js";
|
|
6
|
+
import { Layer } from "./Layer.js";
|
|
7
|
+
import { FastLayer } from "./FastLayer.js";
|
|
8
|
+
import { Group } from "./Group.js";
|
|
9
|
+
import { DD } from "./DragAndDrop.js";
|
|
10
|
+
import { Shape, shapes } from "./Shape.js";
|
|
11
|
+
import { Animation } from "./Animation.js";
|
|
12
|
+
import { Tween, Easings } from "./Tween.js";
|
|
13
|
+
import { Context } from "./Context.js";
|
|
14
|
+
import { Canvas } from "./Canvas.js";
|
|
15
|
+
export const Konva = Util._assign(Global, {
|
|
16
|
+
Util,
|
|
17
|
+
Transform,
|
|
18
|
+
Node,
|
|
19
|
+
Container,
|
|
20
|
+
Stage,
|
|
21
|
+
stages,
|
|
22
|
+
Layer,
|
|
23
|
+
FastLayer,
|
|
24
|
+
Group,
|
|
25
|
+
DD,
|
|
26
|
+
Shape,
|
|
27
|
+
shapes,
|
|
28
|
+
Animation,
|
|
29
|
+
Tween,
|
|
30
|
+
Easings,
|
|
31
|
+
Context,
|
|
32
|
+
Canvas,
|
|
36
33
|
});
|
|
37
|
-
|
|
34
|
+
export default Konva;
|