@inditextech/weave-sdk 0.32.0 → 0.33.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/dist/sdk.cjs CHANGED
@@ -15646,6 +15646,7 @@ const WEAVE_NODES_SELECTION_LAYER_ID = "selectionLayer";
15646
15646
  const WEAVE_CONTEXT_MENU_KEY = "contextMenu";
15647
15647
  const WEAVE_CONTEXT_MENU_X_OFFSET_DEFAULT = 4;
15648
15648
  const WEAVE_CONTEXT_MENU_Y_OFFSET_DEFAULT = 4;
15649
+ const WEAVE_CONTEXT_MENU_TAP_HOLD_TIMEOUT = 500;
15649
15650
 
15650
15651
  //#endregion
15651
15652
  //#region src/plugins/context-menu/context-menu.ts
@@ -15657,13 +15658,14 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
15657
15658
  this.touchTimer = void 0;
15658
15659
  this.tapHold = false;
15659
15660
  this.contextMenuVisible = false;
15660
- this.tapHoldTimeout = 500;
15661
+ this.tapHoldTimeout = WEAVE_CONTEXT_MENU_TAP_HOLD_TIMEOUT;
15661
15662
  const { config } = params ?? {};
15662
15663
  this.config = {
15663
15664
  xOffset: WEAVE_CONTEXT_MENU_X_OFFSET_DEFAULT,
15664
15665
  yOffset: WEAVE_CONTEXT_MENU_Y_OFFSET_DEFAULT,
15665
15666
  ...config
15666
15667
  };
15668
+ this.pointers = {};
15667
15669
  }
15668
15670
  getName() {
15669
15671
  return WEAVE_CONTEXT_MENU_KEY;
@@ -15721,28 +15723,24 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
15721
15723
  }
15722
15724
  initEvents() {
15723
15725
  const stage = this.instance.getStage();
15724
- stage.on("touchstart", (e) => {
15725
- e.evt.preventDefault();
15726
- if (e.evt instanceof TouchEvent && e.evt.touches && e.evt.touches.length > 1) {
15727
- if (this.touchTimer) clearTimeout(this.touchTimer);
15728
- return;
15729
- }
15726
+ stage.on("pointerdown", (e) => {
15727
+ this.pointers[e.evt.pointerId] = e.evt;
15728
+ if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
15730
15729
  this.touchTimer = setTimeout(() => {
15731
15730
  this.tapHold = true;
15732
15731
  this.triggerContextMenu(e.target);
15733
15732
  }, this.tapHoldTimeout);
15734
15733
  });
15735
- stage.on("touchmove", () => {
15734
+ stage.on("pointermove", () => {
15736
15735
  if (this.touchTimer) clearTimeout(this.touchTimer);
15737
15736
  });
15738
- stage.on("touchend", (e) => {
15739
- e.evt.preventDefault();
15740
- if (e.evt instanceof TouchEvent && e.evt.touches && e.evt.touches.length > 1) {
15741
- if (this.touchTimer) clearTimeout(this.touchTimer);
15742
- return;
15737
+ stage.on("pointerup", (e) => {
15738
+ delete this.pointers[e.evt.pointerId];
15739
+ if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) return;
15740
+ if (this.touchTimer) {
15741
+ clearTimeout(this.touchTimer);
15742
+ this.tapHold = false;
15743
15743
  }
15744
- if (this.touchTimer) clearTimeout(this.touchTimer);
15745
- if (this.tapHold) this.tapHold = false;
15746
15744
  });
15747
15745
  stage.on("contextmenu", (e) => {
15748
15746
  e.evt.preventDefault();
@@ -15960,8 +15958,10 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15960
15958
  this.active = false;
15961
15959
  this.cameFromSelectingMultiple = false;
15962
15960
  this.selecting = false;
15961
+ this.dragging = false;
15963
15962
  this.initialized = false;
15964
15963
  this.enabled = false;
15964
+ this.pointers = {};
15965
15965
  }
15966
15966
  getName() {
15967
15967
  return WEAVE_NODES_SELECTION_KEY;
@@ -16009,20 +16009,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16009
16009
  ...this.config.transformer
16010
16010
  });
16011
16011
  selectionLayer?.add(tr);
16012
- tr.on("mouseenter", (e) => {
16013
- if (!this.isPasting()) {
16014
- const stage$1 = this.instance.getStage();
16015
- stage$1.container().style.cursor = "grab";
16016
- e.cancelBubble = true;
16017
- }
16018
- });
16019
- tr.on("mouseleave", (e) => {
16020
- if (!this.isPasting()) {
16021
- const stage$1 = this.instance.getStage();
16022
- stage$1.container().style.cursor = "default";
16023
- e.cancelBubble = true;
16024
- }
16025
- });
16026
16012
  tr.on("transformstart", () => {
16027
16013
  this.triggerSelectedNodesEvent();
16028
16014
  });
@@ -16034,6 +16020,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16034
16020
  this.triggerSelectedNodesEvent();
16035
16021
  });
16036
16022
  tr.on("dragstart", (e) => {
16023
+ this.dragging = true;
16037
16024
  const stage$1 = this.instance.getStage();
16038
16025
  if (stage$1.isMouseWheelPressed()) {
16039
16026
  e.cancelBubble = true;
@@ -16070,6 +16057,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16070
16057
  };
16071
16058
  tr.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 50));
16072
16059
  tr.on("dragend", (e) => {
16060
+ this.dragging = false;
16073
16061
  e.cancelBubble = true;
16074
16062
  const selectedNodes = tr.nodes();
16075
16063
  for (let i = 0; i < selectedNodes.length; i++) {
@@ -16104,11 +16092,11 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16104
16092
  });
16105
16093
  this.tr = tr;
16106
16094
  this.selectionRectangle = selectionRectangle;
16107
- this.tr.on("dblclick dbltap", (evt) => {
16108
- evt.cancelBubble = true;
16095
+ this.tr.on("pointerdblclick", (e) => {
16096
+ e.cancelBubble = true;
16109
16097
  if (this.tr.getNodes().length === 1) {
16110
16098
  const node = this.tr.getNodes()[0];
16111
- node.fire("dblclick");
16099
+ node.fire("pointerdblclick");
16112
16100
  }
16113
16101
  });
16114
16102
  this.initEvents();
@@ -16172,14 +16160,14 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16172
16160
  return;
16173
16161
  }
16174
16162
  });
16175
- stage.on("mousedown touchstart", (e) => {
16163
+ stage.on("pointerdown", (e) => {
16164
+ this.pointers[e.evt.pointerId] = e.evt;
16176
16165
  if (!this.initialized) return;
16177
16166
  if (!this.active) return;
16178
- if (e.evt.button && e.evt.button !== 0) return;
16179
- if (e.evt.touches && e.evt.touches.length > 1) return;
16167
+ if (e.evt.pointerType === "mouse" && e.evt.button !== 0) return;
16168
+ if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16180
16169
  const selectedGroup = this.instance.getInstanceRecursive(e.target);
16181
16170
  if (!(e.target instanceof konva.default.Stage) && !(selectedGroup && selectedGroup.getAttrs().nodeType === "frame")) return;
16182
- e.evt.preventDefault();
16183
16171
  const intStage = this.instance.getStage();
16184
16172
  x1 = intStage.getRelativePointerPosition()?.x ?? 0;
16185
16173
  y1 = intStage.getRelativePointerPosition()?.y ?? 0;
@@ -16196,7 +16184,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16196
16184
  const handleMouseMove = (e) => {
16197
16185
  if (!this.initialized) return;
16198
16186
  if (!this.active) return;
16199
- if (e.evt instanceof TouchEvent && e.evt.touches && e.evt.touches.length > 1) return;
16187
+ if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16200
16188
  const contextMenuPlugin = this.instance.getPlugin("contextMenu");
16201
16189
  if (contextMenuPlugin && contextMenuPlugin.isContextMenuVisible()) {
16202
16190
  this.selecting = false;
@@ -16206,7 +16194,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16206
16194
  this.cameFromSelectingMultiple = false;
16207
16195
  return;
16208
16196
  }
16209
- e.evt.preventDefault();
16210
16197
  const intStage = this.instance.getStage();
16211
16198
  x2 = intStage.getRelativePointerPosition()?.x ?? 0;
16212
16199
  y2 = intStage.getRelativePointerPosition()?.y ?? 0;
@@ -16218,11 +16205,13 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16218
16205
  height: Math.abs(y2 - y1)
16219
16206
  });
16220
16207
  };
16221
- stage.on("mousemove touchmove", (0, import_lodash.throttle)(handleMouseMove, 50));
16222
- stage.on("mouseup touchend", (e) => {
16208
+ stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
16209
+ stage.on("pointerup", (e) => {
16210
+ delete this.pointers[e.evt.pointerId];
16223
16211
  if (!this.initialized) return;
16224
16212
  if (!this.active) return;
16225
- if (e.evt instanceof TouchEvent && e.evt.touches && e.evt.touches.length > 1) return;
16213
+ if (!this.selecting) return;
16214
+ if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) return;
16226
16215
  const contextMenuPlugin = this.instance.getPlugin("contextMenu");
16227
16216
  if (contextMenuPlugin && contextMenuPlugin.isContextMenuVisible()) {
16228
16217
  this.selecting = false;
@@ -16234,7 +16223,6 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16234
16223
  this.cameFromSelectingMultiple = false;
16235
16224
  return;
16236
16225
  }
16237
- e.evt.preventDefault();
16238
16226
  this.tr.nodes([]);
16239
16227
  this.selectionRectangle.visible(false);
16240
16228
  const shapes = stage.find((node) => {
@@ -16270,9 +16258,10 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16270
16258
  stage.container().tabIndex = 1;
16271
16259
  stage.container().focus();
16272
16260
  });
16273
- stage.on("click tap", (e) => {
16261
+ stage.on("pointerclick", (e) => {
16274
16262
  if (!this.enabled) return;
16275
16263
  if (this.instance.getActiveAction() !== "selectionTool") return;
16264
+ if (this.dragging) return;
16276
16265
  const contextMenuPlugin = this.instance.getPlugin("contextMenu");
16277
16266
  if (contextMenuPlugin && contextMenuPlugin.isContextMenuVisible()) {
16278
16267
  this.selecting = false;
@@ -16746,37 +16735,33 @@ var WeaveNode = class {
16746
16735
  }
16747
16736
  });
16748
16737
  this.previousPointer = null;
16749
- node.on("mouseenter", (e) => {
16738
+ node.on("pointerenter", () => {
16750
16739
  const realNode = this.instance.getInstanceRecursive(node);
16751
16740
  if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
16752
16741
  const stage = this.instance.getStage();
16753
16742
  this.previousPointer = stage.container().style.cursor;
16754
16743
  stage.container().style.cursor = "pointer";
16755
- e.cancelBubble = true;
16756
16744
  return;
16757
16745
  }
16758
16746
  if (this.isPasting()) {
16759
16747
  const stage = this.instance.getStage();
16760
16748
  this.previousPointer = stage.container().style.cursor;
16761
16749
  stage.container().style.cursor = "crosshair";
16762
- e.cancelBubble = true;
16763
16750
  return;
16764
16751
  }
16765
16752
  });
16766
- node.on("mouseleave", (e) => {
16753
+ node.on("pointerleave", () => {
16767
16754
  const realNode = this.instance.getInstanceRecursive(node);
16768
16755
  if (this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting()) {
16769
16756
  const stage = this.instance.getStage();
16770
16757
  stage.container().style.cursor = this.previousPointer ?? "default";
16771
16758
  this.previousPointer = null;
16772
- e.cancelBubble = true;
16773
16759
  return;
16774
16760
  }
16775
16761
  if (this.isPasting()) {
16776
16762
  const stage = this.instance.getStage();
16777
16763
  this.previousPointer = stage.container().style.cursor;
16778
16764
  stage.container().style.cursor = "crosshair";
16779
- e.cancelBubble = true;
16780
16765
  return;
16781
16766
  }
16782
16767
  });
@@ -18049,6 +18034,7 @@ var WeaveStateManager = class {
18049
18034
  };
18050
18035
  parent.props.children.push(finalNode);
18051
18036
  }
18037
+ this.instance.emitEvent("onNodeAdded", node);
18052
18038
  if (doRender) this.instance.render();
18053
18039
  }, userName);
18054
18040
  }
@@ -18078,6 +18064,7 @@ var WeaveStateManager = class {
18078
18064
  ...node.props
18079
18065
  }));
18080
18066
  nodeState.props = { ...nodeNew };
18067
+ this.instance.emitEvent("onNodeUpdated", node);
18081
18068
  if (doRender) this.instance.render();
18082
18069
  }, userName);
18083
18070
  }
@@ -18107,6 +18094,7 @@ var WeaveStateManager = class {
18107
18094
  const filteredChildren = newChildren.filter((actNode) => actNode.key !== node.key);
18108
18095
  parentState.props.children = filteredChildren;
18109
18096
  }
18097
+ this.instance.emitEvent("onNodeRemoved", node);
18110
18098
  if (doRender) this.instance.render();
18111
18099
  }, userName);
18112
18100
  }
@@ -18242,7 +18230,7 @@ var WeaveRegisterManager = class {
18242
18230
 
18243
18231
  //#endregion
18244
18232
  //#region package.json
18245
- var version = "0.32.0";
18233
+ var version = "0.33.0";
18246
18234
 
18247
18235
  //#endregion
18248
18236
  //#region src/managers/setup.ts
@@ -18477,6 +18465,7 @@ var WeaveExportManager = class {
18477
18465
  y: unscaledBounds.y - padding,
18478
18466
  width: unscaledBounds.width + 2 * padding,
18479
18467
  height: unscaledBounds.height + 2 * padding,
18468
+ strokeWidth: 0,
18480
18469
  fill: backgroundColor
18481
18470
  });
18482
18471
  exportGroup.add(background);
@@ -18492,10 +18481,10 @@ var WeaveExportManager = class {
18492
18481
  mainLayer.add(exportGroup);
18493
18482
  const backgroundRect = background.getClientRect();
18494
18483
  exportGroup.toImage({
18495
- x: backgroundRect.x,
18496
- y: backgroundRect.y,
18497
- width: backgroundRect.width,
18498
- height: backgroundRect.height,
18484
+ x: Math.round(backgroundRect.x),
18485
+ y: Math.round(backgroundRect.y),
18486
+ width: Math.round(backgroundRect.width),
18487
+ height: Math.round(backgroundRect.height),
18499
18488
  mimeType: format$2,
18500
18489
  pixelRatio,
18501
18490
  quality: options.quality ?? 1,
@@ -18898,10 +18887,10 @@ var WeaveStageNode = class extends WeaveNode {
18898
18887
  stage.container().addEventListener("blur", () => {
18899
18888
  this.stageFocused = false;
18900
18889
  });
18901
- stage.on("mousedown", (e) => {
18890
+ stage.on("pointerdown", (e) => {
18902
18891
  if (e.evt.button === 1) this.wheelMousePressed = true;
18903
18892
  });
18904
- stage.on("mouseup", (e) => {
18893
+ stage.on("pointerup", (e) => {
18905
18894
  if (e.evt.button === 1) this.wheelMousePressed = false;
18906
18895
  });
18907
18896
  stage.batchDraw();
@@ -19237,7 +19226,7 @@ var WeaveTextNode = class extends WeaveNode {
19237
19226
  }
19238
19227
  }
19239
19228
  });
19240
- text.on("dblclick dbltap", (e) => {
19229
+ text.on("pointerdblclick", (e) => {
19241
19230
  e.cancelBubble = true;
19242
19231
  if (this.editing) return;
19243
19232
  if (!(this.isSelecting() && this.isNodeSelected(text))) return;
@@ -19485,7 +19474,7 @@ var WeaveTextNode = class extends WeaveNode {
19485
19474
  this.removeTextAreaDOM(textNode);
19486
19475
  this.instance.removeEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
19487
19476
  this.instance.removeEventListener("onStageMove", this.onStageMoveHandler(textNode).bind(this));
19488
- window.removeEventListener("click", handleOutsideClick);
19477
+ window.removeEventListener("pointerclick", handleOutsideClick);
19489
19478
  return;
19490
19479
  }
19491
19480
  };
@@ -19514,14 +19503,14 @@ var WeaveTextNode = class extends WeaveNode {
19514
19503
  this.removeTextAreaDOM(textNode);
19515
19504
  this.textArea.removeEventListener("keydown", handleKeyDown);
19516
19505
  this.textArea.removeEventListener("keyup", handleKeyUp);
19517
- window.removeEventListener("click", handleOutsideClick);
19518
- window.removeEventListener("touchstart", handleOutsideClick);
19506
+ window.removeEventListener("pointerclick", handleOutsideClick);
19507
+ window.removeEventListener("pointerdown", handleOutsideClick);
19519
19508
  return;
19520
19509
  }
19521
19510
  };
19522
19511
  setTimeout(() => {
19523
- window.addEventListener("click", handleOutsideClick);
19524
- window.addEventListener("touchstart", handleOutsideClick);
19512
+ window.addEventListener("pointerclick", handleOutsideClick);
19513
+ window.addEventListener("pointerdown", handleOutsideClick);
19525
19514
  }, 0);
19526
19515
  this.editing = true;
19527
19516
  }
@@ -19673,8 +19662,7 @@ var WeaveImageToolAction = class extends WeaveAction {
19673
19662
  return;
19674
19663
  }
19675
19664
  });
19676
- stage.on("click tap", (e) => {
19677
- e.evt.preventDefault();
19665
+ stage.on("pointerclick", () => {
19678
19666
  if (this.state === IMAGE_TOOL_STATE.IDLE) return;
19679
19667
  if (this.state === IMAGE_TOOL_STATE.UPLOADING) return;
19680
19668
  if (this.state === IMAGE_TOOL_STATE.ADDING) {
@@ -19682,8 +19670,7 @@ var WeaveImageToolAction = class extends WeaveAction {
19682
19670
  return;
19683
19671
  }
19684
19672
  });
19685
- stage.on("mousemove touchmove", (e) => {
19686
- e.evt.preventDefault();
19673
+ stage.on("pointermove", () => {
19687
19674
  const tempImage = this.instance.getStage().findOne(`#${this.tempImageId}`);
19688
19675
  if (this.state === IMAGE_TOOL_STATE.ADDING && tempImage) {
19689
19676
  const mousePos = stage.getRelativePointerPosition();
@@ -20294,7 +20281,7 @@ var WeaveImageNode = class extends WeaveNode {
20294
20281
  });
20295
20282
  image.add(cropGroup);
20296
20283
  this.setupDefaultNodeEvents(image);
20297
- image.on("dblclick dbltap", (evt) => {
20284
+ image.on("pointerdblclick", (evt) => {
20298
20285
  evt.cancelBubble = true;
20299
20286
  if (image.getAttrs().cropping ?? false) return;
20300
20287
  if (!internalImage.getAttr("image")) return;
@@ -22752,7 +22739,6 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22752
22739
  ...config
22753
22740
  };
22754
22741
  if (!this.config.zoomSteps.includes(this.config.defaultZoom)) throw new Error(`Default zoom ${this.config.defaultZoom} is not in zoom steps`);
22755
- this.isSpaceKeyPressed = false;
22756
22742
  this.isCtrlOrMetaPressed = false;
22757
22743
  this.updatedMinimumZoom = false;
22758
22744
  this.actualStep = this.config.zoomSteps.findIndex((step) => step === this.config.defaultZoom);
@@ -22992,11 +22978,9 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22992
22978
  initEvents() {
22993
22979
  window.addEventListener("keydown", (e) => {
22994
22980
  if (e.ctrlKey || e.metaKey) this.isCtrlOrMetaPressed = true;
22995
- if (e.code === "Space") this.isSpaceKeyPressed = true;
22996
22981
  });
22997
22982
  window.addEventListener("keyup", (e) => {
22998
22983
  if (!(e.ctrlKey || e.metaKey)) this.isCtrlOrMetaPressed = false;
22999
- if (e.code === "Space") this.isSpaceKeyPressed = false;
23000
22984
  });
23001
22985
  const stage = this.instance.getStage();
23002
22986
  const stageContainer = this.instance.getStage().container();
@@ -23022,17 +23006,20 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
23022
23006
  const newScale = initialScale * ev.scale;
23023
23007
  this.setZoom(newScale, false, center);
23024
23008
  });
23025
- window.addEventListener("wheel", (e) => {
23009
+ const handleWheel = (e) => {
23010
+ e.evt.preventDefault();
23026
23011
  const stage$1 = this.instance.getStage();
23027
- if (!this.enabled || !stage$1.isFocused() || !this.isCtrlOrMetaPressed || this.isSpaceKeyPressed) return;
23012
+ const performZoom = this.isCtrlOrMetaPressed || !this.isCtrlOrMetaPressed && e.evt.ctrlKey && e.evt.deltaMode === 0;
23013
+ if (!this.enabled || !stage$1.isFocused() || !performZoom) return;
23028
23014
  const oldScale = stage$1.scaleX();
23029
23015
  const pointer = stage$1.getPointerPosition();
23030
23016
  if (!pointer) return;
23031
23017
  const scaleBy = 1.025;
23032
- const direction = e.deltaY > 0 ? 1 : -1;
23018
+ const direction = e.evt.deltaY > 0 ? 1 : -1;
23033
23019
  const newScale = direction > 0 ? oldScale / scaleBy : oldScale * scaleBy;
23034
23020
  this.setZoom(newScale, false, pointer);
23035
- });
23021
+ };
23022
+ stage.on("wheel", handleWheel);
23036
23023
  }
23037
23024
  };
23038
23025
 
@@ -23315,8 +23302,7 @@ var WeaveEraserToolAction = class extends WeaveAction {
23315
23302
  }
23316
23303
  setupEvents() {
23317
23304
  const stage = this.instance.getStage();
23318
- stage.on("click tap", (e) => {
23319
- e.evt.preventDefault();
23305
+ stage.on("pointerclick", () => {
23320
23306
  if (!this.erasing) return;
23321
23307
  const nodeIntersected = this.instance.pointIntersectsElement();
23322
23308
  if (nodeIntersected) {
@@ -23424,22 +23410,19 @@ var WeaveRectangleToolAction = class extends WeaveAction {
23424
23410
  return;
23425
23411
  }
23426
23412
  });
23427
- stage.on("mousedown touchstart", (e) => {
23428
- e.evt.preventDefault();
23413
+ stage.on("pointerdown", () => {
23429
23414
  if (this.state === RECTANGLE_TOOL_STATE.ADDING) {
23430
23415
  this.creating = true;
23431
23416
  this.handleAdding();
23432
23417
  }
23433
23418
  });
23434
- stage.on("mousemove touchmove", (e) => {
23435
- e.evt.preventDefault();
23419
+ stage.on("pointermove", () => {
23436
23420
  if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) {
23437
23421
  this.moved = true;
23438
23422
  this.handleMovement();
23439
23423
  }
23440
23424
  });
23441
- stage.on("mouseup touchend", (e) => {
23442
- e.evt.preventDefault();
23425
+ stage.on("pointerup", () => {
23443
23426
  if (this.state === RECTANGLE_TOOL_STATE.DEFINING_SIZE) {
23444
23427
  this.creating = false;
23445
23428
  this.handleSettingSize();
@@ -23602,22 +23585,19 @@ var WeaveEllipseToolAction = class extends WeaveAction {
23602
23585
  return;
23603
23586
  }
23604
23587
  });
23605
- stage.on("mousedown touchstart", (e) => {
23606
- e.evt.preventDefault();
23588
+ stage.on("pointerdown", () => {
23607
23589
  if (this.state === ELLIPSE_TOOL_STATE.ADDING) {
23608
23590
  this.creating = true;
23609
23591
  this.handleAdding();
23610
23592
  }
23611
23593
  });
23612
- stage.on("mousemove touchmove", (e) => {
23613
- e.evt.preventDefault();
23594
+ stage.on("pointermove", () => {
23614
23595
  if (this.state === ELLIPSE_TOOL_STATE.DEFINING_SIZE) {
23615
23596
  this.moved = true;
23616
23597
  this.handleMovement();
23617
23598
  }
23618
23599
  });
23619
- stage.on("mouseup touchend", (e) => {
23620
- e.evt.preventDefault();
23600
+ stage.on("pointerup", () => {
23621
23601
  if (this.state === ELLIPSE_TOOL_STATE.DEFINING_SIZE) {
23622
23602
  this.creating = false;
23623
23603
  this.handleSettingSize();
@@ -23789,12 +23769,10 @@ var WeavePenToolAction = class extends WeaveAction {
23789
23769
  return;
23790
23770
  }
23791
23771
  });
23792
- stage.on("dblclick dbltap", (e) => {
23793
- e.evt.preventDefault();
23772
+ stage.on("pointerdblclick", () => {
23794
23773
  this.cancelAction();
23795
23774
  });
23796
- stage.on("click tap", (e) => {
23797
- e.evt.preventDefault();
23775
+ stage.on("pointerclick", () => {
23798
23776
  if (this.state === PEN_TOOL_STATE.IDLE) return;
23799
23777
  if (this.state === PEN_TOOL_STATE.ADDING) {
23800
23778
  this.handleAdding();
@@ -23805,8 +23783,7 @@ var WeavePenToolAction = class extends WeaveAction {
23805
23783
  return;
23806
23784
  }
23807
23785
  });
23808
- stage.on("mousemove touchmove", (e) => {
23809
- e.evt.preventDefault();
23786
+ stage.on("pointermove", () => {
23810
23787
  this.handleMovement();
23811
23788
  });
23812
23789
  this.initialized = true;
@@ -24029,22 +24006,19 @@ var WeaveBrushToolAction = class extends WeaveAction {
24029
24006
  return;
24030
24007
  }
24031
24008
  });
24032
- stage.on("mousedown touchstart", (e) => {
24009
+ stage.on("pointerdown", (e) => {
24033
24010
  if (this.state !== BRUSH_TOOL_STATE.IDLE) return;
24034
24011
  this.handleStartStroke();
24035
- e.evt.preventDefault();
24036
24012
  e.evt.stopPropagation();
24037
24013
  });
24038
- stage.on("mousemove touchmove", (e) => {
24014
+ stage.on("pointermove", (e) => {
24039
24015
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
24040
24016
  this.handleMovement();
24041
- e.evt.preventDefault();
24042
24017
  e.evt.stopPropagation();
24043
24018
  });
24044
- stage.on("mouseup touchend", (e) => {
24019
+ stage.on("pointerup", (e) => {
24045
24020
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
24046
24021
  this.handleEndStroke();
24047
- e.evt.preventDefault();
24048
24022
  e.evt.stopPropagation();
24049
24023
  });
24050
24024
  this.initialized = true;
@@ -24171,17 +24145,13 @@ var WeaveTextToolAction = class extends WeaveAction {
24171
24145
  return;
24172
24146
  }
24173
24147
  });
24174
- stage.on("click tap", (e) => {
24175
- e.evt.preventDefault();
24148
+ stage.on("pointerclick", () => {
24176
24149
  if (this.state === TEXT_TOOL_STATE.IDLE) return;
24177
24150
  if (this.state === TEXT_TOOL_STATE.ADDING) {
24178
24151
  this.handleAdding();
24179
24152
  return;
24180
24153
  }
24181
24154
  });
24182
- stage.on("mousemove touchmove", (e) => {
24183
- e.evt.preventDefault();
24184
- });
24185
24155
  this.initialized = true;
24186
24156
  }
24187
24157
  setState(state) {
@@ -24298,22 +24268,19 @@ var WeaveStarToolAction = class extends WeaveAction {
24298
24268
  return;
24299
24269
  }
24300
24270
  });
24301
- stage.on("mousedown touchstart", (e) => {
24302
- e.evt.preventDefault();
24271
+ stage.on("pointerdown", () => {
24303
24272
  if (this.state === STAR_TOOL_STATE.ADDING) {
24304
24273
  this.creating = true;
24305
24274
  this.handleAdding();
24306
24275
  }
24307
24276
  });
24308
- stage.on("mousemove touchmove", (e) => {
24309
- e.evt.preventDefault();
24277
+ stage.on("pointermove", () => {
24310
24278
  if (this.state === STAR_TOOL_STATE.DEFINING_SIZE) {
24311
24279
  this.moved = true;
24312
24280
  this.handleMovement();
24313
24281
  }
24314
24282
  });
24315
- stage.on("mouseup touchend", (e) => {
24316
- e.evt.preventDefault();
24283
+ stage.on("pointerup", () => {
24317
24284
  if (this.state === STAR_TOOL_STATE.DEFINING_SIZE) {
24318
24285
  this.creating = false;
24319
24286
  this.handleSettingSize();
@@ -24491,12 +24458,10 @@ var WeaveArrowToolAction = class extends WeaveAction {
24491
24458
  return;
24492
24459
  }
24493
24460
  });
24494
- stage.on("dblclick dbltap", (e) => {
24495
- e.evt.preventDefault();
24461
+ stage.on("pointerdblclick", () => {
24496
24462
  this.cancelAction();
24497
24463
  });
24498
- stage.on("click tap", (e) => {
24499
- e.evt.preventDefault();
24464
+ stage.on("pointerclick", () => {
24500
24465
  if (this.state === ARROW_TOOL_STATE.IDLE) return;
24501
24466
  if (this.state === ARROW_TOOL_STATE.ADDING) {
24502
24467
  this.handleAdding();
@@ -24507,8 +24472,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
24507
24472
  return;
24508
24473
  }
24509
24474
  });
24510
- stage.on("mousemove touchmove", (e) => {
24511
- e.evt.preventDefault();
24475
+ stage.on("pointermove", () => {
24512
24476
  this.handleMovement();
24513
24477
  });
24514
24478
  this.initialized = true;
@@ -24742,22 +24706,19 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
24742
24706
  return;
24743
24707
  }
24744
24708
  });
24745
- stage.on("mousedown touchstart", (e) => {
24746
- e.evt.preventDefault();
24709
+ stage.on("pointerdown", () => {
24747
24710
  if (this.state === REGULAR_POLYGON_TOOL_STATE.ADDING) {
24748
24711
  this.creating = true;
24749
24712
  this.handleAdding();
24750
24713
  }
24751
24714
  });
24752
- stage.on("mousemove touchmove", (e) => {
24753
- e.evt.preventDefault();
24715
+ stage.on("pointermove", () => {
24754
24716
  if (this.state === REGULAR_POLYGON_TOOL_STATE.DEFINING_SIZE) {
24755
24717
  this.moved = true;
24756
24718
  this.handleMovement();
24757
24719
  }
24758
24720
  });
24759
- stage.on("mouseup touchend", (e) => {
24760
- e.evt.preventDefault();
24721
+ stage.on("pointerup", () => {
24761
24722
  if (this.state === REGULAR_POLYGON_TOOL_STATE.DEFINING_SIZE) {
24762
24723
  this.creating = false;
24763
24724
  this.handleSettingSize();
@@ -24912,8 +24873,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
24912
24873
  return;
24913
24874
  }
24914
24875
  });
24915
- stage.on("click tap", (e) => {
24916
- e.evt.preventDefault();
24876
+ stage.on("pointerclick", () => {
24917
24877
  if (this.state === FRAME_TOOL_STATE.IDLE) return;
24918
24878
  if (this.state === FRAME_TOOL_STATE.ADDING) {
24919
24879
  this.handleAdding();
@@ -25057,11 +25017,12 @@ var WeaveExportNodesToolAction = class extends WeaveAction {
25057
25017
  link.click();
25058
25018
  this.cancelAction?.();
25059
25019
  }
25060
- async trigger(cancelAction, { nodes, boundingNodes, options, download = true }) {
25020
+ async trigger(cancelAction, { nodes, boundingNodes, options, triggerSelectionTool = true, download = true }) {
25061
25021
  if (!this.instance) throw new Error("Instance not defined");
25062
25022
  const stage = this.instance.getStage();
25063
25023
  stage.container().tabIndex = 1;
25064
25024
  stage.container().focus();
25025
+ this.triggerSelectionTool = triggerSelectionTool;
25065
25026
  this.cancelAction = cancelAction;
25066
25027
  this.options = {
25067
25028
  ...this.defaultFormatOptions,
@@ -25080,7 +25041,7 @@ var WeaveExportNodesToolAction = class extends WeaveAction {
25080
25041
  stage.container().tabIndex = 0;
25081
25042
  stage.container().click();
25082
25043
  stage.container().focus();
25083
- this.instance.triggerAction("selectionTool");
25044
+ if (this.triggerSelectionTool) this.instance.triggerAction("selectionTool");
25084
25045
  }
25085
25046
  };
25086
25047
 
@@ -25145,36 +25106,22 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
25145
25106
  window.addEventListener("keyup", (e) => {
25146
25107
  if (e.code === "Space") this.isSpaceKeyPressed = false;
25147
25108
  });
25148
- stage.on("mousedown", (e) => {
25109
+ stage.on("pointerdown", (e) => {
25149
25110
  const activeAction = this.instance.getActiveAction();
25150
- if (e && e.evt.button === 0 && activeAction === "moveTool") {
25151
- this.moveToolActive = true;
25152
- e.cancelBubble = true;
25153
- }
25154
- if (e && (e.evt.button === 2 || e.evt.buttons === 4)) {
25155
- this.isMouseMiddleButtonPressed = true;
25156
- e.cancelBubble = true;
25157
- }
25111
+ if (e && e.evt.button === 0 && activeAction === "moveTool") this.moveToolActive = true;
25112
+ if (e && (e.evt.button === 2 || e.evt.buttons === 4)) this.isMouseMiddleButtonPressed = true;
25158
25113
  });
25159
- stage.on("mouseup", (e) => {
25114
+ stage.on("pointerup", (e) => {
25160
25115
  const activeAction = this.instance.getActiveAction();
25161
- if (e && e.evt.button === 0 && activeAction === "moveTool") {
25162
- this.moveToolActive = false;
25163
- e.cancelBubble = true;
25164
- }
25165
- if (e && (e.evt.button === 1 || e.evt.buttons === 0)) {
25166
- this.isMouseMiddleButtonPressed = false;
25167
- e.cancelBubble = true;
25168
- }
25116
+ if (e && e.evt.button === 0 && activeAction === "moveTool") this.moveToolActive = false;
25117
+ if (e && (e.evt.button === 1 || e.evt.buttons === 0)) this.isMouseMiddleButtonPressed = false;
25169
25118
  });
25170
- const handleMouseMove = (e) => {
25171
- e.evt.preventDefault();
25119
+ const handleMouseMove = () => {
25172
25120
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
25173
25121
  this.onRender();
25174
25122
  };
25175
- stage.on("mousemove", (0, import_lodash.throttle)(handleMouseMove, 50));
25176
- stage.on("touchmove", (e) => {
25177
- e.evt.preventDefault();
25123
+ stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
25124
+ stage.on("pointermove", () => {
25178
25125
  if (!this.enabled) return;
25179
25126
  this.onRender();
25180
25127
  });
@@ -25429,40 +25376,33 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25429
25376
  this.disableMove();
25430
25377
  }
25431
25378
  });
25432
- stage.on("mousedown", (e) => {
25379
+ stage.on("pointerdown", (e) => {
25433
25380
  const activeAction = this.instance.getActiveAction();
25434
25381
  let enableMove = false;
25435
- if (e && e.evt.button === 0 && activeAction === "moveTool") {
25382
+ if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 1) && activeAction === "moveTool") {
25436
25383
  this.moveToolActive = true;
25437
25384
  enableMove = true;
25438
25385
  }
25439
- if (!enableMove && e && e.evt.button === 1) {
25386
+ if (!enableMove && e.evt.pointerType === "mouse" && e.evt.buttons === 4) {
25440
25387
  this.isMouseMiddleButtonPressed = true;
25441
25388
  enableMove = true;
25442
25389
  }
25443
- if (enableMove) {
25444
- this.enableMove();
25445
- e.cancelBubble = true;
25446
- }
25390
+ if (enableMove) this.enableMove();
25447
25391
  });
25448
- stage.on("mouseup", (e) => {
25392
+ stage.on("pointerup", (e) => {
25449
25393
  const activeAction = this.instance.getActiveAction();
25450
25394
  let disableMove = false;
25451
- if (e && e.evt.button === 0 && activeAction === "moveTool") {
25395
+ if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 0) && activeAction === "moveTool") {
25452
25396
  this.moveToolActive = false;
25453
25397
  disableMove = true;
25454
25398
  }
25455
- if (e && (e.evt.button === 1 || e.evt.buttons === 0)) {
25399
+ if (e && e.evt.pointerType === "mouse" && e.evt.buttons === 0) {
25456
25400
  this.isMouseMiddleButtonPressed = false;
25457
25401
  disableMove = true;
25458
25402
  }
25459
- if (disableMove) {
25460
- this.disableMove();
25461
- e.cancelBubble = true;
25462
- }
25403
+ if (disableMove) this.disableMove();
25463
25404
  });
25464
- const handleMouseMove = (e) => {
25465
- e.evt.preventDefault();
25405
+ const handleMouseMove = () => {
25466
25406
  const mousePos = stage.getPointerPosition();
25467
25407
  if (previousMouseX === Infinity) previousMouseX = mousePos?.x ?? 0;
25468
25408
  if (previousMouseY === Infinity) previousMouseY = mousePos?.y ?? 0;
@@ -25475,38 +25415,22 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25475
25415
  stage.y(stage.y() - deltaY);
25476
25416
  this.instance.emitEvent("onStageMove");
25477
25417
  };
25478
- stage.on("mousemove", (0, import_lodash.throttle)(handleMouseMove, 50));
25479
- stage.on("touchstart", (e) => {
25480
- e.evt.preventDefault();
25418
+ stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
25419
+ stage.on("pointerdown", () => {
25481
25420
  const mousePos = stage.getPointerPosition();
25482
25421
  previousMouseX = mousePos?.x ?? 0;
25483
25422
  previousMouseY = mousePos?.y ?? 0;
25484
25423
  });
25485
- stage.on("touchmove", (e) => {
25486
- e.evt.preventDefault();
25487
- const activeAction = this.instance.getActiveAction();
25488
- if (activeAction !== "moveTool") return;
25489
- const mousePos = stage.getPointerPosition();
25490
- if (previousMouseX === Infinity) previousMouseX = mousePos?.x ?? 0;
25491
- if (previousMouseY === Infinity) previousMouseY = mousePos?.y ?? 0;
25492
- const deltaX = previousMouseX - (mousePos?.x ?? 0);
25493
- const deltaY = previousMouseY - (mousePos?.y ?? 0);
25494
- previousMouseX = mousePos?.x ?? 0;
25495
- previousMouseY = mousePos?.y ?? 0;
25496
- if (!this.enabled) return;
25497
- stage.x(stage.x() - deltaX);
25498
- stage.y(stage.y() - deltaY);
25499
- this.instance.emitEvent("onStageMove");
25500
- });
25501
25424
  const handleWheel = (e) => {
25502
25425
  e.evt.preventDefault();
25503
25426
  const stage$1 = this.instance.getStage();
25504
- if (!this.enabled || !stage$1.isFocused() || this.isCtrlOrMetaPressed) return;
25427
+ const performPanning = !this.isCtrlOrMetaPressed && !e.evt.ctrlKey;
25428
+ if (!this.enabled || !stage$1.isFocused() || this.isCtrlOrMetaPressed || e.evt.buttons === 4 || !performPanning) return;
25505
25429
  stage$1.x(stage$1.x() - e.evt.deltaX);
25506
25430
  stage$1.y(stage$1.y() - e.evt.deltaY);
25507
25431
  this.instance.emitEvent("onStageMove");
25508
25432
  };
25509
- stage.on("wheel", (0, import_lodash.throttle)(handleWheel, 10));
25433
+ stage.on("wheel", handleWheel);
25510
25434
  }
25511
25435
  enable() {
25512
25436
  this.enabled = true;
@@ -25842,8 +25766,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
25842
25766
  for (let i = 0; i < inactiveUsers.length; i++) delete this.usersPointers[inactiveUsers[i]];
25843
25767
  this.renderPointers();
25844
25768
  });
25845
- stage.on("dragmove", (e) => {
25846
- e.evt.preventDefault();
25769
+ stage.on("dragmove", () => {
25847
25770
  const userInfo = this.config.getUser();
25848
25771
  const mousePos = stage.getRelativePointerPosition();
25849
25772
  if (mousePos) store.setAwarenessInfo(WEAVE_USER_POINTER_KEY, {
@@ -25852,8 +25775,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
25852
25775
  y: mousePos.y
25853
25776
  });
25854
25777
  });
25855
- stage.on("pointermove", (e) => {
25856
- e.evt.preventDefault();
25778
+ stage.on("pointermove", () => {
25857
25779
  const userInfo = this.config.getUser();
25858
25780
  const mousePos = stage.getRelativePointerPosition();
25859
25781
  if (mousePos) store.setAwarenessInfo(WEAVE_USER_POINTER_KEY, {
@@ -25967,11 +25889,9 @@ var WeaveStageDropAreaPlugin = class extends WeavePlugin {
25967
25889
  initEvents() {
25968
25890
  const stage = this.instance.getStage();
25969
25891
  stage.container().addEventListener("dragover", (e) => {
25970
- e.preventDefault();
25971
25892
  e.stopPropagation();
25972
25893
  });
25973
25894
  stage.container().addEventListener("drop", (e) => {
25974
- e.preventDefault();
25975
25895
  e.stopPropagation();
25976
25896
  this.instance.emitEvent("onStageDrop", e);
25977
25897
  });