konva 10.3.3 → 10.4.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 +1327 -1572
- package/konva.min.js +4 -4
- package/lib/Animation.d.ts +63 -3
- package/lib/Animation.js +86 -65
- package/lib/BezierFunctions.d.ts +10 -0
- package/lib/BezierFunctions.js +32 -0
- package/lib/Canvas.d.ts +53 -0
- package/lib/Canvas.js +93 -34
- package/lib/Container.d.ts +156 -9
- package/lib/Container.js +260 -25
- package/lib/Context.d.ts +247 -0
- package/lib/Context.js +312 -74
- package/lib/Core.js +1 -0
- package/lib/DragAndDrop.d.ts +1 -0
- package/lib/DragAndDrop.js +66 -17
- package/lib/Factory.d.ts +24 -1
- package/lib/Factory.js +14 -20
- package/lib/FastLayer.d.ts +14 -1
- package/lib/FastLayer.js +14 -1
- package/lib/Global.d.ts +114 -3
- package/lib/Global.js +134 -5
- package/lib/Group.d.ts +11 -0
- package/lib/Group.js +11 -0
- package/lib/Layer.d.ts +128 -3
- package/lib/Layer.js +260 -49
- package/lib/Node.d.ts +692 -30
- package/lib/Node.js +1534 -202
- package/lib/PointerEvents.d.ts +2 -1
- package/lib/PointerEvents.js +19 -1
- package/lib/Shape.d.ts +99 -14
- package/lib/Shape.js +1101 -67
- package/lib/Stage.d.ts +81 -1
- package/lib/Stage.js +166 -7
- package/lib/Tween.d.ts +159 -4
- package/lib/Tween.js +243 -24
- package/lib/Util.d.ts +147 -4
- package/lib/Util.js +332 -82
- package/lib/Validators.d.ts +0 -2
- package/lib/Validators.js +3 -25
- package/lib/_CoreInternals.d.ts +10 -6
- package/lib/_CoreInternals.js +1 -0
- package/lib/_FullInternals.d.ts +15 -6
- package/lib/_FullInternals.js +7 -0
- package/lib/canvas-backend.js +6 -0
- package/lib/filters/Blur.d.ts +18 -0
- package/lib/filters/Blur.js +97 -24
- package/lib/filters/Brighten.d.ts +21 -0
- package/lib/filters/Brighten.js +24 -0
- package/lib/filters/Brightness.d.ts +11 -0
- package/lib/filters/Brightness.js +16 -0
- package/lib/filters/Contrast.d.ts +10 -0
- package/lib/filters/Contrast.js +21 -0
- package/lib/filters/Emboss.d.ts +20 -0
- package/lib/filters/Emboss.js +68 -8
- package/lib/filters/Enhance.d.ts +14 -0
- package/lib/filters/Enhance.js +34 -0
- package/lib/filters/Grayscale.d.ts +9 -0
- package/lib/filters/Grayscale.js +12 -0
- package/lib/filters/HSL.d.ts +17 -0
- package/lib/filters/HSL.js +48 -5
- package/lib/filters/HSV.d.ts +18 -0
- package/lib/filters/HSV.js +49 -5
- package/lib/filters/Invert.d.ts +9 -0
- package/lib/filters/Invert.js +12 -0
- package/lib/filters/Kaleidoscope.d.ts +12 -0
- package/lib/filters/Kaleidoscope.js +83 -0
- package/lib/filters/Mask.d.ts +11 -0
- package/lib/filters/Mask.js +18 -0
- package/lib/filters/Noise.d.ts +19 -0
- package/lib/filters/Noise.js +19 -0
- package/lib/filters/Pixelate.d.ts +20 -0
- package/lib/filters/Pixelate.js +28 -1
- package/lib/filters/Posterize.d.ts +21 -0
- package/lib/filters/Posterize.js +22 -0
- package/lib/filters/RGB.d.ts +21 -0
- package/lib/filters/RGB.js +43 -28
- package/lib/filters/RGBA.d.ts +23 -0
- package/lib/filters/RGBA.js +28 -41
- package/lib/filters/Sepia.d.ts +9 -0
- package/lib/filters/Sepia.js +10 -0
- package/lib/filters/Solarize.d.ts +10 -0
- package/lib/filters/Solarize.js +11 -0
- package/lib/filters/Threshold.d.ts +22 -0
- package/lib/filters/Threshold.js +22 -0
- package/lib/shapes/Arc.d.ts +40 -0
- package/lib/shapes/Arc.js +89 -6
- package/lib/shapes/Arrow.d.ts +24 -1
- package/lib/shapes/Arrow.js +83 -0
- package/lib/shapes/Circle.d.ts +18 -0
- package/lib/shapes/Circle.js +36 -9
- package/lib/shapes/Ellipse.d.ts +34 -2
- package/lib/shapes/Ellipse.js +67 -9
- package/lib/shapes/Image.d.ts +49 -0
- package/lib/shapes/Image.js +151 -22
- package/lib/shapes/Label.d.ts +65 -1
- package/lib/shapes/Label.js +113 -20
- package/lib/shapes/Line.d.ts +50 -8
- package/lib/shapes/Line.js +116 -20
- package/lib/shapes/Path.d.ts +40 -6
- package/lib/shapes/Path.js +187 -128
- package/lib/shapes/Rect.d.ts +18 -0
- package/lib/shapes/Rect.js +36 -0
- package/lib/shapes/RegularPolygon.d.ts +22 -0
- package/lib/shapes/RegularPolygon.js +70 -0
- package/lib/shapes/Ring.d.ts +19 -0
- package/lib/shapes/Ring.js +51 -5
- package/lib/shapes/Sprite.d.ts +78 -0
- package/lib/shapes/Sprite.js +238 -25
- package/lib/shapes/Star.d.ts +23 -0
- package/lib/shapes/Star.js +62 -0
- package/lib/shapes/Text.d.ts +59 -1
- package/lib/shapes/Text.js +481 -97
- package/lib/shapes/TextPath.d.ts +49 -3
- package/lib/shapes/TextPath.js +278 -34
- package/lib/shapes/Transformer.d.ts +108 -11
- package/lib/shapes/Transformer.js +744 -102
- package/lib/shapes/Wedge.d.ts +22 -0
- package/lib/shapes/Wedge.js +67 -3
- package/lib/skia-backend.js +9 -0
- package/lib/types.d.ts +2 -23
- package/lib/types.js +1 -21
- package/package.json +12 -16
package/lib/DragAndDrop.js
CHANGED
|
@@ -12,6 +12,7 @@ export const DD = {
|
|
|
12
12
|
},
|
|
13
13
|
justDragged: false,
|
|
14
14
|
get node() {
|
|
15
|
+
// return first dragging node
|
|
15
16
|
let node;
|
|
16
17
|
DD._dragElements.forEach((elem) => {
|
|
17
18
|
node = elem.node;
|
|
@@ -19,11 +20,17 @@ export const DD = {
|
|
|
19
20
|
return node;
|
|
20
21
|
},
|
|
21
22
|
_dragElements: new Map(),
|
|
23
|
+
// Konva is imported into one window, but a stage may be rendered in another
|
|
24
|
+
// one: an iframe, or a window opened with `window.open`. Such a window sends
|
|
25
|
+
// its pointer events to itself, so `Konva.Stage` asks for every window it is
|
|
26
|
+
// rendered in. The handlers get the window they listen to, as only that
|
|
27
|
+
// window has pointer positions the stages of that window can use
|
|
22
28
|
_listenToWindow(win) {
|
|
23
29
|
const endDragBefore = (evt) => DD._endDragBefore(evt, win);
|
|
24
30
|
const drag = (evt) => DD._drag(evt, win);
|
|
25
31
|
win.addEventListener('mouseup', endDragBefore, true);
|
|
26
32
|
win.addEventListener('touchend', endDragBefore, true);
|
|
33
|
+
// add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843
|
|
27
34
|
win.addEventListener('touchcancel', endDragBefore, true);
|
|
28
35
|
win.addEventListener('mousemove', drag);
|
|
29
36
|
win.addEventListener('touchmove', drag);
|
|
@@ -31,19 +38,31 @@ export const DD = {
|
|
|
31
38
|
win.addEventListener('touchend', DD._endDragAfter, false);
|
|
32
39
|
win.addEventListener('touchcancel', DD._endDragAfter, false);
|
|
33
40
|
},
|
|
41
|
+
// methods
|
|
34
42
|
_drag(evt, win) {
|
|
35
43
|
const nodesToFireEvents = [];
|
|
44
|
+
// reading the positions forces a layout, so do it once per stage
|
|
45
|
+
const positioned = new Set();
|
|
36
46
|
DD._dragElements.forEach((elem, key) => {
|
|
37
47
|
const { node } = elem;
|
|
48
|
+
// we need to find pointer relative to that node
|
|
38
49
|
const stage = node.getStage();
|
|
50
|
+
// a pointer position of another window is relative to another viewport,
|
|
51
|
+
// it would drag the node to a random place
|
|
39
52
|
if (win && stage._getOwnerWindow() !== win) {
|
|
40
53
|
return;
|
|
41
54
|
}
|
|
42
|
-
|
|
55
|
+
if (!positioned.has(stage)) {
|
|
56
|
+
stage.setPointersPositions(evt);
|
|
57
|
+
positioned.add(stage);
|
|
58
|
+
}
|
|
59
|
+
// it is possible that user call startDrag without any event
|
|
60
|
+
// it that case we need to detect first movable pointer and attach it into the node
|
|
43
61
|
if (elem.pointerId === undefined) {
|
|
44
62
|
elem.pointerId = Util._getFirstPointerId(evt);
|
|
45
63
|
}
|
|
46
64
|
const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
|
|
65
|
+
// not related pointer
|
|
47
66
|
if (!pos) {
|
|
48
67
|
return;
|
|
49
68
|
}
|
|
@@ -54,6 +73,7 @@ export const DD = {
|
|
|
54
73
|
return;
|
|
55
74
|
}
|
|
56
75
|
node.startDrag({ evt });
|
|
76
|
+
// a user can stop dragging inside `dragstart`
|
|
57
77
|
if (!node.isDragging()) {
|
|
58
78
|
return;
|
|
59
79
|
}
|
|
@@ -61,7 +81,9 @@ export const DD = {
|
|
|
61
81
|
node._setDragPosition(evt, elem);
|
|
62
82
|
nodesToFireEvents.push(node);
|
|
63
83
|
});
|
|
84
|
+
// call dragmove only after ALL positions are changed
|
|
64
85
|
nodesToFireEvents.forEach((node) => {
|
|
86
|
+
// node may have been destroyed during a previous dragmove handler
|
|
65
87
|
if (!node.getStage()) {
|
|
66
88
|
return;
|
|
67
89
|
}
|
|
@@ -72,44 +94,71 @@ export const DD = {
|
|
|
72
94
|
}, true);
|
|
73
95
|
});
|
|
74
96
|
},
|
|
97
|
+
// dragBefore and dragAfter allows us to set correct order of events
|
|
98
|
+
// setup all in dragbefore, and stop dragging only after pointerup triggered.
|
|
75
99
|
_endDragBefore(evt, win) {
|
|
76
100
|
const drawNodes = [];
|
|
77
|
-
|
|
101
|
+
const positioned = new Set();
|
|
102
|
+
DD._dragElements.forEach((elem, key) => {
|
|
78
103
|
const { node } = elem;
|
|
104
|
+
// we need to find pointer relative to that node
|
|
79
105
|
const stage = node.getStage();
|
|
80
|
-
|
|
106
|
+
// a pointer released in another window ends the drag too - the pointer
|
|
107
|
+
// is up everywhere - but its position is not used for this stage
|
|
108
|
+
if (evt &&
|
|
109
|
+
!positioned.has(stage) &&
|
|
110
|
+
(!win || stage._getOwnerWindow() === win)) {
|
|
81
111
|
stage.setPointersPositions(evt);
|
|
112
|
+
positioned.add(stage);
|
|
82
113
|
}
|
|
83
|
-
|
|
84
|
-
|
|
114
|
+
// a drag started without an event (node.startDrag()) that has not
|
|
115
|
+
// moved yet has no pointer: any release ends it
|
|
116
|
+
const released = elem.pointerId === undefined ||
|
|
117
|
+
stage._changedPointerPositions.some((pos) => pos.id === elem.pointerId);
|
|
118
|
+
// that pointer is not related: a "ready" element of another pointer
|
|
119
|
+
// waits for its own release
|
|
120
|
+
if (!released) {
|
|
85
121
|
return;
|
|
86
122
|
}
|
|
87
|
-
if (elem.dragStatus === '
|
|
123
|
+
if (elem.dragStatus === 'ready') {
|
|
124
|
+
DD._dragElements.delete(key);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// if a node is stopped manually we still need to reset events:
|
|
88
128
|
DD.justDragged = true;
|
|
89
129
|
Konva._mouseListenClick = false;
|
|
90
130
|
Konva._touchListenClick = false;
|
|
131
|
+
// for real pointer input this reset comes too late — "pointerup" fired
|
|
132
|
+
// before this handler — so Stage._pointerup also checks the live drag
|
|
133
|
+
// state for the pointer family (issue #1756)
|
|
91
134
|
Konva._pointerListenClick = false;
|
|
92
135
|
elem.dragStatus = 'stopped';
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
136
|
+
// a node that has not moved needs no redraw
|
|
137
|
+
const drawNode = elem.node.getLayer() ||
|
|
138
|
+
(elem.node instanceof Konva['Stage'] && elem.node);
|
|
139
|
+
if (drawNode && drawNodes.indexOf(drawNode) === -1) {
|
|
140
|
+
drawNodes.push(drawNode);
|
|
141
|
+
}
|
|
98
142
|
}
|
|
99
143
|
});
|
|
144
|
+
// draw in a sync way
|
|
145
|
+
// because mousemove event may trigger BEFORE batch draw is called
|
|
146
|
+
// but as we have not hit canvas updated yet, it will trigger incorrect mouseover/mouseout events
|
|
100
147
|
drawNodes.forEach((drawNode) => {
|
|
101
148
|
drawNode.draw();
|
|
102
149
|
});
|
|
103
150
|
},
|
|
104
151
|
_endDragAfter(evt) {
|
|
105
152
|
DD._dragElements.forEach((elem, key) => {
|
|
106
|
-
if (elem.dragStatus
|
|
107
|
-
|
|
108
|
-
type: 'dragend',
|
|
109
|
-
target: elem.node,
|
|
110
|
-
evt: evt,
|
|
111
|
-
}, true);
|
|
153
|
+
if (elem.dragStatus !== 'stopped') {
|
|
154
|
+
return;
|
|
112
155
|
}
|
|
156
|
+
elem.node.fire('dragend', {
|
|
157
|
+
type: 'dragend',
|
|
158
|
+
target: elem.node,
|
|
159
|
+
evt: evt,
|
|
160
|
+
}, true);
|
|
161
|
+
// a dragend handler may have started a new drag of the node
|
|
113
162
|
if (elem.dragStatus !== 'dragging') {
|
|
114
163
|
DD._dragElements.delete(key);
|
|
115
164
|
}
|
package/lib/Factory.d.ts
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
import type { Node } from './Node.ts';
|
|
2
2
|
import type { GetSet } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Enforces that a type is a string.
|
|
5
|
+
*/
|
|
3
6
|
type EnforceString<T> = T extends string ? T : never;
|
|
7
|
+
/**
|
|
8
|
+
* Represents a class.
|
|
9
|
+
*/
|
|
4
10
|
type Constructor = abstract new (...args: any) => any;
|
|
11
|
+
/**
|
|
12
|
+
* An attribute of an instance of the provided class. Attributes names be strings.
|
|
13
|
+
*/
|
|
5
14
|
type Attr<T extends Constructor> = EnforceString<keyof InstanceType<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* A function that is called after a setter is called.
|
|
17
|
+
*/
|
|
6
18
|
type AfterFunc<T extends Constructor> = (this: InstanceType<T>) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts the type of a GetSet.
|
|
21
|
+
*/
|
|
7
22
|
type ExtractGetSet<T> = T extends GetSet<infer U, any> ? U : never;
|
|
23
|
+
/**
|
|
24
|
+
* Extracts the type of a GetSet class attribute.
|
|
25
|
+
*/
|
|
8
26
|
type Value<T extends Constructor, U extends Attr<T>> = ExtractGetSet<InstanceType<T>[U]>;
|
|
27
|
+
/**
|
|
28
|
+
* A function that validates a value.
|
|
29
|
+
*/
|
|
9
30
|
type ValidatorFunc<T> = (val: T, attr: string) => T;
|
|
31
|
+
/**
|
|
32
|
+
* Extracts the "components" (keys) of a GetSet value. The value must be an object.
|
|
33
|
+
*/
|
|
10
34
|
type ExtractComponents<T extends Constructor, U extends Attr<T>> = Value<T, U> extends Record<string, any> ? EnforceString<keyof Value<T, U>>[] : never;
|
|
11
35
|
export declare const Factory: {
|
|
12
36
|
addGetterSetter<T extends Constructor, U extends Attr<T>>(constructor: T, attr: U, def?: Value<T, U>, validator?: ValidatorFunc<Value<T, U>>, after?: AfterFunc<T>): void;
|
|
@@ -15,7 +39,6 @@ export declare const Factory: {
|
|
|
15
39
|
overWriteSetter<T extends Constructor, U extends Attr<T>>(constructor: T, attr: U, validator?: ValidatorFunc<Value<T, U>>, after?: AfterFunc<T>): void;
|
|
16
40
|
addComponentsGetterSetter<T extends Constructor, U extends Attr<T>>(constructor: T, attr: U, components: ExtractComponents<T, U>, validator?: ValidatorFunc<Value<T, U>>, after?: AfterFunc<T>): void;
|
|
17
41
|
addOverloadedGetterSetter<T extends Constructor, U extends Attr<T>>(constructor: T, attr: U): void;
|
|
18
|
-
addDeprecatedGetterSetter<T extends Constructor, U extends Attr<T>>(constructor: T, attr: U, def: Value<T, U>, validator: ValidatorFunc<Value<T, U>>): void;
|
|
19
42
|
backCompat<T extends Constructor>(constructor: T, methods: Record<string, string>): void;
|
|
20
43
|
afterSetFilter(this: Node): void;
|
|
21
44
|
};
|
package/lib/Factory.js
CHANGED
|
@@ -37,16 +37,20 @@ export const Factory = {
|
|
|
37
37
|
};
|
|
38
38
|
},
|
|
39
39
|
addComponentsGetterSetter(constructor, attr, components, validator, after) {
|
|
40
|
-
const len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr)
|
|
40
|
+
const len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr), keys = components.map((c) => attr + capitalize(c)),
|
|
41
|
+
// built-in components have their own getters, e.g. getOffsetX
|
|
42
|
+
getters = keys.map((key) => GET + capitalize(key));
|
|
43
|
+
// getter
|
|
41
44
|
constructor.prototype[getter] = function () {
|
|
42
45
|
const ret = {};
|
|
43
46
|
for (let n = 0; n < len; n++) {
|
|
44
|
-
const
|
|
45
|
-
ret[
|
|
47
|
+
const get = this[getters[n]];
|
|
48
|
+
ret[components[n]] = get ? get.call(this) : this.attrs[keys[n]];
|
|
46
49
|
}
|
|
47
50
|
return ret;
|
|
48
51
|
};
|
|
49
52
|
const basicValidator = getComponentValidator(components);
|
|
53
|
+
// setter
|
|
50
54
|
constructor.prototype[setter] = function (val) {
|
|
51
55
|
const oldVal = this.attrs[attr];
|
|
52
56
|
if (validator) {
|
|
@@ -76,28 +80,18 @@ export const Factory = {
|
|
|
76
80
|
},
|
|
77
81
|
addOverloadedGetterSetter(constructor, attr) {
|
|
78
82
|
const capitalizedAttr = Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
|
|
79
|
-
|
|
83
|
+
const accessor = function () {
|
|
84
|
+
// setting
|
|
80
85
|
if (arguments.length) {
|
|
81
86
|
this[setter](arguments[0]);
|
|
82
87
|
return this;
|
|
83
88
|
}
|
|
89
|
+
// getting
|
|
84
90
|
return this[getter]();
|
|
85
91
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const method = GET + Util._capitalize(attr);
|
|
90
|
-
const message = attr +
|
|
91
|
-
' property is deprecated and will be removed soon. Look at Konva change log for more information.';
|
|
92
|
-
constructor.prototype[method] = function () {
|
|
93
|
-
Util.error(message);
|
|
94
|
-
const val = this.attrs[attr];
|
|
95
|
-
return val === undefined ? def : val;
|
|
96
|
-
};
|
|
97
|
-
Factory.addSetter(constructor, attr, validator, function () {
|
|
98
|
-
Util.error(message);
|
|
99
|
-
});
|
|
100
|
-
Factory.addOverloadedGetterSetter(constructor, attr);
|
|
92
|
+
// marks the accessor for toObject()
|
|
93
|
+
accessor._isAttrAccessor = true;
|
|
94
|
+
constructor.prototype[attr] = accessor;
|
|
101
95
|
},
|
|
102
96
|
backCompat(constructor, methods) {
|
|
103
97
|
Util.each(methods, function (oldMethodName, newMethodName) {
|
|
@@ -105,12 +99,12 @@ export const Factory = {
|
|
|
105
99
|
const oldGetter = GET + Util._capitalize(oldMethodName);
|
|
106
100
|
const oldSetter = SET + Util._capitalize(oldMethodName);
|
|
107
101
|
function deprecated() {
|
|
108
|
-
method.apply(this, arguments);
|
|
109
102
|
Util.error('"' +
|
|
110
103
|
oldMethodName +
|
|
111
104
|
'" method is deprecated and will be removed soon. Use ""' +
|
|
112
105
|
newMethodName +
|
|
113
106
|
'" instead.');
|
|
107
|
+
return method.apply(this, arguments);
|
|
114
108
|
}
|
|
115
109
|
constructor.prototype[oldMethodName] = deprecated;
|
|
116
110
|
constructor.prototype[oldGetter] = deprecated;
|
package/lib/FastLayer.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { Layer } from './Layer.ts';
|
|
2
|
+
/**
|
|
3
|
+
* FastLayer constructor. **DEPRECATED!** Please use `Konva.Layer({ listening: false})` instead. Layers are tied to their own canvas element and are used
|
|
4
|
+
* to contain shapes only. If you don't need node nesting, mouse and touch interactions,
|
|
5
|
+
* or event pub/sub, you should use FastLayer instead of Layer to create your layers.
|
|
6
|
+
* It renders about 2x faster than normal layers.
|
|
7
|
+
*
|
|
8
|
+
* @constructor
|
|
9
|
+
* @memberof Konva
|
|
10
|
+
* @augments Konva.Layer
|
|
11
|
+
@@containerParams
|
|
12
|
+
* @example
|
|
13
|
+
* var layer = new Konva.FastLayer();
|
|
14
|
+
*/
|
|
2
15
|
export declare class FastLayer extends Layer {
|
|
3
|
-
constructor(attrs
|
|
16
|
+
constructor(attrs?: any);
|
|
4
17
|
}
|
package/lib/FastLayer.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { Util } from "./Util.js";
|
|
2
2
|
import { Layer } from "./Layer.js";
|
|
3
3
|
import { _registerNode } from "./Global.js";
|
|
4
|
+
/**
|
|
5
|
+
* FastLayer constructor. **DEPRECATED!** Please use `Konva.Layer({ listening: false})` instead. Layers are tied to their own canvas element and are used
|
|
6
|
+
* to contain shapes only. If you don't need node nesting, mouse and touch interactions,
|
|
7
|
+
* or event pub/sub, you should use FastLayer instead of Layer to create your layers.
|
|
8
|
+
* It renders about 2x faster than normal layers.
|
|
9
|
+
*
|
|
10
|
+
* @constructor
|
|
11
|
+
* @memberof Konva
|
|
12
|
+
* @augments Konva.Layer
|
|
13
|
+
@@containerParams
|
|
14
|
+
* @example
|
|
15
|
+
* var layer = new Konva.FastLayer();
|
|
16
|
+
*/
|
|
4
17
|
export class FastLayer extends Layer {
|
|
5
18
|
constructor(attrs) {
|
|
6
19
|
super(attrs);
|
|
7
20
|
this.listening(false);
|
|
8
|
-
Util.warn('Konva.
|
|
21
|
+
Util.warn('Konva.FastLayer is deprecated. Please use "new Konva.Layer({ listening: false })" instead.');
|
|
9
22
|
}
|
|
10
23
|
}
|
|
11
24
|
FastLayer.prototype.nodeType = 'FastLayer';
|
package/lib/Global.d.ts
CHANGED
|
@@ -8,8 +8,39 @@ export declare const Konva: {
|
|
|
8
8
|
getAngle(angle: number): number;
|
|
9
9
|
enableTrace: boolean;
|
|
10
10
|
pointerEventsEnabled: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Should Konva automatically update canvas on any changes. Default is true.
|
|
13
|
+
* @property autoDrawEnabled
|
|
14
|
+
* @default true
|
|
15
|
+
* @name autoDrawEnabled
|
|
16
|
+
* @memberof Konva
|
|
17
|
+
* @example
|
|
18
|
+
* Konva.autoDrawEnabled = true;
|
|
19
|
+
*/
|
|
11
20
|
autoDrawEnabled: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Should we enable hit detection while dragging? For performance reasons, by default it is false.
|
|
23
|
+
* But on some rare cases you want to see hit graph and check intersections. Just set it to true.
|
|
24
|
+
* @property hitOnDragEnabled
|
|
25
|
+
* @default false
|
|
26
|
+
* @name hitOnDragEnabled
|
|
27
|
+
* @memberof Konva
|
|
28
|
+
* @example
|
|
29
|
+
* Konva.hitOnDragEnabled = true;
|
|
30
|
+
*/
|
|
12
31
|
hitOnDragEnabled: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Should we capture touch events and bind them to the touchstart target? That is how it works on DOM elements.
|
|
34
|
+
* The case: we touchstart on div1, then touchmove out of that element into another element div2.
|
|
35
|
+
* DOM will continue trigger touchmove events on div1 (not div2). Because events are "captured" into initial target.
|
|
36
|
+
* By default Konva do not do that and will trigger touchmove on another element, while pointer is moving.
|
|
37
|
+
* @property capturePointerEventsEnabled
|
|
38
|
+
* @default false
|
|
39
|
+
* @name capturePointerEventsEnabled
|
|
40
|
+
* @memberof Konva
|
|
41
|
+
* @example
|
|
42
|
+
* Konva.capturePointerEventsEnabled = true;
|
|
43
|
+
*/
|
|
13
44
|
capturePointerEventsEnabled: boolean;
|
|
14
45
|
_mouseListenClick: boolean;
|
|
15
46
|
_touchListenClick: boolean;
|
|
@@ -17,19 +48,99 @@ export declare const Konva: {
|
|
|
17
48
|
_mouseInDblClickWindow: boolean;
|
|
18
49
|
_touchInDblClickWindow: boolean;
|
|
19
50
|
_pointerInDblClickWindow: boolean;
|
|
20
|
-
_mouseDblClickPointerId: null;
|
|
21
|
-
_touchDblClickPointerId: null;
|
|
22
|
-
_pointerDblClickPointerId: null;
|
|
23
51
|
_renderBackend: string;
|
|
52
|
+
/**
|
|
53
|
+
* Use legacy text rendering. with "middle" baseline by default.
|
|
54
|
+
* @property legacyTextRendering
|
|
55
|
+
* @default false
|
|
56
|
+
* @name legacyTextRendering
|
|
57
|
+
* @memberof Konva
|
|
58
|
+
* @example
|
|
59
|
+
* Konva.legacyTextRendering = true;
|
|
60
|
+
*/
|
|
24
61
|
legacyTextRendering: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Global pixel ratio configuration. KonvaJS automatically detect pixel ratio of current device.
|
|
64
|
+
* But you may override such property, if you want to use your value. Set this value before any components initializations.
|
|
65
|
+
* @property pixelRatio
|
|
66
|
+
* @default window.devicePixelRatio || 1
|
|
67
|
+
* @name pixelRatio
|
|
68
|
+
* @memberof Konva
|
|
69
|
+
* @example
|
|
70
|
+
* // before any Konva code:
|
|
71
|
+
* Konva.pixelRatio = 1;
|
|
72
|
+
*/
|
|
25
73
|
pixelRatio: number;
|
|
74
|
+
/**
|
|
75
|
+
* Drag distance property. If you start to drag a node you may want to wait until pointer is moved to some distance from start point
|
|
76
|
+
* on either axis, only then start dragging. Default is 3px.
|
|
77
|
+
* @property dragDistance
|
|
78
|
+
* @default 3
|
|
79
|
+
* @memberof Konva
|
|
80
|
+
* @example
|
|
81
|
+
* Konva.dragDistance = 10;
|
|
82
|
+
*/
|
|
26
83
|
dragDistance: number;
|
|
84
|
+
/**
|
|
85
|
+
* Use degree values for angle properties. You may set this property to false if you want to use radian values.
|
|
86
|
+
* @property angleDeg
|
|
87
|
+
* @default true
|
|
88
|
+
* @memberof Konva
|
|
89
|
+
* @example
|
|
90
|
+
* node.rotation(45); // 45 degrees
|
|
91
|
+
* Konva.angleDeg = false;
|
|
92
|
+
* node.rotation(Math.PI / 2); // PI/2 radian
|
|
93
|
+
*/
|
|
27
94
|
angleDeg: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Show warnings about wrong API usage (`Konva.Util.warn`). Errors are always printed
|
|
97
|
+
* @property showWarnings
|
|
98
|
+
* @default true
|
|
99
|
+
* @memberof Konva
|
|
100
|
+
* @example
|
|
101
|
+
* Konva.showWarnings = false;
|
|
102
|
+
*/
|
|
28
103
|
showWarnings: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Configure what mouse buttons can be used for drag and drop.
|
|
106
|
+
* Default value is [0, 1] - left and middle mouse buttons.
|
|
107
|
+
* @property dragButtons
|
|
108
|
+
* @default [0, 1]
|
|
109
|
+
* @memberof Konva
|
|
110
|
+
* @example
|
|
111
|
+
* // enable left and right mouse buttons
|
|
112
|
+
* Konva.dragButtons = [0, 2];
|
|
113
|
+
*/
|
|
29
114
|
dragButtons: number[];
|
|
115
|
+
/**
|
|
116
|
+
* returns whether or not drag and drop is currently active
|
|
117
|
+
* @method
|
|
118
|
+
* @memberof Konva
|
|
119
|
+
*/
|
|
30
120
|
isDragging(): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* returns whether or not a Transformer is currently transforming a node
|
|
123
|
+
* @method
|
|
124
|
+
* @memberof Konva
|
|
125
|
+
*/
|
|
31
126
|
isTransforming(): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* returns whether or not a drag and drop operation is ready, but may
|
|
129
|
+
* not necessarily have started
|
|
130
|
+
* @method
|
|
131
|
+
* @memberof Konva
|
|
132
|
+
*/
|
|
32
133
|
isDragReady(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Should Konva release canvas elements on destroy. Default is true.
|
|
136
|
+
* Useful to avoid memory leak issues in Safari on macOS/iOS.
|
|
137
|
+
* @property releaseCanvasOnDestroy
|
|
138
|
+
* @default true
|
|
139
|
+
* @name releaseCanvasOnDestroy
|
|
140
|
+
* @memberof Konva
|
|
141
|
+
* @example
|
|
142
|
+
* Konva.releaseCanvasOnDestroy = true;
|
|
143
|
+
*/
|
|
33
144
|
releaseCanvasOnDestroy: boolean;
|
|
34
145
|
document: any;
|
|
35
146
|
_injectGlobal(Konva: any): void;
|
package/lib/Global.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Konva JavaScript Framework v10.4.0
|
|
3
|
+
* http://konvajs.org/
|
|
4
|
+
* Licensed under the MIT
|
|
5
|
+
* Date: @@date
|
|
6
|
+
*
|
|
7
|
+
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
|
8
|
+
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
|
9
|
+
*
|
|
10
|
+
* @license
|
|
11
|
+
*/
|
|
1
12
|
const PI_OVER_180 = Math.PI / 180;
|
|
13
|
+
/**
|
|
14
|
+
* @namespace Konva
|
|
15
|
+
*/
|
|
2
16
|
function detectBrowser() {
|
|
3
17
|
return (typeof window !== 'undefined' &&
|
|
18
|
+
// browser case
|
|
4
19
|
({}.toString.call(window) === '[object Window]' ||
|
|
20
|
+
// electron case
|
|
5
21
|
{}.toString.call(window) === '[object global]'));
|
|
6
22
|
}
|
|
7
23
|
export const glob = typeof global !== 'undefined'
|
|
@@ -13,7 +29,7 @@ export const glob = typeof global !== 'undefined'
|
|
|
13
29
|
: {};
|
|
14
30
|
export const Konva = {
|
|
15
31
|
_global: glob,
|
|
16
|
-
version: '10.
|
|
32
|
+
version: '10.4.0',
|
|
17
33
|
isBrowser: detectBrowser(),
|
|
18
34
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
19
35
|
dblClickWindow: 400,
|
|
@@ -22,8 +38,39 @@ export const Konva = {
|
|
|
22
38
|
},
|
|
23
39
|
enableTrace: false,
|
|
24
40
|
pointerEventsEnabled: true,
|
|
41
|
+
/**
|
|
42
|
+
* Should Konva automatically update canvas on any changes. Default is true.
|
|
43
|
+
* @property autoDrawEnabled
|
|
44
|
+
* @default true
|
|
45
|
+
* @name autoDrawEnabled
|
|
46
|
+
* @memberof Konva
|
|
47
|
+
* @example
|
|
48
|
+
* Konva.autoDrawEnabled = true;
|
|
49
|
+
*/
|
|
25
50
|
autoDrawEnabled: true,
|
|
51
|
+
/**
|
|
52
|
+
* Should we enable hit detection while dragging? For performance reasons, by default it is false.
|
|
53
|
+
* But on some rare cases you want to see hit graph and check intersections. Just set it to true.
|
|
54
|
+
* @property hitOnDragEnabled
|
|
55
|
+
* @default false
|
|
56
|
+
* @name hitOnDragEnabled
|
|
57
|
+
* @memberof Konva
|
|
58
|
+
* @example
|
|
59
|
+
* Konva.hitOnDragEnabled = true;
|
|
60
|
+
*/
|
|
26
61
|
hitOnDragEnabled: false,
|
|
62
|
+
/**
|
|
63
|
+
* Should we capture touch events and bind them to the touchstart target? That is how it works on DOM elements.
|
|
64
|
+
* The case: we touchstart on div1, then touchmove out of that element into another element div2.
|
|
65
|
+
* DOM will continue trigger touchmove events on div1 (not div2). Because events are "captured" into initial target.
|
|
66
|
+
* By default Konva do not do that and will trigger touchmove on another element, while pointer is moving.
|
|
67
|
+
* @property capturePointerEventsEnabled
|
|
68
|
+
* @default false
|
|
69
|
+
* @name capturePointerEventsEnabled
|
|
70
|
+
* @memberof Konva
|
|
71
|
+
* @example
|
|
72
|
+
* Konva.capturePointerEventsEnabled = true;
|
|
73
|
+
*/
|
|
27
74
|
capturePointerEventsEnabled: false,
|
|
28
75
|
_mouseListenClick: false,
|
|
29
76
|
_touchListenClick: false,
|
|
@@ -31,28 +78,110 @@ export const Konva = {
|
|
|
31
78
|
_mouseInDblClickWindow: false,
|
|
32
79
|
_touchInDblClickWindow: false,
|
|
33
80
|
_pointerInDblClickWindow: false,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
81
|
+
_renderBackend: 'web', // web, node-canvas, skia-canvas
|
|
82
|
+
/**
|
|
83
|
+
* Use legacy text rendering. with "middle" baseline by default.
|
|
84
|
+
* @property legacyTextRendering
|
|
85
|
+
* @default false
|
|
86
|
+
* @name legacyTextRendering
|
|
87
|
+
* @memberof Konva
|
|
88
|
+
* @example
|
|
89
|
+
* Konva.legacyTextRendering = true;
|
|
90
|
+
*/
|
|
38
91
|
legacyTextRendering: false,
|
|
92
|
+
/**
|
|
93
|
+
* Global pixel ratio configuration. KonvaJS automatically detect pixel ratio of current device.
|
|
94
|
+
* But you may override such property, if you want to use your value. Set this value before any components initializations.
|
|
95
|
+
* @property pixelRatio
|
|
96
|
+
* @default window.devicePixelRatio || 1
|
|
97
|
+
* @name pixelRatio
|
|
98
|
+
* @memberof Konva
|
|
99
|
+
* @example
|
|
100
|
+
* // before any Konva code:
|
|
101
|
+
* Konva.pixelRatio = 1;
|
|
102
|
+
*/
|
|
39
103
|
pixelRatio: (typeof window !== 'undefined' && window.devicePixelRatio) || 1,
|
|
104
|
+
/**
|
|
105
|
+
* Drag distance property. If you start to drag a node you may want to wait until pointer is moved to some distance from start point
|
|
106
|
+
* on either axis, only then start dragging. Default is 3px.
|
|
107
|
+
* @property dragDistance
|
|
108
|
+
* @default 3
|
|
109
|
+
* @memberof Konva
|
|
110
|
+
* @example
|
|
111
|
+
* Konva.dragDistance = 10;
|
|
112
|
+
*/
|
|
40
113
|
dragDistance: 3,
|
|
114
|
+
/**
|
|
115
|
+
* Use degree values for angle properties. You may set this property to false if you want to use radian values.
|
|
116
|
+
* @property angleDeg
|
|
117
|
+
* @default true
|
|
118
|
+
* @memberof Konva
|
|
119
|
+
* @example
|
|
120
|
+
* node.rotation(45); // 45 degrees
|
|
121
|
+
* Konva.angleDeg = false;
|
|
122
|
+
* node.rotation(Math.PI / 2); // PI/2 radian
|
|
123
|
+
*/
|
|
41
124
|
angleDeg: true,
|
|
125
|
+
/**
|
|
126
|
+
* Show warnings about wrong API usage (`Konva.Util.warn`). Errors are always printed
|
|
127
|
+
* @property showWarnings
|
|
128
|
+
* @default true
|
|
129
|
+
* @memberof Konva
|
|
130
|
+
* @example
|
|
131
|
+
* Konva.showWarnings = false;
|
|
132
|
+
*/
|
|
42
133
|
showWarnings: true,
|
|
134
|
+
/**
|
|
135
|
+
* Configure what mouse buttons can be used for drag and drop.
|
|
136
|
+
* Default value is [0, 1] - left and middle mouse buttons.
|
|
137
|
+
* @property dragButtons
|
|
138
|
+
* @default [0, 1]
|
|
139
|
+
* @memberof Konva
|
|
140
|
+
* @example
|
|
141
|
+
* // enable left and right mouse buttons
|
|
142
|
+
* Konva.dragButtons = [0, 2];
|
|
143
|
+
*/
|
|
43
144
|
dragButtons: [0, 1],
|
|
145
|
+
/**
|
|
146
|
+
* returns whether or not drag and drop is currently active
|
|
147
|
+
* @method
|
|
148
|
+
* @memberof Konva
|
|
149
|
+
*/
|
|
44
150
|
isDragging() {
|
|
45
151
|
return Konva['DD'].isDragging;
|
|
46
152
|
},
|
|
153
|
+
/**
|
|
154
|
+
* returns whether or not a Transformer is currently transforming a node
|
|
155
|
+
* @method
|
|
156
|
+
* @memberof Konva
|
|
157
|
+
*/
|
|
47
158
|
isTransforming() {
|
|
48
159
|
var _a, _b;
|
|
49
160
|
return (_b = (_a = Konva['Transformer']) === null || _a === void 0 ? void 0 : _a.isTransforming()) !== null && _b !== void 0 ? _b : false;
|
|
50
161
|
},
|
|
162
|
+
/**
|
|
163
|
+
* returns whether or not a drag and drop operation is ready, but may
|
|
164
|
+
* not necessarily have started
|
|
165
|
+
* @method
|
|
166
|
+
* @memberof Konva
|
|
167
|
+
*/
|
|
51
168
|
isDragReady() {
|
|
52
169
|
return !!Konva['DD'].node;
|
|
53
170
|
},
|
|
171
|
+
/**
|
|
172
|
+
* Should Konva release canvas elements on destroy. Default is true.
|
|
173
|
+
* Useful to avoid memory leak issues in Safari on macOS/iOS.
|
|
174
|
+
* @property releaseCanvasOnDestroy
|
|
175
|
+
* @default true
|
|
176
|
+
* @name releaseCanvasOnDestroy
|
|
177
|
+
* @memberof Konva
|
|
178
|
+
* @example
|
|
179
|
+
* Konva.releaseCanvasOnDestroy = true;
|
|
180
|
+
*/
|
|
54
181
|
releaseCanvasOnDestroy: true,
|
|
55
182
|
document: glob.document,
|
|
183
|
+
// insert Konva into global namespace (window)
|
|
184
|
+
// it is required for npm packages
|
|
56
185
|
_injectGlobal(Konva) {
|
|
57
186
|
if (typeof glob.Konva !== 'undefined') {
|
|
58
187
|
console.error('Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment.');
|
package/lib/Group.d.ts
CHANGED
|
@@ -4,6 +4,17 @@ import type { Node } from './Node.ts';
|
|
|
4
4
|
import type { Shape } from './Shape.ts';
|
|
5
5
|
export interface GroupConfig extends ContainerConfig {
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Group constructor. Groups are used to contain shapes or other groups.
|
|
9
|
+
* @constructor
|
|
10
|
+
* @memberof Konva
|
|
11
|
+
* @augments Konva.Container
|
|
12
|
+
* @param {Object} config
|
|
13
|
+
* @@nodeParams
|
|
14
|
+
* @@containerParams
|
|
15
|
+
* @example
|
|
16
|
+
* var group = new Konva.Group();
|
|
17
|
+
*/
|
|
7
18
|
export declare class Group extends Container<Group | Shape> {
|
|
8
19
|
_validateAdd(child: Node): void;
|
|
9
20
|
}
|