konva 8.3.13 → 8.3.14

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/cmj/Canvas.js CHANGED
@@ -22,6 +22,7 @@ function getDevicePixelRatio() {
22
22
  1;
23
23
  return devicePixelRatio / backingStoreRatio;
24
24
  })();
25
+ Util_1.Util.releaseCanvas(canvas);
25
26
  return _pixelRatio;
26
27
  }
27
28
  class Canvas {
package/cmj/Context.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Canvas } from './Canvas';
2
2
  import { Shape } from './Shape';
3
+ declare var CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled"];
3
4
  export declare class Context {
4
5
  canvas: Canvas;
5
6
  _context: CanvasRenderingContext2D;
@@ -59,6 +60,9 @@ export declare class Context {
59
60
  _enableTrace(): void;
60
61
  _applyGlobalCompositeOperation(node: any): void;
61
62
  }
63
+ declare type CanvasContextProps = Pick<CanvasRenderingContext2D, typeof CONTEXT_PROPERTIES[number]>;
64
+ export interface Context extends CanvasContextProps {
65
+ }
62
66
  export declare class SceneContext extends Context {
63
67
  constructor(canvas: Canvas);
64
68
  _fillColor(shape: Shape): void;
@@ -76,3 +80,4 @@ export declare class HitContext extends Context {
76
80
  strokeShape(shape: Shape): void;
77
81
  _stroke(shape: any): void;
78
82
  }
83
+ export {};
package/cmj/Context.js CHANGED
@@ -370,6 +370,7 @@ class Context {
370
370
  }
371
371
  }
372
372
  exports.Context = Context;
373
+ ;
373
374
  CONTEXT_PROPERTIES.forEach(function (prop) {
374
375
  Object.defineProperty(Context.prototype, prop, {
375
376
  get() {
package/cmj/Global.d.ts CHANGED
@@ -27,6 +27,7 @@ export declare const Konva: {
27
27
  dragButtons: number[];
28
28
  isDragging(): any;
29
29
  isDragReady(): boolean;
30
+ releaseCanvasOnDestroy: boolean;
30
31
  document: any;
31
32
  _injectGlobal(Konva: any): void;
32
33
  };
package/cmj/Global.js CHANGED
@@ -16,7 +16,7 @@ exports.glob = typeof global !== 'undefined'
16
16
  : {};
17
17
  exports.Konva = {
18
18
  _global: exports.glob,
19
- version: '8.3.13',
19
+ version: '8.3.14',
20
20
  isBrowser: detectBrowser(),
21
21
  isUnminified: /param/.test(function (param) { }.toString()),
22
22
  dblClickWindow: 400,
@@ -48,6 +48,7 @@ exports.Konva = {
48
48
  isDragReady() {
49
49
  return !!exports.Konva['DD'].node;
50
50
  },
51
+ releaseCanvasOnDestroy: true,
51
52
  document: exports.glob.document,
52
53
  _injectGlobal(Konva) {
53
54
  exports.glob.Konva = Konva;
package/cmj/Layer.d.ts CHANGED
@@ -54,6 +54,7 @@ export declare class Layer extends Container<Group | Shape> {
54
54
  setHitGraphEnabled(val: any): void;
55
55
  getHitGraphEnabled(val: any): boolean;
56
56
  toggleHitCanvas(): void;
57
+ destroy(): this;
57
58
  hitGraphEnabled: GetSet<boolean, this>;
58
59
  clearBeforeDraw: GetSet<boolean, this>;
59
60
  imageSmoothingEnabled: GetSet<boolean, this>;
package/cmj/Layer.js CHANGED
@@ -296,6 +296,10 @@ class Layer extends Container_1.Container {
296
296
  parent.content.appendChild(this.hitCanvas._canvas);
297
297
  }
298
298
  }
299
+ destroy() {
300
+ Util_1.Util.releaseCanvas(this.getNativeCanvasElement(), this.getHitCanvas()._canvas);
301
+ return super.destroy();
302
+ }
299
303
  }
300
304
  exports.Layer = Layer;
301
305
  Layer.prototype.nodeType = 'Layer';
package/cmj/Node.js CHANGED
@@ -85,7 +85,11 @@ class Node {
85
85
  }
86
86
  }
87
87
  clearCache() {
88
- this._cache.delete(CANVAS);
88
+ if (this._cache.has(CANVAS)) {
89
+ const { scene, filter, hit } = this._cache.get(CANVAS);
90
+ Util_1.Util.releaseCanvas(scene, filter, hit);
91
+ this._cache.delete(CANVAS);
92
+ }
89
93
  this._clearSelfAndDescendantCache();
90
94
  this._requestDraw();
91
95
  return this;
@@ -353,6 +357,7 @@ class Node {
353
357
  }
354
358
  destroy() {
355
359
  this.remove();
360
+ this.clearCache();
356
361
  return this;
357
362
  }
358
363
  getAttr(attr) {
package/cmj/Stage.js CHANGED
@@ -182,6 +182,7 @@ class Stage extends Container_1.Container {
182
182
  if (index > -1) {
183
183
  exports.stages.splice(index, 1);
184
184
  }
185
+ Util_1.Util.releaseCanvas(this.bufferCanvas._canvas, this.bufferHitCanvas._canvas);
185
186
  return this;
186
187
  }
187
188
  getPointerPosition() {
package/cmj/Util.d.ts CHANGED
@@ -83,4 +83,5 @@ export declare const Util: {
83
83
  _prepareToStringify(obj: any): any;
84
84
  _assign<T, U>(target: T, source: U): T & U;
85
85
  _getFirstPointerId(evt: any): any;
86
+ releaseCanvas(...canvases: HTMLCanvasElement[]): void;
86
87
  };
package/cmj/Util.js CHANGED
@@ -744,4 +744,12 @@ exports.Util = {
744
744
  return evt.changedTouches[0].identifier;
745
745
  }
746
746
  },
747
+ releaseCanvas(...canvases) {
748
+ if (!Global_1.Konva.releaseCanvasOnDestroy)
749
+ return;
750
+ canvases.forEach(c => {
751
+ c.width = 0;
752
+ c.height = 0;
753
+ });
754
+ }
747
755
  };
@@ -38,6 +38,7 @@ export declare const Konva: {
38
38
  dragButtons: number[];
39
39
  isDragging(): any;
40
40
  isDragReady(): boolean;
41
+ releaseCanvasOnDestroy: boolean;
41
42
  document: any;
42
43
  _injectGlobal(Konva: any): void;
43
44
  } & {
@@ -93,6 +94,7 @@ export declare const Konva: {
93
94
  _prepareToStringify(obj: any): any;
94
95
  _assign<T, U>(target: T, source: U): T & U;
95
96
  _getFirstPointerId(evt: any): any;
97
+ releaseCanvas(...canvases: HTMLCanvasElement[]): void;
96
98
  };
97
99
  Transform: typeof Transform;
98
100
  Node: typeof Node;
@@ -43,6 +43,7 @@ export declare const Konva: {
43
43
  dragButtons: number[];
44
44
  isDragging(): any;
45
45
  isDragReady(): boolean;
46
+ releaseCanvasOnDestroy: boolean;
46
47
  document: any;
47
48
  _injectGlobal(Konva: any): void;
48
49
  } & {
@@ -98,6 +99,7 @@ export declare const Konva: {
98
99
  _prepareToStringify(obj: any): any;
99
100
  _assign<T, U>(target: T, source: U): T & U;
100
101
  _getFirstPointerId(evt: any): any;
102
+ releaseCanvas(...canvases: HTMLCanvasElement[]): void;
101
103
  };
102
104
  Transform: typeof import("./Util").Transform;
103
105
  Node: typeof import("./Node").Node;
@@ -79,6 +79,7 @@ const Kaleidoscope = function (imageData) {
79
79
  var scratchData = tempCanvas
80
80
  .getContext('2d')
81
81
  .getImageData(0, 0, xSize, ySize);
82
+ Util_1.Util.releaseCanvas(tempCanvas);
82
83
  ToPolar(imageData, scratchData, {
83
84
  polarCenterX: xSize / 2,
84
85
  polarCenterY: ySize / 2,
@@ -40,6 +40,7 @@ export declare class TextPath extends Shape<TextPathConfig> {
40
40
  width: number;
41
41
  height: number;
42
42
  };
43
+ destroy(): this;
43
44
  fontFamily: GetSet<string, this>;
44
45
  fontSize: GetSet<number, this>;
45
46
  fontStyle: GetSet<string, this>;
@@ -325,6 +325,10 @@ class TextPath extends Shape_1.Shape {
325
325
  height: maxY - minY + fontSize,
326
326
  };
327
327
  }
328
+ destroy() {
329
+ Util_1.Util.releaseCanvas(this.dummyCanvas);
330
+ return super.destroy();
331
+ }
328
332
  }
329
333
  exports.TextPath = TextPath;
330
334
  TextPath.prototype._fillFunc = _fillFunc;
package/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v8.3.13
8
+ * Konva JavaScript Framework v8.3.14
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Mon Oct 03 2022
11
+ * Date: Wed Nov 09 2022
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: '8.3.13',
38
+ version: '8.3.14',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -157,6 +157,17 @@
157
157
  isDragReady() {
158
158
  return !!Konva$2['DD'].node;
159
159
  },
160
+ /**
161
+ * Should Konva release canvas elements on destroy. Default is true.
162
+ * Useful to avoid memory leak issues in Safari on macOS/iOS.
163
+ * @property releaseCanvasOnDestroy
164
+ * @default true
165
+ * @name releaseCanvasOnDestroy
166
+ * @memberof Konva
167
+ * @example
168
+ * Konva.releaseCanvasOnDestroy = true;
169
+ */
170
+ releaseCanvasOnDestroy: true,
160
171
  // user agent
161
172
  document: glob.document,
162
173
  // insert Konva into global namespace (window)
@@ -1071,6 +1082,14 @@
1071
1082
  return evt.changedTouches[0].identifier;
1072
1083
  }
1073
1084
  },
1085
+ releaseCanvas(...canvases) {
1086
+ if (!Konva$2.releaseCanvasOnDestroy)
1087
+ return;
1088
+ canvases.forEach(c => {
1089
+ c.width = 0;
1090
+ c.height = 0;
1091
+ });
1092
+ }
1074
1093
  };
1075
1094
 
1076
1095
  function _formatValue(val) {
@@ -2164,6 +2183,7 @@
2164
2183
  1;
2165
2184
  return devicePixelRatio / backingStoreRatio;
2166
2185
  })();
2186
+ Util.releaseCanvas(canvas);
2167
2187
  return _pixelRatio;
2168
2188
  }
2169
2189
  /**
@@ -2556,7 +2576,11 @@
2556
2576
  * node.clearCache();
2557
2577
  */
2558
2578
  clearCache() {
2559
- this._cache.delete(CANVAS);
2579
+ if (this._cache.has(CANVAS)) {
2580
+ const { scene, filter, hit } = this._cache.get(CANVAS);
2581
+ Util.releaseCanvas(scene, filter, hit);
2582
+ this._cache.delete(CANVAS);
2583
+ }
2560
2584
  this._clearSelfAndDescendantCache();
2561
2585
  this._requestDraw();
2562
2586
  return this;
@@ -3042,6 +3066,7 @@
3042
3066
  */
3043
3067
  destroy() {
3044
3068
  this.remove();
3069
+ this.clearCache();
3045
3070
  return this;
3046
3071
  }
3047
3072
  /**
@@ -5997,6 +6022,7 @@
5997
6022
  if (index > -1) {
5998
6023
  stages.splice(index, 1);
5999
6024
  }
6025
+ Util.releaseCanvas(this.bufferCanvas._canvas, this.bufferHitCanvas._canvas);
6000
6026
  return this;
6001
6027
  }
6002
6028
  /**
@@ -8620,6 +8646,10 @@
8620
8646
  parent.content.appendChild(this.hitCanvas._canvas);
8621
8647
  }
8622
8648
  }
8649
+ destroy() {
8650
+ Util.releaseCanvas(this.getNativeCanvasElement(), this.getHitCanvas()._canvas);
8651
+ return super.destroy();
8652
+ }
8623
8653
  }
8624
8654
  Layer.prototype.nodeType = 'Layer';
8625
8655
  _registerNode(Layer);
@@ -14407,6 +14437,10 @@
14407
14437
  height: maxY - minY + fontSize,
14408
14438
  };
14409
14439
  }
14440
+ destroy() {
14441
+ Util.releaseCanvas(this.dummyCanvas);
14442
+ return super.destroy();
14443
+ }
14410
14444
  }
14411
14445
  TextPath.prototype._fillFunc = _fillFunc;
14412
14446
  TextPath.prototype._strokeFunc = _strokeFunc;
@@ -17593,6 +17627,7 @@
17593
17627
  var scratchData = tempCanvas
17594
17628
  .getContext('2d')
17595
17629
  .getImageData(0, 0, xSize, ySize);
17630
+ Util.releaseCanvas(tempCanvas);
17596
17631
  // Convert thhe original to polar coordinates
17597
17632
  ToPolar(imageData, scratchData, {
17598
17633
  polarCenterX: xSize / 2,