@inditextech/weave-sdk 4.0.0 → 4.0.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.node.js CHANGED
@@ -18952,7 +18952,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18952
18952
  const nodesSelected = tr.nodes();
18953
18953
  if (nodesSelected.length === 1) {
18954
18954
  const node = nodesSelected[0];
18955
- stage.container().style.cursor = node.defineMousePointer?.() ?? "grab";
18955
+ stage.container().style.cursor = (typeof node?.defineMousePointer === "function" ? node.defineMousePointer() : null) ?? "grab";
18956
18956
  } else stage.container().style.cursor = "grab";
18957
18957
  });
18958
18958
  tr.on("mouseout", (e) => {
@@ -19015,8 +19015,9 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19015
19015
  let selectedNodes = [];
19016
19016
  tr.on("dragstart", (e) => {
19017
19017
  this.dragInProcess = true;
19018
+ if (!e?.evt) return;
19018
19019
  let isWheelMousePressed = false;
19019
- if (e.evt.button === 1) isWheelMousePressed = true;
19020
+ if (e.evt?.button === 1) isWheelMousePressed = true;
19020
19021
  const mainLayer = this.instance.getMainLayer();
19021
19022
  if (!mainLayer) return;
19022
19023
  initialPos = {
@@ -19057,7 +19058,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19057
19058
  y: e.target.y()
19058
19059
  };
19059
19060
  let isWheelMousePressed = false;
19060
- if (e.evt.button === 1) isWheelMousePressed = true;
19061
+ if (e.evt?.button === 1) isWheelMousePressed = true;
19061
19062
  e.cancelBubble = true;
19062
19063
  this.instance.getHooks().callHook("weave:onTransformerDragMove", {
19063
19064
  e,
@@ -19414,8 +19415,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19414
19415
  this.handledClickOrTap = false;
19415
19416
  this.pointers[e.evt.pointerId] = e.evt;
19416
19417
  if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
19417
- if (e.evt.pointerType === "mouse" && e.evt.button !== 0) return;
19418
- if (e.evt.pointerType === "pen" && e.evt.pressure <= .05) return;
19418
+ if (e.evt.pointerType === "mouse" && e.evt?.button !== 0) return;
19419
+ if (e.evt.pointerType === "pen" && e.evt?.pressure <= .05) return;
19419
19420
  if (!this.initialized) return;
19420
19421
  if (!this.active) return;
19421
19422
  if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
@@ -19468,8 +19469,9 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19468
19469
  this.panLoopId = requestAnimationFrame(() => this.panLoop());
19469
19470
  });
19470
19471
  const handleMouseMove = (e) => {
19472
+ if (!e?.evt) return;
19471
19473
  const moved = this.checkMoved(e);
19472
- if (e.evt.buttons === 0) return;
19474
+ if (e.evt?.buttons === 0) return;
19473
19475
  if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
19474
19476
  if (!this.initialized) return;
19475
19477
  if (!this.active) return;
@@ -19635,7 +19637,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19635
19637
  this.hideHoverState();
19636
19638
  const selectedGroup = getTargetedNode(this.instance);
19637
19639
  if (!this.initialized) return;
19638
- if (e.evt.pointerType === "mouse" && e.evt.button && e.evt.button !== 0) return;
19640
+ if (e.evt.pointerType === "mouse" && e.evt?.button && e.evt?.button !== 0) return;
19639
19641
  let areNodesSelected = false;
19640
19642
  let nodeTargeted = selectedGroup && !(selectedGroup.getAttrs().active ?? false) ? selectedGroup : e.target;
19641
19643
  if (e.target === this.instance.getStage()) {
@@ -19698,7 +19700,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19698
19700
  if (areNodesSelected) {
19699
19701
  stage.container().tabIndex = 1;
19700
19702
  stage.container().focus();
19701
- stage.container().style.cursor = nodeTargeted.defineMousePointer?.() ?? "grab";
19703
+ stage.container().style.cursor = (typeof nodeTargeted?.defineMousePointer === "function" ? nodeTargeted.defineMousePointer() : null) ?? "grab";
19702
19704
  }
19703
19705
  this.triggerSelectedNodesEvent();
19704
19706
  }
@@ -19858,6 +19860,10 @@ const WEAVE_COPY_PASTE_CONFIG_DEFAULT = {
19858
19860
  }
19859
19861
  };
19860
19862
 
19863
+ //#endregion
19864
+ //#region src/actions/fit-to-selection-tool/constants.ts
19865
+ const FIT_TO_SELECTION_TOOL_ACTION_NAME = "fitToSelectionTool";
19866
+
19861
19867
  //#endregion
19862
19868
  //#region src/plugins/copy-paste-nodes/copy-paste-nodes.ts
19863
19869
  var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
@@ -20069,8 +20075,8 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
20069
20075
  }
20070
20076
  const nodesSelectionPlugin = this.getNodesSelectionPlugin();
20071
20077
  nodesSelectionPlugin?.setSelectedNodes(realNodes);
20072
- this.instance?.triggerAction("fitToSelectionTool", {
20073
- previousAction: "selectionTool",
20078
+ this.instance?.triggerAction(FIT_TO_SELECTION_TOOL_ACTION_NAME, {
20079
+ previousAction: SELECTION_TOOL_ACTION_NAME,
20074
20080
  smartZoom: true
20075
20081
  });
20076
20082
  this.instance.emitEvent("onPaste", {
@@ -20345,6 +20351,33 @@ const augmentKonvaNodeClass = (config) => {
20345
20351
  Konva.Node.prototype.closeCrop = function() {};
20346
20352
  Konva.Node.prototype.resetCrop = function() {};
20347
20353
  Konva.Node.prototype.dblClick = function() {};
20354
+ Konva.Node.prototype.allowedAnchors = function() {
20355
+ return [];
20356
+ };
20357
+ Konva.Node.prototype.isSelectable = function() {
20358
+ return true;
20359
+ };
20360
+ Konva.Node.prototype.handleMouseover = function() {};
20361
+ Konva.Node.prototype.handleMouseout = function() {};
20362
+ Konva.Node.prototype.handleSelectNode = function() {};
20363
+ Konva.Node.prototype.handleDeselectNode = function() {};
20364
+ Konva.Node.prototype.defineMousePointer = function() {
20365
+ return "default";
20366
+ };
20367
+ Konva.Node.prototype.canBeHovered = function() {
20368
+ return false;
20369
+ };
20370
+ Konva.Node.prototype.canDrag = function() {
20371
+ return false;
20372
+ };
20373
+ Konva.Node.prototype.canMoveToContainer = function() {
20374
+ return false;
20375
+ };
20376
+ Konva.Node.prototype.getNodeAnchors = function() {
20377
+ return [];
20378
+ };
20379
+ Konva.Node.prototype.lockMutex = function() {};
20380
+ Konva.Node.prototype.releaseMutex = function() {};
20348
20381
  };
20349
20382
  var WeaveNode = class {
20350
20383
  async register(instance) {
@@ -20629,10 +20662,11 @@ var WeaveNode = class {
20629
20662
  node.off("dragstart");
20630
20663
  node.on("dragstart", (e) => {
20631
20664
  const nodeTarget = e.target;
20665
+ if (!e.evt) return;
20632
20666
  let isWheelMousePressed = false;
20633
- if (e.evt.button === 1) isWheelMousePressed = true;
20667
+ if (e.evt?.button === 1) isWheelMousePressed = true;
20634
20668
  this.getNodesSelectionFeedbackPlugin()?.hideSelectionHalo(nodeTarget);
20635
- const canMove = nodeTarget?.canDrag() ?? false;
20669
+ const canMove = typeof nodeTarget?.canDrag === "function" ? nodeTarget.canDrag() : false;
20636
20670
  if (!canMove) {
20637
20671
  nodeTarget.stopDrag();
20638
20672
  return;
@@ -20684,7 +20718,7 @@ var WeaveNode = class {
20684
20718
  nodesSelectionPlugin?.setSelectedNodes([]);
20685
20719
  requestAnimationFrame(() => {
20686
20720
  nodesSelectionPlugin?.setSelectedNodes(this.instance.getCloningManager().getClones());
20687
- clone?.startDrag(e.evt);
20721
+ if (clone?.getStage()) clone.startDrag(e.evt);
20688
20722
  });
20689
20723
  }
20690
20724
  if (this.getNodesSelectionPlugin()?.getSelectedNodes().length === 1) this.instance.setMutexLock({
@@ -20695,7 +20729,7 @@ var WeaveNode = class {
20695
20729
  const handleDragMove = (e) => {
20696
20730
  const nodeTarget = e.target;
20697
20731
  let isWheelMousePressed = false;
20698
- if (e.evt.button === 1) isWheelMousePressed = true;
20732
+ if (e.evt?.button === 1) isWheelMousePressed = true;
20699
20733
  e.cancelBubble = true;
20700
20734
  if (e.evt?.buttons === 0) {
20701
20735
  nodeTarget.stopDrag();
@@ -20883,12 +20917,12 @@ var WeaveNode = class {
20883
20917
  }
20884
20918
  if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isTargetable && !(isLocked || isMutexLocked) && stage.mode() === WEAVE_STAGE_DEFAULT_MODE) {
20885
20919
  showHover = true;
20886
- stage.container().style.cursor = realNode?.defineMousePointer() ?? "pointer";
20920
+ stage.container().style.cursor = (typeof node?.defineMousePointer === "function" ? node.defineMousePointer() : null) ?? "pointer";
20887
20921
  cancelBubble = true;
20888
20922
  }
20889
20923
  if (isNodeSelectionEnabled && this.isSelecting() && this.isNodeSelected(realNode) && !this.isPasting() && isTargetable && !(isLocked || isMutexLocked) && stage.mode() === WEAVE_STAGE_DEFAULT_MODE) {
20890
20924
  showHover = true;
20891
- stage.container().style.cursor = realNode?.defineMousePointer() ?? "grab";
20925
+ stage.container().style.cursor = (typeof node?.defineMousePointer === "function" ? node.defineMousePointer() : null) ?? "grab";
20892
20926
  cancelBubble = true;
20893
20927
  }
20894
20928
  if (!isTargetable) cancelBubble = true;
@@ -22152,7 +22186,7 @@ var WeaveRegisterManager = class {
22152
22186
 
22153
22187
  //#endregion
22154
22188
  //#region package.json
22155
- var version = "4.0.0";
22189
+ var version = "4.0.1";
22156
22190
 
22157
22191
  //#endregion
22158
22192
  //#region src/managers/setup.ts
@@ -24293,6 +24327,7 @@ function loadImageSource(image, options) {
24293
24327
  }
24294
24328
  async function downscaleImageFile(file, ratio) {
24295
24329
  const bitmap = await createImageBitmap(file);
24330
+ if (bitmap.width === 0) throw new Error("Invalid image", { cause: "InvalidImage" });
24296
24331
  const width = Math.round(bitmap.width * ratio);
24297
24332
  const height = Math.round(bitmap.height * ratio);
24298
24333
  const canvas = document.createElement("canvas");
@@ -24309,13 +24344,19 @@ function getImageSizeFromFile(file) {
24309
24344
  const img = new Image();
24310
24345
  const url = URL.createObjectURL(file);
24311
24346
  img.onload = () => {
24347
+ if (img.naturalWidth === 0) {
24348
+ reject(new Error("Invalid image", { cause: "InvalidImage" }));
24349
+ return;
24350
+ }
24312
24351
  resolve({
24313
24352
  width: img.naturalWidth,
24314
24353
  height: img.naturalHeight
24315
24354
  });
24316
24355
  URL.revokeObjectURL(url);
24317
24356
  };
24318
- img.onerror = reject;
24357
+ img.onerror = () => {
24358
+ reject(new Error("Invalid image", { cause: "InvalidImage" }));
24359
+ };
24319
24360
  img.src = url;
24320
24361
  });
24321
24362
  }
@@ -24339,6 +24380,10 @@ const downscaleImageFromURL = (url, options) => {
24339
24380
  const img = new Image();
24340
24381
  img.crossOrigin = crossOrigin;
24341
24382
  img.onload = () => {
24383
+ if (img.naturalWidth === 0) {
24384
+ reject(new Error("Invalid image", { cause: "InvalidImage" }));
24385
+ return;
24386
+ }
24342
24387
  const ratio = Math.min(maxWidth / img.width, maxHeight / img.height, 1);
24343
24388
  const width = Math.round(img.width * ratio);
24344
24389
  const height = Math.round(img.height * ratio);
@@ -24349,7 +24394,9 @@ const downscaleImageFromURL = (url, options) => {
24349
24394
  ctx.drawImage(img, 0, 0, width, height);
24350
24395
  resolve(canvas.toDataURL(type));
24351
24396
  };
24352
- img.onerror = reject;
24397
+ img.onerror = () => {
24398
+ reject(new Error("Invalid image", { cause: "InvalidImage" }));
24399
+ };
24353
24400
  img.src = url;
24354
24401
  });
24355
24402
  };
@@ -27229,15 +27276,24 @@ var WeaveImageNode = class extends WeaveNode {
27229
27276
  const imageURLToLoad = imageURL ?? "http://localhost/false-image";
27230
27277
  this.imageFallback[imageId] = Konva.Util.createImageElement();
27231
27278
  this.imageFallback[imageId].crossOrigin = this.config.crossOrigin;
27232
- this.imageFallback[imageId].onerror = (error) => {
27279
+ this.imageFallback[imageId].onerror = () => {
27233
27280
  this.imageState[imageId] = {
27234
27281
  status: "error-fallback",
27235
27282
  loaded: false,
27236
27283
  error: true
27237
27284
  };
27238
- onError(error);
27285
+ onError(new Error(`Failed to load fallback image from provided URL`, { cause: "ErrorLoadingFallbackImage" }));
27239
27286
  };
27240
27287
  this.imageFallback[imageId].onload = async () => {
27288
+ if (this.imageFallback[imageId].width === 0) {
27289
+ this.imageState[imageId] = {
27290
+ status: "error-fallback",
27291
+ loaded: false,
27292
+ error: true
27293
+ };
27294
+ onError(new Error(`Invalid fallback image provided`, { cause: "InvalidFallbackImage" }));
27295
+ return;
27296
+ }
27241
27297
  this.imageState[imageId] = {
27242
27298
  status: "loading",
27243
27299
  loaded: true,
@@ -27264,15 +27320,19 @@ var WeaveImageNode = class extends WeaveNode {
27264
27320
  }
27265
27321
  this.imageSource[imageId] = Konva.Util.createImageElement();
27266
27322
  this.imageSource[imageId].crossOrigin = this.config.crossOrigin;
27267
- this.imageSource[imageId].onerror = (error) => {
27323
+ this.imageSource[imageId].onerror = () => {
27268
27324
  if (!loadingTryout) {
27269
27325
  const stage = this.instance.getStage();
27270
27326
  const image = stage.findOne(`#${imageId}`);
27271
27327
  if (image) this.setErrorState(imageId, image);
27272
27328
  }
27273
- onError(error);
27329
+ onError(new Error(`Failed to load image from provided URL`, { cause: "ErrorLoadingImage" }));
27274
27330
  };
27275
27331
  this.imageSource[imageId].onload = async () => {
27332
+ if (this.imageSource[imageId].width === 0) {
27333
+ onError(new Error(`Invalid image provided`, { cause: "InvalidImage" }));
27334
+ return;
27335
+ }
27276
27336
  const stage = this.instance.getStage();
27277
27337
  if (!this.instance.isServerSide()) stage.container().style.cursor = "pointer";
27278
27338
  this.imageState[imageId] = {
@@ -27364,14 +27424,16 @@ var WeaveImageNode = class extends WeaveNode {
27364
27424
  }
27365
27425
  },
27366
27426
  onError: (error) => {
27367
- if (!this.config.useFallbackImage) {
27427
+ let isInvalidImage = false;
27428
+ if (error.cause === "InvalidImage") isInvalidImage = true;
27429
+ if (!this.config.useFallbackImage && !isInvalidImage) {
27368
27430
  const tryoutAttempts = this.imageTryoutAttempts[id] ?? 0;
27369
27431
  if (tryoutAttempts - 1 < this.config.imageLoading.maxRetryAttempts) {
27370
27432
  this.loadImageTryout(id);
27371
27433
  return;
27372
27434
  } else this.setErrorState(id, image);
27373
27435
  }
27374
- if (loadTryout) {
27436
+ if (loadTryout && !isInvalidImage) {
27375
27437
  const tryoutAttempts = this.imageTryoutAttempts[id] ?? 0;
27376
27438
  if (tryoutAttempts - 1 < this.config.imageLoading.maxRetryAttempts) {
27377
27439
  this.loadImageTryout(id);
@@ -27384,12 +27446,7 @@ var WeaveImageNode = class extends WeaveNode {
27384
27446
  return;
27385
27447
  }
27386
27448
  this.setErrorState(id, image);
27387
- image.setAttrs({ image: void 0 });
27388
- console.error("Error loading image", error);
27389
27449
  this.resolveAsyncElement(id);
27390
- imagePlaceholder?.setAttrs({ visible: true });
27391
- internalImage?.setAttrs({ visible: false });
27392
- this.cacheNode(image);
27393
27450
  }
27394
27451
  }, loadTryout);
27395
27452
  }
@@ -30075,8 +30132,7 @@ var WeaveVideoNode = class extends WeaveNode {
30075
30132
  this.videoPlaceholder[id] = Konva.Util.createImageElement();
30076
30133
  this.videoPlaceholder[id].crossOrigin = this.config.crossOrigin;
30077
30134
  this.videoPlaceholder[id].src = realVideoPlaceholderURL;
30078
- this.videoPlaceholder[id].onerror = (error) => {
30079
- console.error("Error loading video placeholder", realVideoPlaceholderURL, error);
30135
+ this.videoPlaceholder[id].onerror = () => {
30080
30136
  this.resolveAsyncElement(id);
30081
30137
  };
30082
30138
  this.videoPlaceholder[id].onload = () => {
@@ -33115,13 +33171,13 @@ var WeaveZoomOutToolAction = class extends WeaveAction {
33115
33171
  const stageZoomPlugin = this.getStageZoomPlugin();
33116
33172
  if (!stageZoomPlugin.canZoomOut()) return;
33117
33173
  stageZoomPlugin.zoomOut();
33118
- this.previousAction = params.previousAction;
33174
+ this.previousAction = params?.previousAction;
33119
33175
  this.cancelAction = cancelAction;
33120
33176
  this.cancelAction();
33121
33177
  }
33122
33178
  cleanup() {
33123
33179
  const stage = this.instance.getStage();
33124
- if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
33180
+ if (this.previousAction) this.instance.triggerAction(this.previousAction);
33125
33181
  stage.container().style.cursor = "default";
33126
33182
  }
33127
33183
  };
@@ -33153,13 +33209,13 @@ var WeaveZoomInToolAction = class extends WeaveAction {
33153
33209
  const stageZoomPlugin = this.getStageZoomPlugin();
33154
33210
  if (!stageZoomPlugin.canZoomIn()) return;
33155
33211
  stageZoomPlugin.zoomIn();
33156
- this.previousAction = params.previousAction;
33212
+ this.previousAction = params?.previousAction;
33157
33213
  this.cancelAction = cancelAction;
33158
33214
  this.cancelAction();
33159
33215
  }
33160
33216
  cleanup() {
33161
33217
  const stage = this.instance.getStage();
33162
- if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
33218
+ if (this.previousAction) this.instance.triggerAction(this.previousAction);
33163
33219
  stage.container().style.cursor = "default";
33164
33220
  }
33165
33221
  };
@@ -33190,21 +33246,17 @@ var WeaveFitToScreenToolAction = class extends WeaveAction {
33190
33246
  trigger(cancelAction, params) {
33191
33247
  const stageZoomPlugin = this.getStageZoomPlugin();
33192
33248
  if (stageZoomPlugin) stageZoomPlugin.fitToScreen({ overrideZoom: params?.overrideZoom ?? true });
33193
- this.previousAction = params.previousAction;
33249
+ this.previousAction = params?.previousAction;
33194
33250
  this.cancelAction = cancelAction;
33195
33251
  this.cancelAction();
33196
33252
  }
33197
33253
  cleanup() {
33198
33254
  const stage = this.instance.getStage();
33199
- if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
33255
+ if (this.previousAction) this.instance.triggerAction(this.previousAction);
33200
33256
  stage.container().style.cursor = "default";
33201
33257
  }
33202
33258
  };
33203
33259
 
33204
- //#endregion
33205
- //#region src/actions/fit-to-selection-tool/constants.ts
33206
- const FIT_TO_SELECTION_TOOL_ACTION_NAME = "fitToSelectionTool";
33207
-
33208
33260
  //#endregion
33209
33261
  //#region src/actions/fit-to-selection-tool/fit-to-selection-tool.ts
33210
33262
  var WeaveFitToSelectionToolAction = class extends WeaveAction {
@@ -33236,13 +33288,13 @@ var WeaveFitToSelectionToolAction = class extends WeaveAction {
33236
33288
  smartZoom: params?.smartZoom ?? false,
33237
33289
  overrideZoom: params?.overrideZoom ?? true
33238
33290
  });
33239
- this.previousAction = params.previousAction;
33291
+ this.previousAction = params?.previousAction;
33240
33292
  this.cancelAction = cancelAction;
33241
33293
  this.cancelAction();
33242
33294
  }
33243
33295
  cleanup() {
33244
33296
  const stage = this.instance.getStage();
33245
- if (this.previousAction !== void 0) this.instance.triggerAction(this.previousAction);
33297
+ if (this.previousAction) this.instance.triggerAction(this.previousAction);
33246
33298
  stage.container().style.cursor = "default";
33247
33299
  }
33248
33300
  };
@@ -34526,7 +34578,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
34526
34578
  if (this.state !== BRUSH_TOOL_STATE.IDLE) return;
34527
34579
  if (this.getZoomPlugin()?.isPinching()) return;
34528
34580
  if (this.isSpacePressed) return;
34529
- if (e.evt.button !== 0) return;
34581
+ if (e?.evt?.button !== 0) return;
34530
34582
  const pointPressure = this.getEventPressure(e);
34531
34583
  this.handleStartStroke(pointPressure);
34532
34584
  e.evt.stopPropagation();
@@ -39105,13 +39157,13 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
39105
39157
  });
39106
39158
  stage.on("pointerdown", (e) => {
39107
39159
  const activeAction = this.instance.getActiveAction();
39108
- if (e && e.evt.button === 0 && activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = true;
39109
- if (e && (e.evt.button === 2 || e.evt.buttons === 4)) this.isMouseMiddleButtonPressed = true;
39160
+ if (e && e?.evt?.button === 0 && activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = true;
39161
+ if (e && (e?.evt?.button === 2 || e?.evt?.buttons === 4)) this.isMouseMiddleButtonPressed = true;
39110
39162
  });
39111
39163
  stage.on("pointerup", (e) => {
39112
39164
  const activeAction = this.instance.getActiveAction();
39113
- if (e && e.evt.button === 0 && activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = false;
39114
- if (e && (e.evt.button === 1 || e.evt.buttons === 0)) this.isMouseMiddleButtonPressed = false;
39165
+ if (e && e?.evt?.button === 0 && activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = false;
39166
+ if (e && (e?.evt?.button === 1 || e?.evt?.buttons === 0)) this.isMouseMiddleButtonPressed = false;
39115
39167
  });
39116
39168
  const handleMouseMove = () => {
39117
39169
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
@@ -39428,16 +39480,16 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
39428
39480
  let lastPos = null;
39429
39481
  stage.on("pointerdown", (e) => {
39430
39482
  this.pointers.set(e.evt.pointerId, {
39431
- x: e.evt.clientX,
39432
- y: e.evt.clientY
39483
+ x: e?.evt?.clientX ?? 0,
39484
+ y: e?.evt?.clientY ?? 0
39433
39485
  });
39434
39486
  if (this.pointers.size > 1) return;
39435
39487
  const activeAction = this.instance.getActiveAction();
39436
39488
  this.enableMove = false;
39437
39489
  if (activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = true;
39438
- if (e.evt.pointerType === "mouse" && e.evt.buttons === 1) this.isMouseLeftButtonPressed = true;
39439
- if (e.evt.pointerType === "mouse" && e.evt.buttons === 4) this.isMouseMiddleButtonPressed = true;
39440
- const isTouchOrPen = ["touch", "pen"].includes(e.evt.pointerType);
39490
+ if (e.evt.pointerType === "mouse" && e?.evt?.buttons === 1) this.isMouseLeftButtonPressed = true;
39491
+ if (e.evt.pointerType === "mouse" && e?.evt?.buttons === 4) this.isMouseMiddleButtonPressed = true;
39492
+ const isTouchOrPen = ["touch", "pen"].includes(e?.evt?.pointerType);
39441
39493
  if (this.enabled && (this.isSpaceKeyPressed || this.moveToolActive && (this.isMouseLeftButtonPressed || isTouchOrPen) || this.isMouseMiddleButtonPressed)) this.enableMove = true;
39442
39494
  if (this.enableMove) {
39443
39495
  this.isDragging = true;
@@ -39446,7 +39498,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
39446
39498
  }
39447
39499
  });
39448
39500
  stage.on("pointercancel", (e) => {
39449
- this.pointers.delete(e.evt.pointerId);
39501
+ if (e?.evt?.pointerId) this.pointers.delete(e.evt.pointerId);
39450
39502
  lastPos = null;
39451
39503
  });
39452
39504
  const handleMouseMove = (e) => {