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.
- package/README.md +22 -10
- package/konva.js +18996 -18924
- package/konva.min.js +50 -50
- package/lib/Animation.js +3 -3
- package/lib/Canvas.js +11 -3
- package/lib/Container.js +3 -3
- package/lib/Context.d.ts +1 -2
- package/lib/Context.js +2 -19
- package/lib/Core.js +2 -2
- package/lib/DragAndDrop.js +1 -1
- package/lib/Factory.js +2 -2
- package/lib/FastLayer.js +3 -3
- package/lib/Global.d.ts +0 -1
- package/lib/Global.js +13 -7
- package/lib/Group.js +5 -5
- package/lib/Layer.d.ts +1 -1
- package/lib/Layer.js +8 -8
- package/lib/Node.js +32 -26
- package/lib/PointerEvents.js +1 -1
- package/lib/Shape.js +8 -27
- package/lib/Stage.js +8 -8
- package/lib/Tween.js +4 -4
- package/lib/Util.d.ts +67 -3
- package/lib/Util.js +122 -41
- package/lib/Validators.js +2 -2
- package/lib/_CoreInternals.d.ts +15 -11
- package/lib/_CoreInternals.js +16 -14
- package/lib/_FullInternals.d.ts +14 -10
- package/lib/_FullInternals.js +38 -38
- package/lib/canvas-backend.js +6 -15
- package/lib/filters/Blur.js +3 -3
- package/lib/filters/Brighten.js +3 -3
- package/lib/filters/Brightness.js +2 -2
- package/lib/filters/Contrast.js +3 -3
- package/lib/filters/Emboss.js +10 -9
- package/lib/filters/Enhance.js +3 -3
- package/lib/filters/HSL.js +3 -3
- package/lib/filters/HSV.js +3 -3
- package/lib/filters/Kaleidoscope.js +3 -3
- package/lib/filters/Mask.js +3 -3
- package/lib/filters/Noise.js +3 -3
- package/lib/filters/Pixelate.js +4 -4
- package/lib/filters/Posterize.js +3 -3
- package/lib/filters/RGB.js +3 -3
- package/lib/filters/RGBA.js +3 -3
- package/lib/filters/Threshold.js +3 -3
- package/lib/index.js +1 -1
- package/lib/napi-backend.d.ts +2 -0
- package/lib/napi-backend.js +15 -0
- package/lib/shapes/Arc.js +5 -5
- package/lib/shapes/Arrow.js +5 -5
- package/lib/shapes/Circle.js +4 -4
- package/lib/shapes/Ellipse.js +4 -4
- package/lib/shapes/Image.js +5 -5
- package/lib/shapes/Label.js +7 -7
- package/lib/shapes/Line.js +6 -6
- package/lib/shapes/Path.js +5 -5
- package/lib/shapes/Rect.js +5 -5
- package/lib/shapes/RegularPolygon.js +5 -5
- package/lib/shapes/Ring.js +4 -4
- package/lib/shapes/Sprite.js +5 -5
- package/lib/shapes/Star.js +4 -4
- package/lib/shapes/Text.d.ts +0 -1
- package/lib/shapes/Text.js +32 -30
- package/lib/shapes/TextPath.js +7 -7
- package/lib/shapes/Transformer.js +12 -11
- package/lib/shapes/Wedge.js +5 -5
- package/lib/skia-backend.js +17 -25
- package/package.json +31 -34
package/lib/Animation.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var _a;
|
|
2
|
-
import { glob } from
|
|
3
|
-
import { Node } from
|
|
4
|
-
import { Util } from
|
|
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
|
|
2
|
-
import { SceneContext, HitContext } from
|
|
3
|
-
import { Konva } from
|
|
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
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { getNumberValidator } from
|
|
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 [
|
|
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
|
|
2
|
-
import { Konva } from
|
|
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
|
|
3
|
-
import { Konva } from
|
|
2
|
+
export { Konva } from './_CoreInternals.js';
|
|
3
|
+
import { Konva } from './_CoreInternals.js';
|
|
4
4
|
export default Konva;
|
package/lib/DragAndDrop.js
CHANGED
package/lib/Factory.js
CHANGED
package/lib/FastLayer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Util } from
|
|
2
|
-
import { Layer } from
|
|
3
|
-
import { _registerNode } from
|
|
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
package/lib/Global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Konva JavaScript Framework v10.
|
|
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.
|
|
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
|
|
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
|
-
//
|
|
178
|
-
// it is
|
|
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
|
-
|
|
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
|
|
2
|
-
import { Container } from
|
|
3
|
-
import { _registerNode } from
|
|
4
|
-
import { Factory } from
|
|
5
|
-
import { getBooleanValidator } from
|
|
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
|
|
2
|
-
import { Container } from
|
|
3
|
-
import { Node } from
|
|
4
|
-
import { Factory } from
|
|
5
|
-
import { SceneCanvas, HitCanvas } from
|
|
6
|
-
import { shapes } from
|
|
7
|
-
import { _registerNode, Konva } from
|
|
8
|
-
import { DD } from
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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)
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
(
|
|
1879
|
-
}
|
|
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
|
|
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) {
|
package/lib/PointerEvents.js
CHANGED
package/lib/Shape.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Konva } from
|
|
2
|
-
import { Transform, Util } from
|
|
3
|
-
import { Factory } from
|
|
4
|
-
import { Node } from
|
|
5
|
-
import { getNumberValidator, getNumberOrAutoValidator, getStringValidator, getBooleanValidator, getStringOrGradientValidator, } from
|
|
6
|
-
import { _boundedShapes, _registerNode } from
|
|
7
|
-
import * as PointerEvents from
|
|
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
|
-
|
|
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
|
|
2
|
-
import { Factory } from
|
|
3
|
-
import { Container } from
|
|
4
|
-
import { Konva } from
|
|
5
|
-
import { SceneCanvas, HitCanvas } from
|
|
6
|
-
import { DD } from
|
|
7
|
-
import { _registerNode } from
|
|
8
|
-
import * as PointerEvents from
|
|
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
|
|
2
|
-
import { Animation } from
|
|
3
|
-
import { Node } from
|
|
4
|
-
import { Konva } from
|
|
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 |
|
|
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()
|
|
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):
|
|
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 & {});
|