konva 8.4.2 → 9.0.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.
Files changed (242) hide show
  1. package/README.md +1 -9
  2. package/konva.js +17669 -16968
  3. package/konva.min.js +3 -3
  4. package/lib/Animation.d.ts +2 -2
  5. package/lib/Animation.js +11 -7
  6. package/lib/BezierFunctions.d.ts +6 -0
  7. package/lib/BezierFunctions.js +791 -0
  8. package/lib/Canvas.d.ts +2 -1
  9. package/lib/Canvas.js +26 -18
  10. package/lib/Container.d.ts +4 -4
  11. package/lib/Container.js +16 -12
  12. package/lib/Context.d.ts +16 -13
  13. package/lib/Context.js +27 -19
  14. package/lib/Core.d.ts +2 -2
  15. package/lib/Core.js +7 -3
  16. package/lib/DragAndDrop.d.ts +3 -3
  17. package/lib/DragAndDrop.js +25 -22
  18. package/lib/Factory.js +27 -24
  19. package/lib/FastLayer.d.ts +1 -1
  20. package/lib/FastLayer.js +10 -6
  21. package/lib/Global.js +16 -12
  22. package/lib/Group.d.ts +3 -3
  23. package/lib/Group.js +10 -6
  24. package/lib/Layer.d.ts +9 -9
  25. package/lib/Layer.js +37 -33
  26. package/lib/Node.d.ts +8 -8
  27. package/lib/Node.js +95 -90
  28. package/lib/PointerEvents.d.ts +4 -4
  29. package/lib/PointerEvents.js +15 -7
  30. package/lib/Shape.d.ts +6 -4
  31. package/lib/Shape.js +90 -86
  32. package/lib/Stage.d.ts +7 -7
  33. package/lib/Stage.js +51 -47
  34. package/lib/Tween.d.ts +2 -2
  35. package/lib/Tween.js +26 -22
  36. package/lib/Util.d.ts +2 -2
  37. package/lib/Util.js +29 -25
  38. package/lib/Validators.js +58 -44
  39. package/lib/_CoreInternals.d.ts +29 -29
  40. package/lib/_CoreInternals.js +36 -33
  41. package/lib/_FullInternals.d.ts +67 -67
  42. package/lib/_FullInternals.js +78 -75
  43. package/lib/filters/Blur.d.ts +1 -1
  44. package/lib/filters/Blur.js +9 -5
  45. package/lib/filters/Brighten.d.ts +1 -1
  46. package/lib/filters/Brighten.js +9 -5
  47. package/lib/filters/Contrast.d.ts +1 -1
  48. package/lib/filters/Contrast.js +9 -5
  49. package/lib/filters/Emboss.d.ts +1 -1
  50. package/lib/filters/Emboss.js +14 -10
  51. package/lib/filters/Enhance.d.ts +1 -1
  52. package/lib/filters/Enhance.js +9 -5
  53. package/lib/filters/Grayscale.d.ts +1 -1
  54. package/lib/filters/Grayscale.js +5 -1
  55. package/lib/filters/HSL.d.ts +1 -1
  56. package/lib/filters/HSL.js +11 -7
  57. package/lib/filters/HSV.d.ts +1 -1
  58. package/lib/filters/HSV.js +11 -7
  59. package/lib/filters/Invert.d.ts +1 -1
  60. package/lib/filters/Invert.js +5 -1
  61. package/lib/filters/Kaleidoscope.d.ts +1 -1
  62. package/lib/filters/Kaleidoscope.js +13 -9
  63. package/lib/filters/Mask.d.ts +1 -1
  64. package/lib/filters/Mask.js +9 -5
  65. package/lib/filters/Noise.d.ts +1 -1
  66. package/lib/filters/Noise.js +9 -5
  67. package/lib/filters/Pixelate.d.ts +1 -1
  68. package/lib/filters/Pixelate.js +11 -7
  69. package/lib/filters/Posterize.d.ts +1 -1
  70. package/lib/filters/Posterize.js +9 -5
  71. package/lib/filters/RGB.d.ts +1 -1
  72. package/lib/filters/RGB.js +11 -7
  73. package/lib/filters/RGBA.d.ts +1 -1
  74. package/lib/filters/RGBA.js +12 -8
  75. package/lib/filters/Sepia.d.ts +1 -1
  76. package/lib/filters/Sepia.js +5 -1
  77. package/lib/filters/Solarize.d.ts +1 -1
  78. package/lib/filters/Solarize.js +5 -1
  79. package/lib/filters/Threshold.d.ts +1 -1
  80. package/lib/filters/Threshold.js +9 -5
  81. package/lib/index-node.d.ts +1 -1
  82. package/lib/index-node.js +7 -5
  83. package/lib/index-types.d.ts +124 -124
  84. package/lib/index.d.ts +1 -1
  85. package/lib/index.js +4 -2
  86. package/lib/shapes/Arc.d.ts +6 -5
  87. package/lib/shapes/Arc.js +17 -13
  88. package/lib/shapes/Arrow.d.ts +5 -4
  89. package/lib/shapes/Arrow.js +17 -13
  90. package/lib/shapes/Circle.d.ts +6 -5
  91. package/lib/shapes/Circle.js +11 -7
  92. package/lib/shapes/Ellipse.d.ts +6 -5
  93. package/lib/shapes/Ellipse.js +13 -9
  94. package/lib/shapes/Image.d.ts +5 -5
  95. package/lib/shapes/Image.js +21 -17
  96. package/lib/shapes/Label.d.ts +8 -7
  97. package/lib/shapes/Label.js +18 -13
  98. package/lib/shapes/Line.d.ts +3 -3
  99. package/lib/shapes/Line.js +14 -10
  100. package/lib/shapes/Path.d.ts +6 -3
  101. package/lib/shapes/Path.js +44 -43
  102. package/lib/shapes/Rect.d.ts +3 -3
  103. package/lib/shapes/Rect.js +13 -9
  104. package/lib/shapes/RegularPolygon.d.ts +6 -5
  105. package/lib/shapes/RegularPolygon.js +12 -8
  106. package/lib/shapes/Ring.d.ts +6 -5
  107. package/lib/shapes/Ring.js +12 -8
  108. package/lib/shapes/Sprite.d.ts +7 -6
  109. package/lib/shapes/Sprite.js +19 -15
  110. package/lib/shapes/Star.d.ts +6 -5
  111. package/lib/shapes/Star.js +13 -9
  112. package/lib/shapes/Text.d.ts +8 -7
  113. package/lib/shapes/Text.js +31 -26
  114. package/lib/shapes/TextPath.d.ts +12 -7
  115. package/lib/shapes/TextPath.js +82 -188
  116. package/lib/shapes/Transformer.d.ts +10 -10
  117. package/lib/shapes/Transformer.js +92 -81
  118. package/lib/shapes/Wedge.d.ts +6 -5
  119. package/lib/shapes/Wedge.js +16 -12
  120. package/lib/types.d.ts +6 -0
  121. package/lib/types.js +5 -2
  122. package/package.json +13 -42
  123. package/cmj/Animation.d.ts +0 -24
  124. package/cmj/Animation.js +0 -145
  125. package/cmj/Canvas.d.ts +0 -32
  126. package/cmj/Canvas.js +0 -114
  127. package/cmj/Container.d.ts +0 -47
  128. package/cmj/Container.js +0 -325
  129. package/cmj/Context.d.ts +0 -84
  130. package/cmj/Context.js +0 -538
  131. package/cmj/Core.d.ts +0 -3
  132. package/cmj/Core.js +0 -7
  133. package/cmj/DragAndDrop.d.ts +0 -17
  134. package/cmj/DragAndDrop.js +0 -111
  135. package/cmj/Factory.d.ts +0 -11
  136. package/cmj/Factory.js +0 -125
  137. package/cmj/FastLayer.d.ts +0 -4
  138. package/cmj/FastLayer.js +0 -16
  139. package/cmj/Global.d.ts +0 -34
  140. package/cmj/Global.js +0 -61
  141. package/cmj/Group.d.ts +0 -8
  142. package/cmj/Group.js +0 -17
  143. package/cmj/Layer.d.ts +0 -61
  144. package/cmj/Layer.js +0 -309
  145. package/cmj/Node.d.ts +0 -328
  146. package/cmj/Node.js +0 -1420
  147. package/cmj/PointerEvents.d.ts +0 -11
  148. package/cmj/PointerEvents.js +0 -45
  149. package/cmj/Shape.d.ts +0 -184
  150. package/cmj/Shape.js +0 -521
  151. package/cmj/Stage.d.ts +0 -85
  152. package/cmj/Stage.js +0 -692
  153. package/cmj/Tween.d.ts +0 -86
  154. package/cmj/Tween.js +0 -520
  155. package/cmj/Util.d.ts +0 -91
  156. package/cmj/Util.js +0 -801
  157. package/cmj/Validators.d.ts +0 -11
  158. package/cmj/Validators.js +0 -192
  159. package/cmj/_CoreInternals.d.ts +0 -152
  160. package/cmj/_CoreInternals.js +0 -37
  161. package/cmj/_FullInternals.d.ts +0 -196
  162. package/cmj/_FullInternals.js +0 -81
  163. package/cmj/filters/Blur.d.ts +0 -2
  164. package/cmj/filters/Blur.js +0 -701
  165. package/cmj/filters/Brighten.d.ts +0 -2
  166. package/cmj/filters/Brighten.js +0 -16
  167. package/cmj/filters/Contrast.d.ts +0 -2
  168. package/cmj/filters/Contrast.js +0 -38
  169. package/cmj/filters/Emboss.d.ts +0 -2
  170. package/cmj/filters/Emboss.js +0 -106
  171. package/cmj/filters/Enhance.d.ts +0 -2
  172. package/cmj/filters/Enhance.js +0 -87
  173. package/cmj/filters/Grayscale.d.ts +0 -2
  174. package/cmj/filters/Grayscale.js +0 -13
  175. package/cmj/filters/HSL.d.ts +0 -2
  176. package/cmj/filters/HSL.js +0 -28
  177. package/cmj/filters/HSV.d.ts +0 -2
  178. package/cmj/filters/HSV.js +0 -28
  179. package/cmj/filters/Invert.d.ts +0 -2
  180. package/cmj/filters/Invert.js +0 -12
  181. package/cmj/filters/Kaleidoscope.d.ts +0 -2
  182. package/cmj/filters/Kaleidoscope.js +0 -137
  183. package/cmj/filters/Mask.d.ts +0 -2
  184. package/cmj/filters/Mask.js +0 -144
  185. package/cmj/filters/Noise.d.ts +0 -2
  186. package/cmj/filters/Noise.js +0 -16
  187. package/cmj/filters/Pixelate.d.ts +0 -2
  188. package/cmj/filters/Pixelate.js +0 -64
  189. package/cmj/filters/Posterize.d.ts +0 -2
  190. package/cmj/filters/Posterize.js +0 -14
  191. package/cmj/filters/RGB.d.ts +0 -2
  192. package/cmj/filters/RGB.js +0 -43
  193. package/cmj/filters/RGBA.d.ts +0 -2
  194. package/cmj/filters/RGBA.js +0 -53
  195. package/cmj/filters/Sepia.d.ts +0 -2
  196. package/cmj/filters/Sepia.js +0 -15
  197. package/cmj/filters/Solarize.d.ts +0 -2
  198. package/cmj/filters/Solarize.js +0 -29
  199. package/cmj/filters/Threshold.d.ts +0 -2
  200. package/cmj/filters/Threshold.js +0 -14
  201. package/cmj/index-node.d.ts +0 -2
  202. package/cmj/index-node.js +0 -21
  203. package/cmj/index-types.d.ts +0 -181
  204. package/cmj/index.d.ts +0 -2
  205. package/cmj/index.js +0 -4
  206. package/cmj/package.json +0 -6
  207. package/cmj/shapes/Arc.d.ts +0 -25
  208. package/cmj/shapes/Arc.js +0 -59
  209. package/cmj/shapes/Arrow.d.ts +0 -25
  210. package/cmj/shapes/Arrow.js +0 -103
  211. package/cmj/shapes/Circle.d.ts +0 -13
  212. package/cmj/shapes/Circle.js +0 -37
  213. package/cmj/shapes/Ellipse.d.ts +0 -16
  214. package/cmj/shapes/Ellipse.js +0 -41
  215. package/cmj/shapes/Image.d.ts +0 -25
  216. package/cmj/shapes/Image.js +0 -117
  217. package/cmj/shapes/Label.d.ts +0 -35
  218. package/cmj/shapes/Label.js +0 -178
  219. package/cmj/shapes/Line.d.ts +0 -28
  220. package/cmj/shapes/Line.js +0 -159
  221. package/cmj/shapes/Path.d.ts +0 -37
  222. package/cmj/shapes/Path.js +0 -631
  223. package/cmj/shapes/Rect.d.ts +0 -10
  224. package/cmj/shapes/Rect.js +0 -26
  225. package/cmj/shapes/RegularPolygon.d.ts +0 -22
  226. package/cmj/shapes/RegularPolygon.js +0 -69
  227. package/cmj/shapes/Ring.d.ts +0 -15
  228. package/cmj/shapes/Ring.js +0 -37
  229. package/cmj/shapes/Sprite.d.ts +0 -30
  230. package/cmj/shapes/Sprite.js +0 -112
  231. package/cmj/shapes/Star.d.ts +0 -17
  232. package/cmj/shapes/Star.js +0 -42
  233. package/cmj/shapes/Text.d.ts +0 -62
  234. package/cmj/shapes/Text.js +0 -373
  235. package/cmj/shapes/TextPath.d.ts +0 -55
  236. package/cmj/shapes/TextPath.js +0 -351
  237. package/cmj/shapes/Transformer.d.ts +0 -116
  238. package/cmj/shapes/Transformer.js +0 -964
  239. package/cmj/shapes/Wedge.d.ts +0 -17
  240. package/cmj/shapes/Wedge.js +0 -42
  241. package/cmj/types.d.ts +0 -50
  242. package/cmj/types.js +0 -25
package/lib/Canvas.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { Context } from './Context';
1
+ import { Context } from './Context.js';
2
2
  interface ICanvasConfig {
3
3
  width?: number;
4
4
  height?: number;
5
5
  pixelRatio?: number;
6
+ willReadFrequently?: boolean;
6
7
  }
7
8
  export declare class Canvas {
8
9
  pixelRatio: number;
package/lib/Canvas.js CHANGED
@@ -1,17 +1,20 @@
1
- import { Util } from './Util.js';
2
- import { SceneContext, HitContext } from './Context.js';
3
- import { Konva } from './Global.js';
4
- import { Factory } from './Factory.js';
5
- import { getNumberValidator } from './Validators.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HitCanvas = exports.SceneCanvas = exports.Canvas = void 0;
4
+ const Util_1 = require("./Util");
5
+ const Context_1 = require("./Context");
6
+ const Global_1 = require("./Global");
7
+ const Factory_1 = require("./Factory");
8
+ const Validators_1 = require("./Validators");
6
9
  var _pixelRatio;
7
10
  function getDevicePixelRatio() {
8
11
  if (_pixelRatio) {
9
12
  return _pixelRatio;
10
13
  }
11
- var canvas = Util.createCanvasElement();
14
+ var canvas = Util_1.Util.createCanvasElement();
12
15
  var context = canvas.getContext('2d');
13
16
  _pixelRatio = (function () {
14
- var devicePixelRatio = Konva._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
17
+ var devicePixelRatio = Global_1.Konva._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
15
18
  context.mozBackingStorePixelRatio ||
16
19
  context.msBackingStorePixelRatio ||
17
20
  context.oBackingStorePixelRatio ||
@@ -19,19 +22,19 @@ function getDevicePixelRatio() {
19
22
  1;
20
23
  return devicePixelRatio / backingStoreRatio;
21
24
  })();
22
- Util.releaseCanvas(canvas);
25
+ Util_1.Util.releaseCanvas(canvas);
23
26
  return _pixelRatio;
24
27
  }
25
- export class Canvas {
28
+ class Canvas {
26
29
  constructor(config) {
27
30
  this.pixelRatio = 1;
28
31
  this.width = 0;
29
32
  this.height = 0;
30
33
  this.isCache = false;
31
34
  var conf = config || {};
32
- var pixelRatio = conf.pixelRatio || Konva.pixelRatio || getDevicePixelRatio();
35
+ var pixelRatio = conf.pixelRatio || Global_1.Konva.pixelRatio || getDevicePixelRatio();
33
36
  this.pixelRatio = pixelRatio;
34
- this._canvas = Util.createCanvasElement();
37
+ this._canvas = Util_1.Util.createCanvasElement();
35
38
  this._canvas.style.padding = '0';
36
39
  this._canvas.style.margin = '0';
37
40
  this._canvas.style.border = '0';
@@ -82,7 +85,7 @@ export class Canvas {
82
85
  return this._canvas.toDataURL();
83
86
  }
84
87
  catch (err) {
85
- Util.error('Unable to get data URL. ' +
88
+ Util_1.Util.error('Unable to get data URL. ' +
86
89
  err.message +
87
90
  ' For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html.');
88
91
  return '';
@@ -90,19 +93,24 @@ export class Canvas {
90
93
  }
91
94
  }
92
95
  }
93
- Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, getNumberValidator());
94
- export class SceneCanvas extends Canvas {
95
- constructor(config = { width: 0, height: 0 }) {
96
+ exports.Canvas = Canvas;
97
+ Factory_1.Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, (0, Validators_1.getNumberValidator)());
98
+ class SceneCanvas extends Canvas {
99
+ constructor(config = { width: 0, height: 0, willReadFrequently: false }) {
96
100
  super(config);
97
- this.context = new SceneContext(this);
101
+ this.context = new Context_1.SceneContext(this, {
102
+ willReadFrequently: config.willReadFrequently,
103
+ });
98
104
  this.setSize(config.width, config.height);
99
105
  }
100
106
  }
101
- export class HitCanvas extends Canvas {
107
+ exports.SceneCanvas = SceneCanvas;
108
+ class HitCanvas extends Canvas {
102
109
  constructor(config = { width: 0, height: 0 }) {
103
110
  super(config);
104
111
  this.hitCanvas = true;
105
- this.context = new HitContext(this);
112
+ this.context = new Context_1.HitContext(this);
106
113
  this.setSize(config.width, config.height);
107
114
  }
108
115
  }
116
+ exports.HitCanvas = HitCanvas;
@@ -1,7 +1,7 @@
1
- import { Node, NodeConfig } from './Node';
2
- import { GetSet, IRect } from './types';
3
- import { HitCanvas, SceneCanvas } from './Canvas';
4
- import { SceneContext } from './Context';
1
+ import { Node, NodeConfig } from './Node.js';
2
+ import { GetSet, IRect } from './types.js';
3
+ import { HitCanvas, SceneCanvas } from './Canvas.js';
4
+ import { SceneContext } from './Context.js';
5
5
  export interface ContainerConfig extends NodeConfig {
6
6
  clearBeforeDraw?: boolean;
7
7
  clipFunc?: (ctx: SceneContext) => void;
package/lib/Container.js CHANGED
@@ -1,7 +1,10 @@
1
- import { Factory } from './Factory.js';
2
- import { Node } from './Node.js';
3
- import { getNumberValidator } from './Validators.js';
4
- export class Container extends Node {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Container = void 0;
4
+ const Factory_1 = require("./Factory");
5
+ const Node_1 = require("./Node");
6
+ const Validators_1 = require("./Validators");
7
+ class Container extends Node_1.Node {
5
8
  constructor() {
6
9
  super(...arguments);
7
10
  this.children = [];
@@ -115,7 +118,7 @@ export class Container extends Node {
115
118
  return false;
116
119
  }
117
120
  toObject() {
118
- var obj = Node.prototype.toObject.call(this);
121
+ var obj = Node_1.Node.prototype.toObject.call(this);
119
122
  obj.children = [];
120
123
  this.getChildren().forEach((child) => {
121
124
  obj.children.push(child.toObject());
@@ -133,7 +136,7 @@ export class Container extends Node {
133
136
  return false;
134
137
  }
135
138
  clone(obj) {
136
- var node = Node.prototype.clone.call(this, obj);
139
+ var node = Node_1.Node.prototype.clone.call(this, obj);
137
140
  this.getChildren().forEach(function (no) {
138
141
  node.add(no.clone());
139
142
  });
@@ -308,14 +311,15 @@ export class Container extends Node {
308
311
  return selfRect;
309
312
  }
310
313
  }
311
- Factory.addComponentsGetterSetter(Container, 'clip', [
314
+ exports.Container = Container;
315
+ Factory_1.Factory.addComponentsGetterSetter(Container, 'clip', [
312
316
  'x',
313
317
  'y',
314
318
  'width',
315
319
  'height',
316
320
  ]);
317
- Factory.addGetterSetter(Container, 'clipX', undefined, getNumberValidator());
318
- Factory.addGetterSetter(Container, 'clipY', undefined, getNumberValidator());
319
- Factory.addGetterSetter(Container, 'clipWidth', undefined, getNumberValidator());
320
- Factory.addGetterSetter(Container, 'clipHeight', undefined, getNumberValidator());
321
- Factory.addGetterSetter(Container, 'clipFunc');
321
+ Factory_1.Factory.addGetterSetter(Container, 'clipX', undefined, (0, Validators_1.getNumberValidator)());
322
+ Factory_1.Factory.addGetterSetter(Container, 'clipY', undefined, (0, Validators_1.getNumberValidator)());
323
+ Factory_1.Factory.addGetterSetter(Container, 'clipWidth', undefined, (0, Validators_1.getNumberValidator)());
324
+ Factory_1.Factory.addGetterSetter(Container, 'clipHeight', undefined, (0, Validators_1.getNumberValidator)());
325
+ Factory_1.Factory.addGetterSetter(Container, 'clipFunc');
package/lib/Context.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Canvas } from './Canvas';
2
- import { Shape } from './Shape';
3
- import { IRect } from './types';
1
+ import { Canvas } from './Canvas.js';
2
+ import { Shape } from './Shape.js';
3
+ import { IRect } from './types.js';
4
+ import type { Node } from './Node.js';
4
5
  declare var CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled"];
5
6
  export declare class Context {
6
7
  canvas: Canvas;
@@ -10,16 +11,16 @@ export declare class Context {
10
11
  fillShape(shape: Shape): void;
11
12
  _fill(shape: Shape): void;
12
13
  strokeShape(shape: Shape): void;
13
- _stroke(shape: any): void;
14
+ _stroke(shape: Shape): void;
14
15
  fillStrokeShape(shape: Shape): void;
15
- getTrace(relaxed?: any, rounded?: any): string;
16
+ getTrace(relaxed?: boolean, rounded?: boolean): string;
16
17
  clearTrace(): void;
17
18
  _trace(str: any): void;
18
19
  reset(): void;
19
20
  getCanvas(): Canvas;
20
21
  clear(bounds?: IRect): void;
21
- _applyLineCap(shape: any): void;
22
- _applyOpacity(shape: any): void;
22
+ _applyLineCap(shape: Shape): void;
23
+ _applyOpacity(shape: Node): void;
23
24
  _applyLineJoin(shape: Shape): void;
24
25
  setAttr(attr: string, val: any): void;
25
26
  arc(a0: number, a1: number, a2: number, a3: number, a4: number, a5?: boolean): void;
@@ -55,7 +56,7 @@ export declare class Context {
55
56
  getLineDash(): number[];
56
57
  setTransform(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
57
58
  stroke(path2d?: Path2D): void;
58
- strokeText(a0: string, a1: number, a2: number, a3: number): void;
59
+ strokeText(a0: string, a1: number, a2: number, a3?: number): void;
59
60
  transform(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
60
61
  translate(a0: number, a1: number): void;
61
62
  _enableTrace(): void;
@@ -65,11 +66,13 @@ type CanvasContextProps = Pick<CanvasRenderingContext2D, typeof CONTEXT_PROPERTI
65
66
  export interface Context extends CanvasContextProps {
66
67
  }
67
68
  export declare class SceneContext extends Context {
68
- constructor(canvas: Canvas);
69
+ constructor(canvas: Canvas, { willReadFrequently }?: {
70
+ willReadFrequently?: boolean;
71
+ });
69
72
  _fillColor(shape: Shape): void;
70
- _fillPattern(shape: any): void;
71
- _fillLinearGradient(shape: any): void;
72
- _fillRadialGradient(shape: any): void;
73
+ _fillPattern(shape: Shape): void;
74
+ _fillLinearGradient(shape: Shape): void;
75
+ _fillRadialGradient(shape: Shape): void;
73
76
  _fill(shape: any): void;
74
77
  _strokeLinearGradient(shape: any): void;
75
78
  _stroke(shape: any): void;
@@ -77,7 +80,7 @@ export declare class SceneContext extends Context {
77
80
  }
78
81
  export declare class HitContext extends Context {
79
82
  constructor(canvas: Canvas);
80
- _fill(shape: any): void;
83
+ _fill(shape: Shape): void;
81
84
  strokeShape(shape: Shape): void;
82
85
  _stroke(shape: any): void;
83
86
  }
package/lib/Context.js CHANGED
@@ -1,7 +1,10 @@
1
- import { Util } from './Util.js';
2
- import { Konva } from './Global.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HitContext = exports.SceneContext = exports.Context = void 0;
4
+ const Util_1 = require("./Util");
5
+ const Global_1 = require("./Global");
3
6
  function simplifyArray(arr) {
4
- var retArr = [], len = arr.length, util = Util, n, val;
7
+ var retArr = [], len = arr.length, util = Util_1.Util, n, val;
5
8
  for (n = 0; n < len; n++) {
6
9
  val = arr[n];
7
10
  if (util._isNumber(val)) {
@@ -67,10 +70,10 @@ var CONTEXT_PROPERTIES = [
67
70
  'imageSmoothingEnabled',
68
71
  ];
69
72
  const traceArrMax = 100;
70
- export class Context {
73
+ class Context {
71
74
  constructor(canvas) {
72
75
  this.canvas = canvas;
73
- if (Konva.enableTrace) {
76
+ if (Global_1.Konva.enableTrace) {
74
77
  this.traceArr = [];
75
78
  this._enableTrace();
76
79
  }
@@ -111,7 +114,7 @@ export class Context {
111
114
  str += DOUBLE_PAREN;
112
115
  }
113
116
  else {
114
- if (Util._isArray(args[0])) {
117
+ if (Util_1.Util._isArray(args[0])) {
115
118
  str += OPEN_PAREN_BRACKET + args.join(COMMA) + CLOSE_BRACKET_PAREN;
116
119
  }
117
120
  else {
@@ -160,7 +163,7 @@ export class Context {
160
163
  }
161
164
  }
162
165
  _applyLineCap(shape) {
163
- var lineCap = shape.getLineCap();
166
+ const lineCap = shape.attrs.lineCap;
164
167
  if (lineCap) {
165
168
  this.setAttr('lineCap', lineCap);
166
169
  }
@@ -172,7 +175,7 @@ export class Context {
172
175
  }
173
176
  }
174
177
  _applyLineJoin(shape) {
175
- var lineJoin = shape.attrs.lineJoin;
178
+ const lineJoin = shape.attrs.lineJoin;
176
179
  if (lineJoin) {
177
180
  this.setAttr('lineJoin', lineJoin);
178
181
  }
@@ -369,6 +372,7 @@ export class Context {
369
372
  }
370
373
  }
371
374
  }
375
+ exports.Context = Context;
372
376
  CONTEXT_PROPERTIES.forEach(function (prop) {
373
377
  Object.defineProperty(Context.prototype, prop, {
374
378
  get() {
@@ -379,10 +383,12 @@ CONTEXT_PROPERTIES.forEach(function (prop) {
379
383
  },
380
384
  });
381
385
  });
382
- export class SceneContext extends Context {
383
- constructor(canvas) {
386
+ class SceneContext extends Context {
387
+ constructor(canvas, { willReadFrequently = false } = {}) {
384
388
  super(canvas);
385
- this._context = canvas._canvas.getContext('2d');
389
+ this._context = canvas._canvas.getContext('2d', {
390
+ willReadFrequently,
391
+ });
386
392
  }
387
393
  _fillColor(shape) {
388
394
  var fill = shape.fill();
@@ -401,29 +407,29 @@ export class SceneContext extends Context {
401
407
  }
402
408
  }
403
409
  _fillRadialGradient(shape) {
404
- var grd = shape._getRadialGradient();
410
+ const grd = shape._getRadialGradient();
405
411
  if (grd) {
406
412
  this.setAttr('fillStyle', grd);
407
413
  shape._fillFunc(this);
408
414
  }
409
415
  }
410
416
  _fill(shape) {
411
- var hasColor = shape.fill(), fillPriority = shape.getFillPriority();
417
+ const hasColor = shape.fill(), fillPriority = shape.getFillPriority();
412
418
  if (hasColor && fillPriority === 'color') {
413
419
  this._fillColor(shape);
414
420
  return;
415
421
  }
416
- var hasPattern = shape.getFillPatternImage();
422
+ const hasPattern = shape.getFillPatternImage();
417
423
  if (hasPattern && fillPriority === 'pattern') {
418
424
  this._fillPattern(shape);
419
425
  return;
420
426
  }
421
- var hasLinearGradient = shape.getFillLinearGradientColorStops();
427
+ const hasLinearGradient = shape.getFillLinearGradientColorStops();
422
428
  if (hasLinearGradient && fillPriority === 'linear-gradient') {
423
429
  this._fillLinearGradient(shape);
424
430
  return;
425
431
  }
426
- var hasRadialGradient = shape.getFillRadialGradientColorStops();
432
+ const hasRadialGradient = shape.getFillRadialGradientColorStops();
427
433
  if (hasRadialGradient && fillPriority === 'radial-gradient') {
428
434
  this._fillRadialGradient(shape);
429
435
  return;
@@ -442,7 +448,7 @@ export class SceneContext extends Context {
442
448
  }
443
449
  }
444
450
  _strokeLinearGradient(shape) {
445
- var start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
451
+ const start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
446
452
  if (colorStops) {
447
453
  for (var n = 0; n < colorStops.length; n += 2) {
448
454
  grd.addColorStop(colorStops[n], colorStops[n + 1]);
@@ -492,7 +498,8 @@ export class SceneContext extends Context {
492
498
  this.setAttr('shadowOffsetY', offset.y * scaleY);
493
499
  }
494
500
  }
495
- export class HitContext extends Context {
501
+ exports.SceneContext = SceneContext;
502
+ class HitContext extends Context {
496
503
  constructor(canvas) {
497
504
  super(canvas);
498
505
  this._context = canvas._canvas.getContext('2d', {
@@ -512,7 +519,7 @@ export class HitContext extends Context {
512
519
  }
513
520
  _stroke(shape) {
514
521
  if (shape.hasHitStroke()) {
515
- var strokeScaleEnabled = shape.getStrokeScaleEnabled();
522
+ const strokeScaleEnabled = shape.getStrokeScaleEnabled();
516
523
  if (!strokeScaleEnabled) {
517
524
  this.save();
518
525
  var pixelRatio = this.getCanvas().getPixelRatio();
@@ -530,3 +537,4 @@ export class HitContext extends Context {
530
537
  }
531
538
  }
532
539
  }
540
+ exports.HitContext = HitContext;
package/lib/Core.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { Konva } from './_CoreInternals';
2
- import { Konva } from './_CoreInternals';
1
+ export { Konva } from './_CoreInternals.js';
2
+ import { Konva } from './_CoreInternals.js';
3
3
  export default Konva;
package/lib/Core.js CHANGED
@@ -1,3 +1,7 @@
1
- export { Konva } from './_CoreInternals.js';
2
- import { Konva } from './_CoreInternals.js';
3
- export default Konva;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Konva = void 0;
4
+ var _CoreInternals_1 = require("./_CoreInternals");
5
+ Object.defineProperty(exports, "Konva", { enumerable: true, get: function () { return _CoreInternals_1.Konva; } });
6
+ const _CoreInternals_2 = require("./_CoreInternals");
7
+ module.exports = _CoreInternals_2.Konva;
@@ -1,9 +1,9 @@
1
- import { Node } from './Node';
2
- import { Vector2d } from './types';
1
+ import { Node } from './Node.js';
2
+ import { Vector2d } from './types.js';
3
3
  export declare const DD: {
4
4
  readonly isDragging: boolean;
5
5
  justDragged: boolean;
6
- readonly node: Node<import("./Node").NodeConfig>;
6
+ readonly node: Node<import("./Node.js").NodeConfig>;
7
7
  _dragElements: Map<number, {
8
8
  node: Node;
9
9
  startPointerPos: Vector2d;
@@ -1,9 +1,12 @@
1
- import { Konva } from './Global.js';
2
- import { Util } from './Util.js';
3
- export const DD = {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DD = void 0;
4
+ const Global_1 = require("./Global");
5
+ const Util_1 = require("./Util");
6
+ exports.DD = {
4
7
  get isDragging() {
5
8
  var flag = false;
6
- DD._dragElements.forEach((elem) => {
9
+ exports.DD._dragElements.forEach((elem) => {
7
10
  if (elem.dragStatus === 'dragging') {
8
11
  flag = true;
9
12
  }
@@ -13,7 +16,7 @@ export const DD = {
13
16
  justDragged: false,
14
17
  get node() {
15
18
  var node;
16
- DD._dragElements.forEach((elem) => {
19
+ exports.DD._dragElements.forEach((elem) => {
17
20
  node = elem.node;
18
21
  });
19
22
  return node;
@@ -21,12 +24,12 @@ export const DD = {
21
24
  _dragElements: new Map(),
22
25
  _drag(evt) {
23
26
  const nodesToFireEvents = [];
24
- DD._dragElements.forEach((elem, key) => {
27
+ exports.DD._dragElements.forEach((elem, key) => {
25
28
  const { node } = elem;
26
29
  const stage = node.getStage();
27
30
  stage.setPointersPositions(evt);
28
31
  if (elem.pointerId === undefined) {
29
- elem.pointerId = Util._getFirstPointerId(evt);
32
+ elem.pointerId = Util_1.Util._getFirstPointerId(evt);
30
33
  }
31
34
  const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
32
35
  if (!pos) {
@@ -56,7 +59,7 @@ export const DD = {
56
59
  },
57
60
  _endDragBefore(evt) {
58
61
  const drawNodes = [];
59
- DD._dragElements.forEach((elem) => {
62
+ exports.DD._dragElements.forEach((elem) => {
60
63
  const { node } = elem;
61
64
  const stage = node.getStage();
62
65
  if (evt) {
@@ -67,14 +70,14 @@ export const DD = {
67
70
  return;
68
71
  }
69
72
  if (elem.dragStatus === 'dragging' || elem.dragStatus === 'stopped') {
70
- DD.justDragged = true;
71
- Konva._mouseListenClick = false;
72
- Konva._touchListenClick = false;
73
- Konva._pointerListenClick = false;
73
+ exports.DD.justDragged = true;
74
+ Global_1.Konva._mouseListenClick = false;
75
+ Global_1.Konva._touchListenClick = false;
76
+ Global_1.Konva._pointerListenClick = false;
74
77
  elem.dragStatus = 'stopped';
75
78
  }
76
79
  const drawNode = elem.node.getLayer() ||
77
- (elem.node instanceof Konva['Stage'] && elem.node);
80
+ (elem.node instanceof Global_1.Konva['Stage'] && elem.node);
78
81
  if (drawNode && drawNodes.indexOf(drawNode) === -1) {
79
82
  drawNodes.push(drawNode);
80
83
  }
@@ -84,7 +87,7 @@ export const DD = {
84
87
  });
85
88
  },
86
89
  _endDragAfter(evt) {
87
- DD._dragElements.forEach((elem, key) => {
90
+ exports.DD._dragElements.forEach((elem, key) => {
88
91
  if (elem.dragStatus === 'stopped') {
89
92
  elem.node.fire('dragend', {
90
93
  type: 'dragend',
@@ -93,16 +96,16 @@ export const DD = {
93
96
  }, true);
94
97
  }
95
98
  if (elem.dragStatus !== 'dragging') {
96
- DD._dragElements.delete(key);
99
+ exports.DD._dragElements.delete(key);
97
100
  }
98
101
  });
99
102
  },
100
103
  };
101
- if (Konva.isBrowser) {
102
- window.addEventListener('mouseup', DD._endDragBefore, true);
103
- window.addEventListener('touchend', DD._endDragBefore, true);
104
- window.addEventListener('mousemove', DD._drag);
105
- window.addEventListener('touchmove', DD._drag);
106
- window.addEventListener('mouseup', DD._endDragAfter, false);
107
- window.addEventListener('touchend', DD._endDragAfter, false);
104
+ if (Global_1.Konva.isBrowser) {
105
+ window.addEventListener('mouseup', exports.DD._endDragBefore, true);
106
+ window.addEventListener('touchend', exports.DD._endDragBefore, true);
107
+ window.addEventListener('mousemove', exports.DD._drag);
108
+ window.addEventListener('touchmove', exports.DD._drag);
109
+ window.addEventListener('mouseup', exports.DD._endDragAfter, false);
110
+ window.addEventListener('touchend', exports.DD._endDragAfter, false);
108
111
  }
package/lib/Factory.js CHANGED
@@ -1,14 +1,17 @@
1
- import { Util } from './Util.js';
2
- import { getComponentValidator } from './Validators.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Factory = void 0;
4
+ const Util_1 = require("./Util");
5
+ const Validators_1 = require("./Validators");
3
6
  var GET = 'get', SET = 'set';
4
- export const Factory = {
7
+ exports.Factory = {
5
8
  addGetterSetter(constructor, attr, def, validator, after) {
6
- Factory.addGetter(constructor, attr, def);
7
- Factory.addSetter(constructor, attr, validator, after);
8
- Factory.addOverloadedGetterSetter(constructor, attr);
9
+ exports.Factory.addGetter(constructor, attr, def);
10
+ exports.Factory.addSetter(constructor, attr, validator, after);
11
+ exports.Factory.addOverloadedGetterSetter(constructor, attr);
9
12
  },
10
13
  addGetter(constructor, attr, def) {
11
- var method = GET + Util._capitalize(attr);
14
+ var method = GET + Util_1.Util._capitalize(attr);
12
15
  constructor.prototype[method] =
13
16
  constructor.prototype[method] ||
14
17
  function () {
@@ -17,13 +20,13 @@ export const Factory = {
17
20
  };
18
21
  },
19
22
  addSetter(constructor, attr, validator, after) {
20
- var method = SET + Util._capitalize(attr);
23
+ var method = SET + Util_1.Util._capitalize(attr);
21
24
  if (!constructor.prototype[method]) {
22
- Factory.overWriteSetter(constructor, attr, validator, after);
25
+ exports.Factory.overWriteSetter(constructor, attr, validator, after);
23
26
  }
24
27
  },
25
28
  overWriteSetter(constructor, attr, validator, after) {
26
- var method = SET + Util._capitalize(attr);
29
+ var method = SET + Util_1.Util._capitalize(attr);
27
30
  constructor.prototype[method] = function (val) {
28
31
  if (validator && val !== undefined && val !== null) {
29
32
  val = validator.call(this, val, attr);
@@ -36,7 +39,7 @@ export const Factory = {
36
39
  };
37
40
  },
38
41
  addComponentsGetterSetter(constructor, attr, components, validator, after) {
39
- var len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr), n, component;
42
+ var len = components.length, capitalize = Util_1.Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr), n, component;
40
43
  constructor.prototype[getter] = function () {
41
44
  var ret = {};
42
45
  for (n = 0; n < len; n++) {
@@ -45,7 +48,7 @@ export const Factory = {
45
48
  }
46
49
  return ret;
47
50
  };
48
- var basicValidator = getComponentValidator(components);
51
+ var basicValidator = (0, Validators_1.getComponentValidator)(components);
49
52
  constructor.prototype[setter] = function (val) {
50
53
  var oldVal = this.attrs[attr], key;
51
54
  if (validator) {
@@ -71,10 +74,10 @@ export const Factory = {
71
74
  }
72
75
  return this;
73
76
  };
74
- Factory.addOverloadedGetterSetter(constructor, attr);
77
+ exports.Factory.addOverloadedGetterSetter(constructor, attr);
75
78
  },
76
79
  addOverloadedGetterSetter(constructor, attr) {
77
- var capitalizedAttr = Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
80
+ var capitalizedAttr = Util_1.Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
78
81
  constructor.prototype[attr] = function () {
79
82
  if (arguments.length) {
80
83
  this[setter](arguments[0]);
@@ -84,28 +87,28 @@ export const Factory = {
84
87
  };
85
88
  },
86
89
  addDeprecatedGetterSetter(constructor, attr, def, validator) {
87
- Util.error('Adding deprecated ' + attr);
88
- var method = GET + Util._capitalize(attr);
90
+ Util_1.Util.error('Adding deprecated ' + attr);
91
+ var method = GET + Util_1.Util._capitalize(attr);
89
92
  var message = attr +
90
93
  ' property is deprecated and will be removed soon. Look at Konva change log for more information.';
91
94
  constructor.prototype[method] = function () {
92
- Util.error(message);
95
+ Util_1.Util.error(message);
93
96
  var val = this.attrs[attr];
94
97
  return val === undefined ? def : val;
95
98
  };
96
- Factory.addSetter(constructor, attr, validator, function () {
97
- Util.error(message);
99
+ exports.Factory.addSetter(constructor, attr, validator, function () {
100
+ Util_1.Util.error(message);
98
101
  });
99
- Factory.addOverloadedGetterSetter(constructor, attr);
102
+ exports.Factory.addOverloadedGetterSetter(constructor, attr);
100
103
  },
101
104
  backCompat(constructor, methods) {
102
- Util.each(methods, function (oldMethodName, newMethodName) {
105
+ Util_1.Util.each(methods, function (oldMethodName, newMethodName) {
103
106
  var method = constructor.prototype[newMethodName];
104
- var oldGetter = GET + Util._capitalize(oldMethodName);
105
- var oldSetter = SET + Util._capitalize(oldMethodName);
107
+ var oldGetter = GET + Util_1.Util._capitalize(oldMethodName);
108
+ var oldSetter = SET + Util_1.Util._capitalize(oldMethodName);
106
109
  function deprecated() {
107
110
  method.apply(this, arguments);
108
- Util.error('"' +
111
+ Util_1.Util.error('"' +
109
112
  oldMethodName +
110
113
  '" method is deprecated and will be removed soon. Use ""' +
111
114
  newMethodName +
@@ -1,4 +1,4 @@
1
- import { Layer } from './Layer';
1
+ import { Layer } from './Layer.js';
2
2
  export declare class FastLayer extends Layer {
3
3
  constructor(attrs: any);
4
4
  }
package/lib/FastLayer.js CHANGED
@@ -1,12 +1,16 @@
1
- import { Util } from './Util.js';
2
- import { Layer } from './Layer.js';
3
- import { _registerNode } from './Global.js';
4
- export class FastLayer extends Layer {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FastLayer = void 0;
4
+ const Util_1 = require("./Util");
5
+ const Layer_1 = require("./Layer");
6
+ const Global_1 = require("./Global");
7
+ class FastLayer extends Layer_1.Layer {
5
8
  constructor(attrs) {
6
9
  super(attrs);
7
10
  this.listening(false);
8
- Util.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.');
11
+ Util_1.Util.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.');
9
12
  }
10
13
  }
14
+ exports.FastLayer = FastLayer;
11
15
  FastLayer.prototype.nodeType = 'FastLayer';
12
- _registerNode(FastLayer);
16
+ (0, Global_1._registerNode)(FastLayer);