@zenode/designer 3.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 (529) hide show
  1. package/APIs.md +60 -0
  2. package/LICENSE +12 -0
  3. package/README.md +219 -0
  4. package/dist/components/canvas/canvas.cjs +106 -0
  5. package/dist/components/canvas/canvas.cjs.map +1 -0
  6. package/dist/components/canvas/canvas.d.ts +15 -0
  7. package/dist/components/canvas/canvas.js +84 -0
  8. package/dist/components/canvas/canvas.js.map +1 -0
  9. package/dist/components/canvas/grid.cjs +167 -0
  10. package/dist/components/canvas/grid.cjs.map +1 -0
  11. package/dist/components/canvas/grid.d.ts +5 -0
  12. package/dist/components/canvas/grid.js +144 -0
  13. package/dist/components/canvas/grid.js.map +1 -0
  14. package/dist/components/shapeTypes/circle.d.ts +2 -0
  15. package/dist/components/shapeTypes/rectangle.d.ts +4 -0
  16. package/dist/components/shapeTypes/rectangle.js +22 -0
  17. package/dist/components/shapeTypes/rectangle.js.map +1 -0
  18. package/dist/components/shapeTypes/rhombus.d.ts +1 -0
  19. package/dist/config/defaultConfig.cjs +542 -0
  20. package/dist/config/defaultConfig.cjs.map +1 -0
  21. package/dist/config/defaultConfig.d.ts +2 -0
  22. package/dist/config/defaultConfig.js +540 -0
  23. package/dist/config/defaultConfig.js.map +1 -0
  24. package/dist/config/testConfig.cjs +553 -0
  25. package/dist/config/testConfig.cjs.map +1 -0
  26. package/dist/config/testConfig.d.ts +2 -0
  27. package/dist/config/testConfig.js +551 -0
  28. package/dist/config/testConfig.js.map +1 -0
  29. package/dist/config/testConfig1.d.ts +2 -0
  30. package/dist/config/testXML.cjs +17 -0
  31. package/dist/config/testXML.cjs.map +1 -0
  32. package/dist/config/testXML.d.ts +1 -0
  33. package/dist/config/testXML.js +15 -0
  34. package/dist/config/testXML.js.map +1 -0
  35. package/dist/connections/paths/curved.cjs +34 -0
  36. package/dist/connections/paths/curved.cjs.map +1 -0
  37. package/dist/connections/paths/curved.d.ts +2 -0
  38. package/dist/connections/paths/curved.js +32 -0
  39. package/dist/connections/paths/curved.js.map +1 -0
  40. package/dist/connections/paths/index.cjs +16 -0
  41. package/dist/connections/paths/index.cjs.map +1 -0
  42. package/dist/connections/paths/index.d.ts +12 -0
  43. package/dist/connections/paths/index.js +14 -0
  44. package/dist/connections/paths/index.js.map +1 -0
  45. package/dist/connections/paths/l-bent.cjs +59 -0
  46. package/dist/connections/paths/l-bent.cjs.map +1 -0
  47. package/dist/connections/paths/l-bent.d.ts +5 -0
  48. package/dist/connections/paths/l-bent.js +57 -0
  49. package/dist/connections/paths/l-bent.js.map +1 -0
  50. package/dist/connections/paths/s-shaped.cjs +24 -0
  51. package/dist/connections/paths/s-shaped.cjs.map +1 -0
  52. package/dist/connections/paths/s-shaped.d.ts +5 -0
  53. package/dist/connections/paths/s-shaped.js +22 -0
  54. package/dist/connections/paths/s-shaped.js.map +1 -0
  55. package/dist/connections/paths/straight.cjs +9 -0
  56. package/dist/connections/paths/straight.cjs.map +1 -0
  57. package/dist/connections/paths/straight.d.ts +2 -0
  58. package/dist/connections/paths/straight.js +7 -0
  59. package/dist/connections/paths/straight.js.map +1 -0
  60. package/dist/connections/render.cjs +382 -0
  61. package/dist/connections/render.cjs.map +1 -0
  62. package/dist/connections/render.d.ts +29 -0
  63. package/dist/connections/render.js +360 -0
  64. package/dist/connections/render.js.map +1 -0
  65. package/dist/connections/routing/index.d.ts +14 -0
  66. package/dist/connections/routing/smartRouter.cjs +26 -0
  67. package/dist/connections/routing/smartRouter.cjs.map +1 -0
  68. package/dist/connections/routing/smartRouter.d.ts +13 -0
  69. package/dist/connections/routing/smartRouter.js +24 -0
  70. package/dist/connections/routing/smartRouter.js.map +1 -0
  71. package/dist/contextpad/defaults.cjs +181 -0
  72. package/dist/contextpad/defaults.cjs.map +1 -0
  73. package/dist/contextpad/defaults.d.ts +2 -0
  74. package/dist/contextpad/defaults.js +179 -0
  75. package/dist/contextpad/defaults.js.map +1 -0
  76. package/dist/contextpad/registry.cjs +54 -0
  77. package/dist/contextpad/registry.cjs.map +1 -0
  78. package/dist/contextpad/registry.d.ts +21 -0
  79. package/dist/contextpad/registry.js +52 -0
  80. package/dist/contextpad/registry.js.map +1 -0
  81. package/dist/contextpad/renderer.cjs +347 -0
  82. package/dist/contextpad/renderer.cjs.map +1 -0
  83. package/dist/contextpad/renderer.d.ts +32 -0
  84. package/dist/contextpad/renderer.js +326 -0
  85. package/dist/contextpad/renderer.js.map +1 -0
  86. package/dist/core/engine.cjs +2254 -0
  87. package/dist/core/engine.cjs.map +1 -0
  88. package/dist/core/engine.d.ts +444 -0
  89. package/dist/core/engine.js +2233 -0
  90. package/dist/core/engine.js.map +1 -0
  91. package/dist/core/eventManager.cjs +29 -0
  92. package/dist/core/eventManager.cjs.map +1 -0
  93. package/dist/core/eventManager.d.ts +6 -0
  94. package/dist/core/eventManager.js +27 -0
  95. package/dist/core/eventManager.js.map +1 -0
  96. package/dist/core/history/command.cjs +182 -0
  97. package/dist/core/history/command.cjs.map +1 -0
  98. package/dist/core/history/command.d.ts +119 -0
  99. package/dist/core/history/command.js +171 -0
  100. package/dist/core/history/command.js.map +1 -0
  101. package/dist/core/history/undoManager.cjs +54 -0
  102. package/dist/core/history/undoManager.cjs.map +1 -0
  103. package/dist/core/history/undoManager.d.ts +18 -0
  104. package/dist/core/history/undoManager.js +52 -0
  105. package/dist/core/history/undoManager.js.map +1 -0
  106. package/dist/core/license.cjs +36 -0
  107. package/dist/core/license.cjs.map +1 -0
  108. package/dist/core/license.d.ts +16 -0
  109. package/dist/core/license.js +34 -0
  110. package/dist/core/license.js.map +1 -0
  111. package/dist/core/samples.cjs +68 -0
  112. package/dist/core/samples.cjs.map +1 -0
  113. package/dist/core/samples.d.ts +6 -0
  114. package/dist/core/samples.js +66 -0
  115. package/dist/core/samples.js.map +1 -0
  116. package/dist/core/serialization.cjs +123 -0
  117. package/dist/core/serialization.cjs.map +1 -0
  118. package/dist/core/serialization.d.ts +26 -0
  119. package/dist/core/serialization.js +121 -0
  120. package/dist/core/serialization.js.map +1 -0
  121. package/dist/core/validation.cjs +92 -0
  122. package/dist/core/validation.cjs.map +1 -0
  123. package/dist/core/validation.d.ts +24 -0
  124. package/dist/core/validation.js +89 -0
  125. package/dist/core/validation.js.map +1 -0
  126. package/dist/core/zoom&PanManager.d.ts +16 -0
  127. package/dist/core/zoom_PanManager.cjs +96 -0
  128. package/dist/core/zoom_PanManager.cjs.map +1 -0
  129. package/dist/core/zoom_PanManager.js +75 -0
  130. package/dist/core/zoom_PanManager.js.map +1 -0
  131. package/dist/effects/engine.cjs +203 -0
  132. package/dist/effects/engine.cjs.map +1 -0
  133. package/dist/effects/engine.d.ts +6 -0
  134. package/dist/effects/engine.js +182 -0
  135. package/dist/effects/engine.js.map +1 -0
  136. package/dist/events/drag.cjs +299 -0
  137. package/dist/events/drag.cjs.map +1 -0
  138. package/dist/events/drag.d.ts +19 -0
  139. package/dist/events/drag.js +278 -0
  140. package/dist/events/drag.js.map +1 -0
  141. package/dist/events/mouseClick.cjs +36 -0
  142. package/dist/events/mouseClick.cjs.map +1 -0
  143. package/dist/events/mouseClick.d.ts +26 -0
  144. package/dist/events/mouseClick.js +34 -0
  145. package/dist/events/mouseClick.js.map +1 -0
  146. package/dist/events/mouseMove.cjs +104 -0
  147. package/dist/events/mouseMove.cjs.map +1 -0
  148. package/dist/events/mouseMove.d.ts +11 -0
  149. package/dist/events/mouseMove.js +82 -0
  150. package/dist/events/mouseMove.js.map +1 -0
  151. package/dist/events/resize.cjs +98 -0
  152. package/dist/events/resize.cjs.map +1 -0
  153. package/dist/events/resize.d.ts +14 -0
  154. package/dist/events/resize.js +77 -0
  155. package/dist/events/resize.js.map +1 -0
  156. package/dist/examples/keyboard-shortcuts.d.ts +10 -0
  157. package/dist/icons.bundle.js +763 -0
  158. package/dist/icons.bundle.js.map +1 -0
  159. package/dist/icons.cjs +105 -0
  160. package/dist/icons.cjs.map +1 -0
  161. package/dist/icons.d.ts +7 -0
  162. package/dist/icons.js +89 -0
  163. package/dist/icons.js.map +1 -0
  164. package/dist/index.cjs +284 -0
  165. package/dist/index.cjs.map +1 -0
  166. package/dist/index.d.ts +160 -0
  167. package/dist/index.js +204 -0
  168. package/dist/index.js.map +1 -0
  169. package/dist/model/configurationModel.d.ts +280 -0
  170. package/dist/model/interface.d.ts +95 -0
  171. package/dist/model/shapeModel.d.ts +28 -0
  172. package/dist/node_modules/lucide/dist/esm/createElement.cjs +36 -0
  173. package/dist/node_modules/lucide/dist/esm/createElement.cjs.map +1 -0
  174. package/dist/node_modules/lucide/dist/esm/createElement.js +34 -0
  175. package/dist/node_modules/lucide/dist/esm/createElement.js.map +1 -0
  176. package/dist/node_modules/lucide/dist/esm/defaultAttributes.cjs +23 -0
  177. package/dist/node_modules/lucide/dist/esm/defaultAttributes.cjs.map +1 -0
  178. package/dist/node_modules/lucide/dist/esm/defaultAttributes.js +21 -0
  179. package/dist/node_modules/lucide/dist/esm/defaultAttributes.js.map +1 -0
  180. package/dist/node_modules/lucide/dist/esm/icons/arrow-down-right.cjs +16 -0
  181. package/dist/node_modules/lucide/dist/esm/icons/arrow-down-right.cjs.map +1 -0
  182. package/dist/node_modules/lucide/dist/esm/icons/arrow-down-right.js +14 -0
  183. package/dist/node_modules/lucide/dist/esm/icons/arrow-down-right.js.map +1 -0
  184. package/dist/node_modules/lucide/dist/esm/icons/arrow-right.cjs +16 -0
  185. package/dist/node_modules/lucide/dist/esm/icons/arrow-right.cjs.map +1 -0
  186. package/dist/node_modules/lucide/dist/esm/icons/arrow-right.js +14 -0
  187. package/dist/node_modules/lucide/dist/esm/icons/arrow-right.js.map +1 -0
  188. package/dist/node_modules/lucide/dist/esm/icons/arrow-up-right.cjs +16 -0
  189. package/dist/node_modules/lucide/dist/esm/icons/arrow-up-right.cjs.map +1 -0
  190. package/dist/node_modules/lucide/dist/esm/icons/arrow-up-right.js +14 -0
  191. package/dist/node_modules/lucide/dist/esm/icons/arrow-up-right.js.map +1 -0
  192. package/dist/node_modules/lucide/dist/esm/icons/box.cjs +22 -0
  193. package/dist/node_modules/lucide/dist/esm/icons/box.cjs.map +1 -0
  194. package/dist/node_modules/lucide/dist/esm/icons/box.js +20 -0
  195. package/dist/node_modules/lucide/dist/esm/icons/box.js.map +1 -0
  196. package/dist/node_modules/lucide/dist/esm/icons/chevron-down.cjs +13 -0
  197. package/dist/node_modules/lucide/dist/esm/icons/chevron-down.cjs.map +1 -0
  198. package/dist/node_modules/lucide/dist/esm/icons/chevron-down.js +11 -0
  199. package/dist/node_modules/lucide/dist/esm/icons/chevron-down.js.map +1 -0
  200. package/dist/node_modules/lucide/dist/esm/icons/chevron-right.cjs +13 -0
  201. package/dist/node_modules/lucide/dist/esm/icons/chevron-right.cjs.map +1 -0
  202. package/dist/node_modules/lucide/dist/esm/icons/chevron-right.js +11 -0
  203. package/dist/node_modules/lucide/dist/esm/icons/chevron-right.js.map +1 -0
  204. package/dist/node_modules/lucide/dist/esm/icons/circle-alert.cjs +17 -0
  205. package/dist/node_modules/lucide/dist/esm/icons/circle-alert.cjs.map +1 -0
  206. package/dist/node_modules/lucide/dist/esm/icons/circle-alert.js +15 -0
  207. package/dist/node_modules/lucide/dist/esm/icons/circle-alert.js.map +1 -0
  208. package/dist/node_modules/lucide/dist/esm/icons/circle-check-big.cjs +16 -0
  209. package/dist/node_modules/lucide/dist/esm/icons/circle-check-big.cjs.map +1 -0
  210. package/dist/node_modules/lucide/dist/esm/icons/circle-check-big.js +14 -0
  211. package/dist/node_modules/lucide/dist/esm/icons/circle-check-big.js.map +1 -0
  212. package/dist/node_modules/lucide/dist/esm/icons/circle-question-mark.cjs +17 -0
  213. package/dist/node_modules/lucide/dist/esm/icons/circle-question-mark.cjs.map +1 -0
  214. package/dist/node_modules/lucide/dist/esm/icons/circle-question-mark.js +15 -0
  215. package/dist/node_modules/lucide/dist/esm/icons/circle-question-mark.js.map +1 -0
  216. package/dist/node_modules/lucide/dist/esm/icons/circle.cjs +13 -0
  217. package/dist/node_modules/lucide/dist/esm/icons/circle.cjs.map +1 -0
  218. package/dist/node_modules/lucide/dist/esm/icons/circle.js +11 -0
  219. package/dist/node_modules/lucide/dist/esm/icons/circle.js.map +1 -0
  220. package/dist/node_modules/lucide/dist/esm/icons/cloud.cjs +13 -0
  221. package/dist/node_modules/lucide/dist/esm/icons/cloud.cjs.map +1 -0
  222. package/dist/node_modules/lucide/dist/esm/icons/cloud.js +11 -0
  223. package/dist/node_modules/lucide/dist/esm/icons/cloud.js.map +1 -0
  224. package/dist/node_modules/lucide/dist/esm/icons/copy.cjs +16 -0
  225. package/dist/node_modules/lucide/dist/esm/icons/copy.cjs.map +1 -0
  226. package/dist/node_modules/lucide/dist/esm/icons/copy.js +14 -0
  227. package/dist/node_modules/lucide/dist/esm/icons/copy.js.map +1 -0
  228. package/dist/node_modules/lucide/dist/esm/icons/database.cjs +17 -0
  229. package/dist/node_modules/lucide/dist/esm/icons/database.cjs.map +1 -0
  230. package/dist/node_modules/lucide/dist/esm/icons/database.js +15 -0
  231. package/dist/node_modules/lucide/dist/esm/icons/database.js.map +1 -0
  232. package/dist/node_modules/lucide/dist/esm/icons/diamond.cjs +20 -0
  233. package/dist/node_modules/lucide/dist/esm/icons/diamond.cjs.map +1 -0
  234. package/dist/node_modules/lucide/dist/esm/icons/diamond.js +18 -0
  235. package/dist/node_modules/lucide/dist/esm/icons/diamond.js.map +1 -0
  236. package/dist/node_modules/lucide/dist/esm/icons/download.cjs +17 -0
  237. package/dist/node_modules/lucide/dist/esm/icons/download.cjs.map +1 -0
  238. package/dist/node_modules/lucide/dist/esm/icons/download.js +15 -0
  239. package/dist/node_modules/lucide/dist/esm/icons/download.js.map +1 -0
  240. package/dist/node_modules/lucide/dist/esm/icons/eye-off.cjs +28 -0
  241. package/dist/node_modules/lucide/dist/esm/icons/eye-off.cjs.map +1 -0
  242. package/dist/node_modules/lucide/dist/esm/icons/eye-off.js +26 -0
  243. package/dist/node_modules/lucide/dist/esm/icons/eye-off.js.map +1 -0
  244. package/dist/node_modules/lucide/dist/esm/icons/eye.cjs +21 -0
  245. package/dist/node_modules/lucide/dist/esm/icons/eye.cjs.map +1 -0
  246. package/dist/node_modules/lucide/dist/esm/icons/eye.js +19 -0
  247. package/dist/node_modules/lucide/dist/esm/icons/eye.js.map +1 -0
  248. package/dist/node_modules/lucide/dist/esm/icons/grid-3x3.cjs +19 -0
  249. package/dist/node_modules/lucide/dist/esm/icons/grid-3x3.cjs.map +1 -0
  250. package/dist/node_modules/lucide/dist/esm/icons/grid-3x3.js +17 -0
  251. package/dist/node_modules/lucide/dist/esm/icons/grid-3x3.js.map +1 -0
  252. package/dist/node_modules/lucide/dist/esm/icons/history.cjs +17 -0
  253. package/dist/node_modules/lucide/dist/esm/icons/history.cjs.map +1 -0
  254. package/dist/node_modules/lucide/dist/esm/icons/history.js +15 -0
  255. package/dist/node_modules/lucide/dist/esm/icons/history.js.map +1 -0
  256. package/dist/node_modules/lucide/dist/esm/icons/info.cjs +17 -0
  257. package/dist/node_modules/lucide/dist/esm/icons/info.cjs.map +1 -0
  258. package/dist/node_modules/lucide/dist/esm/icons/info.js +15 -0
  259. package/dist/node_modules/lucide/dist/esm/icons/info.js.map +1 -0
  260. package/dist/node_modules/lucide/dist/esm/icons/lasso.cjs +17 -0
  261. package/dist/node_modules/lucide/dist/esm/icons/lasso.cjs.map +1 -0
  262. package/dist/node_modules/lucide/dist/esm/icons/lasso.js +15 -0
  263. package/dist/node_modules/lucide/dist/esm/icons/lasso.js.map +1 -0
  264. package/dist/node_modules/lucide/dist/esm/icons/maximize.cjs +18 -0
  265. package/dist/node_modules/lucide/dist/esm/icons/maximize.cjs.map +1 -0
  266. package/dist/node_modules/lucide/dist/esm/icons/maximize.js +16 -0
  267. package/dist/node_modules/lucide/dist/esm/icons/maximize.js.map +1 -0
  268. package/dist/node_modules/lucide/dist/esm/icons/minimize.cjs +18 -0
  269. package/dist/node_modules/lucide/dist/esm/icons/minimize.cjs.map +1 -0
  270. package/dist/node_modules/lucide/dist/esm/icons/minimize.js +16 -0
  271. package/dist/node_modules/lucide/dist/esm/icons/minimize.js.map +1 -0
  272. package/dist/node_modules/lucide/dist/esm/icons/mouse-pointer.cjs +21 -0
  273. package/dist/node_modules/lucide/dist/esm/icons/mouse-pointer.cjs.map +1 -0
  274. package/dist/node_modules/lucide/dist/esm/icons/mouse-pointer.js +19 -0
  275. package/dist/node_modules/lucide/dist/esm/icons/mouse-pointer.js.map +1 -0
  276. package/dist/node_modules/lucide/dist/esm/icons/move.cjs +20 -0
  277. package/dist/node_modules/lucide/dist/esm/icons/move.cjs.map +1 -0
  278. package/dist/node_modules/lucide/dist/esm/icons/move.js +18 -0
  279. package/dist/node_modules/lucide/dist/esm/icons/move.js.map +1 -0
  280. package/dist/node_modules/lucide/dist/esm/icons/panels-top-left.cjs +17 -0
  281. package/dist/node_modules/lucide/dist/esm/icons/panels-top-left.cjs.map +1 -0
  282. package/dist/node_modules/lucide/dist/esm/icons/panels-top-left.js +15 -0
  283. package/dist/node_modules/lucide/dist/esm/icons/panels-top-left.js.map +1 -0
  284. package/dist/node_modules/lucide/dist/esm/icons/pen.cjs +20 -0
  285. package/dist/node_modules/lucide/dist/esm/icons/pen.cjs.map +1 -0
  286. package/dist/node_modules/lucide/dist/esm/icons/pen.js +18 -0
  287. package/dist/node_modules/lucide/dist/esm/icons/pen.js.map +1 -0
  288. package/dist/node_modules/lucide/dist/esm/icons/plus.cjs +16 -0
  289. package/dist/node_modules/lucide/dist/esm/icons/plus.cjs.map +1 -0
  290. package/dist/node_modules/lucide/dist/esm/icons/plus.js +14 -0
  291. package/dist/node_modules/lucide/dist/esm/icons/plus.js.map +1 -0
  292. package/dist/node_modules/lucide/dist/esm/icons/search.cjs +16 -0
  293. package/dist/node_modules/lucide/dist/esm/icons/search.cjs.map +1 -0
  294. package/dist/node_modules/lucide/dist/esm/icons/search.js +14 -0
  295. package/dist/node_modules/lucide/dist/esm/icons/search.js.map +1 -0
  296. package/dist/node_modules/lucide/dist/esm/icons/settings.cjs +21 -0
  297. package/dist/node_modules/lucide/dist/esm/icons/settings.cjs.map +1 -0
  298. package/dist/node_modules/lucide/dist/esm/icons/settings.js +19 -0
  299. package/dist/node_modules/lucide/dist/esm/icons/settings.js.map +1 -0
  300. package/dist/node_modules/lucide/dist/esm/icons/share-2.cjs +19 -0
  301. package/dist/node_modules/lucide/dist/esm/icons/share-2.cjs.map +1 -0
  302. package/dist/node_modules/lucide/dist/esm/icons/share-2.js +17 -0
  303. package/dist/node_modules/lucide/dist/esm/icons/share-2.js.map +1 -0
  304. package/dist/node_modules/lucide/dist/esm/icons/square.cjs +13 -0
  305. package/dist/node_modules/lucide/dist/esm/icons/square.cjs.map +1 -0
  306. package/dist/node_modules/lucide/dist/esm/icons/square.js +11 -0
  307. package/dist/node_modules/lucide/dist/esm/icons/square.js.map +1 -0
  308. package/dist/node_modules/lucide/dist/esm/icons/sticky-note.cjs +21 -0
  309. package/dist/node_modules/lucide/dist/esm/icons/sticky-note.cjs.map +1 -0
  310. package/dist/node_modules/lucide/dist/esm/icons/sticky-note.js +19 -0
  311. package/dist/node_modules/lucide/dist/esm/icons/sticky-note.js.map +1 -0
  312. package/dist/node_modules/lucide/dist/esm/icons/trash-2.cjs +19 -0
  313. package/dist/node_modules/lucide/dist/esm/icons/trash-2.cjs.map +1 -0
  314. package/dist/node_modules/lucide/dist/esm/icons/trash-2.js +17 -0
  315. package/dist/node_modules/lucide/dist/esm/icons/trash-2.js.map +1 -0
  316. package/dist/node_modules/lucide/dist/esm/icons/triangle.cjs +15 -0
  317. package/dist/node_modules/lucide/dist/esm/icons/triangle.cjs.map +1 -0
  318. package/dist/node_modules/lucide/dist/esm/icons/triangle.js +13 -0
  319. package/dist/node_modules/lucide/dist/esm/icons/triangle.js.map +1 -0
  320. package/dist/node_modules/lucide/dist/esm/icons/x.cjs +16 -0
  321. package/dist/node_modules/lucide/dist/esm/icons/x.cjs.map +1 -0
  322. package/dist/node_modules/lucide/dist/esm/icons/x.js +14 -0
  323. package/dist/node_modules/lucide/dist/esm/icons/x.js.map +1 -0
  324. package/dist/node_modules/lucide/dist/esm/icons/zap.cjs +20 -0
  325. package/dist/node_modules/lucide/dist/esm/icons/zap.cjs.map +1 -0
  326. package/dist/node_modules/lucide/dist/esm/icons/zap.js +18 -0
  327. package/dist/node_modules/lucide/dist/esm/icons/zap.js.map +1 -0
  328. package/dist/node_modules/lucide/dist/esm/lucide.cjs +56 -0
  329. package/dist/node_modules/lucide/dist/esm/lucide.cjs.map +1 -0
  330. package/dist/node_modules/lucide/dist/esm/lucide.js +54 -0
  331. package/dist/node_modules/lucide/dist/esm/lucide.js.map +1 -0
  332. package/dist/node_modules/lucide/dist/esm/replaceElement.cjs +73 -0
  333. package/dist/node_modules/lucide/dist/esm/replaceElement.cjs.map +1 -0
  334. package/dist/node_modules/lucide/dist/esm/replaceElement.js +67 -0
  335. package/dist/node_modules/lucide/dist/esm/replaceElement.js.map +1 -0
  336. package/dist/node_modules/lucide/dist/esm/shared/src/utils/hasA11yProp.cjs +20 -0
  337. package/dist/node_modules/lucide/dist/esm/shared/src/utils/hasA11yProp.cjs.map +1 -0
  338. package/dist/node_modules/lucide/dist/esm/shared/src/utils/hasA11yProp.js +18 -0
  339. package/dist/node_modules/lucide/dist/esm/shared/src/utils/hasA11yProp.js.map +1 -0
  340. package/dist/node_modules/lucide/dist/esm/shared/src/utils/mergeClasses.cjs +15 -0
  341. package/dist/node_modules/lucide/dist/esm/shared/src/utils/mergeClasses.cjs.map +1 -0
  342. package/dist/node_modules/lucide/dist/esm/shared/src/utils/mergeClasses.js +13 -0
  343. package/dist/node_modules/lucide/dist/esm/shared/src/utils/mergeClasses.js.map +1 -0
  344. package/dist/node_modules/lucide/dist/esm/shared/src/utils/toCamelCase.cjs +16 -0
  345. package/dist/node_modules/lucide/dist/esm/shared/src/utils/toCamelCase.cjs.map +1 -0
  346. package/dist/node_modules/lucide/dist/esm/shared/src/utils/toCamelCase.js +14 -0
  347. package/dist/node_modules/lucide/dist/esm/shared/src/utils/toCamelCase.js.map +1 -0
  348. package/dist/node_modules/lucide/dist/esm/shared/src/utils/toPascalCase.cjs +19 -0
  349. package/dist/node_modules/lucide/dist/esm/shared/src/utils/toPascalCase.cjs.map +1 -0
  350. package/dist/node_modules/lucide/dist/esm/shared/src/utils/toPascalCase.js +17 -0
  351. package/dist/node_modules/lucide/dist/esm/shared/src/utils/toPascalCase.js.map +1 -0
  352. package/dist/nodes/content.cjs +186 -0
  353. package/dist/nodes/content.cjs.map +1 -0
  354. package/dist/nodes/content.d.ts +16 -0
  355. package/dist/nodes/content.js +184 -0
  356. package/dist/nodes/content.js.map +1 -0
  357. package/dist/nodes/geometry/ellipsePath.cjs +18 -0
  358. package/dist/nodes/geometry/ellipsePath.cjs.map +1 -0
  359. package/dist/nodes/geometry/ellipsePath.d.ts +5 -0
  360. package/dist/nodes/geometry/ellipsePath.js +16 -0
  361. package/dist/nodes/geometry/ellipsePath.js.map +1 -0
  362. package/dist/nodes/geometry/kitePath.cjs +15 -0
  363. package/dist/nodes/geometry/kitePath.cjs.map +1 -0
  364. package/dist/nodes/geometry/kitePath.d.ts +5 -0
  365. package/dist/nodes/geometry/kitePath.js +13 -0
  366. package/dist/nodes/geometry/kitePath.js.map +1 -0
  367. package/dist/nodes/geometry/octagonPath.cjs +23 -0
  368. package/dist/nodes/geometry/octagonPath.cjs.map +1 -0
  369. package/dist/nodes/geometry/octagonPath.d.ts +4 -0
  370. package/dist/nodes/geometry/octagonPath.js +21 -0
  371. package/dist/nodes/geometry/octagonPath.js.map +1 -0
  372. package/dist/nodes/geometry/parallelogramPath.cjs +16 -0
  373. package/dist/nodes/geometry/parallelogramPath.cjs.map +1 -0
  374. package/dist/nodes/geometry/parallelogramPath.d.ts +5 -0
  375. package/dist/nodes/geometry/parallelogramPath.js +14 -0
  376. package/dist/nodes/geometry/parallelogramPath.js.map +1 -0
  377. package/dist/nodes/geometry/pentagonPath.cjs +23 -0
  378. package/dist/nodes/geometry/pentagonPath.cjs.map +1 -0
  379. package/dist/nodes/geometry/pentagonPath.d.ts +4 -0
  380. package/dist/nodes/geometry/pentagonPath.js +21 -0
  381. package/dist/nodes/geometry/pentagonPath.js.map +1 -0
  382. package/dist/nodes/geometry/polygonPath.cjs +28 -0
  383. package/dist/nodes/geometry/polygonPath.cjs.map +1 -0
  384. package/dist/nodes/geometry/polygonPath.d.ts +5 -0
  385. package/dist/nodes/geometry/polygonPath.js +26 -0
  386. package/dist/nodes/geometry/polygonPath.js.map +1 -0
  387. package/dist/nodes/geometry/rectanglePath.cjs +23 -0
  388. package/dist/nodes/geometry/rectanglePath.cjs.map +1 -0
  389. package/dist/nodes/geometry/rectanglePath.d.ts +4 -0
  390. package/dist/nodes/geometry/rectanglePath.js +21 -0
  391. package/dist/nodes/geometry/rectanglePath.js.map +1 -0
  392. package/dist/nodes/geometry/semicirclePath.cjs +17 -0
  393. package/dist/nodes/geometry/semicirclePath.cjs.map +1 -0
  394. package/dist/nodes/geometry/semicirclePath.d.ts +5 -0
  395. package/dist/nodes/geometry/semicirclePath.js +15 -0
  396. package/dist/nodes/geometry/semicirclePath.js.map +1 -0
  397. package/dist/nodes/geometry/starPath.cjs +28 -0
  398. package/dist/nodes/geometry/starPath.cjs.map +1 -0
  399. package/dist/nodes/geometry/starPath.d.ts +4 -0
  400. package/dist/nodes/geometry/starPath.js +26 -0
  401. package/dist/nodes/geometry/starPath.js.map +1 -0
  402. package/dist/nodes/geometry/trapezoidPath.cjs +16 -0
  403. package/dist/nodes/geometry/trapezoidPath.cjs.map +1 -0
  404. package/dist/nodes/geometry/trapezoidPath.d.ts +5 -0
  405. package/dist/nodes/geometry/trapezoidPath.js +14 -0
  406. package/dist/nodes/geometry/trapezoidPath.js.map +1 -0
  407. package/dist/nodes/geometry/trianglePath.cjs +14 -0
  408. package/dist/nodes/geometry/trianglePath.cjs.map +1 -0
  409. package/dist/nodes/geometry/trianglePath.d.ts +5 -0
  410. package/dist/nodes/geometry/trianglePath.js +12 -0
  411. package/dist/nodes/geometry/trianglePath.js.map +1 -0
  412. package/dist/nodes/overlay.cjs +136 -0
  413. package/dist/nodes/overlay.cjs.map +1 -0
  414. package/dist/nodes/overlay.d.ts +24 -0
  415. package/dist/nodes/overlay.js +130 -0
  416. package/dist/nodes/overlay.js.map +1 -0
  417. package/dist/nodes/placement.cjs +346 -0
  418. package/dist/nodes/placement.cjs.map +1 -0
  419. package/dist/nodes/placement.d.ts +66 -0
  420. package/dist/nodes/placement.js +325 -0
  421. package/dist/nodes/placement.js.map +1 -0
  422. package/dist/nodes/ports.cjs +196 -0
  423. package/dist/nodes/ports.cjs.map +1 -0
  424. package/dist/nodes/ports.d.ts +12 -0
  425. package/dist/nodes/ports.js +194 -0
  426. package/dist/nodes/ports.js.map +1 -0
  427. package/dist/nodes/registry.cjs +26 -0
  428. package/dist/nodes/registry.cjs.map +1 -0
  429. package/dist/nodes/registry.d.ts +8 -0
  430. package/dist/nodes/registry.js +24 -0
  431. package/dist/nodes/registry.js.map +1 -0
  432. package/dist/nodes/shapes/circle.cjs +50 -0
  433. package/dist/nodes/shapes/circle.cjs.map +1 -0
  434. package/dist/nodes/shapes/circle.d.ts +2 -0
  435. package/dist/nodes/shapes/circle.js +48 -0
  436. package/dist/nodes/shapes/circle.js.map +1 -0
  437. package/dist/nodes/shapes/decagon.cjs +51 -0
  438. package/dist/nodes/shapes/decagon.cjs.map +1 -0
  439. package/dist/nodes/shapes/decagon.d.ts +5 -0
  440. package/dist/nodes/shapes/decagon.js +49 -0
  441. package/dist/nodes/shapes/decagon.js.map +1 -0
  442. package/dist/nodes/shapes/heptagon.cjs +51 -0
  443. package/dist/nodes/shapes/heptagon.cjs.map +1 -0
  444. package/dist/nodes/shapes/heptagon.d.ts +5 -0
  445. package/dist/nodes/shapes/heptagon.js +49 -0
  446. package/dist/nodes/shapes/heptagon.js.map +1 -0
  447. package/dist/nodes/shapes/hexagon.cjs +51 -0
  448. package/dist/nodes/shapes/hexagon.cjs.map +1 -0
  449. package/dist/nodes/shapes/hexagon.d.ts +5 -0
  450. package/dist/nodes/shapes/hexagon.js +49 -0
  451. package/dist/nodes/shapes/hexagon.js.map +1 -0
  452. package/dist/nodes/shapes/kite.cjs +43 -0
  453. package/dist/nodes/shapes/kite.cjs.map +1 -0
  454. package/dist/nodes/shapes/kite.d.ts +5 -0
  455. package/dist/nodes/shapes/kite.js +41 -0
  456. package/dist/nodes/shapes/kite.js.map +1 -0
  457. package/dist/nodes/shapes/nonagon.cjs +51 -0
  458. package/dist/nodes/shapes/nonagon.cjs.map +1 -0
  459. package/dist/nodes/shapes/nonagon.d.ts +5 -0
  460. package/dist/nodes/shapes/nonagon.js +49 -0
  461. package/dist/nodes/shapes/nonagon.js.map +1 -0
  462. package/dist/nodes/shapes/octagon.cjs +46 -0
  463. package/dist/nodes/shapes/octagon.cjs.map +1 -0
  464. package/dist/nodes/shapes/octagon.d.ts +2 -0
  465. package/dist/nodes/shapes/octagon.js +44 -0
  466. package/dist/nodes/shapes/octagon.js.map +1 -0
  467. package/dist/nodes/shapes/oval.cjs +43 -0
  468. package/dist/nodes/shapes/oval.cjs.map +1 -0
  469. package/dist/nodes/shapes/oval.d.ts +5 -0
  470. package/dist/nodes/shapes/oval.js +41 -0
  471. package/dist/nodes/shapes/oval.js.map +1 -0
  472. package/dist/nodes/shapes/parallelogram.cjs +44 -0
  473. package/dist/nodes/shapes/parallelogram.cjs.map +1 -0
  474. package/dist/nodes/shapes/parallelogram.d.ts +5 -0
  475. package/dist/nodes/shapes/parallelogram.js +42 -0
  476. package/dist/nodes/shapes/parallelogram.js.map +1 -0
  477. package/dist/nodes/shapes/pentagon.cjs +46 -0
  478. package/dist/nodes/shapes/pentagon.cjs.map +1 -0
  479. package/dist/nodes/shapes/pentagon.d.ts +2 -0
  480. package/dist/nodes/shapes/pentagon.js +44 -0
  481. package/dist/nodes/shapes/pentagon.js.map +1 -0
  482. package/dist/nodes/shapes/rectangle.cjs +43 -0
  483. package/dist/nodes/shapes/rectangle.cjs.map +1 -0
  484. package/dist/nodes/shapes/rectangle.d.ts +2 -0
  485. package/dist/nodes/shapes/rectangle.js +41 -0
  486. package/dist/nodes/shapes/rectangle.js.map +1 -0
  487. package/dist/nodes/shapes/rhombus.cjs +38 -0
  488. package/dist/nodes/shapes/rhombus.cjs.map +1 -0
  489. package/dist/nodes/shapes/rhombus.d.ts +2 -0
  490. package/dist/nodes/shapes/rhombus.js +36 -0
  491. package/dist/nodes/shapes/rhombus.js.map +1 -0
  492. package/dist/nodes/shapes/semicircle.cjs +38 -0
  493. package/dist/nodes/shapes/semicircle.cjs.map +1 -0
  494. package/dist/nodes/shapes/semicircle.d.ts +2 -0
  495. package/dist/nodes/shapes/semicircle.js +36 -0
  496. package/dist/nodes/shapes/semicircle.js.map +1 -0
  497. package/dist/nodes/shapes/star.cjs +51 -0
  498. package/dist/nodes/shapes/star.cjs.map +1 -0
  499. package/dist/nodes/shapes/star.d.ts +2 -0
  500. package/dist/nodes/shapes/star.js +49 -0
  501. package/dist/nodes/shapes/star.js.map +1 -0
  502. package/dist/nodes/shapes/trapezoid.cjs +44 -0
  503. package/dist/nodes/shapes/trapezoid.cjs.map +1 -0
  504. package/dist/nodes/shapes/trapezoid.d.ts +5 -0
  505. package/dist/nodes/shapes/trapezoid.js +42 -0
  506. package/dist/nodes/shapes/trapezoid.js.map +1 -0
  507. package/dist/nodes/shapes/triangle.cjs +42 -0
  508. package/dist/nodes/shapes/triangle.cjs.map +1 -0
  509. package/dist/nodes/shapes/triangle.d.ts +5 -0
  510. package/dist/nodes/shapes/triangle.js +40 -0
  511. package/dist/nodes/shapes/triangle.js.map +1 -0
  512. package/dist/types/index.d.ts +213 -0
  513. package/dist/utils/configMerger.cjs +147 -0
  514. package/dist/utils/configMerger.cjs.map +1 -0
  515. package/dist/utils/configMerger.d.ts +2 -0
  516. package/dist/utils/configMerger.js +145 -0
  517. package/dist/utils/configMerger.js.map +1 -0
  518. package/dist/utils/helpers.cjs +21 -0
  519. package/dist/utils/helpers.cjs.map +1 -0
  520. package/dist/utils/helpers.d.ts +13 -0
  521. package/dist/utils/helpers.js +18 -0
  522. package/dist/utils/helpers.js.map +1 -0
  523. package/dist/zenode.cjs.js +1228 -0
  524. package/dist/zenode.cjs.js.map +1 -0
  525. package/dist/zenode.esm.js +1203 -0
  526. package/dist/zenode.esm.js.map +1 -0
  527. package/dist/zenode.umd.js +1232 -0
  528. package/dist/zenode.umd.js.map +1 -0
  529. package/package.json +60 -0
@@ -0,0 +1,1228 @@
1
+ 'use strict';
2
+
3
+ var d3 = require('d3');
4
+
5
+ function _interopNamespaceDefault(e) {
6
+ var n = Object.create(null);
7
+ if (e) {
8
+ Object.keys(e).forEach(function (k) {
9
+ if (k !== 'default') {
10
+ var d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: function () { return e[k]; }
14
+ });
15
+ }
16
+ });
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ var d3__namespace = /*#__PURE__*/_interopNamespaceDefault(d3);
23
+
24
+ const defaultConfig = {
25
+ canvas: {
26
+ grid: {
27
+ gridEnabled: true,
28
+ gridType: "dotted", // dotted, line , cross , sheet
29
+ gridColor: "#000000",
30
+ gridTransparency: 1,
31
+ gridSize: 20,
32
+ gridShape: 'circle',
33
+ gridDimension: 1,
34
+ sheetDimension: 3,
35
+ crossLength: 2
36
+ },
37
+ backgroundColor: "#ffffff",
38
+ width: 800,
39
+ canvasClasses: ["zenode-canvas"],
40
+ height: 500,
41
+ locked: false
42
+ },
43
+ canvasProperties: {
44
+ zoomEnabled: true,
45
+ zoomExtent: [0.1, 10],
46
+ zoomOnDoubleClick: true,
47
+ zoomOnScroll: true,
48
+ zoomScale: 1,
49
+ zoomDuration: 200,
50
+ panEnabled: true,
51
+ snapToGrid: true,
52
+ alignmentLines: {
53
+ enabled: true,
54
+ color: '#000000',
55
+ width: 2,
56
+ dashed: true,
57
+ dashArray: [2, 3],
58
+ guideLineMode: 'partial'
59
+ }
60
+ // defaultNodeSpacing: 50,
61
+ // dragType: "smooth"
62
+ },
63
+ shapes: {
64
+ default: {
65
+ "circle": [
66
+ {
67
+ "id": "circle1",
68
+ "radius": 30,
69
+ "color": "#008000",
70
+ "stroke": { "width": 2, "color": "#000000", "strokeDasharray": [] },
71
+ "textColor": "#ffffff",
72
+ "boxShadow": "0px 4px 6px rgba(0, 0, 0, 0.1)",
73
+ "transparency": 1,
74
+ "overlay": {
75
+ "enabled": true, // Enable selection overlay
76
+ "color": "blue", // Example color
77
+ "strokeWidth": 2, // Example stroke width
78
+ "opacity": 1,
79
+ "type": "line"
80
+ },
81
+ 'previewEnabled': true,
82
+ 'previewTransparency': 0.4
83
+ },
84
+ ],
85
+ "rectangle": [
86
+ {
87
+ "id": "task0",
88
+ "width": 120,
89
+ "height": 60,
90
+ "color": "#0000ff",
91
+ "borderRadius": { "leftTop": 3, "leftBottom": 3, "rightTop": 3, "rightBottom": 3 },
92
+ "stroke": { "width": 2, "color": "#000000", "strokeDasharray": [] },
93
+ "textColor": "#ffffff",
94
+ "boxShadow": "0px 4px 6px rgba(0, 0, 0, 0.1)",
95
+ "transparency": 1,
96
+ "overlay": {
97
+ "enabled": true, // Enable selection overlay
98
+ "color": "blue", // Example color
99
+ "strokeWidth": 2, // Example stroke width
100
+ "opacity": 1,
101
+ "type": "line"
102
+ },
103
+ 'previewEnabled': true,
104
+ 'previewTransparency': 0.4
105
+ },
106
+ {
107
+ "id": "task1",
108
+ "width": 100,
109
+ "height": 50,
110
+ "color": "#00FFFF",
111
+ "borderRadius": { "leftTop": 5, "leftBottom": 5, "rightTop": 5, "rightBottom": 5 },
112
+ "stroke": { "width": 2, "color": "#000000", "strokeDasharray": [] },
113
+ "textColor": "#000000",
114
+ "boxShadow": "0px 3px 5px rgba(0, 0, 0, 0.1)",
115
+ "transparency": 1,
116
+ "overlay": {
117
+ "enabled": true, // Enable selection overlay
118
+ "color": "blue", // Example color
119
+ "strokeWidth": 2, // Example stroke width
120
+ "opacity": 1,
121
+ "type": "line"
122
+ },
123
+ 'previewEnabled': true,
124
+ 'previewTransparency': 0.4
125
+ }
126
+ ],
127
+ "rhombus": [
128
+ {
129
+ "id": "rhombus1",
130
+ "width": 80,
131
+ "height": 80,
132
+ "color": "#FF00FF",
133
+ "stroke": { "width": 2, "color": "#000000", "strokeDasharray": [] },
134
+ "textColor": "#ffffff",
135
+ "boxShadow": "0px 4px 6px rgba(0, 0, 0, 0.1)",
136
+ "transparency": 1,
137
+ "overlay": {
138
+ "enabled": true, // Enable selection overlay
139
+ "color": "blue", // Example color
140
+ "strokeWidth": 2, // Example stroke width
141
+ "opacity": 1,
142
+ "type": "line"
143
+ },
144
+ 'previewEnabled': true,
145
+ 'previewTransparency': 0.4
146
+ }
147
+ ]
148
+ },
149
+ extraShapes: []
150
+ },
151
+ connections: {
152
+ default: {
153
+ straight: {
154
+ type: "line",
155
+ style: "solid",
156
+ color: "#000000",
157
+ width: 2,
158
+ lineStyle: {
159
+ dashArray: [],
160
+ innerTextEnabled: false,
161
+ innerText: "",
162
+ innerTextColor: "#000000",
163
+ icon: null,
164
+ clickFunction: null
165
+ }
166
+ },
167
+ curved: {
168
+ type: "bezier",
169
+ style: "smooth",
170
+ color: "#666666",
171
+ width: 2,
172
+ lineStyle: {
173
+ dashArray: [],
174
+ innerTextEnabled: false,
175
+ innerText: "",
176
+ innerTextColor: "#000000",
177
+ icon: null,
178
+ clickFunction: null
179
+ }
180
+ },
181
+ sShaped: {
182
+ type: "s-shaped",
183
+ style: "smooth",
184
+ color: "#333333",
185
+ width: 2,
186
+ lineStyle: {
187
+ dashArray: [],
188
+ innerTextEnabled: false,
189
+ innerText: "",
190
+ innerTextColor: "#000000",
191
+ icon: null,
192
+ clickFunction: null
193
+ }
194
+ },
195
+ lBent: {
196
+ type: "l-bent",
197
+ style: "cornered",
198
+ color: "#444444",
199
+ width: 2,
200
+ lineStyle: {
201
+ dashArray: [],
202
+ innerTextEnabled: false,
203
+ innerText: "",
204
+ innerTextColor: "#000000",
205
+ icon: null,
206
+ clickFunction: null
207
+ }
208
+ }
209
+ },
210
+ custom: []
211
+ },
212
+ globalProperties: {
213
+ nodeSpacing: 80,
214
+ connectionGap: 10,
215
+ animationEnabled: true,
216
+ validateGridSize: null
217
+ },
218
+ dragOptions: {
219
+ enableDrag: true,
220
+ dragMode: "smooth",
221
+ connectionDraw: "onDragEnd"
222
+ }
223
+ };
224
+
225
+ // src/components/canvas/drawCanvas.ts
226
+ function drawCanvas(containerSelector, canvasConfig) {
227
+ const container = d3__namespace.select(containerSelector);
228
+ if (container.empty()) {
229
+ throw new Error(`Container '${containerSelector}' not found in DOM.`);
230
+ }
231
+ let canvasClasses = (canvasConfig === null || canvasConfig === void 0 ? void 0 : canvasConfig.canvasClasses) || defaultConfig.canvas.canvasClasses;
232
+ const width = (canvasConfig === null || canvasConfig === void 0 ? void 0 : canvasConfig.width) || defaultConfig.canvas.width;
233
+ const height = (canvasConfig === null || canvasConfig === void 0 ? void 0 : canvasConfig.height) || defaultConfig.canvas.height;
234
+ const backgroundColor = (canvasConfig === null || canvasConfig === void 0 ? void 0 : canvasConfig.backgroundColor) || defaultConfig.canvas.backgroundColor;
235
+ const svg = container
236
+ .append("svg")
237
+ .attr("width", width)
238
+ .attr("height", height)
239
+ .attr("class", canvasClasses.join(" "))
240
+ .style("background-color", backgroundColor)
241
+ .attr("viewBox", `0 0 ${width} ${height}`)
242
+ .attr("preserveAspectRatio", "xMidYMid meet")
243
+ .style("display", "block")
244
+ .style("margin", "auto");
245
+ const canvasContainerGroup = svg
246
+ .append("g")
247
+ .attr("class", "canvas-container");
248
+ const gridLayout = canvasContainerGroup.append("g").attr("class", "grid");
249
+ const elementsGroup = canvasContainerGroup
250
+ .append("g")
251
+ .attr("class", "elements-group");
252
+ // Insert below preview so layer order: grid, connections, placed-nodes, preview
253
+ const connectionsGroup = canvasContainerGroup
254
+ .insert("g", ".elements-group")
255
+ .attr("class", "connections");
256
+ const placedNodesGroup = canvasContainerGroup
257
+ .insert("g", ".elements-group")
258
+ .attr("class", "placed-nodes");
259
+ const guidesGroup = canvasContainerGroup
260
+ .append("g")
261
+ .attr("class", "guides")
262
+ .style("pointer-events", "none");
263
+ elementsGroup.style("pointer-events", "none");
264
+ return {
265
+ grid: gridLayout,
266
+ elements: elementsGroup,
267
+ svg: svg,
268
+ canvasContainer: canvasContainerGroup,
269
+ connections: connectionsGroup,
270
+ placedNodes: placedNodesGroup,
271
+ guides: guidesGroup,
272
+ };
273
+ }
274
+ function lockedCanvas(locked, svg, zoomBehaviour) {
275
+ if (locked) {
276
+ svg.on(".zoom", null); // Disable zoom and pan
277
+ svg.style("cursor", "default");
278
+ d3__namespace.selectAll(".shape, .connection").style("pointer-events", "none");
279
+ }
280
+ else {
281
+ svg.call(zoomBehaviour); // Enable zoom and pan
282
+ svg.style("cursor", "grab");
283
+ d3__namespace.selectAll(".shape, .connection").style("pointer-events", "all");
284
+ }
285
+ console.log(`Canvas ${locked ? "locked (Preview Mode)" : "unlocked (Edit Mode)"}`);
286
+ }
287
+
288
+ // src/components/canvas/drawGrid.ts
289
+ function drawGrid(svg, canvasConfig, grid) {
290
+ var _a, _b, _c, _d, _e;
291
+ //Check if the grid is enabled
292
+ if (!((_a = canvasConfig === null || canvasConfig === void 0 ? void 0 : canvasConfig.grid) === null || _a === void 0 ? void 0 : _a.gridEnabled)) {
293
+ return grid;
294
+ }
295
+ // Check Grid Type
296
+ if (((_b = canvasConfig === null || canvasConfig === void 0 ? void 0 : canvasConfig.grid) === null || _b === void 0 ? void 0 : _b.gridType) === "dotted") {
297
+ let gridPattern = createDottedGrid(canvasConfig, grid);
298
+ return gridPattern;
299
+ }
300
+ else if (((_c = canvasConfig === null || canvasConfig === void 0 ? void 0 : canvasConfig.grid) === null || _c === void 0 ? void 0 : _c.gridType) === "line") {
301
+ let gridPattern = createLineGrid(canvasConfig, grid);
302
+ return gridPattern;
303
+ }
304
+ else if (((_d = canvasConfig === null || canvasConfig === void 0 ? void 0 : canvasConfig.grid) === null || _d === void 0 ? void 0 : _d.gridType) === "cross") {
305
+ let gridPattern = createCrossGrid(canvasConfig, grid);
306
+ return gridPattern;
307
+ }
308
+ else if (((_e = canvasConfig === null || canvasConfig === void 0 ? void 0 : canvasConfig.grid) === null || _e === void 0 ? void 0 : _e.gridType) === "sheet") {
309
+ let gridPattern = createSquareGrid(canvasConfig, grid);
310
+ return gridPattern;
311
+ }
312
+ else {
313
+ return grid;
314
+ }
315
+ }
316
+ function toggleGrid(enable) {
317
+ d3__namespace.select(".grid-group").style("display", enable ? "block" : "none");
318
+ }
319
+ function createDottedGrid(canvasConfig, grid) {
320
+ var _a, _b;
321
+ const pattern = grid
322
+ .append("defs")
323
+ .append("pattern")
324
+ .attr("id", "dotPattern")
325
+ .attr("patternUnits", "userSpaceOnUse")
326
+ .attr("width", canvasConfig.grid.gridSize || defaultConfig.canvas.grid.gridSize)
327
+ .attr("height", canvasConfig.grid.gridSize || defaultConfig.canvas.grid.gridSize);
328
+ if (canvasConfig.grid.gridShape == "square") {
329
+ pattern
330
+ .append("rect")
331
+ .attr("width", canvasConfig.grid.gridDimension ||
332
+ defaultConfig.canvas.grid.gridDimension)
333
+ .attr("height", canvasConfig.grid.gridDimension ||
334
+ defaultConfig.canvas.grid.gridDimension)
335
+ .attr("fill", canvasConfig.grid.gridColor || defaultConfig.canvas.grid.gridColor);
336
+ }
337
+ else {
338
+ pattern
339
+ .append("circle")
340
+ .attr("cx", ((_a = canvasConfig.grid.gridSize) !== null && _a !== void 0 ? _a : defaultConfig.canvas.grid.gridSize) / 4)
341
+ .attr("cy", ((_b = canvasConfig.grid.gridSize) !== null && _b !== void 0 ? _b : defaultConfig.canvas.grid.gridSize) / 4)
342
+ .attr("r", canvasConfig.grid.gridDimension ||
343
+ defaultConfig.canvas.grid.gridDimension)
344
+ .attr("fill", canvasConfig.grid.gridColor || defaultConfig.canvas.grid.gridColor);
345
+ }
346
+ // Set the Grid
347
+ grid
348
+ .append("rect")
349
+ .attr("x", -(canvasConfig.width * 10000))
350
+ .attr("y", -(canvasConfig.height * 10000))
351
+ .attr("width", canvasConfig.width * 20000)
352
+ .attr("height", canvasConfig.height * 20000)
353
+ .attr("opacity", canvasConfig.grid.gridTransparency || defaultConfig.canvas.grid.gridTransparency)
354
+ .attr("fill", "url(#dotPattern)");
355
+ console.log(grid);
356
+ return grid;
357
+ }
358
+ function createLineGrid(canvasConfig, grid) {
359
+ const pattern = grid
360
+ .append("defs")
361
+ .append("pattern")
362
+ .attr("id", "linePattern")
363
+ .attr("patternUnits", "userSpaceOnUse")
364
+ .attr("width", canvasConfig.grid.gridSize || defaultConfig.canvas.grid.gridSize)
365
+ .attr("height", canvasConfig.grid.gridSize || defaultConfig.canvas.grid.gridSize);
366
+ // Draw horizontal and vertical grid lines
367
+ pattern
368
+ .append("line")
369
+ .attr("x1", 0)
370
+ .attr("y1", 0)
371
+ .attr("x2", canvasConfig.grid.gridSize || defaultConfig.canvas.grid.gridSize)
372
+ .attr("y2", 0)
373
+ .attr("stroke", canvasConfig.grid.gridColor || defaultConfig.canvas.grid.gridColor)
374
+ .attr("stroke-width", canvasConfig.grid.gridDimension || defaultConfig.canvas.grid.gridDimension);
375
+ pattern
376
+ .append("line")
377
+ .attr("x1", 0)
378
+ .attr("y1", 0)
379
+ .attr("x2", 0)
380
+ .attr("y2", canvasConfig.grid.gridSize || defaultConfig.canvas.grid.gridSize)
381
+ .attr("stroke", canvasConfig.grid.gridColor || defaultConfig.canvas.grid.gridColor)
382
+ .attr("stroke-width", canvasConfig.grid.gridDimension || defaultConfig.canvas.grid.gridDimension);
383
+ // Set the Grid
384
+ grid
385
+ .append("rect")
386
+ .attr("x", -((canvasConfig.width || defaultConfig.canvas.width) * 10000))
387
+ .attr("y", -((canvasConfig.height || defaultConfig.canvas.height) * 10000))
388
+ .attr("width", (canvasConfig.width || defaultConfig.canvas.width) * 20000)
389
+ .attr("height", (canvasConfig.height || defaultConfig.canvas.height) * 20000)
390
+ .attr("opacity", canvasConfig.grid.gridTransparency || defaultConfig.canvas.grid.gridTransparency)
391
+ .attr("fill", "url(#linePattern)");
392
+ console.log(grid);
393
+ return grid;
394
+ }
395
+ function createCrossGrid(canvasConfig, grid) {
396
+ const gridSize = canvasConfig.grid.gridSize || defaultConfig.canvas.grid.gridSize;
397
+ const crossArmLength = canvasConfig.grid.crossLength || (gridSize / 2);
398
+ const strokeWidth = (canvasConfig.grid.gridDimension && canvasConfig.grid.gridDimension > 0)
399
+ ? canvasConfig.grid.gridDimension
400
+ : 1;
401
+ const gridColor = canvasConfig.grid.gridColor || defaultConfig.canvas.grid.gridColor;
402
+ const patternSize = gridSize;
403
+ const pattern = grid.append("defs")
404
+ .append("pattern")
405
+ .attr("id", "crossGridPattern")
406
+ .attr("patternUnits", "userSpaceOnUse")
407
+ .attr("width", patternSize)
408
+ .attr("height", patternSize);
409
+ const cx = patternSize / 2;
410
+ const cy = patternSize / 2;
411
+ pattern.append("line")
412
+ .attr("x1", cx - crossArmLength / 2)
413
+ .attr("y1", cy)
414
+ .attr("x2", cx + crossArmLength / 2)
415
+ .attr("y2", cy)
416
+ .attr("stroke", gridColor)
417
+ .attr("stroke-width", strokeWidth);
418
+ pattern.append("line")
419
+ .attr("x1", cx)
420
+ .attr("y1", cy - crossArmLength / 2)
421
+ .attr("x2", cx)
422
+ .attr("y2", cy + crossArmLength / 2)
423
+ .attr("stroke", gridColor)
424
+ .attr("stroke-width", strokeWidth);
425
+ grid.append("rect")
426
+ .attr("x", -(canvasConfig.width * 10000))
427
+ .attr("y", -(canvasConfig.height * 10000))
428
+ .attr("width", canvasConfig.width * 20000)
429
+ .attr("height", canvasConfig.height * 20000)
430
+ .attr("opacity", canvasConfig.grid.gridTransparency || defaultConfig.canvas.grid.gridTransparency)
431
+ .attr("fill", "url(#crossGridPattern)");
432
+ console.log("Cross Grid created:", grid);
433
+ return grid;
434
+ }
435
+ function createSquareGrid(canvasConfig, // Replace 'any' with your actual Canvas type if available
436
+ grid) {
437
+ const gridSize = canvasConfig.grid.gridSize || defaultConfig.canvas.grid.gridSize;
438
+ const thinStroke = (canvasConfig.grid.gridDimension && canvasConfig.grid.gridDimension > 0)
439
+ ? canvasConfig.grid.gridDimension
440
+ : 1;
441
+ const cellsPerBlock = canvasConfig.grid.sheetDimension || defaultConfig.canvas.grid.sheetDimension;
442
+ const thickStroke = thinStroke * cellsPerBlock;
443
+ const blockSize = gridSize * cellsPerBlock;
444
+ const pattern = grid.append("defs")
445
+ .append("pattern")
446
+ .attr("id", "sheetPattern")
447
+ .attr("patternUnits", "userSpaceOnUse")
448
+ .attr("width", blockSize)
449
+ .attr("height", blockSize);
450
+ for (let i = 1; i < cellsPerBlock; i++) {
451
+ pattern.append("line")
452
+ .attr("x1", i * gridSize)
453
+ .attr("y1", 0)
454
+ .attr("x2", i * gridSize)
455
+ .attr("y2", blockSize)
456
+ .attr("stroke", canvasConfig.grid.gridColor || "#ccc")
457
+ .attr("stroke-width", thinStroke);
458
+ }
459
+ for (let j = 1; j < cellsPerBlock; j++) {
460
+ pattern.append("line")
461
+ .attr("x1", 0)
462
+ .attr("y1", j * gridSize)
463
+ .attr("x2", blockSize)
464
+ .attr("y2", j * gridSize)
465
+ .attr("stroke", canvasConfig.grid.gridColor || "#ccc")
466
+ .attr("stroke-width", thinStroke);
467
+ }
468
+ pattern.append("rect")
469
+ .attr("x", 0)
470
+ .attr("y", 0)
471
+ .attr("width", blockSize)
472
+ .attr("height", blockSize)
473
+ .attr("fill", "none")
474
+ .attr("stroke", canvasConfig.grid.gridColor || "#ccc")
475
+ .attr("stroke-width", thickStroke);
476
+ grid.append("rect")
477
+ .attr("x", -(canvasConfig.width * 10000))
478
+ .attr("y", -(canvasConfig.height * 10000))
479
+ .attr("width", canvasConfig.width * 20000)
480
+ .attr("height", canvasConfig.height * 20000)
481
+ .attr("opacity", canvasConfig.grid.gridTransparency || defaultConfig.canvas.grid.gridTransparency)
482
+ .attr("fill", "url(#sheetPattern)");
483
+ console.log("Grid created:", grid);
484
+ return grid;
485
+ }
486
+
487
+ class EventManager {
488
+ constructor() {
489
+ this.listeners = {};
490
+ }
491
+ // Register a callback for an event type (e.g., "zoom", "shapePlaced", etc.)
492
+ on(eventType, callback) {
493
+ if (!this.listeners[eventType]) {
494
+ this.listeners[eventType] = [];
495
+ }
496
+ this.listeners[eventType].push(callback);
497
+ }
498
+ // Trigger an event and call all callbacks registered for that event type
499
+ trigger(eventType, event) {
500
+ if (this.listeners[eventType]) {
501
+ this.listeners[eventType].forEach(callback => callback(event));
502
+ }
503
+ }
504
+ }
505
+
506
+ class ZoomManager {
507
+ constructor(container, svg, config, triggerEvent) {
508
+ this.container = container;
509
+ this.config = config;
510
+ this.zoomBehaviour = d3__namespace.zoom()
511
+ .scaleExtent(this.config.canvasProperties.zoomExtent)
512
+ .translateExtent([
513
+ [-1e4, -1e4], [10000, 10000]
514
+ ])
515
+ .filter((event) => {
516
+ if (event.type === "dblclick")
517
+ return false;
518
+ if (!this.config.canvasProperties.zoomOnScroll && event.type === "wheel")
519
+ return false;
520
+ if (!this.config.canvasProperties.panEnabled && event.type === "mousedown")
521
+ return false;
522
+ if (event.type === "wheel")
523
+ return event.ctrlKey || event.metaKey || event.button === 1;
524
+ return true;
525
+ })
526
+ .on("start", (event) => triggerEvent("zoomStart", event))
527
+ .on("zoom", (event) => {
528
+ this.container.attr("transform", event.transform);
529
+ triggerEvent("zoom", event);
530
+ })
531
+ .on("end", (event) => triggerEvent("zoomEnd", event));
532
+ svg.call(this.zoomBehaviour);
533
+ const initialZoom = config.canvasProperties.zoomScale || defaultConfig.canvasProperties.zoomScale;
534
+ const zoomDuration = config.canvasProperties.zoomDuration || defaultConfig.canvasProperties.zoomDuration;
535
+ const initialTransform = d3__namespace.zoomIdentity.scale(initialZoom);
536
+ svg.call(this.zoomBehaviour.transform, initialTransform).transition().duration(zoomDuration);
537
+ //addMarkers
538
+ }
539
+ }
540
+
541
+ function snapToGrid(x, y, grid) {
542
+ const snappedX = Math.round(x / grid) * grid;
543
+ const snappedY = Math.round(y / grid) * grid;
544
+ return { x: snappedX, y: snappedY };
545
+ }
546
+ /**
547
+ * Generates a unique id for a placed node (nanoid-style short id).
548
+ * Uses crypto.randomUUID when available, otherwise a time-based fallback.
549
+ */
550
+ function generatePlacedNodeId() {
551
+ if (typeof crypto !== "undefined" && crypto.randomUUID) {
552
+ return crypto.randomUUID();
553
+ }
554
+ return `node_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
555
+ }
556
+
557
+ function roundedRectPath(x, y, width, height, r1, // top-left
558
+ r2, // top-right
559
+ r3, // bottom-right
560
+ r4 // bottom-left
561
+ ) {
562
+ r1 = Math.min(r1, width / 2, height / 2);
563
+ r2 = Math.min(r2, width / 2, height / 2);
564
+ r3 = Math.min(r3, width / 2, height / 2);
565
+ r4 = Math.min(r4, width / 2, height / 2);
566
+ return `M ${x + r1},${y}
567
+ H ${x + width - r2}
568
+ A ${r2},${r2} 0 0 1 ${x + width},${y + r2}
569
+ V ${y + height - r3}
570
+ A ${r3},${r3} 0 0 1 ${x + width - r3},${y + height}
571
+ H ${x + r4}
572
+ A ${r4},${r4} 0 0 1 ${x},${y + height - r4}
573
+ V ${y + r1}
574
+ A ${r1},${r1} 0 0 1 ${x + r1},${y} Z`;
575
+ }
576
+
577
+ function svgMouseMove(event, shapeType, shapeToFind, grid, config, canvasObject, data) {
578
+ const gridSize = config.canvas.grid.gridSize || defaultConfig.canvas.grid.gridSize;
579
+ const zoomTransform = d3__namespace.zoomTransform(canvasObject.svg.node());
580
+ const [cursorX, cursorY] = d3__namespace.pointer(event, canvasObject.svg.node());
581
+ const adjustedX = (cursorX - zoomTransform.x) / zoomTransform.k;
582
+ const adjustedY = (cursorY - zoomTransform.y) / zoomTransform.k;
583
+ let exactPosition;
584
+ if (config.canvasProperties.snapToGrid) {
585
+ exactPosition = snapToGrid(adjustedX, adjustedY, gridSize);
586
+ }
587
+ else {
588
+ exactPosition = { x: adjustedX, y: adjustedY };
589
+ }
590
+ if (shapeToFind.previewEnabled) {
591
+ createShapePreview(shapeType, exactPosition.x, exactPosition.y, canvasObject, shapeToFind);
592
+ }
593
+ }
594
+ function createShapePreview(shapeType, x, y, canvasObject, shapeToFind) {
595
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
596
+ removeAllPreview(canvasObject);
597
+ let elementId = `preview_${shapeType}`;
598
+ let shape;
599
+ if (shapeType === "rectangle") {
600
+ // Compute top-left corner assuming shape's position is the center.
601
+ const width = (_a = shapeToFind.width) !== null && _a !== void 0 ? _a : 120;
602
+ const height = (_b = shapeToFind.height) !== null && _b !== void 0 ? _b : 60;
603
+ const x0 = x - width / 2;
604
+ const y0 = y - height / 2;
605
+ const r1 = ((_c = shapeToFind.borderRadius) === null || _c === void 0 ? void 0 : _c.leftTop) || 0;
606
+ const r2 = ((_d = shapeToFind.borderRadius) === null || _d === void 0 ? void 0 : _d.rightTop) || 0;
607
+ const r3 = ((_e = shapeToFind.borderRadius) === null || _e === void 0 ? void 0 : _e.rightBottom) || 0;
608
+ const r4 = ((_f = shapeToFind.borderRadius) === null || _f === void 0 ? void 0 : _f.leftBottom) || 0;
609
+ const pathData = roundedRectPath(x0, y0, width, height, r1, r2, r3, r4);
610
+ shape = canvasObject.elements.append("path")
611
+ .attr("id", elementId)
612
+ .attr("d", pathData)
613
+ .attr("fill", shapeToFind.color)
614
+ .attr("stroke", shapeToFind.stroke.color)
615
+ .attr("stroke-width", shapeToFind.stroke.width)
616
+ .attr("stroke-dasharray", ((_g = shapeToFind.stroke.strokeDasharray) === null || _g === void 0 ? void 0 : _g.join(" ")) || null)
617
+ .attr("opacity", (_h = shapeToFind.previewTransparency) !== null && _h !== void 0 ? _h : 0.5);
618
+ }
619
+ else if (shapeType === "circle") {
620
+ shape = canvasObject.elements.append("circle")
621
+ .attr("id", elementId)
622
+ .attr("cx", x)
623
+ .attr("cy", y)
624
+ .attr("r", (_j = shapeToFind.radius) !== null && _j !== void 0 ? _j : 30)
625
+ .attr("fill", shapeToFind.color)
626
+ .attr("stroke", shapeToFind.stroke.color)
627
+ .attr("stroke-width", shapeToFind.stroke.width)
628
+ .attr("opacity", (_k = shapeToFind.previewTransparency) !== null && _k !== void 0 ? _k : 0.5);
629
+ }
630
+ else if (shapeType === "rhombus") {
631
+ shape = canvasObject.elements.append("polygon")
632
+ .attr("id", elementId)
633
+ .attr("points", `${x},${y - 30} ${x + 30},${y} ${x},${y + 30} ${x - 30},${y}`)
634
+ .attr("fill", shapeToFind.color)
635
+ .attr("stroke", shapeToFind.stroke.color)
636
+ .attr("stroke-width", shapeToFind.stroke.width)
637
+ .attr("opacity", (_l = shapeToFind.previewTransparency) !== null && _l !== void 0 ? _l : 0.5);
638
+ }
639
+ else {
640
+ return null;
641
+ }
642
+ return shape;
643
+ }
644
+ function removeAllPreview(canvasObject) {
645
+ canvasObject.elements.selectAll("path[id^='preview_'], polygon[id^='preview_'], circle[id^='preview_']").remove();
646
+ }
647
+
648
+ /**
649
+ * Handles canvas click: if a placement is pending (preview active), places the node
650
+ * at the snapped position and clears the preview.
651
+ */
652
+ function svgMouseClick(event, api) {
653
+ if (event.defaultPrevented)
654
+ return; // drag fired — ignore
655
+ const ctx = api.getPlacementContext();
656
+ if (!ctx)
657
+ return;
658
+ const point = api.getCanvasPoint(event);
659
+ const { shapeType, shapeConfig } = ctx;
660
+ const node = {
661
+ id: generatePlacedNodeId(),
662
+ type: shapeType,
663
+ shapeVariantId: shapeConfig.id,
664
+ x: point.x,
665
+ y: point.y,
666
+ width: shapeConfig.width,
667
+ height: shapeConfig.height,
668
+ radius: shapeConfig.radius,
669
+ meta: {},
670
+ };
671
+ api.placeNode(node);
672
+ removeAllPreview(api.canvasObject);
673
+ api.clearPlacementContext();
674
+ api.removePlacementListeners();
675
+ }
676
+
677
+ /**
678
+ * Creates and returns a D3 drag behavior for placed nodes.
679
+ */
680
+ function createDragBehavior(api) {
681
+ return d3__namespace.drag()
682
+ .on("start", function (event, d) {
683
+ event.sourceEvent.stopPropagation();
684
+ d3__namespace.select(this).raise().classed("dragging", true);
685
+ })
686
+ .on("drag", function (event, d) {
687
+ var _a, _b;
688
+ const gridSize = (_b = (_a = api.config.canvas.grid) === null || _a === void 0 ? void 0 : _a.gridSize) !== null && _b !== void 0 ? _b : 20;
689
+ const zoomTransform = d3__namespace.zoomTransform(api.svgNode);
690
+ const [px, py] = d3__namespace.pointer(event.sourceEvent, api.svgNode);
691
+ let newX = (px - zoomTransform.x) / zoomTransform.k;
692
+ let newY = (py - zoomTransform.y) / zoomTransform.k;
693
+ if (api.config.canvasProperties.snapToGrid) {
694
+ const snapped = snapToGrid(newX, newY, gridSize);
695
+ newX = snapped.x;
696
+ newY = snapped.y;
697
+ }
698
+ d3__namespace.select(this).attr("transform", `translate(${newX},${newY})`);
699
+ renderAlignmentGuides(newX, newY, d.id, api);
700
+ })
701
+ .on("end", function (event, d) {
702
+ var _a, _b;
703
+ d3__namespace.select(this).classed("dragging", false);
704
+ const gridSize = (_b = (_a = api.config.canvas.grid) === null || _a === void 0 ? void 0 : _a.gridSize) !== null && _b !== void 0 ? _b : 20;
705
+ const zoomTransform = d3__namespace.zoomTransform(api.svgNode);
706
+ const [px, py] = d3__namespace.pointer(event.sourceEvent, api.svgNode);
707
+ let finalX = (px - zoomTransform.x) / zoomTransform.k;
708
+ let finalY = (py - zoomTransform.y) / zoomTransform.k;
709
+ if (api.config.canvasProperties.snapToGrid) {
710
+ const snapped = snapToGrid(finalX, finalY, gridSize);
711
+ finalX = snapped.x;
712
+ finalY = snapped.y;
713
+ }
714
+ api.updateNodePosition(d.id, finalX, finalY);
715
+ if (api.canvasObject.guides) {
716
+ api.canvasObject.guides.selectAll("*").remove();
717
+ }
718
+ });
719
+ }
720
+ function renderAlignmentGuides(x, y, nodeId, api) {
721
+ var _a, _b, _c, _d;
722
+ if (!api.canvasObject.guides)
723
+ return;
724
+ const alignCfg = api.config.canvasProperties.alignmentLines;
725
+ if (!(alignCfg === null || alignCfg === void 0 ? void 0 : alignCfg.enabled))
726
+ return;
727
+ const nodes = api.getPlacedNodes().filter(n => n.id !== nodeId);
728
+ const guidesLayer = api.canvasObject.guides;
729
+ guidesLayer.selectAll("*").remove();
730
+ const threshold = 5;
731
+ const guideColor = (_a = alignCfg.color) !== null && _a !== void 0 ? _a : "var(--zenode-guide-color, #ffaa00)";
732
+ const strokeWidth = (_b = alignCfg.width) !== null && _b !== void 0 ? _b : 1;
733
+ const dashArray = alignCfg.dashed ? ((_d = (_c = alignCfg.dashArray) === null || _c === void 0 ? void 0 : _c.join(" ")) !== null && _d !== void 0 ? _d : "4 4") : null;
734
+ const isFull = alignCfg.guideLineMode === 'full';
735
+ console.log('Guide mode:', alignCfg.guideLineMode, 'isFull:', isFull);
736
+ // For full mode: use a very large value in canvas-space (before zoom transform)
737
+ // The guides layer is inside the zoom group so coordinates are in canvas-space already
738
+ const FULL_EXTENT = 1e6;
739
+ nodes.forEach(other => {
740
+ // Normalize other node center (rectangles store top-left, circles store center)
741
+ const otherCX = other.x;
742
+ const otherCY = other.y;
743
+ // Horizontal alignment (same Y center)
744
+ if (Math.abs(otherCY - y) < threshold) {
745
+ const x1 = isFull ? -1e6 : Math.min(x, otherCX) - 100;
746
+ const x2 = isFull ? FULL_EXTENT : Math.max(x, otherCX) + 100;
747
+ guidesLayer.append("line")
748
+ .attr("x1", x1).attr("x2", x2)
749
+ .attr("y1", otherCY).attr("y2", otherCY)
750
+ .attr("stroke", guideColor)
751
+ .attr("stroke-width", strokeWidth)
752
+ .attr("stroke-dasharray", dashArray);
753
+ }
754
+ // Vertical alignment (same X center)
755
+ if (Math.abs(otherCX - x) < threshold) {
756
+ const y1 = isFull ? -1e6 : Math.min(y, otherCY) - 100;
757
+ const y2 = isFull ? FULL_EXTENT : Math.max(y, otherCY) + 100;
758
+ guidesLayer.append("line")
759
+ .attr("x1", otherCX).attr("x2", otherCX)
760
+ .attr("y1", y1).attr("y2", y2)
761
+ .attr("stroke", guideColor)
762
+ .attr("stroke-width", strokeWidth)
763
+ .attr("stroke-dasharray", dashArray);
764
+ }
765
+ });
766
+ }
767
+
768
+ /**
769
+ * Renders placed nodes using D3 data join. Keeps g.placed-nodes in sync with engine state.
770
+ */
771
+ function getShapeStyle(node, config) {
772
+ var _a;
773
+ const list = (_a = config.shapes.default) === null || _a === void 0 ? void 0 : _a[node.type];
774
+ if (!Array.isArray(list))
775
+ return undefined;
776
+ return list.find((s) => s.id === node.shapeVariantId);
777
+ }
778
+ function drawPlacedRectangle(g, style) {
779
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
780
+ const width = (_a = style.width) !== null && _a !== void 0 ? _a : 120;
781
+ const height = (_b = style.height) !== null && _b !== void 0 ? _b : 60;
782
+ const x0 = -width / 2;
783
+ const y0 = -height / 2;
784
+ const r1 = (_d = (_c = style.borderRadius) === null || _c === void 0 ? void 0 : _c.leftTop) !== null && _d !== void 0 ? _d : 0;
785
+ const r2 = (_f = (_e = style.borderRadius) === null || _e === void 0 ? void 0 : _e.rightTop) !== null && _f !== void 0 ? _f : 0;
786
+ const r3 = (_h = (_g = style.borderRadius) === null || _g === void 0 ? void 0 : _g.rightBottom) !== null && _h !== void 0 ? _h : 0;
787
+ const r4 = (_k = (_j = style.borderRadius) === null || _j === void 0 ? void 0 : _j.leftBottom) !== null && _k !== void 0 ? _k : 0;
788
+ const pathData = roundedRectPath(x0, y0, width, height, r1, r2, r3, r4);
789
+ g.append("path")
790
+ .attr("d", pathData)
791
+ .attr("fill", style.color)
792
+ .attr("stroke", style.stroke.color)
793
+ .attr("stroke-width", style.stroke.width)
794
+ .attr("stroke-dasharray", ((_l = style.stroke.strokeDasharray) === null || _l === void 0 ? void 0 : _l.length) ? style.stroke.strokeDasharray.join(" ") : null);
795
+ }
796
+ function drawPlacedCircle(g, style) {
797
+ var _a, _b;
798
+ const r = (_a = style.radius) !== null && _a !== void 0 ? _a : 30;
799
+ g.append("circle")
800
+ .attr("cx", 0)
801
+ .attr("cy", 0)
802
+ .attr("r", r)
803
+ .attr("fill", style.color)
804
+ .attr("stroke", style.stroke.color)
805
+ .attr("stroke-width", style.stroke.width)
806
+ .attr("stroke-dasharray", ((_b = style.stroke.strokeDasharray) === null || _b === void 0 ? void 0 : _b.length) ? style.stroke.strokeDasharray.join(" ") : null);
807
+ }
808
+ function drawPlacedRhombus(g, style) {
809
+ var _a, _b;
810
+ const size = (_a = style.width) !== null && _a !== void 0 ? _a : 60;
811
+ const points = `0,${-size / 2} ${size / 2},0 0,${size / 2} ${-size / 2},0`;
812
+ g.append("polygon")
813
+ .attr("points", points)
814
+ .attr("fill", style.color)
815
+ .attr("stroke", style.stroke.color)
816
+ .attr("stroke-width", style.stroke.width)
817
+ .attr("stroke-dasharray", ((_b = style.stroke.strokeDasharray) === null || _b === void 0 ? void 0 : _b.length) ? style.stroke.strokeDasharray.join(" ") : null);
818
+ }
819
+ /**
820
+ * Renders the placed nodes layer using a D3 data join. Call after state changes.
821
+ * @param placedNodesGroup - D3 selection for g.placed-nodes
822
+ * @param placedNodes - Current array of placed nodes
823
+ * @param config - Engine config for shape styles
824
+ */
825
+ function renderPlacedNodes(placedNodesGroup, placedNodes, api) {
826
+ const dragBehavior = createDragBehavior(api);
827
+ const binding = placedNodesGroup
828
+ .selectAll("g.node")
829
+ .data(placedNodes, (d) => d.id);
830
+ binding
831
+ .join((enter) => {
832
+ const g = enter
833
+ .append("g")
834
+ .attr("class", "node placed-node")
835
+ .attr("data-id", (d) => d.id)
836
+ .attr("transform", (d) => `translate(${d.x},${d.y})`)
837
+ .call(dragBehavior)
838
+ .on("click", function (event) {
839
+ var _a, _b, _c, _d;
840
+ event.stopPropagation();
841
+ const isSelected = d3__namespace.select(this).classed("selected");
842
+ d3__namespace.selectAll("g.placed-node").classed("selected", false).select(".selection-ring").remove();
843
+ if (!isSelected) {
844
+ const sel = d3__namespace.select(this);
845
+ sel.classed("selected", true);
846
+ const d = sel.datum();
847
+ const selectionStroke = "var(--zenode-selection-color, #4A90E2)";
848
+ const pad = 4;
849
+ if (d.type === "circle") {
850
+ const r = ((_a = d.radius) !== null && _a !== void 0 ? _a : 30) + pad;
851
+ sel.append("circle")
852
+ .attr("class", "selection-ring")
853
+ .attr("cx", 0).attr("cy", 0).attr("r", r)
854
+ .attr("fill", "none")
855
+ .attr("stroke", selectionStroke)
856
+ .attr("stroke-width", 2)
857
+ .attr("stroke-dasharray", "4 2")
858
+ .style("pointer-events", "none");
859
+ }
860
+ else if (d.type === "rhombus") {
861
+ const size = ((_b = d.width) !== null && _b !== void 0 ? _b : 60) / 2 + pad;
862
+ sel.append("polygon")
863
+ .attr("class", "selection-ring")
864
+ .attr("points", `0,${-size} ${size},0 0,${size} ${-size},0`)
865
+ .attr("fill", "none")
866
+ .attr("stroke", selectionStroke)
867
+ .attr("stroke-width", 2)
868
+ .attr("stroke-dasharray", "4 2")
869
+ .style("pointer-events", "none");
870
+ }
871
+ else {
872
+ const w = (_c = d.width) !== null && _c !== void 0 ? _c : 120;
873
+ const h = (_d = d.height) !== null && _d !== void 0 ? _d : 60;
874
+ sel.append("rect")
875
+ .attr("class", "selection-ring")
876
+ .attr("x", -w / 2 - pad).attr("y", -h / 2 - pad)
877
+ .attr("width", w + pad * 2).attr("height", h + pad * 2)
878
+ .attr("rx", 3)
879
+ .attr("fill", "none")
880
+ .attr("stroke", selectionStroke)
881
+ .attr("stroke-width", 2)
882
+ .attr("stroke-dasharray", "4 2")
883
+ .style("pointer-events", "none");
884
+ }
885
+ }
886
+ });
887
+ g.each(function (d) {
888
+ const style = getShapeStyle(d, api.config);
889
+ if (!style)
890
+ return;
891
+ const el = d3__namespace.select(this);
892
+ if (d.type === "rectangle")
893
+ drawPlacedRectangle(el, style);
894
+ else if (d.type === "circle")
895
+ drawPlacedCircle(el, style);
896
+ else if (d.type === "rhombus")
897
+ drawPlacedRhombus(el, style);
898
+ });
899
+ return g;
900
+ }, (update) => update.attr("transform", (d) => `translate(${d.x},${d.y})`), (exit) => exit.remove());
901
+ }
902
+
903
+ function getNodeCenter(node) {
904
+ return { x: node.x, y: node.y };
905
+ }
906
+ /**
907
+ * Draws all connections as straight lines between node centers.
908
+ */
909
+ function renderConnections(connectionsGroup, connections, placedNodes) {
910
+ const nodeById = new Map(placedNodes.map((n) => [n.id, n]));
911
+ const valid = connections.filter((c) => nodeById.has(c.sourceNodeId) && nodeById.has(c.targetNodeId));
912
+ const binding = connectionsGroup
913
+ .selectAll("line.connection")
914
+ .data(valid, (d) => d.id);
915
+ binding
916
+ .join((enter) => {
917
+ return enter
918
+ .append("line")
919
+ .attr("class", "connection")
920
+ .attr("data-connection-id", (d) => d.id)
921
+ .attr("stroke", "#333")
922
+ .attr("stroke-width", 2)
923
+ .attr("x1", (d) => getNodeCenter(nodeById.get(d.sourceNodeId)).x)
924
+ .attr("y1", (d) => getNodeCenter(nodeById.get(d.sourceNodeId)).y)
925
+ .attr("x2", (d) => getNodeCenter(nodeById.get(d.targetNodeId)).x)
926
+ .attr("y2", (d) => getNodeCenter(nodeById.get(d.targetNodeId)).y);
927
+ }, (update) => {
928
+ return update
929
+ .attr("x1", (d) => getNodeCenter(nodeById.get(d.sourceNodeId)).x)
930
+ .attr("y1", (d) => getNodeCenter(nodeById.get(d.sourceNodeId)).y)
931
+ .attr("x2", (d) => getNodeCenter(nodeById.get(d.targetNodeId)).x)
932
+ .attr("y2", (d) => getNodeCenter(nodeById.get(d.targetNodeId)).y);
933
+ }, (exit) => exit.remove());
934
+ }
935
+
936
+ function mergeConfig(userConfig) {
937
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50;
938
+ return {
939
+ canvas: {
940
+ width: (_b = (_a = userConfig.canvas) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : defaultConfig.canvas.width,
941
+ height: (_d = (_c = userConfig.canvas) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : defaultConfig.canvas.height,
942
+ backgroundColor: (_f = (_e = userConfig.canvas) === null || _e === void 0 ? void 0 : _e.backgroundColor) !== null && _f !== void 0 ? _f : defaultConfig.canvas.backgroundColor,
943
+ canvasClasses: (_h = (_g = userConfig.canvas) === null || _g === void 0 ? void 0 : _g.canvasClasses) !== null && _h !== void 0 ? _h : defaultConfig.canvas.canvasClasses,
944
+ locked: (_k = (_j = userConfig.canvas) === null || _j === void 0 ? void 0 : _j.locked) !== null && _k !== void 0 ? _k : defaultConfig.canvas.locked,
945
+ grid: {
946
+ gridEnabled: (_o = (_m = (_l = userConfig.canvas) === null || _l === void 0 ? void 0 : _l.grid) === null || _m === void 0 ? void 0 : _m.gridEnabled) !== null && _o !== void 0 ? _o : defaultConfig.canvas.grid.gridEnabled,
947
+ gridType: (_r = (_q = (_p = userConfig.canvas) === null || _p === void 0 ? void 0 : _p.grid) === null || _q === void 0 ? void 0 : _q.gridType) !== null && _r !== void 0 ? _r : defaultConfig.canvas.grid.gridType,
948
+ gridSize: (_u = (_t = (_s = userConfig.canvas) === null || _s === void 0 ? void 0 : _s.grid) === null || _t === void 0 ? void 0 : _t.gridSize) !== null && _u !== void 0 ? _u : defaultConfig.canvas.grid.gridSize,
949
+ gridColor: (_x = (_w = (_v = userConfig.canvas) === null || _v === void 0 ? void 0 : _v.grid) === null || _w === void 0 ? void 0 : _w.gridColor) !== null && _x !== void 0 ? _x : defaultConfig.canvas.grid.gridColor,
950
+ gridDimension: (_0 = (_z = (_y = userConfig.canvas) === null || _y === void 0 ? void 0 : _y.grid) === null || _z === void 0 ? void 0 : _z.gridDimension) !== null && _0 !== void 0 ? _0 : defaultConfig.canvas.grid.gridDimension,
951
+ gridTransparency: (_3 = (_2 = (_1 = userConfig.canvas) === null || _1 === void 0 ? void 0 : _1.grid) === null || _2 === void 0 ? void 0 : _2.gridTransparency) !== null && _3 !== void 0 ? _3 : defaultConfig.canvas.grid.gridTransparency,
952
+ gridShape: (_6 = (_5 = (_4 = userConfig.canvas) === null || _4 === void 0 ? void 0 : _4.grid) === null || _5 === void 0 ? void 0 : _5.gridShape) !== null && _6 !== void 0 ? _6 : defaultConfig.canvas.grid.gridShape,
953
+ crossLength: (_9 = (_8 = (_7 = userConfig.canvas) === null || _7 === void 0 ? void 0 : _7.grid) === null || _8 === void 0 ? void 0 : _8.crossLength) !== null && _9 !== void 0 ? _9 : defaultConfig.canvas.grid.crossLength,
954
+ sheetDimension: (_12 = (_11 = (_10 = userConfig.canvas) === null || _10 === void 0 ? void 0 : _10.grid) === null || _11 === void 0 ? void 0 : _11.sheetDimension) !== null && _12 !== void 0 ? _12 : defaultConfig.canvas.grid.sheetDimension
955
+ }
956
+ },
957
+ canvasProperties: {
958
+ zoomEnabled: (_14 = (_13 = userConfig.canvasProperties) === null || _13 === void 0 ? void 0 : _13.zoomEnabled) !== null && _14 !== void 0 ? _14 : defaultConfig.canvasProperties.zoomEnabled,
959
+ zoomExtent: (_16 = (_15 = userConfig.canvasProperties) === null || _15 === void 0 ? void 0 : _15.zoomExtent) !== null && _16 !== void 0 ? _16 : defaultConfig.canvasProperties.zoomExtent,
960
+ zoomOnDoubleClick: (_18 = (_17 = userConfig.canvasProperties) === null || _17 === void 0 ? void 0 : _17.zoomOnDoubleClick) !== null && _18 !== void 0 ? _18 : defaultConfig.canvasProperties.zoomOnDoubleClick,
961
+ zoomScale: (_20 = (_19 = userConfig.canvasProperties) === null || _19 === void 0 ? void 0 : _19.zoomScale) !== null && _20 !== void 0 ? _20 : defaultConfig.canvasProperties.zoomScale,
962
+ zoomOnScroll: (_22 = (_21 = userConfig.canvasProperties) === null || _21 === void 0 ? void 0 : _21.zoomOnScroll) !== null && _22 !== void 0 ? _22 : defaultConfig.canvasProperties.zoomOnScroll,
963
+ zoomDuration: (_24 = (_23 = userConfig.canvasProperties) === null || _23 === void 0 ? void 0 : _23.zoomDuration) !== null && _24 !== void 0 ? _24 : defaultConfig.canvasProperties.zoomDuration,
964
+ panEnabled: (_26 = (_25 = userConfig.canvasProperties) === null || _25 === void 0 ? void 0 : _25.panEnabled) !== null && _26 !== void 0 ? _26 : defaultConfig.canvasProperties.panEnabled,
965
+ snapToGrid: (_28 = (_27 = userConfig.canvasProperties) === null || _27 === void 0 ? void 0 : _27.snapToGrid) !== null && _28 !== void 0 ? _28 : defaultConfig.canvasProperties.snapToGrid,
966
+ alignmentLines: {
967
+ enabled: (_31 = (_30 = (_29 = userConfig.canvasProperties) === null || _29 === void 0 ? void 0 : _29.alignmentLines) === null || _30 === void 0 ? void 0 : _30.enabled) !== null && _31 !== void 0 ? _31 : defaultConfig.canvasProperties.alignmentLines.enabled,
968
+ color: (_34 = (_33 = (_32 = userConfig.canvasProperties) === null || _32 === void 0 ? void 0 : _32.alignmentLines) === null || _33 === void 0 ? void 0 : _33.color) !== null && _34 !== void 0 ? _34 : defaultConfig.canvasProperties.alignmentLines.color,
969
+ width: (_37 = (_36 = (_35 = userConfig.canvasProperties) === null || _35 === void 0 ? void 0 : _35.alignmentLines) === null || _36 === void 0 ? void 0 : _36.width) !== null && _37 !== void 0 ? _37 : defaultConfig.canvasProperties.alignmentLines.width,
970
+ dashed: (_40 = (_39 = (_38 = userConfig.canvasProperties) === null || _38 === void 0 ? void 0 : _38.alignmentLines) === null || _39 === void 0 ? void 0 : _39.dashed) !== null && _40 !== void 0 ? _40 : defaultConfig.canvasProperties.alignmentLines.dashed,
971
+ dashArray: (_43 = (_42 = (_41 = userConfig.canvasProperties) === null || _41 === void 0 ? void 0 : _41.alignmentLines) === null || _42 === void 0 ? void 0 : _42.dashArray) !== null && _43 !== void 0 ? _43 : defaultConfig.canvasProperties.alignmentLines.dashArray,
972
+ guideLineMode: (_46 = (_45 = (_44 = userConfig.canvasProperties) === null || _44 === void 0 ? void 0 : _44.alignmentLines) === null || _45 === void 0 ? void 0 : _45.guideLineMode) !== null && _46 !== void 0 ? _46 : defaultConfig.canvasProperties.alignmentLines.guideLineMode
973
+ }
974
+ },
975
+ shapes: (_47 = userConfig.shapes) !== null && _47 !== void 0 ? _47 : defaultConfig.shapes,
976
+ connections: (_48 = userConfig.connections) !== null && _48 !== void 0 ? _48 : defaultConfig.connections,
977
+ globalProperties: (_49 = userConfig.globalProperties) !== null && _49 !== void 0 ? _49 : defaultConfig.globalProperties,
978
+ dragOptions: (_50 = userConfig.dragOptions) !== null && _50 !== void 0 ? _50 : defaultConfig.dragOptions
979
+ };
980
+ }
981
+
982
+ // src/core/engine.ts
983
+ class ZenodeEngine {
984
+ constructor(container, config) {
985
+ this.shapeMap = new Map();
986
+ this.shapes = new Map();
987
+ this.connections = [];
988
+ /** Placed nodes on the canvas. Source of truth for g.placed-nodes layer. */
989
+ this.placedNodes = [];
990
+ /** When set, next click will place a node of this type/config (preview → placed). */
991
+ this.placementContext = null;
992
+ this.canvasObject = {
993
+ svg: null,
994
+ grid: null,
995
+ elements: null,
996
+ canvasContainer: null,
997
+ connections: null,
998
+ placedNodes: null,
999
+ guides: null,
1000
+ };
1001
+ this.container = container;
1002
+ this.config = mergeConfig(config);
1003
+ this.eventManager = new EventManager();
1004
+ this.initializeCanvas();
1005
+ }
1006
+ initializeCanvas() {
1007
+ this.canvasObject = drawCanvas(this.container ? `#${this.container.id}` : "body", this.config.canvas);
1008
+ this.svg = this.canvasObject.svg;
1009
+ this.grid = drawGrid(this.svg, this.config.canvas, this.canvasObject.grid);
1010
+ this.alignmentLine = this.svg.append("g").attr("class", "alignment-line");
1011
+ this.canvasContainerGroup = this.canvasObject.canvasContainer;
1012
+ this.zoomManager = new ZoomManager(this.canvasContainerGroup, this.svg, this.config, (eventType, event) => {
1013
+ this.eventManager.trigger(eventType, event);
1014
+ });
1015
+ console.log("SVG canvas and grid created.");
1016
+ }
1017
+ on(eventType, callback) {
1018
+ this.eventManager.on(eventType, callback);
1019
+ }
1020
+ /** SVG root DOM node — passed to DragApi for correct pointer coordinate transform */
1021
+ get svgNode() {
1022
+ return this.svg.node();
1023
+ }
1024
+ /** Returns current placement context (shape type + config for next click). */
1025
+ getPlacementContext() {
1026
+ return this.placementContext;
1027
+ }
1028
+ /** Sets placement context so the next canvas click places a node of this type/config. */
1029
+ setPlacementContext(shapeType, shapeConfig) {
1030
+ this.placementContext = { shapeType, shapeConfig };
1031
+ }
1032
+ /** Clears placement context (e.g. after placing or cancel). */
1033
+ clearPlacementContext() {
1034
+ this.placementContext = null;
1035
+ }
1036
+ /** Removes mousemove and click handlers used for placement; stops preview. */
1037
+ removePlacementListeners() {
1038
+ this.svg.on("mousemove", null);
1039
+ this.svg.on("click", null);
1040
+ }
1041
+ /**
1042
+ * Places a node on the canvas: appends to state and re-renders g.placed-nodes.
1043
+ * @param node - Node to place (id must be unique; use generatePlacedNodeId() if creating new).
1044
+ */
1045
+ placeNode(node) {
1046
+ this.placedNodes = [...this.placedNodes, node];
1047
+ if (this.canvasObject.placedNodes) {
1048
+ renderPlacedNodes(this.canvasObject.placedNodes, this.placedNodes, this);
1049
+ }
1050
+ this.eventManager.trigger("node:placed", { node });
1051
+ }
1052
+ /** Returns a copy of the current placed nodes (immutable). */
1053
+ getPlacedNodes() {
1054
+ return [...this.placedNodes];
1055
+ }
1056
+ /**
1057
+ * Updates a placed node's position and triggers sub-renders.
1058
+ */
1059
+ updateNodePosition(id, x, y) {
1060
+ this.placedNodes = this.placedNodes.map((n) => (n.id === id ? Object.assign(Object.assign({}, n), { x, y }) : n));
1061
+ // Re-render nodes (this might be handled by the renderer d3 join,
1062
+ // but we need to ensure connections follow)
1063
+ if (this.canvasObject.connections) {
1064
+ this.reRenderConnections();
1065
+ }
1066
+ this.eventManager.trigger("node:moved", { id, x, y });
1067
+ }
1068
+ reRenderConnections() {
1069
+ if (this.canvasObject.connections) {
1070
+ renderConnections(this.canvasObject.connections, this.connections, this.placedNodes);
1071
+ }
1072
+ }
1073
+ /**
1074
+ * Converts a mouse event to canvas coordinates (with optional grid snap).
1075
+ * Used for placement and hit-testing.
1076
+ */
1077
+ getCanvasPoint(event) {
1078
+ var _a, _b;
1079
+ const gridSize = (_b = (_a = this.config.canvas.grid) === null || _a === void 0 ? void 0 : _a.gridSize) !== null && _b !== void 0 ? _b : 20;
1080
+ const zoomTransform = d3__namespace.zoomTransform(this.svg.node());
1081
+ const [cursorX, cursorY] = d3__namespace.pointer(event, this.svg.node());
1082
+ const adjustedX = (cursorX - zoomTransform.x) / zoomTransform.k;
1083
+ const adjustedY = (cursorY - zoomTransform.y) / zoomTransform.k;
1084
+ if (this.config.canvasProperties.snapToGrid) {
1085
+ return snapToGrid(adjustedX, adjustedY, gridSize);
1086
+ }
1087
+ return { x: adjustedX, y: adjustedY };
1088
+ }
1089
+ /**
1090
+ * Creates a shape on the canvas (preview on move, place on click).
1091
+ * @param shapeType - Type of shape ('rectangle', 'circle', 'rhombus').
1092
+ * @param id - Shape variant id from config (e.g. 'task0').
1093
+ * @param data - Optional inner content for preview
1094
+ */
1095
+ createShape(shapeType, id, data) {
1096
+ var _a, _b;
1097
+ const shapeList = (_b = (_a = this.config.shapes.default) === null || _a === void 0 ? void 0 : _a[shapeType]) !== null && _b !== void 0 ? _b : [];
1098
+ if (!shapeList.length) {
1099
+ console.error(`No shapes found for type "${shapeType}".`);
1100
+ return;
1101
+ }
1102
+ const shapeToFind = shapeList.find((shape) => shape.id === id);
1103
+ if (!shapeToFind) {
1104
+ console.error(`Shape ID "${id}" not found in type "${shapeType}".`);
1105
+ return;
1106
+ }
1107
+ this.removePlacementListeners();
1108
+ this.setPlacementContext(shapeType, shapeToFind);
1109
+ this.svg.on("mousemove", (event) => svgMouseMove(event, shapeType, shapeToFind, this.grid, this.config, this.canvasObject));
1110
+ this.svg.on("click", (event) => svgMouseClick(event, this));
1111
+ }
1112
+ /**
1113
+ * Creates a connection between two placed nodes by their node ids.
1114
+ * (Full connector UI is Phase 2; this records the connection in state.)
1115
+ * @param sourceNodeId - Placed node id (from getPlacedNodes()[i].id).
1116
+ * @param targetNodeId - Placed node id.
1117
+ */
1118
+ createConnection(sourceNodeId, targetNodeId) {
1119
+ const fromExists = this.placedNodes.some((n) => n.id === sourceNodeId);
1120
+ const toExists = this.placedNodes.some((n) => n.id === targetNodeId);
1121
+ if (!fromExists || !toExists) {
1122
+ console.warn(`One or both nodes do not exist. Use getPlacedNodes() to get valid node ids.`);
1123
+ return;
1124
+ }
1125
+ const connection = {
1126
+ id: `conn-${sourceNodeId}-${targetNodeId}`,
1127
+ sourceNodeId,
1128
+ targetNodeId,
1129
+ type: "straight",
1130
+ };
1131
+ this.connections = [...this.connections, connection];
1132
+ if (this.canvasObject.connections) {
1133
+ renderConnections(this.canvasObject.connections, this.connections, this.placedNodes);
1134
+ }
1135
+ this.eventManager.trigger("connection:created", { connection });
1136
+ }
1137
+ lockedTheCanvas(locked) {
1138
+ lockedCanvas(locked, this.svg, this.zoomBehaviour);
1139
+ }
1140
+ gridToggles(toggle) {
1141
+ toggleGrid(toggle);
1142
+ }
1143
+ }
1144
+
1145
+ let engineInstance = null;
1146
+ /**
1147
+ * Initializes the Zenode engine.
1148
+ * @param containerSelector The selector for the container element.
1149
+ * @param userConfig Optional custom configuration.
1150
+ * @throws Error if container is not found.
1151
+ */
1152
+ function initializeCanvas(containerSelector, userConfig) {
1153
+ if (!engineInstance) {
1154
+ const inputConfig = Object.assign({}, userConfig);
1155
+ console.log(inputConfig);
1156
+ const container = document.querySelector(containerSelector);
1157
+ if (!container) {
1158
+ throw new Error(`Container '${containerSelector}' not found in DOM.`);
1159
+ }
1160
+ engineInstance = new ZenodeEngine(container, inputConfig);
1161
+ }
1162
+ else {
1163
+ console.warn("ZenodeEngine is already initialized!");
1164
+ }
1165
+ }
1166
+ /**
1167
+ * Creates a shape dynamically on the canvas.
1168
+ * @param type Shape type (e.g., "rectangle", "circle").
1169
+ * @param name Optional shape name.
1170
+ * @throws Error if engine is not initialized or parameters are invalid.
1171
+ */
1172
+ function createShape(type, id) {
1173
+ if (!engineInstance) {
1174
+ throw new Error("ZenodeEngine is not initialized. Call initialize() first.");
1175
+ }
1176
+ if (typeof type !== "string" || !["rectangle", "circle", "rhombus"].includes(type)) {
1177
+ throw new Error(`Invalid shape type '${type}'. Supported types: rectangle, circle, rhombus.`);
1178
+ }
1179
+ engineInstance.createShape(type, id);
1180
+ // engineInstance.createShape(type, x, y, name);
1181
+ }
1182
+ /**
1183
+ * Creates a connection between two shapes.
1184
+ * @param from The ID or name of the first shape.
1185
+ * @param to The ID or name of the second shape.
1186
+ * @throws Error if engine is not initialized or shapes are missing.
1187
+ */
1188
+ function createConnection(from, to) {
1189
+ if (!engineInstance) {
1190
+ throw new Error("ZenodeEngine is not initialized. Call initialize() first.");
1191
+ }
1192
+ if (!from || !to) {
1193
+ throw new Error("Both 'from' and 'to' shape names are required.");
1194
+ }
1195
+ engineInstance.createConnection(from, to);
1196
+ }
1197
+ /**
1198
+ * Returns the list of placed nodes (for use with createConnection node ids).
1199
+ */
1200
+ function getPlacedNodes() {
1201
+ if (!engineInstance) {
1202
+ throw new Error("ZenodeEngine is not initialized. Call initializeCanvas first.");
1203
+ }
1204
+ return engineInstance.getPlacedNodes();
1205
+ }
1206
+ /**
1207
+ * Connects the first two placed nodes. Convenience for demos.
1208
+ * @returns true if a connection was created, false otherwise
1209
+ */
1210
+ function connectFirstTwoNodes() {
1211
+ if (!engineInstance) {
1212
+ throw new Error("ZenodeEngine is not initialized. Call initializeCanvas first.");
1213
+ }
1214
+ const nodes = engineInstance.getPlacedNodes();
1215
+ if (nodes.length < 2) {
1216
+ console.warn("Place at least 2 shapes on the canvas, then click Connect.");
1217
+ return false;
1218
+ }
1219
+ engineInstance.createConnection(nodes[0].id, nodes[1].id);
1220
+ return true;
1221
+ }
1222
+
1223
+ exports.connectFirstTwoNodes = connectFirstTwoNodes;
1224
+ exports.createConnection = createConnection;
1225
+ exports.createShape = createShape;
1226
+ exports.getPlacedNodes = getPlacedNodes;
1227
+ exports.initializeCanvas = initializeCanvas;
1228
+ //# sourceMappingURL=zenode.cjs.js.map