konva 10.2.5 → 10.3.1
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 +12 -6
- package/konva.js +763 -515
- package/konva.min.js +4 -4
- package/lib/BezierFunctions.d.ts +2 -0
- package/lib/BezierFunctions.js +46 -0
- package/lib/Container.js +20 -6
- package/lib/Context.js +6 -0
- package/lib/Factory.d.ts +1 -1
- package/lib/Global.js +1 -1
- package/lib/Node.d.ts +3 -0
- package/lib/Node.js +20 -4
- package/lib/Shape.js +1 -0
- package/lib/Tween.js +10 -4
- package/lib/Util.d.ts +0 -6
- package/lib/Util.js +113 -119
- package/lib/_CoreInternals.d.ts +0 -6
- package/lib/_FullInternals.d.ts +0 -6
- package/lib/shapes/Arc.js +11 -0
- package/lib/shapes/Line.d.ts +2 -0
- package/lib/shapes/Line.js +39 -59
- package/lib/shapes/Path.js +10 -6
- package/lib/shapes/Text.js +3 -4
- package/lib/shapes/TextPath.d.ts +2 -0
- package/lib/shapes/TextPath.js +5 -1
- package/lib/shapes/Transformer.d.ts +3 -0
- package/lib/shapes/Transformer.js +35 -5
- package/package.json +14 -2
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v10.
|
|
8
|
+
* Konva JavaScript Framework v10.3.1
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date: Fri
|
|
11
|
+
* Date: Fri Aug 14 2026
|
|
12
12
|
*
|
|
13
13
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
|
14
14
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
: {};
|
|
36
36
|
const Konva$2 = {
|
|
37
37
|
_global: glob,
|
|
38
|
-
version: '10.
|
|
38
|
+
version: '10.3.1',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -465,7 +465,7 @@ js: import "konva/skia-backend";
|
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
// CONSTANTS
|
|
468
|
-
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$1 = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ',
|
|
468
|
+
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$1 = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', COLORS = {
|
|
469
469
|
aliceblue: [240, 248, 255],
|
|
470
470
|
antiquewhite: [250, 235, 215],
|
|
471
471
|
aqua: [0, 255, 255],
|
|
@@ -489,7 +489,7 @@ js: import "konva/skia-backend";
|
|
|
489
489
|
cyan: [0, 255, 255],
|
|
490
490
|
darkblue: [0, 0, 139],
|
|
491
491
|
darkcyan: [0, 139, 139],
|
|
492
|
-
darkgoldenrod: [184,
|
|
492
|
+
darkgoldenrod: [184, 134, 11],
|
|
493
493
|
darkgray: [169, 169, 169],
|
|
494
494
|
darkgreen: [0, 100, 0],
|
|
495
495
|
darkgrey: [169, 169, 169],
|
|
@@ -512,7 +512,7 @@ js: import "konva/skia-backend";
|
|
|
512
512
|
dimgrey: [105, 105, 105],
|
|
513
513
|
dodgerblue: [30, 144, 255],
|
|
514
514
|
firebrick: [178, 34, 34],
|
|
515
|
-
floralwhite: [255,
|
|
515
|
+
floralwhite: [255, 250, 240],
|
|
516
516
|
forestgreen: [34, 139, 34],
|
|
517
517
|
fuchsia: [255, 0, 255],
|
|
518
518
|
gainsboro: [220, 220, 220],
|
|
@@ -582,7 +582,7 @@ js: import "konva/skia-backend";
|
|
|
582
582
|
peachpuff: [255, 218, 185],
|
|
583
583
|
peru: [205, 133, 63],
|
|
584
584
|
pink: [255, 192, 203],
|
|
585
|
-
plum: [221, 160,
|
|
585
|
+
plum: [221, 160, 221],
|
|
586
586
|
powderblue: [176, 224, 230],
|
|
587
587
|
purple: [128, 0, 128],
|
|
588
588
|
rebeccapurple: [102, 51, 153],
|
|
@@ -598,9 +598,9 @@ js: import "konva/skia-backend";
|
|
|
598
598
|
silver: [192, 192, 192],
|
|
599
599
|
skyblue: [135, 206, 235],
|
|
600
600
|
slateblue: [106, 90, 205],
|
|
601
|
-
slategray: [
|
|
602
|
-
slategrey: [
|
|
603
|
-
snow: [255,
|
|
601
|
+
slategray: [112, 128, 144],
|
|
602
|
+
slategrey: [112, 128, 144],
|
|
603
|
+
snow: [255, 250, 250],
|
|
604
604
|
springgreen: [0, 255, 127],
|
|
605
605
|
steelblue: [70, 130, 180],
|
|
606
606
|
tan: [210, 180, 140],
|
|
@@ -614,8 +614,8 @@ js: import "konva/skia-backend";
|
|
|
614
614
|
white: [255, 255, 255],
|
|
615
615
|
whitesmoke: [245, 245, 245],
|
|
616
616
|
yellow: [255, 255, 0],
|
|
617
|
-
yellowgreen: [154, 205,
|
|
618
|
-
}
|
|
617
|
+
yellowgreen: [154, 205, 50],
|
|
618
|
+
};
|
|
619
619
|
let animQueue = [];
|
|
620
620
|
// Cache for canvas farbling detection
|
|
621
621
|
let _isCanvasFarblingActive = null;
|
|
@@ -623,6 +623,46 @@ js: import "konva/skia-backend";
|
|
|
623
623
|
function (f) {
|
|
624
624
|
setTimeout(f, 16); // 60fps ≈ 16.67ms per frame
|
|
625
625
|
};
|
|
626
|
+
const capitalizeCache = new Map();
|
|
627
|
+
// Split the components of rgb()/hsl(). CSS separates them with commas (legacy
|
|
628
|
+
// syntax), or with spaces and a slash before the alpha (CSS Color 4 syntax),
|
|
629
|
+
// but never with both. Keep the two apart, so that a space inside a
|
|
630
|
+
// comma-separated color adds no component. A component the user left empty
|
|
631
|
+
// stays as "", which then fails the color.
|
|
632
|
+
const splitColorComponents = (str) => {
|
|
633
|
+
const components = str.trim();
|
|
634
|
+
return components.indexOf(',') === -1
|
|
635
|
+
? components.split(/\s*\/\s*|\s+/)
|
|
636
|
+
: components.split(/\s*,\s*/);
|
|
637
|
+
};
|
|
638
|
+
// A CSS number: "50", "-0.5", ".5", "1e2". Everything else, from "50abc" to
|
|
639
|
+
// "0x10" and "1.2.3", is not a number and makes the color fail.
|
|
640
|
+
const NUMBER_SOURCE = '[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?';
|
|
641
|
+
// A component is a number with an optional "%" sign.
|
|
642
|
+
const COLOR_COMPONENT_REGEX = new RegExp(`^(${NUMBER_SOURCE})(%?)$`, 'i');
|
|
643
|
+
// Parse one color component. 100% is `max`: 255 for the color channels of
|
|
644
|
+
// rgb(), 1 for the alpha, 100 for the saturation and the lightness of hsl().
|
|
645
|
+
const parseColorComponent = (value, max) => {
|
|
646
|
+
const match = COLOR_COMPONENT_REGEX.exec(value);
|
|
647
|
+
if (!match) {
|
|
648
|
+
return NaN;
|
|
649
|
+
}
|
|
650
|
+
return match[2] ? (Number(match[1]) / 100) * max : Number(match[1]);
|
|
651
|
+
};
|
|
652
|
+
// parseInt() stops at the first character it can not read, so "#0g0000" would
|
|
653
|
+
// give a valid black instead of failing. The hex parsers test the shape first.
|
|
654
|
+
const HEX_COLOR_REGEX = /^#[0-9a-f]+$/i;
|
|
655
|
+
// Keep a fraction in [0, 1]. NaN stays NaN, so a bad value still fails.
|
|
656
|
+
const clamp01 = (value) => Math.min(Math.max(value, 0), 1);
|
|
657
|
+
// The hue of hsl() is the same number, with a CSS Color 4 angle unit
|
|
658
|
+
// instead of the "%" sign. No unit means degrees.
|
|
659
|
+
const HUE_REGEX = new RegExp(`^(${NUMBER_SOURCE})(deg|grad|rad|turn)?$`, 'i');
|
|
660
|
+
const HUE_UNITS = {
|
|
661
|
+
deg: 1,
|
|
662
|
+
grad: 0.9,
|
|
663
|
+
rad: DEG180_OVER_PI,
|
|
664
|
+
turn: 360,
|
|
665
|
+
};
|
|
626
666
|
/**
|
|
627
667
|
* @namespace Util
|
|
628
668
|
* @memberof Konva
|
|
@@ -842,50 +882,29 @@ js: import "konva/skia-backend";
|
|
|
842
882
|
* var rgb = Konva.Util.getRGB('rgb(0,0,255)');
|
|
843
883
|
*/
|
|
844
884
|
getRGB(color) {
|
|
845
|
-
|
|
846
|
-
// color
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
return {
|
|
850
|
-
r: rgb[0],
|
|
851
|
-
g: rgb[1],
|
|
852
|
-
b: rgb[2],
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
else if (color[0] === HASH) {
|
|
856
|
-
// hex
|
|
857
|
-
return this._hexToRgb(color.substring(1));
|
|
858
|
-
}
|
|
859
|
-
else if (color.substr(0, 4) === RGB_PAREN) {
|
|
860
|
-
// rgb string
|
|
861
|
-
rgb = RGB_REGEX.exec(color.replace(/ /g, ''));
|
|
862
|
-
return {
|
|
863
|
-
r: parseInt(rgb[1], 10),
|
|
864
|
-
g: parseInt(rgb[2], 10),
|
|
865
|
-
b: parseInt(rgb[3], 10),
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
else {
|
|
869
|
-
// default
|
|
870
|
-
return {
|
|
871
|
-
r: 0,
|
|
872
|
-
g: 0,
|
|
873
|
-
b: 0,
|
|
874
|
-
};
|
|
875
|
-
}
|
|
885
|
+
var _a;
|
|
886
|
+
// black for a color we can not parse
|
|
887
|
+
const { r = 0, g = 0, b = 0 } = (_a = Util.colorToRGBA(color)) !== null && _a !== void 0 ? _a : {};
|
|
888
|
+
return { r, g, b };
|
|
876
889
|
},
|
|
877
890
|
// convert any color string to RGBA object
|
|
878
891
|
// from https://github.com/component/color-parser
|
|
879
892
|
colorToRGBA(str) {
|
|
880
|
-
|
|
881
|
-
|
|
893
|
+
// a CSS custom property keeps the space after the colon,
|
|
894
|
+
// so "--brand: #ff0000" gives us " #ff0000"
|
|
895
|
+
str = (str || '').trim() || 'black';
|
|
896
|
+
const color = Util._namedColorToRBA(str) ||
|
|
882
897
|
Util._hex3ColorToRGBA(str) ||
|
|
883
898
|
Util._hex4ColorToRGBA(str) ||
|
|
884
899
|
Util._hex6ColorToRGBA(str) ||
|
|
885
900
|
Util._hex8ColorToRGBA(str) ||
|
|
886
901
|
Util._rgbColorToRGBA(str) ||
|
|
887
|
-
Util.
|
|
888
|
-
|
|
902
|
+
Util._hslColorToRGBA(str);
|
|
903
|
+
// a NaN component stays invisible until it reaches the canvas and drops the
|
|
904
|
+
// shape, so a color we can not fully parse must fail as a whole
|
|
905
|
+
if (color && [color.r, color.g, color.b, color.a].every(Util._isNumber)) {
|
|
906
|
+
return color;
|
|
907
|
+
}
|
|
889
908
|
},
|
|
890
909
|
// Parse named css color. Like "green"
|
|
891
910
|
_namedColorToRBA(str) {
|
|
@@ -897,43 +916,29 @@ js: import "konva/skia-backend";
|
|
|
897
916
|
r: c[0],
|
|
898
917
|
g: c[1],
|
|
899
918
|
b: c[2],
|
|
900
|
-
a: 1,
|
|
919
|
+
a: c.length > 3 ? c[3] : 1,
|
|
901
920
|
};
|
|
902
921
|
},
|
|
903
|
-
// Parse rgb(n, n, n)
|
|
922
|
+
// Parse rgb(n, n, n), rgba(n, n, n, n) and rgb(n n n / n)
|
|
904
923
|
_rgbColorToRGBA(str) {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
return {
|
|
909
|
-
r: parts[0],
|
|
910
|
-
g: parts[1],
|
|
911
|
-
b: parts[2],
|
|
912
|
-
a: 1,
|
|
913
|
-
};
|
|
924
|
+
const match = /^rgba?\(([^)]*)\)$/i.exec(str);
|
|
925
|
+
if (!match) {
|
|
926
|
+
return;
|
|
914
927
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
if (str.indexOf('rgba(') === 0) {
|
|
919
|
-
str = str.match(/rgba\(([^)]+)\)/)[1];
|
|
920
|
-
const parts = str.split(/ *, */).map((n, index) => {
|
|
921
|
-
if (n.slice(-1) === '%') {
|
|
922
|
-
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
|
923
|
-
}
|
|
924
|
-
return Number(n);
|
|
925
|
-
});
|
|
926
|
-
return {
|
|
927
|
-
r: parts[0],
|
|
928
|
-
g: parts[1],
|
|
929
|
-
b: parts[2],
|
|
930
|
-
a: parts[3],
|
|
931
|
-
};
|
|
928
|
+
const parts = splitColorComponents(match[1]);
|
|
929
|
+
if (parts.length < 3 || parts.length > 4) {
|
|
930
|
+
return;
|
|
932
931
|
}
|
|
932
|
+
return {
|
|
933
|
+
r: parseColorComponent(parts[0], 255),
|
|
934
|
+
g: parseColorComponent(parts[1], 255),
|
|
935
|
+
b: parseColorComponent(parts[2], 255),
|
|
936
|
+
a: parts.length > 3 ? parseColorComponent(parts[3], 1) : 1,
|
|
937
|
+
};
|
|
933
938
|
},
|
|
934
939
|
// Parse #nnnnnnnn
|
|
935
940
|
_hex8ColorToRGBA(str) {
|
|
936
|
-
if (str
|
|
941
|
+
if (str.length === 9 && HEX_COLOR_REGEX.test(str)) {
|
|
937
942
|
return {
|
|
938
943
|
r: parseInt(str.slice(1, 3), 16),
|
|
939
944
|
g: parseInt(str.slice(3, 5), 16),
|
|
@@ -944,7 +949,7 @@ js: import "konva/skia-backend";
|
|
|
944
949
|
},
|
|
945
950
|
// Parse #nnnnnn
|
|
946
951
|
_hex6ColorToRGBA(str) {
|
|
947
|
-
if (str
|
|
952
|
+
if (str.length === 7 && HEX_COLOR_REGEX.test(str)) {
|
|
948
953
|
return {
|
|
949
954
|
r: parseInt(str.slice(1, 3), 16),
|
|
950
955
|
g: parseInt(str.slice(3, 5), 16),
|
|
@@ -955,7 +960,7 @@ js: import "konva/skia-backend";
|
|
|
955
960
|
},
|
|
956
961
|
// Parse #nnnn
|
|
957
962
|
_hex4ColorToRGBA(str) {
|
|
958
|
-
if (str
|
|
963
|
+
if (str.length === 5 && HEX_COLOR_REGEX.test(str)) {
|
|
959
964
|
return {
|
|
960
965
|
r: parseInt(str[1] + str[1], 16),
|
|
961
966
|
g: parseInt(str[2] + str[2], 16),
|
|
@@ -966,7 +971,7 @@ js: import "konva/skia-backend";
|
|
|
966
971
|
},
|
|
967
972
|
// Parse #nnn
|
|
968
973
|
_hex3ColorToRGBA(str) {
|
|
969
|
-
if (str
|
|
974
|
+
if (str.length === 4 && HEX_COLOR_REGEX.test(str)) {
|
|
970
975
|
return {
|
|
971
976
|
r: parseInt(str[1] + str[1], 16),
|
|
972
977
|
g: parseInt(str[2] + str[2], 16),
|
|
@@ -976,63 +981,69 @@ js: import "konva/skia-backend";
|
|
|
976
981
|
}
|
|
977
982
|
},
|
|
978
983
|
// Code adapted from https://github.com/Qix-/color-convert/blob/master/conversions.js#L244
|
|
984
|
+
// Parse hsl(h, s%, l%), hsla(h, s%, l%, n) and hsl(h s% l% / n)
|
|
979
985
|
_hslColorToRGBA(str) {
|
|
980
|
-
|
|
981
|
-
if (
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
986
|
+
const match = /^hsla?\(([^)]*)\)$/i.exec(str);
|
|
987
|
+
if (!match) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
const parts = splitColorComponents(match[1]);
|
|
991
|
+
if (parts.length < 3 || parts.length > 4) {
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
// a hue we can not parse gives a gray color instead of a NaN one,
|
|
995
|
+
// so colorToRGBA() can not catch it at the end
|
|
996
|
+
const hue = HUE_REGEX.exec(parts[0]);
|
|
997
|
+
if (!hue) {
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
const unit = hue[2];
|
|
1001
|
+
const degrees = Number(hue[1]) * (unit ? HUE_UNITS[unit.toLowerCase()] : 1);
|
|
1002
|
+
if (!isFinite(degrees)) {
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
// the hue is an angle, so keep it in [0, 360) to also accept
|
|
1006
|
+
// negative angles and angles over one full turn
|
|
1007
|
+
const h = (((degrees % 360) + 360) % 360) / 360;
|
|
1008
|
+
// the saturation and the lightness are percentages of 1, written with or
|
|
1009
|
+
// without the "%" sign, so read them out of 100 and then scale them down.
|
|
1010
|
+
// CSS keeps them in [0, 1]; out of that range the math gives a negative
|
|
1011
|
+
// channel, which the canvas can not read at all.
|
|
1012
|
+
const s = clamp01(parseColorComponent(parts[1], 100) / 100);
|
|
1013
|
+
const l = clamp01(parseColorComponent(parts[2], 100) / 100);
|
|
1014
|
+
const a = parts.length > 3 ? parseColorComponent(parts[3], 1) : 1;
|
|
1015
|
+
const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
1016
|
+
const t1 = 2 * l - t2;
|
|
1017
|
+
const rgb = [0, 0, 0];
|
|
1018
|
+
for (let i = 0; i < 3; i++) {
|
|
1019
|
+
let t3 = h + (1 / 3) * -(i - 1);
|
|
1020
|
+
if (t3 < 0) {
|
|
1021
|
+
t3++;
|
|
1022
|
+
}
|
|
1023
|
+
if (t3 > 1) {
|
|
1024
|
+
t3--;
|
|
1025
|
+
}
|
|
989
1026
|
let val;
|
|
990
|
-
if (
|
|
991
|
-
val =
|
|
992
|
-
return {
|
|
993
|
-
r: Math.round(val),
|
|
994
|
-
g: Math.round(val),
|
|
995
|
-
b: Math.round(val),
|
|
996
|
-
a: 1,
|
|
997
|
-
};
|
|
1027
|
+
if (6 * t3 < 1) {
|
|
1028
|
+
val = t1 + (t2 - t1) * 6 * t3;
|
|
998
1029
|
}
|
|
999
|
-
if (
|
|
1000
|
-
|
|
1030
|
+
else if (2 * t3 < 1) {
|
|
1031
|
+
val = t2;
|
|
1032
|
+
}
|
|
1033
|
+
else if (3 * t3 < 2) {
|
|
1034
|
+
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
1001
1035
|
}
|
|
1002
1036
|
else {
|
|
1003
|
-
|
|
1004
|
-
}
|
|
1005
|
-
const t1 = 2 * l - t2;
|
|
1006
|
-
const rgb = [0, 0, 0];
|
|
1007
|
-
for (let i = 0; i < 3; i++) {
|
|
1008
|
-
t3 = h + (1 / 3) * -(i - 1);
|
|
1009
|
-
if (t3 < 0) {
|
|
1010
|
-
t3++;
|
|
1011
|
-
}
|
|
1012
|
-
if (t3 > 1) {
|
|
1013
|
-
t3--;
|
|
1014
|
-
}
|
|
1015
|
-
if (6 * t3 < 1) {
|
|
1016
|
-
val = t1 + (t2 - t1) * 6 * t3;
|
|
1017
|
-
}
|
|
1018
|
-
else if (2 * t3 < 1) {
|
|
1019
|
-
val = t2;
|
|
1020
|
-
}
|
|
1021
|
-
else if (3 * t3 < 2) {
|
|
1022
|
-
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
1023
|
-
}
|
|
1024
|
-
else {
|
|
1025
|
-
val = t1;
|
|
1026
|
-
}
|
|
1027
|
-
rgb[i] = val * 255;
|
|
1037
|
+
val = t1;
|
|
1028
1038
|
}
|
|
1029
|
-
|
|
1030
|
-
r: Math.round(rgb[0]),
|
|
1031
|
-
g: Math.round(rgb[1]),
|
|
1032
|
-
b: Math.round(rgb[2]),
|
|
1033
|
-
a: 1,
|
|
1034
|
-
};
|
|
1039
|
+
rgb[i] = val * 255;
|
|
1035
1040
|
}
|
|
1041
|
+
return {
|
|
1042
|
+
r: Math.round(rgb[0]),
|
|
1043
|
+
g: Math.round(rgb[1]),
|
|
1044
|
+
b: Math.round(rgb[2]),
|
|
1045
|
+
a,
|
|
1046
|
+
};
|
|
1036
1047
|
},
|
|
1037
1048
|
/**
|
|
1038
1049
|
* check intersection of two client rectangles
|
|
@@ -1084,8 +1095,14 @@ js: import "konva/skia-backend";
|
|
|
1084
1095
|
_getRotation(radians) {
|
|
1085
1096
|
return Konva$2.angleDeg ? Util.radToDeg(radians) : radians;
|
|
1086
1097
|
},
|
|
1098
|
+
// Memoized — called per-attr per setAttrs; input vocabulary is bounded.
|
|
1087
1099
|
_capitalize(str) {
|
|
1088
|
-
|
|
1100
|
+
const cached = capitalizeCache.get(str);
|
|
1101
|
+
if (cached !== undefined)
|
|
1102
|
+
return cached;
|
|
1103
|
+
const out = str.charAt(0).toUpperCase() + str.slice(1);
|
|
1104
|
+
capitalizeCache.set(str, out);
|
|
1105
|
+
return out;
|
|
1089
1106
|
},
|
|
1090
1107
|
throw(str) {
|
|
1091
1108
|
throw new Error(KONVA_ERROR + str);
|
|
@@ -1984,6 +2001,16 @@ js: import "konva/skia-backend";
|
|
|
1984
2001
|
shape._fillFunc(this);
|
|
1985
2002
|
}
|
|
1986
2003
|
_fillPattern(shape) {
|
|
2004
|
+
// `imageSmoothingEnabled` (set on the layer/context) controls pattern
|
|
2005
|
+
// smoothing in the browser. node-canvas ignores it for pattern fills and
|
|
2006
|
+
// instead exposes a non-standard `patternQuality` property, so mirror the
|
|
2007
|
+
// current smoothing setting onto it to keep both backends consistent.
|
|
2008
|
+
const context = this._context;
|
|
2009
|
+
if ('patternQuality' in context) {
|
|
2010
|
+
context.patternQuality = context.imageSmoothingEnabled
|
|
2011
|
+
? 'good'
|
|
2012
|
+
: 'nearest';
|
|
2013
|
+
}
|
|
1987
2014
|
this.setAttr('fillStyle', shape._getFillPattern());
|
|
1988
2015
|
shape._fillFunc(this);
|
|
1989
2016
|
}
|
|
@@ -2904,6 +2931,14 @@ js: import "konva/skia-backend";
|
|
|
2904
2931
|
this.fire('absoluteTransformChange');
|
|
2905
2932
|
}
|
|
2906
2933
|
}
|
|
2934
|
+
static _runAfterAbsTransformCascade(cb) {
|
|
2935
|
+
if (Node._absTransformCascadeDepth > 0) {
|
|
2936
|
+
Node._pendingAfterCascade.push(cb);
|
|
2937
|
+
}
|
|
2938
|
+
else {
|
|
2939
|
+
cb();
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2907
2942
|
/**
|
|
2908
2943
|
* clear cached canvas
|
|
2909
2944
|
* @method
|
|
@@ -4743,10 +4778,20 @@ js: import "konva/skia-backend";
|
|
|
4743
4778
|
if (events === undefined) {
|
|
4744
4779
|
//recalculate cache
|
|
4745
4780
|
events = [];
|
|
4781
|
+
// Dedupe across the prototype chain: subclasses without their own
|
|
4782
|
+
// `eventListeners` inherit the parent's, so a single handler would
|
|
4783
|
+
// otherwise be pushed once per chain level (Stage→Container→Node = 3x).
|
|
4784
|
+
const seen = new Set();
|
|
4746
4785
|
let obj = Object.getPrototypeOf(this);
|
|
4747
4786
|
while (obj) {
|
|
4748
4787
|
const hierarchyEvents = (_b = (_a = obj.eventListeners) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : [];
|
|
4749
|
-
|
|
4788
|
+
for (let i = 0; i < hierarchyEvents.length; i++) {
|
|
4789
|
+
const entry = hierarchyEvents[i];
|
|
4790
|
+
if (!seen.has(entry)) {
|
|
4791
|
+
seen.add(entry);
|
|
4792
|
+
events.push(entry);
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4750
4795
|
obj = Object.getPrototypeOf(obj);
|
|
4751
4796
|
}
|
|
4752
4797
|
// update cache
|
|
@@ -4761,9 +4806,10 @@ js: import "konva/skia-backend";
|
|
|
4761
4806
|
evt.type = eventType;
|
|
4762
4807
|
const topListeners = this._getProtoListeners(eventType);
|
|
4763
4808
|
if (topListeners) {
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4809
|
+
// Proto listeners are wired at module load and never mutated at
|
|
4810
|
+
// runtime, so no defensive .slice() needed (hot path: every *Change).
|
|
4811
|
+
for (let i = 0; i < topListeners.length; i++) {
|
|
4812
|
+
topListeners[i].handler.call(this, evt);
|
|
4767
4813
|
}
|
|
4768
4814
|
}
|
|
4769
4815
|
// snapshot prevents skipping listeners when a handler mutates the array
|
|
@@ -5018,6 +5064,12 @@ js: import "konva/skia-backend";
|
|
|
5018
5064
|
return no;
|
|
5019
5065
|
}
|
|
5020
5066
|
}
|
|
5067
|
+
// Perf: lets a listener inside an absoluteTransform cascade (e.g. Konva
|
|
5068
|
+
// .Transformer reacting to a stage drag fan-out across N attached nodes)
|
|
5069
|
+
// defer work until the cascade ends — collapses O(N) listener-driven calls
|
|
5070
|
+
// into one. Counter is mutated by Container's _clearSelfAndDescendantCache.
|
|
5071
|
+
Node._absTransformCascadeDepth = 0;
|
|
5072
|
+
Node._pendingAfterCascade = [];
|
|
5021
5073
|
Node.protoListenerMap = new Map();
|
|
5022
5074
|
Node.prototype.nodeType = 'Node';
|
|
5023
5075
|
Node.prototype._attrsAffectingSize = [];
|
|
@@ -5863,15 +5915,31 @@ js: import "konva/skia-backend";
|
|
|
5863
5915
|
}
|
|
5864
5916
|
_clearSelfAndDescendantCache(attr) {
|
|
5865
5917
|
var _a;
|
|
5866
|
-
|
|
5867
|
-
//
|
|
5868
|
-
//
|
|
5869
|
-
|
|
5870
|
-
|
|
5918
|
+
// Perf: bracket absoluteTransform cascades with a depth counter so
|
|
5919
|
+
// Node._runAfterAbsTransformCascade can defer work until the outermost
|
|
5920
|
+
// walk returns. try/finally so depth/flush survive listener exceptions.
|
|
5921
|
+
const isAbsTransform = attr === 'absoluteTransform';
|
|
5922
|
+
if (isAbsTransform)
|
|
5923
|
+
Node._absTransformCascadeDepth++;
|
|
5924
|
+
try {
|
|
5925
|
+
super._clearSelfAndDescendantCache(attr);
|
|
5926
|
+
// skip clearing if node is cached with canvas (perf)
|
|
5927
|
+
if (this.isCached())
|
|
5928
|
+
return;
|
|
5929
|
+
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
|
|
5930
|
+
node._clearSelfAndDescendantCache(attr);
|
|
5931
|
+
});
|
|
5932
|
+
}
|
|
5933
|
+
finally {
|
|
5934
|
+
if (isAbsTransform && --Node._absTransformCascadeDepth === 0) {
|
|
5935
|
+
const callbacks = Node._pendingAfterCascade;
|
|
5936
|
+
if (callbacks.length) {
|
|
5937
|
+
Node._pendingAfterCascade = [];
|
|
5938
|
+
for (let i = 0; i < callbacks.length; i++)
|
|
5939
|
+
callbacks[i]();
|
|
5940
|
+
}
|
|
5941
|
+
}
|
|
5871
5942
|
}
|
|
5872
|
-
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
|
|
5873
|
-
node._clearSelfAndDescendantCache(attr);
|
|
5874
|
-
});
|
|
5875
5943
|
}
|
|
5876
5944
|
_setChildrenIndices() {
|
|
5877
5945
|
var _a;
|
|
@@ -7550,6 +7618,10 @@ js: import "konva/skia-backend";
|
|
|
7550
7618
|
bufferContext.clear();
|
|
7551
7619
|
}
|
|
7552
7620
|
bufferContext.save();
|
|
7621
|
+
// the buffer canvas is a separate context that does not inherit the
|
|
7622
|
+
// destination `imageSmoothingEnabled` flag, so propagate it to keep
|
|
7623
|
+
// pattern/image smoothing consistent with the target context.
|
|
7624
|
+
bufferContext.imageSmoothingEnabled = context.imageSmoothingEnabled;
|
|
7553
7625
|
bufferContext._applyLineJoin(this);
|
|
7554
7626
|
bufferContext._applyMiterLimit(this);
|
|
7555
7627
|
// layer might be undefined if we are using cache before adding to layer
|
|
@@ -9505,6 +9577,14 @@ js: import "konva/skia-backend";
|
|
|
9505
9577
|
yoyo: 1,
|
|
9506
9578
|
}, PAUSED = 1, PLAYING = 2, REVERSING = 3, colorAttrs = ['fill', 'stroke', 'shadowColor'];
|
|
9507
9579
|
let idCounter = 0;
|
|
9580
|
+
// the diff below reads r/g/b/a directly, so a color we can not parse must fail
|
|
9581
|
+
// with its own message instead of "Cannot read properties of undefined"
|
|
9582
|
+
function colorToRGBA(color) {
|
|
9583
|
+
return (Util.colorToRGBA(color) ||
|
|
9584
|
+
Util.throw('can not tween the color "' +
|
|
9585
|
+
color +
|
|
9586
|
+
'", because it is not a valid color.'));
|
|
9587
|
+
}
|
|
9508
9588
|
class TweenEngine {
|
|
9509
9589
|
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
|
9510
9590
|
this.prop = prop;
|
|
@@ -9728,8 +9808,8 @@ js: import "konva/skia-backend";
|
|
|
9728
9808
|
diff.push(end[n] - start[n]);
|
|
9729
9809
|
}
|
|
9730
9810
|
else {
|
|
9731
|
-
const startRGBA =
|
|
9732
|
-
endRGBA =
|
|
9811
|
+
const startRGBA = colorToRGBA(start[n]);
|
|
9812
|
+
endRGBA = colorToRGBA(end[n]);
|
|
9733
9813
|
start[n] = startRGBA;
|
|
9734
9814
|
diff.push({
|
|
9735
9815
|
r: endRGBA.r - startRGBA.r,
|
|
@@ -9747,8 +9827,8 @@ js: import "konva/skia-backend";
|
|
|
9747
9827
|
}
|
|
9748
9828
|
}
|
|
9749
9829
|
else if (colorAttrs.indexOf(key) !== -1) {
|
|
9750
|
-
start =
|
|
9751
|
-
endRGBA =
|
|
9830
|
+
start = colorToRGBA(start);
|
|
9831
|
+
endRGBA = colorToRGBA(end);
|
|
9752
9832
|
diff = {
|
|
9753
9833
|
r: endRGBA.r - start.r,
|
|
9754
9834
|
g: endRGBA.g - start.g,
|
|
@@ -10358,6 +10438,20 @@ js: import "konva/skia-backend";
|
|
|
10358
10438
|
const innerRadius = this.innerRadius();
|
|
10359
10439
|
const outerRadius = this.outerRadius();
|
|
10360
10440
|
const clockwise = this.clockwise();
|
|
10441
|
+
// canvas draws a full circle for any non-zero full-turn end angle regardless
|
|
10442
|
+
// of direction, and nothing for angle 0. The 360 - angle flip below maps both
|
|
10443
|
+
// onto the same value, so handle exact full turns before the trig formula.
|
|
10444
|
+
const rawAngle = Konva$2.getAngle(this.angle());
|
|
10445
|
+
if (rawAngle % (Math.PI * 2) === 0) {
|
|
10446
|
+
return rawAngle !== 0
|
|
10447
|
+
? {
|
|
10448
|
+
x: -outerRadius,
|
|
10449
|
+
y: -outerRadius,
|
|
10450
|
+
width: outerRadius * 2,
|
|
10451
|
+
height: outerRadius * 2,
|
|
10452
|
+
}
|
|
10453
|
+
: { x: innerRadius, y: 0, width: outerRadius - innerRadius, height: 0 };
|
|
10454
|
+
}
|
|
10361
10455
|
const angle = Konva$2.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
|
10362
10456
|
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
|
10363
10457
|
const boundRightRatio = 1;
|
|
@@ -10445,357 +10539,6 @@ js: import "konva/skia-backend";
|
|
|
10445
10539
|
* arc.clockwise(true);
|
|
10446
10540
|
*/
|
|
10447
10541
|
|
|
10448
|
-
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
|
|
10449
|
-
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = (t * d01) / (d01 + d12), fb = (t * d12) / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);
|
|
10450
|
-
return [p1x, p1y, p2x, p2y];
|
|
10451
|
-
}
|
|
10452
|
-
function expandPoints(p, tension) {
|
|
10453
|
-
const len = p.length, allPoints = [];
|
|
10454
|
-
for (let n = 2; n < len - 2; n += 2) {
|
|
10455
|
-
const cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
|
|
10456
|
-
if (isNaN(cp[0])) {
|
|
10457
|
-
continue;
|
|
10458
|
-
}
|
|
10459
|
-
allPoints.push(cp[0]);
|
|
10460
|
-
allPoints.push(cp[1]);
|
|
10461
|
-
allPoints.push(p[n]);
|
|
10462
|
-
allPoints.push(p[n + 1]);
|
|
10463
|
-
allPoints.push(cp[2]);
|
|
10464
|
-
allPoints.push(cp[3]);
|
|
10465
|
-
}
|
|
10466
|
-
return allPoints;
|
|
10467
|
-
}
|
|
10468
|
-
function getBezierExtremaPoints(points) {
|
|
10469
|
-
const axisPoints = [
|
|
10470
|
-
[points[0], points[2], points[4], points[6]],
|
|
10471
|
-
[points[1], points[3], points[5], points[7]],
|
|
10472
|
-
];
|
|
10473
|
-
const extremaTs = [];
|
|
10474
|
-
for (const axis of axisPoints) {
|
|
10475
|
-
const a = -3 * axis[0] + 9 * axis[1] - 9 * axis[2] + 3 * axis[3];
|
|
10476
|
-
if (a !== 0) {
|
|
10477
|
-
const b = 6 * axis[0] - 12 * axis[1] + 6 * axis[2];
|
|
10478
|
-
const c = -3 * axis[0] + 3 * axis[1];
|
|
10479
|
-
const discriminant = b * b - 4 * a * c;
|
|
10480
|
-
if (discriminant >= 0) {
|
|
10481
|
-
const d = Math.sqrt(discriminant);
|
|
10482
|
-
extremaTs.push((-b + d) / (2 * a));
|
|
10483
|
-
extremaTs.push((-b - d) / (2 * a));
|
|
10484
|
-
}
|
|
10485
|
-
}
|
|
10486
|
-
}
|
|
10487
|
-
return extremaTs
|
|
10488
|
-
.filter((t) => t > 0 && t < 1)
|
|
10489
|
-
.flatMap((t) => axisPoints.map((axis) => {
|
|
10490
|
-
const mt = 1 - t;
|
|
10491
|
-
return (mt * mt * mt * axis[0] +
|
|
10492
|
-
3 * mt * mt * t * axis[1] +
|
|
10493
|
-
3 * mt * t * t * axis[2] +
|
|
10494
|
-
t * t * t * axis[3]);
|
|
10495
|
-
}));
|
|
10496
|
-
}
|
|
10497
|
-
/**
|
|
10498
|
-
* Line constructor. Lines are defined by an array of points and
|
|
10499
|
-
* a tension
|
|
10500
|
-
* @constructor
|
|
10501
|
-
* @memberof Konva
|
|
10502
|
-
* @augments Konva.Shape
|
|
10503
|
-
* @param {Object} config
|
|
10504
|
-
* @param {Array} config.points Flat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].
|
|
10505
|
-
* @param {Number} [config.tension] Higher values will result in a more curvy line. A value of 0 will result in no interpolation.
|
|
10506
|
-
* The default is 0
|
|
10507
|
-
* @param {Boolean} [config.closed] defines whether or not the line shape is closed, creating a polygon or blob
|
|
10508
|
-
* @param {Boolean} [config.bezier] if no tension is provided but bezier=true, we draw the line as a bezier using the passed points
|
|
10509
|
-
* @param {String} [config.fill] fill color
|
|
10510
|
-
* @param {Image} [config.fillPatternImage] fill pattern image
|
|
10511
|
-
* @param {Number} [config.fillPatternX]
|
|
10512
|
-
* @param {Number} [config.fillPatternY]
|
|
10513
|
-
* @param {Object} [config.fillPatternOffset] object with x and y component
|
|
10514
|
-
* @param {Number} [config.fillPatternOffsetX]
|
|
10515
|
-
* @param {Number} [config.fillPatternOffsetY]
|
|
10516
|
-
* @param {Object} [config.fillPatternScale] object with x and y component
|
|
10517
|
-
* @param {Number} [config.fillPatternScaleX]
|
|
10518
|
-
* @param {Number} [config.fillPatternScaleY]
|
|
10519
|
-
* @param {Number} [config.fillPatternRotation]
|
|
10520
|
-
* @param {String} [config.fillPatternRepeat] can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"
|
|
10521
|
-
* @param {Object} [config.fillLinearGradientStartPoint] object with x and y component
|
|
10522
|
-
* @param {Number} [config.fillLinearGradientStartPointX]
|
|
10523
|
-
* @param {Number} [config.fillLinearGradientStartPointY]
|
|
10524
|
-
* @param {Object} [config.fillLinearGradientEndPoint] object with x and y component
|
|
10525
|
-
* @param {Number} [config.fillLinearGradientEndPointX]
|
|
10526
|
-
* @param {Number} [config.fillLinearGradientEndPointY]
|
|
10527
|
-
* @param {Array} [config.fillLinearGradientColorStops] array of color stops
|
|
10528
|
-
* @param {Object} [config.fillRadialGradientStartPoint] object with x and y component
|
|
10529
|
-
* @param {Number} [config.fillRadialGradientStartPointX]
|
|
10530
|
-
* @param {Number} [config.fillRadialGradientStartPointY]
|
|
10531
|
-
* @param {Object} [config.fillRadialGradientEndPoint] object with x and y component
|
|
10532
|
-
* @param {Number} [config.fillRadialGradientEndPointX]
|
|
10533
|
-
* @param {Number} [config.fillRadialGradientEndPointY]
|
|
10534
|
-
* @param {Number} [config.fillRadialGradientStartRadius]
|
|
10535
|
-
* @param {Number} [config.fillRadialGradientEndRadius]
|
|
10536
|
-
* @param {Array} [config.fillRadialGradientColorStops] array of color stops
|
|
10537
|
-
* @param {Boolean} [config.fillEnabled] flag which enables or disables the fill. The default value is true
|
|
10538
|
-
* @param {String} [config.fillPriority] can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration
|
|
10539
|
-
* @param {String} [config.stroke] stroke color
|
|
10540
|
-
* @param {Number} [config.strokeWidth] stroke width
|
|
10541
|
-
* @param {Boolean} [config.fillAfterStrokeEnabled]. Should we draw fill AFTER stroke? Default is false.
|
|
10542
|
-
* @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
|
|
10543
|
-
* @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
|
|
10544
|
-
* @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
|
|
10545
|
-
* @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
|
|
10546
|
-
* @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
|
|
10547
|
-
* @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
|
|
10548
|
-
* @param {String} [config.lineJoin] can be miter, round, or bevel. The default
|
|
10549
|
-
* is miter
|
|
10550
|
-
* @param {String} [config.lineCap] can be butt, round, or square. The default
|
|
10551
|
-
* is butt
|
|
10552
|
-
* @param {String} [config.shadowColor]
|
|
10553
|
-
* @param {Number} [config.shadowBlur]
|
|
10554
|
-
* @param {Object} [config.shadowOffset] object with x and y component
|
|
10555
|
-
* @param {Number} [config.shadowOffsetX]
|
|
10556
|
-
* @param {Number} [config.shadowOffsetY]
|
|
10557
|
-
* @param {Number} [config.shadowOpacity] shadow opacity. Can be any real number
|
|
10558
|
-
* between 0 and 1
|
|
10559
|
-
* @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
|
|
10560
|
-
* @param {Array} [config.dash]
|
|
10561
|
-
* @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
|
|
10562
|
-
|
|
10563
|
-
* @param {Number} [config.x]
|
|
10564
|
-
* @param {Number} [config.y]
|
|
10565
|
-
* @param {Number} [config.width]
|
|
10566
|
-
* @param {Number} [config.height]
|
|
10567
|
-
* @param {Boolean} [config.visible]
|
|
10568
|
-
* @param {Boolean} [config.listening] whether or not the node is listening for events
|
|
10569
|
-
* @param {String} [config.id] unique id
|
|
10570
|
-
* @param {String} [config.name] non-unique name
|
|
10571
|
-
* @param {Number} [config.opacity] determines node opacity. Can be any number between 0 and 1
|
|
10572
|
-
* @param {Object} [config.scale] set scale
|
|
10573
|
-
* @param {Number} [config.scaleX] set scale x
|
|
10574
|
-
* @param {Number} [config.scaleY] set scale y
|
|
10575
|
-
* @param {Number} [config.rotation] rotation in degrees
|
|
10576
|
-
* @param {Object} [config.offset] offset from center point and rotation point
|
|
10577
|
-
* @param {Number} [config.offsetX] set offset x
|
|
10578
|
-
* @param {Number} [config.offsetY] set offset y
|
|
10579
|
-
* @param {Boolean} [config.draggable] makes the node draggable. When stages are draggable, you can drag and drop
|
|
10580
|
-
* the entire stage by dragging any portion of the stage
|
|
10581
|
-
* @param {Number} [config.dragDistance]
|
|
10582
|
-
* @param {Function} [config.dragBoundFunc]
|
|
10583
|
-
* @example
|
|
10584
|
-
* var line = new Konva.Line({
|
|
10585
|
-
* x: 100,
|
|
10586
|
-
* y: 50,
|
|
10587
|
-
* points: [73, 70, 340, 23, 450, 60, 500, 20],
|
|
10588
|
-
* stroke: 'red',
|
|
10589
|
-
* tension: 1
|
|
10590
|
-
* });
|
|
10591
|
-
*/
|
|
10592
|
-
class Line extends Shape {
|
|
10593
|
-
constructor(config) {
|
|
10594
|
-
super(config);
|
|
10595
|
-
this.on('pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva', function () {
|
|
10596
|
-
this._clearCache('tensionPoints');
|
|
10597
|
-
});
|
|
10598
|
-
}
|
|
10599
|
-
_sceneFunc(context) {
|
|
10600
|
-
const points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier();
|
|
10601
|
-
if (!length) {
|
|
10602
|
-
return;
|
|
10603
|
-
}
|
|
10604
|
-
let n = 0;
|
|
10605
|
-
context.beginPath();
|
|
10606
|
-
context.moveTo(points[0], points[1]);
|
|
10607
|
-
// tension
|
|
10608
|
-
if (tension !== 0 && length > 4) {
|
|
10609
|
-
const tp = this.getTensionPoints();
|
|
10610
|
-
const len = tp.length;
|
|
10611
|
-
n = closed ? 0 : 4;
|
|
10612
|
-
if (!closed) {
|
|
10613
|
-
context.quadraticCurveTo(tp[0], tp[1], tp[2], tp[3]);
|
|
10614
|
-
}
|
|
10615
|
-
while (n < len - 2) {
|
|
10616
|
-
context.bezierCurveTo(tp[n++], tp[n++], tp[n++], tp[n++], tp[n++], tp[n++]);
|
|
10617
|
-
}
|
|
10618
|
-
if (!closed) {
|
|
10619
|
-
context.quadraticCurveTo(tp[len - 2], tp[len - 1], points[length - 2], points[length - 1]);
|
|
10620
|
-
}
|
|
10621
|
-
}
|
|
10622
|
-
else if (bezier) {
|
|
10623
|
-
// no tension but bezier
|
|
10624
|
-
n = 2;
|
|
10625
|
-
while (n < length) {
|
|
10626
|
-
context.bezierCurveTo(points[n++], points[n++], points[n++], points[n++], points[n++], points[n++]);
|
|
10627
|
-
}
|
|
10628
|
-
}
|
|
10629
|
-
else {
|
|
10630
|
-
// no tension
|
|
10631
|
-
for (n = 2; n < length; n += 2) {
|
|
10632
|
-
context.lineTo(points[n], points[n + 1]);
|
|
10633
|
-
}
|
|
10634
|
-
}
|
|
10635
|
-
// closed e.g. polygons and blobs
|
|
10636
|
-
if (closed) {
|
|
10637
|
-
context.closePath();
|
|
10638
|
-
context.fillStrokeShape(this);
|
|
10639
|
-
}
|
|
10640
|
-
else {
|
|
10641
|
-
// open e.g. lines and splines
|
|
10642
|
-
context.strokeShape(this);
|
|
10643
|
-
}
|
|
10644
|
-
}
|
|
10645
|
-
getTensionPoints() {
|
|
10646
|
-
return this._getCache('tensionPoints', this._getTensionPoints);
|
|
10647
|
-
}
|
|
10648
|
-
_getTensionPoints() {
|
|
10649
|
-
if (this.closed()) {
|
|
10650
|
-
return this._getTensionPointsClosed();
|
|
10651
|
-
}
|
|
10652
|
-
else {
|
|
10653
|
-
return expandPoints(this.points(), this.tension());
|
|
10654
|
-
}
|
|
10655
|
-
}
|
|
10656
|
-
_getTensionPointsClosed() {
|
|
10657
|
-
const p = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]]
|
|
10658
|
-
.concat(middle)
|
|
10659
|
-
.concat([
|
|
10660
|
-
lastControlPoints[0],
|
|
10661
|
-
lastControlPoints[1],
|
|
10662
|
-
p[len - 2],
|
|
10663
|
-
p[len - 1],
|
|
10664
|
-
lastControlPoints[2],
|
|
10665
|
-
lastControlPoints[3],
|
|
10666
|
-
firstControlPoints[0],
|
|
10667
|
-
firstControlPoints[1],
|
|
10668
|
-
p[0],
|
|
10669
|
-
p[1],
|
|
10670
|
-
]);
|
|
10671
|
-
return tp;
|
|
10672
|
-
}
|
|
10673
|
-
getWidth() {
|
|
10674
|
-
return this.getSelfRect().width;
|
|
10675
|
-
}
|
|
10676
|
-
getHeight() {
|
|
10677
|
-
return this.getSelfRect().height;
|
|
10678
|
-
}
|
|
10679
|
-
// overload size detection
|
|
10680
|
-
getSelfRect() {
|
|
10681
|
-
let points = this.points();
|
|
10682
|
-
if (points.length < 4) {
|
|
10683
|
-
return {
|
|
10684
|
-
x: points[0] || 0,
|
|
10685
|
-
y: points[1] || 0,
|
|
10686
|
-
width: 0,
|
|
10687
|
-
height: 0,
|
|
10688
|
-
};
|
|
10689
|
-
}
|
|
10690
|
-
if (this.tension() !== 0) {
|
|
10691
|
-
points = [
|
|
10692
|
-
points[0],
|
|
10693
|
-
points[1],
|
|
10694
|
-
...this._getTensionPoints(),
|
|
10695
|
-
points[points.length - 2],
|
|
10696
|
-
points[points.length - 1],
|
|
10697
|
-
];
|
|
10698
|
-
}
|
|
10699
|
-
else if (this.bezier()) {
|
|
10700
|
-
points = [
|
|
10701
|
-
points[0],
|
|
10702
|
-
points[1],
|
|
10703
|
-
...getBezierExtremaPoints(this.points()),
|
|
10704
|
-
points[points.length - 2],
|
|
10705
|
-
points[points.length - 1],
|
|
10706
|
-
];
|
|
10707
|
-
}
|
|
10708
|
-
else {
|
|
10709
|
-
points = this.points();
|
|
10710
|
-
}
|
|
10711
|
-
let minX = points[0];
|
|
10712
|
-
let maxX = points[0];
|
|
10713
|
-
let minY = points[1];
|
|
10714
|
-
let maxY = points[1];
|
|
10715
|
-
let x, y;
|
|
10716
|
-
for (let i = 0; i < points.length / 2; i++) {
|
|
10717
|
-
x = points[i * 2];
|
|
10718
|
-
y = points[i * 2 + 1];
|
|
10719
|
-
minX = Math.min(minX, x);
|
|
10720
|
-
maxX = Math.max(maxX, x);
|
|
10721
|
-
minY = Math.min(minY, y);
|
|
10722
|
-
maxY = Math.max(maxY, y);
|
|
10723
|
-
}
|
|
10724
|
-
return {
|
|
10725
|
-
x: minX,
|
|
10726
|
-
y: minY,
|
|
10727
|
-
width: maxX - minX,
|
|
10728
|
-
height: maxY - minY,
|
|
10729
|
-
};
|
|
10730
|
-
}
|
|
10731
|
-
}
|
|
10732
|
-
Line.prototype.className = 'Line';
|
|
10733
|
-
Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension'];
|
|
10734
|
-
_registerNode(Line);
|
|
10735
|
-
// add getters setters
|
|
10736
|
-
Factory.addGetterSetter(Line, 'closed', false);
|
|
10737
|
-
/**
|
|
10738
|
-
* get/set closed flag. The default is false
|
|
10739
|
-
* @name Konva.Line#closed
|
|
10740
|
-
* @method
|
|
10741
|
-
* @param {Boolean} closed
|
|
10742
|
-
* @returns {Boolean}
|
|
10743
|
-
* @example
|
|
10744
|
-
* // get closed flag
|
|
10745
|
-
* var closed = line.closed();
|
|
10746
|
-
*
|
|
10747
|
-
* // close the shape
|
|
10748
|
-
* line.closed(true);
|
|
10749
|
-
*
|
|
10750
|
-
* // open the shape
|
|
10751
|
-
* line.closed(false);
|
|
10752
|
-
*/
|
|
10753
|
-
Factory.addGetterSetter(Line, 'bezier', false);
|
|
10754
|
-
/**
|
|
10755
|
-
* get/set bezier flag. The default is false
|
|
10756
|
-
* @name Konva.Line#bezier
|
|
10757
|
-
* @method
|
|
10758
|
-
* @param {Boolean} bezier
|
|
10759
|
-
* @returns {Boolean}
|
|
10760
|
-
* @example
|
|
10761
|
-
* // get whether the line is a bezier
|
|
10762
|
-
* var isBezier = line.bezier();
|
|
10763
|
-
*
|
|
10764
|
-
* // set whether the line is a bezier
|
|
10765
|
-
* line.bezier(true);
|
|
10766
|
-
*/
|
|
10767
|
-
Factory.addGetterSetter(Line, 'tension', 0, getNumberValidator());
|
|
10768
|
-
/**
|
|
10769
|
-
* get/set tension
|
|
10770
|
-
* @name Konva.Line#tension
|
|
10771
|
-
* @method
|
|
10772
|
-
* @param {Number} tension Higher values will result in a more curvy line. A value of 0 will result in no interpolation. The default is 0
|
|
10773
|
-
* @returns {Number}
|
|
10774
|
-
* @example
|
|
10775
|
-
* // get tension
|
|
10776
|
-
* var tension = line.tension();
|
|
10777
|
-
*
|
|
10778
|
-
* // set tension
|
|
10779
|
-
* line.tension(3);
|
|
10780
|
-
*/
|
|
10781
|
-
Factory.addGetterSetter(Line, 'points', [], getNumberArrayValidator());
|
|
10782
|
-
/**
|
|
10783
|
-
* get/set points array. Points is a flat array [x1, y1, x2, y2]. It is flat for performance reasons.
|
|
10784
|
-
* @name Konva.Line#points
|
|
10785
|
-
* @method
|
|
10786
|
-
* @param {Array} points
|
|
10787
|
-
* @returns {Array}
|
|
10788
|
-
* @example
|
|
10789
|
-
* // get points
|
|
10790
|
-
* var points = line.points();
|
|
10791
|
-
*
|
|
10792
|
-
* // set points
|
|
10793
|
-
* line.points([10, 20, 30, 40, 50, 60]);
|
|
10794
|
-
*
|
|
10795
|
-
* // push a new point
|
|
10796
|
-
* line.points(line.points().concat([70, 80]));
|
|
10797
|
-
*/
|
|
10798
|
-
|
|
10799
10542
|
// Credits: rveciana/svg-path-properties
|
|
10800
10543
|
// Legendre-Gauss abscissae (xi values, defined at i=n as the roots of the nth order Legendre polynomial Pn(x))
|
|
10801
10544
|
const tValues = [
|
|
@@ -11594,6 +11337,425 @@ js: import "konva/skia-backend";
|
|
|
11594
11337
|
}
|
|
11595
11338
|
return t;
|
|
11596
11339
|
};
|
|
11340
|
+
const quadraticAt = (p0, p1, p2, t) => {
|
|
11341
|
+
const mt = 1 - t;
|
|
11342
|
+
return mt * mt * p0 + 2 * mt * t * p1 + t * t * p2;
|
|
11343
|
+
};
|
|
11344
|
+
/**
|
|
11345
|
+
* Points where a quadratic bezier segment reaches its highest or lowest value
|
|
11346
|
+
* on one of the two axes, as a flat [x, y, x, y, ...] list. The two end points
|
|
11347
|
+
* are not included, because the caller knows them already.
|
|
11348
|
+
*/
|
|
11349
|
+
const getQuadraticExtremaPoints = (x0, y0, x1, y1, x2, y2) => {
|
|
11350
|
+
const extrema = [];
|
|
11351
|
+
for (const axis of [
|
|
11352
|
+
[x0, x1, x2],
|
|
11353
|
+
[y0, y1, y2],
|
|
11354
|
+
]) {
|
|
11355
|
+
// the derivative of the quadratic is linear, so it has one root. A straight
|
|
11356
|
+
// segment makes the denominator 0, and the division then gives a value that
|
|
11357
|
+
// is not in the range below.
|
|
11358
|
+
const t = (axis[0] - axis[1]) / (axis[0] - 2 * axis[1] + axis[2]);
|
|
11359
|
+
if (t > 0 && t < 1) {
|
|
11360
|
+
extrema.push(quadraticAt(x0, x1, x2, t), quadraticAt(y0, y1, y2, t));
|
|
11361
|
+
}
|
|
11362
|
+
}
|
|
11363
|
+
return extrema;
|
|
11364
|
+
};
|
|
11365
|
+
const cubicAt = (p0, p1, p2, p3, t) => {
|
|
11366
|
+
const mt = 1 - t;
|
|
11367
|
+
return (mt * mt * mt * p0 +
|
|
11368
|
+
3 * mt * mt * t * p1 +
|
|
11369
|
+
3 * mt * t * t * p2 +
|
|
11370
|
+
t * t * t * p3);
|
|
11371
|
+
};
|
|
11372
|
+
/**
|
|
11373
|
+
* Points where a cubic bezier segment reaches its highest or lowest value on
|
|
11374
|
+
* one of the two axes, as a flat [x, y, x, y, ...] list. The two end points
|
|
11375
|
+
* are not included, because the caller knows them already.
|
|
11376
|
+
*/
|
|
11377
|
+
const getCubicExtremaPoints = (x0, y0, x1, y1, x2, y2, x3, y3) => {
|
|
11378
|
+
const extrema = [];
|
|
11379
|
+
for (const axis of [
|
|
11380
|
+
[x0, x1, x2, x3],
|
|
11381
|
+
[y0, y1, y2, y3],
|
|
11382
|
+
]) {
|
|
11383
|
+
// the derivative of the cubic is a * t * t + b * t + c
|
|
11384
|
+
const a = -3 * axis[0] + 9 * axis[1] - 9 * axis[2] + 3 * axis[3];
|
|
11385
|
+
const b = 6 * axis[0] - 12 * axis[1] + 6 * axis[2];
|
|
11386
|
+
const c = -3 * axis[0] + 3 * axis[1];
|
|
11387
|
+
const discriminant = b * b - 4 * a * c;
|
|
11388
|
+
if (discriminant < 0) {
|
|
11389
|
+
continue;
|
|
11390
|
+
}
|
|
11391
|
+
// stable form of the quadratic formula. The plain (-b +- d) / (2 * a)
|
|
11392
|
+
// loses the root that stays finite when a is zero or near zero, which is
|
|
11393
|
+
// what a symmetric pair of control points gives. Roots that are not
|
|
11394
|
+
// finite fall out of the range test below.
|
|
11395
|
+
const q = -(b + (b < 0 ? -1 : 1) * Math.sqrt(discriminant)) / 2;
|
|
11396
|
+
for (const t of [q / a, c / q]) {
|
|
11397
|
+
if (t > 0 && t < 1) {
|
|
11398
|
+
extrema.push(cubicAt(x0, x1, x2, x3, t), cubicAt(y0, y1, y2, y3, t));
|
|
11399
|
+
}
|
|
11400
|
+
}
|
|
11401
|
+
}
|
|
11402
|
+
return extrema;
|
|
11403
|
+
};
|
|
11404
|
+
|
|
11405
|
+
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
|
|
11406
|
+
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), dSum = d01 + d12;
|
|
11407
|
+
// all three points are the same, so the control points collapse into that
|
|
11408
|
+
// point. Without this the divisions below are 0 / 0 = NaN.
|
|
11409
|
+
if (dSum === 0) {
|
|
11410
|
+
return [x1, y1, x1, y1];
|
|
11411
|
+
}
|
|
11412
|
+
const fa = (t * d01) / dSum, fb = (t * d12) / dSum, p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);
|
|
11413
|
+
return [p1x, p1y, p2x, p2y];
|
|
11414
|
+
}
|
|
11415
|
+
function expandPoints(p, tension) {
|
|
11416
|
+
const len = p.length, allPoints = [];
|
|
11417
|
+
for (let n = 2; n < len - 2; n += 2) {
|
|
11418
|
+
const cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
|
|
11419
|
+
if (isNaN(cp[0])) {
|
|
11420
|
+
continue;
|
|
11421
|
+
}
|
|
11422
|
+
allPoints.push(cp[0]);
|
|
11423
|
+
allPoints.push(cp[1]);
|
|
11424
|
+
allPoints.push(p[n]);
|
|
11425
|
+
allPoints.push(p[n + 1]);
|
|
11426
|
+
allPoints.push(cp[2]);
|
|
11427
|
+
allPoints.push(cp[3]);
|
|
11428
|
+
}
|
|
11429
|
+
return allPoints;
|
|
11430
|
+
}
|
|
11431
|
+
function getBezierExtremaPoints(points) {
|
|
11432
|
+
const extrema = [];
|
|
11433
|
+
// points[0], points[1] is the starting point; every subsequent group of
|
|
11434
|
+
// 6 values is one cubic bezier segment (cp1x, cp1y, cp2x, cp2y, x, y),
|
|
11435
|
+
// whose start is the previous segment's end point (matching the layout
|
|
11436
|
+
// Line#_sceneFunc feeds to context.bezierCurveTo in a loop).
|
|
11437
|
+
for (let n = 0; n + 7 < points.length; n += 6) {
|
|
11438
|
+
// the end point of the segment. It is a joint with the next segment, and
|
|
11439
|
+
// the curve can reach its highest or lowest value there without the
|
|
11440
|
+
// derivative going to zero on either side.
|
|
11441
|
+
extrema.push(points[n + 6], points[n + 7], ...getCubicExtremaPoints(points[n], points[n + 1], points[n + 2], points[n + 3], points[n + 4], points[n + 5], points[n + 6], points[n + 7]));
|
|
11442
|
+
}
|
|
11443
|
+
return extrema;
|
|
11444
|
+
}
|
|
11445
|
+
/**
|
|
11446
|
+
* Line constructor. Lines are defined by an array of points and
|
|
11447
|
+
* a tension
|
|
11448
|
+
* @constructor
|
|
11449
|
+
* @memberof Konva
|
|
11450
|
+
* @augments Konva.Shape
|
|
11451
|
+
* @param {Object} config
|
|
11452
|
+
* @param {Array} config.points Flat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].
|
|
11453
|
+
* @param {Number} [config.tension] Higher values will result in a more curvy line. A value of 0 will result in no interpolation.
|
|
11454
|
+
* The default is 0
|
|
11455
|
+
* @param {Boolean} [config.closed] defines whether or not the line shape is closed, creating a polygon or blob
|
|
11456
|
+
* @param {Boolean} [config.bezier] if no tension is provided but bezier=true, we draw the line as a bezier using the passed points
|
|
11457
|
+
* @param {String} [config.fill] fill color
|
|
11458
|
+
* @param {Image} [config.fillPatternImage] fill pattern image
|
|
11459
|
+
* @param {Number} [config.fillPatternX]
|
|
11460
|
+
* @param {Number} [config.fillPatternY]
|
|
11461
|
+
* @param {Object} [config.fillPatternOffset] object with x and y component
|
|
11462
|
+
* @param {Number} [config.fillPatternOffsetX]
|
|
11463
|
+
* @param {Number} [config.fillPatternOffsetY]
|
|
11464
|
+
* @param {Object} [config.fillPatternScale] object with x and y component
|
|
11465
|
+
* @param {Number} [config.fillPatternScaleX]
|
|
11466
|
+
* @param {Number} [config.fillPatternScaleY]
|
|
11467
|
+
* @param {Number} [config.fillPatternRotation]
|
|
11468
|
+
* @param {String} [config.fillPatternRepeat] can be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"
|
|
11469
|
+
* @param {Object} [config.fillLinearGradientStartPoint] object with x and y component
|
|
11470
|
+
* @param {Number} [config.fillLinearGradientStartPointX]
|
|
11471
|
+
* @param {Number} [config.fillLinearGradientStartPointY]
|
|
11472
|
+
* @param {Object} [config.fillLinearGradientEndPoint] object with x and y component
|
|
11473
|
+
* @param {Number} [config.fillLinearGradientEndPointX]
|
|
11474
|
+
* @param {Number} [config.fillLinearGradientEndPointY]
|
|
11475
|
+
* @param {Array} [config.fillLinearGradientColorStops] array of color stops
|
|
11476
|
+
* @param {Object} [config.fillRadialGradientStartPoint] object with x and y component
|
|
11477
|
+
* @param {Number} [config.fillRadialGradientStartPointX]
|
|
11478
|
+
* @param {Number} [config.fillRadialGradientStartPointY]
|
|
11479
|
+
* @param {Object} [config.fillRadialGradientEndPoint] object with x and y component
|
|
11480
|
+
* @param {Number} [config.fillRadialGradientEndPointX]
|
|
11481
|
+
* @param {Number} [config.fillRadialGradientEndPointY]
|
|
11482
|
+
* @param {Number} [config.fillRadialGradientStartRadius]
|
|
11483
|
+
* @param {Number} [config.fillRadialGradientEndRadius]
|
|
11484
|
+
* @param {Array} [config.fillRadialGradientColorStops] array of color stops
|
|
11485
|
+
* @param {Boolean} [config.fillEnabled] flag which enables or disables the fill. The default value is true
|
|
11486
|
+
* @param {String} [config.fillPriority] can be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration
|
|
11487
|
+
* @param {String} [config.stroke] stroke color
|
|
11488
|
+
* @param {Number} [config.strokeWidth] stroke width
|
|
11489
|
+
* @param {Boolean} [config.fillAfterStrokeEnabled]. Should we draw fill AFTER stroke? Default is false.
|
|
11490
|
+
* @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
|
|
11491
|
+
* @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
|
|
11492
|
+
* @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
|
|
11493
|
+
* @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
|
|
11494
|
+
* @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
|
|
11495
|
+
* @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
|
|
11496
|
+
* @param {String} [config.lineJoin] can be miter, round, or bevel. The default
|
|
11497
|
+
* is miter
|
|
11498
|
+
* @param {String} [config.lineCap] can be butt, round, or square. The default
|
|
11499
|
+
* is butt
|
|
11500
|
+
* @param {String} [config.shadowColor]
|
|
11501
|
+
* @param {Number} [config.shadowBlur]
|
|
11502
|
+
* @param {Object} [config.shadowOffset] object with x and y component
|
|
11503
|
+
* @param {Number} [config.shadowOffsetX]
|
|
11504
|
+
* @param {Number} [config.shadowOffsetY]
|
|
11505
|
+
* @param {Number} [config.shadowOpacity] shadow opacity. Can be any real number
|
|
11506
|
+
* between 0 and 1
|
|
11507
|
+
* @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
|
|
11508
|
+
* @param {Array} [config.dash]
|
|
11509
|
+
* @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
|
|
11510
|
+
|
|
11511
|
+
* @param {Number} [config.x]
|
|
11512
|
+
* @param {Number} [config.y]
|
|
11513
|
+
* @param {Number} [config.width]
|
|
11514
|
+
* @param {Number} [config.height]
|
|
11515
|
+
* @param {Boolean} [config.visible]
|
|
11516
|
+
* @param {Boolean} [config.listening] whether or not the node is listening for events
|
|
11517
|
+
* @param {String} [config.id] unique id
|
|
11518
|
+
* @param {String} [config.name] non-unique name
|
|
11519
|
+
* @param {Number} [config.opacity] determines node opacity. Can be any number between 0 and 1
|
|
11520
|
+
* @param {Object} [config.scale] set scale
|
|
11521
|
+
* @param {Number} [config.scaleX] set scale x
|
|
11522
|
+
* @param {Number} [config.scaleY] set scale y
|
|
11523
|
+
* @param {Number} [config.rotation] rotation in degrees
|
|
11524
|
+
* @param {Object} [config.offset] offset from center point and rotation point
|
|
11525
|
+
* @param {Number} [config.offsetX] set offset x
|
|
11526
|
+
* @param {Number} [config.offsetY] set offset y
|
|
11527
|
+
* @param {Boolean} [config.draggable] makes the node draggable. When stages are draggable, you can drag and drop
|
|
11528
|
+
* the entire stage by dragging any portion of the stage
|
|
11529
|
+
* @param {Number} [config.dragDistance]
|
|
11530
|
+
* @param {Function} [config.dragBoundFunc]
|
|
11531
|
+
* @example
|
|
11532
|
+
* var line = new Konva.Line({
|
|
11533
|
+
* x: 100,
|
|
11534
|
+
* y: 50,
|
|
11535
|
+
* points: [73, 70, 340, 23, 450, 60, 500, 20],
|
|
11536
|
+
* stroke: 'red',
|
|
11537
|
+
* tension: 1
|
|
11538
|
+
* });
|
|
11539
|
+
*/
|
|
11540
|
+
class Line extends Shape {
|
|
11541
|
+
constructor(config) {
|
|
11542
|
+
super(config);
|
|
11543
|
+
this.on('pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva', function () {
|
|
11544
|
+
this._clearCache('tensionPoints');
|
|
11545
|
+
});
|
|
11546
|
+
}
|
|
11547
|
+
_hasTension() {
|
|
11548
|
+
return this.tension() !== 0 && this.points().length > 4;
|
|
11549
|
+
}
|
|
11550
|
+
/**
|
|
11551
|
+
* Report every curve segment of a line with a tension, in draw order. Both
|
|
11552
|
+
* the scene function and the bounding rect read the shape through this, so
|
|
11553
|
+
* that they can not disagree about which curve the line is.
|
|
11554
|
+
*
|
|
11555
|
+
* The handlers take plain numbers, because this runs on every frame.
|
|
11556
|
+
*/
|
|
11557
|
+
_eachTensionSegment(onQuadratic, onCubic) {
|
|
11558
|
+
const points = this.points(), length = points.length, closed = this.closed(), tp = this.getTensionPoints(), len = tp.length;
|
|
11559
|
+
let x0 = points[0], y0 = points[1],
|
|
11560
|
+
// a closed line has a curve on both sides of the first point, so it
|
|
11561
|
+
// starts on a full cubic. An open one is capped by a quadratic instead
|
|
11562
|
+
n = closed ? 0 : 4;
|
|
11563
|
+
if (!closed) {
|
|
11564
|
+
onQuadratic(x0, y0, tp[0], tp[1], tp[2], tp[3]);
|
|
11565
|
+
x0 = tp[2];
|
|
11566
|
+
y0 = tp[3];
|
|
11567
|
+
}
|
|
11568
|
+
while (n < len - 2) {
|
|
11569
|
+
const cp1x = tp[n++], cp1y = tp[n++], cp2x = tp[n++], cp2y = tp[n++], x = tp[n++], y = tp[n++];
|
|
11570
|
+
onCubic(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y);
|
|
11571
|
+
x0 = x;
|
|
11572
|
+
y0 = y;
|
|
11573
|
+
}
|
|
11574
|
+
if (!closed) {
|
|
11575
|
+
onQuadratic(x0, y0, tp[len - 2], tp[len - 1], points[length - 2], points[length - 1]);
|
|
11576
|
+
}
|
|
11577
|
+
}
|
|
11578
|
+
_sceneFunc(context) {
|
|
11579
|
+
const points = this.points(), length = points.length, closed = this.closed(), bezier = this.bezier();
|
|
11580
|
+
if (!length) {
|
|
11581
|
+
return;
|
|
11582
|
+
}
|
|
11583
|
+
let n = 0;
|
|
11584
|
+
context.beginPath();
|
|
11585
|
+
context.moveTo(points[0], points[1]);
|
|
11586
|
+
// tension
|
|
11587
|
+
if (this._hasTension()) {
|
|
11588
|
+
this._eachTensionSegment((_x0, _y0, cpx, cpy, x, y) => context.quadraticCurveTo(cpx, cpy, x, y), (_x0, _y0, cp1x, cp1y, cp2x, cp2y, x, y) => context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y));
|
|
11589
|
+
}
|
|
11590
|
+
else if (bezier) {
|
|
11591
|
+
// no tension but bezier
|
|
11592
|
+
n = 2;
|
|
11593
|
+
while (n < length) {
|
|
11594
|
+
context.bezierCurveTo(points[n++], points[n++], points[n++], points[n++], points[n++], points[n++]);
|
|
11595
|
+
}
|
|
11596
|
+
}
|
|
11597
|
+
else {
|
|
11598
|
+
// no tension
|
|
11599
|
+
for (n = 2; n < length; n += 2) {
|
|
11600
|
+
context.lineTo(points[n], points[n + 1]);
|
|
11601
|
+
}
|
|
11602
|
+
}
|
|
11603
|
+
// closed e.g. polygons and blobs
|
|
11604
|
+
if (closed) {
|
|
11605
|
+
context.closePath();
|
|
11606
|
+
context.fillStrokeShape(this);
|
|
11607
|
+
}
|
|
11608
|
+
else {
|
|
11609
|
+
// open e.g. lines and splines
|
|
11610
|
+
context.strokeShape(this);
|
|
11611
|
+
}
|
|
11612
|
+
}
|
|
11613
|
+
getTensionPoints() {
|
|
11614
|
+
return this._getCache('tensionPoints', this._getTensionPoints);
|
|
11615
|
+
}
|
|
11616
|
+
_getTensionPoints() {
|
|
11617
|
+
if (this.closed()) {
|
|
11618
|
+
return this._getTensionPointsClosed();
|
|
11619
|
+
}
|
|
11620
|
+
else {
|
|
11621
|
+
return expandPoints(this.points(), this.tension());
|
|
11622
|
+
}
|
|
11623
|
+
}
|
|
11624
|
+
_getTensionPointsClosed() {
|
|
11625
|
+
const p = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]]
|
|
11626
|
+
.concat(middle)
|
|
11627
|
+
.concat([
|
|
11628
|
+
lastControlPoints[0],
|
|
11629
|
+
lastControlPoints[1],
|
|
11630
|
+
p[len - 2],
|
|
11631
|
+
p[len - 1],
|
|
11632
|
+
lastControlPoints[2],
|
|
11633
|
+
lastControlPoints[3],
|
|
11634
|
+
firstControlPoints[0],
|
|
11635
|
+
firstControlPoints[1],
|
|
11636
|
+
p[0],
|
|
11637
|
+
p[1],
|
|
11638
|
+
]);
|
|
11639
|
+
return tp;
|
|
11640
|
+
}
|
|
11641
|
+
getWidth() {
|
|
11642
|
+
return this.getSelfRect().width;
|
|
11643
|
+
}
|
|
11644
|
+
getHeight() {
|
|
11645
|
+
return this.getSelfRect().height;
|
|
11646
|
+
}
|
|
11647
|
+
// overload size detection
|
|
11648
|
+
getSelfRect() {
|
|
11649
|
+
let points = this.points();
|
|
11650
|
+
if (points.length < 4) {
|
|
11651
|
+
return {
|
|
11652
|
+
x: points[0] || 0,
|
|
11653
|
+
y: points[1] || 0,
|
|
11654
|
+
width: 0,
|
|
11655
|
+
height: 0,
|
|
11656
|
+
};
|
|
11657
|
+
}
|
|
11658
|
+
if (this._hasTension()) {
|
|
11659
|
+
// the two end points of every segment, plus the points where it turns
|
|
11660
|
+
// back on either axis. Together they are the exact bounds of the curve
|
|
11661
|
+
const bounds = [points[0], points[1]];
|
|
11662
|
+
this._eachTensionSegment((x0, y0, cpx, cpy, x, y) => bounds.push(x, y, ...getQuadraticExtremaPoints(x0, y0, cpx, cpy, x, y)), (x0, y0, cp1x, cp1y, cp2x, cp2y, x, y) => bounds.push(x, y, ...getCubicExtremaPoints(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y)));
|
|
11663
|
+
points = bounds;
|
|
11664
|
+
}
|
|
11665
|
+
else if (this.bezier()) {
|
|
11666
|
+
// no trailing point here: the extrema already carry the end point of
|
|
11667
|
+
// every segment that is drawn. Adding the last pair of the array back
|
|
11668
|
+
// would include a control point of a trailing partial segment, which
|
|
11669
|
+
// _sceneFunc never draws.
|
|
11670
|
+
points = [points[0], points[1], ...getBezierExtremaPoints(points)];
|
|
11671
|
+
}
|
|
11672
|
+
let minX = points[0];
|
|
11673
|
+
let maxX = points[0];
|
|
11674
|
+
let minY = points[1];
|
|
11675
|
+
let maxY = points[1];
|
|
11676
|
+
let x, y;
|
|
11677
|
+
for (let i = 0; i < points.length / 2; i++) {
|
|
11678
|
+
x = points[i * 2];
|
|
11679
|
+
y = points[i * 2 + 1];
|
|
11680
|
+
minX = Math.min(minX, x);
|
|
11681
|
+
maxX = Math.max(maxX, x);
|
|
11682
|
+
minY = Math.min(minY, y);
|
|
11683
|
+
maxY = Math.max(maxY, y);
|
|
11684
|
+
}
|
|
11685
|
+
return {
|
|
11686
|
+
x: minX,
|
|
11687
|
+
y: minY,
|
|
11688
|
+
width: maxX - minX,
|
|
11689
|
+
height: maxY - minY,
|
|
11690
|
+
};
|
|
11691
|
+
}
|
|
11692
|
+
}
|
|
11693
|
+
Line.prototype.className = 'Line';
|
|
11694
|
+
Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension'];
|
|
11695
|
+
_registerNode(Line);
|
|
11696
|
+
// add getters setters
|
|
11697
|
+
Factory.addGetterSetter(Line, 'closed', false);
|
|
11698
|
+
/**
|
|
11699
|
+
* get/set closed flag. The default is false
|
|
11700
|
+
* @name Konva.Line#closed
|
|
11701
|
+
* @method
|
|
11702
|
+
* @param {Boolean} closed
|
|
11703
|
+
* @returns {Boolean}
|
|
11704
|
+
* @example
|
|
11705
|
+
* // get closed flag
|
|
11706
|
+
* var closed = line.closed();
|
|
11707
|
+
*
|
|
11708
|
+
* // close the shape
|
|
11709
|
+
* line.closed(true);
|
|
11710
|
+
*
|
|
11711
|
+
* // open the shape
|
|
11712
|
+
* line.closed(false);
|
|
11713
|
+
*/
|
|
11714
|
+
Factory.addGetterSetter(Line, 'bezier', false);
|
|
11715
|
+
/**
|
|
11716
|
+
* get/set bezier flag. The default is false
|
|
11717
|
+
* @name Konva.Line#bezier
|
|
11718
|
+
* @method
|
|
11719
|
+
* @param {Boolean} bezier
|
|
11720
|
+
* @returns {Boolean}
|
|
11721
|
+
* @example
|
|
11722
|
+
* // get whether the line is a bezier
|
|
11723
|
+
* var isBezier = line.bezier();
|
|
11724
|
+
*
|
|
11725
|
+
* // set whether the line is a bezier
|
|
11726
|
+
* line.bezier(true);
|
|
11727
|
+
*/
|
|
11728
|
+
Factory.addGetterSetter(Line, 'tension', 0, getNumberValidator());
|
|
11729
|
+
/**
|
|
11730
|
+
* get/set tension
|
|
11731
|
+
* @name Konva.Line#tension
|
|
11732
|
+
* @method
|
|
11733
|
+
* @param {Number} tension Higher values will result in a more curvy line. A value of 0 will result in no interpolation. The default is 0
|
|
11734
|
+
* @returns {Number}
|
|
11735
|
+
* @example
|
|
11736
|
+
* // get tension
|
|
11737
|
+
* var tension = line.tension();
|
|
11738
|
+
*
|
|
11739
|
+
* // set tension
|
|
11740
|
+
* line.tension(3);
|
|
11741
|
+
*/
|
|
11742
|
+
Factory.addGetterSetter(Line, 'points', [], getNumberArrayValidator());
|
|
11743
|
+
/**
|
|
11744
|
+
* get/set points array. Points is a flat array [x1, y1, x2, y2]. It is flat for performance reasons.
|
|
11745
|
+
* @name Konva.Line#points
|
|
11746
|
+
* @method
|
|
11747
|
+
* @param {Array} points
|
|
11748
|
+
* @returns {Array}
|
|
11749
|
+
* @example
|
|
11750
|
+
* // get points
|
|
11751
|
+
* var points = line.points();
|
|
11752
|
+
*
|
|
11753
|
+
* // set points
|
|
11754
|
+
* line.points([10, 20, 30, 40, 50, 60]);
|
|
11755
|
+
*
|
|
11756
|
+
* // push a new point
|
|
11757
|
+
* line.points(line.points().concat([70, 80]));
|
|
11758
|
+
*/
|
|
11597
11759
|
|
|
11598
11760
|
/**
|
|
11599
11761
|
* Path constructor.
|
|
@@ -11779,14 +11941,16 @@ js: import "konva/skia-backend";
|
|
|
11779
11941
|
}
|
|
11780
11942
|
}
|
|
11781
11943
|
else if (data.command === 'C') {
|
|
11782
|
-
//
|
|
11783
|
-
|
|
11784
|
-
|
|
11785
|
-
|
|
11786
|
-
|
|
11944
|
+
// the two end points, plus the points where the curve turns back on
|
|
11945
|
+
// either axis. Together they are the exact bounds of the segment
|
|
11946
|
+
points.push(data.start.x, data.start.y, data.points[4], data.points[5], ...getCubicExtremaPoints(data.start.x, data.start.y, data.points[0], data.points[1], data.points[2], data.points[3], data.points[4], data.points[5]));
|
|
11947
|
+
}
|
|
11948
|
+
else if (data.command === 'Q') {
|
|
11949
|
+
// same as 'C'. Note that 'q', 'T' and 't' are all normalised to 'Q' by
|
|
11950
|
+
// the parser, so this one branch covers every quadratic segment
|
|
11951
|
+
points.push(data.start.x, data.start.y, data.points[2], data.points[3], ...getQuadraticExtremaPoints(data.start.x, data.start.y, data.points[0], data.points[1], data.points[2], data.points[3]));
|
|
11787
11952
|
}
|
|
11788
11953
|
else {
|
|
11789
|
-
// TODO: how can we calculate bezier curves better?
|
|
11790
11954
|
points = points.concat(data.points);
|
|
11791
11955
|
}
|
|
11792
11956
|
});
|
|
@@ -11858,7 +12022,11 @@ js: import "konva/skia-backend";
|
|
|
11858
12022
|
++i;
|
|
11859
12023
|
}
|
|
11860
12024
|
if (i === ii) {
|
|
11861
|
-
|
|
12025
|
+
let j = i - 1;
|
|
12026
|
+
while (j > 0 && dataArray[j].points.length < 2) {
|
|
12027
|
+
j--;
|
|
12028
|
+
}
|
|
12029
|
+
points = dataArray[j].points.slice(-2);
|
|
11862
12030
|
return {
|
|
11863
12031
|
x: points[0],
|
|
11864
12032
|
y: points[1],
|
|
@@ -15171,16 +15339,21 @@ js: import "konva/skia-backend";
|
|
|
15171
15339
|
* break the line into multiple fitting lines
|
|
15172
15340
|
*/
|
|
15173
15341
|
while (line.length > 0) {
|
|
15342
|
+
// Compute the grapheme array once per iteration. `line` is constant
|
|
15343
|
+
// within this block (only reassigned at the bottom), so calling
|
|
15344
|
+
// `stringToArray(line)` inside the binary search and again afterwards
|
|
15345
|
+
// is redundant and makes resize O(N·logN) on long text.
|
|
15346
|
+
const lineArray = stringToArray(line);
|
|
15174
15347
|
/*
|
|
15175
15348
|
* use binary search to find the longest substring that
|
|
15176
15349
|
* that would fit in the specified width
|
|
15177
15350
|
*/
|
|
15178
|
-
let low = 0, high =
|
|
15351
|
+
let low = 0, high = lineArray.length, // Convert to array for proper emoji handling
|
|
15179
15352
|
match = '', matchWidth = 0;
|
|
15180
15353
|
while (low < high) {
|
|
15181
15354
|
const mid = (low + high) >>> 1,
|
|
15182
15355
|
// Convert array indices to string
|
|
15183
|
-
|
|
15356
|
+
substr = lineArray.slice(0, mid + 1).join(''), substrWidth = this._getTextWidth(substr);
|
|
15184
15357
|
// Only add ellipsis width when we need to consider truncation
|
|
15185
15358
|
// for the current line (when it might be the last visible line)
|
|
15186
15359
|
const shouldConsiderEllipsis = shouldAddEllipsis &&
|
|
@@ -15207,7 +15380,6 @@ js: import "konva/skia-backend";
|
|
|
15207
15380
|
// a fitting substring was found
|
|
15208
15381
|
if (wrapAtWord) {
|
|
15209
15382
|
// try to find a space or dash where wrapping could be done
|
|
15210
|
-
const lineArray = stringToArray(line);
|
|
15211
15383
|
const matchArray = stringToArray(match);
|
|
15212
15384
|
const nextChar = lineArray[matchArray.length];
|
|
15213
15385
|
const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
|
|
@@ -15242,8 +15414,7 @@ js: import "konva/skia-backend";
|
|
|
15242
15414
|
*/
|
|
15243
15415
|
break;
|
|
15244
15416
|
}
|
|
15245
|
-
//
|
|
15246
|
-
const lineArray = stringToArray(line);
|
|
15417
|
+
// Reuse the cached `lineArray` to compute the remaining text.
|
|
15247
15418
|
line = lineArray.slice(low).join('').trimLeft();
|
|
15248
15419
|
if (line.length > 0) {
|
|
15249
15420
|
lineWidth = this._getTextWidth(line);
|
|
@@ -15749,7 +15920,7 @@ js: import "konva/skia-backend";
|
|
|
15749
15920
|
this._setTextData();
|
|
15750
15921
|
});
|
|
15751
15922
|
// update text data for certain attr changes
|
|
15752
|
-
this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
|
|
15923
|
+
this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva directionChange.konva', this._setTextData);
|
|
15753
15924
|
this._setTextData();
|
|
15754
15925
|
}
|
|
15755
15926
|
_getTextPathLength() {
|
|
@@ -15878,6 +16049,15 @@ js: import "konva/skia-backend";
|
|
|
15878
16049
|
}
|
|
15879
16050
|
_setTextData() {
|
|
15880
16051
|
const charArr = stringToArray(this.text());
|
|
16052
|
+
// For RTL scripts (Hebrew, Arabic, …) the path is still walked left to
|
|
16053
|
+
// right by glyph index, so we lay glyphs out in reversed logical order.
|
|
16054
|
+
// A reader scanning the path right-to-left then sees the text in its
|
|
16055
|
+
// intended reading order. This does not perform full Unicode bidi or
|
|
16056
|
+
// Arabic cursive shaping — those need a real shaping engine — but it
|
|
16057
|
+
// makes pure RTL strings render in the right direction.
|
|
16058
|
+
if (this.direction() === 'rtl') {
|
|
16059
|
+
charArr.reverse();
|
|
16060
|
+
}
|
|
15881
16061
|
const chars = [];
|
|
15882
16062
|
let width = 0;
|
|
15883
16063
|
for (let i = 0; i < charArr.length; i++) {
|
|
@@ -16185,6 +16365,28 @@ js: import "konva/skia-backend";
|
|
|
16185
16365
|
* });
|
|
16186
16366
|
*/
|
|
16187
16367
|
Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
|
|
16368
|
+
/**
|
|
16369
|
+
* get/set text direction. Can be 'inherit', 'ltr' or 'rtl'. Default is 'inherit'.
|
|
16370
|
+
*
|
|
16371
|
+
* Setting `'rtl'` reverses the per-glyph layout order along the path, so
|
|
16372
|
+
* Hebrew/Arabic strings read correctly when scanned right-to-left. This is a
|
|
16373
|
+
* pragmatic fix limited by canvas TextPath rendering: each glyph is still
|
|
16374
|
+
* drawn independently, so Arabic cursive joining and full Unicode bidi
|
|
16375
|
+
* reordering of mixed-direction text are not supported. For best results,
|
|
16376
|
+
* pair `direction: 'rtl'` with `align: 'right'` so the text starts at the
|
|
16377
|
+
* end of the path.
|
|
16378
|
+
* @name Konva.TextPath#direction
|
|
16379
|
+
* @method
|
|
16380
|
+
* @param {String} direction
|
|
16381
|
+
* @returns {String}
|
|
16382
|
+
* @example
|
|
16383
|
+
* // get direction
|
|
16384
|
+
* var direction = textpath.direction();
|
|
16385
|
+
*
|
|
16386
|
+
* // set direction
|
|
16387
|
+
* textpath.direction('rtl');
|
|
16388
|
+
*/
|
|
16389
|
+
Factory.addGetterSetter(TextPath, 'direction', 'inherit');
|
|
16188
16390
|
|
|
16189
16391
|
const EVENTS_NAME = 'tr-konva';
|
|
16190
16392
|
const ATTR_CHANGE_LIST = [
|
|
@@ -16376,6 +16578,7 @@ js: import "konva/skia-backend";
|
|
|
16376
16578
|
this._movingAnchorName = null;
|
|
16377
16579
|
this._transforming = false;
|
|
16378
16580
|
this._elementsCreated = false;
|
|
16581
|
+
this._updateScheduled = false;
|
|
16379
16582
|
this._createElements();
|
|
16380
16583
|
// bindings
|
|
16381
16584
|
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
@@ -16430,12 +16633,22 @@ js: import "konva/skia-backend";
|
|
|
16430
16633
|
}
|
|
16431
16634
|
this._nodes.forEach((node) => {
|
|
16432
16635
|
const onChange = () => {
|
|
16636
|
+
// Perf: skip during anchor drag — _fitNodesInto does the final
|
|
16637
|
+
// _resetTransformCache + update itself, so per-attr fan-out here is
|
|
16638
|
+
// pure waste (was O(N*events) per resize step).
|
|
16639
|
+
if (this._transforming)
|
|
16640
|
+
return;
|
|
16433
16641
|
if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
|
|
16434
16642
|
this.rotation(this.nodes()[0].getAbsoluteRotation());
|
|
16435
16643
|
}
|
|
16644
|
+
// Cache reset stays synchronous so sync reads of tr.x() etc. are fresh.
|
|
16436
16645
|
this._resetTransformCache();
|
|
16437
|
-
if (!this.
|
|
16438
|
-
|
|
16646
|
+
if (!this.isDragging()) {
|
|
16647
|
+
// Perf: an ancestor cascade (e.g. stage drag) fires
|
|
16648
|
+
// absoluteTransformChange on every attached node — without batching,
|
|
16649
|
+
// update() runs once per node and each call walks all N nodes via
|
|
16650
|
+
// __getNodeRect, giving O(N^2) per drag frame.
|
|
16651
|
+
this._scheduleUpdate();
|
|
16439
16652
|
}
|
|
16440
16653
|
};
|
|
16441
16654
|
if (node._attrsAffectingSize.length) {
|
|
@@ -17023,6 +17236,19 @@ js: import "konva/skia-backend";
|
|
|
17023
17236
|
}
|
|
17024
17237
|
}
|
|
17025
17238
|
_fitNodesInto(newAttrs, evt) {
|
|
17239
|
+
// Perf: suspend autoDraw for the whole method so per-attr _setAttr writes
|
|
17240
|
+
// don't each trigger _requestDraw -> getLayer parent-chain walks.
|
|
17241
|
+
// batchDraw per affected layer is issued at the end.
|
|
17242
|
+
const prevAutoDraw = Konva$2.autoDrawEnabled;
|
|
17243
|
+
Konva$2.autoDrawEnabled = false;
|
|
17244
|
+
try {
|
|
17245
|
+
return this._doFitNodesInto(newAttrs, evt);
|
|
17246
|
+
}
|
|
17247
|
+
finally {
|
|
17248
|
+
Konva$2.autoDrawEnabled = prevAutoDraw;
|
|
17249
|
+
}
|
|
17250
|
+
}
|
|
17251
|
+
_doFitNodesInto(newAttrs, evt) {
|
|
17026
17252
|
const oldAttrs = this._getNodeRect();
|
|
17027
17253
|
const minSize = 1;
|
|
17028
17254
|
if (Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) {
|
|
@@ -17126,8 +17352,10 @@ js: import "konva/skia-backend";
|
|
|
17126
17352
|
// that means that
|
|
17127
17353
|
// [delta transform] = [new transform] * [old transform inverted]
|
|
17128
17354
|
const delta = newTr.multiply(oldTr.invert());
|
|
17355
|
+
// Perf: collect unique affected layers and batchDraw each once at the end
|
|
17356
|
+
// (was once per node — O(N)).
|
|
17357
|
+
const layersToDraw = new Set();
|
|
17129
17358
|
this._nodes.forEach((node) => {
|
|
17130
|
-
var _a;
|
|
17131
17359
|
// check to close this issue: https://github.com/konvajs/konva/issues/1957
|
|
17132
17360
|
// a node can be destroyed during the transformation
|
|
17133
17361
|
// probably a developer must remove it from transformer
|
|
@@ -17155,7 +17383,10 @@ js: import "konva/skia-backend";
|
|
|
17155
17383
|
.multiply(localTransform);
|
|
17156
17384
|
const attrs = newLocalTransform.decompose();
|
|
17157
17385
|
node.setAttrs(attrs);
|
|
17158
|
-
|
|
17386
|
+
const layer = node.getLayer();
|
|
17387
|
+
if (layer) {
|
|
17388
|
+
layersToDraw.add(layer);
|
|
17389
|
+
}
|
|
17159
17390
|
});
|
|
17160
17391
|
this.rotation(Util._getRotation(newAttrs.rotation));
|
|
17161
17392
|
// trigger transform event AFTER we update rotation
|
|
@@ -17165,7 +17396,24 @@ js: import "konva/skia-backend";
|
|
|
17165
17396
|
});
|
|
17166
17397
|
this._resetTransformCache();
|
|
17167
17398
|
this.update();
|
|
17168
|
-
this.getLayer()
|
|
17399
|
+
layersToDraw.add(this.getLayer());
|
|
17400
|
+
layersToDraw.forEach((layer) => layer && layer.batchDraw());
|
|
17401
|
+
}
|
|
17402
|
+
// Inside an absoluteTransform cascade, queue a single update to run when
|
|
17403
|
+
// the cascade ends; outside a cascade, run synchronously so reads of
|
|
17404
|
+
// transformer state stay consistent.
|
|
17405
|
+
_scheduleUpdate() {
|
|
17406
|
+
if (this._updateScheduled)
|
|
17407
|
+
return;
|
|
17408
|
+
this._updateScheduled = true;
|
|
17409
|
+
Node._runAfterAbsTransformCascade(() => {
|
|
17410
|
+
var _a;
|
|
17411
|
+
this._updateScheduled = false;
|
|
17412
|
+
if (!((_a = this._nodes) === null || _a === void 0 ? void 0 : _a.length) || this._transforming || this.isDragging()) {
|
|
17413
|
+
return;
|
|
17414
|
+
}
|
|
17415
|
+
this.update();
|
|
17416
|
+
});
|
|
17169
17417
|
}
|
|
17170
17418
|
/**
|
|
17171
17419
|
* force update of Konva.Transformer.
|