konva 10.0.11 → 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.11
8
+ * Konva JavaScript Framework v10.1.0
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Thu Nov 20 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.11',
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
@@ -766,17 +766,26 @@ js: import "konva/skia-backend";
766
766
  return false;
767
767
  }
768
768
  const c = this.createCanvasElement();
769
- c.width = 1;
770
- c.height = 1;
769
+ c.width = 10;
770
+ c.height = 10;
771
771
  const ctx = c.getContext('2d', {
772
772
  willReadFrequently: true,
773
773
  });
774
- ctx.clearRect(0, 0, 1, 1);
775
- ctx.fillStyle = 'rgba(255,0,255,1)'; // clear #FF00FF, no alpha
776
- ctx.fillRect(0, 0, 1, 1);
777
- const d = ctx.getImageData(0, 0, 1, 1).data;
778
- const exact = d[0] === 255 && d[1] === 0 && d[2] === 255 && d[3] === 255;
779
- _isCanvasFarblingActive = !exact;
774
+ ctx.clearRect(0, 0, 10, 10);
775
+ ctx.fillStyle = '#282828'; // 40, 40, 40
776
+ ctx.fillRect(0, 0, 10, 10);
777
+ const d = ctx.getImageData(0, 0, 10, 10).data;
778
+ let isFarbling = false;
779
+ for (let i = 0; i < 100; i++) {
780
+ if (d[i * 4] !== 40 ||
781
+ d[i * 4 + 1] !== 40 ||
782
+ d[i * 4 + 2] !== 40 ||
783
+ d[i * 4 + 3] !== 255) {
784
+ isFarbling = true;
785
+ break;
786
+ }
787
+ }
788
+ _isCanvasFarblingActive = isFarbling;
780
789
  this.releaseCanvas(c);
781
790
  return _isCanvasFarblingActive;
782
791
  },
@@ -2901,8 +2910,8 @@ js: import "konva/skia-backend";
2901
2910
  */
2902
2911
  clearCache() {
2903
2912
  if (this._cache.has(CANVAS)) {
2904
- const { scene, filter, hit, buffer } = this._cache.get(CANVAS);
2905
- Util.releaseCanvas(scene, filter, hit, buffer);
2913
+ const { scene, filter, hit } = this._cache.get(CANVAS);
2914
+ Util.releaseCanvas(scene._canvas, filter._canvas, hit._canvas);
2906
2915
  this._cache.delete(CANVAS);
2907
2916
  }
2908
2917
  this._clearSelfAndDescendantCache();
@@ -3052,11 +3061,13 @@ js: import "konva/skia-backend";
3052
3061
  sceneContext.stroke();
3053
3062
  sceneContext.restore();
3054
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);
3055
3067
  this._cache.set(CANVAS, {
3056
3068
  scene: cachedSceneCanvas,
3057
3069
  filter: cachedFilterCanvas,
3058
3070
  hit: cachedHitCanvas,
3059
- buffer: bufferCanvas,
3060
3071
  x: x,
3061
3072
  y: y,
3062
3073
  });
@@ -4771,21 +4782,22 @@ js: import "konva/skia-backend";
4771
4782
  }
4772
4783
  }
4773
4784
  _getProtoListeners(eventType) {
4774
- var _a, _b, _c;
4775
- 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) || {};
4776
4788
  let events = allListeners === null || allListeners === void 0 ? void 0 : allListeners[eventType];
4777
4789
  if (events === undefined) {
4778
4790
  //recalculate cache
4779
4791
  events = [];
4780
4792
  let obj = Object.getPrototypeOf(this);
4781
4793
  while (obj) {
4782
- 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 : [];
4783
4795
  events.push(...hierarchyEvents);
4784
4796
  obj = Object.getPrototypeOf(obj);
4785
4797
  }
4786
4798
  // update cache
4787
4799
  allListeners[eventType] = events;
4788
- this._cache.set(ALL_LISTENERS, allListeners);
4800
+ Node.protoListenerMap.set(nodeType, allListeners);
4789
4801
  }
4790
4802
  return events;
4791
4803
  }
@@ -5038,6 +5050,7 @@ js: import "konva/skia-backend";
5038
5050
  return no;
5039
5051
  }
5040
5052
  }
5053
+ Node.protoListenerMap = new Map();
5041
5054
  Node.prototype.nodeType = 'Node';
5042
5055
  Node.prototype._attrsAffectingSize = [];
5043
5056
  // attache events listeners once into prototype
@@ -7557,7 +7570,17 @@ js: import "konva/skia-backend";
7557
7570
  stage = this.getStage();
7558
7571
  const bc = bufferCanvas || stage.bufferCanvas;
7559
7572
  const bufferContext = bc.getContext();
7560
- 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
+ }
7561
7584
  bufferContext.save();
7562
7585
  bufferContext._applyLineJoin(this);
7563
7586
  bufferContext._applyMiterLimit(this);
@@ -10474,6 +10497,35 @@ js: import "konva/skia-backend";
10474
10497
  }
10475
10498
  return allPoints;
10476
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
+ }
10477
10529
  /**
10478
10530
  * Line constructor.&nbsp; Lines are defined by an array of points and
10479
10531
  * a tension
@@ -10676,6 +10728,15 @@ js: import "konva/skia-backend";
10676
10728
  points[points.length - 1],
10677
10729
  ];
10678
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
+ }
10679
10740
  else {
10680
10741
  points = this.points();
10681
10742
  }
@@ -14739,6 +14800,7 @@ js: import "konva/skia-backend";
14739
14800
  * @param {String} [config.fontStyle] can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
14740
14801
  * @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
14741
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.
14742
14804
  * @param {String} config.text
14743
14805
  * @param {String} [config.align] can be left, center, right or justify
14744
14806
  * @param {String} [config.verticalAlign] can be top, middle or bottom
@@ -14847,7 +14909,7 @@ js: import "konva/skia-backend";
14847
14909
  if (!this.text()) {
14848
14910
  return;
14849
14911
  }
14850
- 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;
14851
14913
  direction = direction === INHERIT ? context.direction : direction;
14852
14914
  let translateY = lineHeightPx / 2;
14853
14915
  let baseline = MIDDLE;
@@ -14888,9 +14950,9 @@ js: import "konva/skia-backend";
14888
14950
  if (shouldUnderline) {
14889
14951
  context.save();
14890
14952
  context.beginPath();
14891
- const yOffset = !Konva$2.legacyTextRendering
14953
+ const yOffset = underlineOffset !== null && underlineOffset !== void 0 ? underlineOffset : (!Konva$2.legacyTextRendering
14892
14954
  ? Math.round(fontSize / 4)
14893
- : Math.round(fontSize / 2);
14955
+ : Math.round(fontSize / 2));
14894
14956
  const x = lineTranslateX;
14895
14957
  const y = translateY + lineTranslateY + yOffset;
14896
14958
  context.moveTo(x, y);
@@ -15511,6 +15573,20 @@ js: import "konva/skia-backend";
15511
15573
  * text.textDecoration('underline line-through');
15512
15574
  */
15513
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());
15514
15590
  /**
15515
15591
  * get/set per-character render hook. The callback is invoked for each grapheme before drawing.
15516
15592
  * It can mutate the provided context (e.g. translate, rotate, change styles) and should return void.