konva 10.9.0 → 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 -18838
- 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 +2 -2
- package/lib/Context.js +17 -20
- 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.d.ts +2 -0
- package/lib/Node.js +76 -76
- package/lib/PointerEvents.js +1 -1
- package/lib/Shape.d.ts +5 -1
- package/lib/Shape.js +37 -43
- package/lib/Stage.js +8 -8
- package/lib/Tween.js +4 -4
- package/lib/Util.d.ts +67 -3
- package/lib/Util.js +124 -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 +27 -3
- package/lib/filters/Brighten.js +3 -3
- package/lib/filters/Brightness.js +9 -3
- package/lib/filters/Contrast.js +9 -5
- package/lib/filters/Emboss.js +17 -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 +36 -34
- package/lib/shapes/TextPath.d.ts +3 -2
- package/lib/shapes/TextPath.js +71 -46
- 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/_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 } 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
|
|
@@ -302,6 +302,30 @@ export const Blur = function Blur(imageData, pixelRatio = 1) {
|
|
|
302
302
|
filterGaussBlurRGBA(imageData, radius);
|
|
303
303
|
}
|
|
304
304
|
};
|
|
305
|
+
// CSS blur(σ) where the 2D context has no `filter`. A stack blur of radius 2σ
|
|
306
|
+
// stays within about 10/255 alpha of the native Gaussian in Chromium, Firefox
|
|
307
|
+
// and WebKit. Like the native filter, it has no radius limit and reads the
|
|
308
|
+
// area beyond the image as transparent: a 1px transparent border is what the
|
|
309
|
+
// blur repeats past the edges.
|
|
310
|
+
_registerCSSFilterFallback('blur', (imageData, sigma, pixelRatio) => {
|
|
311
|
+
const radius = Math.round(2 * sigma * pixelRatio);
|
|
312
|
+
if (radius <= 0) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const { width, height, data } = imageData, row = width * 4, framedRow = row + 8, framed = {
|
|
316
|
+
width: width + 2,
|
|
317
|
+
height: height + 2,
|
|
318
|
+
data: new Uint8ClampedArray(framedRow * (height + 2)),
|
|
319
|
+
};
|
|
320
|
+
for (let y = 0; y < height; y++) {
|
|
321
|
+
framed.data.set(data.subarray(y * row, y * row + row), (y + 1) * framedRow + 4);
|
|
322
|
+
}
|
|
323
|
+
filterGaussBlurRGBA(framed, radius);
|
|
324
|
+
for (let y = 0; y < height; y++) {
|
|
325
|
+
const start = (y + 1) * framedRow + 4;
|
|
326
|
+
data.set(framed.data.subarray(start, start + row), y * row);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
305
329
|
Factory.addGetterSetter(Node, 'blurRadius', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
306
330
|
/**
|
|
307
331
|
* get/set blur radius. Use with {@link Konva.Filters.Blur} filter
|
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,5 +1,6 @@
|
|
|
1
|
+
import { _registerCSSFilterFallback } from '../Node.js';
|
|
1
2
|
// The shared brightness accessor is registered by Brighten.
|
|
2
|
-
import
|
|
3
|
+
import './Brighten.js';
|
|
3
4
|
/**
|
|
4
5
|
* Brightness Filter.
|
|
5
6
|
* CSS-compatible brightness multiplier. An unset brightness leaves pixels unchanged.
|
|
@@ -12,7 +13,12 @@ import "./Brighten.js";
|
|
|
12
13
|
* node.brightness(1.5); // 50% brighter (CSS-compatible)
|
|
13
14
|
*/
|
|
14
15
|
export const Brightness = function (imageData) {
|
|
15
|
-
|
|
16
|
+
brighten(imageData, this.attrs.brightness === undefined ? 1 : this.brightness());
|
|
17
|
+
};
|
|
18
|
+
// CSS brightness(v) is the same multiplier.
|
|
19
|
+
_registerCSSFilterFallback('brightness', brighten);
|
|
20
|
+
function brighten(imageData, brightness) {
|
|
21
|
+
const data = imageData.data, len = data.length;
|
|
16
22
|
for (let i = 0; i < len; i += 4) {
|
|
17
23
|
// red
|
|
18
24
|
data[i] = Math.min(255, data[i] * brightness);
|
|
@@ -21,4 +27,4 @@ export const Brightness = function (imageData) {
|
|
|
21
27
|
// blue
|
|
22
28
|
data[i + 2] = Math.min(255, data[i + 2] * brightness);
|
|
23
29
|
}
|
|
24
|
-
}
|
|
30
|
+
}
|
package/lib/filters/Contrast.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, _registerCSSFilterFallback } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
/**
|
|
5
5
|
* Contrast Filter.
|
|
6
6
|
* @function
|
|
@@ -12,7 +12,11 @@ import { getNumberValidator } from "../Validators.js";
|
|
|
12
12
|
* node.contrast(10);
|
|
13
13
|
*/
|
|
14
14
|
export const Contrast = function (imageData) {
|
|
15
|
-
|
|
15
|
+
applyContrast(imageData, Math.pow((this.contrast() + 100) / 100, 2));
|
|
16
|
+
};
|
|
17
|
+
// CSS contrast(v) scales the distance from mid-grey by v.
|
|
18
|
+
_registerCSSFilterFallback('contrast', applyContrast);
|
|
19
|
+
function applyContrast(imageData, adjust) {
|
|
16
20
|
const data = imageData.data, nPixels = data.length;
|
|
17
21
|
let red = 150, green = 150, blue = 150;
|
|
18
22
|
for (let i = 0; i < nPixels; i += 4) {
|
|
@@ -44,7 +48,7 @@ export const Contrast = function (imageData) {
|
|
|
44
48
|
data[i + 1] = green;
|
|
45
49
|
data[i + 2] = blue;
|
|
46
50
|
}
|
|
47
|
-
}
|
|
51
|
+
}
|
|
48
52
|
/**
|
|
49
53
|
* get/set filter contrast. The contrast is a number between -100 and 100.
|
|
50
54
|
* Use with {@link Konva.Filters.Contrast} filter.
|
package/lib/filters/Emboss.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Util } from '../Util.js';
|
|
3
|
+
import { Node } from '../Node.js';
|
|
4
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
5
|
/**
|
|
5
6
|
* Emboss Filter.
|
|
6
7
|
* @function
|
|
@@ -15,13 +16,14 @@ import { getNumberValidator } from "../Validators.js";
|
|
|
15
16
|
* node.embossBlend(true);
|
|
16
17
|
*/
|
|
17
18
|
export const Emboss = function (imageData) {
|
|
18
|
-
var _a, _b, _c, _d
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
|
+
var _e, _f, _g, _h;
|
|
19
21
|
const data = imageData.data;
|
|
20
22
|
const w = imageData.width;
|
|
21
23
|
const h = imageData.height;
|
|
22
24
|
// Inputs from Konva node
|
|
23
|
-
const strength01 = Math.min(1, Math.max(0, (
|
|
24
|
-
const whiteLevel01 = Math.min(1, Math.max(0, (
|
|
25
|
+
const strength01 = Math.min(1, Math.max(0, (_e = (_a = this.embossStrength) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _e !== void 0 ? _e : 0.5)); // [0..1]
|
|
26
|
+
const whiteLevel01 = Math.min(1, Math.max(0, (_f = (_b = this.embossWhiteLevel) === null || _b === void 0 ? void 0 : _b.call(this)) !== null && _f !== void 0 ? _f : 0.5)); // [0..1]
|
|
25
27
|
// Convert string direction to degrees
|
|
26
28
|
const directionMap = {
|
|
27
29
|
'top-left': 315,
|
|
@@ -33,8 +35,13 @@ export const Emboss = function (imageData) {
|
|
|
33
35
|
'bottom-left': 45,
|
|
34
36
|
left: 0,
|
|
35
37
|
};
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
+
const direction = (_g = (_c = this.embossDirection) === null || _c === void 0 ? void 0 : _c.call(this)) !== null && _g !== void 0 ? _g : 'top-left';
|
|
39
|
+
let directionDeg = directionMap[direction]; // degrees
|
|
40
|
+
if (directionDeg === undefined) {
|
|
41
|
+
Util.warn('Unknown emboss direction: "' + direction + '". Using "top-left".');
|
|
42
|
+
directionDeg = directionMap['top-left'];
|
|
43
|
+
}
|
|
44
|
+
const blend = !!((_h = (_d = this.embossBlend) === null || _d === void 0 ? void 0 : _d.call(this)) !== null && _h !== void 0 ? _h : false);
|
|
38
45
|
// Internal mapping:
|
|
39
46
|
// - "strength" was 0..10; we honor your 0..1 API and scale accordingly.
|
|
40
47
|
// - Sobel directional response is roughly in [-1020..1020] for 8-bit luminance; scale to ~±128.
|
|
@@ -42,7 +49,8 @@ export const Emboss = function (imageData) {
|
|
|
42
49
|
const bias = whiteLevel01 * 255;
|
|
43
50
|
const dirRad = (directionDeg * Math.PI) / 180;
|
|
44
51
|
const cx = Math.cos(dirRad);
|
|
45
|
-
|
|
52
|
+
// the angles above are measured with y up, but image rows go down
|
|
53
|
+
const cy = -Math.sin(dirRad);
|
|
46
54
|
const SCALE = (128 / 1020) * strength; // ≈0.1255 * strength
|
|
47
55
|
// Precompute luminance (Rec.709)
|
|
48
56
|
const lum = new Float32Array(w * h);
|
package/lib/filters/Enhance.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
|
function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
|
5
5
|
// Compute the range of the data
|
|
6
6
|
const fromRange = fromMax - fromMin, toRange = toMax - toMin;
|
package/lib/filters/HSL.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
|
Factory.addGetterSetter(Node, 'hue', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
5
5
|
/**
|
|
6
6
|
* get/set hsv hue in degrees. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter.
|
package/lib/filters/HSV.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
|
* HSV Filter. Adjusts the hue, saturation and value
|
|
6
6
|
* @function
|
|
@@ -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
|
* ToPolar Filter. Converts image data to polar coordinates. Performs
|
|
6
6
|
* w*h*4 pixel reads and w*h pixel writes. The r axis is placed along
|
package/lib/filters/Mask.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
|
function pixelAt(idata, x, y) {
|
|
5
5
|
let idx = (y * idata.width + x) * 4;
|
|
6
6
|
const d = [];
|
package/lib/filters/Noise.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
|
* Noise Filter. Randomly adds or substracts to the color channels
|
|
6
6
|
* @function
|
package/lib/filters/Pixelate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Util } from
|
|
3
|
-
import { Node } from
|
|
4
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Util } from '../Util.js';
|
|
3
|
+
import { Node } from '../Node.js';
|
|
4
|
+
import { getNumberValidator } from '../Validators.js';
|
|
5
5
|
/**
|
|
6
6
|
* Pixelate Filter. Averages groups of pixels and redraws
|
|
7
7
|
* them as larger pixels
|
package/lib/filters/Posterize.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
|
* Posterize Filter. Adjusts the channels so that there are no more
|
|
6
6
|
* than n different values for that channel. This is also applied
|
package/lib/filters/RGB.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { RGBComponent } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { RGBComponent } from '../Validators.js';
|
|
4
4
|
/**
|
|
5
5
|
* RGB Filter
|
|
6
6
|
* @function
|
package/lib/filters/RGBA.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
3
|
// red, green and blue are registered there
|
|
4
|
-
import
|
|
4
|
+
import './RGB.js';
|
|
5
5
|
/**
|
|
6
6
|
* RGBA Filter
|
|
7
7
|
* @function
|
package/lib/filters/Threshold.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
|
* Threshold Filter. Pushes any value above the mid point to
|
|
6
6
|
* the max and any value below the mid point to the min.
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Konva } from
|
|
1
|
+
import { Konva } from './_FullInternals.js';
|
|
2
2
|
export default Konva;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Konva } from './_CoreInternals.js';
|
|
2
|
+
import { Canvas, DOMMatrix, Image, Path2D } from '@napi-rs/canvas';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
global.DOMMatrix = DOMMatrix;
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
global.Path2D = Path2D;
|
|
7
|
+
Konva.setCanvasBackend({
|
|
8
|
+
name: 'napi-rs-canvas',
|
|
9
|
+
createCanvas: () => new Canvas(300, 300),
|
|
10
|
+
createImage: () => new Image(),
|
|
11
|
+
createPath2D: (path) => new Path2D(path),
|
|
12
|
+
});
|
|
13
|
+
// the core Konva object, without shapes and filters. `import 'konva'` extends
|
|
14
|
+
// this same object with them
|
|
15
|
+
export default Konva;
|
package/lib/shapes/Arc.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { Konva } from
|
|
4
|
-
import { getNumberValidator, getBooleanValidator } from
|
|
5
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { Konva } from '../Global.js';
|
|
4
|
+
import { getNumberValidator, getBooleanValidator } from '../Validators.js';
|
|
5
|
+
import { _registerNode } from '../Global.js';
|
|
6
6
|
/**
|
|
7
7
|
* Arc constructor
|
|
8
8
|
* @constructor
|
package/lib/shapes/Arrow.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Line } from
|
|
3
|
-
import { getNumberValidator } from
|
|
4
|
-
import { _registerNode } from
|
|
5
|
-
import { Path } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Line } from './Line.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
import { Path } from './Path.js';
|
|
6
6
|
/**
|
|
7
7
|
* Arrow constructor
|
|
8
8
|
* @constructor
|
package/lib/shapes/Circle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { getNumberValidator } from
|
|
4
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
5
|
/**
|
|
6
6
|
* Circle constructor
|
|
7
7
|
* @constructor
|
package/lib/shapes/Ellipse.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { getNumberValidator } from
|
|
4
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
5
|
/**
|
|
6
6
|
* Ellipse constructor
|
|
7
7
|
* @constructor
|
package/lib/shapes/Image.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Util } from
|
|
2
|
-
import { Factory } from
|
|
3
|
-
import { Shape } from
|
|
4
|
-
import { _registerNode } from
|
|
5
|
-
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from
|
|
1
|
+
import { Util } from '../Util.js';
|
|
2
|
+
import { Factory } from '../Factory.js';
|
|
3
|
+
import { Shape } from '../Shape.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from '../Validators.js';
|
|
6
6
|
/**
|
|
7
7
|
* Image constructor
|
|
8
8
|
* @constructor
|
package/lib/shapes/Label.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Util } from
|
|
3
|
-
import { Shape } from
|
|
4
|
-
import { Group } from
|
|
5
|
-
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from
|
|
6
|
-
import { _registerNode } from
|
|
7
|
-
import { Text } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Util } from '../Util.js';
|
|
3
|
+
import { Shape } from '../Shape.js';
|
|
4
|
+
import { Group } from '../Group.js';
|
|
5
|
+
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from '../Validators.js';
|
|
6
|
+
import { _registerNode } from '../Global.js';
|
|
7
|
+
import { Text } from './Text.js';
|
|
8
8
|
// constants
|
|
9
9
|
const ATTR_CHANGE_LIST = [
|
|
10
10
|
...Text.prototype._attrsAffectingSize,
|