konva 10.0.12 → 10.1.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.1.0
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Fri Nov 21 2025
11
+ * Date: Wed Jan 14 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.1.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.