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/Util.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import { Konva } from
|
|
2
|
-
const NODE_ERROR =
|
|
3
|
-
|
|
4
|
-
Looks like you are trying to use Konva.js in Node.js environment (or in a Web Worker), because "document" object is undefined.
|
|
5
|
-
|
|
6
|
-
To use Konva.js in Node.js environment, you need to use the "canvas-backend" or "skia-backend" module.
|
|
7
|
-
|
|
8
|
-
bash: npm install canvas
|
|
9
|
-
js: import "konva/canvas-backend";
|
|
10
|
-
|
|
11
|
-
or
|
|
12
|
-
|
|
13
|
-
bash: npm install skia-canvas
|
|
14
|
-
js: import "konva/skia-backend";
|
|
15
|
-
`;
|
|
1
|
+
import { Konva } from './Global.js';
|
|
2
|
+
const NODE_ERROR = 'Konva needs a canvas outside the browser. Import "konva/canvas-backend", "konva/skia-backend" or "konva/napi-backend", or call Konva.setCanvasBackend().';
|
|
16
3
|
const ensureBrowser = () => {
|
|
17
4
|
if (typeof document === 'undefined') {
|
|
18
5
|
throw new Error(NODE_ERROR);
|
|
@@ -282,13 +269,11 @@ export class Transform {
|
|
|
282
269
|
result.skewY = 0;
|
|
283
270
|
}
|
|
284
271
|
else if (c != 0 || d != 0) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
result.
|
|
289
|
-
result.scaleY =
|
|
290
|
-
result.skewX = 0;
|
|
291
|
-
result.skewY = delta && (a * c + b * d) / delta;
|
|
272
|
+
// a = b = 0: the x axis is collapsed, so scaleX and the skew stay 0 and
|
|
273
|
+
// only the y axis, the scaled unit vector (-sin, cos), carries the
|
|
274
|
+
// rotation. "+ 0" turns the -0 that atan2 gives for a zero angle into 0
|
|
275
|
+
result.rotation = Math.atan2(-c, d) + 0;
|
|
276
|
+
result.scaleY = Math.sqrt(c * c + d * d);
|
|
292
277
|
}
|
|
293
278
|
else {
|
|
294
279
|
// a = b = c = d = 0
|
|
@@ -449,8 +434,6 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
449
434
|
yellow: [255, 255, 0],
|
|
450
435
|
yellowgreen: [154, 205, 50],
|
|
451
436
|
};
|
|
452
|
-
// Cache for canvas farbling detection
|
|
453
|
-
let _isCanvasFarblingActive = null;
|
|
454
437
|
// A stage may be rendered in another window than the one Konva was imported
|
|
455
438
|
// into, and a window that is not visible gives almost no frames. So frames are
|
|
456
439
|
// asked from the window of the stage, and the callbacks are kept per window
|
|
@@ -590,18 +573,36 @@ export const Util = {
|
|
|
590
573
|
},
|
|
591
574
|
createCanvasElement() {
|
|
592
575
|
ensureBrowser();
|
|
593
|
-
|
|
594
|
-
// on some environments canvas.style is readonly
|
|
595
|
-
try {
|
|
596
|
-
canvas.style = canvas.style || {};
|
|
597
|
-
}
|
|
598
|
-
catch (e) { }
|
|
599
|
-
return canvas;
|
|
576
|
+
return document.createElement('canvas');
|
|
600
577
|
},
|
|
601
578
|
createImageElement() {
|
|
602
579
|
ensureBrowser();
|
|
603
580
|
return document.createElement('img');
|
|
604
581
|
},
|
|
582
|
+
/**
|
|
583
|
+
* Make a DOMMatrix of the canvas library Konva draws with. Without a createDOMMatrix
|
|
584
|
+
* in Konva.setCanvasBackend(), the class comes from the library's own context.
|
|
585
|
+
* @method
|
|
586
|
+
* @memberof Konva.Util
|
|
587
|
+
* @param {Array} [init] the six numbers a, b, c, d, e, f
|
|
588
|
+
* @returns {DOMMatrix}
|
|
589
|
+
*/
|
|
590
|
+
createDOMMatrix(init) {
|
|
591
|
+
// node-canvas accepts only its own DOMMatrix, so the global one may not fit
|
|
592
|
+
const Matrix = getDummyContext().getTransform().constructor;
|
|
593
|
+
return new Matrix(init);
|
|
594
|
+
},
|
|
595
|
+
/**
|
|
596
|
+
* Make a Path2D of the canvas library Konva draws with, for example for a clipFunc.
|
|
597
|
+
* Without a createPath2D in Konva.setCanvasBackend(), it is the global Path2D.
|
|
598
|
+
* @method
|
|
599
|
+
* @memberof Konva.Util
|
|
600
|
+
* @param {String} [path] SVG path data
|
|
601
|
+
* @returns {Path2D}
|
|
602
|
+
*/
|
|
603
|
+
createPath2D(path) {
|
|
604
|
+
return new Path2D(path);
|
|
605
|
+
},
|
|
605
606
|
/*
|
|
606
607
|
* arg can be an image object or image data
|
|
607
608
|
*/
|
|
@@ -648,15 +649,15 @@ export const Util = {
|
|
|
648
649
|
* @memberof Konva.Util
|
|
649
650
|
* @returns {Boolean}
|
|
650
651
|
*/
|
|
651
|
-
isCanvasFarblingActive() {
|
|
652
|
-
|
|
653
|
-
|
|
652
|
+
isCanvasFarblingActive: _perCanvasBackend(() => {
|
|
653
|
+
let c;
|
|
654
|
+
try {
|
|
655
|
+
c = Util.createCanvasElement();
|
|
654
656
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
+
catch (e) {
|
|
658
|
+
// no canvas to read, e.g. Node.js without a backend
|
|
657
659
|
return false;
|
|
658
660
|
}
|
|
659
|
-
const c = this.createCanvasElement();
|
|
660
661
|
c.width = 10;
|
|
661
662
|
c.height = 10;
|
|
662
663
|
const ctx = c.getContext('2d', {
|
|
@@ -676,10 +677,9 @@ export const Util = {
|
|
|
676
677
|
break;
|
|
677
678
|
}
|
|
678
679
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
},
|
|
680
|
+
Util.releaseCanvas(c);
|
|
681
|
+
return isFarbling;
|
|
682
|
+
}),
|
|
683
683
|
/**
|
|
684
684
|
* Get a random color for hit detection (snapped to the hit color grid)
|
|
685
685
|
* @method
|
|
@@ -1220,3 +1220,84 @@ export const Util = {
|
|
|
1220
1220
|
}
|
|
1221
1221
|
},
|
|
1222
1222
|
};
|
|
1223
|
+
let activeBackend = { name: 'web', createCanvas: Util.createCanvasElement };
|
|
1224
|
+
const { createDOMMatrix, createPath2D } = Util;
|
|
1225
|
+
/**
|
|
1226
|
+
* Set the canvas library Konva draws with: Konva makes every canvas and image through it.
|
|
1227
|
+
* Applies to everything Konva creates afterwards, including the context it measures text
|
|
1228
|
+
* and makes gradients with. Stages and nodes created before keep their canvases, so
|
|
1229
|
+
* create them again after a switch.
|
|
1230
|
+
* @method
|
|
1231
|
+
* @name Konva.setCanvasBackend
|
|
1232
|
+
* @param {Object} backend
|
|
1233
|
+
* @param {String} backend.name reported by Konva.getCanvasBackend()
|
|
1234
|
+
* @param {Function} backend.createCanvas returns a new canvas
|
|
1235
|
+
* @param {Function} [backend.createImage] returns a new image
|
|
1236
|
+
* @param {Function} [backend.createDOMMatrix] returns a new DOMMatrix, see Konva.Util.createDOMMatrix
|
|
1237
|
+
* @param {Function} [backend.createPath2D] returns a new Path2D, see Konva.Util.createPath2D
|
|
1238
|
+
* @example
|
|
1239
|
+
* import { Canvas, Image } from '@napi-rs/canvas';
|
|
1240
|
+
* Konva.setCanvasBackend({
|
|
1241
|
+
* name: 'my-napi-rs',
|
|
1242
|
+
* createCanvas: () => new Canvas(300, 150),
|
|
1243
|
+
* createImage: () => new Image(),
|
|
1244
|
+
* });
|
|
1245
|
+
*/
|
|
1246
|
+
export function setCanvasBackend(backend) {
|
|
1247
|
+
var _a, _b;
|
|
1248
|
+
const { name, createCanvas, createImage } = backend;
|
|
1249
|
+
Util.createCanvasElement = createCanvas;
|
|
1250
|
+
Util.createDOMMatrix = ((_a = backend.createDOMMatrix) !== null && _a !== void 0 ? _a : createDOMMatrix);
|
|
1251
|
+
Util.createPath2D = ((_b = backend.createPath2D) !== null && _b !== void 0 ? _b : createPath2D);
|
|
1252
|
+
Util.createImageElement = createImage
|
|
1253
|
+
? createImage
|
|
1254
|
+
: () => {
|
|
1255
|
+
throw new Error(`Konva: the "${name}" canvas backend has no createImage(), so it can not load images.`);
|
|
1256
|
+
};
|
|
1257
|
+
activeBackend = { name, createCanvas: Util.createCanvasElement };
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* The name of the canvas backend Konva draws with: "web" in a browser, "offscreen-canvas" in a
|
|
1261
|
+
* Web Worker, the name given to Konva.setCanvasBackend(), "custom" when
|
|
1262
|
+
* Konva.Util.createCanvasElement was replaced directly, or null when there is none, as in
|
|
1263
|
+
* Node.js before a backend is set.
|
|
1264
|
+
* @method
|
|
1265
|
+
* @name Konva.getCanvasBackend
|
|
1266
|
+
* @returns {String|null}
|
|
1267
|
+
*/
|
|
1268
|
+
export function getCanvasBackend() {
|
|
1269
|
+
if (Util.createCanvasElement !== activeBackend.createCanvas) {
|
|
1270
|
+
return 'custom';
|
|
1271
|
+
}
|
|
1272
|
+
// checked on each call: a document can appear after Konva loads (jsdom)
|
|
1273
|
+
return activeBackend.name === 'web' && typeof document === 'undefined'
|
|
1274
|
+
? null
|
|
1275
|
+
: activeBackend.name;
|
|
1276
|
+
}
|
|
1277
|
+
// a Web Worker has no document, but it has OffscreenCanvas
|
|
1278
|
+
if (typeof document === 'undefined' && typeof OffscreenCanvas !== 'undefined') {
|
|
1279
|
+
setCanvasBackend({
|
|
1280
|
+
name: 'offscreen-canvas',
|
|
1281
|
+
createCanvas: () => new OffscreenCanvas(300, 150),
|
|
1282
|
+
createImage: () => {
|
|
1283
|
+
throw new Error('Konva: a Web Worker has no image element. Load the image with createImageBitmap() and pass the ImageBitmap to Konva.Image.');
|
|
1284
|
+
},
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
// A value Konva computes from a canvas, such as a feature check, belongs to
|
|
1288
|
+
// the library that made the canvas. It is recomputed when the canvas factory
|
|
1289
|
+
// changes, by setCanvasBackend() or by assigning Util.createCanvasElement
|
|
1290
|
+
export function _perCanvasBackend(compute) {
|
|
1291
|
+
let factory;
|
|
1292
|
+
let value;
|
|
1293
|
+
return () => {
|
|
1294
|
+
if (factory !== Util.createCanvasElement) {
|
|
1295
|
+
value = compute();
|
|
1296
|
+
factory = Util.createCanvasElement;
|
|
1297
|
+
}
|
|
1298
|
+
return value;
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
// The context Konva measures text and makes gradients and patterns with. A
|
|
1302
|
+
// gradient from one canvas library is ignored by the context of another
|
|
1303
|
+
export const getDummyContext = _perCanvasBackend(() => Util.createCanvasElement().getContext('2d'));
|
package/lib/Validators.js
CHANGED
package/lib/_CoreInternals.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transform } from './Util.ts';
|
|
1
|
+
import { Transform, setCanvasBackend, getCanvasBackend } from './Util.ts';
|
|
2
2
|
import { Node } from './Node.ts';
|
|
3
3
|
import { Container } from './Container.ts';
|
|
4
4
|
import { Stage } from './Stage.ts';
|
|
@@ -22,7 +22,6 @@ export declare const Konva: {
|
|
|
22
22
|
autoDrawEnabled: boolean;
|
|
23
23
|
hitOnDragEnabled: boolean;
|
|
24
24
|
capturePointerEventsEnabled: boolean;
|
|
25
|
-
_renderBackend: string;
|
|
26
25
|
legacyTextRendering: boolean;
|
|
27
26
|
pixelRatio: number;
|
|
28
27
|
dragDistance: number;
|
|
@@ -62,6 +61,8 @@ export declare const Konva: {
|
|
|
62
61
|
* }
|
|
63
62
|
*/
|
|
64
63
|
beginUpdateBatch: typeof Node._beginUpdateBatch;
|
|
64
|
+
setCanvasBackend: typeof setCanvasBackend;
|
|
65
|
+
getCanvasBackend: typeof getCanvasBackend;
|
|
65
66
|
Util: {
|
|
66
67
|
_isElement(obj: any): obj is Element;
|
|
67
68
|
_isFunction(obj: any): boolean;
|
|
@@ -72,15 +73,17 @@ export declare const Konva: {
|
|
|
72
73
|
_isBoolean(obj: any): obj is boolean;
|
|
73
74
|
isObject(val: any): val is object;
|
|
74
75
|
isValidSelector(selector: any): boolean;
|
|
75
|
-
_sign(number: number): 1 |
|
|
76
|
+
_sign(number: number): -1 | 1;
|
|
76
77
|
requestAnimFrame(callback: Function, win?: Window | null): void;
|
|
77
78
|
createCanvasElement(): HTMLCanvasElement;
|
|
78
79
|
createImageElement(): HTMLImageElement;
|
|
80
|
+
createDOMMatrix(init?: number[]): DOMMatrix;
|
|
81
|
+
createPath2D(path?: string): Path2D;
|
|
79
82
|
_urlToImage(url: string, callback: Function, onError?: (error: Error) => void): void;
|
|
80
83
|
_rgbToHex(r: number, g: number, b: number): string;
|
|
81
84
|
_hexToRgb(hex: string): import("./types.ts").RGB;
|
|
82
85
|
getRandomColor(): string;
|
|
83
|
-
isCanvasFarblingActive()
|
|
86
|
+
isCanvasFarblingActive: () => boolean;
|
|
84
87
|
getHitColor(): string;
|
|
85
88
|
getHitColorKey(r: number, g: number, b: number): string;
|
|
86
89
|
getSnappedHexColor(hex: string): string;
|
|
@@ -153,7 +156,7 @@ export declare const Konva: {
|
|
|
153
156
|
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
|
|
154
157
|
_prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
|
|
155
158
|
_assign<T, U>(target: T, source: U): T & U;
|
|
156
|
-
_getEventType(type: string):
|
|
159
|
+
_getEventType(type: string): 'mouse' | 'touch' | 'pointer';
|
|
157
160
|
_getFirstPointerId(evt: any): any;
|
|
158
161
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
159
162
|
_cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
|
|
@@ -176,10 +179,10 @@ export declare const Konva: {
|
|
|
176
179
|
startPointerPos: import("./types.ts").Vector2d;
|
|
177
180
|
offset: import("./types.ts").Vector2d;
|
|
178
181
|
pointerId?: number;
|
|
179
|
-
pointerEventType?: Stage[
|
|
182
|
+
pointerEventType?: Stage['_pointerEventType'];
|
|
180
183
|
lastPos?: import("./types.ts").Vector2d;
|
|
181
184
|
startEvent?: any;
|
|
182
|
-
dragStatus:
|
|
185
|
+
dragStatus: 'ready' | 'dragging' | 'stopped';
|
|
183
186
|
}>;
|
|
184
187
|
_listenToWindow(win: Window): void;
|
|
185
188
|
_batchEvents(callback: () => void, win?: Window): void;
|
|
@@ -189,20 +192,20 @@ export declare const Konva: {
|
|
|
189
192
|
startPointerPos: import("./types.ts").Vector2d;
|
|
190
193
|
offset: import("./types.ts").Vector2d;
|
|
191
194
|
pointerId?: number;
|
|
192
|
-
pointerEventType?: Stage[
|
|
195
|
+
pointerEventType?: Stage['_pointerEventType'];
|
|
193
196
|
lastPos?: import("./types.ts").Vector2d;
|
|
194
197
|
startEvent?: any;
|
|
195
|
-
dragStatus:
|
|
198
|
+
dragStatus: 'ready' | 'dragging' | 'stopped';
|
|
196
199
|
}): void;
|
|
197
200
|
_endDragAfter(evt: any, only?: {
|
|
198
201
|
node: Node;
|
|
199
202
|
startPointerPos: import("./types.ts").Vector2d;
|
|
200
203
|
offset: import("./types.ts").Vector2d;
|
|
201
204
|
pointerId?: number;
|
|
202
|
-
pointerEventType?: Stage[
|
|
205
|
+
pointerEventType?: Stage['_pointerEventType'];
|
|
203
206
|
lastPos?: import("./types.ts").Vector2d;
|
|
204
207
|
startEvent?: any;
|
|
205
|
-
dragStatus:
|
|
208
|
+
dragStatus: 'ready' | 'dragging' | 'stopped';
|
|
206
209
|
}): void;
|
|
207
210
|
};
|
|
208
211
|
Shape: typeof Shape;
|
|
@@ -234,6 +237,7 @@ export declare const Konva: {
|
|
|
234
237
|
};
|
|
235
238
|
export declare namespace Konva {
|
|
236
239
|
type Vector2d = import('./types.ts').Vector2d;
|
|
240
|
+
type CanvasBackend = import('./Util.ts').CanvasBackend;
|
|
237
241
|
type IRect = import('./types.ts').IRect;
|
|
238
242
|
type GetSet<Type, This> = import('./types.ts').GetSet<Type, This>;
|
|
239
243
|
type Filter = import('./Node.ts').Filter;
|
package/lib/_CoreInternals.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// what is core parts of Konva?
|
|
2
|
-
import { Konva as Global } from
|
|
3
|
-
import { Util, Transform } from
|
|
4
|
-
import { Node } from
|
|
5
|
-
import { Container } from
|
|
6
|
-
import { Stage, stages } from
|
|
7
|
-
import { Layer } from
|
|
8
|
-
import { FastLayer } from
|
|
9
|
-
import { Group } from
|
|
10
|
-
import { DD } from
|
|
11
|
-
import { Shape, shapes } from
|
|
12
|
-
import { Animation } from
|
|
13
|
-
import { Tween, Easings } from
|
|
14
|
-
import { Context } from
|
|
15
|
-
import { Canvas } from
|
|
2
|
+
import { Konva as Global } from './Global.js';
|
|
3
|
+
import { Util, Transform, setCanvasBackend, getCanvasBackend } from './Util.js';
|
|
4
|
+
import { Node } from './Node.js';
|
|
5
|
+
import { Container } from './Container.js';
|
|
6
|
+
import { Stage, stages } from './Stage.js';
|
|
7
|
+
import { Layer } from './Layer.js';
|
|
8
|
+
import { FastLayer } from './FastLayer.js';
|
|
9
|
+
import { Group } from './Group.js';
|
|
10
|
+
import { DD } from './DragAndDrop.js';
|
|
11
|
+
import { Shape, shapes } from './Shape.js';
|
|
12
|
+
import { Animation } from './Animation.js';
|
|
13
|
+
import { Tween, Easings } from './Tween.js';
|
|
14
|
+
import { Context } from './Context.js';
|
|
15
|
+
import { Canvas } from './Canvas.js';
|
|
16
16
|
export const Konva = Util._assign(Global, {
|
|
17
17
|
/**
|
|
18
18
|
* Defer automatic Konva.Transformer updates across many synchronous node changes
|
|
@@ -40,6 +40,8 @@ export const Konva = Util._assign(Global, {
|
|
|
40
40
|
* }
|
|
41
41
|
*/
|
|
42
42
|
beginUpdateBatch: Node._beginUpdateBatch,
|
|
43
|
+
setCanvasBackend,
|
|
44
|
+
getCanvasBackend,
|
|
43
45
|
Util,
|
|
44
46
|
Transform,
|
|
45
47
|
Node,
|
package/lib/_FullInternals.d.ts
CHANGED
|
@@ -28,7 +28,6 @@ export declare const Konva: {
|
|
|
28
28
|
autoDrawEnabled: boolean;
|
|
29
29
|
hitOnDragEnabled: boolean;
|
|
30
30
|
capturePointerEventsEnabled: boolean;
|
|
31
|
-
_renderBackend: string;
|
|
32
31
|
legacyTextRendering: boolean;
|
|
33
32
|
pixelRatio: number;
|
|
34
33
|
dragDistance: number;
|
|
@@ -43,6 +42,8 @@ export declare const Konva: {
|
|
|
43
42
|
_injectGlobal(Konva: any): void;
|
|
44
43
|
} & {
|
|
45
44
|
beginUpdateBatch: typeof import("./Node.ts").Node._beginUpdateBatch;
|
|
45
|
+
setCanvasBackend: typeof import("./Util.ts").setCanvasBackend;
|
|
46
|
+
getCanvasBackend: typeof import("./Util.ts").getCanvasBackend;
|
|
46
47
|
Util: {
|
|
47
48
|
_isElement(obj: any): obj is Element;
|
|
48
49
|
_isFunction(obj: any): boolean;
|
|
@@ -53,15 +54,17 @@ export declare const Konva: {
|
|
|
53
54
|
_isBoolean(obj: any): obj is boolean;
|
|
54
55
|
isObject(val: any): val is object;
|
|
55
56
|
isValidSelector(selector: any): boolean;
|
|
56
|
-
_sign(number: number): 1 |
|
|
57
|
+
_sign(number: number): -1 | 1;
|
|
57
58
|
requestAnimFrame(callback: Function, win?: Window | null): void;
|
|
58
59
|
createCanvasElement(): HTMLCanvasElement;
|
|
59
60
|
createImageElement(): HTMLImageElement;
|
|
61
|
+
createDOMMatrix(init?: number[]): DOMMatrix;
|
|
62
|
+
createPath2D(path?: string): Path2D;
|
|
60
63
|
_urlToImage(url: string, callback: Function, onError?: (error: Error) => void): void;
|
|
61
64
|
_rgbToHex(r: number, g: number, b: number): string;
|
|
62
65
|
_hexToRgb(hex: string): import("./types.ts").RGB;
|
|
63
66
|
getRandomColor(): string;
|
|
64
|
-
isCanvasFarblingActive()
|
|
67
|
+
isCanvasFarblingActive: () => boolean;
|
|
65
68
|
getHitColor(): string;
|
|
66
69
|
getHitColorKey(r: number, g: number, b: number): string;
|
|
67
70
|
getSnappedHexColor(hex: string): string;
|
|
@@ -134,7 +137,7 @@ export declare const Konva: {
|
|
|
134
137
|
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
|
|
135
138
|
_prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
|
|
136
139
|
_assign<T, U>(target: T, source: U): T & U;
|
|
137
|
-
_getEventType(type: string):
|
|
140
|
+
_getEventType(type: string): 'mouse' | 'touch' | 'pointer';
|
|
138
141
|
_getFirstPointerId(evt: any): any;
|
|
139
142
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
140
143
|
_cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
|
|
@@ -157,10 +160,10 @@ export declare const Konva: {
|
|
|
157
160
|
startPointerPos: import("./types.ts").Vector2d;
|
|
158
161
|
offset: import("./types.ts").Vector2d;
|
|
159
162
|
pointerId?: number;
|
|
160
|
-
pointerEventType?: import("./Stage.ts").Stage[
|
|
163
|
+
pointerEventType?: import("./Stage.ts").Stage['_pointerEventType'];
|
|
161
164
|
lastPos?: import("./types.ts").Vector2d;
|
|
162
165
|
startEvent?: any;
|
|
163
|
-
dragStatus:
|
|
166
|
+
dragStatus: 'ready' | 'dragging' | 'stopped';
|
|
164
167
|
}>;
|
|
165
168
|
_listenToWindow(win: Window): void;
|
|
166
169
|
_batchEvents(callback: () => void, win?: Window): void;
|
|
@@ -170,20 +173,20 @@ export declare const Konva: {
|
|
|
170
173
|
startPointerPos: import("./types.ts").Vector2d;
|
|
171
174
|
offset: import("./types.ts").Vector2d;
|
|
172
175
|
pointerId?: number;
|
|
173
|
-
pointerEventType?: import("./Stage.ts").Stage[
|
|
176
|
+
pointerEventType?: import("./Stage.ts").Stage['_pointerEventType'];
|
|
174
177
|
lastPos?: import("./types.ts").Vector2d;
|
|
175
178
|
startEvent?: any;
|
|
176
|
-
dragStatus:
|
|
179
|
+
dragStatus: 'ready' | 'dragging' | 'stopped';
|
|
177
180
|
}): void;
|
|
178
181
|
_endDragAfter(evt: any, only?: {
|
|
179
182
|
node: import("./Node.ts").Node;
|
|
180
183
|
startPointerPos: import("./types.ts").Vector2d;
|
|
181
184
|
offset: import("./types.ts").Vector2d;
|
|
182
185
|
pointerId?: number;
|
|
183
|
-
pointerEventType?: import("./Stage.ts").Stage[
|
|
186
|
+
pointerEventType?: import("./Stage.ts").Stage['_pointerEventType'];
|
|
184
187
|
lastPos?: import("./types.ts").Vector2d;
|
|
185
188
|
startEvent?: any;
|
|
186
|
-
dragStatus:
|
|
189
|
+
dragStatus: 'ready' | 'dragging' | 'stopped';
|
|
187
190
|
}): void;
|
|
188
191
|
};
|
|
189
192
|
Shape: typeof import("./Shape.ts").Shape;
|
|
@@ -260,6 +263,7 @@ export declare const Konva: {
|
|
|
260
263
|
};
|
|
261
264
|
export declare namespace Konva {
|
|
262
265
|
type Vector2d = Core.Vector2d;
|
|
266
|
+
type CanvasBackend = Core.CanvasBackend;
|
|
263
267
|
type IRect = Core.IRect;
|
|
264
268
|
type GetSet<Type, This> = Core.GetSet<Type, This>;
|
|
265
269
|
type Filter = Core.Filter;
|
package/lib/_FullInternals.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
// we need to import core of the Konva and then extend it with all additional objects
|
|
2
|
-
import { Konva as Core } from
|
|
2
|
+
import { Konva as Core } from './_CoreInternals.js';
|
|
3
3
|
// shapes
|
|
4
|
-
import { Arc } from
|
|
5
|
-
import { Arrow } from
|
|
6
|
-
import { Circle } from
|
|
7
|
-
import { Ellipse } from
|
|
8
|
-
import { Image } from
|
|
9
|
-
import { Label, Tag } from
|
|
10
|
-
import { Line } from
|
|
11
|
-
import { Path } from
|
|
12
|
-
import { Rect } from
|
|
13
|
-
import { RegularPolygon } from
|
|
14
|
-
import { Ring } from
|
|
15
|
-
import { Sprite } from
|
|
16
|
-
import { Star } from
|
|
17
|
-
import { Text } from
|
|
18
|
-
import { TextPath } from
|
|
19
|
-
import { Transformer } from
|
|
20
|
-
import { Wedge } from
|
|
4
|
+
import { Arc } from './shapes/Arc.js';
|
|
5
|
+
import { Arrow } from './shapes/Arrow.js';
|
|
6
|
+
import { Circle } from './shapes/Circle.js';
|
|
7
|
+
import { Ellipse } from './shapes/Ellipse.js';
|
|
8
|
+
import { Image } from './shapes/Image.js';
|
|
9
|
+
import { Label, Tag } from './shapes/Label.js';
|
|
10
|
+
import { Line } from './shapes/Line.js';
|
|
11
|
+
import { Path } from './shapes/Path.js';
|
|
12
|
+
import { Rect } from './shapes/Rect.js';
|
|
13
|
+
import { RegularPolygon } from './shapes/RegularPolygon.js';
|
|
14
|
+
import { Ring } from './shapes/Ring.js';
|
|
15
|
+
import { Sprite } from './shapes/Sprite.js';
|
|
16
|
+
import { Star } from './shapes/Star.js';
|
|
17
|
+
import { Text } from './shapes/Text.js';
|
|
18
|
+
import { TextPath } from './shapes/TextPath.js';
|
|
19
|
+
import { Transformer } from './shapes/Transformer.js';
|
|
20
|
+
import { Wedge } from './shapes/Wedge.js';
|
|
21
21
|
// filters
|
|
22
|
-
import { Blur } from
|
|
23
|
-
import { Brighten } from
|
|
24
|
-
import { Brightness } from
|
|
25
|
-
import { Contrast } from
|
|
26
|
-
import { Emboss } from
|
|
27
|
-
import { Enhance } from
|
|
28
|
-
import { Grayscale } from
|
|
29
|
-
import { HSL } from
|
|
30
|
-
import { HSV } from
|
|
31
|
-
import { Invert } from
|
|
32
|
-
import { Kaleidoscope } from
|
|
33
|
-
import { Mask } from
|
|
34
|
-
import { Noise } from
|
|
35
|
-
import { Pixelate } from
|
|
36
|
-
import { Posterize } from
|
|
37
|
-
import { RGB } from
|
|
38
|
-
import { RGBA } from
|
|
39
|
-
import { Sepia } from
|
|
40
|
-
import { Solarize } from
|
|
41
|
-
import { Threshold } from
|
|
22
|
+
import { Blur } from './filters/Blur.js';
|
|
23
|
+
import { Brighten } from './filters/Brighten.js';
|
|
24
|
+
import { Brightness } from './filters/Brightness.js';
|
|
25
|
+
import { Contrast } from './filters/Contrast.js';
|
|
26
|
+
import { Emboss } from './filters/Emboss.js';
|
|
27
|
+
import { Enhance } from './filters/Enhance.js';
|
|
28
|
+
import { Grayscale } from './filters/Grayscale.js';
|
|
29
|
+
import { HSL } from './filters/HSL.js';
|
|
30
|
+
import { HSV } from './filters/HSV.js';
|
|
31
|
+
import { Invert } from './filters/Invert.js';
|
|
32
|
+
import { Kaleidoscope } from './filters/Kaleidoscope.js';
|
|
33
|
+
import { Mask } from './filters/Mask.js';
|
|
34
|
+
import { Noise } from './filters/Noise.js';
|
|
35
|
+
import { Pixelate } from './filters/Pixelate.js';
|
|
36
|
+
import { Posterize } from './filters/Posterize.js';
|
|
37
|
+
import { RGB } from './filters/RGB.js';
|
|
38
|
+
import { RGBA } from './filters/RGBA.js';
|
|
39
|
+
import { Sepia } from './filters/Sepia.js';
|
|
40
|
+
import { Solarize } from './filters/Solarize.js';
|
|
41
|
+
import { Threshold } from './filters/Threshold.js';
|
|
42
42
|
export const Konva = Core.Util._assign(Core, {
|
|
43
43
|
Arc,
|
|
44
44
|
Arrow,
|
package/lib/canvas-backend.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
var _b;
|
|
3
|
-
import { Konva } from
|
|
4
|
-
// @ts-ignore
|
|
3
|
+
import { Konva } from './_CoreInternals.js';
|
|
5
4
|
import * as Canvas from 'canvas';
|
|
6
5
|
const canvas = Canvas['default'] || Canvas;
|
|
7
6
|
// @ts-ignore
|
|
@@ -15,19 +14,11 @@ global.DOMMatrix = canvas.DOMMatrix;
|
|
|
15
14
|
return `Path2D`;
|
|
16
15
|
}
|
|
17
16
|
});
|
|
18
|
-
Konva.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return node;
|
|
24
|
-
};
|
|
25
|
-
// create image in Node env
|
|
26
|
-
Konva.Util.createImageElement = () => {
|
|
27
|
-
const node = new canvas.Image();
|
|
28
|
-
return node;
|
|
29
|
-
};
|
|
30
|
-
Konva._renderBackend = 'node-canvas';
|
|
17
|
+
Konva.setCanvasBackend({
|
|
18
|
+
name: 'node-canvas',
|
|
19
|
+
createCanvas: () => canvas.createCanvas(300, 300),
|
|
20
|
+
createImage: () => new canvas.Image(),
|
|
21
|
+
});
|
|
31
22
|
// the core Konva object, without shapes and filters. `import 'konva'` extends
|
|
32
23
|
// this same object with them
|
|
33
24
|
export default Konva;
|
package/lib/filters/Blur.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node, _registerCSSFilterFallback } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node, _registerCSSFilterFallback } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
/*
|
|
5
5
|
the Gauss filter
|
|
6
6
|
master repo: https://github.com/pavelpower/kineticjsGaussFilter
|
package/lib/filters/Brighten.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
|
* Brighten Filter.
|
|
6
6
|
* @deprecated Use {@link Konva.Filters.Brightness} instead for CSS-compatible behavior.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _registerCSSFilterFallback } from
|
|
1
|
+
import { _registerCSSFilterFallback } from '../Node.js';
|
|
2
2
|
// The shared brightness accessor is registered by Brighten.
|
|
3
|
-
import
|
|
3
|
+
import './Brighten.js';
|
|
4
4
|
/**
|
|
5
5
|
* Brightness Filter.
|
|
6
6
|
* CSS-compatible brightness multiplier. An unset brightness leaves pixels unchanged.
|
package/lib/filters/Contrast.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node, _registerCSSFilterFallback } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node, _registerCSSFilterFallback } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
/**
|
|
5
5
|
* Contrast Filter.
|
|
6
6
|
* @function
|