konva 9.3.15 → 9.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/konva.js +821 -801
  2. package/konva.min.js +3 -3
  3. package/lib/Animation.js +1 -1
  4. package/lib/BezierFunctions.js +1 -2
  5. package/lib/Canvas.js +9 -9
  6. package/lib/Container.d.ts +1 -1
  7. package/lib/Container.js +29 -29
  8. package/lib/Context.d.ts +2 -2
  9. package/lib/Context.js +28 -28
  10. package/lib/DragAndDrop.d.ts +2 -2
  11. package/lib/DragAndDrop.js +6 -4
  12. package/lib/Factory.d.ts +18 -8
  13. package/lib/Factory.js +17 -16
  14. package/lib/Global.js +1 -1
  15. package/lib/Group.js +1 -1
  16. package/lib/Layer.js +17 -17
  17. package/lib/Node.d.ts +2 -2
  18. package/lib/Node.js +89 -89
  19. package/lib/PointerEvents.js +5 -6
  20. package/lib/Shape.d.ts +5 -0
  21. package/lib/Shape.js +37 -37
  22. package/lib/Stage.d.ts +2 -2
  23. package/lib/Stage.js +32 -31
  24. package/lib/Tween.js +31 -27
  25. package/lib/Util.d.ts +4 -4
  26. package/lib/Util.js +66 -65
  27. package/lib/Validators.d.ts +9 -9
  28. package/lib/Validators.js +12 -13
  29. package/lib/_CoreInternals.d.ts +8 -8
  30. package/lib/_FullInternals.d.ts +8 -8
  31. package/lib/filters/Blur.js +7 -6
  32. package/lib/filters/Brighten.js +2 -2
  33. package/lib/filters/Contrast.js +4 -3
  34. package/lib/filters/Emboss.js +22 -21
  35. package/lib/filters/Enhance.js +8 -7
  36. package/lib/filters/Grayscale.js +3 -3
  37. package/lib/filters/HSL.js +7 -7
  38. package/lib/filters/HSV.js +7 -7
  39. package/lib/filters/Invert.js +2 -2
  40. package/lib/filters/Kaleidoscope.js +44 -44
  41. package/lib/filters/Mask.js +58 -57
  42. package/lib/filters/Noise.js +2 -2
  43. package/lib/filters/Pixelate.js +1 -1
  44. package/lib/filters/Posterize.js +2 -2
  45. package/lib/filters/RGB.js +3 -4
  46. package/lib/filters/RGBA.js +3 -3
  47. package/lib/filters/Sepia.js +5 -5
  48. package/lib/filters/Solarize.js +8 -7
  49. package/lib/filters/Threshold.js +2 -2
  50. package/lib/shapes/Arc.js +1 -1
  51. package/lib/shapes/Arrow.js +12 -12
  52. package/lib/shapes/Ellipse.js +1 -1
  53. package/lib/shapes/Image.js +3 -3
  54. package/lib/shapes/Label.d.ts +3 -1
  55. package/lib/shapes/Label.js +6 -6
  56. package/lib/shapes/Line.d.ts +1 -1
  57. package/lib/shapes/Line.js +14 -14
  58. package/lib/shapes/Path.js +62 -62
  59. package/lib/shapes/Rect.js +1 -1
  60. package/lib/shapes/RegularPolygon.js +6 -6
  61. package/lib/shapes/Ring.js +1 -1
  62. package/lib/shapes/Sprite.js +9 -9
  63. package/lib/shapes/Star.js +5 -5
  64. package/lib/shapes/Text.js +48 -44
  65. package/lib/shapes/TextPath.js +25 -25
  66. package/lib/shapes/Transformer.d.ts +1 -1
  67. package/lib/shapes/Transformer.js +64 -64
  68. package/package.json +15 -17
package/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v9.3.15
8
+ * Konva JavaScript Framework v9.3.17
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Mon Sep 09 2024
11
+ * Date: Mon Dec 23 2024
12
12
  *
13
13
  * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
14
14
  * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@@ -35,7 +35,7 @@
35
35
  : {};
36
36
  const Konva$2 = {
37
37
  _global: glob,
38
- version: '9.3.15',
38
+ version: '9.3.17',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -249,7 +249,7 @@
249
249
  * @returns {Object} 2D point(x, y)
250
250
  */
251
251
  point(point) {
252
- var m = this.m;
252
+ const m = this.m;
253
253
  return {
254
254
  x: m[0] * point.x + m[2] * point.y + m[4],
255
255
  y: m[1] * point.x + m[3] * point.y + m[5],
@@ -291,12 +291,12 @@
291
291
  * @returns {Konva.Transform}
292
292
  */
293
293
  rotate(rad) {
294
- var c = Math.cos(rad);
295
- var s = Math.sin(rad);
296
- var m11 = this.m[0] * c + this.m[2] * s;
297
- var m12 = this.m[1] * c + this.m[3] * s;
298
- var m21 = this.m[0] * -s + this.m[2] * c;
299
- var m22 = this.m[1] * -s + this.m[3] * c;
294
+ const c = Math.cos(rad);
295
+ const s = Math.sin(rad);
296
+ const m11 = this.m[0] * c + this.m[2] * s;
297
+ const m12 = this.m[1] * c + this.m[3] * s;
298
+ const m21 = this.m[0] * -s + this.m[2] * c;
299
+ const m22 = this.m[1] * -s + this.m[3] * c;
300
300
  this.m[0] = m11;
301
301
  this.m[1] = m12;
302
302
  this.m[2] = m21;
@@ -324,10 +324,10 @@
324
324
  * @returns {Konva.Transform}
325
325
  */
326
326
  skew(sx, sy) {
327
- var m11 = this.m[0] + this.m[2] * sy;
328
- var m12 = this.m[1] + this.m[3] * sy;
329
- var m21 = this.m[2] + this.m[0] * sx;
330
- var m22 = this.m[3] + this.m[1] * sx;
327
+ const m11 = this.m[0] + this.m[2] * sy;
328
+ const m12 = this.m[1] + this.m[3] * sy;
329
+ const m21 = this.m[2] + this.m[0] * sx;
330
+ const m22 = this.m[3] + this.m[1] * sx;
331
331
  this.m[0] = m11;
332
332
  this.m[1] = m12;
333
333
  this.m[2] = m21;
@@ -342,12 +342,12 @@
342
342
  * @returns {Konva.Transform}
343
343
  */
344
344
  multiply(matrix) {
345
- var m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];
346
- var m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];
347
- var m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];
348
- var m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];
349
- var dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];
350
- var dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];
345
+ const m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];
346
+ const m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];
347
+ const m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];
348
+ const m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];
349
+ const dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];
350
+ const dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];
351
351
  this.m[0] = m11;
352
352
  this.m[1] = m12;
353
353
  this.m[2] = m21;
@@ -363,13 +363,13 @@
363
363
  * @returns {Konva.Transform}
364
364
  */
365
365
  invert() {
366
- var d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);
367
- var m0 = this.m[3] * d;
368
- var m1 = -this.m[1] * d;
369
- var m2 = -this.m[2] * d;
370
- var m3 = this.m[0] * d;
371
- var m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);
372
- var m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
366
+ const d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);
367
+ const m0 = this.m[3] * d;
368
+ const m1 = -this.m[1] * d;
369
+ const m2 = -this.m[2] * d;
370
+ const m3 = this.m[0] * d;
371
+ const m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);
372
+ const m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
373
373
  this.m[0] = m0;
374
374
  this.m[1] = m1;
375
375
  this.m[2] = m2;
@@ -393,14 +393,14 @@
393
393
  * @returns {Konva.Transform}
394
394
  */
395
395
  decompose() {
396
- var a = this.m[0];
397
- var b = this.m[1];
398
- var c = this.m[2];
399
- var d = this.m[3];
400
- var e = this.m[4];
401
- var f = this.m[5];
402
- var delta = a * d - b * c;
403
- let result = {
396
+ const a = this.m[0];
397
+ const b = this.m[1];
398
+ const c = this.m[2];
399
+ const d = this.m[3];
400
+ const e = this.m[4];
401
+ const f = this.m[5];
402
+ const delta = a * d - b * c;
403
+ const result = {
404
404
  x: e,
405
405
  y: f,
406
406
  rotation: 0,
@@ -411,7 +411,7 @@
411
411
  };
412
412
  // Apply the QR-like decomposition.
413
413
  if (a != 0 || b != 0) {
414
- var r = Math.sqrt(a * a + b * b);
414
+ const r = Math.sqrt(a * a + b * b);
415
415
  result.rotation = b > 0 ? Math.acos(a / r) : -Math.acos(a / r);
416
416
  result.scaleX = r;
417
417
  result.scaleY = delta / r;
@@ -419,7 +419,7 @@
419
419
  result.skewY = 0;
420
420
  }
421
421
  else if (c != 0 || d != 0) {
422
- var s = Math.sqrt(c * c + d * d);
422
+ const s = Math.sqrt(c * c + d * d);
423
423
  result.rotation =
424
424
  Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
425
425
  result.scaleX = delta / s;
@@ -433,7 +433,7 @@
433
433
  }
434
434
  }
435
435
  // CONSTANTS
436
- var OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH$1 = '#', EMPTY_STRING$1 = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = {
436
+ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH$1 = '#', EMPTY_STRING$1 = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = {
437
437
  aliceblue: [240, 248, 255],
438
438
  antiquewhite: [250, 235, 215],
439
439
  aqua: [0, 255, 255],
@@ -583,7 +583,8 @@
583
583
  whitesmoke: [245, 245, 245],
584
584
  yellow: [255, 255, 0],
585
585
  yellowgreen: [154, 205, 5],
586
- }, RGB_REGEX = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/, animQueue = [];
586
+ }, RGB_REGEX = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;
587
+ let animQueue = [];
587
588
  const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
588
589
  function (f) {
589
590
  setTimeout(f, 60);
@@ -627,7 +628,7 @@
627
628
  if (typeof selector !== 'string') {
628
629
  return false;
629
630
  }
630
- var firstChar = selector[0];
631
+ const firstChar = selector[0];
631
632
  return (firstChar === '#' ||
632
633
  firstChar === '.' ||
633
634
  firstChar === firstChar.toUpperCase());
@@ -658,7 +659,7 @@
658
659
  }
659
660
  },
660
661
  createCanvasElement() {
661
- var canvas = document.createElement('canvas');
662
+ const canvas = document.createElement('canvas');
662
663
  // on some environments canvas.style is readonly
663
664
  try {
664
665
  canvas.style = canvas.style || {};
@@ -682,7 +683,7 @@
682
683
  */
683
684
  _urlToImage(url, callback) {
684
685
  // if arg is a string, then it's a data url
685
- var imageObj = Util.createImageElement();
686
+ const imageObj = Util.createImageElement();
686
687
  imageObj.onload = function () {
687
688
  callback(imageObj);
688
689
  };
@@ -693,7 +694,7 @@
693
694
  },
694
695
  _hexToRgb(hex) {
695
696
  hex = hex.replace(HASH$1, EMPTY_STRING$1);
696
- var bigint = parseInt(hex, 16);
697
+ const bigint = parseInt(hex, 16);
697
698
  return {
698
699
  r: (bigint >> 16) & 255,
699
700
  g: (bigint >> 8) & 255,
@@ -708,7 +709,7 @@
708
709
  * shape.fill(Konva.Util.getRandomColor());
709
710
  */
710
711
  getRandomColor() {
711
- var randColor = ((Math.random() * 0xffffff) << 0).toString(16);
712
+ let randColor = ((Math.random() * 0xffffff) << 0).toString(16);
712
713
  while (randColor.length < 6) {
713
714
  randColor = ZERO + randColor;
714
715
  }
@@ -726,7 +727,7 @@
726
727
  * var rgb = Konva.Util.getRGB('rgb(0,0,255)');
727
728
  */
728
729
  getRGB(color) {
729
- var rgb;
730
+ let rgb;
730
731
  // color string
731
732
  if (color in COLORS) {
732
733
  rgb = COLORS[color];
@@ -773,7 +774,7 @@
773
774
  },
774
775
  // Parse named css color. Like "green"
775
776
  _namedColorToRBA(str) {
776
- var c = COLORS[str.toLowerCase()];
777
+ const c = COLORS[str.toLowerCase()];
777
778
  if (!c) {
778
779
  return null;
779
780
  }
@@ -788,7 +789,7 @@
788
789
  _rgbColorToRGBA(str) {
789
790
  if (str.indexOf('rgb(') === 0) {
790
791
  str = str.match(/rgb\(([^)]+)\)/)[1];
791
- var parts = str.split(/ *, */).map(Number);
792
+ const parts = str.split(/ *, */).map(Number);
792
793
  return {
793
794
  r: parts[0],
794
795
  g: parts[1],
@@ -801,7 +802,7 @@
801
802
  _rgbaColorToRGBA(str) {
802
803
  if (str.indexOf('rgba(') === 0) {
803
804
  str = str.match(/rgba\(([^)]+)\)/)[1];
804
- var parts = str.split(/ *, */).map((n, index) => {
805
+ const parts = str.split(/ *, */).map((n, index) => {
805
806
  if (n.slice(-1) === '%') {
806
807
  return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
807
808
  }
@@ -934,8 +935,8 @@
934
935
  r2.y + r2.height < r1.y);
935
936
  },
936
937
  cloneObject(obj) {
937
- var retObj = {};
938
- for (var key in obj) {
938
+ const retObj = {};
939
+ for (const key in obj) {
939
940
  if (this._isPlainObject(obj[key])) {
940
941
  retObj[key] = this.cloneObject(obj[key]);
941
942
  }
@@ -984,7 +985,7 @@
984
985
  console.warn(KONVA_WARNING + str);
985
986
  },
986
987
  each(obj, func) {
987
- for (var key in obj) {
988
+ for (const key in obj) {
988
989
  func(key, obj[key]);
989
990
  }
990
991
  },
@@ -992,15 +993,15 @@
992
993
  return left <= val && val < right;
993
994
  },
994
995
  _getProjectionToSegment(x1, y1, x2, y2, x3, y3) {
995
- var x, y, dist;
996
- var pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
996
+ let x, y, dist;
997
+ const pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
997
998
  if (pd2 == 0) {
998
999
  x = x1;
999
1000
  y = y1;
1000
1001
  dist = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
1001
1002
  }
1002
1003
  else {
1003
- var u = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2;
1004
+ const u = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2;
1004
1005
  if (u < 0) {
1005
1006
  x = x1;
1006
1007
  y = y1;
@@ -1022,15 +1023,15 @@
1022
1023
  // line as array of points.
1023
1024
  // line might be closed
1024
1025
  _getProjectionToLine(pt, line, isClosed) {
1025
- var pc = Util.cloneObject(pt);
1026
- var dist = Number.MAX_VALUE;
1026
+ const pc = Util.cloneObject(pt);
1027
+ let dist = Number.MAX_VALUE;
1027
1028
  line.forEach(function (p1, i) {
1028
1029
  if (!isClosed && i === line.length - 1) {
1029
1030
  return;
1030
1031
  }
1031
- var p2 = line[(i + 1) % line.length];
1032
- var proj = Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y);
1033
- var px = proj[0], py = proj[1], pdist = proj[2];
1032
+ const p2 = line[(i + 1) % line.length];
1033
+ const proj = Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y);
1034
+ const px = proj[0], py = proj[1], pdist = proj[2];
1034
1035
  if (pdist < dist) {
1035
1036
  pc.x = px;
1036
1037
  pc.y = py;
@@ -1040,36 +1041,36 @@
1040
1041
  return pc;
1041
1042
  },
1042
1043
  _prepareArrayForTween(startArray, endArray, isClosed) {
1043
- var n, start = [], end = [];
1044
+ const start = [], end = [];
1044
1045
  if (startArray.length > endArray.length) {
1045
- var temp = endArray;
1046
+ const temp = endArray;
1046
1047
  endArray = startArray;
1047
1048
  startArray = temp;
1048
1049
  }
1049
- for (n = 0; n < startArray.length; n += 2) {
1050
+ for (let n = 0; n < startArray.length; n += 2) {
1050
1051
  start.push({
1051
1052
  x: startArray[n],
1052
1053
  y: startArray[n + 1],
1053
1054
  });
1054
1055
  }
1055
- for (n = 0; n < endArray.length; n += 2) {
1056
+ for (let n = 0; n < endArray.length; n += 2) {
1056
1057
  end.push({
1057
1058
  x: endArray[n],
1058
1059
  y: endArray[n + 1],
1059
1060
  });
1060
1061
  }
1061
- var newStart = [];
1062
+ const newStart = [];
1062
1063
  end.forEach(function (point) {
1063
- var pr = Util._getProjectionToLine(point, start, isClosed);
1064
+ const pr = Util._getProjectionToLine(point, start, isClosed);
1064
1065
  newStart.push(pr.x);
1065
1066
  newStart.push(pr.y);
1066
1067
  });
1067
1068
  return newStart;
1068
1069
  },
1069
1070
  _prepareToStringify(obj) {
1070
- var desc;
1071
+ let desc;
1071
1072
  obj.visitedByCircularReferenceRemoval = true;
1072
- for (var key in obj) {
1073
+ for (const key in obj) {
1073
1074
  if (!(obj.hasOwnProperty(key) && obj[key] && typeof obj[key] == 'object')) {
1074
1075
  continue;
1075
1076
  }
@@ -1097,7 +1098,7 @@
1097
1098
  },
1098
1099
  // very simplified version of Object.assign
1099
1100
  _assign(target, source) {
1100
- for (var key in source) {
1101
+ for (const key in source) {
1101
1102
  target[key] = source[key];
1102
1103
  }
1103
1104
  return target;
@@ -1233,7 +1234,7 @@
1233
1234
  return function (val, attr) {
1234
1235
  const isString = Util._isString(val);
1235
1236
  const isGradient = Object.prototype.toString.call(val) === '[object CanvasGradient]' ||
1236
- (val && val.addColorStop);
1237
+ (val && val['addColorStop']);
1237
1238
  if (!(isString || isGradient)) {
1238
1239
  Util.warn(_formatValue(val) +
1239
1240
  ' is a not valid value for "' +
@@ -1307,7 +1308,8 @@
1307
1308
  }
1308
1309
  }
1309
1310
 
1310
- var GET = 'get', SET$1 = 'set';
1311
+ const GET = 'get';
1312
+ const SET$1 = 'set';
1311
1313
  const Factory = {
1312
1314
  addGetterSetter(constructor, attr, def, validator, after) {
1313
1315
  Factory.addGetter(constructor, attr, def);
@@ -1319,7 +1321,7 @@
1319
1321
  constructor.prototype[method] =
1320
1322
  constructor.prototype[method] ||
1321
1323
  function () {
1322
- var val = this.attrs[attr];
1324
+ const val = this.attrs[attr];
1323
1325
  return val === undefined ? def : val;
1324
1326
  };
1325
1327
  },
@@ -1343,27 +1345,27 @@
1343
1345
  };
1344
1346
  },
1345
1347
  addComponentsGetterSetter(constructor, attr, components, validator, after) {
1346
- var len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET$1 + capitalize(attr), n, component;
1348
+ const len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET$1 + capitalize(attr);
1347
1349
  // getter
1348
1350
  constructor.prototype[getter] = function () {
1349
- var ret = {};
1350
- for (n = 0; n < len; n++) {
1351
- component = components[n];
1351
+ const ret = {};
1352
+ for (let n = 0; n < len; n++) {
1353
+ const component = components[n];
1352
1354
  ret[component] = this.getAttr(attr + capitalize(component));
1353
1355
  }
1354
1356
  return ret;
1355
1357
  };
1356
- var basicValidator = getComponentValidator(components);
1358
+ const basicValidator = getComponentValidator(components);
1357
1359
  // setter
1358
1360
  constructor.prototype[setter] = function (val) {
1359
- var oldVal = this.attrs[attr], key;
1361
+ const oldVal = this.attrs[attr];
1360
1362
  if (validator) {
1361
- val = validator.call(this, val);
1363
+ val = validator.call(this, val, attr);
1362
1364
  }
1363
1365
  if (basicValidator) {
1364
1366
  basicValidator.call(this, val, attr);
1365
1367
  }
1366
- for (key in val) {
1368
+ for (const key in val) {
1367
1369
  if (!val.hasOwnProperty(key)) {
1368
1370
  continue;
1369
1371
  }
@@ -1396,12 +1398,12 @@
1396
1398
  },
1397
1399
  addDeprecatedGetterSetter(constructor, attr, def, validator) {
1398
1400
  Util.error('Adding deprecated ' + attr);
1399
- var method = GET + Util._capitalize(attr);
1400
- var message = attr +
1401
+ const method = GET + Util._capitalize(attr);
1402
+ const message = attr +
1401
1403
  ' property is deprecated and will be removed soon. Look at Konva change log for more information.';
1402
1404
  constructor.prototype[method] = function () {
1403
1405
  Util.error(message);
1404
- var val = this.attrs[attr];
1406
+ const val = this.attrs[attr];
1405
1407
  return val === undefined ? def : val;
1406
1408
  };
1407
1409
  Factory.addSetter(constructor, attr, validator, function () {
@@ -1411,9 +1413,9 @@
1411
1413
  },
1412
1414
  backCompat(constructor, methods) {
1413
1415
  Util.each(methods, function (oldMethodName, newMethodName) {
1414
- var method = constructor.prototype[newMethodName];
1415
- var oldGetter = GET + Util._capitalize(oldMethodName);
1416
- var oldSetter = SET$1 + Util._capitalize(oldMethodName);
1416
+ const method = constructor.prototype[newMethodName];
1417
+ const oldGetter = GET + Util._capitalize(oldMethodName);
1418
+ const oldSetter = SET$1 + Util._capitalize(oldMethodName);
1417
1419
  function deprecated() {
1418
1420
  method.apply(this, arguments);
1419
1421
  Util.error('"' +
@@ -1433,9 +1435,9 @@
1433
1435
  };
1434
1436
 
1435
1437
  function simplifyArray(arr) {
1436
- var retArr = [], len = arr.length, util = Util, n, val;
1437
- for (n = 0; n < len; n++) {
1438
- val = arr[n];
1438
+ const retArr = [], len = arr.length, util = Util;
1439
+ for (let n = 0; n < len; n++) {
1440
+ let val = arr[n];
1439
1441
  if (util._isNumber(val)) {
1440
1442
  val = Math.round(val * 1000) / 1000;
1441
1443
  }
@@ -1446,7 +1448,7 @@
1446
1448
  }
1447
1449
  return retArr;
1448
1450
  }
1449
- var COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([', CLOSE_BRACKET_PAREN = '])', SEMICOLON = ';', DOUBLE_PAREN = '()',
1451
+ const COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([', CLOSE_BRACKET_PAREN = '])', SEMICOLON = ';', DOUBLE_PAREN = '()',
1450
1452
  // EMPTY_STRING = '',
1451
1453
  EQUALS = '=',
1452
1454
  // SET = 'set',
@@ -1484,7 +1486,7 @@
1484
1486
  'transform',
1485
1487
  'translate',
1486
1488
  ];
1487
- var CONTEXT_PROPERTIES = [
1489
+ const CONTEXT_PROPERTIES = [
1488
1490
  'fillStyle',
1489
1491
  'strokeStyle',
1490
1492
  'shadowColor',
@@ -1581,7 +1583,7 @@
1581
1583
  }
1582
1584
  }
1583
1585
  getTrace(relaxed, rounded) {
1584
- var traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args;
1586
+ let traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args;
1585
1587
  for (n = 0; n < len; n++) {
1586
1588
  trace = traceArr[n];
1587
1589
  method = trace.method;
@@ -1619,7 +1621,7 @@
1619
1621
  this.traceArr = [];
1620
1622
  }
1621
1623
  _trace(str) {
1622
- var traceArr = this.traceArr, len;
1624
+ let traceArr = this.traceArr, len;
1623
1625
  traceArr.push(str);
1624
1626
  len = traceArr.length;
1625
1627
  if (len >= traceArrMax) {
@@ -1632,7 +1634,7 @@
1632
1634
  * @name Konva.Context#reset
1633
1635
  */
1634
1636
  reset() {
1635
- var pixelRatio = this.getCanvas().getPixelRatio();
1637
+ const pixelRatio = this.getCanvas().getPixelRatio();
1636
1638
  this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0);
1637
1639
  }
1638
1640
  /**
@@ -1655,7 +1657,7 @@
1655
1657
  * @param {Number} [bounds.height]
1656
1658
  */
1657
1659
  clear(bounds) {
1658
- var canvas = this.getCanvas();
1660
+ const canvas = this.getCanvas();
1659
1661
  if (bounds) {
1660
1662
  this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0);
1661
1663
  }
@@ -1670,7 +1672,7 @@
1670
1672
  }
1671
1673
  }
1672
1674
  _applyOpacity(shape) {
1673
- var absOpacity = shape.getAbsoluteOpacity();
1675
+ const absOpacity = shape.getAbsoluteOpacity();
1674
1676
  if (absOpacity !== 1) {
1675
1677
  this.setAttr('globalAlpha', absOpacity);
1676
1678
  }
@@ -1742,7 +1744,7 @@
1742
1744
  * @name Konva.Context#createImageData
1743
1745
  */
1744
1746
  createImageData(width, height) {
1745
- var a = arguments;
1747
+ const a = arguments;
1746
1748
  if (a.length === 2) {
1747
1749
  return this._context.createImageData(width, height);
1748
1750
  }
@@ -1781,7 +1783,7 @@
1781
1783
  */
1782
1784
  drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
1783
1785
  // this._context.drawImage(...arguments);
1784
- var a = arguments, _context = this._context;
1786
+ const a = arguments, _context = this._context;
1785
1787
  if (a.length === 3) {
1786
1788
  _context.drawImage(image, sx, sy);
1787
1789
  }
@@ -2014,10 +2016,10 @@
2014
2016
  this._context.translate(x, y);
2015
2017
  }
2016
2018
  _enableTrace() {
2017
- var that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;
2019
+ let that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;
2018
2020
  // to prevent creating scope function at each loop
2019
- var func = function (methodName) {
2020
- var origMethod = that[methodName], ret;
2021
+ const func = function (methodName) {
2022
+ let origMethod = that[methodName], ret;
2021
2023
  that[methodName] = function () {
2022
2024
  args = simplifyArray(Array.prototype.slice.call(arguments, 0));
2023
2025
  ret = origMethod.apply(that, arguments);
@@ -2035,8 +2037,8 @@
2035
2037
  // attrs
2036
2038
  that.setAttr = function () {
2037
2039
  origSetter.apply(that, arguments);
2038
- var prop = arguments[0];
2039
- var val = arguments[1];
2040
+ const prop = arguments[0];
2041
+ let val = arguments[1];
2040
2042
  if (prop === 'shadowOffsetX' ||
2041
2043
  prop === 'shadowOffsetY' ||
2042
2044
  prop === 'shadowBlur') {
@@ -2050,7 +2052,7 @@
2050
2052
  }
2051
2053
  _applyGlobalCompositeOperation(node) {
2052
2054
  const op = node.attrs.globalCompositeOperation;
2053
- var def = !op || op === 'source-over';
2055
+ const def = !op || op === 'source-over';
2054
2056
  if (!def) {
2055
2057
  this.setAttr('globalCompositeOperation', op);
2056
2058
  }
@@ -2074,7 +2076,7 @@
2074
2076
  });
2075
2077
  }
2076
2078
  _fillColor(shape) {
2077
- var fill = shape.fill();
2079
+ const fill = shape.fill();
2078
2080
  this.setAttr('fillStyle', fill);
2079
2081
  shape._fillFunc(this);
2080
2082
  }
@@ -2083,7 +2085,7 @@
2083
2085
  shape._fillFunc(this);
2084
2086
  }
2085
2087
  _fillLinearGradient(shape) {
2086
- var grd = shape._getLinearGradient();
2088
+ const grd = shape._getLinearGradient();
2087
2089
  if (grd) {
2088
2090
  this.setAttr('fillStyle', grd);
2089
2091
  shape._fillFunc(this);
@@ -2136,20 +2138,20 @@
2136
2138
  const start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
2137
2139
  if (colorStops) {
2138
2140
  // build color stops
2139
- for (var n = 0; n < colorStops.length; n += 2) {
2141
+ for (let n = 0; n < colorStops.length; n += 2) {
2140
2142
  grd.addColorStop(colorStops[n], colorStops[n + 1]);
2141
2143
  }
2142
2144
  this.setAttr('strokeStyle', grd);
2143
2145
  }
2144
2146
  }
2145
2147
  _stroke(shape) {
2146
- var dash = shape.dash(),
2148
+ const dash = shape.dash(),
2147
2149
  // ignore strokeScaleEnabled for Text
2148
2150
  strokeScaleEnabled = shape.getStrokeScaleEnabled();
2149
2151
  if (shape.hasStroke()) {
2150
2152
  if (!strokeScaleEnabled) {
2151
2153
  this.save();
2152
- var pixelRatio = this.getCanvas().getPixelRatio();
2154
+ const pixelRatio = this.getCanvas().getPixelRatio();
2153
2155
  this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
2154
2156
  }
2155
2157
  this._applyLineCap(shape);
@@ -2161,7 +2163,7 @@
2161
2163
  if (!shape.getShadowForStrokeEnabled()) {
2162
2164
  this.setAttr('shadowColor', 'rgba(0,0,0,0)');
2163
2165
  }
2164
- var hasLinearGradient = shape.getStrokeLinearGradientColorStops();
2166
+ const hasLinearGradient = shape.getStrokeLinearGradientColorStops();
2165
2167
  if (hasLinearGradient) {
2166
2168
  this._strokeLinearGradient(shape);
2167
2169
  }
@@ -2176,7 +2178,7 @@
2176
2178
  }
2177
2179
  _applyShadow(shape) {
2178
2180
  var _a, _b, _c;
2179
- var color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : 'black', blur = (_b = shape.getShadowBlur()) !== null && _b !== void 0 ? _b : 5, offset = (_c = shape.getShadowOffset()) !== null && _c !== void 0 ? _c : {
2181
+ 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 : {
2180
2182
  x: 0,
2181
2183
  y: 0,
2182
2184
  }, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
@@ -2210,12 +2212,12 @@
2210
2212
  const strokeScaleEnabled = shape.getStrokeScaleEnabled();
2211
2213
  if (!strokeScaleEnabled) {
2212
2214
  this.save();
2213
- var pixelRatio = this.getCanvas().getPixelRatio();
2215
+ const pixelRatio = this.getCanvas().getPixelRatio();
2214
2216
  this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
2215
2217
  }
2216
2218
  this._applyLineCap(shape);
2217
- var hitStrokeWidth = shape.hitStrokeWidth();
2218
- var strokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth;
2219
+ const hitStrokeWidth = shape.hitStrokeWidth();
2220
+ const strokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth;
2219
2221
  this.setAttr('lineWidth', strokeWidth);
2220
2222
  this.setAttr('strokeStyle', shape.colorKey);
2221
2223
  shape._strokeFuncHit(this);
@@ -2227,15 +2229,15 @@
2227
2229
  }
2228
2230
 
2229
2231
  // calculate pixel ratio
2230
- var _pixelRatio;
2232
+ let _pixelRatio;
2231
2233
  function getDevicePixelRatio() {
2232
2234
  if (_pixelRatio) {
2233
2235
  return _pixelRatio;
2234
2236
  }
2235
- var canvas = Util.createCanvasElement();
2236
- var context = canvas.getContext('2d');
2237
+ const canvas = Util.createCanvasElement();
2238
+ const context = canvas.getContext('2d');
2237
2239
  _pixelRatio = (function () {
2238
- var devicePixelRatio = Konva$2._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
2240
+ const devicePixelRatio = Konva$2._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
2239
2241
  context.mozBackingStorePixelRatio ||
2240
2242
  context.msBackingStorePixelRatio ||
2241
2243
  context.oBackingStorePixelRatio ||
@@ -2263,8 +2265,8 @@
2263
2265
  this.width = 0;
2264
2266
  this.height = 0;
2265
2267
  this.isCache = false;
2266
- var conf = config || {};
2267
- var pixelRatio = conf.pixelRatio || Konva$2.pixelRatio || getDevicePixelRatio();
2268
+ const conf = config || {};
2269
+ const pixelRatio = conf.pixelRatio || Konva$2.pixelRatio || getDevicePixelRatio();
2268
2270
  this.pixelRatio = pixelRatio;
2269
2271
  this._canvas = Util.createCanvasElement();
2270
2272
  // set inline styles
@@ -2289,7 +2291,7 @@
2289
2291
  return this.pixelRatio;
2290
2292
  }
2291
2293
  setPixelRatio(pixelRatio) {
2292
- var previousRatio = this.pixelRatio;
2294
+ const previousRatio = this.pixelRatio;
2293
2295
  this.pixelRatio = pixelRatio;
2294
2296
  this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio);
2295
2297
  }
@@ -2297,14 +2299,14 @@
2297
2299
  // take into account pixel ratio
2298
2300
  this.width = this._canvas.width = width * this.pixelRatio;
2299
2301
  this._canvas.style.width = width + 'px';
2300
- var pixelRatio = this.pixelRatio, _context = this.getContext()._context;
2302
+ const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
2301
2303
  _context.scale(pixelRatio, pixelRatio);
2302
2304
  }
2303
2305
  setHeight(height) {
2304
2306
  // take into account pixel ratio
2305
2307
  this.height = this._canvas.height = height * this.pixelRatio;
2306
2308
  this._canvas.style.height = height + 'px';
2307
- var pixelRatio = this.pixelRatio, _context = this.getContext()._context;
2309
+ const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
2308
2310
  _context.scale(pixelRatio, pixelRatio);
2309
2311
  }
2310
2312
  getWidth() {
@@ -2385,7 +2387,7 @@
2385
2387
 
2386
2388
  const DD = {
2387
2389
  get isDragging() {
2388
- var flag = false;
2390
+ let flag = false;
2389
2391
  DD._dragElements.forEach((elem) => {
2390
2392
  if (elem.dragStatus === 'dragging') {
2391
2393
  flag = true;
@@ -2396,7 +2398,7 @@
2396
2398
  justDragged: false,
2397
2399
  get node() {
2398
2400
  // return first dragging node
2399
- var node;
2401
+ let node;
2400
2402
  DD._dragElements.forEach((elem) => {
2401
2403
  node = elem.node;
2402
2404
  });
@@ -2422,8 +2424,8 @@
2422
2424
  return;
2423
2425
  }
2424
2426
  if (elem.dragStatus !== 'dragging') {
2425
- var dragDistance = node.dragDistance();
2426
- var distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));
2427
+ const dragDistance = node.dragDistance();
2428
+ const distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));
2427
2429
  if (distance < dragDistance) {
2428
2430
  return;
2429
2431
  }
@@ -2500,14 +2502,17 @@
2500
2502
  if (Konva$2.isBrowser) {
2501
2503
  window.addEventListener('mouseup', DD._endDragBefore, true);
2502
2504
  window.addEventListener('touchend', DD._endDragBefore, true);
2505
+ // add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843
2506
+ window.addEventListener('touchcancel', DD._endDragBefore, true);
2503
2507
  window.addEventListener('mousemove', DD._drag);
2504
2508
  window.addEventListener('touchmove', DD._drag);
2505
2509
  window.addEventListener('mouseup', DD._endDragAfter, false);
2506
2510
  window.addEventListener('touchend', DD._endDragAfter, false);
2511
+ window.addEventListener('touchcancel', DD._endDragAfter, false);
2507
2512
  }
2508
2513
 
2509
2514
  // CONSTANTS
2510
- var ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER$1 = 'mouseenter', MOUSELEAVE$1 = 'mouseleave', SET = 'set', SHAPE = 'Shape', SPACE$1 = ' ', STAGE$1 = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR$1 = [
2515
+ const ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER$1 = 'mouseenter', MOUSELEAVE$1 = 'mouseleave', SET = 'set', SHAPE = 'Shape', SPACE$1 = ' ', STAGE$1 = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR$1 = [
2511
2516
  'xChange.konva',
2512
2517
  'yChange.konva',
2513
2518
  'scaleXChange.konva',
@@ -2590,11 +2595,11 @@
2590
2595
  }
2591
2596
  }
2592
2597
  _getCache(attr, privateGetter) {
2593
- var cache = this._cache.get(attr);
2598
+ let cache = this._cache.get(attr);
2594
2599
  // for transform the cache can be NOT empty
2595
2600
  // but we still need to recalculate it if it is dirty
2596
- var isTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM;
2597
- var invalid = cache === undefined || (isTransform && cache.dirty === true);
2601
+ const isTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM;
2602
+ const invalid = cache === undefined || (isTransform && cache.dirty === true);
2598
2603
  // if not cached, we need to set it using the private getter method.
2599
2604
  if (invalid) {
2600
2605
  cache = privateGetter.call(this);
@@ -2692,8 +2697,8 @@
2692
2697
  * });
2693
2698
  */
2694
2699
  cache(config) {
2695
- var conf = config || {};
2696
- var rect = {};
2700
+ const conf = config || {};
2701
+ let rect = {};
2697
2702
  // don't call getClientRect if we have all attributes
2698
2703
  // it means call it only if have one undefined
2699
2704
  if (conf.x === undefined ||
@@ -2705,7 +2710,7 @@
2705
2710
  relativeTo: this.getParent() || undefined,
2706
2711
  });
2707
2712
  }
2708
- var width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? Math.floor(rect.x) : conf.x, y = conf.y === undefined ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
2713
+ let width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? Math.floor(rect.x) : conf.x, y = conf.y === undefined ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
2709
2714
  if (!width || !height) {
2710
2715
  Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
2711
2716
  return;
@@ -2728,7 +2733,7 @@
2728
2733
  // // height += 1;
2729
2734
  // }
2730
2735
  // console.log({ x, y, width, height }, rect);
2731
- var cachedSceneCanvas = new SceneCanvas({
2736
+ const cachedSceneCanvas = new SceneCanvas({
2732
2737
  pixelRatio: pixelRatio,
2733
2738
  width: width,
2734
2739
  height: height,
@@ -2836,16 +2841,16 @@
2836
2841
  throw new Error('abstract "getClientRect" method call');
2837
2842
  }
2838
2843
  _transformedRect(rect, top) {
2839
- var points = [
2844
+ const points = [
2840
2845
  { x: rect.x, y: rect.y },
2841
2846
  { x: rect.x + rect.width, y: rect.y },
2842
2847
  { x: rect.x + rect.width, y: rect.y + rect.height },
2843
2848
  { x: rect.x, y: rect.y + rect.height },
2844
2849
  ];
2845
- var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
2846
- var trans = this.getAbsoluteTransform(top);
2850
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
2851
+ const trans = this.getAbsoluteTransform(top);
2847
2852
  points.forEach(function (point) {
2848
- var transformed = trans.point(point);
2853
+ const transformed = trans.point(point);
2849
2854
  if (minX === undefined) {
2850
2855
  minX = maxX = transformed.x;
2851
2856
  minY = maxY = transformed.y;
@@ -2868,23 +2873,23 @@
2868
2873
  context._applyGlobalCompositeOperation(this);
2869
2874
  const canvasCache = this._getCanvasCache();
2870
2875
  context.translate(canvasCache.x, canvasCache.y);
2871
- var cacheCanvas = this._getCachedSceneCanvas();
2872
- var ratio = cacheCanvas.pixelRatio;
2876
+ const cacheCanvas = this._getCachedSceneCanvas();
2877
+ const ratio = cacheCanvas.pixelRatio;
2873
2878
  context.drawImage(cacheCanvas._canvas, 0, 0, cacheCanvas.width / ratio, cacheCanvas.height / ratio);
2874
2879
  context.restore();
2875
2880
  }
2876
2881
  _drawCachedHitCanvas(context) {
2877
- var canvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit;
2882
+ const canvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit;
2878
2883
  context.save();
2879
2884
  context.translate(canvasCache.x, canvasCache.y);
2880
2885
  context.drawImage(hitCanvas._canvas, 0, 0, hitCanvas.width / hitCanvas.pixelRatio, hitCanvas.height / hitCanvas.pixelRatio);
2881
2886
  context.restore();
2882
2887
  }
2883
2888
  _getCachedSceneCanvas() {
2884
- var filters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter;
2889
+ let filters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter;
2885
2890
  if (filters) {
2886
2891
  if (!this._filterUpToDate) {
2887
- var ratio = sceneCanvas.pixelRatio;
2892
+ const ratio = sceneCanvas.pixelRatio;
2888
2893
  filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio);
2889
2894
  try {
2890
2895
  len = filters.length;
@@ -2982,7 +2987,7 @@
2982
2987
  if (arguments.length === 3) {
2983
2988
  return this._delegate.apply(this, arguments);
2984
2989
  }
2985
- var events = evtStr.split(SPACE$1), len = events.length, n, event, parts, baseEvent, name;
2990
+ let events = evtStr.split(SPACE$1), len = events.length, n, event, parts, baseEvent, name;
2986
2991
  /*
2987
2992
  * loop through types and attach event listeners to
2988
2993
  * each one. eg. 'click mouseover.namespace mouseout'
@@ -3026,7 +3031,7 @@
3026
3031
  * node.off('click.foo');
3027
3032
  */
3028
3033
  off(evtStr, callback) {
3029
- var events = (evtStr || '').split(SPACE$1), len = events.length, n, t, event, parts, baseEvent, name;
3034
+ let events = (evtStr || '').split(SPACE$1), len = events.length, n, t, event, parts, baseEvent, name;
3030
3035
  this._cache && this._cache.delete(ALL_LISTENERS);
3031
3036
  if (!evtStr) {
3032
3037
  // remove all events
@@ -3054,7 +3059,7 @@
3054
3059
  }
3055
3060
  // some event aliases for third party integration like HammerJS
3056
3061
  dispatchEvent(evt) {
3057
- var e = {
3062
+ const e = {
3058
3063
  target: this,
3059
3064
  type: evt.type,
3060
3065
  evt: evt,
@@ -3075,10 +3080,10 @@
3075
3080
  }
3076
3081
  // like node.on
3077
3082
  _delegate(event, selector, handler) {
3078
- var stopNode = this;
3083
+ const stopNode = this;
3079
3084
  this.on(event, function (evt) {
3080
- var targets = evt.target.findAncestors(selector, true, stopNode);
3081
- for (var i = 0; i < targets.length; i++) {
3085
+ const targets = evt.target.findAncestors(selector, true, stopNode);
3086
+ for (let i = 0; i < targets.length; i++) {
3082
3087
  evt = Util.cloneObject(evt);
3083
3088
  evt.currentTarget = targets[i];
3084
3089
  handler.call(targets[i], evt);
@@ -3115,7 +3120,7 @@
3115
3120
  // every cached attr that is calculated via node tree
3116
3121
  // traversal must be cleared when removing a node
3117
3122
  this._clearCaches();
3118
- var parent = this.getParent();
3123
+ const parent = this.getParent();
3119
3124
  if (parent && parent.children) {
3120
3125
  parent.children.splice(this.index, 1);
3121
3126
  parent._setChildrenIndices();
@@ -3145,7 +3150,7 @@
3145
3150
  * var x = node.getAttr('x');
3146
3151
  */
3147
3152
  getAttr(attr) {
3148
- var method = 'get' + Util._capitalize(attr);
3153
+ const method = 'get' + Util._capitalize(attr);
3149
3154
  if (Util._isFunction(this[method])) {
3150
3155
  return this[method]();
3151
3156
  }
@@ -3163,7 +3168,7 @@
3163
3168
  * })
3164
3169
  */
3165
3170
  getAncestors() {
3166
- var parent = this.getParent(), ancestors = [];
3171
+ let parent = this.getParent(), ancestors = [];
3167
3172
  while (parent) {
3168
3173
  ancestors.push(parent);
3169
3174
  parent = parent.getParent();
@@ -3193,7 +3198,7 @@
3193
3198
  */
3194
3199
  setAttrs(config) {
3195
3200
  this._batchTransformChanges(() => {
3196
- var key, method;
3201
+ let key, method;
3197
3202
  if (!config) {
3198
3203
  return this;
3199
3204
  }
@@ -3279,8 +3284,8 @@
3279
3284
  if (top) {
3280
3285
  return this._isVisible(top) && this._isListening(top);
3281
3286
  }
3282
- var layer = this.getLayer();
3283
- var layerUnderDrag = false;
3287
+ const layer = this.getLayer();
3288
+ let layerUnderDrag = false;
3284
3289
  DD._dragElements.forEach((elem) => {
3285
3290
  if (elem.dragStatus !== 'dragging') {
3286
3291
  return;
@@ -3292,7 +3297,7 @@
3292
3297
  layerUnderDrag = true;
3293
3298
  }
3294
3299
  });
3295
- var dragSkip = !skipDragCheck &&
3300
+ const dragSkip = !skipDragCheck &&
3296
3301
  !Konva$2.hitOnDragEnabled &&
3297
3302
  (layerUnderDrag || Konva$2.isTransforming());
3298
3303
  return this.isListening() && this.isVisible() && !dragSkip;
@@ -3328,7 +3333,7 @@
3328
3333
  * @returns {Integer}
3329
3334
  */
3330
3335
  getAbsoluteZIndex() {
3331
- var depth = this.getDepth(), that = this, index = 0, nodes, len, n, child;
3336
+ let depth = this.getDepth(), that = this, index = 0, nodes, len, n, child;
3332
3337
  function addChildren(children) {
3333
3338
  nodes = [];
3334
3339
  len = children.length;
@@ -3361,7 +3366,7 @@
3361
3366
  * @returns {Integer}
3362
3367
  */
3363
3368
  getDepth() {
3364
- var depth = 0, parent = this.parent;
3369
+ let depth = 0, parent = this.parent;
3365
3370
  while (parent) {
3366
3371
  depth++;
3367
3372
  parent = parent.parent;
@@ -3413,11 +3418,11 @@
3413
3418
  return null;
3414
3419
  }
3415
3420
  // get pointer (say mouse or touch) position
3416
- var pos = stage.getPointerPosition();
3421
+ const pos = stage.getPointerPosition();
3417
3422
  if (!pos) {
3418
3423
  return null;
3419
3424
  }
3420
- var transform = this.getAbsoluteTransform().copy();
3425
+ const transform = this.getAbsoluteTransform().copy();
3421
3426
  // to detect relative position we need to invert transform
3422
3427
  transform.invert();
3423
3428
  // now we can find relative point
@@ -3453,7 +3458,7 @@
3453
3458
  // "true" is not a node, but it will just allow skip all caching
3454
3459
  top = true;
3455
3460
  }
3456
- var absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Transform(), offset = this.offset();
3461
+ const absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Transform(), offset = this.offset();
3457
3462
  // clone the matrix array
3458
3463
  absoluteTransform.m = absoluteMatrix.slice();
3459
3464
  absoluteTransform.translate(offset.x, offset.y);
@@ -3466,7 +3471,7 @@
3466
3471
  this.attrs.y = y;
3467
3472
  // important, use non cached value
3468
3473
  this._clearCache(TRANSFORM);
3469
- var it = this._getAbsoluteTransform().copy();
3474
+ const it = this._getAbsoluteTransform().copy();
3470
3475
  it.invert();
3471
3476
  it.translate(pos.x, pos.y);
3472
3477
  pos = {
@@ -3480,7 +3485,7 @@
3480
3485
  return this;
3481
3486
  }
3482
3487
  _setTransform(trans) {
3483
- var key;
3488
+ let key;
3484
3489
  for (key in trans) {
3485
3490
  this.attrs[key] = trans[key];
3486
3491
  }
@@ -3488,7 +3493,7 @@
3488
3493
  // this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
3489
3494
  }
3490
3495
  _clearTransform() {
3491
- var trans = {
3496
+ const trans = {
3492
3497
  x: this.x(),
3493
3498
  y: this.y(),
3494
3499
  rotation: this.rotation(),
@@ -3527,7 +3532,7 @@
3527
3532
  * });
3528
3533
  */
3529
3534
  move(change) {
3530
- var changeX = change.x, changeY = change.y, x = this.x(), y = this.y();
3535
+ let changeX = change.x, changeY = change.y, x = this.x(), y = this.y();
3531
3536
  if (changeX !== undefined) {
3532
3537
  x += changeX;
3533
3538
  }
@@ -3538,7 +3543,7 @@
3538
3543
  return this;
3539
3544
  }
3540
3545
  _eachAncestorReverse(func, top) {
3541
- var family = [], parent = this.getParent(), len, n;
3546
+ let family = [], parent = this.getParent(), len, n;
3542
3547
  // if top node is defined, and this node is top node,
3543
3548
  // there's no need to build a family tree. just execute
3544
3549
  // func with this because it will be the only node
@@ -3578,7 +3583,7 @@
3578
3583
  Util.warn('Node has no parent. moveToTop function is ignored.');
3579
3584
  return false;
3580
3585
  }
3581
- var index = this.index, len = this.parent.getChildren().length;
3586
+ const index = this.index, len = this.parent.getChildren().length;
3582
3587
  if (index < len - 1) {
3583
3588
  this.parent.children.splice(index, 1);
3584
3589
  this.parent.children.push(this);
@@ -3598,7 +3603,7 @@
3598
3603
  Util.warn('Node has no parent. moveUp function is ignored.');
3599
3604
  return false;
3600
3605
  }
3601
- var index = this.index, len = this.parent.getChildren().length;
3606
+ const index = this.index, len = this.parent.getChildren().length;
3602
3607
  if (index < len - 1) {
3603
3608
  this.parent.children.splice(index, 1);
3604
3609
  this.parent.children.splice(index + 1, 0, this);
@@ -3618,7 +3623,7 @@
3618
3623
  Util.warn('Node has no parent. moveDown function is ignored.');
3619
3624
  return false;
3620
3625
  }
3621
- var index = this.index;
3626
+ const index = this.index;
3622
3627
  if (index > 0) {
3623
3628
  this.parent.children.splice(index, 1);
3624
3629
  this.parent.children.splice(index - 1, 0, this);
@@ -3638,7 +3643,7 @@
3638
3643
  Util.warn('Node has no parent. moveToBottom function is ignored.');
3639
3644
  return false;
3640
3645
  }
3641
- var index = this.index;
3646
+ const index = this.index;
3642
3647
  if (index > 0) {
3643
3648
  this.parent.children.splice(index, 1);
3644
3649
  this.parent.children.unshift(this);
@@ -3659,7 +3664,7 @@
3659
3664
  (this.parent.children.length - 1) +
3660
3665
  '.');
3661
3666
  }
3662
- var index = this.index;
3667
+ const index = this.index;
3663
3668
  this.parent.children.splice(index, 1);
3664
3669
  this.parent.children.splice(zIndex, 0, this);
3665
3670
  this.parent._setChildrenIndices();
@@ -3675,8 +3680,8 @@
3675
3680
  return this._getCache(ABSOLUTE_OPACITY, this._getAbsoluteOpacity);
3676
3681
  }
3677
3682
  _getAbsoluteOpacity() {
3678
- var absOpacity = this.opacity();
3679
- var parent = this.getParent();
3683
+ let absOpacity = this.opacity();
3684
+ const parent = this.getParent();
3680
3685
  if (parent && !parent._isUnderCache) {
3681
3686
  absOpacity *= parent.getAbsoluteOpacity();
3682
3687
  }
@@ -3707,7 +3712,7 @@
3707
3712
  * @returns {Object}
3708
3713
  */
3709
3714
  toObject() {
3710
- var attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;
3715
+ let attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;
3711
3716
  const obj = {
3712
3717
  attrs: {},
3713
3718
  className: this.getClassName(),
@@ -3764,11 +3769,11 @@
3764
3769
  * var parentGroups = node.findAncestors('Group');
3765
3770
  */
3766
3771
  findAncestors(selector, includeSelf, stopNode) {
3767
- var res = [];
3772
+ const res = [];
3768
3773
  if (includeSelf && this._isMatch(selector)) {
3769
3774
  res.push(this);
3770
3775
  }
3771
- var ancestor = this.parent;
3776
+ let ancestor = this.parent;
3772
3777
  while (ancestor) {
3773
3778
  if (ancestor === stopNode) {
3774
3779
  return res;
@@ -3806,7 +3811,7 @@
3806
3811
  if (typeof selector === 'function') {
3807
3812
  return selector(this);
3808
3813
  }
3809
- var selectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel;
3814
+ let selectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel;
3810
3815
  for (n = 0; n < len; n++) {
3811
3816
  sel = selectorArr[n];
3812
3817
  if (!Util.isValidSelector(sel)) {
@@ -3841,7 +3846,7 @@
3841
3846
  * @returns {Konva.Layer}
3842
3847
  */
3843
3848
  getLayer() {
3844
- var parent = this.getParent();
3849
+ const parent = this.getParent();
3845
3850
  return parent ? parent.getLayer() : null;
3846
3851
  }
3847
3852
  /**
@@ -3854,7 +3859,7 @@
3854
3859
  return this._getCache(STAGE$1, this._getStage);
3855
3860
  }
3856
3861
  _getStage() {
3857
- var parent = this.getParent();
3862
+ const parent = this.getParent();
3858
3863
  if (parent) {
3859
3864
  return parent.getStage();
3860
3865
  }
@@ -3916,13 +3921,13 @@
3916
3921
  }
3917
3922
  }
3918
3923
  _getAbsoluteTransform(top) {
3919
- var at;
3924
+ let at;
3920
3925
  // we we need position relative to an ancestor, we will iterate for all
3921
3926
  if (top) {
3922
3927
  at = new Transform();
3923
3928
  // start with stage and traverse downwards to self
3924
3929
  this._eachAncestorReverse(function (node) {
3925
- var transformsEnabled = node.transformsEnabled();
3930
+ const transformsEnabled = node.transformsEnabled();
3926
3931
  if (transformsEnabled === 'all') {
3927
3932
  at.multiply(node.getTransform());
3928
3933
  }
@@ -3942,7 +3947,7 @@
3942
3947
  else {
3943
3948
  at.reset();
3944
3949
  }
3945
- var transformsEnabled = this.transformsEnabled();
3950
+ const transformsEnabled = this.transformsEnabled();
3946
3951
  if (transformsEnabled === 'all') {
3947
3952
  at.multiply(this.getTransform());
3948
3953
  }
@@ -3972,7 +3977,7 @@
3972
3977
  // do not cache this calculations,
3973
3978
  // because it use cache transform
3974
3979
  // this is special logic for caching with some shapes with shadow
3975
- var parent = this;
3980
+ let parent = this;
3976
3981
  while (parent) {
3977
3982
  if (parent._isUnderCache) {
3978
3983
  top = parent;
@@ -4017,12 +4022,12 @@
4017
4022
  }
4018
4023
  _getTransform() {
4019
4024
  var _a, _b;
4020
- var m = this._cache.get(TRANSFORM) || new Transform();
4025
+ const m = this._cache.get(TRANSFORM) || new Transform();
4021
4026
  m.reset();
4022
4027
  // I was trying to use attributes directly here
4023
4028
  // but it doesn't work for Transformer well
4024
4029
  // because it overwrite x,y getters
4025
- var x = this.x(), y = this.y(), rotation = Konva$2.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;
4030
+ const x = this.x(), y = this.y(), rotation = Konva$2.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;
4026
4031
  if (x !== 0 || y !== 0) {
4027
4032
  m.translate(x, y);
4028
4033
  }
@@ -4060,12 +4065,12 @@
4060
4065
  */
4061
4066
  clone(obj) {
4062
4067
  // instantiate new node
4063
- var attrs = Util.cloneObject(this.attrs), key, allListeners, len, n, listener;
4068
+ let attrs = Util.cloneObject(this.attrs), key, allListeners, len, n, listener;
4064
4069
  // apply attr overrides
4065
4070
  for (key in obj) {
4066
4071
  attrs[key] = obj[key];
4067
4072
  }
4068
- var node = new this.constructor(attrs);
4073
+ const node = new this.constructor(attrs);
4069
4074
  // copy over listeners
4070
4075
  for (key in this.eventListeners) {
4071
4076
  allListeners = this.eventListeners[key];
@@ -4089,8 +4094,8 @@
4089
4094
  }
4090
4095
  _toKonvaCanvas(config) {
4091
4096
  config = config || {};
4092
- var box = this.getClientRect();
4093
- var stage = this.getStage(), x = config.x !== undefined ? config.x : Math.floor(box.x), y = config.y !== undefined ? config.y : Math.floor(box.y), pixelRatio = config.pixelRatio || 1, canvas = new SceneCanvas({
4097
+ const box = this.getClientRect();
4098
+ const stage = this.getStage(), x = config.x !== undefined ? config.x : Math.floor(box.x), y = config.y !== undefined ? config.y : Math.floor(box.y), pixelRatio = config.pixelRatio || 1, canvas = new SceneCanvas({
4094
4099
  width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0),
4095
4100
  height: config.height ||
4096
4101
  Math.ceil(box.height) ||
@@ -4162,8 +4167,8 @@
4162
4167
  */
4163
4168
  toDataURL(config) {
4164
4169
  config = config || {};
4165
- var mimeType = config.mimeType || null, quality = config.quality || null;
4166
- var url = this._toKonvaCanvas(config).toDataURL(mimeType, quality);
4170
+ const mimeType = config.mimeType || null, quality = config.quality || null;
4171
+ const url = this._toKonvaCanvas(config).toDataURL(mimeType, quality);
4167
4172
  if (config.callback) {
4168
4173
  config.callback(url);
4169
4174
  }
@@ -4295,7 +4300,7 @@
4295
4300
  }
4296
4301
  }
4297
4302
  _off(type, name, callback) {
4298
- var evtListeners = this.eventListeners[type], i, evtName, handler;
4303
+ let evtListeners = this.eventListeners[type], i, evtName, handler;
4299
4304
  for (i = 0; i < evtListeners.length; i++) {
4300
4305
  evtName = evtListeners[i].name;
4301
4306
  handler = evtListeners[i].handler;
@@ -4334,8 +4339,8 @@
4334
4339
  */
4335
4340
  addName(name) {
4336
4341
  if (!this.hasName(name)) {
4337
- var oldName = this.name();
4338
- var newName = oldName ? oldName + ' ' + name : name;
4342
+ const oldName = this.name();
4343
+ const newName = oldName ? oldName + ' ' + name : name;
4339
4344
  this.name(newName);
4340
4345
  }
4341
4346
  return this;
@@ -4361,7 +4366,7 @@
4361
4366
  return false;
4362
4367
  }
4363
4368
  // if name is '' the "names" will be [''], so I added extra check above
4364
- var names = (fullName || '').split(/\s/g);
4369
+ const names = (fullName || '').split(/\s/g);
4365
4370
  return names.indexOf(name) !== -1;
4366
4371
  }
4367
4372
  /**
@@ -4377,8 +4382,8 @@
4377
4382
  * node.name(); // return 'red'
4378
4383
  */
4379
4384
  removeName(name) {
4380
- var names = (this.name() || '').split(/\s/g);
4381
- var index = names.indexOf(name);
4385
+ const names = (this.name() || '').split(/\s/g);
4386
+ const index = names.indexOf(name);
4382
4387
  if (index !== -1) {
4383
4388
  names.splice(index, 1);
4384
4389
  this.name(names.join(' '));
@@ -4396,7 +4401,7 @@
4396
4401
  * node.setAttr('x', 5);
4397
4402
  */
4398
4403
  setAttr(attr, val) {
4399
- var func = this[SET + Util._capitalize(attr)];
4404
+ const func = this[SET + Util._capitalize(attr)];
4400
4405
  if (Util._isFunction(func)) {
4401
4406
  func.call(this, val);
4402
4407
  }
@@ -4413,7 +4418,7 @@
4413
4418
  }
4414
4419
  }
4415
4420
  _setAttr(key, val) {
4416
- var oldVal = this.attrs[key];
4421
+ const oldVal = this.attrs[key];
4417
4422
  if (oldVal === val && !Util.isObject(val)) {
4418
4423
  return;
4419
4424
  }
@@ -4429,7 +4434,7 @@
4429
4434
  this._requestDraw();
4430
4435
  }
4431
4436
  _setComponentAttr(key, component, val) {
4432
- var oldVal;
4437
+ let oldVal;
4433
4438
  if (val !== undefined) {
4434
4439
  oldVal = this.attrs[key];
4435
4440
  if (!oldVal) {
@@ -4444,7 +4449,7 @@
4444
4449
  if (evt && this.nodeType === SHAPE) {
4445
4450
  evt.target = this;
4446
4451
  }
4447
- var shouldStop = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&
4452
+ const shouldStop = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&
4448
4453
  ((compareShape &&
4449
4454
  (this === compareShape ||
4450
4455
  (this.isAncestorOf && this.isAncestorOf(compareShape)))) ||
@@ -4452,7 +4457,7 @@
4452
4457
  if (!shouldStop) {
4453
4458
  this._fire(eventType, evt);
4454
4459
  // simulate event bubbling
4455
- var stopBubble = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&
4460
+ const stopBubble = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&
4456
4461
  compareShape &&
4457
4462
  compareShape.isAncestorOf &&
4458
4463
  compareShape.isAncestorOf(this) &&
@@ -4521,13 +4526,13 @@
4521
4526
  }
4522
4527
  // drag & drop
4523
4528
  _createDragElement(evt) {
4524
- var pointerId = evt ? evt.pointerId : undefined;
4525
- var stage = this.getStage();
4526
- var ap = this.getAbsolutePosition();
4529
+ const pointerId = evt ? evt.pointerId : undefined;
4530
+ const stage = this.getStage();
4531
+ const ap = this.getAbsolutePosition();
4527
4532
  if (!stage) {
4528
4533
  return;
4529
4534
  }
4530
- var pos = stage._getPointerById(pointerId) ||
4535
+ const pos = stage._getPointerById(pointerId) ||
4531
4536
  stage._changedPointerPositions[0] ||
4532
4537
  ap;
4533
4538
  DD._dragElements.set(this._id, {
@@ -4565,11 +4570,11 @@
4565
4570
  if (!pos) {
4566
4571
  return;
4567
4572
  }
4568
- var newNodePos = {
4573
+ let newNodePos = {
4569
4574
  x: pos.x - elem.offset.x,
4570
4575
  y: pos.y - elem.offset.y,
4571
4576
  };
4572
- var dbf = this.dragBoundFunc();
4577
+ const dbf = this.dragBoundFunc();
4573
4578
  if (dbf !== undefined) {
4574
4579
  const bounded = dbf.call(this, newNodePos, evt);
4575
4580
  if (!bounded) {
@@ -4616,15 +4621,15 @@
4616
4621
  _listenDrag() {
4617
4622
  this._dragCleanup();
4618
4623
  this.on('mousedown.konva touchstart.konva', function (evt) {
4619
- var shouldCheckButton = evt.evt['button'] !== undefined;
4620
- var canDrag = !shouldCheckButton || Konva$2.dragButtons.indexOf(evt.evt['button']) >= 0;
4624
+ const shouldCheckButton = evt.evt['button'] !== undefined;
4625
+ const canDrag = !shouldCheckButton || Konva$2.dragButtons.indexOf(evt.evt['button']) >= 0;
4621
4626
  if (!canDrag) {
4622
4627
  return;
4623
4628
  }
4624
4629
  if (this.isDragging()) {
4625
4630
  return;
4626
4631
  }
4627
- var hasDraggingChild = false;
4632
+ let hasDraggingChild = false;
4628
4633
  DD._dragElements.forEach((elem) => {
4629
4634
  if (this.isAncestorOf(elem.node)) {
4630
4635
  hasDraggingChild = true;
@@ -4649,7 +4654,7 @@
4649
4654
  * if this node is currently in
4650
4655
  * drag and drop mode
4651
4656
  */
4652
- var stage = this.getStage();
4657
+ const stage = this.getStage();
4653
4658
  if (!stage) {
4654
4659
  return;
4655
4660
  }
@@ -4716,7 +4721,7 @@
4716
4721
  return this._createNode(data, container);
4717
4722
  }
4718
4723
  static _createNode(obj, container) {
4719
- var className = Node.prototype.getClassName.call(obj), children = obj.children, no, len, n;
4724
+ let className = Node.prototype.getClassName.call(obj), children = obj.children, no, len, n;
4720
4725
  // if container was passed in, add it to attrs
4721
4726
  if (container) {
4722
4727
  obj.attrs.container = container;
@@ -5057,7 +5062,7 @@
5057
5062
  * // set offset y
5058
5063
  * node.offsetY(3);
5059
5064
  */
5060
- addGetterSetter(Node, 'dragDistance', null, getNumberValidator());
5065
+ addGetterSetter(Node, 'dragDistance', undefined, getNumberValidator());
5061
5066
  /**
5062
5067
  * get/set drag distance
5063
5068
  * @name Konva.Node#dragDistance
@@ -5141,7 +5146,7 @@
5141
5146
  * shape.preventDefault(false);
5142
5147
  */
5143
5148
  addGetterSetter(Node, 'preventDefault', true, getBooleanValidator());
5144
- addGetterSetter(Node, 'filters', null, function (val) {
5149
+ addGetterSetter(Node, 'filters', undefined, function (val) {
5145
5150
  this._filterUpToDate = false;
5146
5151
  return val;
5147
5152
  });
@@ -5328,7 +5333,7 @@
5328
5333
  return this.children || [];
5329
5334
  }
5330
5335
  const children = this.children || [];
5331
- var results = [];
5336
+ const results = [];
5332
5337
  children.forEach(function (child) {
5333
5338
  if (filterFunc(child)) {
5334
5339
  results.push(child);
@@ -5399,7 +5404,7 @@
5399
5404
  return this;
5400
5405
  }
5401
5406
  if (children.length > 1) {
5402
- for (var i = 0; i < children.length; i++) {
5407
+ for (let i = 0; i < children.length; i++) {
5403
5408
  this.add(children[i]);
5404
5409
  }
5405
5410
  return this;
@@ -5492,11 +5497,11 @@
5492
5497
  * })
5493
5498
  */
5494
5499
  findOne(selector) {
5495
- var result = this._generalFind(selector, true);
5500
+ const result = this._generalFind(selector, true);
5496
5501
  return result.length > 0 ? result[0] : undefined;
5497
5502
  }
5498
5503
  _generalFind(selector, findOne) {
5499
- var retArr = [];
5504
+ const retArr = [];
5500
5505
  this._descendants((node) => {
5501
5506
  const valid = node._isMatch(selector);
5502
5507
  if (valid) {
@@ -5529,7 +5534,7 @@
5529
5534
  }
5530
5535
  // extenders
5531
5536
  toObject() {
5532
- var obj = Node.prototype.toObject.call(this);
5537
+ const obj = Node.prototype.toObject.call(this);
5533
5538
  obj.children = [];
5534
5539
  this.getChildren().forEach((child) => {
5535
5540
  obj.children.push(child.toObject());
@@ -5544,7 +5549,7 @@
5544
5549
  * @param {Konva.Node} node
5545
5550
  */
5546
5551
  isAncestorOf(node) {
5547
- var parent = node.getParent();
5552
+ let parent = node.getParent();
5548
5553
  while (parent) {
5549
5554
  if (parent._id === this._id) {
5550
5555
  return true;
@@ -5555,7 +5560,7 @@
5555
5560
  }
5556
5561
  clone(obj) {
5557
5562
  // call super method
5558
- var node = Node.prototype.clone.call(this, obj);
5563
+ const node = Node.prototype.clone.call(this, obj);
5559
5564
  this.getChildren().forEach(function (no) {
5560
5565
  node.add(no.clone());
5561
5566
  });
@@ -5575,7 +5580,7 @@
5575
5580
  * @returns {Array} array of shapes
5576
5581
  */
5577
5582
  getAllIntersections(pos) {
5578
- var arr = [];
5583
+ const arr = [];
5579
5584
  this.find('Shape').forEach((shape) => {
5580
5585
  if (shape.isVisible() && shape.intersects(pos)) {
5581
5586
  arr.push(shape);
@@ -5603,14 +5608,14 @@
5603
5608
  this._requestDraw();
5604
5609
  }
5605
5610
  drawScene(can, top, bufferCanvas) {
5606
- var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
5607
- var caching = canvas && canvas.isCache;
5611
+ const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
5612
+ const caching = canvas && canvas.isCache;
5608
5613
  if (!this.isVisible() && !caching) {
5609
5614
  return this;
5610
5615
  }
5611
5616
  if (cachedSceneCanvas) {
5612
5617
  context.save();
5613
- var m = this.getAbsoluteTransform(top).getMatrix();
5618
+ const m = this.getAbsoluteTransform(top).getMatrix();
5614
5619
  context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
5615
5620
  this._drawCachedSceneCanvas(context);
5616
5621
  context.restore();
@@ -5624,10 +5629,10 @@
5624
5629
  if (!this.shouldDrawHit(top)) {
5625
5630
  return this;
5626
5631
  }
5627
- var layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
5632
+ const layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
5628
5633
  if (cachedHitCanvas) {
5629
5634
  context.save();
5630
- var m = this.getAbsoluteTransform(top).getMatrix();
5635
+ const m = this.getAbsoluteTransform(top).getMatrix();
5631
5636
  context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
5632
5637
  this._drawCachedHitCanvas(context);
5633
5638
  context.restore();
@@ -5639,13 +5644,13 @@
5639
5644
  }
5640
5645
  _drawChildren(drawMethod, canvas, top, bufferCanvas) {
5641
5646
  var _a;
5642
- var context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (typeof clipWidth === 'number' && typeof clipHeight === 'number') ||
5647
+ const context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (typeof clipWidth === 'number' && typeof clipHeight === 'number') ||
5643
5648
  clipFunc;
5644
5649
  const selfCache = top === this;
5645
5650
  if (hasClip) {
5646
5651
  context.save();
5647
- var transform = this.getAbsoluteTransform(top);
5648
- var m = transform.getMatrix();
5652
+ const transform = this.getAbsoluteTransform(top);
5653
+ let m = transform.getMatrix();
5649
5654
  context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
5650
5655
  context.beginPath();
5651
5656
  let clipArgs;
@@ -5653,15 +5658,15 @@
5653
5658
  clipArgs = clipFunc.call(this, context, this);
5654
5659
  }
5655
5660
  else {
5656
- var clipX = this.clipX();
5657
- var clipY = this.clipY();
5661
+ const clipX = this.clipX();
5662
+ const clipY = this.clipY();
5658
5663
  context.rect(clipX || 0, clipY || 0, clipWidth, clipHeight);
5659
5664
  }
5660
5665
  context.clip.apply(context, clipArgs);
5661
5666
  m = transform.copy().invert().getMatrix();
5662
5667
  context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
5663
5668
  }
5664
- var hasComposition = !selfCache &&
5669
+ const hasComposition = !selfCache &&
5665
5670
  this.globalCompositeOperation() !== 'source-over' &&
5666
5671
  drawMethod === 'drawScene';
5667
5672
  if (hasComposition) {
@@ -5680,22 +5685,22 @@
5680
5685
  }
5681
5686
  getClientRect(config = {}) {
5682
5687
  var _a;
5683
- var skipTransform = config.skipTransform;
5684
- var relativeTo = config.relativeTo;
5685
- var minX, minY, maxX, maxY;
5686
- var selfRect = {
5688
+ const skipTransform = config.skipTransform;
5689
+ const relativeTo = config.relativeTo;
5690
+ let minX, minY, maxX, maxY;
5691
+ let selfRect = {
5687
5692
  x: Infinity,
5688
5693
  y: Infinity,
5689
5694
  width: 0,
5690
5695
  height: 0,
5691
5696
  };
5692
- var that = this;
5697
+ const that = this;
5693
5698
  (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
5694
5699
  // skip invisible children
5695
5700
  if (!child.visible()) {
5696
5701
  return;
5697
5702
  }
5698
- var rect = child.getClientRect({
5703
+ const rect = child.getClientRect({
5699
5704
  relativeTo: that,
5700
5705
  skipShadow: config.skipShadow,
5701
5706
  skipStroke: config.skipStroke,
@@ -5719,10 +5724,10 @@
5719
5724
  }
5720
5725
  });
5721
5726
  // if child is group we need to make sure it has visible shapes inside
5722
- var shapes = this.find('Shape');
5723
- var hasVisible = false;
5724
- for (var i = 0; i < shapes.length; i++) {
5725
- var shape = shapes[i];
5727
+ const shapes = this.find('Shape');
5728
+ let hasVisible = false;
5729
+ for (let i = 0; i < shapes.length; i++) {
5730
+ const shape = shapes[i];
5726
5731
  if (shape._isVisible(this)) {
5727
5732
  hasVisible = true;
5728
5733
  break;
@@ -5896,7 +5901,7 @@
5896
5901
  }
5897
5902
 
5898
5903
  // CONSTANTS
5899
- var STAGE = 'Stage', STRING = 'string', PX = 'px', MOUSEOUT = 'mouseout', MOUSELEAVE = 'mouseleave', MOUSEOVER = 'mouseover', MOUSEENTER = 'mouseenter', MOUSEMOVE = 'mousemove', MOUSEDOWN = 'mousedown', MOUSEUP = 'mouseup', POINTERMOVE = 'pointermove', POINTERDOWN = 'pointerdown', POINTERUP = 'pointerup', POINTERCANCEL = 'pointercancel', LOSTPOINTERCAPTURE = 'lostpointercapture', POINTEROUT = 'pointerout', POINTERLEAVE = 'pointerleave', POINTEROVER = 'pointerover', POINTERENTER = 'pointerenter', CONTEXTMENU = 'contextmenu', TOUCHSTART = 'touchstart', TOUCHEND = 'touchend', TOUCHMOVE = 'touchmove', TOUCHCANCEL = 'touchcancel', WHEEL = 'wheel', MAX_LAYERS_NUMBER = 5, EVENTS = [
5904
+ const STAGE = 'Stage', STRING = 'string', PX = 'px', MOUSEOUT = 'mouseout', MOUSELEAVE = 'mouseleave', MOUSEOVER = 'mouseover', MOUSEENTER = 'mouseenter', MOUSEMOVE = 'mousemove', MOUSEDOWN = 'mousedown', MOUSEUP = 'mouseup', POINTERMOVE = 'pointermove', POINTERDOWN = 'pointerdown', POINTERUP = 'pointerup', POINTERCANCEL = 'pointercancel', LOSTPOINTERCAPTURE = 'lostpointercapture', POINTEROUT = 'pointerout', POINTERLEAVE = 'pointerleave', POINTEROVER = 'pointerover', POINTERENTER = 'pointerenter', CONTEXTMENU = 'contextmenu', TOUCHSTART = 'touchstart', TOUCHEND = 'touchend', TOUCHMOVE = 'touchmove', TOUCHCANCEL = 'touchcancel', WHEEL = 'wheel', MAX_LAYERS_NUMBER = 5, EVENTS = [
5900
5905
  [MOUSEENTER, '_pointerenter'],
5901
5906
  [MOUSEDOWN, '_pointerdown'],
5902
5907
  [MOUSEMOVE, '_pointermove'],
@@ -6055,7 +6060,7 @@
6055
6060
  setContainer(container) {
6056
6061
  if (typeof container === STRING) {
6057
6062
  if (container.charAt(0) === '.') {
6058
- var className = container.slice(1);
6063
+ const className = container.slice(1);
6059
6064
  container = document.getElementsByClassName(className)[0];
6060
6065
  }
6061
6066
  else {
@@ -6090,8 +6095,8 @@
6090
6095
  * @name Konva.Stage#clear
6091
6096
  */
6092
6097
  clear() {
6093
- var layers = this.children, len = layers.length, n;
6094
- for (n = 0; n < len; n++) {
6098
+ const layers = this.children, len = layers.length;
6099
+ for (let n = 0; n < len; n++) {
6095
6100
  layers[n].clear();
6096
6101
  }
6097
6102
  return this;
@@ -6106,11 +6111,11 @@
6106
6111
  }
6107
6112
  destroy() {
6108
6113
  super.destroy();
6109
- var content = this.content;
6114
+ const content = this.content;
6110
6115
  if (content && Util._isInDocument(content)) {
6111
6116
  this.container().removeChild(content);
6112
6117
  }
6113
- var index = stages.indexOf(this);
6118
+ const index = stages.indexOf(this);
6114
6119
  if (index > -1) {
6115
6120
  stages.splice(index, 1);
6116
6121
  }
@@ -6154,13 +6159,13 @@
6154
6159
  config.y = config.y || 0;
6155
6160
  config.width = config.width || this.width();
6156
6161
  config.height = config.height || this.height();
6157
- var canvas = new SceneCanvas({
6162
+ const canvas = new SceneCanvas({
6158
6163
  width: config.width,
6159
6164
  height: config.height,
6160
6165
  pixelRatio: config.pixelRatio || 1,
6161
6166
  });
6162
- var _context = canvas.getContext()._context;
6163
- var layers = this.children;
6167
+ const _context = canvas.getContext()._context;
6168
+ const layers = this.children;
6164
6169
  if (config.x || config.y) {
6165
6170
  _context.translate(-1 * config.x, -1 * config.y);
6166
6171
  }
@@ -6168,7 +6173,7 @@
6168
6173
  if (!layer.isVisible()) {
6169
6174
  return;
6170
6175
  }
6171
- var layerCanvas = layer._toKonvaCanvas(config);
6176
+ const layerCanvas = layer._toKonvaCanvas(config);
6172
6177
  _context.drawImage(layerCanvas._canvas, config.x, config.y, layerCanvas.getWidth() / layerCanvas.getPixelRatio(), layerCanvas.getHeight() / layerCanvas.getPixelRatio());
6173
6178
  });
6174
6179
  return canvas;
@@ -6190,8 +6195,8 @@
6190
6195
  if (!pos) {
6191
6196
  return null;
6192
6197
  }
6193
- var layers = this.children, len = layers.length, end = len - 1, n;
6194
- for (n = end; n >= 0; n--) {
6198
+ const layers = this.children, len = layers.length, end = len - 1;
6199
+ for (let n = end; n >= 0; n--) {
6195
6200
  const shape = layers[n].getIntersection(pos);
6196
6201
  if (shape) {
6197
6202
  return shape;
@@ -6200,8 +6205,8 @@
6200
6205
  return null;
6201
6206
  }
6202
6207
  _resizeDOM() {
6203
- var width = this.width();
6204
- var height = this.height();
6208
+ const width = this.width();
6209
+ const height = this.height();
6205
6210
  if (this.content) {
6206
6211
  // set content dimensions
6207
6212
  this.content.style.width = width + PX;
@@ -6217,13 +6222,13 @@
6217
6222
  }
6218
6223
  add(layer, ...rest) {
6219
6224
  if (arguments.length > 1) {
6220
- for (var i = 0; i < arguments.length; i++) {
6225
+ for (let i = 0; i < arguments.length; i++) {
6221
6226
  this.add(arguments[i]);
6222
6227
  }
6223
6228
  return this;
6224
6229
  }
6225
6230
  super.add(layer);
6226
- var length = this.children.length;
6231
+ const length = this.children.length;
6227
6232
  if (length > MAX_LAYERS_NUMBER) {
6228
6233
  Util.warn('The stage has ' +
6229
6234
  length +
@@ -6307,8 +6312,8 @@
6307
6312
  return;
6308
6313
  }
6309
6314
  this.setPointersPositions(evt);
6310
- var targetShape = this._getTargetShape(eventType);
6311
- var eventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled;
6315
+ const targetShape = this._getTargetShape(eventType);
6316
+ const eventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled;
6312
6317
  if (targetShape && eventsEnabled) {
6313
6318
  targetShape._fireAndBubble(events.pointerout, { evt: evt });
6314
6319
  targetShape._fireAndBubble(events.pointerleave, { evt: evt });
@@ -6341,9 +6346,9 @@
6341
6346
  return;
6342
6347
  }
6343
6348
  this.setPointersPositions(evt);
6344
- var triggeredOnShape = false;
6349
+ let triggeredOnShape = false;
6345
6350
  this._changedPointerPositions.forEach((pos) => {
6346
- var shape = this.getIntersection(pos);
6351
+ const shape = this.getIntersection(pos);
6347
6352
  DD.justDragged = false;
6348
6353
  // probably we are staring a click
6349
6354
  Konva$2['_' + eventType + 'ListenClick'] = true;
@@ -6389,19 +6394,19 @@
6389
6394
  evt.preventDefault();
6390
6395
  }
6391
6396
  this.setPointersPositions(evt);
6392
- var eventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled;
6397
+ const eventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled;
6393
6398
  if (!eventsEnabled) {
6394
6399
  return;
6395
6400
  }
6396
- var processedShapesIds = {};
6401
+ const processedShapesIds = {};
6397
6402
  let triggeredOnShape = false;
6398
- var targetShape = this._getTargetShape(eventType);
6403
+ const targetShape = this._getTargetShape(eventType);
6399
6404
  this._changedPointerPositions.forEach((pos) => {
6400
6405
  const shape = (getCapturedShape(pos.id) ||
6401
6406
  this.getIntersection(pos));
6402
6407
  const pointerId = pos.id;
6403
6408
  const event = { evt: evt, pointerId };
6404
- var differentTarget = targetShape !== shape;
6409
+ const differentTarget = targetShape !== shape;
6405
6410
  if (differentTarget && targetShape) {
6406
6411
  targetShape._fireAndBubble(events.pointerout, { ...event }, shape);
6407
6412
  targetShape._fireAndBubble(events.pointerleave, { ...event }, shape);
@@ -6451,7 +6456,7 @@
6451
6456
  this.setPointersPositions(evt);
6452
6457
  const clickStartShape = this[eventType + 'ClickStartShape'];
6453
6458
  const clickEndShape = this[eventType + 'ClickEndShape'];
6454
- var processedShapesIds = {};
6459
+ const processedShapesIds = {};
6455
6460
  let triggeredOnShape = false;
6456
6461
  this._changedPointerPositions.forEach((pos) => {
6457
6462
  const shape = (getCapturedShape(pos.id) ||
@@ -6526,13 +6531,13 @@
6526
6531
  // TODO: are we sure we need to prevent default at all?
6527
6532
  // do not call this function on mobile because it prevent "click" event on all parent containers
6528
6533
  // but apps may listen to it.
6529
- if (evt.cancelable && eventType !== 'touch') {
6534
+ if (evt.cancelable && eventType !== 'touch' && eventType !== 'pointer') {
6530
6535
  evt.preventDefault();
6531
6536
  }
6532
6537
  }
6533
6538
  _contextmenu(evt) {
6534
6539
  this.setPointersPositions(evt);
6535
- var shape = this.getIntersection(this.getPointerPosition());
6540
+ const shape = this.getIntersection(this.getPointerPosition());
6536
6541
  if (shape && shape.isListening()) {
6537
6542
  shape._fireAndBubble(CONTEXTMENU, { evt: evt });
6538
6543
  }
@@ -6546,7 +6551,7 @@
6546
6551
  }
6547
6552
  _wheel(evt) {
6548
6553
  this.setPointersPositions(evt);
6549
- var shape = this.getIntersection(this.getPointerPosition());
6554
+ const shape = this.getIntersection(this.getPointerPosition());
6550
6555
  if (shape && shape.isListening()) {
6551
6556
  shape._fireAndBubble(WHEEL, { evt: evt });
6552
6557
  }
@@ -6585,7 +6590,8 @@
6585
6590
  * });
6586
6591
  */
6587
6592
  setPointersPositions(evt) {
6588
- var contentPosition = this._getContentPosition(), x = null, y = null;
6593
+ const contentPosition = this._getContentPosition();
6594
+ let x = null, y = null;
6589
6595
  evt = evt ? evt : window.event;
6590
6596
  // touch events
6591
6597
  if (evt.touches !== undefined) {
@@ -6635,7 +6641,7 @@
6635
6641
  scaleY: 1,
6636
6642
  };
6637
6643
  }
6638
- var rect = this.content.getBoundingClientRect();
6644
+ const rect = this.content.getBoundingClientRect();
6639
6645
  return {
6640
6646
  top: rect.top,
6641
6647
  left: rect.left,
@@ -6658,7 +6664,7 @@
6658
6664
  if (!Konva$2.isBrowser) {
6659
6665
  return;
6660
6666
  }
6661
- var container = this.container();
6667
+ const container = this.container();
6662
6668
  if (!container) {
6663
6669
  throw 'Stage has no container. A container is required.';
6664
6670
  }
@@ -6722,11 +6728,11 @@
6722
6728
  });
6723
6729
  }
6724
6730
 
6725
- var HAS_SHADOW = 'hasShadow';
6726
- var SHADOW_RGBA = 'shadowRGBA';
6727
- var patternImage = 'patternImage';
6728
- var linearGradient = 'linearGradient';
6729
- var radialGradient = 'radialGradient';
6731
+ const HAS_SHADOW = 'hasShadow';
6732
+ const SHADOW_RGBA = 'shadowRGBA';
6733
+ const patternImage = 'patternImage';
6734
+ const linearGradient = 'linearGradient';
6735
+ const radialGradient = 'radialGradient';
6730
6736
  let dummyContext$1;
6731
6737
  function getDummyContext$1() {
6732
6738
  if (dummyContext$1) {
@@ -6928,7 +6934,7 @@
6928
6934
  }
6929
6935
  __getFillPattern() {
6930
6936
  if (this.fillPatternImage()) {
6931
- var ctx = getDummyContext$1();
6937
+ const ctx = getDummyContext$1();
6932
6938
  const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat');
6933
6939
  if (pattern && pattern.setTransform) {
6934
6940
  const tr = new Transform();
@@ -6956,14 +6962,14 @@
6956
6962
  return this._getCache(linearGradient, this.__getLinearGradient);
6957
6963
  }
6958
6964
  __getLinearGradient() {
6959
- var colorStops = this.fillLinearGradientColorStops();
6965
+ const colorStops = this.fillLinearGradientColorStops();
6960
6966
  if (colorStops) {
6961
- var ctx = getDummyContext$1();
6962
- var start = this.fillLinearGradientStartPoint();
6963
- var end = this.fillLinearGradientEndPoint();
6964
- var grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
6967
+ const ctx = getDummyContext$1();
6968
+ const start = this.fillLinearGradientStartPoint();
6969
+ const end = this.fillLinearGradientEndPoint();
6970
+ const grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
6965
6971
  // build color stops
6966
- for (var n = 0; n < colorStops.length; n += 2) {
6972
+ for (let n = 0; n < colorStops.length; n += 2) {
6967
6973
  grd.addColorStop(colorStops[n], colorStops[n + 1]);
6968
6974
  }
6969
6975
  return grd;
@@ -6973,14 +6979,14 @@
6973
6979
  return this._getCache(radialGradient, this.__getRadialGradient);
6974
6980
  }
6975
6981
  __getRadialGradient() {
6976
- var colorStops = this.fillRadialGradientColorStops();
6982
+ const colorStops = this.fillRadialGradientColorStops();
6977
6983
  if (colorStops) {
6978
- var ctx = getDummyContext$1();
6979
- var start = this.fillRadialGradientStartPoint();
6980
- var end = this.fillRadialGradientEndPoint();
6981
- var grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
6984
+ const ctx = getDummyContext$1();
6985
+ const start = this.fillRadialGradientStartPoint();
6986
+ const end = this.fillRadialGradientEndPoint();
6987
+ const grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
6982
6988
  // build color stops
6983
- for (var n = 0; n < colorStops.length; n += 2) {
6989
+ for (let n = 0; n < colorStops.length; n += 2) {
6984
6990
  grd.addColorStop(colorStops[n], colorStops[n + 1]);
6985
6991
  }
6986
6992
  return grd;
@@ -6993,7 +6999,7 @@
6993
6999
  if (!this.hasShadow()) {
6994
7000
  return;
6995
7001
  }
6996
- var rgba = Util.colorToRGBA(this.shadowColor());
7002
+ const rgba = Util.colorToRGBA(this.shadowColor());
6997
7003
  if (rgba) {
6998
7004
  return ('rgba(' +
6999
7005
  rgba.r +
@@ -7076,7 +7082,7 @@
7076
7082
  * @returns {Boolean}
7077
7083
  */
7078
7084
  intersects(point) {
7079
- var stage = this.getStage();
7085
+ const stage = this.getStage();
7080
7086
  if (!stage) {
7081
7087
  return false;
7082
7088
  }
@@ -7148,7 +7154,7 @@
7148
7154
  *
7149
7155
  */
7150
7156
  getSelfRect() {
7151
- var size = this.size();
7157
+ const size = this.size();
7152
7158
  return {
7153
7159
  x: this._centroid ? -size.width / 2 : 0,
7154
7160
  y: this._centroid ? -size.height / 2 : 0,
@@ -7204,17 +7210,17 @@
7204
7210
  // 1 - simple drawing when nothing is cached.
7205
7211
  // 2 - when we are caching current
7206
7212
  // 3 - when node is cached and we need to draw it into layer
7207
- var layer = this.getLayer();
7208
- var canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
7209
- var skipBuffer = canvas.isCache;
7210
- var cachingSelf = top === this;
7213
+ const layer = this.getLayer();
7214
+ let canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
7215
+ const skipBuffer = canvas.isCache;
7216
+ const cachingSelf = top === this;
7211
7217
  if (!this.isVisible() && !cachingSelf) {
7212
7218
  return this;
7213
7219
  }
7214
7220
  // if node is cached we just need to draw from cache
7215
7221
  if (cachedCanvas) {
7216
7222
  context.save();
7217
- var m = this.getAbsoluteTransform(top).getMatrix();
7223
+ const m = this.getAbsoluteTransform(top).getMatrix();
7218
7224
  context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
7219
7225
  this._drawCachedSceneCanvas(context);
7220
7226
  context.restore();
@@ -7237,7 +7243,7 @@
7237
7243
  bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
7238
7244
  drawFunc.call(this, bufferContext, this);
7239
7245
  bufferContext.restore();
7240
- var ratio = bc.pixelRatio;
7246
+ const ratio = bc.pixelRatio;
7241
7247
  if (hasShadow) {
7242
7248
  context._applyShadow(this);
7243
7249
  }
@@ -7265,13 +7271,13 @@
7265
7271
  if (!this.shouldDrawHit(top, skipDragCheck)) {
7266
7272
  return this;
7267
7273
  }
7268
- var layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
7274
+ const layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
7269
7275
  if (!this.colorKey) {
7270
7276
  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()');
7271
7277
  }
7272
7278
  if (cachedHitCanvas) {
7273
7279
  context.save();
7274
- var m = this.getAbsoluteTransform(top).getMatrix();
7280
+ const m = this.getAbsoluteTransform(top).getMatrix();
7275
7281
  context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
7276
7282
  this._drawCachedHitCanvas(context);
7277
7283
  context.restore();
@@ -7284,7 +7290,7 @@
7284
7290
  context._applyLineJoin(this);
7285
7291
  const selfCache = this === top;
7286
7292
  if (!selfCache) {
7287
- var o = this.getAbsoluteTransform(top).getMatrix();
7293
+ const o = this.getAbsoluteTransform(top).getMatrix();
7288
7294
  context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
7289
7295
  }
7290
7296
  drawFunc.call(this, context, this);
@@ -7304,17 +7310,17 @@
7304
7310
  * shape.drawHitFromCache();
7305
7311
  */
7306
7312
  drawHitFromCache(alphaThreshold = 0) {
7307
- var cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha;
7313
+ const cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight();
7308
7314
  hitContext.clear();
7309
7315
  hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight);
7310
7316
  try {
7311
- hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
7312
- hitData = hitImageData.data;
7313
- len = hitData.length;
7314
- rgbColorKey = Util._hexToRgb(this.colorKey);
7317
+ const hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
7318
+ const hitData = hitImageData.data;
7319
+ const len = hitData.length;
7320
+ const rgbColorKey = Util._hexToRgb(this.colorKey);
7315
7321
  // replace non transparent pixels with color key
7316
- for (i = 0; i < len; i += 4) {
7317
- alpha = hitData[i + 3];
7322
+ for (let i = 0; i < len; i += 4) {
7323
+ const alpha = hitData[i + 3];
7318
7324
  if (alpha > alphaThreshold) {
7319
7325
  hitData[i] = rgbColorKey.r;
7320
7326
  hitData[i + 1] = rgbColorKey.g;
@@ -8368,7 +8374,7 @@
8368
8374
  });
8369
8375
 
8370
8376
  // constants
8371
- var HASH = '#', BEFORE_DRAW = 'beforeDraw', DRAW = 'draw',
8377
+ const HASH = '#', BEFORE_DRAW = 'beforeDraw', DRAW = 'draw',
8372
8378
  /*
8373
8379
  * 2 - 3 - 4
8374
8380
  * | |
@@ -8483,7 +8489,7 @@
8483
8489
  // extend Node.prototype.setZIndex
8484
8490
  setZIndex(index) {
8485
8491
  super.setZIndex(index);
8486
- var stage = this.getStage();
8492
+ const stage = this.getStage();
8487
8493
  if (stage && stage.content) {
8488
8494
  stage.content.removeChild(this.getNativeCanvasElement());
8489
8495
  if (index < stage.children.length - 1) {
@@ -8497,7 +8503,7 @@
8497
8503
  }
8498
8504
  moveToTop() {
8499
8505
  Node.prototype.moveToTop.call(this);
8500
- var stage = this.getStage();
8506
+ const stage = this.getStage();
8501
8507
  if (stage && stage.content) {
8502
8508
  stage.content.removeChild(this.getNativeCanvasElement());
8503
8509
  stage.content.appendChild(this.getNativeCanvasElement());
@@ -8505,11 +8511,11 @@
8505
8511
  return true;
8506
8512
  }
8507
8513
  moveUp() {
8508
- var moved = Node.prototype.moveUp.call(this);
8514
+ const moved = Node.prototype.moveUp.call(this);
8509
8515
  if (!moved) {
8510
8516
  return false;
8511
8517
  }
8512
- var stage = this.getStage();
8518
+ const stage = this.getStage();
8513
8519
  if (!stage || !stage.content) {
8514
8520
  return false;
8515
8521
  }
@@ -8525,9 +8531,9 @@
8525
8531
  // extend Node.prototype.moveDown
8526
8532
  moveDown() {
8527
8533
  if (Node.prototype.moveDown.call(this)) {
8528
- var stage = this.getStage();
8534
+ const stage = this.getStage();
8529
8535
  if (stage) {
8530
- var children = stage.children;
8536
+ const children = stage.children;
8531
8537
  if (stage.content) {
8532
8538
  stage.content.removeChild(this.getNativeCanvasElement());
8533
8539
  stage.content.insertBefore(this.getNativeCanvasElement(), children[this.index + 1].getCanvas()._canvas);
@@ -8540,9 +8546,9 @@
8540
8546
  // extend Node.prototype.moveToBottom
8541
8547
  moveToBottom() {
8542
8548
  if (Node.prototype.moveToBottom.call(this)) {
8543
- var stage = this.getStage();
8549
+ const stage = this.getStage();
8544
8550
  if (stage) {
8545
- var children = stage.children;
8551
+ const children = stage.children;
8546
8552
  if (stage.content) {
8547
8553
  stage.content.removeChild(this.getNativeCanvasElement());
8548
8554
  stage.content.insertBefore(this.getNativeCanvasElement(), children[1].getCanvas()._canvas);
@@ -8556,7 +8562,7 @@
8556
8562
  return this;
8557
8563
  }
8558
8564
  remove() {
8559
- var _canvas = this.getNativeCanvasElement();
8565
+ const _canvas = this.getNativeCanvasElement();
8560
8566
  Node.prototype.remove.call(this);
8561
8567
  if (_canvas && _canvas.parentNode && Util._isInDocument(_canvas)) {
8562
8568
  _canvas.parentNode.removeChild(_canvas);
@@ -8573,7 +8579,7 @@
8573
8579
  return this;
8574
8580
  }
8575
8581
  _validateAdd(child) {
8576
- var type = child.getType();
8582
+ const type = child.getType();
8577
8583
  if (type !== 'Group' && type !== 'Shape') {
8578
8584
  Util.throw('You may only add groups and shapes to a layer.');
8579
8585
  }
@@ -8670,8 +8676,8 @@
8670
8676
  }
8671
8677
  // in some cases antialiased area may be bigger than 1px
8672
8678
  // it is possible if we will cache node, then scale it a lot
8673
- var spiralSearchDistance = 1;
8674
- var continueSearch = false;
8679
+ let spiralSearchDistance = 1;
8680
+ let continueSearch = false;
8675
8681
  while (true) {
8676
8682
  for (let i = 0; i < INTERSECTION_OFFSETS_LEN; i++) {
8677
8683
  const intersectionOffset = INTERSECTION_OFFSETS[i];
@@ -8727,7 +8733,7 @@
8727
8733
  return {};
8728
8734
  }
8729
8735
  drawScene(can, top) {
8730
- var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
8736
+ const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
8731
8737
  this._fire(BEFORE_DRAW, {
8732
8738
  node: this,
8733
8739
  });
@@ -8741,7 +8747,7 @@
8741
8747
  return this;
8742
8748
  }
8743
8749
  drawHit(can, top) {
8744
- var layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas);
8750
+ const layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas);
8745
8751
  if (layer && layer.clearBeforeDraw()) {
8746
8752
  layer.getHitCanvas().getContext().clear();
8747
8753
  }
@@ -8785,8 +8791,8 @@
8785
8791
  if (!this.parent || !this.parent['content']) {
8786
8792
  return;
8787
8793
  }
8788
- var parent = this.parent;
8789
- var added = !!this.hitCanvas._canvas.parentNode;
8794
+ const parent = this.parent;
8795
+ const added = !!this.hitCanvas._canvas.parentNode;
8790
8796
  if (added) {
8791
8797
  parent.content.removeChild(this.hitCanvas._canvas);
8792
8798
  }
@@ -8923,7 +8929,7 @@
8923
8929
  */
8924
8930
  class Group extends Container {
8925
8931
  _validateAdd(child) {
8926
- var type = child.getType();
8932
+ const type = child.getType();
8927
8933
  if (type !== 'Group' && type !== 'Shape') {
8928
8934
  Util.throw('You may only add groups and shapes to groups.');
8929
8935
  }
@@ -9120,7 +9126,7 @@
9120
9126
  }
9121
9127
  }
9122
9128
  }
9123
- for (let key in layerHash) {
9129
+ for (const key in layerHash) {
9124
9130
  if (!layerHash.hasOwnProperty(key)) {
9125
9131
  continue;
9126
9132
  }
@@ -9148,13 +9154,14 @@
9148
9154
  Animation.animIdCounter = 0;
9149
9155
  Animation.animRunning = false;
9150
9156
 
9151
- var blacklist = {
9157
+ const blacklist = {
9152
9158
  node: 1,
9153
9159
  duration: 1,
9154
9160
  easing: 1,
9155
9161
  onFinish: 1,
9156
9162
  yoyo: 1,
9157
- }, PAUSED = 1, PLAYING = 2, REVERSING = 3, idCounter = 0, colorAttrs = ['fill', 'stroke', 'shadowColor'];
9163
+ }, PAUSED = 1, PLAYING = 2, REVERSING = 3, colorAttrs = ['fill', 'stroke', 'shadowColor'];
9164
+ let idCounter = 0;
9158
9165
  class TweenEngine {
9159
9166
  constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
9160
9167
  this.prop = prop;
@@ -9174,7 +9181,7 @@
9174
9181
  this.pause();
9175
9182
  }
9176
9183
  fire(str) {
9177
- var handler = this[str];
9184
+ const handler = this[str];
9178
9185
  if (handler) {
9179
9186
  handler();
9180
9187
  }
@@ -9253,7 +9260,7 @@
9253
9260
  this.fire('onUpdate');
9254
9261
  }
9255
9262
  onEnterFrame() {
9256
- var t = this.getTimer() - this._startTime;
9263
+ const t = this.getTimer() - this._startTime;
9257
9264
  if (this.state === PLAYING) {
9258
9265
  this.setTime(t);
9259
9266
  }
@@ -9297,7 +9304,8 @@
9297
9304
  */
9298
9305
  class Tween {
9299
9306
  constructor(config) {
9300
- var that = this, node = config.node, nodeId = node._id, duration, easing = config.easing || Easings.Linear, yoyo = !!config.yoyo, key;
9307
+ const that = this, node = config.node, nodeId = node._id, easing = config.easing || Easings.Linear, yoyo = !!config.yoyo;
9308
+ let duration, key;
9301
9309
  if (typeof config.duration === 'undefined') {
9302
9310
  duration = 0.3;
9303
9311
  }
@@ -9310,7 +9318,7 @@
9310
9318
  }
9311
9319
  this.node = node;
9312
9320
  this._id = idCounter++;
9313
- var layers = node.getLayer() ||
9321
+ const layers = node.getLayer() ||
9314
9322
  (node instanceof Konva$2['Stage'] ? node.getLayers() : null);
9315
9323
  if (!layers) {
9316
9324
  Util.error('Tween constructor have `node` that is not in a layer. Please add node into layer first.');
@@ -9345,14 +9353,15 @@
9345
9353
  this.onUpdate = config.onUpdate;
9346
9354
  }
9347
9355
  _addAttr(key, end) {
9348
- var node = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA;
9356
+ const node = this.node, nodeId = node._id;
9357
+ let diff, len, trueEnd, trueStart, endRGBA;
9349
9358
  // remove conflict from tween map if it exists
9350
- tweenId = Tween.tweens[nodeId][key];
9359
+ const tweenId = Tween.tweens[nodeId][key];
9351
9360
  if (tweenId) {
9352
9361
  delete Tween.attrs[nodeId][tweenId][key];
9353
9362
  }
9354
9363
  // add to tween map
9355
- start = node.getAttr(key);
9364
+ let start = node.getAttr(key);
9356
9365
  if (Util._isArray(end)) {
9357
9366
  diff = [];
9358
9367
  len = Math.max(end.length, start.length);
@@ -9371,12 +9380,12 @@
9371
9380
  }
9372
9381
  }
9373
9382
  if (key.indexOf('fill') === 0) {
9374
- for (n = 0; n < len; n++) {
9383
+ for (let n = 0; n < len; n++) {
9375
9384
  if (n % 2 === 0) {
9376
9385
  diff.push(end[n] - start[n]);
9377
9386
  }
9378
9387
  else {
9379
- var startRGBA = Util.colorToRGBA(start[n]);
9388
+ const startRGBA = Util.colorToRGBA(start[n]);
9380
9389
  endRGBA = Util.colorToRGBA(end[n]);
9381
9390
  start[n] = startRGBA;
9382
9391
  diff.push({
@@ -9389,7 +9398,7 @@
9389
9398
  }
9390
9399
  }
9391
9400
  else {
9392
- for (n = 0; n < len; n++) {
9401
+ for (let n = 0; n < len; n++) {
9393
9402
  diff.push(end[n] - start[n]);
9394
9403
  }
9395
9404
  }
@@ -9417,7 +9426,8 @@
9417
9426
  Tween.tweens[nodeId][key] = this._id;
9418
9427
  }
9419
9428
  _tweenFunc(i) {
9420
- var node = this.node, attrs = Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end;
9429
+ const node = this.node, attrs = Tween.attrs[node._id][this._id];
9430
+ let key, attr, start, diff, newVal, n, len, end;
9421
9431
  for (key in attrs) {
9422
9432
  attr = attrs[key];
9423
9433
  start = attr.start;
@@ -9481,9 +9491,9 @@
9481
9491
  this.anim.stop();
9482
9492
  };
9483
9493
  this.tween.onFinish = () => {
9484
- var node = this.node;
9494
+ const node = this.node;
9485
9495
  // after tweening points of line we need to set original end
9486
- var attrs = Tween.attrs[node._id][this._id];
9496
+ const attrs = Tween.attrs[node._id][this._id];
9487
9497
  if (attrs.points && attrs.points.trueEnd) {
9488
9498
  node.setAttr('points', attrs.points.trueEnd);
9489
9499
  }
@@ -9492,9 +9502,9 @@
9492
9502
  }
9493
9503
  };
9494
9504
  this.tween.onReset = () => {
9495
- var node = this.node;
9505
+ const node = this.node;
9496
9506
  // after tweening points of line we need to set original start
9497
- var attrs = Tween.attrs[node._id][this._id];
9507
+ const attrs = Tween.attrs[node._id][this._id];
9498
9508
  if (attrs.points && attrs.points.trueStart) {
9499
9509
  node.points(attrs.points.trueStart);
9500
9510
  }
@@ -9575,9 +9585,9 @@
9575
9585
  * @name Konva.Tween#destroy
9576
9586
  */
9577
9587
  destroy() {
9578
- var nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId], key;
9588
+ const nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId];
9579
9589
  this.pause();
9580
- for (key in attrs) {
9590
+ for (const key in attrs) {
9581
9591
  delete Tween.tweens[nodeId][key];
9582
9592
  }
9583
9593
  delete Tween.attrs[nodeId][thisId];
@@ -9600,7 +9610,7 @@
9600
9610
  * });
9601
9611
  */
9602
9612
  Node.prototype.to = function (params) {
9603
- var onFinish = params.onFinish;
9613
+ const onFinish = params.onFinish;
9604
9614
  params.node = this;
9605
9615
  params.onFinish = function () {
9606
9616
  this.destroy();
@@ -9608,7 +9618,7 @@
9608
9618
  onFinish();
9609
9619
  }
9610
9620
  };
9611
- var tween = new Tween(params);
9621
+ const tween = new Tween(params);
9612
9622
  tween.play();
9613
9623
  };
9614
9624
  /*
@@ -9626,7 +9636,7 @@
9626
9636
  * @memberof Konva.Easings
9627
9637
  */
9628
9638
  BackEaseIn(t, b, c, d) {
9629
- var s = 1.70158;
9639
+ const s = 1.70158;
9630
9640
  return c * (t /= d) * t * ((s + 1) * t - s) + b;
9631
9641
  },
9632
9642
  /**
@@ -9635,7 +9645,7 @@
9635
9645
  * @memberof Konva.Easings
9636
9646
  */
9637
9647
  BackEaseOut(t, b, c, d) {
9638
- var s = 1.70158;
9648
+ const s = 1.70158;
9639
9649
  return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
9640
9650
  },
9641
9651
  /**
@@ -9644,7 +9654,7 @@
9644
9654
  * @memberof Konva.Easings
9645
9655
  */
9646
9656
  BackEaseInOut(t, b, c, d) {
9647
- var s = 1.70158;
9657
+ let s = 1.70158;
9648
9658
  if ((t /= d / 2) < 1) {
9649
9659
  return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
9650
9660
  }
@@ -9657,7 +9667,7 @@
9657
9667
  */
9658
9668
  ElasticEaseIn(t, b, c, d, a, p) {
9659
9669
  // added s = 0
9660
- var s = 0;
9670
+ let s = 0;
9661
9671
  if (t === 0) {
9662
9672
  return b;
9663
9673
  }
@@ -9685,7 +9695,7 @@
9685
9695
  */
9686
9696
  ElasticEaseOut(t, b, c, d, a, p) {
9687
9697
  // added s = 0
9688
- var s = 0;
9698
+ let s = 0;
9689
9699
  if (t === 0) {
9690
9700
  return b;
9691
9701
  }
@@ -9713,7 +9723,7 @@
9713
9723
  */
9714
9724
  ElasticEaseInOut(t, b, c, d, a, p) {
9715
9725
  // added s = 0
9716
- var s = 0;
9726
+ let s = 0;
9717
9727
  if (t === 0) {
9718
9728
  return b;
9719
9729
  }
@@ -9967,7 +9977,7 @@
9967
9977
  */
9968
9978
  class Arc extends Shape {
9969
9979
  _sceneFunc(context) {
9970
- var angle = Konva$2.getAngle(this.angle()), clockwise = this.clockwise();
9980
+ const angle = Konva$2.getAngle(this.angle()), clockwise = this.clockwise();
9971
9981
  context.beginPath();
9972
9982
  context.arc(0, 0, this.outerRadius(), 0, angle, clockwise);
9973
9983
  context.arc(0, 0, this.innerRadius(), angle, 0, !clockwise);
@@ -10073,13 +10083,13 @@
10073
10083
  */
10074
10084
 
10075
10085
  function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
10076
- var 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);
10086
+ 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);
10077
10087
  return [p1x, p1y, p2x, p2y];
10078
10088
  }
10079
10089
  function expandPoints(p, tension) {
10080
- var len = p.length, allPoints = [], n, cp;
10081
- for (n = 2; n < len - 2; n += 2) {
10082
- cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
10090
+ const len = p.length, allPoints = [];
10091
+ for (let n = 2; n < len - 2; n += 2) {
10092
+ const cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
10083
10093
  if (isNaN(cp[0])) {
10084
10094
  continue;
10085
10095
  }
@@ -10195,7 +10205,7 @@
10195
10205
  });
10196
10206
  }
10197
10207
  _sceneFunc(context) {
10198
- var points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n;
10208
+ let points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n;
10199
10209
  if (!length) {
10200
10210
  return;
10201
10211
  }
@@ -10251,7 +10261,7 @@
10251
10261
  }
10252
10262
  }
10253
10263
  _getTensionPointsClosed() {
10254
- var 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]]
10264
+ 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]]
10255
10265
  .concat(middle)
10256
10266
  .concat([
10257
10267
  lastControlPoints[0],
@@ -10275,7 +10285,7 @@
10275
10285
  }
10276
10286
  // overload size detection
10277
10287
  getSelfRect() {
10278
- var points = this.points();
10288
+ let points = this.points();
10279
10289
  if (points.length < 4) {
10280
10290
  return {
10281
10291
  x: points[0] || 0,
@@ -10296,12 +10306,12 @@
10296
10306
  else {
10297
10307
  points = this.points();
10298
10308
  }
10299
- var minX = points[0];
10300
- var maxX = points[0];
10301
- var minY = points[1];
10302
- var maxY = points[1];
10303
- var x, y;
10304
- for (var i = 0; i < points.length / 2; i++) {
10309
+ let minX = points[0];
10310
+ let maxX = points[0];
10311
+ let minY = points[1];
10312
+ let maxY = points[1];
10313
+ let x, y;
10314
+ for (let i = 0; i < points.length / 2; i++) {
10305
10315
  x = points[i * 2];
10306
10316
  y = points[i * 2 + 1];
10307
10317
  minX = Math.min(minX, x);
@@ -11074,14 +11084,13 @@
11074
11084
  // LUT for binomial coefficient arrays per curve order 'n'
11075
11085
  const binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]];
11076
11086
  const getCubicArcLength = (xs, ys, t) => {
11077
- let z;
11078
11087
  let sum;
11079
11088
  let correctedT;
11080
11089
  /*if (xs.length >= tValues.length) {
11081
11090
  throw new Error('too high n bezier');
11082
11091
  }*/
11083
11092
  const n = 20;
11084
- z = t / 2;
11093
+ const z = t / 2;
11085
11094
  sum = 0;
11086
11095
  for (let i = 0; i < n; i++) {
11087
11096
  correctedT = z * tValues[n][i] + z;
@@ -11291,13 +11300,13 @@
11291
11300
  this.pathLength = Path.getPathLength(this.dataArray);
11292
11301
  }
11293
11302
  _sceneFunc(context) {
11294
- var ca = this.dataArray;
11303
+ const ca = this.dataArray;
11295
11304
  // context position
11296
11305
  context.beginPath();
11297
- var isClosed = false;
11298
- for (var n = 0; n < ca.length; n++) {
11299
- var c = ca[n].command;
11300
- var p = ca[n].points;
11306
+ let isClosed = false;
11307
+ for (let n = 0; n < ca.length; n++) {
11308
+ const c = ca[n].command;
11309
+ const p = ca[n].points;
11301
11310
  switch (c) {
11302
11311
  case 'L':
11303
11312
  context.lineTo(p[0], p[1]);
@@ -11338,16 +11347,16 @@
11338
11347
  }
11339
11348
  }
11340
11349
  getSelfRect() {
11341
- var points = [];
11350
+ let points = [];
11342
11351
  this.dataArray.forEach(function (data) {
11343
11352
  if (data.command === 'A') {
11344
11353
  // Approximates by breaking curve into line segments
11345
- var start = data.points[4];
11354
+ const start = data.points[4];
11346
11355
  // 4 = theta
11347
- var dTheta = data.points[5];
11356
+ const dTheta = data.points[5];
11348
11357
  // 5 = dTheta
11349
- var end = data.points[4] + dTheta;
11350
- var inc = Math.PI / 180.0;
11358
+ const end = data.points[4] + dTheta;
11359
+ let inc = Math.PI / 180.0;
11351
11360
  // 1 degree resolution
11352
11361
  if (Math.abs(start - end) < inc) {
11353
11362
  inc = Math.abs(start - end);
@@ -11379,12 +11388,12 @@
11379
11388
  points = points.concat(data.points);
11380
11389
  }
11381
11390
  });
11382
- var minX = points[0];
11383
- var maxX = points[0];
11384
- var minY = points[1];
11385
- var maxY = points[1];
11386
- var x, y;
11387
- for (var i = 0; i < points.length / 2; i++) {
11391
+ let minX = points[0];
11392
+ let maxX = points[0];
11393
+ let minY = points[1];
11394
+ let maxY = points[1];
11395
+ let x, y;
11396
+ for (let i = 0; i < points.length / 2; i++) {
11388
11397
  x = points[i * 2];
11389
11398
  y = points[i * 2 + 1];
11390
11399
  // skip bad values
@@ -11432,13 +11441,13 @@
11432
11441
  }
11433
11442
  static getPathLength(dataArray) {
11434
11443
  let pathLength = 0;
11435
- for (var i = 0; i < dataArray.length; ++i) {
11444
+ for (let i = 0; i < dataArray.length; ++i) {
11436
11445
  pathLength += dataArray[i].pathLength;
11437
11446
  }
11438
11447
  return pathLength;
11439
11448
  }
11440
11449
  static getPointAtLengthOfDataArray(length, dataArray) {
11441
- var points, i = 0, ii = dataArray.length;
11450
+ let points, i = 0, ii = dataArray.length;
11442
11451
  if (!ii) {
11443
11452
  return null;
11444
11453
  }
@@ -11460,8 +11469,8 @@
11460
11469
  y: points[1],
11461
11470
  };
11462
11471
  }
11463
- var cp = dataArray[i];
11464
- var p = cp.points;
11472
+ const cp = dataArray[i];
11473
+ const p = cp.points;
11465
11474
  switch (cp.command) {
11466
11475
  case 'L':
11467
11476
  return Path.getPointOnLine(length, cp.start.x, cp.start.y, p[0], p[1]);
@@ -11519,8 +11528,8 @@
11519
11528
  function CB4(t) {
11520
11529
  return (1 - t) * (1 - t) * (1 - t);
11521
11530
  }
11522
- var x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
11523
- var y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
11531
+ const x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
11532
+ const y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
11524
11533
  return {
11525
11534
  x: x,
11526
11535
  y: y,
@@ -11536,16 +11545,16 @@
11536
11545
  function QB3(t) {
11537
11546
  return (1 - t) * (1 - t);
11538
11547
  }
11539
- var x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
11540
- var y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
11548
+ const x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
11549
+ const y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
11541
11550
  return {
11542
11551
  x: x,
11543
11552
  y: y,
11544
11553
  };
11545
11554
  }
11546
11555
  static getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) {
11547
- var cosPsi = Math.cos(psi), sinPsi = Math.sin(psi);
11548
- var pt = {
11556
+ const cosPsi = Math.cos(psi), sinPsi = Math.sin(psi);
11557
+ const pt = {
11549
11558
  x: rx * Math.cos(theta),
11550
11559
  y: ry * Math.sin(theta),
11551
11560
  };
@@ -11587,9 +11596,9 @@
11587
11596
  return [];
11588
11597
  }
11589
11598
  // command string
11590
- var cs = data;
11599
+ let cs = data;
11591
11600
  // command chars
11592
- var cc = [
11601
+ const cc = [
11593
11602
  'm',
11594
11603
  'M',
11595
11604
  'l',
@@ -11618,17 +11627,17 @@
11618
11627
  cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
11619
11628
  }
11620
11629
  // create array
11621
- var arr = cs.split('|');
11622
- var ca = [];
11623
- var coords = [];
11630
+ const arr = cs.split('|');
11631
+ const ca = [];
11632
+ const coords = [];
11624
11633
  // init context point
11625
- var cpx = 0;
11626
- var cpy = 0;
11627
- var re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
11628
- var match;
11634
+ let cpx = 0;
11635
+ let cpy = 0;
11636
+ const re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
11637
+ let match;
11629
11638
  for (n = 1; n < arr.length; n++) {
11630
- var str = arr[n];
11631
- var c = str.charAt(0);
11639
+ let str = arr[n];
11640
+ let c = str.charAt(0);
11632
11641
  str = str.slice(1);
11633
11642
  coords.length = 0;
11634
11643
  while ((match = re.exec(str))) {
@@ -11637,14 +11646,14 @@
11637
11646
  // while ((match = re.exec(str))) {
11638
11647
  // coords.push(match[0]);
11639
11648
  // }
11640
- var p = [];
11641
- for (var j = 0, jlen = coords.length; j < jlen; j++) {
11649
+ const p = [];
11650
+ for (let j = 0, jlen = coords.length; j < jlen; j++) {
11642
11651
  // extra case for merged flags
11643
11652
  if (coords[j] === '00') {
11644
11653
  p.push(0, 0);
11645
11654
  continue;
11646
11655
  }
11647
- var parsed = parseFloat(coords[j]);
11656
+ const parsed = parseFloat(coords[j]);
11648
11657
  if (!isNaN(parsed)) {
11649
11658
  p.push(parsed);
11650
11659
  }
@@ -11657,9 +11666,9 @@
11657
11666
  // case for a trailing comma before next command
11658
11667
  break;
11659
11668
  }
11660
- var cmd = '';
11661
- var points = [];
11662
- var startX = cpx, startY = cpy;
11669
+ let cmd = '';
11670
+ let points = [];
11671
+ const startX = cpx, startY = cpy;
11663
11672
  // Move var from within the switch to up here (jshint)
11664
11673
  var prevCmd, ctlPtx, ctlPty; // Ss, Tt
11665
11674
  var rx, ry, psi, fa, fs, x1, y1; // Aa
@@ -11687,7 +11696,7 @@
11687
11696
  // After closing the path move the current position
11688
11697
  // to the the first point of the path (if any).
11689
11698
  if (ca.length > 2 && ca[ca.length - 1].command === 'z') {
11690
- for (var idx = ca.length - 2; idx >= 0; idx--) {
11699
+ for (let idx = ca.length - 2; idx >= 0; idx--) {
11691
11700
  if (ca[idx].command === 'M') {
11692
11701
  cpx = ca[idx].points[0] + dx;
11693
11702
  cpy = ca[idx].points[1] + dy;
@@ -11856,8 +11865,8 @@
11856
11865
  return ca;
11857
11866
  }
11858
11867
  static calcLength(x, y, cmd, points) {
11859
- var len, p1, p2, t;
11860
- var path = Path;
11868
+ let len, p1, p2, t;
11869
+ const path = Path;
11861
11870
  switch (cmd) {
11862
11871
  case 'L':
11863
11872
  return path.getLineLength(x, y, points[0], points[1]);
@@ -11904,16 +11913,16 @@
11904
11913
  }
11905
11914
  static convertEndpointToCenterParameterization(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg) {
11906
11915
  // Derived from: http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
11907
- var psi = psiDeg * (Math.PI / 180.0);
11908
- var xp = (Math.cos(psi) * (x1 - x2)) / 2.0 + (Math.sin(psi) * (y1 - y2)) / 2.0;
11909
- var yp = (-1 * Math.sin(psi) * (x1 - x2)) / 2.0 +
11916
+ const psi = psiDeg * (Math.PI / 180.0);
11917
+ const xp = (Math.cos(psi) * (x1 - x2)) / 2.0 + (Math.sin(psi) * (y1 - y2)) / 2.0;
11918
+ const yp = (-1 * Math.sin(psi) * (x1 - x2)) / 2.0 +
11910
11919
  (Math.cos(psi) * (y1 - y2)) / 2.0;
11911
- var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
11920
+ const lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
11912
11921
  if (lambda > 1) {
11913
11922
  rx *= Math.sqrt(lambda);
11914
11923
  ry *= Math.sqrt(lambda);
11915
11924
  }
11916
- var f = Math.sqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) /
11925
+ let f = Math.sqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) /
11917
11926
  (rx * rx * (yp * yp) + ry * ry * (xp * xp)));
11918
11927
  if (fa === fs) {
11919
11928
  f *= -1;
@@ -11921,23 +11930,23 @@
11921
11930
  if (isNaN(f)) {
11922
11931
  f = 0;
11923
11932
  }
11924
- var cxp = (f * rx * yp) / ry;
11925
- var cyp = (f * -ry * xp) / rx;
11926
- var cx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp;
11927
- var cy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp;
11928
- var vMag = function (v) {
11933
+ const cxp = (f * rx * yp) / ry;
11934
+ const cyp = (f * -ry * xp) / rx;
11935
+ const cx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp;
11936
+ const cy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp;
11937
+ const vMag = function (v) {
11929
11938
  return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
11930
11939
  };
11931
- var vRatio = function (u, v) {
11940
+ const vRatio = function (u, v) {
11932
11941
  return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
11933
11942
  };
11934
- var vAngle = function (u, v) {
11943
+ const vAngle = function (u, v) {
11935
11944
  return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
11936
11945
  };
11937
- var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
11938
- var u = [(xp - cxp) / rx, (yp - cyp) / ry];
11939
- var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
11940
- var dTheta = vAngle(u, v);
11946
+ const theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
11947
+ const u = [(xp - cxp) / rx, (yp - cyp) / ry];
11948
+ const v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
11949
+ let dTheta = vAngle(u, v);
11941
11950
  if (vRatio(u, v) <= -1) {
11942
11951
  dTheta = Math.PI;
11943
11952
  }
@@ -12073,16 +12082,16 @@
12073
12082
  class Arrow extends Line {
12074
12083
  _sceneFunc(ctx) {
12075
12084
  super._sceneFunc(ctx);
12076
- var PI2 = Math.PI * 2;
12077
- var points = this.points();
12078
- var tp = points;
12079
- var fromTension = this.tension() !== 0 && points.length > 4;
12085
+ const PI2 = Math.PI * 2;
12086
+ const points = this.points();
12087
+ let tp = points;
12088
+ const fromTension = this.tension() !== 0 && points.length > 4;
12080
12089
  if (fromTension) {
12081
12090
  tp = this.getTensionPoints();
12082
12091
  }
12083
- var length = this.pointerLength();
12084
- var n = points.length;
12085
- var dx, dy;
12092
+ const length = this.pointerLength();
12093
+ const n = points.length;
12094
+ let dx, dy;
12086
12095
  if (fromTension) {
12087
12096
  const lp = [
12088
12097
  tp[tp.length - 4],
@@ -12101,8 +12110,8 @@
12101
12110
  dx = points[n - 2] - points[n - 4];
12102
12111
  dy = points[n - 1] - points[n - 3];
12103
12112
  }
12104
- var radians = (Math.atan2(dy, dx) + PI2) % PI2;
12105
- var width = this.pointerWidth();
12113
+ const radians = (Math.atan2(dy, dx) + PI2) % PI2;
12114
+ const width = this.pointerWidth();
12106
12115
  if (this.pointerAtEnding()) {
12107
12116
  ctx.save();
12108
12117
  ctx.beginPath();
@@ -12139,7 +12148,7 @@
12139
12148
  __fillStroke(ctx) {
12140
12149
  // here is a tricky part
12141
12150
  // we need to disable dash for arrow pointers
12142
- var isDashEnabled = this.dashEnabled();
12151
+ const isDashEnabled = this.dashEnabled();
12143
12152
  if (isDashEnabled) {
12144
12153
  // manually disable dash for head
12145
12154
  // it is better not to use setter here,
@@ -12157,9 +12166,9 @@
12157
12166
  const lineRect = super.getSelfRect();
12158
12167
  const offset = this.pointerWidth() / 2;
12159
12168
  return {
12160
- x: lineRect.x - offset,
12169
+ x: lineRect.x,
12161
12170
  y: lineRect.y - offset,
12162
- width: lineRect.width + offset * 2,
12171
+ width: lineRect.width,
12163
12172
  height: lineRect.height + offset * 2,
12164
12173
  };
12165
12174
  }
@@ -12449,7 +12458,7 @@
12449
12458
  */
12450
12459
  class Ellipse extends Shape {
12451
12460
  _sceneFunc(context) {
12452
- var rx = this.radiusX(), ry = this.radiusY();
12461
+ const rx = this.radiusX(), ry = this.radiusY();
12453
12462
  context.beginPath();
12454
12463
  context.save();
12455
12464
  if (rx !== ry) {
@@ -12696,7 +12705,7 @@
12696
12705
  // If you need to draw later, you need to execute save/restore
12697
12706
  }
12698
12707
  _hitFunc(context) {
12699
- var width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
12708
+ const width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
12700
12709
  context.beginPath();
12701
12710
  if (!cornerRadius) {
12702
12711
  context.rect(0, 0, width, height);
@@ -12730,9 +12739,9 @@
12730
12739
  * });
12731
12740
  */
12732
12741
  static fromURL(url, callback, onError = null) {
12733
- var img = Util.createImageElement();
12742
+ const img = Util.createImageElement();
12734
12743
  img.onload = function () {
12735
- var image = new Image({
12744
+ const image = new Image({
12736
12745
  image: img,
12737
12746
  });
12738
12747
  callback(image);
@@ -12857,7 +12866,7 @@
12857
12866
  */
12858
12867
 
12859
12868
  // constants
12860
- var ATTR_CHANGE_LIST$2 = [
12869
+ const ATTR_CHANGE_LIST$2 = [
12861
12870
  'fontFamily',
12862
12871
  'fontSize',
12863
12872
  'fontStyle',
@@ -12958,8 +12967,8 @@
12958
12967
  return this.find('Tag')[0];
12959
12968
  }
12960
12969
  _addListeners(text) {
12961
- var that = this, n;
12962
- var func = function () {
12970
+ let that = this, n;
12971
+ const func = function () {
12963
12972
  that._sync();
12964
12973
  };
12965
12974
  // update text data for certain attr changes
@@ -12974,7 +12983,7 @@
12974
12983
  return this.getText().height();
12975
12984
  }
12976
12985
  _sync() {
12977
- var text = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight;
12986
+ let text = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight;
12978
12987
  if (text && tag) {
12979
12988
  width = text.width();
12980
12989
  height = text.height();
@@ -13030,7 +13039,7 @@
13030
13039
  */
13031
13040
  class Tag extends Shape {
13032
13041
  _sceneFunc(context) {
13033
- var width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
13042
+ const width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
13034
13043
  let topLeft = 0;
13035
13044
  let topRight = 0;
13036
13045
  let bottomLeft = 0;
@@ -13082,7 +13091,7 @@
13082
13091
  context.fillStrokeShape(this);
13083
13092
  }
13084
13093
  getSelfRect() {
13085
- var x = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();
13094
+ let x = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();
13086
13095
  if (direction === UP) {
13087
13096
  y -= pointerHeight;
13088
13097
  height += pointerHeight;
@@ -13245,7 +13254,7 @@
13245
13254
  */
13246
13255
  class Rect extends Shape {
13247
13256
  _sceneFunc(context) {
13248
- var cornerRadius = this.cornerRadius(), width = this.width(), height = this.height();
13257
+ const cornerRadius = this.cornerRadius(), width = this.width(), height = this.height();
13249
13258
  context.beginPath();
13250
13259
  if (!cornerRadius) {
13251
13260
  // simple rect - don't bother doing all that complicated maths stuff.
@@ -13377,7 +13386,7 @@
13377
13386
  const points = this._getPoints();
13378
13387
  context.beginPath();
13379
13388
  context.moveTo(points[0].x, points[0].y);
13380
- for (var n = 1; n < points.length; n++) {
13389
+ for (let n = 1; n < points.length; n++) {
13381
13390
  context.lineTo(points[n].x, points[n].y);
13382
13391
  }
13383
13392
  context.closePath();
@@ -13387,7 +13396,7 @@
13387
13396
  const sides = this.attrs.sides;
13388
13397
  const radius = this.attrs.radius || 0;
13389
13398
  const points = [];
13390
- for (var n = 0; n < sides; n++) {
13399
+ for (let n = 0; n < sides; n++) {
13391
13400
  points.push({
13392
13401
  x: radius * Math.sin((n * 2 * Math.PI) / sides),
13393
13402
  y: -1 * radius * Math.cos((n * 2 * Math.PI) / sides),
@@ -13397,10 +13406,10 @@
13397
13406
  }
13398
13407
  getSelfRect() {
13399
13408
  const points = this._getPoints();
13400
- var minX = points[0].x;
13401
- var maxX = points[0].y;
13402
- var minY = points[0].x;
13403
- var maxY = points[0].y;
13409
+ let minX = points[0].x;
13410
+ let maxX = points[0].y;
13411
+ let minY = points[0].x;
13412
+ let maxY = points[0].y;
13404
13413
  points.forEach((point) => {
13405
13414
  minX = Math.min(minX, point.x);
13406
13415
  maxX = Math.max(maxX, point.x);
@@ -13460,7 +13469,7 @@
13460
13469
  */
13461
13470
  Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator());
13462
13471
 
13463
- var PIx2 = Math.PI * 2;
13472
+ const PIx2 = Math.PI * 2;
13464
13473
  /**
13465
13474
  * Ring constructor
13466
13475
  * @constructor
@@ -13732,7 +13741,7 @@
13732
13741
  this._updated = true;
13733
13742
  this.anim = new Animation(() => {
13734
13743
  // if we don't need to redraw layer we should return false
13735
- var updated = this._updated;
13744
+ const updated = this._updated;
13736
13745
  this._updated = false;
13737
13746
  return updated;
13738
13747
  });
@@ -13753,7 +13762,7 @@
13753
13762
  });
13754
13763
  }
13755
13764
  _sceneFunc(context) {
13756
- var 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();
13765
+ 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();
13757
13766
  if (this.hasFill() || this.hasStroke()) {
13758
13767
  context.beginPath();
13759
13768
  context.rect(0, 0, width, height);
@@ -13762,7 +13771,7 @@
13762
13771
  }
13763
13772
  if (image) {
13764
13773
  if (offsets) {
13765
- var offset = offsets[anim], ix2 = index * 2;
13774
+ const offset = offsets[anim], ix2 = index * 2;
13766
13775
  context.drawImage(image, x, y, width, height, offset[ix2 + 0], offset[ix2 + 1], width, height);
13767
13776
  }
13768
13777
  else {
@@ -13771,11 +13780,11 @@
13771
13780
  }
13772
13781
  }
13773
13782
  _hitFunc(context) {
13774
- var anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), width = set[ix4 + 2], height = set[ix4 + 3];
13783
+ 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];
13775
13784
  context.beginPath();
13776
13785
  if (offsets) {
13777
- var offset = offsets[anim];
13778
- var ix2 = index * 2;
13786
+ const offset = offsets[anim];
13787
+ const ix2 = index * 2;
13779
13788
  context.rect(offset[ix2 + 0], offset[ix2 + 1], width, height);
13780
13789
  }
13781
13790
  else {
@@ -13788,7 +13797,7 @@
13788
13797
  return super._useBufferCanvas(true);
13789
13798
  }
13790
13799
  _setInterval() {
13791
- var that = this;
13800
+ const that = this;
13792
13801
  this.interval = setInterval(function () {
13793
13802
  that._updateIndex();
13794
13803
  }, 1000 / this.frameRate());
@@ -13802,7 +13811,7 @@
13802
13811
  if (this.isRunning()) {
13803
13812
  return;
13804
13813
  }
13805
- var layer = this.getLayer();
13814
+ const layer = this.getLayer();
13806
13815
  /*
13807
13816
  * animation object has no executable function because
13808
13817
  * the updates are done with a fixed FPS with the setInterval
@@ -13832,7 +13841,7 @@
13832
13841
  return this.anim.isRunning();
13833
13842
  }
13834
13843
  _updateIndex() {
13835
- var index = this.frameIndex(), animation = this.animation(), animations = this.animations(), anim = animations[animation], len = anim.length / 4;
13844
+ const index = this.frameIndex(), animation = this.animation(), animations = this.animations(), anim = animations[animation], len = anim.length / 4;
13836
13845
  if (index < len - 1) {
13837
13846
  this.frameIndex(index + 1);
13838
13847
  }
@@ -14071,13 +14080,13 @@
14071
14080
  */
14072
14081
  class Star extends Shape {
14073
14082
  _sceneFunc(context) {
14074
- var innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();
14083
+ const innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();
14075
14084
  context.beginPath();
14076
14085
  context.moveTo(0, 0 - outerRadius);
14077
- for (var n = 1; n < numPoints * 2; n++) {
14078
- var radius = n % 2 === 0 ? outerRadius : innerRadius;
14079
- var x = radius * Math.sin((n * Math.PI) / numPoints);
14080
- var y = -1 * radius * Math.cos((n * Math.PI) / numPoints);
14086
+ for (let n = 1; n < numPoints * 2; n++) {
14087
+ const radius = n % 2 === 0 ? outerRadius : innerRadius;
14088
+ const x = radius * Math.sin((n * Math.PI) / numPoints);
14089
+ const y = -1 * radius * Math.cos((n * Math.PI) / numPoints);
14081
14090
  context.lineTo(x, y);
14082
14091
  }
14083
14092
  context.closePath();
@@ -14146,9 +14155,15 @@
14146
14155
  function stringToArray(string) {
14147
14156
  // Use Unicode-aware splitting
14148
14157
  return [...string].reduce((acc, char, index, array) => {
14149
- // Handle emoji sequences (including ZWJ sequences)
14150
- if (/\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?(?:\u200D\p{Emoji_Presentation})+/u.test(char)) {
14151
- acc.push(char);
14158
+ // Handle emoji with skin tone modifiers and ZWJ sequences
14159
+ if (/\p{Emoji}/u.test(char)) {
14160
+ if (acc.length > 0 && /\p{Emoji}/u.test(acc[acc.length - 1])) {
14161
+ // Combine with previous emoji if it's part of a sequence
14162
+ acc[acc.length - 1] += char;
14163
+ }
14164
+ else {
14165
+ acc.push(char);
14166
+ }
14152
14167
  }
14153
14168
  // Handle regional indicator symbols (flags)
14154
14169
  else if (/\p{Regional_Indicator}{2}/u.test(char + (array[index + 1] || ''))) {
@@ -14166,7 +14181,7 @@
14166
14181
  }, []);
14167
14182
  }
14168
14183
  // constants
14169
- var AUTO = 'auto',
14184
+ const AUTO = 'auto',
14170
14185
  //CANVAS = 'canvas',
14171
14186
  CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL$1 = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST$1 = [
14172
14187
  'direction',
@@ -14201,7 +14216,7 @@
14201
14216
  })
14202
14217
  .join(', ');
14203
14218
  }
14204
- var dummyContext;
14219
+ let dummyContext;
14205
14220
  function getDummyContext() {
14206
14221
  if (dummyContext) {
14207
14222
  return dummyContext;
@@ -14335,22 +14350,22 @@
14335
14350
  this._partialTextX = 0;
14336
14351
  this._partialTextY = 0;
14337
14352
  // update text data for certain attr changes
14338
- for (var n = 0; n < attrChangeListLen; n++) {
14353
+ for (let n = 0; n < attrChangeListLen; n++) {
14339
14354
  this.on(ATTR_CHANGE_LIST$1[n] + CHANGE_KONVA, this._setTextData);
14340
14355
  }
14341
14356
  this._setTextData();
14342
14357
  }
14343
14358
  _sceneFunc(context) {
14344
- var textArr = this.textArr, textArrLen = textArr.length;
14359
+ const textArr = this.textArr, textArrLen = textArr.length;
14345
14360
  if (!this.text()) {
14346
14361
  return;
14347
14362
  }
14348
- var 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;
14363
+ 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;
14349
14364
  direction = direction === INHERIT ? context.direction : direction;
14350
- var translateY = lineHeightPx / 2;
14351
- var baseline = MIDDLE;
14365
+ let translateY = lineHeightPx / 2;
14366
+ let baseline = MIDDLE;
14352
14367
  if (Konva$2._fixTextRendering) {
14353
- var metrics = this.measureSize('M'); // Use a sample character to get the ascent
14368
+ const metrics = this.measureSize('M'); // Use a sample character to get the ascent
14354
14369
  baseline = 'alphabetic';
14355
14370
  translateY =
14356
14371
  (metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2 +
@@ -14376,7 +14391,7 @@
14376
14391
  for (n = 0; n < textArrLen; n++) {
14377
14392
  var lineTranslateX = 0;
14378
14393
  var lineTranslateY = 0;
14379
- var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, oneWord, lineWidth;
14394
+ var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, lineWidth;
14380
14395
  // horizontal alignment
14381
14396
  context.save();
14382
14397
  if (align === RIGHT) {
@@ -14388,14 +14403,13 @@
14388
14403
  if (shouldUnderline) {
14389
14404
  context.save();
14390
14405
  context.beginPath();
14391
- let yOffset = Konva$2._fixTextRendering
14406
+ const yOffset = Konva$2._fixTextRendering
14392
14407
  ? Math.round(fontSize / 4)
14393
14408
  : Math.round(fontSize / 2);
14394
14409
  const x = lineTranslateX;
14395
14410
  const y = translateY + lineTranslateY + yOffset;
14396
14411
  context.moveTo(x, y);
14397
14412
  spacesNumber = text.split(' ').length - 1;
14398
- oneWord = spacesNumber === 0;
14399
14413
  lineWidth =
14400
14414
  align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
14401
14415
  context.lineTo(x + Math.round(lineWidth), y);
@@ -14410,14 +14424,11 @@
14410
14424
  if (shouldLineThrough) {
14411
14425
  context.save();
14412
14426
  context.beginPath();
14413
- let yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0;
14427
+ const yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0;
14414
14428
  context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
14415
14429
  spacesNumber = text.split(' ').length - 1;
14416
- oneWord = spacesNumber === 0;
14417
14430
  lineWidth =
14418
- align === JUSTIFY && lastLine && !oneWord
14419
- ? totalWidth - padding * 2
14420
- : width;
14431
+ align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
14421
14432
  context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
14422
14433
  context.lineWidth = fontSize / 15;
14423
14434
  const gradient = this._getLinearGradient();
@@ -14431,9 +14442,9 @@
14431
14442
  if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) {
14432
14443
  // var words = text.split(' ');
14433
14444
  spacesNumber = text.split(' ').length - 1;
14434
- var array = stringToArray(text);
14435
- for (var li = 0; li < array.length; li++) {
14436
- var letter = array[li];
14445
+ const array = stringToArray(text);
14446
+ for (let li = 0; li < array.length; li++) {
14447
+ const letter = array[li];
14437
14448
  // skip justify for the last line
14438
14449
  if (letter === ' ' && !lastLine && align === JUSTIFY) {
14439
14450
  lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber;
@@ -14465,14 +14476,14 @@
14465
14476
  }
14466
14477
  }
14467
14478
  _hitFunc(context) {
14468
- var width = this.getWidth(), height = this.getHeight();
14479
+ const width = this.getWidth(), height = this.getHeight();
14469
14480
  context.beginPath();
14470
14481
  context.rect(0, 0, width, height);
14471
14482
  context.closePath();
14472
14483
  context.fillStrokeShape(this);
14473
14484
  }
14474
14485
  setText(text) {
14475
- var str = Util._isString(text)
14486
+ const str = Util._isString(text)
14476
14487
  ? text
14477
14488
  : text === null || text === undefined
14478
14489
  ? ''
@@ -14481,11 +14492,11 @@
14481
14492
  return this;
14482
14493
  }
14483
14494
  getWidth() {
14484
- var isAuto = this.attrs.width === AUTO || this.attrs.width === undefined;
14495
+ const isAuto = this.attrs.width === AUTO || this.attrs.width === undefined;
14485
14496
  return isAuto ? this.getTextWidth() + this.padding() * 2 : this.attrs.width;
14486
14497
  }
14487
14498
  getHeight() {
14488
- var isAuto = this.attrs.height === AUTO || this.attrs.height === undefined;
14499
+ const isAuto = this.attrs.height === AUTO || this.attrs.height === undefined;
14489
14500
  return isAuto
14490
14501
  ? this.fontSize() * this.textArr.length * this.lineHeight() +
14491
14502
  this.padding() * 2
@@ -14514,7 +14525,7 @@
14514
14525
  */
14515
14526
  measureSize(text) {
14516
14527
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
14517
- var _context = getDummyContext(), fontSize = this.fontSize(), metrics;
14528
+ let _context = getDummyContext(), fontSize = this.fontSize(), metrics;
14518
14529
  _context.save();
14519
14530
  _context.font = this._getContextFont();
14520
14531
  metrics = _context.measureText(text);
@@ -14552,7 +14563,7 @@
14552
14563
  if (align === JUSTIFY) {
14553
14564
  line = line.trim();
14554
14565
  }
14555
- var width = this._getTextWidth(line);
14566
+ const width = this._getTextWidth(line);
14556
14567
  return this.textArr.push({
14557
14568
  text: line,
14558
14569
  width: width,
@@ -14560,21 +14571,24 @@
14560
14571
  });
14561
14572
  }
14562
14573
  _getTextWidth(text) {
14563
- var letterSpacing = this.letterSpacing();
14564
- var length = text.length;
14565
- return (getDummyContext().measureText(text).width +
14566
- (length ? letterSpacing * (length - 1) : 0));
14574
+ const letterSpacing = this.letterSpacing();
14575
+ const length = text.length;
14576
+ // letterSpacing * length is the total letter spacing for the text
14577
+ // previously we used letterSpacing * (length - 1) but it doesn't match DOM behavior
14578
+ return getDummyContext().measureText(text).width + letterSpacing * length;
14567
14579
  }
14568
14580
  _setTextData() {
14569
- var 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 !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(),
14581
+ 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 !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(),
14570
14582
  // align = this.align(),
14571
14583
  shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
14572
14584
  this.textArr = [];
14573
14585
  getDummyContext().font = this._getContextFont();
14574
- var additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
14575
- for (var i = 0, max = lines.length; i < max; ++i) {
14576
- var line = lines[i];
14577
- var lineWidth = this._getTextWidth(line);
14586
+ const additionalWidth = shouldAddEllipsis
14587
+ ? this._getTextWidth(ELLIPSIS)
14588
+ : 0;
14589
+ for (let i = 0, max = lines.length; i < max; ++i) {
14590
+ let line = lines[i];
14591
+ let lineWidth = this._getTextWidth(line);
14578
14592
  if (fixedWidth && lineWidth > maxWidth) {
14579
14593
  /*
14580
14594
  * if width is fixed and line does not fit entirely
@@ -14585,9 +14599,9 @@
14585
14599
  * use binary search to find the longest substring that
14586
14600
  * that would fit in the specified width
14587
14601
  */
14588
- var low = 0, high = line.length, match = '', matchWidth = 0;
14602
+ let low = 0, high = line.length, match = '', matchWidth = 0;
14589
14603
  while (low < high) {
14590
- var mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;
14604
+ const mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;
14591
14605
  if (substrWidth <= maxWidth) {
14592
14606
  low = mid + 1;
14593
14607
  match = substr;
@@ -14607,8 +14621,8 @@
14607
14621
  if (wrapAtWord) {
14608
14622
  // try to find a space or dash where wrapping could be done
14609
14623
  var wrapIndex;
14610
- var nextChar = line[match.length];
14611
- var nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
14624
+ const nextChar = line[match.length];
14625
+ const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
14612
14626
  if (nextIsSpaceOrDash && matchWidth <= maxWidth) {
14613
14627
  wrapIndex = match.length;
14614
14628
  }
@@ -14630,7 +14644,7 @@
14630
14644
  this._addTextLine(match);
14631
14645
  textWidth = Math.max(textWidth, matchWidth);
14632
14646
  currentHeightPx += lineHeightPx;
14633
- var shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
14647
+ const shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
14634
14648
  if (shouldHandleEllipsis) {
14635
14649
  this._tryToAddEllipsisToLastLine();
14636
14650
  /*
@@ -14691,18 +14705,18 @@
14691
14705
  * @returns
14692
14706
  */
14693
14707
  _shouldHandleEllipsis(currentHeightPx) {
14694
- var fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
14708
+ const fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
14695
14709
  return (!shouldWrap ||
14696
14710
  (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx));
14697
14711
  }
14698
14712
  _tryToAddEllipsisToLastLine() {
14699
- var width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
14700
- var lastLine = this.textArr[this.textArr.length - 1];
14713
+ const width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
14714
+ const lastLine = this.textArr[this.textArr.length - 1];
14701
14715
  if (!lastLine || !shouldAddEllipsis) {
14702
14716
  return;
14703
14717
  }
14704
14718
  if (fixedWidth) {
14705
- var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
14719
+ const haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
14706
14720
  if (!haveSpace) {
14707
14721
  lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
14708
14722
  }
@@ -14976,7 +14990,7 @@
14976
14990
  */
14977
14991
  Factory.addGetterSetter(Text, 'textDecoration', '');
14978
14992
 
14979
- var EMPTY_STRING = '', NORMAL = 'normal';
14993
+ const EMPTY_STRING = '', NORMAL = 'normal';
14980
14994
  function _fillFunc(context) {
14981
14995
  context.fillText(this.partialText, 0, 0);
14982
14996
  }
@@ -15138,16 +15152,16 @@
15138
15152
  context.setAttr('textBaseline', this.textBaseline());
15139
15153
  context.setAttr('textAlign', 'left');
15140
15154
  context.save();
15141
- var textDecoration = this.textDecoration();
15142
- var fill = this.fill();
15143
- var fontSize = this.fontSize();
15144
- var glyphInfo = this.glyphInfo;
15155
+ const textDecoration = this.textDecoration();
15156
+ const fill = this.fill();
15157
+ const fontSize = this.fontSize();
15158
+ const glyphInfo = this.glyphInfo;
15145
15159
  if (textDecoration === 'underline') {
15146
15160
  context.beginPath();
15147
15161
  }
15148
- for (var i = 0; i < glyphInfo.length; i++) {
15162
+ for (let i = 0; i < glyphInfo.length; i++) {
15149
15163
  context.save();
15150
- var p0 = glyphInfo[i].p0;
15164
+ const p0 = glyphInfo[i].p0;
15151
15165
  context.translate(p0.x, p0.y);
15152
15166
  context.rotate(glyphInfo[i].rotation);
15153
15167
  this.partialText = glyphInfo[i].text;
@@ -15177,13 +15191,13 @@
15177
15191
  }
15178
15192
  _hitFunc(context) {
15179
15193
  context.beginPath();
15180
- var glyphInfo = this.glyphInfo;
15194
+ const glyphInfo = this.glyphInfo;
15181
15195
  if (glyphInfo.length >= 1) {
15182
- var p0 = glyphInfo[0].p0;
15196
+ const p0 = glyphInfo[0].p0;
15183
15197
  context.moveTo(p0.x, p0.y);
15184
15198
  }
15185
- for (var i = 0; i < glyphInfo.length; i++) {
15186
- var p1 = glyphInfo[i].p1;
15199
+ for (let i = 0; i < glyphInfo.length; i++) {
15200
+ const p1 = glyphInfo[i].p1;
15187
15201
  context.lineTo(p1.x, p1.y);
15188
15202
  }
15189
15203
  context.setAttr('lineWidth', this.fontSize());
@@ -15209,11 +15223,11 @@
15209
15223
  return Text.prototype._getContextFont.call(this);
15210
15224
  }
15211
15225
  _getTextSize(text) {
15212
- var dummyCanvas = this.dummyCanvas;
15213
- var _context = dummyCanvas.getContext('2d');
15226
+ const dummyCanvas = this.dummyCanvas;
15227
+ const _context = dummyCanvas.getContext('2d');
15214
15228
  _context.save();
15215
15229
  _context.font = this._getContextFont();
15216
- var metrics = _context.measureText(text);
15230
+ const metrics = _context.measureText(text);
15217
15231
  _context.restore();
15218
15232
  return {
15219
15233
  width: metrics.width,
@@ -15247,7 +15261,7 @@
15247
15261
  // 3. Calculate the rotation, width, and midpoint of the glyph using the start and end points,
15248
15262
  // 4. Add glyph width to the offsetToGlyph and repeat
15249
15263
  let offsetToGlyph = offset;
15250
- for (var i = 0; i < charArr.length; i++) {
15264
+ for (let i = 0; i < charArr.length; i++) {
15251
15265
  const charStartPoint = this._getPointAtLength(offsetToGlyph);
15252
15266
  if (!charStartPoint)
15253
15267
  return;
@@ -15295,19 +15309,19 @@
15295
15309
  height: 0,
15296
15310
  };
15297
15311
  }
15298
- var points = [];
15312
+ const points = [];
15299
15313
  this.glyphInfo.forEach(function (info) {
15300
15314
  points.push(info.p0.x);
15301
15315
  points.push(info.p0.y);
15302
15316
  points.push(info.p1.x);
15303
15317
  points.push(info.p1.y);
15304
15318
  });
15305
- var minX = points[0] || 0;
15306
- var maxX = points[0] || 0;
15307
- var minY = points[1] || 0;
15308
- var maxY = points[1] || 0;
15309
- var x, y;
15310
- for (var i = 0; i < points.length / 2; i++) {
15319
+ let minX = points[0] || 0;
15320
+ let maxX = points[0] || 0;
15321
+ let minY = points[1] || 0;
15322
+ let maxY = points[1] || 0;
15323
+ let x, y;
15324
+ for (let i = 0; i < points.length / 2; i++) {
15311
15325
  x = points[i * 2];
15312
15326
  y = points[i * 2 + 1];
15313
15327
  minX = Math.min(minX, x);
@@ -15315,7 +15329,7 @@
15315
15329
  minY = Math.min(minY, y);
15316
15330
  maxY = Math.max(maxY, y);
15317
15331
  }
15318
- var fontSize = this.fontSize();
15332
+ const fontSize = this.fontSize();
15319
15333
  return {
15320
15334
  x: minX - fontSize / 2,
15321
15335
  y: minY - fontSize / 2,
@@ -15480,7 +15494,7 @@
15480
15494
  * // underline text
15481
15495
  * shape.textDecoration('underline');
15482
15496
  */
15483
- Factory.addGetterSetter(TextPath, 'textDecoration', null);
15497
+ Factory.addGetterSetter(TextPath, 'textDecoration', '');
15484
15498
  /**
15485
15499
  * get/set kerning function.
15486
15500
  * @name Konva.TextPath#kerningFunc
@@ -15496,10 +15510,10 @@
15496
15510
  * return 1;
15497
15511
  * });
15498
15512
  */
15499
- Factory.addGetterSetter(TextPath, 'kerningFunc', null);
15513
+ Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
15500
15514
 
15501
- var EVENTS_NAME = 'tr-konva';
15502
- var ATTR_CHANGE_LIST = [
15515
+ const EVENTS_NAME = 'tr-konva';
15516
+ const ATTR_CHANGE_LIST = [
15503
15517
  'resizeEnabledChange',
15504
15518
  'rotateAnchorOffsetChange',
15505
15519
  'rotateEnabledChange',
@@ -15518,8 +15532,8 @@
15518
15532
  ]
15519
15533
  .map((e) => e + `.${EVENTS_NAME}`)
15520
15534
  .join(' ');
15521
- var NODES_RECT = 'nodesRect';
15522
- var TRANSFORM_CHANGE_STR = [
15535
+ const NODES_RECT = 'nodesRect';
15536
+ const TRANSFORM_CHANGE_STR = [
15523
15537
  'widthChange',
15524
15538
  'heightChange',
15525
15539
  'scaleXChange',
@@ -15532,7 +15546,7 @@
15532
15546
  'transformsEnabledChange',
15533
15547
  'strokeWidthChange',
15534
15548
  ];
15535
- var ANGLES = {
15549
+ const ANGLES = {
15536
15550
  'top-left': -45,
15537
15551
  'top-center': 0,
15538
15552
  'top-right': 45,
@@ -15548,7 +15562,7 @@
15548
15562
  return rotateCursor;
15549
15563
  }
15550
15564
  rad += Util.degToRad(ANGLES[anchorName] || 0);
15551
- var angle = ((Util.radToDeg(rad) % 360) + 360) % 360;
15565
+ const angle = ((Util.radToDeg(rad) % 360) + 360) % 360;
15552
15566
  if (Util._inRange(angle, 315 + 22.5, 360) || Util._inRange(angle, 0, 22.5)) {
15553
15567
  // TOP
15554
15568
  return 'ns-resize';
@@ -15587,7 +15601,7 @@
15587
15601
  return 'pointer';
15588
15602
  }
15589
15603
  }
15590
- var ANCHORS_NAMES = [
15604
+ const ANCHORS_NAMES = [
15591
15605
  'top-left',
15592
15606
  'top-center',
15593
15607
  'top-right',
@@ -15597,7 +15611,7 @@
15597
15611
  'bottom-center',
15598
15612
  'bottom-right',
15599
15613
  ];
15600
- var MAX_SAFE_INTEGER = 100000000;
15614
+ const MAX_SAFE_INTEGER = 100000000;
15601
15615
  function getCenter(shape) {
15602
15616
  return {
15603
15617
  x: shape.x +
@@ -15759,7 +15773,7 @@
15759
15773
  this._resetTransformCache();
15760
15774
  // we may need it if we set node in initial props
15761
15775
  // so elements are not defined yet
15762
- var elementsCreated = !!this.findOne('.top-left');
15776
+ const elementsCreated = !!this.findOne('.top-left');
15763
15777
  if (elementsCreated) {
15764
15778
  this.update();
15765
15779
  }
@@ -15854,15 +15868,15 @@
15854
15868
  }
15855
15869
  // return absolute rotated bounding rectangle
15856
15870
  __getNodeShape(node, rot = this.rotation(), relative) {
15857
- var rect = node.getClientRect({
15871
+ const rect = node.getClientRect({
15858
15872
  skipTransform: true,
15859
15873
  skipShadow: true,
15860
15874
  skipStroke: this.ignoreStroke(),
15861
15875
  });
15862
- var absScale = node.getAbsoluteScale(relative);
15863
- var absPos = node.getAbsolutePosition(relative);
15864
- var dx = rect.x * absScale.x - node.offsetX() * absScale.x;
15865
- var dy = rect.y * absScale.y - node.offsetY() * absScale.y;
15876
+ const absScale = node.getAbsoluteScale(relative);
15877
+ const absPos = node.getAbsolutePosition(relative);
15878
+ const dx = rect.x * absScale.x - node.offsetX() * absScale.x;
15879
+ const dy = rect.y * absScale.y - node.offsetY() * absScale.y;
15866
15880
  const rotation = (Konva$2.getAngle(node.getAbsoluteRotation()) + Math.PI * 2) %
15867
15881
  (Math.PI * 2);
15868
15882
  const box = {
@@ -15879,7 +15893,7 @@
15879
15893
  }
15880
15894
  // returns box + rotation of all shapes
15881
15895
  __getNodeRect() {
15882
- var node = this.getNode();
15896
+ const node = this.getNode();
15883
15897
  if (!node) {
15884
15898
  return {
15885
15899
  x: -MAX_SAFE_INTEGER,
@@ -15896,23 +15910,23 @@
15896
15910
  skipShadow: true,
15897
15911
  skipStroke: this.ignoreStroke(),
15898
15912
  });
15899
- var points = [
15913
+ const points = [
15900
15914
  { x: box.x, y: box.y },
15901
15915
  { x: box.x + box.width, y: box.y },
15902
15916
  { x: box.x + box.width, y: box.y + box.height },
15903
15917
  { x: box.x, y: box.y + box.height },
15904
15918
  ];
15905
- var trans = node.getAbsoluteTransform();
15919
+ const trans = node.getAbsoluteTransform();
15906
15920
  points.forEach(function (point) {
15907
- var transformed = trans.point(point);
15921
+ const transformed = trans.point(point);
15908
15922
  totalPoints.push(transformed);
15909
15923
  });
15910
15924
  });
15911
15925
  const tr = new Transform();
15912
15926
  tr.rotate(-Konva$2.getAngle(this.rotation()));
15913
- var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
15927
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
15914
15928
  totalPoints.forEach(function (point) {
15915
- var transformed = tr.point(point);
15929
+ const transformed = tr.point(point);
15916
15930
  if (minX === undefined) {
15917
15931
  minX = maxX = transformed.x;
15918
15932
  minY = maxY = transformed.y;
@@ -15960,7 +15974,7 @@
15960
15974
  this._createAnchor('rotater');
15961
15975
  }
15962
15976
  _createAnchor(name) {
15963
- var anchor = new Rect({
15977
+ const anchor = new Rect({
15964
15978
  stroke: 'rgb(0, 161, 255)',
15965
15979
  fill: 'white',
15966
15980
  strokeWidth: 1,
@@ -15971,7 +15985,7 @@
15971
15985
  draggable: true,
15972
15986
  hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto',
15973
15987
  });
15974
- var self = this;
15988
+ const self = this;
15975
15989
  anchor.on('mousedown touchstart', function (e) {
15976
15990
  self._handleMouseDown(e);
15977
15991
  });
@@ -15984,9 +15998,9 @@
15984
15998
  });
15985
15999
  // add hover styling
15986
16000
  anchor.on('mouseenter', () => {
15987
- var rad = Konva$2.getAngle(this.rotation());
15988
- var rotateCursor = this.rotateAnchorCursor();
15989
- var cursor = getCursor(name, rad, rotateCursor);
16001
+ const rad = Konva$2.getAngle(this.rotation());
16002
+ const rotateCursor = this.rotateAnchorCursor();
16003
+ const cursor = getCursor(name, rad, rotateCursor);
15990
16004
  anchor.getStage().content &&
15991
16005
  (anchor.getStage().content.style.cursor = cursor);
15992
16006
  this._cursorChange = true;
@@ -15999,14 +16013,14 @@
15999
16013
  this.add(anchor);
16000
16014
  }
16001
16015
  _createBack() {
16002
- var back = new Shape({
16016
+ const back = new Shape({
16003
16017
  name: 'back',
16004
16018
  width: 0,
16005
16019
  height: 0,
16006
16020
  draggable: true,
16007
16021
  sceneFunc(ctx, shape) {
16008
- var tr = shape.getParent();
16009
- var padding = tr.padding();
16022
+ const tr = shape.getParent();
16023
+ const padding = tr.padding();
16010
16024
  ctx.beginPath();
16011
16025
  ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
16012
16026
  ctx.moveTo(shape.width() / 2, -padding);
@@ -16019,7 +16033,7 @@
16019
16033
  if (!this.shouldOverdrawWholeArea()) {
16020
16034
  return;
16021
16035
  }
16022
- var padding = this.padding();
16036
+ const padding = this.padding();
16023
16037
  ctx.beginPath();
16024
16038
  ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
16025
16039
  ctx.fillStrokeShape(shape);
@@ -16051,10 +16065,10 @@
16051
16065
  return;
16052
16066
  }
16053
16067
  this._movingAnchorName = e.target.name().split(' ')[0];
16054
- var attrs = this._getNodeRect();
16055
- var width = attrs.width;
16056
- var height = attrs.height;
16057
- var hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
16068
+ const attrs = this._getNodeRect();
16069
+ const width = attrs.width;
16070
+ const height = attrs.height;
16071
+ const hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
16058
16072
  this.sin = Math.abs(height / hypotenuse);
16059
16073
  this.cos = Math.abs(width / hypotenuse);
16060
16074
  if (typeof window !== 'undefined') {
@@ -16064,8 +16078,8 @@
16064
16078
  window.addEventListener('touchend', this._handleMouseUp, true);
16065
16079
  }
16066
16080
  this._transforming = true;
16067
- var ap = e.target.getAbsolutePosition();
16068
- var pos = e.target.getStage().getPointerPosition();
16081
+ const ap = e.target.getAbsolutePosition();
16082
+ const pos = e.target.getStage().getPointerPosition();
16069
16083
  this._anchorDragOffset = {
16070
16084
  x: pos.x - ap.x,
16071
16085
  y: pos.y - ap.y,
@@ -16077,9 +16091,9 @@
16077
16091
  });
16078
16092
  }
16079
16093
  _handleMouseMove(e) {
16080
- var x, y, newHypotenuse;
16081
- var anchorNode = this.findOne('.' + this._movingAnchorName);
16082
- var stage = anchorNode.getStage();
16094
+ let x, y, newHypotenuse;
16095
+ const anchorNode = this.findOne('.' + this._movingAnchorName);
16096
+ const stage = anchorNode.getStage();
16083
16097
  stage.setPointersPositions(e);
16084
16098
  const pp = stage.getPointerPosition();
16085
16099
  let newNodePos = {
@@ -16098,7 +16112,7 @@
16098
16112
  }
16099
16113
  // rotater is working very differently, so do it first
16100
16114
  if (this._movingAnchorName === 'rotater') {
16101
- var attrs = this._getNodeRect();
16115
+ const attrs = this._getNodeRect();
16102
16116
  x = anchorNode.x() - attrs.width / 2;
16103
16117
  y = -anchorNode.y() + attrs.height / 2;
16104
16118
  // hor angle is changed?
@@ -16106,7 +16120,7 @@
16106
16120
  if (attrs.height < 0) {
16107
16121
  delta -= Math.PI;
16108
16122
  }
16109
- var oldRotation = Konva$2.getAngle(this.rotation());
16123
+ const oldRotation = Konva$2.getAngle(this.rotation());
16110
16124
  const newRotation = oldRotation + delta;
16111
16125
  const tol = Konva$2.getAngle(this.rotationSnapTolerance());
16112
16126
  const snappedRot = getSnap(this.rotationSnaps(), newRotation, tol);
@@ -16115,8 +16129,8 @@
16115
16129
  this._fitNodesInto(shape, e);
16116
16130
  return;
16117
16131
  }
16118
- var shiftBehavior = this.shiftBehavior();
16119
- var keepProportion;
16132
+ const shiftBehavior = this.shiftBehavior();
16133
+ let keepProportion;
16120
16134
  if (shiftBehavior === 'inverted') {
16121
16135
  keepProportion = this.keepRatio() && !e.shiftKey;
16122
16136
  }
@@ -16235,12 +16249,12 @@
16235
16249
  }
16236
16250
  var centeredScaling = this.centeredScaling() || e.altKey;
16237
16251
  if (centeredScaling) {
16238
- var topLeft = this.findOne('.top-left');
16239
- var bottomRight = this.findOne('.bottom-right');
16240
- var topOffsetX = topLeft.x();
16241
- var topOffsetY = topLeft.y();
16242
- var bottomOffsetX = this.getWidth() - bottomRight.x();
16243
- var bottomOffsetY = this.getHeight() - bottomRight.y();
16252
+ const topLeft = this.findOne('.top-left');
16253
+ const bottomRight = this.findOne('.bottom-right');
16254
+ const topOffsetX = topLeft.x();
16255
+ const topOffsetY = topLeft.y();
16256
+ const bottomOffsetX = this.getWidth() - bottomRight.x();
16257
+ const bottomOffsetY = this.getHeight() - bottomRight.y();
16244
16258
  bottomRight.move({
16245
16259
  x: -topOffsetX,
16246
16260
  y: -topOffsetY,
@@ -16250,11 +16264,11 @@
16250
16264
  y: bottomOffsetY,
16251
16265
  });
16252
16266
  }
16253
- var absPos = this.findOne('.top-left').getAbsolutePosition();
16267
+ const absPos = this.findOne('.top-left').getAbsolutePosition();
16254
16268
  x = absPos.x;
16255
16269
  y = absPos.y;
16256
- var width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();
16257
- var height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
16270
+ const width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();
16271
+ const height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
16258
16272
  this._fitNodesInto({
16259
16273
  x: x,
16260
16274
  y: y,
@@ -16279,7 +16293,7 @@
16279
16293
  window.removeEventListener('mouseup', this._handleMouseUp, true);
16280
16294
  window.removeEventListener('touchend', this._handleMouseUp, true);
16281
16295
  }
16282
- var node = this.getNode();
16296
+ const node = this.getNode();
16283
16297
  activeTransformersCount--;
16284
16298
  this._fire('transformend', { evt: e, target: node });
16285
16299
  // redraw layer to restore hit graph
@@ -16296,7 +16310,7 @@
16296
16310
  }
16297
16311
  }
16298
16312
  _fitNodesInto(newAttrs, evt) {
16299
- var oldAttrs = this._getNodeRect();
16313
+ const oldAttrs = this._getNodeRect();
16300
16314
  const minSize = 1;
16301
16315
  if (Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) {
16302
16316
  this.update();
@@ -16306,7 +16320,7 @@
16306
16320
  this.update();
16307
16321
  return;
16308
16322
  }
16309
- var t = new Transform();
16323
+ const t = new Transform();
16310
16324
  t.rotate(Konva$2.getAngle(this.rotation()));
16311
16325
  if (this._movingAnchorName &&
16312
16326
  newAttrs.width < 0 &&
@@ -16446,14 +16460,14 @@
16446
16460
  }
16447
16461
  update() {
16448
16462
  var _a;
16449
- var attrs = this._getNodeRect();
16463
+ const attrs = this._getNodeRect();
16450
16464
  this.rotation(Util._getRotation(attrs.rotation));
16451
- var width = attrs.width;
16452
- var height = attrs.height;
16453
- var enabledAnchors = this.enabledAnchors();
16454
- var resizeEnabled = this.resizeEnabled();
16455
- var padding = this.padding();
16456
- var anchorSize = this.anchorSize();
16465
+ const width = attrs.width;
16466
+ const height = attrs.height;
16467
+ const enabledAnchors = this.enabledAnchors();
16468
+ const resizeEnabled = this.resizeEnabled();
16469
+ const padding = this.padding();
16470
+ const anchorSize = this.anchorSize();
16457
16471
  const anchors = this.find('._anchor');
16458
16472
  anchors.forEach((node) => {
16459
16473
  node.setAttrs({
@@ -16560,7 +16574,7 @@
16560
16574
  stopTransform() {
16561
16575
  if (this._transforming) {
16562
16576
  this._removeEvents();
16563
- var anchorNode = this.findOne('.' + this._movingAnchorName);
16577
+ const anchorNode = this.findOne('.' + this._movingAnchorName);
16564
16578
  if (anchorNode) {
16565
16579
  anchorNode.stopDrag();
16566
16580
  }
@@ -16582,7 +16596,7 @@
16582
16596
  }
16583
16597
  // overwrite clone to NOT use method from Container
16584
16598
  clone(obj) {
16585
- var node = Node.prototype.clone.call(this, obj);
16599
+ const node = Node.prototype.clone.call(this, obj);
16586
16600
  return node;
16587
16601
  }
16588
16602
  getClientRect() {
@@ -16940,7 +16954,6 @@
16940
16954
  * transformer.padding(10);
16941
16955
  */
16942
16956
  Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator());
16943
- Factory.addGetterSetter(Transformer, 'node');
16944
16957
  /**
16945
16958
  * get/set attached nodes of the Transformer. Transformer will adapt to their size and listen to their events
16946
16959
  * @method
@@ -16960,6 +16973,9 @@
16960
16973
  * transformer.nodes(newNodes);
16961
16974
  */
16962
16975
  Factory.addGetterSetter(Transformer, 'nodes');
16976
+ // @ts-ignore
16977
+ // deprecated
16978
+ Factory.addGetterSetter(Transformer, 'node');
16963
16979
  /**
16964
16980
  * get/set bounding box function. **IMPORTANT!** boundBondFunc operates in absolute coordinates.
16965
16981
  * @name Konva.Transformer#boundBoxFunc
@@ -17280,7 +17296,7 @@
17280
17296
  this.a = 0;
17281
17297
  this.next = null;
17282
17298
  }
17283
- var mul_table = [
17299
+ const mul_table = [
17284
17300
  512, 512, 456, 512, 328, 456, 335, 512, 405, 328, 271, 456, 388, 335, 292,
17285
17301
  512, 454, 405, 364, 328, 298, 271, 496, 456, 420, 388, 360, 335, 312, 292,
17286
17302
  273, 512, 482, 454, 428, 405, 383, 364, 345, 328, 312, 298, 284, 271, 259,
@@ -17299,7 +17315,7 @@
17299
17315
  329, 326, 323, 320, 318, 315, 312, 310, 307, 304, 302, 299, 297, 294, 292,
17300
17316
  289, 287, 285, 282, 280, 278, 275, 273, 271, 269, 267, 265, 263, 261, 259,
17301
17317
  ];
17302
- var shg_table = [
17318
+ const shg_table = [
17303
17319
  9, 11, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17,
17304
17320
  17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19,
17305
17321
  19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
@@ -17316,9 +17332,10 @@
17316
17332
  24, 24, 24, 24, 24, 24, 24,
17317
17333
  ];
17318
17334
  function filterGaussBlurRGBA(imageData, radius) {
17319
- var pixels = imageData.data, width = imageData.width, height = imageData.height;
17320
- var 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;
17321
- var 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];
17335
+ const pixels = imageData.data, width = imageData.width, height = imageData.height;
17336
+ 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;
17337
+ const div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(), mul_sum = mul_table[radius], shg_sum = shg_table[radius];
17338
+ let stackEnd = null, stack = stackStart, stackIn = null, stackOut = null;
17322
17339
  for (i = 1; i < div; i++) {
17323
17340
  stack = stack.next = new BlurStack();
17324
17341
  if (i === radiusPlus1) {
@@ -17509,7 +17526,7 @@
17509
17526
  * node.blurRadius(10);
17510
17527
  */
17511
17528
  const Blur = function Blur(imageData) {
17512
- var radius = Math.round(this.blurRadius());
17529
+ const radius = Math.round(this.blurRadius());
17513
17530
  if (radius > 0) {
17514
17531
  filterGaussBlurRGBA(imageData, radius);
17515
17532
  }
@@ -17534,8 +17551,8 @@
17534
17551
  * node.brightness(0.8);
17535
17552
  */
17536
17553
  const Brighten = function (imageData) {
17537
- var brightness = this.brightness() * 255, data = imageData.data, len = data.length, i;
17538
- for (i = 0; i < len; i += 4) {
17554
+ const brightness = this.brightness() * 255, data = imageData.data, len = data.length;
17555
+ for (let i = 0; i < len; i += 4) {
17539
17556
  // red
17540
17557
  data[i] += brightness;
17541
17558
  // green
@@ -17566,9 +17583,10 @@
17566
17583
  * node.contrast(10);
17567
17584
  */
17568
17585
  const Contrast = function (imageData) {
17569
- var adjust = Math.pow((this.contrast() + 100) / 100, 2);
17570
- var data = imageData.data, nPixels = data.length, red = 150, green = 150, blue = 150, i;
17571
- for (i = 0; i < nPixels; i += 4) {
17586
+ const adjust = Math.pow((this.contrast() + 100) / 100, 2);
17587
+ const data = imageData.data, nPixels = data.length;
17588
+ let red = 150, green = 150, blue = 150;
17589
+ for (let i = 0; i < nPixels; i += 4) {
17572
17590
  red = data[i];
17573
17591
  green = data[i + 1];
17574
17592
  blue = data[i + 2];
@@ -17629,7 +17647,8 @@
17629
17647
  // pixastic greyLevel is between 0 and 255. I want it between 0 and 1. Also,
17630
17648
  // a max value of greyLevel yields a white emboss, and the min value yields a black
17631
17649
  // emboss. Therefore, I changed greyLevel to whiteLevel
17632
- var 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;
17650
+ const strength = this.embossStrength() * 10, greyLevel = this.embossWhiteLevel() * 255, direction = this.embossDirection(), blend = this.embossBlend(), data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4;
17651
+ let dirY = 0, dirX = 0, y = h;
17633
17652
  switch (direction) {
17634
17653
  case 'top-left':
17635
17654
  dirY = -1;
@@ -17667,33 +17686,33 @@
17667
17686
  Util.error('Unknown emboss direction: ' + direction);
17668
17687
  }
17669
17688
  do {
17670
- var offsetY = (y - 1) * w4;
17671
- var otherY = dirY;
17689
+ const offsetY = (y - 1) * w4;
17690
+ let otherY = dirY;
17672
17691
  if (y + otherY < 1) {
17673
17692
  otherY = 0;
17674
17693
  }
17675
17694
  if (y + otherY > h) {
17676
17695
  otherY = 0;
17677
17696
  }
17678
- var offsetYOther = (y - 1 + otherY) * w * 4;
17679
- var x = w;
17697
+ const offsetYOther = (y - 1 + otherY) * w * 4;
17698
+ let x = w;
17680
17699
  do {
17681
- var offset = offsetY + (x - 1) * 4;
17682
- var otherX = dirX;
17700
+ const offset = offsetY + (x - 1) * 4;
17701
+ let otherX = dirX;
17683
17702
  if (x + otherX < 1) {
17684
17703
  otherX = 0;
17685
17704
  }
17686
17705
  if (x + otherX > w) {
17687
17706
  otherX = 0;
17688
17707
  }
17689
- var offsetOther = offsetYOther + (x - 1 + otherX) * 4;
17690
- var dR = data[offset] - data[offsetOther];
17691
- var dG = data[offset + 1] - data[offsetOther + 1];
17692
- var dB = data[offset + 2] - data[offsetOther + 2];
17693
- var dif = dR;
17694
- var absDif = dif > 0 ? dif : -dif;
17695
- var absG = dG > 0 ? dG : -dG;
17696
- var absB = dB > 0 ? dB : -dB;
17708
+ const offsetOther = offsetYOther + (x - 1 + otherX) * 4;
17709
+ const dR = data[offset] - data[offsetOther];
17710
+ const dG = data[offset + 1] - data[offsetOther + 1];
17711
+ const dB = data[offset + 2] - data[offsetOther + 2];
17712
+ let dif = dR;
17713
+ const absDif = dif > 0 ? dif : -dif;
17714
+ const absG = dG > 0 ? dG : -dG;
17715
+ const absB = dB > 0 ? dB : -dB;
17697
17716
  if (absG > absDif) {
17698
17717
  dif = dG;
17699
17718
  }
@@ -17702,15 +17721,15 @@
17702
17721
  }
17703
17722
  dif *= strength;
17704
17723
  if (blend) {
17705
- var r = data[offset] + dif;
17706
- var g = data[offset + 1] + dif;
17707
- var b = data[offset + 2] + dif;
17724
+ const r = data[offset] + dif;
17725
+ const g = data[offset + 1] + dif;
17726
+ const b = data[offset + 2] + dif;
17708
17727
  data[offset] = r > 255 ? 255 : r < 0 ? 0 : r;
17709
17728
  data[offset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
17710
17729
  data[offset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
17711
17730
  }
17712
17731
  else {
17713
- var grey = greyLevel - dif;
17732
+ let grey = greyLevel - dif;
17714
17733
  if (grey < 0) {
17715
17734
  grey = 0;
17716
17735
  }
@@ -17738,7 +17757,7 @@
17738
17757
  * @param {Number} embossWhiteLevel between 0 and 1. Default is 0.5
17739
17758
  * @returns {Number}
17740
17759
  */
17741
- Factory.addGetterSetter(Node, 'embossDirection', 'top-left', null, Factory.afterSetFilter);
17760
+ Factory.addGetterSetter(Node, 'embossDirection', 'top-left', undefined, Factory.afterSetFilter);
17742
17761
  /**
17743
17762
  * get/set emboss direction. Use with {@link Konva.Filters.Emboss} filter.
17744
17763
  * @name Konva.Node#embossDirection
@@ -17747,7 +17766,7 @@
17747
17766
  * The default is top-left
17748
17767
  * @returns {String}
17749
17768
  */
17750
- Factory.addGetterSetter(Node, 'embossBlend', false, null, Factory.afterSetFilter);
17769
+ Factory.addGetterSetter(Node, 'embossBlend', false, undefined, Factory.afterSetFilter);
17751
17770
  /**
17752
17771
  * get/set emboss blend. Use with {@link Konva.Filters.Emboss} filter.
17753
17772
  * @name Konva.Node#embossBlend
@@ -17758,7 +17777,7 @@
17758
17777
 
17759
17778
  function remap(fromValue, fromMin, fromMax, toMin, toMax) {
17760
17779
  // Compute the range of the data
17761
- var fromRange = fromMax - fromMin, toRange = toMax - toMin, toValue;
17780
+ const fromRange = fromMax - fromMin, toRange = toMax - toMin;
17762
17781
  // If either range is 0, then the value can only be mapped to 1 value
17763
17782
  if (fromRange === 0) {
17764
17783
  return toMin + toRange / 2;
@@ -17767,7 +17786,7 @@
17767
17786
  return toMin;
17768
17787
  }
17769
17788
  // (1) untranslate, (2) unscale, (3) rescale, (4) retranslate
17770
- toValue = (fromValue - fromMin) / fromRange;
17789
+ let toValue = (fromValue - fromMin) / fromRange;
17771
17790
  toValue = toRange * toValue + toMin;
17772
17791
  return toValue;
17773
17792
  }
@@ -17786,14 +17805,15 @@
17786
17805
  * node.enhance(0.4);
17787
17806
  */
17788
17807
  const Enhance = function (imageData) {
17789
- var 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;
17808
+ const data = imageData.data, nSubPixels = data.length;
17809
+ let rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b;
17790
17810
  // If we are not enhancing anything - don't do any computation
17791
- var enhanceAmount = this.enhance();
17811
+ const enhanceAmount = this.enhance();
17792
17812
  if (enhanceAmount === 0) {
17793
17813
  return;
17794
17814
  }
17795
17815
  // 1st Pass - find the min and max for each channel:
17796
- for (i = 0; i < nSubPixels; i += 4) {
17816
+ for (let i = 0; i < nSubPixels; i += 4) {
17797
17817
  r = data[i + 0];
17798
17818
  if (r < rMin) {
17799
17819
  rMin = r;
@@ -17832,7 +17852,7 @@
17832
17852
  bMax = 255;
17833
17853
  bMin = 0;
17834
17854
  }
17835
- var rMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin;
17855
+ let rMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin;
17836
17856
  // If the enhancement is positive - stretch the histogram
17837
17857
  if (enhanceAmount > 0) {
17838
17858
  rGoalMax = rMax + enhanceAmount * (255 - rMax);
@@ -17855,7 +17875,7 @@
17855
17875
  bGoalMin = bMin + enhanceAmount * (bMin - bMid);
17856
17876
  }
17857
17877
  // Pass 2 - remap everything, except the alpha
17858
- for (i = 0; i < nSubPixels; i += 4) {
17878
+ for (let i = 0; i < nSubPixels; i += 4) {
17859
17879
  data[i + 0] = remap(data[i + 0], rMin, rMax, rGoalMin, rGoalMax);
17860
17880
  data[i + 1] = remap(data[i + 1], gMin, gMax, gGoalMin, gGoalMax);
17861
17881
  data[i + 2] = remap(data[i + 2], bMin, bMax, bGoalMin, bGoalMax);
@@ -17881,9 +17901,9 @@
17881
17901
  * node.filters([Konva.Filters.Grayscale]);
17882
17902
  */
17883
17903
  const Grayscale = function (imageData) {
17884
- var data = imageData.data, len = data.length, i, brightness;
17885
- for (i = 0; i < len; i += 4) {
17886
- brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
17904
+ const data = imageData.data, len = data.length;
17905
+ for (let i = 0; i < len; i += 4) {
17906
+ const brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
17887
17907
  // red
17888
17908
  data[i] = brightness;
17889
17909
  // green
@@ -17928,7 +17948,7 @@
17928
17948
  * image.luminance(0.2);
17929
17949
  */
17930
17950
  const HSL = function (imageData) {
17931
- var 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;
17951
+ const 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;
17932
17952
  // Basis for the technique used:
17933
17953
  // http://beesbuzz.biz/code/hsv_color_transforms.php
17934
17954
  // V is the value multiplier (1 for none, 2 for double, 0.5 for half)
@@ -17940,13 +17960,13 @@
17940
17960
  //[ .299V-.299vsu-.328vsw .587V+.413vsu+.035vsw .114V-.114vsu+.292vsw ]*[G]
17941
17961
  //[ .299V-.300vsu+1.25vsw .587V-.588vsu-1.05vsw .114V+.886vsu-.203vsw ] [B]
17942
17962
  // Precompute the values in the matrix:
17943
- var vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
17963
+ const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
17944
17964
  // (result spot)(source spot)
17945
- var 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;
17946
- var 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;
17947
- var 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;
17948
- var r, g, b, a;
17949
- for (i = 0; i < nPixels; i += 4) {
17965
+ 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;
17966
+ 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;
17967
+ 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;
17968
+ let r, g, b, a;
17969
+ for (let i = 0; i < nPixels; i += 4) {
17950
17970
  r = data[i + 0];
17951
17971
  g = data[i + 1];
17952
17972
  b = data[i + 2];
@@ -17970,7 +17990,7 @@
17970
17990
  * image.value(200);
17971
17991
  */
17972
17992
  const HSV = function (imageData) {
17973
- 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;
17993
+ 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;
17974
17994
  // Basis for the technique used:
17975
17995
  // http://beesbuzz.biz/code/hsv_color_transforms.php
17976
17996
  // V is the value multiplier (1 for none, 2 for double, 0.5 for half)
@@ -17982,13 +18002,13 @@
17982
18002
  //[ .299V-.299vsu-.328vsw .587V+.413vsu+.035vsw .114V-.114vsu+.292vsw ]*[G]
17983
18003
  //[ .299V-.300vsu+1.25vsw .587V-.588vsu-1.05vsw .114V+.886vsu-.203vsw ] [B]
17984
18004
  // Precompute the values in the matrix:
17985
- var vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
18005
+ const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
17986
18006
  // (result spot)(source spot)
17987
- var 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;
17988
- var 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;
17989
- var 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;
17990
- var r, g, b, a;
17991
- for (i = 0; i < nPixels; i += 4) {
18007
+ 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;
18008
+ 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;
18009
+ 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;
18010
+ let r, g, b, a;
18011
+ for (let i = 0; i < nPixels; i += 4) {
17992
18012
  r = data[i + 0];
17993
18013
  g = data[i + 1];
17994
18014
  b = data[i + 2];
@@ -18034,8 +18054,8 @@
18034
18054
  * node.filters([Konva.Filters.Invert]);
18035
18055
  */
18036
18056
  const Invert = function (imageData) {
18037
- var data = imageData.data, len = data.length, i;
18038
- for (i = 0; i < len; i += 4) {
18057
+ const data = imageData.data, len = data.length;
18058
+ for (let i = 0; i < len; i += 4) {
18039
18059
  // red
18040
18060
  data[i] = 255 - data[i];
18041
18061
  // green
@@ -18060,31 +18080,31 @@
18060
18080
  * @param {Number} [opt.polarCenterY] vertical location for the center of the circle,
18061
18081
  * default is in the middle
18062
18082
  */
18063
- var ToPolar = function (src, dst, opt) {
18064
- var 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;
18083
+ const ToPolar = function (src, dst, opt) {
18084
+ const srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2;
18065
18085
  // Find the largest radius
18066
- var rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
18067
- x = xSize - xMid;
18068
- y = ySize - yMid;
18069
- rad = Math.sqrt(x * x + y * y);
18086
+ let rMax = Math.sqrt(xMid * xMid + yMid * yMid);
18087
+ let x = xSize - xMid;
18088
+ let y = ySize - yMid;
18089
+ const rad = Math.sqrt(x * x + y * y);
18070
18090
  rMax = rad > rMax ? rad : rMax;
18071
18091
  // We'll be uisng y as the radius, and x as the angle (theta=t)
18072
- var rSize = ySize, tSize = xSize, radius, theta;
18092
+ const rSize = ySize, tSize = xSize;
18073
18093
  // We want to cover all angles (0-360) and we need to convert to
18074
18094
  // radians (*PI/180)
18075
- var conversion = ((360 / tSize) * Math.PI) / 180, sin, cos;
18095
+ const conversion = ((360 / tSize) * Math.PI) / 180;
18076
18096
  // var x1, x2, x1i, x2i, y1, y2, y1i, y2i, scale;
18077
- for (theta = 0; theta < tSize; theta += 1) {
18078
- sin = Math.sin(theta * conversion);
18079
- cos = Math.cos(theta * conversion);
18080
- for (radius = 0; radius < rSize; radius += 1) {
18097
+ for (let theta = 0; theta < tSize; theta += 1) {
18098
+ const sin = Math.sin(theta * conversion);
18099
+ const cos = Math.cos(theta * conversion);
18100
+ for (let radius = 0; radius < rSize; radius += 1) {
18081
18101
  x = Math.floor(xMid + ((rMax * radius) / rSize) * cos);
18082
18102
  y = Math.floor(yMid + ((rMax * radius) / rSize) * sin);
18083
- i = (y * xSize + x) * 4;
18084
- r = srcPixels[i + 0];
18085
- g = srcPixels[i + 1];
18086
- b = srcPixels[i + 2];
18087
- a = srcPixels[i + 3];
18103
+ let i = (y * xSize + x) * 4;
18104
+ const r = srcPixels[i + 0];
18105
+ const g = srcPixels[i + 1];
18106
+ const b = srcPixels[i + 2];
18107
+ const a = srcPixels[i + 3];
18088
18108
  // Store it
18089
18109
  //i = (theta * xSize + radius) * 4;
18090
18110
  i = (theta + radius * xSize) * 4;
@@ -18111,35 +18131,35 @@
18111
18131
  * @param {Number} [opt.polarRotation] amount to rotate the image counterclockwis,
18112
18132
  * 0 is no rotation, 360 degrees is a full rotation
18113
18133
  */
18114
- var FromPolar = function (src, dst, opt) {
18115
- var 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;
18134
+ const FromPolar = function (src, dst, opt) {
18135
+ const srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2;
18116
18136
  // Find the largest radius
18117
- var rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
18118
- x = xSize - xMid;
18119
- y = ySize - yMid;
18120
- rad = Math.sqrt(x * x + y * y);
18137
+ let rMax = Math.sqrt(xMid * xMid + yMid * yMid);
18138
+ let x = xSize - xMid;
18139
+ let y = ySize - yMid;
18140
+ const rad = Math.sqrt(x * x + y * y);
18121
18141
  rMax = rad > rMax ? rad : rMax;
18122
18142
  // We'll be uisng x as the radius, and y as the angle (theta=t)
18123
- var rSize = ySize, tSize = xSize, radius, theta, phaseShift = 0;
18143
+ const rSize = ySize, tSize = xSize, phaseShift = 0;
18124
18144
  // We need to convert to degrees and we need to make sure
18125
18145
  // it's between (0-360)
18126
18146
  // var conversion = tSize/360*180/Math.PI;
18127
18147
  //var conversion = tSize/360*180/Math.PI;
18128
- var x1, y1;
18148
+ let x1, y1;
18129
18149
  for (x = 0; x < xSize; x += 1) {
18130
18150
  for (y = 0; y < ySize; y += 1) {
18131
- dx = x - xMid;
18132
- dy = y - yMid;
18133
- radius = (Math.sqrt(dx * dx + dy * dy) * rSize) / rMax;
18134
- theta = ((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
18151
+ const dx = x - xMid;
18152
+ const dy = y - yMid;
18153
+ const radius = (Math.sqrt(dx * dx + dy * dy) * rSize) / rMax;
18154
+ let theta = ((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
18135
18155
  theta = (theta * tSize) / 360;
18136
18156
  x1 = Math.floor(theta);
18137
18157
  y1 = Math.floor(radius);
18138
- i = (y1 * xSize + x1) * 4;
18139
- r = srcPixels[i + 0];
18140
- g = srcPixels[i + 1];
18141
- b = srcPixels[i + 2];
18142
- a = srcPixels[i + 3];
18158
+ let i = (y1 * xSize + x1) * 4;
18159
+ const r = srcPixels[i + 0];
18160
+ const g = srcPixels[i + 1];
18161
+ const b = srcPixels[i + 2];
18162
+ const a = srcPixels[i + 3];
18143
18163
  // Store it
18144
18164
  i = (y * xSize + x) * 4;
18145
18165
  dstPixels[i + 0] = r;
@@ -18165,19 +18185,19 @@
18165
18185
  * node.kaleidoscopeAngle(45);
18166
18186
  */
18167
18187
  const Kaleidoscope = function (imageData) {
18168
- var xSize = imageData.width, ySize = imageData.height;
18169
- var x, y, xoff, i, r, g, b, a, srcPos, dstPos;
18170
- var power = Math.round(this.kaleidoscopePower());
18171
- var angle = Math.round(this.kaleidoscopeAngle());
18172
- var offset = Math.floor((xSize * (angle % 360)) / 360);
18188
+ const xSize = imageData.width, ySize = imageData.height;
18189
+ let x, y, xoff, i, r, g, b, a, srcPos, dstPos;
18190
+ let power = Math.round(this.kaleidoscopePower());
18191
+ const angle = Math.round(this.kaleidoscopeAngle());
18192
+ const offset = Math.floor((xSize * (angle % 360)) / 360);
18173
18193
  if (power < 1) {
18174
18194
  return;
18175
18195
  }
18176
18196
  // Work with our shared buffer canvas
18177
- var tempCanvas = Util.createCanvasElement();
18197
+ const tempCanvas = Util.createCanvasElement();
18178
18198
  tempCanvas.width = xSize;
18179
18199
  tempCanvas.height = ySize;
18180
- var scratchData = tempCanvas
18200
+ const scratchData = tempCanvas
18181
18201
  .getContext('2d')
18182
18202
  .getImageData(0, 0, xSize, ySize);
18183
18203
  Util.releaseCanvas(tempCanvas);
@@ -18188,17 +18208,17 @@
18188
18208
  });
18189
18209
  // Determine how big each section will be, if it's too small
18190
18210
  // make it bigger
18191
- var minSectionSize = xSize / Math.pow(2, power);
18211
+ let minSectionSize = xSize / Math.pow(2, power);
18192
18212
  while (minSectionSize <= 8) {
18193
18213
  minSectionSize = minSectionSize * 2;
18194
18214
  power -= 1;
18195
18215
  }
18196
18216
  minSectionSize = Math.ceil(minSectionSize);
18197
- var sectionSize = minSectionSize;
18217
+ let sectionSize = minSectionSize;
18198
18218
  // Copy the offset region to 0
18199
18219
  // Depending on the size of filter and location of the offset we may need
18200
18220
  // to copy the section backwards to prevent it from rewriting itself
18201
- var xStart = 0, xEnd = sectionSize, xDelta = 1;
18221
+ let xStart = 0, xEnd = sectionSize, xDelta = 1;
18202
18222
  if (offset + minSectionSize > xSize) {
18203
18223
  xStart = sectionSize;
18204
18224
  xEnd = 0;
@@ -18259,8 +18279,8 @@
18259
18279
  Factory.addGetterSetter(Node, 'kaleidoscopeAngle', 0, getNumberValidator(), Factory.afterSetFilter);
18260
18280
 
18261
18281
  function pixelAt(idata, x, y) {
18262
- var idx = (y * idata.width + x) * 4;
18263
- var d = [];
18282
+ let idx = (y * idata.width + x) * 4;
18283
+ const d = [];
18264
18284
  d.push(idata.data[idx++], idata.data[idx++], idata.data[idx++], idata.data[idx++]);
18265
18285
  return d;
18266
18286
  }
@@ -18270,8 +18290,8 @@
18270
18290
  Math.pow(p1[2] - p2[2], 2));
18271
18291
  }
18272
18292
  function rgbMean(pTab) {
18273
- var m = [0, 0, 0];
18274
- for (var i = 0; i < pTab.length; i++) {
18293
+ const m = [0, 0, 0];
18294
+ for (let i = 0; i < pTab.length; i++) {
18275
18295
  m[0] += pTab[i][0];
18276
18296
  m[1] += pTab[i][1];
18277
18297
  m[2] += pTab[i][2];
@@ -18282,21 +18302,21 @@
18282
18302
  return m;
18283
18303
  }
18284
18304
  function backgroundMask(idata, threshold) {
18285
- var rgbv_no = pixelAt(idata, 0, 0);
18286
- var rgbv_ne = pixelAt(idata, idata.width - 1, 0);
18287
- var rgbv_so = pixelAt(idata, 0, idata.height - 1);
18288
- var rgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1);
18289
- var thres = threshold || 10;
18305
+ const rgbv_no = pixelAt(idata, 0, 0);
18306
+ const rgbv_ne = pixelAt(idata, idata.width - 1, 0);
18307
+ const rgbv_so = pixelAt(idata, 0, idata.height - 1);
18308
+ const rgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1);
18309
+ const thres = threshold || 10;
18290
18310
  if (rgbDistance(rgbv_no, rgbv_ne) < thres &&
18291
18311
  rgbDistance(rgbv_ne, rgbv_se) < thres &&
18292
18312
  rgbDistance(rgbv_se, rgbv_so) < thres &&
18293
18313
  rgbDistance(rgbv_so, rgbv_no) < thres) {
18294
18314
  // Mean color
18295
- var mean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]);
18315
+ const mean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]);
18296
18316
  // Mask based on color distance
18297
- var mask = [];
18298
- for (var i = 0; i < idata.width * idata.height; i++) {
18299
- var d = rgbDistance(mean, [
18317
+ const mask = [];
18318
+ for (let i = 0; i < idata.width * idata.height; i++) {
18319
+ const d = rgbDistance(mean, [
18300
18320
  idata.data[i * 4],
18301
18321
  idata.data[i * 4 + 1],
18302
18322
  idata.data[i * 4 + 2],
@@ -18307,26 +18327,26 @@
18307
18327
  }
18308
18328
  }
18309
18329
  function applyMask(idata, mask) {
18310
- for (var i = 0; i < idata.width * idata.height; i++) {
18330
+ for (let i = 0; i < idata.width * idata.height; i++) {
18311
18331
  idata.data[4 * i + 3] = mask[i];
18312
18332
  }
18313
18333
  }
18314
18334
  function erodeMask(mask, sw, sh) {
18315
- var weights = [1, 1, 1, 1, 0, 1, 1, 1, 1];
18316
- var side = Math.round(Math.sqrt(weights.length));
18317
- var halfSide = Math.floor(side / 2);
18318
- var maskResult = [];
18319
- for (var y = 0; y < sh; y++) {
18320
- for (var x = 0; x < sw; x++) {
18321
- var so = y * sw + x;
18322
- var a = 0;
18323
- for (var cy = 0; cy < side; cy++) {
18324
- for (var cx = 0; cx < side; cx++) {
18325
- var scy = y + cy - halfSide;
18326
- var scx = x + cx - halfSide;
18335
+ const weights = [1, 1, 1, 1, 0, 1, 1, 1, 1];
18336
+ const side = Math.round(Math.sqrt(weights.length));
18337
+ const halfSide = Math.floor(side / 2);
18338
+ const maskResult = [];
18339
+ for (let y = 0; y < sh; y++) {
18340
+ for (let x = 0; x < sw; x++) {
18341
+ const so = y * sw + x;
18342
+ let a = 0;
18343
+ for (let cy = 0; cy < side; cy++) {
18344
+ for (let cx = 0; cx < side; cx++) {
18345
+ const scy = y + cy - halfSide;
18346
+ const scx = x + cx - halfSide;
18327
18347
  if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
18328
- var srcOff = scy * sw + scx;
18329
- var wt = weights[cy * side + cx];
18348
+ const srcOff = scy * sw + scx;
18349
+ const wt = weights[cy * side + cx];
18330
18350
  a += mask[srcOff] * wt;
18331
18351
  }
18332
18352
  }
@@ -18337,21 +18357,21 @@
18337
18357
  return maskResult;
18338
18358
  }
18339
18359
  function dilateMask(mask, sw, sh) {
18340
- var weights = [1, 1, 1, 1, 1, 1, 1, 1, 1];
18341
- var side = Math.round(Math.sqrt(weights.length));
18342
- var halfSide = Math.floor(side / 2);
18343
- var maskResult = [];
18344
- for (var y = 0; y < sh; y++) {
18345
- for (var x = 0; x < sw; x++) {
18346
- var so = y * sw + x;
18347
- var a = 0;
18348
- for (var cy = 0; cy < side; cy++) {
18349
- for (var cx = 0; cx < side; cx++) {
18350
- var scy = y + cy - halfSide;
18351
- var scx = x + cx - halfSide;
18360
+ const weights = [1, 1, 1, 1, 1, 1, 1, 1, 1];
18361
+ const side = Math.round(Math.sqrt(weights.length));
18362
+ const halfSide = Math.floor(side / 2);
18363
+ const maskResult = [];
18364
+ for (let y = 0; y < sh; y++) {
18365
+ for (let x = 0; x < sw; x++) {
18366
+ const so = y * sw + x;
18367
+ let a = 0;
18368
+ for (let cy = 0; cy < side; cy++) {
18369
+ for (let cx = 0; cx < side; cx++) {
18370
+ const scy = y + cy - halfSide;
18371
+ const scx = x + cx - halfSide;
18352
18372
  if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
18353
- var srcOff = scy * sw + scx;
18354
- var wt = weights[cy * side + cx];
18373
+ const srcOff = scy * sw + scx;
18374
+ const wt = weights[cy * side + cx];
18355
18375
  a += mask[srcOff] * wt;
18356
18376
  }
18357
18377
  }
@@ -18362,21 +18382,21 @@
18362
18382
  return maskResult;
18363
18383
  }
18364
18384
  function smoothEdgeMask(mask, sw, sh) {
18365
- var weights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9];
18366
- var side = Math.round(Math.sqrt(weights.length));
18367
- var halfSide = Math.floor(side / 2);
18368
- var maskResult = [];
18369
- for (var y = 0; y < sh; y++) {
18370
- for (var x = 0; x < sw; x++) {
18371
- var so = y * sw + x;
18372
- var a = 0;
18373
- for (var cy = 0; cy < side; cy++) {
18374
- for (var cx = 0; cx < side; cx++) {
18375
- var scy = y + cy - halfSide;
18376
- var scx = x + cx - halfSide;
18385
+ const weights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9];
18386
+ const side = Math.round(Math.sqrt(weights.length));
18387
+ const halfSide = Math.floor(side / 2);
18388
+ const maskResult = [];
18389
+ for (let y = 0; y < sh; y++) {
18390
+ for (let x = 0; x < sw; x++) {
18391
+ const so = y * sw + x;
18392
+ let a = 0;
18393
+ for (let cy = 0; cy < side; cy++) {
18394
+ for (let cx = 0; cx < side; cx++) {
18395
+ const scy = y + cy - halfSide;
18396
+ const scx = x + cx - halfSide;
18377
18397
  if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
18378
- var srcOff = scy * sw + scx;
18379
- var wt = weights[cy * side + cx];
18398
+ const srcOff = scy * sw + scx;
18399
+ const wt = weights[cy * side + cx];
18380
18400
  a += mask[srcOff] * wt;
18381
18401
  }
18382
18402
  }
@@ -18399,7 +18419,8 @@
18399
18419
  */
18400
18420
  const Mask = function (imageData) {
18401
18421
  // Detect pixels close to the background color
18402
- var threshold = this.threshold(), mask = backgroundMask(imageData, threshold);
18422
+ const threshold = this.threshold();
18423
+ let mask = backgroundMask(imageData, threshold);
18403
18424
  if (mask) {
18404
18425
  // Erode
18405
18426
  mask = erodeMask(mask, imageData.width, imageData.height);
@@ -18427,8 +18448,8 @@
18427
18448
  * node.noise(0.8);
18428
18449
  */
18429
18450
  const Noise = function (imageData) {
18430
- var amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2, i;
18431
- for (i = 0; i < nPixels; i += 4) {
18451
+ const amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2;
18452
+ for (let i = 0; i < nPixels; i += 4) {
18432
18453
  data[i + 0] += half - 2 * half * Math.random();
18433
18454
  data[i + 1] += half - 2 * half * Math.random();
18434
18455
  data[i + 2] += half - 2 * half * Math.random();
@@ -18443,7 +18464,6 @@
18443
18464
  * @returns {Number}
18444
18465
  */
18445
18466
 
18446
- /*eslint-disable max-depth */
18447
18467
  /**
18448
18468
  * Pixelate Filter. Averages groups of pixels and redraws
18449
18469
  * them as larger pixels
@@ -18458,7 +18478,7 @@
18458
18478
  * node.pixelSize(10);
18459
18479
  */
18460
18480
  const Pixelate = function (imageData) {
18461
- var pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i,
18481
+ let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i,
18462
18482
  //pixelsPerBin = pixelSize * pixelSize,
18463
18483
  red, green, blue, alpha, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), xBinStart, xBinEnd, yBinStart, yBinEnd, xBin, yBin, pixelsInBin, data = imageData.data;
18464
18484
  if (pixelSize <= 0) {
@@ -18544,8 +18564,8 @@
18544
18564
  */
18545
18565
  const Posterize = function (imageData) {
18546
18566
  // level must be between 1 and 255
18547
- var levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i;
18548
- for (i = 0; i < len; i += 1) {
18567
+ const levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels;
18568
+ for (let i = 0; i < len; i += 1) {
18549
18569
  data[i] = Math.floor(data[i] / scale) * scale;
18550
18570
  }
18551
18571
  };
@@ -18572,10 +18592,9 @@
18572
18592
  * node.green(200);
18573
18593
  */
18574
18594
  const RGB = function (imageData) {
18575
- var data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness;
18576
- for (i = 0; i < nPixels; i += 4) {
18577
- brightness =
18578
- (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
18595
+ const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue();
18596
+ for (let i = 0; i < nPixels; i += 4) {
18597
+ const brightness = (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
18579
18598
  data[i] = brightness * red; // r
18580
18599
  data[i + 1] = brightness * green; // g
18581
18600
  data[i + 2] = brightness * blue; // b
@@ -18647,9 +18666,9 @@
18647
18666
  * node.alpha(0.3);
18648
18667
  */
18649
18668
  const RGBA = function (imageData) {
18650
- var data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha(), i, ia;
18651
- for (i = 0; i < nPixels; i += 4) {
18652
- ia = 1 - alpha;
18669
+ const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha();
18670
+ for (let i = 0; i < nPixels; i += 4) {
18671
+ const ia = 1 - alpha;
18653
18672
  data[i] = red * alpha + data[i] * ia; // r
18654
18673
  data[i + 1] = green * alpha + data[i + 1] * ia; // g
18655
18674
  data[i + 2] = blue * alpha + data[i + 2] * ia; // b
@@ -18736,11 +18755,11 @@
18736
18755
  * node.filters([Konva.Filters.Sepia]);
18737
18756
  */
18738
18757
  const Sepia = function (imageData) {
18739
- var data = imageData.data, nPixels = data.length, i, r, g, b;
18740
- for (i = 0; i < nPixels; i += 4) {
18741
- r = data[i + 0];
18742
- g = data[i + 1];
18743
- b = data[i + 2];
18758
+ const data = imageData.data, nPixels = data.length;
18759
+ for (let i = 0; i < nPixels; i += 4) {
18760
+ const r = data[i + 0];
18761
+ const g = data[i + 1];
18762
+ const b = data[i + 2];
18744
18763
  data[i + 0] = Math.min(255, r * 0.393 + g * 0.769 + b * 0.189);
18745
18764
  data[i + 1] = Math.min(255, r * 0.349 + g * 0.686 + b * 0.168);
18746
18765
  data[i + 2] = Math.min(255, r * 0.272 + g * 0.534 + b * 0.131);
@@ -18761,15 +18780,16 @@
18761
18780
  * node.filters([Konva.Filters.Solarize]);
18762
18781
  */
18763
18782
  const Solarize = function (imageData) {
18764
- var data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4, y = h;
18783
+ const data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4;
18784
+ let y = h;
18765
18785
  do {
18766
- var offsetY = (y - 1) * w4;
18767
- var x = w;
18786
+ const offsetY = (y - 1) * w4;
18787
+ let x = w;
18768
18788
  do {
18769
- var offset = offsetY + (x - 1) * 4;
18770
- var r = data[offset];
18771
- var g = data[offset + 1];
18772
- var b = data[offset + 2];
18789
+ const offset = offsetY + (x - 1) * 4;
18790
+ let r = data[offset];
18791
+ let g = data[offset + 1];
18792
+ let b = data[offset + 2];
18773
18793
  if (r > 127) {
18774
18794
  r = 255 - r;
18775
18795
  }
@@ -18801,8 +18821,8 @@
18801
18821
  * node.threshold(0.1);
18802
18822
  */
18803
18823
  const Threshold = function (imageData) {
18804
- var level = this.threshold() * 255, data = imageData.data, len = data.length, i;
18805
- for (i = 0; i < len; i += 1) {
18824
+ const level = this.threshold() * 255, data = imageData.data, len = data.length;
18825
+ for (let i = 0; i < len; i += 1) {
18806
18826
  data[i] = data[i] < level ? 0 : 255;
18807
18827
  }
18808
18828
  };