konva 8.1.4
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/CHANGELOG.md +1140 -0
- package/LICENSE +22 -0
- package/README.md +189 -0
- package/konva.js +18090 -0
- package/konva.min.js +12 -0
- package/lib/Animation.d.ts +24 -0
- package/lib/Animation.js +141 -0
- package/lib/Canvas.d.ts +32 -0
- package/lib/Canvas.js +107 -0
- package/lib/Container.d.ts +47 -0
- package/lib/Container.js +318 -0
- package/lib/Context.d.ts +76 -0
- package/lib/Context.js +520 -0
- package/lib/Core.d.ts +3 -0
- package/lib/Core.js +3 -0
- package/lib/DragAndDrop.d.ts +17 -0
- package/lib/DragAndDrop.js +104 -0
- package/lib/Factory.d.ts +11 -0
- package/lib/Factory.js +117 -0
- package/lib/FastLayer.d.ts +4 -0
- package/lib/FastLayer.js +12 -0
- package/lib/Global.d.ts +30 -0
- package/lib/Global.js +53 -0
- package/lib/Group.d.ts +6 -0
- package/lib/Group.js +13 -0
- package/lib/Layer.d.ts +60 -0
- package/lib/Layer.js +301 -0
- package/lib/Node.d.ts +318 -0
- package/lib/Node.js +1381 -0
- package/lib/PointerEvents.d.ts +11 -0
- package/lib/PointerEvents.js +37 -0
- package/lib/Shape.d.ts +184 -0
- package/lib/Shape.js +515 -0
- package/lib/Stage.d.ts +85 -0
- package/lib/Stage.js +687 -0
- package/lib/Tween.d.ts +86 -0
- package/lib/Tween.js +516 -0
- package/lib/Util.d.ts +87 -0
- package/lib/Util.js +742 -0
- package/lib/Validators.d.ts +11 -0
- package/lib/Validators.js +171 -0
- package/lib/_CoreInternals.d.ts +144 -0
- package/lib/_CoreInternals.js +34 -0
- package/lib/_FullInternals.d.ts +188 -0
- package/lib/_FullInternals.js +78 -0
- package/lib/filters/Blur.d.ts +2 -0
- package/lib/filters/Blur.js +697 -0
- package/lib/filters/Brighten.d.ts +2 -0
- package/lib/filters/Brighten.js +12 -0
- package/lib/filters/Contrast.d.ts +2 -0
- package/lib/filters/Contrast.js +34 -0
- package/lib/filters/Emboss.d.ts +2 -0
- package/lib/filters/Emboss.js +102 -0
- package/lib/filters/Enhance.d.ts +2 -0
- package/lib/filters/Enhance.js +83 -0
- package/lib/filters/Grayscale.d.ts +2 -0
- package/lib/filters/Grayscale.js +9 -0
- package/lib/filters/HSL.d.ts +2 -0
- package/lib/filters/HSL.js +24 -0
- package/lib/filters/HSV.d.ts +2 -0
- package/lib/filters/HSV.js +24 -0
- package/lib/filters/Invert.d.ts +2 -0
- package/lib/filters/Invert.js +8 -0
- package/lib/filters/Kaleidoscope.d.ts +2 -0
- package/lib/filters/Kaleidoscope.js +132 -0
- package/lib/filters/Mask.d.ts +2 -0
- package/lib/filters/Mask.js +140 -0
- package/lib/filters/Noise.d.ts +2 -0
- package/lib/filters/Noise.js +12 -0
- package/lib/filters/Pixelate.d.ts +2 -0
- package/lib/filters/Pixelate.js +60 -0
- package/lib/filters/Posterize.d.ts +2 -0
- package/lib/filters/Posterize.js +10 -0
- package/lib/filters/RGB.d.ts +2 -0
- package/lib/filters/RGB.js +39 -0
- package/lib/filters/RGBA.d.ts +2 -0
- package/lib/filters/RGBA.js +49 -0
- package/lib/filters/Sepia.d.ts +2 -0
- package/lib/filters/Sepia.js +11 -0
- package/lib/filters/Solarize.d.ts +2 -0
- package/lib/filters/Solarize.js +25 -0
- package/lib/filters/Threshold.d.ts +2 -0
- package/lib/filters/Threshold.js +10 -0
- package/lib/index-node.d.ts +2 -0
- package/lib/index-node.js +18 -0
- package/lib/index-types.d.ts +179 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/shapes/Arc.d.ts +19 -0
- package/lib/shapes/Arc.js +35 -0
- package/lib/shapes/Arrow.d.ts +24 -0
- package/lib/shapes/Arrow.js +94 -0
- package/lib/shapes/Circle.d.ts +13 -0
- package/lib/shapes/Circle.js +33 -0
- package/lib/shapes/Ellipse.d.ts +16 -0
- package/lib/shapes/Ellipse.js +37 -0
- package/lib/shapes/Image.d.ts +23 -0
- package/lib/shapes/Image.js +100 -0
- package/lib/shapes/Label.d.ts +35 -0
- package/lib/shapes/Label.js +166 -0
- package/lib/shapes/Line.d.ts +28 -0
- package/lib/shapes/Line.js +155 -0
- package/lib/shapes/Path.d.ts +37 -0
- package/lib/shapes/Path.js +627 -0
- package/lib/shapes/Rect.d.ts +9 -0
- package/lib/shapes/Rect.js +42 -0
- package/lib/shapes/RegularPolygon.d.ts +22 -0
- package/lib/shapes/RegularPolygon.js +65 -0
- package/lib/shapes/Ring.d.ts +16 -0
- package/lib/shapes/Ring.js +33 -0
- package/lib/shapes/Sprite.d.ts +30 -0
- package/lib/shapes/Sprite.js +108 -0
- package/lib/shapes/Star.d.ts +17 -0
- package/lib/shapes/Star.js +38 -0
- package/lib/shapes/Text.d.ts +59 -0
- package/lib/shapes/Text.js +347 -0
- package/lib/shapes/TextPath.d.ts +54 -0
- package/lib/shapes/TextPath.js +343 -0
- package/lib/shapes/Transformer.d.ts +112 -0
- package/lib/shapes/Transformer.js +944 -0
- package/lib/shapes/Wedge.d.ts +17 -0
- package/lib/shapes/Wedge.js +38 -0
- package/lib/types.d.ts +50 -0
- package/lib/types.js +22 -0
- package/package.json +111 -0
package/lib/Layer.js
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
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';
|
|
9
|
+
var HASH = '#', BEFORE_DRAW = 'beforeDraw', DRAW = 'draw', INTERSECTION_OFFSETS = [
|
|
10
|
+
{ x: 0, y: 0 },
|
|
11
|
+
{ x: -1, y: -1 },
|
|
12
|
+
{ x: 1, y: -1 },
|
|
13
|
+
{ x: 1, y: 1 },
|
|
14
|
+
{ x: -1, y: 1 },
|
|
15
|
+
], INTERSECTION_OFFSETS_LEN = INTERSECTION_OFFSETS.length;
|
|
16
|
+
export class Layer extends Container {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
super(config);
|
|
19
|
+
this.canvas = new SceneCanvas();
|
|
20
|
+
this.hitCanvas = new HitCanvas({
|
|
21
|
+
pixelRatio: 1,
|
|
22
|
+
});
|
|
23
|
+
this._waitingForDraw = false;
|
|
24
|
+
this.on('visibleChange.konva', this._checkVisibility);
|
|
25
|
+
this._checkVisibility();
|
|
26
|
+
this.on('imageSmoothingEnabledChange.konva', this._setSmoothEnabled);
|
|
27
|
+
this._setSmoothEnabled();
|
|
28
|
+
}
|
|
29
|
+
createPNGStream() {
|
|
30
|
+
const c = this.canvas._canvas;
|
|
31
|
+
return c.createPNGStream();
|
|
32
|
+
}
|
|
33
|
+
getCanvas() {
|
|
34
|
+
return this.canvas;
|
|
35
|
+
}
|
|
36
|
+
getNativeCanvasElement() {
|
|
37
|
+
return this.canvas._canvas;
|
|
38
|
+
}
|
|
39
|
+
getHitCanvas() {
|
|
40
|
+
return this.hitCanvas;
|
|
41
|
+
}
|
|
42
|
+
getContext() {
|
|
43
|
+
return this.getCanvas().getContext();
|
|
44
|
+
}
|
|
45
|
+
clear(bounds) {
|
|
46
|
+
this.getContext().clear(bounds);
|
|
47
|
+
this.getHitCanvas().getContext().clear(bounds);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
setZIndex(index) {
|
|
51
|
+
super.setZIndex(index);
|
|
52
|
+
var stage = this.getStage();
|
|
53
|
+
if (stage && stage.content) {
|
|
54
|
+
stage.content.removeChild(this.getNativeCanvasElement());
|
|
55
|
+
if (index < stage.children.length - 1) {
|
|
56
|
+
stage.content.insertBefore(this.getNativeCanvasElement(), stage.children[index + 1].getCanvas()._canvas);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
stage.content.appendChild(this.getNativeCanvasElement());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
moveToTop() {
|
|
65
|
+
Node.prototype.moveToTop.call(this);
|
|
66
|
+
var stage = this.getStage();
|
|
67
|
+
if (stage && stage.content) {
|
|
68
|
+
stage.content.removeChild(this.getNativeCanvasElement());
|
|
69
|
+
stage.content.appendChild(this.getNativeCanvasElement());
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
moveUp() {
|
|
74
|
+
var moved = Node.prototype.moveUp.call(this);
|
|
75
|
+
if (!moved) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
var stage = this.getStage();
|
|
79
|
+
if (!stage || !stage.content) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
stage.content.removeChild(this.getNativeCanvasElement());
|
|
83
|
+
if (this.index < stage.children.length - 1) {
|
|
84
|
+
stage.content.insertBefore(this.getNativeCanvasElement(), stage.children[this.index + 1].getCanvas()._canvas);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
stage.content.appendChild(this.getNativeCanvasElement());
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
moveDown() {
|
|
92
|
+
if (Node.prototype.moveDown.call(this)) {
|
|
93
|
+
var stage = this.getStage();
|
|
94
|
+
if (stage) {
|
|
95
|
+
var children = stage.children;
|
|
96
|
+
if (stage.content) {
|
|
97
|
+
stage.content.removeChild(this.getNativeCanvasElement());
|
|
98
|
+
stage.content.insertBefore(this.getNativeCanvasElement(), children[this.index + 1].getCanvas()._canvas);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
moveToBottom() {
|
|
106
|
+
if (Node.prototype.moveToBottom.call(this)) {
|
|
107
|
+
var stage = this.getStage();
|
|
108
|
+
if (stage) {
|
|
109
|
+
var children = stage.children;
|
|
110
|
+
if (stage.content) {
|
|
111
|
+
stage.content.removeChild(this.getNativeCanvasElement());
|
|
112
|
+
stage.content.insertBefore(this.getNativeCanvasElement(), children[1].getCanvas()._canvas);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
getLayer() {
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
remove() {
|
|
123
|
+
var _canvas = this.getNativeCanvasElement();
|
|
124
|
+
Node.prototype.remove.call(this);
|
|
125
|
+
if (_canvas && _canvas.parentNode && Util._isInDocument(_canvas)) {
|
|
126
|
+
_canvas.parentNode.removeChild(_canvas);
|
|
127
|
+
}
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
getStage() {
|
|
131
|
+
return this.parent;
|
|
132
|
+
}
|
|
133
|
+
setSize({ width, height }) {
|
|
134
|
+
this.canvas.setSize(width, height);
|
|
135
|
+
this.hitCanvas.setSize(width, height);
|
|
136
|
+
this._setSmoothEnabled();
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
_validateAdd(child) {
|
|
140
|
+
var type = child.getType();
|
|
141
|
+
if (type !== 'Group' && type !== 'Shape') {
|
|
142
|
+
Util.throw('You may only add groups and shapes to a layer.');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
_toKonvaCanvas(config) {
|
|
146
|
+
config = config || {};
|
|
147
|
+
config.width = config.width || this.getWidth();
|
|
148
|
+
config.height = config.height || this.getHeight();
|
|
149
|
+
config.x = config.x !== undefined ? config.x : this.x();
|
|
150
|
+
config.y = config.y !== undefined ? config.y : this.y();
|
|
151
|
+
return Node.prototype._toKonvaCanvas.call(this, config);
|
|
152
|
+
}
|
|
153
|
+
_checkVisibility() {
|
|
154
|
+
const visible = this.visible();
|
|
155
|
+
if (visible) {
|
|
156
|
+
this.canvas._canvas.style.display = 'block';
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
this.canvas._canvas.style.display = 'none';
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
_setSmoothEnabled() {
|
|
163
|
+
this.getContext()._context.imageSmoothingEnabled =
|
|
164
|
+
this.imageSmoothingEnabled();
|
|
165
|
+
}
|
|
166
|
+
getWidth() {
|
|
167
|
+
if (this.parent) {
|
|
168
|
+
return this.parent.width();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
setWidth() {
|
|
172
|
+
Util.warn('Can not change width of layer. Use "stage.width(value)" function instead.');
|
|
173
|
+
}
|
|
174
|
+
getHeight() {
|
|
175
|
+
if (this.parent) {
|
|
176
|
+
return this.parent.height();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
setHeight() {
|
|
180
|
+
Util.warn('Can not change height of layer. Use "stage.height(value)" function instead.');
|
|
181
|
+
}
|
|
182
|
+
batchDraw() {
|
|
183
|
+
if (!this._waitingForDraw) {
|
|
184
|
+
this._waitingForDraw = true;
|
|
185
|
+
Util.requestAnimFrame(() => {
|
|
186
|
+
this.draw();
|
|
187
|
+
this._waitingForDraw = false;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
getIntersection(pos) {
|
|
193
|
+
if (!this.isListening() || !this.isVisible()) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
var spiralSearchDistance = 1;
|
|
197
|
+
var continueSearch = false;
|
|
198
|
+
while (true) {
|
|
199
|
+
for (let i = 0; i < INTERSECTION_OFFSETS_LEN; i++) {
|
|
200
|
+
const intersectionOffset = INTERSECTION_OFFSETS[i];
|
|
201
|
+
const obj = this._getIntersection({
|
|
202
|
+
x: pos.x + intersectionOffset.x * spiralSearchDistance,
|
|
203
|
+
y: pos.y + intersectionOffset.y * spiralSearchDistance,
|
|
204
|
+
});
|
|
205
|
+
const shape = obj.shape;
|
|
206
|
+
if (shape) {
|
|
207
|
+
return shape;
|
|
208
|
+
}
|
|
209
|
+
continueSearch = !!obj.antialiased;
|
|
210
|
+
if (!obj.antialiased) {
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (continueSearch) {
|
|
215
|
+
spiralSearchDistance += 1;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
_getIntersection(pos) {
|
|
223
|
+
const ratio = this.hitCanvas.pixelRatio;
|
|
224
|
+
const p = this.hitCanvas.context.getImageData(Math.round(pos.x * ratio), Math.round(pos.y * ratio), 1, 1).data;
|
|
225
|
+
const p3 = p[3];
|
|
226
|
+
if (p3 === 255) {
|
|
227
|
+
const colorKey = Util._rgbToHex(p[0], p[1], p[2]);
|
|
228
|
+
const shape = shapes[HASH + colorKey];
|
|
229
|
+
if (shape) {
|
|
230
|
+
return {
|
|
231
|
+
shape: shape,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
antialiased: true,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
else if (p3 > 0) {
|
|
239
|
+
return {
|
|
240
|
+
antialiased: true,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return {};
|
|
244
|
+
}
|
|
245
|
+
drawScene(can, top) {
|
|
246
|
+
var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
|
|
247
|
+
this._fire(BEFORE_DRAW, {
|
|
248
|
+
node: this,
|
|
249
|
+
});
|
|
250
|
+
if (this.clearBeforeDraw()) {
|
|
251
|
+
canvas.getContext().clear();
|
|
252
|
+
}
|
|
253
|
+
Container.prototype.drawScene.call(this, canvas, top);
|
|
254
|
+
this._fire(DRAW, {
|
|
255
|
+
node: this,
|
|
256
|
+
});
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
drawHit(can, top) {
|
|
260
|
+
var layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas);
|
|
261
|
+
if (layer && layer.clearBeforeDraw()) {
|
|
262
|
+
layer.getHitCanvas().getContext().clear();
|
|
263
|
+
}
|
|
264
|
+
Container.prototype.drawHit.call(this, canvas, top);
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
enableHitGraph() {
|
|
268
|
+
this.hitGraphEnabled(true);
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
disableHitGraph() {
|
|
272
|
+
this.hitGraphEnabled(false);
|
|
273
|
+
return this;
|
|
274
|
+
}
|
|
275
|
+
setHitGraphEnabled(val) {
|
|
276
|
+
Util.warn('hitGraphEnabled method is deprecated. Please use layer.listening() instead.');
|
|
277
|
+
this.listening(val);
|
|
278
|
+
}
|
|
279
|
+
getHitGraphEnabled(val) {
|
|
280
|
+
Util.warn('hitGraphEnabled method is deprecated. Please use layer.listening() instead.');
|
|
281
|
+
return this.listening();
|
|
282
|
+
}
|
|
283
|
+
toggleHitCanvas() {
|
|
284
|
+
if (!this.parent || !this.parent['content']) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
var parent = this.parent;
|
|
288
|
+
var added = !!this.hitCanvas._canvas.parentNode;
|
|
289
|
+
if (added) {
|
|
290
|
+
parent.content.removeChild(this.hitCanvas._canvas);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
parent.content.appendChild(this.hitCanvas._canvas);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
Layer.prototype.nodeType = 'Layer';
|
|
298
|
+
_registerNode(Layer);
|
|
299
|
+
Factory.addGetterSetter(Layer, 'imageSmoothingEnabled', true);
|
|
300
|
+
Factory.addGetterSetter(Layer, 'clearBeforeDraw', true);
|
|
301
|
+
Factory.addGetterSetter(Layer, 'hitGraphEnabled', true, getBooleanValidator());
|
package/lib/Node.d.ts
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { Transform } from './Util';
|
|
2
|
+
import { SceneCanvas, Canvas } from './Canvas';
|
|
3
|
+
import { Container } from './Container';
|
|
4
|
+
import { GetSet, Vector2d, IRect } from './types';
|
|
5
|
+
import { Stage } from './Stage';
|
|
6
|
+
import { Context } from './Context';
|
|
7
|
+
import { Shape } from './Shape';
|
|
8
|
+
import { Layer } from './Layer';
|
|
9
|
+
export declare type Filter = (this: Node, imageData: ImageData) => void;
|
|
10
|
+
declare 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
|
+
export interface NodeConfig {
|
|
12
|
+
[index: string]: any;
|
|
13
|
+
x?: number;
|
|
14
|
+
y?: number;
|
|
15
|
+
width?: number;
|
|
16
|
+
height?: number;
|
|
17
|
+
visible?: boolean;
|
|
18
|
+
listening?: boolean;
|
|
19
|
+
id?: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
opacity?: Number;
|
|
22
|
+
scale?: Vector2d;
|
|
23
|
+
scaleX?: number;
|
|
24
|
+
scaleY?: number;
|
|
25
|
+
rotation?: number;
|
|
26
|
+
rotationDeg?: number;
|
|
27
|
+
offset?: Vector2d;
|
|
28
|
+
offsetX?: number;
|
|
29
|
+
offsetY?: number;
|
|
30
|
+
draggable?: boolean;
|
|
31
|
+
dragDistance?: number;
|
|
32
|
+
dragBoundFunc?: (this: Node, pos: Vector2d) => Vector2d;
|
|
33
|
+
preventDefault?: boolean;
|
|
34
|
+
globalCompositeOperation?: globalCompositeOperationType;
|
|
35
|
+
filters?: Array<Filter>;
|
|
36
|
+
}
|
|
37
|
+
declare type NodeEventMap = GlobalEventHandlersEventMap & {
|
|
38
|
+
[index: string]: any;
|
|
39
|
+
};
|
|
40
|
+
export interface KonvaEventObject<EventType> {
|
|
41
|
+
type: string;
|
|
42
|
+
target: Shape | Stage;
|
|
43
|
+
evt: EventType;
|
|
44
|
+
currentTarget: Node;
|
|
45
|
+
cancelBubble: boolean;
|
|
46
|
+
child?: Node;
|
|
47
|
+
}
|
|
48
|
+
export declare type KonvaEventListener<This, EventType> = (this: This, ev: KonvaEventObject<EventType>) => void;
|
|
49
|
+
export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
50
|
+
_id: number;
|
|
51
|
+
eventListeners: {
|
|
52
|
+
[index: string]: Array<{
|
|
53
|
+
name: string;
|
|
54
|
+
handler: Function;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
attrs: any;
|
|
58
|
+
index: number;
|
|
59
|
+
_allEventListeners: null | Array<Function>;
|
|
60
|
+
parent: Container<Node> | null;
|
|
61
|
+
_cache: Map<string, any>;
|
|
62
|
+
_attachedDepsListeners: Map<string, boolean>;
|
|
63
|
+
_lastPos: Vector2d;
|
|
64
|
+
_attrsAffectingSize: string[];
|
|
65
|
+
_batchingTransformChange: boolean;
|
|
66
|
+
_needClearTransformCache: boolean;
|
|
67
|
+
_filterUpToDate: boolean;
|
|
68
|
+
_isUnderCache: boolean;
|
|
69
|
+
nodeType: string;
|
|
70
|
+
className: string;
|
|
71
|
+
_dragEventId: number | null;
|
|
72
|
+
_shouldFireChangeEvents: boolean;
|
|
73
|
+
constructor(config?: Config);
|
|
74
|
+
hasChildren(): boolean;
|
|
75
|
+
_clearCache(attr?: string): void;
|
|
76
|
+
_getCache(attr: string, privateGetter: Function): any;
|
|
77
|
+
_calculate(name: string, deps: Array<string>, getter: Function): any;
|
|
78
|
+
_getCanvasCache(): any;
|
|
79
|
+
_clearSelfAndDescendantCache(attr?: string): void;
|
|
80
|
+
clearCache(): this;
|
|
81
|
+
cache(config?: {
|
|
82
|
+
x?: number;
|
|
83
|
+
y?: number;
|
|
84
|
+
width?: number;
|
|
85
|
+
height?: number;
|
|
86
|
+
drawBorder?: boolean;
|
|
87
|
+
offset?: number;
|
|
88
|
+
pixelRatio?: number;
|
|
89
|
+
imageSmoothingEnabled?: boolean;
|
|
90
|
+
hitCanvasPixelRatio?: number;
|
|
91
|
+
}): this;
|
|
92
|
+
isCached(): boolean;
|
|
93
|
+
abstract drawScene(canvas?: Canvas, top?: Node): void;
|
|
94
|
+
abstract drawHit(canvas?: Canvas, top?: Node): void;
|
|
95
|
+
getClientRect(config?: {
|
|
96
|
+
skipTransform?: boolean;
|
|
97
|
+
skipShadow?: boolean;
|
|
98
|
+
skipStroke?: boolean;
|
|
99
|
+
relativeTo?: Container<Node>;
|
|
100
|
+
}): {
|
|
101
|
+
x: number;
|
|
102
|
+
y: number;
|
|
103
|
+
width: number;
|
|
104
|
+
height: number;
|
|
105
|
+
};
|
|
106
|
+
_transformedRect(rect: IRect, top: Node): {
|
|
107
|
+
x: number;
|
|
108
|
+
y: number;
|
|
109
|
+
width: number;
|
|
110
|
+
height: number;
|
|
111
|
+
};
|
|
112
|
+
_drawCachedSceneCanvas(context: Context): void;
|
|
113
|
+
_drawCachedHitCanvas(context: Context): void;
|
|
114
|
+
_getCachedSceneCanvas(): any;
|
|
115
|
+
on<K extends keyof NodeEventMap>(evtStr: K, handler: KonvaEventListener<this, NodeEventMap[K]>): any;
|
|
116
|
+
off(evtStr?: string, callback?: Function): this;
|
|
117
|
+
dispatchEvent(evt: any): this;
|
|
118
|
+
addEventListener(type: string, handler: (e: Event) => void): this;
|
|
119
|
+
removeEventListener(type: string): this;
|
|
120
|
+
_delegate(event: string, selector: string, handler: (e: Event) => void): void;
|
|
121
|
+
remove(): this;
|
|
122
|
+
_clearCaches(): void;
|
|
123
|
+
_remove(): void;
|
|
124
|
+
destroy(): this;
|
|
125
|
+
getAttr(attr: string): any;
|
|
126
|
+
getAncestors(): Node<NodeConfig>[];
|
|
127
|
+
getAttrs(): any;
|
|
128
|
+
setAttrs(config: any): this;
|
|
129
|
+
isListening(): any;
|
|
130
|
+
_isListening(relativeTo?: Node): boolean;
|
|
131
|
+
isVisible(): any;
|
|
132
|
+
_isVisible(relativeTo?: Node): boolean;
|
|
133
|
+
shouldDrawHit(top?: Node, skipDragCheck?: boolean): boolean;
|
|
134
|
+
show(): this;
|
|
135
|
+
hide(): this;
|
|
136
|
+
getZIndex(): number;
|
|
137
|
+
getAbsoluteZIndex(): number;
|
|
138
|
+
getDepth(): number;
|
|
139
|
+
_batchTransformChanges(func: any): void;
|
|
140
|
+
setPosition(pos: Vector2d): this;
|
|
141
|
+
getPosition(): {
|
|
142
|
+
x: number;
|
|
143
|
+
y: number;
|
|
144
|
+
};
|
|
145
|
+
getRelativePointerPosition(): {
|
|
146
|
+
x: number;
|
|
147
|
+
y: number;
|
|
148
|
+
};
|
|
149
|
+
getAbsolutePosition(top?: Node): {
|
|
150
|
+
x: number;
|
|
151
|
+
y: number;
|
|
152
|
+
};
|
|
153
|
+
setAbsolutePosition(pos: Vector2d): this;
|
|
154
|
+
_setTransform(trans: any): void;
|
|
155
|
+
_clearTransform(): {
|
|
156
|
+
x: number;
|
|
157
|
+
y: number;
|
|
158
|
+
rotation: number;
|
|
159
|
+
scaleX: number;
|
|
160
|
+
scaleY: number;
|
|
161
|
+
offsetX: number;
|
|
162
|
+
offsetY: number;
|
|
163
|
+
skewX: number;
|
|
164
|
+
skewY: number;
|
|
165
|
+
};
|
|
166
|
+
move(change: Vector2d): this;
|
|
167
|
+
_eachAncestorReverse(func: any, top: any): void;
|
|
168
|
+
rotate(theta: number): this;
|
|
169
|
+
moveToTop(): boolean;
|
|
170
|
+
moveUp(): boolean;
|
|
171
|
+
moveDown(): boolean;
|
|
172
|
+
moveToBottom(): boolean;
|
|
173
|
+
setZIndex(zIndex: any): this;
|
|
174
|
+
getAbsoluteOpacity(): any;
|
|
175
|
+
_getAbsoluteOpacity(): number;
|
|
176
|
+
moveTo(newContainer: any): this;
|
|
177
|
+
toObject(): any;
|
|
178
|
+
toJSON(): string;
|
|
179
|
+
getParent(): Container<Node<NodeConfig>>;
|
|
180
|
+
findAncestors(selector: string, includeSelf?: boolean, stopNode?: Node): Node<NodeConfig>[];
|
|
181
|
+
isAncestorOf(node: Node): boolean;
|
|
182
|
+
findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container): any;
|
|
183
|
+
_isMatch(selector: string | Function): any;
|
|
184
|
+
getLayer(): Layer | null;
|
|
185
|
+
getStage(): Stage | null;
|
|
186
|
+
_getStage(): Stage | undefined;
|
|
187
|
+
fire(eventType: string, evt?: any, bubble?: boolean): this;
|
|
188
|
+
getAbsoluteTransform(top?: Node): Transform;
|
|
189
|
+
_getAbsoluteTransform(top?: Node): Transform;
|
|
190
|
+
getAbsoluteScale(top?: Node): {
|
|
191
|
+
x: number;
|
|
192
|
+
y: number;
|
|
193
|
+
};
|
|
194
|
+
getAbsoluteRotation(): number;
|
|
195
|
+
getTransform(): Transform;
|
|
196
|
+
_getTransform(): Transform;
|
|
197
|
+
clone(obj?: any): any;
|
|
198
|
+
_toKonvaCanvas(config: any): SceneCanvas;
|
|
199
|
+
toCanvas(config?: any): HTMLCanvasElement;
|
|
200
|
+
toDataURL(config?: {
|
|
201
|
+
x?: number;
|
|
202
|
+
y?: number;
|
|
203
|
+
width?: number;
|
|
204
|
+
height?: number;
|
|
205
|
+
pixelRatio?: number;
|
|
206
|
+
mimeType?: string;
|
|
207
|
+
quality?: number;
|
|
208
|
+
callback?: (str: string) => void;
|
|
209
|
+
}): string;
|
|
210
|
+
toImage(config?: {
|
|
211
|
+
x?: number;
|
|
212
|
+
y?: number;
|
|
213
|
+
width?: number;
|
|
214
|
+
height?: number;
|
|
215
|
+
pixelRatio?: number;
|
|
216
|
+
mimeType?: string;
|
|
217
|
+
quality?: number;
|
|
218
|
+
callback?: (img: HTMLImageElement) => void;
|
|
219
|
+
}): void;
|
|
220
|
+
setSize(size: any): this;
|
|
221
|
+
getSize(): {
|
|
222
|
+
width: number;
|
|
223
|
+
height: number;
|
|
224
|
+
};
|
|
225
|
+
getClassName(): string;
|
|
226
|
+
getType(): string;
|
|
227
|
+
getDragDistance(): number;
|
|
228
|
+
_off(type: any, name?: any, callback?: any): void;
|
|
229
|
+
_fireChangeEvent(attr: any, oldVal: any, newVal: any): void;
|
|
230
|
+
addName(name: any): this;
|
|
231
|
+
hasName(name: any): boolean;
|
|
232
|
+
removeName(name: any): this;
|
|
233
|
+
setAttr(attr: any, val: any): this;
|
|
234
|
+
_requestDraw(): void;
|
|
235
|
+
_setAttr(key: any, val: any): void;
|
|
236
|
+
_setComponentAttr(key: any, component: any, val: any): void;
|
|
237
|
+
_fireAndBubble(eventType: any, evt: any, compareShape?: any): void;
|
|
238
|
+
_getProtoListeners(eventType: any): any;
|
|
239
|
+
_fire(eventType: any, evt: any): void;
|
|
240
|
+
draw(): this;
|
|
241
|
+
_createDragElement(evt: any): void;
|
|
242
|
+
startDrag(evt?: any, bubbleEvent?: boolean): void;
|
|
243
|
+
_setDragPosition(evt: any, elem: any): void;
|
|
244
|
+
stopDrag(evt?: any): void;
|
|
245
|
+
setDraggable(draggable: any): void;
|
|
246
|
+
isDragging(): boolean;
|
|
247
|
+
_listenDrag(): void;
|
|
248
|
+
_dragChange(): void;
|
|
249
|
+
_dragCleanup(): void;
|
|
250
|
+
isClientRectOnScreen(margin?: {
|
|
251
|
+
x: number;
|
|
252
|
+
y: number;
|
|
253
|
+
}): boolean;
|
|
254
|
+
preventDefault: GetSet<boolean, this>;
|
|
255
|
+
blue: GetSet<number, this>;
|
|
256
|
+
brightness: GetSet<number, this>;
|
|
257
|
+
contrast: GetSet<number, this>;
|
|
258
|
+
blurRadius: GetSet<number, this>;
|
|
259
|
+
luminance: GetSet<number, this>;
|
|
260
|
+
green: GetSet<number, this>;
|
|
261
|
+
alpha: GetSet<number, this>;
|
|
262
|
+
hue: GetSet<number, this>;
|
|
263
|
+
kaleidoscopeAngle: GetSet<number, this>;
|
|
264
|
+
kaleidoscopePower: GetSet<number, this>;
|
|
265
|
+
levels: GetSet<number, this>;
|
|
266
|
+
noise: GetSet<number, this>;
|
|
267
|
+
pixelSize: GetSet<number, this>;
|
|
268
|
+
red: GetSet<number, this>;
|
|
269
|
+
saturation: GetSet<number, this>;
|
|
270
|
+
threshold: GetSet<number, this>;
|
|
271
|
+
value: GetSet<number, this>;
|
|
272
|
+
dragBoundFunc: GetSet<(this: Node, pos: Vector2d) => Vector2d, this>;
|
|
273
|
+
draggable: GetSet<boolean, this>;
|
|
274
|
+
dragDistance: GetSet<number, this>;
|
|
275
|
+
embossBlend: GetSet<boolean, this>;
|
|
276
|
+
embossDirection: GetSet<string, this>;
|
|
277
|
+
embossStrength: GetSet<number, this>;
|
|
278
|
+
embossWhiteLevel: GetSet<number, this>;
|
|
279
|
+
enhance: GetSet<number, this>;
|
|
280
|
+
filters: GetSet<Filter[], this>;
|
|
281
|
+
position: GetSet<Vector2d, this>;
|
|
282
|
+
absolutePosition: GetSet<Vector2d, this>;
|
|
283
|
+
size: GetSet<{
|
|
284
|
+
width: number;
|
|
285
|
+
height: number;
|
|
286
|
+
}, this>;
|
|
287
|
+
id: GetSet<string, this>;
|
|
288
|
+
listening: GetSet<boolean, this>;
|
|
289
|
+
name: GetSet<string, this>;
|
|
290
|
+
offset: GetSet<Vector2d, this>;
|
|
291
|
+
offsetX: GetSet<number, this>;
|
|
292
|
+
offsetY: GetSet<number, this>;
|
|
293
|
+
opacity: GetSet<number, this>;
|
|
294
|
+
rotation: GetSet<number, this>;
|
|
295
|
+
zIndex: GetSet<number, this>;
|
|
296
|
+
scale: GetSet<Vector2d, this>;
|
|
297
|
+
scaleX: GetSet<number, this>;
|
|
298
|
+
scaleY: GetSet<number, this>;
|
|
299
|
+
skew: GetSet<Vector2d, this>;
|
|
300
|
+
skewX: GetSet<number, this>;
|
|
301
|
+
skewY: GetSet<number, this>;
|
|
302
|
+
to: (params: AnimTo) => void;
|
|
303
|
+
transformsEnabled: GetSet<string, this>;
|
|
304
|
+
visible: GetSet<boolean, this>;
|
|
305
|
+
width: GetSet<number, this>;
|
|
306
|
+
height: GetSet<number, this>;
|
|
307
|
+
x: GetSet<number, this>;
|
|
308
|
+
y: GetSet<number, this>;
|
|
309
|
+
globalCompositeOperation: GetSet<globalCompositeOperationType, this>;
|
|
310
|
+
static create(data: any, container?: any): any;
|
|
311
|
+
static _createNode(obj: any, container?: any): any;
|
|
312
|
+
}
|
|
313
|
+
interface AnimTo extends NodeConfig {
|
|
314
|
+
onFinish?: Function;
|
|
315
|
+
onUpdate?: Function;
|
|
316
|
+
duration?: number;
|
|
317
|
+
}
|
|
318
|
+
export {};
|