@inditextech/weave-sdk 0.42.0 → 0.42.2
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/dist/sdk.cjs +341 -97
- package/dist/sdk.d.cts +85 -41
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +85 -41
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +355 -110
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.cjs
CHANGED
|
@@ -17037,14 +17037,15 @@ var WeaveNode = class {
|
|
|
17037
17037
|
node.on("pointerover", (e) => {
|
|
17038
17038
|
e.cancelBubble = true;
|
|
17039
17039
|
const stage = this.instance.getStage();
|
|
17040
|
+
const isNodeSelectionEnabled = this.getSelectionPlugin()?.isEnabled();
|
|
17040
17041
|
const realNode = this.instance.getInstanceRecursive(node);
|
|
17041
17042
|
const isTargetable = e.target.getAttrs().isTargetable !== false;
|
|
17042
17043
|
const isLocked$1 = realNode.getAttrs().locked ?? false;
|
|
17043
|
-
if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isLocked$1) {
|
|
17044
|
+
if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isLocked$1) {
|
|
17044
17045
|
const stage$1 = this.instance.getStage();
|
|
17045
17046
|
stage$1.container().style.cursor = "default";
|
|
17046
17047
|
}
|
|
17047
|
-
if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isTargetable && !isLocked$1 && stage.mode() === WEAVE_STAGE_DEFAULT_MODE) {
|
|
17048
|
+
if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isTargetable && !isLocked$1 && stage.mode() === WEAVE_STAGE_DEFAULT_MODE) {
|
|
17048
17049
|
const stage$1 = this.instance.getStage();
|
|
17049
17050
|
stage$1.container().style.cursor = "pointer";
|
|
17050
17051
|
this.setHoverState(realNode);
|
|
@@ -18422,7 +18423,6 @@ var WeaveStateManager = class {
|
|
|
18422
18423
|
}
|
|
18423
18424
|
addNode(node, parentId = "mainLayer", index = void 0) {
|
|
18424
18425
|
const state = this.instance.getStore().getState();
|
|
18425
|
-
this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before addNode");
|
|
18426
18426
|
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18427
18427
|
const msg = `State is empty, cannot add the node`;
|
|
18428
18428
|
this.logger.warn({
|
|
@@ -18449,8 +18449,6 @@ var WeaveStateManager = class {
|
|
|
18449
18449
|
}, msg);
|
|
18450
18450
|
return;
|
|
18451
18451
|
}
|
|
18452
|
-
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before init");
|
|
18453
|
-
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before add");
|
|
18454
18452
|
const doc = (0, __syncedstore_core.getYjsDoc)(state);
|
|
18455
18453
|
doc.transact(() => {
|
|
18456
18454
|
if (!parent.props.children) parent.props.children = [];
|
|
@@ -18467,10 +18465,8 @@ var WeaveStateManager = class {
|
|
|
18467
18465
|
zIndex: childrenAmount
|
|
18468
18466
|
}
|
|
18469
18467
|
};
|
|
18470
|
-
this.logger.info({ node: JSON.parse(JSON.stringify(nodeToAdd)) }, "addNode: node to add");
|
|
18471
18468
|
parent.props.children.push(nodeToAdd);
|
|
18472
18469
|
}
|
|
18473
|
-
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent after add");
|
|
18474
18470
|
this.instance.emitEvent("onNodeAdded", node);
|
|
18475
18471
|
});
|
|
18476
18472
|
}
|
|
@@ -18504,7 +18500,6 @@ var WeaveStateManager = class {
|
|
|
18504
18500
|
}
|
|
18505
18501
|
updateNode(node) {
|
|
18506
18502
|
const state = this.instance.getStore().getState();
|
|
18507
|
-
this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before updateNode");
|
|
18508
18503
|
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18509
18504
|
const msg = `State is empty, cannot update the node`;
|
|
18510
18505
|
this.logger.warn({ node }, msg);
|
|
@@ -18516,20 +18511,14 @@ var WeaveStateManager = class {
|
|
|
18516
18511
|
this.logger.warn({ node }, msg);
|
|
18517
18512
|
return;
|
|
18518
18513
|
}
|
|
18519
|
-
this.logger.info({
|
|
18520
|
-
node: JSON.parse(JSON.stringify(nodeState)),
|
|
18521
|
-
toUpdate: node
|
|
18522
|
-
}, "updateNode: before update");
|
|
18523
18514
|
const doc = (0, __syncedstore_core.getYjsDoc)(state);
|
|
18524
18515
|
doc.transact(() => {
|
|
18525
18516
|
this.deepSyncSyncedStore(nodeState.props, node.props);
|
|
18526
18517
|
});
|
|
18527
|
-
this.logger.info({ node: JSON.parse(JSON.stringify(nodeState)) }, "updateNode: after update");
|
|
18528
18518
|
this.instance.emitEvent("onNodeUpdated", node);
|
|
18529
18519
|
}
|
|
18530
18520
|
removeNode(node) {
|
|
18531
18521
|
const state = this.instance.getStore().getState();
|
|
18532
|
-
this.logger.info({ stage: JSON.parse(JSON.stringify(state)) }, "State before removeNode");
|
|
18533
18522
|
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18534
18523
|
const msg = `State is empty, cannot update the node`;
|
|
18535
18524
|
this.logger.warn({ node }, msg);
|
|
@@ -18546,8 +18535,6 @@ var WeaveStateManager = class {
|
|
|
18546
18535
|
this.logger.warn({ node }, msg);
|
|
18547
18536
|
return;
|
|
18548
18537
|
}
|
|
18549
|
-
this.logger.info({ key: node.key }, "removeNode: node to remove");
|
|
18550
|
-
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "removeNode: parent before remove");
|
|
18551
18538
|
const doc = (0, __syncedstore_core.getYjsDoc)(state);
|
|
18552
18539
|
doc.transact(() => {
|
|
18553
18540
|
if (parent.props.children) {
|
|
@@ -18556,7 +18543,6 @@ var WeaveStateManager = class {
|
|
|
18556
18543
|
break;
|
|
18557
18544
|
}
|
|
18558
18545
|
for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
|
|
18559
|
-
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "removeNode: parent after remove");
|
|
18560
18546
|
this.instance.emitEvent("onNodeRemoved", node);
|
|
18561
18547
|
}
|
|
18562
18548
|
});
|
|
@@ -18566,7 +18552,6 @@ var WeaveStateManager = class {
|
|
|
18566
18552
|
}
|
|
18567
18553
|
moveNode(node, position) {
|
|
18568
18554
|
const state = this.instance.getStore().getState();
|
|
18569
|
-
this.logger.info({ stage: JSON.parse(JSON.stringify(state)) }, "State before moveNode");
|
|
18570
18555
|
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18571
18556
|
const msg = `State is empty, cannot update the node`;
|
|
18572
18557
|
this.logger.warn({ node }, msg);
|
|
@@ -18583,7 +18568,6 @@ var WeaveStateManager = class {
|
|
|
18583
18568
|
this.logger.warn({ node }, msg);
|
|
18584
18569
|
return;
|
|
18585
18570
|
}
|
|
18586
|
-
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "moveNode: parent before move");
|
|
18587
18571
|
if (parent.props.children) {
|
|
18588
18572
|
const childrenAmount = parent.props.children.length;
|
|
18589
18573
|
const nodeIndex = parent.props.children.findIndex((child) => child.key === node.key);
|
|
@@ -18605,7 +18589,6 @@ var WeaveStateManager = class {
|
|
|
18605
18589
|
}
|
|
18606
18590
|
});
|
|
18607
18591
|
}
|
|
18608
|
-
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "moveNode: parent after move");
|
|
18609
18592
|
}
|
|
18610
18593
|
getElementsTree() {
|
|
18611
18594
|
const state = this.instance.getStore().getState().weave;
|
|
@@ -18690,7 +18673,7 @@ var WeaveRegisterManager = class {
|
|
|
18690
18673
|
|
|
18691
18674
|
//#endregion
|
|
18692
18675
|
//#region package.json
|
|
18693
|
-
var version = "0.42.
|
|
18676
|
+
var version = "0.42.2";
|
|
18694
18677
|
|
|
18695
18678
|
//#endregion
|
|
18696
18679
|
//#region src/managers/setup.ts
|
|
@@ -18790,7 +18773,6 @@ var WeaveStageManager = class {
|
|
|
18790
18773
|
initialZIndex: void 0
|
|
18791
18774
|
};
|
|
18792
18775
|
const stage = new konva.default.Stage({ ...props });
|
|
18793
|
-
stage.batchDraw();
|
|
18794
18776
|
this.setStage(stage);
|
|
18795
18777
|
}
|
|
18796
18778
|
getContainerNodes() {
|
|
@@ -19425,6 +19407,10 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
19425
19407
|
this.wheelMousePressed = false;
|
|
19426
19408
|
stage.isFocused = () => this.stageFocused;
|
|
19427
19409
|
stage.isMouseWheelPressed = () => this.wheelMousePressed;
|
|
19410
|
+
stage.position({
|
|
19411
|
+
x: 0,
|
|
19412
|
+
y: 0
|
|
19413
|
+
});
|
|
19428
19414
|
const container = stage.container();
|
|
19429
19415
|
container.setAttribute("tabindex", "0");
|
|
19430
19416
|
stage.container().addEventListener("focus", () => {
|
|
@@ -19473,7 +19459,6 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
19473
19459
|
stage.on("pointerup", (e) => {
|
|
19474
19460
|
if (e.evt.button === 1) this.wheelMousePressed = false;
|
|
19475
19461
|
});
|
|
19476
|
-
stage.batchDraw();
|
|
19477
19462
|
return stage;
|
|
19478
19463
|
}
|
|
19479
19464
|
onUpdate() {}
|
|
@@ -19857,7 +19842,6 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
19857
19842
|
width,
|
|
19858
19843
|
height
|
|
19859
19844
|
});
|
|
19860
|
-
if (nextProps.width !== nodeInstance.getAttrs().width || nextProps.height !== nodeInstance.getAttrs().height) this.updateNode(nodeInstance);
|
|
19861
19845
|
if (this.editing) this.updateTextAreaDOM(nodeInstance);
|
|
19862
19846
|
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
19863
19847
|
if (nodesSelectionPlugin) {
|
|
@@ -20192,6 +20176,8 @@ const IMAGE_TOOL_ACTION_NAME = "imageTool";
|
|
|
20192
20176
|
const IMAGE_TOOL_STATE = {
|
|
20193
20177
|
["IDLE"]: "idle",
|
|
20194
20178
|
["UPLOADING"]: "uploading",
|
|
20179
|
+
["DEFINING_POSITION"]: "definingPosition",
|
|
20180
|
+
["SELECTED_POSITION"]: "selectedPosition",
|
|
20195
20181
|
["ADDING"]: "adding",
|
|
20196
20182
|
["FINISHED"]: "finished"
|
|
20197
20183
|
};
|
|
@@ -20201,14 +20187,17 @@ const IMAGE_TOOL_STATE = {
|
|
|
20201
20187
|
var WeaveImageToolAction = class extends WeaveAction {
|
|
20202
20188
|
initialized = false;
|
|
20203
20189
|
initialCursor = null;
|
|
20190
|
+
cursorPadding = 5;
|
|
20204
20191
|
onPropsChange = void 0;
|
|
20205
20192
|
update = void 0;
|
|
20206
20193
|
constructor() {
|
|
20207
20194
|
super();
|
|
20195
|
+
this.pointers = new Map();
|
|
20208
20196
|
this.initialized = false;
|
|
20209
20197
|
this.state = IMAGE_TOOL_STATE.IDLE;
|
|
20210
20198
|
this.imageId = null;
|
|
20211
20199
|
this.tempImageId = null;
|
|
20200
|
+
this.tempImageNode = null;
|
|
20212
20201
|
this.container = void 0;
|
|
20213
20202
|
this.imageURL = null;
|
|
20214
20203
|
this.preloadImgs = {};
|
|
@@ -20249,26 +20238,37 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
20249
20238
|
return;
|
|
20250
20239
|
}
|
|
20251
20240
|
});
|
|
20252
|
-
stage.on("
|
|
20253
|
-
|
|
20254
|
-
|
|
20255
|
-
|
|
20256
|
-
|
|
20241
|
+
stage.on("pointerdown", (e) => {
|
|
20242
|
+
this.setTapStart(e);
|
|
20243
|
+
this.pointers.set(e.evt.pointerId, {
|
|
20244
|
+
x: e.evt.clientX,
|
|
20245
|
+
y: e.evt.clientY
|
|
20246
|
+
});
|
|
20247
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === IMAGE_TOOL_ACTION_NAME) {
|
|
20248
|
+
this.state = IMAGE_TOOL_STATE.DEFINING_POSITION;
|
|
20257
20249
|
return;
|
|
20258
20250
|
}
|
|
20251
|
+
if (this.state === IMAGE_TOOL_STATE.DEFINING_POSITION) this.state = IMAGE_TOOL_STATE.SELECTED_POSITION;
|
|
20259
20252
|
});
|
|
20260
|
-
stage.on("pointermove", () => {
|
|
20261
|
-
|
|
20262
|
-
|
|
20253
|
+
stage.on("pointermove", (e) => {
|
|
20254
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === IMAGE_TOOL_ACTION_NAME) {
|
|
20255
|
+
this.state = IMAGE_TOOL_STATE.DEFINING_POSITION;
|
|
20256
|
+
return;
|
|
20257
|
+
}
|
|
20258
|
+
if ([IMAGE_TOOL_STATE.DEFINING_POSITION, IMAGE_TOOL_STATE.SELECTED_POSITION].includes(this.state) && this.tempImageNode && this.instance.getActiveAction() === IMAGE_TOOL_ACTION_NAME && e.evt.pointerType === "mouse") {
|
|
20259
|
+
stage.container().style.cursor = "crosshair";
|
|
20260
|
+
stage.container().focus();
|
|
20263
20261
|
const mousePos = stage.getRelativePointerPosition();
|
|
20264
|
-
|
|
20265
|
-
x: (mousePos?.x ?? 0) +
|
|
20266
|
-
y: (mousePos?.y ?? 0) +
|
|
20262
|
+
this.tempImageNode.setAttrs({
|
|
20263
|
+
x: (mousePos?.x ?? 0) + this.cursorPadding,
|
|
20264
|
+
y: (mousePos?.y ?? 0) + this.cursorPadding
|
|
20267
20265
|
});
|
|
20268
|
-
const nodeHandler = this.instance.getNodeHandler("rectangle");
|
|
20269
|
-
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempImage));
|
|
20270
20266
|
}
|
|
20271
20267
|
});
|
|
20268
|
+
stage.on("pointerup", (e) => {
|
|
20269
|
+
this.pointers.delete(e.evt.pointerId);
|
|
20270
|
+
if (this.state === IMAGE_TOOL_STATE.SELECTED_POSITION) this.handleAdding();
|
|
20271
|
+
});
|
|
20272
20272
|
this.initialized = true;
|
|
20273
20273
|
}
|
|
20274
20274
|
setState(state) {
|
|
@@ -20303,47 +20303,50 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
20303
20303
|
this.preloadImgs[this.imageId].src = imageURL;
|
|
20304
20304
|
this.instance.emitEvent("onImageLoadStart");
|
|
20305
20305
|
}
|
|
20306
|
+
isTouchDevice() {
|
|
20307
|
+
return window.matchMedia("(pointer: coarse)").matches;
|
|
20308
|
+
}
|
|
20306
20309
|
addImageNode(position) {
|
|
20307
20310
|
const stage = this.instance.getStage();
|
|
20308
20311
|
stage.container().style.cursor = "crosshair";
|
|
20309
20312
|
stage.container().focus();
|
|
20310
20313
|
if (position) {
|
|
20311
|
-
this.setState(IMAGE_TOOL_STATE.
|
|
20314
|
+
this.setState(IMAGE_TOOL_STATE.SELECTED_POSITION);
|
|
20312
20315
|
this.handleAdding(position);
|
|
20313
20316
|
return;
|
|
20314
20317
|
}
|
|
20315
20318
|
if (this.imageId) {
|
|
20316
20319
|
const mousePos = stage.getRelativePointerPosition();
|
|
20317
|
-
const nodeHandler = this.instance.getNodeHandler("image");
|
|
20318
20320
|
this.tempImageId = v4_default();
|
|
20319
20321
|
const aspectRatio = this.preloadImgs[this.imageId].width / this.preloadImgs[this.imageId].height;
|
|
20320
|
-
if (
|
|
20321
|
-
|
|
20322
|
-
|
|
20323
|
-
|
|
20324
|
-
|
|
20325
|
-
|
|
20322
|
+
if (!this.tempImageNode && this.tempImageId && !this.isTouchDevice()) {
|
|
20323
|
+
this.tempImageNode = new konva.default.Image({
|
|
20324
|
+
id: this.tempImageId,
|
|
20325
|
+
x: (mousePos?.x ?? 0) + this.cursorPadding,
|
|
20326
|
+
y: (mousePos?.y ?? 0) + this.cursorPadding,
|
|
20327
|
+
width: 240 * aspectRatio * (1 / stage.scaleX()),
|
|
20328
|
+
height: 240 * (1 / stage.scaleY()),
|
|
20326
20329
|
opacity: 1,
|
|
20327
20330
|
adding: true,
|
|
20328
|
-
|
|
20331
|
+
image: this.preloadImgs[this.imageId],
|
|
20329
20332
|
stroke: "#000000ff",
|
|
20330
20333
|
strokeWidth: 0,
|
|
20331
20334
|
strokeScaleEnabled: true,
|
|
20332
20335
|
listening: false
|
|
20333
20336
|
});
|
|
20334
|
-
this.instance.
|
|
20337
|
+
this.instance.getMainLayer()?.add(this.tempImageNode);
|
|
20335
20338
|
}
|
|
20339
|
+
this.instance.emitEvent("onAddingImage", { imageURL: this.props.imageURL });
|
|
20336
20340
|
}
|
|
20337
20341
|
this.clickPoint = null;
|
|
20338
|
-
this.setState(IMAGE_TOOL_STATE.
|
|
20342
|
+
this.setState(IMAGE_TOOL_STATE.DEFINING_POSITION);
|
|
20339
20343
|
}
|
|
20340
20344
|
addImage(position) {
|
|
20341
20345
|
if (position) this.clickPoint = position;
|
|
20342
20346
|
this.setState(IMAGE_TOOL_STATE.UPLOADING);
|
|
20343
20347
|
}
|
|
20344
20348
|
handleAdding(position) {
|
|
20345
|
-
|
|
20346
|
-
if (this.imageId && this.imageURL && this.preloadImgs[this.imageId] && (!position && tempImage || position)) {
|
|
20349
|
+
if (this.imageId && this.imageURL && this.preloadImgs[this.imageId]) {
|
|
20347
20350
|
const { mousePoint, container } = this.instance.getMousePointer(position);
|
|
20348
20351
|
this.clickPoint = mousePoint;
|
|
20349
20352
|
this.container = container;
|
|
@@ -20367,10 +20370,7 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
20367
20370
|
}
|
|
20368
20371
|
});
|
|
20369
20372
|
this.instance.addNode(node, this.container?.getAttrs().id);
|
|
20370
|
-
|
|
20371
|
-
if (!position) {
|
|
20372
|
-
const imageNodeHandler = this.instance.getNodeHandler("image");
|
|
20373
|
-
if (imageNodeHandler) this.instance.removeNode(imageNodeHandler.serialize(tempImage));
|
|
20373
|
+
this.instance.emitEvent("onAddedImage", { imageURL: this.props.imageURL });
|
|
20374
20374
|
}
|
|
20375
20375
|
this.setState(IMAGE_TOOL_STATE.FINISHED);
|
|
20376
20376
|
}
|
|
@@ -20393,11 +20393,7 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
20393
20393
|
cleanup() {
|
|
20394
20394
|
const stage = this.instance.getStage();
|
|
20395
20395
|
if (this.imageId) delete this.preloadImgs[this.imageId];
|
|
20396
|
-
|
|
20397
|
-
if (tempImage) {
|
|
20398
|
-
const nodeHandler = this.instance.getNodeHandler("rectangle");
|
|
20399
|
-
if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempImage));
|
|
20400
|
-
}
|
|
20396
|
+
if (this.tempImageNode) this.tempImageNode.destroy();
|
|
20401
20397
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
20402
20398
|
if (selectionPlugin) {
|
|
20403
20399
|
const node = stage.findOne(`#${this.imageId}`);
|
|
@@ -20875,8 +20871,8 @@ var WeaveImageNode = class extends WeaveNode {
|
|
|
20875
20871
|
scaleX: 1,
|
|
20876
20872
|
scaleY: 1,
|
|
20877
20873
|
rotation: 0,
|
|
20878
|
-
width: imageProps.width
|
|
20879
|
-
height: imageProps.height
|
|
20874
|
+
width: imageProps.width || 0,
|
|
20875
|
+
height: imageProps.height || 0,
|
|
20880
20876
|
fill: "#ccccccff",
|
|
20881
20877
|
strokeWidth: 0,
|
|
20882
20878
|
draggable: false,
|
|
@@ -23402,6 +23398,7 @@ var import_hammer = __toESM(require_hammer(), 1);
|
|
|
23402
23398
|
var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
23403
23399
|
getLayerName = void 0;
|
|
23404
23400
|
initLayer = void 0;
|
|
23401
|
+
pinching = false;
|
|
23405
23402
|
zooming = false;
|
|
23406
23403
|
isTrackpad = false;
|
|
23407
23404
|
zoomVelocity = 0;
|
|
@@ -23418,6 +23415,8 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23418
23415
|
const { config } = params ?? {};
|
|
23419
23416
|
this.config = (0, import_lodash.merge)(WEAVE_STAGE_ZOOM_DEFAULT_CONFIG, config);
|
|
23420
23417
|
if (!this.config.zoomSteps.includes(this.config.defaultZoom)) throw new Error(`Default zoom ${this.config.defaultZoom} is not in zoom steps`);
|
|
23418
|
+
this.threshold = .2;
|
|
23419
|
+
this.pinching = false;
|
|
23421
23420
|
this.isTrackpad = false;
|
|
23422
23421
|
this.isCtrlOrMetaPressed = false;
|
|
23423
23422
|
this.updatedMinimumZoom = false;
|
|
@@ -23557,10 +23556,6 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23557
23556
|
const scale = Math.min(scaleX, scaleY);
|
|
23558
23557
|
return scale;
|
|
23559
23558
|
}
|
|
23560
|
-
getSelectionPlugin() {
|
|
23561
|
-
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
23562
|
-
return selectionPlugin;
|
|
23563
|
-
}
|
|
23564
23559
|
fitToScreen() {
|
|
23565
23560
|
if (!this.enabled) return;
|
|
23566
23561
|
const mainLayer = this.instance.getMainLayer();
|
|
@@ -23601,7 +23596,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23601
23596
|
fitToSelection() {
|
|
23602
23597
|
if (!this.enabled) return;
|
|
23603
23598
|
const stage = this.instance.getStage();
|
|
23604
|
-
const selectionPlugin = this.
|
|
23599
|
+
const selectionPlugin = this.getNodesSelectionPlugin();
|
|
23605
23600
|
if (!selectionPlugin) return;
|
|
23606
23601
|
const nodes = selectionPlugin.getTransformer().getNodes();
|
|
23607
23602
|
if (nodes.length === 0) return;
|
|
@@ -23672,10 +23667,15 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23672
23667
|
const stageContainer = this.instance.getStage().container();
|
|
23673
23668
|
const sc = new import_hammer.default.Manager(stageContainer);
|
|
23674
23669
|
sc.add(new import_hammer.default.Pinch({
|
|
23675
|
-
threshold:
|
|
23670
|
+
threshold: this.threshold,
|
|
23676
23671
|
pointers: 2
|
|
23677
23672
|
}));
|
|
23678
23673
|
sc.on("pinchstart", (e) => {
|
|
23674
|
+
if (this.getPanPlugin()?.isPanning()) {
|
|
23675
|
+
this.pinching = false;
|
|
23676
|
+
return;
|
|
23677
|
+
}
|
|
23678
|
+
this.getNodesSelectionPlugin()?.disable();
|
|
23679
23679
|
this.initialScale = this.instance.getStage().scaleX();
|
|
23680
23680
|
this.center = {
|
|
23681
23681
|
x: e.center.x,
|
|
@@ -23684,6 +23684,11 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23684
23684
|
this.lastTime = performance.now();
|
|
23685
23685
|
});
|
|
23686
23686
|
sc.on("pinchmove", (e) => {
|
|
23687
|
+
if (this.getPanPlugin()?.isPanning()) {
|
|
23688
|
+
this.pinching = false;
|
|
23689
|
+
return;
|
|
23690
|
+
}
|
|
23691
|
+
this.pinching = true;
|
|
23687
23692
|
const now = performance.now();
|
|
23688
23693
|
this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
23689
23694
|
const newScale = Math.max(this.config.zoomSteps[0], Math.min(this.config.zoomSteps[this.config.zoomSteps.length - 1], this.initialScale * e.scale));
|
|
@@ -23693,6 +23698,13 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23693
23698
|
this.lastTime = now;
|
|
23694
23699
|
});
|
|
23695
23700
|
sc.on("pinchend", () => {
|
|
23701
|
+
if (this.getPanPlugin()?.isPanning()) {
|
|
23702
|
+
this.pinching = false;
|
|
23703
|
+
this.zooming = false;
|
|
23704
|
+
return;
|
|
23705
|
+
}
|
|
23706
|
+
this.getNodesSelectionPlugin()?.enable();
|
|
23707
|
+
this.pinching = false;
|
|
23696
23708
|
this.zooming = true;
|
|
23697
23709
|
this.zoomInertiaType = WEAVE_STAGE_ZOOM_TYPE.PINCH_ZOOM;
|
|
23698
23710
|
requestAnimationFrame(this.zoomTick.bind(this));
|
|
@@ -23702,6 +23714,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23702
23714
|
const stage$1 = this.instance.getStage();
|
|
23703
23715
|
const performZoom = this.isCtrlOrMetaPressed || !this.isCtrlOrMetaPressed && e.evt.ctrlKey && e.evt.deltaMode === 0;
|
|
23704
23716
|
if (!this.enabled || !stage$1.isFocused() || !performZoom) return;
|
|
23717
|
+
this.getNodesSelectionPlugin()?.disable();
|
|
23705
23718
|
const delta = e.evt.deltaY > 0 ? 1 : -1;
|
|
23706
23719
|
this.zoomVelocity += delta;
|
|
23707
23720
|
this.isTrackpad = Math.abs(e.evt.deltaY) < 15 && e.evt.deltaMode === 0;
|
|
@@ -23734,10 +23747,27 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
23734
23747
|
pointer = stage.getPointerPosition();
|
|
23735
23748
|
}
|
|
23736
23749
|
if (!pointer) return;
|
|
23750
|
+
this.getNodesSelectionPlugin()?.enable();
|
|
23737
23751
|
this.setZoom(this.getInertiaScale(), false, pointer);
|
|
23738
23752
|
this.zoomVelocity *= this.config.zoomInertia.friction;
|
|
23753
|
+
this.getStageGridPlugin()?.onRender();
|
|
23739
23754
|
requestAnimationFrame(this.zoomTick.bind(this));
|
|
23740
23755
|
}
|
|
23756
|
+
isPinching() {
|
|
23757
|
+
return this.pinching;
|
|
23758
|
+
}
|
|
23759
|
+
getStageGridPlugin() {
|
|
23760
|
+
const gridPlugin = this.instance.getPlugin("stageGrid");
|
|
23761
|
+
return gridPlugin;
|
|
23762
|
+
}
|
|
23763
|
+
getNodesSelectionPlugin() {
|
|
23764
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
23765
|
+
return selectionPlugin;
|
|
23766
|
+
}
|
|
23767
|
+
getPanPlugin() {
|
|
23768
|
+
const panPlugin = this.instance.getPlugin("stagePanning");
|
|
23769
|
+
return panPlugin;
|
|
23770
|
+
}
|
|
23741
23771
|
getContextMenuPlugin() {
|
|
23742
23772
|
const contextMenuPlugin = this.instance.getPlugin("contextMenu");
|
|
23743
23773
|
return contextMenuPlugin;
|
|
@@ -24103,6 +24133,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24103
24133
|
onInit = void 0;
|
|
24104
24134
|
constructor() {
|
|
24105
24135
|
super();
|
|
24136
|
+
this.pointers = new Map();
|
|
24106
24137
|
this.initialized = false;
|
|
24107
24138
|
this.state = RECTANGLE_TOOL_STATE.IDLE;
|
|
24108
24139
|
this.rectId = null;
|
|
@@ -24139,6 +24170,14 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24139
24170
|
});
|
|
24140
24171
|
stage.on("pointerdown", (e) => {
|
|
24141
24172
|
this.setTapStart(e);
|
|
24173
|
+
this.pointers.set(e.evt.pointerId, {
|
|
24174
|
+
x: e.evt.clientX,
|
|
24175
|
+
y: e.evt.clientY
|
|
24176
|
+
});
|
|
24177
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === RECTANGLE_TOOL_ACTION_NAME) {
|
|
24178
|
+
this.state = RECTANGLE_TOOL_STATE.ADDING;
|
|
24179
|
+
return;
|
|
24180
|
+
}
|
|
24142
24181
|
if (this.state === RECTANGLE_TOOL_STATE.ADDING) {
|
|
24143
24182
|
this.creating = true;
|
|
24144
24183
|
this.handleAdding();
|
|
@@ -24146,12 +24185,18 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24146
24185
|
});
|
|
24147
24186
|
stage.on("pointermove", (e) => {
|
|
24148
24187
|
if (!this.isPressed(e)) return;
|
|
24188
|
+
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
24189
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === RECTANGLE_TOOL_ACTION_NAME) {
|
|
24190
|
+
this.state = RECTANGLE_TOOL_STATE.ADDING;
|
|
24191
|
+
return;
|
|
24192
|
+
}
|
|
24149
24193
|
if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) {
|
|
24150
24194
|
this.moved = true;
|
|
24151
24195
|
this.handleMovement();
|
|
24152
24196
|
}
|
|
24153
24197
|
});
|
|
24154
24198
|
stage.on("pointerup", (e) => {
|
|
24199
|
+
this.pointers.delete(e.evt.pointerId);
|
|
24155
24200
|
const isTap = this.isTap(e);
|
|
24156
24201
|
if (isTap) this.moved = false;
|
|
24157
24202
|
if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) {
|
|
@@ -24168,6 +24213,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24168
24213
|
const stage = this.instance.getStage();
|
|
24169
24214
|
stage.container().style.cursor = "crosshair";
|
|
24170
24215
|
stage.container().focus();
|
|
24216
|
+
this.instance.emitEvent("onAddingRectangle");
|
|
24171
24217
|
this.clickPoint = null;
|
|
24172
24218
|
this.setState(RECTANGLE_TOOL_STATE.ADDING);
|
|
24173
24219
|
}
|
|
@@ -24215,6 +24261,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
24215
24261
|
height: rectHeight
|
|
24216
24262
|
});
|
|
24217
24263
|
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(rectangle));
|
|
24264
|
+
this.instance.emitEvent("onAddedRectangle");
|
|
24218
24265
|
}
|
|
24219
24266
|
this.cancelAction();
|
|
24220
24267
|
}
|
|
@@ -24281,6 +24328,7 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
24281
24328
|
onInit = void 0;
|
|
24282
24329
|
constructor() {
|
|
24283
24330
|
super();
|
|
24331
|
+
this.pointers = new Map();
|
|
24284
24332
|
this.initialized = false;
|
|
24285
24333
|
this.state = ELLIPSE_TOOL_STATE.IDLE;
|
|
24286
24334
|
this.ellipseId = null;
|
|
@@ -24318,6 +24366,14 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
24318
24366
|
});
|
|
24319
24367
|
stage.on("pointerdown", (e) => {
|
|
24320
24368
|
this.setTapStart(e);
|
|
24369
|
+
this.pointers.set(e.evt.pointerId, {
|
|
24370
|
+
x: e.evt.clientX,
|
|
24371
|
+
y: e.evt.clientY
|
|
24372
|
+
});
|
|
24373
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === ELLIPSE_TOOL_ACTION_NAME) {
|
|
24374
|
+
this.state = ELLIPSE_TOOL_STATE.ADDING;
|
|
24375
|
+
return;
|
|
24376
|
+
}
|
|
24321
24377
|
if (this.state === ELLIPSE_TOOL_STATE.ADDING) {
|
|
24322
24378
|
this.creating = true;
|
|
24323
24379
|
this.handleAdding();
|
|
@@ -24325,12 +24381,18 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
24325
24381
|
});
|
|
24326
24382
|
stage.on("pointermove", (e) => {
|
|
24327
24383
|
if (!this.isPressed(e)) return;
|
|
24384
|
+
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
24385
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === ELLIPSE_TOOL_ACTION_NAME) {
|
|
24386
|
+
this.state = ELLIPSE_TOOL_STATE.ADDING;
|
|
24387
|
+
return;
|
|
24388
|
+
}
|
|
24328
24389
|
if (this.state === ELLIPSE_TOOL_STATE.DEFINING_SIZE) {
|
|
24329
24390
|
this.moved = true;
|
|
24330
24391
|
this.handleMovement();
|
|
24331
24392
|
}
|
|
24332
24393
|
});
|
|
24333
24394
|
stage.on("pointerup", (e) => {
|
|
24395
|
+
this.pointers.delete(e.evt.pointerId);
|
|
24334
24396
|
const isTap = this.isTap(e);
|
|
24335
24397
|
if (isTap) this.moved = false;
|
|
24336
24398
|
if (this.state === ELLIPSE_TOOL_STATE.DEFINING_SIZE) {
|
|
@@ -24347,6 +24409,7 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
24347
24409
|
const stage = this.instance.getStage();
|
|
24348
24410
|
stage.container().style.cursor = "crosshair";
|
|
24349
24411
|
stage.container().focus();
|
|
24412
|
+
this.instance.emitEvent("onAddingEllipse");
|
|
24350
24413
|
this.clickPoint = null;
|
|
24351
24414
|
this.setState(ELLIPSE_TOOL_STATE.ADDING);
|
|
24352
24415
|
}
|
|
@@ -24394,6 +24457,7 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
24394
24457
|
radiusY: ellipseRadiusY
|
|
24395
24458
|
});
|
|
24396
24459
|
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(ellipse));
|
|
24460
|
+
this.instance.emitEvent("onAddedEllipse");
|
|
24397
24461
|
}
|
|
24398
24462
|
this.cancelAction();
|
|
24399
24463
|
}
|
|
@@ -24471,6 +24535,7 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
24471
24535
|
onInit = void 0;
|
|
24472
24536
|
constructor() {
|
|
24473
24537
|
super();
|
|
24538
|
+
this.pointers = new Map();
|
|
24474
24539
|
this.initialized = false;
|
|
24475
24540
|
this.state = PEN_TOOL_STATE.IDLE;
|
|
24476
24541
|
this.lineId = null;
|
|
@@ -24504,19 +24569,30 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
24504
24569
|
return;
|
|
24505
24570
|
}
|
|
24506
24571
|
});
|
|
24507
|
-
stage.on("
|
|
24508
|
-
|
|
24509
|
-
|
|
24510
|
-
|
|
24572
|
+
stage.on("pointerdown", (e) => {
|
|
24573
|
+
this.setTapStart(e);
|
|
24574
|
+
this.pointers.set(e.evt.pointerId, {
|
|
24575
|
+
x: e.evt.clientX,
|
|
24576
|
+
y: e.evt.clientY
|
|
24577
|
+
});
|
|
24578
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === PEN_TOOL_ACTION_NAME) {
|
|
24579
|
+
this.state = PEN_TOOL_STATE.ADDING;
|
|
24511
24580
|
return;
|
|
24512
24581
|
}
|
|
24513
|
-
if (this.state === PEN_TOOL_STATE.
|
|
24514
|
-
|
|
24582
|
+
if (this.state === PEN_TOOL_STATE.ADDING) this.handleAdding();
|
|
24583
|
+
});
|
|
24584
|
+
stage.on("pointermove", (e) => {
|
|
24585
|
+
if (!this.isPressed(e)) return;
|
|
24586
|
+
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
24587
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === PEN_TOOL_ACTION_NAME) {
|
|
24588
|
+
this.state = PEN_TOOL_STATE.ADDING;
|
|
24515
24589
|
return;
|
|
24516
24590
|
}
|
|
24591
|
+
if (this.state === PEN_TOOL_STATE.DEFINING_SIZE) this.handleMovement();
|
|
24517
24592
|
});
|
|
24518
|
-
stage.on("
|
|
24519
|
-
this.
|
|
24593
|
+
stage.on("pointerup", (e) => {
|
|
24594
|
+
this.pointers.delete(e.evt.pointerId);
|
|
24595
|
+
if (this.state === PEN_TOOL_STATE.DEFINING_SIZE) this.handleSettingSize();
|
|
24520
24596
|
});
|
|
24521
24597
|
this.initialized = true;
|
|
24522
24598
|
}
|
|
@@ -25028,6 +25104,7 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
25028
25104
|
onInit = void 0;
|
|
25029
25105
|
constructor() {
|
|
25030
25106
|
super();
|
|
25107
|
+
this.pointers = new Map();
|
|
25031
25108
|
this.initialized = false;
|
|
25032
25109
|
this.state = STAR_TOOL_STATE.IDLE;
|
|
25033
25110
|
this.starId = null;
|
|
@@ -25066,6 +25143,14 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
25066
25143
|
});
|
|
25067
25144
|
stage.on("pointerdown", (e) => {
|
|
25068
25145
|
this.setTapStart(e);
|
|
25146
|
+
this.pointers.set(e.evt.pointerId, {
|
|
25147
|
+
x: e.evt.clientX,
|
|
25148
|
+
y: e.evt.clientY
|
|
25149
|
+
});
|
|
25150
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === STAR_TOOL_ACTION_NAME) {
|
|
25151
|
+
this.state = STAR_TOOL_STATE.ADDING;
|
|
25152
|
+
return;
|
|
25153
|
+
}
|
|
25069
25154
|
if (this.state === STAR_TOOL_STATE.ADDING) {
|
|
25070
25155
|
this.creating = true;
|
|
25071
25156
|
this.handleAdding();
|
|
@@ -25073,12 +25158,18 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
25073
25158
|
});
|
|
25074
25159
|
stage.on("pointermove", (e) => {
|
|
25075
25160
|
if (!this.isPressed(e)) return;
|
|
25161
|
+
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
25162
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === STAR_TOOL_ACTION_NAME) {
|
|
25163
|
+
this.state = STAR_TOOL_STATE.ADDING;
|
|
25164
|
+
return;
|
|
25165
|
+
}
|
|
25076
25166
|
if (this.state === STAR_TOOL_STATE.DEFINING_SIZE) {
|
|
25077
25167
|
this.moved = true;
|
|
25078
25168
|
this.handleMovement();
|
|
25079
25169
|
}
|
|
25080
25170
|
});
|
|
25081
25171
|
stage.on("pointerup", (e) => {
|
|
25172
|
+
this.pointers.delete(e.evt.pointerId);
|
|
25082
25173
|
const isTap = this.isTap(e);
|
|
25083
25174
|
if (isTap) this.moved = false;
|
|
25084
25175
|
if (this.state === STAR_TOOL_STATE.DEFINING_SIZE) {
|
|
@@ -25095,6 +25186,7 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
25095
25186
|
const stage = this.instance.getStage();
|
|
25096
25187
|
stage.container().style.cursor = "crosshair";
|
|
25097
25188
|
stage.container().focus();
|
|
25189
|
+
this.instance.emitEvent("onAddingStar");
|
|
25098
25190
|
this.clickPoint = null;
|
|
25099
25191
|
this.setState(STAR_TOOL_STATE.ADDING);
|
|
25100
25192
|
}
|
|
@@ -25143,6 +25235,7 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
25143
25235
|
innerRadius: starInnerRadius
|
|
25144
25236
|
});
|
|
25145
25237
|
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(star));
|
|
25238
|
+
this.instance.emitEvent("onAddedStar");
|
|
25146
25239
|
}
|
|
25147
25240
|
this.cancelAction();
|
|
25148
25241
|
}
|
|
@@ -25472,6 +25565,7 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
25472
25565
|
onInit = void 0;
|
|
25473
25566
|
constructor() {
|
|
25474
25567
|
super();
|
|
25568
|
+
this.pointers = new Map();
|
|
25475
25569
|
this.initialized = false;
|
|
25476
25570
|
this.state = REGULAR_POLYGON_TOOL_STATE.IDLE;
|
|
25477
25571
|
this.regularPolygonId = null;
|
|
@@ -25508,6 +25602,14 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
25508
25602
|
});
|
|
25509
25603
|
stage.on("pointerdown", (e) => {
|
|
25510
25604
|
this.setTapStart(e);
|
|
25605
|
+
this.pointers.set(e.evt.pointerId, {
|
|
25606
|
+
x: e.evt.clientX,
|
|
25607
|
+
y: e.evt.clientY
|
|
25608
|
+
});
|
|
25609
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === REGULAR_POLYGON_TOOL_ACTION_NAME) {
|
|
25610
|
+
this.state = REGULAR_POLYGON_TOOL_STATE.ADDING;
|
|
25611
|
+
return;
|
|
25612
|
+
}
|
|
25511
25613
|
if (this.state === REGULAR_POLYGON_TOOL_STATE.ADDING) {
|
|
25512
25614
|
this.creating = true;
|
|
25513
25615
|
this.handleAdding();
|
|
@@ -25515,12 +25617,18 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
25515
25617
|
});
|
|
25516
25618
|
stage.on("pointermove", (e) => {
|
|
25517
25619
|
if (!this.isPressed(e)) return;
|
|
25620
|
+
if (!this.pointers.has(e.evt.pointerId)) return;
|
|
25621
|
+
if (this.pointers.size === 2 && this.instance.getActiveAction() === REGULAR_POLYGON_TOOL_ACTION_NAME) {
|
|
25622
|
+
this.state = REGULAR_POLYGON_TOOL_STATE.ADDING;
|
|
25623
|
+
return;
|
|
25624
|
+
}
|
|
25518
25625
|
if (this.state === REGULAR_POLYGON_TOOL_STATE.DEFINING_SIZE) {
|
|
25519
25626
|
this.moved = true;
|
|
25520
25627
|
this.handleMovement();
|
|
25521
25628
|
}
|
|
25522
25629
|
});
|
|
25523
25630
|
stage.on("pointerup", (e) => {
|
|
25631
|
+
this.pointers.delete(e.evt.pointerId);
|
|
25524
25632
|
const isTap = this.isTap(e);
|
|
25525
25633
|
if (isTap) this.moved = false;
|
|
25526
25634
|
if (this.state === REGULAR_POLYGON_TOOL_STATE.DEFINING_SIZE) {
|
|
@@ -25537,6 +25645,7 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
25537
25645
|
const stage = this.instance.getStage();
|
|
25538
25646
|
stage.container().style.cursor = "crosshair";
|
|
25539
25647
|
stage.container().focus();
|
|
25648
|
+
this.instance.emitEvent("onAddingRegularPolygon");
|
|
25540
25649
|
this.clickPoint = null;
|
|
25541
25650
|
this.setState(REGULAR_POLYGON_TOOL_STATE.ADDING);
|
|
25542
25651
|
}
|
|
@@ -25580,6 +25689,7 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
25580
25689
|
radius: newRadius
|
|
25581
25690
|
});
|
|
25582
25691
|
if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(regularPolygon));
|
|
25692
|
+
this.instance.emitEvent("onAddedRegularPolygon");
|
|
25583
25693
|
}
|
|
25584
25694
|
this.cancelAction();
|
|
25585
25695
|
}
|
|
@@ -26156,6 +26266,9 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
26156
26266
|
window.addEventListener("keyup", (e) => {
|
|
26157
26267
|
if (e.code === "Space") this.isSpaceKeyPressed = false;
|
|
26158
26268
|
});
|
|
26269
|
+
this.instance.addEventListener("onStageMove", () => {
|
|
26270
|
+
this.onRender();
|
|
26271
|
+
});
|
|
26159
26272
|
stage.on("pointerdown", (e) => {
|
|
26160
26273
|
const activeAction = this.instance.getActiveAction();
|
|
26161
26274
|
if (e && e.evt.button === 0 && activeAction === "moveTool") this.moveToolActive = true;
|
|
@@ -26348,7 +26461,9 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
26348
26461
|
}
|
|
26349
26462
|
}
|
|
26350
26463
|
onRender() {
|
|
26351
|
-
|
|
26464
|
+
requestAnimationFrame(() => {
|
|
26465
|
+
this.renderGrid();
|
|
26466
|
+
});
|
|
26352
26467
|
}
|
|
26353
26468
|
enable() {
|
|
26354
26469
|
this.enabled = true;
|
|
@@ -26376,11 +26491,18 @@ const WEAVE_STAGE_PANNING_KEY = "stagePanning";
|
|
|
26376
26491
|
//#endregion
|
|
26377
26492
|
//#region src/plugins/stage-panning/stage-panning.ts
|
|
26378
26493
|
var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
26494
|
+
pinching = false;
|
|
26495
|
+
panning = false;
|
|
26379
26496
|
getLayerName = void 0;
|
|
26380
26497
|
initLayer = void 0;
|
|
26381
26498
|
constructor() {
|
|
26382
26499
|
super();
|
|
26383
|
-
this.
|
|
26500
|
+
this.pointers = new Map();
|
|
26501
|
+
this.lastCenter = null;
|
|
26502
|
+
this.pinching = false;
|
|
26503
|
+
this.panning = false;
|
|
26504
|
+
this.threshold = 5;
|
|
26505
|
+
this.pointersDistanceDiffThreshold = 10;
|
|
26384
26506
|
this.enabled = true;
|
|
26385
26507
|
this.moveToolActive = false;
|
|
26386
26508
|
this.isMouseMiddleButtonPressed = false;
|
|
@@ -26424,6 +26546,8 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
26424
26546
|
this.disableMove();
|
|
26425
26547
|
}
|
|
26426
26548
|
});
|
|
26549
|
+
let startPointersDistance = null;
|
|
26550
|
+
let startCenter = null;
|
|
26427
26551
|
let lastPos = null;
|
|
26428
26552
|
let isDragging = false;
|
|
26429
26553
|
let velocity = {
|
|
@@ -26432,7 +26556,10 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
26432
26556
|
};
|
|
26433
26557
|
let lastTime = 0;
|
|
26434
26558
|
stage.on("pointerdown", (e) => {
|
|
26435
|
-
this.
|
|
26559
|
+
this.pointers.set(e.evt.pointerId, {
|
|
26560
|
+
x: e.evt.clientX,
|
|
26561
|
+
y: e.evt.clientY
|
|
26562
|
+
});
|
|
26436
26563
|
const activeAction = this.instance.getActiveAction();
|
|
26437
26564
|
let enableMove = false;
|
|
26438
26565
|
if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 1) && activeAction === "moveTool") {
|
|
@@ -26443,6 +26570,27 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
26443
26570
|
this.isMouseMiddleButtonPressed = true;
|
|
26444
26571
|
enableMove = true;
|
|
26445
26572
|
}
|
|
26573
|
+
if (e.evt.pointerType !== "mouse" && this.pointers.size === 2 && !this.pinching && !this.panning) {
|
|
26574
|
+
const center = this.getTouchCenter();
|
|
26575
|
+
const [p1, p2] = Array.from(this.pointers.values());
|
|
26576
|
+
const pointersDistance = this.getDistance(p1, p2);
|
|
26577
|
+
if (!startCenter) {
|
|
26578
|
+
startPointersDistance = pointersDistance;
|
|
26579
|
+
startCenter = center;
|
|
26580
|
+
this.lastCenter = center;
|
|
26581
|
+
this.pinching = false;
|
|
26582
|
+
this.panning = false;
|
|
26583
|
+
velocity = {
|
|
26584
|
+
x: 0,
|
|
26585
|
+
y: 0
|
|
26586
|
+
};
|
|
26587
|
+
}
|
|
26588
|
+
isDragging = true;
|
|
26589
|
+
lastPos = stage.getPointerPosition();
|
|
26590
|
+
lastTime = performance.now();
|
|
26591
|
+
this.enableMove();
|
|
26592
|
+
return;
|
|
26593
|
+
}
|
|
26446
26594
|
if (enableMove) {
|
|
26447
26595
|
isDragging = true;
|
|
26448
26596
|
lastPos = stage.getPointerPosition();
|
|
@@ -26454,28 +26602,65 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
26454
26602
|
this.enableMove();
|
|
26455
26603
|
}
|
|
26456
26604
|
});
|
|
26457
|
-
stage.on("pointercancel", () => {
|
|
26605
|
+
stage.on("pointercancel", (e) => {
|
|
26606
|
+
this.pointers.delete(e.evt.pointerId);
|
|
26458
26607
|
lastPos = null;
|
|
26608
|
+
this.lastCenter = null;
|
|
26459
26609
|
});
|
|
26460
|
-
|
|
26461
|
-
this.
|
|
26462
|
-
|
|
26463
|
-
|
|
26464
|
-
|
|
26465
|
-
velocity.x *= decay;
|
|
26466
|
-
velocity.y *= decay;
|
|
26467
|
-
if (Math.abs(velocity.x) < .01 && Math.abs(velocity.y) < .01) return;
|
|
26468
|
-
stage.x(stage.x() + velocity.x * 16);
|
|
26469
|
-
stage.y(stage.y() + velocity.y * 16);
|
|
26470
|
-
stage.batchDraw();
|
|
26471
|
-
requestAnimationFrame(animateInertia);
|
|
26472
|
-
}
|
|
26473
|
-
requestAnimationFrame(animateInertia);
|
|
26474
|
-
});
|
|
26475
|
-
const handleMouseMove = () => {
|
|
26476
|
-
if (this.activePointers.size !== 1) return;
|
|
26610
|
+
const handleMouseMove = (e) => {
|
|
26611
|
+
this.pointers.set(e.evt.pointerId, {
|
|
26612
|
+
x: e.evt.clientX,
|
|
26613
|
+
y: e.evt.clientY
|
|
26614
|
+
});
|
|
26477
26615
|
if (!isDragging) return;
|
|
26616
|
+
const center = this.getTouchCenter();
|
|
26617
|
+
if (e.evt.pointerType !== "mouse" && this.pointers.size !== 2) {
|
|
26618
|
+
startCenter = null;
|
|
26619
|
+
startPointersDistance = null;
|
|
26620
|
+
this.pinching = false;
|
|
26621
|
+
this.panning = false;
|
|
26622
|
+
}
|
|
26623
|
+
if (e.evt.pointerType !== "mouse" && this.pointers.size === 2) {
|
|
26624
|
+
this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
26625
|
+
const [p1, p2] = Array.from(this.pointers.values());
|
|
26626
|
+
const pointersDistance = this.getDistance(p1, p2);
|
|
26627
|
+
if (!startCenter) {
|
|
26628
|
+
startPointersDistance = pointersDistance;
|
|
26629
|
+
startCenter = center;
|
|
26630
|
+
this.lastCenter = center;
|
|
26631
|
+
this.pinching = false;
|
|
26632
|
+
this.panning = false;
|
|
26633
|
+
}
|
|
26634
|
+
if (center && startCenter && startPointersDistance && this.lastCenter) {
|
|
26635
|
+
const now$1 = performance.now();
|
|
26636
|
+
const dt$1 = now$1 - lastTime;
|
|
26637
|
+
const dx = center.x - startCenter.x;
|
|
26638
|
+
const dy = center.y - startCenter.y;
|
|
26639
|
+
const distanceCenters = Math.hypot(dx, dy);
|
|
26640
|
+
const distanceChange = Math.abs(pointersDistance - startPointersDistance);
|
|
26641
|
+
if (!this.pinching && distanceCenters > this.threshold && distanceChange <= this.pointersDistanceDiffThreshold) this.panning = true;
|
|
26642
|
+
if (!this.panning && distanceCenters <= this.threshold && distanceChange > this.pointersDistanceDiffThreshold) this.pinching = true;
|
|
26643
|
+
if (this.panning) {
|
|
26644
|
+
this.getNodesSelectionPlugin()?.disable();
|
|
26645
|
+
const dx$1 = center.x - this.lastCenter.x;
|
|
26646
|
+
const dy$1 = center.y - this.lastCenter.y;
|
|
26647
|
+
velocity = {
|
|
26648
|
+
x: dx$1 / dt$1,
|
|
26649
|
+
y: dy$1 / dt$1
|
|
26650
|
+
};
|
|
26651
|
+
stage.x(stage.x() + dx$1);
|
|
26652
|
+
stage.y(stage.y() + dy$1);
|
|
26653
|
+
this.instance.emitEvent("onStageMove");
|
|
26654
|
+
}
|
|
26655
|
+
this.lastCenter = center;
|
|
26656
|
+
lastTime = now$1;
|
|
26657
|
+
return;
|
|
26658
|
+
}
|
|
26659
|
+
}
|
|
26660
|
+
this.lastCenter = center;
|
|
26478
26661
|
if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
|
|
26662
|
+
this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
26663
|
+
this.getNodesSelectionPlugin()?.disable();
|
|
26479
26664
|
const pos = stage.getPointerPosition();
|
|
26480
26665
|
const now = performance.now();
|
|
26481
26666
|
const dt = now - lastTime;
|
|
@@ -26488,20 +26673,50 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
26488
26673
|
};
|
|
26489
26674
|
stage.x(stage.x() + dx);
|
|
26490
26675
|
stage.y(stage.y() + dy);
|
|
26491
|
-
stage.batchDraw();
|
|
26492
26676
|
}
|
|
26493
26677
|
lastPos = pos;
|
|
26494
26678
|
lastTime = now;
|
|
26495
26679
|
this.instance.emitEvent("onStageMove");
|
|
26496
26680
|
};
|
|
26497
26681
|
stage.on("pointermove", handleMouseMove);
|
|
26682
|
+
const decay = .95;
|
|
26683
|
+
const animateInertia = () => {
|
|
26684
|
+
velocity.x *= decay;
|
|
26685
|
+
velocity.y *= decay;
|
|
26686
|
+
if (Math.abs(velocity.x) < .01 && Math.abs(velocity.y) < .01) return;
|
|
26687
|
+
stage.x(stage.x() + velocity.x);
|
|
26688
|
+
stage.y(stage.y() + velocity.y);
|
|
26689
|
+
this.instance.emitEvent("onStageMove");
|
|
26690
|
+
requestAnimationFrame(animateInertia);
|
|
26691
|
+
};
|
|
26692
|
+
stage.on("pointerup", (e) => {
|
|
26693
|
+
this.pointers.delete(e.evt.pointerId);
|
|
26694
|
+
if (e.evt.pointerType !== "mouse" && this.pointers.size < 2) {
|
|
26695
|
+
this.getNodesSelectionPlugin()?.enable();
|
|
26696
|
+
isDragging = false;
|
|
26697
|
+
startCenter = null;
|
|
26698
|
+
startPointersDistance = null;
|
|
26699
|
+
this.lastCenter = null;
|
|
26700
|
+
this.pinching = false;
|
|
26701
|
+
this.panning = false;
|
|
26702
|
+
requestAnimationFrame(animateInertia);
|
|
26703
|
+
return;
|
|
26704
|
+
}
|
|
26705
|
+
isDragging = false;
|
|
26706
|
+
this.pinching = false;
|
|
26707
|
+
this.panning = false;
|
|
26708
|
+
requestAnimationFrame(animateInertia);
|
|
26709
|
+
});
|
|
26498
26710
|
const handleWheel = (e) => {
|
|
26499
26711
|
e.evt.preventDefault();
|
|
26500
26712
|
const stage$1 = this.instance.getStage();
|
|
26501
26713
|
const performPanning = !this.isCtrlOrMetaPressed && !e.evt.ctrlKey;
|
|
26502
26714
|
if (!this.enabled || !stage$1.isFocused() || this.isCtrlOrMetaPressed || e.evt.buttons === 4 || !performPanning) return;
|
|
26715
|
+
this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
26716
|
+
this.getNodesSelectionPlugin()?.disable();
|
|
26503
26717
|
stage$1.x(stage$1.x() - e.evt.deltaX);
|
|
26504
26718
|
stage$1.y(stage$1.y() - e.evt.deltaY);
|
|
26719
|
+
this.getNodesSelectionPlugin()?.enable();
|
|
26505
26720
|
this.instance.emitEvent("onStageMove");
|
|
26506
26721
|
};
|
|
26507
26722
|
stage.on("wheel", handleWheel);
|
|
@@ -26512,6 +26727,35 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
26512
26727
|
e.preventDefault();
|
|
26513
26728
|
}, { passive: false });
|
|
26514
26729
|
}
|
|
26730
|
+
isPanning() {
|
|
26731
|
+
return this.panning;
|
|
26732
|
+
}
|
|
26733
|
+
getDistance(p1, p2) {
|
|
26734
|
+
const dx = p2.x - p1.x;
|
|
26735
|
+
const dy = p2.y - p1.y;
|
|
26736
|
+
return Math.hypot(dx, dy);
|
|
26737
|
+
}
|
|
26738
|
+
getTouchCenter() {
|
|
26739
|
+
const points = Array.from(this.pointers.values());
|
|
26740
|
+
if (points.length !== 2) return null;
|
|
26741
|
+
const [p1, p2] = points;
|
|
26742
|
+
return {
|
|
26743
|
+
x: (p1.x + p2.x) / 2,
|
|
26744
|
+
y: (p1.y + p2.y) / 2
|
|
26745
|
+
};
|
|
26746
|
+
}
|
|
26747
|
+
getNodesSelectionPlugin() {
|
|
26748
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
26749
|
+
return selectionPlugin;
|
|
26750
|
+
}
|
|
26751
|
+
getZoomPlugin() {
|
|
26752
|
+
const zoomPlugin = this.instance.getPlugin("stageZoom");
|
|
26753
|
+
return zoomPlugin;
|
|
26754
|
+
}
|
|
26755
|
+
getContextMenuPlugin() {
|
|
26756
|
+
const contextMenuPlugin = this.instance.getPlugin("contextMenu");
|
|
26757
|
+
return contextMenuPlugin;
|
|
26758
|
+
}
|
|
26515
26759
|
enable() {
|
|
26516
26760
|
this.enabled = true;
|
|
26517
26761
|
}
|