konva 10.8.0 → 10.9.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/konva.js +165 -112
- package/konva.min.js +4 -4
- package/lib/Animation.js +13 -10
- package/lib/Container.d.ts +1 -0
- package/lib/Container.js +22 -32
- package/lib/Global.js +2 -2
- package/lib/Node.d.ts +6 -3
- package/lib/Node.js +53 -20
- package/lib/_CoreInternals.d.ts +26 -0
- package/lib/_CoreInternals.js +26 -0
- package/lib/_FullInternals.d.ts +1 -0
- package/lib/shapes/Transformer.d.ts +5 -3
- package/lib/shapes/Transformer.js +49 -47
- package/package.json +1 -1
package/lib/Animation.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
import { glob } from "./Global.js";
|
|
3
|
+
import { Node } from "./Node.js";
|
|
3
4
|
import { Util } from "./Util.js";
|
|
4
5
|
const now = ((_a = glob.performance) === null || _a === void 0 ? void 0 : _a.now)
|
|
5
6
|
? () => glob.performance.now()
|
|
@@ -128,16 +129,18 @@ export class Animation {
|
|
|
128
129
|
const layersToDraw = new Set();
|
|
129
130
|
// an animation may stop or restart itself, or another one, inside its
|
|
130
131
|
// function: each one runs at most once per frame, a stopped one not at all
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
Node._updateBatch(() => {
|
|
133
|
+
Array.from(this.animations).forEach((anim) => {
|
|
134
|
+
if (!this.animations.has(anim)) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
anim._updateFrameObject(now());
|
|
138
|
+
// the function returns false to skip the redraw
|
|
139
|
+
if (anim.func && anim.func.call(anim, anim.frame) === false) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
anim.layers.forEach((layer) => layer && layersToDraw.add(layer));
|
|
143
|
+
});
|
|
141
144
|
});
|
|
142
145
|
layersToDraw.forEach((layer) => layer.batchDraw());
|
|
143
146
|
}
|
package/lib/Container.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export declare abstract class Container<ChildType extends Node = Node, Config ex
|
|
|
61
61
|
* @name Konva.Container#destroyChildren
|
|
62
62
|
*/
|
|
63
63
|
destroyChildren(): this;
|
|
64
|
+
_clearChildren(dispose: 'remove' | 'destroy'): this;
|
|
64
65
|
abstract _validateAdd(node: Node): void;
|
|
65
66
|
/**
|
|
66
67
|
* add a child and children into container
|
package/lib/Container.js
CHANGED
|
@@ -52,17 +52,7 @@ export class Container extends Node {
|
|
|
52
52
|
* @name Konva.Container#removeChildren
|
|
53
53
|
*/
|
|
54
54
|
removeChildren() {
|
|
55
|
-
this.
|
|
56
|
-
// reset parent to prevent many _setChildrenIndices calls
|
|
57
|
-
child.parent = null;
|
|
58
|
-
child.index = 0;
|
|
59
|
-
child.remove();
|
|
60
|
-
});
|
|
61
|
-
this.children = [];
|
|
62
|
-
// because all children were detached from parent, request draw via container
|
|
63
|
-
this._notifySubtreeChange();
|
|
64
|
-
this._requestDraw();
|
|
65
|
-
return this;
|
|
55
|
+
return this._clearChildren('remove');
|
|
66
56
|
}
|
|
67
57
|
/**
|
|
68
58
|
* destroy all children nodes.
|
|
@@ -70,17 +60,22 @@ export class Container extends Node {
|
|
|
70
60
|
* @name Konva.Container#destroyChildren
|
|
71
61
|
*/
|
|
72
62
|
destroyChildren() {
|
|
73
|
-
this.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
return this._clearChildren('destroy');
|
|
64
|
+
}
|
|
65
|
+
_clearChildren(dispose) {
|
|
66
|
+
return Node._updateBatch(() => {
|
|
67
|
+
this.children.forEach((child) => {
|
|
68
|
+
// reset parent to prevent many _setChildrenIndices calls
|
|
69
|
+
child.parent = null;
|
|
70
|
+
child.index = 0;
|
|
71
|
+
child[dispose]();
|
|
72
|
+
});
|
|
73
|
+
this.children = [];
|
|
74
|
+
// because all children were detached from parent, request draw via container
|
|
75
|
+
this._notifySubtreeChange();
|
|
76
|
+
this._requestDraw();
|
|
77
|
+
return this;
|
|
78
78
|
});
|
|
79
|
-
this.children = [];
|
|
80
|
-
// because all children were detached from parent, request draw via container
|
|
81
|
-
this._notifySubtreeChange();
|
|
82
|
-
this._requestDraw();
|
|
83
|
-
return this;
|
|
84
79
|
}
|
|
85
80
|
/**
|
|
86
81
|
* add a child and children into container
|
|
@@ -285,12 +280,12 @@ export class Container extends Node {
|
|
|
285
280
|
}
|
|
286
281
|
_clearSelfAndDescendantCache(attr) {
|
|
287
282
|
var _a;
|
|
288
|
-
// Perf:
|
|
289
|
-
//
|
|
290
|
-
//
|
|
283
|
+
// Perf: an absoluteTransform cascade is an update batch, so a listener on
|
|
284
|
+
// one of N descendants defers its work until the outermost walk returns.
|
|
285
|
+
// try/finally so depth/flush survive listener exceptions.
|
|
291
286
|
const isAbsTransform = attr === undefined || attr === 'absoluteTransform';
|
|
292
287
|
if (isAbsTransform)
|
|
293
|
-
Node.
|
|
288
|
+
Node._updateBatchDepth++;
|
|
294
289
|
try {
|
|
295
290
|
super._clearSelfAndDescendantCache(attr);
|
|
296
291
|
// a cached container is drawn from its bitmap, so its descendants keep
|
|
@@ -303,13 +298,8 @@ export class Container extends Node {
|
|
|
303
298
|
});
|
|
304
299
|
}
|
|
305
300
|
finally {
|
|
306
|
-
if (isAbsTransform && --Node.
|
|
307
|
-
|
|
308
|
-
if (callbacks.length) {
|
|
309
|
-
Node._pendingAfterCascade = [];
|
|
310
|
-
for (let i = 0; i < callbacks.length; i++)
|
|
311
|
-
callbacks[i]();
|
|
312
|
-
}
|
|
301
|
+
if (isAbsTransform && --Node._updateBatchDepth === 0) {
|
|
302
|
+
Node._flushUpdateBatch();
|
|
313
303
|
}
|
|
314
304
|
}
|
|
315
305
|
}
|
package/lib/Global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Konva JavaScript Framework v10.
|
|
2
|
+
* Konva JavaScript Framework v10.9.0
|
|
3
3
|
* http://konvajs.org/
|
|
4
4
|
* Licensed under the MIT
|
|
5
5
|
* Date: @@date
|
|
@@ -29,7 +29,7 @@ export const glob = typeof global !== 'undefined'
|
|
|
29
29
|
: {};
|
|
30
30
|
export const Konva = {
|
|
31
31
|
_global: glob,
|
|
32
|
-
version: '10.
|
|
32
|
+
version: '10.9.0',
|
|
33
33
|
isBrowser: detectBrowser(),
|
|
34
34
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
35
35
|
dblClickWindow: 400,
|
package/lib/Node.d.ts
CHANGED
|
@@ -139,9 +139,12 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
139
139
|
y: number;
|
|
140
140
|
} | null;
|
|
141
141
|
_clearSelfAndDescendantCache(attr?: string): void;
|
|
142
|
-
static
|
|
143
|
-
static
|
|
144
|
-
static
|
|
142
|
+
static _updateBatchDepth: number;
|
|
143
|
+
static _pendingUpdates: Set<() => void>;
|
|
144
|
+
static _runAfterUpdateBatch(cb: () => void): void;
|
|
145
|
+
static _flushUpdateBatch(): void;
|
|
146
|
+
static _updateBatch<T>(fn: () => T): T;
|
|
147
|
+
static _beginUpdateBatch(): () => void;
|
|
145
148
|
/**
|
|
146
149
|
* clear cached canvas
|
|
147
150
|
* @method
|
package/lib/Node.js
CHANGED
|
@@ -186,14 +186,44 @@ export class Node {
|
|
|
186
186
|
this.fire('absoluteTransformChange');
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
static
|
|
190
|
-
if (Node.
|
|
191
|
-
Node.
|
|
189
|
+
static _runAfterUpdateBatch(cb) {
|
|
190
|
+
if (Node._updateBatchDepth > 0) {
|
|
191
|
+
Node._pendingUpdates.add(cb);
|
|
192
192
|
}
|
|
193
193
|
else {
|
|
194
194
|
cb();
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
+
static _flushUpdateBatch() {
|
|
198
|
+
if (Node._updateBatchDepth > 0)
|
|
199
|
+
return;
|
|
200
|
+
const callbacks = Node._pendingUpdates;
|
|
201
|
+
if (!callbacks.size)
|
|
202
|
+
return;
|
|
203
|
+
Node._pendingUpdates = new Set();
|
|
204
|
+
callbacks.forEach((callback) => callback());
|
|
205
|
+
}
|
|
206
|
+
static _updateBatch(fn) {
|
|
207
|
+
Node._updateBatchDepth++;
|
|
208
|
+
try {
|
|
209
|
+
return fn();
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
Node._updateBatchDepth--;
|
|
213
|
+
Node._flushUpdateBatch();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
static _beginUpdateBatch() {
|
|
217
|
+
Node._updateBatchDepth++;
|
|
218
|
+
let finished = false;
|
|
219
|
+
return () => {
|
|
220
|
+
if (finished)
|
|
221
|
+
return;
|
|
222
|
+
finished = true;
|
|
223
|
+
Node._updateBatchDepth--;
|
|
224
|
+
Node._flushUpdateBatch();
|
|
225
|
+
};
|
|
226
|
+
}
|
|
197
227
|
/**
|
|
198
228
|
* clear cached canvas
|
|
199
229
|
* @method
|
|
@@ -984,18 +1014,20 @@ export class Node {
|
|
|
984
1014
|
func();
|
|
985
1015
|
return;
|
|
986
1016
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
finally {
|
|
992
|
-
this._batchingTransformChange = false;
|
|
993
|
-
if (this._needClearTransformCache) {
|
|
994
|
-
this._needClearTransformCache = false;
|
|
995
|
-
this._clearCache(TRANSFORM);
|
|
996
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
1017
|
+
Node._updateBatch(() => {
|
|
1018
|
+
this._batchingTransformChange = true;
|
|
1019
|
+
try {
|
|
1020
|
+
func();
|
|
997
1021
|
}
|
|
998
|
-
|
|
1022
|
+
finally {
|
|
1023
|
+
this._batchingTransformChange = false;
|
|
1024
|
+
if (this._needClearTransformCache) {
|
|
1025
|
+
this._needClearTransformCache = false;
|
|
1026
|
+
this._clearCache(TRANSFORM);
|
|
1027
|
+
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
999
1031
|
}
|
|
1000
1032
|
setPosition(pos) {
|
|
1001
1033
|
this._batchTransformChanges(() => {
|
|
@@ -2412,12 +2444,13 @@ export class Node {
|
|
|
2412
2444
|
}
|
|
2413
2445
|
// Number of registered observers. The ancestor walk is skipped while it is 0.
|
|
2414
2446
|
Node._subtreeObserverCount = 0;
|
|
2415
|
-
// Perf:
|
|
2416
|
-
// .Transformer
|
|
2417
|
-
//
|
|
2418
|
-
//
|
|
2419
|
-
Node.
|
|
2420
|
-
|
|
2447
|
+
// Perf: while a batch is open, work that depends on many nodes (a Konva
|
|
2448
|
+
// .Transformer refresh) is queued and runs once when the outermost scope
|
|
2449
|
+
// ends, instead of once per node change. Scopes are the callers of
|
|
2450
|
+
// _updateBatch() and _beginUpdateBatch().
|
|
2451
|
+
Node._updateBatchDepth = 0;
|
|
2452
|
+
// a Set, so a callback queued once per change runs once per batch
|
|
2453
|
+
Node._pendingUpdates = new Set();
|
|
2421
2454
|
// keyed by prototype: subclasses that share a nodeType (every shape class)
|
|
2422
2455
|
// have their own listeners
|
|
2423
2456
|
Node.protoListenerMap = new WeakMap();
|
package/lib/_CoreInternals.d.ts
CHANGED
|
@@ -36,6 +36,32 @@ export declare const Konva: {
|
|
|
36
36
|
document: any;
|
|
37
37
|
_injectGlobal(Konva: any): void;
|
|
38
38
|
} & {
|
|
39
|
+
/**
|
|
40
|
+
* Defer automatic Konva.Transformer updates across many synchronous node changes
|
|
41
|
+
* and run them once when the returned function is called.
|
|
42
|
+
* A Transformer normally updates after every change of an attached node, so a loop
|
|
43
|
+
* over N selected nodes costs N updates, each measuring all N nodes. In a batch it costs one.
|
|
44
|
+
* A single setAttrs(), position(), destroyChildren(), removeChildren() call or animation frame is
|
|
45
|
+
* already batched; use this for anything else, for example a React commit or an undo.
|
|
46
|
+
* Attributes and change events stay synchronous. Inside the batch, the Transformer's own
|
|
47
|
+
* x(), y(), width(), height() and getClientRect() are computed on read; its anchors are laid out
|
|
48
|
+
* when the batch finishes, or earlier if something draws or measures them.
|
|
49
|
+
* Change events fire inside the batch, so a listener sees the new attributes and the
|
|
50
|
+
* Transformer's box, but not its anchors; call transformer.update() there if it needs them.
|
|
51
|
+
* Batches nest. Call the returned function in a finally block, and do not keep a batch
|
|
52
|
+
* open across an await or an animation frame.
|
|
53
|
+
* @method
|
|
54
|
+
* @name Konva.beginUpdateBatch
|
|
55
|
+
* @returns {Function} finishes the batch and runs the pending updates
|
|
56
|
+
* @example
|
|
57
|
+
* const finish = Konva.beginUpdateBatch();
|
|
58
|
+
* try {
|
|
59
|
+
* selectedNodes.forEach((node) => node.width(100));
|
|
60
|
+
* } finally {
|
|
61
|
+
* finish();
|
|
62
|
+
* }
|
|
63
|
+
*/
|
|
64
|
+
beginUpdateBatch: typeof Node._beginUpdateBatch;
|
|
39
65
|
Util: {
|
|
40
66
|
_isElement(obj: any): obj is Element;
|
|
41
67
|
_isFunction(obj: any): boolean;
|
package/lib/_CoreInternals.js
CHANGED
|
@@ -14,6 +14,32 @@ import { Tween, Easings } from "./Tween.js";
|
|
|
14
14
|
import { Context } from "./Context.js";
|
|
15
15
|
import { Canvas } from "./Canvas.js";
|
|
16
16
|
export const Konva = Util._assign(Global, {
|
|
17
|
+
/**
|
|
18
|
+
* Defer automatic Konva.Transformer updates across many synchronous node changes
|
|
19
|
+
* and run them once when the returned function is called.
|
|
20
|
+
* A Transformer normally updates after every change of an attached node, so a loop
|
|
21
|
+
* over N selected nodes costs N updates, each measuring all N nodes. In a batch it costs one.
|
|
22
|
+
* A single setAttrs(), position(), destroyChildren(), removeChildren() call or animation frame is
|
|
23
|
+
* already batched; use this for anything else, for example a React commit or an undo.
|
|
24
|
+
* Attributes and change events stay synchronous. Inside the batch, the Transformer's own
|
|
25
|
+
* x(), y(), width(), height() and getClientRect() are computed on read; its anchors are laid out
|
|
26
|
+
* when the batch finishes, or earlier if something draws or measures them.
|
|
27
|
+
* Change events fire inside the batch, so a listener sees the new attributes and the
|
|
28
|
+
* Transformer's box, but not its anchors; call transformer.update() there if it needs them.
|
|
29
|
+
* Batches nest. Call the returned function in a finally block, and do not keep a batch
|
|
30
|
+
* open across an await or an animation frame.
|
|
31
|
+
* @method
|
|
32
|
+
* @name Konva.beginUpdateBatch
|
|
33
|
+
* @returns {Function} finishes the batch and runs the pending updates
|
|
34
|
+
* @example
|
|
35
|
+
* const finish = Konva.beginUpdateBatch();
|
|
36
|
+
* try {
|
|
37
|
+
* selectedNodes.forEach((node) => node.width(100));
|
|
38
|
+
* } finally {
|
|
39
|
+
* finish();
|
|
40
|
+
* }
|
|
41
|
+
*/
|
|
42
|
+
beginUpdateBatch: Node._beginUpdateBatch,
|
|
17
43
|
Util,
|
|
18
44
|
Transform,
|
|
19
45
|
Node,
|
package/lib/_FullInternals.d.ts
CHANGED
|
@@ -115,9 +115,8 @@ export declare class Transformer extends Group {
|
|
|
115
115
|
cos: number;
|
|
116
116
|
_cursorChange: boolean;
|
|
117
117
|
_elementsCreated: boolean;
|
|
118
|
-
_updateScheduled: boolean;
|
|
119
118
|
_lastNodeRect?: Readonly<Box>;
|
|
120
|
-
|
|
119
|
+
_updatePending: boolean;
|
|
121
120
|
static isTransforming: () => boolean;
|
|
122
121
|
static _isLayerTransforming(layer: Node): boolean;
|
|
123
122
|
constructor(config?: TransformerConfig);
|
|
@@ -135,6 +134,9 @@ export declare class Transformer extends Group {
|
|
|
135
134
|
_getEventNamespace(): string;
|
|
136
135
|
setNodes(nodes?: Array<Node>): this;
|
|
137
136
|
_proxyDrag(node: Node): void;
|
|
137
|
+
_detachNode(node: Node): void;
|
|
138
|
+
_resetRotation(): void;
|
|
139
|
+
_removeNode(node: Node): void;
|
|
138
140
|
getNodes(): Node<import("../Node.ts").NodeConfig>[];
|
|
139
141
|
/**
|
|
140
142
|
* return the name of current active anchor
|
|
@@ -169,7 +171,7 @@ export declare class Transformer extends Group {
|
|
|
169
171
|
*/
|
|
170
172
|
_resetTransformCache(changedNode?: Node): void;
|
|
171
173
|
_onSubtreeChange(node: Node): void;
|
|
172
|
-
|
|
174
|
+
_syncUpdate(): void;
|
|
173
175
|
drawScene(can?: SceneCanvas, top?: Node): this;
|
|
174
176
|
drawHit(can?: HitCanvas, top?: Node): this;
|
|
175
177
|
_getNodeRect(): any;
|
|
@@ -289,14 +289,14 @@ export class Transformer extends Group {
|
|
|
289
289
|
// rendered in another window than the one Konva was imported into
|
|
290
290
|
this._transformWindow = null;
|
|
291
291
|
this._elementsCreated = false;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
this._subtreeChanged = false;
|
|
292
|
+
// the layout is stale; the next sync point runs _update() (see _syncUpdate)
|
|
293
|
+
this._updatePending = false;
|
|
295
294
|
this._createElements();
|
|
296
295
|
// bindings
|
|
297
296
|
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
298
297
|
this._handleMouseUp = this._handleMouseUp.bind(this);
|
|
299
298
|
this.update = this.update.bind(this);
|
|
299
|
+
this._syncUpdate = this._syncUpdate.bind(this);
|
|
300
300
|
// update transformer data for certain attr changes
|
|
301
301
|
this.on(ATTR_CHANGE_LIST, (event) => {
|
|
302
302
|
if (event.type === 'ignoreStrokeChange')
|
|
@@ -352,12 +352,7 @@ export class Transformer extends Group {
|
|
|
352
352
|
return true;
|
|
353
353
|
});
|
|
354
354
|
this._nodes = nodes = filteredNodes;
|
|
355
|
-
|
|
356
|
-
this.rotation(nodes[0].getAbsoluteRotation());
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
this.rotation(0);
|
|
360
|
-
}
|
|
355
|
+
this._resetRotation();
|
|
361
356
|
this._nodes.forEach((node) => {
|
|
362
357
|
const onChange = () => {
|
|
363
358
|
var _a;
|
|
@@ -369,6 +364,7 @@ export class Transformer extends Group {
|
|
|
369
364
|
(_a = this._nodeRectCache) === null || _a === void 0 ? void 0 : _a.delete(node);
|
|
370
365
|
return;
|
|
371
366
|
}
|
|
367
|
+
// unlike _resetRotation, a multi-node box keeps its rotation here
|
|
372
368
|
if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
|
|
373
369
|
this.rotation(this.nodes()[0].getAbsoluteRotation());
|
|
374
370
|
}
|
|
@@ -393,8 +389,7 @@ export class Transformer extends Group {
|
|
|
393
389
|
if (node instanceof Container)
|
|
394
390
|
node._addSubtreeObserver(this);
|
|
395
391
|
node.on(`destroy.${this._getEventNamespace()}`, () => {
|
|
396
|
-
|
|
397
|
-
this.setNodes(this._nodes.filter((n) => n !== node));
|
|
392
|
+
this._removeNode(node);
|
|
398
393
|
});
|
|
399
394
|
this._proxyDrag(node);
|
|
400
395
|
});
|
|
@@ -440,6 +435,23 @@ export class Transformer extends Group {
|
|
|
440
435
|
lastPos = null;
|
|
441
436
|
});
|
|
442
437
|
}
|
|
438
|
+
_detachNode(node) {
|
|
439
|
+
node.off('.' + this._getEventNamespace());
|
|
440
|
+
node._removeSubtreeObserver(this);
|
|
441
|
+
}
|
|
442
|
+
_resetRotation() {
|
|
443
|
+
const single = this._nodes.length === 1 && this.useSingleNodeRotation();
|
|
444
|
+
this.rotation(single ? this._nodes[0].getAbsoluteRotation() : 0);
|
|
445
|
+
}
|
|
446
|
+
// Drops one destroyed node. Re-attaching the survivors instead costs
|
|
447
|
+
// O(N) listener rebinds per destroyed node, O(N^2) for a deleted selection.
|
|
448
|
+
_removeNode(node) {
|
|
449
|
+
this._detachNode(node);
|
|
450
|
+
this._nodes = this._nodes.filter((n) => n !== node);
|
|
451
|
+
this._resetRotation();
|
|
452
|
+
this._resetTransformCache(node);
|
|
453
|
+
this._scheduleUpdate();
|
|
454
|
+
}
|
|
443
455
|
getNodes() {
|
|
444
456
|
return this._nodes || [];
|
|
445
457
|
}
|
|
@@ -463,17 +475,12 @@ export class Transformer extends Group {
|
|
|
463
475
|
* transformer.detach();
|
|
464
476
|
*/
|
|
465
477
|
detach() {
|
|
466
|
-
var _a;
|
|
467
|
-
|
|
468
|
-
if (this._nodes) {
|
|
469
|
-
this._nodes.forEach((node) => {
|
|
470
|
-
node.off('.' + this._getEventNamespace());
|
|
471
|
-
node._removeSubtreeObserver(this);
|
|
472
|
-
});
|
|
473
|
-
}
|
|
478
|
+
var _a, _b;
|
|
479
|
+
(_a = this._nodes) === null || _a === void 0 ? void 0 : _a.forEach((node) => this._detachNode(node));
|
|
474
480
|
this._nodes = [];
|
|
481
|
+
this._updatePending = false;
|
|
475
482
|
this._resetTransformCache();
|
|
476
|
-
(
|
|
483
|
+
(_b = this.getLayer()) === null || _b === void 0 ? void 0 : _b.batchDraw();
|
|
477
484
|
}
|
|
478
485
|
/**
|
|
479
486
|
* bind events to the Transformer. You can use events: `transform`, `transformstart`, `transformend`, `dragstart`, `dragmove`, `dragend`
|
|
@@ -501,37 +508,42 @@ export class Transformer extends Group {
|
|
|
501
508
|
// Called for every change below an attached container. A burst of child
|
|
502
509
|
// changes only drops cached values here. The new bounds are measured once,
|
|
503
510
|
// before the next frame, or earlier if a draw or transform step comes first
|
|
504
|
-
// (
|
|
511
|
+
// (_syncUpdate).
|
|
505
512
|
_onSubtreeChange(node) {
|
|
506
513
|
var _a, _b;
|
|
507
514
|
if (this._fitting)
|
|
508
515
|
return;
|
|
509
516
|
// nothing was measured since the last change, so nothing cached is stale
|
|
510
|
-
|
|
517
|
+
const measured = !this._updatePending || !!this._cache[NODES_RECT];
|
|
518
|
+
if (measured)
|
|
519
|
+
this._resetTransformCache(node);
|
|
520
|
+
if (Node._updateBatchDepth > 0) {
|
|
521
|
+
// the batch flush lays the new bounds out, no frame needed
|
|
522
|
+
this._scheduleUpdate();
|
|
511
523
|
return;
|
|
512
|
-
|
|
513
|
-
if (!this.
|
|
514
|
-
this.
|
|
524
|
+
}
|
|
525
|
+
if (!this._updatePending) {
|
|
526
|
+
this._updatePending = true;
|
|
515
527
|
// queued ahead of the draw the change requests, so that draw shows the
|
|
516
528
|
// new layout. Updating inside the draw would request one more frame.
|
|
517
|
-
Util.requestAnimFrame(
|
|
529
|
+
Util.requestAnimFrame(this._syncUpdate, (_a = this.getStage()) === null || _a === void 0 ? void 0 : _a._getOwnerWindow());
|
|
518
530
|
// the transformer can be on another layer than the changed node
|
|
519
531
|
(_b = this.getLayer()) === null || _b === void 0 ? void 0 : _b.batchDraw();
|
|
520
532
|
}
|
|
521
533
|
}
|
|
522
|
-
|
|
523
|
-
|
|
534
|
+
// Runs a deferred update before anything draws or measures the anchors.
|
|
535
|
+
_syncUpdate() {
|
|
524
536
|
// while dragging, the dragmove handler updates the layout
|
|
525
|
-
if (this.
|
|
537
|
+
if (this._updatePending && !this._fitting && !this.isDragging()) {
|
|
526
538
|
this._update();
|
|
527
539
|
}
|
|
528
540
|
}
|
|
529
541
|
drawScene(can, top) {
|
|
530
|
-
this.
|
|
542
|
+
this._syncUpdate();
|
|
531
543
|
return super.drawScene(can, top);
|
|
532
544
|
}
|
|
533
545
|
drawHit(can, top) {
|
|
534
|
-
this.
|
|
546
|
+
this._syncUpdate();
|
|
535
547
|
return super.drawHit(can, top);
|
|
536
548
|
}
|
|
537
549
|
_getNodeRect() {
|
|
@@ -818,7 +830,7 @@ export class Transformer extends Group {
|
|
|
818
830
|
}
|
|
819
831
|
_moveTransform(e) {
|
|
820
832
|
// anchors must show the current bounds before they are measured against
|
|
821
|
-
this.
|
|
833
|
+
this._syncUpdate();
|
|
822
834
|
let x, y, newHypotenuse;
|
|
823
835
|
const anchorNode = this._anchors[this._movingAnchorName];
|
|
824
836
|
const stage = anchorNode.getStage();
|
|
@@ -1252,21 +1264,10 @@ export class Transformer extends Group {
|
|
|
1252
1264
|
layersToDraw.add(this.getLayer());
|
|
1253
1265
|
layersToDraw.forEach((layer) => layer && layer.batchDraw());
|
|
1254
1266
|
}
|
|
1255
|
-
//
|
|
1256
|
-
// the cascade ends; outside a cascade, run synchronously so reads of
|
|
1257
|
-
// transformer state stay consistent.
|
|
1267
|
+
// deferred to the batch flush when one is open, else synchronous
|
|
1258
1268
|
_scheduleUpdate() {
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
this._updateScheduled = true;
|
|
1262
|
-
Node._runAfterAbsTransformCascade(() => {
|
|
1263
|
-
var _a;
|
|
1264
|
-
this._updateScheduled = false;
|
|
1265
|
-
if (!((_a = this._nodes) === null || _a === void 0 ? void 0 : _a.length) || this._fitting || this.isDragging()) {
|
|
1266
|
-
return;
|
|
1267
|
-
}
|
|
1268
|
-
this._update();
|
|
1269
|
-
});
|
|
1269
|
+
this._updatePending = true;
|
|
1270
|
+
Node._runAfterUpdateBatch(this._syncUpdate);
|
|
1270
1271
|
}
|
|
1271
1272
|
/**
|
|
1272
1273
|
* force update of Konva.Transformer.
|
|
@@ -1288,7 +1289,7 @@ export class Transformer extends Group {
|
|
|
1288
1289
|
}
|
|
1289
1290
|
_update() {
|
|
1290
1291
|
var _a;
|
|
1291
|
-
this.
|
|
1292
|
+
this._updatePending = false;
|
|
1292
1293
|
const attrs = this._getNodeRect();
|
|
1293
1294
|
this._updateElements(attrs);
|
|
1294
1295
|
const draggable = this.nodes().some((node) => node.draggable());
|
|
@@ -1468,6 +1469,7 @@ export class Transformer extends Group {
|
|
|
1468
1469
|
return node;
|
|
1469
1470
|
}
|
|
1470
1471
|
getClientRect(config) {
|
|
1472
|
+
this._syncUpdate();
|
|
1471
1473
|
if (this.nodes().length > 0) {
|
|
1472
1474
|
return super.getClientRect(config);
|
|
1473
1475
|
}
|