konva 10.4.0 → 10.5.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 +255 -70
- package/konva.min.js +4 -4
- package/lib/DragAndDrop.d.ts +1 -0
- package/lib/DragAndDrop.js +26 -4
- package/lib/Global.js +2 -2
- package/lib/Node.d.ts +12 -3
- package/lib/Node.js +20 -9
- package/lib/Stage.d.ts +4 -1
- package/lib/Stage.js +39 -7
- package/lib/Util.d.ts +1 -0
- package/lib/Util.js +22 -0
- package/lib/_CoreInternals.d.ts +2 -0
- package/lib/_FullInternals.d.ts +2 -0
- package/lib/shapes/Path.d.ts +16 -0
- package/lib/shapes/Path.js +16 -0
- package/lib/shapes/Transformer.d.ts +16 -1
- package/lib/shapes/Transformer.js +123 -41
- package/package.json +1 -1
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v10.
|
|
8
|
+
* Konva JavaScript Framework v10.5.0
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Tue Sep 08 2026
|
|
12
12
|
*
|
|
13
13
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
|
14
14
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
: {};
|
|
36
36
|
const Konva$2 = {
|
|
37
37
|
_global: glob,
|
|
38
|
-
version: '10.
|
|
38
|
+
version: '10.5.0',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -1167,6 +1167,28 @@ js: import "konva/skia-backend";
|
|
|
1167
1167
|
}
|
|
1168
1168
|
console.warn(KONVA_WARNING + str);
|
|
1169
1169
|
},
|
|
1170
|
+
_batchEvents(batch, run) {
|
|
1171
|
+
if (!batch)
|
|
1172
|
+
return run();
|
|
1173
|
+
let called = false;
|
|
1174
|
+
let active = true;
|
|
1175
|
+
try {
|
|
1176
|
+
batch(() => {
|
|
1177
|
+
if (called || !active) {
|
|
1178
|
+
Util.warn('eventBatchFunc must call its argument exactly once, synchronously.');
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
called = true;
|
|
1182
|
+
run();
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
finally {
|
|
1186
|
+
active = false;
|
|
1187
|
+
if (!called) {
|
|
1188
|
+
Util.warn('eventBatchFunc must call its argument synchronously.');
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
},
|
|
1170
1192
|
each(obj, func) {
|
|
1171
1193
|
for (const key in obj) {
|
|
1172
1194
|
func(key, obj[key]);
|
|
@@ -2367,16 +2389,38 @@ js: import "konva/skia-backend";
|
|
|
2367
2389
|
// window has pointer positions the stages of that window can use
|
|
2368
2390
|
_listenToWindow(win) {
|
|
2369
2391
|
const endDragBefore = (evt) => DD._endDragBefore(evt, win);
|
|
2370
|
-
const drag = (evt) => DD._drag(evt, win);
|
|
2392
|
+
const drag = (evt) => DD._batchEvents(() => DD._drag(evt, win), win);
|
|
2393
|
+
const endDragAfter = (evt) => DD._batchEvents(() => DD._endDragAfter(evt));
|
|
2371
2394
|
win.addEventListener('mouseup', endDragBefore, true);
|
|
2372
2395
|
win.addEventListener('touchend', endDragBefore, true);
|
|
2373
2396
|
// add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843
|
|
2374
2397
|
win.addEventListener('touchcancel', endDragBefore, true);
|
|
2375
2398
|
win.addEventListener('mousemove', drag);
|
|
2376
2399
|
win.addEventListener('touchmove', drag);
|
|
2377
|
-
win.addEventListener('mouseup',
|
|
2378
|
-
win.addEventListener('touchend',
|
|
2379
|
-
win.addEventListener('touchcancel',
|
|
2400
|
+
win.addEventListener('mouseup', endDragAfter, false);
|
|
2401
|
+
win.addEventListener('touchend', endDragAfter, false);
|
|
2402
|
+
win.addEventListener('touchcancel', endDragAfter, false);
|
|
2403
|
+
},
|
|
2404
|
+
_batchEvents(callback, win) {
|
|
2405
|
+
if (!DD._dragElements.size)
|
|
2406
|
+
return;
|
|
2407
|
+
// One scope per integration, even when several stages use the same callback.
|
|
2408
|
+
// Keep all positions and handlers in the original order across those stages.
|
|
2409
|
+
const batches = new Set();
|
|
2410
|
+
for (const { node } of DD._dragElements.values()) {
|
|
2411
|
+
const stage = node.getStage();
|
|
2412
|
+
if (!stage || (win && stage._getOwnerWindow() !== win))
|
|
2413
|
+
continue;
|
|
2414
|
+
const batch = stage.eventBatchFunc();
|
|
2415
|
+
if (batch)
|
|
2416
|
+
batches.add(batch);
|
|
2417
|
+
}
|
|
2418
|
+
let run = callback;
|
|
2419
|
+
for (const batch of batches) {
|
|
2420
|
+
const next = run;
|
|
2421
|
+
run = () => Util._batchEvents(batch, next);
|
|
2422
|
+
}
|
|
2423
|
+
run();
|
|
2380
2424
|
},
|
|
2381
2425
|
// methods
|
|
2382
2426
|
_drag(evt, win) {
|
|
@@ -2940,6 +2984,20 @@ js: import "konva/skia-backend";
|
|
|
2940
2984
|
'transformsEnabledChange.konva',
|
|
2941
2985
|
].join(SPACE$1);
|
|
2942
2986
|
let idCounter$1 = 1;
|
|
2987
|
+
// "perfect drawing" buffer for cache() and toCanvas(): it mirrors the target
|
|
2988
|
+
// canvas and is drawn back at (x, y) in the target's coordinate space.
|
|
2989
|
+
// It starts empty and Shape.drawScene sizes it on first use, so nodes
|
|
2990
|
+
// without buffered shapes never allocate it.
|
|
2991
|
+
function createBufferCanvas(target, x, y) {
|
|
2992
|
+
const bufferCanvas = new SceneCanvas({
|
|
2993
|
+
width: 0,
|
|
2994
|
+
height: 0,
|
|
2995
|
+
pixelRatio: target.pixelRatio,
|
|
2996
|
+
});
|
|
2997
|
+
bufferCanvas.x = x;
|
|
2998
|
+
bufferCanvas.y = y;
|
|
2999
|
+
return bufferCanvas;
|
|
3000
|
+
}
|
|
2943
3001
|
/**
|
|
2944
3002
|
* Node constructor. Nodes are entities that can be transformed, layered,
|
|
2945
3003
|
* and have bound events. The stage, layers, groups, and shapes all extend Node.
|
|
@@ -2967,20 +3025,6 @@ js: import "konva/skia-backend";
|
|
|
2967
3025
|
* @param {Number} [config.dragDistance]
|
|
2968
3026
|
* @param {Function} [config.dragBoundFunc]
|
|
2969
3027
|
*/
|
|
2970
|
-
// "perfect drawing" buffer for cache() and toCanvas(): it mirrors the target
|
|
2971
|
-
// canvas and is drawn back at (x, y) in the target's coordinate space.
|
|
2972
|
-
// It starts empty and Shape.drawScene sizes it on first use, so nodes
|
|
2973
|
-
// without buffered shapes never allocate it.
|
|
2974
|
-
function createBufferCanvas(target, x, y) {
|
|
2975
|
-
const bufferCanvas = new SceneCanvas({
|
|
2976
|
-
width: 0,
|
|
2977
|
-
height: 0,
|
|
2978
|
-
pixelRatio: target.pixelRatio,
|
|
2979
|
-
});
|
|
2980
|
-
bufferCanvas.x = x;
|
|
2981
|
-
bufferCanvas.y = y;
|
|
2982
|
-
return bufferCanvas;
|
|
2983
|
-
}
|
|
2984
3028
|
class Node {
|
|
2985
3029
|
constructor(config) {
|
|
2986
3030
|
this._id = idCounter$1++;
|
|
@@ -3021,6 +3065,10 @@ js: import "konva/skia-backend";
|
|
|
3021
3065
|
}
|
|
3022
3066
|
else {
|
|
3023
3067
|
this._cache = {};
|
|
3068
|
+
// clearCache() also reaches descendants whose ancestor transform changes
|
|
3069
|
+
// were suppressed while cached. Invalidate their saved Transformer bounds.
|
|
3070
|
+
if (this._attrsVersion !== undefined)
|
|
3071
|
+
this._attrsVersion++;
|
|
3024
3072
|
}
|
|
3025
3073
|
}
|
|
3026
3074
|
// drop the cached canvases and give their memory back
|
|
@@ -4697,7 +4745,7 @@ js: import "konva/skia-backend";
|
|
|
4697
4745
|
* @param {Boolean} [config.imageSmoothingEnabled] set this to false if you want to disable imageSmoothing
|
|
4698
4746
|
* @example
|
|
4699
4747
|
* var blob = await node.toBlob({});
|
|
4700
|
-
* @returns {Promise<Blob>}
|
|
4748
|
+
* @returns {Promise<Blob>} rejects if the canvas can not be encoded
|
|
4701
4749
|
*/
|
|
4702
4750
|
toBlob(config) {
|
|
4703
4751
|
return new Promise((resolve, reject) => {
|
|
@@ -4706,6 +4754,11 @@ js: import "konva/skia-backend";
|
|
|
4706
4754
|
if (callback)
|
|
4707
4755
|
delete config.callback;
|
|
4708
4756
|
this.toCanvas(config).toBlob((blob) => {
|
|
4757
|
+
// the canvas reports a failed encode by passing null
|
|
4758
|
+
if (!blob) {
|
|
4759
|
+
reject(new Error('Konva: toBlob() failed, the canvas was not encoded'));
|
|
4760
|
+
return;
|
|
4761
|
+
}
|
|
4709
4762
|
resolve(blob);
|
|
4710
4763
|
callback === null || callback === void 0 ? void 0 : callback(blob);
|
|
4711
4764
|
}, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality);
|
|
@@ -4885,6 +4938,8 @@ js: import "konva/skia-backend";
|
|
|
4885
4938
|
else {
|
|
4886
4939
|
this.attrs[key] = val;
|
|
4887
4940
|
}
|
|
4941
|
+
if (this._attrsVersion !== undefined)
|
|
4942
|
+
this._attrsVersion++;
|
|
4888
4943
|
if (this._shouldFireChangeEvents) {
|
|
4889
4944
|
this._fireChangeEvent(key, oldVal, val);
|
|
4890
4945
|
}
|
|
@@ -6783,10 +6838,13 @@ js: import "konva/skia-backend";
|
|
|
6783
6838
|
}
|
|
6784
6839
|
EVENTS.forEach(([event, methodName]) => {
|
|
6785
6840
|
this.content.addEventListener(event, (evt) => {
|
|
6786
|
-
this[methodName](evt);
|
|
6841
|
+
this._batchEvents(() => this[methodName](evt));
|
|
6787
6842
|
}, { passive: false });
|
|
6788
6843
|
});
|
|
6789
6844
|
}
|
|
6845
|
+
_batchEvents(callback) {
|
|
6846
|
+
Util._batchEvents(this.eventBatchFunc(), callback);
|
|
6847
|
+
}
|
|
6790
6848
|
_pointerenter(evt) {
|
|
6791
6849
|
this.setPointersPositions(evt);
|
|
6792
6850
|
const events = getEventsMap(evt.type);
|
|
@@ -7095,12 +7153,25 @@ js: import "konva/skia-backend";
|
|
|
7095
7153
|
}
|
|
7096
7154
|
_pointercancel(evt) {
|
|
7097
7155
|
this.setPointersPositions(evt);
|
|
7098
|
-
const
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7156
|
+
const events = getEventsMap(evt.type);
|
|
7157
|
+
this._changedPointerPositions.forEach((pos) => {
|
|
7158
|
+
const shape = getCapturedShape(pos.id) || this.getIntersection(pos);
|
|
7159
|
+
const event = { evt, pointerId: pos.id };
|
|
7160
|
+
if (shape) {
|
|
7161
|
+
if (events)
|
|
7162
|
+
shape._fireAndBubble(events.pointercancel, { ...event });
|
|
7163
|
+
// Keep the historical pointerup notification for cancellation listeners.
|
|
7164
|
+
shape._fireAndBubble(POINTERUP, { ...event });
|
|
7165
|
+
}
|
|
7166
|
+
else if (events) {
|
|
7167
|
+
this._fire(events.pointercancel, {
|
|
7168
|
+
...event,
|
|
7169
|
+
target: this,
|
|
7170
|
+
currentTarget: this,
|
|
7171
|
+
});
|
|
7172
|
+
}
|
|
7173
|
+
releaseCapture(pos.id);
|
|
7174
|
+
});
|
|
7104
7175
|
}
|
|
7105
7176
|
_lostpointercapture(evt) {
|
|
7106
7177
|
releaseCapture(evt.pointerId);
|
|
@@ -7260,6 +7331,22 @@ js: import "konva/skia-backend";
|
|
|
7260
7331
|
* stage.container(popout.document.body);
|
|
7261
7332
|
*/
|
|
7262
7333
|
Factory.addGetterSetter(Stage, 'container');
|
|
7334
|
+
/**
|
|
7335
|
+
* Get/set the callback used by framework integrations to batch native input.
|
|
7336
|
+
* The callback must invoke its argument exactly once, synchronously. Existing
|
|
7337
|
+
* node events keep their order and cancellation behavior. Direct node.fire()
|
|
7338
|
+
* and programmatic mutations do not create a batch.
|
|
7339
|
+
* Missing calls warn; duplicate or late calls warn and are ignored. Exceptions
|
|
7340
|
+
* propagate and skipped input is not replayed, so an invalid callback can
|
|
7341
|
+
* prevent input processing and drag cleanup.
|
|
7342
|
+
* Each native Konva listener creates its own scope; a DOM event may invoke
|
|
7343
|
+
* several listeners. Batching does not reorder or merge those listeners.
|
|
7344
|
+
* @method
|
|
7345
|
+
* @name Konva.Stage#eventBatchFunc
|
|
7346
|
+
* @example
|
|
7347
|
+
* stage.eventBatchFunc((run) => frameworkBatch(run));
|
|
7348
|
+
*/
|
|
7349
|
+
Factory.addGetterSetter(Stage, 'eventBatchFunc');
|
|
7263
7350
|
|
|
7264
7351
|
const HAS_SHADOW = 'hasShadow';
|
|
7265
7352
|
const HAS_FILL = 'hasFill';
|
|
@@ -12704,6 +12791,22 @@ js: import "konva/skia-backend";
|
|
|
12704
12791
|
* path.data('M200,100h100v50z');
|
|
12705
12792
|
*/
|
|
12706
12793
|
Factory.addGetterSetter(Path, 'data');
|
|
12794
|
+
/**
|
|
12795
|
+
* get width of the path. It is computed from the path data and cannot be set
|
|
12796
|
+
* @name Konva.Path#width
|
|
12797
|
+
* @method
|
|
12798
|
+
* @returns {Number}
|
|
12799
|
+
* @example
|
|
12800
|
+
* var width = path.width();
|
|
12801
|
+
*/
|
|
12802
|
+
/**
|
|
12803
|
+
* get height of the path. It is computed from the path data and cannot be set
|
|
12804
|
+
* @name Konva.Path#height
|
|
12805
|
+
* @method
|
|
12806
|
+
* @returns {Number}
|
|
12807
|
+
* @example
|
|
12808
|
+
* var height = path.height();
|
|
12809
|
+
*/
|
|
12707
12810
|
|
|
12708
12811
|
/**
|
|
12709
12812
|
* Arrow constructor
|
|
@@ -16717,21 +16820,24 @@ js: import "konva/skia-backend";
|
|
|
16717
16820
|
}
|
|
16718
16821
|
this._nodes.forEach((node) => {
|
|
16719
16822
|
const onChange = () => {
|
|
16823
|
+
var _a;
|
|
16720
16824
|
// Perf: skip the changes _fitNodesInto makes itself — it does the
|
|
16721
16825
|
// final _resetTransformCache + update, so per-attr fan-out here is
|
|
16722
16826
|
// pure waste (was O(N*events) per resize step). A change made between
|
|
16723
16827
|
// two pointer moves (e.g. a deferred state update) must get through.
|
|
16724
|
-
if (this._fitting)
|
|
16828
|
+
if (this._fitting) {
|
|
16829
|
+
(_a = this._nodeRectCache) === null || _a === void 0 ? void 0 : _a.delete(node);
|
|
16725
16830
|
return;
|
|
16831
|
+
}
|
|
16726
16832
|
if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
|
|
16727
16833
|
this.rotation(this.nodes()[0].getAbsoluteRotation());
|
|
16728
16834
|
}
|
|
16729
16835
|
// Cache reset stays synchronous so sync reads of tr.x() etc. are fresh.
|
|
16730
|
-
this._resetTransformCache();
|
|
16836
|
+
this._resetTransformCache(node);
|
|
16731
16837
|
if (!this.isDragging()) {
|
|
16732
16838
|
// Perf: an ancestor cascade (e.g. stage drag) fires
|
|
16733
16839
|
// absoluteTransformChange on every attached node — without batching,
|
|
16734
|
-
//
|
|
16840
|
+
// a refresh runs once per node and each call walks all N nodes via
|
|
16735
16841
|
// __getNodeRect, giving O(N^2) per drag frame.
|
|
16736
16842
|
this._scheduleUpdate();
|
|
16737
16843
|
}
|
|
@@ -16837,7 +16943,12 @@ js: import "konva/skia-backend";
|
|
|
16837
16943
|
* console.log('transform started');
|
|
16838
16944
|
* });
|
|
16839
16945
|
*/
|
|
16840
|
-
_resetTransformCache() {
|
|
16946
|
+
_resetTransformCache(changedNode) {
|
|
16947
|
+
var _a, _b;
|
|
16948
|
+
if (changedNode)
|
|
16949
|
+
(_a = this._nodeRectCache) === null || _a === void 0 ? void 0 : _a.delete(changedNode);
|
|
16950
|
+
else
|
|
16951
|
+
(_b = this._nodeRectCache) === null || _b === void 0 ? void 0 : _b.clear();
|
|
16841
16952
|
this._clearCache(NODES_RECT);
|
|
16842
16953
|
this._clearCache('transform');
|
|
16843
16954
|
this._clearSelfAndDescendantCache('absoluteTransform');
|
|
@@ -16846,6 +16957,7 @@ js: import "konva/skia-backend";
|
|
|
16846
16957
|
return this._getCache(NODES_RECT, this.__getNodeRect);
|
|
16847
16958
|
}
|
|
16848
16959
|
__getNodeRect() {
|
|
16960
|
+
var _a;
|
|
16849
16961
|
const node = this.getNode();
|
|
16850
16962
|
if (!node) {
|
|
16851
16963
|
return {
|
|
@@ -16856,35 +16968,76 @@ js: import "konva/skia-backend";
|
|
|
16856
16968
|
rotation: 0,
|
|
16857
16969
|
};
|
|
16858
16970
|
}
|
|
16859
|
-
const
|
|
16860
|
-
this.
|
|
16861
|
-
const box = node.getClientRect({
|
|
16862
|
-
skipTransform: true,
|
|
16863
|
-
skipShadow: true,
|
|
16864
|
-
skipStroke: this.ignoreStroke(),
|
|
16865
|
-
});
|
|
16866
|
-
const points = [
|
|
16867
|
-
{ x: box.x, y: box.y },
|
|
16868
|
-
{ x: box.x + box.width, y: box.y },
|
|
16869
|
-
{ x: box.x + box.width, y: box.y + box.height },
|
|
16870
|
-
{ x: box.x, y: box.y + box.height },
|
|
16871
|
-
];
|
|
16872
|
-
const trans = node.getAbsoluteTransform();
|
|
16873
|
-
points.forEach(function (point) {
|
|
16874
|
-
const transformed = trans.point(point);
|
|
16875
|
-
totalPoints.push(transformed);
|
|
16876
|
-
});
|
|
16877
|
-
});
|
|
16971
|
+
const rotation = Konva$2.getAngle(this.rotation());
|
|
16972
|
+
const ignoreStroke = this.ignoreStroke();
|
|
16878
16973
|
const tr = new Transform();
|
|
16879
|
-
tr.rotate(-
|
|
16974
|
+
tr.rotate(-rotation);
|
|
16975
|
+
const cache = this._nodeRectCache || (this._nodeRectCache = new Map());
|
|
16880
16976
|
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
16881
|
-
|
|
16882
|
-
|
|
16883
|
-
|
|
16884
|
-
|
|
16885
|
-
|
|
16886
|
-
|
|
16887
|
-
|
|
16977
|
+
for (const node of this.nodes()) {
|
|
16978
|
+
// Bounds may only be reused when they are a pure function of the node's
|
|
16979
|
+
// own size: then every change reaches us either through _setAttr or
|
|
16980
|
+
// through the size probe below. A shape with its own getSelfRect - Line
|
|
16981
|
+
// mutates its points array in place, and a user subclass can measure
|
|
16982
|
+
// anything at all - may change with no signal, so it is measured every
|
|
16983
|
+
// time. Groups depend on their descendants, and a cached ancestor
|
|
16984
|
+
// suppresses descendant transform-change notifications, so both are
|
|
16985
|
+
// measured too.
|
|
16986
|
+
const cacheable = node instanceof Shape &&
|
|
16987
|
+
node.getSelfRect === Shape.prototype.getSelfRect &&
|
|
16988
|
+
!node._hasCachedAncestor();
|
|
16989
|
+
// width() and height() are the only inputs of the default getSelfRect and
|
|
16990
|
+
// they can come from outside the attrs (an Image source that loads or
|
|
16991
|
+
// resizes, Text metrics), so the attr revision alone cannot key them.
|
|
16992
|
+
const width = cacheable ? node.width() : 0;
|
|
16993
|
+
const height = cacheable ? node.height() : 0;
|
|
16994
|
+
if (cacheable)
|
|
16995
|
+
(_a = node._attrsVersion) !== null && _a !== void 0 ? _a : (node._attrsVersion = 0);
|
|
16996
|
+
let bounds = cacheable ? cache.get(node) : undefined;
|
|
16997
|
+
if (!bounds ||
|
|
16998
|
+
bounds.rotation !== rotation ||
|
|
16999
|
+
bounds.ignoreStroke !== ignoreStroke ||
|
|
17000
|
+
bounds.version !== node._attrsVersion ||
|
|
17001
|
+
bounds.width !== width ||
|
|
17002
|
+
bounds.height !== height) {
|
|
17003
|
+
const box = node.getClientRect({
|
|
17004
|
+
skipTransform: true,
|
|
17005
|
+
skipShadow: true,
|
|
17006
|
+
skipStroke: ignoreStroke,
|
|
17007
|
+
});
|
|
17008
|
+
const points = [
|
|
17009
|
+
{ x: box.x, y: box.y },
|
|
17010
|
+
{ x: box.x + box.width, y: box.y },
|
|
17011
|
+
{ x: box.x + box.width, y: box.y + box.height },
|
|
17012
|
+
{ x: box.x, y: box.y + box.height },
|
|
17013
|
+
];
|
|
17014
|
+
const trans = node.getAbsoluteTransform();
|
|
17015
|
+
bounds = {
|
|
17016
|
+
rotation,
|
|
17017
|
+
ignoreStroke,
|
|
17018
|
+
width,
|
|
17019
|
+
height,
|
|
17020
|
+
version: node._attrsVersion || 0,
|
|
17021
|
+
minX: Infinity,
|
|
17022
|
+
minY: Infinity,
|
|
17023
|
+
maxX: -Infinity,
|
|
17024
|
+
maxY: -Infinity,
|
|
17025
|
+
};
|
|
17026
|
+
for (const point of points) {
|
|
17027
|
+
const projected = tr.point(trans.point(point));
|
|
17028
|
+
bounds.minX = Math.min(bounds.minX, projected.x);
|
|
17029
|
+
bounds.minY = Math.min(bounds.minY, projected.y);
|
|
17030
|
+
bounds.maxX = Math.max(bounds.maxX, projected.x);
|
|
17031
|
+
bounds.maxY = Math.max(bounds.maxY, projected.y);
|
|
17032
|
+
}
|
|
17033
|
+
if (cacheable)
|
|
17034
|
+
cache.set(node, bounds);
|
|
17035
|
+
}
|
|
17036
|
+
minX = Math.min(minX, bounds.minX);
|
|
17037
|
+
minY = Math.min(minY, bounds.minY);
|
|
17038
|
+
maxX = Math.max(maxX, bounds.maxX);
|
|
17039
|
+
maxY = Math.max(maxY, bounds.maxY);
|
|
17040
|
+
}
|
|
16888
17041
|
tr.invert();
|
|
16889
17042
|
const p = tr.point({ x: minX, y: minY });
|
|
16890
17043
|
return {
|
|
@@ -17056,6 +17209,7 @@ js: import "konva/skia-backend";
|
|
|
17056
17209
|
win.addEventListener('touchmove', this._handleMouseMove);
|
|
17057
17210
|
win.addEventListener('mouseup', this._handleMouseUp, true);
|
|
17058
17211
|
win.addEventListener('touchend', this._handleMouseUp, true);
|
|
17212
|
+
win.addEventListener('touchcancel', this._handleMouseUp, true);
|
|
17059
17213
|
}
|
|
17060
17214
|
this._transforming = true;
|
|
17061
17215
|
// the pointer that hit the anchor (a touchstart can land several fingers)
|
|
@@ -17073,6 +17227,10 @@ js: import "konva/skia-backend";
|
|
|
17073
17227
|
});
|
|
17074
17228
|
}
|
|
17075
17229
|
_handleMouseMove(e) {
|
|
17230
|
+
var _a;
|
|
17231
|
+
(_a = this.getStage()) === null || _a === void 0 ? void 0 : _a._batchEvents(() => this._moveTransform(e));
|
|
17232
|
+
}
|
|
17233
|
+
_moveTransform(e) {
|
|
17076
17234
|
let x, y, newHypotenuse;
|
|
17077
17235
|
const anchorNode = this._anchors[this._movingAnchorName];
|
|
17078
17236
|
const stage = anchorNode.getStage();
|
|
@@ -17281,7 +17439,10 @@ js: import "konva/skia-backend";
|
|
|
17281
17439
|
return;
|
|
17282
17440
|
}
|
|
17283
17441
|
}
|
|
17284
|
-
|
|
17442
|
+
if (stage)
|
|
17443
|
+
stage._batchEvents(() => this._removeEvents(e));
|
|
17444
|
+
else
|
|
17445
|
+
this._removeEvents(e);
|
|
17285
17446
|
}
|
|
17286
17447
|
// the transformer positions itself in absolute coordinates (see
|
|
17287
17448
|
// _getNodeRect), whatever the transforms of its ancestors are
|
|
@@ -17300,6 +17461,7 @@ js: import "konva/skia-backend";
|
|
|
17300
17461
|
win.removeEventListener('touchmove', this._handleMouseMove);
|
|
17301
17462
|
win.removeEventListener('mouseup', this._handleMouseUp, true);
|
|
17302
17463
|
win.removeEventListener('touchend', this._handleMouseUp, true);
|
|
17464
|
+
win.removeEventListener('touchcancel', this._handleMouseUp, true);
|
|
17303
17465
|
}
|
|
17304
17466
|
const node = this.getNode();
|
|
17305
17467
|
activeTransformers.delete(this);
|
|
@@ -17506,7 +17668,7 @@ js: import "konva/skia-backend";
|
|
|
17506
17668
|
if (!((_a = this._nodes) === null || _a === void 0 ? void 0 : _a.length) || this._fitting || this.isDragging()) {
|
|
17507
17669
|
return;
|
|
17508
17670
|
}
|
|
17509
|
-
this.
|
|
17671
|
+
this._update();
|
|
17510
17672
|
});
|
|
17511
17673
|
}
|
|
17512
17674
|
/**
|
|
@@ -17520,8 +17682,39 @@ js: import "konva/skia-backend";
|
|
|
17520
17682
|
this.update();
|
|
17521
17683
|
}
|
|
17522
17684
|
update() {
|
|
17685
|
+
// Explicit updates and Transformer configuration changes also refresh
|
|
17686
|
+
// styles and layout when the selected nodes' bounds are unchanged.
|
|
17687
|
+
this._lastNodeRect = undefined;
|
|
17688
|
+
this._update();
|
|
17689
|
+
}
|
|
17690
|
+
_update() {
|
|
17523
17691
|
var _a;
|
|
17524
17692
|
const attrs = this._getNodeRect();
|
|
17693
|
+
this._updateElements(attrs);
|
|
17694
|
+
const draggable = this.nodes().some((node) => node.draggable());
|
|
17695
|
+
if (this._back.draggable() !== draggable) {
|
|
17696
|
+
this._back.draggable(draggable);
|
|
17697
|
+
}
|
|
17698
|
+
const styleFunc = this.anchorStyleFunc();
|
|
17699
|
+
if (styleFunc) {
|
|
17700
|
+
Object.values(this._anchors).forEach((node) => styleFunc(node));
|
|
17701
|
+
}
|
|
17702
|
+
(_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
|
|
17703
|
+
}
|
|
17704
|
+
_updateElements(attrs) {
|
|
17705
|
+
const previous = this._lastNodeRect;
|
|
17706
|
+
// Only element layout is cached. Drag handling, user callbacks and drawing
|
|
17707
|
+
// remain in _update(). Custom styling needs fresh defaults on every update.
|
|
17708
|
+
if (previous &&
|
|
17709
|
+
!this.anchorStyleFunc() &&
|
|
17710
|
+
attrs.x === previous.x &&
|
|
17711
|
+
attrs.y === previous.y &&
|
|
17712
|
+
attrs.width === previous.width &&
|
|
17713
|
+
attrs.height === previous.height &&
|
|
17714
|
+
attrs.rotation === previous.rotation) {
|
|
17715
|
+
return;
|
|
17716
|
+
}
|
|
17717
|
+
this._lastNodeRect = { ...attrs };
|
|
17525
17718
|
this.rotation(Util._getRotation(attrs.rotation));
|
|
17526
17719
|
const width = attrs.width;
|
|
17527
17720
|
const height = attrs.height;
|
|
@@ -17641,17 +17834,9 @@ js: import "konva/skia-backend";
|
|
|
17641
17834
|
stroke: this.borderStroke(),
|
|
17642
17835
|
strokeWidth: this.borderStrokeWidth(),
|
|
17643
17836
|
dash: this.borderDash(),
|
|
17644
|
-
draggable: this.nodes().some((node) => node.draggable()),
|
|
17645
17837
|
x: 0,
|
|
17646
17838
|
y: 0,
|
|
17647
17839
|
});
|
|
17648
|
-
const styleFunc = this.anchorStyleFunc();
|
|
17649
|
-
if (styleFunc) {
|
|
17650
|
-
anchors.forEach((node) => {
|
|
17651
|
-
styleFunc(node);
|
|
17652
|
-
});
|
|
17653
|
-
}
|
|
17654
|
-
(_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
|
|
17655
17840
|
}
|
|
17656
17841
|
/**
|
|
17657
17842
|
* determine if transformer is in active transform
|