1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | exports.Util = exports.Transform = void 0;
|
---|
4 | const Global_1 = require("./Global");
|
---|
5 | class Transform {
|
---|
6 | constructor(m = [1, 0, 0, 1, 0, 0]) {
|
---|
7 | this.dirty = false;
|
---|
8 | this.m = (m && m.slice()) || [1, 0, 0, 1, 0, 0];
|
---|
9 | }
|
---|
10 | reset() {
|
---|
11 | this.m[0] = 1;
|
---|
12 | this.m[1] = 0;
|
---|
13 | this.m[2] = 0;
|
---|
14 | this.m[3] = 1;
|
---|
15 | this.m[4] = 0;
|
---|
16 | this.m[5] = 0;
|
---|
17 | }
|
---|
18 | copy() {
|
---|
19 | return new Transform(this.m);
|
---|
20 | }
|
---|
21 | copyInto(tr) {
|
---|
22 | tr.m[0] = this.m[0];
|
---|
23 | tr.m[1] = this.m[1];
|
---|
24 | tr.m[2] = this.m[2];
|
---|
25 | tr.m[3] = this.m[3];
|
---|
26 | tr.m[4] = this.m[4];
|
---|
27 | tr.m[5] = this.m[5];
|
---|
28 | }
|
---|
29 | point(point) {
|
---|
30 | var m = this.m;
|
---|
31 | return {
|
---|
32 | x: m[0] * point.x + m[2] * point.y + m[4],
|
---|
33 | y: m[1] * point.x + m[3] * point.y + m[5],
|
---|
34 | };
|
---|
35 | }
|
---|
36 | translate(x, y) {
|
---|
37 | this.m[4] += this.m[0] * x + this.m[2] * y;
|
---|
38 | this.m[5] += this.m[1] * x + this.m[3] * y;
|
---|
39 | return this;
|
---|
40 | }
|
---|
41 | scale(sx, sy) {
|
---|
42 | this.m[0] *= sx;
|
---|
43 | this.m[1] *= sx;
|
---|
44 | this.m[2] *= sy;
|
---|
45 | this.m[3] *= sy;
|
---|
46 | return this;
|
---|
47 | }
|
---|
48 | rotate(rad) {
|
---|
49 | var c = Math.cos(rad);
|
---|
50 | var s = Math.sin(rad);
|
---|
51 | var m11 = this.m[0] * c + this.m[2] * s;
|
---|
52 | var m12 = this.m[1] * c + this.m[3] * s;
|
---|
53 | var m21 = this.m[0] * -s + this.m[2] * c;
|
---|
54 | var m22 = this.m[1] * -s + this.m[3] * c;
|
---|
55 | this.m[0] = m11;
|
---|
56 | this.m[1] = m12;
|
---|
57 | this.m[2] = m21;
|
---|
58 | this.m[3] = m22;
|
---|
59 | return this;
|
---|
60 | }
|
---|
61 | getTranslation() {
|
---|
62 | return {
|
---|
63 | x: this.m[4],
|
---|
64 | y: this.m[5],
|
---|
65 | };
|
---|
66 | }
|
---|
67 | skew(sx, sy) {
|
---|
68 | var m11 = this.m[0] + this.m[2] * sy;
|
---|
69 | var m12 = this.m[1] + this.m[3] * sy;
|
---|
70 | var m21 = this.m[2] + this.m[0] * sx;
|
---|
71 | var m22 = this.m[3] + this.m[1] * sx;
|
---|
72 | this.m[0] = m11;
|
---|
73 | this.m[1] = m12;
|
---|
74 | this.m[2] = m21;
|
---|
75 | this.m[3] = m22;
|
---|
76 | return this;
|
---|
77 | }
|
---|
78 | multiply(matrix) {
|
---|
79 | var m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];
|
---|
80 | var m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];
|
---|
81 | var m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];
|
---|
82 | var m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];
|
---|
83 | var dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];
|
---|
84 | var dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];
|
---|
85 | this.m[0] = m11;
|
---|
86 | this.m[1] = m12;
|
---|
87 | this.m[2] = m21;
|
---|
88 | this.m[3] = m22;
|
---|
89 | this.m[4] = dx;
|
---|
90 | this.m[5] = dy;
|
---|
91 | return this;
|
---|
92 | }
|
---|
93 | invert() {
|
---|
94 | var d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);
|
---|
95 | var m0 = this.m[3] * d;
|
---|
96 | var m1 = -this.m[1] * d;
|
---|
97 | var m2 = -this.m[2] * d;
|
---|
98 | var m3 = this.m[0] * d;
|
---|
99 | var m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);
|
---|
100 | var m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
|
---|
101 | this.m[0] = m0;
|
---|
102 | this.m[1] = m1;
|
---|
103 | this.m[2] = m2;
|
---|
104 | this.m[3] = m3;
|
---|
105 | this.m[4] = m4;
|
---|
106 | this.m[5] = m5;
|
---|
107 | return this;
|
---|
108 | }
|
---|
109 | getMatrix() {
|
---|
110 | return this.m;
|
---|
111 | }
|
---|
112 | decompose() {
|
---|
113 | var a = this.m[0];
|
---|
114 | var b = this.m[1];
|
---|
115 | var c = this.m[2];
|
---|
116 | var d = this.m[3];
|
---|
117 | var e = this.m[4];
|
---|
118 | var f = this.m[5];
|
---|
119 | var delta = a * d - b * c;
|
---|
120 | let result = {
|
---|
121 | x: e,
|
---|
122 | y: f,
|
---|
123 | rotation: 0,
|
---|
124 | scaleX: 0,
|
---|
125 | scaleY: 0,
|
---|
126 | skewX: 0,
|
---|
127 | skewY: 0,
|
---|
128 | };
|
---|
129 | if (a != 0 || b != 0) {
|
---|
130 | var r = Math.sqrt(a * a + b * b);
|
---|
131 | result.rotation = b > 0 ? Math.acos(a / r) : -Math.acos(a / r);
|
---|
132 | result.scaleX = r;
|
---|
133 | result.scaleY = delta / r;
|
---|
134 | result.skewX = (a * c + b * d) / delta;
|
---|
135 | result.skewY = 0;
|
---|
136 | }
|
---|
137 | else if (c != 0 || d != 0) {
|
---|
138 | var s = Math.sqrt(c * c + d * d);
|
---|
139 | result.rotation =
|
---|
140 | Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
|
---|
141 | result.scaleX = delta / s;
|
---|
142 | result.scaleY = s;
|
---|
143 | result.skewX = 0;
|
---|
144 | result.skewY = (a * c + b * d) / delta;
|
---|
145 | }
|
---|
146 | else {
|
---|
147 | }
|
---|
148 | result.rotation = exports.Util._getRotation(result.rotation);
|
---|
149 | return result;
|
---|
150 | }
|
---|
151 | }
|
---|
152 | exports.Transform = Transform;
|
---|
153 | var OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH = '#', EMPTY_STRING = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = {
|
---|
154 | aliceblue: [240, 248, 255],
|
---|
155 | antiquewhite: [250, 235, 215],
|
---|
156 | aqua: [0, 255, 255],
|
---|
157 | aquamarine: [127, 255, 212],
|
---|
158 | azure: [240, 255, 255],
|
---|
159 | beige: [245, 245, 220],
|
---|
160 | bisque: [255, 228, 196],
|
---|
161 | black: [0, 0, 0],
|
---|
162 | blanchedalmond: [255, 235, 205],
|
---|
163 | blue: [0, 0, 255],
|
---|
164 | blueviolet: [138, 43, 226],
|
---|
165 | brown: [165, 42, 42],
|
---|
166 | burlywood: [222, 184, 135],
|
---|
167 | cadetblue: [95, 158, 160],
|
---|
168 | chartreuse: [127, 255, 0],
|
---|
169 | chocolate: [210, 105, 30],
|
---|
170 | coral: [255, 127, 80],
|
---|
171 | cornflowerblue: [100, 149, 237],
|
---|
172 | cornsilk: [255, 248, 220],
|
---|
173 | crimson: [220, 20, 60],
|
---|
174 | cyan: [0, 255, 255],
|
---|
175 | darkblue: [0, 0, 139],
|
---|
176 | darkcyan: [0, 139, 139],
|
---|
177 | darkgoldenrod: [184, 132, 11],
|
---|
178 | darkgray: [169, 169, 169],
|
---|
179 | darkgreen: [0, 100, 0],
|
---|
180 | darkgrey: [169, 169, 169],
|
---|
181 | darkkhaki: [189, 183, 107],
|
---|
182 | darkmagenta: [139, 0, 139],
|
---|
183 | darkolivegreen: [85, 107, 47],
|
---|
184 | darkorange: [255, 140, 0],
|
---|
185 | darkorchid: [153, 50, 204],
|
---|
186 | darkred: [139, 0, 0],
|
---|
187 | darksalmon: [233, 150, 122],
|
---|
188 | darkseagreen: [143, 188, 143],
|
---|
189 | darkslateblue: [72, 61, 139],
|
---|
190 | darkslategray: [47, 79, 79],
|
---|
191 | darkslategrey: [47, 79, 79],
|
---|
192 | darkturquoise: [0, 206, 209],
|
---|
193 | darkviolet: [148, 0, 211],
|
---|
194 | deeppink: [255, 20, 147],
|
---|
195 | deepskyblue: [0, 191, 255],
|
---|
196 | dimgray: [105, 105, 105],
|
---|
197 | dimgrey: [105, 105, 105],
|
---|
198 | dodgerblue: [30, 144, 255],
|
---|
199 | firebrick: [178, 34, 34],
|
---|
200 | floralwhite: [255, 255, 240],
|
---|
201 | forestgreen: [34, 139, 34],
|
---|
202 | fuchsia: [255, 0, 255],
|
---|
203 | gainsboro: [220, 220, 220],
|
---|
204 | ghostwhite: [248, 248, 255],
|
---|
205 | gold: [255, 215, 0],
|
---|
206 | goldenrod: [218, 165, 32],
|
---|
207 | gray: [128, 128, 128],
|
---|
208 | green: [0, 128, 0],
|
---|
209 | greenyellow: [173, 255, 47],
|
---|
210 | grey: [128, 128, 128],
|
---|
211 | honeydew: [240, 255, 240],
|
---|
212 | hotpink: [255, 105, 180],
|
---|
213 | indianred: [205, 92, 92],
|
---|
214 | indigo: [75, 0, 130],
|
---|
215 | ivory: [255, 255, 240],
|
---|
216 | khaki: [240, 230, 140],
|
---|
217 | lavender: [230, 230, 250],
|
---|
218 | lavenderblush: [255, 240, 245],
|
---|
219 | lawngreen: [124, 252, 0],
|
---|
220 | lemonchiffon: [255, 250, 205],
|
---|
221 | lightblue: [173, 216, 230],
|
---|
222 | lightcoral: [240, 128, 128],
|
---|
223 | lightcyan: [224, 255, 255],
|
---|
224 | lightgoldenrodyellow: [250, 250, 210],
|
---|
225 | lightgray: [211, 211, 211],
|
---|
226 | lightgreen: [144, 238, 144],
|
---|
227 | lightgrey: [211, 211, 211],
|
---|
228 | lightpink: [255, 182, 193],
|
---|
229 | lightsalmon: [255, 160, 122],
|
---|
230 | lightseagreen: [32, 178, 170],
|
---|
231 | lightskyblue: [135, 206, 250],
|
---|
232 | lightslategray: [119, 136, 153],
|
---|
233 | lightslategrey: [119, 136, 153],
|
---|
234 | lightsteelblue: [176, 196, 222],
|
---|
235 | lightyellow: [255, 255, 224],
|
---|
236 | lime: [0, 255, 0],
|
---|
237 | limegreen: [50, 205, 50],
|
---|
238 | linen: [250, 240, 230],
|
---|
239 | magenta: [255, 0, 255],
|
---|
240 | maroon: [128, 0, 0],
|
---|
241 | mediumaquamarine: [102, 205, 170],
|
---|
242 | mediumblue: [0, 0, 205],
|
---|
243 | mediumorchid: [186, 85, 211],
|
---|
244 | mediumpurple: [147, 112, 219],
|
---|
245 | mediumseagreen: [60, 179, 113],
|
---|
246 | mediumslateblue: [123, 104, 238],
|
---|
247 | mediumspringgreen: [0, 250, 154],
|
---|
248 | mediumturquoise: [72, 209, 204],
|
---|
249 | mediumvioletred: [199, 21, 133],
|
---|
250 | midnightblue: [25, 25, 112],
|
---|
251 | mintcream: [245, 255, 250],
|
---|
252 | mistyrose: [255, 228, 225],
|
---|
253 | moccasin: [255, 228, 181],
|
---|
254 | navajowhite: [255, 222, 173],
|
---|
255 | navy: [0, 0, 128],
|
---|
256 | oldlace: [253, 245, 230],
|
---|
257 | olive: [128, 128, 0],
|
---|
258 | olivedrab: [107, 142, 35],
|
---|
259 | orange: [255, 165, 0],
|
---|
260 | orangered: [255, 69, 0],
|
---|
261 | orchid: [218, 112, 214],
|
---|
262 | palegoldenrod: [238, 232, 170],
|
---|
263 | palegreen: [152, 251, 152],
|
---|
264 | paleturquoise: [175, 238, 238],
|
---|
265 | palevioletred: [219, 112, 147],
|
---|
266 | papayawhip: [255, 239, 213],
|
---|
267 | peachpuff: [255, 218, 185],
|
---|
268 | peru: [205, 133, 63],
|
---|
269 | pink: [255, 192, 203],
|
---|
270 | plum: [221, 160, 203],
|
---|
271 | powderblue: [176, 224, 230],
|
---|
272 | purple: [128, 0, 128],
|
---|
273 | rebeccapurple: [102, 51, 153],
|
---|
274 | red: [255, 0, 0],
|
---|
275 | rosybrown: [188, 143, 143],
|
---|
276 | royalblue: [65, 105, 225],
|
---|
277 | saddlebrown: [139, 69, 19],
|
---|
278 | salmon: [250, 128, 114],
|
---|
279 | sandybrown: [244, 164, 96],
|
---|
280 | seagreen: [46, 139, 87],
|
---|
281 | seashell: [255, 245, 238],
|
---|
282 | sienna: [160, 82, 45],
|
---|
283 | silver: [192, 192, 192],
|
---|
284 | skyblue: [135, 206, 235],
|
---|
285 | slateblue: [106, 90, 205],
|
---|
286 | slategray: [119, 128, 144],
|
---|
287 | slategrey: [119, 128, 144],
|
---|
288 | snow: [255, 255, 250],
|
---|
289 | springgreen: [0, 255, 127],
|
---|
290 | steelblue: [70, 130, 180],
|
---|
291 | tan: [210, 180, 140],
|
---|
292 | teal: [0, 128, 128],
|
---|
293 | thistle: [216, 191, 216],
|
---|
294 | transparent: [255, 255, 255, 0],
|
---|
295 | tomato: [255, 99, 71],
|
---|
296 | turquoise: [64, 224, 208],
|
---|
297 | violet: [238, 130, 238],
|
---|
298 | wheat: [245, 222, 179],
|
---|
299 | white: [255, 255, 255],
|
---|
300 | whitesmoke: [245, 245, 245],
|
---|
301 | yellow: [255, 255, 0],
|
---|
302 | yellowgreen: [154, 205, 5],
|
---|
303 | }, RGB_REGEX = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/, animQueue = [];
|
---|
304 | const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
|
---|
305 | function (f) {
|
---|
306 | setTimeout(f, 60);
|
---|
307 | };
|
---|
308 | exports.Util = {
|
---|
309 | _isElement(obj) {
|
---|
310 | return !!(obj && obj.nodeType == 1);
|
---|
311 | },
|
---|
312 | _isFunction(obj) {
|
---|
313 | return !!(obj && obj.constructor && obj.call && obj.apply);
|
---|
314 | },
|
---|
315 | _isPlainObject(obj) {
|
---|
316 | return !!obj && obj.constructor === Object;
|
---|
317 | },
|
---|
318 | _isArray(obj) {
|
---|
319 | return Object.prototype.toString.call(obj) === OBJECT_ARRAY;
|
---|
320 | },
|
---|
321 | _isNumber(obj) {
|
---|
322 | return (Object.prototype.toString.call(obj) === OBJECT_NUMBER &&
|
---|
323 | !isNaN(obj) &&
|
---|
324 | isFinite(obj));
|
---|
325 | },
|
---|
326 | _isString(obj) {
|
---|
327 | return Object.prototype.toString.call(obj) === OBJECT_STRING;
|
---|
328 | },
|
---|
329 | _isBoolean(obj) {
|
---|
330 | return Object.prototype.toString.call(obj) === OBJECT_BOOLEAN;
|
---|
331 | },
|
---|
332 | isObject(val) {
|
---|
333 | return val instanceof Object;
|
---|
334 | },
|
---|
335 | isValidSelector(selector) {
|
---|
336 | if (typeof selector !== 'string') {
|
---|
337 | return false;
|
---|
338 | }
|
---|
339 | var firstChar = selector[0];
|
---|
340 | return (firstChar === '#' ||
|
---|
341 | firstChar === '.' ||
|
---|
342 | firstChar === firstChar.toUpperCase());
|
---|
343 | },
|
---|
344 | _sign(number) {
|
---|
345 | if (number === 0) {
|
---|
346 | return 1;
|
---|
347 | }
|
---|
348 | if (number > 0) {
|
---|
349 | return 1;
|
---|
350 | }
|
---|
351 | else {
|
---|
352 | return -1;
|
---|
353 | }
|
---|
354 | },
|
---|
355 | requestAnimFrame(callback) {
|
---|
356 | animQueue.push(callback);
|
---|
357 | if (animQueue.length === 1) {
|
---|
358 | req(function () {
|
---|
359 | const queue = animQueue;
|
---|
360 | animQueue = [];
|
---|
361 | queue.forEach(function (cb) {
|
---|
362 | cb();
|
---|
363 | });
|
---|
364 | });
|
---|
365 | }
|
---|
366 | },
|
---|
367 | createCanvasElement() {
|
---|
368 | var canvas = document.createElement('canvas');
|
---|
369 | try {
|
---|
370 | canvas.style = canvas.style || {};
|
---|
371 | }
|
---|
372 | catch (e) { }
|
---|
373 | return canvas;
|
---|
374 | },
|
---|
375 | createImageElement() {
|
---|
376 | return document.createElement('img');
|
---|
377 | },
|
---|
378 | _isInDocument(el) {
|
---|
379 | while ((el = el.parentNode)) {
|
---|
380 | if (el == document) {
|
---|
381 | return true;
|
---|
382 | }
|
---|
383 | }
|
---|
384 | return false;
|
---|
385 | },
|
---|
386 | _urlToImage(url, callback) {
|
---|
387 | var imageObj = exports.Util.createImageElement();
|
---|
388 | imageObj.onload = function () {
|
---|
389 | callback(imageObj);
|
---|
390 | };
|
---|
391 | imageObj.src = url;
|
---|
392 | },
|
---|
393 | _rgbToHex(r, g, b) {
|
---|
394 | return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
---|
395 | },
|
---|
396 | _hexToRgb(hex) {
|
---|
397 | hex = hex.replace(HASH, EMPTY_STRING);
|
---|
398 | var bigint = parseInt(hex, 16);
|
---|
399 | return {
|
---|
400 | r: (bigint >> 16) & 255,
|
---|
401 | g: (bigint >> 8) & 255,
|
---|
402 | b: bigint & 255,
|
---|
403 | };
|
---|
404 | },
|
---|
405 | getRandomColor() {
|
---|
406 | var randColor = ((Math.random() * 0xffffff) << 0).toString(16);
|
---|
407 | while (randColor.length < 6) {
|
---|
408 | randColor = ZERO + randColor;
|
---|
409 | }
|
---|
410 | return HASH + randColor;
|
---|
411 | },
|
---|
412 | getRGB(color) {
|
---|
413 | var rgb;
|
---|
414 | if (color in COLORS) {
|
---|
415 | rgb = COLORS[color];
|
---|
416 | return {
|
---|
417 | r: rgb[0],
|
---|
418 | g: rgb[1],
|
---|
419 | b: rgb[2],
|
---|
420 | };
|
---|
421 | }
|
---|
422 | else if (color[0] === HASH) {
|
---|
423 | return this._hexToRgb(color.substring(1));
|
---|
424 | }
|
---|
425 | else if (color.substr(0, 4) === RGB_PAREN) {
|
---|
426 | rgb = RGB_REGEX.exec(color.replace(/ /g, ''));
|
---|
427 | return {
|
---|
428 | r: parseInt(rgb[1], 10),
|
---|
429 | g: parseInt(rgb[2], 10),
|
---|
430 | b: parseInt(rgb[3], 10),
|
---|
431 | };
|
---|
432 | }
|
---|
433 | else {
|
---|
434 | return {
|
---|
435 | r: 0,
|
---|
436 | g: 0,
|
---|
437 | b: 0,
|
---|
438 | };
|
---|
439 | }
|
---|
440 | },
|
---|
441 | colorToRGBA(str) {
|
---|
442 | str = str || 'black';
|
---|
443 | return (exports.Util._namedColorToRBA(str) ||
|
---|
444 | exports.Util._hex3ColorToRGBA(str) ||
|
---|
445 | exports.Util._hex4ColorToRGBA(str) ||
|
---|
446 | exports.Util._hex6ColorToRGBA(str) ||
|
---|
447 | exports.Util._hex8ColorToRGBA(str) ||
|
---|
448 | exports.Util._rgbColorToRGBA(str) ||
|
---|
449 | exports.Util._rgbaColorToRGBA(str) ||
|
---|
450 | exports.Util._hslColorToRGBA(str));
|
---|
451 | },
|
---|
452 | _namedColorToRBA(str) {
|
---|
453 | var c = COLORS[str.toLowerCase()];
|
---|
454 | if (!c) {
|
---|
455 | return null;
|
---|
456 | }
|
---|
457 | return {
|
---|
458 | r: c[0],
|
---|
459 | g: c[1],
|
---|
460 | b: c[2],
|
---|
461 | a: 1,
|
---|
462 | };
|
---|
463 | },
|
---|
464 | _rgbColorToRGBA(str) {
|
---|
465 | if (str.indexOf('rgb(') === 0) {
|
---|
466 | str = str.match(/rgb\(([^)]+)\)/)[1];
|
---|
467 | var parts = str.split(/ *, */).map(Number);
|
---|
468 | return {
|
---|
469 | r: parts[0],
|
---|
470 | g: parts[1],
|
---|
471 | b: parts[2],
|
---|
472 | a: 1,
|
---|
473 | };
|
---|
474 | }
|
---|
475 | },
|
---|
476 | _rgbaColorToRGBA(str) {
|
---|
477 | if (str.indexOf('rgba(') === 0) {
|
---|
478 | str = str.match(/rgba\(([^)]+)\)/)[1];
|
---|
479 | var parts = str.split(/ *, */).map((n, index) => {
|
---|
480 | if (n.slice(-1) === '%') {
|
---|
481 | return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
---|
482 | }
|
---|
483 | return Number(n);
|
---|
484 | });
|
---|
485 | return {
|
---|
486 | r: parts[0],
|
---|
487 | g: parts[1],
|
---|
488 | b: parts[2],
|
---|
489 | a: parts[3],
|
---|
490 | };
|
---|
491 | }
|
---|
492 | },
|
---|
493 | _hex8ColorToRGBA(str) {
|
---|
494 | if (str[0] === '#' && str.length === 9) {
|
---|
495 | return {
|
---|
496 | r: parseInt(str.slice(1, 3), 16),
|
---|
497 | g: parseInt(str.slice(3, 5), 16),
|
---|
498 | b: parseInt(str.slice(5, 7), 16),
|
---|
499 | a: parseInt(str.slice(7, 9), 16) / 0xff,
|
---|
500 | };
|
---|
501 | }
|
---|
502 | },
|
---|
503 | _hex6ColorToRGBA(str) {
|
---|
504 | if (str[0] === '#' && str.length === 7) {
|
---|
505 | return {
|
---|
506 | r: parseInt(str.slice(1, 3), 16),
|
---|
507 | g: parseInt(str.slice(3, 5), 16),
|
---|
508 | b: parseInt(str.slice(5, 7), 16),
|
---|
509 | a: 1,
|
---|
510 | };
|
---|
511 | }
|
---|
512 | },
|
---|
513 | _hex4ColorToRGBA(str) {
|
---|
514 | if (str[0] === '#' && str.length === 5) {
|
---|
515 | return {
|
---|
516 | r: parseInt(str[1] + str[1], 16),
|
---|
517 | g: parseInt(str[2] + str[2], 16),
|
---|
518 | b: parseInt(str[3] + str[3], 16),
|
---|
519 | a: parseInt(str[4] + str[4], 16) / 0xff,
|
---|
520 | };
|
---|
521 | }
|
---|
522 | },
|
---|
523 | _hex3ColorToRGBA(str) {
|
---|
524 | if (str[0] === '#' && str.length === 4) {
|
---|
525 | return {
|
---|
526 | r: parseInt(str[1] + str[1], 16),
|
---|
527 | g: parseInt(str[2] + str[2], 16),
|
---|
528 | b: parseInt(str[3] + str[3], 16),
|
---|
529 | a: 1,
|
---|
530 | };
|
---|
531 | }
|
---|
532 | },
|
---|
533 | _hslColorToRGBA(str) {
|
---|
534 | if (/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(str)) {
|
---|
535 | const [_, ...hsl] = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(str);
|
---|
536 | const h = Number(hsl[0]) / 360;
|
---|
537 | const s = Number(hsl[1]) / 100;
|
---|
538 | const l = Number(hsl[2]) / 100;
|
---|
539 | let t2;
|
---|
540 | let t3;
|
---|
541 | let val;
|
---|
542 | if (s === 0) {
|
---|
543 | val = l * 255;
|
---|
544 | return {
|
---|
545 | r: Math.round(val),
|
---|
546 | g: Math.round(val),
|
---|
547 | b: Math.round(val),
|
---|
548 | a: 1,
|
---|
549 | };
|
---|
550 | }
|
---|
551 | if (l < 0.5) {
|
---|
552 | t2 = l * (1 + s);
|
---|
553 | }
|
---|
554 | else {
|
---|
555 | t2 = l + s - l * s;
|
---|
556 | }
|
---|
557 | const t1 = 2 * l - t2;
|
---|
558 | const rgb = [0, 0, 0];
|
---|
559 | for (let i = 0; i < 3; i++) {
|
---|
560 | t3 = h + (1 / 3) * -(i - 1);
|
---|
561 | if (t3 < 0) {
|
---|
562 | t3++;
|
---|
563 | }
|
---|
564 | if (t3 > 1) {
|
---|
565 | t3--;
|
---|
566 | }
|
---|
567 | if (6 * t3 < 1) {
|
---|
568 | val = t1 + (t2 - t1) * 6 * t3;
|
---|
569 | }
|
---|
570 | else if (2 * t3 < 1) {
|
---|
571 | val = t2;
|
---|
572 | }
|
---|
573 | else if (3 * t3 < 2) {
|
---|
574 | val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
---|
575 | }
|
---|
576 | else {
|
---|
577 | val = t1;
|
---|
578 | }
|
---|
579 | rgb[i] = val * 255;
|
---|
580 | }
|
---|
581 | return {
|
---|
582 | r: Math.round(rgb[0]),
|
---|
583 | g: Math.round(rgb[1]),
|
---|
584 | b: Math.round(rgb[2]),
|
---|
585 | a: 1,
|
---|
586 | };
|
---|
587 | }
|
---|
588 | },
|
---|
589 | haveIntersection(r1, r2) {
|
---|
590 | return !(r2.x > r1.x + r1.width ||
|
---|
591 | r2.x + r2.width < r1.x ||
|
---|
592 | r2.y > r1.y + r1.height ||
|
---|
593 | r2.y + r2.height < r1.y);
|
---|
594 | },
|
---|
595 | cloneObject(obj) {
|
---|
596 | var retObj = {};
|
---|
597 | for (var key in obj) {
|
---|
598 | if (this._isPlainObject(obj[key])) {
|
---|
599 | retObj[key] = this.cloneObject(obj[key]);
|
---|
600 | }
|
---|
601 | else if (this._isArray(obj[key])) {
|
---|
602 | retObj[key] = this.cloneArray(obj[key]);
|
---|
603 | }
|
---|
604 | else {
|
---|
605 | retObj[key] = obj[key];
|
---|
606 | }
|
---|
607 | }
|
---|
608 | return retObj;
|
---|
609 | },
|
---|
610 | cloneArray(arr) {
|
---|
611 | return arr.slice(0);
|
---|
612 | },
|
---|
613 | degToRad(deg) {
|
---|
614 | return deg * PI_OVER_DEG180;
|
---|
615 | },
|
---|
616 | radToDeg(rad) {
|
---|
617 | return rad * DEG180_OVER_PI;
|
---|
618 | },
|
---|
619 | _degToRad(deg) {
|
---|
620 | exports.Util.warn('Util._degToRad is removed. Please use public Util.degToRad instead.');
|
---|
621 | return exports.Util.degToRad(deg);
|
---|
622 | },
|
---|
623 | _radToDeg(rad) {
|
---|
624 | exports.Util.warn('Util._radToDeg is removed. Please use public Util.radToDeg instead.');
|
---|
625 | return exports.Util.radToDeg(rad);
|
---|
626 | },
|
---|
627 | _getRotation(radians) {
|
---|
628 | return Global_1.Konva.angleDeg ? exports.Util.radToDeg(radians) : radians;
|
---|
629 | },
|
---|
630 | _capitalize(str) {
|
---|
631 | return str.charAt(0).toUpperCase() + str.slice(1);
|
---|
632 | },
|
---|
633 | throw(str) {
|
---|
634 | throw new Error(KONVA_ERROR + str);
|
---|
635 | },
|
---|
636 | error(str) {
|
---|
637 | console.error(KONVA_ERROR + str);
|
---|
638 | },
|
---|
639 | warn(str) {
|
---|
640 | if (!Global_1.Konva.showWarnings) {
|
---|
641 | return;
|
---|
642 | }
|
---|
643 | console.warn(KONVA_WARNING + str);
|
---|
644 | },
|
---|
645 | each(obj, func) {
|
---|
646 | for (var key in obj) {
|
---|
647 | func(key, obj[key]);
|
---|
648 | }
|
---|
649 | },
|
---|
650 | _inRange(val, left, right) {
|
---|
651 | return left <= val && val < right;
|
---|
652 | },
|
---|
653 | _getProjectionToSegment(x1, y1, x2, y2, x3, y3) {
|
---|
654 | var x, y, dist;
|
---|
655 | var pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
|
---|
656 | if (pd2 == 0) {
|
---|
657 | x = x1;
|
---|
658 | y = y1;
|
---|
659 | dist = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
|
---|
660 | }
|
---|
661 | else {
|
---|
662 | var u = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2;
|
---|
663 | if (u < 0) {
|
---|
664 | x = x1;
|
---|
665 | y = y1;
|
---|
666 | dist = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
|
---|
667 | }
|
---|
668 | else if (u > 1.0) {
|
---|
669 | x = x2;
|
---|
670 | y = y2;
|
---|
671 | dist = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
|
---|
672 | }
|
---|
673 | else {
|
---|
674 | x = x1 + u * (x2 - x1);
|
---|
675 | y = y1 + u * (y2 - y1);
|
---|
676 | dist = (x - x3) * (x - x3) + (y - y3) * (y - y3);
|
---|
677 | }
|
---|
678 | }
|
---|
679 | return [x, y, dist];
|
---|
680 | },
|
---|
681 | _getProjectionToLine(pt, line, isClosed) {
|
---|
682 | var pc = exports.Util.cloneObject(pt);
|
---|
683 | var dist = Number.MAX_VALUE;
|
---|
684 | line.forEach(function (p1, i) {
|
---|
685 | if (!isClosed && i === line.length - 1) {
|
---|
686 | return;
|
---|
687 | }
|
---|
688 | var p2 = line[(i + 1) % line.length];
|
---|
689 | var proj = exports.Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y);
|
---|
690 | var px = proj[0], py = proj[1], pdist = proj[2];
|
---|
691 | if (pdist < dist) {
|
---|
692 | pc.x = px;
|
---|
693 | pc.y = py;
|
---|
694 | dist = pdist;
|
---|
695 | }
|
---|
696 | });
|
---|
697 | return pc;
|
---|
698 | },
|
---|
699 | _prepareArrayForTween(startArray, endArray, isClosed) {
|
---|
700 | var n, start = [], end = [];
|
---|
701 | if (startArray.length > endArray.length) {
|
---|
702 | var temp = endArray;
|
---|
703 | endArray = startArray;
|
---|
704 | startArray = temp;
|
---|
705 | }
|
---|
706 | for (n = 0; n < startArray.length; n += 2) {
|
---|
707 | start.push({
|
---|
708 | x: startArray[n],
|
---|
709 | y: startArray[n + 1],
|
---|
710 | });
|
---|
711 | }
|
---|
712 | for (n = 0; n < endArray.length; n += 2) {
|
---|
713 | end.push({
|
---|
714 | x: endArray[n],
|
---|
715 | y: endArray[n + 1],
|
---|
716 | });
|
---|
717 | }
|
---|
718 | var newStart = [];
|
---|
719 | end.forEach(function (point) {
|
---|
720 | var pr = exports.Util._getProjectionToLine(point, start, isClosed);
|
---|
721 | newStart.push(pr.x);
|
---|
722 | newStart.push(pr.y);
|
---|
723 | });
|
---|
724 | return newStart;
|
---|
725 | },
|
---|
726 | _prepareToStringify(obj) {
|
---|
727 | var desc;
|
---|
728 | obj.visitedByCircularReferenceRemoval = true;
|
---|
729 | for (var key in obj) {
|
---|
730 | if (!(obj.hasOwnProperty(key) && obj[key] && typeof obj[key] == 'object')) {
|
---|
731 | continue;
|
---|
732 | }
|
---|
733 | desc = Object.getOwnPropertyDescriptor(obj, key);
|
---|
734 | if (obj[key].visitedByCircularReferenceRemoval ||
|
---|
735 | exports.Util._isElement(obj[key])) {
|
---|
736 | if (desc.configurable) {
|
---|
737 | delete obj[key];
|
---|
738 | }
|
---|
739 | else {
|
---|
740 | return null;
|
---|
741 | }
|
---|
742 | }
|
---|
743 | else if (exports.Util._prepareToStringify(obj[key]) === null) {
|
---|
744 | if (desc.configurable) {
|
---|
745 | delete obj[key];
|
---|
746 | }
|
---|
747 | else {
|
---|
748 | return null;
|
---|
749 | }
|
---|
750 | }
|
---|
751 | }
|
---|
752 | delete obj.visitedByCircularReferenceRemoval;
|
---|
753 | return obj;
|
---|
754 | },
|
---|
755 | _assign(target, source) {
|
---|
756 | for (var key in source) {
|
---|
757 | target[key] = source[key];
|
---|
758 | }
|
---|
759 | return target;
|
---|
760 | },
|
---|
761 | _getFirstPointerId(evt) {
|
---|
762 | if (!evt.touches) {
|
---|
763 | return evt.pointerId || 999;
|
---|
764 | }
|
---|
765 | else {
|
---|
766 | return evt.changedTouches[0].identifier;
|
---|
767 | }
|
---|
768 | },
|
---|
769 | releaseCanvas(...canvases) {
|
---|
770 | if (!Global_1.Konva.releaseCanvasOnDestroy)
|
---|
771 | return;
|
---|
772 | canvases.forEach((c) => {
|
---|
773 | c.width = 0;
|
---|
774 | c.height = 0;
|
---|
775 | });
|
---|
776 | },
|
---|
777 | drawRoundedRectPath(context, width, height, cornerRadius) {
|
---|
778 | let topLeft = 0;
|
---|
779 | let topRight = 0;
|
---|
780 | let bottomLeft = 0;
|
---|
781 | let bottomRight = 0;
|
---|
782 | if (typeof cornerRadius === 'number') {
|
---|
783 | topLeft =
|
---|
784 | topRight =
|
---|
785 | bottomLeft =
|
---|
786 | bottomRight =
|
---|
787 | Math.min(cornerRadius, width / 2, height / 2);
|
---|
788 | }
|
---|
789 | else {
|
---|
790 | topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
---|
791 | topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
---|
792 | bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
---|
793 | bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
---|
794 | }
|
---|
795 | context.moveTo(topLeft, 0);
|
---|
796 | context.lineTo(width - topRight, 0);
|
---|
797 | context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
---|
798 | context.lineTo(width, height - bottomRight);
|
---|
799 | context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
---|
800 | context.lineTo(bottomLeft, height);
|
---|
801 | context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
---|
802 | context.lineTo(0, topLeft);
|
---|
803 | context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
---|
804 | },
|
---|
805 | };
|
---|