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