1 | import {
|
---|
2 | require_Global
|
---|
3 | } from "./chunk-M3JPOOL7.js";
|
---|
4 | import {
|
---|
5 | __commonJS
|
---|
6 | } from "./chunk-V4OQ3NZ2.js";
|
---|
7 |
|
---|
8 | // node_modules/konva/lib/Util.js
|
---|
9 | var require_Util = __commonJS({
|
---|
10 | "node_modules/konva/lib/Util.js"(exports) {
|
---|
11 | "use strict";
|
---|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
13 | exports.Util = exports.Transform = void 0;
|
---|
14 | var Global_1 = require_Global();
|
---|
15 | var Transform = class _Transform {
|
---|
16 | constructor(m = [1, 0, 0, 1, 0, 0]) {
|
---|
17 | this.dirty = false;
|
---|
18 | this.m = m && m.slice() || [1, 0, 0, 1, 0, 0];
|
---|
19 | }
|
---|
20 | reset() {
|
---|
21 | this.m[0] = 1;
|
---|
22 | this.m[1] = 0;
|
---|
23 | this.m[2] = 0;
|
---|
24 | this.m[3] = 1;
|
---|
25 | this.m[4] = 0;
|
---|
26 | this.m[5] = 0;
|
---|
27 | }
|
---|
28 | copy() {
|
---|
29 | return new _Transform(this.m);
|
---|
30 | }
|
---|
31 | copyInto(tr) {
|
---|
32 | tr.m[0] = this.m[0];
|
---|
33 | tr.m[1] = this.m[1];
|
---|
34 | tr.m[2] = this.m[2];
|
---|
35 | tr.m[3] = this.m[3];
|
---|
36 | tr.m[4] = this.m[4];
|
---|
37 | tr.m[5] = this.m[5];
|
---|
38 | }
|
---|
39 | point(point) {
|
---|
40 | var m = this.m;
|
---|
41 | return {
|
---|
42 | x: m[0] * point.x + m[2] * point.y + m[4],
|
---|
43 | y: m[1] * point.x + m[3] * point.y + m[5]
|
---|
44 | };
|
---|
45 | }
|
---|
46 | translate(x, y) {
|
---|
47 | this.m[4] += this.m[0] * x + this.m[2] * y;
|
---|
48 | this.m[5] += this.m[1] * x + this.m[3] * y;
|
---|
49 | return this;
|
---|
50 | }
|
---|
51 | scale(sx, sy) {
|
---|
52 | this.m[0] *= sx;
|
---|
53 | this.m[1] *= sx;
|
---|
54 | this.m[2] *= sy;
|
---|
55 | this.m[3] *= sy;
|
---|
56 | return this;
|
---|
57 | }
|
---|
58 | rotate(rad) {
|
---|
59 | var c = Math.cos(rad);
|
---|
60 | var s = Math.sin(rad);
|
---|
61 | var m11 = this.m[0] * c + this.m[2] * s;
|
---|
62 | var m12 = this.m[1] * c + this.m[3] * s;
|
---|
63 | var m21 = this.m[0] * -s + this.m[2] * c;
|
---|
64 | var m22 = this.m[1] * -s + this.m[3] * c;
|
---|
65 | this.m[0] = m11;
|
---|
66 | this.m[1] = m12;
|
---|
67 | this.m[2] = m21;
|
---|
68 | this.m[3] = m22;
|
---|
69 | return this;
|
---|
70 | }
|
---|
71 | getTranslation() {
|
---|
72 | return {
|
---|
73 | x: this.m[4],
|
---|
74 | y: this.m[5]
|
---|
75 | };
|
---|
76 | }
|
---|
77 | skew(sx, sy) {
|
---|
78 | var m11 = this.m[0] + this.m[2] * sy;
|
---|
79 | var m12 = this.m[1] + this.m[3] * sy;
|
---|
80 | var m21 = this.m[2] + this.m[0] * sx;
|
---|
81 | var m22 = this.m[3] + this.m[1] * sx;
|
---|
82 | this.m[0] = m11;
|
---|
83 | this.m[1] = m12;
|
---|
84 | this.m[2] = m21;
|
---|
85 | this.m[3] = m22;
|
---|
86 | return this;
|
---|
87 | }
|
---|
88 | multiply(matrix) {
|
---|
89 | var m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];
|
---|
90 | var m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];
|
---|
91 | var m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];
|
---|
92 | var m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];
|
---|
93 | var dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];
|
---|
94 | var dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];
|
---|
95 | this.m[0] = m11;
|
---|
96 | this.m[1] = m12;
|
---|
97 | this.m[2] = m21;
|
---|
98 | this.m[3] = m22;
|
---|
99 | this.m[4] = dx;
|
---|
100 | this.m[5] = dy;
|
---|
101 | return this;
|
---|
102 | }
|
---|
103 | invert() {
|
---|
104 | var d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);
|
---|
105 | var m0 = this.m[3] * d;
|
---|
106 | var m1 = -this.m[1] * d;
|
---|
107 | var m2 = -this.m[2] * d;
|
---|
108 | var m3 = this.m[0] * d;
|
---|
109 | var m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);
|
---|
110 | var m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
|
---|
111 | this.m[0] = m0;
|
---|
112 | this.m[1] = m1;
|
---|
113 | this.m[2] = m2;
|
---|
114 | this.m[3] = m3;
|
---|
115 | this.m[4] = m4;
|
---|
116 | this.m[5] = m5;
|
---|
117 | return this;
|
---|
118 | }
|
---|
119 | getMatrix() {
|
---|
120 | return this.m;
|
---|
121 | }
|
---|
122 | decompose() {
|
---|
123 | var a = this.m[0];
|
---|
124 | var b = this.m[1];
|
---|
125 | var c = this.m[2];
|
---|
126 | var d = this.m[3];
|
---|
127 | var e = this.m[4];
|
---|
128 | var f = this.m[5];
|
---|
129 | var delta = a * d - b * c;
|
---|
130 | let result = {
|
---|
131 | x: e,
|
---|
132 | y: f,
|
---|
133 | rotation: 0,
|
---|
134 | scaleX: 0,
|
---|
135 | scaleY: 0,
|
---|
136 | skewX: 0,
|
---|
137 | skewY: 0
|
---|
138 | };
|
---|
139 | if (a != 0 || b != 0) {
|
---|
140 | var r = Math.sqrt(a * a + b * b);
|
---|
141 | result.rotation = b > 0 ? Math.acos(a / r) : -Math.acos(a / r);
|
---|
142 | result.scaleX = r;
|
---|
143 | result.scaleY = delta / r;
|
---|
144 | result.skewX = (a * c + b * d) / delta;
|
---|
145 | result.skewY = 0;
|
---|
146 | } else if (c != 0 || d != 0) {
|
---|
147 | var s = Math.sqrt(c * c + d * d);
|
---|
148 | result.rotation = Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
|
---|
149 | result.scaleX = delta / s;
|
---|
150 | result.scaleY = s;
|
---|
151 | result.skewX = 0;
|
---|
152 | result.skewY = (a * c + b * d) / delta;
|
---|
153 | } else {
|
---|
154 | }
|
---|
155 | result.rotation = exports.Util._getRotation(result.rotation);
|
---|
156 | return result;
|
---|
157 | }
|
---|
158 | };
|
---|
159 | exports.Transform = Transform;
|
---|
160 | var OBJECT_ARRAY = "[object Array]";
|
---|
161 | var OBJECT_NUMBER = "[object Number]";
|
---|
162 | var OBJECT_STRING = "[object String]";
|
---|
163 | var OBJECT_BOOLEAN = "[object Boolean]";
|
---|
164 | var PI_OVER_DEG180 = Math.PI / 180;
|
---|
165 | var DEG180_OVER_PI = 180 / Math.PI;
|
---|
166 | var HASH = "#";
|
---|
167 | var EMPTY_STRING = "";
|
---|
168 | var ZERO = "0";
|
---|
169 | var KONVA_WARNING = "Konva warning: ";
|
---|
170 | var KONVA_ERROR = "Konva error: ";
|
---|
171 | var RGB_PAREN = "rgb(";
|
---|
172 | var COLORS = {
|
---|
173 | aliceblue: [240, 248, 255],
|
---|
174 | antiquewhite: [250, 235, 215],
|
---|
175 | aqua: [0, 255, 255],
|
---|
176 | aquamarine: [127, 255, 212],
|
---|
177 | azure: [240, 255, 255],
|
---|
178 | beige: [245, 245, 220],
|
---|
179 | bisque: [255, 228, 196],
|
---|
180 | black: [0, 0, 0],
|
---|
181 | blanchedalmond: [255, 235, 205],
|
---|
182 | blue: [0, 0, 255],
|
---|
183 | blueviolet: [138, 43, 226],
|
---|
184 | brown: [165, 42, 42],
|
---|
185 | burlywood: [222, 184, 135],
|
---|
186 | cadetblue: [95, 158, 160],
|
---|
187 | chartreuse: [127, 255, 0],
|
---|
188 | chocolate: [210, 105, 30],
|
---|
189 | coral: [255, 127, 80],
|
---|
190 | cornflowerblue: [100, 149, 237],
|
---|
191 | cornsilk: [255, 248, 220],
|
---|
192 | crimson: [220, 20, 60],
|
---|
193 | cyan: [0, 255, 255],
|
---|
194 | darkblue: [0, 0, 139],
|
---|
195 | darkcyan: [0, 139, 139],
|
---|
196 | darkgoldenrod: [184, 132, 11],
|
---|
197 | darkgray: [169, 169, 169],
|
---|
198 | darkgreen: [0, 100, 0],
|
---|
199 | darkgrey: [169, 169, 169],
|
---|
200 | darkkhaki: [189, 183, 107],
|
---|
201 | darkmagenta: [139, 0, 139],
|
---|
202 | darkolivegreen: [85, 107, 47],
|
---|
203 | darkorange: [255, 140, 0],
|
---|
204 | darkorchid: [153, 50, 204],
|
---|
205 | darkred: [139, 0, 0],
|
---|
206 | darksalmon: [233, 150, 122],
|
---|
207 | darkseagreen: [143, 188, 143],
|
---|
208 | darkslateblue: [72, 61, 139],
|
---|
209 | darkslategray: [47, 79, 79],
|
---|
210 | darkslategrey: [47, 79, 79],
|
---|
211 | darkturquoise: [0, 206, 209],
|
---|
212 | darkviolet: [148, 0, 211],
|
---|
213 | deeppink: [255, 20, 147],
|
---|
214 | deepskyblue: [0, 191, 255],
|
---|
215 | dimgray: [105, 105, 105],
|
---|
216 | dimgrey: [105, 105, 105],
|
---|
217 | dodgerblue: [30, 144, 255],
|
---|
218 | firebrick: [178, 34, 34],
|
---|
219 | floralwhite: [255, 255, 240],
|
---|
220 | forestgreen: [34, 139, 34],
|
---|
221 | fuchsia: [255, 0, 255],
|
---|
222 | gainsboro: [220, 220, 220],
|
---|
223 | ghostwhite: [248, 248, 255],
|
---|
224 | gold: [255, 215, 0],
|
---|
225 | goldenrod: [218, 165, 32],
|
---|
226 | gray: [128, 128, 128],
|
---|
227 | green: [0, 128, 0],
|
---|
228 | greenyellow: [173, 255, 47],
|
---|
229 | grey: [128, 128, 128],
|
---|
230 | honeydew: [240, 255, 240],
|
---|
231 | hotpink: [255, 105, 180],
|
---|
232 | indianred: [205, 92, 92],
|
---|
233 | indigo: [75, 0, 130],
|
---|
234 | ivory: [255, 255, 240],
|
---|
235 | khaki: [240, 230, 140],
|
---|
236 | lavender: [230, 230, 250],
|
---|
237 | lavenderblush: [255, 240, 245],
|
---|
238 | lawngreen: [124, 252, 0],
|
---|
239 | lemonchiffon: [255, 250, 205],
|
---|
240 | lightblue: [173, 216, 230],
|
---|
241 | lightcoral: [240, 128, 128],
|
---|
242 | lightcyan: [224, 255, 255],
|
---|
243 | lightgoldenrodyellow: [250, 250, 210],
|
---|
244 | lightgray: [211, 211, 211],
|
---|
245 | lightgreen: [144, 238, 144],
|
---|
246 | lightgrey: [211, 211, 211],
|
---|
247 | lightpink: [255, 182, 193],
|
---|
248 | lightsalmon: [255, 160, 122],
|
---|
249 | lightseagreen: [32, 178, 170],
|
---|
250 | lightskyblue: [135, 206, 250],
|
---|
251 | lightslategray: [119, 136, 153],
|
---|
252 | lightslategrey: [119, 136, 153],
|
---|
253 | lightsteelblue: [176, 196, 222],
|
---|
254 | lightyellow: [255, 255, 224],
|
---|
255 | lime: [0, 255, 0],
|
---|
256 | limegreen: [50, 205, 50],
|
---|
257 | linen: [250, 240, 230],
|
---|
258 | magenta: [255, 0, 255],
|
---|
259 | maroon: [128, 0, 0],
|
---|
260 | mediumaquamarine: [102, 205, 170],
|
---|
261 | mediumblue: [0, 0, 205],
|
---|
262 | mediumorchid: [186, 85, 211],
|
---|
263 | mediumpurple: [147, 112, 219],
|
---|
264 | mediumseagreen: [60, 179, 113],
|
---|
265 | mediumslateblue: [123, 104, 238],
|
---|
266 | mediumspringgreen: [0, 250, 154],
|
---|
267 | mediumturquoise: [72, 209, 204],
|
---|
268 | mediumvioletred: [199, 21, 133],
|
---|
269 | midnightblue: [25, 25, 112],
|
---|
270 | mintcream: [245, 255, 250],
|
---|
271 | mistyrose: [255, 228, 225],
|
---|
272 | moccasin: [255, 228, 181],
|
---|
273 | navajowhite: [255, 222, 173],
|
---|
274 | navy: [0, 0, 128],
|
---|
275 | oldlace: [253, 245, 230],
|
---|
276 | olive: [128, 128, 0],
|
---|
277 | olivedrab: [107, 142, 35],
|
---|
278 | orange: [255, 165, 0],
|
---|
279 | orangered: [255, 69, 0],
|
---|
280 | orchid: [218, 112, 214],
|
---|
281 | palegoldenrod: [238, 232, 170],
|
---|
282 | palegreen: [152, 251, 152],
|
---|
283 | paleturquoise: [175, 238, 238],
|
---|
284 | palevioletred: [219, 112, 147],
|
---|
285 | papayawhip: [255, 239, 213],
|
---|
286 | peachpuff: [255, 218, 185],
|
---|
287 | peru: [205, 133, 63],
|
---|
288 | pink: [255, 192, 203],
|
---|
289 | plum: [221, 160, 203],
|
---|
290 | powderblue: [176, 224, 230],
|
---|
291 | purple: [128, 0, 128],
|
---|
292 | rebeccapurple: [102, 51, 153],
|
---|
293 | red: [255, 0, 0],
|
---|
294 | rosybrown: [188, 143, 143],
|
---|
295 | royalblue: [65, 105, 225],
|
---|
296 | saddlebrown: [139, 69, 19],
|
---|
297 | salmon: [250, 128, 114],
|
---|
298 | sandybrown: [244, 164, 96],
|
---|
299 | seagreen: [46, 139, 87],
|
---|
300 | seashell: [255, 245, 238],
|
---|
301 | sienna: [160, 82, 45],
|
---|
302 | silver: [192, 192, 192],
|
---|
303 | skyblue: [135, 206, 235],
|
---|
304 | slateblue: [106, 90, 205],
|
---|
305 | slategray: [119, 128, 144],
|
---|
306 | slategrey: [119, 128, 144],
|
---|
307 | snow: [255, 255, 250],
|
---|
308 | springgreen: [0, 255, 127],
|
---|
309 | steelblue: [70, 130, 180],
|
---|
310 | tan: [210, 180, 140],
|
---|
311 | teal: [0, 128, 128],
|
---|
312 | thistle: [216, 191, 216],
|
---|
313 | transparent: [255, 255, 255, 0],
|
---|
314 | tomato: [255, 99, 71],
|
---|
315 | turquoise: [64, 224, 208],
|
---|
316 | violet: [238, 130, 238],
|
---|
317 | wheat: [245, 222, 179],
|
---|
318 | white: [255, 255, 255],
|
---|
319 | whitesmoke: [245, 245, 245],
|
---|
320 | yellow: [255, 255, 0],
|
---|
321 | yellowgreen: [154, 205, 5]
|
---|
322 | };
|
---|
323 | var RGB_REGEX = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;
|
---|
324 | var animQueue = [];
|
---|
325 | var req = typeof requestAnimationFrame !== "undefined" && requestAnimationFrame || function(f) {
|
---|
326 | setTimeout(f, 60);
|
---|
327 | };
|
---|
328 | exports.Util = {
|
---|
329 | _isElement(obj) {
|
---|
330 | return !!(obj && obj.nodeType == 1);
|
---|
331 | },
|
---|
332 | _isFunction(obj) {
|
---|
333 | return !!(obj && obj.constructor && obj.call && obj.apply);
|
---|
334 | },
|
---|
335 | _isPlainObject(obj) {
|
---|
336 | return !!obj && obj.constructor === Object;
|
---|
337 | },
|
---|
338 | _isArray(obj) {
|
---|
339 | return Object.prototype.toString.call(obj) === OBJECT_ARRAY;
|
---|
340 | },
|
---|
341 | _isNumber(obj) {
|
---|
342 | return Object.prototype.toString.call(obj) === OBJECT_NUMBER && !isNaN(obj) && isFinite(obj);
|
---|
343 | },
|
---|
344 | _isString(obj) {
|
---|
345 | return Object.prototype.toString.call(obj) === OBJECT_STRING;
|
---|
346 | },
|
---|
347 | _isBoolean(obj) {
|
---|
348 | return Object.prototype.toString.call(obj) === OBJECT_BOOLEAN;
|
---|
349 | },
|
---|
350 | isObject(val) {
|
---|
351 | return val instanceof Object;
|
---|
352 | },
|
---|
353 | isValidSelector(selector) {
|
---|
354 | if (typeof selector !== "string") {
|
---|
355 | return false;
|
---|
356 | }
|
---|
357 | var firstChar = selector[0];
|
---|
358 | return firstChar === "#" || firstChar === "." || firstChar === firstChar.toUpperCase();
|
---|
359 | },
|
---|
360 | _sign(number) {
|
---|
361 | if (number === 0) {
|
---|
362 | return 1;
|
---|
363 | }
|
---|
364 | if (number > 0) {
|
---|
365 | return 1;
|
---|
366 | } else {
|
---|
367 | return -1;
|
---|
368 | }
|
---|
369 | },
|
---|
370 | requestAnimFrame(callback) {
|
---|
371 | animQueue.push(callback);
|
---|
372 | if (animQueue.length === 1) {
|
---|
373 | req(function() {
|
---|
374 | const queue = animQueue;
|
---|
375 | animQueue = [];
|
---|
376 | queue.forEach(function(cb) {
|
---|
377 | cb();
|
---|
378 | });
|
---|
379 | });
|
---|
380 | }
|
---|
381 | },
|
---|
382 | createCanvasElement() {
|
---|
383 | var canvas = document.createElement("canvas");
|
---|
384 | try {
|
---|
385 | canvas.style = canvas.style || {};
|
---|
386 | } catch (e) {
|
---|
387 | }
|
---|
388 | return canvas;
|
---|
389 | },
|
---|
390 | createImageElement() {
|
---|
391 | return document.createElement("img");
|
---|
392 | },
|
---|
393 | _isInDocument(el) {
|
---|
394 | while (el = el.parentNode) {
|
---|
395 | if (el == document) {
|
---|
396 | return true;
|
---|
397 | }
|
---|
398 | }
|
---|
399 | return false;
|
---|
400 | },
|
---|
401 | _urlToImage(url, callback) {
|
---|
402 | var imageObj = exports.Util.createImageElement();
|
---|
403 | imageObj.onload = function() {
|
---|
404 | callback(imageObj);
|
---|
405 | };
|
---|
406 | imageObj.src = url;
|
---|
407 | },
|
---|
408 | _rgbToHex(r, g, b) {
|
---|
409 | return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
---|
410 | },
|
---|
411 | _hexToRgb(hex) {
|
---|
412 | hex = hex.replace(HASH, EMPTY_STRING);
|
---|
413 | var bigint = parseInt(hex, 16);
|
---|
414 | return {
|
---|
415 | r: bigint >> 16 & 255,
|
---|
416 | g: bigint >> 8 & 255,
|
---|
417 | b: bigint & 255
|
---|
418 | };
|
---|
419 | },
|
---|
420 | getRandomColor() {
|
---|
421 | var randColor = (Math.random() * 16777215 << 0).toString(16);
|
---|
422 | while (randColor.length < 6) {
|
---|
423 | randColor = ZERO + randColor;
|
---|
424 | }
|
---|
425 | return HASH + randColor;
|
---|
426 | },
|
---|
427 | getRGB(color) {
|
---|
428 | var rgb;
|
---|
429 | if (color in COLORS) {
|
---|
430 | rgb = COLORS[color];
|
---|
431 | return {
|
---|
432 | r: rgb[0],
|
---|
433 | g: rgb[1],
|
---|
434 | b: rgb[2]
|
---|
435 | };
|
---|
436 | } else if (color[0] === HASH) {
|
---|
437 | return this._hexToRgb(color.substring(1));
|
---|
438 | } else if (color.substr(0, 4) === RGB_PAREN) {
|
---|
439 | rgb = RGB_REGEX.exec(color.replace(/ /g, ""));
|
---|
440 | return {
|
---|
441 | r: parseInt(rgb[1], 10),
|
---|
442 | g: parseInt(rgb[2], 10),
|
---|
443 | b: parseInt(rgb[3], 10)
|
---|
444 | };
|
---|
445 | } else {
|
---|
446 | return {
|
---|
447 | r: 0,
|
---|
448 | g: 0,
|
---|
449 | b: 0
|
---|
450 | };
|
---|
451 | }
|
---|
452 | },
|
---|
453 | colorToRGBA(str) {
|
---|
454 | str = str || "black";
|
---|
455 | return exports.Util._namedColorToRBA(str) || exports.Util._hex3ColorToRGBA(str) || exports.Util._hex4ColorToRGBA(str) || exports.Util._hex6ColorToRGBA(str) || exports.Util._hex8ColorToRGBA(str) || exports.Util._rgbColorToRGBA(str) || exports.Util._rgbaColorToRGBA(str) || exports.Util._hslColorToRGBA(str);
|
---|
456 | },
|
---|
457 | _namedColorToRBA(str) {
|
---|
458 | var c = COLORS[str.toLowerCase()];
|
---|
459 | if (!c) {
|
---|
460 | return null;
|
---|
461 | }
|
---|
462 | return {
|
---|
463 | r: c[0],
|
---|
464 | g: c[1],
|
---|
465 | b: c[2],
|
---|
466 | a: 1
|
---|
467 | };
|
---|
468 | },
|
---|
469 | _rgbColorToRGBA(str) {
|
---|
470 | if (str.indexOf("rgb(") === 0) {
|
---|
471 | str = str.match(/rgb\(([^)]+)\)/)[1];
|
---|
472 | var parts = str.split(/ *, */).map(Number);
|
---|
473 | return {
|
---|
474 | r: parts[0],
|
---|
475 | g: parts[1],
|
---|
476 | b: parts[2],
|
---|
477 | a: 1
|
---|
478 | };
|
---|
479 | }
|
---|
480 | },
|
---|
481 | _rgbaColorToRGBA(str) {
|
---|
482 | if (str.indexOf("rgba(") === 0) {
|
---|
483 | str = str.match(/rgba\(([^)]+)\)/)[1];
|
---|
484 | var parts = str.split(/ *, */).map((n, index) => {
|
---|
485 | if (n.slice(-1) === "%") {
|
---|
486 | return index === 3 ? parseInt(n) / 100 : parseInt(n) / 100 * 255;
|
---|
487 | }
|
---|
488 | return Number(n);
|
---|
489 | });
|
---|
490 | return {
|
---|
491 | r: parts[0],
|
---|
492 | g: parts[1],
|
---|
493 | b: parts[2],
|
---|
494 | a: parts[3]
|
---|
495 | };
|
---|
496 | }
|
---|
497 | },
|
---|
498 | _hex8ColorToRGBA(str) {
|
---|
499 | if (str[0] === "#" && str.length === 9) {
|
---|
500 | return {
|
---|
501 | r: parseInt(str.slice(1, 3), 16),
|
---|
502 | g: parseInt(str.slice(3, 5), 16),
|
---|
503 | b: parseInt(str.slice(5, 7), 16),
|
---|
504 | a: parseInt(str.slice(7, 9), 16) / 255
|
---|
505 | };
|
---|
506 | }
|
---|
507 | },
|
---|
508 | _hex6ColorToRGBA(str) {
|
---|
509 | if (str[0] === "#" && str.length === 7) {
|
---|
510 | return {
|
---|
511 | r: parseInt(str.slice(1, 3), 16),
|
---|
512 | g: parseInt(str.slice(3, 5), 16),
|
---|
513 | b: parseInt(str.slice(5, 7), 16),
|
---|
514 | a: 1
|
---|
515 | };
|
---|
516 | }
|
---|
517 | },
|
---|
518 | _hex4ColorToRGBA(str) {
|
---|
519 | if (str[0] === "#" && str.length === 5) {
|
---|
520 | return {
|
---|
521 | r: parseInt(str[1] + str[1], 16),
|
---|
522 | g: parseInt(str[2] + str[2], 16),
|
---|
523 | b: parseInt(str[3] + str[3], 16),
|
---|
524 | a: parseInt(str[4] + str[4], 16) / 255
|
---|
525 | };
|
---|
526 | }
|
---|
527 | },
|
---|
528 | _hex3ColorToRGBA(str) {
|
---|
529 | if (str[0] === "#" && str.length === 4) {
|
---|
530 | return {
|
---|
531 | r: parseInt(str[1] + str[1], 16),
|
---|
532 | g: parseInt(str[2] + str[2], 16),
|
---|
533 | b: parseInt(str[3] + str[3], 16),
|
---|
534 | a: 1
|
---|
535 | };
|
---|
536 | }
|
---|
537 | },
|
---|
538 | _hslColorToRGBA(str) {
|
---|
539 | if (/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(str)) {
|
---|
540 | const [_, ...hsl] = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(str);
|
---|
541 | const h = Number(hsl[0]) / 360;
|
---|
542 | const s = Number(hsl[1]) / 100;
|
---|
543 | const l = Number(hsl[2]) / 100;
|
---|
544 | let t2;
|
---|
545 | let t3;
|
---|
546 | let val;
|
---|
547 | if (s === 0) {
|
---|
548 | val = l * 255;
|
---|
549 | return {
|
---|
550 | r: Math.round(val),
|
---|
551 | g: Math.round(val),
|
---|
552 | b: Math.round(val),
|
---|
553 | a: 1
|
---|
554 | };
|
---|
555 | }
|
---|
556 | if (l < 0.5) {
|
---|
557 | t2 = l * (1 + s);
|
---|
558 | } else {
|
---|
559 | t2 = l + s - l * s;
|
---|
560 | }
|
---|
561 | const t1 = 2 * l - t2;
|
---|
562 | const rgb = [0, 0, 0];
|
---|
563 | for (let i = 0; i < 3; i++) {
|
---|
564 | t3 = h + 1 / 3 * -(i - 1);
|
---|
565 | if (t3 < 0) {
|
---|
566 | t3++;
|
---|
567 | }
|
---|
568 | if (t3 > 1) {
|
---|
569 | t3--;
|
---|
570 | }
|
---|
571 | if (6 * t3 < 1) {
|
---|
572 | val = t1 + (t2 - t1) * 6 * t3;
|
---|
573 | } else if (2 * t3 < 1) {
|
---|
574 | val = t2;
|
---|
575 | } else if (3 * t3 < 2) {
|
---|
576 | val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
---|
577 | } else {
|
---|
578 | val = t1;
|
---|
579 | }
|
---|
580 | rgb[i] = val * 255;
|
---|
581 | }
|
---|
582 | return {
|
---|
583 | r: Math.round(rgb[0]),
|
---|
584 | g: Math.round(rgb[1]),
|
---|
585 | b: Math.round(rgb[2]),
|
---|
586 | a: 1
|
---|
587 | };
|
---|
588 | }
|
---|
589 | },
|
---|
590 | haveIntersection(r1, r2) {
|
---|
591 | return !(r2.x > r1.x + r1.width || r2.x + r2.width < r1.x || r2.y > r1.y + r1.height || r2.y + r2.height < r1.y);
|
---|
592 | },
|
---|
593 | cloneObject(obj) {
|
---|
594 | var retObj = {};
|
---|
595 | for (var key in obj) {
|
---|
596 | if (this._isPlainObject(obj[key])) {
|
---|
597 | retObj[key] = this.cloneObject(obj[key]);
|
---|
598 | } else if (this._isArray(obj[key])) {
|
---|
599 | retObj[key] = this.cloneArray(obj[key]);
|
---|
600 | } else {
|
---|
601 | retObj[key] = obj[key];
|
---|
602 | }
|
---|
603 | }
|
---|
604 | return retObj;
|
---|
605 | },
|
---|
606 | cloneArray(arr) {
|
---|
607 | return arr.slice(0);
|
---|
608 | },
|
---|
609 | degToRad(deg) {
|
---|
610 | return deg * PI_OVER_DEG180;
|
---|
611 | },
|
---|
612 | radToDeg(rad) {
|
---|
613 | return rad * DEG180_OVER_PI;
|
---|
614 | },
|
---|
615 | _degToRad(deg) {
|
---|
616 | exports.Util.warn("Util._degToRad is removed. Please use public Util.degToRad instead.");
|
---|
617 | return exports.Util.degToRad(deg);
|
---|
618 | },
|
---|
619 | _radToDeg(rad) {
|
---|
620 | exports.Util.warn("Util._radToDeg is removed. Please use public Util.radToDeg instead.");
|
---|
621 | return exports.Util.radToDeg(rad);
|
---|
622 | },
|
---|
623 | _getRotation(radians) {
|
---|
624 | return Global_1.Konva.angleDeg ? exports.Util.radToDeg(radians) : radians;
|
---|
625 | },
|
---|
626 | _capitalize(str) {
|
---|
627 | return str.charAt(0).toUpperCase() + str.slice(1);
|
---|
628 | },
|
---|
629 | throw(str) {
|
---|
630 | throw new Error(KONVA_ERROR + str);
|
---|
631 | },
|
---|
632 | error(str) {
|
---|
633 | console.error(KONVA_ERROR + str);
|
---|
634 | },
|
---|
635 | warn(str) {
|
---|
636 | if (!Global_1.Konva.showWarnings) {
|
---|
637 | return;
|
---|
638 | }
|
---|
639 | console.warn(KONVA_WARNING + str);
|
---|
640 | },
|
---|
641 | each(obj, func) {
|
---|
642 | for (var key in obj) {
|
---|
643 | func(key, obj[key]);
|
---|
644 | }
|
---|
645 | },
|
---|
646 | _inRange(val, left, right) {
|
---|
647 | return left <= val && val < right;
|
---|
648 | },
|
---|
649 | _getProjectionToSegment(x1, y1, x2, y2, x3, y3) {
|
---|
650 | var x, y, dist;
|
---|
651 | var pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
|
---|
652 | if (pd2 == 0) {
|
---|
653 | x = x1;
|
---|
654 | y = y1;
|
---|
655 | dist = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
|
---|
656 | } else {
|
---|
657 | var u = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2;
|
---|
658 | if (u < 0) {
|
---|
659 | x = x1;
|
---|
660 | y = y1;
|
---|
661 | dist = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
|
---|
662 | } else if (u > 1) {
|
---|
663 | x = x2;
|
---|
664 | y = y2;
|
---|
665 | dist = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
|
---|
666 | } else {
|
---|
667 | x = x1 + u * (x2 - x1);
|
---|
668 | y = y1 + u * (y2 - y1);
|
---|
669 | dist = (x - x3) * (x - x3) + (y - y3) * (y - y3);
|
---|
670 | }
|
---|
671 | }
|
---|
672 | return [x, y, dist];
|
---|
673 | },
|
---|
674 | _getProjectionToLine(pt, line, isClosed) {
|
---|
675 | var pc = exports.Util.cloneObject(pt);
|
---|
676 | var dist = Number.MAX_VALUE;
|
---|
677 | line.forEach(function(p1, i) {
|
---|
678 | if (!isClosed && i === line.length - 1) {
|
---|
679 | return;
|
---|
680 | }
|
---|
681 | var p2 = line[(i + 1) % line.length];
|
---|
682 | var proj = exports.Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y);
|
---|
683 | var px = proj[0], py = proj[1], pdist = proj[2];
|
---|
684 | if (pdist < dist) {
|
---|
685 | pc.x = px;
|
---|
686 | pc.y = py;
|
---|
687 | dist = pdist;
|
---|
688 | }
|
---|
689 | });
|
---|
690 | return pc;
|
---|
691 | },
|
---|
692 | _prepareArrayForTween(startArray, endArray, isClosed) {
|
---|
693 | var n, start = [], end = [];
|
---|
694 | if (startArray.length > endArray.length) {
|
---|
695 | var temp = endArray;
|
---|
696 | endArray = startArray;
|
---|
697 | startArray = temp;
|
---|
698 | }
|
---|
699 | for (n = 0; n < startArray.length; n += 2) {
|
---|
700 | start.push({
|
---|
701 | x: startArray[n],
|
---|
702 | y: startArray[n + 1]
|
---|
703 | });
|
---|
704 | }
|
---|
705 | for (n = 0; n < endArray.length; n += 2) {
|
---|
706 | end.push({
|
---|
707 | x: endArray[n],
|
---|
708 | y: endArray[n + 1]
|
---|
709 | });
|
---|
710 | }
|
---|
711 | var newStart = [];
|
---|
712 | end.forEach(function(point) {
|
---|
713 | var pr = exports.Util._getProjectionToLine(point, start, isClosed);
|
---|
714 | newStart.push(pr.x);
|
---|
715 | newStart.push(pr.y);
|
---|
716 | });
|
---|
717 | return newStart;
|
---|
718 | },
|
---|
719 | _prepareToStringify(obj) {
|
---|
720 | var desc;
|
---|
721 | obj.visitedByCircularReferenceRemoval = true;
|
---|
722 | for (var key in obj) {
|
---|
723 | if (!(obj.hasOwnProperty(key) && obj[key] && typeof obj[key] == "object")) {
|
---|
724 | continue;
|
---|
725 | }
|
---|
726 | desc = Object.getOwnPropertyDescriptor(obj, key);
|
---|
727 | if (obj[key].visitedByCircularReferenceRemoval || exports.Util._isElement(obj[key])) {
|
---|
728 | if (desc.configurable) {
|
---|
729 | delete obj[key];
|
---|
730 | } else {
|
---|
731 | return null;
|
---|
732 | }
|
---|
733 | } else if (exports.Util._prepareToStringify(obj[key]) === null) {
|
---|
734 | if (desc.configurable) {
|
---|
735 | delete obj[key];
|
---|
736 | } else {
|
---|
737 | return null;
|
---|
738 | }
|
---|
739 | }
|
---|
740 | }
|
---|
741 | delete obj.visitedByCircularReferenceRemoval;
|
---|
742 | return obj;
|
---|
743 | },
|
---|
744 | _assign(target, source) {
|
---|
745 | for (var key in source) {
|
---|
746 | target[key] = source[key];
|
---|
747 | }
|
---|
748 | return target;
|
---|
749 | },
|
---|
750 | _getFirstPointerId(evt) {
|
---|
751 | if (!evt.touches) {
|
---|
752 | return evt.pointerId || 999;
|
---|
753 | } else {
|
---|
754 | return evt.changedTouches[0].identifier;
|
---|
755 | }
|
---|
756 | },
|
---|
757 | releaseCanvas(...canvases) {
|
---|
758 | if (!Global_1.Konva.releaseCanvasOnDestroy)
|
---|
759 | return;
|
---|
760 | canvases.forEach((c) => {
|
---|
761 | c.width = 0;
|
---|
762 | c.height = 0;
|
---|
763 | });
|
---|
764 | },
|
---|
765 | drawRoundedRectPath(context, width, height, cornerRadius) {
|
---|
766 | let topLeft = 0;
|
---|
767 | let topRight = 0;
|
---|
768 | let bottomLeft = 0;
|
---|
769 | let bottomRight = 0;
|
---|
770 | if (typeof cornerRadius === "number") {
|
---|
771 | topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
|
---|
772 | } else {
|
---|
773 | topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
---|
774 | topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
---|
775 | bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
---|
776 | bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
---|
777 | }
|
---|
778 | context.moveTo(topLeft, 0);
|
---|
779 | context.lineTo(width - topRight, 0);
|
---|
780 | context.arc(width - topRight, topRight, topRight, Math.PI * 3 / 2, 0, false);
|
---|
781 | context.lineTo(width, height - bottomRight);
|
---|
782 | context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
---|
783 | context.lineTo(bottomLeft, height);
|
---|
784 | context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
---|
785 | context.lineTo(0, topLeft);
|
---|
786 | context.arc(topLeft, topLeft, topLeft, Math.PI, Math.PI * 3 / 2, false);
|
---|
787 | }
|
---|
788 | };
|
---|
789 | }
|
---|
790 | });
|
---|
791 |
|
---|
792 | // node_modules/konva/lib/Validators.js
|
---|
793 | var require_Validators = __commonJS({
|
---|
794 | "node_modules/konva/lib/Validators.js"(exports) {
|
---|
795 | "use strict";
|
---|
796 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
797 | exports.getComponentValidator = exports.getBooleanValidator = exports.getNumberArrayValidator = exports.getFunctionValidator = exports.getStringOrGradientValidator = exports.getStringValidator = exports.getNumberOrAutoValidator = exports.getNumberOrArrayOfNumbersValidator = exports.getNumberValidator = exports.alphaComponent = exports.RGBComponent = void 0;
|
---|
798 | var Global_1 = require_Global();
|
---|
799 | var Util_1 = require_Util();
|
---|
800 | function _formatValue(val) {
|
---|
801 | if (Util_1.Util._isString(val)) {
|
---|
802 | return '"' + val + '"';
|
---|
803 | }
|
---|
804 | if (Object.prototype.toString.call(val) === "[object Number]") {
|
---|
805 | return val;
|
---|
806 | }
|
---|
807 | if (Util_1.Util._isBoolean(val)) {
|
---|
808 | return val;
|
---|
809 | }
|
---|
810 | return Object.prototype.toString.call(val);
|
---|
811 | }
|
---|
812 | function RGBComponent(val) {
|
---|
813 | if (val > 255) {
|
---|
814 | return 255;
|
---|
815 | } else if (val < 0) {
|
---|
816 | return 0;
|
---|
817 | }
|
---|
818 | return Math.round(val);
|
---|
819 | }
|
---|
820 | exports.RGBComponent = RGBComponent;
|
---|
821 | function alphaComponent(val) {
|
---|
822 | if (val > 1) {
|
---|
823 | return 1;
|
---|
824 | } else if (val < 1e-4) {
|
---|
825 | return 1e-4;
|
---|
826 | }
|
---|
827 | return val;
|
---|
828 | }
|
---|
829 | exports.alphaComponent = alphaComponent;
|
---|
830 | function getNumberValidator() {
|
---|
831 | if (Global_1.Konva.isUnminified) {
|
---|
832 | return function(val, attr) {
|
---|
833 | if (!Util_1.Util._isNumber(val)) {
|
---|
834 | Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a number.');
|
---|
835 | }
|
---|
836 | return val;
|
---|
837 | };
|
---|
838 | }
|
---|
839 | }
|
---|
840 | exports.getNumberValidator = getNumberValidator;
|
---|
841 | function getNumberOrArrayOfNumbersValidator(noOfElements) {
|
---|
842 | if (Global_1.Konva.isUnminified) {
|
---|
843 | return function(val, attr) {
|
---|
844 | let isNumber = Util_1.Util._isNumber(val);
|
---|
845 | let isValidArray = Util_1.Util._isArray(val) && val.length == noOfElements;
|
---|
846 | if (!isNumber && !isValidArray) {
|
---|
847 | Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a number or Array<number>(' + noOfElements + ")");
|
---|
848 | }
|
---|
849 | return val;
|
---|
850 | };
|
---|
851 | }
|
---|
852 | }
|
---|
853 | exports.getNumberOrArrayOfNumbersValidator = getNumberOrArrayOfNumbersValidator;
|
---|
854 | function getNumberOrAutoValidator() {
|
---|
855 | if (Global_1.Konva.isUnminified) {
|
---|
856 | return function(val, attr) {
|
---|
857 | var isNumber = Util_1.Util._isNumber(val);
|
---|
858 | var isAuto = val === "auto";
|
---|
859 | if (!(isNumber || isAuto)) {
|
---|
860 | Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a number or "auto".');
|
---|
861 | }
|
---|
862 | return val;
|
---|
863 | };
|
---|
864 | }
|
---|
865 | }
|
---|
866 | exports.getNumberOrAutoValidator = getNumberOrAutoValidator;
|
---|
867 | function getStringValidator() {
|
---|
868 | if (Global_1.Konva.isUnminified) {
|
---|
869 | return function(val, attr) {
|
---|
870 | if (!Util_1.Util._isString(val)) {
|
---|
871 | Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a string.');
|
---|
872 | }
|
---|
873 | return val;
|
---|
874 | };
|
---|
875 | }
|
---|
876 | }
|
---|
877 | exports.getStringValidator = getStringValidator;
|
---|
878 | function getStringOrGradientValidator() {
|
---|
879 | if (Global_1.Konva.isUnminified) {
|
---|
880 | return function(val, attr) {
|
---|
881 | const isString = Util_1.Util._isString(val);
|
---|
882 | const isGradient = Object.prototype.toString.call(val) === "[object CanvasGradient]" || val && val.addColorStop;
|
---|
883 | if (!(isString || isGradient)) {
|
---|
884 | Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a string or a native gradient.');
|
---|
885 | }
|
---|
886 | return val;
|
---|
887 | };
|
---|
888 | }
|
---|
889 | }
|
---|
890 | exports.getStringOrGradientValidator = getStringOrGradientValidator;
|
---|
891 | function getFunctionValidator() {
|
---|
892 | if (Global_1.Konva.isUnminified) {
|
---|
893 | return function(val, attr) {
|
---|
894 | if (!Util_1.Util._isFunction(val)) {
|
---|
895 | Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a function.');
|
---|
896 | }
|
---|
897 | return val;
|
---|
898 | };
|
---|
899 | }
|
---|
900 | }
|
---|
901 | exports.getFunctionValidator = getFunctionValidator;
|
---|
902 | function getNumberArrayValidator() {
|
---|
903 | if (Global_1.Konva.isUnminified) {
|
---|
904 | return function(val, attr) {
|
---|
905 | const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
|
---|
906 | if (TypedArray && val instanceof TypedArray) {
|
---|
907 | return val;
|
---|
908 | }
|
---|
909 | if (!Util_1.Util._isArray(val)) {
|
---|
910 | Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a array of numbers.');
|
---|
911 | } else {
|
---|
912 | val.forEach(function(item) {
|
---|
913 | if (!Util_1.Util._isNumber(item)) {
|
---|
914 | Util_1.Util.warn('"' + attr + '" attribute has non numeric element ' + item + ". Make sure that all elements are numbers.");
|
---|
915 | }
|
---|
916 | });
|
---|
917 | }
|
---|
918 | return val;
|
---|
919 | };
|
---|
920 | }
|
---|
921 | }
|
---|
922 | exports.getNumberArrayValidator = getNumberArrayValidator;
|
---|
923 | function getBooleanValidator() {
|
---|
924 | if (Global_1.Konva.isUnminified) {
|
---|
925 | return function(val, attr) {
|
---|
926 | var isBool = val === true || val === false;
|
---|
927 | if (!isBool) {
|
---|
928 | Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a boolean.');
|
---|
929 | }
|
---|
930 | return val;
|
---|
931 | };
|
---|
932 | }
|
---|
933 | }
|
---|
934 | exports.getBooleanValidator = getBooleanValidator;
|
---|
935 | function getComponentValidator(components) {
|
---|
936 | if (Global_1.Konva.isUnminified) {
|
---|
937 | return function(val, attr) {
|
---|
938 | if (val === void 0 || val === null) {
|
---|
939 | return val;
|
---|
940 | }
|
---|
941 | if (!Util_1.Util.isObject(val)) {
|
---|
942 | Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be an object with properties ' + components);
|
---|
943 | }
|
---|
944 | return val;
|
---|
945 | };
|
---|
946 | }
|
---|
947 | }
|
---|
948 | exports.getComponentValidator = getComponentValidator;
|
---|
949 | }
|
---|
950 | });
|
---|
951 |
|
---|
952 | // node_modules/konva/lib/Factory.js
|
---|
953 | var require_Factory = __commonJS({
|
---|
954 | "node_modules/konva/lib/Factory.js"(exports) {
|
---|
955 | "use strict";
|
---|
956 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
957 | exports.Factory = void 0;
|
---|
958 | var Util_1 = require_Util();
|
---|
959 | var Validators_1 = require_Validators();
|
---|
960 | var GET = "get";
|
---|
961 | var SET = "set";
|
---|
962 | exports.Factory = {
|
---|
963 | addGetterSetter(constructor, attr, def, validator, after) {
|
---|
964 | exports.Factory.addGetter(constructor, attr, def);
|
---|
965 | exports.Factory.addSetter(constructor, attr, validator, after);
|
---|
966 | exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
---|
967 | },
|
---|
968 | addGetter(constructor, attr, def) {
|
---|
969 | var method = GET + Util_1.Util._capitalize(attr);
|
---|
970 | constructor.prototype[method] = constructor.prototype[method] || function() {
|
---|
971 | var val = this.attrs[attr];
|
---|
972 | return val === void 0 ? def : val;
|
---|
973 | };
|
---|
974 | },
|
---|
975 | addSetter(constructor, attr, validator, after) {
|
---|
976 | var method = SET + Util_1.Util._capitalize(attr);
|
---|
977 | if (!constructor.prototype[method]) {
|
---|
978 | exports.Factory.overWriteSetter(constructor, attr, validator, after);
|
---|
979 | }
|
---|
980 | },
|
---|
981 | overWriteSetter(constructor, attr, validator, after) {
|
---|
982 | var method = SET + Util_1.Util._capitalize(attr);
|
---|
983 | constructor.prototype[method] = function(val) {
|
---|
984 | if (validator && val !== void 0 && val !== null) {
|
---|
985 | val = validator.call(this, val, attr);
|
---|
986 | }
|
---|
987 | this._setAttr(attr, val);
|
---|
988 | if (after) {
|
---|
989 | after.call(this);
|
---|
990 | }
|
---|
991 | return this;
|
---|
992 | };
|
---|
993 | },
|
---|
994 | addComponentsGetterSetter(constructor, attr, components, validator, after) {
|
---|
995 | var len = components.length, capitalize = Util_1.Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr), n, component;
|
---|
996 | constructor.prototype[getter] = function() {
|
---|
997 | var ret = {};
|
---|
998 | for (n = 0; n < len; n++) {
|
---|
999 | component = components[n];
|
---|
1000 | ret[component] = this.getAttr(attr + capitalize(component));
|
---|
1001 | }
|
---|
1002 | return ret;
|
---|
1003 | };
|
---|
1004 | var basicValidator = (0, Validators_1.getComponentValidator)(components);
|
---|
1005 | constructor.prototype[setter] = function(val) {
|
---|
1006 | var oldVal = this.attrs[attr], key;
|
---|
1007 | if (validator) {
|
---|
1008 | val = validator.call(this, val);
|
---|
1009 | }
|
---|
1010 | if (basicValidator) {
|
---|
1011 | basicValidator.call(this, val, attr);
|
---|
1012 | }
|
---|
1013 | for (key in val) {
|
---|
1014 | if (!val.hasOwnProperty(key)) {
|
---|
1015 | continue;
|
---|
1016 | }
|
---|
1017 | this._setAttr(attr + capitalize(key), val[key]);
|
---|
1018 | }
|
---|
1019 | if (!val) {
|
---|
1020 | components.forEach((component2) => {
|
---|
1021 | this._setAttr(attr + capitalize(component2), void 0);
|
---|
1022 | });
|
---|
1023 | }
|
---|
1024 | this._fireChangeEvent(attr, oldVal, val);
|
---|
1025 | if (after) {
|
---|
1026 | after.call(this);
|
---|
1027 | }
|
---|
1028 | return this;
|
---|
1029 | };
|
---|
1030 | exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
---|
1031 | },
|
---|
1032 | addOverloadedGetterSetter(constructor, attr) {
|
---|
1033 | var capitalizedAttr = Util_1.Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
|
---|
1034 | constructor.prototype[attr] = function() {
|
---|
1035 | if (arguments.length) {
|
---|
1036 | this[setter](arguments[0]);
|
---|
1037 | return this;
|
---|
1038 | }
|
---|
1039 | return this[getter]();
|
---|
1040 | };
|
---|
1041 | },
|
---|
1042 | addDeprecatedGetterSetter(constructor, attr, def, validator) {
|
---|
1043 | Util_1.Util.error("Adding deprecated " + attr);
|
---|
1044 | var method = GET + Util_1.Util._capitalize(attr);
|
---|
1045 | var message = attr + " property is deprecated and will be removed soon. Look at Konva change log for more information.";
|
---|
1046 | constructor.prototype[method] = function() {
|
---|
1047 | Util_1.Util.error(message);
|
---|
1048 | var val = this.attrs[attr];
|
---|
1049 | return val === void 0 ? def : val;
|
---|
1050 | };
|
---|
1051 | exports.Factory.addSetter(constructor, attr, validator, function() {
|
---|
1052 | Util_1.Util.error(message);
|
---|
1053 | });
|
---|
1054 | exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
---|
1055 | },
|
---|
1056 | backCompat(constructor, methods) {
|
---|
1057 | Util_1.Util.each(methods, function(oldMethodName, newMethodName) {
|
---|
1058 | var method = constructor.prototype[newMethodName];
|
---|
1059 | var oldGetter = GET + Util_1.Util._capitalize(oldMethodName);
|
---|
1060 | var oldSetter = SET + Util_1.Util._capitalize(oldMethodName);
|
---|
1061 | function deprecated() {
|
---|
1062 | method.apply(this, arguments);
|
---|
1063 | Util_1.Util.error('"' + oldMethodName + '" method is deprecated and will be removed soon. Use ""' + newMethodName + '" instead.');
|
---|
1064 | }
|
---|
1065 | constructor.prototype[oldMethodName] = deprecated;
|
---|
1066 | constructor.prototype[oldGetter] = deprecated;
|
---|
1067 | constructor.prototype[oldSetter] = deprecated;
|
---|
1068 | });
|
---|
1069 | },
|
---|
1070 | afterSetFilter() {
|
---|
1071 | this._filterUpToDate = false;
|
---|
1072 | }
|
---|
1073 | };
|
---|
1074 | }
|
---|
1075 | });
|
---|
1076 |
|
---|
1077 | // node_modules/konva/lib/Context.js
|
---|
1078 | var require_Context = __commonJS({
|
---|
1079 | "node_modules/konva/lib/Context.js"(exports) {
|
---|
1080 | "use strict";
|
---|
1081 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
1082 | exports.HitContext = exports.SceneContext = exports.Context = void 0;
|
---|
1083 | var Util_1 = require_Util();
|
---|
1084 | var Global_1 = require_Global();
|
---|
1085 | function simplifyArray(arr) {
|
---|
1086 | var retArr = [], len = arr.length, util = Util_1.Util, n, val;
|
---|
1087 | for (n = 0; n < len; n++) {
|
---|
1088 | val = arr[n];
|
---|
1089 | if (util._isNumber(val)) {
|
---|
1090 | val = Math.round(val * 1e3) / 1e3;
|
---|
1091 | } else if (!util._isString(val)) {
|
---|
1092 | val = val + "";
|
---|
1093 | }
|
---|
1094 | retArr.push(val);
|
---|
1095 | }
|
---|
1096 | return retArr;
|
---|
1097 | }
|
---|
1098 | var COMMA = ",";
|
---|
1099 | var OPEN_PAREN = "(";
|
---|
1100 | var CLOSE_PAREN = ")";
|
---|
1101 | var OPEN_PAREN_BRACKET = "([";
|
---|
1102 | var CLOSE_BRACKET_PAREN = "])";
|
---|
1103 | var SEMICOLON = ";";
|
---|
1104 | var DOUBLE_PAREN = "()";
|
---|
1105 | var EQUALS = "=";
|
---|
1106 | var CONTEXT_METHODS = [
|
---|
1107 | "arc",
|
---|
1108 | "arcTo",
|
---|
1109 | "beginPath",
|
---|
1110 | "bezierCurveTo",
|
---|
1111 | "clearRect",
|
---|
1112 | "clip",
|
---|
1113 | "closePath",
|
---|
1114 | "createLinearGradient",
|
---|
1115 | "createPattern",
|
---|
1116 | "createRadialGradient",
|
---|
1117 | "drawImage",
|
---|
1118 | "ellipse",
|
---|
1119 | "fill",
|
---|
1120 | "fillText",
|
---|
1121 | "getImageData",
|
---|
1122 | "createImageData",
|
---|
1123 | "lineTo",
|
---|
1124 | "moveTo",
|
---|
1125 | "putImageData",
|
---|
1126 | "quadraticCurveTo",
|
---|
1127 | "rect",
|
---|
1128 | "roundRect",
|
---|
1129 | "restore",
|
---|
1130 | "rotate",
|
---|
1131 | "save",
|
---|
1132 | "scale",
|
---|
1133 | "setLineDash",
|
---|
1134 | "setTransform",
|
---|
1135 | "stroke",
|
---|
1136 | "strokeText",
|
---|
1137 | "transform",
|
---|
1138 | "translate"
|
---|
1139 | ];
|
---|
1140 | var CONTEXT_PROPERTIES = [
|
---|
1141 | "fillStyle",
|
---|
1142 | "strokeStyle",
|
---|
1143 | "shadowColor",
|
---|
1144 | "shadowBlur",
|
---|
1145 | "shadowOffsetX",
|
---|
1146 | "shadowOffsetY",
|
---|
1147 | "letterSpacing",
|
---|
1148 | "lineCap",
|
---|
1149 | "lineDashOffset",
|
---|
1150 | "lineJoin",
|
---|
1151 | "lineWidth",
|
---|
1152 | "miterLimit",
|
---|
1153 | "direction",
|
---|
1154 | "font",
|
---|
1155 | "textAlign",
|
---|
1156 | "textBaseline",
|
---|
1157 | "globalAlpha",
|
---|
1158 | "globalCompositeOperation",
|
---|
1159 | "imageSmoothingEnabled"
|
---|
1160 | ];
|
---|
1161 | var traceArrMax = 100;
|
---|
1162 | var Context = class {
|
---|
1163 | constructor(canvas) {
|
---|
1164 | this.canvas = canvas;
|
---|
1165 | if (Global_1.Konva.enableTrace) {
|
---|
1166 | this.traceArr = [];
|
---|
1167 | this._enableTrace();
|
---|
1168 | }
|
---|
1169 | }
|
---|
1170 | fillShape(shape) {
|
---|
1171 | if (shape.fillEnabled()) {
|
---|
1172 | this._fill(shape);
|
---|
1173 | }
|
---|
1174 | }
|
---|
1175 | _fill(shape) {
|
---|
1176 | }
|
---|
1177 | strokeShape(shape) {
|
---|
1178 | if (shape.hasStroke()) {
|
---|
1179 | this._stroke(shape);
|
---|
1180 | }
|
---|
1181 | }
|
---|
1182 | _stroke(shape) {
|
---|
1183 | }
|
---|
1184 | fillStrokeShape(shape) {
|
---|
1185 | if (shape.attrs.fillAfterStrokeEnabled) {
|
---|
1186 | this.strokeShape(shape);
|
---|
1187 | this.fillShape(shape);
|
---|
1188 | } else {
|
---|
1189 | this.fillShape(shape);
|
---|
1190 | this.strokeShape(shape);
|
---|
1191 | }
|
---|
1192 | }
|
---|
1193 | getTrace(relaxed, rounded) {
|
---|
1194 | var traceArr = this.traceArr, len = traceArr.length, str = "", n, trace, method, args;
|
---|
1195 | for (n = 0; n < len; n++) {
|
---|
1196 | trace = traceArr[n];
|
---|
1197 | method = trace.method;
|
---|
1198 | if (method) {
|
---|
1199 | args = trace.args;
|
---|
1200 | str += method;
|
---|
1201 | if (relaxed) {
|
---|
1202 | str += DOUBLE_PAREN;
|
---|
1203 | } else {
|
---|
1204 | if (Util_1.Util._isArray(args[0])) {
|
---|
1205 | str += OPEN_PAREN_BRACKET + args.join(COMMA) + CLOSE_BRACKET_PAREN;
|
---|
1206 | } else {
|
---|
1207 | if (rounded) {
|
---|
1208 | args = args.map((a) => typeof a === "number" ? Math.floor(a) : a);
|
---|
1209 | }
|
---|
1210 | str += OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN;
|
---|
1211 | }
|
---|
1212 | }
|
---|
1213 | } else {
|
---|
1214 | str += trace.property;
|
---|
1215 | if (!relaxed) {
|
---|
1216 | str += EQUALS + trace.val;
|
---|
1217 | }
|
---|
1218 | }
|
---|
1219 | str += SEMICOLON;
|
---|
1220 | }
|
---|
1221 | return str;
|
---|
1222 | }
|
---|
1223 | clearTrace() {
|
---|
1224 | this.traceArr = [];
|
---|
1225 | }
|
---|
1226 | _trace(str) {
|
---|
1227 | var traceArr = this.traceArr, len;
|
---|
1228 | traceArr.push(str);
|
---|
1229 | len = traceArr.length;
|
---|
1230 | if (len >= traceArrMax) {
|
---|
1231 | traceArr.shift();
|
---|
1232 | }
|
---|
1233 | }
|
---|
1234 | reset() {
|
---|
1235 | var pixelRatio = this.getCanvas().getPixelRatio();
|
---|
1236 | this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0);
|
---|
1237 | }
|
---|
1238 | getCanvas() {
|
---|
1239 | return this.canvas;
|
---|
1240 | }
|
---|
1241 | clear(bounds) {
|
---|
1242 | var canvas = this.getCanvas();
|
---|
1243 | if (bounds) {
|
---|
1244 | this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0);
|
---|
1245 | } else {
|
---|
1246 | this.clearRect(0, 0, canvas.getWidth() / canvas.pixelRatio, canvas.getHeight() / canvas.pixelRatio);
|
---|
1247 | }
|
---|
1248 | }
|
---|
1249 | _applyLineCap(shape) {
|
---|
1250 | const lineCap = shape.attrs.lineCap;
|
---|
1251 | if (lineCap) {
|
---|
1252 | this.setAttr("lineCap", lineCap);
|
---|
1253 | }
|
---|
1254 | }
|
---|
1255 | _applyOpacity(shape) {
|
---|
1256 | var absOpacity = shape.getAbsoluteOpacity();
|
---|
1257 | if (absOpacity !== 1) {
|
---|
1258 | this.setAttr("globalAlpha", absOpacity);
|
---|
1259 | }
|
---|
1260 | }
|
---|
1261 | _applyLineJoin(shape) {
|
---|
1262 | const lineJoin = shape.attrs.lineJoin;
|
---|
1263 | if (lineJoin) {
|
---|
1264 | this.setAttr("lineJoin", lineJoin);
|
---|
1265 | }
|
---|
1266 | }
|
---|
1267 | setAttr(attr, val) {
|
---|
1268 | this._context[attr] = val;
|
---|
1269 | }
|
---|
1270 | arc(x, y, radius, startAngle, endAngle, counterClockwise) {
|
---|
1271 | this._context.arc(x, y, radius, startAngle, endAngle, counterClockwise);
|
---|
1272 | }
|
---|
1273 | arcTo(x1, y1, x2, y2, radius) {
|
---|
1274 | this._context.arcTo(x1, y1, x2, y2, radius);
|
---|
1275 | }
|
---|
1276 | beginPath() {
|
---|
1277 | this._context.beginPath();
|
---|
1278 | }
|
---|
1279 | bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
---|
1280 | this._context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
---|
1281 | }
|
---|
1282 | clearRect(x, y, width, height) {
|
---|
1283 | this._context.clearRect(x, y, width, height);
|
---|
1284 | }
|
---|
1285 | clip(...args) {
|
---|
1286 | this._context.clip.apply(this._context, args);
|
---|
1287 | }
|
---|
1288 | closePath() {
|
---|
1289 | this._context.closePath();
|
---|
1290 | }
|
---|
1291 | createImageData(width, height) {
|
---|
1292 | var a = arguments;
|
---|
1293 | if (a.length === 2) {
|
---|
1294 | return this._context.createImageData(width, height);
|
---|
1295 | } else if (a.length === 1) {
|
---|
1296 | return this._context.createImageData(width);
|
---|
1297 | }
|
---|
1298 | }
|
---|
1299 | createLinearGradient(x0, y0, x1, y1) {
|
---|
1300 | return this._context.createLinearGradient(x0, y0, x1, y1);
|
---|
1301 | }
|
---|
1302 | createPattern(image, repetition) {
|
---|
1303 | return this._context.createPattern(image, repetition);
|
---|
1304 | }
|
---|
1305 | createRadialGradient(x0, y0, r0, x1, y1, r1) {
|
---|
1306 | return this._context.createRadialGradient(x0, y0, r0, x1, y1, r1);
|
---|
1307 | }
|
---|
1308 | drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
|
---|
1309 | var a = arguments, _context = this._context;
|
---|
1310 | if (a.length === 3) {
|
---|
1311 | _context.drawImage(image, sx, sy);
|
---|
1312 | } else if (a.length === 5) {
|
---|
1313 | _context.drawImage(image, sx, sy, sWidth, sHeight);
|
---|
1314 | } else if (a.length === 9) {
|
---|
1315 | _context.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
|
---|
1316 | }
|
---|
1317 | }
|
---|
1318 | ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
|
---|
1319 | this._context.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise);
|
---|
1320 | }
|
---|
1321 | isPointInPath(x, y, path, fillRule) {
|
---|
1322 | if (path) {
|
---|
1323 | return this._context.isPointInPath(path, x, y, fillRule);
|
---|
1324 | }
|
---|
1325 | return this._context.isPointInPath(x, y, fillRule);
|
---|
1326 | }
|
---|
1327 | fill(...args) {
|
---|
1328 | this._context.fill.apply(this._context, args);
|
---|
1329 | }
|
---|
1330 | fillRect(x, y, width, height) {
|
---|
1331 | this._context.fillRect(x, y, width, height);
|
---|
1332 | }
|
---|
1333 | strokeRect(x, y, width, height) {
|
---|
1334 | this._context.strokeRect(x, y, width, height);
|
---|
1335 | }
|
---|
1336 | fillText(text, x, y, maxWidth) {
|
---|
1337 | if (maxWidth) {
|
---|
1338 | this._context.fillText(text, x, y, maxWidth);
|
---|
1339 | } else {
|
---|
1340 | this._context.fillText(text, x, y);
|
---|
1341 | }
|
---|
1342 | }
|
---|
1343 | measureText(text) {
|
---|
1344 | return this._context.measureText(text);
|
---|
1345 | }
|
---|
1346 | getImageData(sx, sy, sw, sh) {
|
---|
1347 | return this._context.getImageData(sx, sy, sw, sh);
|
---|
1348 | }
|
---|
1349 | lineTo(x, y) {
|
---|
1350 | this._context.lineTo(x, y);
|
---|
1351 | }
|
---|
1352 | moveTo(x, y) {
|
---|
1353 | this._context.moveTo(x, y);
|
---|
1354 | }
|
---|
1355 | rect(x, y, width, height) {
|
---|
1356 | this._context.rect(x, y, width, height);
|
---|
1357 | }
|
---|
1358 | roundRect(x, y, width, height, radii) {
|
---|
1359 | this._context.roundRect(x, y, width, height, radii);
|
---|
1360 | }
|
---|
1361 | putImageData(imageData, dx, dy) {
|
---|
1362 | this._context.putImageData(imageData, dx, dy);
|
---|
1363 | }
|
---|
1364 | quadraticCurveTo(cpx, cpy, x, y) {
|
---|
1365 | this._context.quadraticCurveTo(cpx, cpy, x, y);
|
---|
1366 | }
|
---|
1367 | restore() {
|
---|
1368 | this._context.restore();
|
---|
1369 | }
|
---|
1370 | rotate(angle) {
|
---|
1371 | this._context.rotate(angle);
|
---|
1372 | }
|
---|
1373 | save() {
|
---|
1374 | this._context.save();
|
---|
1375 | }
|
---|
1376 | scale(x, y) {
|
---|
1377 | this._context.scale(x, y);
|
---|
1378 | }
|
---|
1379 | setLineDash(segments) {
|
---|
1380 | if (this._context.setLineDash) {
|
---|
1381 | this._context.setLineDash(segments);
|
---|
1382 | } else if ("mozDash" in this._context) {
|
---|
1383 | this._context["mozDash"] = segments;
|
---|
1384 | } else if ("webkitLineDash" in this._context) {
|
---|
1385 | this._context["webkitLineDash"] = segments;
|
---|
1386 | }
|
---|
1387 | }
|
---|
1388 | getLineDash() {
|
---|
1389 | return this._context.getLineDash();
|
---|
1390 | }
|
---|
1391 | setTransform(a, b, c, d, e, f) {
|
---|
1392 | this._context.setTransform(a, b, c, d, e, f);
|
---|
1393 | }
|
---|
1394 | stroke(path2d) {
|
---|
1395 | if (path2d) {
|
---|
1396 | this._context.stroke(path2d);
|
---|
1397 | } else {
|
---|
1398 | this._context.stroke();
|
---|
1399 | }
|
---|
1400 | }
|
---|
1401 | strokeText(text, x, y, maxWidth) {
|
---|
1402 | this._context.strokeText(text, x, y, maxWidth);
|
---|
1403 | }
|
---|
1404 | transform(a, b, c, d, e, f) {
|
---|
1405 | this._context.transform(a, b, c, d, e, f);
|
---|
1406 | }
|
---|
1407 | translate(x, y) {
|
---|
1408 | this._context.translate(x, y);
|
---|
1409 | }
|
---|
1410 | _enableTrace() {
|
---|
1411 | var that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;
|
---|
1412 | var func = function(methodName) {
|
---|
1413 | var origMethod = that[methodName], ret;
|
---|
1414 | that[methodName] = function() {
|
---|
1415 | args = simplifyArray(Array.prototype.slice.call(arguments, 0));
|
---|
1416 | ret = origMethod.apply(that, arguments);
|
---|
1417 | that._trace({
|
---|
1418 | method: methodName,
|
---|
1419 | args
|
---|
1420 | });
|
---|
1421 | return ret;
|
---|
1422 | };
|
---|
1423 | };
|
---|
1424 | for (n = 0; n < len; n++) {
|
---|
1425 | func(CONTEXT_METHODS[n]);
|
---|
1426 | }
|
---|
1427 | that.setAttr = function() {
|
---|
1428 | origSetter.apply(that, arguments);
|
---|
1429 | var prop = arguments[0];
|
---|
1430 | var val = arguments[1];
|
---|
1431 | if (prop === "shadowOffsetX" || prop === "shadowOffsetY" || prop === "shadowBlur") {
|
---|
1432 | val = val / this.canvas.getPixelRatio();
|
---|
1433 | }
|
---|
1434 | that._trace({
|
---|
1435 | property: prop,
|
---|
1436 | val
|
---|
1437 | });
|
---|
1438 | };
|
---|
1439 | }
|
---|
1440 | _applyGlobalCompositeOperation(node) {
|
---|
1441 | const op = node.attrs.globalCompositeOperation;
|
---|
1442 | var def = !op || op === "source-over";
|
---|
1443 | if (!def) {
|
---|
1444 | this.setAttr("globalCompositeOperation", op);
|
---|
1445 | }
|
---|
1446 | }
|
---|
1447 | };
|
---|
1448 | exports.Context = Context;
|
---|
1449 | CONTEXT_PROPERTIES.forEach(function(prop) {
|
---|
1450 | Object.defineProperty(Context.prototype, prop, {
|
---|
1451 | get() {
|
---|
1452 | return this._context[prop];
|
---|
1453 | },
|
---|
1454 | set(val) {
|
---|
1455 | this._context[prop] = val;
|
---|
1456 | }
|
---|
1457 | });
|
---|
1458 | });
|
---|
1459 | var SceneContext = class extends Context {
|
---|
1460 | constructor(canvas, { willReadFrequently = false } = {}) {
|
---|
1461 | super(canvas);
|
---|
1462 | this._context = canvas._canvas.getContext("2d", {
|
---|
1463 | willReadFrequently
|
---|
1464 | });
|
---|
1465 | }
|
---|
1466 | _fillColor(shape) {
|
---|
1467 | var fill = shape.fill();
|
---|
1468 | this.setAttr("fillStyle", fill);
|
---|
1469 | shape._fillFunc(this);
|
---|
1470 | }
|
---|
1471 | _fillPattern(shape) {
|
---|
1472 | this.setAttr("fillStyle", shape._getFillPattern());
|
---|
1473 | shape._fillFunc(this);
|
---|
1474 | }
|
---|
1475 | _fillLinearGradient(shape) {
|
---|
1476 | var grd = shape._getLinearGradient();
|
---|
1477 | if (grd) {
|
---|
1478 | this.setAttr("fillStyle", grd);
|
---|
1479 | shape._fillFunc(this);
|
---|
1480 | }
|
---|
1481 | }
|
---|
1482 | _fillRadialGradient(shape) {
|
---|
1483 | const grd = shape._getRadialGradient();
|
---|
1484 | if (grd) {
|
---|
1485 | this.setAttr("fillStyle", grd);
|
---|
1486 | shape._fillFunc(this);
|
---|
1487 | }
|
---|
1488 | }
|
---|
1489 | _fill(shape) {
|
---|
1490 | const hasColor = shape.fill(), fillPriority = shape.getFillPriority();
|
---|
1491 | if (hasColor && fillPriority === "color") {
|
---|
1492 | this._fillColor(shape);
|
---|
1493 | return;
|
---|
1494 | }
|
---|
1495 | const hasPattern = shape.getFillPatternImage();
|
---|
1496 | if (hasPattern && fillPriority === "pattern") {
|
---|
1497 | this._fillPattern(shape);
|
---|
1498 | return;
|
---|
1499 | }
|
---|
1500 | const hasLinearGradient = shape.getFillLinearGradientColorStops();
|
---|
1501 | if (hasLinearGradient && fillPriority === "linear-gradient") {
|
---|
1502 | this._fillLinearGradient(shape);
|
---|
1503 | return;
|
---|
1504 | }
|
---|
1505 | const hasRadialGradient = shape.getFillRadialGradientColorStops();
|
---|
1506 | if (hasRadialGradient && fillPriority === "radial-gradient") {
|
---|
1507 | this._fillRadialGradient(shape);
|
---|
1508 | return;
|
---|
1509 | }
|
---|
1510 | if (hasColor) {
|
---|
1511 | this._fillColor(shape);
|
---|
1512 | } else if (hasPattern) {
|
---|
1513 | this._fillPattern(shape);
|
---|
1514 | } else if (hasLinearGradient) {
|
---|
1515 | this._fillLinearGradient(shape);
|
---|
1516 | } else if (hasRadialGradient) {
|
---|
1517 | this._fillRadialGradient(shape);
|
---|
1518 | }
|
---|
1519 | }
|
---|
1520 | _strokeLinearGradient(shape) {
|
---|
1521 | const start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
|
---|
1522 | if (colorStops) {
|
---|
1523 | for (var n = 0; n < colorStops.length; n += 2) {
|
---|
1524 | grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
---|
1525 | }
|
---|
1526 | this.setAttr("strokeStyle", grd);
|
---|
1527 | }
|
---|
1528 | }
|
---|
1529 | _stroke(shape) {
|
---|
1530 | var dash = shape.dash(), strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
---|
1531 | if (shape.hasStroke()) {
|
---|
1532 | if (!strokeScaleEnabled) {
|
---|
1533 | this.save();
|
---|
1534 | var pixelRatio = this.getCanvas().getPixelRatio();
|
---|
1535 | this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
---|
1536 | }
|
---|
1537 | this._applyLineCap(shape);
|
---|
1538 | if (dash && shape.dashEnabled()) {
|
---|
1539 | this.setLineDash(dash);
|
---|
1540 | this.setAttr("lineDashOffset", shape.dashOffset());
|
---|
1541 | }
|
---|
1542 | this.setAttr("lineWidth", shape.strokeWidth());
|
---|
1543 | if (!shape.getShadowForStrokeEnabled()) {
|
---|
1544 | this.setAttr("shadowColor", "rgba(0,0,0,0)");
|
---|
1545 | }
|
---|
1546 | var hasLinearGradient = shape.getStrokeLinearGradientColorStops();
|
---|
1547 | if (hasLinearGradient) {
|
---|
1548 | this._strokeLinearGradient(shape);
|
---|
1549 | } else {
|
---|
1550 | this.setAttr("strokeStyle", shape.stroke());
|
---|
1551 | }
|
---|
1552 | shape._strokeFunc(this);
|
---|
1553 | if (!strokeScaleEnabled) {
|
---|
1554 | this.restore();
|
---|
1555 | }
|
---|
1556 | }
|
---|
1557 | }
|
---|
1558 | _applyShadow(shape) {
|
---|
1559 | var _a, _b, _c;
|
---|
1560 | var color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : "black", blur = (_b = shape.getShadowBlur()) !== null && _b !== void 0 ? _b : 5, offset = (_c = shape.getShadowOffset()) !== null && _c !== void 0 ? _c : {
|
---|
1561 | x: 0,
|
---|
1562 | y: 0
|
---|
1563 | }, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
|
---|
1564 | this.setAttr("shadowColor", color);
|
---|
1565 | this.setAttr("shadowBlur", blur * Math.min(Math.abs(scaleX), Math.abs(scaleY)));
|
---|
1566 | this.setAttr("shadowOffsetX", offset.x * scaleX);
|
---|
1567 | this.setAttr("shadowOffsetY", offset.y * scaleY);
|
---|
1568 | }
|
---|
1569 | };
|
---|
1570 | exports.SceneContext = SceneContext;
|
---|
1571 | var HitContext = class extends Context {
|
---|
1572 | constructor(canvas) {
|
---|
1573 | super(canvas);
|
---|
1574 | this._context = canvas._canvas.getContext("2d", {
|
---|
1575 | willReadFrequently: true
|
---|
1576 | });
|
---|
1577 | }
|
---|
1578 | _fill(shape) {
|
---|
1579 | this.save();
|
---|
1580 | this.setAttr("fillStyle", shape.colorKey);
|
---|
1581 | shape._fillFuncHit(this);
|
---|
1582 | this.restore();
|
---|
1583 | }
|
---|
1584 | strokeShape(shape) {
|
---|
1585 | if (shape.hasHitStroke()) {
|
---|
1586 | this._stroke(shape);
|
---|
1587 | }
|
---|
1588 | }
|
---|
1589 | _stroke(shape) {
|
---|
1590 | if (shape.hasHitStroke()) {
|
---|
1591 | const strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
---|
1592 | if (!strokeScaleEnabled) {
|
---|
1593 | this.save();
|
---|
1594 | var pixelRatio = this.getCanvas().getPixelRatio();
|
---|
1595 | this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
---|
1596 | }
|
---|
1597 | this._applyLineCap(shape);
|
---|
1598 | var hitStrokeWidth = shape.hitStrokeWidth();
|
---|
1599 | var strokeWidth = hitStrokeWidth === "auto" ? shape.strokeWidth() : hitStrokeWidth;
|
---|
1600 | this.setAttr("lineWidth", strokeWidth);
|
---|
1601 | this.setAttr("strokeStyle", shape.colorKey);
|
---|
1602 | shape._strokeFuncHit(this);
|
---|
1603 | if (!strokeScaleEnabled) {
|
---|
1604 | this.restore();
|
---|
1605 | }
|
---|
1606 | }
|
---|
1607 | }
|
---|
1608 | };
|
---|
1609 | exports.HitContext = HitContext;
|
---|
1610 | }
|
---|
1611 | });
|
---|
1612 |
|
---|
1613 | // node_modules/konva/lib/Canvas.js
|
---|
1614 | var require_Canvas = __commonJS({
|
---|
1615 | "node_modules/konva/lib/Canvas.js"(exports) {
|
---|
1616 | "use strict";
|
---|
1617 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
1618 | exports.HitCanvas = exports.SceneCanvas = exports.Canvas = void 0;
|
---|
1619 | var Util_1 = require_Util();
|
---|
1620 | var Context_1 = require_Context();
|
---|
1621 | var Global_1 = require_Global();
|
---|
1622 | var Factory_1 = require_Factory();
|
---|
1623 | var Validators_1 = require_Validators();
|
---|
1624 | var _pixelRatio;
|
---|
1625 | function getDevicePixelRatio() {
|
---|
1626 | if (_pixelRatio) {
|
---|
1627 | return _pixelRatio;
|
---|
1628 | }
|
---|
1629 | var canvas = Util_1.Util.createCanvasElement();
|
---|
1630 | var context = canvas.getContext("2d");
|
---|
1631 | _pixelRatio = function() {
|
---|
1632 | var devicePixelRatio = Global_1.Konva._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1;
|
---|
1633 | return devicePixelRatio / backingStoreRatio;
|
---|
1634 | }();
|
---|
1635 | Util_1.Util.releaseCanvas(canvas);
|
---|
1636 | return _pixelRatio;
|
---|
1637 | }
|
---|
1638 | var Canvas = class {
|
---|
1639 | constructor(config) {
|
---|
1640 | this.pixelRatio = 1;
|
---|
1641 | this.width = 0;
|
---|
1642 | this.height = 0;
|
---|
1643 | this.isCache = false;
|
---|
1644 | var conf = config || {};
|
---|
1645 | var pixelRatio = conf.pixelRatio || Global_1.Konva.pixelRatio || getDevicePixelRatio();
|
---|
1646 | this.pixelRatio = pixelRatio;
|
---|
1647 | this._canvas = Util_1.Util.createCanvasElement();
|
---|
1648 | this._canvas.style.padding = "0";
|
---|
1649 | this._canvas.style.margin = "0";
|
---|
1650 | this._canvas.style.border = "0";
|
---|
1651 | this._canvas.style.background = "transparent";
|
---|
1652 | this._canvas.style.position = "absolute";
|
---|
1653 | this._canvas.style.top = "0";
|
---|
1654 | this._canvas.style.left = "0";
|
---|
1655 | }
|
---|
1656 | getContext() {
|
---|
1657 | return this.context;
|
---|
1658 | }
|
---|
1659 | getPixelRatio() {
|
---|
1660 | return this.pixelRatio;
|
---|
1661 | }
|
---|
1662 | setPixelRatio(pixelRatio) {
|
---|
1663 | var previousRatio = this.pixelRatio;
|
---|
1664 | this.pixelRatio = pixelRatio;
|
---|
1665 | this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio);
|
---|
1666 | }
|
---|
1667 | setWidth(width) {
|
---|
1668 | this.width = this._canvas.width = width * this.pixelRatio;
|
---|
1669 | this._canvas.style.width = width + "px";
|
---|
1670 | var pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
---|
1671 | _context.scale(pixelRatio, pixelRatio);
|
---|
1672 | }
|
---|
1673 | setHeight(height) {
|
---|
1674 | this.height = this._canvas.height = height * this.pixelRatio;
|
---|
1675 | this._canvas.style.height = height + "px";
|
---|
1676 | var pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
---|
1677 | _context.scale(pixelRatio, pixelRatio);
|
---|
1678 | }
|
---|
1679 | getWidth() {
|
---|
1680 | return this.width;
|
---|
1681 | }
|
---|
1682 | getHeight() {
|
---|
1683 | return this.height;
|
---|
1684 | }
|
---|
1685 | setSize(width, height) {
|
---|
1686 | this.setWidth(width || 0);
|
---|
1687 | this.setHeight(height || 0);
|
---|
1688 | }
|
---|
1689 | toDataURL(mimeType, quality) {
|
---|
1690 | try {
|
---|
1691 | return this._canvas.toDataURL(mimeType, quality);
|
---|
1692 | } catch (e) {
|
---|
1693 | try {
|
---|
1694 | return this._canvas.toDataURL();
|
---|
1695 | } catch (err) {
|
---|
1696 | Util_1.Util.error("Unable to get data URL. " + err.message + " For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html.");
|
---|
1697 | return "";
|
---|
1698 | }
|
---|
1699 | }
|
---|
1700 | }
|
---|
1701 | };
|
---|
1702 | exports.Canvas = Canvas;
|
---|
1703 | Factory_1.Factory.addGetterSetter(Canvas, "pixelRatio", void 0, (0, Validators_1.getNumberValidator)());
|
---|
1704 | var SceneCanvas = class extends Canvas {
|
---|
1705 | constructor(config = { width: 0, height: 0, willReadFrequently: false }) {
|
---|
1706 | super(config);
|
---|
1707 | this.context = new Context_1.SceneContext(this, {
|
---|
1708 | willReadFrequently: config.willReadFrequently
|
---|
1709 | });
|
---|
1710 | this.setSize(config.width, config.height);
|
---|
1711 | }
|
---|
1712 | };
|
---|
1713 | exports.SceneCanvas = SceneCanvas;
|
---|
1714 | var HitCanvas = class extends Canvas {
|
---|
1715 | constructor(config = { width: 0, height: 0 }) {
|
---|
1716 | super(config);
|
---|
1717 | this.hitCanvas = true;
|
---|
1718 | this.context = new Context_1.HitContext(this);
|
---|
1719 | this.setSize(config.width, config.height);
|
---|
1720 | }
|
---|
1721 | };
|
---|
1722 | exports.HitCanvas = HitCanvas;
|
---|
1723 | }
|
---|
1724 | });
|
---|
1725 |
|
---|
1726 | // node_modules/konva/lib/DragAndDrop.js
|
---|
1727 | var require_DragAndDrop = __commonJS({
|
---|
1728 | "node_modules/konva/lib/DragAndDrop.js"(exports) {
|
---|
1729 | "use strict";
|
---|
1730 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
1731 | exports.DD = void 0;
|
---|
1732 | var Global_1 = require_Global();
|
---|
1733 | var Util_1 = require_Util();
|
---|
1734 | exports.DD = {
|
---|
1735 | get isDragging() {
|
---|
1736 | var flag = false;
|
---|
1737 | exports.DD._dragElements.forEach((elem) => {
|
---|
1738 | if (elem.dragStatus === "dragging") {
|
---|
1739 | flag = true;
|
---|
1740 | }
|
---|
1741 | });
|
---|
1742 | return flag;
|
---|
1743 | },
|
---|
1744 | justDragged: false,
|
---|
1745 | get node() {
|
---|
1746 | var node;
|
---|
1747 | exports.DD._dragElements.forEach((elem) => {
|
---|
1748 | node = elem.node;
|
---|
1749 | });
|
---|
1750 | return node;
|
---|
1751 | },
|
---|
1752 | _dragElements: /* @__PURE__ */ new Map(),
|
---|
1753 | _drag(evt) {
|
---|
1754 | const nodesToFireEvents = [];
|
---|
1755 | exports.DD._dragElements.forEach((elem, key) => {
|
---|
1756 | const { node } = elem;
|
---|
1757 | const stage = node.getStage();
|
---|
1758 | stage.setPointersPositions(evt);
|
---|
1759 | if (elem.pointerId === void 0) {
|
---|
1760 | elem.pointerId = Util_1.Util._getFirstPointerId(evt);
|
---|
1761 | }
|
---|
1762 | const pos = stage._changedPointerPositions.find((pos2) => pos2.id === elem.pointerId);
|
---|
1763 | if (!pos) {
|
---|
1764 | return;
|
---|
1765 | }
|
---|
1766 | if (elem.dragStatus !== "dragging") {
|
---|
1767 | var dragDistance = node.dragDistance();
|
---|
1768 | var distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));
|
---|
1769 | if (distance < dragDistance) {
|
---|
1770 | return;
|
---|
1771 | }
|
---|
1772 | node.startDrag({ evt });
|
---|
1773 | if (!node.isDragging()) {
|
---|
1774 | return;
|
---|
1775 | }
|
---|
1776 | }
|
---|
1777 | node._setDragPosition(evt, elem);
|
---|
1778 | nodesToFireEvents.push(node);
|
---|
1779 | });
|
---|
1780 | nodesToFireEvents.forEach((node) => {
|
---|
1781 | node.fire("dragmove", {
|
---|
1782 | type: "dragmove",
|
---|
1783 | target: node,
|
---|
1784 | evt
|
---|
1785 | }, true);
|
---|
1786 | });
|
---|
1787 | },
|
---|
1788 | _endDragBefore(evt) {
|
---|
1789 | const drawNodes = [];
|
---|
1790 | exports.DD._dragElements.forEach((elem) => {
|
---|
1791 | const { node } = elem;
|
---|
1792 | const stage = node.getStage();
|
---|
1793 | if (evt) {
|
---|
1794 | stage.setPointersPositions(evt);
|
---|
1795 | }
|
---|
1796 | const pos = stage._changedPointerPositions.find((pos2) => pos2.id === elem.pointerId);
|
---|
1797 | if (!pos) {
|
---|
1798 | return;
|
---|
1799 | }
|
---|
1800 | if (elem.dragStatus === "dragging" || elem.dragStatus === "stopped") {
|
---|
1801 | exports.DD.justDragged = true;
|
---|
1802 | Global_1.Konva._mouseListenClick = false;
|
---|
1803 | Global_1.Konva._touchListenClick = false;
|
---|
1804 | Global_1.Konva._pointerListenClick = false;
|
---|
1805 | elem.dragStatus = "stopped";
|
---|
1806 | }
|
---|
1807 | const drawNode = elem.node.getLayer() || elem.node instanceof Global_1.Konva["Stage"] && elem.node;
|
---|
1808 | if (drawNode && drawNodes.indexOf(drawNode) === -1) {
|
---|
1809 | drawNodes.push(drawNode);
|
---|
1810 | }
|
---|
1811 | });
|
---|
1812 | drawNodes.forEach((drawNode) => {
|
---|
1813 | drawNode.draw();
|
---|
1814 | });
|
---|
1815 | },
|
---|
1816 | _endDragAfter(evt) {
|
---|
1817 | exports.DD._dragElements.forEach((elem, key) => {
|
---|
1818 | if (elem.dragStatus === "stopped") {
|
---|
1819 | elem.node.fire("dragend", {
|
---|
1820 | type: "dragend",
|
---|
1821 | target: elem.node,
|
---|
1822 | evt
|
---|
1823 | }, true);
|
---|
1824 | }
|
---|
1825 | if (elem.dragStatus !== "dragging") {
|
---|
1826 | exports.DD._dragElements.delete(key);
|
---|
1827 | }
|
---|
1828 | });
|
---|
1829 | }
|
---|
1830 | };
|
---|
1831 | if (Global_1.Konva.isBrowser) {
|
---|
1832 | window.addEventListener("mouseup", exports.DD._endDragBefore, true);
|
---|
1833 | window.addEventListener("touchend", exports.DD._endDragBefore, true);
|
---|
1834 | window.addEventListener("mousemove", exports.DD._drag);
|
---|
1835 | window.addEventListener("touchmove", exports.DD._drag);
|
---|
1836 | window.addEventListener("mouseup", exports.DD._endDragAfter, false);
|
---|
1837 | window.addEventListener("touchend", exports.DD._endDragAfter, false);
|
---|
1838 | }
|
---|
1839 | }
|
---|
1840 | });
|
---|
1841 |
|
---|
1842 | // node_modules/konva/lib/Node.js
|
---|
1843 | var require_Node = __commonJS({
|
---|
1844 | "node_modules/konva/lib/Node.js"(exports) {
|
---|
1845 | "use strict";
|
---|
1846 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
1847 | exports.Node = void 0;
|
---|
1848 | var Util_1 = require_Util();
|
---|
1849 | var Factory_1 = require_Factory();
|
---|
1850 | var Canvas_1 = require_Canvas();
|
---|
1851 | var Global_1 = require_Global();
|
---|
1852 | var DragAndDrop_1 = require_DragAndDrop();
|
---|
1853 | var Validators_1 = require_Validators();
|
---|
1854 | var ABSOLUTE_OPACITY = "absoluteOpacity";
|
---|
1855 | var ALL_LISTENERS = "allEventListeners";
|
---|
1856 | var ABSOLUTE_TRANSFORM = "absoluteTransform";
|
---|
1857 | var ABSOLUTE_SCALE = "absoluteScale";
|
---|
1858 | var CANVAS = "canvas";
|
---|
1859 | var CHANGE = "Change";
|
---|
1860 | var CHILDREN = "children";
|
---|
1861 | var KONVA = "konva";
|
---|
1862 | var LISTENING = "listening";
|
---|
1863 | var MOUSEENTER = "mouseenter";
|
---|
1864 | var MOUSELEAVE = "mouseleave";
|
---|
1865 | var SET = "set";
|
---|
1866 | var SHAPE = "Shape";
|
---|
1867 | var SPACE = " ";
|
---|
1868 | var STAGE = "stage";
|
---|
1869 | var TRANSFORM = "transform";
|
---|
1870 | var UPPER_STAGE = "Stage";
|
---|
1871 | var VISIBLE = "visible";
|
---|
1872 | var TRANSFORM_CHANGE_STR = [
|
---|
1873 | "xChange.konva",
|
---|
1874 | "yChange.konva",
|
---|
1875 | "scaleXChange.konva",
|
---|
1876 | "scaleYChange.konva",
|
---|
1877 | "skewXChange.konva",
|
---|
1878 | "skewYChange.konva",
|
---|
1879 | "rotationChange.konva",
|
---|
1880 | "offsetXChange.konva",
|
---|
1881 | "offsetYChange.konva",
|
---|
1882 | "transformsEnabledChange.konva"
|
---|
1883 | ].join(SPACE);
|
---|
1884 | var idCounter = 1;
|
---|
1885 | var Node = class _Node {
|
---|
1886 | constructor(config) {
|
---|
1887 | this._id = idCounter++;
|
---|
1888 | this.eventListeners = {};
|
---|
1889 | this.attrs = {};
|
---|
1890 | this.index = 0;
|
---|
1891 | this._allEventListeners = null;
|
---|
1892 | this.parent = null;
|
---|
1893 | this._cache = /* @__PURE__ */ new Map();
|
---|
1894 | this._attachedDepsListeners = /* @__PURE__ */ new Map();
|
---|
1895 | this._lastPos = null;
|
---|
1896 | this._batchingTransformChange = false;
|
---|
1897 | this._needClearTransformCache = false;
|
---|
1898 | this._filterUpToDate = false;
|
---|
1899 | this._isUnderCache = false;
|
---|
1900 | this._dragEventId = null;
|
---|
1901 | this._shouldFireChangeEvents = false;
|
---|
1902 | this.setAttrs(config);
|
---|
1903 | this._shouldFireChangeEvents = true;
|
---|
1904 | }
|
---|
1905 | hasChildren() {
|
---|
1906 | return false;
|
---|
1907 | }
|
---|
1908 | _clearCache(attr) {
|
---|
1909 | if ((attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM) && this._cache.get(attr)) {
|
---|
1910 | this._cache.get(attr).dirty = true;
|
---|
1911 | } else if (attr) {
|
---|
1912 | this._cache.delete(attr);
|
---|
1913 | } else {
|
---|
1914 | this._cache.clear();
|
---|
1915 | }
|
---|
1916 | }
|
---|
1917 | _getCache(attr, privateGetter) {
|
---|
1918 | var cache = this._cache.get(attr);
|
---|
1919 | var isTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM;
|
---|
1920 | var invalid = cache === void 0 || isTransform && cache.dirty === true;
|
---|
1921 | if (invalid) {
|
---|
1922 | cache = privateGetter.call(this);
|
---|
1923 | this._cache.set(attr, cache);
|
---|
1924 | }
|
---|
1925 | return cache;
|
---|
1926 | }
|
---|
1927 | _calculate(name, deps, getter) {
|
---|
1928 | if (!this._attachedDepsListeners.get(name)) {
|
---|
1929 | const depsString = deps.map((dep) => dep + "Change.konva").join(SPACE);
|
---|
1930 | this.on(depsString, () => {
|
---|
1931 | this._clearCache(name);
|
---|
1932 | });
|
---|
1933 | this._attachedDepsListeners.set(name, true);
|
---|
1934 | }
|
---|
1935 | return this._getCache(name, getter);
|
---|
1936 | }
|
---|
1937 | _getCanvasCache() {
|
---|
1938 | return this._cache.get(CANVAS);
|
---|
1939 | }
|
---|
1940 | _clearSelfAndDescendantCache(attr) {
|
---|
1941 | this._clearCache(attr);
|
---|
1942 | if (attr === ABSOLUTE_TRANSFORM) {
|
---|
1943 | this.fire("absoluteTransformChange");
|
---|
1944 | }
|
---|
1945 | }
|
---|
1946 | clearCache() {
|
---|
1947 | if (this._cache.has(CANVAS)) {
|
---|
1948 | const { scene, filter, hit } = this._cache.get(CANVAS);
|
---|
1949 | Util_1.Util.releaseCanvas(scene, filter, hit);
|
---|
1950 | this._cache.delete(CANVAS);
|
---|
1951 | }
|
---|
1952 | this._clearSelfAndDescendantCache();
|
---|
1953 | this._requestDraw();
|
---|
1954 | return this;
|
---|
1955 | }
|
---|
1956 | cache(config) {
|
---|
1957 | var conf = config || {};
|
---|
1958 | var rect = {};
|
---|
1959 | if (conf.x === void 0 || conf.y === void 0 || conf.width === void 0 || conf.height === void 0) {
|
---|
1960 | rect = this.getClientRect({
|
---|
1961 | skipTransform: true,
|
---|
1962 | relativeTo: this.getParent() || void 0
|
---|
1963 | });
|
---|
1964 | }
|
---|
1965 | var width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === void 0 ? Math.floor(rect.x) : conf.x, y = conf.y === void 0 ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
|
---|
1966 | if (!width || !height) {
|
---|
1967 | Util_1.Util.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped.");
|
---|
1968 | return;
|
---|
1969 | }
|
---|
1970 | const extraPaddingX = Math.abs(Math.round(rect.x) - x) > 0.5 ? 1 : 0;
|
---|
1971 | const extraPaddingY = Math.abs(Math.round(rect.y) - y) > 0.5 ? 1 : 0;
|
---|
1972 | width += offset * 2 + extraPaddingX;
|
---|
1973 | height += offset * 2 + extraPaddingY;
|
---|
1974 | x -= offset;
|
---|
1975 | y -= offset;
|
---|
1976 | var cachedSceneCanvas = new Canvas_1.SceneCanvas({
|
---|
1977 | pixelRatio,
|
---|
1978 | width,
|
---|
1979 | height
|
---|
1980 | }), cachedFilterCanvas = new Canvas_1.SceneCanvas({
|
---|
1981 | pixelRatio,
|
---|
1982 | width: 0,
|
---|
1983 | height: 0,
|
---|
1984 | willReadFrequently: true
|
---|
1985 | }), cachedHitCanvas = new Canvas_1.HitCanvas({
|
---|
1986 | pixelRatio: hitCanvasPixelRatio,
|
---|
1987 | width,
|
---|
1988 | height
|
---|
1989 | }), sceneContext = cachedSceneCanvas.getContext(), hitContext = cachedHitCanvas.getContext();
|
---|
1990 | cachedHitCanvas.isCache = true;
|
---|
1991 | cachedSceneCanvas.isCache = true;
|
---|
1992 | this._cache.delete(CANVAS);
|
---|
1993 | this._filterUpToDate = false;
|
---|
1994 | if (conf.imageSmoothingEnabled === false) {
|
---|
1995 | cachedSceneCanvas.getContext()._context.imageSmoothingEnabled = false;
|
---|
1996 | cachedFilterCanvas.getContext()._context.imageSmoothingEnabled = false;
|
---|
1997 | }
|
---|
1998 | sceneContext.save();
|
---|
1999 | hitContext.save();
|
---|
2000 | sceneContext.translate(-x, -y);
|
---|
2001 | hitContext.translate(-x, -y);
|
---|
2002 | this._isUnderCache = true;
|
---|
2003 | this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
---|
2004 | this._clearSelfAndDescendantCache(ABSOLUTE_SCALE);
|
---|
2005 | this.drawScene(cachedSceneCanvas, this);
|
---|
2006 | this.drawHit(cachedHitCanvas, this);
|
---|
2007 | this._isUnderCache = false;
|
---|
2008 | sceneContext.restore();
|
---|
2009 | hitContext.restore();
|
---|
2010 | if (drawBorder) {
|
---|
2011 | sceneContext.save();
|
---|
2012 | sceneContext.beginPath();
|
---|
2013 | sceneContext.rect(0, 0, width, height);
|
---|
2014 | sceneContext.closePath();
|
---|
2015 | sceneContext.setAttr("strokeStyle", "red");
|
---|
2016 | sceneContext.setAttr("lineWidth", 5);
|
---|
2017 | sceneContext.stroke();
|
---|
2018 | sceneContext.restore();
|
---|
2019 | }
|
---|
2020 | this._cache.set(CANVAS, {
|
---|
2021 | scene: cachedSceneCanvas,
|
---|
2022 | filter: cachedFilterCanvas,
|
---|
2023 | hit: cachedHitCanvas,
|
---|
2024 | x,
|
---|
2025 | y
|
---|
2026 | });
|
---|
2027 | this._requestDraw();
|
---|
2028 | return this;
|
---|
2029 | }
|
---|
2030 | isCached() {
|
---|
2031 | return this._cache.has(CANVAS);
|
---|
2032 | }
|
---|
2033 | getClientRect(config) {
|
---|
2034 | throw new Error('abstract "getClientRect" method call');
|
---|
2035 | }
|
---|
2036 | _transformedRect(rect, top) {
|
---|
2037 | var points = [
|
---|
2038 | { x: rect.x, y: rect.y },
|
---|
2039 | { x: rect.x + rect.width, y: rect.y },
|
---|
2040 | { x: rect.x + rect.width, y: rect.y + rect.height },
|
---|
2041 | { x: rect.x, y: rect.y + rect.height }
|
---|
2042 | ];
|
---|
2043 | var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
---|
2044 | var trans = this.getAbsoluteTransform(top);
|
---|
2045 | points.forEach(function(point) {
|
---|
2046 | var transformed = trans.point(point);
|
---|
2047 | if (minX === void 0) {
|
---|
2048 | minX = maxX = transformed.x;
|
---|
2049 | minY = maxY = transformed.y;
|
---|
2050 | }
|
---|
2051 | minX = Math.min(minX, transformed.x);
|
---|
2052 | minY = Math.min(minY, transformed.y);
|
---|
2053 | maxX = Math.max(maxX, transformed.x);
|
---|
2054 | maxY = Math.max(maxY, transformed.y);
|
---|
2055 | });
|
---|
2056 | return {
|
---|
2057 | x: minX,
|
---|
2058 | y: minY,
|
---|
2059 | width: maxX - minX,
|
---|
2060 | height: maxY - minY
|
---|
2061 | };
|
---|
2062 | }
|
---|
2063 | _drawCachedSceneCanvas(context) {
|
---|
2064 | context.save();
|
---|
2065 | context._applyOpacity(this);
|
---|
2066 | context._applyGlobalCompositeOperation(this);
|
---|
2067 | const canvasCache = this._getCanvasCache();
|
---|
2068 | context.translate(canvasCache.x, canvasCache.y);
|
---|
2069 | var cacheCanvas = this._getCachedSceneCanvas();
|
---|
2070 | var ratio = cacheCanvas.pixelRatio;
|
---|
2071 | context.drawImage(cacheCanvas._canvas, 0, 0, cacheCanvas.width / ratio, cacheCanvas.height / ratio);
|
---|
2072 | context.restore();
|
---|
2073 | }
|
---|
2074 | _drawCachedHitCanvas(context) {
|
---|
2075 | var canvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit;
|
---|
2076 | context.save();
|
---|
2077 | context.translate(canvasCache.x, canvasCache.y);
|
---|
2078 | context.drawImage(hitCanvas._canvas, 0, 0, hitCanvas.width / hitCanvas.pixelRatio, hitCanvas.height / hitCanvas.pixelRatio);
|
---|
2079 | context.restore();
|
---|
2080 | }
|
---|
2081 | _getCachedSceneCanvas() {
|
---|
2082 | var filters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter;
|
---|
2083 | if (filters) {
|
---|
2084 | if (!this._filterUpToDate) {
|
---|
2085 | var ratio = sceneCanvas.pixelRatio;
|
---|
2086 | filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio);
|
---|
2087 | try {
|
---|
2088 | len = filters.length;
|
---|
2089 | filterContext.clear();
|
---|
2090 | filterContext.drawImage(sceneCanvas._canvas, 0, 0, sceneCanvas.getWidth() / ratio, sceneCanvas.getHeight() / ratio);
|
---|
2091 | imageData = filterContext.getImageData(0, 0, filterCanvas.getWidth(), filterCanvas.getHeight());
|
---|
2092 | for (n = 0; n < len; n++) {
|
---|
2093 | filter = filters[n];
|
---|
2094 | if (typeof filter !== "function") {
|
---|
2095 | Util_1.Util.error("Filter should be type of function, but got " + typeof filter + " instead. Please check correct filters");
|
---|
2096 | continue;
|
---|
2097 | }
|
---|
2098 | filter.call(this, imageData);
|
---|
2099 | filterContext.putImageData(imageData, 0, 0);
|
---|
2100 | }
|
---|
2101 | } catch (e) {
|
---|
2102 | Util_1.Util.error("Unable to apply filter. " + e.message + " This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.");
|
---|
2103 | }
|
---|
2104 | this._filterUpToDate = true;
|
---|
2105 | }
|
---|
2106 | return filterCanvas;
|
---|
2107 | }
|
---|
2108 | return sceneCanvas;
|
---|
2109 | }
|
---|
2110 | on(evtStr, handler) {
|
---|
2111 | this._cache && this._cache.delete(ALL_LISTENERS);
|
---|
2112 | if (arguments.length === 3) {
|
---|
2113 | return this._delegate.apply(this, arguments);
|
---|
2114 | }
|
---|
2115 | var events = evtStr.split(SPACE), len = events.length, n, event, parts, baseEvent, name;
|
---|
2116 | for (n = 0; n < len; n++) {
|
---|
2117 | event = events[n];
|
---|
2118 | parts = event.split(".");
|
---|
2119 | baseEvent = parts[0];
|
---|
2120 | name = parts[1] || "";
|
---|
2121 | if (!this.eventListeners[baseEvent]) {
|
---|
2122 | this.eventListeners[baseEvent] = [];
|
---|
2123 | }
|
---|
2124 | this.eventListeners[baseEvent].push({
|
---|
2125 | name,
|
---|
2126 | handler
|
---|
2127 | });
|
---|
2128 | }
|
---|
2129 | return this;
|
---|
2130 | }
|
---|
2131 | off(evtStr, callback) {
|
---|
2132 | var events = (evtStr || "").split(SPACE), len = events.length, n, t, event, parts, baseEvent, name;
|
---|
2133 | this._cache && this._cache.delete(ALL_LISTENERS);
|
---|
2134 | if (!evtStr) {
|
---|
2135 | for (t in this.eventListeners) {
|
---|
2136 | this._off(t);
|
---|
2137 | }
|
---|
2138 | }
|
---|
2139 | for (n = 0; n < len; n++) {
|
---|
2140 | event = events[n];
|
---|
2141 | parts = event.split(".");
|
---|
2142 | baseEvent = parts[0];
|
---|
2143 | name = parts[1];
|
---|
2144 | if (baseEvent) {
|
---|
2145 | if (this.eventListeners[baseEvent]) {
|
---|
2146 | this._off(baseEvent, name, callback);
|
---|
2147 | }
|
---|
2148 | } else {
|
---|
2149 | for (t in this.eventListeners) {
|
---|
2150 | this._off(t, name, callback);
|
---|
2151 | }
|
---|
2152 | }
|
---|
2153 | }
|
---|
2154 | return this;
|
---|
2155 | }
|
---|
2156 | dispatchEvent(evt) {
|
---|
2157 | var e = {
|
---|
2158 | target: this,
|
---|
2159 | type: evt.type,
|
---|
2160 | evt
|
---|
2161 | };
|
---|
2162 | this.fire(evt.type, e);
|
---|
2163 | return this;
|
---|
2164 | }
|
---|
2165 | addEventListener(type, handler) {
|
---|
2166 | this.on(type, function(evt) {
|
---|
2167 | handler.call(this, evt.evt);
|
---|
2168 | });
|
---|
2169 | return this;
|
---|
2170 | }
|
---|
2171 | removeEventListener(type) {
|
---|
2172 | this.off(type);
|
---|
2173 | return this;
|
---|
2174 | }
|
---|
2175 | _delegate(event, selector, handler) {
|
---|
2176 | var stopNode = this;
|
---|
2177 | this.on(event, function(evt) {
|
---|
2178 | var targets = evt.target.findAncestors(selector, true, stopNode);
|
---|
2179 | for (var i = 0; i < targets.length; i++) {
|
---|
2180 | evt = Util_1.Util.cloneObject(evt);
|
---|
2181 | evt.currentTarget = targets[i];
|
---|
2182 | handler.call(targets[i], evt);
|
---|
2183 | }
|
---|
2184 | });
|
---|
2185 | }
|
---|
2186 | remove() {
|
---|
2187 | if (this.isDragging()) {
|
---|
2188 | this.stopDrag();
|
---|
2189 | }
|
---|
2190 | DragAndDrop_1.DD._dragElements.delete(this._id);
|
---|
2191 | this._remove();
|
---|
2192 | return this;
|
---|
2193 | }
|
---|
2194 | _clearCaches() {
|
---|
2195 | this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
---|
2196 | this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
---|
2197 | this._clearSelfAndDescendantCache(ABSOLUTE_SCALE);
|
---|
2198 | this._clearSelfAndDescendantCache(STAGE);
|
---|
2199 | this._clearSelfAndDescendantCache(VISIBLE);
|
---|
2200 | this._clearSelfAndDescendantCache(LISTENING);
|
---|
2201 | }
|
---|
2202 | _remove() {
|
---|
2203 | this._clearCaches();
|
---|
2204 | var parent = this.getParent();
|
---|
2205 | if (parent && parent.children) {
|
---|
2206 | parent.children.splice(this.index, 1);
|
---|
2207 | parent._setChildrenIndices();
|
---|
2208 | this.parent = null;
|
---|
2209 | }
|
---|
2210 | }
|
---|
2211 | destroy() {
|
---|
2212 | this.remove();
|
---|
2213 | this.clearCache();
|
---|
2214 | return this;
|
---|
2215 | }
|
---|
2216 | getAttr(attr) {
|
---|
2217 | var method = "get" + Util_1.Util._capitalize(attr);
|
---|
2218 | if (Util_1.Util._isFunction(this[method])) {
|
---|
2219 | return this[method]();
|
---|
2220 | }
|
---|
2221 | return this.attrs[attr];
|
---|
2222 | }
|
---|
2223 | getAncestors() {
|
---|
2224 | var parent = this.getParent(), ancestors = [];
|
---|
2225 | while (parent) {
|
---|
2226 | ancestors.push(parent);
|
---|
2227 | parent = parent.getParent();
|
---|
2228 | }
|
---|
2229 | return ancestors;
|
---|
2230 | }
|
---|
2231 | getAttrs() {
|
---|
2232 | return this.attrs || {};
|
---|
2233 | }
|
---|
2234 | setAttrs(config) {
|
---|
2235 | this._batchTransformChanges(() => {
|
---|
2236 | var key, method;
|
---|
2237 | if (!config) {
|
---|
2238 | return this;
|
---|
2239 | }
|
---|
2240 | for (key in config) {
|
---|
2241 | if (key === CHILDREN) {
|
---|
2242 | continue;
|
---|
2243 | }
|
---|
2244 | method = SET + Util_1.Util._capitalize(key);
|
---|
2245 | if (Util_1.Util._isFunction(this[method])) {
|
---|
2246 | this[method](config[key]);
|
---|
2247 | } else {
|
---|
2248 | this._setAttr(key, config[key]);
|
---|
2249 | }
|
---|
2250 | }
|
---|
2251 | });
|
---|
2252 | return this;
|
---|
2253 | }
|
---|
2254 | isListening() {
|
---|
2255 | return this._getCache(LISTENING, this._isListening);
|
---|
2256 | }
|
---|
2257 | _isListening(relativeTo) {
|
---|
2258 | const listening = this.listening();
|
---|
2259 | if (!listening) {
|
---|
2260 | return false;
|
---|
2261 | }
|
---|
2262 | const parent = this.getParent();
|
---|
2263 | if (parent && parent !== relativeTo && this !== relativeTo) {
|
---|
2264 | return parent._isListening(relativeTo);
|
---|
2265 | } else {
|
---|
2266 | return true;
|
---|
2267 | }
|
---|
2268 | }
|
---|
2269 | isVisible() {
|
---|
2270 | return this._getCache(VISIBLE, this._isVisible);
|
---|
2271 | }
|
---|
2272 | _isVisible(relativeTo) {
|
---|
2273 | const visible = this.visible();
|
---|
2274 | if (!visible) {
|
---|
2275 | return false;
|
---|
2276 | }
|
---|
2277 | const parent = this.getParent();
|
---|
2278 | if (parent && parent !== relativeTo && this !== relativeTo) {
|
---|
2279 | return parent._isVisible(relativeTo);
|
---|
2280 | } else {
|
---|
2281 | return true;
|
---|
2282 | }
|
---|
2283 | }
|
---|
2284 | shouldDrawHit(top, skipDragCheck = false) {
|
---|
2285 | if (top) {
|
---|
2286 | return this._isVisible(top) && this._isListening(top);
|
---|
2287 | }
|
---|
2288 | var layer = this.getLayer();
|
---|
2289 | var layerUnderDrag = false;
|
---|
2290 | DragAndDrop_1.DD._dragElements.forEach((elem) => {
|
---|
2291 | if (elem.dragStatus !== "dragging") {
|
---|
2292 | return;
|
---|
2293 | } else if (elem.node.nodeType === "Stage") {
|
---|
2294 | layerUnderDrag = true;
|
---|
2295 | } else if (elem.node.getLayer() === layer) {
|
---|
2296 | layerUnderDrag = true;
|
---|
2297 | }
|
---|
2298 | });
|
---|
2299 | var dragSkip = !skipDragCheck && !Global_1.Konva.hitOnDragEnabled && (layerUnderDrag || Global_1.Konva.isTransforming());
|
---|
2300 | return this.isListening() && this.isVisible() && !dragSkip;
|
---|
2301 | }
|
---|
2302 | show() {
|
---|
2303 | this.visible(true);
|
---|
2304 | return this;
|
---|
2305 | }
|
---|
2306 | hide() {
|
---|
2307 | this.visible(false);
|
---|
2308 | return this;
|
---|
2309 | }
|
---|
2310 | getZIndex() {
|
---|
2311 | return this.index || 0;
|
---|
2312 | }
|
---|
2313 | getAbsoluteZIndex() {
|
---|
2314 | var depth = this.getDepth(), that = this, index = 0, nodes, len, n, child;
|
---|
2315 | function addChildren(children) {
|
---|
2316 | nodes = [];
|
---|
2317 | len = children.length;
|
---|
2318 | for (n = 0; n < len; n++) {
|
---|
2319 | child = children[n];
|
---|
2320 | index++;
|
---|
2321 | if (child.nodeType !== SHAPE) {
|
---|
2322 | nodes = nodes.concat(child.getChildren().slice());
|
---|
2323 | }
|
---|
2324 | if (child._id === that._id) {
|
---|
2325 | n = len;
|
---|
2326 | }
|
---|
2327 | }
|
---|
2328 | if (nodes.length > 0 && nodes[0].getDepth() <= depth) {
|
---|
2329 | addChildren(nodes);
|
---|
2330 | }
|
---|
2331 | }
|
---|
2332 | const stage = this.getStage();
|
---|
2333 | if (that.nodeType !== UPPER_STAGE && stage) {
|
---|
2334 | addChildren(stage.getChildren());
|
---|
2335 | }
|
---|
2336 | return index;
|
---|
2337 | }
|
---|
2338 | getDepth() {
|
---|
2339 | var depth = 0, parent = this.parent;
|
---|
2340 | while (parent) {
|
---|
2341 | depth++;
|
---|
2342 | parent = parent.parent;
|
---|
2343 | }
|
---|
2344 | return depth;
|
---|
2345 | }
|
---|
2346 | _batchTransformChanges(func) {
|
---|
2347 | this._batchingTransformChange = true;
|
---|
2348 | func();
|
---|
2349 | this._batchingTransformChange = false;
|
---|
2350 | if (this._needClearTransformCache) {
|
---|
2351 | this._clearCache(TRANSFORM);
|
---|
2352 | this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
---|
2353 | }
|
---|
2354 | this._needClearTransformCache = false;
|
---|
2355 | }
|
---|
2356 | setPosition(pos) {
|
---|
2357 | this._batchTransformChanges(() => {
|
---|
2358 | this.x(pos.x);
|
---|
2359 | this.y(pos.y);
|
---|
2360 | });
|
---|
2361 | return this;
|
---|
2362 | }
|
---|
2363 | getPosition() {
|
---|
2364 | return {
|
---|
2365 | x: this.x(),
|
---|
2366 | y: this.y()
|
---|
2367 | };
|
---|
2368 | }
|
---|
2369 | getRelativePointerPosition() {
|
---|
2370 | const stage = this.getStage();
|
---|
2371 | if (!stage) {
|
---|
2372 | return null;
|
---|
2373 | }
|
---|
2374 | var pos = stage.getPointerPosition();
|
---|
2375 | if (!pos) {
|
---|
2376 | return null;
|
---|
2377 | }
|
---|
2378 | var transform = this.getAbsoluteTransform().copy();
|
---|
2379 | transform.invert();
|
---|
2380 | return transform.point(pos);
|
---|
2381 | }
|
---|
2382 | getAbsolutePosition(top) {
|
---|
2383 | let haveCachedParent = false;
|
---|
2384 | let parent = this.parent;
|
---|
2385 | while (parent) {
|
---|
2386 | if (parent.isCached()) {
|
---|
2387 | haveCachedParent = true;
|
---|
2388 | break;
|
---|
2389 | }
|
---|
2390 | parent = parent.parent;
|
---|
2391 | }
|
---|
2392 | if (haveCachedParent && !top) {
|
---|
2393 | top = true;
|
---|
2394 | }
|
---|
2395 | var absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Util_1.Transform(), offset = this.offset();
|
---|
2396 | absoluteTransform.m = absoluteMatrix.slice();
|
---|
2397 | absoluteTransform.translate(offset.x, offset.y);
|
---|
2398 | return absoluteTransform.getTranslation();
|
---|
2399 | }
|
---|
2400 | setAbsolutePosition(pos) {
|
---|
2401 | const { x, y, ...origTrans } = this._clearTransform();
|
---|
2402 | this.attrs.x = x;
|
---|
2403 | this.attrs.y = y;
|
---|
2404 | this._clearCache(TRANSFORM);
|
---|
2405 | var it = this._getAbsoluteTransform().copy();
|
---|
2406 | it.invert();
|
---|
2407 | it.translate(pos.x, pos.y);
|
---|
2408 | pos = {
|
---|
2409 | x: this.attrs.x + it.getTranslation().x,
|
---|
2410 | y: this.attrs.y + it.getTranslation().y
|
---|
2411 | };
|
---|
2412 | this._setTransform(origTrans);
|
---|
2413 | this.setPosition({ x: pos.x, y: pos.y });
|
---|
2414 | this._clearCache(TRANSFORM);
|
---|
2415 | this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
---|
2416 | return this;
|
---|
2417 | }
|
---|
2418 | _setTransform(trans) {
|
---|
2419 | var key;
|
---|
2420 | for (key in trans) {
|
---|
2421 | this.attrs[key] = trans[key];
|
---|
2422 | }
|
---|
2423 | }
|
---|
2424 | _clearTransform() {
|
---|
2425 | var trans = {
|
---|
2426 | x: this.x(),
|
---|
2427 | y: this.y(),
|
---|
2428 | rotation: this.rotation(),
|
---|
2429 | scaleX: this.scaleX(),
|
---|
2430 | scaleY: this.scaleY(),
|
---|
2431 | offsetX: this.offsetX(),
|
---|
2432 | offsetY: this.offsetY(),
|
---|
2433 | skewX: this.skewX(),
|
---|
2434 | skewY: this.skewY()
|
---|
2435 | };
|
---|
2436 | this.attrs.x = 0;
|
---|
2437 | this.attrs.y = 0;
|
---|
2438 | this.attrs.rotation = 0;
|
---|
2439 | this.attrs.scaleX = 1;
|
---|
2440 | this.attrs.scaleY = 1;
|
---|
2441 | this.attrs.offsetX = 0;
|
---|
2442 | this.attrs.offsetY = 0;
|
---|
2443 | this.attrs.skewX = 0;
|
---|
2444 | this.attrs.skewY = 0;
|
---|
2445 | return trans;
|
---|
2446 | }
|
---|
2447 | move(change) {
|
---|
2448 | var changeX = change.x, changeY = change.y, x = this.x(), y = this.y();
|
---|
2449 | if (changeX !== void 0) {
|
---|
2450 | x += changeX;
|
---|
2451 | }
|
---|
2452 | if (changeY !== void 0) {
|
---|
2453 | y += changeY;
|
---|
2454 | }
|
---|
2455 | this.setPosition({ x, y });
|
---|
2456 | return this;
|
---|
2457 | }
|
---|
2458 | _eachAncestorReverse(func, top) {
|
---|
2459 | var family = [], parent = this.getParent(), len, n;
|
---|
2460 | if (top && top._id === this._id) {
|
---|
2461 | return;
|
---|
2462 | }
|
---|
2463 | family.unshift(this);
|
---|
2464 | while (parent && (!top || parent._id !== top._id)) {
|
---|
2465 | family.unshift(parent);
|
---|
2466 | parent = parent.parent;
|
---|
2467 | }
|
---|
2468 | len = family.length;
|
---|
2469 | for (n = 0; n < len; n++) {
|
---|
2470 | func(family[n]);
|
---|
2471 | }
|
---|
2472 | }
|
---|
2473 | rotate(theta) {
|
---|
2474 | this.rotation(this.rotation() + theta);
|
---|
2475 | return this;
|
---|
2476 | }
|
---|
2477 | moveToTop() {
|
---|
2478 | if (!this.parent) {
|
---|
2479 | Util_1.Util.warn("Node has no parent. moveToTop function is ignored.");
|
---|
2480 | return false;
|
---|
2481 | }
|
---|
2482 | var index = this.index, len = this.parent.getChildren().length;
|
---|
2483 | if (index < len - 1) {
|
---|
2484 | this.parent.children.splice(index, 1);
|
---|
2485 | this.parent.children.push(this);
|
---|
2486 | this.parent._setChildrenIndices();
|
---|
2487 | return true;
|
---|
2488 | }
|
---|
2489 | return false;
|
---|
2490 | }
|
---|
2491 | moveUp() {
|
---|
2492 | if (!this.parent) {
|
---|
2493 | Util_1.Util.warn("Node has no parent. moveUp function is ignored.");
|
---|
2494 | return false;
|
---|
2495 | }
|
---|
2496 | var index = this.index, len = this.parent.getChildren().length;
|
---|
2497 | if (index < len - 1) {
|
---|
2498 | this.parent.children.splice(index, 1);
|
---|
2499 | this.parent.children.splice(index + 1, 0, this);
|
---|
2500 | this.parent._setChildrenIndices();
|
---|
2501 | return true;
|
---|
2502 | }
|
---|
2503 | return false;
|
---|
2504 | }
|
---|
2505 | moveDown() {
|
---|
2506 | if (!this.parent) {
|
---|
2507 | Util_1.Util.warn("Node has no parent. moveDown function is ignored.");
|
---|
2508 | return false;
|
---|
2509 | }
|
---|
2510 | var index = this.index;
|
---|
2511 | if (index > 0) {
|
---|
2512 | this.parent.children.splice(index, 1);
|
---|
2513 | this.parent.children.splice(index - 1, 0, this);
|
---|
2514 | this.parent._setChildrenIndices();
|
---|
2515 | return true;
|
---|
2516 | }
|
---|
2517 | return false;
|
---|
2518 | }
|
---|
2519 | moveToBottom() {
|
---|
2520 | if (!this.parent) {
|
---|
2521 | Util_1.Util.warn("Node has no parent. moveToBottom function is ignored.");
|
---|
2522 | return false;
|
---|
2523 | }
|
---|
2524 | var index = this.index;
|
---|
2525 | if (index > 0) {
|
---|
2526 | this.parent.children.splice(index, 1);
|
---|
2527 | this.parent.children.unshift(this);
|
---|
2528 | this.parent._setChildrenIndices();
|
---|
2529 | return true;
|
---|
2530 | }
|
---|
2531 | return false;
|
---|
2532 | }
|
---|
2533 | setZIndex(zIndex) {
|
---|
2534 | if (!this.parent) {
|
---|
2535 | Util_1.Util.warn("Node has no parent. zIndex parameter is ignored.");
|
---|
2536 | return this;
|
---|
2537 | }
|
---|
2538 | if (zIndex < 0 || zIndex >= this.parent.children.length) {
|
---|
2539 | Util_1.Util.warn("Unexpected value " + zIndex + " for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to " + (this.parent.children.length - 1) + ".");
|
---|
2540 | }
|
---|
2541 | var index = this.index;
|
---|
2542 | this.parent.children.splice(index, 1);
|
---|
2543 | this.parent.children.splice(zIndex, 0, this);
|
---|
2544 | this.parent._setChildrenIndices();
|
---|
2545 | return this;
|
---|
2546 | }
|
---|
2547 | getAbsoluteOpacity() {
|
---|
2548 | return this._getCache(ABSOLUTE_OPACITY, this._getAbsoluteOpacity);
|
---|
2549 | }
|
---|
2550 | _getAbsoluteOpacity() {
|
---|
2551 | var absOpacity = this.opacity();
|
---|
2552 | var parent = this.getParent();
|
---|
2553 | if (parent && !parent._isUnderCache) {
|
---|
2554 | absOpacity *= parent.getAbsoluteOpacity();
|
---|
2555 | }
|
---|
2556 | return absOpacity;
|
---|
2557 | }
|
---|
2558 | moveTo(newContainer) {
|
---|
2559 | if (this.getParent() !== newContainer) {
|
---|
2560 | this._remove();
|
---|
2561 | newContainer.add(this);
|
---|
2562 | }
|
---|
2563 | return this;
|
---|
2564 | }
|
---|
2565 | toObject() {
|
---|
2566 | var attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;
|
---|
2567 | const obj = {
|
---|
2568 | attrs: {},
|
---|
2569 | className: this.getClassName()
|
---|
2570 | };
|
---|
2571 | for (key in attrs) {
|
---|
2572 | val = attrs[key];
|
---|
2573 | nonPlainObject = Util_1.Util.isObject(val) && !Util_1.Util._isPlainObject(val) && !Util_1.Util._isArray(val);
|
---|
2574 | if (nonPlainObject) {
|
---|
2575 | continue;
|
---|
2576 | }
|
---|
2577 | getter = typeof this[key] === "function" && this[key];
|
---|
2578 | delete attrs[key];
|
---|
2579 | defaultValue = getter ? getter.call(this) : null;
|
---|
2580 | attrs[key] = val;
|
---|
2581 | if (defaultValue !== val) {
|
---|
2582 | obj.attrs[key] = val;
|
---|
2583 | }
|
---|
2584 | }
|
---|
2585 | return Util_1.Util._prepareToStringify(obj);
|
---|
2586 | }
|
---|
2587 | toJSON() {
|
---|
2588 | return JSON.stringify(this.toObject());
|
---|
2589 | }
|
---|
2590 | getParent() {
|
---|
2591 | return this.parent;
|
---|
2592 | }
|
---|
2593 | findAncestors(selector, includeSelf, stopNode) {
|
---|
2594 | var res = [];
|
---|
2595 | if (includeSelf && this._isMatch(selector)) {
|
---|
2596 | res.push(this);
|
---|
2597 | }
|
---|
2598 | var ancestor = this.parent;
|
---|
2599 | while (ancestor) {
|
---|
2600 | if (ancestor === stopNode) {
|
---|
2601 | return res;
|
---|
2602 | }
|
---|
2603 | if (ancestor._isMatch(selector)) {
|
---|
2604 | res.push(ancestor);
|
---|
2605 | }
|
---|
2606 | ancestor = ancestor.parent;
|
---|
2607 | }
|
---|
2608 | return res;
|
---|
2609 | }
|
---|
2610 | isAncestorOf(node) {
|
---|
2611 | return false;
|
---|
2612 | }
|
---|
2613 | findAncestor(selector, includeSelf, stopNode) {
|
---|
2614 | return this.findAncestors(selector, includeSelf, stopNode)[0];
|
---|
2615 | }
|
---|
2616 | _isMatch(selector) {
|
---|
2617 | if (!selector) {
|
---|
2618 | return false;
|
---|
2619 | }
|
---|
2620 | if (typeof selector === "function") {
|
---|
2621 | return selector(this);
|
---|
2622 | }
|
---|
2623 | var selectorArr = selector.replace(/ /g, "").split(","), len = selectorArr.length, n, sel;
|
---|
2624 | for (n = 0; n < len; n++) {
|
---|
2625 | sel = selectorArr[n];
|
---|
2626 | if (!Util_1.Util.isValidSelector(sel)) {
|
---|
2627 | Util_1.Util.warn('Selector "' + sel + '" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".');
|
---|
2628 | Util_1.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".');
|
---|
2629 | Util_1.Util.warn("Konva is awesome, right?");
|
---|
2630 | }
|
---|
2631 | if (sel.charAt(0) === "#") {
|
---|
2632 | if (this.id() === sel.slice(1)) {
|
---|
2633 | return true;
|
---|
2634 | }
|
---|
2635 | } else if (sel.charAt(0) === ".") {
|
---|
2636 | if (this.hasName(sel.slice(1))) {
|
---|
2637 | return true;
|
---|
2638 | }
|
---|
2639 | } else if (this.className === sel || this.nodeType === sel) {
|
---|
2640 | return true;
|
---|
2641 | }
|
---|
2642 | }
|
---|
2643 | return false;
|
---|
2644 | }
|
---|
2645 | getLayer() {
|
---|
2646 | var parent = this.getParent();
|
---|
2647 | return parent ? parent.getLayer() : null;
|
---|
2648 | }
|
---|
2649 | getStage() {
|
---|
2650 | return this._getCache(STAGE, this._getStage);
|
---|
2651 | }
|
---|
2652 | _getStage() {
|
---|
2653 | var parent = this.getParent();
|
---|
2654 | if (parent) {
|
---|
2655 | return parent.getStage();
|
---|
2656 | } else {
|
---|
2657 | return null;
|
---|
2658 | }
|
---|
2659 | }
|
---|
2660 | fire(eventType, evt = {}, bubble) {
|
---|
2661 | evt.target = evt.target || this;
|
---|
2662 | if (bubble) {
|
---|
2663 | this._fireAndBubble(eventType, evt);
|
---|
2664 | } else {
|
---|
2665 | this._fire(eventType, evt);
|
---|
2666 | }
|
---|
2667 | return this;
|
---|
2668 | }
|
---|
2669 | getAbsoluteTransform(top) {
|
---|
2670 | if (top) {
|
---|
2671 | return this._getAbsoluteTransform(top);
|
---|
2672 | } else {
|
---|
2673 | return this._getCache(ABSOLUTE_TRANSFORM, this._getAbsoluteTransform);
|
---|
2674 | }
|
---|
2675 | }
|
---|
2676 | _getAbsoluteTransform(top) {
|
---|
2677 | var at;
|
---|
2678 | if (top) {
|
---|
2679 | at = new Util_1.Transform();
|
---|
2680 | this._eachAncestorReverse(function(node) {
|
---|
2681 | var transformsEnabled2 = node.transformsEnabled();
|
---|
2682 | if (transformsEnabled2 === "all") {
|
---|
2683 | at.multiply(node.getTransform());
|
---|
2684 | } else if (transformsEnabled2 === "position") {
|
---|
2685 | at.translate(node.x() - node.offsetX(), node.y() - node.offsetY());
|
---|
2686 | }
|
---|
2687 | }, top);
|
---|
2688 | return at;
|
---|
2689 | } else {
|
---|
2690 | at = this._cache.get(ABSOLUTE_TRANSFORM) || new Util_1.Transform();
|
---|
2691 | if (this.parent) {
|
---|
2692 | this.parent.getAbsoluteTransform().copyInto(at);
|
---|
2693 | } else {
|
---|
2694 | at.reset();
|
---|
2695 | }
|
---|
2696 | var transformsEnabled = this.transformsEnabled();
|
---|
2697 | if (transformsEnabled === "all") {
|
---|
2698 | at.multiply(this.getTransform());
|
---|
2699 | } else if (transformsEnabled === "position") {
|
---|
2700 | const x = this.attrs.x || 0;
|
---|
2701 | const y = this.attrs.y || 0;
|
---|
2702 | const offsetX = this.attrs.offsetX || 0;
|
---|
2703 | const offsetY = this.attrs.offsetY || 0;
|
---|
2704 | at.translate(x - offsetX, y - offsetY);
|
---|
2705 | }
|
---|
2706 | at.dirty = false;
|
---|
2707 | return at;
|
---|
2708 | }
|
---|
2709 | }
|
---|
2710 | getAbsoluteScale(top) {
|
---|
2711 | var parent = this;
|
---|
2712 | while (parent) {
|
---|
2713 | if (parent._isUnderCache) {
|
---|
2714 | top = parent;
|
---|
2715 | }
|
---|
2716 | parent = parent.getParent();
|
---|
2717 | }
|
---|
2718 | const transform = this.getAbsoluteTransform(top);
|
---|
2719 | const attrs = transform.decompose();
|
---|
2720 | return {
|
---|
2721 | x: attrs.scaleX,
|
---|
2722 | y: attrs.scaleY
|
---|
2723 | };
|
---|
2724 | }
|
---|
2725 | getAbsoluteRotation() {
|
---|
2726 | return this.getAbsoluteTransform().decompose().rotation;
|
---|
2727 | }
|
---|
2728 | getTransform() {
|
---|
2729 | return this._getCache(TRANSFORM, this._getTransform);
|
---|
2730 | }
|
---|
2731 | _getTransform() {
|
---|
2732 | var _a, _b;
|
---|
2733 | var m = this._cache.get(TRANSFORM) || new Util_1.Transform();
|
---|
2734 | m.reset();
|
---|
2735 | var x = this.x(), y = this.y(), rotation = Global_1.Konva.getAngle(this.rotation()), scaleX = (_a = this.attrs.scaleX) !== null && _a !== void 0 ? _a : 1, scaleY = (_b = this.attrs.scaleY) !== null && _b !== void 0 ? _b : 1, skewX = this.attrs.skewX || 0, skewY = this.attrs.skewY || 0, offsetX = this.attrs.offsetX || 0, offsetY = this.attrs.offsetY || 0;
|
---|
2736 | if (x !== 0 || y !== 0) {
|
---|
2737 | m.translate(x, y);
|
---|
2738 | }
|
---|
2739 | if (rotation !== 0) {
|
---|
2740 | m.rotate(rotation);
|
---|
2741 | }
|
---|
2742 | if (skewX !== 0 || skewY !== 0) {
|
---|
2743 | m.skew(skewX, skewY);
|
---|
2744 | }
|
---|
2745 | if (scaleX !== 1 || scaleY !== 1) {
|
---|
2746 | m.scale(scaleX, scaleY);
|
---|
2747 | }
|
---|
2748 | if (offsetX !== 0 || offsetY !== 0) {
|
---|
2749 | m.translate(-1 * offsetX, -1 * offsetY);
|
---|
2750 | }
|
---|
2751 | m.dirty = false;
|
---|
2752 | return m;
|
---|
2753 | }
|
---|
2754 | clone(obj) {
|
---|
2755 | var attrs = Util_1.Util.cloneObject(this.attrs), key, allListeners, len, n, listener;
|
---|
2756 | for (key in obj) {
|
---|
2757 | attrs[key] = obj[key];
|
---|
2758 | }
|
---|
2759 | var node = new this.constructor(attrs);
|
---|
2760 | for (key in this.eventListeners) {
|
---|
2761 | allListeners = this.eventListeners[key];
|
---|
2762 | len = allListeners.length;
|
---|
2763 | for (n = 0; n < len; n++) {
|
---|
2764 | listener = allListeners[n];
|
---|
2765 | if (listener.name.indexOf(KONVA) < 0) {
|
---|
2766 | if (!node.eventListeners[key]) {
|
---|
2767 | node.eventListeners[key] = [];
|
---|
2768 | }
|
---|
2769 | node.eventListeners[key].push(listener);
|
---|
2770 | }
|
---|
2771 | }
|
---|
2772 | }
|
---|
2773 | return node;
|
---|
2774 | }
|
---|
2775 | _toKonvaCanvas(config) {
|
---|
2776 | config = config || {};
|
---|
2777 | var box = this.getClientRect();
|
---|
2778 | var stage = this.getStage(), x = config.x !== void 0 ? config.x : Math.floor(box.x), y = config.y !== void 0 ? config.y : Math.floor(box.y), pixelRatio = config.pixelRatio || 1, canvas = new Canvas_1.SceneCanvas({
|
---|
2779 | width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0),
|
---|
2780 | height: config.height || Math.ceil(box.height) || (stage ? stage.height() : 0),
|
---|
2781 | pixelRatio
|
---|
2782 | }), context = canvas.getContext();
|
---|
2783 | const bufferCanvas = new Canvas_1.SceneCanvas({
|
---|
2784 | width: canvas.width / canvas.pixelRatio + Math.abs(x),
|
---|
2785 | height: canvas.height / canvas.pixelRatio + Math.abs(y),
|
---|
2786 | pixelRatio: canvas.pixelRatio
|
---|
2787 | });
|
---|
2788 | if (config.imageSmoothingEnabled === false) {
|
---|
2789 | context._context.imageSmoothingEnabled = false;
|
---|
2790 | }
|
---|
2791 | context.save();
|
---|
2792 | if (x || y) {
|
---|
2793 | context.translate(-1 * x, -1 * y);
|
---|
2794 | }
|
---|
2795 | this.drawScene(canvas, void 0, bufferCanvas);
|
---|
2796 | context.restore();
|
---|
2797 | return canvas;
|
---|
2798 | }
|
---|
2799 | toCanvas(config) {
|
---|
2800 | return this._toKonvaCanvas(config)._canvas;
|
---|
2801 | }
|
---|
2802 | toDataURL(config) {
|
---|
2803 | config = config || {};
|
---|
2804 | var mimeType = config.mimeType || null, quality = config.quality || null;
|
---|
2805 | var url = this._toKonvaCanvas(config).toDataURL(mimeType, quality);
|
---|
2806 | if (config.callback) {
|
---|
2807 | config.callback(url);
|
---|
2808 | }
|
---|
2809 | return url;
|
---|
2810 | }
|
---|
2811 | toImage(config) {
|
---|
2812 | return new Promise((resolve, reject) => {
|
---|
2813 | try {
|
---|
2814 | const callback = config === null || config === void 0 ? void 0 : config.callback;
|
---|
2815 | if (callback)
|
---|
2816 | delete config.callback;
|
---|
2817 | Util_1.Util._urlToImage(this.toDataURL(config), function(img) {
|
---|
2818 | resolve(img);
|
---|
2819 | callback === null || callback === void 0 ? void 0 : callback(img);
|
---|
2820 | });
|
---|
2821 | } catch (err) {
|
---|
2822 | reject(err);
|
---|
2823 | }
|
---|
2824 | });
|
---|
2825 | }
|
---|
2826 | toBlob(config) {
|
---|
2827 | return new Promise((resolve, reject) => {
|
---|
2828 | try {
|
---|
2829 | const callback = config === null || config === void 0 ? void 0 : config.callback;
|
---|
2830 | if (callback)
|
---|
2831 | delete config.callback;
|
---|
2832 | this.toCanvas(config).toBlob((blob) => {
|
---|
2833 | resolve(blob);
|
---|
2834 | callback === null || callback === void 0 ? void 0 : callback(blob);
|
---|
2835 | }, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality);
|
---|
2836 | } catch (err) {
|
---|
2837 | reject(err);
|
---|
2838 | }
|
---|
2839 | });
|
---|
2840 | }
|
---|
2841 | setSize(size) {
|
---|
2842 | this.width(size.width);
|
---|
2843 | this.height(size.height);
|
---|
2844 | return this;
|
---|
2845 | }
|
---|
2846 | getSize() {
|
---|
2847 | return {
|
---|
2848 | width: this.width(),
|
---|
2849 | height: this.height()
|
---|
2850 | };
|
---|
2851 | }
|
---|
2852 | getClassName() {
|
---|
2853 | return this.className || this.nodeType;
|
---|
2854 | }
|
---|
2855 | getType() {
|
---|
2856 | return this.nodeType;
|
---|
2857 | }
|
---|
2858 | getDragDistance() {
|
---|
2859 | if (this.attrs.dragDistance !== void 0) {
|
---|
2860 | return this.attrs.dragDistance;
|
---|
2861 | } else if (this.parent) {
|
---|
2862 | return this.parent.getDragDistance();
|
---|
2863 | } else {
|
---|
2864 | return Global_1.Konva.dragDistance;
|
---|
2865 | }
|
---|
2866 | }
|
---|
2867 | _off(type, name, callback) {
|
---|
2868 | var evtListeners = this.eventListeners[type], i, evtName, handler;
|
---|
2869 | for (i = 0; i < evtListeners.length; i++) {
|
---|
2870 | evtName = evtListeners[i].name;
|
---|
2871 | handler = evtListeners[i].handler;
|
---|
2872 | if ((evtName !== "konva" || name === "konva") && (!name || evtName === name) && (!callback || callback === handler)) {
|
---|
2873 | evtListeners.splice(i, 1);
|
---|
2874 | if (evtListeners.length === 0) {
|
---|
2875 | delete this.eventListeners[type];
|
---|
2876 | break;
|
---|
2877 | }
|
---|
2878 | i--;
|
---|
2879 | }
|
---|
2880 | }
|
---|
2881 | }
|
---|
2882 | _fireChangeEvent(attr, oldVal, newVal) {
|
---|
2883 | this._fire(attr + CHANGE, {
|
---|
2884 | oldVal,
|
---|
2885 | newVal
|
---|
2886 | });
|
---|
2887 | }
|
---|
2888 | addName(name) {
|
---|
2889 | if (!this.hasName(name)) {
|
---|
2890 | var oldName = this.name();
|
---|
2891 | var newName = oldName ? oldName + " " + name : name;
|
---|
2892 | this.name(newName);
|
---|
2893 | }
|
---|
2894 | return this;
|
---|
2895 | }
|
---|
2896 | hasName(name) {
|
---|
2897 | if (!name) {
|
---|
2898 | return false;
|
---|
2899 | }
|
---|
2900 | const fullName = this.name();
|
---|
2901 | if (!fullName) {
|
---|
2902 | return false;
|
---|
2903 | }
|
---|
2904 | var names = (fullName || "").split(/\s/g);
|
---|
2905 | return names.indexOf(name) !== -1;
|
---|
2906 | }
|
---|
2907 | removeName(name) {
|
---|
2908 | var names = (this.name() || "").split(/\s/g);
|
---|
2909 | var index = names.indexOf(name);
|
---|
2910 | if (index !== -1) {
|
---|
2911 | names.splice(index, 1);
|
---|
2912 | this.name(names.join(" "));
|
---|
2913 | }
|
---|
2914 | return this;
|
---|
2915 | }
|
---|
2916 | setAttr(attr, val) {
|
---|
2917 | var func = this[SET + Util_1.Util._capitalize(attr)];
|
---|
2918 | if (Util_1.Util._isFunction(func)) {
|
---|
2919 | func.call(this, val);
|
---|
2920 | } else {
|
---|
2921 | this._setAttr(attr, val);
|
---|
2922 | }
|
---|
2923 | return this;
|
---|
2924 | }
|
---|
2925 | _requestDraw() {
|
---|
2926 | if (Global_1.Konva.autoDrawEnabled) {
|
---|
2927 | const drawNode = this.getLayer() || this.getStage();
|
---|
2928 | drawNode === null || drawNode === void 0 ? void 0 : drawNode.batchDraw();
|
---|
2929 | }
|
---|
2930 | }
|
---|
2931 | _setAttr(key, val) {
|
---|
2932 | var oldVal = this.attrs[key];
|
---|
2933 | if (oldVal === val && !Util_1.Util.isObject(val)) {
|
---|
2934 | return;
|
---|
2935 | }
|
---|
2936 | if (val === void 0 || val === null) {
|
---|
2937 | delete this.attrs[key];
|
---|
2938 | } else {
|
---|
2939 | this.attrs[key] = val;
|
---|
2940 | }
|
---|
2941 | if (this._shouldFireChangeEvents) {
|
---|
2942 | this._fireChangeEvent(key, oldVal, val);
|
---|
2943 | }
|
---|
2944 | this._requestDraw();
|
---|
2945 | }
|
---|
2946 | _setComponentAttr(key, component, val) {
|
---|
2947 | var oldVal;
|
---|
2948 | if (val !== void 0) {
|
---|
2949 | oldVal = this.attrs[key];
|
---|
2950 | if (!oldVal) {
|
---|
2951 | this.attrs[key] = this.getAttr(key);
|
---|
2952 | }
|
---|
2953 | this.attrs[key][component] = val;
|
---|
2954 | this._fireChangeEvent(key, oldVal, val);
|
---|
2955 | }
|
---|
2956 | }
|
---|
2957 | _fireAndBubble(eventType, evt, compareShape) {
|
---|
2958 | if (evt && this.nodeType === SHAPE) {
|
---|
2959 | evt.target = this;
|
---|
2960 | }
|
---|
2961 | var shouldStop = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && (compareShape && (this === compareShape || this.isAncestorOf && this.isAncestorOf(compareShape)) || this.nodeType === "Stage" && !compareShape);
|
---|
2962 | if (!shouldStop) {
|
---|
2963 | this._fire(eventType, evt);
|
---|
2964 | var stopBubble = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && compareShape && compareShape.isAncestorOf && compareShape.isAncestorOf(this) && !compareShape.isAncestorOf(this.parent);
|
---|
2965 | if ((evt && !evt.cancelBubble || !evt) && this.parent && this.parent.isListening() && !stopBubble) {
|
---|
2966 | if (compareShape && compareShape.parent) {
|
---|
2967 | this._fireAndBubble.call(this.parent, eventType, evt, compareShape);
|
---|
2968 | } else {
|
---|
2969 | this._fireAndBubble.call(this.parent, eventType, evt);
|
---|
2970 | }
|
---|
2971 | }
|
---|
2972 | }
|
---|
2973 | }
|
---|
2974 | _getProtoListeners(eventType) {
|
---|
2975 | var _a, _b, _c;
|
---|
2976 | const allListeners = (_a = this._cache.get(ALL_LISTENERS)) !== null && _a !== void 0 ? _a : {};
|
---|
2977 | let events = allListeners === null || allListeners === void 0 ? void 0 : allListeners[eventType];
|
---|
2978 | if (events === void 0) {
|
---|
2979 | events = [];
|
---|
2980 | let obj = Object.getPrototypeOf(this);
|
---|
2981 | while (obj) {
|
---|
2982 | const hierarchyEvents = (_c = (_b = obj.eventListeners) === null || _b === void 0 ? void 0 : _b[eventType]) !== null && _c !== void 0 ? _c : [];
|
---|
2983 | events.push(...hierarchyEvents);
|
---|
2984 | obj = Object.getPrototypeOf(obj);
|
---|
2985 | }
|
---|
2986 | allListeners[eventType] = events;
|
---|
2987 | this._cache.set(ALL_LISTENERS, allListeners);
|
---|
2988 | }
|
---|
2989 | return events;
|
---|
2990 | }
|
---|
2991 | _fire(eventType, evt) {
|
---|
2992 | evt = evt || {};
|
---|
2993 | evt.currentTarget = this;
|
---|
2994 | evt.type = eventType;
|
---|
2995 | const topListeners = this._getProtoListeners(eventType);
|
---|
2996 | if (topListeners) {
|
---|
2997 | for (var i = 0; i < topListeners.length; i++) {
|
---|
2998 | topListeners[i].handler.call(this, evt);
|
---|
2999 | }
|
---|
3000 | }
|
---|
3001 | const selfListeners = this.eventListeners[eventType];
|
---|
3002 | if (selfListeners) {
|
---|
3003 | for (var i = 0; i < selfListeners.length; i++) {
|
---|
3004 | selfListeners[i].handler.call(this, evt);
|
---|
3005 | }
|
---|
3006 | }
|
---|
3007 | }
|
---|
3008 | draw() {
|
---|
3009 | this.drawScene();
|
---|
3010 | this.drawHit();
|
---|
3011 | return this;
|
---|
3012 | }
|
---|
3013 | _createDragElement(evt) {
|
---|
3014 | var pointerId = evt ? evt.pointerId : void 0;
|
---|
3015 | var stage = this.getStage();
|
---|
3016 | var ap = this.getAbsolutePosition();
|
---|
3017 | if (!stage) {
|
---|
3018 | return;
|
---|
3019 | }
|
---|
3020 | var pos = stage._getPointerById(pointerId) || stage._changedPointerPositions[0] || ap;
|
---|
3021 | DragAndDrop_1.DD._dragElements.set(this._id, {
|
---|
3022 | node: this,
|
---|
3023 | startPointerPos: pos,
|
---|
3024 | offset: {
|
---|
3025 | x: pos.x - ap.x,
|
---|
3026 | y: pos.y - ap.y
|
---|
3027 | },
|
---|
3028 | dragStatus: "ready",
|
---|
3029 | pointerId
|
---|
3030 | });
|
---|
3031 | }
|
---|
3032 | startDrag(evt, bubbleEvent = true) {
|
---|
3033 | if (!DragAndDrop_1.DD._dragElements.has(this._id)) {
|
---|
3034 | this._createDragElement(evt);
|
---|
3035 | }
|
---|
3036 | const elem = DragAndDrop_1.DD._dragElements.get(this._id);
|
---|
3037 | elem.dragStatus = "dragging";
|
---|
3038 | this.fire("dragstart", {
|
---|
3039 | type: "dragstart",
|
---|
3040 | target: this,
|
---|
3041 | evt: evt && evt.evt
|
---|
3042 | }, bubbleEvent);
|
---|
3043 | }
|
---|
3044 | _setDragPosition(evt, elem) {
|
---|
3045 | const pos = this.getStage()._getPointerById(elem.pointerId);
|
---|
3046 | if (!pos) {
|
---|
3047 | return;
|
---|
3048 | }
|
---|
3049 | var newNodePos = {
|
---|
3050 | x: pos.x - elem.offset.x,
|
---|
3051 | y: pos.y - elem.offset.y
|
---|
3052 | };
|
---|
3053 | var dbf = this.dragBoundFunc();
|
---|
3054 | if (dbf !== void 0) {
|
---|
3055 | const bounded = dbf.call(this, newNodePos, evt);
|
---|
3056 | if (!bounded) {
|
---|
3057 | Util_1.Util.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.");
|
---|
3058 | } else {
|
---|
3059 | newNodePos = bounded;
|
---|
3060 | }
|
---|
3061 | }
|
---|
3062 | if (!this._lastPos || this._lastPos.x !== newNodePos.x || this._lastPos.y !== newNodePos.y) {
|
---|
3063 | this.setAbsolutePosition(newNodePos);
|
---|
3064 | this._requestDraw();
|
---|
3065 | }
|
---|
3066 | this._lastPos = newNodePos;
|
---|
3067 | }
|
---|
3068 | stopDrag(evt) {
|
---|
3069 | const elem = DragAndDrop_1.DD._dragElements.get(this._id);
|
---|
3070 | if (elem) {
|
---|
3071 | elem.dragStatus = "stopped";
|
---|
3072 | }
|
---|
3073 | DragAndDrop_1.DD._endDragBefore(evt);
|
---|
3074 | DragAndDrop_1.DD._endDragAfter(evt);
|
---|
3075 | }
|
---|
3076 | setDraggable(draggable) {
|
---|
3077 | this._setAttr("draggable", draggable);
|
---|
3078 | this._dragChange();
|
---|
3079 | }
|
---|
3080 | isDragging() {
|
---|
3081 | const elem = DragAndDrop_1.DD._dragElements.get(this._id);
|
---|
3082 | return elem ? elem.dragStatus === "dragging" : false;
|
---|
3083 | }
|
---|
3084 | _listenDrag() {
|
---|
3085 | this._dragCleanup();
|
---|
3086 | this.on("mousedown.konva touchstart.konva", function(evt) {
|
---|
3087 | var shouldCheckButton = evt.evt["button"] !== void 0;
|
---|
3088 | var canDrag = !shouldCheckButton || Global_1.Konva.dragButtons.indexOf(evt.evt["button"]) >= 0;
|
---|
3089 | if (!canDrag) {
|
---|
3090 | return;
|
---|
3091 | }
|
---|
3092 | if (this.isDragging()) {
|
---|
3093 | return;
|
---|
3094 | }
|
---|
3095 | var hasDraggingChild = false;
|
---|
3096 | DragAndDrop_1.DD._dragElements.forEach((elem) => {
|
---|
3097 | if (this.isAncestorOf(elem.node)) {
|
---|
3098 | hasDraggingChild = true;
|
---|
3099 | }
|
---|
3100 | });
|
---|
3101 | if (!hasDraggingChild) {
|
---|
3102 | this._createDragElement(evt);
|
---|
3103 | }
|
---|
3104 | });
|
---|
3105 | }
|
---|
3106 | _dragChange() {
|
---|
3107 | if (this.attrs.draggable) {
|
---|
3108 | this._listenDrag();
|
---|
3109 | } else {
|
---|
3110 | this._dragCleanup();
|
---|
3111 | var stage = this.getStage();
|
---|
3112 | if (!stage) {
|
---|
3113 | return;
|
---|
3114 | }
|
---|
3115 | const dragElement = DragAndDrop_1.DD._dragElements.get(this._id);
|
---|
3116 | const isDragging = dragElement && dragElement.dragStatus === "dragging";
|
---|
3117 | const isReady = dragElement && dragElement.dragStatus === "ready";
|
---|
3118 | if (isDragging) {
|
---|
3119 | this.stopDrag();
|
---|
3120 | } else if (isReady) {
|
---|
3121 | DragAndDrop_1.DD._dragElements.delete(this._id);
|
---|
3122 | }
|
---|
3123 | }
|
---|
3124 | }
|
---|
3125 | _dragCleanup() {
|
---|
3126 | this.off("mousedown.konva");
|
---|
3127 | this.off("touchstart.konva");
|
---|
3128 | }
|
---|
3129 | isClientRectOnScreen(margin = { x: 0, y: 0 }) {
|
---|
3130 | const stage = this.getStage();
|
---|
3131 | if (!stage) {
|
---|
3132 | return false;
|
---|
3133 | }
|
---|
3134 | const screenRect = {
|
---|
3135 | x: -margin.x,
|
---|
3136 | y: -margin.y,
|
---|
3137 | width: stage.width() + 2 * margin.x,
|
---|
3138 | height: stage.height() + 2 * margin.y
|
---|
3139 | };
|
---|
3140 | return Util_1.Util.haveIntersection(screenRect, this.getClientRect());
|
---|
3141 | }
|
---|
3142 | static create(data, container) {
|
---|
3143 | if (Util_1.Util._isString(data)) {
|
---|
3144 | data = JSON.parse(data);
|
---|
3145 | }
|
---|
3146 | return this._createNode(data, container);
|
---|
3147 | }
|
---|
3148 | static _createNode(obj, container) {
|
---|
3149 | var className = _Node.prototype.getClassName.call(obj), children = obj.children, no, len, n;
|
---|
3150 | if (container) {
|
---|
3151 | obj.attrs.container = container;
|
---|
3152 | }
|
---|
3153 | if (!Global_1.Konva[className]) {
|
---|
3154 | Util_1.Util.warn('Can not find a node with class name "' + className + '". Fallback to "Shape".');
|
---|
3155 | className = "Shape";
|
---|
3156 | }
|
---|
3157 | const Class = Global_1.Konva[className];
|
---|
3158 | no = new Class(obj.attrs);
|
---|
3159 | if (children) {
|
---|
3160 | len = children.length;
|
---|
3161 | for (n = 0; n < len; n++) {
|
---|
3162 | no.add(_Node._createNode(children[n]));
|
---|
3163 | }
|
---|
3164 | }
|
---|
3165 | return no;
|
---|
3166 | }
|
---|
3167 | };
|
---|
3168 | exports.Node = Node;
|
---|
3169 | Node.prototype.nodeType = "Node";
|
---|
3170 | Node.prototype._attrsAffectingSize = [];
|
---|
3171 | Node.prototype.eventListeners = {};
|
---|
3172 | Node.prototype.on.call(Node.prototype, TRANSFORM_CHANGE_STR, function() {
|
---|
3173 | if (this._batchingTransformChange) {
|
---|
3174 | this._needClearTransformCache = true;
|
---|
3175 | return;
|
---|
3176 | }
|
---|
3177 | this._clearCache(TRANSFORM);
|
---|
3178 | this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
---|
3179 | });
|
---|
3180 | Node.prototype.on.call(Node.prototype, "visibleChange.konva", function() {
|
---|
3181 | this._clearSelfAndDescendantCache(VISIBLE);
|
---|
3182 | });
|
---|
3183 | Node.prototype.on.call(Node.prototype, "listeningChange.konva", function() {
|
---|
3184 | this._clearSelfAndDescendantCache(LISTENING);
|
---|
3185 | });
|
---|
3186 | Node.prototype.on.call(Node.prototype, "opacityChange.konva", function() {
|
---|
3187 | this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
---|
3188 | });
|
---|
3189 | var addGetterSetter = Factory_1.Factory.addGetterSetter;
|
---|
3190 | addGetterSetter(Node, "zIndex");
|
---|
3191 | addGetterSetter(Node, "absolutePosition");
|
---|
3192 | addGetterSetter(Node, "position");
|
---|
3193 | addGetterSetter(Node, "x", 0, (0, Validators_1.getNumberValidator)());
|
---|
3194 | addGetterSetter(Node, "y", 0, (0, Validators_1.getNumberValidator)());
|
---|
3195 | addGetterSetter(Node, "globalCompositeOperation", "source-over", (0, Validators_1.getStringValidator)());
|
---|
3196 | addGetterSetter(Node, "opacity", 1, (0, Validators_1.getNumberValidator)());
|
---|
3197 | addGetterSetter(Node, "name", "", (0, Validators_1.getStringValidator)());
|
---|
3198 | addGetterSetter(Node, "id", "", (0, Validators_1.getStringValidator)());
|
---|
3199 | addGetterSetter(Node, "rotation", 0, (0, Validators_1.getNumberValidator)());
|
---|
3200 | Factory_1.Factory.addComponentsGetterSetter(Node, "scale", ["x", "y"]);
|
---|
3201 | addGetterSetter(Node, "scaleX", 1, (0, Validators_1.getNumberValidator)());
|
---|
3202 | addGetterSetter(Node, "scaleY", 1, (0, Validators_1.getNumberValidator)());
|
---|
3203 | Factory_1.Factory.addComponentsGetterSetter(Node, "skew", ["x", "y"]);
|
---|
3204 | addGetterSetter(Node, "skewX", 0, (0, Validators_1.getNumberValidator)());
|
---|
3205 | addGetterSetter(Node, "skewY", 0, (0, Validators_1.getNumberValidator)());
|
---|
3206 | Factory_1.Factory.addComponentsGetterSetter(Node, "offset", ["x", "y"]);
|
---|
3207 | addGetterSetter(Node, "offsetX", 0, (0, Validators_1.getNumberValidator)());
|
---|
3208 | addGetterSetter(Node, "offsetY", 0, (0, Validators_1.getNumberValidator)());
|
---|
3209 | addGetterSetter(Node, "dragDistance", null, (0, Validators_1.getNumberValidator)());
|
---|
3210 | addGetterSetter(Node, "width", 0, (0, Validators_1.getNumberValidator)());
|
---|
3211 | addGetterSetter(Node, "height", 0, (0, Validators_1.getNumberValidator)());
|
---|
3212 | addGetterSetter(Node, "listening", true, (0, Validators_1.getBooleanValidator)());
|
---|
3213 | addGetterSetter(Node, "preventDefault", true, (0, Validators_1.getBooleanValidator)());
|
---|
3214 | addGetterSetter(Node, "filters", null, function(val) {
|
---|
3215 | this._filterUpToDate = false;
|
---|
3216 | return val;
|
---|
3217 | });
|
---|
3218 | addGetterSetter(Node, "visible", true, (0, Validators_1.getBooleanValidator)());
|
---|
3219 | addGetterSetter(Node, "transformsEnabled", "all", (0, Validators_1.getStringValidator)());
|
---|
3220 | addGetterSetter(Node, "size");
|
---|
3221 | addGetterSetter(Node, "dragBoundFunc");
|
---|
3222 | addGetterSetter(Node, "draggable", false, (0, Validators_1.getBooleanValidator)());
|
---|
3223 | Factory_1.Factory.backCompat(Node, {
|
---|
3224 | rotateDeg: "rotate",
|
---|
3225 | setRotationDeg: "setRotation",
|
---|
3226 | getRotationDeg: "getRotation"
|
---|
3227 | });
|
---|
3228 | }
|
---|
3229 | });
|
---|
3230 |
|
---|
3231 | // node_modules/konva/lib/PointerEvents.js
|
---|
3232 | var require_PointerEvents = __commonJS({
|
---|
3233 | "node_modules/konva/lib/PointerEvents.js"(exports) {
|
---|
3234 | "use strict";
|
---|
3235 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3236 | exports.releaseCapture = exports.setPointerCapture = exports.hasPointerCapture = exports.createEvent = exports.getCapturedShape = void 0;
|
---|
3237 | var Global_1 = require_Global();
|
---|
3238 | var Captures = /* @__PURE__ */ new Map();
|
---|
3239 | var SUPPORT_POINTER_EVENTS = Global_1.Konva._global["PointerEvent"] !== void 0;
|
---|
3240 | function getCapturedShape(pointerId) {
|
---|
3241 | return Captures.get(pointerId);
|
---|
3242 | }
|
---|
3243 | exports.getCapturedShape = getCapturedShape;
|
---|
3244 | function createEvent(evt) {
|
---|
3245 | return {
|
---|
3246 | evt,
|
---|
3247 | pointerId: evt.pointerId
|
---|
3248 | };
|
---|
3249 | }
|
---|
3250 | exports.createEvent = createEvent;
|
---|
3251 | function hasPointerCapture(pointerId, shape) {
|
---|
3252 | return Captures.get(pointerId) === shape;
|
---|
3253 | }
|
---|
3254 | exports.hasPointerCapture = hasPointerCapture;
|
---|
3255 | function setPointerCapture(pointerId, shape) {
|
---|
3256 | releaseCapture(pointerId);
|
---|
3257 | const stage = shape.getStage();
|
---|
3258 | if (!stage)
|
---|
3259 | return;
|
---|
3260 | Captures.set(pointerId, shape);
|
---|
3261 | if (SUPPORT_POINTER_EVENTS) {
|
---|
3262 | shape._fire("gotpointercapture", createEvent(new PointerEvent("gotpointercapture")));
|
---|
3263 | }
|
---|
3264 | }
|
---|
3265 | exports.setPointerCapture = setPointerCapture;
|
---|
3266 | function releaseCapture(pointerId, target) {
|
---|
3267 | const shape = Captures.get(pointerId);
|
---|
3268 | if (!shape)
|
---|
3269 | return;
|
---|
3270 | const stage = shape.getStage();
|
---|
3271 | if (stage && stage.content) {
|
---|
3272 | }
|
---|
3273 | Captures.delete(pointerId);
|
---|
3274 | if (SUPPORT_POINTER_EVENTS) {
|
---|
3275 | shape._fire("lostpointercapture", createEvent(new PointerEvent("lostpointercapture")));
|
---|
3276 | }
|
---|
3277 | }
|
---|
3278 | exports.releaseCapture = releaseCapture;
|
---|
3279 | }
|
---|
3280 | });
|
---|
3281 |
|
---|
3282 | // node_modules/konva/lib/Shape.js
|
---|
3283 | var require_Shape = __commonJS({
|
---|
3284 | "node_modules/konva/lib/Shape.js"(exports) {
|
---|
3285 | "use strict";
|
---|
3286 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3287 | exports.Shape = exports.shapes = void 0;
|
---|
3288 | var Global_1 = require_Global();
|
---|
3289 | var Util_1 = require_Util();
|
---|
3290 | var Factory_1 = require_Factory();
|
---|
3291 | var Node_1 = require_Node();
|
---|
3292 | var Validators_1 = require_Validators();
|
---|
3293 | var Global_2 = require_Global();
|
---|
3294 | var PointerEvents = require_PointerEvents();
|
---|
3295 | var HAS_SHADOW = "hasShadow";
|
---|
3296 | var SHADOW_RGBA = "shadowRGBA";
|
---|
3297 | var patternImage = "patternImage";
|
---|
3298 | var linearGradient = "linearGradient";
|
---|
3299 | var radialGradient = "radialGradient";
|
---|
3300 | var dummyContext;
|
---|
3301 | function getDummyContext() {
|
---|
3302 | if (dummyContext) {
|
---|
3303 | return dummyContext;
|
---|
3304 | }
|
---|
3305 | dummyContext = Util_1.Util.createCanvasElement().getContext("2d");
|
---|
3306 | return dummyContext;
|
---|
3307 | }
|
---|
3308 | exports.shapes = {};
|
---|
3309 | function _fillFunc(context) {
|
---|
3310 | const fillRule = this.attrs.fillRule;
|
---|
3311 | if (fillRule) {
|
---|
3312 | context.fill(fillRule);
|
---|
3313 | } else {
|
---|
3314 | context.fill();
|
---|
3315 | }
|
---|
3316 | }
|
---|
3317 | function _strokeFunc(context) {
|
---|
3318 | context.stroke();
|
---|
3319 | }
|
---|
3320 | function _fillFuncHit(context) {
|
---|
3321 | const fillRule = this.attrs.fillRule;
|
---|
3322 | if (fillRule) {
|
---|
3323 | context.fill(fillRule);
|
---|
3324 | } else {
|
---|
3325 | context.fill();
|
---|
3326 | }
|
---|
3327 | }
|
---|
3328 | function _strokeFuncHit(context) {
|
---|
3329 | context.stroke();
|
---|
3330 | }
|
---|
3331 | function _clearHasShadowCache() {
|
---|
3332 | this._clearCache(HAS_SHADOW);
|
---|
3333 | }
|
---|
3334 | function _clearGetShadowRGBACache() {
|
---|
3335 | this._clearCache(SHADOW_RGBA);
|
---|
3336 | }
|
---|
3337 | function _clearFillPatternCache() {
|
---|
3338 | this._clearCache(patternImage);
|
---|
3339 | }
|
---|
3340 | function _clearLinearGradientCache() {
|
---|
3341 | this._clearCache(linearGradient);
|
---|
3342 | }
|
---|
3343 | function _clearRadialGradientCache() {
|
---|
3344 | this._clearCache(radialGradient);
|
---|
3345 | }
|
---|
3346 | var Shape = class extends Node_1.Node {
|
---|
3347 | constructor(config) {
|
---|
3348 | super(config);
|
---|
3349 | let key;
|
---|
3350 | while (true) {
|
---|
3351 | key = Util_1.Util.getRandomColor();
|
---|
3352 | if (key && !(key in exports.shapes)) {
|
---|
3353 | break;
|
---|
3354 | }
|
---|
3355 | }
|
---|
3356 | this.colorKey = key;
|
---|
3357 | exports.shapes[key] = this;
|
---|
3358 | }
|
---|
3359 | getContext() {
|
---|
3360 | Util_1.Util.warn("shape.getContext() method is deprecated. Please do not use it.");
|
---|
3361 | return this.getLayer().getContext();
|
---|
3362 | }
|
---|
3363 | getCanvas() {
|
---|
3364 | Util_1.Util.warn("shape.getCanvas() method is deprecated. Please do not use it.");
|
---|
3365 | return this.getLayer().getCanvas();
|
---|
3366 | }
|
---|
3367 | getSceneFunc() {
|
---|
3368 | return this.attrs.sceneFunc || this["_sceneFunc"];
|
---|
3369 | }
|
---|
3370 | getHitFunc() {
|
---|
3371 | return this.attrs.hitFunc || this["_hitFunc"];
|
---|
3372 | }
|
---|
3373 | hasShadow() {
|
---|
3374 | return this._getCache(HAS_SHADOW, this._hasShadow);
|
---|
3375 | }
|
---|
3376 | _hasShadow() {
|
---|
3377 | return this.shadowEnabled() && this.shadowOpacity() !== 0 && !!(this.shadowColor() || this.shadowBlur() || this.shadowOffsetX() || this.shadowOffsetY());
|
---|
3378 | }
|
---|
3379 | _getFillPattern() {
|
---|
3380 | return this._getCache(patternImage, this.__getFillPattern);
|
---|
3381 | }
|
---|
3382 | __getFillPattern() {
|
---|
3383 | if (this.fillPatternImage()) {
|
---|
3384 | var ctx = getDummyContext();
|
---|
3385 | const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || "repeat");
|
---|
3386 | if (pattern && pattern.setTransform) {
|
---|
3387 | const tr = new Util_1.Transform();
|
---|
3388 | tr.translate(this.fillPatternX(), this.fillPatternY());
|
---|
3389 | tr.rotate(Global_1.Konva.getAngle(this.fillPatternRotation()));
|
---|
3390 | tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
|
---|
3391 | tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
|
---|
3392 | const m = tr.getMatrix();
|
---|
3393 | const matrix = typeof DOMMatrix === "undefined" ? {
|
---|
3394 | a: m[0],
|
---|
3395 | b: m[1],
|
---|
3396 | c: m[2],
|
---|
3397 | d: m[3],
|
---|
3398 | e: m[4],
|
---|
3399 | f: m[5]
|
---|
3400 | } : new DOMMatrix(m);
|
---|
3401 | pattern.setTransform(matrix);
|
---|
3402 | }
|
---|
3403 | return pattern;
|
---|
3404 | }
|
---|
3405 | }
|
---|
3406 | _getLinearGradient() {
|
---|
3407 | return this._getCache(linearGradient, this.__getLinearGradient);
|
---|
3408 | }
|
---|
3409 | __getLinearGradient() {
|
---|
3410 | var colorStops = this.fillLinearGradientColorStops();
|
---|
3411 | if (colorStops) {
|
---|
3412 | var ctx = getDummyContext();
|
---|
3413 | var start = this.fillLinearGradientStartPoint();
|
---|
3414 | var end = this.fillLinearGradientEndPoint();
|
---|
3415 | var grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
|
---|
3416 | for (var n = 0; n < colorStops.length; n += 2) {
|
---|
3417 | grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
---|
3418 | }
|
---|
3419 | return grd;
|
---|
3420 | }
|
---|
3421 | }
|
---|
3422 | _getRadialGradient() {
|
---|
3423 | return this._getCache(radialGradient, this.__getRadialGradient);
|
---|
3424 | }
|
---|
3425 | __getRadialGradient() {
|
---|
3426 | var colorStops = this.fillRadialGradientColorStops();
|
---|
3427 | if (colorStops) {
|
---|
3428 | var ctx = getDummyContext();
|
---|
3429 | var start = this.fillRadialGradientStartPoint();
|
---|
3430 | var end = this.fillRadialGradientEndPoint();
|
---|
3431 | var grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
|
---|
3432 | for (var n = 0; n < colorStops.length; n += 2) {
|
---|
3433 | grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
---|
3434 | }
|
---|
3435 | return grd;
|
---|
3436 | }
|
---|
3437 | }
|
---|
3438 | getShadowRGBA() {
|
---|
3439 | return this._getCache(SHADOW_RGBA, this._getShadowRGBA);
|
---|
3440 | }
|
---|
3441 | _getShadowRGBA() {
|
---|
3442 | if (!this.hasShadow()) {
|
---|
3443 | return;
|
---|
3444 | }
|
---|
3445 | var rgba = Util_1.Util.colorToRGBA(this.shadowColor());
|
---|
3446 | if (rgba) {
|
---|
3447 | return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a * (this.shadowOpacity() || 1) + ")";
|
---|
3448 | }
|
---|
3449 | }
|
---|
3450 | hasFill() {
|
---|
3451 | return this._calculate("hasFill", [
|
---|
3452 | "fillEnabled",
|
---|
3453 | "fill",
|
---|
3454 | "fillPatternImage",
|
---|
3455 | "fillLinearGradientColorStops",
|
---|
3456 | "fillRadialGradientColorStops"
|
---|
3457 | ], () => {
|
---|
3458 | return this.fillEnabled() && !!(this.fill() || this.fillPatternImage() || this.fillLinearGradientColorStops() || this.fillRadialGradientColorStops());
|
---|
3459 | });
|
---|
3460 | }
|
---|
3461 | hasStroke() {
|
---|
3462 | return this._calculate("hasStroke", [
|
---|
3463 | "strokeEnabled",
|
---|
3464 | "strokeWidth",
|
---|
3465 | "stroke",
|
---|
3466 | "strokeLinearGradientColorStops"
|
---|
3467 | ], () => {
|
---|
3468 | return this.strokeEnabled() && this.strokeWidth() && !!(this.stroke() || this.strokeLinearGradientColorStops());
|
---|
3469 | });
|
---|
3470 | }
|
---|
3471 | hasHitStroke() {
|
---|
3472 | const width = this.hitStrokeWidth();
|
---|
3473 | if (width === "auto") {
|
---|
3474 | return this.hasStroke();
|
---|
3475 | }
|
---|
3476 | return this.strokeEnabled() && !!width;
|
---|
3477 | }
|
---|
3478 | intersects(point) {
|
---|
3479 | var stage = this.getStage();
|
---|
3480 | if (!stage) {
|
---|
3481 | return false;
|
---|
3482 | }
|
---|
3483 | const bufferHitCanvas = stage.bufferHitCanvas;
|
---|
3484 | bufferHitCanvas.getContext().clear();
|
---|
3485 | this.drawHit(bufferHitCanvas, void 0, true);
|
---|
3486 | const p = bufferHitCanvas.context.getImageData(Math.round(point.x), Math.round(point.y), 1, 1).data;
|
---|
3487 | return p[3] > 0;
|
---|
3488 | }
|
---|
3489 | destroy() {
|
---|
3490 | Node_1.Node.prototype.destroy.call(this);
|
---|
3491 | delete exports.shapes[this.colorKey];
|
---|
3492 | delete this.colorKey;
|
---|
3493 | return this;
|
---|
3494 | }
|
---|
3495 | _useBufferCanvas(forceFill) {
|
---|
3496 | var _a;
|
---|
3497 | const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true;
|
---|
3498 | if (!perfectDrawEnabled) {
|
---|
3499 | return false;
|
---|
3500 | }
|
---|
3501 | const hasFill = forceFill || this.hasFill();
|
---|
3502 | const hasStroke = this.hasStroke();
|
---|
3503 | const isTransparent = this.getAbsoluteOpacity() !== 1;
|
---|
3504 | if (hasFill && hasStroke && isTransparent) {
|
---|
3505 | return true;
|
---|
3506 | }
|
---|
3507 | const hasShadow = this.hasShadow();
|
---|
3508 | const strokeForShadow = this.shadowForStrokeEnabled();
|
---|
3509 | if (hasFill && hasStroke && hasShadow && strokeForShadow) {
|
---|
3510 | return true;
|
---|
3511 | }
|
---|
3512 | return false;
|
---|
3513 | }
|
---|
3514 | setStrokeHitEnabled(val) {
|
---|
3515 | Util_1.Util.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead.");
|
---|
3516 | if (val) {
|
---|
3517 | this.hitStrokeWidth("auto");
|
---|
3518 | } else {
|
---|
3519 | this.hitStrokeWidth(0);
|
---|
3520 | }
|
---|
3521 | }
|
---|
3522 | getStrokeHitEnabled() {
|
---|
3523 | if (this.hitStrokeWidth() === 0) {
|
---|
3524 | return false;
|
---|
3525 | } else {
|
---|
3526 | return true;
|
---|
3527 | }
|
---|
3528 | }
|
---|
3529 | getSelfRect() {
|
---|
3530 | var size = this.size();
|
---|
3531 | return {
|
---|
3532 | x: this._centroid ? -size.width / 2 : 0,
|
---|
3533 | y: this._centroid ? -size.height / 2 : 0,
|
---|
3534 | width: size.width,
|
---|
3535 | height: size.height
|
---|
3536 | };
|
---|
3537 | }
|
---|
3538 | getClientRect(config = {}) {
|
---|
3539 | let hasCachedParent = false;
|
---|
3540 | let parent = this.getParent();
|
---|
3541 | while (parent) {
|
---|
3542 | if (parent.isCached()) {
|
---|
3543 | hasCachedParent = true;
|
---|
3544 | break;
|
---|
3545 | }
|
---|
3546 | parent = parent.getParent();
|
---|
3547 | }
|
---|
3548 | const skipTransform = config.skipTransform;
|
---|
3549 | const relativeTo = config.relativeTo || hasCachedParent && this.getStage() || void 0;
|
---|
3550 | const fillRect = this.getSelfRect();
|
---|
3551 | const applyStroke = !config.skipStroke && this.hasStroke();
|
---|
3552 | const strokeWidth = applyStroke && this.strokeWidth() || 0;
|
---|
3553 | const fillAndStrokeWidth = fillRect.width + strokeWidth;
|
---|
3554 | const fillAndStrokeHeight = fillRect.height + strokeWidth;
|
---|
3555 | const applyShadow = !config.skipShadow && this.hasShadow();
|
---|
3556 | const shadowOffsetX = applyShadow ? this.shadowOffsetX() : 0;
|
---|
3557 | const shadowOffsetY = applyShadow ? this.shadowOffsetY() : 0;
|
---|
3558 | const preWidth = fillAndStrokeWidth + Math.abs(shadowOffsetX);
|
---|
3559 | const preHeight = fillAndStrokeHeight + Math.abs(shadowOffsetY);
|
---|
3560 | const blurRadius = applyShadow && this.shadowBlur() || 0;
|
---|
3561 | const width = preWidth + blurRadius * 2;
|
---|
3562 | const height = preHeight + blurRadius * 2;
|
---|
3563 | const rect = {
|
---|
3564 | width,
|
---|
3565 | height,
|
---|
3566 | x: -(strokeWidth / 2 + blurRadius) + Math.min(shadowOffsetX, 0) + fillRect.x,
|
---|
3567 | y: -(strokeWidth / 2 + blurRadius) + Math.min(shadowOffsetY, 0) + fillRect.y
|
---|
3568 | };
|
---|
3569 | if (!skipTransform) {
|
---|
3570 | return this._transformedRect(rect, relativeTo);
|
---|
3571 | }
|
---|
3572 | return rect;
|
---|
3573 | }
|
---|
3574 | drawScene(can, top, bufferCanvas) {
|
---|
3575 | var layer = this.getLayer();
|
---|
3576 | var canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
|
---|
3577 | var skipBuffer = canvas.isCache;
|
---|
3578 | var cachingSelf = top === this;
|
---|
3579 | if (!this.isVisible() && !cachingSelf) {
|
---|
3580 | return this;
|
---|
3581 | }
|
---|
3582 | if (cachedCanvas) {
|
---|
3583 | context.save();
|
---|
3584 | var m = this.getAbsoluteTransform(top).getMatrix();
|
---|
3585 | context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
---|
3586 | this._drawCachedSceneCanvas(context);
|
---|
3587 | context.restore();
|
---|
3588 | return this;
|
---|
3589 | }
|
---|
3590 | if (!drawFunc) {
|
---|
3591 | return this;
|
---|
3592 | }
|
---|
3593 | context.save();
|
---|
3594 | if (this._useBufferCanvas() && !skipBuffer) {
|
---|
3595 | stage = this.getStage();
|
---|
3596 | const bc = bufferCanvas || stage.bufferCanvas;
|
---|
3597 | bufferContext = bc.getContext();
|
---|
3598 | bufferContext.clear();
|
---|
3599 | bufferContext.save();
|
---|
3600 | bufferContext._applyLineJoin(this);
|
---|
3601 | var o = this.getAbsoluteTransform(top).getMatrix();
|
---|
3602 | bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
---|
3603 | drawFunc.call(this, bufferContext, this);
|
---|
3604 | bufferContext.restore();
|
---|
3605 | var ratio = bc.pixelRatio;
|
---|
3606 | if (hasShadow) {
|
---|
3607 | context._applyShadow(this);
|
---|
3608 | }
|
---|
3609 | context._applyOpacity(this);
|
---|
3610 | context._applyGlobalCompositeOperation(this);
|
---|
3611 | context.drawImage(bc._canvas, 0, 0, bc.width / ratio, bc.height / ratio);
|
---|
3612 | } else {
|
---|
3613 | context._applyLineJoin(this);
|
---|
3614 | if (!cachingSelf) {
|
---|
3615 | var o = this.getAbsoluteTransform(top).getMatrix();
|
---|
3616 | context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
---|
3617 | context._applyOpacity(this);
|
---|
3618 | context._applyGlobalCompositeOperation(this);
|
---|
3619 | }
|
---|
3620 | if (hasShadow) {
|
---|
3621 | context._applyShadow(this);
|
---|
3622 | }
|
---|
3623 | drawFunc.call(this, context, this);
|
---|
3624 | }
|
---|
3625 | context.restore();
|
---|
3626 | return this;
|
---|
3627 | }
|
---|
3628 | drawHit(can, top, skipDragCheck = false) {
|
---|
3629 | if (!this.shouldDrawHit(top, skipDragCheck)) {
|
---|
3630 | return this;
|
---|
3631 | }
|
---|
3632 | var layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
---|
3633 | if (!this.colorKey) {
|
---|
3634 | Util_1.Util.warn("Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()");
|
---|
3635 | }
|
---|
3636 | if (cachedHitCanvas) {
|
---|
3637 | context.save();
|
---|
3638 | var m = this.getAbsoluteTransform(top).getMatrix();
|
---|
3639 | context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
---|
3640 | this._drawCachedHitCanvas(context);
|
---|
3641 | context.restore();
|
---|
3642 | return this;
|
---|
3643 | }
|
---|
3644 | if (!drawFunc) {
|
---|
3645 | return this;
|
---|
3646 | }
|
---|
3647 | context.save();
|
---|
3648 | context._applyLineJoin(this);
|
---|
3649 | const selfCache = this === top;
|
---|
3650 | if (!selfCache) {
|
---|
3651 | var o = this.getAbsoluteTransform(top).getMatrix();
|
---|
3652 | context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
---|
3653 | }
|
---|
3654 | drawFunc.call(this, context, this);
|
---|
3655 | context.restore();
|
---|
3656 | return this;
|
---|
3657 | }
|
---|
3658 | drawHitFromCache(alphaThreshold = 0) {
|
---|
3659 | var cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha;
|
---|
3660 | hitContext.clear();
|
---|
3661 | hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight);
|
---|
3662 | try {
|
---|
3663 | hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
|
---|
3664 | hitData = hitImageData.data;
|
---|
3665 | len = hitData.length;
|
---|
3666 | rgbColorKey = Util_1.Util._hexToRgb(this.colorKey);
|
---|
3667 | for (i = 0; i < len; i += 4) {
|
---|
3668 | alpha = hitData[i + 3];
|
---|
3669 | if (alpha > alphaThreshold) {
|
---|
3670 | hitData[i] = rgbColorKey.r;
|
---|
3671 | hitData[i + 1] = rgbColorKey.g;
|
---|
3672 | hitData[i + 2] = rgbColorKey.b;
|
---|
3673 | hitData[i + 3] = 255;
|
---|
3674 | } else {
|
---|
3675 | hitData[i + 3] = 0;
|
---|
3676 | }
|
---|
3677 | }
|
---|
3678 | hitContext.putImageData(hitImageData, 0, 0);
|
---|
3679 | } catch (e) {
|
---|
3680 | Util_1.Util.error("Unable to draw hit graph from cached scene canvas. " + e.message);
|
---|
3681 | }
|
---|
3682 | return this;
|
---|
3683 | }
|
---|
3684 | hasPointerCapture(pointerId) {
|
---|
3685 | return PointerEvents.hasPointerCapture(pointerId, this);
|
---|
3686 | }
|
---|
3687 | setPointerCapture(pointerId) {
|
---|
3688 | PointerEvents.setPointerCapture(pointerId, this);
|
---|
3689 | }
|
---|
3690 | releaseCapture(pointerId) {
|
---|
3691 | PointerEvents.releaseCapture(pointerId, this);
|
---|
3692 | }
|
---|
3693 | };
|
---|
3694 | exports.Shape = Shape;
|
---|
3695 | Shape.prototype._fillFunc = _fillFunc;
|
---|
3696 | Shape.prototype._strokeFunc = _strokeFunc;
|
---|
3697 | Shape.prototype._fillFuncHit = _fillFuncHit;
|
---|
3698 | Shape.prototype._strokeFuncHit = _strokeFuncHit;
|
---|
3699 | Shape.prototype._centroid = false;
|
---|
3700 | Shape.prototype.nodeType = "Shape";
|
---|
3701 | (0, Global_2._registerNode)(Shape);
|
---|
3702 | Shape.prototype.eventListeners = {};
|
---|
3703 | Shape.prototype.on.call(Shape.prototype, "shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva", _clearHasShadowCache);
|
---|
3704 | Shape.prototype.on.call(Shape.prototype, "shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva", _clearGetShadowRGBACache);
|
---|
3705 | Shape.prototype.on.call(Shape.prototype, "fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva", _clearFillPatternCache);
|
---|
3706 | Shape.prototype.on.call(Shape.prototype, "fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva", _clearLinearGradientCache);
|
---|
3707 | Shape.prototype.on.call(Shape.prototype, "fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva", _clearRadialGradientCache);
|
---|
3708 | Factory_1.Factory.addGetterSetter(Shape, "stroke", void 0, (0, Validators_1.getStringOrGradientValidator)());
|
---|
3709 | Factory_1.Factory.addGetterSetter(Shape, "strokeWidth", 2, (0, Validators_1.getNumberValidator)());
|
---|
3710 | Factory_1.Factory.addGetterSetter(Shape, "fillAfterStrokeEnabled", false);
|
---|
3711 | Factory_1.Factory.addGetterSetter(Shape, "hitStrokeWidth", "auto", (0, Validators_1.getNumberOrAutoValidator)());
|
---|
3712 | Factory_1.Factory.addGetterSetter(Shape, "strokeHitEnabled", true, (0, Validators_1.getBooleanValidator)());
|
---|
3713 | Factory_1.Factory.addGetterSetter(Shape, "perfectDrawEnabled", true, (0, Validators_1.getBooleanValidator)());
|
---|
3714 | Factory_1.Factory.addGetterSetter(Shape, "shadowForStrokeEnabled", true, (0, Validators_1.getBooleanValidator)());
|
---|
3715 | Factory_1.Factory.addGetterSetter(Shape, "lineJoin");
|
---|
3716 | Factory_1.Factory.addGetterSetter(Shape, "lineCap");
|
---|
3717 | Factory_1.Factory.addGetterSetter(Shape, "sceneFunc");
|
---|
3718 | Factory_1.Factory.addGetterSetter(Shape, "hitFunc");
|
---|
3719 | Factory_1.Factory.addGetterSetter(Shape, "dash");
|
---|
3720 | Factory_1.Factory.addGetterSetter(Shape, "dashOffset", 0, (0, Validators_1.getNumberValidator)());
|
---|
3721 | Factory_1.Factory.addGetterSetter(Shape, "shadowColor", void 0, (0, Validators_1.getStringValidator)());
|
---|
3722 | Factory_1.Factory.addGetterSetter(Shape, "shadowBlur", 0, (0, Validators_1.getNumberValidator)());
|
---|
3723 | Factory_1.Factory.addGetterSetter(Shape, "shadowOpacity", 1, (0, Validators_1.getNumberValidator)());
|
---|
3724 | Factory_1.Factory.addComponentsGetterSetter(Shape, "shadowOffset", ["x", "y"]);
|
---|
3725 | Factory_1.Factory.addGetterSetter(Shape, "shadowOffsetX", 0, (0, Validators_1.getNumberValidator)());
|
---|
3726 | Factory_1.Factory.addGetterSetter(Shape, "shadowOffsetY", 0, (0, Validators_1.getNumberValidator)());
|
---|
3727 | Factory_1.Factory.addGetterSetter(Shape, "fillPatternImage");
|
---|
3728 | Factory_1.Factory.addGetterSetter(Shape, "fill", void 0, (0, Validators_1.getStringOrGradientValidator)());
|
---|
3729 | Factory_1.Factory.addGetterSetter(Shape, "fillPatternX", 0, (0, Validators_1.getNumberValidator)());
|
---|
3730 | Factory_1.Factory.addGetterSetter(Shape, "fillPatternY", 0, (0, Validators_1.getNumberValidator)());
|
---|
3731 | Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientColorStops");
|
---|
3732 | Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientColorStops");
|
---|
3733 | Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientStartRadius", 0);
|
---|
3734 | Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientEndRadius", 0);
|
---|
3735 | Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientColorStops");
|
---|
3736 | Factory_1.Factory.addGetterSetter(Shape, "fillPatternRepeat", "repeat");
|
---|
3737 | Factory_1.Factory.addGetterSetter(Shape, "fillEnabled", true);
|
---|
3738 | Factory_1.Factory.addGetterSetter(Shape, "strokeEnabled", true);
|
---|
3739 | Factory_1.Factory.addGetterSetter(Shape, "shadowEnabled", true);
|
---|
3740 | Factory_1.Factory.addGetterSetter(Shape, "dashEnabled", true);
|
---|
3741 | Factory_1.Factory.addGetterSetter(Shape, "strokeScaleEnabled", true);
|
---|
3742 | Factory_1.Factory.addGetterSetter(Shape, "fillPriority", "color");
|
---|
3743 | Factory_1.Factory.addComponentsGetterSetter(Shape, "fillPatternOffset", ["x", "y"]);
|
---|
3744 | Factory_1.Factory.addGetterSetter(Shape, "fillPatternOffsetX", 0, (0, Validators_1.getNumberValidator)());
|
---|
3745 | Factory_1.Factory.addGetterSetter(Shape, "fillPatternOffsetY", 0, (0, Validators_1.getNumberValidator)());
|
---|
3746 | Factory_1.Factory.addComponentsGetterSetter(Shape, "fillPatternScale", ["x", "y"]);
|
---|
3747 | Factory_1.Factory.addGetterSetter(Shape, "fillPatternScaleX", 1, (0, Validators_1.getNumberValidator)());
|
---|
3748 | Factory_1.Factory.addGetterSetter(Shape, "fillPatternScaleY", 1, (0, Validators_1.getNumberValidator)());
|
---|
3749 | Factory_1.Factory.addComponentsGetterSetter(Shape, "fillLinearGradientStartPoint", [
|
---|
3750 | "x",
|
---|
3751 | "y"
|
---|
3752 | ]);
|
---|
3753 | Factory_1.Factory.addComponentsGetterSetter(Shape, "strokeLinearGradientStartPoint", [
|
---|
3754 | "x",
|
---|
3755 | "y"
|
---|
3756 | ]);
|
---|
3757 | Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientStartPointX", 0);
|
---|
3758 | Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientStartPointX", 0);
|
---|
3759 | Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientStartPointY", 0);
|
---|
3760 | Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientStartPointY", 0);
|
---|
3761 | Factory_1.Factory.addComponentsGetterSetter(Shape, "fillLinearGradientEndPoint", [
|
---|
3762 | "x",
|
---|
3763 | "y"
|
---|
3764 | ]);
|
---|
3765 | Factory_1.Factory.addComponentsGetterSetter(Shape, "strokeLinearGradientEndPoint", [
|
---|
3766 | "x",
|
---|
3767 | "y"
|
---|
3768 | ]);
|
---|
3769 | Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientEndPointX", 0);
|
---|
3770 | Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientEndPointX", 0);
|
---|
3771 | Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientEndPointY", 0);
|
---|
3772 | Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientEndPointY", 0);
|
---|
3773 | Factory_1.Factory.addComponentsGetterSetter(Shape, "fillRadialGradientStartPoint", [
|
---|
3774 | "x",
|
---|
3775 | "y"
|
---|
3776 | ]);
|
---|
3777 | Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientStartPointX", 0);
|
---|
3778 | Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientStartPointY", 0);
|
---|
3779 | Factory_1.Factory.addComponentsGetterSetter(Shape, "fillRadialGradientEndPoint", [
|
---|
3780 | "x",
|
---|
3781 | "y"
|
---|
3782 | ]);
|
---|
3783 | Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientEndPointX", 0);
|
---|
3784 | Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientEndPointY", 0);
|
---|
3785 | Factory_1.Factory.addGetterSetter(Shape, "fillPatternRotation", 0);
|
---|
3786 | Factory_1.Factory.addGetterSetter(Shape, "fillRule", void 0, (0, Validators_1.getStringValidator)());
|
---|
3787 | Factory_1.Factory.backCompat(Shape, {
|
---|
3788 | dashArray: "dash",
|
---|
3789 | getDashArray: "getDash",
|
---|
3790 | setDashArray: "getDash",
|
---|
3791 | drawFunc: "sceneFunc",
|
---|
3792 | getDrawFunc: "getSceneFunc",
|
---|
3793 | setDrawFunc: "setSceneFunc",
|
---|
3794 | drawHitFunc: "hitFunc",
|
---|
3795 | getDrawHitFunc: "getHitFunc",
|
---|
3796 | setDrawHitFunc: "setHitFunc"
|
---|
3797 | });
|
---|
3798 | }
|
---|
3799 | });
|
---|
3800 |
|
---|
3801 | export {
|
---|
3802 | require_Util,
|
---|
3803 | require_Validators,
|
---|
3804 | require_Factory,
|
---|
3805 | require_Context,
|
---|
3806 | require_Canvas,
|
---|
3807 | require_DragAndDrop,
|
---|
3808 | require_Node,
|
---|
3809 | require_PointerEvents,
|
---|
3810 | require_Shape
|
---|
3811 | };
|
---|
3812 | //# sourceMappingURL=chunk-HC2KSO22.js.map
|
---|