@redvars/peacock 4.0.0 → 4.1.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 (408) hide show
  1. package/dist/{BaseField-CAog9TIc.js → BaseField-BMumJpkW.js} +6 -3
  2. package/dist/BaseField-BMumJpkW.js.map +1 -0
  3. package/dist/{BaseInput-CcMfg1Y2.js → BaseInput-mWdyYv27.js} +6 -3
  4. package/dist/BaseInput-mWdyYv27.js.map +1 -0
  5. package/dist/accordion.js.map +1 -1
  6. package/dist/ai-badge.js +2 -2
  7. package/dist/ai-summary.js +2 -2
  8. package/dist/alert.js +2 -2
  9. package/dist/anchor-nav.js +2 -2
  10. package/dist/app-shell.js +2 -2
  11. package/dist/assistant-panel.js +2 -2
  12. package/dist/assistant-step.js +2 -2
  13. package/dist/assistant-steps.js +2 -2
  14. package/dist/avatar-group.js +2 -2
  15. package/dist/banner.js +2 -2
  16. package/dist/{base-button-Do2TUy8M.js → base-button-BJMGMcMv.js} +3 -1
  17. package/dist/base-button-BJMGMcMv.js.map +1 -0
  18. package/dist/{base-progress-BiLlZVHJ.js → base-progress-CvLVSjuy.js} +4 -2
  19. package/dist/base-progress-CvLVSjuy.js.map +1 -0
  20. package/dist/bottom-sheet.js +2 -2
  21. package/dist/breadcrumb.js +2 -2
  22. package/dist/button-group.js +4 -4
  23. package/dist/button.js +3 -3
  24. package/dist/calendar.js +2 -2
  25. package/dist/canvas-base-BTQMEVn_.js +788 -0
  26. package/dist/canvas-base-BTQMEVn_.js.map +1 -0
  27. package/dist/canvas-link-CtgsALq4.js +54 -0
  28. package/dist/canvas-link-CtgsALq4.js.map +1 -0
  29. package/dist/{cartesian-chart-C-f1frt0.js → cartesian-chart-DM1FC_XT.js} +3 -2
  30. package/dist/cartesian-chart-DM1FC_XT.js.map +1 -0
  31. package/dist/{cb-group-base-DeuCVx3a.js → cb-group-base-B6fa4Lll.js} +2 -2
  32. package/dist/{cb-group-base-DeuCVx3a.js.map → cb-group-base-B6fa4Lll.js.map} +1 -1
  33. package/dist/cb-group.js +3 -3
  34. package/dist/cb-rule.js +3 -3
  35. package/dist/chart-area.js +5 -4
  36. package/dist/chart-area.js.map +1 -1
  37. package/dist/chart-bar.js +5 -4
  38. package/dist/chart-bar.js.map +1 -1
  39. package/dist/chart-base-Dhxuw_Mw.js +833 -0
  40. package/dist/chart-base-Dhxuw_Mw.js.map +1 -0
  41. package/dist/chart-doughnut.js +4 -3
  42. package/dist/chart-doughnut.js.map +1 -1
  43. package/dist/chart-line.js +5 -4
  44. package/dist/chart-line.js.map +1 -1
  45. package/dist/chart-pie.js +4 -3
  46. package/dist/chart-pie.js.map +1 -1
  47. package/dist/chat-message.js +2 -2
  48. package/dist/chat-thread.js +2 -2
  49. package/dist/checkbox-group.js +4 -4
  50. package/dist/checkbox.js +4 -4
  51. package/dist/chip-set.js +3 -3
  52. package/dist/chip.js +4 -4
  53. package/dist/circular-progress.js +3 -3
  54. package/dist/citation.js +2 -2
  55. package/dist/code-editor.js +5 -4
  56. package/dist/code-editor.js.map +1 -1
  57. package/dist/code-highlighter.js +2 -2
  58. package/dist/color-field.js +5 -5
  59. package/dist/color-picker.js +2 -2
  60. package/dist/command-palette.js +2 -2
  61. package/dist/comment-composer.js +5 -5
  62. package/dist/condition-builder.js +3 -3
  63. package/dist/confirm-dialog.js +2 -2
  64. package/dist/copy-button.js +2 -2
  65. package/dist/currency-field.js +5 -5
  66. package/dist/custom-elements-jsdocs.json +2115 -336
  67. package/dist/custom-elements.json +19483 -615
  68. package/dist/date-field.js +6 -6
  69. package/dist/date-picker.js +4 -2
  70. package/dist/date-picker.js.map +1 -1
  71. package/dist/date-range-field.js +6 -6
  72. package/dist/datetime-field.js +6 -6
  73. package/dist/dependency-map-layout-5KUueabk.js +1390 -0
  74. package/dist/dependency-map-layout-5KUueabk.js.map +1 -0
  75. package/dist/dependency-map.js +1605 -0
  76. package/dist/dependency-map.js.map +1 -0
  77. package/dist/description-item.js +2 -2
  78. package/dist/description-list.js +2 -2
  79. package/dist/diagram-2r11KySs.js +2029 -0
  80. package/dist/diagram-2r11KySs.js.map +1 -0
  81. package/dist/diagram-controls.js +345 -0
  82. package/dist/diagram-controls.js.map +1 -0
  83. package/dist/diagram-minimap.js +216 -0
  84. package/dist/diagram-minimap.js.map +1 -0
  85. package/dist/diagram.js +20 -0
  86. package/dist/diagram.js.map +1 -0
  87. package/dist/diff-viewer.js +2 -2
  88. package/dist/discussion-activity.js +2 -2
  89. package/dist/discussion-comment.js +2 -2
  90. package/dist/discussion.js +5 -5
  91. package/dist/{document-editor-BO7QPbO5.js → document-editor-BnEugM3E.js} +2 -2
  92. package/dist/{document-editor-BO7QPbO5.js.map → document-editor-BnEugM3E.js.map} +1 -1
  93. package/dist/document-editor.js +3 -3
  94. package/dist/draft-card.js +2 -2
  95. package/dist/erd.js +2021 -0
  96. package/dist/erd.js.map +1 -0
  97. package/dist/fab.js +4 -4
  98. package/dist/field.js +257 -43
  99. package/dist/field.js.map +1 -1
  100. package/dist/file-upload.js +37 -15
  101. package/dist/file-upload.js.map +1 -1
  102. package/dist/filter-bar.js +2 -2
  103. package/dist/flow.js +27 -970
  104. package/dist/flow.js.map +1 -1
  105. package/dist/focus-ring.js +2 -0
  106. package/dist/focus-ring.js.map +1 -1
  107. package/dist/{form-associated-D3Tn33s_.js → form-associated-BHbg72PG.js} +3 -1
  108. package/dist/{form-associated-D3Tn33s_.js.map → form-associated-BHbg72PG.js.map} +1 -1
  109. package/dist/{form-submitter-DWwv6K9-.js → form-submitter-beG1CXAn.js} +7 -1
  110. package/dist/{form-submitter-DWwv6K9-.js.map → form-submitter-beG1CXAn.js.map} +1 -1
  111. package/dist/form.js +2 -2
  112. package/dist/{generative-view-DmtpDobn.js → generative-view-BgOcLRXr.js} +13 -13
  113. package/dist/generative-view-BgOcLRXr.js.map +1 -0
  114. package/dist/generative-view.js +3 -3
  115. package/dist/geometry-INg82Lxq.js +305 -0
  116. package/dist/geometry-INg82Lxq.js.map +1 -0
  117. package/dist/history-YbTSQZHj.js +45 -0
  118. package/dist/history-YbTSQZHj.js.map +1 -0
  119. package/dist/host-CZK7xhzh.js +40 -0
  120. package/dist/host-CZK7xhzh.js.map +1 -0
  121. package/dist/html-editor.js +5 -5
  122. package/dist/{hyperlink-DhE9RlVS.js → hyperlink-DycWPKwU.js} +10 -1
  123. package/dist/hyperlink-DycWPKwU.js.map +1 -0
  124. package/dist/{i18n-controller-urcQKYGe.js → i18n-controller-Cp43HjJl.js} +2 -2
  125. package/dist/{i18n-controller-urcQKYGe.js.map → i18n-controller-Cp43HjJl.js.map} +1 -1
  126. package/dist/icon-button.js +4 -4
  127. package/dist/image.js +2 -2
  128. package/dist/index.js +37 -18
  129. package/dist/index.js.map +1 -1
  130. package/dist/inline-edit.js +2 -2
  131. package/dist/input.js +4 -4
  132. package/dist/json-viewer.js +2 -2
  133. package/dist/kanban.js +2 -2
  134. package/dist/kbd.js +2 -2
  135. package/dist/linear-progress.js +3 -3
  136. package/dist/link-button.js +2 -2
  137. package/dist/list-item.js +2 -2
  138. package/dist/list.js +2 -2
  139. package/dist/listbox.js +3 -3
  140. package/dist/loader-full.js +13 -13
  141. package/dist/loader.js +44 -15
  142. package/dist/loader.js.map +1 -1
  143. package/dist/markdown-editor.js +5 -5
  144. package/dist/markers-BFmh1OCz.js +46 -0
  145. package/dist/markers-BFmh1OCz.js.map +1 -0
  146. package/dist/measure-controller-Dmc5hZKg.js +89 -0
  147. package/dist/measure-controller-Dmc5hZKg.js.map +1 -0
  148. package/dist/mention-input.js +6 -5
  149. package/dist/mention-input.js.map +1 -1
  150. package/dist/menu-item.js +3 -2
  151. package/dist/menu-item.js.map +1 -1
  152. package/dist/menu.js +2 -2
  153. package/dist/modal.js +2 -2
  154. package/dist/navigation-bar.js +2 -2
  155. package/dist/navigation-drawer.js +2 -2
  156. package/dist/navigation-rail.js +2 -2
  157. package/dist/notification-center.js +2 -2
  158. package/dist/number-field.js +6 -5
  159. package/dist/number-field.js.map +1 -1
  160. package/dist/option.js +2 -2
  161. package/dist/page-header.js +2 -2
  162. package/dist/pagination.js +2 -2
  163. package/dist/password-field.js +5 -5
  164. package/dist/password-rules.js +2 -2
  165. package/dist/phone-field.js +5 -5
  166. package/dist/{picker-field-B4DtcJfL.js → picker-field-dTlIMAQn.js} +3 -3
  167. package/dist/{picker-field-B4DtcJfL.js.map → picker-field-dTlIMAQn.js.map} +1 -1
  168. package/dist/pin-input.js +5 -5
  169. package/dist/presence-indicator.js +2 -2
  170. package/dist/prompt-input.js +5 -5
  171. package/dist/radio-group.js +1 -0
  172. package/dist/radio-group.js.map +1 -1
  173. package/dist/radio.js +5 -5
  174. package/dist/radio.js.map +1 -1
  175. package/dist/rating.js +5 -4
  176. package/dist/rating.js.map +1 -1
  177. package/dist/redvars-loader.js +2 -2
  178. package/dist/relative-time.js +2 -2
  179. package/dist/resizable-panels.js +2 -2
  180. package/dist/{rich-text-input-DLICqof1.js → rich-text-input-DM_BOzgk.js} +3 -3
  181. package/dist/{rich-text-input-DLICqof1.js.map → rich-text-input-DM_BOzgk.js.map} +1 -1
  182. package/dist/ripple.js +2 -0
  183. package/dist/ripple.js.map +1 -1
  184. package/dist/{schema-hMt-NRLk.js → schema-B8g30A_n.js} +2 -2
  185. package/dist/{schema-hMt-NRLk.js.map → schema-B8g30A_n.js.map} +1 -1
  186. package/dist/search.js +4 -4
  187. package/dist/segmented-button-group.js +1 -1
  188. package/dist/select.js +7 -7
  189. package/dist/side-sheet.js +2 -2
  190. package/dist/signature-pad.js +5 -4
  191. package/dist/signature-pad.js.map +1 -1
  192. package/dist/slider.js +5 -4
  193. package/dist/slider.js.map +1 -1
  194. package/dist/snackbar.js +2 -2
  195. package/dist/sparkline.js +2 -2
  196. package/dist/split-button.js +2 -2
  197. package/dist/src/__internal/diagram/canvas-base.d.ts +105 -0
  198. package/dist/src/__internal/diagram/canvas-link.d.ts +21 -0
  199. package/dist/src/__internal/diagram/geometry.d.ts +49 -0
  200. package/dist/src/__internal/diagram/history.d.ts +17 -0
  201. package/dist/src/__internal/diagram/host.d.ts +45 -0
  202. package/dist/src/__internal/diagram/markers.d.ts +16 -0
  203. package/dist/src/__internal/diagram/measure-controller.d.ts +32 -0
  204. package/dist/src/__internal/diagram/motion.d.ts +22 -0
  205. package/dist/src/__internal/diagram/selection.d.ts +20 -0
  206. package/dist/src/__internal/diagram/types.d.ts +39 -0
  207. package/dist/src/__internal/diagram/viewport-controller.d.ts +89 -0
  208. package/dist/src/__internal/i18n/strings.d.ts +149 -0
  209. package/dist/src/__internal/toggle-base.d.ts +8 -0
  210. package/dist/src/__internal/utils/deprecate.d.ts +3 -3
  211. package/dist/src/accordion/accordion.d.ts +1 -0
  212. package/dist/src/code-editor/code-editor.d.ts +1 -0
  213. package/dist/src/date-picker/date-picker.d.ts +2 -0
  214. package/dist/src/dependency-map/dependency-map-layout.d.ts +48 -0
  215. package/dist/src/dependency-map/dependency-map.d.ts +241 -0
  216. package/dist/src/dependency-map/index.d.ts +2 -0
  217. package/dist/src/diagram/diagram.d.ts +300 -0
  218. package/dist/src/diagram/flow.d.ts +53 -0
  219. package/dist/src/diagram/index.d.ts +4 -0
  220. package/dist/src/diagram-controls/diagram-controls.d.ts +46 -0
  221. package/dist/src/diagram-controls/index.d.ts +1 -0
  222. package/dist/src/diagram-minimap/diagram-minimap.d.ts +39 -0
  223. package/dist/src/diagram-minimap/index.d.ts +1 -0
  224. package/dist/src/erd/erd-layout.d.ts +27 -0
  225. package/dist/src/erd/erd.d.ts +266 -0
  226. package/dist/src/erd/index.d.ts +2 -0
  227. package/dist/src/field/field.d.ts +38 -1
  228. package/dist/src/file-upload/file-upload.d.ts +3 -1
  229. package/dist/src/focus-ring/focus-ring.d.ts +2 -0
  230. package/dist/src/index.d.ts +15 -2
  231. package/dist/src/input/BaseField.d.ts +3 -0
  232. package/dist/src/input/BaseInput.d.ts +3 -0
  233. package/dist/src/menu/menu-item/menu-item.d.ts +1 -0
  234. package/dist/src/number-field/number-field.d.ts +4 -0
  235. package/dist/src/progress/base-progress.d.ts +3 -0
  236. package/dist/src/radio/radio-group.d.ts +1 -0
  237. package/dist/src/rating/rating.d.ts +1 -0
  238. package/dist/src/ripple/ripple.d.ts +2 -0
  239. package/dist/src/signature-pad/signature-pad.d.ts +1 -0
  240. package/dist/src/slider/slider.d.ts +1 -0
  241. package/dist/src/switch/switch.d.ts +1 -0
  242. package/dist/src/tabs/tab.d.ts +2 -0
  243. package/dist/src/tabs/tabs.d.ts +1 -0
  244. package/dist/src/textarea/textarea.d.ts +1 -0
  245. package/dist/src/time-picker/time-picker.d.ts +2 -0
  246. package/dist/src/transfer-list/transfer-list.d.ts +1 -0
  247. package/dist/src/tree-chart/index.d.ts +2 -0
  248. package/dist/src/tree-chart/tree-chart-layout.d.ts +49 -0
  249. package/dist/src/tree-chart/tree-chart.d.ts +221 -0
  250. package/dist/src/workflow/index.d.ts +2 -0
  251. package/dist/src/workflow/workflow-format.d.ts +5 -0
  252. package/dist/src/workflow/workflow-model.d.ts +194 -0
  253. package/dist/src/workflow/workflow.d.ts +313 -0
  254. package/dist/src/workflow-timeline/index.d.ts +1 -0
  255. package/dist/src/workflow-timeline/workflow-timeline.d.ts +41 -0
  256. package/dist/stat.js +2 -2
  257. package/dist/status-indicator.js +2 -2
  258. package/dist/step.js +2 -2
  259. package/dist/stepper.js +2 -2
  260. package/dist/{strings-DmbqMTfs.js → strings-BJPuhKJk.js} +163 -1
  261. package/dist/{strings-DmbqMTfs.js.map → strings-BJPuhKJk.js.map} +1 -1
  262. package/dist/sub-menu.js +2 -2
  263. package/dist/svg.js +2 -2
  264. package/dist/switch.js +5 -4
  265. package/dist/switch.js.map +1 -1
  266. package/dist/tab.js +1 -0
  267. package/dist/tab.js.map +1 -1
  268. package/dist/table.js +2 -2
  269. package/dist/tabs.js +1 -0
  270. package/dist/tabs.js.map +1 -1
  271. package/dist/test/diagram-controls.test.d.ts +1 -0
  272. package/dist/test/diagram-geometry.test.d.ts +1 -0
  273. package/dist/test/diagram.test.d.ts +1 -0
  274. package/dist/test/erd.test.d.ts +1 -0
  275. package/dist/test/toggle-label.test.d.ts +1 -0
  276. package/dist/test/tree-chart.test.d.ts +1 -0
  277. package/dist/test/workflow-debug.test.d.ts +1 -0
  278. package/dist/test/workflow.test.d.ts +1 -0
  279. package/dist/textarea.js +7 -5
  280. package/dist/textarea.js.map +1 -1
  281. package/dist/time-field.js +6 -6
  282. package/dist/time-picker.js +4 -2
  283. package/dist/time-picker.js.map +1 -1
  284. package/dist/timeline-item.js +2 -2
  285. package/dist/timeline.js +2 -2
  286. package/dist/{toggle-base-BQO5pjrU.js → toggle-base-BlaHalfS.js} +19 -3
  287. package/dist/toggle-base-BlaHalfS.js.map +1 -0
  288. package/dist/tour.js +2 -2
  289. package/dist/transfer-list.js +5 -4
  290. package/dist/transfer-list.js.map +1 -1
  291. package/dist/{chart-base-B-gOg2Di.js → transform-CxeQFXXB.js} +9 -839
  292. package/dist/transform-CxeQFXXB.js.map +1 -0
  293. package/dist/tree-chart.js +1986 -0
  294. package/dist/tree-chart.js.map +1 -0
  295. package/dist/tree-item.js +2 -2
  296. package/dist/tree.js +2 -2
  297. package/dist/tsconfig.tsbuildinfo +1 -1
  298. package/dist/typing-indicator.js +2 -2
  299. package/dist/url-field.js +5 -5
  300. package/dist/user-menu.js +2 -2
  301. package/dist/virtual-list.js +2 -2
  302. package/dist/workflow-format-BsyveyeC.js +34 -0
  303. package/dist/workflow-format-BsyveyeC.js.map +1 -0
  304. package/dist/workflow-model-CauduOG2.js +330 -0
  305. package/dist/workflow-model-CauduOG2.js.map +1 -0
  306. package/dist/workflow-timeline.js +354 -0
  307. package/dist/workflow-timeline.js.map +1 -0
  308. package/dist/workflow.js +3337 -0
  309. package/dist/workflow.js.map +1 -0
  310. package/dist/workspace-switcher.js +2 -2
  311. package/package.json +1 -1
  312. package/readme.md +44 -2
  313. package/src/LoaderUtils.ts +9 -2
  314. package/src/__internal/diagram/canvas-base.ts +410 -0
  315. package/src/__internal/diagram/canvas-link.ts +66 -0
  316. package/src/__internal/diagram/geometry.ts +372 -0
  317. package/src/__internal/diagram/history.ts +49 -0
  318. package/src/__internal/diagram/host.ts +76 -0
  319. package/src/__internal/diagram/markers.ts +56 -0
  320. package/src/__internal/diagram/measure-controller.ts +104 -0
  321. package/src/__internal/diagram/motion.ts +89 -0
  322. package/src/__internal/diagram/selection.ts +69 -0
  323. package/src/__internal/diagram/types.ts +56 -0
  324. package/src/__internal/diagram/viewport-controller.ts +494 -0
  325. package/src/__internal/i18n/strings.ts +201 -0
  326. package/src/__internal/mixins/field.ts +3 -0
  327. package/src/__internal/mixins/form-associated.ts +2 -0
  328. package/src/__internal/mixins/form-submitter.ts +6 -0
  329. package/src/__internal/mixins/hyperlink.ts +10 -0
  330. package/src/__internal/toggle-base.ts +16 -0
  331. package/src/__internal/utils/deprecate.ts +5 -4
  332. package/src/accordion/accordion.ts +1 -0
  333. package/src/button/base-button/base-button.ts +2 -0
  334. package/src/code-editor/code-editor.ts +1 -0
  335. package/src/date-picker/date-picker.ts +2 -0
  336. package/src/dependency-map/dependency-map-layout.ts +505 -0
  337. package/src/dependency-map/dependency-map.scss +626 -0
  338. package/src/dependency-map/dependency-map.ts +1280 -0
  339. package/src/dependency-map/index.ts +16 -0
  340. package/src/diagram/diagram.scss +513 -0
  341. package/src/diagram/diagram.ts +1852 -0
  342. package/src/diagram/flow.ts +81 -0
  343. package/src/diagram/index.ts +44 -0
  344. package/src/diagram-controls/diagram-controls.scss +68 -0
  345. package/src/diagram-controls/diagram-controls.ts +255 -0
  346. package/src/diagram-controls/index.ts +1 -0
  347. package/src/diagram-minimap/diagram-minimap.scss +41 -0
  348. package/src/diagram-minimap/diagram-minimap.ts +149 -0
  349. package/src/diagram-minimap/index.ts +1 -0
  350. package/src/erd/erd-layout.ts +92 -0
  351. package/src/erd/erd.scss +636 -0
  352. package/src/erd/erd.ts +1728 -0
  353. package/src/erd/index.ts +17 -0
  354. package/src/field/field.scss +197 -23
  355. package/src/field/field.ts +109 -16
  356. package/src/file-upload/file-upload.scss +37 -10
  357. package/src/file-upload/file-upload.ts +3 -1
  358. package/src/focus-ring/focus-ring.ts +2 -0
  359. package/src/generative-view/catalog.generated.ts +12 -11
  360. package/src/index.ts +121 -2
  361. package/src/input/BaseField.ts +3 -0
  362. package/src/input/BaseInput.ts +3 -0
  363. package/src/loader.ts +25 -0
  364. package/src/mention-input/mention-input.scss +2 -0
  365. package/src/menu/menu-item/menu-item.ts +1 -0
  366. package/src/number-field/number-field.ts +4 -0
  367. package/src/progress/base-progress.ts +3 -0
  368. package/src/radio/radio-group.ts +1 -0
  369. package/src/radio/radio.ts +1 -1
  370. package/src/rating/rating.ts +1 -0
  371. package/src/ripple/ripple.ts +2 -0
  372. package/src/signature-pad/signature-pad.ts +1 -0
  373. package/src/slider/slider.ts +1 -0
  374. package/src/switch/switch.ts +1 -0
  375. package/src/tabs/tab.ts +2 -0
  376. package/src/tabs/tabs.ts +1 -0
  377. package/src/textarea/textarea.scss +2 -0
  378. package/src/textarea/textarea.ts +1 -0
  379. package/src/time-picker/time-picker.ts +2 -0
  380. package/src/transfer-list/transfer-list.ts +1 -0
  381. package/src/tree-chart/index.ts +13 -0
  382. package/src/tree-chart/tree-chart-layout.ts +185 -0
  383. package/src/tree-chart/tree-chart.scss +377 -0
  384. package/src/tree-chart/tree-chart.ts +1170 -0
  385. package/src/workflow/index.ts +35 -0
  386. package/src/workflow/workflow-format.ts +29 -0
  387. package/src/workflow/workflow-model.ts +583 -0
  388. package/src/workflow/workflow.scss +1164 -0
  389. package/src/workflow/workflow.ts +2674 -0
  390. package/src/workflow-timeline/index.ts +1 -0
  391. package/src/workflow-timeline/workflow-timeline.scss +128 -0
  392. package/src/workflow-timeline/workflow-timeline.ts +238 -0
  393. package/dist/BaseField-CAog9TIc.js.map +0 -1
  394. package/dist/BaseInput-CcMfg1Y2.js.map +0 -1
  395. package/dist/base-button-Do2TUy8M.js.map +0 -1
  396. package/dist/base-progress-BiLlZVHJ.js.map +0 -1
  397. package/dist/cartesian-chart-C-f1frt0.js.map +0 -1
  398. package/dist/chart-base-B-gOg2Di.js.map +0 -1
  399. package/dist/generative-view-DmtpDobn.js.map +0 -1
  400. package/dist/hyperlink-DhE9RlVS.js.map +0 -1
  401. package/dist/src/flow/flow.d.ts +0 -178
  402. package/dist/src/flow/index.d.ts +0 -2
  403. package/dist/toggle-base-BQO5pjrU.js.map +0 -1
  404. package/src/button/button-group/readme.md +0 -23
  405. package/src/flow/flow.scss +0 -215
  406. package/src/flow/flow.ts +0 -958
  407. package/src/flow/index.ts +0 -10
  408. /package/dist/test/{flow.test.d.ts → dependency-map.test.d.ts} +0 -0
@@ -0,0 +1,1852 @@
1
+ import { html, nothing, svg, type PropertyValues } from 'lit';
2
+ import { property, query, state } from 'lit/decorators.js';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import { repeat } from 'lit/directives/repeat.js';
5
+ import IndividualComponent from '@/IndividualComponent.js';
6
+ import { deprecate } from '@/__internal/utils/deprecate.js';
7
+ import { DiagramCanvasElement } from '@/__internal/diagram/canvas-base.js';
8
+ import { MeasureController } from '@/__internal/diagram/measure-controller.js';
9
+ import {
10
+ anchorOnRect,
11
+ boundsOf,
12
+ edgeGeometry,
13
+ inflateRect,
14
+ nearestInDirection,
15
+ OPPOSITE_SIDE,
16
+ rectFromPoints,
17
+ rectsIntersect,
18
+ type EdgeGeometry,
19
+ } from '@/__internal/diagram/geometry.js';
20
+ import {
21
+ markerInset,
22
+ markerShapes,
23
+ markerTransform,
24
+ } from '@/__internal/diagram/markers.js';
25
+ import { History } from '@/__internal/diagram/history.js';
26
+ import { DiagramSelection } from '@/__internal/diagram/selection.js';
27
+ import {
28
+ animateOut,
29
+ easeOutCubic,
30
+ prefersReducedMotion,
31
+ tween,
32
+ } from '@/__internal/diagram/motion.js';
33
+ import type { DiagramOverview } from '@/__internal/diagram/host.js';
34
+ import type {
35
+ DiagramConnector,
36
+ DiagramMarker,
37
+ DiagramPoint,
38
+ DiagramRect,
39
+ DiagramStartPosition,
40
+ DiagramView,
41
+ DiagramViewportDetail,
42
+ } from '@/__internal/diagram/types.js';
43
+ import styles from './diagram.scss';
44
+
45
+ // The canvas types every diagram shares, public under their own names.
46
+ export type {
47
+ DiagramConnector,
48
+ DiagramMarker,
49
+ DiagramPoint,
50
+ DiagramStartPosition,
51
+ DiagramView,
52
+ DiagramViewportDetail,
53
+ };
54
+
55
+ export type DiagramStrokeVariant = 'solid' | 'dashed' | 'animated-dashed';
56
+
57
+ export type DiagramHandlePosition = 'top' | 'left' | 'bottom' | 'right';
58
+
59
+ /** How an edge is drawn. `smoothstep` is the deprecated name of `elbow`. */
60
+ export type DiagramEdgeType = DiagramConnector | 'smoothstep';
61
+
62
+ export type DiagramIntent = 'info' | 'success' | 'warning' | 'danger';
63
+
64
+ /** A connection point on a node's side. */
65
+ export interface DiagramPort {
66
+ /** Unique within the node. Edges name it in `sourceHandle` or `targetHandle`. */
67
+ id: string;
68
+ side: DiagramHandlePosition;
69
+ /** `source` ports start connections, `target` ports receive them, `both` (default) do both. */
70
+ type?: 'source' | 'target' | 'both';
71
+ /** Shown as a tooltip. */
72
+ label?: string;
73
+ /** Position along the side, 0 to 1. Ports on the same side spread evenly by default. */
74
+ offset?: number;
75
+ }
76
+
77
+ export interface DiagramNode {
78
+ id: string;
79
+ position: { x: number; y: number };
80
+ /** Title of the built-in card. */
81
+ headline?: string;
82
+ /** Second line of the built-in card. */
83
+ supportingText?: string;
84
+ /** Material Symbols name shown on the built-in card. */
85
+ icon?: string;
86
+ /** Colours the built-in card's icon and border. */
87
+ intent?: DiagramIntent;
88
+ /** Connection points. Default: a target port on the left and a source port on the right. */
89
+ ports?: DiagramPort[];
90
+ /** Keeps the node from being moved or deleted by the person. */
91
+ locked?: boolean;
92
+ /** @deprecated Use `ports` with `type: 'target'`. */
93
+ inputs?: DiagramHandlePosition[];
94
+ /** @deprecated Use `ports` with `type: 'source'`. */
95
+ outputs?: DiagramHandlePosition[];
96
+ /**
97
+ * Your own data, kept with the node. Rendering from `data` is deprecated: put custom content in
98
+ * an element with `slot="node:<id>"` and use `headline` instead of `data.label`.
99
+ */
100
+ data?:
101
+ | {
102
+ label?: string;
103
+ element?: HTMLElement;
104
+ [key: string]: unknown;
105
+ }
106
+ | HTMLElement;
107
+ }
108
+
109
+ export interface DiagramEdge {
110
+ id: string;
111
+ source: string;
112
+ target: string;
113
+ /** Id of the source port. A side name works for nodes without `ports`. */
114
+ sourceHandle?: string;
115
+ /** Id of the target port. A side name works for nodes without `ports`. */
116
+ targetHandle?: string;
117
+ /** How the edge is drawn; defaults to the diagram's `connector`. */
118
+ type?: DiagramEdgeType;
119
+ variant?: DiagramStrokeVariant;
120
+ /** Shown as a pill at the middle of the edge. */
121
+ label?: string;
122
+ /** Any CSS colour. */
123
+ color?: string;
124
+ /** Marker at the source end. Default `none`. */
125
+ markerStart?: DiagramMarker;
126
+ /** Marker at the target end. Default `arrow`. */
127
+ markerEnd?: DiagramMarker;
128
+ }
129
+
130
+ /** Detail of `node-drag` and `node-drag-end`. */
131
+ export interface DiagramNodeMoveDetail {
132
+ id: string;
133
+ position: DiagramPoint;
134
+ }
135
+
136
+ /** Detail of `select`. */
137
+ export interface DiagramSelectDetail {
138
+ id: string;
139
+ kind: 'node' | 'edge';
140
+ node?: DiagramNode;
141
+ edge?: DiagramEdge;
142
+ }
143
+
144
+ /** Detail of `connect`. */
145
+ export interface DiagramConnectDetail {
146
+ source: string;
147
+ target: string;
148
+ sourceHandle: string;
149
+ targetHandle: string;
150
+ }
151
+
152
+ export type DiagramChangeReason =
153
+ | 'move'
154
+ | 'connect'
155
+ | 'reconnect'
156
+ | 'delete'
157
+ | 'paste'
158
+ | 'undo'
159
+ | 'redo';
160
+
161
+ /** Detail of `change`. */
162
+ export interface DiagramChangeDetail {
163
+ nodes: DiagramNode[];
164
+ edges: DiagramEdge[];
165
+ reason: DiagramChangeReason;
166
+ }
167
+
168
+ /** Detail of `delete`. */
169
+ export interface DiagramDeleteDetail {
170
+ nodes: string[];
171
+ edges: string[];
172
+ }
173
+
174
+ interface ResolvedPort {
175
+ id: string;
176
+ side: DiagramHandlePosition;
177
+ type: 'source' | 'target' | 'both';
178
+ label?: string;
179
+ offset: number;
180
+ }
181
+
182
+ interface Snapshot {
183
+ nodes: DiagramNode[];
184
+ edges: DiagramEdge[];
185
+ }
186
+
187
+ interface EdgeRender {
188
+ edge: DiagramEdge;
189
+ geometry: EdgeGeometry;
190
+ start: DiagramPoint;
191
+ end: DiagramPoint;
192
+ markerStart: DiagramMarker;
193
+ markerEnd: DiagramMarker;
194
+ }
195
+
196
+ /** Canvas pixels an arrow key moves the focused node; matches the dot grid. */
197
+ const KEY_STEP = 20;
198
+
199
+ /** Canvas pixels Shift + arrow key moves the focused node. */
200
+ const LARGE_KEY_STEP = 100;
201
+
202
+ /** Pointer travel, in screen pixels, before a press on a node becomes a drag. */
203
+ const DRAG_THRESHOLD = 3;
204
+
205
+ /** Screen pixels within which a dragged connection snaps to a port. */
206
+ const SNAP_DISTANCE = 28;
207
+
208
+ /** Screen pixels within which a dragged node snaps to another node's edge or centre. */
209
+ const GUIDE_DISTANCE = 6;
210
+
211
+ /** Size assumed for a node before it has been measured. */
212
+ const DEFAULT_SIZE = { width: 150, height: 70 };
213
+
214
+ /** Screen pixels rendered beyond the viewport, so panning does not reveal empty space. */
215
+ const CULL_MARGIN = 200;
216
+
217
+ /** Elements inside a node that handle their own pointer and keyboard input. */
218
+ const INTERACTIVE =
219
+ '.handle, button, input, select, textarea, a, [contenteditable], wc-button, wc-icon-button, wc-input, wc-select, wc-checkbox, wc-switch, wc-link';
220
+
221
+ /** Shared between diagrams on a page, like the system clipboard. */
222
+ let clipboard: Snapshot | undefined;
223
+
224
+ /**
225
+ * @label Diagram
226
+ * @tag wc-diagram
227
+ * @rawTag diagram
228
+ * @summary An infinite canvas of nodes and connections that the person pans, zooms and edits, for state machines, process maps and node editors.
229
+ *
230
+ * @overview
231
+ * <p>Set <code>nodes</code> and <code>edges</code> as properties. A node shows a built-in card with
232
+ * <code>headline</code>, <code>supportingText</code> and <code>icon</code>, or your own content in an
233
+ * element with <code>slot="node:&lt;id&gt;"</code>. Nodes connect through <code>ports</code> on their
234
+ * sides; edges are drawn as rounded elbows by default (<code>connector</code>), with an optional label
235
+ * and markers at each end.</p>
236
+ * <p>The canvas is infinite: drag the background, hold Space and drag, use the middle button or a
237
+ * trackpad to pan, and hold Ctrl or Command and scroll, or pinch, to zoom. It opens at
238
+ * <code>start-position</code> (<code>fit</code>, <code>origin</code> or <code>first</code>) or at an exact
239
+ * <code>start-view</code>; Home or <code>home()</code> flies back there, Shift+1 or <code>fit()</code> fits
240
+ * all content, and a "Back to content" button appears when everything is out of view. Read and set
241
+ * the camera with <code>view</code>, and save it from <code>viewport-change</code>. Add
242
+ * <code>wc-diagram-controls</code> and <code>wc-diagram-minimap</code> in the <code>controls</code> and
243
+ * <code>minimap</code> slots.</p>
244
+ * <p>By default nodes can be dragged and connections drawn; the diagram fires <code>node-drag-end</code>
245
+ * and <code>connect</code> and leaves edges to you. <code>editable</code> turns it into a full editor:
246
+ * it adds the edge on <code>connect</code> unless you cancel the event, selects edges, draws a marquee
247
+ * with Shift + drag, moves several nodes at once, snaps to other nodes (and to the grid with
248
+ * <code>snap-to-grid</code>), deletes with Delete, copies and pastes, and undoes with Ctrl+Z. Every
249
+ * committed edit fires <code>change</code>. <code>readonly</code> keeps everything in place.</p>
250
+ * <p>The diagram never mutates the objects you pass: edits assign new <code>nodes</code> and
251
+ * <code>edges</code> arrays. Each node is focusable and named by its headline. Arrow keys move the
252
+ * focused node by 20px (Shift: 100px), Alt + arrow moves focus to the nearest node in that
253
+ * direction, and Enter or Space selects it. Arrow keys follow the canvas axes and are not mirrored in
254
+ * right-to-left layouts.</p>
255
+ * <p>This component was called <code>wc-flow</code> before 4.0. That tag still works as a
256
+ * deprecated alias until 5.0.</p>
257
+ *
258
+ * @example
259
+ * ```html
260
+ * <wc-diagram id="my-diagram" style="height: 400px">
261
+ * <wc-diagram-controls slot="controls"></wc-diagram-controls>
262
+ * <wc-diagram-minimap slot="minimap"></wc-diagram-minimap>
263
+ * </wc-diagram>
264
+ * <script>
265
+ * const diagram = document.getElementById('my-diagram');
266
+ * diagram.nodes = [
267
+ * { id: 'new', position: { x: 0, y: 0 }, headline: 'New', icon: 'fiber_new' },
268
+ * { id: 'done', position: { x: 300, y: 0 }, headline: 'Done', icon: 'task_alt' }
269
+ * ];
270
+ * diagram.edges = [{ id: 'e1', source: 'new', target: 'done', label: 'finish' }];
271
+ * </script>
272
+ * ```
273
+ *
274
+ * @slot controls - A `wc-diagram-controls`, shown at the bottom start corner.
275
+ * @slot minimap - A `wc-diagram-minimap`, shown at the bottom end corner.
276
+ * @slot node:<id> - Custom content for the node with that id, in place of the built-in card.
277
+ *
278
+ * @fires {CustomEvent<DiagramNodeMoveDetail>} node-drag - While a node is dragged. Detail contains `{ id, position }`.
279
+ * @fires {CustomEvent<DiagramNodeMoveDetail>} node-drag-end - Once when a drag ends, and after each keyboard move. Detail contains `{ id, position }`.
280
+ * @fires {CustomEvent<DiagramSelectDetail>} select - A node or edge was chosen with a click, Enter or Space. Detail contains `{ id, kind, node, edge }`.
281
+ * @fires {CustomEvent<DiagramConnectDetail>} connect - A connection was dragged onto a port. With `editable`, the diagram adds the edge unless the event is canceled. Detail contains `{ source, target, sourceHandle, targetHandle }`.
282
+ * @fires {CustomEvent<DiagramDeleteDetail>} delete - Before nodes and edges are deleted with `editable`. Cancel it to keep them. Detail contains `{ nodes, edges }` (ids).
283
+ * @fires {CustomEvent<DiagramChangeDetail>} change - After a committed edit. Detail contains `{ nodes, edges, reason }`.
284
+ * @fires {CustomEvent<DiagramViewportDetail>} viewport-change - Once per frame while the camera moves and once when it settles. Detail contains `{ x, y, zoom, settled }`.
285
+ *
286
+ * @cssprop --diagram-background - Canvas background. Defaults to surface-container-lowest.
287
+ * @cssprop --diagram-dot-color - Colour of the grid dots. Defaults to outline-variant.
288
+ * @cssprop --diagram-line-color - Colour of edges at rest. Defaults to a mix of primary and outline-variant.
289
+ * @cssprop --diagram-hover-color - Colour of hovered and selected edges, ports and nodes. Defaults to primary.
290
+ * @cssprop --diagram-port-size - Diameter of a port ring. Defaults to 10px.
291
+ * @cssprop --diagram-node-background - Background of the built-in card.
292
+ * @tags data
293
+ */
294
+ @IndividualComponent
295
+ export class Diagram extends DiagramCanvasElement {
296
+ // ── Static
297
+
298
+ static styles = [styles];
299
+
300
+ // ── Properties
301
+
302
+ /** Nodes to draw. Replaced with a new array, never mutated, when the person edits. */
303
+ @property({ type: Array })
304
+ nodes: DiagramNode[] = [];
305
+
306
+ /** Connections between node ports. */
307
+ @property({ type: Array })
308
+ edges: DiagramEdge[] = [];
309
+
310
+ /** Id of the selected node or edge. With several selected, the last one chosen. */
311
+ @property({ type: String, reflect: true })
312
+ selected: string = '';
313
+
314
+ /** How edges without a `type` are drawn. */
315
+ @property({ type: String, reflect: true })
316
+ connector: DiagramConnector = 'elbow';
317
+
318
+ /** Snaps dragged nodes to the grid (`grid-size`). */
319
+ @property({ type: Boolean, attribute: 'snap-to-grid' })
320
+ snapToGrid = false;
321
+
322
+ // ── State
323
+
324
+ @state()
325
+ private _connection?: {
326
+ mode: 'new' | 'reconnect';
327
+ edgeId?: string;
328
+ /** Which end of the edge moves while reconnecting. */
329
+ end: 'source' | 'target';
330
+ fixedNode: string;
331
+ fixedPort: ResolvedPort;
332
+ fixedPoint: DiagramPoint;
333
+ pointer: DiagramPoint;
334
+ snap?: { nodeId: string; port: ResolvedPort; point: DiagramPoint };
335
+ };
336
+
337
+ @state()
338
+ private _marquee?: { start: DiagramPoint; end: DiagramPoint };
339
+
340
+ @state()
341
+ private _guides: { x1: number; y1: number; x2: number; y2: number }[] = [];
342
+
343
+ @state()
344
+ private _draggingIds: string[] = [];
345
+
346
+ @state()
347
+ private _announcement = '';
348
+
349
+ @state()
350
+ private _ripple = '';
351
+
352
+ // ── Private fields
353
+
354
+ @query('.diagram-viewport')
355
+ private readonly _viewportEl?: HTMLElement;
356
+
357
+ private readonly selection = new DiagramSelection(() => this.requestUpdate());
358
+
359
+ private readonly history = new History<Snapshot>();
360
+
361
+ private readonly measure = new MeasureController(this, {
362
+ elements: () => this.nodeElements(),
363
+ fallback: DEFAULT_SIZE,
364
+ });
365
+
366
+ private pasteCount = 0;
367
+
368
+ private focusedId = '';
369
+
370
+ private positionOverrides = new Map<string, DiagramPoint>();
371
+
372
+ /** Key events a node or edge already handled, so the canvas does not act on them again. */
373
+ private handledKeys = new WeakSet<Event>();
374
+
375
+ private stopRestoreTween?: () => void;
376
+
377
+ private rippleTimer?: ReturnType<typeof setTimeout>;
378
+
379
+ private connectionFrame = 0;
380
+
381
+ private nodeDrag?: {
382
+ pointerId: number;
383
+ startX: number;
384
+ startY: number;
385
+ primary: string;
386
+ ids: string[];
387
+ origins: Map<string, DiagramPoint>;
388
+ before: Snapshot;
389
+ moved: boolean;
390
+ movable: boolean;
391
+ additive: boolean;
392
+ element: HTMLElement;
393
+ };
394
+
395
+ private connectionDrag?: { pointerId: number; element: HTMLElement };
396
+
397
+ private marqueeDrag?: {
398
+ pointerId: number;
399
+ element: HTMLElement;
400
+ origin: DiagramRect;
401
+ };
402
+
403
+ // ── Lifecycle
404
+
405
+ disconnectedCallback() {
406
+ super.disconnectedCallback();
407
+ this.endNodeDrag(false);
408
+ this.cancelConnection();
409
+ this.endMarquee();
410
+ this.stopRestoreTween?.();
411
+ cancelAnimationFrame(this.connectionFrame);
412
+ clearTimeout(this.rippleTimer);
413
+ }
414
+
415
+ protected willUpdate(changed: PropertyValues<this>) {
416
+ super.willUpdate(changed);
417
+ if (changed.has('nodes')) {
418
+ this.warnLegacyNodes();
419
+ this.selection.retain('node', new Set(this.nodes.map(n => n.id)));
420
+ this.measure.retain(new Set(this.nodes.map(n => n.id)));
421
+ }
422
+ if (changed.has('edges')) {
423
+ if (this.edges.some(e => e.type === 'smoothstep')) {
424
+ deprecate(
425
+ this.localName,
426
+ 'edge `type: "smoothstep"`',
427
+ '`type: "elbow"`',
428
+ );
429
+ }
430
+ this.selection.retain('edge', new Set(this.edges.map(e => e.id)));
431
+ }
432
+ if (changed.has('selected')) this.syncSelectedProperty();
433
+ }
434
+
435
+ // ── Public API
436
+
437
+ /** Whether `undo()` has something to undo. */
438
+ get canUndo(): boolean {
439
+ return this.history.canUndo;
440
+ }
441
+
442
+ /** Whether `redo()` has something to redo. */
443
+ get canRedo(): boolean {
444
+ return this.history.canRedo;
445
+ }
446
+
447
+ /** Ids of the selected nodes. */
448
+ get selectedNodes(): string[] {
449
+ return this.selection.ids('node');
450
+ }
451
+
452
+ /** Ids of the selected edges. */
453
+ get selectedEdges(): string[] {
454
+ return this.selection.ids('edge');
455
+ }
456
+
457
+ undo() {
458
+ const previous = this.history.undo(this.snapshot());
459
+ if (previous) this.restore(previous, 'undo');
460
+ }
461
+
462
+ redo() {
463
+ const next = this.history.redo(this.snapshot());
464
+ if (next) this.restore(next, 'redo');
465
+ }
466
+
467
+ /** Forgets the undo and redo history, for example after saving. */
468
+ clearHistory() {
469
+ this.history.clear();
470
+ this.listeners.notify();
471
+ }
472
+
473
+ /** Selects every node and edge. */
474
+ selectAll() {
475
+ this.selection.set([
476
+ ...this.nodes.map(n => ({ kind: 'node' as const, id: n.id })),
477
+ ...this.edges.map(e => ({ kind: 'edge' as const, id: e.id })),
478
+ ]);
479
+ }
480
+
481
+ /** Deletes the selected nodes and edges (and edges attached to deleted nodes). Needs `editable`. */
482
+ deleteSelection() {
483
+ if (!this.editable) return;
484
+ const nodeIds = this.selection
485
+ .ids('node')
486
+ .filter(id => !this.nodes.find(n => n.id === id)?.locked);
487
+ const nodeSet = new Set(nodeIds);
488
+ const edgeIds = new Set(this.selection.ids('edge'));
489
+ for (const e of this.edges) {
490
+ if (nodeSet.has(e.source) || nodeSet.has(e.target)) edgeIds.add(e.id);
491
+ }
492
+ if (nodeSet.size === 0 && edgeIds.size === 0) return;
493
+ const allowed = this.emit<DiagramDeleteDetail>(
494
+ 'delete',
495
+ { nodes: nodeIds, edges: [...edgeIds] },
496
+ true,
497
+ );
498
+ if (!allowed) return;
499
+ const before = this.snapshot();
500
+ const leaving = nodeIds
501
+ .map(id => this.nodeElement(id))
502
+ .filter((el): el is HTMLElement => !!el);
503
+ animateOut(leaving, () => {
504
+ this.history.push(before);
505
+ this.nodes = this.nodes.filter(n => !nodeSet.has(n.id));
506
+ this.edges = this.edges.filter(e => !edgeIds.has(e.id));
507
+ this.selection.clear();
508
+ this.selected = '';
509
+ this.announce(this.i18n.t('diagramDeleted')(nodeSet.size + edgeIds.size));
510
+ this.emitChange('delete');
511
+ });
512
+ }
513
+
514
+ // ── Canvas hooks
515
+
516
+ protected viewportElement() {
517
+ return this._viewportEl;
518
+ }
519
+
520
+ protected overviewItems(): DiagramOverview['items'] {
521
+ return this.nodes.map(n => ({
522
+ ...this.nodeRect(n),
523
+ selected: this.selection.has('node', n.id),
524
+ }));
525
+ }
526
+
527
+ protected itemRect(id: string): DiagramRect | undefined {
528
+ const node = this.nodes.find(n => n.id === id);
529
+ return node ? this.nodeRect(node) : undefined;
530
+ }
531
+
532
+ protected firstItemRect(): DiagramRect | undefined {
533
+ return this.nodes[0] ? this.nodeRect(this.nodes[0]) : undefined;
534
+ }
535
+
536
+ protected onBackgroundPointerDown(event: PointerEvent): boolean {
537
+ return this.startMarquee(event);
538
+ }
539
+
540
+ protected onBackgroundClick() {
541
+ this.clearSelection();
542
+ }
543
+
544
+ // ── Private methods: data
545
+
546
+ private emitChange(reason: DiagramChangeReason) {
547
+ this.emit<DiagramChangeDetail>('change', {
548
+ nodes: this.nodes,
549
+ edges: this.edges,
550
+ reason,
551
+ });
552
+ this.listeners.notify();
553
+ }
554
+
555
+ private snapshot(): Snapshot {
556
+ return { nodes: this.nodes, edges: this.edges };
557
+ }
558
+
559
+ private announce(message: string) {
560
+ this._announcement = '';
561
+ requestAnimationFrame(() => {
562
+ this._announcement = message;
563
+ });
564
+ }
565
+
566
+ private warnLegacyNodes() {
567
+ for (const node of this.nodes) {
568
+ if (node.inputs || node.outputs) {
569
+ deprecate(this.localName, 'node `inputs` and `outputs`', '`ports`');
570
+ }
571
+ if (node.data instanceof HTMLElement || node.data?.element) {
572
+ deprecate(
573
+ this.localName,
574
+ 'an element in node `data`',
575
+ 'an element with `slot="node:<id>"`',
576
+ );
577
+ } else if (node.data && 'label' in node.data && !node.headline) {
578
+ deprecate(this.localName, 'node `data.label`', '`headline`');
579
+ }
580
+ }
581
+ }
582
+
583
+ /** Keeps the selection in step when the app sets `selected`. */
584
+ private syncSelectedProperty() {
585
+ const id = this.selected;
586
+ if (!id) {
587
+ if (this.selection.size) this.selection.clear();
588
+ return;
589
+ }
590
+ const kind = this.nodes.some(n => n.id === id) ? 'node' : 'edge';
591
+ if (!this.selection.has(kind, id)) this.selection.set([{ kind, id }]);
592
+ }
593
+
594
+ private nodePosition(node: DiagramNode): DiagramPoint {
595
+ return this.positionOverrides.get(node.id) ?? node.position;
596
+ }
597
+
598
+ private nodeRect(node: DiagramNode): DiagramRect {
599
+ const { x, y } = this.nodePosition(node);
600
+ const size = this.measure.size(node.id);
601
+ return { x, y, width: size.width, height: size.height };
602
+ }
603
+
604
+ protected contentBounds(): DiagramRect | undefined {
605
+ return boundsOf(this.nodes.map(n => this.nodeRect(n)));
606
+ }
607
+
608
+ protected selectionRects(): DiagramRect[] {
609
+ const nodeIds = new Set(this.selection.ids('node'));
610
+ const edgeIds = new Set(this.selection.ids('edge'));
611
+ for (const e of this.edges) {
612
+ if (edgeIds.has(e.id)) {
613
+ nodeIds.add(e.source);
614
+ nodeIds.add(e.target);
615
+ }
616
+ }
617
+ return this.nodes.filter(n => nodeIds.has(n.id)).map(n => this.nodeRect(n));
618
+ }
619
+
620
+ private nodeLabel(node: DiagramNode): string {
621
+ if (node.headline) return node.headline;
622
+ if (node.data instanceof HTMLElement) {
623
+ return node.data.getAttribute('aria-label') || node.id;
624
+ }
625
+ const label = node.data?.label;
626
+ return typeof label === 'string' && label ? label : node.id;
627
+ }
628
+
629
+ private legacyElement(node: DiagramNode): HTMLElement | undefined {
630
+ if (node.data instanceof HTMLElement) return node.data;
631
+ const el = node.data?.element;
632
+ return el instanceof HTMLElement ? el : undefined;
633
+ }
634
+
635
+ private resolvePorts(node: DiagramNode): ResolvedPort[] {
636
+ let ports: (Omit<ResolvedPort, 'offset'> & { offset?: number })[];
637
+ if (node.ports?.length) {
638
+ ports = node.ports.map(p => ({ ...p, type: p.type ?? 'both' }));
639
+ } else {
640
+ const inputs = node.inputs ?? ['left'];
641
+ const outputs = node.outputs ?? ['right'];
642
+ ports = [
643
+ ...inputs.map(side => ({ id: side, side, type: 'target' as const })),
644
+ ...outputs.map(side => ({ id: side, side, type: 'source' as const })),
645
+ ];
646
+ }
647
+ const bySide = new Map<string, number>();
648
+ const counts = new Map<string, number>();
649
+ for (const p of ports) counts.set(p.side, (counts.get(p.side) ?? 0) + 1);
650
+ return ports.map(p => {
651
+ const i = bySide.get(p.side) ?? 0;
652
+ bySide.set(p.side, i + 1);
653
+ const n = counts.get(p.side) ?? 1;
654
+ return { ...p, offset: p.offset ?? (i + 1) / (n + 1) };
655
+ });
656
+ }
657
+
658
+ private findPort(
659
+ node: DiagramNode,
660
+ id: string | undefined,
661
+ role: 'source' | 'target',
662
+ ): ResolvedPort {
663
+ const ports = this.resolvePorts(node);
664
+ const capable = (p: ResolvedPort) => p.type === 'both' || p.type === role;
665
+ return (
666
+ (id
667
+ ? (ports.find(p => p.id === id) ??
668
+ ports.find(p => p.side === id && capable(p)))
669
+ : undefined) ??
670
+ ports.find(capable) ??
671
+ ports[0] ?? {
672
+ id: role === 'source' ? 'right' : 'left',
673
+ side: role === 'source' ? 'right' : 'left',
674
+ type: role,
675
+ offset: 0.5,
676
+ }
677
+ );
678
+ }
679
+
680
+ private portPoint(node: DiagramNode, port: ResolvedPort): DiagramPoint {
681
+ return anchorOnRect(this.nodeRect(node), port.side, port.offset);
682
+ }
683
+
684
+ private edgeRender(
685
+ edge: DiagramEdge,
686
+ byId: Map<string, DiagramNode>,
687
+ ): EdgeRender | undefined {
688
+ const source = byId.get(edge.source);
689
+ const target = byId.get(edge.target);
690
+ if (!source || !target) return undefined;
691
+ const sp = this.findPort(source, edge.sourceHandle, 'source');
692
+ const tp = this.findPort(target, edge.targetHandle, 'target');
693
+ const start = this.portPoint(source, sp);
694
+ const end = this.portPoint(target, tp);
695
+ let kind: DiagramConnector = this.connector;
696
+ if (edge.type === 'smoothstep') kind = 'elbow';
697
+ else if (edge.type) kind = edge.type;
698
+ const markerStart = edge.markerStart ?? 'none';
699
+ const markerEnd = edge.markerEnd ?? 'arrow';
700
+ const geometry = edgeGeometry(kind, start, sp.side, end, tp.side, {
701
+ startInset: markerInset(markerStart),
702
+ endInset: markerInset(markerEnd),
703
+ });
704
+ return { edge, geometry, start, end, markerStart, markerEnd };
705
+ }
706
+
707
+ private uniqueId(base: string, taken: Set<string>): string {
708
+ if (!taken.has(base)) return base;
709
+ let i = 2;
710
+ while (taken.has(`${base}-${i}`)) i += 1;
711
+ return `${base}-${i}`;
712
+ }
713
+
714
+ protected isBackground(target: EventTarget | null): boolean {
715
+ const el = target as Element | null;
716
+ if (!el) return false;
717
+ return (
718
+ el === this._viewportEl ||
719
+ (el.classList?.contains('diagram-world') ?? false) ||
720
+ (el.classList?.contains('diagram-svg') ?? false) ||
721
+ (el.classList?.contains('diagram-nodes') ?? false)
722
+ );
723
+ }
724
+
725
+ // ── Private methods: selection
726
+
727
+ private clearSelection() {
728
+ this.selection.clear();
729
+ this.selected = '';
730
+ }
731
+
732
+ private selectNode(node: DiagramNode, additive = false) {
733
+ if (additive && this.editable) {
734
+ this.selection.toggle('node', node.id);
735
+ } else {
736
+ this.selection.set([{ kind: 'node', id: node.id }]);
737
+ }
738
+ this.selected = node.id;
739
+ this.emit<DiagramSelectDetail>('select', {
740
+ id: node.id,
741
+ kind: 'node',
742
+ node,
743
+ });
744
+ }
745
+
746
+ private selectEdge(edge: DiagramEdge, additive = false) {
747
+ if (additive && this.editable) {
748
+ this.selection.toggle('edge', edge.id);
749
+ } else {
750
+ this.selection.set([{ kind: 'edge', id: edge.id }]);
751
+ }
752
+ this.selected = edge.id;
753
+ this.emit<DiagramSelectDetail>('select', {
754
+ id: edge.id,
755
+ kind: 'edge',
756
+ edge,
757
+ });
758
+ }
759
+
760
+ // ── Private methods: node dragging
761
+
762
+ private nodeElements(): [string, HTMLElement][] {
763
+ const out: [string, HTMLElement][] = [];
764
+ this.renderRoot
765
+ .querySelectorAll<HTMLElement>('.diagram-node')
766
+ .forEach(el => {
767
+ const { id } = el.dataset;
768
+ if (id) out.push([id, el]);
769
+ });
770
+ return out;
771
+ }
772
+
773
+ private nodeElement(id: string): HTMLElement | null {
774
+ return this.renderRoot.querySelector<HTMLElement>(
775
+ `.diagram-node[data-id="${CSS.escape(id)}"]`,
776
+ );
777
+ }
778
+
779
+ private onNodePointerDown(event: PointerEvent, node: DiagramNode) {
780
+ if (event.button !== 0 || this.viewport.spaceHeld) return;
781
+ const target = event.composedPath()[0] as Element | undefined;
782
+ if (target instanceof Element && target.closest(INTERACTIVE)) return;
783
+ event.preventDefault();
784
+ const element = event.currentTarget as HTMLElement;
785
+ element.focus({ preventScroll: true });
786
+ this.stopRestoreTween?.();
787
+ const additive = event.shiftKey || event.metaKey || event.ctrlKey;
788
+ const ids =
789
+ this.editable && this.selection.has('node', node.id) && !additive
790
+ ? this.selection
791
+ .ids('node')
792
+ .filter(id => !this.nodes.find(n => n.id === id)?.locked)
793
+ : [node.id];
794
+ this.nodeDrag = {
795
+ pointerId: event.pointerId,
796
+ startX: event.clientX,
797
+ startY: event.clientY,
798
+ primary: node.id,
799
+ ids: ids.includes(node.id) ? ids : [node.id],
800
+ origins: new Map(
801
+ this.nodes
802
+ .filter(n => ids.includes(n.id) || n.id === node.id)
803
+ .map(n => [n.id, { ...n.position }]),
804
+ ),
805
+ before: this.snapshot(),
806
+ moved: false,
807
+ movable: !this.readonly && !node.locked,
808
+ additive,
809
+ element,
810
+ };
811
+ try {
812
+ element.setPointerCapture(event.pointerId);
813
+ } catch {
814
+ // Synthetic or already released pointers cannot be captured.
815
+ }
816
+ element.addEventListener('pointermove', this.onNodePointerMove);
817
+ element.addEventListener('pointerup', this.onNodePointerUp);
818
+ element.addEventListener('pointercancel', this.onNodePointerUp);
819
+ }
820
+
821
+ private onNodePointerMove = (event: PointerEvent) => {
822
+ const drag = this.nodeDrag;
823
+ if (!drag || event.pointerId !== drag.pointerId || !drag.movable) return;
824
+ const { zoom } = this.viewport.view;
825
+ const dx = (event.clientX - drag.startX) / zoom;
826
+ const dy = (event.clientY - drag.startY) / zoom;
827
+ if (!drag.moved && Math.hypot(dx * zoom, dy * zoom) < DRAG_THRESHOLD)
828
+ return;
829
+ if (!drag.moved) {
830
+ drag.moved = true;
831
+ this._draggingIds = drag.ids;
832
+ }
833
+ const origin = drag.origins.get(drag.primary) ?? { x: 0, y: 0 };
834
+ let next = { x: origin.x + dx, y: origin.y + dy };
835
+ if (this.snapToGrid) {
836
+ next = {
837
+ x: Math.round(next.x / this.gridSize) * this.gridSize,
838
+ y: Math.round(next.y / this.gridSize) * this.gridSize,
839
+ };
840
+ }
841
+ const aligned = this.editable
842
+ ? this.alignToOthers(drag.primary, next, new Set(drag.ids))
843
+ : { position: next, guides: [] };
844
+ next = aligned.position;
845
+ this._guides = aligned.guides;
846
+ const delta = { x: next.x - origin.x, y: next.y - origin.y };
847
+ const moved = new Map<string, DiagramPoint>();
848
+ for (const id of drag.ids) {
849
+ const o = drag.origins.get(id);
850
+ if (o) moved.set(id, { x: o.x + delta.x, y: o.y + delta.y });
851
+ }
852
+ this.moveNodes(moved);
853
+ this.emit<DiagramNodeMoveDetail>('node-drag', {
854
+ id: drag.primary,
855
+ position: next,
856
+ });
857
+ };
858
+
859
+ private onNodePointerUp = (event: PointerEvent) => {
860
+ if (!this.nodeDrag || event.pointerId !== this.nodeDrag.pointerId) return;
861
+ this.endNodeDrag(true);
862
+ };
863
+
864
+ /** Ends the press on a node: a drag commits the move, a press without movement selects. */
865
+ private endNodeDrag(notify: boolean) {
866
+ const drag = this.nodeDrag;
867
+ if (!drag) return;
868
+ this.nodeDrag = undefined;
869
+ this._draggingIds = [];
870
+ this._guides = [];
871
+ const { element } = drag;
872
+ element.removeEventListener('pointermove', this.onNodePointerMove);
873
+ element.removeEventListener('pointerup', this.onNodePointerUp);
874
+ element.removeEventListener('pointercancel', this.onNodePointerUp);
875
+ try {
876
+ if (element.hasPointerCapture(drag.pointerId)) {
877
+ element.releasePointerCapture(drag.pointerId);
878
+ }
879
+ } catch {
880
+ // The pointer is already gone.
881
+ }
882
+ if (!notify) return;
883
+ if (drag.moved) {
884
+ const node = this.nodes.find(n => n.id === drag.primary);
885
+ if (!node) return;
886
+ this.history.push(drag.before);
887
+ this.emit<DiagramNodeMoveDetail>('node-drag-end', {
888
+ id: drag.primary,
889
+ position: { ...node.position },
890
+ });
891
+ this.emitChange('move');
892
+ } else {
893
+ const node = this.nodes.find(n => n.id === drag.primary);
894
+ if (node) this.selectNode(node, drag.additive);
895
+ }
896
+ }
897
+
898
+ /** Replaces moved nodes with new objects and assigns a new `nodes` array. */
899
+ private moveNodes(positions: Map<string, DiagramPoint>) {
900
+ this.nodes = this.nodes.map(node => {
901
+ const p = positions.get(node.id);
902
+ return p ? { ...node, position: { x: p.x, y: p.y } } : node;
903
+ });
904
+ }
905
+
906
+ /** Snaps a dragged node's edges or centre to nearby nodes and returns guide lines to draw. */
907
+ private alignToOthers(
908
+ id: string,
909
+ position: DiagramPoint,
910
+ moving: Set<string>,
911
+ ) {
912
+ const size = this.measure.size(id);
913
+ const threshold = GUIDE_DISTANCE / this.viewport.view.zoom;
914
+ const visible = this.viewport.visibleRect();
915
+ const others = this.nodes
916
+ .filter(n => !moving.has(n.id))
917
+ .map(n => this.nodeRect(n))
918
+ .filter(r => rectsIntersect(r, visible));
919
+ const mine = (p: DiagramPoint) => ({
920
+ xs: [p.x, p.x + size.width / 2, p.x + size.width],
921
+ ys: [p.y, p.y + size.height / 2, p.y + size.height],
922
+ });
923
+ let bestX: { delta: number; line: number; rect: DiagramRect } | undefined;
924
+ let bestY: { delta: number; line: number; rect: DiagramRect } | undefined;
925
+ const m = mine(position);
926
+ for (const r of others) {
927
+ for (const ox of [r.x, r.x + r.width / 2, r.x + r.width]) {
928
+ for (const mx of m.xs) {
929
+ const d = ox - mx;
930
+ if (
931
+ Math.abs(d) < threshold &&
932
+ (!bestX || Math.abs(d) < Math.abs(bestX.delta))
933
+ ) {
934
+ bestX = { delta: d, line: ox, rect: r };
935
+ }
936
+ }
937
+ }
938
+ for (const oy of [r.y, r.y + r.height / 2, r.y + r.height]) {
939
+ for (const my of m.ys) {
940
+ const d = oy - my;
941
+ if (
942
+ Math.abs(d) < threshold &&
943
+ (!bestY || Math.abs(d) < Math.abs(bestY.delta))
944
+ ) {
945
+ bestY = { delta: d, line: oy, rect: r };
946
+ }
947
+ }
948
+ }
949
+ }
950
+ const next = {
951
+ x: position.x + (bestX?.delta ?? 0),
952
+ y: position.y + (bestY?.delta ?? 0),
953
+ };
954
+ const guides: { x1: number; y1: number; x2: number; y2: number }[] = [];
955
+ if (bestX) {
956
+ const top = Math.min(bestX.rect.y, next.y) - 16;
957
+ const bottom =
958
+ Math.max(bestX.rect.y + bestX.rect.height, next.y + size.height) + 16;
959
+ guides.push({ x1: bestX.line, y1: top, x2: bestX.line, y2: bottom });
960
+ }
961
+ if (bestY) {
962
+ const left = Math.min(bestY.rect.x, next.x) - 16;
963
+ const right =
964
+ Math.max(bestY.rect.x + bestY.rect.width, next.x + size.width) + 16;
965
+ guides.push({ x1: left, y1: bestY.line, x2: right, y2: bestY.line });
966
+ }
967
+ return { position: next, guides };
968
+ }
969
+
970
+ // ── Private methods: keyboard
971
+
972
+ private onNodeKeyDown(event: KeyboardEvent, node: DiagramNode) {
973
+ // Keys typed into controls inside a custom node are theirs.
974
+ if (event.target !== event.currentTarget) return;
975
+ const { key } = event;
976
+ if (key === 'Enter' || key === ' ') {
977
+ this.markHandled(event);
978
+ this.selectNode(node, event.shiftKey);
979
+ return;
980
+ }
981
+ if ((key === 'Delete' || key === 'Backspace') && this.editable) {
982
+ this.markHandled(event);
983
+ if (!this.selection.has('node', node.id)) {
984
+ this.selection.set([{ kind: 'node', id: node.id }]);
985
+ }
986
+ this.deleteSelection();
987
+ return;
988
+ }
989
+ const dir = {
990
+ ArrowLeft: 'left',
991
+ ArrowRight: 'right',
992
+ ArrowUp: 'up',
993
+ ArrowDown: 'down',
994
+ }[key] as 'left' | 'right' | 'up' | 'down' | undefined;
995
+ if (!dir) return;
996
+ this.markHandled(event);
997
+ if (event.altKey) {
998
+ const from = this.nodeRect(node);
999
+ const next = nearestInDirection(
1000
+ from,
1001
+ this.nodes
1002
+ .filter(n => n.id !== node.id)
1003
+ .map(n => ({ node: n, rect: this.nodeRect(n) })),
1004
+ dir,
1005
+ );
1006
+ if (next) this.focusNode(next.node.id);
1007
+ return;
1008
+ }
1009
+ if (this.readonly || node.locked) return;
1010
+ const step = event.shiftKey ? LARGE_KEY_STEP : KEY_STEP;
1011
+ const offset = {
1012
+ left: { x: -step, y: 0 },
1013
+ right: { x: step, y: 0 },
1014
+ up: { x: 0, y: -step },
1015
+ down: { x: 0, y: step },
1016
+ }[dir];
1017
+ const ids =
1018
+ this.editable && this.selection.has('node', node.id)
1019
+ ? this.selection
1020
+ .ids('node')
1021
+ .filter(id => !this.nodes.find(n => n.id === id)?.locked)
1022
+ : [node.id];
1023
+ const before = this.snapshot();
1024
+ const moved = new Map<string, DiagramPoint>();
1025
+ for (const n of this.nodes) {
1026
+ if (ids.includes(n.id)) {
1027
+ moved.set(n.id, {
1028
+ x: n.position.x + offset.x,
1029
+ y: n.position.y + offset.y,
1030
+ });
1031
+ }
1032
+ }
1033
+ this.moveNodes(moved);
1034
+ this.history.push(before);
1035
+ const position = moved.get(node.id) ?? node.position;
1036
+ this.emit<DiagramNodeMoveDetail>('node-drag-end', {
1037
+ id: node.id,
1038
+ position,
1039
+ });
1040
+ this.announce(
1041
+ this.i18n.t('diagramMoved')(
1042
+ this.nodeLabel(node),
1043
+ String(Math.round(position.x)),
1044
+ String(Math.round(position.y)),
1045
+ ),
1046
+ );
1047
+ this.emitChange('move');
1048
+ this.keepInView(node.id);
1049
+ }
1050
+
1051
+ private onEdgeKeyDown(event: KeyboardEvent, edge: DiagramEdge) {
1052
+ if (event.key === 'Enter' || event.key === ' ') {
1053
+ this.markHandled(event);
1054
+ this.selectEdge(edge, event.shiftKey);
1055
+ } else if (
1056
+ (event.key === 'Delete' || event.key === 'Backspace') &&
1057
+ this.editable
1058
+ ) {
1059
+ this.markHandled(event);
1060
+ if (!this.selection.has('edge', edge.id)) {
1061
+ this.selection.set([{ kind: 'edge', id: edge.id }]);
1062
+ }
1063
+ this.deleteSelection();
1064
+ }
1065
+ }
1066
+
1067
+ private markHandled(event: Event) {
1068
+ event.preventDefault();
1069
+ this.handledKeys.add(event);
1070
+ }
1071
+
1072
+ private onViewportKeyDown = (event: KeyboardEvent) => {
1073
+ if (event.defaultPrevented || this.handledKeys.has(event)) return;
1074
+ const origin = event.composedPath()[0];
1075
+ if (
1076
+ origin instanceof HTMLElement &&
1077
+ origin.matches(
1078
+ 'input, textarea, select, [contenteditable], [contenteditable] *',
1079
+ )
1080
+ ) {
1081
+ return;
1082
+ }
1083
+ const mod = event.ctrlKey || event.metaKey;
1084
+ const key = event.key.toLowerCase();
1085
+ const handled = (fn: () => void) => {
1086
+ event.preventDefault();
1087
+ fn();
1088
+ };
1089
+ if (mod && key === 'z' && this.editable) {
1090
+ handled(() => (event.shiftKey ? this.redo() : this.undo()));
1091
+ } else if (mod && key === 'y' && this.editable) {
1092
+ handled(() => this.redo());
1093
+ } else if (mod && key === 'a' && this.editable) {
1094
+ handled(() => this.selectAll());
1095
+ } else if (mod && key === 'c' && this.editable) {
1096
+ handled(() => this.copySelection());
1097
+ } else if (mod && key === 'v' && this.editable) {
1098
+ handled(() => this.paste());
1099
+ } else if (mod && key === 'd' && this.editable) {
1100
+ handled(() => {
1101
+ this.copySelection();
1102
+ this.paste();
1103
+ });
1104
+ } else if ((key === 'delete' || key === 'backspace') && this.editable) {
1105
+ handled(() => this.deleteSelection());
1106
+ } else if (key === 'escape') {
1107
+ handled(() => {
1108
+ this.cancelConnection();
1109
+ this.clearSelection();
1110
+ });
1111
+ } else {
1112
+ this.handleCanvasKey(event);
1113
+ }
1114
+ };
1115
+
1116
+ private focusNode(id: string) {
1117
+ this.focusedId = id;
1118
+ this.keepInView(id, true);
1119
+ this.updateComplete.then(() =>
1120
+ this.nodeElement(id)?.focus({ preventScroll: true }),
1121
+ );
1122
+ }
1123
+
1124
+ /** Pans so the node is in view, when it is not. */
1125
+ private keepInView(id: string, animate = false) {
1126
+ const node = this.nodes.find(n => n.id === id);
1127
+ if (!node) return;
1128
+ const r = this.nodeRect(node);
1129
+ const visible = inflateRect(
1130
+ this.viewport.visibleRect(),
1131
+ -20 / this.viewport.view.zoom,
1132
+ );
1133
+ const inside =
1134
+ r.x >= visible.x &&
1135
+ r.y >= visible.y &&
1136
+ r.x + r.width <= visible.x + visible.width &&
1137
+ r.y + r.height <= visible.y + visible.height;
1138
+ if (inside) return;
1139
+ const view = this.viewport.viewCentering({
1140
+ x: r.x + r.width / 2,
1141
+ y: r.y + r.height / 2,
1142
+ });
1143
+ if (animate) this.viewport.animateTo(view, 300);
1144
+ else this.viewport.setView(view);
1145
+ }
1146
+
1147
+ // ── Private methods: copy and paste
1148
+
1149
+ private copySelection() {
1150
+ const ids = new Set(this.selection.ids('node'));
1151
+ if (!ids.size) return;
1152
+ clipboard = {
1153
+ nodes: this.nodes.filter(n => ids.has(n.id)),
1154
+ edges: this.edges.filter(e => ids.has(e.source) && ids.has(e.target)),
1155
+ };
1156
+ this.pasteCount = 0;
1157
+ }
1158
+
1159
+ private paste() {
1160
+ if (!clipboard || !this.editable) return;
1161
+ this.pasteCount += 1;
1162
+ const offset = 40 * this.pasteCount;
1163
+ const takenNodes = new Set(this.nodes.map(n => n.id));
1164
+ const takenEdges = new Set(this.edges.map(e => e.id));
1165
+ const idMap = new Map<string, string>();
1166
+ const nodes = clipboard.nodes.map(n => {
1167
+ const id = this.uniqueId(`${n.id}-copy`, takenNodes);
1168
+ takenNodes.add(id);
1169
+ idMap.set(n.id, id);
1170
+ return {
1171
+ ...n,
1172
+ id,
1173
+ position: { x: n.position.x + offset, y: n.position.y + offset },
1174
+ };
1175
+ });
1176
+ const edges = clipboard.edges.map(e => {
1177
+ const id = this.uniqueId(`${e.id}-copy`, takenEdges);
1178
+ takenEdges.add(id);
1179
+ return {
1180
+ ...e,
1181
+ id,
1182
+ source: idMap.get(e.source) ?? e.source,
1183
+ target: idMap.get(e.target) ?? e.target,
1184
+ };
1185
+ });
1186
+ this.history.push(this.snapshot());
1187
+ this.nodes = [...this.nodes, ...nodes];
1188
+ this.edges = [...this.edges, ...edges];
1189
+ this.selection.set([
1190
+ ...nodes.map(n => ({ kind: 'node' as const, id: n.id })),
1191
+ ...edges.map(e => ({ kind: 'edge' as const, id: e.id })),
1192
+ ]);
1193
+ this.announce(this.i18n.t('diagramPasted')(nodes.length + edges.length));
1194
+ this.emitChange('paste');
1195
+ }
1196
+
1197
+ // ── Private methods: undo
1198
+
1199
+ /** Restores a snapshot; nodes that moved glide to their restored places. */
1200
+ private restore(snapshot: Snapshot, reason: 'undo' | 'redo') {
1201
+ this.stopRestoreTween?.();
1202
+ const from = new Map(this.nodes.map(n => [n.id, { ...n.position }]));
1203
+ this.nodes = snapshot.nodes;
1204
+ this.edges = snapshot.edges;
1205
+ const moving = snapshot.nodes.filter(n => {
1206
+ const f = from.get(n.id);
1207
+ return f && (f.x !== n.position.x || f.y !== n.position.y);
1208
+ });
1209
+ if (moving.length && !prefersReducedMotion()) {
1210
+ this.stopRestoreTween = tween({
1211
+ duration: 260,
1212
+ easing: easeOutCubic,
1213
+ onUpdate: p => {
1214
+ for (const n of moving) {
1215
+ const f = from.get(n.id);
1216
+ if (f) {
1217
+ this.positionOverrides.set(n.id, {
1218
+ x: f.x + (n.position.x - f.x) * p,
1219
+ y: f.y + (n.position.y - f.y) * p,
1220
+ });
1221
+ }
1222
+ }
1223
+ this.requestUpdate();
1224
+ },
1225
+ onDone: () => {
1226
+ this.positionOverrides.clear();
1227
+ this.stopRestoreTween = undefined;
1228
+ this.requestUpdate();
1229
+ },
1230
+ });
1231
+ }
1232
+ this.selection.retain('node', new Set(snapshot.nodes.map(n => n.id)));
1233
+ this.selection.retain('edge', new Set(snapshot.edges.map(e => e.id)));
1234
+ this.emitChange(reason);
1235
+ }
1236
+
1237
+ // ── Private methods: connections
1238
+
1239
+ private onPortPointerDown(
1240
+ event: PointerEvent,
1241
+ node: DiagramNode,
1242
+ port: ResolvedPort,
1243
+ ) {
1244
+ if (event.button !== 0 || this.viewport.spaceHeld) return;
1245
+ event.stopPropagation();
1246
+ event.preventDefault();
1247
+ if (this.readonly || port.type === 'target') return;
1248
+ const point = this.portPoint(node, port);
1249
+ this.beginConnectionDrag(event, {
1250
+ mode: 'new',
1251
+ end: 'target',
1252
+ fixedNode: node.id,
1253
+ fixedPort: port,
1254
+ fixedPoint: point,
1255
+ pointer: point,
1256
+ });
1257
+ }
1258
+
1259
+ private startReconnect(
1260
+ event: PointerEvent,
1261
+ edge: DiagramEdge,
1262
+ end: 'source' | 'target',
1263
+ ) {
1264
+ if (event.button !== 0) return;
1265
+ event.stopPropagation();
1266
+ event.preventDefault();
1267
+ const byId = new Map(this.nodes.map(n => [n.id, n]));
1268
+ const render = this.edgeRender(edge, byId);
1269
+ const fixedNode = byId.get(end === 'target' ? edge.source : edge.target);
1270
+ if (!render || !fixedNode) return;
1271
+ const fixedPort = this.findPort(
1272
+ fixedNode,
1273
+ end === 'target' ? edge.sourceHandle : edge.targetHandle,
1274
+ end === 'target' ? 'source' : 'target',
1275
+ );
1276
+ this.beginConnectionDrag(event, {
1277
+ mode: 'reconnect',
1278
+ edgeId: edge.id,
1279
+ end,
1280
+ fixedNode: fixedNode.id,
1281
+ fixedPort,
1282
+ fixedPoint: end === 'target' ? render.start : render.end,
1283
+ pointer: end === 'target' ? render.end : render.start,
1284
+ });
1285
+ }
1286
+
1287
+ private beginConnectionDrag(
1288
+ event: PointerEvent,
1289
+ connection: NonNullable<Diagram['_connection']>,
1290
+ ) {
1291
+ const element = event.currentTarget as HTMLElement;
1292
+ this._connection = connection;
1293
+ this.connectionDrag = { pointerId: event.pointerId, element };
1294
+ try {
1295
+ element.setPointerCapture(event.pointerId);
1296
+ } catch {
1297
+ // Synthetic or already released pointers cannot be captured.
1298
+ }
1299
+ element.addEventListener('pointermove', this.onConnectionPointerMove);
1300
+ element.addEventListener('pointerup', this.onConnectionPointerUp);
1301
+ element.addEventListener('pointercancel', this.onConnectionPointerCancel);
1302
+ }
1303
+
1304
+ /** The nearest port that can take the moving end, within snapping distance. */
1305
+ private findSnap(point: DiagramPoint) {
1306
+ const c = this._connection;
1307
+ if (!c) return undefined;
1308
+ const role = c.end === 'target' ? 'target' : 'source';
1309
+ const limit = SNAP_DISTANCE / this.viewport.view.zoom;
1310
+ let best:
1311
+ | { nodeId: string; port: ResolvedPort; point: DiagramPoint; d: number }
1312
+ | undefined;
1313
+ const probe = { ...point, width: 0.01, height: 0.01 };
1314
+ for (const node of this.nodes.filter(n => n.id !== c.fixedNode)) {
1315
+ const rect = this.nodeRect(node);
1316
+ const inside = rectsIntersect(rect, probe);
1317
+ if (inside || rectsIntersect(inflateRect(rect, limit), probe)) {
1318
+ const ports = this.resolvePorts(node).filter(
1319
+ port => port.type === 'both' || port.type === role,
1320
+ );
1321
+ for (const port of ports) {
1322
+ const p = this.portPoint(node, port);
1323
+ const d = Math.hypot(p.x - point.x, p.y - point.y);
1324
+ if ((inside || d <= limit) && (!best || d < best.d)) {
1325
+ best = { nodeId: node.id, port, point: p, d };
1326
+ }
1327
+ }
1328
+ }
1329
+ }
1330
+ return best
1331
+ ? { nodeId: best.nodeId, port: best.port, point: best.point }
1332
+ : undefined;
1333
+ }
1334
+
1335
+ private onConnectionPointerMove = (event: PointerEvent) => {
1336
+ const c = this._connection;
1337
+ if (!c || event.pointerId !== this.connectionDrag?.pointerId) return;
1338
+ const goal = this.viewport.toCanvas(event.clientX, event.clientY);
1339
+ const snap = this.findSnap(goal);
1340
+ const target = snap?.point ?? goal;
1341
+ if (prefersReducedMotion()) {
1342
+ this._connection = { ...c, snap, pointer: target };
1343
+ return;
1344
+ }
1345
+ // A short spring so the preview line follows the pointer smoothly.
1346
+ this._connection = { ...c, snap };
1347
+ const step = () => {
1348
+ const cur = this._connection;
1349
+ if (!cur) return;
1350
+ const dx = target.x - cur.pointer.x;
1351
+ const dy = target.y - cur.pointer.y;
1352
+ const done = Math.hypot(dx, dy) < 0.5;
1353
+ this._connection = {
1354
+ ...cur,
1355
+ pointer: done
1356
+ ? target
1357
+ : { x: cur.pointer.x + dx * 0.45, y: cur.pointer.y + dy * 0.45 },
1358
+ };
1359
+ this.connectionFrame = done ? 0 : requestAnimationFrame(step);
1360
+ };
1361
+ cancelAnimationFrame(this.connectionFrame);
1362
+ this.connectionFrame = requestAnimationFrame(step);
1363
+ };
1364
+
1365
+ private onConnectionPointerUp = (event: PointerEvent) => {
1366
+ const c = this._connection;
1367
+ if (!c || event.pointerId !== this.connectionDrag?.pointerId) return;
1368
+ const snap =
1369
+ this.findSnap(this.viewport.toCanvas(event.clientX, event.clientY)) ??
1370
+ c.snap;
1371
+ this.cancelConnection();
1372
+ if (!snap) return;
1373
+ if (c.mode === 'new') {
1374
+ this.connect(c.fixedNode, c.fixedPort.id, snap.nodeId, snap.port.id);
1375
+ } else if (c.edgeId) {
1376
+ this.reconnect(c.edgeId, c.end, snap.nodeId, snap.port.id);
1377
+ }
1378
+ };
1379
+
1380
+ private onConnectionPointerCancel = () => {
1381
+ this.cancelConnection();
1382
+ };
1383
+
1384
+ /** Stops drawing a connection and releases its pointer. */
1385
+ private cancelConnection() {
1386
+ const drag = this.connectionDrag;
1387
+ this.connectionDrag = undefined;
1388
+ this._connection = undefined;
1389
+ cancelAnimationFrame(this.connectionFrame);
1390
+ this.connectionFrame = 0;
1391
+ if (!drag) return;
1392
+ const { element } = drag;
1393
+ element.removeEventListener('pointermove', this.onConnectionPointerMove);
1394
+ element.removeEventListener('pointerup', this.onConnectionPointerUp);
1395
+ element.removeEventListener(
1396
+ 'pointercancel',
1397
+ this.onConnectionPointerCancel,
1398
+ );
1399
+ try {
1400
+ if (element.hasPointerCapture(drag.pointerId)) {
1401
+ element.releasePointerCapture(drag.pointerId);
1402
+ }
1403
+ } catch {
1404
+ // The pointer is already gone.
1405
+ }
1406
+ }
1407
+
1408
+ private connect(
1409
+ source: string,
1410
+ sourceHandle: string,
1411
+ target: string,
1412
+ targetHandle: string,
1413
+ ) {
1414
+ if (source === target) return;
1415
+ const detail = { source, target, sourceHandle, targetHandle };
1416
+ const allowed = this.emit<DiagramConnectDetail>('connect', detail, true);
1417
+ this.ripple(target, targetHandle);
1418
+ if (!this.editable || !allowed) return;
1419
+ const duplicate = this.edges.some(
1420
+ e =>
1421
+ e.source === source &&
1422
+ e.target === target &&
1423
+ (e.sourceHandle ?? '') === sourceHandle &&
1424
+ (e.targetHandle ?? '') === targetHandle,
1425
+ );
1426
+ if (duplicate) return;
1427
+ const id = this.uniqueId(
1428
+ `${source}-${target}`,
1429
+ new Set(this.edges.map(e => e.id)),
1430
+ );
1431
+ this.history.push(this.snapshot());
1432
+ this.edges = [...this.edges, { id, ...detail }];
1433
+ const byId = new Map(this.nodes.map(n => [n.id, n]));
1434
+ const from = byId.get(source);
1435
+ const to = byId.get(target);
1436
+ if (from && to) {
1437
+ this.announce(
1438
+ this.i18n.t('diagramConnected')(
1439
+ this.nodeLabel(from),
1440
+ this.nodeLabel(to),
1441
+ ),
1442
+ );
1443
+ }
1444
+ this.emitChange('connect');
1445
+ }
1446
+
1447
+ private reconnect(
1448
+ edgeId: string,
1449
+ end: 'source' | 'target',
1450
+ nodeId: string,
1451
+ portId: string,
1452
+ ) {
1453
+ const edge = this.edges.find(e => e.id === edgeId);
1454
+ if (!edge || !this.editable) return;
1455
+ const next =
1456
+ end === 'target'
1457
+ ? { ...edge, target: nodeId, targetHandle: portId }
1458
+ : { ...edge, source: nodeId, sourceHandle: portId };
1459
+ if (next.source === next.target) return;
1460
+ this.history.push(this.snapshot());
1461
+ this.edges = this.edges.map(e => (e.id === edgeId ? next : e));
1462
+ this.ripple(nodeId, portId);
1463
+ this.emitChange('reconnect');
1464
+ }
1465
+
1466
+ private ripple(nodeId: string, portId: string) {
1467
+ clearTimeout(this.rippleTimer);
1468
+ this._ripple = `${nodeId}\u0000${portId}`;
1469
+ this.rippleTimer = setTimeout(() => {
1470
+ this._ripple = '';
1471
+ }, 500);
1472
+ }
1473
+
1474
+ // ── Private methods: edges and marquee
1475
+
1476
+ private onEdgePointerDown(event: PointerEvent, edge: DiagramEdge) {
1477
+ if (event.button !== 0 || this.viewport.spaceHeld) return;
1478
+ event.stopPropagation();
1479
+ this.selectEdge(edge, event.shiftKey || event.metaKey || event.ctrlKey);
1480
+ }
1481
+
1482
+ private startMarquee(event: PointerEvent): boolean {
1483
+ if (!this.editable || !event.shiftKey) return false;
1484
+ const element = this._viewportEl;
1485
+ if (!element) return false;
1486
+ event.preventDefault();
1487
+ const rect = element.getBoundingClientRect();
1488
+ const point = { x: event.clientX - rect.left, y: event.clientY - rect.top };
1489
+ this._marquee = { start: point, end: point };
1490
+ this.marqueeDrag = { pointerId: event.pointerId, element, origin: rect };
1491
+ try {
1492
+ element.setPointerCapture(event.pointerId);
1493
+ } catch {
1494
+ // Synthetic pointers cannot be captured.
1495
+ }
1496
+ element.addEventListener('pointermove', this.onMarqueeMove);
1497
+ element.addEventListener('pointerup', this.onMarqueeUp);
1498
+ element.addEventListener('pointercancel', this.onMarqueeUp);
1499
+ return true;
1500
+ }
1501
+
1502
+ private onMarqueeMove = (event: PointerEvent) => {
1503
+ const drag = this.marqueeDrag;
1504
+ const m = this._marquee;
1505
+ if (!drag || !m || event.pointerId !== drag.pointerId) return;
1506
+ const end = {
1507
+ x: event.clientX - drag.origin.x,
1508
+ y: event.clientY - drag.origin.y,
1509
+ };
1510
+ this._marquee = { ...m, end };
1511
+ const { x, y, zoom } = this.viewport.view;
1512
+ const screen = rectFromPoints(m.start, end);
1513
+ const canvas = {
1514
+ x: (screen.x - x) / zoom,
1515
+ y: (screen.y - y) / zoom,
1516
+ width: screen.width / zoom,
1517
+ height: screen.height / zoom,
1518
+ };
1519
+ this.selection.set(
1520
+ this.nodes
1521
+ .filter(n => rectsIntersect(this.nodeRect(n), canvas))
1522
+ .map(n => ({ kind: 'node' as const, id: n.id })),
1523
+ );
1524
+ };
1525
+
1526
+ private onMarqueeUp = (event: PointerEvent) => {
1527
+ if (event.pointerId !== this.marqueeDrag?.pointerId) return;
1528
+ this.endMarquee();
1529
+ };
1530
+
1531
+ private endMarquee() {
1532
+ const drag = this.marqueeDrag;
1533
+ this.marqueeDrag = undefined;
1534
+ this._marquee = undefined;
1535
+ if (!drag) return;
1536
+ drag.element.removeEventListener('pointermove', this.onMarqueeMove);
1537
+ drag.element.removeEventListener('pointerup', this.onMarqueeUp);
1538
+ drag.element.removeEventListener('pointercancel', this.onMarqueeUp);
1539
+ try {
1540
+ if (drag.element.hasPointerCapture(drag.pointerId)) {
1541
+ drag.element.releasePointerCapture(drag.pointerId);
1542
+ }
1543
+ } catch {
1544
+ // The pointer is already gone.
1545
+ }
1546
+ }
1547
+
1548
+ // ── Render helpers
1549
+
1550
+ private renderNodeContent(node: DiagramNode) {
1551
+ const legacy = this.legacyElement(node);
1552
+ if (legacy) return legacy;
1553
+ return html`<slot name=${`node:${node.id}`}>
1554
+ <div class="diagram-node-default-card">
1555
+ ${node.icon
1556
+ ? html`<span class="diagram-node-icon"
1557
+ ><wc-icon name=${node.icon}></wc-icon
1558
+ ></span>`
1559
+ : nothing}
1560
+ <span class="diagram-node-text">
1561
+ <span class="diagram-node-title">${this.nodeLabel(node)}</span>
1562
+ ${node.supportingText
1563
+ ? html`<span class="diagram-node-supporting"
1564
+ >${node.supportingText}</span
1565
+ >`
1566
+ : nothing}
1567
+ </span>
1568
+ </div>
1569
+ </slot>`;
1570
+ }
1571
+
1572
+ private renderNode(node: DiagramNode, slotted: Set<string>) {
1573
+ const selected = this.selection.has('node', node.id);
1574
+ const position = this.nodePosition(node);
1575
+ const custom = !!this.legacyElement(node) || slotted.has(node.id);
1576
+ const connecting = !!this._connection;
1577
+ return html`
1578
+ <div
1579
+ class=${classMap({
1580
+ 'diagram-node': true,
1581
+ 'diagram-node-custom': custom,
1582
+ 'is-dragging': this._draggingIds.includes(node.id),
1583
+ 'is-selected': selected,
1584
+ 'is-locked': !!node.locked,
1585
+ [`intent-${node.intent}`]: !!node.intent,
1586
+ })}
1587
+ data-id=${node.id}
1588
+ role="group"
1589
+ aria-roledescription=${this.i18n.t('diagramNode')}
1590
+ tabindex="0"
1591
+ aria-label=${this.nodeLabel(node)}
1592
+ aria-current=${selected ? 'true' : nothing}
1593
+ style="left: ${position.x}px; top: ${position.y}px;"
1594
+ @pointerdown=${(e: PointerEvent) => this.onNodePointerDown(e, node)}
1595
+ @keydown=${(e: KeyboardEvent) => this.onNodeKeyDown(e, node)}
1596
+ @focus=${() => {
1597
+ this.focusedId = node.id;
1598
+ }}
1599
+ >
1600
+ ${this.resolvePorts(node).map(port => {
1601
+ const isSnap =
1602
+ this._connection?.snap?.nodeId === node.id &&
1603
+ this._connection.snap.port.id === port.id;
1604
+ const canTake =
1605
+ connecting &&
1606
+ this._connection?.fixedNode !== node.id &&
1607
+ (port.type === 'both' ||
1608
+ port.type ===
1609
+ (this._connection?.end === 'target' ? 'target' : 'source'));
1610
+ return html`<div
1611
+ class=${classMap({
1612
+ handle: true,
1613
+ 'handle-input': port.type !== 'source',
1614
+ 'handle-output': port.type !== 'target',
1615
+ [`handle-position-${port.side}`]: true,
1616
+ 'is-snap': isSnap,
1617
+ 'is-candidate': canTake,
1618
+ 'is-ripple': this._ripple === `${node.id}\u0000${port.id}`,
1619
+ })}
1620
+ data-node-id=${node.id}
1621
+ data-port=${port.id}
1622
+ data-position=${port.side}
1623
+ style="--_offset: ${port.offset * 100}%"
1624
+ title=${port.label ?? nothing}
1625
+ @pointerdown=${(e: PointerEvent) =>
1626
+ this.onPortPointerDown(e, node, port)}
1627
+ ></div>`;
1628
+ })}
1629
+ <div class="diagram-node-content">${this.renderNodeContent(node)}</div>
1630
+ </div>
1631
+ `;
1632
+ }
1633
+
1634
+ private renderMarkers(render: EdgeRender) {
1635
+ const out = [];
1636
+ for (const [marker, at, angle] of [
1637
+ [render.markerEnd, render.end, render.geometry.endAngle],
1638
+ [render.markerStart, render.start, render.geometry.startAngle],
1639
+ ] as const) {
1640
+ for (const shape of markerShapes(marker)) {
1641
+ out.push(
1642
+ svg`<path class="diagram-marker fill-${shape.fill}" d=${shape.d} transform=${markerTransform(at, angle)}></path>`,
1643
+ );
1644
+ }
1645
+ }
1646
+ return out;
1647
+ }
1648
+
1649
+ private renderEdge(render: EdgeRender, labels: Map<string, string>) {
1650
+ const { edge, geometry } = render;
1651
+ const selected = this.selection.has('edge', edge.id);
1652
+ const variant = edge.variant ?? 'solid';
1653
+ return svg`
1654
+ <g
1655
+ class=${classMap({
1656
+ 'diagram-edge-group': true,
1657
+ 'is-selected': selected,
1658
+ 'is-colored': !!edge.color,
1659
+ })}
1660
+ data-id=${edge.id}
1661
+ style=${edge.color ? `--_edge-color: ${edge.color}` : nothing}
1662
+ tabindex=${this.editable ? '0' : nothing}
1663
+ role=${this.editable ? 'button' : nothing}
1664
+ aria-label=${this.editable ? (labels.get(edge.id) ?? edge.id) : nothing}
1665
+ aria-pressed=${this.editable ? String(selected) : nothing}
1666
+ @pointerdown=${(e: PointerEvent) => this.onEdgePointerDown(e, edge)}
1667
+ @keydown=${(e: KeyboardEvent) => this.onEdgeKeyDown(e, edge)}
1668
+ >
1669
+ <path class="diagram-edge-hit" d=${geometry.d}></path>
1670
+ <path
1671
+ class=${classMap({
1672
+ 'diagram-edge': true,
1673
+ 'variant-dashed':
1674
+ variant === 'dashed' || variant === 'animated-dashed',
1675
+ 'variant-animated-dashed': variant === 'animated-dashed',
1676
+ })}
1677
+ d=${geometry.d}
1678
+ ></path>
1679
+ ${this.renderMarkers(render)}
1680
+ </g>
1681
+ `;
1682
+ }
1683
+
1684
+ private renderConnectionPreview() {
1685
+ const c = this._connection;
1686
+ if (!c) return nothing;
1687
+ const movingSide = c.snap?.port.side ?? OPPOSITE_SIDE[c.fixedPort.side];
1688
+ const g =
1689
+ c.end === 'target'
1690
+ ? edgeGeometry(
1691
+ this.connector,
1692
+ c.fixedPoint,
1693
+ c.fixedPort.side,
1694
+ c.pointer,
1695
+ movingSide,
1696
+ )
1697
+ : edgeGeometry(
1698
+ this.connector,
1699
+ c.pointer,
1700
+ movingSide,
1701
+ c.fixedPoint,
1702
+ c.fixedPort.side,
1703
+ );
1704
+ return svg`<path class=${classMap({ 'diagram-edge-preview': true, 'is-snapped': !!c.snap })} d=${g.d}></path>`;
1705
+ }
1706
+
1707
+ // ── Render
1708
+
1709
+ protected render() {
1710
+ const { x, y, zoom } = this.viewport.view;
1711
+ const { width, height } = this.viewport.size();
1712
+ const cull = this.startApplied && width > 0 && height > 0;
1713
+ const visible = inflateRect(
1714
+ this.viewport.visibleRect(),
1715
+ CULL_MARGIN / zoom,
1716
+ );
1717
+ const byId = new Map(this.nodes.map(n => [n.id, n]));
1718
+ const rects = new Map(this.nodes.map(n => [n.id, this.nodeRect(n)]));
1719
+ const keep = (n: DiagramNode) => {
1720
+ if (!cull) return true;
1721
+ const r = rects.get(n.id);
1722
+ return (
1723
+ (r && rectsIntersect(r, visible)) ||
1724
+ this.selection.has('node', n.id) ||
1725
+ this.focusedId === n.id ||
1726
+ this._draggingIds.includes(n.id)
1727
+ );
1728
+ };
1729
+ const shownNodes = this.nodes.filter(keep);
1730
+ const edgeLabels = new Map<string, string>();
1731
+ const shownEdges: EdgeRender[] = [];
1732
+ const edgeInView = (edge: DiagramEdge) => {
1733
+ const a = rects.get(edge.source);
1734
+ const b = rects.get(edge.target);
1735
+ if (!a || !b) return false;
1736
+ return !cull || rectsIntersect(boundsOf([a, b]) as DiagramRect, visible);
1737
+ };
1738
+ for (const edge of this.edges.filter(edgeInView)) {
1739
+ const render = this.edgeRender(edge, byId);
1740
+ if (render) shownEdges.push(render);
1741
+ const from = byId.get(edge.source);
1742
+ const to = byId.get(edge.target);
1743
+ edgeLabels.set(
1744
+ edge.id,
1745
+ this.i18n.t('diagramEdgeLabel')(
1746
+ from ? this.nodeLabel(from) : edge.source,
1747
+ to ? this.nodeLabel(to) : edge.target,
1748
+ edge.label,
1749
+ ),
1750
+ );
1751
+ }
1752
+ const slotted = new Set<string>();
1753
+ for (const child of Array.from(this.children)) {
1754
+ const slot = child.getAttribute('slot');
1755
+ if (slot?.startsWith('node:')) slotted.add(slot.slice(5));
1756
+ }
1757
+ const selectedEdges = this.editable
1758
+ ? shownEdges.filter(r => this.selection.has('edge', r.edge.id))
1759
+ : [];
1760
+ const marquee = this._marquee
1761
+ ? rectFromPoints(this._marquee.start, this._marquee.end)
1762
+ : undefined;
1763
+
1764
+ return html`
1765
+ <div
1766
+ class=${classMap({
1767
+ 'diagram-viewport': true,
1768
+ 'is-panning': this.viewport.panning,
1769
+ 'is-space': this.viewport.spaceHeld,
1770
+ 'is-connecting': !!this._connection,
1771
+ })}
1772
+ tabindex="0"
1773
+ role="region"
1774
+ aria-label=${this.label || this.i18n.t('diagramLabel')}
1775
+ aria-describedby="instructions"
1776
+ style=${this.gridStyle()}
1777
+ @keydown=${this.onViewportKeyDown}
1778
+ >
1779
+ <div
1780
+ class="diagram-world"
1781
+ style="transform: translate(${x}px, ${y}px) scale(${zoom});"
1782
+ >
1783
+ <svg class="diagram-svg" width="1" height="1" aria-hidden="true">
1784
+ ${shownEdges.map(r => this.renderEdge(r, edgeLabels))}
1785
+ ${this.renderConnectionPreview()}
1786
+ ${this._guides.map(
1787
+ g =>
1788
+ svg`<line class="diagram-guide" x1=${g.x1} y1=${g.y1} x2=${g.x2} y2=${g.y2}></line>`,
1789
+ )}
1790
+ </svg>
1791
+ <div class="diagram-nodes" @slotchange=${() => this.requestUpdate()}>
1792
+ ${repeat(
1793
+ shownNodes,
1794
+ node => node.id,
1795
+ node => this.renderNode(node, slotted),
1796
+ )}
1797
+ </div>
1798
+ ${shownEdges
1799
+ .filter(r => r.edge.label)
1800
+ .map(
1801
+ r =>
1802
+ html`<div
1803
+ class=${classMap({
1804
+ 'diagram-edge-label': true,
1805
+ 'is-selected': this.selection.has('edge', r.edge.id),
1806
+ })}
1807
+ style="left: ${r.geometry.mid.x}px; top: ${r.geometry.mid
1808
+ .y}px;"
1809
+ @pointerdown=${(e: PointerEvent) =>
1810
+ this.onEdgePointerDown(e, r.edge)}
1811
+ >
1812
+ ${r.edge.label}
1813
+ </div>`,
1814
+ )}
1815
+ ${selectedEdges.map(
1816
+ r => html`
1817
+ <div
1818
+ class="edge-end"
1819
+ style="left: ${r.start.x}px; top: ${r.start.y}px;"
1820
+ @pointerdown=${(e: PointerEvent) =>
1821
+ this.startReconnect(e, r.edge, 'source')}
1822
+ ></div>
1823
+ <div
1824
+ class="edge-end"
1825
+ style="left: ${r.end.x}px; top: ${r.end.y}px;"
1826
+ @pointerdown=${(e: PointerEvent) =>
1827
+ this.startReconnect(e, r.edge, 'target')}
1828
+ ></div>
1829
+ `,
1830
+ )}
1831
+ </div>
1832
+ ${marquee
1833
+ ? html`<div
1834
+ class="diagram-marquee"
1835
+ style="left: ${marquee.x}px; top: ${marquee.y}px; width: ${marquee.width}px; height: ${marquee.height}px;"
1836
+ ></div>`
1837
+ : nothing}
1838
+ ${this.renderBackToContent()}
1839
+ <div class="slot-controls"><slot name="controls"></slot></div>
1840
+ <div class="slot-minimap"><slot name="minimap"></slot></div>
1841
+ <div id="instructions" hidden>
1842
+ ${this.i18n.t('diagramInstructions')}
1843
+ </div>
1844
+ <div class="sr-only" aria-live="polite">${this._announcement}</div>
1845
+ </div>
1846
+ `;
1847
+ }
1848
+ }
1849
+
1850
+ // Nodes are measured after they render and the camera is placed from those sizes, so a second
1851
+ // update right after the first is expected. Lit warns about that in development builds.
1852
+ Diagram.disableWarning?.('change-in-update');