@inditextech/weave-sdk 0.30.1 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.cjs CHANGED
@@ -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.0";
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);
@@ -18516,40 +18525,26 @@ var WeavePluginsManager = class {
18516
18525
  }
18517
18526
  enable(pluginName) {
18518
18527
  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?.();
18528
+ if (plugins[pluginName]) plugins[pluginName].enable();
18525
18529
  }
18526
18530
  disable(pluginName) {
18527
18531
  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?.();
18532
+ if (plugins[pluginName]) plugins[pluginName].disable();
18534
18533
  }
18535
18534
  isEnabled(pluginName) {
18536
18535
  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?.();
18536
+ if (plugins[pluginName]) return plugins[pluginName].isEnabled();
18537
+ return false;
18543
18538
  }
18544
18539
  };
18545
18540
 
18546
18541
  //#endregion
18547
18542
  //#region src/weave.ts
18548
- var Weave = class extends Emittery {
18543
+ var Weave = class {
18549
18544
  initialized = false;
18550
18545
  status = __inditextech_weave_types.WEAVE_INSTANCE_STATUS.IDLE;
18551
18546
  constructor(weaveConfig, stageConfig) {
18552
- super();
18547
+ this.emitter = new Emittery();
18553
18548
  konva.default.showWarnings = false;
18554
18549
  this.id = v4_default();
18555
18550
  this.initialized = false;
@@ -18636,7 +18631,7 @@ var Weave = class extends Emittery {
18636
18631
  }
18637
18632
  destroy() {
18638
18633
  this.moduleLogger.info(`Destroying the instance`);
18639
- this.clearListeners();
18634
+ this.emitter.clearListeners();
18640
18635
  this.status = __inditextech_weave_types.WEAVE_INSTANCE_STATUS.IDLE;
18641
18636
  this.emitEvent("onInstanceStatus", this.status);
18642
18637
  const store = this.storeManager.getStore();
@@ -18659,15 +18654,15 @@ var Weave = class extends Emittery {
18659
18654
  }
18660
18655
  emitEvent(event, payload) {
18661
18656
  this.moduleLogger.debug({ payload }, `Emitted event [${event}]`);
18662
- this.emit(event, payload);
18657
+ this.emitter.emit(event, payload);
18663
18658
  }
18664
18659
  addEventListener(event, callback) {
18665
18660
  this.moduleLogger.debug(`Listening event [${event}]`);
18666
- this.on(event, callback);
18661
+ this.emitter.on(event, callback);
18667
18662
  }
18668
18663
  removeEventListener(event, callback) {
18669
18664
  this.moduleLogger.debug(`Removing listening to event [${event}]`);
18670
- this.off(event, callback);
18665
+ this.emitter.off(event, callback);
18671
18666
  }
18672
18667
  getLogger() {
18673
18668
  return this.logger;
@@ -18930,6 +18925,7 @@ var WeaveLayerNode = class extends WeaveNode {
18930
18925
  const children = [...instance.getChildren()];
18931
18926
  for (const node of children) {
18932
18927
  const handler = this.instance.getNodeHandler(node.getAttr("nodeType"));
18928
+ if (!handler) continue;
18933
18929
  childrenMapped.push(handler.serialize(node));
18934
18930
  }
18935
18931
  return {
@@ -18984,6 +18980,7 @@ var WeaveGroupNode = class extends WeaveNode {
18984
18980
  const children = [...instance.getChildren()];
18985
18981
  for (const node of children) {
18986
18982
  const handler = this.instance.getNodeHandler(node.getAttr("nodeType"));
18983
+ if (!handler) continue;
18987
18984
  childrenMapped.push(handler.serialize(node));
18988
18985
  }
18989
18986
  return {
@@ -19689,7 +19686,7 @@ var WeaveImageToolAction = class extends WeaveAction {
19689
19686
  y: (mousePos?.y ?? 0) + 2
19690
19687
  });
19691
19688
  const nodeHandler = this.instance.getNodeHandler("rectangle");
19692
- this.instance.updateNode(nodeHandler.serialize(tempImage));
19689
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempImage));
19693
19690
  }
19694
19691
  });
19695
19692
  this.initialized = true;
@@ -19735,20 +19732,22 @@ var WeaveImageToolAction = class extends WeaveAction {
19735
19732
  const nodeHandler = this.instance.getNodeHandler("image");
19736
19733
  this.tempImageId = v4_default();
19737
19734
  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);
19735
+ if (nodeHandler) {
19736
+ const node = nodeHandler.create(this.tempImageId, {
19737
+ x: (mousePos?.x ?? 0) + 5,
19738
+ y: (mousePos?.y ?? 0) + 5,
19739
+ width: 100 * aspectRatio,
19740
+ height: 100,
19741
+ opacity: 1,
19742
+ adding: true,
19743
+ imageURL: this.imageURL,
19744
+ stroke: "#000000ff",
19745
+ strokeWidth: 0,
19746
+ strokeScaleEnabled: true,
19747
+ listening: false
19748
+ });
19749
+ this.instance.addNode(node, this.container?.getAttrs().id);
19750
+ }
19752
19751
  }
19753
19752
  this.clickPoint = null;
19754
19753
  this.setState(IMAGE_TOOL_STATE.ADDING);
@@ -19764,27 +19763,29 @@ var WeaveImageToolAction = class extends WeaveAction {
19764
19763
  this.clickPoint = mousePoint;
19765
19764
  this.container = container;
19766
19765
  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);
19766
+ if (nodeHandler) {
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);
19785
+ }
19785
19786
  if (!position) {
19786
19787
  const imageNodeHandler = this.instance.getNodeHandler("image");
19787
- this.instance.removeNode(imageNodeHandler.serialize(tempImage));
19788
+ if (imageNodeHandler) this.instance.removeNode(imageNodeHandler.serialize(tempImage));
19788
19789
  }
19789
19790
  this.setState(IMAGE_TOOL_STATE.FINISHED);
19790
19791
  }
@@ -19810,7 +19811,7 @@ var WeaveImageToolAction = class extends WeaveAction {
19810
19811
  const tempImage = this.instance.getStage().findOne(`#${this.tempImageId}`);
19811
19812
  if (tempImage) {
19812
19813
  const nodeHandler = this.instance.getNodeHandler("rectangle");
19813
- this.instance.removeNode(nodeHandler.serialize(tempImage));
19814
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempImage));
19814
19815
  }
19815
19816
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
19816
19817
  if (selectionPlugin) {
@@ -20445,7 +20446,7 @@ var WeaveImageNode = class extends WeaveNode {
20445
20446
  });
20446
20447
  this.updateImageCrop(imageProps);
20447
20448
  const nodeHandler = this.instance.getNodeHandler(image.getAttrs().nodeType);
20448
- this.instance.updateNode(nodeHandler.serialize(image));
20449
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(image));
20449
20450
  }
20450
20451
  };
20451
20452
  if (imageProps.imageURL) imageObj.src = imageProps.imageURL;
@@ -21009,6 +21010,7 @@ var WeaveFrameNode = class extends WeaveNode {
21009
21010
  const children = [...frameInternal.getChildren()];
21010
21011
  for (const node of children) {
21011
21012
  const handler = this.instance.getNodeHandler(node.getAttr("nodeType"));
21013
+ if (!handler) continue;
21012
21014
  childrenMapped.push(handler.serialize(node));
21013
21015
  }
21014
21016
  }
@@ -22922,6 +22924,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22922
22924
  if (!this.enabled) return;
22923
22925
  const stage = this.instance.getStage();
22924
22926
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
22927
+ if (!selectionPlugin) return;
22925
22928
  const nodes = selectionPlugin.getTransformer().getNodes();
22926
22929
  if (nodes.length === 0) return;
22927
22930
  let zoomTransformer = stage.findOne("#zoomTransformer");
@@ -23039,11 +23042,12 @@ var WeaveZoomOutToolAction = class extends WeaveAction {
23039
23042
  return ZOOM_OUT_TOOL_ACTION_NAME;
23040
23043
  }
23041
23044
  getStageZoomPlugin() {
23042
- return this.instance.getPlugin("stageZoom");
23045
+ const stageZoomPlugin = this.instance.getPlugin("stageZoom");
23046
+ if (!stageZoomPlugin) throw new Error("WeaveZoomOutToolAction requires the WeaveStageZoomPlugin to be loaded");
23047
+ return stageZoomPlugin;
23043
23048
  }
23044
23049
  onInit() {
23045
- const stageZoomPlugin = this.getStageZoomPlugin();
23046
- if (!stageZoomPlugin) throw new Error("WeaveZoomOutToolAction requires the WeaveStageZoomPlugin to be loaded");
23050
+ this.getStageZoomPlugin();
23047
23051
  }
23048
23052
  trigger(cancelAction, params) {
23049
23053
  const stageZoomPlugin = this.getStageZoomPlugin();
@@ -23072,11 +23076,12 @@ var WeaveZoomInToolAction = class extends WeaveAction {
23072
23076
  return ZOOM_IN_TOOL_ACTION_NAME;
23073
23077
  }
23074
23078
  getStageZoomPlugin() {
23075
- return this.instance.getPlugin("stageZoom");
23079
+ const stageZoomPlugin = this.instance.getPlugin("stageZoom");
23080
+ if (!stageZoomPlugin) throw new Error("WeaveZoomInToolAction requires the WeaveStageZoomPlugin to be loaded");
23081
+ return stageZoomPlugin;
23076
23082
  }
23077
23083
  onInit() {
23078
- const stageZoomPlugin = this.getStageZoomPlugin();
23079
- if (!stageZoomPlugin) throw new Error("WeaveZoomInToolAction requires the WeaveStageZoomPlugin to be loaded");
23084
+ this.getStageZoomPlugin();
23080
23085
  }
23081
23086
  trigger(cancelAction, params) {
23082
23087
  const stageZoomPlugin = this.getStageZoomPlugin();
@@ -23105,15 +23110,16 @@ var WeaveFitToScreenToolAction = class extends WeaveAction {
23105
23110
  return FIT_TO_SCREEN_TOOL_ACTION_NAME;
23106
23111
  }
23107
23112
  getStageZoomPlugin() {
23108
- return this.instance.getPlugin("stageZoom");
23113
+ const stageZoomPlugin = this.instance.getPlugin("stageZoom");
23114
+ if (!stageZoomPlugin) throw new Error("WeaveFitToScreenToolAction requires the WeaveStageZoomPlugin to be loaded");
23115
+ return stageZoomPlugin;
23109
23116
  }
23110
23117
  onInit() {
23111
- const stageZoomPlugin = this.getStageZoomPlugin();
23112
- if (!stageZoomPlugin) throw new Error("WeaveFitToScreenToolAction requires the WeaveStageZoomPlugin to be loaded");
23118
+ this.getStageZoomPlugin();
23113
23119
  }
23114
23120
  trigger(cancelAction, params) {
23115
23121
  const stageZoomPlugin = this.getStageZoomPlugin();
23116
- stageZoomPlugin.fitToScreen();
23122
+ if (stageZoomPlugin) stageZoomPlugin.fitToScreen();
23117
23123
  this.previousAction = params.previousAction;
23118
23124
  this.cancelAction = cancelAction;
23119
23125
  this.cancelAction();
@@ -23137,16 +23143,18 @@ var WeaveFitToSelectionToolAction = class extends WeaveAction {
23137
23143
  return FIT_TO_SELECTION_TOOL_ACTION_NAME;
23138
23144
  }
23139
23145
  getNodesSelectionPlugin() {
23140
- return this.instance.getPlugin("nodesSelection");
23146
+ const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
23147
+ if (!nodesSelectionPlugin) throw new Error("WeaveFitToSelectionToolAction requires the WeaveNodesSelectionPlugin to be loaded");
23148
+ return nodesSelectionPlugin;
23141
23149
  }
23142
23150
  getStageZoomPlugin() {
23143
- return this.instance.getPlugin("stageZoom");
23151
+ const stageZoomPlugin = this.instance.getPlugin("stageZoom");
23152
+ if (!stageZoomPlugin) throw new Error("WeaveFitToSelectionToolAction requires the WeaveStageZoomPlugin to be loaded");
23153
+ return stageZoomPlugin;
23144
23154
  }
23145
23155
  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");
23156
+ this.getStageZoomPlugin();
23157
+ this.getNodesSelectionPlugin();
23150
23158
  }
23151
23159
  trigger(cancelAction, params) {
23152
23160
  const stageZoomPlugin = this.getStageZoomPlugin();
@@ -23310,8 +23318,10 @@ var WeaveEraserToolAction = class extends WeaveAction {
23310
23318
  if (!realNode) return;
23311
23319
  const nodeType = realNode.getAttrs().nodeType;
23312
23320
  const nodeHandler = this.instance.getNodeHandler(nodeType);
23313
- const nodeSerialized = nodeHandler.serialize(realNode);
23314
- this.instance.removeNode(nodeSerialized);
23321
+ if (nodeHandler) {
23322
+ const nodeSerialized = nodeHandler.serialize(realNode);
23323
+ this.instance.removeNode(nodeSerialized);
23324
+ }
23315
23325
  }
23316
23326
  });
23317
23327
  stage.container().addEventListener("keydown", (e) => {
@@ -23447,15 +23457,17 @@ var WeaveRectangleToolAction = class extends WeaveAction {
23447
23457
  this.container = container;
23448
23458
  this.rectId = v4_default();
23449
23459
  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);
23460
+ if (nodeHandler) {
23461
+ const node = nodeHandler.create(this.rectId, {
23462
+ ...this.props,
23463
+ strokeScaleEnabled: true,
23464
+ x: this.clickPoint?.x ?? 0,
23465
+ y: this.clickPoint?.y ?? 0,
23466
+ width: 0,
23467
+ height: 0
23468
+ });
23469
+ this.instance.addNode(node, this.container?.getAttrs().id);
23470
+ }
23459
23471
  this.setState(RECTANGLE_TOOL_STATE.DEFINING_SIZE);
23460
23472
  }
23461
23473
  handleSettingSize() {
@@ -23482,7 +23494,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
23482
23494
  width: rectWidth,
23483
23495
  height: rectHeight
23484
23496
  });
23485
- this.instance.updateNode(nodeHandler.serialize(rectangle));
23497
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(rectangle));
23486
23498
  }
23487
23499
  this.cancelAction();
23488
23500
  }
@@ -23498,7 +23510,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
23498
23510
  width: deltaX,
23499
23511
  height: deltaY
23500
23512
  });
23501
- this.instance.updateNode(nodeHandler.serialize(rectangle));
23513
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(rectangle));
23502
23514
  }
23503
23515
  }
23504
23516
  trigger(cancelAction) {
@@ -23623,15 +23635,17 @@ var WeaveEllipseToolAction = class extends WeaveAction {
23623
23635
  this.container = container;
23624
23636
  this.ellipseId = v4_default();
23625
23637
  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);
23638
+ if (nodeHandler) {
23639
+ const node = nodeHandler.create(this.ellipseId, {
23640
+ ...this.props,
23641
+ strokeScaleEnabled: true,
23642
+ x: this.clickPoint?.x ?? 0 + this.props.radiusX,
23643
+ y: this.clickPoint?.y ?? 0 + this.props.radiusY,
23644
+ radiusX: 0,
23645
+ radiusY: 0
23646
+ });
23647
+ this.instance.addNode(node, this.container?.getAttrs().id);
23648
+ }
23635
23649
  this.setState(ELLIPSE_TOOL_STATE.DEFINING_SIZE);
23636
23650
  }
23637
23651
  handleSettingSize() {
@@ -23658,7 +23672,7 @@ var WeaveEllipseToolAction = class extends WeaveAction {
23658
23672
  radiusX: ellipseRadiusX,
23659
23673
  radiusY: ellipseRadiusY
23660
23674
  });
23661
- this.instance.updateNode(nodeHandler.serialize(ellipse));
23675
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(ellipse));
23662
23676
  }
23663
23677
  this.cancelAction();
23664
23678
  }
@@ -23684,7 +23698,7 @@ var WeaveEllipseToolAction = class extends WeaveAction {
23684
23698
  radiusX: deltaX,
23685
23699
  radiusY: deltaY
23686
23700
  });
23687
- this.instance.updateNode(nodeHandler.serialize(ellipse));
23701
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(ellipse));
23688
23702
  }
23689
23703
  }
23690
23704
  trigger(cancelAction) {
@@ -23811,14 +23825,16 @@ var WeavePenToolAction = class extends WeaveAction {
23811
23825
  this.lineId = v4_default();
23812
23826
  this.tempLineId = v4_default();
23813
23827
  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);
23828
+ if (nodeHandler) {
23829
+ const node = nodeHandler.create(this.lineId, {
23830
+ ...this.props,
23831
+ strokeScaleEnabled: true,
23832
+ x: this.clickPoint?.x ?? 0,
23833
+ y: this.clickPoint?.y ?? 0,
23834
+ points: [0, 0]
23835
+ });
23836
+ this.instance.addNode(node, this.container?.getAttrs().id);
23837
+ }
23822
23838
  this.tempPoint = new konva.default.Circle({
23823
23839
  x: this.clickPoint?.x ?? 0,
23824
23840
  y: this.clickPoint?.y ?? 0,
@@ -23829,14 +23845,16 @@ var WeavePenToolAction = class extends WeaveAction {
23829
23845
  fill: "#cccccc"
23830
23846
  });
23831
23847
  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);
23848
+ if (nodeHandler) {
23849
+ const tempLine = nodeHandler.create(this.tempLineId, {
23850
+ ...this.props,
23851
+ x: this.clickPoint?.x ?? 0,
23852
+ y: this.clickPoint?.y ?? 0,
23853
+ strokeScaleEnabled: true,
23854
+ points: [0, 0]
23855
+ });
23856
+ this.instance.addNode(tempLine, this.container?.getAttrs().id);
23857
+ }
23840
23858
  this.tempNextPoint = new konva.default.Circle({
23841
23859
  x: this.clickPoint?.x ?? 0,
23842
23860
  y: this.clickPoint?.y ?? 0,
@@ -23862,7 +23880,7 @@ var WeavePenToolAction = class extends WeaveAction {
23862
23880
  points: newPoints
23863
23881
  });
23864
23882
  const nodeHandler = this.instance.getNodeHandler("line");
23865
- this.instance.updateNode(nodeHandler.serialize(tempMainLine));
23883
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempMainLine));
23866
23884
  this.tempPoint.setAttrs({
23867
23885
  x: mousePoint.x,
23868
23886
  y: mousePoint.y
@@ -23877,7 +23895,7 @@ var WeavePenToolAction = class extends WeaveAction {
23877
23895
  y: mousePoint.y,
23878
23896
  points: [0, 0]
23879
23897
  });
23880
- this.instance.updateNode(nodeHandler.serialize(tempLine));
23898
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempLine));
23881
23899
  }
23882
23900
  this.setState(PEN_TOOL_STATE.DEFINING_SIZE);
23883
23901
  }
@@ -23896,7 +23914,7 @@ var WeavePenToolAction = class extends WeaveAction {
23896
23914
  ]
23897
23915
  });
23898
23916
  const nodeHandler = this.instance.getNodeHandler("line");
23899
- this.instance.updateNode(nodeHandler.serialize(tempLine));
23917
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempLine));
23900
23918
  this.tempNextPoint.setAttrs({
23901
23919
  x: mousePoint.x,
23902
23920
  y: mousePoint.y
@@ -23923,11 +23941,11 @@ var WeavePenToolAction = class extends WeaveAction {
23923
23941
  const tempMainLine = this.instance.getStage().findOne(`#${this.lineId}`);
23924
23942
  if (tempLine) {
23925
23943
  const nodeHandler = this.instance.getNodeHandler("line");
23926
- this.instance.removeNode(nodeHandler.serialize(tempLine));
23944
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempLine));
23927
23945
  }
23928
23946
  if (this.lineId && tempMainLine && tempMainLine.points().length < 4) {
23929
23947
  const nodeHandler = this.instance.getNodeHandler("line");
23930
- this.instance.removeNode(nodeHandler.serialize(tempMainLine));
23948
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempMainLine));
23931
23949
  }
23932
23950
  if (this.lineId && tempMainLine && tempMainLine.points().length >= 4) {
23933
23951
  const nodeHandler = this.instance.getNodeHandler("line");
@@ -23936,7 +23954,7 @@ var WeavePenToolAction = class extends WeaveAction {
23936
23954
  strokeWidth: 1,
23937
23955
  hitStrokeWidth: 16
23938
23956
  });
23939
- this.instance.updateNode(nodeHandler.serialize(tempMainLine));
23957
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempMainLine));
23940
23958
  }
23941
23959
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
23942
23960
  if (selectionPlugin) {
@@ -24035,14 +24053,16 @@ var WeaveBrushToolAction = class extends WeaveAction {
24035
24053
  this.measureContainer = measureContainer;
24036
24054
  this.strokeId = v4_default();
24037
24055
  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);
24056
+ if (nodeHandler) {
24057
+ const node = nodeHandler.create(this.strokeId, {
24058
+ ...this.props,
24059
+ strokeScaleEnabled: true,
24060
+ x: this.clickPoint?.x ?? 0,
24061
+ y: this.clickPoint?.y ?? 0,
24062
+ points: [0, 0]
24063
+ });
24064
+ this.instance.addNode(node, this.container?.getAttrs().id);
24065
+ }
24046
24066
  this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
24047
24067
  }
24048
24068
  handleEndStroke() {
@@ -24054,7 +24074,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
24054
24074
  ...this.props,
24055
24075
  hitStrokeWidth: 10
24056
24076
  });
24057
- this.instance.updateNode(nodeHandler.serialize(tempStroke));
24077
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempStroke));
24058
24078
  this.clickPoint = null;
24059
24079
  stage.container().tabIndex = 1;
24060
24080
  stage.container().focus();
@@ -24072,7 +24092,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
24072
24092
  mousePoint.y - tempStroke.y()
24073
24093
  ]);
24074
24094
  const nodeHandler = this.instance.getNodeHandler("line");
24075
- this.instance.updateNode(nodeHandler.serialize(tempStroke));
24095
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempStroke));
24076
24096
  }
24077
24097
  }
24078
24098
  trigger(cancel) {
@@ -24178,13 +24198,15 @@ var WeaveTextToolAction = class extends WeaveAction {
24178
24198
  this.container = container;
24179
24199
  this.textId = v4_default();
24180
24200
  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);
24201
+ if (nodeHandler) {
24202
+ const node = nodeHandler.create(this.textId, {
24203
+ ...this.props,
24204
+ x: this.clickPoint?.x ?? 0,
24205
+ y: this.clickPoint?.y ?? 0,
24206
+ draggable: true
24207
+ });
24208
+ this.instance.addNode(node, this.container?.getAttrs().id);
24209
+ }
24188
24210
  this.setState(TEXT_TOOL_STATE.FINISHED);
24189
24211
  this.cancelAction();
24190
24212
  }
@@ -24309,16 +24331,18 @@ var WeaveStarToolAction = class extends WeaveAction {
24309
24331
  this.container = container;
24310
24332
  this.starId = v4_default();
24311
24333
  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);
24334
+ if (nodeHandler) {
24335
+ const node = nodeHandler.create(this.starId, {
24336
+ ...this.props,
24337
+ strokeScaleEnabled: true,
24338
+ x: this.clickPoint?.x ?? 0 + this.props.outerRadius,
24339
+ y: this.clickPoint?.y ?? 0 + this.props.outerRadius,
24340
+ numPoints: 5,
24341
+ innerRadius: 0,
24342
+ outerRadius: 0
24343
+ });
24344
+ this.instance.addNode(node, this.container?.getAttrs().id);
24345
+ }
24322
24346
  this.setState(STAR_TOOL_STATE.DEFINING_SIZE);
24323
24347
  }
24324
24348
  handleSettingSize() {
@@ -24345,7 +24369,7 @@ var WeaveStarToolAction = class extends WeaveAction {
24345
24369
  outerRadius: starOuterRadius,
24346
24370
  innerRadius: starInnerRadius
24347
24371
  });
24348
- this.instance.updateNode(nodeHandler.serialize(star));
24372
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(star));
24349
24373
  }
24350
24374
  this.cancelAction();
24351
24375
  }
@@ -24371,7 +24395,7 @@ var WeaveStarToolAction = class extends WeaveAction {
24371
24395
  outerRadius: deltaX,
24372
24396
  innerRadius: deltaY
24373
24397
  });
24374
- this.instance.updateNode(nodeHandler.serialize(star));
24398
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(star));
24375
24399
  }
24376
24400
  }
24377
24401
  trigger(cancelAction) {
@@ -24504,14 +24528,16 @@ var WeaveArrowToolAction = class extends WeaveAction {
24504
24528
  this.tempArrowId = v4_default();
24505
24529
  const nodeHandler = this.instance.getNodeHandler("arrow");
24506
24530
  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);
24531
+ if (lineNodeHandler) {
24532
+ const node = lineNodeHandler.create(this.arrowId, {
24533
+ ...this.props,
24534
+ strokeScaleEnabled: true,
24535
+ x: this.clickPoint?.x ?? 0,
24536
+ y: this.clickPoint?.y ?? 0,
24537
+ points: [0, 0]
24538
+ });
24539
+ this.instance.addNode(node, this.container?.getAttrs().id);
24540
+ }
24515
24541
  this.tempPoint = new konva.default.Circle({
24516
24542
  x: this.clickPoint?.x ?? 0,
24517
24543
  y: this.clickPoint?.y ?? 0,
@@ -24522,14 +24548,16 @@ var WeaveArrowToolAction = class extends WeaveAction {
24522
24548
  fill: "#cccccc"
24523
24549
  });
24524
24550
  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);
24551
+ if (nodeHandler) {
24552
+ const tempArrow = nodeHandler.create(this.tempArrowId, {
24553
+ ...this.props,
24554
+ x: this.clickPoint?.x ?? 0,
24555
+ y: this.clickPoint?.y ?? 0,
24556
+ strokeScaleEnabled: true,
24557
+ points: [0, 0]
24558
+ });
24559
+ this.instance.addNode(tempArrow, this.container?.getAttrs().id);
24560
+ }
24533
24561
  this.tempNextPoint = new konva.default.Circle({
24534
24562
  x: this.clickPoint?.x ?? 0,
24535
24563
  y: this.clickPoint?.y ?? 0,
@@ -24556,7 +24584,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
24556
24584
  });
24557
24585
  const nodeHandler = this.instance.getNodeHandler("arrow");
24558
24586
  const lineNodeHandler = this.instance.getNodeHandler("line");
24559
- this.instance.updateNode(lineNodeHandler.serialize(tempMainArrow));
24587
+ if (lineNodeHandler) this.instance.updateNode(lineNodeHandler.serialize(tempMainArrow));
24560
24588
  this.tempPoint.setAttrs({
24561
24589
  x: mousePoint.x,
24562
24590
  y: mousePoint.y
@@ -24571,7 +24599,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
24571
24599
  y: mousePoint.y,
24572
24600
  points: [0, 0]
24573
24601
  });
24574
- this.instance.updateNode(nodeHandler.serialize(tempArrow));
24602
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempArrow));
24575
24603
  }
24576
24604
  this.setState(ARROW_TOOL_STATE.DEFINING_SIZE);
24577
24605
  }
@@ -24590,7 +24618,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
24590
24618
  ]
24591
24619
  });
24592
24620
  const nodeHandler = this.instance.getNodeHandler("arrow");
24593
- this.instance.updateNode(nodeHandler.serialize(tempArrow));
24621
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(tempArrow));
24594
24622
  this.tempNextPoint.setAttrs({
24595
24623
  x: mousePoint.x,
24596
24624
  y: mousePoint.y
@@ -24617,24 +24645,26 @@ var WeaveArrowToolAction = class extends WeaveAction {
24617
24645
  const tempMainArrow = this.instance.getStage().findOne(`#${this.arrowId}`);
24618
24646
  if (tempArrow) {
24619
24647
  const nodeHandler = this.instance.getNodeHandler("arrow");
24620
- this.instance.removeNode(nodeHandler.serialize(tempArrow));
24648
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempArrow));
24621
24649
  }
24622
24650
  if (this.arrowId && tempMainArrow && tempMainArrow.points().length < 4) {
24623
24651
  const nodeHandler = this.instance.getNodeHandler("line");
24624
- this.instance.removeNode(nodeHandler.serialize(tempMainArrow));
24652
+ if (nodeHandler) this.instance.removeNode(nodeHandler.serialize(tempMainArrow));
24625
24653
  }
24626
24654
  if (this.arrowId && tempMainArrow && tempMainArrow.points().length >= 4) {
24627
24655
  const nodeHandler = this.instance.getNodeHandler("arrow");
24628
24656
  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);
24657
+ if (nodeHandler && lineNodeHandler) {
24658
+ const finalArrow = nodeHandler.create(this.arrowId, {
24659
+ ...tempMainArrow.getAttrs(),
24660
+ ...this.props,
24661
+ strokeScaleEnabled: true,
24662
+ strokeWidth: 1,
24663
+ hitStrokeWidth: 16
24664
+ });
24665
+ this.instance.removeNode(lineNodeHandler.serialize(tempMainArrow));
24666
+ this.instance.addNode(finalArrow, this.container?.getAttrs().id);
24667
+ }
24638
24668
  }
24639
24669
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
24640
24670
  if (selectionPlugin) {
@@ -24745,14 +24775,16 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
24745
24775
  this.container = container;
24746
24776
  this.regularPolygonId = v4_default();
24747
24777
  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);
24778
+ if (nodeHandler) {
24779
+ const node = nodeHandler.create(this.regularPolygonId, {
24780
+ ...this.props,
24781
+ strokeScaleEnabled: true,
24782
+ x: (this.clickPoint?.x ?? 0) + this.props.radius,
24783
+ y: (this.clickPoint?.y ?? 0) + this.props.radius,
24784
+ radius: 0
24785
+ });
24786
+ this.instance.addNode(node, this.container?.getAttrs().id);
24787
+ }
24756
24788
  this.setState(REGULAR_POLYGON_TOOL_STATE.DEFINING_SIZE);
24757
24789
  }
24758
24790
  handleSettingSize() {
@@ -24776,7 +24808,7 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
24776
24808
  y: starPos.y + newRadius,
24777
24809
  radius: newRadius
24778
24810
  });
24779
- this.instance.updateNode(nodeHandler.serialize(regularPolygon));
24811
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(regularPolygon));
24780
24812
  }
24781
24813
  this.cancelAction();
24782
24814
  }
@@ -24800,7 +24832,7 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
24800
24832
  y: starPos.y + deltaX,
24801
24833
  radius: deltaX
24802
24834
  });
24803
- this.instance.updateNode(nodeHandler.serialize(regularPolygon));
24835
+ if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(regularPolygon));
24804
24836
  }
24805
24837
  }
24806
24838
  trigger(cancelAction) {
@@ -24905,12 +24937,14 @@ var WeaveFrameToolAction = class extends WeaveAction {
24905
24937
  this.container = container;
24906
24938
  this.frameId = v4_default();
24907
24939
  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);
24940
+ if (nodeHandler) {
24941
+ const node = nodeHandler.create(this.frameId, {
24942
+ ...this.props,
24943
+ x: this.clickPoint.x,
24944
+ y: this.clickPoint.y
24945
+ });
24946
+ this.instance.addNode(node, this.container?.getAttrs().id);
24947
+ }
24914
24948
  this.cancelAction?.();
24915
24949
  }
24916
24950
  trigger(cancelAction, params) {
@@ -25055,13 +25089,15 @@ const WEAVE_GRID_DEFAULT_SIZE = 50;
25055
25089
  const WEAVE_GRID_DEFAULT_TYPE = WEAVE_GRID_TYPES.LINES;
25056
25090
  const WEAVE_GRID_DEFAULT_COLOR = "rgba(0,0,0,0.2)";
25057
25091
  const WEAVE_GRID_DEFAULT_ORIGIN_COLOR = "rgba(255,0,0,0.2)";
25092
+ const WEAVE_GRID_DEFAULT_STROKE = .5;
25093
+ const WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO = 4;
25094
+ const WEAVE_GRID_DEFAULT_RADIUS = 1;
25095
+ const WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO = 2;
25096
+ const WEAVE_GRID_DEFAULT_MAJOR_EVERY = 10;
25058
25097
  const WEAVE_GRID_LAYER_ID = "gridLayer";
25059
25098
 
25060
25099
  //#endregion
25061
25100
  //#region src/plugins/stage-grid/stage-grid.ts
25062
- function isZeroOrClose(value, tolerance = 1e-6) {
25063
- return Math.abs(value) <= tolerance;
25064
- }
25065
25101
  var WeaveStageGridPlugin = class extends WeavePlugin {
25066
25102
  constructor(params) {
25067
25103
  super();
@@ -25146,111 +25182,167 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
25146
25182
  const layer = stage.findOne(`#${WEAVE_GRID_LAYER_ID}`);
25147
25183
  return layer;
25148
25184
  }
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;
25185
+ getAdaptiveSpacing(scale) {
25186
+ const baseGridSpacing = this.config.gridSize;
25187
+ const minPixelSpacing = 8;
25188
+ const maxPixelSpacing = 100;
25189
+ let spacing = baseGridSpacing;
25190
+ let pixelSpacing = spacing * scale;
25191
+ while (pixelSpacing < minPixelSpacing) {
25192
+ spacing *= 2;
25193
+ pixelSpacing = spacing * scale;
25194
+ }
25195
+ while (pixelSpacing > maxPixelSpacing && spacing > baseGridSpacing / 16) {
25196
+ spacing /= 2;
25197
+ pixelSpacing = spacing * scale;
25198
+ }
25199
+ const logFactor = Math.round(Math.log2(spacing / baseGridSpacing));
25200
+ const snappedSpacing = baseGridSpacing * Math.pow(2, logFactor);
25201
+ return snappedSpacing;
25202
+ }
25203
+ getAdjustedSpacing(startX, endX, startY, endY, baseSpacing = 50, maxDotsPerAxis = 500) {
25204
+ let spacing = baseSpacing;
25205
+ let dotCountX = Math.ceil((endX - startX) / spacing);
25206
+ let dotCountY = Math.ceil((endY - startY) / spacing);
25207
+ while ((dotCountX > maxDotsPerAxis || dotCountY > maxDotsPerAxis) && spacing < 1e6) {
25208
+ spacing *= 2;
25209
+ dotCountX = Math.ceil((endX - startX) / spacing);
25210
+ dotCountY = Math.ceil((endY - startY) / spacing);
25211
+ }
25212
+ return spacing;
25168
25213
  }
25169
25214
  renderGridLines() {
25170
- const layer = this.getLayer();
25171
- if (!layer) return;
25172
25215
  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({
25216
+ const gridLayer = this.getLayer();
25217
+ if (!gridLayer) return;
25218
+ gridLayer.destroyChildren();
25219
+ if (!this.enabled) return;
25220
+ const scale = stage.scaleX();
25221
+ const spacing = this.getAdaptiveSpacing(scale);
25222
+ const invScale = (this.config.gridStroke ?? WEAVE_GRID_DEFAULT_STROKE) / scale;
25223
+ const offsetX = -stage.x() / stage.scaleX();
25224
+ const offsetY = -stage.y() / stage.scaleY();
25225
+ const margin = 2;
25226
+ const worldWidth = stage.width() * invScale;
25227
+ const worldHeight = stage.height() * invScale;
25228
+ const startX = Math.floor((offsetX - margin * worldWidth) / spacing) * spacing;
25229
+ const startY = Math.floor((offsetY - margin * worldHeight) / spacing) * spacing;
25230
+ const endX = offsetX + (1 + margin) * worldWidth;
25231
+ const endY = offsetY + (1 + margin) * worldHeight;
25232
+ const highlightEvery = this.config.gridMajorEvery ?? WEAVE_GRID_DEFAULT_MAJOR_EVERY;
25233
+ for (let x = startX; x <= endX; x += spacing) {
25234
+ const index = Math.round(x / spacing);
25235
+ const isHighlight = index % highlightEvery === 0;
25236
+ const isOrigin = Math.abs(x) < spacing / 2;
25237
+ const line = new konva.default.Line({
25192
25238
  points: [
25193
- point,
25194
- (-stage.y() - overflowY) / stage.scaleY(),
25195
- point,
25196
- (-stage.y() + stage.height() + overflowY) / stage.scaleY()
25239
+ x,
25240
+ startY,
25241
+ x,
25242
+ endY
25197
25243
  ],
25198
- stroke: color,
25199
- strokeWidth: (isZeroOrClose(ref % (10 * this.config.gridSize)) ? 2.5 : .5) / stage.scaleX(),
25244
+ stroke: isOrigin ? this.config.gridOriginColor : this.config.gridColor,
25245
+ strokeWidth: !isHighlight && !isOrigin ? invScale : invScale * (this.config.gridMajorRatio ?? WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO),
25200
25246
  listening: false
25201
- }));
25247
+ });
25248
+ gridLayer.add(line);
25202
25249
  }
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({
25250
+ for (let y = startY; y <= endY; y += spacing) {
25251
+ const index = Math.round(y / spacing);
25252
+ const isHighlight = index % highlightEvery === 0;
25253
+ const isOrigin = Math.abs(y) < spacing / 2;
25254
+ const line = new konva.default.Line({
25208
25255
  points: [
25209
- (-stage.x() - overflowX) / stage.scaleX(),
25210
- point,
25211
- (-stage.x() + stage.width() + overflowX) / stage.scaleX(),
25212
- point
25256
+ startX,
25257
+ y,
25258
+ endX,
25259
+ y
25213
25260
  ],
25214
- stroke: color,
25215
- strokeWidth: (isZeroOrClose(ref % (10 * this.config.gridSize)) ? 2.5 : .5) / stage.scaleX(),
25261
+ stroke: isOrigin ? this.config.gridOriginColor : this.config.gridColor,
25262
+ strokeWidth: !isHighlight && !isOrigin ? invScale : invScale * 2,
25216
25263
  listening: false
25217
- }));
25264
+ });
25265
+ gridLayer.add(line);
25218
25266
  }
25219
25267
  }
25220
25268
  renderGridDots() {
25221
- const layer = this.getLayer();
25222
- if (!layer) return;
25223
25269
  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
- }
25270
+ const gridLayer = this.getLayer();
25271
+ if (!gridLayer) return;
25272
+ gridLayer.destroyChildren();
25273
+ if (!this.enabled) return;
25274
+ const scale = stage.scaleX();
25275
+ const spacing = this.getAdaptiveSpacing(scale);
25276
+ const invScale = (this.config.gridDotRadius ?? WEAVE_GRID_DEFAULT_RADIUS) / scale;
25277
+ const position = stage.position();
25278
+ const offsetX = -position.x * invScale;
25279
+ const offsetY = -position.y * invScale;
25280
+ const margin = 2;
25281
+ const worldWidth = stage.width() * invScale;
25282
+ const worldHeight = stage.height() * invScale;
25283
+ let startX = Math.floor((offsetX - margin * worldWidth) / spacing) * spacing;
25284
+ const endX = offsetX + (1 + margin) * worldWidth;
25285
+ let startY = Math.floor((offsetY - margin * worldHeight) / spacing) * spacing;
25286
+ const endY = offsetY + (1 + margin) * worldHeight;
25287
+ let adjustedSpacing = spacing;
25288
+ let dotCountX = Math.ceil((endX - startX) / adjustedSpacing);
25289
+ let dotCountY = Math.ceil((endY - startY) / adjustedSpacing);
25290
+ const maxDotsPerAxis = 500;
25291
+ while ((dotCountX > maxDotsPerAxis || dotCountY > maxDotsPerAxis) && adjustedSpacing < 1e6) {
25292
+ adjustedSpacing *= 2;
25293
+ dotCountX = Math.ceil((endX - startX) / adjustedSpacing);
25294
+ dotCountY = Math.ceil((endY - startY) / adjustedSpacing);
25295
+ }
25296
+ this.getAdjustedSpacing(startX, endX, startY, endY, spacing);
25297
+ startX = Math.floor((offsetX - margin * worldWidth) / adjustedSpacing) * adjustedSpacing;
25298
+ startY = Math.floor((offsetY - margin * worldHeight) / adjustedSpacing) * adjustedSpacing;
25299
+ const highlightEvery = this.config.gridMajorEvery ?? WEAVE_GRID_DEFAULT_MAJOR_EVERY;
25300
+ const majorColor = this.config.gridColor;
25301
+ const gridMajorRatio = this.config.gridMajorRatio ?? WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO;
25302
+ const majorShape = new konva.default.Shape({ sceneFunc: function(context) {
25303
+ context.beginPath();
25304
+ for (let x = startX; x <= endX; x += adjustedSpacing) for (let y = startY; y <= endY; y += adjustedSpacing) {
25305
+ if (Math.abs(x) < spacing / 2 || Math.abs(y) < spacing / 2) continue;
25306
+ const indexX = Math.round(x / spacing);
25307
+ const indexY = Math.round(y / spacing);
25308
+ const isHighlightX = indexX % highlightEvery === 0;
25309
+ const isHighlightY = indexY % highlightEvery === 0;
25310
+ const radius = !(isHighlightX || isHighlightY) ? invScale : invScale * gridMajorRatio;
25311
+ context.moveTo(x + radius, y);
25312
+ context.arc(x, y, radius, 0, Math.PI * 2, false);
25313
+ }
25314
+ context.fillStyle = majorColor;
25315
+ context.fill();
25316
+ } });
25317
+ gridLayer.add(majorShape);
25318
+ const originColor = this.config.gridOriginColor;
25319
+ const originShape = new konva.default.Shape({ sceneFunc: function(context) {
25320
+ context.beginPath();
25321
+ for (let x = startX; x <= endX; x += adjustedSpacing) {
25322
+ const radius = invScale * gridMajorRatio;
25323
+ context.moveTo(x + radius, 0);
25324
+ context.arc(x, 0, radius, 0, Math.PI * 2);
25325
+ }
25326
+ for (let y = startY; y <= endY; y += adjustedSpacing) {
25327
+ const radius = invScale * gridMajorRatio;
25328
+ if (Math.abs(y) < spacing / 2) continue;
25329
+ context.moveTo(0 + radius, y);
25330
+ context.arc(0, y, radius, 0, Math.PI * 2);
25331
+ }
25332
+ context.fillStyle = originColor;
25333
+ context.fill();
25334
+ } });
25335
+ gridLayer.add(originShape);
25336
+ }
25337
+ renderGrid() {
25338
+ switch (this.config.type) {
25339
+ case WEAVE_GRID_TYPES.LINES:
25340
+ this.renderGridLines();
25341
+ break;
25342
+ case WEAVE_GRID_TYPES.DOTS:
25343
+ this.renderGridDots();
25344
+ break;
25345
+ default: break;
25254
25346
  }
25255
25347
  }
25256
25348
  onRender() {
@@ -25375,7 +25467,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25375
25467
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
25376
25468
  stage.x(stage.x() - deltaX);
25377
25469
  stage.y(stage.y() - deltaY);
25378
- this.instance.emit("onStageMove", void 0);
25470
+ this.instance.emitEvent("onStageMove");
25379
25471
  };
25380
25472
  stage.on("mousemove", (0, import_lodash.throttle)(handleMouseMove, 50));
25381
25473
  stage.on("touchstart", (e) => {
@@ -25398,14 +25490,14 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25398
25490
  if (!this.enabled) return;
25399
25491
  stage.x(stage.x() - deltaX);
25400
25492
  stage.y(stage.y() - deltaY);
25401
- this.instance.emit("onStageMove", void 0);
25493
+ this.instance.emitEvent("onStageMove");
25402
25494
  });
25403
25495
  const handleWheel = (e) => {
25404
25496
  const stage$1 = this.instance.getStage();
25405
- if (!this.enabled || !stage$1.isFocused() || this.isCtrlOrMetaPressed || !this.isSpaceKeyPressed) return;
25497
+ if (!this.enabled || !stage$1.isFocused() || this.isCtrlOrMetaPressed) return;
25406
25498
  stage$1.x(stage$1.x() - e.deltaX);
25407
25499
  stage$1.y(stage$1.y() - e.deltaY);
25408
- this.instance.emit("onStageMove", void 0);
25500
+ this.instance.emitEvent("onStageMove");
25409
25501
  };
25410
25502
  window.addEventListener("wheel", (0, import_lodash.throttle)(handleWheel, 10));
25411
25503
  }
@@ -26292,8 +26384,13 @@ exports.WEAVE_FRAME_NODE_DEFAULT_CONFIG = WEAVE_FRAME_NODE_DEFAULT_CONFIG
26292
26384
  exports.WEAVE_FRAME_NODE_DEFAULT_PROPS = WEAVE_FRAME_NODE_DEFAULT_PROPS
26293
26385
  exports.WEAVE_FRAME_NODE_TYPE = WEAVE_FRAME_NODE_TYPE
26294
26386
  exports.WEAVE_GRID_DEFAULT_COLOR = WEAVE_GRID_DEFAULT_COLOR
26387
+ exports.WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO = WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO
26388
+ exports.WEAVE_GRID_DEFAULT_MAJOR_EVERY = WEAVE_GRID_DEFAULT_MAJOR_EVERY
26389
+ exports.WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO = WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO
26295
26390
  exports.WEAVE_GRID_DEFAULT_ORIGIN_COLOR = WEAVE_GRID_DEFAULT_ORIGIN_COLOR
26391
+ exports.WEAVE_GRID_DEFAULT_RADIUS = WEAVE_GRID_DEFAULT_RADIUS
26296
26392
  exports.WEAVE_GRID_DEFAULT_SIZE = WEAVE_GRID_DEFAULT_SIZE
26393
+ exports.WEAVE_GRID_DEFAULT_STROKE = WEAVE_GRID_DEFAULT_STROKE
26297
26394
  exports.WEAVE_GRID_DEFAULT_TYPE = WEAVE_GRID_DEFAULT_TYPE
26298
26395
  exports.WEAVE_GRID_LAYER_ID = WEAVE_GRID_LAYER_ID
26299
26396
  exports.WEAVE_GRID_TYPES = WEAVE_GRID_TYPES