konva 10.3.2 → 10.4.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 (123) hide show
  1. package/README.md +5 -1
  2. package/konva.js +1327 -1572
  3. package/konva.min.js +4 -4
  4. package/lib/Animation.d.ts +63 -3
  5. package/lib/Animation.js +86 -65
  6. package/lib/BezierFunctions.d.ts +10 -0
  7. package/lib/BezierFunctions.js +32 -0
  8. package/lib/Canvas.d.ts +53 -0
  9. package/lib/Canvas.js +93 -34
  10. package/lib/Container.d.ts +156 -9
  11. package/lib/Container.js +260 -25
  12. package/lib/Context.d.ts +247 -0
  13. package/lib/Context.js +312 -74
  14. package/lib/Core.js +1 -0
  15. package/lib/DragAndDrop.d.ts +1 -0
  16. package/lib/DragAndDrop.js +66 -17
  17. package/lib/Factory.d.ts +24 -1
  18. package/lib/Factory.js +14 -20
  19. package/lib/FastLayer.d.ts +14 -1
  20. package/lib/FastLayer.js +14 -1
  21. package/lib/Global.d.ts +114 -3
  22. package/lib/Global.js +134 -5
  23. package/lib/Group.d.ts +11 -0
  24. package/lib/Group.js +11 -0
  25. package/lib/Layer.d.ts +128 -3
  26. package/lib/Layer.js +260 -49
  27. package/lib/Node.d.ts +692 -30
  28. package/lib/Node.js +1534 -202
  29. package/lib/PointerEvents.d.ts +2 -1
  30. package/lib/PointerEvents.js +19 -1
  31. package/lib/Shape.d.ts +99 -14
  32. package/lib/Shape.js +1101 -67
  33. package/lib/Stage.d.ts +81 -1
  34. package/lib/Stage.js +166 -7
  35. package/lib/Tween.d.ts +159 -4
  36. package/lib/Tween.js +243 -24
  37. package/lib/Util.d.ts +147 -4
  38. package/lib/Util.js +332 -82
  39. package/lib/Validators.d.ts +0 -2
  40. package/lib/Validators.js +3 -25
  41. package/lib/_CoreInternals.d.ts +10 -6
  42. package/lib/_CoreInternals.js +1 -0
  43. package/lib/_FullInternals.d.ts +15 -6
  44. package/lib/_FullInternals.js +7 -0
  45. package/lib/canvas-backend.js +6 -0
  46. package/lib/filters/Blur.d.ts +18 -0
  47. package/lib/filters/Blur.js +97 -24
  48. package/lib/filters/Brighten.d.ts +21 -0
  49. package/lib/filters/Brighten.js +24 -0
  50. package/lib/filters/Brightness.d.ts +11 -0
  51. package/lib/filters/Brightness.js +16 -0
  52. package/lib/filters/Contrast.d.ts +10 -0
  53. package/lib/filters/Contrast.js +21 -0
  54. package/lib/filters/Emboss.d.ts +20 -0
  55. package/lib/filters/Emboss.js +68 -8
  56. package/lib/filters/Enhance.d.ts +14 -0
  57. package/lib/filters/Enhance.js +34 -0
  58. package/lib/filters/Grayscale.d.ts +9 -0
  59. package/lib/filters/Grayscale.js +12 -0
  60. package/lib/filters/HSL.d.ts +17 -0
  61. package/lib/filters/HSL.js +48 -5
  62. package/lib/filters/HSV.d.ts +18 -0
  63. package/lib/filters/HSV.js +49 -5
  64. package/lib/filters/Invert.d.ts +9 -0
  65. package/lib/filters/Invert.js +12 -0
  66. package/lib/filters/Kaleidoscope.d.ts +12 -0
  67. package/lib/filters/Kaleidoscope.js +83 -0
  68. package/lib/filters/Mask.d.ts +11 -0
  69. package/lib/filters/Mask.js +18 -0
  70. package/lib/filters/Noise.d.ts +19 -0
  71. package/lib/filters/Noise.js +19 -0
  72. package/lib/filters/Pixelate.d.ts +20 -0
  73. package/lib/filters/Pixelate.js +28 -1
  74. package/lib/filters/Posterize.d.ts +21 -0
  75. package/lib/filters/Posterize.js +22 -0
  76. package/lib/filters/RGB.d.ts +21 -0
  77. package/lib/filters/RGB.js +43 -28
  78. package/lib/filters/RGBA.d.ts +23 -0
  79. package/lib/filters/RGBA.js +28 -41
  80. package/lib/filters/Sepia.d.ts +9 -0
  81. package/lib/filters/Sepia.js +10 -0
  82. package/lib/filters/Solarize.d.ts +10 -0
  83. package/lib/filters/Solarize.js +11 -0
  84. package/lib/filters/Threshold.d.ts +22 -0
  85. package/lib/filters/Threshold.js +22 -0
  86. package/lib/shapes/Arc.d.ts +40 -0
  87. package/lib/shapes/Arc.js +89 -6
  88. package/lib/shapes/Arrow.d.ts +24 -1
  89. package/lib/shapes/Arrow.js +83 -0
  90. package/lib/shapes/Circle.d.ts +18 -0
  91. package/lib/shapes/Circle.js +36 -9
  92. package/lib/shapes/Ellipse.d.ts +34 -2
  93. package/lib/shapes/Ellipse.js +67 -9
  94. package/lib/shapes/Image.d.ts +49 -0
  95. package/lib/shapes/Image.js +151 -22
  96. package/lib/shapes/Label.d.ts +65 -1
  97. package/lib/shapes/Label.js +113 -20
  98. package/lib/shapes/Line.d.ts +50 -8
  99. package/lib/shapes/Line.js +116 -20
  100. package/lib/shapes/Path.d.ts +40 -6
  101. package/lib/shapes/Path.js +187 -128
  102. package/lib/shapes/Rect.d.ts +18 -0
  103. package/lib/shapes/Rect.js +36 -0
  104. package/lib/shapes/RegularPolygon.d.ts +22 -0
  105. package/lib/shapes/RegularPolygon.js +70 -0
  106. package/lib/shapes/Ring.d.ts +19 -0
  107. package/lib/shapes/Ring.js +51 -5
  108. package/lib/shapes/Sprite.d.ts +78 -0
  109. package/lib/shapes/Sprite.js +238 -25
  110. package/lib/shapes/Star.d.ts +23 -0
  111. package/lib/shapes/Star.js +62 -0
  112. package/lib/shapes/Text.d.ts +59 -1
  113. package/lib/shapes/Text.js +481 -97
  114. package/lib/shapes/TextPath.d.ts +49 -3
  115. package/lib/shapes/TextPath.js +278 -34
  116. package/lib/shapes/Transformer.d.ts +108 -11
  117. package/lib/shapes/Transformer.js +744 -102
  118. package/lib/shapes/Wedge.d.ts +22 -0
  119. package/lib/shapes/Wedge.js +67 -3
  120. package/lib/skia-backend.js +9 -0
  121. package/lib/types.d.ts +2 -23
  122. package/lib/types.js +1 -21
  123. package/package.json +24 -21
@@ -25,6 +25,7 @@ const ATTR_CHANGE_LIST = [
25
25
  'anchorCornerRadiusChange',
26
26
  'ignoreStrokeChange',
27
27
  'anchorStyleFuncChange',
28
+ 'paddingChange',
28
29
  ]
29
30
  .map((e) => e + `.${EVENTS_NAME}`)
30
31
  .join(' ');
@@ -61,30 +62,39 @@ function getCursor(anchorName, rad, rotateCursor) {
61
62
  rad += Util.degToRad(ANGLES[anchorName] || 0);
62
63
  const angle = ((Util.radToDeg(rad) % 360) + 360) % 360;
63
64
  if (Util._inRange(angle, 315 + 22.5, 360) || Util._inRange(angle, 0, 22.5)) {
65
+ // TOP
64
66
  return 'ns-resize';
65
67
  }
66
68
  else if (Util._inRange(angle, 45 - 22.5, 45 + 22.5)) {
69
+ // TOP - RIGHT
67
70
  return 'nesw-resize';
68
71
  }
69
72
  else if (Util._inRange(angle, 90 - 22.5, 90 + 22.5)) {
73
+ // RIGHT
70
74
  return 'ew-resize';
71
75
  }
72
76
  else if (Util._inRange(angle, 135 - 22.5, 135 + 22.5)) {
77
+ // BOTTOM - RIGHT
73
78
  return 'nwse-resize';
74
79
  }
75
80
  else if (Util._inRange(angle, 180 - 22.5, 180 + 22.5)) {
81
+ // BOTTOM
76
82
  return 'ns-resize';
77
83
  }
78
84
  else if (Util._inRange(angle, 225 - 22.5, 225 + 22.5)) {
85
+ // BOTTOM - LEFT
79
86
  return 'nesw-resize';
80
87
  }
81
88
  else if (Util._inRange(angle, 270 - 22.5, 270 + 22.5)) {
89
+ // RIGHT
82
90
  return 'ew-resize';
83
91
  }
84
92
  else if (Util._inRange(angle, 315 - 22.5, 315 + 22.5)) {
93
+ // BOTTOM - RIGHT
85
94
  return 'nwse-resize';
86
95
  }
87
96
  else {
97
+ // how can we can there?
88
98
  Util.error('Transformer has unknown angle for cursor detection: ' + angle);
89
99
  return 'pointer';
90
100
  }
@@ -140,24 +150,95 @@ function getSnap(snaps, newRotationRad, tol) {
140
150
  }
141
151
  return snapped;
142
152
  }
143
- let activeTransformersCount = 0;
153
+ const activeTransformers = new Set();
154
+ /**
155
+ * Transformer constructor. Transformer is a special type of group that allow you transform Konva
156
+ * primitives and shapes. Transforming tool is not changing `width` and `height` properties of nodes
157
+ * when you resize them. Instead it changes `scaleX` and `scaleY` properties.
158
+ * @constructor
159
+ * @memberof Konva
160
+ * @param {Object} config
161
+ * @param {Boolean} [config.resizeEnabled] Default is true
162
+ * @param {Boolean} [config.rotateEnabled] Default is true
163
+ * @param {Boolean} [config.rotateLineVisible] Default is true
164
+ * @param {Array} [config.rotationSnaps] Array of angles for rotation snaps. Default is []
165
+ * @param {Number} [config.rotationSnapTolerance] Snapping tolerance. If closer than this it will snap. Default is 5
166
+ * @param {Number} [config.rotateAnchorOffset] Default is 50
167
+ * @param {Number} [config.rotateAnchorAngle] Angle of the rotate anchor around the box, in degrees. Default is 0 (top)
168
+ * @param {String} [config.rotateAnchorCursor] Default is crosshair
169
+ * @param {Number} [config.padding] Default is 0
170
+ * @param {Boolean} [config.borderEnabled] Should we draw border? Default is true
171
+ * @param {String} [config.borderStroke] Border stroke color
172
+ * @param {Number} [config.borderStrokeWidth] Border stroke size
173
+ * @param {Array} [config.borderDash] Array for border dash.
174
+ * @param {String} [config.anchorFill] Anchor fill color
175
+ * @param {String} [config.anchorStroke] Anchor stroke color
176
+ * @param {Number} [config.anchorCornerRadius] Anchor corner radius
177
+ * @param {Number} [config.anchorStrokeWidth] Anchor stroke size
178
+ * @param {Number} [config.anchorSize] Default is 10
179
+ * @param {Boolean} [config.keepRatio] Should we keep ratio when we are moving edges? Default is true
180
+ * @param {String} [config.shiftBehavior] How does transformer react on shift key press when we are moving edges? Default is 'default'
181
+ * @param {Boolean} [config.centeredScaling] Should we resize relative to node's center? Default is false
182
+ * @param {Array} [config.enabledAnchors] Array of names of enabled handles
183
+ * @param {Boolean} [config.flipEnabled] Can we flip/mirror shape on transform?. True by default
184
+ * @param {Function} [config.boundBoxFunc] Bounding box function, see {@link Konva.Transformer#boundBoxFunc}
185
+ * @param {Function} [config.anchorDragBoundFunc] Function bounding the position of a dragged anchor, see {@link Konva.Transformer#anchorDragBoundFunc}
186
+ * @param {Function} [config.anchorStyleFunc] Function styling every anchor, see {@link Konva.Transformer#anchorStyleFunc}
187
+ * @param {Boolean} [config.ignoreStroke] Should we ignore stroke size? Default is false
188
+ * @param {Boolean} [config.useSingleNodeRotation] When just one node attached, should we use its rotation for transformer?
189
+ * @param {Boolean} [config.shouldOverdrawWholeArea] Should we fill whole transformer area with fake transparent shape to enable dragging from empty spaces?
190
+ * @example
191
+ * var transformer = new Konva.Transformer({
192
+ * nodes: [rectangle],
193
+ * rotateAnchorOffset: 60,
194
+ * enabledAnchors: ['top-left', 'top-right', 'bottom-left', 'bottom-right']
195
+ * });
196
+ * layer.add(transformer);
197
+ */
144
198
  export class Transformer extends Group {
199
+ // the hit graph of a layer is not drawn while a transformer on it, or of
200
+ // a node on it, is transforming (see Layer.shouldDrawHit)
201
+ static _isLayerTransforming(layer) {
202
+ for (const tr of activeTransformers) {
203
+ if (tr.getLayer() === layer ||
204
+ tr._nodes.some((node) => node.getLayer() === layer)) {
205
+ return true;
206
+ }
207
+ }
208
+ return false;
209
+ }
145
210
  constructor(config) {
211
+ // call super constructor
146
212
  super(config);
147
213
  this._movingAnchorName = null;
214
+ this._anchors = {};
148
215
  this._transforming = false;
216
+ // true while _fitNodesInto writes the new attrs into the nodes
217
+ this._fitting = false;
218
+ // the window the transform events are listened to. The stage may be
219
+ // rendered in another window than the one Konva was imported into
149
220
  this._transformWindow = null;
150
221
  this._elementsCreated = false;
151
222
  this._updateScheduled = false;
152
223
  this._createElements();
224
+ // bindings
153
225
  this._handleMouseMove = this._handleMouseMove.bind(this);
154
226
  this._handleMouseUp = this._handleMouseUp.bind(this);
155
227
  this.update = this.update.bind(this);
228
+ // update transformer data for certain attr changes
156
229
  this.on(ATTR_CHANGE_LIST, this.update);
157
230
  if (this.getNode()) {
158
231
  this.update();
159
232
  }
160
233
  }
234
+ /**
235
+ * alias to `tr.nodes([shape])`/ This method is deprecated and will be removed soon.
236
+ * @method
237
+ * @name Konva.Transformer#attachTo
238
+ * @returns {Konva.Transformer}
239
+ * @example
240
+ * transformer.attachTo(shape);
241
+ */
161
242
  attachTo(node) {
162
243
  this.setNode(node);
163
244
  return this;
@@ -177,6 +258,7 @@ export class Transformer extends Group {
177
258
  this.detach();
178
259
  }
179
260
  const filteredNodes = nodes.filter((node) => {
261
+ // check if ancestor of the transformer
180
262
  if (node.isAncestorOf(this)) {
181
263
  Util.error('Konva.Transformer cannot be an a child of the node you are trying to attach');
182
264
  return false;
@@ -192,13 +274,22 @@ export class Transformer extends Group {
192
274
  }
193
275
  this._nodes.forEach((node) => {
194
276
  const onChange = () => {
195
- if (this._transforming)
277
+ // Perf: skip the changes _fitNodesInto makes itself — it does the
278
+ // final _resetTransformCache + update, so per-attr fan-out here is
279
+ // pure waste (was O(N*events) per resize step). A change made between
280
+ // two pointer moves (e.g. a deferred state update) must get through.
281
+ if (this._fitting)
196
282
  return;
197
283
  if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
198
284
  this.rotation(this.nodes()[0].getAbsoluteRotation());
199
285
  }
286
+ // Cache reset stays synchronous so sync reads of tr.x() etc. are fresh.
200
287
  this._resetTransformCache();
201
288
  if (!this.isDragging()) {
289
+ // Perf: an ancestor cascade (e.g. stage drag) fires
290
+ // absoluteTransformChange on every attached node — without batching,
291
+ // update() runs once per node and each call walks all N nodes via
292
+ // __getNodeRect, giving O(N^2) per drag frame.
202
293
  this._scheduleUpdate();
203
294
  }
204
295
  };
@@ -210,11 +301,16 @@ export class Transformer extends Group {
210
301
  }
211
302
  node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
212
303
  node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
304
+ node.on(`destroy.${this._getEventNamespace()}`, () => {
305
+ // a destroyed node has nothing left to transform
306
+ this.setNodes(this._nodes.filter((n) => n !== node));
307
+ });
213
308
  this._proxyDrag(node);
214
309
  });
215
310
  this._resetTransformCache();
216
- const elementsCreated = !!this.findOne('.top-left');
217
- if (elementsCreated) {
311
+ // we may need it if we set node in initial props
312
+ // so elements are not defined yet
313
+ if (this._elementsCreated) {
218
314
  this.update();
219
315
  }
220
316
  return this;
@@ -223,7 +319,9 @@ export class Transformer extends Group {
223
319
  let lastPos;
224
320
  node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
225
321
  lastPos = node.getAbsolutePosition();
226
- if (!this.isDragging() && node !== this.findOne('.back')) {
322
+ // actual dragging of Transformer doesn't make sense
323
+ // but we need to make sure it also has all drag events
324
+ if (!this.isDragging() && node !== this._back) {
227
325
  this.startDrag(e, false);
228
326
  }
229
327
  });
@@ -254,10 +352,27 @@ export class Transformer extends Group {
254
352
  getNodes() {
255
353
  return this._nodes || [];
256
354
  }
355
+ /**
356
+ * return the name of current active anchor
357
+ * @method
358
+ * @name Konva.Transformer#getActiveAnchor
359
+ * @returns {String | Null}
360
+ * @example
361
+ * transformer.getActiveAnchor();
362
+ */
257
363
  getActiveAnchor() {
258
364
  return this._movingAnchorName;
259
365
  }
366
+ /**
367
+ * detach transformer from an attached node
368
+ * @method
369
+ * @name Konva.Transformer#detach
370
+ * @returns {Konva.Transformer}
371
+ * @example
372
+ * transformer.detach();
373
+ */
260
374
  detach() {
375
+ // remove events
261
376
  if (this._nodes) {
262
377
  this._nodes.forEach((node) => {
263
378
  node.off('.' + this._getEventNamespace());
@@ -266,6 +381,19 @@ export class Transformer extends Group {
266
381
  this._nodes = [];
267
382
  this._resetTransformCache();
268
383
  }
384
+ /**
385
+ * bind events to the Transformer. You can use events: `transform`, `transformstart`, `transformend`, `dragstart`, `dragmove`, `dragend`
386
+ * @method
387
+ * @name Konva.Transformer#on
388
+ * @param {String} evtStr e.g. 'transform'
389
+ * @param {Function} handler The handler function. The first argument of that function is event object. Event object has `target` as main target of the event, `currentTarget` as current node listener and `evt` as native browser event.
390
+ * @returns {Konva.Transformer}
391
+ * @example
392
+ * // add click listener
393
+ * tr.on('transformstart', function() {
394
+ * console.log('transform started');
395
+ * });
396
+ */
269
397
  _resetTransformCache() {
270
398
  this._clearCache(NODES_RECT);
271
399
  this._clearCache('transform');
@@ -274,30 +402,6 @@ export class Transformer extends Group {
274
402
  _getNodeRect() {
275
403
  return this._getCache(NODES_RECT, this.__getNodeRect);
276
404
  }
277
- __getNodeShape(node, rot = this.rotation(), relative) {
278
- const rect = node.getClientRect({
279
- skipTransform: true,
280
- skipShadow: true,
281
- skipStroke: this.ignoreStroke(),
282
- });
283
- const absScale = node.getAbsoluteScale(relative);
284
- const absPos = node.getAbsolutePosition(relative);
285
- const dx = rect.x * absScale.x - node.offsetX() * absScale.x;
286
- const dy = rect.y * absScale.y - node.offsetY() * absScale.y;
287
- const rotation = (Konva.getAngle(node.getAbsoluteRotation()) + Math.PI * 2) %
288
- (Math.PI * 2);
289
- const box = {
290
- x: absPos.x + dx * Math.cos(rotation) + dy * Math.sin(-rotation),
291
- y: absPos.y + dy * Math.cos(rotation) + dx * Math.sin(rotation),
292
- width: rect.width * absScale.x,
293
- height: rect.height * absScale.y,
294
- rotation: rotation,
295
- };
296
- return rotateAroundPoint(box, -Konva.getAngle(rot), {
297
- x: 0,
298
- y: 0,
299
- });
300
- }
301
405
  __getNodeRect() {
302
406
  const node = this.getNode();
303
407
  if (!node) {
@@ -333,10 +437,6 @@ export class Transformer extends Group {
333
437
  let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
334
438
  totalPoints.forEach(function (point) {
335
439
  const transformed = tr.point(point);
336
- if (minX === undefined) {
337
- minX = maxX = transformed.x;
338
- minY = maxY = transformed.y;
339
- }
340
440
  minX = Math.min(minX, transformed.x);
341
441
  minY = Math.min(minY, transformed.y);
342
442
  maxX = Math.max(maxX, transformed.x);
@@ -379,9 +479,12 @@ export class Transformer extends Group {
379
479
  strokeWidth: 1,
380
480
  name: name + ' _anchor',
381
481
  dragDistance: 0,
482
+ // make it draggable,
483
+ // so activating the anchor will not start drag&drop of any parent
382
484
  draggable: true,
383
485
  hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto',
384
486
  });
487
+ this._anchors[name] = anchor;
385
488
  const self = this;
386
489
  anchor.on('mousedown touchstart', function (e) {
387
490
  self._handleMouseDown(e);
@@ -393,6 +496,7 @@ export class Transformer extends Group {
393
496
  anchor.on('dragend', (e) => {
394
497
  e.cancelBubble = true;
395
498
  });
499
+ // add hover styling
396
500
  anchor.on('mouseenter', () => {
397
501
  const rad = Konva.getAngle(this.rotation());
398
502
  const rotateCursor = this.rotateAnchorCursor();
@@ -421,13 +525,17 @@ export class Transformer extends Group {
421
525
  ctx.beginPath();
422
526
  ctx.rect(-padding, -padding, width + padding * 2, height + padding * 2);
423
527
  if (tr.rotateEnabled() && tr.rotateLineVisible()) {
528
+ // Calculate rotation line position based on rotateAnchorAngle
424
529
  const rotateAnchorAngle = tr.rotateAnchorAngle();
425
530
  const rotateAnchorOffset = tr.rotateAnchorOffset();
426
531
  const rad = Util.degToRad(rotateAnchorAngle);
532
+ // Direction vector (0 degrees = up/top)
427
533
  const dirX = Math.sin(rad);
428
534
  const dirY = -Math.cos(rad);
535
+ // Center of the box
429
536
  const cx = width / 2;
430
537
  const cy = height / 2;
538
+ // Find intersection with box edge
431
539
  let t = Infinity;
432
540
  if (dirY < 0) {
433
541
  t = Math.min(t, -cy / dirY);
@@ -441,8 +549,10 @@ export class Transformer extends Group {
441
549
  else if (dirX > 0) {
442
550
  t = Math.min(t, (width - cx) / dirX);
443
551
  }
552
+ // Edge point (start of line)
444
553
  const edgeX = cx + dirX * t;
445
554
  const edgeY = cy + dirY * t;
555
+ // End point with offset
446
556
  const sign = Util._sign(height);
447
557
  const endX = edgeX + dirX * rotateAnchorOffset * sign;
448
558
  const endY = edgeY + dirY * rotateAnchorOffset * sign;
@@ -461,8 +571,12 @@ export class Transformer extends Group {
461
571
  ctx.fillStrokeShape(shape);
462
572
  },
463
573
  });
574
+ this._back = back;
464
575
  this.add(back);
465
576
  this._proxyDrag(back);
577
+ // do not bubble drag from the back shape
578
+ // because we already "drag" whole transformer
579
+ // so we don't want to trigger drag twice on transformer
466
580
  back.on('dragstart', (e) => {
467
581
  e.cancelBubble = true;
468
582
  });
@@ -472,12 +586,15 @@ export class Transformer extends Group {
472
586
  back.on('dragend', (e) => {
473
587
  e.cancelBubble = true;
474
588
  });
589
+ // force self update when we drag with shouldOverDrawWholeArea setting
475
590
  this.on('dragmove', (e) => {
476
591
  this.update();
477
592
  });
478
593
  }
479
594
  _handleMouseDown(e) {
480
- var _a;
595
+ var _a, _b;
596
+ // do nothing if we already transforming
597
+ // that is possible to trigger with multitouch
481
598
  if (this._transforming) {
482
599
  return;
483
600
  }
@@ -488,6 +605,7 @@ export class Transformer extends Group {
488
605
  const hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
489
606
  this.sin = Math.abs(height / hypotenuse);
490
607
  this.cos = Math.abs(width / hypotenuse);
608
+ // the window that owns the stage is the one that gets the pointer events
491
609
  const win = (_a = this.getStage()) === null || _a === void 0 ? void 0 : _a._getOwnerWindow();
492
610
  this._transformWindow = win || null;
493
611
  if (win) {
@@ -497,13 +615,15 @@ export class Transformer extends Group {
497
615
  win.addEventListener('touchend', this._handleMouseUp, true);
498
616
  }
499
617
  this._transforming = true;
618
+ // the pointer that hit the anchor (a touchstart can land several fingers)
619
+ this._pointerId = (_b = e.pointerId) !== null && _b !== void 0 ? _b : Util._getFirstPointerId(e.evt);
500
620
  const ap = e.target.getAbsolutePosition();
501
- const pos = e.target.getStage().getPointerPosition();
621
+ const pos = e.target.getStage()._getPointerById(this._pointerId);
502
622
  this._anchorDragOffset = {
503
623
  x: pos.x - ap.x,
504
624
  y: pos.y - ap.y,
505
625
  };
506
- activeTransformersCount++;
626
+ activeTransformers.add(this);
507
627
  this._fire('transformstart', { evt: e.evt, target: this.getNode() });
508
628
  this._nodes.forEach((target) => {
509
629
  target._fire('transformstart', { evt: e.evt, target });
@@ -511,10 +631,13 @@ export class Transformer extends Group {
511
631
  }
512
632
  _handleMouseMove(e) {
513
633
  let x, y, newHypotenuse;
514
- const anchorNode = this.findOne('.' + this._movingAnchorName);
634
+ const anchorNode = this._anchors[this._movingAnchorName];
515
635
  const stage = anchorNode.getStage();
516
636
  stage.setPointersPositions(e);
517
- const pp = stage.getPointerPosition();
637
+ const pp = stage._getPointerById(this._pointerId);
638
+ if (!pp) {
639
+ return;
640
+ }
518
641
  let newNodePos = {
519
642
  x: pp.x - this._anchorDragOffset.x,
520
643
  y: pp.y - this._anchorDragOffset.y,
@@ -525,13 +648,17 @@ export class Transformer extends Group {
525
648
  }
526
649
  anchorNode.setAbsolutePosition(newNodePos);
527
650
  const newAbs = anchorNode.getAbsolutePosition();
651
+ // console.log(oldAbs, newNodePos, newAbs);
528
652
  if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
529
653
  return;
530
654
  }
655
+ // rotater is working very differently, so do it first
531
656
  if (this._movingAnchorName === 'rotater') {
532
657
  const attrs = this._getNodeRect();
533
658
  x = anchorNode.x() - attrs.width / 2;
534
659
  y = -anchorNode.y() + attrs.height / 2;
660
+ // Calculate angle from center to current anchor position
661
+ // Offset by rotateAnchorAngle so we measure rotation from the anchor's starting position
535
662
  const rotateAnchorAngleRad = Konva.getAngle(this.rotateAnchorAngle());
536
663
  let delta = Math.atan2(-y, x) + Math.PI / 2 - rotateAnchorAngleRad;
537
664
  if (attrs.height < 0) {
@@ -558,6 +685,9 @@ export class Transformer extends Group {
558
685
  keepProportion = this.keepRatio() || e.shiftKey;
559
686
  }
560
687
  let centeredScaling = this.centeredScaling() || e.altKey;
688
+ // with keepRatio, a corner anchor doesn't follow the pointer — the blocks
689
+ // below project it onto the ratio diagonal. _doFitNodesInto must know
690
+ // that to skip the padding flip compensation (issue #1878)
561
691
  let anchorProjected = false;
562
692
  if (this._movingAnchorName === 'top-left') {
563
693
  if (keepProportion) {
@@ -568,21 +698,21 @@ export class Transformer extends Group {
568
698
  y: this.height() / 2,
569
699
  }
570
700
  : {
571
- x: this.findOne('.bottom-right').x(),
572
- y: this.findOne('.bottom-right').y(),
701
+ x: this._anchors['bottom-right'].x(),
702
+ y: this._anchors['bottom-right'].y(),
573
703
  };
574
704
  newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
575
705
  Math.pow(comparePoint.y - anchorNode.y(), 2));
576
- const reverseX = this.findOne('.top-left').x() > comparePoint.x ? -1 : 1;
577
- const reverseY = this.findOne('.top-left').y() > comparePoint.y ? -1 : 1;
706
+ const reverseX = this._anchors['top-left'].x() > comparePoint.x ? -1 : 1;
707
+ const reverseY = this._anchors['top-left'].y() > comparePoint.y ? -1 : 1;
578
708
  x = newHypotenuse * this.cos * reverseX;
579
709
  y = newHypotenuse * this.sin * reverseY;
580
- this.findOne('.top-left').x(comparePoint.x - x);
581
- this.findOne('.top-left').y(comparePoint.y - y);
710
+ this._anchors['top-left'].x(comparePoint.x - x);
711
+ this._anchors['top-left'].y(comparePoint.y - y);
582
712
  }
583
713
  }
584
714
  else if (this._movingAnchorName === 'top-center') {
585
- this.findOne('.top-left').y(anchorNode.y());
715
+ this._anchors['top-left'].y(anchorNode.y());
586
716
  }
587
717
  else if (this._movingAnchorName === 'top-right') {
588
718
  if (keepProportion) {
@@ -593,27 +723,27 @@ export class Transformer extends Group {
593
723
  y: this.height() / 2,
594
724
  }
595
725
  : {
596
- x: this.findOne('.bottom-left').x(),
597
- y: this.findOne('.bottom-left').y(),
726
+ x: this._anchors['bottom-left'].x(),
727
+ y: this._anchors['bottom-left'].y(),
598
728
  };
599
729
  newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
600
730
  Math.pow(comparePoint.y - anchorNode.y(), 2));
601
- const reverseX = this.findOne('.top-right').x() < comparePoint.x ? -1 : 1;
602
- const reverseY = this.findOne('.top-right').y() > comparePoint.y ? -1 : 1;
731
+ const reverseX = this._anchors['top-right'].x() < comparePoint.x ? -1 : 1;
732
+ const reverseY = this._anchors['top-right'].y() > comparePoint.y ? -1 : 1;
603
733
  x = newHypotenuse * this.cos * reverseX;
604
734
  y = newHypotenuse * this.sin * reverseY;
605
- this.findOne('.top-right').x(comparePoint.x + x);
606
- this.findOne('.top-right').y(comparePoint.y - y);
735
+ this._anchors['top-right'].x(comparePoint.x + x);
736
+ this._anchors['top-right'].y(comparePoint.y - y);
607
737
  }
608
738
  var pos = anchorNode.position();
609
- this.findOne('.top-left').y(pos.y);
610
- this.findOne('.bottom-right').x(pos.x);
739
+ this._anchors['top-left'].y(pos.y);
740
+ this._anchors['bottom-right'].x(pos.x);
611
741
  }
612
742
  else if (this._movingAnchorName === 'middle-left') {
613
- this.findOne('.top-left').x(anchorNode.x());
743
+ this._anchors['top-left'].x(anchorNode.x());
614
744
  }
615
745
  else if (this._movingAnchorName === 'middle-right') {
616
- this.findOne('.bottom-right').x(anchorNode.x());
746
+ this._anchors['bottom-right'].x(anchorNode.x());
617
747
  }
618
748
  else if (this._movingAnchorName === 'bottom-left') {
619
749
  if (keepProportion) {
@@ -624,8 +754,8 @@ export class Transformer extends Group {
624
754
  y: this.height() / 2,
625
755
  }
626
756
  : {
627
- x: this.findOne('.top-right').x(),
628
- y: this.findOne('.top-right').y(),
757
+ x: this._anchors['top-right'].x(),
758
+ y: this._anchors['top-right'].y(),
629
759
  };
630
760
  newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
631
761
  Math.pow(anchorNode.y() - comparePoint.y, 2));
@@ -637,11 +767,11 @@ export class Transformer extends Group {
637
767
  anchorNode.y(comparePoint.y + y);
638
768
  }
639
769
  pos = anchorNode.position();
640
- this.findOne('.top-left').x(pos.x);
641
- this.findOne('.bottom-right').y(pos.y);
770
+ this._anchors['top-left'].x(pos.x);
771
+ this._anchors['bottom-right'].y(pos.y);
642
772
  }
643
773
  else if (this._movingAnchorName === 'bottom-center') {
644
- this.findOne('.bottom-right').y(anchorNode.y());
774
+ this._anchors['bottom-right'].y(anchorNode.y());
645
775
  }
646
776
  else if (this._movingAnchorName === 'bottom-right') {
647
777
  if (keepProportion) {
@@ -652,17 +782,17 @@ export class Transformer extends Group {
652
782
  y: this.height() / 2,
653
783
  }
654
784
  : {
655
- x: this.findOne('.top-left').x(),
656
- y: this.findOne('.top-left').y(),
785
+ x: this._anchors['top-left'].x(),
786
+ y: this._anchors['top-left'].y(),
657
787
  };
658
788
  newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
659
789
  Math.pow(anchorNode.y() - comparePoint.y, 2));
660
- const reverseX = this.findOne('.bottom-right').x() < comparePoint.x ? -1 : 1;
661
- const reverseY = this.findOne('.bottom-right').y() < comparePoint.y ? -1 : 1;
790
+ const reverseX = this._anchors['bottom-right'].x() < comparePoint.x ? -1 : 1;
791
+ const reverseY = this._anchors['bottom-right'].y() < comparePoint.y ? -1 : 1;
662
792
  x = newHypotenuse * this.cos * reverseX;
663
793
  y = newHypotenuse * this.sin * reverseY;
664
- this.findOne('.bottom-right').x(comparePoint.x + x);
665
- this.findOne('.bottom-right').y(comparePoint.y + y);
794
+ this._anchors['bottom-right'].x(comparePoint.x + x);
795
+ this._anchors['bottom-right'].y(comparePoint.y + y);
666
796
  }
667
797
  }
668
798
  else {
@@ -671,8 +801,8 @@ export class Transformer extends Group {
671
801
  }
672
802
  centeredScaling = this.centeredScaling() || e.altKey;
673
803
  if (centeredScaling) {
674
- const topLeft = this.findOne('.top-left');
675
- const bottomRight = this.findOne('.bottom-right');
804
+ const topLeft = this._anchors['top-left'];
805
+ const bottomRight = this._anchors['bottom-right'];
676
806
  const topOffsetX = topLeft.x();
677
807
  const topOffsetY = topLeft.y();
678
808
  const bottomOffsetX = this.getWidth() - bottomRight.x();
@@ -686,11 +816,11 @@ export class Transformer extends Group {
686
816
  y: bottomOffsetY,
687
817
  });
688
818
  }
689
- const absPos = this.findOne('.top-left').getAbsolutePosition();
819
+ const absPos = this._anchors['top-left'].getAbsolutePosition();
690
820
  x = absPos.x;
691
821
  y = absPos.y;
692
- const width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();
693
- const height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
822
+ const width = this._anchors['bottom-right'].x() - this._anchors['top-left'].x();
823
+ const height = this._anchors['bottom-right'].y() - this._anchors['top-left'].y();
694
824
  this._fitNodesInto({
695
825
  x: x,
696
826
  y: y,
@@ -700,10 +830,21 @@ export class Transformer extends Group {
700
830
  }, e, anchorProjected);
701
831
  }
702
832
  _handleMouseUp(e) {
833
+ // only the pointer that grabbed the anchor ends the transform
834
+ const stage = this.getStage();
835
+ if (stage) {
836
+ stage.setPointersPositions(e);
837
+ if (!stage._changedPointerPositions.some((p) => p.id === this._pointerId)) {
838
+ return;
839
+ }
840
+ }
703
841
  this._removeEvents(e);
704
842
  }
705
- getAbsoluteTransform() {
706
- return this.getTransform();
843
+ // the transformer positions itself in absolute coordinates (see
844
+ // _getNodeRect), whatever the transforms of its ancestors are
845
+ getAbsoluteTransform(top) {
846
+ const at = this.getTransform();
847
+ return top ? top.getAbsoluteTransform().copy().invert().multiply(at) : at;
707
848
  }
708
849
  _removeEvents(e) {
709
850
  var _a;
@@ -718,13 +859,15 @@ export class Transformer extends Group {
718
859
  win.removeEventListener('touchend', this._handleMouseUp, true);
719
860
  }
720
861
  const node = this.getNode();
721
- activeTransformersCount--;
862
+ activeTransformers.delete(this);
722
863
  this._fire('transformend', { evt: e, target: node });
864
+ // redraw layer to restore hit graph
723
865
  (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
724
866
  if (node) {
725
867
  this._nodes.forEach((target) => {
726
868
  var _a;
727
869
  target._fire('transformend', { evt: e, target });
870
+ // redraw layer to restore hit graph
728
871
  (_a = target.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
729
872
  });
730
873
  }
@@ -732,28 +875,39 @@ export class Transformer extends Group {
732
875
  }
733
876
  }
734
877
  _fitNodesInto(newAttrs, evt, anchorProjected = false) {
878
+ // Perf: suspend autoDraw for the whole method so per-attr _setAttr writes
879
+ // don't each trigger _requestDraw -> getLayer parent-chain walks.
880
+ // batchDraw per affected layer is issued at the end.
735
881
  const prevAutoDraw = Konva.autoDrawEnabled;
736
882
  Konva.autoDrawEnabled = false;
883
+ this._fitting = true;
737
884
  try {
738
885
  return this._doFitNodesInto(newAttrs, evt, anchorProjected);
739
886
  }
740
887
  finally {
741
888
  Konva.autoDrawEnabled = prevAutoDraw;
889
+ this._fitting = false;
742
890
  }
743
891
  }
744
892
  _doFitNodesInto(newAttrs, evt, anchorProjected = false) {
745
893
  const oldAttrs = this._getNodeRect();
746
894
  const minSize = 1;
747
- if (Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) {
748
- this.update();
749
- return;
750
- }
751
- if (Util._inRange(newAttrs.height, -this.padding() * 2 - minSize, minSize)) {
895
+ // a zero-size box has a singular transform, there is nothing to scale from
896
+ if (!oldAttrs.width ||
897
+ !oldAttrs.height ||
898
+ Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize) ||
899
+ Util._inRange(newAttrs.height, -this.padding() * 2 - minSize, minSize)) {
752
900
  this.update();
753
901
  return;
754
902
  }
755
903
  const t = new Transform();
756
904
  t.rotate(Konva.getAngle(this.rotation()));
905
+ // the ±2*padding shifts below assume the box size passed through zero
906
+ // continuously (the anchor tied to the pointer). A projected anchor snaps
907
+ // the box across zero instead; the shifts then leave the drag state
908
+ // inconsistent with the real anchor position and the box flips back and
909
+ // forth on every following move (issue #1878) — so flip only the anchor
910
+ // name, exactly as when padding is 0.
757
911
  const flipPadding = anchorProjected ? 0 : this.padding() * 2;
758
912
  let widthFlip = null;
759
913
  let heightFlip = null;
@@ -810,6 +964,8 @@ export class Transformer extends Group {
810
964
  Util.warn('boundBoxFunc returned falsy. You should return new bound rect from it!');
811
965
  }
812
966
  }
967
+ // a staged flip survived only if the bounded size is still negative on
968
+ // its axis
813
969
  for (const flip of [widthFlip, heightFlip]) {
814
970
  if (flip && newAttrs[flip.axis] < 0 && this._movingAnchorName) {
815
971
  this._movingAnchorName = this._movingAnchorName.replace(flip.from, flip.to);
@@ -817,6 +973,10 @@ export class Transformer extends Group {
817
973
  this._anchorDragOffset.y -= flip.offset.y;
818
974
  }
819
975
  }
976
+ // base size value doesn't really matter
977
+ // we just need to think about bounding boxes as transforms
978
+ // but how?
979
+ // the idea is that we have a transformed rectangle with the size of "baseSize"
820
980
  const baseSize = 10000000;
821
981
  const oldTr = new Transform();
822
982
  oldTr.translate(oldAttrs.x, oldAttrs.y);
@@ -836,14 +996,35 @@ export class Transformer extends Group {
836
996
  newTr.rotate(newAttrs.rotation);
837
997
  newTr.scale(newScaleX, newScaleY);
838
998
  }
999
+ // now lets think we had [old transform] and n ow we have [new transform]
1000
+ // Now, the questions is: how can we transform "parent" to go from [old transform] into [new transform]
1001
+ // in equation it will be:
1002
+ // [delta transform] * [old transform] = [new transform]
1003
+ // that means that
1004
+ // [delta transform] = [new transform] * [old transform inverted]
839
1005
  const delta = newTr.multiply(oldTr.invert());
1006
+ // Perf: collect unique affected layers and batchDraw each once at the end
1007
+ // (was once per node — O(N)).
840
1008
  const layersToDraw = new Set();
841
1009
  this._nodes.forEach((node) => {
1010
+ // check to close this issue: https://github.com/konvajs/konva/issues/1957
1011
+ // a node can be destroyed during the transformation
1012
+ // probably a developer must remove it from transformer
842
1013
  if (!node.getStage()) {
1014
+ // do we need a helping message?
1015
+ // Util.error(
1016
+ // 'Node is not attached to the stage. This is not allowed. Please attach the node to the stage before transforming. If node was destroyed, make sure to remove it from transformer.'
1017
+ // );
843
1018
  return;
844
1019
  }
1020
+ // for each node we have the same [delta transform]
1021
+ // the equations is
1022
+ // [delta transform] * [parent transform] * [old local transform] = [parent transform] * [new local transform]
1023
+ // and we need to find [new local transform]
1024
+ // [new local] = [parent inverted] * [delta] * [parent] * [old local]
845
1025
  const parentTransform = node.getParent().getAbsoluteTransform();
846
1026
  const localTransform = node.getTransform().copy();
1027
+ // skip offset:
847
1028
  localTransform.translate(node.offsetX(), node.offsetY());
848
1029
  const newLocalTransform = new Transform();
849
1030
  newLocalTransform
@@ -859,6 +1040,7 @@ export class Transformer extends Group {
859
1040
  }
860
1041
  });
861
1042
  this.rotation(Util._getRotation(newAttrs.rotation));
1043
+ // trigger transform event AFTER we update rotation
862
1044
  this._nodes.forEach((node) => {
863
1045
  this._fire('transform', { evt: evt, target: node });
864
1046
  node._fire('transform', { evt: evt, target: node });
@@ -868,6 +1050,9 @@ export class Transformer extends Group {
868
1050
  layersToDraw.add(this.getLayer());
869
1051
  layersToDraw.forEach((layer) => layer && layer.batchDraw());
870
1052
  }
1053
+ // Inside an absoluteTransform cascade, queue a single update to run when
1054
+ // the cascade ends; outside a cascade, run synchronously so reads of
1055
+ // transformer state stay consistent.
871
1056
  _scheduleUpdate() {
872
1057
  if (this._updateScheduled)
873
1058
  return;
@@ -875,20 +1060,22 @@ export class Transformer extends Group {
875
1060
  Node._runAfterAbsTransformCascade(() => {
876
1061
  var _a;
877
1062
  this._updateScheduled = false;
878
- if (!((_a = this._nodes) === null || _a === void 0 ? void 0 : _a.length) || this._transforming || this.isDragging()) {
1063
+ if (!((_a = this._nodes) === null || _a === void 0 ? void 0 : _a.length) || this._fitting || this.isDragging()) {
879
1064
  return;
880
1065
  }
881
1066
  this.update();
882
1067
  });
883
1068
  }
1069
+ /**
1070
+ * force update of Konva.Transformer.
1071
+ * Use it when you updated attached Konva.Group and now you need to reset transformer size
1072
+ * @method
1073
+ * @name Konva.Transformer#forceUpdate
1074
+ */
884
1075
  forceUpdate() {
885
1076
  this._resetTransformCache();
886
1077
  this.update();
887
1078
  }
888
- _batchChangeChild(selector, attrs) {
889
- const anchor = this.findOne(selector);
890
- anchor.setAttrs(attrs);
891
- }
892
1079
  update() {
893
1080
  var _a;
894
1081
  const attrs = this._getNodeRect();
@@ -899,7 +1086,7 @@ export class Transformer extends Group {
899
1086
  const resizeEnabled = this.resizeEnabled();
900
1087
  const padding = this.padding();
901
1088
  const anchorSize = this.anchorSize();
902
- const anchors = this.find('._anchor');
1089
+ const anchors = Object.values(this._anchors);
903
1090
  anchors.forEach((node) => {
904
1091
  node.setAttrs({
905
1092
  width: anchorSize,
@@ -912,87 +1099,99 @@ export class Transformer extends Group {
912
1099
  cornerRadius: this.anchorCornerRadius(),
913
1100
  });
914
1101
  });
915
- this._batchChangeChild('.top-left', {
1102
+ this._anchors['top-left'].setAttrs({
916
1103
  x: 0,
917
1104
  y: 0,
918
1105
  offsetX: anchorSize / 2 + padding,
919
1106
  offsetY: anchorSize / 2 + padding,
920
1107
  visible: resizeEnabled && enabledAnchors.indexOf('top-left') >= 0,
921
1108
  });
922
- this._batchChangeChild('.top-center', {
1109
+ this._anchors['top-center'].setAttrs({
923
1110
  x: width / 2,
924
1111
  y: 0,
925
1112
  offsetY: anchorSize / 2 + padding,
926
1113
  visible: resizeEnabled && enabledAnchors.indexOf('top-center') >= 0,
927
1114
  });
928
- this._batchChangeChild('.top-right', {
1115
+ this._anchors['top-right'].setAttrs({
929
1116
  x: width,
930
1117
  y: 0,
931
1118
  offsetX: anchorSize / 2 - padding,
932
1119
  offsetY: anchorSize / 2 + padding,
933
1120
  visible: resizeEnabled && enabledAnchors.indexOf('top-right') >= 0,
934
1121
  });
935
- this._batchChangeChild('.middle-left', {
1122
+ this._anchors['middle-left'].setAttrs({
936
1123
  x: 0,
937
1124
  y: height / 2,
938
1125
  offsetX: anchorSize / 2 + padding,
939
1126
  visible: resizeEnabled && enabledAnchors.indexOf('middle-left') >= 0,
940
1127
  });
941
- this._batchChangeChild('.middle-right', {
1128
+ this._anchors['middle-right'].setAttrs({
942
1129
  x: width,
943
1130
  y: height / 2,
944
1131
  offsetX: anchorSize / 2 - padding,
945
1132
  visible: resizeEnabled && enabledAnchors.indexOf('middle-right') >= 0,
946
1133
  });
947
- this._batchChangeChild('.bottom-left', {
1134
+ this._anchors['bottom-left'].setAttrs({
948
1135
  x: 0,
949
1136
  y: height,
950
1137
  offsetX: anchorSize / 2 + padding,
951
1138
  offsetY: anchorSize / 2 - padding,
952
1139
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-left') >= 0,
953
1140
  });
954
- this._batchChangeChild('.bottom-center', {
1141
+ this._anchors['bottom-center'].setAttrs({
955
1142
  x: width / 2,
956
1143
  y: height,
957
1144
  offsetY: anchorSize / 2 - padding,
958
1145
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-center') >= 0,
959
1146
  });
960
- this._batchChangeChild('.bottom-right', {
1147
+ this._anchors['bottom-right'].setAttrs({
961
1148
  x: width,
962
1149
  y: height,
963
1150
  offsetX: anchorSize / 2 - padding,
964
1151
  offsetY: anchorSize / 2 - padding,
965
1152
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-right') >= 0,
966
1153
  });
1154
+ // Calculate rotation anchor position based on rotateAnchorAngle
967
1155
  const rotateAnchorAngle = this.rotateAnchorAngle();
968
1156
  const rotateAnchorOffset = this.rotateAnchorOffset();
969
1157
  const rad = Util.degToRad(rotateAnchorAngle);
1158
+ // Direction vector (0 degrees = up/top)
970
1159
  const dirX = Math.sin(rad);
971
1160
  const dirY = -Math.cos(rad);
1161
+ // Center of the box
972
1162
  const cx = width / 2;
973
1163
  const cy = height / 2;
1164
+ // Find intersection with box edge
1165
+ // Calculate time to hit each edge from center
974
1166
  let t = Infinity;
1167
+ // Handle each direction
975
1168
  if (dirY < 0) {
1169
+ // Moving up, check top edge (y = 0)
976
1170
  t = Math.min(t, -cy / dirY);
977
1171
  }
978
1172
  else if (dirY > 0) {
1173
+ // Moving down, check bottom edge (y = height)
979
1174
  t = Math.min(t, (height - cy) / dirY);
980
1175
  }
981
1176
  if (dirX < 0) {
1177
+ // Moving left, check left edge (x = 0)
982
1178
  t = Math.min(t, -cx / dirX);
983
1179
  }
984
1180
  else if (dirX > 0) {
1181
+ // Moving right, check right edge (x = width)
985
1182
  t = Math.min(t, (width - cx) / dirX);
986
1183
  }
1184
+ // Edge point
987
1185
  const edgeX = cx + dirX * t;
988
1186
  const edgeY = cy + dirY * t;
1187
+ // Final position with offset (accounting for height sign and padding)
989
1188
  const sign = Util._sign(height);
990
- this._batchChangeChild('.rotater', {
1189
+ this._anchors['rotater'].setAttrs({
991
1190
  x: edgeX + dirX * rotateAnchorOffset * sign,
992
1191
  y: edgeY + dirY * rotateAnchorOffset * sign - padding * dirY,
993
1192
  visible: this.rotateEnabled(),
994
1193
  });
995
- this._batchChangeChild('.back', {
1194
+ this._back.setAttrs({
996
1195
  width: width,
997
1196
  height: height,
998
1197
  visible: this.borderEnabled(),
@@ -1011,16 +1210,24 @@ export class Transformer extends Group {
1011
1210
  }
1012
1211
  (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
1013
1212
  }
1213
+ /**
1214
+ * determine if transformer is in active transform
1215
+ * @method
1216
+ * @name Konva.Transformer#isTransforming
1217
+ * @returns {Boolean}
1218
+ */
1014
1219
  isTransforming() {
1015
1220
  return this._transforming;
1016
1221
  }
1222
+ /**
1223
+ * Stop active transform action
1224
+ * @method
1225
+ * @name Konva.Transformer#stopTransform
1226
+ * @returns {Boolean}
1227
+ */
1017
1228
  stopTransform() {
1018
1229
  if (this._transforming) {
1019
1230
  this._removeEvents();
1020
- const anchorNode = this.findOne('.' + this._movingAnchorName);
1021
- if (anchorNode) {
1022
- anchorNode.stopDrag();
1023
- }
1024
1231
  }
1025
1232
  }
1026
1233
  destroy() {
@@ -1032,6 +1239,10 @@ export class Transformer extends Group {
1032
1239
  this._removeEvents();
1033
1240
  return this;
1034
1241
  }
1242
+ // Transformer manages its own internal children (anchors, back shape).
1243
+ // Adding external nodes as children can cause infinite recursion because
1244
+ // the Transformer's absoluteTransform depends on nodes' transforms.
1245
+ // Use tr.nodes([node]) to attach nodes instead.
1035
1246
  add(...children) {
1036
1247
  if (this._elementsCreated) {
1037
1248
  Util.error('You cannot add external nodes to the Transformer. Use tr.nodes([node]) instead.');
@@ -1039,24 +1250,29 @@ export class Transformer extends Group {
1039
1250
  }
1040
1251
  return super.add(...children);
1041
1252
  }
1253
+ // do not work as a container
1254
+ // we will recreate inner nodes manually
1042
1255
  toObject() {
1043
1256
  return Node.prototype.toObject.call(this);
1044
1257
  }
1258
+ // overwrite clone to NOT use method from Container
1045
1259
  clone(obj) {
1046
1260
  const node = Node.prototype.clone.call(this, obj);
1047
1261
  return node;
1048
1262
  }
1049
- getClientRect() {
1263
+ getClientRect(config) {
1050
1264
  if (this.nodes().length > 0) {
1051
- return super.getClientRect();
1265
+ return super.getClientRect(config);
1052
1266
  }
1053
1267
  else {
1268
+ // if we are detached return zero size
1269
+ // so it will be skipped in calculations
1054
1270
  return { x: 0, y: 0, width: 0, height: 0 };
1055
1271
  }
1056
1272
  }
1057
1273
  }
1058
1274
  Transformer.isTransforming = () => {
1059
- return activeTransformersCount > 0;
1275
+ return activeTransformers.size > 0;
1060
1276
  };
1061
1277
  function validateAnchors(val) {
1062
1278
  if (!(val instanceof Array)) {
@@ -1076,36 +1292,462 @@ function validateAnchors(val) {
1076
1292
  }
1077
1293
  Transformer.prototype.className = 'Transformer';
1078
1294
  _registerNode(Transformer);
1295
+ /**
1296
+ * get/set enabled handlers
1297
+ * @name Konva.Transformer#enabledAnchors
1298
+ * @method
1299
+ * @param {Array} array
1300
+ * @returns {Array}
1301
+ * @example
1302
+ * // get list of handlers
1303
+ * var enabledAnchors = transformer.enabledAnchors();
1304
+ *
1305
+ * // set handlers
1306
+ * transformer.enabledAnchors(['top-left', 'top-center', 'top-right', 'middle-right', 'middle-left', 'bottom-left', 'bottom-center', 'bottom-right']);
1307
+ */
1079
1308
  Factory.addGetterSetter(Transformer, 'enabledAnchors', ANCHORS_NAMES, validateAnchors);
1309
+ /**
1310
+ * get/set flip enabled
1311
+ * @name Konva.Transformer#flipEnabled
1312
+ * @method
1313
+ * @param {Boolean} flag
1314
+ * @returns {Boolean}
1315
+ * @example
1316
+ * // get flip enabled property
1317
+ * var flipEnabled = transformer.flipEnabled();
1318
+ *
1319
+ * // set flip enabled property
1320
+ * transformer.flipEnabled(false);
1321
+ */
1080
1322
  Factory.addGetterSetter(Transformer, 'flipEnabled', true, getBooleanValidator());
1323
+ /**
1324
+ * get/set resize ability. If false it will automatically hide resizing handlers
1325
+ * @name Konva.Transformer#resizeEnabled
1326
+ * @method
1327
+ * @param {Boolean} enabled
1328
+ * @returns {Boolean}
1329
+ * @example
1330
+ * // get
1331
+ * var resizeEnabled = transformer.resizeEnabled();
1332
+ *
1333
+ * // set
1334
+ * transformer.resizeEnabled(false);
1335
+ */
1081
1336
  Factory.addGetterSetter(Transformer, 'resizeEnabled', true);
1337
+ /**
1338
+ * get/set anchor size. Default is 10
1339
+ * @name Konva.Transformer#anchorSize
1340
+ * @method
1341
+ * @param {Number} size
1342
+ * @returns {Number}
1343
+ * @example
1344
+ * // get
1345
+ * var anchorSize = transformer.anchorSize();
1346
+ *
1347
+ * // set
1348
+ * transformer.anchorSize(20)
1349
+ */
1082
1350
  Factory.addGetterSetter(Transformer, 'anchorSize', 10, getNumberValidator());
1351
+ /**
1352
+ * get/set ability to rotate.
1353
+ * @name Konva.Transformer#rotateEnabled
1354
+ * @method
1355
+ * @param {Boolean} enabled
1356
+ * @returns {Boolean}
1357
+ * @example
1358
+ * // get
1359
+ * var rotateEnabled = transformer.rotateEnabled();
1360
+ *
1361
+ * // set
1362
+ * transformer.rotateEnabled(false);
1363
+ */
1083
1364
  Factory.addGetterSetter(Transformer, 'rotateEnabled', true);
1365
+ /**
1366
+ * get/set visibility of a little line that connects transformer and rotate anchor.
1367
+ * @name Konva.Transformer#rotateLineVisible
1368
+ * @method
1369
+ * @param {Boolean} enabled
1370
+ * @returns {Boolean}
1371
+ * @example
1372
+ * // get
1373
+ * var rotateLineVisible = transformer.rotateLineVisible();
1374
+ *
1375
+ * // set
1376
+ * transformer.rotateLineVisible(false);
1377
+ */
1084
1378
  Factory.addGetterSetter(Transformer, 'rotateLineVisible', true);
1379
+ /**
1380
+ * get/set rotation snaps angles.
1381
+ * @name Konva.Transformer#rotationSnaps
1382
+ * @method
1383
+ * @param {Array} array
1384
+ * @returns {Array}
1385
+ * @example
1386
+ * // get
1387
+ * var rotationSnaps = transformer.rotationSnaps();
1388
+ *
1389
+ * // set
1390
+ * transformer.rotationSnaps([0, 90, 180, 270]);
1391
+ */
1085
1392
  Factory.addGetterSetter(Transformer, 'rotationSnaps', []);
1393
+ /**
1394
+ * get/set distance for rotation handler
1395
+ * @name Konva.Transformer#rotateAnchorOffset
1396
+ * @method
1397
+ * @param {Number} offset
1398
+ * @returns {Number}
1399
+ * @example
1400
+ * // get
1401
+ * var rotateAnchorOffset = transformer.rotateAnchorOffset();
1402
+ *
1403
+ * // set
1404
+ * transformer.rotateAnchorOffset(100);
1405
+ */
1086
1406
  Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, getNumberValidator());
1407
+ /**
1408
+ * get/set the angle (in degrees) of the rotation anchor position around the bounding box.
1409
+ * 0 = top-center (default), 90 = middle-right, 180 = bottom-center, -90 = middle-left
1410
+ * @name Konva.Transformer#rotateAnchorAngle
1411
+ * @method
1412
+ * @param {Number} angle
1413
+ * @returns {Number}
1414
+ * @example
1415
+ * // get
1416
+ * var rotateAnchorAngle = transformer.rotateAnchorAngle();
1417
+ *
1418
+ * // set rotation anchor to the right side
1419
+ * transformer.rotateAnchorAngle(90);
1420
+ *
1421
+ * // set rotation anchor to the bottom
1422
+ * transformer.rotateAnchorAngle(180);
1423
+ */
1087
1424
  Factory.addGetterSetter(Transformer, 'rotateAnchorAngle', 0, getNumberValidator());
1425
+ /**
1426
+ * get/set rotation anchor cursor
1427
+ * @name Konva.Transformer#rotateAnchorCursor
1428
+ * @method
1429
+ * @param {String} cursorName
1430
+ * @returns {String}
1431
+ * @example
1432
+ * // get
1433
+ * var currentRotationAnchorCursor = transformer.rotateAnchorCursor();
1434
+ *
1435
+ * // set
1436
+ * transformer.rotateAnchorCursor('grab');
1437
+ */
1088
1438
  Factory.addGetterSetter(Transformer, 'rotateAnchorCursor', 'crosshair');
1439
+ /**
1440
+ * get/set distance for rotation tolerance
1441
+ * @name Konva.Transformer#rotationSnapTolerance
1442
+ * @method
1443
+ * @param {Number} tolerance
1444
+ * @returns {Number}
1445
+ * @example
1446
+ * // get
1447
+ * var rotationSnapTolerance = transformer.rotationSnapTolerance();
1448
+ *
1449
+ * // set
1450
+ * transformer.rotationSnapTolerance(100);
1451
+ */
1089
1452
  Factory.addGetterSetter(Transformer, 'rotationSnapTolerance', 5, getNumberValidator());
1453
+ /**
1454
+ * get/set visibility of border
1455
+ * @name Konva.Transformer#borderEnabled
1456
+ * @method
1457
+ * @param {Boolean} enabled
1458
+ * @returns {Boolean}
1459
+ * @example
1460
+ * // get
1461
+ * var borderEnabled = transformer.borderEnabled();
1462
+ *
1463
+ * // set
1464
+ * transformer.borderEnabled(false);
1465
+ */
1090
1466
  Factory.addGetterSetter(Transformer, 'borderEnabled', true);
1467
+ /**
1468
+ * get/set anchor stroke color
1469
+ * @name Konva.Transformer#anchorStroke
1470
+ * @method
1471
+ * @param {String} strokeColor
1472
+ * @returns {String}
1473
+ * @example
1474
+ * // get
1475
+ * var anchorStroke = transformer.anchorStroke();
1476
+ *
1477
+ * // set
1478
+ * transformer.anchorStroke('red');
1479
+ */
1091
1480
  Factory.addGetterSetter(Transformer, 'anchorStroke', 'rgb(0, 161, 255)');
1481
+ /**
1482
+ * get/set anchor stroke width
1483
+ * @name Konva.Transformer#anchorStrokeWidth
1484
+ * @method
1485
+ * @param {Number} anchorStrokeWidth
1486
+ * @returns {Number}
1487
+ * @example
1488
+ * // get
1489
+ * var anchorStrokeWidth = transformer.anchorStrokeWidth();
1490
+ *
1491
+ * // set
1492
+ * transformer.anchorStrokeWidth(3);
1493
+ */
1092
1494
  Factory.addGetterSetter(Transformer, 'anchorStrokeWidth', 1, getNumberValidator());
1495
+ /**
1496
+ * get/set anchor fill color
1497
+ * @name Konva.Transformer#anchorFill
1498
+ * @method
1499
+ * @param {String} anchorFill
1500
+ * @returns {String}
1501
+ * @example
1502
+ * // get
1503
+ * var anchorFill = transformer.anchorFill();
1504
+ *
1505
+ * // set
1506
+ * transformer.anchorFill('red');
1507
+ */
1093
1508
  Factory.addGetterSetter(Transformer, 'anchorFill', 'white');
1509
+ /**
1510
+ * get/set anchor corner radius
1511
+ * @name Konva.Transformer#anchorCornerRadius
1512
+ * @method
1513
+ * @param {Number} radius
1514
+ * @returns {Number}
1515
+ * @example
1516
+ * // get
1517
+ * var anchorCornerRadius = transformer.anchorCornerRadius();
1518
+ *
1519
+ * // set
1520
+ * transformer.anchorCornerRadius(3);
1521
+ */
1094
1522
  Factory.addGetterSetter(Transformer, 'anchorCornerRadius', 0, getNumberValidator());
1523
+ /**
1524
+ * get/set border stroke color
1525
+ * @name Konva.Transformer#borderStroke
1526
+ * @method
1527
+ * @param {Boolean} enabled
1528
+ * @returns {Boolean}
1529
+ * @example
1530
+ * // get
1531
+ * var borderStroke = transformer.borderStroke();
1532
+ *
1533
+ * // set
1534
+ * transformer.borderStroke('red');
1535
+ */
1095
1536
  Factory.addGetterSetter(Transformer, 'borderStroke', 'rgb(0, 161, 255)');
1537
+ /**
1538
+ * get/set border stroke width
1539
+ * @name Konva.Transformer#borderStrokeWidth
1540
+ * @method
1541
+ * @param {Number} strokeWidth
1542
+ * @returns {Number}
1543
+ * @example
1544
+ * // get
1545
+ * var borderStrokeWidth = transformer.borderStrokeWidth();
1546
+ *
1547
+ * // set
1548
+ * transformer.borderStrokeWidth(3);
1549
+ */
1096
1550
  Factory.addGetterSetter(Transformer, 'borderStrokeWidth', 1, getNumberValidator());
1551
+ /**
1552
+ * get/set border dash array
1553
+ * @name Konva.Transformer#borderDash
1554
+ * @method
1555
+ * @param {Array} dash array
1556
+ * @returns {Array}
1557
+ * @example
1558
+ * // get
1559
+ * var borderDash = transformer.borderDash();
1560
+ *
1561
+ * // set
1562
+ * transformer.borderDash([2, 2]);
1563
+ */
1097
1564
  Factory.addGetterSetter(Transformer, 'borderDash');
1565
+ /**
1566
+ * get/set should we keep ratio while resize anchors at corners
1567
+ * @name Konva.Transformer#keepRatio
1568
+ * @method
1569
+ * @param {Boolean} keepRatio
1570
+ * @returns {Boolean}
1571
+ * @example
1572
+ * // get
1573
+ * var keepRatio = transformer.keepRatio();
1574
+ *
1575
+ * // set
1576
+ * transformer.keepRatio(false);
1577
+ */
1098
1578
  Factory.addGetterSetter(Transformer, 'keepRatio', true);
1579
+ /**
1580
+ * get/set how to react on skift key while resizing anchors at corners
1581
+ * @name Konva.Transformer#shiftBehavior
1582
+ * @method
1583
+ * @param {String} shiftBehavior
1584
+ * @returns {String}
1585
+ * @example
1586
+ * // get
1587
+ * var shiftBehavior = transformer.shiftBehavior();
1588
+ *
1589
+ * // set
1590
+ * transformer.shiftBehavior('none');
1591
+ */
1099
1592
  Factory.addGetterSetter(Transformer, 'shiftBehavior', 'default');
1593
+ /**
1594
+ * get/set should we resize relative to node's center?
1595
+ * @name Konva.Transformer#centeredScaling
1596
+ * @method
1597
+ * @param {Boolean} centeredScaling
1598
+ * @returns {Boolean}
1599
+ * @example
1600
+ * // get
1601
+ * var centeredScaling = transformer.centeredScaling();
1602
+ *
1603
+ * // set
1604
+ * transformer.centeredScaling(true);
1605
+ */
1100
1606
  Factory.addGetterSetter(Transformer, 'centeredScaling', false);
1607
+ /**
1608
+ * get/set should we think about stroke while resize? Good to use when a shape has strokeScaleEnabled = false
1609
+ * default is false
1610
+ * @name Konva.Transformer#ignoreStroke
1611
+ * @method
1612
+ * @param {Boolean} ignoreStroke
1613
+ * @returns {Boolean}
1614
+ * @example
1615
+ * // get
1616
+ * var ignoreStroke = transformer.ignoreStroke();
1617
+ *
1618
+ * // set
1619
+ * transformer.ignoreStroke(true);
1620
+ */
1101
1621
  Factory.addGetterSetter(Transformer, 'ignoreStroke', false);
1622
+ /**
1623
+ * get/set padding
1624
+ * @name Konva.Transformer#padding
1625
+ * @method
1626
+ * @param {Number} padding
1627
+ * @returns {Number}
1628
+ * @example
1629
+ * // get
1630
+ * var padding = transformer.padding();
1631
+ *
1632
+ * // set
1633
+ * transformer.padding(10);
1634
+ */
1102
1635
  Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator());
1636
+ /**
1637
+ * get/set attached nodes of the Transformer. Transformer will adapt to their size and listen to their events
1638
+ * @method
1639
+ * @name Konva.Transformer#nodes
1640
+ * @returns {Konva.Node}
1641
+ * @example
1642
+ * // get
1643
+ * const nodes = transformer.nodes();
1644
+ *
1645
+ * // set
1646
+ * transformer.nodes([rect, circle]);
1647
+ *
1648
+ * // push new item:
1649
+ * const oldNodes = transformer.nodes();
1650
+ * const newNodes = oldNodes.concat([newShape]);
1651
+ * // it is important to set new array instance (and concat method above will create it)
1652
+ * transformer.nodes(newNodes);
1653
+ */
1103
1654
  Factory.addGetterSetter(Transformer, 'nodes');
1655
+ // @ts-ignore
1656
+ // deprecated
1104
1657
  Factory.addGetterSetter(Transformer, 'node');
1658
+ /**
1659
+ * get/set bounding box function. **IMPORTANT!** boundBoxFunc operates in absolute coordinates.
1660
+ * Both boxes are `{ x, y, width, height, rotation }`, with the rotation in radians.
1661
+ * @name Konva.Transformer#boundBoxFunc
1662
+ * @method
1663
+ * @param {Function} func
1664
+ * @returns {Function}
1665
+ * @example
1666
+ * // get
1667
+ * var boundBoxFunc = transformer.boundBoxFunc();
1668
+ *
1669
+ * // set
1670
+ * transformer.boundBoxFunc(function(oldBox, newBox) {
1671
+ * // width and height of the boxes are corresponding to total absolute width and height of all nodes combined
1672
+ * // so it includes scale of the node.
1673
+ * if (newBox.width > 200) {
1674
+ * return oldBox;
1675
+ * }
1676
+ * return newBox;
1677
+ * });
1678
+ */
1105
1679
  Factory.addGetterSetter(Transformer, 'boundBoxFunc');
1680
+ /**
1681
+ * get/set dragging func for transformer anchors
1682
+ * @name Konva.Transformer#anchorDragBoundFunc
1683
+ * @method
1684
+ * @param {Function} func
1685
+ * @returns {Function}
1686
+ * @example
1687
+ * // get
1688
+ * var anchorDragBoundFunc = transformer.anchorDragBoundFunc();
1689
+ *
1690
+ * // set
1691
+ * transformer.anchorDragBoundFunc(function(oldAbsPos, newAbsPos, event) {
1692
+ * return {
1693
+ * x: 0,
1694
+ * y: newAbsolutePosition.y
1695
+ * }
1696
+ * });
1697
+ */
1106
1698
  Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
1699
+ /**
1700
+ * get/set styling function for transformer anchors to overwrite default styles
1701
+ * @name Konva.Transformer#anchorStyleFunc
1702
+ * @method
1703
+ * @param {Function} func
1704
+ * @returns {Function}
1705
+ * @example
1706
+ * // get
1707
+ * var anchorStyleFunc = transformer.anchorStyleFunc();
1708
+ *
1709
+ * // set
1710
+ * transformer.anchorStyleFunc(function(anchor) {
1711
+ * // anchor is a simple Konva.Rect instance
1712
+ * // it will be executed AFTER all attributes are set, like 'anchorStrokeWidth' or 'anchorFill'
1713
+ * if (anchor.hasName('rotater')) {
1714
+ * // make rotater anchor filled black and looks like a circle
1715
+ * anchor.fill('black');
1716
+ * anchor.cornerRadius(anchor.width() / 2);
1717
+ * }
1718
+ * });
1719
+ */
1107
1720
  Factory.addGetterSetter(Transformer, 'anchorStyleFunc');
1721
+ /**
1722
+ * using this setting you can drag transformer group by dragging empty space between attached nodes
1723
+ * shouldOverdrawWholeArea = true may temporary disable all events on attached nodes
1724
+ * @name Konva.Transformer#shouldOverdrawWholeArea
1725
+ * @method
1726
+ * @param {Boolean} shouldOverdrawWholeArea
1727
+ * @returns {Boolean}
1728
+ * @example
1729
+ * // get
1730
+ * var shouldOverdrawWholeArea = transformer.shouldOverdrawWholeArea();
1731
+ *
1732
+ * // set
1733
+ * transformer.shouldOverdrawWholeArea(true);
1734
+ */
1108
1735
  Factory.addGetterSetter(Transformer, 'shouldOverdrawWholeArea', false);
1736
+ /**
1737
+ * If you have just one attached node to Transformer it will set its initial rotation to the rotation of that node.
1738
+ * In some cases you may need to set a different rotation.
1739
+ * @name Konva.Transformer#useSingleNodeRotation
1740
+ * @method
1741
+ * @param {Boolean} useSingleNodeRotation
1742
+ * @returns {Boolean}
1743
+ * @example
1744
+ * // set flag to false
1745
+ * transformer.useSingleNodeRotation(false);
1746
+ * // attach a shape
1747
+ * transformer.nodes([shape]);
1748
+ * transformer.rotation(45);
1749
+ * transformer.update();
1750
+ */
1109
1751
  Factory.addGetterSetter(Transformer, 'useSingleNodeRotation', true);
1110
1752
  Factory.backCompat(Transformer, {
1111
1753
  lineEnabled: 'borderEnabled',