@elixpo/lixsketch 5.4.7 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react/AIRenderer-M4LMJ66J.js +1105 -0
- package/dist/react/AIRenderer-M4LMJ66J.js.map +7 -0
- package/dist/react/Arrow-BJDAXPMH.js +8 -0
- package/dist/react/Arrow-BJDAXPMH.js.map +7 -0
- package/dist/react/Circle-KPG7TKIX.js +8 -0
- package/dist/react/Circle-KPG7TKIX.js.map +7 -0
- package/dist/react/CodeShape-K4DIZAIV.js +8 -0
- package/dist/react/CodeShape-K4DIZAIV.js.map +7 -0
- package/dist/react/CopyPaste-4CKJRHJ3.js +569 -0
- package/dist/react/CopyPaste-4CKJRHJ3.js.map +7 -0
- package/dist/react/EraserTrail-PA6IQLQN.js +20 -0
- package/dist/react/EraserTrail-PA6IQLQN.js.map +7 -0
- package/dist/react/EventDispatcher-SRFH6LQZ.js +463 -0
- package/dist/react/EventDispatcher-SRFH6LQZ.js.map +7 -0
- package/dist/react/Frame-6UR5XPAX.js +10 -0
- package/dist/react/Frame-6UR5XPAX.js.map +7 -0
- package/dist/react/FreehandStroke-CK24NUT3.js +8 -0
- package/dist/react/FreehandStroke-CK24NUT3.js.map +7 -0
- package/dist/react/GraphEngine-QE5B2PMR.js +340 -0
- package/dist/react/GraphEngine-QE5B2PMR.js.map +7 -0
- package/dist/react/GraphMathParser-2WMTY4IE.js +10 -0
- package/dist/react/GraphMathParser-2WMTY4IE.js.map +7 -0
- package/dist/react/IconShape-KMIA6T2H.js +10 -0
- package/dist/react/IconShape-KMIA6T2H.js.map +7 -0
- package/dist/react/ImageShape-CHHGBXUQ.js +10 -0
- package/dist/react/ImageShape-CHHGBXUQ.js.map +7 -0
- package/dist/react/LayerOrder-XCHF4MSS.js +66 -0
- package/dist/react/LayerOrder-XCHF4MSS.js.map +7 -0
- package/dist/react/Line-2KOQEEGA.js +10 -0
- package/dist/react/Line-2KOQEEGA.js.map +7 -0
- package/dist/react/LixScriptParser-JYWJX375.js +1033 -0
- package/dist/react/LixScriptParser-JYWJX375.js.map +7 -0
- package/dist/react/MermaidFlowchartRenderer-4QBAZ5MB.js +412 -0
- package/dist/react/MermaidFlowchartRenderer-4QBAZ5MB.js.map +7 -0
- package/dist/react/MermaidSequenceParser-UKG2NSZY.js +8 -0
- package/dist/react/MermaidSequenceParser-UKG2NSZY.js.map +7 -0
- package/dist/react/MermaidSequenceRenderer-HPLHY5II.js +387 -0
- package/dist/react/MermaidSequenceRenderer-HPLHY5II.js.map +7 -0
- package/dist/react/Rectangle-6FE7RN6W.js +8 -0
- package/dist/react/Rectangle-6FE7RN6W.js.map +7 -0
- package/dist/react/ResizeCode-WAMDTKSW.js +2 -0
- package/dist/react/ResizeCode-WAMDTKSW.js.map +7 -0
- package/dist/react/ResizeShapes-LKEQTITP.js +250 -0
- package/dist/react/ResizeShapes-LKEQTITP.js.map +7 -0
- package/dist/react/SceneSerializer-4U4B24JM.js +739 -0
- package/dist/react/SceneSerializer-4U4B24JM.js.map +7 -0
- package/dist/react/Selection-VVUHY5YJ.js +34 -0
- package/dist/react/Selection-VVUHY5YJ.js.map +7 -0
- package/dist/react/SketchEngine-YA4RG3KX.js +413 -0
- package/dist/react/SketchEngine-YA4RG3KX.js.map +7 -0
- package/dist/react/TextShape-54ZJ66E3.js +8 -0
- package/dist/react/TextShape-54ZJ66E3.js.map +7 -0
- package/dist/react/UndoRedo-M2JZUBKN.js +30 -0
- package/dist/react/UndoRedo-M2JZUBKN.js.map +7 -0
- package/dist/react/ZoomPan-U3TXC5AJ.js +186 -0
- package/dist/react/ZoomPan-U3TXC5AJ.js.map +7 -0
- package/dist/react/arrowTool-CWEMIRXK.js +17 -0
- package/dist/react/arrowTool-CWEMIRXK.js.map +7 -0
- package/dist/react/boxicons-5JNJQPUP.woff +0 -0
- package/dist/react/boxicons-6NVWQSCQ.eot +0 -0
- package/dist/react/boxicons-AQ5N6WP7.woff2 +0 -0
- package/dist/react/boxicons-GDR4JU3X.ttf +0 -0
- package/dist/react/boxicons-NNFHLMOR.svg +1660 -0
- package/dist/react/chunk-2OQXI7QB.js +564 -0
- package/dist/react/chunk-2OQXI7QB.js.map +7 -0
- package/dist/react/chunk-5OUBTHHO.js +187 -0
- package/dist/react/chunk-5OUBTHHO.js.map +7 -0
- package/dist/react/chunk-6PFXZKL2.js +628 -0
- package/dist/react/chunk-6PFXZKL2.js.map +7 -0
- package/dist/react/chunk-6SFNWGGZ.js +453 -0
- package/dist/react/chunk-6SFNWGGZ.js.map +7 -0
- package/dist/react/chunk-7TZSIR6V.js +210 -0
- package/dist/react/chunk-7TZSIR6V.js.map +7 -0
- package/dist/react/chunk-AJAZC37E.js +662 -0
- package/dist/react/chunk-AJAZC37E.js.map +7 -0
- package/dist/react/chunk-BU4D2WYQ.js +1213 -0
- package/dist/react/chunk-BU4D2WYQ.js.map +7 -0
- package/dist/react/chunk-BZE4CEBG.js +747 -0
- package/dist/react/chunk-BZE4CEBG.js.map +7 -0
- package/dist/react/chunk-CB2RANCB.js +212 -0
- package/dist/react/chunk-CB2RANCB.js.map +7 -0
- package/dist/react/chunk-DNAG7ML6.js +128 -0
- package/dist/react/chunk-DNAG7ML6.js.map +7 -0
- package/dist/react/chunk-HZWLPXFN.js +198 -0
- package/dist/react/chunk-HZWLPXFN.js.map +7 -0
- package/dist/react/chunk-I6HCCIXB.js +572 -0
- package/dist/react/chunk-I6HCCIXB.js.map +7 -0
- package/dist/react/chunk-IZ5OGWGW.js +235 -0
- package/dist/react/chunk-IZ5OGWGW.js.map +7 -0
- package/dist/react/chunk-JJCJNLNN.js +1490 -0
- package/dist/react/chunk-JJCJNLNN.js.map +7 -0
- package/dist/react/chunk-JQ3IRFDP.js +222 -0
- package/dist/react/chunk-JQ3IRFDP.js.map +7 -0
- package/dist/react/chunk-L5OARZJ7.js +1134 -0
- package/dist/react/chunk-L5OARZJ7.js.map +7 -0
- package/dist/react/chunk-LHRTXNVE.js +1600 -0
- package/dist/react/chunk-LHRTXNVE.js.map +7 -0
- package/dist/react/chunk-Q2GA4MBZ.js +1653 -0
- package/dist/react/chunk-Q2GA4MBZ.js.map +7 -0
- package/dist/react/chunk-QNSE5BAY.js +519 -0
- package/dist/react/chunk-QNSE5BAY.js.map +7 -0
- package/dist/react/chunk-QXFBG7OM.js +191 -0
- package/dist/react/chunk-QXFBG7OM.js.map +7 -0
- package/dist/react/chunk-T6ZVV5ZO.js +714 -0
- package/dist/react/chunk-T6ZVV5ZO.js.map +7 -0
- package/dist/react/chunk-URB6MY46.js +974 -0
- package/dist/react/chunk-URB6MY46.js.map +7 -0
- package/dist/react/chunk-VN62KLOC.js +931 -0
- package/dist/react/chunk-VN62KLOC.js.map +7 -0
- package/dist/react/chunk-VQVEPJSA.js +158 -0
- package/dist/react/chunk-VQVEPJSA.js.map +7 -0
- package/dist/react/chunk-XISEAGBV.js +1632 -0
- package/dist/react/chunk-XISEAGBV.js.map +7 -0
- package/dist/react/chunk-YKJUBFHE.js +575 -0
- package/dist/react/chunk-YKJUBFHE.js.map +7 -0
- package/dist/react/circleTool-NUATSEI2.js +14 -0
- package/dist/react/circleTool-NUATSEI2.js.map +7 -0
- package/dist/react/codeTool-MHCB2FNB.js +38 -0
- package/dist/react/codeTool-MHCB2FNB.js.map +7 -0
- package/dist/react/eraserTool-2GS2LQCS.js +103 -0
- package/dist/react/eraserTool-2GS2LQCS.js.map +7 -0
- package/dist/react/frameTool-PWVKKXSP.js +14 -0
- package/dist/react/frameTool-PWVKKXSP.js.map +7 -0
- package/dist/react/freehandTool-SLYGASVP.js +14 -0
- package/dist/react/freehandTool-SLYGASVP.js.map +7 -0
- package/dist/react/iconTool-GPZ7O7NH.js +18 -0
- package/dist/react/iconTool-GPZ7O7NH.js.map +7 -0
- package/dist/react/imageTool-D5R4XGEU.js +15 -0
- package/dist/react/imageTool-D5R4XGEU.js.map +7 -0
- package/dist/react/index.js +5349 -0
- package/dist/react/index.js.map +7 -0
- package/dist/react/laserTool-XVMV63AV.js +239 -0
- package/dist/react/laserTool-XVMV63AV.js.map +7 -0
- package/dist/react/lineTool-WNI5EMZ5.js +14 -0
- package/dist/react/lineTool-WNI5EMZ5.js.map +7 -0
- package/dist/react/lixCode-OJMVUXXI.ttf +0 -0
- package/dist/react/lixDefault-JEAPAUJL.ttf +0 -0
- package/dist/react/lixFancy-BPXYM5CQ.ttf +0 -0
- package/dist/react/lixFont-CPKEUDVM.woff2 +0 -0
- package/dist/react/rectangleTool-U7DZ6ZTA.js +14 -0
- package/dist/react/rectangleTool-U7DZ6ZTA.js.map +7 -0
- package/dist/react/styles.css +6627 -0
- package/dist/react/textTool-M7S6F3VC.js +21 -0
- package/dist/react/textTool-M7S6F3VC.js.map +7 -0
- package/package.json +39 -5
- package/src/EngineShortcuts.js +83 -27
- package/src/core/AIRenderer.js +30 -18
- package/src/core/GraphEngine.js +64 -41
- package/src/core/MermaidFlowchartRenderer.js +153 -88
- package/src/core/MermaidSequenceRenderer.js +168 -93
- package/src/core/SceneSerializer.js +86 -2
- package/src/core/Selection.js +119 -19
- package/src/core/UndoRedo.js +82 -15
- package/src/core/ZoomPan.js +15 -5
- package/src/index.js +14 -1
- package/src/react/LixSketchCanvas.jsx +347 -0
- package/src/react/components/AppMenu.jsx +482 -0
- package/src/react/components/Footer.jsx +85 -0
- package/src/react/components/Toolbar.jsx +140 -0
- package/src/react/components/canvas/CanvasLoadingOverlay.jsx +76 -0
- package/src/react/components/canvas/ContextMenu.jsx +466 -0
- package/src/react/components/canvas/FindBar.jsx +177 -0
- package/src/react/components/canvas/ImageSourcePicker.jsx +133 -0
- package/src/react/components/canvas/MultiSelectActions.jsx +120 -0
- package/src/react/components/canvas/SVGCanvas.jsx +145 -0
- package/src/react/components/canvas/SaveStatusIndicator.jsx +29 -0
- package/src/react/components/modals/CanvasPropertiesModal.jsx +358 -0
- package/src/react/components/modals/CommandPalette.jsx +307 -0
- package/src/react/components/modals/ExportImageModal.jsx +287 -0
- package/src/react/components/modals/GraphModal.jsx +174 -0
- package/src/react/components/modals/HelpModal.jsx +208 -0
- package/src/react/components/modals/LixScriptModal.jsx +130 -0
- package/src/react/components/modals/ShortcutsModal.jsx +125 -0
- package/src/react/components/sidebars/ArrowSidebar.jsx +173 -0
- package/src/react/components/sidebars/CircleSidebar.jsx +134 -0
- package/src/react/components/sidebars/FrameSidebar.jsx +263 -0
- package/src/react/components/sidebars/IconSidebar.jsx +279 -0
- package/src/react/components/sidebars/ImageSidebar.jsx +69 -0
- package/src/react/components/sidebars/LineSidebar.jsx +109 -0
- package/src/react/components/sidebars/PaintbrushSidebar.jsx +119 -0
- package/src/react/components/sidebars/RectangleSidebar.jsx +165 -0
- package/src/react/components/sidebars/ShapeSidebar.jsx +130 -0
- package/src/react/components/sidebars/TextSidebar.jsx +174 -0
- package/src/react/hooks/inertStores.js +58 -0
- package/src/react/hooks/useSketchEngine.js +76 -0
- package/src/react/hooks/useTranslation.js +92 -0
- package/src/react/index.js +41 -0
- package/src/react/store/useSketchStore.js +234 -0
- package/src/react/store/useUIStore.js +196 -0
- package/src/react/styles/arrowSidebar.css +263 -0
- package/src/react/styles/canvasStroke.css +47 -0
- package/src/react/styles/canvasTools.css +769 -0
- package/src/react/styles/circleSidebar.css +206 -0
- package/src/react/styles/fonts/fonts.css +29 -0
- package/src/react/styles/fonts/lixCode.ttf +0 -0
- package/src/react/styles/fonts/lixDefault.ttf +0 -0
- package/src/react/styles/fonts/lixDocs.ttf +0 -0
- package/src/react/styles/fonts/lixFancy.ttf +0 -0
- package/src/react/styles/fonts/lixFont.woff2 +0 -0
- package/src/react/styles/lineSidebar.css +207 -0
- package/src/react/styles/paintbrushSidebar.css +247 -0
- package/src/react/styles/squareSidebar.css +206 -0
- package/src/react/styles/writeText.css +149 -0
- package/src/react/styles.css +175 -0
- package/src/react/toolsEnum.js +20 -0
- package/src/react/utils/toast.js +18 -0
- package/src/shapes/Frame.js +7 -1
- package/src/shapes/Line.js +11 -5
- package/src/tools/arrowTool.js +30 -4
- package/src/tools/circleTool.js +33 -9
- package/src/tools/codeTool.js +5 -3
- package/src/tools/frameTool.js +47 -7
- package/src/tools/freehandTool.js +12 -4
- package/src/tools/iconTool.js +7 -1
- package/src/tools/imageTool.js +7 -1
- package/src/tools/lineTool.js +27 -3
- package/src/tools/rectangleTool.js +45 -8
- package/src/tools/textTool.js +23 -6
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
pushCreateAction,
|
|
4
|
+
pushDeleteAction,
|
|
5
|
+
pushFrameAttachmentAction,
|
|
6
|
+
pushOptionsChangeAction,
|
|
7
|
+
pushTransformAction
|
|
8
|
+
} from "./chunk-L5OARZJ7.js";
|
|
9
|
+
|
|
10
|
+
// src/core/SnapGuides.js
|
|
11
|
+
var SNAP_THRESHOLD = 6;
|
|
12
|
+
var BREAK_THRESHOLD = 12;
|
|
13
|
+
var GUIDE_COLOR = "#ff4444";
|
|
14
|
+
var GUIDE_WIDTH = 1;
|
|
15
|
+
var guideLayer = null;
|
|
16
|
+
var activeSnapX = null;
|
|
17
|
+
var activeSnapY = null;
|
|
18
|
+
function ensureGuideLayer() {
|
|
19
|
+
if (guideLayer && guideLayer.parentNode) return guideLayer;
|
|
20
|
+
const svg2 = window.svg;
|
|
21
|
+
if (!svg2) return null;
|
|
22
|
+
guideLayer = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
23
|
+
guideLayer.setAttribute("id", "snap-guides");
|
|
24
|
+
guideLayer.setAttribute("pointer-events", "none");
|
|
25
|
+
svg2.appendChild(guideLayer);
|
|
26
|
+
return guideLayer;
|
|
27
|
+
}
|
|
28
|
+
function clearGuides() {
|
|
29
|
+
if (guideLayer) {
|
|
30
|
+
while (guideLayer.firstChild) guideLayer.removeChild(guideLayer.firstChild);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function drawGuide(x1, y1, x2, y2) {
|
|
34
|
+
const layer = ensureGuideLayer();
|
|
35
|
+
if (!layer) return;
|
|
36
|
+
const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
37
|
+
line.setAttribute("x1", x1);
|
|
38
|
+
line.setAttribute("y1", y1);
|
|
39
|
+
line.setAttribute("x2", x2);
|
|
40
|
+
line.setAttribute("y2", y2);
|
|
41
|
+
line.setAttribute("stroke", GUIDE_COLOR);
|
|
42
|
+
line.setAttribute("stroke-width", GUIDE_WIDTH);
|
|
43
|
+
line.setAttribute("stroke-dasharray", "4 2");
|
|
44
|
+
layer.appendChild(line);
|
|
45
|
+
}
|
|
46
|
+
function getShapeBounds(shape) {
|
|
47
|
+
if (!shape) return null;
|
|
48
|
+
const name = shape.shapeName;
|
|
49
|
+
if (name === "rectangle" || name === "frame") {
|
|
50
|
+
return {
|
|
51
|
+
left: shape.x,
|
|
52
|
+
top: shape.y,
|
|
53
|
+
right: shape.x + shape.width,
|
|
54
|
+
bottom: shape.y + shape.height,
|
|
55
|
+
cx: shape.x + shape.width / 2,
|
|
56
|
+
cy: shape.y + shape.height / 2
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (name === "circle") {
|
|
60
|
+
return {
|
|
61
|
+
left: shape.x - shape.rx,
|
|
62
|
+
top: shape.y - shape.ry,
|
|
63
|
+
right: shape.x + shape.rx,
|
|
64
|
+
bottom: shape.y + shape.ry,
|
|
65
|
+
cx: shape.x,
|
|
66
|
+
cy: shape.y
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (name === "text" || name === "code" || name === "image" || name === "icon") {
|
|
70
|
+
const el = shape.group || shape.element;
|
|
71
|
+
if (!el) return null;
|
|
72
|
+
const bbox = el.getBBox();
|
|
73
|
+
return {
|
|
74
|
+
left: bbox.x,
|
|
75
|
+
top: bbox.y,
|
|
76
|
+
right: bbox.x + bbox.width,
|
|
77
|
+
bottom: bbox.y + bbox.height,
|
|
78
|
+
cx: bbox.x + bbox.width / 2,
|
|
79
|
+
cy: bbox.y + bbox.height / 2
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (name === "line" || name === "arrow") {
|
|
83
|
+
const sx = shape.startPoint?.x ?? 0;
|
|
84
|
+
const sy = shape.startPoint?.y ?? 0;
|
|
85
|
+
const ex = shape.endPoint?.x ?? 0;
|
|
86
|
+
const ey = shape.endPoint?.y ?? 0;
|
|
87
|
+
return {
|
|
88
|
+
left: Math.min(sx, ex),
|
|
89
|
+
top: Math.min(sy, ey),
|
|
90
|
+
right: Math.max(sx, ex),
|
|
91
|
+
bottom: Math.max(sy, ey),
|
|
92
|
+
cx: (sx + ex) / 2,
|
|
93
|
+
cy: (sy + ey) / 2
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
function getCanvasGuides() {
|
|
99
|
+
const vb = window.currentViewBox;
|
|
100
|
+
if (!vb) return [];
|
|
101
|
+
return [
|
|
102
|
+
{
|
|
103
|
+
// Viewport center
|
|
104
|
+
left: vb.x + vb.width / 2,
|
|
105
|
+
top: vb.y + vb.height / 2,
|
|
106
|
+
right: vb.x + vb.width / 2,
|
|
107
|
+
bottom: vb.y + vb.height / 2,
|
|
108
|
+
cx: vb.x + vb.width / 2,
|
|
109
|
+
cy: vb.y + vb.height / 2
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
// Viewport edges
|
|
113
|
+
left: vb.x,
|
|
114
|
+
top: vb.y,
|
|
115
|
+
right: vb.x + vb.width,
|
|
116
|
+
bottom: vb.y + vb.height,
|
|
117
|
+
cx: vb.x + vb.width / 2,
|
|
118
|
+
cy: vb.y + vb.height / 2
|
|
119
|
+
}
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
function calculateSnap(movingShape, shiftKey = false, mouseX, mouseY) {
|
|
123
|
+
clearGuides();
|
|
124
|
+
const shapes2 = window.shapes;
|
|
125
|
+
if (!shapes2 || !movingShape) return { dx: 0, dy: 0 };
|
|
126
|
+
const moving = getShapeBounds(movingShape);
|
|
127
|
+
if (!moving) return { dx: 0, dy: 0 };
|
|
128
|
+
if (activeSnapX && mouseX !== void 0) {
|
|
129
|
+
if (Math.abs(mouseX - activeSnapX.mouseAtSnap) > BREAK_THRESHOLD) {
|
|
130
|
+
activeSnapX = null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (activeSnapY && mouseY !== void 0) {
|
|
134
|
+
if (Math.abs(mouseY - activeSnapY.mouseAtSnap) > BREAK_THRESHOLD) {
|
|
135
|
+
activeSnapY = null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
let snapX = null;
|
|
139
|
+
let snapY = null;
|
|
140
|
+
let bestDistX = SNAP_THRESHOLD;
|
|
141
|
+
let bestDistY = SNAP_THRESHOLD;
|
|
142
|
+
const movingXs = [moving.left, moving.cx, moving.right];
|
|
143
|
+
const movingYs = [moving.top, moving.cy, moving.bottom];
|
|
144
|
+
const vb = window.currentViewBox;
|
|
145
|
+
const extendY1 = vb ? vb.y : 0;
|
|
146
|
+
const extendY2 = vb ? vb.y + vb.height : 1e4;
|
|
147
|
+
const extendX1 = vb ? vb.x : 0;
|
|
148
|
+
const extendX2 = vb ? vb.x + vb.width : 1e4;
|
|
149
|
+
let otherShapeCount = 0;
|
|
150
|
+
for (const shape of shapes2) {
|
|
151
|
+
if (shape === movingShape) continue;
|
|
152
|
+
if (window.multiSelection && window.multiSelection.selectedShapes?.has(shape)) continue;
|
|
153
|
+
const other = getShapeBounds(shape);
|
|
154
|
+
if (!other) continue;
|
|
155
|
+
otherShapeCount++;
|
|
156
|
+
const otherXs = [other.left, other.cx, other.right];
|
|
157
|
+
const otherYs = [other.top, other.cy, other.bottom];
|
|
158
|
+
for (const mx of movingXs) {
|
|
159
|
+
for (const ox of otherXs) {
|
|
160
|
+
const dist = Math.abs(mx - ox);
|
|
161
|
+
if (dist < bestDistX) {
|
|
162
|
+
bestDistX = dist;
|
|
163
|
+
snapX = { offset: ox - mx, x: ox, extendY1, extendY2 };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for (const my of movingYs) {
|
|
168
|
+
for (const oy of otherYs) {
|
|
169
|
+
const dist = Math.abs(my - oy);
|
|
170
|
+
if (dist < bestDistY) {
|
|
171
|
+
bestDistY = dist;
|
|
172
|
+
snapY = { offset: oy - my, y: oy, extendX1, extendX2 };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (shiftKey || otherShapeCount === 0 || !snapX && !snapY) {
|
|
178
|
+
const canvasGuides = getCanvasGuides();
|
|
179
|
+
for (const guide of canvasGuides) {
|
|
180
|
+
const guideXs = [guide.left, guide.cx, guide.right];
|
|
181
|
+
const guideYs = [guide.top, guide.cy, guide.bottom];
|
|
182
|
+
for (const mx of movingXs) {
|
|
183
|
+
for (const gx of guideXs) {
|
|
184
|
+
const dist = Math.abs(mx - gx);
|
|
185
|
+
if (dist < bestDistX) {
|
|
186
|
+
bestDistX = dist;
|
|
187
|
+
snapX = { offset: gx - mx, x: gx, extendY1, extendY2 };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const my of movingYs) {
|
|
192
|
+
for (const gy of guideYs) {
|
|
193
|
+
const dist = Math.abs(my - gy);
|
|
194
|
+
if (dist < bestDistY) {
|
|
195
|
+
bestDistY = dist;
|
|
196
|
+
snapY = { offset: gy - my, y: gy, extendX1, extendX2 };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
let dx = 0;
|
|
203
|
+
let dy = 0;
|
|
204
|
+
if (snapX && !activeSnapX) {
|
|
205
|
+
dx = snapX.offset;
|
|
206
|
+
drawGuide(snapX.x, snapX.extendY1, snapX.x, snapX.extendY2);
|
|
207
|
+
if (mouseX !== void 0) {
|
|
208
|
+
activeSnapX = { guideValue: snapX.x, mouseAtSnap: mouseX };
|
|
209
|
+
}
|
|
210
|
+
} else if (activeSnapX) {
|
|
211
|
+
drawGuide(activeSnapX.guideValue, extendY1, activeSnapX.guideValue, extendY2);
|
|
212
|
+
}
|
|
213
|
+
if (snapY && !activeSnapY) {
|
|
214
|
+
dy = snapY.offset;
|
|
215
|
+
drawGuide(snapY.extendX1, snapY.y, snapY.extendX2, snapY.y);
|
|
216
|
+
if (mouseY !== void 0) {
|
|
217
|
+
activeSnapY = { guideValue: snapY.y, mouseAtSnap: mouseY };
|
|
218
|
+
}
|
|
219
|
+
} else if (activeSnapY) {
|
|
220
|
+
drawGuide(extendX1, activeSnapY.guideValue, extendX2, activeSnapY.guideValue);
|
|
221
|
+
}
|
|
222
|
+
return { dx, dy };
|
|
223
|
+
}
|
|
224
|
+
function clearSnapGuides() {
|
|
225
|
+
clearGuides();
|
|
226
|
+
activeSnapX = null;
|
|
227
|
+
activeSnapY = null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/tools/arrowTool.js
|
|
231
|
+
function getThemeStroke() {
|
|
232
|
+
if (typeof document === "undefined") return "#fff";
|
|
233
|
+
return document.body && document.body.classList.contains("theme-dark") ? "#fff" : "#1a1a2e";
|
|
234
|
+
}
|
|
235
|
+
var currentArrow = null;
|
|
236
|
+
var isResizing = false;
|
|
237
|
+
var isDragging = false;
|
|
238
|
+
var activeAnchor = null;
|
|
239
|
+
var isDrawingArrow = false;
|
|
240
|
+
var arrowStrokeColor = null;
|
|
241
|
+
var arrowStrokeThickness = 2;
|
|
242
|
+
var arrowOutlineStyle = "solid";
|
|
243
|
+
var arrowCurved = "straight";
|
|
244
|
+
var arrowCurveAmount = 20;
|
|
245
|
+
var arrowHeadStyle = "default";
|
|
246
|
+
var startX;
|
|
247
|
+
var startY;
|
|
248
|
+
var dragOldPosArrow = null;
|
|
249
|
+
var draggedShapeInitialFrameArrow = null;
|
|
250
|
+
var hoveredFrameArrow = null;
|
|
251
|
+
var arrowStrokeColorOptions = document.querySelectorAll(".arrowStrokeSpan");
|
|
252
|
+
var arrowStrokeThicknessValue = document.querySelectorAll(".arrowStrokeThickSpan");
|
|
253
|
+
var arrowOutlineStyleValue = document.querySelectorAll(".arrowOutlineStyle");
|
|
254
|
+
var arrowTypeStyleValue = document.querySelectorAll(".arrowTypeStyle");
|
|
255
|
+
var arrowHeadStyleValue = document.querySelectorAll(".arrowHeadStyleSpan");
|
|
256
|
+
var arrowCurveAmountOptions = document.querySelectorAll(".arrowCurveSpan");
|
|
257
|
+
function getSVGCoordsFromMouse(e) {
|
|
258
|
+
const viewBox = svg.viewBox.baseVal;
|
|
259
|
+
const rect = svg.getBoundingClientRect();
|
|
260
|
+
const mouseX = e.clientX - rect.left;
|
|
261
|
+
const mouseY = e.clientY - rect.top;
|
|
262
|
+
const svgX = viewBox.x + mouseX / rect.width * viewBox.width;
|
|
263
|
+
const svgY = viewBox.y + mouseY / rect.height * viewBox.height;
|
|
264
|
+
return { x: svgX, y: svgY };
|
|
265
|
+
}
|
|
266
|
+
function deleteCurrentShape() {
|
|
267
|
+
if (currentShape && currentShape.shapeName === "arrow") {
|
|
268
|
+
const idx = shapes.indexOf(currentShape);
|
|
269
|
+
if (idx !== -1) shapes.splice(idx, 1);
|
|
270
|
+
if (currentShape.group.parentNode) {
|
|
271
|
+
currentShape.group.parentNode.removeChild(currentShape.group);
|
|
272
|
+
}
|
|
273
|
+
pushDeleteAction(currentShape);
|
|
274
|
+
currentShape = null;
|
|
275
|
+
disableAllSideBars();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
document.addEventListener("keydown", (e) => {
|
|
279
|
+
if (e.key === "Delete" && currentShape && currentShape.shapeName === "arrow") {
|
|
280
|
+
deleteCurrentShape();
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
var handleMouseDown = (e) => {
|
|
284
|
+
if (!isArrowToolActive && !isSelectionToolActive) return;
|
|
285
|
+
const { x, y } = getSVGCoordsFromMouse(e);
|
|
286
|
+
if (isArrowToolActive) {
|
|
287
|
+
isDrawingArrow = true;
|
|
288
|
+
currentArrow = new Arrow({ x, y }, { x, y }, {
|
|
289
|
+
stroke: arrowStrokeColor ?? getThemeStroke(),
|
|
290
|
+
strokeWidth: arrowStrokeThickness,
|
|
291
|
+
arrowOutlineStyle,
|
|
292
|
+
arrowHeadStyle,
|
|
293
|
+
arrowCurved,
|
|
294
|
+
arrowCurveAmount
|
|
295
|
+
});
|
|
296
|
+
shapes.push(currentArrow);
|
|
297
|
+
currentShape = currentArrow;
|
|
298
|
+
} else if (isSelectionToolActive) {
|
|
299
|
+
let clickedOnShape = false;
|
|
300
|
+
let clickedOnAnchor = false;
|
|
301
|
+
if (currentShape && currentShape.shapeName === "arrow" && currentShape.isSelected) {
|
|
302
|
+
const anchorInfo = currentShape.isNearAnchor(x, y);
|
|
303
|
+
if (anchorInfo && anchorInfo.type === "anchor") {
|
|
304
|
+
clickedOnAnchor = true;
|
|
305
|
+
clickedOnShape = true;
|
|
306
|
+
}
|
|
307
|
+
if (currentShape.contains(x, y)) {
|
|
308
|
+
isDragging = true;
|
|
309
|
+
dragOldPosArrow = {
|
|
310
|
+
startPoint: { x: currentShape.startPoint.x, y: currentShape.startPoint.y },
|
|
311
|
+
endPoint: { x: currentShape.endPoint.x, y: currentShape.endPoint.y },
|
|
312
|
+
controlPoint1: currentShape.controlPoint1 ? { x: currentShape.controlPoint1.x, y: currentShape.controlPoint1.y } : null,
|
|
313
|
+
controlPoint2: currentShape.controlPoint2 ? { x: currentShape.controlPoint2.x, y: currentShape.controlPoint2.y } : null,
|
|
314
|
+
parentFrame: currentShape.parentFrame
|
|
315
|
+
// Add this line
|
|
316
|
+
};
|
|
317
|
+
draggedShapeInitialFrameArrow = currentShape.parentFrame || null;
|
|
318
|
+
if (currentShape.parentFrame) {
|
|
319
|
+
currentShape.parentFrame.temporarilyRemoveFromFrame(currentShape);
|
|
320
|
+
}
|
|
321
|
+
startX = x;
|
|
322
|
+
startY = y;
|
|
323
|
+
clickedOnShape = true;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (!clickedOnShape) {
|
|
327
|
+
let shapeToSelect = null;
|
|
328
|
+
for (let i = shapes.length - 1; i >= 0; i--) {
|
|
329
|
+
const shape = shapes[i];
|
|
330
|
+
if (shape instanceof Arrow && shape.contains(x, y)) {
|
|
331
|
+
shapeToSelect = shape;
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (currentShape && currentShape !== shapeToSelect) {
|
|
336
|
+
currentShape.removeSelection();
|
|
337
|
+
currentShape = null;
|
|
338
|
+
}
|
|
339
|
+
if (shapeToSelect) {
|
|
340
|
+
currentShape = shapeToSelect;
|
|
341
|
+
currentShape.selectArrow();
|
|
342
|
+
const anchorInfo = currentShape.isNearAnchor(x, y);
|
|
343
|
+
if (anchorInfo && anchorInfo.type === "anchor") {
|
|
344
|
+
clickedOnAnchor = true;
|
|
345
|
+
} else {
|
|
346
|
+
isDragging = true;
|
|
347
|
+
dragOldPosArrow = {
|
|
348
|
+
startPoint: { x: currentShape.startPoint.x, y: currentShape.startPoint.y },
|
|
349
|
+
endPoint: { x: currentShape.endPoint.x, y: currentShape.endPoint.y },
|
|
350
|
+
controlPoint1: currentShape.controlPoint1 ? { x: currentShape.controlPoint1.x, y: currentShape.controlPoint1.y } : null,
|
|
351
|
+
controlPoint2: currentShape.controlPoint2 ? { x: currentShape.controlPoint2.x, y: currentShape.controlPoint2.y } : null
|
|
352
|
+
};
|
|
353
|
+
startX = x;
|
|
354
|
+
startY = y;
|
|
355
|
+
}
|
|
356
|
+
clickedOnShape = true;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (!clickedOnShape && !clickedOnAnchor && currentShape) {
|
|
360
|
+
currentShape.removeSelection();
|
|
361
|
+
currentShape = null;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
var handleMouseMove = (e) => {
|
|
366
|
+
const { x, y } = getSVGCoordsFromMouse(e);
|
|
367
|
+
if (isDrawingArrow && currentArrow) {
|
|
368
|
+
let endX = x, endY = y;
|
|
369
|
+
if (e.shiftKey) {
|
|
370
|
+
const dx = x - currentArrow.startPoint.x;
|
|
371
|
+
const dy = y - currentArrow.startPoint.y;
|
|
372
|
+
const angle = Math.atan2(dy, dx);
|
|
373
|
+
const snapAngle = Math.round(angle / (Math.PI / 4)) * (Math.PI / 4);
|
|
374
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
375
|
+
endX = currentArrow.startPoint.x + dist * Math.cos(snapAngle);
|
|
376
|
+
endY = currentArrow.startPoint.y + dist * Math.sin(snapAngle);
|
|
377
|
+
}
|
|
378
|
+
currentArrow.endPoint = { x: endX, y: endY };
|
|
379
|
+
const nearbyShape = Arrow.findNearbyShape({ x: endX, y: endY });
|
|
380
|
+
if (nearbyShape) {
|
|
381
|
+
currentArrow.endPoint = nearbyShape.attachment.point;
|
|
382
|
+
svg.style.cursor = "crosshair";
|
|
383
|
+
const existingPreview = svg.querySelector(".attachment-preview");
|
|
384
|
+
if (existingPreview) existingPreview.remove();
|
|
385
|
+
const preview = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
386
|
+
preview.setAttribute("cx", nearbyShape.attachment.point.x);
|
|
387
|
+
preview.setAttribute("cy", nearbyShape.attachment.point.y);
|
|
388
|
+
preview.setAttribute("r", 6);
|
|
389
|
+
preview.setAttribute("fill", "none");
|
|
390
|
+
preview.setAttribute("stroke", "#5B57D1");
|
|
391
|
+
preview.setAttribute("stroke-width", 2);
|
|
392
|
+
preview.setAttribute("class", "attachment-preview");
|
|
393
|
+
preview.setAttribute("opacity", "0.7");
|
|
394
|
+
svg.appendChild(preview);
|
|
395
|
+
} else {
|
|
396
|
+
const existingPreview = svg.querySelector(".attachment-preview");
|
|
397
|
+
if (existingPreview) existingPreview.remove();
|
|
398
|
+
}
|
|
399
|
+
shapes.forEach((frame) => {
|
|
400
|
+
if (frame.shapeName === "frame") {
|
|
401
|
+
if (frame.isShapeInFrame(currentArrow)) {
|
|
402
|
+
frame.highlightFrame();
|
|
403
|
+
hoveredFrameArrow = frame;
|
|
404
|
+
} else if (hoveredFrameArrow === frame) {
|
|
405
|
+
frame.removeHighlight();
|
|
406
|
+
hoveredFrameArrow = null;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
if (currentArrow.arrowCurved) {
|
|
411
|
+
currentArrow.initializeCurveControlPoints();
|
|
412
|
+
}
|
|
413
|
+
currentArrow.draw();
|
|
414
|
+
} else if (isDragging && currentShape && currentShape.isSelected) {
|
|
415
|
+
const dx = x - startX;
|
|
416
|
+
const dy = y - startY;
|
|
417
|
+
currentShape.move(dx, dy);
|
|
418
|
+
startX = x;
|
|
419
|
+
startY = y;
|
|
420
|
+
let newHover = null;
|
|
421
|
+
for (const f of shapes) {
|
|
422
|
+
if (f.shapeName !== "frame") continue;
|
|
423
|
+
if (f === currentShape) continue;
|
|
424
|
+
if (typeof f.isShapeInFrame === "function" && f.isShapeInFrame(currentShape)) {
|
|
425
|
+
newHover = f;
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (hoveredFrameArrow && hoveredFrameArrow !== newHover && typeof hoveredFrameArrow.removeHighlight === "function") {
|
|
430
|
+
hoveredFrameArrow.removeHighlight();
|
|
431
|
+
}
|
|
432
|
+
if (newHover && newHover !== hoveredFrameArrow && typeof newHover.highlightFrame === "function") {
|
|
433
|
+
newHover.highlightFrame();
|
|
434
|
+
}
|
|
435
|
+
hoveredFrameArrow = newHover;
|
|
436
|
+
if (window.__sketchStoreApi && window.__sketchStoreApi.getState().snapToObjects) {
|
|
437
|
+
const snap = calculateSnap(currentShape, e.shiftKey, e.clientX, e.clientY);
|
|
438
|
+
if (snap.dx || snap.dy) {
|
|
439
|
+
currentShape.move(snap.dx, snap.dy);
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
clearSnapGuides();
|
|
443
|
+
}
|
|
444
|
+
svg.style.cursor = "grabbing";
|
|
445
|
+
} else if (isSelectionToolActive && currentShape && currentShape.isSelected) {
|
|
446
|
+
const anchorInfo = currentShape.isNearAnchor(x, y);
|
|
447
|
+
if (anchorInfo) {
|
|
448
|
+
svg.style.cursor = "grab";
|
|
449
|
+
} else if (currentShape.contains(x, y)) {
|
|
450
|
+
svg.style.cursor = "move";
|
|
451
|
+
} else {
|
|
452
|
+
svg.style.cursor = "default";
|
|
453
|
+
}
|
|
454
|
+
} else if (isSelectionToolActive) {
|
|
455
|
+
let hoveringOverArrow = false;
|
|
456
|
+
for (let i = shapes.length - 1; i >= 0; i--) {
|
|
457
|
+
const shape = shapes[i];
|
|
458
|
+
if (shape instanceof Arrow && shape.contains(x, y)) {
|
|
459
|
+
hoveringOverArrow = true;
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
svg.style.cursor = hoveringOverArrow ? "pointer" : "default";
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
var handleMouseUp = (e) => {
|
|
467
|
+
if (isDrawingArrow && currentArrow) {
|
|
468
|
+
const existingPreview = svg.querySelector(".attachment-preview");
|
|
469
|
+
if (existingPreview) existingPreview.remove();
|
|
470
|
+
const dx = currentArrow.endPoint.x - currentArrow.startPoint.x;
|
|
471
|
+
const dy = currentArrow.endPoint.y - currentArrow.startPoint.y;
|
|
472
|
+
const lengthSq = dx * dx + dy * dy;
|
|
473
|
+
if (lengthSq < (5 / currentZoom) ** 2) {
|
|
474
|
+
shapes.pop();
|
|
475
|
+
if (currentArrow.group.parentNode) {
|
|
476
|
+
currentArrow.group.parentNode.removeChild(currentArrow.group);
|
|
477
|
+
}
|
|
478
|
+
currentArrow = null;
|
|
479
|
+
currentShape = null;
|
|
480
|
+
} else {
|
|
481
|
+
const startAttachment = Arrow.findNearbyShape(currentArrow.startPoint);
|
|
482
|
+
const endAttachment = Arrow.findNearbyShape(currentArrow.endPoint);
|
|
483
|
+
if (startAttachment) {
|
|
484
|
+
currentArrow.attachToShape(true, startAttachment.shape, startAttachment.attachment);
|
|
485
|
+
}
|
|
486
|
+
if (endAttachment) {
|
|
487
|
+
currentArrow.attachToShape(false, endAttachment.shape, endAttachment.attachment);
|
|
488
|
+
}
|
|
489
|
+
const finalFrame = hoveredFrameArrow;
|
|
490
|
+
if (finalFrame) {
|
|
491
|
+
finalFrame.addShapeToFrame(currentArrow);
|
|
492
|
+
pushFrameAttachmentAction(finalFrame, currentArrow, "attach", null);
|
|
493
|
+
}
|
|
494
|
+
pushCreateAction(currentArrow);
|
|
495
|
+
const drawnArrow = currentArrow;
|
|
496
|
+
if (window.__sketchStoreApi) window.__sketchStoreApi.setActiveTool("select", { afterDraw: true });
|
|
497
|
+
currentShape = drawnArrow;
|
|
498
|
+
drawnArrow.selectArrow();
|
|
499
|
+
}
|
|
500
|
+
if (hoveredFrameArrow) {
|
|
501
|
+
hoveredFrameArrow.removeHighlight();
|
|
502
|
+
hoveredFrameArrow = null;
|
|
503
|
+
}
|
|
504
|
+
currentArrow = null;
|
|
505
|
+
}
|
|
506
|
+
if (isDragging && dragOldPosArrow && currentShape) {
|
|
507
|
+
const newPos = {
|
|
508
|
+
startPoint: { x: currentShape.startPoint.x, y: currentShape.startPoint.y },
|
|
509
|
+
endPoint: { x: currentShape.endPoint.x, y: currentShape.endPoint.y },
|
|
510
|
+
parentFrame: hoveredFrameArrow || null
|
|
511
|
+
};
|
|
512
|
+
const oldPos = {
|
|
513
|
+
...dragOldPosArrow,
|
|
514
|
+
parentFrame: draggedShapeInitialFrameArrow
|
|
515
|
+
// Add this line
|
|
516
|
+
};
|
|
517
|
+
const stateChanged = dragOldPosArrow.startPoint.x !== newPos.startPoint.x || dragOldPosArrow.startPoint.y !== newPos.startPoint.y || dragOldPosArrow.endPoint.x !== newPos.endPoint.x || dragOldPosArrow.endPoint.y !== newPos.endPoint.y;
|
|
518
|
+
const frameChanged = oldPos.parentFrame !== newPos.parentFrame;
|
|
519
|
+
if (stateChanged || frameChanged) {
|
|
520
|
+
pushTransformAction(currentShape, oldPos, newPos);
|
|
521
|
+
}
|
|
522
|
+
if (isDragging) {
|
|
523
|
+
const finalFrame = hoveredFrameArrow;
|
|
524
|
+
if (draggedShapeInitialFrameArrow !== finalFrame) {
|
|
525
|
+
if (draggedShapeInitialFrameArrow) {
|
|
526
|
+
draggedShapeInitialFrameArrow.removeShapeFromFrame(currentShape);
|
|
527
|
+
}
|
|
528
|
+
if (finalFrame) {
|
|
529
|
+
finalFrame.addShapeToFrame(currentShape);
|
|
530
|
+
}
|
|
531
|
+
if (frameChanged) {
|
|
532
|
+
pushFrameAttachmentAction(
|
|
533
|
+
finalFrame || draggedShapeInitialFrameArrow,
|
|
534
|
+
currentShape,
|
|
535
|
+
finalFrame ? "attach" : "detach",
|
|
536
|
+
draggedShapeInitialFrameArrow
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
} else if (draggedShapeInitialFrameArrow) {
|
|
540
|
+
draggedShapeInitialFrameArrow.restoreToFrame(currentShape);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
draggedShapeInitialFrameArrow = null;
|
|
544
|
+
dragOldPosArrow = null;
|
|
545
|
+
}
|
|
546
|
+
if (hoveredFrameArrow) {
|
|
547
|
+
hoveredFrameArrow.removeHighlight();
|
|
548
|
+
hoveredFrameArrow = null;
|
|
549
|
+
}
|
|
550
|
+
clearSnapGuides();
|
|
551
|
+
isDrawingArrow = false;
|
|
552
|
+
isResizing = false;
|
|
553
|
+
isDragging = false;
|
|
554
|
+
activeAnchor = null;
|
|
555
|
+
svg.style.cursor = "default";
|
|
556
|
+
};
|
|
557
|
+
svg.removeEventListener("pointerdown", handleMouseDown);
|
|
558
|
+
svg.removeEventListener("pointermove", handleMouseMove);
|
|
559
|
+
svg.removeEventListener("pointerup", handleMouseUp);
|
|
560
|
+
var updateSelectedArrowStyle = (styleChanges) => {
|
|
561
|
+
if (currentShape instanceof Arrow && currentShape.isSelected) {
|
|
562
|
+
const oldOptions = {
|
|
563
|
+
...currentShape.options,
|
|
564
|
+
arrowOutlineStyle: currentShape.arrowOutlineStyle,
|
|
565
|
+
arrowHeadStyle: currentShape.arrowHeadStyle,
|
|
566
|
+
arrowCurved: currentShape.arrowCurved,
|
|
567
|
+
arrowCurveAmount: currentShape.arrowCurveAmount
|
|
568
|
+
};
|
|
569
|
+
currentShape.updateStyle(styleChanges);
|
|
570
|
+
pushOptionsChangeAction(currentShape, oldOptions);
|
|
571
|
+
} else {
|
|
572
|
+
if (styleChanges.stroke !== void 0) arrowStrokeColor = styleChanges.stroke;
|
|
573
|
+
if (styleChanges.strokeWidth !== void 0) arrowStrokeThickness = styleChanges.strokeWidth;
|
|
574
|
+
if (styleChanges.arrowOutlineStyle !== void 0) arrowOutlineStyle = styleChanges.arrowOutlineStyle;
|
|
575
|
+
if (styleChanges.arrowHeadStyle !== void 0) arrowHeadStyle = styleChanges.arrowHeadStyle;
|
|
576
|
+
if (styleChanges.arrowCurved !== void 0) arrowCurved = styleChanges.arrowCurved;
|
|
577
|
+
if (styleChanges.arrowCurveAmount !== void 0) arrowCurveAmount = styleChanges.arrowCurveAmount;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
arrowStrokeColorOptions.forEach((span) => {
|
|
581
|
+
span.addEventListener("click", (event) => {
|
|
582
|
+
event.stopPropagation();
|
|
583
|
+
arrowStrokeColorOptions.forEach((el) => el.classList.remove("selected"));
|
|
584
|
+
span.classList.add("selected");
|
|
585
|
+
const newColor = span.getAttribute("data-id");
|
|
586
|
+
updateSelectedArrowStyle({ stroke: newColor });
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
arrowStrokeThicknessValue.forEach((span) => {
|
|
590
|
+
span.addEventListener("click", (event) => {
|
|
591
|
+
event.stopPropagation();
|
|
592
|
+
arrowStrokeThicknessValue.forEach((el) => el.classList.remove("selected"));
|
|
593
|
+
span.classList.add("selected");
|
|
594
|
+
const newThickness = parseInt(span.getAttribute("data-id"));
|
|
595
|
+
updateSelectedArrowStyle({ strokeWidth: newThickness });
|
|
596
|
+
});
|
|
597
|
+
});
|
|
598
|
+
arrowOutlineStyleValue.forEach((span) => {
|
|
599
|
+
span.addEventListener("click", (event) => {
|
|
600
|
+
event.stopPropagation();
|
|
601
|
+
arrowOutlineStyleValue.forEach((el) => el.classList.remove("selected"));
|
|
602
|
+
span.classList.add("selected");
|
|
603
|
+
const newStyle = span.getAttribute("data-id");
|
|
604
|
+
updateSelectedArrowStyle({ arrowOutlineStyle: newStyle });
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
arrowTypeStyleValue.forEach((span) => {
|
|
608
|
+
span.addEventListener("click", (event) => {
|
|
609
|
+
event.stopPropagation();
|
|
610
|
+
arrowTypeStyleValue.forEach((el) => el.classList.remove("selected"));
|
|
611
|
+
span.classList.add("selected");
|
|
612
|
+
updateSelectedArrowStyle({ arrowCurved: span.getAttribute("data-id") });
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
arrowCurveAmountOptions.forEach((span) => {
|
|
616
|
+
span.addEventListener("click", (event) => {
|
|
617
|
+
event.stopPropagation();
|
|
618
|
+
arrowCurveAmountOptions.forEach((el) => el.classList.remove("selected"));
|
|
619
|
+
span.classList.add("selected");
|
|
620
|
+
updateSelectedArrowStyle({ arrowCurveAmount: parseInt(span.getAttribute("data-id")) });
|
|
621
|
+
});
|
|
622
|
+
});
|
|
623
|
+
arrowHeadStyleValue.forEach((span) => {
|
|
624
|
+
span.addEventListener("click", (event) => {
|
|
625
|
+
event.stopPropagation();
|
|
626
|
+
arrowHeadStyleValue.forEach((el) => el.classList.remove("selected"));
|
|
627
|
+
span.classList.add("selected");
|
|
628
|
+
const newHeadStyle = span.getAttribute("data-id");
|
|
629
|
+
updateSelectedArrowStyle({ arrowHeadStyle: newHeadStyle });
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
function detachSelectedArrow() {
|
|
633
|
+
if (currentShape instanceof Arrow && currentShape.isSelected) {
|
|
634
|
+
if (currentShape.attachedToStart || currentShape.attachedToEnd) {
|
|
635
|
+
const oldState = {
|
|
636
|
+
attachedToStart: currentShape.attachedToStart,
|
|
637
|
+
attachedToEnd: currentShape.attachedToEnd,
|
|
638
|
+
startPoint: { ...currentShape.startPoint },
|
|
639
|
+
endPoint: { ...currentShape.endPoint }
|
|
640
|
+
};
|
|
641
|
+
currentShape.detachFromShape(true);
|
|
642
|
+
currentShape.detachFromShape(false);
|
|
643
|
+
currentShape.draw();
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function updateAttachedArrows(shape) {
|
|
648
|
+
if (!shape) return;
|
|
649
|
+
let targetShape = shape;
|
|
650
|
+
if (shape.nodeType) {
|
|
651
|
+
targetShape = shapes.find((s) => s.group === shape || s.element === shape) || shape;
|
|
652
|
+
}
|
|
653
|
+
shapes.forEach((arrowShape) => {
|
|
654
|
+
if (arrowShape instanceof Arrow) {
|
|
655
|
+
let needsUpdate = false;
|
|
656
|
+
if (arrowShape.attachedToStart && arrowShape.attachedToStart.shape === targetShape) {
|
|
657
|
+
needsUpdate = true;
|
|
658
|
+
}
|
|
659
|
+
if (arrowShape.attachedToEnd && arrowShape.attachedToEnd.shape === targetShape) {
|
|
660
|
+
needsUpdate = true;
|
|
661
|
+
}
|
|
662
|
+
if (needsUpdate) {
|
|
663
|
+
arrowShape.updateAttachments();
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
function cleanupAttachments(deletedShape) {
|
|
669
|
+
if (!deletedShape) return;
|
|
670
|
+
let targetShape = deletedShape;
|
|
671
|
+
if (deletedShape.nodeType) {
|
|
672
|
+
targetShape = shapes.find((s) => s.group === deletedShape || s.element === deletedShape) || deletedShape;
|
|
673
|
+
}
|
|
674
|
+
shapes.forEach((shape) => {
|
|
675
|
+
if (shape instanceof Arrow) {
|
|
676
|
+
let needsDraw = false;
|
|
677
|
+
if (shape.attachedToStart && shape.attachedToStart.shape === targetShape) {
|
|
678
|
+
shape.detachFromShape(true);
|
|
679
|
+
needsDraw = true;
|
|
680
|
+
}
|
|
681
|
+
if (shape.attachedToEnd && shape.attachedToEnd.shape === targetShape) {
|
|
682
|
+
shape.detachFromShape(false);
|
|
683
|
+
needsDraw = true;
|
|
684
|
+
}
|
|
685
|
+
if (needsDraw) {
|
|
686
|
+
shape.draw();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
document.addEventListener("keydown", (e) => {
|
|
692
|
+
if (e.key.toLowerCase() === "d" && e.ctrlKey) {
|
|
693
|
+
e.preventDefault();
|
|
694
|
+
detachSelectedArrow();
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
window.arrowToolSettings = {
|
|
698
|
+
get strokeColor() {
|
|
699
|
+
return arrowStrokeColor;
|
|
700
|
+
},
|
|
701
|
+
set strokeColor(v) {
|
|
702
|
+
arrowStrokeColor = v;
|
|
703
|
+
},
|
|
704
|
+
get strokeWidth() {
|
|
705
|
+
return arrowStrokeThickness;
|
|
706
|
+
},
|
|
707
|
+
set strokeWidth(v) {
|
|
708
|
+
arrowStrokeThickness = v;
|
|
709
|
+
},
|
|
710
|
+
get outlineStyle() {
|
|
711
|
+
return arrowOutlineStyle;
|
|
712
|
+
},
|
|
713
|
+
set outlineStyle(v) {
|
|
714
|
+
arrowOutlineStyle = v;
|
|
715
|
+
},
|
|
716
|
+
get headStyle() {
|
|
717
|
+
return arrowHeadStyle;
|
|
718
|
+
},
|
|
719
|
+
set headStyle(v) {
|
|
720
|
+
arrowHeadStyle = v;
|
|
721
|
+
},
|
|
722
|
+
get arrowCurved() {
|
|
723
|
+
return arrowCurved;
|
|
724
|
+
},
|
|
725
|
+
set arrowCurved(v) {
|
|
726
|
+
arrowCurved = v;
|
|
727
|
+
},
|
|
728
|
+
get curveAmount() {
|
|
729
|
+
return arrowCurveAmount;
|
|
730
|
+
},
|
|
731
|
+
set curveAmount(v) {
|
|
732
|
+
arrowCurveAmount = v;
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
window.updateSelectedArrowStyle = updateSelectedArrowStyle;
|
|
736
|
+
window.cleanupAttachments = cleanupAttachments;
|
|
737
|
+
|
|
738
|
+
export {
|
|
739
|
+
calculateSnap,
|
|
740
|
+
clearSnapGuides,
|
|
741
|
+
handleMouseDown,
|
|
742
|
+
handleMouseMove,
|
|
743
|
+
handleMouseUp,
|
|
744
|
+
updateAttachedArrows,
|
|
745
|
+
cleanupAttachments
|
|
746
|
+
};
|
|
747
|
+
//# sourceMappingURL=chunk-BZE4CEBG.js.map
|