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/lib/Global.js CHANGED
@@ -13,7 +13,7 @@ export const glob = typeof global !== 'undefined'
13
13
  : {};
14
14
  export const Konva = {
15
15
  _global: glob,
16
- version: '10.0.12',
16
+ version: '10.1.0',
17
17
  isBrowser: detectBrowser(),
18
18
  isUnminified: /param/.test(function (param) { }.toString()),
19
19
  dblClickWindow: 400,
package/lib/Node.d.ts CHANGED
@@ -240,6 +240,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
240
240
  _setAttr<AttrConfig extends Config, K extends AnyString<keyof Config>>(key: K, val: K extends keyof AttrConfig ? AttrConfig[K] : any): void;
241
241
  _setComponentAttr(key: any, component: any, val: any): void;
242
242
  _fireAndBubble(eventType: any, evt: any, compareShape?: any): void;
243
+ static protoListenerMap: Map<string, any>;
243
244
  _getProtoListeners(eventType: any): any;
244
245
  _fire(eventType: any, evt: any): void;
245
246
  draw(): this;
package/lib/Node.js CHANGED
@@ -154,8 +154,8 @@ export class Node {
154
154
  }
155
155
  clearCache() {
156
156
  if (this._cache.has(CANVAS)) {
157
- const { scene, filter, hit, buffer } = this._cache.get(CANVAS);
158
- Util.releaseCanvas(scene, filter, hit, buffer);
157
+ const { scene, filter, hit } = this._cache.get(CANVAS);
158
+ Util.releaseCanvas(scene._canvas, filter._canvas, hit._canvas);
159
159
  this._cache.delete(CANVAS);
160
160
  }
161
161
  this._clearSelfAndDescendantCache();
@@ -238,11 +238,11 @@ export class Node {
238
238
  sceneContext.stroke();
239
239
  sceneContext.restore();
240
240
  }
241
+ Util.releaseCanvas(bufferCanvas._canvas);
241
242
  this._cache.set(CANVAS, {
242
243
  scene: cachedSceneCanvas,
243
244
  filter: cachedFilterCanvas,
244
245
  hit: cachedHitCanvas,
245
- buffer: bufferCanvas,
246
246
  x: x,
247
247
  y: y,
248
248
  });
@@ -1269,19 +1269,20 @@ export class Node {
1269
1269
  }
1270
1270
  }
1271
1271
  _getProtoListeners(eventType) {
1272
- var _a, _b, _c;
1273
- const allListeners = (_a = this._cache.get(ALL_LISTENERS)) !== null && _a !== void 0 ? _a : {};
1272
+ var _a, _b;
1273
+ const { nodeType } = this;
1274
+ const allListeners = Node.protoListenerMap.get(nodeType) || {};
1274
1275
  let events = allListeners === null || allListeners === void 0 ? void 0 : allListeners[eventType];
1275
1276
  if (events === undefined) {
1276
1277
  events = [];
1277
1278
  let obj = Object.getPrototypeOf(this);
1278
1279
  while (obj) {
1279
- const hierarchyEvents = (_c = (_b = obj.eventListeners) === null || _b === void 0 ? void 0 : _b[eventType]) !== null && _c !== void 0 ? _c : [];
1280
+ const hierarchyEvents = (_b = (_a = obj.eventListeners) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : [];
1280
1281
  events.push(...hierarchyEvents);
1281
1282
  obj = Object.getPrototypeOf(obj);
1282
1283
  }
1283
1284
  allListeners[eventType] = events;
1284
- this._cache.set(ALL_LISTENERS, allListeners);
1285
+ Node.protoListenerMap.set(nodeType, allListeners);
1285
1286
  }
1286
1287
  return events;
1287
1288
  }
@@ -1471,6 +1472,7 @@ export class Node {
1471
1472
  return no;
1472
1473
  }
1473
1474
  }
1475
+ Node.protoListenerMap = new Map();
1474
1476
  Node.prototype.nodeType = 'Node';
1475
1477
  Node.prototype._attrsAffectingSize = [];
1476
1478
  Node.prototype.eventListeners = {};
package/lib/Shape.js CHANGED
@@ -345,7 +345,15 @@ export class Shape extends Node {
345
345
  stage = this.getStage();
346
346
  const bc = bufferCanvas || stage.bufferCanvas;
347
347
  const bufferContext = bc.getContext();
348
- bufferContext.clear();
348
+ if (bufferCanvas) {
349
+ bufferContext.save();
350
+ bufferContext.setTransform(1, 0, 0, 1, 0, 0);
351
+ bufferContext.clearRect(0, 0, bc.width, bc.height);
352
+ bufferContext.restore();
353
+ }
354
+ else {
355
+ bufferContext.clear();
356
+ }
349
357
  bufferContext.save();
350
358
  bufferContext._applyLineJoin(this);
351
359
  bufferContext._applyMiterLimit(this);
package/lib/Tween.d.ts CHANGED
@@ -39,7 +39,7 @@ declare class TweenEngine {
39
39
  getTimer(): number;
40
40
  }
41
41
  export interface TweenConfig extends NodeConfig {
42
- easing?: typeof Easings[keyof typeof Easings];
42
+ easing?: (typeof Easings)[keyof typeof Easings];
43
43
  yoyo?: boolean;
44
44
  onReset?: Function;
45
45
  onFinish?: Function;
package/lib/Util.js CHANGED
@@ -320,7 +320,7 @@ let animQueue = [];
320
320
  let _isCanvasFarblingActive = null;
321
321
  const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
322
322
  function (f) {
323
- setTimeout(f, 60);
323
+ setTimeout(f, 16);
324
324
  };
325
325
  export const Util = {
326
326
  _isElement(obj) {
@@ -22,6 +22,35 @@ function expandPoints(p, tension) {
22
22
  }
23
23
  return allPoints;
24
24
  }
25
+ function getBezierExtremaPoints(points) {
26
+ const axisPoints = [
27
+ [points[0], points[2], points[4], points[6]],
28
+ [points[1], points[3], points[5], points[7]],
29
+ ];
30
+ const extremaTs = [];
31
+ for (const axis of axisPoints) {
32
+ const a = -3 * axis[0] + 9 * axis[1] - 9 * axis[2] + 3 * axis[3];
33
+ if (a !== 0) {
34
+ const b = 6 * axis[0] - 12 * axis[1] + 6 * axis[2];
35
+ const c = -3 * axis[0] + 3 * axis[1];
36
+ const discriminant = b * b - 4 * a * c;
37
+ if (discriminant >= 0) {
38
+ const d = Math.sqrt(discriminant);
39
+ extremaTs.push((-b + d) / (2 * a));
40
+ extremaTs.push((-b - d) / (2 * a));
41
+ }
42
+ }
43
+ }
44
+ return extremaTs
45
+ .filter((t) => t > 0 && t < 1)
46
+ .flatMap((t) => axisPoints.map((axis) => {
47
+ const mt = 1 - t;
48
+ return (mt * mt * mt * axis[0] +
49
+ 3 * mt * mt * t * axis[1] +
50
+ 3 * mt * t * t * axis[2] +
51
+ t * t * t * axis[3]);
52
+ }));
53
+ }
25
54
  export class Line extends Shape {
26
55
  constructor(config) {
27
56
  super(config);
@@ -123,6 +152,15 @@ export class Line extends Shape {
123
152
  points[points.length - 1],
124
153
  ];
125
154
  }
155
+ else if (this.bezier()) {
156
+ points = [
157
+ points[0],
158
+ points[1],
159
+ ...getBezierExtremaPoints(this.points()),
160
+ points[points.length - 2],
161
+ points[points.length - 1],
162
+ ];
163
+ }
126
164
  else {
127
165
  points = this.points();
128
166
  }
@@ -22,6 +22,7 @@ export interface TextConfig extends ShapeConfig {
22
22
  fontStyle?: string;
23
23
  fontVariant?: string;
24
24
  textDecoration?: string;
25
+ underlineOffset?: number;
25
26
  align?: string;
26
27
  verticalAlign?: string;
27
28
  padding?: number;
@@ -83,6 +84,7 @@ export declare class Text extends Shape<TextConfig> {
83
84
  padding: GetSet<number, this>;
84
85
  lineHeight: GetSet<number, this>;
85
86
  textDecoration: GetSet<string, this>;
87
+ underlineOffset: GetSet<number, this>;
86
88
  text: GetSet<string, this>;
87
89
  wrap: GetSet<string, this>;
88
90
  ellipsis: GetSet<boolean, this>;
@@ -99,7 +99,7 @@ export class Text extends Shape {
99
99
  if (!this.text()) {
100
100
  return;
101
101
  }
102
- 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;
102
+ 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;
103
103
  direction = direction === INHERIT ? context.direction : direction;
104
104
  let translateY = lineHeightPx / 2;
105
105
  let baseline = MIDDLE;
@@ -137,9 +137,9 @@ export class Text extends Shape {
137
137
  if (shouldUnderline) {
138
138
  context.save();
139
139
  context.beginPath();
140
- const yOffset = !Konva.legacyTextRendering
140
+ const yOffset = underlineOffset !== null && underlineOffset !== void 0 ? underlineOffset : (!Konva.legacyTextRendering
141
141
  ? Math.round(fontSize / 4)
142
- : Math.round(fontSize / 2);
142
+ : Math.round(fontSize / 2));
143
143
  const x = lineTranslateX;
144
144
  const y = translateY + lineTranslateY + yOffset;
145
145
  context.moveTo(x, y);
@@ -458,4 +458,5 @@ Factory.addGetterSetter(Text, 'ellipsis', false, getBooleanValidator());
458
458
  Factory.addGetterSetter(Text, 'letterSpacing', 0, getNumberValidator());
459
459
  Factory.addGetterSetter(Text, 'text', '', getStringValidator());
460
460
  Factory.addGetterSetter(Text, 'textDecoration', '');
461
+ Factory.addGetterSetter(Text, 'underlineOffset', undefined, getNumberValidator());
461
462
  Factory.addGetterSetter(Text, 'charRenderFunc', undefined);
@@ -8,6 +8,7 @@ export interface Box extends IRect {
8
8
  rotation: number;
9
9
  }
10
10
  export interface TransformerConfig extends ContainerConfig {
11
+ nodes?: Array<Node>;
11
12
  resizeEnabled?: boolean;
12
13
  rotateEnabled?: boolean;
13
14
  rotateLineVisible?: boolean;
@@ -29,7 +30,6 @@ export interface TransformerConfig extends ContainerConfig {
29
30
  centeredScaling?: boolean;
30
31
  enabledAnchors?: Array<string>;
31
32
  flipEnabled?: boolean;
32
- node?: Rect;
33
33
  ignoreStroke?: boolean;
34
34
  boundBoxFunc?: (oldBox: Box, newBox: Box) => Box;
35
35
  useSingleNodeRotation?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "10.0.12",
3
+ "version": "10.1.0",
4
4
  "description": "HTML5 2d canvas library.",
5
5
  "author": "Anton Lavrenov",
6
6
  "type": "module",
@@ -88,8 +88,8 @@
88
88
  "@parcel/transformer-image": "2.15.4",
89
89
  "@size-limit/preset-big-lib": "^11.2.0",
90
90
  "@types/mocha": "^10.0.10",
91
- "canvas": "^3.2.0",
92
- "chai": "6.0.1",
91
+ "canvas": "^3.2.1",
92
+ "chai": "6.2.2",
93
93
  "filehound": "^1.17.6",
94
94
  "gulp": "^5.0.1",
95
95
  "gulp-concat": "^2.6.1",
@@ -105,17 +105,17 @@
105
105
  "mocha": "^10",
106
106
  "mocha-headless-chrome": "^4.0.0",
107
107
  "parcel": "2.15.4",
108
- "prettier": "^3.6.2",
108
+ "prettier": "^3.7.4",
109
109
  "process": "^0.11.10",
110
- "rimraf": "^6.0.1",
111
- "rollup": "^4.48.0",
110
+ "rimraf": "^6.1.2",
111
+ "rollup": "^4.55.1",
112
112
  "rollup-plugin-typescript2": "^0.36.0",
113
113
  "size-limit": "^11.2.0",
114
114
  "skia-canvas": "^3.0.4",
115
115
  "ts-mocha": "^11.1.0",
116
116
  "ts-node": "^10.9.2",
117
- "tsx": "^4.20.5",
118
- "typescript": "^5.9.2"
117
+ "tsx": "^4.21.0",
118
+ "typescript": "^5.9.3"
119
119
  },
120
120
  "keywords": [
121
121
  "canvas",