konva 8.3.12 → 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,7 +60,11 @@ 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 {
67
+ constructor(canvas: Canvas);
63
68
  _fillColor(shape: Shape): void;
64
69
  _fillPattern(shape: any): void;
65
70
  _fillLinearGradient(shape: any): void;
@@ -70,7 +75,9 @@ export declare class SceneContext extends Context {
70
75
  _applyShadow(shape: any): void;
71
76
  }
72
77
  export declare class HitContext extends Context {
78
+ constructor(canvas: Canvas);
73
79
  _fill(shape: any): void;
74
80
  strokeShape(shape: Shape): void;
75
81
  _stroke(shape: any): void;
76
82
  }
83
+ export {};
package/cmj/Context.js CHANGED
@@ -73,7 +73,6 @@ const traceArrMax = 100;
73
73
  class Context {
74
74
  constructor(canvas) {
75
75
  this.canvas = canvas;
76
- this._context = canvas._canvas.getContext('2d');
77
76
  if (Global_1.Konva.enableTrace) {
78
77
  this.traceArr = [];
79
78
  this._enableTrace();
@@ -371,6 +370,7 @@ class Context {
371
370
  }
372
371
  }
373
372
  exports.Context = Context;
373
+ ;
374
374
  CONTEXT_PROPERTIES.forEach(function (prop) {
375
375
  Object.defineProperty(Context.prototype, prop, {
376
376
  get() {
@@ -382,6 +382,10 @@ CONTEXT_PROPERTIES.forEach(function (prop) {
382
382
  });
383
383
  });
384
384
  class SceneContext extends Context {
385
+ constructor(canvas) {
386
+ super(canvas);
387
+ this._context = canvas._canvas.getContext('2d');
388
+ }
385
389
  _fillColor(shape) {
386
390
  var fill = shape.fill();
387
391
  this.setAttr('fillStyle', fill);
@@ -492,6 +496,12 @@ class SceneContext extends Context {
492
496
  }
493
497
  exports.SceneContext = SceneContext;
494
498
  class HitContext extends Context {
499
+ constructor(canvas) {
500
+ super(canvas);
501
+ this._context = canvas._canvas.getContext('2d', {
502
+ willReadFrequently: true,
503
+ });
504
+ }
495
505
  _fill(shape) {
496
506
  this.save();
497
507
  this.setAttr('fillStyle', shape.colorKey);
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.12',
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.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface NodeConfig {
18
18
  listening?: boolean;
19
19
  id?: string;
20
20
  name?: string;
21
- opacity?: Number;
21
+ opacity?: number;
22
22
  scale?: Vector2d;
23
23
  scaleX?: number;
24
24
  scaleY?: number;
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/Shape.js CHANGED
@@ -152,8 +152,11 @@ class Shape extends Node_1.Node {
152
152
  return this._getCache(SHADOW_RGBA, this._getShadowRGBA);
153
153
  }
154
154
  _getShadowRGBA() {
155
- if (this.hasShadow()) {
156
- var rgba = Util_1.Util.colorToRGBA(this.shadowColor());
155
+ if (!this.hasShadow()) {
156
+ return;
157
+ }
158
+ var rgba = Util_1.Util.colorToRGBA(this.shadowColor());
159
+ if (rgba) {
157
160
  return ('rgba(' +
158
161
  rgba.r +
159
162
  ',' +
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() {
@@ -305,7 +306,7 @@ class Stage extends Container_1.Container {
305
306
  EVENTS.forEach(([event, methodName]) => {
306
307
  this.content.addEventListener(event, (evt) => {
307
308
  this[methodName](evt);
308
- });
309
+ }, { passive: false });
309
310
  });
310
311
  }
311
312
  _pointerenter(evt) {
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,
@@ -3,7 +3,6 @@ import { GetSet } from '../types';
3
3
  export interface RingConfig extends ShapeConfig {
4
4
  innerRadius: number;
5
5
  outerRadius: number;
6
- clockwise?: boolean;
7
6
  }
8
7
  export declare class Ring extends Shape<RingConfig> {
9
8
  _sceneFunc(context: any): void;
@@ -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.12
8
+ * Konva JavaScript Framework v8.3.14
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Mon Aug 29 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.12',
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) {
@@ -1452,7 +1471,6 @@
1452
1471
  class Context {
1453
1472
  constructor(canvas) {
1454
1473
  this.canvas = canvas;
1455
- this._context = canvas._canvas.getContext('2d');
1456
1474
  if (Konva$2.enableTrace) {
1457
1475
  this.traceArr = [];
1458
1476
  this._enableTrace();
@@ -1991,6 +2009,10 @@
1991
2009
  });
1992
2010
  });
1993
2011
  class SceneContext extends Context {
2012
+ constructor(canvas) {
2013
+ super(canvas);
2014
+ this._context = canvas._canvas.getContext('2d');
2015
+ }
1994
2016
  _fillColor(shape) {
1995
2017
  var fill = shape.fill();
1996
2018
  this.setAttr('fillStyle', fill);
@@ -2105,6 +2127,12 @@
2105
2127
  }
2106
2128
  }
2107
2129
  class HitContext extends Context {
2130
+ constructor(canvas) {
2131
+ super(canvas);
2132
+ this._context = canvas._canvas.getContext('2d', {
2133
+ willReadFrequently: true,
2134
+ });
2135
+ }
2108
2136
  _fill(shape) {
2109
2137
  this.save();
2110
2138
  this.setAttr('fillStyle', shape.colorKey);
@@ -2155,6 +2183,7 @@
2155
2183
  1;
2156
2184
  return devicePixelRatio / backingStoreRatio;
2157
2185
  })();
2186
+ Util.releaseCanvas(canvas);
2158
2187
  return _pixelRatio;
2159
2188
  }
2160
2189
  /**
@@ -2547,7 +2576,11 @@
2547
2576
  * node.clearCache();
2548
2577
  */
2549
2578
  clearCache() {
2550
- 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
+ }
2551
2584
  this._clearSelfAndDescendantCache();
2552
2585
  this._requestDraw();
2553
2586
  return this;
@@ -3033,6 +3066,7 @@
3033
3066
  */
3034
3067
  destroy() {
3035
3068
  this.remove();
3069
+ this.clearCache();
3036
3070
  return this;
3037
3071
  }
3038
3072
  /**
@@ -5988,6 +6022,7 @@
5988
6022
  if (index > -1) {
5989
6023
  stages.splice(index, 1);
5990
6024
  }
6025
+ Util.releaseCanvas(this.bufferCanvas._canvas, this.bufferHitCanvas._canvas);
5991
6026
  return this;
5992
6027
  }
5993
6028
  /**
@@ -6140,7 +6175,7 @@
6140
6175
  EVENTS.forEach(([event, methodName]) => {
6141
6176
  this.content.addEventListener(event, (evt) => {
6142
6177
  this[methodName](evt);
6143
- });
6178
+ }, { passive: false });
6144
6179
  });
6145
6180
  }
6146
6181
  _pointerenter(evt) {
@@ -6835,8 +6870,11 @@
6835
6870
  return this._getCache(SHADOW_RGBA, this._getShadowRGBA);
6836
6871
  }
6837
6872
  _getShadowRGBA() {
6838
- if (this.hasShadow()) {
6839
- var rgba = Util.colorToRGBA(this.shadowColor());
6873
+ if (!this.hasShadow()) {
6874
+ return;
6875
+ }
6876
+ var rgba = Util.colorToRGBA(this.shadowColor());
6877
+ if (rgba) {
6840
6878
  return ('rgba(' +
6841
6879
  rgba.r +
6842
6880
  ',' +
@@ -8608,6 +8646,10 @@
8608
8646
  parent.content.appendChild(this.hitCanvas._canvas);
8609
8647
  }
8610
8648
  }
8649
+ destroy() {
8650
+ Util.releaseCanvas(this.getNativeCanvasElement(), this.getHitCanvas()._canvas);
8651
+ return super.destroy();
8652
+ }
8611
8653
  }
8612
8654
  Layer.prototype.nodeType = 'Layer';
8613
8655
  _registerNode(Layer);
@@ -12502,7 +12544,6 @@
12502
12544
  * @param {Object} config
12503
12545
  * @param {Number} config.innerRadius
12504
12546
  * @param {Number} config.outerRadius
12505
- * @param {Boolean} [config.clockwise]
12506
12547
  * @param {String} [config.fill] fill color
12507
12548
  * @param {Image} [config.fillPatternImage] fill pattern image
12508
12549
  * @param {Number} [config.fillPatternX]
@@ -14396,6 +14437,10 @@
14396
14437
  height: maxY - minY + fontSize,
14397
14438
  };
14398
14439
  }
14440
+ destroy() {
14441
+ Util.releaseCanvas(this.dummyCanvas);
14442
+ return super.destroy();
14443
+ }
14399
14444
  }
14400
14445
  TextPath.prototype._fillFunc = _fillFunc;
14401
14446
  TextPath.prototype._strokeFunc = _strokeFunc;
@@ -17582,6 +17627,7 @@
17582
17627
  var scratchData = tempCanvas
17583
17628
  .getContext('2d')
17584
17629
  .getImageData(0, 0, xSize, ySize);
17630
+ Util.releaseCanvas(tempCanvas);
17585
17631
  // Convert thhe original to polar coordinates
17586
17632
  ToPolar(imageData, scratchData, {
17587
17633
  polarCenterX: xSize / 2,