konva 8.4.2 → 9.0.0

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 (242) hide show
  1. package/README.md +1 -9
  2. package/konva.js +17669 -16968
  3. package/konva.min.js +3 -3
  4. package/lib/Animation.d.ts +2 -2
  5. package/lib/Animation.js +11 -7
  6. package/lib/BezierFunctions.d.ts +6 -0
  7. package/lib/BezierFunctions.js +791 -0
  8. package/lib/Canvas.d.ts +2 -1
  9. package/lib/Canvas.js +26 -18
  10. package/lib/Container.d.ts +4 -4
  11. package/lib/Container.js +16 -12
  12. package/lib/Context.d.ts +16 -13
  13. package/lib/Context.js +27 -19
  14. package/lib/Core.d.ts +2 -2
  15. package/lib/Core.js +7 -3
  16. package/lib/DragAndDrop.d.ts +3 -3
  17. package/lib/DragAndDrop.js +25 -22
  18. package/lib/Factory.js +27 -24
  19. package/lib/FastLayer.d.ts +1 -1
  20. package/lib/FastLayer.js +10 -6
  21. package/lib/Global.js +16 -12
  22. package/lib/Group.d.ts +3 -3
  23. package/lib/Group.js +10 -6
  24. package/lib/Layer.d.ts +9 -9
  25. package/lib/Layer.js +37 -33
  26. package/lib/Node.d.ts +8 -8
  27. package/lib/Node.js +95 -90
  28. package/lib/PointerEvents.d.ts +4 -4
  29. package/lib/PointerEvents.js +15 -7
  30. package/lib/Shape.d.ts +6 -4
  31. package/lib/Shape.js +90 -86
  32. package/lib/Stage.d.ts +7 -7
  33. package/lib/Stage.js +51 -47
  34. package/lib/Tween.d.ts +2 -2
  35. package/lib/Tween.js +26 -22
  36. package/lib/Util.d.ts +2 -2
  37. package/lib/Util.js +29 -25
  38. package/lib/Validators.js +58 -44
  39. package/lib/_CoreInternals.d.ts +29 -29
  40. package/lib/_CoreInternals.js +36 -33
  41. package/lib/_FullInternals.d.ts +67 -67
  42. package/lib/_FullInternals.js +78 -75
  43. package/lib/filters/Blur.d.ts +1 -1
  44. package/lib/filters/Blur.js +9 -5
  45. package/lib/filters/Brighten.d.ts +1 -1
  46. package/lib/filters/Brighten.js +9 -5
  47. package/lib/filters/Contrast.d.ts +1 -1
  48. package/lib/filters/Contrast.js +9 -5
  49. package/lib/filters/Emboss.d.ts +1 -1
  50. package/lib/filters/Emboss.js +14 -10
  51. package/lib/filters/Enhance.d.ts +1 -1
  52. package/lib/filters/Enhance.js +9 -5
  53. package/lib/filters/Grayscale.d.ts +1 -1
  54. package/lib/filters/Grayscale.js +5 -1
  55. package/lib/filters/HSL.d.ts +1 -1
  56. package/lib/filters/HSL.js +11 -7
  57. package/lib/filters/HSV.d.ts +1 -1
  58. package/lib/filters/HSV.js +11 -7
  59. package/lib/filters/Invert.d.ts +1 -1
  60. package/lib/filters/Invert.js +5 -1
  61. package/lib/filters/Kaleidoscope.d.ts +1 -1
  62. package/lib/filters/Kaleidoscope.js +13 -9
  63. package/lib/filters/Mask.d.ts +1 -1
  64. package/lib/filters/Mask.js +9 -5
  65. package/lib/filters/Noise.d.ts +1 -1
  66. package/lib/filters/Noise.js +9 -5
  67. package/lib/filters/Pixelate.d.ts +1 -1
  68. package/lib/filters/Pixelate.js +11 -7
  69. package/lib/filters/Posterize.d.ts +1 -1
  70. package/lib/filters/Posterize.js +9 -5
  71. package/lib/filters/RGB.d.ts +1 -1
  72. package/lib/filters/RGB.js +11 -7
  73. package/lib/filters/RGBA.d.ts +1 -1
  74. package/lib/filters/RGBA.js +12 -8
  75. package/lib/filters/Sepia.d.ts +1 -1
  76. package/lib/filters/Sepia.js +5 -1
  77. package/lib/filters/Solarize.d.ts +1 -1
  78. package/lib/filters/Solarize.js +5 -1
  79. package/lib/filters/Threshold.d.ts +1 -1
  80. package/lib/filters/Threshold.js +9 -5
  81. package/lib/index-node.d.ts +1 -1
  82. package/lib/index-node.js +7 -5
  83. package/lib/index-types.d.ts +124 -124
  84. package/lib/index.d.ts +1 -1
  85. package/lib/index.js +4 -2
  86. package/lib/shapes/Arc.d.ts +6 -5
  87. package/lib/shapes/Arc.js +17 -13
  88. package/lib/shapes/Arrow.d.ts +5 -4
  89. package/lib/shapes/Arrow.js +17 -13
  90. package/lib/shapes/Circle.d.ts +6 -5
  91. package/lib/shapes/Circle.js +11 -7
  92. package/lib/shapes/Ellipse.d.ts +6 -5
  93. package/lib/shapes/Ellipse.js +13 -9
  94. package/lib/shapes/Image.d.ts +5 -5
  95. package/lib/shapes/Image.js +21 -17
  96. package/lib/shapes/Label.d.ts +8 -7
  97. package/lib/shapes/Label.js +18 -13
  98. package/lib/shapes/Line.d.ts +3 -3
  99. package/lib/shapes/Line.js +14 -10
  100. package/lib/shapes/Path.d.ts +6 -3
  101. package/lib/shapes/Path.js +44 -43
  102. package/lib/shapes/Rect.d.ts +3 -3
  103. package/lib/shapes/Rect.js +13 -9
  104. package/lib/shapes/RegularPolygon.d.ts +6 -5
  105. package/lib/shapes/RegularPolygon.js +12 -8
  106. package/lib/shapes/Ring.d.ts +6 -5
  107. package/lib/shapes/Ring.js +12 -8
  108. package/lib/shapes/Sprite.d.ts +7 -6
  109. package/lib/shapes/Sprite.js +19 -15
  110. package/lib/shapes/Star.d.ts +6 -5
  111. package/lib/shapes/Star.js +13 -9
  112. package/lib/shapes/Text.d.ts +8 -7
  113. package/lib/shapes/Text.js +31 -26
  114. package/lib/shapes/TextPath.d.ts +12 -7
  115. package/lib/shapes/TextPath.js +82 -188
  116. package/lib/shapes/Transformer.d.ts +10 -10
  117. package/lib/shapes/Transformer.js +92 -81
  118. package/lib/shapes/Wedge.d.ts +6 -5
  119. package/lib/shapes/Wedge.js +16 -12
  120. package/lib/types.d.ts +6 -0
  121. package/lib/types.js +5 -2
  122. package/package.json +13 -42
  123. package/cmj/Animation.d.ts +0 -24
  124. package/cmj/Animation.js +0 -145
  125. package/cmj/Canvas.d.ts +0 -32
  126. package/cmj/Canvas.js +0 -114
  127. package/cmj/Container.d.ts +0 -47
  128. package/cmj/Container.js +0 -325
  129. package/cmj/Context.d.ts +0 -84
  130. package/cmj/Context.js +0 -538
  131. package/cmj/Core.d.ts +0 -3
  132. package/cmj/Core.js +0 -7
  133. package/cmj/DragAndDrop.d.ts +0 -17
  134. package/cmj/DragAndDrop.js +0 -111
  135. package/cmj/Factory.d.ts +0 -11
  136. package/cmj/Factory.js +0 -125
  137. package/cmj/FastLayer.d.ts +0 -4
  138. package/cmj/FastLayer.js +0 -16
  139. package/cmj/Global.d.ts +0 -34
  140. package/cmj/Global.js +0 -61
  141. package/cmj/Group.d.ts +0 -8
  142. package/cmj/Group.js +0 -17
  143. package/cmj/Layer.d.ts +0 -61
  144. package/cmj/Layer.js +0 -309
  145. package/cmj/Node.d.ts +0 -328
  146. package/cmj/Node.js +0 -1420
  147. package/cmj/PointerEvents.d.ts +0 -11
  148. package/cmj/PointerEvents.js +0 -45
  149. package/cmj/Shape.d.ts +0 -184
  150. package/cmj/Shape.js +0 -521
  151. package/cmj/Stage.d.ts +0 -85
  152. package/cmj/Stage.js +0 -692
  153. package/cmj/Tween.d.ts +0 -86
  154. package/cmj/Tween.js +0 -520
  155. package/cmj/Util.d.ts +0 -91
  156. package/cmj/Util.js +0 -801
  157. package/cmj/Validators.d.ts +0 -11
  158. package/cmj/Validators.js +0 -192
  159. package/cmj/_CoreInternals.d.ts +0 -152
  160. package/cmj/_CoreInternals.js +0 -37
  161. package/cmj/_FullInternals.d.ts +0 -196
  162. package/cmj/_FullInternals.js +0 -81
  163. package/cmj/filters/Blur.d.ts +0 -2
  164. package/cmj/filters/Blur.js +0 -701
  165. package/cmj/filters/Brighten.d.ts +0 -2
  166. package/cmj/filters/Brighten.js +0 -16
  167. package/cmj/filters/Contrast.d.ts +0 -2
  168. package/cmj/filters/Contrast.js +0 -38
  169. package/cmj/filters/Emboss.d.ts +0 -2
  170. package/cmj/filters/Emboss.js +0 -106
  171. package/cmj/filters/Enhance.d.ts +0 -2
  172. package/cmj/filters/Enhance.js +0 -87
  173. package/cmj/filters/Grayscale.d.ts +0 -2
  174. package/cmj/filters/Grayscale.js +0 -13
  175. package/cmj/filters/HSL.d.ts +0 -2
  176. package/cmj/filters/HSL.js +0 -28
  177. package/cmj/filters/HSV.d.ts +0 -2
  178. package/cmj/filters/HSV.js +0 -28
  179. package/cmj/filters/Invert.d.ts +0 -2
  180. package/cmj/filters/Invert.js +0 -12
  181. package/cmj/filters/Kaleidoscope.d.ts +0 -2
  182. package/cmj/filters/Kaleidoscope.js +0 -137
  183. package/cmj/filters/Mask.d.ts +0 -2
  184. package/cmj/filters/Mask.js +0 -144
  185. package/cmj/filters/Noise.d.ts +0 -2
  186. package/cmj/filters/Noise.js +0 -16
  187. package/cmj/filters/Pixelate.d.ts +0 -2
  188. package/cmj/filters/Pixelate.js +0 -64
  189. package/cmj/filters/Posterize.d.ts +0 -2
  190. package/cmj/filters/Posterize.js +0 -14
  191. package/cmj/filters/RGB.d.ts +0 -2
  192. package/cmj/filters/RGB.js +0 -43
  193. package/cmj/filters/RGBA.d.ts +0 -2
  194. package/cmj/filters/RGBA.js +0 -53
  195. package/cmj/filters/Sepia.d.ts +0 -2
  196. package/cmj/filters/Sepia.js +0 -15
  197. package/cmj/filters/Solarize.d.ts +0 -2
  198. package/cmj/filters/Solarize.js +0 -29
  199. package/cmj/filters/Threshold.d.ts +0 -2
  200. package/cmj/filters/Threshold.js +0 -14
  201. package/cmj/index-node.d.ts +0 -2
  202. package/cmj/index-node.js +0 -21
  203. package/cmj/index-types.d.ts +0 -181
  204. package/cmj/index.d.ts +0 -2
  205. package/cmj/index.js +0 -4
  206. package/cmj/package.json +0 -6
  207. package/cmj/shapes/Arc.d.ts +0 -25
  208. package/cmj/shapes/Arc.js +0 -59
  209. package/cmj/shapes/Arrow.d.ts +0 -25
  210. package/cmj/shapes/Arrow.js +0 -103
  211. package/cmj/shapes/Circle.d.ts +0 -13
  212. package/cmj/shapes/Circle.js +0 -37
  213. package/cmj/shapes/Ellipse.d.ts +0 -16
  214. package/cmj/shapes/Ellipse.js +0 -41
  215. package/cmj/shapes/Image.d.ts +0 -25
  216. package/cmj/shapes/Image.js +0 -117
  217. package/cmj/shapes/Label.d.ts +0 -35
  218. package/cmj/shapes/Label.js +0 -178
  219. package/cmj/shapes/Line.d.ts +0 -28
  220. package/cmj/shapes/Line.js +0 -159
  221. package/cmj/shapes/Path.d.ts +0 -37
  222. package/cmj/shapes/Path.js +0 -631
  223. package/cmj/shapes/Rect.d.ts +0 -10
  224. package/cmj/shapes/Rect.js +0 -26
  225. package/cmj/shapes/RegularPolygon.d.ts +0 -22
  226. package/cmj/shapes/RegularPolygon.js +0 -69
  227. package/cmj/shapes/Ring.d.ts +0 -15
  228. package/cmj/shapes/Ring.js +0 -37
  229. package/cmj/shapes/Sprite.d.ts +0 -30
  230. package/cmj/shapes/Sprite.js +0 -112
  231. package/cmj/shapes/Star.d.ts +0 -17
  232. package/cmj/shapes/Star.js +0 -42
  233. package/cmj/shapes/Text.d.ts +0 -62
  234. package/cmj/shapes/Text.js +0 -373
  235. package/cmj/shapes/TextPath.d.ts +0 -55
  236. package/cmj/shapes/TextPath.js +0 -351
  237. package/cmj/shapes/Transformer.d.ts +0 -116
  238. package/cmj/shapes/Transformer.js +0 -964
  239. package/cmj/shapes/Wedge.d.ts +0 -17
  240. package/cmj/shapes/Wedge.js +0 -42
  241. package/cmj/types.d.ts +0 -50
  242. package/cmj/types.js +0 -25
package/lib/Node.js CHANGED
@@ -1,9 +1,12 @@
1
- import { Util, Transform } from './Util.js';
2
- import { Factory } from './Factory.js';
3
- import { SceneCanvas, HitCanvas } from './Canvas.js';
4
- import { Konva } from './Global.js';
5
- import { DD } from './DragAndDrop.js';
6
- import { getNumberValidator, getStringValidator, getBooleanValidator, } from './Validators.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Node = void 0;
4
+ const Util_1 = require("./Util");
5
+ const Factory_1 = require("./Factory");
6
+ const Canvas_1 = require("./Canvas");
7
+ const Global_1 = require("./Global");
8
+ const DragAndDrop_1 = require("./DragAndDrop");
9
+ const Validators_1 = require("./Validators");
7
10
  var ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', NAME = 'name', SET = 'set', SHAPE = 'Shape', SPACE = ' ', STAGE = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR = [
8
11
  'xChange.konva',
9
12
  'yChange.konva',
@@ -17,7 +20,7 @@ var ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', A
17
20
  'transformsEnabledChange.konva',
18
21
  ].join(SPACE);
19
22
  let idCounter = 1;
20
- export class Node {
23
+ class Node {
21
24
  constructor(config) {
22
25
  this._id = idCounter++;
23
26
  this.eventListeners = {};
@@ -84,7 +87,7 @@ export class Node {
84
87
  clearCache() {
85
88
  if (this._cache.has(CANVAS)) {
86
89
  const { scene, filter, hit } = this._cache.get(CANVAS);
87
- Util.releaseCanvas(scene, filter, hit);
90
+ Util_1.Util.releaseCanvas(scene, filter, hit);
88
91
  this._cache.delete(CANVAS);
89
92
  }
90
93
  this._clearSelfAndDescendantCache();
@@ -105,22 +108,23 @@ export class Node {
105
108
  }
106
109
  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;
107
110
  if (!width || !height) {
108
- Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
111
+ Util_1.Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
109
112
  return;
110
113
  }
111
114
  width += offset * 2 + 1;
112
115
  height += offset * 2 + 1;
113
116
  x -= offset;
114
117
  y -= offset;
115
- var cachedSceneCanvas = new SceneCanvas({
118
+ var cachedSceneCanvas = new Canvas_1.SceneCanvas({
116
119
  pixelRatio: pixelRatio,
117
120
  width: width,
118
121
  height: height,
119
- }), cachedFilterCanvas = new SceneCanvas({
122
+ }), cachedFilterCanvas = new Canvas_1.SceneCanvas({
120
123
  pixelRatio: pixelRatio,
121
124
  width: 0,
122
125
  height: 0,
123
- }), cachedHitCanvas = new HitCanvas({
126
+ willReadFrequently: true,
127
+ }), cachedHitCanvas = new Canvas_1.HitCanvas({
124
128
  pixelRatio: hitCanvasPixelRatio,
125
129
  width: width,
126
130
  height: height,
@@ -230,7 +234,7 @@ export class Node {
230
234
  for (n = 0; n < len; n++) {
231
235
  filter = filters[n];
232
236
  if (typeof filter !== 'function') {
233
- Util.error('Filter should be type of function, but got ' +
237
+ Util_1.Util.error('Filter should be type of function, but got ' +
234
238
  typeof filter +
235
239
  ' instead. Please check correct filters');
236
240
  continue;
@@ -240,7 +244,7 @@ export class Node {
240
244
  }
241
245
  }
242
246
  catch (e) {
243
- Util.error('Unable to apply filter. ' +
247
+ Util_1.Util.error('Unable to apply filter. ' +
244
248
  e.message +
245
249
  ' This post my help you https://konvajs.org/docs/posts/Tainted_Canvas.html.');
246
250
  }
@@ -321,7 +325,7 @@ export class Node {
321
325
  this.on(event, function (evt) {
322
326
  var targets = evt.target.findAncestors(selector, true, stopNode);
323
327
  for (var i = 0; i < targets.length; i++) {
324
- evt = Util.cloneObject(evt);
328
+ evt = Util_1.Util.cloneObject(evt);
325
329
  evt.currentTarget = targets[i];
326
330
  handler.call(targets[i], evt);
327
331
  }
@@ -331,7 +335,7 @@ export class Node {
331
335
  if (this.isDragging()) {
332
336
  this.stopDrag();
333
337
  }
334
- DD._dragElements.delete(this._id);
338
+ DragAndDrop_1.DD._dragElements.delete(this._id);
335
339
  this._remove();
336
340
  return this;
337
341
  }
@@ -358,8 +362,8 @@ export class Node {
358
362
  return this;
359
363
  }
360
364
  getAttr(attr) {
361
- var method = 'get' + Util._capitalize(attr);
362
- if (Util._isFunction(this[method])) {
365
+ var method = 'get' + Util_1.Util._capitalize(attr);
366
+ if (Util_1.Util._isFunction(this[method])) {
363
367
  return this[method]();
364
368
  }
365
369
  return this.attrs[attr];
@@ -385,8 +389,8 @@ export class Node {
385
389
  if (key === CHILDREN) {
386
390
  continue;
387
391
  }
388
- method = SET + Util._capitalize(key);
389
- if (Util._isFunction(this[method])) {
392
+ method = SET + Util_1.Util._capitalize(key);
393
+ if (Util_1.Util._isFunction(this[method])) {
390
394
  this[method](config[key]);
391
395
  }
392
396
  else {
@@ -434,7 +438,7 @@ export class Node {
434
438
  }
435
439
  var layer = this.getLayer();
436
440
  var layerUnderDrag = false;
437
- DD._dragElements.forEach((elem) => {
441
+ DragAndDrop_1.DD._dragElements.forEach((elem) => {
438
442
  if (elem.dragStatus !== 'dragging') {
439
443
  return;
440
444
  }
@@ -445,7 +449,7 @@ export class Node {
445
449
  layerUnderDrag = true;
446
450
  }
447
451
  });
448
- var dragSkip = !skipDragCheck && !Konva.hitOnDragEnabled && layerUnderDrag;
452
+ var dragSkip = !skipDragCheck && !Global_1.Konva.hitOnDragEnabled && layerUnderDrag;
449
453
  return this.isListening() && this.isVisible() && !dragSkip;
450
454
  }
451
455
  show() {
@@ -539,7 +543,7 @@ export class Node {
539
543
  if (haveCachedParent && !top) {
540
544
  top = true;
541
545
  }
542
- var absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Transform(), offset = this.offset();
546
+ var absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Util_1.Transform(), offset = this.offset();
543
547
  absoluteTransform.m = absoluteMatrix.slice();
544
548
  absoluteTransform.translate(offset.x, offset.y);
545
549
  return absoluteTransform.getTranslation();
@@ -625,7 +629,7 @@ export class Node {
625
629
  }
626
630
  moveToTop() {
627
631
  if (!this.parent) {
628
- Util.warn('Node has no parent. moveToTop function is ignored.');
632
+ Util_1.Util.warn('Node has no parent. moveToTop function is ignored.');
629
633
  return false;
630
634
  }
631
635
  var index = this.index, len = this.parent.getChildren().length;
@@ -639,7 +643,7 @@ export class Node {
639
643
  }
640
644
  moveUp() {
641
645
  if (!this.parent) {
642
- Util.warn('Node has no parent. moveUp function is ignored.');
646
+ Util_1.Util.warn('Node has no parent. moveUp function is ignored.');
643
647
  return false;
644
648
  }
645
649
  var index = this.index, len = this.parent.getChildren().length;
@@ -653,7 +657,7 @@ export class Node {
653
657
  }
654
658
  moveDown() {
655
659
  if (!this.parent) {
656
- Util.warn('Node has no parent. moveDown function is ignored.');
660
+ Util_1.Util.warn('Node has no parent. moveDown function is ignored.');
657
661
  return false;
658
662
  }
659
663
  var index = this.index;
@@ -667,7 +671,7 @@ export class Node {
667
671
  }
668
672
  moveToBottom() {
669
673
  if (!this.parent) {
670
- Util.warn('Node has no parent. moveToBottom function is ignored.');
674
+ Util_1.Util.warn('Node has no parent. moveToBottom function is ignored.');
671
675
  return false;
672
676
  }
673
677
  var index = this.index;
@@ -681,11 +685,11 @@ export class Node {
681
685
  }
682
686
  setZIndex(zIndex) {
683
687
  if (!this.parent) {
684
- Util.warn('Node has no parent. zIndex parameter is ignored.');
688
+ Util_1.Util.warn('Node has no parent. zIndex parameter is ignored.');
685
689
  return this;
686
690
  }
687
691
  if (zIndex < 0 || zIndex >= this.parent.children.length) {
688
- Util.warn('Unexpected value ' +
692
+ Util_1.Util.warn('Unexpected value ' +
689
693
  zIndex +
690
694
  ' for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to ' +
691
695
  (this.parent.children.length - 1) +
@@ -721,7 +725,7 @@ export class Node {
721
725
  for (key in attrs) {
722
726
  val = attrs[key];
723
727
  nonPlainObject =
724
- Util.isObject(val) && !Util._isPlainObject(val) && !Util._isArray(val);
728
+ Util_1.Util.isObject(val) && !Util_1.Util._isPlainObject(val) && !Util_1.Util._isArray(val);
725
729
  if (nonPlainObject) {
726
730
  continue;
727
731
  }
@@ -734,7 +738,7 @@ export class Node {
734
738
  }
735
739
  }
736
740
  obj.className = this.getClassName();
737
- return Util._prepareToStringify(obj);
741
+ return Util_1.Util._prepareToStringify(obj);
738
742
  }
739
743
  toJSON() {
740
744
  return JSON.stringify(this.toObject());
@@ -775,12 +779,12 @@ export class Node {
775
779
  var selectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel;
776
780
  for (n = 0; n < len; n++) {
777
781
  sel = selectorArr[n];
778
- if (!Util.isValidSelector(sel)) {
779
- Util.warn('Selector "' +
782
+ if (!Util_1.Util.isValidSelector(sel)) {
783
+ Util_1.Util.warn('Selector "' +
780
784
  sel +
781
785
  '" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".');
782
- Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".');
783
- Util.warn('Konva is awesome, right?');
786
+ Util_1.Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".');
787
+ Util_1.Util.warn('Konva is awesome, right?');
784
788
  }
785
789
  if (sel.charAt(0) === '#') {
786
790
  if (this.id() === sel.slice(1)) {
@@ -835,7 +839,7 @@ export class Node {
835
839
  _getAbsoluteTransform(top) {
836
840
  var at;
837
841
  if (top) {
838
- at = new Transform();
842
+ at = new Util_1.Transform();
839
843
  this._eachAncestorReverse(function (node) {
840
844
  var transformsEnabled = node.transformsEnabled();
841
845
  if (transformsEnabled === 'all') {
@@ -848,7 +852,7 @@ export class Node {
848
852
  return at;
849
853
  }
850
854
  else {
851
- at = this._cache.get(ABSOLUTE_TRANSFORM) || new Transform();
855
+ at = this._cache.get(ABSOLUTE_TRANSFORM) || new Util_1.Transform();
852
856
  if (this.parent) {
853
857
  this.parent.getAbsoluteTransform().copyInto(at);
854
858
  }
@@ -893,9 +897,9 @@ export class Node {
893
897
  }
894
898
  _getTransform() {
895
899
  var _a, _b;
896
- var m = this._cache.get(TRANSFORM) || new Transform();
900
+ var m = this._cache.get(TRANSFORM) || new Util_1.Transform();
897
901
  m.reset();
898
- var x = this.x(), y = this.y(), rotation = Konva.getAngle(this.rotation()), scaleX = (_a = this.attrs.scaleX) !== null && _a !== void 0 ? _a : 1, scaleY = (_b = this.attrs.scaleY) !== null && _b !== void 0 ? _b : 1, skewX = this.attrs.skewX || 0, skewY = this.attrs.skewY || 0, offsetX = this.attrs.offsetX || 0, offsetY = this.attrs.offsetY || 0;
902
+ var x = this.x(), y = this.y(), rotation = Global_1.Konva.getAngle(this.rotation()), scaleX = (_a = this.attrs.scaleX) !== null && _a !== void 0 ? _a : 1, scaleY = (_b = this.attrs.scaleY) !== null && _b !== void 0 ? _b : 1, skewX = this.attrs.skewX || 0, skewY = this.attrs.skewY || 0, offsetX = this.attrs.offsetX || 0, offsetY = this.attrs.offsetY || 0;
899
903
  if (x !== 0 || y !== 0) {
900
904
  m.translate(x, y);
901
905
  }
@@ -915,7 +919,7 @@ export class Node {
915
919
  return m;
916
920
  }
917
921
  clone(obj) {
918
- var attrs = Util.cloneObject(this.attrs), key, allListeners, len, n, listener;
922
+ var attrs = Util_1.Util.cloneObject(this.attrs), key, allListeners, len, n, listener;
919
923
  for (key in obj) {
920
924
  attrs[key] = obj[key];
921
925
  }
@@ -938,7 +942,7 @@ export class Node {
938
942
  _toKonvaCanvas(config) {
939
943
  config = config || {};
940
944
  var box = this.getClientRect();
941
- 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({
945
+ 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 Canvas_1.SceneCanvas({
942
946
  width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0),
943
947
  height: config.height ||
944
948
  Math.ceil(box.height) ||
@@ -974,7 +978,7 @@ export class Node {
974
978
  const callback = config === null || config === void 0 ? void 0 : config.callback;
975
979
  if (callback)
976
980
  delete config.callback;
977
- Util._urlToImage(this.toDataURL(config), function (img) {
981
+ Util_1.Util._urlToImage(this.toDataURL(config), function (img) {
978
982
  resolve(img);
979
983
  callback === null || callback === void 0 ? void 0 : callback(img);
980
984
  });
@@ -1025,7 +1029,7 @@ export class Node {
1025
1029
  return this.parent.getDragDistance();
1026
1030
  }
1027
1031
  else {
1028
- return Konva.dragDistance;
1032
+ return Global_1.Konva.dragDistance;
1029
1033
  }
1030
1034
  }
1031
1035
  _off(type, name, callback) {
@@ -1080,8 +1084,8 @@ export class Node {
1080
1084
  return this;
1081
1085
  }
1082
1086
  setAttr(attr, val) {
1083
- var func = this[SET + Util._capitalize(attr)];
1084
- if (Util._isFunction(func)) {
1087
+ var func = this[SET + Util_1.Util._capitalize(attr)];
1088
+ if (Util_1.Util._isFunction(func)) {
1085
1089
  func.call(this, val);
1086
1090
  }
1087
1091
  else {
@@ -1090,14 +1094,14 @@ export class Node {
1090
1094
  return this;
1091
1095
  }
1092
1096
  _requestDraw() {
1093
- if (Konva.autoDrawEnabled) {
1097
+ if (Global_1.Konva.autoDrawEnabled) {
1094
1098
  const drawNode = this.getLayer() || this.getStage();
1095
1099
  drawNode === null || drawNode === void 0 ? void 0 : drawNode.batchDraw();
1096
1100
  }
1097
1101
  }
1098
1102
  _setAttr(key, val) {
1099
1103
  var oldVal = this.attrs[key];
1100
- if (oldVal === val && !Util.isObject(val)) {
1104
+ if (oldVal === val && !Util_1.Util.isObject(val)) {
1101
1105
  return;
1102
1106
  }
1103
1107
  if (val === undefined || val === null) {
@@ -1201,7 +1205,7 @@ export class Node {
1201
1205
  var pos = stage._getPointerById(pointerId) ||
1202
1206
  stage._changedPointerPositions[0] ||
1203
1207
  ap;
1204
- DD._dragElements.set(this._id, {
1208
+ DragAndDrop_1.DD._dragElements.set(this._id, {
1205
1209
  node: this,
1206
1210
  startPointerPos: pos,
1207
1211
  offset: {
@@ -1213,10 +1217,10 @@ export class Node {
1213
1217
  });
1214
1218
  }
1215
1219
  startDrag(evt, bubbleEvent = true) {
1216
- if (!DD._dragElements.has(this._id)) {
1220
+ if (!DragAndDrop_1.DD._dragElements.has(this._id)) {
1217
1221
  this._createDragElement(evt);
1218
1222
  }
1219
- const elem = DD._dragElements.get(this._id);
1223
+ const elem = DragAndDrop_1.DD._dragElements.get(this._id);
1220
1224
  elem.dragStatus = 'dragging';
1221
1225
  this.fire('dragstart', {
1222
1226
  type: 'dragstart',
@@ -1237,7 +1241,7 @@ export class Node {
1237
1241
  if (dbf !== undefined) {
1238
1242
  const bounded = dbf.call(this, newNodePos, evt);
1239
1243
  if (!bounded) {
1240
- Util.warn('dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.');
1244
+ Util_1.Util.warn('dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.');
1241
1245
  }
1242
1246
  else {
1243
1247
  newNodePos = bounded;
@@ -1252,26 +1256,26 @@ export class Node {
1252
1256
  this._lastPos = newNodePos;
1253
1257
  }
1254
1258
  stopDrag(evt) {
1255
- const elem = DD._dragElements.get(this._id);
1259
+ const elem = DragAndDrop_1.DD._dragElements.get(this._id);
1256
1260
  if (elem) {
1257
1261
  elem.dragStatus = 'stopped';
1258
1262
  }
1259
- DD._endDragBefore(evt);
1260
- DD._endDragAfter(evt);
1263
+ DragAndDrop_1.DD._endDragBefore(evt);
1264
+ DragAndDrop_1.DD._endDragAfter(evt);
1261
1265
  }
1262
1266
  setDraggable(draggable) {
1263
1267
  this._setAttr('draggable', draggable);
1264
1268
  this._dragChange();
1265
1269
  }
1266
1270
  isDragging() {
1267
- const elem = DD._dragElements.get(this._id);
1271
+ const elem = DragAndDrop_1.DD._dragElements.get(this._id);
1268
1272
  return elem ? elem.dragStatus === 'dragging' : false;
1269
1273
  }
1270
1274
  _listenDrag() {
1271
1275
  this._dragCleanup();
1272
1276
  this.on('mousedown.konva touchstart.konva', function (evt) {
1273
1277
  var shouldCheckButton = evt.evt['button'] !== undefined;
1274
- var canDrag = !shouldCheckButton || Konva.dragButtons.indexOf(evt.evt['button']) >= 0;
1278
+ var canDrag = !shouldCheckButton || Global_1.Konva.dragButtons.indexOf(evt.evt['button']) >= 0;
1275
1279
  if (!canDrag) {
1276
1280
  return;
1277
1281
  }
@@ -1279,7 +1283,7 @@ export class Node {
1279
1283
  return;
1280
1284
  }
1281
1285
  var hasDraggingChild = false;
1282
- DD._dragElements.forEach((elem) => {
1286
+ DragAndDrop_1.DD._dragElements.forEach((elem) => {
1283
1287
  if (this.isAncestorOf(elem.node)) {
1284
1288
  hasDraggingChild = true;
1285
1289
  }
@@ -1299,14 +1303,14 @@ export class Node {
1299
1303
  if (!stage) {
1300
1304
  return;
1301
1305
  }
1302
- const dragElement = DD._dragElements.get(this._id);
1306
+ const dragElement = DragAndDrop_1.DD._dragElements.get(this._id);
1303
1307
  const isDragging = dragElement && dragElement.dragStatus === 'dragging';
1304
1308
  const isReady = dragElement && dragElement.dragStatus === 'ready';
1305
1309
  if (isDragging) {
1306
1310
  this.stopDrag();
1307
1311
  }
1308
1312
  else if (isReady) {
1309
- DD._dragElements.delete(this._id);
1313
+ DragAndDrop_1.DD._dragElements.delete(this._id);
1310
1314
  }
1311
1315
  }
1312
1316
  }
@@ -1325,10 +1329,10 @@ export class Node {
1325
1329
  width: stage.width() + 2 * margin.x,
1326
1330
  height: stage.height() + 2 * margin.y,
1327
1331
  };
1328
- return Util.haveIntersection(screenRect, this.getClientRect());
1332
+ return Util_1.Util.haveIntersection(screenRect, this.getClientRect());
1329
1333
  }
1330
1334
  static create(data, container) {
1331
- if (Util._isString(data)) {
1335
+ if (Util_1.Util._isString(data)) {
1332
1336
  data = JSON.parse(data);
1333
1337
  }
1334
1338
  return this._createNode(data, container);
@@ -1338,13 +1342,13 @@ export class Node {
1338
1342
  if (container) {
1339
1343
  obj.attrs.container = container;
1340
1344
  }
1341
- if (!Konva[className]) {
1342
- Util.warn('Can not find a node with class name "' +
1345
+ if (!Global_1.Konva[className]) {
1346
+ Util_1.Util.warn('Can not find a node with class name "' +
1343
1347
  className +
1344
1348
  '". Fallback to "Shape".');
1345
1349
  className = 'Shape';
1346
1350
  }
1347
- const Class = Konva[className];
1351
+ const Class = Global_1.Konva[className];
1348
1352
  no = new Class(obj.attrs);
1349
1353
  if (children) {
1350
1354
  len = children.length;
@@ -1355,6 +1359,7 @@ export class Node {
1355
1359
  return no;
1356
1360
  }
1357
1361
  }
1362
+ exports.Node = Node;
1358
1363
  Node.prototype.nodeType = 'Node';
1359
1364
  Node.prototype._attrsAffectingSize = [];
1360
1365
  Node.prototype.eventListeners = {};
@@ -1375,41 +1380,41 @@ Node.prototype.on.call(Node.prototype, 'listeningChange.konva', function () {
1375
1380
  Node.prototype.on.call(Node.prototype, 'opacityChange.konva', function () {
1376
1381
  this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
1377
1382
  });
1378
- const addGetterSetter = Factory.addGetterSetter;
1383
+ const addGetterSetter = Factory_1.Factory.addGetterSetter;
1379
1384
  addGetterSetter(Node, 'zIndex');
1380
1385
  addGetterSetter(Node, 'absolutePosition');
1381
1386
  addGetterSetter(Node, 'position');
1382
- addGetterSetter(Node, 'x', 0, getNumberValidator());
1383
- addGetterSetter(Node, 'y', 0, getNumberValidator());
1384
- addGetterSetter(Node, 'globalCompositeOperation', 'source-over', getStringValidator());
1385
- addGetterSetter(Node, 'opacity', 1, getNumberValidator());
1386
- addGetterSetter(Node, 'name', '', getStringValidator());
1387
- addGetterSetter(Node, 'id', '', getStringValidator());
1388
- addGetterSetter(Node, 'rotation', 0, getNumberValidator());
1389
- Factory.addComponentsGetterSetter(Node, 'scale', ['x', 'y']);
1390
- addGetterSetter(Node, 'scaleX', 1, getNumberValidator());
1391
- addGetterSetter(Node, 'scaleY', 1, getNumberValidator());
1392
- Factory.addComponentsGetterSetter(Node, 'skew', ['x', 'y']);
1393
- addGetterSetter(Node, 'skewX', 0, getNumberValidator());
1394
- addGetterSetter(Node, 'skewY', 0, getNumberValidator());
1395
- Factory.addComponentsGetterSetter(Node, 'offset', ['x', 'y']);
1396
- addGetterSetter(Node, 'offsetX', 0, getNumberValidator());
1397
- addGetterSetter(Node, 'offsetY', 0, getNumberValidator());
1398
- addGetterSetter(Node, 'dragDistance', null, getNumberValidator());
1399
- addGetterSetter(Node, 'width', 0, getNumberValidator());
1400
- addGetterSetter(Node, 'height', 0, getNumberValidator());
1401
- addGetterSetter(Node, 'listening', true, getBooleanValidator());
1402
- addGetterSetter(Node, 'preventDefault', true, getBooleanValidator());
1387
+ addGetterSetter(Node, 'x', 0, (0, Validators_1.getNumberValidator)());
1388
+ addGetterSetter(Node, 'y', 0, (0, Validators_1.getNumberValidator)());
1389
+ addGetterSetter(Node, 'globalCompositeOperation', 'source-over', (0, Validators_1.getStringValidator)());
1390
+ addGetterSetter(Node, 'opacity', 1, (0, Validators_1.getNumberValidator)());
1391
+ addGetterSetter(Node, 'name', '', (0, Validators_1.getStringValidator)());
1392
+ addGetterSetter(Node, 'id', '', (0, Validators_1.getStringValidator)());
1393
+ addGetterSetter(Node, 'rotation', 0, (0, Validators_1.getNumberValidator)());
1394
+ Factory_1.Factory.addComponentsGetterSetter(Node, 'scale', ['x', 'y']);
1395
+ addGetterSetter(Node, 'scaleX', 1, (0, Validators_1.getNumberValidator)());
1396
+ addGetterSetter(Node, 'scaleY', 1, (0, Validators_1.getNumberValidator)());
1397
+ Factory_1.Factory.addComponentsGetterSetter(Node, 'skew', ['x', 'y']);
1398
+ addGetterSetter(Node, 'skewX', 0, (0, Validators_1.getNumberValidator)());
1399
+ addGetterSetter(Node, 'skewY', 0, (0, Validators_1.getNumberValidator)());
1400
+ Factory_1.Factory.addComponentsGetterSetter(Node, 'offset', ['x', 'y']);
1401
+ addGetterSetter(Node, 'offsetX', 0, (0, Validators_1.getNumberValidator)());
1402
+ addGetterSetter(Node, 'offsetY', 0, (0, Validators_1.getNumberValidator)());
1403
+ addGetterSetter(Node, 'dragDistance', null, (0, Validators_1.getNumberValidator)());
1404
+ addGetterSetter(Node, 'width', 0, (0, Validators_1.getNumberValidator)());
1405
+ addGetterSetter(Node, 'height', 0, (0, Validators_1.getNumberValidator)());
1406
+ addGetterSetter(Node, 'listening', true, (0, Validators_1.getBooleanValidator)());
1407
+ addGetterSetter(Node, 'preventDefault', true, (0, Validators_1.getBooleanValidator)());
1403
1408
  addGetterSetter(Node, 'filters', null, function (val) {
1404
1409
  this._filterUpToDate = false;
1405
1410
  return val;
1406
1411
  });
1407
- addGetterSetter(Node, 'visible', true, getBooleanValidator());
1408
- addGetterSetter(Node, 'transformsEnabled', 'all', getStringValidator());
1412
+ addGetterSetter(Node, 'visible', true, (0, Validators_1.getBooleanValidator)());
1413
+ addGetterSetter(Node, 'transformsEnabled', 'all', (0, Validators_1.getStringValidator)());
1409
1414
  addGetterSetter(Node, 'size');
1410
1415
  addGetterSetter(Node, 'dragBoundFunc');
1411
- addGetterSetter(Node, 'draggable', false, getBooleanValidator());
1412
- Factory.backCompat(Node, {
1416
+ addGetterSetter(Node, 'draggable', false, (0, Validators_1.getBooleanValidator)());
1417
+ Factory_1.Factory.backCompat(Node, {
1413
1418
  rotateDeg: 'rotate',
1414
1419
  setRotationDeg: 'setRotation',
1415
1420
  getRotationDeg: 'getRotation',
@@ -1,10 +1,10 @@
1
- import { KonvaEventObject } from './Node';
2
- import { Shape } from './Shape';
3
- import { Stage } from './Stage';
1
+ import { KonvaEventObject } from './Node.js';
2
+ import { Shape } from './Shape.js';
3
+ import { Stage } from './Stage.js';
4
4
  export interface KonvaPointerEvent extends KonvaEventObject<PointerEvent> {
5
5
  pointerId: number;
6
6
  }
7
- export declare function getCapturedShape(pointerId: number): Shape<import("./Shape").ShapeConfig> | Stage;
7
+ export declare function getCapturedShape(pointerId: number): Shape<import("./Shape.js").ShapeConfig> | Stage;
8
8
  export declare function createEvent(evt: PointerEvent): KonvaPointerEvent;
9
9
  export declare function hasPointerCapture(pointerId: number, shape: Shape | Stage): boolean;
10
10
  export declare function setPointerCapture(pointerId: number, shape: Shape | Stage): void;
@@ -1,19 +1,25 @@
1
- import { Konva } from './Global.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.releaseCapture = exports.setPointerCapture = exports.hasPointerCapture = exports.createEvent = exports.getCapturedShape = void 0;
4
+ const Global_1 = require("./Global");
2
5
  const Captures = new Map();
3
- const SUPPORT_POINTER_EVENTS = Konva._global['PointerEvent'] !== undefined;
4
- export function getCapturedShape(pointerId) {
6
+ const SUPPORT_POINTER_EVENTS = Global_1.Konva._global['PointerEvent'] !== undefined;
7
+ function getCapturedShape(pointerId) {
5
8
  return Captures.get(pointerId);
6
9
  }
7
- export function createEvent(evt) {
10
+ exports.getCapturedShape = getCapturedShape;
11
+ function createEvent(evt) {
8
12
  return {
9
13
  evt,
10
14
  pointerId: evt.pointerId,
11
15
  };
12
16
  }
13
- export function hasPointerCapture(pointerId, shape) {
17
+ exports.createEvent = createEvent;
18
+ function hasPointerCapture(pointerId, shape) {
14
19
  return Captures.get(pointerId) === shape;
15
20
  }
16
- export function setPointerCapture(pointerId, shape) {
21
+ exports.hasPointerCapture = hasPointerCapture;
22
+ function setPointerCapture(pointerId, shape) {
17
23
  releaseCapture(pointerId);
18
24
  const stage = shape.getStage();
19
25
  if (!stage)
@@ -23,7 +29,8 @@ export function setPointerCapture(pointerId, shape) {
23
29
  shape._fire('gotpointercapture', createEvent(new PointerEvent('gotpointercapture')));
24
30
  }
25
31
  }
26
- export function releaseCapture(pointerId, target) {
32
+ exports.setPointerCapture = setPointerCapture;
33
+ function releaseCapture(pointerId, target) {
27
34
  const shape = Captures.get(pointerId);
28
35
  if (!shape)
29
36
  return;
@@ -35,3 +42,4 @@ export function releaseCapture(pointerId, target) {
35
42
  shape._fire('lostpointercapture', createEvent(new PointerEvent('lostpointercapture')));
36
43
  }
37
44
  }
45
+ exports.releaseCapture = releaseCapture;
package/lib/Shape.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Node, NodeConfig } from './Node';
2
- import { Context } from './Context';
3
- import { GetSet, Vector2d } from './types';
4
- import { HitCanvas, SceneCanvas } from './Canvas';
1
+ import { Node, NodeConfig } from './Node.js';
2
+ import { Context } from './Context.js';
3
+ import { GetSet, Vector2d } from './types.js';
4
+ import { HitCanvas, SceneCanvas } from './Canvas.js';
5
5
  export type ShapeConfigHandler<TTarget> = {
6
6
  bivarianceHack(ctx: Context, shape: TTarget): void;
7
7
  }['bivarianceHack'];
@@ -180,5 +180,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
180
180
  strokeHitEnabled: GetSet<boolean, this>;
181
181
  strokeWidth: GetSet<number, this>;
182
182
  hitStrokeWidth: GetSet<number | 'auto', this>;
183
+ strokeLinearGradientStartPoint: GetSet<Vector2d, this>;
184
+ strokeLinearGradientEndPoint: GetSet<Vector2d, this>;
183
185
  strokeLinearGradientColorStops: GetSet<Array<number | string>, this>;
184
186
  }