@inditextech/weave-sdk 0.47.0 → 0.48.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
@@ -15665,21 +15665,21 @@ function clearContainerTargets(instance) {
15665
15665
  const containers = instance.getContainerNodes();
15666
15666
  for (const container of containers) container.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
15667
15667
  }
15668
- function containerOverCursor(instance) {
15668
+ function containerOverCursor(instance, ignoreNodes) {
15669
15669
  konva.default.hitOnDragEnabled = true;
15670
15670
  const stage = instance.getStage();
15671
15671
  const cursorPosition = stage.getRelativePointerPosition();
15672
15672
  if (!cursorPosition) return void 0;
15673
- const nodesUnderPointer = new Set();
15674
- stage.find("Shape").reverse().forEach((node) => {
15675
- if (!node.isVisible() || !(node instanceof konva.default.Shape)) return;
15673
+ const containerUnderPointer = new Set();
15674
+ stage.find(".containerCapable").reverse().forEach((node) => {
15675
+ if (!node.isVisible()) return;
15676
+ if (containsNodeDeep(ignoreNodes, node)) return;
15676
15677
  const shapeRect = node.getClientRect({ relativeTo: stage });
15677
- if (cursorPosition.x >= shapeRect.x && cursorPosition.x <= shapeRect.x + shapeRect.width && cursorPosition.y >= shapeRect.y && cursorPosition.y <= shapeRect.y + shapeRect.height && node.getAttrs().nodeId) {
15678
- const realNode = stage.findOne(`#${node.getAttrs().nodeId}`);
15679
- if (realNode?.getAttrs().isContainerPrincipal) nodesUnderPointer.add(realNode);
15678
+ if (cursorPosition.x >= shapeRect.x && cursorPosition.x <= shapeRect.x + shapeRect.width && cursorPosition.y >= shapeRect.y && cursorPosition.y <= shapeRect.y + shapeRect.height) {
15679
+ if (node?.getAttrs().isContainerPrincipal) containerUnderPointer.add(node);
15680
15680
  }
15681
15681
  });
15682
- const nodes = Array.from(nodesUnderPointer);
15682
+ const nodes = Array.from(containerUnderPointer);
15683
15683
  if (nodes.length === 0) return void 0;
15684
15684
  let layerToMove = void 0;
15685
15685
  if (nodes[0]?.getAttrs().containerId && nodes[0]?.getAttrs().isContainerPrincipal) layerToMove = nodes[0];
@@ -15738,6 +15738,31 @@ function stringToColor(str) {
15738
15738
  }
15739
15739
  return color;
15740
15740
  }
15741
+ function getExportBoundingBox(stage, nodes) {
15742
+ if (nodes.length === 0) return {
15743
+ x: 0,
15744
+ y: 0,
15745
+ width: 0,
15746
+ height: 0
15747
+ };
15748
+ let minX = Infinity;
15749
+ let minY = Infinity;
15750
+ let maxX = -Infinity;
15751
+ let maxY = -Infinity;
15752
+ for (const node of nodes) {
15753
+ const box = node.getExportClientRect({ skipTransform: false });
15754
+ minX = Math.min(minX, box.x);
15755
+ minY = Math.min(minY, box.y);
15756
+ maxX = Math.max(maxX, box.x + box.width);
15757
+ maxY = Math.max(maxY, box.y + box.height);
15758
+ }
15759
+ return {
15760
+ x: minX,
15761
+ y: minY,
15762
+ width: maxX - minX,
15763
+ height: maxY - minY
15764
+ };
15765
+ }
15741
15766
  function getBoundingBox(stage, nodes) {
15742
15767
  if (nodes.length === 0) return {
15743
15768
  x: 0,
@@ -15794,6 +15819,24 @@ function hasFrames(node) {
15794
15819
  function intersectArrays(arrays) {
15795
15820
  return arrays.reduce((acc, arr) => acc.filter((val) => arr.includes(val)), arrays[0]);
15796
15821
  }
15822
+ function isNodeInSelection(node, nodes) {
15823
+ return nodes.some((selectedNode) => selectedNode.id() === node.id());
15824
+ }
15825
+ function containsNodeDeep(nodes, target) {
15826
+ for (const node of nodes) {
15827
+ if (node === target) return true;
15828
+ if (node.hasChildren?.() && containsNodeDeep(node.getChildren(), target)) return true;
15829
+ }
15830
+ return false;
15831
+ }
15832
+
15833
+ //#endregion
15834
+ //#region src/actions/selection-tool/constants.ts
15835
+ const SELECTION_TOOL_ACTION_NAME = "selectionTool";
15836
+ const SELECTION_TOOL_STATE = {
15837
+ ["IDLE"]: "idle",
15838
+ ["SELECTING"]: "selection"
15839
+ };
15797
15840
 
15798
15841
  //#endregion
15799
15842
  //#region src/plugins/context-menu/context-menu.ts
@@ -15907,7 +15950,7 @@ var WeaveContextMenuPlugin = class extends WeavePlugin {
15907
15950
  this.timer = setTimeout(() => {
15908
15951
  this.tapHold = true;
15909
15952
  const actualActions = this.instance.getActiveAction();
15910
- if (actualActions !== "selectionTool") return;
15953
+ if (actualActions !== SELECTION_TOOL_ACTION_NAME) return;
15911
15954
  delete this.pointers[e.evt.pointerId];
15912
15955
  const selectedGroup = getTargetedNode(this.instance);
15913
15956
  this.triggerContextMenu(e.target, selectedGroup);
@@ -16088,7 +16131,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16088
16131
  return this.selecting;
16089
16132
  }
16090
16133
  isSelecting() {
16091
- return this.instance.getActiveAction() === "selectionTool";
16134
+ return this.instance.getActiveAction() === SELECTION_TOOL_ACTION_NAME;
16092
16135
  }
16093
16136
  isNodeSelected(ele) {
16094
16137
  let selected = false;
@@ -16181,7 +16224,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16181
16224
  }
16182
16225
  if (this.isSelecting() && selectedNodes.length > 1) {
16183
16226
  clearContainerTargets(this.instance);
16184
- const layerToMove = containerOverCursor(this.instance);
16227
+ const layerToMove = containerOverCursor(this.instance, selectedNodes);
16185
16228
  if (layerToMove && !selectionContainsFrames) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
16186
16229
  }
16187
16230
  tr.forceUpdate();
@@ -16203,7 +16246,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16203
16246
  clearContainerTargets(this.instance);
16204
16247
  const toSelect = [];
16205
16248
  const toUpdate = [];
16206
- const layerToMove = containerOverCursor(this.instance);
16249
+ const layerToMove = containerOverCursor(this.instance, selectedNodes);
16207
16250
  const nodeUpdatePromise = (node) => {
16208
16251
  return new Promise((resolve) => {
16209
16252
  setTimeout(() => {
@@ -16215,10 +16258,11 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16215
16258
  containerToMove = layerToMove;
16216
16259
  containerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
16217
16260
  }
16218
- if (containerToMove && !selectionContainsFrames) moveNodeToContainer(this.instance, node, containerToMove);
16261
+ let moved = false;
16262
+ if (containerToMove && !selectionContainsFrames) moved = moveNodeToContainer(this.instance, node, containerToMove);
16219
16263
  if (!nodeHandler) return resolve();
16220
16264
  toSelect.push(node.getAttrs().id ?? "");
16221
- toUpdate.push(nodeHandler.serialize(node));
16265
+ if (!moved) toUpdate.push(nodeHandler.serialize(node));
16222
16266
  resolve();
16223
16267
  }, 0);
16224
16268
  });
@@ -16251,7 +16295,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16251
16295
  this.initEvents();
16252
16296
  this.initialized = true;
16253
16297
  this.instance.addEventListener("onActiveActionChange", (activeAction) => {
16254
- if (typeof activeAction !== "undefined" && activeAction !== "selectionTool") {
16298
+ if (typeof activeAction !== "undefined" && activeAction !== SELECTION_TOOL_ACTION_NAME) {
16255
16299
  this.active = false;
16256
16300
  return;
16257
16301
  }
@@ -16554,7 +16598,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16554
16598
  const stage = this.instance.getStage();
16555
16599
  e.cancelBubble = true;
16556
16600
  if (!this.enabled) return;
16557
- if (this.instance.getActiveAction() !== "selectionTool") return;
16601
+ if (this.instance.getActiveAction() !== SELECTION_TOOL_ACTION_NAME) return;
16558
16602
  const contextMenuPlugin = this.getContextMenuPlugin();
16559
16603
  if (contextMenuPlugin?.isContextMenuVisible()) {
16560
16604
  this.selecting = false;
@@ -16922,6 +16966,14 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
16922
16966
  }
16923
16967
  };
16924
16968
 
16969
+ //#endregion
16970
+ //#region src/actions/move-tool/constants.ts
16971
+ const MOVE_TOOL_ACTION_NAME = "moveTool";
16972
+ const MOVE_TOOL_STATE = {
16973
+ ["IDLE"]: "idle",
16974
+ ["MOVING"]: "moving"
16975
+ };
16976
+
16925
16977
  //#endregion
16926
16978
  //#region src/nodes/node.ts
16927
16979
  const augmentKonvaStageClass = () => {
@@ -16934,6 +16986,9 @@ const augmentKonvaNodeClass = (config) => {
16934
16986
  konva.default.Node.prototype.getTransformerProperties = function() {
16935
16987
  return { ...transform };
16936
16988
  };
16989
+ konva.default.Node.prototype.getExportClientRect = function(config$1) {
16990
+ return this.getClientRect(config$1);
16991
+ };
16937
16992
  konva.default.Node.prototype.getRealClientRect = function(config$1) {
16938
16993
  return this.getClientRect(config$1);
16939
16994
  };
@@ -16962,7 +17017,7 @@ var WeaveNode = class {
16962
17017
  return selectionPlugin;
16963
17018
  }
16964
17019
  isSelecting() {
16965
- return this.instance.getActiveAction() === "selectionTool";
17020
+ return this.instance.getActiveAction() === SELECTION_TOOL_ACTION_NAME;
16966
17021
  }
16967
17022
  isPasting() {
16968
17023
  const copyPastePlugin = this.instance.getPlugin("copyPasteNodes");
@@ -17098,7 +17153,7 @@ var WeaveNode = class {
17098
17153
  }
17099
17154
  if (this.isSelecting() && this.isNodeSelected(node) && this.getSelectionPlugin()?.getSelectedNodes().length === 1) {
17100
17155
  clearContainerTargets(this.instance);
17101
- const layerToMove = containerOverCursor(this.instance);
17156
+ const layerToMove = containerOverCursor(this.instance, [node]);
17102
17157
  if (layerToMove && !hasFrames(node)) layerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
17103
17158
  }
17104
17159
  };
@@ -17115,24 +17170,26 @@ var WeaveNode = class {
17115
17170
  clearContainerTargets(this.instance);
17116
17171
  const nodesSnappingPlugin = this.instance.getPlugin("nodesSnapping");
17117
17172
  if (nodesSnappingPlugin) nodesSnappingPlugin.cleanupEvaluateGuidelines();
17118
- const layerToMove = containerOverCursor(this.instance);
17173
+ const layerToMove = containerOverCursor(this.instance, [node]);
17119
17174
  let containerToMove = this.instance.getMainLayer();
17120
17175
  if (layerToMove) {
17121
17176
  containerToMove = layerToMove;
17122
17177
  containerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
17123
17178
  }
17124
17179
  let moved = false;
17125
- if (containerToMove) moved = moveNodeToContainer(this.instance, e.target, containerToMove);
17180
+ if (containerToMove && !hasFrames(node)) moved = moveNodeToContainer(this.instance, e.target, containerToMove);
17126
17181
  if (!moved) this.instance.updateNode(this.serialize(node));
17127
17182
  }
17128
17183
  });
17129
17184
  node.on("pointerover", (e) => {
17130
17185
  e.cancelBubble = true;
17131
17186
  const stage = this.instance.getStage();
17187
+ const activeAction = this.instance.getActiveAction();
17132
17188
  const isNodeSelectionEnabled = this.getSelectionPlugin()?.isEnabled();
17133
17189
  const realNode = this.instance.getInstanceRecursive(node);
17134
17190
  const isTargetable = e.target.getAttrs().isTargetable !== false;
17135
17191
  const isLocked$1 = realNode.getAttrs().locked ?? false;
17192
+ if ([MOVE_TOOL_ACTION_NAME].includes(activeAction ?? "")) return;
17136
17193
  if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isLocked$1) {
17137
17194
  const stage$1 = this.instance.getStage();
17138
17195
  stage$1.container().style.cursor = "default";
@@ -18819,7 +18876,7 @@ var WeaveRegisterManager = class {
18819
18876
 
18820
18877
  //#endregion
18821
18878
  //#region package.json
18822
- var version = "0.47.0";
18879
+ var version = "0.48.0";
18823
18880
 
18824
18881
  //#endregion
18825
18882
  //#region src/managers/setup.ts
@@ -18942,7 +18999,8 @@ var WeaveActionsManager = class {
18942
18999
  }
18943
19000
  triggerAction(actionName, params) {
18944
19001
  const actionsHandlers = this.instance.getActionsHandlers();
18945
- if (!actionsHandlers[actionName]) return;
19002
+ if (typeof actionName === "undefined") throw new Error("Action name is required");
19003
+ if (actionName && !actionsHandlers[actionName]) throw new Error(`Action handler with name [${actionName}] not registered`);
18946
19004
  if (typeof this.activeAction !== "undefined") this.cancelAction(this.activeAction);
18947
19005
  this.activeAction = actionName;
18948
19006
  const payload = actionsHandlers[actionName].trigger(this.cancelActionCallback(actionName), params);
@@ -19032,17 +19090,20 @@ var WeaveExportManager = class {
19032
19090
  const { format: format$2 = __inditextech_weave_types.WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = __inditextech_weave_types.WEAVE_EXPORT_BACKGROUND_COLOR } = options;
19033
19091
  const stage = this.instance.getStage();
19034
19092
  const mainLayer = this.instance.getMainLayer();
19035
- const originalScale = stage.scale();
19093
+ const originalPosition = {
19094
+ x: stage.x(),
19095
+ y: stage.y()
19096
+ };
19097
+ const originalScale = {
19098
+ x: stage.scaleX(),
19099
+ y: stage.scaleY()
19100
+ };
19036
19101
  stage.scale({
19037
19102
  x: 1,
19038
19103
  y: 1
19039
19104
  });
19040
- const realNodes = nodes.map((node) => {
19041
- if (node.getAttrs().nodeId) return stage.findOne(`#${node.getAttrs().nodeId}`);
19042
- return node;
19043
- }).filter((node) => typeof node !== "undefined");
19044
19105
  if (mainLayer) {
19045
- const bounds = getBoundingBox(stage, boundingNodes(realNodes));
19106
+ const bounds = getExportBoundingBox(stage, boundingNodes(nodes));
19046
19107
  const scaleX = stage.scaleX();
19047
19108
  const scaleY = stage.scaleY();
19048
19109
  const unscaledBounds = {
@@ -19061,7 +19122,7 @@ var WeaveExportManager = class {
19061
19122
  fill: backgroundColor
19062
19123
  });
19063
19124
  exportGroup.add(background);
19064
- for (const node of realNodes) {
19125
+ for (const node of nodes) {
19065
19126
  const clonedNode = node.clone({ id: v4_default() });
19066
19127
  const absPos = node.getAbsolutePosition();
19067
19128
  clonedNode.absolutePosition({
@@ -19082,7 +19143,9 @@ var WeaveExportManager = class {
19082
19143
  quality: options.quality ?? 1,
19083
19144
  callback: (img) => {
19084
19145
  exportGroup.destroy();
19146
+ stage.position(originalPosition);
19085
19147
  stage.scale(originalScale);
19148
+ stage.batchDraw();
19086
19149
  resolve(img);
19087
19150
  }
19088
19151
  });
@@ -19582,29 +19645,35 @@ var WeaveStageNode = class extends WeaveNode {
19582
19645
  return this._allowSelection;
19583
19646
  };
19584
19647
  stage.mode(WEAVE_STAGE_DEFAULT_MODE);
19648
+ stage.on("pointerdown", (e) => {
19649
+ if (e.evt.button === 1) this.wheelMousePressed = true;
19650
+ if ([MOVE_TOOL_ACTION_NAME].includes(this.instance.getActiveAction() ?? "")) stage.container().style.cursor = "grabbing";
19651
+ });
19585
19652
  stage.on("pointermove", (e) => {
19586
- if (stage.allowSelection() && !stage.allowActions().includes(this.instance.getActiveAction() ?? "") && !stage.allowSelectNodes().includes(e.target.getAttrs()?.nodeType ?? "")) {
19653
+ const activeAction = this.instance.getActiveAction();
19654
+ if (![MOVE_TOOL_ACTION_NAME].includes(activeAction ?? "") && stage.allowSelection() && !stage.allowActions().includes(this.instance.getActiveAction() ?? "") && !stage.allowSelectNodes().includes(e.target.getAttrs()?.nodeType ?? "")) {
19587
19655
  const stage$1 = this.instance.getStage();
19588
19656
  stage$1.container().style.cursor = "default";
19589
19657
  }
19590
- if (e.target === stage && this.instance.getActiveAction() === "selectionTool") {
19658
+ if (e.target === stage && [SELECTION_TOOL_ACTION_NAME].includes(activeAction ?? "")) {
19591
19659
  const stage$1 = this.instance.getStage();
19592
19660
  stage$1.container().style.cursor = "default";
19593
19661
  }
19594
19662
  });
19663
+ stage.on("pointerup", (e) => {
19664
+ const activeAction = this.instance.getActiveAction();
19665
+ if (e.evt.button === 1) this.wheelMousePressed = false;
19666
+ if ([MOVE_TOOL_ACTION_NAME].includes(activeAction ?? "")) stage.container().style.cursor = "grab";
19667
+ });
19595
19668
  stage.on("pointerover", (e) => {
19669
+ const activeAction = this.instance.getActiveAction();
19670
+ if ([MOVE_TOOL_ACTION_NAME].includes(activeAction ?? "")) return;
19596
19671
  if (e.target !== stage && !e.target.getAttrs().nodeId) return;
19597
19672
  const parent = e.target.getParent();
19598
19673
  if (parent && parent instanceof konva.default.Transformer) return;
19599
19674
  this.hideHoverState();
19600
19675
  stage.container().style.cursor = "default";
19601
19676
  });
19602
- stage.on("pointerdown", (e) => {
19603
- if (e.evt.button === 1) this.wheelMousePressed = true;
19604
- });
19605
- stage.on("pointerup", (e) => {
19606
- if (e.evt.button === 1) this.wheelMousePressed = false;
19607
- });
19608
19677
  return stage;
19609
19678
  }
19610
19679
  onUpdate() {}
@@ -19903,14 +19972,6 @@ var WeaveLineNode = class extends WeaveNode {
19903
19972
  //#region src/nodes/text/constants.ts
19904
19973
  const WEAVE_TEXT_NODE_TYPE = "text";
19905
19974
 
19906
- //#endregion
19907
- //#region src/actions/selection-tool/constants.ts
19908
- const SELECTION_TOOL_ACTION_NAME = "selectionTool";
19909
- const SELECTION_TOOL_STATE = {
19910
- ["IDLE"]: "idle",
19911
- ["SELECTING"]: "selection"
19912
- };
19913
-
19914
19975
  //#endregion
19915
19976
  //#region src/actions/text-tool/constants.ts
19916
19977
  const TEXT_TOOL_ACTION_NAME = "textTool";
@@ -20355,7 +20416,7 @@ var WeaveTextNode = class extends WeaveNode {
20355
20416
  tr.nodes([textNode]);
20356
20417
  tr.show();
20357
20418
  }
20358
- this.instance.triggerAction("selectionTool");
20419
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
20359
20420
  }
20360
20421
  stage.container().tabIndex = 1;
20361
20422
  stage.container().click();
@@ -20434,7 +20495,7 @@ var WeaveImageToolAction = class extends WeaveAction {
20434
20495
  if (window.weaveDragImageURL) {
20435
20496
  this.instance.getStage().setPointersPositions(e);
20436
20497
  const position = this.instance.getStage().getRelativePointerPosition();
20437
- this.instance.triggerAction("imageTool", {
20498
+ this.instance.triggerAction(IMAGE_TOOL_ACTION_NAME, {
20438
20499
  imageURL: window.weaveDragImageURL,
20439
20500
  position
20440
20501
  });
@@ -20610,7 +20671,7 @@ var WeaveImageToolAction = class extends WeaveAction {
20610
20671
  if (selectionPlugin) {
20611
20672
  const node = stage.findOne(`#${this.imageId}`);
20612
20673
  if (node) selectionPlugin.setSelectedNodes([node]);
20613
- this.instance.triggerAction("selectionTool");
20674
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
20614
20675
  }
20615
20676
  stage.container().style.cursor = "default";
20616
20677
  this.initialCursor = null;
@@ -21322,7 +21383,7 @@ var WeaveImageNode = class extends WeaveNode {
21322
21383
  }
21323
21384
  }
21324
21385
  getImageToolAction() {
21325
- const imageToolAction = this.instance.getActionHandler("imageTool");
21386
+ const imageToolAction = this.instance.getActionHandler(IMAGE_TOOL_ACTION_NAME);
21326
21387
  if (!imageToolAction) throw new Error("Image Tool action not found");
21327
21388
  return imageToolAction;
21328
21389
  }
@@ -21683,7 +21744,7 @@ var WeaveFrameNode = class extends WeaveNode {
21683
21744
  const text = new konva.default.Text({
21684
21745
  id: `${id}-title`,
21685
21746
  x: 0,
21686
- width: props.frameWidth / stage.scaleX(),
21747
+ width: props.frameWidth,
21687
21748
  fontSize: fontSize / stage.scaleX(),
21688
21749
  fontFamily,
21689
21750
  fontStyle,
@@ -21759,6 +21820,16 @@ var WeaveFrameNode = class extends WeaveNode {
21759
21820
  listening: false,
21760
21821
  draggable: false
21761
21822
  });
21823
+ frame.getExportClientRect = (config) => {
21824
+ const textBox = text.getClientRect(config);
21825
+ const containerAreaBox = containerArea.getClientRect(config);
21826
+ return {
21827
+ x: textBox.x,
21828
+ y: textBox.y,
21829
+ width: containerAreaBox.width,
21830
+ height: containerAreaBox.height + textBox.height
21831
+ };
21832
+ };
21762
21833
  frame.getClientRect = (config) => {
21763
21834
  return containerArea.getClientRect(config);
21764
21835
  };
@@ -21777,7 +21848,7 @@ var WeaveFrameNode = class extends WeaveNode {
21777
21848
  this.instance.addEventListener("onZoomChange", () => {
21778
21849
  const stage$1 = this.instance.getStage();
21779
21850
  text.fontSize(fontSize / stage$1.scaleX());
21780
- text.width(props.frameWidth / stage$1.scaleX());
21851
+ text.width(props.frameWidth);
21781
21852
  const textMeasures$1 = text.measureSize(text.getAttrs().text ?? "");
21782
21853
  const textHeight$1 = textMeasures$1.height + 2 * titleMargin / stage$1.scaleX();
21783
21854
  text.y(-textHeight$1);
@@ -22177,13 +22248,22 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22177
22248
  }
22178
22249
  fitToScreen() {
22179
22250
  if (!this.enabled) return;
22251
+ const stage = this.instance.getStage();
22180
22252
  const mainLayer = this.instance.getMainLayer();
22181
22253
  if (!mainLayer) return;
22254
+ const container = stage.container();
22255
+ const rect = container.getBoundingClientRect();
22256
+ const containerWidth = rect.width;
22257
+ const containerHeight = rect.height;
22258
+ const centerPoint = {
22259
+ x: containerWidth / 2,
22260
+ y: containerHeight / 2
22261
+ };
22182
22262
  if (mainLayer?.getChildren().length === 0) {
22263
+ stage.position(centerPoint);
22183
22264
  this.setZoom(this.config.zoomSteps[this.defaultStep]);
22184
22265
  return;
22185
22266
  }
22186
- const stage = this.instance.getStage();
22187
22267
  stage.scale({
22188
22268
  x: 1,
22189
22269
  y: 1
@@ -22195,6 +22275,11 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22195
22275
  let realNodes = mainLayer.getChildren();
22196
22276
  realNodes = realNodes.filter((node) => typeof node.getAttrs().visible === "undefined" || node.getAttrs().visible);
22197
22277
  const bounds = getBoundingBox(stage, realNodes);
22278
+ if (bounds.width === 0 || bounds.height === 0) {
22279
+ stage.position(centerPoint);
22280
+ this.setZoom(this.config.zoomSteps[this.defaultStep]);
22281
+ return;
22282
+ }
22198
22283
  const stageWidth = stage.width();
22199
22284
  const stageHeight = stage.height();
22200
22285
  const scaleX = (stageWidth - this.config.fitToScreen.padding * 2) / bounds.width;
@@ -22219,30 +22304,13 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22219
22304
  if (!selectionPlugin) return;
22220
22305
  const nodes = selectionPlugin.getTransformer().getNodes();
22221
22306
  if (nodes.length === 0) return;
22222
- let zoomTransformer = stage.findOne("#zoomTransformer");
22223
- if (!zoomTransformer) {
22224
- zoomTransformer = new konva.default.Transformer({
22225
- id: "zoomTransformer",
22226
- clearBeforeDraw: true,
22227
- resizeEnabled: false,
22228
- ignoreStroke: true,
22229
- rotateEnabled: false,
22230
- enabledAnchors: [],
22231
- shouldOverdrawWholeArea: true,
22232
- scaleX: stage.scaleX(),
22233
- scaleY: stage.scaleY()
22234
- });
22235
- const mainLayer = this.instance.getMainLayer();
22236
- mainLayer?.add(zoomTransformer);
22237
- }
22238
22307
  this.setZoom(1, false);
22239
22308
  stage.setAttrs({
22240
22309
  x: 0,
22241
22310
  y: 0
22242
22311
  });
22243
- zoomTransformer.setNodes(selectionPlugin.getTransformer().getNodes());
22244
- zoomTransformer.forceUpdate();
22245
- const box = zoomTransformer.__getNodeRect();
22312
+ const box = getBoundingBox(stage, selectionPlugin.getTransformer().getNodes());
22313
+ if (box.width === 0 || box.height === 0) return;
22246
22314
  const stageBox = {
22247
22315
  width: stage.width(),
22248
22316
  height: stage.height()
@@ -22267,7 +22335,6 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22267
22335
  y: stageY
22268
22336
  });
22269
22337
  this.setZoom(scale, false);
22270
- zoomTransformer.destroy();
22271
22338
  }
22272
22339
  enable() {
22273
22340
  this.enabled = true;
@@ -22555,19 +22622,11 @@ var WeaveFitToSelectionToolAction = class extends WeaveAction {
22555
22622
  }
22556
22623
  cleanup() {
22557
22624
  const stage = this.instance.getStage();
22558
- this.instance.triggerAction(this.previousAction);
22625
+ if (this.previousAction) this.instance.triggerAction(this.previousAction);
22559
22626
  stage.container().style.cursor = "default";
22560
22627
  }
22561
22628
  };
22562
22629
 
22563
- //#endregion
22564
- //#region src/actions/move-tool/constants.ts
22565
- const MOVE_TOOL_ACTION_NAME = "moveTool";
22566
- const MOVE_TOOL_STATE = {
22567
- ["IDLE"]: "idle",
22568
- ["MOVING"]: "moving"
22569
- };
22570
-
22571
22630
  //#endregion
22572
22631
  //#region src/actions/move-tool/move-tool.ts
22573
22632
  var WeaveMoveToolAction = class extends WeaveAction {
@@ -22590,6 +22649,12 @@ var WeaveMoveToolAction = class extends WeaveAction {
22590
22649
  return;
22591
22650
  }
22592
22651
  });
22652
+ stage.on("pointerdown", () => {
22653
+ if ([MOVE_TOOL_ACTION_NAME].includes(this.instance.getActiveAction() ?? "")) stage.container().style.cursor = "grabbing";
22654
+ });
22655
+ stage.on("pointerup", () => {
22656
+ if ([MOVE_TOOL_ACTION_NAME].includes(this.instance.getActiveAction() ?? "")) stage.container().style.cursor = "grab";
22657
+ });
22593
22658
  this.initialized = true;
22594
22659
  }
22595
22660
  setState(state) {
@@ -22600,6 +22665,14 @@ var WeaveMoveToolAction = class extends WeaveAction {
22600
22665
  stage.container().style.cursor = "grab";
22601
22666
  stage.container().focus();
22602
22667
  this.setState(MOVE_TOOL_STATE.MOVING);
22668
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
22669
+ if (selectionPlugin && !selectionPlugin.isEnabled()) {
22670
+ const tr = selectionPlugin.getTransformer();
22671
+ this.instance.enablePlugin("nodesSelection");
22672
+ tr.listening(false);
22673
+ tr.draggable(false);
22674
+ tr.show();
22675
+ }
22603
22676
  }
22604
22677
  trigger(cancelAction, params) {
22605
22678
  if (!this.instance) throw new Error("Instance not defined");
@@ -22616,6 +22689,11 @@ var WeaveMoveToolAction = class extends WeaveAction {
22616
22689
  const stage = this.instance.getStage();
22617
22690
  stage.container().style.cursor = "default";
22618
22691
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
22692
+ if (selectionPlugin) {
22693
+ const tr = selectionPlugin.getTransformer();
22694
+ tr.listening(true);
22695
+ tr.draggable(true);
22696
+ }
22619
22697
  if (selectionPlugin && this.triggerSelectionTool) this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
22620
22698
  this.setState(MOVE_TOOL_STATE.IDLE);
22621
22699
  }
@@ -23386,7 +23464,7 @@ var WeavePenToolAction = class extends WeaveAction {
23386
23464
  if (selectionPlugin) {
23387
23465
  const node = stage.findOne(`#${this.lineId}`);
23388
23466
  if (node) selectionPlugin.setSelectedNodes([node]);
23389
- this.instance.triggerAction("selectionTool");
23467
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
23390
23468
  }
23391
23469
  stage.container().style.cursor = "default";
23392
23470
  this.initialCursor = null;
@@ -23466,6 +23544,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
23466
23544
  stage.on("pointerdown touchstart", handlePointerDown);
23467
23545
  const handlePointerMove = (e) => {
23468
23546
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
23547
+ stage.container().style.cursor = "crosshair";
23469
23548
  const pointPressure = this.getPointPressure(e);
23470
23549
  this.handleMovement(pointPressure);
23471
23550
  e.evt.stopPropagation();
@@ -23579,9 +23658,10 @@ var WeaveBrushToolAction = class extends WeaveAction {
23579
23658
  });
23580
23659
  const realNode = this.instance.getStage().findOne(`#${tempStroke.getAttrs().id}`);
23581
23660
  if (realNode) realNode.destroy();
23582
- this.instance.addNode(nodeHandler.serialize(tempStroke), this.container?.getAttrs().id);
23661
+ if (tempStroke.getAttrs().strokeElements.length >= 3) this.instance.addNode(nodeHandler.serialize(tempStroke), this.container?.getAttrs().id);
23583
23662
  }
23584
23663
  this.clickPoint = null;
23664
+ stage.container().style.cursor = "crosshair";
23585
23665
  stage.container().tabIndex = 1;
23586
23666
  stage.container().focus();
23587
23667
  this.setState(BRUSH_TOOL_STATE.IDLE);
@@ -23613,7 +23693,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
23613
23693
  if (selectionPlugin) {
23614
23694
  const node = stage.findOne(`#${this.strokeId}`);
23615
23695
  if (node) selectionPlugin.setSelectedNodes([node]);
23616
- this.instance.triggerAction("selectionTool");
23696
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
23617
23697
  }
23618
23698
  this.clickPoint = null;
23619
23699
  this.setState(BRUSH_TOOL_STATE.INACTIVE);
@@ -24169,7 +24249,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
24169
24249
  if (selectionPlugin) {
24170
24250
  const node = stage.findOne(`#${this.arrowId}`);
24171
24251
  if (node) selectionPlugin.setSelectedNodes([node]);
24172
- this.instance.triggerAction("selectionTool");
24252
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
24173
24253
  }
24174
24254
  stage.container().style.cursor = "default";
24175
24255
  this.initialCursor = null;
@@ -24487,7 +24567,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
24487
24567
  if (selectionPlugin) {
24488
24568
  const node = stage.findOne(`#${this.frameId}-selector-area`);
24489
24569
  if (node) selectionPlugin.setSelectedNodes([node]);
24490
- this.instance.triggerAction("selectionTool");
24570
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
24491
24571
  }
24492
24572
  this.frameId = null;
24493
24573
  this.container = void 0;
@@ -24517,12 +24597,13 @@ var WeaveExportStageToolAction = class extends WeaveAction {
24517
24597
  }
24518
24598
  async exportStage(boundingNodes) {
24519
24599
  const mainLayer = this.instance.getMainLayer();
24520
- const img = await this.instance.exportNodes(mainLayer?.getChildren() ?? [], boundingNodes, this.options);
24521
- const link = document.createElement("a");
24522
- link.href = img.src;
24523
- link.download = `${v4_default()}${__inditextech_weave_types.WEAVE_EXPORT_FILE_FORMAT[this.options.format ?? __inditextech_weave_types.WEAVE_EXPORT_FORMATS.PNG]}`;
24524
- link.click();
24525
- this.cancelAction?.();
24600
+ const img = await this.instance.exportNodes(
24601
+ // mainLayer?.find('.node') ?? [],
24602
+ mainLayer?.getChildren() ?? [],
24603
+ boundingNodes,
24604
+ this.options
24605
+ );
24606
+ return img;
24526
24607
  }
24527
24608
  async trigger(cancelAction, { boundingNodes, options }) {
24528
24609
  if (!this.instance) throw new Error("Instance not defined");
@@ -24534,14 +24615,16 @@ var WeaveExportStageToolAction = class extends WeaveAction {
24534
24615
  ...this.defaultFormatOptions,
24535
24616
  ...options
24536
24617
  };
24537
- await this.exportStage(boundingNodes ?? ((nodes) => nodes));
24618
+ const img = await this.exportStage(boundingNodes ?? ((nodes) => nodes));
24619
+ this.cancelAction?.();
24620
+ return img;
24538
24621
  }
24539
24622
  cleanup() {
24540
24623
  const stage = this.instance.getStage();
24541
24624
  stage.container().tabIndex = 0;
24542
24625
  stage.container().click();
24543
24626
  stage.container().focus();
24544
- this.instance.triggerAction("selectionTool");
24627
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
24545
24628
  }
24546
24629
  };
24547
24630
 
@@ -24566,13 +24649,9 @@ var WeaveExportNodesToolAction = class extends WeaveAction {
24566
24649
  }
24567
24650
  async exportNodes(nodes, boundingNodes) {
24568
24651
  const img = await this.instance.exportNodes(nodes, boundingNodes ?? ((nodes$1) => nodes$1), this.options);
24569
- const link = document.createElement("a");
24570
- link.href = img.src;
24571
- link.download = `${v4_default()}${__inditextech_weave_types.WEAVE_EXPORT_FILE_FORMAT[this.options.format ?? __inditextech_weave_types.WEAVE_EXPORT_FORMATS.PNG]}`;
24572
- link.click();
24573
- this.cancelAction?.();
24652
+ return img;
24574
24653
  }
24575
- async trigger(cancelAction, { nodes, boundingNodes, options, triggerSelectionTool = true, download = true }) {
24654
+ async trigger(cancelAction, { nodes, boundingNodes, options, triggerSelectionTool = true }) {
24576
24655
  if (!this.instance) throw new Error("Instance not defined");
24577
24656
  const stage = this.instance.getStage();
24578
24657
  stage.container().tabIndex = 1;
@@ -24583,20 +24662,16 @@ var WeaveExportNodesToolAction = class extends WeaveAction {
24583
24662
  ...this.defaultFormatOptions,
24584
24663
  ...options
24585
24664
  };
24586
- if (!download) {
24587
- const img = await this.instance.exportNodes(nodes, boundingNodes ?? ((nodes$1) => nodes$1), this.options);
24588
- const base64URL = this.instance.imageToBase64(img, this.options.format ?? "image/png");
24589
- this.cancelAction?.();
24590
- return base64URL;
24591
- }
24592
- await this.exportNodes(nodes, boundingNodes ?? ((nodes$1) => nodes$1));
24665
+ const img = await this.exportNodes(nodes, boundingNodes ?? ((nodes$1) => nodes$1));
24666
+ this.cancelAction?.();
24667
+ return img;
24593
24668
  }
24594
24669
  cleanup() {
24595
24670
  const stage = this.instance.getStage();
24596
24671
  stage.container().tabIndex = 0;
24597
24672
  stage.container().click();
24598
24673
  stage.container().focus();
24599
- if (this.triggerSelectionTool) this.instance.triggerAction("selectionTool");
24674
+ if (this.triggerSelectionTool) this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
24600
24675
  }
24601
24676
  };
24602
24677
 
@@ -24841,7 +24916,7 @@ var WeaveAlignNodesToolAction = class extends WeaveAction {
24841
24916
  this.alignNodes(alignTo);
24842
24917
  }
24843
24918
  cleanup() {
24844
- if (this.triggerSelectionTool) this.instance.triggerAction("selectionTool");
24919
+ if (this.triggerSelectionTool) this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
24845
24920
  this.setState(ALIGN_NODES_TOOL_STATE.IDLE);
24846
24921
  }
24847
24922
  };
@@ -24912,12 +24987,12 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
24912
24987
  });
24913
24988
  stage.on("pointerdown", (e) => {
24914
24989
  const activeAction = this.instance.getActiveAction();
24915
- if (e && e.evt.button === 0 && activeAction === "moveTool") this.moveToolActive = true;
24990
+ if (e && e.evt.button === 0 && activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = true;
24916
24991
  if (e && (e.evt.button === 2 || e.evt.buttons === 4)) this.isMouseMiddleButtonPressed = true;
24917
24992
  });
24918
24993
  stage.on("pointerup", (e) => {
24919
24994
  const activeAction = this.instance.getActiveAction();
24920
- if (e && e.evt.button === 0 && activeAction === "moveTool") this.moveToolActive = false;
24995
+ if (e && e.evt.button === 0 && activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = false;
24921
24996
  if (e && (e.evt.button === 1 || e.evt.buttons === 0)) this.isMouseMiddleButtonPressed = false;
24922
24997
  });
24923
24998
  const handleMouseMove = () => {
@@ -25192,7 +25267,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25192
25267
  if (this.pointers.size > 1) return;
25193
25268
  const activeAction = this.instance.getActiveAction();
25194
25269
  let enableMove = false;
25195
- if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 1) && activeAction === "moveTool") {
25270
+ if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 1) && activeAction === MOVE_TOOL_ACTION_NAME) {
25196
25271
  this.moveToolActive = true;
25197
25272
  enableMove = true;
25198
25273
  }
@@ -25241,10 +25316,8 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25241
25316
  const performPanning = !this.isCtrlOrMetaPressed && !e.evt.ctrlKey;
25242
25317
  if (!this.enabled || !stage$1.isFocused() || this.isCtrlOrMetaPressed || e.evt.buttons === 4 || !performPanning) return;
25243
25318
  this.getContextMenuPlugin()?.cancelLongPressTimer();
25244
- this.getNodesSelectionPlugin()?.disable();
25245
25319
  stage$1.x(stage$1.x() - e.evt.deltaX);
25246
25320
  stage$1.y(stage$1.y() - e.evt.deltaY);
25247
- this.getNodesSelectionPlugin()?.enable();
25248
25321
  this.instance.emitEvent("onStageMove");
25249
25322
  };
25250
25323
  stage.on("wheel", handleWheel);
@@ -25272,10 +25345,6 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25272
25345
  y: (p1.y + p2.y) / 2
25273
25346
  };
25274
25347
  }
25275
- getNodesSelectionPlugin() {
25276
- const selectionPlugin = this.instance.getPlugin("nodesSelection");
25277
- return selectionPlugin;
25278
- }
25279
25348
  getZoomPlugin() {
25280
25349
  const zoomPlugin = this.instance.getPlugin("stageZoom");
25281
25350
  return zoomPlugin;
@@ -26275,12 +26344,15 @@ exports.WeaveZoomInToolAction = WeaveZoomInToolAction
26275
26344
  exports.WeaveZoomOutToolAction = WeaveZoomOutToolAction
26276
26345
  exports.clearContainerTargets = clearContainerTargets
26277
26346
  exports.containerOverCursor = containerOverCursor
26347
+ exports.containsNodeDeep = containsNodeDeep
26278
26348
  exports.getBoundingBox = getBoundingBox
26279
26349
  exports.getContrastTextColor = getContrastTextColor
26350
+ exports.getExportBoundingBox = getExportBoundingBox
26280
26351
  exports.getTargetedNode = getTargetedNode
26281
26352
  exports.hasFrames = hasFrames
26282
26353
  exports.hasImages = hasImages
26283
26354
  exports.intersectArrays = intersectArrays
26355
+ exports.isNodeInSelection = isNodeInSelection
26284
26356
  exports.moveNodeToContainer = moveNodeToContainer
26285
26357
  exports.resetScale = resetScale
26286
26358
  exports.stringToColor = stringToColor