@inditextech/weave-sdk 0.52.2 → 0.53.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
@@ -15913,6 +15913,39 @@ function getClosestParentWithId(el) {
15913
15913
  }
15914
15914
  return null;
15915
15915
  }
15916
+ function isInShadowDOM(el) {
15917
+ return el?.getRootNode() instanceof ShadowRoot;
15918
+ }
15919
+ function getTopmostShadowHost(el) {
15920
+ let current = el;
15921
+ let root = current?.getRootNode();
15922
+ while (root instanceof ShadowRoot) {
15923
+ current = root.host;
15924
+ root = current.getRootNode();
15925
+ }
15926
+ return current?.shadowRoot || null;
15927
+ }
15928
+ function getVisibleNodes(instance, stage, nodeParent, skipNodes, referenceLayer) {
15929
+ const nodesSelection = instance.getPlugin("nodesSelection");
15930
+ if (nodesSelection) nodesSelection.getTransformer().hide();
15931
+ const nodes = getVisibleNodesInViewport(stage, referenceLayer);
15932
+ const finalVisibleNodes = [];
15933
+ nodes.forEach((node) => {
15934
+ const actualNodeParent = instance.getNodeContainer(node);
15935
+ if (actualNodeParent?.getAttrs().id !== nodeParent?.getAttrs().id) return;
15936
+ if (node.getParent()?.getAttrs().nodeType === "group") return;
15937
+ if (skipNodes.includes(node.getParent()?.getAttrs().nodeId)) return;
15938
+ if (skipNodes.includes(node.getAttrs().id ?? "")) return;
15939
+ if (node.getParent() !== referenceLayer && !node.getParent()?.getAttrs().nodeId) return;
15940
+ if (node.getParent() !== referenceLayer && node.getParent()?.getAttrs().nodeId) {
15941
+ const realNode = stage.findOne(`#${node.getParent()?.getAttrs().nodeId}`);
15942
+ if (realNode && realNode !== referenceLayer) return;
15943
+ }
15944
+ finalVisibleNodes.push(node);
15945
+ });
15946
+ if (nodesSelection) nodesSelection.getTransformer().show();
15947
+ return finalVisibleNodes;
15948
+ }
15916
15949
 
15917
15950
  //#endregion
15918
15951
  //#region src/actions/selection-tool/constants.ts
@@ -16148,6 +16181,22 @@ const NODE_SNAP = {
16148
16181
  const WEAVE_NODES_DISTANCE_SNAPPING_PLUGIN_KEY = "nodesDistanceSnapping";
16149
16182
  const GUIDE_HORIZONTAL_LINE_NAME = "guide-distance-snapping-horizontal-line";
16150
16183
  const GUIDE_VERTICAL_LINE_NAME = "guide-distance-snapping-vertical-line";
16184
+ const GUIDE_DISTANCE_LINE_DEFAULT_CONFIG = {
16185
+ line: {
16186
+ stroke: "#E12D3C",
16187
+ strokeWidth: 1
16188
+ },
16189
+ label: {
16190
+ linePadding: 10,
16191
+ height: 20,
16192
+ cornerRadius: 0,
16193
+ fill: "#E12D3C",
16194
+ fontStyle: "normal",
16195
+ fontSize: 14,
16196
+ fontFamily: "Arial",
16197
+ paddingX: 4
16198
+ }
16199
+ };
16151
16200
  const GUIDE_ENTER_SNAPPING_TOLERANCE = 3;
16152
16201
  const GUIDE_EXIT_SNAPPING_TOLERANCE = 5;
16153
16202
  const NODE_SNAP_HORIZONTAL = {
@@ -16981,14 +17030,23 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
16981
17030
  if (stageContainer?.parentNode) stageContainer.parentNode.appendChild(catcher);
16982
17031
  }
16983
17032
  }
17033
+ getCatcherElement() {
17034
+ const stage = this.instance.getStage();
17035
+ let catcher = document.getElementById(WEAVE_COPY_PASTE_PASTE_CATCHER_ID);
17036
+ if (isInShadowDOM(stage.container())) {
17037
+ const shadowHost = getTopmostShadowHost(stage.container());
17038
+ if (shadowHost) catcher = shadowHost.querySelector(`#${WEAVE_COPY_PASTE_PASTE_CATCHER_ID}`);
17039
+ }
17040
+ return catcher;
17041
+ }
16984
17042
  focusPasteCatcher() {
16985
- const catcher = document.getElementById(WEAVE_COPY_PASTE_PASTE_CATCHER_ID);
17043
+ const catcher = this.getCatcherElement();
16986
17044
  catcher?.focus();
16987
17045
  }
16988
17046
  initEvents() {
16989
17047
  const stage = this.instance.getStage();
16990
17048
  this.createPasteCatcher();
16991
- const catcher = document.getElementById(WEAVE_COPY_PASTE_PASTE_CATCHER_ID);
17049
+ const catcher = this.getCatcherElement();
16992
17050
  window.addEventListener("keydown", async (e) => {
16993
17051
  if (stage.isFocused() && e.key === "c" && (e.ctrlKey || e.metaKey)) {
16994
17052
  e.preventDefault();
@@ -17113,9 +17171,11 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
17113
17171
  this.instance.addNode(node, containerId);
17114
17172
  const realNode = this.instance.getStage().findOne(`#${newNodeId}`);
17115
17173
  if (realNode) nodesToSelect.push(realNode);
17116
- this.instance.emitEvent("onPaste");
17117
17174
  }
17118
- this.instance.emitEvent("onPaste", void 0);
17175
+ this.instance.emitEvent("onPaste", {
17176
+ error: void 0,
17177
+ pastedNodes: nodesToSelect.map((n) => n.getAttrs().id ?? "")
17178
+ });
17119
17179
  const nodesSelectionPlugin = this.getNodesSelectionPlugin();
17120
17180
  nodesSelectionPlugin?.setSelectedNodes(nodesToSelect);
17121
17181
  this.toPaste = void 0;
@@ -17165,7 +17225,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
17165
17225
  await this.writeClipboardData(JSON.stringify(copyClipboard));
17166
17226
  this.instance.emitEvent("onCopy");
17167
17227
  } catch (ex) {
17168
- this.instance.emitEvent("onCopy", ex);
17228
+ this.instance.emitEvent("onCopy", { error: ex });
17169
17229
  }
17170
17230
  }
17171
17231
  async copy() {
@@ -17181,7 +17241,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
17181
17241
  return;
17182
17242
  }
17183
17243
  } catch (ex) {
17184
- this.instance.emitEvent("onPaste", ex);
17244
+ this.instance.emitEvent("onPaste", { error: ex });
17185
17245
  }
17186
17246
  try {
17187
17247
  const items = await navigator.clipboard.read();
@@ -17207,7 +17267,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
17207
17267
  items
17208
17268
  });
17209
17269
  } catch (ex) {
17210
- this.instance.emitEvent("onPaste", ex);
17270
+ this.instance.emitEvent("onPaste", { error: ex });
17211
17271
  }
17212
17272
  }
17213
17273
  getSelectedNodes() {
@@ -19169,7 +19229,7 @@ var WeaveRegisterManager = class {
19169
19229
 
19170
19230
  //#endregion
19171
19231
  //#region package.json
19172
- var version = "0.52.2";
19232
+ var version = "0.53.0";
19173
19233
 
19174
19234
  //#endregion
19175
19235
  //#region src/managers/setup.ts
@@ -19760,6 +19820,15 @@ var Weave = class {
19760
19820
  }
19761
19821
  return nodeContainer;
19762
19822
  }
19823
+ getNodeContainer(node) {
19824
+ const stage = this.getStage();
19825
+ let nodeContainer = node.getParent();
19826
+ if (typeof node.getParent()?.getAttrs().nodeId !== "undefined") {
19827
+ const realContainer = stage.findOne(`#${node.getParent()?.getAttrs().nodeId}`);
19828
+ if (realContainer) nodeContainer = realContainer;
19829
+ }
19830
+ return nodeContainer;
19831
+ }
19763
19832
  moveUp(node) {
19764
19833
  this.zIndexManager.moveUp(node);
19765
19834
  }
@@ -20631,7 +20700,7 @@ var WeaveTextNode = class extends WeaveNode {
20631
20700
  this.removeTextAreaDOM(textNode);
20632
20701
  this.instance.removeEventListener("onZoomChange", this.onZoomChangeHandler(textNode).bind(this));
20633
20702
  this.instance.removeEventListener("onStageMove", this.onStageMoveHandler(textNode).bind(this));
20634
- window.removeEventListener("pointerclick", handleOutsideClick);
20703
+ window.removeEventListener("pointerup", handleOutsideClick);
20635
20704
  return;
20636
20705
  }
20637
20706
  };
@@ -20655,20 +20724,27 @@ var WeaveTextNode = class extends WeaveNode {
20655
20724
  const handleOutsideClick = (e) => {
20656
20725
  e.stopPropagation();
20657
20726
  if (!this.textArea) return;
20727
+ const mouseX = e.clientX;
20728
+ const mouseY = e.clientY;
20729
+ let elementUnderMouse = document.elementFromPoint(mouseX, mouseY);
20730
+ if (isInShadowDOM(stage.container())) {
20731
+ const shadowHost = getTopmostShadowHost(stage.container());
20732
+ if (shadowHost) elementUnderMouse = shadowHost.elementFromPoint(mouseX, mouseY);
20733
+ }
20658
20734
  let clickedOnCanvas = false;
20659
- if (e.target?.id !== `${textNode.id()}`) clickedOnCanvas = true;
20735
+ if (elementUnderMouse?.id !== `${textNode.id()}`) clickedOnCanvas = true;
20660
20736
  if (clickedOnCanvas) {
20661
20737
  textNode.text(this.textArea.value);
20662
20738
  this.removeTextAreaDOM(textNode);
20663
20739
  this.textArea.removeEventListener("keydown", handleKeyDown);
20664
20740
  this.textArea.removeEventListener("keyup", handleKeyUp);
20665
- window.removeEventListener("pointerclick", handleOutsideClick);
20741
+ window.removeEventListener("pointerup", handleOutsideClick);
20666
20742
  window.removeEventListener("pointerdown", handleOutsideClick);
20667
20743
  return;
20668
20744
  }
20669
20745
  };
20670
20746
  setTimeout(() => {
20671
- window.addEventListener("pointerclick", handleOutsideClick);
20747
+ window.addEventListener("pointerup", handleOutsideClick);
20672
20748
  window.addEventListener("pointerdown", handleOutsideClick);
20673
20749
  }, 0);
20674
20750
  this.editing = true;
@@ -22779,8 +22855,13 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
22779
22855
  const performZoom = this.isCtrlOrMetaPressed || !this.isCtrlOrMetaPressed && e.ctrlKey && e.deltaMode === 0;
22780
22856
  const mouseX = e.clientX;
22781
22857
  const mouseY = e.clientY;
22782
- const elementUnderMouse = document.elementFromPoint(mouseX, mouseY);
22858
+ let elementUnderMouse = document.elementFromPoint(mouseX, mouseY);
22859
+ if (isInShadowDOM(stage.container())) {
22860
+ const shadowHost = getTopmostShadowHost(stage.container());
22861
+ if (shadowHost) elementUnderMouse = shadowHost.elementFromPoint(mouseX, mouseY);
22862
+ }
22783
22863
  if (!this.enabled || !performZoom || getClosestParentWithId(elementUnderMouse) !== stage.container()) return;
22864
+ e.preventDefault();
22784
22865
  const delta = e.deltaY > 0 ? 1 : -1;
22785
22866
  this.zoomVelocity += delta;
22786
22867
  this.isTrackpad = Math.abs(e.deltaY) < 15 && e.deltaMode === 0;
@@ -25563,8 +25644,11 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25563
25644
  super();
25564
25645
  this.pointers = new Map();
25565
25646
  this.panning = false;
25647
+ this.isDragging = false;
25648
+ this.enableMove = false;
25566
25649
  this.enabled = true;
25567
25650
  this.moveToolActive = false;
25651
+ this.isMouseLeftButtonPressed = false;
25568
25652
  this.isMouseMiddleButtonPressed = false;
25569
25653
  this.isCtrlOrMetaPressed = false;
25570
25654
  this.isSpaceKeyPressed = false;
@@ -25576,7 +25660,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25576
25660
  onInit() {
25577
25661
  this.initEvents();
25578
25662
  }
25579
- enableMove() {
25663
+ setCursor() {
25580
25664
  const stage = this.instance.getStage();
25581
25665
  if (stage.container().style.cursor !== "grabbing") {
25582
25666
  this.previousPointer = stage.container().style.cursor;
@@ -25600,7 +25684,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25600
25684
  this.getNodesEdgeSnappingPlugin()?.disable();
25601
25685
  this.getNodesDistanceSnappingPlugin()?.disable();
25602
25686
  this.isSpaceKeyPressed = true;
25603
- this.enableMove();
25687
+ this.setCursor();
25604
25688
  }
25605
25689
  });
25606
25690
  window.addEventListener("keyup", (e) => {
@@ -25615,7 +25699,6 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25615
25699
  }
25616
25700
  });
25617
25701
  let lastPos = null;
25618
- let isDragging = false;
25619
25702
  stage.on("pointerdown", (e) => {
25620
25703
  this.pointers.set(e.evt.pointerId, {
25621
25704
  x: e.evt.clientX,
@@ -25623,14 +25706,15 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25623
25706
  });
25624
25707
  if (this.pointers.size > 1) return;
25625
25708
  const activeAction = this.instance.getActiveAction();
25626
- let enableMove = false;
25627
- if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 1) && activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = true;
25628
- if (!enableMove && e.evt.pointerType === "mouse" && e.evt.buttons === 4) this.isMouseMiddleButtonPressed = true;
25629
- if (this.enabled && (this.isSpaceKeyPressed || this.moveToolActive || this.isMouseMiddleButtonPressed)) enableMove = true;
25630
- if (enableMove) {
25631
- isDragging = true;
25709
+ this.enableMove = false;
25710
+ if (activeAction === MOVE_TOOL_ACTION_NAME) this.moveToolActive = true;
25711
+ if (e.evt.pointerType === "mouse" && e.evt.buttons === 1) this.isMouseLeftButtonPressed = true;
25712
+ if (e.evt.pointerType === "mouse" && e.evt.buttons === 4) this.isMouseMiddleButtonPressed = true;
25713
+ if (this.enabled && (this.isSpaceKeyPressed || this.moveToolActive && this.isMouseLeftButtonPressed || this.isMouseMiddleButtonPressed)) this.enableMove = true;
25714
+ if (this.enableMove) {
25715
+ this.isDragging = true;
25632
25716
  lastPos = stage.getPointerPosition();
25633
- this.enableMove();
25717
+ this.setCursor();
25634
25718
  }
25635
25719
  });
25636
25720
  stage.on("pointercancel", (e) => {
@@ -25644,7 +25728,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25644
25728
  });
25645
25729
  if (this.pointers.size > 1) return;
25646
25730
  if (this.isSpaceKeyPressed) stage.container().style.cursor = "grabbing";
25647
- if (!isDragging) return;
25731
+ if (!this.isDragging) return;
25648
25732
  this.getContextMenuPlugin()?.cancelLongPressTimer();
25649
25733
  const pos = stage.getPointerPosition();
25650
25734
  if (pos && lastPos) {
@@ -25659,21 +25743,29 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
25659
25743
  stage.on("pointermove", handleMouseMove);
25660
25744
  stage.on("pointerup", (e) => {
25661
25745
  this.pointers.delete(e.evt.pointerId);
25662
- isDragging = false;
25746
+ this.isMouseLeftButtonPressed = false;
25747
+ this.isMouseMiddleButtonPressed = false;
25748
+ this.moveToolActive = false;
25749
+ this.isDragging = false;
25750
+ this.enableMove = false;
25663
25751
  this.panning = false;
25664
25752
  });
25665
25753
  const handleWheel = (e) => {
25666
25754
  const performPanning = !this.isCtrlOrMetaPressed && !e.ctrlKey;
25667
25755
  const mouseX = e.clientX;
25668
25756
  const mouseY = e.clientY;
25669
- const elementUnderMouse = document.elementFromPoint(mouseX, mouseY);
25757
+ let elementUnderMouse = document.elementFromPoint(mouseX, mouseY);
25758
+ if (isInShadowDOM(stage.container())) {
25759
+ const shadowHost = getTopmostShadowHost(stage.container());
25760
+ if (shadowHost) elementUnderMouse = shadowHost.elementFromPoint(mouseX, mouseY);
25761
+ }
25670
25762
  if (!this.enabled || this.isCtrlOrMetaPressed || e.buttons === 4 || !performPanning || getClosestParentWithId(elementUnderMouse) !== stage.container()) return;
25671
25763
  this.getContextMenuPlugin()?.cancelLongPressTimer();
25672
25764
  stage.x(stage.x() - e.deltaX);
25673
25765
  stage.y(stage.y() - e.deltaY);
25674
25766
  this.instance.emitEvent("onStageMove");
25675
25767
  };
25676
- window.addEventListener("wheel", handleWheel, { passive: false });
25768
+ window.addEventListener("wheel", handleWheel, { passive: true });
25677
25769
  stage.container().style.touchAction = "none";
25678
25770
  stage.container().style.userSelect = "none";
25679
25771
  stage.container().style.setProperty("-webkit-user-drag", "none");
@@ -26226,7 +26318,10 @@ var WeaveNodesEdgeSnappingPlugin = class extends WeavePlugin {
26226
26318
  if (!utilityLayer) return;
26227
26319
  const { targetNode: node, skipNodes } = getTargetAndSkipNodes(this.instance, e);
26228
26320
  if (typeof node === "undefined") return;
26229
- const visibleNodes = this.getVisibleNodes(skipNodes);
26321
+ const nodeParent = this.instance.getNodeContainer(node);
26322
+ if (nodeParent === null) return;
26323
+ const stage = this.instance.getStage();
26324
+ const visibleNodes = getVisibleNodes(this.instance, stage, nodeParent, skipNodes, this.instance.getMainLayer());
26230
26325
  const lineGuideStops = this.getLineGuideStops(visibleNodes);
26231
26326
  const itemBounds = this.getObjectSnappingEdges(node);
26232
26327
  const guides = this.getGuides(lineGuideStops, itemBounds, e.type);
@@ -26304,21 +26399,6 @@ var WeaveNodesEdgeSnappingPlugin = class extends WeavePlugin {
26304
26399
  });
26305
26400
  }
26306
26401
  }
26307
- getVisibleNodes(skipNodes) {
26308
- const stage = this.instance.getStage();
26309
- const nodesSelection = this.instance.getPlugin("nodesSelection");
26310
- if (nodesSelection) nodesSelection.getTransformer().hide();
26311
- const nodes = getVisibleNodesInViewport(stage, this.instance.getMainLayer());
26312
- const finalVisibleNodes = [];
26313
- nodes.forEach((node) => {
26314
- if (node.getParent()?.getAttrs().nodeType === "group") return;
26315
- if (skipNodes.includes(node.getParent()?.getAttrs().nodeId)) return;
26316
- if (skipNodes.includes(node.getAttrs().id ?? "")) return;
26317
- finalVisibleNodes.push(node);
26318
- });
26319
- if (nodesSelection) nodesSelection.getTransformer().show();
26320
- return finalVisibleNodes;
26321
- }
26322
26402
  getLineGuideStops(nodes) {
26323
26403
  const vertical = [];
26324
26404
  const horizontal = [];
@@ -26540,6 +26620,7 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
26540
26620
  const { config } = params ?? {};
26541
26621
  this.enterSnappingTolerance = config?.enterSnappingTolerance ?? GUIDE_ENTER_SNAPPING_TOLERANCE;
26542
26622
  this.exitSnappingTolerance = config?.exitSnappingTolerance ?? GUIDE_EXIT_SNAPPING_TOLERANCE;
26623
+ this.uiConfig = import_lodash.default.merge(GUIDE_DISTANCE_LINE_DEFAULT_CONFIG, config?.ui);
26543
26624
  this.enabled = true;
26544
26625
  }
26545
26626
  getName() {
@@ -26559,19 +26640,16 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
26559
26640
  }
26560
26641
  }
26561
26642
  evaluateGuidelines(e) {
26562
- const stage = this.instance.getStage();
26563
- const mainLayer = this.instance.getMainLayer();
26564
26643
  const utilityLayer = this.instance.getUtilityLayer();
26565
26644
  if (!this.enabled) return;
26566
26645
  if (!utilityLayer) return;
26567
26646
  const { targetNode: node, skipNodes } = getTargetAndSkipNodes(this.instance, e);
26568
26647
  if (typeof node === "undefined") return;
26569
- if (node.getParent() === mainLayer) this.referenceLayer = mainLayer;
26570
- if (node.getParent()?.getAttrs().nodeId) {
26571
- const realNode = stage.findOne(`#${node.getParent()?.getAttrs().nodeId}`);
26572
- if (realNode) this.referenceLayer = realNode;
26573
- }
26574
- const visibleNodes = this.getVisibleNodes(skipNodes);
26648
+ const nodeParent = this.instance.getNodeContainer(node);
26649
+ if (nodeParent === null) return;
26650
+ const stage = this.instance.getStage();
26651
+ this.referenceLayer = nodeParent;
26652
+ const visibleNodes = getVisibleNodes(this.instance, stage, nodeParent, skipNodes, this.referenceLayer);
26575
26653
  const { intersectedNodes: sortedHorizontalIntersectedNodes, intersectedNodesWithDistances: horizontalIntersectedNodes } = this.getHorizontallyIntersectingNodes(node, visibleNodes);
26576
26654
  const { intersectedNodes: sortedVerticalIntersectedNodes, intersectedNodesWithDistances: verticalIntersectedNodes } = this.getVerticallyIntersectingNodes(node, visibleNodes);
26577
26655
  this.cleanupGuidelines();
@@ -26802,6 +26880,11 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
26802
26880
  });
26803
26881
  }
26804
26882
  }
26883
+ isOverlapping(node1, node2) {
26884
+ const box1 = this.getBoxClientRect(node1);
26885
+ const box2 = this.getBoxClientRect(node2);
26886
+ return !(box1.x + box1.width <= box2.x || box2.x + box2.width <= box1.x || box1.y + box1.height <= box2.y || box2.y + box2.height <= box1.y);
26887
+ }
26805
26888
  getVerticallyIntersectingNodes(targetNode, nodes) {
26806
26889
  const targetBox = this.getBoxClientRect(targetNode);
26807
26890
  const intersectedNodes = [];
@@ -26818,30 +26901,32 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
26818
26901
  return ay - by;
26819
26902
  });
26820
26903
  const intersectedNodesWithDistances = [];
26821
- for (let i = 0; i < intersectedNodes.length - 1; i++) {
26822
- const a = intersectedNodes[i];
26823
- const b = intersectedNodes[i + 1];
26824
- const boxA = this.getBoxClientRect(a);
26825
- const boxB = this.getBoxClientRect(b);
26826
- const aBottom = boxA.y + boxA.height;
26827
- const bTop = boxB.y;
26828
- const distance = Math.abs(aBottom - bTop);
26829
- const left = Math.max(boxA.x, boxB.x);
26830
- const right = Math.min(boxA.x + boxA.width, boxB.x + boxB.width);
26831
- let midX;
26832
- if (right > left) midX = left + (right - left) / 2;
26833
- else {
26834
- const aCenterX = boxA.x + boxA.width / 2;
26835
- const bCenterX = boxB.x + boxB.width / 2;
26836
- midX = (aCenterX + bCenterX) / 2;
26837
- }
26838
- intersectedNodesWithDistances.push({
26839
- index: i,
26840
- from: a,
26841
- to: b,
26842
- midX,
26843
- distance: Math.round(distance)
26844
- });
26904
+ for (let i = 0; i < intersectedNodes.length; i++) for (let j = i + 1; j < intersectedNodes.length; j++) {
26905
+ const nodeA = intersectedNodes[i];
26906
+ const nodeB = intersectedNodes[j];
26907
+ if (!this.isOverlapping(nodeA, nodeB)) {
26908
+ const boxA = this.getBoxClientRect(nodeA);
26909
+ const boxB = this.getBoxClientRect(nodeB);
26910
+ const aBottom = boxA.y + boxA.height;
26911
+ const bTop = boxB.y;
26912
+ const distance = Math.abs(aBottom - bTop);
26913
+ const left = Math.max(boxA.x, boxB.x);
26914
+ const right = Math.min(boxA.x + boxA.width, boxB.x + boxB.width);
26915
+ let midX;
26916
+ if (right > left) midX = left + (right - left) / 2;
26917
+ else {
26918
+ const aCenterX = boxA.x + boxA.width / 2;
26919
+ const bCenterX = boxB.x + boxB.width / 2;
26920
+ midX = (aCenterX + bCenterX) / 2;
26921
+ }
26922
+ intersectedNodesWithDistances.push({
26923
+ index: i,
26924
+ from: nodeA,
26925
+ to: nodeB,
26926
+ midX,
26927
+ distance: Math.round(distance)
26928
+ });
26929
+ }
26845
26930
  }
26846
26931
  return {
26847
26932
  intersectedNodes,
@@ -26864,56 +26949,38 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
26864
26949
  return ax - bx;
26865
26950
  });
26866
26951
  const intersectedNodesWithDistances = [];
26867
- for (let i = 0; i < intersectedNodes.length - 1; i++) {
26868
- const a = intersectedNodes[i];
26869
- const b = intersectedNodes[i + 1];
26870
- const boxA = this.getBoxClientRect(a);
26871
- const boxB = this.getBoxClientRect(b);
26872
- const aRight = boxA.x + boxA.width;
26873
- const bLeft = boxB.x;
26874
- const distance = Math.abs(Math.round(aRight - bLeft));
26875
- const top = Math.max(boxA.y, boxB.y);
26876
- const bottom = Math.min(boxA.y + boxA.height, boxB.y + boxB.height);
26877
- let midY;
26878
- if (bottom > top) midY = top + (bottom - top) / 2;
26879
- else {
26880
- const aCenterY = boxA.y + boxA.height / 2;
26881
- const bCenterY = boxB.y + boxB.height / 2;
26882
- midY = (aCenterY + bCenterY) / 2;
26883
- }
26884
- intersectedNodesWithDistances.push({
26885
- index: i,
26886
- from: a,
26887
- to: b,
26888
- midY,
26889
- distance
26890
- });
26952
+ for (let i = 0; i < intersectedNodes.length; i++) for (let j = i + 1; j < intersectedNodes.length; j++) {
26953
+ const nodeA = intersectedNodes[i];
26954
+ const nodeB = intersectedNodes[j];
26955
+ if (!this.isOverlapping(nodeA, nodeB)) {
26956
+ const boxA = this.getBoxClientRect(nodeA);
26957
+ const boxB = this.getBoxClientRect(nodeB);
26958
+ const aRight = boxA.x + boxA.width;
26959
+ const bLeft = boxB.x;
26960
+ const distance = Math.abs(Math.round(aRight - bLeft));
26961
+ const top = Math.max(boxA.y, boxB.y);
26962
+ const bottom = Math.min(boxA.y + boxA.height, boxB.y + boxB.height);
26963
+ let midY;
26964
+ if (bottom > top) midY = top + (bottom - top) / 2;
26965
+ else {
26966
+ const aCenterY = boxA.y + boxA.height / 2;
26967
+ const bCenterY = boxB.y + boxB.height / 2;
26968
+ midY = (aCenterY + bCenterY) / 2;
26969
+ }
26970
+ intersectedNodesWithDistances.push({
26971
+ index: i,
26972
+ from: nodeA,
26973
+ to: nodeB,
26974
+ midY,
26975
+ distance: Math.round(distance)
26976
+ });
26977
+ }
26891
26978
  }
26892
26979
  return {
26893
26980
  intersectedNodes,
26894
26981
  intersectedNodesWithDistances
26895
26982
  };
26896
26983
  }
26897
- getVisibleNodes(skipNodes) {
26898
- const stage = this.instance.getStage();
26899
- const nodesSelection = this.instance.getPlugin("nodesSelection");
26900
- if (nodesSelection) nodesSelection.getTransformer().hide();
26901
- const nodes = getVisibleNodesInViewport(stage, this.referenceLayer);
26902
- const finalVisibleNodes = [];
26903
- nodes.forEach((node) => {
26904
- if (node.getParent()?.getAttrs().nodeType === "group") return;
26905
- if (skipNodes.includes(node.getParent()?.getAttrs().nodeId)) return;
26906
- if (skipNodes.includes(node.getAttrs().id ?? "")) return;
26907
- if (node.getParent() !== this.referenceLayer && !node.getParent()?.getAttrs().nodeId) return;
26908
- if (node.getParent() !== this.referenceLayer && node.getParent()?.getAttrs().nodeId) {
26909
- const realNode = stage.findOne(`#${node.getParent()?.getAttrs().nodeId}`);
26910
- if (realNode && realNode !== this.referenceLayer) return;
26911
- }
26912
- finalVisibleNodes.push(node);
26913
- });
26914
- if (nodesSelection) nodesSelection.getTransformer().show();
26915
- return finalVisibleNodes;
26916
- }
26917
26984
  drawSizeGuidesHorizontally(intersectionsH, peerDistance) {
26918
26985
  const utilityLayer = this.instance.getUtilityLayer();
26919
26986
  if (utilityLayer) intersectionsH.forEach((pairInfo) => {
@@ -26930,40 +26997,60 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
26930
26997
  if (pairInfo.distance === peerDistance) this.renderVerticalLineWithDistanceBetweenNodes(from, to, pairInfo.midX, `${pairInfo.distance}`);
26931
26998
  });
26932
26999
  }
26933
- renderDistanceLabel(ctx, stage, labelText, { canvasMidX, canvasMidY }) {
27000
+ renderDistanceLabel(ctx, stage, labelText, orientation, { canvasMidX, canvasMidY }, config) {
26934
27001
  const scaleX = stage?.scaleX() || 1;
26935
27002
  const scaleY = stage?.scaleY() || 1;
26936
- const fontSize = 12;
26937
- const fontFamily = "Arial";
26938
- const padding = 6;
27003
+ const fontSize = config.label.fontSize;
27004
+ const fontFamily = config.label.fontFamily;
27005
+ const fontStyle = config.label.fontStyle;
27006
+ const cornerRadius = config.label.cornerRadius;
27007
+ const linePadding = config.label.linePadding;
27008
+ const fill = config.label.fill;
27009
+ const height = config.label.height;
27010
+ const paddingX = config.label.paddingX;
26939
27011
  const tempText = new konva.default.Text({
26940
27012
  text: labelText,
26941
27013
  fontSize,
27014
+ fontStyle,
26942
27015
  fontFamily,
26943
27016
  visible: false
26944
27017
  });
26945
27018
  const textWidth = tempText.width();
26946
- const textHeight = tempText.height();
26947
- const labelWidth = textWidth + padding * 2;
26948
- const labelHeight = textHeight + padding * 2;
27019
+ const labelWidth = textWidth + paddingX * 2;
27020
+ const labelHeight = height;
26949
27021
  ctx.save();
26950
27022
  ctx.scale(1 / scaleX, 1 / scaleY);
26951
- const labelX = canvasMidX - labelWidth / 2;
26952
- const labelY = canvasMidY - labelHeight / 2;
27023
+ let labelX = canvasMidX - labelWidth / 2;
27024
+ let labelY = canvasMidY + linePadding;
27025
+ if (orientation === "vertical") {
27026
+ labelX = canvasMidX + linePadding;
27027
+ labelY = canvasMidY - labelWidth / 2;
27028
+ }
27029
+ const r = Math.min(cornerRadius, labelWidth / 2, labelHeight / 2);
26953
27030
  ctx.beginPath();
26954
- ctx.rect(labelX, labelY, labelWidth, labelHeight);
26955
- ctx.fillStyle = "#ff0000";
27031
+ ctx.moveTo(labelX + r, labelY);
27032
+ ctx.lineTo(labelX + labelWidth - r, labelY);
27033
+ ctx.quadraticCurveTo(labelX + labelWidth, labelY, labelX + labelWidth, labelY + r);
27034
+ ctx.lineTo(labelX + labelWidth, labelY + labelHeight - r);
27035
+ ctx.quadraticCurveTo(labelX + labelWidth, labelY + labelHeight, labelX + labelWidth - r, labelY + labelHeight);
27036
+ ctx.lineTo(labelX + r, labelY + labelHeight);
27037
+ ctx.quadraticCurveTo(labelX, labelY + labelHeight, labelX, labelY + labelHeight - r);
27038
+ ctx.lineTo(labelX, labelY + r);
27039
+ ctx.quadraticCurveTo(labelX, labelY, labelX + r, labelY);
27040
+ ctx.closePath();
27041
+ ctx.fillStyle = fill;
26956
27042
  ctx.fill();
26957
- ctx.font = `bold ${fontSize}px ${fontFamily}`;
27043
+ ctx.font = `${fontStyle} ${fontSize}px ${fontFamily}`;
26958
27044
  ctx.fillStyle = "white";
26959
27045
  ctx.textAlign = "center";
26960
27046
  ctx.textBaseline = "middle";
26961
- ctx.fillText(labelText, canvasMidX, labelY + labelHeight / 2);
27047
+ ctx.fillText(labelText, labelX + labelWidth / 2, labelY + labelHeight / 2);
26962
27048
  ctx.restore();
26963
27049
  }
26964
27050
  renderHorizontalLineWithDistanceBetweenNodes(from, to, midY, labelText) {
26965
27051
  const utilityLayer = this.instance.getUtilityLayer();
26966
27052
  const renderLabel = this.renderDistanceLabel;
27053
+ const uiConfig = this.uiConfig;
26967
27054
  const lineWithLabel = new konva.default.Shape({
26968
27055
  name: GUIDE_HORIZONTAL_LINE_NAME,
26969
27056
  sceneFunc: function(ctx, shape) {
@@ -26977,8 +27064,8 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
26977
27064
  ctx.moveTo(x1, y);
26978
27065
  ctx.lineTo(x2, y);
26979
27066
  ctx.closePath();
26980
- ctx.strokeStyle = "#ff0000";
26981
- ctx.lineWidth = 1;
27067
+ ctx.strokeStyle = uiConfig.line.stroke;
27068
+ ctx.lineWidth = uiConfig.line.strokeWidth;
26982
27069
  ctx.setLineDash([]);
26983
27070
  ctx.stroke();
26984
27071
  ctx.closePath();
@@ -26986,10 +27073,10 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
26986
27073
  const worldMidY = y;
26987
27074
  const canvasMidX = worldMidX * scaleX;
26988
27075
  const canvasMidY = worldMidY * scaleY;
26989
- renderLabel(ctx, stage, labelText, {
27076
+ renderLabel(ctx, stage, labelText, "horizontal", {
26990
27077
  canvasMidX,
26991
27078
  canvasMidY
26992
- });
27079
+ }, uiConfig);
26993
27080
  ctx.fillStrokeShape(shape);
26994
27081
  }
26995
27082
  });
@@ -26999,6 +27086,7 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
26999
27086
  renderVerticalLineWithDistanceBetweenNodes(from, to, midX, labelText) {
27000
27087
  const utilityLayer = this.instance.getUtilityLayer();
27001
27088
  const renderLabel = this.renderDistanceLabel;
27089
+ const uiConfig = this.uiConfig;
27002
27090
  const lineWithLabel = new konva.default.Shape({
27003
27091
  name: GUIDE_VERTICAL_LINE_NAME,
27004
27092
  sceneFunc: function(ctx, shape) {
@@ -27012,18 +27100,18 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
27012
27100
  ctx.setLineDash([]);
27013
27101
  ctx.moveTo(x, y1);
27014
27102
  ctx.lineTo(x, y2);
27015
- ctx.strokeStyle = "#ff0000";
27016
- ctx.lineWidth = 1;
27103
+ ctx.strokeStyle = uiConfig.line.stroke;
27104
+ ctx.lineWidth = uiConfig.line.strokeWidth;
27017
27105
  ctx.stroke();
27018
27106
  ctx.closePath();
27019
27107
  const worldMidX = x;
27020
27108
  const worldMidY = (y1 + y2) / 2;
27021
27109
  const canvasMidX = worldMidX * scaleX;
27022
27110
  const canvasMidY = worldMidY * scaleY;
27023
- renderLabel(ctx, stage, labelText, {
27111
+ renderLabel(ctx, stage, labelText, "vertical", {
27024
27112
  canvasMidX,
27025
27113
  canvasMidY
27026
- });
27114
+ }, uiConfig);
27027
27115
  ctx.fillStrokeShape(shape);
27028
27116
  }
27029
27117
  });
@@ -27053,6 +27141,7 @@ exports.ERASER_TOOL_ACTION_NAME = ERASER_TOOL_ACTION_NAME
27053
27141
  exports.ERASER_TOOL_STATE = ERASER_TOOL_STATE
27054
27142
  exports.FRAME_TOOL_ACTION_NAME = FRAME_TOOL_ACTION_NAME
27055
27143
  exports.FRAME_TOOL_STATE = FRAME_TOOL_STATE
27144
+ exports.GUIDE_DISTANCE_LINE_DEFAULT_CONFIG = GUIDE_DISTANCE_LINE_DEFAULT_CONFIG
27056
27145
  exports.GUIDE_ENTER_SNAPPING_TOLERANCE = GUIDE_ENTER_SNAPPING_TOLERANCE
27057
27146
  exports.GUIDE_EXIT_SNAPPING_TOLERANCE = GUIDE_EXIT_SNAPPING_TOLERANCE
27058
27147
  exports.GUIDE_HORIZONTAL_LINE_NAME = GUIDE_HORIZONTAL_LINE_NAME
@@ -27186,10 +27275,13 @@ exports.getExportBoundingBox = getExportBoundingBox
27186
27275
  exports.getSelectedNodesMetadata = getSelectedNodesMetadata
27187
27276
  exports.getTargetAndSkipNodes = getTargetAndSkipNodes
27188
27277
  exports.getTargetedNode = getTargetedNode
27278
+ exports.getTopmostShadowHost = getTopmostShadowHost
27279
+ exports.getVisibleNodes = getVisibleNodes
27189
27280
  exports.getVisibleNodesInViewport = getVisibleNodesInViewport
27190
27281
  exports.hasFrames = hasFrames
27191
27282
  exports.hasImages = hasImages
27192
27283
  exports.intersectArrays = intersectArrays
27284
+ exports.isInShadowDOM = isInShadowDOM
27193
27285
  exports.isNodeInSelection = isNodeInSelection
27194
27286
  exports.moveNodeToContainer = moveNodeToContainer
27195
27287
  exports.resetScale = resetScale