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