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