Changeset 0c6b92a for imaps-frontend/node_modules/.vite/deps/konva.js
- Timestamp:
- 12/12/24 17:06:06 (5 weeks ago)
- Branches:
- main
- Parents:
- d565449
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/.vite/deps/konva.js
rd565449 r0c6b92a 1 import {2 require_Ring3 } from "./chunk-D42GQH4N.js";4 import {5 require_Rect6 } from "./chunk-6JNWGPFD.js";7 import {8 require_Canvas,9 require_Context,10 require_DragAndDrop,11 require_Factory,12 require_Node,13 require_PointerEvents,14 require_Shape,15 require_Util,16 require_Validators17 } from "./chunk-HC2KSO22.js";18 1 import { 19 2 require_Global 20 } from "./chunk- M3JPOOL7.js";3 } from "./chunk-3OE4LJUD.js"; 21 4 import { 22 5 __commonJS 23 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 const 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 const c = Math.cos(rad); 60 const s = Math.sin(rad); 61 const m11 = this.m[0] * c + this.m[2] * s; 62 const m12 = this.m[1] * c + this.m[3] * s; 63 const m21 = this.m[0] * -s + this.m[2] * c; 64 const 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 const m11 = this.m[0] + this.m[2] * sy; 79 const m12 = this.m[1] + this.m[3] * sy; 80 const m21 = this.m[2] + this.m[0] * sx; 81 const 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 const m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1]; 90 const m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1]; 91 const m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3]; 92 const m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3]; 93 const dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4]; 94 const 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 const d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]); 105 const m0 = this.m[3] * d; 106 const m1 = -this.m[1] * d; 107 const m2 = -this.m[2] * d; 108 const m3 = this.m[0] * d; 109 const m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]); 110 const 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 const a = this.m[0]; 124 const b = this.m[1]; 125 const c = this.m[2]; 126 const d = this.m[3]; 127 const e = this.m[4]; 128 const f = this.m[5]; 129 const delta = a * d - b * c; 130 const 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 const 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 const 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 const 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 const 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 const 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 const 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 let 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 let 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 const 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 const 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 const 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 const retObj = {}; 595 for (const 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 (const 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 let x, y, dist; 651 const 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 const 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 const pc = exports.Util.cloneObject(pt); 676 let dist = Number.MAX_VALUE; 677 line.forEach(function(p1, i) { 678 if (!isClosed && i === line.length - 1) { 679 return; 680 } 681 const p2 = line[(i + 1) % line.length]; 682 const proj = exports.Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y); 683 const 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 let n, start = [], end = []; 694 if (startArray.length > endArray.length) { 695 const 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 const newStart = []; 712 end.forEach(function(point) { 713 const 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 let desc; 721 obj.visitedByCircularReferenceRemoval = true; 722 for (const 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 (const 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.RGBComponent = RGBComponent; 798 exports.alphaComponent = alphaComponent; 799 exports.getNumberValidator = getNumberValidator; 800 exports.getNumberOrArrayOfNumbersValidator = getNumberOrArrayOfNumbersValidator; 801 exports.getNumberOrAutoValidator = getNumberOrAutoValidator; 802 exports.getStringValidator = getStringValidator; 803 exports.getStringOrGradientValidator = getStringOrGradientValidator; 804 exports.getFunctionValidator = getFunctionValidator; 805 exports.getNumberArrayValidator = getNumberArrayValidator; 806 exports.getBooleanValidator = getBooleanValidator; 807 exports.getComponentValidator = getComponentValidator; 808 var Global_1 = require_Global(); 809 var Util_1 = require_Util(); 810 function _formatValue(val) { 811 if (Util_1.Util._isString(val)) { 812 return '"' + val + '"'; 813 } 814 if (Object.prototype.toString.call(val) === "[object Number]") { 815 return val; 816 } 817 if (Util_1.Util._isBoolean(val)) { 818 return val; 819 } 820 return Object.prototype.toString.call(val); 821 } 822 function RGBComponent(val) { 823 if (val > 255) { 824 return 255; 825 } else if (val < 0) { 826 return 0; 827 } 828 return Math.round(val); 829 } 830 function alphaComponent(val) { 831 if (val > 1) { 832 return 1; 833 } else if (val < 1e-4) { 834 return 1e-4; 835 } 836 return val; 837 } 838 function getNumberValidator() { 839 if (Global_1.Konva.isUnminified) { 840 return function(val, attr) { 841 if (!Util_1.Util._isNumber(val)) { 842 Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a number.'); 843 } 844 return val; 845 }; 846 } 847 } 848 function getNumberOrArrayOfNumbersValidator(noOfElements) { 849 if (Global_1.Konva.isUnminified) { 850 return function(val, attr) { 851 const isNumber = Util_1.Util._isNumber(val); 852 const isValidArray = Util_1.Util._isArray(val) && val.length == noOfElements; 853 if (!isNumber && !isValidArray) { 854 Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a number or Array<number>(' + noOfElements + ")"); 855 } 856 return val; 857 }; 858 } 859 } 860 function getNumberOrAutoValidator() { 861 if (Global_1.Konva.isUnminified) { 862 return function(val, attr) { 863 const isNumber = Util_1.Util._isNumber(val); 864 const isAuto = val === "auto"; 865 if (!(isNumber || isAuto)) { 866 Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a number or "auto".'); 867 } 868 return val; 869 }; 870 } 871 } 872 function getStringValidator() { 873 if (Global_1.Konva.isUnminified) { 874 return function(val, attr) { 875 if (!Util_1.Util._isString(val)) { 876 Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a string.'); 877 } 878 return val; 879 }; 880 } 881 } 882 function getStringOrGradientValidator() { 883 if (Global_1.Konva.isUnminified) { 884 return function(val, attr) { 885 const isString = Util_1.Util._isString(val); 886 const isGradient = Object.prototype.toString.call(val) === "[object CanvasGradient]" || val && val.addColorStop; 887 if (!(isString || isGradient)) { 888 Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a string or a native gradient.'); 889 } 890 return val; 891 }; 892 } 893 } 894 function getFunctionValidator() { 895 if (Global_1.Konva.isUnminified) { 896 return function(val, attr) { 897 if (!Util_1.Util._isFunction(val)) { 898 Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a function.'); 899 } 900 return val; 901 }; 902 } 903 } 904 function getNumberArrayValidator() { 905 if (Global_1.Konva.isUnminified) { 906 return function(val, attr) { 907 const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null; 908 if (TypedArray && val instanceof TypedArray) { 909 return val; 910 } 911 if (!Util_1.Util._isArray(val)) { 912 Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a array of numbers.'); 913 } else { 914 val.forEach(function(item) { 915 if (!Util_1.Util._isNumber(item)) { 916 Util_1.Util.warn('"' + attr + '" attribute has non numeric element ' + item + ". Make sure that all elements are numbers."); 917 } 918 }); 919 } 920 return val; 921 }; 922 } 923 } 924 function getBooleanValidator() { 925 if (Global_1.Konva.isUnminified) { 926 return function(val, attr) { 927 const isBool = val === true || val === false; 928 if (!isBool) { 929 Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a boolean.'); 930 } 931 return val; 932 }; 933 } 934 } 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 } 949 }); 950 951 // node_modules/konva/lib/Factory.js 952 var require_Factory = __commonJS({ 953 "node_modules/konva/lib/Factory.js"(exports) { 954 "use strict"; 955 Object.defineProperty(exports, "__esModule", { value: true }); 956 exports.Factory = void 0; 957 var Util_1 = require_Util(); 958 var Validators_1 = require_Validators(); 959 var GET = "get"; 960 var SET = "set"; 961 exports.Factory = { 962 addGetterSetter(constructor, attr, def, validator, after) { 963 exports.Factory.addGetter(constructor, attr, def); 964 exports.Factory.addSetter(constructor, attr, validator, after); 965 exports.Factory.addOverloadedGetterSetter(constructor, attr); 966 }, 967 addGetter(constructor, attr, def) { 968 const method = GET + Util_1.Util._capitalize(attr); 969 constructor.prototype[method] = constructor.prototype[method] || function() { 970 const val = this.attrs[attr]; 971 return val === void 0 ? def : val; 972 }; 973 }, 974 addSetter(constructor, attr, validator, after) { 975 const method = SET + Util_1.Util._capitalize(attr); 976 if (!constructor.prototype[method]) { 977 exports.Factory.overWriteSetter(constructor, attr, validator, after); 978 } 979 }, 980 overWriteSetter(constructor, attr, validator, after) { 981 const method = SET + Util_1.Util._capitalize(attr); 982 constructor.prototype[method] = function(val) { 983 if (validator && val !== void 0 && val !== null) { 984 val = validator.call(this, val, attr); 985 } 986 this._setAttr(attr, val); 987 if (after) { 988 after.call(this); 989 } 990 return this; 991 }; 992 }, 993 addComponentsGetterSetter(constructor, attr, components, validator, after) { 994 let len = components.length, capitalize = Util_1.Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr), n, component; 995 constructor.prototype[getter] = function() { 996 const ret = {}; 997 for (n = 0; n < len; n++) { 998 component = components[n]; 999 ret[component] = this.getAttr(attr + capitalize(component)); 1000 } 1001 return ret; 1002 }; 1003 const basicValidator = (0, Validators_1.getComponentValidator)(components); 1004 constructor.prototype[setter] = function(val) { 1005 let oldVal = this.attrs[attr], key; 1006 if (validator) { 1007 val = validator.call(this, val); 1008 } 1009 if (basicValidator) { 1010 basicValidator.call(this, val, attr); 1011 } 1012 for (key in val) { 1013 if (!val.hasOwnProperty(key)) { 1014 continue; 1015 } 1016 this._setAttr(attr + capitalize(key), val[key]); 1017 } 1018 if (!val) { 1019 components.forEach((component2) => { 1020 this._setAttr(attr + capitalize(component2), void 0); 1021 }); 1022 } 1023 this._fireChangeEvent(attr, oldVal, val); 1024 if (after) { 1025 after.call(this); 1026 } 1027 return this; 1028 }; 1029 exports.Factory.addOverloadedGetterSetter(constructor, attr); 1030 }, 1031 addOverloadedGetterSetter(constructor, attr) { 1032 const capitalizedAttr = Util_1.Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr; 1033 constructor.prototype[attr] = function() { 1034 if (arguments.length) { 1035 this[setter](arguments[0]); 1036 return this; 1037 } 1038 return this[getter](); 1039 }; 1040 }, 1041 addDeprecatedGetterSetter(constructor, attr, def, validator) { 1042 Util_1.Util.error("Adding deprecated " + attr); 1043 const method = GET + Util_1.Util._capitalize(attr); 1044 const message = attr + " property is deprecated and will be removed soon. Look at Konva change log for more information."; 1045 constructor.prototype[method] = function() { 1046 Util_1.Util.error(message); 1047 const val = this.attrs[attr]; 1048 return val === void 0 ? def : val; 1049 }; 1050 exports.Factory.addSetter(constructor, attr, validator, function() { 1051 Util_1.Util.error(message); 1052 }); 1053 exports.Factory.addOverloadedGetterSetter(constructor, attr); 1054 }, 1055 backCompat(constructor, methods) { 1056 Util_1.Util.each(methods, function(oldMethodName, newMethodName) { 1057 const method = constructor.prototype[newMethodName]; 1058 const oldGetter = GET + Util_1.Util._capitalize(oldMethodName); 1059 const oldSetter = SET + Util_1.Util._capitalize(oldMethodName); 1060 function deprecated() { 1061 method.apply(this, arguments); 1062 Util_1.Util.error('"' + oldMethodName + '" method is deprecated and will be removed soon. Use ""' + newMethodName + '" instead.'); 1063 } 1064 constructor.prototype[oldMethodName] = deprecated; 1065 constructor.prototype[oldGetter] = deprecated; 1066 constructor.prototype[oldSetter] = deprecated; 1067 }); 1068 }, 1069 afterSetFilter() { 1070 this._filterUpToDate = false; 1071 } 1072 }; 1073 } 1074 }); 1075 1076 // node_modules/konva/lib/Context.js 1077 var require_Context = __commonJS({ 1078 "node_modules/konva/lib/Context.js"(exports) { 1079 "use strict"; 1080 Object.defineProperty(exports, "__esModule", { value: true }); 1081 exports.HitContext = exports.SceneContext = exports.Context = void 0; 1082 var Util_1 = require_Util(); 1083 var Global_1 = require_Global(); 1084 function simplifyArray(arr) { 1085 let retArr = [], len = arr.length, util = Util_1.Util, n, val; 1086 for (n = 0; n < len; n++) { 1087 val = arr[n]; 1088 if (util._isNumber(val)) { 1089 val = Math.round(val * 1e3) / 1e3; 1090 } else if (!util._isString(val)) { 1091 val = val + ""; 1092 } 1093 retArr.push(val); 1094 } 1095 return retArr; 1096 } 1097 var COMMA = ","; 1098 var OPEN_PAREN = "("; 1099 var CLOSE_PAREN = ")"; 1100 var OPEN_PAREN_BRACKET = "(["; 1101 var CLOSE_BRACKET_PAREN = "])"; 1102 var SEMICOLON = ";"; 1103 var DOUBLE_PAREN = "()"; 1104 var EQUALS = "="; 1105 var CONTEXT_METHODS = [ 1106 "arc", 1107 "arcTo", 1108 "beginPath", 1109 "bezierCurveTo", 1110 "clearRect", 1111 "clip", 1112 "closePath", 1113 "createLinearGradient", 1114 "createPattern", 1115 "createRadialGradient", 1116 "drawImage", 1117 "ellipse", 1118 "fill", 1119 "fillText", 1120 "getImageData", 1121 "createImageData", 1122 "lineTo", 1123 "moveTo", 1124 "putImageData", 1125 "quadraticCurveTo", 1126 "rect", 1127 "roundRect", 1128 "restore", 1129 "rotate", 1130 "save", 1131 "scale", 1132 "setLineDash", 1133 "setTransform", 1134 "stroke", 1135 "strokeText", 1136 "transform", 1137 "translate" 1138 ]; 1139 var CONTEXT_PROPERTIES = [ 1140 "fillStyle", 1141 "strokeStyle", 1142 "shadowColor", 1143 "shadowBlur", 1144 "shadowOffsetX", 1145 "shadowOffsetY", 1146 "letterSpacing", 1147 "lineCap", 1148 "lineDashOffset", 1149 "lineJoin", 1150 "lineWidth", 1151 "miterLimit", 1152 "direction", 1153 "font", 1154 "textAlign", 1155 "textBaseline", 1156 "globalAlpha", 1157 "globalCompositeOperation", 1158 "imageSmoothingEnabled" 1159 ]; 1160 var traceArrMax = 100; 1161 var Context = class { 1162 constructor(canvas) { 1163 this.canvas = canvas; 1164 if (Global_1.Konva.enableTrace) { 1165 this.traceArr = []; 1166 this._enableTrace(); 1167 } 1168 } 1169 fillShape(shape) { 1170 if (shape.fillEnabled()) { 1171 this._fill(shape); 1172 } 1173 } 1174 _fill(shape) { 1175 } 1176 strokeShape(shape) { 1177 if (shape.hasStroke()) { 1178 this._stroke(shape); 1179 } 1180 } 1181 _stroke(shape) { 1182 } 1183 fillStrokeShape(shape) { 1184 if (shape.attrs.fillAfterStrokeEnabled) { 1185 this.strokeShape(shape); 1186 this.fillShape(shape); 1187 } else { 1188 this.fillShape(shape); 1189 this.strokeShape(shape); 1190 } 1191 } 1192 getTrace(relaxed, rounded) { 1193 let traceArr = this.traceArr, len = traceArr.length, str = "", n, trace, method, args; 1194 for (n = 0; n < len; n++) { 1195 trace = traceArr[n]; 1196 method = trace.method; 1197 if (method) { 1198 args = trace.args; 1199 str += method; 1200 if (relaxed) { 1201 str += DOUBLE_PAREN; 1202 } else { 1203 if (Util_1.Util._isArray(args[0])) { 1204 str += OPEN_PAREN_BRACKET + args.join(COMMA) + CLOSE_BRACKET_PAREN; 1205 } else { 1206 if (rounded) { 1207 args = args.map((a) => typeof a === "number" ? Math.floor(a) : a); 1208 } 1209 str += OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN; 1210 } 1211 } 1212 } else { 1213 str += trace.property; 1214 if (!relaxed) { 1215 str += EQUALS + trace.val; 1216 } 1217 } 1218 str += SEMICOLON; 1219 } 1220 return str; 1221 } 1222 clearTrace() { 1223 this.traceArr = []; 1224 } 1225 _trace(str) { 1226 let traceArr = this.traceArr, len; 1227 traceArr.push(str); 1228 len = traceArr.length; 1229 if (len >= traceArrMax) { 1230 traceArr.shift(); 1231 } 1232 } 1233 reset() { 1234 const pixelRatio = this.getCanvas().getPixelRatio(); 1235 this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0); 1236 } 1237 getCanvas() { 1238 return this.canvas; 1239 } 1240 clear(bounds) { 1241 const canvas = this.getCanvas(); 1242 if (bounds) { 1243 this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0); 1244 } else { 1245 this.clearRect(0, 0, canvas.getWidth() / canvas.pixelRatio, canvas.getHeight() / canvas.pixelRatio); 1246 } 1247 } 1248 _applyLineCap(shape) { 1249 const lineCap = shape.attrs.lineCap; 1250 if (lineCap) { 1251 this.setAttr("lineCap", lineCap); 1252 } 1253 } 1254 _applyOpacity(shape) { 1255 const absOpacity = shape.getAbsoluteOpacity(); 1256 if (absOpacity !== 1) { 1257 this.setAttr("globalAlpha", absOpacity); 1258 } 1259 } 1260 _applyLineJoin(shape) { 1261 const lineJoin = shape.attrs.lineJoin; 1262 if (lineJoin) { 1263 this.setAttr("lineJoin", lineJoin); 1264 } 1265 } 1266 setAttr(attr, val) { 1267 this._context[attr] = val; 1268 } 1269 arc(x, y, radius, startAngle, endAngle, counterClockwise) { 1270 this._context.arc(x, y, radius, startAngle, endAngle, counterClockwise); 1271 } 1272 arcTo(x1, y1, x2, y2, radius) { 1273 this._context.arcTo(x1, y1, x2, y2, radius); 1274 } 1275 beginPath() { 1276 this._context.beginPath(); 1277 } 1278 bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) { 1279 this._context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); 1280 } 1281 clearRect(x, y, width, height) { 1282 this._context.clearRect(x, y, width, height); 1283 } 1284 clip(...args) { 1285 this._context.clip.apply(this._context, args); 1286 } 1287 closePath() { 1288 this._context.closePath(); 1289 } 1290 createImageData(width, height) { 1291 const a = arguments; 1292 if (a.length === 2) { 1293 return this._context.createImageData(width, height); 1294 } else if (a.length === 1) { 1295 return this._context.createImageData(width); 1296 } 1297 } 1298 createLinearGradient(x0, y0, x1, y1) { 1299 return this._context.createLinearGradient(x0, y0, x1, y1); 1300 } 1301 createPattern(image, repetition) { 1302 return this._context.createPattern(image, repetition); 1303 } 1304 createRadialGradient(x0, y0, r0, x1, y1, r1) { 1305 return this._context.createRadialGradient(x0, y0, r0, x1, y1, r1); 1306 } 1307 drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) { 1308 const a = arguments, _context = this._context; 1309 if (a.length === 3) { 1310 _context.drawImage(image, sx, sy); 1311 } else if (a.length === 5) { 1312 _context.drawImage(image, sx, sy, sWidth, sHeight); 1313 } else if (a.length === 9) { 1314 _context.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); 1315 } 1316 } 1317 ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) { 1318 this._context.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise); 1319 } 1320 isPointInPath(x, y, path, fillRule) { 1321 if (path) { 1322 return this._context.isPointInPath(path, x, y, fillRule); 1323 } 1324 return this._context.isPointInPath(x, y, fillRule); 1325 } 1326 fill(...args) { 1327 this._context.fill.apply(this._context, args); 1328 } 1329 fillRect(x, y, width, height) { 1330 this._context.fillRect(x, y, width, height); 1331 } 1332 strokeRect(x, y, width, height) { 1333 this._context.strokeRect(x, y, width, height); 1334 } 1335 fillText(text, x, y, maxWidth) { 1336 if (maxWidth) { 1337 this._context.fillText(text, x, y, maxWidth); 1338 } else { 1339 this._context.fillText(text, x, y); 1340 } 1341 } 1342 measureText(text) { 1343 return this._context.measureText(text); 1344 } 1345 getImageData(sx, sy, sw, sh) { 1346 return this._context.getImageData(sx, sy, sw, sh); 1347 } 1348 lineTo(x, y) { 1349 this._context.lineTo(x, y); 1350 } 1351 moveTo(x, y) { 1352 this._context.moveTo(x, y); 1353 } 1354 rect(x, y, width, height) { 1355 this._context.rect(x, y, width, height); 1356 } 1357 roundRect(x, y, width, height, radii) { 1358 this._context.roundRect(x, y, width, height, radii); 1359 } 1360 putImageData(imageData, dx, dy) { 1361 this._context.putImageData(imageData, dx, dy); 1362 } 1363 quadraticCurveTo(cpx, cpy, x, y) { 1364 this._context.quadraticCurveTo(cpx, cpy, x, y); 1365 } 1366 restore() { 1367 this._context.restore(); 1368 } 1369 rotate(angle) { 1370 this._context.rotate(angle); 1371 } 1372 save() { 1373 this._context.save(); 1374 } 1375 scale(x, y) { 1376 this._context.scale(x, y); 1377 } 1378 setLineDash(segments) { 1379 if (this._context.setLineDash) { 1380 this._context.setLineDash(segments); 1381 } else if ("mozDash" in this._context) { 1382 this._context["mozDash"] = segments; 1383 } else if ("webkitLineDash" in this._context) { 1384 this._context["webkitLineDash"] = segments; 1385 } 1386 } 1387 getLineDash() { 1388 return this._context.getLineDash(); 1389 } 1390 setTransform(a, b, c, d, e, f) { 1391 this._context.setTransform(a, b, c, d, e, f); 1392 } 1393 stroke(path2d) { 1394 if (path2d) { 1395 this._context.stroke(path2d); 1396 } else { 1397 this._context.stroke(); 1398 } 1399 } 1400 strokeText(text, x, y, maxWidth) { 1401 this._context.strokeText(text, x, y, maxWidth); 1402 } 1403 transform(a, b, c, d, e, f) { 1404 this._context.transform(a, b, c, d, e, f); 1405 } 1406 translate(x, y) { 1407 this._context.translate(x, y); 1408 } 1409 _enableTrace() { 1410 let that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args; 1411 const func = function(methodName) { 1412 let origMethod = that[methodName], ret; 1413 that[methodName] = function() { 1414 args = simplifyArray(Array.prototype.slice.call(arguments, 0)); 1415 ret = origMethod.apply(that, arguments); 1416 that._trace({ 1417 method: methodName, 1418 args 1419 }); 1420 return ret; 1421 }; 1422 }; 1423 for (n = 0; n < len; n++) { 1424 func(CONTEXT_METHODS[n]); 1425 } 1426 that.setAttr = function() { 1427 origSetter.apply(that, arguments); 1428 const prop = arguments[0]; 1429 let val = arguments[1]; 1430 if (prop === "shadowOffsetX" || prop === "shadowOffsetY" || prop === "shadowBlur") { 1431 val = val / this.canvas.getPixelRatio(); 1432 } 1433 that._trace({ 1434 property: prop, 1435 val 1436 }); 1437 }; 1438 } 1439 _applyGlobalCompositeOperation(node) { 1440 const op = node.attrs.globalCompositeOperation; 1441 const def = !op || op === "source-over"; 1442 if (!def) { 1443 this.setAttr("globalCompositeOperation", op); 1444 } 1445 } 1446 }; 1447 exports.Context = Context; 1448 CONTEXT_PROPERTIES.forEach(function(prop) { 1449 Object.defineProperty(Context.prototype, prop, { 1450 get() { 1451 return this._context[prop]; 1452 }, 1453 set(val) { 1454 this._context[prop] = val; 1455 } 1456 }); 1457 }); 1458 var SceneContext = class extends Context { 1459 constructor(canvas, { willReadFrequently = false } = {}) { 1460 super(canvas); 1461 this._context = canvas._canvas.getContext("2d", { 1462 willReadFrequently 1463 }); 1464 } 1465 _fillColor(shape) { 1466 const fill = shape.fill(); 1467 this.setAttr("fillStyle", fill); 1468 shape._fillFunc(this); 1469 } 1470 _fillPattern(shape) { 1471 this.setAttr("fillStyle", shape._getFillPattern()); 1472 shape._fillFunc(this); 1473 } 1474 _fillLinearGradient(shape) { 1475 const grd = shape._getLinearGradient(); 1476 if (grd) { 1477 this.setAttr("fillStyle", grd); 1478 shape._fillFunc(this); 1479 } 1480 } 1481 _fillRadialGradient(shape) { 1482 const grd = shape._getRadialGradient(); 1483 if (grd) { 1484 this.setAttr("fillStyle", grd); 1485 shape._fillFunc(this); 1486 } 1487 } 1488 _fill(shape) { 1489 const hasColor = shape.fill(), fillPriority = shape.getFillPriority(); 1490 if (hasColor && fillPriority === "color") { 1491 this._fillColor(shape); 1492 return; 1493 } 1494 const hasPattern = shape.getFillPatternImage(); 1495 if (hasPattern && fillPriority === "pattern") { 1496 this._fillPattern(shape); 1497 return; 1498 } 1499 const hasLinearGradient = shape.getFillLinearGradientColorStops(); 1500 if (hasLinearGradient && fillPriority === "linear-gradient") { 1501 this._fillLinearGradient(shape); 1502 return; 1503 } 1504 const hasRadialGradient = shape.getFillRadialGradientColorStops(); 1505 if (hasRadialGradient && fillPriority === "radial-gradient") { 1506 this._fillRadialGradient(shape); 1507 return; 1508 } 1509 if (hasColor) { 1510 this._fillColor(shape); 1511 } else if (hasPattern) { 1512 this._fillPattern(shape); 1513 } else if (hasLinearGradient) { 1514 this._fillLinearGradient(shape); 1515 } else if (hasRadialGradient) { 1516 this._fillRadialGradient(shape); 1517 } 1518 } 1519 _strokeLinearGradient(shape) { 1520 const start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y); 1521 if (colorStops) { 1522 for (let n = 0; n < colorStops.length; n += 2) { 1523 grd.addColorStop(colorStops[n], colorStops[n + 1]); 1524 } 1525 this.setAttr("strokeStyle", grd); 1526 } 1527 } 1528 _stroke(shape) { 1529 const dash = shape.dash(), strokeScaleEnabled = shape.getStrokeScaleEnabled(); 1530 if (shape.hasStroke()) { 1531 if (!strokeScaleEnabled) { 1532 this.save(); 1533 const pixelRatio = this.getCanvas().getPixelRatio(); 1534 this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0); 1535 } 1536 this._applyLineCap(shape); 1537 if (dash && shape.dashEnabled()) { 1538 this.setLineDash(dash); 1539 this.setAttr("lineDashOffset", shape.dashOffset()); 1540 } 1541 this.setAttr("lineWidth", shape.strokeWidth()); 1542 if (!shape.getShadowForStrokeEnabled()) { 1543 this.setAttr("shadowColor", "rgba(0,0,0,0)"); 1544 } 1545 const hasLinearGradient = shape.getStrokeLinearGradientColorStops(); 1546 if (hasLinearGradient) { 1547 this._strokeLinearGradient(shape); 1548 } else { 1549 this.setAttr("strokeStyle", shape.stroke()); 1550 } 1551 shape._strokeFunc(this); 1552 if (!strokeScaleEnabled) { 1553 this.restore(); 1554 } 1555 } 1556 } 1557 _applyShadow(shape) { 1558 var _a, _b, _c; 1559 const 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 : { 1560 x: 0, 1561 y: 0 1562 }, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio; 1563 this.setAttr("shadowColor", color); 1564 this.setAttr("shadowBlur", blur * Math.min(Math.abs(scaleX), Math.abs(scaleY))); 1565 this.setAttr("shadowOffsetX", offset.x * scaleX); 1566 this.setAttr("shadowOffsetY", offset.y * scaleY); 1567 } 1568 }; 1569 exports.SceneContext = SceneContext; 1570 var HitContext = class extends Context { 1571 constructor(canvas) { 1572 super(canvas); 1573 this._context = canvas._canvas.getContext("2d", { 1574 willReadFrequently: true 1575 }); 1576 } 1577 _fill(shape) { 1578 this.save(); 1579 this.setAttr("fillStyle", shape.colorKey); 1580 shape._fillFuncHit(this); 1581 this.restore(); 1582 } 1583 strokeShape(shape) { 1584 if (shape.hasHitStroke()) { 1585 this._stroke(shape); 1586 } 1587 } 1588 _stroke(shape) { 1589 if (shape.hasHitStroke()) { 1590 const strokeScaleEnabled = shape.getStrokeScaleEnabled(); 1591 if (!strokeScaleEnabled) { 1592 this.save(); 1593 const pixelRatio = this.getCanvas().getPixelRatio(); 1594 this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0); 1595 } 1596 this._applyLineCap(shape); 1597 const hitStrokeWidth = shape.hitStrokeWidth(); 1598 const strokeWidth = hitStrokeWidth === "auto" ? shape.strokeWidth() : hitStrokeWidth; 1599 this.setAttr("lineWidth", strokeWidth); 1600 this.setAttr("strokeStyle", shape.colorKey); 1601 shape._strokeFuncHit(this); 1602 if (!strokeScaleEnabled) { 1603 this.restore(); 1604 } 1605 } 1606 } 1607 }; 1608 exports.HitContext = HitContext; 1609 } 1610 }); 1611 1612 // node_modules/konva/lib/Canvas.js 1613 var require_Canvas = __commonJS({ 1614 "node_modules/konva/lib/Canvas.js"(exports) { 1615 "use strict"; 1616 Object.defineProperty(exports, "__esModule", { value: true }); 1617 exports.HitCanvas = exports.SceneCanvas = exports.Canvas = void 0; 1618 var Util_1 = require_Util(); 1619 var Context_1 = require_Context(); 1620 var Global_1 = require_Global(); 1621 var Factory_1 = require_Factory(); 1622 var Validators_1 = require_Validators(); 1623 var _pixelRatio; 1624 function getDevicePixelRatio() { 1625 if (_pixelRatio) { 1626 return _pixelRatio; 1627 } 1628 const canvas = Util_1.Util.createCanvasElement(); 1629 const context = canvas.getContext("2d"); 1630 _pixelRatio = function() { 1631 const devicePixelRatio = Global_1.Konva._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1; 1632 return devicePixelRatio / backingStoreRatio; 1633 }(); 1634 Util_1.Util.releaseCanvas(canvas); 1635 return _pixelRatio; 1636 } 1637 var Canvas = class { 1638 constructor(config) { 1639 this.pixelRatio = 1; 1640 this.width = 0; 1641 this.height = 0; 1642 this.isCache = false; 1643 const conf = config || {}; 1644 const pixelRatio = conf.pixelRatio || Global_1.Konva.pixelRatio || getDevicePixelRatio(); 1645 this.pixelRatio = pixelRatio; 1646 this._canvas = Util_1.Util.createCanvasElement(); 1647 this._canvas.style.padding = "0"; 1648 this._canvas.style.margin = "0"; 1649 this._canvas.style.border = "0"; 1650 this._canvas.style.background = "transparent"; 1651 this._canvas.style.position = "absolute"; 1652 this._canvas.style.top = "0"; 1653 this._canvas.style.left = "0"; 1654 } 1655 getContext() { 1656 return this.context; 1657 } 1658 getPixelRatio() { 1659 return this.pixelRatio; 1660 } 1661 setPixelRatio(pixelRatio) { 1662 const previousRatio = this.pixelRatio; 1663 this.pixelRatio = pixelRatio; 1664 this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio); 1665 } 1666 setWidth(width) { 1667 this.width = this._canvas.width = width * this.pixelRatio; 1668 this._canvas.style.width = width + "px"; 1669 const pixelRatio = this.pixelRatio, _context = this.getContext()._context; 1670 _context.scale(pixelRatio, pixelRatio); 1671 } 1672 setHeight(height) { 1673 this.height = this._canvas.height = height * this.pixelRatio; 1674 this._canvas.style.height = height + "px"; 1675 const pixelRatio = this.pixelRatio, _context = this.getContext()._context; 1676 _context.scale(pixelRatio, pixelRatio); 1677 } 1678 getWidth() { 1679 return this.width; 1680 } 1681 getHeight() { 1682 return this.height; 1683 } 1684 setSize(width, height) { 1685 this.setWidth(width || 0); 1686 this.setHeight(height || 0); 1687 } 1688 toDataURL(mimeType, quality) { 1689 try { 1690 return this._canvas.toDataURL(mimeType, quality); 1691 } catch (e) { 1692 try { 1693 return this._canvas.toDataURL(); 1694 } catch (err) { 1695 Util_1.Util.error("Unable to get data URL. " + err.message + " For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html."); 1696 return ""; 1697 } 1698 } 1699 } 1700 }; 1701 exports.Canvas = Canvas; 1702 Factory_1.Factory.addGetterSetter(Canvas, "pixelRatio", void 0, (0, Validators_1.getNumberValidator)()); 1703 var SceneCanvas = class extends Canvas { 1704 constructor(config = { width: 0, height: 0, willReadFrequently: false }) { 1705 super(config); 1706 this.context = new Context_1.SceneContext(this, { 1707 willReadFrequently: config.willReadFrequently 1708 }); 1709 this.setSize(config.width, config.height); 1710 } 1711 }; 1712 exports.SceneCanvas = SceneCanvas; 1713 var HitCanvas = class extends Canvas { 1714 constructor(config = { width: 0, height: 0 }) { 1715 super(config); 1716 this.hitCanvas = true; 1717 this.context = new Context_1.HitContext(this); 1718 this.setSize(config.width, config.height); 1719 } 1720 }; 1721 exports.HitCanvas = HitCanvas; 1722 } 1723 }); 1724 1725 // node_modules/konva/lib/DragAndDrop.js 1726 var require_DragAndDrop = __commonJS({ 1727 "node_modules/konva/lib/DragAndDrop.js"(exports) { 1728 "use strict"; 1729 Object.defineProperty(exports, "__esModule", { value: true }); 1730 exports.DD = void 0; 1731 var Global_1 = require_Global(); 1732 var Util_1 = require_Util(); 1733 exports.DD = { 1734 get isDragging() { 1735 let flag = false; 1736 exports.DD._dragElements.forEach((elem) => { 1737 if (elem.dragStatus === "dragging") { 1738 flag = true; 1739 } 1740 }); 1741 return flag; 1742 }, 1743 justDragged: false, 1744 get node() { 1745 let node; 1746 exports.DD._dragElements.forEach((elem) => { 1747 node = elem.node; 1748 }); 1749 return node; 1750 }, 1751 _dragElements: /* @__PURE__ */ new Map(), 1752 _drag(evt) { 1753 const nodesToFireEvents = []; 1754 exports.DD._dragElements.forEach((elem, key) => { 1755 const { node } = elem; 1756 const stage = node.getStage(); 1757 stage.setPointersPositions(evt); 1758 if (elem.pointerId === void 0) { 1759 elem.pointerId = Util_1.Util._getFirstPointerId(evt); 1760 } 1761 const pos = stage._changedPointerPositions.find((pos2) => pos2.id === elem.pointerId); 1762 if (!pos) { 1763 return; 1764 } 1765 if (elem.dragStatus !== "dragging") { 1766 const dragDistance = node.dragDistance(); 1767 const distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y)); 1768 if (distance < dragDistance) { 1769 return; 1770 } 1771 node.startDrag({ evt }); 1772 if (!node.isDragging()) { 1773 return; 1774 } 1775 } 1776 node._setDragPosition(evt, elem); 1777 nodesToFireEvents.push(node); 1778 }); 1779 nodesToFireEvents.forEach((node) => { 1780 node.fire("dragmove", { 1781 type: "dragmove", 1782 target: node, 1783 evt 1784 }, true); 1785 }); 1786 }, 1787 _endDragBefore(evt) { 1788 const drawNodes = []; 1789 exports.DD._dragElements.forEach((elem) => { 1790 const { node } = elem; 1791 const stage = node.getStage(); 1792 if (evt) { 1793 stage.setPointersPositions(evt); 1794 } 1795 const pos = stage._changedPointerPositions.find((pos2) => pos2.id === elem.pointerId); 1796 if (!pos) { 1797 return; 1798 } 1799 if (elem.dragStatus === "dragging" || elem.dragStatus === "stopped") { 1800 exports.DD.justDragged = true; 1801 Global_1.Konva._mouseListenClick = false; 1802 Global_1.Konva._touchListenClick = false; 1803 Global_1.Konva._pointerListenClick = false; 1804 elem.dragStatus = "stopped"; 1805 } 1806 const drawNode = elem.node.getLayer() || elem.node instanceof Global_1.Konva["Stage"] && elem.node; 1807 if (drawNode && drawNodes.indexOf(drawNode) === -1) { 1808 drawNodes.push(drawNode); 1809 } 1810 }); 1811 drawNodes.forEach((drawNode) => { 1812 drawNode.draw(); 1813 }); 1814 }, 1815 _endDragAfter(evt) { 1816 exports.DD._dragElements.forEach((elem, key) => { 1817 if (elem.dragStatus === "stopped") { 1818 elem.node.fire("dragend", { 1819 type: "dragend", 1820 target: elem.node, 1821 evt 1822 }, true); 1823 } 1824 if (elem.dragStatus !== "dragging") { 1825 exports.DD._dragElements.delete(key); 1826 } 1827 }); 1828 } 1829 }; 1830 if (Global_1.Konva.isBrowser) { 1831 window.addEventListener("mouseup", exports.DD._endDragBefore, true); 1832 window.addEventListener("touchend", exports.DD._endDragBefore, true); 1833 window.addEventListener("touchcancel", 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 window.addEventListener("touchcancel", exports.DD._endDragAfter, false); 1839 } 1840 } 1841 }); 1842 1843 // node_modules/konva/lib/Node.js 1844 var require_Node = __commonJS({ 1845 "node_modules/konva/lib/Node.js"(exports) { 1846 "use strict"; 1847 Object.defineProperty(exports, "__esModule", { value: true }); 1848 exports.Node = void 0; 1849 var Util_1 = require_Util(); 1850 var Factory_1 = require_Factory(); 1851 var Canvas_1 = require_Canvas(); 1852 var Global_1 = require_Global(); 1853 var DragAndDrop_1 = require_DragAndDrop(); 1854 var Validators_1 = require_Validators(); 1855 var ABSOLUTE_OPACITY = "absoluteOpacity"; 1856 var ALL_LISTENERS = "allEventListeners"; 1857 var ABSOLUTE_TRANSFORM = "absoluteTransform"; 1858 var ABSOLUTE_SCALE = "absoluteScale"; 1859 var CANVAS = "canvas"; 1860 var CHANGE = "Change"; 1861 var CHILDREN = "children"; 1862 var KONVA = "konva"; 1863 var LISTENING = "listening"; 1864 var MOUSEENTER = "mouseenter"; 1865 var MOUSELEAVE = "mouseleave"; 1866 var SET = "set"; 1867 var SHAPE = "Shape"; 1868 var SPACE = " "; 1869 var STAGE = "stage"; 1870 var TRANSFORM = "transform"; 1871 var UPPER_STAGE = "Stage"; 1872 var VISIBLE = "visible"; 1873 var TRANSFORM_CHANGE_STR = [ 1874 "xChange.konva", 1875 "yChange.konva", 1876 "scaleXChange.konva", 1877 "scaleYChange.konva", 1878 "skewXChange.konva", 1879 "skewYChange.konva", 1880 "rotationChange.konva", 1881 "offsetXChange.konva", 1882 "offsetYChange.konva", 1883 "transformsEnabledChange.konva" 1884 ].join(SPACE); 1885 var idCounter = 1; 1886 var Node = class _Node { 1887 constructor(config) { 1888 this._id = idCounter++; 1889 this.eventListeners = {}; 1890 this.attrs = {}; 1891 this.index = 0; 1892 this._allEventListeners = null; 1893 this.parent = null; 1894 this._cache = /* @__PURE__ */ new Map(); 1895 this._attachedDepsListeners = /* @__PURE__ */ new Map(); 1896 this._lastPos = null; 1897 this._batchingTransformChange = false; 1898 this._needClearTransformCache = false; 1899 this._filterUpToDate = false; 1900 this._isUnderCache = false; 1901 this._dragEventId = null; 1902 this._shouldFireChangeEvents = false; 1903 this.setAttrs(config); 1904 this._shouldFireChangeEvents = true; 1905 } 1906 hasChildren() { 1907 return false; 1908 } 1909 _clearCache(attr) { 1910 if ((attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM) && this._cache.get(attr)) { 1911 this._cache.get(attr).dirty = true; 1912 } else if (attr) { 1913 this._cache.delete(attr); 1914 } else { 1915 this._cache.clear(); 1916 } 1917 } 1918 _getCache(attr, privateGetter) { 1919 let cache = this._cache.get(attr); 1920 const isTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM; 1921 const invalid = cache === void 0 || isTransform && cache.dirty === true; 1922 if (invalid) { 1923 cache = privateGetter.call(this); 1924 this._cache.set(attr, cache); 1925 } 1926 return cache; 1927 } 1928 _calculate(name, deps, getter) { 1929 if (!this._attachedDepsListeners.get(name)) { 1930 const depsString = deps.map((dep) => dep + "Change.konva").join(SPACE); 1931 this.on(depsString, () => { 1932 this._clearCache(name); 1933 }); 1934 this._attachedDepsListeners.set(name, true); 1935 } 1936 return this._getCache(name, getter); 1937 } 1938 _getCanvasCache() { 1939 return this._cache.get(CANVAS); 1940 } 1941 _clearSelfAndDescendantCache(attr) { 1942 this._clearCache(attr); 1943 if (attr === ABSOLUTE_TRANSFORM) { 1944 this.fire("absoluteTransformChange"); 1945 } 1946 } 1947 clearCache() { 1948 if (this._cache.has(CANVAS)) { 1949 const { scene, filter, hit } = this._cache.get(CANVAS); 1950 Util_1.Util.releaseCanvas(scene, filter, hit); 1951 this._cache.delete(CANVAS); 1952 } 1953 this._clearSelfAndDescendantCache(); 1954 this._requestDraw(); 1955 return this; 1956 } 1957 cache(config) { 1958 const conf = config || {}; 1959 let rect = {}; 1960 if (conf.x === void 0 || conf.y === void 0 || conf.width === void 0 || conf.height === void 0) { 1961 rect = this.getClientRect({ 1962 skipTransform: true, 1963 relativeTo: this.getParent() || void 0 1964 }); 1965 } 1966 let 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; 1967 if (!width || !height) { 1968 Util_1.Util.error("Can not cache the node. Width or height of the node equals 0. Caching is skipped."); 1969 return; 1970 } 1971 const extraPaddingX = Math.abs(Math.round(rect.x) - x) > 0.5 ? 1 : 0; 1972 const extraPaddingY = Math.abs(Math.round(rect.y) - y) > 0.5 ? 1 : 0; 1973 width += offset * 2 + extraPaddingX; 1974 height += offset * 2 + extraPaddingY; 1975 x -= offset; 1976 y -= offset; 1977 const cachedSceneCanvas = new Canvas_1.SceneCanvas({ 1978 pixelRatio, 1979 width, 1980 height 1981 }), cachedFilterCanvas = new Canvas_1.SceneCanvas({ 1982 pixelRatio, 1983 width: 0, 1984 height: 0, 1985 willReadFrequently: true 1986 }), cachedHitCanvas = new Canvas_1.HitCanvas({ 1987 pixelRatio: hitCanvasPixelRatio, 1988 width, 1989 height 1990 }), sceneContext = cachedSceneCanvas.getContext(), hitContext = cachedHitCanvas.getContext(); 1991 cachedHitCanvas.isCache = true; 1992 cachedSceneCanvas.isCache = true; 1993 this._cache.delete(CANVAS); 1994 this._filterUpToDate = false; 1995 if (conf.imageSmoothingEnabled === false) { 1996 cachedSceneCanvas.getContext()._context.imageSmoothingEnabled = false; 1997 cachedFilterCanvas.getContext()._context.imageSmoothingEnabled = false; 1998 } 1999 sceneContext.save(); 2000 hitContext.save(); 2001 sceneContext.translate(-x, -y); 2002 hitContext.translate(-x, -y); 2003 this._isUnderCache = true; 2004 this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY); 2005 this._clearSelfAndDescendantCache(ABSOLUTE_SCALE); 2006 this.drawScene(cachedSceneCanvas, this); 2007 this.drawHit(cachedHitCanvas, this); 2008 this._isUnderCache = false; 2009 sceneContext.restore(); 2010 hitContext.restore(); 2011 if (drawBorder) { 2012 sceneContext.save(); 2013 sceneContext.beginPath(); 2014 sceneContext.rect(0, 0, width, height); 2015 sceneContext.closePath(); 2016 sceneContext.setAttr("strokeStyle", "red"); 2017 sceneContext.setAttr("lineWidth", 5); 2018 sceneContext.stroke(); 2019 sceneContext.restore(); 2020 } 2021 this._cache.set(CANVAS, { 2022 scene: cachedSceneCanvas, 2023 filter: cachedFilterCanvas, 2024 hit: cachedHitCanvas, 2025 x, 2026 y 2027 }); 2028 this._requestDraw(); 2029 return this; 2030 } 2031 isCached() { 2032 return this._cache.has(CANVAS); 2033 } 2034 getClientRect(config) { 2035 throw new Error('abstract "getClientRect" method call'); 2036 } 2037 _transformedRect(rect, top) { 2038 const points = [ 2039 { x: rect.x, y: rect.y }, 2040 { x: rect.x + rect.width, y: rect.y }, 2041 { x: rect.x + rect.width, y: rect.y + rect.height }, 2042 { x: rect.x, y: rect.y + rect.height } 2043 ]; 2044 let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; 2045 const trans = this.getAbsoluteTransform(top); 2046 points.forEach(function(point) { 2047 const transformed = trans.point(point); 2048 if (minX === void 0) { 2049 minX = maxX = transformed.x; 2050 minY = maxY = transformed.y; 2051 } 2052 minX = Math.min(minX, transformed.x); 2053 minY = Math.min(minY, transformed.y); 2054 maxX = Math.max(maxX, transformed.x); 2055 maxY = Math.max(maxY, transformed.y); 2056 }); 2057 return { 2058 x: minX, 2059 y: minY, 2060 width: maxX - minX, 2061 height: maxY - minY 2062 }; 2063 } 2064 _drawCachedSceneCanvas(context) { 2065 context.save(); 2066 context._applyOpacity(this); 2067 context._applyGlobalCompositeOperation(this); 2068 const canvasCache = this._getCanvasCache(); 2069 context.translate(canvasCache.x, canvasCache.y); 2070 const cacheCanvas = this._getCachedSceneCanvas(); 2071 const ratio = cacheCanvas.pixelRatio; 2072 context.drawImage(cacheCanvas._canvas, 0, 0, cacheCanvas.width / ratio, cacheCanvas.height / ratio); 2073 context.restore(); 2074 } 2075 _drawCachedHitCanvas(context) { 2076 const canvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit; 2077 context.save(); 2078 context.translate(canvasCache.x, canvasCache.y); 2079 context.drawImage(hitCanvas._canvas, 0, 0, hitCanvas.width / hitCanvas.pixelRatio, hitCanvas.height / hitCanvas.pixelRatio); 2080 context.restore(); 2081 } 2082 _getCachedSceneCanvas() { 2083 let filters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter; 2084 if (filters) { 2085 if (!this._filterUpToDate) { 2086 const ratio = sceneCanvas.pixelRatio; 2087 filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio); 2088 try { 2089 len = filters.length; 2090 filterContext.clear(); 2091 filterContext.drawImage(sceneCanvas._canvas, 0, 0, sceneCanvas.getWidth() / ratio, sceneCanvas.getHeight() / ratio); 2092 imageData = filterContext.getImageData(0, 0, filterCanvas.getWidth(), filterCanvas.getHeight()); 2093 for (n = 0; n < len; n++) { 2094 filter = filters[n]; 2095 if (typeof filter !== "function") { 2096 Util_1.Util.error("Filter should be type of function, but got " + typeof filter + " instead. Please check correct filters"); 2097 continue; 2098 } 2099 filter.call(this, imageData); 2100 filterContext.putImageData(imageData, 0, 0); 2101 } 2102 } catch (e) { 2103 Util_1.Util.error("Unable to apply filter. " + e.message + " This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html."); 2104 } 2105 this._filterUpToDate = true; 2106 } 2107 return filterCanvas; 2108 } 2109 return sceneCanvas; 2110 } 2111 on(evtStr, handler) { 2112 this._cache && this._cache.delete(ALL_LISTENERS); 2113 if (arguments.length === 3) { 2114 return this._delegate.apply(this, arguments); 2115 } 2116 let events = evtStr.split(SPACE), len = events.length, n, event, parts, baseEvent, name; 2117 for (n = 0; n < len; n++) { 2118 event = events[n]; 2119 parts = event.split("."); 2120 baseEvent = parts[0]; 2121 name = parts[1] || ""; 2122 if (!this.eventListeners[baseEvent]) { 2123 this.eventListeners[baseEvent] = []; 2124 } 2125 this.eventListeners[baseEvent].push({ 2126 name, 2127 handler 2128 }); 2129 } 2130 return this; 2131 } 2132 off(evtStr, callback) { 2133 let events = (evtStr || "").split(SPACE), len = events.length, n, t, event, parts, baseEvent, name; 2134 this._cache && this._cache.delete(ALL_LISTENERS); 2135 if (!evtStr) { 2136 for (t in this.eventListeners) { 2137 this._off(t); 2138 } 2139 } 2140 for (n = 0; n < len; n++) { 2141 event = events[n]; 2142 parts = event.split("."); 2143 baseEvent = parts[0]; 2144 name = parts[1]; 2145 if (baseEvent) { 2146 if (this.eventListeners[baseEvent]) { 2147 this._off(baseEvent, name, callback); 2148 } 2149 } else { 2150 for (t in this.eventListeners) { 2151 this._off(t, name, callback); 2152 } 2153 } 2154 } 2155 return this; 2156 } 2157 dispatchEvent(evt) { 2158 const e = { 2159 target: this, 2160 type: evt.type, 2161 evt 2162 }; 2163 this.fire(evt.type, e); 2164 return this; 2165 } 2166 addEventListener(type, handler) { 2167 this.on(type, function(evt) { 2168 handler.call(this, evt.evt); 2169 }); 2170 return this; 2171 } 2172 removeEventListener(type) { 2173 this.off(type); 2174 return this; 2175 } 2176 _delegate(event, selector, handler) { 2177 const stopNode = this; 2178 this.on(event, function(evt) { 2179 const targets = evt.target.findAncestors(selector, true, stopNode); 2180 for (let i = 0; i < targets.length; i++) { 2181 evt = Util_1.Util.cloneObject(evt); 2182 evt.currentTarget = targets[i]; 2183 handler.call(targets[i], evt); 2184 } 2185 }); 2186 } 2187 remove() { 2188 if (this.isDragging()) { 2189 this.stopDrag(); 2190 } 2191 DragAndDrop_1.DD._dragElements.delete(this._id); 2192 this._remove(); 2193 return this; 2194 } 2195 _clearCaches() { 2196 this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM); 2197 this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY); 2198 this._clearSelfAndDescendantCache(ABSOLUTE_SCALE); 2199 this._clearSelfAndDescendantCache(STAGE); 2200 this._clearSelfAndDescendantCache(VISIBLE); 2201 this._clearSelfAndDescendantCache(LISTENING); 2202 } 2203 _remove() { 2204 this._clearCaches(); 2205 const parent = this.getParent(); 2206 if (parent && parent.children) { 2207 parent.children.splice(this.index, 1); 2208 parent._setChildrenIndices(); 2209 this.parent = null; 2210 } 2211 } 2212 destroy() { 2213 this.remove(); 2214 this.clearCache(); 2215 return this; 2216 } 2217 getAttr(attr) { 2218 const method = "get" + Util_1.Util._capitalize(attr); 2219 if (Util_1.Util._isFunction(this[method])) { 2220 return this[method](); 2221 } 2222 return this.attrs[attr]; 2223 } 2224 getAncestors() { 2225 let parent = this.getParent(), ancestors = []; 2226 while (parent) { 2227 ancestors.push(parent); 2228 parent = parent.getParent(); 2229 } 2230 return ancestors; 2231 } 2232 getAttrs() { 2233 return this.attrs || {}; 2234 } 2235 setAttrs(config) { 2236 this._batchTransformChanges(() => { 2237 let key, method; 2238 if (!config) { 2239 return this; 2240 } 2241 for (key in config) { 2242 if (key === CHILDREN) { 2243 continue; 2244 } 2245 method = SET + Util_1.Util._capitalize(key); 2246 if (Util_1.Util._isFunction(this[method])) { 2247 this[method](config[key]); 2248 } else { 2249 this._setAttr(key, config[key]); 2250 } 2251 } 2252 }); 2253 return this; 2254 } 2255 isListening() { 2256 return this._getCache(LISTENING, this._isListening); 2257 } 2258 _isListening(relativeTo) { 2259 const listening = this.listening(); 2260 if (!listening) { 2261 return false; 2262 } 2263 const parent = this.getParent(); 2264 if (parent && parent !== relativeTo && this !== relativeTo) { 2265 return parent._isListening(relativeTo); 2266 } else { 2267 return true; 2268 } 2269 } 2270 isVisible() { 2271 return this._getCache(VISIBLE, this._isVisible); 2272 } 2273 _isVisible(relativeTo) { 2274 const visible = this.visible(); 2275 if (!visible) { 2276 return false; 2277 } 2278 const parent = this.getParent(); 2279 if (parent && parent !== relativeTo && this !== relativeTo) { 2280 return parent._isVisible(relativeTo); 2281 } else { 2282 return true; 2283 } 2284 } 2285 shouldDrawHit(top, skipDragCheck = false) { 2286 if (top) { 2287 return this._isVisible(top) && this._isListening(top); 2288 } 2289 const layer = this.getLayer(); 2290 let layerUnderDrag = false; 2291 DragAndDrop_1.DD._dragElements.forEach((elem) => { 2292 if (elem.dragStatus !== "dragging") { 2293 return; 2294 } else if (elem.node.nodeType === "Stage") { 2295 layerUnderDrag = true; 2296 } else if (elem.node.getLayer() === layer) { 2297 layerUnderDrag = true; 2298 } 2299 }); 2300 const dragSkip = !skipDragCheck && !Global_1.Konva.hitOnDragEnabled && (layerUnderDrag || Global_1.Konva.isTransforming()); 2301 return this.isListening() && this.isVisible() && !dragSkip; 2302 } 2303 show() { 2304 this.visible(true); 2305 return this; 2306 } 2307 hide() { 2308 this.visible(false); 2309 return this; 2310 } 2311 getZIndex() { 2312 return this.index || 0; 2313 } 2314 getAbsoluteZIndex() { 2315 let depth = this.getDepth(), that = this, index = 0, nodes, len, n, child; 2316 function addChildren(children) { 2317 nodes = []; 2318 len = children.length; 2319 for (n = 0; n < len; n++) { 2320 child = children[n]; 2321 index++; 2322 if (child.nodeType !== SHAPE) { 2323 nodes = nodes.concat(child.getChildren().slice()); 2324 } 2325 if (child._id === that._id) { 2326 n = len; 2327 } 2328 } 2329 if (nodes.length > 0 && nodes[0].getDepth() <= depth) { 2330 addChildren(nodes); 2331 } 2332 } 2333 const stage = this.getStage(); 2334 if (that.nodeType !== UPPER_STAGE && stage) { 2335 addChildren(stage.getChildren()); 2336 } 2337 return index; 2338 } 2339 getDepth() { 2340 let depth = 0, parent = this.parent; 2341 while (parent) { 2342 depth++; 2343 parent = parent.parent; 2344 } 2345 return depth; 2346 } 2347 _batchTransformChanges(func) { 2348 this._batchingTransformChange = true; 2349 func(); 2350 this._batchingTransformChange = false; 2351 if (this._needClearTransformCache) { 2352 this._clearCache(TRANSFORM); 2353 this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM); 2354 } 2355 this._needClearTransformCache = false; 2356 } 2357 setPosition(pos) { 2358 this._batchTransformChanges(() => { 2359 this.x(pos.x); 2360 this.y(pos.y); 2361 }); 2362 return this; 2363 } 2364 getPosition() { 2365 return { 2366 x: this.x(), 2367 y: this.y() 2368 }; 2369 } 2370 getRelativePointerPosition() { 2371 const stage = this.getStage(); 2372 if (!stage) { 2373 return null; 2374 } 2375 const pos = stage.getPointerPosition(); 2376 if (!pos) { 2377 return null; 2378 } 2379 const transform = this.getAbsoluteTransform().copy(); 2380 transform.invert(); 2381 return transform.point(pos); 2382 } 2383 getAbsolutePosition(top) { 2384 let haveCachedParent = false; 2385 let parent = this.parent; 2386 while (parent) { 2387 if (parent.isCached()) { 2388 haveCachedParent = true; 2389 break; 2390 } 2391 parent = parent.parent; 2392 } 2393 if (haveCachedParent && !top) { 2394 top = true; 2395 } 2396 const absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Util_1.Transform(), offset = this.offset(); 2397 absoluteTransform.m = absoluteMatrix.slice(); 2398 absoluteTransform.translate(offset.x, offset.y); 2399 return absoluteTransform.getTranslation(); 2400 } 2401 setAbsolutePosition(pos) { 2402 const { x, y, ...origTrans } = this._clearTransform(); 2403 this.attrs.x = x; 2404 this.attrs.y = y; 2405 this._clearCache(TRANSFORM); 2406 const it = this._getAbsoluteTransform().copy(); 2407 it.invert(); 2408 it.translate(pos.x, pos.y); 2409 pos = { 2410 x: this.attrs.x + it.getTranslation().x, 2411 y: this.attrs.y + it.getTranslation().y 2412 }; 2413 this._setTransform(origTrans); 2414 this.setPosition({ x: pos.x, y: pos.y }); 2415 this._clearCache(TRANSFORM); 2416 this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM); 2417 return this; 2418 } 2419 _setTransform(trans) { 2420 let key; 2421 for (key in trans) { 2422 this.attrs[key] = trans[key]; 2423 } 2424 } 2425 _clearTransform() { 2426 const trans = { 2427 x: this.x(), 2428 y: this.y(), 2429 rotation: this.rotation(), 2430 scaleX: this.scaleX(), 2431 scaleY: this.scaleY(), 2432 offsetX: this.offsetX(), 2433 offsetY: this.offsetY(), 2434 skewX: this.skewX(), 2435 skewY: this.skewY() 2436 }; 2437 this.attrs.x = 0; 2438 this.attrs.y = 0; 2439 this.attrs.rotation = 0; 2440 this.attrs.scaleX = 1; 2441 this.attrs.scaleY = 1; 2442 this.attrs.offsetX = 0; 2443 this.attrs.offsetY = 0; 2444 this.attrs.skewX = 0; 2445 this.attrs.skewY = 0; 2446 return trans; 2447 } 2448 move(change) { 2449 let changeX = change.x, changeY = change.y, x = this.x(), y = this.y(); 2450 if (changeX !== void 0) { 2451 x += changeX; 2452 } 2453 if (changeY !== void 0) { 2454 y += changeY; 2455 } 2456 this.setPosition({ x, y }); 2457 return this; 2458 } 2459 _eachAncestorReverse(func, top) { 2460 let family = [], parent = this.getParent(), len, n; 2461 if (top && top._id === this._id) { 2462 return; 2463 } 2464 family.unshift(this); 2465 while (parent && (!top || parent._id !== top._id)) { 2466 family.unshift(parent); 2467 parent = parent.parent; 2468 } 2469 len = family.length; 2470 for (n = 0; n < len; n++) { 2471 func(family[n]); 2472 } 2473 } 2474 rotate(theta) { 2475 this.rotation(this.rotation() + theta); 2476 return this; 2477 } 2478 moveToTop() { 2479 if (!this.parent) { 2480 Util_1.Util.warn("Node has no parent. moveToTop function is ignored."); 2481 return false; 2482 } 2483 const index = this.index, len = this.parent.getChildren().length; 2484 if (index < len - 1) { 2485 this.parent.children.splice(index, 1); 2486 this.parent.children.push(this); 2487 this.parent._setChildrenIndices(); 2488 return true; 2489 } 2490 return false; 2491 } 2492 moveUp() { 2493 if (!this.parent) { 2494 Util_1.Util.warn("Node has no parent. moveUp function is ignored."); 2495 return false; 2496 } 2497 const index = this.index, len = this.parent.getChildren().length; 2498 if (index < len - 1) { 2499 this.parent.children.splice(index, 1); 2500 this.parent.children.splice(index + 1, 0, this); 2501 this.parent._setChildrenIndices(); 2502 return true; 2503 } 2504 return false; 2505 } 2506 moveDown() { 2507 if (!this.parent) { 2508 Util_1.Util.warn("Node has no parent. moveDown function is ignored."); 2509 return false; 2510 } 2511 const index = this.index; 2512 if (index > 0) { 2513 this.parent.children.splice(index, 1); 2514 this.parent.children.splice(index - 1, 0, this); 2515 this.parent._setChildrenIndices(); 2516 return true; 2517 } 2518 return false; 2519 } 2520 moveToBottom() { 2521 if (!this.parent) { 2522 Util_1.Util.warn("Node has no parent. moveToBottom function is ignored."); 2523 return false; 2524 } 2525 const index = this.index; 2526 if (index > 0) { 2527 this.parent.children.splice(index, 1); 2528 this.parent.children.unshift(this); 2529 this.parent._setChildrenIndices(); 2530 return true; 2531 } 2532 return false; 2533 } 2534 setZIndex(zIndex) { 2535 if (!this.parent) { 2536 Util_1.Util.warn("Node has no parent. zIndex parameter is ignored."); 2537 return this; 2538 } 2539 if (zIndex < 0 || zIndex >= this.parent.children.length) { 2540 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) + "."); 2541 } 2542 const index = this.index; 2543 this.parent.children.splice(index, 1); 2544 this.parent.children.splice(zIndex, 0, this); 2545 this.parent._setChildrenIndices(); 2546 return this; 2547 } 2548 getAbsoluteOpacity() { 2549 return this._getCache(ABSOLUTE_OPACITY, this._getAbsoluteOpacity); 2550 } 2551 _getAbsoluteOpacity() { 2552 let absOpacity = this.opacity(); 2553 const parent = this.getParent(); 2554 if (parent && !parent._isUnderCache) { 2555 absOpacity *= parent.getAbsoluteOpacity(); 2556 } 2557 return absOpacity; 2558 } 2559 moveTo(newContainer) { 2560 if (this.getParent() !== newContainer) { 2561 this._remove(); 2562 newContainer.add(this); 2563 } 2564 return this; 2565 } 2566 toObject() { 2567 let attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject; 2568 const obj = { 2569 attrs: {}, 2570 className: this.getClassName() 2571 }; 2572 for (key in attrs) { 2573 val = attrs[key]; 2574 nonPlainObject = Util_1.Util.isObject(val) && !Util_1.Util._isPlainObject(val) && !Util_1.Util._isArray(val); 2575 if (nonPlainObject) { 2576 continue; 2577 } 2578 getter = typeof this[key] === "function" && this[key]; 2579 delete attrs[key]; 2580 defaultValue = getter ? getter.call(this) : null; 2581 attrs[key] = val; 2582 if (defaultValue !== val) { 2583 obj.attrs[key] = val; 2584 } 2585 } 2586 return Util_1.Util._prepareToStringify(obj); 2587 } 2588 toJSON() { 2589 return JSON.stringify(this.toObject()); 2590 } 2591 getParent() { 2592 return this.parent; 2593 } 2594 findAncestors(selector, includeSelf, stopNode) { 2595 const res = []; 2596 if (includeSelf && this._isMatch(selector)) { 2597 res.push(this); 2598 } 2599 let ancestor = this.parent; 2600 while (ancestor) { 2601 if (ancestor === stopNode) { 2602 return res; 2603 } 2604 if (ancestor._isMatch(selector)) { 2605 res.push(ancestor); 2606 } 2607 ancestor = ancestor.parent; 2608 } 2609 return res; 2610 } 2611 isAncestorOf(node) { 2612 return false; 2613 } 2614 findAncestor(selector, includeSelf, stopNode) { 2615 return this.findAncestors(selector, includeSelf, stopNode)[0]; 2616 } 2617 _isMatch(selector) { 2618 if (!selector) { 2619 return false; 2620 } 2621 if (typeof selector === "function") { 2622 return selector(this); 2623 } 2624 let selectorArr = selector.replace(/ /g, "").split(","), len = selectorArr.length, n, sel; 2625 for (n = 0; n < len; n++) { 2626 sel = selectorArr[n]; 2627 if (!Util_1.Util.isValidSelector(sel)) { 2628 Util_1.Util.warn('Selector "' + sel + '" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".'); 2629 Util_1.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".'); 2630 Util_1.Util.warn("Konva is awesome, right?"); 2631 } 2632 if (sel.charAt(0) === "#") { 2633 if (this.id() === sel.slice(1)) { 2634 return true; 2635 } 2636 } else if (sel.charAt(0) === ".") { 2637 if (this.hasName(sel.slice(1))) { 2638 return true; 2639 } 2640 } else if (this.className === sel || this.nodeType === sel) { 2641 return true; 2642 } 2643 } 2644 return false; 2645 } 2646 getLayer() { 2647 const parent = this.getParent(); 2648 return parent ? parent.getLayer() : null; 2649 } 2650 getStage() { 2651 return this._getCache(STAGE, this._getStage); 2652 } 2653 _getStage() { 2654 const parent = this.getParent(); 2655 if (parent) { 2656 return parent.getStage(); 2657 } else { 2658 return null; 2659 } 2660 } 2661 fire(eventType, evt = {}, bubble) { 2662 evt.target = evt.target || this; 2663 if (bubble) { 2664 this._fireAndBubble(eventType, evt); 2665 } else { 2666 this._fire(eventType, evt); 2667 } 2668 return this; 2669 } 2670 getAbsoluteTransform(top) { 2671 if (top) { 2672 return this._getAbsoluteTransform(top); 2673 } else { 2674 return this._getCache(ABSOLUTE_TRANSFORM, this._getAbsoluteTransform); 2675 } 2676 } 2677 _getAbsoluteTransform(top) { 2678 let at; 2679 if (top) { 2680 at = new Util_1.Transform(); 2681 this._eachAncestorReverse(function(node) { 2682 const transformsEnabled = node.transformsEnabled(); 2683 if (transformsEnabled === "all") { 2684 at.multiply(node.getTransform()); 2685 } else if (transformsEnabled === "position") { 2686 at.translate(node.x() - node.offsetX(), node.y() - node.offsetY()); 2687 } 2688 }, top); 2689 return at; 2690 } else { 2691 at = this._cache.get(ABSOLUTE_TRANSFORM) || new Util_1.Transform(); 2692 if (this.parent) { 2693 this.parent.getAbsoluteTransform().copyInto(at); 2694 } else { 2695 at.reset(); 2696 } 2697 const transformsEnabled = this.transformsEnabled(); 2698 if (transformsEnabled === "all") { 2699 at.multiply(this.getTransform()); 2700 } else if (transformsEnabled === "position") { 2701 const x = this.attrs.x || 0; 2702 const y = this.attrs.y || 0; 2703 const offsetX = this.attrs.offsetX || 0; 2704 const offsetY = this.attrs.offsetY || 0; 2705 at.translate(x - offsetX, y - offsetY); 2706 } 2707 at.dirty = false; 2708 return at; 2709 } 2710 } 2711 getAbsoluteScale(top) { 2712 let parent = this; 2713 while (parent) { 2714 if (parent._isUnderCache) { 2715 top = parent; 2716 } 2717 parent = parent.getParent(); 2718 } 2719 const transform = this.getAbsoluteTransform(top); 2720 const attrs = transform.decompose(); 2721 return { 2722 x: attrs.scaleX, 2723 y: attrs.scaleY 2724 }; 2725 } 2726 getAbsoluteRotation() { 2727 return this.getAbsoluteTransform().decompose().rotation; 2728 } 2729 getTransform() { 2730 return this._getCache(TRANSFORM, this._getTransform); 2731 } 2732 _getTransform() { 2733 var _a, _b; 2734 const m = this._cache.get(TRANSFORM) || new Util_1.Transform(); 2735 m.reset(); 2736 const 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; 2737 if (x !== 0 || y !== 0) { 2738 m.translate(x, y); 2739 } 2740 if (rotation !== 0) { 2741 m.rotate(rotation); 2742 } 2743 if (skewX !== 0 || skewY !== 0) { 2744 m.skew(skewX, skewY); 2745 } 2746 if (scaleX !== 1 || scaleY !== 1) { 2747 m.scale(scaleX, scaleY); 2748 } 2749 if (offsetX !== 0 || offsetY !== 0) { 2750 m.translate(-1 * offsetX, -1 * offsetY); 2751 } 2752 m.dirty = false; 2753 return m; 2754 } 2755 clone(obj) { 2756 let attrs = Util_1.Util.cloneObject(this.attrs), key, allListeners, len, n, listener; 2757 for (key in obj) { 2758 attrs[key] = obj[key]; 2759 } 2760 const node = new this.constructor(attrs); 2761 for (key in this.eventListeners) { 2762 allListeners = this.eventListeners[key]; 2763 len = allListeners.length; 2764 for (n = 0; n < len; n++) { 2765 listener = allListeners[n]; 2766 if (listener.name.indexOf(KONVA) < 0) { 2767 if (!node.eventListeners[key]) { 2768 node.eventListeners[key] = []; 2769 } 2770 node.eventListeners[key].push(listener); 2771 } 2772 } 2773 } 2774 return node; 2775 } 2776 _toKonvaCanvas(config) { 2777 config = config || {}; 2778 const box = this.getClientRect(); 2779 const 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({ 2780 width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0), 2781 height: config.height || Math.ceil(box.height) || (stage ? stage.height() : 0), 2782 pixelRatio 2783 }), context = canvas.getContext(); 2784 const bufferCanvas = new Canvas_1.SceneCanvas({ 2785 width: canvas.width / canvas.pixelRatio + Math.abs(x), 2786 height: canvas.height / canvas.pixelRatio + Math.abs(y), 2787 pixelRatio: canvas.pixelRatio 2788 }); 2789 if (config.imageSmoothingEnabled === false) { 2790 context._context.imageSmoothingEnabled = false; 2791 } 2792 context.save(); 2793 if (x || y) { 2794 context.translate(-1 * x, -1 * y); 2795 } 2796 this.drawScene(canvas, void 0, bufferCanvas); 2797 context.restore(); 2798 return canvas; 2799 } 2800 toCanvas(config) { 2801 return this._toKonvaCanvas(config)._canvas; 2802 } 2803 toDataURL(config) { 2804 config = config || {}; 2805 const mimeType = config.mimeType || null, quality = config.quality || null; 2806 const url = this._toKonvaCanvas(config).toDataURL(mimeType, quality); 2807 if (config.callback) { 2808 config.callback(url); 2809 } 2810 return url; 2811 } 2812 toImage(config) { 2813 return new Promise((resolve, reject) => { 2814 try { 2815 const callback = config === null || config === void 0 ? void 0 : config.callback; 2816 if (callback) 2817 delete config.callback; 2818 Util_1.Util._urlToImage(this.toDataURL(config), function(img) { 2819 resolve(img); 2820 callback === null || callback === void 0 ? void 0 : callback(img); 2821 }); 2822 } catch (err) { 2823 reject(err); 2824 } 2825 }); 2826 } 2827 toBlob(config) { 2828 return new Promise((resolve, reject) => { 2829 try { 2830 const callback = config === null || config === void 0 ? void 0 : config.callback; 2831 if (callback) 2832 delete config.callback; 2833 this.toCanvas(config).toBlob((blob) => { 2834 resolve(blob); 2835 callback === null || callback === void 0 ? void 0 : callback(blob); 2836 }, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality); 2837 } catch (err) { 2838 reject(err); 2839 } 2840 }); 2841 } 2842 setSize(size) { 2843 this.width(size.width); 2844 this.height(size.height); 2845 return this; 2846 } 2847 getSize() { 2848 return { 2849 width: this.width(), 2850 height: this.height() 2851 }; 2852 } 2853 getClassName() { 2854 return this.className || this.nodeType; 2855 } 2856 getType() { 2857 return this.nodeType; 2858 } 2859 getDragDistance() { 2860 if (this.attrs.dragDistance !== void 0) { 2861 return this.attrs.dragDistance; 2862 } else if (this.parent) { 2863 return this.parent.getDragDistance(); 2864 } else { 2865 return Global_1.Konva.dragDistance; 2866 } 2867 } 2868 _off(type, name, callback) { 2869 let evtListeners = this.eventListeners[type], i, evtName, handler; 2870 for (i = 0; i < evtListeners.length; i++) { 2871 evtName = evtListeners[i].name; 2872 handler = evtListeners[i].handler; 2873 if ((evtName !== "konva" || name === "konva") && (!name || evtName === name) && (!callback || callback === handler)) { 2874 evtListeners.splice(i, 1); 2875 if (evtListeners.length === 0) { 2876 delete this.eventListeners[type]; 2877 break; 2878 } 2879 i--; 2880 } 2881 } 2882 } 2883 _fireChangeEvent(attr, oldVal, newVal) { 2884 this._fire(attr + CHANGE, { 2885 oldVal, 2886 newVal 2887 }); 2888 } 2889 addName(name) { 2890 if (!this.hasName(name)) { 2891 const oldName = this.name(); 2892 const newName = oldName ? oldName + " " + name : name; 2893 this.name(newName); 2894 } 2895 return this; 2896 } 2897 hasName(name) { 2898 if (!name) { 2899 return false; 2900 } 2901 const fullName = this.name(); 2902 if (!fullName) { 2903 return false; 2904 } 2905 const names = (fullName || "").split(/\s/g); 2906 return names.indexOf(name) !== -1; 2907 } 2908 removeName(name) { 2909 const names = (this.name() || "").split(/\s/g); 2910 const index = names.indexOf(name); 2911 if (index !== -1) { 2912 names.splice(index, 1); 2913 this.name(names.join(" ")); 2914 } 2915 return this; 2916 } 2917 setAttr(attr, val) { 2918 const func = this[SET + Util_1.Util._capitalize(attr)]; 2919 if (Util_1.Util._isFunction(func)) { 2920 func.call(this, val); 2921 } else { 2922 this._setAttr(attr, val); 2923 } 2924 return this; 2925 } 2926 _requestDraw() { 2927 if (Global_1.Konva.autoDrawEnabled) { 2928 const drawNode = this.getLayer() || this.getStage(); 2929 drawNode === null || drawNode === void 0 ? void 0 : drawNode.batchDraw(); 2930 } 2931 } 2932 _setAttr(key, val) { 2933 const oldVal = this.attrs[key]; 2934 if (oldVal === val && !Util_1.Util.isObject(val)) { 2935 return; 2936 } 2937 if (val === void 0 || val === null) { 2938 delete this.attrs[key]; 2939 } else { 2940 this.attrs[key] = val; 2941 } 2942 if (this._shouldFireChangeEvents) { 2943 this._fireChangeEvent(key, oldVal, val); 2944 } 2945 this._requestDraw(); 2946 } 2947 _setComponentAttr(key, component, val) { 2948 let oldVal; 2949 if (val !== void 0) { 2950 oldVal = this.attrs[key]; 2951 if (!oldVal) { 2952 this.attrs[key] = this.getAttr(key); 2953 } 2954 this.attrs[key][component] = val; 2955 this._fireChangeEvent(key, oldVal, val); 2956 } 2957 } 2958 _fireAndBubble(eventType, evt, compareShape) { 2959 if (evt && this.nodeType === SHAPE) { 2960 evt.target = this; 2961 } 2962 const shouldStop = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && (compareShape && (this === compareShape || this.isAncestorOf && this.isAncestorOf(compareShape)) || this.nodeType === "Stage" && !compareShape); 2963 if (!shouldStop) { 2964 this._fire(eventType, evt); 2965 const stopBubble = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && compareShape && compareShape.isAncestorOf && compareShape.isAncestorOf(this) && !compareShape.isAncestorOf(this.parent); 2966 if ((evt && !evt.cancelBubble || !evt) && this.parent && this.parent.isListening() && !stopBubble) { 2967 if (compareShape && compareShape.parent) { 2968 this._fireAndBubble.call(this.parent, eventType, evt, compareShape); 2969 } else { 2970 this._fireAndBubble.call(this.parent, eventType, evt); 2971 } 2972 } 2973 } 2974 } 2975 _getProtoListeners(eventType) { 2976 var _a, _b, _c; 2977 const allListeners = (_a = this._cache.get(ALL_LISTENERS)) !== null && _a !== void 0 ? _a : {}; 2978 let events = allListeners === null || allListeners === void 0 ? void 0 : allListeners[eventType]; 2979 if (events === void 0) { 2980 events = []; 2981 let obj = Object.getPrototypeOf(this); 2982 while (obj) { 2983 const hierarchyEvents = (_c = (_b = obj.eventListeners) === null || _b === void 0 ? void 0 : _b[eventType]) !== null && _c !== void 0 ? _c : []; 2984 events.push(...hierarchyEvents); 2985 obj = Object.getPrototypeOf(obj); 2986 } 2987 allListeners[eventType] = events; 2988 this._cache.set(ALL_LISTENERS, allListeners); 2989 } 2990 return events; 2991 } 2992 _fire(eventType, evt) { 2993 evt = evt || {}; 2994 evt.currentTarget = this; 2995 evt.type = eventType; 2996 const topListeners = this._getProtoListeners(eventType); 2997 if (topListeners) { 2998 for (var i = 0; i < topListeners.length; i++) { 2999 topListeners[i].handler.call(this, evt); 3000 } 3001 } 3002 const selfListeners = this.eventListeners[eventType]; 3003 if (selfListeners) { 3004 for (var i = 0; i < selfListeners.length; i++) { 3005 selfListeners[i].handler.call(this, evt); 3006 } 3007 } 3008 } 3009 draw() { 3010 this.drawScene(); 3011 this.drawHit(); 3012 return this; 3013 } 3014 _createDragElement(evt) { 3015 const pointerId = evt ? evt.pointerId : void 0; 3016 const stage = this.getStage(); 3017 const ap = this.getAbsolutePosition(); 3018 if (!stage) { 3019 return; 3020 } 3021 const pos = stage._getPointerById(pointerId) || stage._changedPointerPositions[0] || ap; 3022 DragAndDrop_1.DD._dragElements.set(this._id, { 3023 node: this, 3024 startPointerPos: pos, 3025 offset: { 3026 x: pos.x - ap.x, 3027 y: pos.y - ap.y 3028 }, 3029 dragStatus: "ready", 3030 pointerId 3031 }); 3032 } 3033 startDrag(evt, bubbleEvent = true) { 3034 if (!DragAndDrop_1.DD._dragElements.has(this._id)) { 3035 this._createDragElement(evt); 3036 } 3037 const elem = DragAndDrop_1.DD._dragElements.get(this._id); 3038 elem.dragStatus = "dragging"; 3039 this.fire("dragstart", { 3040 type: "dragstart", 3041 target: this, 3042 evt: evt && evt.evt 3043 }, bubbleEvent); 3044 } 3045 _setDragPosition(evt, elem) { 3046 const pos = this.getStage()._getPointerById(elem.pointerId); 3047 if (!pos) { 3048 return; 3049 } 3050 let newNodePos = { 3051 x: pos.x - elem.offset.x, 3052 y: pos.y - elem.offset.y 3053 }; 3054 const dbf = this.dragBoundFunc(); 3055 if (dbf !== void 0) { 3056 const bounded = dbf.call(this, newNodePos, evt); 3057 if (!bounded) { 3058 Util_1.Util.warn("dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc."); 3059 } else { 3060 newNodePos = bounded; 3061 } 3062 } 3063 if (!this._lastPos || this._lastPos.x !== newNodePos.x || this._lastPos.y !== newNodePos.y) { 3064 this.setAbsolutePosition(newNodePos); 3065 this._requestDraw(); 3066 } 3067 this._lastPos = newNodePos; 3068 } 3069 stopDrag(evt) { 3070 const elem = DragAndDrop_1.DD._dragElements.get(this._id); 3071 if (elem) { 3072 elem.dragStatus = "stopped"; 3073 } 3074 DragAndDrop_1.DD._endDragBefore(evt); 3075 DragAndDrop_1.DD._endDragAfter(evt); 3076 } 3077 setDraggable(draggable) { 3078 this._setAttr("draggable", draggable); 3079 this._dragChange(); 3080 } 3081 isDragging() { 3082 const elem = DragAndDrop_1.DD._dragElements.get(this._id); 3083 return elem ? elem.dragStatus === "dragging" : false; 3084 } 3085 _listenDrag() { 3086 this._dragCleanup(); 3087 this.on("mousedown.konva touchstart.konva", function(evt) { 3088 const shouldCheckButton = evt.evt["button"] !== void 0; 3089 const canDrag = !shouldCheckButton || Global_1.Konva.dragButtons.indexOf(evt.evt["button"]) >= 0; 3090 if (!canDrag) { 3091 return; 3092 } 3093 if (this.isDragging()) { 3094 return; 3095 } 3096 let hasDraggingChild = false; 3097 DragAndDrop_1.DD._dragElements.forEach((elem) => { 3098 if (this.isAncestorOf(elem.node)) { 3099 hasDraggingChild = true; 3100 } 3101 }); 3102 if (!hasDraggingChild) { 3103 this._createDragElement(evt); 3104 } 3105 }); 3106 } 3107 _dragChange() { 3108 if (this.attrs.draggable) { 3109 this._listenDrag(); 3110 } else { 3111 this._dragCleanup(); 3112 const stage = this.getStage(); 3113 if (!stage) { 3114 return; 3115 } 3116 const dragElement = DragAndDrop_1.DD._dragElements.get(this._id); 3117 const isDragging = dragElement && dragElement.dragStatus === "dragging"; 3118 const isReady = dragElement && dragElement.dragStatus === "ready"; 3119 if (isDragging) { 3120 this.stopDrag(); 3121 } else if (isReady) { 3122 DragAndDrop_1.DD._dragElements.delete(this._id); 3123 } 3124 } 3125 } 3126 _dragCleanup() { 3127 this.off("mousedown.konva"); 3128 this.off("touchstart.konva"); 3129 } 3130 isClientRectOnScreen(margin = { x: 0, y: 0 }) { 3131 const stage = this.getStage(); 3132 if (!stage) { 3133 return false; 3134 } 3135 const screenRect = { 3136 x: -margin.x, 3137 y: -margin.y, 3138 width: stage.width() + 2 * margin.x, 3139 height: stage.height() + 2 * margin.y 3140 }; 3141 return Util_1.Util.haveIntersection(screenRect, this.getClientRect()); 3142 } 3143 static create(data, container) { 3144 if (Util_1.Util._isString(data)) { 3145 data = JSON.parse(data); 3146 } 3147 return this._createNode(data, container); 3148 } 3149 static _createNode(obj, container) { 3150 let className = _Node.prototype.getClassName.call(obj), children = obj.children, no, len, n; 3151 if (container) { 3152 obj.attrs.container = container; 3153 } 3154 if (!Global_1.Konva[className]) { 3155 Util_1.Util.warn('Can not find a node with class name "' + className + '". Fallback to "Shape".'); 3156 className = "Shape"; 3157 } 3158 const Class = Global_1.Konva[className]; 3159 no = new Class(obj.attrs); 3160 if (children) { 3161 len = children.length; 3162 for (n = 0; n < len; n++) { 3163 no.add(_Node._createNode(children[n])); 3164 } 3165 } 3166 return no; 3167 } 3168 }; 3169 exports.Node = Node; 3170 Node.prototype.nodeType = "Node"; 3171 Node.prototype._attrsAffectingSize = []; 3172 Node.prototype.eventListeners = {}; 3173 Node.prototype.on.call(Node.prototype, TRANSFORM_CHANGE_STR, function() { 3174 if (this._batchingTransformChange) { 3175 this._needClearTransformCache = true; 3176 return; 3177 } 3178 this._clearCache(TRANSFORM); 3179 this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM); 3180 }); 3181 Node.prototype.on.call(Node.prototype, "visibleChange.konva", function() { 3182 this._clearSelfAndDescendantCache(VISIBLE); 3183 }); 3184 Node.prototype.on.call(Node.prototype, "listeningChange.konva", function() { 3185 this._clearSelfAndDescendantCache(LISTENING); 3186 }); 3187 Node.prototype.on.call(Node.prototype, "opacityChange.konva", function() { 3188 this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY); 3189 }); 3190 var addGetterSetter = Factory_1.Factory.addGetterSetter; 3191 addGetterSetter(Node, "zIndex"); 3192 addGetterSetter(Node, "absolutePosition"); 3193 addGetterSetter(Node, "position"); 3194 addGetterSetter(Node, "x", 0, (0, Validators_1.getNumberValidator)()); 3195 addGetterSetter(Node, "y", 0, (0, Validators_1.getNumberValidator)()); 3196 addGetterSetter(Node, "globalCompositeOperation", "source-over", (0, Validators_1.getStringValidator)()); 3197 addGetterSetter(Node, "opacity", 1, (0, Validators_1.getNumberValidator)()); 3198 addGetterSetter(Node, "name", "", (0, Validators_1.getStringValidator)()); 3199 addGetterSetter(Node, "id", "", (0, Validators_1.getStringValidator)()); 3200 addGetterSetter(Node, "rotation", 0, (0, Validators_1.getNumberValidator)()); 3201 Factory_1.Factory.addComponentsGetterSetter(Node, "scale", ["x", "y"]); 3202 addGetterSetter(Node, "scaleX", 1, (0, Validators_1.getNumberValidator)()); 3203 addGetterSetter(Node, "scaleY", 1, (0, Validators_1.getNumberValidator)()); 3204 Factory_1.Factory.addComponentsGetterSetter(Node, "skew", ["x", "y"]); 3205 addGetterSetter(Node, "skewX", 0, (0, Validators_1.getNumberValidator)()); 3206 addGetterSetter(Node, "skewY", 0, (0, Validators_1.getNumberValidator)()); 3207 Factory_1.Factory.addComponentsGetterSetter(Node, "offset", ["x", "y"]); 3208 addGetterSetter(Node, "offsetX", 0, (0, Validators_1.getNumberValidator)()); 3209 addGetterSetter(Node, "offsetY", 0, (0, Validators_1.getNumberValidator)()); 3210 addGetterSetter(Node, "dragDistance", null, (0, Validators_1.getNumberValidator)()); 3211 addGetterSetter(Node, "width", 0, (0, Validators_1.getNumberValidator)()); 3212 addGetterSetter(Node, "height", 0, (0, Validators_1.getNumberValidator)()); 3213 addGetterSetter(Node, "listening", true, (0, Validators_1.getBooleanValidator)()); 3214 addGetterSetter(Node, "preventDefault", true, (0, Validators_1.getBooleanValidator)()); 3215 addGetterSetter(Node, "filters", null, function(val) { 3216 this._filterUpToDate = false; 3217 return val; 3218 }); 3219 addGetterSetter(Node, "visible", true, (0, Validators_1.getBooleanValidator)()); 3220 addGetterSetter(Node, "transformsEnabled", "all", (0, Validators_1.getStringValidator)()); 3221 addGetterSetter(Node, "size"); 3222 addGetterSetter(Node, "dragBoundFunc"); 3223 addGetterSetter(Node, "draggable", false, (0, Validators_1.getBooleanValidator)()); 3224 Factory_1.Factory.backCompat(Node, { 3225 rotateDeg: "rotate", 3226 setRotationDeg: "setRotation", 3227 getRotationDeg: "getRotation" 3228 }); 3229 } 3230 }); 24 3231 25 3232 // node_modules/konva/lib/Container.js … … 42 3249 } 43 3250 const children = this.children || []; 44 varresults = [];3251 const results = []; 45 3252 children.forEach(function(child) { 46 3253 if (filterFunc(child)) { … … 78 3285 } 79 3286 if (children.length > 1) { 80 for ( vari = 0; i < children.length; i++) {3287 for (let i = 0; i < children.length; i++) { 81 3288 this.add(children[i]); 82 3289 } … … 110 3317 } 111 3318 findOne(selector) { 112 varresult = this._generalFind(selector, true);3319 const result = this._generalFind(selector, true); 113 3320 return result.length > 0 ? result[0] : void 0; 114 3321 } 115 3322 _generalFind(selector, findOne) { 116 varretArr = [];3323 const retArr = []; 117 3324 this._descendants((node) => { 118 3325 const valid = node._isMatch(selector); … … 146 3353 } 147 3354 toObject() { 148 varobj = Node_1.Node.prototype.toObject.call(this);3355 const obj = Node_1.Node.prototype.toObject.call(this); 149 3356 obj.children = []; 150 3357 this.getChildren().forEach((child) => { … … 154 3361 } 155 3362 isAncestorOf(node) { 156 varparent = node.getParent();3363 let parent = node.getParent(); 157 3364 while (parent) { 158 3365 if (parent._id === this._id) { … … 164 3371 } 165 3372 clone(obj) { 166 varnode = Node_1.Node.prototype.clone.call(this, obj);3373 const node = Node_1.Node.prototype.clone.call(this, obj); 167 3374 this.getChildren().forEach(function(no) { 168 3375 node.add(no.clone()); … … 171 3378 } 172 3379 getAllIntersections(pos) { 173 vararr = [];3380 const arr = []; 174 3381 this.find("Shape").forEach((shape) => { 175 3382 if (shape.isVisible() && shape.intersects(pos)) { … … 197 3404 } 198 3405 drawScene(can, top, bufferCanvas) { 199 varlayer = this.getLayer(), canvas = can || layer && layer.getCanvas(), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;200 varcaching = canvas && canvas.isCache;3406 const layer = this.getLayer(), canvas = can || layer && layer.getCanvas(), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene; 3407 const caching = canvas && canvas.isCache; 201 3408 if (!this.isVisible() && !caching) { 202 3409 return this; … … 204 3411 if (cachedSceneCanvas) { 205 3412 context.save(); 206 varm = this.getAbsoluteTransform(top).getMatrix();3413 const m = this.getAbsoluteTransform(top).getMatrix(); 207 3414 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 208 3415 this._drawCachedSceneCanvas(context); … … 217 3424 return this; 218 3425 } 219 varlayer = this.getLayer(), canvas = can || layer && layer.hitCanvas, context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;3426 const layer = this.getLayer(), canvas = can || layer && layer.hitCanvas, context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit; 220 3427 if (cachedHitCanvas) { 221 3428 context.save(); 222 varm = this.getAbsoluteTransform(top).getMatrix();3429 const m = this.getAbsoluteTransform(top).getMatrix(); 223 3430 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 224 3431 this._drawCachedHitCanvas(context); … … 231 3438 _drawChildren(drawMethod, canvas, top, bufferCanvas) { 232 3439 var _a; 233 varcontext = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = typeof clipWidth === "number" && typeof clipHeight === "number" || clipFunc;3440 const context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = typeof clipWidth === "number" && typeof clipHeight === "number" || clipFunc; 234 3441 const selfCache = top === this; 235 3442 if (hasClip) { 236 3443 context.save(); 237 vartransform = this.getAbsoluteTransform(top);238 varm = transform.getMatrix();3444 const transform = this.getAbsoluteTransform(top); 3445 let m = transform.getMatrix(); 239 3446 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 240 3447 context.beginPath(); … … 243 3450 clipArgs = clipFunc.call(this, context, this); 244 3451 } else { 245 varclipX = this.clipX();246 varclipY = this.clipY();3452 const clipX = this.clipX(); 3453 const clipY = this.clipY(); 247 3454 context.rect(clipX || 0, clipY || 0, clipWidth, clipHeight); 248 3455 } … … 251 3458 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 252 3459 } 253 varhasComposition = !selfCache && this.globalCompositeOperation() !== "source-over" && drawMethod === "drawScene";3460 const hasComposition = !selfCache && this.globalCompositeOperation() !== "source-over" && drawMethod === "drawScene"; 254 3461 if (hasComposition) { 255 3462 context.save(); … … 268 3475 getClientRect(config = {}) { 269 3476 var _a; 270 varskipTransform = config.skipTransform;271 varrelativeTo = config.relativeTo;272 varminX, minY, maxX, maxY;273 varselfRect = {3477 const skipTransform = config.skipTransform; 3478 const relativeTo = config.relativeTo; 3479 let minX, minY, maxX, maxY; 3480 let selfRect = { 274 3481 x: Infinity, 275 3482 y: Infinity, … … 277 3484 height: 0 278 3485 }; 279 varthat = this;3486 const that = this; 280 3487 (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function(child) { 281 3488 if (!child.visible()) { 282 3489 return; 283 3490 } 284 varrect = child.getClientRect({3491 const rect = child.getClientRect({ 285 3492 relativeTo: that, 286 3493 skipShadow: config.skipShadow, … … 302 3509 } 303 3510 }); 304 varshapes = this.find("Shape");305 varhasVisible = false;306 for ( vari = 0; i < shapes.length; i++) {307 varshape = shapes[i];3511 const shapes = this.find("Shape"); 3512 let hasVisible = false; 3513 for (let i = 0; i < shapes.length; i++) { 3514 const shape = shapes[i]; 308 3515 if (shape._isVisible(this)) { 309 3516 hasVisible = true; … … 344 3551 Factory_1.Factory.addGetterSetter(Container, "clipHeight", void 0, (0, Validators_1.getNumberValidator)()); 345 3552 Factory_1.Factory.addGetterSetter(Container, "clipFunc"); 3553 } 3554 }); 3555 3556 // node_modules/konva/lib/PointerEvents.js 3557 var require_PointerEvents = __commonJS({ 3558 "node_modules/konva/lib/PointerEvents.js"(exports) { 3559 "use strict"; 3560 Object.defineProperty(exports, "__esModule", { value: true }); 3561 exports.getCapturedShape = getCapturedShape; 3562 exports.createEvent = createEvent; 3563 exports.hasPointerCapture = hasPointerCapture; 3564 exports.setPointerCapture = setPointerCapture; 3565 exports.releaseCapture = releaseCapture; 3566 var Global_1 = require_Global(); 3567 var Captures = /* @__PURE__ */ new Map(); 3568 var SUPPORT_POINTER_EVENTS = Global_1.Konva._global["PointerEvent"] !== void 0; 3569 function getCapturedShape(pointerId) { 3570 return Captures.get(pointerId); 3571 } 3572 function createEvent(evt) { 3573 return { 3574 evt, 3575 pointerId: evt.pointerId 3576 }; 3577 } 3578 function hasPointerCapture(pointerId, shape) { 3579 return Captures.get(pointerId) === shape; 3580 } 3581 function setPointerCapture(pointerId, shape) { 3582 releaseCapture(pointerId); 3583 const stage = shape.getStage(); 3584 if (!stage) 3585 return; 3586 Captures.set(pointerId, shape); 3587 if (SUPPORT_POINTER_EVENTS) { 3588 shape._fire("gotpointercapture", createEvent(new PointerEvent("gotpointercapture"))); 3589 } 3590 } 3591 function releaseCapture(pointerId, target) { 3592 const shape = Captures.get(pointerId); 3593 if (!shape) 3594 return; 3595 const stage = shape.getStage(); 3596 if (stage && stage.content) { 3597 } 3598 Captures.delete(pointerId); 3599 if (SUPPORT_POINTER_EVENTS) { 3600 shape._fire("lostpointercapture", createEvent(new PointerEvent("lostpointercapture"))); 3601 } 3602 } 346 3603 } 347 3604 }); … … 506 3763 if (typeof container === STRING) { 507 3764 if (container.charAt(0) === ".") { 508 varclassName = container.slice(1);3765 const className = container.slice(1); 509 3766 container = document.getElementsByClassName(className)[0]; 510 3767 } else { … … 534 3791 } 535 3792 clear() { 536 varlayers = this.children, len = layers.length, n;3793 let layers = this.children, len = layers.length, n; 537 3794 for (n = 0; n < len; n++) { 538 3795 layers[n].clear(); … … 549 3806 destroy() { 550 3807 super.destroy(); 551 varcontent = this.content;3808 const content = this.content; 552 3809 if (content && Util_1.Util._isInDocument(content)) { 553 3810 this.container().removeChild(content); 554 3811 } 555 varindex = exports.stages.indexOf(this);3812 const index = exports.stages.indexOf(this); 556 3813 if (index > -1) { 557 3814 exports.stages.splice(index, 1); … … 589 3846 config.width = config.width || this.width(); 590 3847 config.height = config.height || this.height(); 591 varcanvas = new Canvas_1.SceneCanvas({3848 const canvas = new Canvas_1.SceneCanvas({ 592 3849 width: config.width, 593 3850 height: config.height, 594 3851 pixelRatio: config.pixelRatio || 1 595 3852 }); 596 var_context = canvas.getContext()._context;597 varlayers = this.children;3853 const _context = canvas.getContext()._context; 3854 const layers = this.children; 598 3855 if (config.x || config.y) { 599 3856 _context.translate(-1 * config.x, -1 * config.y); … … 603 3860 return; 604 3861 } 605 varlayerCanvas = layer._toKonvaCanvas(config);3862 const layerCanvas = layer._toKonvaCanvas(config); 606 3863 _context.drawImage(layerCanvas._canvas, config.x, config.y, layerCanvas.getWidth() / layerCanvas.getPixelRatio(), layerCanvas.getHeight() / layerCanvas.getPixelRatio()); 607 3864 }); … … 612 3869 return null; 613 3870 } 614 varlayers = this.children, len = layers.length, end = len - 1, n;3871 let layers = this.children, len = layers.length, end = len - 1, n; 615 3872 for (n = end; n >= 0; n--) { 616 3873 const shape = layers[n].getIntersection(pos); … … 622 3879 } 623 3880 _resizeDOM() { 624 varwidth = this.width();625 varheight = this.height();3881 const width = this.width(); 3882 const height = this.height(); 626 3883 if (this.content) { 627 3884 this.content.style.width = width + PX; … … 637 3894 add(layer, ...rest) { 638 3895 if (arguments.length > 1) { 639 for ( vari = 0; i < arguments.length; i++) {3896 for (let i = 0; i < arguments.length; i++) { 640 3897 this.add(arguments[i]); 641 3898 } … … 643 3900 } 644 3901 super.add(layer); 645 varlength = this.children.length;3902 const length = this.children.length; 646 3903 if (length > MAX_LAYERS_NUMBER) { 647 3904 Util_1.Util.warn("The stage has " + length + " layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group."); … … 718 3975 } 719 3976 this.setPointersPositions(evt); 720 vartargetShape = this._getTargetShape(eventType);721 vareventsEnabled = !(Global_1.Konva.isDragging() || Global_1.Konva.isTransforming()) || Global_1.Konva.hitOnDragEnabled;3977 const targetShape = this._getTargetShape(eventType); 3978 const eventsEnabled = !(Global_1.Konva.isDragging() || Global_1.Konva.isTransforming()) || Global_1.Konva.hitOnDragEnabled; 722 3979 if (targetShape && eventsEnabled) { 723 3980 targetShape._fireAndBubble(events.pointerout, { evt }); … … 751 4008 } 752 4009 this.setPointersPositions(evt); 753 vartriggeredOnShape = false;4010 let triggeredOnShape = false; 754 4011 this._changedPointerPositions.forEach((pos) => { 755 varshape = this.getIntersection(pos);4012 const shape = this.getIntersection(pos); 756 4013 DragAndDrop_1.DD.justDragged = false; 757 4014 Global_1.Konva["_" + eventType + "ListenClick"] = true; … … 793 4050 } 794 4051 this.setPointersPositions(evt); 795 vareventsEnabled = !(Global_1.Konva.isDragging() || Global_1.Konva.isTransforming()) || Global_1.Konva.hitOnDragEnabled;4052 const eventsEnabled = !(Global_1.Konva.isDragging() || Global_1.Konva.isTransforming()) || Global_1.Konva.hitOnDragEnabled; 796 4053 if (!eventsEnabled) { 797 4054 return; 798 4055 } 799 varprocessedShapesIds = {};4056 const processedShapesIds = {}; 800 4057 let triggeredOnShape = false; 801 vartargetShape = this._getTargetShape(eventType);4058 const targetShape = this._getTargetShape(eventType); 802 4059 this._changedPointerPositions.forEach((pos) => { 803 4060 const shape = PointerEvents.getCapturedShape(pos.id) || this.getIntersection(pos); 804 4061 const pointerId = pos.id; 805 4062 const event = { evt, pointerId }; 806 vardifferentTarget = targetShape !== shape;4063 const differentTarget = targetShape !== shape; 807 4064 if (differentTarget && targetShape) { 808 4065 targetShape._fireAndBubble(events.pointerout, { ...event }, shape); … … 853 4110 const clickStartShape = this[eventType + "ClickStartShape"]; 854 4111 const clickEndShape = this[eventType + "ClickEndShape"]; 855 varprocessedShapesIds = {};4112 const processedShapesIds = {}; 856 4113 let triggeredOnShape = false; 857 4114 this._changedPointerPositions.forEach((pos) => { … … 922 4179 _contextmenu(evt) { 923 4180 this.setPointersPositions(evt); 924 varshape = this.getIntersection(this.getPointerPosition());4181 const shape = this.getIntersection(this.getPointerPosition()); 925 4182 if (shape && shape.isListening()) { 926 4183 shape._fireAndBubble(CONTEXTMENU, { evt }); … … 935 4192 _wheel(evt) { 936 4193 this.setPointersPositions(evt); 937 varshape = this.getIntersection(this.getPointerPosition());4194 const shape = this.getIntersection(this.getPointerPosition()); 938 4195 if (shape && shape.isListening()) { 939 4196 shape._fireAndBubble(WHEEL, { evt }); … … 958 4215 } 959 4216 setPointersPositions(evt) { 960 varcontentPosition = this._getContentPosition(), x = null, y = null;4217 let contentPosition = this._getContentPosition(), x = null, y = null; 961 4218 evt = evt ? evt : window.event; 962 4219 if (evt.touches !== void 0) { … … 1003 4260 }; 1004 4261 } 1005 varrect = this.content.getBoundingClientRect();4262 const rect = this.content.getBoundingClientRect(); 1006 4263 return { 1007 4264 top: rect.top, … … 1024 4281 return; 1025 4282 } 1026 varcontainer = this.container();4283 const container = this.container(); 1027 4284 if (!container) { 1028 4285 throw "Stage has no container. A container is required."; … … 1062 4319 }); 1063 4320 } 4321 } 4322 }); 4323 4324 // node_modules/konva/lib/Shape.js 4325 var require_Shape = __commonJS({ 4326 "node_modules/konva/lib/Shape.js"(exports) { 4327 "use strict"; 4328 Object.defineProperty(exports, "__esModule", { value: true }); 4329 exports.Shape = exports.shapes = void 0; 4330 var Global_1 = require_Global(); 4331 var Util_1 = require_Util(); 4332 var Factory_1 = require_Factory(); 4333 var Node_1 = require_Node(); 4334 var Validators_1 = require_Validators(); 4335 var Global_2 = require_Global(); 4336 var PointerEvents = require_PointerEvents(); 4337 var HAS_SHADOW = "hasShadow"; 4338 var SHADOW_RGBA = "shadowRGBA"; 4339 var patternImage = "patternImage"; 4340 var linearGradient = "linearGradient"; 4341 var radialGradient = "radialGradient"; 4342 var dummyContext; 4343 function getDummyContext() { 4344 if (dummyContext) { 4345 return dummyContext; 4346 } 4347 dummyContext = Util_1.Util.createCanvasElement().getContext("2d"); 4348 return dummyContext; 4349 } 4350 exports.shapes = {}; 4351 function _fillFunc(context) { 4352 const fillRule = this.attrs.fillRule; 4353 if (fillRule) { 4354 context.fill(fillRule); 4355 } else { 4356 context.fill(); 4357 } 4358 } 4359 function _strokeFunc(context) { 4360 context.stroke(); 4361 } 4362 function _fillFuncHit(context) { 4363 const fillRule = this.attrs.fillRule; 4364 if (fillRule) { 4365 context.fill(fillRule); 4366 } else { 4367 context.fill(); 4368 } 4369 } 4370 function _strokeFuncHit(context) { 4371 context.stroke(); 4372 } 4373 function _clearHasShadowCache() { 4374 this._clearCache(HAS_SHADOW); 4375 } 4376 function _clearGetShadowRGBACache() { 4377 this._clearCache(SHADOW_RGBA); 4378 } 4379 function _clearFillPatternCache() { 4380 this._clearCache(patternImage); 4381 } 4382 function _clearLinearGradientCache() { 4383 this._clearCache(linearGradient); 4384 } 4385 function _clearRadialGradientCache() { 4386 this._clearCache(radialGradient); 4387 } 4388 var Shape = class extends Node_1.Node { 4389 constructor(config) { 4390 super(config); 4391 let key; 4392 while (true) { 4393 key = Util_1.Util.getRandomColor(); 4394 if (key && !(key in exports.shapes)) { 4395 break; 4396 } 4397 } 4398 this.colorKey = key; 4399 exports.shapes[key] = this; 4400 } 4401 getContext() { 4402 Util_1.Util.warn("shape.getContext() method is deprecated. Please do not use it."); 4403 return this.getLayer().getContext(); 4404 } 4405 getCanvas() { 4406 Util_1.Util.warn("shape.getCanvas() method is deprecated. Please do not use it."); 4407 return this.getLayer().getCanvas(); 4408 } 4409 getSceneFunc() { 4410 return this.attrs.sceneFunc || this["_sceneFunc"]; 4411 } 4412 getHitFunc() { 4413 return this.attrs.hitFunc || this["_hitFunc"]; 4414 } 4415 hasShadow() { 4416 return this._getCache(HAS_SHADOW, this._hasShadow); 4417 } 4418 _hasShadow() { 4419 return this.shadowEnabled() && this.shadowOpacity() !== 0 && !!(this.shadowColor() || this.shadowBlur() || this.shadowOffsetX() || this.shadowOffsetY()); 4420 } 4421 _getFillPattern() { 4422 return this._getCache(patternImage, this.__getFillPattern); 4423 } 4424 __getFillPattern() { 4425 if (this.fillPatternImage()) { 4426 const ctx = getDummyContext(); 4427 const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || "repeat"); 4428 if (pattern && pattern.setTransform) { 4429 const tr = new Util_1.Transform(); 4430 tr.translate(this.fillPatternX(), this.fillPatternY()); 4431 tr.rotate(Global_1.Konva.getAngle(this.fillPatternRotation())); 4432 tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY()); 4433 tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY()); 4434 const m = tr.getMatrix(); 4435 const matrix = typeof DOMMatrix === "undefined" ? { 4436 a: m[0], 4437 b: m[1], 4438 c: m[2], 4439 d: m[3], 4440 e: m[4], 4441 f: m[5] 4442 } : new DOMMatrix(m); 4443 pattern.setTransform(matrix); 4444 } 4445 return pattern; 4446 } 4447 } 4448 _getLinearGradient() { 4449 return this._getCache(linearGradient, this.__getLinearGradient); 4450 } 4451 __getLinearGradient() { 4452 const colorStops = this.fillLinearGradientColorStops(); 4453 if (colorStops) { 4454 const ctx = getDummyContext(); 4455 const start = this.fillLinearGradientStartPoint(); 4456 const end = this.fillLinearGradientEndPoint(); 4457 const grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y); 4458 for (let n = 0; n < colorStops.length; n += 2) { 4459 grd.addColorStop(colorStops[n], colorStops[n + 1]); 4460 } 4461 return grd; 4462 } 4463 } 4464 _getRadialGradient() { 4465 return this._getCache(radialGradient, this.__getRadialGradient); 4466 } 4467 __getRadialGradient() { 4468 const colorStops = this.fillRadialGradientColorStops(); 4469 if (colorStops) { 4470 const ctx = getDummyContext(); 4471 const start = this.fillRadialGradientStartPoint(); 4472 const end = this.fillRadialGradientEndPoint(); 4473 const grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius()); 4474 for (let n = 0; n < colorStops.length; n += 2) { 4475 grd.addColorStop(colorStops[n], colorStops[n + 1]); 4476 } 4477 return grd; 4478 } 4479 } 4480 getShadowRGBA() { 4481 return this._getCache(SHADOW_RGBA, this._getShadowRGBA); 4482 } 4483 _getShadowRGBA() { 4484 if (!this.hasShadow()) { 4485 return; 4486 } 4487 const rgba = Util_1.Util.colorToRGBA(this.shadowColor()); 4488 if (rgba) { 4489 return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a * (this.shadowOpacity() || 1) + ")"; 4490 } 4491 } 4492 hasFill() { 4493 return this._calculate("hasFill", [ 4494 "fillEnabled", 4495 "fill", 4496 "fillPatternImage", 4497 "fillLinearGradientColorStops", 4498 "fillRadialGradientColorStops" 4499 ], () => { 4500 return this.fillEnabled() && !!(this.fill() || this.fillPatternImage() || this.fillLinearGradientColorStops() || this.fillRadialGradientColorStops()); 4501 }); 4502 } 4503 hasStroke() { 4504 return this._calculate("hasStroke", [ 4505 "strokeEnabled", 4506 "strokeWidth", 4507 "stroke", 4508 "strokeLinearGradientColorStops" 4509 ], () => { 4510 return this.strokeEnabled() && this.strokeWidth() && !!(this.stroke() || this.strokeLinearGradientColorStops()); 4511 }); 4512 } 4513 hasHitStroke() { 4514 const width = this.hitStrokeWidth(); 4515 if (width === "auto") { 4516 return this.hasStroke(); 4517 } 4518 return this.strokeEnabled() && !!width; 4519 } 4520 intersects(point) { 4521 const stage = this.getStage(); 4522 if (!stage) { 4523 return false; 4524 } 4525 const bufferHitCanvas = stage.bufferHitCanvas; 4526 bufferHitCanvas.getContext().clear(); 4527 this.drawHit(bufferHitCanvas, void 0, true); 4528 const p = bufferHitCanvas.context.getImageData(Math.round(point.x), Math.round(point.y), 1, 1).data; 4529 return p[3] > 0; 4530 } 4531 destroy() { 4532 Node_1.Node.prototype.destroy.call(this); 4533 delete exports.shapes[this.colorKey]; 4534 delete this.colorKey; 4535 return this; 4536 } 4537 _useBufferCanvas(forceFill) { 4538 var _a; 4539 const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true; 4540 if (!perfectDrawEnabled) { 4541 return false; 4542 } 4543 const hasFill = forceFill || this.hasFill(); 4544 const hasStroke = this.hasStroke(); 4545 const isTransparent = this.getAbsoluteOpacity() !== 1; 4546 if (hasFill && hasStroke && isTransparent) { 4547 return true; 4548 } 4549 const hasShadow = this.hasShadow(); 4550 const strokeForShadow = this.shadowForStrokeEnabled(); 4551 if (hasFill && hasStroke && hasShadow && strokeForShadow) { 4552 return true; 4553 } 4554 return false; 4555 } 4556 setStrokeHitEnabled(val) { 4557 Util_1.Util.warn("strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead."); 4558 if (val) { 4559 this.hitStrokeWidth("auto"); 4560 } else { 4561 this.hitStrokeWidth(0); 4562 } 4563 } 4564 getStrokeHitEnabled() { 4565 if (this.hitStrokeWidth() === 0) { 4566 return false; 4567 } else { 4568 return true; 4569 } 4570 } 4571 getSelfRect() { 4572 const size = this.size(); 4573 return { 4574 x: this._centroid ? -size.width / 2 : 0, 4575 y: this._centroid ? -size.height / 2 : 0, 4576 width: size.width, 4577 height: size.height 4578 }; 4579 } 4580 getClientRect(config = {}) { 4581 let hasCachedParent = false; 4582 let parent = this.getParent(); 4583 while (parent) { 4584 if (parent.isCached()) { 4585 hasCachedParent = true; 4586 break; 4587 } 4588 parent = parent.getParent(); 4589 } 4590 const skipTransform = config.skipTransform; 4591 const relativeTo = config.relativeTo || hasCachedParent && this.getStage() || void 0; 4592 const fillRect = this.getSelfRect(); 4593 const applyStroke = !config.skipStroke && this.hasStroke(); 4594 const strokeWidth = applyStroke && this.strokeWidth() || 0; 4595 const fillAndStrokeWidth = fillRect.width + strokeWidth; 4596 const fillAndStrokeHeight = fillRect.height + strokeWidth; 4597 const applyShadow = !config.skipShadow && this.hasShadow(); 4598 const shadowOffsetX = applyShadow ? this.shadowOffsetX() : 0; 4599 const shadowOffsetY = applyShadow ? this.shadowOffsetY() : 0; 4600 const preWidth = fillAndStrokeWidth + Math.abs(shadowOffsetX); 4601 const preHeight = fillAndStrokeHeight + Math.abs(shadowOffsetY); 4602 const blurRadius = applyShadow && this.shadowBlur() || 0; 4603 const width = preWidth + blurRadius * 2; 4604 const height = preHeight + blurRadius * 2; 4605 const rect = { 4606 width, 4607 height, 4608 x: -(strokeWidth / 2 + blurRadius) + Math.min(shadowOffsetX, 0) + fillRect.x, 4609 y: -(strokeWidth / 2 + blurRadius) + Math.min(shadowOffsetY, 0) + fillRect.y 4610 }; 4611 if (!skipTransform) { 4612 return this._transformedRect(rect, relativeTo); 4613 } 4614 return rect; 4615 } 4616 drawScene(can, top, bufferCanvas) { 4617 const layer = this.getLayer(); 4618 let canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext; 4619 const skipBuffer = canvas.isCache; 4620 const cachingSelf = top === this; 4621 if (!this.isVisible() && !cachingSelf) { 4622 return this; 4623 } 4624 if (cachedCanvas) { 4625 context.save(); 4626 const m = this.getAbsoluteTransform(top).getMatrix(); 4627 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 4628 this._drawCachedSceneCanvas(context); 4629 context.restore(); 4630 return this; 4631 } 4632 if (!drawFunc) { 4633 return this; 4634 } 4635 context.save(); 4636 if (this._useBufferCanvas() && !skipBuffer) { 4637 stage = this.getStage(); 4638 const bc = bufferCanvas || stage.bufferCanvas; 4639 bufferContext = bc.getContext(); 4640 bufferContext.clear(); 4641 bufferContext.save(); 4642 bufferContext._applyLineJoin(this); 4643 var o = this.getAbsoluteTransform(top).getMatrix(); 4644 bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]); 4645 drawFunc.call(this, bufferContext, this); 4646 bufferContext.restore(); 4647 const ratio = bc.pixelRatio; 4648 if (hasShadow) { 4649 context._applyShadow(this); 4650 } 4651 context._applyOpacity(this); 4652 context._applyGlobalCompositeOperation(this); 4653 context.drawImage(bc._canvas, 0, 0, bc.width / ratio, bc.height / ratio); 4654 } else { 4655 context._applyLineJoin(this); 4656 if (!cachingSelf) { 4657 var o = this.getAbsoluteTransform(top).getMatrix(); 4658 context.transform(o[0], o[1], o[2], o[3], o[4], o[5]); 4659 context._applyOpacity(this); 4660 context._applyGlobalCompositeOperation(this); 4661 } 4662 if (hasShadow) { 4663 context._applyShadow(this); 4664 } 4665 drawFunc.call(this, context, this); 4666 } 4667 context.restore(); 4668 return this; 4669 } 4670 drawHit(can, top, skipDragCheck = false) { 4671 if (!this.shouldDrawHit(top, skipDragCheck)) { 4672 return this; 4673 } 4674 const layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit; 4675 if (!this.colorKey) { 4676 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()"); 4677 } 4678 if (cachedHitCanvas) { 4679 context.save(); 4680 const m = this.getAbsoluteTransform(top).getMatrix(); 4681 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 4682 this._drawCachedHitCanvas(context); 4683 context.restore(); 4684 return this; 4685 } 4686 if (!drawFunc) { 4687 return this; 4688 } 4689 context.save(); 4690 context._applyLineJoin(this); 4691 const selfCache = this === top; 4692 if (!selfCache) { 4693 const o = this.getAbsoluteTransform(top).getMatrix(); 4694 context.transform(o[0], o[1], o[2], o[3], o[4], o[5]); 4695 } 4696 drawFunc.call(this, context, this); 4697 context.restore(); 4698 return this; 4699 } 4700 drawHitFromCache(alphaThreshold = 0) { 4701 let cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha; 4702 hitContext.clear(); 4703 hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight); 4704 try { 4705 hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight); 4706 hitData = hitImageData.data; 4707 len = hitData.length; 4708 rgbColorKey = Util_1.Util._hexToRgb(this.colorKey); 4709 for (i = 0; i < len; i += 4) { 4710 alpha = hitData[i + 3]; 4711 if (alpha > alphaThreshold) { 4712 hitData[i] = rgbColorKey.r; 4713 hitData[i + 1] = rgbColorKey.g; 4714 hitData[i + 2] = rgbColorKey.b; 4715 hitData[i + 3] = 255; 4716 } else { 4717 hitData[i + 3] = 0; 4718 } 4719 } 4720 hitContext.putImageData(hitImageData, 0, 0); 4721 } catch (e) { 4722 Util_1.Util.error("Unable to draw hit graph from cached scene canvas. " + e.message); 4723 } 4724 return this; 4725 } 4726 hasPointerCapture(pointerId) { 4727 return PointerEvents.hasPointerCapture(pointerId, this); 4728 } 4729 setPointerCapture(pointerId) { 4730 PointerEvents.setPointerCapture(pointerId, this); 4731 } 4732 releaseCapture(pointerId) { 4733 PointerEvents.releaseCapture(pointerId, this); 4734 } 4735 }; 4736 exports.Shape = Shape; 4737 Shape.prototype._fillFunc = _fillFunc; 4738 Shape.prototype._strokeFunc = _strokeFunc; 4739 Shape.prototype._fillFuncHit = _fillFuncHit; 4740 Shape.prototype._strokeFuncHit = _strokeFuncHit; 4741 Shape.prototype._centroid = false; 4742 Shape.prototype.nodeType = "Shape"; 4743 (0, Global_2._registerNode)(Shape); 4744 Shape.prototype.eventListeners = {}; 4745 Shape.prototype.on.call(Shape.prototype, "shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva", _clearHasShadowCache); 4746 Shape.prototype.on.call(Shape.prototype, "shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva", _clearGetShadowRGBACache); 4747 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); 4748 Shape.prototype.on.call(Shape.prototype, "fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva", _clearLinearGradientCache); 4749 Shape.prototype.on.call(Shape.prototype, "fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva", _clearRadialGradientCache); 4750 Factory_1.Factory.addGetterSetter(Shape, "stroke", void 0, (0, Validators_1.getStringOrGradientValidator)()); 4751 Factory_1.Factory.addGetterSetter(Shape, "strokeWidth", 2, (0, Validators_1.getNumberValidator)()); 4752 Factory_1.Factory.addGetterSetter(Shape, "fillAfterStrokeEnabled", false); 4753 Factory_1.Factory.addGetterSetter(Shape, "hitStrokeWidth", "auto", (0, Validators_1.getNumberOrAutoValidator)()); 4754 Factory_1.Factory.addGetterSetter(Shape, "strokeHitEnabled", true, (0, Validators_1.getBooleanValidator)()); 4755 Factory_1.Factory.addGetterSetter(Shape, "perfectDrawEnabled", true, (0, Validators_1.getBooleanValidator)()); 4756 Factory_1.Factory.addGetterSetter(Shape, "shadowForStrokeEnabled", true, (0, Validators_1.getBooleanValidator)()); 4757 Factory_1.Factory.addGetterSetter(Shape, "lineJoin"); 4758 Factory_1.Factory.addGetterSetter(Shape, "lineCap"); 4759 Factory_1.Factory.addGetterSetter(Shape, "sceneFunc"); 4760 Factory_1.Factory.addGetterSetter(Shape, "hitFunc"); 4761 Factory_1.Factory.addGetterSetter(Shape, "dash"); 4762 Factory_1.Factory.addGetterSetter(Shape, "dashOffset", 0, (0, Validators_1.getNumberValidator)()); 4763 Factory_1.Factory.addGetterSetter(Shape, "shadowColor", void 0, (0, Validators_1.getStringValidator)()); 4764 Factory_1.Factory.addGetterSetter(Shape, "shadowBlur", 0, (0, Validators_1.getNumberValidator)()); 4765 Factory_1.Factory.addGetterSetter(Shape, "shadowOpacity", 1, (0, Validators_1.getNumberValidator)()); 4766 Factory_1.Factory.addComponentsGetterSetter(Shape, "shadowOffset", ["x", "y"]); 4767 Factory_1.Factory.addGetterSetter(Shape, "shadowOffsetX", 0, (0, Validators_1.getNumberValidator)()); 4768 Factory_1.Factory.addGetterSetter(Shape, "shadowOffsetY", 0, (0, Validators_1.getNumberValidator)()); 4769 Factory_1.Factory.addGetterSetter(Shape, "fillPatternImage"); 4770 Factory_1.Factory.addGetterSetter(Shape, "fill", void 0, (0, Validators_1.getStringOrGradientValidator)()); 4771 Factory_1.Factory.addGetterSetter(Shape, "fillPatternX", 0, (0, Validators_1.getNumberValidator)()); 4772 Factory_1.Factory.addGetterSetter(Shape, "fillPatternY", 0, (0, Validators_1.getNumberValidator)()); 4773 Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientColorStops"); 4774 Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientColorStops"); 4775 Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientStartRadius", 0); 4776 Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientEndRadius", 0); 4777 Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientColorStops"); 4778 Factory_1.Factory.addGetterSetter(Shape, "fillPatternRepeat", "repeat"); 4779 Factory_1.Factory.addGetterSetter(Shape, "fillEnabled", true); 4780 Factory_1.Factory.addGetterSetter(Shape, "strokeEnabled", true); 4781 Factory_1.Factory.addGetterSetter(Shape, "shadowEnabled", true); 4782 Factory_1.Factory.addGetterSetter(Shape, "dashEnabled", true); 4783 Factory_1.Factory.addGetterSetter(Shape, "strokeScaleEnabled", true); 4784 Factory_1.Factory.addGetterSetter(Shape, "fillPriority", "color"); 4785 Factory_1.Factory.addComponentsGetterSetter(Shape, "fillPatternOffset", ["x", "y"]); 4786 Factory_1.Factory.addGetterSetter(Shape, "fillPatternOffsetX", 0, (0, Validators_1.getNumberValidator)()); 4787 Factory_1.Factory.addGetterSetter(Shape, "fillPatternOffsetY", 0, (0, Validators_1.getNumberValidator)()); 4788 Factory_1.Factory.addComponentsGetterSetter(Shape, "fillPatternScale", ["x", "y"]); 4789 Factory_1.Factory.addGetterSetter(Shape, "fillPatternScaleX", 1, (0, Validators_1.getNumberValidator)()); 4790 Factory_1.Factory.addGetterSetter(Shape, "fillPatternScaleY", 1, (0, Validators_1.getNumberValidator)()); 4791 Factory_1.Factory.addComponentsGetterSetter(Shape, "fillLinearGradientStartPoint", [ 4792 "x", 4793 "y" 4794 ]); 4795 Factory_1.Factory.addComponentsGetterSetter(Shape, "strokeLinearGradientStartPoint", [ 4796 "x", 4797 "y" 4798 ]); 4799 Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientStartPointX", 0); 4800 Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientStartPointX", 0); 4801 Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientStartPointY", 0); 4802 Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientStartPointY", 0); 4803 Factory_1.Factory.addComponentsGetterSetter(Shape, "fillLinearGradientEndPoint", [ 4804 "x", 4805 "y" 4806 ]); 4807 Factory_1.Factory.addComponentsGetterSetter(Shape, "strokeLinearGradientEndPoint", [ 4808 "x", 4809 "y" 4810 ]); 4811 Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientEndPointX", 0); 4812 Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientEndPointX", 0); 4813 Factory_1.Factory.addGetterSetter(Shape, "fillLinearGradientEndPointY", 0); 4814 Factory_1.Factory.addGetterSetter(Shape, "strokeLinearGradientEndPointY", 0); 4815 Factory_1.Factory.addComponentsGetterSetter(Shape, "fillRadialGradientStartPoint", [ 4816 "x", 4817 "y" 4818 ]); 4819 Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientStartPointX", 0); 4820 Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientStartPointY", 0); 4821 Factory_1.Factory.addComponentsGetterSetter(Shape, "fillRadialGradientEndPoint", [ 4822 "x", 4823 "y" 4824 ]); 4825 Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientEndPointX", 0); 4826 Factory_1.Factory.addGetterSetter(Shape, "fillRadialGradientEndPointY", 0); 4827 Factory_1.Factory.addGetterSetter(Shape, "fillPatternRotation", 0); 4828 Factory_1.Factory.addGetterSetter(Shape, "fillRule", void 0, (0, Validators_1.getStringValidator)()); 4829 Factory_1.Factory.backCompat(Shape, { 4830 dashArray: "dash", 4831 getDashArray: "getDash", 4832 setDashArray: "getDash", 4833 drawFunc: "sceneFunc", 4834 getDrawFunc: "getSceneFunc", 4835 setDrawFunc: "setSceneFunc", 4836 drawHitFunc: "hitFunc", 4837 getDrawHitFunc: "getHitFunc", 4838 setDrawHitFunc: "setHitFunc" 4839 }); 1064 4840 } 1065 4841 }); … … 1126 4902 setZIndex(index) { 1127 4903 super.setZIndex(index); 1128 varstage = this.getStage();4904 const stage = this.getStage(); 1129 4905 if (stage && stage.content) { 1130 4906 stage.content.removeChild(this.getNativeCanvasElement()); … … 1139 4915 moveToTop() { 1140 4916 Node_1.Node.prototype.moveToTop.call(this); 1141 varstage = this.getStage();4917 const stage = this.getStage(); 1142 4918 if (stage && stage.content) { 1143 4919 stage.content.removeChild(this.getNativeCanvasElement()); … … 1147 4923 } 1148 4924 moveUp() { 1149 varmoved = Node_1.Node.prototype.moveUp.call(this);4925 const moved = Node_1.Node.prototype.moveUp.call(this); 1150 4926 if (!moved) { 1151 4927 return false; 1152 4928 } 1153 varstage = this.getStage();4929 const stage = this.getStage(); 1154 4930 if (!stage || !stage.content) { 1155 4931 return false; … … 1165 4941 moveDown() { 1166 4942 if (Node_1.Node.prototype.moveDown.call(this)) { 1167 varstage = this.getStage();4943 const stage = this.getStage(); 1168 4944 if (stage) { 1169 varchildren = stage.children;4945 const children = stage.children; 1170 4946 if (stage.content) { 1171 4947 stage.content.removeChild(this.getNativeCanvasElement()); … … 1179 4955 moveToBottom() { 1180 4956 if (Node_1.Node.prototype.moveToBottom.call(this)) { 1181 varstage = this.getStage();4957 const stage = this.getStage(); 1182 4958 if (stage) { 1183 varchildren = stage.children;4959 const children = stage.children; 1184 4960 if (stage.content) { 1185 4961 stage.content.removeChild(this.getNativeCanvasElement()); … … 1195 4971 } 1196 4972 remove() { 1197 var_canvas = this.getNativeCanvasElement();4973 const _canvas = this.getNativeCanvasElement(); 1198 4974 Node_1.Node.prototype.remove.call(this); 1199 4975 if (_canvas && _canvas.parentNode && Util_1.Util._isInDocument(_canvas)) { … … 1212 4988 } 1213 4989 _validateAdd(child) { 1214 vartype = child.getType();4990 const type = child.getType(); 1215 4991 if (type !== "Group" && type !== "Shape") { 1216 4992 Util_1.Util.throw("You may only add groups and shapes to a layer."); … … 1266 5042 return null; 1267 5043 } 1268 varspiralSearchDistance = 1;1269 varcontinueSearch = false;5044 let spiralSearchDistance = 1; 5045 let continueSearch = false; 1270 5046 while (true) { 1271 5047 for (let i = 0; i < INTERSECTION_OFFSETS_LEN; i++) { … … 1314 5090 } 1315 5091 drawScene(can, top) { 1316 varlayer = this.getLayer(), canvas = can || layer && layer.getCanvas();5092 const layer = this.getLayer(), canvas = can || layer && layer.getCanvas(); 1317 5093 this._fire(BEFORE_DRAW, { 1318 5094 node: this … … 1328 5104 } 1329 5105 drawHit(can, top) { 1330 varlayer = this.getLayer(), canvas = can || layer && layer.hitCanvas;5106 const layer = this.getLayer(), canvas = can || layer && layer.hitCanvas; 1331 5107 if (layer && layer.clearBeforeDraw()) { 1332 5108 layer.getHitCanvas().getContext().clear(); … … 1355 5131 return; 1356 5132 } 1357 varparent = this.parent;1358 varadded = !!this.hitCanvas._canvas.parentNode;5133 const parent = this.parent; 5134 const added = !!this.hitCanvas._canvas.parentNode; 1359 5135 if (added) { 1360 5136 parent.content.removeChild(this.hitCanvas._canvas); … … 1410 5186 var Group = class extends Container_1.Container { 1411 5187 _validateAdd(child) { 1412 vartype = child.getType();5188 const type = child.getType(); 1413 5189 if (type !== "Group" && type !== "Shape") { 1414 5190 Util_1.Util.throw("You may only add groups and shapes to groups."); … … 1542 5318 } 1543 5319 } 1544 for ( let key in layerHash) {5320 for (const key in layerHash) { 1545 5321 if (!layerHash.hasOwnProperty(key)) { 1546 5322 continue; … … 1613 5389 } 1614 5390 fire(str) { 1615 varhandler = this[str];5391 const handler = this[str]; 1616 5392 if (handler) { 1617 5393 handler(); … … 1688 5464 } 1689 5465 onEnterFrame() { 1690 vart = this.getTimer() - this._startTime;5466 const t = this.getTimer() - this._startTime; 1691 5467 if (this.state === PLAYING) { 1692 5468 this.setTime(t); … … 1705 5481 var Tween = class _Tween { 1706 5482 constructor(config) { 1707 varthat = this, node = config.node, nodeId = node._id, duration, easing = config.easing || exports.Easings.Linear, yoyo = !!config.yoyo, key;5483 let that = this, node = config.node, nodeId = node._id, duration, easing = config.easing || exports.Easings.Linear, yoyo = !!config.yoyo, key; 1708 5484 if (typeof config.duration === "undefined") { 1709 5485 duration = 0.3; … … 1715 5491 this.node = node; 1716 5492 this._id = idCounter++; 1717 varlayers = node.getLayer() || (node instanceof Global_1.Konva["Stage"] ? node.getLayers() : null);5493 const layers = node.getLayer() || (node instanceof Global_1.Konva["Stage"] ? node.getLayers() : null); 1718 5494 if (!layers) { 1719 5495 Util_1.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."); … … 1746 5522 } 1747 5523 _addAttr(key, end) { 1748 varnode = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA;5524 let node = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA; 1749 5525 tweenId = _Tween.tweens[nodeId][key]; 1750 5526 if (tweenId) { … … 1769 5545 diff.push(end[n] - start[n]); 1770 5546 } else { 1771 varstartRGBA = Util_1.Util.colorToRGBA(start[n]);5547 const startRGBA = Util_1.Util.colorToRGBA(start[n]); 1772 5548 endRGBA = Util_1.Util.colorToRGBA(end[n]); 1773 5549 start[n] = startRGBA; … … 1807 5583 } 1808 5584 _tweenFunc(i) { 1809 varnode = this.node, attrs = _Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end;5585 let node = this.node, attrs = _Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end; 1810 5586 for (key in attrs) { 1811 5587 attr = attrs[key]; … … 1848 5624 }; 1849 5625 this.tween.onFinish = () => { 1850 varnode = this.node;1851 varattrs = _Tween.attrs[node._id][this._id];5626 const node = this.node; 5627 const attrs = _Tween.attrs[node._id][this._id]; 1852 5628 if (attrs.points && attrs.points.trueEnd) { 1853 5629 node.setAttr("points", attrs.points.trueEnd); … … 1858 5634 }; 1859 5635 this.tween.onReset = () => { 1860 varnode = this.node;1861 varattrs = _Tween.attrs[node._id][this._id];5636 const node = this.node; 5637 const attrs = _Tween.attrs[node._id][this._id]; 1862 5638 if (attrs.points && attrs.points.trueStart) { 1863 5639 node.points(attrs.points.trueStart); … … 1898 5674 } 1899 5675 destroy() { 1900 varnodeId = this.node._id, thisId = this._id, attrs = _Tween.tweens[nodeId], key;5676 let nodeId = this.node._id, thisId = this._id, attrs = _Tween.tweens[nodeId], key; 1901 5677 this.pause(); 1902 5678 for (key in attrs) { … … 1910 5686 Tween.tweens = {}; 1911 5687 Node_1.Node.prototype.to = function(params) { 1912 varonFinish = params.onFinish;5688 const onFinish = params.onFinish; 1913 5689 params.node = this; 1914 5690 params.onFinish = function() { … … 1918 5694 } 1919 5695 }; 1920 vartween = new Tween(params);5696 const tween = new Tween(params); 1921 5697 tween.play(); 1922 5698 }; 1923 5699 exports.Easings = { 1924 5700 BackEaseIn(t, b, c, d) { 1925 vars = 1.70158;5701 const s = 1.70158; 1926 5702 return c * (t /= d) * t * ((s + 1) * t - s) + b; 1927 5703 }, 1928 5704 BackEaseOut(t, b, c, d) { 1929 vars = 1.70158;5705 const s = 1.70158; 1930 5706 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; 1931 5707 }, 1932 5708 BackEaseInOut(t, b, c, d) { 1933 vars = 1.70158;5709 let s = 1.70158; 1934 5710 if ((t /= d / 2) < 1) { 1935 5711 return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b; … … 1938 5714 }, 1939 5715 ElasticEaseIn(t, b, c, d, a, p) { 1940 vars = 0;5716 let s = 0; 1941 5717 if (t === 0) { 1942 5718 return b; … … 1957 5733 }, 1958 5734 ElasticEaseOut(t, b, c, d, a, p) { 1959 vars = 0;5735 let s = 0; 1960 5736 if (t === 0) { 1961 5737 return b; … … 1976 5752 }, 1977 5753 ElasticEaseInOut(t, b, c, d, a, p) { 1978 vars = 0;5754 let s = 0; 1979 5755 if (t === 0) { 1980 5756 return b; … … 2105 5881 var Arc = class extends Shape_1.Shape { 2106 5882 _sceneFunc(context) { 2107 varangle = Global_1.Konva.getAngle(this.angle()), clockwise = this.clockwise();5883 const angle = Global_1.Konva.getAngle(this.angle()), clockwise = this.clockwise(); 2108 5884 context.beginPath(); 2109 5885 context.arc(0, 0, this.outerRadius(), 0, angle, clockwise); … … 2164 5940 exports.Line = void 0; 2165 5941 var Factory_1 = require_Factory(); 5942 var Global_1 = require_Global(); 2166 5943 var Shape_1 = require_Shape(); 2167 5944 var Validators_1 = require_Validators(); 2168 var Global_1 = require_Global();2169 5945 function getControlPoints(x0, y0, x1, y1, x2, y2, t) { 2170 vard01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = t * d01 / (d01 + d12), fb = t * d12 / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);5946 const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = t * d01 / (d01 + d12), fb = t * d12 / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0); 2171 5947 return [p1x, p1y, p2x, p2y]; 2172 5948 } 2173 5949 function expandPoints(p, tension) { 2174 var len = p.length, allPoints = [], n, cp;2175 for ( n = 2; n < len - 2; n += 2) {2176 c p = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);5950 const len = p.length, allPoints = []; 5951 for (let n = 2; n < len - 2; n += 2) { 5952 const cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension); 2177 5953 if (isNaN(cp[0])) { 2178 5954 continue; … … 2195 5971 } 2196 5972 _sceneFunc(context) { 2197 varpoints = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n;5973 let points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n; 2198 5974 if (!length) { 2199 5975 return; … … 2242 6018 } 2243 6019 _getTensionPointsClosed() { 2244 varp = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]].concat(middle).concat([6020 const p = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]].concat(middle).concat([ 2245 6021 lastControlPoints[0], 2246 6022 lastControlPoints[1], … … 2263 6039 } 2264 6040 getSelfRect() { 2265 varpoints = this.points();6041 let points = this.points(); 2266 6042 if (points.length < 4) { 2267 6043 return { … … 2283 6059 points = this.points(); 2284 6060 } 2285 varminX = points[0];2286 varmaxX = points[0];2287 varminY = points[1];2288 varmaxY = points[1];2289 varx, y;2290 for ( vari = 0; i < points.length / 2; i++) {6061 let minX = points[0]; 6062 let maxX = points[0]; 6063 let minY = points[1]; 6064 let maxY = points[1]; 6065 let x, y; 6066 for (let i = 0; i < points.length / 2; i++) { 2291 6067 x = points[i * 2]; 2292 6068 y = points[i * 2 + 1]; … … 3018 6794 exports.binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]; 3019 6795 var getCubicArcLength = (xs, ys, t) => { 3020 let z;3021 6796 let sum; 3022 6797 let correctedT; 3023 6798 const n = 20; 3024 z = t / 2;6799 const z = t / 2; 3025 6800 sum = 0; 3026 6801 for (let i = 0; i < n; i++) { … … 3139 6914 } 3140 6915 _sceneFunc(context) { 3141 varca = this.dataArray;6916 const ca = this.dataArray; 3142 6917 context.beginPath(); 3143 varisClosed = false;3144 for ( varn = 0; n < ca.length; n++) {3145 varc = ca[n].command;3146 varp = ca[n].points;6918 let isClosed = false; 6919 for (let n = 0; n < ca.length; n++) { 6920 const c = ca[n].command; 6921 const p = ca[n].points; 3147 6922 switch (c) { 3148 6923 case "L": … … 3184 6959 } 3185 6960 getSelfRect() { 3186 varpoints = [];6961 let points = []; 3187 6962 this.dataArray.forEach(function(data) { 3188 6963 if (data.command === "A") { 3189 varstart = data.points[4];3190 vardTheta = data.points[5];3191 varend = data.points[4] + dTheta;3192 varinc = Math.PI / 180;6964 const start = data.points[4]; 6965 const dTheta = data.points[5]; 6966 const end = data.points[4] + dTheta; 6967 let inc = Math.PI / 180; 3193 6968 if (Math.abs(start - end) < inc) { 3194 6969 inc = Math.abs(start - end); … … 3214 6989 } 3215 6990 }); 3216 varminX = points[0];3217 varmaxX = points[0];3218 varminY = points[1];3219 varmaxY = points[1];3220 varx, y;3221 for ( vari = 0; i < points.length / 2; i++) {6991 let minX = points[0]; 6992 let maxX = points[0]; 6993 let minY = points[1]; 6994 let maxY = points[1]; 6995 let x, y; 6996 for (let i = 0; i < points.length / 2; i++) { 3222 6997 x = points[i * 2]; 3223 6998 y = points[i * 2 + 1]; … … 3249 7024 static getPathLength(dataArray) { 3250 7025 let pathLength = 0; 3251 for ( vari = 0; i < dataArray.length; ++i) {7026 for (let i = 0; i < dataArray.length; ++i) { 3252 7027 pathLength += dataArray[i].pathLength; 3253 7028 } … … 3255 7030 } 3256 7031 static getPointAtLengthOfDataArray(length, dataArray) { 3257 var point, i = 0, ii = dataArray.length;7032 let points, i = 0, ii = dataArray.length; 3258 7033 if (!ii) { 3259 7034 return null; … … 3264 7039 } 3265 7040 if (i === ii) { 3266 point = dataArray[i - 1].points.slice(-2);7041 points = dataArray[i - 1].points.slice(-2); 3267 7042 return { 3268 x: point [0],3269 y: point [1]7043 x: points[0], 7044 y: points[1] 3270 7045 }; 3271 7046 } 3272 7047 if (length < 0.01) { 3273 point = dataArray[i].points.slice(0, 2);7048 points = dataArray[i].points.slice(0, 2); 3274 7049 return { 3275 x: point [0],3276 y: point [1]7050 x: points[0], 7051 y: points[1] 3277 7052 }; 3278 7053 } 3279 varcp = dataArray[i];3280 varp = cp.points;7054 const cp = dataArray[i]; 7055 const p = cp.points; 3281 7056 switch (cp.command) { 3282 7057 case "L": … … 3335 7110 return (1 - t) * (1 - t) * (1 - t); 3336 7111 } 3337 varx = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);3338 vary = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);7112 const x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct); 7113 const y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct); 3339 7114 return { 3340 7115 x, … … 3352 7127 return (1 - t) * (1 - t); 3353 7128 } 3354 varx = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);3355 vary = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);7129 const x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct); 7130 const y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct); 3356 7131 return { 3357 7132 x, … … 3360 7135 } 3361 7136 static getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) { 3362 varcosPsi = Math.cos(psi), sinPsi = Math.sin(psi);3363 varpt = {7137 const cosPsi = Math.cos(psi), sinPsi = Math.sin(psi); 7138 const pt = { 3364 7139 x: rx * Math.cos(theta), 3365 7140 y: ry * Math.sin(theta) … … 3374 7149 return []; 3375 7150 } 3376 varcs = data;3377 varcc = [7151 let cs = data; 7152 const cc = [ 3378 7153 "m", 3379 7154 "M", … … 3401 7176 cs = cs.replace(new RegExp(cc[n], "g"), "|" + cc[n]); 3402 7177 } 3403 vararr = cs.split("|");3404 varca = [];3405 varcoords = [];3406 varcpx = 0;3407 varcpy = 0;3408 varre = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;3409 varmatch;7178 const arr = cs.split("|"); 7179 const ca = []; 7180 const coords = []; 7181 let cpx = 0; 7182 let cpy = 0; 7183 const re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi; 7184 let match; 3410 7185 for (n = 1; n < arr.length; n++) { 3411 varstr = arr[n];3412 varc = str.charAt(0);7186 let str = arr[n]; 7187 let c = str.charAt(0); 3413 7188 str = str.slice(1); 3414 7189 coords.length = 0; … … 3416 7191 coords.push(match[0]); 3417 7192 } 3418 varp = [];3419 for ( varj = 0, jlen = coords.length; j < jlen; j++) {7193 const p = []; 7194 for (let j = 0, jlen = coords.length; j < jlen; j++) { 3420 7195 if (coords[j] === "00") { 3421 7196 p.push(0, 0); 3422 7197 continue; 3423 7198 } 3424 varparsed = parseFloat(coords[j]);7199 const parsed = parseFloat(coords[j]); 3425 7200 if (!isNaN(parsed)) { 3426 7201 p.push(parsed); … … 3433 7208 break; 3434 7209 } 3435 varcmd = "";3436 varpoints = [];3437 varstartX = cpx, startY = cpy;7210 let cmd = ""; 7211 let points = []; 7212 const startX = cpx, startY = cpy; 3438 7213 var prevCmd, ctlPtx, ctlPty; 3439 7214 var rx, ry, psi, fa, fs, x1, y1; … … 3457 7232 cmd = "M"; 3458 7233 if (ca.length > 2 && ca[ca.length - 1].command === "z") { 3459 for ( varidx = ca.length - 2; idx >= 0; idx--) {7234 for (let idx = ca.length - 2; idx >= 0; idx--) { 3460 7235 if (ca[idx].command === "M") { 3461 7236 cpx = ca[idx].points[0] + dx; … … 3624 7399 } 3625 7400 static calcLength(x, y, cmd, points) { 3626 varlen, p1, p2, t;3627 varpath = _Path;7401 let len, p1, p2, t; 7402 const path = _Path; 3628 7403 switch (cmd) { 3629 7404 case "L": … … 3663 7438 } 3664 7439 static convertEndpointToCenterParameterization(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg) { 3665 varpsi = psiDeg * (Math.PI / 180);3666 varxp = Math.cos(psi) * (x1 - x2) / 2 + Math.sin(psi) * (y1 - y2) / 2;3667 varyp = -1 * Math.sin(psi) * (x1 - x2) / 2 + Math.cos(psi) * (y1 - y2) / 2;3668 varlambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);7440 const psi = psiDeg * (Math.PI / 180); 7441 const xp = Math.cos(psi) * (x1 - x2) / 2 + Math.sin(psi) * (y1 - y2) / 2; 7442 const yp = -1 * Math.sin(psi) * (x1 - x2) / 2 + Math.cos(psi) * (y1 - y2) / 2; 7443 const lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry); 3669 7444 if (lambda > 1) { 3670 7445 rx *= Math.sqrt(lambda); 3671 7446 ry *= Math.sqrt(lambda); 3672 7447 } 3673 varf = Math.sqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) / (rx * rx * (yp * yp) + ry * ry * (xp * xp)));7448 let f = Math.sqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) / (rx * rx * (yp * yp) + ry * ry * (xp * xp))); 3674 7449 if (fa === fs) { 3675 7450 f *= -1; … … 3678 7453 f = 0; 3679 7454 } 3680 varcxp = f * rx * yp / ry;3681 varcyp = f * -ry * xp / rx;3682 varcx = (x1 + x2) / 2 + Math.cos(psi) * cxp - Math.sin(psi) * cyp;3683 varcy = (y1 + y2) / 2 + Math.sin(psi) * cxp + Math.cos(psi) * cyp;3684 varvMag = function(v2) {7455 const cxp = f * rx * yp / ry; 7456 const cyp = f * -ry * xp / rx; 7457 const cx = (x1 + x2) / 2 + Math.cos(psi) * cxp - Math.sin(psi) * cyp; 7458 const cy = (y1 + y2) / 2 + Math.sin(psi) * cxp + Math.cos(psi) * cyp; 7459 const vMag = function(v2) { 3685 7460 return Math.sqrt(v2[0] * v2[0] + v2[1] * v2[1]); 3686 7461 }; 3687 varvRatio = function(u2, v2) {7462 const vRatio = function(u2, v2) { 3688 7463 return (u2[0] * v2[0] + u2[1] * v2[1]) / (vMag(u2) * vMag(v2)); 3689 7464 }; 3690 varvAngle = function(u2, v2) {7465 const vAngle = function(u2, v2) { 3691 7466 return (u2[0] * v2[1] < u2[1] * v2[0] ? -1 : 1) * Math.acos(vRatio(u2, v2)); 3692 7467 }; 3693 vartheta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);3694 varu = [(xp - cxp) / rx, (yp - cyp) / ry];3695 varv = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];3696 vardTheta = vAngle(u, v);7468 const theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]); 7469 const u = [(xp - cxp) / rx, (yp - cyp) / ry]; 7470 const v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry]; 7471 let dTheta = vAngle(u, v); 3697 7472 if (vRatio(u, v) <= -1) { 3698 7473 dTheta = Math.PI; … … 3732 7507 _sceneFunc(ctx) { 3733 7508 super._sceneFunc(ctx); 3734 varPI2 = Math.PI * 2;3735 varpoints = this.points();3736 vartp = points;3737 varfromTension = this.tension() !== 0 && points.length > 4;7509 const PI2 = Math.PI * 2; 7510 const points = this.points(); 7511 let tp = points; 7512 const fromTension = this.tension() !== 0 && points.length > 4; 3738 7513 if (fromTension) { 3739 7514 tp = this.getTensionPoints(); 3740 7515 } 3741 varlength = this.pointerLength();3742 varn = points.length;3743 vardx, dy;7516 const length = this.pointerLength(); 7517 const n = points.length; 7518 let dx, dy; 3744 7519 if (fromTension) { 3745 7520 const lp = [ … … 3759 7534 dy = points[n - 1] - points[n - 3]; 3760 7535 } 3761 varradians = (Math.atan2(dy, dx) + PI2) % PI2;3762 varwidth = this.pointerWidth();7536 const radians = (Math.atan2(dy, dx) + PI2) % PI2; 7537 const width = this.pointerWidth(); 3763 7538 if (this.pointerAtEnding()) { 3764 7539 ctx.save(); … … 3794 7569 } 3795 7570 __fillStroke(ctx) { 3796 varisDashEnabled = this.dashEnabled();7571 const isDashEnabled = this.dashEnabled(); 3797 7572 if (isDashEnabled) { 3798 7573 this.attrs.dashEnabled = false; … … 3880 7655 var Ellipse = class extends Shape_1.Shape { 3881 7656 _sceneFunc(context) { 3882 varrx = this.radiusX(), ry = this.radiusY();7657 const rx = this.radiusX(), ry = this.radiusY(); 3883 7658 context.beginPath(); 3884 7659 context.save(); … … 3995 7770 } 3996 7771 _hitFunc(context) { 3997 varwidth = this.width(), height = this.height(), cornerRadius = this.cornerRadius();7772 const width = this.width(), height = this.height(), cornerRadius = this.cornerRadius(); 3998 7773 context.beginPath(); 3999 7774 if (!cornerRadius) { … … 4014 7789 } 4015 7790 static fromURL(url, callback, onError = null) { 4016 varimg = Util_1.Util.createImageElement();7791 const img = Util_1.Util.createImageElement(); 4017 7792 img.onload = function() { 4018 varimage = new _Image({7793 const image = new _Image({ 4019 7794 image: img 4020 7795 }); … … 4085 7860 } 4086 7861 _addListeners(text) { 4087 varthat = this, n;4088 varfunc = function() {7862 let that = this, n; 7863 const func = function() { 4089 7864 that._sync(); 4090 7865 }; … … 4100 7875 } 4101 7876 _sync() { 4102 vartext = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight;7877 let text = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight; 4103 7878 if (text && tag) { 4104 7879 width = text.width(); … … 4145 7920 var Tag = class extends Shape_1.Shape { 4146 7921 _sceneFunc(context) { 4147 varwidth = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();7922 const width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius(); 4148 7923 let topLeft = 0; 4149 7924 let topRight = 0; … … 4192 7967 } 4193 7968 getSelfRect() { 4194 varx = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();7969 let x = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height(); 4195 7970 if (direction === UP) { 4196 7971 y -= pointerHeight; … … 4219 7994 Factory_1.Factory.addGetterSetter(Tag, "pointerHeight", 0, (0, Validators_1.getNumberValidator)()); 4220 7995 Factory_1.Factory.addGetterSetter(Tag, "cornerRadius", 0, (0, Validators_1.getNumberOrArrayOfNumbersValidator)(4)); 7996 } 7997 }); 7998 7999 // node_modules/konva/lib/shapes/Rect.js 8000 var require_Rect = __commonJS({ 8001 "node_modules/konva/lib/shapes/Rect.js"(exports) { 8002 "use strict"; 8003 Object.defineProperty(exports, "__esModule", { value: true }); 8004 exports.Rect = void 0; 8005 var Factory_1 = require_Factory(); 8006 var Shape_1 = require_Shape(); 8007 var Global_1 = require_Global(); 8008 var Util_1 = require_Util(); 8009 var Validators_1 = require_Validators(); 8010 var Rect = class extends Shape_1.Shape { 8011 _sceneFunc(context) { 8012 const cornerRadius = this.cornerRadius(), width = this.width(), height = this.height(); 8013 context.beginPath(); 8014 if (!cornerRadius) { 8015 context.rect(0, 0, width, height); 8016 } else { 8017 Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius); 8018 } 8019 context.closePath(); 8020 context.fillStrokeShape(this); 8021 } 8022 }; 8023 exports.Rect = Rect; 8024 Rect.prototype.className = "Rect"; 8025 (0, Global_1._registerNode)(Rect); 8026 Factory_1.Factory.addGetterSetter(Rect, "cornerRadius", 0, (0, Validators_1.getNumberOrArrayOfNumbersValidator)(4)); 4221 8027 } 4222 8028 }); … … 4237 8043 context.beginPath(); 4238 8044 context.moveTo(points[0].x, points[0].y); 4239 for ( varn = 1; n < points.length; n++) {8045 for (let n = 1; n < points.length; n++) { 4240 8046 context.lineTo(points[n].x, points[n].y); 4241 8047 } … … 4247 8053 const radius = this.attrs.radius || 0; 4248 8054 const points = []; 4249 for ( varn = 0; n < sides; n++) {8055 for (let n = 0; n < sides; n++) { 4250 8056 points.push({ 4251 8057 x: radius * Math.sin(n * 2 * Math.PI / sides), … … 4257 8063 getSelfRect() { 4258 8064 const points = this._getPoints(); 4259 varminX = points[0].x;4260 varmaxX = points[0].y;4261 varminY = points[0].x;4262 varmaxY = points[0].y;8065 let minX = points[0].x; 8066 let maxX = points[0].y; 8067 let minY = points[0].x; 8068 let maxY = points[0].y; 4263 8069 points.forEach((point) => { 4264 8070 minX = Math.min(minX, point.x); … … 4294 8100 Factory_1.Factory.addGetterSetter(RegularPolygon, "radius", 0, (0, Validators_1.getNumberValidator)()); 4295 8101 Factory_1.Factory.addGetterSetter(RegularPolygon, "sides", 0, (0, Validators_1.getNumberValidator)()); 8102 } 8103 }); 8104 8105 // node_modules/konva/lib/shapes/Ring.js 8106 var require_Ring = __commonJS({ 8107 "node_modules/konva/lib/shapes/Ring.js"(exports) { 8108 "use strict"; 8109 Object.defineProperty(exports, "__esModule", { value: true }); 8110 exports.Ring = void 0; 8111 var Factory_1 = require_Factory(); 8112 var Shape_1 = require_Shape(); 8113 var Validators_1 = require_Validators(); 8114 var Global_1 = require_Global(); 8115 var PIx2 = Math.PI * 2; 8116 var Ring = class extends Shape_1.Shape { 8117 _sceneFunc(context) { 8118 context.beginPath(); 8119 context.arc(0, 0, this.innerRadius(), 0, PIx2, false); 8120 context.moveTo(this.outerRadius(), 0); 8121 context.arc(0, 0, this.outerRadius(), PIx2, 0, true); 8122 context.closePath(); 8123 context.fillStrokeShape(this); 8124 } 8125 getWidth() { 8126 return this.outerRadius() * 2; 8127 } 8128 getHeight() { 8129 return this.outerRadius() * 2; 8130 } 8131 setWidth(width) { 8132 this.outerRadius(width / 2); 8133 } 8134 setHeight(height) { 8135 this.outerRadius(height / 2); 8136 } 8137 }; 8138 exports.Ring = Ring; 8139 Ring.prototype.className = "Ring"; 8140 Ring.prototype._centroid = true; 8141 Ring.prototype._attrsAffectingSize = ["innerRadius", "outerRadius"]; 8142 (0, Global_1._registerNode)(Ring); 8143 Factory_1.Factory.addGetterSetter(Ring, "innerRadius", 0, (0, Validators_1.getNumberValidator)()); 8144 Factory_1.Factory.addGetterSetter(Ring, "outerRadius", 0, (0, Validators_1.getNumberValidator)()); 4296 8145 } 4297 8146 }); … … 4313 8162 this._updated = true; 4314 8163 this.anim = new Animation_1.Animation(() => { 4315 varupdated = this._updated;8164 const updated = this._updated; 4316 8165 this._updated = false; 4317 8166 return updated; … … 4332 8181 } 4333 8182 _sceneFunc(context) { 4334 varanim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), x = set[ix4 + 0], y = set[ix4 + 1], width = set[ix4 + 2], height = set[ix4 + 3], image = this.image();8183 const anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), x = set[ix4 + 0], y = set[ix4 + 1], width = set[ix4 + 2], height = set[ix4 + 3], image = this.image(); 4335 8184 if (this.hasFill() || this.hasStroke()) { 4336 8185 context.beginPath(); … … 4341 8190 if (image) { 4342 8191 if (offsets) { 4343 varoffset = offsets[anim], ix2 = index * 2;8192 const offset = offsets[anim], ix2 = index * 2; 4344 8193 context.drawImage(image, x, y, width, height, offset[ix2 + 0], offset[ix2 + 1], width, height); 4345 8194 } else { … … 4349 8198 } 4350 8199 _hitFunc(context) { 4351 varanim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), width = set[ix4 + 2], height = set[ix4 + 3];8200 const anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), width = set[ix4 + 2], height = set[ix4 + 3]; 4352 8201 context.beginPath(); 4353 8202 if (offsets) { 4354 varoffset = offsets[anim];4355 varix2 = index * 2;8203 const offset = offsets[anim]; 8204 const ix2 = index * 2; 4356 8205 context.rect(offset[ix2 + 0], offset[ix2 + 1], width, height); 4357 8206 } else { … … 4365 8214 } 4366 8215 _setInterval() { 4367 varthat = this;8216 const that = this; 4368 8217 this.interval = setInterval(function() { 4369 8218 that._updateIndex(); … … 4374 8223 return; 4375 8224 } 4376 varlayer = this.getLayer();8225 const layer = this.getLayer(); 4377 8226 this.anim.setLayers(layer); 4378 8227 this._setInterval(); … … 4387 8236 } 4388 8237 _updateIndex() { 4389 varindex = this.frameIndex(), animation = this.animation(), animations = this.animations(), anim = animations[animation], len = anim.length / 4;8238 const index = this.frameIndex(), animation = this.animation(), animations = this.animations(), anim = animations[animation], len = anim.length / 4; 4390 8239 if (index < len - 1) { 4391 8240 this.frameIndex(index + 1); … … 4424 8273 var Star = class extends Shape_1.Shape { 4425 8274 _sceneFunc(context) { 4426 varinnerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();8275 const innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints(); 4427 8276 context.beginPath(); 4428 8277 context.moveTo(0, 0 - outerRadius); 4429 for ( varn = 1; n < numPoints * 2; n++) {4430 varradius = n % 2 === 0 ? outerRadius : innerRadius;4431 varx = radius * Math.sin(n * Math.PI / numPoints);4432 vary = -1 * radius * Math.cos(n * Math.PI / numPoints);8278 for (let n = 1; n < numPoints * 2; n++) { 8279 const radius = n % 2 === 0 ? outerRadius : innerRadius; 8280 const x = radius * Math.sin(n * Math.PI / numPoints); 8281 const y = -1 * radius * Math.cos(n * Math.PI / numPoints); 4433 8282 context.lineTo(x, y); 4434 8283 } … … 4465 8314 "use strict"; 4466 8315 Object.defineProperty(exports, "__esModule", { value: true }); 4467 exports.Text = exports.stringToArray = void 0; 8316 exports.Text = void 0; 8317 exports.stringToArray = stringToArray; 4468 8318 var Util_1 = require_Util(); 4469 8319 var Factory_1 = require_Factory(); … … 4473 8323 var Global_2 = require_Global(); 4474 8324 function stringToArray(string) { 4475 return Array.from(string); 8325 return [...string].reduce((acc, char, index, array) => { 8326 if (new RegExp("\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?(?:\\u200D\\p{Emoji_Presentation})+", "u").test(char)) { 8327 acc.push(char); 8328 } else if (new RegExp("\\p{Regional_Indicator}{2}", "u").test(char + (array[index + 1] || ""))) { 8329 acc.push(char + array[index + 1]); 8330 } else if (index > 0 && new RegExp("\\p{Mn}|\\p{Me}|\\p{Mc}", "u").test(char)) { 8331 acc[acc.length - 1] += char; 8332 } else { 8333 acc.push(char); 8334 } 8335 return acc; 8336 }, []); 4476 8337 } 4477 exports.stringToArray = stringToArray;4478 8338 var AUTO = "auto"; 4479 8339 var CENTER = "center"; … … 4554 8414 this._partialTextX = 0; 4555 8415 this._partialTextY = 0; 4556 for ( varn = 0; n < attrChangeListLen; n++) {8416 for (let n = 0; n < attrChangeListLen; n++) { 4557 8417 this.on(ATTR_CHANGE_LIST[n] + CHANGE_KONVA, this._setTextData); 4558 8418 } … … 4560 8420 } 4561 8421 _sceneFunc(context) { 4562 vartextArr = this.textArr, textArrLen = textArr.length;8422 const textArr = this.textArr, textArrLen = textArr.length; 4563 8423 if (!this.text()) { 4564 8424 return; 4565 8425 } 4566 varpadding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf("underline") !== -1, shouldLineThrough = textDecoration.indexOf("line-through") !== -1, n;8426 let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf("underline") !== -1, shouldLineThrough = textDecoration.indexOf("line-through") !== -1, n; 4567 8427 direction = direction === INHERIT ? context.direction : direction; 4568 vartranslateY = lineHeightPx / 2;4569 varbaseline = MIDDLE;8428 let translateY = lineHeightPx / 2; 8429 let baseline = MIDDLE; 4570 8430 if (Global_1.Konva._fixTextRendering) { 4571 varmetrics = this.measureSize("M");8431 const metrics = this.measureSize("M"); 4572 8432 baseline = "alphabetic"; 4573 8433 translateY = (metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2 + lineHeightPx / 2; … … 4600 8460 context.save(); 4601 8461 context.beginPath(); 4602 let yOffset = Global_1.Konva._fixTextRendering ? Math.round(fontSize / 4) : Math.round(fontSize / 2);8462 const yOffset = Global_1.Konva._fixTextRendering ? Math.round(fontSize / 4) : Math.round(fontSize / 2); 4603 8463 const x = lineTranslateX; 4604 8464 const y = translateY + lineTranslateY + yOffset; … … 4617 8477 context.save(); 4618 8478 context.beginPath(); 4619 let yOffset = Global_1.Konva._fixTextRendering ? -Math.round(fontSize / 4) : 0;8479 const yOffset = Global_1.Konva._fixTextRendering ? -Math.round(fontSize / 4) : 0; 4620 8480 context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset); 4621 8481 spacesNumber = text.split(" ").length - 1; … … 4631 8491 if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) { 4632 8492 spacesNumber = text.split(" ").length - 1; 4633 vararray = stringToArray(text);4634 for ( varli = 0; li < array.length; li++) {4635 varletter = array[li];8493 const array = stringToArray(text); 8494 for (let li = 0; li < array.length; li++) { 8495 const letter = array[li]; 4636 8496 if (letter === " " && !lastLine && align === JUSTIFY) { 4637 8497 lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber; … … 4659 8519 } 4660 8520 _hitFunc(context) { 4661 varwidth = this.getWidth(), height = this.getHeight();8521 const width = this.getWidth(), height = this.getHeight(); 4662 8522 context.beginPath(); 4663 8523 context.rect(0, 0, width, height); … … 4666 8526 } 4667 8527 setText(text) { 4668 varstr = Util_1.Util._isString(text) ? text : text === null || text === void 0 ? "" : text + "";8528 const str = Util_1.Util._isString(text) ? text : text === null || text === void 0 ? "" : text + ""; 4669 8529 this._setAttr(TEXT, str); 4670 8530 return this; 4671 8531 } 4672 8532 getWidth() { 4673 varisAuto = this.attrs.width === AUTO || this.attrs.width === void 0;8533 const isAuto = this.attrs.width === AUTO || this.attrs.width === void 0; 4674 8534 return isAuto ? this.getTextWidth() + this.padding() * 2 : this.attrs.width; 4675 8535 } 4676 8536 getHeight() { 4677 varisAuto = this.attrs.height === AUTO || this.attrs.height === void 0;8537 const isAuto = this.attrs.height === AUTO || this.attrs.height === void 0; 4678 8538 return isAuto ? this.fontSize() * this.textArr.length * this.lineHeight() + this.padding() * 2 : this.attrs.height; 4679 8539 } … … 4687 8547 measureSize(text) { 4688 8548 var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; 4689 var_context = getDummyContext(), fontSize = this.fontSize(), metrics;8549 let _context = getDummyContext(), fontSize = this.fontSize(), metrics; 4690 8550 _context.save(); 4691 8551 _context.font = this._getContextFont(); … … 4717 8577 line = line.trim(); 4718 8578 } 4719 varwidth = this._getTextWidth(line);8579 const width = this._getTextWidth(line); 4720 8580 return this.textArr.push({ 4721 8581 text: line, … … 4725 8585 } 4726 8586 _getTextWidth(text) { 4727 varletterSpacing = this.letterSpacing();4728 varlength = text.length;8587 const letterSpacing = this.letterSpacing(); 8588 const length = text.length; 4729 8589 return getDummyContext().measureText(text).width + (length ? letterSpacing * (length - 1) : 0); 4730 8590 } 4731 8591 _setTextData() { 4732 varlines = this.text().split("\n"), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== void 0, fixedHeight = height !== AUTO && height !== void 0, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(), shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();8592 let lines = this.text().split("\n"), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== void 0, fixedHeight = height !== AUTO && height !== void 0, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(), shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis(); 4733 8593 this.textArr = []; 4734 8594 getDummyContext().font = this._getContextFont(); 4735 varadditionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;4736 for ( vari = 0, max = lines.length; i < max; ++i) {4737 varline = lines[i];4738 varlineWidth = this._getTextWidth(line);8595 const additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0; 8596 for (let i = 0, max = lines.length; i < max; ++i) { 8597 let line = lines[i]; 8598 let lineWidth = this._getTextWidth(line); 4739 8599 if (fixedWidth && lineWidth > maxWidth) { 4740 8600 while (line.length > 0) { 4741 varlow = 0, high = line.length, match = "", matchWidth = 0;8601 let low = 0, high = line.length, match = "", matchWidth = 0; 4742 8602 while (low < high) { 4743 varmid = low + high >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;8603 const mid = low + high >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth; 4744 8604 if (substrWidth <= maxWidth) { 4745 8605 low = mid + 1; … … 4753 8613 if (wrapAtWord) { 4754 8614 var wrapIndex; 4755 varnextChar = line[match.length];4756 varnextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;8615 const nextChar = line[match.length]; 8616 const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH; 4757 8617 if (nextIsSpaceOrDash && matchWidth <= maxWidth) { 4758 8618 wrapIndex = match.length; … … 4770 8630 textWidth = Math.max(textWidth, matchWidth); 4771 8631 currentHeightPx += lineHeightPx; 4772 varshouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);8632 const shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx); 4773 8633 if (shouldHandleEllipsis) { 4774 8634 this._tryToAddEllipsisToLastLine(); … … 4809 8669 } 4810 8670 _shouldHandleEllipsis(currentHeightPx) { 4811 varfontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== void 0, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;8671 const fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== void 0, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE; 4812 8672 return !shouldWrap || fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx; 4813 8673 } 4814 8674 _tryToAddEllipsisToLastLine() { 4815 varwidth = this.attrs.width, fixedWidth = width !== AUTO && width !== void 0, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();4816 varlastLine = this.textArr[this.textArr.length - 1];8675 const width = this.attrs.width, fixedWidth = width !== AUTO && width !== void 0, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis(); 8676 const lastLine = this.textArr[this.textArr.length - 1]; 4817 8677 if (!lastLine || !shouldAddEllipsis) { 4818 8678 return; 4819 8679 } 4820 8680 if (fixedWidth) { 4821 varhaveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;8681 const haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth; 4822 8682 if (!haveSpace) { 4823 8683 lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3); … … 4927 8787 context.setAttr("textAlign", "left"); 4928 8788 context.save(); 4929 vartextDecoration = this.textDecoration();4930 varfill = this.fill();4931 varfontSize = this.fontSize();4932 varglyphInfo = this.glyphInfo;8789 const textDecoration = this.textDecoration(); 8790 const fill = this.fill(); 8791 const fontSize = this.fontSize(); 8792 const glyphInfo = this.glyphInfo; 4933 8793 if (textDecoration === "underline") { 4934 8794 context.beginPath(); 4935 8795 } 4936 for ( vari = 0; i < glyphInfo.length; i++) {8796 for (let i = 0; i < glyphInfo.length; i++) { 4937 8797 context.save(); 4938 varp0 = glyphInfo[i].p0;8798 const p0 = glyphInfo[i].p0; 4939 8799 context.translate(p0.x, p0.y); 4940 8800 context.rotate(glyphInfo[i].rotation); … … 4958 8818 _hitFunc(context) { 4959 8819 context.beginPath(); 4960 varglyphInfo = this.glyphInfo;8820 const glyphInfo = this.glyphInfo; 4961 8821 if (glyphInfo.length >= 1) { 4962 varp0 = glyphInfo[0].p0;8822 const p0 = glyphInfo[0].p0; 4963 8823 context.moveTo(p0.x, p0.y); 4964 8824 } 4965 for ( vari = 0; i < glyphInfo.length; i++) {4966 varp1 = glyphInfo[i].p1;8825 for (let i = 0; i < glyphInfo.length; i++) { 8826 const p1 = glyphInfo[i].p1; 4967 8827 context.lineTo(p1.x, p1.y); 4968 8828 } … … 4985 8845 } 4986 8846 _getTextSize(text) { 4987 vardummyCanvas = this.dummyCanvas;4988 var_context = dummyCanvas.getContext("2d");8847 const dummyCanvas = this.dummyCanvas; 8848 const _context = dummyCanvas.getContext("2d"); 4989 8849 _context.save(); 4990 8850 _context.font = this._getContextFont(); 4991 varmetrics = _context.measureText(text);8851 const metrics = _context.measureText(text); 4992 8852 _context.restore(); 4993 8853 return { … … 5017 8877 const charArr = (0, Text_1.stringToArray)(this.text()); 5018 8878 let offsetToGlyph = offset; 5019 for ( vari = 0; i < charArr.length; i++) {8879 for (let i = 0; i < charArr.length; i++) { 5020 8880 const charStartPoint = this._getPointAtLength(offsetToGlyph); 5021 8881 if (!charStartPoint) … … 5063 8923 }; 5064 8924 } 5065 varpoints = [];8925 const points = []; 5066 8926 this.glyphInfo.forEach(function(info) { 5067 8927 points.push(info.p0.x); … … 5070 8930 points.push(info.p1.y); 5071 8931 }); 5072 varminX = points[0] || 0;5073 varmaxX = points[0] || 0;5074 varminY = points[1] || 0;5075 varmaxY = points[1] || 0;5076 varx, y;5077 for ( vari = 0; i < points.length / 2; i++) {8932 let minX = points[0] || 0; 8933 let maxX = points[0] || 0; 8934 let minY = points[1] || 0; 8935 let maxY = points[1] || 0; 8936 let x, y; 8937 for (let i = 0; i < points.length / 2; i++) { 5078 8938 x = points[i * 2]; 5079 8939 y = points[i * 2 + 1]; … … 5083 8943 maxY = Math.max(maxY, y); 5084 8944 } 5085 varfontSize = this.fontSize();8945 const fontSize = this.fontSize(); 5086 8946 return { 5087 8947 x: minX - fontSize / 2, … … 5181 9041 } 5182 9042 rad += Util_1.Util.degToRad(ANGLES[anchorName] || 0); 5183 varangle = (Util_1.Util.radToDeg(rad) % 360 + 360) % 360;9043 const angle = (Util_1.Util.radToDeg(rad) % 360 + 360) % 360; 5184 9044 if (Util_1.Util._inRange(angle, 315 + 22.5, 360) || Util_1.Util._inRange(angle, 0, 22.5)) { 5185 9045 return "ns-resize"; … … 5309 9169 }); 5310 9170 this._resetTransformCache(); 5311 varelementsCreated = !!this.findOne(".top-left");9171 const elementsCreated = !!this.findOne(".top-left"); 5312 9172 if (elementsCreated) { 5313 9173 this.update(); … … 5371 9231 } 5372 9232 __getNodeShape(node, rot = this.rotation(), relative) { 5373 varrect = node.getClientRect({9233 const rect = node.getClientRect({ 5374 9234 skipTransform: true, 5375 9235 skipShadow: true, 5376 9236 skipStroke: this.ignoreStroke() 5377 9237 }); 5378 varabsScale = node.getAbsoluteScale(relative);5379 varabsPos = node.getAbsolutePosition(relative);5380 vardx = rect.x * absScale.x - node.offsetX() * absScale.x;5381 vardy = rect.y * absScale.y - node.offsetY() * absScale.y;9238 const absScale = node.getAbsoluteScale(relative); 9239 const absPos = node.getAbsolutePosition(relative); 9240 const dx = rect.x * absScale.x - node.offsetX() * absScale.x; 9241 const dy = rect.y * absScale.y - node.offsetY() * absScale.y; 5382 9242 const rotation = (Global_1.Konva.getAngle(node.getAbsoluteRotation()) + Math.PI * 2) % (Math.PI * 2); 5383 9243 const box = { … … 5394 9254 } 5395 9255 __getNodeRect() { 5396 varnode = this.getNode();9256 const node = this.getNode(); 5397 9257 if (!node) { 5398 9258 return { … … 5411 9271 skipStroke: this.ignoreStroke() 5412 9272 }); 5413 varpoints = [9273 const points = [ 5414 9274 { x: box.x, y: box.y }, 5415 9275 { x: box.x + box.width, y: box.y }, … … 5417 9277 { x: box.x, y: box.y + box.height } 5418 9278 ]; 5419 vartrans = node2.getAbsoluteTransform();9279 const trans = node2.getAbsoluteTransform(); 5420 9280 points.forEach(function(point) { 5421 vartransformed = trans.point(point);9281 const transformed = trans.point(point); 5422 9282 totalPoints.push(transformed); 5423 9283 }); … … 5425 9285 const tr = new Util_1.Transform(); 5426 9286 tr.rotate(-Global_1.Konva.getAngle(this.rotation())); 5427 varminX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;9287 let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; 5428 9288 totalPoints.forEach(function(point) { 5429 vartransformed = tr.point(point);9289 const transformed = tr.point(point); 5430 9290 if (minX === void 0) { 5431 9291 minX = maxX = transformed.x; … … 5467 9327 } 5468 9328 _createAnchor(name) { 5469 varanchor = new Rect_1.Rect({9329 const anchor = new Rect_1.Rect({ 5470 9330 stroke: "rgb(0, 161, 255)", 5471 9331 fill: "white", … … 5476 9336 hitStrokeWidth: TOUCH_DEVICE ? 10 : "auto" 5477 9337 }); 5478 varself = this;9338 const self = this; 5479 9339 anchor.on("mousedown touchstart", function(e) { 5480 9340 self._handleMouseDown(e); … … 5488 9348 }); 5489 9349 anchor.on("mouseenter", () => { 5490 varrad = Global_1.Konva.getAngle(this.rotation());5491 varrotateCursor = this.rotateAnchorCursor();5492 varcursor = getCursor(name, rad, rotateCursor);9350 const rad = Global_1.Konva.getAngle(this.rotation()); 9351 const rotateCursor = this.rotateAnchorCursor(); 9352 const cursor = getCursor(name, rad, rotateCursor); 5493 9353 anchor.getStage().content && (anchor.getStage().content.style.cursor = cursor); 5494 9354 this._cursorChange = true; … … 5501 9361 } 5502 9362 _createBack() { 5503 varback = new Shape_1.Shape({9363 const back = new Shape_1.Shape({ 5504 9364 name: "back", 5505 9365 width: 0, … … 5507 9367 draggable: true, 5508 9368 sceneFunc(ctx, shape) { 5509 vartr = shape.getParent();5510 varpadding = tr.padding();9369 const tr = shape.getParent(); 9370 const padding = tr.padding(); 5511 9371 ctx.beginPath(); 5512 9372 ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2); … … 5521 9381 return; 5522 9382 } 5523 varpadding = this.padding();9383 const padding = this.padding(); 5524 9384 ctx.beginPath(); 5525 9385 ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2); … … 5547 9407 } 5548 9408 this._movingAnchorName = e.target.name().split(" ")[0]; 5549 varattrs = this._getNodeRect();5550 varwidth = attrs.width;5551 varheight = attrs.height;5552 varhypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));9409 const attrs = this._getNodeRect(); 9410 const width = attrs.width; 9411 const height = attrs.height; 9412 const hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); 5553 9413 this.sin = Math.abs(height / hypotenuse); 5554 9414 this.cos = Math.abs(width / hypotenuse); … … 5560 9420 } 5561 9421 this._transforming = true; 5562 varap = e.target.getAbsolutePosition();5563 varpos = e.target.getStage().getPointerPosition();9422 const ap = e.target.getAbsolutePosition(); 9423 const pos = e.target.getStage().getPointerPosition(); 5564 9424 this._anchorDragOffset = { 5565 9425 x: pos.x - ap.x, … … 5573 9433 } 5574 9434 _handleMouseMove(e) { 5575 varx, y, newHypotenuse;5576 varanchorNode = this.findOne("." + this._movingAnchorName);5577 varstage = anchorNode.getStage();9435 let x, y, newHypotenuse; 9436 const anchorNode = this.findOne("." + this._movingAnchorName); 9437 const stage = anchorNode.getStage(); 5578 9438 stage.setPointersPositions(e); 5579 9439 const pp = stage.getPointerPosition(); … … 5592 9452 } 5593 9453 if (this._movingAnchorName === "rotater") { 5594 varattrs = this._getNodeRect();9454 const attrs = this._getNodeRect(); 5595 9455 x = anchorNode.x() - attrs.width / 2; 5596 9456 y = -anchorNode.y() + attrs.height / 2; … … 5599 9459 delta -= Math.PI; 5600 9460 } 5601 varoldRotation = Global_1.Konva.getAngle(this.rotation());9461 const oldRotation = Global_1.Konva.getAngle(this.rotation()); 5602 9462 const newRotation = oldRotation + delta; 5603 9463 const tol = Global_1.Konva.getAngle(this.rotationSnapTolerance()); … … 5608 9468 return; 5609 9469 } 5610 varshiftBehavior = this.shiftBehavior();5611 varkeepProportion;9470 const shiftBehavior = this.shiftBehavior(); 9471 let keepProportion; 5612 9472 if (shiftBehavior === "inverted") { 5613 9473 keepProportion = this.keepRatio() && !e.shiftKey; … … 5705 9565 var centeredScaling = this.centeredScaling() || e.altKey; 5706 9566 if (centeredScaling) { 5707 vartopLeft = this.findOne(".top-left");5708 varbottomRight = this.findOne(".bottom-right");5709 vartopOffsetX = topLeft.x();5710 vartopOffsetY = topLeft.y();5711 varbottomOffsetX = this.getWidth() - bottomRight.x();5712 varbottomOffsetY = this.getHeight() - bottomRight.y();9567 const topLeft = this.findOne(".top-left"); 9568 const bottomRight = this.findOne(".bottom-right"); 9569 const topOffsetX = topLeft.x(); 9570 const topOffsetY = topLeft.y(); 9571 const bottomOffsetX = this.getWidth() - bottomRight.x(); 9572 const bottomOffsetY = this.getHeight() - bottomRight.y(); 5713 9573 bottomRight.move({ 5714 9574 x: -topOffsetX, … … 5720 9580 }); 5721 9581 } 5722 varabsPos = this.findOne(".top-left").getAbsolutePosition();9582 const absPos = this.findOne(".top-left").getAbsolutePosition(); 5723 9583 x = absPos.x; 5724 9584 y = absPos.y; 5725 varwidth = this.findOne(".bottom-right").x() - this.findOne(".top-left").x();5726 varheight = this.findOne(".bottom-right").y() - this.findOne(".top-left").y();9585 const width = this.findOne(".bottom-right").x() - this.findOne(".top-left").x(); 9586 const height = this.findOne(".bottom-right").y() - this.findOne(".top-left").y(); 5727 9587 this._fitNodesInto({ 5728 9588 x, … … 5749 9609 window.removeEventListener("touchend", this._handleMouseUp, true); 5750 9610 } 5751 varnode = this.getNode();9611 const node = this.getNode(); 5752 9612 activeTransformersCount--; 5753 9613 this._fire("transformend", { evt: e, target: node }); … … 5764 9624 } 5765 9625 _fitNodesInto(newAttrs, evt) { 5766 varoldAttrs = this._getNodeRect();9626 const oldAttrs = this._getNodeRect(); 5767 9627 const minSize = 1; 5768 9628 if (Util_1.Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) { … … 5774 9634 return; 5775 9635 } 5776 vart = new Util_1.Transform();9636 const t = new Util_1.Transform(); 5777 9637 t.rotate(Global_1.Konva.getAngle(this.rotation())); 5778 9638 if (this._movingAnchorName && newAttrs.width < 0 && this._movingAnchorName.indexOf("left") >= 0) { … … 5875 9735 update() { 5876 9736 var _a; 5877 varattrs = this._getNodeRect();9737 const attrs = this._getNodeRect(); 5878 9738 this.rotation(Util_1.Util._getRotation(attrs.rotation)); 5879 varwidth = attrs.width;5880 varheight = attrs.height;5881 varenabledAnchors = this.enabledAnchors();5882 varresizeEnabled = this.resizeEnabled();5883 varpadding = this.padding();5884 varanchorSize = this.anchorSize();9739 const width = attrs.width; 9740 const height = attrs.height; 9741 const enabledAnchors = this.enabledAnchors(); 9742 const resizeEnabled = this.resizeEnabled(); 9743 const padding = this.padding(); 9744 const anchorSize = this.anchorSize(); 5885 9745 const anchors = this.find("._anchor"); 5886 9746 anchors.forEach((node) => { … … 5977 9837 if (this._transforming) { 5978 9838 this._removeEvents(); 5979 varanchorNode = this.findOne("." + this._movingAnchorName);9839 const anchorNode = this.findOne("." + this._movingAnchorName); 5980 9840 if (anchorNode) { 5981 9841 anchorNode.stopDrag(); … … 5996 9856 } 5997 9857 clone(obj) { 5998 varnode = Node_1.Node.prototype.clone.call(this, obj);9858 const node = Node_1.Node.prototype.clone.call(this, obj); 5999 9859 return node; 6000 9860 } … … 6643 10503 ]; 6644 10504 function filterGaussBlurRGBA(imageData, radius) { 6645 varpixels = imageData.data, width = imageData.width, height = imageData.height;6646 varx, y, i, p, yp, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs;6647 vardiv = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = radiusPlus1 * (radiusPlus1 + 1) / 2, stackStart = new BlurStack(), stackEnd = null, stack = stackStart, stackIn = null, stackOut = null, mul_sum = mul_table[radius], shg_sum = shg_table[radius];10505 const pixels = imageData.data, width = imageData.width, height = imageData.height; 10506 let x, y, i, p, yp, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs; 10507 let div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = radiusPlus1 * (radiusPlus1 + 1) / 2, stackStart = new BlurStack(), stackEnd = null, stack = stackStart, stackIn = null, stackOut = null, mul_sum = mul_table[radius], shg_sum = shg_table[radius]; 6648 10508 for (i = 1; i < div; i++) { 6649 10509 stack = stack.next = new BlurStack(); … … 6804 10664 } 6805 10665 var Blur = function Blur2(imageData) { 6806 varradius = Math.round(this.blurRadius());10666 const radius = Math.round(this.blurRadius()); 6807 10667 if (radius > 0) { 6808 10668 filterGaussBlurRGBA(imageData, radius); … … 6824 10684 var Validators_1 = require_Validators(); 6825 10685 var Brighten = function(imageData) { 6826 varbrightness = this.brightness() * 255, data = imageData.data, len = data.length, i;10686 let brightness = this.brightness() * 255, data = imageData.data, len = data.length, i; 6827 10687 for (i = 0; i < len; i += 4) { 6828 10688 data[i] += brightness; … … 6846 10706 var Validators_1 = require_Validators(); 6847 10707 var Contrast = function(imageData) { 6848 varadjust = Math.pow((this.contrast() + 100) / 100, 2);6849 vardata = imageData.data, nPixels = data.length, red = 150, green = 150, blue = 150, i;10708 const adjust = Math.pow((this.contrast() + 100) / 100, 2); 10709 let data = imageData.data, nPixels = data.length, red = 150, green = 150, blue = 150, i; 6850 10710 for (i = 0; i < nPixels; i += 4) { 6851 10711 red = data[i]; … … 6891 10751 var Validators_1 = require_Validators(); 6892 10752 var Emboss = function(imageData) { 6893 varstrength = this.embossStrength() * 10, greyLevel = this.embossWhiteLevel() * 255, direction = this.embossDirection(), blend = this.embossBlend(), dirY = 0, dirX = 0, data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4, y = h;10753 let strength = this.embossStrength() * 10, greyLevel = this.embossWhiteLevel() * 255, direction = this.embossDirection(), blend = this.embossBlend(), dirY = 0, dirX = 0, data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4, y = h; 6894 10754 switch (direction) { 6895 10755 case "top-left": … … 6929 10789 } 6930 10790 do { 6931 varoffsetY = (y - 1) * w4;6932 varotherY = dirY;10791 const offsetY = (y - 1) * w4; 10792 let otherY = dirY; 6933 10793 if (y + otherY < 1) { 6934 10794 otherY = 0; … … 6937 10797 otherY = 0; 6938 10798 } 6939 varoffsetYOther = (y - 1 + otherY) * w * 4;6940 varx = w;10799 const offsetYOther = (y - 1 + otherY) * w * 4; 10800 let x = w; 6941 10801 do { 6942 varoffset = offsetY + (x - 1) * 4;6943 varotherX = dirX;10802 const offset = offsetY + (x - 1) * 4; 10803 let otherX = dirX; 6944 10804 if (x + otherX < 1) { 6945 10805 otherX = 0; … … 6948 10808 otherX = 0; 6949 10809 } 6950 varoffsetOther = offsetYOther + (x - 1 + otherX) * 4;6951 vardR = data[offset] - data[offsetOther];6952 vardG = data[offset + 1] - data[offsetOther + 1];6953 vardB = data[offset + 2] - data[offsetOther + 2];6954 vardif = dR;6955 varabsDif = dif > 0 ? dif : -dif;6956 varabsG = dG > 0 ? dG : -dG;6957 varabsB = dB > 0 ? dB : -dB;10810 const offsetOther = offsetYOther + (x - 1 + otherX) * 4; 10811 const dR = data[offset] - data[offsetOther]; 10812 const dG = data[offset + 1] - data[offsetOther + 1]; 10813 const dB = data[offset + 2] - data[offsetOther + 2]; 10814 let dif = dR; 10815 const absDif = dif > 0 ? dif : -dif; 10816 const absG = dG > 0 ? dG : -dG; 10817 const absB = dB > 0 ? dB : -dB; 6958 10818 if (absG > absDif) { 6959 10819 dif = dG; … … 6964 10824 dif *= strength; 6965 10825 if (blend) { 6966 varr = data[offset] + dif;6967 varg = data[offset + 1] + dif;6968 varb = data[offset + 2] + dif;10826 const r = data[offset] + dif; 10827 const g = data[offset + 1] + dif; 10828 const b = data[offset + 2] + dif; 6969 10829 data[offset] = r > 255 ? 255 : r < 0 ? 0 : r; 6970 10830 data[offset + 1] = g > 255 ? 255 : g < 0 ? 0 : g; 6971 10831 data[offset + 2] = b > 255 ? 255 : b < 0 ? 0 : b; 6972 10832 } else { 6973 vargrey = greyLevel - dif;10833 let grey = greyLevel - dif; 6974 10834 if (grey < 0) { 6975 10835 grey = 0; … … 7000 10860 var Validators_1 = require_Validators(); 7001 10861 function remap(fromValue, fromMin, fromMax, toMin, toMax) { 7002 varfromRange = fromMax - fromMin, toRange = toMax - toMin, toValue;10862 let fromRange = fromMax - fromMin, toRange = toMax - toMin, toValue; 7003 10863 if (fromRange === 0) { 7004 10864 return toMin + toRange / 2; … … 7012 10872 } 7013 10873 var Enhance = function(imageData) { 7014 vardata = imageData.data, nSubPixels = data.length, rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b, i;7015 varenhanceAmount = this.enhance();10874 let data = imageData.data, nSubPixels = data.length, rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b, i; 10875 const enhanceAmount = this.enhance(); 7016 10876 if (enhanceAmount === 0) { 7017 10877 return; … … 7049 10909 bMin = 0; 7050 10910 } 7051 varrMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin;10911 let rMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin; 7052 10912 if (enhanceAmount > 0) { 7053 10913 rGoalMax = rMax + enhanceAmount * (255 - rMax); … … 7086 10946 exports.Grayscale = void 0; 7087 10947 var Grayscale = function(imageData) { 7088 vardata = imageData.data, len = data.length, i, brightness;10948 let data = imageData.data, len = data.length, i, brightness; 7089 10949 for (i = 0; i < len; i += 4) { 7090 10950 brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]; … … 7111 10971 Factory_1.Factory.addGetterSetter(Node_1.Node, "luminance", 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter); 7112 10972 var HSL = function(imageData) { 7113 vardata = imageData.data, nPixels = data.length, v = 1, s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360, l = this.luminance() * 127, i;7114 varvsu = v * s * Math.cos(h * Math.PI / 180), vsw = v * s * Math.sin(h * Math.PI / 180);7115 varrr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;7116 vargr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;7117 varbr = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;7118 varr, g, b, a;10973 let data = imageData.data, nPixels = data.length, v = 1, s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360, l = this.luminance() * 127, i; 10974 const vsu = v * s * Math.cos(h * Math.PI / 180), vsw = v * s * Math.sin(h * Math.PI / 180); 10975 const rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw; 10976 const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw; 10977 const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw; 10978 let r, g, b, a; 7119 10979 for (i = 0; i < nPixels; i += 4) { 7120 10980 r = data[i + 0]; … … 7142 11002 var Validators_1 = require_Validators(); 7143 11003 var HSV = function(imageData) { 7144 var data = imageData.data, nPixels = data.length, v = Math.pow(2, this.value()), s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360, i;7145 varvsu = v * s * Math.cos(h * Math.PI / 180), vsw = v * s * Math.sin(h * Math.PI / 180);7146 varrr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;7147 vargr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;7148 varbr = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;7149 varr, g, b, a;7150 for ( i = 0; i < nPixels; i += 4) {11004 const data = imageData.data, nPixels = data.length, v = Math.pow(2, this.value()), s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360; 11005 const vsu = v * s * Math.cos(h * Math.PI / 180), vsw = v * s * Math.sin(h * Math.PI / 180); 11006 const rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw; 11007 const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw; 11008 const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw; 11009 let r, g, b, a; 11010 for (let i = 0; i < nPixels; i += 4) { 7151 11011 r = data[i + 0]; 7152 11012 g = data[i + 1]; … … 7173 11033 exports.Invert = void 0; 7174 11034 var Invert = function(imageData) { 7175 vardata = imageData.data, len = data.length, i;11035 let data = imageData.data, len = data.length, i; 7176 11036 for (i = 0; i < len; i += 4) { 7177 11037 data[i] = 255 - data[i]; … … 7195 11055 var Validators_1 = require_Validators(); 7196 11056 var ToPolar = function(src, dst, opt) { 7197 varsrcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, r = 0, g = 0, b = 0, a = 0;7198 varrad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);11057 let srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, r = 0, g = 0, b = 0, a = 0; 11058 let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid); 7199 11059 x = xSize - xMid; 7200 11060 y = ySize - yMid; 7201 11061 rad = Math.sqrt(x * x + y * y); 7202 11062 rMax = rad > rMax ? rad : rMax; 7203 varrSize = ySize, tSize = xSize, radius, theta;7204 varconversion = 360 / tSize * Math.PI / 180, sin, cos;11063 let rSize = ySize, tSize = xSize, radius, theta; 11064 let conversion = 360 / tSize * Math.PI / 180, sin, cos; 7205 11065 for (theta = 0; theta < tSize; theta += 1) { 7206 11066 sin = Math.sin(theta * conversion); … … 7223 11083 }; 7224 11084 var FromPolar = function(src, dst, opt) { 7225 varsrcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, dx, dy, r = 0, g = 0, b = 0, a = 0;7226 varrad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);11085 let srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, dx, dy, r = 0, g = 0, b = 0, a = 0; 11086 let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid); 7227 11087 x = xSize - xMid; 7228 11088 y = ySize - yMid; 7229 11089 rad = Math.sqrt(x * x + y * y); 7230 11090 rMax = rad > rMax ? rad : rMax; 7231 varrSize = ySize, tSize = xSize, radius, theta, phaseShift = opt.polarRotation || 0;7232 varx1, y1;11091 let rSize = ySize, tSize = xSize, radius, theta, phaseShift = opt.polarRotation || 0; 11092 let x1, y1; 7233 11093 for (x = 0; x < xSize; x += 1) { 7234 11094 for (y = 0; y < ySize; y += 1) { … … 7254 11114 }; 7255 11115 var Kaleidoscope = function(imageData) { 7256 varxSize = imageData.width, ySize = imageData.height;7257 varx, y, xoff, i, r, g, b, a, srcPos, dstPos;7258 varpower = Math.round(this.kaleidoscopePower());7259 varangle = Math.round(this.kaleidoscopeAngle());7260 varoffset = Math.floor(xSize * (angle % 360) / 360);11116 const xSize = imageData.width, ySize = imageData.height; 11117 let x, y, xoff, i, r, g, b, a, srcPos, dstPos; 11118 let power = Math.round(this.kaleidoscopePower()); 11119 const angle = Math.round(this.kaleidoscopeAngle()); 11120 const offset = Math.floor(xSize * (angle % 360) / 360); 7261 11121 if (power < 1) { 7262 11122 return; 7263 11123 } 7264 vartempCanvas = Util_1.Util.createCanvasElement();11124 const tempCanvas = Util_1.Util.createCanvasElement(); 7265 11125 tempCanvas.width = xSize; 7266 11126 tempCanvas.height = ySize; 7267 varscratchData = tempCanvas.getContext("2d").getImageData(0, 0, xSize, ySize);11127 const scratchData = tempCanvas.getContext("2d").getImageData(0, 0, xSize, ySize); 7268 11128 Util_1.Util.releaseCanvas(tempCanvas); 7269 11129 ToPolar(imageData, scratchData, { … … 7271 11131 polarCenterY: ySize / 2 7272 11132 }); 7273 varminSectionSize = xSize / Math.pow(2, power);11133 let minSectionSize = xSize / Math.pow(2, power); 7274 11134 while (minSectionSize <= 8) { 7275 11135 minSectionSize = minSectionSize * 2; … … 7277 11137 } 7278 11138 minSectionSize = Math.ceil(minSectionSize); 7279 varsectionSize = minSectionSize;7280 varxStart = 0, xEnd = sectionSize, xDelta = 1;11139 let sectionSize = minSectionSize; 11140 let xStart = 0, xEnd = sectionSize, xDelta = 1; 7281 11141 if (offset + minSectionSize > xSize) { 7282 11142 xStart = sectionSize; … … 7335 11195 var Validators_1 = require_Validators(); 7336 11196 function pixelAt(idata, x, y) { 7337 varidx = (y * idata.width + x) * 4;7338 vard = [];11197 let idx = (y * idata.width + x) * 4; 11198 const d = []; 7339 11199 d.push(idata.data[idx++], idata.data[idx++], idata.data[idx++], idata.data[idx++]); 7340 11200 return d; … … 7344 11204 } 7345 11205 function rgbMean(pTab) { 7346 varm = [0, 0, 0];7347 for ( vari = 0; i < pTab.length; i++) {11206 const m = [0, 0, 0]; 11207 for (let i = 0; i < pTab.length; i++) { 7348 11208 m[0] += pTab[i][0]; 7349 11209 m[1] += pTab[i][1]; … … 7356 11216 } 7357 11217 function backgroundMask(idata, threshold) { 7358 varrgbv_no = pixelAt(idata, 0, 0);7359 varrgbv_ne = pixelAt(idata, idata.width - 1, 0);7360 varrgbv_so = pixelAt(idata, 0, idata.height - 1);7361 varrgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1);7362 varthres = threshold || 10;11218 const rgbv_no = pixelAt(idata, 0, 0); 11219 const rgbv_ne = pixelAt(idata, idata.width - 1, 0); 11220 const rgbv_so = pixelAt(idata, 0, idata.height - 1); 11221 const rgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1); 11222 const thres = threshold || 10; 7363 11223 if (rgbDistance(rgbv_no, rgbv_ne) < thres && rgbDistance(rgbv_ne, rgbv_se) < thres && rgbDistance(rgbv_se, rgbv_so) < thres && rgbDistance(rgbv_so, rgbv_no) < thres) { 7364 varmean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]);7365 varmask = [];7366 for ( vari = 0; i < idata.width * idata.height; i++) {7367 vard = rgbDistance(mean, [11224 const mean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]); 11225 const mask = []; 11226 for (let i = 0; i < idata.width * idata.height; i++) { 11227 const d = rgbDistance(mean, [ 7368 11228 idata.data[i * 4], 7369 11229 idata.data[i * 4 + 1], … … 7376 11236 } 7377 11237 function applyMask(idata, mask) { 7378 for ( vari = 0; i < idata.width * idata.height; i++) {11238 for (let i = 0; i < idata.width * idata.height; i++) { 7379 11239 idata.data[4 * i + 3] = mask[i]; 7380 11240 } 7381 11241 } 7382 11242 function erodeMask(mask, sw, sh) { 7383 varweights = [1, 1, 1, 1, 0, 1, 1, 1, 1];7384 varside = Math.round(Math.sqrt(weights.length));7385 varhalfSide = Math.floor(side / 2);7386 varmaskResult = [];7387 for ( vary = 0; y < sh; y++) {7388 for ( varx = 0; x < sw; x++) {7389 varso = y * sw + x;7390 vara = 0;7391 for ( varcy = 0; cy < side; cy++) {7392 for ( varcx = 0; cx < side; cx++) {7393 varscy = y + cy - halfSide;7394 varscx = x + cx - halfSide;11243 const weights = [1, 1, 1, 1, 0, 1, 1, 1, 1]; 11244 const side = Math.round(Math.sqrt(weights.length)); 11245 const halfSide = Math.floor(side / 2); 11246 const maskResult = []; 11247 for (let y = 0; y < sh; y++) { 11248 for (let x = 0; x < sw; x++) { 11249 const so = y * sw + x; 11250 let a = 0; 11251 for (let cy = 0; cy < side; cy++) { 11252 for (let cx = 0; cx < side; cx++) { 11253 const scy = y + cy - halfSide; 11254 const scx = x + cx - halfSide; 7395 11255 if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { 7396 varsrcOff = scy * sw + scx;7397 varwt = weights[cy * side + cx];11256 const srcOff = scy * sw + scx; 11257 const wt = weights[cy * side + cx]; 7398 11258 a += mask[srcOff] * wt; 7399 11259 } … … 7406 11266 } 7407 11267 function dilateMask(mask, sw, sh) { 7408 varweights = [1, 1, 1, 1, 1, 1, 1, 1, 1];7409 varside = Math.round(Math.sqrt(weights.length));7410 varhalfSide = Math.floor(side / 2);7411 varmaskResult = [];7412 for ( vary = 0; y < sh; y++) {7413 for ( varx = 0; x < sw; x++) {7414 varso = y * sw + x;7415 vara = 0;7416 for ( varcy = 0; cy < side; cy++) {7417 for ( varcx = 0; cx < side; cx++) {7418 varscy = y + cy - halfSide;7419 varscx = x + cx - halfSide;11268 const weights = [1, 1, 1, 1, 1, 1, 1, 1, 1]; 11269 const side = Math.round(Math.sqrt(weights.length)); 11270 const halfSide = Math.floor(side / 2); 11271 const maskResult = []; 11272 for (let y = 0; y < sh; y++) { 11273 for (let x = 0; x < sw; x++) { 11274 const so = y * sw + x; 11275 let a = 0; 11276 for (let cy = 0; cy < side; cy++) { 11277 for (let cx = 0; cx < side; cx++) { 11278 const scy = y + cy - halfSide; 11279 const scx = x + cx - halfSide; 7420 11280 if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { 7421 varsrcOff = scy * sw + scx;7422 varwt = weights[cy * side + cx];11281 const srcOff = scy * sw + scx; 11282 const wt = weights[cy * side + cx]; 7423 11283 a += mask[srcOff] * wt; 7424 11284 } … … 7431 11291 } 7432 11292 function smoothEdgeMask(mask, sw, sh) { 7433 varweights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9];7434 varside = Math.round(Math.sqrt(weights.length));7435 varhalfSide = Math.floor(side / 2);7436 varmaskResult = [];7437 for ( vary = 0; y < sh; y++) {7438 for ( varx = 0; x < sw; x++) {7439 varso = y * sw + x;7440 vara = 0;7441 for ( varcy = 0; cy < side; cy++) {7442 for ( varcx = 0; cx < side; cx++) {7443 varscy = y + cy - halfSide;7444 varscx = x + cx - halfSide;11293 const weights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9]; 11294 const side = Math.round(Math.sqrt(weights.length)); 11295 const halfSide = Math.floor(side / 2); 11296 const maskResult = []; 11297 for (let y = 0; y < sh; y++) { 11298 for (let x = 0; x < sw; x++) { 11299 const so = y * sw + x; 11300 let a = 0; 11301 for (let cy = 0; cy < side; cy++) { 11302 for (let cx = 0; cx < side; cx++) { 11303 const scy = y + cy - halfSide; 11304 const scx = x + cx - halfSide; 7445 11305 if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { 7446 varsrcOff = scy * sw + scx;7447 varwt = weights[cy * side + cx];11306 const srcOff = scy * sw + scx; 11307 const wt = weights[cy * side + cx]; 7448 11308 a += mask[srcOff] * wt; 7449 11309 } … … 7456 11316 } 7457 11317 var Mask = function(imageData) { 7458 varthreshold = this.threshold(), mask = backgroundMask(imageData, threshold);11318 let threshold = this.threshold(), mask = backgroundMask(imageData, threshold); 7459 11319 if (mask) { 7460 11320 mask = erodeMask(mask, imageData.width, imageData.height); … … 7480 11340 var Validators_1 = require_Validators(); 7481 11341 var Noise = function(imageData) { 7482 var amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2, i;7483 for ( i = 0; i < nPixels; i += 4) {11342 const amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2; 11343 for (let i = 0; i < nPixels; i += 4) { 7484 11344 data[i + 0] += half - 2 * half * Math.random(); 7485 11345 data[i + 1] += half - 2 * half * Math.random(); … … 7503 11363 var Validators_1 = require_Validators(); 7504 11364 var Pixelate = function(imageData) { 7505 varpixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i, red, green, blue, alpha, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), xBinStart, xBinEnd, yBinStart, yBinEnd, xBin, yBin, pixelsInBin, data = imageData.data;11365 let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i, red, green, blue, alpha, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), xBinStart, xBinEnd, yBinStart, yBinEnd, xBin, yBin, pixelsInBin, data = imageData.data; 7506 11366 if (pixelSize <= 0) { 7507 11367 Util_1.Util.error("pixelSize value can not be <= 0"); … … 7572 11432 var Validators_1 = require_Validators(); 7573 11433 var Posterize = function(imageData) { 7574 varlevels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i;11434 let levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i; 7575 11435 for (i = 0; i < len; i += 1) { 7576 11436 data[i] = Math.floor(data[i] / scale) * scale; … … 7592 11452 var Validators_1 = require_Validators(); 7593 11453 var RGB = function(imageData) { 7594 vardata = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness;11454 let data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness; 7595 11455 for (i = 0; i < nPixels; i += 4) { 7596 11456 brightness = (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255; … … 7636 11496 var Validators_1 = require_Validators(); 7637 11497 var RGBA = function(imageData) { 7638 var data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha(), i, ia;7639 for ( i = 0; i < nPixels; i += 4) {7640 ia = 1 - alpha;11498 const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha(); 11499 for (let i = 0; i < nPixels; i += 4) { 11500 const ia = 1 - alpha; 7641 11501 data[i] = red * alpha + data[i] * ia; 7642 11502 data[i + 1] = green * alpha + data[i + 1] * ia; … … 7686 11546 exports.Sepia = void 0; 7687 11547 var Sepia = function(imageData) { 7688 vardata = imageData.data, nPixels = data.length, i, r, g, b;11548 let data = imageData.data, nPixels = data.length, i, r, g, b; 7689 11549 for (i = 0; i < nPixels; i += 4) { 7690 11550 r = data[i + 0]; … … 7707 11567 exports.Solarize = void 0; 7708 11568 var Solarize = function(imageData) { 7709 var data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4, y = h; 11569 const data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4; 11570 let y = h; 7710 11571 do { 7711 varoffsetY = (y - 1) * w4;7712 varx = w;11572 const offsetY = (y - 1) * w4; 11573 let x = w; 7713 11574 do { 7714 varoffset = offsetY + (x - 1) * 4;7715 varr = data[offset];7716 varg = data[offset + 1];7717 varb = data[offset + 2];11575 const offset = offsetY + (x - 1) * 4; 11576 let r = data[offset]; 11577 let g = data[offset + 1]; 11578 let b = data[offset + 2]; 7718 11579 if (r > 127) { 7719 11580 r = 255 - r; … … 7745 11606 var Validators_1 = require_Validators(); 7746 11607 var Threshold = function(imageData) { 7747 var level = this.threshold() * 255, data = imageData.data, len = data.length, i;7748 for ( i = 0; i < len; i += 1) {11608 const level = this.threshold() * 255, data = imageData.data, len = data.length; 11609 for (let i = 0; i < len; i += 1) { 7749 11610 data[i] = data[i] < level ? 0 : 255; 7750 11611 }
Note:
See TracChangeset
for help on using the changeset viewer.