konva 10.7.0 → 10.7.1
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 +87 -4
- package/konva.min.js +4 -4
- package/lib/Container.js +4 -0
- package/lib/Global.js +2 -2
- package/lib/Node.d.ts +8 -0
- package/lib/Node.js +34 -1
- package/lib/shapes/Transformer.d.ts +10 -2
- package/lib/shapes/Transformer.js +48 -1
- package/package.json +1 -1
package/lib/Container.js
CHANGED
|
@@ -60,6 +60,7 @@ export class Container extends Node {
|
|
|
60
60
|
});
|
|
61
61
|
this.children = [];
|
|
62
62
|
// because all children were detached from parent, request draw via container
|
|
63
|
+
this._notifySubtreeChange();
|
|
63
64
|
this._requestDraw();
|
|
64
65
|
return this;
|
|
65
66
|
}
|
|
@@ -77,6 +78,7 @@ export class Container extends Node {
|
|
|
77
78
|
});
|
|
78
79
|
this.children = [];
|
|
79
80
|
// because all children were detached from parent, request draw via container
|
|
81
|
+
this._notifySubtreeChange();
|
|
80
82
|
this._requestDraw();
|
|
81
83
|
return this;
|
|
82
84
|
}
|
|
@@ -115,6 +117,7 @@ export class Container extends Node {
|
|
|
115
117
|
this._fire('add', {
|
|
116
118
|
child: child,
|
|
117
119
|
});
|
|
120
|
+
this._notifySubtreeChange();
|
|
118
121
|
this._requestDraw();
|
|
119
122
|
// chainable
|
|
120
123
|
return this;
|
|
@@ -315,6 +318,7 @@ export class Container extends Node {
|
|
|
315
318
|
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child, n) {
|
|
316
319
|
child.index = n;
|
|
317
320
|
});
|
|
321
|
+
this._notifySubtreeChange();
|
|
318
322
|
this._requestDraw();
|
|
319
323
|
}
|
|
320
324
|
drawScene(can, top) {
|
package/lib/Global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Konva JavaScript Framework v10.7.
|
|
2
|
+
* Konva JavaScript Framework v10.7.1
|
|
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.7.
|
|
32
|
+
version: '10.7.1',
|
|
33
33
|
isBrowser: detectBrowser(),
|
|
34
34
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
35
35
|
dblClickWindow: 400,
|
package/lib/Node.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ import { Transform, type AnyString } from './Util.ts';
|
|
|
11
11
|
export type FilterFunction = (this: Node, imageData: ImageData, pixelRatio?: number) => void;
|
|
12
12
|
export type Filter = FilterFunction | string;
|
|
13
13
|
type Filters = Array<FilterFunction | string>;
|
|
14
|
+
type SubtreeObserver = {
|
|
15
|
+
_onSubtreeChange(node: Node): void;
|
|
16
|
+
};
|
|
14
17
|
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';
|
|
15
18
|
export type NodeConfig = {
|
|
16
19
|
x?: number;
|
|
@@ -108,6 +111,8 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
108
111
|
} | null;
|
|
109
112
|
_attrsAffectingSize: string[];
|
|
110
113
|
_attrsVersion?: number;
|
|
114
|
+
_subtreeObservers?: Set<SubtreeObserver>;
|
|
115
|
+
static _subtreeObserverCount: number;
|
|
111
116
|
_batchingTransformChange: boolean;
|
|
112
117
|
_needClearTransformCache: boolean;
|
|
113
118
|
_filterUpToDate: boolean;
|
|
@@ -871,6 +876,9 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
871
876
|
* node.setAttr('x', 5);
|
|
872
877
|
*/
|
|
873
878
|
setAttr<AttrConfig extends Config, K extends AnyString<keyof Config>>(attr: K, val: K extends keyof AttrConfig ? AttrConfig[K] : any): this;
|
|
879
|
+
_addSubtreeObserver(observer: SubtreeObserver): void;
|
|
880
|
+
_removeSubtreeObserver(observer: SubtreeObserver): void;
|
|
881
|
+
_notifySubtreeChange(): void;
|
|
874
882
|
_requestDraw(): void;
|
|
875
883
|
_setAttr<AttrConfig extends Config, K extends AnyString<keyof Config>>(key: K, val: K extends keyof AttrConfig ? AttrConfig[K] : any): void;
|
|
876
884
|
_fireAndBubble(eventType: any, evt: any, compareShape?: any): void;
|
package/lib/Node.js
CHANGED
|
@@ -4,7 +4,7 @@ import { DD } from "./DragAndDrop.js";
|
|
|
4
4
|
import * as PointerEvents from "./PointerEvents.js";
|
|
5
5
|
import { Factory } from "./Factory.js";
|
|
6
6
|
import { Konva } from "./Global.js";
|
|
7
|
-
import { Transform, Util } from "./Util.js";
|
|
7
|
+
import { Transform, TypedArray, Util } from "./Util.js";
|
|
8
8
|
import { getBooleanValidator, getNumberValidator, getStringValidator, } from "./Validators.js";
|
|
9
9
|
// CSS filter parser for fallback to function filters.
|
|
10
10
|
function parseCSSFilters(cssFilter) {
|
|
@@ -1299,6 +1299,10 @@ export class Node {
|
|
|
1299
1299
|
};
|
|
1300
1300
|
for (key in attrs) {
|
|
1301
1301
|
val = attrs[key];
|
|
1302
|
+
// JSON has no typed arrays, so typed line points are written as an array
|
|
1303
|
+
if (val instanceof TypedArray) {
|
|
1304
|
+
val = Array.from(val);
|
|
1305
|
+
}
|
|
1302
1306
|
// if value is object and object is not plain
|
|
1303
1307
|
// like class instance, we should skip it and to not include
|
|
1304
1308
|
nonPlainObject =
|
|
@@ -2007,7 +2011,34 @@ export class Node {
|
|
|
2007
2011
|
}
|
|
2008
2012
|
return this;
|
|
2009
2013
|
}
|
|
2014
|
+
_addSubtreeObserver(observer) {
|
|
2015
|
+
var _a;
|
|
2016
|
+
((_a = this._subtreeObservers) !== null && _a !== void 0 ? _a : (this._subtreeObservers = new Set())).add(observer);
|
|
2017
|
+
Node._subtreeObserverCount++;
|
|
2018
|
+
}
|
|
2019
|
+
_removeSubtreeObserver(observer) {
|
|
2020
|
+
var _a;
|
|
2021
|
+
if ((_a = this._subtreeObservers) === null || _a === void 0 ? void 0 : _a.delete(observer)) {
|
|
2022
|
+
Node._subtreeObserverCount--;
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
// Tells the observers of this node and of its ancestors that something below
|
|
2026
|
+
// them changed. A node's own changes reach its observers through its change
|
|
2027
|
+
// events, so a draw request starts at the parent. A container calls this
|
|
2028
|
+
// itself when its child list changes.
|
|
2029
|
+
_notifySubtreeChange() {
|
|
2030
|
+
if (!Node._subtreeObserverCount)
|
|
2031
|
+
return;
|
|
2032
|
+
for (let node = this; node; node = node.parent) {
|
|
2033
|
+
const observers = node._subtreeObservers;
|
|
2034
|
+
if (observers)
|
|
2035
|
+
for (const o of observers)
|
|
2036
|
+
o._onSubtreeChange(node);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2010
2039
|
_requestDraw() {
|
|
2040
|
+
var _a;
|
|
2041
|
+
(_a = this.parent) === null || _a === void 0 ? void 0 : _a._notifySubtreeChange();
|
|
2011
2042
|
if (Konva.autoDrawEnabled) {
|
|
2012
2043
|
const drawNode = this.getLayer() || this.getStage();
|
|
2013
2044
|
drawNode === null || drawNode === void 0 ? void 0 : drawNode.batchDraw();
|
|
@@ -2379,6 +2410,8 @@ export class Node {
|
|
|
2379
2410
|
return no;
|
|
2380
2411
|
}
|
|
2381
2412
|
}
|
|
2413
|
+
// Number of registered observers. The ancestor walk is skipped while it is 0.
|
|
2414
|
+
Node._subtreeObserverCount = 0;
|
|
2382
2415
|
// Perf: lets a listener inside an absoluteTransform cascade (e.g. Konva
|
|
2383
2416
|
// .Transformer reacting to a stage drag fan-out across N attached nodes)
|
|
2384
2417
|
// defer work until the cascade ends — collapses O(N) listener-driven calls
|
|
@@ -3,8 +3,9 @@ import { Node } from '../Node.ts';
|
|
|
3
3
|
import { Shape } from '../Shape.ts';
|
|
4
4
|
import { Rect } from './Rect.ts';
|
|
5
5
|
import { Group } from '../Group.ts';
|
|
6
|
-
import type
|
|
6
|
+
import { type ContainerConfig } from '../Container.ts';
|
|
7
7
|
import type { GetSet, IRect, Vector2d } from '../types.ts';
|
|
8
|
+
import type { HitCanvas, SceneCanvas } from '../Canvas.ts';
|
|
8
9
|
export interface Box extends IRect {
|
|
9
10
|
rotation: number;
|
|
10
11
|
}
|
|
@@ -110,6 +111,7 @@ export declare class Transformer extends Group {
|
|
|
110
111
|
_elementsCreated: boolean;
|
|
111
112
|
_updateScheduled: boolean;
|
|
112
113
|
_lastNodeRect?: Readonly<Box>;
|
|
114
|
+
_subtreeChanged: boolean;
|
|
113
115
|
static isTransforming: () => boolean;
|
|
114
116
|
static _isLayerTransforming(layer: Node): boolean;
|
|
115
117
|
constructor(config?: TransformerConfig);
|
|
@@ -160,6 +162,10 @@ export declare class Transformer extends Group {
|
|
|
160
162
|
* });
|
|
161
163
|
*/
|
|
162
164
|
_resetTransformCache(changedNode?: Node): void;
|
|
165
|
+
_onSubtreeChange(node: Node): void;
|
|
166
|
+
_syncSubtreeChange(): void;
|
|
167
|
+
drawScene(can?: SceneCanvas, top?: Node): this;
|
|
168
|
+
drawHit(can?: HitCanvas, top?: Node): this;
|
|
163
169
|
_getNodeRect(): any;
|
|
164
170
|
__getNodeRect(): {
|
|
165
171
|
x: number;
|
|
@@ -186,7 +192,9 @@ export declare class Transformer extends Group {
|
|
|
186
192
|
_scheduleUpdate(): void;
|
|
187
193
|
/**
|
|
188
194
|
* force update of Konva.Transformer.
|
|
189
|
-
*
|
|
195
|
+
* The transformer follows attribute changes of attached nodes and, for an attached group, any change of its descendants.
|
|
196
|
+
* Use it after a change that sets no attribute, for example a `Line` points array mutated in place
|
|
197
|
+
* or a custom `getSelfRect()` that depends on outside state.
|
|
190
198
|
* @method
|
|
191
199
|
* @name Konva.Transformer#forceUpdate
|
|
192
200
|
*/
|
|
@@ -4,6 +4,7 @@ import { Node } from "../Node.js";
|
|
|
4
4
|
import { Shape } from "../Shape.js";
|
|
5
5
|
import { Rect } from "./Rect.js";
|
|
6
6
|
import { Group } from "../Group.js";
|
|
7
|
+
import { Container } from "../Container.js";
|
|
7
8
|
import { Konva } from "../Global.js";
|
|
8
9
|
import { getBooleanValidator, getNumberValidator } from "../Validators.js";
|
|
9
10
|
import { _registerNode } from "../Global.js";
|
|
@@ -260,6 +261,8 @@ export class Transformer extends Group {
|
|
|
260
261
|
this._transformWindow = null;
|
|
261
262
|
this._elementsCreated = false;
|
|
262
263
|
this._updateScheduled = false;
|
|
264
|
+
// an attached container's descendants changed after the last layout
|
|
265
|
+
this._subtreeChanged = false;
|
|
263
266
|
this._createElements();
|
|
264
267
|
// bindings
|
|
265
268
|
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
@@ -358,6 +361,8 @@ export class Transformer extends Group {
|
|
|
358
361
|
}
|
|
359
362
|
node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
|
|
360
363
|
node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
|
|
364
|
+
if (node instanceof Container)
|
|
365
|
+
node._addSubtreeObserver(this);
|
|
361
366
|
node.on(`destroy.${this._getEventNamespace()}`, () => {
|
|
362
367
|
// a destroyed node has nothing left to transform
|
|
363
368
|
this.setNodes(this._nodes.filter((n) => n !== node));
|
|
@@ -434,6 +439,7 @@ export class Transformer extends Group {
|
|
|
434
439
|
if (this._nodes) {
|
|
435
440
|
this._nodes.forEach((node) => {
|
|
436
441
|
node.off('.' + this._getEventNamespace());
|
|
442
|
+
node._removeSubtreeObserver(this);
|
|
437
443
|
});
|
|
438
444
|
}
|
|
439
445
|
this._nodes = [];
|
|
@@ -463,6 +469,42 @@ export class Transformer extends Group {
|
|
|
463
469
|
this._clearCache('transform');
|
|
464
470
|
this._clearSelfAndDescendantCache('absoluteTransform');
|
|
465
471
|
}
|
|
472
|
+
// Called for every change below an attached container. A burst of child
|
|
473
|
+
// changes only drops cached values here. The new bounds are measured once,
|
|
474
|
+
// before the next frame, or earlier if a draw or transform step comes first
|
|
475
|
+
// (_syncSubtreeChange).
|
|
476
|
+
_onSubtreeChange(node) {
|
|
477
|
+
var _a, _b;
|
|
478
|
+
if (this._fitting)
|
|
479
|
+
return;
|
|
480
|
+
// nothing was measured since the last change, so nothing cached is stale
|
|
481
|
+
if (this._subtreeChanged && !this._cache[NODES_RECT])
|
|
482
|
+
return;
|
|
483
|
+
this._resetTransformCache(node);
|
|
484
|
+
if (!this._subtreeChanged) {
|
|
485
|
+
this._subtreeChanged = true;
|
|
486
|
+
// queued ahead of the draw the change requests, so that draw shows the
|
|
487
|
+
// new layout. Updating inside the draw would request one more frame.
|
|
488
|
+
Util.requestAnimFrame(() => this._syncSubtreeChange(), (_a = this.getStage()) === null || _a === void 0 ? void 0 : _a._getOwnerWindow());
|
|
489
|
+
// the transformer can be on another layer than the changed node
|
|
490
|
+
(_b = this.getLayer()) === null || _b === void 0 ? void 0 : _b.batchDraw();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
_syncSubtreeChange() {
|
|
494
|
+
var _a;
|
|
495
|
+
// while dragging, the dragmove handler updates the layout
|
|
496
|
+
if (this._subtreeChanged && ((_a = this._nodes) === null || _a === void 0 ? void 0 : _a.length) && !this.isDragging()) {
|
|
497
|
+
this._update();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
drawScene(can, top) {
|
|
501
|
+
this._syncSubtreeChange();
|
|
502
|
+
return super.drawScene(can, top);
|
|
503
|
+
}
|
|
504
|
+
drawHit(can, top) {
|
|
505
|
+
this._syncSubtreeChange();
|
|
506
|
+
return super.drawHit(can, top);
|
|
507
|
+
}
|
|
466
508
|
_getNodeRect() {
|
|
467
509
|
return this._getCache(NODES_RECT, this.__getNodeRect);
|
|
468
510
|
}
|
|
@@ -724,6 +766,8 @@ export class Transformer extends Group {
|
|
|
724
766
|
(_a = this.getStage()) === null || _a === void 0 ? void 0 : _a._batchEvents(() => this._moveTransform(e));
|
|
725
767
|
}
|
|
726
768
|
_moveTransform(e) {
|
|
769
|
+
// anchors must show the current bounds before they are measured against
|
|
770
|
+
this._syncSubtreeChange();
|
|
727
771
|
let x, y, newHypotenuse;
|
|
728
772
|
const anchorNode = this._anchors[this._movingAnchorName];
|
|
729
773
|
const stage = anchorNode.getStage();
|
|
@@ -1161,7 +1205,9 @@ export class Transformer extends Group {
|
|
|
1161
1205
|
}
|
|
1162
1206
|
/**
|
|
1163
1207
|
* force update of Konva.Transformer.
|
|
1164
|
-
*
|
|
1208
|
+
* The transformer follows attribute changes of attached nodes and, for an attached group, any change of its descendants.
|
|
1209
|
+
* Use it after a change that sets no attribute, for example a `Line` points array mutated in place
|
|
1210
|
+
* or a custom `getSelfRect()` that depends on outside state.
|
|
1165
1211
|
* @method
|
|
1166
1212
|
* @name Konva.Transformer#forceUpdate
|
|
1167
1213
|
*/
|
|
@@ -1177,6 +1223,7 @@ export class Transformer extends Group {
|
|
|
1177
1223
|
}
|
|
1178
1224
|
_update() {
|
|
1179
1225
|
var _a;
|
|
1226
|
+
this._subtreeChanged = false;
|
|
1180
1227
|
const attrs = this._getNodeRect();
|
|
1181
1228
|
this._updateElements(attrs);
|
|
1182
1229
|
const draggable = this.nodes().some((node) => node.draggable());
|