@flanksource/clicky-ui 0.3.45 → 0.3.46

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 (140) hide show
  1. package/README.md +22 -0
  2. package/dist/data/AccessMark.cjs +23 -0
  3. package/dist/data/AccessMark.cjs.map +1 -0
  4. package/dist/data/AccessMark.d.ts +11 -0
  5. package/dist/data/AccessMark.d.ts.map +1 -0
  6. package/dist/data/AccessMark.js +23 -0
  7. package/dist/data/AccessMark.js.map +1 -0
  8. package/dist/data/CodeDiff.cjs +116 -23
  9. package/dist/data/CodeDiff.cjs.map +1 -1
  10. package/dist/data/CodeDiff.d.ts +26 -0
  11. package/dist/data/CodeDiff.d.ts.map +1 -1
  12. package/dist/data/CodeDiff.js +116 -23
  13. package/dist/data/CodeDiff.js.map +1 -1
  14. package/dist/data/GraphDiagram.cjs +65 -13
  15. package/dist/data/GraphDiagram.cjs.map +1 -1
  16. package/dist/data/GraphDiagram.d.ts +9 -2
  17. package/dist/data/GraphDiagram.d.ts.map +1 -1
  18. package/dist/data/GraphDiagram.js +66 -14
  19. package/dist/data/GraphDiagram.js.map +1 -1
  20. package/dist/data/GraphDiagramGroups.cjs +100 -0
  21. package/dist/data/GraphDiagramGroups.cjs.map +1 -0
  22. package/dist/data/GraphDiagramGroups.d.ts +24 -0
  23. package/dist/data/GraphDiagramGroups.d.ts.map +1 -0
  24. package/dist/data/GraphDiagramGroups.js +100 -0
  25. package/dist/data/GraphDiagramGroups.js.map +1 -0
  26. package/dist/data/GraphDiagramNodes.cjs +17 -31
  27. package/dist/data/GraphDiagramNodes.cjs.map +1 -1
  28. package/dist/data/GraphDiagramNodes.d.ts +6 -13
  29. package/dist/data/GraphDiagramNodes.d.ts.map +1 -1
  30. package/dist/data/GraphDiagramNodes.js +17 -31
  31. package/dist/data/GraphDiagramNodes.js.map +1 -1
  32. package/dist/data/TreeNode.cjs +1 -1
  33. package/dist/data/TreeNode.cjs.map +1 -1
  34. package/dist/data/TreeNode.d.ts.map +1 -1
  35. package/dist/data/TreeNode.js +1 -1
  36. package/dist/data/TreeNode.js.map +1 -1
  37. package/dist/data/call-graph/CallGraph.cjs +50 -31
  38. package/dist/data/call-graph/CallGraph.cjs.map +1 -1
  39. package/dist/data/call-graph/CallGraph.d.ts +10 -1
  40. package/dist/data/call-graph/CallGraph.d.ts.map +1 -1
  41. package/dist/data/call-graph/CallGraph.js +52 -33
  42. package/dist/data/call-graph/CallGraph.js.map +1 -1
  43. package/dist/data/call-graph/CallGraphMembers.cjs +5 -4
  44. package/dist/data/call-graph/CallGraphMembers.cjs.map +1 -1
  45. package/dist/data/call-graph/CallGraphMembers.d.ts +1 -1
  46. package/dist/data/call-graph/CallGraphMembers.d.ts.map +1 -1
  47. package/dist/data/call-graph/CallGraphMembers.js +5 -4
  48. package/dist/data/call-graph/CallGraphMembers.js.map +1 -1
  49. package/dist/data/call-graph/CallGraphToolbar.cjs +17 -5
  50. package/dist/data/call-graph/CallGraphToolbar.cjs.map +1 -1
  51. package/dist/data/call-graph/CallGraphToolbar.d.ts +10 -0
  52. package/dist/data/call-graph/CallGraphToolbar.d.ts.map +1 -1
  53. package/dist/data/call-graph/CallGraphToolbar.js +18 -6
  54. package/dist/data/call-graph/CallGraphToolbar.js.map +1 -1
  55. package/dist/data/call-graph/call-graph-model.cjs +169 -18
  56. package/dist/data/call-graph/call-graph-model.cjs.map +1 -1
  57. package/dist/data/call-graph/call-graph-model.d.ts +40 -4
  58. package/dist/data/call-graph/call-graph-model.d.ts.map +1 -1
  59. package/dist/data/call-graph/call-graph-model.js +170 -19
  60. package/dist/data/call-graph/call-graph-model.js.map +1 -1
  61. package/dist/data/call-graph/call-graph-vocabulary.cjs +19 -1
  62. package/dist/data/call-graph/call-graph-vocabulary.cjs.map +1 -1
  63. package/dist/data/call-graph/call-graph-vocabulary.d.ts +4 -0
  64. package/dist/data/call-graph/call-graph-vocabulary.d.ts.map +1 -1
  65. package/dist/data/call-graph/call-graph-vocabulary.js +19 -1
  66. package/dist/data/call-graph/call-graph-vocabulary.js.map +1 -1
  67. package/dist/data/call-graph/call-graph.fixtures.d.ts.map +1 -1
  68. package/dist/data/call-graph/index.d.ts +2 -2
  69. package/dist/data/call-graph/index.d.ts.map +1 -1
  70. package/dist/data/call-graph/types.cjs.map +1 -1
  71. package/dist/data/call-graph/types.d.ts +7 -2
  72. package/dist/data/call-graph/types.d.ts.map +1 -1
  73. package/dist/data/call-graph/types.js.map +1 -1
  74. package/dist/data/data-access.cjs +8 -0
  75. package/dist/data/data-access.cjs.map +1 -0
  76. package/dist/data/data-access.d.ts +5 -0
  77. package/dist/data/data-access.d.ts.map +1 -0
  78. package/dist/data/data-access.js +8 -0
  79. package/dist/data/data-access.js.map +1 -0
  80. package/dist/data/git/GitChangeList.cjs +6 -2
  81. package/dist/data/git/GitChangeList.cjs.map +1 -1
  82. package/dist/data/git/GitChangeList.d.ts +6 -1
  83. package/dist/data/git/GitChangeList.d.ts.map +1 -1
  84. package/dist/data/git/GitChangeList.js +6 -2
  85. package/dist/data/git/GitChangeList.js.map +1 -1
  86. package/dist/data/graph-columns-layout.cjs +47 -16
  87. package/dist/data/graph-columns-layout.cjs.map +1 -1
  88. package/dist/data/graph-columns-layout.d.ts +34 -0
  89. package/dist/data/graph-columns-layout.d.ts.map +1 -1
  90. package/dist/data/graph-columns-layout.js +47 -16
  91. package/dist/data/graph-columns-layout.js.map +1 -1
  92. package/dist/data/graph-diagram-model.cjs +5 -0
  93. package/dist/data/graph-diagram-model.cjs.map +1 -1
  94. package/dist/data/graph-diagram-model.d.ts +19 -0
  95. package/dist/data/graph-diagram-model.d.ts.map +1 -1
  96. package/dist/data/graph-diagram-model.js +5 -0
  97. package/dist/data/graph-diagram-model.js.map +1 -1
  98. package/dist/data/graph-group-window.cjs +60 -0
  99. package/dist/data/graph-group-window.cjs.map +1 -0
  100. package/dist/data/graph-group-window.d.ts +33 -0
  101. package/dist/data/graph-group-window.d.ts.map +1 -0
  102. package/dist/data/graph-group-window.js +60 -0
  103. package/dist/data/graph-group-window.js.map +1 -0
  104. package/dist/data/use-group-windows.cjs +50 -0
  105. package/dist/data/use-group-windows.cjs.map +1 -0
  106. package/dist/data/use-group-windows.d.ts +27 -0
  107. package/dist/data/use-group-windows.d.ts.map +1 -0
  108. package/dist/data/use-group-windows.js +50 -0
  109. package/dist/data/use-group-windows.js.map +1 -0
  110. package/dist/data/version-info.cjs +3 -3
  111. package/dist/data/version-info.js +3 -3
  112. package/dist/data.cjs +10 -0
  113. package/dist/data.cjs.map +1 -1
  114. package/dist/data.d.ts +4 -2
  115. package/dist/data.d.ts.map +1 -1
  116. package/dist/data.js +13 -3
  117. package/dist/data.js.map +1 -1
  118. package/dist/hooks/event-hub.cjs +229 -0
  119. package/dist/hooks/event-hub.cjs.map +1 -0
  120. package/dist/hooks/event-hub.d.ts +26 -0
  121. package/dist/hooks/event-hub.d.ts.map +1 -0
  122. package/dist/hooks/event-hub.js +229 -0
  123. package/dist/hooks/event-hub.js.map +1 -0
  124. package/dist/hooks.cjs +2 -0
  125. package/dist/hooks.cjs.map +1 -1
  126. package/dist/hooks.d.ts +1 -0
  127. package/dist/hooks.d.ts.map +1 -1
  128. package/dist/hooks.js +2 -0
  129. package/dist/hooks.js.map +1 -1
  130. package/dist/index.cjs +12 -0
  131. package/dist/index.cjs.map +1 -1
  132. package/dist/index.js +15 -3
  133. package/dist/index.js.map +1 -1
  134. package/dist/overlay/modalStack.cjs +13 -6
  135. package/dist/overlay/modalStack.cjs.map +1 -1
  136. package/dist/overlay/modalStack.d.ts.map +1 -1
  137. package/dist/overlay/modalStack.js +13 -6
  138. package/dist/overlay/modalStack.js.map +1 -1
  139. package/dist/styles.css +1 -1
  140. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"graph-columns-layout.js","sources":["../../src/data/graph-columns-layout.ts"],"sourcesContent":["// Level-column layout for GraphDiagram: pure math, no React. Split from\n// graph-layout.ts, which owns the shared types and `ringLayout`.\n\nimport { loopOverhang } from \"./graph-edge-routing\";\nimport type { GraphLayoutEdge, GraphLayoutNode, GraphLayoutPosition, GraphLayoutResult } from \"./graph-layout\";\n\nexport interface ColumnsLayoutNode extends GraphLayoutNode {\n /** Column of the node. May be negative: the lowest level is the first column. */\n level: number;\n /** Nodes sharing a group stay contiguous within their column and are boxed together. */\n group?: string;\n /** Drawn at `compactNodeHeight`; a group of only compact nodes stacks them at the compact gap and padding. */\n compact?: boolean;\n}\n\nexport interface ColumnsLayoutOptions {\n /** Node bounding-box width in px. Defaults to 168. */\n nodeWidth?: number;\n /** Node bounding-box height in px. Defaults to 60. */\n nodeHeight?: number;\n /** Horizontal gap between the node boxes of adjacent columns in px. Defaults to 96. */\n columnGap?: number;\n /** Vertical gap between stacked nodes, and between group rectangles, in px. Defaults to 20. */\n rowGap?: number;\n /** Space between a group's nodes and its rectangle in px. Defaults to 12. */\n groupPadding?: number;\n /** Height of a compact node in px. Defaults to 24. */\n compactNodeHeight?: number;\n /** Vertical gap between the nodes of a group of only compact nodes in px. Defaults to 4. */\n compactRowGap?: number;\n /** Space between a group of only compact nodes and its rectangle in px. Defaults to 8. */\n compactGroupPadding?: number;\n /** Space reserved around the columns before the viewport edge. Defaults to 24. */\n padding?: number;\n /**\n * Re-ordering passes over all columns after the first placement, alternating direction; a pass\n * is kept only if it leaves fewer crossings. Defaults to 4. 0 keeps the first placement.\n */\n sweeps?: number;\n}\n\nexport interface GraphLayoutGroupBox {\n /** `${level}:${group}` — a group spanning several columns gets one rectangle per column. */\n id: string;\n group: string;\n level: number;\n /** Top-left corner, in the same coordinate space as the layout's `width`/`height`. */\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface ColumnsLayoutResult extends GraphLayoutResult {\n groups: GraphLayoutGroupBox[];\n}\n\ntype ColumnMetrics = Required<ColumnsLayoutOptions>;\n\ninterface GroupRun {\n group: string | undefined;\n nodes: ColumnsLayoutNode[];\n}\n\n/** One ordering of every column, stacked: the node centres and group rectangles it gives. */\ninterface Arrangement {\n order: Map<number, ColumnsLayoutNode[]>;\n placed: Map<string, GraphLayoutPosition>;\n boxes: Map<number, GraphLayoutGroupBox[]>;\n}\n\n/** What stays fixed while columns are re-ordered. */\ninterface ColumnsContext {\n m: ColumnMetrics;\n levels: number[];\n levelOf: Map<string, number>;\n groupRank: Map<string | undefined, number>;\n neighbours: Map<string, string[]>;\n edges: readonly GraphLayoutEdge[];\n /** Centre x and top y of a level's column. */\n origin: (level: number) => { x: number; top: number; level: number };\n}\n\nconst DEFAULT_NODE_WIDTH = 168;\nconst DEFAULT_NODE_HEIGHT = 60;\nconst DEFAULT_COLUMN_GAP = 96;\nconst DEFAULT_ROW_GAP = 20;\nconst DEFAULT_GROUP_PADDING = 12;\nconst DEFAULT_COMPACT_NODE_HEIGHT = 24;\nconst DEFAULT_COMPACT_ROW_GAP = 4;\nconst DEFAULT_COMPACT_GROUP_PADDING = 8;\nconst DEFAULT_PADDING = 24;\nconst DEFAULT_SWEEPS = 4;\n\nfunction mustGet<K, V>(map: ReadonlyMap<K, V>, key: K, what: string): V {\n const value = map.get(key);\n if (value === undefined) {\n throw new Error(`columnsLayout: no ${what} for \"${String(key)}\"`);\n }\n return value;\n}\n\nfunction columnMetrics(options: ColumnsLayoutOptions): ColumnMetrics {\n return {\n nodeWidth: options.nodeWidth ?? DEFAULT_NODE_WIDTH,\n nodeHeight: options.nodeHeight ?? DEFAULT_NODE_HEIGHT,\n columnGap: options.columnGap ?? DEFAULT_COLUMN_GAP,\n rowGap: options.rowGap ?? DEFAULT_ROW_GAP,\n groupPadding: options.groupPadding ?? DEFAULT_GROUP_PADDING,\n compactNodeHeight: options.compactNodeHeight ?? DEFAULT_COMPACT_NODE_HEIGHT,\n compactRowGap: options.compactRowGap ?? DEFAULT_COMPACT_ROW_GAP,\n compactGroupPadding: options.compactGroupPadding ?? DEFAULT_COMPACT_GROUP_PADDING,\n padding: options.padding ?? DEFAULT_PADDING,\n sweeps: options.sweeps ?? DEFAULT_SWEEPS,\n };\n}\n\nfunction indexColumns(nodes: readonly ColumnsLayoutNode[]) {\n const columns = new Map<number, ColumnsLayoutNode[]>();\n const groupRank = new Map<string | undefined, number>();\n for (const node of nodes) {\n if (!Number.isFinite(node.level)) {\n throw new Error(`columnsLayout: node \"${node.id}\" has no finite level (got ${node.level})`);\n }\n if (!groupRank.has(node.group)) groupRank.set(node.group, groupRank.size);\n const column = columns.get(node.level);\n if (column) {\n column.push(node);\n } else {\n columns.set(node.level, [node]);\n }\n }\n return { columns, groupRank };\n}\n\nfunction indexNeighbours(\n nodes: readonly ColumnsLayoutNode[],\n edges: readonly GraphLayoutEdge[],\n): Map<string, string[]> {\n const neighbours = new Map<string, string[]>(nodes.map((node) => [node.id, []]));\n for (const edge of edges) {\n const from = neighbours.get(edge.from);\n const to = neighbours.get(edge.to);\n if (!from || !to) {\n const missing = from ? edge.to : edge.from;\n throw new Error(`columnsLayout: edge \"${edge.id}\" references unknown node \"${missing}\"`);\n }\n from.push(edge.to);\n to.push(edge.from);\n }\n return neighbours;\n}\n\n/**\n * How a run of nodes stacks: each node's height, the gap between them and the padding inside the run's\n * rectangle. A grouped run of only compact nodes takes the compact gap and padding; any other run the\n * regular ones, whatever its order, so a column's height does not depend on how it is ordered.\n */\nfunction runMetrics(group: string | undefined, nodes: readonly ColumnsLayoutNode[], m: ColumnMetrics) {\n const compact = group !== undefined && nodes.every((node) => node.compact === true);\n const pad = group === undefined ? 0 : compact ? m.compactGroupPadding : m.groupPadding;\n const gap = compact ? m.compactRowGap : m.rowGap;\n const heightOf = (node: ColumnsLayoutNode) => (node.compact ? m.compactNodeHeight : m.nodeHeight);\n const height = nodes.reduce((sum, node) => sum + heightOf(node), 0) + (nodes.length - 1) * gap + 2 * pad;\n return { pad, gap, heightOf, height };\n}\n\nfunction columnHeight(column: readonly ColumnsLayoutNode[], m: ColumnMetrics): number {\n const runs = new Map<string | undefined, ColumnsLayoutNode[]>();\n for (const node of column) runs.set(node.group, [...(runs.get(node.group) ?? []), node]);\n const stacked = [...runs].reduce((sum, [group, nodes]) => sum + runMetrics(group, nodes, m).height, 0);\n return stacked + (runs.size - 1) * m.rowGap;\n}\n\n/** Groups in order of first appearance; within a group by ascending weight, the column's order on ties. */\nfunction orderColumn(\n column: readonly ColumnsLayoutNode[],\n groupRank: ReadonlyMap<string | undefined, number>,\n weight: (node: ColumnsLayoutNode) => number,\n): GroupRun[] {\n const runs = new Map<number, { node: ColumnsLayoutNode; index: number; weight: number }[]>();\n column.forEach((node, index) => {\n const rank = mustGet(groupRank, node.group, \"group rank\");\n const entry = { node, index, weight: weight(node) };\n const run = runs.get(rank);\n if (run) {\n run.push(entry);\n } else {\n runs.set(rank, [entry]);\n }\n });\n return [...runs.entries()]\n .sort(([a], [b]) => a - b)\n .map(([, run]) => {\n // Infinity - Infinity is NaN, which falls through to the column-order tiebreak.\n const nodes = run.sort((a, b) => a.weight - b.weight || a.index - b.index).map((entry) => entry.node);\n return { group: nodes[0]?.group, nodes };\n });\n}\n\nfunction stackColumn(\n runs: readonly GroupRun[],\n origin: { x: number; top: number; level: number },\n m: ColumnMetrics,\n placed: Map<string, GraphLayoutPosition>,\n): GraphLayoutGroupBox[] {\n const boxes: GraphLayoutGroupBox[] = [];\n let cursor = origin.top;\n for (const { group, nodes } of runs) {\n const { pad, gap, heightOf, height } = runMetrics(group, nodes, m);\n let top = cursor + pad;\n for (const node of nodes) {\n placed.set(node.id, { x: origin.x, y: top + heightOf(node) / 2 });\n top += heightOf(node) + gap;\n }\n if (group !== undefined) {\n boxes.push({\n id: `${origin.level}:${group}`,\n group,\n level: origin.level,\n x: origin.x - m.nodeWidth / 2 - pad,\n y: cursor,\n width: m.nodeWidth + 2 * pad,\n height,\n });\n }\n cursor += height + m.rowGap;\n }\n return boxes;\n}\n\nfunction meanY(ids: readonly string[], placed: ReadonlyMap<string, GraphLayoutPosition>): number {\n if (ids.length === 0) return Number.POSITIVE_INFINITY;\n return ids.reduce((sum, id) => sum + mustGet(placed, id, \"position\").y, 0) / ids.length;\n}\n\n/**\n * Levels in the order they are first laid out — the one nearest 0, then\n * outward on each side — each paired with the already-placed adjacent level\n * its nodes are ordered against.\n */\nfunction placementOrder(levels: readonly number[]): [level: number, reference: number | undefined][] {\n const anchor = levels.reduce((best, level) => (Math.abs(level) < Math.abs(best) ? level : best));\n const outward = (side: readonly number[]) =>\n side.map((level, index): [number, number] => [level, side[index - 1] ?? anchor]);\n return [\n [anchor, undefined],\n ...outward(levels.filter((level) => level > anchor)),\n ...outward(levels.filter((level) => level < anchor).reverse()),\n ];\n}\n\n/** Orders one column by the mean y of its nodes' neighbours in the `references` levels, and stacks it. */\nfunction placeColumn(level: number, references: readonly number[], ctx: ColumnsContext, into: Arrangement): void {\n const runs = orderColumn(mustGet(into.order, level, \"column\"), ctx.groupRank, (node) =>\n meanY(\n mustGet(ctx.neighbours, node.id, \"neighbours\").filter((id) =>\n references.includes(mustGet(ctx.levelOf, id, \"level\")),\n ),\n into.placed,\n ),\n );\n into.order.set(\n level,\n runs.flatMap((run) => run.nodes),\n );\n into.boxes.set(level, stackColumn(runs, ctx.origin(level), ctx.m, into.placed));\n}\n\n/** Pairs of edges between adjacent columns that cross, taking each edge as a straight line. */\nfunction countCrossings(ctx: ColumnsContext, placed: ReadonlyMap<string, GraphLayoutPosition>): number {\n const spans = new Map<number, [lower: number, upper: number][]>();\n for (const edge of ctx.edges) {\n const levels = [mustGet(ctx.levelOf, edge.from, \"level\"), mustGet(ctx.levelOf, edge.to, \"level\")] as const;\n const [lower, upper] = levels[0] < levels[1] ? [edge.from, edge.to] : [edge.to, edge.from];\n const index = ctx.levels.indexOf(Math.min(...levels));\n if (levels[0] === levels[1] || ctx.levels[index + 1] !== Math.max(...levels)) continue;\n const span: [number, number] = [mustGet(placed, lower, \"position\").y, mustGet(placed, upper, \"position\").y];\n spans.set(index, [...(spans.get(index) ?? []), span]);\n }\n let crossings = 0;\n for (const gap of spans.values()) {\n gap.forEach((a, index) => {\n crossings += gap.slice(index + 1).filter((b) => (a[0] - b[0]) * (a[1] - b[1]) < 0).length;\n });\n }\n return crossings;\n}\n\n/** A copy of `from` with every column re-ordered against both its neighbours, in the order given. */\nfunction sweep(from: Arrangement, sequence: readonly number[], ctx: ColumnsContext): Arrangement {\n const next: Arrangement = { order: new Map(from.order), placed: new Map(from.placed), boxes: new Map(from.boxes) };\n for (const level of sequence) {\n const index = ctx.levels.indexOf(level);\n const adjacent = [ctx.levels[index - 1], ctx.levels[index + 1]].filter((other): other is number => other !== undefined);\n placeColumn(level, adjacent, ctx, next);\n }\n return next;\n}\n\n/**\n * Orders the columns. The first pass places the level nearest 0 and works\n * outward, ordering each column against the one just placed. Then up to\n * `sweeps` passes re-order every column against both its neighbours, inward\n * then outward, and the arrangement with the fewest crossings is kept: the\n * first pass's unless a later one strictly beats it.\n */\nfunction arrange(columns: ReadonlyMap<number, ColumnsLayoutNode[]>, ctx: ColumnsContext): Arrangement {\n let current: Arrangement = { order: new Map(columns), placed: new Map(), boxes: new Map() };\n for (const [level, reference] of placementOrder(ctx.levels)) {\n placeColumn(level, reference === undefined ? [] : [reference], ctx, current);\n }\n let best = current;\n let fewest = countCrossings(ctx, best.placed);\n for (let pass = 0; pass < ctx.m.sweeps && fewest > 0; pass++) {\n current = sweep(current, pass % 2 === 0 ? [...ctx.levels].reverse() : ctx.levels, ctx);\n const crossings = countCrossings(ctx, current.placed);\n if (crossings < fewest) {\n best = current;\n fewest = crossings;\n }\n }\n return best;\n}\n\n/**\n * Places nodes in left-to-right columns by `level` (the lowest level first),\n * stacking each column top to bottom and centring it against the tallest one.\n *\n * Within a column, nodes of one group are contiguous, groups appearing in the\n * order they first occur in `nodes`. Inside a group nodes are ordered by the\n * mean y of their neighbours in the adjacent columns, so edges between columns\n * cross less (see `arrange`); nodes with no neighbour there go last, and ties\n * keep input order.\n *\n * Returns node centres plus one rectangle per (column, group). Extra width is\n * reserved on each side for the loops `routeEdges` draws outside the first and\n * last columns.\n */\nexport function columnsLayout(\n nodes: readonly ColumnsLayoutNode[],\n edges: readonly GraphLayoutEdge[],\n options: ColumnsLayoutOptions = {},\n): ColumnsLayoutResult {\n const m = columnMetrics(options);\n const { columns, groupRank } = indexColumns(nodes);\n const neighbours = indexNeighbours(nodes, edges);\n const levels = [...columns.keys()].sort((a, b) => a - b);\n if (levels.length === 0) {\n return { width: 2 * m.padding, height: 2 * m.padding, positions: {}, groups: [] };\n }\n\n const minLevel = Math.min(...levels);\n const tallest = Math.max(...[...columns.values()].map((column) => columnHeight(column, m)));\n const inset = m.padding + (nodes.some((node) => node.group !== undefined) ? m.groupPadding : 0);\n const { placed, boxes } = arrange(columns, {\n m,\n levels,\n levelOf: new Map(nodes.map((node) => [node.id, node.level])),\n groupRank,\n neighbours,\n edges,\n origin: (level) => ({\n x: inset + m.nodeWidth / 2 + (level - minLevel) * (m.nodeWidth + m.columnGap),\n top: m.padding + (tallest - columnHeight(mustGet(columns, level, \"column\"), m)) / 2,\n level,\n }),\n });\n\n const nodeHeights = Object.fromEntries(nodes.filter((node) => node.compact).map((node) => [node.id, m.compactNodeHeight]));\n const room = loopOverhang(edges, Object.fromEntries(placed), { ...m, nodeHeights });\n const span = (Math.max(...levels) - minLevel) * (m.nodeWidth + m.columnGap) + m.nodeWidth;\n return {\n width: room.left + 2 * inset + span + room.right,\n height: tallest + 2 * m.padding,\n positions: Object.fromEntries([...placed].map(([id, { x, y }]) => [id, { x: x + room.left, y }])),\n groups: [...boxes.values()]\n .flat()\n .map((box) => ({ ...box, x: box.x + room.left }))\n .sort((a, b) => a.level - b.level || a.y - b.y),\n };\n}\n"],"names":[],"mappings":";AAmFA,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAC3B,MAAM,kBAAkB;AACxB,MAAM,wBAAwB;AAC9B,MAAM,8BAA8B;AACpC,MAAM,0BAA0B;AAChC,MAAM,gCAAgC;AACtC,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,SAAS,QAAc,KAAwB,KAAQ,MA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C,IAAI,EAAE,GAAG,IAAI,KAAK,MAAM,EAAA,CAAG,CAAC,CAAC;AAAA,IAChG,QAAQ,CAAC,GAAG,MAAM,QAAQ,EACvB,KAAA,EACA,IAAI,CAAC,SAAS,EAAE,GAAG,KAAK,GAAG,IAAI,IAAI,KAAK,KAAA,EAAO,EAC/C,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAAA,EAAA;AAEpD;"}
1
+ {"version":3,"file":"graph-columns-layout.js","sources":["../../src/data/graph-columns-layout.ts"],"sourcesContent":["// Level-column layout for GraphDiagram: pure math, no React. Split from\n// graph-layout.ts, which owns the shared types and `ringLayout`.\n\nimport { loopOverhang } from \"./graph-edge-routing\";\nimport type { GraphLayoutEdge, GraphLayoutNode, GraphLayoutPosition, GraphLayoutResult } from \"./graph-layout\";\n\nexport interface ColumnsLayoutNode extends GraphLayoutNode {\n /** Column of the node. May be negative: the lowest level is the first column. */\n level: number;\n /** Nodes sharing a group stay contiguous within their column and are boxed together. */\n group?: string;\n /** Drawn at `compactNodeHeight`; a group of only compact nodes stacks them at the compact gap and padding. */\n compact?: boolean;\n}\n\n/** The most members a group shows at once in a column; a group with more scrolls them in a window this many rows tall. */\nexport const GROUP_MEMBER_WINDOW = 10;\n/** Height of the \"rows a–b of n\" footer under a windowed group's rows. */\nconst GROUP_WINDOW_FOOTER_HEIGHT = 18;\n\nexport interface ColumnsLayoutOptions {\n /** Group ids drawn as records with a header and flush compact rows. */\n records?: readonly string[];\n /**\n * Group ids drawn as their header alone, `recordHeaderHeight` tall. Each holds one node per column it\n * is drawn in, the stand-in its edges attach to, placed at the header's middle.\n */\n collapsed?: readonly string[];\n /** Height of a record's header in px. Defaults to 24. */\n recordHeaderHeight?: number;\n /** Node bounding-box width in px. Defaults to 168. */\n nodeWidth?: number;\n /** Node bounding-box height in px. Defaults to 60. */\n nodeHeight?: number;\n /** Horizontal gap between the node boxes of adjacent columns in px. Defaults to 96. */\n columnGap?: number;\n /** Vertical gap between stacked nodes, and between group rectangles, in px. Defaults to 20. */\n rowGap?: number;\n /** Space between a group's nodes and its rectangle in px. Defaults to 12. */\n groupPadding?: number;\n /** Height of a compact node in px. Defaults to 24. */\n compactNodeHeight?: number;\n /** Vertical gap between the nodes of a group of only compact nodes in px. Defaults to 4. */\n compactRowGap?: number;\n /** Space between a group of only compact nodes and its rectangle in px. Defaults to 8. */\n compactGroupPadding?: number;\n /** Space reserved around the columns before the viewport edge. Defaults to 24. */\n padding?: number;\n /**\n * Re-ordering passes over all columns after the first placement, alternating direction; a pass\n * is kept only if it leaves fewer crossings. Defaults to 4. 0 keeps the first placement.\n */\n sweeps?: number;\n}\n\nexport interface GraphLayoutGroupBox {\n /** `${level}:${group}` — a group spanning several columns gets one rectangle per column. */\n id: string;\n group: string;\n level: number;\n /** Top-left corner, in the same coordinate space as the layout's `width`/`height`. */\n x: number;\n y: number;\n width: number;\n height: number;\n record: boolean;\n headerHeight: number;\n /** Set when the group holds more members in this column than `GROUP_MEMBER_WINDOW`: they scroll in a window. */\n window?: GroupMemberWindow;\n /** Drawn as its header alone: see `ColumnsLayoutOptions.collapsed`. */\n collapsed?: true;\n}\n\n/**\n * The rows a group with more members than `GROUP_MEMBER_WINDOW` shows at once. The layout places every\n * member as if the group were drawn whole; a member shown from row `start` is drawn `tops[start]` higher.\n */\nexport interface GroupMemberWindow {\n /** The members in this column, top to bottom. */\n members: string[];\n /** Each member's top, from the first member's top. */\n tops: number[];\n /** How many rows show at once. */\n rows: number;\n /** Top of the area members are drawn in, and its height. */\n top: number;\n height: number;\n /** Height of the footer below that area, inside the group's rectangle. */\n footerHeight: number;\n}\n\nexport interface ColumnsLayoutResult extends GraphLayoutResult {\n groups: GraphLayoutGroupBox[];\n}\n\ntype ColumnMetrics = Required<ColumnsLayoutOptions>;\n\ninterface GroupRun {\n group: string | undefined;\n nodes: ColumnsLayoutNode[];\n}\n\n/** One ordering of every column, stacked: the node centres and group rectangles it gives. */\ninterface Arrangement {\n order: Map<number, ColumnsLayoutNode[]>;\n placed: Map<string, GraphLayoutPosition>;\n boxes: Map<number, GraphLayoutGroupBox[]>;\n}\n\n/** What stays fixed while columns are re-ordered. */\ninterface ColumnsContext {\n m: ColumnMetrics;\n levels: number[];\n levelOf: Map<string, number>;\n groupRank: Map<string | undefined, number>;\n neighbours: Map<string, string[]>;\n edges: readonly GraphLayoutEdge[];\n /** Centre x and top y of a level's column. */\n origin: (level: number) => { x: number; top: number; level: number };\n}\n\nconst DEFAULT_NODE_WIDTH = 168;\nconst DEFAULT_NODE_HEIGHT = 60;\nconst DEFAULT_COLUMN_GAP = 96;\nconst DEFAULT_ROW_GAP = 20;\nconst DEFAULT_GROUP_PADDING = 12;\nconst DEFAULT_COMPACT_NODE_HEIGHT = 24;\nconst DEFAULT_COMPACT_ROW_GAP = 4;\nconst DEFAULT_COMPACT_GROUP_PADDING = 8;\nconst DEFAULT_PADDING = 24;\nconst DEFAULT_SWEEPS = 4;\n\nfunction mustGet<K, V>(map: ReadonlyMap<K, V>, key: K, what: string): V {\n const value = map.get(key);\n if (value === undefined) {\n throw new Error(`columnsLayout: no ${what} for \"${String(key)}\"`);\n }\n return value;\n}\n\nfunction columnMetrics(options: ColumnsLayoutOptions): ColumnMetrics {\n return {\n records: options.records ?? [],\n collapsed: options.collapsed ?? [],\n recordHeaderHeight: options.recordHeaderHeight ?? 24,\n nodeWidth: options.nodeWidth ?? DEFAULT_NODE_WIDTH,\n nodeHeight: options.nodeHeight ?? DEFAULT_NODE_HEIGHT,\n columnGap: options.columnGap ?? DEFAULT_COLUMN_GAP,\n rowGap: options.rowGap ?? DEFAULT_ROW_GAP,\n groupPadding: options.groupPadding ?? DEFAULT_GROUP_PADDING,\n compactNodeHeight: options.compactNodeHeight ?? DEFAULT_COMPACT_NODE_HEIGHT,\n compactRowGap: options.compactRowGap ?? DEFAULT_COMPACT_ROW_GAP,\n compactGroupPadding: options.compactGroupPadding ?? DEFAULT_COMPACT_GROUP_PADDING,\n padding: options.padding ?? DEFAULT_PADDING,\n sweeps: options.sweeps ?? DEFAULT_SWEEPS,\n };\n}\n\nfunction indexColumns(nodes: readonly ColumnsLayoutNode[]) {\n const columns = new Map<number, ColumnsLayoutNode[]>();\n const groupRank = new Map<string | undefined, number>();\n for (const node of nodes) {\n if (!Number.isFinite(node.level)) {\n throw new Error(`columnsLayout: node \"${node.id}\" has no finite level (got ${node.level})`);\n }\n if (!groupRank.has(node.group)) groupRank.set(node.group, groupRank.size);\n const column = columns.get(node.level);\n if (column) {\n column.push(node);\n } else {\n columns.set(node.level, [node]);\n }\n }\n return { columns, groupRank };\n}\n\nfunction indexNeighbours(\n nodes: readonly ColumnsLayoutNode[],\n edges: readonly GraphLayoutEdge[],\n): Map<string, string[]> {\n const neighbours = new Map<string, string[]>(nodes.map((node) => [node.id, []]));\n for (const edge of edges) {\n const from = neighbours.get(edge.from);\n const to = neighbours.get(edge.to);\n if (!from || !to) {\n const missing = from ? edge.to : edge.from;\n throw new Error(`columnsLayout: edge \"${edge.id}\" references unknown node \"${missing}\"`);\n }\n from.push(edge.to);\n to.push(edge.from);\n }\n return neighbours;\n}\n\ninterface RunMetrics {\n pad: number;\n gap: number;\n heightOf: (node: ColumnsLayoutNode) => number;\n /** Room above the first node inside the run's rectangle: a record's header. */\n header: number;\n height: number;\n /** The height members are drawn in, when there are more of them than the window holds. */\n view?: number;\n collapsed: boolean;\n}\n\nfunction collapsedRun(group: string, nodes: readonly ColumnsLayoutNode[], m: ColumnMetrics): RunMetrics {\n if (nodes.length !== 1) throw new Error(`columnsLayout: collapsed group \"${group}\" holds ${nodes.length} nodes in a column; it draws one stand-in`);\n return { pad: 0, gap: 0, heightOf: () => m.recordHeaderHeight, header: 0, height: m.recordHeaderHeight, collapsed: true };\n}\n\n/**\n * How a run of nodes stacks: each node's height, the gap between them and the padding inside the run's\n * rectangle. A grouped run of only compact nodes takes the compact gap and padding; any other run the\n * regular ones, whatever its order, so a column's height does not depend on how it is ordered. A group\n * of more than `GROUP_MEMBER_WINDOW` members is only as tall as that many of its tallest rows, over a footer.\n */\nfunction runMetrics(group: string | undefined, nodes: readonly ColumnsLayoutNode[], m: ColumnMetrics, record: boolean): RunMetrics {\n if (group !== undefined && m.collapsed.includes(group)) return collapsedRun(group, nodes, m);\n let stack: Omit<RunMetrics, \"height\" | \"collapsed\">;\n if (record) {\n const regular = nodes.find((node) => !node.compact);\n if (regular) throw new Error(`columnsLayout: record group \"${group}\" holds non-compact node \"${regular.id}\"`);\n stack = { pad: 0, gap: 0, heightOf: () => m.compactNodeHeight, header: m.recordHeaderHeight };\n } else {\n const compact = group !== undefined && nodes.every((node) => node.compact === true);\n const heightOf = (node: ColumnsLayoutNode) => (node.compact ? m.compactNodeHeight : m.nodeHeight);\n stack = { pad: group === undefined ? 0 : compact ? m.compactGroupPadding : m.groupPadding, gap: compact ? m.compactRowGap : m.rowGap, heightOf, header: 0 };\n }\n const chrome = stack.header + 2 * stack.pad;\n if (group === undefined || nodes.length <= GROUP_MEMBER_WINDOW) {\n const stacked = nodes.reduce((sum, node) => sum + stack.heightOf(node), 0) + (nodes.length - 1) * stack.gap;\n return { ...stack, height: chrome + stacked, collapsed: false };\n }\n const view = GROUP_MEMBER_WINDOW * Math.max(...nodes.map(stack.heightOf)) + (GROUP_MEMBER_WINDOW - 1) * stack.gap;\n return { ...stack, view, height: chrome + view + GROUP_WINDOW_FOOTER_HEIGHT, collapsed: false };\n}\n\nfunction columnHeight(column: readonly ColumnsLayoutNode[], m: ColumnMetrics): number {\n const runs = new Map<string | undefined, ColumnsLayoutNode[]>();\n for (const node of column) runs.set(node.group, [...(runs.get(node.group) ?? []), node]);\n const stacked = [...runs].reduce((sum, [group, nodes]) => sum + runMetrics(group, nodes, m, group !== undefined && m.records.includes(group)).height, 0);\n return stacked + (runs.size - 1) * m.rowGap;\n}\n\n/** Groups in order of first appearance; within a group by ascending weight, the column's order on ties. */\nfunction orderColumn(\n column: readonly ColumnsLayoutNode[],\n groupRank: ReadonlyMap<string | undefined, number>,\n weight: (node: ColumnsLayoutNode) => number,\n): GroupRun[] {\n const runs = new Map<number, { node: ColumnsLayoutNode; index: number; weight: number }[]>();\n column.forEach((node, index) => {\n const rank = mustGet(groupRank, node.group, \"group rank\");\n const entry = { node, index, weight: weight(node) };\n const run = runs.get(rank);\n if (run) {\n run.push(entry);\n } else {\n runs.set(rank, [entry]);\n }\n });\n return [...runs.entries()]\n .sort(([a], [b]) => a - b)\n .map(([, run]) => {\n // Infinity - Infinity is NaN, which falls through to the column-order tiebreak.\n const nodes = run.sort((a, b) => a.weight - b.weight || a.index - b.index).map((entry) => entry.node);\n return { group: nodes[0]?.group, nodes };\n });\n}\n\nfunction stackColumn(\n runs: readonly GroupRun[],\n origin: { x: number; top: number; level: number },\n m: ColumnMetrics,\n placed: Map<string, GraphLayoutPosition>,\n): GraphLayoutGroupBox[] {\n const boxes: GraphLayoutGroupBox[] = [];\n let cursor = origin.top;\n for (const { group, nodes } of runs) {\n const record = group !== undefined && m.records.includes(group);\n const run = runMetrics(group, nodes, m, record);\n const first = cursor + run.pad + run.header;\n const tops: number[] = [];\n let top = first;\n for (const node of nodes) {\n tops.push(top - first);\n placed.set(node.id, { x: origin.x, y: top + run.heightOf(node) / 2 });\n top += run.heightOf(node) + run.gap;\n }\n if (group !== undefined) {\n const memberWindow: GroupMemberWindow | undefined = run.view === undefined ? undefined\n : { members: nodes.map((node) => node.id), tops, rows: GROUP_MEMBER_WINDOW, top: first, height: run.view, footerHeight: GROUP_WINDOW_FOOTER_HEIGHT };\n boxes.push({\n id: `${origin.level}:${group}`,\n group,\n level: origin.level,\n x: origin.x - m.nodeWidth / 2 - run.pad,\n y: cursor,\n width: m.nodeWidth + 2 * run.pad,\n height: run.height,\n record,\n headerHeight: run.collapsed ? m.recordHeaderHeight : run.header,\n ...(memberWindow ? { window: memberWindow } : {}),\n ...(run.collapsed ? { collapsed: true as const } : {}),\n });\n }\n cursor += run.height + m.rowGap;\n }\n return boxes;\n}\n\nfunction meanY(ids: readonly string[], placed: ReadonlyMap<string, GraphLayoutPosition>): number {\n if (ids.length === 0) return Number.POSITIVE_INFINITY;\n return ids.reduce((sum, id) => sum + mustGet(placed, id, \"position\").y, 0) / ids.length;\n}\n\n/**\n * Levels in the order they are first laid out — the one nearest 0, then\n * outward on each side — each paired with the already-placed adjacent level\n * its nodes are ordered against.\n */\nfunction placementOrder(levels: readonly number[]): [level: number, reference: number | undefined][] {\n const anchor = levels.reduce((best, level) => (Math.abs(level) < Math.abs(best) ? level : best));\n const outward = (side: readonly number[]) =>\n side.map((level, index): [number, number] => [level, side[index - 1] ?? anchor]);\n return [\n [anchor, undefined],\n ...outward(levels.filter((level) => level > anchor)),\n ...outward(levels.filter((level) => level < anchor).reverse()),\n ];\n}\n\n/** Orders one column by the mean y of its nodes' neighbours in the `references` levels, and stacks it. */\nfunction placeColumn(level: number, references: readonly number[], ctx: ColumnsContext, into: Arrangement): void {\n const runs = orderColumn(mustGet(into.order, level, \"column\"), ctx.groupRank, (node) =>\n meanY(\n mustGet(ctx.neighbours, node.id, \"neighbours\").filter((id) =>\n references.includes(mustGet(ctx.levelOf, id, \"level\")),\n ),\n into.placed,\n ),\n );\n into.order.set(\n level,\n runs.flatMap((run) => run.nodes),\n );\n into.boxes.set(level, stackColumn(runs, ctx.origin(level), ctx.m, into.placed));\n}\n\n/** Pairs of edges between adjacent columns that cross, taking each edge as a straight line. */\nfunction countCrossings(ctx: ColumnsContext, placed: ReadonlyMap<string, GraphLayoutPosition>): number {\n const spans = new Map<number, [lower: number, upper: number][]>();\n for (const edge of ctx.edges) {\n const levels = [mustGet(ctx.levelOf, edge.from, \"level\"), mustGet(ctx.levelOf, edge.to, \"level\")] as const;\n const [lower, upper] = levels[0] < levels[1] ? [edge.from, edge.to] : [edge.to, edge.from];\n const index = ctx.levels.indexOf(Math.min(...levels));\n if (levels[0] === levels[1] || ctx.levels[index + 1] !== Math.max(...levels)) continue;\n const span: [number, number] = [mustGet(placed, lower, \"position\").y, mustGet(placed, upper, \"position\").y];\n spans.set(index, [...(spans.get(index) ?? []), span]);\n }\n let crossings = 0;\n for (const gap of spans.values()) {\n gap.forEach((a, index) => {\n crossings += gap.slice(index + 1).filter((b) => (a[0] - b[0]) * (a[1] - b[1]) < 0).length;\n });\n }\n return crossings;\n}\n\n/** A copy of `from` with every column re-ordered against both its neighbours, in the order given. */\nfunction sweep(from: Arrangement, sequence: readonly number[], ctx: ColumnsContext): Arrangement {\n const next: Arrangement = { order: new Map(from.order), placed: new Map(from.placed), boxes: new Map(from.boxes) };\n for (const level of sequence) {\n const index = ctx.levels.indexOf(level);\n const adjacent = [ctx.levels[index - 1], ctx.levels[index + 1]].filter((other): other is number => other !== undefined);\n placeColumn(level, adjacent, ctx, next);\n }\n return next;\n}\n\n/**\n * Orders the columns. The first pass places the level nearest 0 and works\n * outward, ordering each column against the one just placed. Then up to\n * `sweeps` passes re-order every column against both its neighbours, inward\n * then outward, and the arrangement with the fewest crossings is kept: the\n * first pass's unless a later one strictly beats it.\n */\nfunction arrange(columns: ReadonlyMap<number, ColumnsLayoutNode[]>, ctx: ColumnsContext): Arrangement {\n let current: Arrangement = { order: new Map(columns), placed: new Map(), boxes: new Map() };\n for (const [level, reference] of placementOrder(ctx.levels)) {\n placeColumn(level, reference === undefined ? [] : [reference], ctx, current);\n }\n let best = current;\n let fewest = countCrossings(ctx, best.placed);\n for (let pass = 0; pass < ctx.m.sweeps && fewest > 0; pass++) {\n current = sweep(current, pass % 2 === 0 ? [...ctx.levels].reverse() : ctx.levels, ctx);\n const crossings = countCrossings(ctx, current.placed);\n if (crossings < fewest) {\n best = current;\n fewest = crossings;\n }\n }\n return best;\n}\n\n/**\n * Places nodes in left-to-right columns by `level` (the lowest level first),\n * stacking each column top to bottom and centring it against the tallest one.\n *\n * Within a column, nodes of one group are contiguous, groups appearing in the\n * order they first occur in `nodes`. Inside a group nodes are ordered by the\n * mean y of their neighbours in the adjacent columns, so edges between columns\n * cross less (see `arrange`); nodes with no neighbour there go last, and ties\n * keep input order.\n *\n * Returns node centres plus one rectangle per (column, group). Extra width is\n * reserved on each side for the loops `routeEdges` draws outside the first and\n * last columns.\n */\nexport function columnsLayout(\n nodes: readonly ColumnsLayoutNode[],\n edges: readonly GraphLayoutEdge[],\n options: ColumnsLayoutOptions = {},\n): ColumnsLayoutResult {\n const m = columnMetrics(options);\n const { columns, groupRank } = indexColumns(nodes);\n const neighbours = indexNeighbours(nodes, edges);\n const levels = [...columns.keys()].sort((a, b) => a - b);\n if (levels.length === 0) {\n return { width: 2 * m.padding, height: 2 * m.padding, positions: {}, groups: [] };\n }\n\n const minLevel = Math.min(...levels);\n const tallest = Math.max(...[...columns.values()].map((column) => columnHeight(column, m)));\n const inset = m.padding + (nodes.some((node) => node.group !== undefined) ? m.groupPadding : 0);\n const { placed, boxes } = arrange(columns, {\n m,\n levels,\n levelOf: new Map(nodes.map((node) => [node.id, node.level])),\n groupRank,\n neighbours,\n edges,\n origin: (level) => ({\n x: inset + m.nodeWidth / 2 + (level - minLevel) * (m.nodeWidth + m.columnGap),\n top: m.padding + (tallest - columnHeight(mustGet(columns, level, \"column\"), m)) / 2,\n level,\n }),\n });\n\n const nodeHeights = Object.fromEntries(nodes.filter((node) => node.compact).map((node) => [node.id, m.compactNodeHeight]));\n const room = loopOverhang(edges, Object.fromEntries(placed), { ...m, nodeHeights });\n const span = (Math.max(...levels) - minLevel) * (m.nodeWidth + m.columnGap) + m.nodeWidth;\n return {\n width: room.left + 2 * inset + span + room.right,\n height: tallest + 2 * m.padding,\n positions: Object.fromEntries([...placed].map(([id, { x, y }]) => [id, { x: x + room.left, y }])),\n groups: [...boxes.values()]\n .flat()\n .map((box) => ({ ...box, x: box.x + room.left }))\n .sort((a, b) => a.level - b.level || a.y - b.y),\n };\n}\n"],"names":[],"mappings":";AAgBO,MAAM,sBAAsB;AAEnC,MAAM,6BAA6B;AAuGnC,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;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AAS,OAAO,QAAQ,GAAG,CAAC,KAAK;AAAA,MAClF;AAAA,IAAA;AAAA,EACF,CACD;AAED,QAAM,cAAc,OAAO,YAAY,MAAM,OAAO,CAAC,SAAS,KAAK,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,iBAAiB,CAAC,CAAC;AACzH,QAAM,OAAO,aAAa,OAAO,OAAO,YAAY,MAAM,GAAG,EAAE,GAAG,GAAG,aAAa;AAClF,QAAM,QAAQ,KAAK,IAAI,GAAG,MAAM,IAAI,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE;AAChF,SAAO;AAAA,IACL,OAAO,KAAK,OAAO,IAAI,QAAQ,OAAO,KAAK;AAAA,IAC3C,QAAQ,UAAU,IAAI,EAAE;AAAA,IACxB,WAAW,OAAO,YAAY,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,KAAK,MAAM,EAAA,CAAG,CAAC,CAAC;AAAA,IAChG,QAAQ,CAAC,GAAG,MAAM,QAAQ,EACvB,KAAA,EACA,IAAI,CAAC,SAAS,EAAE,GAAG,KAAK,GAAG,IAAI,IAAI,KAAK,KAAA,EAAO,EAC/C,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAAA,EAAA;AAEpD;"}
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function groupName(group, id) {
4
+ if ((group == null ? void 0 : group.title) !== void 0) return group.title;
5
+ return typeof (group == null ? void 0 : group.label) === "string" ? group.label : id;
6
+ }
3
7
  const DENSE_EDGE_COUNT = 32;
4
8
  function edgeFocusOn(mode, edgeCount) {
5
9
  return mode === "on" || mode === "auto" && edgeCount > DENSE_EDGE_COUNT;
@@ -67,6 +71,7 @@ exports.edgeFocusOn = edgeFocusOn;
67
71
  exports.edgeLabelWidth = edgeLabelWidth;
68
72
  exports.edgeName = edgeName;
69
73
  exports.focusedEdgeIds = focusedEdgeIds;
74
+ exports.groupName = groupName;
70
75
  exports.hoverHandlers = hoverHandlers;
71
76
  exports.nodeName = nodeName;
72
77
  exports.requireEntry = requireEntry;
@@ -1 +1 @@
1
- {"version":3,"file":"graph-diagram-model.cjs","sources":["../../src/data/graph-diagram-model.ts"],"sourcesContent":["import type { KeyboardEvent, ReactNode } from \"react\";\nimport type { BadgeTone } from \"./Badge\";\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphDiagramNode {\n id: string;\n label: ReactNode;\n /** Drawn before the label, on the same line. Give the icon its own `title` so it names itself. */\n icon?: ReactNode;\n detail?: ReactNode;\n badge?: ReactNode;\n tone?: BadgeTone;\n shape?: \"pill\" | \"rect\";\n /** Accessible name for the node, when `label` alone isn't enough. */\n ariaLabel?: string;\n /** Full text for the node, shown as its native tooltip. */\n title?: string;\n /** Column of the node. Required by the \"columns\" layout; may be negative. */\n level?: number;\n /** \"columns\" layout: nodes sharing a group are stacked together and boxed. */\n group?: string;\n /**\n * \"columns\" layout: \"compact\" draws the node on one short line at `compactNodeHeight`, its icon and\n * label only, for a member its group box already names the owner of. Defaults to \"regular\".\n */\n size?: \"regular\" | \"compact\";\n /** Dimmed styling, for a node that leads nowhere further: external, unresolved, not expandable. */\n muted?: boolean;\n /** Neighbours not drawn yet. Renders a `+N` control on the node's outer side. */\n expandCount?: number;\n}\n\nexport interface GraphDiagramEdge {\n id: string;\n from: string;\n to: string;\n /** Short text shown in a pill on the edge. */\n label?: string;\n /** Drawn in the pill before the label. An edge with an icon and no label still gets a pill. */\n icon?: ReactNode;\n /** What `icon` says, in words. It precedes the label in the edge's accessible name. */\n iconLabel?: string;\n /** Full text for the edge, shown as its native tooltip. */\n title?: string;\n tone?: BadgeTone;\n dashed?: boolean;\n}\n\nexport interface GraphDiagramGroup {\n id: string;\n label: ReactNode;\n /** Full text for the group, shown as its caption's native tooltip: what a shortened `label` stands for. */\n title?: string;\n}\n\nexport type GraphDiagramLayout = \"ring\" | \"columns\";\n\n/**\n * Whether edges compete for attention or take turns. With focus on, an edge\n * shows its label pill only while it is in focus — selected, hovered, or\n * attached to the selected or hovered node — and while anything is in focus\n * the other edges fade. \"auto\" turns it on past `DENSE_EDGE_COUNT` edges.\n */\nexport type GraphDiagramEdgeFocus = \"auto\" | \"on\" | \"off\";\n\n/** The most edges a diagram draws with every pill showing under `edgeFocus=\"auto\"`. */\nexport const DENSE_EDGE_COUNT = 32;\n\nexport function edgeFocusOn(mode: GraphDiagramEdgeFocus, edgeCount: number): boolean {\n return mode === \"on\" || (mode === \"auto\" && edgeCount > DENSE_EDGE_COUNT);\n}\n\n/** The edges in focus: the named ones, and every edge attached to a named node. */\nexport function focusedEdgeIds(\n edges: readonly { id: string; from: string; to: string }[],\n focus: { nodes: readonly (string | undefined)[]; edges: readonly (string | undefined)[] },\n): Set<string> {\n return new Set(\n edges\n .filter((edge) => focus.edges.includes(edge.id) || focus.nodes.includes(edge.from) || focus.nodes.includes(edge.to))\n .map((edge) => edge.id),\n );\n}\n\n/** Maps a point in layout coordinates to the CSS offsets of the stage it is drawn on. */\nexport type GraphPlacer = (point: GraphLayoutPosition) => { left: number | string; top: number | string };\n\nexport const TONE_TEXT_CLASS: Record<BadgeTone, string> = {\n neutral: \"text-muted-foreground\",\n success: \"text-emerald-600 dark:text-emerald-400\",\n danger: \"text-red-600 dark:text-red-400\",\n warning: \"text-amber-600 dark:text-amber-400\",\n info: \"text-sky-600 dark:text-sky-400\",\n};\n\nexport const TONE_NODE_CLASS: Record<BadgeTone, string> = {\n neutral: \"border-border bg-card text-foreground\",\n success: \"border-emerald-500/50 bg-emerald-500/10 text-foreground\",\n danger: \"border-red-500/50 bg-red-500/10 text-foreground\",\n warning: \"border-amber-500/50 bg-amber-500/10 text-foreground\",\n info: \"border-sky-500/50 bg-sky-500/10 text-foreground\",\n};\n\n/** The node's accessible name: its `ariaLabel`, else a plain-text label, else its id. */\nexport function nodeName(node: GraphDiagramNode): string {\n if (node.ariaLabel !== undefined) return node.ariaLabel;\n return typeof node.label === \"string\" ? node.label : node.id;\n}\n\n/** A selectable edge's accessible name: `<from> to <to>`, then what its pill shows, in words. */\nexport function edgeName(edge: GraphDiagramEdge, names: Record<string, string>): string {\n const ends = `${requireEntry(names, edge.from, \"node name\")} to ${requireEntry(names, edge.to, \"node name\")}`;\n const pill = [edge.iconLabel, edge.label].filter(Boolean).join(\" \");\n return pill === \"\" ? ends : `${ends}: ${pill}`;\n}\n\n// A pill is not measured: its size is estimated from its content, at the mean\n// glyph advance of its 10px medium label plus its padding and border.\nconst LABEL_CHAR_WIDTH = 5.4;\nconst LABEL_CHROME = 14;\n// The pill's icon slot (`text-sm`, so a 1em icon is 14px) and its `gap-1` to the text.\nconst LABEL_ICON_SIZE = 14;\nconst LABEL_ICON_GAP = 4;\n\n/** Estimated px width of an edge's pill. An icon counts as a fixed width, whatever it draws. */\nexport function edgeLabelWidth(edge: GraphDiagramEdge): number {\n const icon = edge.icon == null ? 0 : LABEL_ICON_SIZE + (edge.label ? LABEL_ICON_GAP : 0);\n return (edge.label?.length ?? 0) * LABEL_CHAR_WIDTH + icon + LABEL_CHROME;\n}\n\nexport function requireEntry<T>(entries: Record<string, T>, id: string, what: string): T {\n const entry = entries[id];\n if (entry === undefined) {\n throw new Error(`GraphDiagram: no ${what} computed for \"${id}\"`);\n }\n return entry;\n}\n\n/** Props that report an element as hovered while the pointer is over it or the keyboard focus is inside it. */\nexport function hoverHandlers(id: string, onHover: (id: string | undefined) => void) {\n const enter = () => onHover(id);\n const leave = () => onHover(undefined);\n return { onMouseEnter: enter, onMouseLeave: leave, onFocus: enter, onBlur: leave };\n}\n\n/** Enter and Space activate a focused `role=\"button\"` element, as they do a native button. */\nexport function activateOnKey(event: KeyboardEvent<Element>, activate: () => void): void {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n activate();\n }\n}\n"],"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AO;AAC/D;AAEO,SAAS,aAAgB,SAA4B,IAAY,MAAiB;AACvF,QAAM,QAAQ,QAAQ,EAAE;AACxB,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,oBAAoB,IAAI,kBAAkB,EAAE,GAAG;AAAA,EACjE;AACA,SAAO;AACT;AAGO,SAAS,cAAc,IAAY,SAA2C;AACnF,QAAM,QAAQ,MAAM,QAAQ,EAAE;AAC9B,QAAM,QAAQ,MAAM,QAAQ,MAAS;AACrC,SAAO,EAAE,cAAc,OAAO,cAAc,OAAO,SAAS,OAAO,QAAQ,MAAA;AAC7E;AAGO,SAAS,cAAc,OAA+B,UAA4B;AACvF,MAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;AAC9C,UAAM,eAAA;AACN,aAAA;AAAA,EACF;AACF;;;;;;;;;;;;"}
1
+ {"version":3,"file":"graph-diagram-model.cjs","sources":["../../src/data/graph-diagram-model.ts"],"sourcesContent":["import type { KeyboardEvent, ReactNode } from \"react\";\nimport type { BadgeTone } from \"./Badge\";\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphDiagramNode {\n id: string;\n label: ReactNode;\n /** Drawn before the label, on the same line. Give the icon its own `title` so it names itself. */\n icon?: ReactNode;\n /** Right-aligned content on a record row, such as a column type. */\n aside?: ReactNode;\n /**\n * A small mark at the end of the node's line, such as how it is accessed (see `AccessMark`). It is\n * hidden from assistive technology, so the node's accessible name stays its own: give it a title.\n */\n mark?: ReactNode;\n detail?: ReactNode;\n badge?: ReactNode;\n tone?: BadgeTone;\n shape?: \"pill\" | \"rect\";\n /** Accessible name for the node, when `label` alone isn't enough. */\n ariaLabel?: string;\n /** Full text for the node, shown as its native tooltip. */\n title?: string;\n /** Column of the node. Required by the \"columns\" layout; may be negative. */\n level?: number;\n /** \"columns\" layout: nodes sharing a group are stacked together and boxed. */\n group?: string;\n /**\n * \"columns\" layout: \"compact\" draws the node on one short line at `compactNodeHeight`, its icon and\n * label only, for a member its group box already names the owner of. Defaults to \"regular\".\n */\n size?: \"regular\" | \"compact\";\n /** Dimmed styling, for a node that leads nowhere further: external, unresolved, not expandable. */\n muted?: boolean;\n /** Neighbours not drawn yet. Renders a `+N` control on the node's outer side. */\n expandCount?: number;\n}\n\nexport interface GraphDiagramEdge {\n id: string;\n from: string;\n to: string;\n /** Short text shown in a pill on the edge. */\n label?: string;\n /** Drawn in the pill before the label. An edge with an icon and no label still gets a pill. */\n icon?: ReactNode;\n /** What `icon` says, in words. It precedes the label in the edge's accessible name. */\n iconLabel?: string;\n /** Full text for the edge, shown as its native tooltip. */\n title?: string;\n tone?: BadgeTone;\n dashed?: boolean;\n}\n\nexport interface GraphDiagramGroup {\n id: string;\n label: ReactNode;\n /** A record draws a header and flush compact member rows. Defaults to a box. */\n variant?: \"box\" | \"record\";\n /** Full text for the group, shown as its caption's native tooltip: what a shortened `label` stands for. */\n title?: string;\n /**\n * \"columns\" layout: whether the group is drawn as its header alone. Set (true or false) to make it\n * collapsible: its header then shows a chevron calling `onGroupToggle`. A collapsed group holds one\n * node, the stand-in its edges attach to, which is not drawn: its header stands for it.\n */\n collapsed?: boolean;\n /** Right-aligned content in the group's header, such as what a collapsed group holds. */\n aside?: ReactNode;\n}\n\n/** The group's name in words: its title, else a plain-text label, else its id. */\nexport function groupName(group: GraphDiagramGroup | undefined, id: string): string {\n if (group?.title !== undefined) return group.title;\n return typeof group?.label === \"string\" ? group.label : id;\n}\n\nexport type GraphDiagramLayout = \"ring\" | \"columns\";\n\n/**\n * Whether edges compete for attention or take turns. With focus on, an edge\n * shows its label pill only while it is in focus — selected, hovered, or\n * attached to the selected or hovered node — and while anything is in focus\n * the other edges fade. \"auto\" turns it on past `DENSE_EDGE_COUNT` edges.\n */\nexport type GraphDiagramEdgeFocus = \"auto\" | \"on\" | \"off\";\n\n/** The most edges a diagram draws with every pill showing under `edgeFocus=\"auto\"`. */\nexport const DENSE_EDGE_COUNT = 32;\n\nexport function edgeFocusOn(mode: GraphDiagramEdgeFocus, edgeCount: number): boolean {\n return mode === \"on\" || (mode === \"auto\" && edgeCount > DENSE_EDGE_COUNT);\n}\n\n/** The edges in focus: the named ones, and every edge attached to a named node. */\nexport function focusedEdgeIds(\n edges: readonly { id: string; from: string; to: string }[],\n focus: { nodes: readonly (string | undefined)[]; edges: readonly (string | undefined)[] },\n): Set<string> {\n return new Set(\n edges\n .filter((edge) => focus.edges.includes(edge.id) || focus.nodes.includes(edge.from) || focus.nodes.includes(edge.to))\n .map((edge) => edge.id),\n );\n}\n\n/** Maps a point in layout coordinates to the CSS offsets of the stage it is drawn on. */\nexport type GraphPlacer = (point: GraphLayoutPosition) => { left: number | string; top: number | string };\n\nexport const TONE_TEXT_CLASS: Record<BadgeTone, string> = {\n neutral: \"text-muted-foreground\",\n success: \"text-emerald-600 dark:text-emerald-400\",\n danger: \"text-red-600 dark:text-red-400\",\n warning: \"text-amber-600 dark:text-amber-400\",\n info: \"text-sky-600 dark:text-sky-400\",\n};\n\nexport const TONE_NODE_CLASS: Record<BadgeTone, string> = {\n neutral: \"border-border bg-card text-foreground\",\n success: \"border-emerald-500/50 bg-emerald-500/10 text-foreground\",\n danger: \"border-red-500/50 bg-red-500/10 text-foreground\",\n warning: \"border-amber-500/50 bg-amber-500/10 text-foreground\",\n info: \"border-sky-500/50 bg-sky-500/10 text-foreground\",\n};\n\n/** The node's accessible name: its `ariaLabel`, else a plain-text label, else its id. */\nexport function nodeName(node: GraphDiagramNode): string {\n if (node.ariaLabel !== undefined) return node.ariaLabel;\n return typeof node.label === \"string\" ? node.label : node.id;\n}\n\n/** A selectable edge's accessible name: `<from> to <to>`, then what its pill shows, in words. */\nexport function edgeName(edge: GraphDiagramEdge, names: Record<string, string>): string {\n const ends = `${requireEntry(names, edge.from, \"node name\")} to ${requireEntry(names, edge.to, \"node name\")}`;\n const pill = [edge.iconLabel, edge.label].filter(Boolean).join(\" \");\n return pill === \"\" ? ends : `${ends}: ${pill}`;\n}\n\n// A pill is not measured: its size is estimated from its content, at the mean\n// glyph advance of its 10px medium label plus its padding and border.\nconst LABEL_CHAR_WIDTH = 5.4;\nconst LABEL_CHROME = 14;\n// The pill's icon slot (`text-sm`, so a 1em icon is 14px) and its `gap-1` to the text.\nconst LABEL_ICON_SIZE = 14;\nconst LABEL_ICON_GAP = 4;\n\n/** Estimated px width of an edge's pill. An icon counts as a fixed width, whatever it draws. */\nexport function edgeLabelWidth(edge: GraphDiagramEdge): number {\n const icon = edge.icon == null ? 0 : LABEL_ICON_SIZE + (edge.label ? LABEL_ICON_GAP : 0);\n return (edge.label?.length ?? 0) * LABEL_CHAR_WIDTH + icon + LABEL_CHROME;\n}\n\nexport function requireEntry<T>(entries: Record<string, T>, id: string, what: string): T {\n const entry = entries[id];\n if (entry === undefined) {\n throw new Error(`GraphDiagram: no ${what} computed for \"${id}\"`);\n }\n return entry;\n}\n\n/** Props that report an element as hovered while the pointer is over it or the keyboard focus is inside it. */\nexport function hoverHandlers(id: string, onHover: (id: string | undefined) => void) {\n const enter = () => onHover(id);\n const leave = () => onHover(undefined);\n return { onMouseEnter: enter, onMouseLeave: leave, onFocus: enter, onBlur: leave };\n}\n\n/** Enter and Space activate a focused `role=\"button\"` element, as they do a native button. */\nexport function activateOnKey(event: KeyboardEvent<Element>, activate: () => void): void {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n activate();\n }\n}\n"],"names":[],"mappings":";;AAyEO,SAAS,UAAU,OAAsC,IAAoB;AAClF,OAAI,+BAAO,WAAU,OAAW,QAAO,MAAM;AAC7C,SAAO,QAAO,+BAAO,WAAU,WAAW,MAAM,QAAQ;AAC1D;AAaO,MAAM,mBAAmB;AAEzB,SAAS,YAAY,MAA6B,WAA4B;AACnF,SAAO,SAAS,QAAS,SAAS,UAAU,YAAY;AAC1D;AAGO,SAAS,eACd,OACA,OACa;AACb,SAAO,IAAI;AAAA,IACT,MACG,OAAO,CAAC,SAAS,MAAM,MAAM,SAAS,KAAK,EAAE,KAAK,MAAM,MAAM,S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MAAM,QAAQ,EAAE;AAC9B,QAAM,QAAQ,MAAM,QAAQ,MAAS;AACrC,SAAO,EAAE,cAAc,OAAO,cAAc,OAAO,SAAS,OAAO,QAAQ,MAAA;AAC7E;AAGO,SAAS,cAAc,OAA+B,UAA4B;AACvF,MAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;AAC9C,UAAM,eAAA;AACN,aAAA;AAAA,EACF;AACF;;;;;;;;;;;;;"}
@@ -6,6 +6,13 @@ export interface GraphDiagramNode {
6
6
  label: ReactNode;
7
7
  /** Drawn before the label, on the same line. Give the icon its own `title` so it names itself. */
8
8
  icon?: ReactNode;
9
+ /** Right-aligned content on a record row, such as a column type. */
10
+ aside?: ReactNode;
11
+ /**
12
+ * A small mark at the end of the node's line, such as how it is accessed (see `AccessMark`). It is
13
+ * hidden from assistive technology, so the node's accessible name stays its own: give it a title.
14
+ */
15
+ mark?: ReactNode;
9
16
  detail?: ReactNode;
10
17
  badge?: ReactNode;
11
18
  tone?: BadgeTone;
@@ -46,9 +53,21 @@ export interface GraphDiagramEdge {
46
53
  export interface GraphDiagramGroup {
47
54
  id: string;
48
55
  label: ReactNode;
56
+ /** A record draws a header and flush compact member rows. Defaults to a box. */
57
+ variant?: "box" | "record";
49
58
  /** Full text for the group, shown as its caption's native tooltip: what a shortened `label` stands for. */
50
59
  title?: string;
60
+ /**
61
+ * "columns" layout: whether the group is drawn as its header alone. Set (true or false) to make it
62
+ * collapsible: its header then shows a chevron calling `onGroupToggle`. A collapsed group holds one
63
+ * node, the stand-in its edges attach to, which is not drawn: its header stands for it.
64
+ */
65
+ collapsed?: boolean;
66
+ /** Right-aligned content in the group's header, such as what a collapsed group holds. */
67
+ aside?: ReactNode;
51
68
  }
69
+ /** The group's name in words: its title, else a plain-text label, else its id. */
70
+ export declare function groupName(group: GraphDiagramGroup | undefined, id: string): string;
52
71
  export type GraphDiagramLayout = "ring" | "columns";
53
72
  /**
54
73
  * Whether edges compete for attention or take turns. With focus on, an edge
@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AC,GAAG,MAAM,CAItF;AAUD,gGAAgG;AAChG,wBAAgB,cAAc,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAG7D;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAMvF;AAED,+GAA+G;AAC/G,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI;;;;;EAIlF;AAED,8FAA8F;AAC9F,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAKvF"}
@@ -1,3 +1,7 @@
1
+ function groupName(group, id) {
2
+ if ((group == null ? void 0 : group.title) !== void 0) return group.title;
3
+ return typeof (group == null ? void 0 : group.label) === "string" ? group.label : id;
4
+ }
1
5
  const DENSE_EDGE_COUNT = 32;
2
6
  function edgeFocusOn(mode, edgeCount) {
3
7
  return mode === "on" || mode === "auto" && edgeCount > DENSE_EDGE_COUNT;
@@ -66,6 +70,7 @@ export {
66
70
  edgeLabelWidth,
67
71
  edgeName,
68
72
  focusedEdgeIds,
73
+ groupName,
69
74
  hoverHandlers,
70
75
  nodeName,
71
76
  requireEntry
@@ -1 +1 @@
1
- {"version":3,"file":"graph-diagram-model.js","sources":["../../src/data/graph-diagram-model.ts"],"sourcesContent":["import type { KeyboardEvent, ReactNode } from \"react\";\nimport type { BadgeTone } from \"./Badge\";\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphDiagramNode {\n id: string;\n label: ReactNode;\n /** Drawn before the label, on the same line. Give the icon its own `title` so it names itself. */\n icon?: ReactNode;\n detail?: ReactNode;\n badge?: ReactNode;\n tone?: BadgeTone;\n shape?: \"pill\" | \"rect\";\n /** Accessible name for the node, when `label` alone isn't enough. */\n ariaLabel?: string;\n /** Full text for the node, shown as its native tooltip. */\n title?: string;\n /** Column of the node. Required by the \"columns\" layout; may be negative. */\n level?: number;\n /** \"columns\" layout: nodes sharing a group are stacked together and boxed. */\n group?: string;\n /**\n * \"columns\" layout: \"compact\" draws the node on one short line at `compactNodeHeight`, its icon and\n * label only, for a member its group box already names the owner of. Defaults to \"regular\".\n */\n size?: \"regular\" | \"compact\";\n /** Dimmed styling, for a node that leads nowhere further: external, unresolved, not expandable. */\n muted?: boolean;\n /** Neighbours not drawn yet. Renders a `+N` control on the node's outer side. */\n expandCount?: number;\n}\n\nexport interface GraphDiagramEdge {\n id: string;\n from: string;\n to: string;\n /** Short text shown in a pill on the edge. */\n label?: string;\n /** Drawn in the pill before the label. An edge with an icon and no label still gets a pill. */\n icon?: ReactNode;\n /** What `icon` says, in words. It precedes the label in the edge's accessible name. */\n iconLabel?: string;\n /** Full text for the edge, shown as its native tooltip. */\n title?: string;\n tone?: BadgeTone;\n dashed?: boolean;\n}\n\nexport interface GraphDiagramGroup {\n id: string;\n label: ReactNode;\n /** Full text for the group, shown as its caption's native tooltip: what a shortened `label` stands for. */\n title?: string;\n}\n\nexport type GraphDiagramLayout = \"ring\" | \"columns\";\n\n/**\n * Whether edges compete for attention or take turns. With focus on, an edge\n * shows its label pill only while it is in focus — selected, hovered, or\n * attached to the selected or hovered node — and while anything is in focus\n * the other edges fade. \"auto\" turns it on past `DENSE_EDGE_COUNT` edges.\n */\nexport type GraphDiagramEdgeFocus = \"auto\" | \"on\" | \"off\";\n\n/** The most edges a diagram draws with every pill showing under `edgeFocus=\"auto\"`. */\nexport const DENSE_EDGE_COUNT = 32;\n\nexport function edgeFocusOn(mode: GraphDiagramEdgeFocus, edgeCount: number): boolean {\n return mode === \"on\" || (mode === \"auto\" && edgeCount > DENSE_EDGE_COUNT);\n}\n\n/** The edges in focus: the named ones, and every edge attached to a named node. */\nexport function focusedEdgeIds(\n edges: readonly { id: string; from: string; to: string }[],\n focus: { nodes: readonly (string | undefined)[]; edges: readonly (string | undefined)[] },\n): Set<string> {\n return new Set(\n edges\n .filter((edge) => focus.edges.includes(edge.id) || focus.nodes.includes(edge.from) || focus.nodes.includes(edge.to))\n .map((edge) => edge.id),\n );\n}\n\n/** Maps a point in layout coordinates to the CSS offsets of the stage it is drawn on. */\nexport type GraphPlacer = (point: GraphLayoutPosition) => { left: number | string; top: number | string };\n\nexport const TONE_TEXT_CLASS: Record<BadgeTone, string> = {\n neutral: \"text-muted-foreground\",\n success: \"text-emerald-600 dark:text-emerald-400\",\n danger: \"text-red-600 dark:text-red-400\",\n warning: \"text-amber-600 dark:text-amber-400\",\n info: \"text-sky-600 dark:text-sky-400\",\n};\n\nexport const TONE_NODE_CLASS: Record<BadgeTone, string> = {\n neutral: \"border-border bg-card text-foreground\",\n success: \"border-emerald-500/50 bg-emerald-500/10 text-foreground\",\n danger: \"border-red-500/50 bg-red-500/10 text-foreground\",\n warning: \"border-amber-500/50 bg-amber-500/10 text-foreground\",\n info: \"border-sky-500/50 bg-sky-500/10 text-foreground\",\n};\n\n/** The node's accessible name: its `ariaLabel`, else a plain-text label, else its id. */\nexport function nodeName(node: GraphDiagramNode): string {\n if (node.ariaLabel !== undefined) return node.ariaLabel;\n return typeof node.label === \"string\" ? node.label : node.id;\n}\n\n/** A selectable edge's accessible name: `<from> to <to>`, then what its pill shows, in words. */\nexport function edgeName(edge: GraphDiagramEdge, names: Record<string, string>): string {\n const ends = `${requireEntry(names, edge.from, \"node name\")} to ${requireEntry(names, edge.to, \"node name\")}`;\n const pill = [edge.iconLabel, edge.label].filter(Boolean).join(\" \");\n return pill === \"\" ? ends : `${ends}: ${pill}`;\n}\n\n// A pill is not measured: its size is estimated from its content, at the mean\n// glyph advance of its 10px medium label plus its padding and border.\nconst LABEL_CHAR_WIDTH = 5.4;\nconst LABEL_CHROME = 14;\n// The pill's icon slot (`text-sm`, so a 1em icon is 14px) and its `gap-1` to the text.\nconst LABEL_ICON_SIZE = 14;\nconst LABEL_ICON_GAP = 4;\n\n/** Estimated px width of an edge's pill. An icon counts as a fixed width, whatever it draws. */\nexport function edgeLabelWidth(edge: GraphDiagramEdge): number {\n const icon = edge.icon == null ? 0 : LABEL_ICON_SIZE + (edge.label ? LABEL_ICON_GAP : 0);\n return (edge.label?.length ?? 0) * LABEL_CHAR_WIDTH + icon + LABEL_CHROME;\n}\n\nexport function requireEntry<T>(entries: Record<string, T>, id: string, what: string): T {\n const entry = entries[id];\n if (entry === undefined) {\n throw new Error(`GraphDiagram: no ${what} computed for \"${id}\"`);\n }\n return entry;\n}\n\n/** Props that report an element as hovered while the pointer is over it or the keyboard focus is inside it. */\nexport function hoverHandlers(id: string, onHover: (id: string | undefined) => void) {\n const enter = () => onHover(id);\n const leave = () => onHover(undefined);\n return { onMouseEnter: enter, onMouseLeave: leave, onFocus: enter, onBlur: leave };\n}\n\n/** Enter and Space activate a focused `role=\"button\"` element, as they do a native button. */\nexport function activateOnKey(event: KeyboardEvent<Element>, activate: () => void): void {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n activate();\n }\n}\n"],"names":[],"mappings":"AAkEO,MAAM,mBAAmB;AAEzB,SAAS,YAAY,MAA6B,WAA4B;AACnF,SAAO,SAAS,QAAS,SAAS,UAAU,YAAY;AAC1D;AAGO,SAAS,eACd,OACA,OACa;AACb,SAAO,IAAI;AAAA,IACT,MACG,OAAO,CAAC,SAAS,MAAM,MAAM,SAAS,KAAK,EAAE,KAAK,MAAM,MAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,KAAK,EAAE,CAAC,EAClH,IAAI,CAAC,SAAS,KAAK,EAAE;AAAA,EAAA;AAE5B;AAKO,MAAM,kBAA6C;AAAA,EACxD,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACR;AAEO,MAAM,kBAA6C;AAAA,EACxD,SAAS;AAAA,EACT,SAAS;AAA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"file":"graph-diagram-model.js","sources":["../../src/data/graph-diagram-model.ts"],"sourcesContent":["import type { KeyboardEvent, ReactNode } from \"react\";\nimport type { BadgeTone } from \"./Badge\";\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nexport interface GraphDiagramNode {\n id: string;\n label: ReactNode;\n /** Drawn before the label, on the same line. Give the icon its own `title` so it names itself. */\n icon?: ReactNode;\n /** Right-aligned content on a record row, such as a column type. */\n aside?: ReactNode;\n /**\n * A small mark at the end of the node's line, such as how it is accessed (see `AccessMark`). It is\n * hidden from assistive technology, so the node's accessible name stays its own: give it a title.\n */\n mark?: ReactNode;\n detail?: ReactNode;\n badge?: ReactNode;\n tone?: BadgeTone;\n shape?: \"pill\" | \"rect\";\n /** Accessible name for the node, when `label` alone isn't enough. */\n ariaLabel?: string;\n /** Full text for the node, shown as its native tooltip. */\n title?: string;\n /** Column of the node. Required by the \"columns\" layout; may be negative. */\n level?: number;\n /** \"columns\" layout: nodes sharing a group are stacked together and boxed. */\n group?: string;\n /**\n * \"columns\" layout: \"compact\" draws the node on one short line at `compactNodeHeight`, its icon and\n * label only, for a member its group box already names the owner of. Defaults to \"regular\".\n */\n size?: \"regular\" | \"compact\";\n /** Dimmed styling, for a node that leads nowhere further: external, unresolved, not expandable. */\n muted?: boolean;\n /** Neighbours not drawn yet. Renders a `+N` control on the node's outer side. */\n expandCount?: number;\n}\n\nexport interface GraphDiagramEdge {\n id: string;\n from: string;\n to: string;\n /** Short text shown in a pill on the edge. */\n label?: string;\n /** Drawn in the pill before the label. An edge with an icon and no label still gets a pill. */\n icon?: ReactNode;\n /** What `icon` says, in words. It precedes the label in the edge's accessible name. */\n iconLabel?: string;\n /** Full text for the edge, shown as its native tooltip. */\n title?: string;\n tone?: BadgeTone;\n dashed?: boolean;\n}\n\nexport interface GraphDiagramGroup {\n id: string;\n label: ReactNode;\n /** A record draws a header and flush compact member rows. Defaults to a box. */\n variant?: \"box\" | \"record\";\n /** Full text for the group, shown as its caption's native tooltip: what a shortened `label` stands for. */\n title?: string;\n /**\n * \"columns\" layout: whether the group is drawn as its header alone. Set (true or false) to make it\n * collapsible: its header then shows a chevron calling `onGroupToggle`. A collapsed group holds one\n * node, the stand-in its edges attach to, which is not drawn: its header stands for it.\n */\n collapsed?: boolean;\n /** Right-aligned content in the group's header, such as what a collapsed group holds. */\n aside?: ReactNode;\n}\n\n/** The group's name in words: its title, else a plain-text label, else its id. */\nexport function groupName(group: GraphDiagramGroup | undefined, id: string): string {\n if (group?.title !== undefined) return group.title;\n return typeof group?.label === \"string\" ? group.label : id;\n}\n\nexport type GraphDiagramLayout = \"ring\" | \"columns\";\n\n/**\n * Whether edges compete for attention or take turns. With focus on, an edge\n * shows its label pill only while it is in focus — selected, hovered, or\n * attached to the selected or hovered node — and while anything is in focus\n * the other edges fade. \"auto\" turns it on past `DENSE_EDGE_COUNT` edges.\n */\nexport type GraphDiagramEdgeFocus = \"auto\" | \"on\" | \"off\";\n\n/** The most edges a diagram draws with every pill showing under `edgeFocus=\"auto\"`. */\nexport const DENSE_EDGE_COUNT = 32;\n\nexport function edgeFocusOn(mode: GraphDiagramEdgeFocus, edgeCount: number): boolean {\n return mode === \"on\" || (mode === \"auto\" && edgeCount > DENSE_EDGE_COUNT);\n}\n\n/** The edges in focus: the named ones, and every edge attached to a named node. */\nexport function focusedEdgeIds(\n edges: readonly { id: string; from: string; to: string }[],\n focus: { nodes: readonly (string | undefined)[]; edges: readonly (string | undefined)[] },\n): Set<string> {\n return new Set(\n edges\n .filter((edge) => focus.edges.includes(edge.id) || focus.nodes.includes(edge.from) || focus.nodes.includes(edge.to))\n .map((edge) => edge.id),\n );\n}\n\n/** Maps a point in layout coordinates to the CSS offsets of the stage it is drawn on. */\nexport type GraphPlacer = (point: GraphLayoutPosition) => { left: number | string; top: number | string };\n\nexport const TONE_TEXT_CLASS: Record<BadgeTone, string> = {\n neutral: \"text-muted-foreground\",\n success: \"text-emerald-600 dark:text-emerald-400\",\n danger: \"text-red-600 dark:text-red-400\",\n warning: \"text-amber-600 dark:text-amber-400\",\n info: \"text-sky-600 dark:text-sky-400\",\n};\n\nexport const TONE_NODE_CLASS: Record<BadgeTone, string> = {\n neutral: \"border-border bg-card text-foreground\",\n success: \"border-emerald-500/50 bg-emerald-500/10 text-foreground\",\n danger: \"border-red-500/50 bg-red-500/10 text-foreground\",\n warning: \"border-amber-500/50 bg-amber-500/10 text-foreground\",\n info: \"border-sky-500/50 bg-sky-500/10 text-foreground\",\n};\n\n/** The node's accessible name: its `ariaLabel`, else a plain-text label, else its id. */\nexport function nodeName(node: GraphDiagramNode): string {\n if (node.ariaLabel !== undefined) return node.ariaLabel;\n return typeof node.label === \"string\" ? node.label : node.id;\n}\n\n/** A selectable edge's accessible name: `<from> to <to>`, then what its pill shows, in words. */\nexport function edgeName(edge: GraphDiagramEdge, names: Record<string, string>): string {\n const ends = `${requireEntry(names, edge.from, \"node name\")} to ${requireEntry(names, edge.to, \"node name\")}`;\n const pill = [edge.iconLabel, edge.label].filter(Boolean).join(\" \");\n return pill === \"\" ? ends : `${ends}: ${pill}`;\n}\n\n// A pill is not measured: its size is estimated from its content, at the mean\n// glyph advance of its 10px medium label plus its padding and border.\nconst LABEL_CHAR_WIDTH = 5.4;\nconst LABEL_CHROME = 14;\n// The pill's icon slot (`text-sm`, so a 1em icon is 14px) and its `gap-1` to the text.\nconst LABEL_ICON_SIZE = 14;\nconst LABEL_ICON_GAP = 4;\n\n/** Estimated px width of an edge's pill. An icon counts as a fixed width, whatever it draws. */\nexport function edgeLabelWidth(edge: GraphDiagramEdge): number {\n const icon = edge.icon == null ? 0 : LABEL_ICON_SIZE + (edge.label ? LABEL_ICON_GAP : 0);\n return (edge.label?.length ?? 0) * LABEL_CHAR_WIDTH + icon + LABEL_CHROME;\n}\n\nexport function requireEntry<T>(entries: Record<string, T>, id: string, what: string): T {\n const entry = entries[id];\n if (entry === undefined) {\n throw new Error(`GraphDiagram: no ${what} computed for \"${id}\"`);\n }\n return entry;\n}\n\n/** Props that report an element as hovered while the pointer is over it or the keyboard focus is inside it. */\nexport function hoverHandlers(id: string, onHover: (id: string | undefined) => void) {\n const enter = () => onHover(id);\n const leave = () => onHover(undefined);\n return { onMouseEnter: enter, onMouseLeave: leave, onFocus: enter, onBlur: leave };\n}\n\n/** Enter and Space activate a focused `role=\"button\"` element, as they do a native button. */\nexport function activateOnKey(event: KeyboardEvent<Element>, activate: () => void): void {\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n activate();\n }\n}\n"],"names":[],"mappings":"AAyEO,SAAS,UAAU,OAAsC,IAAoB;AAClF,OAAI,+BAAO,WAAU,OAAW,QAAO,MAAM;AAC7C,SAAO,QAAO,+BAAO,WAAU,WAAW,MAAM,QAAQ;AAC1D;AAaO,MAAM,mBAAmB;AAEzB,SAAS,YAAY,MAA6B,WAA4B;AACnF,SAAO,SAAS,QAAS,SAAS,UAAU,YAAY;AAC1D;AAGO,SAAS,eACd,OACA,OACa;AACb,SAAO,IAAI;AAAA,IACT,MACG,OAAO,CAAC,SAAS,MAAM,MAAM,SAAS,KAAK,EAAE,KAAK,MAAM,MAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,KAAK,EAAE,CAAC,EAClH,IAAI,CAAC,SAAS,KAAK,EAAE;AAAA,EAAA;AAE5B;AAKO,MAAM,kBAA6C;AAAA,EACxD,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACR;AAEO,MAAM,kBAA6C;AAAA,EACxD,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AACR;AAGO,SAAS,SAAS,MAAgC;AACvD,MAAI,KAAK,cAAc,OAAW,QAAO,KAAK;AAC9C,SAAO,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,KAAK;AAC5D;AAGO,SAAS,SAAS,MAAwB,OAAuC;AACtF,QAAM,OAAO,GAAG,aAAa,OAAO,KAAK,MAAM,WAAW,CAAC,OAAO,aAAa,OAAO,KAAK,IAAI,WAAW,CAAC;AAC3G,QAAM,OAAO,CAAC,KAAK,WAAW,KAAK,KAAK,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAClE,SAAO,SAAS,KAAK,OAAO,GAAG,IAAI,KAAK,IAAI;AAC9C;AAIA,MAAM,mBAAmB;AACzB,MAAM,eAAe;AAErB,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAGhB,SAAS,eAAe,MAAgC;AA3ExD;AA4EL,QAAM,OAAO,KAAK,QAAQ,OAAO,IAAI,mBAAmB,KAAK,QAAQ,iBAAiB;AACtF,YAAQ,UAAK,UAAL,mBAAY,WAAU,KAAK,mBAAmB,OAAO;AAC/D;AAEO,SAAS,aAAgB,SAA4B,IAAY,MAAiB;AACvF,QAAM,QAAQ,QAAQ,EAAE;AACxB,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,oBAAoB,IAAI,kBAAkB,EAAE,GAAG;AAAA,EACjE;AACA,SAAO;AACT;AAGO,SAAS,cAAc,IAAY,SAA2C;AACnF,QAAM,QAAQ,MAAM,QAAQ,EAAE;AAC9B,QAAM,QAAQ,MAAM,QAAQ,MAAS;AACrC,SAAO,EAAE,cAAc,OAAO,cAAc,OAAO,SAAS,OAAO,QAAQ,MAAA;AAC7E;AAGO,SAAS,cAAc,OAA+B,UAA4B;AACvF,MAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,KAAK;AAC9C,UAAM,eAAA;AACN,aAAA;AAAA,EACF;AACF;"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function clampWindowStart(memberWindow, start) {
4
+ return Math.min(Math.max(0, memberWindow.members.length - memberWindow.rows), Math.max(0, Math.round(start)));
5
+ }
6
+ function revealWindowStart(memberWindow, start, id) {
7
+ const index = memberWindow.members.indexOf(id);
8
+ const current = clampWindowStart(memberWindow, start);
9
+ if (index < 0) return current;
10
+ if (index < current) return index;
11
+ return index >= current + memberWindow.rows ? clampWindowStart(memberWindow, index - memberWindow.rows + 1) : current;
12
+ }
13
+ function revealMember(boxes, starts, id) {
14
+ if (id === void 0) return starts;
15
+ const box = boxes.find((candidate) => {
16
+ var _a;
17
+ return (_a = candidate.window) == null ? void 0 : _a.members.includes(id);
18
+ });
19
+ if (!(box == null ? void 0 : box.window)) return starts;
20
+ const current = starts[box.id] ?? 0;
21
+ const next = revealWindowStart(box.window, current, id);
22
+ return next === clampWindowStart(box.window, current) ? starts : { ...starts, [box.id]: next };
23
+ }
24
+ function windowedPositions(positions, boxes, starts) {
25
+ const moved = { ...positions };
26
+ const hidden = /* @__PURE__ */ new Set();
27
+ for (const box of boxes) {
28
+ const memberWindow = box.window;
29
+ if (!memberWindow) continue;
30
+ const start = clampWindowStart(memberWindow, starts[box.id] ?? 0);
31
+ const shift = memberWindow.tops[start] ?? 0;
32
+ memberWindow.members.forEach((id, index) => {
33
+ const at = positions[id];
34
+ if (!at) throw new Error(`GraphDiagram: windowed member "${id}" of "${box.id}" has no layout position`);
35
+ if (index < start || index >= start + memberWindow.rows) {
36
+ hidden.add(id);
37
+ moved[id] = { x: at.x, y: index < start ? memberWindow.top : memberWindow.top + memberWindow.height };
38
+ } else {
39
+ moved[id] = { x: at.x, y: at.y - shift };
40
+ }
41
+ });
42
+ }
43
+ return { positions: moved, hidden };
44
+ }
45
+ function windowRows(memberWindow, start) {
46
+ const first = clampWindowStart(memberWindow, start);
47
+ return { first: first + 1, last: Math.min(memberWindow.members.length, first + memberWindow.rows), total: memberWindow.members.length };
48
+ }
49
+ function wheelRows(carry, deltaPx, rowPx) {
50
+ const total = carry + deltaPx;
51
+ const rows = Math.trunc(total / rowPx);
52
+ return { rows, carry: total - rows * rowPx };
53
+ }
54
+ exports.clampWindowStart = clampWindowStart;
55
+ exports.revealMember = revealMember;
56
+ exports.revealWindowStart = revealWindowStart;
57
+ exports.wheelRows = wheelRows;
58
+ exports.windowRows = windowRows;
59
+ exports.windowedPositions = windowedPositions;
60
+ //# sourceMappingURL=graph-group-window.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-group-window.cjs","sources":["../../src/data/graph-group-window.ts"],"sourcesContent":["// Scrolling the members of a windowed group (see `GroupMemberWindow`): which rows show, where shown\n// members are drawn, and where the edges of hidden ones attach. Pure math, no React.\n\nimport type { GraphLayoutGroupBox, GroupMemberWindow } from \"./graph-columns-layout\";\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\n/** Window starts, in rows, by group box id. A box without one starts at its first member. */\nexport type WindowStarts = Readonly<Record<string, number>>;\n\n/** The start kept between the first row and the last full window. */\nexport function clampWindowStart(memberWindow: GroupMemberWindow, start: number): number {\n return Math.min(Math.max(0, memberWindow.members.length - memberWindow.rows), Math.max(0, Math.round(start)));\n}\n\n/** The start that brings member `id` into view, moving no further than needed; unchanged for a shown member or a stranger. */\nexport function revealWindowStart(memberWindow: GroupMemberWindow, start: number, id: string): number {\n const index = memberWindow.members.indexOf(id);\n const current = clampWindowStart(memberWindow, start);\n if (index < 0) return current;\n if (index < current) return index;\n return index >= current + memberWindow.rows ? clampWindowStart(memberWindow, index - memberWindow.rows + 1) : current;\n}\n\n/** The starts after revealing `id` in the windowed box holding it: the same object when nothing moves. */\nexport function revealMember(boxes: readonly GraphLayoutGroupBox[], starts: WindowStarts, id: string | undefined): WindowStarts {\n if (id === undefined) return starts;\n const box = boxes.find((candidate) => candidate.window?.members.includes(id));\n if (!box?.window) return starts;\n const current = starts[box.id] ?? 0;\n const next = revealWindowStart(box.window, current, id);\n return next === clampWindowStart(box.window, current) ? starts : { ...starts, [box.id]: next };\n}\n\nexport interface WindowedPositions {\n positions: Record<string, GraphLayoutPosition>;\n /** Members scrolled out of view: not drawn, their edges attached at the window's edge. */\n hidden: Set<string>;\n}\n\n/**\n * Where each node is drawn once windows scroll: a shown member moves up by the rows scrolled past, a\n * member above the window sits on its top edge and one below on its bottom edge, so its edges still\n * reach the group. Every other node keeps its layout position.\n */\nexport function windowedPositions(\n positions: Readonly<Record<string, GraphLayoutPosition>>,\n boxes: readonly GraphLayoutGroupBox[],\n starts: WindowStarts,\n): WindowedPositions {\n const moved: Record<string, GraphLayoutPosition> = { ...positions };\n const hidden = new Set<string>();\n for (const box of boxes) {\n const memberWindow = box.window;\n if (!memberWindow) continue;\n const start = clampWindowStart(memberWindow, starts[box.id] ?? 0);\n const shift = memberWindow.tops[start] ?? 0;\n memberWindow.members.forEach((id, index) => {\n const at = positions[id];\n if (!at) throw new Error(`GraphDiagram: windowed member \"${id}\" of \"${box.id}\" has no layout position`);\n if (index < start || index >= start + memberWindow.rows) {\n hidden.add(id);\n moved[id] = { x: at.x, y: index < start ? memberWindow.top : memberWindow.top + memberWindow.height };\n } else {\n moved[id] = { x: at.x, y: at.y - shift };\n }\n });\n }\n return { positions: moved, hidden };\n}\n\n/** The rows shown, counted from one, as the footer says them. */\nexport function windowRows(memberWindow: GroupMemberWindow, start: number): { first: number; last: number; total: number } {\n const first = clampWindowStart(memberWindow, start);\n return { first: first + 1, last: Math.min(memberWindow.members.length, first + memberWindow.rows), total: memberWindow.members.length };\n}\n\n/** Whole rows of wheel travel, `rowPx` each, the remainder carried to the next event so small deltas add up. */\nexport function wheelRows(carry: number, deltaPx: number, rowPx: number): { rows: number; carry: number } {\n const total = carry + deltaPx;\n const rows = Math.trunc(total / rowPx);\n return { rows, carry: total - rows * rowPx };\n}\n"],"names":[],"mappings":";;AAUO,SAAS,iBAAiB,cAAiC,OAAuB;AACvF,SAAO,KAAK,IAAI,KAAK,IAAI,GAAG,aAAa,QAAQ,SAAS,aAAa,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC,CAAC;AAC9G;AAGO,SAAS,kBAAkB,cAAiC,OAAe,IAAoB;AACpG,QAAM,QAAQ,aAAa,QAAQ,QAAQ,EAAE;AAC7C,QAAM,UAAU,iBAAiB,cAAc,KAAK;AACpD,MAAI,QAAQ,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AG,GAAG,IAAI,MAAA;AAAA,MACnC;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,EAAE,WAAW,OAAO,OAAA;AAC7B;AAGO,SAAS,WAAW,cAAiC,OAA+D;AACzH,QAAM,QAAQ,iBAAiB,cAAc,KAAK;AAClD,SAAO,EAAE,OAAO,QAAQ,GAAG,MAAM,KAAK,IAAI,aAAa,QAAQ,QAAQ,QAAQ,aAAa,IAAI,GAAG,OAAO,aAAa,QAAQ,OAAA;AACjI;AAGO,SAAS,UAAU,OAAe,SAAiB,OAAgD;AACxG,QAAM,QAAQ,QAAQ;AACtB,QAAM,OAAO,KAAK,MAAM,QAAQ,KAAK;AACrC,SAAO,EAAE,MAAM,OAAO,QAAQ,OAAO,MAAA;AACvC;;;;;;;"}
@@ -0,0 +1,33 @@
1
+ import { GraphLayoutGroupBox, GroupMemberWindow } from './graph-columns-layout.js';
2
+ import { GraphLayoutPosition } from './graph-layout.js';
3
+ /** Window starts, in rows, by group box id. A box without one starts at its first member. */
4
+ export type WindowStarts = Readonly<Record<string, number>>;
5
+ /** The start kept between the first row and the last full window. */
6
+ export declare function clampWindowStart(memberWindow: GroupMemberWindow, start: number): number;
7
+ /** The start that brings member `id` into view, moving no further than needed; unchanged for a shown member or a stranger. */
8
+ export declare function revealWindowStart(memberWindow: GroupMemberWindow, start: number, id: string): number;
9
+ /** The starts after revealing `id` in the windowed box holding it: the same object when nothing moves. */
10
+ export declare function revealMember(boxes: readonly GraphLayoutGroupBox[], starts: WindowStarts, id: string | undefined): WindowStarts;
11
+ export interface WindowedPositions {
12
+ positions: Record<string, GraphLayoutPosition>;
13
+ /** Members scrolled out of view: not drawn, their edges attached at the window's edge. */
14
+ hidden: Set<string>;
15
+ }
16
+ /**
17
+ * Where each node is drawn once windows scroll: a shown member moves up by the rows scrolled past, a
18
+ * member above the window sits on its top edge and one below on its bottom edge, so its edges still
19
+ * reach the group. Every other node keeps its layout position.
20
+ */
21
+ export declare function windowedPositions(positions: Readonly<Record<string, GraphLayoutPosition>>, boxes: readonly GraphLayoutGroupBox[], starts: WindowStarts): WindowedPositions;
22
+ /** The rows shown, counted from one, as the footer says them. */
23
+ export declare function windowRows(memberWindow: GroupMemberWindow, start: number): {
24
+ first: number;
25
+ last: number;
26
+ total: number;
27
+ };
28
+ /** Whole rows of wheel travel, `rowPx` each, the remainder carried to the next event so small deltas add up. */
29
+ export declare function wheelRows(carry: number, deltaPx: number, rowPx: number): {
30
+ rows: number;
31
+ carry: number;
32
+ };
33
+ //# sourceMappingURL=graph-group-window.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-group-window.d.ts","sourceRoot":"","sources":["../../src/data/graph-group-window.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,6FAA6F;AAC7F,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE5D,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvF;AAED,8HAA8H;AAC9H,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAMpG;AAED,0GAA0G;AAC1G,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,mBAAmB,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,CAO9H;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC/C,0FAA0F;IAC1F,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,EACxD,KAAK,EAAE,SAAS,mBAAmB,EAAE,EACrC,MAAM,EAAE,YAAY,GACnB,iBAAiB,CAoBnB;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,YAAY,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAGzH;AAED,gHAAgH;AAChH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAIxG"}
@@ -0,0 +1,60 @@
1
+ function clampWindowStart(memberWindow, start) {
2
+ return Math.min(Math.max(0, memberWindow.members.length - memberWindow.rows), Math.max(0, Math.round(start)));
3
+ }
4
+ function revealWindowStart(memberWindow, start, id) {
5
+ const index = memberWindow.members.indexOf(id);
6
+ const current = clampWindowStart(memberWindow, start);
7
+ if (index < 0) return current;
8
+ if (index < current) return index;
9
+ return index >= current + memberWindow.rows ? clampWindowStart(memberWindow, index - memberWindow.rows + 1) : current;
10
+ }
11
+ function revealMember(boxes, starts, id) {
12
+ if (id === void 0) return starts;
13
+ const box = boxes.find((candidate) => {
14
+ var _a;
15
+ return (_a = candidate.window) == null ? void 0 : _a.members.includes(id);
16
+ });
17
+ if (!(box == null ? void 0 : box.window)) return starts;
18
+ const current = starts[box.id] ?? 0;
19
+ const next = revealWindowStart(box.window, current, id);
20
+ return next === clampWindowStart(box.window, current) ? starts : { ...starts, [box.id]: next };
21
+ }
22
+ function windowedPositions(positions, boxes, starts) {
23
+ const moved = { ...positions };
24
+ const hidden = /* @__PURE__ */ new Set();
25
+ for (const box of boxes) {
26
+ const memberWindow = box.window;
27
+ if (!memberWindow) continue;
28
+ const start = clampWindowStart(memberWindow, starts[box.id] ?? 0);
29
+ const shift = memberWindow.tops[start] ?? 0;
30
+ memberWindow.members.forEach((id, index) => {
31
+ const at = positions[id];
32
+ if (!at) throw new Error(`GraphDiagram: windowed member "${id}" of "${box.id}" has no layout position`);
33
+ if (index < start || index >= start + memberWindow.rows) {
34
+ hidden.add(id);
35
+ moved[id] = { x: at.x, y: index < start ? memberWindow.top : memberWindow.top + memberWindow.height };
36
+ } else {
37
+ moved[id] = { x: at.x, y: at.y - shift };
38
+ }
39
+ });
40
+ }
41
+ return { positions: moved, hidden };
42
+ }
43
+ function windowRows(memberWindow, start) {
44
+ const first = clampWindowStart(memberWindow, start);
45
+ return { first: first + 1, last: Math.min(memberWindow.members.length, first + memberWindow.rows), total: memberWindow.members.length };
46
+ }
47
+ function wheelRows(carry, deltaPx, rowPx) {
48
+ const total = carry + deltaPx;
49
+ const rows = Math.trunc(total / rowPx);
50
+ return { rows, carry: total - rows * rowPx };
51
+ }
52
+ export {
53
+ clampWindowStart,
54
+ revealMember,
55
+ revealWindowStart,
56
+ wheelRows,
57
+ windowRows,
58
+ windowedPositions
59
+ };
60
+ //# sourceMappingURL=graph-group-window.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-group-window.js","sources":["../../src/data/graph-group-window.ts"],"sourcesContent":["// Scrolling the members of a windowed group (see `GroupMemberWindow`): which rows show, where shown\n// members are drawn, and where the edges of hidden ones attach. Pure math, no React.\n\nimport type { GraphLayoutGroupBox, GroupMemberWindow } from \"./graph-columns-layout\";\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\n/** Window starts, in rows, by group box id. A box without one starts at its first member. */\nexport type WindowStarts = Readonly<Record<string, number>>;\n\n/** The start kept between the first row and the last full window. */\nexport function clampWindowStart(memberWindow: GroupMemberWindow, start: number): number {\n return Math.min(Math.max(0, memberWindow.members.length - memberWindow.rows), Math.max(0, Math.round(start)));\n}\n\n/** The start that brings member `id` into view, moving no further than needed; unchanged for a shown member or a stranger. */\nexport function revealWindowStart(memberWindow: GroupMemberWindow, start: number, id: string): number {\n const index = memberWindow.members.indexOf(id);\n const current = clampWindowStart(memberWindow, start);\n if (index < 0) return current;\n if (index < current) return index;\n return index >= current + memberWindow.rows ? clampWindowStart(memberWindow, index - memberWindow.rows + 1) : current;\n}\n\n/** The starts after revealing `id` in the windowed box holding it: the same object when nothing moves. */\nexport function revealMember(boxes: readonly GraphLayoutGroupBox[], starts: WindowStarts, id: string | undefined): WindowStarts {\n if (id === undefined) return starts;\n const box = boxes.find((candidate) => candidate.window?.members.includes(id));\n if (!box?.window) return starts;\n const current = starts[box.id] ?? 0;\n const next = revealWindowStart(box.window, current, id);\n return next === clampWindowStart(box.window, current) ? starts : { ...starts, [box.id]: next };\n}\n\nexport interface WindowedPositions {\n positions: Record<string, GraphLayoutPosition>;\n /** Members scrolled out of view: not drawn, their edges attached at the window's edge. */\n hidden: Set<string>;\n}\n\n/**\n * Where each node is drawn once windows scroll: a shown member moves up by the rows scrolled past, a\n * member above the window sits on its top edge and one below on its bottom edge, so its edges still\n * reach the group. Every other node keeps its layout position.\n */\nexport function windowedPositions(\n positions: Readonly<Record<string, GraphLayoutPosition>>,\n boxes: readonly GraphLayoutGroupBox[],\n starts: WindowStarts,\n): WindowedPositions {\n const moved: Record<string, GraphLayoutPosition> = { ...positions };\n const hidden = new Set<string>();\n for (const box of boxes) {\n const memberWindow = box.window;\n if (!memberWindow) continue;\n const start = clampWindowStart(memberWindow, starts[box.id] ?? 0);\n const shift = memberWindow.tops[start] ?? 0;\n memberWindow.members.forEach((id, index) => {\n const at = positions[id];\n if (!at) throw new Error(`GraphDiagram: windowed member \"${id}\" of \"${box.id}\" has no layout position`);\n if (index < start || index >= start + memberWindow.rows) {\n hidden.add(id);\n moved[id] = { x: at.x, y: index < start ? memberWindow.top : memberWindow.top + memberWindow.height };\n } else {\n moved[id] = { x: at.x, y: at.y - shift };\n }\n });\n }\n return { positions: moved, hidden };\n}\n\n/** The rows shown, counted from one, as the footer says them. */\nexport function windowRows(memberWindow: GroupMemberWindow, start: number): { first: number; last: number; total: number } {\n const first = clampWindowStart(memberWindow, start);\n return { first: first + 1, last: Math.min(memberWindow.members.length, first + memberWindow.rows), total: memberWindow.members.length };\n}\n\n/** Whole rows of wheel travel, `rowPx` each, the remainder carried to the next event so small deltas add up. */\nexport function wheelRows(carry: number, deltaPx: number, rowPx: number): { rows: number; carry: number } {\n const total = carry + deltaPx;\n const rows = Math.trunc(total / rowPx);\n return { rows, carry: total - rows * rowPx };\n}\n"],"names":[],"mappings":"AAUO,SAAS,iBAAiB,cAAiC,OAAuB;AACvF,SAAO,KAAK,IAAI,KAAK,IAAI,GAAG,aAAa,QAAQ,SAAS,aAAa,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC,CAAC;AAC9G;AAGO,SAAS,kBAAkB,cAAiC,OAAe,IAAoB;AACpG,QAAM,QAAQ,aAAa,QAAQ,QAAQ,EAAE;AAC7C,QAAM,UAAU,iBAAiB,cAAc,KAAK;AACpD,MAAI,QAAQ,EAAG,QAAO;AACtB,MAAI,QAAQ,QAAS,QAAO;AAC5B,SAAO,SAAS,UAAU,aAAa,OAAO,iBAAiB,cAAc,QAAQ,aAAa,OAAO,CAAC,IAAI;AAChH;AAGO,SAAS,aAAa,OAAuC,QAAsB,IAAsC;AAC9H,MAAI,OAAO,OAAW,QAAO;AAC7B,QAAM,MAAM,MAAM,KAAK,CAAC,cAAA;AAhBnB;AAgBiC,2BAAU,WAAV,mBAAkB,QAAQ,SAAS;AAAA,GAAG;AAC5E,MAAI,EAAC,2BAAK,QAAQ,QAAO;AACzB,QAAM,UAAU,OAAO,IAAI,EAAE,KAAK;AAClC,QAAM,OAAO,kBAAkB,IAAI,QAAQ,SAAS,EAAE;AACtD,SAAO,SAAS,iBAAiB,IAAI,QAAQ,OAAO,IAAI,SAA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 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const graphGroupWindow = require("./graph-group-window.cjs");
5
+ const DOM_DELTA_LINE = 1;
6
+ const DOM_DELTA_PAGE = 2;
7
+ function useGroupWindows({ boxes, positions, reveal, stageRef, scale }) {
8
+ const [starts, setStarts] = react.useState(() => graphGroupWindow.revealMember(boxes, {}, reveal));
9
+ const [revealed, setRevealed] = react.useState(reveal);
10
+ if (reveal !== revealed) {
11
+ setRevealed(reveal);
12
+ setStarts((current) => graphGroupWindow.revealMember(boxes, current, reveal));
13
+ }
14
+ const live = react.useRef({ boxes, scale });
15
+ live.current = { boxes, scale };
16
+ const scroll = react.useCallback((boxId, rows) => {
17
+ var _a;
18
+ const memberWindow = (_a = live.current.boxes.find((box) => box.id === boxId)) == null ? void 0 : _a.window;
19
+ if (!memberWindow) throw new Error(`GraphDiagram: group box "${boxId}" has no member window to scroll`);
20
+ setStarts((current) => {
21
+ const next = graphGroupWindow.clampWindowStart(memberWindow, (current[boxId] ?? 0) + rows);
22
+ return next === graphGroupWindow.clampWindowStart(memberWindow, current[boxId] ?? 0) ? current : { ...current, [boxId]: next };
23
+ });
24
+ }, []);
25
+ react.useEffect(() => {
26
+ const stage = stageRef.current;
27
+ if (!stage) return;
28
+ let carry = { boxId: "", px: 0 };
29
+ const onWheel = (event) => {
30
+ var _a, _b;
31
+ if (event.ctrlKey || event.metaKey || !(event.target instanceof Element)) return;
32
+ const boxId = (_a = event.target.closest("[data-graph-window]")) == null ? void 0 : _a.getAttribute("data-graph-window");
33
+ const memberWindow = (_b = live.current.boxes.find((box) => box.id === boxId)) == null ? void 0 : _b.window;
34
+ if (!boxId || !memberWindow) return;
35
+ event.preventDefault();
36
+ event.stopPropagation();
37
+ const rowPx = memberWindow.height / memberWindow.rows * live.current.scale;
38
+ const unit = event.deltaMode === DOM_DELTA_LINE ? rowPx : event.deltaMode === DOM_DELTA_PAGE ? rowPx * memberWindow.rows : 1;
39
+ const moved = graphGroupWindow.wheelRows(carry.boxId === boxId ? carry.px : 0, event.deltaY * unit, rowPx);
40
+ carry = { boxId, px: moved.carry };
41
+ if (moved.rows !== 0) scroll(boxId, moved.rows);
42
+ };
43
+ stage.addEventListener("wheel", onWheel, { passive: false });
44
+ return () => stage.removeEventListener("wheel", onWheel);
45
+ }, [stageRef, scroll]);
46
+ const windowed = react.useMemo(() => graphGroupWindow.windowedPositions(positions, boxes, starts), [positions, boxes, starts]);
47
+ return { ...windowed, starts, scroll };
48
+ }
49
+ exports.useGroupWindows = useGroupWindows;
50
+ //# sourceMappingURL=use-group-windows.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-group-windows.cjs","sources":["../../src/data/use-group-windows.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState, type RefObject } from \"react\";\nimport type { GraphLayoutGroupBox } from \"./graph-columns-layout\";\nimport { clampWindowStart, revealMember, wheelRows, windowedPositions, type WindowedPositions, type WindowStarts } from \"./graph-group-window\";\nimport type { GraphLayoutPosition } from \"./graph-layout\";\n\nconst DOM_DELTA_LINE = 1;\nconst DOM_DELTA_PAGE = 2;\n\nexport interface GroupWindows extends WindowedPositions {\n starts: WindowStarts;\n /** Scrolls a windowed box by `rows`, kept within its members. */\n scroll: (boxId: string, rows: number) => void;\n}\n\ninterface UseGroupWindowsOptions {\n boxes: readonly GraphLayoutGroupBox[];\n positions: Record<string, GraphLayoutPosition>;\n /** The member kept in view: scrolled to whenever it changes. */\n reveal: string | undefined;\n /** The stage the boxes and nodes are drawn on: a wheel over a windowed group there scrolls it. */\n stageRef: RefObject<HTMLElement | null>;\n /** The stage's zoom, so a row of wheel travel is a row on screen. */\n scale: number;\n}\n\n/**\n * Each windowed group's scroll position, and the positions it draws members at. A plain wheel over a\n * windowed group, or over one of its members, scrolls the group and goes no further, so it never zooms\n * the diagram; ctrl/meta + wheel still does.\n */\nexport function useGroupWindows({ boxes, positions, reveal, stageRef, scale }: UseGroupWindowsOptions): GroupWindows {\n const [starts, setStarts] = useState<WindowStarts>(() => revealMember(boxes, {}, reveal));\n const [revealed, setRevealed] = useState(reveal);\n if (reveal !== revealed) {\n setRevealed(reveal);\n setStarts((current) => revealMember(boxes, current, reveal));\n }\n const live = useRef({ boxes, scale });\n live.current = { boxes, scale };\n\n const scroll = useCallback((boxId: string, rows: number) => {\n const memberWindow = live.current.boxes.find((box) => box.id === boxId)?.window;\n if (!memberWindow) throw new Error(`GraphDiagram: group box \"${boxId}\" has no member window to scroll`);\n setStarts((current) => {\n const next = clampWindowStart(memberWindow, (current[boxId] ?? 0) + rows);\n return next === clampWindowStart(memberWindow, current[boxId] ?? 0) ? current : { ...current, [boxId]: next };\n });\n }, []);\n\n useEffect(() => {\n const stage = stageRef.current;\n if (!stage) return;\n let carry = { boxId: \"\", px: 0 };\n const onWheel = (event: WheelEvent) => {\n if (event.ctrlKey || event.metaKey || !(event.target instanceof Element)) return;\n const boxId = event.target.closest(\"[data-graph-window]\")?.getAttribute(\"data-graph-window\");\n const memberWindow = live.current.boxes.find((box) => box.id === boxId)?.window;\n if (!boxId || !memberWindow) return;\n event.preventDefault();\n event.stopPropagation();\n const rowPx = (memberWindow.height / memberWindow.rows) * live.current.scale;\n const unit = event.deltaMode === DOM_DELTA_LINE ? rowPx : event.deltaMode === DOM_DELTA_PAGE ? rowPx * memberWindow.rows : 1;\n const moved = wheelRows(carry.boxId === boxId ? carry.px : 0, event.deltaY * unit, rowPx);\n carry = { boxId, px: moved.carry };\n if (moved.rows !== 0) scroll(boxId, moved.rows);\n };\n // React registers wheel listeners as passive, which cannot keep the wheel from zooming the viewport.\n stage.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => stage.removeEventListener(\"wheel\", onWheel);\n }, [stageRef, scroll]);\n\n const windowed = useMemo(() => windowedPositions(positions, boxes, starts), [positions, boxes, starts]);\n return { ...windowed, starts, scroll };\n}\n"],"names":["useState","revealMember","useRef","useCallback","clampWindowStart","useEffect","wheelRows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MAA1C,mBAA6C,aAAa;AACxE,YAAM,gBAAe,UAAK,QAAQ,MAAM,KAAK,CAAC,QAAQ,IAAI,OAAO,KAAK,MAAjD,mBAAoD;AACzE,UAAI,CAAC,SAAS,CAAC,aAAc;AAC7B,YAAM,eAAA;AACN,YAAM,gBAAA;AACN,YAAM,QAAS,aAAa,SAAS,aAAa,OAAQ,KAAK,QAAQ;AACvE,YAAM,OAAO,MAAM,cAAc,iBAAiB,QAAQ,MAAM,cAAc,iBAAiB,QAAQ,aAAa,OAAO;AAC3H,YAAM,QAAQC,iBAAAA,UAAU,MAAM,UAAU,QAAQ,MAAM,KAAK,GAAG,MAAM,SAAS,MAAM,KAAK;AACxF,cAAQ,EAAE,OAAO,IAAI,MAAM,MAAA;AAC3B,UAAI,MAAM,SAAS,EAAG,QAAO,OAAO,MAAM,IAAI;AAAA,IAChD;AAEA,UAAM,iBAAiB,SAAS,SAAS,EAAE,SAAS,OAAO;AAC3D,WAAO,MAAM,MAAM,oBAAoB,SAAS,OAAO;AAAA,EACzD,GAAG,CAAC,UAAU,MAAM,CAAC;AAErB,QAAM,WAAWC,MAAAA,QAAQ,MAAMC,iBAAAA,kBAAkB,WAAW,OAAO,MAAM,GAAG,CAAC,WAAW,OAAO,MAAM,CAAC;AACtG,SAAO,EAAE,GAAG,UAAU,QAAQ,OAAA;AAChC;;"}
@@ -0,0 +1,27 @@
1
+ import { RefObject } from 'react';
2
+ import { GraphLayoutGroupBox } from './graph-columns-layout.js';
3
+ import { WindowedPositions, WindowStarts } from './graph-group-window.js';
4
+ import { GraphLayoutPosition } from './graph-layout.js';
5
+ export interface GroupWindows extends WindowedPositions {
6
+ starts: WindowStarts;
7
+ /** Scrolls a windowed box by `rows`, kept within its members. */
8
+ scroll: (boxId: string, rows: number) => void;
9
+ }
10
+ interface UseGroupWindowsOptions {
11
+ boxes: readonly GraphLayoutGroupBox[];
12
+ positions: Record<string, GraphLayoutPosition>;
13
+ /** The member kept in view: scrolled to whenever it changes. */
14
+ reveal: string | undefined;
15
+ /** The stage the boxes and nodes are drawn on: a wheel over a windowed group there scrolls it. */
16
+ stageRef: RefObject<HTMLElement | null>;
17
+ /** The stage's zoom, so a row of wheel travel is a row on screen. */
18
+ scale: number;
19
+ }
20
+ /**
21
+ * Each windowed group's scroll position, and the positions it draws members at. A plain wheel over a
22
+ * windowed group, or over one of its members, scrolls the group and goes no further, so it never zooms
23
+ * the diagram; ctrl/meta + wheel still does.
24
+ */
25
+ export declare function useGroupWindows({ boxes, positions, reveal, stageRef, scale }: UseGroupWindowsOptions): GroupWindows;
26
+ export {};
27
+ //# sourceMappingURL=use-group-windows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-group-windows.d.ts","sourceRoot":"","sources":["../../src/data/use-group-windows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAgE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC/I,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAK1D,MAAM,WAAW,YAAa,SAAQ,iBAAiB;IACrD,MAAM,EAAE,YAAY,CAAC;IACrB,iEAAiE;IACjE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C;AAED,UAAU,sBAAsB;IAC9B,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACtC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC/C,gEAAgE;IAChE,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,kGAAkG;IAClG,QAAQ,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACxC,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,sBAAsB,GAAG,YAAY,CA2CnH"}