@getartisanflow/alpineflow 0.1.0-alpha

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 (196) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -0
  3. package/dist/alpineflow-collab.esm.js +465 -0
  4. package/dist/alpineflow-collab.esm.js.map +1 -0
  5. package/dist/alpineflow-collab.js +247 -0
  6. package/dist/alpineflow-collab.js.map +1 -0
  7. package/dist/alpineflow-dagre.esm.js +1661 -0
  8. package/dist/alpineflow-dagre.esm.js.map +1 -0
  9. package/dist/alpineflow-dagre.js +1655 -0
  10. package/dist/alpineflow-dagre.js.map +1 -0
  11. package/dist/alpineflow-elk.esm.js +47378 -0
  12. package/dist/alpineflow-elk.esm.js.map +1 -0
  13. package/dist/alpineflow-elk.js +47373 -0
  14. package/dist/alpineflow-elk.js.map +1 -0
  15. package/dist/alpineflow-force.esm.js +599 -0
  16. package/dist/alpineflow-force.esm.js.map +1 -0
  17. package/dist/alpineflow-force.js +477 -0
  18. package/dist/alpineflow-force.js.map +1 -0
  19. package/dist/alpineflow-hierarchy.esm.js +398 -0
  20. package/dist/alpineflow-hierarchy.esm.js.map +1 -0
  21. package/dist/alpineflow-hierarchy.js +393 -0
  22. package/dist/alpineflow-hierarchy.js.map +1 -0
  23. package/dist/alpineflow-theme.css +473 -0
  24. package/dist/alpineflow-whiteboard.esm.js +922 -0
  25. package/dist/alpineflow-whiteboard.esm.js.map +1 -0
  26. package/dist/alpineflow-whiteboard.js +922 -0
  27. package/dist/alpineflow-whiteboard.js.map +1 -0
  28. package/dist/alpineflow.bundle.esm.js +12604 -0
  29. package/dist/alpineflow.bundle.esm.js.map +1 -0
  30. package/dist/alpineflow.css +1415 -0
  31. package/dist/alpineflow.esm.js +158 -0
  32. package/dist/alpineflow.esm.js.map +1 -0
  33. package/dist/alpineflow.js +5 -0
  34. package/dist/alpineflow.js.map +1 -0
  35. package/dist/export-DjmXOnKD.js +76 -0
  36. package/dist/export-DjmXOnKD.js.map +1 -0
  37. package/dist/geometry-DZSZoYHE.js +82 -0
  38. package/dist/geometry-DZSZoYHE.js.map +1 -0
  39. package/dist/index-C0N1DL3G.js +11728 -0
  40. package/dist/index-C0N1DL3G.js.map +1 -0
  41. package/dist/index-L3Zm-CoX.js +513 -0
  42. package/dist/index-L3Zm-CoX.js.map +1 -0
  43. package/dist/registry-CChkuoVJ.js +15 -0
  44. package/dist/registry-CChkuoVJ.js.map +1 -0
  45. package/dist/store-CaFAFEdD.js +9 -0
  46. package/dist/store-CaFAFEdD.js.map +1 -0
  47. package/dist/timer-B39XOBYL.js +124 -0
  48. package/dist/timer-B39XOBYL.js.map +1 -0
  49. package/dist/types/lib/collab.cdn.d.ts +1 -0
  50. package/dist/types/lib/collab.d.ts +2 -0
  51. package/dist/types/lib/core.cdn.d.ts +1 -0
  52. package/dist/types/lib/core.d.ts +2 -0
  53. package/dist/types/lib/dagre.cdn.d.ts +1 -0
  54. package/dist/types/lib/dagre.d.ts +1 -0
  55. package/dist/types/lib/elk.cdn.d.ts +1 -0
  56. package/dist/types/lib/elk.d.ts +1 -0
  57. package/dist/types/lib/force.cdn.d.ts +1 -0
  58. package/dist/types/lib/force.d.ts +1 -0
  59. package/dist/types/lib/hierarchy.cdn.d.ts +1 -0
  60. package/dist/types/lib/hierarchy.d.ts +1 -0
  61. package/dist/types/lib/whiteboard.cdn.d.ts +1 -0
  62. package/dist/types/lib/whiteboard.d.ts +1 -0
  63. package/dist/types/src/animate/animator.d.ts +57 -0
  64. package/dist/types/src/animate/easing.d.ts +4 -0
  65. package/dist/types/src/animate/edge-transitions.d.ts +22 -0
  66. package/dist/types/src/animate/engine.d.ts +37 -0
  67. package/dist/types/src/animate/index.d.ts +10 -0
  68. package/dist/types/src/animate/interpolators.d.ts +14 -0
  69. package/dist/types/src/animate/paths.d.ts +64 -0
  70. package/dist/types/src/animate/timeline.d.ts +149 -0
  71. package/dist/types/src/collab/awareness.d.ts +40 -0
  72. package/dist/types/src/collab/bridge.d.ts +36 -0
  73. package/dist/types/src/collab/directives/flow-cursors.d.ts +16 -0
  74. package/dist/types/src/collab/index.d.ts +19 -0
  75. package/dist/types/src/collab/providers/in-memory.d.ts +41 -0
  76. package/dist/types/src/collab/providers/reverb.d.ts +59 -0
  77. package/dist/types/src/collab/providers/websocket.d.ts +33 -0
  78. package/dist/types/src/collab/store.d.ts +22 -0
  79. package/dist/types/src/collab/types.d.ts +55 -0
  80. package/dist/types/src/core/__fixtures__/nodes.d.ts +42 -0
  81. package/dist/types/src/core/announcer.d.ts +21 -0
  82. package/dist/types/src/core/auto-pan.d.ts +37 -0
  83. package/dist/types/src/core/child-layout.d.ts +18 -0
  84. package/dist/types/src/core/child-validation.d.ts +23 -0
  85. package/dist/types/src/core/clipboard.d.ts +29 -0
  86. package/dist/types/src/core/collapse.d.ts +54 -0
  87. package/dist/types/src/core/color-mode.d.ts +11 -0
  88. package/dist/types/src/core/compute.d.ts +33 -0
  89. package/dist/types/src/core/connections.d.ts +32 -0
  90. package/dist/types/src/core/constants.d.ts +18 -0
  91. package/dist/types/src/core/controls-panel.d.ts +23 -0
  92. package/dist/types/src/core/debug.d.ts +10 -0
  93. package/dist/types/src/core/deep-merge.d.ts +10 -0
  94. package/dist/types/src/core/drag.d.ts +63 -0
  95. package/dist/types/src/core/edge-paths/avoidant.d.ts +25 -0
  96. package/dist/types/src/core/edge-paths/bezier.d.ts +26 -0
  97. package/dist/types/src/core/edge-paths/editable.d.ts +22 -0
  98. package/dist/types/src/core/edge-paths/index.d.ts +7 -0
  99. package/dist/types/src/core/edge-paths/orthogonal.d.ts +27 -0
  100. package/dist/types/src/core/edge-paths/smoothstep.d.ts +22 -0
  101. package/dist/types/src/core/edge-paths/straight.d.ts +12 -0
  102. package/dist/types/src/core/edge-paths/utils.d.ts +30 -0
  103. package/dist/types/src/core/edge-utils.d.ts +57 -0
  104. package/dist/types/src/core/export.d.ts +12 -0
  105. package/dist/types/src/core/floating-edge.d.ts +33 -0
  106. package/dist/types/src/core/geometry.d.ts +79 -0
  107. package/dist/types/src/core/gradients.d.ts +30 -0
  108. package/dist/types/src/core/graph.d.ts +38 -0
  109. package/dist/types/src/core/helper-lines.d.ts +32 -0
  110. package/dist/types/src/core/history.d.ts +19 -0
  111. package/dist/types/src/core/index.d.ts +17 -0
  112. package/dist/types/src/core/intersection.d.ts +30 -0
  113. package/dist/types/src/core/keyboard-shortcuts.d.ts +45 -0
  114. package/dist/types/src/core/lasso-hit-test.d.ts +25 -0
  115. package/dist/types/src/core/lasso.d.ts +10 -0
  116. package/dist/types/src/core/layout/dagre.d.ts +11 -0
  117. package/dist/types/src/core/layout/elk.d.ts +13 -0
  118. package/dist/types/src/core/layout/force.d.ts +15 -0
  119. package/dist/types/src/core/layout/hierarchy.d.ts +13 -0
  120. package/dist/types/src/core/long-press.d.ts +11 -0
  121. package/dist/types/src/core/markers.d.ts +49 -0
  122. package/dist/types/src/core/minimap.d.ts +18 -0
  123. package/dist/types/src/core/node-flags.d.ts +19 -0
  124. package/dist/types/src/core/pan-zoom.d.ts +62 -0
  125. package/dist/types/src/core/proximity-connect.d.ts +25 -0
  126. package/dist/types/src/core/registry.d.ts +16 -0
  127. package/dist/types/src/core/render-plan.d.ts +52 -0
  128. package/dist/types/src/core/resize.d.ts +31 -0
  129. package/dist/types/src/core/rotation.d.ts +8 -0
  130. package/dist/types/src/core/selection-box.d.ts +14 -0
  131. package/dist/types/src/core/shapes.d.ts +10 -0
  132. package/dist/types/src/core/sub-flow.d.ts +61 -0
  133. package/dist/types/src/core/svg-path.d.ts +5 -0
  134. package/dist/types/src/core/types.d.ts +1238 -0
  135. package/dist/types/src/core/wire-bridge.d.ts +36 -0
  136. package/dist/types/src/index.d.ts +43 -0
  137. package/dist/types/src/layout/dagre.d.ts +2 -0
  138. package/dist/types/src/layout/elk.d.ts +2 -0
  139. package/dist/types/src/layout/force.d.ts +2 -0
  140. package/dist/types/src/layout/hierarchy.d.ts +2 -0
  141. package/dist/types/src/plugin/connection-utils.d.ts +54 -0
  142. package/dist/types/src/plugin/data/__test-utils.d.ts +9 -0
  143. package/dist/types/src/plugin/data/canvas-animation.d.ts +62 -0
  144. package/dist/types/src/plugin/data/canvas-collapse.d.ts +35 -0
  145. package/dist/types/src/plugin/data/canvas-compute.d.ts +6 -0
  146. package/dist/types/src/plugin/data/canvas-condense.d.ts +19 -0
  147. package/dist/types/src/plugin/data/canvas-config.d.ts +4 -0
  148. package/dist/types/src/plugin/data/canvas-context.d.ts +570 -0
  149. package/dist/types/src/plugin/data/canvas-dom.d.ts +13 -0
  150. package/dist/types/src/plugin/data/canvas-edges.d.ts +37 -0
  151. package/dist/types/src/plugin/data/canvas-history.d.ts +53 -0
  152. package/dist/types/src/plugin/data/canvas-layout.d.ts +151 -0
  153. package/dist/types/src/plugin/data/canvas-nodes.d.ts +73 -0
  154. package/dist/types/src/plugin/data/canvas-rows.d.ts +13 -0
  155. package/dist/types/src/plugin/data/canvas-selection.d.ts +45 -0
  156. package/dist/types/src/plugin/data/canvas-validation.d.ts +21 -0
  157. package/dist/types/src/plugin/data/canvas-viewport.d.ts +111 -0
  158. package/dist/types/src/plugin/data/flow-canvas.d.ts +2 -0
  159. package/dist/types/src/plugin/directives/flow-action.d.ts +12 -0
  160. package/dist/types/src/plugin/directives/flow-animate.d.ts +2 -0
  161. package/dist/types/src/plugin/directives/flow-arrow-draw.d.ts +2 -0
  162. package/dist/types/src/plugin/directives/flow-circle-draw.d.ts +2 -0
  163. package/dist/types/src/plugin/directives/flow-collapse.d.ts +2 -0
  164. package/dist/types/src/plugin/directives/flow-condense.d.ts +2 -0
  165. package/dist/types/src/plugin/directives/flow-context-menu.d.ts +2 -0
  166. package/dist/types/src/plugin/directives/flow-detail.d.ts +2 -0
  167. package/dist/types/src/plugin/directives/flow-devtools.d.ts +2 -0
  168. package/dist/types/src/plugin/directives/flow-drag-handle.d.ts +2 -0
  169. package/dist/types/src/plugin/directives/flow-draggable.d.ts +2 -0
  170. package/dist/types/src/plugin/directives/flow-edge-toolbar.d.ts +2 -0
  171. package/dist/types/src/plugin/directives/flow-edge.d.ts +7 -0
  172. package/dist/types/src/plugin/directives/flow-eraser.d.ts +2 -0
  173. package/dist/types/src/plugin/directives/flow-filter.d.ts +9 -0
  174. package/dist/types/src/plugin/directives/flow-follow.d.ts +9 -0
  175. package/dist/types/src/plugin/directives/flow-freehand.d.ts +2 -0
  176. package/dist/types/src/plugin/directives/flow-handle-connectable.d.ts +12 -0
  177. package/dist/types/src/plugin/directives/flow-handle-limit.d.ts +9 -0
  178. package/dist/types/src/plugin/directives/flow-handle-validate.d.ts +10 -0
  179. package/dist/types/src/plugin/directives/flow-handle.d.ts +29 -0
  180. package/dist/types/src/plugin/directives/flow-highlighter.d.ts +2 -0
  181. package/dist/types/src/plugin/directives/flow-loading.d.ts +2 -0
  182. package/dist/types/src/plugin/directives/flow-node-toolbar.d.ts +2 -0
  183. package/dist/types/src/plugin/directives/flow-node.d.ts +10 -0
  184. package/dist/types/src/plugin/directives/flow-panel.d.ts +2 -0
  185. package/dist/types/src/plugin/directives/flow-rectangle-draw.d.ts +2 -0
  186. package/dist/types/src/plugin/directives/flow-resizer.d.ts +2 -0
  187. package/dist/types/src/plugin/directives/flow-rotate.d.ts +11 -0
  188. package/dist/types/src/plugin/directives/flow-row-select.d.ts +2 -0
  189. package/dist/types/src/plugin/directives/flow-snapshot.d.ts +14 -0
  190. package/dist/types/src/plugin/directives/flow-text-tool.d.ts +2 -0
  191. package/dist/types/src/plugin/directives/flow-timeline.d.ts +2 -0
  192. package/dist/types/src/plugin/directives/flow-viewport.d.ts +2 -0
  193. package/dist/types/src/plugin/magics/flow.d.ts +2 -0
  194. package/dist/types/src/plugin/store.d.ts +2 -0
  195. package/dist/types/src/whiteboard/index.d.ts +2 -0
  196. package/package.json +153 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alpineflow-hierarchy.esm.js","sources":["../src/core/registry.ts","../node_modules/d3-hierarchy/src/cluster.js","../node_modules/d3-hierarchy/src/hierarchy/count.js","../node_modules/d3-hierarchy/src/hierarchy/each.js","../node_modules/d3-hierarchy/src/hierarchy/eachBefore.js","../node_modules/d3-hierarchy/src/hierarchy/eachAfter.js","../node_modules/d3-hierarchy/src/hierarchy/find.js","../node_modules/d3-hierarchy/src/hierarchy/sum.js","../node_modules/d3-hierarchy/src/hierarchy/sort.js","../node_modules/d3-hierarchy/src/hierarchy/path.js","../node_modules/d3-hierarchy/src/hierarchy/ancestors.js","../node_modules/d3-hierarchy/src/hierarchy/descendants.js","../node_modules/d3-hierarchy/src/hierarchy/leaves.js","../node_modules/d3-hierarchy/src/hierarchy/links.js","../node_modules/d3-hierarchy/src/hierarchy/iterator.js","../node_modules/d3-hierarchy/src/hierarchy/index.js","../node_modules/d3-hierarchy/src/accessors.js","../node_modules/d3-hierarchy/src/stratify.js","../node_modules/d3-hierarchy/src/tree.js","../src/core/geometry.ts","../src/core/layout/hierarchy.ts","../src/layout/hierarchy.ts"],"sourcesContent":["/**\n * Addon registry — singleton via window global.\n *\n * When AlpineFlow core is loaded from one bundle (e.g., WireFlow's\n * alpineflow.bundle.esm.js) and addons are loaded from separate ESM\n * files, each bundle gets its own module scope. A module-scoped Map\n * would create disconnected registries — addons would register on\n * their copy, but the core would check its own empty copy.\n *\n * Using a window global ensures all bundles share one registry,\n * regardless of how they're loaded (CDN, npm, Vite, WireFlow bundle).\n */\n\nconst REGISTRY_KEY = '__alpineflow_registry__';\n\nfunction getRegistry(): Map<string, any> {\n if (typeof globalThis !== 'undefined') {\n if (!(globalThis as any)[REGISTRY_KEY]) {\n (globalThis as any)[REGISTRY_KEY] = new Map<string, any>();\n }\n return (globalThis as any)[REGISTRY_KEY];\n }\n // Fallback for environments without globalThis (shouldn't happen in modern runtimes)\n return new Map<string, any>();\n}\n\nexport function registerAddon(name: string, value: any): void {\n getRegistry().set(name, value);\n}\n\nexport function getAddon<T = any>(name: string): T | undefined {\n return getRegistry().get(name);\n}\n\n/** Test-only: clear all registered addons. */\nexport function _resetRegistry(): void {\n getRegistry().clear();\n}\n","function defaultSeparation(a, b) {\n return a.parent === b.parent ? 1 : 2;\n}\n\nfunction meanX(children) {\n return children.reduce(meanXReduce, 0) / children.length;\n}\n\nfunction meanXReduce(x, c) {\n return x + c.x;\n}\n\nfunction maxY(children) {\n return 1 + children.reduce(maxYReduce, 0);\n}\n\nfunction maxYReduce(y, c) {\n return Math.max(y, c.y);\n}\n\nfunction leafLeft(node) {\n var children;\n while (children = node.children) node = children[0];\n return node;\n}\n\nfunction leafRight(node) {\n var children;\n while (children = node.children) node = children[children.length - 1];\n return node;\n}\n\nexport default function() {\n var separation = defaultSeparation,\n dx = 1,\n dy = 1,\n nodeSize = false;\n\n function cluster(root) {\n var previousNode,\n x = 0;\n\n // First walk, computing the initial x & y values.\n root.eachAfter(function(node) {\n var children = node.children;\n if (children) {\n node.x = meanX(children);\n node.y = maxY(children);\n } else {\n node.x = previousNode ? x += separation(node, previousNode) : 0;\n node.y = 0;\n previousNode = node;\n }\n });\n\n var left = leafLeft(root),\n right = leafRight(root),\n x0 = left.x - separation(left, right) / 2,\n x1 = right.x + separation(right, left) / 2;\n\n // Second walk, normalizing x & y to the desired size.\n return root.eachAfter(nodeSize ? function(node) {\n node.x = (node.x - root.x) * dx;\n node.y = (root.y - node.y) * dy;\n } : function(node) {\n node.x = (node.x - x0) / (x1 - x0) * dx;\n node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;\n });\n }\n\n cluster.separation = function(x) {\n return arguments.length ? (separation = x, cluster) : separation;\n };\n\n cluster.size = function(x) {\n return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);\n };\n\n cluster.nodeSize = function(x) {\n return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);\n };\n\n return cluster;\n}\n","function count(node) {\n var sum = 0,\n children = node.children,\n i = children && children.length;\n if (!i) sum = 1;\n else while (--i >= 0) sum += children[i].value;\n node.value = sum;\n}\n\nexport default function() {\n return this.eachAfter(count);\n}\n","export default function(callback, that) {\n let index = -1;\n for (const node of this) {\n callback.call(that, node, ++index, this);\n }\n return this;\n}\n","export default function(callback, that) {\n var node = this, nodes = [node], children, i, index = -1;\n while (node = nodes.pop()) {\n callback.call(that, node, ++index, this);\n if (children = node.children) {\n for (i = children.length - 1; i >= 0; --i) {\n nodes.push(children[i]);\n }\n }\n }\n return this;\n}\n","export default function(callback, that) {\n var node = this, nodes = [node], next = [], children, i, n, index = -1;\n while (node = nodes.pop()) {\n next.push(node);\n if (children = node.children) {\n for (i = 0, n = children.length; i < n; ++i) {\n nodes.push(children[i]);\n }\n }\n }\n while (node = next.pop()) {\n callback.call(that, node, ++index, this);\n }\n return this;\n}\n","export default function(callback, that) {\n let index = -1;\n for (const node of this) {\n if (callback.call(that, node, ++index, this)) {\n return node;\n }\n }\n}\n","export default function(value) {\n return this.eachAfter(function(node) {\n var sum = +value(node.data) || 0,\n children = node.children,\n i = children && children.length;\n while (--i >= 0) sum += children[i].value;\n node.value = sum;\n });\n}\n","export default function(compare) {\n return this.eachBefore(function(node) {\n if (node.children) {\n node.children.sort(compare);\n }\n });\n}\n","export default function(end) {\n var start = this,\n ancestor = leastCommonAncestor(start, end),\n nodes = [start];\n while (start !== ancestor) {\n start = start.parent;\n nodes.push(start);\n }\n var k = nodes.length;\n while (end !== ancestor) {\n nodes.splice(k, 0, end);\n end = end.parent;\n }\n return nodes;\n}\n\nfunction leastCommonAncestor(a, b) {\n if (a === b) return a;\n var aNodes = a.ancestors(),\n bNodes = b.ancestors(),\n c = null;\n a = aNodes.pop();\n b = bNodes.pop();\n while (a === b) {\n c = a;\n a = aNodes.pop();\n b = bNodes.pop();\n }\n return c;\n}\n","export default function() {\n var node = this, nodes = [node];\n while (node = node.parent) {\n nodes.push(node);\n }\n return nodes;\n}\n","export default function() {\n return Array.from(this);\n}\n","export default function() {\n var leaves = [];\n this.eachBefore(function(node) {\n if (!node.children) {\n leaves.push(node);\n }\n });\n return leaves;\n}\n","export default function() {\n var root = this, links = [];\n root.each(function(node) {\n if (node !== root) { // Don’t include the root’s parent, if any.\n links.push({source: node.parent, target: node});\n }\n });\n return links;\n}\n","export default function*() {\n var node = this, current, next = [node], children, i, n;\n do {\n current = next.reverse(), next = [];\n while (node = current.pop()) {\n yield node;\n if (children = node.children) {\n for (i = 0, n = children.length; i < n; ++i) {\n next.push(children[i]);\n }\n }\n }\n } while (next.length);\n}\n","import node_count from \"./count.js\";\nimport node_each from \"./each.js\";\nimport node_eachBefore from \"./eachBefore.js\";\nimport node_eachAfter from \"./eachAfter.js\";\nimport node_find from \"./find.js\";\nimport node_sum from \"./sum.js\";\nimport node_sort from \"./sort.js\";\nimport node_path from \"./path.js\";\nimport node_ancestors from \"./ancestors.js\";\nimport node_descendants from \"./descendants.js\";\nimport node_leaves from \"./leaves.js\";\nimport node_links from \"./links.js\";\nimport node_iterator from \"./iterator.js\";\n\nexport default function hierarchy(data, children) {\n if (data instanceof Map) {\n data = [undefined, data];\n if (children === undefined) children = mapChildren;\n } else if (children === undefined) {\n children = objectChildren;\n }\n\n var root = new Node(data),\n node,\n nodes = [root],\n child,\n childs,\n i,\n n;\n\n while (node = nodes.pop()) {\n if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {\n node.children = childs;\n for (i = n - 1; i >= 0; --i) {\n nodes.push(child = childs[i] = new Node(childs[i]));\n child.parent = node;\n child.depth = node.depth + 1;\n }\n }\n }\n\n return root.eachBefore(computeHeight);\n}\n\nfunction node_copy() {\n return hierarchy(this).eachBefore(copyData);\n}\n\nfunction objectChildren(d) {\n return d.children;\n}\n\nfunction mapChildren(d) {\n return Array.isArray(d) ? d[1] : null;\n}\n\nfunction copyData(node) {\n if (node.data.value !== undefined) node.value = node.data.value;\n node.data = node.data.data;\n}\n\nexport function computeHeight(node) {\n var height = 0;\n do node.height = height;\n while ((node = node.parent) && (node.height < ++height));\n}\n\nexport function Node(data) {\n this.data = data;\n this.depth =\n this.height = 0;\n this.parent = null;\n}\n\nNode.prototype = hierarchy.prototype = {\n constructor: Node,\n count: node_count,\n each: node_each,\n eachAfter: node_eachAfter,\n eachBefore: node_eachBefore,\n find: node_find,\n sum: node_sum,\n sort: node_sort,\n path: node_path,\n ancestors: node_ancestors,\n descendants: node_descendants,\n leaves: node_leaves,\n links: node_links,\n copy: node_copy,\n [Symbol.iterator]: node_iterator\n};\n","export function optional(f) {\n return f == null ? null : required(f);\n}\n\nexport function required(f) {\n if (typeof f !== \"function\") throw new Error;\n return f;\n}\n","import {optional} from \"./accessors.js\";\nimport {Node, computeHeight} from \"./hierarchy/index.js\";\n\nvar preroot = {depth: -1},\n ambiguous = {},\n imputed = {};\n\nfunction defaultId(d) {\n return d.id;\n}\n\nfunction defaultParentId(d) {\n return d.parentId;\n}\n\nexport default function() {\n var id = defaultId,\n parentId = defaultParentId,\n path;\n\n function stratify(data) {\n var nodes = Array.from(data),\n currentId = id,\n currentParentId = parentId,\n n,\n d,\n i,\n root,\n parent,\n node,\n nodeId,\n nodeKey,\n nodeByKey = new Map;\n\n if (path != null) {\n const I = nodes.map((d, i) => normalize(path(d, i, data)));\n const P = I.map(parentof);\n const S = new Set(I).add(\"\");\n for (const i of P) {\n if (!S.has(i)) {\n S.add(i);\n I.push(i);\n P.push(parentof(i));\n nodes.push(imputed);\n }\n }\n currentId = (_, i) => I[i];\n currentParentId = (_, i) => P[i];\n }\n\n for (i = 0, n = nodes.length; i < n; ++i) {\n d = nodes[i], node = nodes[i] = new Node(d);\n if ((nodeId = currentId(d, i, data)) != null && (nodeId += \"\")) {\n nodeKey = node.id = nodeId;\n nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);\n }\n if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += \"\")) {\n node.parent = nodeId;\n }\n }\n\n for (i = 0; i < n; ++i) {\n node = nodes[i];\n if (nodeId = node.parent) {\n parent = nodeByKey.get(nodeId);\n if (!parent) throw new Error(\"missing: \" + nodeId);\n if (parent === ambiguous) throw new Error(\"ambiguous: \" + nodeId);\n if (parent.children) parent.children.push(node);\n else parent.children = [node];\n node.parent = parent;\n } else {\n if (root) throw new Error(\"multiple roots\");\n root = node;\n }\n }\n\n if (!root) throw new Error(\"no root\");\n\n // When imputing internal nodes, only introduce roots if needed.\n // Then replace the imputed marker data with null.\n if (path != null) {\n while (root.data === imputed && root.children.length === 1) {\n root = root.children[0], --n;\n }\n for (let i = nodes.length - 1; i >= 0; --i) {\n node = nodes[i];\n if (node.data !== imputed) break;\n node.data = null;\n }\n }\n\n root.parent = preroot;\n root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);\n root.parent = null;\n if (n > 0) throw new Error(\"cycle\");\n\n return root;\n }\n\n stratify.id = function(x) {\n return arguments.length ? (id = optional(x), stratify) : id;\n };\n\n stratify.parentId = function(x) {\n return arguments.length ? (parentId = optional(x), stratify) : parentId;\n };\n\n stratify.path = function(x) {\n return arguments.length ? (path = optional(x), stratify) : path;\n };\n\n return stratify;\n}\n\n// To normalize a path, we coerce to a string, strip the trailing slash if any\n// (as long as the trailing slash is not immediately preceded by another slash),\n// and add leading slash if missing.\nfunction normalize(path) {\n path = `${path}`;\n let i = path.length;\n if (slash(path, i - 1) && !slash(path, i - 2)) path = path.slice(0, -1);\n return path[0] === \"/\" ? path : `/${path}`;\n}\n\n// Walk backwards to find the first slash that is not the leading slash, e.g.:\n// \"/foo/bar\" ⇥ \"/foo\", \"/foo\" ⇥ \"/\", \"/\" ↦ \"\". (The root is special-cased\n// because the id of the root must be a truthy value.)\nfunction parentof(path) {\n let i = path.length;\n if (i < 2) return \"\";\n while (--i > 1) if (slash(path, i)) break;\n return path.slice(0, i);\n}\n\n// Slashes can be escaped; to determine whether a slash is a path delimiter, we\n// count the number of preceding backslashes escaping the forward slash: an odd\n// number indicates an escaped forward slash.\nfunction slash(path, i) {\n if (path[i] === \"/\") {\n let k = 0;\n while (i > 0 && path[--i] === \"\\\\\") ++k;\n if ((k & 1) === 0) return true;\n }\n return false;\n}\n","import {Node} from \"./hierarchy/index.js\";\n\nfunction defaultSeparation(a, b) {\n return a.parent === b.parent ? 1 : 2;\n}\n\n// function radialSeparation(a, b) {\n// return (a.parent === b.parent ? 1 : 2) / a.depth;\n// }\n\n// This function is used to traverse the left contour of a subtree (or\n// subforest). It returns the successor of v on this contour. This successor is\n// either given by the leftmost child of v or by the thread of v. The function\n// returns null if and only if v is on the highest level of its subtree.\nfunction nextLeft(v) {\n var children = v.children;\n return children ? children[0] : v.t;\n}\n\n// This function works analogously to nextLeft.\nfunction nextRight(v) {\n var children = v.children;\n return children ? children[children.length - 1] : v.t;\n}\n\n// Shifts the current subtree rooted at w+. This is done by increasing\n// prelim(w+) and mod(w+) by shift.\nfunction moveSubtree(wm, wp, shift) {\n var change = shift / (wp.i - wm.i);\n wp.c -= change;\n wp.s += shift;\n wm.c += change;\n wp.z += shift;\n wp.m += shift;\n}\n\n// All other shifts, applied to the smaller subtrees between w- and w+, are\n// performed by this function. To prepare the shifts, we have to adjust\n// change(w+), shift(w+), and change(w-).\nfunction executeShifts(v) {\n var shift = 0,\n change = 0,\n children = v.children,\n i = children.length,\n w;\n while (--i >= 0) {\n w = children[i];\n w.z += shift;\n w.m += shift;\n shift += w.s + (change += w.c);\n }\n}\n\n// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,\n// returns the specified (default) ancestor.\nfunction nextAncestor(vim, v, ancestor) {\n return vim.a.parent === v.parent ? vim.a : ancestor;\n}\n\nfunction TreeNode(node, i) {\n this._ = node;\n this.parent = null;\n this.children = null;\n this.A = null; // default ancestor\n this.a = this; // ancestor\n this.z = 0; // prelim\n this.m = 0; // mod\n this.c = 0; // change\n this.s = 0; // shift\n this.t = null; // thread\n this.i = i; // number\n}\n\nTreeNode.prototype = Object.create(Node.prototype);\n\nfunction treeRoot(root) {\n var tree = new TreeNode(root, 0),\n node,\n nodes = [tree],\n child,\n children,\n i,\n n;\n\n while (node = nodes.pop()) {\n if (children = node._.children) {\n node.children = new Array(n = children.length);\n for (i = n - 1; i >= 0; --i) {\n nodes.push(child = node.children[i] = new TreeNode(children[i], i));\n child.parent = node;\n }\n }\n }\n\n (tree.parent = new TreeNode(null, 0)).children = [tree];\n return tree;\n}\n\n// Node-link tree diagram using the Reingold-Tilford \"tidy\" algorithm\nexport default function() {\n var separation = defaultSeparation,\n dx = 1,\n dy = 1,\n nodeSize = null;\n\n function tree(root) {\n var t = treeRoot(root);\n\n // Compute the layout using Buchheim et al.’s algorithm.\n t.eachAfter(firstWalk), t.parent.m = -t.z;\n t.eachBefore(secondWalk);\n\n // If a fixed node size is specified, scale x and y.\n if (nodeSize) root.eachBefore(sizeNode);\n\n // If a fixed tree size is specified, scale x and y based on the extent.\n // Compute the left-most, right-most, and depth-most nodes for extents.\n else {\n var left = root,\n right = root,\n bottom = root;\n root.eachBefore(function(node) {\n if (node.x < left.x) left = node;\n if (node.x > right.x) right = node;\n if (node.depth > bottom.depth) bottom = node;\n });\n var s = left === right ? 1 : separation(left, right) / 2,\n tx = s - left.x,\n kx = dx / (right.x + s + tx),\n ky = dy / (bottom.depth || 1);\n root.eachBefore(function(node) {\n node.x = (node.x + tx) * kx;\n node.y = node.depth * ky;\n });\n }\n\n return root;\n }\n\n // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is\n // applied recursively to the children of v, as well as the function\n // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the\n // node v is placed to the midpoint of its outermost children.\n function firstWalk(v) {\n var children = v.children,\n siblings = v.parent.children,\n w = v.i ? siblings[v.i - 1] : null;\n if (children) {\n executeShifts(v);\n var midpoint = (children[0].z + children[children.length - 1].z) / 2;\n if (w) {\n v.z = w.z + separation(v._, w._);\n v.m = v.z - midpoint;\n } else {\n v.z = midpoint;\n }\n } else if (w) {\n v.z = w.z + separation(v._, w._);\n }\n v.parent.A = apportion(v, w, v.parent.A || siblings[0]);\n }\n\n // Computes all real x-coordinates by summing up the modifiers recursively.\n function secondWalk(v) {\n v._.x = v.z + v.parent.m;\n v.m += v.parent.m;\n }\n\n // The core of the algorithm. Here, a new subtree is combined with the\n // previous subtrees. Threads are used to traverse the inside and outside\n // contours of the left and right subtree up to the highest common level. The\n // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the\n // superscript o means outside and i means inside, the subscript - means left\n // subtree and + means right subtree. For summing up the modifiers along the\n // contour, we use respective variables si+, si-, so-, and so+. Whenever two\n // nodes of the inside contours conflict, we compute the left one of the\n // greatest uncommon ancestors using the function ANCESTOR and call MOVE\n // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.\n // Finally, we add a new thread (if necessary).\n function apportion(v, w, ancestor) {\n if (w) {\n var vip = v,\n vop = v,\n vim = w,\n vom = vip.parent.children[0],\n sip = vip.m,\n sop = vop.m,\n sim = vim.m,\n som = vom.m,\n shift;\n while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {\n vom = nextLeft(vom);\n vop = nextRight(vop);\n vop.a = v;\n shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);\n if (shift > 0) {\n moveSubtree(nextAncestor(vim, v, ancestor), v, shift);\n sip += shift;\n sop += shift;\n }\n sim += vim.m;\n sip += vip.m;\n som += vom.m;\n sop += vop.m;\n }\n if (vim && !nextRight(vop)) {\n vop.t = vim;\n vop.m += sim - sop;\n }\n if (vip && !nextLeft(vom)) {\n vom.t = vip;\n vom.m += sip - som;\n ancestor = v;\n }\n }\n return ancestor;\n }\n\n function sizeNode(node) {\n node.x *= dx;\n node.y = node.depth * dy;\n }\n\n tree.separation = function(x) {\n return arguments.length ? (separation = x, tree) : separation;\n };\n\n tree.size = function(x) {\n return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);\n };\n\n tree.nodeSize = function(x) {\n return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);\n };\n\n return tree;\n}\n","// ============================================================================\n// Geometry Utilities\n//\n// Coordinate transforms between screen space and flow space, bounding box\n// calculations for fitView, and DOM measurement helpers.\n// ============================================================================\n\nimport type { XYPosition, Viewport, Rect, Dimensions, FlowNode } from './types';\n\n/**\n * Convert screen (client) coordinates to flow coordinates.\n */\nexport function screenToFlowPosition(\n screenX: number,\n screenY: number,\n viewport: Viewport,\n containerRect: DOMRect,\n): XYPosition {\n return {\n x: (screenX - containerRect.left - viewport.x) / viewport.zoom,\n y: (screenY - containerRect.top - viewport.y) / viewport.zoom,\n };\n}\n\n/**\n * Convert flow coordinates to screen (client) coordinates.\n */\nexport function flowToScreenPosition(\n flowX: number,\n flowY: number,\n viewport: Viewport,\n containerRect: DOMRect,\n): XYPosition {\n return {\n x: flowX * viewport.zoom + viewport.x + containerRect.left,\n y: flowY * viewport.zoom + viewport.y + containerRect.top,\n };\n}\n\n/**\n * Calculate the bounding box that contains all given nodes.\n */\nexport const DEFAULT_NODE_WIDTH = 150;\nexport const DEFAULT_NODE_HEIGHT = 50;\n\n/**\n * Compute the axis-aligned bounding box of a rectangle rotated around its center.\n * Returns the expanded AABB in the same coordinate space as the input.\n */\nexport function getRotatedBounds(\n x: number,\n y: number,\n w: number,\n h: number,\n rotation: number,\n): Rect {\n if (rotation % 360 === 0) return { x, y, width: w, height: h };\n\n const rad = (rotation * Math.PI) / 180;\n const cos = Math.abs(Math.cos(rad));\n const sin = Math.abs(Math.sin(rad));\n const newW = w * cos + h * sin;\n const newH = w * sin + h * cos;\n const cx = x + w / 2;\n const cy = y + h / 2;\n\n return { x: cx - newW / 2, y: cy - newH / 2, width: newW, height: newH };\n}\n\nexport function getNodesBounds(\n nodes: FlowNode[],\n globalOrigin?: [number, number],\n): Rect {\n if (nodes.length === 0) {\n return { x: 0, y: 0, width: 0, height: 0 };\n }\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const node of nodes) {\n const w = node.dimensions?.width ?? DEFAULT_NODE_WIDTH;\n const h = node.dimensions?.height ?? DEFAULT_NODE_HEIGHT;\n\n const vp = getNodeVisualPosition(node, globalOrigin);\n const bounds = node.rotation\n ? getRotatedBounds(vp.x, vp.y, w, h, node.rotation)\n : { x: vp.x, y: vp.y, width: w, height: h };\n\n minX = Math.min(minX, bounds.x);\n minY = Math.min(minY, bounds.y);\n maxX = Math.max(maxX, bounds.x + bounds.width);\n maxY = Math.max(maxY, bounds.y + bounds.height);\n }\n\n return {\n x: minX,\n y: minY,\n width: maxX - minX,\n height: maxY - minY,\n };\n}\n\n/**\n * Return all nodes whose bounding box intersects the given rectangle.\n * Uses AABB intersection with DEFAULT_NODE_WIDTH/HEIGHT fallback.\n */\nexport function getNodesInRect(\n nodes: FlowNode[],\n rect: Rect,\n globalOrigin?: [number, number],\n): FlowNode[] {\n const rectRight = rect.x + rect.width;\n const rectBottom = rect.y + rect.height;\n\n return nodes.filter((node) => {\n const w = node.dimensions?.width ?? DEFAULT_NODE_WIDTH;\n const h = node.dimensions?.height ?? DEFAULT_NODE_HEIGHT;\n\n const vp = getNodeVisualPosition(node, globalOrigin);\n const bounds = node.rotation\n ? getRotatedBounds(vp.x, vp.y, w, h, node.rotation)\n : { x: vp.x, y: vp.y, width: w, height: h };\n\n const nodeRight = bounds.x + bounds.width;\n const nodeBottom = bounds.y + bounds.height;\n\n return !(\n nodeRight < rect.x ||\n bounds.x > rectRight ||\n nodeBottom < rect.y ||\n bounds.y > rectBottom\n );\n });\n}\n\n/**\n * Return all nodes whose bounding box is fully contained within the given rectangle.\n * Uses DEFAULT_NODE_WIDTH/HEIGHT fallback for nodes without measured dimensions.\n */\nexport function getNodesFullyInRect(\n nodes: FlowNode[],\n rect: Rect,\n globalOrigin?: [number, number],\n): FlowNode[] {\n const rectRight = rect.x + rect.width;\n const rectBottom = rect.y + rect.height;\n\n return nodes.filter((node) => {\n const w = node.dimensions?.width ?? DEFAULT_NODE_WIDTH;\n const h = node.dimensions?.height ?? DEFAULT_NODE_HEIGHT;\n\n const vp = getNodeVisualPosition(node, globalOrigin);\n const bounds = node.rotation\n ? getRotatedBounds(vp.x, vp.y, w, h, node.rotation)\n : { x: vp.x, y: vp.y, width: w, height: h };\n\n return (\n bounds.x >= rect.x &&\n bounds.y >= rect.y &&\n bounds.x + bounds.width <= rectRight &&\n bounds.y + bounds.height <= rectBottom\n );\n });\n}\n\n/**\n * Calculate the viewport transform needed to fit a rect into a container.\n */\nexport function getViewportForBounds(\n bounds: Rect,\n containerWidth: number,\n containerHeight: number,\n minZoom: number,\n maxZoom: number,\n padding: number = 0.1,\n): Viewport {\n const effectiveWidth = Math.max(bounds.width, 1);\n const effectiveHeight = Math.max(bounds.height, 1);\n\n const paddedWidth = effectiveWidth * (1 + padding);\n const paddedHeight = effectiveHeight * (1 + padding);\n\n const zoomX = containerWidth / paddedWidth;\n const zoomY = containerHeight / paddedHeight;\n const zoom = Math.min(Math.max(Math.min(zoomX, zoomY), minZoom), maxZoom);\n\n const boundsCenter = { x: bounds.x + effectiveWidth / 2, y: bounds.y + effectiveHeight / 2 };\n const x = containerWidth / 2 - boundsCenter.x * zoom;\n const y = containerHeight / 2 - boundsCenter.y * zoom;\n\n return { x, y, zoom };\n}\n\n// ─── Viewport Culling Utilities ─────────────────────────────────────────────\n\n/** Axis-aligned bounds (min/max form, not x/y/width/height) */\nexport interface Bounds {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n}\n\n/**\n * Compute the visible bounds in flow coordinates given viewport state,\n * container dimensions, and a buffer margin.\n */\nexport function getVisibleBounds(\n viewport: Viewport,\n containerWidth: number,\n containerHeight: number,\n buffer: number,\n): Bounds {\n const invZoom = 1 / viewport.zoom;\n\n return {\n minX: (0 - viewport.x) * invZoom - buffer,\n minY: (0 - viewport.y) * invZoom - buffer,\n maxX: (containerWidth - viewport.x) * invZoom + buffer,\n maxY: (containerHeight - viewport.y) * invZoom + buffer,\n };\n}\n\n/**\n * Grid-based spatial index for fast viewport queries.\n *\n * Flow space is divided into cells of `cellSize` pixels.\n * Each cell holds a Set of node IDs whose bounding boxes overlap that cell.\n * Viewport queries find all cells overlapping the query bounds, then\n * union their node sets — O(cells) instead of O(nodes).\n */\nexport class SpatialGrid {\n private _cellSize: number;\n private _cells = new Map<string, Set<string>>();\n private _nodeCells = new Map<string, string[]>();\n\n constructor(cellSize: number = 300) {\n this._cellSize = cellSize;\n }\n\n private _cellKey(cx: number, cy: number): string {\n return `${cx},${cy}`;\n }\n\n private _getCellRange(\n x: number,\n y: number,\n w: number,\n h: number,\n ): { minCX: number; minCY: number; maxCX: number; maxCY: number } {\n return {\n minCX: Math.floor(x / this._cellSize),\n minCY: Math.floor(y / this._cellSize),\n maxCX: Math.floor((x + w) / this._cellSize),\n maxCY: Math.floor((y + h) / this._cellSize),\n };\n }\n\n insert(id: string, x: number, y: number, w: number, h: number): void {\n this.remove(id);\n const { minCX, minCY, maxCX, maxCY } = this._getCellRange(x, y, w, h);\n const keys: string[] = [];\n for (let cx = minCX; cx <= maxCX; cx++) {\n for (let cy = minCY; cy <= maxCY; cy++) {\n const key = this._cellKey(cx, cy);\n keys.push(key);\n let cell = this._cells.get(key);\n if (!cell) {\n cell = new Set();\n this._cells.set(key, cell);\n }\n cell.add(id);\n }\n }\n this._nodeCells.set(id, keys);\n }\n\n remove(id: string): void {\n const keys = this._nodeCells.get(id);\n if (!keys) {\n return;\n }\n for (const key of keys) {\n const cell = this._cells.get(key);\n if (cell) {\n cell.delete(id);\n if (cell.size === 0) {\n this._cells.delete(key);\n }\n }\n }\n this._nodeCells.delete(id);\n }\n\n update(id: string, x: number, y: number, w: number, h: number): void {\n this.insert(id, x, y, w, h);\n }\n\n query(bounds: Bounds): Set<string> {\n const { minCX, minCY, maxCX, maxCY } = this._getCellRange(\n bounds.minX,\n bounds.minY,\n bounds.maxX - bounds.minX,\n bounds.maxY - bounds.minY,\n );\n const result = new Set<string>();\n for (let cx = minCX; cx <= maxCX; cx++) {\n for (let cy = minCY; cy <= maxCY; cy++) {\n const cell = this._cells.get(this._cellKey(cx, cy));\n if (cell) {\n for (const id of cell) {\n result.add(id);\n }\n }\n }\n }\n return result;\n }\n\n clear(): void {\n this._cells.clear();\n this._nodeCells.clear();\n }\n\n get size(): number {\n return this._nodeCells.size;\n }\n}\n\n// ─── Node Origin Utilities ──────────────────────────────────────────────────\n\n/**\n * Compute the pixel offset from a node's anchor point to its visual top-left corner.\n * Returns {x: 0, y: 0} for the default [0, 0] origin.\n */\nexport function getOriginOffset(\n origin: [number, number] | undefined,\n width: number,\n height: number,\n): XYPosition {\n if (!origin || (origin[0] === 0 && origin[1] === 0)) return { x: 0, y: 0 };\n return { x: -width * origin[0], y: -height * origin[1] };\n}\n\n/**\n * Get the visual top-left position of a node, accounting for nodeOrigin.\n * The node's `position` is its anchor point; this returns where the DOM\n * element's top-left corner should be placed.\n */\nexport function getNodeVisualPosition(\n node: FlowNode,\n globalOrigin?: [number, number],\n): XYPosition {\n if (!node.position) return { x: 0, y: 0 };\n const origin = node.nodeOrigin ?? globalOrigin ?? [0, 0];\n const w = node.dimensions?.width ?? DEFAULT_NODE_WIDTH;\n const h = node.dimensions?.height ?? DEFAULT_NODE_HEIGHT;\n return {\n x: node.position.x - w * origin[0],\n y: node.position.y - h * origin[1],\n };\n}\n","// ============================================================================\n// d3-hierarchy Tree/Cluster Auto-Layout\n//\n// Computes tree or cluster (dendrogram) node positions using d3-hierarchy.\n// Converts flat nodes+edges → tree structure via d3.stratify(), then\n// extracts positions back to a flat map. Returns a position map — does NOT\n// mutate nodes directly.\n// ============================================================================\n\nimport { stratify, tree, cluster } from 'd3-hierarchy';\nimport type { FlowNode, FlowEdge } from '../types';\nimport { DEFAULT_NODE_WIDTH, DEFAULT_NODE_HEIGHT } from '../geometry';\n\nexport type HierarchyLayoutType = 'tree' | 'cluster';\nexport type HierarchyDirection = 'TB' | 'LR';\n\nexport interface HierarchyLayoutOptions {\n layoutType?: HierarchyLayoutType;\n direction?: HierarchyDirection;\n nodeWidth?: number;\n nodeHeight?: number;\n}\n\n/** @internal Sentinel ID for the synthetic root used when there are multiple real roots. */\nconst VIRTUAL_ROOT_ID = '__virtual_root';\n\nexport function computeHierarchyLayout(\n nodes: FlowNode[],\n edges: FlowEdge[],\n options: HierarchyLayoutOptions = {},\n): Map<string, { x: number; y: number }> {\n const {\n layoutType = 'tree',\n direction = 'TB',\n nodeWidth = DEFAULT_NODE_WIDTH,\n nodeHeight = DEFAULT_NODE_HEIGHT,\n } = options;\n\n if (nodes.length === 0) {\n return new Map();\n }\n\n // Build child → parent map from edges (each edge.target has parent edge.source)\n const childToParent = new Map<string, string>();\n for (const edge of edges) {\n childToParent.set(edge.target, edge.source);\n }\n\n // Detect root nodes (nodes with no incoming edge)\n const roots = nodes.filter((n) => !childToParent.has(n.id));\n\n if (roots.length === 0) {\n console.warn(\n '[AlpineFlow] computeHierarchyLayout: no root nodes found (every node has an incoming edge). Returning empty layout.',\n );\n return new Map();\n }\n\n // Build stratify-compatible data: { id, parentId }\n const data: { id: string; parentId: string | null }[] = nodes.map((node) => ({\n id: node.id,\n parentId: childToParent.get(node.id) ?? null,\n }));\n\n // If multiple roots, insert a virtual root that parents all of them\n const hasVirtualRoot = roots.length > 1;\n if (hasVirtualRoot) {\n data.push({ id: VIRTUAL_ROOT_ID, parentId: null });\n for (const entry of data) {\n if (entry.parentId === null && entry.id !== VIRTUAL_ROOT_ID) {\n entry.parentId = VIRTUAL_ROOT_ID;\n }\n }\n }\n\n // Create hierarchy via stratify\n const root = stratify<{ id: string; parentId: string | null }>()\n .id((d) => d.id)\n .parentId((d) => d.parentId)(data);\n\n // Apply tree or cluster layout with nodeSize for spacing\n // nodeSize([sibling separation, level depth]) — in the tree's native TB axes.\n // For LR, x↔y are swapped later, so the depth axis (y) becomes horizontal.\n // Use the wider nodeWidth multiplier for depth so nodes don't overlap edges.\n const layoutFn = layoutType === 'cluster' ? cluster<{ id: string; parentId: string | null }>() : tree<{ id: string; parentId: string | null }>();\n layoutFn.nodeSize(\n direction === 'LR'\n ? [nodeHeight * 2, nodeWidth * 2]\n : [nodeWidth * 1.5, nodeHeight * 2],\n );\n layoutFn(root);\n\n // Extract positions from descendants\n // d3 tree: x = horizontal spread, y = depth\n const nodeMap = new Map(nodes.map((n) => [n.id, n]));\n const positions = new Map<string, { x: number; y: number }>();\n\n // When a virtual root was added, shift all y-values up by one level depth\n // so the real roots sit at y=0 instead of one level below the virtual root.\n const depthOffset = hasVirtualRoot\n ? (direction === 'LR' ? nodeWidth * 2 : nodeHeight * 2)\n : 0;\n\n for (const descendant of root.descendants()) {\n // Skip the virtual root — it should never appear in the output\n if (descendant.id === VIRTUAL_ROOT_ID) {\n continue;\n }\n\n const original = nodeMap.get(descendant.id!);\n const w = original?.dimensions?.width ?? nodeWidth;\n const h = original?.dimensions?.height ?? nodeHeight;\n\n if (direction === 'LR') {\n // Swap x↔y for left-to-right layout, convert center → top-left\n positions.set(descendant.id!, {\n x: descendant.y! - depthOffset - w / 2,\n y: descendant.x! - h / 2,\n });\n } else {\n // TB: keep as-is, convert center → top-left\n positions.set(descendant.id!, {\n x: descendant.x! - w / 2,\n y: descendant.y! - depthOffset - h / 2,\n });\n }\n }\n\n return positions;\n}\n","import type { Alpine } from 'alpinejs';\nimport { registerAddon } from '../core/registry';\nimport { computeHierarchyLayout } from '../core/layout/hierarchy';\n\nexport default function AlpineFlowHierarchy(_Alpine: Alpine): void {\n registerAddon('layout:hierarchy', computeHierarchyLayout);\n}\n"],"names":["REGISTRY_KEY","getRegistry","registerAddon","name","value","defaultSeparation","a","b","meanX","children","meanXReduce","x","c","maxY","maxYReduce","y","leafLeft","node","leafRight","cluster","separation","dx","dy","nodeSize","root","previousNode","left","right","x0","x1","count","sum","i","node_count","node_each","callback","that","index","node_eachBefore","nodes","node_eachAfter","next","n","node_find","node_sum","node_sort","compare","node_path","end","start","ancestor","leastCommonAncestor","k","aNodes","bNodes","node_ancestors","node_descendants","node_leaves","leaves","node_links","links","node_iterator","current","hierarchy","data","mapChildren","objectChildren","Node","child","childs","computeHeight","node_copy","copyData","d","height","optional","f","required","preroot","ambiguous","imputed","defaultId","defaultParentId","stratify","id","parentId","path","currentId","currentParentId","parent","nodeId","nodeKey","nodeByKey","I","normalize","P","parentof","S","_","slash","nextLeft","v","nextRight","moveSubtree","wm","wp","shift","change","executeShifts","w","nextAncestor","vim","TreeNode","treeRoot","tree","t","firstWalk","secondWalk","sizeNode","bottom","s","tx","kx","ky","siblings","midpoint","apportion","vip","vop","vom","sip","sop","sim","som","DEFAULT_NODE_WIDTH","DEFAULT_NODE_HEIGHT","VIRTUAL_ROOT_ID","computeHierarchyLayout","edges","options","layoutType","direction","nodeWidth","nodeHeight","childToParent","edge","roots","hasVirtualRoot","entry","layoutFn","nodeMap","positions","depthOffset","descendant","original","h","AlpineFlowHierarchy","_Alpine"],"mappings":"AAaA,MAAMA,IAAe;AAErB,SAASC,IAAgC;AACvC,SAAI,OAAO,aAAe,OAClB,WAAmBD,CAAY,MAClC,WAAmBA,CAAY,IAAI,oBAAI,IAAA,IAElC,WAAmBA,CAAY,yBAG9B,IAAA;AACb;AAEO,SAASE,EAAcC,GAAcC,GAAkB;AAC5D,EAAAH,IAAc,IAAIE,GAAMC,CAAK;AAC/B;AC5BA,SAASC,EAAkBC,GAAGC,GAAG;AAC/B,SAAOD,EAAE,WAAWC,EAAE,SAAS,IAAI;AACrC;AAEA,SAASC,EAAMC,GAAU;AACvB,SAAOA,EAAS,OAAOC,GAAa,CAAC,IAAID,EAAS;AACpD;AAEA,SAASC,EAAYC,GAAGC,GAAG;AACzB,SAAOD,IAAIC,EAAE;AACf;AAEA,SAASC,EAAKJ,GAAU;AACtB,SAAO,IAAIA,EAAS,OAAOK,GAAY,CAAC;AAC1C;AAEA,SAASA,EAAWC,GAAGH,GAAG;AACxB,SAAO,KAAK,IAAIG,GAAGH,EAAE,CAAC;AACxB;AAEA,SAASI,EAASC,GAAM;AAEtB,WADIR,GACGA,IAAWQ,EAAK,WAAU,CAAAA,IAAOR,EAAS,CAAC;AAClD,SAAOQ;AACT;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,IAAa,CAAC;AAAA,EAAA,GAEtCM,EAAS7H,CAAI;AAIb,QAAM8H,IAAU,IAAI,IAAI/G,EAAM,IAAI,CAACG,MAAM,CAACA,EAAE,IAAIA,CAAC,CAAC,CAAC,GAC7C6G,wBAAgB,IAAA,GAIhBC,IAAcL,IACfN,MAAc,OAAOC,IAAY,IAAIC,IAAa,IACnD;AAEJ,aAAWU,KAAcjI,EAAK,eAAe;AAE3C,QAAIiI,EAAW,OAAOjB;AACpB;AAGF,UAAMkB,IAAWJ,EAAQ,IAAIG,EAAW,EAAG,GACrC5C,IAAI6C,GAAU,YAAY,SAASZ,GACnCa,IAAID,GAAU,YAAY,UAAUX;AAE1C,IAAIF,MAAc,OAEhBU,EAAU,IAAIE,EAAW,IAAK;AAAA,MAC5B,GAAGA,EAAW,IAAKD,IAAc3C,IAAI;AAAA,MACrC,GAAG4C,EAAW,IAAKE,IAAI;AAAA,IAAA,CACxB,IAGDJ,EAAU,IAAIE,EAAW,IAAK;AAAA,MAC5B,GAAGA,EAAW,IAAK5C,IAAI;AAAA,MACvB,GAAG4C,EAAW,IAAKD,IAAcG,IAAI;AAAA,IAAA,CACtC;AAAA,EAEL;AAEA,SAAOJ;AACT;AC7HA,SAAwBK,GAAoBC,GAAuB;AACjE,EAAA3J,EAAc,oBAAoBuI,EAAsB;AAC1D;","x_google_ignoreList":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]}
@@ -0,0 +1,393 @@
1
+ import { r as N } from "./registry-CChkuoVJ.js";
2
+ import { a as O, D as F } from "./geometry-DZSZoYHE.js";
3
+ function b(e, n) {
4
+ return e.parent === n.parent ? 1 : 2;
5
+ }
6
+ function P(e) {
7
+ return e.reduce(W, 0) / e.length;
8
+ }
9
+ function W(e, n) {
10
+ return e + n.x;
11
+ }
12
+ function C(e) {
13
+ return 1 + e.reduce(U, 0);
14
+ }
15
+ function U(e, n) {
16
+ return Math.max(e, n.y);
17
+ }
18
+ function $(e) {
19
+ for (var n; n = e.children; ) e = n[0];
20
+ return e;
21
+ }
22
+ function j(e) {
23
+ for (var n; n = e.children; ) e = n[n.length - 1];
24
+ return e;
25
+ }
26
+ function K() {
27
+ var e = b, n = 1, t = 1, r = !1;
28
+ function u(a) {
29
+ var h, p = 0;
30
+ a.eachAfter(function(c) {
31
+ var o = c.children;
32
+ o ? (c.x = P(o), c.y = C(o)) : (c.x = h ? p += e(c, h) : 0, c.y = 0, h = c);
33
+ });
34
+ var y = $(a), i = j(a), f = y.x - e(y, i) / 2, s = i.x + e(i, y) / 2;
35
+ return a.eachAfter(r ? function(c) {
36
+ c.x = (c.x - a.x) * n, c.y = (a.y - c.y) * t;
37
+ } : function(c) {
38
+ c.x = (c.x - f) / (s - f) * n, c.y = (1 - (a.y ? c.y / a.y : 1)) * t;
39
+ });
40
+ }
41
+ return u.separation = function(a) {
42
+ return arguments.length ? (e = a, u) : e;
43
+ }, u.size = function(a) {
44
+ return arguments.length ? (r = !1, n = +a[0], t = +a[1], u) : r ? null : [n, t];
45
+ }, u.nodeSize = function(a) {
46
+ return arguments.length ? (r = !0, n = +a[0], t = +a[1], u) : r ? [n, t] : null;
47
+ }, u;
48
+ }
49
+ function V(e) {
50
+ var n = 0, t = e.children, r = t && t.length;
51
+ if (!r) n = 1;
52
+ else for (; --r >= 0; ) n += t[r].value;
53
+ e.value = n;
54
+ }
55
+ function X() {
56
+ return this.eachAfter(V);
57
+ }
58
+ function Y(e, n) {
59
+ let t = -1;
60
+ for (const r of this)
61
+ e.call(n, r, ++t, this);
62
+ return this;
63
+ }
64
+ function q(e, n) {
65
+ for (var t = this, r = [t], u, a, h = -1; t = r.pop(); )
66
+ if (e.call(n, t, ++h, this), u = t.children)
67
+ for (a = u.length - 1; a >= 0; --a)
68
+ r.push(u[a]);
69
+ return this;
70
+ }
71
+ function G(e, n) {
72
+ for (var t = this, r = [t], u = [], a, h, p, y = -1; t = r.pop(); )
73
+ if (u.push(t), a = t.children)
74
+ for (h = 0, p = a.length; h < p; ++h)
75
+ r.push(a[h]);
76
+ for (; t = u.pop(); )
77
+ e.call(n, t, ++y, this);
78
+ return this;
79
+ }
80
+ function J(e, n) {
81
+ let t = -1;
82
+ for (const r of this)
83
+ if (e.call(n, r, ++t, this))
84
+ return r;
85
+ }
86
+ function Q(e) {
87
+ return this.eachAfter(function(n) {
88
+ for (var t = +e(n.data) || 0, r = n.children, u = r && r.length; --u >= 0; ) t += r[u].value;
89
+ n.value = t;
90
+ });
91
+ }
92
+ function Z(e) {
93
+ return this.eachBefore(function(n) {
94
+ n.children && n.children.sort(e);
95
+ });
96
+ }
97
+ function v(e) {
98
+ for (var n = this, t = ee(n, e), r = [n]; n !== t; )
99
+ n = n.parent, r.push(n);
100
+ for (var u = r.length; e !== t; )
101
+ r.splice(u, 0, e), e = e.parent;
102
+ return r;
103
+ }
104
+ function ee(e, n) {
105
+ if (e === n) return e;
106
+ var t = e.ancestors(), r = n.ancestors(), u = null;
107
+ for (e = t.pop(), n = r.pop(); e === n; )
108
+ u = e, e = t.pop(), n = r.pop();
109
+ return u;
110
+ }
111
+ function ne() {
112
+ for (var e = this, n = [e]; e = e.parent; )
113
+ n.push(e);
114
+ return n;
115
+ }
116
+ function te() {
117
+ return Array.from(this);
118
+ }
119
+ function re() {
120
+ var e = [];
121
+ return this.eachBefore(function(n) {
122
+ n.children || e.push(n);
123
+ }), e;
124
+ }
125
+ function ie() {
126
+ var e = this, n = [];
127
+ return e.each(function(t) {
128
+ t !== e && n.push({ source: t.parent, target: t });
129
+ }), n;
130
+ }
131
+ function* ue() {
132
+ var e = this, n, t = [e], r, u, a;
133
+ do
134
+ for (n = t.reverse(), t = []; e = n.pop(); )
135
+ if (yield e, r = e.children)
136
+ for (u = 0, a = r.length; u < a; ++u)
137
+ t.push(r[u]);
138
+ while (t.length);
139
+ }
140
+ function D(e, n) {
141
+ e instanceof Map ? (e = [void 0, e], n === void 0 && (n = le)) : n === void 0 && (n = ce);
142
+ for (var t = new A(e), r, u = [t], a, h, p, y; r = u.pop(); )
143
+ if ((h = n(r.data)) && (y = (h = Array.from(h)).length))
144
+ for (r.children = h, p = y - 1; p >= 0; --p)
145
+ u.push(a = h[p] = new A(h[p])), a.parent = r, a.depth = r.depth + 1;
146
+ return t.eachBefore(H);
147
+ }
148
+ function ae() {
149
+ return D(this).eachBefore(oe);
150
+ }
151
+ function ce(e) {
152
+ return e.children;
153
+ }
154
+ function le(e) {
155
+ return Array.isArray(e) ? e[1] : null;
156
+ }
157
+ function oe(e) {
158
+ e.data.value !== void 0 && (e.value = e.data.value), e.data = e.data.data;
159
+ }
160
+ function H(e) {
161
+ var n = 0;
162
+ do
163
+ e.height = n;
164
+ while ((e = e.parent) && e.height < ++n);
165
+ }
166
+ function A(e) {
167
+ this.data = e, this.depth = this.height = 0, this.parent = null;
168
+ }
169
+ A.prototype = D.prototype = {
170
+ constructor: A,
171
+ count: X,
172
+ each: Y,
173
+ eachAfter: G,
174
+ eachBefore: q,
175
+ find: J,
176
+ sum: Q,
177
+ sort: Z,
178
+ path: v,
179
+ ancestors: ne,
180
+ descendants: te,
181
+ leaves: re,
182
+ links: ie,
183
+ copy: ae,
184
+ [Symbol.iterator]: ue
185
+ };
186
+ function E(e) {
187
+ return e == null ? null : he(e);
188
+ }
189
+ function he(e) {
190
+ if (typeof e != "function") throw new Error();
191
+ return e;
192
+ }
193
+ var fe = { depth: -1 }, k = {}, R = {};
194
+ function se(e) {
195
+ return e.id;
196
+ }
197
+ function de(e) {
198
+ return e.parentId;
199
+ }
200
+ function pe() {
201
+ var e = se, n = de, t;
202
+ function r(u) {
203
+ var a = Array.from(u), h = e, p = n, y, i, f, s, c, o, d, m, l = /* @__PURE__ */ new Map();
204
+ if (t != null) {
205
+ const w = a.map((x, z) => ge(t(x, z, u))), g = w.map(M), _ = new Set(w).add("");
206
+ for (const x of g)
207
+ _.has(x) || (_.add(x), w.push(x), g.push(M(x)), a.push(R));
208
+ h = (x, z) => w[z], p = (x, z) => g[z];
209
+ }
210
+ for (f = 0, y = a.length; f < y; ++f)
211
+ i = a[f], o = a[f] = new A(i), (d = h(i, f, u)) != null && (d += "") && (m = o.id = d, l.set(m, l.has(m) ? k : o)), (d = p(i, f, u)) != null && (d += "") && (o.parent = d);
212
+ for (f = 0; f < y; ++f)
213
+ if (o = a[f], d = o.parent) {
214
+ if (c = l.get(d), !c) throw new Error("missing: " + d);
215
+ if (c === k) throw new Error("ambiguous: " + d);
216
+ c.children ? c.children.push(o) : c.children = [o], o.parent = c;
217
+ } else {
218
+ if (s) throw new Error("multiple roots");
219
+ s = o;
220
+ }
221
+ if (!s) throw new Error("no root");
222
+ if (t != null) {
223
+ for (; s.data === R && s.children.length === 1; )
224
+ s = s.children[0], --y;
225
+ for (let w = a.length - 1; w >= 0 && (o = a[w], o.data === R); --w)
226
+ o.data = null;
227
+ }
228
+ if (s.parent = fe, s.eachBefore(function(w) {
229
+ w.depth = w.parent.depth + 1, --y;
230
+ }).eachBefore(H), s.parent = null, y > 0) throw new Error("cycle");
231
+ return s;
232
+ }
233
+ return r.id = function(u) {
234
+ return arguments.length ? (e = E(u), r) : e;
235
+ }, r.parentId = function(u) {
236
+ return arguments.length ? (n = E(u), r) : n;
237
+ }, r.path = function(u) {
238
+ return arguments.length ? (t = E(u), r) : t;
239
+ }, r;
240
+ }
241
+ function ge(e) {
242
+ e = `${e}`;
243
+ let n = e.length;
244
+ return T(e, n - 1) && !T(e, n - 2) && (e = e.slice(0, -1)), e[0] === "/" ? e : `/${e}`;
245
+ }
246
+ function M(e) {
247
+ let n = e.length;
248
+ if (n < 2) return "";
249
+ for (; --n > 1 && !T(e, n); ) ;
250
+ return e.slice(0, n);
251
+ }
252
+ function T(e, n) {
253
+ if (e[n] === "/") {
254
+ let t = 0;
255
+ for (; n > 0 && e[--n] === "\\"; ) ++t;
256
+ if ((t & 1) === 0) return !0;
257
+ }
258
+ return !1;
259
+ }
260
+ function ye(e, n) {
261
+ return e.parent === n.parent ? 1 : 2;
262
+ }
263
+ function S(e) {
264
+ var n = e.children;
265
+ return n ? n[0] : e.t;
266
+ }
267
+ function L(e) {
268
+ var n = e.children;
269
+ return n ? n[n.length - 1] : e.t;
270
+ }
271
+ function we(e, n, t) {
272
+ var r = t / (n.i - e.i);
273
+ n.c -= r, n.s += t, e.c += r, n.z += t, n.m += t;
274
+ }
275
+ function me(e) {
276
+ for (var n = 0, t = 0, r = e.children, u = r.length, a; --u >= 0; )
277
+ a = r[u], a.z += n, a.m += n, n += a.s + (t += a.c);
278
+ }
279
+ function xe(e, n, t) {
280
+ return e.a.parent === n.parent ? e.a : t;
281
+ }
282
+ function B(e, n) {
283
+ this._ = e, this.parent = null, this.children = null, this.A = null, this.a = this, this.z = 0, this.m = 0, this.c = 0, this.s = 0, this.t = null, this.i = n;
284
+ }
285
+ B.prototype = Object.create(A.prototype);
286
+ function _e(e) {
287
+ for (var n = new B(e, 0), t, r = [n], u, a, h, p; t = r.pop(); )
288
+ if (a = t._.children)
289
+ for (t.children = new Array(p = a.length), h = p - 1; h >= 0; --h)
290
+ r.push(u = t.children[h] = new B(a[h], h)), u.parent = t;
291
+ return (n.parent = new B(null, 0)).children = [n], n;
292
+ }
293
+ function Ae() {
294
+ var e = ye, n = 1, t = 1, r = null;
295
+ function u(i) {
296
+ var f = _e(i);
297
+ if (f.eachAfter(a), f.parent.m = -f.z, f.eachBefore(h), r) i.eachBefore(y);
298
+ else {
299
+ var s = i, c = i, o = i;
300
+ i.eachBefore(function(g) {
301
+ g.x < s.x && (s = g), g.x > c.x && (c = g), g.depth > o.depth && (o = g);
302
+ });
303
+ var d = s === c ? 1 : e(s, c) / 2, m = d - s.x, l = n / (c.x + d + m), w = t / (o.depth || 1);
304
+ i.eachBefore(function(g) {
305
+ g.x = (g.x + m) * l, g.y = g.depth * w;
306
+ });
307
+ }
308
+ return i;
309
+ }
310
+ function a(i) {
311
+ var f = i.children, s = i.parent.children, c = i.i ? s[i.i - 1] : null;
312
+ if (f) {
313
+ me(i);
314
+ var o = (f[0].z + f[f.length - 1].z) / 2;
315
+ c ? (i.z = c.z + e(i._, c._), i.m = i.z - o) : i.z = o;
316
+ } else c && (i.z = c.z + e(i._, c._));
317
+ i.parent.A = p(i, c, i.parent.A || s[0]);
318
+ }
319
+ function h(i) {
320
+ i._.x = i.z + i.parent.m, i.m += i.parent.m;
321
+ }
322
+ function p(i, f, s) {
323
+ if (f) {
324
+ for (var c = i, o = i, d = f, m = c.parent.children[0], l = c.m, w = o.m, g = d.m, _ = m.m, x; d = L(d), c = S(c), d && c; )
325
+ m = S(m), o = L(o), o.a = i, x = d.z + g - c.z - l + e(d._, c._), x > 0 && (we(xe(d, i, s), i, x), l += x, w += x), g += d.m, l += c.m, _ += m.m, w += o.m;
326
+ d && !L(o) && (o.t = d, o.m += g - w), c && !S(m) && (m.t = c, m.m += l - _, s = i);
327
+ }
328
+ return s;
329
+ }
330
+ function y(i) {
331
+ i.x *= n, i.y = i.depth * t;
332
+ }
333
+ return u.separation = function(i) {
334
+ return arguments.length ? (e = i, u) : e;
335
+ }, u.size = function(i) {
336
+ return arguments.length ? (r = !1, n = +i[0], t = +i[1], u) : r ? null : [n, t];
337
+ }, u.nodeSize = function(i) {
338
+ return arguments.length ? (r = !0, n = +i[0], t = +i[1], u) : r ? [n, t] : null;
339
+ }, u;
340
+ }
341
+ const I = "__virtual_root";
342
+ function ze(e, n, t = {}) {
343
+ const {
344
+ layoutType: r = "tree",
345
+ direction: u = "TB",
346
+ nodeWidth: a = F,
347
+ nodeHeight: h = O
348
+ } = t;
349
+ if (e.length === 0)
350
+ return /* @__PURE__ */ new Map();
351
+ const p = /* @__PURE__ */ new Map();
352
+ for (const l of n)
353
+ p.set(l.target, l.source);
354
+ const y = e.filter((l) => !p.has(l.id));
355
+ if (y.length === 0)
356
+ return console.warn(
357
+ "[AlpineFlow] computeHierarchyLayout: no root nodes found (every node has an incoming edge). Returning empty layout."
358
+ ), /* @__PURE__ */ new Map();
359
+ const i = e.map((l) => ({
360
+ id: l.id,
361
+ parentId: p.get(l.id) ?? null
362
+ })), f = y.length > 1;
363
+ if (f) {
364
+ i.push({ id: I, parentId: null });
365
+ for (const l of i)
366
+ l.parentId === null && l.id !== I && (l.parentId = I);
367
+ }
368
+ const s = pe().id((l) => l.id).parentId((l) => l.parentId)(i), c = r === "cluster" ? K() : Ae();
369
+ c.nodeSize(
370
+ u === "LR" ? [h * 2, a * 2] : [a * 1.5, h * 2]
371
+ ), c(s);
372
+ const o = new Map(e.map((l) => [l.id, l])), d = /* @__PURE__ */ new Map(), m = f ? u === "LR" ? a * 2 : h * 2 : 0;
373
+ for (const l of s.descendants()) {
374
+ if (l.id === I)
375
+ continue;
376
+ const w = o.get(l.id), g = w?.dimensions?.width ?? a, _ = w?.dimensions?.height ?? h;
377
+ u === "LR" ? d.set(l.id, {
378
+ x: l.y - m - g / 2,
379
+ y: l.x - _ / 2
380
+ }) : d.set(l.id, {
381
+ x: l.x - g / 2,
382
+ y: l.y - m - _ / 2
383
+ });
384
+ }
385
+ return d;
386
+ }
387
+ function Ie(e) {
388
+ N("layout:hierarchy", ze);
389
+ }
390
+ document.addEventListener("alpine:init", () => {
391
+ window.Alpine.plugin(Ie);
392
+ });
393
+ //# sourceMappingURL=alpineflow-hierarchy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alpineflow-hierarchy.js","sources":["../node_modules/d3-hierarchy/src/cluster.js","../node_modules/d3-hierarchy/src/hierarchy/count.js","../node_modules/d3-hierarchy/src/hierarchy/each.js","../node_modules/d3-hierarchy/src/hierarchy/eachBefore.js","../node_modules/d3-hierarchy/src/hierarchy/eachAfter.js","../node_modules/d3-hierarchy/src/hierarchy/find.js","../node_modules/d3-hierarchy/src/hierarchy/sum.js","../node_modules/d3-hierarchy/src/hierarchy/sort.js","../node_modules/d3-hierarchy/src/hierarchy/path.js","../node_modules/d3-hierarchy/src/hierarchy/ancestors.js","../node_modules/d3-hierarchy/src/hierarchy/descendants.js","../node_modules/d3-hierarchy/src/hierarchy/leaves.js","../node_modules/d3-hierarchy/src/hierarchy/links.js","../node_modules/d3-hierarchy/src/hierarchy/iterator.js","../node_modules/d3-hierarchy/src/hierarchy/index.js","../node_modules/d3-hierarchy/src/accessors.js","../node_modules/d3-hierarchy/src/stratify.js","../node_modules/d3-hierarchy/src/tree.js","../src/core/layout/hierarchy.ts","../src/layout/hierarchy.ts","../lib/hierarchy.cdn.ts"],"sourcesContent":["function defaultSeparation(a, b) {\n return a.parent === b.parent ? 1 : 2;\n}\n\nfunction meanX(children) {\n return children.reduce(meanXReduce, 0) / children.length;\n}\n\nfunction meanXReduce(x, c) {\n return x + c.x;\n}\n\nfunction maxY(children) {\n return 1 + children.reduce(maxYReduce, 0);\n}\n\nfunction maxYReduce(y, c) {\n return Math.max(y, c.y);\n}\n\nfunction leafLeft(node) {\n var children;\n while (children = node.children) node = children[0];\n return node;\n}\n\nfunction leafRight(node) {\n var children;\n while (children = node.children) node = children[children.length - 1];\n return node;\n}\n\nexport default function() {\n var separation = defaultSeparation,\n dx = 1,\n dy = 1,\n nodeSize = false;\n\n function cluster(root) {\n var previousNode,\n x = 0;\n\n // First walk, computing the initial x & y values.\n root.eachAfter(function(node) {\n var children = node.children;\n if (children) {\n node.x = meanX(children);\n node.y = maxY(children);\n } else {\n node.x = previousNode ? x += separation(node, previousNode) : 0;\n node.y = 0;\n previousNode = node;\n }\n });\n\n var left = leafLeft(root),\n right = leafRight(root),\n x0 = left.x - separation(left, right) / 2,\n x1 = right.x + separation(right, left) / 2;\n\n // Second walk, normalizing x & y to the desired size.\n return root.eachAfter(nodeSize ? function(node) {\n node.x = (node.x - root.x) * dx;\n node.y = (root.y - node.y) * dy;\n } : function(node) {\n node.x = (node.x - x0) / (x1 - x0) * dx;\n node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;\n });\n }\n\n cluster.separation = function(x) {\n return arguments.length ? (separation = x, cluster) : separation;\n };\n\n cluster.size = function(x) {\n return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);\n };\n\n cluster.nodeSize = function(x) {\n return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);\n };\n\n return cluster;\n}\n","function count(node) {\n var sum = 0,\n children = node.children,\n i = children && children.length;\n if (!i) sum = 1;\n else while (--i >= 0) sum += children[i].value;\n node.value = sum;\n}\n\nexport default function() {\n return this.eachAfter(count);\n}\n","export default function(callback, that) {\n let index = -1;\n for (const node of this) {\n callback.call(that, node, ++index, this);\n }\n return this;\n}\n","export default function(callback, that) {\n var node = this, nodes = [node], children, i, index = -1;\n while (node = nodes.pop()) {\n callback.call(that, node, ++index, this);\n if (children = node.children) {\n for (i = children.length - 1; i >= 0; --i) {\n nodes.push(children[i]);\n }\n }\n }\n return this;\n}\n","export default function(callback, that) {\n var node = this, nodes = [node], next = [], children, i, n, index = -1;\n while (node = nodes.pop()) {\n next.push(node);\n if (children = node.children) {\n for (i = 0, n = children.length; i < n; ++i) {\n nodes.push(children[i]);\n }\n }\n }\n while (node = next.pop()) {\n callback.call(that, node, ++index, this);\n }\n return this;\n}\n","export default function(callback, that) {\n let index = -1;\n for (const node of this) {\n if (callback.call(that, node, ++index, this)) {\n return node;\n }\n }\n}\n","export default function(value) {\n return this.eachAfter(function(node) {\n var sum = +value(node.data) || 0,\n children = node.children,\n i = children && children.length;\n while (--i >= 0) sum += children[i].value;\n node.value = sum;\n });\n}\n","export default function(compare) {\n return this.eachBefore(function(node) {\n if (node.children) {\n node.children.sort(compare);\n }\n });\n}\n","export default function(end) {\n var start = this,\n ancestor = leastCommonAncestor(start, end),\n nodes = [start];\n while (start !== ancestor) {\n start = start.parent;\n nodes.push(start);\n }\n var k = nodes.length;\n while (end !== ancestor) {\n nodes.splice(k, 0, end);\n end = end.parent;\n }\n return nodes;\n}\n\nfunction leastCommonAncestor(a, b) {\n if (a === b) return a;\n var aNodes = a.ancestors(),\n bNodes = b.ancestors(),\n c = null;\n a = aNodes.pop();\n b = bNodes.pop();\n while (a === b) {\n c = a;\n a = aNodes.pop();\n b = bNodes.pop();\n }\n return c;\n}\n","export default function() {\n var node = this, nodes = [node];\n while (node = node.parent) {\n nodes.push(node);\n }\n return nodes;\n}\n","export default function() {\n return Array.from(this);\n}\n","export default function() {\n var leaves = [];\n this.eachBefore(function(node) {\n if (!node.children) {\n leaves.push(node);\n }\n });\n return leaves;\n}\n","export default function() {\n var root = this, links = [];\n root.each(function(node) {\n if (node !== root) { // Don’t include the root’s parent, if any.\n links.push({source: node.parent, target: node});\n }\n });\n return links;\n}\n","export default function*() {\n var node = this, current, next = [node], children, i, n;\n do {\n current = next.reverse(), next = [];\n while (node = current.pop()) {\n yield node;\n if (children = node.children) {\n for (i = 0, n = children.length; i < n; ++i) {\n next.push(children[i]);\n }\n }\n }\n } while (next.length);\n}\n","import node_count from \"./count.js\";\nimport node_each from \"./each.js\";\nimport node_eachBefore from \"./eachBefore.js\";\nimport node_eachAfter from \"./eachAfter.js\";\nimport node_find from \"./find.js\";\nimport node_sum from \"./sum.js\";\nimport node_sort from \"./sort.js\";\nimport node_path from \"./path.js\";\nimport node_ancestors from \"./ancestors.js\";\nimport node_descendants from \"./descendants.js\";\nimport node_leaves from \"./leaves.js\";\nimport node_links from \"./links.js\";\nimport node_iterator from \"./iterator.js\";\n\nexport default function hierarchy(data, children) {\n if (data instanceof Map) {\n data = [undefined, data];\n if (children === undefined) children = mapChildren;\n } else if (children === undefined) {\n children = objectChildren;\n }\n\n var root = new Node(data),\n node,\n nodes = [root],\n child,\n childs,\n i,\n n;\n\n while (node = nodes.pop()) {\n if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {\n node.children = childs;\n for (i = n - 1; i >= 0; --i) {\n nodes.push(child = childs[i] = new Node(childs[i]));\n child.parent = node;\n child.depth = node.depth + 1;\n }\n }\n }\n\n return root.eachBefore(computeHeight);\n}\n\nfunction node_copy() {\n return hierarchy(this).eachBefore(copyData);\n}\n\nfunction objectChildren(d) {\n return d.children;\n}\n\nfunction mapChildren(d) {\n return Array.isArray(d) ? d[1] : null;\n}\n\nfunction copyData(node) {\n if (node.data.value !== undefined) node.value = node.data.value;\n node.data = node.data.data;\n}\n\nexport function computeHeight(node) {\n var height = 0;\n do node.height = height;\n while ((node = node.parent) && (node.height < ++height));\n}\n\nexport function Node(data) {\n this.data = data;\n this.depth =\n this.height = 0;\n this.parent = null;\n}\n\nNode.prototype = hierarchy.prototype = {\n constructor: Node,\n count: node_count,\n each: node_each,\n eachAfter: node_eachAfter,\n eachBefore: node_eachBefore,\n find: node_find,\n sum: node_sum,\n sort: node_sort,\n path: node_path,\n ancestors: node_ancestors,\n descendants: node_descendants,\n leaves: node_leaves,\n links: node_links,\n copy: node_copy,\n [Symbol.iterator]: node_iterator\n};\n","export function optional(f) {\n return f == null ? null : required(f);\n}\n\nexport function required(f) {\n if (typeof f !== \"function\") throw new Error;\n return f;\n}\n","import {optional} from \"./accessors.js\";\nimport {Node, computeHeight} from \"./hierarchy/index.js\";\n\nvar preroot = {depth: -1},\n ambiguous = {},\n imputed = {};\n\nfunction defaultId(d) {\n return d.id;\n}\n\nfunction defaultParentId(d) {\n return d.parentId;\n}\n\nexport default function() {\n var id = defaultId,\n parentId = defaultParentId,\n path;\n\n function stratify(data) {\n var nodes = Array.from(data),\n currentId = id,\n currentParentId = parentId,\n n,\n d,\n i,\n root,\n parent,\n node,\n nodeId,\n nodeKey,\n nodeByKey = new Map;\n\n if (path != null) {\n const I = nodes.map((d, i) => normalize(path(d, i, data)));\n const P = I.map(parentof);\n const S = new Set(I).add(\"\");\n for (const i of P) {\n if (!S.has(i)) {\n S.add(i);\n I.push(i);\n P.push(parentof(i));\n nodes.push(imputed);\n }\n }\n currentId = (_, i) => I[i];\n currentParentId = (_, i) => P[i];\n }\n\n for (i = 0, n = nodes.length; i < n; ++i) {\n d = nodes[i], node = nodes[i] = new Node(d);\n if ((nodeId = currentId(d, i, data)) != null && (nodeId += \"\")) {\n nodeKey = node.id = nodeId;\n nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);\n }\n if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += \"\")) {\n node.parent = nodeId;\n }\n }\n\n for (i = 0; i < n; ++i) {\n node = nodes[i];\n if (nodeId = node.parent) {\n parent = nodeByKey.get(nodeId);\n if (!parent) throw new Error(\"missing: \" + nodeId);\n if (parent === ambiguous) throw new Error(\"ambiguous: \" + nodeId);\n if (parent.children) parent.children.push(node);\n else parent.children = [node];\n node.parent = parent;\n } else {\n if (root) throw new Error(\"multiple roots\");\n root = node;\n }\n }\n\n if (!root) throw new Error(\"no root\");\n\n // When imputing internal nodes, only introduce roots if needed.\n // Then replace the imputed marker data with null.\n if (path != null) {\n while (root.data === imputed && root.children.length === 1) {\n root = root.children[0], --n;\n }\n for (let i = nodes.length - 1; i >= 0; --i) {\n node = nodes[i];\n if (node.data !== imputed) break;\n node.data = null;\n }\n }\n\n root.parent = preroot;\n root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);\n root.parent = null;\n if (n > 0) throw new Error(\"cycle\");\n\n return root;\n }\n\n stratify.id = function(x) {\n return arguments.length ? (id = optional(x), stratify) : id;\n };\n\n stratify.parentId = function(x) {\n return arguments.length ? (parentId = optional(x), stratify) : parentId;\n };\n\n stratify.path = function(x) {\n return arguments.length ? (path = optional(x), stratify) : path;\n };\n\n return stratify;\n}\n\n// To normalize a path, we coerce to a string, strip the trailing slash if any\n// (as long as the trailing slash is not immediately preceded by another slash),\n// and add leading slash if missing.\nfunction normalize(path) {\n path = `${path}`;\n let i = path.length;\n if (slash(path, i - 1) && !slash(path, i - 2)) path = path.slice(0, -1);\n return path[0] === \"/\" ? path : `/${path}`;\n}\n\n// Walk backwards to find the first slash that is not the leading slash, e.g.:\n// \"/foo/bar\" ⇥ \"/foo\", \"/foo\" ⇥ \"/\", \"/\" ↦ \"\". (The root is special-cased\n// because the id of the root must be a truthy value.)\nfunction parentof(path) {\n let i = path.length;\n if (i < 2) return \"\";\n while (--i > 1) if (slash(path, i)) break;\n return path.slice(0, i);\n}\n\n// Slashes can be escaped; to determine whether a slash is a path delimiter, we\n// count the number of preceding backslashes escaping the forward slash: an odd\n// number indicates an escaped forward slash.\nfunction slash(path, i) {\n if (path[i] === \"/\") {\n let k = 0;\n while (i > 0 && path[--i] === \"\\\\\") ++k;\n if ((k & 1) === 0) return true;\n }\n return false;\n}\n","import {Node} from \"./hierarchy/index.js\";\n\nfunction defaultSeparation(a, b) {\n return a.parent === b.parent ? 1 : 2;\n}\n\n// function radialSeparation(a, b) {\n// return (a.parent === b.parent ? 1 : 2) / a.depth;\n// }\n\n// This function is used to traverse the left contour of a subtree (or\n// subforest). It returns the successor of v on this contour. This successor is\n// either given by the leftmost child of v or by the thread of v. The function\n// returns null if and only if v is on the highest level of its subtree.\nfunction nextLeft(v) {\n var children = v.children;\n return children ? children[0] : v.t;\n}\n\n// This function works analogously to nextLeft.\nfunction nextRight(v) {\n var children = v.children;\n return children ? children[children.length - 1] : v.t;\n}\n\n// Shifts the current subtree rooted at w+. This is done by increasing\n// prelim(w+) and mod(w+) by shift.\nfunction moveSubtree(wm, wp, shift) {\n var change = shift / (wp.i - wm.i);\n wp.c -= change;\n wp.s += shift;\n wm.c += change;\n wp.z += shift;\n wp.m += shift;\n}\n\n// All other shifts, applied to the smaller subtrees between w- and w+, are\n// performed by this function. To prepare the shifts, we have to adjust\n// change(w+), shift(w+), and change(w-).\nfunction executeShifts(v) {\n var shift = 0,\n change = 0,\n children = v.children,\n i = children.length,\n w;\n while (--i >= 0) {\n w = children[i];\n w.z += shift;\n w.m += shift;\n shift += w.s + (change += w.c);\n }\n}\n\n// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,\n// returns the specified (default) ancestor.\nfunction nextAncestor(vim, v, ancestor) {\n return vim.a.parent === v.parent ? vim.a : ancestor;\n}\n\nfunction TreeNode(node, i) {\n this._ = node;\n this.parent = null;\n this.children = null;\n this.A = null; // default ancestor\n this.a = this; // ancestor\n this.z = 0; // prelim\n this.m = 0; // mod\n this.c = 0; // change\n this.s = 0; // shift\n this.t = null; // thread\n this.i = i; // number\n}\n\nTreeNode.prototype = Object.create(Node.prototype);\n\nfunction treeRoot(root) {\n var tree = new TreeNode(root, 0),\n node,\n nodes = [tree],\n child,\n children,\n i,\n n;\n\n while (node = nodes.pop()) {\n if (children = node._.children) {\n node.children = new Array(n = children.length);\n for (i = n - 1; i >= 0; --i) {\n nodes.push(child = node.children[i] = new TreeNode(children[i], i));\n child.parent = node;\n }\n }\n }\n\n (tree.parent = new TreeNode(null, 0)).children = [tree];\n return tree;\n}\n\n// Node-link tree diagram using the Reingold-Tilford \"tidy\" algorithm\nexport default function() {\n var separation = defaultSeparation,\n dx = 1,\n dy = 1,\n nodeSize = null;\n\n function tree(root) {\n var t = treeRoot(root);\n\n // Compute the layout using Buchheim et al.’s algorithm.\n t.eachAfter(firstWalk), t.parent.m = -t.z;\n t.eachBefore(secondWalk);\n\n // If a fixed node size is specified, scale x and y.\n if (nodeSize) root.eachBefore(sizeNode);\n\n // If a fixed tree size is specified, scale x and y based on the extent.\n // Compute the left-most, right-most, and depth-most nodes for extents.\n else {\n var left = root,\n right = root,\n bottom = root;\n root.eachBefore(function(node) {\n if (node.x < left.x) left = node;\n if (node.x > right.x) right = node;\n if (node.depth > bottom.depth) bottom = node;\n });\n var s = left === right ? 1 : separation(left, right) / 2,\n tx = s - left.x,\n kx = dx / (right.x + s + tx),\n ky = dy / (bottom.depth || 1);\n root.eachBefore(function(node) {\n node.x = (node.x + tx) * kx;\n node.y = node.depth * ky;\n });\n }\n\n return root;\n }\n\n // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is\n // applied recursively to the children of v, as well as the function\n // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the\n // node v is placed to the midpoint of its outermost children.\n function firstWalk(v) {\n var children = v.children,\n siblings = v.parent.children,\n w = v.i ? siblings[v.i - 1] : null;\n if (children) {\n executeShifts(v);\n var midpoint = (children[0].z + children[children.length - 1].z) / 2;\n if (w) {\n v.z = w.z + separation(v._, w._);\n v.m = v.z - midpoint;\n } else {\n v.z = midpoint;\n }\n } else if (w) {\n v.z = w.z + separation(v._, w._);\n }\n v.parent.A = apportion(v, w, v.parent.A || siblings[0]);\n }\n\n // Computes all real x-coordinates by summing up the modifiers recursively.\n function secondWalk(v) {\n v._.x = v.z + v.parent.m;\n v.m += v.parent.m;\n }\n\n // The core of the algorithm. Here, a new subtree is combined with the\n // previous subtrees. Threads are used to traverse the inside and outside\n // contours of the left and right subtree up to the highest common level. The\n // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the\n // superscript o means outside and i means inside, the subscript - means left\n // subtree and + means right subtree. For summing up the modifiers along the\n // contour, we use respective variables si+, si-, so-, and so+. Whenever two\n // nodes of the inside contours conflict, we compute the left one of the\n // greatest uncommon ancestors using the function ANCESTOR and call MOVE\n // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.\n // Finally, we add a new thread (if necessary).\n function apportion(v, w, ancestor) {\n if (w) {\n var vip = v,\n vop = v,\n vim = w,\n vom = vip.parent.children[0],\n sip = vip.m,\n sop = vop.m,\n sim = vim.m,\n som = vom.m,\n shift;\n while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {\n vom = nextLeft(vom);\n vop = nextRight(vop);\n vop.a = v;\n shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);\n if (shift > 0) {\n moveSubtree(nextAncestor(vim, v, ancestor), v, shift);\n sip += shift;\n sop += shift;\n }\n sim += vim.m;\n sip += vip.m;\n som += vom.m;\n sop += vop.m;\n }\n if (vim && !nextRight(vop)) {\n vop.t = vim;\n vop.m += sim - sop;\n }\n if (vip && !nextLeft(vom)) {\n vom.t = vip;\n vom.m += sip - som;\n ancestor = v;\n }\n }\n return ancestor;\n }\n\n function sizeNode(node) {\n node.x *= dx;\n node.y = node.depth * dy;\n }\n\n tree.separation = function(x) {\n return arguments.length ? (separation = x, tree) : separation;\n };\n\n tree.size = function(x) {\n return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);\n };\n\n tree.nodeSize = function(x) {\n return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);\n };\n\n return tree;\n}\n","// ============================================================================\n// d3-hierarchy Tree/Cluster Auto-Layout\n//\n// Computes tree or cluster (dendrogram) node positions using d3-hierarchy.\n// Converts flat nodes+edges → tree structure via d3.stratify(), then\n// extracts positions back to a flat map. Returns a position map — does NOT\n// mutate nodes directly.\n// ============================================================================\n\nimport { stratify, tree, cluster } from 'd3-hierarchy';\nimport type { FlowNode, FlowEdge } from '../types';\nimport { DEFAULT_NODE_WIDTH, DEFAULT_NODE_HEIGHT } from '../geometry';\n\nexport type HierarchyLayoutType = 'tree' | 'cluster';\nexport type HierarchyDirection = 'TB' | 'LR';\n\nexport interface HierarchyLayoutOptions {\n layoutType?: HierarchyLayoutType;\n direction?: HierarchyDirection;\n nodeWidth?: number;\n nodeHeight?: number;\n}\n\n/** @internal Sentinel ID for the synthetic root used when there are multiple real roots. */\nconst VIRTUAL_ROOT_ID = '__virtual_root';\n\nexport function computeHierarchyLayout(\n nodes: FlowNode[],\n edges: FlowEdge[],\n options: HierarchyLayoutOptions = {},\n): Map<string, { x: number; y: number }> {\n const {\n layoutType = 'tree',\n direction = 'TB',\n nodeWidth = DEFAULT_NODE_WIDTH,\n nodeHeight = DEFAULT_NODE_HEIGHT,\n } = options;\n\n if (nodes.length === 0) {\n return new Map();\n }\n\n // Build child → parent map from edges (each edge.target has parent edge.source)\n const childToParent = new Map<string, string>();\n for (const edge of edges) {\n childToParent.set(edge.target, edge.source);\n }\n\n // Detect root nodes (nodes with no incoming edge)\n const roots = nodes.filter((n) => !childToParent.has(n.id));\n\n if (roots.length === 0) {\n console.warn(\n '[AlpineFlow] computeHierarchyLayout: no root nodes found (every node has an incoming edge). Returning empty layout.',\n );\n return new Map();\n }\n\n // Build stratify-compatible data: { id, parentId }\n const data: { id: string; parentId: string | null }[] = nodes.map((node) => ({\n id: node.id,\n parentId: childToParent.get(node.id) ?? null,\n }));\n\n // If multiple roots, insert a virtual root that parents all of them\n const hasVirtualRoot = roots.length > 1;\n if (hasVirtualRoot) {\n data.push({ id: VIRTUAL_ROOT_ID, parentId: null });\n for (const entry of data) {\n if (entry.parentId === null && entry.id !== VIRTUAL_ROOT_ID) {\n entry.parentId = VIRTUAL_ROOT_ID;\n }\n }\n }\n\n // Create hierarchy via stratify\n const root = stratify<{ id: string; parentId: string | null }>()\n .id((d) => d.id)\n .parentId((d) => d.parentId)(data);\n\n // Apply tree or cluster layout with nodeSize for spacing\n // nodeSize([sibling separation, level depth]) — in the tree's native TB axes.\n // For LR, x↔y are swapped later, so the depth axis (y) becomes horizontal.\n // Use the wider nodeWidth multiplier for depth so nodes don't overlap edges.\n const layoutFn = layoutType === 'cluster' ? cluster<{ id: string; parentId: string | null }>() : tree<{ id: string; parentId: string | null }>();\n layoutFn.nodeSize(\n direction === 'LR'\n ? [nodeHeight * 2, nodeWidth * 2]\n : [nodeWidth * 1.5, nodeHeight * 2],\n );\n layoutFn(root);\n\n // Extract positions from descendants\n // d3 tree: x = horizontal spread, y = depth\n const nodeMap = new Map(nodes.map((n) => [n.id, n]));\n const positions = new Map<string, { x: number; y: number }>();\n\n // When a virtual root was added, shift all y-values up by one level depth\n // so the real roots sit at y=0 instead of one level below the virtual root.\n const depthOffset = hasVirtualRoot\n ? (direction === 'LR' ? nodeWidth * 2 : nodeHeight * 2)\n : 0;\n\n for (const descendant of root.descendants()) {\n // Skip the virtual root — it should never appear in the output\n if (descendant.id === VIRTUAL_ROOT_ID) {\n continue;\n }\n\n const original = nodeMap.get(descendant.id!);\n const w = original?.dimensions?.width ?? nodeWidth;\n const h = original?.dimensions?.height ?? nodeHeight;\n\n if (direction === 'LR') {\n // Swap x↔y for left-to-right layout, convert center → top-left\n positions.set(descendant.id!, {\n x: descendant.y! - depthOffset - w / 2,\n y: descendant.x! - h / 2,\n });\n } else {\n // TB: keep as-is, convert center → top-left\n positions.set(descendant.id!, {\n x: descendant.x! - w / 2,\n y: descendant.y! - depthOffset - h / 2,\n });\n }\n }\n\n return positions;\n}\n","import type { Alpine } from 'alpinejs';\nimport { registerAddon } from '../core/registry';\nimport { computeHierarchyLayout } from '../core/layout/hierarchy';\n\nexport default function AlpineFlowHierarchy(_Alpine: Alpine): void {\n registerAddon('layout:hierarchy', computeHierarchyLayout);\n}\n","import AlpineFlowHierarchy from './hierarchy';\n\ndocument.addEventListener('alpine:init', () => {\n (window as any).Alpine.plugin(AlpineFlowHierarchy);\n});\n"],"names":["defaultSeparation","a","b","meanX","children","meanXReduce","x","c","maxY","maxYReduce","y","leafLeft","node","leafRight","cluster","separation","dx","dy","nodeSize","root","previousNode","left","right","x0","x1","count","sum","i","node_count","node_each","callback","that","index","node_eachBefore","nodes","node_eachAfter","next","n","node_find","node_sum","value","node_sort","compare","node_path","end","start","ancestor","leastCommonAncestor","k","aNodes","bNodes","node_ancestors","node_descendants","node_leaves","leaves","node_links","links","node_iterator","current","hierarchy","data","mapChildren","objectChildren","Node","child","childs","computeHeight","node_copy","copyData","d","height","optional","f","required","preroot","ambiguous","imputed","defaultId","defaultParentId","stratify","id","parentId","path","currentId","currentParentId","parent","nodeId","nodeKey","nodeByKey","I","normalize","P","parentof","S","_","slash","nextLeft","v","nextRight","moveSubtree","wm","wp","shift","change","executeShifts","w","nextAncestor","vim","TreeNode","treeRoot","tree","t","firstWalk","secondWalk","sizeNode","bottom","s","tx","kx","ky","siblings","midpoint","apportion","vip","vop","vom","sip","sop","sim","som","VIRTUAL_ROOT_ID","computeHierarchyLayout","edges","options","layoutType","direction","nodeWidth","DEFAULT_NODE_WIDTH","nodeHeight","DEFAULT_NODE_HEIGHT","childToParent","edge","roots","hasVirtualRoot","entry","layoutFn","nodeMap","positions","depthOffset","descendant","original","h","AlpineFlowHierarchy","_Alpine","registerAddon"],"mappings":";;AAAA,SAASA,EAAkBC,GAAGC,GAA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