konva 9.3.15 → 9.3.16

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 (65) hide show
  1. package/konva.js +726 -724
  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 +26 -26
  10. package/lib/DragAndDrop.d.ts +2 -2
  11. package/lib/DragAndDrop.js +6 -4
  12. package/lib/Factory.js +16 -16
  13. package/lib/Global.js +1 -1
  14. package/lib/Group.js +1 -1
  15. package/lib/Layer.js +17 -17
  16. package/lib/Node.d.ts +1 -1
  17. package/lib/Node.js +87 -87
  18. package/lib/PointerEvents.js +5 -6
  19. package/lib/Shape.js +31 -31
  20. package/lib/Stage.d.ts +2 -2
  21. package/lib/Stage.js +28 -28
  22. package/lib/Tween.js +21 -21
  23. package/lib/Util.d.ts +4 -4
  24. package/lib/Util.js +62 -62
  25. package/lib/Validators.js +16 -17
  26. package/lib/_CoreInternals.d.ts +8 -8
  27. package/lib/_FullInternals.d.ts +8 -8
  28. package/lib/filters/Blur.js +6 -6
  29. package/lib/filters/Brighten.js +1 -1
  30. package/lib/filters/Contrast.js +2 -2
  31. package/lib/filters/Emboss.js +19 -19
  32. package/lib/filters/Enhance.js +4 -4
  33. package/lib/filters/Grayscale.js +1 -1
  34. package/lib/filters/HSL.js +6 -6
  35. package/lib/filters/HSV.js +7 -7
  36. package/lib/filters/Invert.js +1 -1
  37. package/lib/filters/Kaleidoscope.js +20 -20
  38. package/lib/filters/Mask.js +57 -57
  39. package/lib/filters/Noise.js +2 -2
  40. package/lib/filters/Pixelate.js +1 -1
  41. package/lib/filters/Posterize.js +1 -1
  42. package/lib/filters/RGB.js +1 -1
  43. package/lib/filters/RGBA.js +3 -3
  44. package/lib/filters/Sepia.js +1 -1
  45. package/lib/filters/Solarize.js +8 -7
  46. package/lib/filters/Threshold.js +2 -2
  47. package/lib/shapes/Arc.js +1 -1
  48. package/lib/shapes/Arrow.js +10 -10
  49. package/lib/shapes/Ellipse.js +1 -1
  50. package/lib/shapes/Image.js +3 -3
  51. package/lib/shapes/Label.d.ts +1 -1
  52. package/lib/shapes/Label.js +6 -6
  53. package/lib/shapes/Line.d.ts +1 -1
  54. package/lib/shapes/Line.js +14 -14
  55. package/lib/shapes/Path.js +62 -62
  56. package/lib/shapes/Rect.js +1 -1
  57. package/lib/shapes/RegularPolygon.js +6 -6
  58. package/lib/shapes/Ring.js +1 -1
  59. package/lib/shapes/Sprite.js +9 -9
  60. package/lib/shapes/Star.js +5 -5
  61. package/lib/shapes/Text.js +37 -37
  62. package/lib/shapes/TextPath.js +23 -23
  63. package/lib/shapes/Transformer.d.ts +1 -1
  64. package/lib/shapes/Transformer.js +63 -63
  65. package/package.json +2 -5
@@ -10,8 +10,8 @@ const Group_1 = require("../Group");
10
10
  const Global_1 = require("../Global");
11
11
  const Validators_1 = require("../Validators");
12
12
  const Global_2 = require("../Global");
13
- var EVENTS_NAME = 'tr-konva';
14
- var ATTR_CHANGE_LIST = [
13
+ const EVENTS_NAME = 'tr-konva';
14
+ const ATTR_CHANGE_LIST = [
15
15
  'resizeEnabledChange',
16
16
  'rotateAnchorOffsetChange',
17
17
  'rotateEnabledChange',
@@ -30,8 +30,8 @@ var ATTR_CHANGE_LIST = [
30
30
  ]
31
31
  .map((e) => e + `.${EVENTS_NAME}`)
32
32
  .join(' ');
33
- var NODES_RECT = 'nodesRect';
34
- var TRANSFORM_CHANGE_STR = [
33
+ const NODES_RECT = 'nodesRect';
34
+ const TRANSFORM_CHANGE_STR = [
35
35
  'widthChange',
36
36
  'heightChange',
37
37
  'scaleXChange',
@@ -44,7 +44,7 @@ var TRANSFORM_CHANGE_STR = [
44
44
  'transformsEnabledChange',
45
45
  'strokeWidthChange',
46
46
  ];
47
- var ANGLES = {
47
+ const ANGLES = {
48
48
  'top-left': -45,
49
49
  'top-center': 0,
50
50
  'top-right': 45,
@@ -60,7 +60,7 @@ function getCursor(anchorName, rad, rotateCursor) {
60
60
  return rotateCursor;
61
61
  }
62
62
  rad += Util_1.Util.degToRad(ANGLES[anchorName] || 0);
63
- var angle = ((Util_1.Util.radToDeg(rad) % 360) + 360) % 360;
63
+ const angle = ((Util_1.Util.radToDeg(rad) % 360) + 360) % 360;
64
64
  if (Util_1.Util._inRange(angle, 315 + 22.5, 360) || Util_1.Util._inRange(angle, 0, 22.5)) {
65
65
  return 'ns-resize';
66
66
  }
@@ -90,7 +90,7 @@ function getCursor(anchorName, rad, rotateCursor) {
90
90
  return 'pointer';
91
91
  }
92
92
  }
93
- var ANCHORS_NAMES = [
93
+ const ANCHORS_NAMES = [
94
94
  'top-left',
95
95
  'top-center',
96
96
  'top-right',
@@ -100,7 +100,7 @@ var ANCHORS_NAMES = [
100
100
  'bottom-center',
101
101
  'bottom-right',
102
102
  ];
103
- var MAX_SAFE_INTEGER = 100000000;
103
+ const MAX_SAFE_INTEGER = 100000000;
104
104
  function getCenter(shape) {
105
105
  return {
106
106
  x: shape.x +
@@ -207,7 +207,7 @@ class Transformer extends Group_1.Group {
207
207
  this._proxyDrag(node);
208
208
  });
209
209
  this._resetTransformCache();
210
- var elementsCreated = !!this.findOne('.top-left');
210
+ const elementsCreated = !!this.findOne('.top-left');
211
211
  if (elementsCreated) {
212
212
  this.update();
213
213
  }
@@ -269,15 +269,15 @@ class Transformer extends Group_1.Group {
269
269
  return this._getCache(NODES_RECT, this.__getNodeRect);
270
270
  }
271
271
  __getNodeShape(node, rot = this.rotation(), relative) {
272
- var rect = node.getClientRect({
272
+ const rect = node.getClientRect({
273
273
  skipTransform: true,
274
274
  skipShadow: true,
275
275
  skipStroke: this.ignoreStroke(),
276
276
  });
277
- var absScale = node.getAbsoluteScale(relative);
278
- var absPos = node.getAbsolutePosition(relative);
279
- var dx = rect.x * absScale.x - node.offsetX() * absScale.x;
280
- var dy = rect.y * absScale.y - node.offsetY() * absScale.y;
277
+ const absScale = node.getAbsoluteScale(relative);
278
+ const absPos = node.getAbsolutePosition(relative);
279
+ const dx = rect.x * absScale.x - node.offsetX() * absScale.x;
280
+ const dy = rect.y * absScale.y - node.offsetY() * absScale.y;
281
281
  const rotation = (Global_1.Konva.getAngle(node.getAbsoluteRotation()) + Math.PI * 2) %
282
282
  (Math.PI * 2);
283
283
  const box = {
@@ -293,7 +293,7 @@ class Transformer extends Group_1.Group {
293
293
  });
294
294
  }
295
295
  __getNodeRect() {
296
- var node = this.getNode();
296
+ const node = this.getNode();
297
297
  if (!node) {
298
298
  return {
299
299
  x: -MAX_SAFE_INTEGER,
@@ -310,23 +310,23 @@ class Transformer extends Group_1.Group {
310
310
  skipShadow: true,
311
311
  skipStroke: this.ignoreStroke(),
312
312
  });
313
- var points = [
313
+ const points = [
314
314
  { x: box.x, y: box.y },
315
315
  { x: box.x + box.width, y: box.y },
316
316
  { x: box.x + box.width, y: box.y + box.height },
317
317
  { x: box.x, y: box.y + box.height },
318
318
  ];
319
- var trans = node.getAbsoluteTransform();
319
+ const trans = node.getAbsoluteTransform();
320
320
  points.forEach(function (point) {
321
- var transformed = trans.point(point);
321
+ const transformed = trans.point(point);
322
322
  totalPoints.push(transformed);
323
323
  });
324
324
  });
325
325
  const tr = new Util_1.Transform();
326
326
  tr.rotate(-Global_1.Konva.getAngle(this.rotation()));
327
- var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
327
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
328
328
  totalPoints.forEach(function (point) {
329
- var transformed = tr.point(point);
329
+ const transformed = tr.point(point);
330
330
  if (minX === undefined) {
331
331
  minX = maxX = transformed.x;
332
332
  minY = maxY = transformed.y;
@@ -366,7 +366,7 @@ class Transformer extends Group_1.Group {
366
366
  this._createAnchor('rotater');
367
367
  }
368
368
  _createAnchor(name) {
369
- var anchor = new Rect_1.Rect({
369
+ const anchor = new Rect_1.Rect({
370
370
  stroke: 'rgb(0, 161, 255)',
371
371
  fill: 'white',
372
372
  strokeWidth: 1,
@@ -375,7 +375,7 @@ class Transformer extends Group_1.Group {
375
375
  draggable: true,
376
376
  hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto',
377
377
  });
378
- var self = this;
378
+ const self = this;
379
379
  anchor.on('mousedown touchstart', function (e) {
380
380
  self._handleMouseDown(e);
381
381
  });
@@ -387,9 +387,9 @@ class Transformer extends Group_1.Group {
387
387
  e.cancelBubble = true;
388
388
  });
389
389
  anchor.on('mouseenter', () => {
390
- var rad = Global_1.Konva.getAngle(this.rotation());
391
- var rotateCursor = this.rotateAnchorCursor();
392
- var cursor = getCursor(name, rad, rotateCursor);
390
+ const rad = Global_1.Konva.getAngle(this.rotation());
391
+ const rotateCursor = this.rotateAnchorCursor();
392
+ const cursor = getCursor(name, rad, rotateCursor);
393
393
  anchor.getStage().content &&
394
394
  (anchor.getStage().content.style.cursor = cursor);
395
395
  this._cursorChange = true;
@@ -402,14 +402,14 @@ class Transformer extends Group_1.Group {
402
402
  this.add(anchor);
403
403
  }
404
404
  _createBack() {
405
- var back = new Shape_1.Shape({
405
+ const back = new Shape_1.Shape({
406
406
  name: 'back',
407
407
  width: 0,
408
408
  height: 0,
409
409
  draggable: true,
410
410
  sceneFunc(ctx, shape) {
411
- var tr = shape.getParent();
412
- var padding = tr.padding();
411
+ const tr = shape.getParent();
412
+ const padding = tr.padding();
413
413
  ctx.beginPath();
414
414
  ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
415
415
  ctx.moveTo(shape.width() / 2, -padding);
@@ -422,7 +422,7 @@ class Transformer extends Group_1.Group {
422
422
  if (!this.shouldOverdrawWholeArea()) {
423
423
  return;
424
424
  }
425
- var padding = this.padding();
425
+ const padding = this.padding();
426
426
  ctx.beginPath();
427
427
  ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
428
428
  ctx.fillStrokeShape(shape);
@@ -448,10 +448,10 @@ class Transformer extends Group_1.Group {
448
448
  return;
449
449
  }
450
450
  this._movingAnchorName = e.target.name().split(' ')[0];
451
- var attrs = this._getNodeRect();
452
- var width = attrs.width;
453
- var height = attrs.height;
454
- var hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
451
+ const attrs = this._getNodeRect();
452
+ const width = attrs.width;
453
+ const height = attrs.height;
454
+ const hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
455
455
  this.sin = Math.abs(height / hypotenuse);
456
456
  this.cos = Math.abs(width / hypotenuse);
457
457
  if (typeof window !== 'undefined') {
@@ -461,8 +461,8 @@ class Transformer extends Group_1.Group {
461
461
  window.addEventListener('touchend', this._handleMouseUp, true);
462
462
  }
463
463
  this._transforming = true;
464
- var ap = e.target.getAbsolutePosition();
465
- var pos = e.target.getStage().getPointerPosition();
464
+ const ap = e.target.getAbsolutePosition();
465
+ const pos = e.target.getStage().getPointerPosition();
466
466
  this._anchorDragOffset = {
467
467
  x: pos.x - ap.x,
468
468
  y: pos.y - ap.y,
@@ -474,9 +474,9 @@ class Transformer extends Group_1.Group {
474
474
  });
475
475
  }
476
476
  _handleMouseMove(e) {
477
- var x, y, newHypotenuse;
478
- var anchorNode = this.findOne('.' + this._movingAnchorName);
479
- var stage = anchorNode.getStage();
477
+ let x, y, newHypotenuse;
478
+ const anchorNode = this.findOne('.' + this._movingAnchorName);
479
+ const stage = anchorNode.getStage();
480
480
  stage.setPointersPositions(e);
481
481
  const pp = stage.getPointerPosition();
482
482
  let newNodePos = {
@@ -493,14 +493,14 @@ class Transformer extends Group_1.Group {
493
493
  return;
494
494
  }
495
495
  if (this._movingAnchorName === 'rotater') {
496
- var attrs = this._getNodeRect();
496
+ const attrs = this._getNodeRect();
497
497
  x = anchorNode.x() - attrs.width / 2;
498
498
  y = -anchorNode.y() + attrs.height / 2;
499
499
  let delta = Math.atan2(-y, x) + Math.PI / 2;
500
500
  if (attrs.height < 0) {
501
501
  delta -= Math.PI;
502
502
  }
503
- var oldRotation = Global_1.Konva.getAngle(this.rotation());
503
+ const oldRotation = Global_1.Konva.getAngle(this.rotation());
504
504
  const newRotation = oldRotation + delta;
505
505
  const tol = Global_1.Konva.getAngle(this.rotationSnapTolerance());
506
506
  const snappedRot = getSnap(this.rotationSnaps(), newRotation, tol);
@@ -509,8 +509,8 @@ class Transformer extends Group_1.Group {
509
509
  this._fitNodesInto(shape, e);
510
510
  return;
511
511
  }
512
- var shiftBehavior = this.shiftBehavior();
513
- var keepProportion;
512
+ const shiftBehavior = this.shiftBehavior();
513
+ let keepProportion;
514
514
  if (shiftBehavior === 'inverted') {
515
515
  keepProportion = this.keepRatio() && !e.shiftKey;
516
516
  }
@@ -629,12 +629,12 @@ class Transformer extends Group_1.Group {
629
629
  }
630
630
  var centeredScaling = this.centeredScaling() || e.altKey;
631
631
  if (centeredScaling) {
632
- var topLeft = this.findOne('.top-left');
633
- var bottomRight = this.findOne('.bottom-right');
634
- var topOffsetX = topLeft.x();
635
- var topOffsetY = topLeft.y();
636
- var bottomOffsetX = this.getWidth() - bottomRight.x();
637
- var bottomOffsetY = this.getHeight() - bottomRight.y();
632
+ const topLeft = this.findOne('.top-left');
633
+ const bottomRight = this.findOne('.bottom-right');
634
+ const topOffsetX = topLeft.x();
635
+ const topOffsetY = topLeft.y();
636
+ const bottomOffsetX = this.getWidth() - bottomRight.x();
637
+ const bottomOffsetY = this.getHeight() - bottomRight.y();
638
638
  bottomRight.move({
639
639
  x: -topOffsetX,
640
640
  y: -topOffsetY,
@@ -644,11 +644,11 @@ class Transformer extends Group_1.Group {
644
644
  y: bottomOffsetY,
645
645
  });
646
646
  }
647
- var absPos = this.findOne('.top-left').getAbsolutePosition();
647
+ const absPos = this.findOne('.top-left').getAbsolutePosition();
648
648
  x = absPos.x;
649
649
  y = absPos.y;
650
- var width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();
651
- var height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
650
+ const width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();
651
+ const height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
652
652
  this._fitNodesInto({
653
653
  x: x,
654
654
  y: y,
@@ -673,7 +673,7 @@ class Transformer extends Group_1.Group {
673
673
  window.removeEventListener('mouseup', this._handleMouseUp, true);
674
674
  window.removeEventListener('touchend', this._handleMouseUp, true);
675
675
  }
676
- var node = this.getNode();
676
+ const node = this.getNode();
677
677
  activeTransformersCount--;
678
678
  this._fire('transformend', { evt: e, target: node });
679
679
  (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
@@ -688,7 +688,7 @@ class Transformer extends Group_1.Group {
688
688
  }
689
689
  }
690
690
  _fitNodesInto(newAttrs, evt) {
691
- var oldAttrs = this._getNodeRect();
691
+ const oldAttrs = this._getNodeRect();
692
692
  const minSize = 1;
693
693
  if (Util_1.Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) {
694
694
  this.update();
@@ -698,7 +698,7 @@ class Transformer extends Group_1.Group {
698
698
  this.update();
699
699
  return;
700
700
  }
701
- var t = new Util_1.Transform();
701
+ const t = new Util_1.Transform();
702
702
  t.rotate(Global_1.Konva.getAngle(this.rotation()));
703
703
  if (this._movingAnchorName &&
704
704
  newAttrs.width < 0 &&
@@ -815,14 +815,14 @@ class Transformer extends Group_1.Group {
815
815
  }
816
816
  update() {
817
817
  var _a;
818
- var attrs = this._getNodeRect();
818
+ const attrs = this._getNodeRect();
819
819
  this.rotation(Util_1.Util._getRotation(attrs.rotation));
820
- var width = attrs.width;
821
- var height = attrs.height;
822
- var enabledAnchors = this.enabledAnchors();
823
- var resizeEnabled = this.resizeEnabled();
824
- var padding = this.padding();
825
- var anchorSize = this.anchorSize();
820
+ const width = attrs.width;
821
+ const height = attrs.height;
822
+ const enabledAnchors = this.enabledAnchors();
823
+ const resizeEnabled = this.resizeEnabled();
824
+ const padding = this.padding();
825
+ const anchorSize = this.anchorSize();
826
826
  const anchors = this.find('._anchor');
827
827
  anchors.forEach((node) => {
828
828
  node.setAttrs({
@@ -917,7 +917,7 @@ class Transformer extends Group_1.Group {
917
917
  stopTransform() {
918
918
  if (this._transforming) {
919
919
  this._removeEvents();
920
- var anchorNode = this.findOne('.' + this._movingAnchorName);
920
+ const anchorNode = this.findOne('.' + this._movingAnchorName);
921
921
  if (anchorNode) {
922
922
  anchorNode.stopDrag();
923
923
  }
@@ -936,7 +936,7 @@ class Transformer extends Group_1.Group {
936
936
  return Node_1.Node.prototype.toObject.call(this);
937
937
  }
938
938
  clone(obj) {
939
- var node = Node_1.Node.prototype.clone.call(this, obj);
939
+ const node = Node_1.Node.prototype.clone.call(this, obj);
940
940
  return node;
941
941
  }
942
942
  getClientRect() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "9.3.15",
3
+ "version": "9.3.16",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",
@@ -20,7 +20,7 @@
20
20
  "test": "npm run test:browser && npm run test:node",
21
21
  "test:build": "parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
22
22
  "test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security",
23
- "test:watch": "rm -rf ./.parcel-cache && parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html ./test/text-paths.html ./test/bunnies.html",
23
+ "test:watch": "rm -rf ./.parcel-cache && PARCEL_WORKERS=0 parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html ./test/text-paths.html ./test/bunnies.html",
24
24
  "test:node": "ts-mocha -r ./test/node-global-setup.mjs -p ./test/tsconfig.json test/unit/**/*.ts --exit && npm run test:import",
25
25
  "tsc": "tsc --removeComments",
26
26
  "rollup": "rollup -c --bundleConfigAsCjs",
@@ -81,9 +81,6 @@
81
81
  "parcel": "2.10.1",
82
82
  "process": "^0.11.10",
83
83
  "rollup": "^4.9.1",
84
- "rollup-plugin-commonjs": "^10.1.0",
85
- "rollup-plugin-node-resolve": "^5.2.0",
86
- "rollup-plugin-sourcemaps": "^0.6.3",
87
84
  "rollup-plugin-typescript2": "^0.36.0",
88
85
  "size-limit": "^11.0.1",
89
86
  "ts-mocha": "^10.0.0",