konva 10.0.12 → 10.2.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.
package/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v10.0.12
8
+ * Konva JavaScript Framework v10.2.0
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Fri Nov 21 2025
11
+ * Date: Thu Jan 15 2026
12
12
  *
13
13
  * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
14
14
  * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@@ -35,7 +35,7 @@
35
35
  : {};
36
36
  const Konva$2 = {
37
37
  _global: glob,
38
- version: '10.0.12',
38
+ version: '10.2.0',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -114,7 +114,7 @@
114
114
  * Drag distance property. If you start to drag a node you may want to wait until pointer is moved to some distance from start point,
115
115
  * only then start dragging. Default is 3px.
116
116
  * @property dragDistance
117
- * @default 0
117
+ * @default 3
118
118
  * @memberof Konva
119
119
  * @example
120
120
  * Konva.dragDistance = 10;
@@ -142,9 +142,9 @@
142
142
  showWarnings: true,
143
143
  /**
144
144
  * Configure what mouse buttons can be used for drag and drop.
145
- * Default value is [0] - only left mouse button.
145
+ * Default value is [0, 1] - left and middle mouse buttons.
146
146
  * @property dragButtons
147
- * @default true
147
+ * @default [0, 1]
148
148
  * @memberof Konva
149
149
  * @example
150
150
  * // enable left and right mouse buttons
@@ -621,7 +621,7 @@ js: import "konva/skia-backend";
621
621
  let _isCanvasFarblingActive = null;
622
622
  const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
623
623
  function (f) {
624
- setTimeout(f, 60);
624
+ setTimeout(f, 16); // 60fps ≈ 16.67ms per frame
625
625
  };
626
626
  /**
627
627
  * @namespace Util
@@ -2910,8 +2910,8 @@ js: import "konva/skia-backend";
2910
2910
  */
2911
2911
  clearCache() {
2912
2912
  if (this._cache.has(CANVAS)) {
2913
- const { scene, filter, hit, buffer } = this._cache.get(CANVAS);
2914
- Util.releaseCanvas(scene, filter, hit, buffer);
2913
+ const { scene, filter, hit } = this._cache.get(CANVAS);
2914
+ Util.releaseCanvas(scene._canvas, filter._canvas, hit._canvas);
2915
2915
  this._cache.delete(CANVAS);
2916
2916
  }
2917
2917
  this._clearSelfAndDescendantCache();
@@ -3061,11 +3061,13 @@ js: import "konva/skia-backend";
3061
3061
  sceneContext.stroke();
3062
3062
  sceneContext.restore();
3063
3063
  }
3064
+ // Release buffer canvas immediately - it's only needed during initial cache drawing
3065
+ // This significantly reduces memory usage for cached nodes
3066
+ Util.releaseCanvas(bufferCanvas._canvas);
3064
3067
  this._cache.set(CANVAS, {
3065
3068
  scene: cachedSceneCanvas,
3066
3069
  filter: cachedFilterCanvas,
3067
3070
  hit: cachedHitCanvas,
3068
- buffer: bufferCanvas,
3069
3071
  x: x,
3070
3072
  y: y,
3071
3073
  });
@@ -4780,21 +4782,22 @@ js: import "konva/skia-backend";
4780
4782
  }
4781
4783
  }
4782
4784
  _getProtoListeners(eventType) {
4783
- var _a, _b, _c;
4784
- const allListeners = (_a = this._cache.get(ALL_LISTENERS)) !== null && _a !== void 0 ? _a : {};
4785
+ var _a, _b;
4786
+ const { nodeType } = this;
4787
+ const allListeners = Node.protoListenerMap.get(nodeType) || {};
4785
4788
  let events = allListeners === null || allListeners === void 0 ? void 0 : allListeners[eventType];
4786
4789
  if (events === undefined) {
4787
4790
  //recalculate cache
4788
4791
  events = [];
4789
4792
  let obj = Object.getPrototypeOf(this);
4790
4793
  while (obj) {
4791
- const hierarchyEvents = (_c = (_b = obj.eventListeners) === null || _b === void 0 ? void 0 : _b[eventType]) !== null && _c !== void 0 ? _c : [];
4794
+ const hierarchyEvents = (_b = (_a = obj.eventListeners) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : [];
4792
4795
  events.push(...hierarchyEvents);
4793
4796
  obj = Object.getPrototypeOf(obj);
4794
4797
  }
4795
4798
  // update cache
4796
4799
  allListeners[eventType] = events;
4797
- this._cache.set(ALL_LISTENERS, allListeners);
4800
+ Node.protoListenerMap.set(nodeType, allListeners);
4798
4801
  }
4799
4802
  return events;
4800
4803
  }
@@ -5047,6 +5050,7 @@ js: import "konva/skia-backend";
5047
5050
  return no;
5048
5051
  }
5049
5052
  }
5053
+ Node.protoListenerMap = new Map();
5050
5054
  Node.prototype.nodeType = 'Node';
5051
5055
  Node.prototype._attrsAffectingSize = [];
5052
5056
  // attache events listeners once into prototype
@@ -7566,7 +7570,17 @@ js: import "konva/skia-backend";
7566
7570
  stage = this.getStage();
7567
7571
  const bc = bufferCanvas || stage.bufferCanvas;
7568
7572
  const bufferContext = bc.getContext();
7569
- bufferContext.clear();
7573
+ // When caching, the buffer canvas may have a translation applied.
7574
+ // We need to reset the transform before clearing to ensure the entire canvas is cleared.
7575
+ if (bufferCanvas) {
7576
+ bufferContext.save();
7577
+ bufferContext.setTransform(1, 0, 0, 1, 0, 0);
7578
+ bufferContext.clearRect(0, 0, bc.width, bc.height);
7579
+ bufferContext.restore();
7580
+ }
7581
+ else {
7582
+ bufferContext.clear();
7583
+ }
7570
7584
  bufferContext.save();
7571
7585
  bufferContext._applyLineJoin(this);
7572
7586
  bufferContext._applyMiterLimit(this);
@@ -10483,6 +10497,35 @@ js: import "konva/skia-backend";
10483
10497
  }
10484
10498
  return allPoints;
10485
10499
  }
10500
+ function getBezierExtremaPoints(points) {
10501
+ const axisPoints = [
10502
+ [points[0], points[2], points[4], points[6]],
10503
+ [points[1], points[3], points[5], points[7]],
10504
+ ];
10505
+ const extremaTs = [];
10506
+ for (const axis of axisPoints) {
10507
+ const a = -3 * axis[0] + 9 * axis[1] - 9 * axis[2] + 3 * axis[3];
10508
+ if (a !== 0) {
10509
+ const b = 6 * axis[0] - 12 * axis[1] + 6 * axis[2];
10510
+ const c = -3 * axis[0] + 3 * axis[1];
10511
+ const discriminant = b * b - 4 * a * c;
10512
+ if (discriminant >= 0) {
10513
+ const d = Math.sqrt(discriminant);
10514
+ extremaTs.push((-b + d) / (2 * a));
10515
+ extremaTs.push((-b - d) / (2 * a));
10516
+ }
10517
+ }
10518
+ }
10519
+ return extremaTs
10520
+ .filter((t) => t > 0 && t < 1)
10521
+ .flatMap((t) => axisPoints.map((axis) => {
10522
+ const mt = 1 - t;
10523
+ return (mt * mt * mt * axis[0] +
10524
+ 3 * mt * mt * t * axis[1] +
10525
+ 3 * mt * t * t * axis[2] +
10526
+ t * t * t * axis[3]);
10527
+ }));
10528
+ }
10486
10529
  /**
10487
10530
  * Line constructor.&nbsp; Lines are defined by an array of points and
10488
10531
  * a tension
@@ -10685,6 +10728,15 @@ js: import "konva/skia-backend";
10685
10728
  points[points.length - 1],
10686
10729
  ];
10687
10730
  }
10731
+ else if (this.bezier()) {
10732
+ points = [
10733
+ points[0],
10734
+ points[1],
10735
+ ...getBezierExtremaPoints(this.points()),
10736
+ points[points.length - 2],
10737
+ points[points.length - 1],
10738
+ ];
10739
+ }
10688
10740
  else {
10689
10741
  points = this.points();
10690
10742
  }
@@ -14748,6 +14800,7 @@ js: import "konva/skia-backend";
14748
14800
  * @param {String} [config.fontStyle] can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
14749
14801
  * @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
14750
14802
  * @param {String} [config.textDecoration] can be line-through, underline or empty string. Default is empty string.
14803
+ * @param {String} [config.underlineOffset] offset for underline line. Default is calculated based on font size.
14751
14804
  * @param {String} config.text
14752
14805
  * @param {String} [config.align] can be left, center, right or justify
14753
14806
  * @param {String} [config.verticalAlign] can be top, middle or bottom
@@ -14856,7 +14909,7 @@ js: import "konva/skia-backend";
14856
14909
  if (!this.text()) {
14857
14910
  return;
14858
14911
  }
14859
- let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
14912
+ let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), fill = this.fill(), textDecoration = this.textDecoration(), underlineOffset = this.underlineOffset(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
14860
14913
  direction = direction === INHERIT ? context.direction : direction;
14861
14914
  let translateY = lineHeightPx / 2;
14862
14915
  let baseline = MIDDLE;
@@ -14897,9 +14950,9 @@ js: import "konva/skia-backend";
14897
14950
  if (shouldUnderline) {
14898
14951
  context.save();
14899
14952
  context.beginPath();
14900
- const yOffset = !Konva$2.legacyTextRendering
14953
+ const yOffset = underlineOffset !== null && underlineOffset !== void 0 ? underlineOffset : (!Konva$2.legacyTextRendering
14901
14954
  ? Math.round(fontSize / 4)
14902
- : Math.round(fontSize / 2);
14955
+ : Math.round(fontSize / 2));
14903
14956
  const x = lineTranslateX;
14904
14957
  const y = translateY + lineTranslateY + yOffset;
14905
14958
  context.moveTo(x, y);
@@ -15520,6 +15573,20 @@ js: import "konva/skia-backend";
15520
15573
  * text.textDecoration('underline line-through');
15521
15574
  */
15522
15575
  Factory.addGetterSetter(Text, 'textDecoration', '');
15576
+ /**
15577
+ * get/set text underline decoration offset. Offset for underline line. Default is calculated based on font size.
15578
+ * @name Konva.Text#underlineOffset
15579
+ * @method
15580
+ * @param {Number} underlineOffset
15581
+ * @returns {Number}
15582
+ * @example
15583
+ * // get underline offset
15584
+ * var underlineOffset = text.underlineOffset();
15585
+ *
15586
+ * // set underline offset
15587
+ * text.underlineOffset(5);
15588
+ */
15589
+ Factory.addGetterSetter(Text, 'underlineOffset', undefined, getNumberValidator());
15523
15590
  /**
15524
15591
  * get/set per-character render hook. The callback is invoked for each grapheme before drawing.
15525
15592
  * It can mutate the provided context (e.g. translate, rotate, change styles) and should return void.
@@ -16100,6 +16167,7 @@ js: import "konva/skia-backend";
16100
16167
  const ATTR_CHANGE_LIST = [
16101
16168
  'resizeEnabledChange',
16102
16169
  'rotateAnchorOffsetChange',
16170
+ 'rotateAnchorAngleChange',
16103
16171
  'rotateEnabledChange',
16104
16172
  'enabledAnchorsChange',
16105
16173
  'anchorSizeChange',
@@ -16606,11 +16674,44 @@ js: import "konva/skia-backend";
16606
16674
  sceneFunc(ctx, shape) {
16607
16675
  const tr = shape.getParent();
16608
16676
  const padding = tr.padding();
16677
+ const width = shape.width();
16678
+ const height = shape.height();
16609
16679
  ctx.beginPath();
16610
- ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
16611
- ctx.moveTo(shape.width() / 2, -padding);
16680
+ ctx.rect(-padding, -padding, width + padding * 2, height + padding * 2);
16612
16681
  if (tr.rotateEnabled() && tr.rotateLineVisible()) {
16613
- ctx.lineTo(shape.width() / 2, -tr.rotateAnchorOffset() * Util._sign(shape.height()) - padding);
16682
+ // Calculate rotation line position based on rotateAnchorAngle
16683
+ const rotateAnchorAngle = tr.rotateAnchorAngle();
16684
+ const rotateAnchorOffset = tr.rotateAnchorOffset();
16685
+ const rad = Util.degToRad(rotateAnchorAngle);
16686
+ // Direction vector (0 degrees = up/top)
16687
+ const dirX = Math.sin(rad);
16688
+ const dirY = -Math.cos(rad);
16689
+ // Center of the box
16690
+ const cx = width / 2;
16691
+ const cy = height / 2;
16692
+ // Find intersection with box edge
16693
+ let t = Infinity;
16694
+ if (dirY < 0) {
16695
+ t = Math.min(t, -cy / dirY);
16696
+ }
16697
+ else if (dirY > 0) {
16698
+ t = Math.min(t, (height - cy) / dirY);
16699
+ }
16700
+ if (dirX < 0) {
16701
+ t = Math.min(t, -cx / dirX);
16702
+ }
16703
+ else if (dirX > 0) {
16704
+ t = Math.min(t, (width - cx) / dirX);
16705
+ }
16706
+ // Edge point (start of line)
16707
+ const edgeX = cx + dirX * t;
16708
+ const edgeY = cy + dirY * t;
16709
+ // End point with offset
16710
+ const sign = Util._sign(height);
16711
+ const endX = edgeX + dirX * rotateAnchorOffset * sign;
16712
+ const endY = edgeY + dirY * rotateAnchorOffset * sign;
16713
+ ctx.moveTo(edgeX, edgeY);
16714
+ ctx.lineTo(endX, endY);
16614
16715
  }
16615
16716
  ctx.fillStrokeShape(shape);
16616
16717
  },
@@ -16700,8 +16801,10 @@ js: import "konva/skia-backend";
16700
16801
  const attrs = this._getNodeRect();
16701
16802
  x = anchorNode.x() - attrs.width / 2;
16702
16803
  y = -anchorNode.y() + attrs.height / 2;
16703
- // hor angle is changed?
16704
- let delta = Math.atan2(-y, x) + Math.PI / 2;
16804
+ // Calculate angle from center to current anchor position
16805
+ // Offset by rotateAnchorAngle so we measure rotation from the anchor's starting position
16806
+ const rotateAnchorAngleRad = Konva$2.getAngle(this.rotateAnchorAngle());
16807
+ let delta = Math.atan2(-y, x) + Math.PI / 2 - rotateAnchorAngleRad;
16705
16808
  if (attrs.height < 0) {
16706
16809
  delta -= Math.PI;
16707
16810
  }
@@ -17128,9 +17231,44 @@ js: import "konva/skia-backend";
17128
17231
  offsetY: anchorSize / 2 - padding,
17129
17232
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-right') >= 0,
17130
17233
  });
17234
+ // Calculate rotation anchor position based on rotateAnchorAngle
17235
+ const rotateAnchorAngle = this.rotateAnchorAngle();
17236
+ const rotateAnchorOffset = this.rotateAnchorOffset();
17237
+ const rad = Util.degToRad(rotateAnchorAngle);
17238
+ // Direction vector (0 degrees = up/top)
17239
+ const dirX = Math.sin(rad);
17240
+ const dirY = -Math.cos(rad);
17241
+ // Center of the box
17242
+ const cx = width / 2;
17243
+ const cy = height / 2;
17244
+ // Find intersection with box edge
17245
+ // Calculate time to hit each edge from center
17246
+ let t = Infinity;
17247
+ // Handle each direction
17248
+ if (dirY < 0) {
17249
+ // Moving up, check top edge (y = 0)
17250
+ t = Math.min(t, -cy / dirY);
17251
+ }
17252
+ else if (dirY > 0) {
17253
+ // Moving down, check bottom edge (y = height)
17254
+ t = Math.min(t, (height - cy) / dirY);
17255
+ }
17256
+ if (dirX < 0) {
17257
+ // Moving left, check left edge (x = 0)
17258
+ t = Math.min(t, -cx / dirX);
17259
+ }
17260
+ else if (dirX > 0) {
17261
+ // Moving right, check right edge (x = width)
17262
+ t = Math.min(t, (width - cx) / dirX);
17263
+ }
17264
+ // Edge point
17265
+ const edgeX = cx + dirX * t;
17266
+ const edgeY = cy + dirY * t;
17267
+ // Final position with offset (accounting for height sign and padding)
17268
+ const sign = Util._sign(height);
17131
17269
  this._batchChangeChild('.rotater', {
17132
- x: width / 2,
17133
- y: -this.rotateAnchorOffset() * Util._sign(height) - padding,
17270
+ x: edgeX + dirX * rotateAnchorOffset * sign,
17271
+ y: edgeY + dirY * rotateAnchorOffset * sign - padding * dirY,
17134
17272
  visible: this.rotateEnabled(),
17135
17273
  });
17136
17274
  this._batchChangeChild('.back', {
@@ -17339,6 +17477,24 @@ js: import "konva/skia-backend";
17339
17477
  * transformer.rotateAnchorOffset(100);
17340
17478
  */
17341
17479
  Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, getNumberValidator());
17480
+ /**
17481
+ * get/set the angle (in degrees) of the rotation anchor position around the bounding box.
17482
+ * 0 = top-center (default), 90 = middle-right, 180 = bottom-center, -90 = middle-left
17483
+ * @name Konva.Transformer#rotateAnchorAngle
17484
+ * @method
17485
+ * @param {Number} angle
17486
+ * @returns {Number}
17487
+ * @example
17488
+ * // get
17489
+ * var rotateAnchorAngle = transformer.rotateAnchorAngle();
17490
+ *
17491
+ * // set rotation anchor to the right side
17492
+ * transformer.rotateAnchorAngle(90);
17493
+ *
17494
+ * // set rotation anchor to the bottom
17495
+ * transformer.rotateAnchorAngle(180);
17496
+ */
17497
+ Factory.addGetterSetter(Transformer, 'rotateAnchorAngle', 0, getNumberValidator());
17342
17498
  /**
17343
17499
  * get/set rotation anchor cursor
17344
17500
  * @name Konva.Transformer#rotateAnchorCursor