@inditextech/weave-sdk 0.42.0 → 0.42.1

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