@elixpo/lixsketch 5.4.7 → 5.5.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.
Files changed (218) hide show
  1. package/dist/react/AIRenderer-M4LMJ66J.js +1105 -0
  2. package/dist/react/AIRenderer-M4LMJ66J.js.map +7 -0
  3. package/dist/react/Arrow-BJDAXPMH.js +8 -0
  4. package/dist/react/Arrow-BJDAXPMH.js.map +7 -0
  5. package/dist/react/Circle-KPG7TKIX.js +8 -0
  6. package/dist/react/Circle-KPG7TKIX.js.map +7 -0
  7. package/dist/react/CodeShape-K4DIZAIV.js +8 -0
  8. package/dist/react/CodeShape-K4DIZAIV.js.map +7 -0
  9. package/dist/react/CopyPaste-4CKJRHJ3.js +569 -0
  10. package/dist/react/CopyPaste-4CKJRHJ3.js.map +7 -0
  11. package/dist/react/EraserTrail-PA6IQLQN.js +20 -0
  12. package/dist/react/EraserTrail-PA6IQLQN.js.map +7 -0
  13. package/dist/react/EventDispatcher-SRFH6LQZ.js +463 -0
  14. package/dist/react/EventDispatcher-SRFH6LQZ.js.map +7 -0
  15. package/dist/react/Frame-6UR5XPAX.js +10 -0
  16. package/dist/react/Frame-6UR5XPAX.js.map +7 -0
  17. package/dist/react/FreehandStroke-CK24NUT3.js +8 -0
  18. package/dist/react/FreehandStroke-CK24NUT3.js.map +7 -0
  19. package/dist/react/GraphEngine-QE5B2PMR.js +340 -0
  20. package/dist/react/GraphEngine-QE5B2PMR.js.map +7 -0
  21. package/dist/react/GraphMathParser-2WMTY4IE.js +10 -0
  22. package/dist/react/GraphMathParser-2WMTY4IE.js.map +7 -0
  23. package/dist/react/IconShape-KMIA6T2H.js +10 -0
  24. package/dist/react/IconShape-KMIA6T2H.js.map +7 -0
  25. package/dist/react/ImageShape-CHHGBXUQ.js +10 -0
  26. package/dist/react/ImageShape-CHHGBXUQ.js.map +7 -0
  27. package/dist/react/LayerOrder-XCHF4MSS.js +66 -0
  28. package/dist/react/LayerOrder-XCHF4MSS.js.map +7 -0
  29. package/dist/react/Line-2KOQEEGA.js +10 -0
  30. package/dist/react/Line-2KOQEEGA.js.map +7 -0
  31. package/dist/react/LixScriptParser-JYWJX375.js +1033 -0
  32. package/dist/react/LixScriptParser-JYWJX375.js.map +7 -0
  33. package/dist/react/MermaidFlowchartRenderer-4QBAZ5MB.js +412 -0
  34. package/dist/react/MermaidFlowchartRenderer-4QBAZ5MB.js.map +7 -0
  35. package/dist/react/MermaidSequenceParser-UKG2NSZY.js +8 -0
  36. package/dist/react/MermaidSequenceParser-UKG2NSZY.js.map +7 -0
  37. package/dist/react/MermaidSequenceRenderer-HPLHY5II.js +387 -0
  38. package/dist/react/MermaidSequenceRenderer-HPLHY5II.js.map +7 -0
  39. package/dist/react/Rectangle-6FE7RN6W.js +8 -0
  40. package/dist/react/Rectangle-6FE7RN6W.js.map +7 -0
  41. package/dist/react/ResizeCode-WAMDTKSW.js +2 -0
  42. package/dist/react/ResizeCode-WAMDTKSW.js.map +7 -0
  43. package/dist/react/ResizeShapes-LKEQTITP.js +250 -0
  44. package/dist/react/ResizeShapes-LKEQTITP.js.map +7 -0
  45. package/dist/react/SceneSerializer-4U4B24JM.js +739 -0
  46. package/dist/react/SceneSerializer-4U4B24JM.js.map +7 -0
  47. package/dist/react/Selection-VVUHY5YJ.js +34 -0
  48. package/dist/react/Selection-VVUHY5YJ.js.map +7 -0
  49. package/dist/react/SketchEngine-YA4RG3KX.js +413 -0
  50. package/dist/react/SketchEngine-YA4RG3KX.js.map +7 -0
  51. package/dist/react/TextShape-54ZJ66E3.js +8 -0
  52. package/dist/react/TextShape-54ZJ66E3.js.map +7 -0
  53. package/dist/react/UndoRedo-M2JZUBKN.js +30 -0
  54. package/dist/react/UndoRedo-M2JZUBKN.js.map +7 -0
  55. package/dist/react/ZoomPan-U3TXC5AJ.js +186 -0
  56. package/dist/react/ZoomPan-U3TXC5AJ.js.map +7 -0
  57. package/dist/react/arrowTool-CWEMIRXK.js +17 -0
  58. package/dist/react/arrowTool-CWEMIRXK.js.map +7 -0
  59. package/dist/react/boxicons-5JNJQPUP.woff +0 -0
  60. package/dist/react/boxicons-6NVWQSCQ.eot +0 -0
  61. package/dist/react/boxicons-AQ5N6WP7.woff2 +0 -0
  62. package/dist/react/boxicons-GDR4JU3X.ttf +0 -0
  63. package/dist/react/boxicons-NNFHLMOR.svg +1660 -0
  64. package/dist/react/chunk-2OQXI7QB.js +564 -0
  65. package/dist/react/chunk-2OQXI7QB.js.map +7 -0
  66. package/dist/react/chunk-5OUBTHHO.js +187 -0
  67. package/dist/react/chunk-5OUBTHHO.js.map +7 -0
  68. package/dist/react/chunk-6PFXZKL2.js +628 -0
  69. package/dist/react/chunk-6PFXZKL2.js.map +7 -0
  70. package/dist/react/chunk-6SFNWGGZ.js +453 -0
  71. package/dist/react/chunk-6SFNWGGZ.js.map +7 -0
  72. package/dist/react/chunk-7TZSIR6V.js +210 -0
  73. package/dist/react/chunk-7TZSIR6V.js.map +7 -0
  74. package/dist/react/chunk-AJAZC37E.js +662 -0
  75. package/dist/react/chunk-AJAZC37E.js.map +7 -0
  76. package/dist/react/chunk-BU4D2WYQ.js +1213 -0
  77. package/dist/react/chunk-BU4D2WYQ.js.map +7 -0
  78. package/dist/react/chunk-BZE4CEBG.js +747 -0
  79. package/dist/react/chunk-BZE4CEBG.js.map +7 -0
  80. package/dist/react/chunk-CB2RANCB.js +212 -0
  81. package/dist/react/chunk-CB2RANCB.js.map +7 -0
  82. package/dist/react/chunk-DNAG7ML6.js +128 -0
  83. package/dist/react/chunk-DNAG7ML6.js.map +7 -0
  84. package/dist/react/chunk-HZWLPXFN.js +198 -0
  85. package/dist/react/chunk-HZWLPXFN.js.map +7 -0
  86. package/dist/react/chunk-I6HCCIXB.js +572 -0
  87. package/dist/react/chunk-I6HCCIXB.js.map +7 -0
  88. package/dist/react/chunk-IZ5OGWGW.js +235 -0
  89. package/dist/react/chunk-IZ5OGWGW.js.map +7 -0
  90. package/dist/react/chunk-JJCJNLNN.js +1490 -0
  91. package/dist/react/chunk-JJCJNLNN.js.map +7 -0
  92. package/dist/react/chunk-JQ3IRFDP.js +222 -0
  93. package/dist/react/chunk-JQ3IRFDP.js.map +7 -0
  94. package/dist/react/chunk-L5OARZJ7.js +1134 -0
  95. package/dist/react/chunk-L5OARZJ7.js.map +7 -0
  96. package/dist/react/chunk-LHRTXNVE.js +1600 -0
  97. package/dist/react/chunk-LHRTXNVE.js.map +7 -0
  98. package/dist/react/chunk-Q2GA4MBZ.js +1653 -0
  99. package/dist/react/chunk-Q2GA4MBZ.js.map +7 -0
  100. package/dist/react/chunk-QNSE5BAY.js +519 -0
  101. package/dist/react/chunk-QNSE5BAY.js.map +7 -0
  102. package/dist/react/chunk-QXFBG7OM.js +191 -0
  103. package/dist/react/chunk-QXFBG7OM.js.map +7 -0
  104. package/dist/react/chunk-T6ZVV5ZO.js +714 -0
  105. package/dist/react/chunk-T6ZVV5ZO.js.map +7 -0
  106. package/dist/react/chunk-URB6MY46.js +974 -0
  107. package/dist/react/chunk-URB6MY46.js.map +7 -0
  108. package/dist/react/chunk-VN62KLOC.js +931 -0
  109. package/dist/react/chunk-VN62KLOC.js.map +7 -0
  110. package/dist/react/chunk-VQVEPJSA.js +158 -0
  111. package/dist/react/chunk-VQVEPJSA.js.map +7 -0
  112. package/dist/react/chunk-XISEAGBV.js +1632 -0
  113. package/dist/react/chunk-XISEAGBV.js.map +7 -0
  114. package/dist/react/chunk-YKJUBFHE.js +575 -0
  115. package/dist/react/chunk-YKJUBFHE.js.map +7 -0
  116. package/dist/react/circleTool-NUATSEI2.js +14 -0
  117. package/dist/react/circleTool-NUATSEI2.js.map +7 -0
  118. package/dist/react/codeTool-MHCB2FNB.js +38 -0
  119. package/dist/react/codeTool-MHCB2FNB.js.map +7 -0
  120. package/dist/react/eraserTool-2GS2LQCS.js +103 -0
  121. package/dist/react/eraserTool-2GS2LQCS.js.map +7 -0
  122. package/dist/react/frameTool-PWVKKXSP.js +14 -0
  123. package/dist/react/frameTool-PWVKKXSP.js.map +7 -0
  124. package/dist/react/freehandTool-SLYGASVP.js +14 -0
  125. package/dist/react/freehandTool-SLYGASVP.js.map +7 -0
  126. package/dist/react/iconTool-GPZ7O7NH.js +18 -0
  127. package/dist/react/iconTool-GPZ7O7NH.js.map +7 -0
  128. package/dist/react/imageTool-D5R4XGEU.js +15 -0
  129. package/dist/react/imageTool-D5R4XGEU.js.map +7 -0
  130. package/dist/react/index.js +5342 -0
  131. package/dist/react/index.js.map +7 -0
  132. package/dist/react/laserTool-XVMV63AV.js +239 -0
  133. package/dist/react/laserTool-XVMV63AV.js.map +7 -0
  134. package/dist/react/lineTool-WNI5EMZ5.js +14 -0
  135. package/dist/react/lineTool-WNI5EMZ5.js.map +7 -0
  136. package/dist/react/lixCode-OJMVUXXI.ttf +0 -0
  137. package/dist/react/lixDefault-JEAPAUJL.ttf +0 -0
  138. package/dist/react/lixFancy-BPXYM5CQ.ttf +0 -0
  139. package/dist/react/lixFont-CPKEUDVM.woff2 +0 -0
  140. package/dist/react/rectangleTool-U7DZ6ZTA.js +14 -0
  141. package/dist/react/rectangleTool-U7DZ6ZTA.js.map +7 -0
  142. package/dist/react/styles.css +6627 -0
  143. package/dist/react/textTool-M7S6F3VC.js +21 -0
  144. package/dist/react/textTool-M7S6F3VC.js.map +7 -0
  145. package/package.json +39 -5
  146. package/src/EngineShortcuts.js +83 -27
  147. package/src/core/AIRenderer.js +30 -18
  148. package/src/core/GraphEngine.js +64 -41
  149. package/src/core/MermaidFlowchartRenderer.js +153 -88
  150. package/src/core/MermaidSequenceRenderer.js +168 -93
  151. package/src/core/SceneSerializer.js +86 -2
  152. package/src/core/Selection.js +119 -19
  153. package/src/core/UndoRedo.js +82 -15
  154. package/src/core/ZoomPan.js +15 -5
  155. package/src/index.js +14 -1
  156. package/src/react/LixSketchCanvas.jsx +347 -0
  157. package/src/react/components/AppMenu.jsx +475 -0
  158. package/src/react/components/Footer.jsx +85 -0
  159. package/src/react/components/Toolbar.jsx +140 -0
  160. package/src/react/components/canvas/CanvasLoadingOverlay.jsx +76 -0
  161. package/src/react/components/canvas/ContextMenu.jsx +466 -0
  162. package/src/react/components/canvas/FindBar.jsx +177 -0
  163. package/src/react/components/canvas/ImageSourcePicker.jsx +133 -0
  164. package/src/react/components/canvas/MultiSelectActions.jsx +120 -0
  165. package/src/react/components/canvas/SVGCanvas.jsx +145 -0
  166. package/src/react/components/canvas/SaveStatusIndicator.jsx +29 -0
  167. package/src/react/components/modals/CanvasPropertiesModal.jsx +358 -0
  168. package/src/react/components/modals/CommandPalette.jsx +307 -0
  169. package/src/react/components/modals/ExportImageModal.jsx +287 -0
  170. package/src/react/components/modals/GraphModal.jsx +174 -0
  171. package/src/react/components/modals/HelpModal.jsx +208 -0
  172. package/src/react/components/modals/LixScriptModal.jsx +130 -0
  173. package/src/react/components/modals/ShortcutsModal.jsx +125 -0
  174. package/src/react/components/sidebars/ArrowSidebar.jsx +173 -0
  175. package/src/react/components/sidebars/CircleSidebar.jsx +134 -0
  176. package/src/react/components/sidebars/FrameSidebar.jsx +263 -0
  177. package/src/react/components/sidebars/IconSidebar.jsx +279 -0
  178. package/src/react/components/sidebars/ImageSidebar.jsx +69 -0
  179. package/src/react/components/sidebars/LineSidebar.jsx +109 -0
  180. package/src/react/components/sidebars/PaintbrushSidebar.jsx +119 -0
  181. package/src/react/components/sidebars/RectangleSidebar.jsx +165 -0
  182. package/src/react/components/sidebars/ShapeSidebar.jsx +130 -0
  183. package/src/react/components/sidebars/TextSidebar.jsx +174 -0
  184. package/src/react/hooks/inertStores.js +58 -0
  185. package/src/react/hooks/useSketchEngine.js +76 -0
  186. package/src/react/hooks/useTranslation.js +92 -0
  187. package/src/react/index.js +41 -0
  188. package/src/react/store/useSketchStore.js +234 -0
  189. package/src/react/store/useUIStore.js +196 -0
  190. package/src/react/styles/arrowSidebar.css +263 -0
  191. package/src/react/styles/canvasStroke.css +47 -0
  192. package/src/react/styles/canvasTools.css +769 -0
  193. package/src/react/styles/circleSidebar.css +206 -0
  194. package/src/react/styles/fonts/fonts.css +29 -0
  195. package/src/react/styles/fonts/lixCode.ttf +0 -0
  196. package/src/react/styles/fonts/lixDefault.ttf +0 -0
  197. package/src/react/styles/fonts/lixDocs.ttf +0 -0
  198. package/src/react/styles/fonts/lixFancy.ttf +0 -0
  199. package/src/react/styles/fonts/lixFont.woff2 +0 -0
  200. package/src/react/styles/lineSidebar.css +207 -0
  201. package/src/react/styles/paintbrushSidebar.css +247 -0
  202. package/src/react/styles/squareSidebar.css +206 -0
  203. package/src/react/styles/writeText.css +149 -0
  204. package/src/react/styles.css +175 -0
  205. package/src/react/toolsEnum.js +20 -0
  206. package/src/react/utils/toast.js +18 -0
  207. package/src/shapes/Frame.js +7 -1
  208. package/src/shapes/Line.js +11 -5
  209. package/src/tools/arrowTool.js +30 -4
  210. package/src/tools/circleTool.js +33 -9
  211. package/src/tools/codeTool.js +5 -3
  212. package/src/tools/frameTool.js +47 -7
  213. package/src/tools/freehandTool.js +12 -4
  214. package/src/tools/iconTool.js +7 -1
  215. package/src/tools/imageTool.js +7 -1
  216. package/src/tools/lineTool.js +27 -3
  217. package/src/tools/rectangleTool.js +45 -8
  218. package/src/tools/textTool.js +23 -6
@@ -0,0 +1,1134 @@
1
+ "use client";
2
+
3
+ // src/core/UndoRedo.js
4
+ var undoStack = [];
5
+ var redoStack = [];
6
+ var selectedElement = null;
7
+ var updateSelectionFeedback = null;
8
+ var svg = null;
9
+ function setTextReferences(element, updateFn, svgElement) {
10
+ selectedElement = element;
11
+ updateSelectionFeedback = updateFn;
12
+ svg = svgElement;
13
+ }
14
+ function getCurrentSelectedElement() {
15
+ return selectedElement;
16
+ }
17
+ function updateSelectedElement(element) {
18
+ selectedElement = element;
19
+ }
20
+ function pushCreateAction(shape) {
21
+ undoStack.push({
22
+ type: "create",
23
+ shape
24
+ });
25
+ redoStack.length = 0;
26
+ }
27
+ function pushDeleteAction(shape, meta = null) {
28
+ const action = { type: "delete", shape };
29
+ if (meta && meta.childSnapshot) action.childSnapshot = meta.childSnapshot;
30
+ undoStack.push(action);
31
+ redoStack.length = 0;
32
+ }
33
+ function pushDeleteActionWithAttachments(shape) {
34
+ let affectedArrows = [];
35
+ if (shape.type === "text" || shape.shapeName === "text") {
36
+ affectedArrows = shapes.filter((s) => s.shapeName === "arrow" && (s.attachedToStart?.shape === shape || s.attachedToEnd?.shape === shape)).map((arrow) => ({
37
+ arrow,
38
+ oldAttachments: arrow.getAttachmentState(),
39
+ oldPoints: {
40
+ startPoint: { ...arrow.startPoint },
41
+ endPoint: { ...arrow.endPoint }
42
+ }
43
+ }));
44
+ }
45
+ undoStack.push({
46
+ type: "delete",
47
+ shape,
48
+ affectedArrows
49
+ });
50
+ redoStack.length = 0;
51
+ }
52
+ function pushFrameAttachmentAction(frame, shape, action, oldFrame = null) {
53
+ undoStack.push({
54
+ type: "frameAttachment",
55
+ frame,
56
+ shape,
57
+ action,
58
+ // 'attach' or 'detach'
59
+ oldFrame,
60
+ // Previous frame if shape was moved between frames
61
+ // Store shape position for potential restoration
62
+ shapeState: {
63
+ x: shape.x,
64
+ y: shape.y,
65
+ width: shape.width || 0,
66
+ height: shape.height || 0,
67
+ rotation: shape.rotation || 0
68
+ }
69
+ });
70
+ redoStack.length = 0;
71
+ }
72
+ function pushCreateActionWithAttachments(shape) {
73
+ undoStack.push({
74
+ type: "create",
75
+ shape,
76
+ // Store any arrows that might need to reattach when this is undone
77
+ potentialAttachments: []
78
+ });
79
+ redoStack.length = 0;
80
+ }
81
+ function pushTransformAction(shape, oldPos, newPos) {
82
+ if (shape.shapeName === "frame") {
83
+ const containedShapesStates = shape.containedShapes.map((containedShape) => ({
84
+ shape: containedShape,
85
+ oldState: {
86
+ x: containedShape.x - (newPos.x - oldPos.x),
87
+ y: containedShape.y - (newPos.y - oldPos.y),
88
+ width: containedShape.width || 0,
89
+ height: containedShape.height || 0,
90
+ rotation: containedShape.rotation || 0
91
+ },
92
+ newState: {
93
+ x: containedShape.x,
94
+ y: containedShape.y,
95
+ width: containedShape.width || 0,
96
+ height: containedShape.height || 0,
97
+ rotation: containedShape.rotation || 0
98
+ }
99
+ }));
100
+ undoStack.push({
101
+ type: "frameTransform",
102
+ shape,
103
+ oldPos: {
104
+ x: oldPos.x,
105
+ y: oldPos.y,
106
+ width: oldPos.width,
107
+ height: oldPos.height,
108
+ rotation: oldPos.rotation,
109
+ frameName: oldPos.frameName || shape.frameName
110
+ },
111
+ newPos: {
112
+ x: newPos.x,
113
+ y: newPos.y,
114
+ width: newPos.width,
115
+ height: newPos.height,
116
+ rotation: newPos.rotation,
117
+ frameName: newPos.frameName || shape.frameName
118
+ },
119
+ containedShapes: containedShapesStates
120
+ });
121
+ } else if (shape.type === "text") {
122
+ const currentFrame = shape.parentFrame || null;
123
+ undoStack.push({
124
+ type: "transform",
125
+ shape,
126
+ oldPos: {
127
+ x: oldPos.x,
128
+ y: oldPos.y,
129
+ rotation: oldPos.rotation,
130
+ fontSize: oldPos.fontSize
131
+ },
132
+ newPos: {
133
+ x: newPos.x,
134
+ y: newPos.y,
135
+ rotation: newPos.rotation,
136
+ fontSize: newPos.fontSize
137
+ },
138
+ // Track frame attachment state
139
+ frameAttachment: {
140
+ oldFrame: oldPos.parentFrame || null,
141
+ newFrame: currentFrame
142
+ },
143
+ // Store affected arrows with their attachment states
144
+ affectedArrows: shapes.filter((s) => s.shapeName === "arrow" && (s.attachedToStart?.shape === shape || s.attachedToEnd?.shape === shape)).map((arrow) => ({
145
+ arrow,
146
+ oldAttachments: arrow.getAttachmentState(),
147
+ oldPoints: {
148
+ startPoint: { ...arrow.startPoint },
149
+ endPoint: { ...arrow.endPoint }
150
+ }
151
+ }))
152
+ });
153
+ } else if (shape.type === "image") {
154
+ const currentFrame = shape.parentFrame || null;
155
+ undoStack.push({
156
+ type: "transform",
157
+ shape,
158
+ oldPos: {
159
+ x: oldPos.x,
160
+ y: oldPos.y,
161
+ width: oldPos.width,
162
+ height: oldPos.height,
163
+ rotation: oldPos.rotation
164
+ },
165
+ newPos: {
166
+ x: newPos.x,
167
+ y: newPos.y,
168
+ width: newPos.width,
169
+ height: newPos.height,
170
+ rotation: newPos.rotation
171
+ },
172
+ // Track frame attachment state
173
+ frameAttachment: {
174
+ oldFrame: oldPos.parentFrame || null,
175
+ newFrame: currentFrame
176
+ },
177
+ // Store affected arrows with their attachment states
178
+ affectedArrows: shapes.filter((s) => s.shapeName === "arrow" && (s.attachedToStart?.shape === shape || s.attachedToEnd?.shape === shape)).map((arrow) => ({
179
+ arrow,
180
+ oldAttachments: arrow.getAttachmentState(),
181
+ oldPoints: {
182
+ startPoint: { ...arrow.startPoint },
183
+ endPoint: { ...arrow.endPoint }
184
+ }
185
+ }))
186
+ });
187
+ } else if (shape.shapeName === "circle") {
188
+ const currentFrame = shape.parentFrame || null;
189
+ undoStack.push({
190
+ type: "transform",
191
+ shape,
192
+ oldPos: {
193
+ x: oldPos.x,
194
+ y: oldPos.y,
195
+ rx: oldPos.rx,
196
+ ry: oldPos.ry,
197
+ rotation: oldPos.rotation
198
+ },
199
+ newPos: {
200
+ x: newPos.x,
201
+ y: newPos.y,
202
+ rx: newPos.rx,
203
+ ry: newPos.ry,
204
+ rotation: newPos.rotation
205
+ },
206
+ // Track frame attachment state
207
+ frameAttachment: {
208
+ oldFrame: oldPos.parentFrame || null,
209
+ newFrame: currentFrame
210
+ },
211
+ // Store affected arrows with their attachment states
212
+ affectedArrows: shapes.filter((s) => s.shapeName === "arrow" && (s.attachedToStart?.shape === shape || s.attachedToEnd?.shape === shape)).map((arrow) => ({
213
+ arrow,
214
+ oldAttachments: arrow.getAttachmentState(),
215
+ oldPoints: {
216
+ startPoint: { ...arrow.startPoint },
217
+ endPoint: { ...arrow.endPoint }
218
+ }
219
+ }))
220
+ });
221
+ } else if (shape.shapeName === "rectangle") {
222
+ const currentFrame = shape.parentFrame || null;
223
+ undoStack.push({
224
+ type: "transform",
225
+ shape,
226
+ oldPos: {
227
+ x: oldPos.x,
228
+ y: oldPos.y,
229
+ width: oldPos.width,
230
+ height: oldPos.height,
231
+ rotation: oldPos.rotation
232
+ },
233
+ newPos: {
234
+ x: newPos.x,
235
+ y: newPos.y,
236
+ width: newPos.width,
237
+ height: newPos.height,
238
+ rotation: newPos.rotation
239
+ },
240
+ // Track frame attachment state
241
+ frameAttachment: {
242
+ oldFrame: oldPos.parentFrame || null,
243
+ newFrame: currentFrame
244
+ },
245
+ // Store affected arrows with their attachment states
246
+ affectedArrows: shapes.filter((s) => s.shapeName === "arrow" && (s.attachedToStart?.shape === shape || s.attachedToEnd?.shape === shape)).map((arrow) => ({
247
+ arrow,
248
+ oldAttachments: arrow.getAttachmentState(),
249
+ oldPoints: {
250
+ startPoint: { ...arrow.startPoint },
251
+ endPoint: { ...arrow.endPoint }
252
+ }
253
+ }))
254
+ });
255
+ } else if (shape.shapeName === "line") {
256
+ const currentFrame = shape.parentFrame || null;
257
+ undoStack.push({
258
+ type: "transform",
259
+ shape,
260
+ oldPos: {
261
+ startPoint: { x: oldPos.startPoint.x, y: oldPos.startPoint.y },
262
+ endPoint: { x: oldPos.endPoint.x, y: oldPos.endPoint.y },
263
+ controlPoint: oldPos.controlPoint ? { x: oldPos.controlPoint.x, y: oldPos.controlPoint.y } : null,
264
+ isCurved: oldPos.isCurved || false
265
+ },
266
+ newPos: {
267
+ startPoint: { x: newPos.startPoint.x, y: newPos.startPoint.y },
268
+ endPoint: { x: newPos.endPoint.x, y: newPos.endPoint.y },
269
+ controlPoint: newPos.controlPoint ? { x: newPos.controlPoint.x, y: newPos.controlPoint.y } : null,
270
+ isCurved: newPos.isCurved || false
271
+ },
272
+ // Track frame attachment state
273
+ frameAttachment: {
274
+ oldFrame: oldPos.parentFrame || null,
275
+ newFrame: currentFrame
276
+ }
277
+ });
278
+ } else if (shape.shapeName === "arrow") {
279
+ undoStack.push({
280
+ type: "transform",
281
+ shape,
282
+ oldPos: {
283
+ startPoint: { x: oldPos.startPoint.x, y: oldPos.startPoint.y },
284
+ endPoint: { x: oldPos.endPoint.x, y: oldPos.endPoint.y },
285
+ controlPoint1: oldPos.controlPoint1 ? { x: oldPos.controlPoint1.x, y: oldPos.controlPoint1.y } : null,
286
+ controlPoint2: oldPos.controlPoint2 ? { x: oldPos.controlPoint2.x, y: oldPos.controlPoint2.y } : null,
287
+ attachments: oldPos.attachments || shape.getAttachmentState()
288
+ },
289
+ newPos: {
290
+ startPoint: { x: newPos.startPoint.x, y: newPos.startPoint.y },
291
+ endPoint: { x: newPos.endPoint.x, y: newPos.endPoint.y },
292
+ controlPoint1: newPos.controlPoint1 ? { x: newPos.controlPoint1.x, y: newPos.controlPoint1.y } : null,
293
+ controlPoint2: newPos.controlPoint2 ? { x: newPos.controlPoint2.x, y: newPos.controlPoint2.y } : null,
294
+ attachments: newPos.attachments || shape.getAttachmentState()
295
+ }
296
+ });
297
+ } else if (shape.type === "icon") {
298
+ const currentFrame = shape.parentFrame || null;
299
+ undoStack.push({
300
+ type: "transform",
301
+ shape,
302
+ oldPos: {
303
+ x: oldPos.x,
304
+ y: oldPos.y,
305
+ width: oldPos.width,
306
+ height: oldPos.height,
307
+ rotation: oldPos.rotation
308
+ },
309
+ newPos: {
310
+ x: newPos.x,
311
+ y: newPos.y,
312
+ width: newPos.width,
313
+ height: newPos.height,
314
+ rotation: newPos.rotation
315
+ },
316
+ // Track frame attachment state
317
+ frameAttachment: {
318
+ oldFrame: oldPos.parentFrame || null,
319
+ newFrame: currentFrame
320
+ },
321
+ // Store affected arrows with their attachment states
322
+ affectedArrows: shapes.filter((s) => s.shapeName === "arrow" && (s.attachedToStart?.shape === shape || s.attachedToEnd?.shape === shape)).map((arrow) => ({
323
+ arrow,
324
+ oldAttachments: arrow.getAttachmentState(),
325
+ oldPoints: {
326
+ startPoint: { ...arrow.startPoint },
327
+ endPoint: { ...arrow.endPoint }
328
+ }
329
+ }))
330
+ });
331
+ } else if (shape.shapeName === "freehandStroke") {
332
+ undoStack.push({
333
+ type: "transform",
334
+ shape,
335
+ oldPos: {
336
+ points: JSON.parse(JSON.stringify(oldPos.points)),
337
+ rotation: oldPos.rotation
338
+ },
339
+ newPos: {
340
+ points: JSON.parse(JSON.stringify(newPos.points)),
341
+ rotation: newPos.rotation
342
+ }
343
+ });
344
+ }
345
+ redoStack.length = 0;
346
+ }
347
+ function pushOptionsChangeAction(shape, oldOptions) {
348
+ undoStack.push({
349
+ type: "optionsChange",
350
+ shape,
351
+ oldOptions
352
+ });
353
+ redoStack.length = 0;
354
+ }
355
+ function refreshSelectionAfterAction() {
356
+ const ms = typeof window !== "undefined" ? window.multiSelection : null;
357
+ if (!ms) return;
358
+ if (typeof ms.updateControls !== "function") return;
359
+ if (!ms.selectedShapes || ms.selectedShapes.size === 0) return;
360
+ try {
361
+ ms.updateControls();
362
+ } catch (err) {
363
+ console.warn("[UndoRedo] selection refresh failed:", err);
364
+ }
365
+ }
366
+ function undo() {
367
+ if (undoStack.length === 0) return;
368
+ const action = undoStack.pop();
369
+ try {
370
+ if (action.type === "frameTransform") {
371
+ action.shape.x = action.oldPos.x;
372
+ action.shape.y = action.oldPos.y;
373
+ action.shape.width = action.oldPos.width;
374
+ action.shape.height = action.oldPos.height;
375
+ action.shape.rotation = action.oldPos.rotation;
376
+ action.shape.frameName = action.oldPos.frameName;
377
+ action.containedShapes.forEach((shapeData) => {
378
+ const shape = shapeData.shape;
379
+ shape.x = shapeData.oldState.x;
380
+ shape.y = shapeData.oldState.y;
381
+ shape.width = shapeData.oldState.width;
382
+ shape.height = shapeData.oldState.height;
383
+ shape.rotation = shapeData.oldState.rotation;
384
+ if (typeof shape.draw === "function") {
385
+ shape.draw();
386
+ }
387
+ });
388
+ action.shape.isSelected = false;
389
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
390
+ action.shape.draw();
391
+ action.shape.updateClipPath();
392
+ redoStack.push(action);
393
+ return;
394
+ }
395
+ if (action.type === "frameAttachment") {
396
+ if (action.action === "attach") {
397
+ const frameIndex = action.frame.containedShapes.indexOf(action.shape);
398
+ if (frameIndex > -1) {
399
+ action.frame.containedShapes.splice(frameIndex, 1);
400
+ action.shape.parentFrame = null;
401
+ if (action.shape.group && action.shape.group.parentNode === action.frame.clipGroup) {
402
+ action.frame.clipGroup.removeChild(action.shape.group);
403
+ svg.appendChild(action.shape.group);
404
+ }
405
+ }
406
+ if (action.oldFrame) {
407
+ action.oldFrame.containedShapes.push(action.shape);
408
+ action.shape.parentFrame = action.oldFrame;
409
+ if (action.shape.group && action.shape.group.parentNode === svg) {
410
+ svg.removeChild(action.shape.group);
411
+ action.oldFrame.clipGroup.appendChild(action.shape.group);
412
+ }
413
+ }
414
+ } else if (action.action === "detach") {
415
+ if (!action.frame.containedShapes.includes(action.shape)) {
416
+ action.frame.containedShapes.push(action.shape);
417
+ action.shape.parentFrame = action.frame;
418
+ if (action.shape.group && action.shape.group.parentNode === svg) {
419
+ svg.removeChild(action.shape.group);
420
+ action.frame.clipGroup.appendChild(action.shape.group);
421
+ }
422
+ }
423
+ }
424
+ action.shape.x = action.shapeState.x;
425
+ action.shape.y = action.shapeState.y;
426
+ action.shape.width = action.shapeState.width;
427
+ action.shape.height = action.shapeState.height;
428
+ action.shape.rotation = action.shapeState.rotation;
429
+ if (typeof action.shape.draw === "function") {
430
+ action.shape.draw();
431
+ }
432
+ redoStack.push(action);
433
+ return;
434
+ }
435
+ if (action.type === "create" && action.shape.type === "modeConvert") {
436
+ const newShape = action.shape.newShape;
437
+ const newElement = action.shape.newElement;
438
+ const oldShape = action.shape.oldShape;
439
+ const oldElement = action.shape.oldElement;
440
+ if (newElement && newElement.parentNode) {
441
+ newElement.parentNode.removeChild(newElement);
442
+ }
443
+ const newIdx = shapes.indexOf(newShape);
444
+ if (newIdx !== -1) shapes.splice(newIdx, 1);
445
+ if (svg && oldElement) {
446
+ svg.appendChild(oldElement);
447
+ }
448
+ if (oldShape) {
449
+ shapes.push(oldShape);
450
+ }
451
+ redoStack.push(action);
452
+ return;
453
+ }
454
+ if (action.type === "create") {
455
+ if (action.shape.type === "text") {
456
+ if (action.shape.element && action.shape.element.parentNode) {
457
+ action.shape.element.parentNode.removeChild(action.shape.element);
458
+ } else if (action.shape.parentNode) {
459
+ action.shape.parentNode.removeChild(action.shape);
460
+ }
461
+ const idx = shapes.indexOf(action.shape.element || action.shape);
462
+ if (idx !== -1) shapes.splice(idx, 1);
463
+ if (typeof cleanupAttachments === "function") {
464
+ cleanupAttachments(action.shape.element || action.shape);
465
+ }
466
+ } else if (action.shape.type === "image") {
467
+ action.shape.remove();
468
+ } else if (action.shape.type === "icon") {
469
+ action.shape.remove();
470
+ } else {
471
+ const idx = shapes.indexOf(action.shape);
472
+ if (idx !== -1) shapes.splice(idx, 1);
473
+ if (action.shape.group && action.shape.group.parentNode) {
474
+ action.shape.group.parentNode.removeChild(action.shape.group);
475
+ }
476
+ if (action.shape.shapeName === "frame") {
477
+ action.shape.destroy();
478
+ }
479
+ }
480
+ redoStack.push(action);
481
+ return;
482
+ }
483
+ if (action.type === "delete") {
484
+ if (action.shape.type === "text") {
485
+ if (svg) {
486
+ svg.appendChild(action.shape.element || action.shape);
487
+ shapes.push(action.shape.element || action.shape);
488
+ }
489
+ if (action.affectedArrows) {
490
+ action.affectedArrows.forEach((arrowData) => {
491
+ const arrow = arrowData.arrow;
492
+ arrow.restoreAttachmentState(arrowData.oldAttachments);
493
+ });
494
+ }
495
+ } else if (action.shape.type === "image") {
496
+ action.shape.restore();
497
+ } else {
498
+ shapes.push(action.shape);
499
+ if (svg) {
500
+ svg.appendChild(action.shape.group);
501
+ }
502
+ if (action.shape.shapeName === "frame" && svg) {
503
+ if (action.shape.clipGroup && !action.shape.clipGroup.parentNode) {
504
+ svg.appendChild(action.shape.clipGroup);
505
+ }
506
+ if (action.shape.clipPath && !action.shape.clipPath.parentNode) {
507
+ const defs = svg.querySelector("defs");
508
+ if (defs) defs.appendChild(action.shape.clipPath);
509
+ else svg.insertBefore(action.shape.clipPath, svg.firstChild);
510
+ }
511
+ if (action.childSnapshot && Array.isArray(action.childSnapshot)) {
512
+ for (const child of action.childSnapshot) {
513
+ if (!child) continue;
514
+ if (shapes.indexOf(child) === -1) continue;
515
+ if (typeof action.shape.addShapeToFrame === "function") {
516
+ action.shape.addShapeToFrame(child);
517
+ }
518
+ }
519
+ }
520
+ }
521
+ }
522
+ redoStack.push(action);
523
+ return;
524
+ }
525
+ if (action.type === "transform") {
526
+ if (action.frameAttachment) {
527
+ if (action.frameAttachment.newFrame) {
528
+ const frameIndex = action.frameAttachment.newFrame.containedShapes.indexOf(action.shape);
529
+ if (frameIndex > -1) {
530
+ action.frameAttachment.newFrame.containedShapes.splice(frameIndex, 1);
531
+ if (action.shape.group && action.shape.group.parentNode === action.frameAttachment.newFrame.clipGroup) {
532
+ action.frameAttachment.newFrame.clipGroup.removeChild(action.shape.group);
533
+ svg.appendChild(action.shape.group);
534
+ }
535
+ }
536
+ }
537
+ if (action.frameAttachment.oldFrame) {
538
+ if (!action.frameAttachment.oldFrame.containedShapes.includes(action.shape)) {
539
+ action.frameAttachment.oldFrame.containedShapes.push(action.shape);
540
+ action.shape.parentFrame = action.frameAttachment.oldFrame;
541
+ if (action.shape.group && action.shape.group.parentNode === svg) {
542
+ svg.removeChild(action.shape.group);
543
+ action.frameAttachment.oldFrame.clipGroup.appendChild(action.shape.group);
544
+ }
545
+ }
546
+ } else {
547
+ action.shape.parentFrame = null;
548
+ }
549
+ }
550
+ if (action.shape.type === "text") {
551
+ const textElement = (action.shape.element || action.shape).querySelector("text");
552
+ if (textElement && action.oldPos.fontSize !== void 0) {
553
+ textElement.setAttribute("font-size", action.oldPos.fontSize + "px");
554
+ }
555
+ const centerX = textElement ? textElement.getBBox().x + textElement.getBBox().width / 2 : 0;
556
+ const centerY = textElement ? textElement.getBBox().y + textElement.getBBox().height / 2 : 0;
557
+ (action.shape.element || action.shape).setAttribute(
558
+ "transform",
559
+ `translate(${action.oldPos.x}, ${action.oldPos.y}) rotate(${action.oldPos.rotation}, ${centerX}, ${centerY})`
560
+ );
561
+ (action.shape.element || action.shape).setAttribute("data-x", action.oldPos.x);
562
+ (action.shape.element || action.shape).setAttribute("data-y", action.oldPos.y);
563
+ if (action.affectedArrows) {
564
+ action.affectedArrows.forEach((arrowData) => {
565
+ const arrow = arrowData.arrow;
566
+ arrow.restoreAttachmentState(arrowData.oldAttachments);
567
+ arrowData.newPoints = {
568
+ startPoint: { ...arrow.startPoint },
569
+ endPoint: { ...arrow.endPoint }
570
+ };
571
+ arrowData.newAttachments = arrow.getAttachmentState();
572
+ });
573
+ }
574
+ if (selectedElement === (action.shape.element || action.shape) && updateSelectionFeedback) {
575
+ setTimeout(updateSelectionFeedback, 0);
576
+ }
577
+ } else if (action.shape.type === "image") {
578
+ action.shape.restore(action.oldPos);
579
+ if (action.affectedArrows) {
580
+ action.affectedArrows.forEach((arrowData) => {
581
+ const arrow = arrowData.arrow;
582
+ arrow.restoreAttachmentState(arrowData.oldAttachments);
583
+ arrowData.newPoints = {
584
+ startPoint: { ...arrow.startPoint },
585
+ endPoint: { ...arrow.endPoint }
586
+ };
587
+ arrowData.newAttachments = arrow.getAttachmentState();
588
+ });
589
+ }
590
+ } else if (action.shape.shapeName === "circle") {
591
+ action.shape.x = action.oldPos.x;
592
+ action.shape.y = action.oldPos.y;
593
+ action.shape.rx = action.oldPos.rx;
594
+ action.shape.ry = action.oldPos.ry;
595
+ action.shape.rotation = action.oldPos.rotation;
596
+ action.shape.isSelected = false;
597
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
598
+ action.shape.draw();
599
+ if (action.affectedArrows) {
600
+ action.affectedArrows.forEach((arrowData) => {
601
+ const arrow = arrowData.arrow;
602
+ arrow.restoreAttachmentState(arrowData.oldAttachments);
603
+ arrowData.newPoints = {
604
+ startPoint: { ...arrow.startPoint },
605
+ endPoint: { ...arrow.endPoint }
606
+ };
607
+ arrowData.newAttachments = arrow.getAttachmentState();
608
+ });
609
+ }
610
+ } else if (action.shape.shapeName === "line") {
611
+ action.shape.startPoint = { x: action.oldPos.startPoint.x, y: action.oldPos.startPoint.y };
612
+ action.shape.endPoint = { x: action.oldPos.endPoint.x, y: action.oldPos.endPoint.y };
613
+ action.shape.isCurved = action.oldPos.isCurved || false;
614
+ if (action.oldPos.controlPoint) {
615
+ action.shape.controlPoint = { x: action.oldPos.controlPoint.x, y: action.oldPos.controlPoint.y };
616
+ } else {
617
+ action.shape.controlPoint = null;
618
+ }
619
+ if (action.frameAttachment) {
620
+ if (action.frameAttachment.newFrame) {
621
+ const frameIndex = action.frameAttachment.newFrame.containedShapes.indexOf(action.shape);
622
+ if (frameIndex > -1) {
623
+ action.frameAttachment.newFrame.containedShapes.splice(frameIndex, 1);
624
+ if (action.shape.group && action.shape.group.parentNode === action.frameAttachment.newFrame.clipGroup) {
625
+ action.frameAttachment.newFrame.clipGroup.removeChild(action.shape.group);
626
+ svg.appendChild(action.shape.group);
627
+ }
628
+ }
629
+ }
630
+ if (action.frameAttachment.oldFrame) {
631
+ if (!action.frameAttachment.oldFrame.containedShapes.includes(action.shape)) {
632
+ action.frameAttachment.oldFrame.containedShapes.push(action.shape);
633
+ action.shape.parentFrame = action.frameAttachment.oldFrame;
634
+ if (action.shape.group && action.shape.group.parentNode === svg) {
635
+ svg.removeChild(action.shape.group);
636
+ action.frameAttachment.oldFrame.clipGroup.appendChild(action.shape.group);
637
+ }
638
+ }
639
+ } else {
640
+ action.shape.parentFrame = null;
641
+ }
642
+ }
643
+ action.shape.isSelected = false;
644
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
645
+ action.shape.draw();
646
+ } else if (action.shape.shapeName === "arrow") {
647
+ action.shape.startPoint = { x: action.oldPos.startPoint.x, y: action.oldPos.startPoint.y };
648
+ action.shape.endPoint = { x: action.oldPos.endPoint.x, y: action.oldPos.endPoint.y };
649
+ action.shape.controlPoint1 = action.oldPos.controlPoint1 ? { x: action.oldPos.controlPoint1.x, y: action.oldPos.controlPoint1.y } : null;
650
+ action.shape.controlPoint2 = action.oldPos.controlPoint2 ? { x: action.oldPos.controlPoint2.x, y: action.oldPos.controlPoint2.y } : null;
651
+ if (action.oldPos.attachments) {
652
+ action.shape.restoreAttachmentState(action.oldPos.attachments);
653
+ } else {
654
+ action.shape.attachedToStart = null;
655
+ action.shape.attachedToEnd = null;
656
+ }
657
+ action.shape.isSelected = false;
658
+ action.shape.draw();
659
+ } else if (action.shape.type === "icon") {
660
+ action.shape.restore(action.oldPos);
661
+ if (action.affectedArrows) {
662
+ action.affectedArrows.forEach((arrowData) => {
663
+ const arrow = arrowData.arrow;
664
+ arrow.restoreAttachmentState(arrowData.oldAttachments);
665
+ arrowData.newPoints = {
666
+ startPoint: { ...arrow.startPoint },
667
+ endPoint: { ...arrow.endPoint }
668
+ };
669
+ arrowData.newAttachments = arrow.getAttachmentState();
670
+ });
671
+ }
672
+ } else if (action.shape.shapeName === "freehandStroke") {
673
+ action.shape.points = JSON.parse(JSON.stringify(action.oldPos.points));
674
+ action.shape.rotation = action.oldPos.rotation;
675
+ action.shape.isSelected = false;
676
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
677
+ action.shape.draw();
678
+ } else if (action.shape.shapeName === "rectangle") {
679
+ action.shape.x = action.oldPos.x;
680
+ action.shape.y = action.oldPos.y;
681
+ action.shape.height = action.oldPos.height;
682
+ action.shape.width = action.oldPos.width;
683
+ action.shape.rotation = action.oldPos.rotation;
684
+ action.shape.isSelected = false;
685
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
686
+ action.shape.draw();
687
+ if (action.affectedArrows) {
688
+ action.affectedArrows.forEach((arrowData) => {
689
+ const arrow = arrowData.arrow;
690
+ arrow.restoreAttachmentState(arrowData.oldAttachments);
691
+ arrowData.newPoints = {
692
+ startPoint: { ...arrow.startPoint },
693
+ endPoint: { ...arrow.endPoint }
694
+ };
695
+ arrowData.newAttachments = arrow.getAttachmentState();
696
+ });
697
+ }
698
+ }
699
+ redoStack.push(action);
700
+ return;
701
+ }
702
+ if (action.type === "optionsChange") {
703
+ if (action.shape.type === "text") {
704
+ const textElement = (action.shape.element || action.shape).querySelector("text");
705
+ if (textElement) {
706
+ if (action.oldOptions.color) textElement.setAttribute("fill", action.oldOptions.color);
707
+ if (action.oldOptions.font) textElement.setAttribute("font-family", action.oldOptions.font);
708
+ if (action.oldOptions.size) textElement.setAttribute("font-size", action.oldOptions.size);
709
+ if (action.oldOptions.align) textElement.setAttribute("text-anchor", action.oldOptions.align);
710
+ if (selectedElement === (action.shape.element || action.shape) && updateSelectionFeedback) {
711
+ setTimeout(updateSelectionFeedback, 0);
712
+ }
713
+ }
714
+ } else if (action.shape.shapeName === "arrow") {
715
+ action.shape.options = { ...action.oldOptions };
716
+ action.shape.arrowOutlineStyle = action.oldOptions.arrowOutlineStyle;
717
+ action.shape.arrowHeadStyle = action.oldOptions.arrowHeadStyle;
718
+ action.shape.arrowCurved = action.oldOptions.arrowCurved;
719
+ action.shape.arrowCurveAmount = action.oldOptions.arrowCurveAmount;
720
+ action.shape.draw();
721
+ } else {
722
+ action.shape.options = action.oldOptions;
723
+ action.shape.draw();
724
+ }
725
+ redoStack.push(action);
726
+ return;
727
+ }
728
+ } finally {
729
+ refreshSelectionAfterAction();
730
+ }
731
+ }
732
+ function redo() {
733
+ if (redoStack.length === 0) return;
734
+ const action = redoStack.pop();
735
+ try {
736
+ if (action.type === "frameTransform") {
737
+ action.shape.x = action.newPos.x;
738
+ action.shape.y = action.newPos.y;
739
+ action.shape.width = action.newPos.width;
740
+ action.shape.height = action.newPos.height;
741
+ action.shape.rotation = action.newPos.rotation;
742
+ action.shape.frameName = action.newPos.frameName;
743
+ action.containedShapes.forEach((shapeData) => {
744
+ const shape = shapeData.shape;
745
+ shape.x = shapeData.newState.x;
746
+ shape.y = shapeData.newState.y;
747
+ shape.width = shapeData.newState.width;
748
+ shape.height = shapeData.newState.height;
749
+ shape.rotation = shapeData.newState.rotation;
750
+ if (typeof shape.draw === "function") {
751
+ shape.draw();
752
+ }
753
+ });
754
+ action.shape.isSelected = false;
755
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
756
+ action.shape.draw();
757
+ action.shape.updateClipPath();
758
+ undoStack.push(action);
759
+ return;
760
+ }
761
+ if (action.type === "frameAttachment") {
762
+ if (action.action === "attach") {
763
+ if (action.oldFrame) {
764
+ const oldFrameIndex = action.oldFrame.containedShapes.indexOf(action.shape);
765
+ if (oldFrameIndex > -1) {
766
+ action.oldFrame.containedShapes.splice(oldFrameIndex, 1);
767
+ if (action.shape.group && action.shape.group.parentNode === action.oldFrame.clipGroup) {
768
+ action.oldFrame.clipGroup.removeChild(action.shape.group);
769
+ svg.appendChild(action.shape.group);
770
+ }
771
+ }
772
+ }
773
+ if (!action.frame.containedShapes.includes(action.shape)) {
774
+ action.frame.containedShapes.push(action.shape);
775
+ action.shape.parentFrame = action.frame;
776
+ if (action.shape.group && action.shape.group.parentNode === svg) {
777
+ svg.removeChild(action.shape.group);
778
+ action.frame.clipGroup.appendChild(action.shape.group);
779
+ }
780
+ }
781
+ } else if (action.action === "detach") {
782
+ const frameIndex = action.frame.containedShapes.indexOf(action.shape);
783
+ if (frameIndex > -1) {
784
+ action.frame.containedShapes.splice(frameIndex, 1);
785
+ action.shape.parentFrame = null;
786
+ if (action.shape.group && action.shape.group.parentNode === action.frame.clipGroup) {
787
+ action.frame.clipGroup.removeChild(action.shape.group);
788
+ svg.appendChild(action.shape.group);
789
+ }
790
+ }
791
+ }
792
+ if (typeof action.shape.draw === "function") {
793
+ action.shape.draw();
794
+ }
795
+ undoStack.push(action);
796
+ return;
797
+ }
798
+ if (action.type === "create" && action.shape.type === "modeConvert") {
799
+ const newShape = action.shape.newShape;
800
+ const newElement = action.shape.newElement;
801
+ const oldShape = action.shape.oldShape;
802
+ const oldElement = action.shape.oldElement;
803
+ if (oldElement && oldElement.parentNode) {
804
+ oldElement.parentNode.removeChild(oldElement);
805
+ }
806
+ const oldIdx = shapes.indexOf(oldShape);
807
+ if (oldIdx !== -1) shapes.splice(oldIdx, 1);
808
+ if (svg && newElement) {
809
+ svg.appendChild(newElement);
810
+ }
811
+ if (newShape) {
812
+ shapes.push(newShape);
813
+ }
814
+ undoStack.push(action);
815
+ return;
816
+ }
817
+ if (action.type === "create") {
818
+ if (action.shape.type === "text") {
819
+ if (svg) {
820
+ svg.appendChild(action.shape.element || action.shape);
821
+ shapes.push(action.shape.element || action.shape);
822
+ }
823
+ } else if (action.shape.type === "image") {
824
+ action.shape.restore();
825
+ } else if (action.shape.type === "icon") {
826
+ if (svg && action.shape.group) {
827
+ svg.appendChild(action.shape.group);
828
+ }
829
+ if (shapes.indexOf(action.shape) === -1) {
830
+ shapes.push(action.shape);
831
+ }
832
+ } else {
833
+ shapes.push(action.shape);
834
+ if (svg) {
835
+ svg.appendChild(action.shape.group);
836
+ }
837
+ }
838
+ undoStack.push(action);
839
+ return;
840
+ }
841
+ if (action.type === "delete") {
842
+ if (action.shape.type === "text") {
843
+ if ((action.shape.element || action.shape).parentNode) {
844
+ (action.shape.element || action.shape).parentNode.removeChild(action.shape.element || action.shape);
845
+ }
846
+ const idx = shapes.indexOf(action.shape.element || action.shape);
847
+ if (idx !== -1) shapes.splice(idx, 1);
848
+ if (action.affectedArrows) {
849
+ action.affectedArrows.forEach((arrowData) => {
850
+ const arrow = arrowData.arrow;
851
+ if (arrow.attachedToStart && arrow.attachedToStart.shape === (action.shape.element || action.shape)) {
852
+ arrow.detachFromShape(true);
853
+ }
854
+ if (arrow.attachedToEnd && arrow.attachedToEnd.shape === (action.shape.element || action.shape)) {
855
+ arrow.detachFromShape(false);
856
+ }
857
+ arrow.draw();
858
+ });
859
+ }
860
+ } else if (action.shape.type === "image") {
861
+ action.shape.remove();
862
+ } else {
863
+ const idx = shapes.indexOf(action.shape);
864
+ if (idx !== -1) shapes.splice(idx, 1);
865
+ if (action.shape.shapeName === "frame" && !action.shape._diagramType && action.childSnapshot) {
866
+ for (const child of action.childSnapshot) {
867
+ if (!child) continue;
868
+ const el = child.group || child.element;
869
+ if (el && svg) {
870
+ if (action.shape.clipGroup && el.parentNode === action.shape.clipGroup) {
871
+ action.shape.clipGroup.removeChild(el);
872
+ }
873
+ if (el.parentNode !== svg) svg.appendChild(el);
874
+ }
875
+ child.parentFrame = null;
876
+ delete child.isBeingMovedByFrame;
877
+ }
878
+ action.shape.containedShapes = [];
879
+ if (action.shape.group && action.shape.group.parentNode) action.shape.group.parentNode.removeChild(action.shape.group);
880
+ if (action.shape.clipGroup && action.shape.clipGroup.parentNode) action.shape.clipGroup.parentNode.removeChild(action.shape.clipGroup);
881
+ if (action.shape.clipPath && action.shape.clipPath.parentNode) action.shape.clipPath.parentNode.removeChild(action.shape.clipPath);
882
+ } else {
883
+ if (action.shape.group && action.shape.group.parentNode) {
884
+ action.shape.group.parentNode.removeChild(action.shape.group);
885
+ }
886
+ if (action.shape.shapeName === "frame" && typeof action.shape.destroy === "function") {
887
+ action.shape.destroy();
888
+ }
889
+ }
890
+ }
891
+ undoStack.push(action);
892
+ return;
893
+ }
894
+ if (action.type === "transform") {
895
+ if (action.frameAttachment) {
896
+ if (action.frameAttachment.oldFrame) {
897
+ const oldFrameIndex = action.frameAttachment.oldFrame.containedShapes.indexOf(action.shape);
898
+ if (oldFrameIndex > -1) {
899
+ action.frameAttachment.oldFrame.containedShapes.splice(oldFrameIndex, 1);
900
+ if (action.shape.group && action.shape.group.parentNode === action.frameAttachment.oldFrame.clipGroup) {
901
+ action.frameAttachment.oldFrame.clipGroup.removeChild(action.shape.group);
902
+ svg.appendChild(action.shape.group);
903
+ }
904
+ }
905
+ }
906
+ if (action.frameAttachment.newFrame) {
907
+ if (!action.frameAttachment.newFrame.containedShapes.includes(action.shape)) {
908
+ action.frameAttachment.newFrame.containedShapes.push(action.shape);
909
+ action.shape.parentFrame = action.frameAttachment.newFrame;
910
+ if (action.shape.group && action.shape.group.parentNode === svg) {
911
+ svg.removeChild(action.shape.group);
912
+ action.frameAttachment.newFrame.clipGroup.appendChild(action.shape.group);
913
+ }
914
+ }
915
+ } else {
916
+ action.shape.parentFrame = null;
917
+ }
918
+ }
919
+ if (action.shape.type === "text") {
920
+ const textElement = (action.shape.element || action.shape).querySelector("text");
921
+ if (textElement && action.newPos.fontSize !== void 0) {
922
+ textElement.setAttribute("font-size", action.newPos.fontSize + "px");
923
+ }
924
+ const centerX = textElement ? textElement.getBBox().x + textElement.getBBox().width / 2 : 0;
925
+ const centerY = textElement ? textElement.getBBox().y + textElement.getBBox().height / 2 : 0;
926
+ (action.shape.element || action.shape).setAttribute(
927
+ "transform",
928
+ `translate(${action.newPos.x}, ${action.newPos.y}) rotate(${action.newPos.rotation}, ${centerX}, ${centerY})`
929
+ );
930
+ (action.shape.element || action.shape).setAttribute("data-x", action.newPos.x);
931
+ (action.shape.element || action.shape).setAttribute("data-y", action.newPos.y);
932
+ if (action.affectedArrows) {
933
+ action.affectedArrows.forEach((arrowData) => {
934
+ const arrow = arrowData.arrow;
935
+ if (arrowData.newAttachments) {
936
+ arrow.restoreAttachmentState(arrowData.newAttachments);
937
+ } else {
938
+ arrow.updateAttachments();
939
+ }
940
+ });
941
+ }
942
+ if (selectedElement === (action.shape.element || action.shape) && updateSelectionFeedback) {
943
+ setTimeout(updateSelectionFeedback, 0);
944
+ }
945
+ } else if (action.shape.type === "image") {
946
+ action.shape.restore(action.newPos);
947
+ if (action.affectedArrows) {
948
+ action.affectedArrows.forEach((arrowData) => {
949
+ const arrow = arrowData.arrow;
950
+ if (arrowData.newAttachments) {
951
+ arrow.restoreAttachmentState(arrowData.newAttachments);
952
+ } else {
953
+ arrow.updateAttachments();
954
+ }
955
+ });
956
+ }
957
+ } else if (action.shape.shapeName === "circle") {
958
+ action.shape.x = action.newPos.x;
959
+ action.shape.y = action.newPos.y;
960
+ action.shape.rx = action.newPos.rx;
961
+ action.shape.ry = action.newPos.ry;
962
+ action.shape.rotation = action.newPos.rotation;
963
+ action.shape.isSelected = false;
964
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
965
+ action.shape.draw();
966
+ if (action.affectedArrows) {
967
+ action.affectedArrows.forEach((arrowData) => {
968
+ const arrow = arrowData.arrow;
969
+ if (arrowData.newAttachments) {
970
+ arrow.restoreAttachmentState(arrowData.newAttachments);
971
+ } else {
972
+ arrow.updateAttachments();
973
+ }
974
+ });
975
+ }
976
+ } else if (action.shape.shapeName === "line") {
977
+ action.shape.startPoint = { x: action.newPos.startPoint.x, y: action.newPos.startPoint.y };
978
+ action.shape.endPoint = { x: action.newPos.endPoint.x, y: action.newPos.endPoint.y };
979
+ action.shape.isCurved = action.newPos.isCurved || false;
980
+ if (action.newPos.controlPoint) {
981
+ action.shape.controlPoint = { x: action.newPos.controlPoint.x, y: action.newPos.controlPoint.y };
982
+ } else {
983
+ action.shape.controlPoint = null;
984
+ }
985
+ if (action.frameAttachment) {
986
+ if (action.frameAttachment.oldFrame) {
987
+ const oldFrameIndex = action.frameAttachment.oldFrame.containedShapes.indexOf(action.shape);
988
+ if (oldFrameIndex > -1) {
989
+ action.frameAttachment.oldFrame.containedShapes.splice(oldFrameIndex, 1);
990
+ if (action.shape.group && action.shape.group.parentNode === action.frameAttachment.oldFrame.clipGroup) {
991
+ action.frameAttachment.oldFrame.clipGroup.removeChild(action.shape.group);
992
+ svg.appendChild(action.shape.group);
993
+ }
994
+ }
995
+ }
996
+ if (action.frameAttachment.newFrame) {
997
+ if (!action.frameAttachment.newFrame.containedShapes.includes(action.shape)) {
998
+ action.frameAttachment.newFrame.containedShapes.push(action.shape);
999
+ action.shape.parentFrame = action.frameAttachment.newFrame;
1000
+ if (action.shape.group && action.shape.group.parentNode === svg) {
1001
+ svg.removeChild(action.shape.group);
1002
+ action.frameAttachment.newFrame.clipGroup.appendChild(action.shape.group);
1003
+ }
1004
+ }
1005
+ } else {
1006
+ action.shape.parentFrame = null;
1007
+ }
1008
+ }
1009
+ action.shape.isSelected = false;
1010
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
1011
+ action.shape.draw();
1012
+ } else if (action.shape.shapeName === "arrow") {
1013
+ action.shape.startPoint = { x: action.newPos.startPoint.x, y: action.newPos.startPoint.y };
1014
+ action.shape.endPoint = { x: action.newPos.endPoint.x, y: action.newPos.endPoint.y };
1015
+ action.shape.controlPoint1 = action.newPos.controlPoint1 ? { x: action.newPos.controlPoint1.x, y: action.newPos.controlPoint1.y } : null;
1016
+ action.shape.controlPoint2 = action.newPos.controlPoint2 ? { x: action.newPos.controlPoint2.x, y: action.newPos.controlPoint2.y } : null;
1017
+ if (action.newPos.attachments) {
1018
+ action.shape.restoreAttachmentState(action.newPos.attachments);
1019
+ } else {
1020
+ action.shape.attachedToStart = null;
1021
+ action.shape.attachedToEnd = null;
1022
+ }
1023
+ action.shape.isSelected = false;
1024
+ action.shape.draw();
1025
+ } else if (action.shape.type === "icon") {
1026
+ action.shape.restore(action.newPos);
1027
+ if (action.affectedArrows) {
1028
+ action.affectedArrows.forEach((arrowData) => {
1029
+ const arrow = arrowData.arrow;
1030
+ if (arrowData.newAttachments) {
1031
+ arrow.restoreAttachmentState(arrowData.newAttachments);
1032
+ } else {
1033
+ arrow.updateAttachments();
1034
+ }
1035
+ });
1036
+ }
1037
+ } else if (action.shape.shapeName === "freehandStroke") {
1038
+ action.shape.points = JSON.parse(JSON.stringify(action.newPos.points));
1039
+ action.shape.rotation = action.newPos.rotation;
1040
+ action.shape.isSelected = false;
1041
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
1042
+ action.shape.draw();
1043
+ } else if (action.shape.shapeName === "rectangle") {
1044
+ action.shape.x = action.newPos.x;
1045
+ action.shape.y = action.newPos.y;
1046
+ action.shape.height = action.newPos.height;
1047
+ action.shape.width = action.newPos.width;
1048
+ action.shape.rotation = action.newPos.rotation;
1049
+ action.shape.isSelected = false;
1050
+ if (typeof action.shape.removeSelection === "function") action.shape.removeSelection();
1051
+ action.shape.draw();
1052
+ if (action.affectedArrows) {
1053
+ action.affectedArrows.forEach((arrowData) => {
1054
+ const arrow = arrowData.arrow;
1055
+ if (arrowData.newAttachments) {
1056
+ arrow.restoreAttachmentState(arrowData.newAttachments);
1057
+ } else {
1058
+ arrow.updateAttachments();
1059
+ }
1060
+ });
1061
+ }
1062
+ }
1063
+ undoStack.push(action);
1064
+ return;
1065
+ }
1066
+ if (action.type === "optionsChange") {
1067
+ if (action.shape.type === "text") {
1068
+ const textElement = (action.shape.element || action.shape).querySelector("text");
1069
+ if (textElement) {
1070
+ if (action.newOptions.color) textElement.setAttribute("fill", action.newOptions.color);
1071
+ if (action.newOptions.font) textElement.setAttribute("font-family", action.newOptions.font);
1072
+ if (action.newOptions.size) textElement.setAttribute("font-size", action.newOptions.size);
1073
+ if (action.newOptions.align) textElement.setAttribute("text-anchor", action.newOptions.align);
1074
+ if (selectedElement === (action.shape.element || action.shape) && updateSelectionFeedback) {
1075
+ setTimeout(updateSelectionFeedback, 0);
1076
+ }
1077
+ }
1078
+ } else if (action.shape.shapeName === "arrow") {
1079
+ const currentOptions = {
1080
+ ...action.shape.options,
1081
+ arrowOutlineStyle: action.shape.arrowOutlineStyle,
1082
+ arrowHeadStyle: action.shape.arrowHeadStyle,
1083
+ arrowCurved: action.shape.arrowCurved,
1084
+ arrowCurveAmount: action.shape.arrowCurveAmount
1085
+ };
1086
+ action.newOptions = currentOptions;
1087
+ action.shape.draw();
1088
+ } else {
1089
+ action.newOptions = action.shape.options;
1090
+ action.shape.draw();
1091
+ }
1092
+ undoStack.push(action);
1093
+ return;
1094
+ }
1095
+ } finally {
1096
+ refreshSelectionAfterAction();
1097
+ }
1098
+ }
1099
+ document.addEventListener("keydown", (e) => {
1100
+ if ((e.ctrlKey || e.metaKey) && e.key === "z") {
1101
+ e.preventDefault();
1102
+ undo();
1103
+ }
1104
+ if ((e.ctrlKey || e.metaKey) && (e.key === "y" || e.shiftKey && e.key === "z")) {
1105
+ e.preventDefault();
1106
+ redo();
1107
+ }
1108
+ });
1109
+ document.getElementById("undo")?.addEventListener("click", undo);
1110
+ document.getElementById("redo")?.addEventListener("click", redo);
1111
+ window.pushCreateAction = pushCreateAction;
1112
+ window.pushDeleteAction = pushDeleteAction;
1113
+ window.pushDeleteActionWithAttachments = pushDeleteActionWithAttachments;
1114
+ window.pushTransformAction = pushTransformAction;
1115
+ window.pushOptionsChangeAction = pushOptionsChangeAction;
1116
+ window.pushCreateActionWithAttachments = pushCreateActionWithAttachments;
1117
+ window.undo = undo;
1118
+ window.redo = redo;
1119
+
1120
+ export {
1121
+ setTextReferences,
1122
+ getCurrentSelectedElement,
1123
+ updateSelectedElement,
1124
+ pushCreateAction,
1125
+ pushDeleteAction,
1126
+ pushDeleteActionWithAttachments,
1127
+ pushFrameAttachmentAction,
1128
+ pushCreateActionWithAttachments,
1129
+ pushTransformAction,
1130
+ pushOptionsChangeAction,
1131
+ undo,
1132
+ redo
1133
+ };
1134
+ //# sourceMappingURL=chunk-L5OARZJ7.js.map