konva 10.9.1 → 10.10.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 (69) hide show
  1. package/README.md +22 -10
  2. package/konva.js +18996 -18924
  3. package/konva.min.js +50 -50
  4. package/lib/Animation.js +3 -3
  5. package/lib/Canvas.js +11 -3
  6. package/lib/Container.js +3 -3
  7. package/lib/Context.d.ts +1 -2
  8. package/lib/Context.js +2 -19
  9. package/lib/Core.js +2 -2
  10. package/lib/DragAndDrop.js +1 -1
  11. package/lib/Factory.js +2 -2
  12. package/lib/FastLayer.js +3 -3
  13. package/lib/Global.d.ts +0 -1
  14. package/lib/Global.js +13 -7
  15. package/lib/Group.js +5 -5
  16. package/lib/Layer.d.ts +1 -1
  17. package/lib/Layer.js +8 -8
  18. package/lib/Node.js +32 -26
  19. package/lib/PointerEvents.js +1 -1
  20. package/lib/Shape.js +8 -27
  21. package/lib/Stage.js +8 -8
  22. package/lib/Tween.js +4 -4
  23. package/lib/Util.d.ts +67 -3
  24. package/lib/Util.js +122 -41
  25. package/lib/Validators.js +2 -2
  26. package/lib/_CoreInternals.d.ts +15 -11
  27. package/lib/_CoreInternals.js +16 -14
  28. package/lib/_FullInternals.d.ts +14 -10
  29. package/lib/_FullInternals.js +38 -38
  30. package/lib/canvas-backend.js +6 -15
  31. package/lib/filters/Blur.js +3 -3
  32. package/lib/filters/Brighten.js +3 -3
  33. package/lib/filters/Brightness.js +2 -2
  34. package/lib/filters/Contrast.js +3 -3
  35. package/lib/filters/Emboss.js +10 -9
  36. package/lib/filters/Enhance.js +3 -3
  37. package/lib/filters/HSL.js +3 -3
  38. package/lib/filters/HSV.js +3 -3
  39. package/lib/filters/Kaleidoscope.js +3 -3
  40. package/lib/filters/Mask.js +3 -3
  41. package/lib/filters/Noise.js +3 -3
  42. package/lib/filters/Pixelate.js +4 -4
  43. package/lib/filters/Posterize.js +3 -3
  44. package/lib/filters/RGB.js +3 -3
  45. package/lib/filters/RGBA.js +3 -3
  46. package/lib/filters/Threshold.js +3 -3
  47. package/lib/index.js +1 -1
  48. package/lib/napi-backend.d.ts +2 -0
  49. package/lib/napi-backend.js +15 -0
  50. package/lib/shapes/Arc.js +5 -5
  51. package/lib/shapes/Arrow.js +5 -5
  52. package/lib/shapes/Circle.js +4 -4
  53. package/lib/shapes/Ellipse.js +4 -4
  54. package/lib/shapes/Image.js +5 -5
  55. package/lib/shapes/Label.js +7 -7
  56. package/lib/shapes/Line.js +6 -6
  57. package/lib/shapes/Path.js +5 -5
  58. package/lib/shapes/Rect.js +5 -5
  59. package/lib/shapes/RegularPolygon.js +5 -5
  60. package/lib/shapes/Ring.js +4 -4
  61. package/lib/shapes/Sprite.js +5 -5
  62. package/lib/shapes/Star.js +4 -4
  63. package/lib/shapes/Text.d.ts +0 -1
  64. package/lib/shapes/Text.js +32 -30
  65. package/lib/shapes/TextPath.js +7 -7
  66. package/lib/shapes/Transformer.js +12 -11
  67. package/lib/shapes/Wedge.js +5 -5
  68. package/lib/skia-backend.js +17 -25
  69. package/package.json +31 -34
package/lib/Animation.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var _a;
2
- import { glob } from "./Global.js";
3
- import { Node } from "./Node.js";
4
- import { Util } from "./Util.js";
2
+ import { glob } from './Global.js';
3
+ import { Node } from './Node.js';
4
+ import { Util } from './Util.js';
5
5
  const now = ((_a = glob.performance) === null || _a === void 0 ? void 0 : _a.now)
6
6
  ? () => glob.performance.now()
7
7
  : Date.now;
package/lib/Canvas.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Transform, Util } from "./Util.js";
2
- import { SceneContext, HitContext } from "./Context.js";
3
- import { Konva } from "./Global.js";
1
+ import { Transform, Util } from './Util.js';
2
+ import { SceneContext, HitContext } from './Context.js';
3
+ import { Konva } from './Global.js';
4
4
  /**
5
5
  * Canvas Renderer constructor. It is a wrapper around native canvas element.
6
6
  * Usually you don't need to use it manually.
@@ -14,6 +14,8 @@ import { Konva } from "./Global.js";
14
14
  */
15
15
  export class Canvas {
16
16
  constructor(config) {
17
+ var _a;
18
+ var _b;
17
19
  this.pixelRatio = 1;
18
20
  // the bitmap size, in device pixels
19
21
  this.width = 0;
@@ -30,6 +32,8 @@ export class Canvas {
30
32
  1;
31
33
  this.pixelRatio = pixelRatio;
32
34
  this._canvas = Util.createCanvasElement();
35
+ // a canvas outside the DOM (OffscreenCanvas, Node.js backends) has no style
36
+ (_a = (_b = this._canvas).style) !== null && _a !== void 0 ? _a : (_b.style = {});
33
37
  // set inline styles
34
38
  this._canvas.style.padding = '0';
35
39
  this._canvas.style.margin = '0';
@@ -134,6 +138,10 @@ export class Canvas {
134
138
  * @returns {String} data url string
135
139
  */
136
140
  toDataURL(mimeType, quality) {
141
+ if (!this._canvas.toDataURL) {
142
+ // an OffscreenCanvas, as in a Web Worker, only encodes asynchronously
143
+ throw new Error('Konva: this canvas can not make a data URL. In a Web Worker, use toBlob() instead.');
144
+ }
137
145
  try {
138
146
  // If the requested encoding fails, retry with the default PNG encoding.
139
147
  return this._canvas.toDataURL(mimeType, quality);
package/lib/Container.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Factory } from "./Factory.js";
2
- import { Node } from "./Node.js";
3
- import { getNumberValidator } from "./Validators.js";
1
+ import { Factory } from './Factory.js';
2
+ import { Node } from './Node.js';
3
+ import { getNumberValidator } from './Validators.js';
4
4
  /**
5
5
  * Container constructor.  Containers are used to contain nodes or other containers
6
6
  * @constructor
package/lib/Context.d.ts CHANGED
@@ -2,8 +2,7 @@ import type { Canvas, SceneCanvas } from './Canvas.ts';
2
2
  import type { Shape } from './Shape.ts';
3
3
  import type { IRect } from './types.ts';
4
4
  import type { Node } from './Node.ts';
5
- declare const CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "letterSpacing", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "direction", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled", "imageSmoothingQuality", "filter"];
6
- export declare function isCSSFiltersSupported(): boolean;
5
+ declare const CONTEXT_PROPERTIES: readonly ['fillStyle', 'strokeStyle', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'letterSpacing', 'lineCap', 'lineDashOffset', 'lineJoin', 'lineWidth', 'miterLimit', 'direction', 'font', 'textAlign', 'textBaseline', 'globalAlpha', 'globalCompositeOperation', 'imageSmoothingEnabled', 'imageSmoothingQuality', 'filter'];
7
6
  interface ExtendedCanvasRenderingContext2D extends CanvasRenderingContext2D {
8
7
  letterSpacing: string;
9
8
  }
package/lib/Context.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Transform, Util } from "./Util.js";
2
- import { Konva } from "./Global.js";
1
+ import { Transform, Util } from './Util.js';
2
+ import { Konva } from './Global.js';
3
3
  function simplifyArray(arr) {
4
4
  const retArr = [], len = arr.length, util = Util;
5
5
  for (let n = 0; n < len; n++) {
@@ -76,23 +76,6 @@ const CONTEXT_PROPERTIES = [
76
76
  'filter',
77
77
  ];
78
78
  const traceArrMax = 100;
79
- // Check if CSS filters are supported in the current browser
80
- let _cssFiltersSupported = null;
81
- export function isCSSFiltersSupported() {
82
- if (_cssFiltersSupported !== null) {
83
- return _cssFiltersSupported;
84
- }
85
- try {
86
- const canvas = Util.createCanvasElement();
87
- const ctx = canvas.getContext('2d');
88
- _cssFiltersSupported = !!ctx && 'filter' in ctx;
89
- Util.releaseCanvas(canvas);
90
- }
91
- catch (e) {
92
- _cssFiltersSupported = false;
93
- }
94
- return _cssFiltersSupported;
95
- }
96
79
  /**
97
80
  * Konva wrapper around native 2d canvas context. It has almost the same API of 2d context with some additional functions.
98
81
  * With core Konva shapes you don't need to use this object. But you will use it if you want to create
package/lib/Core.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // enter file of limited Konva version with only core functions
2
- export { Konva } from "./_CoreInternals.js";
3
- import { Konva } from "./_CoreInternals.js";
2
+ export { Konva } from './_CoreInternals.js';
3
+ import { Konva } from './_CoreInternals.js';
4
4
  export default Konva;
@@ -1,4 +1,4 @@
1
- import { Util } from "./Util.js";
1
+ import { Util } from './Util.js';
2
2
  export const DD = {
3
3
  get isDragging() {
4
4
  let flag = false;
package/lib/Factory.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Util } from "./Util.js";
2
- import { getComponentValidator } from "./Validators.js";
1
+ import { Util } from './Util.js';
2
+ import { getComponentValidator } from './Validators.js';
3
3
  const GET = 'get';
4
4
  const SET = 'set';
5
5
  export const Factory = {
package/lib/FastLayer.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Util } from "./Util.js";
2
- import { Layer } from "./Layer.js";
3
- import { _registerNode } from "./Global.js";
1
+ import { Util } from './Util.js';
2
+ import { Layer } from './Layer.js';
3
+ import { _registerNode } from './Global.js';
4
4
  /**
5
5
  * FastLayer constructor. **DEPRECATED!** Please use `Konva.Layer({ listening: false})` instead. Layers are tied to their own canvas element and are used
6
6
  * to contain shapes only. If you don't need node nesting, mouse and touch interactions,
package/lib/Global.d.ts CHANGED
@@ -42,7 +42,6 @@ export declare const Konva: {
42
42
  * Konva.capturePointerEventsEnabled = true;
43
43
  */
44
44
  capturePointerEventsEnabled: boolean;
45
- _renderBackend: string;
46
45
  /**
47
46
  * Use legacy text rendering. with "middle" baseline by default.
48
47
  * @property legacyTextRendering
package/lib/Global.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Konva JavaScript Framework v10.9.1
2
+ * Konva JavaScript Framework v10.10.0
3
3
  * http://konvajs.org/
4
4
  * Licensed under the MIT
5
5
  * Date: @@date
@@ -29,7 +29,7 @@ export const glob = typeof global !== 'undefined'
29
29
  : {};
30
30
  export const Konva = {
31
31
  _global: glob,
32
- version: '10.9.1',
32
+ version: '10.10.0',
33
33
  isBrowser: detectBrowser(),
34
34
  isUnminified: /param/.test(function (param) { }.toString()),
35
35
  dblClickWindow: 400,
@@ -72,7 +72,6 @@ export const Konva = {
72
72
  * Konva.capturePointerEventsEnabled = true;
73
73
  */
74
74
  capturePointerEventsEnabled: false,
75
- _renderBackend: 'web', // web, node-canvas, skia-canvas
76
75
  /**
77
76
  * Use legacy text rendering. with "middle" baseline by default.
78
77
  * @property legacyTextRendering
@@ -150,7 +149,8 @@ export const Konva = {
150
149
  * @memberof Konva
151
150
  */
152
151
  isTransforming() {
153
- var _a, _b;
152
+ var _a;
153
+ var _b;
154
154
  return (_b = (_a = Konva['Transformer']) === null || _a === void 0 ? void 0 : _a.isTransforming()) !== null && _b !== void 0 ? _b : false;
155
155
  },
156
156
  /**
@@ -174,11 +174,13 @@ export const Konva = {
174
174
  */
175
175
  releaseCanvasOnDestroy: true,
176
176
  document: glob.document,
177
- // insert Konva into global namespace (window)
178
- // it is required for npm packages
177
+ // window.Konva is how konva-devtool and browser tests find the stages, so
178
+ // the first copy keeps it. A second copy in one page is usually a bundling
179
+ // mistake that splits stages and settings between the copies
179
180
  _injectGlobal(Konva) {
180
181
  if (typeof glob.Konva !== 'undefined') {
181
182
  console.error('Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment.');
183
+ return;
182
184
  }
183
185
  glob.Konva = Konva;
184
186
  },
@@ -191,4 +193,8 @@ export const _registerNode = (NodeClass, boundsCoverPaint = false) => {
191
193
  if (boundsCoverPaint)
192
194
  _boundedShapes.add(NodeClass);
193
195
  };
194
- Konva._injectGlobal(Konva);
196
+ // devtools and browser tests can not see a copy in Node.js or a worker, such
197
+ // as a library's private copy for server rendering, so it stays quiet
198
+ if (Konva.isBrowser) {
199
+ Konva._injectGlobal(Konva);
200
+ }
package/lib/Group.js CHANGED
@@ -1,8 +1,8 @@
1
- import { Util } from "./Util.js";
2
- import { Container } from "./Container.js";
3
- import { _registerNode } from "./Global.js";
4
- import { Factory } from "./Factory.js";
5
- import { getBooleanValidator } from "./Validators.js";
1
+ import { Util } from './Util.js';
2
+ import { Container } from './Container.js';
3
+ import { _registerNode } from './Global.js';
4
+ import { Factory } from './Factory.js';
5
+ import { getBooleanValidator } from './Validators.js';
6
6
  /**
7
7
  * Group constructor. Groups are used to contain shapes or other groups.
8
8
  * @constructor
package/lib/Layer.d.ts CHANGED
@@ -78,8 +78,8 @@ export declare class Layer extends Container<Group | Shape> {
78
78
  remove(): this;
79
79
  getStage(): Stage;
80
80
  _setSize({ width, height }: {
81
- width: any;
82
81
  height: any;
82
+ width: any;
83
83
  }): this;
84
84
  _syncHitCanvasSize(): void;
85
85
  _validateAdd(child: any): void;
package/lib/Layer.js CHANGED
@@ -1,11 +1,11 @@
1
- import { Util } from "./Util.js";
2
- import { Container } from "./Container.js";
3
- import { Node } from "./Node.js";
4
- import { Factory } from "./Factory.js";
5
- import { SceneCanvas, HitCanvas } from "./Canvas.js";
6
- import { shapes } from "./Shape.js";
7
- import { _registerNode, Konva } from "./Global.js";
8
- import { DD } from "./DragAndDrop.js";
1
+ import { Util } from './Util.js';
2
+ import { Container } from './Container.js';
3
+ import { Node } from './Node.js';
4
+ import { Factory } from './Factory.js';
5
+ import { SceneCanvas, HitCanvas } from './Canvas.js';
6
+ import { shapes } from './Shape.js';
7
+ import { _registerNode, Konva } from './Global.js';
8
+ import { DD } from './DragAndDrop.js';
9
9
  // constants
10
10
  const BEFORE_DRAW = 'beforeDraw', DRAW = 'draw',
11
11
  // getIntersection() reads the hit canvas around an edge pixel in blocks
package/lib/Node.js CHANGED
@@ -1,11 +1,10 @@
1
- import { HitCanvas, SceneCanvas } from "./Canvas.js";
2
- import { isCSSFiltersSupported } from "./Context.js";
3
- import { DD } from "./DragAndDrop.js";
4
- import * as PointerEvents from "./PointerEvents.js";
5
- import { Factory } from "./Factory.js";
6
- import { Konva } from "./Global.js";
7
- import { Transform, TypedArray, Util } from "./Util.js";
8
- import { getBooleanValidator, getNumberValidator, getStringValidator, } from "./Validators.js";
1
+ import { HitCanvas, SceneCanvas } from './Canvas.js';
2
+ import { DD } from './DragAndDrop.js';
3
+ import * as PointerEvents from './PointerEvents.js';
4
+ import { Factory } from './Factory.js';
5
+ import { Konva } from './Global.js';
6
+ import { Transform, TypedArray, Util } from './Util.js';
7
+ import { getBooleanValidator, getNumberValidator, getStringValidator, } from './Validators.js';
9
8
  // CSS filter parser for fallback to function filters.
10
9
  function parseCSSFilters(cssFilter) {
11
10
  const steps = [];
@@ -486,13 +485,9 @@ export class Node {
486
485
  if (this._filterUpToDate) {
487
486
  return filterCanvas;
488
487
  }
489
- let useNativeOnly = true;
490
- for (let i = 0; i < filters.length; i++) {
491
- if (typeof filters[i] !== 'string' || !isCSSFiltersSupported()) {
492
- useNativeOnly = false;
493
- break;
494
- }
495
- }
488
+ // node-canvas has no ctx.filter, so CSS filter strings take the fallback
489
+ const useNativeOnly = 'filter' in filterContext._context &&
490
+ filters.every((filter) => typeof filter === 'string');
496
491
  const ratio = sceneCanvas.pixelRatio;
497
492
  filterCanvas.setSizeIfChanged(sceneCanvas._logicalWidth, sceneCanvas._logicalHeight);
498
493
  if (useNativeOnly) {
@@ -1866,17 +1861,27 @@ export class Node {
1866
1861
  */
1867
1862
  toBlob(config) {
1868
1863
  return new Promise((resolve, reject) => {
1864
+ const done = (blob) => {
1865
+ var _a;
1866
+ // the canvas reports a failed encode by passing null
1867
+ if (!blob) {
1868
+ reject(new Error('Konva: toBlob() failed, the canvas was not encoded'));
1869
+ return;
1870
+ }
1871
+ resolve(blob);
1872
+ (_a = config === null || config === void 0 ? void 0 : config.callback) === null || _a === void 0 ? void 0 : _a.call(config, blob);
1873
+ };
1869
1874
  try {
1870
- this.toCanvas(config).toBlob((blob) => {
1871
- var _a;
1872
- // the canvas reports a failed encode by passing null
1873
- if (!blob) {
1874
- reject(new Error('Konva: toBlob() failed, the canvas was not encoded'));
1875
- return;
1876
- }
1877
- resolve(blob);
1878
- (_a = config === null || config === void 0 ? void 0 : config.callback) === null || _a === void 0 ? void 0 : _a.call(config, blob);
1879
- }, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality);
1875
+ const canvas = this.toCanvas(config);
1876
+ // an OffscreenCanvas, as in a Web Worker, has no toBlob()
1877
+ if (canvas.convertToBlob) {
1878
+ canvas
1879
+ .convertToBlob({ type: config === null || config === void 0 ? void 0 : config.mimeType, quality: config === null || config === void 0 ? void 0 : config.quality })
1880
+ .then(done, reject);
1881
+ }
1882
+ else {
1883
+ canvas.toBlob(done, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality);
1884
+ }
1880
1885
  }
1881
1886
  catch (err) {
1882
1887
  reject(err);
@@ -2119,7 +2124,8 @@ export class Node {
2119
2124
  }
2120
2125
  }
2121
2126
  _getProtoListeners(eventType) {
2122
- var _a, _b;
2127
+ var _a;
2128
+ var _b;
2123
2129
  const proto = Object.getPrototypeOf(this);
2124
2130
  let allListeners = Node.protoListenerMap.get(proto);
2125
2131
  if (!allListeners) {
@@ -1,4 +1,4 @@
1
- import { Konva } from "./Global.js";
1
+ import { Konva } from './Global.js';
2
2
  const Captures = new Map();
3
3
  // we may use this module for capturing touch events too
4
4
  // so make sure we don't do something super specific to pointer
package/lib/Shape.js CHANGED
@@ -1,10 +1,10 @@
1
- import { Konva } from "./Global.js";
2
- import { Transform, Util } from "./Util.js";
3
- import { Factory } from "./Factory.js";
4
- import { Node } from "./Node.js";
5
- import { getNumberValidator, getNumberOrAutoValidator, getStringValidator, getBooleanValidator, getStringOrGradientValidator, } from "./Validators.js";
6
- import { _boundedShapes, _registerNode } from "./Global.js";
7
- import * as PointerEvents from "./PointerEvents.js";
1
+ import { Konva } from './Global.js';
2
+ import { Transform, Util, getDummyContext } from './Util.js';
3
+ import { Factory } from './Factory.js';
4
+ import { Node } from './Node.js';
5
+ import { getNumberValidator, getNumberOrAutoValidator, getStringValidator, getBooleanValidator, getStringOrGradientValidator, } from './Validators.js';
6
+ import { _boundedShapes, _registerNode } from './Global.js';
7
+ import * as PointerEvents from './PointerEvents.js';
8
8
  const HAS_SHADOW = 'hasShadow';
9
9
  const HAS_FILL = 'hasFill';
10
10
  const HAS_STROKE = 'hasStroke';
@@ -12,14 +12,6 @@ const SHADOW_RGBA = 'shadowRGBA';
12
12
  const patternImage = 'patternImage';
13
13
  const linearGradient = 'linearGradient';
14
14
  const radialGradient = 'radialGradient';
15
- let dummyContext;
16
- function getDummyContext() {
17
- if (dummyContext) {
18
- return dummyContext;
19
- }
20
- dummyContext = Util.createCanvasElement().getContext('2d');
21
- return dummyContext;
22
- }
23
15
  export const shapes = {};
24
16
  function _fillFunc(context) {
25
17
  const fillRule = this.attrs.fillRule;
@@ -160,18 +152,7 @@ export class Shape extends Node {
160
152
  tr.rotate(Konva.getAngle(this.fillPatternRotation()));
161
153
  tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
162
154
  tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
163
- const m = tr.getMatrix();
164
- const matrix = typeof DOMMatrix === 'undefined'
165
- ? {
166
- a: m[0], // Horizontal scaling. A value of 1 results in no scaling.
167
- b: m[1], // Vertical skewing.
168
- c: m[2], // Horizontal skewing.
169
- d: m[3],
170
- e: m[4], // Horizontal translation (moving).
171
- f: m[5], // Vertical translation (moving).
172
- }
173
- : new DOMMatrix(m);
174
- pattern.setTransform(matrix);
155
+ pattern.setTransform(Util.createDOMMatrix(tr.getMatrix()));
175
156
  }
176
157
  return pattern;
177
158
  }
package/lib/Stage.js CHANGED
@@ -1,11 +1,11 @@
1
- import { Util } from "./Util.js";
2
- import { Factory } from "./Factory.js";
3
- import { Container } from "./Container.js";
4
- import { Konva } from "./Global.js";
5
- import { SceneCanvas, HitCanvas } from "./Canvas.js";
6
- import { DD } from "./DragAndDrop.js";
7
- import { _registerNode } from "./Global.js";
8
- import * as PointerEvents from "./PointerEvents.js";
1
+ import { Util } from './Util.js';
2
+ import { Factory } from './Factory.js';
3
+ import { Container } from './Container.js';
4
+ import { Konva } from './Global.js';
5
+ import { SceneCanvas, HitCanvas } from './Canvas.js';
6
+ import { DD } from './DragAndDrop.js';
7
+ import { _registerNode } from './Global.js';
8
+ import * as PointerEvents from './PointerEvents.js';
9
9
  // CONSTANTS
10
10
  const STAGE = 'Stage', STRING = 'string', PX = 'px', MOUSEOUT = 'mouseout', MOUSELEAVE = 'mouseleave', MOUSEOVER = 'mouseover', MOUSEENTER = 'mouseenter', MOUSEMOVE = 'mousemove', MOUSEDOWN = 'mousedown', MOUSEUP = 'mouseup', POINTERMOVE = 'pointermove', POINTERDOWN = 'pointerdown', POINTERUP = 'pointerup', POINTERCANCEL = 'pointercancel', LOSTPOINTERCAPTURE = 'lostpointercapture', POINTEROUT = 'pointerout', POINTERLEAVE = 'pointerleave', POINTEROVER = 'pointerover', POINTERENTER = 'pointerenter', CONTEXTMENU = 'contextmenu', TOUCHSTART = 'touchstart', TOUCHEND = 'touchend', TOUCHMOVE = 'touchmove', TOUCHCANCEL = 'touchcancel', WHEEL = 'wheel', MAX_LAYERS_NUMBER = 5, EVENTS = [
11
11
  [MOUSEENTER, '_pointerenter'],
package/lib/Tween.js CHANGED
@@ -1,7 +1,7 @@
1
- import { Util } from "./Util.js";
2
- import { Animation } from "./Animation.js";
3
- import { Node } from "./Node.js";
4
- import { Konva } from "./Global.js";
1
+ import { Util } from './Util.js';
2
+ import { Animation } from './Animation.js';
3
+ import { Node } from './Node.js';
4
+ import { Konva } from './Global.js';
5
5
  // every config key that is not an attribute to tween
6
6
  const blacklist = {
7
7
  node: 1,
package/lib/Util.d.ts CHANGED
@@ -130,10 +130,28 @@ export declare const Util: {
130
130
  _isBoolean(obj: any): obj is boolean;
131
131
  isObject(val: any): val is object;
132
132
  isValidSelector(selector: any): boolean;
133
- _sign(number: number): 1 | -1;
133
+ _sign(number: number): -1 | 1;
134
134
  requestAnimFrame(callback: Function, win?: Window | null): void;
135
135
  createCanvasElement(): HTMLCanvasElement;
136
136
  createImageElement(): HTMLImageElement;
137
+ /**
138
+ * Make a DOMMatrix of the canvas library Konva draws with. Without a createDOMMatrix
139
+ * in Konva.setCanvasBackend(), the class comes from the library's own context.
140
+ * @method
141
+ * @memberof Konva.Util
142
+ * @param {Array} [init] the six numbers a, b, c, d, e, f
143
+ * @returns {DOMMatrix}
144
+ */
145
+ createDOMMatrix(init?: number[]): DOMMatrix;
146
+ /**
147
+ * Make a Path2D of the canvas library Konva draws with, for example for a clipFunc.
148
+ * Without a createPath2D in Konva.setCanvasBackend(), it is the global Path2D.
149
+ * @method
150
+ * @memberof Konva.Util
151
+ * @param {String} [path] SVG path data
152
+ * @returns {Path2D}
153
+ */
154
+ createPath2D(path?: string): Path2D;
137
155
  _urlToImage(url: string, callback: Function, onError?: (error: Error) => void): void;
138
156
  _rgbToHex(r: number, g: number, b: number): string;
139
157
  _hexToRgb(hex: string): RGB;
@@ -151,7 +169,7 @@ export declare const Util: {
151
169
  * @memberof Konva.Util
152
170
  * @returns {Boolean}
153
171
  */
154
- isCanvasFarblingActive(): boolean;
172
+ isCanvasFarblingActive: () => boolean;
155
173
  /**
156
174
  * Get a random color for hit detection (snapped to the hit color grid)
157
175
  * @method
@@ -266,11 +284,57 @@ export declare const Util: {
266
284
  _prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
267
285
  _prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
268
286
  _assign<T, U>(target: T, source: U): T & U;
269
- _getEventType(type: string): "mouse" | "touch" | "pointer";
287
+ _getEventType(type: string): 'mouse' | 'touch' | 'pointer';
270
288
  _getFirstPointerId(evt: any): any;
271
289
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
272
290
  _cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
273
291
  drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
274
292
  drawRoundedPolygonPath(context: Context, points: Vector2d[], sides: number, radius: number, cornerRadius: number | number[]): void;
275
293
  };
294
+ export interface CanvasBackend {
295
+ /** what Konva.getCanvasBackend() reports */
296
+ name: string;
297
+ /** makes a canvas with a 2d context; Konva sets its size */
298
+ createCanvas: () => object;
299
+ /** makes an image that loads from its src; without it Konva can not load images */
300
+ createImage?: () => object;
301
+ /** makes a DOMMatrix; by default its class comes from the canvas */
302
+ createDOMMatrix?: (init?: number[]) => object;
303
+ /** makes a Path2D; by default the global Path2D */
304
+ createPath2D?: (path?: string) => object;
305
+ }
306
+ /**
307
+ * Set the canvas library Konva draws with: Konva makes every canvas and image through it.
308
+ * Applies to everything Konva creates afterwards, including the context it measures text
309
+ * and makes gradients with. Stages and nodes created before keep their canvases, so
310
+ * create them again after a switch.
311
+ * @method
312
+ * @name Konva.setCanvasBackend
313
+ * @param {Object} backend
314
+ * @param {String} backend.name reported by Konva.getCanvasBackend()
315
+ * @param {Function} backend.createCanvas returns a new canvas
316
+ * @param {Function} [backend.createImage] returns a new image
317
+ * @param {Function} [backend.createDOMMatrix] returns a new DOMMatrix, see Konva.Util.createDOMMatrix
318
+ * @param {Function} [backend.createPath2D] returns a new Path2D, see Konva.Util.createPath2D
319
+ * @example
320
+ * import { Canvas, Image } from '@napi-rs/canvas';
321
+ * Konva.setCanvasBackend({
322
+ * name: 'my-napi-rs',
323
+ * createCanvas: () => new Canvas(300, 150),
324
+ * createImage: () => new Image(),
325
+ * });
326
+ */
327
+ export declare function setCanvasBackend(backend: CanvasBackend): void;
328
+ /**
329
+ * The name of the canvas backend Konva draws with: "web" in a browser, "offscreen-canvas" in a
330
+ * Web Worker, the name given to Konva.setCanvasBackend(), "custom" when
331
+ * Konva.Util.createCanvasElement was replaced directly, or null when there is none, as in
332
+ * Node.js before a backend is set.
333
+ * @method
334
+ * @name Konva.getCanvasBackend
335
+ * @returns {String|null}
336
+ */
337
+ export declare function getCanvasBackend(): string | null;
338
+ export declare function _perCanvasBackend<T>(compute: () => T): () => T;
339
+ export declare const getDummyContext: () => CanvasRenderingContext2D;
276
340
  export type AnyString<T> = T | (string & {});