konva 10.3.2 → 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 +5 -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 +24 -21
package/lib/Node.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { Context } from './Context.ts';
|
|
|
5
5
|
import type { Layer } from './Layer.ts';
|
|
6
6
|
import type { Shape } from './Shape.ts';
|
|
7
7
|
import type { Stage } from './Stage.ts';
|
|
8
|
+
import type { Tween, TweenConfig } from './Tween.ts';
|
|
8
9
|
import type { GetSet, IRect, Vector2d } from './types.ts';
|
|
9
10
|
import { Transform, type AnyString } from './Util.ts';
|
|
10
11
|
export type FilterFunction = (this: Node, imageData: ImageData) => void;
|
|
@@ -33,7 +34,7 @@ export type NodeConfig = {
|
|
|
33
34
|
offsetY?: number;
|
|
34
35
|
draggable?: boolean;
|
|
35
36
|
dragDistance?: number;
|
|
36
|
-
dragBoundFunc?: (this: Node, pos: Vector2d) => Vector2d;
|
|
37
|
+
dragBoundFunc?: (this: Node, pos: Vector2d, evt: any) => Vector2d;
|
|
37
38
|
preventDefault?: boolean;
|
|
38
39
|
globalCompositeOperation?: globalCompositeOperationType;
|
|
39
40
|
filters?: Filters;
|
|
@@ -50,6 +51,14 @@ export interface KonvaEventObject<EventType, This = Node> {
|
|
|
50
51
|
currentTarget: This;
|
|
51
52
|
cancelBubble: boolean;
|
|
52
53
|
child?: Node;
|
|
54
|
+
oldVal?: any;
|
|
55
|
+
newVal?: any;
|
|
56
|
+
}
|
|
57
|
+
export interface GetClientRectConfig {
|
|
58
|
+
skipTransform?: boolean;
|
|
59
|
+
skipShadow?: boolean;
|
|
60
|
+
skipStroke?: boolean;
|
|
61
|
+
relativeTo?: Node;
|
|
53
62
|
}
|
|
54
63
|
export type KonvaEventListener<This, EventType> = (this: This, ev: KonvaEventObject<EventType, This>) => void;
|
|
55
64
|
export type CanvasConfig = {
|
|
@@ -74,11 +83,20 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
74
83
|
};
|
|
75
84
|
attrs: any;
|
|
76
85
|
index: number;
|
|
77
|
-
_allEventListeners: null | Array<Function>;
|
|
78
86
|
parent: Container | null;
|
|
79
|
-
_cache:
|
|
80
|
-
|
|
81
|
-
|
|
87
|
+
_cache: Record<string, any>;
|
|
88
|
+
_canvasCache: {
|
|
89
|
+
scene: SceneCanvas;
|
|
90
|
+
filter: SceneCanvas;
|
|
91
|
+
hit: HitCanvas | null;
|
|
92
|
+
hitConfig: {
|
|
93
|
+
pixelRatio: number;
|
|
94
|
+
width: number;
|
|
95
|
+
height: number;
|
|
96
|
+
};
|
|
97
|
+
x: number;
|
|
98
|
+
y: number;
|
|
99
|
+
} | null;
|
|
82
100
|
_attrsAffectingSize: string[];
|
|
83
101
|
_batchingTransformChange: boolean;
|
|
84
102
|
_needClearTransformCache: boolean;
|
|
@@ -91,34 +109,129 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
91
109
|
constructor(config?: Config);
|
|
92
110
|
hasChildren(): boolean;
|
|
93
111
|
_clearCache(attr?: string): void;
|
|
112
|
+
_releaseCanvasCache(): void;
|
|
94
113
|
_getCache(attr: string, privateGetter: Function): any;
|
|
95
|
-
|
|
96
|
-
|
|
114
|
+
_getCanvasCache(): {
|
|
115
|
+
scene: SceneCanvas;
|
|
116
|
+
filter: SceneCanvas;
|
|
117
|
+
hit: HitCanvas | null;
|
|
118
|
+
hitConfig: {
|
|
119
|
+
pixelRatio: number;
|
|
120
|
+
width: number;
|
|
121
|
+
height: number;
|
|
122
|
+
};
|
|
123
|
+
x: number;
|
|
124
|
+
y: number;
|
|
125
|
+
} | null;
|
|
97
126
|
_clearSelfAndDescendantCache(attr?: string): void;
|
|
98
127
|
static _absTransformCascadeDepth: number;
|
|
99
128
|
static _pendingAfterCascade: Array<() => void>;
|
|
100
129
|
static _runAfterAbsTransformCascade(cb: () => void): void;
|
|
130
|
+
/**
|
|
131
|
+
* clear cached canvas
|
|
132
|
+
* @method
|
|
133
|
+
* @name Konva.Node#clearCache
|
|
134
|
+
* @returns {Konva.Node}
|
|
135
|
+
* @example
|
|
136
|
+
* node.clearCache();
|
|
137
|
+
*/
|
|
101
138
|
clearCache(): this;
|
|
139
|
+
/**
|
|
140
|
+
* cache node to improve drawing performance, apply filters, or create more accurate
|
|
141
|
+
* hit regions. For all basic shapes size of cache canvas will be automatically detected.
|
|
142
|
+
* If you need to cache your custom `Konva.Shape` instance you have to pass shape's bounding box
|
|
143
|
+
* properties. Look at [https://konvajs.org/docs/performance/Shape_Caching.html](https://konvajs.org/docs/performance/Shape_Caching.html) for more information.
|
|
144
|
+
* @method
|
|
145
|
+
* @name Konva.Node#cache
|
|
146
|
+
* @param {Object} [config]
|
|
147
|
+
* @param {Number} [config.x]
|
|
148
|
+
* @param {Number} [config.y]
|
|
149
|
+
* @param {Number} [config.width]
|
|
150
|
+
* @param {Number} [config.height]
|
|
151
|
+
* @param {Number} [config.offset] increase canvas size by `offset` pixel in all directions.
|
|
152
|
+
* @param {Boolean} [config.drawBorder] when set to true, a red border will be drawn around the cached
|
|
153
|
+
* region for debugging purposes
|
|
154
|
+
* @param {Number} [config.pixelRatio] pixel ratio of the cache canvas, the canvas pixels per CSS pixel of the node. Default is `Konva.pixelRatio`, the device pixel ratio. A higher value keeps the cache sharp when the node is scaled up.
|
|
155
|
+
* @param {Boolean} [config.imageSmoothingEnabled] control imageSmoothingEnabled property of created canvas for cache
|
|
156
|
+
* @param {Number} [config.hitCanvasPixelRatio] change quality (or pixel ratio) of cached hit canvas.
|
|
157
|
+
* @returns {Konva.Node}
|
|
158
|
+
* @example
|
|
159
|
+
* // cache a shape with the x,y position of the bounding box at the center and
|
|
160
|
+
* // the width and height of the bounding box equal to the width and height of
|
|
161
|
+
* // the shape obtained from shape.width() and shape.height()
|
|
162
|
+
* image.cache();
|
|
163
|
+
*
|
|
164
|
+
* // cache a node and define the bounding box position and size
|
|
165
|
+
* node.cache({
|
|
166
|
+
* x: -30,
|
|
167
|
+
* y: -30,
|
|
168
|
+
* width: 100,
|
|
169
|
+
* height: 200
|
|
170
|
+
* });
|
|
171
|
+
*
|
|
172
|
+
* // cache a node and draw a red border around the bounding box
|
|
173
|
+
* // for debugging purposes
|
|
174
|
+
* node.cache({
|
|
175
|
+
* x: -30,
|
|
176
|
+
* y: -30,
|
|
177
|
+
* width: 100,
|
|
178
|
+
* height: 200,
|
|
179
|
+
* offset : 10,
|
|
180
|
+
* drawBorder: true
|
|
181
|
+
* });
|
|
182
|
+
*/
|
|
102
183
|
cache(config?: CanvasConfig & {
|
|
103
184
|
drawBorder?: boolean;
|
|
104
185
|
offset?: number;
|
|
105
186
|
hitCanvasPixelRatio?: number;
|
|
106
|
-
}): this
|
|
187
|
+
}): this;
|
|
107
188
|
_getCachedHitCanvas(top?: Node): HitCanvas | null;
|
|
189
|
+
/**
|
|
190
|
+
* determine if node is currently cached
|
|
191
|
+
* @method
|
|
192
|
+
* @name Konva.Node#isCached
|
|
193
|
+
* @returns {Boolean}
|
|
194
|
+
*/
|
|
108
195
|
isCached(): boolean;
|
|
109
196
|
abstract drawScene(canvas?: Canvas, top?: Node, bufferCanvas?: Canvas): void;
|
|
110
197
|
abstract drawHit(canvas?: Canvas, top?: Node): void;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Return client rectangle {x, y, width, height} of node. This rectangle also include all styling (strokes, shadows, etc).
|
|
200
|
+
* The purpose of the method is similar to getBoundingClientRect API of the DOM.
|
|
201
|
+
* @method
|
|
202
|
+
* @name Konva.Node#getClientRect
|
|
203
|
+
* @param {Object} config
|
|
204
|
+
* @param {Boolean} [config.skipTransform] should we apply transform to node for calculating rect?
|
|
205
|
+
* @param {Boolean} [config.skipShadow] should we apply shadow to the node for calculating bound box?
|
|
206
|
+
* @param {Boolean} [config.skipStroke] should we apply stroke to the node for calculating bound box?
|
|
207
|
+
* @param {Object} [config.relativeTo] calculate client rect relative to one of the parents
|
|
208
|
+
* @returns {Object} rect with {x, y, width, height} properties
|
|
209
|
+
* @example
|
|
210
|
+
* var rect = new Konva.Rect({
|
|
211
|
+
* width : 100,
|
|
212
|
+
* height : 100,
|
|
213
|
+
* x : 50,
|
|
214
|
+
* y : 50,
|
|
215
|
+
* strokeWidth : 4,
|
|
216
|
+
* stroke : 'black',
|
|
217
|
+
* offsetX : 50,
|
|
218
|
+
* scaleY : 2
|
|
219
|
+
* });
|
|
220
|
+
*
|
|
221
|
+
* // get client rect without think off transformations (position, rotation, scale, offset, etc)
|
|
222
|
+
* rect.getClientRect({ skipTransform: true});
|
|
223
|
+
* // returns {
|
|
224
|
+
* // x : -2, // two pixels for stroke / 2
|
|
225
|
+
* // y : -2,
|
|
226
|
+
* // width : 104, // increased by 4 for stroke
|
|
227
|
+
* // height : 104
|
|
228
|
+
* //}
|
|
229
|
+
*
|
|
230
|
+
* // get client rect with transformation applied
|
|
231
|
+
* rect.getClientRect();
|
|
232
|
+
* // returns Object {x: -2, y: 46, width: 104, height: 208}
|
|
233
|
+
*/
|
|
234
|
+
getClientRect(config?: GetClientRectConfig): IRect;
|
|
122
235
|
_transformedRect(rect: IRect, top?: Node | null): {
|
|
123
236
|
x: number;
|
|
124
237
|
y: number;
|
|
@@ -130,28 +243,164 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
130
243
|
_getCachedSceneCanvas(): Canvas;
|
|
131
244
|
on<K extends keyof NodeEventMap>(evtStr: K, handler: KonvaEventListener<this, NodeEventMap[K]>): this;
|
|
132
245
|
on<K extends keyof NodeEventMap>(evtStr: K, selector: string, handler: KonvaEventListener<Node, NodeEventMap[K]>): this;
|
|
246
|
+
/**
|
|
247
|
+
* remove event bindings from the node. Pass in a string of
|
|
248
|
+
* event types delimmited by a space to remove multiple event
|
|
249
|
+
* bindings at once such as 'mousedown mouseup mousemove'.
|
|
250
|
+
* include a namespace to remove an event binding by name
|
|
251
|
+
* such as 'click.foobar'. If you only give a name like '.foobar',
|
|
252
|
+
* all events in that namespace will be removed.
|
|
253
|
+
* @method
|
|
254
|
+
* @name Konva.Node#off
|
|
255
|
+
* @param {String} evtStr e.g. 'click', 'mousedown touchstart', '.foobar'
|
|
256
|
+
* @returns {Konva.Node}
|
|
257
|
+
* @example
|
|
258
|
+
* // remove listener
|
|
259
|
+
* node.off('click');
|
|
260
|
+
*
|
|
261
|
+
* // remove multiple listeners
|
|
262
|
+
* node.off('click touchstart');
|
|
263
|
+
*
|
|
264
|
+
* // remove listener by name
|
|
265
|
+
* node.off('click.foo');
|
|
266
|
+
*/
|
|
267
|
+
_prepareListeners(): void;
|
|
133
268
|
off(evtStr?: string, callback?: Function): this;
|
|
134
269
|
dispatchEvent(evt: any): this;
|
|
135
270
|
addEventListener(type: string, handler: (e: Event) => void): this;
|
|
136
271
|
removeEventListener(type: string): this;
|
|
137
272
|
_delegate(event: string, selector: string, handler: (e: Event) => void): this;
|
|
273
|
+
/**
|
|
274
|
+
* remove a node from parent, but don't destroy. You can reuse the node later.
|
|
275
|
+
* @method
|
|
276
|
+
* @name Konva.Node#remove
|
|
277
|
+
* @returns {Konva.Node}
|
|
278
|
+
* @example
|
|
279
|
+
* node.remove();
|
|
280
|
+
*/
|
|
138
281
|
remove(): this;
|
|
139
282
|
_clearCaches(): void;
|
|
140
283
|
_remove(): void;
|
|
284
|
+
/**
|
|
285
|
+
* remove and destroy a node. Kill it and delete forever! You should not reuse node after destroy().
|
|
286
|
+
* If the node is a container (Group, Stage or Layer) it will destroy all children too.
|
|
287
|
+
* The node fires a `destroy` event first, so anything holding a reference to it can let go.
|
|
288
|
+
* When an ancestor is being destroyed the node is already detached from its parent at that point.
|
|
289
|
+
* @method
|
|
290
|
+
* @name Konva.Node#destroy
|
|
291
|
+
* @example
|
|
292
|
+
* node.on('destroy', () => console.log('gone'));
|
|
293
|
+
* node.destroy();
|
|
294
|
+
*/
|
|
141
295
|
destroy(): this;
|
|
296
|
+
/**
|
|
297
|
+
* get attr
|
|
298
|
+
* @method
|
|
299
|
+
* @name Konva.Node#getAttr
|
|
300
|
+
* @param {String} attr
|
|
301
|
+
* @returns {Integer|String|Object|Array}
|
|
302
|
+
* @example
|
|
303
|
+
* var x = node.getAttr('x');
|
|
304
|
+
*/
|
|
142
305
|
getAttr<AttrConfig extends Config, K extends AnyString<keyof Config>>(attr: K): K extends keyof AttrConfig ? AttrConfig[K] : any;
|
|
306
|
+
/**
|
|
307
|
+
* get ancestors
|
|
308
|
+
* @method
|
|
309
|
+
* @name Konva.Node#getAncestors
|
|
310
|
+
* @returns {Array}
|
|
311
|
+
* @example
|
|
312
|
+
* shape.getAncestors().forEach(function(node) {
|
|
313
|
+
* console.log(node.id());
|
|
314
|
+
* })
|
|
315
|
+
*/
|
|
143
316
|
getAncestors(): Node<NodeConfig>[];
|
|
317
|
+
/**
|
|
318
|
+
* get attrs object literal
|
|
319
|
+
* @method
|
|
320
|
+
* @name Konva.Node#getAttrs
|
|
321
|
+
* @returns {Object}
|
|
322
|
+
*/
|
|
144
323
|
getAttrs(): Config;
|
|
324
|
+
/**
|
|
325
|
+
* set multiple attrs at once using an object literal
|
|
326
|
+
* @method
|
|
327
|
+
* @name Konva.Node#setAttrs
|
|
328
|
+
* @param {Object} config object containing key value pairs
|
|
329
|
+
* @returns {Konva.Node}
|
|
330
|
+
* @example
|
|
331
|
+
* node.setAttrs({
|
|
332
|
+
* x: 5,
|
|
333
|
+
* fill: 'red'
|
|
334
|
+
* });
|
|
335
|
+
*/
|
|
145
336
|
setAttrs(config?: Config): this;
|
|
337
|
+
/**
|
|
338
|
+
* determine if node is listening for events by taking into account ancestors.
|
|
339
|
+
*
|
|
340
|
+
* Parent | Self | isListening
|
|
341
|
+
* listening | listening |
|
|
342
|
+
* ----------+-----------+------------
|
|
343
|
+
* T | T | T
|
|
344
|
+
* T | F | F
|
|
345
|
+
* F | T | F
|
|
346
|
+
* F | F | F
|
|
347
|
+
*
|
|
348
|
+
* @method
|
|
349
|
+
* @name Konva.Node#isListening
|
|
350
|
+
* @returns {Boolean}
|
|
351
|
+
*/
|
|
146
352
|
isListening(): any;
|
|
147
353
|
_isListening(relativeTo?: Node): boolean;
|
|
354
|
+
/**
|
|
355
|
+
* determine if node is visible by taking into account ancestors.
|
|
356
|
+
*
|
|
357
|
+
* Parent | Self | isVisible
|
|
358
|
+
* visible | visible |
|
|
359
|
+
* ----------+-----------+------------
|
|
360
|
+
* T | T | T
|
|
361
|
+
* T | F | F
|
|
362
|
+
* F | T | F
|
|
363
|
+
* F | F | F
|
|
364
|
+
* @method
|
|
365
|
+
* @name Konva.Node#isVisible
|
|
366
|
+
* @returns {Boolean}
|
|
367
|
+
*/
|
|
148
368
|
isVisible(): any;
|
|
149
369
|
_isVisible(relativeTo?: Node): boolean;
|
|
150
|
-
shouldDrawHit(top?: Node
|
|
370
|
+
shouldDrawHit(top?: Node): any;
|
|
371
|
+
/**
|
|
372
|
+
* show node. set visible = true
|
|
373
|
+
* @method
|
|
374
|
+
* @name Konva.Node#show
|
|
375
|
+
* @returns {Konva.Node}
|
|
376
|
+
*/
|
|
151
377
|
show(): this;
|
|
378
|
+
/**
|
|
379
|
+
* hide node. Hidden nodes are no longer detectable
|
|
380
|
+
* @method
|
|
381
|
+
* @name Konva.Node#hide
|
|
382
|
+
* @returns {Konva.Node}
|
|
383
|
+
*/
|
|
152
384
|
hide(): this;
|
|
153
385
|
getZIndex(): number;
|
|
386
|
+
/**
|
|
387
|
+
* get absolute z-index which takes into account sibling
|
|
388
|
+
* and ancestor indices
|
|
389
|
+
* @method
|
|
390
|
+
* @name Konva.Node#getAbsoluteZIndex
|
|
391
|
+
* @returns {Integer}
|
|
392
|
+
*/
|
|
154
393
|
getAbsoluteZIndex(): number;
|
|
394
|
+
/**
|
|
395
|
+
* get node depth in node tree. Returns an integer.
|
|
396
|
+
* e.g. Stage depth will always be 0. Layers will always be 1. Groups and Shapes will always
|
|
397
|
+
* be >= 2
|
|
398
|
+
* @method
|
|
399
|
+
* @name Konva.Node#getDepth
|
|
400
|
+
* @returns {Integer}
|
|
401
|
+
* @example
|
|
402
|
+
* var depth = shape.getDepth(); // 2 for a shape right inside of a layer
|
|
403
|
+
*/
|
|
155
404
|
getDepth(): number;
|
|
156
405
|
_batchTransformChanges(func: any): void;
|
|
157
406
|
setPosition(pos: Vector2d): this;
|
|
@@ -159,10 +408,37 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
159
408
|
x: number;
|
|
160
409
|
y: number;
|
|
161
410
|
};
|
|
411
|
+
/**
|
|
412
|
+
* get position of first pointer (like mouse or first touch) relative to local coordinates of current node
|
|
413
|
+
* @method
|
|
414
|
+
* @name Konva.Node#getRelativePointerPosition
|
|
415
|
+
* @returns {Konva.Node}
|
|
416
|
+
* @example
|
|
417
|
+
*
|
|
418
|
+
* // let's think we have a rectangle at position x = 10, y = 10
|
|
419
|
+
* // now we clicked at x = 15, y = 15 of the stage
|
|
420
|
+
* // if you want to know position of the click, related to the rectangle you can use
|
|
421
|
+
* rect.getRelativePointerPosition();
|
|
422
|
+
*/
|
|
162
423
|
getRelativePointerPosition(): {
|
|
163
424
|
x: number;
|
|
164
425
|
y: number;
|
|
165
426
|
} | null;
|
|
427
|
+
/**
|
|
428
|
+
* get absolute position of a node. That function can be used to calculate absolute position, but relative to any ancestor
|
|
429
|
+
* @method
|
|
430
|
+
* @name Konva.Node#getAbsolutePosition
|
|
431
|
+
* @param {Object} [top] optional ancestor node
|
|
432
|
+
* @returns {Konva.Node}
|
|
433
|
+
* @example
|
|
434
|
+
*
|
|
435
|
+
* // returns absolute position relative to top-left corner of canvas
|
|
436
|
+
* node.getAbsolutePosition();
|
|
437
|
+
*
|
|
438
|
+
* // calculate absolute position of node, inside stage
|
|
439
|
+
* // so stage transforms are ignored
|
|
440
|
+
* node.getAbsolutePosition(stage)
|
|
441
|
+
*/
|
|
166
442
|
getAbsolutePosition(top?: Node): {
|
|
167
443
|
x: number;
|
|
168
444
|
y: number;
|
|
@@ -180,50 +456,335 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
180
456
|
skewX: number;
|
|
181
457
|
skewY: number;
|
|
182
458
|
};
|
|
459
|
+
/**
|
|
460
|
+
* move node by an amount relative to its current position
|
|
461
|
+
* @method
|
|
462
|
+
* @name Konva.Node#move
|
|
463
|
+
* @param {Object} change
|
|
464
|
+
* @param {Number} change.x
|
|
465
|
+
* @param {Number} change.y
|
|
466
|
+
* @returns {Konva.Node}
|
|
467
|
+
* @example
|
|
468
|
+
* // move node in x direction by 1px and y direction by 2px
|
|
469
|
+
* node.move({
|
|
470
|
+
* x: 1,
|
|
471
|
+
* y: 2
|
|
472
|
+
* });
|
|
473
|
+
*/
|
|
183
474
|
move(change: Vector2d): this;
|
|
184
|
-
|
|
475
|
+
/**
|
|
476
|
+
* rotate node by an amount in degrees relative to its current rotation
|
|
477
|
+
* @method
|
|
478
|
+
* @name Konva.Node#rotate
|
|
479
|
+
* @param {Number} theta
|
|
480
|
+
* @returns {Konva.Node}
|
|
481
|
+
*/
|
|
185
482
|
rotate(theta: number): this;
|
|
483
|
+
/**
|
|
484
|
+
* move node to the top of its siblings
|
|
485
|
+
* @method
|
|
486
|
+
* @name Konva.Node#moveToTop
|
|
487
|
+
* @returns {Boolean}
|
|
488
|
+
*/
|
|
186
489
|
moveToTop(): boolean;
|
|
490
|
+
/**
|
|
491
|
+
* move node up
|
|
492
|
+
* @method
|
|
493
|
+
* @name Konva.Node#moveUp
|
|
494
|
+
* @returns {Boolean} flag is moved or not
|
|
495
|
+
*/
|
|
187
496
|
moveUp(): boolean;
|
|
497
|
+
/**
|
|
498
|
+
* move node down
|
|
499
|
+
* @method
|
|
500
|
+
* @name Konva.Node#moveDown
|
|
501
|
+
* @returns {Boolean}
|
|
502
|
+
*/
|
|
188
503
|
moveDown(): boolean;
|
|
504
|
+
/**
|
|
505
|
+
* move node to the bottom of its siblings
|
|
506
|
+
* @method
|
|
507
|
+
* @name Konva.Node#moveToBottom
|
|
508
|
+
* @returns {Boolean}
|
|
509
|
+
*/
|
|
189
510
|
moveToBottom(): boolean;
|
|
190
511
|
setZIndex(zIndex: any): this;
|
|
512
|
+
/**
|
|
513
|
+
* get absolute opacity
|
|
514
|
+
* @method
|
|
515
|
+
* @name Konva.Node#getAbsoluteOpacity
|
|
516
|
+
* @returns {Number}
|
|
517
|
+
*/
|
|
191
518
|
getAbsoluteOpacity(): any;
|
|
192
519
|
_getAbsoluteOpacity(): number;
|
|
520
|
+
/**
|
|
521
|
+
* move node to another container
|
|
522
|
+
* @method
|
|
523
|
+
* @name Konva.Node#moveTo
|
|
524
|
+
* @param {Container} newContainer
|
|
525
|
+
* @returns {Konva.Node}
|
|
526
|
+
* @example
|
|
527
|
+
* // move node from current layer into layer2
|
|
528
|
+
* node.moveTo(layer2);
|
|
529
|
+
*/
|
|
193
530
|
moveTo(newContainer: any): this;
|
|
531
|
+
/**
|
|
532
|
+
* convert Node into an object for serialization. Returns an object.
|
|
533
|
+
* @method
|
|
534
|
+
* @name Konva.Node#toObject
|
|
535
|
+
* @returns {Object}
|
|
536
|
+
*/
|
|
194
537
|
toObject(): {
|
|
195
538
|
attrs: Config & Record<string, any>;
|
|
196
539
|
className: string;
|
|
197
540
|
children?: Array<any>;
|
|
198
541
|
};
|
|
542
|
+
/**
|
|
543
|
+
* convert Node into a JSON string. Returns a JSON string.
|
|
544
|
+
* @method
|
|
545
|
+
* @name Konva.Node#toJSON
|
|
546
|
+
* @returns {String}
|
|
547
|
+
*/
|
|
199
548
|
toJSON(): string;
|
|
549
|
+
/**
|
|
550
|
+
* get parent container
|
|
551
|
+
* @method
|
|
552
|
+
* @name Konva.Node#getParent
|
|
553
|
+
* @returns {Konva.Node}
|
|
554
|
+
*/
|
|
200
555
|
getParent(): Container<Node<NodeConfig>, import("./Container.ts").ContainerConfig> | null;
|
|
556
|
+
/**
|
|
557
|
+
* get all ancestors (parent then parent of the parent, etc) of the node
|
|
558
|
+
* @method
|
|
559
|
+
* @name Konva.Node#findAncestors
|
|
560
|
+
* @param {String} selector selector for search
|
|
561
|
+
* @param {Boolean} [includeSelf] show we think that node is ancestro itself?
|
|
562
|
+
* @param {Konva.Node} [stopNode] optional node where we need to stop searching (one of ancestors)
|
|
563
|
+
* @returns {Array} [ancestors]
|
|
564
|
+
* @example
|
|
565
|
+
* // get one of the parent group
|
|
566
|
+
* var parentGroups = node.findAncestors('Group');
|
|
567
|
+
*/
|
|
201
568
|
findAncestors(selector: string | Function, includeSelf?: boolean, stopNode?: Node): Node<NodeConfig>[];
|
|
202
569
|
isAncestorOf(node: Node): boolean;
|
|
570
|
+
/**
|
|
571
|
+
* get ancestor (parent or parent of the parent, etc) of the node that match passed selector
|
|
572
|
+
* @method
|
|
573
|
+
* @name Konva.Node#findAncestor
|
|
574
|
+
* @param {String} selector selector for search
|
|
575
|
+
* @param {Boolean} [includeSelf] show we think that node is ancestro itself?
|
|
576
|
+
* @param {Konva.Node} [stopNode] optional node where we need to stop searching (one of ancestors)
|
|
577
|
+
* @returns {Konva.Node} ancestor
|
|
578
|
+
* @example
|
|
579
|
+
* // get one of the parent group
|
|
580
|
+
* var group = node.findAncestors('.mygroup');
|
|
581
|
+
*/
|
|
203
582
|
findAncestor(selector: string | Function, includeSelf?: boolean, stopNode?: Container): Node<NodeConfig>;
|
|
204
583
|
_isMatch(selector: string | Function): any;
|
|
584
|
+
/**
|
|
585
|
+
* get layer ancestor
|
|
586
|
+
* @method
|
|
587
|
+
* @name Konva.Node#getLayer
|
|
588
|
+
* @returns {Konva.Layer}
|
|
589
|
+
*/
|
|
205
590
|
getLayer(): Layer | null;
|
|
591
|
+
/**
|
|
592
|
+
* get stage ancestor
|
|
593
|
+
* @method
|
|
594
|
+
* @name Konva.Node#getStage
|
|
595
|
+
* @returns {Konva.Stage}
|
|
596
|
+
*/
|
|
206
597
|
getStage(): Stage | null;
|
|
207
598
|
_getStage(): Stage | null;
|
|
599
|
+
/**
|
|
600
|
+
* fire event
|
|
601
|
+
* @method
|
|
602
|
+
* @name Konva.Node#fire
|
|
603
|
+
* @param {String} eventType event type. can be a regular event, like click, mouseover, or mouseout, or it can be a custom event, like myCustomEvent
|
|
604
|
+
* @param {Event} [evt] event object
|
|
605
|
+
* @param {Boolean} [bubble] setting the value to false, or leaving it undefined, will result in the event
|
|
606
|
+
* not bubbling. Setting the value to true will result in the event bubbling.
|
|
607
|
+
* @returns {Konva.Node}
|
|
608
|
+
* @example
|
|
609
|
+
* // manually fire click event
|
|
610
|
+
* node.fire('click');
|
|
611
|
+
*
|
|
612
|
+
* // fire custom event
|
|
613
|
+
* node.fire('foo');
|
|
614
|
+
*
|
|
615
|
+
* // fire custom event with custom event object
|
|
616
|
+
* node.fire('foo', {
|
|
617
|
+
* bar: 10
|
|
618
|
+
* });
|
|
619
|
+
*
|
|
620
|
+
* // fire click event that bubbles
|
|
621
|
+
* node.fire('click', null, true);
|
|
622
|
+
*/
|
|
208
623
|
fire(eventType: string, evt?: any, bubble?: boolean): this;
|
|
624
|
+
/**
|
|
625
|
+
* get absolute transform of the node which takes into
|
|
626
|
+
* account its ancestor transforms
|
|
627
|
+
* @method
|
|
628
|
+
* @name Konva.Node#getAbsoluteTransform
|
|
629
|
+
* @returns {Konva.Transform}
|
|
630
|
+
*/
|
|
209
631
|
getAbsoluteTransform(top?: Node | null): Transform;
|
|
210
|
-
|
|
632
|
+
_hasCachedAncestor(): boolean;
|
|
633
|
+
_getAbsoluteTransform(top?: Node | null): Transform;
|
|
634
|
+
_getCachedAbsoluteTransform(): Transform;
|
|
635
|
+
_multiplyOwnTransform(at: Transform): Transform;
|
|
636
|
+
/**
|
|
637
|
+
* get absolute scale of the node which takes into
|
|
638
|
+
* account its ancestor scales
|
|
639
|
+
* @method
|
|
640
|
+
* @name Konva.Node#getAbsoluteScale
|
|
641
|
+
* @returns {Object}
|
|
642
|
+
* @example
|
|
643
|
+
* // get absolute scale x
|
|
644
|
+
* var scaleX = node.getAbsoluteScale().x;
|
|
645
|
+
*/
|
|
211
646
|
getAbsoluteScale(top?: Node): {
|
|
212
647
|
x: number;
|
|
213
648
|
y: number;
|
|
214
649
|
};
|
|
650
|
+
/**
|
|
651
|
+
* get absolute rotation of the node which takes into
|
|
652
|
+
* account its ancestor rotations
|
|
653
|
+
* @method
|
|
654
|
+
* @name Konva.Node#getAbsoluteRotation
|
|
655
|
+
* @returns {Number}
|
|
656
|
+
* @example
|
|
657
|
+
* // get absolute rotation
|
|
658
|
+
* var rotation = node.getAbsoluteRotation();
|
|
659
|
+
*/
|
|
215
660
|
getAbsoluteRotation(): number;
|
|
661
|
+
/**
|
|
662
|
+
* get transform of the node
|
|
663
|
+
* @method
|
|
664
|
+
* @name Konva.Node#getTransform
|
|
665
|
+
* @returns {Konva.Transform}
|
|
666
|
+
*/
|
|
216
667
|
getTransform(): Transform;
|
|
217
668
|
_getTransform(): Transform;
|
|
669
|
+
/**
|
|
670
|
+
* clone node. Returns a new Node instance with identical attributes. You can also override
|
|
671
|
+
* the node properties with an object literal, enabling you to use an existing node as a template
|
|
672
|
+
* for another node
|
|
673
|
+
* @method
|
|
674
|
+
* @name Konva.Node#clone
|
|
675
|
+
* @param {Object} obj override attrs
|
|
676
|
+
* @returns {Konva.Node}
|
|
677
|
+
* @example
|
|
678
|
+
* // simple clone
|
|
679
|
+
* var clone = node.clone();
|
|
680
|
+
*
|
|
681
|
+
* // clone a node and override the x position
|
|
682
|
+
* var clone = rect.clone({
|
|
683
|
+
* x: 5
|
|
684
|
+
* });
|
|
685
|
+
*/
|
|
218
686
|
clone(obj?: any): any;
|
|
219
687
|
_toKonvaCanvas(config: any): SceneCanvas;
|
|
688
|
+
/**
|
|
689
|
+
* converts node into an canvas element.
|
|
690
|
+
* @method
|
|
691
|
+
* @name Konva.Node#toCanvas
|
|
692
|
+
* @param {Object} config
|
|
693
|
+
* @param {Function} config.callback function executed when the composite has completed
|
|
694
|
+
* @param {Number} [config.x] x position of canvas section
|
|
695
|
+
* @param {Number} [config.y] y position of canvas section
|
|
696
|
+
* @param {Number} [config.width] width of canvas section
|
|
697
|
+
* @param {Number} [config.height] height of canvas section
|
|
698
|
+
* @param {Number} [config.pixelRatio] pixelRatio of output canvas. Default is 1.
|
|
699
|
+
* You can use that property to increase quality of the image, for example for super hight quality exports
|
|
700
|
+
* or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
|
|
701
|
+
* If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
|
|
702
|
+
* @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
|
|
703
|
+
* @example
|
|
704
|
+
* var canvas = node.toCanvas();
|
|
705
|
+
*/
|
|
220
706
|
toCanvas(config?: CanvasConfig): HTMLCanvasElement;
|
|
707
|
+
/**
|
|
708
|
+
* Creates a composite data URL (base64 string). If MIME type is not
|
|
709
|
+
* specified, then "image/png" will result. For "image/jpeg", specify a quality
|
|
710
|
+
* level as quality (range 0.0 - 1.0)
|
|
711
|
+
* @method
|
|
712
|
+
* @name Konva.Node#toDataURL
|
|
713
|
+
* @param {Object} config
|
|
714
|
+
* @param {String} [config.mimeType] can be "image/png" or "image/jpeg".
|
|
715
|
+
* "image/png" is the default
|
|
716
|
+
* @param {Number} [config.x] x position of canvas section
|
|
717
|
+
* @param {Number} [config.y] y position of canvas section
|
|
718
|
+
* @param {Number} [config.width] width of canvas section
|
|
719
|
+
* @param {Number} [config.height] height of canvas section
|
|
720
|
+
* @param {Number} [config.quality] jpeg quality. If using an "image/jpeg" mimeType,
|
|
721
|
+
* you can specify the quality from 0 to 1, where 0 is very poor quality and 1
|
|
722
|
+
* is very high quality
|
|
723
|
+
* @param {Number} [config.pixelRatio] pixelRatio of output image url. Default is 1.
|
|
724
|
+
* You can use that property to increase quality of the image, for example for super hight quality exports
|
|
725
|
+
* or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
|
|
726
|
+
* If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
|
|
727
|
+
* @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
|
|
728
|
+
* @returns {String}
|
|
729
|
+
*/
|
|
221
730
|
toDataURL(config?: ImageConfig & {
|
|
222
731
|
callback?: (url: string) => void;
|
|
223
732
|
}): string;
|
|
733
|
+
/**
|
|
734
|
+
* converts node into an image. Since the toImage
|
|
735
|
+
* method is asynchronous, the resulting image can only be retrieved from the config callback
|
|
736
|
+
* or the returned Promise. toImage is most commonly used
|
|
737
|
+
* to cache complex drawings as an image so that they don't have to constantly be redrawn
|
|
738
|
+
* @method
|
|
739
|
+
* @name Konva.Node#toImage
|
|
740
|
+
* @param {Object} config
|
|
741
|
+
* @param {Function} [config.callback] function executed when the composite has completed
|
|
742
|
+
* @param {String} [config.mimeType] can be "image/png" or "image/jpeg".
|
|
743
|
+
* "image/png" is the default
|
|
744
|
+
* @param {Number} [config.x] x position of canvas section
|
|
745
|
+
* @param {Number} [config.y] y position of canvas section
|
|
746
|
+
* @param {Number} [config.width] width of canvas section
|
|
747
|
+
* @param {Number} [config.height] height of canvas section
|
|
748
|
+
* @param {Number} [config.quality] jpeg quality. If using an "image/jpeg" mimeType,
|
|
749
|
+
* you can specify the quality from 0 to 1, where 0 is very poor quality and 1
|
|
750
|
+
* is very high quality
|
|
751
|
+
* @param {Number} [config.pixelRatio] pixelRatio of output image. Default is 1.
|
|
752
|
+
* You can use that property to increase quality of the image, for example for super hight quality exports
|
|
753
|
+
* or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
|
|
754
|
+
* If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
|
|
755
|
+
* @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
|
|
756
|
+
* @return {Promise<Image>}
|
|
757
|
+
* @example
|
|
758
|
+
* var image = node.toImage({
|
|
759
|
+
* callback(img) {
|
|
760
|
+
* // do stuff with img
|
|
761
|
+
* }
|
|
762
|
+
* });
|
|
763
|
+
*/
|
|
224
764
|
toImage(config?: ImageConfig & {
|
|
225
765
|
callback?: (img: HTMLImageElement) => void;
|
|
226
766
|
}): Promise<HTMLImageElement>;
|
|
767
|
+
/**
|
|
768
|
+
* Converts node into a blob. Since the toBlob method is asynchronous,
|
|
769
|
+
* the resulting blob can only be retrieved from the config callback
|
|
770
|
+
* or the returned Promise.
|
|
771
|
+
* @method
|
|
772
|
+
* @name Konva.Node#toBlob
|
|
773
|
+
* @param {Object} config
|
|
774
|
+
* @param {Function} [config.callback] function executed when the composite has completed
|
|
775
|
+
* @param {Number} [config.x] x position of canvas section
|
|
776
|
+
* @param {Number} [config.y] y position of canvas section
|
|
777
|
+
* @param {Number} [config.width] width of canvas section
|
|
778
|
+
* @param {Number} [config.height] height of canvas section
|
|
779
|
+
* @param {Number} [config.pixelRatio] pixelRatio of output canvas. Default is 1.
|
|
780
|
+
* You can use that property to increase quality of the image, for example for super hight quality exports
|
|
781
|
+
* or usage on retina (or similar) displays. pixelRatio will be used to multiply the size of exported image.
|
|
782
|
+
* If you export to 500x500 size with pixelRatio = 2, then produced image will have size 1000x1000.
|
|
783
|
+
* @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
|
|
784
|
+
* @example
|
|
785
|
+
* var blob = await node.toBlob({});
|
|
786
|
+
* @returns {Promise<Blob>}
|
|
787
|
+
*/
|
|
227
788
|
toBlob(config?: ImageConfig & {
|
|
228
789
|
callback?: (blob: Blob | null) => void;
|
|
229
790
|
}): Promise<unknown>;
|
|
@@ -232,32 +793,124 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
232
793
|
width: number;
|
|
233
794
|
height: number;
|
|
234
795
|
};
|
|
796
|
+
/**
|
|
797
|
+
* get class name, which may return Stage, Layer, Group, or shape class names like Rect, Circle, Text, etc.
|
|
798
|
+
* @method
|
|
799
|
+
* @name Konva.Node#getClassName
|
|
800
|
+
* @returns {String}
|
|
801
|
+
*/
|
|
235
802
|
getClassName(): string;
|
|
803
|
+
/**
|
|
804
|
+
* get the node type, which may return Stage, Layer, Group, or Shape
|
|
805
|
+
* @method
|
|
806
|
+
* @name Konva.Node#getType
|
|
807
|
+
* @returns {String}
|
|
808
|
+
*/
|
|
236
809
|
getType(): string;
|
|
237
810
|
getDragDistance(): number;
|
|
238
811
|
_off(type: any, name?: any, callback?: any): void;
|
|
239
812
|
_fireChangeEvent(attr: any, oldVal: any, newVal: any): void;
|
|
813
|
+
/**
|
|
814
|
+
* add name to node
|
|
815
|
+
* @method
|
|
816
|
+
* @name Konva.Node#addName
|
|
817
|
+
* @param {String} name
|
|
818
|
+
* @returns {Konva.Node}
|
|
819
|
+
* @example
|
|
820
|
+
* node.name('red');
|
|
821
|
+
* node.addName('selected');
|
|
822
|
+
* node.name(); // return 'red selected'
|
|
823
|
+
*/
|
|
240
824
|
addName(name: string): this;
|
|
825
|
+
/**
|
|
826
|
+
* check is node has name
|
|
827
|
+
* @method
|
|
828
|
+
* @name Konva.Node#hasName
|
|
829
|
+
* @param {String} name
|
|
830
|
+
* @returns {Boolean}
|
|
831
|
+
* @example
|
|
832
|
+
* node.name('red');
|
|
833
|
+
* node.hasName('red'); // return true
|
|
834
|
+
* node.hasName('selected'); // return false
|
|
835
|
+
* node.hasName(''); // return false
|
|
836
|
+
*/
|
|
241
837
|
hasName(name: any): boolean;
|
|
838
|
+
/**
|
|
839
|
+
* remove name from node
|
|
840
|
+
* @method
|
|
841
|
+
* @name Konva.Node#removeName
|
|
842
|
+
* @param {String} name
|
|
843
|
+
* @returns {Konva.Node}
|
|
844
|
+
* @example
|
|
845
|
+
* node.name('red selected');
|
|
846
|
+
* node.removeName('selected');
|
|
847
|
+
* node.hasName('selected'); // return false
|
|
848
|
+
* node.name(); // return 'red'
|
|
849
|
+
*/
|
|
242
850
|
removeName(name: any): this;
|
|
851
|
+
/**
|
|
852
|
+
* set attr
|
|
853
|
+
* @method
|
|
854
|
+
* @name Konva.Node#setAttr
|
|
855
|
+
* @param {String} attr
|
|
856
|
+
* @param {*} val
|
|
857
|
+
* @returns {Konva.Node}
|
|
858
|
+
* @example
|
|
859
|
+
* node.setAttr('x', 5);
|
|
860
|
+
*/
|
|
243
861
|
setAttr<AttrConfig extends Config, K extends AnyString<keyof Config>>(attr: K, val: K extends keyof AttrConfig ? AttrConfig[K] : any): this;
|
|
244
862
|
_requestDraw(): void;
|
|
245
863
|
_setAttr<AttrConfig extends Config, K extends AnyString<keyof Config>>(key: K, val: K extends keyof AttrConfig ? AttrConfig[K] : any): void;
|
|
246
|
-
_setComponentAttr(key: any, component: any, val: any): void;
|
|
247
864
|
_fireAndBubble(eventType: any, evt: any, compareShape?: any): void;
|
|
248
|
-
static protoListenerMap:
|
|
865
|
+
static protoListenerMap: WeakMap<object, any>;
|
|
249
866
|
_getProtoListeners(eventType: any): any;
|
|
250
867
|
_fire(eventType: any, evt: any): void;
|
|
868
|
+
/**
|
|
869
|
+
* draw both scene and hit graphs. If the node being drawn is the stage, all of the layers will be cleared and redrawn
|
|
870
|
+
* @method
|
|
871
|
+
* @name Konva.Node#draw
|
|
872
|
+
* @returns {Konva.Node}
|
|
873
|
+
*/
|
|
251
874
|
draw(): this;
|
|
252
875
|
_createDragElement(evt: any): void;
|
|
876
|
+
/**
|
|
877
|
+
* initiate drag and drop.
|
|
878
|
+
* @method
|
|
879
|
+
* @name Konva.Node#startDrag
|
|
880
|
+
*/
|
|
253
881
|
startDrag(evt?: any, bubbleEvent?: boolean): void;
|
|
254
882
|
_setDragPosition(evt: any, elem: any): void;
|
|
883
|
+
/**
|
|
884
|
+
* stop drag and drop
|
|
885
|
+
* @method
|
|
886
|
+
* @name Konva.Node#stopDrag
|
|
887
|
+
*/
|
|
255
888
|
stopDrag(evt?: any): void;
|
|
256
889
|
setDraggable(draggable: any): void;
|
|
890
|
+
/**
|
|
891
|
+
* determine if node is currently in drag and drop mode
|
|
892
|
+
* @method
|
|
893
|
+
* @name Konva.Node#isDragging
|
|
894
|
+
*/
|
|
257
895
|
isDragging(): boolean;
|
|
258
896
|
_listenDrag(): void;
|
|
259
897
|
_dragChange(): void;
|
|
260
898
|
_dragCleanup(): void;
|
|
899
|
+
/**
|
|
900
|
+
* determine if node (at least partially) is currently in user-visible area
|
|
901
|
+
* @method
|
|
902
|
+
* @param {(Number | Object)} margin optional margin in pixels
|
|
903
|
+
* @param {Number} margin.x
|
|
904
|
+
* @param {Number} margin.y
|
|
905
|
+
* @returns {Boolean}
|
|
906
|
+
* @name Konva.Node#isClientRectOnScreen
|
|
907
|
+
* @example
|
|
908
|
+
* // get index
|
|
909
|
+
* // default calculations
|
|
910
|
+
* var isOnScreen = node.isClientRectOnScreen()
|
|
911
|
+
* // increase object size (or screen size) for cases when objects close to the screen still need to be marked as "visible"
|
|
912
|
+
* var isOnScreen = node.isClientRectOnScreen({ x: stage.width(), y: stage.height() })
|
|
913
|
+
*/
|
|
261
914
|
isClientRectOnScreen(margin?: {
|
|
262
915
|
x: number;
|
|
263
916
|
y: number;
|
|
@@ -310,7 +963,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
310
963
|
skew: GetSet<Vector2d, this>;
|
|
311
964
|
skewX: GetSet<number, this>;
|
|
312
965
|
skewY: GetSet<number, this>;
|
|
313
|
-
to: (params:
|
|
966
|
+
to: (params: Omit<TweenConfig, 'node'>) => Tween;
|
|
314
967
|
transformsEnabled: GetSet<string, this>;
|
|
315
968
|
visible: GetSet<boolean, this>;
|
|
316
969
|
width: GetSet<number, this>;
|
|
@@ -318,12 +971,21 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
318
971
|
x: GetSet<number, this>;
|
|
319
972
|
y: GetSet<number, this>;
|
|
320
973
|
globalCompositeOperation: GetSet<globalCompositeOperationType, this>;
|
|
974
|
+
/**
|
|
975
|
+
* create node with JSON string or an Object. Deserialization restores attributes only,
|
|
976
|
+
* not functions, images or event handlers (that would make the serialized object huge):
|
|
977
|
+
* `sceneFunc`/`hitFunc` of custom shapes, images and `fillPatternImage`, `clipFunc`,
|
|
978
|
+
* `dragBoundFunc`, filter functions, the `nodes`, `boundBoxFunc` and `anchorStyleFunc`
|
|
979
|
+
* of a Transformer, typed arrays and the `cache()` state. If your app uses them (it probably
|
|
980
|
+
* does), select the nodes after loading the stage and set these properties again with
|
|
981
|
+
* `on()`, `sceneFunc()`, `image()` and so on
|
|
982
|
+
* @method
|
|
983
|
+
* @memberof Konva.Node
|
|
984
|
+
* @param {String|Object} data string or object
|
|
985
|
+
* @param {Element} [container] optional container dom element used only if you're
|
|
986
|
+
* creating a stage node
|
|
987
|
+
*/
|
|
321
988
|
static create(data: any, container?: any): any;
|
|
322
989
|
static _createNode(obj: any, container?: any): any;
|
|
323
990
|
}
|
|
324
|
-
interface AnimTo extends NodeConfig {
|
|
325
|
-
onFinish?: Function;
|
|
326
|
-
onUpdate?: Function;
|
|
327
|
-
duration?: number;
|
|
328
|
-
}
|
|
329
991
|
export {};
|