konva 9.3.21 → 10.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/konva.js +664 -226
- package/konva.min.js +46 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +7 -11
- package/lib/BezierFunctions.js +9 -15
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +14 -20
- package/lib/Container.d.ts +7 -6
- package/lib/Container.js +12 -16
- package/lib/Context.d.ts +7 -5
- package/lib/Context.js +34 -14
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +3 -7
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +24 -27
- package/lib/Factory.d.ts +2 -2
- package/lib/Factory.js +24 -27
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +6 -10
- package/lib/Global.d.ts +4 -3
- package/lib/Global.js +19 -19
- package/lib/Group.d.ts +4 -3
- package/lib/Group.js +6 -10
- package/lib/Layer.d.ts +10 -9
- package/lib/Layer.js +33 -37
- package/lib/Node.d.ts +16 -13
- package/lib/Node.js +207 -123
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +7 -14
- package/lib/Shape.d.ts +7 -4
- package/lib/Shape.js +91 -91
- package/lib/Stage.d.ts +8 -7
- package/lib/Stage.js +66 -56
- package/lib/Tween.d.ts +3 -2
- package/lib/Tween.js +29 -31
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +98 -38
- package/lib/Validators.js +44 -57
- package/lib/_CoreInternals.d.ts +49 -23
- package/lib/_CoreInternals.js +33 -36
- package/lib/_FullInternals.d.ts +126 -62
- package/lib/_FullInternals.js +77 -78
- package/lib/canvas-backend.d.ts +2 -0
- package/lib/canvas-backend.js +27 -0
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +5 -9
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +5 -9
- package/lib/filters/Brightness.d.ts +2 -0
- package/lib/filters/Brightness.js +8 -0
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +5 -9
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +95 -101
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +5 -9
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +1 -5
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +7 -11
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +7 -11
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +1 -5
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +9 -13
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +16 -10
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +5 -9
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +7 -11
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +5 -9
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +7 -11
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +8 -12
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +1 -5
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +13 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +5 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -4
- package/lib/shapes/Arc.d.ts +4 -3
- package/lib/shapes/Arc.js +13 -17
- package/lib/shapes/Arrow.d.ts +4 -3
- package/lib/shapes/Arrow.js +13 -17
- package/lib/shapes/Circle.d.ts +4 -3
- package/lib/shapes/Circle.js +7 -11
- package/lib/shapes/Ellipse.d.ts +4 -3
- package/lib/shapes/Ellipse.js +9 -13
- package/lib/shapes/Image.d.ts +4 -3
- package/lib/shapes/Image.js +17 -21
- package/lib/shapes/Label.d.ts +7 -6
- package/lib/shapes/Label.js +13 -18
- package/lib/shapes/Line.d.ts +4 -3
- package/lib/shapes/Line.js +10 -14
- package/lib/shapes/Path.d.ts +3 -2
- package/lib/shapes/Path.js +83 -23
- package/lib/shapes/Rect.d.ts +4 -3
- package/lib/shapes/Rect.js +9 -13
- package/lib/shapes/RegularPolygon.d.ts +6 -3
- package/lib/shapes/RegularPolygon.js +19 -16
- package/lib/shapes/Ring.d.ts +4 -3
- package/lib/shapes/Ring.js +8 -12
- package/lib/shapes/Sprite.d.ts +5 -4
- package/lib/shapes/Sprite.js +15 -19
- package/lib/shapes/Star.d.ts +4 -3
- package/lib/shapes/Star.js +9 -13
- package/lib/shapes/Text.d.ts +16 -3
- package/lib/shapes/Text.js +73 -53
- package/lib/shapes/TextPath.d.ts +5 -4
- package/lib/shapes/TextPath.js +48 -41
- package/lib/shapes/Transformer.d.ts +8 -8
- package/lib/shapes/Transformer.js +90 -90
- package/lib/shapes/Wedge.d.ts +4 -3
- package/lib/shapes/Wedge.js +12 -16
- package/lib/skia-backend.d.ts +2 -0
- package/lib/skia-backend.js +24 -0
- package/lib/types.d.ts +22 -22
- package/lib/types.js +21 -25
- package/package.json +53 -25
- package/lib/index-node.d.ts +0 -2
- package/lib/index-node.js +0 -21
- package/lib/index-types.d.ts +0 -181
package/lib/Factory.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Factory = void 0;
|
|
4
|
-
const Util_1 = require("./Util");
|
|
5
|
-
const Validators_1 = require("./Validators");
|
|
1
|
+
import { Util } from "./Util.js";
|
|
2
|
+
import { getComponentValidator } from "./Validators.js";
|
|
6
3
|
const GET = 'get';
|
|
7
4
|
const SET = 'set';
|
|
8
|
-
|
|
5
|
+
export const Factory = {
|
|
9
6
|
addGetterSetter(constructor, attr, def, validator, after) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
Factory.addGetter(constructor, attr, def);
|
|
8
|
+
Factory.addSetter(constructor, attr, validator, after);
|
|
9
|
+
Factory.addOverloadedGetterSetter(constructor, attr);
|
|
13
10
|
},
|
|
14
11
|
addGetter(constructor, attr, def) {
|
|
15
|
-
const method = GET +
|
|
12
|
+
const method = GET + Util._capitalize(attr);
|
|
16
13
|
constructor.prototype[method] =
|
|
17
14
|
constructor.prototype[method] ||
|
|
18
15
|
function () {
|
|
@@ -21,13 +18,13 @@ exports.Factory = {
|
|
|
21
18
|
};
|
|
22
19
|
},
|
|
23
20
|
addSetter(constructor, attr, validator, after) {
|
|
24
|
-
const method = SET +
|
|
21
|
+
const method = SET + Util._capitalize(attr);
|
|
25
22
|
if (!constructor.prototype[method]) {
|
|
26
|
-
|
|
23
|
+
Factory.overWriteSetter(constructor, attr, validator, after);
|
|
27
24
|
}
|
|
28
25
|
},
|
|
29
26
|
overWriteSetter(constructor, attr, validator, after) {
|
|
30
|
-
const method = SET +
|
|
27
|
+
const method = SET + Util._capitalize(attr);
|
|
31
28
|
constructor.prototype[method] = function (val) {
|
|
32
29
|
if (validator && val !== undefined && val !== null) {
|
|
33
30
|
val = validator.call(this, val, attr);
|
|
@@ -40,7 +37,7 @@ exports.Factory = {
|
|
|
40
37
|
};
|
|
41
38
|
},
|
|
42
39
|
addComponentsGetterSetter(constructor, attr, components, validator, after) {
|
|
43
|
-
const len = components.length, capitalize =
|
|
40
|
+
const len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr);
|
|
44
41
|
constructor.prototype[getter] = function () {
|
|
45
42
|
const ret = {};
|
|
46
43
|
for (let n = 0; n < len; n++) {
|
|
@@ -49,7 +46,7 @@ exports.Factory = {
|
|
|
49
46
|
}
|
|
50
47
|
return ret;
|
|
51
48
|
};
|
|
52
|
-
const basicValidator =
|
|
49
|
+
const basicValidator = getComponentValidator(components);
|
|
53
50
|
constructor.prototype[setter] = function (val) {
|
|
54
51
|
const oldVal = this.attrs[attr];
|
|
55
52
|
if (validator) {
|
|
@@ -75,10 +72,10 @@ exports.Factory = {
|
|
|
75
72
|
}
|
|
76
73
|
return this;
|
|
77
74
|
};
|
|
78
|
-
|
|
75
|
+
Factory.addOverloadedGetterSetter(constructor, attr);
|
|
79
76
|
},
|
|
80
77
|
addOverloadedGetterSetter(constructor, attr) {
|
|
81
|
-
const capitalizedAttr =
|
|
78
|
+
const capitalizedAttr = Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
|
|
82
79
|
constructor.prototype[attr] = function () {
|
|
83
80
|
if (arguments.length) {
|
|
84
81
|
this[setter](arguments[0]);
|
|
@@ -88,28 +85,28 @@ exports.Factory = {
|
|
|
88
85
|
};
|
|
89
86
|
},
|
|
90
87
|
addDeprecatedGetterSetter(constructor, attr, def, validator) {
|
|
91
|
-
|
|
92
|
-
const method = GET +
|
|
88
|
+
Util.error('Adding deprecated ' + attr);
|
|
89
|
+
const method = GET + Util._capitalize(attr);
|
|
93
90
|
const message = attr +
|
|
94
91
|
' property is deprecated and will be removed soon. Look at Konva change log for more information.';
|
|
95
92
|
constructor.prototype[method] = function () {
|
|
96
|
-
|
|
93
|
+
Util.error(message);
|
|
97
94
|
const val = this.attrs[attr];
|
|
98
95
|
return val === undefined ? def : val;
|
|
99
96
|
};
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
Factory.addSetter(constructor, attr, validator, function () {
|
|
98
|
+
Util.error(message);
|
|
102
99
|
});
|
|
103
|
-
|
|
100
|
+
Factory.addOverloadedGetterSetter(constructor, attr);
|
|
104
101
|
},
|
|
105
102
|
backCompat(constructor, methods) {
|
|
106
|
-
|
|
103
|
+
Util.each(methods, function (oldMethodName, newMethodName) {
|
|
107
104
|
const method = constructor.prototype[newMethodName];
|
|
108
|
-
const oldGetter = GET +
|
|
109
|
-
const oldSetter = SET +
|
|
105
|
+
const oldGetter = GET + Util._capitalize(oldMethodName);
|
|
106
|
+
const oldSetter = SET + Util._capitalize(oldMethodName);
|
|
110
107
|
function deprecated() {
|
|
111
108
|
method.apply(this, arguments);
|
|
112
|
-
|
|
109
|
+
Util.error('"' +
|
|
113
110
|
oldMethodName +
|
|
114
111
|
'" method is deprecated and will be removed soon. Use ""' +
|
|
115
112
|
newMethodName +
|
package/lib/FastLayer.d.ts
CHANGED
package/lib/FastLayer.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Layer_1 = require("./Layer");
|
|
6
|
-
const Global_1 = require("./Global");
|
|
7
|
-
class FastLayer extends Layer_1.Layer {
|
|
1
|
+
import { Util } from "./Util.js";
|
|
2
|
+
import { Layer } from "./Layer.js";
|
|
3
|
+
import { _registerNode } from "./Global.js";
|
|
4
|
+
export class FastLayer extends Layer {
|
|
8
5
|
constructor(attrs) {
|
|
9
6
|
super(attrs);
|
|
10
7
|
this.listening(false);
|
|
11
|
-
|
|
8
|
+
Util.warn('Konva.Fast layer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.');
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.FastLayer = FastLayer;
|
|
15
11
|
FastLayer.prototype.nodeType = 'FastLayer';
|
|
16
|
-
|
|
12
|
+
_registerNode(FastLayer);
|
package/lib/Global.d.ts
CHANGED
|
@@ -20,14 +20,15 @@ export declare const Konva: {
|
|
|
20
20
|
_mouseDblClickPointerId: null;
|
|
21
21
|
_touchDblClickPointerId: null;
|
|
22
22
|
_pointerDblClickPointerId: null;
|
|
23
|
-
|
|
23
|
+
_renderBackend: string;
|
|
24
|
+
legacyTextRendering: boolean;
|
|
24
25
|
pixelRatio: number;
|
|
25
26
|
dragDistance: number;
|
|
26
27
|
angleDeg: boolean;
|
|
27
28
|
showWarnings: boolean;
|
|
28
29
|
dragButtons: number[];
|
|
29
|
-
isDragging():
|
|
30
|
-
isTransforming():
|
|
30
|
+
isDragging(): boolean;
|
|
31
|
+
isTransforming(): boolean;
|
|
31
32
|
isDragReady(): boolean;
|
|
32
33
|
releaseCanvasOnDestroy: boolean;
|
|
33
34
|
document: any;
|
package/lib/Global.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._registerNode = exports.Konva = exports.glob = void 0;
|
|
4
1
|
const PI_OVER_180 = Math.PI / 180;
|
|
5
2
|
function detectBrowser() {
|
|
6
3
|
return (typeof window !== 'undefined' &&
|
|
7
4
|
({}.toString.call(window) === '[object Window]' ||
|
|
8
5
|
{}.toString.call(window) === '[object global]'));
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export const glob = typeof global !== 'undefined'
|
|
11
8
|
? global
|
|
12
9
|
: typeof window !== 'undefined'
|
|
13
10
|
? window
|
|
14
11
|
: typeof WorkerGlobalScope !== 'undefined'
|
|
15
12
|
? self
|
|
16
13
|
: {};
|
|
17
|
-
|
|
18
|
-
_global:
|
|
19
|
-
version: '
|
|
14
|
+
export const Konva = {
|
|
15
|
+
_global: glob,
|
|
16
|
+
version: '10.0.0-0',
|
|
20
17
|
isBrowser: detectBrowser(),
|
|
21
18
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
22
19
|
dblClickWindow: 400,
|
|
23
20
|
getAngle(angle) {
|
|
24
|
-
return
|
|
21
|
+
return Konva.angleDeg ? angle * PI_OVER_180 : angle;
|
|
25
22
|
},
|
|
26
23
|
enableTrace: false,
|
|
27
24
|
pointerEventsEnabled: true,
|
|
@@ -37,30 +34,33 @@ exports.Konva = {
|
|
|
37
34
|
_mouseDblClickPointerId: null,
|
|
38
35
|
_touchDblClickPointerId: null,
|
|
39
36
|
_pointerDblClickPointerId: null,
|
|
40
|
-
|
|
37
|
+
_renderBackend: 'web',
|
|
38
|
+
legacyTextRendering: false,
|
|
41
39
|
pixelRatio: (typeof window !== 'undefined' && window.devicePixelRatio) || 1,
|
|
42
40
|
dragDistance: 3,
|
|
43
41
|
angleDeg: true,
|
|
44
42
|
showWarnings: true,
|
|
45
43
|
dragButtons: [0, 1],
|
|
46
44
|
isDragging() {
|
|
47
|
-
return
|
|
45
|
+
return Konva['DD'].isDragging;
|
|
48
46
|
},
|
|
49
47
|
isTransforming() {
|
|
50
|
-
var _a;
|
|
51
|
-
return (_a =
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return (_b = (_a = Konva['Transformer']) === null || _a === void 0 ? void 0 : _a.isTransforming()) !== null && _b !== void 0 ? _b : false;
|
|
52
50
|
},
|
|
53
51
|
isDragReady() {
|
|
54
|
-
return !!
|
|
52
|
+
return !!Konva['DD'].node;
|
|
55
53
|
},
|
|
56
54
|
releaseCanvasOnDestroy: true,
|
|
57
|
-
document:
|
|
55
|
+
document: glob.document,
|
|
58
56
|
_injectGlobal(Konva) {
|
|
59
|
-
|
|
57
|
+
if (typeof glob.Konva !== 'undefined') {
|
|
58
|
+
console.error('Severa Konva instances detected. It is not recommended to use multiple Konva instances in the same environment.');
|
|
59
|
+
}
|
|
60
|
+
glob.Konva = Konva;
|
|
60
61
|
},
|
|
61
62
|
};
|
|
62
|
-
const _registerNode = (NodeClass) => {
|
|
63
|
-
|
|
63
|
+
export const _registerNode = (NodeClass) => {
|
|
64
|
+
Konva[NodeClass.prototype.getClassName()] = NodeClass;
|
|
64
65
|
};
|
|
65
|
-
|
|
66
|
-
exports.Konva._injectGlobal(exports.Konva);
|
|
66
|
+
Konva._injectGlobal(Konva);
|
package/lib/Group.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ContainerConfig } from './Container.ts';
|
|
2
|
+
import { Container } from './Container.ts';
|
|
3
|
+
import type { Node } from './Node.ts';
|
|
4
|
+
import type { Shape } from './Shape.ts';
|
|
4
5
|
export interface GroupConfig extends ContainerConfig {
|
|
5
6
|
}
|
|
6
7
|
export declare class Group extends Container<Group | Shape> {
|
package/lib/Group.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Container_1 = require("./Container");
|
|
6
|
-
const Global_1 = require("./Global");
|
|
7
|
-
class Group extends Container_1.Container {
|
|
1
|
+
import { Util } from "./Util.js";
|
|
2
|
+
import { Container } from "./Container.js";
|
|
3
|
+
import { _registerNode } from "./Global.js";
|
|
4
|
+
export class Group extends Container {
|
|
8
5
|
_validateAdd(child) {
|
|
9
6
|
const type = child.getType();
|
|
10
7
|
if (type !== 'Group' && type !== 'Shape') {
|
|
11
|
-
|
|
8
|
+
Util.throw('You may only add groups and shapes to groups.');
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
11
|
}
|
|
15
|
-
exports.Group = Group;
|
|
16
12
|
Group.prototype.nodeType = 'Group';
|
|
17
|
-
|
|
13
|
+
_registerNode(Group);
|
package/lib/Layer.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import type { ContainerConfig } from './Container.ts';
|
|
2
|
+
import { Container } from './Container.ts';
|
|
3
|
+
import { Node } from './Node.ts';
|
|
4
|
+
import { SceneCanvas, HitCanvas } from './Canvas.ts';
|
|
5
|
+
import type { Stage } from './Stage.ts';
|
|
6
|
+
import type { GetSet, Vector2d } from './types.ts';
|
|
7
|
+
import type { Group } from './Group.ts';
|
|
8
|
+
import type { Shape } from './Shape.ts';
|
|
8
9
|
export interface LayerConfig extends ContainerConfig {
|
|
9
10
|
clearBeforeDraw?: boolean;
|
|
10
11
|
hitGraphEnabled?: boolean;
|
|
@@ -19,7 +20,7 @@ export declare class Layer extends Container<Group | Shape> {
|
|
|
19
20
|
getCanvas(): SceneCanvas;
|
|
20
21
|
getNativeCanvasElement(): HTMLCanvasElement;
|
|
21
22
|
getHitCanvas(): HitCanvas;
|
|
22
|
-
getContext(): import("./Context.
|
|
23
|
+
getContext(): import("./Context.ts").Context;
|
|
23
24
|
clear(bounds?: any): this;
|
|
24
25
|
setZIndex(index: number): this;
|
|
25
26
|
moveToTop(): boolean;
|
|
@@ -42,7 +43,7 @@ export declare class Layer extends Container<Group | Shape> {
|
|
|
42
43
|
getHeight(): number | undefined;
|
|
43
44
|
setHeight(): void;
|
|
44
45
|
batchDraw(): this;
|
|
45
|
-
getIntersection(pos: Vector2d): Shape<import("./Shape.
|
|
46
|
+
getIntersection(pos: Vector2d): Shape<import("./Shape.ts").ShapeConfig> | null;
|
|
46
47
|
_getIntersection(pos: Vector2d): {
|
|
47
48
|
shape?: Shape;
|
|
48
49
|
antialiased?: boolean;
|
package/lib/Layer.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const Validators_1 = require("./Validators");
|
|
10
|
-
const Shape_1 = require("./Shape");
|
|
11
|
-
const Global_1 = require("./Global");
|
|
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 { getBooleanValidator } from "./Validators.js";
|
|
7
|
+
import { shapes } from "./Shape.js";
|
|
8
|
+
import { _registerNode } from "./Global.js";
|
|
12
9
|
const HASH = '#', BEFORE_DRAW = 'beforeDraw', DRAW = 'draw', INTERSECTION_OFFSETS = [
|
|
13
10
|
{ x: 0, y: 0 },
|
|
14
11
|
{ x: -1, y: -1 },
|
|
@@ -16,11 +13,11 @@ const HASH = '#', BEFORE_DRAW = 'beforeDraw', DRAW = 'draw', INTERSECTION_OFFSET
|
|
|
16
13
|
{ x: 1, y: 1 },
|
|
17
14
|
{ x: -1, y: 1 },
|
|
18
15
|
], INTERSECTION_OFFSETS_LEN = INTERSECTION_OFFSETS.length;
|
|
19
|
-
class Layer extends
|
|
16
|
+
export class Layer extends Container {
|
|
20
17
|
constructor(config) {
|
|
21
18
|
super(config);
|
|
22
|
-
this.canvas = new
|
|
23
|
-
this.hitCanvas = new
|
|
19
|
+
this.canvas = new SceneCanvas();
|
|
20
|
+
this.hitCanvas = new HitCanvas({
|
|
24
21
|
pixelRatio: 1,
|
|
25
22
|
});
|
|
26
23
|
this._waitingForDraw = false;
|
|
@@ -65,7 +62,7 @@ class Layer extends Container_1.Container {
|
|
|
65
62
|
return this;
|
|
66
63
|
}
|
|
67
64
|
moveToTop() {
|
|
68
|
-
|
|
65
|
+
Node.prototype.moveToTop.call(this);
|
|
69
66
|
const stage = this.getStage();
|
|
70
67
|
if (stage && stage.content) {
|
|
71
68
|
stage.content.removeChild(this.getNativeCanvasElement());
|
|
@@ -74,7 +71,7 @@ class Layer extends Container_1.Container {
|
|
|
74
71
|
return true;
|
|
75
72
|
}
|
|
76
73
|
moveUp() {
|
|
77
|
-
const moved =
|
|
74
|
+
const moved = Node.prototype.moveUp.call(this);
|
|
78
75
|
if (!moved) {
|
|
79
76
|
return false;
|
|
80
77
|
}
|
|
@@ -92,7 +89,7 @@ class Layer extends Container_1.Container {
|
|
|
92
89
|
return true;
|
|
93
90
|
}
|
|
94
91
|
moveDown() {
|
|
95
|
-
if (
|
|
92
|
+
if (Node.prototype.moveDown.call(this)) {
|
|
96
93
|
const stage = this.getStage();
|
|
97
94
|
if (stage) {
|
|
98
95
|
const children = stage.children;
|
|
@@ -106,7 +103,7 @@ class Layer extends Container_1.Container {
|
|
|
106
103
|
return false;
|
|
107
104
|
}
|
|
108
105
|
moveToBottom() {
|
|
109
|
-
if (
|
|
106
|
+
if (Node.prototype.moveToBottom.call(this)) {
|
|
110
107
|
const stage = this.getStage();
|
|
111
108
|
if (stage) {
|
|
112
109
|
const children = stage.children;
|
|
@@ -124,8 +121,8 @@ class Layer extends Container_1.Container {
|
|
|
124
121
|
}
|
|
125
122
|
remove() {
|
|
126
123
|
const _canvas = this.getNativeCanvasElement();
|
|
127
|
-
|
|
128
|
-
if (_canvas && _canvas.parentNode &&
|
|
124
|
+
Node.prototype.remove.call(this);
|
|
125
|
+
if (_canvas && _canvas.parentNode && Util._isInDocument(_canvas)) {
|
|
129
126
|
_canvas.parentNode.removeChild(_canvas);
|
|
130
127
|
}
|
|
131
128
|
return this;
|
|
@@ -142,7 +139,7 @@ class Layer extends Container_1.Container {
|
|
|
142
139
|
_validateAdd(child) {
|
|
143
140
|
const type = child.getType();
|
|
144
141
|
if (type !== 'Group' && type !== 'Shape') {
|
|
145
|
-
|
|
142
|
+
Util.throw('You may only add groups and shapes to a layer.');
|
|
146
143
|
}
|
|
147
144
|
}
|
|
148
145
|
_toKonvaCanvas(config) {
|
|
@@ -151,7 +148,7 @@ class Layer extends Container_1.Container {
|
|
|
151
148
|
config.height = config.height || this.getHeight();
|
|
152
149
|
config.x = config.x !== undefined ? config.x : this.x();
|
|
153
150
|
config.y = config.y !== undefined ? config.y : this.y();
|
|
154
|
-
return
|
|
151
|
+
return Node.prototype._toKonvaCanvas.call(this, config);
|
|
155
152
|
}
|
|
156
153
|
_checkVisibility() {
|
|
157
154
|
const visible = this.visible();
|
|
@@ -172,7 +169,7 @@ class Layer extends Container_1.Container {
|
|
|
172
169
|
}
|
|
173
170
|
}
|
|
174
171
|
setWidth() {
|
|
175
|
-
|
|
172
|
+
Util.warn('Can not change width of layer. Use "stage.width(value)" function instead.');
|
|
176
173
|
}
|
|
177
174
|
getHeight() {
|
|
178
175
|
if (this.parent) {
|
|
@@ -180,12 +177,12 @@ class Layer extends Container_1.Container {
|
|
|
180
177
|
}
|
|
181
178
|
}
|
|
182
179
|
setHeight() {
|
|
183
|
-
|
|
180
|
+
Util.warn('Can not change height of layer. Use "stage.height(value)" function instead.');
|
|
184
181
|
}
|
|
185
182
|
batchDraw() {
|
|
186
183
|
if (!this._waitingForDraw) {
|
|
187
184
|
this._waitingForDraw = true;
|
|
188
|
-
|
|
185
|
+
Util.requestAnimFrame(() => {
|
|
189
186
|
this.draw();
|
|
190
187
|
this._waitingForDraw = false;
|
|
191
188
|
});
|
|
@@ -227,8 +224,8 @@ class Layer extends Container_1.Container {
|
|
|
227
224
|
const p = this.hitCanvas.context.getImageData(Math.round(pos.x * ratio), Math.round(pos.y * ratio), 1, 1).data;
|
|
228
225
|
const p3 = p[3];
|
|
229
226
|
if (p3 === 255) {
|
|
230
|
-
const colorKey =
|
|
231
|
-
const shape =
|
|
227
|
+
const colorKey = Util._rgbToHex(p[0], p[1], p[2]);
|
|
228
|
+
const shape = shapes[HASH + colorKey];
|
|
232
229
|
if (shape) {
|
|
233
230
|
return {
|
|
234
231
|
shape: shape,
|
|
@@ -253,7 +250,7 @@ class Layer extends Container_1.Container {
|
|
|
253
250
|
if (this.clearBeforeDraw()) {
|
|
254
251
|
canvas.getContext().clear();
|
|
255
252
|
}
|
|
256
|
-
|
|
253
|
+
Container.prototype.drawScene.call(this, canvas, top, bufferCanvas);
|
|
257
254
|
this._fire(DRAW, {
|
|
258
255
|
node: this,
|
|
259
256
|
});
|
|
@@ -264,7 +261,7 @@ class Layer extends Container_1.Container {
|
|
|
264
261
|
if (layer && layer.clearBeforeDraw()) {
|
|
265
262
|
layer.getHitCanvas().getContext().clear();
|
|
266
263
|
}
|
|
267
|
-
|
|
264
|
+
Container.prototype.drawHit.call(this, canvas, top);
|
|
268
265
|
return this;
|
|
269
266
|
}
|
|
270
267
|
enableHitGraph() {
|
|
@@ -276,11 +273,11 @@ class Layer extends Container_1.Container {
|
|
|
276
273
|
return this;
|
|
277
274
|
}
|
|
278
275
|
setHitGraphEnabled(val) {
|
|
279
|
-
|
|
276
|
+
Util.warn('hitGraphEnabled method is deprecated. Please use layer.listening() instead.');
|
|
280
277
|
this.listening(val);
|
|
281
278
|
}
|
|
282
279
|
getHitGraphEnabled(val) {
|
|
283
|
-
|
|
280
|
+
Util.warn('hitGraphEnabled method is deprecated. Please use layer.listening() instead.');
|
|
284
281
|
return this.listening();
|
|
285
282
|
}
|
|
286
283
|
toggleHitCanvas() {
|
|
@@ -297,13 +294,12 @@ class Layer extends Container_1.Container {
|
|
|
297
294
|
}
|
|
298
295
|
}
|
|
299
296
|
destroy() {
|
|
300
|
-
|
|
297
|
+
Util.releaseCanvas(this.getNativeCanvasElement(), this.getHitCanvas()._canvas);
|
|
301
298
|
return super.destroy();
|
|
302
299
|
}
|
|
303
300
|
}
|
|
304
|
-
exports.Layer = Layer;
|
|
305
301
|
Layer.prototype.nodeType = 'Layer';
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
302
|
+
_registerNode(Layer);
|
|
303
|
+
Factory.addGetterSetter(Layer, 'imageSmoothingEnabled', true);
|
|
304
|
+
Factory.addGetterSetter(Layer, 'clearBeforeDraw', true);
|
|
305
|
+
Factory.addGetterSetter(Layer, 'hitGraphEnabled', true, getBooleanValidator());
|
package/lib/Node.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { Canvas
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
1
|
+
import type { Canvas } from './Canvas.ts';
|
|
2
|
+
import { SceneCanvas } from './Canvas.ts';
|
|
3
|
+
import type { Container } from './Container.ts';
|
|
4
|
+
import type { Context } from './Context.ts';
|
|
5
|
+
import type { Layer } from './Layer.ts';
|
|
6
|
+
import type { Shape } from './Shape.ts';
|
|
7
|
+
import type { Stage } from './Stage.ts';
|
|
8
|
+
import type { GetSet, IRect, Vector2d } from './types.ts';
|
|
9
|
+
import { Transform } from './Util.ts';
|
|
10
|
+
export type FilterFunction = (this: Node, imageData: ImageData) => void;
|
|
11
|
+
export type Filter = FilterFunction | string;
|
|
12
|
+
type Filters = Array<FilterFunction | string>;
|
|
10
13
|
type globalCompositeOperationType = '' | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
|
|
11
14
|
export interface NodeConfig {
|
|
12
15
|
[index: string]: any;
|
|
@@ -34,7 +37,7 @@ export interface NodeConfig {
|
|
|
34
37
|
dragBoundFunc?: (this: Node, pos: Vector2d) => Vector2d;
|
|
35
38
|
preventDefault?: boolean;
|
|
36
39
|
globalCompositeOperation?: globalCompositeOperationType;
|
|
37
|
-
filters?:
|
|
40
|
+
filters?: Filters;
|
|
38
41
|
}
|
|
39
42
|
type NodeEventMap = GlobalEventHandlersEventMap & {
|
|
40
43
|
[index: string]: any;
|
|
@@ -114,7 +117,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
114
117
|
};
|
|
115
118
|
_drawCachedSceneCanvas(context: Context): void;
|
|
116
119
|
_drawCachedHitCanvas(context: Context): void;
|
|
117
|
-
_getCachedSceneCanvas():
|
|
120
|
+
_getCachedSceneCanvas(): Canvas;
|
|
118
121
|
on<K extends keyof NodeEventMap>(evtStr: K, handler: KonvaEventListener<this, NodeEventMap[K]>): void | this;
|
|
119
122
|
off(evtStr?: string, callback?: Function): this;
|
|
120
123
|
dispatchEvent(evt: any): this;
|
|
@@ -223,7 +226,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
223
226
|
mimeType?: string;
|
|
224
227
|
quality?: number;
|
|
225
228
|
callback?: (img: HTMLImageElement) => void;
|
|
226
|
-
}): Promise<
|
|
229
|
+
}): Promise<HTMLImageElement>;
|
|
227
230
|
toBlob(config?: {
|
|
228
231
|
x?: number;
|
|
229
232
|
y?: number;
|
|
@@ -294,7 +297,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
294
297
|
embossStrength: GetSet<number, this>;
|
|
295
298
|
embossWhiteLevel: GetSet<number, this>;
|
|
296
299
|
enhance: GetSet<number, this>;
|
|
297
|
-
filters: GetSet<
|
|
300
|
+
filters: GetSet<Filters, this>;
|
|
298
301
|
position: GetSet<Vector2d, this>;
|
|
299
302
|
absolutePosition: GetSet<Vector2d, this>;
|
|
300
303
|
size: GetSet<{
|