@inditextech/weave-sdk 0.30.1 → 0.31.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
@@ -31,8 +31,6 @@ const __syncedstore_core = __toESM(require("@syncedstore/core"));
31
31
  const yjs = __toESM(require("yjs"));
32
32
  const react = __toESM(require("react"));
33
33
  const react_reconciler = __toESM(require("react-reconciler"));
34
- const konva_lib_shapes_Line = __toESM(require("konva/lib/shapes/Line"));
35
- const konva_lib_shapes_Circle = __toESM(require("konva/lib/shapes/Circle"));
36
34
 
37
35
  //#region ../../node_modules/emittery/maps.js
38
36
  const anyMap = new WeakMap();
@@ -15685,15 +15683,15 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
15685
15683
  }
15686
15684
  if (target !== stage && !clickOnTransformer) return;
15687
15685
  let nodes = [];
15688
- if (clickOnTransformer) {
15686
+ if (clickOnTransformer && selectionPlugin) {
15689
15687
  const transformer = selectionPlugin.getTransformer();
15690
15688
  nodes = transformer.getNodes().map((node) => {
15691
15689
  const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
15692
15690
  return {
15693
15691
  instance: node,
15694
- node: nodeHandler.serialize(node)
15692
+ node: nodeHandler?.serialize(node)
15695
15693
  };
15696
- }).filter((node) => node !== void 0);
15694
+ }).filter((node) => typeof node !== "undefined");
15697
15695
  }
15698
15696
  const containerRect = stage.container().getBoundingClientRect();
15699
15697
  const pointerPos = stage.getPointerPosition();
@@ -15826,10 +15824,12 @@ function moveNodeToContainer(instance, node) {
15826
15824
  node.y(node.y() - (layerToMoveAttrs.containerOffsetY ?? 0));
15827
15825
  node.movedToContainer(layerToMove);
15828
15826
  const nodeHandler = instance.getNodeHandler(node.getAttrs().nodeType);
15829
- const actualNode = nodeHandler.serialize(node);
15830
- instance.removeNode(actualNode);
15831
- instance.addNode(actualNode, layerToMoveAttrs.id);
15832
- return layerToMove;
15827
+ if (nodeHandler) {
15828
+ const actualNode = nodeHandler.serialize(node);
15829
+ instance.removeNode(actualNode);
15830
+ instance.addNode(actualNode, layerToMoveAttrs.id);
15831
+ return layerToMove;
15832
+ }
15833
15833
  }
15834
15834
  return void 0;
15835
15835
  }
@@ -15976,6 +15976,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
15976
15976
  }
15977
15977
  isPasting() {
15978
15978
  const copyPastePlugin = this.instance.getPlugin("copyPasteNodes");
15979
+ if (!copyPastePlugin) return false;
15979
15980
  return copyPastePlugin.isPasting();
15980
15981
  }
15981
15982
  isAreaSelecting() {
@@ -16086,6 +16087,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16086
16087
  const layerToMove = moveNodeToContainer(this.instance, node);
16087
16088
  if (layerToMove) return resolve();
16088
16089
  const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
16090
+ if (!nodeHandler) return resolve();
16089
16091
  toUpdate.push(nodeHandler.serialize(node));
16090
16092
  resolve();
16091
16093
  }, 0);
@@ -16093,8 +16095,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16093
16095
  };
16094
16096
  const promises = [];
16095
16097
  for (let i = 0; i < selectedNodes.length; i++) promises.push(nodeUpdatePromise(selectedNodes[i]));
16096
- Promise.all(promises).then(() => {
16097
- if (toUpdate.length > 0) this.instance.updateNodes(toUpdate);
16098
+ Promise.allSettled(promises).then((results) => {
16099
+ if (results.length > 0) this.instance.updateNodes(toUpdate);
16098
16100
  stage.container().style.cursor = actualCursor;
16099
16101
  });
16100
16102
  }
@@ -16111,17 +16113,17 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16111
16113
  });
16112
16114
  this.initEvents();
16113
16115
  this.initialized = true;
16114
- this.instance.on("onActiveActionChange", (activeAction) => {
16116
+ this.instance.addEventListener("onActiveActionChange", (activeAction) => {
16115
16117
  if (typeof activeAction !== "undefined" && activeAction !== "selectionTool") {
16116
16118
  this.active = false;
16117
16119
  return;
16118
16120
  }
16119
16121
  this.active = true;
16120
16122
  });
16121
- this.instance.on("onStateChange", () => {
16123
+ this.instance.addEventListener("onStateChange", () => {
16122
16124
  this.triggerSelectedNodesEvent();
16123
16125
  });
16124
- this.instance.on("onNodeRemoved", (node) => {
16126
+ this.instance.addEventListener("onNodeRemoved", (node) => {
16125
16127
  const selectedNodes = this.getSelectedNodes();
16126
16128
  const newSelectedNodes = selectedNodes.filter((actNode) => {
16127
16129
  return actNode.getAttrs().id !== node.id;
@@ -16143,7 +16145,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16143
16145
  const nodeHandler = this.instance.getNodeHandler(nodeType);
16144
16146
  return {
16145
16147
  instance: node,
16146
- node: nodeHandler.serialize(node)
16148
+ node: nodeHandler?.serialize(node)
16147
16149
  };
16148
16150
  });
16149
16151
  const usersSelectionPlugin = this.instance.getPlugin(WEAVE_USERS_SELECTION_KEY);
@@ -16154,8 +16156,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16154
16156
  const selectedNodes = this.getSelectedNodes();
16155
16157
  const mappedSelectedNodes = selectedNodes.map((node) => {
16156
16158
  const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
16157
- return handler.serialize(node);
16158
- });
16159
+ return handler?.serialize(node);
16160
+ }).filter((node) => typeof node !== "undefined");
16159
16161
  this.instance.removeNodes(mappedSelectedNodes);
16160
16162
  this.tr.nodes([]);
16161
16163
  this.triggerSelectedNodesEvent();
@@ -16270,6 +16272,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16270
16272
  });
16271
16273
  stage.on("click tap", (e) => {
16272
16274
  if (!this.enabled) return;
16275
+ if (this.instance.getActiveAction() !== "selectionTool") return;
16273
16276
  const contextMenuPlugin = this.instance.getPlugin("contextMenu");
16274
16277
  if (contextMenuPlugin && contextMenuPlugin.isContextMenuVisible()) {
16275
16278
  this.selecting = false;
@@ -16364,7 +16367,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16364
16367
  const nodeHandler = this.instance.getNodeHandler(nodeType);
16365
16368
  return {
16366
16369
  instance: node,
16367
- node: nodeHandler.serialize(node)
16370
+ node: nodeHandler?.serialize(node)
16368
16371
  };
16369
16372
  });
16370
16373
  return selectedNodes;
@@ -16591,7 +16594,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
16591
16594
  }
16592
16595
  getNodesSelectionPlugin() {
16593
16596
  const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
16594
- if (!nodesSelectionPlugin) throw new Error("Nodes selection plugin not found");
16597
+ if (!nodesSelectionPlugin) throw new Error("WeaveNodesSelectionPlugin plugin not found");
16595
16598
  return nodesSelectionPlugin;
16596
16599
  }
16597
16600
  enable() {
@@ -16641,6 +16644,7 @@ var WeaveNode = class {
16641
16644
  }
16642
16645
  getSelectionPlugin() {
16643
16646
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
16647
+ if (!selectionPlugin) throw new Error("WeaveNodesSelectionPlugin plugin not found");
16644
16648
  return selectionPlugin;
16645
16649
  }
16646
16650
  isSelecting() {
@@ -16648,7 +16652,8 @@ var WeaveNode = class {
16648
16652
  }
16649
16653
  isPasting() {
16650
16654
  const copyPastePlugin = this.instance.getPlugin("copyPasteNodes");
16651
- return copyPastePlugin.isPasting();
16655
+ if (copyPastePlugin) return copyPastePlugin.isPasting();
16656
+ return false;
16652
16657
  }
16653
16658
  setupDefaultNodeAugmentation(node) {
16654
16659
  node.getTransformerProperties = () => {
@@ -16661,7 +16666,7 @@ var WeaveNode = class {
16661
16666
  isNodeSelected(ele) {
16662
16667
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
16663
16668
  let selected = false;
16664
- if (selectionPlugin.getSelectedNodes().length === 1 && selectionPlugin.getSelectedNodes()[0].getAttrs().id === ele.getAttrs().id) selected = true;
16669
+ if (selectionPlugin && selectionPlugin.getSelectedNodes().length === 1 && selectionPlugin.getSelectedNodes()[0].getAttrs().id === ele.getAttrs().id) selected = true;
16665
16670
  return selected;
16666
16671
  }
16667
16672
  scaleReset(node) {
@@ -16692,7 +16697,7 @@ var WeaveNode = class {
16692
16697
  if (this.isSelecting() && this.isNodeSelected(node$1)) {
16693
16698
  this.scaleReset(node$1);
16694
16699
  const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
16695
- this.instance.updateNode(nodeHandler.serialize(node$1));
16700
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
16696
16701
  }
16697
16702
  };
16698
16703
  node.on("transform", (0, import_lodash.throttle)(handleTransform, 100));
@@ -16704,7 +16709,7 @@ var WeaveNode = class {
16704
16709
  if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
16705
16710
  if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
16706
16711
  const nodeHandler = this.instance.getNodeHandler(node$1.getAttrs().nodeType);
16707
- this.instance.updateNode(nodeHandler.serialize(node$1));
16712
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node$1));
16708
16713
  });
16709
16714
  node.on("dragstart", (e) => {
16710
16715
  const stage = this.instance.getStage();
@@ -16726,7 +16731,7 @@ var WeaveNode = class {
16726
16731
  const layerToMove = checkIfOverContainer(this.instance, e.target);
16727
16732
  if (layerToMove) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
16728
16733
  const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
16729
- this.instance.updateNode(nodeHandler.serialize(node));
16734
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node));
16730
16735
  }
16731
16736
  };
16732
16737
  node.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 100));
@@ -16857,6 +16862,7 @@ var WeaveReconciler = class {
16857
16862
  this.logger = this.instance.getChildLogger("reconciler");
16858
16863
  }
16859
16864
  addNode(parentInstance, child) {
16865
+ if (!parentInstance || !child) return;
16860
16866
  const parentAttrs = parentInstance.getAttrs();
16861
16867
  const childInitialZIndex = child.getAttrs().initialZIndex;
16862
16868
  if (parentInstance instanceof konva.default.Stage && child instanceof konva.default.Layer) parentInstance.add(child);
@@ -17211,8 +17217,10 @@ var WeaveGroupsManager = class {
17211
17217
  });
17212
17218
  parentLayer?.add(groupInstance);
17213
17219
  const groupHandler = this.instance.getNodeHandler("group");
17214
- const groupNode = groupHandler.create(groupId, { draggable: true });
17215
- this.instance.addNode(groupNode, nodeId ?? parentNodeId);
17220
+ if (groupHandler) {
17221
+ const groupNode = groupHandler.create(groupId, { draggable: true });
17222
+ this.instance.addNode(groupNode, nodeId ?? parentNodeId);
17223
+ }
17216
17224
  const nodesWithZIndex = nodes.map((node) => {
17217
17225
  const instance = mainLayer?.findOne(`#${node.key}`);
17218
17226
  return {
@@ -17235,8 +17243,10 @@ var WeaveGroupsManager = class {
17235
17243
  konvaGroup.setAttr("id", v4_default());
17236
17244
  konvaGroup.setAttr("draggable", false);
17237
17245
  const handler = this.instance.getNodeHandler("group");
17238
- const stateNode = handler.serialize(konvaGroup);
17239
- this.instance.addNode(stateNode, groupId);
17246
+ if (handler) {
17247
+ const stateNode = handler.serialize(konvaGroup);
17248
+ this.instance.addNode(stateNode, groupId);
17249
+ }
17240
17250
  }
17241
17251
  continue;
17242
17252
  }
@@ -17251,18 +17261,20 @@ var WeaveGroupsManager = class {
17251
17261
  konvaNode.setAttr("id", v4_default());
17252
17262
  konvaNode.setAttr("draggable", false);
17253
17263
  const handler = this.instance.getNodeHandler(konvaNode.getAttrs().nodeType);
17254
- const stateNode = handler.serialize(konvaNode);
17255
- this.instance.addNode(stateNode, groupId);
17264
+ if (handler) {
17265
+ const stateNode = handler.serialize(konvaNode);
17266
+ this.instance.addNode(stateNode, groupId);
17267
+ }
17256
17268
  }
17257
17269
  }
17258
17270
  this.instance.removeNodes(sortedNodesByZIndex);
17259
17271
  groupInstance.destroy();
17260
17272
  setTimeout(() => {
17261
- const groupNode$1 = stage.findOne(`#${groupId}`);
17273
+ const groupNode = stage.findOne(`#${groupId}`);
17262
17274
  const selectionPlugin$1 = this.instance.getPlugin("nodesSelection");
17263
- if (groupNode$1 && selectionPlugin$1) {
17275
+ if (groupNode && selectionPlugin$1) {
17264
17276
  const tr = selectionPlugin$1.getTransformer();
17265
- selectionPlugin$1.setSelectedNodes([groupNode$1]);
17277
+ selectionPlugin$1.setSelectedNodes([groupNode]);
17266
17278
  tr.show();
17267
17279
  tr.forceUpdate();
17268
17280
  }
@@ -17302,13 +17314,17 @@ var WeaveGroupsManager = class {
17302
17314
  child.setAttr("draggable", true);
17303
17315
  newChildId = child.getAttrs().id;
17304
17316
  const handler = this.instance.getNodeHandler(child.getAttrs().nodeType);
17305
- const node = handler.serialize(child);
17306
- this.instance.addNode(node, nodeId ?? newLayer.getAttrs().id);
17317
+ if (handler) {
17318
+ const node = handler.serialize(child);
17319
+ this.instance.addNode(node, nodeId ?? newLayer.getAttrs().id);
17320
+ }
17307
17321
  child.destroy();
17308
17322
  }
17309
17323
  const groupHandler = this.instance.getNodeHandler("group");
17310
- const groupNode = groupHandler.serialize(konvaGroup);
17311
- this.instance.removeNode(groupNode);
17324
+ if (groupHandler) {
17325
+ const groupNode = groupHandler.serialize(konvaGroup);
17326
+ this.instance.removeNode(groupNode);
17327
+ }
17312
17328
  setTimeout(() => {
17313
17329
  const firstElement = newLayer.findOne(`#${newChildId}`);
17314
17330
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
@@ -17580,8 +17596,10 @@ var WeaveCloningManager = class {
17580
17596
  const nodePos = node.getClientRect();
17581
17597
  if (nodePos.x < minPoint.x) minPoint.x = nodePos.x;
17582
17598
  if (nodePos.y < minPoint.y) minPoint.y = nodePos.y;
17583
- const serialized = nodeHandler.serialize(node);
17584
- serializedNodes.push(serialized);
17599
+ if (nodeHandler) {
17600
+ const serialized = nodeHandler.serialize(node);
17601
+ serializedNodes.push(serialized);
17602
+ }
17585
17603
  });
17586
17604
  newGroup.destroy();
17587
17605
  return {
@@ -17651,8 +17669,10 @@ var WeaveCloningManager = class {
17651
17669
  node.setAbsolutePosition(nodePos);
17652
17670
  node.rotation(nodeRotation);
17653
17671
  const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
17654
- const stateNode = handler.serialize(node);
17655
- this.instance.addNode(stateNode, targetContainer.getAttrs().id);
17672
+ if (handler) {
17673
+ const stateNode = handler.serialize(node);
17674
+ this.instance.addNode(stateNode, targetContainer.getAttrs().id);
17675
+ }
17656
17676
  node.destroy();
17657
17677
  }
17658
17678
  newGroup.destroy();
@@ -17869,30 +17889,38 @@ var WeaveZIndexManager = class {
17869
17889
  this.logger.debug(`Moving instance with id [${instance.getAttrs().id}], up one step of z-index`);
17870
17890
  instance.moveUp();
17871
17891
  const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
17872
- const node = handler.serialize(instance);
17873
- this.instance.moveNode(node, __inditextech_weave_types.WEAVE_NODE_POSITION.UP);
17892
+ if (handler) {
17893
+ const node = handler.serialize(instance);
17894
+ this.instance.moveNode(node, __inditextech_weave_types.WEAVE_NODE_POSITION.UP);
17895
+ }
17874
17896
  }
17875
17897
  moveDown(instance) {
17876
17898
  this.logger.debug(`Moving instance with id [${instance.getAttrs().id}], down one step of z-index`);
17877
17899
  instance.moveDown();
17878
17900
  const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
17879
- const node = handler.serialize(instance);
17880
- this.instance.moveNode(node, __inditextech_weave_types.WEAVE_NODE_POSITION.DOWN);
17901
+ if (handler) {
17902
+ const node = handler.serialize(instance);
17903
+ this.instance.moveNode(node, __inditextech_weave_types.WEAVE_NODE_POSITION.DOWN);
17904
+ }
17881
17905
  }
17882
17906
  sendToBack(instance) {
17883
17907
  this.logger.debug(`Moving instance with id [${instance.getAttrs().id}], to bottom of z-index`);
17884
17908
  instance.moveToBottom();
17885
17909
  const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
17886
- const node = handler.serialize(instance);
17887
- this.instance.moveNode(node, __inditextech_weave_types.WEAVE_NODE_POSITION.BACK);
17910
+ if (handler) {
17911
+ const node = handler.serialize(instance);
17912
+ this.instance.moveNode(node, __inditextech_weave_types.WEAVE_NODE_POSITION.BACK);
17913
+ }
17888
17914
  }
17889
17915
  bringToFront(instance) {
17890
17916
  this.logger.debug(`Moving instance with id [${instance.getAttrs().id}], to top of z-index`);
17891
17917
  instance.moveToTop();
17892
17918
  const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
17893
- const node = handler.serialize(instance);
17894
- this.instance.updateNode(node);
17895
- this.instance.moveNode(node, __inditextech_weave_types.WEAVE_NODE_POSITION.FRONT);
17919
+ if (handler) {
17920
+ const node = handler.serialize(instance);
17921
+ this.instance.updateNode(node);
17922
+ this.instance.moveNode(node, __inditextech_weave_types.WEAVE_NODE_POSITION.FRONT);
17923
+ }
17896
17924
  }
17897
17925
  };
17898
17926
 
@@ -18162,28 +18190,13 @@ var WeaveRegisterManager = class {
18162
18190
  return this.actionsHandlers;
18163
18191
  }
18164
18192
  getPlugin(pluginName) {
18165
- if (!this.plugins[pluginName]) {
18166
- const msg = `Plugin with name [${pluginName}] is not registered`;
18167
- this.logger.error(msg);
18168
- throw new Error(msg);
18169
- }
18170
- return this.plugins[pluginName];
18193
+ return this.plugins?.[pluginName];
18171
18194
  }
18172
18195
  getActionHandler(actionName) {
18173
- if (!this.actionsHandlers[actionName]) {
18174
- const msg = `Action handler with name [${actionName}] is not registered`;
18175
- this.logger.error(msg);
18176
- throw new Error(msg);
18177
- }
18178
- return this.actionsHandlers[actionName];
18196
+ return this.actionsHandlers?.[actionName];
18179
18197
  }
18180
18198
  getNodeHandler(nodeType) {
18181
- if (!this.nodesHandlers[nodeType]) {
18182
- const msg = `Node handler with type [${nodeType}] is not registered`;
18183
- this.logger.error(msg);
18184
- throw new Error(msg);
18185
- }
18186
- return this.nodesHandlers[nodeType];
18199
+ return this.nodesHandlers?.[nodeType];
18187
18200
  }
18188
18201
  registerPlugins() {
18189
18202
  const config = this.instance.getConfiguration();
@@ -18229,7 +18242,7 @@ var WeaveRegisterManager = class {
18229
18242
 
18230
18243
  //#endregion
18231
18244
  //#region package.json
18232
- var version = "0.30.1";
18245
+ var version = "0.31.1";
18233
18246
 
18234
18247
  //#endregion
18235
18248
  //#region src/managers/setup.ts
@@ -18349,11 +18362,7 @@ var WeaveActionsManager = class {
18349
18362
  }
18350
18363
  triggerAction(actionName, params) {
18351
18364
  const actionsHandlers = this.instance.getActionsHandlers();
18352
- if (!actionsHandlers[actionName]) {
18353
- const msg = `Action handler with name [${actionName}] not registered`;
18354
- this.logger.error(msg);
18355
- throw new Error(msg);
18356
- }
18365
+ if (!actionsHandlers[actionName]) return;
18357
18366
  if (typeof this.activeAction !== "undefined") this.cancelAction(this.activeAction);
18358
18367
  this.activeAction = actionName;
18359
18368
  const payload = actionsHandlers[actionName].trigger(this.cancelActionCallback(actionName), params);
@@ -18443,6 +18452,11 @@ var WeaveExportManager = class {
18443
18452
  const { format: format$2 = __inditextech_weave_types.WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = __inditextech_weave_types.WEAVE_EXPORT_BACKGROUND_COLOR } = options;
18444
18453
  const stage = this.instance.getStage();
18445
18454
  const mainLayer = this.instance.getMainLayer();
18455
+ const originalScale = stage.scale();
18456
+ stage.scale({
18457
+ x: 1,
18458
+ y: 1
18459
+ });
18446
18460
  const realNodes = nodes.map((node) => {
18447
18461
  if (node.getAttrs().nodeId) return stage.findOne(`#${node.getAttrs().nodeId}`);
18448
18462
  return node;
@@ -18487,6 +18501,7 @@ var WeaveExportManager = class {
18487
18501
  quality: options.quality ?? 1,
18488
18502
  callback: (img) => {
18489
18503
  exportGroup.destroy();
18504
+ stage.scale(originalScale);
18490
18505
  resolve(img);
18491
18506
  }
18492
18507
  });
@@ -18516,40 +18531,26 @@ var WeavePluginsManager = class {
18516
18531
  }
18517
18532
  enable(pluginName) {
18518
18533
  const plugins = this.instance.getPlugins();
18519
- if (!plugins[pluginName]) {
18520
- const msg = `Plugin with name [${pluginName}] not registered`;
18521
- this.logger.error(msg);
18522
- throw new Error(msg);
18523
- }
18524
- plugins[pluginName].enable?.();
18534
+ if (plugins[pluginName]) plugins[pluginName].enable();
18525
18535
  }
18526
18536
  disable(pluginName) {
18527
18537
  const plugins = this.instance.getPlugins();
18528
- if (!plugins[pluginName]) {
18529
- const msg = `Plugin with name [${pluginName}] not registered`;
18530
- this.logger.error(msg);
18531
- throw new Error(msg);
18532
- }
18533
- plugins[pluginName].disable?.();
18538
+ if (plugins[pluginName]) plugins[pluginName].disable();
18534
18539
  }
18535
18540
  isEnabled(pluginName) {
18536
18541
  const plugins = this.instance.getPlugins();
18537
- if (!plugins[pluginName]) {
18538
- const msg = `Plugin with name [${pluginName}] not registered`;
18539
- this.logger.error(msg);
18540
- throw new Error(msg);
18541
- }
18542
- return plugins[pluginName].isEnabled?.();
18542
+ if (plugins[pluginName]) return plugins[pluginName].isEnabled();
18543
+ return false;
18543
18544
  }
18544
18545
  };
18545
18546
 
18546
18547
  //#endregion
18547
18548
  //#region src/weave.ts
18548
- var Weave = class extends Emittery {
18549
+ var Weave = class {
18549
18550
  initialized = false;
18550
18551
  status = __inditextech_weave_types.WEAVE_INSTANCE_STATUS.IDLE;
18551
18552
  constructor(weaveConfig, stageConfig) {
18552
- super();
18553
+ this.emitter = new Emittery();
18553
18554
  konva.default.showWarnings = false;
18554
18555
  this.id = v4_default();
18555
18556
  this.initialized = false;
@@ -18636,7 +18637,7 @@ var Weave = class extends Emittery {
18636
18637
  }
18637
18638
  destroy() {
18638
18639
  this.moduleLogger.info(`Destroying the instance`);
18639
- this.clearListeners();
18640
+ this.emitter.clearListeners();
18640
18641
  this.status = __inditextech_weave_types.WEAVE_INSTANCE_STATUS.IDLE;
18641
18642
  this.emitEvent("onInstanceStatus", this.status);
18642
18643
  const store = this.storeManager.getStore();
@@ -18659,15 +18660,15 @@ var Weave = class extends Emittery {
18659
18660
  }
18660
18661
  emitEvent(event, payload) {
18661
18662
  this.moduleLogger.debug({ payload }, `Emitted event [${event}]`);
18662
- this.emit(event, payload);
18663
+ this.emitter.emit(event, payload);
18663
18664
  }
18664
18665
  addEventListener(event, callback) {
18665
18666
  this.moduleLogger.debug(`Listening event [${event}]`);
18666
- this.on(event, callback);
18667
+ this.emitter.on(event, callback);
18667
18668
  }
18668
18669
  removeEventListener(event, callback) {
18669
18670
  this.moduleLogger.debug(`Removing listening to event [${event}]`);
18670
- this.off(event, callback);
18671
+ this.emitter.off(event, callback);
18671
18672
  }
18672
18673
  getLogger() {
18673
18674
  return this.logger;
@@ -18930,6 +18931,7 @@ var WeaveLayerNode = class extends WeaveNode {
18930
18931
  const children = [...instance.getChildren()];
18931
18932
  for (const node of children) {
18932
18933
  const handler = this.instance.getNodeHandler(node.getAttr("nodeType"));
18934
+ if (!handler) continue;
18933
18935
  childrenMapped.push(handler.serialize(node));
18934
18936
  }
18935
18937
  return {
@@ -18984,6 +18986,7 @@ var WeaveGroupNode = class extends WeaveNode {
18984
18986
  const children = [...instance.getChildren()];
18985
18987
  for (const node of children) {
18986
18988
  const handler = this.instance.getNodeHandler(node.getAttr("nodeType"));
18989
+ if (!handler) continue;
18987
18990
  childrenMapped.push(handler.serialize(node));
18988
18991
  }
18989
18992
  return {
@@ -19689,7 +19692,7 @@ var WeaveImageToolAction = class extends WeaveAction {
19689
19692
  y: (mousePos?.y ?? 0) + 2
19690
19693
  });
19691
19694
  const nodeHandler = this.instance.getNodeHandler("rectangle");
19692
- this.instance.updateNode(nodeHandler.serialize(tempImage));
19695
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempImage));
19693
19696
  }
19694
19697
  });
19695
19698
  this.initialized = true;
@@ -19735,20 +19738,22 @@ var WeaveImageToolAction = class extends WeaveAction {
19735
19738
  const nodeHandler = this.instance.getNodeHandler("image");
19736
19739
  this.tempImageId = v4_default();
19737
19740
  const aspectRatio = this.preloadImgs[this.imageId].width / this.preloadImgs[this.imageId].height;
19738
- const node = nodeHandler.create(this.tempImageId, {
19739
- x: (mousePos?.x ?? 0) + 5,
19740
- y: (mousePos?.y ?? 0) + 5,
19741
- width: 100 * aspectRatio,
19742
- height: 100,
19743
- opacity: 1,
19744
- adding: true,
19745
- imageURL: this.imageURL,
19746
- stroke: "#000000ff",
19747
- strokeWidth: 0,
19748
- strokeScaleEnabled: true,
19749
- listening: false
19750
- });
19751
- this.instance.addNode(node, this.container?.getAttrs().id);
19741
+ if (nodeHandler) {
19742
+ const node = nodeHandler.create(this.tempImageId, {
19743
+ x: (mousePos?.x ?? 0) + 5,
19744
+ y: (mousePos?.y ?? 0) + 5,
19745
+ width: 100 * aspectRatio,
19746
+ height: 100,
19747
+ opacity: 1,
19748
+ adding: true,
19749
+ imageURL: this.imageURL,
19750
+ stroke: "#000000ff",
19751
+ strokeWidth: 0,
19752
+ strokeScaleEnabled: true,
19753
+ listening: false
19754
+ });
19755
+ this.instance.addNode(node, this.container?.getAttrs().id);
19756
+ }
19752
19757
  }
19753
19758
  this.clickPoint = null;
19754
19759
  this.setState(IMAGE_TOOL_STATE.ADDING);
@@ -19764,27 +19769,29 @@ var WeaveImageToolAction = class extends WeaveAction {
19764
19769
  this.clickPoint = mousePoint;
19765
19770
  this.container = container;
19766
19771
  const nodeHandler = this.instance.getNodeHandler("image");
19767
- const node = nodeHandler.create(this.imageId, {
19768
- ...this.props,
19769
- x: this.clickPoint?.x ?? 0,
19770
- y: this.clickPoint?.y ?? 0,
19771
- opacity: 1,
19772
- adding: false,
19773
- imageURL: this.imageURL,
19774
- stroke: "#000000ff",
19775
- strokeWidth: 0,
19776
- strokeScaleEnabled: true,
19777
- imageWidth: this.preloadImgs[this.imageId].width,
19778
- imageHeight: this.preloadImgs[this.imageId].height,
19779
- imageInfo: {
19780
- width: this.preloadImgs[this.imageId].width,
19781
- height: this.preloadImgs[this.imageId].height
19782
- }
19783
- });
19784
- this.instance.addNode(node, this.container?.getAttrs().id);
19772
+ if (nodeHandler) {
19773
+ const node = nodeHandler.create(this.imageId, {
19774
+ ...this.props,
19775
+ x: this.clickPoint?.x ?? 0,
19776
+ y: this.clickPoint?.y ?? 0,
19777
+ opacity: 1,
19778
+ adding: false,
19779
+ imageURL: this.imageURL,
19780
+ stroke: "#000000ff",
19781
+ strokeWidth: 0,
19782
+ strokeScaleEnabled: true,
19783
+ imageWidth: this.preloadImgs[this.imageId].width,
19784
+ imageHeight: this.preloadImgs[this.imageId].height,
19785
+ imageInfo: {
19786
+ width: this.preloadImgs[this.imageId].width,
19787
+ height: this.preloadImgs[this.imageId].height
19788
+ }
19789
+ });
19790
+ this.instance.addNode(node, this.container?.getAttrs().id);
19791
+ }
19785
19792
  if (!position) {
19786
19793
  const imageNodeHandler = this.instance.getNodeHandler("image");
19787
- this.instance.removeNode(imageNodeHandler.serialize(tempImage));
19794
+ if (imageNodeHandler) this.instance.removeNode(imageNodeHandler.serialize(tempImage));
19788
19795
  }
19789
19796
  this.setState(IMAGE_TOOL_STATE.FINISHED);
19790
19797
  }
@@ -19810,7 +19817,7 @@ var WeaveImageToolAction = class extends WeaveAction {
19810
19817
  const tempImage = this.instance.getStage().findOne(`#${this.tempImageId}`);
19811
19818
  if (tempImage) {
19812
19819
  const nodeHandler = this.instance.getNodeHandler("rectangle");
19813
- this.instance.removeNode(nodeHandler.serialize(tempImage));
19820
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempImage));
19814
19821
  }
19815
19822
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
19816
19823
  if (selectionPlugin) {
@@ -20445,7 +20452,7 @@ var WeaveImageNode = class extends WeaveNode {
20445
20452
  });
20446
20453
  this.updateImageCrop(imageProps);
20447
20454
  const nodeHandler = this.instance.getNodeHandler(image.getAttrs().nodeType);
20448
- this.instance.updateNode(nodeHandler.serialize(image));
20455
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(image));
20449
20456
  }
20450
20457
  };
20451
20458
  if (imageProps.imageURL) imageObj.src = imageProps.imageURL;
@@ -21009,6 +21016,7 @@ var WeaveFrameNode = class extends WeaveNode {
21009
21016
  const children = [...frameInternal.getChildren()];
21010
21017
  for (const node of children) {
21011
21018
  const handler = this.instance.getNodeHandler(node.getAttr("nodeType"));
21019
+ if (!handler) continue;
21012
21020
  childrenMapped.push(handler.serialize(node));
21013
21021
  }
21014
21022
  }
@@ -22922,6 +22930,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22922
22930
  if (!this.enabled) return;
22923
22931
  const stage = this.instance.getStage();
22924
22932
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
22933
+ if (!selectionPlugin) return;
22925
22934
  const nodes = selectionPlugin.getTransformer().getNodes();
22926
22935
  if (nodes.length === 0) return;
22927
22936
  let zoomTransformer = stage.findOne("#zoomTransformer");
@@ -23039,11 +23048,12 @@ var WeaveZoomOutToolAction = class extends WeaveAction {
23039
23048
  return ZOOM_OUT_TOOL_ACTION_NAME;
23040
23049
  }
23041
23050
  getStageZoomPlugin() {
23042
- return this.instance.getPlugin("stageZoom");
23051
+ const stageZoomPlugin = this.instance.getPlugin("stageZoom");
23052
+ if (!stageZoomPlugin) throw new Error("WeaveZoomOutToolAction requires the WeaveStageZoomPlugin to be loaded");
23053
+ return stageZoomPlugin;
23043
23054
  }
23044
23055
  onInit() {
23045
- const stageZoomPlugin = this.getStageZoomPlugin();
23046
- if (!stageZoomPlugin) throw new Error("WeaveZoomOutToolAction requires the WeaveStageZoomPlugin to be loaded");
23056
+ this.getStageZoomPlugin();
23047
23057
  }
23048
23058
  trigger(cancelAction, params) {
23049
23059
  const stageZoomPlugin = this.getStageZoomPlugin();
@@ -23072,11 +23082,12 @@ var WeaveZoomInToolAction = class extends WeaveAction {
23072
23082
  return ZOOM_IN_TOOL_ACTION_NAME;
23073
23083
  }
23074
23084
  getStageZoomPlugin() {
23075
- return this.instance.getPlugin("stageZoom");
23085
+ const stageZoomPlugin = this.instance.getPlugin("stageZoom");
23086
+ if (!stageZoomPlugin) throw new Error("WeaveZoomInToolAction requires the WeaveStageZoomPlugin to be loaded");
23087
+ return stageZoomPlugin;
23076
23088
  }
23077
23089
  onInit() {
23078
- const stageZoomPlugin = this.getStageZoomPlugin();
23079
- if (!stageZoomPlugin) throw new Error("WeaveZoomInToolAction requires the WeaveStageZoomPlugin to be loaded");
23090
+ this.getStageZoomPlugin();
23080
23091
  }
23081
23092
  trigger(cancelAction, params) {
23082
23093
  const stageZoomPlugin = this.getStageZoomPlugin();
@@ -23105,15 +23116,16 @@ var WeaveFitToScreenToolAction = class extends WeaveAction {
23105
23116
  return FIT_TO_SCREEN_TOOL_ACTION_NAME;
23106
23117
  }
23107
23118
  getStageZoomPlugin() {
23108
- return this.instance.getPlugin("stageZoom");
23119
+ const stageZoomPlugin = this.instance.getPlugin("stageZoom");
23120
+ if (!stageZoomPlugin) throw new Error("WeaveFitToScreenToolAction requires the WeaveStageZoomPlugin to be loaded");
23121
+ return stageZoomPlugin;
23109
23122
  }
23110
23123
  onInit() {
23111
- const stageZoomPlugin = this.getStageZoomPlugin();
23112
- if (!stageZoomPlugin) throw new Error("WeaveFitToScreenToolAction requires the WeaveStageZoomPlugin to be loaded");
23124
+ this.getStageZoomPlugin();
23113
23125
  }
23114
23126
  trigger(cancelAction, params) {
23115
23127
  const stageZoomPlugin = this.getStageZoomPlugin();
23116
- stageZoomPlugin.fitToScreen();
23128
+ if (stageZoomPlugin) stageZoomPlugin.fitToScreen();
23117
23129
  this.previousAction = params.previousAction;
23118
23130
  this.cancelAction = cancelAction;
23119
23131
  this.cancelAction();
@@ -23137,16 +23149,18 @@ var WeaveFitToSelectionToolAction = class extends WeaveAction {
23137
23149
  return FIT_TO_SELECTION_TOOL_ACTION_NAME;
23138
23150
  }
23139
23151
  getNodesSelectionPlugin() {
23140
- return this.instance.getPlugin("nodesSelection");
23152
+ const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
23153
+ if (!nodesSelectionPlugin) throw new Error("WeaveFitToSelectionToolAction requires the WeaveNodesSelectionPlugin to be loaded");
23154
+ return nodesSelectionPlugin;
23141
23155
  }
23142
23156
  getStageZoomPlugin() {
23143
- return this.instance.getPlugin("stageZoom");
23157
+ const stageZoomPlugin = this.instance.getPlugin("stageZoom");
23158
+ if (!stageZoomPlugin) throw new Error("WeaveFitToSelectionToolAction requires the WeaveStageZoomPlugin to be loaded");
23159
+ return stageZoomPlugin;
23144
23160
  }
23145
23161
  onInit() {
23146
- const stageZoomPlugin = this.getStageZoomPlugin();
23147
- if (!stageZoomPlugin) throw new Error("WeaveFitToSelectionTool requires the WeaveStageZoomPlugin to be loaded");
23148
- const nodesSelectionPlugin = this.getNodesSelectionPlugin();
23149
- if (!nodesSelectionPlugin) throw new Error("WeaveFitToSelectionTool requires the WeaveNodeSelectionPlugin to be loaded");
23162
+ this.getStageZoomPlugin();
23163
+ this.getNodesSelectionPlugin();
23150
23164
  }
23151
23165
  trigger(cancelAction, params) {
23152
23166
  const stageZoomPlugin = this.getStageZoomPlugin();
@@ -23310,8 +23324,10 @@ var WeaveEraserToolAction = class extends WeaveAction {
23310
23324
  if (!realNode) return;
23311
23325
  const nodeType = realNode.getAttrs().nodeType;
23312
23326
  const nodeHandler = this.instance.getNodeHandler(nodeType);
23313
- const nodeSerialized = nodeHandler.serialize(realNode);
23314
- this.instance.removeNode(nodeSerialized);
23327
+ if (nodeHandler) {
23328
+ const nodeSerialized = nodeHandler.serialize(realNode);
23329
+ this.instance.removeNode(nodeSerialized);
23330
+ }
23315
23331
  }
23316
23332
  });
23317
23333
  stage.container().addEventListener("keydown", (e) => {
@@ -23447,15 +23463,17 @@ var WeaveRectangleToolAction = class extends WeaveAction {
23447
23463
  this.container = container;
23448
23464
  this.rectId = v4_default();
23449
23465
  const nodeHandler = this.instance.getNodeHandler("rectangle");
23450
- const node = nodeHandler.create(this.rectId, {
23451
- ...this.props,
23452
- strokeScaleEnabled: true,
23453
- x: this.clickPoint?.x ?? 0,
23454
- y: this.clickPoint?.y ?? 0,
23455
- width: 0,
23456
- height: 0
23457
- });
23458
- this.instance.addNode(node, this.container?.getAttrs().id);
23466
+ if (nodeHandler) {
23467
+ const node = nodeHandler.create(this.rectId, {
23468
+ ...this.props,
23469
+ strokeScaleEnabled: true,
23470
+ x: this.clickPoint?.x ?? 0,
23471
+ y: this.clickPoint?.y ?? 0,
23472
+ width: 0,
23473
+ height: 0
23474
+ });
23475
+ this.instance.addNode(node, this.container?.getAttrs().id);
23476
+ }
23459
23477
  this.setState(RECTANGLE_TOOL_STATE.DEFINING_SIZE);
23460
23478
  }
23461
23479
  handleSettingSize() {
@@ -23482,7 +23500,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
23482
23500
  width: rectWidth,
23483
23501
  height: rectHeight
23484
23502
  });
23485
- this.instance.updateNode(nodeHandler.serialize(rectangle));
23503
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(rectangle));
23486
23504
  }
23487
23505
  this.cancelAction();
23488
23506
  }
@@ -23498,7 +23516,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
23498
23516
  width: deltaX,
23499
23517
  height: deltaY
23500
23518
  });
23501
- this.instance.updateNode(nodeHandler.serialize(rectangle));
23519
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(rectangle));
23502
23520
  }
23503
23521
  }
23504
23522
  trigger(cancelAction) {
@@ -23623,15 +23641,17 @@ var WeaveEllipseToolAction = class extends WeaveAction {
23623
23641
  this.container = container;
23624
23642
  this.ellipseId = v4_default();
23625
23643
  const nodeHandler = this.instance.getNodeHandler("ellipse");
23626
- const node = nodeHandler.create(this.ellipseId, {
23627
- ...this.props,
23628
- strokeScaleEnabled: true,
23629
- x: this.clickPoint?.x ?? 0 + this.props.radiusX,
23630
- y: this.clickPoint?.y ?? 0 + this.props.radiusY,
23631
- radiusX: 0,
23632
- radiusY: 0
23633
- });
23634
- this.instance.addNode(node, this.container?.getAttrs().id);
23644
+ if (nodeHandler) {
23645
+ const node = nodeHandler.create(this.ellipseId, {
23646
+ ...this.props,
23647
+ strokeScaleEnabled: true,
23648
+ x: this.clickPoint?.x ?? 0 + this.props.radiusX,
23649
+ y: this.clickPoint?.y ?? 0 + this.props.radiusY,
23650
+ radiusX: 0,
23651
+ radiusY: 0
23652
+ });
23653
+ this.instance.addNode(node, this.container?.getAttrs().id);
23654
+ }
23635
23655
  this.setState(ELLIPSE_TOOL_STATE.DEFINING_SIZE);
23636
23656
  }
23637
23657
  handleSettingSize() {
@@ -23658,7 +23678,7 @@ var WeaveEllipseToolAction = class extends WeaveAction {
23658
23678
  radiusX: ellipseRadiusX,
23659
23679
  radiusY: ellipseRadiusY
23660
23680
  });
23661
- this.instance.updateNode(nodeHandler.serialize(ellipse));
23681
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(ellipse));
23662
23682
  }
23663
23683
  this.cancelAction();
23664
23684
  }
@@ -23684,7 +23704,7 @@ var WeaveEllipseToolAction = class extends WeaveAction {
23684
23704
  radiusX: deltaX,
23685
23705
  radiusY: deltaY
23686
23706
  });
23687
- this.instance.updateNode(nodeHandler.serialize(ellipse));
23707
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(ellipse));
23688
23708
  }
23689
23709
  }
23690
23710
  trigger(cancelAction) {
@@ -23811,14 +23831,16 @@ var WeavePenToolAction = class extends WeaveAction {
23811
23831
  this.lineId = v4_default();
23812
23832
  this.tempLineId = v4_default();
23813
23833
  const nodeHandler = this.instance.getNodeHandler("line");
23814
- const node = nodeHandler.create(this.lineId, {
23815
- ...this.props,
23816
- strokeScaleEnabled: true,
23817
- x: this.clickPoint?.x ?? 0,
23818
- y: this.clickPoint?.y ?? 0,
23819
- points: [0, 0]
23820
- });
23821
- this.instance.addNode(node, this.container?.getAttrs().id);
23834
+ if (nodeHandler) {
23835
+ const node = nodeHandler.create(this.lineId, {
23836
+ ...this.props,
23837
+ strokeScaleEnabled: true,
23838
+ x: this.clickPoint?.x ?? 0,
23839
+ y: this.clickPoint?.y ?? 0,
23840
+ points: [0, 0]
23841
+ });
23842
+ this.instance.addNode(node, this.container?.getAttrs().id);
23843
+ }
23822
23844
  this.tempPoint = new konva.default.Circle({
23823
23845
  x: this.clickPoint?.x ?? 0,
23824
23846
  y: this.clickPoint?.y ?? 0,
@@ -23829,14 +23851,16 @@ var WeavePenToolAction = class extends WeaveAction {
23829
23851
  fill: "#cccccc"
23830
23852
  });
23831
23853
  this.measureContainer?.add(this.tempPoint);
23832
- const tempLine = nodeHandler.create(this.tempLineId, {
23833
- ...this.props,
23834
- x: this.clickPoint?.x ?? 0,
23835
- y: this.clickPoint?.y ?? 0,
23836
- strokeScaleEnabled: true,
23837
- points: [0, 0]
23838
- });
23839
- this.instance.addNode(tempLine, this.container?.getAttrs().id);
23854
+ if (nodeHandler) {
23855
+ const tempLine = nodeHandler.create(this.tempLineId, {
23856
+ ...this.props,
23857
+ x: this.clickPoint?.x ?? 0,
23858
+ y: this.clickPoint?.y ?? 0,
23859
+ strokeScaleEnabled: true,
23860
+ points: [0, 0]
23861
+ });
23862
+ this.instance.addNode(tempLine, this.container?.getAttrs().id);
23863
+ }
23840
23864
  this.tempNextPoint = new konva.default.Circle({
23841
23865
  x: this.clickPoint?.x ?? 0,
23842
23866
  y: this.clickPoint?.y ?? 0,
@@ -23862,7 +23886,7 @@ var WeavePenToolAction = class extends WeaveAction {
23862
23886
  points: newPoints
23863
23887
  });
23864
23888
  const nodeHandler = this.instance.getNodeHandler("line");
23865
- this.instance.updateNode(nodeHandler.serialize(tempMainLine));
23889
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempMainLine));
23866
23890
  this.tempPoint.setAttrs({
23867
23891
  x: mousePoint.x,
23868
23892
  y: mousePoint.y
@@ -23877,7 +23901,7 @@ var WeavePenToolAction = class extends WeaveAction {
23877
23901
  y: mousePoint.y,
23878
23902
  points: [0, 0]
23879
23903
  });
23880
- this.instance.updateNode(nodeHandler.serialize(tempLine));
23904
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempLine));
23881
23905
  }
23882
23906
  this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
23883
23907
  }
@@ -23896,7 +23920,7 @@ var WeavePenToolAction = class extends WeaveAction {
23896
23920
  ]
23897
23921
  });
23898
23922
  const nodeHandler = this.instance.getNodeHandler("line");
23899
- this.instance.updateNode(nodeHandler.serialize(tempLine));
23923
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempLine));
23900
23924
  this.tempNextPoint.setAttrs({
23901
23925
  x: mousePoint.x,
23902
23926
  y: mousePoint.y
@@ -23923,11 +23947,11 @@ var WeavePenToolAction = class extends WeaveAction {
23923
23947
  const tempMainLine = this.instance.getStage().findOne(`#${this.lineId}`);
23924
23948
  if (tempLine) {
23925
23949
  const nodeHandler = this.instance.getNodeHandler("line");
23926
- this.instance.removeNode(nodeHandler.serialize(tempLine));
23950
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempLine));
23927
23951
  }
23928
23952
  if (this.lineId && tempMainLine && tempMainLine.points().length < 4) {
23929
23953
  const nodeHandler = this.instance.getNodeHandler("line");
23930
- this.instance.removeNode(nodeHandler.serialize(tempMainLine));
23954
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempMainLine));
23931
23955
  }
23932
23956
  if (this.lineId && tempMainLine && tempMainLine.points().length >= 4) {
23933
23957
  const nodeHandler = this.instance.getNodeHandler("line");
@@ -23936,7 +23960,7 @@ var WeavePenToolAction = class extends WeaveAction {
23936
23960
  strokeWidth: 1,
23937
23961
  hitStrokeWidth: 16
23938
23962
  });
23939
- this.instance.updateNode(nodeHandler.serialize(tempMainLine));
23963
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempMainLine));
23940
23964
  }
23941
23965
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
23942
23966
  if (selectionPlugin) {
@@ -24035,14 +24059,16 @@ var WeaveBrushToolAction = class extends WeaveAction {
24035
24059
  this.measureContainer = measureContainer;
24036
24060
  this.strokeId = v4_default();
24037
24061
  const nodeHandler = this.instance.getNodeHandler("line");
24038
- const node = nodeHandler.create(this.strokeId, {
24039
- ...this.props,
24040
- strokeScaleEnabled: true,
24041
- x: this.clickPoint?.x ?? 0,
24042
- y: this.clickPoint?.y ?? 0,
24043
- points: [0, 0]
24044
- });
24045
- this.instance.addNode(node, this.container?.getAttrs().id);
24062
+ if (nodeHandler) {
24063
+ const node = nodeHandler.create(this.strokeId, {
24064
+ ...this.props,
24065
+ strokeScaleEnabled: true,
24066
+ x: this.clickPoint?.x ?? 0,
24067
+ y: this.clickPoint?.y ?? 0,
24068
+ points: [0, 0]
24069
+ });
24070
+ this.instance.addNode(node, this.container?.getAttrs().id);
24071
+ }
24046
24072
  this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
24047
24073
  }
24048
24074
  handleEndStroke() {
@@ -24054,7 +24080,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
24054
24080
  ...this.props,
24055
24081
  hitStrokeWidth: 10
24056
24082
  });
24057
- this.instance.updateNode(nodeHandler.serialize(tempStroke));
24083
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempStroke));
24058
24084
  this.clickPoint = null;
24059
24085
  stage.container().tabIndex = 1;
24060
24086
  stage.container().focus();
@@ -24072,7 +24098,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
24072
24098
  mousePoint.y - tempStroke.y()
24073
24099
  ]);
24074
24100
  const nodeHandler = this.instance.getNodeHandler("line");
24075
- this.instance.updateNode(nodeHandler.serialize(tempStroke));
24101
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempStroke));
24076
24102
  }
24077
24103
  }
24078
24104
  trigger(cancel) {
@@ -24178,13 +24204,15 @@ var WeaveTextToolAction = class extends WeaveAction {
24178
24204
  this.container = container;
24179
24205
  this.textId = v4_default();
24180
24206
  const nodeHandler = this.instance.getNodeHandler("text");
24181
- const node = nodeHandler.create(this.textId, {
24182
- ...this.props,
24183
- x: this.clickPoint?.x ?? 0,
24184
- y: this.clickPoint?.y ?? 0,
24185
- draggable: true
24186
- });
24187
- this.instance.addNode(node, this.container?.getAttrs().id);
24207
+ if (nodeHandler) {
24208
+ const node = nodeHandler.create(this.textId, {
24209
+ ...this.props,
24210
+ x: this.clickPoint?.x ?? 0,
24211
+ y: this.clickPoint?.y ?? 0,
24212
+ draggable: true
24213
+ });
24214
+ this.instance.addNode(node, this.container?.getAttrs().id);
24215
+ }
24188
24216
  this.setState(TEXT_TOOL_STATE.FINISHED);
24189
24217
  this.cancelAction();
24190
24218
  }
@@ -24309,16 +24337,18 @@ var WeaveStarToolAction = class extends WeaveAction {
24309
24337
  this.container = container;
24310
24338
  this.starId = v4_default();
24311
24339
  const nodeHandler = this.instance.getNodeHandler("star");
24312
- const node = nodeHandler.create(this.starId, {
24313
- ...this.props,
24314
- strokeScaleEnabled: true,
24315
- x: this.clickPoint?.x ?? 0 + this.props.outerRadius,
24316
- y: this.clickPoint?.y ?? 0 + this.props.outerRadius,
24317
- numPoints: 5,
24318
- innerRadius: 0,
24319
- outerRadius: 0
24320
- });
24321
- this.instance.addNode(node, this.container?.getAttrs().id);
24340
+ if (nodeHandler) {
24341
+ const node = nodeHandler.create(this.starId, {
24342
+ ...this.props,
24343
+ strokeScaleEnabled: true,
24344
+ x: this.clickPoint?.x ?? 0 + this.props.outerRadius,
24345
+ y: this.clickPoint?.y ?? 0 + this.props.outerRadius,
24346
+ numPoints: 5,
24347
+ innerRadius: 0,
24348
+ outerRadius: 0
24349
+ });
24350
+ this.instance.addNode(node, this.container?.getAttrs().id);
24351
+ }
24322
24352
  this.setState(STAR_TOOL_STATE.DEFINING_SIZE);
24323
24353
  }
24324
24354
  handleSettingSize() {
@@ -24345,7 +24375,7 @@ var WeaveStarToolAction = class extends WeaveAction {
24345
24375
  outerRadius: starOuterRadius,
24346
24376
  innerRadius: starInnerRadius
24347
24377
  });
24348
- this.instance.updateNode(nodeHandler.serialize(star));
24378
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(star));
24349
24379
  }
24350
24380
  this.cancelAction();
24351
24381
  }
@@ -24371,7 +24401,7 @@ var WeaveStarToolAction = class extends WeaveAction {
24371
24401
  outerRadius: deltaX,
24372
24402
  innerRadius: deltaY
24373
24403
  });
24374
- this.instance.updateNode(nodeHandler.serialize(star));
24404
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(star));
24375
24405
  }
24376
24406
  }
24377
24407
  trigger(cancelAction) {
@@ -24504,14 +24534,16 @@ var WeaveArrowToolAction = class extends WeaveAction {
24504
24534
  this.tempArrowId = v4_default();
24505
24535
  const nodeHandler = this.instance.getNodeHandler("arrow");
24506
24536
  const lineNodeHandler = this.instance.getNodeHandler("line");
24507
- const node = lineNodeHandler.create(this.arrowId, {
24508
- ...this.props,
24509
- strokeScaleEnabled: true,
24510
- x: this.clickPoint?.x ?? 0,
24511
- y: this.clickPoint?.y ?? 0,
24512
- points: [0, 0]
24513
- });
24514
- this.instance.addNode(node, this.container?.getAttrs().id);
24537
+ if (lineNodeHandler) {
24538
+ const node = lineNodeHandler.create(this.arrowId, {
24539
+ ...this.props,
24540
+ strokeScaleEnabled: true,
24541
+ x: this.clickPoint?.x ?? 0,
24542
+ y: this.clickPoint?.y ?? 0,
24543
+ points: [0, 0]
24544
+ });
24545
+ this.instance.addNode(node, this.container?.getAttrs().id);
24546
+ }
24515
24547
  this.tempPoint = new konva.default.Circle({
24516
24548
  x: this.clickPoint?.x ?? 0,
24517
24549
  y: this.clickPoint?.y ?? 0,
@@ -24522,14 +24554,16 @@ var WeaveArrowToolAction = class extends WeaveAction {
24522
24554
  fill: "#cccccc"
24523
24555
  });
24524
24556
  this.measureContainer?.add(this.tempPoint);
24525
- const tempArrow = nodeHandler.create(this.tempArrowId, {
24526
- ...this.props,
24527
- x: this.clickPoint?.x ?? 0,
24528
- y: this.clickPoint?.y ?? 0,
24529
- strokeScaleEnabled: true,
24530
- points: [0, 0]
24531
- });
24532
- this.instance.addNode(tempArrow, this.container?.getAttrs().id);
24557
+ if (nodeHandler) {
24558
+ const tempArrow = nodeHandler.create(this.tempArrowId, {
24559
+ ...this.props,
24560
+ x: this.clickPoint?.x ?? 0,
24561
+ y: this.clickPoint?.y ?? 0,
24562
+ strokeScaleEnabled: true,
24563
+ points: [0, 0]
24564
+ });
24565
+ this.instance.addNode(tempArrow, this.container?.getAttrs().id);
24566
+ }
24533
24567
  this.tempNextPoint = new konva.default.Circle({
24534
24568
  x: this.clickPoint?.x ?? 0,
24535
24569
  y: this.clickPoint?.y ?? 0,
@@ -24556,7 +24590,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
24556
24590
  });
24557
24591
  const nodeHandler = this.instance.getNodeHandler("arrow");
24558
24592
  const lineNodeHandler = this.instance.getNodeHandler("line");
24559
- this.instance.updateNode(lineNodeHandler.serialize(tempMainArrow));
24593
+ if (lineNodeHandler) this.instance.updateNode(lineNodeHandler.serialize(tempMainArrow));
24560
24594
  this.tempPoint.setAttrs({
24561
24595
  x: mousePoint.x,
24562
24596
  y: mousePoint.y
@@ -24571,7 +24605,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
24571
24605
  y: mousePoint.y,
24572
24606
  points: [0, 0]
24573
24607
  });
24574
- this.instance.updateNode(nodeHandler.serialize(tempArrow));
24608
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempArrow));
24575
24609
  }
24576
24610
  this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
24577
24611
  }
@@ -24590,7 +24624,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
24590
24624
  ]
24591
24625
  });
24592
24626
  const nodeHandler = this.instance.getNodeHandler("arrow");
24593
- this.instance.updateNode(nodeHandler.serialize(tempArrow));
24627
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempArrow));
24594
24628
  this.tempNextPoint.setAttrs({
24595
24629
  x: mousePoint.x,
24596
24630
  y: mousePoint.y
@@ -24617,24 +24651,26 @@ var WeaveArrowToolAction = class extends WeaveAction {
24617
24651
  const tempMainArrow = this.instance.getStage().findOne(`#${this.arrowId}`);
24618
24652
  if (tempArrow) {
24619
24653
  const nodeHandler = this.instance.getNodeHandler("arrow");
24620
- this.instance.removeNode(nodeHandler.serialize(tempArrow));
24654
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempArrow));
24621
24655
  }
24622
24656
  if (this.arrowId && tempMainArrow && tempMainArrow.points().length < 4) {
24623
24657
  const nodeHandler = this.instance.getNodeHandler("line");
24624
- this.instance.removeNode(nodeHandler.serialize(tempMainArrow));
24658
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempMainArrow));
24625
24659
  }
24626
24660
  if (this.arrowId && tempMainArrow && tempMainArrow.points().length >= 4) {
24627
24661
  const nodeHandler = this.instance.getNodeHandler("arrow");
24628
24662
  const lineNodeHandler = this.instance.getNodeHandler("line");
24629
- const finalArrow = nodeHandler.create(this.arrowId, {
24630
- ...tempMainArrow.getAttrs(),
24631
- ...this.props,
24632
- strokeScaleEnabled: true,
24633
- strokeWidth: 1,
24634
- hitStrokeWidth: 16
24635
- });
24636
- this.instance.removeNode(lineNodeHandler.serialize(tempMainArrow));
24637
- this.instance.addNode(finalArrow, this.container?.getAttrs().id);
24663
+ if (nodeHandler && lineNodeHandler) {
24664
+ const finalArrow = nodeHandler.create(this.arrowId, {
24665
+ ...tempMainArrow.getAttrs(),
24666
+ ...this.props,
24667
+ strokeScaleEnabled: true,
24668
+ strokeWidth: 1,
24669
+ hitStrokeWidth: 16
24670
+ });
24671
+ this.instance.removeNode(lineNodeHandler.serialize(tempMainArrow));
24672
+ this.instance.addNode(finalArrow, this.container?.getAttrs().id);
24673
+ }
24638
24674
  }
24639
24675
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
24640
24676
  if (selectionPlugin) {
@@ -24745,14 +24781,16 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
24745
24781
  this.container = container;
24746
24782
  this.regularPolygonId = v4_default();
24747
24783
  const nodeHandler = this.instance.getNodeHandler("regular-polygon");
24748
- const node = nodeHandler.create(this.regularPolygonId, {
24749
- ...this.props,
24750
- strokeScaleEnabled: true,
24751
- x: (this.clickPoint?.x ?? 0) + this.props.radius,
24752
- y: (this.clickPoint?.y ?? 0) + this.props.radius,
24753
- radius: 0
24754
- });
24755
- this.instance.addNode(node, this.container?.getAttrs().id);
24784
+ if (nodeHandler) {
24785
+ const node = nodeHandler.create(this.regularPolygonId, {
24786
+ ...this.props,
24787
+ strokeScaleEnabled: true,
24788
+ x: (this.clickPoint?.x ?? 0) + this.props.radius,
24789
+ y: (this.clickPoint?.y ?? 0) + this.props.radius,
24790
+ radius: 0
24791
+ });
24792
+ this.instance.addNode(node, this.container?.getAttrs().id);
24793
+ }
24756
24794
  this.setState(REGULAR_POLYGON_TOOL_STATE.DEFINING_SIZE);
24757
24795
  }
24758
24796
  handleSettingSize() {
@@ -24776,7 +24814,7 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
24776
24814
  y: starPos.y + newRadius,
24777
24815
  radius: newRadius
24778
24816
  });
24779
- this.instance.updateNode(nodeHandler.serialize(regularPolygon));
24817
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(regularPolygon));
24780
24818
  }
24781
24819
  this.cancelAction();
24782
24820
  }
@@ -24800,7 +24838,7 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
24800
24838
  y: starPos.y + deltaX,
24801
24839
  radius: deltaX
24802
24840
  });
24803
- this.instance.updateNode(nodeHandler.serialize(regularPolygon));
24841
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(regularPolygon));
24804
24842
  }
24805
24843
  }
24806
24844
  trigger(cancelAction) {
@@ -24905,12 +24943,14 @@ var WeaveFrameToolAction = class extends WeaveAction {
24905
24943
  this.container = container;
24906
24944
  this.frameId = v4_default();
24907
24945
  const nodeHandler = this.instance.getNodeHandler("frame");
24908
- const node = nodeHandler.create(this.frameId, {
24909
- ...this.props,
24910
- x: this.clickPoint.x,
24911
- y: this.clickPoint.y
24912
- });
24913
- this.instance.addNode(node, this.container?.getAttrs().id);
24946
+ if (nodeHandler) {
24947
+ const node = nodeHandler.create(this.frameId, {
24948
+ ...this.props,
24949
+ x: this.clickPoint.x,
24950
+ y: this.clickPoint.y
24951
+ });
24952
+ this.instance.addNode(node, this.container?.getAttrs().id);
24953
+ }
24914
24954
  this.cancelAction?.();
24915
24955
  }
24916
24956
  trigger(cancelAction, params) {
@@ -25055,13 +25095,15 @@ const WEAVE_GRID_DEFAULT_SIZE = 50;
25055
25095
  const WEAVE_GRID_DEFAULT_TYPE = WEAVE_GRID_TYPES.LINES;
25056
25096
  const WEAVE_GRID_DEFAULT_COLOR = "rgba(0,0,0,0.2)";
25057
25097
  const WEAVE_GRID_DEFAULT_ORIGIN_COLOR = "rgba(255,0,0,0.2)";
25098
+ const WEAVE_GRID_DEFAULT_STROKE = .5;
25099
+ const WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO = 4;
25100
+ const WEAVE_GRID_DEFAULT_RADIUS = 1;
25101
+ const WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO = 2;
25102
+ const WEAVE_GRID_DEFAULT_MAJOR_EVERY = 10;
25058
25103
  const WEAVE_GRID_LAYER_ID = "gridLayer";
25059
25104
 
25060
25105
  //#endregion
25061
25106
  //#region src/plugins/stage-grid/stage-grid.ts
25062
- function isZeroOrClose(value, tolerance = 1e-6) {
25063
- return Math.abs(value) <= tolerance;
25064
- }
25065
25107
  var WeaveStageGridPlugin = class extends WeavePlugin {
25066
25108
  constructor(params) {
25067
25109
  super();
@@ -25146,111 +25188,167 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
25146
25188
  const layer = stage.findOne(`#${WEAVE_GRID_LAYER_ID}`);
25147
25189
  return layer;
25148
25190
  }
25149
- renderGrid() {
25150
- const layer = this.getLayer();
25151
- if (!layer) return;
25152
- layer.destroyChildren();
25153
- if (!this.enabled) return;
25154
- switch (this.config.type) {
25155
- case WEAVE_GRID_TYPES.LINES:
25156
- this.renderGridLines();
25157
- break;
25158
- case WEAVE_GRID_TYPES.DOTS:
25159
- this.renderGridDots();
25160
- break;
25161
- default:
25162
- this.renderGridLines();
25163
- break;
25164
- }
25165
- }
25166
- round(number, step) {
25167
- return Math.round(number / step) * step;
25191
+ getAdaptiveSpacing(scale) {
25192
+ const baseGridSpacing = this.config.gridSize;
25193
+ const minPixelSpacing = 8;
25194
+ const maxPixelSpacing = 100;
25195
+ let spacing = baseGridSpacing;
25196
+ let pixelSpacing = spacing * scale;
25197
+ while (pixelSpacing < minPixelSpacing) {
25198
+ spacing *= 2;
25199
+ pixelSpacing = spacing * scale;
25200
+ }
25201
+ while (pixelSpacing > maxPixelSpacing && spacing > baseGridSpacing / 16) {
25202
+ spacing /= 2;
25203
+ pixelSpacing = spacing * scale;
25204
+ }
25205
+ const logFactor = Math.round(Math.log2(spacing / baseGridSpacing));
25206
+ const snappedSpacing = baseGridSpacing * Math.pow(2, logFactor);
25207
+ return snappedSpacing;
25208
+ }
25209
+ getAdjustedSpacing(startX, endX, startY, endY, baseSpacing = 50, maxDotsPerAxis = 500) {
25210
+ let spacing = baseSpacing;
25211
+ let dotCountX = Math.ceil((endX - startX) / spacing);
25212
+ let dotCountY = Math.ceil((endY - startY) / spacing);
25213
+ while ((dotCountX > maxDotsPerAxis || dotCountY > maxDotsPerAxis) && spacing < 1e6) {
25214
+ spacing *= 2;
25215
+ dotCountX = Math.ceil((endX - startX) / spacing);
25216
+ dotCountY = Math.ceil((endY - startY) / spacing);
25217
+ }
25218
+ return spacing;
25168
25219
  }
25169
25220
  renderGridLines() {
25170
- const layer = this.getLayer();
25171
- if (!layer) return;
25172
25221
  const stage = this.instance.getStage();
25173
- const stageXRound = this.round(stage.x(), this.config.gridSize) * -1;
25174
- const overflowX = this.round(10 * this.config.gridSize, this.config.gridSize);
25175
- const overflowY = this.round(10 * this.config.gridSize, this.config.gridSize);
25176
- const pointsX = [];
25177
- for (let i = stageXRound - overflowX; i < stageXRound + stage.width() + overflowX; i += this.config.gridSize) pointsX.push({
25178
- real: i / stage.scaleX(),
25179
- ref: i
25180
- });
25181
- const stageYRound = this.round(stage.y(), this.config.gridSize) * -1;
25182
- const pointsY = [];
25183
- for (let i = stageYRound - overflowY; i < stageYRound + stage.height() + overflowY; i += this.config.gridSize) pointsY.push({
25184
- real: i / stage.scaleY(),
25185
- ref: i
25186
- });
25187
- for (let index = 0; index < pointsX.length; index++) {
25188
- const { real: point, ref } = pointsX[index];
25189
- let color = this.config.gridColor;
25190
- if (point === 0) color = this.config.gridOriginColor;
25191
- layer.add(new konva_lib_shapes_Line.Line({
25222
+ const gridLayer = this.getLayer();
25223
+ if (!gridLayer) return;
25224
+ gridLayer.destroyChildren();
25225
+ if (!this.enabled) return;
25226
+ const scale = stage.scaleX();
25227
+ const spacing = this.getAdaptiveSpacing(scale);
25228
+ const invScale = (this.config.gridStroke ?? WEAVE_GRID_DEFAULT_STROKE) / scale;
25229
+ const offsetX = -stage.x() / stage.scaleX();
25230
+ const offsetY = -stage.y() / stage.scaleY();
25231
+ const margin = 2;
25232
+ const worldWidth = stage.width() * invScale;
25233
+ const worldHeight = stage.height() * invScale;
25234
+ const startX = Math.floor((offsetX - margin * worldWidth) / spacing) * spacing;
25235
+ const startY = Math.floor((offsetY - margin * worldHeight) / spacing) * spacing;
25236
+ const endX = offsetX + (1 + margin) * worldWidth;
25237
+ const endY = offsetY + (1 + margin) * worldHeight;
25238
+ const highlightEvery = this.config.gridMajorEvery ?? WEAVE_GRID_DEFAULT_MAJOR_EVERY;
25239
+ for (let x = startX; x <= endX; x += spacing) {
25240
+ const index = Math.round(x / spacing);
25241
+ const isHighlight = index % highlightEvery === 0;
25242
+ const isOrigin = Math.abs(x) < spacing / 2;
25243
+ const line = new konva.default.Line({
25192
25244
  points: [
25193
- point,
25194
- (-stage.y() - overflowY) / stage.scaleY(),
25195
- point,
25196
- (-stage.y() + stage.height() + overflowY) / stage.scaleY()
25245
+ x,
25246
+ startY,
25247
+ x,
25248
+ endY
25197
25249
  ],
25198
- stroke: color,
25199
- strokeWidth: (isZeroOrClose(ref % (10 * this.config.gridSize)) ? 2.5 : .5) / stage.scaleX(),
25250
+ stroke: isOrigin ? this.config.gridOriginColor : this.config.gridColor,
25251
+ strokeWidth: !isHighlight && !isOrigin ? invScale : invScale * (this.config.gridMajorRatio ?? WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO),
25200
25252
  listening: false
25201
- }));
25253
+ });
25254
+ gridLayer.add(line);
25202
25255
  }
25203
- for (let index = 0; index < pointsY.length; index++) {
25204
- const { real: point, ref } = pointsY[index];
25205
- let color = this.config.gridColor;
25206
- if (point === 0) color = this.config.gridOriginColor;
25207
- layer.add(new konva_lib_shapes_Line.Line({
25256
+ for (let y = startY; y <= endY; y += spacing) {
25257
+ const index = Math.round(y / spacing);
25258
+ const isHighlight = index % highlightEvery === 0;
25259
+ const isOrigin = Math.abs(y) < spacing / 2;
25260
+ const line = new konva.default.Line({
25208
25261
  points: [
25209
- (-stage.x() - overflowX) / stage.scaleX(),
25210
- point,
25211
- (-stage.x() + stage.width() + overflowX) / stage.scaleX(),
25212
- point
25262
+ startX,
25263
+ y,
25264
+ endX,
25265
+ y
25213
25266
  ],
25214
- stroke: color,
25215
- strokeWidth: (isZeroOrClose(ref % (10 * this.config.gridSize)) ? 2.5 : .5) / stage.scaleX(),
25267
+ stroke: isOrigin ? this.config.gridOriginColor : this.config.gridColor,
25268
+ strokeWidth: !isHighlight && !isOrigin ? invScale : invScale * 2,
25216
25269
  listening: false
25217
- }));
25270
+ });
25271
+ gridLayer.add(line);
25218
25272
  }
25219
25273
  }
25220
25274
  renderGridDots() {
25221
- const layer = this.getLayer();
25222
- if (!layer) return;
25223
25275
  const stage = this.instance.getStage();
25224
- const overflowX = 10 * this.config.gridSize;
25225
- const overflowY = 10 * this.config.gridSize;
25226
- const stageXRound = this.round(stage.x(), this.config.gridSize) * -1;
25227
- const pointsX = [];
25228
- for (let i = stageXRound - overflowX; i < stageXRound + stage.width() + overflowX; i += this.config.gridSize) pointsX.push({
25229
- real: i / stage.scaleX(),
25230
- ref: i
25231
- });
25232
- const stageYRound = this.round(stage.y(), this.config.gridSize) * -1;
25233
- const pointsY = [];
25234
- for (let i = stageYRound - overflowY; i < stageYRound + stage.height() + overflowY; i += this.config.gridSize) pointsY.push({
25235
- real: i / stage.scaleY(),
25236
- ref: i
25237
- });
25238
- for (let indexX = 0; indexX < pointsX.length; indexX++) {
25239
- const { real: pointX, ref: refX } = pointsX[indexX];
25240
- for (let indexY = 0; indexY < pointsY.length; indexY++) {
25241
- const { real: pointY, ref: refY } = pointsY[indexY];
25242
- let color = this.config.gridColor;
25243
- if (refX === 0 || refY === 0) color = this.config.gridOriginColor;
25244
- layer.add(new konva_lib_shapes_Circle.Circle({
25245
- x: pointX,
25246
- y: pointY,
25247
- radius: (pointX === 0 || pointY === 0 ? 2.5 : 1.5) / stage.scaleX(),
25248
- fill: color,
25249
- stroke: color,
25250
- strokeWidth: 0,
25251
- listening: false
25252
- }));
25253
- }
25276
+ const gridLayer = this.getLayer();
25277
+ if (!gridLayer) return;
25278
+ gridLayer.destroyChildren();
25279
+ if (!this.enabled) return;
25280
+ const scale = stage.scaleX();
25281
+ const spacing = this.getAdaptiveSpacing(scale);
25282
+ const invScale = (this.config.gridDotRadius ?? WEAVE_GRID_DEFAULT_RADIUS) / scale;
25283
+ const position = stage.position();
25284
+ const offsetX = -position.x * invScale;
25285
+ const offsetY = -position.y * invScale;
25286
+ const margin = 2;
25287
+ const worldWidth = stage.width() * invScale;
25288
+ const worldHeight = stage.height() * invScale;
25289
+ let startX = Math.floor((offsetX - margin * worldWidth) / spacing) * spacing;
25290
+ const endX = offsetX + (1 + margin) * worldWidth;
25291
+ let startY = Math.floor((offsetY - margin * worldHeight) / spacing) * spacing;
25292
+ const endY = offsetY + (1 + margin) * worldHeight;
25293
+ let adjustedSpacing = spacing;
25294
+ let dotCountX = Math.ceil((endX - startX) / adjustedSpacing);
25295
+ let dotCountY = Math.ceil((endY - startY) / adjustedSpacing);
25296
+ const maxDotsPerAxis = 500;
25297
+ while ((dotCountX > maxDotsPerAxis || dotCountY > maxDotsPerAxis) && adjustedSpacing < 1e6) {
25298
+ adjustedSpacing *= 2;
25299
+ dotCountX = Math.ceil((endX - startX) / adjustedSpacing);
25300
+ dotCountY = Math.ceil((endY - startY) / adjustedSpacing);
25301
+ }
25302
+ this.getAdjustedSpacing(startX, endX, startY, endY, spacing);
25303
+ startX = Math.floor((offsetX - margin * worldWidth) / adjustedSpacing) * adjustedSpacing;
25304
+ startY = Math.floor((offsetY - margin * worldHeight) / adjustedSpacing) * adjustedSpacing;
25305
+ const highlightEvery = this.config.gridMajorEvery ?? WEAVE_GRID_DEFAULT_MAJOR_EVERY;
25306
+ const majorColor = this.config.gridColor;
25307
+ const gridMajorRatio = this.config.gridMajorRatio ?? WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO;
25308
+ const majorShape = new konva.default.Shape({ sceneFunc: function(context) {
25309
+ context.beginPath();
25310
+ for (let x = startX; x <= endX; x += adjustedSpacing) for (let y = startY; y <= endY; y += adjustedSpacing) {
25311
+ if (Math.abs(x) < spacing / 2 || Math.abs(y) < spacing / 2) continue;
25312
+ const indexX = Math.round(x / spacing);
25313
+ const indexY = Math.round(y / spacing);
25314
+ const isHighlightX = indexX % highlightEvery === 0;
25315
+ const isHighlightY = indexY % highlightEvery === 0;
25316
+ const radius = !(isHighlightX || isHighlightY) ? invScale : invScale * gridMajorRatio;
25317
+ context.moveTo(x + radius, y);
25318
+ context.arc(x, y, radius, 0, Math.PI * 2, false);
25319
+ }
25320
+ context.fillStyle = majorColor;
25321
+ context.fill();
25322
+ } });
25323
+ gridLayer.add(majorShape);
25324
+ const originColor = this.config.gridOriginColor;
25325
+ const originShape = new konva.default.Shape({ sceneFunc: function(context) {
25326
+ context.beginPath();
25327
+ for (let x = startX; x <= endX; x += adjustedSpacing) {
25328
+ const radius = invScale * gridMajorRatio;
25329
+ context.moveTo(x + radius, 0);
25330
+ context.arc(x, 0, radius, 0, Math.PI * 2);
25331
+ }
25332
+ for (let y = startY; y <= endY; y += adjustedSpacing) {
25333
+ const radius = invScale * gridMajorRatio;
25334
+ if (Math.abs(y) < spacing / 2) continue;
25335
+ context.moveTo(0 + radius, y);
25336
+ context.arc(0, y, radius, 0, Math.PI * 2);
25337
+ }
25338
+ context.fillStyle = originColor;
25339
+ context.fill();
25340
+ } });
25341
+ gridLayer.add(originShape);
25342
+ }
25343
+ renderGrid() {
25344
+ switch (this.config.type) {
25345
+ case WEAVE_GRID_TYPES.LINES:
25346
+ this.renderGridLines();
25347
+ break;
25348
+ case WEAVE_GRID_TYPES.DOTS:
25349
+ this.renderGridDots();
25350
+ break;
25351
+ default: break;
25254
25352
  }
25255
25353
  }
25256
25354
  onRender() {
@@ -25338,7 +25436,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25338
25436
  this.moveToolActive = true;
25339
25437
  enableMove = true;
25340
25438
  }
25341
- if (e && (e.evt.button === 2 || e.evt.buttons === 4)) {
25439
+ if (!enableMove && e && e.evt.button === 1) {
25342
25440
  this.isMouseMiddleButtonPressed = true;
25343
25441
  enableMove = true;
25344
25442
  }
@@ -25375,7 +25473,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25375
25473
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
25376
25474
  stage.x(stage.x() - deltaX);
25377
25475
  stage.y(stage.y() - deltaY);
25378
- this.instance.emit("onStageMove", void 0);
25476
+ this.instance.emitEvent("onStageMove");
25379
25477
  };
25380
25478
  stage.on("mousemove", (0, import_lodash.throttle)(handleMouseMove, 50));
25381
25479
  stage.on("touchstart", (e) => {
@@ -25398,16 +25496,17 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25398
25496
  if (!this.enabled) return;
25399
25497
  stage.x(stage.x() - deltaX);
25400
25498
  stage.y(stage.y() - deltaY);
25401
- this.instance.emit("onStageMove", void 0);
25499
+ this.instance.emitEvent("onStageMove");
25402
25500
  });
25403
25501
  const handleWheel = (e) => {
25502
+ e.evt.preventDefault();
25404
25503
  const stage$1 = this.instance.getStage();
25405
- if (!this.enabled || !stage$1.isFocused() || this.isCtrlOrMetaPressed || !this.isSpaceKeyPressed) return;
25406
- stage$1.x(stage$1.x() - e.deltaX);
25407
- stage$1.y(stage$1.y() - e.deltaY);
25408
- this.instance.emit("onStageMove", void 0);
25504
+ if (!this.enabled || !stage$1.isFocused() || this.isCtrlOrMetaPressed) return;
25505
+ stage$1.x(stage$1.x() - e.evt.deltaX);
25506
+ stage$1.y(stage$1.y() - e.evt.deltaY);
25507
+ this.instance.emitEvent("onStageMove");
25409
25508
  };
25410
- window.addEventListener("wheel", (0, import_lodash.throttle)(handleWheel, 10));
25509
+ stage.on("wheel", (0, import_lodash.throttle)(handleWheel, 10));
25411
25510
  }
25412
25511
  enable() {
25413
25512
  this.enabled = true;
@@ -26292,8 +26391,13 @@ exports.WEAVE_FRAME_NODE_DEFAULT_CONFIG = WEAVE_FRAME_NODE_DEFAULT_CONFIG
26292
26391
  exports.WEAVE_FRAME_NODE_DEFAULT_PROPS = WEAVE_FRAME_NODE_DEFAULT_PROPS
26293
26392
  exports.WEAVE_FRAME_NODE_TYPE = WEAVE_FRAME_NODE_TYPE
26294
26393
  exports.WEAVE_GRID_DEFAULT_COLOR = WEAVE_GRID_DEFAULT_COLOR
26394
+ exports.WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO = WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO
26395
+ exports.WEAVE_GRID_DEFAULT_MAJOR_EVERY = WEAVE_GRID_DEFAULT_MAJOR_EVERY
26396
+ exports.WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO = WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO
26295
26397
  exports.WEAVE_GRID_DEFAULT_ORIGIN_COLOR = WEAVE_GRID_DEFAULT_ORIGIN_COLOR
26398
+ exports.WEAVE_GRID_DEFAULT_RADIUS = WEAVE_GRID_DEFAULT_RADIUS
26296
26399
  exports.WEAVE_GRID_DEFAULT_SIZE = WEAVE_GRID_DEFAULT_SIZE
26400
+ exports.WEAVE_GRID_DEFAULT_STROKE = WEAVE_GRID_DEFAULT_STROKE
26297
26401
  exports.WEAVE_GRID_DEFAULT_TYPE = WEAVE_GRID_DEFAULT_TYPE
26298
26402
  exports.WEAVE_GRID_LAYER_ID = WEAVE_GRID_LAYER_ID
26299
26403
  exports.WEAVE_GRID_TYPES = WEAVE_GRID_TYPES