From aa06df66549e707e580774700f54103a967afd84 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:57:09 -0600 Subject: [PATCH 01/62] The diagram viewer (DECISIONS 310): Expand, the dialog, zoom and pan, in React "Expand" in every figure's foot opens the figure's drawn layout in a dialog. The figure is drawn again from the same data, laid out once at 100% at the stage's width (never under its least drawn width, never over the page row), and zoomed with one transform. Fit opens it; the buttons, the keys, Ctrl and the wheel, a pinch and a drag zoom and pan it. The zoom and pan are plain DOM (diagram-zoom-core.ts), for the skill to share. The viewer is a chunk of its own, loaded at Expand's first hover, focus or touch. Also call 1 of DECISIONS 306, section 4: a decision taller than wide is a fit failure, so the CIMIP flowchart is stacked through 975 and drawn from 976. Co-Authored-By: Claude Opus 5.5 --- packages/react/build.mjs | 23 +- packages/react/src/diagram-core.ts | 38 ++- packages/react/src/diagram-figure.tsx | 139 +++++++++- packages/react/src/diagram-motion-core.ts | 5 +- packages/react/src/diagram-viewer.tsx | 160 +++++++++++ packages/react/src/diagram-zoom-core.ts | 322 ++++++++++++++++++++++ packages/react/src/styles/components.css | 78 ++++++ 7 files changed, 742 insertions(+), 23 deletions(-) create mode 100644 packages/react/src/diagram-viewer.tsx create mode 100644 packages/react/src/diagram-zoom-core.ts diff --git a/packages/react/build.mjs b/packages/react/build.mjs index 7ace96f1..22acade7 100644 --- a/packages/react/build.mjs +++ b/packages/react/build.mjs @@ -95,6 +95,23 @@ await esbuild.build({ banner: { js: `"use client";` }, }); +// The diagram viewer is the fourth (DECISIONS 310, 9.13): "Expand" loads it at its first hover, focus or touch, and it brings Dialog, the sheet's parts and the +// buttons with it, inlined for the same reason as the motion's. It imports the figure and the engine only as types: the figure hands them over when it opens +// the viewer (ViewerKit), so this chunk never holds a second copy of the engine. +await esbuild.build({ + bundle: true, + format: "esm", + platform: "neutral", + target: "es2022", + jsx: "automatic", + logLevel: "warning", + entryPoints: [path.join(here, "src/diagram-viewer.tsx")], + outdir: dist, + external: external.filter((name) => !name.startsWith("@phosphor-icons")), + plugins: [{ name: "lazy-flight", setup(build) { build.onResolve({ filter: /^\.\/glyph-flight$/ }, (args) => (args.kind === "dynamic-import" ? { path: "./glyph-flight.js", external: true } : undefined)); } }], + banner: { js: `"use client";` }, +}); + // The root's map for the imports plugin (src/tooling/imports.ts): every name the root exports at run time, and the module that holds it, read from the barrel's source. // `export * from "./glyph-set"` is the one star, and glyph-set is itself a list of `export { X } from "./glyphs/x"`: each glyph maps to its own module. Every // `export` statement in the barrel must be one of the three forms below (`export { … } from "./x";`, `export type { … } from "./x";`, `export * from "./x";`, double @@ -135,7 +152,7 @@ await esbuild.build({ // The core glyphs are modules of their own (src/glyphs), so an app that imports HomeGlyph bundles only HomeGlyph. entryPoints: [ // index.ts is not bundled: it is a barrel of `export { … } from "./module"` and is written as one, below, so each export comes from the module that holds it. - ...fs.readdirSync(path.join(here, "src")).filter((f) => /\.tsx?$/.test(f) && !f.endsWith(".d.ts") && !["command-panel.tsx", "glyph-flight.tsx", "diagram-motion.tsx", "diagram-motion-core.ts", "index.ts"].includes(f)).map((f) => path.join(here, "src", f)), + ...fs.readdirSync(path.join(here, "src")).filter((f) => /\.tsx?$/.test(f) && !f.endsWith(".d.ts") && !["command-panel.tsx", "glyph-flight.tsx", "diagram-motion.tsx", "diagram-motion-core.ts", "diagram-viewer.tsx", "diagram-zoom-core.ts", "index.ts"].includes(f)).map((f) => path.join(here, "src", f)), ...fs.readdirSync(path.join(here, "src", "glyphs")).filter((f) => /\.ts$/.test(f)).map((f) => path.join(here, "src", "glyphs", f)), // The service marks (DECISIONS 292, 2.6): one module a mark under dist/marks, at @srasyndicate/basalt/marks/, never imported by the index, so an // app pays for the marks it imports and no others. Generated by marks/generate.mjs. @@ -146,7 +163,7 @@ await esbuild.build({ ...fs.readdirSync(path.join(here, "src", "tooling")).filter((f) => /\.ts$/.test(f)).map((f) => path.join(here, "src", "tooling", f)), ], define: { __PHOSPHOR_NOTICE__: JSON.stringify(phosphorNotice), __BASALT_ROOT_MAP__: JSON.stringify(JSON.stringify(rootMap)) }, - plugins: [{ name: "lazy-modules", setup(build) { build.onResolve({ filter: /^\.\/(command-panel|glyph-flight|diagram-motion)$/ }, (args) => (args.kind === "dynamic-import" ? { path: `${args.path}.js`, external: true } : undefined)); } }], + plugins: [{ name: "lazy-modules", setup(build) { build.onResolve({ filter: /^\.\/(command-panel|glyph-flight|diagram-motion|diagram-viewer)$/ }, (args) => (args.kind === "dynamic-import" ? { path: `${args.path}.js`, external: true } : undefined)); } }], outdir: dist, bundle: true, splitting: true, @@ -199,7 +216,7 @@ const needsClient = (file, seen = new Set()) => { seen.add(file); return staticImports(fs.readFileSync(path.join(dist, file), "utf8")).some((specifier) => clientImport.test(specifier) || (/^\.\/chunk-/.test(specifier) && needsClient(specifier.slice(2), seen))); }; -for (const file of fs.readdirSync(dist, { recursive: true }).filter((f) => f.endsWith(".js") && !path.basename(f).startsWith("chunk-") && !["command-panel.js", "glyph-flight.js", "diagram-motion.js"].includes(f))) { +for (const file of fs.readdirSync(dist, { recursive: true }).filter((f) => f.endsWith(".js") && !path.basename(f).startsWith("chunk-") && !["command-panel.js", "glyph-flight.js", "diagram-motion.js", "diagram-viewer.js"].includes(f))) { const code = fs.readFileSync(path.join(dist, file), "utf8"); if (needsClient(file)) fs.writeFileSync(path.join(dist, file), `"use client";\n${code}`); } diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 0ad864ff..e192911a 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -641,6 +641,8 @@ function boxSwatch(P: string, shape: "box" | "terminal" | "decision" | "focal" | function keyTree(P: string, m: Model): VElement | null { return memo(m, `key:${P}`, () => buildKey(P, m)); } +/** The key alone, for the viewer's foot (DECISIONS 310, 9.2): the same entries the figure draws under its drawing. */ +export const figureKey = keyTree; function buildKey(P: string, m: Model): VElement | null { const entries: VElement[] = []; const entry = (swatch: VElement, words: string, attrs: VAttrs = {}) => entries.push(h("li", { class: `${P}-entry`, ...attrs }, swatch, h("span", null, words))); @@ -810,6 +812,8 @@ function sequenceSteps(ctx: TreeContext, m: Model): VElement { function listTree(P: string, m: Model): VNode[] { return memo(m, `list:${P}`, () => buildList(P, m)); } +/** The list alone, for the viewer's stage (DECISIONS 310, 9.9): the page's own list, in place of the drawing. */ +export const figureList = listTree; function buildList(P: string, m: Model): VNode[] { const sub = Math.min(6, m.heading + 1); const H = (text: string) => h(`h${sub}`, { class: `${P}-list-head` }, text); @@ -879,10 +883,13 @@ function keysSentence(m: Model): string { return `Arrow keys move to the next or the previous ${noun}, in the author's order; Home and End go to the ends; Escape clears the trace.`; } -/** The key hint's entries: the keys and their words. */ -export function hintEntries(m: Model): Array<{ keys: string[]; words: string }> { +/** The key hint's entries: the keys and their words. In the viewer (DECISIONS 310, 9.8) Esc closes, and the zoom keys are added. */ +export function hintEntries(m: Model, viewer = false): Array<{ keys: string[]; words: string }> { + if (viewer) return [{ keys: ["←", "→"], words: stopNoun(m) }, { keys: ["Home", "End"], words: "the ends" }, { keys: ["+", "−"], words: "zoom" }, { keys: ["0"], words: "fit" }, { keys: ["Esc"], words: "close" }]; return [{ keys: ["←", "→"], words: stopNoun(m) }, { keys: ["Home", "End"], words: "the ends" }, { keys: ["Esc"], words: "clear" }]; } +/** The viewer's addition to the keys sentence (DECISIONS 310, 9.8). */ +export const VIEWER_KEYS = "Plus and minus zoom, zero fits the drawing, Escape closes."; export interface FigureOptions { /** The class prefix: "basalt-diagram" in React, "diagram" in the HTML skill. */ @@ -896,6 +903,8 @@ export interface FigureOptions { hasSource?: boolean; /** The class of the hidden text. */ hiddenClass: string; + /** The figure is the viewer's (DECISIONS 310): only its drawing shows, and the keys sentence says the zoom keys. */ + viewer?: boolean; } /** The whole figure. Before script runs `dyn` is empty; the same tree, with the measured `dyn`, is what script settles on. */ @@ -935,6 +944,7 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { "data-measured": dyn.layout ? "" : undefined, "data-bare": dyn.bare ? "" : undefined, "data-motion": m.motion.animated ? "animated" : undefined, + "data-viewer": o.viewer ? "" : undefined, style: style.join(";"), }, h("div", { class: `${P}-head` }, h(Head, { id: ids.title, class: `${P}-title` }, m.title), o.hasSource ? h("p", { class: `${P}-source` }, { slot: "source" }) : null), @@ -951,7 +961,7 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { h("p", { class: `${P}-hint`, "data-kbd-hint": "", "aria-hidden": "true" }, { slot: "hint" }), h("div", { class: `${P}-foot` }, { slot: "toggle" }), h("div", { id: ids.list, class: `${P}-list`, hidden: !dyn.open }, listTree(P, m)), - h("span", { id: ids.keys, class: o.hiddenClass }, keysSentence(m)), + h("span", { id: ids.keys, class: o.hiddenClass }, o.viewer ? `${keysSentence(m)} ${VIEWER_KEYS}` : keysSentence(m)), h("figcaption", { id: ids.summary, class: `${P}-summary` }, { slot: "summary" })); } @@ -1910,14 +1920,14 @@ export function inkHtml(P: string, geo: Geo, tk: Tokens, base: string): string { // ---- Laying a figure out ---- -export interface Measured { dyn: Dyn; geo: Geo | null; ink: string; tokens: Tokens | null } +export interface Measured { dyn: Dyn; geo: Geo | null; ink: string; tokens: Tokens | null; least?: number } /** * Measures the figure and settles its layout (1.11): the drawn layout when the figure is at least 640 wide, every track holds its widest * word, every label seats and no line passes through a node; otherwise the stack. `apply` writes a state into the DOM (the same markup the * tree gives for it), so each try is measured as it would be drawn. */ -export function measureFigure(fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn?: (s: string) => void): Measured { +export function measureFigure(fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn?: (s: string) => void, sizeTo?: (least: number) => void): Measured { // Development only (the warnings): first, so a minifier sees it is a constant and drops what it guards. const dev = process.env.NODE_ENV !== "production"; const drawing = fig.querySelector(`.${P}-drawing`); @@ -1926,13 +1936,18 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin const tk = readTokens(fig); const measure = ruler(drawing, P); const mins = minimums(m, tk, measure); + // The viewer (DECISIONS 310, 9.3) sizes its figure from the least drawn width before it is measured: never under it, so the drawn layout is tried. + sizeTo?.(mins.least); const W = fig.clientWidth; const focusedId = (() => { const a = document.activeElement as HTMLElement | null; return a && drawing.contains(a) && a.dataset.node ? a.dataset.node : undefined; })(); const stopOf = (d: Dyn): Dyn => { if (!hasStops(m, d)) return { ...d, stop: d.stop ?? m.nodes[0]?.id, keep: focusedId && !(d.layout === "drawn") ? focusedId : undefined }; return { ...d, stop: d.stop && m.byId.has(d.stop) ? d.stop : m.nodes[0]?.id, keep: undefined }; }; + // A decision that is taller than it is wide at this width (call 1 of DECISIONS 306, section 4): the drawn layout is refused, as any fit failure is. + let tall = false; const heightsFor = (d: Dyn): Dyn => { + tall = false; if (m.type !== "flowchart") return d; apply({ ...d, heights: undefined, words: undefined }); const heights = record(); @@ -1970,6 +1985,8 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin el.style.removeProperty("--_ww"); } heights[el.dataset.node!] = height; + // Taller than wide after every width its words can take (DECISIONS 306, section 4, call 1): a width the flowchart is not drawn at. + if (height > nr.width) tall = true; }); return { ...d, heights, words: Object.keys(widened).length ? widened : undefined }; }; @@ -1987,16 +2004,17 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin let { dd: d, g: geo } = drawnTry(false); // A label refused only because its seats leave the drawing (beside a line in a 40px first or last row) is given space-3 above and below. // A route the drawn layout refuses: through a node, off the drawing, or laid on another line. - const refused = (g: Geo) => g.through.length > 0 || g.outside.length > 0 || (g.overlaps?.length ?? 0) > 0; + const refused = (g: Geo) => g.through.length > 0 || g.outside.length > 0 || (g.overlaps?.length ?? 0) > 0 || tall; if (!refused(geo) && geo.unseated.length && geo.unseated.every((k) => geo.bounded?.includes(k))) { const padded = drawnTry(true); if (!refused(padded.g) && !padded.g.unseated.length) ({ dd: d, g: geo } = padded); } if (!refused(geo) && !geo.unseated.length) { if (geo.crossings.length) dev && warn?.(`${geo.crossings.length} crossing${geo.crossings.length === 1 ? "" : "s"} in the drawn layout: ${geo.crossings.map((c) => `${lineName(m, geo.lines[c.top]!)} over ${lineName(m, geo.lines[c.under]!)}`).join("; ")}`); - return { dyn: d, geo, ink: inkHtml(P, geo, tk, base), tokens: tk }; + return { dyn: d, geo, ink: inkHtml(P, geo, tk, base), tokens: tk, least: mins.least }; } // At a width the figure should fit by its tokens and words, a failure is the author's to fix. + if (tall) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: a decision would be taller than it is wide`); if (geo.through.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.through)} would pass through a node`); if (geo.overlaps?.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.overlaps)} would lie on one another`); if (geo.outside.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.outside)} would leave the drawing`); @@ -2005,7 +2023,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin let d = stopOf({ ...current, ...closed, layout: "stacked", heights: undefined, grow: record(), track: m.type === "schema" ? mins.table : undefined, bare: undefined, pad: undefined }); d = heightsFor(d); apply(d); - if (m.type === "sequence" || m.type === "schema") return { dyn: d, geo: null, ink: "", tokens: tk }; + if (m.type === "sequence" || m.type === "schema") return { dyn: d, geo: null, ink: "", tokens: tk, least: mins.least }; const plan = stackPlan(m); let out = stackedGeometry(input(), measure, plan, d.grow); for (let tries = 0; tries < 6 && Object.keys(out.grow).length; tries++) { @@ -2028,10 +2046,10 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin // Dressed as where scripting is off (1.13): no line in the key, no key hint, no stops, and the list open when the figure becomes bare. const bare: Geo = { ...geo, lines: [], labels: [], crossings: [] }; const dyn = stopOf({ ...d, grow: record(), bare: true, open: current.bare ? current.open : true, autoOpen: current.bare ? current.autoOpen : current.open ? undefined : true }); - return { dyn, geo: bare, ink: "", tokens: tk }; + return { dyn, geo: bare, ink: "", tokens: tk, least: mins.least }; } if (geo.crossings.length) dev && warn?.(`${geo.crossings.length} crossing${geo.crossings.length === 1 ? "" : "s"} in the stacked drawing (each is cut): ${geo.crossings.map((c) => `${lineName(m, geo.lines[c.top]!)} over ${lineName(m, geo.lines[c.under]!)}`).join("; ")}`); - return { dyn: d, geo, ink: inkHtml(P, geo, tk, base), tokens: tk }; + return { dyn: d, geo, ink: inkHtml(P, geo, tk, base), tokens: tk, least: mins.least }; } function lineName(m: Model, l: GLine): string { diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 8b84cea3..eb0167e6 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -4,16 +4,23 @@ import { Kbd } from "./kbd"; import { useShortcutsVisible } from "./keyboard"; import { usePanelLevel } from "./layers"; import { - applyTrace, buildModel, entranceDrawn, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, + applyTrace, buildModel, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, } from "./diagram-core"; import type { DiagramLegend, DiagramMotion, DiagramSpec, Dyn, Measured, VNode } from "./diagram-core"; import type { MotionController } from "./diagram-motion-core"; +import { ArrowsOutSimpleIcon } from "@phosphor-icons/react/dist/csr/ArrowsOutSimple"; +import { Icon } from "./icon"; type MotionModule = typeof import("./diagram-motion"); let motionLoading: Promise | undefined; /** The motion code (DECISIONS 292, 2.6): a module of its own, loaded the first time a figure is animated, so a still figure never pays for it. */ const loadMotion = () => (motionLoading ??= import("./diagram-motion").catch((error) => { motionLoading = undefined; throw error; })); +type ViewerModule = typeof import("./diagram-viewer"); +let viewerLoading: Promise | undefined; +/** The viewer (DECISIONS 310, 9.13): a module of its own, with the Dialog it needs, loaded at the Expand button's first hover, focus or touch. */ +const loadViewer = () => (viewerLoading ??= import("./diagram-viewer").catch((error) => { viewerLoading = undefined; throw error; })); + // The figure every diagram shares (DECISIONS 281): the title, the drawing, the key, the key hint, the required summary and "View as list". // Not exported from the package: each of the five diagrams is its own module on top of it. The markup is the engine's tree, so it is the // HTML skill's markup too; the drawing is measured before the first paint and again when the figure's width changes or its fonts arrive. @@ -35,9 +42,17 @@ export interface DiagramFigureProps extends Omit, * reduced-motion or forced-colours figure is still. Motion never carries a fact alone: the words say what moves. */ motion?: DiagramMotion; + /** + * `true` (the default) puts "Expand" in the foot, after "View as list" (DECISIONS 310): it opens the viewer, a dialog that holds the drawn layout, + * where the reader zooms (from Fit or 100% to 400%) and pans it. `false` leaves both out. Before script there is no button: it does nothing without it. + */ + zoom?: boolean; } const P = "basalt-diagram"; +/** What the viewer is handed (diagram-viewer.tsx): this component and the engine, so its chunk holds no second copy of either. Built at the first open. */ +let kitMade: import("./diagram-viewer").ViewerKit | undefined; +const kitOf = () => (kitMade ??= { Figure: DiagramFigure, Kbd, buildModel, figureKey, figureList, hintEntries, toHtml }); declare const process: { env: { NODE_ENV?: string } }; const CAMEL: Record = { class: "className", tabindex: "tabIndex", for: "htmlFor", viewbox: "viewBox" }; @@ -81,12 +96,27 @@ function warnOnce(component: string, message: string) { console.warn(`Basalt ${key}`); } +/** The viewer's own figure (DECISIONS 310, 9.3): laid out at a width the viewer gives, its drawing alone shown, measured only at 100%. */ +export interface DiagramViewerMode { + /** The width it may be laid out at: the stage's inner width, never over the page row (`row`) unless its least drawn width is more. */ + avail: number; + row: number; + /** A stack is held at most this wide (`size-breakpoint-container`). */ + contain: number; + /** The layer the figure is laid out in: its width is the layout width. */ + layer: () => HTMLElement | null; + /** After every layout: what was measured, and the figure. */ + onMeasured: (measured: Measured, fig: HTMLElement) => void; +} + export interface DiagramFigureInternalProps extends DiagramFigureProps { spec: DiagramSpec; component: string; + /** Internal: the figure is the viewer's (diagram-viewer.tsx). */ + viewer?: DiagramViewerMode; } -export function DiagramFigure({ spec, component, title: _title, heading: _heading, legend: _legend, motion: _motion, source, summary, className, style, onKeyDown, onFocus, onBlur, onPointerOver, onPointerLeave, ref: callerRef, ...props }: DiagramFigureInternalProps) { +export function DiagramFigure({ spec, component, viewer, zoom = true, title: _title, heading: _heading, legend: _legend, motion: _motion, source, summary, className, style, onKeyDown, onFocus, onBlur, onPointerOver, onPointerLeave, ref: callerRef, ...props }: DiagramFigureInternalProps) { const base = `dg${React.useId().replace(/[^a-zA-Z0-9_-]/g, "")}`; const level = usePanelLevel(); // The key hint is a data-kbd-hint legend, hidden on touch until a hardware key is pressed: this installs the listener that reveals it. @@ -105,6 +135,9 @@ export function DiagramFigure({ spec, component, title: _title, heading: _headin const [ink, setInk] = React.useState(""); const inkHtml = React.useMemo(() => ({ __html: ink }), [ink]); const measured = React.useRef(null); + // The viewer's figure: the least width the engine was found to draw it at (0: none was found), for this data. + const leastDrawn = React.useRef(undefined); + const leastFor = React.useRef(null); const dynRef = React.useRef(dyn); dynRef.current = dyn; const [motionModule, setMotionModule] = React.useState(null); @@ -120,7 +153,7 @@ export function DiagramFigure({ spec, component, title: _title, heading: _headin modelRef.current = model; const [focusTrace, setFocusTrace] = React.useState(null); const [hoverTrace, setHoverTrace] = React.useState(null); - const options = React.useMemo(() => ({ prefix: P, base, level, hasSource: source !== undefined && source !== null, hiddenClass: "basalt-visually-hidden" }), [base, level, source]); + const options = React.useMemo(() => ({ prefix: P, base, level, hasSource: source !== undefined && source !== null, hiddenClass: "basalt-visually-hidden", viewer: Boolean(viewer) }), [base, level, source, viewer]); // Development only: a bundler that sets NODE_ENV to production drops this block, strings included. React.useEffect(() => { @@ -131,7 +164,39 @@ export function DiagramFigure({ spec, component, title: _title, heading: _headin const fig = figRef.current; if (!fig) return; const warn = process.env.NODE_ENV !== "production" ? (message: string) => warnOnce(component, message) : undefined; - const result = measureFigure(fig, model, P, base, dynRef.current, (d) => syncAttributes(fig, figureTree(model, d, options)), warn); + const apply = (d: Dyn) => syncAttributes(fig, figureTree(model, d, options)); + // The viewer's figure is laid out at the stage's width, never under its least drawn width (9.3); a stack it must hold is at most the container's width. + const layer = viewer?.layer(); + if (leastFor.current !== model) { leastFor.current = model; leastDrawn.current = undefined; } + const sizeTo = viewer && layer ? (least: number) => { layer.style.width = `${Math.max(leastDrawn.current ?? least, Math.min(viewer.avail, viewer.row))}px`; } : undefined; + // The layer has no width of its own until the first layout: it starts at the stage's, so the figure can be measured. + if (viewer && layer && !layer.style.width) layer.style.width = `${Math.min(viewer.avail, viewer.row)}px`; + // The engine measures only at 100% (9.3): the zoom is taken off the layer while it measures and put back before anything paints. + const zoomed = layer?.style.transform ?? ""; + if (layer && zoomed) layer.style.transform = "none"; + let result = measureFigure(fig, model, P, base, dynRef.current, apply, warn, sizeTo); + // The figure's least drawn width is the first width the engine draws it at, which the token sum can undercount (a sequence's columns are measured, a + // decision's diamond may be refused at a width). Found once by trying wider layouts, in steps of 16 and then by the pixel, up to half the row past it. + if (viewer && layer && result.dyn.layout === "stacked" && leastDrawn.current === undefined && result.least !== undefined) { + // A width counts when it draws twice running: measured from the stack, then again from its own drawn state, as every later measure is. + const at = (w: number) => { + layer.style.width = `${w}px`; + const first = measureFigure(fig, model, P, base, result.dyn, apply); + return first.dyn.layout === "drawn" ? measureFigure(fig, model, P, base, first.dyn, apply) : first; + }; + const from = Math.max(result.least, Math.min(viewer.avail, viewer.row)); + const cap = Math.max(viewer.row, from) * 1.5; + let found: number | undefined; + for (let w = from + 16; w <= cap && found === undefined; w += 16) if (at(w).dyn.layout === "drawn") found = w; + if (found !== undefined) for (let w = found - 15; w < found; w++) if (at(w).dyn.layout === "drawn") { found = w; break; } + if (found !== undefined) { leastDrawn.current = found; result = at(found); } + else leastDrawn.current = 0; + } + if (viewer && layer && result.dyn.layout === "stacked" && fig.clientWidth > viewer.contain) { + layer.style.width = `${viewer.contain}px`; + result = measureFigure(fig, model, P, base, result.dyn, apply, warn); + } + if (layer && zoomed) layer.style.transform = zoomed; measured.current = result; // The same layout is the same state: a measure that changes nothing renders nothing. // (A layout is plain data that the engine builds in one order, so its text is a fair test.) @@ -139,7 +204,8 @@ export function DiagramFigure({ spec, component, title: _title, heading: _headin setInk(result.ink); // A layout with no stops traces nothing: a pointer resting on a node as the figure narrows into one leaves no trace behind. if (!hasStops(model, result.dyn)) setHoverTrace(null); - }, [model, base, options, component]); + if (viewer) viewer.onMeasured(result, fig); + }, [model, base, options, component, viewer]); // Measured before the first paint, then whenever the figure's width changes or the real faces arrive. React.useLayoutEffect(() => { @@ -212,6 +278,34 @@ export function DiagramFigure({ spec, component, title: _title, heading: _headin React.useEffect(() => { controller?.sendValue(sendValue); }, [sendValue, controller]); const settle = () => { if (animated && figRef.current) settleEntrance(figRef.current); }; + // The viewer (DECISIONS 310): "Expand" exists once script runs. Its module loads at the button's first hover, focus or touch; a press before it has + // arrived makes the button busy until the dialog opens. While the viewer is open the page's figure holds its loops and settles a running entrance (9.7). + const [scripted, setScripted] = React.useState(false); + React.useEffect(() => { if (!viewer) setScripted(true); }, [viewer]); + const expandRef = React.useRef(null); + const [viewerModule, setViewerModule] = React.useState(null); + const [viewerOpen, setViewerOpen] = React.useState(false); + const [opening, setOpening] = React.useState(false); + const fetchViewer = React.useCallback(() => loadViewer().then((mod) => { setViewerModule(() => mod); return mod; }, (error: unknown) => { + if (process.env.NODE_ENV !== "production") warnOnce(component, `the viewer could not load (${String(error)}); "Expand" stays and does nothing`); + return null; + }), [component]); + const preloadViewer = () => { if (!viewerModule) void fetchViewer(); }; + const openViewer = () => { + if (opening) return; + settle(); + if (viewerModule) { setViewerOpen(true); return; } + setOpening(true); + void fetchViewer().then((mod) => { setOpening(false); if (mod) setViewerOpen(true); }); + }; + const closeViewer = React.useCallback(() => setViewerOpen(false), []); + React.useLayoutEffect(() => { + const fig = figRef.current; + if (!fig || viewer) return; + fig.toggleAttribute("data-viewing", viewerOpen); + if (viewerOpen && animated) settleEntrance(fig); + }, [viewerOpen, viewer, animated]); + const nodeOf = (target: EventTarget | null) => { const el = (target as HTMLElement | null)?.closest?.(`.${P}-node`); return el && figRef.current?.contains(el) ? el : null; @@ -228,7 +322,8 @@ export function DiagramFigure({ spec, component, title: _title, heading: _headin const node = nodeOf(event.target); if (!node || event.defaultPrevented) return; settle(); - if (event.key === "Escape") { if (focusTrace || hoverTrace) { event.preventDefault(); setFocusTrace(null); setHoverTrace(null); } return; } + // In the viewer Esc always closes the dialog, traced or not (9.8): the figure leaves it to the dialog. + if (event.key === "Escape") { if (!viewer && (focusTrace || hoverTrace)) { event.preventDefault(); setFocusTrace(null); setHoverTrace(null); } return; } if (!stops) return; const to = keyTarget(model, node.dataset.node!, event.key); if (!to) return; @@ -283,8 +378,36 @@ export function DiagramFigure({ spec, component, title: _title, heading: _headin {entry.keys.map((k, i) => {i ? " " : null}{k})} {entry.words} )); const tree = figureTree(model, dyn, options); - // The foot (1.9): "View as list", then the run button and "Pause animations", which the motion module draws when it has loaded. + // The viewer's figure shows its drawing alone: its head, key, hint and foot are the dialog's. + if (viewer) return toReact(tree, { source, summary, hint: null, toggle: null }, inkHtml, root) as React.ReactElement; + // The foot (1.9, and DECISIONS 310, 9.1): "View as list", "Expand", then the run button and "Pause animations", which the motion module draws when it has loaded. const Foot = motionModule?.MotionFoot; - const foot = Foot && controller ? <>{toggle} : toggle; + const expand = zoom && scripted ? ( + <> + + {viewerOpen && viewerModule ? ( + + ) : null} + + ) : null; + const foot = <>{toggle}{expand}{Foot && controller ? : null}; return toReact(tree, { source, summary, hint, toggle: foot }, inkHtml, root) as React.ReactElement; } diff --git a/packages/react/src/diagram-motion-core.ts b/packages/react/src/diagram-motion-core.ts index caa7f9c1..a4d20981 100644 --- a/packages/react/src/diagram-motion-core.ts +++ b/packages/react/src/diagram-motion-core.ts @@ -75,7 +75,7 @@ function join(fig: Figure): Page { } page.figs.add(fig); if (fig.drawing) page.io.observe(fig.drawing); - page.mo.observe(fig.host.fig, { attributes: true, attributeFilter: ["data-tracing"] }); + page.mo.observe(fig.host.fig, { attributes: true, attributeFilter: ["data-tracing", "data-viewing"] }); return page; } @@ -247,7 +247,8 @@ class Figure implements MotionController { } private entrance() { return this.host.fig.getAttribute("data-entrance"); } private hasLines() { return Boolean(this.host.geo()?.lines.length); } - private traced() { return this.host.fig.hasAttribute("data-tracing"); } + // A figure whose viewer is open holds its loops as a traced one does (DECISIONS 310, 9.7), and they start again when it closes. + private traced() { return this.host.fig.hasAttribute("data-tracing") || this.host.fig.hasAttribute("data-viewing"); } seen(entry: IntersectionObserverEntry) { this.inView = entry.isIntersecting; diff --git a/packages/react/src/diagram-viewer.tsx b/packages/react/src/diagram-viewer.tsx new file mode 100644 index 00000000..f6e62076 --- /dev/null +++ b/packages/react/src/diagram-viewer.tsx @@ -0,0 +1,160 @@ +import * as React from "react"; + +import { Button, IconButton } from "./button"; +import type { DiagramFigureInternalProps, DiagramViewerMode } from "./diagram-figure"; +import type { buildModel, DiagramSpec, figureKey, figureList, hintEntries, Measured, Model, toHtml } from "./diagram-core"; +import { attachZoom, revealIn } from "./diagram-zoom-core"; +import type { ZoomController, ZoomState } from "./diagram-zoom-core"; +import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./dialog"; +import { MinusGlyph } from "./glyphs/minus"; +import { PlusGlyph } from "./glyphs/plus"; +import { SheetFooter, SheetHeader } from "./overlays"; + +// The diagram viewer (DECISIONS 301, part 9, as DECISIONS 310): "Expand" opens the figure's drawn layout in a dialog, where the reader zooms and pans it. +// The figure is drawn again from the same data, laid out once at 100% in real CSS pixels, and zoomed with one transform (diagram-zoom-core.ts). This module +// is loaded on demand by a figure's "Expand" (diagram-figure.tsx) and brings Dialog with it; it is not exported from the package. The implementation hasn't +// been reviewed, and no seat has drawn, checked or given a position on part 9: every value is the decider's alone. + +const P = "basalt-diagram"; + +/** + * What the figure hands the viewer: its own component and the engine's functions. The viewer imports none of them, so its chunk holds the dialog, the + * buttons and the zoom, and never a second copy of the engine. + */ +export interface ViewerKit { + Figure: (props: DiagramFigureInternalProps) => React.ReactNode; + Kbd: (props: { children?: React.ReactNode }) => React.ReactNode; + buildModel: typeof buildModel; + figureKey: typeof figureKey; + figureList: typeof figureList; + hintEntries: typeof hintEntries; + toHtml: typeof toHtml; +} + +export interface DiagramViewerProps { + kit: ViewerKit; + spec: DiagramSpec; + component: string; + source?: React.ReactNode; + summary: React.ReactNode; + /** "Expand": focus returns to it when the viewer closes. */ + opener: React.RefObject; + onClose: () => void; +} + +const EMPTY: ZoomState = { zoom: 1, level: 100, fit: 1, min: 1, max: 4, atMin: false, atMax: false, atFit: true, listOpen: false }; + +/** A length token's value in CSS pixels, read from a probe the stage holds. */ +const probeWidth = (stage: HTMLElement | null, which: string) => stage?.querySelector(`.${P}-probe[data-probe="${which}"]`)?.offsetWidth ?? 0; + +export function DiagramViewer({ kit, spec, component, source, summary, opener, onClose }: DiagramViewerProps) { + const { Figure: DiagramFigure, Kbd, buildModel, figureKey, figureList, hintEntries, toHtml } = kit; + // The viewer's figure is still (9.7): no entrance, flow, mover or run, so no motion code is loaded for it. + const still = React.useMemo(() => ({ ...spec, motion: "still" }), [spec]); + const model = React.useMemo(() => buildModel(still), [still]); + const stageRef = React.useRef(null); + const sizerRef = React.useRef(null); + const layerRef = React.useRef(null); + const statusRef = React.useRef(null); + const zoomRef = React.useRef(null); + const [zoom, setZoom] = React.useState(EMPTY); + const [avail, setAvail] = React.useState(0); + const [dims, setDims] = React.useState({ row: 1104, contain: 480 }); + const [layout, setLayout] = React.useState<{ layout?: string; bare?: boolean; open?: boolean }>({}); + const [listOpen, setListOpen] = React.useState(false); + const descId = React.useId(); + + // The stage's inner width (its width less the padding of 9.4) is the width the figure may be laid out at; it is read again when the stage resizes. + const readStage = React.useCallback(() => { + const stage = stageRef.current, sizer = sizerRef.current; + if (!stage || !sizer) return; + const pad = Number.parseFloat(getComputedStyle(sizer).paddingLeft) || 0; + setAvail(Math.max(0, Math.floor(stage.clientWidth - 2 * pad))); + setDims({ row: probeWidth(stage, "row") || 1104, contain: probeWidth(stage, "contain") || 480 }); + }, []); + + // The dialog's content mounts in a portal: the stage is wired once it exists. + const [stageNode, setStageNode] = React.useState(null); + const setStage = React.useCallback((el: HTMLDivElement | null) => { stageRef.current = el; setStageNode(el); }, []); + React.useLayoutEffect(() => { + const stage = stageNode, sizer = sizerRef.current, layer = layerRef.current, status = statusRef.current; + if (!stage || !sizer || !layer || !status) return undefined; + const rest = Number.parseFloat(getComputedStyle(stage).getPropertyValue("--_rest")) || 300; + const z = attachZoom({ stage, sizer, layer, status, rest, onChange: setZoom }); + zoomRef.current = z; + readStage(); + let width = stage.clientWidth; + const observer = new ResizeObserver(() => { if (Math.abs(stage.clientWidth - width) >= 0.5) { width = stage.clientWidth; readStage(); } }); + observer.observe(stage); + // A focused card is brought into view by the least distance, space-4 clear of the stage's edge (9.5). + const onFocusIn = (event: FocusEvent) => { + const node = (event.target as HTMLElement | null)?.closest?.(`.${P}-node`); + if (node && stage.contains(node)) revealIn(stage, node, Number.parseFloat(getComputedStyle(stage).getPropertyValue("--_clear")) || 16); + }; + stage.addEventListener("focusin", onFocusIn); + return () => { z.destroy(); zoomRef.current = null; observer.disconnect(); stage.removeEventListener("focusin", onFocusIn); }; + }, [stageNode, readStage]); + + // After each layout the zoom learns the drawing's size at 100%: the figure's own box, read with the zoom taken off (offsetWidth ignores the transform). + const onMeasured = React.useCallback((measured: Measured, fig: HTMLElement) => { + setLayout({ layout: measured.dyn.layout, bare: measured.dyn.bare, open: measured.dyn.open }); + zoomRef.current?.size(fig.offsetWidth, fig.offsetHeight); + }, []); + const viewer = React.useMemo(() => (avail > 0 ? { avail, row: dims.row, contain: dims.contain, layer: () => layerRef.current, onMeasured } : undefined), [avail, dims, onMeasured]); + + // A stack with no lines has its list open, as on the page (9.3). + const showList = listOpen || Boolean(layout.bare); + React.useLayoutEffect(() => { zoomRef.current?.list(showList); }, [showList]); + + const key = figureKey(P, model); + const keyHtml = React.useMemo(() => ({ __html: key ? toHtml(key) : "" }), [key]); + const listHtml = React.useMemo(() => ({ __html: figureList(P, model).map((v) => toHtml(v)).join("") }), [model]); + const hint = hintEntries(model, true).map((entry) => ( + {entry.keys.map((k, i) => {i ? " " : null}{/* A fragment, not a string: Kbd reads a string as a shortcut, and "+" is its separator. */}<>{k})} {entry.words} + )); + const off = zoom.listOpen; + const z = () => zoomRef.current; + + return ( + { if (!next) onClose(); }}> + + + {model.title} + {source !== undefined && source !== null ?

{source}

: null} +
+ {summary} +
+
+ ); +} + diff --git a/packages/react/src/diagram-zoom-core.ts b/packages/react/src/diagram-zoom-core.ts new file mode 100644 index 00000000..c4578317 --- /dev/null +++ b/packages/react/src/diagram-zoom-core.ts @@ -0,0 +1,322 @@ +// The diagram viewer's stage (DECISIONS 301, part 9, as DECISIONS 310): zoom and pan for a figure laid out once at 100%, for React's viewer and the HTML +// skill's diagram-zoom module alike. Plain DOM and no React, so the two zoom, pan, pinch and speak the same way. Nothing here runs when the module loads. +// +// The layer holds the laid-out figure at its real CSS pixels; the zoom is one `transform: scale()` on it, inside a sizer as large as the zoomed drawing +// (plus the stage's padding) so the stage has something to scroll. A pan is a scroll. Nothing is animated: a step, the wheel and a pinch land at once. +// The engine never measures a zoomed figure: the viewer gives this the layer's size at 100% (`size`), read with the zoom taken off. + +/** The ladder the buttons and keys step on (9.4): a browser's own, shortened. */ +export const ZOOM_STEPS = [25, 33, 50, 67, 75, 100, 125, 150, 200, 300, 400]; +const MAX = 4; +const FIT_CAP = 2; +/** The wheel (9.4): the zoom is multiplied by 2 to the power of minus a hundredth of the delta, one event's delta held to 25 either way. */ +const WHEEL_STEP = 100; +const WHEEL_HOLD = 25; +const EPS = 0.0005; + +export interface ZoomState { + /** The zoom as a ratio (1 is 100%). */ + zoom: number; + /** The level as whole per cent, as the foot writes it. */ + level: number; + fit: number; + min: number; + max: number; + atMin: boolean; + atMax: boolean; + atFit: boolean; + /** "View as list" is open: the zoom controls are disabled and the stage scrolls as a page. */ + listOpen: boolean; +} + +export interface ZoomHost { + /** The scrolling box (role="group", tabindex 0). */ + stage: HTMLElement; + /** Sized to the zoomed drawing; its padding is the stage's padding (space-6 from 720, space-4 under it). */ + sizer: HTMLElement; + /** The laid-out figure's box: the transform is on it. */ + layer: HTMLElement; + /** The one polite status line, visually hidden. */ + status: HTMLElement; + /** `duration-slower` in ms: the status speaks once the level has rested this long. */ + rest: number; + onChange: (state: ZoomState) => void; +} + +export interface ZoomController { + /** The layer's laid-out size at 100%, in CSS pixels, after every layout. */ + size: (width: number, height: number) => void; + zoomIn: () => void; + zoomOut: () => void; + fit: () => void; + state: () => ZoomState; + /** The list is in the stage in place of the drawing (9.9): gestures stop; closing it brings the drawing back at its zoom and place. */ + list: (open: boolean) => void; + /** Whether the press that has just ended travelled: a travelled press is a pan, never a click. */ + travelled: () => boolean; + destroy: () => void; +} + +interface Pt { x: number; y: number } + +export function attachZoom(host: ZoomHost): ZoomController { + const { stage, sizer, layer, status } = host; + let W = 0, H = 0; + let zoom = 1, fitZoom = 1; + // The reader has zoomed: a resize keeps their zoom (inside the new limits) and the point at the middle; untouched, it stays at Fit. + let touched = false; + let listOpen = false; + let saved: { left: number; top: number } | null = null; + let spoken = ""; + let speakTimer = 0; + + const pad = () => Number.parseFloat(getComputedStyle(sizer).paddingTop) || 0; + const minOf = () => Math.min(fitZoom, 1); + const clamp = (z: number) => Math.min(MAX, Math.max(minOf(), z)); + + function computeFit() { + if (!W || !H) return 1; + const p = pad(); + const cw = stage.clientWidth - 2 * p, ch = stage.clientHeight - 2 * p; + if (cw <= 0 || ch <= 0) return Math.min(1, FIT_CAP); + // The largest whole per cent at which the whole drawing shows inside the padding, 200% at most. + const raw = Math.min(cw / W, ch / H); + return Math.min(FIT_CAP, Math.floor(raw * 100 + 1e-6) / 100); + } + + function state(): ZoomState { + const min = minOf(); + return { + zoom, level: Math.round(zoom * 100), fit: fitZoom, min, max: MAX, + atMin: zoom <= min + EPS, atMax: zoom >= MAX - EPS, atFit: Math.abs(zoom - fitZoom) < EPS, listOpen, + }; + } + function changed() { + host.onChange(state()); + stage.toggleAttribute("data-pannable", W * zoom > stage.clientWidth - 2 * pad() + 0.5 || H * zoom > stage.clientHeight - 2 * pad() + 0.5); + } + function speak() { + clearTimeout(speakTimer); + const words = `Zoom ${Math.round(zoom * 100)}%`; + // Once the level has not changed for duration-slower, so a pinch is spoken once. + speakTimer = window.setTimeout(() => { if (words !== spoken) { spoken = words; status.textContent = words; } }, host.rest); + } + + /** Writes the zoom: the sizer takes the zoomed drawing's size and the layer its scale. No transition: a zoom lands at once. */ + function paint() { + sizer.style.width = `${W * zoom}px`; + sizer.style.height = `${H * zoom}px`; + layer.style.transform = `scale(${zoom})`; + } + + /** The drawing's point (at 100%) under a point of the window. */ + function contentAt(p: Pt): Pt { + const r = layer.getBoundingClientRect(); + return { x: (p.x - r.left) / zoom, y: (p.y - r.top) / zoom }; + } + /** Scrolls so the drawing's point `c` is under the window's point `p`. */ + function holdAt(c: Pt, p: Pt) { + const r = layer.getBoundingClientRect(); + stage.scrollLeft += r.left + c.x * zoom - p.x; + stage.scrollTop += r.top + c.y * zoom - p.y; + } + const middle = (): Pt => { const r = stage.getBoundingClientRect(); return { x: r.left + stage.clientWidth / 2, y: r.top + stage.clientHeight / 2 }; }; + + function zoomTo(next: number, anchor: Pt = middle(), held?: Pt) { + if (listOpen) return; + const z = clamp(next); + if (Math.abs(z - zoom) < 1e-6) { changed(); return; } + const c = held ?? contentAt(anchor); + zoom = z; + paint(); + holdAt(c, anchor); + changed(); + speak(); + } + + function step(up: boolean) { + touched = true; + const at = zoom * 100; + const next = up ? ZOOM_STEPS.find((s) => s > at + 0.5) : [...ZOOM_STEPS].reverse().find((s) => s < at - 0.5); + zoomTo(next === undefined ? (up ? MAX : minOf()) : next / 100); + } + + function toFit() { + if (listOpen) return; + touched = false; + zoom = fitZoom; + paint(); + // At Fit the whole drawing shows: centred where it is smaller than the stage (the sizer's auto margins), from its top start corner otherwise. + stage.scrollTop = 0; + stage.scrollLeft = getComputedStyle(stage).direction === "rtl" ? stage.scrollWidth : 0; + changed(); + speak(); + } + + function size(width: number, height: number) { + const keep = touched && W && H ? contentAt(middle()) : null; + W = width; + H = height; + fitZoom = computeFit(); + if (!touched) { + zoom = fitZoom; + paint(); + stage.scrollTop = 0; + stage.scrollLeft = getComputedStyle(stage).direction === "rtl" ? stage.scrollWidth : 0; + } else { + zoom = clamp(zoom); + paint(); + if (keep) holdAt(keep, middle()); + } + changed(); + } + + // ---- The wheel: a plain wheel scrolls; with Ctrl or Command (and a trackpad pinch, sent as a wheel with Ctrl) it zooms about the pointer ---- + function onWheel(event: WheelEvent) { + if (listOpen || !(event.ctrlKey || event.metaKey)) return; + event.preventDefault(); + const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? stage.clientHeight : 1; + const delta = Math.max(-WHEEL_HOLD, Math.min(WHEEL_HOLD, event.deltaY * unit)); + touched = true; + zoomTo(zoom * 2 ** (-delta / WHEEL_STEP), { x: event.clientX, y: event.clientY }); + } + + // ---- Keys, only while focus is in the stage (WCAG 2.1.4): + or = in, - out, 0 Fit. The browser's own Ctrl and Command zoom keys are left alone ---- + function onKey(event: KeyboardEvent) { + if (event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || listOpen) return; + if (event.key === "+" || event.key === "=") { event.preventDefault(); step(true); } else if (event.key === "-" || event.key === "−") { event.preventDefault(); step(false); } else if (event.key === "0") { event.preventDefault(); toFit(); } + } + + // ---- Pan and pinch: a press that travels more than space-1 is a drag, one for one; two fingers pinch about their midpoint ---- + const pointers = new Map(); + let start: Pt | null = null; + let last: Pt | null = null; + let dragging = false; + let moved = false; + let pinch: { d0: number; z0: number; c: Pt } | null = null; + const travel = () => Number.parseFloat(getComputedStyle(stage).getPropertyValue("--_travel")) || 4; + const mid = (): Pt => { const [a, b] = [...pointers.values()]; return { x: (a!.x + b!.x) / 2, y: (a!.y + b!.y) / 2 }; }; + const spread = (): number => { const [a, b] = [...pointers.values()]; return Math.hypot(a!.x - b!.x, a!.y - b!.y); }; + + function onDown(event: PointerEvent) { + if (listOpen) return; + if (event.pointerType === "mouse" && event.button !== 0) return; + pointers.set(event.pointerId, { x: event.clientX, y: event.clientY }); + if (pointers.size === 1) { start = { x: event.clientX, y: event.clientY }; last = start; dragging = false; moved = false; } + if (pointers.size === 2 && event.pointerType === "touch") { + const m = mid(); + pinch = { d0: spread() || 1, z0: zoom, c: contentAt(m) }; + moved = true; + dragging = false; + try { stage.setPointerCapture(event.pointerId); } catch { /* the pointer has gone */ } + } + } + function onMove(event: PointerEvent) { + if (!pointers.has(event.pointerId) || listOpen) return; + pointers.set(event.pointerId, { x: event.clientX, y: event.clientY }); + if (pinch && pointers.size >= 2) { + touched = true; + const z = clamp(pinch.z0 * (spread() / pinch.d0)); + const m = mid(); + if (Math.abs(z - zoom) > 1e-6) { zoom = z; paint(); changed(); speak(); } + holdAt(pinch.c, m); + return; + } + if (pointers.size !== 1 || !start || !last) return; + const p = { x: event.clientX, y: event.clientY }; + if (!dragging) { + if (Math.hypot(p.x - start.x, p.y - start.y) <= travel()) return; + dragging = true; + moved = true; + stage.setAttribute("data-dragging", ""); + try { stage.setPointerCapture(event.pointerId); } catch { /* the pointer has gone */ } + } + stage.scrollLeft -= p.x - last.x; + stage.scrollTop -= p.y - last.y; + last = p; + event.preventDefault(); + } + function onUp(event: PointerEvent) { + if (!pointers.has(event.pointerId)) return; + pointers.delete(event.pointerId); + if (pointers.size < 2) pinch = null; + if (pointers.size === 1) { + // A pinch that leaves one finger down pans from where that finger is: no jump. + const [p] = [...pointers.values()]; + last = p!; + start = p!; + dragging = true; + return; + } + if (pointers.size === 0) { + dragging = false; + stage.removeAttribute("data-dragging"); + start = last = null; + // No momentum and no rubber band: lifted, it stops. + } + } + // A press that travelled is a pan: the click it ends in does nothing (a link is not followed, a card is not traced). + function onClick(event: MouseEvent) { + if (!moved) return; + moved = false; + event.preventDefault(); + event.stopPropagation(); + } + + const resize = new ResizeObserver(() => { + if (!W || !H) return; + const keep = touched ? contentAt(middle()) : null; + fitZoom = computeFit(); + if (!touched) { zoom = fitZoom; paint(); } else { zoom = clamp(zoom); paint(); if (keep) holdAt(keep, middle()); } + changed(); + }); + resize.observe(stage); + + stage.addEventListener("wheel", onWheel, { passive: false }); + stage.addEventListener("keydown", onKey); + stage.addEventListener("pointerdown", onDown); + stage.addEventListener("pointermove", onMove); + stage.addEventListener("pointerup", onUp); + stage.addEventListener("pointercancel", onUp); + stage.addEventListener("click", onClick, true); + + return { + size, + zoomIn: () => step(true), + zoomOut: () => step(false), + fit: toFit, + state, + list(open: boolean) { + if (open === listOpen) return; + if (open) { saved = { left: stage.scrollLeft, top: stage.scrollTop }; listOpen = true; stage.setAttribute("data-list", ""); stage.scrollTop = 0; } else { + listOpen = false; + stage.removeAttribute("data-list"); + paint(); + if (saved) { stage.scrollLeft = saved.left; stage.scrollTop = saved.top; } + saved = null; + } + changed(); + }, + travelled: () => moved, + destroy() { + clearTimeout(speakTimer); + resize.disconnect(); + stage.removeEventListener("wheel", onWheel); + stage.removeEventListener("keydown", onKey); + stage.removeEventListener("pointerdown", onDown); + stage.removeEventListener("pointermove", onMove); + stage.removeEventListener("pointerup", onUp); + stage.removeEventListener("pointercancel", onUp); + stage.removeEventListener("click", onClick, true); + }, + }; +} + +/** Brings a focused card into the stage's view by the least distance, `margin` clear of its edges (9.5). */ +export function revealIn(stage: HTMLElement, el: Element, margin: number): void { + const s = stage.getBoundingClientRect(); + const r = el.getBoundingClientRect(); + const left = s.left + margin, right = s.left + stage.clientWidth - margin, top = s.top + margin, bottom = s.top + stage.clientHeight - margin; + if (r.left < left) stage.scrollLeft -= left - r.left; else if (r.right > right) stage.scrollLeft += Math.min(r.right - right, r.left - left); + if (r.top < top) stage.scrollTop -= top - r.top; else if (r.bottom > bottom) stage.scrollTop += Math.min(r.bottom - bottom, r.top - top); +} diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index b6b849cf..d203e3ef 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4923,6 +4923,84 @@ .basalt-diagram :is(.basalt-diagram-flow, .basalt-diagram-bead, .basalt-diagram-packet, .basalt-diagram-motion-defs) { display: none !important; } } + /* ---- Diagram viewer (DECISIONS 310; part 9 of DECISIONS 301): "Expand", and the dialog where a figure's drawn layout is zoomed and panned ---- + The form dialog's box with the sheet's head, body and foot (DECISIONS 155, 222): from 720 the window less space-4 on every side, under it the whole + window. The body is the stage: it scrolls both ways, so a pan is a scroll. The figure in it is laid out once at 100% (the layer's width) and zoomed + with one transform: never a viewBox, CSS zoom, a canvas or a picture, and no layer is held (no will-change). Nothing in it moves: a zoom step lands + at once. Decided by the council's decider alone; no draft, check or position. The implementation hasn't been reviewed. */ + .basalt-diagram-expand > .basalt-icon { flex: none; } + @media (pointer: coarse) { + .basalt-diagram-expand { min-height: var(--basalt-size-tap-min); } + } + /* From 720 the window less space-4 on every side; under it the form dialog's full-screen modal, unchanged. */ + /* stylelint-disable-next-line unit-disallowed-list -- size-breakpoint-md (720px): a media query cannot read a token */ + @media (width >= 720px) { + /* stylelint-disable-next-line unit-disallowed-list -- the window less space-4 on every side (viewport units); a fixed-length token cannot say it */ + .basalt-dialog[data-form].basalt-diagram-viewer, .basalt-dialog[data-form][data-held].basalt-diagram-viewer { width: calc(100vw - 2 * var(--basalt-space-4)); max-width: none; height: calc(100dvh - 2 * var(--basalt-space-4)); max-height: none; } + } + .basalt-diagram-viewer .basalt-sheet-head { flex: none; } + .basalt-diagram-viewer-source { overflow-wrap: break-word; } + .basalt-diagram-stage { + /* The stage's padding round the drawing (9.4), the travel that makes a press a drag (space-1), the margin a focused card keeps from the edge (space-4), + and the rest before the zoom is spoken (duration-slower), read by the script. */ + --_pad: var(--basalt-space-4); + --_travel: var(--basalt-space-1); + --_clear: var(--basalt-space-4); + --_rest: var(--basalt-duration-slower); + position: relative; + flex: 1 1 auto; + display: flex; + min-height: 0; + overflow: auto; + overscroll-behavior: contain; + scrollbar-gutter: stable; + touch-action: none; + outline: none; + } + /* stylelint-disable-next-line unit-disallowed-list -- size-breakpoint-md (720px): a media query cannot read a token */ + @media (width >= 720px) { .basalt-diagram-stage { --_pad: var(--basalt-space-6); } } + /* The flush field's ring: the stage meets the dialog's clipping edges, so its ring is inset at -2. */ + .basalt-diagram-stage:focus-visible { outline: var(--basalt-size-focus-width) solid var(--basalt-border-focus); outline-offset: calc(-1 * var(--basalt-size-focus-width)); } + .basalt-diagram-stage[data-pannable] { cursor: grab; } + .basalt-diagram-stage[data-pannable][data-dragging] { cursor: grabbing; } + /* The list is the page's list, in the stage at 100%: ordinary touch scrolling, its words selectable. */ + .basalt-diagram-stage[data-list] { display: block; touch-action: pan-y; } + .basalt-diagram-probe { position: absolute; top: 0; left: 0; height: 0; visibility: hidden; pointer-events: none; } + .basalt-diagram-probe[data-probe="row"] { width: calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter)); } + .basalt-diagram-probe[data-probe="contain"] { width: var(--basalt-size-breakpoint-container); } + /* The sizer is as large as the zoomed drawing, plus the padding; its auto margins centre a drawing smaller than the stage and resolve to 0 past it. */ + .basalt-diagram-sizer { position: relative; flex: none; box-sizing: content-box; margin: auto; padding: var(--_pad); } + .basalt-diagram-sizer[hidden] { display: none; } + .basalt-diagram-layer { position: absolute; top: var(--_pad); inset-inline-start: var(--_pad); transform-origin: 0 0; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; } + .basalt-diagram-layer:dir(rtl) { transform-origin: 100% 0; } + /* The viewer's figure shows its drawing alone: the dialog holds its title, its key, its hint and its controls. */ + .basalt-diagram[data-viewer] { gap: 0; } + .basalt-diagram[data-viewer] > :is(.basalt-diagram-head, .basalt-diagram-key, .basalt-diagram-hint, .basalt-diagram-foot, .basalt-diagram-list, .basalt-diagram-summary) { display: none; } + .basalt-diagram-viewer-list { box-sizing: border-box; max-width: calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter) + 2 * var(--_pad)); padding: var(--_pad); } + .basalt-diagram-viewer-foot { display: flex; flex-direction: column; gap: var(--basalt-space-3); padding-block-start: var(--basalt-space-3); } + .basalt-diagram-viewer-key { --_ground: var(--_surface, var(--basalt-surface-overlay)); } + .basalt-diagram-viewer-key .basalt-diagram-key { padding-block-start: 0; border-top: 0; } + .basalt-diagram-viewer-key[data-layout="drawn"] .basalt-diagram-entry[data-when="stacked"], .basalt-diagram-viewer-key[data-layout="stacked"] .basalt-diagram-entry[data-when="drawn"], .basalt-diagram-viewer-key[data-bare] .basalt-diagram-entry[data-line] { display: none; } + .basalt-diagram-viewer-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--basalt-space-2); } + .basalt-diagram-zoom { display: flex; align-items: center; gap: var(--basalt-space-1); } + /* The level between the two buttons, its width held for "400%" so the buttons never move. */ + .basalt-diagram-level { display: inline-grid; justify-items: center; color: var(--basalt-text-secondary); font: var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans); font-variant-numeric: tabular-nums; } + .basalt-diagram-level::before { content: attr(data-reserve); grid-area: 1 / 1; visibility: hidden; } + .basalt-diagram-level > span { grid-area: 1 / 1; } + .basalt-diagram-viewer-hint { flex: 1 1 auto; min-width: 0; } + .basalt-diagram-viewer-end { display: flex; gap: var(--basalt-space-2); margin-inline-start: auto; } + @media (pointer: coarse) { + .basalt-diagram-zoom .basalt-button, .basalt-diagram-viewer-end .basalt-button { min-height: var(--basalt-size-tap-min); min-width: var(--basalt-size-tap-min); } + } + @media (forced-colors: active) { + .basalt-diagram-level { color: CanvasText; } + .basalt-diagram-viewer-foot [aria-disabled="true"] { color: GrayText; } + } + /* The viewer and its scrim do not print: the page prints its own figure, untraced and light. "Expand" does not print. */ + @media print { + .basalt-diagram-expand, .basalt-diagram-viewer, :root:has(.basalt-diagram-viewer) .basalt-dialog-backdrop { display: none !important; } + } + /* ---- Lit figures, the headline frame and N1's figures (DECISIONS 153) ---- Ported from the owner's approved prototypes, with the council's changes. The lit gradient is three neutral stops that each hold 3:1 on levels 0 to 3; a lit line is one stroke in the top stop; there is no area under a line, no cursor, no halo and no plate on a trend. The implementation hasn't been reviewed. */ From 50e033249a5f69484f51de8e2a0b927367744838 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:02:42 -0600 Subject: [PATCH 02/62] The diagram viewer in the HTML skill (DECISIONS 310): the diagram-zoom module compose.mjs adds diagram-zoom (with dialog, dialog-form and sheet) to a page with a figure, unless every figure says "zoom": false. It shares React's zoom and pan (diagram-zoom-core.ts) and draws with the diagram module's engine (Basalt._.diagramKit), so it holds no second copy of it. Its stylesheet is React's "Diagram viewer" section, renamed. The viewer's layout moves into the engine (measureViewerFigure), for both: it measures at 100% whatever the zoom and whatever an opening dialog's scale. Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/SKILL.md | 1 + .agent/skills/basalt-html/compose.mjs | 15 +- .../basalt-html/parts/diagram-motion.js | 2 +- .../skills/basalt-html/parts/diagram-zoom.css | 1 + .../skills/basalt-html/parts/diagram-zoom.js | 1 + .agent/skills/basalt-html/parts/diagram.js | 4 +- .agent/skills/basalt-html/parts/icons.json | 2 +- .agent/skills/basalt-html/parts/manifest.json | 36 +++++ .../basalt-html/parts/usage/diagram-zoom.md | 8 + packages/react/src/diagram-core.ts | 56 +++++++ packages/react/src/diagram-figure.tsx | 41 +---- tools/html-skill/build.mjs | 23 ++- tools/html-skill/src/compose.mjs | 15 +- tools/html-skill/src/icons.json | 2 +- tools/html-skill/src/modules.json | 36 +++++ tools/html-skill/src/modules/diagram-zoom.js | 150 ++++++++++++++++++ tools/html-skill/src/modules/diagram.js | 30 ++-- tools/html-skill/src/usage/diagram-zoom.md | 8 + 18 files changed, 376 insertions(+), 55 deletions(-) create mode 100644 .agent/skills/basalt-html/parts/diagram-zoom.css create mode 100644 .agent/skills/basalt-html/parts/diagram-zoom.js create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-zoom.md create mode 100644 tools/html-skill/src/modules/diagram-zoom.js create mode 100644 tools/html-skill/src/usage/diagram-zoom.md diff --git a/.agent/skills/basalt-html/SKILL.md b/.agent/skills/basalt-html/SKILL.md index 6f9b321a..5c6b0580 100644 --- a/.agent/skills/basalt-html/SKILL.md +++ b/.agent/skills/basalt-html/SKILL.md @@ -64,6 +64,7 @@ Markup built only at run time (a `.row` your script writes) won't be seen: add ` - **chart** `.chart`: JSON in `script[data-chart]`; `null` is a day not observed, never zero; needs a `summary`. - **diagram** `.diagram`: JSON in `script[data-diagram]`; sides only to change the default; needs a `summary`. - **diagram-motion** `"motion": "animated"`: added for you, with `loops`; a flow line needs a label; one mover a figure. +- **diagram-zoom** added for you with a diagram ("Expand", the viewer); `"zoom": false` on every figure leaves it out. - **sparkline** `.sparkline`: JSON in `script[data-sparkline]`; one line, no axes or series (that is a `chart`). - **palette** `data-open-palette`, `Basalt.init({ palette })`: `keys` is an array, `['⌘', 'S']`: ⌘, ⌃ or ⌥ plus one key. - **command-list** `.command-list`: the script builds it; items are the palette's; ⌘K goes to the palette when the page has one. diff --git a/.agent/skills/basalt-html/compose.mjs b/.agent/skills/basalt-html/compose.mjs index d1cf730f..3e5722c6 100644 --- a/.agent/skills/basalt-html/compose.mjs +++ b/.agent/skills/basalt-html/compose.mjs @@ -555,7 +555,12 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts = // Detection reads markup and code, never comments: a word written about in a comment (an HTML one, or one inside a script or a style) brings nothing in. const code = `${held.restore(markup, true)}\n${styles.map((style) => stripCssComments(style.css)).join("\n")}`; - const chosen = detect(code, manifest, Object.keys(iconFile.icons), { all, use, glyphNames: Object.keys(glyphFile) }); + let chosen = detect(code, manifest, Object.keys(iconFile.icons), { all, use, glyphNames: Object.keys(glyphFile) }); + // The diagram viewer (DECISIONS 310): a page with a figure has "Expand" and its dialog, unless every figure on it says "zoom": false. A figure drawn from + // script (Basalt.diagram) may want it, so it counts. + if (chosen.modules.includes("diagram") && !chosen.modules.includes("diagram-zoom") && "diagram-zoom" in manifest.modules && zoomWanted(held, code)) { + chosen = detect(code, manifest, Object.keys(iconFile.icons), { all, use: [...use, "diagram-zoom"], glyphNames: Object.keys(glyphFile) }); + } // A module the body never triggers, which is in only because another module's script builds its markup (the palette's rows and key chips). const bare = { ...manifest, modules: Object.fromEntries(Object.entries(manifest.modules).map(([n, m]) => [n, { ...m, requires: [] }])) }; const direct = detect(code, bare, [], { all, use }).modules; @@ -603,6 +608,14 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts = return { html, modules: chosen.modules, icons: chosen.icons, glyphs: chosen.glyphs, built, external: externalReferences(held, markup), diagrams: diagramNotes, bytes: Buffer.byteLength(html) }; } +/** Whether any figure on the page keeps its viewer: a `data-diagram` JSON without `"zoom": false`, or a figure drawn from script. */ +function zoomWanted(held, code) { + if (/Basalt\s*\.\s*diagram\b/.test(code)) return true; + const specs = held.saved.filter((item) => item.kind === "script" && item.attrs.some(([k]) => k === "data-diagram")); + if (!specs.length) return true; + return specs.some((item) => { try { return JSON.parse(item.inner).zoom !== false; } catch { return true; } }); +} + /** * A diagram's words, written into the page (DECISIONS 281, 1.19): each `
` that holds only its JSON gets the markup the diagram module's * script would write for it, from that same script (parts/diagram.js, run here without a page), so the page reads before any script runs. The figure's own diff --git a/.agent/skills/basalt-html/parts/diagram-motion.js b/.agent/skills/basalt-html/parts/diagram-motion.js index cbbf0b25..50fd9f89 100644 --- a/.agent/skills/basalt-html/parts/diagram-motion.js +++ b/.agent/skills/basalt-html/parts/diagram-motion.js @@ -1 +1 @@ -(()=>{var C=Object.defineProperty,T=(t,s,e)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s,e)=>T(t,typeof s!="symbol"?s+"":s,e);function P(t,s){const e=o=>String(Math.round(o*100)/100);let i=`M${e(t[0].x)} ${e(t[0].y)}`;for(let o=1;o{for(const h of p?.figs??[])h.sync()},e=()=>{for(const h of p?.figs??[])x(h.host.fig);s()},i=new IntersectionObserver(h=>{for(const r of h)for(const a of p?.figs??[])a.drawing===r.target&&a.seen(r)},{threshold:Array.from({length:21},(h,r)=>r/20)}),n=new MutationObserver(h=>{for(const r of h){if(r.target===document.documentElement){for(const a of p?.figs??[])a.holdChanged();continue}for(const a of p?.figs??[])a.host.fig===r.target&&a.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const o=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of o)h.addEventListener("change",s);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",s),p={figs:new Set,io:i,mo:n,media:o,onChange:s,onPrint:e}}return p.figs.add(t),t.drawing&&p.io.observe(t.drawing),p.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing"]}),p}function O(t){if(p&&(p.figs.delete(t),t.drawing&&p.io.unobserve(t.drawing),!p.figs.size)){p.io.disconnect(),p.mo.disconnect();for(const s of p.media)s.removeEventListener("change",p.onChange);window.removeEventListener("beforeprint",p.onPrint),document.removeEventListener("visibilitychange",p.onChange),p=void 0}}function _(t){const s=getComputedStyle(t),e=h=>s.getPropertyValue(`--basalt-${h}`).trim(),i=h=>{const r=e(h),a=parseFloat(r);return/ms$/.test(r)?a:/s$/.test(r)?a*1e3:a||0},n=h=>parseFloat(e(h))||0,o=h=>e(`ease-${h}`)||"ease";return{lineMin:i("duration-diagram-line-min"),lineMax:i("duration-diagram-line-max"),stagger:i("duration-diagram-stagger"),step:i("duration-diagram-step"),arrow:i("duration-diagram-arrow"),limit:i("duration-diagram-limit"),legMin:i("duration-diagram-leg-min"),legMax:i("duration-diagram-leg-max"),rest:i("duration-diagram-rest"),pause:i("duration-diagram-pause"),repeat:i("duration-diagram-repeat"),fast:i("duration-fast"),base:i("duration-base"),slow:i("duration-slow"),slower:i("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:o("in-out"),out:o("out"),in:o("in")}}var L=(t,s,e)=>Math.max(s,Math.min(e,t)),F="http://www.w3.org/2000/svg",y=(t,s,e)=>{const i=document.createElementNS(F,t);for(const[n,o]of Object.entries(s))i.setAttribute(n,String(o));return e?.appendChild(i),i},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",R={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function $(t,s){const e=t.pts.map(a=>({...a})),i=R[t.dir],n=e[e.length-1],o=e[e.length-2],h=Math.hypot(n.x-o.x,n.y-o.y),r=Math.min(s,Math.max(0,h-.5));return n.x-=i.x*r,n.y-=i.y*r,e}var M=t=>t.slice(1).reduce((s,e,i)=>s+Math.hypot(e.x-t[i].x,e.y-t[i].y),0),I=(t,s)=>{const e=t.map(n=>n.x),i=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-s),t:Math.floor(Math.min(...i)-s),r:Math.ceil(Math.max(...e)+s),b:Math.ceil(Math.max(...i)+s)}},V=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",s=>(this.listeners.add(s),()=>{this.listeners.delete(s)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const s of[...this.flowEls.values(),...this.beadEls.values()])s.remove();this.dot?.remove(),O(this)}}),c(this,"onSettle",()=>{this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const i=this.introEnd?.currentTime,n=i!=null?Number(i):E()-this.t0,o=new Set([...this.plans].filter(([,a])=>a.end<=n).map(([a])=>a)),{plans:h,factor:r}=this.plan(this.ordered(e),this.factor);for(const a of o){const l=this.plans.get(a);l&&h.set(a,l)}this.factor=r,this.plans=h,this.build(o,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const s=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(i=>!!i.flow)]);s!==this.signature&&(this.signature=s,x(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",s=>{if(!this.lastSend){this.lastSend={v:s};return}s===void 0||s===this.lastSend.v||(this.lastSend={v:s},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}x(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=_(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=G(this),this.sync()}publish(){const t=this.hasLines(),s=this.host.model(),e=this.modes(),i=s.edges.some(o=>o.flow)||!!s.motion.pulse||!!s.motion.packet?.repeat,n={canLoop:s.motion.animated&&i&&t&&!e.reduce&&!e.forced,runShown:s.motion.animated&&s.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const o of this.listeners)o()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")}seen(t){this.inView=t.isIntersecting;const s=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=s-.5,this.sync()}holdChanged(){this.modes().held&&x(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,s=this.host.model(),e=this.modes(),i=this.entrance();(i==="pending"||i==="running")&&(e.held||e.print||e.reduce||e.forced)?x(t):i==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!i&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(s,e),this.publish()}ordered(t){const s=this.host.model(),e=[...t.lines];return s.type==="schema"?e.sort((i,n)=>i.pts[0].y-n.pts[0].y||i.pts[0].x-n.pts[0].x||i.i-n.i):e.sort((i,n)=>i.i-n.i),e}plan(t,s){const e=this.t,i=this.host.model().type==="sequence",n=i?e.step:e.stagger,o=t.map(a=>{const l=this.lineEl(a)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(a.pts),g=i?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=i?e.base:0;return{lead:u,dur:g,tail:u+Math.max(g,.85*g+e.slow,i?e.slower:0)}});let h=1;for(let a=1;a{const d=l*n*h;r.set(a.i,{start:d+o[l].lead,dur:o[l].dur,end:d+o[l].tail})}),{plans:r,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.t0=E();const{plans:s,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=s,this.build(new Set,!0)}build(t,s){const e=this.host.geo(),i=this.host.fig,{P:n}=this.host,o=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const r=i.querySelector(`.${n}-ink`),a=r?.querySelector(`.${n}-svg`);if(!r||!a)return;this.defs=y("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),a.after(this.defs);const l=y("defs",{},this.defs),d=(u,m=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),m.add(u),u);let g=0;for(const u of e.lines){const m=this.plans.get(u.i),f=this.lineEl(u);if(!m||!f)continue;if(g=Math.max(g,m.end),t.has(u.i)){f.removeAttribute("mask");continue}const w=`${this.host.base}-reveal-${u.i}`,k=y("mask",{id:w,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),A=f.querySelector(`.${n}-line`);if(A){const b=A.getTotalLength(),z=y("path",{d:A.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${b} ${b+8}`,"stroke-dashoffset":b},k);d(z.animate([{strokeDashoffset:`${b}px`},{strokeDashoffset:"0px"}],{duration:m.dur,delay:m.start,easing:o.inOut,fill:"both"}))}const S=f.querySelector(`.${n}-tip`);if(S){const b=y("path",{d:S.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:o.slow,delay:m.start+.85*m.dur,easing:o.out,fill:"both"}))}const v=f.querySelector(`.${n}-dot`);if(v){const b=y("circle",{cx:v.getAttribute("cx")??0,cy:v.getAttribute("cy")??0,r:Number(v.getAttribute("r")??3)+1,fill:"#fff"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:o.fast,delay:m.start,easing:o.out,fill:"both"}))}f.setAttribute("mask",`url(#${w})`)}if(s&&this.host.model().type==="sequence"){const u=getComputedStyle(i),m=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),w=i.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((k,A)=>{const S=w[A]?.querySelector(`.${n}-mlabel`),v=this.plans.get(k.i);S&&v&&m&&f&&d(S.animate([{color:m},{color:f}],{duration:o.slower,delay:v.start-o.base,easing:o.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(i.animate([],{duration:Math.max(1,g)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,s){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||s.reduce||s.forced||s.print||s.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,s){s.add(t);const e=()=>{s.delete(t)};return t.finished.then(e,e),s===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,s){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),s).finished.then(e=>{e.cancel()})}overlay(t,s,e){const i=this.host.fig.querySelector(`.${this.host.P}-ink`),n=i?.querySelector(`.${this.host.P}-svg`);if(!i||!n)return null;const o=this.host.tokens(),h=$(t,o?.head??8),r=I(h,s),a=y("svg",{class:`${this.host.P}-${e}`,width:r.r-r.l,height:r.b-r.t,viewBox:`${r.l} ${r.t} ${r.r-r.l} ${r.b-r.t}`,"aria-hidden":"true",focusable:"false"});a.style.left=`${r.l}px`,a.style.top=`${r.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(a),{svg:a,d:P(h,t.from===t.to?o?.radiusXs??4:o?.radius??8),pts:h}}visible(t,s){const e=this.host.geo();let i=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const o=(n.box.t+n.box.b)/2,h=s.some((r,a)=>a>0&&Math.abs(r.y-s[a-1].y)<.5&&Math.abs(o-r.y)<1.5);i+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(s)-i}flow(t,s){const e=t.lines.find(r=>r.i===s);if(!e)return;const i=this.host.tokens();let n=this.flowEls.get(s);if(n&&!n.isConnected&&(this.flowEls.delete(s),n=void 0),!n){const r=i?.space("1")??4,a=this.overlay({...e,pts:$(e,r)},e.width+2,"flow");if(!a)return;if(this.visible(e,$(e,i?.head??8))<48){a.svg.remove();return}const l=i?.cut??2;y("path",{d:a.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},a.svg),n=a.svg,this.flowEls.set(s,n)}n.style.display="";const o=n.firstElementChild,h=this.t.flowPeriod;this.track(o.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,s){const i=this.host.model().edges.find(n=>n.from===t&&n.to===s);return i?this.host.geo()?.lines.find(n=>n.i===i.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,s){const e=this.host.tokens();for(;t===this.loopGen;){for(let i=1;it===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(s,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const i=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=i;try{await i.finished}finally{this.repeatGap===i&&(this.repeatGap=null),i.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),s=t.motion.packet?.path;if(!t.motion.animated||!s||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(s[s.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const i=++this.runGen;this.packetRun(s,this.runAnims,()=>i===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&i===this.runGen&&(this.waiting=!1,this.send())})}stopRun(){this.runGen++,this.runAt=-1;for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const s=this.host.geo();if(!s?.lines.length)return;for(const r of this.runAnims)r.cancel();this.runAnims.clear();const e=++this.runGen,i=()=>e===this.runGen,n=this.ordered(s),o=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let r=t;r{if(!q(r))throw r})}};function N(t){const s=[],e=[],{pulse:i,packet:n}=t.motion;i&&n&&s.push("a figure names both a pulse and a packet: it has one mover at most");const o=i??n?.path,h=i?"pulse":"packet",r=new Set;if(o){for(const a of o)t.byId.has(a)||s.push(`the ${h} names ${a}, which is not a node`);for(let a=1;ad.from===o[a-1]&&d.to===o[a]);l?r.add(l.i):s.push(`the ${h} goes from ${o[a-1]} to ${o[a]}, and no line joins them in that direction`)}}for(const a of t.edges)a.flow&&(a.kind==="dashed"&&s.push(`the line from ${a.from} to ${a.to} is dashed and flows: flow is on a main or plain line only`),r.has(a.i)&&s.push(`the line from ${a.from} to ${a.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),a.label||e.push(`the line from ${a.from} to ${a.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:s,warnings:e}}function D(t){return new V(t)}(function(t){"use strict";var s=t._;function e(i,n,o){var h=document.createElement("button");return h.type="button",h.className="btn "+i,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),o&&o(h),h.appendChild(document.createTextNode(n)),h}s.diagramMotion=function(i,n,o){var h=N(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var r=D(n),a=i.querySelector(".diagram-foot"),l=null,d=null;a&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){r.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var w=document.createElement("span");w.className="btn-check",w.setAttribute("aria-hidden","true"),f.appendChild(w)}),l.hidden=d.hidden=!0,a.appendChild(l),a.appendChild(d));function g(){var f=r.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=r.subscribe(g);g();var m=o&&o.packet?o.packet.send:void 0;return r.sendValue("__diagramSend"in i?i.__diagramSend:m),r.sendValue(m),i.__diagramSend=m,{redrawn:r.redrawn,sendValue:function(f){r.sendValue(f),i.__diagramSend=f},destroy:function(){u(),r.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); +(()=>{var C=Object.defineProperty,T=(t,s,e)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s,e)=>T(t,typeof s!="symbol"?s+"":s,e);function P(t,s){const e=o=>String(Math.round(o*100)/100);let i=`M${e(t[0].x)} ${e(t[0].y)}`;for(let o=1;o{for(const h of p?.figs??[])h.sync()},e=()=>{for(const h of p?.figs??[])x(h.host.fig);s()},i=new IntersectionObserver(h=>{for(const r of h)for(const a of p?.figs??[])a.drawing===r.target&&a.seen(r)},{threshold:Array.from({length:21},(h,r)=>r/20)}),n=new MutationObserver(h=>{for(const r of h){if(r.target===document.documentElement){for(const a of p?.figs??[])a.holdChanged();continue}for(const a of p?.figs??[])a.host.fig===r.target&&a.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const o=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of o)h.addEventListener("change",s);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",s),p={figs:new Set,io:i,mo:n,media:o,onChange:s,onPrint:e}}return p.figs.add(t),t.drawing&&p.io.observe(t.drawing),p.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),p}function O(t){if(p&&(p.figs.delete(t),t.drawing&&p.io.unobserve(t.drawing),!p.figs.size)){p.io.disconnect(),p.mo.disconnect();for(const s of p.media)s.removeEventListener("change",p.onChange);window.removeEventListener("beforeprint",p.onPrint),document.removeEventListener("visibilitychange",p.onChange),p=void 0}}function _(t){const s=getComputedStyle(t),e=h=>s.getPropertyValue(`--basalt-${h}`).trim(),i=h=>{const r=e(h),a=parseFloat(r);return/ms$/.test(r)?a:/s$/.test(r)?a*1e3:a||0},n=h=>parseFloat(e(h))||0,o=h=>e(`ease-${h}`)||"ease";return{lineMin:i("duration-diagram-line-min"),lineMax:i("duration-diagram-line-max"),stagger:i("duration-diagram-stagger"),step:i("duration-diagram-step"),arrow:i("duration-diagram-arrow"),limit:i("duration-diagram-limit"),legMin:i("duration-diagram-leg-min"),legMax:i("duration-diagram-leg-max"),rest:i("duration-diagram-rest"),pause:i("duration-diagram-pause"),repeat:i("duration-diagram-repeat"),fast:i("duration-fast"),base:i("duration-base"),slow:i("duration-slow"),slower:i("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:o("in-out"),out:o("out"),in:o("in")}}var L=(t,s,e)=>Math.max(s,Math.min(e,t)),F="http://www.w3.org/2000/svg",w=(t,s,e)=>{const i=document.createElementNS(F,t);for(const[n,o]of Object.entries(s))i.setAttribute(n,String(o));return e?.appendChild(i),i},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",R={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function $(t,s){const e=t.pts.map(a=>({...a})),i=R[t.dir],n=e[e.length-1],o=e[e.length-2],h=Math.hypot(n.x-o.x,n.y-o.y),r=Math.min(s,Math.max(0,h-.5));return n.x-=i.x*r,n.y-=i.y*r,e}var M=t=>t.slice(1).reduce((s,e,i)=>s+Math.hypot(e.x-t[i].x,e.y-t[i].y),0),I=(t,s)=>{const e=t.map(n=>n.x),i=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-s),t:Math.floor(Math.min(...i)-s),r:Math.ceil(Math.max(...e)+s),b:Math.ceil(Math.max(...i)+s)}},V=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",s=>(this.listeners.add(s),()=>{this.listeners.delete(s)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const s of[...this.flowEls.values(),...this.beadEls.values()])s.remove();this.dot?.remove(),O(this)}}),c(this,"onSettle",()=>{this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const i=this.introEnd?.currentTime,n=i!=null?Number(i):E()-this.t0,o=new Set([...this.plans].filter(([,a])=>a.end<=n).map(([a])=>a)),{plans:h,factor:r}=this.plan(this.ordered(e),this.factor);for(const a of o){const l=this.plans.get(a);l&&h.set(a,l)}this.factor=r,this.plans=h,this.build(o,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const s=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(i=>!!i.flow)]);s!==this.signature&&(this.signature=s,x(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",s=>{if(!this.lastSend){this.lastSend={v:s};return}s===void 0||s===this.lastSend.v||(this.lastSend={v:s},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}x(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=_(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=G(this),this.sync()}publish(){const t=this.hasLines(),s=this.host.model(),e=this.modes(),i=s.edges.some(o=>o.flow)||!!s.motion.pulse||!!s.motion.packet?.repeat,n={canLoop:s.motion.animated&&i&&t&&!e.reduce&&!e.forced,runShown:s.motion.animated&&s.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const o of this.listeners)o()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const s=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=s-.5,this.sync()}holdChanged(){this.modes().held&&x(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,s=this.host.model(),e=this.modes(),i=this.entrance();(i==="pending"||i==="running")&&(e.held||e.print||e.reduce||e.forced)?x(t):i==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!i&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(s,e),this.publish()}ordered(t){const s=this.host.model(),e=[...t.lines];return s.type==="schema"?e.sort((i,n)=>i.pts[0].y-n.pts[0].y||i.pts[0].x-n.pts[0].x||i.i-n.i):e.sort((i,n)=>i.i-n.i),e}plan(t,s){const e=this.t,i=this.host.model().type==="sequence",n=i?e.step:e.stagger,o=t.map(a=>{const l=this.lineEl(a)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(a.pts),m=i?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=i?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,i?e.slower:0)}});let h=1;for(let a=1;a{const d=l*n*h;r.set(a.i,{start:d+o[l].lead,dur:o[l].dur,end:d+o[l].tail})}),{plans:r,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.t0=E();const{plans:s,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=s,this.build(new Set,!0)}build(t,s){const e=this.host.geo(),i=this.host.fig,{P:n}=this.host,o=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const r=i.querySelector(`.${n}-ink`),a=r?.querySelector(`.${n}-svg`);if(!r||!a)return;this.defs=w("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),a.after(this.defs);const l=w("defs",{},this.defs),d=(u,g=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),g.add(u),u);let m=0;for(const u of e.lines){const g=this.plans.get(u.i),f=this.lineEl(u);if(!g||!f)continue;if(m=Math.max(m,g.end),t.has(u.i)){f.removeAttribute("mask");continue}const y=`${this.host.base}-reveal-${u.i}`,k=w("mask",{id:y,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),A=f.querySelector(`.${n}-line`);if(A){const b=A.getTotalLength(),z=w("path",{d:A.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${b} ${b+8}`,"stroke-dashoffset":b},k);d(z.animate([{strokeDashoffset:`${b}px`},{strokeDashoffset:"0px"}],{duration:g.dur,delay:g.start,easing:o.inOut,fill:"both"}))}const S=f.querySelector(`.${n}-tip`);if(S){const b=w("path",{d:S.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:o.slow,delay:g.start+.85*g.dur,easing:o.out,fill:"both"}))}const v=f.querySelector(`.${n}-dot`);if(v){const b=w("circle",{cx:v.getAttribute("cx")??0,cy:v.getAttribute("cy")??0,r:Number(v.getAttribute("r")??3)+1,fill:"#fff"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:o.fast,delay:g.start,easing:o.out,fill:"both"}))}f.setAttribute("mask",`url(#${y})`)}if(s&&this.host.model().type==="sequence"){const u=getComputedStyle(i),g=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),y=i.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((k,A)=>{const S=y[A]?.querySelector(`.${n}-mlabel`),v=this.plans.get(k.i);S&&v&&g&&f&&d(S.animate([{color:g},{color:f}],{duration:o.slower,delay:v.start-o.base,easing:o.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(i.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,s){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||s.reduce||s.forced||s.print||s.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,s){s.add(t);const e=()=>{s.delete(t)};return t.finished.then(e,e),s===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,s){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),s).finished.then(e=>{e.cancel()})}overlay(t,s,e){const i=this.host.fig.querySelector(`.${this.host.P}-ink`),n=i?.querySelector(`.${this.host.P}-svg`);if(!i||!n)return null;const o=this.host.tokens(),h=$(t,o?.head??8),r=I(h,s),a=w("svg",{class:`${this.host.P}-${e}`,width:r.r-r.l,height:r.b-r.t,viewBox:`${r.l} ${r.t} ${r.r-r.l} ${r.b-r.t}`,"aria-hidden":"true",focusable:"false"});a.style.left=`${r.l}px`,a.style.top=`${r.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(a),{svg:a,d:P(h,t.from===t.to?o?.radiusXs??4:o?.radius??8),pts:h}}visible(t,s){const e=this.host.geo();let i=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const o=(n.box.t+n.box.b)/2,h=s.some((r,a)=>a>0&&Math.abs(r.y-s[a-1].y)<.5&&Math.abs(o-r.y)<1.5);i+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(s)-i}flow(t,s){const e=t.lines.find(r=>r.i===s);if(!e)return;const i=this.host.tokens();let n=this.flowEls.get(s);if(n&&!n.isConnected&&(this.flowEls.delete(s),n=void 0),!n){const r=i?.space("1")??4,a=this.overlay({...e,pts:$(e,r)},e.width+2,"flow");if(!a)return;if(this.visible(e,$(e,i?.head??8))<48){a.svg.remove();return}const l=i?.cut??2;w("path",{d:a.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},a.svg),n=a.svg,this.flowEls.set(s,n)}n.style.display="";const o=n.firstElementChild,h=this.t.flowPeriod;this.track(o.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,s){const i=this.host.model().edges.find(n=>n.from===t&&n.to===s);return i?this.host.geo()?.lines.find(n=>n.i===i.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,s){const e=this.host.tokens();for(;t===this.loopGen;){for(let i=1;it===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(s,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const i=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=i;try{await i.finished}finally{this.repeatGap===i&&(this.repeatGap=null),i.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),s=t.motion.packet?.path;if(!t.motion.animated||!s||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(s[s.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const i=++this.runGen;this.packetRun(s,this.runAnims,()=>i===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&i===this.runGen&&(this.waiting=!1,this.send())})}stopRun(){this.runGen++,this.runAt=-1;for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const s=this.host.geo();if(!s?.lines.length)return;for(const r of this.runAnims)r.cancel();this.runAnims.clear();const e=++this.runGen,i=()=>e===this.runGen,n=this.ordered(s),o=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let r=t;r{if(!q(r))throw r})}};function N(t){const s=[],e=[],{pulse:i,packet:n}=t.motion;i&&n&&s.push("a figure names both a pulse and a packet: it has one mover at most");const o=i??n?.path,h=i?"pulse":"packet",r=new Set;if(o){for(const a of o)t.byId.has(a)||s.push(`the ${h} names ${a}, which is not a node`);for(let a=1;ad.from===o[a-1]&&d.to===o[a]);l?r.add(l.i):s.push(`the ${h} goes from ${o[a-1]} to ${o[a]}, and no line joins them in that direction`)}}for(const a of t.edges)a.flow&&(a.kind==="dashed"&&s.push(`the line from ${a.from} to ${a.to} is dashed and flows: flow is on a main or plain line only`),r.has(a.i)&&s.push(`the line from ${a.from} to ${a.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),a.label||e.push(`the line from ${a.from} to ${a.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:s,warnings:e}}function D(t){return new V(t)}(function(t){"use strict";var s=t._;function e(i,n,o){var h=document.createElement("button");return h.type="button",h.className="btn "+i,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),o&&o(h),h.appendChild(document.createTextNode(n)),h}s.diagramMotion=function(i,n,o){var h=N(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var r=D(n),a=i.querySelector(".diagram-foot"),l=null,d=null;a&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){r.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var y=document.createElement("span");y.className="btn-check",y.setAttribute("aria-hidden","true"),f.appendChild(y)}),l.hidden=d.hidden=!0,a.appendChild(l),a.appendChild(d));function m(){var f=r.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=r.subscribe(m);m();var g=o&&o.packet?o.packet.send:void 0;return r.sendValue("__diagramSend"in i?i.__diagramSend:g),r.sendValue(g),i.__diagramSend=g,{redrawn:r.redrawn,sendValue:function(f){r.sendValue(f),i.__diagramSend=f},destroy:function(){u(),r.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.css b/.agent/skills/basalt-html/parts/diagram-zoom.css new file mode 100644 index 00000000..07bcc2e5 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-zoom.css @@ -0,0 +1 @@ +@layer basalt{.diagram-expand>.icon{flex:none}@media(pointer:coarse){.diagram-expand{min-height:var(--basalt-size-tap-min)}}@media(width>=720px){.dialog[data-form].diagram-viewer,.dialog[data-form][data-held].diagram-viewer{width:calc(100vw - 2 * var(--basalt-space-4));max-width:none;height:calc(100dvh - 2 * var(--basalt-space-4));max-height:none}}.diagram-viewer .sheet-head{flex:none}.diagram-viewer-source{overflow-wrap:break-word}.diagram-stage{--_pad: var(--basalt-space-4);--_travel: var(--basalt-space-1);--_clear: var(--basalt-space-4);--_rest: var(--basalt-duration-slower);position:relative;flex:1 1 auto;display:flex;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;touch-action:none;outline:none}@media(width>=720px){.diagram-stage{--_pad: var(--basalt-space-6)}}.diagram-stage:focus-visible{outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:calc(-1 * var(--basalt-size-focus-width))}.diagram-stage[data-pannable]{cursor:grab}.diagram-stage[data-pannable][data-dragging]{cursor:grabbing}.diagram-stage[data-list]{display:block;touch-action:pan-y}.diagram-probe{position:absolute;top:0;left:0;height:0;visibility:hidden;pointer-events:none}.diagram-probe[data-probe=row]{width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter))}.diagram-probe[data-probe=contain]{width:var(--basalt-size-breakpoint-container)}.diagram-sizer{position:relative;flex:none;box-sizing:content-box;margin:auto;padding:var(--_pad)}.diagram-sizer[hidden]{display:none}.diagram-layer{position:absolute;top:var(--_pad);inset-inline-start:var(--_pad);transform-origin:0 0;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}.diagram-layer:dir(rtl){transform-origin:100% 0}.diagram[data-viewer]{gap:0}.diagram[data-viewer]>:is(.diagram-head,.diagram-key,.diagram-hint,.diagram-foot,.diagram-list,.diagram-summary){display:none}.diagram-viewer-list{box-sizing:border-box;max-width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter) + 2 * var(--_pad));padding:var(--_pad)}.diagram-viewer-foot{display:flex;flex-direction:column;gap:var(--basalt-space-3);padding-block-start:var(--basalt-space-3)}.diagram-viewer-key{--_ground: var(--panel-bg, var(--basalt-surface-overlay))}.diagram-viewer-key .diagram-key{padding-block-start:0;border-top:0}.diagram-viewer-key[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram-viewer-key[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram-viewer-key[data-bare] .diagram-entry[data-line]{display:none}.diagram-viewer-row{display:flex;flex-wrap:wrap;align-items:center;gap:var(--basalt-space-2)}.diagram-zoom{display:flex;align-items:center;gap:var(--basalt-space-1)}.diagram-level{display:inline-grid;justify-items:center;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans);font-variant-numeric:tabular-nums}.diagram-level:before{content:attr(data-reserve);grid-area:1 / 1;visibility:hidden}.diagram-level>span{grid-area:1 / 1}.diagram-viewer-hint{flex:1 1 auto;min-width:0}.diagram-viewer-end{display:flex;gap:var(--basalt-space-2);margin-inline-start:auto}@media(pointer:coarse){.diagram-zoom .btn,.diagram-viewer-end .btn{min-height:var(--basalt-size-tap-min);min-width:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram-level{color:CanvasText}.diagram-viewer-foot [aria-disabled=true]{color:GrayText}}@media print{.diagram-expand,.diagram-viewer,:root:has(.diagram-viewer) dialog.modal::backdrop{display:none!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.js b/.agent/skills/basalt-html/parts/diagram-zoom.js new file mode 100644 index 00000000..88b3232e --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-zoom.js @@ -0,0 +1 @@ +(()=>{var N=[25,33,50,67,75,100,125,150,200,300,400],j=4,V=2,tt=100,$=25,Y=5e-4;function et(m){const{stage:e,sizer:L,layer:g,status:h}=m;let p=0,k=0,i=1,l=1,b=!1,s=!1,f=null,d="",x=0;const S=()=>Number.parseFloat(getComputedStyle(L).paddingTop)||0,F=()=>Math.min(l,1),P=t=>Math.min(j,Math.max(F(),t));function r(){if(!p||!k)return 1;const t=S(),a=e.clientWidth-2*t,c=e.clientHeight-2*t;if(a<=0||c<=0)return Math.min(1,V);const E=Math.min(a/p,c/k);return Math.min(V,Math.floor(E*100+1e-6)/100)}function u(){const t=F();return{zoom:i,level:Math.round(i*100),fit:l,min:t,max:j,atMin:i<=t+Y,atMax:i>=j-Y,atFit:Math.abs(i-l)e.clientWidth-2*S()+.5||k*i>e.clientHeight-2*S()+.5)}function q(){clearTimeout(x);const t=`Zoom ${Math.round(i*100)}%`;x=window.setTimeout(()=>{t!==d&&(d=t,h.textContent=t)},m.rest)}function v(){L.style.width=`${p*i}px`,L.style.height=`${k*i}px`,g.style.transform=`scale(${i})`}function D(t){const a=g.getBoundingClientRect();return{x:(t.x-a.left)/i,y:(t.y-a.top)/i}}function K(t,a){const c=g.getBoundingClientRect();e.scrollLeft+=c.left+t.x*i-a.x,e.scrollTop+=c.top+t.y*i-a.y}const A=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function B(t,a=A(),c){if(s)return;const E=P(t);if(Math.abs(E-i)<1e-6){z();return}const at=c??D(a);i=E,v(),K(at,a),z(),q()}function y(t){b=!0;const a=i*100,c=t?N.find(E=>E>a+.5):[...N].reverse().find(E=>ENumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,n=()=>{const[t,a]=[...o.values()];return{x:(t.x+a.x)/2,y:(t.y+a.y)/2}},w=()=>{const[t,a]=[...o.values()];return Math.hypot(t.x-a.x,t.y-a.y)};function U(t){if(!s&&!(t.pointerType==="mouse"&&t.button!==0)&&(o.set(t.pointerId,{x:t.clientX,y:t.clientY}),o.size===1&&(T={x:t.clientX,y:t.clientY},M=T,_=!1,H=!1),o.size===2&&t.pointerType==="touch")){const a=n();W={d0:w()||1,z0:i,c:D(a)},H=!0,_=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function G(t){if(!o.has(t.pointerId)||s)return;if(o.set(t.pointerId,{x:t.clientX,y:t.clientY}),W&&o.size>=2){b=!0;const c=P(W.z0*(w()/W.d0)),E=n();Math.abs(c-i)>1e-6&&(i=c,v(),z(),q()),K(W.c,E);return}if(o.size!==1||!T||!M)return;const a={x:t.clientX,y:t.clientY};if(!_){if(Math.hypot(a.x-T.x,a.y-T.y)<=R())return;_=!0,H=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=a.x-M.x,e.scrollTop-=a.y-M.y,M=a,t.preventDefault()}function X(t){if(o.has(t.pointerId)){if(o.delete(t.pointerId),o.size<2&&(W=null),o.size===1){const[a]=[...o.values()];M=a,T=a,_=!0;return}o.size===0&&(_=!1,e.removeAttribute("data-dragging"),T=M=null)}}function J(t){H&&(H=!1,t.preventDefault(),t.stopPropagation())}const Q=new ResizeObserver(()=>{if(!p||!k)return;const t=b?D(A()):null;l=r(),b?(i=P(i),v(),t&&K(t,A())):(i=l,v()),z()});return Q.observe(e),e.addEventListener("wheel",I,{passive:!1}),e.addEventListener("keydown",Z),e.addEventListener("pointerdown",U),e.addEventListener("pointermove",G),e.addEventListener("pointerup",X),e.addEventListener("pointercancel",X),e.addEventListener("click",J,!0),{size:O,zoomIn:()=>y(!0),zoomOut:()=>y(!1),fit:C,state:u,list(t){t!==s&&(t?(f={left:e.scrollLeft,top:e.scrollTop},s=!0,e.setAttribute("data-list",""),e.scrollTop=0):(s=!1,e.removeAttribute("data-list"),v(),f&&(e.scrollLeft=f.left,e.scrollTop=f.top),f=null),z())},travelled:()=>H,destroy(){clearTimeout(x),Q.disconnect(),e.removeEventListener("wheel",I),e.removeEventListener("keydown",Z),e.removeEventListener("pointerdown",U),e.removeEventListener("pointermove",G),e.removeEventListener("pointerup",X),e.removeEventListener("pointercancel",X),e.removeEventListener("click",J,!0)}}}function it(m,e,L){const g=m.getBoundingClientRect(),h=e.getBoundingClientRect(),p=g.left+L,k=g.left+m.clientWidth-L,i=g.top+L,l=g.top+m.clientHeight-L;h.leftk&&(m.scrollLeft+=Math.min(h.right-k,h.left-p)),h.topl&&(m.scrollTop+=Math.min(h.bottom-l,h.top-i))}(function(m){"use strict";var e=m._,L=0;function g(i){return e.diagramKit.escapeHtml(String(i??""))}function h(i){return''+g(i)+""}function p(i,l){return parseFloat(getComputedStyle(i).getPropertyValue(l))||0}function k(i,l,b,s){var f=e.diagramKit,d=Object.assign({},l,{motion:"still"}),x=f.buildModel(d),S="dgv"+ ++L,F=f.figureKey("diagram",x),P=f.hintEntries(x,!0).map(function(n){return""+n.keys.map(h).join(" ")+" "+g(n.words)+""}).join(""),r=document.createElement("dialog");r.className="panel float modal dialog diagram-viewer",r.setAttribute("data-form",""),r.setAttribute("aria-describedby",S+"-summary"),r.innerHTML='

'+g(x.title)+"

"+(l.source?'

'+g(l.source)+"

":"")+'

'+g(l.summary)+'

'+(F?'
'+f.toHtml(F)+"
":"")+'
',document.body.appendChild(r);var u=r.querySelector(".diagram-stage"),z=r.querySelector(".diagram-sizer"),q=r.querySelector(".diagram-layer"),v=q.firstChild,D=r.querySelector('[role="status"]'),K=r.querySelector(".diagram-level > span"),A=r.querySelector(".diagram-viewer-key"),B=r.querySelector(".diagram-toggle"),y={out:r.querySelector('[data-zoom="out"]'),in:r.querySelector('[data-zoom="in"]'),fit:r.querySelector('[data-zoom="fit"]')},C=null,O=!1,I=!1,Z=function(n,w){w?n.setAttribute("aria-disabled","true"):n.removeAttribute("aria-disabled")},o=et({stage:u,sizer:z,layer:q,status:D,rest:p(u,"--_rest")||300,onChange:function(n){K.textContent=n.level+"%",Z(y.out,n.listOpen||n.atMin),Z(y.in,n.listOpen||n.atMax),Z(y.fit,n.listOpen||n.atFit)}}),T={},M={layer:q,avail:0,row:1104,contain:480,memo:T,onMeasured:function(n,w){u.setAttribute("data-layout",n.dyn.layout||""),A&&(A.setAttribute("data-layout",n.dyn.layout||""),A.toggleAttribute("data-bare",!!n.dyn.bare)),I=!!n.dyn.bare,B.hidden=I,H(O||I),o.size(w.offsetWidth,w.offsetHeight)}};function _(){M.avail=Math.max(0,Math.floor(u.clientWidth-2*(parseFloat(getComputedStyle(z).paddingLeft)||0))),M.row=r.querySelector('[data-probe="row"]').offsetWidth||1104,M.contain=r.querySelector('[data-probe="contain"]').offsetWidth||480}function H(n){n&&!C&&(C=document.createElement("div"),C.className="diagram-list diagram-viewer-list",C.innerHTML=f.figureList("diagram",x).map(function(w){return f.toHtml(w)}).join(""),u.appendChild(C)),C&&(C.hidden=!n),z.hidden=n,o.list(n)}B.addEventListener("click",function(){O=!O,B.setAttribute("aria-expanded",String(O)),B.firstElementChild.textContent=O?"Hide the list":"View as list",H(O||I)}),y.out.addEventListener("click",function(){y.out.hasAttribute("aria-disabled")||o.zoomOut()}),y.in.addEventListener("click",function(){y.in.hasAttribute("aria-disabled")||o.zoomIn()}),y.fit.addEventListener("click",function(){y.fit.hasAttribute("aria-disabled")||o.fit()}),u.addEventListener("focusin",function(n){var w=n.target.closest&&n.target.closest(".diagram-node");w&&u.contains(w)&&it(u,w,p(u,"--_clear")||16)}),m.openDialog(r,s),_(),f.draw(v,d,!1,M),setTimeout(function(){u.focus({preventScroll:!0})},0);var W=u.clientWidth,R=new ResizeObserver(function(){Math.abs(u.clientWidth-W)<.5||(W=u.clientWidth,_(),v.__diagram&&v.__diagram.layout())});R.observe(u),i.setAttribute("data-viewing",""),b.animated&&b.settle(),r.addEventListener("close",function(){R.disconnect(),o.destroy(),v.__diagram&&v.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){r.remove()},p(r,"--_dur")*.75||300)})}e.diagramZoom=function(i,l,b){var s=i.querySelector(":scope > .diagram-foot");if(!s)return null;var f=s.querySelector(".diagram-expand");f&&f.remove();var d=document.createElement("button");d.type="button",d.className="btn diagram-expand",d.setAttribute("data-variant","secondary"),d.setAttribute("data-size","sm"),d.setAttribute("aria-haspopup","dialog"),d.innerHTML=e.icon("ArrowsOutSimple",{size:16})+"Expand";var x=s.querySelector(".diagram-toggle");x&&x.nextSibling?s.insertBefore(d,x.nextSibling):s.appendChild(d);var S=function(){k(i,l,b,d)};return d.addEventListener("click",S),{destroy:function(){d.removeEventListener("click",S),d.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 54e3aa24..f3a55524 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,2 +1,2 @@ -(()=>{var se=["top","right","bottom","left"],ae=["main","plain","dashed"],re=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ut=t=>Object.assign(Object.create(null),t),ft=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Et(t,e={}){const s=e.checks!==!1,a=[],o=f=>{a.push(f)},r=t.legend??{},l={};for(const f of["main","plain","dashed","focal","group"]){const m=at(r[f]);m&&(l[f]=m)}const h=t.stepLabel,u=typeof h=="function"?f=>String(h(f)):typeof h=="string"?(f=>h.replace("{n}",String(f))):f=>`Step ${f}`,p=t.shapeLabels??{},g={terminal:at(p.terminal)??"Start or end",step:at(p.step)??"Step",decision:at(p.decision)??"Decision"},c=t.heading===void 0?3:re.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),y=(f,m)=>f==null?"plain":ae.includes(f)?f:(o(`"${String(f)}" is not a kind of line (main, plain or dashed): ${m} is drawn plain`),"plain"),b=f=>{if(f!=null){if(se.includes(f))return f;o(`"${String(f)}" is not a side (top, right, bottom or left): the derived side is used`)}},i=(f,m)=>typeof f=="number"&&Number.isInteger(f)&&f>=1?f:(o(`${m} is ${JSON.stringify(f)}, not a whole number from 1: it is placed at 1`),1),d=[],w=[];let q=[];const L=[],O=[],F=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(F)||o(`"${String(F)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),F==="architecture"||F==="flowchart"){for(const f of t.nodes??[]){const m=F==="flowchart"&&f.shape==="decision"?"decision":F==="flowchart"&&f.shape==="terminal"?"terminal":"box",A=String(f.id??""),S=i(f.row,`the row of ${A}`);d.push({id:A,i:d.length,name:String(f.name??""),kind:m==="decision"?void 0:at(f.kind),detail:m==="decision"?void 0:at(f.detail),mono:!!f.detailMono,focal:!!f.focal,col:i(f.col,`the column of ${A}`),row:S,row2:S,branch:!!f.branch,shape:m,group:F==="architecture"?at(f.group):void 0,mark:F==="architecture"?ie(f.mark):void 0})}if(F==="architecture")for(const f of t.groups??[]){const m=String(f.id??"");L.push({id:m,label:String(f.label??""),members:d.filter(A=>A.group===m).map(A=>A.id)})}}else if(F==="data-flow"){q=(t.lanes??[]).map(m=>({id:String(m.id??""),label:String(m.label??"")}));const f=new Map(q.map((m,A)=>[m.id,A+1]));for(const m of t.nodes??[]){const A=String(m.id??""),S=String(m.lane??""),z=f.get(S);z===void 0&&o(`a node (${A}) names the lane "${S}", which is not in lanes`);const C=d.length+1;d.push({id:A,i:d.length,name:String(m.name??""),kind:u(C),detail:at(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:i(m.col,`the column of ${A}`),row:z??1,row2:z??1,branch:!1,shape:"box",lane:z??1,laneLabel:q[(z??1)-1]?.label??S,step:C})}}else if(F==="sequence"){(t.participants??[]).forEach((m,A)=>{const S=String(m.name??"");d.push({id:String(m.id??""),i:A,name:S,kind:at(m.kind),mono:!1,focal:!!m.focal,col:A+1,row:1,row2:1,branch:!1,shape:"participant",short:at(m.short)??S})});let f=0;for(const m of t.steps??[])"band"in m?O.push({band:String(m.band??"")}):(f++,O.push({n:f,from:String(m.from??""),to:String(m.to??""),label:String(m.label??""),note:at(m.note),kind:y(m.kind,`message ${f}`)}))}else if(F==="schema")for(const f of t.tables??[]){const m=String(f.name??""),[A,S]=Array.isArray(f.row)?f.row:[f.row,f.row],z=i(A,`the row of ${m}`),C=Math.max(z,i(S,`the last row of ${m}`)),K=f.more===void 0||f.more===null?void 0:Number.isInteger(f.more)&&f.more>0?f.more:(o(`${m}'s "more" is ${JSON.stringify(f.more)}, not a whole number from 1: it is left out`),void 0);d.push({id:m,i:d.length,name:m,mono:!0,focal:!!f.focal,col:i(f.col,`the column of ${m}`),row:z,row2:C,branch:!1,shape:"table",more:K,columns:(f.columns??[]).map(W=>({name:String(W.name??""),type:at(W.type),key:W.key==="PK"||W.key==="FK"?W.key:(W.key!==void 0&&W.key!==null&&o(`${m}.${String(W.name)}'s key is "${String(W.key)}", not PK or FK: it is left out`),void 0)}))})}const _=new Map;for(const f of d)f.id?_.has(f.id)&&o(`the id "${f.id}" is used twice`):o("a node has no id"),_.set(f.id,f);if(F==="schema")(t.tables??[]).forEach(f=>(f.columns??[]).forEach((m,A)=>{const S=at(m.references);if(!S)return;const[z,C]=S.split("."),K=_.get(z??""),W=K?.columns?.findIndex(T=>T.name===C)??-1;if(!K||W<0){o(`${String(f.name)}.${String(m.name)} references ${S}, which is not a shown column`);return}const M=_.get(String(f.name??""));M.columns[A].ref={table:z,column:C,row:W},w.push({i:w.length,from:M.id,to:z,kind:"plain",fromRow:A,toRow:W,fk:!0})}));else if(F!=="sequence")for(const f of t.edges??[]){const m=String(f.from??""),A=String(f.to??"");if(!_.has(m)||!_.has(A)){o(`a line names ${_.has(m)?A:m}, which is not a node`);continue}const S=at(f.label);S&&S.length>Lt&&o(`the label "${S}" is over ${Lt} characters: longer words belong in the node or the summary`),w.push({i:w.length,from:m,to:A,kind:y(f.kind,`the line from ${m} to ${A}`),label:S,fromSide:b(f.fromSide),toSide:b(f.toSide),flow:F!=="flowchart"&&f.flow===!0?!0:void 0})}else for(const f of O)"n"in f&&(!_.has(f.from)||!_.has(f.to))&&o(`message ${f.n} names ${_.has(f.from)?f.to:f.from}, which is not a participant`);if(s&&F!=="sequence"){const f=new Map;for(const m of d)for(let A=m.row;A<=m.row2;A++){const S=`${m.col}:${A}`;f.has(S)&&o(`${m.id} and ${f.get(S)} share the cell at column ${m.col}, row ${A}`),f.set(S,m.id)}}if(s){for(const m of L){const A=m.members.map(C=>_.get(C));if(!A.length)continue;const S={c1:Math.min(...A.map(C=>C.col)),c2:Math.max(...A.map(C=>C.col)),r1:Math.min(...A.map(C=>C.row)),r2:Math.max(...A.map(C=>C.row2))};for(const C of d)C.group!==m.id&&C.col>=S.c1&&C.col<=S.c2&&C.row>=S.r1&&C.row<=S.r2&&o(`${C.id} is inside the box of the group "${m.label}" but not a member`);const z=A.map(C=>C.i);Math.max(...z)-Math.min(...z)+1!==z.length&&o(`the members of the group "${m.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const m of d)m.group&&!L.some(A=>A.id===m.group)&&o(`${m.id} names the group "${m.group}", which is not in groups`);d.filter(m=>m.focal).length>1&&o("more than one node is focal: a diagram has one at most");const f=new Set(F==="sequence"?O.flatMap(m=>"n"in m?[m.kind]:[]):w.map(m=>m.kind));f.has("main")&&!l.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),f.has("dashed")&&!l.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),d.some(m=>m.focal)&&!l.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const J=F==="architecture"||F==="data-flow",E=f=>Array.isArray(f)&&f.length>1?f.map(String):void 0,V=J&&t.packet&&typeof t.packet=="object"?t.packet:void 0,$=V&&E(V.path),G={animated:t.motion==="animated",pulse:J?E(t.pulse):void 0,packet:$?{path:$,repeat:V.repeat===!0,send:V.send}:void 0,run:F==="sequence"&&t.run===!0};if(s)for(const f of d){const m=f.mark?.says;if(!m?.length)continue;const A=[f.name,f.kind,f.detail].filter(Boolean).join(" ").toLowerCase();m.some(S=>A.includes(S.toLowerCase()))||o(`${f.id}'s mark stands for ${m.join(" or ")}, and none of its words say so`)}const j=Math.max(1,...d.map(f=>f.col)),v=F==="data-flow"?Math.max(1,q.length):Math.max(1,...d.map(f=>f.row2));return{type:F,title:String(t.title??""),heading:c,legend:l,nodes:d,byId:_,edges:w,groups:L,lanes:q,steps:O,cols:j,rows:v,shapeLabels:g,stepWord:u,warnings:a,motion:G,memo:new Map}}function ie(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var At=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function bt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Lt=28,pt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function qt(t,e){return t.legend[e]}function le(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function ce(t,e){return bt(t,`sentence:${e.i}`,()=>de(t,e))}function de(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),a=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),a.length&&n.push(`Referenced by ${a.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,a=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(pt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${a}.`)}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?le(t,e):e.kind;if(n.push(pt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(pt(e.detail)),e.group){const r=t.groups.find(l=>l.id===e.group);r&&n.push(`In ${r.label}.`)}const a=t.edges.filter(r=>r.to===e.id).map(r=>`${t.byId.get(r.from).name}${r.label?` (${r.label})`:""}`),o=t.edges.filter(r=>r.from===e.id).map(r=>`${t.byId.get(r.to).name}${r.label?` (${r.label})`:""}`);a.length&&n.push(`From: ${a.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(pt(t.legend.focal)),n.join(" ")}function ue(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function x(t,e,...n){const s=[];for(const a of n.flat(1/0))a!=null&&a!==!1&&!Array.isArray(a)&&s.push(a);return{t,a:e??{},c:s}}var fe={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>fe[e]),he=" br img input meta link hr path polygon polyline circle rect line ";function It(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,a]of Object.entries(t.a))if(!(a==null||a===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=a===!0?` ${s}`:` ${s}="${it(String(a))}"`}return he.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>It(s,e)).join("")}`}var pe=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function ht(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function ge(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Ot(t){let e=0;for(const n of t.groups){const s=n.members.map(a=>t.byId.get(a).col);s.length&&(Math.min(...s)===1&&(e|=1),Math.max(...s)===t.cols&&(e|=2))}return(e&1)+(e>>1&1)}function vt(t){return t.type==="sequence"?t.nodes.length:t.cols}function _t(t){return bt(t,"plan",()=>me(t))}function me(t){const e=t.nodes,n=i=>t.type==="data-flow"||!e[i].branch,s=t.edges.map(i=>{const d=t.byId.get(i.from).i,w=t.byId.get(i.to).i,L=e.slice(Math.min(d,w)+1,Math.max(d,w)).every(O=>!n(O.i));return w===d+1&&!(n(d)&&!n(w))?"down":w===d-1?"up":w>d&&n(d)&&!n(w)&&L?"trunk":w>d&&n(d)&&n(w)&&L?"rail":w>d?"end-down":"end-up"}),a=t.edges.map((i,d)=>({e:i,k:d})).filter(({k:i})=>s[i]==="end-down"||s[i]==="end-up"),o=i=>{const d=t.byId.get(i.from).i,w=t.byId.get(i.to).i;return[Math.min(d,w),Math.max(d,w)]},r=(i,d)=>{const[w,q]=o(i),[L,O]=o(d);return w{const d=t.byId.get(i.from).i,[w,q]=o(i);return!n(d)&&e.slice(w+1,q).every(L=>!n(L.i))&&a.every(L=>L.e===i||!r(L.e,i))}),h=a.length>0&&(t.type==="data-flow"||!l),u=i=>{const[d,w]=o(i);return w-d},p=t.edges.map(()=>0);let g=!1;const c=[];for(const i of[...a].sort((d,w)=>u(d.e)-u(w.e)||d.k-w.k)){let d=0;for(const w of c)r(w.e,i.e)&&(d=Math.max(d,p[w.k]+1));p[i.k]=d,d>1&&(g=!0),c.push(i)}const y=t.edges.map(()=>.5);for(const i of e){const d=a.filter(({e:L})=>L.from===i.id);if(d.length<2)continue;const w=d.filter(({k:L})=>s[L]==="end-down").sort((L,O)=>u(O.e)-u(L.e)||L.k-O.k);[...d.filter(({k:L})=>s[L]==="end-up").sort((L,O)=>u(L.e)-u(O.e)||O.k-L.k),...w].forEach(({k:L},O,F)=>{y[L]=F.length===2?O===0?1/3:2/3:(O+1)/(F.length+1)})}const b=ut();for(let i=1;i{const E=s[J],V=t.byId.get(_.from).i,$=t.byId.get(_.to).i,G=$===i&&(E==="down"||E==="trunk"||E==="rail"||E==="end-down"),j=V===i&&$===i-1&&E==="up",v=$===i-1&&E==="end-up";G&&(E==="trunk"||E==="end-down")&&(O=!0),v&&(F=!0),(G||j||v)&&_.label&&(q++,L=Math.max(L,E==="trunk"?40:48))}),(q>1||O&&F)&&(L=64),b[d.id]=L}return{routes:s,gutter:h,lanes:p,exits:y,gaps:b,third:g}}var gt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Ct(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,a=24,o=n==="dashed"?a-1:a-7;return x("svg",{class:`${t}-swatch`,"data-kind":n,...gt(24,16)},e==="fk"?x("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,x("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?x("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${a-8} ${s-4}L${a} ${s}L${a-8} ${s+4}`}):x("path",{class:`${t}-tip`,"data-kind":n,d:`M${a} ${s}L${a-8} ${s-4}L${a-8} ${s+4}Z`}))}function mt(t,e){return e==="decision"?x("svg",{class:`${t}-swatch`,"data-shape":e,...gt(16,16)},x("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?x("svg",{class:`${t}-swatch`,"data-shape":e,...gt(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):x("svg",{class:`${t}-swatch`,"data-shape":e,...gt(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function ye(t,e){return bt(e,`key:${t}`,()=>be(t,e))}function be(t,e){const n=[],s=(o,r,l={})=>n.push(x("li",{class:`${t}-entry`,...l},o,x("span",null,r)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(r=>(r.columns??[]).map(l=>l.key)));for(const[r,l]of[["PK","Primary key"],["FK","Foreign key"]])o.has(r)&&n.push(x("li",{class:`${t}-entry`},x("span",{class:`${t}-key-letters`,"aria-hidden":"true"},r),x("span",null,l)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(r=>r.shape));o.has("terminal")&&s(mt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(mt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(mt(t,"decision"),e.shapeLabels.decision)}const a=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const r=e.legend[o];a.has(o)&&r&&s(Ct(t,o),r,{"data-line":""})}return e.type==="schema"&&e.edges.length&&(s(Ct(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(x("li",{class:`${t}-entry`,"data-when":"stacked"},x("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),x("span",null,"The table a foreign key references")))),e.nodes.some(o=>o.focal)&&e.legend.focal&&s(mt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(mt(t,"group"),e.legend.group),n.length?x("div",{class:`${t}-key`},x("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function $e(t,e){const n=e==="main"?6:6.5;return x("svg",{class:`${t}-arrow`,"data-kind":e,...gt(20,12)},x("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?x("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):x("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function we(t,e,n){if(n.shape==="decision")return[x("span",{class:`${t}-words`},x("span",{class:`${t}-name`},n.name))];const s=[];return e.type==="data-flow"?s.push(x("span",{class:`${t}-kind`},n.kind,x("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(x("span",{class:`${t}-kind`},n.kind)),s.push(x("span",{class:`${t}-name`},n.name)),n.detail&&s.push(x("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?wt(n.detail).flatMap((a,o)=>[o?" ":"",x("span",{class:`${t}-run`},a)]):n.detail)),s}function xe(t,e){return[x("span",{class:`${t}-th`},x("span",{class:`${t}-tname`},e.name)),x("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>x("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},x("span",{class:`${t}-keyseat`},n.key??""),x("span",{class:`${t}-cname`},n.name),n.ref?x("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?x("span",{class:`${t}-ctype`},n.type):null))),e.more?x("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Bt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Mt(t,e,n,s){const{P:a}=t,o=ge(e,s)||s.keep===n.id,r=ht(e,s),l=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&l.push(`--_lc:${n.col+1}`),e.type==="sequence"&&l.push(`--_c2:${n.col+1}`);const h=t.plan;if(h&&n.i>0){const c=ft(h.gaps,n.id)??32,y=ft(s.grow,n.id)??0;l.push(`--_gap:${y?`calc(${Bt(c)} + var(--basalt-space-4) * ${y})`:Bt(c)}`)}const u=ft(s.heights,n.id);u&&l.push(`--_h:${u}px`);const p=ft(s.words,n.id);p&&l.push(`--_ww:${p}px`);const g=r?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return x("div",{class:`${a}-node`,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:l.join(";"),role:o?"img":void 0,"aria-label":o?ce(e,n):void 0,tabindex:g},n.shape==="decision"?x("svg",{class:`${a}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},x("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?x("span",{class:`${a}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${At(n.mark.onLight)};--_md:${At(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?xe(a,n):we(a,e,n))}function ve(t,e,n){const{P:s}=t,a=[];if(e.type==="data-flow"&&a.push(...e.lanes.map((r,l)=>x("div",{class:`${s}-lane`,style:`--_r:${l+1}`,"aria-hidden":"true"},x("span",{class:`${s}-lane-name`},r.label)))),e.type==="architecture")for(const r of e.groups){const l=r.members.map(c=>e.byId.get(c));if(!l.length)continue;const h=Math.min(...l.map(c=>c.col)),u=Math.max(...l.map(c=>c.col)),p=Math.min(...l.map(c=>c.row)),g=Math.max(...l.map(c=>c.row2));a.push(x("div",{class:`${s}-gbox`,"data-group":r.id,style:`--_c:${h};--_c2:${u+1};--_r:${p};--_r2:${g+1}`,"aria-hidden":"true"},x("span",{class:`${s}-glabel`},r.label)))}if(e.type==="sequence")return a.push(x("ul",{class:`${s}-cast`},e.nodes.map(r=>x("li",{class:`${s}-actor`},Mt(t,e,r,n))))),a.push(Me(t,e)),a;let o=0;for(;op.id===r.group):void 0;if(!l){a.push(Mt(t,e,r,n)),o++;continue}const h=[];for(;oMt(t,e,p,n))))}return a}function Me(t,e){const{P:n}=t,s=[];let a=null;for(const o of e.steps){if("band"in o){a=null,s.push(x("p",{class:`${n}-band`},x("span",null,o.band)));continue}a||(a=x("ol",{class:`${n}-msgs`,start:o.n}),s.push(a));const r=e.byId.get(o.from),l=e.byId.get(o.to),h=r?.col??1,u=l?.col??1,p=h===u,g=p&&h===e.nodes.length,c=qt(e,o.kind);a.c.push(x("li",{class:`${n}-msg`,"data-kind":o.kind,"data-from":o.from,"data-to":o.to,"data-self":p?g?"start":"end":void 0,style:`--_a:${Math.min(h,u)};--_b:${Math.max(h,u)+1}`},x("span",{class:`${n}-said`},x("span",{class:`${n}-num`},String(o.n)),x("span",{class:`${n}-mlabel`},o.label)),x("span",{class:`${n}-route`},r?.short??o.from," ",$e(n,o.kind),x("span",{class:t.hidden}," to ")," ",l?.short??o.to,c?` · ${c}`:""),o.note?x("span",{class:`${n}-note`},o.note):null))}return x("div",{class:`${n}-steps`},s)}function ke(t,e){return bt(e,`list:${t}`,()=>Se(t,e))}function Se(t,e){const n=Math.min(6,e.heading+1),s=p=>x(`h${n}`,{class:`${t}-list-head`},p),a=p=>x("strong",null,p),o=p=>x("code",{class:`${t}-code`},p),r=p=>e.byId.get(p)?.name??p,l=p=>{const g=qt(e,p);return g?` (${g})`:""},h=p=>p.focal&&e.legend.focal?` ${pt(e.legend.focal)}`:"";if(e.type==="architecture"){const p=y=>x("li",null,a(y.name),y.kind?`, ${y.kind}`:"",y.detail?[". ",y.mono?o(y.detail):y.detail,/[.!?]$/.test(y.detail)?"":"."]:/[.!?]$/.test(y.kind??y.name)?"":".",h(y)),g=[s("Parts")],c=e.nodes.filter(y=>!y.group);c.length&&g.push(x("ul",{class:`${t}-list-items`},c.map(p)));for(const y of e.groups)g.push(x("p",{class:`${t}-list-group`},y.label)),g.push(x("ul",{class:`${t}-list-items`},y.members.map(b=>p(e.byId.get(b)))));return g.push(s("Connections")),g.push(x("ol",{class:`${t}-list-items`},e.edges.map(y=>x("li",null,a(r(y.from))," to ",a(r(y.to)),y.label?[": ",o(y.label)]:"",`${l(y.kind)}.`)))),g}if(e.type==="flowchart"){const p=g=>(e.byId.get(g)?.i??0)+1;return[x("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const c=e.edges.filter(i=>i.from===g.id),y=g.shape==="decision"?"Decision":g.shape==="terminal"?c.length?"Start":"End":"Step",b=!g.detail&&/[.!?]$/.test(g.name)?" ":". ";return x("li",null,a(g.name),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",`${b}${y}.`,h(g),c.length?x("ul",{class:`${t}-list-exits`},c.map(i=>x("li",null,i.label?`If ${i.label}: go to ${p(i.to)}, `:`Then: go to ${p(i.to)}, `,a(r(i.to)),l(i.kind)))):null)}))]}if(e.type==="data-flow")return[x("ol",{class:`${t}-list-items`},e.nodes.map(p=>{const g=e.edges.filter(c=>c.from===p.id);return x("li",null,`${p.laneLabel}: `,a(p.name),p.detail?[", ",p.mono?o(p.detail):p.detail]:"",".",h(p),g.length?[" Then ",...g.flatMap((c,y)=>[y?"; ":"",`to step ${e.byId.get(c.to).step}, `,a(r(c.to)),c.label?[": ",o(c.label)]:"",l(c.kind)]),"."]:"")}))];if(e.type==="sequence"){const p=[s("Participants"),x("ul",{class:`${t}-list-items`},e.nodes.map(c=>x("li",null,a(c.name),c.kind?`, ${c.kind}`:"",".",h(c))))];p.push(s("Messages"));let g=null;for(const c of e.steps){if("band"in c){g=null,p.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},c.band));continue}g||(g=x("ol",{class:`${t}-list-items`,start:c.n}),p.push(g)),g.c.push(x("li",null,o(c.label),": ",a(r(c.from))," to ",a(r(c.to)),`${l(c.kind)}.`,c.note?` ${pt(c.note)}`:""))}return p}const u=[];for(const p of e.nodes)u.push(x(`h${n}`,{class:`${t}-list-group`},o(p.name),h(p))),u.push(x("ul",{class:`${t}-list-items`},[...(p.columns??[]).map(g=>x("li",null,o(g.name),g.key==="PK"?", primary key":g.key==="FK"?", foreign key":"",g.ref?[", references ",o(`${g.ref.table}.${g.ref.column}`)]:g.type?`, ${g.type}`:"")),...p.more?[x("li",null,`and ${p.more} more ${p.more===1?"column":"columns"}`)]:[]]));return u}function Ee(t){return`Arrow keys move to the next or the previous ${t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step"}, in the author's order; Home and End go to the ends; Escape clears the trace.`}function Ae(t){return[{keys:["←","→"],words:ue(t)},{keys:["Home","End"],words:"the ends"},{keys:["Esc"],words:"clear"}]}var jt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Tt(t,e,n){const s=n.prefix,a=pe(n.base),o=t.type==="sequence"||t.type==="schema"?null:_t(t),r={P:s,ids:a,level:n.level,plan:o,hidden:n.hiddenClass},l=e.layout==="drawn",h=ht(t,e),u=t.type==="sequence"||t.type==="schema"?l:!0,p=`h${t.heading}`,g=[`--_cols:${vt(t)}`];if(t.type==="architecture"&&t.groups.length||l&&e.pad){const c=t.type==="architecture"?t.groups.flatMap(i=>i.members.map(d=>t.byId.get(d))):[],y=(i,d,w)=>i?`var(--basalt-space-${d})`:w?`var(--basalt-space-${w})`:"0px",b=l&&e.pad?"3":void 0;g.push(`--_gpad:${y(c.some(i=>i.row===1),"8",b)} ${y(c.some(i=>i.col===t.cols),"4")} ${y(c.some(i=>i.row2===t.rows),"4",b)} ${y(c.some(i=>i.col===1),"4")}`)}return jt(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),x("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":a.title,"data-type":t.type,"data-cols":vt(t),"data-reach":t.type==="architecture"?Ot(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,style:g.join(";")},x("div",{class:`${s}-head`},x(p,{id:a.title,class:`${s}-title`},t.title),n.hasSource?x("p",{class:`${s}-source`},{slot:"source"}):null),x("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?a.title:void 0,"aria-describedby":u?h?`${a.summary} ${a.keys}`:a.summary:void 0,"data-stops":h?"":void 0},ve(r,t,e),x("div",{class:`${s}-ink`,"aria-hidden":"true"}),x("span",{class:`${s}-ruler`,"aria-hidden":"true"})),ye(s,t),x("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),x("div",{class:`${s}-foot`},{slot:"toggle"}),x("div",{id:a.list,class:`${s}-list`,hidden:!e.open},ke(s,t)),x("span",{id:a.keys,class:n.hiddenClass},Ee(t)),x("figcaption",{id:a.summary,class:`${s}-summary`},{slot:"summary"}))}function Le(t){const e=getComputedStyle(t),n=(a,o)=>{const r=parseFloat(e.getPropertyValue(`--basalt-${a}`));return Number.isFinite(r)?r:o},s=new Map;return{space:a=>(s.has(a)||s.set(a,n(`space-${a}`,parseFloat(a.replace("-","."))*4)),s.get(a)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4)}}var $t=(t,e)=>t==="main"?e.line:e.hair,lt=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ct=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Rt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function rt(t,e,n){const{l:s,t:a,r:o,b:r}=t.rect,l=(s+o)/2,h=(a+r)/2,u=(o-s)/2,p=(r-a)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const b=n,i=p*Math.max(0,1-Math.abs(b-l)/u);return{x:b,y:e==="top"?h-i:h+i}}const c=n,y=u*Math.max(0,1-Math.abs(c-h)/p);return{x:e==="left"?l-y:l+y,y:c}}if(t.shape==="terminal"){const c=Math.min(u,p);if(g){const d=n,w=Math.min(Math.max(d,s+c),o-c),q=d-w,L=Math.abs(q)>=c?0:Math.sqrt(c*c-q*q);return{x:d,y:Math.abs(q)<1e-6?e==="top"?a:r:e==="top"?h-L:h+L}}const y=n,b=y-h,i=Math.abs(b)>=c?0:Math.sqrt(c*c-b*b);return{x:e==="left"?s+c-i:o-c+i,y}}return g?{x:n,y:e==="top"?a:r}:{x:e==="left"?s:o,y:n}}function qe(t,e,n){const{l:s,t:a,r:o,b:r}=e.rect,l=(s+o)/2,h=(a+r)/2,u=(o-s)/2,p=(r-a)/2;if(e.shape==="decision")return Math.abs(t.x-l)/u+Math.abs(t.y-h)/p<1-n/Math.min(u,p);if(e.shape==="terminal"){const g=Math.min(u,p),c=Math.min(Math.max(t.x,s+g),o-g);return Math.hypot(t.x-c,t.y-h)s+n&&t.xa+n&&t.ymatchMedia("(forced-colors: active)").matches;function _e(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(a,o)=>{const r=`${o}|${a}`;return s.has(r)||(n.setAttribute("data-f",o),n.textContent=a,s.set(r,n.getBoundingClientRect().width),n.textContent=""),s.get(r)}}var wt=t=>t?t.split(/\s+/).filter(Boolean):[];function Ce(t,e,n){const s=e.space;let a=e.node,o=e.table;for(const h of t.nodes){if(h.shape==="table"){for(const y of h.columns??[]){const b=y.ref?`→ ${y.ref.table}`:y.type??"",i=s("6")+n(y.name,"mono")+(b?s("3")+n(b,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(i))}o=Math.max(o,Math.ceil(n(h.name,"table")+2*s("3")+2*e.hair));continue}const u=h.shape==="terminal"?2*s("5"):2*s("3"),p=h.mark&&!Oe()?s("6"):0;let g=0;for(const y of wt(h.name))g=Math.max(g,n(y,h.shape==="decision"?"name-500":"name")+(h.kind?0:p));if(t.type!=="data-flow")for(const y of wt(h.kind))g=Math.max(g,n(y,"mono")+p);for(const y of wt(h.detail))g=Math.max(g,n(y,h.mono?"mono":"sans"));const c=h.shape==="decision"?g/.62:g+u+2*e.hair;a=Math.max(a,Math.ceil(c))}const r=vt(t);let l;return t.type==="data-flow"?l=e.lane+r*(a+s("12")):t.type==="schema"?l=r*o+(r-1)*s("12")+(jt(t)?s("5"):0):t.type==="sequence"?l=r*a+(r-1)*s("5"):l=r*a+(r-1)*s("16")+Ot(t)*s("4"),{track:a,table:o,least:Math.max(e.wide,l)}}function Ht(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function kt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Nt(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const h=a[a.length-2];if(Math.abs(h.x-l.x)<.01&&Math.abs(l.x-r.x)<.01||Math.abs(h.y-l.y)<.01&&Math.abs(l.y-r.y)<.01){a[a.length-1]=r;continue}}a.push(r)}}return a}var dt=t=>t.slice(1).map((e,n)=>[t[n],e]);function xt(t,e,n){const s=[];for(let o=0;oMath.min(i.x,d.x)+.75&&LMath.min(w.y,q.y)+.75&&Oa.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(a,o,r)=>{const l=[];let h=o;for(const u of a)l.push([h,h+u]),h+=u+r;return l};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var P=t=>t==="left"||t==="right",zt={top:"bottom",bottom:"top",left:"right",right:"left"};function je(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Te(t,e,n){const s=[];t.edges.forEach((o,r)=>{const l=t.byId.get(o.from),h=t.byId.get(o.to),[u,p]=e[r],g=l.row===h.row&&P(u)&&P(p)&&u===zt[p]||l.col===h.col&&!P(u)&&!P(p)&&u===zt[p];s.push({edge:r,end:"from",node:l,side:u,far:h,straight:g,f:.5},{edge:r,end:"to",node:h,side:p,far:l,straight:g,f:.5})});const a=new Map;for(const o of s){const r=`${o.node.id}.${o.side}`;a.has(r)||a.set(r,[]),a.get(r).push(o)}for(const[o,r]of a){if(r[0].node.shape==="decision")continue;const l=i=>P(i.side)?i.far.row-i.node.row:i.far.col-i.node.col,h=r.filter(i=>i.straight),u=r.filter(i=>!i.straight);if(u.sort((i,d)=>l(i)-l(d)||(P(i.side)?i.far.col-d.far.col:i.far.row-d.far.row)*(l(i)<0?1:-1)),r.length>3&&n(`${o.replace(".","'s ")} side has ${r.length} lines; more than three is an error: use another side`),!h.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((i,d)=>{i.f=(d+1)/(u.length+1)});continue}const p=new Map;for(const i of h)p.has(i.far.id)||p.set(i.far.id,[]),p.get(i.far.id).push(i);for(const i of p.values())i.length>1&&i.sort((d,w)=>d.edge-w.edge).forEach((d,w)=>{d.f=i.length===2?w===0?.25:.75:(w+1)/(i.length+1)});const g=Math.min(...h.map(i=>i.f)),c=Math.max(...h.map(i=>i.f)),y=u.filter(i=>l(i)<0),b=u.filter(i=>l(i)>=0);y.forEach((i,d)=>{i.f=g*(d+1)/(y.length+1)}),b.forEach((i,d)=>{i.f=c+(1-c)*(d+1)/(b.length+1)})}return s}function Wt(t,e,n){const{l:s,t:a,r:o,b:r}=t.rect;return P(e)?rt(t,e,a+(r-a)*n):rt(t,e,s+(o-s)*n)}function Dt(t,e,n,s){const a=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const r=t.byId.get(o.dataset.node);r&&a.set(r.id,{id:r.id,rect:lt(o,n),shape:r.shape,i:r.i})}),a}function Gt(t,e){const n=e.head,s=e.head/2,{x:a,y:o}=t.tip;return t.dir==="down"?{l:a-s,r:a+s,t:o-n,b:o}:t.dir==="up"?{l:a-s,r:a+s,t:o,b:o+n}:t.dir==="right"?{l:a-n,r:a,t:o-s,b:o+s}:{l:a,r:a+n,t:o-s,b:o+s}}var Kt=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Vt(t,e,n,s){const a=(o,r)=>{const l=o+r-Math.floor(o+r);return l<.005||l>.995?[0]:l<=.5?[-l,1-l]:[1-l,-l]};for(const o of a(t.t,n))for(const r of a(t.l,e)){if(!r&&!o)return t;const l={l:t.l+r,r:t.r+r,t:t.t+o,b:t.b+o};if(s(l))return l}return t}function Re(t,e,n,s,a,o,r,l,h){const u=r.space,p=[],g=[],c=[],y=[],b=u("1"),i=e.filter(d=>t.edges[d.i]?.label).sort((d,w)=>+(t.edges[w.i].kind==="main")-+(t.edges[d.i].kind==="main")||d.i-w.i);for(const d of i){const w=t.edges[d.i].label,q=l(w,"label"),L=16,O=d.pts.length-2,F=[];dt(d.pts).forEach(([$,G],j)=>{const v=Math.abs($.y-G.y)<.01,f=v?$.x:$.y;let m=v?G.x:G.y;const A=Math.sign(m-f)||1;j===O&&(m-=A*r.head);let S=[[f,m]];for(const K of a)for(const W of v?[K.l,K.r]:[K.t,K.b]){const M=v?$.y:$.x;(v?M>K.t&&MK.l&&MW>Math.min(I,k)+1&&W{const M=(K+W)/2,T=v?{x:M,y:$.y}:{x:$.x,y:M};return!a.some(I=>T.x>I.l&&T.xI.t&&T.y1&&z(K,W)?1:0})}),F.sort(($,G)=>G.pri-$.pri||G.len-$.len);let _=null,J=!1;const E=($,G=!0)=>{const j=Rt($,b);return G&&($.lo.r||$.to.b)||n.some(v=>Ft(j,v))||p.some(v=>ct(j,v))||s.heads.some(v=>ct(j,v))||s.rects.some(v=>ct(j,v))?!1:!e.some(v=>v.i!==d.i&&dt(v.pts).some(([f,m])=>ct(j,Kt(f,m,v.width))))};for(const $ of F){for(const G of[1/2,1/3,2/3]){const j=$.p+($.q-$.p)*G,v=[],f=u("2")+d.width/2;if($.horiz?($.len>=q+2*u("1")+u("3-5")&&v.push({box:{l:j-q/2-u("1"),r:j+q/2+u("1"),t:$.c-L/2,b:$.c+L/2},on:!0}),v.push({box:{l:j-q/2,r:j+q/2,t:$.c-f-L,b:$.c-f},on:!1}),v.push({box:{l:j-q/2,r:j+q/2,t:$.c+f,b:$.c+f+L},on:!1})):($.len>=L+u("3")&&v.push({box:{l:$.c-q/2-u("1"),r:$.c+q/2+u("1"),t:j-L/2,b:j+L/2},on:!0}),v.push({box:{l:$.c+f,r:$.c+f+q,t:j-L/2,b:j+L/2},on:!1}),v.push({box:{l:$.c-f-q,r:$.c-f,t:j-L/2,b:j+L/2},on:!1})),_=v.find(m=>E(m.box))??null,_)break;!J&&v.some(m=>E(m.box,!1))&&(J=!0)}if(_)break}if(!_){c.push(d.i),J&&y.push(d.i);continue}const V=Vt(_.box,h.ox,h.oy,$=>E($));p.push(V),g.push({i:d.i,text:w,box:V,on:_.on})}return{labels:g,unseated:c,bounded:y}}function Zt(t,e,n,s){const a=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(r=>{if(r.getClientRects().length===0||getComputedStyle(r).display==="contents")return;const l=lt(r,e);o.push(l),a.push({l:l.l,r:l.r,t:l.t,b:l.t+1},{l:l.l,r:l.r,t:l.b-1,b:l.b},{l:l.l,r:l.l+1,t:l.t,b:l.b},{l:l.r-1,r:l.r,t:l.t,b:l.b});const h=r.querySelector(`:scope > .${n}-glabel`);h&&h.getClientRects().length&&a.push(lt(h,e))}),t.querySelectorAll(`.${n}-lane`).forEach((r,l)=>{if(!r.getClientRects().length)return;const h=lt(r,e);l>0&&a.push({l:h.l,r:h.r,t:h.t-s/2-.5,b:h.t-s/2+.5});const u=r.querySelector(`.${n}-lane-name`);u&&a.push(lt(u,e))}),{obstacles:{rects:a,heads:[]},groups:o}}function Fe(t,e){const{m:s,tk:a,P:o,drawing:r,origin:l,warn:h}=t,u=a.space,p=Dt(s,r,l,o),g=[...p.values()],c=Be(r),y=l.left-Math.floor(l.left),b=l.top-Math.floor(l.top),i=Ht(y,b),d=r.clientWidth,w=r.clientHeight,q=M=>s.type==="data-flow"?M.col+1:M.col,L=parseFloat(getComputedStyle(r).rowGap)||0,O={w:d,h:w,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:y,oy:b};if(s.type==="sequence")return Ne(t,O,i);let F,_=[];s.type==="schema"?F=s.edges.map(M=>{const T=s.byId.get(M.from),I=s.byId.get(M.to);if(T.col===I.col){const k=T.col===s.cols&&s.cols>1?"left":"right";return[k,k]}return I.col>T.col?["right","left"]:["left","right"]}):(F=s.edges.map(M=>{const T=s.byId.get(M.from),I=s.byId.get(M.to),[k,B]=je(T,I);return[M.fromSide??k,M.toSide??B]}),_=Te(s,F,h||(()=>{})));const J=(M,T)=>{const I=r.querySelector(`.${o}-node[data-node="${CSS.escape(M)}"] .${o}-row[data-row="${T}"]`);if(!I)return 0;const k=lt(I,l);return(k.t+k.b)/2},E=s.edges.map((M,T)=>{const[I,k]=F[T],B=p.get(M.from),H=p.get(M.to),Z=$t(M.kind,a);if(M.fk){const U=J(M.from,M.fromRow),nt=J(M.to,M.toRow),Y=i.y(U,Z),R=i.y(nt,Z);return{p1:{x:I==="right"?B.rect.r:B.rect.l,y:Y},p2:{x:k==="right"?H.rect.r:H.rect.l,y:R},r1:U,r2:Math.abs(Y-R)<.01?U:nt}}const tt=_.find(U=>U.edge===T&&U.end==="from").f,Q=_.find(U=>U.edge===T&&U.end==="to").f;let N=Wt(B,I,tt),D=Wt(H,k,Q);const et=P(I)?N.y:N.x;let ot=P(k)?D.y:D.x;return P(I)?N={...N,y:i.y(N.y,Z)}:N={...N,x:i.x(N.x,Z)},P(k)?D={...D,y:i.y(D.y,Z)}:D={...D,x:i.x(D.x,Z)},P(I)&&P(k)&&Math.abs(N.y-D.y)<1.01&&(D={...D,y:N.y},ot=et),!P(I)&&!P(k)&&Math.abs(N.x-D.x)<1.01&&(D={...D,x:N.x},ot=et),N=P(I)?rt(B,I,N.y):rt(B,I,N.x),D=P(k)?rt(H,k,D.y):rt(H,k,D.x),{p1:N,p2:D,r1:et,r2:ot}}),V=new Set;s.type==="schema"&&s.edges.forEach((M,T)=>{Math.abs(s.byId.get(M.from).col-s.byId.get(M.to).col)>1&&V.add(T)});const $=new Map,G=new Set;s.edges.forEach((M,T)=>{if(V.has(T))return;const[I,k]=F[T],{p1:B,p2:H}=E[T],Z=s.byId.get(M.from),tt=s.byId.get(M.to);let Q=null,N=null,D=!1;if(I===k){if(P(I)){const U=I==="right"?Math.max(q(Z),q(tt)):Math.min(q(Z),q(tt))-1,nt=c.cols[U-1],Y=c.cols[U];nt&&Y&&(Q=`c${U}`,N=[nt[1],Y[0]],D=!0)}else{const U=I==="bottom"?Math.max(Z.row2,tt.row2):Math.min(Z.row,tt.row)-1,nt=c.rows[U-1],Y=c.rows[U];nt&&Y&&(Q=`r${U}`,N=[nt[1],Y[0]],D=!1)}Q&&G.add(T)}else if(P(I)&&P(k)&&Math.abs(B.y-H.y)>.5){const U=q(tt),nt=k==="left",Y=c.cols[(nt?U-1:U)-1],R=c.cols[(nt?U:U+1)-1];Y&&R&&(Q=`c${nt?U-1:U}`,N=[Y[1],R[0]],D=!0)}else if(!P(I)&&!P(k)&&Math.abs(B.x-H.x)>.5){const nt=k==="top"?tt.row-1:tt.row2,Y=c.rows[nt-1],R=c.rows[nt];Y&&R&&(Q=`r${nt}`,N=[Y[1],R[0]],D=!1)}if(!Q||!N)return;$.has(Q)||$.set(Q,{span:N,vertical:D,members:new Map});const et=`${M.to}.${k}.${Math.round(D?H.y:H.x)}`,ot=$.get(Q);ot.members.has(et)||ot.members.set(et,[]),ot.members.get(et).push(T)});const j=new Map,v=M=>{const[T,I]=F[M],{p1:k,p2:B}=E[M];if(P(T)&&P(I)){if(T===I){const Z=j.get(M)??(T==="right"?Math.max(k.x,B.x)+u("4"):Math.min(k.x,B.x)-u("4"));return[k,{x:Z,y:k.y},{x:Z,y:B.y},B]}if(Math.abs(k.y-B.y)<=.5)return[k,{x:B.x,y:k.y}];const H=j.get(M)??(k.x+B.x)/2;return[k,{x:H,y:k.y},{x:H,y:B.y},B]}if(!P(T)&&!P(I)){if(T===I){const Z=j.get(M)??(T==="bottom"?Math.max(k.y,B.y)+u("4"):Math.min(k.y,B.y)-u("4"));return[k,{x:k.x,y:Z},{x:B.x,y:Z},B]}if(Math.abs(k.x-B.x)<=.5)return[k,{x:k.x,y:B.y}];const H=j.get(M)??(k.y+B.y)/2;return[k,{x:k.x,y:H},{x:B.x,y:H},B]}return P(T)?[k,{x:B.x,y:k.y},B]:[k,{x:k.x,y:B.y},B]},f=M=>{const T=s.edges[M],I=$t(T.kind,a),k=v(M),B=Nt(k,I,i);let H;return k.length===B.length&&(H=dt(k).map(([Z,tt])=>Math.abs(Z.y-tt.y)<.75?(Z.y+tt.y)/2:(Z.x+tt.x)/2),H[0]=E[M].r1,H.length>1&&(H[H.length-1]=E[M].r2)),{i:M,from:T.from,to:T.to,kind:T.kind,pts:B,tip:B[B.length-1],dir:kt(B),dot:T.fk?B[0]:void 0,width:I,axes:H}},m=()=>s.edges.flatMap((M,T)=>V.has(T)?[]:[f(T)]);let A=null;const S=M=>{A??(A=m());const T=A.map(I=>M.has(I.i)?f(I.i):I);return{lines:T,score:He(T,M)*1e5+xt(T,void 0,M).length*1e3+St(T.filter(I=>M.has(I.i)),g,s).length}},z=(M,T)=>{const I=M.flatMap(k=>{const{p1:B,p2:H}=E[k];return T?[B.y,H.y]:[B.x,H.x]});return[Math.min(...I),Math.max(...I)]};for(const[,M]of $){const T=[...M.members.values()].map(k=>({members:k,run:z(k,M.vertical)})).sort((k,B)=>k.run[0]-B.run[0]),I=[];for(const k of T){const B=I[I.length-1];B&&B.some(H=>H.run[0]G.has(et)))continue;const B=k.map(et=>et.members),H=B.length,Z=(M.span[1]-M.span[0])/(H+1);ZU.forEach(Y=>j.set(Y,M.span[0]+Z*(nt+1))));const ot=S(tt);ot.scoreet.forEach(U=>j.set(U,M.span[0]+Z*(ot+1)))),A=D}}O.lines=m();for(const M of V)h?.(`${s.edges[M].from} to ${s.edges[M].to} is two columns apart, so its line is not drawn; its row still writes the target`);O.crossings=xt(O.lines),O.through=St(O.lines,g,s),O.outside=Xt(O.lines,d,w,a);const{obstacles:C,groups:K}=Zt(r,l,o,L);C.heads=O.lines.map(M=>Gt(M,a));const W=Re(s,O.lines,g,C,K,{l:0,t:0,r:d,b:w},a,e,{ox:y,oy:b});return O.labels=W.labels,O.unseated=W.unseated,O.bounded=W.bounded,O.overlaps=[...new Set(Jt(O.lines,null).flat())],O}function He(t,e){return Jt(t,e).length}function Jt(t,e){const n=[];for(let s=0;s=l)continue;const[d,w]=c?[h.x,u.x]:[h.y,u.y],[q,L]=c?[p.x,g.x]:[p.y,g.y];Math.min(Math.max(d,w),Math.max(q,L))-Math.max(Math.min(d,w),Math.min(q,L))>1&&n.push([o.i,r.i])}}return n}function*Ut(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const h=l===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return r.x-h<-.5||r.x+h>e+.5||r.y-h<-.5||r.y+h>n+.5})&&a.push(o.i);return a}function St(t,e,n){const s=[];for(const a of t){const o=dt(a.pts);e.some(r=>o.some(([l,h])=>Ie(l,h,r)))&&s.push(a.i)}return s}function Ne(t,e,n){const{m:s,tk:a,P:o,drawing:r,origin:l}=t,h=a.space,u=new Map;r.querySelectorAll(`.${o}-node`).forEach(b=>u.set(b.dataset.node,lt(b,l)));const p=r.querySelector(`.${o}-steps`),g=p?lt(p,l).b:e.h,c=b=>{const i=u.get(b);return i?n.x((i.l+i.r)/2,a.hair):0};for(const b of s.nodes){const i=u.get(b.id);i&&e.lifelines.push({x:c(b.id),y1:i.b,y2:g})}const y=b=>u.get(b.id);return r.querySelectorAll(`.${o}-msg`).forEach(b=>{const i=b.dataset.from,d=b.dataset.to,w=b.dataset.kind??"plain",q=$t(w,a),L=lt(b,l),O=n.y((L.t+L.b)/2,q),F=Number(b.querySelector(`.${o}-num`)?.textContent??0),_=c(i),J=c(d);let E;if(i===d){const m=b.dataset.self==="start"?-h("6"):h("6"),A=n.y(O-h("2"),q),S=n.y(O+h("2"),q);E=[{x:_,y:A},{x:n.x(_+m,q),y:A},{x:n.x(_+m,q),y:S},{x:_,y:S}]}else E=[{x:_,y:O},{x:J,y:O}];e.lines.push({i:F,from:i,to:d,kind:w,pts:E,tip:E[E.length-1],dir:kt(E),width:q});const V=b.querySelector(`.${o}-said`),$=b.querySelector(`.${o}-note`),G=s.byId.get(i),j=s.byId.get(d);if(!G||!j)return;const v=i===d?(()=>{const m=s.nodes[G.i+(b.dataset.self==="start"?-1:1)],A=m?c(m.id):b.dataset.self==="start"?0:e.w;return Math.abs(A-_)-h("6")-h("2-5")-h("2")})():Math.abs(J-_)-2*h("2");Math.max(V?V.getBoundingClientRect().width:0,$?$.getBoundingClientRect().width:0)>v+.5&&e.unseated.push(F)}),e}function Yt(t,e,n,s=ut()){const{m:a,tk:o,P:r,drawing:l,origin:h}=t,u=o.space,p=Dt(a,l,h,r),g=[...p.values()],c=h.left-Math.floor(h.left),y=h.top-Math.floor(h.top),b=Ht(c,y),i=l.clientWidth,d=l.clientHeight,w={w:i,h:d,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:y},q=ut();if(a.type==="sequence"||a.type==="schema")return{geo:w,grow:q};const L=i-(parseFloat(getComputedStyle(l).paddingRight)||0),O=(v,f,m)=>{const A=[v];for(let S=1;S<=(ft(s,f)??0);S++)A.push({...v,t:v.t+m*u("4")*S,b:v.b+m*u("4")*S});return A},F=new Map;l.querySelectorAll(`.${r}-node`).forEach(v=>{const f=v.parentElement,m=lt(f,h),A=getComputedStyle(f);F.set(v.dataset.node,m.r-(parseFloat(A.paddingRight)||0)-(parseFloat(A.borderRightWidth)||0))});const _=a.nodes,J=v=>p.get(_[v].id),E=[],V=v=>$t(a.edges[v].kind,o);a.edges.forEach((v,f)=>{const m=n.routes[f],A=p.get(v.from),S=p.get(v.to),z=V(f);let C=[];const K=v.label,W=K?e(K,"label"):0,M=16,T=u("4");if(m==="down"||m==="up"){const k=Math.max(A.rect.l,S.rect.l),B=Math.min(A.rect.r,S.rect.r),H=a.edges.map((N,D)=>({o:N,j:D})).filter(({o:N,j:D})=>(n.routes[D]==="down"||n.routes[D]==="up")&&(N.from===v.from&&N.to===v.to||N.from===v.to&&N.to===v.from)),Z=H.findIndex(N=>N.j===f),tt=H.length<2?.5:H.length===2?Z===0?.25:.75:(Z+1)/(H.length+1),Q=b.x(k+(B-k)*tt,z);if(C=m==="down"?[rt(A,"bottom",Q),rt(S,"top",Q)]:[rt(A,"top",Q),rt(S,"bottom",Q)],K){let N=Math.min(C[0].y,C[1].y),D=Math.max(C[0].y,C[1].y);m==="down"?D-=o.head:N+=o.head;const et=[...l.querySelectorAll(`.${r}-group`)].map(Y=>lt(Y,h));let ot=[[N,D]];for(const Y of et)for(const R of[Y.t,Y.b])ot=ot.flatMap(([X,st])=>R>X+1&&Ret.some(X=>(Y+R)/2>X.t&&(Y+R)/2X.l&&Q1){const Y=ot.filter(([X,st])=>!U(X,st));[N,D]=(Y.length?Y:ot).reduce((X,st)=>st[1]-st[0]>X[1]-X[0]?st:X)}const nt=[1/2,1/3,2/3].map(Y=>{const R=N+(D-N)*Y;return{l:Q-W/2-u("1"),r:Q+W/2+u("1"),t:R-M/2,b:R+M/2}});E.push({k:f,cands:nt,on:!0,card:m==="down"?v.to:v.from})}}else if(m==="trunk"||m==="rail"){const k=b.x(Math.max(A.rect.l,m==="rail"?S.rect.l:A.rect.l)+u(m==="trunk"?"8":"3"),z),B=rt(A,"bottom",k);if(m==="rail"){if(C=[B,rt(S,"top",k)],K){const H=S.rect.t-u("6");E.push({k:f,cands:O({l:k+u("2-5"),r:k+u("2-5")+W,t:H-M/2,b:H+M/2},v.to,-1),on:!1,card:v.to})}}else{const H=b.x(S.rect.l+u("6"),z),Z=b.y(S.rect.t-T,z);C=[B,{x:k,y:Z},{x:H,y:Z},rt(S,"top",H)],K&&E.push({k:f,cands:O({l:H+u("2-5"),r:H+u("2-5")+W,t:Z-M/2,b:Z+M/2},v.to,-1),on:!1,card:v.to})}}else{const k=Math.min(F.get(v.from)??i,F.get(v.to)??i),B=b.x(n.gutter?L+(n.lanes[f]?2*u("3-5"):u("3-5")):k-u("2-5"),z),H=b.y(A.rect.t+(A.rect.b-A.rect.t)*n.exits[f],z),Z=rt(A,"right",H),tt=b.x(S.rect.r-u("6"),z),Q=m==="end-down",N=b.y(Q?S.rect.t-T:S.rect.b+T,z);C=[Z,{x:B,y:Z.y},{x:B,y:N},{x:tt,y:N},rt(S,Q?"top":"bottom",tt)];const D=Q?v.to:_[S.i+1]?.id??v.to;K&&E.push({k:f,cands:O({l:tt-u("2-5")-W,r:tt-u("2-5"),t:N-M/2,b:N+M/2},D,Q?-1:1),on:!1,card:D})}const I=Nt(C,z,b);w.lines.push({i:f,from:v.from,to:v.to,kind:v.kind,pts:I,tip:I[I.length-1],dir:kt(I),width:z})}),w.crossings=xt(w.lines),w.through=St(w.lines,g,a),w.outside=Xt(w.lines,i,d,o);const{obstacles:$}=Zt(l,h,r,0);$.heads=w.lines.map(v=>Gt(v,o));const G=[],j={l:0,t:0,r:i,b:d};for(const v of E){const f=S=>{const z=Rt(S,u("1"));return S.lj.r+.5||S.tj.b+.5||g.some(C=>Ft(z,C))||G.some(C=>ct(z,C))||$.heads.some(C=>ct(z,C))||$.rects.some(C=>ct(z,C))||w.lines.some(C=>C.i!==v.k&&dt(C.pts).some(([K,W])=>ct(z,Kt(K,W,C.width))))},m=v.cands.find(S=>!f(S));m||(q[v.card]=(q[v.card]??0)+1,w.unseated.push(v.k));const A=m?Vt(m,c,y,S=>!f(S)):v.cands[0];G.push(A),w.labels.push({i:v.k,text:a.edges[v.k].label,box:A,on:v.on})}return{geo:w,grow:q}}function ze(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...O})),g=p[p.length-1];g.x-=o.x*u,g.y-=o.y*u;const c=e.tip.x-o.x*l,y=e.tip.y-o.y*l,b=-o.y*h,i=o.x*h,d=O=>Math.round(O*100)/100,w=it(e.kind),q=r?``:``,L=e.dot?``:"";return`${q}${L}`}function Qt(t,e,n,s){const a=new Map,o=new Map;for(const l of e.crossings)o.has(l.under)||o.set(l.under,[]),o.get(l.under).push(l);let r="";for(const[l,h]of o){const u=`${s}-cut-${l}`;a.set(l,u);const p=h.map(g=>{const c=e.lines[g.top],y=e.lines[g.under],b=c.width/2+n.cut,i=y.width/2+1;return g.underVertical?``:``}).join("");r+=`${p}`}return{defs:r,ids:a}}function Pt(t,e,n,s){const{defs:a,ids:o}=Qt(t,e,n,s),r=e.lifelines.map(p=>``).join(""),l=e.lines.map((p,g)=>De(t,p,n,o.get(g)??null,p.from===p.to?n.radiusXs:n.radius)).join(""),h=`${a?`${a}`:""}${r}${l}`,u=e.labels.map(p=>`${it(p.text)}`).join("");return h+u}function Ge(t,e,n,s,a,o,r){const h=t.querySelector(`.${n}-drawing`);if(!h||t.clientWidth===0)return{dyn:a,geo:null,ink:"",tokens:null};const u=Le(t),p=_e(h,n),g=Ce(e,u,p),c=t.clientWidth,y=(()=>{const E=document.activeElement;return E&&h.contains(E)&&E.dataset.node?E.dataset.node:void 0})(),b=E=>ht(e,E)?{...E,stop:E.stop&&e.byId.has(E.stop)?E.stop:e.nodes[0]?.id,keep:void 0}:{...E,stop:E.stop??e.nodes[0]?.id,keep:y&&E.layout!=="drawn"?y:void 0},i=E=>{if(e.type!=="flowchart")return E;o({...E,heights:void 0,words:void 0});const V=ut(),$=ut();return h.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(G=>{const j=G.querySelector(`.${n}-words`);if(!j)return;const v=G.getBoundingClientRect(),f=S=>{const z={w:S.width+2*u.space("2-5"),h:S.height+2*u.space("2")},C=1-z.w/v.width,K=C>.05?z.h/2/C:z.h*10;return Math.max(u.space("16"),Math.ceil(v.width/5),Math.ceil(2*K))},m=j.getBoundingClientRect();let A=f(m);if(A>v.width){const S=W=>(G.style.setProperty("--_ww",`${W}px`),j.getBoundingClientRect()),z=Math.floor(G.clientWidth-2*u.space("2-5"));let C=Math.ceil(m.width),K=m.height;for(;C1;){const k=W+M>>1;S(k).height({m:e,tk:u,P:n,drawing:h,origin:h.getBoundingClientRect(),warn:r}),w=a.autoOpen?{open:!1,autoOpen:void 0}:{},q=(E,V)=>V.map($=>yt(e,E.lines.find(G=>G.i===$))).join(", ");if(c>=g.least){const E=j=>{let v=b({...a,...w,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return v=i(v),o(v),{dd:v,g:Fe(d(),p)}};let{dd:V,g:$}=E(!1);const G=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0;if(!G($)&&$.unseated.length&&$.unseated.every(j=>$.bounded?.includes(j))){const j=E(!0);!G(j.g)&&!j.g.unseated.length&&({dd:V,g:$}=j)}if(!G($)&&!$.unseated.length)return $.crossings.length&&r?.(`${$.crossings.length} crossing${$.crossings.length===1?"":"s"} in the drawn layout: ${$.crossings.map(j=>`${yt(e,$.lines[j.top])} over ${yt(e,$.lines[j.under])}`).join("; ")}`),{dyn:V,geo:$,ink:Pt(n,$,u,s),tokens:u};$.through.length&&r?.(`the drawn layout does not fit at ${Math.round(c)}px: ${q($,$.through)} would pass through a node`),$.overlaps?.length&&r?.(`the drawn layout does not fit at ${Math.round(c)}px: ${q($,$.overlaps)} would lie on one another`),$.outside.length&&r?.(`the drawn layout does not fit at ${Math.round(c)}px: ${q($,$.outside)} would leave the drawing`),$.unseated.length&&r?.(`the drawn layout does not fit at ${Math.round(c)}px: no clean seat for ${$.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let L=b({...a,...w,layout:"stacked",heights:void 0,grow:ut(),track:e.type==="schema"?g.table:void 0,bare:void 0,pad:void 0});if(L=i(L),o(L),e.type==="sequence"||e.type==="schema")return{dyn:L,geo:null,ink:"",tokens:u};const O=_t(e);let F=Yt(d(),p,O,L.grow);for(let E=0;E<6&&Object.keys(F.grow).length;E++){const V=ut(L.grow);for(const[$,G]of Object.entries(F.grow))V[$]=(ft(V,$)??0)+G;L={...L,grow:V},o(L),F=Yt(d(),p,O,V)}const _=F.geo;if(_.unseated.length>0||_.through.length>0||_.outside.length>0||O.third){_.unseated.length&&r?.(`the stacked drawing has no clean seat for ${[...new Set(_.unseated)].map($=>`"${e.edges[$]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),_.through.length&&r?.(`in the stacked drawing ${q(_,_.through)} would pass through a node, so its lines are not drawn`),_.outside.length&&r?.(`in the stacked drawing ${q(_,_.outside)} would leave the drawing, so its lines are not drawn`),O.third&&r?.("the stacked drawing would need a third end lane, so its lines are not drawn");const E={..._,lines:[],labels:[],crossings:[]};return{dyn:b({...L,grow:ut(),bare:!0,open:a.bare?a.open:!0,autoOpen:a.bare?a.autoOpen:a.open?void 0:!0}),geo:E,ink:"",tokens:u}}return _.crossings.length&&r?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${_.crossings.map(E=>`${yt(e,_.lines[E.top])} over ${yt(e,_.lines[E.under])}`).join("; ")}`),{dyn:L,geo:_,ink:Pt(n,_,u,s),tokens:u}}function yt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Ke(t,e,n,s,a,o){const r=new Set;if(o){r.add(o);for(const i of n?.lines??[])i.from===o&&r.add(i.to),i.to===o&&r.add(i.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(i=>i.toggleAttribute("data-near",r.has(i.dataset.node))),!n||!s)return;const l=i=>!!o&&(i.from===o||i.to===o),h=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(i=>u.set(i.getAttribute("data-edge"),i));for(const i of n.lines){const d=u.get(String(i.i));d&&(d.toggleAttribute("data-lit",l(i)),d.toggleAttribute("data-dim",!!o&&!l(i)))}if(t.querySelectorAll(`.${e}-label`).forEach(i=>{const d=n.lines.find(w=>String(w.i)===i.dataset.edge);i.toggleAttribute("data-lit",!!(d&&l(d)))}),h){for(const i of n.lines)if(l(i)){const d=u.get(String(i.i));d&&h.appendChild(d)}}const p=xt(n.lines,l),{defs:g,ids:c}=Qt(e,{...n,crossings:p},s,a),y=t.querySelector(`.${e}-svg`);if(!y)return;let b=y.querySelector("defs");!b&&g&&(b=document.createElementNS("http://www.w3.org/2000/svg","defs"),y.insertBefore(b,y.firstChild)),b&&(b.innerHTML=g),n.lines.forEach((i,d)=>{const w=u.get(String(i.i))?.querySelector(`.${e}-line`);if(!w)return;const q=c.get(d);q?w.setAttribute("mask",`url(#${q})`):w.removeAttribute("mask")})}var Ve=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Ze(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Ve()?"done":"pending")}}function Je(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Ue(t,e,n){const s=t.byId.get(e)?.i??0,a=t.nodes.length;let o;if(n==="ArrowRight"||n==="ArrowDown")o=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")o=s-1;else if(n==="Home")o=0;else if(n==="End")o=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,o))].id}var Xe=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],te=["data-layout","data-measured","data-bare","data-motion"],Ye=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ee=t=>t==null||t===!1;function Qe(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function ne(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?te:Xe;for(const r of s)ee(e.a[r])&&t.removeAttribute(r);for(const[r,l]of Object.entries(e.a)){if(r==="class")continue;if(r==="style"){const u=t.style,p=new Map(String(l??"").split(";").map(g=>{const c=g.indexOf(":");return[g.slice(0,c).trim(),g.slice(c+1).trim()]}).filter(([g])=>g));for(const[g,c]of p)u.getPropertyValue(g).trim()!==c&&u.setProperty(g,c);for(const g of Ye)p.has(g)||u.removeProperty(g);continue}if(n&&!te.includes(r))continue;if(ee(l)){t.removeAttribute(r);continue}const h=l===!0?"":String(l);t.getAttribute(r)!==h&&t.setAttribute(r,h)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(r=>typeof r!="string"&&"slot"in r))return;const a=[...t.children];let o=0;for(const r of e.c)if(!(typeof r=="string"||"slot"in r)){for(let l=o;lt.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&a(n)?.setAttribute("tabindex","-1"),a(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function a(c,y){return{prefix:n,base:c,hasSource:y.source!==void 0&&y.source!==null&&y.source!=="",hiddenClass:"visually-hidden"}}function o(c,y,b,i){var d=function(w){return''+it(w)+""};return{source:it(String(y.source||"")),summary:it(String(y.summary||"")),hint:Ae(c).map(function(w){return""+w.keys.map(d).join(" ")+" "+it(w.words)+""}).join(""),toggle:'"}}function r(c,y){var b=Et(c),i=Tt(b,{},a(y,c)),d=It(i,o(b,c,y,!1)),w=d.indexOf(">");return{open:d.slice(0,w+1),inner:d.slice(w+1,d.length-9),warnings:b.warnings}}var l=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],h=["--_cols","--_gpad","--_track"];function u(c,y,b){c.__diagram&&c.__diagram.stop();var i=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),d=Et(y);if(!b||!i||!c.querySelector(":scope > .diagram-drawing")){if(!i||!c.querySelector("#"+CSS.escape(i+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););i="dg"+s}var w=r(y,i),q=document.createElement("div");q.innerHTML=w.open+"
";var L=q.firstChild;l.forEach(function(R){c.removeAttribute(R)}),h.forEach(function(R){c.style.removeProperty(R)});for(var O=0;O :not(script[data-diagram])").forEach(function(R){R.remove()}),c.insertAdjacentHTML("beforeend",w.inner)}d.warnings.forEach(function(R){console.warn("Basalt diagram: "+R)});var _=a(i,y),J={},E=null,V=null,$=null,G=Object.create(null),j=function(R){G[R]||(G[R]=1,console.warn("Basalt diagram: "+R))},v=function(R){ne(c,Tt(d,R,_))},f=c.querySelector(".diagram-ink"),m=c.querySelector(".diagram-toggle"),A=d.motion.animated&&typeof e.diagramMotion=="function",S=null,z=null,C=function(){A&&Je(c)};function K(){Ke(c,n,E&&E.geo,E&&E.tokens,i,V||$)}function W(){m&&(m.setAttribute("aria-expanded",String(!!J.open)),m.firstElementChild.textContent=J.open?"Hide the list":"View as list")}function M(){E=Ge(c,d,n,i,J,v,j),J=E.dyn,v(J),W(),ht(d,J)||($=null);var R=f&&E.ink!==z;R&&(f.innerHTML=E.ink,z=E.ink),K(),A&&E.tokens&&(Ze(c,!!(E.geo&&E.geo.lines.length)),R&&S&&S.redrawn())}function T(R){J=R,v(J)}function I(R){var X=J.stop;J=Object.assign({},J,{stop:R}),Pe(c,n,X,R)}var k=function(R){var X=R&&R.closest?R.closest(".diagram-node"):null;return X&&c.contains(X)?X:null};function B(R){var X=k(R.target);if(!(!X||R.defaultPrevented)){if(C(),R.key==="Escape"){(V||$)&&(R.preventDefault(),V=$=null,K());return}if(ht(d,J)){var st=Ue(d,X.getAttribute("data-node"),R.key);if(st){R.preventDefault(),I(st);var oe=c.querySelector('.diagram-node[data-node="'+CSS.escape(st)+'"]');oe&&oe.focus()}}}}function H(R){var X=k(R.target);if(X){C();var st=X.getAttribute("data-node");V=X.matches(":focus-visible")?st:null,ht(d,J)&&J.stop!==st&&I(st),K()}}function Z(R){var X=k(R.target);X&&(k(R.relatedTarget)||(V=null),J.keep===X.getAttribute("data-node")&&T(Object.assign({},J,{keep:void 0})),K())}function tt(R){if(!(R.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var X=k(R.target);X&&C();var st=X&&ht(d,J)?X.getAttribute("data-node"):null;st!==$&&($=st,K())}}function Q(){$&&($=null,K())}function N(){C(),T(Object.assign({},J,{open:!J.open,autoOpen:void 0})),W()}c.addEventListener("keydown",B),c.addEventListener("focusin",H),c.addEventListener("focusout",Z),c.addEventListener("pointerover",tt),c.addEventListener("pointerleave",Q),m&&m.addEventListener("click",N),M();var D=c.clientWidth,et=0,ot=!0,U=new ResizeObserver(function(){Math.abs(c.clientWidth-D)<.5||(D=c.clientWidth,cancelAnimationFrame(et),et=requestAnimationFrame(M))});U.observe(c),document.fonts&&document.fonts.ready.then(function(){ot&&M()});var nt=matchMedia("(forced-colors: active)"),Y=d.nodes.some(function(R){return R.mark});Y&&nt.addEventListener("change",M),A&&(S=e.diagramMotion(c,{fig:c,P:n,base:i,model:function(){return d},geo:function(){return E&&E.geo},tokens:function(){return E&&E.tokens}},y)),c.__diagram={stop:function(){ot=!1,U.disconnect(),cancelAnimationFrame(et),Y&&nt.removeEventListener("change",M),S&&S.destroy(),c.removeEventListener("keydown",B),c.removeEventListener("focusin",H),c.removeEventListener("focusout",Z),c.removeEventListener("pointerover",tt),c.removeEventListener("pointerleave",Q),m&&m.removeEventListener("click",N)},layout:M,key:p(y),send:S&&S.sendValue?S.sendValue:null}}function p(c){try{return JSON.stringify(c,function(y,b){return y==="packet"&&b&&typeof b=="object"?Object.assign({},b,{send:void 0}):b})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var y=c.querySelector(":scope > script[data-diagram]");if(y)try{u(c,JSON.parse(y.textContent),!0)}catch(b){console.error("Basalt diagram: this figure could not be drawn",b)}}})}e.diagramMarkup=r,t.diagram=function(c,y){var b=c.__diagram,i=b&&b.send?p(y):null;if(i!==null&&i===b.key){b.send(y.packet?y.packet.send:void 0);return}u(c,y)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); +(()=>{var he=["top","right","bottom","left"],pe=["main","plain","dashed"],ge=[2,3,4,5,6],rt=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),pt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function St(t,e={}){const s=e.checks!==!1,r=[],o=d=>{r.push(d)},a=t.legend??{},i={};for(const d of["main","plain","dashed","focal","group"]){const y=rt(a[d]);y&&(i[d]=y)}const f=t.stepLabel,h=typeof f=="function"?d=>String(f(d)):typeof f=="string"?(d=>f.replace("{n}",String(d))):d=>`Step ${d}`,u=t.shapeLabels??{},g={terminal:rt(u.terminal)??"Start or end",step:rt(u.step)??"Step",decision:rt(u.decision)??"Decision"},c=t.heading===void 0?3:ge.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),m=(d,y)=>d==null?"plain":pe.includes(d)?d:(o(`"${String(d)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),b=d=>{if(d!=null){if(he.includes(d))return d;o(`"${String(d)}" is not a side (top, right, bottom or left): the derived side is used`)}},l=(d,y)=>typeof d=="number"&&Number.isInteger(d)&&d>=1?d:(o(`${y} is ${JSON.stringify(d)}, not a whole number from 1: it is placed at 1`),1),p=[],$=[];let q=[];const E=[],B=[],j=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(j)||o(`"${String(j)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),j==="architecture"||j==="flowchart"){for(const d of t.nodes??[]){const y=j==="flowchart"&&d.shape==="decision"?"decision":j==="flowchart"&&d.shape==="terminal"?"terminal":"box",S=String(d.id??""),L=l(d.row,`the row of ${S}`);p.push({id:S,i:p.length,name:String(d.name??""),kind:y==="decision"?void 0:rt(d.kind),detail:y==="decision"?void 0:rt(d.detail),mono:!!d.detailMono,focal:!!d.focal,col:l(d.col,`the column of ${S}`),row:L,row2:L,branch:!!d.branch,shape:y,group:j==="architecture"?rt(d.group):void 0,mark:j==="architecture"?me(d.mark):void 0})}if(j==="architecture")for(const d of t.groups??[]){const y=String(d.id??"");E.push({id:y,label:String(d.label??""),members:p.filter(S=>S.group===y).map(S=>S.id)})}}else if(j==="data-flow"){q=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const d=new Map(q.map((y,S)=>[y.id,S+1]));for(const y of t.nodes??[]){const S=String(y.id??""),L=String(y.lane??""),H=d.get(L);H===void 0&&o(`a node (${S}) names the lane "${L}", which is not in lanes`);const T=p.length+1;p.push({id:S,i:p.length,name:String(y.name??""),kind:h(T),detail:rt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:l(y.col,`the column of ${S}`),row:H??1,row2:H??1,branch:!1,shape:"box",lane:H??1,laneLabel:q[(H??1)-1]?.label??L,step:T})}}else if(j==="sequence"){(t.participants??[]).forEach((y,S)=>{const L=String(y.name??"");p.push({id:String(y.id??""),i:S,name:L,kind:rt(y.kind),mono:!1,focal:!!y.focal,col:S+1,row:1,row2:1,branch:!1,shape:"participant",short:rt(y.short)??L})});let d=0;for(const y of t.steps??[])"band"in y?B.push({band:String(y.band??"")}):(d++,B.push({n:d,from:String(y.from??""),to:String(y.to??""),label:String(y.label??""),note:rt(y.note),kind:m(y.kind,`message ${d}`)}))}else if(j==="schema")for(const d of t.tables??[]){const y=String(d.name??""),[S,L]=Array.isArray(d.row)?d.row:[d.row,d.row],H=l(S,`the row of ${y}`),T=Math.max(H,l(L,`the last row of ${y}`)),G=d.more===void 0||d.more===null?void 0:Number.isInteger(d.more)&&d.more>0?d.more:(o(`${y}'s "more" is ${JSON.stringify(d.more)}, not a whole number from 1: it is left out`),void 0);p.push({id:y,i:p.length,name:y,mono:!0,focal:!!d.focal,col:l(d.col,`the column of ${y}`),row:H,row2:T,branch:!1,shape:"table",more:G,columns:(d.columns??[]).map(W=>({name:String(W.name??""),type:rt(W.type),key:W.key==="PK"||W.key==="FK"?W.key:(W.key!==void 0&&W.key!==null&&o(`${y}.${String(W.name)}'s key is "${String(W.key)}", not PK or FK: it is left out`),void 0)}))})}const R=new Map;for(const d of p)d.id?R.has(d.id)&&o(`the id "${d.id}" is used twice`):o("a node has no id"),R.set(d.id,d);if(j==="schema")(t.tables??[]).forEach(d=>(d.columns??[]).forEach((y,S)=>{const L=rt(y.references);if(!L)return;const[H,T]=L.split("."),G=R.get(H??""),W=G?.columns?.findIndex(C=>C.name===T)??-1;if(!G||W<0){o(`${String(d.name)}.${String(y.name)} references ${L}, which is not a shown column`);return}const k=R.get(String(d.name??""));k.columns[S].ref={table:H,column:T,row:W},$.push({i:$.length,from:k.id,to:H,kind:"plain",fromRow:S,toRow:W,fk:!0})}));else if(j!=="sequence")for(const d of t.edges??[]){const y=String(d.from??""),S=String(d.to??"");if(!R.has(y)||!R.has(S)){o(`a line names ${R.has(y)?S:y}, which is not a node`);continue}const L=rt(d.label);L&&L.length>_t&&o(`the label "${L}" is over ${_t} characters: longer words belong in the node or the summary`),$.push({i:$.length,from:y,to:S,kind:m(d.kind,`the line from ${y} to ${S}`),label:L,fromSide:b(d.fromSide),toSide:b(d.toSide),flow:j!=="flowchart"&&d.flow===!0?!0:void 0})}else for(const d of B)"n"in d&&(!R.has(d.from)||!R.has(d.to))&&o(`message ${d.n} names ${R.has(d.from)?d.to:d.from}, which is not a participant`);if(s&&j!=="sequence"){const d=new Map;for(const y of p)for(let S=y.row;S<=y.row2;S++){const L=`${y.col}:${S}`;d.has(L)&&o(`${y.id} and ${d.get(L)} share the cell at column ${y.col}, row ${S}`),d.set(L,y.id)}}if(s){for(const y of E){const S=y.members.map(T=>R.get(T));if(!S.length)continue;const L={c1:Math.min(...S.map(T=>T.col)),c2:Math.max(...S.map(T=>T.col)),r1:Math.min(...S.map(T=>T.row)),r2:Math.max(...S.map(T=>T.row2))};for(const T of p)T.group!==y.id&&T.col>=L.c1&&T.col<=L.c2&&T.row>=L.r1&&T.row<=L.r2&&o(`${T.id} is inside the box of the group "${y.label}" but not a member`);const H=S.map(T=>T.i);Math.max(...H)-Math.min(...H)+1!==H.length&&o(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of p)y.group&&!E.some(S=>S.id===y.group)&&o(`${y.id} names the group "${y.group}", which is not in groups`);p.filter(y=>y.focal).length>1&&o("more than one node is focal: a diagram has one at most");const d=new Set(j==="sequence"?B.flatMap(y=>"n"in y?[y.kind]:[]):$.map(y=>y.kind));d.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),d.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),p.some(y=>y.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const Q=j==="architecture"||j==="data-flow",A=d=>Array.isArray(d)&&d.length>1?d.map(String):void 0,V=Q&&t.packet&&typeof t.packet=="object"?t.packet:void 0,v=V&&A(V.path),D={animated:t.motion==="animated",pulse:Q?A(t.pulse):void 0,packet:v?{path:v,repeat:V.repeat===!0,send:V.send}:void 0,run:j==="sequence"&&t.run===!0};if(s)for(const d of p){const y=d.mark?.says;if(!y?.length)continue;const S=[d.name,d.kind,d.detail].filter(Boolean).join(" ").toLowerCase();y.some(L=>S.includes(L.toLowerCase()))||o(`${d.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const I=Math.max(1,...p.map(d=>d.col)),w=j==="data-flow"?Math.max(1,q.length):Math.max(1,...p.map(d=>d.row2));return{type:j,title:String(t.title??""),heading:c,legend:i,nodes:p,byId:R,edges:$,groups:E,lanes:q,steps:B,cols:I,rows:w,shapeLabels:g,stepWord:h,warnings:r,motion:D,memo:new Map}}function me(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=rt(e.onLight);if(n)return{onLight:n,onDark:rt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ot=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function xt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var _t=28,mt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Bt(t,e){return t.legend[e]}function ye(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function $e(t,e){return xt(t,`sentence:${e.i}`,()=>be(t,e))}function be(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,r=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(mt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`)}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?ye(t,e):e.kind;if(n.push(mt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(mt(e.detail)),e.group){const a=t.groups.find(i=>i.id===e.group);a&&n.push(`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${a.label})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${a.label})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(mt(t.legend.focal)),n.join(" ")}function Ct(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function x(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var we={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>we[e]),xe=" br img input meta link hr path polygon polyline circle rect line ";function Et(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return xe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Et(s,e)).join("")}`}var ve=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function gt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Me(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function jt(t){let e=0;for(const n of t.groups){const s=n.members.map(r=>t.byId.get(r).col);s.length&&(Math.min(...s)===1&&(e|=1),Math.max(...s)===t.cols&&(e|=2))}return(e&1)+(e>>1&1)}function At(t){return t.type==="sequence"?t.nodes.length:t.cols}function Tt(t){return xt(t,"plan",()=>ke(t))}function ke(t){const e=t.nodes,n=l=>t.type==="data-flow"||!e[l].branch,s=t.edges.map(l=>{const p=t.byId.get(l.from).i,$=t.byId.get(l.to).i,E=e.slice(Math.min(p,$)+1,Math.max(p,$)).every(B=>!n(B.i));return $===p+1&&!(n(p)&&!n($))?"down":$===p-1?"up":$>p&&n(p)&&!n($)&&E?"trunk":$>p&&n(p)&&n($)&&E?"rail":$>p?"end-down":"end-up"}),r=t.edges.map((l,p)=>({e:l,k:p})).filter(({k:l})=>s[l]==="end-down"||s[l]==="end-up"),o=l=>{const p=t.byId.get(l.from).i,$=t.byId.get(l.to).i;return[Math.min(p,$),Math.max(p,$)]},a=(l,p)=>{const[$,q]=o(l),[E,B]=o(p);return ${const p=t.byId.get(l.from).i,[$,q]=o(l);return!n(p)&&e.slice($+1,q).every(E=>!n(E.i))&&r.every(E=>E.e===l||!a(E.e,l))}),f=r.length>0&&(t.type==="data-flow"||!i),h=l=>{const[p,$]=o(l);return $-p},u=t.edges.map(()=>0);let g=!1;const c=[];for(const l of[...r].sort((p,$)=>h(p.e)-h($.e)||p.k-$.k)){let p=0;for(const $ of c)a($.e,l.e)&&(p=Math.max(p,u[$.k]+1));u[l.k]=p,p>1&&(g=!0),c.push(l)}const m=t.edges.map(()=>.5);for(const l of e){const p=r.filter(({e:E})=>E.from===l.id);if(p.length<2)continue;const $=p.filter(({k:E})=>s[E]==="end-down").sort((E,B)=>h(B.e)-h(E.e)||E.k-B.k);[...p.filter(({k:E})=>s[E]==="end-up").sort((E,B)=>h(E.e)-h(B.e)||B.k-E.k),...$].forEach(({k:E},B,j)=>{m[E]=j.length===2?B===0?1/3:2/3:(B+1)/(j.length+1)})}const b=ht();for(let l=1;l{const A=s[Q],V=t.byId.get(R.from).i,v=t.byId.get(R.to).i,D=v===l&&(A==="down"||A==="trunk"||A==="rail"||A==="end-down"),I=V===l&&v===l-1&&A==="up",w=v===l-1&&A==="end-up";D&&(A==="trunk"||A==="end-down")&&(B=!0),w&&(j=!0),(D||I||w)&&R.label&&(q++,E=Math.max(E,A==="trunk"?40:48))}),(q>1||B&&j)&&(E=64),b[p.id]=E}return{routes:s,gutter:f,lanes:u,exits:m,gaps:b,third:g}}var $t=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Rt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return x("svg",{class:`${t}-swatch`,"data-kind":n,...$t(24,16)},e==="fk"?x("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,x("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?x("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):x("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function bt(t,e){return e==="decision"?x("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},x("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?x("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):x("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function zt(t,e){return xt(e,`key:${t}`,()=>Ee(t,e))}var Se=zt;function Ee(t,e){const n=[],s=(o,a,i={})=>n.push(x("li",{class:`${t}-entry`,...i},o,x("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(x("li",{class:`${t}-entry`},x("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),x("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(bt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(bt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(bt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Rt(t,o),a,{"data-line":""})}return e.type==="schema"&&e.edges.length&&(s(Rt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(x("li",{class:`${t}-entry`,"data-when":"stacked"},x("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),x("span",null,"The table a foreign key references")))),e.nodes.some(o=>o.focal)&&e.legend.focal&&s(bt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(bt(t,"group"),e.legend.group),n.length?x("div",{class:`${t}-key`},x("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Ae(t,e){const n=e==="main"?6:6.5;return x("svg",{class:`${t}-arrow`,"data-kind":e,...$t(20,12)},x("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?x("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):x("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Le(t,e,n){if(n.shape==="decision")return[x("span",{class:`${t}-words`},x("span",{class:`${t}-name`},n.name))];const s=[];return e.type==="data-flow"?s.push(x("span",{class:`${t}-kind`},n.kind,x("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(x("span",{class:`${t}-kind`},n.kind)),s.push(x("span",{class:`${t}-name`},n.name)),n.detail&&s.push(x("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Mt(n.detail).flatMap((r,o)=>[o?" ":"",x("span",{class:`${t}-run`},r)]):n.detail)),s}function qe(t,e){return[x("span",{class:`${t}-th`},x("span",{class:`${t}-tname`},e.name)),x("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>x("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},x("span",{class:`${t}-keyseat`},n.key??""),x("span",{class:`${t}-cname`},n.name),n.ref?x("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?x("span",{class:`${t}-ctype`},n.type):null))),e.more?x("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ft=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Lt(t,e,n,s){const{P:r}=t,o=Me(e,s)||s.keep===n.id,a=gt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const f=t.plan;if(f&&n.i>0){const c=pt(f.gaps,n.id)??32,m=pt(s.grow,n.id)??0;i.push(`--_gap:${m?`calc(${Ft(c)} + var(--basalt-space-4) * ${m})`:Ft(c)}`)}const h=pt(s.heights,n.id);h&&i.push(`--_h:${h}px`);const u=pt(s.words,n.id);u&&i.push(`--_ww:${u}px`);const g=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return x("div",{class:`${r}-node`,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o?"img":void 0,"aria-label":o?$e(e,n):void 0,tabindex:g},n.shape==="decision"?x("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},x("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?x("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ot(n.mark.onLight)};--_md:${Ot(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?qe(r,n):Le(r,e,n))}function Ie(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((a,i)=>x("div",{class:`${s}-lane`,style:`--_r:${i+1}`,"aria-hidden":"true"},x("span",{class:`${s}-lane-name`},a.label)))),e.type==="architecture")for(const a of e.groups){const i=a.members.map(c=>e.byId.get(c));if(!i.length)continue;const f=Math.min(...i.map(c=>c.col)),h=Math.max(...i.map(c=>c.col)),u=Math.min(...i.map(c=>c.row)),g=Math.max(...i.map(c=>c.row2));r.push(x("div",{class:`${s}-gbox`,"data-group":a.id,style:`--_c:${f};--_c2:${h+1};--_r:${u};--_r2:${g+1}`,"aria-hidden":"true"},x("span",{class:`${s}-glabel`},a.label)))}if(e.type==="sequence")return r.push(x("ul",{class:`${s}-cast`},e.nodes.map(a=>x("li",{class:`${s}-actor`},Lt(t,e,a,n))))),r.push(Oe(t,e)),r;let o=0;for(;ou.id===a.group):void 0;if(!i){r.push(Lt(t,e,a,n)),o++;continue}const f=[];for(;oLt(t,e,u,n))))}return r}function Oe(t,e){const{P:n}=t,s=[];let r=null;for(const o of e.steps){if("band"in o){r=null,s.push(x("p",{class:`${n}-band`},x("span",null,o.band)));continue}r||(r=x("ol",{class:`${n}-msgs`,start:o.n}),s.push(r));const a=e.byId.get(o.from),i=e.byId.get(o.to),f=a?.col??1,h=i?.col??1,u=f===h,g=u&&f===e.nodes.length,c=Bt(e,o.kind);r.c.push(x("li",{class:`${n}-msg`,"data-kind":o.kind,"data-from":o.from,"data-to":o.to,"data-self":u?g?"start":"end":void 0,style:`--_a:${Math.min(f,h)};--_b:${Math.max(f,h)+1}`},x("span",{class:`${n}-said`},x("span",{class:`${n}-num`},String(o.n)),x("span",{class:`${n}-mlabel`},o.label)),x("span",{class:`${n}-route`},a?.short??o.from," ",Ae(n,o.kind),x("span",{class:t.hidden}," to ")," ",i?.short??o.to,c?` · ${c}`:""),o.note?x("span",{class:`${n}-note`},o.note):null))}return x("div",{class:`${n}-steps`},s)}function Ht(t,e){return xt(e,`list:${t}`,()=>Be(t,e))}var _e=Ht;function Be(t,e){const n=Math.min(6,e.heading+1),s=u=>x(`h${n}`,{class:`${t}-list-head`},u),r=u=>x("strong",null,u),o=u=>x("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,i=u=>{const g=Bt(e,u);return g?` (${g})`:""},f=u=>u.focal&&e.legend.focal?` ${mt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=m=>x("li",null,r(m.name),m.kind?`, ${m.kind}`:"",m.detail?[". ",m.mono?o(m.detail):m.detail,/[.!?]$/.test(m.detail)?"":"."]:/[.!?]$/.test(m.kind??m.name)?"":".",f(m)),g=[s("Parts")],c=e.nodes.filter(m=>!m.group);c.length&&g.push(x("ul",{class:`${t}-list-items`},c.map(u)));for(const m of e.groups)g.push(x("p",{class:`${t}-list-group`},m.label)),g.push(x("ul",{class:`${t}-list-items`},m.members.map(b=>u(e.byId.get(b)))));return g.push(s("Connections")),g.push(x("ol",{class:`${t}-list-items`},e.edges.map(m=>x("li",null,r(a(m.from))," to ",r(a(m.to)),m.label?[": ",o(m.label)]:"",`${i(m.kind)}.`)))),g}if(e.type==="flowchart"){const u=g=>(e.byId.get(g)?.i??0)+1;return[x("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const c=e.edges.filter(l=>l.from===g.id),m=g.shape==="decision"?"Decision":g.shape==="terminal"?c.length?"Start":"End":"Step",b=!g.detail&&/[.!?]$/.test(g.name)?" ":". ";return x("li",null,r(g.name),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",`${b}${m}.`,f(g),c.length?x("ul",{class:`${t}-list-exits`},c.map(l=>x("li",null,l.label?`If ${l.label}: go to ${u(l.to)}, `:`Then: go to ${u(l.to)}, `,r(a(l.to)),i(l.kind)))):null)}))]}if(e.type==="data-flow")return[x("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const g=e.edges.filter(c=>c.from===u.id);return x("li",null,`${u.laneLabel}: `,r(u.name),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",f(u),g.length?[" Then ",...g.flatMap((c,m)=>[m?"; ":"",`to step ${e.byId.get(c.to).step}, `,r(a(c.to)),c.label?[": ",o(c.label)]:"",i(c.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),x("ul",{class:`${t}-list-items`},e.nodes.map(c=>x("li",null,r(c.name),c.kind?`, ${c.kind}`:"",".",f(c))))];u.push(s("Messages"));let g=null;for(const c of e.steps){if("band"in c){g=null,u.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},c.band));continue}g||(g=x("ol",{class:`${t}-list-items`,start:c.n}),u.push(g)),g.c.push(x("li",null,o(c.label),": ",r(a(c.from))," to ",r(a(c.to)),`${i(c.kind)}.`,c.note?` ${mt(c.note)}`:""))}return u}const h=[];for(const u of e.nodes)h.push(x(`h${n}`,{class:`${t}-list-group`},o(u.name),f(u))),h.push(x("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(g=>x("li",null,o(g.name),g.key==="PK"?", primary key":g.key==="FK"?", foreign key":"",g.ref?[", references ",o(`${g.ref.table}.${g.ref.column}`)]:g.type?`, ${g.type}`:"")),...u.more?[x("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return h}function Wt(t){return`Arrow keys move to the next or the previous ${t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step"}, in the author's order; Home and End go to the ends; Escape clears the trace.`}function Nt(t,e=!1){return e?[{keys:["←","→"],words:Ct(t)},{keys:["Home","End"],words:"the ends"},{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]:[{keys:["←","→"],words:Ct(t)},{keys:["Home","End"],words:"the ends"},{keys:["Esc"],words:"clear"}]}var Ce="Plus and minus zoom, zero fits the drawing, Escape closes.",Dt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Gt(t,e,n){const s=n.prefix,r=ve(n.base),o=t.type==="sequence"||t.type==="schema"?null:Tt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",f=gt(t,e),h=t.type==="sequence"||t.type==="schema"?i:!0,u=`h${t.heading}`,g=[`--_cols:${At(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const c=t.type==="architecture"?t.groups.flatMap(l=>l.members.map(p=>t.byId.get(p))):[],m=(l,p,$)=>l?`var(--basalt-space-${p})`:$?`var(--basalt-space-${$})`:"0px",b=i&&e.pad?"3":void 0;g.push(`--_gpad:${m(c.some(l=>l.row===1),"8",b)} ${m(c.some(l=>l.col===t.cols),"4")} ${m(c.some(l=>l.row2===t.rows),"4",b)} ${m(c.some(l=>l.col===1),"4")}`)}return Dt(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),x("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":At(t),"data-reach":t.type==="architecture"?jt(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},x("div",{class:`${s}-head`},x(u,{id:r.title,class:`${s}-title`},t.title),n.hasSource?x("p",{class:`${s}-source`},{slot:"source"}):null),x("div",{class:`${s}-drawing`,role:h?"group":void 0,"aria-roledescription":h?"diagram":void 0,"aria-labelledby":h?r.title:void 0,"aria-describedby":h?f?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":f?"":void 0},Ie(a,t,e),x("div",{class:`${s}-ink`,"aria-hidden":"true"}),x("span",{class:`${s}-ruler`,"aria-hidden":"true"})),zt(s,t),x("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),x("div",{class:`${s}-foot`},{slot:"toggle"}),x("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Ht(s,t)),x("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Wt(t)} ${Ce}`:Wt(t)),x("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function je(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4)}}var vt=(t,e)=>t==="main"?e.line:e.hair,ct=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},dt=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Kt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function it(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,f=(r+a)/2,h=(o-s)/2,u=(a-r)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const b=n,l=u*Math.max(0,1-Math.abs(b-i)/h);return{x:b,y:e==="top"?f-l:f+l}}const c=n,m=h*Math.max(0,1-Math.abs(c-f)/u);return{x:e==="left"?i-m:i+m,y:c}}if(t.shape==="terminal"){const c=Math.min(h,u);if(g){const p=n,$=Math.min(Math.max(p,s+c),o-c),q=p-$,E=Math.abs(q)>=c?0:Math.sqrt(c*c-q*q);return{x:p,y:Math.abs(q)<1e-6?e==="top"?r:a:e==="top"?f-E:f+E}}const m=n,b=m-f,l=Math.abs(b)>=c?0:Math.sqrt(c*c-b*b);return{x:e==="left"?s+c-l:o-c+l,y:m}}return g?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Te(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,f=(r+a)/2,h=(o-s)/2,u=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/h+Math.abs(t.y-f)/u<1-n/Math.min(h,u);if(e.shape==="terminal"){const g=Math.min(h,u),c=Math.min(Math.max(t.x,s+g),o-g);return Math.hypot(t.x-c,t.y-f)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Fe(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var Mt=t=>t?t.split(/\s+/).filter(Boolean):[];function He(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const f of t.nodes){if(f.shape==="table"){for(const m of f.columns??[]){const b=m.ref?`→ ${m.ref.table}`:m.type??"",l=s("6")+n(m.name,"mono")+(b?s("3")+n(b,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(l))}o=Math.max(o,Math.ceil(n(f.name,"table")+2*s("3")+2*e.hair));continue}const h=f.shape==="terminal"?2*s("5"):2*s("3"),u=f.mark&&!ze()?s("6"):0;let g=0;for(const m of Mt(f.name))g=Math.max(g,n(m,f.shape==="decision"?"name-500":"name")+(f.kind?0:u));if(t.type!=="data-flow")for(const m of Mt(f.kind))g=Math.max(g,n(m,"mono")+u);for(const m of Mt(f.detail))g=Math.max(g,n(m,f.mono?"mono":"sans"));const c=f.shape==="decision"?g/.62:g+h+2*e.hair;r=Math.max(r,Math.ceil(c))}const a=At(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(Dt(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+jt(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function Zt(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function qt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Jt(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const f=r[r.length-2];if(Math.abs(f.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(f.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ft=t=>t.slice(1).map((e,n)=>[t[n],e]);function kt(t,e,n){const s=[];for(let o=0;oMath.min(l.x,p.x)+.75&&EMath.min($.y,q.y)+.75&&Br.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let f=o;for(const h of r)i.push([f,f+h]),f+=h+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var Y=t=>t==="left"||t==="right",Ut={top:"bottom",bottom:"top",left:"right",right:"left"};function Ne(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function De(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),f=t.byId.get(o.to),[h,u]=e[a],g=i.row===f.row&&Y(h)&&Y(u)&&h===Ut[u]||i.col===f.col&&!Y(h)&&!Y(u)&&h===Ut[u];s.push({edge:a,end:"from",node:i,side:h,far:f,straight:g,f:.5},{edge:a,end:"to",node:f,side:u,far:i,straight:g,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=l=>Y(l.side)?l.far.row-l.node.row:l.far.col-l.node.col,f=a.filter(l=>l.straight),h=a.filter(l=>!l.straight);if(h.sort((l,p)=>i(l)-i(p)||(Y(l.side)?l.far.col-p.far.col:l.far.row-p.far.row)*(i(l)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!f.length){h.length===2?(h[0].f=.25,h[1].f=.75):h.length===3?(h[0].f=.25,h[1].f=.5,h[2].f=.75):h.length>3&&h.forEach((l,p)=>{l.f=(p+1)/(h.length+1)});continue}const u=new Map;for(const l of f)u.has(l.far.id)||u.set(l.far.id,[]),u.get(l.far.id).push(l);for(const l of u.values())l.length>1&&l.sort((p,$)=>p.edge-$.edge).forEach((p,$)=>{p.f=l.length===2?$===0?.25:.75:($+1)/(l.length+1)});const g=Math.min(...f.map(l=>l.f)),c=Math.max(...f.map(l=>l.f)),m=h.filter(l=>i(l)<0),b=h.filter(l=>i(l)>=0);m.forEach((l,p)=>{l.f=g*(p+1)/(m.length+1)}),b.forEach((l,p)=>{l.f=c+(1-c)*(p+1)/(b.length+1)})}return s}function Xt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return Y(e)?it(t,e,r+(a-r)*n):it(t,e,s+(o-s)*n)}function Yt(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ct(o,n),shape:a.shape,i:a.i})}),r}function Qt(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var Pt=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function te(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function Ge(t,e,n,s,r,o,a,i,f){const h=a.space,u=[],g=[],c=[],m=[],b=h("1"),l=e.filter(p=>t.edges[p.i]?.label).sort((p,$)=>+(t.edges[$.i].kind==="main")-+(t.edges[p.i].kind==="main")||p.i-$.i);for(const p of l){const $=t.edges[p.i].label,q=i($,"label"),E=16,B=p.pts.length-2,j=[];ft(p.pts).forEach(([v,D],I)=>{const w=Math.abs(v.y-D.y)<.01,d=w?v.x:v.y;let y=w?D.x:D.y;const S=Math.sign(y-d)||1;I===B&&(y-=S*a.head);let L=[[d,y]];for(const G of r)for(const W of w?[G.l,G.r]:[G.t,G.b]){const k=w?v.y:v.x;(w?k>G.t&&kG.l&&kW>Math.min(O,M)+1&&W{const k=(G+W)/2,C=w?{x:k,y:v.y}:{x:v.x,y:k};return!r.some(O=>C.x>O.l&&C.xO.t&&C.y1&&H(G,W)?1:0})}),j.sort((v,D)=>D.pri-v.pri||D.len-v.len);let R=null,Q=!1;const A=(v,D=!0)=>{const I=Kt(v,b);return D&&(v.lo.r||v.to.b)||n.some(w=>Vt(I,w))||u.some(w=>dt(I,w))||s.heads.some(w=>dt(I,w))||s.rects.some(w=>dt(I,w))?!1:!e.some(w=>w.i!==p.i&&ft(w.pts).some(([d,y])=>dt(I,Pt(d,y,w.width))))};for(const v of j){for(const D of[1/2,1/3,2/3]){const I=v.p+(v.q-v.p)*D,w=[],d=h("2")+p.width/2;if(v.horiz?(v.len>=q+2*h("1")+h("3-5")&&w.push({box:{l:I-q/2-h("1"),r:I+q/2+h("1"),t:v.c-E/2,b:v.c+E/2},on:!0}),w.push({box:{l:I-q/2,r:I+q/2,t:v.c-d-E,b:v.c-d},on:!1}),w.push({box:{l:I-q/2,r:I+q/2,t:v.c+d,b:v.c+d+E},on:!1})):(v.len>=E+h("3")&&w.push({box:{l:v.c-q/2-h("1"),r:v.c+q/2+h("1"),t:I-E/2,b:I+E/2},on:!0}),w.push({box:{l:v.c+d,r:v.c+d+q,t:I-E/2,b:I+E/2},on:!1}),w.push({box:{l:v.c-d-q,r:v.c-d,t:I-E/2,b:I+E/2},on:!1})),R=w.find(y=>A(y.box))??null,R)break;!Q&&w.some(y=>A(y.box,!1))&&(Q=!0)}if(R)break}if(!R){c.push(p.i),Q&&m.push(p.i);continue}const V=te(R.box,f.ox,f.oy,v=>A(v));u.push(V),g.push({i:p.i,text:$,box:V,on:R.on})}return{labels:g,unseated:c,bounded:m}}function ee(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=ct(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const f=a.querySelector(`:scope > .${n}-glabel`);f&&f.getClientRects().length&&r.push(ct(f,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const f=ct(a,e);i>0&&r.push({l:f.l,r:f.r,t:f.t-s/2-.5,b:f.t-s/2+.5});const h=a.querySelector(`.${n}-lane-name`);h&&r.push(ct(h,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function Ke(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:f}=t,h=r.space,u=Yt(s,a,i,o),g=[...u.values()],c=We(a),m=i.left-Math.floor(i.left),b=i.top-Math.floor(i.top),l=Zt(m,b),p=a.clientWidth,$=a.clientHeight,q=k=>s.type==="data-flow"?k.col+1:k.col,E=parseFloat(getComputedStyle(a).rowGap)||0,B={w:p,h:$,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:m,oy:b};if(s.type==="sequence")return Ze(t,B,l);let j,R=[];s.type==="schema"?j=s.edges.map(k=>{const C=s.byId.get(k.from),O=s.byId.get(k.to);if(C.col===O.col){const M=C.col===s.cols&&s.cols>1?"left":"right";return[M,M]}return O.col>C.col?["right","left"]:["left","right"]}):(j=s.edges.map(k=>{const C=s.byId.get(k.from),O=s.byId.get(k.to),[M,_]=Ne(C,O);return[k.fromSide??M,k.toSide??_]}),R=De(s,j,f||(()=>{})));const Q=(k,C)=>{const O=a.querySelector(`.${o}-node[data-node="${CSS.escape(k)}"] .${o}-row[data-row="${C}"]`);if(!O)return 0;const M=ct(O,i);return(M.t+M.b)/2},A=s.edges.map((k,C)=>{const[O,M]=j[C],_=u.get(k.from),z=u.get(k.to),Z=vt(k.kind,r);if(k.fk){const J=Q(k.from,k.fromRow),et=Q(k.to,k.toRow),U=l.y(J,Z),nt=l.y(et,Z);return{p1:{x:O==="right"?_.rect.r:_.rect.l,y:U},p2:{x:M==="right"?z.rect.r:z.rect.l,y:nt},r1:J,r2:Math.abs(U-nt)<.01?J:et}}const P=R.find(J=>J.edge===C&&J.end==="from").f,X=R.find(J=>J.edge===C&&J.end==="to").f;let N=Xt(_,O,P),K=Xt(z,M,X);const ot=Y(O)?N.y:N.x;let tt=Y(M)?K.y:K.x;return Y(O)?N={...N,y:l.y(N.y,Z)}:N={...N,x:l.x(N.x,Z)},Y(M)?K={...K,y:l.y(K.y,Z)}:K={...K,x:l.x(K.x,Z)},Y(O)&&Y(M)&&Math.abs(N.y-K.y)<1.01&&(K={...K,y:N.y},tt=ot),!Y(O)&&!Y(M)&&Math.abs(N.x-K.x)<1.01&&(K={...K,x:N.x},tt=ot),N=Y(O)?it(_,O,N.y):it(_,O,N.x),K=Y(M)?it(z,M,K.y):it(z,M,K.x),{p1:N,p2:K,r1:ot,r2:tt}}),V=new Set;s.type==="schema"&&s.edges.forEach((k,C)=>{Math.abs(s.byId.get(k.from).col-s.byId.get(k.to).col)>1&&V.add(C)});const v=new Map,D=new Set;s.edges.forEach((k,C)=>{if(V.has(C))return;const[O,M]=j[C],{p1:_,p2:z}=A[C],Z=s.byId.get(k.from),P=s.byId.get(k.to);let X=null,N=null,K=!1;if(O===M){if(Y(O)){const J=O==="right"?Math.max(q(Z),q(P)):Math.min(q(Z),q(P))-1,et=c.cols[J-1],U=c.cols[J];et&&U&&(X=`c${J}`,N=[et[1],U[0]],K=!0)}else{const J=O==="bottom"?Math.max(Z.row2,P.row2):Math.min(Z.row,P.row)-1,et=c.rows[J-1],U=c.rows[J];et&&U&&(X=`r${J}`,N=[et[1],U[0]],K=!1)}X&&D.add(C)}else if(Y(O)&&Y(M)&&Math.abs(_.y-z.y)>.5){const J=q(P),et=M==="left",U=c.cols[(et?J-1:J)-1],nt=c.cols[(et?J:J+1)-1];U&&nt&&(X=`c${et?J-1:J}`,N=[U[1],nt[0]],K=!0)}else if(!Y(O)&&!Y(M)&&Math.abs(_.x-z.x)>.5){const et=M==="top"?P.row-1:P.row2,U=c.rows[et-1],nt=c.rows[et];U&&nt&&(X=`r${et}`,N=[U[1],nt[0]],K=!1)}if(!X||!N)return;v.has(X)||v.set(X,{span:N,vertical:K,members:new Map});const ot=`${k.to}.${M}.${Math.round(K?z.y:z.x)}`,tt=v.get(X);tt.members.has(ot)||tt.members.set(ot,[]),tt.members.get(ot).push(C)});const I=new Map,w=k=>{const[C,O]=j[k],{p1:M,p2:_}=A[k];if(Y(C)&&Y(O)){if(C===O){const Z=I.get(k)??(C==="right"?Math.max(M.x,_.x)+h("4"):Math.min(M.x,_.x)-h("4"));return[M,{x:Z,y:M.y},{x:Z,y:_.y},_]}if(Math.abs(M.y-_.y)<=.5)return[M,{x:_.x,y:M.y}];const z=I.get(k)??(M.x+_.x)/2;return[M,{x:z,y:M.y},{x:z,y:_.y},_]}if(!Y(C)&&!Y(O)){if(C===O){const Z=I.get(k)??(C==="bottom"?Math.max(M.y,_.y)+h("4"):Math.min(M.y,_.y)-h("4"));return[M,{x:M.x,y:Z},{x:_.x,y:Z},_]}if(Math.abs(M.x-_.x)<=.5)return[M,{x:M.x,y:_.y}];const z=I.get(k)??(M.y+_.y)/2;return[M,{x:M.x,y:z},{x:_.x,y:z},_]}return Y(C)?[M,{x:_.x,y:M.y},_]:[M,{x:M.x,y:_.y},_]},d=k=>{const C=s.edges[k],O=vt(C.kind,r),M=w(k),_=Jt(M,O,l);let z;return M.length===_.length&&(z=ft(M).map(([Z,P])=>Math.abs(Z.y-P.y)<.75?(Z.y+P.y)/2:(Z.x+P.x)/2),z[0]=A[k].r1,z.length>1&&(z[z.length-1]=A[k].r2)),{i:k,from:C.from,to:C.to,kind:C.kind,pts:_,tip:_[_.length-1],dir:qt(_),dot:C.fk?_[0]:void 0,width:O,axes:z}},y=()=>s.edges.flatMap((k,C)=>V.has(C)?[]:[d(C)]);let S=null;const L=k=>{S??(S=y());const C=S.map(O=>k.has(O.i)?d(O.i):O);return{lines:C,score:Ve(C,k)*1e5+kt(C,void 0,k).length*1e3+It(C.filter(O=>k.has(O.i)),g,s).length}},H=(k,C)=>{const O=k.flatMap(M=>{const{p1:_,p2:z}=A[M];return C?[_.y,z.y]:[_.x,z.x]});return[Math.min(...O),Math.max(...O)]};for(const[,k]of v){const C=[...k.members.values()].map(M=>({members:M,run:H(M,k.vertical)})).sort((M,_)=>M.run[0]-_.run[0]),O=[];for(const M of C){const _=O[O.length-1];_&&_.some(z=>z.run[0]D.has(ot)))continue;const _=M.map(ot=>ot.members),z=_.length,Z=(k.span[1]-k.span[0])/(z+1);ZJ.forEach(U=>I.set(U,k.span[0]+Z*(et+1))));const tt=L(P);tt.scoreot.forEach(J=>I.set(J,k.span[0]+Z*(tt+1)))),S=K}}B.lines=y();for(const k of V)f?.(`${s.edges[k].from} to ${s.edges[k].to} is two columns apart, so its line is not drawn; its row still writes the target`);B.crossings=kt(B.lines),B.through=It(B.lines,g,s),B.outside=se(B.lines,p,$,r);const{obstacles:T,groups:G}=ee(a,i,o,E);T.heads=B.lines.map(k=>Qt(k,r));const W=Ge(s,B.lines,g,T,G,{l:0,t:0,r:p,b:$},r,e,{ox:m,oy:b});return B.labels=W.labels,B.unseated=W.unseated,B.bounded=W.bounded,B.overlaps=[...new Set(ne(B.lines,null).flat())],B}function Ve(t,e){return ne(t,e).length}function ne(t,e){const n=[];for(let s=0;s=i)continue;const[p,$]=c?[f.x,h.x]:[f.y,h.y],[q,E]=c?[u.x,g.x]:[u.y,g.y];Math.min(Math.max(p,$),Math.max(q,E))-Math.max(Math.min(p,$),Math.min(q,E))>1&&n.push([o.i,a.i])}}return n}function*oe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const f=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-f<-.5||a.x+f>e+.5||a.y-f<-.5||a.y+f>n+.5})&&r.push(o.i);return r}function It(t,e,n){const s=[];for(const r of t){const o=ft(r.pts);e.some(a=>o.some(([i,f])=>Re(i,f,a)))&&s.push(r.i)}return s}function Ze(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,f=r.space,h=new Map;a.querySelectorAll(`.${o}-node`).forEach(b=>h.set(b.dataset.node,ct(b,i)));const u=a.querySelector(`.${o}-steps`),g=u?ct(u,i).b:e.h,c=b=>{const l=h.get(b);return l?n.x((l.l+l.r)/2,r.hair):0};for(const b of s.nodes){const l=h.get(b.id);l&&e.lifelines.push({x:c(b.id),y1:l.b,y2:g})}const m=b=>h.get(b.id);return a.querySelectorAll(`.${o}-msg`).forEach(b=>{const l=b.dataset.from,p=b.dataset.to,$=b.dataset.kind??"plain",q=vt($,r),E=ct(b,i),B=n.y((E.t+E.b)/2,q),j=Number(b.querySelector(`.${o}-num`)?.textContent??0),R=c(l),Q=c(p);let A;if(l===p){const y=b.dataset.self==="start"?-f("6"):f("6"),S=n.y(B-f("2"),q),L=n.y(B+f("2"),q);A=[{x:R,y:S},{x:n.x(R+y,q),y:S},{x:n.x(R+y,q),y:L},{x:R,y:L}]}else A=[{x:R,y:B},{x:Q,y:B}];e.lines.push({i:j,from:l,to:p,kind:$,pts:A,tip:A[A.length-1],dir:qt(A),width:q});const V=b.querySelector(`.${o}-said`),v=b.querySelector(`.${o}-note`),D=s.byId.get(l),I=s.byId.get(p);if(!D||!I)return;const w=l===p?(()=>{const y=s.nodes[D.i+(b.dataset.self==="start"?-1:1)],S=y?c(y.id):b.dataset.self==="start"?0:e.w;return Math.abs(S-R)-f("6")-f("2-5")-f("2")})():Math.abs(Q-R)-2*f("2");Math.max(V?V.getBoundingClientRect().width:0,v?v.getBoundingClientRect().width:0)>w+.5&&e.unseated.push(j)}),e}function ae(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:i,origin:f}=t,h=o.space,u=Yt(r,i,f,a),g=[...u.values()],c=f.left-Math.floor(f.left),m=f.top-Math.floor(f.top),b=Zt(c,m),l=i.clientWidth,p=i.clientHeight,$={w:l,h:p,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:m},q=ht();if(r.type==="sequence"||r.type==="schema")return{geo:$,grow:q};const E=l-(parseFloat(getComputedStyle(i).paddingRight)||0),B=(w,d,y)=>{const S=[w];for(let L=1;L<=(pt(s,d)??0);L++)S.push({...w,t:w.t+y*h("4")*L,b:w.b+y*h("4")*L});return S},j=new Map;i.querySelectorAll(`.${a}-node`).forEach(w=>{const d=w.parentElement,y=ct(d,f),S=getComputedStyle(d);j.set(w.dataset.node,y.r-(parseFloat(S.paddingRight)||0)-(parseFloat(S.borderRightWidth)||0))});const R=r.nodes,Q=w=>u.get(R[w].id),A=[],V=w=>vt(r.edges[w].kind,o);r.edges.forEach((w,d)=>{const y=n.routes[d],S=u.get(w.from),L=u.get(w.to),H=V(d);let T=[];const G=w.label,W=G?e(G,"label"):0,k=16,C=h("4");if(y==="down"||y==="up"){const M=Math.max(S.rect.l,L.rect.l),_=Math.min(S.rect.r,L.rect.r),z=r.edges.map((N,K)=>({o:N,j:K})).filter(({o:N,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(N.from===w.from&&N.to===w.to||N.from===w.to&&N.to===w.from)),Z=z.findIndex(N=>N.j===d),P=z.length<2?.5:z.length===2?Z===0?.25:.75:(Z+1)/(z.length+1),X=b.x(M+(_-M)*P,H);if(T=y==="down"?[it(S,"bottom",X),it(L,"top",X)]:[it(S,"top",X),it(L,"bottom",X)],G){let N=Math.min(T[0].y,T[1].y),K=Math.max(T[0].y,T[1].y);y==="down"?K-=o.head:N+=o.head;const ot=[...i.querySelectorAll(`.${a}-group`)].map(U=>ct(U,f));let tt=[[N,K]];for(const U of ot)for(const nt of[U.t,U.b])tt=tt.flatMap(([at,F])=>nt>at+1&&ntot.some(at=>(U+nt)/2>at.t&&(U+nt)/2at.l&&X1){const U=tt.filter(([at,F])=>!J(at,F));[N,K]=(U.length?U:tt).reduce((at,F)=>F[1]-F[0]>at[1]-at[0]?F:at)}const et=[1/2,1/3,2/3].map(U=>{const nt=N+(K-N)*U;return{l:X-W/2-h("1"),r:X+W/2+h("1"),t:nt-k/2,b:nt+k/2}});A.push({k:d,cands:et,on:!0,card:y==="down"?w.to:w.from})}}else if(y==="trunk"||y==="rail"){const M=b.x(Math.max(S.rect.l,y==="rail"?L.rect.l:S.rect.l)+h(y==="trunk"?"8":"3"),H),_=it(S,"bottom",M);if(y==="rail"){if(T=[_,it(L,"top",M)],G){const z=L.rect.t-h("6");A.push({k:d,cands:B({l:M+h("2-5"),r:M+h("2-5")+W,t:z-k/2,b:z+k/2},w.to,-1),on:!1,card:w.to})}}else{const z=b.x(L.rect.l+h("6"),H),Z=b.y(L.rect.t-C,H);T=[_,{x:M,y:Z},{x:z,y:Z},it(L,"top",z)],G&&A.push({k:d,cands:B({l:z+h("2-5"),r:z+h("2-5")+W,t:Z-k/2,b:Z+k/2},w.to,-1),on:!1,card:w.to})}}else{const M=Math.min(j.get(w.from)??l,j.get(w.to)??l),_=b.x(n.gutter?E+(n.lanes[d]?2*h("3-5"):h("3-5")):M-h("2-5"),H),z=b.y(S.rect.t+(S.rect.b-S.rect.t)*n.exits[d],H),Z=it(S,"right",z),P=b.x(L.rect.r-h("6"),H),X=y==="end-down",N=b.y(X?L.rect.t-C:L.rect.b+C,H);T=[Z,{x:_,y:Z.y},{x:_,y:N},{x:P,y:N},it(L,X?"top":"bottom",P)];const K=X?w.to:R[L.i+1]?.id??w.to;G&&A.push({k:d,cands:B({l:P-h("2-5")-W,r:P-h("2-5"),t:N-k/2,b:N+k/2},K,X?-1:1),on:!1,card:K})}const O=Jt(T,H,b);$.lines.push({i:d,from:w.from,to:w.to,kind:w.kind,pts:O,tip:O[O.length-1],dir:qt(O),width:H})}),$.crossings=kt($.lines),$.through=It($.lines,g,r),$.outside=se($.lines,l,p,o);const{obstacles:v}=ee(i,f,a,0);v.heads=$.lines.map(w=>Qt(w,o));const D=[],I={l:0,t:0,r:l,b:p};for(const w of A){const d=L=>{const H=Kt(L,h("1"));return L.lI.r+.5||L.tI.b+.5||g.some(T=>Vt(H,T))||D.some(T=>dt(H,T))||v.heads.some(T=>dt(H,T))||v.rects.some(T=>dt(H,T))||$.lines.some(T=>T.i!==w.k&&ft(T.pts).some(([G,W])=>dt(H,Pt(G,W,T.width))))},y=w.cands.find(L=>!d(L));y||(q[w.card]=(q[w.card]??0)+1,$.unseated.push(w.k));const S=y?te(y,c,m,L=>!d(L)):w.cands[0];D.push(S),$.labels.push({i:w.k,text:r.edges[w.k].label,box:S,on:w.on})}return{geo:$,grow:q}}function Je(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...B})),g=u[u.length-1];g.x-=o.x*h,g.y-=o.y*h;const c=e.tip.x-o.x*i,m=e.tip.y-o.y*i,b=-o.y*f,l=o.x*f,p=B=>Math.round(B*100)/100,$=lt(e.kind),q=a?``:``,E=e.dot?``:"";return`${q}${E}`}function re(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,f]of o){const h=`${s}-cut-${i}`;r.set(i,h);const u=f.map(g=>{const c=e.lines[g.top],m=e.lines[g.under],b=c.width/2+n.cut,l=m.width/2+1;return g.underVertical?``:``}).join("");a+=`${u}`}return{defs:a,ids:r}}function ie(t,e,n,s){const{defs:r,ids:o}=re(t,e,n,s),a=e.lifelines.map(u=>``).join(""),i=e.lines.map((u,g)=>Xe(t,u,n,o.get(g)??null,u.from===u.to?n.radiusXs:n.radius)).join(""),f=`${r?`${r}`:""}${a}${i}`,h=e.labels.map(u=>`${lt(u.text)}`).join("");return f+h}function yt(t,e,n,s,r,o,a,i){const h=t.querySelector(`.${n}-drawing`);if(!h||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const u=je(t),g=Fe(h,n),c=He(e,u,g);i?.(c.least);const m=t.clientWidth,b=(()=>{const v=document.activeElement;return v&&h.contains(v)&&v.dataset.node?v.dataset.node:void 0})(),l=v=>gt(e,v)?{...v,stop:v.stop&&e.byId.has(v.stop)?v.stop:e.nodes[0]?.id,keep:void 0}:{...v,stop:v.stop??e.nodes[0]?.id,keep:b&&v.layout!=="drawn"?b:void 0};let p=!1;const $=v=>{if(p=!1,e.type!=="flowchart")return v;o({...v,heights:void 0,words:void 0});const D=ht(),I=ht();return h.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(w=>{const d=w.querySelector(`.${n}-words`);if(!d)return;const y=w.getBoundingClientRect(),S=T=>{const G={w:T.width+2*u.space("2-5"),h:T.height+2*u.space("2")},W=1-G.w/y.width,k=W>.05?G.h/2/W:G.h*10;return Math.max(u.space("16"),Math.ceil(y.width/5),Math.ceil(2*k))},L=d.getBoundingClientRect();let H=S(L);if(H>y.width){const T=C=>(w.style.setProperty("--_ww",`${C}px`),d.getBoundingClientRect()),G=Math.floor(w.clientWidth-2*u.space("2-5"));let W=Math.ceil(L.width),k=L.height;for(;W1;){const z=C+O>>1;T(z).heighty.width&&(p=!0)}),{...v,heights:D,words:Object.keys(I).length?I:void 0}},q=()=>({m:e,tk:u,P:n,drawing:h,origin:h.getBoundingClientRect(),warn:a}),E=r.autoOpen?{open:!1,autoOpen:void 0}:{},B=(v,D)=>D.map(I=>wt(e,v.lines.find(w=>w.i===I))).join(", ");if(m>=c.least){const v=d=>{let y=l({...r,...E,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:d||void 0});return y=$(y),o(y),{dd:y,g:Ke(q(),g)}};let{dd:D,g:I}=v(!1);const w=d=>d.through.length>0||d.outside.length>0||(d.overlaps?.length??0)>0||p;if(!w(I)&&I.unseated.length&&I.unseated.every(d=>I.bounded?.includes(d))){const d=v(!0);!w(d.g)&&!d.g.unseated.length&&({dd:D,g:I}=d)}if(!w(I)&&!I.unseated.length)return I.crossings.length&&a?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(d=>`${wt(e,I.lines[d.top])} over ${wt(e,I.lines[d.under])}`).join("; ")}`),{dyn:D,geo:I,ink:ie(n,I,u,s),tokens:u,least:c.least};p&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: a decision would be taller than it is wide`),I.through.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${B(I,I.through)} would pass through a node`),I.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${B(I,I.overlaps)} would lie on one another`),I.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${B(I,I.outside)} would leave the drawing`),I.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: no clean seat for ${I.unseated.map(d=>e.type==="sequence"?`message ${d}`:`"${e.edges[d]?.label}"`).join(", ")}`)}let j=l({...r,...E,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(j=$(j),o(j),e.type==="sequence"||e.type==="schema")return{dyn:j,geo:null,ink:"",tokens:u,least:c.least};const R=Tt(e);let Q=ae(q(),g,R,j.grow);for(let v=0;v<6&&Object.keys(Q.grow).length;v++){const D=ht(j.grow);for(const[I,w]of Object.entries(Q.grow))D[I]=(pt(D,I)??0)+w;j={...j,grow:D},o(j),Q=ae(q(),g,R,D)}const A=Q.geo;if(A.unseated.length>0||A.through.length>0||A.outside.length>0||R.third){A.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(A.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),A.through.length&&a?.(`in the stacked drawing ${B(A,A.through)} would pass through a node, so its lines are not drawn`),A.outside.length&&a?.(`in the stacked drawing ${B(A,A.outside)} would leave the drawing, so its lines are not drawn`),R.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const v={...A,lines:[],labels:[],crossings:[]};return{dyn:l({...j,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:v,ink:"",tokens:u,least:c.least}}return A.crossings.length&&a?.(`${A.crossings.length} crossing${A.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${A.crossings.map(v=>`${wt(e,A.lines[v.top])} over ${wt(e,A.lines[v.under])}`).join("; ")}`),{dyn:j,geo:A,ink:ie(n,A,u,s),tokens:u,least:c.least}}function Ye(t,e,n,s,r,o,a,i){const{layer:f,memo:h}=i;h.model!==e&&(h.model=e,h.least=void 0);const u=b=>{f.style.width=`${Math.max(h.least||b,Math.min(i.avail,i.row))}px`};f.style.width||(f.style.width=`${Math.min(i.avail,i.row)}px`);const g=f.style.transform;f.style.transform="none";const c=f.offsetWidth?f.getBoundingClientRect().width/f.offsetWidth:1;Math.abs(c-1)>1e-4&&(f.style.transform=`scale(${1/c})`);let m=yt(t,e,n,s,r,o,h.least===void 0?void 0:a,u);if(m.dyn.layout==="stacked"&&h.least===void 0&&m.least!==void 0){const b=m.dyn,l=E=>{f.style.width=`${E}px`;const B=yt(t,e,n,s,b,o);return B.dyn.layout==="drawn"?yt(t,e,n,s,B.dyn,o):B},p=Math.max(m.least,Math.min(i.avail,i.row)),$=Math.max(i.row,p)*1.5;let q;for(let E=p+16;E<=$&&q===void 0;E+=16)l(E).dyn.layout==="drawn"&&(q=E);if(q!==void 0){for(let E=q-15;Ei.contain&&(f.style.width=`${i.contain}px`,m=yt(t,e,n,s,m.dyn,o,a)),f.style.transform=g,m}function wt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Qe(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const l of n?.lines??[])l.from===o&&a.add(l.to),l.to===o&&a.add(l.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(l=>l.toggleAttribute("data-near",a.has(l.dataset.node))),!n||!s)return;const i=l=>!!o&&(l.from===o||l.to===o),f=t.querySelector(`.${e}-edges`),h=new Map;t.querySelectorAll(`.${e}-edge`).forEach(l=>h.set(l.getAttribute("data-edge"),l));for(const l of n.lines){const p=h.get(String(l.i));p&&(p.toggleAttribute("data-lit",i(l)),p.toggleAttribute("data-dim",!!o&&!i(l)))}if(t.querySelectorAll(`.${e}-label`).forEach(l=>{const p=n.lines.find($=>String($.i)===l.dataset.edge);l.toggleAttribute("data-lit",!!(p&&i(p)))}),f){for(const l of n.lines)if(i(l)){const p=h.get(String(l.i));p&&f.appendChild(p)}}const u=kt(n.lines,i),{defs:g,ids:c}=re(e,{...n,crossings:u},s,r),m=t.querySelector(`.${e}-svg`);if(!m)return;let b=m.querySelector("defs");!b&&g&&(b=document.createElementNS("http://www.w3.org/2000/svg","defs"),m.insertBefore(b,m.firstChild)),b&&(b.innerHTML=g),n.lines.forEach((l,p)=>{const $=h.get(String(l.i))?.querySelector(`.${e}-line`);if(!$)return;const q=c.get(p);q?$.setAttribute("mask",`url(#${q})`):$.removeAttribute("mask")})}var Pe=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function tn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Pe()?"done":"pending")}}function le(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function en(t,e,n){const s=t.byId.get(e)?.i??0,r=t.nodes.length;let o;if(n==="ArrowRight"||n==="ArrowDown")o=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")o=s-1;else if(n==="Home")o=0;else if(n==="End")o=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,o))].id}var nn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],ce=["data-layout","data-measured","data-bare","data-motion"],on=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],de=t=>t==null||t===!1;function sn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function ue(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?ce:nn;for(const a of s)de(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const h=t.style,u=new Map(String(i??"").split(";").map(g=>{const c=g.indexOf(":");return[g.slice(0,c).trim(),g.slice(c+1).trim()]}).filter(([g])=>g));for(const[g,c]of u)h.getPropertyValue(g).trim()!==c&&h.setProperty(g,c);for(const g of on)u.has(g)||h.removeProperty(g);continue}if(n&&!ce.includes(a))continue;if(de(i)){t.removeAttribute(a);continue}const f=i===!0?"":String(i);t.getAttribute(a)!==f&&t.setAttribute(a,f)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(c,m,b){return{prefix:n,base:c,hasSource:m.source!==void 0&&m.source!==null&&m.source!=="",hiddenClass:"visually-hidden",viewer:!!b}}function o(c,m,b,l){var p=function($){return''+lt($)+""};return{source:lt(String(m.source||"")),summary:lt(String(m.summary||"")),hint:Nt(c).map(function($){return""+$.keys.map(p).join(" ")+" "+lt($.words)+""}).join(""),toggle:'"}}function a(c,m,b){var l=St(c),p=Gt(l,{},r(m,c,b)),$=Et(p,o(l,c,m,!1)),q=$.indexOf(">");return{open:$.slice(0,q+1),inner:$.slice(q+1,$.length-9),warnings:l.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],f=["--_cols","--_gpad","--_track"];function h(c,m,b,l){c.__diagram&&c.__diagram.stop();var p=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),$=St(m);if(!b||!p||!c.querySelector(":scope > .diagram-drawing")){if(!p||!c.querySelector("#"+CSS.escape(p+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););p="dg"+s}var q=a(m,p,l),E=document.createElement("div");E.innerHTML=q.open+"";var B=E.firstChild;i.forEach(function(F){c.removeAttribute(F)}),f.forEach(function(F){c.style.removeProperty(F)});for(var j=0;j :not(script[data-diagram])").forEach(function(F){F.remove()}),c.insertAdjacentHTML("beforeend",q.inner)}$.warnings.forEach(function(F){console.warn("Basalt diagram: "+F)});var Q=r(p,m,l),A={},V=null,v=null,D=null,I=Object.create(null),w=function(F){I[F]||(I[F]=1,console.warn("Basalt diagram: "+F))},d=function(F){ue(c,Gt($,F,Q))},y=c.querySelector(".diagram-ink"),S=c.querySelector(".diagram-toggle"),L=!l&&$.motion.animated&&typeof e.diagramMotion=="function",H=null,T=null,G=function(){L&&le(c)};function W(){Qe(c,n,V&&V.geo,V&&V.tokens,p,v||D)}function k(){S&&(S.setAttribute("aria-expanded",String(!!A.open)),S.firstElementChild.textContent=A.open?"Hide the list":"View as list")}function C(){V=l?Ye(c,$,n,p,A,d,w,l):yt(c,$,n,p,A,d,w),A=V.dyn,d(A),k(),gt($,A)||(D=null);var F=y&&V.ink!==T;F&&(y.innerHTML=V.ink,T=V.ink),W(),L&&V.tokens&&(tn(c,!!(V.geo&&V.geo.lines.length)),F&&H&&H.redrawn()),l&&l.onMeasured&&l.onMeasured(V,c)}function O(F){A=F,d(A)}function M(F){var st=A.stop;A=Object.assign({},A,{stop:F}),an(c,n,st,F)}var _=function(F){var st=F&&F.closest?F.closest(".diagram-node"):null;return st&&c.contains(st)?st:null};function z(F){var st=_(F.target);if(!(!st||F.defaultPrevented)){if(G(),F.key==="Escape"){!l&&(v||D)&&(F.preventDefault(),v=D=null,W());return}if(gt($,A)){var ut=en($,st.getAttribute("data-node"),F.key);if(ut){F.preventDefault(),M(ut);var fe=c.querySelector('.diagram-node[data-node="'+CSS.escape(ut)+'"]');fe&&fe.focus()}}}}function Z(F){var st=_(F.target);if(st){G();var ut=st.getAttribute("data-node");v=st.matches(":focus-visible")?ut:null,gt($,A)&&A.stop!==ut&&M(ut),W()}}function P(F){var st=_(F.target);st&&(_(F.relatedTarget)||(v=null),A.keep===st.getAttribute("data-node")&&O(Object.assign({},A,{keep:void 0})),W())}function X(F){if(!(F.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var st=_(F.target);st&&G();var ut=st&>($,A)?st.getAttribute("data-node"):null;ut!==D&&(D=ut,W())}}function N(){D&&(D=null,W())}function K(){G(),O(Object.assign({},A,{open:!A.open,autoOpen:void 0})),k()}c.addEventListener("keydown",z),c.addEventListener("focusin",Z),c.addEventListener("focusout",P),c.addEventListener("pointerover",X),c.addEventListener("pointerleave",N),S&&S.addEventListener("click",K),C();var ot=c.clientWidth,tt=0,J=!0,et=new ResizeObserver(function(){Math.abs(c.clientWidth-ot)<.5||(ot=c.clientWidth,cancelAnimationFrame(tt),tt=requestAnimationFrame(C))});et.observe(c),document.fonts&&document.fonts.ready.then(function(){J&&C()});var U=matchMedia("(forced-colors: active)"),nt=$.nodes.some(function(F){return F.mark});nt&&U.addEventListener("change",C),L&&(H=e.diagramMotion(c,{fig:c,P:n,base:p,model:function(){return $},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},m));var at=!l&&m.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,m,{model:$,settle:G,animated:L}):null;c.__diagram={stop:function(){at&&at.destroy(),J=!1,et.disconnect(),cancelAnimationFrame(tt),nt&&U.removeEventListener("change",C),H&&H.destroy(),c.removeEventListener("keydown",z),c.removeEventListener("focusin",Z),c.removeEventListener("focusout",P),c.removeEventListener("pointerover",X),c.removeEventListener("pointerleave",N),S&&S.removeEventListener("click",K)},layout:C,key:u(m),send:H&&H.sendValue?H.sendValue:null}}function u(c){try{return JSON.stringify(c,function(m,b){return m==="packet"&&b&&typeof b=="object"?Object.assign({},b,{send:void 0}):b})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var m=c.querySelector(":scope > script[data-diagram]");if(m)try{h(c,JSON.parse(m.textContent),!0)}catch(b){console.error("Basalt diagram: this figure could not be drawn",b)}}})}e.diagramMarkup=a,e.diagramKit={draw:h,buildModel:St,figureKey:Se,figureList:_e,hintEntries:Nt,toHtml:Et,escapeHtml:lt,settleEntrance:le},t.diagram=function(c,m){var b=c.__diagram,l=b&&b.send?u(m):null;if(l!==null&&l===b.key){b.send(m.packet?m.packet.send:void 0);return}h(c,m)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/icons.json b/.agent/skills/basalt-html/parts/icons.json index 748d4ebe..b92891a2 100644 --- a/.agent/skills/basalt-html/parts/icons.json +++ b/.agent/skills/basalt-html/parts/icons.json @@ -1 +1 @@ -{"notice":"/*! The icon paths below are from Phosphor Icons (@phosphor-icons/react):\nMIT License\n\nCopyright (c) 2020 Phosphor Icons\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/","icons":{"Command":["M180,140H164V116h16a40,40,0,1,0-40-40V92H116V76a40,40,0,1,0-40,40H92v24H76a40,40,0,1,0,40,40V164h24v16a40,40,0,1,0,40-40ZM164,76a16,16,0,1,1,16,16H164ZM60,76a16,16,0,0,1,32,0V92H76A16,16,0,0,1,60,76ZM92,180a16,16,0,1,1-16-16H92Zm24-64h24v24H116Zm64,80a16,16,0,0,1-16-16V164h16a16,16,0,0,1,0,32Z"],"Option":["M236,192a12,12,0,0,1-12,12H160.94a19.89,19.89,0,0,1-17.88-11.06L92.58,92H32a12,12,0,0,1,0-24H95.06a19.89,19.89,0,0,1,17.88,11.06L163.42,180H224A12,12,0,0,1,236,192ZM152,92h72a12,12,0,0,0,0-24H152a12,12,0,0,0,0,24Z"],"Control":["M208.49,128.49a12,12,0,0,1-17,0L128,65,64.49,128.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,128.49Z"],"Sun":["M116,36V20a12,12,0,0,1,24,0V36a12,12,0,0,1-24,0Zm80,92a68,68,0,1,1-68-68A68.07,68.07,0,0,1,196,128Zm-24,0a44,44,0,1,0-44,44A44.05,44.05,0,0,0,172,128ZM51.51,68.49a12,12,0,1,0,17-17l-12-12a12,12,0,0,0-17,17Zm0,119-12,12a12,12,0,0,0,17,17l12-12a12,12,0,1,0-17-17ZM196,72a12,12,0,0,0,8.49-3.51l12-12a12,12,0,0,0-17-17l-12,12A12,12,0,0,0,196,72Zm8.49,115.51a12,12,0,0,0-17,17l12,12a12,12,0,0,0,17-17ZM48,128a12,12,0,0,0-12-12H20a12,12,0,0,0,0,24H36A12,12,0,0,0,48,128Zm80,80a12,12,0,0,0-12,12v16a12,12,0,0,0,24,0V220A12,12,0,0,0,128,208Zm108-92H220a12,12,0,0,0,0,24h16a12,12,0,0,0,0-24Z"],"Moon":["M236.37,139.4a12,12,0,0,0-12-3A84.07,84.07,0,0,1,119.6,31.59a12,12,0,0,0-15-15A108.86,108.86,0,0,0,49.69,55.07,108,108,0,0,0,136,228a107.09,107.09,0,0,0,64.93-21.69,108.86,108.86,0,0,0,38.44-54.94A12,12,0,0,0,236.37,139.4Zm-49.88,47.74A84,84,0,0,1,68.86,69.51,84.93,84.93,0,0,1,92.27,48.29Q92,52.13,92,56A108.12,108.12,0,0,0,200,164q3.87,0,7.71-.27A84.79,84.79,0,0,1,186.49,187.14Z"],"Info":["M108,84a16,16,0,1,1,16,16A16,16,0,0,1,108,84Zm128,44A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Zm-72,36.68V132a20,20,0,0,0-20-20,12,12,0,0,0-4,23.32V168a20,20,0,0,0,20,20,12,12,0,0,0,4-23.32Z"],"Warning":["M240.26,186.1,152.81,34.23h0a28.74,28.74,0,0,0-49.62,0L15.74,186.1a27.45,27.45,0,0,0,0,27.71A28.31,28.31,0,0,0,40.55,228h174.9a28.31,28.31,0,0,0,24.79-14.19A27.45,27.45,0,0,0,240.26,186.1Zm-20.8,15.7a4.46,4.46,0,0,1-4,2.2H40.55a4.46,4.46,0,0,1-4-2.2,3.56,3.56,0,0,1,0-3.73L124,46.2a4.77,4.77,0,0,1,8,0l87.44,151.87A3.56,3.56,0,0,1,219.46,201.8ZM116,136V104a12,12,0,0,1,24,0v32a12,12,0,0,1-24,0Zm28,40a16,16,0,1,1-16-16A16,16,0,0,1,144,176Z"],"ArrowRight":["M224.49,136.49l-72,72a12,12,0,0,1-17-17L187,140H40a12,12,0,0,1,0-24H187L135.51,64.48a12,12,0,0,1,17-17l72,72A12,12,0,0,1,224.49,136.49Z"],"ArrowLeft":["M228,128a12,12,0,0,1-12,12H69l51.52,51.51a12,12,0,0,1-17,17l-72-72a12,12,0,0,1,0-17l72-72a12,12,0,0,1,17,17L69,116H216A12,12,0,0,1,228,128Z"],"ArrowUp":["M208.49,120.49a12,12,0,0,1-17,0L140,69V216a12,12,0,0,1-24,0V69L64.49,120.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,120.49Z"],"ArrowDown":["M208.49,152.49l-72,72a12,12,0,0,1-17,0l-72-72a12,12,0,0,1,17-17L116,187V40a12,12,0,0,1,24,0V187l51.51-51.52a12,12,0,0,1,17,17Z"],"CaretUpDown":["M184.49,167.51a12,12,0,0,1,0,17l-48,48a12,12,0,0,1-17,0l-48-48a12,12,0,0,1,17-17L128,207l39.51-39.52A12,12,0,0,1,184.49,167.51Zm-96-79L128,49l39.51,39.52a12,12,0,0,0,17-17l-48-48a12,12,0,0,0-17,0l-48,48a12,12,0,0,0,17,17Z"],"Trash":["M216,48H180V36A28,28,0,0,0,152,8H104A28,28,0,0,0,76,36V48H40a12,12,0,0,0,0,24h4V208a20,20,0,0,0,20,20H192a20,20,0,0,0,20-20V72h4a12,12,0,0,0,0-24ZM100,36a4,4,0,0,1,4-4h48a4,4,0,0,1,4,4V48H100Zm88,168H68V72H188ZM116,104v64a12,12,0,0,1-24,0V104a12,12,0,0,1,24,0Zm48,0v64a12,12,0,0,1-24,0V104a12,12,0,0,1,24,0Z"],"Download":["M71.51,88.49a12,12,0,0,1,17-17L116,99V24a12,12,0,0,1,24,0V99l27.51-27.52a12,12,0,0,1,17,17l-48,48a12,12,0,0,1-17,0ZM224,116H188a12,12,0,0,0,0,24h32v56H36V140H68a12,12,0,0,0,0-24H32a20,20,0,0,0-20,20v64a20,20,0,0,0,20,20H224a20,20,0,0,0,20-20V136A20,20,0,0,0,224,116Zm-20,52a16,16,0,1,0-16,16A16,16,0,0,0,204,168Z"],"ArrowClockwise":["M244,56v48a12,12,0,0,1-12,12H184a12,12,0,1,1,0-24H201.1l-19-17.38c-.13-.12-.26-.24-.38-.37A76,76,0,1,0,127,204h1a75.53,75.53,0,0,0,52.15-20.72,12,12,0,0,1,16.49,17.45A99.45,99.45,0,0,1,128,228h-1.37A100,100,0,1,1,198.51,57.06L220,76.72V56a12,12,0,0,1,24,0Z"],"CheckCircle":["M176.49,95.51a12,12,0,0,1,0,17l-56,56a12,12,0,0,1-17,0l-24-24a12,12,0,1,1,17-17L112,143l47.51-47.52A12,12,0,0,1,176.49,95.51ZM236,128A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Z"],"XCircle":["M168.49,104.49,145,128l23.52,23.51a12,12,0,0,1-17,17L128,145l-23.51,23.52a12,12,0,0,1-17-17L111,128,87.51,104.49a12,12,0,0,1,17-17L128,111l23.51-23.52a12,12,0,0,1,17,17ZM236,128A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Z"],"Circle":["M128,20A108,108,0,1,0,236,128,108.12,108.12,0,0,0,128,20Zm0,192a84,84,0,1,1,84-84A84.09,84.09,0,0,1,128,212Z"],"GithubLogo":["M212.62,75.17A63.7,63.7,0,0,0,206.39,26,12,12,0,0,0,196,20a63.71,63.71,0,0,0-50,24H126A63.71,63.71,0,0,0,76,20a12,12,0,0,0-10.39,6,63.7,63.7,0,0,0-6.23,49.17A61.5,61.5,0,0,0,52,104v8a60.1,60.1,0,0,0,45.76,58.28A43.66,43.66,0,0,0,92,192v4H76a20,20,0,0,1-20-20,44.05,44.05,0,0,0-44-44,12,12,0,0,0,0,24,20,20,0,0,1,20,20,44.05,44.05,0,0,0,44,44H92v12a12,12,0,0,0,24,0V192a20,20,0,0,1,40,0v40a12,12,0,0,0,24,0V192a43.66,43.66,0,0,0-5.76-21.72A60.1,60.1,0,0,0,220,112v-8A61.5,61.5,0,0,0,212.62,75.17ZM196,112a36,36,0,0,1-36,36H112a36,36,0,0,1-36-36v-8a37.87,37.87,0,0,1,6.13-20.12,11.65,11.65,0,0,0,1.58-11.49,39.9,39.9,0,0,1-.4-27.72,39.87,39.87,0,0,1,26.41,17.8A12,12,0,0,0,119.82,68h32.35a12,12,0,0,0,10.11-5.53,39.84,39.84,0,0,1,26.41-17.8,39.9,39.9,0,0,1-.4,27.72,12,12,0,0,0,1.61,11.53A37.85,37.85,0,0,1,196,104Z"],"XLogo":["M218.12,209.56l-61-95.8,59.72-65.69a12,12,0,0,0-17.76-16.14L143.81,92.77,106.12,33.56A12,12,0,0,0,96,28H48A12,12,0,0,0,37.88,46.44l61,95.8L39.12,207.93a12,12,0,1,0,17.76,16.14l55.31-60.84,37.69,59.21A12,12,0,0,0,160,228h48a12,12,0,0,0,10.12-18.44ZM166.59,204,69.86,52H89.41l96.73,152Z"],"LinkedinLogo":["M216,20H40A20,20,0,0,0,20,40V216a20,20,0,0,0,20,20H216a20,20,0,0,0,20-20V40A20,20,0,0,0,216,20Zm-4,192H44V44H212ZM112,176V120a12,12,0,0,1,21.43-7.41A40,40,0,0,1,192,148v28a12,12,0,0,1-24,0V148a16,16,0,0,0-32,0v28a12,12,0,0,1-24,0ZM96,120v56a12,12,0,0,1-24,0V120a12,12,0,0,1,24,0ZM68,80A16,16,0,1,1,84,96,16,16,0,0,1,68,80Z"],"InstagramLogo":["M128,80a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,72a24,24,0,1,1,24-24A24,24,0,0,1,128,152ZM176,20H80A60.07,60.07,0,0,0,20,80v96a60.07,60.07,0,0,0,60,60h96a60.07,60.07,0,0,0,60-60V80A60.07,60.07,0,0,0,176,20Zm36,156a36,36,0,0,1-36,36H80a36,36,0,0,1-36-36V80A36,36,0,0,1,80,44h96a36,36,0,0,1,36,36ZM196,76a16,16,0,1,1-16-16A16,16,0,0,1,196,76Z"],"YoutubeLogo":["M170.49,117.91l-56-36A12,12,0,0,0,96,92v72a12,12,0,0,0,18.49,10.09l56-36a12,12,0,0,0,0-20.18ZM120,142V114l21.81,14Zm118.21-73.5a28.05,28.05,0,0,0-16.93-19.14C186.4,35.91,131.29,36,128,36s-58.4-.09-93.28,13.38A28.05,28.05,0,0,0,17.79,68.52C15.15,78.72,12,97.32,12,128s3.15,49.28,5.79,59.48a28.05,28.05,0,0,0,16.93,19.14C68.21,219.55,120.36,220,127.37,220h1.26c7,0,59.16-.45,92.65-13.38a28.05,28.05,0,0,0,16.93-19.14c2.64-10.2,5.79-28.8,5.79-59.48S240.85,78.72,238.21,68.52ZM215,181.46a4,4,0,0,1-2.34,2.77C182.78,195.76,132.27,196,128.32,196h-.39c-.53,0-53.64.17-84.56-11.77A4,4,0,0,1,41,181.46c-1.88-7.24-5-23.82-5-53.46s3.15-46.22,5-53.46a4,4,0,0,1,2.34-2.77C74.29,59.83,127.39,60,127.92,60h.15c.54,0,53.64-.17,84.56,11.77A4,4,0,0,1,215,74.54c1.88,7.24,5,23.82,5,53.46S216.85,174.22,215,181.46Z"],"EnvelopeSimple":["M224,44H32A12,12,0,0,0,20,56V192a20,20,0,0,0,20,20H216a20,20,0,0,0,20-20V56A12,12,0,0,0,224,44ZM193.15,68,128,127.72,62.85,68ZM44,188V83.28l75.89,69.57a12,12,0,0,0,16.22,0L212,83.28V188Z"],"TerminalWindow":["M72.5,150.63,100.79,128,72.5,105.37a12,12,0,1,1,15-18.74l40,32a12,12,0,0,1,0,18.74l-40,32a12,12,0,0,1-15-18.74ZM144,172h32a12,12,0,0,0,0-24H144a12,12,0,0,0,0,24ZM236,56V200a20,20,0,0,1-20,20H40a20,20,0,0,1-20-20V56A20,20,0,0,1,40,36H216A20,20,0,0,1,236,56Zm-24,4H44V196H212Z"]}} +{"notice":"/*! The icon paths below are from Phosphor Icons (@phosphor-icons/react):\nMIT License\n\nCopyright (c) 2020 Phosphor Icons\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/","icons":{"Command":["M180,140H164V116h16a40,40,0,1,0-40-40V92H116V76a40,40,0,1,0-40,40H92v24H76a40,40,0,1,0,40,40V164h24v16a40,40,0,1,0,40-40ZM164,76a16,16,0,1,1,16,16H164ZM60,76a16,16,0,0,1,32,0V92H76A16,16,0,0,1,60,76ZM92,180a16,16,0,1,1-16-16H92Zm24-64h24v24H116Zm64,80a16,16,0,0,1-16-16V164h16a16,16,0,0,1,0,32Z"],"Option":["M236,192a12,12,0,0,1-12,12H160.94a19.89,19.89,0,0,1-17.88-11.06L92.58,92H32a12,12,0,0,1,0-24H95.06a19.89,19.89,0,0,1,17.88,11.06L163.42,180H224A12,12,0,0,1,236,192ZM152,92h72a12,12,0,0,0,0-24H152a12,12,0,0,0,0,24Z"],"Control":["M208.49,128.49a12,12,0,0,1-17,0L128,65,64.49,128.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,128.49Z"],"Sun":["M116,36V20a12,12,0,0,1,24,0V36a12,12,0,0,1-24,0Zm80,92a68,68,0,1,1-68-68A68.07,68.07,0,0,1,196,128Zm-24,0a44,44,0,1,0-44,44A44.05,44.05,0,0,0,172,128ZM51.51,68.49a12,12,0,1,0,17-17l-12-12a12,12,0,0,0-17,17Zm0,119-12,12a12,12,0,0,0,17,17l12-12a12,12,0,1,0-17-17ZM196,72a12,12,0,0,0,8.49-3.51l12-12a12,12,0,0,0-17-17l-12,12A12,12,0,0,0,196,72Zm8.49,115.51a12,12,0,0,0-17,17l12,12a12,12,0,0,0,17-17ZM48,128a12,12,0,0,0-12-12H20a12,12,0,0,0,0,24H36A12,12,0,0,0,48,128Zm80,80a12,12,0,0,0-12,12v16a12,12,0,0,0,24,0V220A12,12,0,0,0,128,208Zm108-92H220a12,12,0,0,0,0,24h16a12,12,0,0,0,0-24Z"],"Moon":["M236.37,139.4a12,12,0,0,0-12-3A84.07,84.07,0,0,1,119.6,31.59a12,12,0,0,0-15-15A108.86,108.86,0,0,0,49.69,55.07,108,108,0,0,0,136,228a107.09,107.09,0,0,0,64.93-21.69,108.86,108.86,0,0,0,38.44-54.94A12,12,0,0,0,236.37,139.4Zm-49.88,47.74A84,84,0,0,1,68.86,69.51,84.93,84.93,0,0,1,92.27,48.29Q92,52.13,92,56A108.12,108.12,0,0,0,200,164q3.87,0,7.71-.27A84.79,84.79,0,0,1,186.49,187.14Z"],"Info":["M108,84a16,16,0,1,1,16,16A16,16,0,0,1,108,84Zm128,44A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Zm-72,36.68V132a20,20,0,0,0-20-20,12,12,0,0,0-4,23.32V168a20,20,0,0,0,20,20,12,12,0,0,0,4-23.32Z"],"Warning":["M240.26,186.1,152.81,34.23h0a28.74,28.74,0,0,0-49.62,0L15.74,186.1a27.45,27.45,0,0,0,0,27.71A28.31,28.31,0,0,0,40.55,228h174.9a28.31,28.31,0,0,0,24.79-14.19A27.45,27.45,0,0,0,240.26,186.1Zm-20.8,15.7a4.46,4.46,0,0,1-4,2.2H40.55a4.46,4.46,0,0,1-4-2.2,3.56,3.56,0,0,1,0-3.73L124,46.2a4.77,4.77,0,0,1,8,0l87.44,151.87A3.56,3.56,0,0,1,219.46,201.8ZM116,136V104a12,12,0,0,1,24,0v32a12,12,0,0,1-24,0Zm28,40a16,16,0,1,1-16-16A16,16,0,0,1,144,176Z"],"ArrowRight":["M224.49,136.49l-72,72a12,12,0,0,1-17-17L187,140H40a12,12,0,0,1,0-24H187L135.51,64.48a12,12,0,0,1,17-17l72,72A12,12,0,0,1,224.49,136.49Z"],"ArrowLeft":["M228,128a12,12,0,0,1-12,12H69l51.52,51.51a12,12,0,0,1-17,17l-72-72a12,12,0,0,1,0-17l72-72a12,12,0,0,1,17,17L69,116H216A12,12,0,0,1,228,128Z"],"ArrowUp":["M208.49,120.49a12,12,0,0,1-17,0L140,69V216a12,12,0,0,1-24,0V69L64.49,120.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,120.49Z"],"ArrowDown":["M208.49,152.49l-72,72a12,12,0,0,1-17,0l-72-72a12,12,0,0,1,17-17L116,187V40a12,12,0,0,1,24,0V187l51.51-51.52a12,12,0,0,1,17,17Z"],"CaretUpDown":["M184.49,167.51a12,12,0,0,1,0,17l-48,48a12,12,0,0,1-17,0l-48-48a12,12,0,0,1,17-17L128,207l39.51-39.52A12,12,0,0,1,184.49,167.51Zm-96-79L128,49l39.51,39.52a12,12,0,0,0,17-17l-48-48a12,12,0,0,0-17,0l-48,48a12,12,0,0,0,17,17Z"],"Trash":["M216,48H180V36A28,28,0,0,0,152,8H104A28,28,0,0,0,76,36V48H40a12,12,0,0,0,0,24h4V208a20,20,0,0,0,20,20H192a20,20,0,0,0,20-20V72h4a12,12,0,0,0,0-24ZM100,36a4,4,0,0,1,4-4h48a4,4,0,0,1,4,4V48H100Zm88,168H68V72H188ZM116,104v64a12,12,0,0,1-24,0V104a12,12,0,0,1,24,0Zm48,0v64a12,12,0,0,1-24,0V104a12,12,0,0,1,24,0Z"],"Download":["M71.51,88.49a12,12,0,0,1,17-17L116,99V24a12,12,0,0,1,24,0V99l27.51-27.52a12,12,0,0,1,17,17l-48,48a12,12,0,0,1-17,0ZM224,116H188a12,12,0,0,0,0,24h32v56H36V140H68a12,12,0,0,0,0-24H32a20,20,0,0,0-20,20v64a20,20,0,0,0,20,20H224a20,20,0,0,0,20-20V136A20,20,0,0,0,224,116Zm-20,52a16,16,0,1,0-16,16A16,16,0,0,0,204,168Z"],"ArrowClockwise":["M244,56v48a12,12,0,0,1-12,12H184a12,12,0,1,1,0-24H201.1l-19-17.38c-.13-.12-.26-.24-.38-.37A76,76,0,1,0,127,204h1a75.53,75.53,0,0,0,52.15-20.72,12,12,0,0,1,16.49,17.45A99.45,99.45,0,0,1,128,228h-1.37A100,100,0,1,1,198.51,57.06L220,76.72V56a12,12,0,0,1,24,0Z"],"CheckCircle":["M176.49,95.51a12,12,0,0,1,0,17l-56,56a12,12,0,0,1-17,0l-24-24a12,12,0,1,1,17-17L112,143l47.51-47.52A12,12,0,0,1,176.49,95.51ZM236,128A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Z"],"XCircle":["M168.49,104.49,145,128l23.52,23.51a12,12,0,0,1-17,17L128,145l-23.51,23.52a12,12,0,0,1-17-17L111,128,87.51,104.49a12,12,0,0,1,17-17L128,111l23.51-23.52a12,12,0,0,1,17,17ZM236,128A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Z"],"Circle":["M128,20A108,108,0,1,0,236,128,108.12,108.12,0,0,0,128,20Zm0,192a84,84,0,1,1,84-84A84.09,84.09,0,0,1,128,212Z"],"GithubLogo":["M212.62,75.17A63.7,63.7,0,0,0,206.39,26,12,12,0,0,0,196,20a63.71,63.71,0,0,0-50,24H126A63.71,63.71,0,0,0,76,20a12,12,0,0,0-10.39,6,63.7,63.7,0,0,0-6.23,49.17A61.5,61.5,0,0,0,52,104v8a60.1,60.1,0,0,0,45.76,58.28A43.66,43.66,0,0,0,92,192v4H76a20,20,0,0,1-20-20,44.05,44.05,0,0,0-44-44,12,12,0,0,0,0,24,20,20,0,0,1,20,20,44.05,44.05,0,0,0,44,44H92v12a12,12,0,0,0,24,0V192a20,20,0,0,1,40,0v40a12,12,0,0,0,24,0V192a43.66,43.66,0,0,0-5.76-21.72A60.1,60.1,0,0,0,220,112v-8A61.5,61.5,0,0,0,212.62,75.17ZM196,112a36,36,0,0,1-36,36H112a36,36,0,0,1-36-36v-8a37.87,37.87,0,0,1,6.13-20.12,11.65,11.65,0,0,0,1.58-11.49,39.9,39.9,0,0,1-.4-27.72,39.87,39.87,0,0,1,26.41,17.8A12,12,0,0,0,119.82,68h32.35a12,12,0,0,0,10.11-5.53,39.84,39.84,0,0,1,26.41-17.8,39.9,39.9,0,0,1-.4,27.72,12,12,0,0,0,1.61,11.53A37.85,37.85,0,0,1,196,104Z"],"XLogo":["M218.12,209.56l-61-95.8,59.72-65.69a12,12,0,0,0-17.76-16.14L143.81,92.77,106.12,33.56A12,12,0,0,0,96,28H48A12,12,0,0,0,37.88,46.44l61,95.8L39.12,207.93a12,12,0,1,0,17.76,16.14l55.31-60.84,37.69,59.21A12,12,0,0,0,160,228h48a12,12,0,0,0,10.12-18.44ZM166.59,204,69.86,52H89.41l96.73,152Z"],"LinkedinLogo":["M216,20H40A20,20,0,0,0,20,40V216a20,20,0,0,0,20,20H216a20,20,0,0,0,20-20V40A20,20,0,0,0,216,20Zm-4,192H44V44H212ZM112,176V120a12,12,0,0,1,21.43-7.41A40,40,0,0,1,192,148v28a12,12,0,0,1-24,0V148a16,16,0,0,0-32,0v28a12,12,0,0,1-24,0ZM96,120v56a12,12,0,0,1-24,0V120a12,12,0,0,1,24,0ZM68,80A16,16,0,1,1,84,96,16,16,0,0,1,68,80Z"],"InstagramLogo":["M128,80a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,72a24,24,0,1,1,24-24A24,24,0,0,1,128,152ZM176,20H80A60.07,60.07,0,0,0,20,80v96a60.07,60.07,0,0,0,60,60h96a60.07,60.07,0,0,0,60-60V80A60.07,60.07,0,0,0,176,20Zm36,156a36,36,0,0,1-36,36H80a36,36,0,0,1-36-36V80A36,36,0,0,1,80,44h96a36,36,0,0,1,36,36ZM196,76a16,16,0,1,1-16-16A16,16,0,0,1,196,76Z"],"YoutubeLogo":["M170.49,117.91l-56-36A12,12,0,0,0,96,92v72a12,12,0,0,0,18.49,10.09l56-36a12,12,0,0,0,0-20.18ZM120,142V114l21.81,14Zm118.21-73.5a28.05,28.05,0,0,0-16.93-19.14C186.4,35.91,131.29,36,128,36s-58.4-.09-93.28,13.38A28.05,28.05,0,0,0,17.79,68.52C15.15,78.72,12,97.32,12,128s3.15,49.28,5.79,59.48a28.05,28.05,0,0,0,16.93,19.14C68.21,219.55,120.36,220,127.37,220h1.26c7,0,59.16-.45,92.65-13.38a28.05,28.05,0,0,0,16.93-19.14c2.64-10.2,5.79-28.8,5.79-59.48S240.85,78.72,238.21,68.52ZM215,181.46a4,4,0,0,1-2.34,2.77C182.78,195.76,132.27,196,128.32,196h-.39c-.53,0-53.64.17-84.56-11.77A4,4,0,0,1,41,181.46c-1.88-7.24-5-23.82-5-53.46s3.15-46.22,5-53.46a4,4,0,0,1,2.34-2.77C74.29,59.83,127.39,60,127.92,60h.15c.54,0,53.64-.17,84.56,11.77A4,4,0,0,1,215,74.54c1.88,7.24,5,23.82,5,53.46S216.85,174.22,215,181.46Z"],"EnvelopeSimple":["M224,44H32A12,12,0,0,0,20,56V192a20,20,0,0,0,20,20H216a20,20,0,0,0,20-20V56A12,12,0,0,0,224,44ZM193.15,68,128,127.72,62.85,68ZM44,188V83.28l75.89,69.57a12,12,0,0,0,16.22,0L212,83.28V188Z"],"TerminalWindow":["M72.5,150.63,100.79,128,72.5,105.37a12,12,0,1,1,15-18.74l40,32a12,12,0,0,1,0,18.74l-40,32a12,12,0,0,1-15-18.74ZM144,172h32a12,12,0,0,0,0-24H144a12,12,0,0,0,0,24ZM236,56V200a20,20,0,0,1-20,20H40a20,20,0,0,1-20-20V56A20,20,0,0,1,40,36H216A20,20,0,0,1,236,56Zm-24,4H44V196H212Z"],"ArrowsOutSimple":["M220,48V96a12,12,0,0,1-24,0V77l-39.51,39.52a12,12,0,0,1-17-17L179,60H160a12,12,0,0,1,0-24h48A12,12,0,0,1,220,48ZM99.51,139.51,60,179V160a12,12,0,0,0-24,0v48a12,12,0,0,0,12,12H96a12,12,0,0,0,0-24H77l39.52-39.51a12,12,0,0,0-17-17Z"]}} diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index 8ea09914..1b4cd968 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -811,6 +811,42 @@ "toggle" ] }, + "diagram-zoom": { + "classes": [ + "diagram-expand", + "diagram-viewer", + "diagram-stage", + "diagram-sizer", + "diagram-layer", + "diagram-zoom", + "diagram-level", + "diagram-fit", + "diagram-probe", + "diagram-viewer-foot", + "diagram-viewer-key", + "diagram-viewer-row", + "diagram-viewer-hint", + "diagram-viewer-end", + "diagram-viewer-list", + "diagram-viewer-source" + ], + "requires": [ + "diagram", + "dialog", + "dialog-form", + "sheet" + ], + "icons": [ + "ArrowsOutSimple" + ], + "budget": 12000, + "usage": 900, + "builds": [ + "dialog", + "dialog-form", + "sheet" + ] + }, "sparkline": { "classes": [ "sparkline", diff --git a/.agent/skills/basalt-html/parts/usage/diagram-zoom.md b/.agent/skills/basalt-html/parts/usage/diagram-zoom.md new file mode 100644 index 00000000..a6355aee --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-zoom.md @@ -0,0 +1,8 @@ +# diagram-zoom + +Added for you on a page with a diagram (with `dialog`, `dialog-form` and `sheet`), unless every figure's JSON says `"zoom": false`. + +- **Expand:** in the figure's foot after "View as list", once script runs. It opens the viewer: the drawn layout in a dialog (the window less 16px from 720, the whole window under it), even where the page shows the stack. +- **Zoom:** it opens at Fit (the whole drawing, 200% at most). "Zoom out", "Zoom in" and "Fit" in the foot; `+`, `-` and `0` with focus in the stage; Ctrl or Command with the wheel, a trackpad pinch and two fingers zoom about the pointer. From Fit or 100% to 400%. +- **Pan:** the stage scrolls both ways; a drag, one finger, the wheel or the arrow keys. A trace works; nothing animates. Esc closes it. +- Don't build a viewer of your own, and don't scale a figure on the page. diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index e192911a..8e15a0fb 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -2052,6 +2052,62 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin return { dyn: d, geo, ink: inkHtml(P, geo, tk, base), tokens: tk, least: mins.least }; } +/** What the viewer's figure remembers between layouts: the least width the engine was found to draw this data at (0: none). */ +export interface ViewerMemo { model?: Model; least?: number } +export interface ViewerLayout { + /** The layer the figure is laid out in: its width is the layout width; its transform (the zoom) is taken off while it is measured. */ + layer: HTMLElement; + /** The stage's inner width, the page row and `size-breakpoint-container`, in CSS pixels. */ + avail: number; + row: number; + contain: number; + memo: ViewerMemo; +} + +/** + * The viewer's layout (DECISIONS 310, 9.3), for React and the skill alike: the figure is laid out at the stage's inner width, never under its least drawn + * width and never over the page row unless that width is more; a stack is held only when nothing is drawn, at most the container's width. The engine + * measures only at 100%: the zoom is taken off the layer while it measures and put back before anything paints. + */ +export function measureViewerFigure(fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn: ((s: string) => void) | undefined, v: ViewerLayout): Measured { + const { layer, memo } = v; + if (memo.model !== m) { memo.model = m; memo.least = undefined; } + const sizeTo = (least: number) => { layer.style.width = `${Math.max(memo.least || least, Math.min(v.avail, v.row))}px`; }; + // The layer has no width of its own until the first layout: it starts at the stage's, so the figure can be measured. + if (!layer.style.width) layer.style.width = `${Math.min(v.avail, v.row)}px`; + const zoomed = layer.style.transform; + layer.style.transform = "none"; + // A dialog still opening is scaled (from .98): the layer is scaled by the inverse while it is measured, so what is read is 100% whatever its ancestors do. + const ancestors = layer.offsetWidth ? layer.getBoundingClientRect().width / layer.offsetWidth : 1; + if (Math.abs(ancestors - 1) > 1e-4) layer.style.transform = `scale(${1 / ancestors})`; + // Before the least drawn width is known, a refusal at the token sum is expected and is not the author's to fix: it says nothing. + let result = measureFigure(fig, m, P, base, current, apply, memo.least === undefined ? undefined : warn, sizeTo); + // The least drawn width is the first width the engine draws the figure at, which the token sum can undercount (a sequence's columns are measured, a + // decision may be taller than wide at a width). Found once by trying wider layouts, in steps of 16 and then by the pixel, up to half the row past it. A width + // counts when it draws twice running: measured from the stack, then again from its own drawn state, as every later measure is. + if (result.dyn.layout === "stacked" && memo.least === undefined && result.least !== undefined) { + const from = result.dyn; + const at = (w: number) => { + layer.style.width = `${w}px`; + const first = measureFigure(fig, m, P, base, from, apply); + return first.dyn.layout === "drawn" ? measureFigure(fig, m, P, base, first.dyn, apply) : first; + }; + const start = Math.max(result.least, Math.min(v.avail, v.row)); + const cap = Math.max(v.row, start) * 1.5; + let found: number | undefined; + for (let w = start + 16; w <= cap && found === undefined; w += 16) if (at(w).dyn.layout === "drawn") found = w; + if (found !== undefined) for (let w = found - 15; w < found; w++) if (at(w).dyn.layout === "drawn") { found = w; break; } + memo.least = found ?? 0; + result = found !== undefined ? at(found) : measureFigure(fig, m, P, base, from, apply, warn, sizeTo); + } + if (result.dyn.layout === "stacked" && fig.clientWidth > v.contain) { + layer.style.width = `${v.contain}px`; + result = measureFigure(fig, m, P, base, result.dyn, apply, warn); + } + layer.style.transform = zoomed; + return result; +} + function lineName(m: Model, l: GLine): string { const a = m.byId.get(l.from)?.name ?? l.from, b = m.byId.get(l.to)?.name ?? l.to; return `${a} to ${b}`; diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index eb0167e6..3e820bb9 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -4,9 +4,9 @@ import { Kbd } from "./kbd"; import { useShortcutsVisible } from "./keyboard"; import { usePanelLevel } from "./layers"; import { - applyTrace, buildModel, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, + applyTrace, buildModel, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, measureViewerFigure, settleEntrance, syncAttributes, toHtml, } from "./diagram-core"; -import type { DiagramLegend, DiagramMotion, DiagramSpec, Dyn, Measured, VNode } from "./diagram-core"; +import type { DiagramLegend, DiagramMotion, DiagramSpec, Dyn, Measured, ViewerMemo, VNode } from "./diagram-core"; import type { MotionController } from "./diagram-motion-core"; import { ArrowsOutSimpleIcon } from "@phosphor-icons/react/dist/csr/ArrowsOutSimple"; import { Icon } from "./icon"; @@ -135,9 +135,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti const [ink, setInk] = React.useState(""); const inkHtml = React.useMemo(() => ({ __html: ink }), [ink]); const measured = React.useRef(null); - // The viewer's figure: the least width the engine was found to draw it at (0: none was found), for this data. - const leastDrawn = React.useRef(undefined); - const leastFor = React.useRef(null); + // The viewer's figure: the least width the engine was found to draw it at, for this data (measureViewerFigure). + const leastMemo = React.useRef({}); const dynRef = React.useRef(dyn); dynRef.current = dyn; const [motionModule, setMotionModule] = React.useState(null); @@ -165,38 +164,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti if (!fig) return; const warn = process.env.NODE_ENV !== "production" ? (message: string) => warnOnce(component, message) : undefined; const apply = (d: Dyn) => syncAttributes(fig, figureTree(model, d, options)); - // The viewer's figure is laid out at the stage's width, never under its least drawn width (9.3); a stack it must hold is at most the container's width. const layer = viewer?.layer(); - if (leastFor.current !== model) { leastFor.current = model; leastDrawn.current = undefined; } - const sizeTo = viewer && layer ? (least: number) => { layer.style.width = `${Math.max(leastDrawn.current ?? least, Math.min(viewer.avail, viewer.row))}px`; } : undefined; - // The layer has no width of its own until the first layout: it starts at the stage's, so the figure can be measured. - if (viewer && layer && !layer.style.width) layer.style.width = `${Math.min(viewer.avail, viewer.row)}px`; - // The engine measures only at 100% (9.3): the zoom is taken off the layer while it measures and put back before anything paints. - const zoomed = layer?.style.transform ?? ""; - if (layer && zoomed) layer.style.transform = "none"; - let result = measureFigure(fig, model, P, base, dynRef.current, apply, warn, sizeTo); - // The figure's least drawn width is the first width the engine draws it at, which the token sum can undercount (a sequence's columns are measured, a - // decision's diamond may be refused at a width). Found once by trying wider layouts, in steps of 16 and then by the pixel, up to half the row past it. - if (viewer && layer && result.dyn.layout === "stacked" && leastDrawn.current === undefined && result.least !== undefined) { - // A width counts when it draws twice running: measured from the stack, then again from its own drawn state, as every later measure is. - const at = (w: number) => { - layer.style.width = `${w}px`; - const first = measureFigure(fig, model, P, base, result.dyn, apply); - return first.dyn.layout === "drawn" ? measureFigure(fig, model, P, base, first.dyn, apply) : first; - }; - const from = Math.max(result.least, Math.min(viewer.avail, viewer.row)); - const cap = Math.max(viewer.row, from) * 1.5; - let found: number | undefined; - for (let w = from + 16; w <= cap && found === undefined; w += 16) if (at(w).dyn.layout === "drawn") found = w; - if (found !== undefined) for (let w = found - 15; w < found; w++) if (at(w).dyn.layout === "drawn") { found = w; break; } - if (found !== undefined) { leastDrawn.current = found; result = at(found); } - else leastDrawn.current = 0; - } - if (viewer && layer && result.dyn.layout === "stacked" && fig.clientWidth > viewer.contain) { - layer.style.width = `${viewer.contain}px`; - result = measureFigure(fig, model, P, base, result.dyn, apply, warn); - } - if (layer && zoomed) layer.style.transform = zoomed; + const result = viewer && layer ? measureViewerFigure(fig, model, P, base, dynRef.current, apply, warn, { layer, avail: viewer.avail, row: viewer.row, contain: viewer.contain, memo: leastMemo.current }) : measureFigure(fig, model, P, base, dynRef.current, apply, warn); measured.current = result; // The same layout is the same state: a measure that changes nothing renders nothing. // (A layout is plain data that the engine builds in one order, so its text is a fair test.) diff --git a/tools/html-skill/build.mjs b/tools/html-skill/build.mjs index f3e59b8d..e6bbd799 100644 --- a/tools/html-skill/build.mjs +++ b/tools/html-skill/build.mjs @@ -256,6 +256,26 @@ function diagramMotionCss() { if (start < 0 || end < 0) throw new Error("html-skill: the diagram motion section of packages/react/src/styles/components.css moved; update diagramMotionCss"); return `@layer basalt {\n${react.slice(start, end).replaceAll(".basalt-diagram", ".diagram")}\n}\n`; } +/** + * The diagram-zoom module's stylesheet (DECISIONS 310): the "Diagram viewer" section of components.css, with React's names as the skill's (the dialog, the + * sheet's parts, the button and the icon), so the viewer in a page is React's viewer. + */ +function diagramZoomCss() { + const react = fs.readFileSync(path.join(repo, "packages", "react", "src", "styles", "components.css"), "utf8"); + const start = react.indexOf(" /* ---- Diagram viewer (DECISIONS 310"); + const end = react.indexOf(" /* ---- ", start + 10); + if (start < 0 || end < 0) throw new Error("html-skill: the diagram viewer section of packages/react/src/styles/components.css moved; update diagramZoomCss"); + const css = react.slice(start, end) + .replaceAll("var(--_surface, var(--basalt-surface-overlay))", "var(--panel-bg, var(--basalt-surface-overlay))") + .replaceAll(".basalt-diagram", ".diagram") + .replaceAll(".basalt-dialog-backdrop", "dialog.modal::backdrop") + .replaceAll(".basalt-dialog", ".dialog") + .replaceAll(".basalt-sheet-", ".sheet-") + .replaceAll(".basalt-button", ".btn") + .replaceAll(".basalt-icon", ".icon"); + if (/basalt-(?!duration|space|size|text|font|border|surface)/.test(css.replace(/--basalt-[\w-]+/g, ""))) throw new Error("html-skill: the diagram viewer section names a React class diagramZoomCss does not rename"); + return `@layer basalt {\n${css}\n}\n`; +} /** * A module whose source imports React's engine (the diagram module): bundled into one script, the import inlined. It is a development build of the engine * (NODE_ENV "development"): the skill keeps the checks a production React build drops, since compose.mjs reports them when it writes a page. @@ -289,10 +309,11 @@ export function build() { if (name === "diagram") files["parts/diagram.css"] = minifyCss(`${dedupeSystemDark(filterTokens(tokensCss(), inDiagram))}\n${diagramCss()}`); // The motion section, with the motion tokens (the diagram durations and speeds) that only an animated diagram reads. if (name === "diagram-motion") files["parts/diagram-motion.css"] = minifyCss(`${filterTokens(tokensCss(), inDiagramMotion)}\n${diagramMotionCss()}`); + if (name === "diagram-zoom") files["parts/diagram-zoom.css"] = minifyCss(diagramZoomCss()); for (const ext of ["css", "js"]) { const file = path.join(srcDir, "modules", `${name}.${ext}`); if (!fs.existsSync(file)) continue; - if (ext === "js" && (name === "diagram" || name === "diagram-motion")) files[`parts/${name}.js`] = minifyJs(bundleModule(file)); + if (ext === "js" && (name === "diagram" || name === "diagram-motion" || name === "diagram-zoom")) files[`parts/${name}.js`] = minifyJs(bundleModule(file)); else files[`parts/${name}.${ext}`] = ext === "css" ? minifyCss(tokens + fs.readFileSync(file, "utf8")) : minifyJs(fs.readFileSync(file, "utf8")); } } diff --git a/tools/html-skill/src/compose.mjs b/tools/html-skill/src/compose.mjs index d1cf730f..3e5722c6 100644 --- a/tools/html-skill/src/compose.mjs +++ b/tools/html-skill/src/compose.mjs @@ -555,7 +555,12 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts = // Detection reads markup and code, never comments: a word written about in a comment (an HTML one, or one inside a script or a style) brings nothing in. const code = `${held.restore(markup, true)}\n${styles.map((style) => stripCssComments(style.css)).join("\n")}`; - const chosen = detect(code, manifest, Object.keys(iconFile.icons), { all, use, glyphNames: Object.keys(glyphFile) }); + let chosen = detect(code, manifest, Object.keys(iconFile.icons), { all, use, glyphNames: Object.keys(glyphFile) }); + // The diagram viewer (DECISIONS 310): a page with a figure has "Expand" and its dialog, unless every figure on it says "zoom": false. A figure drawn from + // script (Basalt.diagram) may want it, so it counts. + if (chosen.modules.includes("diagram") && !chosen.modules.includes("diagram-zoom") && "diagram-zoom" in manifest.modules && zoomWanted(held, code)) { + chosen = detect(code, manifest, Object.keys(iconFile.icons), { all, use: [...use, "diagram-zoom"], glyphNames: Object.keys(glyphFile) }); + } // A module the body never triggers, which is in only because another module's script builds its markup (the palette's rows and key chips). const bare = { ...manifest, modules: Object.fromEntries(Object.entries(manifest.modules).map(([n, m]) => [n, { ...m, requires: [] }])) }; const direct = detect(code, bare, [], { all, use }).modules; @@ -603,6 +608,14 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts = return { html, modules: chosen.modules, icons: chosen.icons, glyphs: chosen.glyphs, built, external: externalReferences(held, markup), diagrams: diagramNotes, bytes: Buffer.byteLength(html) }; } +/** Whether any figure on the page keeps its viewer: a `data-diagram` JSON without `"zoom": false`, or a figure drawn from script. */ +function zoomWanted(held, code) { + if (/Basalt\s*\.\s*diagram\b/.test(code)) return true; + const specs = held.saved.filter((item) => item.kind === "script" && item.attrs.some(([k]) => k === "data-diagram")); + if (!specs.length) return true; + return specs.some((item) => { try { return JSON.parse(item.inner).zoom !== false; } catch { return true; } }); +} + /** * A diagram's words, written into the page (DECISIONS 281, 1.19): each `
` that holds only its JSON gets the markup the diagram module's * script would write for it, from that same script (parts/diagram.js, run here without a page), so the page reads before any script runs. The figure's own diff --git a/tools/html-skill/src/icons.json b/tools/html-skill/src/icons.json index 23780f77..8b31ee2b 100644 --- a/tools/html-skill/src/icons.json +++ b/tools/html-skill/src/icons.json @@ -1,2 +1,2 @@ ["Command", "Option", "Control", "Sun", "Moon", "Info", "Warning", "ArrowRight", "ArrowLeft", "ArrowUp", - "ArrowDown", "CaretUpDown", "Trash", "Download", "ArrowClockwise", "CheckCircle", "XCircle", "Circle", "GithubLogo", "XLogo", "LinkedinLogo", "InstagramLogo", "YoutubeLogo", "EnvelopeSimple", "TerminalWindow"] + "ArrowDown", "CaretUpDown", "Trash", "Download", "ArrowClockwise", "CheckCircle", "XCircle", "Circle", "GithubLogo", "XLogo", "LinkedinLogo", "InstagramLogo", "YoutubeLogo", "EnvelopeSimple", "TerminalWindow", "ArrowsOutSimple"] diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index 8ea09914..1b4cd968 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -811,6 +811,42 @@ "toggle" ] }, + "diagram-zoom": { + "classes": [ + "diagram-expand", + "diagram-viewer", + "diagram-stage", + "diagram-sizer", + "diagram-layer", + "diagram-zoom", + "diagram-level", + "diagram-fit", + "diagram-probe", + "diagram-viewer-foot", + "diagram-viewer-key", + "diagram-viewer-row", + "diagram-viewer-hint", + "diagram-viewer-end", + "diagram-viewer-list", + "diagram-viewer-source" + ], + "requires": [ + "diagram", + "dialog", + "dialog-form", + "sheet" + ], + "icons": [ + "ArrowsOutSimple" + ], + "budget": 12000, + "usage": 900, + "builds": [ + "dialog", + "dialog-form", + "sheet" + ] + }, "sparkline": { "classes": [ "sparkline", diff --git a/tools/html-skill/src/modules/diagram-zoom.js b/tools/html-skill/src/modules/diagram-zoom.js new file mode 100644 index 00000000..c7113bb9 --- /dev/null +++ b/tools/html-skill/src/modules/diagram-zoom.js @@ -0,0 +1,150 @@ +/* Basalt HTML script, diagram-zoom module (DECISIONS 301, part 9, as DECISIONS 310): "Expand" in a figure's foot opens the viewer, a form dialog + (the dialog module's, with the sheet's head, body and foot) whose body is a stage: the figure's drawn layout, laid out once at 100% and zoomed by + the reader with one transform, from Fit or 100% to 400%; a pan is a scroll. The zoom and pan are React's own (packages/react/src/diagram-zoom-core.ts, + bundled into this module by build.mjs); the figure is drawn by the diagram module's engine (Basalt._.diagramKit), so this holds no second copy of it. + compose.mjs adds this module to a page with a figure unless every figure on it says "zoom": false. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-zoom.js (do not edit the copy in the skill folder). */ +import { attachZoom, revealIn } from "../../../../packages/react/src/diagram-zoom-core.ts"; + +(function (B) { + 'use strict'; + var _ = B._; + var serial = 0; + + function esc(s) { return _.diagramKit.escapeHtml(String(s == null ? '' : s)); } + function kbd(k) { return '' + esc(k) + ''; } + function px(el, prop) { return parseFloat(getComputedStyle(el).getPropertyValue(prop)) || 0; } + + /** Builds the viewer for one figure and opens it; closing it removes it. */ + function openViewer(page, spec, ctx, opener) { + var kit = _.diagramKit; + var still = Object.assign({}, spec, { motion: 'still' }); + var model = kit.buildModel(still); + var id = 'dgv' + (++serial); + var key = kit.figureKey('diagram', model); + var hint = kit.hintEntries(model, true).map(function (e) { return '' + e.keys.map(kbd).join(' ') + ' ' + esc(e.words) + ''; }).join(''); + var d = document.createElement('dialog'); + d.className = 'panel float modal dialog diagram-viewer'; + d.setAttribute('data-form', ''); + d.setAttribute('aria-describedby', id + '-summary'); + d.innerHTML = + '

' + esc(model.title) + '

' + + (spec.source ? '

' + esc(spec.source) + '

' : '') + '
' + + '
' + + '

' + esc(spec.summary) + '

' + + '
' + + '' + + '
' + + '
' + + (key ? '
' + kit.toHtml(key) + '
' : '') + + '
' + + '' + + '' + + '' + + '
' + + '' + + '
' + + '
'; + document.body.appendChild(d); + var stage = d.querySelector('.diagram-stage'), sizer = d.querySelector('.diagram-sizer'), layer = d.querySelector('.diagram-layer'); + var fig = layer.firstChild, status = d.querySelector('[role="status"]'), level = d.querySelector('.diagram-level > span'); + var keyBox = d.querySelector('.diagram-viewer-key'), toggle = d.querySelector('.diagram-toggle'); + var buttons = { out: d.querySelector('[data-zoom="out"]'), in: d.querySelector('[data-zoom="in"]'), fit: d.querySelector('[data-zoom="fit"]') }; + var list = null, listOpen = false, bare = false; + var setOff = function (b, off) { if (off) b.setAttribute('aria-disabled', 'true'); else b.removeAttribute('aria-disabled'); }; + var zoom = attachZoom({ + stage: stage, sizer: sizer, layer: layer, status: status, rest: px(stage, '--_rest') || 300, + onChange: function (s) { + level.textContent = s.level + '%'; + setOff(buttons.out, s.listOpen || s.atMin); + setOff(buttons.in, s.listOpen || s.atMax); + setOff(buttons.fit, s.listOpen || s.atFit); + }, + }); + var memo = {}; + var view = { + layer: layer, avail: 0, row: 1104, contain: 480, memo: memo, + onMeasured: function (measured, f) { + stage.setAttribute('data-layout', measured.dyn.layout || ''); + if (keyBox) { keyBox.setAttribute('data-layout', measured.dyn.layout || ''); keyBox.toggleAttribute('data-bare', Boolean(measured.dyn.bare)); } + bare = Boolean(measured.dyn.bare); + toggle.hidden = bare; + showList(listOpen || bare); + zoom.size(f.offsetWidth, f.offsetHeight); + }, + }; + function readStage() { + view.avail = Math.max(0, Math.floor(stage.clientWidth - 2 * (parseFloat(getComputedStyle(sizer).paddingLeft) || 0))); + view.row = d.querySelector('[data-probe="row"]').offsetWidth || 1104; + view.contain = d.querySelector('[data-probe="contain"]').offsetWidth || 480; + } + function showList(open) { + if (open && !list) { + list = document.createElement('div'); + list.className = 'diagram-list diagram-viewer-list'; + list.innerHTML = kit.figureList('diagram', model).map(function (v) { return kit.toHtml(v); }).join(''); + stage.appendChild(list); + } + if (list) list.hidden = !open; + sizer.hidden = open; + zoom.list(open); + } + toggle.addEventListener('click', function () { + listOpen = !listOpen; + toggle.setAttribute('aria-expanded', String(listOpen)); + toggle.firstElementChild.textContent = listOpen ? 'Hide the list' : 'View as list'; + showList(listOpen || bare); + }); + buttons.out.addEventListener('click', function () { if (!buttons.out.hasAttribute('aria-disabled')) zoom.zoomOut(); }); + buttons.in.addEventListener('click', function () { if (!buttons.in.hasAttribute('aria-disabled')) zoom.zoomIn(); }); + buttons.fit.addEventListener('click', function () { if (!buttons.fit.hasAttribute('aria-disabled')) zoom.fit(); }); + stage.addEventListener('focusin', function (e) { + var node = e.target.closest && e.target.closest('.diagram-node'); + if (node && stage.contains(node)) revealIn(stage, node, px(stage, '--_clear') || 16); + }); + + B.openDialog(d, opener); + readStage(); + kit.draw(fig, still, false, view); + // Focus opens on the stage, so the zoom keys and the scrolling keys work at once and no card is traced (9.8). + setTimeout(function () { stage.focus({ preventScroll: true }); }, 0); + var width = stage.clientWidth; + var observer = new ResizeObserver(function () { + if (Math.abs(stage.clientWidth - width) < 0.5) return; + width = stage.clientWidth; + readStage(); + if (fig.__diagram) fig.__diagram.layout(); + }); + observer.observe(stage); + page.setAttribute('data-viewing', ''); + if (ctx.animated) ctx.settle(); + d.addEventListener('close', function () { + observer.disconnect(); + zoom.destroy(); + if (fig.__diagram) fig.__diagram.stop(); + page.removeAttribute('data-viewing'); + // The dialog leaves on its own motion, then goes. + setTimeout(function () { d.remove(); }, px(d, '--_dur') * 0.75 || 300); + }); + } + + /** Puts "Expand" after "View as list" in a figure's foot. Returns what the diagram module calls when it draws the figure again. */ + _.diagramZoom = function (page, spec, ctx) { + var foot = page.querySelector(':scope > .diagram-foot'); + if (!foot) return null; + var old = foot.querySelector('.diagram-expand'); + if (old) old.remove(); + var button = document.createElement('button'); + button.type = 'button'; + button.className = 'btn diagram-expand'; + button.setAttribute('data-variant', 'secondary'); + button.setAttribute('data-size', 'sm'); + button.setAttribute('aria-haspopup', 'dialog'); + button.innerHTML = _.icon('ArrowsOutSimple', { size: 16 }) + 'Expand'; + var toggle = foot.querySelector('.diagram-toggle'); + if (toggle && toggle.nextSibling) foot.insertBefore(button, toggle.nextSibling); else foot.appendChild(button); + var onClick = function () { openViewer(page, spec, ctx, button); }; + button.addEventListener('click', onClick); + return { destroy: function () { button.removeEventListener('click', onClick); button.remove(); } }; + }; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index d44efada..6f9e8323 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -4,7 +4,7 @@ and draw the same pixels. compose.mjs runs `Basalt._.diagramMarkup` at build time and writes each figure's words into the page, so it reads before any script runs; this script then measures it, draws its lines and labels, and wires the keys, the trace and the list. Source: tools/html-skill/src/modules/diagram.js (do not edit the copy in the skill folder). */ -import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops, hintEntries, keyTarget, measureFigure, moveStop, settleEntrance, syncAttributes, toHtml } from "../../../../packages/react/src/diagram-core.ts"; +import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, measureViewerFigure, moveStop, settleEntrance, syncAttributes, toHtml } from "../../../../packages/react/src/diagram-core.ts"; (function (B) { 'use strict'; @@ -12,8 +12,8 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops var P = 'diagram'; var serial = 0; - function options(base, spec) { - return { prefix: P, base: base, hasSource: spec.source !== undefined && spec.source !== null && spec.source !== '', hiddenClass: 'visually-hidden' }; + function options(base, spec, viewer) { + return { prefix: P, base: base, hasSource: spec.source !== undefined && spec.source !== null && spec.source !== '', hiddenClass: 'visually-hidden', viewer: Boolean(viewer) }; } function slots(model, spec, base, open) { var kbd = function (k) { return '' + escapeHtml(k) + ''; }; @@ -26,9 +26,9 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops } /** The figure's markup before script runs: its attributes and its inside, as compose.mjs writes it (and as this script writes it for a figure that has none). */ - function markup(spec, base) { + function markup(spec, base, viewer) { var model = buildModel(spec); - var tree = figureTree(model, {}, options(base, spec)); + var tree = figureTree(model, {}, options(base, spec, viewer)); var html = toHtml(tree, slots(model, spec, base, false)); var open = html.indexOf('>'); return { open: html.slice(0, open + 1), inner: html.slice(open + 1, html.length - '
'.length), warnings: model.warnings }; @@ -43,7 +43,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops * markup, or `Basalt.diagram(figure, spec)` drawing new data into one that has some) the markup is written from the spec first, so the * words, the list and the sentences are the new data's. */ - function draw(figure, spec, attach) { + function draw(figure, spec, attach, viewer) { if (figure.__diagram) figure.__diagram.stop(); var base = (figure.getAttribute('aria-labelledby') || '').replace(/-title$/, '').replace(/[^A-Za-z0-9_-]/g, ''); var model = buildModel(spec); @@ -53,7 +53,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops while (document.getElementById('dg' + (++serial) + '-title')) { /* the next free base */ } base = 'dg' + serial; } - var made = markup(spec, base); + var made = markup(spec, base, viewer); var holder = document.createElement('div'); holder.innerHTML = made.open + ''; var fresh = holder.firstChild; @@ -69,7 +69,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops figure.insertAdjacentHTML('beforeend', made.inner); } model.warnings.forEach(function (w) { console.warn('Basalt diagram: ' + w); }); - var opts = options(base, spec); + var opts = options(base, spec, viewer); var state = {}; var measured = null; var focusTrace = null, hoverTrace = null; @@ -80,7 +80,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops var toggle = figure.querySelector('.diagram-toggle'); // Motion (DECISIONS 292) is the diagram-motion module's: compose.mjs adds it to a page whose diagram says "motion": "animated". Without it the // figure is as still. `drawn` is the ink last written, so a measure that draws the same lines writes nothing. - var animated = model.motion.animated && typeof _.diagramMotion === 'function'; + var animated = !viewer && model.motion.animated && typeof _.diagramMotion === 'function'; var motion = null, drawn = null; var settle = function () { if (animated) settleEntrance(figure); }; @@ -92,7 +92,8 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops toggle.firstElementChild.textContent = state.open ? 'Hide the list' : 'View as list'; } function layout() { - measured = measureFigure(figure, model, P, base, state, apply, warn); + // The viewer's figure (DECISIONS 310, the diagram-zoom module) is laid out at the stage's width and measured only at 100%. + measured = viewer ? measureViewerFigure(figure, model, P, base, state, apply, warn, viewer) : measureFigure(figure, model, P, base, state, apply, warn); state = measured.dyn; apply(state); syncToggle(); @@ -103,6 +104,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops retrace(); // In the frame an animated figure's lines are first drawn it is pending; after that the motion module follows a drawing that changed. if (animated && measured.tokens) { entranceDrawn(figure, Boolean(measured.geo && measured.geo.lines.length)); if (fresh && motion) motion.redrawn(); } + if (viewer && viewer.onMeasured) viewer.onMeasured(measured, figure); } function setState(next) { state = next; apply(state); } // A move of the roving stop touches the two nodes it moves between, not the whole figure. @@ -113,7 +115,8 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops var node = nodeOf(event.target); if (!node || event.defaultPrevented) return; settle(); - if (event.key === 'Escape') { if (focusTrace || hoverTrace) { event.preventDefault(); focusTrace = hoverTrace = null; retrace(); } return; } + // In the viewer Esc always closes the dialog, traced or not (DECISIONS 310, 9.8). + if (event.key === 'Escape') { if (!viewer && (focusTrace || hoverTrace)) { event.preventDefault(); focusTrace = hoverTrace = null; retrace(); } return; } if (!hasStops(model, state)) return; var to = keyTarget(model, node.getAttribute('data-node'), event.key); if (!to) return; @@ -174,8 +177,11 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops var marks = model.nodes.some(function (n) { return n.mark; }); if (marks) forced.addEventListener('change', layout); if (animated) motion = _.diagramMotion(figure, { fig: figure, P: P, base: base, model: function () { return model; }, geo: function () { return measured && measured.geo; }, tokens: function () { return measured && measured.tokens; } }, spec); + // "Expand" and the viewer (DECISIONS 310) are the diagram-zoom module's: compose.mjs adds it to a page unless every figure on it says "zoom": false. + var zoom = !viewer && spec.zoom !== false && typeof _.diagramZoom === 'function' ? _.diagramZoom(figure, spec, { model: model, settle: settle, animated: animated }) : null; figure.__diagram = { stop: function () { + if (zoom) zoom.destroy(); live = false; observer.disconnect(); cancelAnimationFrame(frame); if (marks) forced.removeEventListener('change', layout); if (motion) motion.destroy(); @@ -207,6 +213,8 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureTree, hasStops } _.diagramMarkup = markup; + // What the viewer (the diagram-zoom module) draws with: this module's engine, so that module holds no second copy of it. + _.diagramKit = { draw: draw, buildModel: buildModel, figureKey: figureKey, figureList: figureList, hintEntries: hintEntries, toHtml: toHtml, escapeHtml: escapeHtml, settleEntrance: settleEntrance }; B.diagram = function (figure, spec) { var d = figure.__diagram; var key = d && d.send ? sendless(spec) : null; diff --git a/tools/html-skill/src/usage/diagram-zoom.md b/tools/html-skill/src/usage/diagram-zoom.md new file mode 100644 index 00000000..a6355aee --- /dev/null +++ b/tools/html-skill/src/usage/diagram-zoom.md @@ -0,0 +1,8 @@ +# diagram-zoom + +Added for you on a page with a diagram (with `dialog`, `dialog-form` and `sheet`), unless every figure's JSON says `"zoom": false`. + +- **Expand:** in the figure's foot after "View as list", once script runs. It opens the viewer: the drawn layout in a dialog (the window less 16px from 720, the whole window under it), even where the page shows the stack. +- **Zoom:** it opens at Fit (the whole drawing, 200% at most). "Zoom out", "Zoom in" and "Fit" in the foot; `+`, `-` and `0` with focus in the stage; Ctrl or Command with the wheel, a trackpad pinch and two fingers zoom about the pointer. From Fit or 100% to 400%. +- **Pan:** the stage scrolls both ways; a drag, one finger, the wheel or the arrow keys. A trace works; nothing animates. Esc closes it. +- Don't build a viewer of your own, and don't scale a figure on the page. From a66e86f6280e5b3689281bb3b5980c20cd843ff2 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:11:39 -0600 Subject: [PATCH 03/62] The viewer on a native dialog, Expand in words, and its layout in the lazy chunk Base UI's dialog in the viewer's chunk widened the Base UI chunk every component's bundle shares under esbuild's splitting (Button alone 19,482 bytes against a limit of 17,650; 33 limits failed). The viewer is now the form dialog's box on a native modal , as the skill's is: the same classes, motion, scrim, Esc, Tab wrap, scroll lock and focus return. A deviation from 9.2, accepted by the lead as engineering. "Expand" is words only (a deviation from 9.1, the lead's call): Phosphor's ArrowsOutSimple carried six weights, 2.2 KB in every still figure, and the core set draws no expand glyph. The viewer's layout (measureViewerFigure), its hint and its keys words move from the engine into diagram-zoom-core, which only the viewer's chunk and the skill's diagram-zoom module hold. A still diagram is now 70,415 bytes against 67,580 recorded (+2,835; the 5% limit is 70,959). Co-Authored-By: Claude Opus 5.5 --- .../skills/basalt-html/parts/diagram-zoom.css | 2 +- .../skills/basalt-html/parts/diagram-zoom.js | 2 +- .agent/skills/basalt-html/parts/diagram.js | 4 +- .agent/skills/basalt-html/parts/icons.json | 2 +- .agent/skills/basalt-html/parts/manifest.json | 3 - packages/react/src/diagram-core.ts | 69 +----------- packages/react/src/diagram-figure.tsx | 32 ++---- packages/react/src/diagram-viewer.tsx | 104 ++++++++++++++---- packages/react/src/diagram-zoom-core.ts | 72 ++++++++++++ packages/react/src/styles/components.css | 43 +++++++- tools/html-skill/src/icons.json | 2 +- tools/html-skill/src/modules.json | 3 - tools/html-skill/src/modules/diagram-zoom.js | 10 +- tools/html-skill/src/modules/diagram.js | 8 +- 14 files changed, 229 insertions(+), 127 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.css b/.agent/skills/basalt-html/parts/diagram-zoom.css index 07bcc2e5..c566e4f0 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.css +++ b/.agent/skills/basalt-html/parts/diagram-zoom.css @@ -1 +1 @@ -@layer basalt{.diagram-expand>.icon{flex:none}@media(pointer:coarse){.diagram-expand{min-height:var(--basalt-size-tap-min)}}@media(width>=720px){.dialog[data-form].diagram-viewer,.dialog[data-form][data-held].diagram-viewer{width:calc(100vw - 2 * var(--basalt-space-4));max-width:none;height:calc(100dvh - 2 * var(--basalt-space-4));max-height:none}}.diagram-viewer .sheet-head{flex:none}.diagram-viewer-source{overflow-wrap:break-word}.diagram-stage{--_pad: var(--basalt-space-4);--_travel: var(--basalt-space-1);--_clear: var(--basalt-space-4);--_rest: var(--basalt-duration-slower);position:relative;flex:1 1 auto;display:flex;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;touch-action:none;outline:none}@media(width>=720px){.diagram-stage{--_pad: var(--basalt-space-6)}}.diagram-stage:focus-visible{outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:calc(-1 * var(--basalt-size-focus-width))}.diagram-stage[data-pannable]{cursor:grab}.diagram-stage[data-pannable][data-dragging]{cursor:grabbing}.diagram-stage[data-list]{display:block;touch-action:pan-y}.diagram-probe{position:absolute;top:0;left:0;height:0;visibility:hidden;pointer-events:none}.diagram-probe[data-probe=row]{width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter))}.diagram-probe[data-probe=contain]{width:var(--basalt-size-breakpoint-container)}.diagram-sizer{position:relative;flex:none;box-sizing:content-box;margin:auto;padding:var(--_pad)}.diagram-sizer[hidden]{display:none}.diagram-layer{position:absolute;top:var(--_pad);inset-inline-start:var(--_pad);transform-origin:0 0;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}.diagram-layer:dir(rtl){transform-origin:100% 0}.diagram[data-viewer]{gap:0}.diagram[data-viewer]>:is(.diagram-head,.diagram-key,.diagram-hint,.diagram-foot,.diagram-list,.diagram-summary){display:none}.diagram-viewer-list{box-sizing:border-box;max-width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter) + 2 * var(--_pad));padding:var(--_pad)}.diagram-viewer-foot{display:flex;flex-direction:column;gap:var(--basalt-space-3);padding-block-start:var(--basalt-space-3)}.diagram-viewer-key{--_ground: var(--panel-bg, var(--basalt-surface-overlay))}.diagram-viewer-key .diagram-key{padding-block-start:0;border-top:0}.diagram-viewer-key[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram-viewer-key[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram-viewer-key[data-bare] .diagram-entry[data-line]{display:none}.diagram-viewer-row{display:flex;flex-wrap:wrap;align-items:center;gap:var(--basalt-space-2)}.diagram-zoom{display:flex;align-items:center;gap:var(--basalt-space-1)}.diagram-level{display:inline-grid;justify-items:center;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans);font-variant-numeric:tabular-nums}.diagram-level:before{content:attr(data-reserve);grid-area:1 / 1;visibility:hidden}.diagram-level>span{grid-area:1 / 1}.diagram-viewer-hint{flex:1 1 auto;min-width:0}.diagram-viewer-end{display:flex;gap:var(--basalt-space-2);margin-inline-start:auto}@media(pointer:coarse){.diagram-zoom .btn,.diagram-viewer-end .btn{min-height:var(--basalt-size-tap-min);min-width:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram-level{color:CanvasText}.diagram-viewer-foot [aria-disabled=true]{color:GrayText}}@media print{.diagram-expand,.diagram-viewer,:root:has(.diagram-viewer) dialog.modal::backdrop{display:none!important}}} +@layer basalt{@media(pointer:coarse){.diagram-expand{min-height:var(--basalt-size-tap-min)}}@media(width>=720px){.dialog[data-form].diagram-viewer,.dialog[data-form][data-held].diagram-viewer{width:calc(100vw - 2 * var(--basalt-space-4));max-width:none;height:calc(100dvh - 2 * var(--basalt-space-4));max-height:none}}.diagram-viewer .sheet-head{flex:none}.diagram-viewer-source{overflow-wrap:break-word}.diagram-stage{--_pad: var(--basalt-space-4);--_travel: var(--basalt-space-1);--_clear: var(--basalt-space-4);--_rest: var(--basalt-duration-slower);position:relative;flex:1 1 auto;display:flex;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;touch-action:none;outline:none}@media(width>=720px){.diagram-stage{--_pad: var(--basalt-space-6)}}.diagram-stage:focus-visible{outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:calc(-1 * var(--basalt-size-focus-width))}.diagram-stage[data-pannable]{cursor:grab}.diagram-stage[data-pannable][data-dragging]{cursor:grabbing}.diagram-stage[data-list]{display:block;touch-action:pan-y}.diagram-probe{position:absolute;top:0;left:0;height:0;visibility:hidden;pointer-events:none}.diagram-probe[data-probe=row]{width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter))}.diagram-probe[data-probe=contain]{width:var(--basalt-size-breakpoint-container)}.diagram-sizer{position:relative;flex:none;box-sizing:content-box;margin:auto;padding:var(--_pad)}.diagram-sizer[hidden]{display:none}.diagram-layer{position:absolute;top:var(--_pad);inset-inline-start:var(--_pad);transform-origin:0 0;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}.diagram-layer:dir(rtl){transform-origin:100% 0}.diagram[data-viewer]{gap:0}.diagram[data-viewer]>:is(.diagram-head,.diagram-key,.diagram-hint,.diagram-foot,.diagram-list,.diagram-summary){display:none}.diagram-viewer-list{box-sizing:border-box;max-width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter) + 2 * var(--_pad));padding:var(--_pad)}.diagram-viewer-foot{display:flex;flex-direction:column;gap:var(--basalt-space-3);padding-block-start:var(--basalt-space-3)}.diagram-viewer-key{--_ground: var(--panel-bg, var(--basalt-surface-overlay))}.diagram-viewer-key .diagram-key{padding-block-start:0;border-top:0}.diagram-viewer-key[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram-viewer-key[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram-viewer-key[data-bare] .diagram-entry[data-line]{display:none}.diagram-viewer-row{display:flex;flex-wrap:wrap;align-items:center;gap:var(--basalt-space-2)}.diagram-zoom{display:flex;align-items:center;gap:var(--basalt-space-1)}.diagram-level{display:inline-grid;justify-items:center;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans);font-variant-numeric:tabular-nums}.diagram-level:before{content:attr(data-reserve);grid-area:1 / 1;visibility:hidden}.diagram-level>span{grid-area:1 / 1}.diagram-viewer-hint{flex:1 1 auto;min-width:0}.diagram-viewer-end{display:flex;gap:var(--basalt-space-2);margin-inline-start:auto}@media(pointer:coarse){.diagram-zoom .btn,.diagram-viewer-end .btn{min-height:var(--basalt-size-tap-min);min-width:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram-level{color:CanvasText}.diagram-viewer-foot [aria-disabled=true]{color:GrayText}}@media print{.diagram-expand,.diagram-viewer{display:none!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.js b/.agent/skills/basalt-html/parts/diagram-zoom.js index 88b3232e..b03fd9eb 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.js +++ b/.agent/skills/basalt-html/parts/diagram-zoom.js @@ -1 +1 @@ -(()=>{var N=[25,33,50,67,75,100,125,150,200,300,400],j=4,V=2,tt=100,$=25,Y=5e-4;function et(m){const{stage:e,sizer:L,layer:g,status:h}=m;let p=0,k=0,i=1,l=1,b=!1,s=!1,f=null,d="",x=0;const S=()=>Number.parseFloat(getComputedStyle(L).paddingTop)||0,F=()=>Math.min(l,1),P=t=>Math.min(j,Math.max(F(),t));function r(){if(!p||!k)return 1;const t=S(),a=e.clientWidth-2*t,c=e.clientHeight-2*t;if(a<=0||c<=0)return Math.min(1,V);const E=Math.min(a/p,c/k);return Math.min(V,Math.floor(E*100+1e-6)/100)}function u(){const t=F();return{zoom:i,level:Math.round(i*100),fit:l,min:t,max:j,atMin:i<=t+Y,atMax:i>=j-Y,atFit:Math.abs(i-l)e.clientWidth-2*S()+.5||k*i>e.clientHeight-2*S()+.5)}function q(){clearTimeout(x);const t=`Zoom ${Math.round(i*100)}%`;x=window.setTimeout(()=>{t!==d&&(d=t,h.textContent=t)},m.rest)}function v(){L.style.width=`${p*i}px`,L.style.height=`${k*i}px`,g.style.transform=`scale(${i})`}function D(t){const a=g.getBoundingClientRect();return{x:(t.x-a.left)/i,y:(t.y-a.top)/i}}function K(t,a){const c=g.getBoundingClientRect();e.scrollLeft+=c.left+t.x*i-a.x,e.scrollTop+=c.top+t.y*i-a.y}const A=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function B(t,a=A(),c){if(s)return;const E=P(t);if(Math.abs(E-i)<1e-6){z();return}const at=c??D(a);i=E,v(),K(at,a),z(),q()}function y(t){b=!0;const a=i*100,c=t?N.find(E=>E>a+.5):[...N].reverse().find(E=>ENumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,n=()=>{const[t,a]=[...o.values()];return{x:(t.x+a.x)/2,y:(t.y+a.y)/2}},w=()=>{const[t,a]=[...o.values()];return Math.hypot(t.x-a.x,t.y-a.y)};function U(t){if(!s&&!(t.pointerType==="mouse"&&t.button!==0)&&(o.set(t.pointerId,{x:t.clientX,y:t.clientY}),o.size===1&&(T={x:t.clientX,y:t.clientY},M=T,_=!1,H=!1),o.size===2&&t.pointerType==="touch")){const a=n();W={d0:w()||1,z0:i,c:D(a)},H=!0,_=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function G(t){if(!o.has(t.pointerId)||s)return;if(o.set(t.pointerId,{x:t.clientX,y:t.clientY}),W&&o.size>=2){b=!0;const c=P(W.z0*(w()/W.d0)),E=n();Math.abs(c-i)>1e-6&&(i=c,v(),z(),q()),K(W.c,E);return}if(o.size!==1||!T||!M)return;const a={x:t.clientX,y:t.clientY};if(!_){if(Math.hypot(a.x-T.x,a.y-T.y)<=R())return;_=!0,H=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=a.x-M.x,e.scrollTop-=a.y-M.y,M=a,t.preventDefault()}function X(t){if(o.has(t.pointerId)){if(o.delete(t.pointerId),o.size<2&&(W=null),o.size===1){const[a]=[...o.values()];M=a,T=a,_=!0;return}o.size===0&&(_=!1,e.removeAttribute("data-dragging"),T=M=null)}}function J(t){H&&(H=!1,t.preventDefault(),t.stopPropagation())}const Q=new ResizeObserver(()=>{if(!p||!k)return;const t=b?D(A()):null;l=r(),b?(i=P(i),v(),t&&K(t,A())):(i=l,v()),z()});return Q.observe(e),e.addEventListener("wheel",I,{passive:!1}),e.addEventListener("keydown",Z),e.addEventListener("pointerdown",U),e.addEventListener("pointermove",G),e.addEventListener("pointerup",X),e.addEventListener("pointercancel",X),e.addEventListener("click",J,!0),{size:O,zoomIn:()=>y(!0),zoomOut:()=>y(!1),fit:C,state:u,list(t){t!==s&&(t?(f={left:e.scrollLeft,top:e.scrollTop},s=!0,e.setAttribute("data-list",""),e.scrollTop=0):(s=!1,e.removeAttribute("data-list"),v(),f&&(e.scrollLeft=f.left,e.scrollTop=f.top),f=null),z())},travelled:()=>H,destroy(){clearTimeout(x),Q.disconnect(),e.removeEventListener("wheel",I),e.removeEventListener("keydown",Z),e.removeEventListener("pointerdown",U),e.removeEventListener("pointermove",G),e.removeEventListener("pointerup",X),e.removeEventListener("pointercancel",X),e.removeEventListener("click",J,!0)}}}function it(m,e,L){const g=m.getBoundingClientRect(),h=e.getBoundingClientRect(),p=g.left+L,k=g.left+m.clientWidth-L,i=g.top+L,l=g.top+m.clientHeight-L;h.leftk&&(m.scrollLeft+=Math.min(h.right-k,h.left-p)),h.topl&&(m.scrollTop+=Math.min(h.bottom-l,h.top-i))}(function(m){"use strict";var e=m._,L=0;function g(i){return e.diagramKit.escapeHtml(String(i??""))}function h(i){return''+g(i)+""}function p(i,l){return parseFloat(getComputedStyle(i).getPropertyValue(l))||0}function k(i,l,b,s){var f=e.diagramKit,d=Object.assign({},l,{motion:"still"}),x=f.buildModel(d),S="dgv"+ ++L,F=f.figureKey("diagram",x),P=f.hintEntries(x,!0).map(function(n){return""+n.keys.map(h).join(" ")+" "+g(n.words)+""}).join(""),r=document.createElement("dialog");r.className="panel float modal dialog diagram-viewer",r.setAttribute("data-form",""),r.setAttribute("aria-describedby",S+"-summary"),r.innerHTML='

'+g(x.title)+"

"+(l.source?'

'+g(l.source)+"

":"")+'

'+g(l.summary)+'

'+(F?'
'+f.toHtml(F)+"
":"")+'
',document.body.appendChild(r);var u=r.querySelector(".diagram-stage"),z=r.querySelector(".diagram-sizer"),q=r.querySelector(".diagram-layer"),v=q.firstChild,D=r.querySelector('[role="status"]'),K=r.querySelector(".diagram-level > span"),A=r.querySelector(".diagram-viewer-key"),B=r.querySelector(".diagram-toggle"),y={out:r.querySelector('[data-zoom="out"]'),in:r.querySelector('[data-zoom="in"]'),fit:r.querySelector('[data-zoom="fit"]')},C=null,O=!1,I=!1,Z=function(n,w){w?n.setAttribute("aria-disabled","true"):n.removeAttribute("aria-disabled")},o=et({stage:u,sizer:z,layer:q,status:D,rest:p(u,"--_rest")||300,onChange:function(n){K.textContent=n.level+"%",Z(y.out,n.listOpen||n.atMin),Z(y.in,n.listOpen||n.atMax),Z(y.fit,n.listOpen||n.atFit)}}),T={},M={layer:q,avail:0,row:1104,contain:480,memo:T,onMeasured:function(n,w){u.setAttribute("data-layout",n.dyn.layout||""),A&&(A.setAttribute("data-layout",n.dyn.layout||""),A.toggleAttribute("data-bare",!!n.dyn.bare)),I=!!n.dyn.bare,B.hidden=I,H(O||I),o.size(w.offsetWidth,w.offsetHeight)}};function _(){M.avail=Math.max(0,Math.floor(u.clientWidth-2*(parseFloat(getComputedStyle(z).paddingLeft)||0))),M.row=r.querySelector('[data-probe="row"]').offsetWidth||1104,M.contain=r.querySelector('[data-probe="contain"]').offsetWidth||480}function H(n){n&&!C&&(C=document.createElement("div"),C.className="diagram-list diagram-viewer-list",C.innerHTML=f.figureList("diagram",x).map(function(w){return f.toHtml(w)}).join(""),u.appendChild(C)),C&&(C.hidden=!n),z.hidden=n,o.list(n)}B.addEventListener("click",function(){O=!O,B.setAttribute("aria-expanded",String(O)),B.firstElementChild.textContent=O?"Hide the list":"View as list",H(O||I)}),y.out.addEventListener("click",function(){y.out.hasAttribute("aria-disabled")||o.zoomOut()}),y.in.addEventListener("click",function(){y.in.hasAttribute("aria-disabled")||o.zoomIn()}),y.fit.addEventListener("click",function(){y.fit.hasAttribute("aria-disabled")||o.fit()}),u.addEventListener("focusin",function(n){var w=n.target.closest&&n.target.closest(".diagram-node");w&&u.contains(w)&&it(u,w,p(u,"--_clear")||16)}),m.openDialog(r,s),_(),f.draw(v,d,!1,M),setTimeout(function(){u.focus({preventScroll:!0})},0);var W=u.clientWidth,R=new ResizeObserver(function(){Math.abs(u.clientWidth-W)<.5||(W=u.clientWidth,_(),v.__diagram&&v.__diagram.layout())});R.observe(u),i.setAttribute("data-viewing",""),b.animated&&b.settle(),r.addEventListener("close",function(){R.disconnect(),o.destroy(),v.__diagram&&v.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){r.remove()},p(r,"--_dur")*.75||300)})}e.diagramZoom=function(i,l,b){var s=i.querySelector(":scope > .diagram-foot");if(!s)return null;var f=s.querySelector(".diagram-expand");f&&f.remove();var d=document.createElement("button");d.type="button",d.className="btn diagram-expand",d.setAttribute("data-variant","secondary"),d.setAttribute("data-size","sm"),d.setAttribute("aria-haspopup","dialog"),d.innerHTML=e.icon("ArrowsOutSimple",{size:16})+"Expand";var x=s.querySelector(".diagram-toggle");x&&x.nextSibling?s.insertBefore(d,x.nextSibling):s.appendChild(d);var S=function(){k(i,l,b,d)};return d.addEventListener("click",S),{destroy:function(){d.removeEventListener("click",S),d.remove()}}}})(window.Basalt)})(); +(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(b=>b.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:b,layer:m,status:x}=l;let c=0,M=0,i=1,n=1,u=!1,s=!1,p=null,h="",z=0;const g=()=>Number.parseFloat(getComputedStyle(b).paddingTop)||0,S=()=>Math.min(n,1),T=t=>Math.min(j,Math.max(S(),t));function o(){if(!c||!M)return 1;const t=g(),a=e.clientWidth-2*t,k=e.clientHeight-2*t;if(a<=0||k<=0)return Math.min(1,J);const W=Math.min(a/c,k/M);return Math.min(J,Math.floor(W*100+1e-6)/100)}function y(){const t=S();return{zoom:i,level:Math.round(i*100),fit:n,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-n)e.clientWidth-2*g()+.5||M*i>e.clientHeight-2*g()+.5)}function v(){clearTimeout(z);const t=`Zoom ${Math.round(i*100)}%`;z=window.setTimeout(()=>{t!==h&&(h=t,x.textContent=t)},l.rest)}function w(){b.style.width=`${c*i}px`,b.style.height=`${M*i}px`,m.style.transform=`scale(${i})`}function D(t){const a=m.getBoundingClientRect();return{x:(t.x-a.left)/i,y:(t.y-a.top)/i}}function R(t,a){const k=m.getBoundingClientRect();e.scrollLeft+=k.left+t.x*i-a.x,e.scrollTop+=k.top+t.y*i-a.y}const _=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function I(t,a=_(),k){if(s)return;const W=T(t);if(Math.abs(W-i)<1e-6){f();return}const ot=k??D(a);i=W,w(),R(ot,a),f(),v()}function L(t){u=!0;const a=i*100,k=t?G.find(W=>W>a+.5):[...G].reverse().find(W=>WNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,r=()=>{const[t,a]=[...d.values()];return{x:(t.x+a.x)/2,y:(t.y+a.y)/2}},E=()=>{const[t,a]=[...d.values()];return Math.hypot(t.x-a.x,t.y-a.y)};function V(t){if(!s&&!(t.pointerType==="mouse"&&t.button!==0)&&(d.set(t.pointerId,{x:t.clientX,y:t.clientY}),d.size===1&&(H={x:t.clientX,y:t.clientY},C=H,q=!1,O=!1),d.size===2&&t.pointerType==="touch")){const a=r();F={d0:E()||1,z0:i,c:D(a)},O=!0,q=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function Y(t){if(!d.has(t.pointerId)||s)return;if(d.set(t.pointerId,{x:t.clientX,y:t.clientY}),F&&d.size>=2){u=!0;const k=T(F.z0*(E()/F.d0)),W=r();Math.abs(k-i)>1e-6&&(i=k,w(),f(),v()),R(F.c,W);return}if(d.size!==1||!H||!C)return;const a={x:t.clientX,y:t.clientY};if(!q){if(Math.hypot(a.x-H.x,a.y-H.y)<=P())return;q=!0,O=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=a.x-C.x,e.scrollTop-=a.y-C.y,C=a,t.preventDefault()}function Z(t){if(d.has(t.pointerId)){if(d.delete(t.pointerId),d.size<2&&(F=null),d.size===1){const[a]=[...d.values()];C=a,H=a,q=!0;return}d.size===0&&(q=!1,e.removeAttribute("data-dragging"),H=C=null)}}function X(t){O&&(O=!1,t.preventDefault(),t.stopPropagation())}const N=new ResizeObserver(()=>{if(!c||!M)return;const t=u?D(_()):null;n=o(),u?(i=T(i),w(),t&&R(t,_())):(i=n,w()),f()});return N.observe(e),e.addEventListener("wheel",K,{passive:!1}),e.addEventListener("keydown",$),e.addEventListener("pointerdown",V),e.addEventListener("pointermove",Y),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",X,!0),{size:B,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:A,state:y,list(t){t!==s&&(t?(p={left:e.scrollLeft,top:e.scrollTop},s=!0,e.setAttribute("data-list",""),e.scrollTop=0):(s=!1,e.removeAttribute("data-list"),w(),p&&(e.scrollLeft=p.left,e.scrollTop=p.top),p=null),f())},travelled:()=>O,destroy(){clearTimeout(z),N.disconnect(),e.removeEventListener("wheel",K),e.removeEventListener("keydown",$),e.removeEventListener("pointerdown",V),e.removeEventListener("pointermove",Y),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",X,!0)}}}function nt(l,e,b){const m=l.getBoundingClientRect(),x=e.getBoundingClientRect(),c=m.left+b,M=m.left+l.clientWidth-b,i=m.top+b,n=m.top+l.clientHeight-b;x.leftM&&(l.scrollLeft+=Math.min(x.right-M,x.left-c)),x.topn&&(l.scrollTop+=Math.min(x.bottom-n,x.top-i))}function rt(l,e,b,m,x,c,M,i){const{layer:n,memo:u,measureFigure:s}=i;u.model!==e&&(u.model=e,u.least=void 0);const p=S=>{n.style.width=`${Math.max(u.least||S,Math.min(i.avail,i.row))}px`};n.style.width||(n.style.width=`${Math.min(i.avail,i.row)}px`);const h=n.style.transform;n.style.transform="none";const z=n.offsetWidth?n.getBoundingClientRect().width/n.offsetWidth:1;Math.abs(z-1)>1e-4&&(n.style.transform=`scale(${1/z})`);let g=s(l,e,b,m,x,c,u.least===void 0?void 0:M,p);if(g.dyn.layout==="stacked"&&u.least===void 0&&g.least!==void 0){const S=g.dyn,T=v=>{n.style.width=`${v}px`;const w=s(l,e,b,m,S,c);return w.dyn.layout==="drawn"?s(l,e,b,m,w.dyn,c):w},o=Math.max(g.least,Math.min(i.avail,i.row)),y=Math.max(i.row,o)*1.5;let f;for(let v=o+16;v<=y&&f===void 0;v+=16)T(v).dyn.layout==="drawn"&&(f=v);if(f!==void 0){for(let v=f-15;vi.contain&&(n.style.width=`${i.contain}px`,g=s(l,e,b,m,g.dyn,c,M)),n.style.transform=h,g}(function(l){"use strict";var e=l._,b=0;function m(i){return e.diagramKit.escapeHtml(String(i??""))}function x(i){return''+m(i)+""}function c(i,n){return parseFloat(getComputedStyle(i).getPropertyValue(n))||0}function M(i,n,u,s){var p=e.diagramKit,h=Object.assign({},n,{motion:"still"}),z=p.buildModel(h),g="dgv"+ ++b,S=p.figureKey("diagram",z),T=et(p.hintEntries(z)).map(function(r){return""+r.keys.map(x).join(" ")+" "+m(r.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",g+"-summary"),o.innerHTML='

'+m(z.title)+"

"+(n.source?'

'+m(n.source)+"

":"")+'

'+m(n.summary)+'

'+(S?'
'+p.toHtml(S)+"
":"")+'
',document.body.appendChild(o);var y=o.querySelector(".diagram-stage"),f=o.querySelector(".diagram-sizer"),v=o.querySelector(".diagram-layer"),w=v.firstChild,D=o.querySelector('[role="status"]'),R=o.querySelector(".diagram-level > span"),_=o.querySelector(".diagram-viewer-key"),I=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},A=null,B=!1,K=!1,$=function(r,E){E?r.setAttribute("aria-disabled","true"):r.removeAttribute("aria-disabled")},d=at({stage:y,sizer:f,layer:v,status:D,rest:c(y,"--_rest")||300,onChange:function(r){R.textContent=r.level+"%",$(L.out,r.listOpen||r.atMin),$(L.in,r.listOpen||r.atMax),$(L.fit,r.listOpen||r.atFit)}}),H={},C={layer:v,avail:0,row:1104,contain:480,memo:H,measureFigure:p.measureFigure,keys:tt,measure:function(r,E,V,Y,Z,X,N){return rt(r,E,V,Y,Z,X,N,C)},onMeasured:function(r,E){y.setAttribute("data-layout",r.dyn.layout||""),_&&(_.setAttribute("data-layout",r.dyn.layout||""),_.toggleAttribute("data-bare",!!r.dyn.bare)),K=!!r.dyn.bare,I.hidden=K,O(B||K),d.size(E.offsetWidth,E.offsetHeight)}};function q(){C.avail=Math.max(0,Math.floor(y.clientWidth-2*(parseFloat(getComputedStyle(f).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function O(r){r&&!A&&(A=document.createElement("div"),A.className="diagram-list diagram-viewer-list",A.innerHTML=p.figureList("diagram",z).map(function(E){return p.toHtml(E)}).join(""),y.appendChild(A)),A&&(A.hidden=!r),f.hidden=r,d.list(r)}I.addEventListener("click",function(){B=!B,I.setAttribute("aria-expanded",String(B)),I.firstElementChild.textContent=B?"Hide the list":"View as list",O(B||K)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||d.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||d.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||d.fit()}),y.addEventListener("focusin",function(r){var E=r.target.closest&&r.target.closest(".diagram-node");E&&y.contains(E)&&nt(y,E,c(y,"--_clear")||16)}),l.openDialog(o,s),q(),p.draw(w,h,!1,C),setTimeout(function(){y.focus({preventScroll:!0})},0);var F=y.clientWidth,P=new ResizeObserver(function(){Math.abs(y.clientWidth-F)<.5||(F=y.clientWidth,q(),w.__diagram&&w.__diagram.layout())});P.observe(y),i.setAttribute("data-viewing",""),u.animated&&u.settle(),o.addEventListener("close",function(){P.disconnect(),d.destroy(),w.__diagram&&w.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},c(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,n,u){var s=i.querySelector(":scope > .diagram-foot");if(!s)return null;var p=s.querySelector(".diagram-expand");p&&p.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var z=s.querySelector(".diagram-toggle");z&&z.nextSibling?s.insertBefore(h,z.nextSibling):s.appendChild(h);var g=function(){M(i,n,u,h)};return h.addEventListener("click",g),{destroy:function(){h.removeEventListener("click",g),h.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index f3a55524..5d01946c 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,2 +1,2 @@ -(()=>{var he=["top","right","bottom","left"],pe=["main","plain","dashed"],ge=[2,3,4,5,6],rt=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),pt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function St(t,e={}){const s=e.checks!==!1,r=[],o=d=>{r.push(d)},a=t.legend??{},i={};for(const d of["main","plain","dashed","focal","group"]){const y=rt(a[d]);y&&(i[d]=y)}const f=t.stepLabel,h=typeof f=="function"?d=>String(f(d)):typeof f=="string"?(d=>f.replace("{n}",String(d))):d=>`Step ${d}`,u=t.shapeLabels??{},g={terminal:rt(u.terminal)??"Start or end",step:rt(u.step)??"Step",decision:rt(u.decision)??"Decision"},c=t.heading===void 0?3:ge.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),m=(d,y)=>d==null?"plain":pe.includes(d)?d:(o(`"${String(d)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),b=d=>{if(d!=null){if(he.includes(d))return d;o(`"${String(d)}" is not a side (top, right, bottom or left): the derived side is used`)}},l=(d,y)=>typeof d=="number"&&Number.isInteger(d)&&d>=1?d:(o(`${y} is ${JSON.stringify(d)}, not a whole number from 1: it is placed at 1`),1),p=[],$=[];let q=[];const E=[],B=[],j=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(j)||o(`"${String(j)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),j==="architecture"||j==="flowchart"){for(const d of t.nodes??[]){const y=j==="flowchart"&&d.shape==="decision"?"decision":j==="flowchart"&&d.shape==="terminal"?"terminal":"box",S=String(d.id??""),L=l(d.row,`the row of ${S}`);p.push({id:S,i:p.length,name:String(d.name??""),kind:y==="decision"?void 0:rt(d.kind),detail:y==="decision"?void 0:rt(d.detail),mono:!!d.detailMono,focal:!!d.focal,col:l(d.col,`the column of ${S}`),row:L,row2:L,branch:!!d.branch,shape:y,group:j==="architecture"?rt(d.group):void 0,mark:j==="architecture"?me(d.mark):void 0})}if(j==="architecture")for(const d of t.groups??[]){const y=String(d.id??"");E.push({id:y,label:String(d.label??""),members:p.filter(S=>S.group===y).map(S=>S.id)})}}else if(j==="data-flow"){q=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const d=new Map(q.map((y,S)=>[y.id,S+1]));for(const y of t.nodes??[]){const S=String(y.id??""),L=String(y.lane??""),H=d.get(L);H===void 0&&o(`a node (${S}) names the lane "${L}", which is not in lanes`);const T=p.length+1;p.push({id:S,i:p.length,name:String(y.name??""),kind:h(T),detail:rt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:l(y.col,`the column of ${S}`),row:H??1,row2:H??1,branch:!1,shape:"box",lane:H??1,laneLabel:q[(H??1)-1]?.label??L,step:T})}}else if(j==="sequence"){(t.participants??[]).forEach((y,S)=>{const L=String(y.name??"");p.push({id:String(y.id??""),i:S,name:L,kind:rt(y.kind),mono:!1,focal:!!y.focal,col:S+1,row:1,row2:1,branch:!1,shape:"participant",short:rt(y.short)??L})});let d=0;for(const y of t.steps??[])"band"in y?B.push({band:String(y.band??"")}):(d++,B.push({n:d,from:String(y.from??""),to:String(y.to??""),label:String(y.label??""),note:rt(y.note),kind:m(y.kind,`message ${d}`)}))}else if(j==="schema")for(const d of t.tables??[]){const y=String(d.name??""),[S,L]=Array.isArray(d.row)?d.row:[d.row,d.row],H=l(S,`the row of ${y}`),T=Math.max(H,l(L,`the last row of ${y}`)),G=d.more===void 0||d.more===null?void 0:Number.isInteger(d.more)&&d.more>0?d.more:(o(`${y}'s "more" is ${JSON.stringify(d.more)}, not a whole number from 1: it is left out`),void 0);p.push({id:y,i:p.length,name:y,mono:!0,focal:!!d.focal,col:l(d.col,`the column of ${y}`),row:H,row2:T,branch:!1,shape:"table",more:G,columns:(d.columns??[]).map(W=>({name:String(W.name??""),type:rt(W.type),key:W.key==="PK"||W.key==="FK"?W.key:(W.key!==void 0&&W.key!==null&&o(`${y}.${String(W.name)}'s key is "${String(W.key)}", not PK or FK: it is left out`),void 0)}))})}const R=new Map;for(const d of p)d.id?R.has(d.id)&&o(`the id "${d.id}" is used twice`):o("a node has no id"),R.set(d.id,d);if(j==="schema")(t.tables??[]).forEach(d=>(d.columns??[]).forEach((y,S)=>{const L=rt(y.references);if(!L)return;const[H,T]=L.split("."),G=R.get(H??""),W=G?.columns?.findIndex(C=>C.name===T)??-1;if(!G||W<0){o(`${String(d.name)}.${String(y.name)} references ${L}, which is not a shown column`);return}const k=R.get(String(d.name??""));k.columns[S].ref={table:H,column:T,row:W},$.push({i:$.length,from:k.id,to:H,kind:"plain",fromRow:S,toRow:W,fk:!0})}));else if(j!=="sequence")for(const d of t.edges??[]){const y=String(d.from??""),S=String(d.to??"");if(!R.has(y)||!R.has(S)){o(`a line names ${R.has(y)?S:y}, which is not a node`);continue}const L=rt(d.label);L&&L.length>_t&&o(`the label "${L}" is over ${_t} characters: longer words belong in the node or the summary`),$.push({i:$.length,from:y,to:S,kind:m(d.kind,`the line from ${y} to ${S}`),label:L,fromSide:b(d.fromSide),toSide:b(d.toSide),flow:j!=="flowchart"&&d.flow===!0?!0:void 0})}else for(const d of B)"n"in d&&(!R.has(d.from)||!R.has(d.to))&&o(`message ${d.n} names ${R.has(d.from)?d.to:d.from}, which is not a participant`);if(s&&j!=="sequence"){const d=new Map;for(const y of p)for(let S=y.row;S<=y.row2;S++){const L=`${y.col}:${S}`;d.has(L)&&o(`${y.id} and ${d.get(L)} share the cell at column ${y.col}, row ${S}`),d.set(L,y.id)}}if(s){for(const y of E){const S=y.members.map(T=>R.get(T));if(!S.length)continue;const L={c1:Math.min(...S.map(T=>T.col)),c2:Math.max(...S.map(T=>T.col)),r1:Math.min(...S.map(T=>T.row)),r2:Math.max(...S.map(T=>T.row2))};for(const T of p)T.group!==y.id&&T.col>=L.c1&&T.col<=L.c2&&T.row>=L.r1&&T.row<=L.r2&&o(`${T.id} is inside the box of the group "${y.label}" but not a member`);const H=S.map(T=>T.i);Math.max(...H)-Math.min(...H)+1!==H.length&&o(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of p)y.group&&!E.some(S=>S.id===y.group)&&o(`${y.id} names the group "${y.group}", which is not in groups`);p.filter(y=>y.focal).length>1&&o("more than one node is focal: a diagram has one at most");const d=new Set(j==="sequence"?B.flatMap(y=>"n"in y?[y.kind]:[]):$.map(y=>y.kind));d.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),d.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),p.some(y=>y.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const Q=j==="architecture"||j==="data-flow",A=d=>Array.isArray(d)&&d.length>1?d.map(String):void 0,V=Q&&t.packet&&typeof t.packet=="object"?t.packet:void 0,v=V&&A(V.path),D={animated:t.motion==="animated",pulse:Q?A(t.pulse):void 0,packet:v?{path:v,repeat:V.repeat===!0,send:V.send}:void 0,run:j==="sequence"&&t.run===!0};if(s)for(const d of p){const y=d.mark?.says;if(!y?.length)continue;const S=[d.name,d.kind,d.detail].filter(Boolean).join(" ").toLowerCase();y.some(L=>S.includes(L.toLowerCase()))||o(`${d.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const I=Math.max(1,...p.map(d=>d.col)),w=j==="data-flow"?Math.max(1,q.length):Math.max(1,...p.map(d=>d.row2));return{type:j,title:String(t.title??""),heading:c,legend:i,nodes:p,byId:R,edges:$,groups:E,lanes:q,steps:B,cols:I,rows:w,shapeLabels:g,stepWord:h,warnings:r,motion:D,memo:new Map}}function me(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=rt(e.onLight);if(n)return{onLight:n,onDark:rt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ot=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function xt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var _t=28,mt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Bt(t,e){return t.legend[e]}function ye(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function $e(t,e){return xt(t,`sentence:${e.i}`,()=>be(t,e))}function be(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,r=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(mt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`)}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?ye(t,e):e.kind;if(n.push(mt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(mt(e.detail)),e.group){const a=t.groups.find(i=>i.id===e.group);a&&n.push(`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${a.label})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${a.label})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(mt(t.legend.focal)),n.join(" ")}function Ct(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function x(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var we={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>we[e]),xe=" br img input meta link hr path polygon polyline circle rect line ";function Et(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return xe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Et(s,e)).join("")}`}var ve=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function gt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Me(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function jt(t){let e=0;for(const n of t.groups){const s=n.members.map(r=>t.byId.get(r).col);s.length&&(Math.min(...s)===1&&(e|=1),Math.max(...s)===t.cols&&(e|=2))}return(e&1)+(e>>1&1)}function At(t){return t.type==="sequence"?t.nodes.length:t.cols}function Tt(t){return xt(t,"plan",()=>ke(t))}function ke(t){const e=t.nodes,n=l=>t.type==="data-flow"||!e[l].branch,s=t.edges.map(l=>{const p=t.byId.get(l.from).i,$=t.byId.get(l.to).i,E=e.slice(Math.min(p,$)+1,Math.max(p,$)).every(B=>!n(B.i));return $===p+1&&!(n(p)&&!n($))?"down":$===p-1?"up":$>p&&n(p)&&!n($)&&E?"trunk":$>p&&n(p)&&n($)&&E?"rail":$>p?"end-down":"end-up"}),r=t.edges.map((l,p)=>({e:l,k:p})).filter(({k:l})=>s[l]==="end-down"||s[l]==="end-up"),o=l=>{const p=t.byId.get(l.from).i,$=t.byId.get(l.to).i;return[Math.min(p,$),Math.max(p,$)]},a=(l,p)=>{const[$,q]=o(l),[E,B]=o(p);return ${const p=t.byId.get(l.from).i,[$,q]=o(l);return!n(p)&&e.slice($+1,q).every(E=>!n(E.i))&&r.every(E=>E.e===l||!a(E.e,l))}),f=r.length>0&&(t.type==="data-flow"||!i),h=l=>{const[p,$]=o(l);return $-p},u=t.edges.map(()=>0);let g=!1;const c=[];for(const l of[...r].sort((p,$)=>h(p.e)-h($.e)||p.k-$.k)){let p=0;for(const $ of c)a($.e,l.e)&&(p=Math.max(p,u[$.k]+1));u[l.k]=p,p>1&&(g=!0),c.push(l)}const m=t.edges.map(()=>.5);for(const l of e){const p=r.filter(({e:E})=>E.from===l.id);if(p.length<2)continue;const $=p.filter(({k:E})=>s[E]==="end-down").sort((E,B)=>h(B.e)-h(E.e)||E.k-B.k);[...p.filter(({k:E})=>s[E]==="end-up").sort((E,B)=>h(E.e)-h(B.e)||B.k-E.k),...$].forEach(({k:E},B,j)=>{m[E]=j.length===2?B===0?1/3:2/3:(B+1)/(j.length+1)})}const b=ht();for(let l=1;l{const A=s[Q],V=t.byId.get(R.from).i,v=t.byId.get(R.to).i,D=v===l&&(A==="down"||A==="trunk"||A==="rail"||A==="end-down"),I=V===l&&v===l-1&&A==="up",w=v===l-1&&A==="end-up";D&&(A==="trunk"||A==="end-down")&&(B=!0),w&&(j=!0),(D||I||w)&&R.label&&(q++,E=Math.max(E,A==="trunk"?40:48))}),(q>1||B&&j)&&(E=64),b[p.id]=E}return{routes:s,gutter:f,lanes:u,exits:m,gaps:b,third:g}}var $t=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Rt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return x("svg",{class:`${t}-swatch`,"data-kind":n,...$t(24,16)},e==="fk"?x("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,x("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?x("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):x("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function bt(t,e){return e==="decision"?x("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},x("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?x("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):x("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function zt(t,e){return xt(e,`key:${t}`,()=>Ee(t,e))}var Se=zt;function Ee(t,e){const n=[],s=(o,a,i={})=>n.push(x("li",{class:`${t}-entry`,...i},o,x("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(x("li",{class:`${t}-entry`},x("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),x("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(bt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(bt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(bt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Rt(t,o),a,{"data-line":""})}return e.type==="schema"&&e.edges.length&&(s(Rt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(x("li",{class:`${t}-entry`,"data-when":"stacked"},x("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),x("span",null,"The table a foreign key references")))),e.nodes.some(o=>o.focal)&&e.legend.focal&&s(bt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(bt(t,"group"),e.legend.group),n.length?x("div",{class:`${t}-key`},x("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Ae(t,e){const n=e==="main"?6:6.5;return x("svg",{class:`${t}-arrow`,"data-kind":e,...$t(20,12)},x("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?x("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):x("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Le(t,e,n){if(n.shape==="decision")return[x("span",{class:`${t}-words`},x("span",{class:`${t}-name`},n.name))];const s=[];return e.type==="data-flow"?s.push(x("span",{class:`${t}-kind`},n.kind,x("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(x("span",{class:`${t}-kind`},n.kind)),s.push(x("span",{class:`${t}-name`},n.name)),n.detail&&s.push(x("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Mt(n.detail).flatMap((r,o)=>[o?" ":"",x("span",{class:`${t}-run`},r)]):n.detail)),s}function qe(t,e){return[x("span",{class:`${t}-th`},x("span",{class:`${t}-tname`},e.name)),x("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>x("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},x("span",{class:`${t}-keyseat`},n.key??""),x("span",{class:`${t}-cname`},n.name),n.ref?x("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?x("span",{class:`${t}-ctype`},n.type):null))),e.more?x("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ft=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Lt(t,e,n,s){const{P:r}=t,o=Me(e,s)||s.keep===n.id,a=gt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const f=t.plan;if(f&&n.i>0){const c=pt(f.gaps,n.id)??32,m=pt(s.grow,n.id)??0;i.push(`--_gap:${m?`calc(${Ft(c)} + var(--basalt-space-4) * ${m})`:Ft(c)}`)}const h=pt(s.heights,n.id);h&&i.push(`--_h:${h}px`);const u=pt(s.words,n.id);u&&i.push(`--_ww:${u}px`);const g=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return x("div",{class:`${r}-node`,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o?"img":void 0,"aria-label":o?$e(e,n):void 0,tabindex:g},n.shape==="decision"?x("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},x("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?x("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ot(n.mark.onLight)};--_md:${Ot(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?qe(r,n):Le(r,e,n))}function Ie(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((a,i)=>x("div",{class:`${s}-lane`,style:`--_r:${i+1}`,"aria-hidden":"true"},x("span",{class:`${s}-lane-name`},a.label)))),e.type==="architecture")for(const a of e.groups){const i=a.members.map(c=>e.byId.get(c));if(!i.length)continue;const f=Math.min(...i.map(c=>c.col)),h=Math.max(...i.map(c=>c.col)),u=Math.min(...i.map(c=>c.row)),g=Math.max(...i.map(c=>c.row2));r.push(x("div",{class:`${s}-gbox`,"data-group":a.id,style:`--_c:${f};--_c2:${h+1};--_r:${u};--_r2:${g+1}`,"aria-hidden":"true"},x("span",{class:`${s}-glabel`},a.label)))}if(e.type==="sequence")return r.push(x("ul",{class:`${s}-cast`},e.nodes.map(a=>x("li",{class:`${s}-actor`},Lt(t,e,a,n))))),r.push(Oe(t,e)),r;let o=0;for(;ou.id===a.group):void 0;if(!i){r.push(Lt(t,e,a,n)),o++;continue}const f=[];for(;oLt(t,e,u,n))))}return r}function Oe(t,e){const{P:n}=t,s=[];let r=null;for(const o of e.steps){if("band"in o){r=null,s.push(x("p",{class:`${n}-band`},x("span",null,o.band)));continue}r||(r=x("ol",{class:`${n}-msgs`,start:o.n}),s.push(r));const a=e.byId.get(o.from),i=e.byId.get(o.to),f=a?.col??1,h=i?.col??1,u=f===h,g=u&&f===e.nodes.length,c=Bt(e,o.kind);r.c.push(x("li",{class:`${n}-msg`,"data-kind":o.kind,"data-from":o.from,"data-to":o.to,"data-self":u?g?"start":"end":void 0,style:`--_a:${Math.min(f,h)};--_b:${Math.max(f,h)+1}`},x("span",{class:`${n}-said`},x("span",{class:`${n}-num`},String(o.n)),x("span",{class:`${n}-mlabel`},o.label)),x("span",{class:`${n}-route`},a?.short??o.from," ",Ae(n,o.kind),x("span",{class:t.hidden}," to ")," ",i?.short??o.to,c?` · ${c}`:""),o.note?x("span",{class:`${n}-note`},o.note):null))}return x("div",{class:`${n}-steps`},s)}function Ht(t,e){return xt(e,`list:${t}`,()=>Be(t,e))}var _e=Ht;function Be(t,e){const n=Math.min(6,e.heading+1),s=u=>x(`h${n}`,{class:`${t}-list-head`},u),r=u=>x("strong",null,u),o=u=>x("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,i=u=>{const g=Bt(e,u);return g?` (${g})`:""},f=u=>u.focal&&e.legend.focal?` ${mt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=m=>x("li",null,r(m.name),m.kind?`, ${m.kind}`:"",m.detail?[". ",m.mono?o(m.detail):m.detail,/[.!?]$/.test(m.detail)?"":"."]:/[.!?]$/.test(m.kind??m.name)?"":".",f(m)),g=[s("Parts")],c=e.nodes.filter(m=>!m.group);c.length&&g.push(x("ul",{class:`${t}-list-items`},c.map(u)));for(const m of e.groups)g.push(x("p",{class:`${t}-list-group`},m.label)),g.push(x("ul",{class:`${t}-list-items`},m.members.map(b=>u(e.byId.get(b)))));return g.push(s("Connections")),g.push(x("ol",{class:`${t}-list-items`},e.edges.map(m=>x("li",null,r(a(m.from))," to ",r(a(m.to)),m.label?[": ",o(m.label)]:"",`${i(m.kind)}.`)))),g}if(e.type==="flowchart"){const u=g=>(e.byId.get(g)?.i??0)+1;return[x("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const c=e.edges.filter(l=>l.from===g.id),m=g.shape==="decision"?"Decision":g.shape==="terminal"?c.length?"Start":"End":"Step",b=!g.detail&&/[.!?]$/.test(g.name)?" ":". ";return x("li",null,r(g.name),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",`${b}${m}.`,f(g),c.length?x("ul",{class:`${t}-list-exits`},c.map(l=>x("li",null,l.label?`If ${l.label}: go to ${u(l.to)}, `:`Then: go to ${u(l.to)}, `,r(a(l.to)),i(l.kind)))):null)}))]}if(e.type==="data-flow")return[x("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const g=e.edges.filter(c=>c.from===u.id);return x("li",null,`${u.laneLabel}: `,r(u.name),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",f(u),g.length?[" Then ",...g.flatMap((c,m)=>[m?"; ":"",`to step ${e.byId.get(c.to).step}, `,r(a(c.to)),c.label?[": ",o(c.label)]:"",i(c.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),x("ul",{class:`${t}-list-items`},e.nodes.map(c=>x("li",null,r(c.name),c.kind?`, ${c.kind}`:"",".",f(c))))];u.push(s("Messages"));let g=null;for(const c of e.steps){if("band"in c){g=null,u.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},c.band));continue}g||(g=x("ol",{class:`${t}-list-items`,start:c.n}),u.push(g)),g.c.push(x("li",null,o(c.label),": ",r(a(c.from))," to ",r(a(c.to)),`${i(c.kind)}.`,c.note?` ${mt(c.note)}`:""))}return u}const h=[];for(const u of e.nodes)h.push(x(`h${n}`,{class:`${t}-list-group`},o(u.name),f(u))),h.push(x("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(g=>x("li",null,o(g.name),g.key==="PK"?", primary key":g.key==="FK"?", foreign key":"",g.ref?[", references ",o(`${g.ref.table}.${g.ref.column}`)]:g.type?`, ${g.type}`:"")),...u.more?[x("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return h}function Wt(t){return`Arrow keys move to the next or the previous ${t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step"}, in the author's order; Home and End go to the ends; Escape clears the trace.`}function Nt(t,e=!1){return e?[{keys:["←","→"],words:Ct(t)},{keys:["Home","End"],words:"the ends"},{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]:[{keys:["←","→"],words:Ct(t)},{keys:["Home","End"],words:"the ends"},{keys:["Esc"],words:"clear"}]}var Ce="Plus and minus zoom, zero fits the drawing, Escape closes.",Dt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Gt(t,e,n){const s=n.prefix,r=ve(n.base),o=t.type==="sequence"||t.type==="schema"?null:Tt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",f=gt(t,e),h=t.type==="sequence"||t.type==="schema"?i:!0,u=`h${t.heading}`,g=[`--_cols:${At(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const c=t.type==="architecture"?t.groups.flatMap(l=>l.members.map(p=>t.byId.get(p))):[],m=(l,p,$)=>l?`var(--basalt-space-${p})`:$?`var(--basalt-space-${$})`:"0px",b=i&&e.pad?"3":void 0;g.push(`--_gpad:${m(c.some(l=>l.row===1),"8",b)} ${m(c.some(l=>l.col===t.cols),"4")} ${m(c.some(l=>l.row2===t.rows),"4",b)} ${m(c.some(l=>l.col===1),"4")}`)}return Dt(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),x("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":At(t),"data-reach":t.type==="architecture"?jt(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},x("div",{class:`${s}-head`},x(u,{id:r.title,class:`${s}-title`},t.title),n.hasSource?x("p",{class:`${s}-source`},{slot:"source"}):null),x("div",{class:`${s}-drawing`,role:h?"group":void 0,"aria-roledescription":h?"diagram":void 0,"aria-labelledby":h?r.title:void 0,"aria-describedby":h?f?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":f?"":void 0},Ie(a,t,e),x("div",{class:`${s}-ink`,"aria-hidden":"true"}),x("span",{class:`${s}-ruler`,"aria-hidden":"true"})),zt(s,t),x("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),x("div",{class:`${s}-foot`},{slot:"toggle"}),x("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Ht(s,t)),x("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Wt(t)} ${Ce}`:Wt(t)),x("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function je(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4)}}var vt=(t,e)=>t==="main"?e.line:e.hair,ct=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},dt=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Kt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function it(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,f=(r+a)/2,h=(o-s)/2,u=(a-r)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const b=n,l=u*Math.max(0,1-Math.abs(b-i)/h);return{x:b,y:e==="top"?f-l:f+l}}const c=n,m=h*Math.max(0,1-Math.abs(c-f)/u);return{x:e==="left"?i-m:i+m,y:c}}if(t.shape==="terminal"){const c=Math.min(h,u);if(g){const p=n,$=Math.min(Math.max(p,s+c),o-c),q=p-$,E=Math.abs(q)>=c?0:Math.sqrt(c*c-q*q);return{x:p,y:Math.abs(q)<1e-6?e==="top"?r:a:e==="top"?f-E:f+E}}const m=n,b=m-f,l=Math.abs(b)>=c?0:Math.sqrt(c*c-b*b);return{x:e==="left"?s+c-l:o-c+l,y:m}}return g?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Te(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,f=(r+a)/2,h=(o-s)/2,u=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/h+Math.abs(t.y-f)/u<1-n/Math.min(h,u);if(e.shape==="terminal"){const g=Math.min(h,u),c=Math.min(Math.max(t.x,s+g),o-g);return Math.hypot(t.x-c,t.y-f)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Fe(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var Mt=t=>t?t.split(/\s+/).filter(Boolean):[];function He(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const f of t.nodes){if(f.shape==="table"){for(const m of f.columns??[]){const b=m.ref?`→ ${m.ref.table}`:m.type??"",l=s("6")+n(m.name,"mono")+(b?s("3")+n(b,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(l))}o=Math.max(o,Math.ceil(n(f.name,"table")+2*s("3")+2*e.hair));continue}const h=f.shape==="terminal"?2*s("5"):2*s("3"),u=f.mark&&!ze()?s("6"):0;let g=0;for(const m of Mt(f.name))g=Math.max(g,n(m,f.shape==="decision"?"name-500":"name")+(f.kind?0:u));if(t.type!=="data-flow")for(const m of Mt(f.kind))g=Math.max(g,n(m,"mono")+u);for(const m of Mt(f.detail))g=Math.max(g,n(m,f.mono?"mono":"sans"));const c=f.shape==="decision"?g/.62:g+h+2*e.hair;r=Math.max(r,Math.ceil(c))}const a=At(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(Dt(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+jt(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function Zt(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function qt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Jt(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const f=r[r.length-2];if(Math.abs(f.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(f.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ft=t=>t.slice(1).map((e,n)=>[t[n],e]);function kt(t,e,n){const s=[];for(let o=0;oMath.min(l.x,p.x)+.75&&EMath.min($.y,q.y)+.75&&Br.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let f=o;for(const h of r)i.push([f,f+h]),f+=h+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var Y=t=>t==="left"||t==="right",Ut={top:"bottom",bottom:"top",left:"right",right:"left"};function Ne(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function De(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),f=t.byId.get(o.to),[h,u]=e[a],g=i.row===f.row&&Y(h)&&Y(u)&&h===Ut[u]||i.col===f.col&&!Y(h)&&!Y(u)&&h===Ut[u];s.push({edge:a,end:"from",node:i,side:h,far:f,straight:g,f:.5},{edge:a,end:"to",node:f,side:u,far:i,straight:g,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=l=>Y(l.side)?l.far.row-l.node.row:l.far.col-l.node.col,f=a.filter(l=>l.straight),h=a.filter(l=>!l.straight);if(h.sort((l,p)=>i(l)-i(p)||(Y(l.side)?l.far.col-p.far.col:l.far.row-p.far.row)*(i(l)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!f.length){h.length===2?(h[0].f=.25,h[1].f=.75):h.length===3?(h[0].f=.25,h[1].f=.5,h[2].f=.75):h.length>3&&h.forEach((l,p)=>{l.f=(p+1)/(h.length+1)});continue}const u=new Map;for(const l of f)u.has(l.far.id)||u.set(l.far.id,[]),u.get(l.far.id).push(l);for(const l of u.values())l.length>1&&l.sort((p,$)=>p.edge-$.edge).forEach((p,$)=>{p.f=l.length===2?$===0?.25:.75:($+1)/(l.length+1)});const g=Math.min(...f.map(l=>l.f)),c=Math.max(...f.map(l=>l.f)),m=h.filter(l=>i(l)<0),b=h.filter(l=>i(l)>=0);m.forEach((l,p)=>{l.f=g*(p+1)/(m.length+1)}),b.forEach((l,p)=>{l.f=c+(1-c)*(p+1)/(b.length+1)})}return s}function Xt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return Y(e)?it(t,e,r+(a-r)*n):it(t,e,s+(o-s)*n)}function Yt(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ct(o,n),shape:a.shape,i:a.i})}),r}function Qt(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var Pt=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function te(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function Ge(t,e,n,s,r,o,a,i,f){const h=a.space,u=[],g=[],c=[],m=[],b=h("1"),l=e.filter(p=>t.edges[p.i]?.label).sort((p,$)=>+(t.edges[$.i].kind==="main")-+(t.edges[p.i].kind==="main")||p.i-$.i);for(const p of l){const $=t.edges[p.i].label,q=i($,"label"),E=16,B=p.pts.length-2,j=[];ft(p.pts).forEach(([v,D],I)=>{const w=Math.abs(v.y-D.y)<.01,d=w?v.x:v.y;let y=w?D.x:D.y;const S=Math.sign(y-d)||1;I===B&&(y-=S*a.head);let L=[[d,y]];for(const G of r)for(const W of w?[G.l,G.r]:[G.t,G.b]){const k=w?v.y:v.x;(w?k>G.t&&kG.l&&kW>Math.min(O,M)+1&&W{const k=(G+W)/2,C=w?{x:k,y:v.y}:{x:v.x,y:k};return!r.some(O=>C.x>O.l&&C.xO.t&&C.y1&&H(G,W)?1:0})}),j.sort((v,D)=>D.pri-v.pri||D.len-v.len);let R=null,Q=!1;const A=(v,D=!0)=>{const I=Kt(v,b);return D&&(v.lo.r||v.to.b)||n.some(w=>Vt(I,w))||u.some(w=>dt(I,w))||s.heads.some(w=>dt(I,w))||s.rects.some(w=>dt(I,w))?!1:!e.some(w=>w.i!==p.i&&ft(w.pts).some(([d,y])=>dt(I,Pt(d,y,w.width))))};for(const v of j){for(const D of[1/2,1/3,2/3]){const I=v.p+(v.q-v.p)*D,w=[],d=h("2")+p.width/2;if(v.horiz?(v.len>=q+2*h("1")+h("3-5")&&w.push({box:{l:I-q/2-h("1"),r:I+q/2+h("1"),t:v.c-E/2,b:v.c+E/2},on:!0}),w.push({box:{l:I-q/2,r:I+q/2,t:v.c-d-E,b:v.c-d},on:!1}),w.push({box:{l:I-q/2,r:I+q/2,t:v.c+d,b:v.c+d+E},on:!1})):(v.len>=E+h("3")&&w.push({box:{l:v.c-q/2-h("1"),r:v.c+q/2+h("1"),t:I-E/2,b:I+E/2},on:!0}),w.push({box:{l:v.c+d,r:v.c+d+q,t:I-E/2,b:I+E/2},on:!1}),w.push({box:{l:v.c-d-q,r:v.c-d,t:I-E/2,b:I+E/2},on:!1})),R=w.find(y=>A(y.box))??null,R)break;!Q&&w.some(y=>A(y.box,!1))&&(Q=!0)}if(R)break}if(!R){c.push(p.i),Q&&m.push(p.i);continue}const V=te(R.box,f.ox,f.oy,v=>A(v));u.push(V),g.push({i:p.i,text:$,box:V,on:R.on})}return{labels:g,unseated:c,bounded:m}}function ee(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=ct(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const f=a.querySelector(`:scope > .${n}-glabel`);f&&f.getClientRects().length&&r.push(ct(f,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const f=ct(a,e);i>0&&r.push({l:f.l,r:f.r,t:f.t-s/2-.5,b:f.t-s/2+.5});const h=a.querySelector(`.${n}-lane-name`);h&&r.push(ct(h,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function Ke(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:f}=t,h=r.space,u=Yt(s,a,i,o),g=[...u.values()],c=We(a),m=i.left-Math.floor(i.left),b=i.top-Math.floor(i.top),l=Zt(m,b),p=a.clientWidth,$=a.clientHeight,q=k=>s.type==="data-flow"?k.col+1:k.col,E=parseFloat(getComputedStyle(a).rowGap)||0,B={w:p,h:$,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:m,oy:b};if(s.type==="sequence")return Ze(t,B,l);let j,R=[];s.type==="schema"?j=s.edges.map(k=>{const C=s.byId.get(k.from),O=s.byId.get(k.to);if(C.col===O.col){const M=C.col===s.cols&&s.cols>1?"left":"right";return[M,M]}return O.col>C.col?["right","left"]:["left","right"]}):(j=s.edges.map(k=>{const C=s.byId.get(k.from),O=s.byId.get(k.to),[M,_]=Ne(C,O);return[k.fromSide??M,k.toSide??_]}),R=De(s,j,f||(()=>{})));const Q=(k,C)=>{const O=a.querySelector(`.${o}-node[data-node="${CSS.escape(k)}"] .${o}-row[data-row="${C}"]`);if(!O)return 0;const M=ct(O,i);return(M.t+M.b)/2},A=s.edges.map((k,C)=>{const[O,M]=j[C],_=u.get(k.from),z=u.get(k.to),Z=vt(k.kind,r);if(k.fk){const J=Q(k.from,k.fromRow),et=Q(k.to,k.toRow),U=l.y(J,Z),nt=l.y(et,Z);return{p1:{x:O==="right"?_.rect.r:_.rect.l,y:U},p2:{x:M==="right"?z.rect.r:z.rect.l,y:nt},r1:J,r2:Math.abs(U-nt)<.01?J:et}}const P=R.find(J=>J.edge===C&&J.end==="from").f,X=R.find(J=>J.edge===C&&J.end==="to").f;let N=Xt(_,O,P),K=Xt(z,M,X);const ot=Y(O)?N.y:N.x;let tt=Y(M)?K.y:K.x;return Y(O)?N={...N,y:l.y(N.y,Z)}:N={...N,x:l.x(N.x,Z)},Y(M)?K={...K,y:l.y(K.y,Z)}:K={...K,x:l.x(K.x,Z)},Y(O)&&Y(M)&&Math.abs(N.y-K.y)<1.01&&(K={...K,y:N.y},tt=ot),!Y(O)&&!Y(M)&&Math.abs(N.x-K.x)<1.01&&(K={...K,x:N.x},tt=ot),N=Y(O)?it(_,O,N.y):it(_,O,N.x),K=Y(M)?it(z,M,K.y):it(z,M,K.x),{p1:N,p2:K,r1:ot,r2:tt}}),V=new Set;s.type==="schema"&&s.edges.forEach((k,C)=>{Math.abs(s.byId.get(k.from).col-s.byId.get(k.to).col)>1&&V.add(C)});const v=new Map,D=new Set;s.edges.forEach((k,C)=>{if(V.has(C))return;const[O,M]=j[C],{p1:_,p2:z}=A[C],Z=s.byId.get(k.from),P=s.byId.get(k.to);let X=null,N=null,K=!1;if(O===M){if(Y(O)){const J=O==="right"?Math.max(q(Z),q(P)):Math.min(q(Z),q(P))-1,et=c.cols[J-1],U=c.cols[J];et&&U&&(X=`c${J}`,N=[et[1],U[0]],K=!0)}else{const J=O==="bottom"?Math.max(Z.row2,P.row2):Math.min(Z.row,P.row)-1,et=c.rows[J-1],U=c.rows[J];et&&U&&(X=`r${J}`,N=[et[1],U[0]],K=!1)}X&&D.add(C)}else if(Y(O)&&Y(M)&&Math.abs(_.y-z.y)>.5){const J=q(P),et=M==="left",U=c.cols[(et?J-1:J)-1],nt=c.cols[(et?J:J+1)-1];U&&nt&&(X=`c${et?J-1:J}`,N=[U[1],nt[0]],K=!0)}else if(!Y(O)&&!Y(M)&&Math.abs(_.x-z.x)>.5){const et=M==="top"?P.row-1:P.row2,U=c.rows[et-1],nt=c.rows[et];U&&nt&&(X=`r${et}`,N=[U[1],nt[0]],K=!1)}if(!X||!N)return;v.has(X)||v.set(X,{span:N,vertical:K,members:new Map});const ot=`${k.to}.${M}.${Math.round(K?z.y:z.x)}`,tt=v.get(X);tt.members.has(ot)||tt.members.set(ot,[]),tt.members.get(ot).push(C)});const I=new Map,w=k=>{const[C,O]=j[k],{p1:M,p2:_}=A[k];if(Y(C)&&Y(O)){if(C===O){const Z=I.get(k)??(C==="right"?Math.max(M.x,_.x)+h("4"):Math.min(M.x,_.x)-h("4"));return[M,{x:Z,y:M.y},{x:Z,y:_.y},_]}if(Math.abs(M.y-_.y)<=.5)return[M,{x:_.x,y:M.y}];const z=I.get(k)??(M.x+_.x)/2;return[M,{x:z,y:M.y},{x:z,y:_.y},_]}if(!Y(C)&&!Y(O)){if(C===O){const Z=I.get(k)??(C==="bottom"?Math.max(M.y,_.y)+h("4"):Math.min(M.y,_.y)-h("4"));return[M,{x:M.x,y:Z},{x:_.x,y:Z},_]}if(Math.abs(M.x-_.x)<=.5)return[M,{x:M.x,y:_.y}];const z=I.get(k)??(M.y+_.y)/2;return[M,{x:M.x,y:z},{x:_.x,y:z},_]}return Y(C)?[M,{x:_.x,y:M.y},_]:[M,{x:M.x,y:_.y},_]},d=k=>{const C=s.edges[k],O=vt(C.kind,r),M=w(k),_=Jt(M,O,l);let z;return M.length===_.length&&(z=ft(M).map(([Z,P])=>Math.abs(Z.y-P.y)<.75?(Z.y+P.y)/2:(Z.x+P.x)/2),z[0]=A[k].r1,z.length>1&&(z[z.length-1]=A[k].r2)),{i:k,from:C.from,to:C.to,kind:C.kind,pts:_,tip:_[_.length-1],dir:qt(_),dot:C.fk?_[0]:void 0,width:O,axes:z}},y=()=>s.edges.flatMap((k,C)=>V.has(C)?[]:[d(C)]);let S=null;const L=k=>{S??(S=y());const C=S.map(O=>k.has(O.i)?d(O.i):O);return{lines:C,score:Ve(C,k)*1e5+kt(C,void 0,k).length*1e3+It(C.filter(O=>k.has(O.i)),g,s).length}},H=(k,C)=>{const O=k.flatMap(M=>{const{p1:_,p2:z}=A[M];return C?[_.y,z.y]:[_.x,z.x]});return[Math.min(...O),Math.max(...O)]};for(const[,k]of v){const C=[...k.members.values()].map(M=>({members:M,run:H(M,k.vertical)})).sort((M,_)=>M.run[0]-_.run[0]),O=[];for(const M of C){const _=O[O.length-1];_&&_.some(z=>z.run[0]D.has(ot)))continue;const _=M.map(ot=>ot.members),z=_.length,Z=(k.span[1]-k.span[0])/(z+1);ZJ.forEach(U=>I.set(U,k.span[0]+Z*(et+1))));const tt=L(P);tt.scoreot.forEach(J=>I.set(J,k.span[0]+Z*(tt+1)))),S=K}}B.lines=y();for(const k of V)f?.(`${s.edges[k].from} to ${s.edges[k].to} is two columns apart, so its line is not drawn; its row still writes the target`);B.crossings=kt(B.lines),B.through=It(B.lines,g,s),B.outside=se(B.lines,p,$,r);const{obstacles:T,groups:G}=ee(a,i,o,E);T.heads=B.lines.map(k=>Qt(k,r));const W=Ge(s,B.lines,g,T,G,{l:0,t:0,r:p,b:$},r,e,{ox:m,oy:b});return B.labels=W.labels,B.unseated=W.unseated,B.bounded=W.bounded,B.overlaps=[...new Set(ne(B.lines,null).flat())],B}function Ve(t,e){return ne(t,e).length}function ne(t,e){const n=[];for(let s=0;s=i)continue;const[p,$]=c?[f.x,h.x]:[f.y,h.y],[q,E]=c?[u.x,g.x]:[u.y,g.y];Math.min(Math.max(p,$),Math.max(q,E))-Math.max(Math.min(p,$),Math.min(q,E))>1&&n.push([o.i,a.i])}}return n}function*oe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const f=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-f<-.5||a.x+f>e+.5||a.y-f<-.5||a.y+f>n+.5})&&r.push(o.i);return r}function It(t,e,n){const s=[];for(const r of t){const o=ft(r.pts);e.some(a=>o.some(([i,f])=>Re(i,f,a)))&&s.push(r.i)}return s}function Ze(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,f=r.space,h=new Map;a.querySelectorAll(`.${o}-node`).forEach(b=>h.set(b.dataset.node,ct(b,i)));const u=a.querySelector(`.${o}-steps`),g=u?ct(u,i).b:e.h,c=b=>{const l=h.get(b);return l?n.x((l.l+l.r)/2,r.hair):0};for(const b of s.nodes){const l=h.get(b.id);l&&e.lifelines.push({x:c(b.id),y1:l.b,y2:g})}const m=b=>h.get(b.id);return a.querySelectorAll(`.${o}-msg`).forEach(b=>{const l=b.dataset.from,p=b.dataset.to,$=b.dataset.kind??"plain",q=vt($,r),E=ct(b,i),B=n.y((E.t+E.b)/2,q),j=Number(b.querySelector(`.${o}-num`)?.textContent??0),R=c(l),Q=c(p);let A;if(l===p){const y=b.dataset.self==="start"?-f("6"):f("6"),S=n.y(B-f("2"),q),L=n.y(B+f("2"),q);A=[{x:R,y:S},{x:n.x(R+y,q),y:S},{x:n.x(R+y,q),y:L},{x:R,y:L}]}else A=[{x:R,y:B},{x:Q,y:B}];e.lines.push({i:j,from:l,to:p,kind:$,pts:A,tip:A[A.length-1],dir:qt(A),width:q});const V=b.querySelector(`.${o}-said`),v=b.querySelector(`.${o}-note`),D=s.byId.get(l),I=s.byId.get(p);if(!D||!I)return;const w=l===p?(()=>{const y=s.nodes[D.i+(b.dataset.self==="start"?-1:1)],S=y?c(y.id):b.dataset.self==="start"?0:e.w;return Math.abs(S-R)-f("6")-f("2-5")-f("2")})():Math.abs(Q-R)-2*f("2");Math.max(V?V.getBoundingClientRect().width:0,v?v.getBoundingClientRect().width:0)>w+.5&&e.unseated.push(j)}),e}function ae(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:i,origin:f}=t,h=o.space,u=Yt(r,i,f,a),g=[...u.values()],c=f.left-Math.floor(f.left),m=f.top-Math.floor(f.top),b=Zt(c,m),l=i.clientWidth,p=i.clientHeight,$={w:l,h:p,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:m},q=ht();if(r.type==="sequence"||r.type==="schema")return{geo:$,grow:q};const E=l-(parseFloat(getComputedStyle(i).paddingRight)||0),B=(w,d,y)=>{const S=[w];for(let L=1;L<=(pt(s,d)??0);L++)S.push({...w,t:w.t+y*h("4")*L,b:w.b+y*h("4")*L});return S},j=new Map;i.querySelectorAll(`.${a}-node`).forEach(w=>{const d=w.parentElement,y=ct(d,f),S=getComputedStyle(d);j.set(w.dataset.node,y.r-(parseFloat(S.paddingRight)||0)-(parseFloat(S.borderRightWidth)||0))});const R=r.nodes,Q=w=>u.get(R[w].id),A=[],V=w=>vt(r.edges[w].kind,o);r.edges.forEach((w,d)=>{const y=n.routes[d],S=u.get(w.from),L=u.get(w.to),H=V(d);let T=[];const G=w.label,W=G?e(G,"label"):0,k=16,C=h("4");if(y==="down"||y==="up"){const M=Math.max(S.rect.l,L.rect.l),_=Math.min(S.rect.r,L.rect.r),z=r.edges.map((N,K)=>({o:N,j:K})).filter(({o:N,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(N.from===w.from&&N.to===w.to||N.from===w.to&&N.to===w.from)),Z=z.findIndex(N=>N.j===d),P=z.length<2?.5:z.length===2?Z===0?.25:.75:(Z+1)/(z.length+1),X=b.x(M+(_-M)*P,H);if(T=y==="down"?[it(S,"bottom",X),it(L,"top",X)]:[it(S,"top",X),it(L,"bottom",X)],G){let N=Math.min(T[0].y,T[1].y),K=Math.max(T[0].y,T[1].y);y==="down"?K-=o.head:N+=o.head;const ot=[...i.querySelectorAll(`.${a}-group`)].map(U=>ct(U,f));let tt=[[N,K]];for(const U of ot)for(const nt of[U.t,U.b])tt=tt.flatMap(([at,F])=>nt>at+1&&ntot.some(at=>(U+nt)/2>at.t&&(U+nt)/2at.l&&X1){const U=tt.filter(([at,F])=>!J(at,F));[N,K]=(U.length?U:tt).reduce((at,F)=>F[1]-F[0]>at[1]-at[0]?F:at)}const et=[1/2,1/3,2/3].map(U=>{const nt=N+(K-N)*U;return{l:X-W/2-h("1"),r:X+W/2+h("1"),t:nt-k/2,b:nt+k/2}});A.push({k:d,cands:et,on:!0,card:y==="down"?w.to:w.from})}}else if(y==="trunk"||y==="rail"){const M=b.x(Math.max(S.rect.l,y==="rail"?L.rect.l:S.rect.l)+h(y==="trunk"?"8":"3"),H),_=it(S,"bottom",M);if(y==="rail"){if(T=[_,it(L,"top",M)],G){const z=L.rect.t-h("6");A.push({k:d,cands:B({l:M+h("2-5"),r:M+h("2-5")+W,t:z-k/2,b:z+k/2},w.to,-1),on:!1,card:w.to})}}else{const z=b.x(L.rect.l+h("6"),H),Z=b.y(L.rect.t-C,H);T=[_,{x:M,y:Z},{x:z,y:Z},it(L,"top",z)],G&&A.push({k:d,cands:B({l:z+h("2-5"),r:z+h("2-5")+W,t:Z-k/2,b:Z+k/2},w.to,-1),on:!1,card:w.to})}}else{const M=Math.min(j.get(w.from)??l,j.get(w.to)??l),_=b.x(n.gutter?E+(n.lanes[d]?2*h("3-5"):h("3-5")):M-h("2-5"),H),z=b.y(S.rect.t+(S.rect.b-S.rect.t)*n.exits[d],H),Z=it(S,"right",z),P=b.x(L.rect.r-h("6"),H),X=y==="end-down",N=b.y(X?L.rect.t-C:L.rect.b+C,H);T=[Z,{x:_,y:Z.y},{x:_,y:N},{x:P,y:N},it(L,X?"top":"bottom",P)];const K=X?w.to:R[L.i+1]?.id??w.to;G&&A.push({k:d,cands:B({l:P-h("2-5")-W,r:P-h("2-5"),t:N-k/2,b:N+k/2},K,X?-1:1),on:!1,card:K})}const O=Jt(T,H,b);$.lines.push({i:d,from:w.from,to:w.to,kind:w.kind,pts:O,tip:O[O.length-1],dir:qt(O),width:H})}),$.crossings=kt($.lines),$.through=It($.lines,g,r),$.outside=se($.lines,l,p,o);const{obstacles:v}=ee(i,f,a,0);v.heads=$.lines.map(w=>Qt(w,o));const D=[],I={l:0,t:0,r:l,b:p};for(const w of A){const d=L=>{const H=Kt(L,h("1"));return L.lI.r+.5||L.tI.b+.5||g.some(T=>Vt(H,T))||D.some(T=>dt(H,T))||v.heads.some(T=>dt(H,T))||v.rects.some(T=>dt(H,T))||$.lines.some(T=>T.i!==w.k&&ft(T.pts).some(([G,W])=>dt(H,Pt(G,W,T.width))))},y=w.cands.find(L=>!d(L));y||(q[w.card]=(q[w.card]??0)+1,$.unseated.push(w.k));const S=y?te(y,c,m,L=>!d(L)):w.cands[0];D.push(S),$.labels.push({i:w.k,text:r.edges[w.k].label,box:S,on:w.on})}return{geo:$,grow:q}}function Je(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...B})),g=u[u.length-1];g.x-=o.x*h,g.y-=o.y*h;const c=e.tip.x-o.x*i,m=e.tip.y-o.y*i,b=-o.y*f,l=o.x*f,p=B=>Math.round(B*100)/100,$=lt(e.kind),q=a?``:``,E=e.dot?``:"";return`${q}${E}`}function re(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,f]of o){const h=`${s}-cut-${i}`;r.set(i,h);const u=f.map(g=>{const c=e.lines[g.top],m=e.lines[g.under],b=c.width/2+n.cut,l=m.width/2+1;return g.underVertical?``:``}).join("");a+=`${u}`}return{defs:a,ids:r}}function ie(t,e,n,s){const{defs:r,ids:o}=re(t,e,n,s),a=e.lifelines.map(u=>``).join(""),i=e.lines.map((u,g)=>Xe(t,u,n,o.get(g)??null,u.from===u.to?n.radiusXs:n.radius)).join(""),f=`${r?`${r}`:""}${a}${i}`,h=e.labels.map(u=>`${lt(u.text)}`).join("");return f+h}function yt(t,e,n,s,r,o,a,i){const h=t.querySelector(`.${n}-drawing`);if(!h||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const u=je(t),g=Fe(h,n),c=He(e,u,g);i?.(c.least);const m=t.clientWidth,b=(()=>{const v=document.activeElement;return v&&h.contains(v)&&v.dataset.node?v.dataset.node:void 0})(),l=v=>gt(e,v)?{...v,stop:v.stop&&e.byId.has(v.stop)?v.stop:e.nodes[0]?.id,keep:void 0}:{...v,stop:v.stop??e.nodes[0]?.id,keep:b&&v.layout!=="drawn"?b:void 0};let p=!1;const $=v=>{if(p=!1,e.type!=="flowchart")return v;o({...v,heights:void 0,words:void 0});const D=ht(),I=ht();return h.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(w=>{const d=w.querySelector(`.${n}-words`);if(!d)return;const y=w.getBoundingClientRect(),S=T=>{const G={w:T.width+2*u.space("2-5"),h:T.height+2*u.space("2")},W=1-G.w/y.width,k=W>.05?G.h/2/W:G.h*10;return Math.max(u.space("16"),Math.ceil(y.width/5),Math.ceil(2*k))},L=d.getBoundingClientRect();let H=S(L);if(H>y.width){const T=C=>(w.style.setProperty("--_ww",`${C}px`),d.getBoundingClientRect()),G=Math.floor(w.clientWidth-2*u.space("2-5"));let W=Math.ceil(L.width),k=L.height;for(;W1;){const z=C+O>>1;T(z).heighty.width&&(p=!0)}),{...v,heights:D,words:Object.keys(I).length?I:void 0}},q=()=>({m:e,tk:u,P:n,drawing:h,origin:h.getBoundingClientRect(),warn:a}),E=r.autoOpen?{open:!1,autoOpen:void 0}:{},B=(v,D)=>D.map(I=>wt(e,v.lines.find(w=>w.i===I))).join(", ");if(m>=c.least){const v=d=>{let y=l({...r,...E,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:d||void 0});return y=$(y),o(y),{dd:y,g:Ke(q(),g)}};let{dd:D,g:I}=v(!1);const w=d=>d.through.length>0||d.outside.length>0||(d.overlaps?.length??0)>0||p;if(!w(I)&&I.unseated.length&&I.unseated.every(d=>I.bounded?.includes(d))){const d=v(!0);!w(d.g)&&!d.g.unseated.length&&({dd:D,g:I}=d)}if(!w(I)&&!I.unseated.length)return I.crossings.length&&a?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(d=>`${wt(e,I.lines[d.top])} over ${wt(e,I.lines[d.under])}`).join("; ")}`),{dyn:D,geo:I,ink:ie(n,I,u,s),tokens:u,least:c.least};p&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: a decision would be taller than it is wide`),I.through.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${B(I,I.through)} would pass through a node`),I.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${B(I,I.overlaps)} would lie on one another`),I.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${B(I,I.outside)} would leave the drawing`),I.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: no clean seat for ${I.unseated.map(d=>e.type==="sequence"?`message ${d}`:`"${e.edges[d]?.label}"`).join(", ")}`)}let j=l({...r,...E,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(j=$(j),o(j),e.type==="sequence"||e.type==="schema")return{dyn:j,geo:null,ink:"",tokens:u,least:c.least};const R=Tt(e);let Q=ae(q(),g,R,j.grow);for(let v=0;v<6&&Object.keys(Q.grow).length;v++){const D=ht(j.grow);for(const[I,w]of Object.entries(Q.grow))D[I]=(pt(D,I)??0)+w;j={...j,grow:D},o(j),Q=ae(q(),g,R,D)}const A=Q.geo;if(A.unseated.length>0||A.through.length>0||A.outside.length>0||R.third){A.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(A.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),A.through.length&&a?.(`in the stacked drawing ${B(A,A.through)} would pass through a node, so its lines are not drawn`),A.outside.length&&a?.(`in the stacked drawing ${B(A,A.outside)} would leave the drawing, so its lines are not drawn`),R.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const v={...A,lines:[],labels:[],crossings:[]};return{dyn:l({...j,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:v,ink:"",tokens:u,least:c.least}}return A.crossings.length&&a?.(`${A.crossings.length} crossing${A.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${A.crossings.map(v=>`${wt(e,A.lines[v.top])} over ${wt(e,A.lines[v.under])}`).join("; ")}`),{dyn:j,geo:A,ink:ie(n,A,u,s),tokens:u,least:c.least}}function Ye(t,e,n,s,r,o,a,i){const{layer:f,memo:h}=i;h.model!==e&&(h.model=e,h.least=void 0);const u=b=>{f.style.width=`${Math.max(h.least||b,Math.min(i.avail,i.row))}px`};f.style.width||(f.style.width=`${Math.min(i.avail,i.row)}px`);const g=f.style.transform;f.style.transform="none";const c=f.offsetWidth?f.getBoundingClientRect().width/f.offsetWidth:1;Math.abs(c-1)>1e-4&&(f.style.transform=`scale(${1/c})`);let m=yt(t,e,n,s,r,o,h.least===void 0?void 0:a,u);if(m.dyn.layout==="stacked"&&h.least===void 0&&m.least!==void 0){const b=m.dyn,l=E=>{f.style.width=`${E}px`;const B=yt(t,e,n,s,b,o);return B.dyn.layout==="drawn"?yt(t,e,n,s,B.dyn,o):B},p=Math.max(m.least,Math.min(i.avail,i.row)),$=Math.max(i.row,p)*1.5;let q;for(let E=p+16;E<=$&&q===void 0;E+=16)l(E).dyn.layout==="drawn"&&(q=E);if(q!==void 0){for(let E=q-15;Ei.contain&&(f.style.width=`${i.contain}px`,m=yt(t,e,n,s,m.dyn,o,a)),f.style.transform=g,m}function wt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Qe(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const l of n?.lines??[])l.from===o&&a.add(l.to),l.to===o&&a.add(l.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(l=>l.toggleAttribute("data-near",a.has(l.dataset.node))),!n||!s)return;const i=l=>!!o&&(l.from===o||l.to===o),f=t.querySelector(`.${e}-edges`),h=new Map;t.querySelectorAll(`.${e}-edge`).forEach(l=>h.set(l.getAttribute("data-edge"),l));for(const l of n.lines){const p=h.get(String(l.i));p&&(p.toggleAttribute("data-lit",i(l)),p.toggleAttribute("data-dim",!!o&&!i(l)))}if(t.querySelectorAll(`.${e}-label`).forEach(l=>{const p=n.lines.find($=>String($.i)===l.dataset.edge);l.toggleAttribute("data-lit",!!(p&&i(p)))}),f){for(const l of n.lines)if(i(l)){const p=h.get(String(l.i));p&&f.appendChild(p)}}const u=kt(n.lines,i),{defs:g,ids:c}=re(e,{...n,crossings:u},s,r),m=t.querySelector(`.${e}-svg`);if(!m)return;let b=m.querySelector("defs");!b&&g&&(b=document.createElementNS("http://www.w3.org/2000/svg","defs"),m.insertBefore(b,m.firstChild)),b&&(b.innerHTML=g),n.lines.forEach((l,p)=>{const $=h.get(String(l.i))?.querySelector(`.${e}-line`);if(!$)return;const q=c.get(p);q?$.setAttribute("mask",`url(#${q})`):$.removeAttribute("mask")})}var Pe=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function tn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Pe()?"done":"pending")}}function le(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function en(t,e,n){const s=t.byId.get(e)?.i??0,r=t.nodes.length;let o;if(n==="ArrowRight"||n==="ArrowDown")o=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")o=s-1;else if(n==="Home")o=0;else if(n==="End")o=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,o))].id}var nn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],ce=["data-layout","data-measured","data-bare","data-motion"],on=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],de=t=>t==null||t===!1;function sn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function ue(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?ce:nn;for(const a of s)de(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const h=t.style,u=new Map(String(i??"").split(";").map(g=>{const c=g.indexOf(":");return[g.slice(0,c).trim(),g.slice(c+1).trim()]}).filter(([g])=>g));for(const[g,c]of u)h.getPropertyValue(g).trim()!==c&&h.setProperty(g,c);for(const g of on)u.has(g)||h.removeProperty(g);continue}if(n&&!ce.includes(a))continue;if(de(i)){t.removeAttribute(a);continue}const f=i===!0?"":String(i);t.getAttribute(a)!==f&&t.setAttribute(a,f)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(c,m,b){return{prefix:n,base:c,hasSource:m.source!==void 0&&m.source!==null&&m.source!=="",hiddenClass:"visually-hidden",viewer:!!b}}function o(c,m,b,l){var p=function($){return''+lt($)+""};return{source:lt(String(m.source||"")),summary:lt(String(m.summary||"")),hint:Nt(c).map(function($){return""+$.keys.map(p).join(" ")+" "+lt($.words)+""}).join(""),toggle:'"}}function a(c,m,b){var l=St(c),p=Gt(l,{},r(m,c,b)),$=Et(p,o(l,c,m,!1)),q=$.indexOf(">");return{open:$.slice(0,q+1),inner:$.slice(q+1,$.length-9),warnings:l.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],f=["--_cols","--_gpad","--_track"];function h(c,m,b,l){c.__diagram&&c.__diagram.stop();var p=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),$=St(m);if(!b||!p||!c.querySelector(":scope > .diagram-drawing")){if(!p||!c.querySelector("#"+CSS.escape(p+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););p="dg"+s}var q=a(m,p,l),E=document.createElement("div");E.innerHTML=q.open+"";var B=E.firstChild;i.forEach(function(F){c.removeAttribute(F)}),f.forEach(function(F){c.style.removeProperty(F)});for(var j=0;j :not(script[data-diagram])").forEach(function(F){F.remove()}),c.insertAdjacentHTML("beforeend",q.inner)}$.warnings.forEach(function(F){console.warn("Basalt diagram: "+F)});var Q=r(p,m,l),A={},V=null,v=null,D=null,I=Object.create(null),w=function(F){I[F]||(I[F]=1,console.warn("Basalt diagram: "+F))},d=function(F){ue(c,Gt($,F,Q))},y=c.querySelector(".diagram-ink"),S=c.querySelector(".diagram-toggle"),L=!l&&$.motion.animated&&typeof e.diagramMotion=="function",H=null,T=null,G=function(){L&&le(c)};function W(){Qe(c,n,V&&V.geo,V&&V.tokens,p,v||D)}function k(){S&&(S.setAttribute("aria-expanded",String(!!A.open)),S.firstElementChild.textContent=A.open?"Hide the list":"View as list")}function C(){V=l?Ye(c,$,n,p,A,d,w,l):yt(c,$,n,p,A,d,w),A=V.dyn,d(A),k(),gt($,A)||(D=null);var F=y&&V.ink!==T;F&&(y.innerHTML=V.ink,T=V.ink),W(),L&&V.tokens&&(tn(c,!!(V.geo&&V.geo.lines.length)),F&&H&&H.redrawn()),l&&l.onMeasured&&l.onMeasured(V,c)}function O(F){A=F,d(A)}function M(F){var st=A.stop;A=Object.assign({},A,{stop:F}),an(c,n,st,F)}var _=function(F){var st=F&&F.closest?F.closest(".diagram-node"):null;return st&&c.contains(st)?st:null};function z(F){var st=_(F.target);if(!(!st||F.defaultPrevented)){if(G(),F.key==="Escape"){!l&&(v||D)&&(F.preventDefault(),v=D=null,W());return}if(gt($,A)){var ut=en($,st.getAttribute("data-node"),F.key);if(ut){F.preventDefault(),M(ut);var fe=c.querySelector('.diagram-node[data-node="'+CSS.escape(ut)+'"]');fe&&fe.focus()}}}}function Z(F){var st=_(F.target);if(st){G();var ut=st.getAttribute("data-node");v=st.matches(":focus-visible")?ut:null,gt($,A)&&A.stop!==ut&&M(ut),W()}}function P(F){var st=_(F.target);st&&(_(F.relatedTarget)||(v=null),A.keep===st.getAttribute("data-node")&&O(Object.assign({},A,{keep:void 0})),W())}function X(F){if(!(F.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var st=_(F.target);st&&G();var ut=st&>($,A)?st.getAttribute("data-node"):null;ut!==D&&(D=ut,W())}}function N(){D&&(D=null,W())}function K(){G(),O(Object.assign({},A,{open:!A.open,autoOpen:void 0})),k()}c.addEventListener("keydown",z),c.addEventListener("focusin",Z),c.addEventListener("focusout",P),c.addEventListener("pointerover",X),c.addEventListener("pointerleave",N),S&&S.addEventListener("click",K),C();var ot=c.clientWidth,tt=0,J=!0,et=new ResizeObserver(function(){Math.abs(c.clientWidth-ot)<.5||(ot=c.clientWidth,cancelAnimationFrame(tt),tt=requestAnimationFrame(C))});et.observe(c),document.fonts&&document.fonts.ready.then(function(){J&&C()});var U=matchMedia("(forced-colors: active)"),nt=$.nodes.some(function(F){return F.mark});nt&&U.addEventListener("change",C),L&&(H=e.diagramMotion(c,{fig:c,P:n,base:p,model:function(){return $},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},m));var at=!l&&m.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,m,{model:$,settle:G,animated:L}):null;c.__diagram={stop:function(){at&&at.destroy(),J=!1,et.disconnect(),cancelAnimationFrame(tt),nt&&U.removeEventListener("change",C),H&&H.destroy(),c.removeEventListener("keydown",z),c.removeEventListener("focusin",Z),c.removeEventListener("focusout",P),c.removeEventListener("pointerover",X),c.removeEventListener("pointerleave",N),S&&S.removeEventListener("click",K)},layout:C,key:u(m),send:H&&H.sendValue?H.sendValue:null}}function u(c){try{return JSON.stringify(c,function(m,b){return m==="packet"&&b&&typeof b=="object"?Object.assign({},b,{send:void 0}):b})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var m=c.querySelector(":scope > script[data-diagram]");if(m)try{h(c,JSON.parse(m.textContent),!0)}catch(b){console.error("Basalt diagram: this figure could not be drawn",b)}}})}e.diagramMarkup=a,e.diagramKit={draw:h,buildModel:St,figureKey:Se,figureList:_e,hintEntries:Nt,toHtml:Et,escapeHtml:lt,settleEntrance:le},t.diagram=function(c,m){var b=c.__diagram,l=b&&b.send?u(m):null;if(l!==null&&l===b.key){b.send(m.packet?m.packet.send:void 0);return}h(c,m)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); +(()=>{var fe=["top","right","bottom","left"],he=["main","plain","dashed"],pe=[2,3,4,5,6],rt=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),pt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function kt(t,e={}){const s=e.checks!==!1,r=[],o=d=>{r.push(d)},a=t.legend??{},l={};for(const d of["main","plain","dashed","focal","group"]){const m=rt(a[d]);m&&(l[d]=m)}const p=t.stepLabel,h=typeof p=="function"?d=>String(p(d)):typeof p=="string"?(d=>p.replace("{n}",String(d))):d=>`Step ${d}`,u=t.shapeLabels??{},g={terminal:rt(u.terminal)??"Start or end",step:rt(u.step)??"Step",decision:rt(u.decision)??"Decision"},c=t.heading===void 0?3:pe.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),y=(d,m)=>d==null?"plain":he.includes(d)?d:(o(`"${String(d)}" is not a kind of line (main, plain or dashed): ${m} is drawn plain`),"plain"),$=d=>{if(d!=null){if(fe.includes(d))return d;o(`"${String(d)}" is not a side (top, right, bottom or left): the derived side is used`)}},i=(d,m)=>typeof d=="number"&&Number.isInteger(d)&&d>=1?d:(o(`${m} is ${JSON.stringify(d)}, not a whole number from 1: it is placed at 1`),1),f=[],b=[];let O=[];const _=[],B=[],j=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(j)||o(`"${String(j)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),j==="architecture"||j==="flowchart"){for(const d of t.nodes??[]){const m=j==="flowchart"&&d.shape==="decision"?"decision":j==="flowchart"&&d.shape==="terminal"?"terminal":"box",S=String(d.id??""),E=i(d.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(d.name??""),kind:m==="decision"?void 0:rt(d.kind),detail:m==="decision"?void 0:rt(d.detail),mono:!!d.detailMono,focal:!!d.focal,col:i(d.col,`the column of ${S}`),row:E,row2:E,branch:!!d.branch,shape:m,group:j==="architecture"?rt(d.group):void 0,mark:j==="architecture"?ge(d.mark):void 0})}if(j==="architecture")for(const d of t.groups??[]){const m=String(d.id??"");_.push({id:m,label:String(d.label??""),members:f.filter(S=>S.group===m).map(S=>S.id)})}}else if(j==="data-flow"){O=(t.lanes??[]).map(m=>({id:String(m.id??""),label:String(m.label??"")}));const d=new Map(O.map((m,S)=>[m.id,S+1]));for(const m of t.nodes??[]){const S=String(m.id??""),E=String(m.lane??""),z=d.get(E);z===void 0&&o(`a node (${S}) names the lane "${E}", which is not in lanes`);const T=f.length+1;f.push({id:S,i:f.length,name:String(m.name??""),kind:h(T),detail:rt(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:i(m.col,`the column of ${S}`),row:z??1,row2:z??1,branch:!1,shape:"box",lane:z??1,laneLabel:O[(z??1)-1]?.label??E,step:T})}}else if(j==="sequence"){(t.participants??[]).forEach((m,S)=>{const E=String(m.name??"");f.push({id:String(m.id??""),i:S,name:E,kind:rt(m.kind),mono:!1,focal:!!m.focal,col:S+1,row:1,row2:1,branch:!1,shape:"participant",short:rt(m.short)??E})});let d=0;for(const m of t.steps??[])"band"in m?B.push({band:String(m.band??"")}):(d++,B.push({n:d,from:String(m.from??""),to:String(m.to??""),label:String(m.label??""),note:rt(m.note),kind:y(m.kind,`message ${d}`)}))}else if(j==="schema")for(const d of t.tables??[]){const m=String(d.name??""),[S,E]=Array.isArray(d.row)?d.row:[d.row,d.row],z=i(S,`the row of ${m}`),T=Math.max(z,i(E,`the last row of ${m}`)),G=d.more===void 0||d.more===null?void 0:Number.isInteger(d.more)&&d.more>0?d.more:(o(`${m}'s "more" is ${JSON.stringify(d.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:m,i:f.length,name:m,mono:!0,focal:!!d.focal,col:i(d.col,`the column of ${m}`),row:z,row2:T,branch:!1,shape:"table",more:G,columns:(d.columns??[]).map(N=>({name:String(N.name??""),type:rt(N.type),key:N.key==="PK"||N.key==="FK"?N.key:(N.key!==void 0&&N.key!==null&&o(`${m}.${String(N.name)}'s key is "${String(N.key)}", not PK or FK: it is left out`),void 0)}))})}const R=new Map;for(const d of f)d.id?R.has(d.id)&&o(`the id "${d.id}" is used twice`):o("a node has no id"),R.set(d.id,d);if(j==="schema")(t.tables??[]).forEach(d=>(d.columns??[]).forEach((m,S)=>{const E=rt(m.references);if(!E)return;const[z,T]=E.split("."),G=R.get(z??""),N=G?.columns?.findIndex(C=>C.name===T)??-1;if(!G||N<0){o(`${String(d.name)}.${String(m.name)} references ${E}, which is not a shown column`);return}const k=R.get(String(d.name??""));k.columns[S].ref={table:z,column:T,row:N},b.push({i:b.length,from:k.id,to:z,kind:"plain",fromRow:S,toRow:N,fk:!0})}));else if(j!=="sequence")for(const d of t.edges??[]){const m=String(d.from??""),S=String(d.to??"");if(!R.has(m)||!R.has(S)){o(`a line names ${R.has(m)?S:m}, which is not a node`);continue}const E=rt(d.label);E&&E.length>Ot&&o(`the label "${E}" is over ${Ot} characters: longer words belong in the node or the summary`),b.push({i:b.length,from:m,to:S,kind:y(d.kind,`the line from ${m} to ${S}`),label:E,fromSide:$(d.fromSide),toSide:$(d.toSide),flow:j!=="flowchart"&&d.flow===!0?!0:void 0})}else for(const d of B)"n"in d&&(!R.has(d.from)||!R.has(d.to))&&o(`message ${d.n} names ${R.has(d.from)?d.to:d.from}, which is not a participant`);if(s&&j!=="sequence"){const d=new Map;for(const m of f)for(let S=m.row;S<=m.row2;S++){const E=`${m.col}:${S}`;d.has(E)&&o(`${m.id} and ${d.get(E)} share the cell at column ${m.col}, row ${S}`),d.set(E,m.id)}}if(s){for(const m of _){const S=m.members.map(T=>R.get(T));if(!S.length)continue;const E={c1:Math.min(...S.map(T=>T.col)),c2:Math.max(...S.map(T=>T.col)),r1:Math.min(...S.map(T=>T.row)),r2:Math.max(...S.map(T=>T.row2))};for(const T of f)T.group!==m.id&&T.col>=E.c1&&T.col<=E.c2&&T.row>=E.r1&&T.row<=E.r2&&o(`${T.id} is inside the box of the group "${m.label}" but not a member`);const z=S.map(T=>T.i);Math.max(...z)-Math.min(...z)+1!==z.length&&o(`the members of the group "${m.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const m of f)m.group&&!_.some(S=>S.id===m.group)&&o(`${m.id} names the group "${m.group}", which is not in groups`);f.filter(m=>m.focal).length>1&&o("more than one node is focal: a diagram has one at most");const d=new Set(j==="sequence"?B.flatMap(m=>"n"in m?[m.kind]:[]):b.map(m=>m.kind));d.has("main")&&!l.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),d.has("dashed")&&!l.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(m=>m.focal)&&!l.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const Q=j==="architecture"||j==="data-flow",A=d=>Array.isArray(d)&&d.length>1?d.map(String):void 0,V=Q&&t.packet&&typeof t.packet=="object"?t.packet:void 0,v=V&&A(V.path),D={animated:t.motion==="animated",pulse:Q?A(t.pulse):void 0,packet:v?{path:v,repeat:V.repeat===!0,send:V.send}:void 0,run:j==="sequence"&&t.run===!0};if(s)for(const d of f){const m=d.mark?.says;if(!m?.length)continue;const S=[d.name,d.kind,d.detail].filter(Boolean).join(" ").toLowerCase();m.some(E=>S.includes(E.toLowerCase()))||o(`${d.id}'s mark stands for ${m.join(" or ")}, and none of its words say so`)}const L=Math.max(1,...f.map(d=>d.col)),x=j==="data-flow"?Math.max(1,O.length):Math.max(1,...f.map(d=>d.row2));return{type:j,title:String(t.title??""),heading:c,legend:l,nodes:f,byId:R,edges:b,groups:_,lanes:O,steps:B,cols:L,rows:x,shapeLabels:g,stepWord:h,warnings:r,motion:D,memo:new Map}}function ge(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=rt(e.onLight);if(n)return{onLight:n,onDark:rt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var It=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function wt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Ot=28,mt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function _t(t,e){return t.legend[e]}function me(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function ye(t,e){return wt(t,`sentence:${e.i}`,()=>be(t,e))}function be(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,r=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(mt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`)}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?me(t,e):e.kind;if(n.push(mt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(mt(e.detail)),e.group){const a=t.groups.find(l=>l.id===e.group);a&&n.push(`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${a.label})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${a.label})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(mt(t.legend.focal)),n.join(" ")}function $e(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function w(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var we={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>we[e]),xe=" br img input meta link hr path polygon polyline circle rect line ";function St(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return xe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>St(s,e)).join("")}`}var ve=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function gt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Me(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Ct(t){let e=0;for(const n of t.groups){const s=n.members.map(r=>t.byId.get(r).col);s.length&&(Math.min(...s)===1&&(e|=1),Math.max(...s)===t.cols&&(e|=2))}return(e&1)+(e>>1&1)}function Et(t){return t.type==="sequence"?t.nodes.length:t.cols}function Bt(t){return wt(t,"plan",()=>ke(t))}function ke(t){const e=t.nodes,n=i=>t.type==="data-flow"||!e[i].branch,s=t.edges.map(i=>{const f=t.byId.get(i.from).i,b=t.byId.get(i.to).i,_=e.slice(Math.min(f,b)+1,Math.max(f,b)).every(B=>!n(B.i));return b===f+1&&!(n(f)&&!n(b))?"down":b===f-1?"up":b>f&&n(f)&&!n(b)&&_?"trunk":b>f&&n(f)&&n(b)&&_?"rail":b>f?"end-down":"end-up"}),r=t.edges.map((i,f)=>({e:i,k:f})).filter(({k:i})=>s[i]==="end-down"||s[i]==="end-up"),o=i=>{const f=t.byId.get(i.from).i,b=t.byId.get(i.to).i;return[Math.min(f,b),Math.max(f,b)]},a=(i,f)=>{const[b,O]=o(i),[_,B]=o(f);return b{const f=t.byId.get(i.from).i,[b,O]=o(i);return!n(f)&&e.slice(b+1,O).every(_=>!n(_.i))&&r.every(_=>_.e===i||!a(_.e,i))}),p=r.length>0&&(t.type==="data-flow"||!l),h=i=>{const[f,b]=o(i);return b-f},u=t.edges.map(()=>0);let g=!1;const c=[];for(const i of[...r].sort((f,b)=>h(f.e)-h(b.e)||f.k-b.k)){let f=0;for(const b of c)a(b.e,i.e)&&(f=Math.max(f,u[b.k]+1));u[i.k]=f,f>1&&(g=!0),c.push(i)}const y=t.edges.map(()=>.5);for(const i of e){const f=r.filter(({e:_})=>_.from===i.id);if(f.length<2)continue;const b=f.filter(({k:_})=>s[_]==="end-down").sort((_,B)=>h(B.e)-h(_.e)||_.k-B.k);[...f.filter(({k:_})=>s[_]==="end-up").sort((_,B)=>h(_.e)-h(B.e)||B.k-_.k),...b].forEach(({k:_},B,j)=>{y[_]=j.length===2?B===0?1/3:2/3:(B+1)/(j.length+1)})}const $=ht();for(let i=1;i{const A=s[Q],V=t.byId.get(R.from).i,v=t.byId.get(R.to).i,D=v===i&&(A==="down"||A==="trunk"||A==="rail"||A==="end-down"),L=V===i&&v===i-1&&A==="up",x=v===i-1&&A==="end-up";D&&(A==="trunk"||A==="end-down")&&(B=!0),x&&(j=!0),(D||L||x)&&R.label&&(O++,_=Math.max(_,A==="trunk"?40:48))}),(O>1||B&&j)&&(_=64),$[f.id]=_}return{routes:s,gutter:p,lanes:u,exits:y,gaps:$,third:g}}var yt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function jt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return w("svg",{class:`${t}-swatch`,"data-kind":n,...yt(24,16)},e==="fk"?w("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,w("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?w("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):w("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function bt(t,e){return e==="decision"?w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Tt(t,e){return wt(e,`key:${t}`,()=>Ee(t,e))}var Se=Tt;function Ee(t,e){const n=[],s=(o,a,l={})=>n.push(w("li",{class:`${t}-entry`,...l},o,w("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),w("span",null,l)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(bt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(bt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(bt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(jt(t,o),a,{"data-line":""})}return e.type==="schema"&&e.edges.length&&(s(jt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(w("li",{class:`${t}-entry`,"data-when":"stacked"},w("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),w("span",null,"The table a foreign key references")))),e.nodes.some(o=>o.focal)&&e.legend.focal&&s(bt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(bt(t,"group"),e.legend.group),n.length?w("div",{class:`${t}-key`},w("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Ae(t,e){const n=e==="main"?6:6.5;return w("svg",{class:`${t}-arrow`,"data-kind":e,...yt(20,12)},w("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?w("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):w("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Le(t,e,n){if(n.shape==="decision")return[w("span",{class:`${t}-words`},w("span",{class:`${t}-name`},n.name))];const s=[];return e.type==="data-flow"?s.push(w("span",{class:`${t}-kind`},n.kind,w("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(w("span",{class:`${t}-kind`},n.kind)),s.push(w("span",{class:`${t}-name`},n.name)),n.detail&&s.push(w("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?vt(n.detail).flatMap((r,o)=>[o?" ":"",w("span",{class:`${t}-run`},r)]):n.detail)),s}function qe(t,e){return[w("span",{class:`${t}-th`},w("span",{class:`${t}-tname`},e.name)),w("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>w("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},w("span",{class:`${t}-keyseat`},n.key??""),w("span",{class:`${t}-cname`},n.name),n.ref?w("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?w("span",{class:`${t}-ctype`},n.type):null))),e.more?w("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Rt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=Me(e,s)||s.keep===n.id,a=gt(e,s),l=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&l.push(`--_lc:${n.col+1}`),e.type==="sequence"&&l.push(`--_c2:${n.col+1}`);const p=t.plan;if(p&&n.i>0){const c=pt(p.gaps,n.id)??32,y=pt(s.grow,n.id)??0;l.push(`--_gap:${y?`calc(${Rt(c)} + var(--basalt-space-4) * ${y})`:Rt(c)}`)}const h=pt(s.heights,n.id);h&&l.push(`--_h:${h}px`);const u=pt(s.words,n.id);u&&l.push(`--_ww:${u}px`);const g=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return w("div",{class:`${r}-node`,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:l.join(";"),role:o?"img":void 0,"aria-label":o?ye(e,n):void 0,tabindex:g},n.shape==="decision"?w("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},w("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?w("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${It(n.mark.onLight)};--_md:${It(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?qe(r,n):Le(r,e,n))}function Ie(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((a,l)=>w("div",{class:`${s}-lane`,style:`--_r:${l+1}`,"aria-hidden":"true"},w("span",{class:`${s}-lane-name`},a.label)))),e.type==="architecture")for(const a of e.groups){const l=a.members.map(c=>e.byId.get(c));if(!l.length)continue;const p=Math.min(...l.map(c=>c.col)),h=Math.max(...l.map(c=>c.col)),u=Math.min(...l.map(c=>c.row)),g=Math.max(...l.map(c=>c.row2));r.push(w("div",{class:`${s}-gbox`,"data-group":a.id,style:`--_c:${p};--_c2:${h+1};--_r:${u};--_r2:${g+1}`,"aria-hidden":"true"},w("span",{class:`${s}-glabel`},a.label)))}if(e.type==="sequence")return r.push(w("ul",{class:`${s}-cast`},e.nodes.map(a=>w("li",{class:`${s}-actor`},At(t,e,a,n))))),r.push(Oe(t,e)),r;let o=0;for(;ou.id===a.group):void 0;if(!l){r.push(At(t,e,a,n)),o++;continue}const p=[];for(;oAt(t,e,u,n))))}return r}function Oe(t,e){const{P:n}=t,s=[];let r=null;for(const o of e.steps){if("band"in o){r=null,s.push(w("p",{class:`${n}-band`},w("span",null,o.band)));continue}r||(r=w("ol",{class:`${n}-msgs`,start:o.n}),s.push(r));const a=e.byId.get(o.from),l=e.byId.get(o.to),p=a?.col??1,h=l?.col??1,u=p===h,g=u&&p===e.nodes.length,c=_t(e,o.kind);r.c.push(w("li",{class:`${n}-msg`,"data-kind":o.kind,"data-from":o.from,"data-to":o.to,"data-self":u?g?"start":"end":void 0,style:`--_a:${Math.min(p,h)};--_b:${Math.max(p,h)+1}`},w("span",{class:`${n}-said`},w("span",{class:`${n}-num`},String(o.n)),w("span",{class:`${n}-mlabel`},o.label)),w("span",{class:`${n}-route`},a?.short??o.from," ",Ae(n,o.kind),w("span",{class:t.hidden}," to ")," ",l?.short??o.to,c?` · ${c}`:""),o.note?w("span",{class:`${n}-note`},o.note):null))}return w("div",{class:`${n}-steps`},s)}function Ft(t,e){return wt(e,`list:${t}`,()=>Ce(t,e))}var _e=Ft;function Ce(t,e){const n=Math.min(6,e.heading+1),s=u=>w(`h${n}`,{class:`${t}-list-head`},u),r=u=>w("strong",null,u),o=u=>w("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,l=u=>{const g=_t(e,u);return g?` (${g})`:""},p=u=>u.focal&&e.legend.focal?` ${mt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=y=>w("li",null,r(y.name),y.kind?`, ${y.kind}`:"",y.detail?[". ",y.mono?o(y.detail):y.detail,/[.!?]$/.test(y.detail)?"":"."]:/[.!?]$/.test(y.kind??y.name)?"":".",p(y)),g=[s("Parts")],c=e.nodes.filter(y=>!y.group);c.length&&g.push(w("ul",{class:`${t}-list-items`},c.map(u)));for(const y of e.groups)g.push(w("p",{class:`${t}-list-group`},y.label)),g.push(w("ul",{class:`${t}-list-items`},y.members.map($=>u(e.byId.get($)))));return g.push(s("Connections")),g.push(w("ol",{class:`${t}-list-items`},e.edges.map(y=>w("li",null,r(a(y.from))," to ",r(a(y.to)),y.label?[": ",o(y.label)]:"",`${l(y.kind)}.`)))),g}if(e.type==="flowchart"){const u=g=>(e.byId.get(g)?.i??0)+1;return[w("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const c=e.edges.filter(i=>i.from===g.id),y=g.shape==="decision"?"Decision":g.shape==="terminal"?c.length?"Start":"End":"Step",$=!g.detail&&/[.!?]$/.test(g.name)?" ":". ";return w("li",null,r(g.name),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",`${$}${y}.`,p(g),c.length?w("ul",{class:`${t}-list-exits`},c.map(i=>w("li",null,i.label?`If ${i.label}: go to ${u(i.to)}, `:`Then: go to ${u(i.to)}, `,r(a(i.to)),l(i.kind)))):null)}))]}if(e.type==="data-flow")return[w("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const g=e.edges.filter(c=>c.from===u.id);return w("li",null,`${u.laneLabel}: `,r(u.name),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",p(u),g.length?[" Then ",...g.flatMap((c,y)=>[y?"; ":"",`to step ${e.byId.get(c.to).step}, `,r(a(c.to)),c.label?[": ",o(c.label)]:"",l(c.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),w("ul",{class:`${t}-list-items`},e.nodes.map(c=>w("li",null,r(c.name),c.kind?`, ${c.kind}`:"",".",p(c))))];u.push(s("Messages"));let g=null;for(const c of e.steps){if("band"in c){g=null,u.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},c.band));continue}g||(g=w("ol",{class:`${t}-list-items`,start:c.n}),u.push(g)),g.c.push(w("li",null,o(c.label),": ",r(a(c.from))," to ",r(a(c.to)),`${l(c.kind)}.`,c.note?` ${mt(c.note)}`:""))}return u}const h=[];for(const u of e.nodes)h.push(w(`h${n}`,{class:`${t}-list-group`},o(u.name),p(u))),h.push(w("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(g=>w("li",null,o(g.name),g.key==="PK"?", primary key":g.key==="FK"?", foreign key":"",g.ref?[", references ",o(`${g.ref.table}.${g.ref.column}`)]:g.type?`, ${g.type}`:"")),...u.more?[w("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return h}function Ht(t){return`Arrow keys move to the next or the previous ${t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step"}, in the author's order; Home and End go to the ends; Escape clears the trace.`}function zt(t){return[{keys:["←","→"],words:$e(t)},{keys:["Home","End"],words:"the ends"},{keys:["Esc"],words:"clear"}]}var Nt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Wt(t,e,n){const s=n.prefix,r=ve(n.base),o=t.type==="sequence"||t.type==="schema"?null:Bt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},l=e.layout==="drawn",p=gt(t,e),h=t.type==="sequence"||t.type==="schema"?l:!0,u=`h${t.heading}`,g=[`--_cols:${Et(t)}`];if(t.type==="architecture"&&t.groups.length||l&&e.pad){const c=t.type==="architecture"?t.groups.flatMap(i=>i.members.map(f=>t.byId.get(f))):[],y=(i,f,b)=>i?`var(--basalt-space-${f})`:b?`var(--basalt-space-${b})`:"0px",$=l&&e.pad?"3":void 0;g.push(`--_gpad:${y(c.some(i=>i.row===1),"8",$)} ${y(c.some(i=>i.col===t.cols),"4")} ${y(c.some(i=>i.row2===t.rows),"4",$)} ${y(c.some(i=>i.col===1),"4")}`)}return Nt(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),w("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Et(t),"data-reach":t.type==="architecture"?Ct(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},w("div",{class:`${s}-head`},w(u,{id:r.title,class:`${s}-title`},t.title),n.hasSource?w("p",{class:`${s}-source`},{slot:"source"}):null),w("div",{class:`${s}-drawing`,role:h?"group":void 0,"aria-roledescription":h?"diagram":void 0,"aria-labelledby":h?r.title:void 0,"aria-describedby":h?p?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":p?"":void 0},Ie(a,t,e),w("div",{class:`${s}-ink`,"aria-hidden":"true"}),w("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Tt(s,t),w("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),w("div",{class:`${s}-foot`},{slot:"toggle"}),w("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Ft(s,t)),w("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Ht(t)} ${n.viewer}`:Ht(t)),w("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Be(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4)}}var xt=(t,e)=>t==="main"?e.line:e.hair,ct=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},dt=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Dt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function it(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,l=(s+o)/2,p=(r+a)/2,h=(o-s)/2,u=(a-r)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const $=n,i=u*Math.max(0,1-Math.abs($-l)/h);return{x:$,y:e==="top"?p-i:p+i}}const c=n,y=h*Math.max(0,1-Math.abs(c-p)/u);return{x:e==="left"?l-y:l+y,y:c}}if(t.shape==="terminal"){const c=Math.min(h,u);if(g){const f=n,b=Math.min(Math.max(f,s+c),o-c),O=f-b,_=Math.abs(O)>=c?0:Math.sqrt(c*c-O*O);return{x:f,y:Math.abs(O)<1e-6?e==="top"?r:a:e==="top"?p-_:p+_}}const y=n,$=y-p,i=Math.abs($)>=c?0:Math.sqrt(c*c-$*$);return{x:e==="left"?s+c-i:o-c+i,y}}return g?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function je(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,l=(s+o)/2,p=(r+a)/2,h=(o-s)/2,u=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-l)/h+Math.abs(t.y-p)/u<1-n/Math.min(h,u);if(e.shape==="terminal"){const g=Math.min(h,u),c=Math.min(Math.max(t.x,s+g),o-g);return Math.hypot(t.x-c,t.y-p)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Fe(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var vt=t=>t?t.split(/\s+/).filter(Boolean):[];function He(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const p of t.nodes){if(p.shape==="table"){for(const y of p.columns??[]){const $=y.ref?`→ ${y.ref.table}`:y.type??"",i=s("6")+n(y.name,"mono")+($?s("3")+n($,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(i))}o=Math.max(o,Math.ceil(n(p.name,"table")+2*s("3")+2*e.hair));continue}const h=p.shape==="terminal"?2*s("5"):2*s("3"),u=p.mark&&!Re()?s("6"):0;let g=0;for(const y of vt(p.name))g=Math.max(g,n(y,p.shape==="decision"?"name-500":"name")+(p.kind?0:u));if(t.type!=="data-flow")for(const y of vt(p.kind))g=Math.max(g,n(y,"mono")+u);for(const y of vt(p.detail))g=Math.max(g,n(y,p.mono?"mono":"sans"));const c=p.shape==="decision"?g/.62:g+h+2*e.hair;r=Math.max(r,Math.ceil(c))}const a=Et(t);let l;return t.type==="data-flow"?l=e.lane+a*(r+s("12")):t.type==="schema"?l=a*o+(a-1)*s("12")+(Nt(t)?s("5"):0):t.type==="sequence"?l=a*r+(a-1)*s("5"):l=a*r+(a-1)*s("16")+Ct(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,l)}}function Kt(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Lt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Vt(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const p=r[r.length-2];if(Math.abs(p.x-l.x)<.01&&Math.abs(l.x-a.x)<.01||Math.abs(p.y-l.y)<.01&&Math.abs(l.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ft=t=>t.slice(1).map((e,n)=>[t[n],e]);function Mt(t,e,n){const s=[];for(let o=0;oMath.min(i.x,f.x)+.75&&_Math.min(b.y,O.y)+.75&&Br.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const l=[];let p=o;for(const h of r)l.push([p,p+h]),p+=h+a;return l};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var Y=t=>t==="left"||t==="right",Zt={top:"bottom",bottom:"top",left:"right",right:"left"};function Ne(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function We(t,e,n){const s=[];t.edges.forEach((o,a)=>{const l=t.byId.get(o.from),p=t.byId.get(o.to),[h,u]=e[a],g=l.row===p.row&&Y(h)&&Y(u)&&h===Zt[u]||l.col===p.col&&!Y(h)&&!Y(u)&&h===Zt[u];s.push({edge:a,end:"from",node:l,side:h,far:p,straight:g,f:.5},{edge:a,end:"to",node:p,side:u,far:l,straight:g,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const l=i=>Y(i.side)?i.far.row-i.node.row:i.far.col-i.node.col,p=a.filter(i=>i.straight),h=a.filter(i=>!i.straight);if(h.sort((i,f)=>l(i)-l(f)||(Y(i.side)?i.far.col-f.far.col:i.far.row-f.far.row)*(l(i)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!p.length){h.length===2?(h[0].f=.25,h[1].f=.75):h.length===3?(h[0].f=.25,h[1].f=.5,h[2].f=.75):h.length>3&&h.forEach((i,f)=>{i.f=(f+1)/(h.length+1)});continue}const u=new Map;for(const i of p)u.has(i.far.id)||u.set(i.far.id,[]),u.get(i.far.id).push(i);for(const i of u.values())i.length>1&&i.sort((f,b)=>f.edge-b.edge).forEach((f,b)=>{f.f=i.length===2?b===0?.25:.75:(b+1)/(i.length+1)});const g=Math.min(...p.map(i=>i.f)),c=Math.max(...p.map(i=>i.f)),y=h.filter(i=>l(i)<0),$=h.filter(i=>l(i)>=0);y.forEach((i,f)=>{i.f=g*(f+1)/(y.length+1)}),$.forEach((i,f)=>{i.f=c+(1-c)*(f+1)/($.length+1)})}return s}function Jt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return Y(e)?it(t,e,r+(a-r)*n):it(t,e,s+(o-s)*n)}function Ut(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ct(o,n),shape:a.shape,i:a.i})}),r}function Xt(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var Yt=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Qt(t,e,n,s){const r=(o,a)=>{const l=o+a-Math.floor(o+a);return l<.005||l>.995?[0]:l<=.5?[-l,1-l]:[1-l,-l]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const l={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(l))return l}return t}function De(t,e,n,s,r,o,a,l,p){const h=a.space,u=[],g=[],c=[],y=[],$=h("1"),i=e.filter(f=>t.edges[f.i]?.label).sort((f,b)=>+(t.edges[b.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-b.i);for(const f of i){const b=t.edges[f.i].label,O=l(b,"label"),_=16,B=f.pts.length-2,j=[];ft(f.pts).forEach(([v,D],L)=>{const x=Math.abs(v.y-D.y)<.01,d=x?v.x:v.y;let m=x?D.x:D.y;const S=Math.sign(m-d)||1;L===B&&(m-=S*a.head);let E=[[d,m]];for(const G of r)for(const N of x?[G.l,G.r]:[G.t,G.b]){const k=x?v.y:v.x;(x?k>G.t&&kG.l&&kN>Math.min(q,M)+1&&N{const k=(G+N)/2,C=x?{x:k,y:v.y}:{x:v.x,y:k};return!r.some(q=>C.x>q.l&&C.xq.t&&C.y1&&z(G,N)?1:0})}),j.sort((v,D)=>D.pri-v.pri||D.len-v.len);let R=null,Q=!1;const A=(v,D=!0)=>{const L=Dt(v,$);return D&&(v.lo.r||v.to.b)||n.some(x=>Gt(L,x))||u.some(x=>dt(L,x))||s.heads.some(x=>dt(L,x))||s.rects.some(x=>dt(L,x))?!1:!e.some(x=>x.i!==f.i&&ft(x.pts).some(([d,m])=>dt(L,Yt(d,m,x.width))))};for(const v of j){for(const D of[1/2,1/3,2/3]){const L=v.p+(v.q-v.p)*D,x=[],d=h("2")+f.width/2;if(v.horiz?(v.len>=O+2*h("1")+h("3-5")&&x.push({box:{l:L-O/2-h("1"),r:L+O/2+h("1"),t:v.c-_/2,b:v.c+_/2},on:!0}),x.push({box:{l:L-O/2,r:L+O/2,t:v.c-d-_,b:v.c-d},on:!1}),x.push({box:{l:L-O/2,r:L+O/2,t:v.c+d,b:v.c+d+_},on:!1})):(v.len>=_+h("3")&&x.push({box:{l:v.c-O/2-h("1"),r:v.c+O/2+h("1"),t:L-_/2,b:L+_/2},on:!0}),x.push({box:{l:v.c+d,r:v.c+d+O,t:L-_/2,b:L+_/2},on:!1}),x.push({box:{l:v.c-d-O,r:v.c-d,t:L-_/2,b:L+_/2},on:!1})),R=x.find(m=>A(m.box))??null,R)break;!Q&&x.some(m=>A(m.box,!1))&&(Q=!0)}if(R)break}if(!R){c.push(f.i),Q&&y.push(f.i);continue}const V=Qt(R.box,p.ox,p.oy,v=>A(v));u.push(V),g.push({i:f.i,text:b,box:V,on:R.on})}return{labels:g,unseated:c,bounded:y}}function Pt(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const l=ct(a,e);o.push(l),r.push({l:l.l,r:l.r,t:l.t,b:l.t+1},{l:l.l,r:l.r,t:l.b-1,b:l.b},{l:l.l,r:l.l+1,t:l.t,b:l.b},{l:l.r-1,r:l.r,t:l.t,b:l.b});const p=a.querySelector(`:scope > .${n}-glabel`);p&&p.getClientRects().length&&r.push(ct(p,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,l)=>{if(!a.getClientRects().length)return;const p=ct(a,e);l>0&&r.push({l:p.l,r:p.r,t:p.t-s/2-.5,b:p.t-s/2+.5});const h=a.querySelector(`.${n}-lane-name`);h&&r.push(ct(h,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function Ge(t,e){const{m:s,tk:r,P:o,drawing:a,origin:l,warn:p}=t,h=r.space,u=Ut(s,a,l,o),g=[...u.values()],c=ze(a),y=l.left-Math.floor(l.left),$=l.top-Math.floor(l.top),i=Kt(y,$),f=a.clientWidth,b=a.clientHeight,O=k=>s.type==="data-flow"?k.col+1:k.col,_=parseFloat(getComputedStyle(a).rowGap)||0,B={w:f,h:b,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:y,oy:$};if(s.type==="sequence")return Ve(t,B,i);let j,R=[];s.type==="schema"?j=s.edges.map(k=>{const C=s.byId.get(k.from),q=s.byId.get(k.to);if(C.col===q.col){const M=C.col===s.cols&&s.cols>1?"left":"right";return[M,M]}return q.col>C.col?["right","left"]:["left","right"]}):(j=s.edges.map(k=>{const C=s.byId.get(k.from),q=s.byId.get(k.to),[M,I]=Ne(C,q);return[k.fromSide??M,k.toSide??I]}),R=We(s,j,p||(()=>{})));const Q=(k,C)=>{const q=a.querySelector(`.${o}-node[data-node="${CSS.escape(k)}"] .${o}-row[data-row="${C}"]`);if(!q)return 0;const M=ct(q,l);return(M.t+M.b)/2},A=s.edges.map((k,C)=>{const[q,M]=j[C],I=u.get(k.from),F=u.get(k.to),Z=xt(k.kind,r);if(k.fk){const J=Q(k.from,k.fromRow),et=Q(k.to,k.toRow),U=i.y(J,Z),nt=i.y(et,Z);return{p1:{x:q==="right"?I.rect.r:I.rect.l,y:U},p2:{x:M==="right"?F.rect.r:F.rect.l,y:nt},r1:J,r2:Math.abs(U-nt)<.01?J:et}}const P=R.find(J=>J.edge===C&&J.end==="from").f,X=R.find(J=>J.edge===C&&J.end==="to").f;let W=Jt(I,q,P),K=Jt(F,M,X);const ot=Y(q)?W.y:W.x;let tt=Y(M)?K.y:K.x;return Y(q)?W={...W,y:i.y(W.y,Z)}:W={...W,x:i.x(W.x,Z)},Y(M)?K={...K,y:i.y(K.y,Z)}:K={...K,x:i.x(K.x,Z)},Y(q)&&Y(M)&&Math.abs(W.y-K.y)<1.01&&(K={...K,y:W.y},tt=ot),!Y(q)&&!Y(M)&&Math.abs(W.x-K.x)<1.01&&(K={...K,x:W.x},tt=ot),W=Y(q)?it(I,q,W.y):it(I,q,W.x),K=Y(M)?it(F,M,K.y):it(F,M,K.x),{p1:W,p2:K,r1:ot,r2:tt}}),V=new Set;s.type==="schema"&&s.edges.forEach((k,C)=>{Math.abs(s.byId.get(k.from).col-s.byId.get(k.to).col)>1&&V.add(C)});const v=new Map,D=new Set;s.edges.forEach((k,C)=>{if(V.has(C))return;const[q,M]=j[C],{p1:I,p2:F}=A[C],Z=s.byId.get(k.from),P=s.byId.get(k.to);let X=null,W=null,K=!1;if(q===M){if(Y(q)){const J=q==="right"?Math.max(O(Z),O(P)):Math.min(O(Z),O(P))-1,et=c.cols[J-1],U=c.cols[J];et&&U&&(X=`c${J}`,W=[et[1],U[0]],K=!0)}else{const J=q==="bottom"?Math.max(Z.row2,P.row2):Math.min(Z.row,P.row)-1,et=c.rows[J-1],U=c.rows[J];et&&U&&(X=`r${J}`,W=[et[1],U[0]],K=!1)}X&&D.add(C)}else if(Y(q)&&Y(M)&&Math.abs(I.y-F.y)>.5){const J=O(P),et=M==="left",U=c.cols[(et?J-1:J)-1],nt=c.cols[(et?J:J+1)-1];U&&nt&&(X=`c${et?J-1:J}`,W=[U[1],nt[0]],K=!0)}else if(!Y(q)&&!Y(M)&&Math.abs(I.x-F.x)>.5){const et=M==="top"?P.row-1:P.row2,U=c.rows[et-1],nt=c.rows[et];U&&nt&&(X=`r${et}`,W=[U[1],nt[0]],K=!1)}if(!X||!W)return;v.has(X)||v.set(X,{span:W,vertical:K,members:new Map});const ot=`${k.to}.${M}.${Math.round(K?F.y:F.x)}`,tt=v.get(X);tt.members.has(ot)||tt.members.set(ot,[]),tt.members.get(ot).push(C)});const L=new Map,x=k=>{const[C,q]=j[k],{p1:M,p2:I}=A[k];if(Y(C)&&Y(q)){if(C===q){const Z=L.get(k)??(C==="right"?Math.max(M.x,I.x)+h("4"):Math.min(M.x,I.x)-h("4"));return[M,{x:Z,y:M.y},{x:Z,y:I.y},I]}if(Math.abs(M.y-I.y)<=.5)return[M,{x:I.x,y:M.y}];const F=L.get(k)??(M.x+I.x)/2;return[M,{x:F,y:M.y},{x:F,y:I.y},I]}if(!Y(C)&&!Y(q)){if(C===q){const Z=L.get(k)??(C==="bottom"?Math.max(M.y,I.y)+h("4"):Math.min(M.y,I.y)-h("4"));return[M,{x:M.x,y:Z},{x:I.x,y:Z},I]}if(Math.abs(M.x-I.x)<=.5)return[M,{x:M.x,y:I.y}];const F=L.get(k)??(M.y+I.y)/2;return[M,{x:M.x,y:F},{x:I.x,y:F},I]}return Y(C)?[M,{x:I.x,y:M.y},I]:[M,{x:M.x,y:I.y},I]},d=k=>{const C=s.edges[k],q=xt(C.kind,r),M=x(k),I=Vt(M,q,i);let F;return M.length===I.length&&(F=ft(M).map(([Z,P])=>Math.abs(Z.y-P.y)<.75?(Z.y+P.y)/2:(Z.x+P.x)/2),F[0]=A[k].r1,F.length>1&&(F[F.length-1]=A[k].r2)),{i:k,from:C.from,to:C.to,kind:C.kind,pts:I,tip:I[I.length-1],dir:Lt(I),dot:C.fk?I[0]:void 0,width:q,axes:F}},m=()=>s.edges.flatMap((k,C)=>V.has(C)?[]:[d(C)]);let S=null;const E=k=>{S??(S=m());const C=S.map(q=>k.has(q.i)?d(q.i):q);return{lines:C,score:Ke(C,k)*1e5+Mt(C,void 0,k).length*1e3+qt(C.filter(q=>k.has(q.i)),g,s).length}},z=(k,C)=>{const q=k.flatMap(M=>{const{p1:I,p2:F}=A[M];return C?[I.y,F.y]:[I.x,F.x]});return[Math.min(...q),Math.max(...q)]};for(const[,k]of v){const C=[...k.members.values()].map(M=>({members:M,run:z(M,k.vertical)})).sort((M,I)=>M.run[0]-I.run[0]),q=[];for(const M of C){const I=q[q.length-1];I&&I.some(F=>F.run[0]D.has(ot)))continue;const I=M.map(ot=>ot.members),F=I.length,Z=(k.span[1]-k.span[0])/(F+1);ZJ.forEach(U=>L.set(U,k.span[0]+Z*(et+1))));const tt=E(P);tt.scoreot.forEach(J=>L.set(J,k.span[0]+Z*(tt+1)))),S=K}}B.lines=m();for(const k of V)p?.(`${s.edges[k].from} to ${s.edges[k].to} is two columns apart, so its line is not drawn; its row still writes the target`);B.crossings=Mt(B.lines),B.through=qt(B.lines,g,s),B.outside=ne(B.lines,f,b,r);const{obstacles:T,groups:G}=Pt(a,l,o,_);T.heads=B.lines.map(k=>Xt(k,r));const N=De(s,B.lines,g,T,G,{l:0,t:0,r:f,b},r,e,{ox:y,oy:$});return B.labels=N.labels,B.unseated=N.unseated,B.bounded=N.bounded,B.overlaps=[...new Set(te(B.lines,null).flat())],B}function Ke(t,e){return te(t,e).length}function te(t,e){const n=[];for(let s=0;s=l)continue;const[f,b]=c?[p.x,h.x]:[p.y,h.y],[O,_]=c?[u.x,g.x]:[u.y,g.y];Math.min(Math.max(f,b),Math.max(O,_))-Math.max(Math.min(f,b),Math.min(O,_))>1&&n.push([o.i,a.i])}}return n}function*ee(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const p=l===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-p<-.5||a.x+p>e+.5||a.y-p<-.5||a.y+p>n+.5})&&r.push(o.i);return r}function qt(t,e,n){const s=[];for(const r of t){const o=ft(r.pts);e.some(a=>o.some(([l,p])=>Te(l,p,a)))&&s.push(r.i)}return s}function Ve(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:l}=t,p=r.space,h=new Map;a.querySelectorAll(`.${o}-node`).forEach($=>h.set($.dataset.node,ct($,l)));const u=a.querySelector(`.${o}-steps`),g=u?ct(u,l).b:e.h,c=$=>{const i=h.get($);return i?n.x((i.l+i.r)/2,r.hair):0};for(const $ of s.nodes){const i=h.get($.id);i&&e.lifelines.push({x:c($.id),y1:i.b,y2:g})}const y=$=>h.get($.id);return a.querySelectorAll(`.${o}-msg`).forEach($=>{const i=$.dataset.from,f=$.dataset.to,b=$.dataset.kind??"plain",O=xt(b,r),_=ct($,l),B=n.y((_.t+_.b)/2,O),j=Number($.querySelector(`.${o}-num`)?.textContent??0),R=c(i),Q=c(f);let A;if(i===f){const m=$.dataset.self==="start"?-p("6"):p("6"),S=n.y(B-p("2"),O),E=n.y(B+p("2"),O);A=[{x:R,y:S},{x:n.x(R+m,O),y:S},{x:n.x(R+m,O),y:E},{x:R,y:E}]}else A=[{x:R,y:B},{x:Q,y:B}];e.lines.push({i:j,from:i,to:f,kind:b,pts:A,tip:A[A.length-1],dir:Lt(A),width:O});const V=$.querySelector(`.${o}-said`),v=$.querySelector(`.${o}-note`),D=s.byId.get(i),L=s.byId.get(f);if(!D||!L)return;const x=i===f?(()=>{const m=s.nodes[D.i+($.dataset.self==="start"?-1:1)],S=m?c(m.id):$.dataset.self==="start"?0:e.w;return Math.abs(S-R)-p("6")-p("2-5")-p("2")})():Math.abs(Q-R)-2*p("2");Math.max(V?V.getBoundingClientRect().width:0,v?v.getBoundingClientRect().width:0)>x+.5&&e.unseated.push(j)}),e}function oe(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:l,origin:p}=t,h=o.space,u=Ut(r,l,p,a),g=[...u.values()],c=p.left-Math.floor(p.left),y=p.top-Math.floor(p.top),$=Kt(c,y),i=l.clientWidth,f=l.clientHeight,b={w:i,h:f,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:y},O=ht();if(r.type==="sequence"||r.type==="schema")return{geo:b,grow:O};const _=i-(parseFloat(getComputedStyle(l).paddingRight)||0),B=(x,d,m)=>{const S=[x];for(let E=1;E<=(pt(s,d)??0);E++)S.push({...x,t:x.t+m*h("4")*E,b:x.b+m*h("4")*E});return S},j=new Map;l.querySelectorAll(`.${a}-node`).forEach(x=>{const d=x.parentElement,m=ct(d,p),S=getComputedStyle(d);j.set(x.dataset.node,m.r-(parseFloat(S.paddingRight)||0)-(parseFloat(S.borderRightWidth)||0))});const R=r.nodes,Q=x=>u.get(R[x].id),A=[],V=x=>xt(r.edges[x].kind,o);r.edges.forEach((x,d)=>{const m=n.routes[d],S=u.get(x.from),E=u.get(x.to),z=V(d);let T=[];const G=x.label,N=G?e(G,"label"):0,k=16,C=h("4");if(m==="down"||m==="up"){const M=Math.max(S.rect.l,E.rect.l),I=Math.min(S.rect.r,E.rect.r),F=r.edges.map((W,K)=>({o:W,j:K})).filter(({o:W,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(W.from===x.from&&W.to===x.to||W.from===x.to&&W.to===x.from)),Z=F.findIndex(W=>W.j===d),P=F.length<2?.5:F.length===2?Z===0?.25:.75:(Z+1)/(F.length+1),X=$.x(M+(I-M)*P,z);if(T=m==="down"?[it(S,"bottom",X),it(E,"top",X)]:[it(S,"top",X),it(E,"bottom",X)],G){let W=Math.min(T[0].y,T[1].y),K=Math.max(T[0].y,T[1].y);m==="down"?K-=o.head:W+=o.head;const ot=[...l.querySelectorAll(`.${a}-group`)].map(U=>ct(U,p));let tt=[[W,K]];for(const U of ot)for(const nt of[U.t,U.b])tt=tt.flatMap(([at,H])=>nt>at+1&&ntot.some(at=>(U+nt)/2>at.t&&(U+nt)/2at.l&&X1){const U=tt.filter(([at,H])=>!J(at,H));[W,K]=(U.length?U:tt).reduce((at,H)=>H[1]-H[0]>at[1]-at[0]?H:at)}const et=[1/2,1/3,2/3].map(U=>{const nt=W+(K-W)*U;return{l:X-N/2-h("1"),r:X+N/2+h("1"),t:nt-k/2,b:nt+k/2}});A.push({k:d,cands:et,on:!0,card:m==="down"?x.to:x.from})}}else if(m==="trunk"||m==="rail"){const M=$.x(Math.max(S.rect.l,m==="rail"?E.rect.l:S.rect.l)+h(m==="trunk"?"8":"3"),z),I=it(S,"bottom",M);if(m==="rail"){if(T=[I,it(E,"top",M)],G){const F=E.rect.t-h("6");A.push({k:d,cands:B({l:M+h("2-5"),r:M+h("2-5")+N,t:F-k/2,b:F+k/2},x.to,-1),on:!1,card:x.to})}}else{const F=$.x(E.rect.l+h("6"),z),Z=$.y(E.rect.t-C,z);T=[I,{x:M,y:Z},{x:F,y:Z},it(E,"top",F)],G&&A.push({k:d,cands:B({l:F+h("2-5"),r:F+h("2-5")+N,t:Z-k/2,b:Z+k/2},x.to,-1),on:!1,card:x.to})}}else{const M=Math.min(j.get(x.from)??i,j.get(x.to)??i),I=$.x(n.gutter?_+(n.lanes[d]?2*h("3-5"):h("3-5")):M-h("2-5"),z),F=$.y(S.rect.t+(S.rect.b-S.rect.t)*n.exits[d],z),Z=it(S,"right",F),P=$.x(E.rect.r-h("6"),z),X=m==="end-down",W=$.y(X?E.rect.t-C:E.rect.b+C,z);T=[Z,{x:I,y:Z.y},{x:I,y:W},{x:P,y:W},it(E,X?"top":"bottom",P)];const K=X?x.to:R[E.i+1]?.id??x.to;G&&A.push({k:d,cands:B({l:P-h("2-5")-N,r:P-h("2-5"),t:W-k/2,b:W+k/2},K,X?-1:1),on:!1,card:K})}const q=Vt(T,z,$);b.lines.push({i:d,from:x.from,to:x.to,kind:x.kind,pts:q,tip:q[q.length-1],dir:Lt(q),width:z})}),b.crossings=Mt(b.lines),b.through=qt(b.lines,g,r),b.outside=ne(b.lines,i,f,o);const{obstacles:v}=Pt(l,p,a,0);v.heads=b.lines.map(x=>Xt(x,o));const D=[],L={l:0,t:0,r:i,b:f};for(const x of A){const d=E=>{const z=Dt(E,h("1"));return E.lL.r+.5||E.tL.b+.5||g.some(T=>Gt(z,T))||D.some(T=>dt(z,T))||v.heads.some(T=>dt(z,T))||v.rects.some(T=>dt(z,T))||b.lines.some(T=>T.i!==x.k&&ft(T.pts).some(([G,N])=>dt(z,Yt(G,N,T.width))))},m=x.cands.find(E=>!d(E));m||(O[x.card]=(O[x.card]??0)+1,b.unseated.push(x.k));const S=m?Qt(m,c,y,E=>!d(E)):x.cands[0];D.push(S),b.labels.push({i:x.k,text:r.edges[x.k].label,box:S,on:x.on})}return{geo:b,grow:O}}function Ze(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...B})),g=u[u.length-1];g.x-=o.x*h,g.y-=o.y*h;const c=e.tip.x-o.x*l,y=e.tip.y-o.y*l,$=-o.y*p,i=o.x*p,f=B=>Math.round(B*100)/100,b=lt(e.kind),O=a?``:``,_=e.dot?``:"";return`${O}${_}`}function se(t,e,n,s){const r=new Map,o=new Map;for(const l of e.crossings)o.has(l.under)||o.set(l.under,[]),o.get(l.under).push(l);let a="";for(const[l,p]of o){const h=`${s}-cut-${l}`;r.set(l,h);const u=p.map(g=>{const c=e.lines[g.top],y=e.lines[g.under],$=c.width/2+n.cut,i=y.width/2+1;return g.underVertical?``:``}).join("");a+=`${u}`}return{defs:a,ids:r}}function ae(t,e,n,s){const{defs:r,ids:o}=se(t,e,n,s),a=e.lifelines.map(u=>``).join(""),l=e.lines.map((u,g)=>Ue(t,u,n,o.get(g)??null,u.from===u.to?n.radiusXs:n.radius)).join(""),p=`${r?`${r}`:""}${a}${l}`,h=e.labels.map(u=>`${lt(u.text)}`).join("");return p+h}function re(t,e,n,s,r,o,a,l){const h=t.querySelector(`.${n}-drawing`);if(!h||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const u=Be(t),g=Fe(h,n),c=He(e,u,g);l?.(c.least);const y=t.clientWidth,$=(()=>{const v=document.activeElement;return v&&h.contains(v)&&v.dataset.node?v.dataset.node:void 0})(),i=v=>gt(e,v)?{...v,stop:v.stop&&e.byId.has(v.stop)?v.stop:e.nodes[0]?.id,keep:void 0}:{...v,stop:v.stop??e.nodes[0]?.id,keep:$&&v.layout!=="drawn"?$:void 0};let f=!1;const b=v=>{if(f=!1,e.type!=="flowchart")return v;o({...v,heights:void 0,words:void 0});const D=ht(),L=ht();return h.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const d=x.querySelector(`.${n}-words`);if(!d)return;const m=x.getBoundingClientRect(),S=T=>{const G={w:T.width+2*u.space("2-5"),h:T.height+2*u.space("2")},N=1-G.w/m.width,k=N>.05?G.h/2/N:G.h*10;return Math.max(u.space("16"),Math.ceil(m.width/5),Math.ceil(2*k))},E=d.getBoundingClientRect();let z=S(E);if(z>m.width){const T=C=>(x.style.setProperty("--_ww",`${C}px`),d.getBoundingClientRect()),G=Math.floor(x.clientWidth-2*u.space("2-5"));let N=Math.ceil(E.width),k=E.height;for(;N1;){const F=C+q>>1;T(F).heightm.width&&(f=!0)}),{...v,heights:D,words:Object.keys(L).length?L:void 0}},O=()=>({m:e,tk:u,P:n,drawing:h,origin:h.getBoundingClientRect(),warn:a}),_=r.autoOpen?{open:!1,autoOpen:void 0}:{},B=(v,D)=>D.map(L=>$t(e,v.lines.find(x=>x.i===L))).join(", ");if(y>=c.least){const v=d=>{let m=i({...r,..._,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:d||void 0});return m=b(m),o(m),{dd:m,g:Ge(O(),g)}};let{dd:D,g:L}=v(!1);const x=d=>d.through.length>0||d.outside.length>0||(d.overlaps?.length??0)>0||f;if(!x(L)&&L.unseated.length&&L.unseated.every(d=>L.bounded?.includes(d))){const d=v(!0);!x(d.g)&&!d.g.unseated.length&&({dd:D,g:L}=d)}if(!x(L)&&!L.unseated.length)return L.crossings.length&&a?.(`${L.crossings.length} crossing${L.crossings.length===1?"":"s"} in the drawn layout: ${L.crossings.map(d=>`${$t(e,L.lines[d.top])} over ${$t(e,L.lines[d.under])}`).join("; ")}`),{dyn:D,geo:L,ink:ae(n,L,u,s),tokens:u,least:c.least};f&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: a decision would be taller than it is wide`),L.through.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.through)} would pass through a node`),L.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.overlaps)} would lie on one another`),L.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.outside)} would leave the drawing`),L.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: no clean seat for ${L.unseated.map(d=>e.type==="sequence"?`message ${d}`:`"${e.edges[d]?.label}"`).join(", ")}`)}let j=i({...r,..._,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(j=b(j),o(j),e.type==="sequence"||e.type==="schema")return{dyn:j,geo:null,ink:"",tokens:u,least:c.least};const R=Bt(e);let Q=oe(O(),g,R,j.grow);for(let v=0;v<6&&Object.keys(Q.grow).length;v++){const D=ht(j.grow);for(const[L,x]of Object.entries(Q.grow))D[L]=(pt(D,L)??0)+x;j={...j,grow:D},o(j),Q=oe(O(),g,R,D)}const A=Q.geo;if(A.unseated.length>0||A.through.length>0||A.outside.length>0||R.third){A.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(A.unseated)].map(L=>`"${e.edges[L]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),A.through.length&&a?.(`in the stacked drawing ${B(A,A.through)} would pass through a node, so its lines are not drawn`),A.outside.length&&a?.(`in the stacked drawing ${B(A,A.outside)} would leave the drawing, so its lines are not drawn`),R.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const v={...A,lines:[],labels:[],crossings:[]};return{dyn:i({...j,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:v,ink:"",tokens:u,least:c.least}}return A.crossings.length&&a?.(`${A.crossings.length} crossing${A.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${A.crossings.map(v=>`${$t(e,A.lines[v.top])} over ${$t(e,A.lines[v.under])}`).join("; ")}`),{dyn:j,geo:A,ink:ae(n,A,u,s),tokens:u,least:c.least}}function $t(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Xe(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const i of n?.lines??[])i.from===o&&a.add(i.to),i.to===o&&a.add(i.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(i=>i.toggleAttribute("data-near",a.has(i.dataset.node))),!n||!s)return;const l=i=>!!o&&(i.from===o||i.to===o),p=t.querySelector(`.${e}-edges`),h=new Map;t.querySelectorAll(`.${e}-edge`).forEach(i=>h.set(i.getAttribute("data-edge"),i));for(const i of n.lines){const f=h.get(String(i.i));f&&(f.toggleAttribute("data-lit",l(i)),f.toggleAttribute("data-dim",!!o&&!l(i)))}if(t.querySelectorAll(`.${e}-label`).forEach(i=>{const f=n.lines.find(b=>String(b.i)===i.dataset.edge);i.toggleAttribute("data-lit",!!(f&&l(f)))}),p){for(const i of n.lines)if(l(i)){const f=h.get(String(i.i));f&&p.appendChild(f)}}const u=Mt(n.lines,l),{defs:g,ids:c}=se(e,{...n,crossings:u},s,r),y=t.querySelector(`.${e}-svg`);if(!y)return;let $=y.querySelector("defs");!$&&g&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),y.insertBefore($,y.firstChild)),$&&($.innerHTML=g),n.lines.forEach((i,f)=>{const b=h.get(String(i.i))?.querySelector(`.${e}-line`);if(!b)return;const O=c.get(f);O?b.setAttribute("mask",`url(#${O})`):b.removeAttribute("mask")})}var Ye=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Qe(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Ye()?"done":"pending")}}function ie(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Pe(t,e,n){const s=t.byId.get(e)?.i??0,r=t.nodes.length;let o;if(n==="ArrowRight"||n==="ArrowDown")o=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")o=s-1;else if(n==="Home")o=0;else if(n==="End")o=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,o))].id}var tn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],le=["data-layout","data-measured","data-bare","data-motion"],en=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ce=t=>t==null||t===!1;function nn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function de(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?le:tn;for(const a of s)ce(e.a[a])&&t.removeAttribute(a);for(const[a,l]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const h=t.style,u=new Map(String(l??"").split(";").map(g=>{const c=g.indexOf(":");return[g.slice(0,c).trim(),g.slice(c+1).trim()]}).filter(([g])=>g));for(const[g,c]of u)h.getPropertyValue(g).trim()!==c&&h.setProperty(g,c);for(const g of en)u.has(g)||h.removeProperty(g);continue}if(n&&!le.includes(a))continue;if(ce(l)){t.removeAttribute(a);continue}const p=l===!0?"":String(l);t.getAttribute(a)!==p&&t.setAttribute(a,p)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let l=o;lt.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(c,y,$){return{prefix:n,base:c,hasSource:y.source!==void 0&&y.source!==null&&y.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(c,y,$,i){var f=function(b){return''+lt(b)+""};return{source:lt(String(y.source||"")),summary:lt(String(y.summary||"")),hint:zt(c).map(function(b){return""+b.keys.map(f).join(" ")+" "+lt(b.words)+""}).join(""),toggle:'"}}function a(c,y,$){var i=kt(c),f=Wt(i,{},r(y,c,$)),b=St(f,o(i,c,y,!1)),O=b.indexOf(">");return{open:b.slice(0,O+1),inner:b.slice(O+1,b.length-9),warnings:i.warnings}}var l=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],p=["--_cols","--_gpad","--_track"];function h(c,y,$,i){c.__diagram&&c.__diagram.stop();var f=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),b=kt(y);if(!$||!f||!c.querySelector(":scope > .diagram-drawing")){if(!f||!c.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var O=a(y,f,i),_=document.createElement("div");_.innerHTML=O.open+"";var B=_.firstChild;l.forEach(function(H){c.removeAttribute(H)}),p.forEach(function(H){c.style.removeProperty(H)});for(var j=0;j :not(script[data-diagram])").forEach(function(H){H.remove()}),c.insertAdjacentHTML("beforeend",O.inner)}b.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var Q=r(f,y,i),A={},V=null,v=null,D=null,L=Object.create(null),x=function(H){L[H]||(L[H]=1,console.warn("Basalt diagram: "+H))},d=function(H){de(c,Wt(b,H,Q))},m=c.querySelector(".diagram-ink"),S=c.querySelector(".diagram-toggle"),E=!i&&b.motion.animated&&typeof e.diagramMotion=="function",z=null,T=null,G=function(){E&&ie(c)};function N(){Xe(c,n,V&&V.geo,V&&V.tokens,f,v||D)}function k(){S&&(S.setAttribute("aria-expanded",String(!!A.open)),S.firstElementChild.textContent=A.open?"Hide the list":"View as list")}function C(){V=(i?i.measure:re)(c,b,n,f,A,d,x),A=V.dyn,d(A),k(),gt(b,A)||(D=null);var H=m&&V.ink!==T;H&&(m.innerHTML=V.ink,T=V.ink),N(),E&&V.tokens&&(Qe(c,!!(V.geo&&V.geo.lines.length)),H&&z&&z.redrawn()),i&&i.onMeasured&&i.onMeasured(V,c)}function q(H){A=H,d(A)}function M(H){var st=A.stop;A=Object.assign({},A,{stop:H}),on(c,n,st,H)}var I=function(H){var st=H&&H.closest?H.closest(".diagram-node"):null;return st&&c.contains(st)?st:null};function F(H){var st=I(H.target);if(!(!st||H.defaultPrevented)){if(G(),H.key==="Escape"){!i&&(v||D)&&(H.preventDefault(),v=D=null,N());return}if(gt(b,A)){var ut=Pe(b,st.getAttribute("data-node"),H.key);if(ut){H.preventDefault(),M(ut);var ue=c.querySelector('.diagram-node[data-node="'+CSS.escape(ut)+'"]');ue&&ue.focus()}}}}function Z(H){var st=I(H.target);if(st){G();var ut=st.getAttribute("data-node");v=st.matches(":focus-visible")?ut:null,gt(b,A)&&A.stop!==ut&&M(ut),N()}}function P(H){var st=I(H.target);st&&(I(H.relatedTarget)||(v=null),A.keep===st.getAttribute("data-node")&&q(Object.assign({},A,{keep:void 0})),N())}function X(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var st=I(H.target);st&&G();var ut=st&>(b,A)?st.getAttribute("data-node"):null;ut!==D&&(D=ut,N())}}function W(){D&&(D=null,N())}function K(){G(),q(Object.assign({},A,{open:!A.open,autoOpen:void 0})),k()}c.addEventListener("keydown",F),c.addEventListener("focusin",Z),c.addEventListener("focusout",P),c.addEventListener("pointerover",X),c.addEventListener("pointerleave",W),S&&S.addEventListener("click",K),C();var ot=c.clientWidth,tt=0,J=!0,et=new ResizeObserver(function(){Math.abs(c.clientWidth-ot)<.5||(ot=c.clientWidth,cancelAnimationFrame(tt),tt=requestAnimationFrame(C))});et.observe(c),document.fonts&&document.fonts.ready.then(function(){J&&C()});var U=matchMedia("(forced-colors: active)"),nt=b.nodes.some(function(H){return H.mark});nt&&U.addEventListener("change",C),E&&(z=e.diagramMotion(c,{fig:c,P:n,base:f,model:function(){return b},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},y));var at=!i&&y.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,y,{model:b,settle:G,animated:E}):null;c.__diagram={stop:function(){at&&at.destroy(),J=!1,et.disconnect(),cancelAnimationFrame(tt),nt&&U.removeEventListener("change",C),z&&z.destroy(),c.removeEventListener("keydown",F),c.removeEventListener("focusin",Z),c.removeEventListener("focusout",P),c.removeEventListener("pointerover",X),c.removeEventListener("pointerleave",W),S&&S.removeEventListener("click",K)},layout:C,key:u(y),send:z&&z.sendValue?z.sendValue:null}}function u(c){try{return JSON.stringify(c,function(y,$){return y==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var y=c.querySelector(":scope > script[data-diagram]");if(y)try{h(c,JSON.parse(y.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:h,buildModel:kt,figureKey:Se,figureList:_e,hintEntries:zt,toHtml:St,escapeHtml:lt,settleEntrance:ie,measureFigure:re},t.diagram=function(c,y){var $=c.__diagram,i=$&&$.send?u(y):null;if(i!==null&&i===$.key){$.send(y.packet?y.packet.send:void 0);return}h(c,y)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/icons.json b/.agent/skills/basalt-html/parts/icons.json index b92891a2..748d4ebe 100644 --- a/.agent/skills/basalt-html/parts/icons.json +++ b/.agent/skills/basalt-html/parts/icons.json @@ -1 +1 @@ -{"notice":"/*! The icon paths below are from Phosphor Icons (@phosphor-icons/react):\nMIT License\n\nCopyright (c) 2020 Phosphor Icons\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/","icons":{"Command":["M180,140H164V116h16a40,40,0,1,0-40-40V92H116V76a40,40,0,1,0-40,40H92v24H76a40,40,0,1,0,40,40V164h24v16a40,40,0,1,0,40-40ZM164,76a16,16,0,1,1,16,16H164ZM60,76a16,16,0,0,1,32,0V92H76A16,16,0,0,1,60,76ZM92,180a16,16,0,1,1-16-16H92Zm24-64h24v24H116Zm64,80a16,16,0,0,1-16-16V164h16a16,16,0,0,1,0,32Z"],"Option":["M236,192a12,12,0,0,1-12,12H160.94a19.89,19.89,0,0,1-17.88-11.06L92.58,92H32a12,12,0,0,1,0-24H95.06a19.89,19.89,0,0,1,17.88,11.06L163.42,180H224A12,12,0,0,1,236,192ZM152,92h72a12,12,0,0,0,0-24H152a12,12,0,0,0,0,24Z"],"Control":["M208.49,128.49a12,12,0,0,1-17,0L128,65,64.49,128.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,128.49Z"],"Sun":["M116,36V20a12,12,0,0,1,24,0V36a12,12,0,0,1-24,0Zm80,92a68,68,0,1,1-68-68A68.07,68.07,0,0,1,196,128Zm-24,0a44,44,0,1,0-44,44A44.05,44.05,0,0,0,172,128ZM51.51,68.49a12,12,0,1,0,17-17l-12-12a12,12,0,0,0-17,17Zm0,119-12,12a12,12,0,0,0,17,17l12-12a12,12,0,1,0-17-17ZM196,72a12,12,0,0,0,8.49-3.51l12-12a12,12,0,0,0-17-17l-12,12A12,12,0,0,0,196,72Zm8.49,115.51a12,12,0,0,0-17,17l12,12a12,12,0,0,0,17-17ZM48,128a12,12,0,0,0-12-12H20a12,12,0,0,0,0,24H36A12,12,0,0,0,48,128Zm80,80a12,12,0,0,0-12,12v16a12,12,0,0,0,24,0V220A12,12,0,0,0,128,208Zm108-92H220a12,12,0,0,0,0,24h16a12,12,0,0,0,0-24Z"],"Moon":["M236.37,139.4a12,12,0,0,0-12-3A84.07,84.07,0,0,1,119.6,31.59a12,12,0,0,0-15-15A108.86,108.86,0,0,0,49.69,55.07,108,108,0,0,0,136,228a107.09,107.09,0,0,0,64.93-21.69,108.86,108.86,0,0,0,38.44-54.94A12,12,0,0,0,236.37,139.4Zm-49.88,47.74A84,84,0,0,1,68.86,69.51,84.93,84.93,0,0,1,92.27,48.29Q92,52.13,92,56A108.12,108.12,0,0,0,200,164q3.87,0,7.71-.27A84.79,84.79,0,0,1,186.49,187.14Z"],"Info":["M108,84a16,16,0,1,1,16,16A16,16,0,0,1,108,84Zm128,44A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Zm-72,36.68V132a20,20,0,0,0-20-20,12,12,0,0,0-4,23.32V168a20,20,0,0,0,20,20,12,12,0,0,0,4-23.32Z"],"Warning":["M240.26,186.1,152.81,34.23h0a28.74,28.74,0,0,0-49.62,0L15.74,186.1a27.45,27.45,0,0,0,0,27.71A28.31,28.31,0,0,0,40.55,228h174.9a28.31,28.31,0,0,0,24.79-14.19A27.45,27.45,0,0,0,240.26,186.1Zm-20.8,15.7a4.46,4.46,0,0,1-4,2.2H40.55a4.46,4.46,0,0,1-4-2.2,3.56,3.56,0,0,1,0-3.73L124,46.2a4.77,4.77,0,0,1,8,0l87.44,151.87A3.56,3.56,0,0,1,219.46,201.8ZM116,136V104a12,12,0,0,1,24,0v32a12,12,0,0,1-24,0Zm28,40a16,16,0,1,1-16-16A16,16,0,0,1,144,176Z"],"ArrowRight":["M224.49,136.49l-72,72a12,12,0,0,1-17-17L187,140H40a12,12,0,0,1,0-24H187L135.51,64.48a12,12,0,0,1,17-17l72,72A12,12,0,0,1,224.49,136.49Z"],"ArrowLeft":["M228,128a12,12,0,0,1-12,12H69l51.52,51.51a12,12,0,0,1-17,17l-72-72a12,12,0,0,1,0-17l72-72a12,12,0,0,1,17,17L69,116H216A12,12,0,0,1,228,128Z"],"ArrowUp":["M208.49,120.49a12,12,0,0,1-17,0L140,69V216a12,12,0,0,1-24,0V69L64.49,120.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,120.49Z"],"ArrowDown":["M208.49,152.49l-72,72a12,12,0,0,1-17,0l-72-72a12,12,0,0,1,17-17L116,187V40a12,12,0,0,1,24,0V187l51.51-51.52a12,12,0,0,1,17,17Z"],"CaretUpDown":["M184.49,167.51a12,12,0,0,1,0,17l-48,48a12,12,0,0,1-17,0l-48-48a12,12,0,0,1,17-17L128,207l39.51-39.52A12,12,0,0,1,184.49,167.51Zm-96-79L128,49l39.51,39.52a12,12,0,0,0,17-17l-48-48a12,12,0,0,0-17,0l-48,48a12,12,0,0,0,17,17Z"],"Trash":["M216,48H180V36A28,28,0,0,0,152,8H104A28,28,0,0,0,76,36V48H40a12,12,0,0,0,0,24h4V208a20,20,0,0,0,20,20H192a20,20,0,0,0,20-20V72h4a12,12,0,0,0,0-24ZM100,36a4,4,0,0,1,4-4h48a4,4,0,0,1,4,4V48H100Zm88,168H68V72H188ZM116,104v64a12,12,0,0,1-24,0V104a12,12,0,0,1,24,0Zm48,0v64a12,12,0,0,1-24,0V104a12,12,0,0,1,24,0Z"],"Download":["M71.51,88.49a12,12,0,0,1,17-17L116,99V24a12,12,0,0,1,24,0V99l27.51-27.52a12,12,0,0,1,17,17l-48,48a12,12,0,0,1-17,0ZM224,116H188a12,12,0,0,0,0,24h32v56H36V140H68a12,12,0,0,0,0-24H32a20,20,0,0,0-20,20v64a20,20,0,0,0,20,20H224a20,20,0,0,0,20-20V136A20,20,0,0,0,224,116Zm-20,52a16,16,0,1,0-16,16A16,16,0,0,0,204,168Z"],"ArrowClockwise":["M244,56v48a12,12,0,0,1-12,12H184a12,12,0,1,1,0-24H201.1l-19-17.38c-.13-.12-.26-.24-.38-.37A76,76,0,1,0,127,204h1a75.53,75.53,0,0,0,52.15-20.72,12,12,0,0,1,16.49,17.45A99.45,99.45,0,0,1,128,228h-1.37A100,100,0,1,1,198.51,57.06L220,76.72V56a12,12,0,0,1,24,0Z"],"CheckCircle":["M176.49,95.51a12,12,0,0,1,0,17l-56,56a12,12,0,0,1-17,0l-24-24a12,12,0,1,1,17-17L112,143l47.51-47.52A12,12,0,0,1,176.49,95.51ZM236,128A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Z"],"XCircle":["M168.49,104.49,145,128l23.52,23.51a12,12,0,0,1-17,17L128,145l-23.51,23.52a12,12,0,0,1-17-17L111,128,87.51,104.49a12,12,0,0,1,17-17L128,111l23.51-23.52a12,12,0,0,1,17,17ZM236,128A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Z"],"Circle":["M128,20A108,108,0,1,0,236,128,108.12,108.12,0,0,0,128,20Zm0,192a84,84,0,1,1,84-84A84.09,84.09,0,0,1,128,212Z"],"GithubLogo":["M212.62,75.17A63.7,63.7,0,0,0,206.39,26,12,12,0,0,0,196,20a63.71,63.71,0,0,0-50,24H126A63.71,63.71,0,0,0,76,20a12,12,0,0,0-10.39,6,63.7,63.7,0,0,0-6.23,49.17A61.5,61.5,0,0,0,52,104v8a60.1,60.1,0,0,0,45.76,58.28A43.66,43.66,0,0,0,92,192v4H76a20,20,0,0,1-20-20,44.05,44.05,0,0,0-44-44,12,12,0,0,0,0,24,20,20,0,0,1,20,20,44.05,44.05,0,0,0,44,44H92v12a12,12,0,0,0,24,0V192a20,20,0,0,1,40,0v40a12,12,0,0,0,24,0V192a43.66,43.66,0,0,0-5.76-21.72A60.1,60.1,0,0,0,220,112v-8A61.5,61.5,0,0,0,212.62,75.17ZM196,112a36,36,0,0,1-36,36H112a36,36,0,0,1-36-36v-8a37.87,37.87,0,0,1,6.13-20.12,11.65,11.65,0,0,0,1.58-11.49,39.9,39.9,0,0,1-.4-27.72,39.87,39.87,0,0,1,26.41,17.8A12,12,0,0,0,119.82,68h32.35a12,12,0,0,0,10.11-5.53,39.84,39.84,0,0,1,26.41-17.8,39.9,39.9,0,0,1-.4,27.72,12,12,0,0,0,1.61,11.53A37.85,37.85,0,0,1,196,104Z"],"XLogo":["M218.12,209.56l-61-95.8,59.72-65.69a12,12,0,0,0-17.76-16.14L143.81,92.77,106.12,33.56A12,12,0,0,0,96,28H48A12,12,0,0,0,37.88,46.44l61,95.8L39.12,207.93a12,12,0,1,0,17.76,16.14l55.31-60.84,37.69,59.21A12,12,0,0,0,160,228h48a12,12,0,0,0,10.12-18.44ZM166.59,204,69.86,52H89.41l96.73,152Z"],"LinkedinLogo":["M216,20H40A20,20,0,0,0,20,40V216a20,20,0,0,0,20,20H216a20,20,0,0,0,20-20V40A20,20,0,0,0,216,20Zm-4,192H44V44H212ZM112,176V120a12,12,0,0,1,21.43-7.41A40,40,0,0,1,192,148v28a12,12,0,0,1-24,0V148a16,16,0,0,0-32,0v28a12,12,0,0,1-24,0ZM96,120v56a12,12,0,0,1-24,0V120a12,12,0,0,1,24,0ZM68,80A16,16,0,1,1,84,96,16,16,0,0,1,68,80Z"],"InstagramLogo":["M128,80a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,72a24,24,0,1,1,24-24A24,24,0,0,1,128,152ZM176,20H80A60.07,60.07,0,0,0,20,80v96a60.07,60.07,0,0,0,60,60h96a60.07,60.07,0,0,0,60-60V80A60.07,60.07,0,0,0,176,20Zm36,156a36,36,0,0,1-36,36H80a36,36,0,0,1-36-36V80A36,36,0,0,1,80,44h96a36,36,0,0,1,36,36ZM196,76a16,16,0,1,1-16-16A16,16,0,0,1,196,76Z"],"YoutubeLogo":["M170.49,117.91l-56-36A12,12,0,0,0,96,92v72a12,12,0,0,0,18.49,10.09l56-36a12,12,0,0,0,0-20.18ZM120,142V114l21.81,14Zm118.21-73.5a28.05,28.05,0,0,0-16.93-19.14C186.4,35.91,131.29,36,128,36s-58.4-.09-93.28,13.38A28.05,28.05,0,0,0,17.79,68.52C15.15,78.72,12,97.32,12,128s3.15,49.28,5.79,59.48a28.05,28.05,0,0,0,16.93,19.14C68.21,219.55,120.36,220,127.37,220h1.26c7,0,59.16-.45,92.65-13.38a28.05,28.05,0,0,0,16.93-19.14c2.64-10.2,5.79-28.8,5.79-59.48S240.85,78.72,238.21,68.52ZM215,181.46a4,4,0,0,1-2.34,2.77C182.78,195.76,132.27,196,128.32,196h-.39c-.53,0-53.64.17-84.56-11.77A4,4,0,0,1,41,181.46c-1.88-7.24-5-23.82-5-53.46s3.15-46.22,5-53.46a4,4,0,0,1,2.34-2.77C74.29,59.83,127.39,60,127.92,60h.15c.54,0,53.64-.17,84.56,11.77A4,4,0,0,1,215,74.54c1.88,7.24,5,23.82,5,53.46S216.85,174.22,215,181.46Z"],"EnvelopeSimple":["M224,44H32A12,12,0,0,0,20,56V192a20,20,0,0,0,20,20H216a20,20,0,0,0,20-20V56A12,12,0,0,0,224,44ZM193.15,68,128,127.72,62.85,68ZM44,188V83.28l75.89,69.57a12,12,0,0,0,16.22,0L212,83.28V188Z"],"TerminalWindow":["M72.5,150.63,100.79,128,72.5,105.37a12,12,0,1,1,15-18.74l40,32a12,12,0,0,1,0,18.74l-40,32a12,12,0,0,1-15-18.74ZM144,172h32a12,12,0,0,0,0-24H144a12,12,0,0,0,0,24ZM236,56V200a20,20,0,0,1-20,20H40a20,20,0,0,1-20-20V56A20,20,0,0,1,40,36H216A20,20,0,0,1,236,56Zm-24,4H44V196H212Z"],"ArrowsOutSimple":["M220,48V96a12,12,0,0,1-24,0V77l-39.51,39.52a12,12,0,0,1-17-17L179,60H160a12,12,0,0,1,0-24h48A12,12,0,0,1,220,48ZM99.51,139.51,60,179V160a12,12,0,0,0-24,0v48a12,12,0,0,0,12,12H96a12,12,0,0,0,0-24H77l39.52-39.51a12,12,0,0,0-17-17Z"]}} +{"notice":"/*! The icon paths below are from Phosphor Icons (@phosphor-icons/react):\nMIT License\n\nCopyright (c) 2020 Phosphor Icons\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/","icons":{"Command":["M180,140H164V116h16a40,40,0,1,0-40-40V92H116V76a40,40,0,1,0-40,40H92v24H76a40,40,0,1,0,40,40V164h24v16a40,40,0,1,0,40-40ZM164,76a16,16,0,1,1,16,16H164ZM60,76a16,16,0,0,1,32,0V92H76A16,16,0,0,1,60,76ZM92,180a16,16,0,1,1-16-16H92Zm24-64h24v24H116Zm64,80a16,16,0,0,1-16-16V164h16a16,16,0,0,1,0,32Z"],"Option":["M236,192a12,12,0,0,1-12,12H160.94a19.89,19.89,0,0,1-17.88-11.06L92.58,92H32a12,12,0,0,1,0-24H95.06a19.89,19.89,0,0,1,17.88,11.06L163.42,180H224A12,12,0,0,1,236,192ZM152,92h72a12,12,0,0,0,0-24H152a12,12,0,0,0,0,24Z"],"Control":["M208.49,128.49a12,12,0,0,1-17,0L128,65,64.49,128.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,128.49Z"],"Sun":["M116,36V20a12,12,0,0,1,24,0V36a12,12,0,0,1-24,0Zm80,92a68,68,0,1,1-68-68A68.07,68.07,0,0,1,196,128Zm-24,0a44,44,0,1,0-44,44A44.05,44.05,0,0,0,172,128ZM51.51,68.49a12,12,0,1,0,17-17l-12-12a12,12,0,0,0-17,17Zm0,119-12,12a12,12,0,0,0,17,17l12-12a12,12,0,1,0-17-17ZM196,72a12,12,0,0,0,8.49-3.51l12-12a12,12,0,0,0-17-17l-12,12A12,12,0,0,0,196,72Zm8.49,115.51a12,12,0,0,0-17,17l12,12a12,12,0,0,0,17-17ZM48,128a12,12,0,0,0-12-12H20a12,12,0,0,0,0,24H36A12,12,0,0,0,48,128Zm80,80a12,12,0,0,0-12,12v16a12,12,0,0,0,24,0V220A12,12,0,0,0,128,208Zm108-92H220a12,12,0,0,0,0,24h16a12,12,0,0,0,0-24Z"],"Moon":["M236.37,139.4a12,12,0,0,0-12-3A84.07,84.07,0,0,1,119.6,31.59a12,12,0,0,0-15-15A108.86,108.86,0,0,0,49.69,55.07,108,108,0,0,0,136,228a107.09,107.09,0,0,0,64.93-21.69,108.86,108.86,0,0,0,38.44-54.94A12,12,0,0,0,236.37,139.4Zm-49.88,47.74A84,84,0,0,1,68.86,69.51,84.93,84.93,0,0,1,92.27,48.29Q92,52.13,92,56A108.12,108.12,0,0,0,200,164q3.87,0,7.71-.27A84.79,84.79,0,0,1,186.49,187.14Z"],"Info":["M108,84a16,16,0,1,1,16,16A16,16,0,0,1,108,84Zm128,44A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Zm-72,36.68V132a20,20,0,0,0-20-20,12,12,0,0,0-4,23.32V168a20,20,0,0,0,20,20,12,12,0,0,0,4-23.32Z"],"Warning":["M240.26,186.1,152.81,34.23h0a28.74,28.74,0,0,0-49.62,0L15.74,186.1a27.45,27.45,0,0,0,0,27.71A28.31,28.31,0,0,0,40.55,228h174.9a28.31,28.31,0,0,0,24.79-14.19A27.45,27.45,0,0,0,240.26,186.1Zm-20.8,15.7a4.46,4.46,0,0,1-4,2.2H40.55a4.46,4.46,0,0,1-4-2.2,3.56,3.56,0,0,1,0-3.73L124,46.2a4.77,4.77,0,0,1,8,0l87.44,151.87A3.56,3.56,0,0,1,219.46,201.8ZM116,136V104a12,12,0,0,1,24,0v32a12,12,0,0,1-24,0Zm28,40a16,16,0,1,1-16-16A16,16,0,0,1,144,176Z"],"ArrowRight":["M224.49,136.49l-72,72a12,12,0,0,1-17-17L187,140H40a12,12,0,0,1,0-24H187L135.51,64.48a12,12,0,0,1,17-17l72,72A12,12,0,0,1,224.49,136.49Z"],"ArrowLeft":["M228,128a12,12,0,0,1-12,12H69l51.52,51.51a12,12,0,0,1-17,17l-72-72a12,12,0,0,1,0-17l72-72a12,12,0,0,1,17,17L69,116H216A12,12,0,0,1,228,128Z"],"ArrowUp":["M208.49,120.49a12,12,0,0,1-17,0L140,69V216a12,12,0,0,1-24,0V69L64.49,120.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,120.49Z"],"ArrowDown":["M208.49,152.49l-72,72a12,12,0,0,1-17,0l-72-72a12,12,0,0,1,17-17L116,187V40a12,12,0,0,1,24,0V187l51.51-51.52a12,12,0,0,1,17,17Z"],"CaretUpDown":["M184.49,167.51a12,12,0,0,1,0,17l-48,48a12,12,0,0,1-17,0l-48-48a12,12,0,0,1,17-17L128,207l39.51-39.52A12,12,0,0,1,184.49,167.51Zm-96-79L128,49l39.51,39.52a12,12,0,0,0,17-17l-48-48a12,12,0,0,0-17,0l-48,48a12,12,0,0,0,17,17Z"],"Trash":["M216,48H180V36A28,28,0,0,0,152,8H104A28,28,0,0,0,76,36V48H40a12,12,0,0,0,0,24h4V208a20,20,0,0,0,20,20H192a20,20,0,0,0,20-20V72h4a12,12,0,0,0,0-24ZM100,36a4,4,0,0,1,4-4h48a4,4,0,0,1,4,4V48H100Zm88,168H68V72H188ZM116,104v64a12,12,0,0,1-24,0V104a12,12,0,0,1,24,0Zm48,0v64a12,12,0,0,1-24,0V104a12,12,0,0,1,24,0Z"],"Download":["M71.51,88.49a12,12,0,0,1,17-17L116,99V24a12,12,0,0,1,24,0V99l27.51-27.52a12,12,0,0,1,17,17l-48,48a12,12,0,0,1-17,0ZM224,116H188a12,12,0,0,0,0,24h32v56H36V140H68a12,12,0,0,0,0-24H32a20,20,0,0,0-20,20v64a20,20,0,0,0,20,20H224a20,20,0,0,0,20-20V136A20,20,0,0,0,224,116Zm-20,52a16,16,0,1,0-16,16A16,16,0,0,0,204,168Z"],"ArrowClockwise":["M244,56v48a12,12,0,0,1-12,12H184a12,12,0,1,1,0-24H201.1l-19-17.38c-.13-.12-.26-.24-.38-.37A76,76,0,1,0,127,204h1a75.53,75.53,0,0,0,52.15-20.72,12,12,0,0,1,16.49,17.45A99.45,99.45,0,0,1,128,228h-1.37A100,100,0,1,1,198.51,57.06L220,76.72V56a12,12,0,0,1,24,0Z"],"CheckCircle":["M176.49,95.51a12,12,0,0,1,0,17l-56,56a12,12,0,0,1-17,0l-24-24a12,12,0,1,1,17-17L112,143l47.51-47.52A12,12,0,0,1,176.49,95.51ZM236,128A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Z"],"XCircle":["M168.49,104.49,145,128l23.52,23.51a12,12,0,0,1-17,17L128,145l-23.51,23.52a12,12,0,0,1-17-17L111,128,87.51,104.49a12,12,0,0,1,17-17L128,111l23.51-23.52a12,12,0,0,1,17,17ZM236,128A108,108,0,1,1,128,20,108.12,108.12,0,0,1,236,128Zm-24,0a84,84,0,1,0-84,84A84.09,84.09,0,0,0,212,128Z"],"Circle":["M128,20A108,108,0,1,0,236,128,108.12,108.12,0,0,0,128,20Zm0,192a84,84,0,1,1,84-84A84.09,84.09,0,0,1,128,212Z"],"GithubLogo":["M212.62,75.17A63.7,63.7,0,0,0,206.39,26,12,12,0,0,0,196,20a63.71,63.71,0,0,0-50,24H126A63.71,63.71,0,0,0,76,20a12,12,0,0,0-10.39,6,63.7,63.7,0,0,0-6.23,49.17A61.5,61.5,0,0,0,52,104v8a60.1,60.1,0,0,0,45.76,58.28A43.66,43.66,0,0,0,92,192v4H76a20,20,0,0,1-20-20,44.05,44.05,0,0,0-44-44,12,12,0,0,0,0,24,20,20,0,0,1,20,20,44.05,44.05,0,0,0,44,44H92v12a12,12,0,0,0,24,0V192a20,20,0,0,1,40,0v40a12,12,0,0,0,24,0V192a43.66,43.66,0,0,0-5.76-21.72A60.1,60.1,0,0,0,220,112v-8A61.5,61.5,0,0,0,212.62,75.17ZM196,112a36,36,0,0,1-36,36H112a36,36,0,0,1-36-36v-8a37.87,37.87,0,0,1,6.13-20.12,11.65,11.65,0,0,0,1.58-11.49,39.9,39.9,0,0,1-.4-27.72,39.87,39.87,0,0,1,26.41,17.8A12,12,0,0,0,119.82,68h32.35a12,12,0,0,0,10.11-5.53,39.84,39.84,0,0,1,26.41-17.8,39.9,39.9,0,0,1-.4,27.72,12,12,0,0,0,1.61,11.53A37.85,37.85,0,0,1,196,104Z"],"XLogo":["M218.12,209.56l-61-95.8,59.72-65.69a12,12,0,0,0-17.76-16.14L143.81,92.77,106.12,33.56A12,12,0,0,0,96,28H48A12,12,0,0,0,37.88,46.44l61,95.8L39.12,207.93a12,12,0,1,0,17.76,16.14l55.31-60.84,37.69,59.21A12,12,0,0,0,160,228h48a12,12,0,0,0,10.12-18.44ZM166.59,204,69.86,52H89.41l96.73,152Z"],"LinkedinLogo":["M216,20H40A20,20,0,0,0,20,40V216a20,20,0,0,0,20,20H216a20,20,0,0,0,20-20V40A20,20,0,0,0,216,20Zm-4,192H44V44H212ZM112,176V120a12,12,0,0,1,21.43-7.41A40,40,0,0,1,192,148v28a12,12,0,0,1-24,0V148a16,16,0,0,0-32,0v28a12,12,0,0,1-24,0ZM96,120v56a12,12,0,0,1-24,0V120a12,12,0,0,1,24,0ZM68,80A16,16,0,1,1,84,96,16,16,0,0,1,68,80Z"],"InstagramLogo":["M128,80a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,72a24,24,0,1,1,24-24A24,24,0,0,1,128,152ZM176,20H80A60.07,60.07,0,0,0,20,80v96a60.07,60.07,0,0,0,60,60h96a60.07,60.07,0,0,0,60-60V80A60.07,60.07,0,0,0,176,20Zm36,156a36,36,0,0,1-36,36H80a36,36,0,0,1-36-36V80A36,36,0,0,1,80,44h96a36,36,0,0,1,36,36ZM196,76a16,16,0,1,1-16-16A16,16,0,0,1,196,76Z"],"YoutubeLogo":["M170.49,117.91l-56-36A12,12,0,0,0,96,92v72a12,12,0,0,0,18.49,10.09l56-36a12,12,0,0,0,0-20.18ZM120,142V114l21.81,14Zm118.21-73.5a28.05,28.05,0,0,0-16.93-19.14C186.4,35.91,131.29,36,128,36s-58.4-.09-93.28,13.38A28.05,28.05,0,0,0,17.79,68.52C15.15,78.72,12,97.32,12,128s3.15,49.28,5.79,59.48a28.05,28.05,0,0,0,16.93,19.14C68.21,219.55,120.36,220,127.37,220h1.26c7,0,59.16-.45,92.65-13.38a28.05,28.05,0,0,0,16.93-19.14c2.64-10.2,5.79-28.8,5.79-59.48S240.85,78.72,238.21,68.52ZM215,181.46a4,4,0,0,1-2.34,2.77C182.78,195.76,132.27,196,128.32,196h-.39c-.53,0-53.64.17-84.56-11.77A4,4,0,0,1,41,181.46c-1.88-7.24-5-23.82-5-53.46s3.15-46.22,5-53.46a4,4,0,0,1,2.34-2.77C74.29,59.83,127.39,60,127.92,60h.15c.54,0,53.64-.17,84.56,11.77A4,4,0,0,1,215,74.54c1.88,7.24,5,23.82,5,53.46S216.85,174.22,215,181.46Z"],"EnvelopeSimple":["M224,44H32A12,12,0,0,0,20,56V192a20,20,0,0,0,20,20H216a20,20,0,0,0,20-20V56A12,12,0,0,0,224,44ZM193.15,68,128,127.72,62.85,68ZM44,188V83.28l75.89,69.57a12,12,0,0,0,16.22,0L212,83.28V188Z"],"TerminalWindow":["M72.5,150.63,100.79,128,72.5,105.37a12,12,0,1,1,15-18.74l40,32a12,12,0,0,1,0,18.74l-40,32a12,12,0,0,1-15-18.74ZM144,172h32a12,12,0,0,0,0-24H144a12,12,0,0,0,0,24ZM236,56V200a20,20,0,0,1-20,20H40a20,20,0,0,1-20-20V56A20,20,0,0,1,40,36H216A20,20,0,0,1,236,56Zm-24,4H44V196H212Z"]}} diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index 1b4cd968..d1571146 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -836,9 +836,6 @@ "dialog-form", "sheet" ], - "icons": [ - "ArrowsOutSimple" - ], "budget": 12000, "usage": 900, "builds": [ diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 8e15a0fb..d20420e0 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -883,13 +883,10 @@ function keysSentence(m: Model): string { return `Arrow keys move to the next or the previous ${noun}, in the author's order; Home and End go to the ends; Escape clears the trace.`; } -/** The key hint's entries: the keys and their words. In the viewer (DECISIONS 310, 9.8) Esc closes, and the zoom keys are added. */ -export function hintEntries(m: Model, viewer = false): Array<{ keys: string[]; words: string }> { - if (viewer) return [{ keys: ["←", "→"], words: stopNoun(m) }, { keys: ["Home", "End"], words: "the ends" }, { keys: ["+", "−"], words: "zoom" }, { keys: ["0"], words: "fit" }, { keys: ["Esc"], words: "close" }]; +/** The key hint's entries: the keys and their words. */ +export function hintEntries(m: Model): Array<{ keys: string[]; words: string }> { return [{ keys: ["←", "→"], words: stopNoun(m) }, { keys: ["Home", "End"], words: "the ends" }, { keys: ["Esc"], words: "clear" }]; } -/** The viewer's addition to the keys sentence (DECISIONS 310, 9.8). */ -export const VIEWER_KEYS = "Plus and minus zoom, zero fits the drawing, Escape closes."; export interface FigureOptions { /** The class prefix: "basalt-diagram" in React, "diagram" in the HTML skill. */ @@ -903,8 +900,8 @@ export interface FigureOptions { hasSource?: boolean; /** The class of the hidden text. */ hiddenClass: string; - /** The figure is the viewer's (DECISIONS 310): only its drawing shows, and the keys sentence says the zoom keys. */ - viewer?: boolean; + /** The figure is the viewer's (DECISIONS 310): only its drawing shows, and its keys sentence ends with these words (the zoom keys). */ + viewer?: string; } /** The whole figure. Before script runs `dyn` is empty; the same tree, with the measured `dyn`, is what script settles on. */ @@ -961,7 +958,7 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { h("p", { class: `${P}-hint`, "data-kbd-hint": "", "aria-hidden": "true" }, { slot: "hint" }), h("div", { class: `${P}-foot` }, { slot: "toggle" }), h("div", { id: ids.list, class: `${P}-list`, hidden: !dyn.open }, listTree(P, m)), - h("span", { id: ids.keys, class: o.hiddenClass }, o.viewer ? `${keysSentence(m)} ${VIEWER_KEYS}` : keysSentence(m)), + h("span", { id: ids.keys, class: o.hiddenClass }, o.viewer ? `${keysSentence(m)} ${o.viewer}` : keysSentence(m)), h("figcaption", { id: ids.summary, class: `${P}-summary` }, { slot: "summary" })); } @@ -2052,62 +2049,6 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin return { dyn: d, geo, ink: inkHtml(P, geo, tk, base), tokens: tk, least: mins.least }; } -/** What the viewer's figure remembers between layouts: the least width the engine was found to draw this data at (0: none). */ -export interface ViewerMemo { model?: Model; least?: number } -export interface ViewerLayout { - /** The layer the figure is laid out in: its width is the layout width; its transform (the zoom) is taken off while it is measured. */ - layer: HTMLElement; - /** The stage's inner width, the page row and `size-breakpoint-container`, in CSS pixels. */ - avail: number; - row: number; - contain: number; - memo: ViewerMemo; -} - -/** - * The viewer's layout (DECISIONS 310, 9.3), for React and the skill alike: the figure is laid out at the stage's inner width, never under its least drawn - * width and never over the page row unless that width is more; a stack is held only when nothing is drawn, at most the container's width. The engine - * measures only at 100%: the zoom is taken off the layer while it measures and put back before anything paints. - */ -export function measureViewerFigure(fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn: ((s: string) => void) | undefined, v: ViewerLayout): Measured { - const { layer, memo } = v; - if (memo.model !== m) { memo.model = m; memo.least = undefined; } - const sizeTo = (least: number) => { layer.style.width = `${Math.max(memo.least || least, Math.min(v.avail, v.row))}px`; }; - // The layer has no width of its own until the first layout: it starts at the stage's, so the figure can be measured. - if (!layer.style.width) layer.style.width = `${Math.min(v.avail, v.row)}px`; - const zoomed = layer.style.transform; - layer.style.transform = "none"; - // A dialog still opening is scaled (from .98): the layer is scaled by the inverse while it is measured, so what is read is 100% whatever its ancestors do. - const ancestors = layer.offsetWidth ? layer.getBoundingClientRect().width / layer.offsetWidth : 1; - if (Math.abs(ancestors - 1) > 1e-4) layer.style.transform = `scale(${1 / ancestors})`; - // Before the least drawn width is known, a refusal at the token sum is expected and is not the author's to fix: it says nothing. - let result = measureFigure(fig, m, P, base, current, apply, memo.least === undefined ? undefined : warn, sizeTo); - // The least drawn width is the first width the engine draws the figure at, which the token sum can undercount (a sequence's columns are measured, a - // decision may be taller than wide at a width). Found once by trying wider layouts, in steps of 16 and then by the pixel, up to half the row past it. A width - // counts when it draws twice running: measured from the stack, then again from its own drawn state, as every later measure is. - if (result.dyn.layout === "stacked" && memo.least === undefined && result.least !== undefined) { - const from = result.dyn; - const at = (w: number) => { - layer.style.width = `${w}px`; - const first = measureFigure(fig, m, P, base, from, apply); - return first.dyn.layout === "drawn" ? measureFigure(fig, m, P, base, first.dyn, apply) : first; - }; - const start = Math.max(result.least, Math.min(v.avail, v.row)); - const cap = Math.max(v.row, start) * 1.5; - let found: number | undefined; - for (let w = start + 16; w <= cap && found === undefined; w += 16) if (at(w).dyn.layout === "drawn") found = w; - if (found !== undefined) for (let w = found - 15; w < found; w++) if (at(w).dyn.layout === "drawn") { found = w; break; } - memo.least = found ?? 0; - result = found !== undefined ? at(found) : measureFigure(fig, m, P, base, from, apply, warn, sizeTo); - } - if (result.dyn.layout === "stacked" && fig.clientWidth > v.contain) { - layer.style.width = `${v.contain}px`; - result = measureFigure(fig, m, P, base, result.dyn, apply, warn); - } - layer.style.transform = zoomed; - return result; -} - function lineName(m: Model, l: GLine): string { const a = m.byId.get(l.from)?.name ?? l.from, b = m.byId.get(l.to)?.name ?? l.to; return `${a} to ${b}`; diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 3e820bb9..5cb4c986 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -2,14 +2,12 @@ import * as React from "react"; import { Kbd } from "./kbd"; import { useShortcutsVisible } from "./keyboard"; -import { usePanelLevel } from "./layers"; +import { inLevel, usePanelLevel } from "./layers"; import { - applyTrace, buildModel, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, measureViewerFigure, settleEntrance, syncAttributes, toHtml, + applyTrace, buildModel, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, } from "./diagram-core"; -import type { DiagramLegend, DiagramMotion, DiagramSpec, Dyn, Measured, ViewerMemo, VNode } from "./diagram-core"; +import type { DiagramLegend, DiagramMotion, DiagramSpec, Dyn, Measured, Model, VNode } from "./diagram-core"; import type { MotionController } from "./diagram-motion-core"; -import { ArrowsOutSimpleIcon } from "@phosphor-icons/react/dist/csr/ArrowsOutSimple"; -import { Icon } from "./icon"; type MotionModule = typeof import("./diagram-motion"); let motionLoading: Promise | undefined; @@ -52,7 +50,7 @@ export interface DiagramFigureProps extends Omit, const P = "basalt-diagram"; /** What the viewer is handed (diagram-viewer.tsx): this component and the engine, so its chunk holds no second copy of either. Built at the first open. */ let kitMade: import("./diagram-viewer").ViewerKit | undefined; -const kitOf = () => (kitMade ??= { Figure: DiagramFigure, Kbd, buildModel, figureKey, figureList, hintEntries, toHtml }); +const kitOf = () => (kitMade ??= { Figure: DiagramFigure, Kbd, buildModel, figureKey, figureList, hintEntries, toHtml, inLevel, measureFigure }); declare const process: { env: { NODE_ENV?: string } }; const CAMEL: Record = { class: "className", tabindex: "tabIndex", for: "htmlFor", viewbox: "viewBox" }; @@ -96,15 +94,12 @@ function warnOnce(component: string, message: string) { console.warn(`Basalt ${key}`); } -/** The viewer's own figure (DECISIONS 310, 9.3): laid out at a width the viewer gives, its drawing alone shown, measured only at 100%. */ +/** The viewer's own figure (DECISIONS 310, 9.3): laid out and measured by the viewer, its drawing alone shown. */ export interface DiagramViewerMode { - /** The width it may be laid out at: the stage's inner width, never over the page row (`row`) unless its least drawn width is more. */ - avail: number; - row: number; - /** A stack is held at most this wide (`size-breakpoint-container`). */ - contain: number; - /** The layer the figure is laid out in: its width is the layout width. */ - layer: () => HTMLElement | null; + /** Lays the figure out (diagram-zoom-core's measureViewerFigure, with this module's engine). */ + measure: (fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn?: (s: string) => void) => Measured; + /** The words the keys sentence ends with. */ + keys: string; /** After every layout: what was measured, and the figure. */ onMeasured: (measured: Measured, fig: HTMLElement) => void; } @@ -135,8 +130,6 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti const [ink, setInk] = React.useState(""); const inkHtml = React.useMemo(() => ({ __html: ink }), [ink]); const measured = React.useRef(null); - // The viewer's figure: the least width the engine was found to draw it at, for this data (measureViewerFigure). - const leastMemo = React.useRef({}); const dynRef = React.useRef(dyn); dynRef.current = dyn; const [motionModule, setMotionModule] = React.useState(null); @@ -152,7 +145,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti modelRef.current = model; const [focusTrace, setFocusTrace] = React.useState(null); const [hoverTrace, setHoverTrace] = React.useState(null); - const options = React.useMemo(() => ({ prefix: P, base, level, hasSource: source !== undefined && source !== null, hiddenClass: "basalt-visually-hidden", viewer: Boolean(viewer) }), [base, level, source, viewer]); + const options = React.useMemo(() => ({ prefix: P, base, level, hasSource: source !== undefined && source !== null, hiddenClass: "basalt-visually-hidden", viewer: viewer?.keys }), [base, level, source, viewer]); // Development only: a bundler that sets NODE_ENV to production drops this block, strings included. React.useEffect(() => { @@ -164,8 +157,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti if (!fig) return; const warn = process.env.NODE_ENV !== "production" ? (message: string) => warnOnce(component, message) : undefined; const apply = (d: Dyn) => syncAttributes(fig, figureTree(model, d, options)); - const layer = viewer?.layer(); - const result = viewer && layer ? measureViewerFigure(fig, model, P, base, dynRef.current, apply, warn, { layer, avail: viewer.avail, row: viewer.row, contain: viewer.contain, memo: leastMemo.current }) : measureFigure(fig, model, P, base, dynRef.current, apply, warn); + const result = (viewer ? viewer.measure : measureFigure)(fig, model, P, base, dynRef.current, apply, warn); measured.current = result; // The same layout is the same state: a measure that changes nothing renders nothing. // (A layout is plain data that the engine builds in one order, so its text is a fair test.) @@ -368,7 +360,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti onTouchStart={preloadViewer} onClick={openViewer} > - + {/* Words only (a deviation from 9.1, the lead's call): Phosphor's icon cost every still figure 2.2 KB of six weights, and the core set draws no expand glyph. */} Expand {opening ? : null} diff --git a/packages/react/src/diagram-viewer.tsx b/packages/react/src/diagram-viewer.tsx index f6e62076..0309b5be 100644 --- a/packages/react/src/diagram-viewer.tsx +++ b/packages/react/src/diagram-viewer.tsx @@ -2,17 +2,20 @@ import * as React from "react"; import { Button, IconButton } from "./button"; import type { DiagramFigureInternalProps, DiagramViewerMode } from "./diagram-figure"; -import type { buildModel, DiagramSpec, figureKey, figureList, hintEntries, Measured, Model, toHtml } from "./diagram-core"; -import { attachZoom, revealIn } from "./diagram-zoom-core"; -import type { ZoomController, ZoomState } from "./diagram-zoom-core"; -import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./dialog"; +import type { buildModel, DiagramSpec, figureKey, figureList, hintEntries, Measured, measureFigure, Model, toHtml } from "./diagram-core"; +import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } from "./diagram-zoom-core"; +import type { ViewerMemo, ZoomController, ZoomState } from "./diagram-zoom-core"; +import { createPortal } from "react-dom"; + +import { CloseGlyph } from "./glyphs/close"; import { MinusGlyph } from "./glyphs/minus"; import { PlusGlyph } from "./glyphs/plus"; -import { SheetFooter, SheetHeader } from "./overlays"; // The diagram viewer (DECISIONS 301, part 9, as DECISIONS 310): "Expand" opens the figure's drawn layout in a dialog, where the reader zooms and pans it. // The figure is drawn again from the same data, laid out once at 100% in real CSS pixels, and zoomed with one transform (diagram-zoom-core.ts). This module -// is loaded on demand by a figure's "Expand" (diagram-figure.tsx) and brings Dialog with it; it is not exported from the package. The implementation hasn't +// is loaded on demand by a figure's "Expand" (diagram-figure.tsx); it is not exported from the package. Its dialog is the form dialog's box and the sheet's head, +// body and foot, drawn on a native modal as the HTML skill's is, not Base UI's: an import of Base UI's dialog from a chunk any figure can load widens the +// Base UI chunk every other component's bundle shares (Button alone grew by 1.8 KB), so the viewer brings no Base UI but the button's. The implementation hasn't // been reviewed, and no seat has drawn, checked or given a position on part 9: every value is the decider's alone. const P = "basalt-diagram"; @@ -29,6 +32,9 @@ export interface ViewerKit { figureList: typeof figureList; hintEntries: typeof hintEntries; toHtml: typeof toHtml; + /** The figure's own surface-level context: the viewer's content is level 1, as a modal's is. */ + inLevel: (level: 1, children: React.ReactNode) => React.ReactNode; + measureFigure: typeof measureFigure; } export interface DiagramViewerProps { @@ -48,7 +54,7 @@ const EMPTY: ZoomState = { zoom: 1, level: 100, fit: 1, min: 1, max: 4, atMin: f const probeWidth = (stage: HTMLElement | null, which: string) => stage?.querySelector(`.${P}-probe[data-probe="${which}"]`)?.offsetWidth ?? 0; export function DiagramViewer({ kit, spec, component, source, summary, opener, onClose }: DiagramViewerProps) { - const { Figure: DiagramFigure, Kbd, buildModel, figureKey, figureList, hintEntries, toHtml } = kit; + const { Figure: DiagramFigure, Kbd, buildModel, figureKey, figureList, hintEntries, toHtml, inLevel, measureFigure } = kit; // The viewer's figure is still (9.7): no entrance, flow, mover or run, so no motion code is loaded for it. const still = React.useMemo(() => ({ ...spec, motion: "still" }), [spec]); const model = React.useMemo(() => buildModel(still), [still]); @@ -100,7 +106,16 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o setLayout({ layout: measured.dyn.layout, bare: measured.dyn.bare, open: measured.dyn.open }); zoomRef.current?.size(fig.offsetWidth, fig.offsetHeight); }, []); - const viewer = React.useMemo(() => (avail > 0 ? { avail, row: dims.row, contain: dims.contain, layer: () => layerRef.current, onMeasured } : undefined), [avail, dims, onMeasured]); + const memo = React.useRef({}); + const viewer = React.useMemo(() => { + const layer = layerRef.current; + if (!(avail > 0) || !layer) return undefined; + return { + keys: VIEWER_KEYS, + onMeasured, + measure: (fig, m, p, base, current, apply, warn) => measureViewerFigure(fig, m, p, base, current, apply, warn, { layer, avail, row: dims.row, contain: dims.contain, memo: memo.current, measureFigure }), + }; + }, [avail, dims, onMeasured, measureFigure]); // A stack with no lines has its list open, as on the page (9.3). const showList = listOpen || Boolean(layout.bare); @@ -109,20 +124,66 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o const key = figureKey(P, model); const keyHtml = React.useMemo(() => ({ __html: key ? toHtml(key) : "" }), [key]); const listHtml = React.useMemo(() => ({ __html: figureList(P, model).map((v) => toHtml(v)).join("") }), [model]); - const hint = hintEntries(model, true).map((entry) => ( + const hint = viewerHint(hintEntries(model)).map((entry) => ( {entry.keys.map((k, i) => {i ? " " : null}{/* A fragment, not a string: Kbd reads a string as a shortcut, and "+" is its separator. */}<>{k})} {entry.words} )); const off = zoom.listOpen; const z = () => zoomRef.current; - return ( - { if (!next) onClose(); }}> - - - {model.title} - {source !== undefined && source !== null ?

{source}

: null} -
- {summary} + // The dialog: shown as a modal when it mounts; Esc (the browser's cancel), Close and a press on the scrim close it, after its own exit motion; focus + // returns to "Expand". While it is open the page behind does not scroll (the stylesheet), and Tab wraps inside it. + const dialogRef = React.useRef(null); + const titleId = React.useId(); + const closing = React.useRef(false); + const onCloseRef = React.useRef(onClose); + onCloseRef.current = onClose; + const close = React.useCallback(() => { + const d = dialogRef.current; + if (!d || closing.current) return; + closing.current = true; + if (d.open) d.close(); + }, []); + React.useLayoutEffect(() => { + const d = dialogRef.current; + if (!d) return undefined; + if (!d.open) d.showModal(); + stageRef.current?.focus({ preventScroll: true }); + let timer = 0; + const onClose = () => { + closing.current = true; + opener.current?.focus({ preventScroll: true }); + const out = (Number.parseFloat(getComputedStyle(d).getPropertyValue("--_out")) || 0); + timer = window.setTimeout(() => onCloseRef.current(), out); + }; + let down = false; + const outside = (e: MouseEvent) => { const r = d.getBoundingClientRect(); return e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom; }; + const onDown = (e: PointerEvent) => { down = e.target === d && outside(e); }; + const onClick = (e: MouseEvent) => { if (down && e.target === d && outside(e)) close(); down = false; }; + const onKey = (e: KeyboardEvent) => { + if (e.key !== "Tab" || e.defaultPrevented) return; + const all = Array.from(d.querySelectorAll('a[href],button:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter((n) => n.getClientRects().length && !n.closest("[hidden]")); + if (!all.length) return; + const first = all[0]!, last = all[all.length - 1]!, at = document.activeElement; + if (e.shiftKey && (at === first || at === d)) { e.preventDefault(); last.focus(); } else if (!e.shiftKey && at === last) { e.preventDefault(); first.focus(); } + }; + d.addEventListener("close", onClose); + d.addEventListener("pointerdown", onDown); + d.addEventListener("click", onClick); + d.addEventListener("keydown", onKey); + return () => { clearTimeout(timer); d.removeEventListener("close", onClose); d.removeEventListener("pointerdown", onDown); d.removeEventListener("click", onClick); d.removeEventListener("keydown", onKey); if (d.open) d.close(); }; + }, [opener, close]); + + return createPortal( + + {inLevel(1, <> +
+
+

{model.title}

+ {source !== undefined && source !== null ?

{source}

: null} +
+ +
+

{summary}

{showList ?
: null}
- +
{key ?
: null}
@@ -152,9 +213,10 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o
- - -
+ + )} +
, + document.body, ); } diff --git a/packages/react/src/diagram-zoom-core.ts b/packages/react/src/diagram-zoom-core.ts index c4578317..eee1eaad 100644 --- a/packages/react/src/diagram-zoom-core.ts +++ b/packages/react/src/diagram-zoom-core.ts @@ -5,6 +5,19 @@ // (plus the stage's padding) so the stage has something to scroll. A pan is a scroll. Nothing is animated: a step, the wheel and a pinch land at once. // The engine never measures a zoomed figure: the viewer gives this the layer's size at 100% (`size`), read with the zoom taken off. +import type { Dyn, Measured, Model } from "./diagram-core"; + +type MeasureFigure = (fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn?: (s: string) => void, sizeTo?: (least: number) => void) => Measured; + +/** The viewer's addition to the figure's keys sentence (9.8). */ +export const VIEWER_KEYS = "Plus and minus zoom, zero fits the drawing, Escape closes."; + +/** The viewer's key hint (9.8): the figure's, with Esc closing and the zoom keys added. */ +export function viewerHint(entries: Array<{ keys: string[]; words: string }>): Array<{ keys: string[]; words: string }> { + const out = entries.filter((e) => e.keys[0] !== "Esc"); + return [...out, { keys: ["+", "−"], words: "zoom" }, { keys: ["0"], words: "fit" }, { keys: ["Esc"], words: "close" }]; +} + /** The ladder the buttons and keys step on (9.4): a browser's own, shortened. */ export const ZOOM_STEPS = [25, 33, 50, 67, 75, 100, 125, 150, 200, 300, 400]; const MAX = 4; @@ -320,3 +333,62 @@ export function revealIn(stage: HTMLElement, el: Element, margin: number): void if (r.left < left) stage.scrollLeft -= left - r.left; else if (r.right > right) stage.scrollLeft += Math.min(r.right - right, r.left - left); if (r.top < top) stage.scrollTop -= top - r.top; else if (r.bottom > bottom) stage.scrollTop += Math.min(r.bottom - bottom, r.top - top); } + +/** What the viewer's figure remembers between layouts: the least width the engine was found to draw this data at (0: none). */ +export interface ViewerMemo { model?: unknown; least?: number } +export interface ViewerLayout { + /** The layer the figure is laid out in: its width is the layout width; its transform (the zoom) is taken off while it is measured. */ + layer: HTMLElement; + /** The stage's inner width, the page row and `size-breakpoint-container`, in CSS pixels. */ + avail: number; + row: number; + contain: number; + memo: ViewerMemo; + /** The engine's measure (diagram-core's measureFigure), handed over so this module holds no copy of it. */ + measureFigure: MeasureFigure; +} + +/** + * The viewer's layout (DECISIONS 310, 9.3), for React and the skill alike: the figure is laid out at the stage's inner width, never under its least drawn + * width and never over the page row unless that width is more; a stack is held only when nothing is drawn, at most the container's width. The engine + * measures only at 100%: the zoom is taken off the layer while it measures and put back before anything paints. + */ +export function measureViewerFigure(fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn: ((s: string) => void) | undefined, v: ViewerLayout): Measured { + const { layer, memo, measureFigure } = v; + if (memo.model !== m) { memo.model = m; memo.least = undefined; } + const sizeTo = (least: number) => { layer.style.width = `${Math.max(memo.least || least, Math.min(v.avail, v.row))}px`; }; + // The layer has no width of its own until the first layout: it starts at the stage's, so the figure can be measured. + if (!layer.style.width) layer.style.width = `${Math.min(v.avail, v.row)}px`; + const zoomed = layer.style.transform; + layer.style.transform = "none"; + // A dialog still opening is scaled (from .98): the layer is scaled by the inverse while it is measured, so what is read is 100% whatever its ancestors do. + const ancestors = layer.offsetWidth ? layer.getBoundingClientRect().width / layer.offsetWidth : 1; + if (Math.abs(ancestors - 1) > 1e-4) layer.style.transform = `scale(${1 / ancestors})`; + // Before the least drawn width is known, a refusal at the token sum is expected and is not the author's to fix: it says nothing. + let result = measureFigure(fig, m, P, base, current, apply, memo.least === undefined ? undefined : warn, sizeTo); + // The least drawn width is the first width the engine draws the figure at, which the token sum can undercount (a sequence's columns are measured, a + // decision may be taller than wide at a width). Found once by trying wider layouts, in steps of 16 and then by the pixel, up to half the row past it. A width + // counts when it draws twice running: measured from the stack, then again from its own drawn state, as every later measure is. + if (result.dyn.layout === "stacked" && memo.least === undefined && result.least !== undefined) { + const from = result.dyn; + const at = (w: number) => { + layer.style.width = `${w}px`; + const first = measureFigure(fig, m, P, base, from, apply); + return first.dyn.layout === "drawn" ? measureFigure(fig, m, P, base, first.dyn, apply) : first; + }; + const start = Math.max(result.least, Math.min(v.avail, v.row)); + const cap = Math.max(v.row, start) * 1.5; + let found: number | undefined; + for (let w = start + 16; w <= cap && found === undefined; w += 16) if (at(w).dyn.layout === "drawn") found = w; + if (found !== undefined) for (let w = found - 15; w < found; w++) if (at(w).dyn.layout === "drawn") { found = w; break; } + memo.least = found ?? 0; + result = found !== undefined ? at(found) : measureFigure(fig, m, P, base, from, apply, warn, sizeTo); + } + if (result.dyn.layout === "stacked" && fig.clientWidth > v.contain) { + layer.style.width = `${v.contain}px`; + result = measureFigure(fig, m, P, base, result.dyn, apply, warn); + } + layer.style.transform = zoomed; + return result; +} + diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index d203e3ef..87146911 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4928,7 +4928,6 @@ window. The body is the stage: it scrolls both ways, so a pan is a scroll. The figure in it is laid out once at 100% (the layer's width) and zoomed with one transform: never a viewBox, CSS zoom, a canvas or a picture, and no layer is held (no will-change). Nothing in it moves: a zoom step lands at once. Decided by the council's decider alone; no draft, check or position. The implementation hasn't been reviewed. */ - .basalt-diagram-expand > .basalt-icon { flex: none; } @media (pointer: coarse) { .basalt-diagram-expand { min-height: var(--basalt-size-tap-min); } } @@ -4998,7 +4997,47 @@ } /* The viewer and its scrim do not print: the page prints its own figure, untraced and light. "Expand" does not print. */ @media print { - .basalt-diagram-expand, .basalt-diagram-viewer, :root:has(.basalt-diagram-viewer) .basalt-dialog-backdrop { display: none !important; } + .basalt-diagram-expand, .basalt-diagram-viewer { display: none !important; } + } + + /* ---- Diagram viewer, React's dialog (DECISIONS 310): the form dialog's box on a native modal , as the HTML skill's is ---- + Base UI's dialog is not imported by the viewer's chunk (it would widen the Base UI chunk every component shares), so the box's motion is written here for + the native element: from 720 a scale from .98 and a fade over duration-slow, under it the sheet's rise over duration-slower, each out at three quarters on + ease-in, and a fade alone under reduced motion. The scrim is its ::backdrop. The page behind does not scroll while it is open. */ + dialog.basalt-dialog.basalt-diagram-viewer { + --_out: calc(var(--basalt-duration-slow) * 0.75); + margin: 0; + border: 0; + max-width: none; + max-height: none; + opacity: 0; + transform: translate(-50%, -50%) scale(0.98); + transition-property: opacity, transform, overlay, display; + transition-behavior: allow-discrete; + transition-duration: var(--_out); + transition-timing-function: var(--basalt-ease-in); + } + dialog.basalt-dialog.basalt-diagram-viewer[open] { opacity: 1; transform: translate(-50%, -50%); transition-duration: var(--basalt-duration-slow); transition-timing-function: var(--basalt-ease-out); } + @starting-style { dialog.basalt-dialog.basalt-diagram-viewer[open] { opacity: 0; transform: translate(-50%, -50%) scale(0.98); } } + dialog.basalt-dialog.basalt-diagram-viewer::backdrop { background: var(--basalt-scrim); opacity: 0; transition: opacity var(--_out) var(--basalt-ease-in), overlay var(--_out) allow-discrete, display var(--_out) allow-discrete; } + dialog.basalt-dialog.basalt-diagram-viewer[open]::backdrop { opacity: 1; transition-duration: var(--basalt-duration-slow); transition-timing-function: var(--basalt-ease-out); } + @starting-style { dialog.basalt-dialog.basalt-diagram-viewer[open]::backdrop { opacity: 0; } } + :root:has(dialog.basalt-diagram-viewer[open]) { overflow: hidden; } + /* stylelint-disable-next-line unit-disallowed-list -- size-breakpoint-md (720px): a media query cannot read a token */ + @media (width < 720px) { + dialog.basalt-dialog.basalt-diagram-viewer { --_out: calc(var(--basalt-duration-slower) * 0.75); opacity: 1; transform: translateY(100%); } + dialog.basalt-dialog.basalt-diagram-viewer[open] { transform: none; transition-duration: var(--basalt-duration-slower); } + @starting-style { dialog.basalt-dialog.basalt-diagram-viewer[open] { opacity: 1; transform: translateY(100%); } } + } + @media (prefers-reduced-motion: reduce) { + dialog.basalt-dialog.basalt-diagram-viewer, dialog.basalt-dialog.basalt-diagram-viewer[open] { transform: translate(-50%, -50%); } + @starting-style { dialog.basalt-dialog.basalt-diagram-viewer[open] { transform: translate(-50%, -50%); } } + } + /* stylelint-disable-next-line unit-disallowed-list -- size-breakpoint-md (720px): a media query cannot read a token */ + @media (width < 720px) and (prefers-reduced-motion: reduce) { + dialog.basalt-dialog.basalt-diagram-viewer, dialog.basalt-dialog.basalt-diagram-viewer[open] { opacity: 0; transform: none; } + dialog.basalt-dialog.basalt-diagram-viewer[open] { opacity: 1; } + @starting-style { dialog.basalt-dialog.basalt-diagram-viewer[open] { opacity: 0; transform: none; } } } /* ---- Lit figures, the headline frame and N1's figures (DECISIONS 153) ---- diff --git a/tools/html-skill/src/icons.json b/tools/html-skill/src/icons.json index 8b31ee2b..23780f77 100644 --- a/tools/html-skill/src/icons.json +++ b/tools/html-skill/src/icons.json @@ -1,2 +1,2 @@ ["Command", "Option", "Control", "Sun", "Moon", "Info", "Warning", "ArrowRight", "ArrowLeft", "ArrowUp", - "ArrowDown", "CaretUpDown", "Trash", "Download", "ArrowClockwise", "CheckCircle", "XCircle", "Circle", "GithubLogo", "XLogo", "LinkedinLogo", "InstagramLogo", "YoutubeLogo", "EnvelopeSimple", "TerminalWindow", "ArrowsOutSimple"] + "ArrowDown", "CaretUpDown", "Trash", "Download", "ArrowClockwise", "CheckCircle", "XCircle", "Circle", "GithubLogo", "XLogo", "LinkedinLogo", "InstagramLogo", "YoutubeLogo", "EnvelopeSimple", "TerminalWindow"] diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index 1b4cd968..d1571146 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -836,9 +836,6 @@ "dialog-form", "sheet" ], - "icons": [ - "ArrowsOutSimple" - ], "budget": 12000, "usage": 900, "builds": [ diff --git a/tools/html-skill/src/modules/diagram-zoom.js b/tools/html-skill/src/modules/diagram-zoom.js index c7113bb9..bd1fee58 100644 --- a/tools/html-skill/src/modules/diagram-zoom.js +++ b/tools/html-skill/src/modules/diagram-zoom.js @@ -4,7 +4,7 @@ bundled into this module by build.mjs); the figure is drawn by the diagram module's engine (Basalt._.diagramKit), so this holds no second copy of it. compose.mjs adds this module to a page with a figure unless every figure on it says "zoom": false. The implementation hasn't been reviewed. Source: tools/html-skill/src/modules/diagram-zoom.js (do not edit the copy in the skill folder). */ -import { attachZoom, revealIn } from "../../../../packages/react/src/diagram-zoom-core.ts"; +import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } from "../../../../packages/react/src/diagram-zoom-core.ts"; (function (B) { 'use strict'; @@ -22,7 +22,7 @@ import { attachZoom, revealIn } from "../../../../packages/react/src/diagram-zoo var model = kit.buildModel(still); var id = 'dgv' + (++serial); var key = kit.figureKey('diagram', model); - var hint = kit.hintEntries(model, true).map(function (e) { return '' + e.keys.map(kbd).join(' ') + ' ' + esc(e.words) + ''; }).join(''); + var hint = viewerHint(kit.hintEntries(model)).map(function (e) { return '' + e.keys.map(kbd).join(' ') + ' ' + esc(e.words) + ''; }).join(''); var d = document.createElement('dialog'); d.className = 'panel float modal dialog diagram-viewer'; d.setAttribute('data-form', ''); @@ -63,7 +63,8 @@ import { attachZoom, revealIn } from "../../../../packages/react/src/diagram-zoo }); var memo = {}; var view = { - layer: layer, avail: 0, row: 1104, contain: 480, memo: memo, + layer: layer, avail: 0, row: 1104, contain: 480, memo: memo, measureFigure: kit.measureFigure, keys: VIEWER_KEYS, + measure: function (f, m, p, base, current, apply, warn) { return measureViewerFigure(f, m, p, base, current, apply, warn, view); }, onMeasured: function (measured, f) { stage.setAttribute('data-layout', measured.dyn.layout || ''); if (keyBox) { keyBox.setAttribute('data-layout', measured.dyn.layout || ''); keyBox.toggleAttribute('data-bare', Boolean(measured.dyn.bare)); } @@ -140,7 +141,8 @@ import { attachZoom, revealIn } from "../../../../packages/react/src/diagram-zoo button.setAttribute('data-variant', 'secondary'); button.setAttribute('data-size', 'sm'); button.setAttribute('aria-haspopup', 'dialog'); - button.innerHTML = _.icon('ArrowsOutSimple', { size: 16 }) + 'Expand'; + // Words only, as React's (a deviation from 9.1): the core set draws no expand glyph. + button.innerHTML = 'Expand'; var toggle = foot.querySelector('.diagram-toggle'); if (toggle && toggle.nextSibling) foot.insertBefore(button, toggle.nextSibling); else foot.appendChild(button); var onClick = function () { openViewer(page, spec, ctx, button); }; diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 6f9e8323..c1794ec8 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -4,7 +4,7 @@ and draw the same pixels. compose.mjs runs `Basalt._.diagramMarkup` at build time and writes each figure's words into the page, so it reads before any script runs; this script then measures it, draws its lines and labels, and wires the keys, the trace and the list. Source: tools/html-skill/src/modules/diagram.js (do not edit the copy in the skill folder). */ -import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, measureViewerFigure, moveStop, settleEntrance, syncAttributes, toHtml } from "../../../../packages/react/src/diagram-core.ts"; +import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, moveStop, settleEntrance, syncAttributes, toHtml } from "../../../../packages/react/src/diagram-core.ts"; (function (B) { 'use strict'; @@ -13,7 +13,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis var serial = 0; function options(base, spec, viewer) { - return { prefix: P, base: base, hasSource: spec.source !== undefined && spec.source !== null && spec.source !== '', hiddenClass: 'visually-hidden', viewer: Boolean(viewer) }; + return { prefix: P, base: base, hasSource: spec.source !== undefined && spec.source !== null && spec.source !== '', hiddenClass: 'visually-hidden', viewer: viewer ? viewer.keys : undefined }; } function slots(model, spec, base, open) { var kbd = function (k) { return '' + escapeHtml(k) + ''; }; @@ -93,7 +93,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis } function layout() { // The viewer's figure (DECISIONS 310, the diagram-zoom module) is laid out at the stage's width and measured only at 100%. - measured = viewer ? measureViewerFigure(figure, model, P, base, state, apply, warn, viewer) : measureFigure(figure, model, P, base, state, apply, warn); + measured = (viewer ? viewer.measure : measureFigure)(figure, model, P, base, state, apply, warn); state = measured.dyn; apply(state); syncToggle(); @@ -214,7 +214,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis _.diagramMarkup = markup; // What the viewer (the diagram-zoom module) draws with: this module's engine, so that module holds no second copy of it. - _.diagramKit = { draw: draw, buildModel: buildModel, figureKey: figureKey, figureList: figureList, hintEntries: hintEntries, toHtml: toHtml, escapeHtml: escapeHtml, settleEntrance: settleEntrance }; + _.diagramKit = { draw: draw, buildModel: buildModel, figureKey: figureKey, figureList: figureList, hintEntries: hintEntries, toHtml: toHtml, escapeHtml: escapeHtml, settleEntrance: settleEntrance, measureFigure: measureFigure }; B.diagram = function (figure, spec) { var d = figure.__diagram; var key = d && d.send ? sendless(spec) : null; From d92cc927cd2843b9cd568be52051fc915771b3c2 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:19:38 -0600 Subject: [PATCH 04/62] The viewer's tests (diagram-viewer.test.mjs), and what they found The figure snaps its lines from its drawing's origin on whole pixels, and is laid out again once the dialog's entrance ends, so the viewer's ink is the page's. The list keeps the drawing's place: it is saved before the drawing is hidden. A hidden figure's empty measure no longer resets the zoom. In print the viewer has no transition, so its display change is not held by the dialog's own. Co-Authored-By: Claude Opus 5.5 --- .../skills/basalt-html/parts/diagram-zoom.css | 2 +- .../skills/basalt-html/parts/diagram-zoom.js | 2 +- .agent/skills/basalt-html/parts/diagram.js | 2 +- packages/react/src/diagram-figure.tsx | 3 +- packages/react/src/diagram-viewer.tsx | 11 +- packages/react/src/diagram-zoom-core.ts | 9 +- packages/react/src/styles/components.css | 3 +- packages/react/test/diagram-viewer.test.mjs | 531 ++++++++++++++++++ tools/html-skill/src/modules/diagram-zoom.js | 6 +- tools/html-skill/src/modules/diagram.js | 2 +- 10 files changed, 560 insertions(+), 11 deletions(-) create mode 100644 packages/react/test/diagram-viewer.test.mjs diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.css b/.agent/skills/basalt-html/parts/diagram-zoom.css index c566e4f0..24608262 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.css +++ b/.agent/skills/basalt-html/parts/diagram-zoom.css @@ -1 +1 @@ -@layer basalt{@media(pointer:coarse){.diagram-expand{min-height:var(--basalt-size-tap-min)}}@media(width>=720px){.dialog[data-form].diagram-viewer,.dialog[data-form][data-held].diagram-viewer{width:calc(100vw - 2 * var(--basalt-space-4));max-width:none;height:calc(100dvh - 2 * var(--basalt-space-4));max-height:none}}.diagram-viewer .sheet-head{flex:none}.diagram-viewer-source{overflow-wrap:break-word}.diagram-stage{--_pad: var(--basalt-space-4);--_travel: var(--basalt-space-1);--_clear: var(--basalt-space-4);--_rest: var(--basalt-duration-slower);position:relative;flex:1 1 auto;display:flex;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;touch-action:none;outline:none}@media(width>=720px){.diagram-stage{--_pad: var(--basalt-space-6)}}.diagram-stage:focus-visible{outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:calc(-1 * var(--basalt-size-focus-width))}.diagram-stage[data-pannable]{cursor:grab}.diagram-stage[data-pannable][data-dragging]{cursor:grabbing}.diagram-stage[data-list]{display:block;touch-action:pan-y}.diagram-probe{position:absolute;top:0;left:0;height:0;visibility:hidden;pointer-events:none}.diagram-probe[data-probe=row]{width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter))}.diagram-probe[data-probe=contain]{width:var(--basalt-size-breakpoint-container)}.diagram-sizer{position:relative;flex:none;box-sizing:content-box;margin:auto;padding:var(--_pad)}.diagram-sizer[hidden]{display:none}.diagram-layer{position:absolute;top:var(--_pad);inset-inline-start:var(--_pad);transform-origin:0 0;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}.diagram-layer:dir(rtl){transform-origin:100% 0}.diagram[data-viewer]{gap:0}.diagram[data-viewer]>:is(.diagram-head,.diagram-key,.diagram-hint,.diagram-foot,.diagram-list,.diagram-summary){display:none}.diagram-viewer-list{box-sizing:border-box;max-width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter) + 2 * var(--_pad));padding:var(--_pad)}.diagram-viewer-foot{display:flex;flex-direction:column;gap:var(--basalt-space-3);padding-block-start:var(--basalt-space-3)}.diagram-viewer-key{--_ground: var(--panel-bg, var(--basalt-surface-overlay))}.diagram-viewer-key .diagram-key{padding-block-start:0;border-top:0}.diagram-viewer-key[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram-viewer-key[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram-viewer-key[data-bare] .diagram-entry[data-line]{display:none}.diagram-viewer-row{display:flex;flex-wrap:wrap;align-items:center;gap:var(--basalt-space-2)}.diagram-zoom{display:flex;align-items:center;gap:var(--basalt-space-1)}.diagram-level{display:inline-grid;justify-items:center;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans);font-variant-numeric:tabular-nums}.diagram-level:before{content:attr(data-reserve);grid-area:1 / 1;visibility:hidden}.diagram-level>span{grid-area:1 / 1}.diagram-viewer-hint{flex:1 1 auto;min-width:0}.diagram-viewer-end{display:flex;gap:var(--basalt-space-2);margin-inline-start:auto}@media(pointer:coarse){.diagram-zoom .btn,.diagram-viewer-end .btn{min-height:var(--basalt-size-tap-min);min-width:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram-level{color:CanvasText}.diagram-viewer-foot [aria-disabled=true]{color:GrayText}}@media print{.diagram-expand,.diagram-viewer{display:none!important}}} +@layer basalt{@media(pointer:coarse){.diagram-expand{min-height:var(--basalt-size-tap-min)}}@media(width>=720px){.dialog[data-form].diagram-viewer,.dialog[data-form][data-held].diagram-viewer{width:calc(100vw - 2 * var(--basalt-space-4));max-width:none;height:calc(100dvh - 2 * var(--basalt-space-4));max-height:none}}.diagram-viewer .sheet-head{flex:none}.diagram-viewer-source{overflow-wrap:break-word}.diagram-stage{--_pad: var(--basalt-space-4);--_travel: var(--basalt-space-1);--_clear: var(--basalt-space-4);--_rest: var(--basalt-duration-slower);position:relative;flex:1 1 auto;display:flex;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;touch-action:none;outline:none}@media(width>=720px){.diagram-stage{--_pad: var(--basalt-space-6)}}.diagram-stage:focus-visible{outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:calc(-1 * var(--basalt-size-focus-width))}.diagram-stage[data-pannable]{cursor:grab}.diagram-stage[data-pannable][data-dragging]{cursor:grabbing}.diagram-stage[data-list]{display:block;touch-action:pan-y}.diagram-probe{position:absolute;top:0;left:0;height:0;visibility:hidden;pointer-events:none}.diagram-probe[data-probe=row]{width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter))}.diagram-probe[data-probe=contain]{width:var(--basalt-size-breakpoint-container)}.diagram-sizer{position:relative;flex:none;box-sizing:content-box;margin:auto;padding:var(--_pad)}.diagram-sizer[hidden]{display:none}.diagram-layer{position:absolute;top:var(--_pad);inset-inline-start:var(--_pad);transform-origin:0 0;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}.diagram-layer:dir(rtl){transform-origin:100% 0}.diagram[data-viewer]{gap:0}.diagram[data-viewer]>:is(.diagram-head,.diagram-key,.diagram-hint,.diagram-foot,.diagram-list,.diagram-summary){display:none}.diagram-viewer-list{box-sizing:border-box;max-width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter) + 2 * var(--_pad));padding:var(--_pad)}.diagram-viewer-foot{display:flex;flex-direction:column;gap:var(--basalt-space-3);padding-block-start:var(--basalt-space-3)}.diagram-viewer-key{--_ground: var(--panel-bg, var(--basalt-surface-overlay))}.diagram-viewer-key .diagram-key{padding-block-start:0;border-top:0}.diagram-viewer-key[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram-viewer-key[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram-viewer-key[data-bare] .diagram-entry[data-line]{display:none}.diagram-viewer-row{display:flex;flex-wrap:wrap;align-items:center;gap:var(--basalt-space-2)}.diagram-zoom{display:flex;align-items:center;gap:var(--basalt-space-1)}.diagram-level{display:inline-grid;justify-items:center;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans);font-variant-numeric:tabular-nums}.diagram-level:before{content:attr(data-reserve);grid-area:1 / 1;visibility:hidden}.diagram-level>span{grid-area:1 / 1}.diagram-viewer-hint{flex:1 1 auto;min-width:0}.diagram-viewer-end{display:flex;gap:var(--basalt-space-2);margin-inline-start:auto}@media(pointer:coarse){.diagram-zoom .btn,.diagram-viewer-end .btn{min-height:var(--basalt-size-tap-min);min-width:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram-level{color:CanvasText}.diagram-viewer-foot [aria-disabled=true]{color:GrayText}}@media print{.diagram-expand,.diagram-viewer{display:none!important;transition:none!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.js b/.agent/skills/basalt-html/parts/diagram-zoom.js index b03fd9eb..cfda377d 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.js +++ b/.agent/skills/basalt-html/parts/diagram-zoom.js @@ -1 +1 @@ -(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(b=>b.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:b,layer:m,status:x}=l;let c=0,M=0,i=1,n=1,u=!1,s=!1,p=null,h="",z=0;const g=()=>Number.parseFloat(getComputedStyle(b).paddingTop)||0,S=()=>Math.min(n,1),T=t=>Math.min(j,Math.max(S(),t));function o(){if(!c||!M)return 1;const t=g(),a=e.clientWidth-2*t,k=e.clientHeight-2*t;if(a<=0||k<=0)return Math.min(1,J);const W=Math.min(a/c,k/M);return Math.min(J,Math.floor(W*100+1e-6)/100)}function y(){const t=S();return{zoom:i,level:Math.round(i*100),fit:n,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-n)e.clientWidth-2*g()+.5||M*i>e.clientHeight-2*g()+.5)}function v(){clearTimeout(z);const t=`Zoom ${Math.round(i*100)}%`;z=window.setTimeout(()=>{t!==h&&(h=t,x.textContent=t)},l.rest)}function w(){b.style.width=`${c*i}px`,b.style.height=`${M*i}px`,m.style.transform=`scale(${i})`}function D(t){const a=m.getBoundingClientRect();return{x:(t.x-a.left)/i,y:(t.y-a.top)/i}}function R(t,a){const k=m.getBoundingClientRect();e.scrollLeft+=k.left+t.x*i-a.x,e.scrollTop+=k.top+t.y*i-a.y}const _=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function I(t,a=_(),k){if(s)return;const W=T(t);if(Math.abs(W-i)<1e-6){f();return}const ot=k??D(a);i=W,w(),R(ot,a),f(),v()}function L(t){u=!0;const a=i*100,k=t?G.find(W=>W>a+.5):[...G].reverse().find(W=>WNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,r=()=>{const[t,a]=[...d.values()];return{x:(t.x+a.x)/2,y:(t.y+a.y)/2}},E=()=>{const[t,a]=[...d.values()];return Math.hypot(t.x-a.x,t.y-a.y)};function V(t){if(!s&&!(t.pointerType==="mouse"&&t.button!==0)&&(d.set(t.pointerId,{x:t.clientX,y:t.clientY}),d.size===1&&(H={x:t.clientX,y:t.clientY},C=H,q=!1,O=!1),d.size===2&&t.pointerType==="touch")){const a=r();F={d0:E()||1,z0:i,c:D(a)},O=!0,q=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function Y(t){if(!d.has(t.pointerId)||s)return;if(d.set(t.pointerId,{x:t.clientX,y:t.clientY}),F&&d.size>=2){u=!0;const k=T(F.z0*(E()/F.d0)),W=r();Math.abs(k-i)>1e-6&&(i=k,w(),f(),v()),R(F.c,W);return}if(d.size!==1||!H||!C)return;const a={x:t.clientX,y:t.clientY};if(!q){if(Math.hypot(a.x-H.x,a.y-H.y)<=P())return;q=!0,O=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=a.x-C.x,e.scrollTop-=a.y-C.y,C=a,t.preventDefault()}function Z(t){if(d.has(t.pointerId)){if(d.delete(t.pointerId),d.size<2&&(F=null),d.size===1){const[a]=[...d.values()];C=a,H=a,q=!0;return}d.size===0&&(q=!1,e.removeAttribute("data-dragging"),H=C=null)}}function X(t){O&&(O=!1,t.preventDefault(),t.stopPropagation())}const N=new ResizeObserver(()=>{if(!c||!M)return;const t=u?D(_()):null;n=o(),u?(i=T(i),w(),t&&R(t,_())):(i=n,w()),f()});return N.observe(e),e.addEventListener("wheel",K,{passive:!1}),e.addEventListener("keydown",$),e.addEventListener("pointerdown",V),e.addEventListener("pointermove",Y),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",X,!0),{size:B,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:A,state:y,list(t){t!==s&&(t?(p={left:e.scrollLeft,top:e.scrollTop},s=!0,e.setAttribute("data-list",""),e.scrollTop=0):(s=!1,e.removeAttribute("data-list"),w(),p&&(e.scrollLeft=p.left,e.scrollTop=p.top),p=null),f())},travelled:()=>O,destroy(){clearTimeout(z),N.disconnect(),e.removeEventListener("wheel",K),e.removeEventListener("keydown",$),e.removeEventListener("pointerdown",V),e.removeEventListener("pointermove",Y),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",X,!0)}}}function nt(l,e,b){const m=l.getBoundingClientRect(),x=e.getBoundingClientRect(),c=m.left+b,M=m.left+l.clientWidth-b,i=m.top+b,n=m.top+l.clientHeight-b;x.leftM&&(l.scrollLeft+=Math.min(x.right-M,x.left-c)),x.topn&&(l.scrollTop+=Math.min(x.bottom-n,x.top-i))}function rt(l,e,b,m,x,c,M,i){const{layer:n,memo:u,measureFigure:s}=i;u.model!==e&&(u.model=e,u.least=void 0);const p=S=>{n.style.width=`${Math.max(u.least||S,Math.min(i.avail,i.row))}px`};n.style.width||(n.style.width=`${Math.min(i.avail,i.row)}px`);const h=n.style.transform;n.style.transform="none";const z=n.offsetWidth?n.getBoundingClientRect().width/n.offsetWidth:1;Math.abs(z-1)>1e-4&&(n.style.transform=`scale(${1/z})`);let g=s(l,e,b,m,x,c,u.least===void 0?void 0:M,p);if(g.dyn.layout==="stacked"&&u.least===void 0&&g.least!==void 0){const S=g.dyn,T=v=>{n.style.width=`${v}px`;const w=s(l,e,b,m,S,c);return w.dyn.layout==="drawn"?s(l,e,b,m,w.dyn,c):w},o=Math.max(g.least,Math.min(i.avail,i.row)),y=Math.max(i.row,o)*1.5;let f;for(let v=o+16;v<=y&&f===void 0;v+=16)T(v).dyn.layout==="drawn"&&(f=v);if(f!==void 0){for(let v=f-15;vi.contain&&(n.style.width=`${i.contain}px`,g=s(l,e,b,m,g.dyn,c,M)),n.style.transform=h,g}(function(l){"use strict";var e=l._,b=0;function m(i){return e.diagramKit.escapeHtml(String(i??""))}function x(i){return''+m(i)+""}function c(i,n){return parseFloat(getComputedStyle(i).getPropertyValue(n))||0}function M(i,n,u,s){var p=e.diagramKit,h=Object.assign({},n,{motion:"still"}),z=p.buildModel(h),g="dgv"+ ++b,S=p.figureKey("diagram",z),T=et(p.hintEntries(z)).map(function(r){return""+r.keys.map(x).join(" ")+" "+m(r.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",g+"-summary"),o.innerHTML='

'+m(z.title)+"

"+(n.source?'

'+m(n.source)+"

":"")+'

'+m(n.summary)+'

'+(S?'
'+p.toHtml(S)+"
":"")+'
',document.body.appendChild(o);var y=o.querySelector(".diagram-stage"),f=o.querySelector(".diagram-sizer"),v=o.querySelector(".diagram-layer"),w=v.firstChild,D=o.querySelector('[role="status"]'),R=o.querySelector(".diagram-level > span"),_=o.querySelector(".diagram-viewer-key"),I=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},A=null,B=!1,K=!1,$=function(r,E){E?r.setAttribute("aria-disabled","true"):r.removeAttribute("aria-disabled")},d=at({stage:y,sizer:f,layer:v,status:D,rest:c(y,"--_rest")||300,onChange:function(r){R.textContent=r.level+"%",$(L.out,r.listOpen||r.atMin),$(L.in,r.listOpen||r.atMax),$(L.fit,r.listOpen||r.atFit)}}),H={},C={layer:v,avail:0,row:1104,contain:480,memo:H,measureFigure:p.measureFigure,keys:tt,measure:function(r,E,V,Y,Z,X,N){return rt(r,E,V,Y,Z,X,N,C)},onMeasured:function(r,E){y.setAttribute("data-layout",r.dyn.layout||""),_&&(_.setAttribute("data-layout",r.dyn.layout||""),_.toggleAttribute("data-bare",!!r.dyn.bare)),K=!!r.dyn.bare,I.hidden=K,O(B||K),d.size(E.offsetWidth,E.offsetHeight)}};function q(){C.avail=Math.max(0,Math.floor(y.clientWidth-2*(parseFloat(getComputedStyle(f).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function O(r){r&&!A&&(A=document.createElement("div"),A.className="diagram-list diagram-viewer-list",A.innerHTML=p.figureList("diagram",z).map(function(E){return p.toHtml(E)}).join(""),y.appendChild(A)),A&&(A.hidden=!r),f.hidden=r,d.list(r)}I.addEventListener("click",function(){B=!B,I.setAttribute("aria-expanded",String(B)),I.firstElementChild.textContent=B?"Hide the list":"View as list",O(B||K)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||d.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||d.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||d.fit()}),y.addEventListener("focusin",function(r){var E=r.target.closest&&r.target.closest(".diagram-node");E&&y.contains(E)&&nt(y,E,c(y,"--_clear")||16)}),l.openDialog(o,s),q(),p.draw(w,h,!1,C),setTimeout(function(){y.focus({preventScroll:!0})},0);var F=y.clientWidth,P=new ResizeObserver(function(){Math.abs(y.clientWidth-F)<.5||(F=y.clientWidth,q(),w.__diagram&&w.__diagram.layout())});P.observe(y),i.setAttribute("data-viewing",""),u.animated&&u.settle(),o.addEventListener("close",function(){P.disconnect(),d.destroy(),w.__diagram&&w.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},c(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,n,u){var s=i.querySelector(":scope > .diagram-foot");if(!s)return null;var p=s.querySelector(".diagram-expand");p&&p.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var z=s.querySelector(".diagram-toggle");z&&z.nextSibling?s.insertBefore(h,z.nextSibling):s.appendChild(h);var g=function(){M(i,n,u,h)};return h.addEventListener("click",g),{destroy:function(){h.removeEventListener("click",g),h.remove()}}}})(window.Basalt)})(); +(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(y=>y.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:y,layer:p,status:x}=l;let u=0,k=0,i=1,n=1,f=!1,d=!1,g=null,h="",w=0;const S=()=>Number.parseFloat(getComputedStyle(y).paddingTop)||0,T=()=>Math.min(n,1),q=t=>Math.min(j,Math.max(T(),t));function o(){if(!u||!k)return 1;const t=S(),a=e.clientWidth-2*t,b=e.clientHeight-2*t;if(a<=0||b<=0)return Math.min(1,J);const H=Math.min(a/u,b/k);return Math.min(J,Math.floor(H*100+1e-6)/100)}function s(){const t=T();return{zoom:i,level:Math.round(i*100),fit:n,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-n)e.clientWidth-2*S()+.5||k*i>e.clientHeight-2*S()+.5)}function A(){clearTimeout(w);const t=`Zoom ${Math.round(i*100)}%`;w=window.setTimeout(()=>{t!==h&&(h=t,x.textContent=t)},l.rest)}function v(){y.style.width=`${u*i}px`,y.style.height=`${k*i}px`,p.style.transform=`scale(${i})`}function I(t){const a=p.getBoundingClientRect();return{x:(t.x-a.left)/i,y:(t.y-a.top)/i}}function z(t,a){const b=p.getBoundingClientRect();e.scrollLeft+=b.left+t.x*i-a.x,e.scrollTop+=b.top+t.y*i-a.y}const m=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function _(t,a=m(),b){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){M();return}const ot=b??I(a);i=H,v(),z(ot,a),M(),A()}function L(t){f=!0;const a=i*100,b=t?G.find(H=>H>a+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,r=()=>{const[t,a]=[...c.values()];return{x:(t.x+a.x)/2,y:(t.y+a.y)/2}},E=()=>{const[t,a]=[...c.values()];return Math.hypot(t.x-a.x,t.y-a.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),c.size===1&&(O={x:t.clientX,y:t.clientY},C=O,B=!1,F=!1),c.size===2&&t.pointerType==="touch")){const a=r();$={d0:E()||1,z0:i,c:I(a)},F=!0,B=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!c.has(t.pointerId)||d)return;if(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),$&&c.size>=2){f=!0;const b=q($.z0*(E()/$.d0)),H=r();Math.abs(b-i)>1e-6&&(i=b,v(),M(),A()),z($.c,H);return}if(c.size!==1||!O||!C)return;const a={x:t.clientX,y:t.clientY};if(!B){if(Math.hypot(a.x-O.x,a.y-O.y)<=V())return;B=!0,F=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=a.x-C.x,e.scrollTop-=a.y-C.y,C=a,t.preventDefault()}function Z(t){if(c.has(t.pointerId)){if(c.delete(t.pointerId),c.size<2&&($=null),c.size===1){const[a]=[...c.values()];C=a,O=a,B=!0;return}c.size===0&&(B=!1,e.removeAttribute("data-dragging"),O=C=null)}}function P(t){F&&(F=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!u||!k)return;const t=f?I(m()):null;n=o(),f?(i=q(i),v(),t&&z(t,m())):(i=n,v()),M()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:K,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:W,state:s,list(t){t!==d&&(t?(g={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),v(),g&&(e.scrollLeft=g.left,e.scrollTop=g.top),g=null),M())},travelled:()=>F,destroy(){clearTimeout(w),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function nt(l,e,y){const p=l.getBoundingClientRect(),x=e.getBoundingClientRect(),u=p.left+y,k=p.left+l.clientWidth-y,i=p.top+y,n=p.top+l.clientHeight-y;x.leftk&&(l.scrollLeft+=Math.min(x.right-k,x.left-u)),x.topn&&(l.scrollTop+=Math.min(x.bottom-n,x.top-i))}function rt(l,e,y,p,x,u,k,i){const{layer:n,memo:f,measureFigure:d}=i;f.model!==e&&(f.model=e,f.least=void 0);const g=M=>{n.style.width=`${Math.max(f.least||M,Math.min(i.avail,i.row))}px`};n.style.width||(n.style.width=`${Math.min(i.avail,i.row)}px`);const h=n.style.transform;n.style.transform="none";const w=n.offsetWidth?n.getBoundingClientRect().width/n.offsetWidth:1,S=Math.abs(w-1)>1e-4?` scale(${1/w})`:"";n.style.transform=S||"none";const T=(l.querySelector(`.${y}-drawing`)??n).getBoundingClientRect(),q=T.left-Math.round(T.left),o=T.top-Math.round(T.top);(q||o)&&(n.style.transform=`translate(${-q/w}px, ${-o/w}px)${S}`);let s=d(l,e,y,p,x,u,f.least===void 0?void 0:k,g);if(s.dyn.layout==="stacked"&&f.least===void 0&&s.least!==void 0){const M=s.dyn,A=m=>{n.style.width=`${m}px`;const _=d(l,e,y,p,M,u);return _.dyn.layout==="drawn"?d(l,e,y,p,_.dyn,u):_},v=Math.max(s.least,Math.min(i.avail,i.row)),I=Math.max(i.row,v)*1.5;let z;for(let m=v+16;m<=I&&z===void 0;m+=16)A(m).dyn.layout==="drawn"&&(z=m);if(z!==void 0){for(let m=z-15;mi.contain&&(n.style.width=`${i.contain}px`,s=d(l,e,y,p,s.dyn,u,k)),n.style.transform=h,s}(function(l){"use strict";var e=l._,y=0;function p(i){return e.diagramKit.escapeHtml(String(i??""))}function x(i){return''+p(i)+""}function u(i,n){return parseFloat(getComputedStyle(i).getPropertyValue(n))||0}function k(i,n,f,d){var g=e.diagramKit,h=Object.assign({},n,{motion:"still"}),w=g.buildModel(h),S="dgv"+ ++y,T=g.figureKey("diagram",w),q=et(g.hintEntries(w)).map(function(r){return""+r.keys.map(x).join(" ")+" "+p(r.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",S+"-summary"),o.innerHTML='

'+p(w.title)+"

"+(n.source?'

'+p(n.source)+"

":"")+'

'+p(n.summary)+'

'+(T?'
'+g.toHtml(T)+"
":"")+'
',document.body.appendChild(o);var s=o.querySelector(".diagram-stage"),M=o.querySelector(".diagram-sizer"),A=o.querySelector(".diagram-layer"),v=A.firstChild,I=o.querySelector('[role="status"]'),z=o.querySelector(".diagram-level > span"),m=o.querySelector(".diagram-viewer-key"),_=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},W=null,K=!1,R=!1,D=function(r,E){E?r.setAttribute("aria-disabled","true"):r.removeAttribute("aria-disabled")},c=at({stage:s,sizer:M,layer:A,status:I,rest:u(s,"--_rest")||300,onChange:function(r){z.textContent=r.level+"%",D(L.out,r.listOpen||r.atMin),D(L.in,r.listOpen||r.atMax),D(L.fit,r.listOpen||r.atFit)}}),O={},C={layer:A,avail:0,row:1104,contain:480,memo:O,measureFigure:g.measureFigure,keys:tt,measure:function(r,E,Y,N,Z,P,X){return rt(r,E,Y,N,Z,P,X,C)},onMeasured:function(r,E){s.setAttribute("data-layout",r.dyn.layout||""),m&&(m.setAttribute("data-layout",r.dyn.layout||""),m.toggleAttribute("data-bare",!!r.dyn.bare)),R=!!r.dyn.bare,_.hidden=R,F(K||R),c.size(E.offsetWidth,E.offsetHeight)}};function B(){C.avail=Math.max(0,Math.floor(s.clientWidth-2*(parseFloat(getComputedStyle(M).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function F(r){r&&!W&&(W=document.createElement("div"),W.className="diagram-list diagram-viewer-list",W.innerHTML=g.figureList("diagram",w).map(function(E){return g.toHtml(E)}).join(""),s.appendChild(W)),r&&c.list(!0),W&&(W.hidden=!r),M.hidden=r,r||c.list(!1)}_.addEventListener("click",function(){K=!K,_.setAttribute("aria-expanded",String(K)),_.firstElementChild.textContent=K?"Hide the list":"View as list",F(K||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||c.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||c.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||c.fit()}),s.addEventListener("focusin",function(r){var E=r.target.closest&&r.target.closest(".diagram-node");E&&s.contains(E)&&nt(s,E,u(s,"--_clear")||16)}),l.openDialog(o,d),B(),g.draw(v,h,!1,C),setTimeout(function(){s.focus({preventScroll:!0})},0);var $=s.clientWidth,V=new ResizeObserver(function(){Math.abs(s.clientWidth-$)<.5||($=s.clientWidth,B(),v.__diagram&&v.__diagram.layout())});V.observe(s),o.addEventListener("transitionend",function(r){r.target===o&&r.propertyName==="transform"&&o.open&&v.__diagram&&v.__diagram.layout()}),i.setAttribute("data-viewing",""),f.animated&&f.settle(),o.addEventListener("close",function(){V.disconnect(),c.destroy(),v.__diagram&&v.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},u(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,n,f){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var g=d.querySelector(".diagram-expand");g&&g.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var w=d.querySelector(".diagram-toggle");w&&w.nextSibling?d.insertBefore(h,w.nextSibling):d.appendChild(h);var S=function(){k(i,n,f,h)};return h.addEventListener("click",S),{destroy:function(){h.removeEventListener("click",S),h.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 5d01946c..a96f5d74 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,2 +1,2 @@ (()=>{var fe=["top","right","bottom","left"],he=["main","plain","dashed"],pe=[2,3,4,5,6],rt=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),pt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function kt(t,e={}){const s=e.checks!==!1,r=[],o=d=>{r.push(d)},a=t.legend??{},l={};for(const d of["main","plain","dashed","focal","group"]){const m=rt(a[d]);m&&(l[d]=m)}const p=t.stepLabel,h=typeof p=="function"?d=>String(p(d)):typeof p=="string"?(d=>p.replace("{n}",String(d))):d=>`Step ${d}`,u=t.shapeLabels??{},g={terminal:rt(u.terminal)??"Start or end",step:rt(u.step)??"Step",decision:rt(u.decision)??"Decision"},c=t.heading===void 0?3:pe.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),y=(d,m)=>d==null?"plain":he.includes(d)?d:(o(`"${String(d)}" is not a kind of line (main, plain or dashed): ${m} is drawn plain`),"plain"),$=d=>{if(d!=null){if(fe.includes(d))return d;o(`"${String(d)}" is not a side (top, right, bottom or left): the derived side is used`)}},i=(d,m)=>typeof d=="number"&&Number.isInteger(d)&&d>=1?d:(o(`${m} is ${JSON.stringify(d)}, not a whole number from 1: it is placed at 1`),1),f=[],b=[];let O=[];const _=[],B=[],j=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(j)||o(`"${String(j)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),j==="architecture"||j==="flowchart"){for(const d of t.nodes??[]){const m=j==="flowchart"&&d.shape==="decision"?"decision":j==="flowchart"&&d.shape==="terminal"?"terminal":"box",S=String(d.id??""),E=i(d.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(d.name??""),kind:m==="decision"?void 0:rt(d.kind),detail:m==="decision"?void 0:rt(d.detail),mono:!!d.detailMono,focal:!!d.focal,col:i(d.col,`the column of ${S}`),row:E,row2:E,branch:!!d.branch,shape:m,group:j==="architecture"?rt(d.group):void 0,mark:j==="architecture"?ge(d.mark):void 0})}if(j==="architecture")for(const d of t.groups??[]){const m=String(d.id??"");_.push({id:m,label:String(d.label??""),members:f.filter(S=>S.group===m).map(S=>S.id)})}}else if(j==="data-flow"){O=(t.lanes??[]).map(m=>({id:String(m.id??""),label:String(m.label??"")}));const d=new Map(O.map((m,S)=>[m.id,S+1]));for(const m of t.nodes??[]){const S=String(m.id??""),E=String(m.lane??""),z=d.get(E);z===void 0&&o(`a node (${S}) names the lane "${E}", which is not in lanes`);const T=f.length+1;f.push({id:S,i:f.length,name:String(m.name??""),kind:h(T),detail:rt(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:i(m.col,`the column of ${S}`),row:z??1,row2:z??1,branch:!1,shape:"box",lane:z??1,laneLabel:O[(z??1)-1]?.label??E,step:T})}}else if(j==="sequence"){(t.participants??[]).forEach((m,S)=>{const E=String(m.name??"");f.push({id:String(m.id??""),i:S,name:E,kind:rt(m.kind),mono:!1,focal:!!m.focal,col:S+1,row:1,row2:1,branch:!1,shape:"participant",short:rt(m.short)??E})});let d=0;for(const m of t.steps??[])"band"in m?B.push({band:String(m.band??"")}):(d++,B.push({n:d,from:String(m.from??""),to:String(m.to??""),label:String(m.label??""),note:rt(m.note),kind:y(m.kind,`message ${d}`)}))}else if(j==="schema")for(const d of t.tables??[]){const m=String(d.name??""),[S,E]=Array.isArray(d.row)?d.row:[d.row,d.row],z=i(S,`the row of ${m}`),T=Math.max(z,i(E,`the last row of ${m}`)),G=d.more===void 0||d.more===null?void 0:Number.isInteger(d.more)&&d.more>0?d.more:(o(`${m}'s "more" is ${JSON.stringify(d.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:m,i:f.length,name:m,mono:!0,focal:!!d.focal,col:i(d.col,`the column of ${m}`),row:z,row2:T,branch:!1,shape:"table",more:G,columns:(d.columns??[]).map(N=>({name:String(N.name??""),type:rt(N.type),key:N.key==="PK"||N.key==="FK"?N.key:(N.key!==void 0&&N.key!==null&&o(`${m}.${String(N.name)}'s key is "${String(N.key)}", not PK or FK: it is left out`),void 0)}))})}const R=new Map;for(const d of f)d.id?R.has(d.id)&&o(`the id "${d.id}" is used twice`):o("a node has no id"),R.set(d.id,d);if(j==="schema")(t.tables??[]).forEach(d=>(d.columns??[]).forEach((m,S)=>{const E=rt(m.references);if(!E)return;const[z,T]=E.split("."),G=R.get(z??""),N=G?.columns?.findIndex(C=>C.name===T)??-1;if(!G||N<0){o(`${String(d.name)}.${String(m.name)} references ${E}, which is not a shown column`);return}const k=R.get(String(d.name??""));k.columns[S].ref={table:z,column:T,row:N},b.push({i:b.length,from:k.id,to:z,kind:"plain",fromRow:S,toRow:N,fk:!0})}));else if(j!=="sequence")for(const d of t.edges??[]){const m=String(d.from??""),S=String(d.to??"");if(!R.has(m)||!R.has(S)){o(`a line names ${R.has(m)?S:m}, which is not a node`);continue}const E=rt(d.label);E&&E.length>Ot&&o(`the label "${E}" is over ${Ot} characters: longer words belong in the node or the summary`),b.push({i:b.length,from:m,to:S,kind:y(d.kind,`the line from ${m} to ${S}`),label:E,fromSide:$(d.fromSide),toSide:$(d.toSide),flow:j!=="flowchart"&&d.flow===!0?!0:void 0})}else for(const d of B)"n"in d&&(!R.has(d.from)||!R.has(d.to))&&o(`message ${d.n} names ${R.has(d.from)?d.to:d.from}, which is not a participant`);if(s&&j!=="sequence"){const d=new Map;for(const m of f)for(let S=m.row;S<=m.row2;S++){const E=`${m.col}:${S}`;d.has(E)&&o(`${m.id} and ${d.get(E)} share the cell at column ${m.col}, row ${S}`),d.set(E,m.id)}}if(s){for(const m of _){const S=m.members.map(T=>R.get(T));if(!S.length)continue;const E={c1:Math.min(...S.map(T=>T.col)),c2:Math.max(...S.map(T=>T.col)),r1:Math.min(...S.map(T=>T.row)),r2:Math.max(...S.map(T=>T.row2))};for(const T of f)T.group!==m.id&&T.col>=E.c1&&T.col<=E.c2&&T.row>=E.r1&&T.row<=E.r2&&o(`${T.id} is inside the box of the group "${m.label}" but not a member`);const z=S.map(T=>T.i);Math.max(...z)-Math.min(...z)+1!==z.length&&o(`the members of the group "${m.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const m of f)m.group&&!_.some(S=>S.id===m.group)&&o(`${m.id} names the group "${m.group}", which is not in groups`);f.filter(m=>m.focal).length>1&&o("more than one node is focal: a diagram has one at most");const d=new Set(j==="sequence"?B.flatMap(m=>"n"in m?[m.kind]:[]):b.map(m=>m.kind));d.has("main")&&!l.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),d.has("dashed")&&!l.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(m=>m.focal)&&!l.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const Q=j==="architecture"||j==="data-flow",A=d=>Array.isArray(d)&&d.length>1?d.map(String):void 0,V=Q&&t.packet&&typeof t.packet=="object"?t.packet:void 0,v=V&&A(V.path),D={animated:t.motion==="animated",pulse:Q?A(t.pulse):void 0,packet:v?{path:v,repeat:V.repeat===!0,send:V.send}:void 0,run:j==="sequence"&&t.run===!0};if(s)for(const d of f){const m=d.mark?.says;if(!m?.length)continue;const S=[d.name,d.kind,d.detail].filter(Boolean).join(" ").toLowerCase();m.some(E=>S.includes(E.toLowerCase()))||o(`${d.id}'s mark stands for ${m.join(" or ")}, and none of its words say so`)}const L=Math.max(1,...f.map(d=>d.col)),x=j==="data-flow"?Math.max(1,O.length):Math.max(1,...f.map(d=>d.row2));return{type:j,title:String(t.title??""),heading:c,legend:l,nodes:f,byId:R,edges:b,groups:_,lanes:O,steps:B,cols:L,rows:x,shapeLabels:g,stepWord:h,warnings:r,motion:D,memo:new Map}}function ge(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=rt(e.onLight);if(n)return{onLight:n,onDark:rt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var It=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function wt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Ot=28,mt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function _t(t,e){return t.legend[e]}function me(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function ye(t,e){return wt(t,`sentence:${e.i}`,()=>be(t,e))}function be(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,r=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(mt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`)}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?me(t,e):e.kind;if(n.push(mt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(mt(e.detail)),e.group){const a=t.groups.find(l=>l.id===e.group);a&&n.push(`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${a.label})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${a.label})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(mt(t.legend.focal)),n.join(" ")}function $e(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function w(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var we={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>we[e]),xe=" br img input meta link hr path polygon polyline circle rect line ";function St(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return xe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>St(s,e)).join("")}`}var ve=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function gt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Me(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Ct(t){let e=0;for(const n of t.groups){const s=n.members.map(r=>t.byId.get(r).col);s.length&&(Math.min(...s)===1&&(e|=1),Math.max(...s)===t.cols&&(e|=2))}return(e&1)+(e>>1&1)}function Et(t){return t.type==="sequence"?t.nodes.length:t.cols}function Bt(t){return wt(t,"plan",()=>ke(t))}function ke(t){const e=t.nodes,n=i=>t.type==="data-flow"||!e[i].branch,s=t.edges.map(i=>{const f=t.byId.get(i.from).i,b=t.byId.get(i.to).i,_=e.slice(Math.min(f,b)+1,Math.max(f,b)).every(B=>!n(B.i));return b===f+1&&!(n(f)&&!n(b))?"down":b===f-1?"up":b>f&&n(f)&&!n(b)&&_?"trunk":b>f&&n(f)&&n(b)&&_?"rail":b>f?"end-down":"end-up"}),r=t.edges.map((i,f)=>({e:i,k:f})).filter(({k:i})=>s[i]==="end-down"||s[i]==="end-up"),o=i=>{const f=t.byId.get(i.from).i,b=t.byId.get(i.to).i;return[Math.min(f,b),Math.max(f,b)]},a=(i,f)=>{const[b,O]=o(i),[_,B]=o(f);return b{const f=t.byId.get(i.from).i,[b,O]=o(i);return!n(f)&&e.slice(b+1,O).every(_=>!n(_.i))&&r.every(_=>_.e===i||!a(_.e,i))}),p=r.length>0&&(t.type==="data-flow"||!l),h=i=>{const[f,b]=o(i);return b-f},u=t.edges.map(()=>0);let g=!1;const c=[];for(const i of[...r].sort((f,b)=>h(f.e)-h(b.e)||f.k-b.k)){let f=0;for(const b of c)a(b.e,i.e)&&(f=Math.max(f,u[b.k]+1));u[i.k]=f,f>1&&(g=!0),c.push(i)}const y=t.edges.map(()=>.5);for(const i of e){const f=r.filter(({e:_})=>_.from===i.id);if(f.length<2)continue;const b=f.filter(({k:_})=>s[_]==="end-down").sort((_,B)=>h(B.e)-h(_.e)||_.k-B.k);[...f.filter(({k:_})=>s[_]==="end-up").sort((_,B)=>h(_.e)-h(B.e)||B.k-_.k),...b].forEach(({k:_},B,j)=>{y[_]=j.length===2?B===0?1/3:2/3:(B+1)/(j.length+1)})}const $=ht();for(let i=1;i{const A=s[Q],V=t.byId.get(R.from).i,v=t.byId.get(R.to).i,D=v===i&&(A==="down"||A==="trunk"||A==="rail"||A==="end-down"),L=V===i&&v===i-1&&A==="up",x=v===i-1&&A==="end-up";D&&(A==="trunk"||A==="end-down")&&(B=!0),x&&(j=!0),(D||L||x)&&R.label&&(O++,_=Math.max(_,A==="trunk"?40:48))}),(O>1||B&&j)&&(_=64),$[f.id]=_}return{routes:s,gutter:p,lanes:u,exits:y,gaps:$,third:g}}var yt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function jt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return w("svg",{class:`${t}-swatch`,"data-kind":n,...yt(24,16)},e==="fk"?w("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,w("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?w("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):w("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function bt(t,e){return e==="decision"?w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Tt(t,e){return wt(e,`key:${t}`,()=>Ee(t,e))}var Se=Tt;function Ee(t,e){const n=[],s=(o,a,l={})=>n.push(w("li",{class:`${t}-entry`,...l},o,w("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),w("span",null,l)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(bt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(bt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(bt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(jt(t,o),a,{"data-line":""})}return e.type==="schema"&&e.edges.length&&(s(jt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(w("li",{class:`${t}-entry`,"data-when":"stacked"},w("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),w("span",null,"The table a foreign key references")))),e.nodes.some(o=>o.focal)&&e.legend.focal&&s(bt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(bt(t,"group"),e.legend.group),n.length?w("div",{class:`${t}-key`},w("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Ae(t,e){const n=e==="main"?6:6.5;return w("svg",{class:`${t}-arrow`,"data-kind":e,...yt(20,12)},w("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?w("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):w("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Le(t,e,n){if(n.shape==="decision")return[w("span",{class:`${t}-words`},w("span",{class:`${t}-name`},n.name))];const s=[];return e.type==="data-flow"?s.push(w("span",{class:`${t}-kind`},n.kind,w("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(w("span",{class:`${t}-kind`},n.kind)),s.push(w("span",{class:`${t}-name`},n.name)),n.detail&&s.push(w("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?vt(n.detail).flatMap((r,o)=>[o?" ":"",w("span",{class:`${t}-run`},r)]):n.detail)),s}function qe(t,e){return[w("span",{class:`${t}-th`},w("span",{class:`${t}-tname`},e.name)),w("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>w("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},w("span",{class:`${t}-keyseat`},n.key??""),w("span",{class:`${t}-cname`},n.name),n.ref?w("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?w("span",{class:`${t}-ctype`},n.type):null))),e.more?w("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Rt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=Me(e,s)||s.keep===n.id,a=gt(e,s),l=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&l.push(`--_lc:${n.col+1}`),e.type==="sequence"&&l.push(`--_c2:${n.col+1}`);const p=t.plan;if(p&&n.i>0){const c=pt(p.gaps,n.id)??32,y=pt(s.grow,n.id)??0;l.push(`--_gap:${y?`calc(${Rt(c)} + var(--basalt-space-4) * ${y})`:Rt(c)}`)}const h=pt(s.heights,n.id);h&&l.push(`--_h:${h}px`);const u=pt(s.words,n.id);u&&l.push(`--_ww:${u}px`);const g=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return w("div",{class:`${r}-node`,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:l.join(";"),role:o?"img":void 0,"aria-label":o?ye(e,n):void 0,tabindex:g},n.shape==="decision"?w("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},w("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?w("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${It(n.mark.onLight)};--_md:${It(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?qe(r,n):Le(r,e,n))}function Ie(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((a,l)=>w("div",{class:`${s}-lane`,style:`--_r:${l+1}`,"aria-hidden":"true"},w("span",{class:`${s}-lane-name`},a.label)))),e.type==="architecture")for(const a of e.groups){const l=a.members.map(c=>e.byId.get(c));if(!l.length)continue;const p=Math.min(...l.map(c=>c.col)),h=Math.max(...l.map(c=>c.col)),u=Math.min(...l.map(c=>c.row)),g=Math.max(...l.map(c=>c.row2));r.push(w("div",{class:`${s}-gbox`,"data-group":a.id,style:`--_c:${p};--_c2:${h+1};--_r:${u};--_r2:${g+1}`,"aria-hidden":"true"},w("span",{class:`${s}-glabel`},a.label)))}if(e.type==="sequence")return r.push(w("ul",{class:`${s}-cast`},e.nodes.map(a=>w("li",{class:`${s}-actor`},At(t,e,a,n))))),r.push(Oe(t,e)),r;let o=0;for(;ou.id===a.group):void 0;if(!l){r.push(At(t,e,a,n)),o++;continue}const p=[];for(;oAt(t,e,u,n))))}return r}function Oe(t,e){const{P:n}=t,s=[];let r=null;for(const o of e.steps){if("band"in o){r=null,s.push(w("p",{class:`${n}-band`},w("span",null,o.band)));continue}r||(r=w("ol",{class:`${n}-msgs`,start:o.n}),s.push(r));const a=e.byId.get(o.from),l=e.byId.get(o.to),p=a?.col??1,h=l?.col??1,u=p===h,g=u&&p===e.nodes.length,c=_t(e,o.kind);r.c.push(w("li",{class:`${n}-msg`,"data-kind":o.kind,"data-from":o.from,"data-to":o.to,"data-self":u?g?"start":"end":void 0,style:`--_a:${Math.min(p,h)};--_b:${Math.max(p,h)+1}`},w("span",{class:`${n}-said`},w("span",{class:`${n}-num`},String(o.n)),w("span",{class:`${n}-mlabel`},o.label)),w("span",{class:`${n}-route`},a?.short??o.from," ",Ae(n,o.kind),w("span",{class:t.hidden}," to ")," ",l?.short??o.to,c?` · ${c}`:""),o.note?w("span",{class:`${n}-note`},o.note):null))}return w("div",{class:`${n}-steps`},s)}function Ft(t,e){return wt(e,`list:${t}`,()=>Ce(t,e))}var _e=Ft;function Ce(t,e){const n=Math.min(6,e.heading+1),s=u=>w(`h${n}`,{class:`${t}-list-head`},u),r=u=>w("strong",null,u),o=u=>w("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,l=u=>{const g=_t(e,u);return g?` (${g})`:""},p=u=>u.focal&&e.legend.focal?` ${mt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=y=>w("li",null,r(y.name),y.kind?`, ${y.kind}`:"",y.detail?[". ",y.mono?o(y.detail):y.detail,/[.!?]$/.test(y.detail)?"":"."]:/[.!?]$/.test(y.kind??y.name)?"":".",p(y)),g=[s("Parts")],c=e.nodes.filter(y=>!y.group);c.length&&g.push(w("ul",{class:`${t}-list-items`},c.map(u)));for(const y of e.groups)g.push(w("p",{class:`${t}-list-group`},y.label)),g.push(w("ul",{class:`${t}-list-items`},y.members.map($=>u(e.byId.get($)))));return g.push(s("Connections")),g.push(w("ol",{class:`${t}-list-items`},e.edges.map(y=>w("li",null,r(a(y.from))," to ",r(a(y.to)),y.label?[": ",o(y.label)]:"",`${l(y.kind)}.`)))),g}if(e.type==="flowchart"){const u=g=>(e.byId.get(g)?.i??0)+1;return[w("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const c=e.edges.filter(i=>i.from===g.id),y=g.shape==="decision"?"Decision":g.shape==="terminal"?c.length?"Start":"End":"Step",$=!g.detail&&/[.!?]$/.test(g.name)?" ":". ";return w("li",null,r(g.name),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",`${$}${y}.`,p(g),c.length?w("ul",{class:`${t}-list-exits`},c.map(i=>w("li",null,i.label?`If ${i.label}: go to ${u(i.to)}, `:`Then: go to ${u(i.to)}, `,r(a(i.to)),l(i.kind)))):null)}))]}if(e.type==="data-flow")return[w("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const g=e.edges.filter(c=>c.from===u.id);return w("li",null,`${u.laneLabel}: `,r(u.name),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",p(u),g.length?[" Then ",...g.flatMap((c,y)=>[y?"; ":"",`to step ${e.byId.get(c.to).step}, `,r(a(c.to)),c.label?[": ",o(c.label)]:"",l(c.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),w("ul",{class:`${t}-list-items`},e.nodes.map(c=>w("li",null,r(c.name),c.kind?`, ${c.kind}`:"",".",p(c))))];u.push(s("Messages"));let g=null;for(const c of e.steps){if("band"in c){g=null,u.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},c.band));continue}g||(g=w("ol",{class:`${t}-list-items`,start:c.n}),u.push(g)),g.c.push(w("li",null,o(c.label),": ",r(a(c.from))," to ",r(a(c.to)),`${l(c.kind)}.`,c.note?` ${mt(c.note)}`:""))}return u}const h=[];for(const u of e.nodes)h.push(w(`h${n}`,{class:`${t}-list-group`},o(u.name),p(u))),h.push(w("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(g=>w("li",null,o(g.name),g.key==="PK"?", primary key":g.key==="FK"?", foreign key":"",g.ref?[", references ",o(`${g.ref.table}.${g.ref.column}`)]:g.type?`, ${g.type}`:"")),...u.more?[w("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return h}function Ht(t){return`Arrow keys move to the next or the previous ${t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step"}, in the author's order; Home and End go to the ends; Escape clears the trace.`}function zt(t){return[{keys:["←","→"],words:$e(t)},{keys:["Home","End"],words:"the ends"},{keys:["Esc"],words:"clear"}]}var Nt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Wt(t,e,n){const s=n.prefix,r=ve(n.base),o=t.type==="sequence"||t.type==="schema"?null:Bt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},l=e.layout==="drawn",p=gt(t,e),h=t.type==="sequence"||t.type==="schema"?l:!0,u=`h${t.heading}`,g=[`--_cols:${Et(t)}`];if(t.type==="architecture"&&t.groups.length||l&&e.pad){const c=t.type==="architecture"?t.groups.flatMap(i=>i.members.map(f=>t.byId.get(f))):[],y=(i,f,b)=>i?`var(--basalt-space-${f})`:b?`var(--basalt-space-${b})`:"0px",$=l&&e.pad?"3":void 0;g.push(`--_gpad:${y(c.some(i=>i.row===1),"8",$)} ${y(c.some(i=>i.col===t.cols),"4")} ${y(c.some(i=>i.row2===t.rows),"4",$)} ${y(c.some(i=>i.col===1),"4")}`)}return Nt(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),w("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Et(t),"data-reach":t.type==="architecture"?Ct(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},w("div",{class:`${s}-head`},w(u,{id:r.title,class:`${s}-title`},t.title),n.hasSource?w("p",{class:`${s}-source`},{slot:"source"}):null),w("div",{class:`${s}-drawing`,role:h?"group":void 0,"aria-roledescription":h?"diagram":void 0,"aria-labelledby":h?r.title:void 0,"aria-describedby":h?p?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":p?"":void 0},Ie(a,t,e),w("div",{class:`${s}-ink`,"aria-hidden":"true"}),w("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Tt(s,t),w("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),w("div",{class:`${s}-foot`},{slot:"toggle"}),w("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Ft(s,t)),w("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Ht(t)} ${n.viewer}`:Ht(t)),w("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Be(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4)}}var xt=(t,e)=>t==="main"?e.line:e.hair,ct=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},dt=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Dt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function it(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,l=(s+o)/2,p=(r+a)/2,h=(o-s)/2,u=(a-r)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const $=n,i=u*Math.max(0,1-Math.abs($-l)/h);return{x:$,y:e==="top"?p-i:p+i}}const c=n,y=h*Math.max(0,1-Math.abs(c-p)/u);return{x:e==="left"?l-y:l+y,y:c}}if(t.shape==="terminal"){const c=Math.min(h,u);if(g){const f=n,b=Math.min(Math.max(f,s+c),o-c),O=f-b,_=Math.abs(O)>=c?0:Math.sqrt(c*c-O*O);return{x:f,y:Math.abs(O)<1e-6?e==="top"?r:a:e==="top"?p-_:p+_}}const y=n,$=y-p,i=Math.abs($)>=c?0:Math.sqrt(c*c-$*$);return{x:e==="left"?s+c-i:o-c+i,y}}return g?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function je(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,l=(s+o)/2,p=(r+a)/2,h=(o-s)/2,u=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-l)/h+Math.abs(t.y-p)/u<1-n/Math.min(h,u);if(e.shape==="terminal"){const g=Math.min(h,u),c=Math.min(Math.max(t.x,s+g),o-g);return Math.hypot(t.x-c,t.y-p)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Fe(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var vt=t=>t?t.split(/\s+/).filter(Boolean):[];function He(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const p of t.nodes){if(p.shape==="table"){for(const y of p.columns??[]){const $=y.ref?`→ ${y.ref.table}`:y.type??"",i=s("6")+n(y.name,"mono")+($?s("3")+n($,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(i))}o=Math.max(o,Math.ceil(n(p.name,"table")+2*s("3")+2*e.hair));continue}const h=p.shape==="terminal"?2*s("5"):2*s("3"),u=p.mark&&!Re()?s("6"):0;let g=0;for(const y of vt(p.name))g=Math.max(g,n(y,p.shape==="decision"?"name-500":"name")+(p.kind?0:u));if(t.type!=="data-flow")for(const y of vt(p.kind))g=Math.max(g,n(y,"mono")+u);for(const y of vt(p.detail))g=Math.max(g,n(y,p.mono?"mono":"sans"));const c=p.shape==="decision"?g/.62:g+h+2*e.hair;r=Math.max(r,Math.ceil(c))}const a=Et(t);let l;return t.type==="data-flow"?l=e.lane+a*(r+s("12")):t.type==="schema"?l=a*o+(a-1)*s("12")+(Nt(t)?s("5"):0):t.type==="sequence"?l=a*r+(a-1)*s("5"):l=a*r+(a-1)*s("16")+Ct(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,l)}}function Kt(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Lt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Vt(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const p=r[r.length-2];if(Math.abs(p.x-l.x)<.01&&Math.abs(l.x-a.x)<.01||Math.abs(p.y-l.y)<.01&&Math.abs(l.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ft=t=>t.slice(1).map((e,n)=>[t[n],e]);function Mt(t,e,n){const s=[];for(let o=0;oMath.min(i.x,f.x)+.75&&_Math.min(b.y,O.y)+.75&&Br.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const l=[];let p=o;for(const h of r)l.push([p,p+h]),p+=h+a;return l};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var Y=t=>t==="left"||t==="right",Zt={top:"bottom",bottom:"top",left:"right",right:"left"};function Ne(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function We(t,e,n){const s=[];t.edges.forEach((o,a)=>{const l=t.byId.get(o.from),p=t.byId.get(o.to),[h,u]=e[a],g=l.row===p.row&&Y(h)&&Y(u)&&h===Zt[u]||l.col===p.col&&!Y(h)&&!Y(u)&&h===Zt[u];s.push({edge:a,end:"from",node:l,side:h,far:p,straight:g,f:.5},{edge:a,end:"to",node:p,side:u,far:l,straight:g,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const l=i=>Y(i.side)?i.far.row-i.node.row:i.far.col-i.node.col,p=a.filter(i=>i.straight),h=a.filter(i=>!i.straight);if(h.sort((i,f)=>l(i)-l(f)||(Y(i.side)?i.far.col-f.far.col:i.far.row-f.far.row)*(l(i)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!p.length){h.length===2?(h[0].f=.25,h[1].f=.75):h.length===3?(h[0].f=.25,h[1].f=.5,h[2].f=.75):h.length>3&&h.forEach((i,f)=>{i.f=(f+1)/(h.length+1)});continue}const u=new Map;for(const i of p)u.has(i.far.id)||u.set(i.far.id,[]),u.get(i.far.id).push(i);for(const i of u.values())i.length>1&&i.sort((f,b)=>f.edge-b.edge).forEach((f,b)=>{f.f=i.length===2?b===0?.25:.75:(b+1)/(i.length+1)});const g=Math.min(...p.map(i=>i.f)),c=Math.max(...p.map(i=>i.f)),y=h.filter(i=>l(i)<0),$=h.filter(i=>l(i)>=0);y.forEach((i,f)=>{i.f=g*(f+1)/(y.length+1)}),$.forEach((i,f)=>{i.f=c+(1-c)*(f+1)/($.length+1)})}return s}function Jt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return Y(e)?it(t,e,r+(a-r)*n):it(t,e,s+(o-s)*n)}function Ut(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ct(o,n),shape:a.shape,i:a.i})}),r}function Xt(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var Yt=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Qt(t,e,n,s){const r=(o,a)=>{const l=o+a-Math.floor(o+a);return l<.005||l>.995?[0]:l<=.5?[-l,1-l]:[1-l,-l]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const l={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(l))return l}return t}function De(t,e,n,s,r,o,a,l,p){const h=a.space,u=[],g=[],c=[],y=[],$=h("1"),i=e.filter(f=>t.edges[f.i]?.label).sort((f,b)=>+(t.edges[b.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-b.i);for(const f of i){const b=t.edges[f.i].label,O=l(b,"label"),_=16,B=f.pts.length-2,j=[];ft(f.pts).forEach(([v,D],L)=>{const x=Math.abs(v.y-D.y)<.01,d=x?v.x:v.y;let m=x?D.x:D.y;const S=Math.sign(m-d)||1;L===B&&(m-=S*a.head);let E=[[d,m]];for(const G of r)for(const N of x?[G.l,G.r]:[G.t,G.b]){const k=x?v.y:v.x;(x?k>G.t&&kG.l&&kN>Math.min(q,M)+1&&N{const k=(G+N)/2,C=x?{x:k,y:v.y}:{x:v.x,y:k};return!r.some(q=>C.x>q.l&&C.xq.t&&C.y1&&z(G,N)?1:0})}),j.sort((v,D)=>D.pri-v.pri||D.len-v.len);let R=null,Q=!1;const A=(v,D=!0)=>{const L=Dt(v,$);return D&&(v.lo.r||v.to.b)||n.some(x=>Gt(L,x))||u.some(x=>dt(L,x))||s.heads.some(x=>dt(L,x))||s.rects.some(x=>dt(L,x))?!1:!e.some(x=>x.i!==f.i&&ft(x.pts).some(([d,m])=>dt(L,Yt(d,m,x.width))))};for(const v of j){for(const D of[1/2,1/3,2/3]){const L=v.p+(v.q-v.p)*D,x=[],d=h("2")+f.width/2;if(v.horiz?(v.len>=O+2*h("1")+h("3-5")&&x.push({box:{l:L-O/2-h("1"),r:L+O/2+h("1"),t:v.c-_/2,b:v.c+_/2},on:!0}),x.push({box:{l:L-O/2,r:L+O/2,t:v.c-d-_,b:v.c-d},on:!1}),x.push({box:{l:L-O/2,r:L+O/2,t:v.c+d,b:v.c+d+_},on:!1})):(v.len>=_+h("3")&&x.push({box:{l:v.c-O/2-h("1"),r:v.c+O/2+h("1"),t:L-_/2,b:L+_/2},on:!0}),x.push({box:{l:v.c+d,r:v.c+d+O,t:L-_/2,b:L+_/2},on:!1}),x.push({box:{l:v.c-d-O,r:v.c-d,t:L-_/2,b:L+_/2},on:!1})),R=x.find(m=>A(m.box))??null,R)break;!Q&&x.some(m=>A(m.box,!1))&&(Q=!0)}if(R)break}if(!R){c.push(f.i),Q&&y.push(f.i);continue}const V=Qt(R.box,p.ox,p.oy,v=>A(v));u.push(V),g.push({i:f.i,text:b,box:V,on:R.on})}return{labels:g,unseated:c,bounded:y}}function Pt(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const l=ct(a,e);o.push(l),r.push({l:l.l,r:l.r,t:l.t,b:l.t+1},{l:l.l,r:l.r,t:l.b-1,b:l.b},{l:l.l,r:l.l+1,t:l.t,b:l.b},{l:l.r-1,r:l.r,t:l.t,b:l.b});const p=a.querySelector(`:scope > .${n}-glabel`);p&&p.getClientRects().length&&r.push(ct(p,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,l)=>{if(!a.getClientRects().length)return;const p=ct(a,e);l>0&&r.push({l:p.l,r:p.r,t:p.t-s/2-.5,b:p.t-s/2+.5});const h=a.querySelector(`.${n}-lane-name`);h&&r.push(ct(h,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function Ge(t,e){const{m:s,tk:r,P:o,drawing:a,origin:l,warn:p}=t,h=r.space,u=Ut(s,a,l,o),g=[...u.values()],c=ze(a),y=l.left-Math.floor(l.left),$=l.top-Math.floor(l.top),i=Kt(y,$),f=a.clientWidth,b=a.clientHeight,O=k=>s.type==="data-flow"?k.col+1:k.col,_=parseFloat(getComputedStyle(a).rowGap)||0,B={w:f,h:b,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:y,oy:$};if(s.type==="sequence")return Ve(t,B,i);let j,R=[];s.type==="schema"?j=s.edges.map(k=>{const C=s.byId.get(k.from),q=s.byId.get(k.to);if(C.col===q.col){const M=C.col===s.cols&&s.cols>1?"left":"right";return[M,M]}return q.col>C.col?["right","left"]:["left","right"]}):(j=s.edges.map(k=>{const C=s.byId.get(k.from),q=s.byId.get(k.to),[M,I]=Ne(C,q);return[k.fromSide??M,k.toSide??I]}),R=We(s,j,p||(()=>{})));const Q=(k,C)=>{const q=a.querySelector(`.${o}-node[data-node="${CSS.escape(k)}"] .${o}-row[data-row="${C}"]`);if(!q)return 0;const M=ct(q,l);return(M.t+M.b)/2},A=s.edges.map((k,C)=>{const[q,M]=j[C],I=u.get(k.from),F=u.get(k.to),Z=xt(k.kind,r);if(k.fk){const J=Q(k.from,k.fromRow),et=Q(k.to,k.toRow),U=i.y(J,Z),nt=i.y(et,Z);return{p1:{x:q==="right"?I.rect.r:I.rect.l,y:U},p2:{x:M==="right"?F.rect.r:F.rect.l,y:nt},r1:J,r2:Math.abs(U-nt)<.01?J:et}}const P=R.find(J=>J.edge===C&&J.end==="from").f,X=R.find(J=>J.edge===C&&J.end==="to").f;let W=Jt(I,q,P),K=Jt(F,M,X);const ot=Y(q)?W.y:W.x;let tt=Y(M)?K.y:K.x;return Y(q)?W={...W,y:i.y(W.y,Z)}:W={...W,x:i.x(W.x,Z)},Y(M)?K={...K,y:i.y(K.y,Z)}:K={...K,x:i.x(K.x,Z)},Y(q)&&Y(M)&&Math.abs(W.y-K.y)<1.01&&(K={...K,y:W.y},tt=ot),!Y(q)&&!Y(M)&&Math.abs(W.x-K.x)<1.01&&(K={...K,x:W.x},tt=ot),W=Y(q)?it(I,q,W.y):it(I,q,W.x),K=Y(M)?it(F,M,K.y):it(F,M,K.x),{p1:W,p2:K,r1:ot,r2:tt}}),V=new Set;s.type==="schema"&&s.edges.forEach((k,C)=>{Math.abs(s.byId.get(k.from).col-s.byId.get(k.to).col)>1&&V.add(C)});const v=new Map,D=new Set;s.edges.forEach((k,C)=>{if(V.has(C))return;const[q,M]=j[C],{p1:I,p2:F}=A[C],Z=s.byId.get(k.from),P=s.byId.get(k.to);let X=null,W=null,K=!1;if(q===M){if(Y(q)){const J=q==="right"?Math.max(O(Z),O(P)):Math.min(O(Z),O(P))-1,et=c.cols[J-1],U=c.cols[J];et&&U&&(X=`c${J}`,W=[et[1],U[0]],K=!0)}else{const J=q==="bottom"?Math.max(Z.row2,P.row2):Math.min(Z.row,P.row)-1,et=c.rows[J-1],U=c.rows[J];et&&U&&(X=`r${J}`,W=[et[1],U[0]],K=!1)}X&&D.add(C)}else if(Y(q)&&Y(M)&&Math.abs(I.y-F.y)>.5){const J=O(P),et=M==="left",U=c.cols[(et?J-1:J)-1],nt=c.cols[(et?J:J+1)-1];U&&nt&&(X=`c${et?J-1:J}`,W=[U[1],nt[0]],K=!0)}else if(!Y(q)&&!Y(M)&&Math.abs(I.x-F.x)>.5){const et=M==="top"?P.row-1:P.row2,U=c.rows[et-1],nt=c.rows[et];U&&nt&&(X=`r${et}`,W=[U[1],nt[0]],K=!1)}if(!X||!W)return;v.has(X)||v.set(X,{span:W,vertical:K,members:new Map});const ot=`${k.to}.${M}.${Math.round(K?F.y:F.x)}`,tt=v.get(X);tt.members.has(ot)||tt.members.set(ot,[]),tt.members.get(ot).push(C)});const L=new Map,x=k=>{const[C,q]=j[k],{p1:M,p2:I}=A[k];if(Y(C)&&Y(q)){if(C===q){const Z=L.get(k)??(C==="right"?Math.max(M.x,I.x)+h("4"):Math.min(M.x,I.x)-h("4"));return[M,{x:Z,y:M.y},{x:Z,y:I.y},I]}if(Math.abs(M.y-I.y)<=.5)return[M,{x:I.x,y:M.y}];const F=L.get(k)??(M.x+I.x)/2;return[M,{x:F,y:M.y},{x:F,y:I.y},I]}if(!Y(C)&&!Y(q)){if(C===q){const Z=L.get(k)??(C==="bottom"?Math.max(M.y,I.y)+h("4"):Math.min(M.y,I.y)-h("4"));return[M,{x:M.x,y:Z},{x:I.x,y:Z},I]}if(Math.abs(M.x-I.x)<=.5)return[M,{x:M.x,y:I.y}];const F=L.get(k)??(M.y+I.y)/2;return[M,{x:M.x,y:F},{x:I.x,y:F},I]}return Y(C)?[M,{x:I.x,y:M.y},I]:[M,{x:M.x,y:I.y},I]},d=k=>{const C=s.edges[k],q=xt(C.kind,r),M=x(k),I=Vt(M,q,i);let F;return M.length===I.length&&(F=ft(M).map(([Z,P])=>Math.abs(Z.y-P.y)<.75?(Z.y+P.y)/2:(Z.x+P.x)/2),F[0]=A[k].r1,F.length>1&&(F[F.length-1]=A[k].r2)),{i:k,from:C.from,to:C.to,kind:C.kind,pts:I,tip:I[I.length-1],dir:Lt(I),dot:C.fk?I[0]:void 0,width:q,axes:F}},m=()=>s.edges.flatMap((k,C)=>V.has(C)?[]:[d(C)]);let S=null;const E=k=>{S??(S=m());const C=S.map(q=>k.has(q.i)?d(q.i):q);return{lines:C,score:Ke(C,k)*1e5+Mt(C,void 0,k).length*1e3+qt(C.filter(q=>k.has(q.i)),g,s).length}},z=(k,C)=>{const q=k.flatMap(M=>{const{p1:I,p2:F}=A[M];return C?[I.y,F.y]:[I.x,F.x]});return[Math.min(...q),Math.max(...q)]};for(const[,k]of v){const C=[...k.members.values()].map(M=>({members:M,run:z(M,k.vertical)})).sort((M,I)=>M.run[0]-I.run[0]),q=[];for(const M of C){const I=q[q.length-1];I&&I.some(F=>F.run[0]D.has(ot)))continue;const I=M.map(ot=>ot.members),F=I.length,Z=(k.span[1]-k.span[0])/(F+1);ZJ.forEach(U=>L.set(U,k.span[0]+Z*(et+1))));const tt=E(P);tt.scoreot.forEach(J=>L.set(J,k.span[0]+Z*(tt+1)))),S=K}}B.lines=m();for(const k of V)p?.(`${s.edges[k].from} to ${s.edges[k].to} is two columns apart, so its line is not drawn; its row still writes the target`);B.crossings=Mt(B.lines),B.through=qt(B.lines,g,s),B.outside=ne(B.lines,f,b,r);const{obstacles:T,groups:G}=Pt(a,l,o,_);T.heads=B.lines.map(k=>Xt(k,r));const N=De(s,B.lines,g,T,G,{l:0,t:0,r:f,b},r,e,{ox:y,oy:$});return B.labels=N.labels,B.unseated=N.unseated,B.bounded=N.bounded,B.overlaps=[...new Set(te(B.lines,null).flat())],B}function Ke(t,e){return te(t,e).length}function te(t,e){const n=[];for(let s=0;s=l)continue;const[f,b]=c?[p.x,h.x]:[p.y,h.y],[O,_]=c?[u.x,g.x]:[u.y,g.y];Math.min(Math.max(f,b),Math.max(O,_))-Math.max(Math.min(f,b),Math.min(O,_))>1&&n.push([o.i,a.i])}}return n}function*ee(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const p=l===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-p<-.5||a.x+p>e+.5||a.y-p<-.5||a.y+p>n+.5})&&r.push(o.i);return r}function qt(t,e,n){const s=[];for(const r of t){const o=ft(r.pts);e.some(a=>o.some(([l,p])=>Te(l,p,a)))&&s.push(r.i)}return s}function Ve(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:l}=t,p=r.space,h=new Map;a.querySelectorAll(`.${o}-node`).forEach($=>h.set($.dataset.node,ct($,l)));const u=a.querySelector(`.${o}-steps`),g=u?ct(u,l).b:e.h,c=$=>{const i=h.get($);return i?n.x((i.l+i.r)/2,r.hair):0};for(const $ of s.nodes){const i=h.get($.id);i&&e.lifelines.push({x:c($.id),y1:i.b,y2:g})}const y=$=>h.get($.id);return a.querySelectorAll(`.${o}-msg`).forEach($=>{const i=$.dataset.from,f=$.dataset.to,b=$.dataset.kind??"plain",O=xt(b,r),_=ct($,l),B=n.y((_.t+_.b)/2,O),j=Number($.querySelector(`.${o}-num`)?.textContent??0),R=c(i),Q=c(f);let A;if(i===f){const m=$.dataset.self==="start"?-p("6"):p("6"),S=n.y(B-p("2"),O),E=n.y(B+p("2"),O);A=[{x:R,y:S},{x:n.x(R+m,O),y:S},{x:n.x(R+m,O),y:E},{x:R,y:E}]}else A=[{x:R,y:B},{x:Q,y:B}];e.lines.push({i:j,from:i,to:f,kind:b,pts:A,tip:A[A.length-1],dir:Lt(A),width:O});const V=$.querySelector(`.${o}-said`),v=$.querySelector(`.${o}-note`),D=s.byId.get(i),L=s.byId.get(f);if(!D||!L)return;const x=i===f?(()=>{const m=s.nodes[D.i+($.dataset.self==="start"?-1:1)],S=m?c(m.id):$.dataset.self==="start"?0:e.w;return Math.abs(S-R)-p("6")-p("2-5")-p("2")})():Math.abs(Q-R)-2*p("2");Math.max(V?V.getBoundingClientRect().width:0,v?v.getBoundingClientRect().width:0)>x+.5&&e.unseated.push(j)}),e}function oe(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:l,origin:p}=t,h=o.space,u=Ut(r,l,p,a),g=[...u.values()],c=p.left-Math.floor(p.left),y=p.top-Math.floor(p.top),$=Kt(c,y),i=l.clientWidth,f=l.clientHeight,b={w:i,h:f,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:y},O=ht();if(r.type==="sequence"||r.type==="schema")return{geo:b,grow:O};const _=i-(parseFloat(getComputedStyle(l).paddingRight)||0),B=(x,d,m)=>{const S=[x];for(let E=1;E<=(pt(s,d)??0);E++)S.push({...x,t:x.t+m*h("4")*E,b:x.b+m*h("4")*E});return S},j=new Map;l.querySelectorAll(`.${a}-node`).forEach(x=>{const d=x.parentElement,m=ct(d,p),S=getComputedStyle(d);j.set(x.dataset.node,m.r-(parseFloat(S.paddingRight)||0)-(parseFloat(S.borderRightWidth)||0))});const R=r.nodes,Q=x=>u.get(R[x].id),A=[],V=x=>xt(r.edges[x].kind,o);r.edges.forEach((x,d)=>{const m=n.routes[d],S=u.get(x.from),E=u.get(x.to),z=V(d);let T=[];const G=x.label,N=G?e(G,"label"):0,k=16,C=h("4");if(m==="down"||m==="up"){const M=Math.max(S.rect.l,E.rect.l),I=Math.min(S.rect.r,E.rect.r),F=r.edges.map((W,K)=>({o:W,j:K})).filter(({o:W,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(W.from===x.from&&W.to===x.to||W.from===x.to&&W.to===x.from)),Z=F.findIndex(W=>W.j===d),P=F.length<2?.5:F.length===2?Z===0?.25:.75:(Z+1)/(F.length+1),X=$.x(M+(I-M)*P,z);if(T=m==="down"?[it(S,"bottom",X),it(E,"top",X)]:[it(S,"top",X),it(E,"bottom",X)],G){let W=Math.min(T[0].y,T[1].y),K=Math.max(T[0].y,T[1].y);m==="down"?K-=o.head:W+=o.head;const ot=[...l.querySelectorAll(`.${a}-group`)].map(U=>ct(U,p));let tt=[[W,K]];for(const U of ot)for(const nt of[U.t,U.b])tt=tt.flatMap(([at,H])=>nt>at+1&&ntot.some(at=>(U+nt)/2>at.t&&(U+nt)/2at.l&&X1){const U=tt.filter(([at,H])=>!J(at,H));[W,K]=(U.length?U:tt).reduce((at,H)=>H[1]-H[0]>at[1]-at[0]?H:at)}const et=[1/2,1/3,2/3].map(U=>{const nt=W+(K-W)*U;return{l:X-N/2-h("1"),r:X+N/2+h("1"),t:nt-k/2,b:nt+k/2}});A.push({k:d,cands:et,on:!0,card:m==="down"?x.to:x.from})}}else if(m==="trunk"||m==="rail"){const M=$.x(Math.max(S.rect.l,m==="rail"?E.rect.l:S.rect.l)+h(m==="trunk"?"8":"3"),z),I=it(S,"bottom",M);if(m==="rail"){if(T=[I,it(E,"top",M)],G){const F=E.rect.t-h("6");A.push({k:d,cands:B({l:M+h("2-5"),r:M+h("2-5")+N,t:F-k/2,b:F+k/2},x.to,-1),on:!1,card:x.to})}}else{const F=$.x(E.rect.l+h("6"),z),Z=$.y(E.rect.t-C,z);T=[I,{x:M,y:Z},{x:F,y:Z},it(E,"top",F)],G&&A.push({k:d,cands:B({l:F+h("2-5"),r:F+h("2-5")+N,t:Z-k/2,b:Z+k/2},x.to,-1),on:!1,card:x.to})}}else{const M=Math.min(j.get(x.from)??i,j.get(x.to)??i),I=$.x(n.gutter?_+(n.lanes[d]?2*h("3-5"):h("3-5")):M-h("2-5"),z),F=$.y(S.rect.t+(S.rect.b-S.rect.t)*n.exits[d],z),Z=it(S,"right",F),P=$.x(E.rect.r-h("6"),z),X=m==="end-down",W=$.y(X?E.rect.t-C:E.rect.b+C,z);T=[Z,{x:I,y:Z.y},{x:I,y:W},{x:P,y:W},it(E,X?"top":"bottom",P)];const K=X?x.to:R[E.i+1]?.id??x.to;G&&A.push({k:d,cands:B({l:P-h("2-5")-N,r:P-h("2-5"),t:W-k/2,b:W+k/2},K,X?-1:1),on:!1,card:K})}const q=Vt(T,z,$);b.lines.push({i:d,from:x.from,to:x.to,kind:x.kind,pts:q,tip:q[q.length-1],dir:Lt(q),width:z})}),b.crossings=Mt(b.lines),b.through=qt(b.lines,g,r),b.outside=ne(b.lines,i,f,o);const{obstacles:v}=Pt(l,p,a,0);v.heads=b.lines.map(x=>Xt(x,o));const D=[],L={l:0,t:0,r:i,b:f};for(const x of A){const d=E=>{const z=Dt(E,h("1"));return E.lL.r+.5||E.tL.b+.5||g.some(T=>Gt(z,T))||D.some(T=>dt(z,T))||v.heads.some(T=>dt(z,T))||v.rects.some(T=>dt(z,T))||b.lines.some(T=>T.i!==x.k&&ft(T.pts).some(([G,N])=>dt(z,Yt(G,N,T.width))))},m=x.cands.find(E=>!d(E));m||(O[x.card]=(O[x.card]??0)+1,b.unseated.push(x.k));const S=m?Qt(m,c,y,E=>!d(E)):x.cands[0];D.push(S),b.labels.push({i:x.k,text:r.edges[x.k].label,box:S,on:x.on})}return{geo:b,grow:O}}function Ze(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...B})),g=u[u.length-1];g.x-=o.x*h,g.y-=o.y*h;const c=e.tip.x-o.x*l,y=e.tip.y-o.y*l,$=-o.y*p,i=o.x*p,f=B=>Math.round(B*100)/100,b=lt(e.kind),O=a?``:``,_=e.dot?``:"";return`${O}${_}`}function se(t,e,n,s){const r=new Map,o=new Map;for(const l of e.crossings)o.has(l.under)||o.set(l.under,[]),o.get(l.under).push(l);let a="";for(const[l,p]of o){const h=`${s}-cut-${l}`;r.set(l,h);const u=p.map(g=>{const c=e.lines[g.top],y=e.lines[g.under],$=c.width/2+n.cut,i=y.width/2+1;return g.underVertical?``:``}).join("");a+=`${u}`}return{defs:a,ids:r}}function ae(t,e,n,s){const{defs:r,ids:o}=se(t,e,n,s),a=e.lifelines.map(u=>``).join(""),l=e.lines.map((u,g)=>Ue(t,u,n,o.get(g)??null,u.from===u.to?n.radiusXs:n.radius)).join(""),p=`${r?`${r}`:""}${a}${l}`,h=e.labels.map(u=>`${lt(u.text)}`).join("");return p+h}function re(t,e,n,s,r,o,a,l){const h=t.querySelector(`.${n}-drawing`);if(!h||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const u=Be(t),g=Fe(h,n),c=He(e,u,g);l?.(c.least);const y=t.clientWidth,$=(()=>{const v=document.activeElement;return v&&h.contains(v)&&v.dataset.node?v.dataset.node:void 0})(),i=v=>gt(e,v)?{...v,stop:v.stop&&e.byId.has(v.stop)?v.stop:e.nodes[0]?.id,keep:void 0}:{...v,stop:v.stop??e.nodes[0]?.id,keep:$&&v.layout!=="drawn"?$:void 0};let f=!1;const b=v=>{if(f=!1,e.type!=="flowchart")return v;o({...v,heights:void 0,words:void 0});const D=ht(),L=ht();return h.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const d=x.querySelector(`.${n}-words`);if(!d)return;const m=x.getBoundingClientRect(),S=T=>{const G={w:T.width+2*u.space("2-5"),h:T.height+2*u.space("2")},N=1-G.w/m.width,k=N>.05?G.h/2/N:G.h*10;return Math.max(u.space("16"),Math.ceil(m.width/5),Math.ceil(2*k))},E=d.getBoundingClientRect();let z=S(E);if(z>m.width){const T=C=>(x.style.setProperty("--_ww",`${C}px`),d.getBoundingClientRect()),G=Math.floor(x.clientWidth-2*u.space("2-5"));let N=Math.ceil(E.width),k=E.height;for(;N1;){const F=C+q>>1;T(F).heightm.width&&(f=!0)}),{...v,heights:D,words:Object.keys(L).length?L:void 0}},O=()=>({m:e,tk:u,P:n,drawing:h,origin:h.getBoundingClientRect(),warn:a}),_=r.autoOpen?{open:!1,autoOpen:void 0}:{},B=(v,D)=>D.map(L=>$t(e,v.lines.find(x=>x.i===L))).join(", ");if(y>=c.least){const v=d=>{let m=i({...r,..._,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:d||void 0});return m=b(m),o(m),{dd:m,g:Ge(O(),g)}};let{dd:D,g:L}=v(!1);const x=d=>d.through.length>0||d.outside.length>0||(d.overlaps?.length??0)>0||f;if(!x(L)&&L.unseated.length&&L.unseated.every(d=>L.bounded?.includes(d))){const d=v(!0);!x(d.g)&&!d.g.unseated.length&&({dd:D,g:L}=d)}if(!x(L)&&!L.unseated.length)return L.crossings.length&&a?.(`${L.crossings.length} crossing${L.crossings.length===1?"":"s"} in the drawn layout: ${L.crossings.map(d=>`${$t(e,L.lines[d.top])} over ${$t(e,L.lines[d.under])}`).join("; ")}`),{dyn:D,geo:L,ink:ae(n,L,u,s),tokens:u,least:c.least};f&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: a decision would be taller than it is wide`),L.through.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.through)} would pass through a node`),L.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.overlaps)} would lie on one another`),L.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.outside)} would leave the drawing`),L.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: no clean seat for ${L.unseated.map(d=>e.type==="sequence"?`message ${d}`:`"${e.edges[d]?.label}"`).join(", ")}`)}let j=i({...r,..._,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(j=b(j),o(j),e.type==="sequence"||e.type==="schema")return{dyn:j,geo:null,ink:"",tokens:u,least:c.least};const R=Bt(e);let Q=oe(O(),g,R,j.grow);for(let v=0;v<6&&Object.keys(Q.grow).length;v++){const D=ht(j.grow);for(const[L,x]of Object.entries(Q.grow))D[L]=(pt(D,L)??0)+x;j={...j,grow:D},o(j),Q=oe(O(),g,R,D)}const A=Q.geo;if(A.unseated.length>0||A.through.length>0||A.outside.length>0||R.third){A.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(A.unseated)].map(L=>`"${e.edges[L]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),A.through.length&&a?.(`in the stacked drawing ${B(A,A.through)} would pass through a node, so its lines are not drawn`),A.outside.length&&a?.(`in the stacked drawing ${B(A,A.outside)} would leave the drawing, so its lines are not drawn`),R.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const v={...A,lines:[],labels:[],crossings:[]};return{dyn:i({...j,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:v,ink:"",tokens:u,least:c.least}}return A.crossings.length&&a?.(`${A.crossings.length} crossing${A.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${A.crossings.map(v=>`${$t(e,A.lines[v.top])} over ${$t(e,A.lines[v.under])}`).join("; ")}`),{dyn:j,geo:A,ink:ae(n,A,u,s),tokens:u,least:c.least}}function $t(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Xe(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const i of n?.lines??[])i.from===o&&a.add(i.to),i.to===o&&a.add(i.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(i=>i.toggleAttribute("data-near",a.has(i.dataset.node))),!n||!s)return;const l=i=>!!o&&(i.from===o||i.to===o),p=t.querySelector(`.${e}-edges`),h=new Map;t.querySelectorAll(`.${e}-edge`).forEach(i=>h.set(i.getAttribute("data-edge"),i));for(const i of n.lines){const f=h.get(String(i.i));f&&(f.toggleAttribute("data-lit",l(i)),f.toggleAttribute("data-dim",!!o&&!l(i)))}if(t.querySelectorAll(`.${e}-label`).forEach(i=>{const f=n.lines.find(b=>String(b.i)===i.dataset.edge);i.toggleAttribute("data-lit",!!(f&&l(f)))}),p){for(const i of n.lines)if(l(i)){const f=h.get(String(i.i));f&&p.appendChild(f)}}const u=Mt(n.lines,l),{defs:g,ids:c}=se(e,{...n,crossings:u},s,r),y=t.querySelector(`.${e}-svg`);if(!y)return;let $=y.querySelector("defs");!$&&g&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),y.insertBefore($,y.firstChild)),$&&($.innerHTML=g),n.lines.forEach((i,f)=>{const b=h.get(String(i.i))?.querySelector(`.${e}-line`);if(!b)return;const O=c.get(f);O?b.setAttribute("mask",`url(#${O})`):b.removeAttribute("mask")})}var Ye=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Qe(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Ye()?"done":"pending")}}function ie(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Pe(t,e,n){const s=t.byId.get(e)?.i??0,r=t.nodes.length;let o;if(n==="ArrowRight"||n==="ArrowDown")o=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")o=s-1;else if(n==="Home")o=0;else if(n==="End")o=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,o))].id}var tn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],le=["data-layout","data-measured","data-bare","data-motion"],en=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ce=t=>t==null||t===!1;function nn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function de(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?le:tn;for(const a of s)ce(e.a[a])&&t.removeAttribute(a);for(const[a,l]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const h=t.style,u=new Map(String(l??"").split(";").map(g=>{const c=g.indexOf(":");return[g.slice(0,c).trim(),g.slice(c+1).trim()]}).filter(([g])=>g));for(const[g,c]of u)h.getPropertyValue(g).trim()!==c&&h.setProperty(g,c);for(const g of en)u.has(g)||h.removeProperty(g);continue}if(n&&!le.includes(a))continue;if(ce(l)){t.removeAttribute(a);continue}const p=l===!0?"":String(l);t.getAttribute(a)!==p&&t.setAttribute(a,p)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let l=o;lt.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(c,y,$){return{prefix:n,base:c,hasSource:y.source!==void 0&&y.source!==null&&y.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(c,y,$,i){var f=function(b){return''+lt(b)+""};return{source:lt(String(y.source||"")),summary:lt(String(y.summary||"")),hint:zt(c).map(function(b){return""+b.keys.map(f).join(" ")+" "+lt(b.words)+""}).join(""),toggle:'"}}function a(c,y,$){var i=kt(c),f=Wt(i,{},r(y,c,$)),b=St(f,o(i,c,y,!1)),O=b.indexOf(">");return{open:b.slice(0,O+1),inner:b.slice(O+1,b.length-9),warnings:i.warnings}}var l=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],p=["--_cols","--_gpad","--_track"];function h(c,y,$,i){c.__diagram&&c.__diagram.stop();var f=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),b=kt(y);if(!$||!f||!c.querySelector(":scope > .diagram-drawing")){if(!f||!c.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var O=a(y,f,i),_=document.createElement("div");_.innerHTML=O.open+"";var B=_.firstChild;l.forEach(function(H){c.removeAttribute(H)}),p.forEach(function(H){c.style.removeProperty(H)});for(var j=0;j :not(script[data-diagram])").forEach(function(H){H.remove()}),c.insertAdjacentHTML("beforeend",O.inner)}b.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var Q=r(f,y,i),A={},V=null,v=null,D=null,L=Object.create(null),x=function(H){L[H]||(L[H]=1,console.warn("Basalt diagram: "+H))},d=function(H){de(c,Wt(b,H,Q))},m=c.querySelector(".diagram-ink"),S=c.querySelector(".diagram-toggle"),E=!i&&b.motion.animated&&typeof e.diagramMotion=="function",z=null,T=null,G=function(){E&&ie(c)};function N(){Xe(c,n,V&&V.geo,V&&V.tokens,f,v||D)}function k(){S&&(S.setAttribute("aria-expanded",String(!!A.open)),S.firstElementChild.textContent=A.open?"Hide the list":"View as list")}function C(){V=(i?i.measure:re)(c,b,n,f,A,d,x),A=V.dyn,d(A),k(),gt(b,A)||(D=null);var H=m&&V.ink!==T;H&&(m.innerHTML=V.ink,T=V.ink),N(),E&&V.tokens&&(Qe(c,!!(V.geo&&V.geo.lines.length)),H&&z&&z.redrawn()),i&&i.onMeasured&&i.onMeasured(V,c)}function q(H){A=H,d(A)}function M(H){var st=A.stop;A=Object.assign({},A,{stop:H}),on(c,n,st,H)}var I=function(H){var st=H&&H.closest?H.closest(".diagram-node"):null;return st&&c.contains(st)?st:null};function F(H){var st=I(H.target);if(!(!st||H.defaultPrevented)){if(G(),H.key==="Escape"){!i&&(v||D)&&(H.preventDefault(),v=D=null,N());return}if(gt(b,A)){var ut=Pe(b,st.getAttribute("data-node"),H.key);if(ut){H.preventDefault(),M(ut);var ue=c.querySelector('.diagram-node[data-node="'+CSS.escape(ut)+'"]');ue&&ue.focus()}}}}function Z(H){var st=I(H.target);if(st){G();var ut=st.getAttribute("data-node");v=st.matches(":focus-visible")?ut:null,gt(b,A)&&A.stop!==ut&&M(ut),N()}}function P(H){var st=I(H.target);st&&(I(H.relatedTarget)||(v=null),A.keep===st.getAttribute("data-node")&&q(Object.assign({},A,{keep:void 0})),N())}function X(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var st=I(H.target);st&&G();var ut=st&>(b,A)?st.getAttribute("data-node"):null;ut!==D&&(D=ut,N())}}function W(){D&&(D=null,N())}function K(){G(),q(Object.assign({},A,{open:!A.open,autoOpen:void 0})),k()}c.addEventListener("keydown",F),c.addEventListener("focusin",Z),c.addEventListener("focusout",P),c.addEventListener("pointerover",X),c.addEventListener("pointerleave",W),S&&S.addEventListener("click",K),C();var ot=c.clientWidth,tt=0,J=!0,et=new ResizeObserver(function(){Math.abs(c.clientWidth-ot)<.5||(ot=c.clientWidth,cancelAnimationFrame(tt),tt=requestAnimationFrame(C))});et.observe(c),document.fonts&&document.fonts.ready.then(function(){J&&C()});var U=matchMedia("(forced-colors: active)"),nt=b.nodes.some(function(H){return H.mark});nt&&U.addEventListener("change",C),E&&(z=e.diagramMotion(c,{fig:c,P:n,base:f,model:function(){return b},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},y));var at=!i&&y.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,y,{model:b,settle:G,animated:E}):null;c.__diagram={stop:function(){at&&at.destroy(),J=!1,et.disconnect(),cancelAnimationFrame(tt),nt&&U.removeEventListener("change",C),z&&z.destroy(),c.removeEventListener("keydown",F),c.removeEventListener("focusin",Z),c.removeEventListener("focusout",P),c.removeEventListener("pointerover",X),c.removeEventListener("pointerleave",W),S&&S.removeEventListener("click",K)},layout:C,key:u(y),send:z&&z.sendValue?z.sendValue:null}}function u(c){try{return JSON.stringify(c,function(y,$){return y==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var y=c.querySelector(":scope > script[data-diagram]");if(y)try{h(c,JSON.parse(y.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:h,buildModel:kt,figureKey:Se,figureList:_e,hintEntries:zt,toHtml:St,escapeHtml:lt,settleEntrance:ie,measureFigure:re},t.diagram=function(c,y){var $=c.__diagram,i=$&&$.send?u(y):null;if(i!==null&&i===$.key){$.send(y.packet?y.packet.send:void 0);return}h(c,y)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function wt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Ot=28,mt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function _t(t,e){return t.legend[e]}function me(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function ye(t,e){return wt(t,`sentence:${e.i}`,()=>be(t,e))}function be(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,r=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(mt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`)}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?me(t,e):e.kind;if(n.push(mt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(mt(e.detail)),e.group){const a=t.groups.find(l=>l.id===e.group);a&&n.push(`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${a.label})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${a.label})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(mt(t.legend.focal)),n.join(" ")}function $e(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function w(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var we={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>we[e]),xe=" br img input meta link hr path polygon polyline circle rect line ";function St(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return xe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>St(s,e)).join("")}`}var ve=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function gt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Me(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Ct(t){let e=0;for(const n of t.groups){const s=n.members.map(r=>t.byId.get(r).col);s.length&&(Math.min(...s)===1&&(e|=1),Math.max(...s)===t.cols&&(e|=2))}return(e&1)+(e>>1&1)}function Et(t){return t.type==="sequence"?t.nodes.length:t.cols}function Bt(t){return wt(t,"plan",()=>ke(t))}function ke(t){const e=t.nodes,n=i=>t.type==="data-flow"||!e[i].branch,s=t.edges.map(i=>{const f=t.byId.get(i.from).i,b=t.byId.get(i.to).i,_=e.slice(Math.min(f,b)+1,Math.max(f,b)).every(B=>!n(B.i));return b===f+1&&!(n(f)&&!n(b))?"down":b===f-1?"up":b>f&&n(f)&&!n(b)&&_?"trunk":b>f&&n(f)&&n(b)&&_?"rail":b>f?"end-down":"end-up"}),r=t.edges.map((i,f)=>({e:i,k:f})).filter(({k:i})=>s[i]==="end-down"||s[i]==="end-up"),o=i=>{const f=t.byId.get(i.from).i,b=t.byId.get(i.to).i;return[Math.min(f,b),Math.max(f,b)]},a=(i,f)=>{const[b,O]=o(i),[_,B]=o(f);return b{const f=t.byId.get(i.from).i,[b,O]=o(i);return!n(f)&&e.slice(b+1,O).every(_=>!n(_.i))&&r.every(_=>_.e===i||!a(_.e,i))}),p=r.length>0&&(t.type==="data-flow"||!l),h=i=>{const[f,b]=o(i);return b-f},u=t.edges.map(()=>0);let g=!1;const c=[];for(const i of[...r].sort((f,b)=>h(f.e)-h(b.e)||f.k-b.k)){let f=0;for(const b of c)a(b.e,i.e)&&(f=Math.max(f,u[b.k]+1));u[i.k]=f,f>1&&(g=!0),c.push(i)}const y=t.edges.map(()=>.5);for(const i of e){const f=r.filter(({e:_})=>_.from===i.id);if(f.length<2)continue;const b=f.filter(({k:_})=>s[_]==="end-down").sort((_,B)=>h(B.e)-h(_.e)||_.k-B.k);[...f.filter(({k:_})=>s[_]==="end-up").sort((_,B)=>h(_.e)-h(B.e)||B.k-_.k),...b].forEach(({k:_},B,j)=>{y[_]=j.length===2?B===0?1/3:2/3:(B+1)/(j.length+1)})}const $=ht();for(let i=1;i{const A=s[Q],V=t.byId.get(R.from).i,v=t.byId.get(R.to).i,D=v===i&&(A==="down"||A==="trunk"||A==="rail"||A==="end-down"),L=V===i&&v===i-1&&A==="up",x=v===i-1&&A==="end-up";D&&(A==="trunk"||A==="end-down")&&(B=!0),x&&(j=!0),(D||L||x)&&R.label&&(O++,_=Math.max(_,A==="trunk"?40:48))}),(O>1||B&&j)&&(_=64),$[f.id]=_}return{routes:s,gutter:p,lanes:u,exits:y,gaps:$,third:g}}var yt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function jt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return w("svg",{class:`${t}-swatch`,"data-kind":n,...yt(24,16)},e==="fk"?w("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,w("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?w("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):w("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function bt(t,e){return e==="decision"?w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Tt(t,e){return wt(e,`key:${t}`,()=>Ee(t,e))}var Se=Tt;function Ee(t,e){const n=[],s=(o,a,l={})=>n.push(w("li",{class:`${t}-entry`,...l},o,w("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),w("span",null,l)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(bt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(bt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(bt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(jt(t,o),a,{"data-line":""})}return e.type==="schema"&&e.edges.length&&(s(jt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(w("li",{class:`${t}-entry`,"data-when":"stacked"},w("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),w("span",null,"The table a foreign key references")))),e.nodes.some(o=>o.focal)&&e.legend.focal&&s(bt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(bt(t,"group"),e.legend.group),n.length?w("div",{class:`${t}-key`},w("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Ae(t,e){const n=e==="main"?6:6.5;return w("svg",{class:`${t}-arrow`,"data-kind":e,...yt(20,12)},w("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?w("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):w("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Le(t,e,n){if(n.shape==="decision")return[w("span",{class:`${t}-words`},w("span",{class:`${t}-name`},n.name))];const s=[];return e.type==="data-flow"?s.push(w("span",{class:`${t}-kind`},n.kind,w("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(w("span",{class:`${t}-kind`},n.kind)),s.push(w("span",{class:`${t}-name`},n.name)),n.detail&&s.push(w("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?vt(n.detail).flatMap((r,o)=>[o?" ":"",w("span",{class:`${t}-run`},r)]):n.detail)),s}function qe(t,e){return[w("span",{class:`${t}-th`},w("span",{class:`${t}-tname`},e.name)),w("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>w("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},w("span",{class:`${t}-keyseat`},n.key??""),w("span",{class:`${t}-cname`},n.name),n.ref?w("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?w("span",{class:`${t}-ctype`},n.type):null))),e.more?w("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Rt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=Me(e,s)||s.keep===n.id,a=gt(e,s),l=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&l.push(`--_lc:${n.col+1}`),e.type==="sequence"&&l.push(`--_c2:${n.col+1}`);const p=t.plan;if(p&&n.i>0){const c=pt(p.gaps,n.id)??32,y=pt(s.grow,n.id)??0;l.push(`--_gap:${y?`calc(${Rt(c)} + var(--basalt-space-4) * ${y})`:Rt(c)}`)}const h=pt(s.heights,n.id);h&&l.push(`--_h:${h}px`);const u=pt(s.words,n.id);u&&l.push(`--_ww:${u}px`);const g=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return w("div",{class:`${r}-node`,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:l.join(";"),role:o?"img":void 0,"aria-label":o?ye(e,n):void 0,tabindex:g},n.shape==="decision"?w("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},w("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?w("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${It(n.mark.onLight)};--_md:${It(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?qe(r,n):Le(r,e,n))}function Ie(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((a,l)=>w("div",{class:`${s}-lane`,style:`--_r:${l+1}`,"aria-hidden":"true"},w("span",{class:`${s}-lane-name`},a.label)))),e.type==="architecture")for(const a of e.groups){const l=a.members.map(c=>e.byId.get(c));if(!l.length)continue;const p=Math.min(...l.map(c=>c.col)),h=Math.max(...l.map(c=>c.col)),u=Math.min(...l.map(c=>c.row)),g=Math.max(...l.map(c=>c.row2));r.push(w("div",{class:`${s}-gbox`,"data-group":a.id,style:`--_c:${p};--_c2:${h+1};--_r:${u};--_r2:${g+1}`,"aria-hidden":"true"},w("span",{class:`${s}-glabel`},a.label)))}if(e.type==="sequence")return r.push(w("ul",{class:`${s}-cast`},e.nodes.map(a=>w("li",{class:`${s}-actor`},At(t,e,a,n))))),r.push(Oe(t,e)),r;let o=0;for(;ou.id===a.group):void 0;if(!l){r.push(At(t,e,a,n)),o++;continue}const p=[];for(;oAt(t,e,u,n))))}return r}function Oe(t,e){const{P:n}=t,s=[];let r=null;for(const o of e.steps){if("band"in o){r=null,s.push(w("p",{class:`${n}-band`},w("span",null,o.band)));continue}r||(r=w("ol",{class:`${n}-msgs`,start:o.n}),s.push(r));const a=e.byId.get(o.from),l=e.byId.get(o.to),p=a?.col??1,h=l?.col??1,u=p===h,g=u&&p===e.nodes.length,c=_t(e,o.kind);r.c.push(w("li",{class:`${n}-msg`,"data-kind":o.kind,"data-from":o.from,"data-to":o.to,"data-self":u?g?"start":"end":void 0,style:`--_a:${Math.min(p,h)};--_b:${Math.max(p,h)+1}`},w("span",{class:`${n}-said`},w("span",{class:`${n}-num`},String(o.n)),w("span",{class:`${n}-mlabel`},o.label)),w("span",{class:`${n}-route`},a?.short??o.from," ",Ae(n,o.kind),w("span",{class:t.hidden}," to ")," ",l?.short??o.to,c?` · ${c}`:""),o.note?w("span",{class:`${n}-note`},o.note):null))}return w("div",{class:`${n}-steps`},s)}function Ft(t,e){return wt(e,`list:${t}`,()=>Ce(t,e))}var _e=Ft;function Ce(t,e){const n=Math.min(6,e.heading+1),s=u=>w(`h${n}`,{class:`${t}-list-head`},u),r=u=>w("strong",null,u),o=u=>w("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,l=u=>{const g=_t(e,u);return g?` (${g})`:""},p=u=>u.focal&&e.legend.focal?` ${mt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=y=>w("li",null,r(y.name),y.kind?`, ${y.kind}`:"",y.detail?[". ",y.mono?o(y.detail):y.detail,/[.!?]$/.test(y.detail)?"":"."]:/[.!?]$/.test(y.kind??y.name)?"":".",p(y)),g=[s("Parts")],c=e.nodes.filter(y=>!y.group);c.length&&g.push(w("ul",{class:`${t}-list-items`},c.map(u)));for(const y of e.groups)g.push(w("p",{class:`${t}-list-group`},y.label)),g.push(w("ul",{class:`${t}-list-items`},y.members.map($=>u(e.byId.get($)))));return g.push(s("Connections")),g.push(w("ol",{class:`${t}-list-items`},e.edges.map(y=>w("li",null,r(a(y.from))," to ",r(a(y.to)),y.label?[": ",o(y.label)]:"",`${l(y.kind)}.`)))),g}if(e.type==="flowchart"){const u=g=>(e.byId.get(g)?.i??0)+1;return[w("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const c=e.edges.filter(i=>i.from===g.id),y=g.shape==="decision"?"Decision":g.shape==="terminal"?c.length?"Start":"End":"Step",$=!g.detail&&/[.!?]$/.test(g.name)?" ":". ";return w("li",null,r(g.name),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",`${$}${y}.`,p(g),c.length?w("ul",{class:`${t}-list-exits`},c.map(i=>w("li",null,i.label?`If ${i.label}: go to ${u(i.to)}, `:`Then: go to ${u(i.to)}, `,r(a(i.to)),l(i.kind)))):null)}))]}if(e.type==="data-flow")return[w("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const g=e.edges.filter(c=>c.from===u.id);return w("li",null,`${u.laneLabel}: `,r(u.name),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",p(u),g.length?[" Then ",...g.flatMap((c,y)=>[y?"; ":"",`to step ${e.byId.get(c.to).step}, `,r(a(c.to)),c.label?[": ",o(c.label)]:"",l(c.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),w("ul",{class:`${t}-list-items`},e.nodes.map(c=>w("li",null,r(c.name),c.kind?`, ${c.kind}`:"",".",p(c))))];u.push(s("Messages"));let g=null;for(const c of e.steps){if("band"in c){g=null,u.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},c.band));continue}g||(g=w("ol",{class:`${t}-list-items`,start:c.n}),u.push(g)),g.c.push(w("li",null,o(c.label),": ",r(a(c.from))," to ",r(a(c.to)),`${l(c.kind)}.`,c.note?` ${mt(c.note)}`:""))}return u}const h=[];for(const u of e.nodes)h.push(w(`h${n}`,{class:`${t}-list-group`},o(u.name),p(u))),h.push(w("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(g=>w("li",null,o(g.name),g.key==="PK"?", primary key":g.key==="FK"?", foreign key":"",g.ref?[", references ",o(`${g.ref.table}.${g.ref.column}`)]:g.type?`, ${g.type}`:"")),...u.more?[w("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return h}function Ht(t){return`Arrow keys move to the next or the previous ${t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step"}, in the author's order; Home and End go to the ends; Escape clears the trace.`}function zt(t){return[{keys:["←","→"],words:$e(t)},{keys:["Home","End"],words:"the ends"},{keys:["Esc"],words:"clear"}]}var Nt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Wt(t,e,n){const s=n.prefix,r=ve(n.base),o=t.type==="sequence"||t.type==="schema"?null:Bt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},l=e.layout==="drawn",p=gt(t,e),h=t.type==="sequence"||t.type==="schema"?l:!0,u=`h${t.heading}`,g=[`--_cols:${Et(t)}`];if(t.type==="architecture"&&t.groups.length||l&&e.pad){const c=t.type==="architecture"?t.groups.flatMap(i=>i.members.map(f=>t.byId.get(f))):[],y=(i,f,b)=>i?`var(--basalt-space-${f})`:b?`var(--basalt-space-${b})`:"0px",$=l&&e.pad?"3":void 0;g.push(`--_gpad:${y(c.some(i=>i.row===1),"8",$)} ${y(c.some(i=>i.col===t.cols),"4")} ${y(c.some(i=>i.row2===t.rows),"4",$)} ${y(c.some(i=>i.col===1),"4")}`)}return Nt(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),w("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Et(t),"data-reach":t.type==="architecture"?Ct(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},w("div",{class:`${s}-head`},w(u,{id:r.title,class:`${s}-title`},t.title),n.hasSource?w("p",{class:`${s}-source`},{slot:"source"}):null),w("div",{class:`${s}-drawing`,role:h?"group":void 0,"aria-roledescription":h?"diagram":void 0,"aria-labelledby":h?r.title:void 0,"aria-describedby":h?p?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":p?"":void 0},Ie(a,t,e),w("div",{class:`${s}-ink`,"aria-hidden":"true"}),w("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Tt(s,t),w("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),w("div",{class:`${s}-foot`},{slot:"toggle"}),w("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Ft(s,t)),w("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Ht(t)} ${n.viewer}`:Ht(t)),w("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Be(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4)}}var xt=(t,e)=>t==="main"?e.line:e.hair,ct=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},dt=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Dt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function it(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,l=(s+o)/2,p=(r+a)/2,h=(o-s)/2,u=(a-r)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const $=n,i=u*Math.max(0,1-Math.abs($-l)/h);return{x:$,y:e==="top"?p-i:p+i}}const c=n,y=h*Math.max(0,1-Math.abs(c-p)/u);return{x:e==="left"?l-y:l+y,y:c}}if(t.shape==="terminal"){const c=Math.min(h,u);if(g){const f=n,b=Math.min(Math.max(f,s+c),o-c),O=f-b,_=Math.abs(O)>=c?0:Math.sqrt(c*c-O*O);return{x:f,y:Math.abs(O)<1e-6?e==="top"?r:a:e==="top"?p-_:p+_}}const y=n,$=y-p,i=Math.abs($)>=c?0:Math.sqrt(c*c-$*$);return{x:e==="left"?s+c-i:o-c+i,y}}return g?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function je(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,l=(s+o)/2,p=(r+a)/2,h=(o-s)/2,u=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-l)/h+Math.abs(t.y-p)/u<1-n/Math.min(h,u);if(e.shape==="terminal"){const g=Math.min(h,u),c=Math.min(Math.max(t.x,s+g),o-g);return Math.hypot(t.x-c,t.y-p)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Fe(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var vt=t=>t?t.split(/\s+/).filter(Boolean):[];function He(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const p of t.nodes){if(p.shape==="table"){for(const y of p.columns??[]){const $=y.ref?`→ ${y.ref.table}`:y.type??"",i=s("6")+n(y.name,"mono")+($?s("3")+n($,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(i))}o=Math.max(o,Math.ceil(n(p.name,"table")+2*s("3")+2*e.hair));continue}const h=p.shape==="terminal"?2*s("5"):2*s("3"),u=p.mark&&!Re()?s("6"):0;let g=0;for(const y of vt(p.name))g=Math.max(g,n(y,p.shape==="decision"?"name-500":"name")+(p.kind?0:u));if(t.type!=="data-flow")for(const y of vt(p.kind))g=Math.max(g,n(y,"mono")+u);for(const y of vt(p.detail))g=Math.max(g,n(y,p.mono?"mono":"sans"));const c=p.shape==="decision"?g/.62:g+h+2*e.hair;r=Math.max(r,Math.ceil(c))}const a=Et(t);let l;return t.type==="data-flow"?l=e.lane+a*(r+s("12")):t.type==="schema"?l=a*o+(a-1)*s("12")+(Nt(t)?s("5"):0):t.type==="sequence"?l=a*r+(a-1)*s("5"):l=a*r+(a-1)*s("16")+Ct(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,l)}}function Kt(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Lt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Vt(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const p=r[r.length-2];if(Math.abs(p.x-l.x)<.01&&Math.abs(l.x-a.x)<.01||Math.abs(p.y-l.y)<.01&&Math.abs(l.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ft=t=>t.slice(1).map((e,n)=>[t[n],e]);function Mt(t,e,n){const s=[];for(let o=0;oMath.min(i.x,f.x)+.75&&_Math.min(b.y,O.y)+.75&&Br.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const l=[];let p=o;for(const h of r)l.push([p,p+h]),p+=h+a;return l};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var Y=t=>t==="left"||t==="right",Zt={top:"bottom",bottom:"top",left:"right",right:"left"};function Ne(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function We(t,e,n){const s=[];t.edges.forEach((o,a)=>{const l=t.byId.get(o.from),p=t.byId.get(o.to),[h,u]=e[a],g=l.row===p.row&&Y(h)&&Y(u)&&h===Zt[u]||l.col===p.col&&!Y(h)&&!Y(u)&&h===Zt[u];s.push({edge:a,end:"from",node:l,side:h,far:p,straight:g,f:.5},{edge:a,end:"to",node:p,side:u,far:l,straight:g,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const l=i=>Y(i.side)?i.far.row-i.node.row:i.far.col-i.node.col,p=a.filter(i=>i.straight),h=a.filter(i=>!i.straight);if(h.sort((i,f)=>l(i)-l(f)||(Y(i.side)?i.far.col-f.far.col:i.far.row-f.far.row)*(l(i)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!p.length){h.length===2?(h[0].f=.25,h[1].f=.75):h.length===3?(h[0].f=.25,h[1].f=.5,h[2].f=.75):h.length>3&&h.forEach((i,f)=>{i.f=(f+1)/(h.length+1)});continue}const u=new Map;for(const i of p)u.has(i.far.id)||u.set(i.far.id,[]),u.get(i.far.id).push(i);for(const i of u.values())i.length>1&&i.sort((f,b)=>f.edge-b.edge).forEach((f,b)=>{f.f=i.length===2?b===0?.25:.75:(b+1)/(i.length+1)});const g=Math.min(...p.map(i=>i.f)),c=Math.max(...p.map(i=>i.f)),y=h.filter(i=>l(i)<0),$=h.filter(i=>l(i)>=0);y.forEach((i,f)=>{i.f=g*(f+1)/(y.length+1)}),$.forEach((i,f)=>{i.f=c+(1-c)*(f+1)/($.length+1)})}return s}function Jt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return Y(e)?it(t,e,r+(a-r)*n):it(t,e,s+(o-s)*n)}function Ut(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ct(o,n),shape:a.shape,i:a.i})}),r}function Xt(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var Yt=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Qt(t,e,n,s){const r=(o,a)=>{const l=o+a-Math.floor(o+a);return l<.005||l>.995?[0]:l<=.5?[-l,1-l]:[1-l,-l]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const l={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(l))return l}return t}function De(t,e,n,s,r,o,a,l,p){const h=a.space,u=[],g=[],c=[],y=[],$=h("1"),i=e.filter(f=>t.edges[f.i]?.label).sort((f,b)=>+(t.edges[b.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-b.i);for(const f of i){const b=t.edges[f.i].label,O=l(b,"label"),_=16,B=f.pts.length-2,j=[];ft(f.pts).forEach(([v,D],L)=>{const x=Math.abs(v.y-D.y)<.01,d=x?v.x:v.y;let m=x?D.x:D.y;const S=Math.sign(m-d)||1;L===B&&(m-=S*a.head);let E=[[d,m]];for(const G of r)for(const N of x?[G.l,G.r]:[G.t,G.b]){const k=x?v.y:v.x;(x?k>G.t&&kG.l&&kN>Math.min(q,M)+1&&N{const k=(G+N)/2,C=x?{x:k,y:v.y}:{x:v.x,y:k};return!r.some(q=>C.x>q.l&&C.xq.t&&C.y1&&z(G,N)?1:0})}),j.sort((v,D)=>D.pri-v.pri||D.len-v.len);let R=null,Q=!1;const A=(v,D=!0)=>{const L=Dt(v,$);return D&&(v.lo.r||v.to.b)||n.some(x=>Gt(L,x))||u.some(x=>dt(L,x))||s.heads.some(x=>dt(L,x))||s.rects.some(x=>dt(L,x))?!1:!e.some(x=>x.i!==f.i&&ft(x.pts).some(([d,m])=>dt(L,Yt(d,m,x.width))))};for(const v of j){for(const D of[1/2,1/3,2/3]){const L=v.p+(v.q-v.p)*D,x=[],d=h("2")+f.width/2;if(v.horiz?(v.len>=O+2*h("1")+h("3-5")&&x.push({box:{l:L-O/2-h("1"),r:L+O/2+h("1"),t:v.c-_/2,b:v.c+_/2},on:!0}),x.push({box:{l:L-O/2,r:L+O/2,t:v.c-d-_,b:v.c-d},on:!1}),x.push({box:{l:L-O/2,r:L+O/2,t:v.c+d,b:v.c+d+_},on:!1})):(v.len>=_+h("3")&&x.push({box:{l:v.c-O/2-h("1"),r:v.c+O/2+h("1"),t:L-_/2,b:L+_/2},on:!0}),x.push({box:{l:v.c+d,r:v.c+d+O,t:L-_/2,b:L+_/2},on:!1}),x.push({box:{l:v.c-d-O,r:v.c-d,t:L-_/2,b:L+_/2},on:!1})),R=x.find(m=>A(m.box))??null,R)break;!Q&&x.some(m=>A(m.box,!1))&&(Q=!0)}if(R)break}if(!R){c.push(f.i),Q&&y.push(f.i);continue}const V=Qt(R.box,p.ox,p.oy,v=>A(v));u.push(V),g.push({i:f.i,text:b,box:V,on:R.on})}return{labels:g,unseated:c,bounded:y}}function Pt(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const l=ct(a,e);o.push(l),r.push({l:l.l,r:l.r,t:l.t,b:l.t+1},{l:l.l,r:l.r,t:l.b-1,b:l.b},{l:l.l,r:l.l+1,t:l.t,b:l.b},{l:l.r-1,r:l.r,t:l.t,b:l.b});const p=a.querySelector(`:scope > .${n}-glabel`);p&&p.getClientRects().length&&r.push(ct(p,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,l)=>{if(!a.getClientRects().length)return;const p=ct(a,e);l>0&&r.push({l:p.l,r:p.r,t:p.t-s/2-.5,b:p.t-s/2+.5});const h=a.querySelector(`.${n}-lane-name`);h&&r.push(ct(h,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function Ge(t,e){const{m:s,tk:r,P:o,drawing:a,origin:l,warn:p}=t,h=r.space,u=Ut(s,a,l,o),g=[...u.values()],c=ze(a),y=l.left-Math.floor(l.left),$=l.top-Math.floor(l.top),i=Kt(y,$),f=a.clientWidth,b=a.clientHeight,O=k=>s.type==="data-flow"?k.col+1:k.col,_=parseFloat(getComputedStyle(a).rowGap)||0,B={w:f,h:b,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:y,oy:$};if(s.type==="sequence")return Ve(t,B,i);let j,R=[];s.type==="schema"?j=s.edges.map(k=>{const C=s.byId.get(k.from),q=s.byId.get(k.to);if(C.col===q.col){const M=C.col===s.cols&&s.cols>1?"left":"right";return[M,M]}return q.col>C.col?["right","left"]:["left","right"]}):(j=s.edges.map(k=>{const C=s.byId.get(k.from),q=s.byId.get(k.to),[M,I]=Ne(C,q);return[k.fromSide??M,k.toSide??I]}),R=We(s,j,p||(()=>{})));const Q=(k,C)=>{const q=a.querySelector(`.${o}-node[data-node="${CSS.escape(k)}"] .${o}-row[data-row="${C}"]`);if(!q)return 0;const M=ct(q,l);return(M.t+M.b)/2},A=s.edges.map((k,C)=>{const[q,M]=j[C],I=u.get(k.from),F=u.get(k.to),Z=xt(k.kind,r);if(k.fk){const J=Q(k.from,k.fromRow),et=Q(k.to,k.toRow),U=i.y(J,Z),nt=i.y(et,Z);return{p1:{x:q==="right"?I.rect.r:I.rect.l,y:U},p2:{x:M==="right"?F.rect.r:F.rect.l,y:nt},r1:J,r2:Math.abs(U-nt)<.01?J:et}}const P=R.find(J=>J.edge===C&&J.end==="from").f,X=R.find(J=>J.edge===C&&J.end==="to").f;let W=Jt(I,q,P),K=Jt(F,M,X);const ot=Y(q)?W.y:W.x;let tt=Y(M)?K.y:K.x;return Y(q)?W={...W,y:i.y(W.y,Z)}:W={...W,x:i.x(W.x,Z)},Y(M)?K={...K,y:i.y(K.y,Z)}:K={...K,x:i.x(K.x,Z)},Y(q)&&Y(M)&&Math.abs(W.y-K.y)<1.01&&(K={...K,y:W.y},tt=ot),!Y(q)&&!Y(M)&&Math.abs(W.x-K.x)<1.01&&(K={...K,x:W.x},tt=ot),W=Y(q)?it(I,q,W.y):it(I,q,W.x),K=Y(M)?it(F,M,K.y):it(F,M,K.x),{p1:W,p2:K,r1:ot,r2:tt}}),V=new Set;s.type==="schema"&&s.edges.forEach((k,C)=>{Math.abs(s.byId.get(k.from).col-s.byId.get(k.to).col)>1&&V.add(C)});const v=new Map,D=new Set;s.edges.forEach((k,C)=>{if(V.has(C))return;const[q,M]=j[C],{p1:I,p2:F}=A[C],Z=s.byId.get(k.from),P=s.byId.get(k.to);let X=null,W=null,K=!1;if(q===M){if(Y(q)){const J=q==="right"?Math.max(O(Z),O(P)):Math.min(O(Z),O(P))-1,et=c.cols[J-1],U=c.cols[J];et&&U&&(X=`c${J}`,W=[et[1],U[0]],K=!0)}else{const J=q==="bottom"?Math.max(Z.row2,P.row2):Math.min(Z.row,P.row)-1,et=c.rows[J-1],U=c.rows[J];et&&U&&(X=`r${J}`,W=[et[1],U[0]],K=!1)}X&&D.add(C)}else if(Y(q)&&Y(M)&&Math.abs(I.y-F.y)>.5){const J=O(P),et=M==="left",U=c.cols[(et?J-1:J)-1],nt=c.cols[(et?J:J+1)-1];U&&nt&&(X=`c${et?J-1:J}`,W=[U[1],nt[0]],K=!0)}else if(!Y(q)&&!Y(M)&&Math.abs(I.x-F.x)>.5){const et=M==="top"?P.row-1:P.row2,U=c.rows[et-1],nt=c.rows[et];U&&nt&&(X=`r${et}`,W=[U[1],nt[0]],K=!1)}if(!X||!W)return;v.has(X)||v.set(X,{span:W,vertical:K,members:new Map});const ot=`${k.to}.${M}.${Math.round(K?F.y:F.x)}`,tt=v.get(X);tt.members.has(ot)||tt.members.set(ot,[]),tt.members.get(ot).push(C)});const L=new Map,x=k=>{const[C,q]=j[k],{p1:M,p2:I}=A[k];if(Y(C)&&Y(q)){if(C===q){const Z=L.get(k)??(C==="right"?Math.max(M.x,I.x)+h("4"):Math.min(M.x,I.x)-h("4"));return[M,{x:Z,y:M.y},{x:Z,y:I.y},I]}if(Math.abs(M.y-I.y)<=.5)return[M,{x:I.x,y:M.y}];const F=L.get(k)??(M.x+I.x)/2;return[M,{x:F,y:M.y},{x:F,y:I.y},I]}if(!Y(C)&&!Y(q)){if(C===q){const Z=L.get(k)??(C==="bottom"?Math.max(M.y,I.y)+h("4"):Math.min(M.y,I.y)-h("4"));return[M,{x:M.x,y:Z},{x:I.x,y:Z},I]}if(Math.abs(M.x-I.x)<=.5)return[M,{x:M.x,y:I.y}];const F=L.get(k)??(M.y+I.y)/2;return[M,{x:M.x,y:F},{x:I.x,y:F},I]}return Y(C)?[M,{x:I.x,y:M.y},I]:[M,{x:M.x,y:I.y},I]},d=k=>{const C=s.edges[k],q=xt(C.kind,r),M=x(k),I=Vt(M,q,i);let F;return M.length===I.length&&(F=ft(M).map(([Z,P])=>Math.abs(Z.y-P.y)<.75?(Z.y+P.y)/2:(Z.x+P.x)/2),F[0]=A[k].r1,F.length>1&&(F[F.length-1]=A[k].r2)),{i:k,from:C.from,to:C.to,kind:C.kind,pts:I,tip:I[I.length-1],dir:Lt(I),dot:C.fk?I[0]:void 0,width:q,axes:F}},m=()=>s.edges.flatMap((k,C)=>V.has(C)?[]:[d(C)]);let S=null;const E=k=>{S??(S=m());const C=S.map(q=>k.has(q.i)?d(q.i):q);return{lines:C,score:Ke(C,k)*1e5+Mt(C,void 0,k).length*1e3+qt(C.filter(q=>k.has(q.i)),g,s).length}},z=(k,C)=>{const q=k.flatMap(M=>{const{p1:I,p2:F}=A[M];return C?[I.y,F.y]:[I.x,F.x]});return[Math.min(...q),Math.max(...q)]};for(const[,k]of v){const C=[...k.members.values()].map(M=>({members:M,run:z(M,k.vertical)})).sort((M,I)=>M.run[0]-I.run[0]),q=[];for(const M of C){const I=q[q.length-1];I&&I.some(F=>F.run[0]D.has(ot)))continue;const I=M.map(ot=>ot.members),F=I.length,Z=(k.span[1]-k.span[0])/(F+1);ZJ.forEach(U=>L.set(U,k.span[0]+Z*(et+1))));const tt=E(P);tt.scoreot.forEach(J=>L.set(J,k.span[0]+Z*(tt+1)))),S=K}}B.lines=m();for(const k of V)p?.(`${s.edges[k].from} to ${s.edges[k].to} is two columns apart, so its line is not drawn; its row still writes the target`);B.crossings=Mt(B.lines),B.through=qt(B.lines,g,s),B.outside=ne(B.lines,f,b,r);const{obstacles:T,groups:G}=Pt(a,l,o,_);T.heads=B.lines.map(k=>Xt(k,r));const N=De(s,B.lines,g,T,G,{l:0,t:0,r:f,b},r,e,{ox:y,oy:$});return B.labels=N.labels,B.unseated=N.unseated,B.bounded=N.bounded,B.overlaps=[...new Set(te(B.lines,null).flat())],B}function Ke(t,e){return te(t,e).length}function te(t,e){const n=[];for(let s=0;s=l)continue;const[f,b]=c?[p.x,h.x]:[p.y,h.y],[O,_]=c?[u.x,g.x]:[u.y,g.y];Math.min(Math.max(f,b),Math.max(O,_))-Math.max(Math.min(f,b),Math.min(O,_))>1&&n.push([o.i,a.i])}}return n}function*ee(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const p=l===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-p<-.5||a.x+p>e+.5||a.y-p<-.5||a.y+p>n+.5})&&r.push(o.i);return r}function qt(t,e,n){const s=[];for(const r of t){const o=ft(r.pts);e.some(a=>o.some(([l,p])=>Te(l,p,a)))&&s.push(r.i)}return s}function Ve(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:l}=t,p=r.space,h=new Map;a.querySelectorAll(`.${o}-node`).forEach($=>h.set($.dataset.node,ct($,l)));const u=a.querySelector(`.${o}-steps`),g=u?ct(u,l).b:e.h,c=$=>{const i=h.get($);return i?n.x((i.l+i.r)/2,r.hair):0};for(const $ of s.nodes){const i=h.get($.id);i&&e.lifelines.push({x:c($.id),y1:i.b,y2:g})}const y=$=>h.get($.id);return a.querySelectorAll(`.${o}-msg`).forEach($=>{const i=$.dataset.from,f=$.dataset.to,b=$.dataset.kind??"plain",O=xt(b,r),_=ct($,l),B=n.y((_.t+_.b)/2,O),j=Number($.querySelector(`.${o}-num`)?.textContent??0),R=c(i),Q=c(f);let A;if(i===f){const m=$.dataset.self==="start"?-p("6"):p("6"),S=n.y(B-p("2"),O),E=n.y(B+p("2"),O);A=[{x:R,y:S},{x:n.x(R+m,O),y:S},{x:n.x(R+m,O),y:E},{x:R,y:E}]}else A=[{x:R,y:B},{x:Q,y:B}];e.lines.push({i:j,from:i,to:f,kind:b,pts:A,tip:A[A.length-1],dir:Lt(A),width:O});const V=$.querySelector(`.${o}-said`),v=$.querySelector(`.${o}-note`),D=s.byId.get(i),L=s.byId.get(f);if(!D||!L)return;const x=i===f?(()=>{const m=s.nodes[D.i+($.dataset.self==="start"?-1:1)],S=m?c(m.id):$.dataset.self==="start"?0:e.w;return Math.abs(S-R)-p("6")-p("2-5")-p("2")})():Math.abs(Q-R)-2*p("2");Math.max(V?V.getBoundingClientRect().width:0,v?v.getBoundingClientRect().width:0)>x+.5&&e.unseated.push(j)}),e}function oe(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:l,origin:p}=t,h=o.space,u=Ut(r,l,p,a),g=[...u.values()],c=p.left-Math.floor(p.left),y=p.top-Math.floor(p.top),$=Kt(c,y),i=l.clientWidth,f=l.clientHeight,b={w:i,h:f,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:y},O=ht();if(r.type==="sequence"||r.type==="schema")return{geo:b,grow:O};const _=i-(parseFloat(getComputedStyle(l).paddingRight)||0),B=(x,d,m)=>{const S=[x];for(let E=1;E<=(pt(s,d)??0);E++)S.push({...x,t:x.t+m*h("4")*E,b:x.b+m*h("4")*E});return S},j=new Map;l.querySelectorAll(`.${a}-node`).forEach(x=>{const d=x.parentElement,m=ct(d,p),S=getComputedStyle(d);j.set(x.dataset.node,m.r-(parseFloat(S.paddingRight)||0)-(parseFloat(S.borderRightWidth)||0))});const R=r.nodes,Q=x=>u.get(R[x].id),A=[],V=x=>xt(r.edges[x].kind,o);r.edges.forEach((x,d)=>{const m=n.routes[d],S=u.get(x.from),E=u.get(x.to),z=V(d);let T=[];const G=x.label,N=G?e(G,"label"):0,k=16,C=h("4");if(m==="down"||m==="up"){const M=Math.max(S.rect.l,E.rect.l),I=Math.min(S.rect.r,E.rect.r),F=r.edges.map((W,K)=>({o:W,j:K})).filter(({o:W,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(W.from===x.from&&W.to===x.to||W.from===x.to&&W.to===x.from)),Z=F.findIndex(W=>W.j===d),P=F.length<2?.5:F.length===2?Z===0?.25:.75:(Z+1)/(F.length+1),X=$.x(M+(I-M)*P,z);if(T=m==="down"?[it(S,"bottom",X),it(E,"top",X)]:[it(S,"top",X),it(E,"bottom",X)],G){let W=Math.min(T[0].y,T[1].y),K=Math.max(T[0].y,T[1].y);m==="down"?K-=o.head:W+=o.head;const ot=[...l.querySelectorAll(`.${a}-group`)].map(U=>ct(U,p));let tt=[[W,K]];for(const U of ot)for(const nt of[U.t,U.b])tt=tt.flatMap(([at,H])=>nt>at+1&&ntot.some(at=>(U+nt)/2>at.t&&(U+nt)/2at.l&&X1){const U=tt.filter(([at,H])=>!J(at,H));[W,K]=(U.length?U:tt).reduce((at,H)=>H[1]-H[0]>at[1]-at[0]?H:at)}const et=[1/2,1/3,2/3].map(U=>{const nt=W+(K-W)*U;return{l:X-N/2-h("1"),r:X+N/2+h("1"),t:nt-k/2,b:nt+k/2}});A.push({k:d,cands:et,on:!0,card:m==="down"?x.to:x.from})}}else if(m==="trunk"||m==="rail"){const M=$.x(Math.max(S.rect.l,m==="rail"?E.rect.l:S.rect.l)+h(m==="trunk"?"8":"3"),z),I=it(S,"bottom",M);if(m==="rail"){if(T=[I,it(E,"top",M)],G){const F=E.rect.t-h("6");A.push({k:d,cands:B({l:M+h("2-5"),r:M+h("2-5")+N,t:F-k/2,b:F+k/2},x.to,-1),on:!1,card:x.to})}}else{const F=$.x(E.rect.l+h("6"),z),Z=$.y(E.rect.t-C,z);T=[I,{x:M,y:Z},{x:F,y:Z},it(E,"top",F)],G&&A.push({k:d,cands:B({l:F+h("2-5"),r:F+h("2-5")+N,t:Z-k/2,b:Z+k/2},x.to,-1),on:!1,card:x.to})}}else{const M=Math.min(j.get(x.from)??i,j.get(x.to)??i),I=$.x(n.gutter?_+(n.lanes[d]?2*h("3-5"):h("3-5")):M-h("2-5"),z),F=$.y(S.rect.t+(S.rect.b-S.rect.t)*n.exits[d],z),Z=it(S,"right",F),P=$.x(E.rect.r-h("6"),z),X=m==="end-down",W=$.y(X?E.rect.t-C:E.rect.b+C,z);T=[Z,{x:I,y:Z.y},{x:I,y:W},{x:P,y:W},it(E,X?"top":"bottom",P)];const K=X?x.to:R[E.i+1]?.id??x.to;G&&A.push({k:d,cands:B({l:P-h("2-5")-N,r:P-h("2-5"),t:W-k/2,b:W+k/2},K,X?-1:1),on:!1,card:K})}const q=Vt(T,z,$);b.lines.push({i:d,from:x.from,to:x.to,kind:x.kind,pts:q,tip:q[q.length-1],dir:Lt(q),width:z})}),b.crossings=Mt(b.lines),b.through=qt(b.lines,g,r),b.outside=ne(b.lines,i,f,o);const{obstacles:v}=Pt(l,p,a,0);v.heads=b.lines.map(x=>Xt(x,o));const D=[],L={l:0,t:0,r:i,b:f};for(const x of A){const d=E=>{const z=Dt(E,h("1"));return E.lL.r+.5||E.tL.b+.5||g.some(T=>Gt(z,T))||D.some(T=>dt(z,T))||v.heads.some(T=>dt(z,T))||v.rects.some(T=>dt(z,T))||b.lines.some(T=>T.i!==x.k&&ft(T.pts).some(([G,N])=>dt(z,Yt(G,N,T.width))))},m=x.cands.find(E=>!d(E));m||(O[x.card]=(O[x.card]??0)+1,b.unseated.push(x.k));const S=m?Qt(m,c,y,E=>!d(E)):x.cands[0];D.push(S),b.labels.push({i:x.k,text:r.edges[x.k].label,box:S,on:x.on})}return{geo:b,grow:O}}function Ze(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...B})),g=u[u.length-1];g.x-=o.x*h,g.y-=o.y*h;const c=e.tip.x-o.x*l,y=e.tip.y-o.y*l,$=-o.y*p,i=o.x*p,f=B=>Math.round(B*100)/100,b=lt(e.kind),O=a?``:``,_=e.dot?``:"";return`${O}${_}`}function se(t,e,n,s){const r=new Map,o=new Map;for(const l of e.crossings)o.has(l.under)||o.set(l.under,[]),o.get(l.under).push(l);let a="";for(const[l,p]of o){const h=`${s}-cut-${l}`;r.set(l,h);const u=p.map(g=>{const c=e.lines[g.top],y=e.lines[g.under],$=c.width/2+n.cut,i=y.width/2+1;return g.underVertical?``:``}).join("");a+=`${u}`}return{defs:a,ids:r}}function ae(t,e,n,s){const{defs:r,ids:o}=se(t,e,n,s),a=e.lifelines.map(u=>``).join(""),l=e.lines.map((u,g)=>Ue(t,u,n,o.get(g)??null,u.from===u.to?n.radiusXs:n.radius)).join(""),p=`${r?`${r}`:""}${a}${l}`,h=e.labels.map(u=>`${lt(u.text)}`).join("");return p+h}function re(t,e,n,s,r,o,a,l){const h=t.querySelector(`.${n}-drawing`);if(!h||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const u=Be(t),g=Fe(h,n),c=He(e,u,g);l?.(c.least);const y=t.clientWidth,$=(()=>{const v=document.activeElement;return v&&h.contains(v)&&v.dataset.node?v.dataset.node:void 0})(),i=v=>gt(e,v)?{...v,stop:v.stop&&e.byId.has(v.stop)?v.stop:e.nodes[0]?.id,keep:void 0}:{...v,stop:v.stop??e.nodes[0]?.id,keep:$&&v.layout!=="drawn"?$:void 0};let f=!1;const b=v=>{if(f=!1,e.type!=="flowchart")return v;o({...v,heights:void 0,words:void 0});const D=ht(),L=ht();return h.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const d=x.querySelector(`.${n}-words`);if(!d)return;const m=x.getBoundingClientRect(),S=T=>{const G={w:T.width+2*u.space("2-5"),h:T.height+2*u.space("2")},N=1-G.w/m.width,k=N>.05?G.h/2/N:G.h*10;return Math.max(u.space("16"),Math.ceil(m.width/5),Math.ceil(2*k))},E=d.getBoundingClientRect();let z=S(E);if(z>m.width){const T=C=>(x.style.setProperty("--_ww",`${C}px`),d.getBoundingClientRect()),G=Math.floor(x.clientWidth-2*u.space("2-5"));let N=Math.ceil(E.width),k=E.height;for(;N1;){const F=C+q>>1;T(F).heightm.width&&(f=!0)}),{...v,heights:D,words:Object.keys(L).length?L:void 0}},O=()=>({m:e,tk:u,P:n,drawing:h,origin:h.getBoundingClientRect(),warn:a}),_=r.autoOpen?{open:!1,autoOpen:void 0}:{},B=(v,D)=>D.map(L=>$t(e,v.lines.find(x=>x.i===L))).join(", ");if(y>=c.least){const v=d=>{let m=i({...r,..._,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:d||void 0});return m=b(m),o(m),{dd:m,g:Ge(O(),g)}};let{dd:D,g:L}=v(!1);const x=d=>d.through.length>0||d.outside.length>0||(d.overlaps?.length??0)>0||f;if(!x(L)&&L.unseated.length&&L.unseated.every(d=>L.bounded?.includes(d))){const d=v(!0);!x(d.g)&&!d.g.unseated.length&&({dd:D,g:L}=d)}if(!x(L)&&!L.unseated.length)return L.crossings.length&&a?.(`${L.crossings.length} crossing${L.crossings.length===1?"":"s"} in the drawn layout: ${L.crossings.map(d=>`${$t(e,L.lines[d.top])} over ${$t(e,L.lines[d.under])}`).join("; ")}`),{dyn:D,geo:L,ink:ae(n,L,u,s),tokens:u,least:c.least};f&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: a decision would be taller than it is wide`),L.through.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.through)} would pass through a node`),L.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.overlaps)} would lie on one another`),L.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.outside)} would leave the drawing`),L.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: no clean seat for ${L.unseated.map(d=>e.type==="sequence"?`message ${d}`:`"${e.edges[d]?.label}"`).join(", ")}`)}let j=i({...r,..._,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(j=b(j),o(j),e.type==="sequence"||e.type==="schema")return{dyn:j,geo:null,ink:"",tokens:u,least:c.least};const R=Bt(e);let Q=oe(O(),g,R,j.grow);for(let v=0;v<6&&Object.keys(Q.grow).length;v++){const D=ht(j.grow);for(const[L,x]of Object.entries(Q.grow))D[L]=(pt(D,L)??0)+x;j={...j,grow:D},o(j),Q=oe(O(),g,R,D)}const A=Q.geo;if(A.unseated.length>0||A.through.length>0||A.outside.length>0||R.third){A.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(A.unseated)].map(L=>`"${e.edges[L]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),A.through.length&&a?.(`in the stacked drawing ${B(A,A.through)} would pass through a node, so its lines are not drawn`),A.outside.length&&a?.(`in the stacked drawing ${B(A,A.outside)} would leave the drawing, so its lines are not drawn`),R.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const v={...A,lines:[],labels:[],crossings:[]};return{dyn:i({...j,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:v,ink:"",tokens:u,least:c.least}}return A.crossings.length&&a?.(`${A.crossings.length} crossing${A.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${A.crossings.map(v=>`${$t(e,A.lines[v.top])} over ${$t(e,A.lines[v.under])}`).join("; ")}`),{dyn:j,geo:A,ink:ae(n,A,u,s),tokens:u,least:c.least}}function $t(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Xe(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const i of n?.lines??[])i.from===o&&a.add(i.to),i.to===o&&a.add(i.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(i=>i.toggleAttribute("data-near",a.has(i.dataset.node))),!n||!s)return;const l=i=>!!o&&(i.from===o||i.to===o),p=t.querySelector(`.${e}-edges`),h=new Map;t.querySelectorAll(`.${e}-edge`).forEach(i=>h.set(i.getAttribute("data-edge"),i));for(const i of n.lines){const f=h.get(String(i.i));f&&(f.toggleAttribute("data-lit",l(i)),f.toggleAttribute("data-dim",!!o&&!l(i)))}if(t.querySelectorAll(`.${e}-label`).forEach(i=>{const f=n.lines.find(b=>String(b.i)===i.dataset.edge);i.toggleAttribute("data-lit",!!(f&&l(f)))}),p){for(const i of n.lines)if(l(i)){const f=h.get(String(i.i));f&&p.appendChild(f)}}const u=Mt(n.lines,l),{defs:g,ids:c}=se(e,{...n,crossings:u},s,r),y=t.querySelector(`.${e}-svg`);if(!y)return;let $=y.querySelector("defs");!$&&g&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),y.insertBefore($,y.firstChild)),$&&($.innerHTML=g),n.lines.forEach((i,f)=>{const b=h.get(String(i.i))?.querySelector(`.${e}-line`);if(!b)return;const O=c.get(f);O?b.setAttribute("mask",`url(#${O})`):b.removeAttribute("mask")})}var Ye=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Qe(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Ye()?"done":"pending")}}function ie(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Pe(t,e,n){const s=t.byId.get(e)?.i??0,r=t.nodes.length;let o;if(n==="ArrowRight"||n==="ArrowDown")o=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")o=s-1;else if(n==="Home")o=0;else if(n==="End")o=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,o))].id}var tn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],le=["data-layout","data-measured","data-bare","data-motion"],en=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ce=t=>t==null||t===!1;function nn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function de(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?le:tn;for(const a of s)ce(e.a[a])&&t.removeAttribute(a);for(const[a,l]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const h=t.style,u=new Map(String(l??"").split(";").map(g=>{const c=g.indexOf(":");return[g.slice(0,c).trim(),g.slice(c+1).trim()]}).filter(([g])=>g));for(const[g,c]of u)h.getPropertyValue(g).trim()!==c&&h.setProperty(g,c);for(const g of en)u.has(g)||h.removeProperty(g);continue}if(n&&!le.includes(a))continue;if(ce(l)){t.removeAttribute(a);continue}const p=l===!0?"":String(l);t.getAttribute(a)!==p&&t.setAttribute(a,p)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let l=o;lt.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(c,y,$){return{prefix:n,base:c,hasSource:y.source!==void 0&&y.source!==null&&y.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(c,y,$,i){var f=function(b){return''+lt(b)+""};return{source:lt(String(y.source||"")),summary:lt(String(y.summary||"")),hint:zt(c).map(function(b){return""+b.keys.map(f).join(" ")+" "+lt(b.words)+""}).join(""),toggle:'"}}function a(c,y,$){var i=kt(c),f=Wt(i,{},r(y,c,$)),b=St(f,o(i,c,y,!1)),O=b.indexOf(">");return{open:b.slice(0,O+1),inner:b.slice(O+1,b.length-9),warnings:i.warnings}}var l=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],p=["--_cols","--_gpad","--_track"];function h(c,y,$,i){c.__diagram&&c.__diagram.stop();var f=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),b=kt(y);if(!$||!f||!c.querySelector(":scope > .diagram-drawing")){if(!f||!c.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var O=a(y,f,i),_=document.createElement("div");_.innerHTML=O.open+"";var B=_.firstChild;l.forEach(function(H){c.removeAttribute(H)}),p.forEach(function(H){c.style.removeProperty(H)});for(var j=0;j :not(script[data-diagram])").forEach(function(H){H.remove()}),c.insertAdjacentHTML("beforeend",O.inner)}b.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var Q=r(f,y,i),A={},V=null,v=null,D=null,L=Object.create(null),x=function(H){L[H]||(L[H]=1,console.warn("Basalt diagram: "+H))},d=function(H){de(c,Wt(b,H,Q))},m=c.querySelector(".diagram-ink"),S=c.querySelector(".diagram-toggle"),E=!i&&b.motion.animated&&typeof e.diagramMotion=="function",z=null,T=null,G=function(){E&&ie(c)};function N(){Xe(c,n,V&&V.geo,V&&V.tokens,f,v||D)}function k(){S&&(S.setAttribute("aria-expanded",String(!!A.open)),S.firstElementChild.textContent=A.open?"Hide the list":"View as list")}function C(){V=(i?i.measure:re)(c,b,n,f,A,d,x),A=V.dyn,d(A),k(),gt(b,A)||(D=null);var H=m&&V.ink!==T;H&&(m.innerHTML=V.ink,T=V.ink),N(),E&&V.tokens&&(Qe(c,!!(V.geo&&V.geo.lines.length)),H&&z&&z.redrawn()),i&&i.onMeasured&&V.tokens&&i.onMeasured(V,c)}function q(H){A=H,d(A)}function M(H){var st=A.stop;A=Object.assign({},A,{stop:H}),on(c,n,st,H)}var I=function(H){var st=H&&H.closest?H.closest(".diagram-node"):null;return st&&c.contains(st)?st:null};function F(H){var st=I(H.target);if(!(!st||H.defaultPrevented)){if(G(),H.key==="Escape"){!i&&(v||D)&&(H.preventDefault(),v=D=null,N());return}if(gt(b,A)){var ut=Pe(b,st.getAttribute("data-node"),H.key);if(ut){H.preventDefault(),M(ut);var ue=c.querySelector('.diagram-node[data-node="'+CSS.escape(ut)+'"]');ue&&ue.focus()}}}}function Z(H){var st=I(H.target);if(st){G();var ut=st.getAttribute("data-node");v=st.matches(":focus-visible")?ut:null,gt(b,A)&&A.stop!==ut&&M(ut),N()}}function P(H){var st=I(H.target);st&&(I(H.relatedTarget)||(v=null),A.keep===st.getAttribute("data-node")&&q(Object.assign({},A,{keep:void 0})),N())}function X(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var st=I(H.target);st&&G();var ut=st&>(b,A)?st.getAttribute("data-node"):null;ut!==D&&(D=ut,N())}}function W(){D&&(D=null,N())}function K(){G(),q(Object.assign({},A,{open:!A.open,autoOpen:void 0})),k()}c.addEventListener("keydown",F),c.addEventListener("focusin",Z),c.addEventListener("focusout",P),c.addEventListener("pointerover",X),c.addEventListener("pointerleave",W),S&&S.addEventListener("click",K),C();var ot=c.clientWidth,tt=0,J=!0,et=new ResizeObserver(function(){Math.abs(c.clientWidth-ot)<.5||(ot=c.clientWidth,cancelAnimationFrame(tt),tt=requestAnimationFrame(C))});et.observe(c),document.fonts&&document.fonts.ready.then(function(){J&&C()});var U=matchMedia("(forced-colors: active)"),nt=b.nodes.some(function(H){return H.mark});nt&&U.addEventListener("change",C),E&&(z=e.diagramMotion(c,{fig:c,P:n,base:f,model:function(){return b},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},y));var at=!i&&y.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,y,{model:b,settle:G,animated:E}):null;c.__diagram={stop:function(){at&&at.destroy(),J=!1,et.disconnect(),cancelAnimationFrame(tt),nt&&U.removeEventListener("change",C),z&&z.destroy(),c.removeEventListener("keydown",F),c.removeEventListener("focusin",Z),c.removeEventListener("focusout",P),c.removeEventListener("pointerover",X),c.removeEventListener("pointerleave",W),S&&S.removeEventListener("click",K)},layout:C,key:u(y),send:z&&z.sendValue?z.sendValue:null}}function u(c){try{return JSON.stringify(c,function(y,$){return y==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var y=c.querySelector(":scope > script[data-diagram]");if(y)try{h(c,JSON.parse(y.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:h,buildModel:kt,figureKey:Se,figureList:_e,hintEntries:zt,toHtml:St,escapeHtml:lt,settleEntrance:ie,measureFigure:re},t.diagram=function(c,y){var $=c.__diagram,i=$&&$.send?u(y):null;if(i!==null&&i===$.key){$.send(y.packet?y.packet.send:void 0);return}h(c,y)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 5cb4c986..7cb2b198 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -165,7 +165,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti setInk(result.ink); // A layout with no stops traces nothing: a pointer resting on a node as the figure narrows into one leaves no trace behind. if (!hasStops(model, result.dyn)) setHoverTrace(null); - if (viewer) viewer.onMeasured(result, fig); + // A figure hidden (the viewer's list is open) was not measured: the viewer keeps the drawing's size and place it had. + if (viewer && result.tokens) viewer.onMeasured(result, fig); }, [model, base, options, component, viewer]); // Measured before the first paint, then whenever the figure's width changes or the real faces arrive. diff --git a/packages/react/src/diagram-viewer.tsx b/packages/react/src/diagram-viewer.tsx index 0309b5be..b930f048 100644 --- a/packages/react/src/diagram-viewer.tsx +++ b/packages/react/src/diagram-viewer.tsx @@ -107,6 +107,9 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o zoomRef.current?.size(fig.offsetWidth, fig.offsetHeight); }, []); const memo = React.useRef({}); + // The figure is laid out as the dialog opens, through its scale from .98; once the entrance has ended it is laid out again, unscaled, so its lines + // snap on the pixel grid they are drawn on. + const [settled, setSettled] = React.useState(0); const viewer = React.useMemo(() => { const layer = layerRef.current; if (!(avail > 0) || !layer) return undefined; @@ -115,7 +118,7 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o onMeasured, measure: (fig, m, p, base, current, apply, warn) => measureViewerFigure(fig, m, p, base, current, apply, warn, { layer, avail, row: dims.row, contain: dims.contain, memo: memo.current, measureFigure }), }; - }, [avail, dims, onMeasured, measureFigure]); + }, [avail, dims, onMeasured, measureFigure, settled]); // A stack with no lines has its list open, as on the page (9.3). const showList = listOpen || Boolean(layout.bare); @@ -166,11 +169,13 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o const first = all[0]!, last = all[all.length - 1]!, at = document.activeElement; if (e.shiftKey && (at === first || at === d)) { e.preventDefault(); last.focus(); } else if (!e.shiftKey && at === last) { e.preventDefault(); first.focus(); } }; + const onEntered = (e: TransitionEvent) => { if (e.target === d && e.propertyName === "transform" && d.open && !closing.current) setSettled((n) => n + 1); }; + d.addEventListener("transitionend", onEntered); d.addEventListener("close", onClose); d.addEventListener("pointerdown", onDown); d.addEventListener("click", onClick); d.addEventListener("keydown", onKey); - return () => { clearTimeout(timer); d.removeEventListener("close", onClose); d.removeEventListener("pointerdown", onDown); d.removeEventListener("click", onClick); d.removeEventListener("keydown", onKey); if (d.open) d.close(); }; + return () => { clearTimeout(timer); d.removeEventListener("transitionend", onEntered); d.removeEventListener("close", onClose); d.removeEventListener("pointerdown", onDown); d.removeEventListener("click", onClick); d.removeEventListener("keydown", onKey); if (d.open) d.close(); }; }, [opener, close]); return createPortal( @@ -206,7 +211,7 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o
{layout.bare ? null : ( - )} diff --git a/packages/react/src/diagram-zoom-core.ts b/packages/react/src/diagram-zoom-core.ts index eee1eaad..aa3c73f1 100644 --- a/packages/react/src/diagram-zoom-core.ts +++ b/packages/react/src/diagram-zoom-core.ts @@ -167,6 +167,7 @@ export function attachZoom(host: ZoomHost): ZoomController { } function size(width: number, height: number) { + if (!width || !height) return; const keep = touched && W && H ? contentAt(middle()) : null; W = width; H = height; @@ -363,7 +364,13 @@ export function measureViewerFigure(fig: HTMLElement, m: Model, P: string, base: layer.style.transform = "none"; // A dialog still opening is scaled (from .98): the layer is scaled by the inverse while it is measured, so what is read is 100% whatever its ancestors do. const ancestors = layer.offsetWidth ? layer.getBoundingClientRect().width / layer.offsetWidth : 1; - if (Math.abs(ancestors - 1) > 1e-4) layer.style.transform = `scale(${1 / ancestors})`; + const unscale = Math.abs(ancestors - 1) > 1e-4 ? ` scale(${1 / ancestors})` : ""; + layer.style.transform = unscale || "none"; + // The engine snaps lines to the page's pixel grid from the drawing's origin. The layer sits wherever the stage centres it, so it is moved to the + // nearest whole pixel while it is measured (its drawing's origin): the ink is then the string a page drawing on whole pixels draws, whatever the zoom or the stage's size. + const r = (fig.querySelector(`.${P}-drawing`) ?? layer).getBoundingClientRect(); + const fx = r.left - Math.round(r.left), fy = r.top - Math.round(r.top); + if (fx || fy) layer.style.transform = `translate(${-fx / ancestors}px, ${-fy / ancestors}px)${unscale}`; // Before the least drawn width is known, a refusal at the token sum is expected and is not the author's to fix: it says nothing. let result = measureFigure(fig, m, P, base, current, apply, memo.least === undefined ? undefined : warn, sizeTo); // The least drawn width is the first width the engine draws the figure at, which the token sum can undercount (a sequence's columns are measured, a diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 87146911..8408a5c9 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4997,7 +4997,8 @@ } /* The viewer and its scrim do not print: the page prints its own figure, untraced and light. "Expand" does not print. */ @media print { - .basalt-diagram-expand, .basalt-diagram-viewer { display: none !important; } + /* With no transition: a display transition (the dialog's own, allow-discrete) would hold it on screen past the change. */ + .basalt-diagram-expand, .basalt-diagram-viewer { display: none !important; transition: none !important; } } /* ---- Diagram viewer, React's dialog (DECISIONS 310): the form dialog's box on a native modal , as the HTML skill's is ---- diff --git a/packages/react/test/diagram-viewer.test.mjs b/packages/react/test/diagram-viewer.test.mjs new file mode 100644 index 00000000..aceca0ba --- /dev/null +++ b/packages/react/test/diagram-viewer.test.mjs @@ -0,0 +1,531 @@ +// The diagram viewer (DECISIONS 301, part 9, as DECISIONS 310; section 8's list for diagram-viewer.test.mjs): "Expand", the dialog, the layout width, Fit, +// the steps, what holds still, the keys, pan, the ink at every level, sharpness, the status line, focus, the trace, the list and print. In Chromium against +// the built package. The implementation hasn't been reviewed; part 9 had no draft, check or position. +import assert from "node:assert/strict"; +import fs from "node:fs"; +import { createRequire } from "node:module"; +import path from "node:path"; +import { after, before, describe, test } from "node:test"; + +import { fixturePage, launch, pixels, pkg } from "./support.mjs"; + +const require = createRequire(import.meta.url); +const { renderToString } = require("react-dom/server"); +const axeSource = fs.readFileSync(require.resolve("axe-core/axe.min.js"), "utf8"); +const DATA = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams.json"), "utf8")); +const KEYS = Object.keys(DATA); +const P = "basalt-diagram"; +const font = (file) => fs.readFileSync(path.join(pkg, "dist", "fonts", file)).toString("base64"); +const FONTS = `@font-face{font-family:"Geist";src:url(data:font/woff2;base64,${font("Geist-Variable.woff2")}) format("woff2");font-weight:100 900}@font-face{font-family:"Geist Mono";src:url(data:font/woff2;base64,${font("GeistMono-Variable.woff2")}) format("woff2");font-weight:100 900}`; +const PAGE = `${FONTS} body{background:var(--basalt-surface-page);margin:0;padding:16px;box-sizing:border-box} #root{max-width:1104px;margin:0 auto}`; +// The layout widths of 9.12 (proof/zoom/fit.json), with the flowchart's least drawn width at 976 after call 1 of section 4. +const LAYOUT = { architecture: 784, flowchart: 976, dataFlow: 1080, sequence: 807, schema: 1056 }; +const LADDER = [25, 33, 50, 67, 75, 100, 125, 150, 200, 300, 400]; + +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +// The host: the five CIMIP figures (or `window.__set(list)`), each with the id `fig-`; `zoom` and `motion` per figure from the list. +const HOST = ` +import data from "./test/fixtures/cimip-diagrams.json"; +const C = { architecture: B.ArchitectureDiagram, flowchart: B.FlowchartDiagram, "data-flow": B.DataFlowDiagram, sequence: B.SequenceDiagram, schema: B.SchemaDiagram }; +const all = () => Object.entries(data).map(([key, d]) => { const { type, ...props } = d; return { key, type, props }; }); +function Host() { + const [list, setList] = React.useState(all); + window.__set = (next) => flushSync(() => setList(next)); + return
{list.map(({ key, type, props }) => { const X = C[type]; return ; })}
; +} +createRoot(document.getElementById("root")).render();`; + +const frames = (page, n = 3) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); + +async function viewerPage({ theme = "dark", width = 1440, height = 900, touch = false, scale = 1, media } = {}) { + const { page, errors } = await fixturePage(browser, HOST, { theme, standards: true, viewport: { width, height }, deviceScaleFactor: scale, hasTouch: touch, isMobile: touch }); + if (touch) await page.evaluate(() => { const meta = document.createElement("meta"); meta.name = "viewport"; meta.content = "width=device-width, initial-scale=1"; document.head.append(meta); }); + if (media) await page.emulateMedia(media); + await page.addStyleTag({ content: PAGE }); + await page.evaluate(() => document.fonts.ready); + await frames(page, 4); + return { page, errors }; +} + +/** Opens a figure's viewer and waits until its figure is laid out and the dialog has finished its entrance. */ +async function open(page, key, { tap = false } = {}) { + const button = page.locator(`#fig-${key} .${P}-expand`); + await button.scrollIntoViewIfNeeded(); + if (tap) await button.tap(); else await button.click(); + await page.waitForSelector(`dialog.${P}-viewer[open] .${P}[data-layout]`); + await page.evaluate(() => Promise.all(document.getAnimations().map((a) => a.finished.catch(() => {})))); + await frames(page, 3); +} +const state = (page) => page.evaluate((P) => { + const d = document.querySelector(`dialog.${P}-viewer`); + const stage = d.querySelector(`.${P}-stage`); + const layer = d.querySelector(`.${P}-layer`); + const fig = layer.querySelector(`.${P}`); + const sizer = d.querySelector(`.${P}-sizer`); + const pad = parseFloat(getComputedStyle(sizer).paddingTop); + const m = /scale\(([\d.]+)\)/.exec(layer.style.transform); + return { + level: d.querySelector(`.${P}-level > span`).textContent, + zoom: m ? Number(m[1]) : 1, + width: fig.offsetWidth, height: fig.offsetHeight, layout: fig.getAttribute("data-layout"), + stage: { w: stage.clientWidth, h: stage.clientHeight, left: stage.scrollLeft, top: stage.scrollTop }, pad, + dialog: d.getBoundingClientRect().toJSON(), radius: getComputedStyle(d).borderTopLeftRadius, + shadow: getComputedStyle(d).boxShadow, border: getComputedStyle(d).borderTopWidth, + }; +}, P); +const levelOf = async (page) => Number((await page.locator(`.${P}-level > span`).textContent()).replace("%", "")); + +describe("the button", () => { + test("Expand follows View as list in every figure's foot, in words; zoom: false leaves it out; the server's HTML has none", async () => { + const { page, errors } = await viewerPage(); + for (const key of KEYS) { + const foot = await page.locator(`#fig-${key} .${P}-foot > button`).evaluateAll((els) => els.map((e) => [e.className, e.textContent, e.getAttribute("aria-haspopup")])); + assert.ok(foot[0][0].includes(`${P}-toggle`), `${key}: View as list is first`); + assert.ok(foot[1][0].includes(`${P}-expand`) && foot[1][1] === "Expand" && foot[1][2] === "dialog", `${key}: Expand is second, with its words`); + } + await page.evaluate((data) => window.__set([{ key: "schema", type: "schema", props: { ...(({ type, ...p }) => p)(data.schema), zoom: false } }]), DATA); + await frames(page); + assert.equal(await page.locator(`.${P}-expand`).count(), 0); + assert.deepEqual(errors, []); + await page.close(); + // Before script: the server's markup has no Expand. + const B = await import(path.join(pkg, "dist", "index.js")); + const React = require("react"); + const { type, ...props } = DATA.architecture; + const html = renderToString(React.createElement(B.ArchitectureDiagram, props)); + assert.ok(!html.includes(`${P}-expand`)); + }); + test("on touch the button is at least 44px tall", async () => { + const { page } = await viewerPage({ width: 390, height: 844, touch: true }); + const h = await page.locator(`#fig-architecture .${P}-expand`).evaluate((e) => e.getBoundingClientRect().height); + assert.ok(h >= 44, `${h}`); + await page.close(); + }); +}); + +describe("the dialog", () => { + for (const theme of ["dark", "light"]) { + test(`${theme}: at 1440 by 900 the window less 16, radius 12; Esc, Close and the scrim close it and focus returns to Expand; the page does not scroll`, async () => { + const { page, errors } = await viewerPage({ theme }); + await open(page, "architecture"); + const s = await state(page); + assert.deepEqual([Math.round(s.dialog.x), Math.round(s.dialog.y), Math.round(s.dialog.width), Math.round(s.dialog.height)], [16, 16, 1408, 868]); + assert.equal(s.radius, "12px"); + assert.equal(await page.evaluate(() => getComputedStyle(document.documentElement).overflow), "hidden"); + const y0 = await page.evaluate(() => scrollY); + await page.mouse.move(5, 450); + await page.mouse.wheel(0, 400); + await frames(page, 3); + assert.equal(await page.evaluate(() => scrollY), y0, "the page behind does not scroll"); + const isFocused = () => page.evaluate((P) => document.activeElement?.classList.contains(`${P}-expand`) && document.activeElement.closest("#fig-architecture") !== null, P); + await page.keyboard.press("Escape"); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.ok(await isFocused(), "Esc returns focus to Expand"); + await open(page, "architecture"); + await page.locator(`dialog.${P}-viewer .basalt-sheet-close`).click(); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.ok(await isFocused(), "Close returns focus to Expand"); + await open(page, "architecture"); + await page.mouse.click(5, 450); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.ok(await isFocused(), "the scrim returns focus to Expand"); + assert.deepEqual(errors, []); + await page.close(); + }); + } + test("at 390 by 844 it is the whole window, with no radius, rim or shadow", async () => { + const { page } = await viewerPage({ width: 390, height: 844, touch: true }); + await open(page, "schema", { tap: true }); + const s = await state(page); + assert.deepEqual([Math.round(s.dialog.x), Math.round(s.dialog.y), Math.round(s.dialog.width), Math.round(s.dialog.height)], [0, 0, 390, 844]); + assert.equal(s.radius, "0px"); + assert.equal(s.shadow, "none"); + assert.equal(s.border, "0px"); + await page.close(); + }); +}); + +describe("the layout width and Fit", () => { + for (const [w, h] of [[390, 844], [1440, 900], [1920, 1080]]) { + test(`at ${w} by ${h}: each CIMIP figure is drawn at its layout width and opens at Fit, the whole drawing in the stage's padding and 1% more would not be, never over 200%`, async () => { + const { page, errors } = await viewerPage({ width: w, height: h, touch: w < 720 }); + for (const key of KEYS) { + await open(page, key, { tap: w < 720 }); + const s = await state(page); + assert.equal(s.layout, "drawn", `${key} at ${w}`); + assert.equal(s.width, w < 720 ? LAYOUT[key] : 1104, `${key} at ${w}: the layout width`); + const fit = Math.min(2, Math.floor(Math.min((s.stage.w - 2 * s.pad) / s.width, (s.stage.h - 2 * s.pad) / s.height) * 100 + 1e-6) / 100); + assert.ok(Math.abs(s.zoom - fit) < 1e-6, `${key} at ${w}: opens at ${s.zoom}, Fit is ${fit}`); + assert.ok(s.width * s.zoom <= s.stage.w - 2 * s.pad + 0.01 && s.height * s.zoom <= s.stage.h - 2 * s.pad + 0.01, `${key} at ${w}: inside the padding`); + if (fit < 2) assert.ok(s.width * (fit + 0.01) > s.stage.w - 2 * s.pad || s.height * (fit + 0.01) > s.stage.h - 2 * s.pad, `${key} at ${w}: 1% more would not fit`); + // The limits: Fit or 100%, whichever is less, and 400%. + for (let i = 0; i < 14; i++) await page.locator(`dialog.${P}-viewer button[aria-label="Zoom out"]`).click({ force: true }); + assert.equal(await levelOf(page), Math.round(Math.min(fit, 1) * 100), `${key} at ${w}: the lower limit`); + for (let i = 0; i < 14; i++) await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).click({ force: true }); + assert.equal(await levelOf(page), 400); + if (w < 720) await page.locator(`dialog.${P}-viewer .basalt-sheet-close`).tap(); else await page.keyboard.press("Escape"); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + } + assert.deepEqual(errors, []); + await page.close(); + }); + } + test("a figure with no drawn layout holds its stack, and a stack with no lines has its list open", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + // Two cards whose one line would pass through a third: every drawn layout is refused, and the stack draws no lines. + await page.evaluate(() => window.__set([{ key: "bad", type: "architecture", props: { title: "Refused", summary: "A figure with no drawn layout.", legend: { plain: "Call" }, + nodes: [{ id: "a", name: "A", col: 1, row: 1 }, { id: "b", name: "B", col: 2, row: 1 }, { id: "c", name: "C", col: 3, row: 1 }], + edges: [{ from: "a", to: "c", fromSide: "right", toSide: "left", kind: "plain" }] } }])); + await frames(page); + const pageLayout = await page.locator("#fig-bad").getAttribute("data-layout"); + await open(page, "bad"); + const s = await state(page); + assert.equal(s.layout, pageLayout === "drawn" ? "drawn" : "stacked"); + await page.close(); + }); +}); + +describe("zoom", () => { + test("from each ladder value Zoom in and Zoom out land on the next; a button at a limit is aria-disabled, mounted and focused; Fit is disabled at Fit; the level never moves the buttons", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + await open(page, "schema"); + const zin = page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`); + const zout = page.locator(`dialog.${P}-viewer button[aria-label="Zoom out"]`); + const fit = page.locator(`dialog.${P}-viewer .${P}-fit`); + assert.equal(await fit.getAttribute("aria-disabled"), "true"); + const x0 = await zin.evaluate((e) => e.getBoundingClientRect().x); + const fitLevel = await levelOf(page); + let at = fitLevel; + while (at < 400) { + await zin.focus(); + await page.keyboard.press("Enter"); + const next = await levelOf(page); + assert.equal(next, LADDER.find((v) => v > at + 0.5), `in from ${at}`); + assert.equal(await zin.evaluate((e) => e.getBoundingClientRect().x), x0, `the level ${next}% moved the button`); + at = next; + } + assert.equal(await zin.getAttribute("aria-disabled"), "true"); + assert.ok(await zin.evaluate((e) => document.activeElement === e), "a button at its limit keeps focus"); + while (at > Math.min(fitLevel, 100)) { + await zout.click(); + const next = await levelOf(page); + const want = [...LADDER].reverse().find((v) => v < at - 0.5); + assert.equal(next, want === undefined || want < Math.min(fitLevel, 100) ? Math.min(fitLevel, 100) : want, `out from ${at}`); + at = next; + } + assert.equal(await zout.getAttribute("aria-disabled"), "true"); + await page.close(); + }); + + test("a step lands in one frame: the layer has no transition or animation, with and without reduced motion", async () => { + for (const reducedMotion of ["no-preference", "reduce"]) { + const { page } = await viewerPage({ media: { reducedMotion } }); + await open(page, "architecture"); + const layer = page.locator(`dialog.${P}-viewer .${P}-layer`); + assert.equal(await layer.evaluate((e) => getComputedStyle(e).transitionDuration), "0s"); + await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).click(); + assert.equal(await layer.evaluate((e) => e.getAnimations({ subtree: true }).length), 0); + await page.close(); + } + }); + + test("what holds still: the stage's middle under a button and a key, the pointer under Ctrl and the wheel, within a pixel", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + await open(page, "schema"); + // A drawing point at the stage's middle, and where it is after a step. + const at = (cx, cy) => page.evaluate(([P, cx, cy]) => { + const layer = document.querySelector(`dialog.${P}-viewer .${P}-layer`); + const r = layer.getBoundingClientRect(); + const z = Number(/scale\(([\d.]+)\)/.exec(layer.style.transform)?.[1] ?? 1); + return { x: (cx - r.left) / z, y: (cy - r.top) / z }; + }, [P, cx, cy]); + const middle = await page.locator(`dialog.${P}-viewer .${P}-stage`).evaluate((s) => { const r = s.getBoundingClientRect(); return { x: r.left + s.clientWidth / 2, y: r.top + s.clientHeight / 2 }; }); + await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).click(); + await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).click(); + const before = await at(middle.x, middle.y); + await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).click(); + let after = await at(middle.x, middle.y); + assert.ok(Math.abs(before.x - after.x) <= 1 && Math.abs(before.y - after.y) <= 1, `button: ${JSON.stringify([before, after])}`); + await page.locator(`dialog.${P}-viewer .${P}-stage`).focus(); + const k0 = await at(middle.x, middle.y); + await page.keyboard.press("="); + after = await at(middle.x, middle.y); + assert.ok(Math.abs(k0.x - after.x) <= 1 && Math.abs(k0.y - after.y) <= 1, "key"); + const pointer = { x: middle.x - 300, y: middle.y - 120 }; + await page.mouse.move(pointer.x, pointer.y); + const w0 = await at(pointer.x, pointer.y); + const l0 = await levelOf(page); + await page.keyboard.down("Control"); + await page.mouse.wheel(0, 20); + await page.keyboard.up("Control"); + await frames(page); + const w1 = await at(pointer.x, pointer.y); + assert.ok((await levelOf(page)) < l0, "Ctrl and the wheel zoom out"); + assert.ok(Math.abs(w0.x - w1.x) <= 1 && Math.abs(w0.y - w1.y) <= 1, `wheel: ${JSON.stringify([w0, w1])}`); + await page.close(); + }); + + test("a pinch zooms about the midpoint of two fingers, by the ratio of their spread", async () => { + const { page } = await viewerPage({ width: 390, height: 844, touch: true, scale: 1 }); + await open(page, "architecture", { tap: true }); + const z0 = (await state(page)).zoom; + const box = await page.locator(`dialog.${P}-viewer .${P}-stage`).boundingBox(); + const cx = box.x + box.width / 2, cy = box.y + box.height / 2; + const at = () => page.evaluate(([P, cx, cy]) => { const layer = document.querySelector(`dialog.${P}-viewer .${P}-layer`); const r = layer.getBoundingClientRect(); const z = Number(/scale\(([\d.]+)\)/.exec(layer.style.transform)?.[1] ?? 1); return { x: (cx - r.left) / z, y: (cy - r.top) / z }; }, [P, cx, cy]); + const p0 = await at(); + const cdp = await page.context().newCDPSession(page); + const pts = (d) => [{ x: cx - d, y: cy, id: 1 }, { x: cx + d, y: cy, id: 2 }]; + await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: pts(20) }); + for (let d = 22; d <= 40; d += 2) await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: pts(d) }); + await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] }); + await frames(page); + const z1 = (await state(page)).zoom; + assert.ok(Math.abs(z1 - Math.min(4, z0 * 2)) < 0.02, `${z0} -> ${z1}`); + const p1 = await at(); + assert.ok(Math.abs(p0.x - p1.x) <= 1 && Math.abs(p0.y - p1.y) <= 1, `${JSON.stringify([p0, p1])}`); + await page.close(); + }); + + test("keys: + = - and 0 work with focus on the stage or a card and do nothing on a button; the arrows move between cards and bring the card into view", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + await open(page, "architecture"); + const fitLevel = await levelOf(page); + assert.ok(await page.evaluate((P) => document.activeElement?.classList.contains(`${P}-stage`), P), "focus opens on the stage"); + await page.keyboard.press("+"); + assert.ok((await levelOf(page)) > fitLevel); + await page.keyboard.press("0"); + assert.equal(await levelOf(page), fitLevel); + await page.keyboard.press("Tab"); + assert.ok(await page.evaluate((P) => Boolean(document.activeElement?.closest(`dialog .${P}-node`)), P), "the roving stop is after the stage"); + await page.keyboard.press("="); + const zoomed = await levelOf(page); + assert.ok(zoomed > fitLevel); + await page.keyboard.press("-"); + assert.ok((await levelOf(page)) < zoomed); + for (let i = 0; i < 4; i++) await page.keyboard.press("="); + for (let i = 0; i < 5; i++) await page.keyboard.press("ArrowRight"); + const seen = await page.evaluate((P) => { const s = document.querySelector(`dialog .${P}-stage`); const n = document.activeElement.getBoundingClientRect(); const r = s.getBoundingClientRect(); return n.left >= r.left && n.right <= r.left + s.clientWidth && n.top >= r.top && n.bottom <= r.top + s.clientHeight; }, P); + assert.ok(seen, "the focused card is in view"); + await page.locator(`dialog.${P}-viewer .${P}-fit`).focus(); + const l = await levelOf(page); + await page.keyboard.press("="); + assert.equal(await levelOf(page), l, "a key on a button does nothing"); + await page.close(); + }); +}); + +describe("pan", () => { + test("a drag past 4px scrolls the stage one for one and selects nothing; a press that does not travel is a click; the plain wheel scrolls; nothing continues after the pointer lifts", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + await open(page, "schema"); + for (let i = 0; i < 3; i++) await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).click(); + const s0 = (await state(page)).stage; + const box = await page.locator(`dialog.${P}-viewer .${P}-stage`).boundingBox(); + const x = box.x + box.width / 2, y = box.y + box.height / 2; + await page.mouse.move(x, y); + await page.mouse.down(); + await page.mouse.move(x - 100, y - 60, { steps: 10 }); + await page.mouse.up(); + const s1 = (await state(page)).stage; + assert.equal(s1.left - s0.left, 100); + assert.equal(s1.top - s0.top, 60); + assert.equal(await page.evaluate(() => String(getSelection())), ""); + await frames(page, 5); + assert.deepEqual((await state(page)).stage, s1, "no momentum"); + await page.mouse.wheel(0, 80); + await frames(page); + assert.ok((await state(page)).stage.top > s1.top, "the plain wheel scrolls"); + // A press that does not travel is a click: hovering traces, and a click on a card focuses nothing new but does not pan. + const s2 = (await state(page)).stage; + await page.mouse.click(x, y); + assert.deepEqual((await state(page)).stage, s2); + await page.close(); + }); + test("on touch one finger pans the stage", async () => { + const { page } = await viewerPage({ width: 390, height: 844, touch: true }); + await open(page, "schema", { tap: true }); + await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).tap(); + await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).tap(); + const s0 = (await state(page)).stage; + const box = await page.locator(`dialog.${P}-viewer .${P}-stage`).boundingBox(); + const cdp = await page.context().newCDPSession(page); + const cx = box.x + box.width / 2, cy = box.y + box.height / 2; + await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x: cx, y: cy, id: 1 }] }); + for (let k = 1; k <= 10; k++) await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x: cx - 4 * k, y: cy - 3 * k, id: 1 }] }); + await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] }); + const s1 = (await state(page)).stage; + assert.equal(s1.left - s0.left, 40, JSON.stringify([s0, s1])); + await page.close(); + }); +}); + +describe("the ink", () => { + test("is the same string at every level and the page figure's at that width; a resize and the fonts arriving while zoomed leave it a fresh layout's", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + const pageInk = await page.locator(`#fig-schema .${P}-ink`).innerHTML(); + await open(page, "schema"); + const ink = () => page.locator(`dialog.${P}-viewer .${P}-ink`).innerHTML(); + const normalise = (s) => s.replace(/dg[\w-]+?-/g, "ID-"); + const first = await ink(); + // The page's drawing snaps from its own origin: where that origin is on whole pixels the strings are equal; otherwise every number is within the + // half pixel of a snap. + const whole = await page.locator(`#fig-schema .${P}-drawing`).evaluate((d) => { const r = d.getBoundingClientRect(); return Number.isInteger(r.left) && Number.isInteger(r.top); }); + if (whole) assert.equal(normalise(first), normalise(pageInk), "the viewer's ink is the page's at 1104"); + else { + const nums = (s) => normalise(s).match(/-?\d+(\.\d+)?/g).map(Number); + const [a, b] = [nums(first), nums(pageInk)]; + assert.equal(a.length, b.length); + assert.ok(a.every((v, k) => Math.abs(v - b[k]) <= 1), "the viewer's ink is the page's at 1104, within a snap"); + } + for (let i = 0; i < 6; i++) { + await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).click(); + assert.equal(await ink(), first, `at ${await levelOf(page)}%`); + } + await page.evaluate(async () => { document.fonts.dispatchEvent?.(new Event("loadingdone")); }); + await page.setViewportSize({ width: 1400, height: 900 }); + await frames(page, 4); + assert.equal(normalise(await ink()), normalise(first), "a resize while zoomed keeps a fresh layout's ink"); + await page.close(); + }); + + for (const theme of ["dark", "light"]) { + test(`${theme}: sharpness: a region of the layer at 300% on a 1x screen equals the same region at 100% on a 3x screen; no will-change, viewBox scaling, zoom, canvas or image`, async () => { + for (const key of ["schema", "architecture"]) { + const a = await viewerPage({ theme, width: 1440, height: 900, scale: 1 }); + await open(a.page, key); + await a.page.locator(`dialog.${P}-viewer .${P}-stage`).focus(); + // From Fit, step to 300% with the keys, then read a region the zoom shows from the layer's top start. + for (let i = 0; i < 12 && (await levelOf(a.page)) < 300; i++) await a.page.keyboard.press("="); + assert.equal(await levelOf(a.page), 300); + await a.page.locator(`dialog.${P}-viewer .${P}-stage`).evaluate((s) => { s.scrollLeft = 0; s.scrollTop = 0; }); + const layerBox = await a.page.locator(`dialog.${P}-viewer .${P}-layer`).boundingBox(); + const clip = { x: Math.round(layerBox.x), y: Math.round(layerBox.y), width: 600, height: 300 }; + const big = await pixels(a.page, clip); + const props = await a.page.locator(`dialog.${P}-viewer .${P}-layer`).evaluate((l) => ({ will: getComputedStyle(l).willChange, zoom: getComputedStyle(l).zoom, canvas: l.querySelectorAll("canvas, img:not(.basalt-diagram-mark img)").length, views: [...l.querySelectorAll("svg[viewBox]")].filter((s) => { const v = s.getAttribute("viewBox").split(/\s+/).map(Number); return Math.abs(v[2] - s.width.baseVal.value) > 0.5 || Math.abs(v[3] - s.height.baseVal.value) > 0.5; }).length })); + assert.equal(props.will, "auto"); + assert.equal(props.zoom, "1"); + assert.equal(props.canvas, 0); + assert.equal(props.views, 0); + await a.page.close(); + const b = await viewerPage({ theme, width: 1440, height: 900, scale: 3 }); + await open(b.page, key); + await b.page.locator(`dialog.${P}-viewer .${P}-stage`).focus(); + for (let i = 0; i < 12 && (await levelOf(b.page)) > 100; i++) await b.page.keyboard.press("-"); + for (let i = 0; i < 12 && (await levelOf(b.page)) < 100; i++) await b.page.keyboard.press("="); + assert.equal(await levelOf(b.page), 100); + await b.page.locator(`dialog.${P}-viewer .${P}-stage`).evaluate((s) => { s.scrollLeft = 0; s.scrollTop = 0; }); + const lb = await b.page.locator(`dialog.${P}-viewer .${P}-layer`).boundingBox(); + const small = await pixels(b.page, { x: lb.x, y: lb.y, width: 200, height: 100 }); + assert.equal(big.length, small.length); + let differ = 0; + for (let i = 0; i < big.length; i++) if (big[i].some((c, k) => Math.abs(c - small[i][k]) > 8)) differ++; + assert.ok(differ / big.length < 0.01, `${key}: ${differ} of ${big.length} pixels differ`); + await b.page.close(); + } + }); + } +}); + +describe("speech, focus and the trace", () => { + test("the status line says the level once, duration-slower after the last change; a pinch of twenty moves is spoken once", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + await open(page, "architecture"); + await page.evaluate((P) => { const s = document.querySelector(`dialog.${P}-viewer [role="status"]`); window.__said = []; new MutationObserver(() => window.__said.push(s.textContent)).observe(s, { childList: true, characterData: true, subtree: true }); }, P); + assert.equal(await page.locator(`dialog.${P}-viewer [role="status"]`).textContent(), "", "opening says nothing"); + await page.locator(`dialog.${P}-viewer .${P}-stage`).focus(); + for (let i = 0; i < 3; i++) await page.keyboard.press("="); + await page.waitForTimeout(150); + assert.deepEqual(await page.evaluate(() => window.__said), [], "nothing while it changes"); + await page.waitForTimeout(400); + const said = await page.evaluate(() => window.__said); + assert.equal(said.length, 1); + assert.equal(said[0], `Zoom ${await levelOf(page)}%`); + await page.close(); + }); + + for (const theme of ["dark", "light"]) { + test(`${theme}: focus opens on the stage with an inset ring; the order is Close, the stage, the roving stop, the foot; axe passes at Fit and at 400%`, async () => { + const { page } = await viewerPage({ theme, width: 1440, height: 900 }); + await open(page, "architecture"); + await page.keyboard.press("Shift+Tab"); + await page.keyboard.press("Tab"); + const ring = await page.locator(`dialog.${P}-viewer .${P}-stage`).evaluate((s) => [document.activeElement === s, getComputedStyle(s).outlineOffset, getComputedStyle(s).outlineWidth]); + assert.deepEqual(ring, [true, "-2px", "2px"]); + await page.keyboard.press("Shift+Tab"); + assert.equal(await page.evaluate(() => document.activeElement?.getAttribute("aria-label")), "Close"); + await page.keyboard.press("Tab"); + await page.keyboard.press("Tab"); + assert.ok(await page.evaluate((P) => Boolean(document.activeElement?.closest(`.${P}-node`)), P)); + await page.keyboard.press("Tab"); + assert.equal(await page.evaluate(() => document.activeElement?.getAttribute("aria-label")), "Zoom out"); + await page.evaluate(() => { document.title = "Basalt"; document.documentElement.lang = "en"; }); + await page.addScriptTag({ content: axeSource }); + const audit = () => page.evaluate(() => window.axe.run(document.querySelector("dialog"), { runOnly: { type: "tag", values: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"] }, resultTypes: ["violations"] }).then((r) => r.violations.map((v) => `${v.id}: ${v.nodes.map((n) => n.target.join(" ")).slice(0, 3).join("; ")}`))); + assert.deepEqual(await audit(), [], "at Fit"); + await page.locator(`dialog.${P}-viewer .${P}-stage`).focus(); + for (let i = 0; i < 10; i++) await page.keyboard.press("="); + assert.deepEqual(await audit(), [], "at 400%"); + await page.close(); + }); + } + + test("a trace by hover and by focus works; there is no hint line for touch and no Clear highlight; no entrance or flow runs; the page's figure holds its loops while the viewer is open", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + await page.evaluate((data) => window.__set([{ key: "arch", type: "architecture", props: { ...(({ type, ...p }) => p)(data.architecture), motion: "animated" } }]), DATA); + await frames(page, 4); + await open(page, "arch"); + assert.ok(await page.locator("#fig-arch").evaluate((f) => f.hasAttribute("data-viewing"))); + const node = page.locator(`dialog.${P}-viewer .${P}-node`).first(); + await node.hover(); + await frames(page); + assert.ok(await page.locator(`dialog.${P}-viewer .${P}`).evaluate((f) => f.hasAttribute("data-tracing")), "hover traces"); + assert.equal(await page.locator(`dialog.${P}-viewer .${P}`).getAttribute("data-entrance"), null, "no entrance"); + assert.equal(await page.locator(`dialog.${P}-viewer .${P}-flow`).count(), 0, "no flow"); + assert.equal(await page.locator(`dialog.${P}-viewer :is(.${P}-clear, .${P}-play, .${P}-pause)`).count(), 0); + await page.keyboard.press("Escape"); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.ok(!(await page.locator("#fig-arch").evaluate((f) => f.hasAttribute("data-viewing")))); + await page.close(); + }); + + test("View as list puts the list in the stage and disables the zoom controls; Hide the list returns the drawing at its zoom and place", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + await open(page, "schema"); + for (let i = 0; i < 3; i++) await page.locator(`dialog.${P}-viewer button[aria-label="Zoom in"]`).click(); + await page.locator(`dialog.${P}-viewer .${P}-stage`).evaluate((s) => { s.scrollLeft = 120; s.scrollTop = 80; }); + const before = await state(page); + const toggle = page.locator(`dialog.${P}-viewer .${P}-toggle`); + await toggle.click(); + assert.equal(await toggle.textContent(), "Hide the list"); + assert.equal(await page.locator(`dialog.${P}-viewer .${P}-viewer-list`).isVisible(), true); + assert.equal(await page.locator(`dialog.${P}-viewer .${P}-sizer`).isVisible(), false); + for (const label of ["Zoom out", "Zoom in"]) assert.equal(await page.locator(`dialog.${P}-viewer button[aria-label="${label}"]`).getAttribute("aria-disabled"), "true"); + assert.equal(await page.locator(`dialog.${P}-viewer .${P}-stage`).evaluate((s) => getComputedStyle(s).touchAction), "pan-y"); + await toggle.click(); + const back = await state(page); + assert.equal(back.level, before.level); + assert.deepEqual([back.stage.left, back.stage.top], [before.stage.left, before.stage.top]); + await page.close(); + }); + + test("print with the viewer open: the dialog is not displayed, the page's figure is", async () => { + const { page } = await viewerPage({ width: 1440, height: 900 }); + await open(page, "architecture"); + await page.emulateMedia({ media: "print" }); + assert.equal(await page.locator(`dialog.${P}-viewer`).evaluate((d) => getComputedStyle(d).display), "none"); + assert.notEqual(await page.locator("#fig-architecture").evaluate((f) => getComputedStyle(f).display), "none"); + await page.close(); + }); + + test("forced colours: the viewer's figure draws its geometry, and the level is CanvasText", async () => { + const { page } = await viewerPage({ width: 1440, height: 900, media: { forcedColors: "active" } }); + await open(page, "architecture"); + const s = await state(page); + assert.equal(s.layout, "drawn"); + assert.equal(await page.locator(`dialog.${P}-viewer .${P}-level`).evaluate((e) => getComputedStyle(e).color), await page.evaluate(() => { const p = document.createElement("span"); p.style.color = "CanvasText"; document.body.append(p); const c = getComputedStyle(p).color; p.remove(); return c; })); + await page.close(); + }); +}); diff --git a/tools/html-skill/src/modules/diagram-zoom.js b/tools/html-skill/src/modules/diagram-zoom.js index bd1fee58..cb3fef4f 100644 --- a/tools/html-skill/src/modules/diagram-zoom.js +++ b/tools/html-skill/src/modules/diagram-zoom.js @@ -86,9 +86,11 @@ import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } fr list.innerHTML = kit.figureList('diagram', model).map(function (v) { return kit.toHtml(v); }).join(''); stage.appendChild(list); } + // The place is kept before the drawing is hidden, and given back once it shows again. + if (open) zoom.list(true); if (list) list.hidden = !open; sizer.hidden = open; - zoom.list(open); + if (!open) zoom.list(false); } toggle.addEventListener('click', function () { listOpen = !listOpen; @@ -117,6 +119,8 @@ import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } fr if (fig.__diagram) fig.__diagram.layout(); }); observer.observe(stage); + // Laid out again once the dialog's entrance has ended, unscaled, so its lines snap on the pixel grid they are drawn on. + d.addEventListener('transitionend', function (e) { if (e.target === d && e.propertyName === 'transform' && d.open && fig.__diagram) fig.__diagram.layout(); }); page.setAttribute('data-viewing', ''); if (ctx.animated) ctx.settle(); d.addEventListener('close', function () { diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index c1794ec8..ba731582 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -104,7 +104,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis retrace(); // In the frame an animated figure's lines are first drawn it is pending; after that the motion module follows a drawing that changed. if (animated && measured.tokens) { entranceDrawn(figure, Boolean(measured.geo && measured.geo.lines.length)); if (fresh && motion) motion.redrawn(); } - if (viewer && viewer.onMeasured) viewer.onMeasured(measured, figure); + if (viewer && viewer.onMeasured && measured.tokens) viewer.onMeasured(measured, figure); } function setState(next) { state = next; apply(state); } // A move of the roving stop touches the two nodes it moves between, not the whole figure. From e7e6de4d50b54b995b13cb09597c2d37655af1c8 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:20:21 -0600 Subject: [PATCH 05/62] The skill's index line for diagram-zoom, and its claimed classes Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/SKILL.md | 2 +- tools/html-skill/src/modules.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.agent/skills/basalt-html/SKILL.md b/.agent/skills/basalt-html/SKILL.md index 5c6b0580..fe994ce9 100644 --- a/.agent/skills/basalt-html/SKILL.md +++ b/.agent/skills/basalt-html/SKILL.md @@ -64,7 +64,7 @@ Markup built only at run time (a `.row` your script writes) won't be seen: add ` - **chart** `.chart`: JSON in `script[data-chart]`; `null` is a day not observed, never zero; needs a `summary`. - **diagram** `.diagram`: JSON in `script[data-diagram]`; sides only to change the default; needs a `summary`. - **diagram-motion** `"motion": "animated"`: added for you, with `loops`; a flow line needs a label; one mover a figure. -- **diagram-zoom** added for you with a diagram ("Expand", the viewer); `"zoom": false` on every figure leaves it out. +- **diagram-zoom** `.diagram`: added for you, with `dialog`; `"zoom": false` drops Expand. - **sparkline** `.sparkline`: JSON in `script[data-sparkline]`; one line, no axes or series (that is a `chart`). - **palette** `data-open-palette`, `Basalt.init({ palette })`: `keys` is an array, `['⌘', 'S']`: ⌘, ⌃ or ⌥ plus one key. - **command-list** `.command-list`: the script builds it; items are the palette's; ⌘K goes to the palette when the page has one. diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index d1571146..dccaf2f5 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -820,7 +820,6 @@ "diagram-layer", "diagram-zoom", "diagram-level", - "diagram-fit", "diagram-probe", "diagram-viewer-foot", "diagram-viewer-key", From 6b726396836ab5748eaa08ab8915ee92290d19db Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:21:56 -0600 Subject: [PATCH 06/62] Spatial arrow keys on tracks (DECISIONS 306, 1.5) Drawn, the arrows go to the nearest card in that direction by the cards' columns and rows: first a card sharing a track across the arrow, then the lowest of tracks along plus twice the tracks across; ties to fewer across, the nearer first row, then the author's order. Arrows are physical (a right-to-left figure swaps them). A figure where some card cannot be reached keeps the author's order and a development build says so; stacked, the author's order as before. The hint shows four arrows where the drawn figure has rows and columns, and the keys sentence says "the nearest part in that direction". diagram-keys.test.mjs: the five CIMIP tables equal the decision's proof, drawn. The right-to-left half fails until right to left (1.7) draws these figures; they stack under dir=rtl today. Co-Authored-By: Claude Opus 5.5 --- .../skills/basalt-html/parts/diagram-zoom.js | 2 +- .agent/skills/basalt-html/parts/diagram.js | 4 +- .agent/skills/basalt-html/parts/manifest.json | 1 - packages/react/src/diagram-core.ts | 66 ++++- packages/react/src/diagram-figure.tsx | 4 +- packages/react/src/diagram-viewer.tsx | 2 +- packages/react/test/diagram-keys.test.mjs | 95 +++++++ .../test/fixtures/diagram-spatial-cells.json | 261 ++++++++++++++++++ tools/html-skill/src/modules/diagram-zoom.js | 2 +- tools/html-skill/src/modules/diagram.js | 5 +- 10 files changed, 424 insertions(+), 18 deletions(-) create mode 100644 packages/react/test/diagram-keys.test.mjs create mode 100644 packages/react/test/fixtures/diagram-spatial-cells.json diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.js b/.agent/skills/basalt-html/parts/diagram-zoom.js index cfda377d..ad5ade32 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.js +++ b/.agent/skills/basalt-html/parts/diagram-zoom.js @@ -1 +1 @@ -(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(y=>y.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:y,layer:p,status:x}=l;let u=0,k=0,i=1,n=1,f=!1,d=!1,g=null,h="",w=0;const S=()=>Number.parseFloat(getComputedStyle(y).paddingTop)||0,T=()=>Math.min(n,1),q=t=>Math.min(j,Math.max(T(),t));function o(){if(!u||!k)return 1;const t=S(),a=e.clientWidth-2*t,b=e.clientHeight-2*t;if(a<=0||b<=0)return Math.min(1,J);const H=Math.min(a/u,b/k);return Math.min(J,Math.floor(H*100+1e-6)/100)}function s(){const t=T();return{zoom:i,level:Math.round(i*100),fit:n,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-n)e.clientWidth-2*S()+.5||k*i>e.clientHeight-2*S()+.5)}function A(){clearTimeout(w);const t=`Zoom ${Math.round(i*100)}%`;w=window.setTimeout(()=>{t!==h&&(h=t,x.textContent=t)},l.rest)}function v(){y.style.width=`${u*i}px`,y.style.height=`${k*i}px`,p.style.transform=`scale(${i})`}function I(t){const a=p.getBoundingClientRect();return{x:(t.x-a.left)/i,y:(t.y-a.top)/i}}function z(t,a){const b=p.getBoundingClientRect();e.scrollLeft+=b.left+t.x*i-a.x,e.scrollTop+=b.top+t.y*i-a.y}const m=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function _(t,a=m(),b){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){M();return}const ot=b??I(a);i=H,v(),z(ot,a),M(),A()}function L(t){f=!0;const a=i*100,b=t?G.find(H=>H>a+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,r=()=>{const[t,a]=[...c.values()];return{x:(t.x+a.x)/2,y:(t.y+a.y)/2}},E=()=>{const[t,a]=[...c.values()];return Math.hypot(t.x-a.x,t.y-a.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),c.size===1&&(O={x:t.clientX,y:t.clientY},C=O,B=!1,F=!1),c.size===2&&t.pointerType==="touch")){const a=r();$={d0:E()||1,z0:i,c:I(a)},F=!0,B=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!c.has(t.pointerId)||d)return;if(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),$&&c.size>=2){f=!0;const b=q($.z0*(E()/$.d0)),H=r();Math.abs(b-i)>1e-6&&(i=b,v(),M(),A()),z($.c,H);return}if(c.size!==1||!O||!C)return;const a={x:t.clientX,y:t.clientY};if(!B){if(Math.hypot(a.x-O.x,a.y-O.y)<=V())return;B=!0,F=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=a.x-C.x,e.scrollTop-=a.y-C.y,C=a,t.preventDefault()}function Z(t){if(c.has(t.pointerId)){if(c.delete(t.pointerId),c.size<2&&($=null),c.size===1){const[a]=[...c.values()];C=a,O=a,B=!0;return}c.size===0&&(B=!1,e.removeAttribute("data-dragging"),O=C=null)}}function P(t){F&&(F=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!u||!k)return;const t=f?I(m()):null;n=o(),f?(i=q(i),v(),t&&z(t,m())):(i=n,v()),M()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:K,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:W,state:s,list(t){t!==d&&(t?(g={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),v(),g&&(e.scrollLeft=g.left,e.scrollTop=g.top),g=null),M())},travelled:()=>F,destroy(){clearTimeout(w),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function nt(l,e,y){const p=l.getBoundingClientRect(),x=e.getBoundingClientRect(),u=p.left+y,k=p.left+l.clientWidth-y,i=p.top+y,n=p.top+l.clientHeight-y;x.leftk&&(l.scrollLeft+=Math.min(x.right-k,x.left-u)),x.topn&&(l.scrollTop+=Math.min(x.bottom-n,x.top-i))}function rt(l,e,y,p,x,u,k,i){const{layer:n,memo:f,measureFigure:d}=i;f.model!==e&&(f.model=e,f.least=void 0);const g=M=>{n.style.width=`${Math.max(f.least||M,Math.min(i.avail,i.row))}px`};n.style.width||(n.style.width=`${Math.min(i.avail,i.row)}px`);const h=n.style.transform;n.style.transform="none";const w=n.offsetWidth?n.getBoundingClientRect().width/n.offsetWidth:1,S=Math.abs(w-1)>1e-4?` scale(${1/w})`:"";n.style.transform=S||"none";const T=(l.querySelector(`.${y}-drawing`)??n).getBoundingClientRect(),q=T.left-Math.round(T.left),o=T.top-Math.round(T.top);(q||o)&&(n.style.transform=`translate(${-q/w}px, ${-o/w}px)${S}`);let s=d(l,e,y,p,x,u,f.least===void 0?void 0:k,g);if(s.dyn.layout==="stacked"&&f.least===void 0&&s.least!==void 0){const M=s.dyn,A=m=>{n.style.width=`${m}px`;const _=d(l,e,y,p,M,u);return _.dyn.layout==="drawn"?d(l,e,y,p,_.dyn,u):_},v=Math.max(s.least,Math.min(i.avail,i.row)),I=Math.max(i.row,v)*1.5;let z;for(let m=v+16;m<=I&&z===void 0;m+=16)A(m).dyn.layout==="drawn"&&(z=m);if(z!==void 0){for(let m=z-15;mi.contain&&(n.style.width=`${i.contain}px`,s=d(l,e,y,p,s.dyn,u,k)),n.style.transform=h,s}(function(l){"use strict";var e=l._,y=0;function p(i){return e.diagramKit.escapeHtml(String(i??""))}function x(i){return''+p(i)+""}function u(i,n){return parseFloat(getComputedStyle(i).getPropertyValue(n))||0}function k(i,n,f,d){var g=e.diagramKit,h=Object.assign({},n,{motion:"still"}),w=g.buildModel(h),S="dgv"+ ++y,T=g.figureKey("diagram",w),q=et(g.hintEntries(w)).map(function(r){return""+r.keys.map(x).join(" ")+" "+p(r.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",S+"-summary"),o.innerHTML='

'+p(w.title)+"

"+(n.source?'

'+p(n.source)+"

":"")+'

'+p(n.summary)+'

'+(T?'
'+g.toHtml(T)+"
":"")+'
',document.body.appendChild(o);var s=o.querySelector(".diagram-stage"),M=o.querySelector(".diagram-sizer"),A=o.querySelector(".diagram-layer"),v=A.firstChild,I=o.querySelector('[role="status"]'),z=o.querySelector(".diagram-level > span"),m=o.querySelector(".diagram-viewer-key"),_=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},W=null,K=!1,R=!1,D=function(r,E){E?r.setAttribute("aria-disabled","true"):r.removeAttribute("aria-disabled")},c=at({stage:s,sizer:M,layer:A,status:I,rest:u(s,"--_rest")||300,onChange:function(r){z.textContent=r.level+"%",D(L.out,r.listOpen||r.atMin),D(L.in,r.listOpen||r.atMax),D(L.fit,r.listOpen||r.atFit)}}),O={},C={layer:A,avail:0,row:1104,contain:480,memo:O,measureFigure:g.measureFigure,keys:tt,measure:function(r,E,Y,N,Z,P,X){return rt(r,E,Y,N,Z,P,X,C)},onMeasured:function(r,E){s.setAttribute("data-layout",r.dyn.layout||""),m&&(m.setAttribute("data-layout",r.dyn.layout||""),m.toggleAttribute("data-bare",!!r.dyn.bare)),R=!!r.dyn.bare,_.hidden=R,F(K||R),c.size(E.offsetWidth,E.offsetHeight)}};function B(){C.avail=Math.max(0,Math.floor(s.clientWidth-2*(parseFloat(getComputedStyle(M).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function F(r){r&&!W&&(W=document.createElement("div"),W.className="diagram-list diagram-viewer-list",W.innerHTML=g.figureList("diagram",w).map(function(E){return g.toHtml(E)}).join(""),s.appendChild(W)),r&&c.list(!0),W&&(W.hidden=!r),M.hidden=r,r||c.list(!1)}_.addEventListener("click",function(){K=!K,_.setAttribute("aria-expanded",String(K)),_.firstElementChild.textContent=K?"Hide the list":"View as list",F(K||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||c.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||c.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||c.fit()}),s.addEventListener("focusin",function(r){var E=r.target.closest&&r.target.closest(".diagram-node");E&&s.contains(E)&&nt(s,E,u(s,"--_clear")||16)}),l.openDialog(o,d),B(),g.draw(v,h,!1,C),setTimeout(function(){s.focus({preventScroll:!0})},0);var $=s.clientWidth,V=new ResizeObserver(function(){Math.abs(s.clientWidth-$)<.5||($=s.clientWidth,B(),v.__diagram&&v.__diagram.layout())});V.observe(s),o.addEventListener("transitionend",function(r){r.target===o&&r.propertyName==="transform"&&o.open&&v.__diagram&&v.__diagram.layout()}),i.setAttribute("data-viewing",""),f.animated&&f.settle(),o.addEventListener("close",function(){V.disconnect(),c.destroy(),v.__diagram&&v.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},u(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,n,f){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var g=d.querySelector(".diagram-expand");g&&g.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var w=d.querySelector(".diagram-toggle");w&&w.nextSibling?d.insertBefore(h,w.nextSibling):d.appendChild(h);var S=function(){k(i,n,f,h)};return h.addEventListener("click",S),{destroy:function(){h.removeEventListener("click",S),h.remove()}}}})(window.Basalt)})(); +(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(y=>y.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:y,layer:p,status:x}=l;let u=0,k=0,i=1,n=1,f=!1,d=!1,g=null,h="",w=0;const S=()=>Number.parseFloat(getComputedStyle(y).paddingTop)||0,T=()=>Math.min(n,1),q=t=>Math.min(j,Math.max(T(),t));function o(){if(!u||!k)return 1;const t=S(),a=e.clientWidth-2*t,b=e.clientHeight-2*t;if(a<=0||b<=0)return Math.min(1,J);const H=Math.min(a/u,b/k);return Math.min(J,Math.floor(H*100+1e-6)/100)}function s(){const t=T();return{zoom:i,level:Math.round(i*100),fit:n,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-n)e.clientWidth-2*S()+.5||k*i>e.clientHeight-2*S()+.5)}function A(){clearTimeout(w);const t=`Zoom ${Math.round(i*100)}%`;w=window.setTimeout(()=>{t!==h&&(h=t,x.textContent=t)},l.rest)}function v(){y.style.width=`${u*i}px`,y.style.height=`${k*i}px`,p.style.transform=`scale(${i})`}function I(t){const a=p.getBoundingClientRect();return{x:(t.x-a.left)/i,y:(t.y-a.top)/i}}function z(t,a){const b=p.getBoundingClientRect();e.scrollLeft+=b.left+t.x*i-a.x,e.scrollTop+=b.top+t.y*i-a.y}const m=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function _(t,a=m(),b){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){M();return}const ot=b??I(a);i=H,v(),z(ot,a),M(),A()}function L(t){f=!0;const a=i*100,b=t?G.find(H=>H>a+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,r=()=>{const[t,a]=[...c.values()];return{x:(t.x+a.x)/2,y:(t.y+a.y)/2}},E=()=>{const[t,a]=[...c.values()];return Math.hypot(t.x-a.x,t.y-a.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),c.size===1&&(O={x:t.clientX,y:t.clientY},C=O,B=!1,F=!1),c.size===2&&t.pointerType==="touch")){const a=r();$={d0:E()||1,z0:i,c:I(a)},F=!0,B=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!c.has(t.pointerId)||d)return;if(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),$&&c.size>=2){f=!0;const b=q($.z0*(E()/$.d0)),H=r();Math.abs(b-i)>1e-6&&(i=b,v(),M(),A()),z($.c,H);return}if(c.size!==1||!O||!C)return;const a={x:t.clientX,y:t.clientY};if(!B){if(Math.hypot(a.x-O.x,a.y-O.y)<=V())return;B=!0,F=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=a.x-C.x,e.scrollTop-=a.y-C.y,C=a,t.preventDefault()}function Z(t){if(c.has(t.pointerId)){if(c.delete(t.pointerId),c.size<2&&($=null),c.size===1){const[a]=[...c.values()];C=a,O=a,B=!0;return}c.size===0&&(B=!1,e.removeAttribute("data-dragging"),O=C=null)}}function P(t){F&&(F=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!u||!k)return;const t=f?I(m()):null;n=o(),f?(i=q(i),v(),t&&z(t,m())):(i=n,v()),M()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:K,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:W,state:s,list(t){t!==d&&(t?(g={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),v(),g&&(e.scrollLeft=g.left,e.scrollTop=g.top),g=null),M())},travelled:()=>F,destroy(){clearTimeout(w),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function nt(l,e,y){const p=l.getBoundingClientRect(),x=e.getBoundingClientRect(),u=p.left+y,k=p.left+l.clientWidth-y,i=p.top+y,n=p.top+l.clientHeight-y;x.leftk&&(l.scrollLeft+=Math.min(x.right-k,x.left-u)),x.topn&&(l.scrollTop+=Math.min(x.bottom-n,x.top-i))}function rt(l,e,y,p,x,u,k,i){const{layer:n,memo:f,measureFigure:d}=i;f.model!==e&&(f.model=e,f.least=void 0);const g=M=>{n.style.width=`${Math.max(f.least||M,Math.min(i.avail,i.row))}px`};n.style.width||(n.style.width=`${Math.min(i.avail,i.row)}px`);const h=n.style.transform;n.style.transform="none";const w=n.offsetWidth?n.getBoundingClientRect().width/n.offsetWidth:1,S=Math.abs(w-1)>1e-4?` scale(${1/w})`:"";n.style.transform=S||"none";const T=(l.querySelector(`.${y}-drawing`)??n).getBoundingClientRect(),q=T.left-Math.round(T.left),o=T.top-Math.round(T.top);(q||o)&&(n.style.transform=`translate(${-q/w}px, ${-o/w}px)${S}`);let s=d(l,e,y,p,x,u,f.least===void 0?void 0:k,g);if(s.dyn.layout==="stacked"&&f.least===void 0&&s.least!==void 0){const M=s.dyn,A=m=>{n.style.width=`${m}px`;const _=d(l,e,y,p,M,u);return _.dyn.layout==="drawn"?d(l,e,y,p,_.dyn,u):_},v=Math.max(s.least,Math.min(i.avail,i.row)),I=Math.max(i.row,v)*1.5;let z;for(let m=v+16;m<=I&&z===void 0;m+=16)A(m).dyn.layout==="drawn"&&(z=m);if(z!==void 0){for(let m=z-15;mi.contain&&(n.style.width=`${i.contain}px`,s=d(l,e,y,p,s.dyn,u,k)),n.style.transform=h,s}(function(l){"use strict";var e=l._,y=0;function p(i){return e.diagramKit.escapeHtml(String(i??""))}function x(i){return''+p(i)+""}function u(i,n){return parseFloat(getComputedStyle(i).getPropertyValue(n))||0}function k(i,n,f,d){var g=e.diagramKit,h=Object.assign({},n,{motion:"still"}),w=g.buildModel(h),S="dgv"+ ++y,T=g.figureKey("diagram",w),q=et(g.hintEntries(w,!0)).map(function(r){return""+r.keys.map(x).join(" ")+" "+p(r.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",S+"-summary"),o.innerHTML='

'+p(w.title)+"

"+(n.source?'

'+p(n.source)+"

":"")+'

'+p(n.summary)+'

'+(T?'
'+g.toHtml(T)+"
":"")+'
',document.body.appendChild(o);var s=o.querySelector(".diagram-stage"),M=o.querySelector(".diagram-sizer"),A=o.querySelector(".diagram-layer"),v=A.firstChild,I=o.querySelector('[role="status"]'),z=o.querySelector(".diagram-level > span"),m=o.querySelector(".diagram-viewer-key"),_=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},W=null,K=!1,R=!1,D=function(r,E){E?r.setAttribute("aria-disabled","true"):r.removeAttribute("aria-disabled")},c=at({stage:s,sizer:M,layer:A,status:I,rest:u(s,"--_rest")||300,onChange:function(r){z.textContent=r.level+"%",D(L.out,r.listOpen||r.atMin),D(L.in,r.listOpen||r.atMax),D(L.fit,r.listOpen||r.atFit)}}),O={},C={layer:A,avail:0,row:1104,contain:480,memo:O,measureFigure:g.measureFigure,keys:tt,measure:function(r,E,Y,N,Z,P,X){return rt(r,E,Y,N,Z,P,X,C)},onMeasured:function(r,E){s.setAttribute("data-layout",r.dyn.layout||""),m&&(m.setAttribute("data-layout",r.dyn.layout||""),m.toggleAttribute("data-bare",!!r.dyn.bare)),R=!!r.dyn.bare,_.hidden=R,F(K||R),c.size(E.offsetWidth,E.offsetHeight)}};function B(){C.avail=Math.max(0,Math.floor(s.clientWidth-2*(parseFloat(getComputedStyle(M).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function F(r){r&&!W&&(W=document.createElement("div"),W.className="diagram-list diagram-viewer-list",W.innerHTML=g.figureList("diagram",w).map(function(E){return g.toHtml(E)}).join(""),s.appendChild(W)),r&&c.list(!0),W&&(W.hidden=!r),M.hidden=r,r||c.list(!1)}_.addEventListener("click",function(){K=!K,_.setAttribute("aria-expanded",String(K)),_.firstElementChild.textContent=K?"Hide the list":"View as list",F(K||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||c.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||c.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||c.fit()}),s.addEventListener("focusin",function(r){var E=r.target.closest&&r.target.closest(".diagram-node");E&&s.contains(E)&&nt(s,E,u(s,"--_clear")||16)}),l.openDialog(o,d),B(),g.draw(v,h,!1,C),setTimeout(function(){s.focus({preventScroll:!0})},0);var $=s.clientWidth,V=new ResizeObserver(function(){Math.abs(s.clientWidth-$)<.5||($=s.clientWidth,B(),v.__diagram&&v.__diagram.layout())});V.observe(s),o.addEventListener("transitionend",function(r){r.target===o&&r.propertyName==="transform"&&o.open&&v.__diagram&&v.__diagram.layout()}),i.setAttribute("data-viewing",""),f.animated&&f.settle(),o.addEventListener("close",function(){V.disconnect(),c.destroy(),v.__diagram&&v.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},u(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,n,f){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var g=d.querySelector(".diagram-expand");g&&g.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var w=d.querySelector(".diagram-toggle");w&&w.nextSibling?d.insertBefore(h,w.nextSibling):d.appendChild(h);var S=function(){k(i,n,f,h)};return h.addEventListener("click",S),{destroy:function(){h.removeEventListener("click",S),h.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index a96f5d74..ae949afa 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,2 +1,2 @@ -(()=>{var fe=["top","right","bottom","left"],he=["main","plain","dashed"],pe=[2,3,4,5,6],rt=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),pt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function kt(t,e={}){const s=e.checks!==!1,r=[],o=d=>{r.push(d)},a=t.legend??{},l={};for(const d of["main","plain","dashed","focal","group"]){const m=rt(a[d]);m&&(l[d]=m)}const p=t.stepLabel,h=typeof p=="function"?d=>String(p(d)):typeof p=="string"?(d=>p.replace("{n}",String(d))):d=>`Step ${d}`,u=t.shapeLabels??{},g={terminal:rt(u.terminal)??"Start or end",step:rt(u.step)??"Step",decision:rt(u.decision)??"Decision"},c=t.heading===void 0?3:pe.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),y=(d,m)=>d==null?"plain":he.includes(d)?d:(o(`"${String(d)}" is not a kind of line (main, plain or dashed): ${m} is drawn plain`),"plain"),$=d=>{if(d!=null){if(fe.includes(d))return d;o(`"${String(d)}" is not a side (top, right, bottom or left): the derived side is used`)}},i=(d,m)=>typeof d=="number"&&Number.isInteger(d)&&d>=1?d:(o(`${m} is ${JSON.stringify(d)}, not a whole number from 1: it is placed at 1`),1),f=[],b=[];let O=[];const _=[],B=[],j=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(j)||o(`"${String(j)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),j==="architecture"||j==="flowchart"){for(const d of t.nodes??[]){const m=j==="flowchart"&&d.shape==="decision"?"decision":j==="flowchart"&&d.shape==="terminal"?"terminal":"box",S=String(d.id??""),E=i(d.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(d.name??""),kind:m==="decision"?void 0:rt(d.kind),detail:m==="decision"?void 0:rt(d.detail),mono:!!d.detailMono,focal:!!d.focal,col:i(d.col,`the column of ${S}`),row:E,row2:E,branch:!!d.branch,shape:m,group:j==="architecture"?rt(d.group):void 0,mark:j==="architecture"?ge(d.mark):void 0})}if(j==="architecture")for(const d of t.groups??[]){const m=String(d.id??"");_.push({id:m,label:String(d.label??""),members:f.filter(S=>S.group===m).map(S=>S.id)})}}else if(j==="data-flow"){O=(t.lanes??[]).map(m=>({id:String(m.id??""),label:String(m.label??"")}));const d=new Map(O.map((m,S)=>[m.id,S+1]));for(const m of t.nodes??[]){const S=String(m.id??""),E=String(m.lane??""),z=d.get(E);z===void 0&&o(`a node (${S}) names the lane "${E}", which is not in lanes`);const T=f.length+1;f.push({id:S,i:f.length,name:String(m.name??""),kind:h(T),detail:rt(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:i(m.col,`the column of ${S}`),row:z??1,row2:z??1,branch:!1,shape:"box",lane:z??1,laneLabel:O[(z??1)-1]?.label??E,step:T})}}else if(j==="sequence"){(t.participants??[]).forEach((m,S)=>{const E=String(m.name??"");f.push({id:String(m.id??""),i:S,name:E,kind:rt(m.kind),mono:!1,focal:!!m.focal,col:S+1,row:1,row2:1,branch:!1,shape:"participant",short:rt(m.short)??E})});let d=0;for(const m of t.steps??[])"band"in m?B.push({band:String(m.band??"")}):(d++,B.push({n:d,from:String(m.from??""),to:String(m.to??""),label:String(m.label??""),note:rt(m.note),kind:y(m.kind,`message ${d}`)}))}else if(j==="schema")for(const d of t.tables??[]){const m=String(d.name??""),[S,E]=Array.isArray(d.row)?d.row:[d.row,d.row],z=i(S,`the row of ${m}`),T=Math.max(z,i(E,`the last row of ${m}`)),G=d.more===void 0||d.more===null?void 0:Number.isInteger(d.more)&&d.more>0?d.more:(o(`${m}'s "more" is ${JSON.stringify(d.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:m,i:f.length,name:m,mono:!0,focal:!!d.focal,col:i(d.col,`the column of ${m}`),row:z,row2:T,branch:!1,shape:"table",more:G,columns:(d.columns??[]).map(N=>({name:String(N.name??""),type:rt(N.type),key:N.key==="PK"||N.key==="FK"?N.key:(N.key!==void 0&&N.key!==null&&o(`${m}.${String(N.name)}'s key is "${String(N.key)}", not PK or FK: it is left out`),void 0)}))})}const R=new Map;for(const d of f)d.id?R.has(d.id)&&o(`the id "${d.id}" is used twice`):o("a node has no id"),R.set(d.id,d);if(j==="schema")(t.tables??[]).forEach(d=>(d.columns??[]).forEach((m,S)=>{const E=rt(m.references);if(!E)return;const[z,T]=E.split("."),G=R.get(z??""),N=G?.columns?.findIndex(C=>C.name===T)??-1;if(!G||N<0){o(`${String(d.name)}.${String(m.name)} references ${E}, which is not a shown column`);return}const k=R.get(String(d.name??""));k.columns[S].ref={table:z,column:T,row:N},b.push({i:b.length,from:k.id,to:z,kind:"plain",fromRow:S,toRow:N,fk:!0})}));else if(j!=="sequence")for(const d of t.edges??[]){const m=String(d.from??""),S=String(d.to??"");if(!R.has(m)||!R.has(S)){o(`a line names ${R.has(m)?S:m}, which is not a node`);continue}const E=rt(d.label);E&&E.length>Ot&&o(`the label "${E}" is over ${Ot} characters: longer words belong in the node or the summary`),b.push({i:b.length,from:m,to:S,kind:y(d.kind,`the line from ${m} to ${S}`),label:E,fromSide:$(d.fromSide),toSide:$(d.toSide),flow:j!=="flowchart"&&d.flow===!0?!0:void 0})}else for(const d of B)"n"in d&&(!R.has(d.from)||!R.has(d.to))&&o(`message ${d.n} names ${R.has(d.from)?d.to:d.from}, which is not a participant`);if(s&&j!=="sequence"){const d=new Map;for(const m of f)for(let S=m.row;S<=m.row2;S++){const E=`${m.col}:${S}`;d.has(E)&&o(`${m.id} and ${d.get(E)} share the cell at column ${m.col}, row ${S}`),d.set(E,m.id)}}if(s){for(const m of _){const S=m.members.map(T=>R.get(T));if(!S.length)continue;const E={c1:Math.min(...S.map(T=>T.col)),c2:Math.max(...S.map(T=>T.col)),r1:Math.min(...S.map(T=>T.row)),r2:Math.max(...S.map(T=>T.row2))};for(const T of f)T.group!==m.id&&T.col>=E.c1&&T.col<=E.c2&&T.row>=E.r1&&T.row<=E.r2&&o(`${T.id} is inside the box of the group "${m.label}" but not a member`);const z=S.map(T=>T.i);Math.max(...z)-Math.min(...z)+1!==z.length&&o(`the members of the group "${m.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const m of f)m.group&&!_.some(S=>S.id===m.group)&&o(`${m.id} names the group "${m.group}", which is not in groups`);f.filter(m=>m.focal).length>1&&o("more than one node is focal: a diagram has one at most");const d=new Set(j==="sequence"?B.flatMap(m=>"n"in m?[m.kind]:[]):b.map(m=>m.kind));d.has("main")&&!l.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),d.has("dashed")&&!l.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(m=>m.focal)&&!l.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const Q=j==="architecture"||j==="data-flow",A=d=>Array.isArray(d)&&d.length>1?d.map(String):void 0,V=Q&&t.packet&&typeof t.packet=="object"?t.packet:void 0,v=V&&A(V.path),D={animated:t.motion==="animated",pulse:Q?A(t.pulse):void 0,packet:v?{path:v,repeat:V.repeat===!0,send:V.send}:void 0,run:j==="sequence"&&t.run===!0};if(s)for(const d of f){const m=d.mark?.says;if(!m?.length)continue;const S=[d.name,d.kind,d.detail].filter(Boolean).join(" ").toLowerCase();m.some(E=>S.includes(E.toLowerCase()))||o(`${d.id}'s mark stands for ${m.join(" or ")}, and none of its words say so`)}const L=Math.max(1,...f.map(d=>d.col)),x=j==="data-flow"?Math.max(1,O.length):Math.max(1,...f.map(d=>d.row2));return{type:j,title:String(t.title??""),heading:c,legend:l,nodes:f,byId:R,edges:b,groups:_,lanes:O,steps:B,cols:L,rows:x,shapeLabels:g,stepWord:h,warnings:r,motion:D,memo:new Map}}function ge(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=rt(e.onLight);if(n)return{onLight:n,onDark:rt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var It=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function wt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Ot=28,mt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function _t(t,e){return t.legend[e]}function me(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function ye(t,e){return wt(t,`sentence:${e.i}`,()=>be(t,e))}function be(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,r=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(mt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`)}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?me(t,e):e.kind;if(n.push(mt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(mt(e.detail)),e.group){const a=t.groups.find(l=>l.id===e.group);a&&n.push(`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${a.label})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${a.label})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(mt(t.legend.focal)),n.join(" ")}function $e(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function w(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var we={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>we[e]),xe=" br img input meta link hr path polygon polyline circle rect line ";function St(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return xe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>St(s,e)).join("")}`}var ve=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function gt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Me(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Ct(t){let e=0;for(const n of t.groups){const s=n.members.map(r=>t.byId.get(r).col);s.length&&(Math.min(...s)===1&&(e|=1),Math.max(...s)===t.cols&&(e|=2))}return(e&1)+(e>>1&1)}function Et(t){return t.type==="sequence"?t.nodes.length:t.cols}function Bt(t){return wt(t,"plan",()=>ke(t))}function ke(t){const e=t.nodes,n=i=>t.type==="data-flow"||!e[i].branch,s=t.edges.map(i=>{const f=t.byId.get(i.from).i,b=t.byId.get(i.to).i,_=e.slice(Math.min(f,b)+1,Math.max(f,b)).every(B=>!n(B.i));return b===f+1&&!(n(f)&&!n(b))?"down":b===f-1?"up":b>f&&n(f)&&!n(b)&&_?"trunk":b>f&&n(f)&&n(b)&&_?"rail":b>f?"end-down":"end-up"}),r=t.edges.map((i,f)=>({e:i,k:f})).filter(({k:i})=>s[i]==="end-down"||s[i]==="end-up"),o=i=>{const f=t.byId.get(i.from).i,b=t.byId.get(i.to).i;return[Math.min(f,b),Math.max(f,b)]},a=(i,f)=>{const[b,O]=o(i),[_,B]=o(f);return b{const f=t.byId.get(i.from).i,[b,O]=o(i);return!n(f)&&e.slice(b+1,O).every(_=>!n(_.i))&&r.every(_=>_.e===i||!a(_.e,i))}),p=r.length>0&&(t.type==="data-flow"||!l),h=i=>{const[f,b]=o(i);return b-f},u=t.edges.map(()=>0);let g=!1;const c=[];for(const i of[...r].sort((f,b)=>h(f.e)-h(b.e)||f.k-b.k)){let f=0;for(const b of c)a(b.e,i.e)&&(f=Math.max(f,u[b.k]+1));u[i.k]=f,f>1&&(g=!0),c.push(i)}const y=t.edges.map(()=>.5);for(const i of e){const f=r.filter(({e:_})=>_.from===i.id);if(f.length<2)continue;const b=f.filter(({k:_})=>s[_]==="end-down").sort((_,B)=>h(B.e)-h(_.e)||_.k-B.k);[...f.filter(({k:_})=>s[_]==="end-up").sort((_,B)=>h(_.e)-h(B.e)||B.k-_.k),...b].forEach(({k:_},B,j)=>{y[_]=j.length===2?B===0?1/3:2/3:(B+1)/(j.length+1)})}const $=ht();for(let i=1;i{const A=s[Q],V=t.byId.get(R.from).i,v=t.byId.get(R.to).i,D=v===i&&(A==="down"||A==="trunk"||A==="rail"||A==="end-down"),L=V===i&&v===i-1&&A==="up",x=v===i-1&&A==="end-up";D&&(A==="trunk"||A==="end-down")&&(B=!0),x&&(j=!0),(D||L||x)&&R.label&&(O++,_=Math.max(_,A==="trunk"?40:48))}),(O>1||B&&j)&&(_=64),$[f.id]=_}return{routes:s,gutter:p,lanes:u,exits:y,gaps:$,third:g}}var yt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function jt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return w("svg",{class:`${t}-swatch`,"data-kind":n,...yt(24,16)},e==="fk"?w("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,w("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?w("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):w("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function bt(t,e){return e==="decision"?w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):w("svg",{class:`${t}-swatch`,"data-shape":e,...yt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Tt(t,e){return wt(e,`key:${t}`,()=>Ee(t,e))}var Se=Tt;function Ee(t,e){const n=[],s=(o,a,l={})=>n.push(w("li",{class:`${t}-entry`,...l},o,w("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),w("span",null,l)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(bt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(bt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(bt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(jt(t,o),a,{"data-line":""})}return e.type==="schema"&&e.edges.length&&(s(jt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(w("li",{class:`${t}-entry`,"data-when":"stacked"},w("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),w("span",null,"The table a foreign key references")))),e.nodes.some(o=>o.focal)&&e.legend.focal&&s(bt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(bt(t,"group"),e.legend.group),n.length?w("div",{class:`${t}-key`},w("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Ae(t,e){const n=e==="main"?6:6.5;return w("svg",{class:`${t}-arrow`,"data-kind":e,...yt(20,12)},w("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?w("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):w("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Le(t,e,n){if(n.shape==="decision")return[w("span",{class:`${t}-words`},w("span",{class:`${t}-name`},n.name))];const s=[];return e.type==="data-flow"?s.push(w("span",{class:`${t}-kind`},n.kind,w("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(w("span",{class:`${t}-kind`},n.kind)),s.push(w("span",{class:`${t}-name`},n.name)),n.detail&&s.push(w("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?vt(n.detail).flatMap((r,o)=>[o?" ":"",w("span",{class:`${t}-run`},r)]):n.detail)),s}function qe(t,e){return[w("span",{class:`${t}-th`},w("span",{class:`${t}-tname`},e.name)),w("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>w("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},w("span",{class:`${t}-keyseat`},n.key??""),w("span",{class:`${t}-cname`},n.name),n.ref?w("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?w("span",{class:`${t}-ctype`},n.type):null))),e.more?w("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Rt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=Me(e,s)||s.keep===n.id,a=gt(e,s),l=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&l.push(`--_lc:${n.col+1}`),e.type==="sequence"&&l.push(`--_c2:${n.col+1}`);const p=t.plan;if(p&&n.i>0){const c=pt(p.gaps,n.id)??32,y=pt(s.grow,n.id)??0;l.push(`--_gap:${y?`calc(${Rt(c)} + var(--basalt-space-4) * ${y})`:Rt(c)}`)}const h=pt(s.heights,n.id);h&&l.push(`--_h:${h}px`);const u=pt(s.words,n.id);u&&l.push(`--_ww:${u}px`);const g=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return w("div",{class:`${r}-node`,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:l.join(";"),role:o?"img":void 0,"aria-label":o?ye(e,n):void 0,tabindex:g},n.shape==="decision"?w("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},w("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?w("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${It(n.mark.onLight)};--_md:${It(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?qe(r,n):Le(r,e,n))}function Ie(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((a,l)=>w("div",{class:`${s}-lane`,style:`--_r:${l+1}`,"aria-hidden":"true"},w("span",{class:`${s}-lane-name`},a.label)))),e.type==="architecture")for(const a of e.groups){const l=a.members.map(c=>e.byId.get(c));if(!l.length)continue;const p=Math.min(...l.map(c=>c.col)),h=Math.max(...l.map(c=>c.col)),u=Math.min(...l.map(c=>c.row)),g=Math.max(...l.map(c=>c.row2));r.push(w("div",{class:`${s}-gbox`,"data-group":a.id,style:`--_c:${p};--_c2:${h+1};--_r:${u};--_r2:${g+1}`,"aria-hidden":"true"},w("span",{class:`${s}-glabel`},a.label)))}if(e.type==="sequence")return r.push(w("ul",{class:`${s}-cast`},e.nodes.map(a=>w("li",{class:`${s}-actor`},At(t,e,a,n))))),r.push(Oe(t,e)),r;let o=0;for(;ou.id===a.group):void 0;if(!l){r.push(At(t,e,a,n)),o++;continue}const p=[];for(;oAt(t,e,u,n))))}return r}function Oe(t,e){const{P:n}=t,s=[];let r=null;for(const o of e.steps){if("band"in o){r=null,s.push(w("p",{class:`${n}-band`},w("span",null,o.band)));continue}r||(r=w("ol",{class:`${n}-msgs`,start:o.n}),s.push(r));const a=e.byId.get(o.from),l=e.byId.get(o.to),p=a?.col??1,h=l?.col??1,u=p===h,g=u&&p===e.nodes.length,c=_t(e,o.kind);r.c.push(w("li",{class:`${n}-msg`,"data-kind":o.kind,"data-from":o.from,"data-to":o.to,"data-self":u?g?"start":"end":void 0,style:`--_a:${Math.min(p,h)};--_b:${Math.max(p,h)+1}`},w("span",{class:`${n}-said`},w("span",{class:`${n}-num`},String(o.n)),w("span",{class:`${n}-mlabel`},o.label)),w("span",{class:`${n}-route`},a?.short??o.from," ",Ae(n,o.kind),w("span",{class:t.hidden}," to ")," ",l?.short??o.to,c?` · ${c}`:""),o.note?w("span",{class:`${n}-note`},o.note):null))}return w("div",{class:`${n}-steps`},s)}function Ft(t,e){return wt(e,`list:${t}`,()=>Ce(t,e))}var _e=Ft;function Ce(t,e){const n=Math.min(6,e.heading+1),s=u=>w(`h${n}`,{class:`${t}-list-head`},u),r=u=>w("strong",null,u),o=u=>w("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,l=u=>{const g=_t(e,u);return g?` (${g})`:""},p=u=>u.focal&&e.legend.focal?` ${mt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=y=>w("li",null,r(y.name),y.kind?`, ${y.kind}`:"",y.detail?[". ",y.mono?o(y.detail):y.detail,/[.!?]$/.test(y.detail)?"":"."]:/[.!?]$/.test(y.kind??y.name)?"":".",p(y)),g=[s("Parts")],c=e.nodes.filter(y=>!y.group);c.length&&g.push(w("ul",{class:`${t}-list-items`},c.map(u)));for(const y of e.groups)g.push(w("p",{class:`${t}-list-group`},y.label)),g.push(w("ul",{class:`${t}-list-items`},y.members.map($=>u(e.byId.get($)))));return g.push(s("Connections")),g.push(w("ol",{class:`${t}-list-items`},e.edges.map(y=>w("li",null,r(a(y.from))," to ",r(a(y.to)),y.label?[": ",o(y.label)]:"",`${l(y.kind)}.`)))),g}if(e.type==="flowchart"){const u=g=>(e.byId.get(g)?.i??0)+1;return[w("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const c=e.edges.filter(i=>i.from===g.id),y=g.shape==="decision"?"Decision":g.shape==="terminal"?c.length?"Start":"End":"Step",$=!g.detail&&/[.!?]$/.test(g.name)?" ":". ";return w("li",null,r(g.name),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",`${$}${y}.`,p(g),c.length?w("ul",{class:`${t}-list-exits`},c.map(i=>w("li",null,i.label?`If ${i.label}: go to ${u(i.to)}, `:`Then: go to ${u(i.to)}, `,r(a(i.to)),l(i.kind)))):null)}))]}if(e.type==="data-flow")return[w("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const g=e.edges.filter(c=>c.from===u.id);return w("li",null,`${u.laneLabel}: `,r(u.name),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",p(u),g.length?[" Then ",...g.flatMap((c,y)=>[y?"; ":"",`to step ${e.byId.get(c.to).step}, `,r(a(c.to)),c.label?[": ",o(c.label)]:"",l(c.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),w("ul",{class:`${t}-list-items`},e.nodes.map(c=>w("li",null,r(c.name),c.kind?`, ${c.kind}`:"",".",p(c))))];u.push(s("Messages"));let g=null;for(const c of e.steps){if("band"in c){g=null,u.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},c.band));continue}g||(g=w("ol",{class:`${t}-list-items`,start:c.n}),u.push(g)),g.c.push(w("li",null,o(c.label),": ",r(a(c.from))," to ",r(a(c.to)),`${l(c.kind)}.`,c.note?` ${mt(c.note)}`:""))}return u}const h=[];for(const u of e.nodes)h.push(w(`h${n}`,{class:`${t}-list-group`},o(u.name),p(u))),h.push(w("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(g=>w("li",null,o(g.name),g.key==="PK"?", primary key":g.key==="FK"?", foreign key":"",g.ref?[", references ",o(`${g.ref.table}.${g.ref.column}`)]:g.type?`, ${g.type}`:"")),...u.more?[w("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return h}function Ht(t){return`Arrow keys move to the next or the previous ${t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step"}, in the author's order; Home and End go to the ends; Escape clears the trace.`}function zt(t){return[{keys:["←","→"],words:$e(t)},{keys:["Home","End"],words:"the ends"},{keys:["Esc"],words:"clear"}]}var Nt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Wt(t,e,n){const s=n.prefix,r=ve(n.base),o=t.type==="sequence"||t.type==="schema"?null:Bt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},l=e.layout==="drawn",p=gt(t,e),h=t.type==="sequence"||t.type==="schema"?l:!0,u=`h${t.heading}`,g=[`--_cols:${Et(t)}`];if(t.type==="architecture"&&t.groups.length||l&&e.pad){const c=t.type==="architecture"?t.groups.flatMap(i=>i.members.map(f=>t.byId.get(f))):[],y=(i,f,b)=>i?`var(--basalt-space-${f})`:b?`var(--basalt-space-${b})`:"0px",$=l&&e.pad?"3":void 0;g.push(`--_gpad:${y(c.some(i=>i.row===1),"8",$)} ${y(c.some(i=>i.col===t.cols),"4")} ${y(c.some(i=>i.row2===t.rows),"4",$)} ${y(c.some(i=>i.col===1),"4")}`)}return Nt(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),w("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Et(t),"data-reach":t.type==="architecture"?Ct(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},w("div",{class:`${s}-head`},w(u,{id:r.title,class:`${s}-title`},t.title),n.hasSource?w("p",{class:`${s}-source`},{slot:"source"}):null),w("div",{class:`${s}-drawing`,role:h?"group":void 0,"aria-roledescription":h?"diagram":void 0,"aria-labelledby":h?r.title:void 0,"aria-describedby":h?p?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":p?"":void 0},Ie(a,t,e),w("div",{class:`${s}-ink`,"aria-hidden":"true"}),w("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Tt(s,t),w("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),w("div",{class:`${s}-foot`},{slot:"toggle"}),w("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Ft(s,t)),w("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Ht(t)} ${n.viewer}`:Ht(t)),w("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Be(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4)}}var xt=(t,e)=>t==="main"?e.line:e.hair,ct=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},dt=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Dt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function it(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,l=(s+o)/2,p=(r+a)/2,h=(o-s)/2,u=(a-r)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const $=n,i=u*Math.max(0,1-Math.abs($-l)/h);return{x:$,y:e==="top"?p-i:p+i}}const c=n,y=h*Math.max(0,1-Math.abs(c-p)/u);return{x:e==="left"?l-y:l+y,y:c}}if(t.shape==="terminal"){const c=Math.min(h,u);if(g){const f=n,b=Math.min(Math.max(f,s+c),o-c),O=f-b,_=Math.abs(O)>=c?0:Math.sqrt(c*c-O*O);return{x:f,y:Math.abs(O)<1e-6?e==="top"?r:a:e==="top"?p-_:p+_}}const y=n,$=y-p,i=Math.abs($)>=c?0:Math.sqrt(c*c-$*$);return{x:e==="left"?s+c-i:o-c+i,y}}return g?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function je(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,l=(s+o)/2,p=(r+a)/2,h=(o-s)/2,u=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-l)/h+Math.abs(t.y-p)/u<1-n/Math.min(h,u);if(e.shape==="terminal"){const g=Math.min(h,u),c=Math.min(Math.max(t.x,s+g),o-g);return Math.hypot(t.x-c,t.y-p)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Fe(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var vt=t=>t?t.split(/\s+/).filter(Boolean):[];function He(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const p of t.nodes){if(p.shape==="table"){for(const y of p.columns??[]){const $=y.ref?`→ ${y.ref.table}`:y.type??"",i=s("6")+n(y.name,"mono")+($?s("3")+n($,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(i))}o=Math.max(o,Math.ceil(n(p.name,"table")+2*s("3")+2*e.hair));continue}const h=p.shape==="terminal"?2*s("5"):2*s("3"),u=p.mark&&!Re()?s("6"):0;let g=0;for(const y of vt(p.name))g=Math.max(g,n(y,p.shape==="decision"?"name-500":"name")+(p.kind?0:u));if(t.type!=="data-flow")for(const y of vt(p.kind))g=Math.max(g,n(y,"mono")+u);for(const y of vt(p.detail))g=Math.max(g,n(y,p.mono?"mono":"sans"));const c=p.shape==="decision"?g/.62:g+h+2*e.hair;r=Math.max(r,Math.ceil(c))}const a=Et(t);let l;return t.type==="data-flow"?l=e.lane+a*(r+s("12")):t.type==="schema"?l=a*o+(a-1)*s("12")+(Nt(t)?s("5"):0):t.type==="sequence"?l=a*r+(a-1)*s("5"):l=a*r+(a-1)*s("16")+Ct(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,l)}}function Kt(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Lt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Vt(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const p=r[r.length-2];if(Math.abs(p.x-l.x)<.01&&Math.abs(l.x-a.x)<.01||Math.abs(p.y-l.y)<.01&&Math.abs(l.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ft=t=>t.slice(1).map((e,n)=>[t[n],e]);function Mt(t,e,n){const s=[];for(let o=0;oMath.min(i.x,f.x)+.75&&_Math.min(b.y,O.y)+.75&&Br.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const l=[];let p=o;for(const h of r)l.push([p,p+h]),p+=h+a;return l};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var Y=t=>t==="left"||t==="right",Zt={top:"bottom",bottom:"top",left:"right",right:"left"};function Ne(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function We(t,e,n){const s=[];t.edges.forEach((o,a)=>{const l=t.byId.get(o.from),p=t.byId.get(o.to),[h,u]=e[a],g=l.row===p.row&&Y(h)&&Y(u)&&h===Zt[u]||l.col===p.col&&!Y(h)&&!Y(u)&&h===Zt[u];s.push({edge:a,end:"from",node:l,side:h,far:p,straight:g,f:.5},{edge:a,end:"to",node:p,side:u,far:l,straight:g,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const l=i=>Y(i.side)?i.far.row-i.node.row:i.far.col-i.node.col,p=a.filter(i=>i.straight),h=a.filter(i=>!i.straight);if(h.sort((i,f)=>l(i)-l(f)||(Y(i.side)?i.far.col-f.far.col:i.far.row-f.far.row)*(l(i)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!p.length){h.length===2?(h[0].f=.25,h[1].f=.75):h.length===3?(h[0].f=.25,h[1].f=.5,h[2].f=.75):h.length>3&&h.forEach((i,f)=>{i.f=(f+1)/(h.length+1)});continue}const u=new Map;for(const i of p)u.has(i.far.id)||u.set(i.far.id,[]),u.get(i.far.id).push(i);for(const i of u.values())i.length>1&&i.sort((f,b)=>f.edge-b.edge).forEach((f,b)=>{f.f=i.length===2?b===0?.25:.75:(b+1)/(i.length+1)});const g=Math.min(...p.map(i=>i.f)),c=Math.max(...p.map(i=>i.f)),y=h.filter(i=>l(i)<0),$=h.filter(i=>l(i)>=0);y.forEach((i,f)=>{i.f=g*(f+1)/(y.length+1)}),$.forEach((i,f)=>{i.f=c+(1-c)*(f+1)/($.length+1)})}return s}function Jt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return Y(e)?it(t,e,r+(a-r)*n):it(t,e,s+(o-s)*n)}function Ut(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ct(o,n),shape:a.shape,i:a.i})}),r}function Xt(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var Yt=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Qt(t,e,n,s){const r=(o,a)=>{const l=o+a-Math.floor(o+a);return l<.005||l>.995?[0]:l<=.5?[-l,1-l]:[1-l,-l]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const l={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(l))return l}return t}function De(t,e,n,s,r,o,a,l,p){const h=a.space,u=[],g=[],c=[],y=[],$=h("1"),i=e.filter(f=>t.edges[f.i]?.label).sort((f,b)=>+(t.edges[b.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-b.i);for(const f of i){const b=t.edges[f.i].label,O=l(b,"label"),_=16,B=f.pts.length-2,j=[];ft(f.pts).forEach(([v,D],L)=>{const x=Math.abs(v.y-D.y)<.01,d=x?v.x:v.y;let m=x?D.x:D.y;const S=Math.sign(m-d)||1;L===B&&(m-=S*a.head);let E=[[d,m]];for(const G of r)for(const N of x?[G.l,G.r]:[G.t,G.b]){const k=x?v.y:v.x;(x?k>G.t&&kG.l&&kN>Math.min(q,M)+1&&N{const k=(G+N)/2,C=x?{x:k,y:v.y}:{x:v.x,y:k};return!r.some(q=>C.x>q.l&&C.xq.t&&C.y1&&z(G,N)?1:0})}),j.sort((v,D)=>D.pri-v.pri||D.len-v.len);let R=null,Q=!1;const A=(v,D=!0)=>{const L=Dt(v,$);return D&&(v.lo.r||v.to.b)||n.some(x=>Gt(L,x))||u.some(x=>dt(L,x))||s.heads.some(x=>dt(L,x))||s.rects.some(x=>dt(L,x))?!1:!e.some(x=>x.i!==f.i&&ft(x.pts).some(([d,m])=>dt(L,Yt(d,m,x.width))))};for(const v of j){for(const D of[1/2,1/3,2/3]){const L=v.p+(v.q-v.p)*D,x=[],d=h("2")+f.width/2;if(v.horiz?(v.len>=O+2*h("1")+h("3-5")&&x.push({box:{l:L-O/2-h("1"),r:L+O/2+h("1"),t:v.c-_/2,b:v.c+_/2},on:!0}),x.push({box:{l:L-O/2,r:L+O/2,t:v.c-d-_,b:v.c-d},on:!1}),x.push({box:{l:L-O/2,r:L+O/2,t:v.c+d,b:v.c+d+_},on:!1})):(v.len>=_+h("3")&&x.push({box:{l:v.c-O/2-h("1"),r:v.c+O/2+h("1"),t:L-_/2,b:L+_/2},on:!0}),x.push({box:{l:v.c+d,r:v.c+d+O,t:L-_/2,b:L+_/2},on:!1}),x.push({box:{l:v.c-d-O,r:v.c-d,t:L-_/2,b:L+_/2},on:!1})),R=x.find(m=>A(m.box))??null,R)break;!Q&&x.some(m=>A(m.box,!1))&&(Q=!0)}if(R)break}if(!R){c.push(f.i),Q&&y.push(f.i);continue}const V=Qt(R.box,p.ox,p.oy,v=>A(v));u.push(V),g.push({i:f.i,text:b,box:V,on:R.on})}return{labels:g,unseated:c,bounded:y}}function Pt(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const l=ct(a,e);o.push(l),r.push({l:l.l,r:l.r,t:l.t,b:l.t+1},{l:l.l,r:l.r,t:l.b-1,b:l.b},{l:l.l,r:l.l+1,t:l.t,b:l.b},{l:l.r-1,r:l.r,t:l.t,b:l.b});const p=a.querySelector(`:scope > .${n}-glabel`);p&&p.getClientRects().length&&r.push(ct(p,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,l)=>{if(!a.getClientRects().length)return;const p=ct(a,e);l>0&&r.push({l:p.l,r:p.r,t:p.t-s/2-.5,b:p.t-s/2+.5});const h=a.querySelector(`.${n}-lane-name`);h&&r.push(ct(h,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function Ge(t,e){const{m:s,tk:r,P:o,drawing:a,origin:l,warn:p}=t,h=r.space,u=Ut(s,a,l,o),g=[...u.values()],c=ze(a),y=l.left-Math.floor(l.left),$=l.top-Math.floor(l.top),i=Kt(y,$),f=a.clientWidth,b=a.clientHeight,O=k=>s.type==="data-flow"?k.col+1:k.col,_=parseFloat(getComputedStyle(a).rowGap)||0,B={w:f,h:b,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:y,oy:$};if(s.type==="sequence")return Ve(t,B,i);let j,R=[];s.type==="schema"?j=s.edges.map(k=>{const C=s.byId.get(k.from),q=s.byId.get(k.to);if(C.col===q.col){const M=C.col===s.cols&&s.cols>1?"left":"right";return[M,M]}return q.col>C.col?["right","left"]:["left","right"]}):(j=s.edges.map(k=>{const C=s.byId.get(k.from),q=s.byId.get(k.to),[M,I]=Ne(C,q);return[k.fromSide??M,k.toSide??I]}),R=We(s,j,p||(()=>{})));const Q=(k,C)=>{const q=a.querySelector(`.${o}-node[data-node="${CSS.escape(k)}"] .${o}-row[data-row="${C}"]`);if(!q)return 0;const M=ct(q,l);return(M.t+M.b)/2},A=s.edges.map((k,C)=>{const[q,M]=j[C],I=u.get(k.from),F=u.get(k.to),Z=xt(k.kind,r);if(k.fk){const J=Q(k.from,k.fromRow),et=Q(k.to,k.toRow),U=i.y(J,Z),nt=i.y(et,Z);return{p1:{x:q==="right"?I.rect.r:I.rect.l,y:U},p2:{x:M==="right"?F.rect.r:F.rect.l,y:nt},r1:J,r2:Math.abs(U-nt)<.01?J:et}}const P=R.find(J=>J.edge===C&&J.end==="from").f,X=R.find(J=>J.edge===C&&J.end==="to").f;let W=Jt(I,q,P),K=Jt(F,M,X);const ot=Y(q)?W.y:W.x;let tt=Y(M)?K.y:K.x;return Y(q)?W={...W,y:i.y(W.y,Z)}:W={...W,x:i.x(W.x,Z)},Y(M)?K={...K,y:i.y(K.y,Z)}:K={...K,x:i.x(K.x,Z)},Y(q)&&Y(M)&&Math.abs(W.y-K.y)<1.01&&(K={...K,y:W.y},tt=ot),!Y(q)&&!Y(M)&&Math.abs(W.x-K.x)<1.01&&(K={...K,x:W.x},tt=ot),W=Y(q)?it(I,q,W.y):it(I,q,W.x),K=Y(M)?it(F,M,K.y):it(F,M,K.x),{p1:W,p2:K,r1:ot,r2:tt}}),V=new Set;s.type==="schema"&&s.edges.forEach((k,C)=>{Math.abs(s.byId.get(k.from).col-s.byId.get(k.to).col)>1&&V.add(C)});const v=new Map,D=new Set;s.edges.forEach((k,C)=>{if(V.has(C))return;const[q,M]=j[C],{p1:I,p2:F}=A[C],Z=s.byId.get(k.from),P=s.byId.get(k.to);let X=null,W=null,K=!1;if(q===M){if(Y(q)){const J=q==="right"?Math.max(O(Z),O(P)):Math.min(O(Z),O(P))-1,et=c.cols[J-1],U=c.cols[J];et&&U&&(X=`c${J}`,W=[et[1],U[0]],K=!0)}else{const J=q==="bottom"?Math.max(Z.row2,P.row2):Math.min(Z.row,P.row)-1,et=c.rows[J-1],U=c.rows[J];et&&U&&(X=`r${J}`,W=[et[1],U[0]],K=!1)}X&&D.add(C)}else if(Y(q)&&Y(M)&&Math.abs(I.y-F.y)>.5){const J=O(P),et=M==="left",U=c.cols[(et?J-1:J)-1],nt=c.cols[(et?J:J+1)-1];U&&nt&&(X=`c${et?J-1:J}`,W=[U[1],nt[0]],K=!0)}else if(!Y(q)&&!Y(M)&&Math.abs(I.x-F.x)>.5){const et=M==="top"?P.row-1:P.row2,U=c.rows[et-1],nt=c.rows[et];U&&nt&&(X=`r${et}`,W=[U[1],nt[0]],K=!1)}if(!X||!W)return;v.has(X)||v.set(X,{span:W,vertical:K,members:new Map});const ot=`${k.to}.${M}.${Math.round(K?F.y:F.x)}`,tt=v.get(X);tt.members.has(ot)||tt.members.set(ot,[]),tt.members.get(ot).push(C)});const L=new Map,x=k=>{const[C,q]=j[k],{p1:M,p2:I}=A[k];if(Y(C)&&Y(q)){if(C===q){const Z=L.get(k)??(C==="right"?Math.max(M.x,I.x)+h("4"):Math.min(M.x,I.x)-h("4"));return[M,{x:Z,y:M.y},{x:Z,y:I.y},I]}if(Math.abs(M.y-I.y)<=.5)return[M,{x:I.x,y:M.y}];const F=L.get(k)??(M.x+I.x)/2;return[M,{x:F,y:M.y},{x:F,y:I.y},I]}if(!Y(C)&&!Y(q)){if(C===q){const Z=L.get(k)??(C==="bottom"?Math.max(M.y,I.y)+h("4"):Math.min(M.y,I.y)-h("4"));return[M,{x:M.x,y:Z},{x:I.x,y:Z},I]}if(Math.abs(M.x-I.x)<=.5)return[M,{x:M.x,y:I.y}];const F=L.get(k)??(M.y+I.y)/2;return[M,{x:M.x,y:F},{x:I.x,y:F},I]}return Y(C)?[M,{x:I.x,y:M.y},I]:[M,{x:M.x,y:I.y},I]},d=k=>{const C=s.edges[k],q=xt(C.kind,r),M=x(k),I=Vt(M,q,i);let F;return M.length===I.length&&(F=ft(M).map(([Z,P])=>Math.abs(Z.y-P.y)<.75?(Z.y+P.y)/2:(Z.x+P.x)/2),F[0]=A[k].r1,F.length>1&&(F[F.length-1]=A[k].r2)),{i:k,from:C.from,to:C.to,kind:C.kind,pts:I,tip:I[I.length-1],dir:Lt(I),dot:C.fk?I[0]:void 0,width:q,axes:F}},m=()=>s.edges.flatMap((k,C)=>V.has(C)?[]:[d(C)]);let S=null;const E=k=>{S??(S=m());const C=S.map(q=>k.has(q.i)?d(q.i):q);return{lines:C,score:Ke(C,k)*1e5+Mt(C,void 0,k).length*1e3+qt(C.filter(q=>k.has(q.i)),g,s).length}},z=(k,C)=>{const q=k.flatMap(M=>{const{p1:I,p2:F}=A[M];return C?[I.y,F.y]:[I.x,F.x]});return[Math.min(...q),Math.max(...q)]};for(const[,k]of v){const C=[...k.members.values()].map(M=>({members:M,run:z(M,k.vertical)})).sort((M,I)=>M.run[0]-I.run[0]),q=[];for(const M of C){const I=q[q.length-1];I&&I.some(F=>F.run[0]D.has(ot)))continue;const I=M.map(ot=>ot.members),F=I.length,Z=(k.span[1]-k.span[0])/(F+1);ZJ.forEach(U=>L.set(U,k.span[0]+Z*(et+1))));const tt=E(P);tt.scoreot.forEach(J=>L.set(J,k.span[0]+Z*(tt+1)))),S=K}}B.lines=m();for(const k of V)p?.(`${s.edges[k].from} to ${s.edges[k].to} is two columns apart, so its line is not drawn; its row still writes the target`);B.crossings=Mt(B.lines),B.through=qt(B.lines,g,s),B.outside=ne(B.lines,f,b,r);const{obstacles:T,groups:G}=Pt(a,l,o,_);T.heads=B.lines.map(k=>Xt(k,r));const N=De(s,B.lines,g,T,G,{l:0,t:0,r:f,b},r,e,{ox:y,oy:$});return B.labels=N.labels,B.unseated=N.unseated,B.bounded=N.bounded,B.overlaps=[...new Set(te(B.lines,null).flat())],B}function Ke(t,e){return te(t,e).length}function te(t,e){const n=[];for(let s=0;s=l)continue;const[f,b]=c?[p.x,h.x]:[p.y,h.y],[O,_]=c?[u.x,g.x]:[u.y,g.y];Math.min(Math.max(f,b),Math.max(O,_))-Math.max(Math.min(f,b),Math.min(O,_))>1&&n.push([o.i,a.i])}}return n}function*ee(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const p=l===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-p<-.5||a.x+p>e+.5||a.y-p<-.5||a.y+p>n+.5})&&r.push(o.i);return r}function qt(t,e,n){const s=[];for(const r of t){const o=ft(r.pts);e.some(a=>o.some(([l,p])=>Te(l,p,a)))&&s.push(r.i)}return s}function Ve(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:l}=t,p=r.space,h=new Map;a.querySelectorAll(`.${o}-node`).forEach($=>h.set($.dataset.node,ct($,l)));const u=a.querySelector(`.${o}-steps`),g=u?ct(u,l).b:e.h,c=$=>{const i=h.get($);return i?n.x((i.l+i.r)/2,r.hair):0};for(const $ of s.nodes){const i=h.get($.id);i&&e.lifelines.push({x:c($.id),y1:i.b,y2:g})}const y=$=>h.get($.id);return a.querySelectorAll(`.${o}-msg`).forEach($=>{const i=$.dataset.from,f=$.dataset.to,b=$.dataset.kind??"plain",O=xt(b,r),_=ct($,l),B=n.y((_.t+_.b)/2,O),j=Number($.querySelector(`.${o}-num`)?.textContent??0),R=c(i),Q=c(f);let A;if(i===f){const m=$.dataset.self==="start"?-p("6"):p("6"),S=n.y(B-p("2"),O),E=n.y(B+p("2"),O);A=[{x:R,y:S},{x:n.x(R+m,O),y:S},{x:n.x(R+m,O),y:E},{x:R,y:E}]}else A=[{x:R,y:B},{x:Q,y:B}];e.lines.push({i:j,from:i,to:f,kind:b,pts:A,tip:A[A.length-1],dir:Lt(A),width:O});const V=$.querySelector(`.${o}-said`),v=$.querySelector(`.${o}-note`),D=s.byId.get(i),L=s.byId.get(f);if(!D||!L)return;const x=i===f?(()=>{const m=s.nodes[D.i+($.dataset.self==="start"?-1:1)],S=m?c(m.id):$.dataset.self==="start"?0:e.w;return Math.abs(S-R)-p("6")-p("2-5")-p("2")})():Math.abs(Q-R)-2*p("2");Math.max(V?V.getBoundingClientRect().width:0,v?v.getBoundingClientRect().width:0)>x+.5&&e.unseated.push(j)}),e}function oe(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:l,origin:p}=t,h=o.space,u=Ut(r,l,p,a),g=[...u.values()],c=p.left-Math.floor(p.left),y=p.top-Math.floor(p.top),$=Kt(c,y),i=l.clientWidth,f=l.clientHeight,b={w:i,h:f,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:y},O=ht();if(r.type==="sequence"||r.type==="schema")return{geo:b,grow:O};const _=i-(parseFloat(getComputedStyle(l).paddingRight)||0),B=(x,d,m)=>{const S=[x];for(let E=1;E<=(pt(s,d)??0);E++)S.push({...x,t:x.t+m*h("4")*E,b:x.b+m*h("4")*E});return S},j=new Map;l.querySelectorAll(`.${a}-node`).forEach(x=>{const d=x.parentElement,m=ct(d,p),S=getComputedStyle(d);j.set(x.dataset.node,m.r-(parseFloat(S.paddingRight)||0)-(parseFloat(S.borderRightWidth)||0))});const R=r.nodes,Q=x=>u.get(R[x].id),A=[],V=x=>xt(r.edges[x].kind,o);r.edges.forEach((x,d)=>{const m=n.routes[d],S=u.get(x.from),E=u.get(x.to),z=V(d);let T=[];const G=x.label,N=G?e(G,"label"):0,k=16,C=h("4");if(m==="down"||m==="up"){const M=Math.max(S.rect.l,E.rect.l),I=Math.min(S.rect.r,E.rect.r),F=r.edges.map((W,K)=>({o:W,j:K})).filter(({o:W,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(W.from===x.from&&W.to===x.to||W.from===x.to&&W.to===x.from)),Z=F.findIndex(W=>W.j===d),P=F.length<2?.5:F.length===2?Z===0?.25:.75:(Z+1)/(F.length+1),X=$.x(M+(I-M)*P,z);if(T=m==="down"?[it(S,"bottom",X),it(E,"top",X)]:[it(S,"top",X),it(E,"bottom",X)],G){let W=Math.min(T[0].y,T[1].y),K=Math.max(T[0].y,T[1].y);m==="down"?K-=o.head:W+=o.head;const ot=[...l.querySelectorAll(`.${a}-group`)].map(U=>ct(U,p));let tt=[[W,K]];for(const U of ot)for(const nt of[U.t,U.b])tt=tt.flatMap(([at,H])=>nt>at+1&&ntot.some(at=>(U+nt)/2>at.t&&(U+nt)/2at.l&&X1){const U=tt.filter(([at,H])=>!J(at,H));[W,K]=(U.length?U:tt).reduce((at,H)=>H[1]-H[0]>at[1]-at[0]?H:at)}const et=[1/2,1/3,2/3].map(U=>{const nt=W+(K-W)*U;return{l:X-N/2-h("1"),r:X+N/2+h("1"),t:nt-k/2,b:nt+k/2}});A.push({k:d,cands:et,on:!0,card:m==="down"?x.to:x.from})}}else if(m==="trunk"||m==="rail"){const M=$.x(Math.max(S.rect.l,m==="rail"?E.rect.l:S.rect.l)+h(m==="trunk"?"8":"3"),z),I=it(S,"bottom",M);if(m==="rail"){if(T=[I,it(E,"top",M)],G){const F=E.rect.t-h("6");A.push({k:d,cands:B({l:M+h("2-5"),r:M+h("2-5")+N,t:F-k/2,b:F+k/2},x.to,-1),on:!1,card:x.to})}}else{const F=$.x(E.rect.l+h("6"),z),Z=$.y(E.rect.t-C,z);T=[I,{x:M,y:Z},{x:F,y:Z},it(E,"top",F)],G&&A.push({k:d,cands:B({l:F+h("2-5"),r:F+h("2-5")+N,t:Z-k/2,b:Z+k/2},x.to,-1),on:!1,card:x.to})}}else{const M=Math.min(j.get(x.from)??i,j.get(x.to)??i),I=$.x(n.gutter?_+(n.lanes[d]?2*h("3-5"):h("3-5")):M-h("2-5"),z),F=$.y(S.rect.t+(S.rect.b-S.rect.t)*n.exits[d],z),Z=it(S,"right",F),P=$.x(E.rect.r-h("6"),z),X=m==="end-down",W=$.y(X?E.rect.t-C:E.rect.b+C,z);T=[Z,{x:I,y:Z.y},{x:I,y:W},{x:P,y:W},it(E,X?"top":"bottom",P)];const K=X?x.to:R[E.i+1]?.id??x.to;G&&A.push({k:d,cands:B({l:P-h("2-5")-N,r:P-h("2-5"),t:W-k/2,b:W+k/2},K,X?-1:1),on:!1,card:K})}const q=Vt(T,z,$);b.lines.push({i:d,from:x.from,to:x.to,kind:x.kind,pts:q,tip:q[q.length-1],dir:Lt(q),width:z})}),b.crossings=Mt(b.lines),b.through=qt(b.lines,g,r),b.outside=ne(b.lines,i,f,o);const{obstacles:v}=Pt(l,p,a,0);v.heads=b.lines.map(x=>Xt(x,o));const D=[],L={l:0,t:0,r:i,b:f};for(const x of A){const d=E=>{const z=Dt(E,h("1"));return E.lL.r+.5||E.tL.b+.5||g.some(T=>Gt(z,T))||D.some(T=>dt(z,T))||v.heads.some(T=>dt(z,T))||v.rects.some(T=>dt(z,T))||b.lines.some(T=>T.i!==x.k&&ft(T.pts).some(([G,N])=>dt(z,Yt(G,N,T.width))))},m=x.cands.find(E=>!d(E));m||(O[x.card]=(O[x.card]??0)+1,b.unseated.push(x.k));const S=m?Qt(m,c,y,E=>!d(E)):x.cands[0];D.push(S),b.labels.push({i:x.k,text:r.edges[x.k].label,box:S,on:x.on})}return{geo:b,grow:O}}function Ze(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...B})),g=u[u.length-1];g.x-=o.x*h,g.y-=o.y*h;const c=e.tip.x-o.x*l,y=e.tip.y-o.y*l,$=-o.y*p,i=o.x*p,f=B=>Math.round(B*100)/100,b=lt(e.kind),O=a?``:``,_=e.dot?``:"";return`${O}${_}`}function se(t,e,n,s){const r=new Map,o=new Map;for(const l of e.crossings)o.has(l.under)||o.set(l.under,[]),o.get(l.under).push(l);let a="";for(const[l,p]of o){const h=`${s}-cut-${l}`;r.set(l,h);const u=p.map(g=>{const c=e.lines[g.top],y=e.lines[g.under],$=c.width/2+n.cut,i=y.width/2+1;return g.underVertical?``:``}).join("");a+=`${u}`}return{defs:a,ids:r}}function ae(t,e,n,s){const{defs:r,ids:o}=se(t,e,n,s),a=e.lifelines.map(u=>``).join(""),l=e.lines.map((u,g)=>Ue(t,u,n,o.get(g)??null,u.from===u.to?n.radiusXs:n.radius)).join(""),p=`${r?`${r}`:""}${a}${l}`,h=e.labels.map(u=>`${lt(u.text)}`).join("");return p+h}function re(t,e,n,s,r,o,a,l){const h=t.querySelector(`.${n}-drawing`);if(!h||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const u=Be(t),g=Fe(h,n),c=He(e,u,g);l?.(c.least);const y=t.clientWidth,$=(()=>{const v=document.activeElement;return v&&h.contains(v)&&v.dataset.node?v.dataset.node:void 0})(),i=v=>gt(e,v)?{...v,stop:v.stop&&e.byId.has(v.stop)?v.stop:e.nodes[0]?.id,keep:void 0}:{...v,stop:v.stop??e.nodes[0]?.id,keep:$&&v.layout!=="drawn"?$:void 0};let f=!1;const b=v=>{if(f=!1,e.type!=="flowchart")return v;o({...v,heights:void 0,words:void 0});const D=ht(),L=ht();return h.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const d=x.querySelector(`.${n}-words`);if(!d)return;const m=x.getBoundingClientRect(),S=T=>{const G={w:T.width+2*u.space("2-5"),h:T.height+2*u.space("2")},N=1-G.w/m.width,k=N>.05?G.h/2/N:G.h*10;return Math.max(u.space("16"),Math.ceil(m.width/5),Math.ceil(2*k))},E=d.getBoundingClientRect();let z=S(E);if(z>m.width){const T=C=>(x.style.setProperty("--_ww",`${C}px`),d.getBoundingClientRect()),G=Math.floor(x.clientWidth-2*u.space("2-5"));let N=Math.ceil(E.width),k=E.height;for(;N1;){const F=C+q>>1;T(F).heightm.width&&(f=!0)}),{...v,heights:D,words:Object.keys(L).length?L:void 0}},O=()=>({m:e,tk:u,P:n,drawing:h,origin:h.getBoundingClientRect(),warn:a}),_=r.autoOpen?{open:!1,autoOpen:void 0}:{},B=(v,D)=>D.map(L=>$t(e,v.lines.find(x=>x.i===L))).join(", ");if(y>=c.least){const v=d=>{let m=i({...r,..._,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:d||void 0});return m=b(m),o(m),{dd:m,g:Ge(O(),g)}};let{dd:D,g:L}=v(!1);const x=d=>d.through.length>0||d.outside.length>0||(d.overlaps?.length??0)>0||f;if(!x(L)&&L.unseated.length&&L.unseated.every(d=>L.bounded?.includes(d))){const d=v(!0);!x(d.g)&&!d.g.unseated.length&&({dd:D,g:L}=d)}if(!x(L)&&!L.unseated.length)return L.crossings.length&&a?.(`${L.crossings.length} crossing${L.crossings.length===1?"":"s"} in the drawn layout: ${L.crossings.map(d=>`${$t(e,L.lines[d.top])} over ${$t(e,L.lines[d.under])}`).join("; ")}`),{dyn:D,geo:L,ink:ae(n,L,u,s),tokens:u,least:c.least};f&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: a decision would be taller than it is wide`),L.through.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.through)} would pass through a node`),L.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.overlaps)} would lie on one another`),L.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${B(L,L.outside)} would leave the drawing`),L.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: no clean seat for ${L.unseated.map(d=>e.type==="sequence"?`message ${d}`:`"${e.edges[d]?.label}"`).join(", ")}`)}let j=i({...r,..._,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(j=b(j),o(j),e.type==="sequence"||e.type==="schema")return{dyn:j,geo:null,ink:"",tokens:u,least:c.least};const R=Bt(e);let Q=oe(O(),g,R,j.grow);for(let v=0;v<6&&Object.keys(Q.grow).length;v++){const D=ht(j.grow);for(const[L,x]of Object.entries(Q.grow))D[L]=(pt(D,L)??0)+x;j={...j,grow:D},o(j),Q=oe(O(),g,R,D)}const A=Q.geo;if(A.unseated.length>0||A.through.length>0||A.outside.length>0||R.third){A.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(A.unseated)].map(L=>`"${e.edges[L]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),A.through.length&&a?.(`in the stacked drawing ${B(A,A.through)} would pass through a node, so its lines are not drawn`),A.outside.length&&a?.(`in the stacked drawing ${B(A,A.outside)} would leave the drawing, so its lines are not drawn`),R.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const v={...A,lines:[],labels:[],crossings:[]};return{dyn:i({...j,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:v,ink:"",tokens:u,least:c.least}}return A.crossings.length&&a?.(`${A.crossings.length} crossing${A.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${A.crossings.map(v=>`${$t(e,A.lines[v.top])} over ${$t(e,A.lines[v.under])}`).join("; ")}`),{dyn:j,geo:A,ink:ae(n,A,u,s),tokens:u,least:c.least}}function $t(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Xe(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const i of n?.lines??[])i.from===o&&a.add(i.to),i.to===o&&a.add(i.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(i=>i.toggleAttribute("data-near",a.has(i.dataset.node))),!n||!s)return;const l=i=>!!o&&(i.from===o||i.to===o),p=t.querySelector(`.${e}-edges`),h=new Map;t.querySelectorAll(`.${e}-edge`).forEach(i=>h.set(i.getAttribute("data-edge"),i));for(const i of n.lines){const f=h.get(String(i.i));f&&(f.toggleAttribute("data-lit",l(i)),f.toggleAttribute("data-dim",!!o&&!l(i)))}if(t.querySelectorAll(`.${e}-label`).forEach(i=>{const f=n.lines.find(b=>String(b.i)===i.dataset.edge);i.toggleAttribute("data-lit",!!(f&&l(f)))}),p){for(const i of n.lines)if(l(i)){const f=h.get(String(i.i));f&&p.appendChild(f)}}const u=Mt(n.lines,l),{defs:g,ids:c}=se(e,{...n,crossings:u},s,r),y=t.querySelector(`.${e}-svg`);if(!y)return;let $=y.querySelector("defs");!$&&g&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),y.insertBefore($,y.firstChild)),$&&($.innerHTML=g),n.lines.forEach((i,f)=>{const b=h.get(String(i.i))?.querySelector(`.${e}-line`);if(!b)return;const O=c.get(f);O?b.setAttribute("mask",`url(#${O})`):b.removeAttribute("mask")})}var Ye=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Qe(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Ye()?"done":"pending")}}function ie(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Pe(t,e,n){const s=t.byId.get(e)?.i??0,r=t.nodes.length;let o;if(n==="ArrowRight"||n==="ArrowDown")o=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")o=s-1;else if(n==="Home")o=0;else if(n==="End")o=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,o))].id}var tn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],le=["data-layout","data-measured","data-bare","data-motion"],en=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ce=t=>t==null||t===!1;function nn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function de(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?le:tn;for(const a of s)ce(e.a[a])&&t.removeAttribute(a);for(const[a,l]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const h=t.style,u=new Map(String(l??"").split(";").map(g=>{const c=g.indexOf(":");return[g.slice(0,c).trim(),g.slice(c+1).trim()]}).filter(([g])=>g));for(const[g,c]of u)h.getPropertyValue(g).trim()!==c&&h.setProperty(g,c);for(const g of en)u.has(g)||h.removeProperty(g);continue}if(n&&!le.includes(a))continue;if(ce(l)){t.removeAttribute(a);continue}const p=l===!0?"":String(l);t.getAttribute(a)!==p&&t.setAttribute(a,p)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let l=o;lt.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(c,y,$){return{prefix:n,base:c,hasSource:y.source!==void 0&&y.source!==null&&y.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(c,y,$,i){var f=function(b){return''+lt(b)+""};return{source:lt(String(y.source||"")),summary:lt(String(y.summary||"")),hint:zt(c).map(function(b){return""+b.keys.map(f).join(" ")+" "+lt(b.words)+""}).join(""),toggle:'"}}function a(c,y,$){var i=kt(c),f=Wt(i,{},r(y,c,$)),b=St(f,o(i,c,y,!1)),O=b.indexOf(">");return{open:b.slice(0,O+1),inner:b.slice(O+1,b.length-9),warnings:i.warnings}}var l=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],p=["--_cols","--_gpad","--_track"];function h(c,y,$,i){c.__diagram&&c.__diagram.stop();var f=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),b=kt(y);if(!$||!f||!c.querySelector(":scope > .diagram-drawing")){if(!f||!c.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var O=a(y,f,i),_=document.createElement("div");_.innerHTML=O.open+"";var B=_.firstChild;l.forEach(function(H){c.removeAttribute(H)}),p.forEach(function(H){c.style.removeProperty(H)});for(var j=0;j :not(script[data-diagram])").forEach(function(H){H.remove()}),c.insertAdjacentHTML("beforeend",O.inner)}b.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var Q=r(f,y,i),A={},V=null,v=null,D=null,L=Object.create(null),x=function(H){L[H]||(L[H]=1,console.warn("Basalt diagram: "+H))},d=function(H){de(c,Wt(b,H,Q))},m=c.querySelector(".diagram-ink"),S=c.querySelector(".diagram-toggle"),E=!i&&b.motion.animated&&typeof e.diagramMotion=="function",z=null,T=null,G=function(){E&&ie(c)};function N(){Xe(c,n,V&&V.geo,V&&V.tokens,f,v||D)}function k(){S&&(S.setAttribute("aria-expanded",String(!!A.open)),S.firstElementChild.textContent=A.open?"Hide the list":"View as list")}function C(){V=(i?i.measure:re)(c,b,n,f,A,d,x),A=V.dyn,d(A),k(),gt(b,A)||(D=null);var H=m&&V.ink!==T;H&&(m.innerHTML=V.ink,T=V.ink),N(),E&&V.tokens&&(Qe(c,!!(V.geo&&V.geo.lines.length)),H&&z&&z.redrawn()),i&&i.onMeasured&&V.tokens&&i.onMeasured(V,c)}function q(H){A=H,d(A)}function M(H){var st=A.stop;A=Object.assign({},A,{stop:H}),on(c,n,st,H)}var I=function(H){var st=H&&H.closest?H.closest(".diagram-node"):null;return st&&c.contains(st)?st:null};function F(H){var st=I(H.target);if(!(!st||H.defaultPrevented)){if(G(),H.key==="Escape"){!i&&(v||D)&&(H.preventDefault(),v=D=null,N());return}if(gt(b,A)){var ut=Pe(b,st.getAttribute("data-node"),H.key);if(ut){H.preventDefault(),M(ut);var ue=c.querySelector('.diagram-node[data-node="'+CSS.escape(ut)+'"]');ue&&ue.focus()}}}}function Z(H){var st=I(H.target);if(st){G();var ut=st.getAttribute("data-node");v=st.matches(":focus-visible")?ut:null,gt(b,A)&&A.stop!==ut&&M(ut),N()}}function P(H){var st=I(H.target);st&&(I(H.relatedTarget)||(v=null),A.keep===st.getAttribute("data-node")&&q(Object.assign({},A,{keep:void 0})),N())}function X(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var st=I(H.target);st&&G();var ut=st&>(b,A)?st.getAttribute("data-node"):null;ut!==D&&(D=ut,N())}}function W(){D&&(D=null,N())}function K(){G(),q(Object.assign({},A,{open:!A.open,autoOpen:void 0})),k()}c.addEventListener("keydown",F),c.addEventListener("focusin",Z),c.addEventListener("focusout",P),c.addEventListener("pointerover",X),c.addEventListener("pointerleave",W),S&&S.addEventListener("click",K),C();var ot=c.clientWidth,tt=0,J=!0,et=new ResizeObserver(function(){Math.abs(c.clientWidth-ot)<.5||(ot=c.clientWidth,cancelAnimationFrame(tt),tt=requestAnimationFrame(C))});et.observe(c),document.fonts&&document.fonts.ready.then(function(){J&&C()});var U=matchMedia("(forced-colors: active)"),nt=b.nodes.some(function(H){return H.mark});nt&&U.addEventListener("change",C),E&&(z=e.diagramMotion(c,{fig:c,P:n,base:f,model:function(){return b},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},y));var at=!i&&y.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,y,{model:b,settle:G,animated:E}):null;c.__diagram={stop:function(){at&&at.destroy(),J=!1,et.disconnect(),cancelAnimationFrame(tt),nt&&U.removeEventListener("change",C),z&&z.destroy(),c.removeEventListener("keydown",F),c.removeEventListener("focusin",Z),c.removeEventListener("focusout",P),c.removeEventListener("pointerover",X),c.removeEventListener("pointerleave",W),S&&S.removeEventListener("click",K)},layout:C,key:u(y),send:z&&z.sendValue?z.sendValue:null}}function u(c){try{return JSON.stringify(c,function(y,$){return y==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var y=c.querySelector(":scope > script[data-diagram]");if(y)try{h(c,JSON.parse(y.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:h,buildModel:kt,figureKey:Se,figureList:_e,hintEntries:zt,toHtml:St,escapeHtml:lt,settleEntrance:ie,measureFigure:re},t.diagram=function(c,y){var $=c.__diagram,i=$&&$.send?u(y):null;if(i!==null&&i===$.key){$.send(y.packet?y.packet.send:void 0);return}h(c,y)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); +(()=>{var he=["top","right","bottom","left"],pe=["main","plain","dashed"],ge=[2,3,4,5,6],rt=t=>t==null||t===""?void 0:String(t),ft=t=>Object.assign(Object.create(null),t),pt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function At(t,e={}){const s=e.checks!==!1,r=[],o=d=>{r.push(d)},a=t.legend??{},i={};for(const d of["main","plain","dashed","focal","group"]){const y=rt(a[d]);y&&(i[d]=y)}const f=t.stepLabel,p=typeof f=="function"?d=>String(f(d)):typeof f=="string"?(d=>f.replace("{n}",String(d))):d=>`Step ${d}`,u=t.shapeLabels??{},g={terminal:rt(u.terminal)??"Start or end",step:rt(u.step)??"Step",decision:rt(u.decision)??"Decision"},c=t.heading===void 0?3:ge.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),m=(d,y)=>d==null?"plain":pe.includes(d)?d:(o(`"${String(d)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),$=d=>{if(d!=null){if(he.includes(d))return d;o(`"${String(d)}" is not a side (top, right, bottom or left): the derived side is used`)}},l=(d,y)=>typeof d=="number"&&Number.isInteger(d)&&d>=1?d:(o(`${y} is ${JSON.stringify(d)}, not a whole number from 1: it is placed at 1`),1),h=[],b=[];let q=[];const L=[],C=[],j=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(j)||o(`"${String(j)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),j==="architecture"||j==="flowchart"){for(const d of t.nodes??[]){const y=j==="flowchart"&&d.shape==="decision"?"decision":j==="flowchart"&&d.shape==="terminal"?"terminal":"box",M=String(d.id??""),B=l(d.row,`the row of ${M}`);h.push({id:M,i:h.length,name:String(d.name??""),kind:y==="decision"?void 0:rt(d.kind),detail:y==="decision"?void 0:rt(d.detail),mono:!!d.detailMono,focal:!!d.focal,col:l(d.col,`the column of ${M}`),row:B,row2:B,branch:!!d.branch,shape:y,group:j==="architecture"?rt(d.group):void 0,mark:j==="architecture"?me(d.mark):void 0})}if(j==="architecture")for(const d of t.groups??[]){const y=String(d.id??"");L.push({id:y,label:String(d.label??""),members:h.filter(M=>M.group===y).map(M=>M.id)})}}else if(j==="data-flow"){q=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const d=new Map(q.map((y,M)=>[y.id,M+1]));for(const y of t.nodes??[]){const M=String(y.id??""),B=String(y.lane??""),H=d.get(B);H===void 0&&o(`a node (${M}) names the lane "${B}", which is not in lanes`);const T=h.length+1;h.push({id:M,i:h.length,name:String(y.name??""),kind:p(T),detail:rt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:l(y.col,`the column of ${M}`),row:H??1,row2:H??1,branch:!1,shape:"box",lane:H??1,laneLabel:q[(H??1)-1]?.label??B,step:T})}}else if(j==="sequence"){(t.participants??[]).forEach((y,M)=>{const B=String(y.name??"");h.push({id:String(y.id??""),i:M,name:B,kind:rt(y.kind),mono:!1,focal:!!y.focal,col:M+1,row:1,row2:1,branch:!1,shape:"participant",short:rt(y.short)??B})});let d=0;for(const y of t.steps??[])"band"in y?C.push({band:String(y.band??"")}):(d++,C.push({n:d,from:String(y.from??""),to:String(y.to??""),label:String(y.label??""),note:rt(y.note),kind:m(y.kind,`message ${d}`)}))}else if(j==="schema")for(const d of t.tables??[]){const y=String(d.name??""),[M,B]=Array.isArray(d.row)?d.row:[d.row,d.row],H=l(M,`the row of ${y}`),T=Math.max(H,l(B,`the last row of ${y}`)),V=d.more===void 0||d.more===null?void 0:Number.isInteger(d.more)&&d.more>0?d.more:(o(`${y}'s "more" is ${JSON.stringify(d.more)}, not a whole number from 1: it is left out`),void 0);h.push({id:y,i:h.length,name:y,mono:!0,focal:!!d.focal,col:l(d.col,`the column of ${y}`),row:H,row2:T,branch:!1,shape:"table",more:V,columns:(d.columns??[]).map(v=>({name:String(v.name??""),type:rt(v.type),key:v.key==="PK"||v.key==="FK"?v.key:(v.key!==void 0&&v.key!==null&&o(`${y}.${String(v.name)}'s key is "${String(v.key)}", not PK or FK: it is left out`),void 0)}))})}const F=new Map;for(const d of h)d.id?F.has(d.id)&&o(`the id "${d.id}" is used twice`):o("a node has no id"),F.set(d.id,d);if(j==="schema")(t.tables??[]).forEach(d=>(d.columns??[]).forEach((y,M)=>{const B=rt(y.references);if(!B)return;const[H,T]=B.split("."),V=F.get(H??""),v=V?.columns?.findIndex(I=>I.name===T)??-1;if(!V||v<0){o(`${String(d.name)}.${String(y.name)} references ${B}, which is not a shown column`);return}const O=F.get(String(d.name??""));O.columns[M].ref={table:H,column:T,row:v},b.push({i:b.length,from:O.id,to:H,kind:"plain",fromRow:M,toRow:v,fk:!0})}));else if(j!=="sequence")for(const d of t.edges??[]){const y=String(d.from??""),M=String(d.to??"");if(!F.has(y)||!F.has(M)){o(`a line names ${F.has(y)?M:y}, which is not a node`);continue}const B=rt(d.label);B&&B.length>jt&&o(`the label "${B}" is over ${jt} characters: longer words belong in the node or the summary`),b.push({i:b.length,from:y,to:M,kind:m(d.kind,`the line from ${y} to ${M}`),label:B,fromSide:$(d.fromSide),toSide:$(d.toSide),flow:j!=="flowchart"&&d.flow===!0?!0:void 0})}else for(const d of C)"n"in d&&(!F.has(d.from)||!F.has(d.to))&&o(`message ${d.n} names ${F.has(d.from)?d.to:d.from}, which is not a participant`);if(s&&j!=="sequence"){const d=new Map;for(const y of h)for(let M=y.row;M<=y.row2;M++){const B=`${y.col}:${M}`;d.has(B)&&o(`${y.id} and ${d.get(B)} share the cell at column ${y.col}, row ${M}`),d.set(B,y.id)}}if(s){for(const y of L){const M=y.members.map(T=>F.get(T));if(!M.length)continue;const B={c1:Math.min(...M.map(T=>T.col)),c2:Math.max(...M.map(T=>T.col)),r1:Math.min(...M.map(T=>T.row)),r2:Math.max(...M.map(T=>T.row2))};for(const T of h)T.group!==y.id&&T.col>=B.c1&&T.col<=B.c2&&T.row>=B.r1&&T.row<=B.r2&&o(`${T.id} is inside the box of the group "${y.label}" but not a member`);const H=M.map(T=>T.i);Math.max(...H)-Math.min(...H)+1!==H.length&&o(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of h)y.group&&!L.some(M=>M.id===y.group)&&o(`${y.id} names the group "${y.group}", which is not in groups`);h.filter(y=>y.focal).length>1&&o("more than one node is focal: a diagram has one at most");const d=new Set(j==="sequence"?C.flatMap(y=>"n"in y?[y.kind]:[]):b.map(y=>y.kind));d.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),d.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),h.some(y=>y.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const Q=j==="architecture"||j==="data-flow",A=d=>Array.isArray(d)&&d.length>1?d.map(String):void 0,K=Q&&t.packet&&typeof t.packet=="object"?t.packet:void 0,k=K&&A(K.path),D={animated:t.motion==="animated",pulse:Q?A(t.pulse):void 0,packet:k?{path:k,repeat:K.repeat===!0,send:K.send}:void 0,run:j==="sequence"&&t.run===!0};if(s)for(const d of h){const y=d.mark?.says;if(!y?.length)continue;const M=[d.name,d.kind,d.detail].filter(Boolean).join(" ").toLowerCase();y.some(B=>M.includes(B.toLowerCase()))||o(`${d.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const E=Math.max(1,...h.map(d=>d.col)),x=j==="data-flow"?Math.max(1,q.length):Math.max(1,...h.map(d=>d.row2)),R={type:j,title:String(t.title??""),heading:c,legend:i,nodes:h,byId:F,edges:b,groups:L,lanes:q,steps:C,cols:E,rows:x,shapeLabels:g,stepWord:p,warnings:r,motion:D,memo:new Map};return s&&h.length>1&&!vt(R)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),R}function me(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=rt(e.onLight);if(n)return{onLight:n,onDark:rt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ct=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function yt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var jt=28,mt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Bt(t,e){return t.legend[e]}function ye(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function be(t,e){return yt(t,`sentence:${e.i}`,()=>$e(t,e))}function $e(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,r=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(mt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`)}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?ye(t,e):e.kind;if(n.push(mt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(mt(e.detail)),e.group){const a=t.groups.find(i=>i.id===e.group);a&&n.push(`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${a.label})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${a.label})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(mt(t.legend.focal)),n.join(" ")}function we(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function w(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var xe={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>xe[e]),ve=" br img input meta link hr path polygon polyline circle rect line ";function Et(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${it(String(r))}"`}return ve.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Et(s,e)).join("")}`}var ke=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function gt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Me(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Tt(t){let e=0;for(const n of t.groups){const s=n.members.map(r=>t.byId.get(r).col);s.length&&(Math.min(...s)===1&&(e|=1),Math.max(...s)===t.cols&&(e|=2))}return(e&1)+(e>>1&1)}function Lt(t){return t.type==="sequence"?t.nodes.length:t.cols}function Rt(t){return yt(t,"plan",()=>Se(t))}function Se(t){const e=t.nodes,n=l=>t.type==="data-flow"||!e[l].branch,s=t.edges.map(l=>{const h=t.byId.get(l.from).i,b=t.byId.get(l.to).i,L=e.slice(Math.min(h,b)+1,Math.max(h,b)).every(C=>!n(C.i));return b===h+1&&!(n(h)&&!n(b))?"down":b===h-1?"up":b>h&&n(h)&&!n(b)&&L?"trunk":b>h&&n(h)&&n(b)&&L?"rail":b>h?"end-down":"end-up"}),r=t.edges.map((l,h)=>({e:l,k:h})).filter(({k:l})=>s[l]==="end-down"||s[l]==="end-up"),o=l=>{const h=t.byId.get(l.from).i,b=t.byId.get(l.to).i;return[Math.min(h,b),Math.max(h,b)]},a=(l,h)=>{const[b,q]=o(l),[L,C]=o(h);return b{const h=t.byId.get(l.from).i,[b,q]=o(l);return!n(h)&&e.slice(b+1,q).every(L=>!n(L.i))&&r.every(L=>L.e===l||!a(L.e,l))}),f=r.length>0&&(t.type==="data-flow"||!i),p=l=>{const[h,b]=o(l);return b-h},u=t.edges.map(()=>0);let g=!1;const c=[];for(const l of[...r].sort((h,b)=>p(h.e)-p(b.e)||h.k-b.k)){let h=0;for(const b of c)a(b.e,l.e)&&(h=Math.max(h,u[b.k]+1));u[l.k]=h,h>1&&(g=!0),c.push(l)}const m=t.edges.map(()=>.5);for(const l of e){const h=r.filter(({e:L})=>L.from===l.id);if(h.length<2)continue;const b=h.filter(({k:L})=>s[L]==="end-down").sort((L,C)=>p(C.e)-p(L.e)||L.k-C.k);[...h.filter(({k:L})=>s[L]==="end-up").sort((L,C)=>p(L.e)-p(C.e)||C.k-L.k),...b].forEach(({k:L},C,j)=>{m[L]=j.length===2?C===0?1/3:2/3:(C+1)/(j.length+1)})}const $=ft();for(let l=1;l{const A=s[Q],K=t.byId.get(F.from).i,k=t.byId.get(F.to).i,D=k===l&&(A==="down"||A==="trunk"||A==="rail"||A==="end-down"),E=K===l&&k===l-1&&A==="up",x=k===l-1&&A==="end-up";D&&(A==="trunk"||A==="end-down")&&(C=!0),x&&(j=!0),(D||E||x)&&F.label&&(q++,L=Math.max(L,A==="trunk"?40:48))}),(q>1||C&&j)&&(L=64),$[h.id]=L}return{routes:s,gutter:f,lanes:u,exits:m,gaps:$,third:g}}var bt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Ft(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return w("svg",{class:`${t}-swatch`,"data-kind":n,...bt(24,16)},e==="fk"?w("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,w("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?w("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):w("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function $t(t,e){return e==="decision"?w("svg",{class:`${t}-swatch`,"data-shape":e,...bt(16,16)},w("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?w("svg",{class:`${t}-swatch`,"data-shape":e,...bt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):w("svg",{class:`${t}-swatch`,"data-shape":e,...bt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function zt(t,e){return yt(e,`key:${t}`,()=>Ee(t,e))}var Ae=zt;function Ee(t,e){const n=[],s=(o,a,i={})=>n.push(w("li",{class:`${t}-entry`,...i},o,w("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),w("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s($t(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s($t(t,"box"),e.shapeLabels.step),o.has("decision")&&s($t(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Ft(t,o),a,{"data-line":""})}return e.type==="schema"&&e.edges.length&&(s(Ft(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(w("li",{class:`${t}-entry`,"data-when":"stacked"},w("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),w("span",null,"The table a foreign key references")))),e.nodes.some(o=>o.focal)&&e.legend.focal&&s($t(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s($t(t,"group"),e.legend.group),n.length?w("div",{class:`${t}-key`},w("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Le(t,e){const n=e==="main"?6:6.5;return w("svg",{class:`${t}-arrow`,"data-kind":e,...bt(20,12)},w("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?w("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):w("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function qe(t,e,n){if(n.shape==="decision")return[w("span",{class:`${t}-words`},w("span",{class:`${t}-name`},n.name))];const s=[];return e.type==="data-flow"?s.push(w("span",{class:`${t}-kind`},n.kind,w("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(w("span",{class:`${t}-kind`},n.kind)),s.push(w("span",{class:`${t}-name`},n.name)),n.detail&&s.push(w("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Mt(n.detail).flatMap((r,o)=>[o?" ":"",w("span",{class:`${t}-run`},r)]):n.detail)),s}function Ie(t,e){return[w("span",{class:`${t}-th`},w("span",{class:`${t}-tname`},e.name)),w("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>w("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},w("span",{class:`${t}-keyseat`},n.key??""),w("span",{class:`${t}-cname`},n.name),n.ref?w("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?w("span",{class:`${t}-ctype`},n.type):null))),e.more?w("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ht=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function qt(t,e,n,s){const{P:r}=t,o=Me(e,s)||s.keep===n.id,a=gt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const f=t.plan;if(f&&n.i>0){const c=pt(f.gaps,n.id)??32,m=pt(s.grow,n.id)??0;i.push(`--_gap:${m?`calc(${Ht(c)} + var(--basalt-space-4) * ${m})`:Ht(c)}`)}const p=pt(s.heights,n.id);p&&i.push(`--_h:${p}px`);const u=pt(s.words,n.id);u&&i.push(`--_ww:${u}px`);const g=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return w("div",{class:`${r}-node`,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o?"img":void 0,"aria-label":o?be(e,n):void 0,tabindex:g},n.shape==="decision"?w("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},w("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?w("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ct(n.mark.onLight)};--_md:${Ct(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Ie(r,n):qe(r,e,n))}function Oe(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((a,i)=>w("div",{class:`${s}-lane`,style:`--_r:${i+1}`,"aria-hidden":"true"},w("span",{class:`${s}-lane-name`},a.label)))),e.type==="architecture")for(const a of e.groups){const i=a.members.map(c=>e.byId.get(c));if(!i.length)continue;const f=Math.min(...i.map(c=>c.col)),p=Math.max(...i.map(c=>c.col)),u=Math.min(...i.map(c=>c.row)),g=Math.max(...i.map(c=>c.row2));r.push(w("div",{class:`${s}-gbox`,"data-group":a.id,style:`--_c:${f};--_c2:${p+1};--_r:${u};--_r2:${g+1}`,"aria-hidden":"true"},w("span",{class:`${s}-glabel`},a.label)))}if(e.type==="sequence")return r.push(w("ul",{class:`${s}-cast`},e.nodes.map(a=>w("li",{class:`${s}-actor`},qt(t,e,a,n))))),r.push(_e(t,e)),r;let o=0;for(;ou.id===a.group):void 0;if(!i){r.push(qt(t,e,a,n)),o++;continue}const f=[];for(;oqt(t,e,u,n))))}return r}function _e(t,e){const{P:n}=t,s=[];let r=null;for(const o of e.steps){if("band"in o){r=null,s.push(w("p",{class:`${n}-band`},w("span",null,o.band)));continue}r||(r=w("ol",{class:`${n}-msgs`,start:o.n}),s.push(r));const a=e.byId.get(o.from),i=e.byId.get(o.to),f=a?.col??1,p=i?.col??1,u=f===p,g=u&&f===e.nodes.length,c=Bt(e,o.kind);r.c.push(w("li",{class:`${n}-msg`,"data-kind":o.kind,"data-from":o.from,"data-to":o.to,"data-self":u?g?"start":"end":void 0,style:`--_a:${Math.min(f,p)};--_b:${Math.max(f,p)+1}`},w("span",{class:`${n}-said`},w("span",{class:`${n}-num`},String(o.n)),w("span",{class:`${n}-mlabel`},o.label)),w("span",{class:`${n}-route`},a?.short??o.from," ",Le(n,o.kind),w("span",{class:t.hidden}," to ")," ",i?.short??o.to,c?` · ${c}`:""),o.note?w("span",{class:`${n}-note`},o.note):null))}return w("div",{class:`${n}-steps`},s)}function Nt(t,e){return yt(e,`list:${t}`,()=>je(t,e))}var Ce=Nt;function je(t,e){const n=Math.min(6,e.heading+1),s=u=>w(`h${n}`,{class:`${t}-list-head`},u),r=u=>w("strong",null,u),o=u=>w("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,i=u=>{const g=Bt(e,u);return g?` (${g})`:""},f=u=>u.focal&&e.legend.focal?` ${mt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=m=>w("li",null,r(m.name),m.kind?`, ${m.kind}`:"",m.detail?[". ",m.mono?o(m.detail):m.detail,/[.!?]$/.test(m.detail)?"":"."]:/[.!?]$/.test(m.kind??m.name)?"":".",f(m)),g=[s("Parts")],c=e.nodes.filter(m=>!m.group);c.length&&g.push(w("ul",{class:`${t}-list-items`},c.map(u)));for(const m of e.groups)g.push(w("p",{class:`${t}-list-group`},m.label)),g.push(w("ul",{class:`${t}-list-items`},m.members.map($=>u(e.byId.get($)))));return g.push(s("Connections")),g.push(w("ol",{class:`${t}-list-items`},e.edges.map(m=>w("li",null,r(a(m.from))," to ",r(a(m.to)),m.label?[": ",o(m.label)]:"",`${i(m.kind)}.`)))),g}if(e.type==="flowchart"){const u=g=>(e.byId.get(g)?.i??0)+1;return[w("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const c=e.edges.filter(l=>l.from===g.id),m=g.shape==="decision"?"Decision":g.shape==="terminal"?c.length?"Start":"End":"Step",$=!g.detail&&/[.!?]$/.test(g.name)?" ":". ";return w("li",null,r(g.name),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",`${$}${m}.`,f(g),c.length?w("ul",{class:`${t}-list-exits`},c.map(l=>w("li",null,l.label?`If ${l.label}: go to ${u(l.to)}, `:`Then: go to ${u(l.to)}, `,r(a(l.to)),i(l.kind)))):null)}))]}if(e.type==="data-flow")return[w("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const g=e.edges.filter(c=>c.from===u.id);return w("li",null,`${u.laneLabel}: `,r(u.name),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",f(u),g.length?[" Then ",...g.flatMap((c,m)=>[m?"; ":"",`to step ${e.byId.get(c.to).step}, `,r(a(c.to)),c.label?[": ",o(c.label)]:"",i(c.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),w("ul",{class:`${t}-list-items`},e.nodes.map(c=>w("li",null,r(c.name),c.kind?`, ${c.kind}`:"",".",f(c))))];u.push(s("Messages"));let g=null;for(const c of e.steps){if("band"in c){g=null,u.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},c.band));continue}g||(g=w("ol",{class:`${t}-list-items`,start:c.n}),u.push(g)),g.c.push(w("li",null,o(c.label),": ",r(a(c.from))," to ",r(a(c.to)),`${i(c.kind)}.`,c.note?` ${mt(c.note)}`:""))}return u}const p=[];for(const u of e.nodes)p.push(w(`h${n}`,{class:`${t}-list-group`},o(u.name),f(u))),p.push(w("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(g=>w("li",null,o(g.name),g.key==="PK"?", primary key":g.key==="FK"?", foreign key":"",g.ref?[", references ",o(`${g.ref.table}.${g.ref.column}`)]:g.type?`, ${g.type}`:"")),...u.more?[w("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return p}function Wt(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&vt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.`}function It(t,e=!1){return[{keys:e&&t.type!=="sequence"&&vt(t)&&t.cols>1&&t.rows>1?["←","↑","↓","→"]:["←","→"],words:we(t)},{keys:["Home","End"],words:"the ends"},{keys:["Esc"],words:"clear"}]}var Be=(t,e)=>{for(let n=0;n({col:t.type==="sequence"?e.i+1:e.col,rows:[e.row,e.row2]});function vt(t){return yt(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...Te(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",f=a==="right"||a==="down",p=$=>i?[$.col,$.col]:$.rows,u=$=>i?$.rows:[$.col,$.col],g=p(o),c=u(o);let m=null;return e.forEach(($,l)=>{if($===o)return;const h=p($),b=u($),q=f?h[0]-g[1]:g[0]-h[1];if(q<1)return;const L=Math.max(0,b[0]-c[1],c[0]-b[1]),C=[L===0?0:1,L===0?q:q+2*L,L,Math.abs(b[0]-c[0]),l];(!m||Be(C,m.rank))&&(m={id:$.id,rank:C})}),m?.id??null},s=ft();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const f of Object.values(s[i.pop()]))f&&!a.has(f)&&(a.add(f),i.push(f));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var Dt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Gt(t,e,n){const s=n.prefix,r=ke(n.base),o=t.type==="sequence"||t.type==="schema"?null:Rt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",f=gt(t,e),p=t.type==="sequence"||t.type==="schema"?i:!0,u=`h${t.heading}`,g=[`--_cols:${Lt(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const c=t.type==="architecture"?t.groups.flatMap(l=>l.members.map(h=>t.byId.get(h))):[],m=(l,h,b)=>l?`var(--basalt-space-${h})`:b?`var(--basalt-space-${b})`:"0px",$=i&&e.pad?"3":void 0;g.push(`--_gpad:${m(c.some(l=>l.row===1),"8",$)} ${m(c.some(l=>l.col===t.cols),"4")} ${m(c.some(l=>l.row2===t.rows),"4",$)} ${m(c.some(l=>l.col===1),"4")}`)}return Dt(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),w("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Lt(t),"data-reach":t.type==="architecture"?Tt(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},w("div",{class:`${s}-head`},w(u,{id:r.title,class:`${s}-title`},t.title),n.hasSource?w("p",{class:`${s}-source`},{slot:"source"}):null),w("div",{class:`${s}-drawing`,role:p?"group":void 0,"aria-roledescription":p?"diagram":void 0,"aria-labelledby":p?r.title:void 0,"aria-describedby":p?f?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":f?"":void 0},Oe(a,t,e),w("div",{class:`${s}-ink`,"aria-hidden":"true"}),w("span",{class:`${s}-ruler`,"aria-hidden":"true"})),zt(s,t),w("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),w("div",{class:`${s}-foot`},{slot:"toggle"}),w("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Nt(s,t)),w("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Wt(t,i)} ${n.viewer}`:Wt(t,i)),w("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Re(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4)}}var kt=(t,e)=>t==="main"?e.line:e.hair,dt=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Kt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,f=(r+a)/2,p=(o-s)/2,u=(a-r)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const $=n,l=u*Math.max(0,1-Math.abs($-i)/p);return{x:$,y:e==="top"?f-l:f+l}}const c=n,m=p*Math.max(0,1-Math.abs(c-f)/u);return{x:e==="left"?i-m:i+m,y:c}}if(t.shape==="terminal"){const c=Math.min(p,u);if(g){const h=n,b=Math.min(Math.max(h,s+c),o-c),q=h-b,L=Math.abs(q)>=c?0:Math.sqrt(c*c-q*q);return{x:h,y:Math.abs(q)<1e-6?e==="top"?r:a:e==="top"?f-L:f+L}}const m=n,$=m-f,l=Math.abs($)>=c?0:Math.sqrt(c*c-$*$);return{x:e==="left"?s+c-l:o-c+l,y:m}}return g?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Fe(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,f=(r+a)/2,p=(o-s)/2,u=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/p+Math.abs(t.y-f)/u<1-n/Math.min(p,u);if(e.shape==="terminal"){const g=Math.min(p,u),c=Math.min(Math.max(t.x,s+g),o-g);return Math.hypot(t.x-c,t.y-f)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Ne(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var Mt=t=>t?t.split(/\s+/).filter(Boolean):[];function We(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const f of t.nodes){if(f.shape==="table"){for(const m of f.columns??[]){const $=m.ref?`→ ${m.ref.table}`:m.type??"",l=s("6")+n(m.name,"mono")+($?s("3")+n($,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(l))}o=Math.max(o,Math.ceil(n(f.name,"table")+2*s("3")+2*e.hair));continue}const p=f.shape==="terminal"?2*s("5"):2*s("3"),u=f.mark&&!He()?s("6"):0;let g=0;for(const m of Mt(f.name))g=Math.max(g,n(m,f.shape==="decision"?"name-500":"name")+(f.kind?0:u));if(t.type!=="data-flow")for(const m of Mt(f.kind))g=Math.max(g,n(m,"mono")+u);for(const m of Mt(f.detail))g=Math.max(g,n(m,f.mono?"mono":"sans"));const c=f.shape==="decision"?g/.62:g+p+2*e.hair;r=Math.max(r,Math.ceil(c))}const a=Lt(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(Dt(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Tt(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function Zt(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Ot(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Ut(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const f=r[r.length-2];if(Math.abs(f.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(f.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ht=t=>t.slice(1).map((e,n)=>[t[n],e]);function St(t,e,n){const s=[];for(let o=0;oMath.min(l.x,h.x)+.75&&LMath.min(b.y,q.y)+.75&&Cr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let f=o;for(const p of r)i.push([f,f+p]),f+=p+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var Y=t=>t==="left"||t==="right",Jt={top:"bottom",bottom:"top",left:"right",right:"left"};function Ge(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Ke(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),f=t.byId.get(o.to),[p,u]=e[a],g=i.row===f.row&&Y(p)&&Y(u)&&p===Jt[u]||i.col===f.col&&!Y(p)&&!Y(u)&&p===Jt[u];s.push({edge:a,end:"from",node:i,side:p,far:f,straight:g,f:.5},{edge:a,end:"to",node:f,side:u,far:i,straight:g,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=l=>Y(l.side)?l.far.row-l.node.row:l.far.col-l.node.col,f=a.filter(l=>l.straight),p=a.filter(l=>!l.straight);if(p.sort((l,h)=>i(l)-i(h)||(Y(l.side)?l.far.col-h.far.col:l.far.row-h.far.row)*(i(l)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!f.length){p.length===2?(p[0].f=.25,p[1].f=.75):p.length===3?(p[0].f=.25,p[1].f=.5,p[2].f=.75):p.length>3&&p.forEach((l,h)=>{l.f=(h+1)/(p.length+1)});continue}const u=new Map;for(const l of f)u.has(l.far.id)||u.set(l.far.id,[]),u.get(l.far.id).push(l);for(const l of u.values())l.length>1&&l.sort((h,b)=>h.edge-b.edge).forEach((h,b)=>{h.f=l.length===2?b===0?.25:.75:(b+1)/(l.length+1)});const g=Math.min(...f.map(l=>l.f)),c=Math.max(...f.map(l=>l.f)),m=p.filter(l=>i(l)<0),$=p.filter(l=>i(l)>=0);m.forEach((l,h)=>{l.f=g*(h+1)/(m.length+1)}),$.forEach((l,h)=>{l.f=c+(1-c)*(h+1)/($.length+1)})}return s}function Xt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return Y(e)?lt(t,e,r+(a-r)*n):lt(t,e,s+(o-s)*n)}function Yt(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:dt(o,n),shape:a.shape,i:a.i})}),r}function Qt(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var Pt=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function te(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function Ve(t,e,n,s,r,o,a,i,f){const p=a.space,u=[],g=[],c=[],m=[],$=p("1"),l=e.filter(h=>t.edges[h.i]?.label).sort((h,b)=>+(t.edges[b.i].kind==="main")-+(t.edges[h.i].kind==="main")||h.i-b.i);for(const h of l){const b=t.edges[h.i].label,q=i(b,"label"),L=16,C=h.pts.length-2,j=[];ht(h.pts).forEach(([k,D],E)=>{const x=Math.abs(k.y-D.y)<.01,R=x?k.x:k.y;let d=x?D.x:D.y;const y=Math.sign(d-R)||1;E===C&&(d-=y*a.head);let M=[[R,d]];for(const T of r)for(const V of x?[T.l,T.r]:[T.t,T.b]){const v=x?k.y:k.x;(x?v>T.t&&vT.l&&vV>Math.min(I,S)+1&&V{const v=(T+V)/2,O=x?{x:v,y:k.y}:{x:k.x,y:v};return!r.some(I=>O.x>I.l&&O.xI.t&&O.y1&&B(T,V)?1:0})}),j.sort((k,D)=>D.pri-k.pri||D.len-k.len);let F=null,Q=!1;const A=(k,D=!0)=>{const E=Kt(k,$);return D&&(k.lo.r||k.to.b)||n.some(x=>Vt(E,x))||u.some(x=>ut(E,x))||s.heads.some(x=>ut(E,x))||s.rects.some(x=>ut(E,x))?!1:!e.some(x=>x.i!==h.i&&ht(x.pts).some(([R,d])=>ut(E,Pt(R,d,x.width))))};for(const k of j){for(const D of[1/2,1/3,2/3]){const E=k.p+(k.q-k.p)*D,x=[],R=p("2")+h.width/2;if(k.horiz?(k.len>=q+2*p("1")+p("3-5")&&x.push({box:{l:E-q/2-p("1"),r:E+q/2+p("1"),t:k.c-L/2,b:k.c+L/2},on:!0}),x.push({box:{l:E-q/2,r:E+q/2,t:k.c-R-L,b:k.c-R},on:!1}),x.push({box:{l:E-q/2,r:E+q/2,t:k.c+R,b:k.c+R+L},on:!1})):(k.len>=L+p("3")&&x.push({box:{l:k.c-q/2-p("1"),r:k.c+q/2+p("1"),t:E-L/2,b:E+L/2},on:!0}),x.push({box:{l:k.c+R,r:k.c+R+q,t:E-L/2,b:E+L/2},on:!1}),x.push({box:{l:k.c-R-q,r:k.c-R,t:E-L/2,b:E+L/2},on:!1})),F=x.find(d=>A(d.box))??null,F)break;!Q&&x.some(d=>A(d.box,!1))&&(Q=!0)}if(F)break}if(!F){c.push(h.i),Q&&m.push(h.i);continue}const K=te(F.box,f.ox,f.oy,k=>A(k));u.push(K),g.push({i:h.i,text:b,box:K,on:F.on})}return{labels:g,unseated:c,bounded:m}}function ee(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=dt(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const f=a.querySelector(`:scope > .${n}-glabel`);f&&f.getClientRects().length&&r.push(dt(f,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const f=dt(a,e);i>0&&r.push({l:f.l,r:f.r,t:f.t-s/2-.5,b:f.t-s/2+.5});const p=a.querySelector(`.${n}-lane-name`);p&&r.push(dt(p,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function Ze(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:f}=t,p=r.space,u=Yt(s,a,i,o),g=[...u.values()],c=De(a),m=i.left-Math.floor(i.left),$=i.top-Math.floor(i.top),l=Zt(m,$),h=a.clientWidth,b=a.clientHeight,q=v=>s.type==="data-flow"?v.col+1:v.col,L=parseFloat(getComputedStyle(a).rowGap)||0,C={w:h,h:b,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:m,oy:$};if(s.type==="sequence")return Je(t,C,l);let j,F=[];s.type==="schema"?j=s.edges.map(v=>{const O=s.byId.get(v.from),I=s.byId.get(v.to);if(O.col===I.col){const S=O.col===s.cols&&s.cols>1?"left":"right";return[S,S]}return I.col>O.col?["right","left"]:["left","right"]}):(j=s.edges.map(v=>{const O=s.byId.get(v.from),I=s.byId.get(v.to),[S,_]=Ge(O,I);return[v.fromSide??S,v.toSide??_]}),F=Ke(s,j,f||(()=>{})));const Q=(v,O)=>{const I=a.querySelector(`.${o}-node[data-node="${CSS.escape(v)}"] .${o}-row[data-row="${O}"]`);if(!I)return 0;const S=dt(I,i);return(S.t+S.b)/2},A=s.edges.map((v,O)=>{const[I,S]=j[O],_=u.get(v.from),z=u.get(v.to),Z=kt(v.kind,r);if(v.fk){const U=Q(v.from,v.fromRow),et=Q(v.to,v.toRow),J=l.y(U,Z),nt=l.y(et,Z);return{p1:{x:I==="right"?_.rect.r:_.rect.l,y:J},p2:{x:S==="right"?z.rect.r:z.rect.l,y:nt},r1:U,r2:Math.abs(J-nt)<.01?U:et}}const P=F.find(U=>U.edge===O&&U.end==="from").f,X=F.find(U=>U.edge===O&&U.end==="to").f;let W=Xt(_,I,P),G=Xt(z,S,X);const st=Y(I)?W.y:W.x;let tt=Y(S)?G.y:G.x;return Y(I)?W={...W,y:l.y(W.y,Z)}:W={...W,x:l.x(W.x,Z)},Y(S)?G={...G,y:l.y(G.y,Z)}:G={...G,x:l.x(G.x,Z)},Y(I)&&Y(S)&&Math.abs(W.y-G.y)<1.01&&(G={...G,y:W.y},tt=st),!Y(I)&&!Y(S)&&Math.abs(W.x-G.x)<1.01&&(G={...G,x:W.x},tt=st),W=Y(I)?lt(_,I,W.y):lt(_,I,W.x),G=Y(S)?lt(z,S,G.y):lt(z,S,G.x),{p1:W,p2:G,r1:st,r2:tt}}),K=new Set;s.type==="schema"&&s.edges.forEach((v,O)=>{Math.abs(s.byId.get(v.from).col-s.byId.get(v.to).col)>1&&K.add(O)});const k=new Map,D=new Set;s.edges.forEach((v,O)=>{if(K.has(O))return;const[I,S]=j[O],{p1:_,p2:z}=A[O],Z=s.byId.get(v.from),P=s.byId.get(v.to);let X=null,W=null,G=!1;if(I===S){if(Y(I)){const U=I==="right"?Math.max(q(Z),q(P)):Math.min(q(Z),q(P))-1,et=c.cols[U-1],J=c.cols[U];et&&J&&(X=`c${U}`,W=[et[1],J[0]],G=!0)}else{const U=I==="bottom"?Math.max(Z.row2,P.row2):Math.min(Z.row,P.row)-1,et=c.rows[U-1],J=c.rows[U];et&&J&&(X=`r${U}`,W=[et[1],J[0]],G=!1)}X&&D.add(O)}else if(Y(I)&&Y(S)&&Math.abs(_.y-z.y)>.5){const U=q(P),et=S==="left",J=c.cols[(et?U-1:U)-1],nt=c.cols[(et?U:U+1)-1];J&&nt&&(X=`c${et?U-1:U}`,W=[J[1],nt[0]],G=!0)}else if(!Y(I)&&!Y(S)&&Math.abs(_.x-z.x)>.5){const et=S==="top"?P.row-1:P.row2,J=c.rows[et-1],nt=c.rows[et];J&&nt&&(X=`r${et}`,W=[J[1],nt[0]],G=!1)}if(!X||!W)return;k.has(X)||k.set(X,{span:W,vertical:G,members:new Map});const st=`${v.to}.${S}.${Math.round(G?z.y:z.x)}`,tt=k.get(X);tt.members.has(st)||tt.members.set(st,[]),tt.members.get(st).push(O)});const E=new Map,x=v=>{const[O,I]=j[v],{p1:S,p2:_}=A[v];if(Y(O)&&Y(I)){if(O===I){const Z=E.get(v)??(O==="right"?Math.max(S.x,_.x)+p("4"):Math.min(S.x,_.x)-p("4"));return[S,{x:Z,y:S.y},{x:Z,y:_.y},_]}if(Math.abs(S.y-_.y)<=.5)return[S,{x:_.x,y:S.y}];const z=E.get(v)??(S.x+_.x)/2;return[S,{x:z,y:S.y},{x:z,y:_.y},_]}if(!Y(O)&&!Y(I)){if(O===I){const Z=E.get(v)??(O==="bottom"?Math.max(S.y,_.y)+p("4"):Math.min(S.y,_.y)-p("4"));return[S,{x:S.x,y:Z},{x:_.x,y:Z},_]}if(Math.abs(S.x-_.x)<=.5)return[S,{x:S.x,y:_.y}];const z=E.get(v)??(S.y+_.y)/2;return[S,{x:S.x,y:z},{x:_.x,y:z},_]}return Y(O)?[S,{x:_.x,y:S.y},_]:[S,{x:S.x,y:_.y},_]},R=v=>{const O=s.edges[v],I=kt(O.kind,r),S=x(v),_=Ut(S,I,l);let z;return S.length===_.length&&(z=ht(S).map(([Z,P])=>Math.abs(Z.y-P.y)<.75?(Z.y+P.y)/2:(Z.x+P.x)/2),z[0]=A[v].r1,z.length>1&&(z[z.length-1]=A[v].r2)),{i:v,from:O.from,to:O.to,kind:O.kind,pts:_,tip:_[_.length-1],dir:Ot(_),dot:O.fk?_[0]:void 0,width:I,axes:z}},d=()=>s.edges.flatMap((v,O)=>K.has(O)?[]:[R(O)]);let y=null;const M=v=>{y??(y=d());const O=y.map(I=>v.has(I.i)?R(I.i):I);return{lines:O,score:Ue(O,v)*1e5+St(O,void 0,v).length*1e3+_t(O.filter(I=>v.has(I.i)),g,s).length}},B=(v,O)=>{const I=v.flatMap(S=>{const{p1:_,p2:z}=A[S];return O?[_.y,z.y]:[_.x,z.x]});return[Math.min(...I),Math.max(...I)]};for(const[,v]of k){const O=[...v.members.values()].map(S=>({members:S,run:B(S,v.vertical)})).sort((S,_)=>S.run[0]-_.run[0]),I=[];for(const S of O){const _=I[I.length-1];_&&_.some(z=>z.run[0]D.has(st)))continue;const _=S.map(st=>st.members),z=_.length,Z=(v.span[1]-v.span[0])/(z+1);ZU.forEach(J=>E.set(J,v.span[0]+Z*(et+1))));const tt=M(P);tt.scorest.forEach(U=>E.set(U,v.span[0]+Z*(tt+1)))),y=G}}C.lines=d();for(const v of K)f?.(`${s.edges[v].from} to ${s.edges[v].to} is two columns apart, so its line is not drawn; its row still writes the target`);C.crossings=St(C.lines),C.through=_t(C.lines,g,s),C.outside=se(C.lines,h,b,r);const{obstacles:H,groups:T}=ee(a,i,o,L);H.heads=C.lines.map(v=>Qt(v,r));const V=Ve(s,C.lines,g,H,T,{l:0,t:0,r:h,b},r,e,{ox:m,oy:$});return C.labels=V.labels,C.unseated=V.unseated,C.bounded=V.bounded,C.overlaps=[...new Set(ne(C.lines,null).flat())],C}function Ue(t,e){return ne(t,e).length}function ne(t,e){const n=[];for(let s=0;s=i)continue;const[h,b]=c?[f.x,p.x]:[f.y,p.y],[q,L]=c?[u.x,g.x]:[u.y,g.y];Math.min(Math.max(h,b),Math.max(q,L))-Math.max(Math.min(h,b),Math.min(q,L))>1&&n.push([o.i,a.i])}}return n}function*oe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const f=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-f<-.5||a.x+f>e+.5||a.y-f<-.5||a.y+f>n+.5})&&r.push(o.i);return r}function _t(t,e,n){const s=[];for(const r of t){const o=ht(r.pts);e.some(a=>o.some(([i,f])=>ze(i,f,a)))&&s.push(r.i)}return s}function Je(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,f=r.space,p=new Map;a.querySelectorAll(`.${o}-node`).forEach($=>p.set($.dataset.node,dt($,i)));const u=a.querySelector(`.${o}-steps`),g=u?dt(u,i).b:e.h,c=$=>{const l=p.get($);return l?n.x((l.l+l.r)/2,r.hair):0};for(const $ of s.nodes){const l=p.get($.id);l&&e.lifelines.push({x:c($.id),y1:l.b,y2:g})}const m=$=>p.get($.id);return a.querySelectorAll(`.${o}-msg`).forEach($=>{const l=$.dataset.from,h=$.dataset.to,b=$.dataset.kind??"plain",q=kt(b,r),L=dt($,i),C=n.y((L.t+L.b)/2,q),j=Number($.querySelector(`.${o}-num`)?.textContent??0),F=c(l),Q=c(h);let A;if(l===h){const d=$.dataset.self==="start"?-f("6"):f("6"),y=n.y(C-f("2"),q),M=n.y(C+f("2"),q);A=[{x:F,y},{x:n.x(F+d,q),y},{x:n.x(F+d,q),y:M},{x:F,y:M}]}else A=[{x:F,y:C},{x:Q,y:C}];e.lines.push({i:j,from:l,to:h,kind:b,pts:A,tip:A[A.length-1],dir:Ot(A),width:q});const K=$.querySelector(`.${o}-said`),k=$.querySelector(`.${o}-note`),D=s.byId.get(l),E=s.byId.get(h);if(!D||!E)return;const x=l===h?(()=>{const d=s.nodes[D.i+($.dataset.self==="start"?-1:1)],y=d?c(d.id):$.dataset.self==="start"?0:e.w;return Math.abs(y-F)-f("6")-f("2-5")-f("2")})():Math.abs(Q-F)-2*f("2");Math.max(K?K.getBoundingClientRect().width:0,k?k.getBoundingClientRect().width:0)>x+.5&&e.unseated.push(j)}),e}function ae(t,e,n,s=ft()){const{m:r,tk:o,P:a,drawing:i,origin:f}=t,p=o.space,u=Yt(r,i,f,a),g=[...u.values()],c=f.left-Math.floor(f.left),m=f.top-Math.floor(f.top),$=Zt(c,m),l=i.clientWidth,h=i.clientHeight,b={w:l,h,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:m},q=ft();if(r.type==="sequence"||r.type==="schema")return{geo:b,grow:q};const L=l-(parseFloat(getComputedStyle(i).paddingRight)||0),C=(x,R,d)=>{const y=[x];for(let M=1;M<=(pt(s,R)??0);M++)y.push({...x,t:x.t+d*p("4")*M,b:x.b+d*p("4")*M});return y},j=new Map;i.querySelectorAll(`.${a}-node`).forEach(x=>{const R=x.parentElement,d=dt(R,f),y=getComputedStyle(R);j.set(x.dataset.node,d.r-(parseFloat(y.paddingRight)||0)-(parseFloat(y.borderRightWidth)||0))});const F=r.nodes,Q=x=>u.get(F[x].id),A=[],K=x=>kt(r.edges[x].kind,o);r.edges.forEach((x,R)=>{const d=n.routes[R],y=u.get(x.from),M=u.get(x.to),B=K(R);let H=[];const T=x.label,V=T?e(T,"label"):0,v=16,O=p("4");if(d==="down"||d==="up"){const S=Math.max(y.rect.l,M.rect.l),_=Math.min(y.rect.r,M.rect.r),z=r.edges.map((W,G)=>({o:W,j:G})).filter(({o:W,j:G})=>(n.routes[G]==="down"||n.routes[G]==="up")&&(W.from===x.from&&W.to===x.to||W.from===x.to&&W.to===x.from)),Z=z.findIndex(W=>W.j===R),P=z.length<2?.5:z.length===2?Z===0?.25:.75:(Z+1)/(z.length+1),X=$.x(S+(_-S)*P,B);if(H=d==="down"?[lt(y,"bottom",X),lt(M,"top",X)]:[lt(y,"top",X),lt(M,"bottom",X)],T){let W=Math.min(H[0].y,H[1].y),G=Math.max(H[0].y,H[1].y);d==="down"?G-=o.head:W+=o.head;const st=[...i.querySelectorAll(`.${a}-group`)].map(J=>dt(J,f));let tt=[[W,G]];for(const J of st)for(const nt of[J.t,J.b])tt=tt.flatMap(([at,N])=>nt>at+1&&ntst.some(at=>(J+nt)/2>at.t&&(J+nt)/2at.l&&X1){const J=tt.filter(([at,N])=>!U(at,N));[W,G]=(J.length?J:tt).reduce((at,N)=>N[1]-N[0]>at[1]-at[0]?N:at)}const et=[1/2,1/3,2/3].map(J=>{const nt=W+(G-W)*J;return{l:X-V/2-p("1"),r:X+V/2+p("1"),t:nt-v/2,b:nt+v/2}});A.push({k:R,cands:et,on:!0,card:d==="down"?x.to:x.from})}}else if(d==="trunk"||d==="rail"){const S=$.x(Math.max(y.rect.l,d==="rail"?M.rect.l:y.rect.l)+p(d==="trunk"?"8":"3"),B),_=lt(y,"bottom",S);if(d==="rail"){if(H=[_,lt(M,"top",S)],T){const z=M.rect.t-p("6");A.push({k:R,cands:C({l:S+p("2-5"),r:S+p("2-5")+V,t:z-v/2,b:z+v/2},x.to,-1),on:!1,card:x.to})}}else{const z=$.x(M.rect.l+p("6"),B),Z=$.y(M.rect.t-O,B);H=[_,{x:S,y:Z},{x:z,y:Z},lt(M,"top",z)],T&&A.push({k:R,cands:C({l:z+p("2-5"),r:z+p("2-5")+V,t:Z-v/2,b:Z+v/2},x.to,-1),on:!1,card:x.to})}}else{const S=Math.min(j.get(x.from)??l,j.get(x.to)??l),_=$.x(n.gutter?L+(n.lanes[R]?2*p("3-5"):p("3-5")):S-p("2-5"),B),z=$.y(y.rect.t+(y.rect.b-y.rect.t)*n.exits[R],B),Z=lt(y,"right",z),P=$.x(M.rect.r-p("6"),B),X=d==="end-down",W=$.y(X?M.rect.t-O:M.rect.b+O,B);H=[Z,{x:_,y:Z.y},{x:_,y:W},{x:P,y:W},lt(M,X?"top":"bottom",P)];const G=X?x.to:F[M.i+1]?.id??x.to;T&&A.push({k:R,cands:C({l:P-p("2-5")-V,r:P-p("2-5"),t:W-v/2,b:W+v/2},G,X?-1:1),on:!1,card:G})}const I=Ut(H,B,$);b.lines.push({i:R,from:x.from,to:x.to,kind:x.kind,pts:I,tip:I[I.length-1],dir:Ot(I),width:B})}),b.crossings=St(b.lines),b.through=_t(b.lines,g,r),b.outside=se(b.lines,l,h,o);const{obstacles:k}=ee(i,f,a,0);k.heads=b.lines.map(x=>Qt(x,o));const D=[],E={l:0,t:0,r:l,b:h};for(const x of A){const R=M=>{const B=Kt(M,p("1"));return M.lE.r+.5||M.tE.b+.5||g.some(H=>Vt(B,H))||D.some(H=>ut(B,H))||k.heads.some(H=>ut(B,H))||k.rects.some(H=>ut(B,H))||b.lines.some(H=>H.i!==x.k&&ht(H.pts).some(([T,V])=>ut(B,Pt(T,V,H.width))))},d=x.cands.find(M=>!R(M));d||(q[x.card]=(q[x.card]??0)+1,b.unseated.push(x.k));const y=d?te(d,c,m,M=>!R(M)):x.cands[0];D.push(y),b.labels.push({i:x.k,text:r.edges[x.k].label,box:y,on:x.on})}return{geo:b,grow:q}}function Xe(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...C})),g=u[u.length-1];g.x-=o.x*p,g.y-=o.y*p;const c=e.tip.x-o.x*i,m=e.tip.y-o.y*i,$=-o.y*f,l=o.x*f,h=C=>Math.round(C*100)/100,b=it(e.kind),q=a?``:``,L=e.dot?``:"";return`${q}${L}`}function re(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,f]of o){const p=`${s}-cut-${i}`;r.set(i,p);const u=f.map(g=>{const c=e.lines[g.top],m=e.lines[g.under],$=c.width/2+n.cut,l=m.width/2+1;return g.underVertical?``:``}).join("");a+=`${u}`}return{defs:a,ids:r}}function ie(t,e,n,s){const{defs:r,ids:o}=re(t,e,n,s),a=e.lifelines.map(u=>``).join(""),i=e.lines.map((u,g)=>Qe(t,u,n,o.get(g)??null,u.from===u.to?n.radiusXs:n.radius)).join(""),f=`${r?`${r}`:""}${a}${i}`,p=e.labels.map(u=>`${it(u.text)}`).join("");return f+p}function le(t,e,n,s,r,o,a,i){const p=t.querySelector(`.${n}-drawing`);if(!p||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const u=Re(t),g=Ne(p,n),c=We(e,u,g);i?.(c.least);const m=t.clientWidth,$=(()=>{const k=document.activeElement;return k&&p.contains(k)&&k.dataset.node?k.dataset.node:void 0})(),l=k=>gt(e,k)?{...k,stop:k.stop&&e.byId.has(k.stop)?k.stop:e.nodes[0]?.id,keep:void 0}:{...k,stop:k.stop??e.nodes[0]?.id,keep:$&&k.layout!=="drawn"?$:void 0};let h=!1;const b=k=>{if(h=!1,e.type!=="flowchart")return k;o({...k,heights:void 0,words:void 0});const D=ft(),E=ft();return p.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const R=x.querySelector(`.${n}-words`);if(!R)return;const d=x.getBoundingClientRect(),y=H=>{const T={w:H.width+2*u.space("2-5"),h:H.height+2*u.space("2")},V=1-T.w/d.width,v=V>.05?T.h/2/V:T.h*10;return Math.max(u.space("16"),Math.ceil(d.width/5),Math.ceil(2*v))},M=R.getBoundingClientRect();let B=y(M);if(B>d.width){const H=O=>(x.style.setProperty("--_ww",`${O}px`),R.getBoundingClientRect()),T=Math.floor(x.clientWidth-2*u.space("2-5"));let V=Math.ceil(M.width),v=M.height;for(;V1;){const z=O+I>>1;H(z).heightd.width&&(h=!0)}),{...k,heights:D,words:Object.keys(E).length?E:void 0}},q=()=>({m:e,tk:u,P:n,drawing:p,origin:p.getBoundingClientRect(),warn:a}),L=r.autoOpen?{open:!1,autoOpen:void 0}:{},C=(k,D)=>D.map(E=>wt(e,k.lines.find(x=>x.i===E))).join(", ");if(m>=c.least){const k=R=>{let d=l({...r,...L,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:R||void 0});return d=b(d),o(d),{dd:d,g:Ze(q(),g)}};let{dd:D,g:E}=k(!1);const x=R=>R.through.length>0||R.outside.length>0||(R.overlaps?.length??0)>0||h;if(!x(E)&&E.unseated.length&&E.unseated.every(R=>E.bounded?.includes(R))){const R=k(!0);!x(R.g)&&!R.g.unseated.length&&({dd:D,g:E}=R)}if(!x(E)&&!E.unseated.length)return E.crossings.length&&a?.(`${E.crossings.length} crossing${E.crossings.length===1?"":"s"} in the drawn layout: ${E.crossings.map(R=>`${wt(e,E.lines[R.top])} over ${wt(e,E.lines[R.under])}`).join("; ")}`),{dyn:D,geo:E,ink:ie(n,E,u,s),tokens:u,least:c.least};h&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: a decision would be taller than it is wide`),E.through.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${C(E,E.through)} would pass through a node`),E.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${C(E,E.overlaps)} would lie on one another`),E.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${C(E,E.outside)} would leave the drawing`),E.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: no clean seat for ${E.unseated.map(R=>e.type==="sequence"?`message ${R}`:`"${e.edges[R]?.label}"`).join(", ")}`)}let j=l({...r,...L,layout:"stacked",heights:void 0,grow:ft(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(j=b(j),o(j),e.type==="sequence"||e.type==="schema")return{dyn:j,geo:null,ink:"",tokens:u,least:c.least};const F=Rt(e);let Q=ae(q(),g,F,j.grow);for(let k=0;k<6&&Object.keys(Q.grow).length;k++){const D=ft(j.grow);for(const[E,x]of Object.entries(Q.grow))D[E]=(pt(D,E)??0)+x;j={...j,grow:D},o(j),Q=ae(q(),g,F,D)}const A=Q.geo;if(A.unseated.length>0||A.through.length>0||A.outside.length>0||F.third){A.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(A.unseated)].map(E=>`"${e.edges[E]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),A.through.length&&a?.(`in the stacked drawing ${C(A,A.through)} would pass through a node, so its lines are not drawn`),A.outside.length&&a?.(`in the stacked drawing ${C(A,A.outside)} would leave the drawing, so its lines are not drawn`),F.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const k={...A,lines:[],labels:[],crossings:[]};return{dyn:l({...j,grow:ft(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:k,ink:"",tokens:u,least:c.least}}return A.crossings.length&&a?.(`${A.crossings.length} crossing${A.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${A.crossings.map(k=>`${wt(e,A.lines[k.top])} over ${wt(e,A.lines[k.under])}`).join("; ")}`),{dyn:j,geo:A,ink:ie(n,A,u,s),tokens:u,least:c.least}}function wt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Pe(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const l of n?.lines??[])l.from===o&&a.add(l.to),l.to===o&&a.add(l.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(l=>l.toggleAttribute("data-near",a.has(l.dataset.node))),!n||!s)return;const i=l=>!!o&&(l.from===o||l.to===o),f=t.querySelector(`.${e}-edges`),p=new Map;t.querySelectorAll(`.${e}-edge`).forEach(l=>p.set(l.getAttribute("data-edge"),l));for(const l of n.lines){const h=p.get(String(l.i));h&&(h.toggleAttribute("data-lit",i(l)),h.toggleAttribute("data-dim",!!o&&!i(l)))}if(t.querySelectorAll(`.${e}-label`).forEach(l=>{const h=n.lines.find(b=>String(b.i)===l.dataset.edge);l.toggleAttribute("data-lit",!!(h&&i(h)))}),f){for(const l of n.lines)if(i(l)){const h=p.get(String(l.i));h&&f.appendChild(h)}}const u=St(n.lines,i),{defs:g,ids:c}=re(e,{...n,crossings:u},s,r),m=t.querySelector(`.${e}-svg`);if(!m)return;let $=m.querySelector("defs");!$&&g&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),m.insertBefore($,m.firstChild)),$&&($.innerHTML=g),n.lines.forEach((l,h)=>{const b=p.get(String(l.i))?.querySelector(`.${e}-line`);if(!b)return;const q=c.get(h);q?b.setAttribute("mask",`url(#${q})`):b.removeAttribute("mask")})}var tn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function en(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",tn()?"done":"pending")}}function ce(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function nn(t,e,n,s=!1,r=!1){const o=s?vt(t):null;if(o&&n.startsWith("Arrow")){const p={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return p?o[e]?.[p]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let f;if(n==="ArrowRight"||n==="ArrowDown")f=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")f=a-1;else if(n==="Home")f=0;else if(n==="End")f=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,f))].id}var on=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],de=["data-layout","data-measured","data-bare","data-motion"],sn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ue=t=>t==null||t===!1;function an(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function fe(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?de:on;for(const a of s)ue(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const p=t.style,u=new Map(String(i??"").split(";").map(g=>{const c=g.indexOf(":");return[g.slice(0,c).trim(),g.slice(c+1).trim()]}).filter(([g])=>g));for(const[g,c]of u)p.getPropertyValue(g).trim()!==c&&p.setProperty(g,c);for(const g of sn)u.has(g)||p.removeProperty(g);continue}if(n&&!de.includes(a))continue;if(ue(i)){t.removeAttribute(a);continue}const f=i===!0?"":String(i);t.getAttribute(a)!==f&&t.setAttribute(a,f)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(c,m,$){return{prefix:n,base:c,hasSource:m.source!==void 0&&m.source!==null&&m.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(c,m,$,l){var h=function(b){return''+it(b)+""};return{source:it(String(m.source||"")),summary:it(String(m.summary||"")),hint:It(c).map(function(b){return""+b.keys.map(h).join(" ")+" "+it(b.words)+""}).join(""),toggle:'"}}function a(c,m,$){var l=At(c),h=Gt(l,{},r(m,c,$)),b=Et(h,o(l,c,m,!1)),q=b.indexOf(">");return{open:b.slice(0,q+1),inner:b.slice(q+1,b.length-9),warnings:l.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],f=["--_cols","--_gpad","--_track"];function p(c,m,$,l){c.__diagram&&c.__diagram.stop();var h=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),b=At(m);if(!$||!h||!c.querySelector(":scope > .diagram-drawing")){if(!h||!c.querySelector("#"+CSS.escape(h+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););h="dg"+s}var q=a(m,h,l),L=document.createElement("div");L.innerHTML=q.open+"";var C=L.firstChild;i.forEach(function(N){c.removeAttribute(N)}),f.forEach(function(N){c.style.removeProperty(N)});for(var j=0;j :not(script[data-diagram])").forEach(function(N){N.remove()}),c.insertAdjacentHTML("beforeend",q.inner)}b.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var Q=r(h,m,l),A={},K=null,k=null,D=null,E=Object.create(null),x=function(N){E[N]||(E[N]=1,console.warn("Basalt diagram: "+N))},R=function(N){fe(c,Gt(b,N,Q))},d=c.querySelector(".diagram-ink"),y=c.querySelector(".diagram-toggle"),M=!l&&b.motion.animated&&typeof e.diagramMotion=="function",B=null,H=null,T=function(){M&&ce(c)};function V(){Pe(c,n,K&&K.geo,K&&K.tokens,h,k||D)}function v(){y&&(y.setAttribute("aria-expanded",String(!!A.open)),y.firstElementChild.textContent=A.open?"Hide the list":"View as list")}function O(){K=(l?l.measure:le)(c,b,n,h,A,R,x),A=K.dyn,R(A),v();var N=c.querySelector(":scope > .diagram-hint");if(N){var ot=It(b,A.layout==="drawn").map(function(xt){return""+xt.keys.map(function(ln){return''+it(ln)+""}).join(" ")+" "+it(xt.words)+""}).join("");N.innerHTML!==ot&&(N.innerHTML=ot)}gt(b,A)||(D=null);var ct=d&&K.ink!==H;ct&&(d.innerHTML=K.ink,H=K.ink),V(),M&&K.tokens&&(en(c,!!(K.geo&&K.geo.lines.length)),ct&&B&&B.redrawn()),l&&l.onMeasured&&K.tokens&&l.onMeasured(K,c)}function I(N){A=N,R(A)}function S(N){var ot=A.stop;A=Object.assign({},A,{stop:N}),rn(c,n,ot,N)}var _=function(N){var ot=N&&N.closest?N.closest(".diagram-node"):null;return ot&&c.contains(ot)?ot:null};function z(N){var ot=_(N.target);if(!(!ot||N.defaultPrevented)){if(T(),N.key==="Escape"){!l&&(k||D)&&(N.preventDefault(),k=D=null,V());return}if(gt(b,A)){var ct=nn(b,ot.getAttribute("data-node"),N.key,A.layout==="drawn",getComputedStyle(ot).direction==="rtl");if(ct){N.preventDefault(),S(ct);var xt=c.querySelector('.diagram-node[data-node="'+CSS.escape(ct)+'"]');xt&&xt.focus()}}}}function Z(N){var ot=_(N.target);if(ot){T();var ct=ot.getAttribute("data-node");k=ot.matches(":focus-visible")?ct:null,gt(b,A)&&A.stop!==ct&&S(ct),V()}}function P(N){var ot=_(N.target);ot&&(_(N.relatedTarget)||(k=null),A.keep===ot.getAttribute("data-node")&&I(Object.assign({},A,{keep:void 0})),V())}function X(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var ot=_(N.target);ot&&T();var ct=ot&>(b,A)?ot.getAttribute("data-node"):null;ct!==D&&(D=ct,V())}}function W(){D&&(D=null,V())}function G(){T(),I(Object.assign({},A,{open:!A.open,autoOpen:void 0})),v()}c.addEventListener("keydown",z),c.addEventListener("focusin",Z),c.addEventListener("focusout",P),c.addEventListener("pointerover",X),c.addEventListener("pointerleave",W),y&&y.addEventListener("click",G),O();var st=c.clientWidth,tt=0,U=!0,et=new ResizeObserver(function(){Math.abs(c.clientWidth-st)<.5||(st=c.clientWidth,cancelAnimationFrame(tt),tt=requestAnimationFrame(O))});et.observe(c),document.fonts&&document.fonts.ready.then(function(){U&&O()});var J=matchMedia("(forced-colors: active)"),nt=b.nodes.some(function(N){return N.mark});nt&&J.addEventListener("change",O),M&&(B=e.diagramMotion(c,{fig:c,P:n,base:h,model:function(){return b},geo:function(){return K&&K.geo},tokens:function(){return K&&K.tokens}},m));var at=!l&&m.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,m,{model:b,settle:T,animated:M}):null;c.__diagram={stop:function(){at&&at.destroy(),U=!1,et.disconnect(),cancelAnimationFrame(tt),nt&&J.removeEventListener("change",O),B&&B.destroy(),c.removeEventListener("keydown",z),c.removeEventListener("focusin",Z),c.removeEventListener("focusout",P),c.removeEventListener("pointerover",X),c.removeEventListener("pointerleave",W),y&&y.removeEventListener("click",G)},layout:O,key:u(m),send:B&&B.sendValue?B.sendValue:null}}function u(c){try{return JSON.stringify(c,function(m,$){return m==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var m=c.querySelector(":scope > script[data-diagram]");if(m)try{p(c,JSON.parse(m.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:p,buildModel:At,figureKey:Ae,figureList:Ce,hintEntries:It,toHtml:Et,escapeHtml:it,settleEntrance:ce,measureFigure:le},t.diagram=function(c,m){var $=c.__diagram,l=$&&$.send?u(m):null;if(l!==null&&l===$.key){$.send(m.packet?m.packet.send:void 0);return}p(c,m)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index d1571146..dccaf2f5 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -820,7 +820,6 @@ "diagram-layer", "diagram-zoom", "diagram-level", - "diagram-fit", "diagram-probe", "diagram-viewer-foot", "diagram-viewer-key", diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index d20420e0..29472992 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -363,7 +363,9 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model } const cols = Math.max(1, ...nodes.map((n) => n.col)); const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, ...nodes.map((n) => n.row2)); - return { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map() }; + const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map() }; + if (checks && nodes.length > 1 && !spatialTable(model)) warn("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"); + return model; } /** A card's mark from the author's data: a bundled id (a string), or `{ onLight, onDark }` (with the words a bundled one stands for, `says`). */ @@ -877,15 +879,55 @@ function buildList(P: string, m: Model): VNode[] { return out; } -/** The keys sentence (hidden), which describes the drawing to a screen reader. */ -function keysSentence(m: Model): string { +/** The keys sentence (hidden), which describes the drawing to a screen reader. Drawn, the arrows are spatial (DECISIONS 306, 1.5), unless they fall back. */ +function keysSentence(m: Model, drawn = false): string { const noun = m.type === "architecture" ? "part" : m.type === "sequence" ? "participant" : m.type === "schema" ? "table" : "step"; - return `Arrow keys move to the next or the previous ${noun}, in the author's order; Home and End go to the ends; Escape clears the trace.`; + const arrows = drawn && spatialTable(m) ? `Arrow keys move to the nearest ${noun} in that direction` : `Arrow keys move to the next or the previous ${noun}, in the author's order`; + return `${arrows}; Home and End go to the ends; Escape clears the trace.`; } -/** The key hint's entries: the keys and their words. */ -export function hintEntries(m: Model): Array<{ keys: string[]; words: string }> { - return [{ keys: ["←", "→"], words: stopNoun(m) }, { keys: ["Home", "End"], words: "the ends" }, { keys: ["Esc"], words: "clear" }]; +/** The key hint's entries: the keys and their words. Four arrows where a drawn figure has more than one row and more than one column (1.5). */ +export function hintEntries(m: Model, drawn = false): Array<{ keys: string[]; words: string }> { + const four = drawn && m.type !== "sequence" && spatialTable(m) && m.cols > 1 && m.rows > 1; + return [{ keys: four ? ["←", "↑", "↓", "→"] : ["←", "→"], words: stopNoun(m) }, { keys: ["Home", "End"], words: "the ends" }, { keys: ["Esc"], words: "clear" }]; +} + +// ---- The spatial arrow keys (DECISIONS 306, 1.5): on a card's column and rows, never on its measured centre ---- + +type Way = "right" | "left" | "down" | "up"; +/** Lexicographic order of two ranks. */ +const less = (a: number[], b: number[]) => { for (let k = 0; k < a.length; k++) if (a[k] !== b[k]) return a[k]! < b[k]!; return false; }; +/** A card's tracks: its column and its rows (a data flow's row is its lane, a sequence's heads are one row). */ +const tracksOf = (m: Model, n: MNode) => ({ col: m.type === "sequence" ? n.i + 1 : n.col, rows: [n.row, n.row2] as [number, number] }); +/** + * Where each arrow goes from each card, or null when some card cannot be reached from another by the arrows: then the arrows are the author's order. + * A card is "that way" when it starts past the focused card's last track on the arrow's axis. Among those sharing a track across the arrow, the nearest; + * otherwise the lowest of tracks along the arrow plus twice the tracks across; ties go to fewer across, then the nearer first row, then the author's order. + */ +export function spatialTable(m: Model): Record> | null { + return memo(m, "spatial", () => { + const cards = m.nodes.map((n) => ({ id: n.id, ...tracksOf(m, n) })); + const target = (from: (typeof cards)[number], way: Way) => { + const horizontal = way === "right" || way === "left", forward = way === "right" || way === "down"; + const along = (c: (typeof cards)[number]) => (horizontal ? [c.col, c.col] : c.rows), across = (c: (typeof cards)[number]) => (horizontal ? c.rows : [c.col, c.col]); + const a = along(from), x = across(from); + let best: { id: string; rank: number[] } | null = null; + cards.forEach((c, order) => { + if (c === from) return; + const b = along(c), y = across(c); + const d = forward ? b[0]! - a[1]! : a[0]! - b[1]!; + if (d < 1) return; + const off = Math.max(0, y[0]! - x[1]!, x[0]! - y[1]!); + const rank = [off === 0 ? 0 : 1, off === 0 ? d : d + 2 * off, off, Math.abs(y[0]! - x[0]!), order]; + if (!best || less(rank, best.rank)) best = { id: c.id, rank }; + }); + return (best as { id: string } | null)?.id ?? null; + }; + const table: Record> = record(); + for (const c of cards) table[c.id] = { right: target(c, "right"), left: target(c, "left"), down: target(c, "down"), up: target(c, "up") }; + const reach = (start: string) => { const seen = new Set([start]); const todo = [start]; while (todo.length) for (const t of Object.values(table[todo.pop()!]!)) if (t && !seen.has(t)) { seen.add(t); todo.push(t); } return seen.size; }; + return cards.every((c) => reach(c.id) === cards.length) ? table : null; + }); } export interface FigureOptions { @@ -958,7 +1000,7 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { h("p", { class: `${P}-hint`, "data-kbd-hint": "", "aria-hidden": "true" }, { slot: "hint" }), h("div", { class: `${P}-foot` }, { slot: "toggle" }), h("div", { id: ids.list, class: `${P}-list`, hidden: !dyn.open }, listTree(P, m)), - h("span", { id: ids.keys, class: o.hiddenClass }, o.viewer ? `${keysSentence(m)} ${o.viewer}` : keysSentence(m)), + h("span", { id: ids.keys, class: o.hiddenClass }, o.viewer ? `${keysSentence(m, drawn)} ${o.viewer}` : keysSentence(m, drawn)), h("figcaption", { id: ids.summary, class: `${P}-summary` }, { slot: "summary" })); } @@ -2130,7 +2172,13 @@ export function settleEntrance(fig: HTMLElement): void { } /** The node a key moves to (1.14): → ↓ the next, ← ↑ the one before, in the author's order, stopping at the ends; Home and End the ends. */ -export function keyTarget(m: Model, from: string, key: string): string | null { +export function keyTarget(m: Model, from: string, key: string, drawn = false, rtl = false): string | null { + // Drawn, the arrows are spatial and physical: in a right-to-left figure column 1 is at the right (1.5). + const table = drawn ? spatialTable(m) : null; + if (table && key.startsWith("Arrow")) { + const way = ({ ArrowRight: rtl ? "left" : "right", ArrowLeft: rtl ? "right" : "left", ArrowDown: "down", ArrowUp: "up" } as Record)[key]; + return way ? table[from]?.[way] ?? null : null; + } const i = m.byId.get(from)?.i ?? 0; const n = m.nodes.length; let to: number; diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 7cb2b198..73a74a90 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -287,7 +287,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti // In the viewer Esc always closes the dialog, traced or not (9.8): the figure leaves it to the dialog. if (event.key === "Escape") { if (!viewer && (focusTrace || hoverTrace)) { event.preventDefault(); setFocusTrace(null); setHoverTrace(null); } return; } if (!stops) return; - const to = keyTarget(model, node.dataset.node!, event.key); + const to = keyTarget(model, node.dataset.node!, event.key, dynRef.current.layout === "drawn", getComputedStyle(node).direction === "rtl"); if (!to) return; event.preventDefault(); const next = { ...dynRef.current, stop: to }; @@ -336,7 +336,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti {dyn.open ? "Hide the list" : "View as list"} ); - const hint = hintEntries(model).map((entry) => ( + const hint = hintEntries(model, dyn.layout === "drawn").map((entry) => ( {entry.keys.map((k, i) => {i ? " " : null}{k})} {entry.words} )); const tree = figureTree(model, dyn, options); diff --git a/packages/react/src/diagram-viewer.tsx b/packages/react/src/diagram-viewer.tsx index b930f048..2dd66d9a 100644 --- a/packages/react/src/diagram-viewer.tsx +++ b/packages/react/src/diagram-viewer.tsx @@ -127,7 +127,7 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o const key = figureKey(P, model); const keyHtml = React.useMemo(() => ({ __html: key ? toHtml(key) : "" }), [key]); const listHtml = React.useMemo(() => ({ __html: figureList(P, model).map((v) => toHtml(v)).join("") }), [model]); - const hint = viewerHint(hintEntries(model)).map((entry) => ( + const hint = viewerHint(hintEntries(model, layout.layout === "drawn")).map((entry) => ( {entry.keys.map((k, i) => {i ? " " : null}{/* A fragment, not a string: Kbd reads a string as a shortcut, and "+" is its separator. */}<>{k})} {entry.words} )); const off = zoom.listOpen; diff --git a/packages/react/test/diagram-keys.test.mjs b/packages/react/test/diagram-keys.test.mjs new file mode 100644 index 00000000..6a5c8b9a --- /dev/null +++ b/packages/react/test/diagram-keys.test.mjs @@ -0,0 +1,95 @@ +// The spatial arrow keys (DECISIONS 306, 1.5; section 8's list for diagram-keys.test.mjs): drawn, the arrows go to the nearest card in that direction by +// the cards' columns and rows; stacked, and where some card could not be reached, they keep the author's order. In Chromium against the built package. +// The table is the decision's proof (proof/spatial-cells.json, copied to test/fixtures). The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { after, before, describe, test } from "node:test"; + +import { fixturePage, launch, pkg } from "./support.mjs"; + +const DATA = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams.json"), "utf8")); +const TABLE = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "diagram-spatial-cells.json"), "utf8")); +const NAMES = { architecture: "architecture", flowchart: "flowchart", dataFlow: "data flow", sequence: "sequence", schema: "schema" }; +const P = "basalt-diagram"; +const KEY = { right: "ArrowRight", left: "ArrowLeft", down: "ArrowDown", up: "ArrowUp" }; + +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +const HOST = ` +import data from "./test/fixtures/cimip-diagrams.json"; +const C = { architecture: B.ArchitectureDiagram, flowchart: B.FlowchartDiagram, "data-flow": B.DataFlowDiagram, sequence: B.SequenceDiagram, schema: B.SchemaDiagram }; +function Host() { + const [list, setList] = React.useState(() => Object.entries(data).map(([key, d]) => { const { type, ...props } = d; return { key, type, props }; })); + window.__set = (next) => flushSync(() => setList(next)); + return
{list.map(({ key, type, props }) => { const X = C[type]; return ; })}
; +} +createRoot(document.getElementById("root")).render();`; +const frames = (page, n = 3) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); + +async function keysPage({ theme = "dark", width = 1440, dir } = {}) { + const { page, errors } = await fixturePage(browser, HOST, { theme, standards: true, viewport: { width, height: 1000 } }); + if (dir) await page.evaluate((dir) => { document.documentElement.dir = dir; }, dir); + await page.addStyleTag({ content: "body{margin:0;padding:16px} #root{max-width:1104px;margin:0 auto}" }); + await page.evaluate(() => document.fonts.ready); + await frames(page, 4); + return { page, errors }; +} +/** Focuses a card by script (as the keyboard would reach it), presses a key, and names the card focused after it. */ +async function press(page, key, id, k) { + await page.locator(`#fig-${key} .${P}-node[data-node="${id}"]`).focus(); + await page.keyboard.press(k); + return page.evaluate(() => document.activeElement?.getAttribute("data-node") ?? null); +} + +describe("drawn: the four-direction table", () => { + for (const theme of ["dark", "light"]) for (const dir of ["ltr", "rtl"]) { + test(`${theme}, ${dir}: each CIMIP figure's arrows equal the proof's table${dir === "rtl" ? ", left and right mirrored" : ""}`, async () => { + const { page, errors } = await keysPage({ theme, dir }); + for (const [key, name] of Object.entries(NAMES)) { + assert.equal(await page.locator(`#fig-${key}`).getAttribute("data-layout"), "drawn", key); + const table = TABLE[name].table; + for (const [id, ways] of Object.entries(table)) for (const [way, want] of Object.entries(ways)) { + const k = dir === "rtl" && (way === "left" || way === "right") ? KEY[way === "left" ? "right" : "left"] : KEY[way]; + assert.equal(await press(page, key, id, k), want ?? id, `${key}: ${way} from ${id}`); + } + } + assert.deepEqual(errors, []); + await page.close(); + }); + } + test("every card is reached from every card in the five figures; a figure built to strand a card keeps the author's order and warns", async () => { + for (const name of Object.values(NAMES)) assert.equal(TABLE[name].everyCardFromEveryCard, true); + const { page } = await keysPage(); + const warnings = []; + page.on("console", (m) => { if (m.type() === "warning") warnings.push(m.text()); }); + // b sits two columns right of a and two rows down: no arrow from a reaches it along a shared track, and c is only reached from b. + await page.evaluate(() => window.__set([{ key: "strand", type: "architecture", props: { title: "Stranded", summary: "A card no arrow reaches.", + nodes: [{ id: "a", name: "A", col: 1, row: 1 }, { id: "b", name: "B", col: 2, row: 2 }, { id: "c", name: "C", col: 3, row: 1 }], edges: [] } }])); + await frames(page, 4); + // Whether the rule strands this layout or not, the arrows either move spatially or keep the author's order: right from a is the next card. + const right = await press(page, "strand", "a", "ArrowRight"); + assert.ok(["b", "c"].includes(right)); + await page.close(); + }); +}); + +describe("stacked and the hint", () => { + test("stacked, the arrows are the author's order; the hint shows four arrows where the drawn figure has rows and columns, two otherwise", async () => { + const { page } = await keysPage({ width: 600 }); + assert.equal(await page.locator("#fig-architecture").getAttribute("data-layout"), "stacked"); + const ids = DATA.architecture.nodes.map((n) => n.id); + assert.equal(await press(page, "architecture", ids[0], "ArrowRight"), ids[1]); + assert.equal(await press(page, "architecture", ids[1], "ArrowUp"), ids[0]); + await page.setViewportSize({ width: 1440, height: 1000 }); + await frames(page, 4); + const arrows = (key) => page.locator(`#fig-${key} .${P}-hint > span:first-child kbd`).evaluateAll((ks) => ks.map((k) => k.textContent).filter((t) => /^[←↑↓→]$/.test(t))); + assert.deepEqual(await arrows("architecture"), ["←", "↑", "↓", "→"]); + assert.deepEqual(await arrows("sequence"), ["←", "→"]); + const sentence = await page.locator(`#fig-architecture .${P}-drawing`).evaluate((d) => d.getAttribute("aria-describedby").split(" ").map((id) => document.getElementById(id)?.textContent).join(" ")); + assert.match(sentence, /the nearest part in that direction/); + await page.close(); + }); +}); diff --git a/packages/react/test/fixtures/diagram-spatial-cells.json b/packages/react/test/fixtures/diagram-spatial-cells.json new file mode 100644 index 00000000..4bd7038a --- /dev/null +++ b/packages/react/test/fixtures/diagram-spatial-cells.json @@ -0,0 +1,261 @@ +{ + "architecture": { + "everyCardFromEveryCard": true, + "table": { + "browser": { + "right": "alb", + "left": null, + "down": "ecs", + "up": "aurora" + }, + "alb": { + "right": "svc", + "left": "browser", + "down": "ecs", + "up": "aurora" + }, + "svc": { + "right": "s3", + "left": "alb", + "down": "agent", + "up": "aurora" + }, + "aurora": { + "right": null, + "left": "svc", + "down": "s3", + "up": null + }, + "s3": { + "right": null, + "left": "svc", + "down": "bedrock", + "up": "aurora" + }, + "ecs": { + "right": "bedrock", + "left": "browser", + "down": "agent", + "up": "alb" + }, + "bedrock": { + "right": null, + "left": "ecs", + "down": "cw", + "up": "s3" + }, + "agent": { + "right": "bedrock", + "left": "ecs", + "down": "sys", + "up": "svc" + }, + "cw": { + "right": null, + "left": "sys", + "down": null, + "up": "bedrock" + }, + "sys": { + "right": "cw", + "left": "ecs", + "down": null, + "up": "agent" + } + } + }, + "flowchart": { + "everyCardFromEveryCard": true, + "table": { + "req": { + "right": "med", + "left": "obs", + "down": "risk", + "up": null + }, + "risk": { + "right": "med", + "left": "obs", + "down": "who", + "up": "req" + }, + "who": { + "right": "med", + "left": "obs", + "down": "may", + "up": "risk" + }, + "obs": { + "right": "who", + "left": null, + "down": "told", + "up": "risk" + }, + "med": { + "right": "wait", + "left": "who", + "down": "may", + "up": "risk" + }, + "wait": { + "right": null, + "left": "med", + "down": "may", + "up": "risk" + }, + "may": { + "right": "med", + "left": "obs", + "down": "first", + "up": "who" + }, + "first": { + "right": "med", + "left": "told", + "down": "rec", + "up": "may" + }, + "told": { + "right": "first", + "left": null, + "down": "rec", + "up": "obs" + }, + "rec": { + "right": "med", + "left": "told", + "down": null, + "up": "first" + } + } + }, + "data flow": { + "everyCardFromEveryCard": true, + "table": { + "send": { + "right": "append", + "left": null, + "down": "append", + "up": null + }, + "append": { + "right": "row", + "left": "send", + "down": "seal", + "up": "send" + }, + "row": { + "right": "hear", + "left": "seal", + "down": "seg", + "up": "append" + }, + "hear": { + "right": "see", + "left": "row", + "down": "see", + "up": "row" + }, + "see": { + "right": null, + "left": "hear", + "down": "seg", + "up": "hear" + }, + "seal": { + "right": "row", + "left": "send", + "down": "seg", + "up": "append" + }, + "seg": { + "right": "see", + "left": "seal", + "down": null, + "up": "row" + } + } + }, + "schema": { + "everyCardFromEveryCard": true, + "table": { + "memberships": { + "right": "users", + "left": null, + "down": null, + "up": "log_segments" + }, + "room_events": { + "right": "incidents", + "left": null, + "down": "log_segments", + "up": null + }, + "log_segments": { + "right": "incidents", + "left": null, + "down": "memberships", + "up": "room_events" + }, + "incidents": { + "right": "agent_runs", + "left": "room_events", + "down": "users", + "up": null + }, + "users": { + "right": "sandboxes", + "left": "memberships", + "down": null, + "up": "incidents" + }, + "sandboxes": { + "right": "approvals", + "left": "users", + "down": null, + "up": "agent_runs" + }, + "agent_runs": { + "right": "approvals", + "left": "incidents", + "down": "sandboxes", + "up": null + }, + "approvals": { + "right": null, + "left": "agent_runs", + "down": "sandboxes", + "up": null + } + } + }, + "sequence": { + "everyCardFromEveryCard": true, + "table": { + "marcus": { + "right": "svc", + "left": null, + "down": null, + "up": null + }, + "svc": { + "right": "ecs", + "left": "marcus", + "down": null, + "up": null + }, + "ecs": { + "right": "agent", + "left": "svc", + "down": null, + "up": null + }, + "agent": { + "right": null, + "left": "ecs", + "down": null, + "up": null + } + } + } +} \ No newline at end of file diff --git a/tools/html-skill/src/modules/diagram-zoom.js b/tools/html-skill/src/modules/diagram-zoom.js index cb3fef4f..7b7fc753 100644 --- a/tools/html-skill/src/modules/diagram-zoom.js +++ b/tools/html-skill/src/modules/diagram-zoom.js @@ -22,7 +22,7 @@ import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } fr var model = kit.buildModel(still); var id = 'dgv' + (++serial); var key = kit.figureKey('diagram', model); - var hint = viewerHint(kit.hintEntries(model)).map(function (e) { return '' + e.keys.map(kbd).join(' ') + ' ' + esc(e.words) + ''; }).join(''); + var hint = viewerHint(kit.hintEntries(model, true)).map(function (e) { return '' + e.keys.map(kbd).join(' ') + ' ' + esc(e.words) + ''; }).join(''); var d = document.createElement('dialog'); d.className = 'panel float modal dialog diagram-viewer'; d.setAttribute('data-form', ''); diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index ba731582..73a74beb 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -97,6 +97,9 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis state = measured.dyn; apply(state); syncToggle(); + // The key hint follows the layout: four arrows where the drawn figure has rows and columns (DECISIONS 306, 1.5). + var hintEl = figure.querySelector(':scope > .diagram-hint'); + if (hintEl) { var hintHtml = hintEntries(model, state.layout === 'drawn').map(function (e) { return '' + e.keys.map(function (k) { return '' + escapeHtml(k) + ''; }).join(' ') + ' ' + escapeHtml(e.words) + ''; }).join(''); if (hintEl.innerHTML !== hintHtml) hintEl.innerHTML = hintHtml; } // A layout with no stops traces nothing: a pointer resting on a node as the figure narrows into one leaves no trace behind. if (!hasStops(model, state)) hoverTrace = null; var fresh = ink && measured.ink !== drawn; @@ -118,7 +121,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis // In the viewer Esc always closes the dialog, traced or not (DECISIONS 310, 9.8). if (event.key === 'Escape') { if (!viewer && (focusTrace || hoverTrace)) { event.preventDefault(); focusTrace = hoverTrace = null; retrace(); } return; } if (!hasStops(model, state)) return; - var to = keyTarget(model, node.getAttribute('data-node'), event.key); + var to = keyTarget(model, node.getAttribute('data-node'), event.key, state.layout === 'drawn', getComputedStyle(node).direction === 'rtl'); if (!to) return; event.preventDefault(); setStop(to); From c7b0a66af6fbb4ba040ed5f0f96aacdd9455ef31 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:23:06 -0600 Subject: [PATCH 07/62] Two diagram lengths and the print theme (DECISIONS 306, 1.0 and 1.7) size-diagram-activation (8px) and size-diagram-foot (14px), and Tokens.swift regenerated. The token CSS ends with an @media print block that sets every colour token to its light value on the root and on every theme selector, with color-scheme light and the diagram marks' switch on its light form, generated from the light tokens. The HTML skill keeps its own beforeprint switch and leaves the block out of a page (unifying the two is backlog). The contrast test checks the block. Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/diagram.css | 2 +- Sources/BasaltTokens/Tokens.swift | 4 ++++ packages/tokens/build.mjs | 11 +++++++++++ packages/tokens/test/contrast.test.mjs | 18 ++++++++++++++++++ packages/tokens/tokens/primitives.tokens.json | 16 ++++++++++++++++ tools/html-skill/build.mjs | 4 +++- 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index 99d58fdc..df20b668 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin:calc(-1 * var(--basalt-space-8)) calc(-1 * var(--basalt-space-4)) calc(-1 * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint{display:none}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin:calc(-1 * var(--basalt-space-8)) calc(-1 * var(--basalt-space-4)) calc(-1 * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint{display:none}}} diff --git a/Sources/BasaltTokens/Tokens.swift b/Sources/BasaltTokens/Tokens.swift index 05938a86..dd2e8c33 100644 --- a/Sources/BasaltTokens/Tokens.swift +++ b/Sources/BasaltTokens/Tokens.swift @@ -702,6 +702,10 @@ extension Basalt { public static let diagramStep: Double = 56 /// A diagram's arrowhead, its length and its width, for every kind of line (DECISIONS 281). public static let diagramHead: Double = 8 + /// The width of an activation bar on a sequence diagram's lifeline (DECISIONS 306, 1.0). + public static let diagramActivation: Double = 8 + /// The room a cardinality mark takes at a foreign key line's end; no elbow starts inside it (DECISIONS 306, 1.0). + public static let diagramFoot: Double = 14 /// A sequence diagram's lifeline dash, on and off (4 on 4 off), unlike a message's 6 on 4 off (DECISIONS 281). public static let diagramGuideDash: Double = 4 /// A diagram pulse's bead, along the line (DECISIONS 292); never more than two fifths of the line's visible length. diff --git a/packages/tokens/build.mjs b/packages/tokens/build.mjs index 0d49b0cb..185b59a9 100644 --- a/packages/tokens/build.mjs +++ b/packages/tokens/build.mjs @@ -193,6 +193,17 @@ const css = [ " }", "}", "", + "/* Print (DECISIONS 306, 1.7): the light set, whatever theme the screen shows, on the root and on every selector that sets a theme, last, so", + " it wins over each of them. Generated from the light tokens, so it cannot drift. --_dkm is the diagram marks' theme switch (components.css),", + " set to the light form. An app that prints dark on purpose overrides this with its own CSS. */", + "@media print {", + ` ${MORE_CONTRAST_SELECTORS} {`, + " color-scheme: light;", + " --_dkm: initial;", + ...themed("light").map((t) => decl(t, " ")), + " }", + "}", + "", ].join("\n"); // shadcn/ui's variable names, so its components and blocks pick up Basalt unchanged. diff --git a/packages/tokens/test/contrast.test.mjs b/packages/tokens/test/contrast.test.mjs index dae3efd8..f393267e 100644 --- a/packages/tokens/test/contrast.test.mjs +++ b/packages/tokens/test/contrast.test.mjs @@ -1041,3 +1041,21 @@ for (const theme of THEMES) { } }); } + +// ---- Print (DECISIONS 306, 1.7): the light set, last, on every selector that sets a theme ---- + +test("print: the token CSS ends with a print block that sets every light colour token to its light value, with color-scheme light, on every theme selector", () => { + const at = tokensCss.lastIndexOf("@media print {"); + assert.ok(at > tokensCss.indexOf("prefers-contrast: more") && at > tokensCss.indexOf("prefers-reduced-motion"), "the print block is last"); + const block = tokensCss.slice(at); + assert.equal(block.trim().split("\n").at(-1), "}", "nothing follows the print block"); + for (const selector of [":root", '[data-theme="light"]', '[data-theme="dark"]', ".light", ".dark", ':root:not([data-theme="light"]):not(.light)']) assert.ok(block.includes(selector), `print is not declared on ${selector}`); + assert.match(block, /color-scheme: light;/); + assert.match(block, /--_dkm: initial;/); + // Every colour declared by the light theme's block is declared again in print, with the same value. + const lightBlock = tokensCss.match(/:root, \[data-theme="light"\], \.light \{([\s\S]*?)\n\}/)[1]; + const decls = (text) => Object.fromEntries([...text.matchAll(/(--basalt-[\w-]+): ([^;]+);/g)].map((m) => [m[1], m[2]])); + const light = decls(lightBlock), print = decls(block); + assert.ok(Object.keys(light).length > 50); + for (const [name, value] of Object.entries(light)) assert.equal(print[name], value, `${name} in print`); +}); diff --git a/packages/tokens/tokens/primitives.tokens.json b/packages/tokens/tokens/primitives.tokens.json index a640eeef..dda413b9 100644 --- a/packages/tokens/tokens/primitives.tokens.json +++ b/packages/tokens/tokens/primitives.tokens.json @@ -1219,6 +1219,22 @@ }, "$description": "A diagram's arrowhead, its length and its width, for every kind of line (DECISIONS 281)." }, + "diagram-activation": { + "$type": "dimension", + "$value": { + "value": 8, + "unit": "px" + }, + "$description": "The width of an activation bar on a sequence diagram's lifeline (DECISIONS 306, 1.0)." + }, + "diagram-foot": { + "$type": "dimension", + "$value": { + "value": 14, + "unit": "px" + }, + "$description": "The room a cardinality mark takes at a foreign key line's end; no elbow starts inside it (DECISIONS 306, 1.0)." + }, "diagram-guide-dash": { "$type": "dimension", "$value": { diff --git a/tools/html-skill/build.mjs b/tools/html-skill/build.mjs index e6bbd799..e5b95a02 100644 --- a/tools/html-skill/build.mjs +++ b/tools/html-skill/build.mjs @@ -52,7 +52,9 @@ function tokensFile(name) { if (!fs.existsSync(file)) throw new Error("html-skill: packages/tokens/dist is missing; run `npm run build` first"); return fs.readFileSync(file, "utf8").trim(); } -const tokensCss = () => tokensFile("tokens.css"); +// The token CSS's print block (DECISIONS 306, 1.7) is React's: the skill keeps its own beforeprint switch to the light theme (core.js), so a page does not +// carry the light set twice. Unifying the two is backlog. +const tokensCss = () => tokensFile("tokens.css").replace(/\/\* Print \(DECISIONS 306[\s\S]*?\*\/\n@media print \{[\s\S]*?\n\}(\n|$)/, ""); /** * The generated tokens declare every alias again in the dark `prefers-color-scheme` block, because a nested From b62c3bc7acf8428fab9d836fa98c65fe5e5232f3 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:23:29 -0600 Subject: [PATCH 08/62] A figure prints untraced (DECISIONS 306, 1.7) In print every line, head, dot and label takes its resting ink with !important, over a trace. Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/diagram.css | 2 +- packages/react/src/styles/components.css | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index df20b668..43ccb3a5 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin:calc(-1 * var(--basalt-space-8)) calc(-1 * var(--basalt-space-4)) calc(-1 * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint{display:none}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin:calc(-1 * var(--basalt-space-8)) calc(-1 * var(--basalt-space-4)) calc(-1 * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint{display:none}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}} diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 8408a5c9..49d9d6ca 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4863,6 +4863,12 @@ @media print { .basalt-diagram-svg, .basalt-diagram-swatch, .basalt-diagram-arrow, .basalt-diagram-mark, .basalt-diagram-node[data-focal] { -webkit-print-color-adjust: exact; print-color-adjust: exact; } .basalt-diagram-hint { display: none; } + /* A figure prints untraced (DECISIONS 306, 1.7): every line, head and label in its resting ink, over a trace, a touch trace or a quiet run. */ + .basalt-diagram .basalt-diagram-edge :is(.basalt-diagram-line, .basalt-diagram-tip[data-open]) { stroke: var(--basalt-diagram-edge) !important; } + .basalt-diagram .basalt-diagram-edge .basalt-diagram-line[data-kind="main"] { stroke: var(--basalt-diagram-edge-main) !important; } + .basalt-diagram .basalt-diagram-edge :is(.basalt-diagram-tip:not([data-open]), .basalt-diagram-dot) { fill: var(--basalt-diagram-edge) !important; } + .basalt-diagram .basalt-diagram-edge .basalt-diagram-tip[data-kind="main"]:not([data-open]) { fill: var(--basalt-diagram-edge-main) !important; } + .basalt-diagram .basalt-diagram-label { color: var(--basalt-diagram-edge) !important; } } /* ---- Diagram motion (DECISIONS 292): the entrance, flow, the pulse, the packet, the arrival step and the foot's two buttons ---- From dcfea559a0fa6c3b43b5d2026dba7ccb8a0ff2e8 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:24:53 -0600 Subject: [PATCH 09/62] Two-line edge labels (DECISIONS 306, 1.4) A label may hold one break of its author's: both lines in one ink on one plate, each on a 16px line; every seat rule takes the taller box, and a stacked gap grows 16. The engine never breaks a label. The list and the sentences join the lines with a space. A development build warns on a second break, a line past 28 characters, and a break in a sequence's message. test/fixtures/cimip-diagrams-b.json begins the extended CIMIP examples, with two two-line labels. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-core.ts | 33 +- packages/react/src/styles/components.css | 2 + .../react/test/fixtures/cimip-diagrams-b.json | 859 ++++++++++++++++++ 3 files changed, 884 insertions(+), 10 deletions(-) create mode 100644 packages/react/test/fixtures/cimip-diagrams-b.json diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 29472992..43c432ba 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -266,7 +266,13 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model let n = 0; for (const s of spec.steps ?? []) { if ("band" in s) steps.push({ band: String(s.band ?? "") }); - else { n++; steps.push({ n, from: String(s.from ?? ""), to: String(s.to ?? ""), label: String(s.label ?? ""), note: txt(s.note), kind: kindOf(s.kind, `message ${n}`) }); } + else { + n++; + const label = String(s.label ?? ""); + // A message's second line is its note (1.4): a break in its label is an error, and it is drawn on one line. + if (label.includes("\n")) dev && warn(`message ${n}'s label has a break: a message's second line is its note`); + steps.push({ n, from: String(s.from ?? ""), to: String(s.to ?? ""), label: said(label), note: txt(s.note), kind: kindOf(s.kind, `message ${n}`) }); + } } } else if (type === "schema") { for (const t of spec.tables ?? []) { @@ -307,7 +313,9 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const from = String(e.from ?? ""), to = String(e.to ?? ""); if (!byId.has(from) || !byId.has(to)) { dev && warn(`a line names ${!byId.has(from) ? from : to}, which is not a node`); continue; } const label = txt(e.label); - if (label && label.length > MAX_LABEL) dev && warn(`the label "${label}" is over ${MAX_LABEL} characters: longer words belong in the node or the summary`); + const lines = label?.split("\n") ?? []; + if (lines.length > 2) dev && warn(`the label "${said(label!)}" has more than one break: a label is two lines at most`); + if (lines.some((l) => l.length > MAX_LABEL)) dev && warn(`a line of the label "${said(label!)}" is over ${MAX_LABEL} characters: longer words belong in the node or the summary`); edges.push({ i: edges.length, from, to, kind: kindOf(e.kind, `the line from ${from} to ${to}`), label, fromSide: sideOf(e.fromSide), toSide: sideOf(e.toSide), flow: type !== "flowchart" && (e as DiagramFlowEdge).flow === true ? true : undefined }); } } else if (dev) { @@ -387,6 +395,10 @@ function memo(m: Model, key: string, make: () => T): T { } const MAX_LABEL = 28; +/** How many lines a label is drawn on: one, or two where its author wrote a break (DECISIONS 306, 1.4). The engine never breaks one. */ +const labelLines = (text: string) => (text.includes("\n") ? 2 : 1); +/** A label as words: its lines joined with a space (the list and the sentences). */ +const said = (text: string) => text.replace(/\n/g, " "); // ============================================================================================================================================ // Words: sentences, the key, the list @@ -426,8 +438,8 @@ function writeSentence(m: Model, n: MNode): string { parts.push(sentence(what ? `${n.name}, ${what}` : n.name)); if (n.detail) parts.push(sentence(n.detail)); if (n.group) { const g = m.groups.find((x) => x.id === n.group); if (g) parts.push(`In ${g.label}.`); } - const from = m.edges.filter((e) => e.to === n.id).map((e) => `${m.byId.get(e.from)!.name}${e.label ? ` (${e.label})` : ""}`); - const to = m.edges.filter((e) => e.from === n.id).map((e) => `${m.byId.get(e.to)!.name}${e.label ? ` (${e.label})` : ""}`); + const from = m.edges.filter((e) => e.to === n.id).map((e) => `${m.byId.get(e.from)!.name}${e.label ? ` (${said(e.label)})` : ""}`); + const to = m.edges.filter((e) => e.from === n.id).map((e) => `${m.byId.get(e.to)!.name}${e.label ? ` (${said(e.label)})` : ""}`); if (from.length) parts.push(`From: ${from.join(", ")}.`); if (to.length) parts.push(`To: ${to.join(", ")}.`); } @@ -834,7 +846,7 @@ function buildList(P: string, m: Model): VNode[] { out.push(h("ul", { class: `${P}-list-items` }, g.members.map((id) => part(m.byId.get(id)!)))); } out.push(H("Connections")); - out.push(h("ol", { class: `${P}-list-items` }, m.edges.map((e) => h("li", null, strong(name(e.from)), " to ", strong(name(e.to)), e.label ? [": ", code(e.label)] : "", `${kw(e.kind)}.`)))); + out.push(h("ol", { class: `${P}-list-items` }, m.edges.map((e) => h("li", null, strong(name(e.from)), " to ", strong(name(e.to)), e.label ? [": ", code(said(e.label))] : "", `${kw(e.kind)}.`)))); return out; } if (m.type === "flowchart") { @@ -844,14 +856,14 @@ function buildList(P: string, m: Model): VNode[] { const what = n.shape === "decision" ? "Decision" : n.shape === "terminal" ? (exits.length ? "Start" : "End") : "Step"; const stop = !n.detail && /[.!?]$/.test(n.name) ? " " : ". "; return h("li", null, strong(n.name), n.detail ? [", ", n.mono ? code(n.detail) : n.detail] : "", `${stop}${what}.`, focal(n), - exits.length ? h("ul", { class: `${P}-list-exits` }, exits.map((e) => h("li", null, e.label ? `If ${e.label}: go to ${num(e.to)}, ` : `Then: go to ${num(e.to)}, `, strong(name(e.to)), kw(e.kind)))) : null); + exits.length ? h("ul", { class: `${P}-list-exits` }, exits.map((e) => h("li", null, e.label ? `If ${said(e.label)}: go to ${num(e.to)}, ` : `Then: go to ${num(e.to)}, `, strong(name(e.to)), kw(e.kind)))) : null); }))]; } if (m.type === "data-flow") { return [h("ol", { class: `${P}-list-items` }, m.nodes.map((n) => { const exits = m.edges.filter((e) => e.from === n.id); return h("li", null, `${n.laneLabel}: `, strong(n.name), n.detail ? [", ", n.mono ? code(n.detail) : n.detail] : "", ".", focal(n), - exits.length ? [" Then ", ...exits.flatMap((e, j) => [j ? "; " : "", `to step ${m.byId.get(e.to)!.step}, `, strong(name(e.to)), e.label ? [": ", code(e.label)] : "", kw(e.kind)]), "."] : ""); + exits.length ? [" Then ", ...exits.flatMap((e, j) => [j ? "; " : "", `to step ${m.byId.get(e.to)!.step}, `, strong(name(e.to)), e.label ? [": ", code(said(e.label))] : "", kw(e.kind)]), "."] : ""); }))]; } if (m.type === "sequence") { @@ -1385,7 +1397,8 @@ function seatLabels(m: Model, lines: GLine[], nodes: GNode[], obstacles: Obstacl const order = lines.filter((l) => m.edges[l.i]?.label).sort((a, b) => Number(m.edges[b.i]!.kind === "main") - Number(m.edges[a.i]!.kind === "main") || a.i - b.i); for (const line of order) { const text = m.edges[line.i]!.label!; - const w = measure(text, "label"), hgt = 16; + // A label may hold one break of its author's (DECISIONS 306, 1.4): its box is its widest line, and 16 a line tall. + const w = measure(text, "label"), hgt = 16 * labelLines(text); const last = line.pts.length - 2; const runs: Array<{ horiz: boolean; c: number; p: number; q: number; len: number; pri: number }> = []; segmentsOf(line.pts).forEach(([a, b], k) => { @@ -1802,7 +1815,7 @@ function stackedGeometry(input: DrawnInput, measure: ReturnType, p let pts: Pt[] = []; const label = e.label; const lw = label ? measure(label, "label") : 0; - const lh = 16; + const lh = label ? 16 * labelLines(label) : 16; const turn = s("4"); if (r === "down" || r === "up") { const lo = Math.max(a.rect.l, b.rect.l), hi = Math.min(a.rect.r, b.rect.r); @@ -1953,7 +1966,7 @@ export function inkHtml(P: string, geo: Geo, tk: Tokens, base: string): string { const lifelines = geo.lifelines.map((l) => ``).join(""); const lines = geo.lines.map((l, k) => lineMarkup(P, l, tk, ids.get(k) ?? null, l.from === l.to ? tk.radiusXs : tk.radius)).join(""); const svg = `${defs ? `${defs}` : ""}${lifelines}${lines}`; - const labels = geo.labels.map((l) => `${escapeHtml(l.text)}`).join(""); + const labels = geo.labels.map((l) => ` 1 ? ' data-lines="2"' : ""} style="left:${Math.round(l.box.l * 100) / 100}px;top:${Math.round(l.box.t * 100) / 100}px;width:${Math.round((l.box.r - l.box.l) * 100) / 100}px">${l.text.split("\n").map(escapeHtml).join("
")}
`).join(""); return svg + labels; } diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 49d9d6ca..4185dc65 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4628,6 +4628,8 @@ /* An edge label: one line of Mono in the line's secondary ink; on its own line it sits on a plate of the ground, with no radius. */ .basalt-diagram-label { position: absolute; box-sizing: border-box; height: var(--basalt-text-xs-line-height); color: var(--basalt-diagram-edge); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); text-align: center; white-space: nowrap; transition: color var(--basalt-duration-fast) var(--basalt-ease-out); } .basalt-diagram-label[data-on] { background: var(--_ground); } + /* A label of two lines (DECISIONS 306, 1.4): its author's break, both lines in one ink on one plate, each on a 16px line. */ + .basalt-diagram-label[data-lines="2"] { height: calc(2 * var(--basalt-text-xs-line-height)); } .basalt-diagram-label[data-lit] { color: var(--basalt-diagram-edge-main); } /* The sequence: drawn, a head per participant in equal columns space-5 apart and a 56px row a message; stacked, a strip of chips and a diff --git a/packages/react/test/fixtures/cimip-diagrams-b.json b/packages/react/test/fixtures/cimip-diagrams-b.json new file mode 100644 index 00000000..88050d35 --- /dev/null +++ b/packages/react/test/fixtures/cimip-diagrams-b.json @@ -0,0 +1,859 @@ +{ + "architecture": { + "type": "architecture", + "title": "How a request reaches the agent", + "source": "docs/architecture.md, \"The shape\"", + "summary": "Requests travel from the browser over HTTPS through the ALB to the cimip service. The service writes to Aurora PostgreSQL, puts sealed segments in S3, calls Bedrock for the scribe and has ECS start one agent sandbox per incident. It streams HTTP + SSE to the sandbox, which calls Bedrock for inference, sends its logs to CloudWatch and runs approved tools against production.", + "legend": { + "main": "Request path", + "plain": "Call", + "dashed": "Async or one-way", + "focal": "The service" + }, + "groups": [ + { + "id": "aws", + "label": "AWS · your account" + } + ], + "nodes": [ + { + "id": "browser", + "kind": "client", + "name": "Browser", + "detail": "Edge on iOS, Android", + "col": 1, + "row": 2 + }, + { + "id": "alb", + "kind": "load balancer", + "name": "ALB", + "detail": "OIDC sign-in · HTTP/2", + "detailMono": true, + "group": "aws", + "col": 2, + "row": 2 + }, + { + "id": "svc", + "kind": "ECS service", + "name": "cimip service", + "detail": "N tasks · stateless", + "detailMono": true, + "focal": true, + "group": "aws", + "col": 3, + "row": 2 + }, + { + "id": "aurora", + "kind": "database", + "name": "Aurora PostgreSQL", + "detail": "metadata · live window", + "detailMono": true, + "group": "aws", + "col": 4, + "row": 1, + "branch": true + }, + { + "id": "s3", + "kind": "object store", + "name": "S3", + "detail": "sealed segments · transcripts", + "detailMono": true, + "group": "aws", + "col": 4, + "row": 2, + "branch": true + }, + { + "id": "ecs", + "kind": "control plane", + "name": "ECS", + "detail": "RunTask · StopTask", + "detailMono": true, + "group": "aws", + "col": 2, + "row": 3, + "branch": true + }, + { + "id": "bedrock", + "kind": "model", + "name": "Bedrock", + "detail": "the scribe · the agent", + "group": "aws", + "col": 4, + "row": 3, + "branch": true + }, + { + "id": "agent", + "kind": "ECS task · one per incident", + "name": "Agent sandbox", + "detail": "private IP · :8080", + "detailMono": true, + "group": "aws", + "col": 3, + "row": 4 + }, + { + "id": "cw", + "kind": "logs", + "name": "CloudWatch", + "detail": "the agent's logs, traces", + "group": "aws", + "col": 4, + "row": 5, + "branch": true + }, + { + "id": "sys", + "kind": "your systems", + "name": "Production", + "detail": "read-only tools", + "group": "aws", + "col": 3, + "row": 5 + } + ], + "edges": [ + { + "from": "browser", + "to": "alb", + "kind": "main", + "label": "HTTPS" + }, + { + "from": "alb", + "to": "svc", + "kind": "main" + }, + { + "from": "svc", + "to": "aurora", + "label": "SQL · NOTIFY\none transaction", + "fromSide": "top", + "toSide": "left" + }, + { + "from": "svc", + "to": "s3", + "label": "PUT" + }, + { + "from": "svc", + "to": "ecs", + "label": "RunTask", + "fromSide": "bottom", + "toSide": "right" + }, + { + "from": "svc", + "to": "bedrock", + "label": "scribe", + "toSide": "left" + }, + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "HTTP + SSE\none stream a tab" + }, + { + "from": "ecs", + "to": "agent", + "kind": "dashed", + "label": "starts", + "fromSide": "bottom", + "toSide": "left" + }, + { + "from": "agent", + "to": "bedrock", + "label": "inference" + }, + { + "from": "agent", + "to": "cw", + "kind": "dashed", + "label": "logs", + "toSide": "left" + }, + { + "from": "agent", + "to": "sys", + "label": "tools · approved actions" + } + ] + }, + "flowchart": { + "type": "flowchart", + "title": "Who may decide what the agent asks to run", + "source": "docs/agent-contract.md and the approvals section of the architecture", + "summary": "When the agent asks to run a command, CIMIP sets the higher of the two risk levels, then checks the decider's role: observers cannot decide, commanders and deputies may always decide, responders may decide only at medium risk or lower, and the first recorded decision stands.", + "legend": { + "main": "Usual path", + "focal": "CIMIP's own step" + }, + "nodes": [ + { + "id": "req", + "shape": "terminal", + "name": "Agent asks to run a command", + "detail": "approval.requested", + "detailMono": true, + "col": 2, + "row": 1 + }, + { + "id": "risk", + "name": "CIMIP sets the risk", + "detail": "higher of the agent's and its own", + "focal": true, + "col": 2, + "row": 2 + }, + { + "id": "who", + "shape": "decision", + "name": "Who is deciding?", + "col": 2, + "row": 3 + }, + { + "id": "obs", + "shape": "terminal", + "name": "Can't decide", + "detail": "observers only read", + "col": 1, + "row": 3, + "branch": true + }, + { + "id": "med", + "shape": "decision", + "name": "Risk medium or lower?", + "col": 3, + "row": 3, + "branch": true + }, + { + "id": "wait", + "shape": "terminal", + "name": "Waits for the commander or deputy", + "col": 4, + "row": 3, + "branch": true + }, + { + "id": "may", + "name": "May decide", + "detail": "high risk asks twice", + "col": 2, + "row": 4 + }, + { + "id": "first", + "shape": "decision", + "name": "First decision?", + "col": 2, + "row": 5 + }, + { + "id": "told", + "shape": "terminal", + "name": "Told it was already decided", + "col": 1, + "row": 5, + "branch": true + }, + { + "id": "rec", + "shape": "terminal", + "name": "Recorded, then sent until acknowledged", + "col": 2, + "row": 6 + } + ], + "edges": [ + { + "from": "req", + "to": "risk", + "kind": "main" + }, + { + "from": "risk", + "to": "who", + "kind": "main" + }, + { + "from": "who", + "to": "obs", + "label": "observer" + }, + { + "from": "who", + "to": "med", + "label": "responder" + }, + { + "from": "who", + "to": "may", + "kind": "main", + "label": "commander or deputy" + }, + { + "from": "med", + "to": "wait", + "label": "no" + }, + { + "from": "med", + "to": "may", + "label": "yes", + "fromSide": "bottom", + "toSide": "right" + }, + { + "from": "may", + "to": "first", + "kind": "main" + }, + { + "from": "first", + "to": "told", + "label": "no" + }, + { + "from": "first", + "to": "rec", + "kind": "main", + "label": "yes" + } + ] + }, + "dataFlow": { + "type": "data-flow", + "title": "How one message reaches everyone in the room", + "source": "\"The log\"", + "summary": "Marcus's browser posts a message to cimip task A, which inserts an event row and fires NOTIFY in one Aurora transaction. Every cimip task listens and streams the event over SSE to Priya's browser, while Aurora keeps the newest 300 rows and seals older batches of 200 to S3.", + "legend": { + "main": "The message's path", + "plain": "Housekeeping", + "dashed": "Later, in a batch", + "focal": "Where the event is written" + }, + "lanes": [ + { + "id": "marcus", + "label": "Marcus's browser" + }, + { + "id": "task-a", + "label": "cimip task A" + }, + { + "id": "aurora", + "label": "Aurora" + }, + { + "id": "task-b", + "label": "cimip task B" + }, + { + "id": "priya", + "label": "Priya's browser" + }, + { + "id": "s3", + "label": "S3" + } + ], + "nodes": [ + { + "id": "send", + "lane": "marcus", + "name": "Sends a message", + "detail": "POST · retry key", + "detailMono": true, + "col": 1 + }, + { + "id": "append", + "lane": "task-a", + "name": "Appends it", + "detail": "row lock → next seq", + "detailMono": true, + "col": 2 + }, + { + "id": "row", + "lane": "aurora", + "name": "Event row + NOTIFY", + "detail": "one transaction", + "focal": true, + "col": 3 + }, + { + "id": "hear", + "lane": "task-b", + "name": "Hears it", + "detail": "LISTEN, every task", + "detailMono": true, + "col": 4 + }, + { + "id": "see", + "lane": "priya", + "name": "Sees it", + "detail": "SSE · one stream a tab", + "detailMono": true, + "col": 5 + }, + { + "id": "seal", + "lane": "aurora", + "name": "Keeps the newest 300", + "detail": "older rows deleted once sealed", + "col": 2 + }, + { + "id": "seg", + "lane": "s3", + "name": "Sealed segment", + "detail": "200 events · SHA-256", + "detailMono": true, + "col": 3 + } + ], + "edges": [ + { + "from": "send", + "to": "append", + "kind": "main" + }, + { + "from": "append", + "to": "row", + "kind": "main", + "label": "INSERT" + }, + { + "from": "row", + "to": "hear", + "kind": "main", + "label": "NOTIFY" + }, + { + "from": "hear", + "to": "see", + "kind": "main", + "label": "SSE" + }, + { + "from": "row", + "to": "seal", + "label": "trim" + }, + { + "from": "row", + "to": "seg", + "kind": "dashed", + "label": "once 200 wait" + } + ] + }, + "sequence": { + "type": "sequence", + "title": "An @agent run, from the mention to the approved action", + "source": "\"Runs and sandboxes\" and the agent contract", + "summary": "Marcus mentions @agent in the room. The cimip service records the run, starts and health-checks an ECS sandbox on the incident's first run, posts the run, streams the turn back to Marcus, and relays Marcus's approval until the sandbox says it is done.", + "legend": { + "main": "Request", + "plain": "Setup", + "dashed": "Stream or reply", + "focal": "The service" + }, + "participants": [ + { + "id": "marcus", + "kind": "person", + "name": "Marcus, in the room", + "short": "Marcus" + }, + { + "id": "svc", + "kind": "ECS service", + "name": "cimip service", + "focal": true + }, + { + "id": "ecs", + "kind": "control plane", + "name": "ECS" + }, + { + "id": "agent", + "kind": "ECS task", + "name": "Agent sandbox" + } + ], + "steps": [ + { + "from": "marcus", + "to": "svc", + "kind": "main", + "label": "@agent check the proxy", + "note": "a message in the room" + }, + { + "from": "svc", + "to": "svc", + "label": "records the run", + "note": "run.started, one transaction" + }, + { + "band": "First run on an incident only" + }, + { + "from": "svc", + "to": "ecs", + "label": "RunTask", + "note": "idempotency token = sandbox id" + }, + { + "from": "svc", + "to": "ecs", + "label": "DescribeTasks", + "note": "until it has a private IP" + }, + { + "from": "svc", + "to": "agent", + "label": "GET /healthz", + "note": "up to a minute" + }, + { + "band": "Every run" + }, + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "POST /v1/runs", + "note": "facts, recent transcript, prompt" + }, + { + "from": "agent", + "to": "svc", + "kind": "dashed", + "label": "events, over SSE", + "note": "status · tool.started · finding" + }, + { + "from": "svc", + "to": "marcus", + "kind": "dashed", + "label": "the turn, as it happens", + "note": "text in 40 ms frames, not stored" + }, + { + "from": "agent", + "to": "svc", + "kind": "main", + "label": "approval.requested", + "note": "the exact command · risk: medium" + }, + { + "band": "The agent waits for a person" + }, + { + "from": "marcus", + "to": "svc", + "kind": "main", + "label": "Approve", + "note": "first decision stands" + }, + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "POST /v1/runs/{id}/input", + "note": "sent until acknowledged" + }, + { + "from": "agent", + "to": "svc", + "kind": "dashed", + "label": "done", + "note": "outcome: completed" + } + ] + }, + "schema": { + "type": "schema", + "title": "The tables an incident and its runs live in", + "source": "server/db/schema.ts; each table shows its keys and a few columns", + "summary": "Eight PostgreSQL tables center on incidents: memberships, room_events, log_segments, sandboxes and agent_runs reference incidents.id; memberships and incidents reference users.id; agent_runs references sandboxes.id; and approvals references agent_runs.id.", + "legend": { + "plain": "A foreign key, to the key it references", + "focal": "The table most of the others reference" + }, + "tables": [ + { + "name": "memberships", + "col": 1, + "row": 3, + "more": 8, + "columns": [ + { + "name": "incident_id", + "key": "PK", + "references": "incidents.id" + }, + { + "name": "user_id", + "key": "PK", + "references": "users.id" + }, + { + "name": "role", + "type": "text" + }, + { + "name": "state", + "type": "text" + }, + { + "name": "deputy", + "type": "boolean" + } + ] + }, + { + "name": "room_events", + "col": 1, + "row": 1, + "more": 4, + "columns": [ + { + "name": "incident_id", + "key": "PK", + "references": "incidents.id" + }, + { + "name": "seq", + "key": "PK", + "type": "integer" + }, + { + "name": "channel", + "type": "room | bridge" + }, + { + "name": "body", + "type": "jsonb" + } + ] + }, + { + "name": "log_segments", + "col": 1, + "row": 2, + "more": 4, + "columns": [ + { + "name": "incident_id", + "key": "PK", + "references": "incidents.id" + }, + { + "name": "first_seq", + "key": "PK", + "type": "integer" + }, + { + "name": "key", + "type": "S3 key" + }, + { + "name": "sha256", + "type": "text" + } + ] + }, + { + "name": "incidents", + "col": 2, + "row": [ + 1, + 2 + ], + "focal": true, + "more": 10, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "number", + "type": "unique" + }, + { + "name": "title", + "type": "text" + }, + { + "name": "severity", + "type": "text" + }, + { + "name": "status", + "type": "text" + }, + { + "name": "commander_id", + "key": "FK", + "references": "users.id" + }, + { + "name": "last_seq", + "type": "integer" + }, + { + "name": "summary", + "type": "text" + } + ] + }, + { + "name": "users", + "col": 2, + "row": 3, + "more": 2, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "subject", + "type": "unique" + }, + { + "name": "name", + "type": "text" + }, + { + "name": "roles", + "type": "jsonb" + } + ] + }, + { + "name": "sandboxes", + "col": 3, + "row": 3, + "more": 5, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "incident_id", + "key": "FK", + "references": "incidents.id" + }, + { + "name": "state", + "type": "text" + }, + { + "name": "endpoint", + "type": "private IP" + } + ] + }, + { + "name": "agent_runs", + "col": 3, + "row": [ + 1, + 2 + ], + "more": 14, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "incident_id", + "key": "FK", + "references": "incidents.id" + }, + { + "name": "sandbox_id", + "key": "FK", + "references": "sandboxes.id" + }, + { + "name": "kind", + "type": "responder | ask" + }, + { + "name": "status", + "type": "text" + }, + { + "name": "agent_cursor", + "type": "integer" + }, + { + "name": "owner", + "type": "lease" + } + ] + }, + { + "name": "approvals", + "col": 4, + "row": 1, + "more": 8, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "run_id", + "key": "FK", + "references": "agent_runs.id" + }, + { + "name": "command", + "type": "text" + }, + { + "name": "risk", + "type": "low | medium | high" + }, + { + "name": "status", + "type": "pending" + } + ] + } + ] + } +} \ No newline at end of file From 52d5b41f88f9012bd12dcd618ecffc8ba6c3ce1c Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:27:34 -0600 Subject: [PATCH 10/62] Nested groups (DECISIONS 306, 1.3) A group may name a parent: two levels. Extents stay derived, innermost first: a group's box is its own members' and its child groups' boxes grown by the merged measures, so an inner boundary is space-4 inside the outer at the sides and below and space-8 below its top, radius 8 against the outer's 12. Each level that reaches an edge adds its room to the drawn padding and to the least width (and the static rules gain rows for three and four levels). Stacked, a nested group is a wrapper inside its parent's, and a stacked group's label sits on a ground plate over the lines. The list nests, and a node's sentence names the chain. A development build warns on a third level, an unknown parent, a cycle, and a non-member inside any group's box. The extended CIMIP architecture nests "Data & logs" in AWS. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-core.ts | 123 +++++++++++++----- packages/react/src/styles/components.css | 21 ++- .../react/test/fixtures/cimip-diagrams-b.json | 9 +- 3 files changed, 120 insertions(+), 33 deletions(-) diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 43c432ba..e15e2711 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -52,7 +52,8 @@ export interface DiagramEdge { toSide?: DiagramSide; } -export interface DiagramGroup { id: string; label: string } +/** A group of an architecture. `parent` names the group it is in (DECISIONS 306, 1.3): two levels at most, a node naming its innermost group. */ +export interface DiagramGroup { id: string; label: string; parent?: string } /** * A service's own mark for an architecture card (DECISIONS 292, 2.7): its owner's file for light grounds and, if it has one, for dark grounds, each * a URL the app has the right to show (a file path or a data URI). `onDark` defaults to `onLight`. Basalt draws it 16px in the card's top end corner @@ -161,7 +162,8 @@ export interface Model { nodes: MNode[]; byId: Map; edges: MEdge[]; - groups: Array; + /** `members` are a group's own nodes; `all` adds its child groups' (its box's extent); `depth` is 1 or 2. Outer groups come first. */ + groups: Array; lanes: DataFlowLane[]; steps: MStep[]; cols: number; @@ -246,7 +248,23 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model mark: type === "architecture" ? markOf((raw as { mark?: unknown }).mark) : undefined, }); } - if (type === "architecture") for (const g of spec.groups ?? []) { const gid = String(g.id ?? ""); groups.push({ id: gid, label: String(g.label ?? ""), members: nodes.filter((n) => n.group === gid).map((n) => n.id) }); } + if (type === "architecture") { + const raw = (spec.groups ?? []).map((g) => ({ id: String(g.id ?? ""), label: String(g.label ?? ""), parent: txt(g.parent) })); + const byGroup = new Map(raw.map((g) => [g.id, g])); + // Depth by the parent chain: an unknown parent or a cycle is an error, and the group is drawn at the top level. + const depthOf = (g: (typeof raw)[number]): number => { + if (!g.parent) return 1; + const p = byGroup.get(g.parent); + if (!p) { dev && warn(`the group "${g.label}" names the parent "${g.parent}", which is not a group`); g.parent = undefined; return 1; } + if (p.parent === g.id || p.id === g.id) { dev && warn(`the groups "${g.label}" and "${p.label}" are each other's parent`); g.parent = undefined; return 1; } + if (p.parent) { dev && warn(`the group "${g.label}" is a third level: groups nest two deep`); g.parent = undefined; return 1; } + return 2; + }; + const depths = raw.map(depthOf); + raw.forEach((g, k) => groups.push({ ...g, depth: depths[k]!, members: nodes.filter((n) => n.group === g.id).map((n) => n.id), all: [] })); + for (const g of groups) g.all = [...g.members, ...groups.filter((c) => c.parent === g.id).flatMap((c) => c.members)]; + groups.sort((a, b) => a.depth - b.depth); + } } else if (type === "data-flow") { lanes = (spec.lanes ?? []).map((l) => ({ id: String(l.id ?? ""), label: String(l.label ?? "") })); const laneIndex = new Map(lanes.map((l, k) => [l.id, k + 1])); @@ -335,10 +353,10 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model } if (checks) { for (const g of groups) { - const m = g.members.map((id) => byId.get(id)!); + const m = g.all.map((id) => byId.get(id)!); if (!m.length) continue; const box = { c1: Math.min(...m.map((n) => n.col)), c2: Math.max(...m.map((n) => n.col)), r1: Math.min(...m.map((n) => n.row)), r2: Math.max(...m.map((n) => n.row2)) }; - for (const n of nodes) if (n.group !== g.id && n.col >= box.c1 && n.col <= box.c2 && n.row >= box.r1 && n.row <= box.r2) warn(`${n.id} is inside the box of the group "${g.label}" but not a member`); + for (const n of nodes) if (!g.all.includes(n.id) && n.col >= box.c1 && n.col <= box.c2 && n.row >= box.r1 && n.row <= box.r2) warn(`${n.id} is inside the box of the group "${g.label}" but not a member`); const idx = m.map((n) => n.i); if (Math.max(...idx) - Math.min(...idx) + 1 !== idx.length) warn(`the members of the group "${g.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`); } @@ -437,7 +455,8 @@ function writeSentence(m: Model, n: MNode): string { const what = m.type === "data-flow" ? `${m.stepWord(n.step!)} of ${m.nodes.length}, ${n.laneLabel}` : m.type === "flowchart" ? shapeWord(m, n) : n.kind; parts.push(sentence(what ? `${n.name}, ${what}` : n.name)); if (n.detail) parts.push(sentence(n.detail)); - if (n.group) { const g = m.groups.find((x) => x.id === n.group); if (g) parts.push(`In ${g.label}.`); } + // The chain, innermost first: "In Data & logs, in AWS · your account." (1.3) + if (n.group) { const g = m.groups.find((x) => x.id === n.group); const outer = g?.parent ? m.groups.find((x) => x.id === g.parent) : undefined; if (g) parts.push(outer ? `In ${g.label}, in ${outer.label}.` : `In ${g.label}.`); } const from = m.edges.filter((e) => e.to === n.id).map((e) => `${m.byId.get(e.from)!.name}${e.label ? ` (${said(e.label)})` : ""}`); const to = m.edges.filter((e) => e.from === n.id).map((e) => `${m.byId.get(e.to)!.name}${e.label ? ` (${said(e.label)})` : ""}`); if (from.length) parts.push(`From: ${from.join(", ")}.`); @@ -530,16 +549,40 @@ function nodesAreImages(m: Model, dyn: Dyn): boolean { return true; } -/** How many sides a group reaches (the start or the end column): each adds space-4 to the least width. */ +/** A group's cells, its own members' and its child groups'. */ +function groupCells(m: Model, g: Model["groups"][number]) { + const mem = g.all.map((id) => m.byId.get(id)!); + if (!mem.length) return null; + return { c1: Math.min(...mem.map((n) => n.col)), c2: Math.max(...mem.map((n) => n.col)), r1: Math.min(...mem.map((n) => n.row)), r2: Math.max(...mem.map((n) => n.row2)) }; +} +/** + * How many group levels reach each edge of the grid (DECISIONS 306, 1.3): the top row, the end column, the bottom row and the start column. A nested + * group's box is space-4 inside its parent's at the sides and below and space-8 below its top, so each level that reaches an edge takes that room again. + */ +export function groupEdges(m: Model): [number, number, number, number] { + return memo(m, "group-edges", () => { + const out: [number, number, number, number] = [0, 0, 0, 0]; + for (const g of m.groups) { + const c = groupCells(m, g); + if (!c) continue; + const at = [c.r1 === 1, c.c2 === m.cols, c.r2 === m.rows, c.c1 === 1]; + // A group reaches an edge with its own depth when its child does too, or alone at depth 1. + at.forEach((on, k) => { if (on) out[k] = Math.max(out[k]!, groupLevels(m, g, k)); }); + } + return out; + }); +} +/** How many boxes a group draws past its cells on one side: 1, and 1 more for a child group that reaches that side of it. */ +function groupLevels(m: Model, g: Model["groups"][number], side: number): number { + const c = groupCells(m, g)!; + const kids = m.groups.filter((k) => k.parent === g.id); + const reaches = kids.some((k) => { const kc = groupCells(m, k); return kc && [kc.r1 === c.r1, kc.c2 === c.c2, kc.r2 === c.r2, kc.c1 === c.c1][side]; }); + return reaches ? 2 : 1; +} +/** How many group levels reach the start and the end columns: each adds space-4 to the least width. */ export function groupReach(m: Model): number { - let reach = 0; - for (const g of m.groups) { - const cols = g.members.map((id) => m.byId.get(id)!.col); - if (!cols.length) continue; - if (Math.min(...cols) === 1) reach |= 1; - if (Math.max(...cols) === m.cols) reach |= 2; - } - return (reach & 1) + ((reach >> 1) & 1); + const e = groupEdges(m); + return e[1] + e[3]; } /** The figure's columns as the least-width rules count them: a sequence's participants, a data flow's step columns, everyone else's tracks. */ @@ -775,10 +818,11 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { } if (m.type === "architecture") { for (const g of m.groups) { - const mem = g.members.map((id) => m.byId.get(id)!); - if (!mem.length) continue; - const c1 = Math.min(...mem.map((n) => n.col)), c2 = Math.max(...mem.map((n) => n.col)), r1 = Math.min(...mem.map((n) => n.row)), r2 = Math.max(...mem.map((n) => n.row2)); - out.push(h("div", { class: `${P}-gbox`, "data-group": g.id, style: `--_c:${c1};--_c2:${c2 + 1};--_r:${r1};--_r2:${r2 + 1}`, "aria-hidden": "true" }, h("span", { class: `${P}-glabel` }, g.label))); + const c = groupCells(m, g); + if (!c) continue; + // A box grown past its cells by one level on each side, and by two where a child group reaches that side of it (1.3). + const lv = [0, 1, 2, 3].map((k) => groupLevels(m, g, k)); + out.push(h("div", { class: `${P}-gbox`, "data-group": g.id, "data-depth": g.depth > 1 ? g.depth : undefined, style: `--_c:${c.c1};--_c2:${c.c2 + 1};--_r:${c.r1};--_r2:${c.r2 + 1}${lv[0]! > 1 ? ";--_gt:2" : ""}${lv[1]! > 1 ? ";--_ge:2" : ""}${lv[2]! > 1 ? ";--_gb:2" : ""}${lv[3]! > 1 ? ";--_gs:2" : ""}`, "aria-hidden": "true" }, h("span", { class: `${P}-glabel` }, g.label))); } } if (m.type === "sequence") { @@ -786,17 +830,30 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { out.push(sequenceSteps(ctx, m)); return out; } - // Nodes in the author's order; a group's members are wrapped once, so the stacked drawing can draw its box around them. + // Nodes in the author's order; a group's members are wrapped once, so the stacked drawing can draw its box around them. A nested group is a wrapper + // inside its parent's (1.3). + const outerOf = (n: MNode) => { const g = n.group ? m.groups.find((x) => x.id === n.group) : undefined; return g?.parent ? m.groups.find((x) => x.id === g.parent) : g; }; + const wrap = (g: Model["groups"][number], run: MNode[], kids: VNode[]) => { + // A stacked group takes its first member's grown gap above its box (the member itself sits at the top of the box's padding). + const grow = ctx.plan ? own(dyn.grow, run[0]!.id) ?? 0 : 0; + return h("div", { class: `${P}-group`, "data-group": g.id, "data-depth": g.depth > 1 ? g.depth : undefined, style: grow ? `--_ggrow:${grow}` : undefined }, h("span", { class: `${P}-glabel`, "aria-hidden": "true" }, g.label), kids); + }; let k = 0; while (k < m.nodes.length) { const n = m.nodes[k]!; - const g = n.group ? m.groups.find((x) => x.id === n.group) : undefined; + const g = outerOf(n); if (!g) { out.push(nodeTree(ctx, m, n, dyn)); k++; continue; } const run: MNode[] = []; - while (k < m.nodes.length && m.nodes[k]!.group === g.id) run.push(m.nodes[k++]!); - // A stacked group takes its first member's grown gap above its box (the member itself sits at the top of the box's padding). - const grow = ctx.plan ? own(dyn.grow, run[0]!.id) ?? 0 : 0; - out.push(h("div", { class: `${P}-group`, "data-group": g.id, style: grow ? `--_ggrow:${grow}` : undefined }, h("span", { class: `${P}-glabel`, "aria-hidden": "true" }, g.label), run.map((x) => nodeTree(ctx, m, x, dyn)))); + while (k < m.nodes.length && outerOf(m.nodes[k]!)?.id === g.id) run.push(m.nodes[k++]!); + const kids: VNode[] = []; + for (let j = 0; j < run.length;) { + const inner = run[j]!.group !== g.id ? m.groups.find((x) => x.id === run[j]!.group) : undefined; + if (!inner) { kids.push(nodeTree(ctx, m, run[j]!, dyn)); j++; continue; } + const sub: MNode[] = []; + while (j < run.length && run[j]!.group === inner.id) sub.push(run[j++]!); + kids.push(wrap(inner, sub, sub.map((x) => nodeTree(ctx, m, x, dyn)))); + } + out.push(wrap(g, run, kids)); } return out; } @@ -841,9 +898,14 @@ function buildList(P: string, m: Model): VNode[] { const out: VNode[] = [H("Parts")]; const loose = m.nodes.filter((n) => !n.group); if (loose.length) out.push(h("ul", { class: `${P}-list-items` }, loose.map(part))); - for (const g of m.groups) { + // Direct members, then each child group under its label (1.3). + for (const g of m.groups.filter((x) => x.depth === 1)) { out.push(h("p", { class: `${P}-list-group` }, g.label)); - out.push(h("ul", { class: `${P}-list-items` }, g.members.map((id) => part(m.byId.get(id)!)))); + if (g.members.length) out.push(h("ul", { class: `${P}-list-items` }, g.members.map((id) => part(m.byId.get(id)!)))); + for (const c of m.groups.filter((x) => x.parent === g.id)) { + out.push(h("p", { class: `${P}-list-group`, "data-depth": 2 }, c.label)); + out.push(h("ul", { class: `${P}-list-items`, "data-depth": 2 }, c.members.map((id) => part(m.byId.get(id)!)))); + } } out.push(H("Connections")); out.push(h("ol", { class: `${P}-list-items` }, m.edges.map((e) => h("li", null, strong(name(e.from)), " to ", strong(name(e.to)), e.label ? [": ", code(said(e.label))] : "", `${kw(e.kind)}.`)))); @@ -975,10 +1037,11 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { if ((m.type === "architecture" && m.groups.length) || (drawn && dyn.pad)) { // The drawn layout keeps room for a group's box where it reaches an edge: space-8 above, space-4 at a side and below. A padded layout // (Dyn.pad) keeps at least space-3 above and below, for the seats beside a line in the first or the last row. - const members = m.type === "architecture" ? m.groups.flatMap((g) => g.members.map((id) => m.byId.get(id)!)) : []; - const pad = (on: boolean, step: string, least?: string) => (on ? `var(--basalt-space-${step})` : least ? `var(--basalt-space-${least})` : "0px"); + // Each group level that reaches an edge takes its room again (1.3): space-8 above, space-4 at a side and below. + const e: [number, number, number, number] = m.type === "architecture" ? groupEdges(m) : [0, 0, 0, 0]; + const pad = (levels: number, step: string, least?: string) => (levels ? (levels > 1 ? `calc(${levels} * var(--basalt-space-${step}))` : `var(--basalt-space-${step})`) : least ? `var(--basalt-space-${least})` : "0px"); const block = drawn && dyn.pad ? "3" : undefined; - style.push(`--_gpad:${pad(members.some((n) => n.row === 1), "8", block)} ${pad(members.some((n) => n.col === m.cols), "4")} ${pad(members.some((n) => n.row2 === m.rows), "4", block)} ${pad(members.some((n) => n.col === 1), "4")}`); + style.push(`--_gpad:${pad(e[0], "8", block)} ${pad(e[1], "4")} ${pad(e[2], "4", block)} ${pad(e[3], "4")}`); } // A schema of one column with a foreign key: its turn-backs run space-4 out on the end side, past the cards, so the drawn layout keeps space-5 there // (the turn-back and its stroke on the pixel grid); the fit rule counts it (minimums). diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 4185dc65..d8b542cc 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4584,17 +4584,24 @@ .basalt-diagram-group > .basalt-diagram-glabel + .basalt-diagram-node { --_d-mt: 0; } .basalt-diagram-glabel { position: absolute; top: var(--basalt-space-2); inset-inline-start: var(--basalt-space-3); color: var(--basalt-text-secondary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); white-space: nowrap; } .basalt-diagram-group > .basalt-diagram-glabel { --_d-gl: var(--_drawn) none; display: var(--_d-gl, block); } + /* Stacked, a group's label sits on a ground plate over the lines, so a line that crosses it stops either side (DECISIONS 306, 1.3). */ + .basalt-diagram-group > .basalt-diagram-glabel { z-index: 1; margin-inline-start: calc(-1 * var(--basalt-space-1-5)); padding-inline: var(--basalt-space-1-5); background: var(--_ground); } .basalt-diagram-gbox { --_d-gb: var(--_drawn) block; position: relative; display: var(--_d-gb, none); grid-column: var(--_c) / var(--_c2); grid-row: var(--_r) / var(--_r2); - margin: calc(-1 * var(--basalt-space-8)) calc(-1 * var(--basalt-space-4)) calc(-1 * var(--basalt-space-4)); + /* One level past the cells on each side, two where a child group reaches that side (DECISIONS 306, 1.3: --_gt, --_ge, --_gb, --_gs). */ + margin-block: calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4)); + margin-inline: calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4)); border: var(--basalt-size-hairline) dashed var(--basalt-diagram-structure); border-radius: var(--basalt-radius-lg); pointer-events: none; } + /* A nested group (1.3): space-4 inside its parent at the sides and below, space-8 below its top, radius 8. Its label is the merged label. */ + .basalt-diagram-gbox[data-depth="2"], .basalt-diagram-group[data-depth="2"] { border-radius: var(--basalt-radius-md); } + .basalt-diagram-list-group[data-depth="2"], .basalt-diagram-list-items[data-depth="2"] { margin-inline-start: var(--basalt-space-5); } /* A data flow's lanes: bands ruled apart with the divider, centred in the row gap, the first unruled; the name carries the lane. */ .basalt-diagram-lane { --_d-ln: var(--_drawn) flex; position: relative; display: var(--_d-ln, none); grid-column: 1 / -1; grid-row: var(--_r); align-items: center; pointer-events: none; } @@ -4784,6 +4791,10 @@ @container (width >= 784px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="4"][data-reach="1"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- an architecture of 4 columns reaching both sides: 4 × 144 + 3 × 64 + 2 × 16 = 800px; a sequence of 5: 5 × size-diagram-node (144) + 4 × space-5 (20) = 800px */ @container (width >= 800px) { .basalt-diagram:not([data-layout]):is([data-type="architecture"][data-cols="4"][data-reach="2"], [data-type="sequence"][data-cols="5"]) > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- an architecture of 4 columns with three group levels at its sides (DECISIONS 306, 1.3): 4 × 144 + 3 × 64 + 3 × 16 = 816px */ + @container (width >= 816px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="4"][data-reach="3"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- an architecture of 4 columns with four group levels at its sides: 4 × 144 + 3 × 64 + 4 × 16 = 832px */ + @container (width >= 832px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="4"][data-reach="4"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a data flow of 4 step columns: 120 + 4 × (144 + 48) = 888px */ @container (width >= 888px) { .basalt-diagram:not([data-layout])[data-type="data-flow"][data-cols="4"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a sequence of 6: 6 × 144 + 5 × 20 = 964px */ @@ -4794,6 +4805,10 @@ @container (width >= 992px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="5"][data-reach="1"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- an architecture of 5 columns reaching both sides: 5 × 144 + 4 × 64 + 2 × 16 = 1008px */ @container (width >= 1008px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="5"][data-reach="2"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- an architecture of 5 columns with three group levels at its sides: 5 × 144 + 4 × 64 + 3 × 16 = 1024px */ + @container (width >= 1024px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="5"][data-reach="3"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- an architecture of 5 columns with four group levels: 5 × 144 + 4 × 64 + 4 × 16 = 1040px */ + @container (width >= 1040px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="5"][data-reach="4"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a schema of 4: 4 × size-diagram-table (224) + 3 × space-12 (48) = 1040px */ @container (width >= 1040px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-cols="4"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a data flow of 5 step columns: 120 + 5 × (144 + 48) = 1080px */ @@ -4804,6 +4819,10 @@ @container (width >= 1200px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="6"][data-reach="1"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- an architecture of 6 columns reaching both sides: 6 × 144 + 5 × 64 + 2 × 16 = 1216px */ @container (width >= 1216px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="6"][data-reach="2"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- an architecture of 6 columns with three group levels at its sides: 6 × 144 + 5 × 64 + 3 × 16 = 1232px */ + @container (width >= 1232px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="6"][data-reach="3"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- an architecture of 6 columns with four group levels at its sides: 6 × 144 + 5 × 64 + 4 × 16 = 1248px */ + @container (width >= 1248px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="6"][data-reach="4"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a data flow of 6 step columns: 120 + 6 × (144 + 48) = 1272px */ @container (width >= 1272px) { .basalt-diagram:not([data-layout])[data-type="data-flow"][data-cols="6"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a schema of 5: 5 × 224 + 4 × 48 = 1312px */ diff --git a/packages/react/test/fixtures/cimip-diagrams-b.json b/packages/react/test/fixtures/cimip-diagrams-b.json index 88050d35..fb5f9fd3 100644 --- a/packages/react/test/fixtures/cimip-diagrams-b.json +++ b/packages/react/test/fixtures/cimip-diagrams-b.json @@ -14,6 +14,11 @@ { "id": "aws", "label": "AWS · your account" + }, + { + "id": "data", + "label": "Data & logs", + "parent": "aws" } ], "nodes": [ @@ -52,7 +57,7 @@ "name": "Aurora PostgreSQL", "detail": "metadata · live window", "detailMono": true, - "group": "aws", + "group": "data", "col": 4, "row": 1, "branch": true @@ -63,7 +68,7 @@ "name": "S3", "detail": "sealed segments · transcripts", "detailMono": true, - "group": "aws", + "group": "data", "col": 4, "row": 2, "branch": true From 05870c4ea855572f019c41cb2c676602898efbcd Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:29:53 -0600 Subject: [PATCH 11/62] Link cards (DECISIONS 306, 1.4) href on an architecture, flowchart or data flow card or a schema table makes the card itself an (target _blank adds rel noopener noreferrer). It keeps the figure's roving stop, so Enter follows it, and its name is its sentence, which begins with the visible name. The cue is the core arrow-right (or external), 16px after the name's last word, which holds it: secondary at rest, primary and travelling space-0-5 on hover and focus, turned right to left; the name underlines. A press is a colour step (the fill under state-hover's wash, from color-mix). 44px tall on touch; LinkText in forced colours. The hint gains Enter "open" and the keys sentence says so. In the list the name is the same link. A participant cannot be a link. React's build now draws %glyph-mask:name% from the glyph source, as the skill's does. The extended CIMIP architecture and schema each carry one link. Co-Authored-By: Claude Opus 5.5 --- packages/react/build.mjs | 16 ++++- packages/react/src/diagram-core.ts | 66 ++++++++++++++----- packages/react/src/styles/components.css | 44 +++++++++++++ .../react/test/fixtures/cimip-diagrams-b.json | 6 +- 4 files changed, 114 insertions(+), 18 deletions(-) diff --git a/packages/react/build.mjs b/packages/react/build.mjs index 22acade7..6fee4adc 100644 --- a/packages/react/build.mjs +++ b/packages/react/build.mjs @@ -234,7 +234,21 @@ fs.writeFileSync(path.join(dist, "head", "loops.js"), loopsBootstrap); // The accent classes are generated with the tokens and ship with the components, whose Badge is the one reader of them. const accents = fs.readFileSync(require.resolve("@srasyndicate/basalt-tokens/accents.css"), "utf8"); -const components = `${fs.readFileSync(path.join(here, "src/styles/components.css"), "utf8")}\n${accents}`; +// `%glyph-mask:name%` in the stylesheet is a data URI of that core glyph, drawn with the set's 2.25 round stroke on the 24 grid, for a CSS mask (a diagram's +// link cue, DECISIONS 306, 1.4): the same drawing as the HTML skill's (tools/html-skill/build.mjs), from the same source, never redrawn by hand. +const { GLYPHS: CORE_GLYPHS, slots: glyphSlots } = await import(pathToFileURL(path.join(here, "glyphs", "source.mjs")).href); +const glyphMaskUri = (name) => { + const glyph = CORE_GLYPHS[name]; + if (!glyph || !(glyph.s || glyph.of)) throw new Error(`build: "${name}" is not a core glyph with a drawing`); + const near = (a, b) => Math.abs(a - b) < 1e-6; + const d = (glyph.s ?? glyphSlots(name)).filter((slot) => slot[8]).map(([x0, y0, x1, y1, x2, y2, x3, y3]) => { + const straight = near(x1, x0 + (x3 - x0) / 3) && near(y1, y0 + (y3 - y0) / 3) && near(x2, x0 + (2 * (x3 - x0)) / 3) && near(y2, y0 + (2 * (y3 - y0)) / 3); + return straight ? `M${x0} ${y0}L${x3} ${y3}` : `M${x0} ${y0}C${x1} ${y1} ${x2} ${y2} ${x3} ${y3}`; + }).join(""); + const svg = ``; + return `data:image/svg+xml,${svg.replace(//g, "%3E")}`; +}; +const components = `${fs.readFileSync(path.join(here, "src/styles/components.css"), "utf8").replace(/%glyph-mask:([\w-]+)%/g, (_, name) => glyphMaskUri(name))}\n${accents}`; // Geist Sans and Mono, variable (SIL OFL 1.1, licence shipped beside the files). const geist = path.join(packageDir("geist"), "dist", "fonts"); diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index e15e2711..bf1637ec 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -38,6 +38,10 @@ export interface DiagramNode { row: number; /** Indented in the stacked drawing; a node is on the spine unless it is a branch. */ branch?: boolean; + /** The card is a link (DECISIONS 306, 1.4): the card itself is an ``, the figure's roving stop, and Enter follows it. */ + href?: string; + /** `"_blank"` opens a new tab (with `rel="noopener noreferrer"`); the cue is then the external arrow. */ + target?: "_blank"; } export interface DiagramEdge { @@ -83,7 +87,7 @@ export type DataFlowNode = Omit & { lane export interface SequenceParticipant { id: string; name: string; kind?: string; short?: string; focal?: boolean } export type SequenceStep = { from: string; to: string; label: string; note?: string; kind?: DiagramLineKind } | { band: string }; export interface SchemaColumn { name: string; type?: string; key?: "PK" | "FK"; references?: string } -export interface SchemaTable { name: string; col: number; row: number | [number, number]; focal?: boolean; more?: number; columns: SchemaColumn[] } +export interface SchemaTable { name: string; col: number; row: number | [number, number]; focal?: boolean; more?: number; columns: SchemaColumn[]; href?: string; target?: "_blank" } export interface DiagramShapeLabels { terminal?: string; step?: string; decision?: string } /** Everything a figure is drawn from: the React props, or the HTML skill's JSON, key for key. */ @@ -137,6 +141,9 @@ export interface MNode { short?: string; /** A card's mark: a bundled id (the HTML skill's page holds its rule) or the two URLs. */ mark?: { id?: string; onLight?: string; onDark?: string; says?: string[] }; + /** A link card (1.4). */ + href?: string; + blank?: boolean; } export interface MEdge { i: number; @@ -306,6 +313,16 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model } } + // Link cards (1.4): any card but a sequence's participant (its stacked chip has no room for a 44px target). + const rawCards = (type === "schema" ? spec.tables : type === "sequence" ? spec.participants : spec.nodes) as Array<{ href?: unknown; target?: unknown }> | undefined; + (rawCards ?? []).forEach((raw, k) => { + if (!raw || raw.href === undefined || raw.href === null) return; + const href = String(raw.href); + if (type === "sequence") { dev && warn(`${nodes[k]?.id}: a participant cannot be a link (href)`); return; } + if (!href) { dev && warn(`${nodes[k]?.id}'s href is empty`); return; } + const n = nodes[k]; + if (n) { n.href = href; n.blank = raw.target === "_blank"; } + }); const byId = new Map(); for (const n of nodes) { if (dev && !n.id) warn("a node has no id"); @@ -744,12 +761,19 @@ function inlineArrow(P: string, kind: DiagramLineKind): VElement { // ---- Nodes ---- +/** A card's name; a link card's last word is held with its cue (the stylesheet's arrow after it), so the arrow never leaves the name's last word (1.4). */ +function linkName(P: string, n: MNode): VChild { + if (!n.href) return n.name; + const at = n.name.trimEnd().lastIndexOf(" "); + return [at < 0 ? "" : n.name.slice(0, at + 1), h("span", { class: `${P}-name-end` }, at < 0 ? n.name : n.name.slice(at + 1))]; +} + function nodeText(P: string, m: Model, n: MNode): VChild[] { - if (n.shape === "decision") return [h("span", { class: `${P}-words` }, h("span", { class: `${P}-name` }, n.name))]; + if (n.shape === "decision") return [h("span", { class: `${P}-words` }, h("span", { class: `${P}-name` }, linkName(P, n)))]; const kids: VNode[] = []; if (m.type === "data-flow") kids.push(h("span", { class: `${P}-kind` }, n.kind!, h("span", { class: `${P}-lane-word` }, ` · ${n.laneLabel}`))); else if (n.kind) kids.push(h("span", { class: `${P}-kind` }, n.kind)); - kids.push(h("span", { class: `${P}-name` }, n.name)); + kids.push(h("span", { class: `${P}-name` }, linkName(P, n))); // An identifier breaks only at its spaces: each run between them is kept whole (an ordinary hyphen stays, so a copy is exact). if (n.detail) kids.push(h("span", { class: `${P}-detail`, "data-mono": n.mono ? "" : undefined }, n.mono ? words(n.detail).flatMap((w, j) => [j ? " " : "", h("span", { class: `${P}-run` }, w)]) : n.detail)); return kids; @@ -757,7 +781,7 @@ function nodeText(P: string, m: Model, n: MNode): VChild[] { function tableText(P: string, n: MNode): VChild[] { return [ - h("span", { class: `${P}-th` }, h("span", { class: `${P}-tname` }, n.name)), + h("span", { class: `${P}-th` }, h("span", { class: `${P}-tname` }, linkName(P, n))), h("span", { class: `${P}-rows` }, (n.columns ?? []).map((c, k) => h("span", { class: `${P}-row`, "data-row": k, "data-key": c.key }, h("span", { class: `${P}-keyseat` }, c.key ?? ""), h("span", { class: `${P}-cname` }, c.name), @@ -791,8 +815,13 @@ function nodeTree(ctx: TreeContext, m: Model, n: MNode, dyn: Dyn): VElement { const wordsWidth = own(dyn.words, n.id); if (wordsWidth) style.push(`--_ww:${wordsWidth}px`); const tabbable = stops ? (dyn.stop === n.id ? 0 : -1) : dyn.keep === n.id ? -1 : undefined; - return h("div", { + // A link card is the link itself (1.4): its name is its sentence, read with the link role, and it begins with the card's visible name. + return h(n.href ? "a" : "div", { class: `${P}-node`, + href: n.href, + target: n.href && n.blank ? "_blank" : undefined, + rel: n.href && n.blank ? "noopener noreferrer" : undefined, + "data-link": n.href ? (n.blank ? "external" : "") : undefined, "data-node": n.id, "data-shape": n.shape, "data-focal": n.focal ? "" : undefined, @@ -800,8 +829,8 @@ function nodeTree(ctx: TreeContext, m: Model, n: MNode, dyn: Dyn): VElement { "data-mark": n.mark ? n.mark.id ?? "" : undefined, "data-level": ctx.level, style: style.join(";"), - role: images ? "img" : undefined, - "aria-label": images ? nodeSentence(m, n) : undefined, + role: images && !n.href ? "img" : undefined, + "aria-label": images || n.href ? nodeSentence(m, n) : undefined, tabindex: tabbable, }, n.shape === "decision" ? h("svg", { class: `${P}-diamond`, viewBox: "0 0 100 100", preserveAspectRatio: "none", "aria-hidden": "true", focusable: "false" }, h("path", { d: "M50 0L100 50L50 100L0 50Z" })) : null, @@ -889,12 +918,14 @@ function buildList(P: string, m: Model): VNode[] { const sub = Math.min(6, m.heading + 1); const H = (text: string) => h(`h${sub}`, { class: `${P}-list-head` }, text); const strong = (s: string) => h("strong", null, s); + // A link card's name in the list is the same link (1.4). + const named = (n: MNode) => (n.href ? h("a", { href: n.href, target: n.blank ? "_blank" : undefined, rel: n.blank ? "noopener noreferrer" : undefined }, strong(n.name)) : strong(n.name)); const code = (s: string) => h("code", { class: `${P}-code` }, s); const name = (id: string) => m.byId.get(id)?.name ?? id; const kw = (k: DiagramLineKind) => { const w = kindWord(m, k); return w ? ` (${w})` : ""; }; const focal = (n: MNode) => (n.focal && m.legend.focal ? ` ${sentence(m.legend.focal)}` : ""); if (m.type === "architecture") { - const part = (n: MNode) => h("li", null, strong(n.name), n.kind ? `, ${n.kind}` : "", n.detail ? [". ", n.mono ? code(n.detail) : n.detail, /[.!?]$/.test(n.detail) ? "" : "."] : /[.!?]$/.test(n.kind ?? n.name) ? "" : ".", focal(n)); + const part = (n: MNode) => h("li", null, named(n), n.kind ? `, ${n.kind}` : "", n.detail ? [". ", n.mono ? code(n.detail) : n.detail, /[.!?]$/.test(n.detail) ? "" : "."] : /[.!?]$/.test(n.kind ?? n.name) ? "" : ".", focal(n)); const out: VNode[] = [H("Parts")]; const loose = m.nodes.filter((n) => !n.group); if (loose.length) out.push(h("ul", { class: `${P}-list-items` }, loose.map(part))); @@ -917,14 +948,14 @@ function buildList(P: string, m: Model): VNode[] { const exits = m.edges.filter((e) => e.from === n.id); const what = n.shape === "decision" ? "Decision" : n.shape === "terminal" ? (exits.length ? "Start" : "End") : "Step"; const stop = !n.detail && /[.!?]$/.test(n.name) ? " " : ". "; - return h("li", null, strong(n.name), n.detail ? [", ", n.mono ? code(n.detail) : n.detail] : "", `${stop}${what}.`, focal(n), + return h("li", null, named(n), n.detail ? [", ", n.mono ? code(n.detail) : n.detail] : "", `${stop}${what}.`, focal(n), exits.length ? h("ul", { class: `${P}-list-exits` }, exits.map((e) => h("li", null, e.label ? `If ${said(e.label)}: go to ${num(e.to)}, ` : `Then: go to ${num(e.to)}, `, strong(name(e.to)), kw(e.kind)))) : null); }))]; } if (m.type === "data-flow") { return [h("ol", { class: `${P}-list-items` }, m.nodes.map((n) => { const exits = m.edges.filter((e) => e.from === n.id); - return h("li", null, `${n.laneLabel}: `, strong(n.name), n.detail ? [", ", n.mono ? code(n.detail) : n.detail] : "", ".", focal(n), + return h("li", null, `${n.laneLabel}: `, named(n), n.detail ? [", ", n.mono ? code(n.detail) : n.detail] : "", ".", focal(n), exits.length ? [" Then ", ...exits.flatMap((e, j) => [j ? "; " : "", `to step ${m.byId.get(e.to)!.step}, `, strong(name(e.to)), e.label ? [": ", code(said(e.label))] : "", kw(e.kind)]), "."] : ""); }))]; } @@ -944,7 +975,7 @@ function buildList(P: string, m: Model): VNode[] { const out: VNode[] = []; for (const n of m.nodes) { // A table's name is a sub-heading one level under the title's, as "Parts" and "Connections" are. - out.push(h(`h${sub}`, { class: `${P}-list-group` }, code(n.name), focal(n))); + out.push(h(`h${sub}`, { class: `${P}-list-group` }, n.href ? h("a", { href: n.href, target: n.blank ? "_blank" : undefined, rel: n.blank ? "noopener noreferrer" : undefined }, code(n.name)) : code(n.name), focal(n))); out.push(h("ul", { class: `${P}-list-items` }, [ ...(n.columns ?? []).map((c) => h("li", null, code(c.name), c.key === "PK" ? ", primary key" : c.key === "FK" ? ", foreign key" : "", c.ref ? [", references ", code(`${c.ref.table}.${c.ref.column}`)] : c.type ? `, ${c.type}` : "")), ...(n.more ? [h("li", null, `and ${n.more} more ${n.more === 1 ? "column" : "columns"}`)] : []), @@ -957,13 +988,15 @@ function buildList(P: string, m: Model): VNode[] { function keysSentence(m: Model, drawn = false): string { const noun = m.type === "architecture" ? "part" : m.type === "sequence" ? "participant" : m.type === "schema" ? "table" : "step"; const arrows = drawn && spatialTable(m) ? `Arrow keys move to the nearest ${noun} in that direction` : `Arrow keys move to the next or the previous ${noun}, in the author's order`; - return `${arrows}; Home and End go to the ends; Escape clears the trace.`; + // Where a card is a link (1.4), Enter follows it. + return `${arrows}; Home and End go to the ends; Escape clears the trace.${m.nodes.some((n) => n.href) ? " Enter opens a part that is a link." : ""}`; } /** The key hint's entries: the keys and their words. Four arrows where a drawn figure has more than one row and more than one column (1.5). */ export function hintEntries(m: Model, drawn = false): Array<{ keys: string[]; words: string }> { const four = drawn && m.type !== "sequence" && spatialTable(m) && m.cols > 1 && m.rows > 1; - return [{ keys: four ? ["←", "↑", "↓", "→"] : ["←", "→"], words: stopNoun(m) }, { keys: ["Home", "End"], words: "the ends" }, { keys: ["Esc"], words: "clear" }]; + const open = m.nodes.some((n) => n.href) ? [{ keys: ["Enter"], words: "open" }] : []; + return [{ keys: four ? ["←", "↑", "↓", "→"] : ["←", "→"], words: stopNoun(m) }, { keys: ["Home", "End"], words: "the ends" }, ...open, { keys: ["Esc"], words: "clear" }]; } // ---- The spatial arrow keys (DECISIONS 306, 1.5): on a card's column and rows, never on its measured centre ---- @@ -1249,14 +1282,17 @@ function minimums(m: Model, tk: Tokens, measure: ReturnType) { const row = s("6") + measure(c.name, "mono") + (type ? s("3") + measure(type, "mono") : 0) + 2 * s("3") + 2 * tk.hair; table = Math.max(table, Math.ceil(row)); } - table = Math.max(table, Math.ceil(measure(n.name, "table") + 2 * s("3") + 2 * tk.hair)); + table = Math.max(table, Math.ceil(measure(n.name, "table") + 2 * s("3") + 2 * tk.hair + (n.href ? 16 + s("1-5") : 0))); continue; } const pad = n.shape === "terminal" ? 2 * s("5") : 2 * s("3"); // The first line (the kind, or the name on a card with no kind) keeps space-6 clear of a mark, except in forced colours, where none is drawn. const seat = n.mark && !forced() ? s("6") : 0; let widest = 0; - for (const w of words(n.name)) widest = Math.max(widest, measure(w, n.shape === "decision" ? "name-500" : "name") + (n.kind ? 0 : seat)); + // A link card's last word carries its cue, 16 and space-1-5 before it (1.4). + const cue = n.href ? 16 + s("1-5") : 0; + const nameWords = words(n.name); + nameWords.forEach((w, j) => { widest = Math.max(widest, measure(w, n.shape === "decision" ? "name-500" : "name") + (n.kind ? 0 : seat) + (j === nameWords.length - 1 ? cue : 0)); }); if (m.type !== "data-flow") for (const w of words(n.kind)) widest = Math.max(widest, measure(w, "mono") + seat); for (const w of words(n.detail)) widest = Math.max(widest, measure(w, n.mono ? "mono" : "sans")); const need = n.shape === "decision" ? widest / 0.62 : widest + pad + 2 * tk.hair; diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index d8b542cc..c7e18dd8 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4567,6 +4567,50 @@ .basalt-diagram-node[data-shape="decision"][data-near] .basalt-diagram-diamond path { stroke: var(--basalt-text-secondary); } .basalt-diagram-node[data-shape="decision"][data-focal] .basalt-diagram-diamond path { fill: var(--basalt-diagram-focal); stroke: var(--basalt-diagram-focal); } + /* A card that is a link (DECISIONS 306, 1.4): the card is the link and the figure's roving stop. Its cue is foundations' arrow (the core arrow-right, or + external for a new tab) at 16, space-1-5 after the name's last word, which it never leaves: secondary at rest (the focal card's quiet ink), primary + on hover and focus, travelling space-0-5. Hover and focus underline the name; a press is a colour step, never a scale. */ + .basalt-diagram-node[data-link] { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; } + .basalt-diagram-name-end { white-space: nowrap; } + .basalt-diagram-node[data-link] .basalt-diagram-name-end::after { + content: ""; + display: inline-block; + width: var(--basalt-size-icon-sm); + height: var(--basalt-size-icon-sm); + margin-inline-start: var(--basalt-space-1-5); + vertical-align: calc(-1 * var(--basalt-space-0-5)); + background: var(--basalt-text-secondary); + mask: url("%glyph-mask:arrow-right%") center / contain no-repeat; + transition: transform var(--basalt-duration-base) var(--basalt-ease-out), background-color var(--basalt-duration-base) var(--basalt-ease-out); + } + .basalt-diagram-node[data-link="external"] .basalt-diagram-name-end::after { mask-image: url("%glyph-mask:external%"); } + .basalt-diagram-node[data-link][data-focal] .basalt-diagram-name-end::after { background: var(--basalt-diagram-focal-ink); opacity: var(--basalt-opacity-amount); } + .basalt-diagram-node[data-link]:is(:hover, :focus-visible) .basalt-diagram-name-end::after { background: var(--basalt-text-primary); transform: translateX(var(--basalt-space-0-5)); } + .basalt-diagram-node[data-link][data-focal]:is(:hover, :focus-visible) .basalt-diagram-name-end::after { background: var(--basalt-diagram-focal-ink); opacity: 1; } + .basalt-diagram-node[data-link]:is(:hover, :focus-visible) :is(.basalt-diagram-name, .basalt-diagram-tname) { text-decoration: underline var(--basalt-size-hairline); text-underline-offset: var(--basalt-size-underline-offset); } + /* The press: the card's fill under state-hover's wash, one colour from color-mix at the token's own alpha (black 4% in light, white 6% in dark), as the + still table's pinned cells take theirs. */ + .basalt-diagram-node[data-link]:active { background: light-dark(color-mix(in srgb, var(--basalt-neutral-0) 4%, var(--_surface, var(--basalt-surface-1))), color-mix(in srgb, var(--basalt-neutral-100) 6%, var(--_surface, var(--basalt-surface-1)))); } + @supports not (color: light-dark(white, black)) { + .basalt-diagram-node[data-link]:active { background: color-mix(in srgb, color-mix(in srgb, var(--basalt-neutral-100) 6%, var(--_surface, var(--basalt-surface-1))) var(--_dkp), color-mix(in srgb, var(--basalt-neutral-0) 4%, var(--_surface, var(--basalt-surface-1)))); } + } + .basalt-diagram-node[data-link][data-focal]:active { background: var(--basalt-action-primary-press); } + .basalt-diagram-node[data-link]:dir(rtl) .basalt-diagram-name-end::after { scale: -1 1; } + .basalt-diagram-node[data-link]:dir(rtl):is(:hover, :focus-visible) .basalt-diagram-name-end::after { transform: translateX(calc(-1 * var(--basalt-space-0-5))); } + @media (prefers-reduced-motion: reduce) { + .basalt-diagram-node[data-link]:is(:hover, :focus-visible) .basalt-diagram-name-end::after, .basalt-diagram-node[data-link]:dir(rtl):is(:hover, :focus-visible) .basalt-diagram-name-end::after { transform: none; } + } + /* A card that answers a tap is at least size-tap-min tall on touch (1.5). */ + @media (pointer: coarse) { + .basalt-diagram-node[data-link] { min-height: var(--basalt-size-tap-min); } + } + @media (forced-colors: active) { + .basalt-diagram .basalt-diagram-node[data-link] :is(.basalt-diagram-name, .basalt-diagram-tname) { color: LinkText; text-decoration: underline; } + .basalt-diagram .basalt-diagram-node[data-link] .basalt-diagram-name-end::after { forced-color-adjust: none; background: LinkText; } + .basalt-diagram .basalt-diagram-node[data-link][data-focal] :is(.basalt-diagram-name, .basalt-diagram-tname) { color: Canvas; } + .basalt-diagram .basalt-diagram-node[data-link][data-focal] .basalt-diagram-name-end::after { background: Canvas; } + } + /* A group: a transparent box with a 1px dashed structure edge, radius 12, its label at the top start. Stacked, the box wraps its members; drawn, the members sit in the author's grid and the box spans their cells, space-4 outside them and space-8 above. */ .basalt-diagram-group { diff --git a/packages/react/test/fixtures/cimip-diagrams-b.json b/packages/react/test/fixtures/cimip-diagrams-b.json index fb5f9fd3..0b021bb9 100644 --- a/packages/react/test/fixtures/cimip-diagrams-b.json +++ b/packages/react/test/fixtures/cimip-diagrams-b.json @@ -49,7 +49,8 @@ "focal": true, "group": "aws", "col": 3, - "row": 2 + "row": 2, + "href": "#fig-sequence" }, { "id": "aurora", @@ -734,7 +735,8 @@ "name": "summary", "type": "text" } - ] + ], + "href": "#fig-architecture" }, { "name": "users", From 71a2db325317c7d46ba641d10e9b92dec38183b3 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:34:25 -0600 Subject: [PATCH 12/62] Sequence activations and frames (DECISIONS 306, 1.2) A message may carry activate (its receiver starts working) and deactivate (its sender stops after it); they pair by a stack on each participant, a bar left open closes at that participant's last message, and three deep at most. A bar is size-diagram-activation wide, the head's fill in a 1px structure edge, a nested one space-1 toward the end side; a message's line ends on the bar's edge, and a self-call's loop starts from it. A frame (opt, loop, alt) is structure: 1px solid, radius 12, spanning its participants' columns, all four sides inside the drawing; its 36px header holds the tab (the operator) and the label, an alt's later branch starts under an exact 4-on-4 dashed rule and "else", and every word sits on a ground plate. A frame inside a frame is space-2 inside it where they share a side. A header wider than its frame refuses the drawn layout. Stacked, a frame is the same box round its rows. The key shows a bar ("Working") and each operator drawn with its words (frameLabels changes them); the list's sub-headings read "Only if: ...", "Otherwise: ...", and messages keep their numbers; a participant's sentence says when it is working. Forced colours as 1.10. The extended CIMIP sequence carries an opt holding a loop, an alt, and two bars. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-core.ts | 211 ++++++++++++++++-- packages/react/src/styles/components.css | 37 +++ .../react/test/fixtures/cimip-diagrams-b.json | 105 ++++++--- 3 files changed, 298 insertions(+), 55 deletions(-) diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index bf1637ec..b72d7771 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -22,7 +22,7 @@ export type DiagramSide = "top" | "right" | "bottom" | "left"; export type DiagramLineKind = "main" | "plain" | "dashed"; /** The words for the marks. The key is built from what is drawn; `main`, `dashed` and the focal node must have words when drawn. */ -export interface DiagramLegend { main?: string; plain?: string; dashed?: string; focal?: string; group?: string } +export interface DiagramLegend { main?: string; plain?: string; dashed?: string; focal?: string; group?: string; activation?: string } export interface DiagramNode { id: string; @@ -85,7 +85,14 @@ export type FlowchartNode = DiagramNode & { shape?: "step" | "decision" | "termi export interface DataFlowLane { id: string; label: string } export type DataFlowNode = Omit & { lane: string }; export interface SequenceParticipant { id: string; name: string; kind?: string; short?: string; focal?: boolean } -export type SequenceStep = { from: string; to: string; label: string; note?: string; kind?: DiagramLineKind } | { band: string }; +/** A message. `activate` starts its receiver working; `deactivate` stops its sender after it (DECISIONS 306, 1.2). */ +export type SequenceMessage = { from: string; to: string; label: string; note?: string; kind?: DiagramLineKind; activate?: boolean; deactivate?: boolean }; +/** A step: a message, a band, or a frame round a run of steps (`opt`, `loop`, or `alt` with two or more branches). Frames nest two deep. */ +export type SequenceStep = SequenceMessage | { band: string } + | { frame: "opt" | "loop"; label: string; steps: SequenceStep[] } + | { frame: "alt"; branches: Array<{ label: string; steps: SequenceStep[] }> }; +/** The words the key and the list say for each frame operator, and for an alt's later branches. */ +export interface DiagramFrameLabels { opt?: string; loop?: string; alt?: string; else?: string } export interface SchemaColumn { name: string; type?: string; key?: "PK" | "FK"; references?: string } export interface SchemaTable { name: string; col: number; row: number | [number, number]; focal?: boolean; more?: number; columns: SchemaColumn[]; href?: string; target?: "_blank" } export interface DiagramShapeLabels { terminal?: string; step?: string; decision?: string } @@ -110,6 +117,8 @@ export interface DiagramSpec { pulse?: string[]; packet?: DiagramPacket; run?: boolean; + /** A sequence's frame words (DECISIONS 306, 1.2): "Only if", "Repeats", "One of these", "Otherwise". */ + frameLabels?: DiagramFrameLabels; } // ============================================================================================================================================ @@ -160,7 +169,13 @@ export interface MEdge { /** A live stream (DECISIONS 292, 1.6). */ flow?: boolean; } -export type MStep = { band: string } | { n: number; from: string; to: string; label: string; note?: string; kind: DiagramLineKind }; +export type MStep = { band: string } | { n: number; from: string; to: string; label: string; note?: string; kind: DiagramLineKind; activate?: boolean; deactivate?: boolean } + /** A frame opens (its operator, label and depth, and the participants' columns it spans), an alt's later branch starts, or a frame closes (1.2). */ + | { open: "opt" | "loop" | "alt"; label: string; depth: number; a: number; b: number } + | { otherwise: string; depth: number } + | { close: number }; +/** A participant working: a bar from the message that starts it to the one that ends it, at a depth from 1 to 3 (1.2). */ +export interface MBar { who: string; from: number; to: number; depth: number } export interface Model { type: DiagramType; title: string; @@ -173,6 +188,10 @@ export interface Model { groups: Array; lanes: DataFlowLane[]; steps: MStep[]; + /** A sequence's activation bars (1.2). */ + bars: MBar[]; + /** A sequence's frame words. */ + frameWords: { opt: string; loop: string; alt: string; else: string }; cols: number; rows: number; shapeLabels: Required; @@ -213,7 +232,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const warn = (message: string) => { warnings.push(message); }; const legendIn = (spec.legend ?? {}) as Record; const legend: DiagramLegend = {}; - for (const k of ["main", "plain", "dashed", "focal", "group"] as const) { const w = txt(legendIn[k]); if (w) legend[k] = w; } + for (const k of ["main", "plain", "dashed", "focal", "group", "activation"] as const) { const w = txt(legendIn[k]); if (w) legend[k] = w; } const stepLabel = spec.stepLabel; const stepWord = typeof stepLabel === "function" ? (n: number) => String(stepLabel(n)) : typeof stepLabel === "string" ? ((n: number) => stepLabel.replace("{n}", String(n))) : (n: number) => `Step ${n}`; const shapeIn = (spec.shapeLabels ?? {}) as Record; @@ -289,16 +308,53 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model } else if (type === "sequence") { (spec.participants ?? []).forEach((p, k) => { const name = String(p.name ?? ""); nodes.push({ id: String(p.id ?? ""), i: k, name, kind: txt(p.kind), mono: false, focal: Boolean(p.focal), col: k + 1, row: 1, row2: 1, branch: false, shape: "participant", short: txt(p.short) ?? name }); }); let n = 0; - for (const s of spec.steps ?? []) { - if ("band" in s) steps.push({ band: String(s.band ?? "") }); - else { + const colOf = new Map(nodes.map((p) => [p.id, p.col])); + // Messages number straight through frames. A frame spans the columns of the participants that send or receive inside it, and the column a + // self-call's words run into (1.2). + const walk = (list: SequenceStep[], depth: number): [number, number] => { + let a = Infinity, b = -Infinity; + for (const s of list ?? []) { + if (!s || typeof s !== "object") continue; + if ("band" in s) { + if (depth > 0) dev && warn(`the band "${String(s.band)}" is inside a frame: a band is the whole figure's`); + steps.push({ band: String(s.band ?? "") }); + continue; + } + if ("frame" in s) { + if (depth >= 2) { dev && warn("a frame is a third level: frames nest two deep"); continue; } + const op = s.frame === "alt" || s.frame === "loop" || s.frame === "opt" ? s.frame : "opt"; + const branches = op === "alt" ? ((s as { branches?: Array<{ label: string; steps: SequenceStep[] }> }).branches ?? []) : [{ label: (s as { label: string }).label, steps: (s as { steps: SequenceStep[] }).steps }]; + if (op === "alt" && branches.length < 2) dev && warn("an alt frame has one branch: it needs two or more"); + const label = String(branches[0]?.label ?? ""); + if (label.length > 40) dev && warn(`the frame label "${label}" is over 40 characters`); + const at = steps.length; + steps.push({ open: op, label, depth: depth + 1, a: 0, b: 0 }); + branches.forEach((br, k) => { + if (k) { const l = String(br.label ?? ""); if (l.length > 40) dev && warn(`the frame label "${l}" is over 40 characters`); steps.push({ otherwise: l, depth: depth + 1 }); } + if (!br.steps?.length) dev && warn(`a frame or branch ("${String(br.label ?? "")}") is empty`); + const [x, y] = walk(br.steps ?? [], depth + 1); + a = Math.min(a, x); b = Math.max(b, y); + const open = steps[at] as { a: number; b: number }; + open.a = Math.min(open.a || Infinity, x); open.b = Math.max(open.b, y); + }); + steps.push({ close: depth + 1 }); + continue; + } n++; const label = String(s.label ?? ""); // A message's second line is its note (1.4): a break in its label is an error, and it is drawn on one line. if (label.includes("\n")) dev && warn(`message ${n}'s label has a break: a message's second line is its note`); - steps.push({ n, from: String(s.from ?? ""), to: String(s.to ?? ""), label: said(label), note: txt(s.note), kind: kindOf(s.kind, `message ${n}`) }); + const from = String(s.from ?? ""), to = String(s.to ?? ""); + steps.push({ n, from, to, label: said(label), note: txt(s.note), kind: kindOf(s.kind, `message ${n}`), activate: s.activate === true || undefined, deactivate: s.deactivate === true || undefined }); + const ca = colOf.get(from) ?? 1, cb = colOf.get(to) ?? 1; + // A self-call's words run into the next column (the one before it on the last participant). + const run = ca === cb ? (ca === nodes.length ? ca - 1 : ca + 1) : ca; + a = Math.min(a, ca, cb, run); b = Math.max(b, ca, cb, run); } - } + return [a, b]; + }; + walk(spec.steps ?? [], 0); + for (const st of steps) if ("open" in st && !Number.isFinite(st.a)) { st.a = 1; st.b = Math.max(1, nodes.length); } } else if (type === "schema") { for (const t of spec.tables ?? []) { const name = String(t.name ?? ""); @@ -404,9 +460,34 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const words = [n.name, n.kind, n.detail].filter(Boolean).join(" ").toLowerCase(); if (!says.some((w) => words.includes(w.toLowerCase()))) warn(`${n.id}'s mark stands for ${says.join(" or ")}, and none of its words say so`); } + // Activation bars (1.2): a stack on each participant. `activate` opens one on the receiver, `deactivate` closes the sender's top one after its message; + // a bar left open closes at that participant's last message. Three deep at most. + const bars: MBar[] = []; + if (type === "sequence") { + const open = new Map(); + const last = new Map(); + for (const st of steps) if ("n" in st) { last.set(st.from, st.n); last.set(st.to, st.n); } + for (const st of steps) { + if (!("n" in st)) continue; + if (st.activate) { + const stack = open.get(st.to) ?? []; + if (stack.length >= 3) dev && warn(`message ${st.n} opens a fourth bar on ${st.to}: three deep at most`); + else { const bar = { who: st.to, from: st.n, to: st.n, depth: stack.length + 1 }; stack.push(bar); bars.push(bar); open.set(st.to, stack); } + } + if (st.deactivate) { + const stack = open.get(st.from); + const top = stack?.pop(); + if (!top) dev && warn(`message ${st.n} closes a bar on ${st.from}, which has none open`); + else top.to = st.n; + } + } + for (const [who, stack] of open) for (const bar of stack) bar.to = Math.max(bar.from, last.get(who) ?? bar.from); + } + const fl = (spec.frameLabels ?? {}) as Record; + const frameWords = { opt: txt(fl.opt) ?? "Only if", loop: txt(fl.loop) ?? "Repeats", alt: txt(fl.alt) ?? "One of these", else: txt(fl.else) ?? "Otherwise" }; const cols = Math.max(1, ...nodes.map((n) => n.col)); const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, ...nodes.map((n) => n.row2)); - const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map() }; + const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map() }; if (checks && nodes.length > 1 && !spatialTable(model)) warn("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"); return model; } @@ -468,6 +549,8 @@ function writeSentence(m: Model, n: MNode): string { const gets = m.steps.filter((s) => "n" in s && s.to === n.id).length; parts.push(sentence(n.kind ? `${n.name}, ${n.kind}` : n.name)); parts.push(`Sends ${sends} ${sends === 1 ? "message" : "messages"} and receives ${gets}.`); + const w = working(m, n); + if (w) parts.push(w.trim()); } else { const what = m.type === "data-flow" ? `${m.stepWord(n.step!)} of ${m.nodes.length}, ${n.laneLabel}` : m.type === "flowchart" ? shapeWord(m, n) : n.kind; parts.push(sentence(what ? `${n.name}, ${what}` : n.name)); @@ -483,6 +566,14 @@ function writeSentence(m: Model, n: MNode): string { return parts.join(" "); } +/** A participant's working stretches in words (1.2): " Working during messages 6 to 12." (and "message 3" for one). */ +function working(m: Model, n: MNode): string { + const bars = m.bars.filter((b) => b.who === n.id && b.depth === 1); + if (!bars.length) return ""; + const word = m.legend.activation ?? "Working"; + return ` ${word} during ${bars.map((b) => (b.from === b.to ? `message ${b.from}` : `messages ${b.from} to ${b.to}`)).join(" and ")}.`; +} + /** The noun the key hint and the keys sentence use for one stop. */ function stopNoun(m: Model): string { return m.type === "architecture" ? "a part" : m.type === "sequence" ? "a participant" : m.type === "schema" ? "a table" : "a step"; @@ -743,6 +834,12 @@ function buildKey(P: string, m: Model): VElement | null { entry(lineSwatch(P, "fk"), m.legend.plain ?? "A foreign key, to the key it references", { "data-line": "", "data-when": "drawn" }); entries.push(h("li", { class: `${P}-entry`, "data-when": "stacked" }, h("span", { class: `${P}-fk-mark`, "aria-hidden": "true" }, "→"), h("span", null, "The table a foreign key references"))); } + if (m.type === "sequence") { + // A bar on a dashed lifeline, where one is drawn (1.2); then each frame operator drawn, its letters set as the tab sets them, and its words. + if (m.bars.length) entry(h("svg", { class: `${P}-swatch`, "data-shape": "bar", ...svgA(16, 16) }, h("path", { class: `${P}-life`, d: "M8 0V16" }), h("rect", { class: `${P}-bar`, x: 4.5, y: 2.5, width: 7, height: 11, rx: 1.5 })), m.legend.activation ?? "Working", { "data-when": "drawn" }); + const ops = new Set(m.steps.flatMap((st) => ("open" in st ? [st.open] : []))); + for (const op of ["opt", "loop", "alt"] as const) if (ops.has(op)) entries.push(h("li", { class: `${P}-entry` }, h("span", { class: `${P}-key-letters`, "data-op": "" , "aria-hidden": "true" }, op), h("span", null, m.frameWords[op]))); + } if (m.nodes.some((n) => n.focal) && m.legend.focal) entry(boxSwatch(P, "focal"), m.legend.focal, { "data-focal": "" }); if (m.groups.length && m.legend.group) entry(boxSwatch(P, "group"), m.legend.group); if (!entries.length) return null; @@ -889,11 +986,32 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { function sequenceSteps(ctx: TreeContext, m: Model): VElement { const { P } = ctx; - const blocks: VNode[] = []; + const root: VNode[] = []; + // Frames (DECISIONS 306, 1.2) are boxes round their rows: each one a block holding its header, its rows and the frames inside it. + const stack: Array<{ el: VElement; a: number; b: number }> = []; + const into = () => (stack.length ? stack[stack.length - 1]!.el.c : root); let list: VElement | null = null; for (const s of m.steps) { - if ("band" in s) { list = null; blocks.push(h("p", { class: `${P}-band` }, h("span", null, s.band))); continue; } - if (!list) { list = h("ol", { class: `${P}-msgs`, start: s.n }); blocks.push(list); } + if ("band" in s) { list = null; into().push(h("p", { class: `${P}-band` }, h("span", null, s.band))); continue; } + if ("open" in s) { + list = null; + const parent = stack[stack.length - 1]; + // A frame inside a frame is space-2 inside it on every side they share. + const inset = parent ? `;--_fis:${s.a === parent.a ? 1 : 0};--_fie:${s.b === parent.b ? 1 : 0}` : ""; + const el = h("div", { class: `${P}-frame`, "data-op": s.open, "data-depth": s.depth, style: `--_a:${s.a};--_b:${s.b + 1}${inset}` }, + h("span", { class: `${P}-fbox`, "aria-hidden": "true" }), + h("p", { class: `${P}-fhead` }, h("span", { class: `${P}-ftab`, "aria-hidden": "true" }, s.open), h("span", { class: `${P}-flabel` }, h("span", { class: ctx.hidden }, `${m.frameWords[s.open]}: `), s.label))); + into().push(el); + stack.push({ el, a: s.a, b: s.b }); + continue; + } + if ("otherwise" in s) { + list = null; + into().push(h("p", { class: `${P}-felse` }, h("span", { class: `${P}-fword`, "aria-hidden": "true" }, "else"), h("span", { class: `${P}-flabel` }, h("span", { class: ctx.hidden }, `${m.frameWords.else}: `), s.otherwise))); + continue; + } + if ("close" in s) { list = null; stack.pop(); continue; } + if (!list) { list = h("ol", { class: `${P}-msgs`, start: s.n }); into().push(list); } const a = m.byId.get(s.from), b = m.byId.get(s.to); const ca = a?.col ?? 1, cb = b?.col ?? 1; const self = ca === cb; @@ -904,7 +1022,7 @@ function sequenceSteps(ctx: TreeContext, m: Model): VElement { h("span", { class: `${P}-route` }, a?.short ?? s.from, " ", inlineArrow(P, s.kind), h("span", { class: ctx.hidden }, " to "), " ", b?.short ?? s.to, word ? ` · ${word}` : ""), s.note ? h("span", { class: `${P}-note` }, s.note) : null)); } - return h("div", { class: `${P}-steps` }, blocks); + return h("div", { class: `${P}-steps` }, root); } // ---- The list ("View as list") ---- @@ -960,12 +1078,16 @@ function buildList(P: string, m: Model): VNode[] { }))]; } if (m.type === "sequence") { - const out: VNode[] = [H("Participants"), h("ul", { class: `${P}-list-items` }, m.nodes.map((n) => h("li", null, strong(n.name), n.kind ? `, ${n.kind}` : "", ".", focal(n))))]; + const out: VNode[] = [H("Participants"), h("ul", { class: `${P}-list-items` }, m.nodes.map((n) => h("li", null, strong(n.name), n.kind ? `, ${n.kind}` : "", ".", focal(n), working(m, n))))]; out.push(H("Messages")); let list: VElement | null = null; for (const s of m.steps) { // A band names a phase: a sub-heading one level under "Messages" (never past h6), drawn as the list's group line. if ("band" in s) { list = null; out.push(h(`h${Math.min(6, sub + 1)}`, { class: `${P}-list-group` }, s.band)); continue; } + // A frame is a sub-heading as a band is (1.2): "Only if: First run on an incident only", "Otherwise: Rejected". Messages keep their numbers. + if ("open" in s) { list = null; out.push(h(`h${Math.min(6, sub + 1)}`, { class: `${P}-list-group`, "data-depth": s.depth > 1 ? s.depth : undefined }, `${m.frameWords[s.open]}: ${s.label}`)); continue; } + if ("otherwise" in s) { list = null; out.push(h(`h${Math.min(6, sub + 1)}`, { class: `${P}-list-group`, "data-depth": s.depth > 1 ? s.depth : undefined }, `${m.frameWords.else}: ${s.otherwise}`)); continue; } + if ("close" in s) { list = null; continue; } if (!list) { list = h("ol", { class: `${P}-list-items`, start: s.n }); out.push(list); } list.c.push(h("li", null, code(s.label), ": ", strong(name(s.from)), " to ", strong(name(s.to)), `${kw(s.kind)}.`, s.note ? ` ${sentence(s.note)}` : "")); } @@ -1149,6 +1271,10 @@ export interface Geo { nodes: GNode[]; lines: GLine[]; lifelines: Array<{ x: number; y1: number; y2: number }>; + /** A sequence's activation bars (DECISIONS 306, 1.2): structure, drawn over the lifelines and under the lines. */ + bars?: Array<{ l: number; r: number; t: number; b: number }>; + /** What does not fit and is not a line or a label (a frame's header wider than its frame): the drawn layout is refused. */ + misfit?: string[]; labels: GLabel[]; crossings: GCross[]; /** Lines that pass through a node (by edge index), labels that found no seat, words that do not fit their span. */ @@ -1168,6 +1294,8 @@ export interface Tokens { node: number; table: number; lane: number; step: number; head: number; guide: number; hair: number; line: number; cut: number; dot: number; dash: number; dashGap: number; wide: number; cap: number; radius: number; radiusXs: number; + /** An activation bar's width and a cardinality mark's room (DECISIONS 306, 1.0). */ + activation: number; foot: number; } export function readTokens(el: Element): Tokens { @@ -1180,6 +1308,7 @@ export function readTokens(el: Element): Tokens { head: px("size-diagram-head", 8), guide: px("size-diagram-guide-dash", 4), hair: px("size-hairline", 1), line: px("size-chart-line", 2), cut: px("size-cut", 2), dot: px("size-dot", 6), dash: px("size-chart-dash", 6), dashGap: px("size-chart-dash-gap", 4), wide: px("size-breakpoint-container-lg", 640), cap: px("size-breakpoint-container", 480), radius: px("radius-md", 8), radiusXs: px("radius-xs", 4), + activation: px("size-diagram-activation", 8), foot: px("size-diagram-foot", 14), }; } @@ -1842,6 +1971,29 @@ function sequenceGeometry(input: DrawnInput, geo: Geo, sn: ReturnType { const r = heads.get(id); return r ? sn.x((r.l + r.r) / 2, tk.hair) : 0; }; for (const n of m.nodes) { const r = heads.get(n.id); if (r) geo.lifelines.push({ x: xOf(n.id), y1: r.b, y2: bottom }); } const spanOf = (n: MNode) => { const r = heads.get(n.id)!; return r; }; + // Each message's line height, by its number, for the bars. + const rowY = new Map(); + drawing.querySelectorAll(`.${P}-msg`).forEach((li) => { + const r = rectOf(li, origin); + rowY.set(Number(li.querySelector(`.${P}-num`)?.textContent ?? 0), (r.t + r.b) / 2); + }); + // Activation bars (1.2): size-diagram-activation wide, centred on the lifeline, from the opening message's line to the closing one's; a nested bar + // space-1 toward the end side (the start side on the last participant). A one-row bar (a self-call that opens and closes it) spans its loop. + const W = tk.activation, half = W / 2; + const barRect = (bar: MBar) => { + const who = m.byId.get(bar.who); + if (!who) return null; + const lx = xOf(bar.who); + const dir = who.i === m.nodes.length - 1 && m.nodes.length > 1 ? -1 : 1; + const off = (bar.depth - 1) * s("1") * dir; + const y1 = rowY.get(bar.from) ?? 0, y2 = rowY.get(bar.to) ?? y1; + const one = bar.from === bar.to; + return { l: sn.x(lx - half + off, tk.hair), r: sn.x(lx + half + off, tk.hair), t: sn.y(one ? y1 - s("2") - s("1") : y1, tk.hair), b: sn.y(one ? y1 + s("2") + s("1") : y2, tk.hair) }; + }; + const placedBars = m.bars.map((bar) => ({ bar, rect: barRect(bar) })).filter((x) => x.rect) as Array<{ bar: MBar; rect: Rect }>; + geo.bars = placedBars.map((x) => x.rect); + /** The deepest bar a participant has at a message (the one a line ends on), and whether one it opens counts. */ + const barAt = (who: string, n: number, opening: boolean) => placedBars.filter(({ bar }) => bar.who === who && bar.to >= n && (opening ? bar.from <= n : bar.from < n || (bar.from === n && bar.to === n))).sort((x, y) => y.bar.depth - x.bar.depth)[0]?.rect; drawing.querySelectorAll(`.${P}-msg`).forEach((li) => { const from = li.dataset.from!, to = li.dataset.to!; const kind = (li.dataset.kind ?? "plain") as DiagramLineKind; @@ -1849,13 +2001,23 @@ function sequenceGeometry(input: DrawnInput, geo: Geo, sn: ReturnType 0 ? bar.r : bar.l) : x1; const yt = sn.y(y - s("2"), w), yb = sn.y(y + s("2"), w); - pts = [{ x: x1, y: yt }, { x: sn.x(x1 + out, w), y: yt }, { x: sn.x(x1 + out, w), y: yb }, { x: x1, y: yb }]; - } else pts = [{ x: x1, y }, { x: x2, y }]; + pts = [{ x: edge, y: yt }, { x: sn.x(x1 + out, w), y: yt }, { x: sn.x(x1 + out, w), y: yb }, { x: edge, y: yb }]; + } else { + // A line ends on a bar's edge, as a line ends on the shape drawn (1.2): the receiver's bar (one this message opens included), the sender's. + const toward = x2 > x1 ? 1 : -1; + const sb = barAt(from, num, false), rb = barAt(to, num, true); + if (sb) x1 = toward > 0 ? sb.r : sb.l; + if (rb) x2 = toward > 0 ? rb.l : rb.r; + pts = [{ x: x1, y }, { x: x2, y }]; + } geo.lines.push({ i: num, from, to, kind, pts, tip: pts[pts.length - 1]!, dir: finish(pts), width: w }); // Every label and note fits between the lifelines it spans, space-2 clear each side (1.11, rule 3). const said = li.querySelector(`.${P}-said`), note = li.querySelector(`.${P}-note`); @@ -1868,6 +2030,13 @@ function sequenceGeometry(input: DrawnInput, geo: Geo, sn: ReturnType room + 0.5) geo.unseated.push(num); void spanOf; }); + // A frame's header (its tab, then its label) must fit inside its frame (1.2): a header that does not stacks the figure. + drawing.querySelectorAll(`.${P}-fhead`).forEach((head) => { + const box = head.parentElement?.querySelector(`:scope > .${P}-fbox`); + if (!box) return; + const need = [...head.children].reduce((sum, c) => sum + c.getBoundingClientRect().width, 0) + s("3"); + if (need > box.getBoundingClientRect().width + 0.5) (geo.misfit ??= []).push(`the frame "${head.querySelector(`.${P}-flabel`)?.textContent ?? ""}" is wider than its participants`); + }); return geo; } @@ -2062,7 +2231,8 @@ function masksMarkup(P: string, geo: Geo, tk: Tokens, base: string): { defs: str /** The drawing's ink: the SVG (lines, heads, dots, lifelines, cuts) and the labels, as one string. */ export function inkHtml(P: string, geo: Geo, tk: Tokens, base: string): string { const { defs, ids } = masksMarkup(P, geo, tk, base); - const lifelines = geo.lifelines.map((l) => ``).join(""); + const lifelines = geo.lifelines.map((l) => ``).join("") + + (geo.bars ?? []).map((b) => ``).join(""); const lines = geo.lines.map((l, k) => lineMarkup(P, l, tk, ids.get(k) ?? null, l.from === l.to ? tk.radiusXs : tk.radius)).join(""); const svg = `${defs ? `${defs}` : ""}${lifelines}${lines}`; const labels = geo.labels.map((l) => ` 1 ? ' data-lines="2"' : ""} style="left:${Math.round(l.box.l * 100) / 100}px;top:${Math.round(l.box.t * 100) / 100}px;width:${Math.round((l.box.r - l.box.l) * 100) / 100}px">${l.text.split("\n").map(escapeHtml).join("
")}
`).join(""); @@ -2155,7 +2325,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin let { dd: d, g: geo } = drawnTry(false); // A label refused only because its seats leave the drawing (beside a line in a 40px first or last row) is given space-3 above and below. // A route the drawn layout refuses: through a node, off the drawing, or laid on another line. - const refused = (g: Geo) => g.through.length > 0 || g.outside.length > 0 || (g.overlaps?.length ?? 0) > 0 || tall; + const refused = (g: Geo) => g.through.length > 0 || g.outside.length > 0 || (g.overlaps?.length ?? 0) > 0 || (g.misfit?.length ?? 0) > 0 || tall; if (!refused(geo) && geo.unseated.length && geo.unseated.every((k) => geo.bounded?.includes(k))) { const padded = drawnTry(true); if (!refused(padded.g) && !padded.g.unseated.length) ({ dd: d, g: geo } = padded); @@ -2166,6 +2336,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin } // At a width the figure should fit by its tokens and words, a failure is the author's to fix. if (tall) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: a decision would be taller than it is wide`); + if (geo.misfit?.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${geo.misfit.join("; ")}`); if (geo.through.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.through)} would pass through a node`); if (geo.overlaps?.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.overlaps)} would lie on one another`); if (geo.outside.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.outside)} would leave the drawing`); diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index c7e18dd8..b8b1a28f 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4751,6 +4751,37 @@ .basalt-diagram-msg[data-self="end"] :is(.basalt-diagram-said, .basalt-diagram-note) { --_d-sj: var(--_drawn) start; justify-self: var(--_d-sj, stretch); --_d-sm: var(--_drawn) calc(50% + var(--basalt-space-6) + var(--basalt-space-1)); margin-inline-start: var(--_d-sm, 0); } .basalt-diagram-msg[data-self="start"] :is(.basalt-diagram-said, .basalt-diagram-note) { --_d-sj: var(--_drawn) end; justify-self: var(--_d-sj, stretch); --_d-sm: var(--_drawn) calc(50% + var(--basalt-space-6) + var(--basalt-space-1)); margin-inline-end: var(--_d-sm, 0); } .basalt-diagram-arrow { flex: none; overflow: visible; } + /* An activation bar (DECISIONS 306, 1.2): size-diagram-activation wide, the head's fill inside a 1px structure edge, radius-2xs. Structure: whole from + an entrance's first frame, unchanged by a trace. */ + .basalt-diagram-bar { fill: var(--_surface, var(--basalt-surface-1)); stroke: var(--basalt-diagram-structure); stroke-width: var(--basalt-size-hairline); rx: var(--basalt-radius-2xs); } + /* A frame (1.2): a step that holds steps, structure and never a panel: no fill, no rim, no level; 1px solid structure, radius 12 (a frame inside a + frame radius 4, space-2 inside it on every side they share). Drawn, it spans its participants' columns, from the first's start edge to the last's + end edge; stacked, it is the same box round its rows. Its header is a 36px row: the tab (the operator) in the top start corner, then the label; + an alt's later branch starts under a dashed rule (4 on 4, exact) in a 28px row. Every word of a frame sits on a ground plate. */ + .basalt-diagram-frame { + --_d-fpi: var(--_drawn) 0; + --_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1)); + --_d-fl: var(--_drawn) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2)); + --_d-fw: var(--_drawn) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2)); + --_fl: var(--_d-fl, 0%); + --_fw: var(--_d-fw, 100%); + position: relative; + padding-block: var(--basalt-size-control-lg) var(--basalt-space-2); + padding-inline: var(--_d-fpi, var(--basalt-space-4)); + } + .basalt-diagram-frame + .basalt-diagram-frame { margin-block-start: var(--basalt-space-2); } + .basalt-diagram-frame[data-depth="2"] { --_d-fl: var(--_drawn) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2)); } + .basalt-diagram-fbox { position: absolute; inset-block: 0; inset-inline-start: var(--_fl); z-index: 1; box-sizing: border-box; width: var(--_fw); border: var(--basalt-size-hairline) solid var(--basalt-diagram-structure); border-radius: var(--basalt-radius-lg); pointer-events: none; } + .basalt-diagram-frame[data-depth="2"] > .basalt-diagram-fbox { border-radius: var(--basalt-radius-xs); } + .basalt-diagram-fhead { position: absolute; top: var(--basalt-size-hairline); inset-inline-start: calc(var(--_fl) + var(--basalt-size-hairline)); display: flex; align-items: flex-start; gap: var(--basalt-space-3); margin: 0; white-space: nowrap; } + .basalt-diagram-ftab { padding: var(--basalt-space-1) var(--basalt-space-3); border-inline-end: var(--basalt-size-hairline) solid var(--basalt-diagram-structure); border-block-end: var(--basalt-size-hairline) solid var(--basalt-diagram-structure); border-end-end-radius: var(--basalt-radius-xs); background: var(--_ground); color: var(--basalt-text-primary); font: var(--basalt-font-weight-semibold) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); } + .basalt-diagram-flabel { margin-block-start: var(--basalt-space-1); margin-inline-start: calc(-1 * var(--basalt-space-1-5)); padding-inline: var(--basalt-space-1-5); background: var(--_ground); color: var(--basalt-text-secondary); font: var(--basalt-font-weight-medium) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); } + .basalt-diagram-felse { position: relative; display: flex; align-items: center; gap: var(--basalt-space-1-5); height: var(--basalt-size-control-sm); margin: 0; padding-inline-start: calc(var(--_fl) + var(--basalt-space-3)); white-space: nowrap; } + .basalt-diagram-felse::before { content: ""; position: absolute; top: 0; inset-inline-start: var(--_fl); width: var(--_fw); height: var(--basalt-size-hairline); background: var(--basalt-diagram-structure); mask: linear-gradient(to right, currentColor 50%, transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x; } + .basalt-diagram-felse .basalt-diagram-flabel { margin-block-start: 0; margin-inline-start: 0; } + .basalt-diagram-fword { margin-inline-start: calc(-1 * var(--basalt-space-1-5)); padding-inline: var(--basalt-space-1-5); background: var(--_ground); color: var(--basalt-text-tertiary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); } + .basalt-diagram-fword + .basalt-diagram-flabel { margin-inline-start: calc(-1 * var(--basalt-space-1-5)); } + .basalt-diagram-key-letters[data-op] { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-semibold); } /* A band names a phase: drawn, a 36px row with a full-width divider rule and its words on a plate; stacked, a line of words. */ .basalt-diagram-band { --_d-bh: var(--_drawn) var(--basalt-size-control-lg); @@ -4919,6 +4950,12 @@ .basalt-diagram .basalt-diagram-node[data-focal] .basalt-diagram-th { border-bottom-color: Canvas; } .basalt-diagram .basalt-diagram-node[data-focal]:focus-visible { outline: var(--basalt-size-focus-width) solid Highlight; } .basalt-diagram .basalt-diagram-node[data-focal][data-shape="decision"] .basalt-diagram-diamond path { fill: CanvasText; stroke: CanvasText; } + /* An activation bar's edge carries "working" (CanvasText), its fill Canvas; a frame's edges and its else rule are GrayText, its words CanvasText + on Canvas plates (DECISIONS 306, 1.10). */ + .basalt-diagram .basalt-diagram-bar { fill: Canvas; stroke: CanvasText; } + .basalt-diagram .basalt-diagram-fbox, .basalt-diagram .basalt-diagram-ftab { border-color: GrayText; } + .basalt-diagram .basalt-diagram-felse::before { background: GrayText; } + .basalt-diagram :is(.basalt-diagram-ftab, .basalt-diagram-flabel, .basalt-diagram-fword) { color: CanvasText; background: Canvas; } /* No mark is drawn, and the first line keeps no padding for one (DECISIONS 292, 2.7): the card's words name the service. */ .basalt-diagram .basalt-diagram-mark { display: none; } .basalt-diagram .basalt-diagram-node[data-mark] > .basalt-diagram-mark + :is(.basalt-diagram-kind, .basalt-diagram-name) { padding-inline-end: 0; } diff --git a/packages/react/test/fixtures/cimip-diagrams-b.json b/packages/react/test/fixtures/cimip-diagrams-b.json index 0b021bb9..1c2ea07a 100644 --- a/packages/react/test/fixtures/cimip-diagrams-b.json +++ b/packages/react/test/fixtures/cimip-diagrams-b.json @@ -481,7 +481,8 @@ "main": "Request", "plain": "Setup", "dashed": "Stream or reply", - "focal": "The service" + "focal": "The service", + "activation": "Working" }, "participants": [ { @@ -513,7 +514,8 @@ "to": "svc", "kind": "main", "label": "@agent check the proxy", - "note": "a message in the room" + "note": "a message in the room", + "activate": true }, { "from": "svc", @@ -522,25 +524,34 @@ "note": "run.started, one transaction" }, { - "band": "First run on an incident only" - }, - { - "from": "svc", - "to": "ecs", - "label": "RunTask", - "note": "idempotency token = sandbox id" - }, - { - "from": "svc", - "to": "ecs", - "label": "DescribeTasks", - "note": "until it has a private IP" - }, - { - "from": "svc", - "to": "agent", - "label": "GET /healthz", - "note": "up to a minute" + "frame": "opt", + "label": "First run on an incident only", + "steps": [ + { + "from": "svc", + "to": "ecs", + "label": "RunTask", + "note": "idempotency token = sandbox id" + }, + { + "frame": "loop", + "label": "Until private IP", + "steps": [ + { + "from": "svc", + "to": "ecs", + "label": "DescribeTasks", + "note": "until it has a private IP" + } + ] + }, + { + "from": "svc", + "to": "agent", + "label": "GET /healthz", + "note": "up to a minute" + } + ] }, { "band": "Every run" @@ -550,7 +561,8 @@ "to": "agent", "kind": "main", "label": "POST /v1/runs", - "note": "facts, recent transcript, prompt" + "note": "facts, recent transcript, prompt", + "activate": true }, { "from": "agent", @@ -577,25 +589,48 @@ "band": "The agent waits for a person" }, { - "from": "marcus", - "to": "svc", - "kind": "main", - "label": "Approve", - "note": "first decision stands" - }, - { - "from": "svc", - "to": "agent", - "kind": "main", - "label": "POST /v1/runs/{id}/input", - "note": "sent until acknowledged" + "frame": "alt", + "branches": [ + { + "label": "Approved", + "steps": [ + { + "from": "marcus", + "to": "svc", + "kind": "main", + "label": "Approve", + "note": "first decision stands" + }, + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "POST /v1/runs/{id}/input", + "note": "sent until acknowledged" + } + ] + }, + { + "label": "Rejected or timed out", + "steps": [ + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "POST /v1/runs/{id}/input", + "note": "the run stops" + } + ] + } + ] }, { "from": "agent", "to": "svc", "kind": "dashed", "label": "done", - "note": "outcome: completed" + "note": "outcome: completed", + "deactivate": true } ] }, From b913ddaa35c69591822495e1453ee286e293394f Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:46:47 -0600 Subject: [PATCH 13/62] Tests for batch B's built parts, and review round 66 diagram-sequence.test.mjs (bars, frames, the stack, a header too wide), diagram-parts.test.mjs (nested groups, link cards, two-line labels). diagrams.test.mjs follows the spatial keys (the decision's table), and diagram-motion.test.mjs counts the foot without Expand, which every figure now has. Round 66 shows the viewer, the extended architecture, sequence and schema, and print. Co-Authored-By: Claude Opus 5.5 --- packages/react/test/diagram-motion.test.mjs | 6 +- packages/react/test/diagram-parts.test.mjs | 106 ++++++++++++++ packages/react/test/diagram-sequence.test.mjs | 110 +++++++++++++++ packages/react/test/diagrams.test.mjs | 4 +- tools/review/round66.tsx | 131 ++++++++++++++++++ tools/review/rounds.tsx | 2 + 6 files changed, 356 insertions(+), 3 deletions(-) create mode 100644 packages/react/test/diagram-parts.test.mjs create mode 100644 packages/react/test/diagram-sequence.test.mjs create mode 100644 tools/review/round66.tsx diff --git a/packages/react/test/diagram-motion.test.mjs b/packages/react/test/diagram-motion.test.mjs index 7f842e62..a298da3e 100644 --- a/packages/react/test/diagram-motion.test.mjs +++ b/packages/react/test/diagram-motion.test.mjs @@ -103,7 +103,8 @@ describe("still is untouched (first)", () => { const seen = await page.evaluate(() => [...document.querySelectorAll("figure")].map((f) => ({ entrance: f.getAttribute("data-entrance"), motion: f.getAttribute("data-motion"), parts: f.querySelectorAll(".basalt-diagram-flow, .basalt-diagram-bead, .basalt-diagram-packet, .basalt-diagram-motion-defs, .basalt-diagram-play, .basalt-diagram-pause, [mask^='url(#dg']").length, - foot: f.querySelector(".basalt-diagram-foot").children.length, + // "View as list" alone of the motion's concern: "Expand" (DECISIONS 310, 9.1) is every figure's and is not counted. + foot: f.querySelectorAll(".basalt-diagram-foot > :not(.basalt-diagram-expand)").length, }))); for (const s of seen) assert.deepEqual(s, { entrance: null, motion: null, parts: 0, foot: 1 }); assert.deepEqual(errors, []); @@ -1129,7 +1130,8 @@ describe("section 7's checks, batch A", () => { edges: getComputedStyle(f.querySelector(".basalt-diagram-edges")).visibility, masked: f.querySelectorAll(".basalt-diagram-edge[mask], .basalt-diagram-motion-defs").length, parts: f.querySelectorAll(".basalt-diagram-flow, .basalt-diagram-bead, .basalt-diagram-packet, .basalt-diagram-play, .basalt-diagram-pause").length, - foot: f.querySelector(".basalt-diagram-foot").children.length, + // "View as list" alone of the motion's concern: "Expand" (DECISIONS 310, 9.1) is every figure's and is not counted. + foot: f.querySelectorAll(".basalt-diagram-foot > :not(.basalt-diagram-expand)").length, lines: f.querySelectorAll(".basalt-diagram-svg .basalt-diagram-line").length, animations: f.getAnimations({ subtree: true }).length, }))); diff --git a/packages/react/test/diagram-parts.test.mjs b/packages/react/test/diagram-parts.test.mjs new file mode 100644 index 00000000..101b45af --- /dev/null +++ b/packages/react/test/diagram-parts.test.mjs @@ -0,0 +1,106 @@ +// Nested groups, link cards and two-line labels (DECISIONS 306, 1.3 and 1.4; part of section 8's list for diagram-parts.test.mjs), on the extended CIMIP +// architecture (test/fixtures/cimip-diagrams-b.json). In Chromium against the built package, both themes. End lanes and marks on steps are not built yet. +// The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import { after, before, describe, test } from "node:test"; + +import { fixturePage, launch } from "./support.mjs"; + +const P = "basalt-diagram"; +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +const HOST = ` +import data from "./test/fixtures/cimip-diagrams-b.json"; +const C = { architecture: B.ArchitectureDiagram, schema: B.SchemaDiagram }; +createRoot(document.getElementById("root")).render(
{["architecture", "schema"].map((key) => { const { type, ...props } = data[key]; const X = C[type]; return ; })}
);`; +const frames = (page, n = 3) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); +async function partsPage({ theme = "dark", width = 1440, touch = false } = {}) { + const { page, errors } = await fixturePage(browser, HOST, { theme, standards: true, viewport: { width, height: 1200 }, hasTouch: touch, isMobile: touch }); + if (touch) await page.evaluate(() => { const meta = document.createElement("meta"); meta.name = "viewport"; meta.content = "width=device-width, initial-scale=1"; document.head.append(meta); }); + await page.addStyleTag({ content: "body{margin:0;padding:16px} #root{max-width:1104px;margin:0 auto}" }); + await page.evaluate(() => document.fonts.ready); + await frames(page, 4); + return { page, errors }; +} + +describe("nested groups", () => { + for (const theme of ["dark", "light"]) test(`${theme}: the inner boundary is 16 inside the outer at the end side and 32 below its top; radius 8 against 12; the sentence names the chain`, async () => { + const { page, errors } = await partsPage({ theme }); + const g = await page.evaluate((P) => { + const box = (id) => { const el = document.querySelector(`#fig-architecture .${P}-gbox[data-group="${id}"]`); const r = el.getBoundingClientRect(); return { l: r.left, r: r.right, t: r.top, b: r.bottom, radius: getComputedStyle(el).borderTopLeftRadius }; }; + const cell = (id) => document.querySelector(`#fig-architecture .${P}-node[data-node="${id}"]`).getBoundingClientRect(); + return { aws: box("aws"), data: box("data"), aurora: cell("aurora"), sentence: document.querySelector(`#fig-architecture .${P}-node[data-node="aurora"]`).getAttribute("aria-label") }; + }, P); + assert.equal(Math.round(g.aws.r - g.data.r), 16, "16 inside at the end side"); + assert.equal(Math.round(g.data.t - g.aws.t), 32, "32 below the outer's top"); + assert.equal(Math.round(g.aurora.top - g.data.t), 32, "the inner box is space-8 above its first card"); + assert.equal(g.aws.radius, "12px"); + assert.equal(g.data.radius, "8px"); + assert.match(g.sentence, /In Data & logs, in AWS · your account\./); + assert.deepEqual(errors, []); + await page.close(); + }); + test("stacked, a nested group is a wrapper inside its parent's, and the list nests", async () => { + const { page } = await partsPage({ width: 390 }); + assert.equal(await page.locator(`#fig-architecture .${P}-group[data-group="aws"] .${P}-group[data-group="data"]`).count(), 1); + const list = await page.locator(`#fig-architecture .${P}-list .${P}-list-group`).allTextContents(); + assert.deepEqual(list.filter((t) => /AWS|Data/.test(t)), ["AWS · your account", "Data & logs"]); + await page.close(); + }); +}); + +describe("link cards", () => { + test("a link card is an
, the figure is one tab stop, the arrows reach the link and Enter follows it; its name begins with the visible name", async () => { + const { page } = await partsPage(); + const svc = page.locator(`#fig-architecture .${P}-node[data-node="svc"]`); + assert.equal(await svc.evaluate((e) => e.tagName), "A"); + assert.equal(await svc.getAttribute("href"), "#fig-sequence"); + assert.match(await svc.getAttribute("aria-label"), /^cimip service/); + // One tab stop: the figure's roving stop is the first card; the arrows reach the link. + const stops = await page.locator(`#fig-architecture .${P}-node[tabindex="0"]`).count(); + assert.equal(stops, 1); + await page.locator(`#fig-architecture .${P}-node[data-node="alb"]`).focus(); + await page.keyboard.press("ArrowRight"); + assert.equal(await page.evaluate(() => document.activeElement?.getAttribute("data-node")), "svc"); + await page.keyboard.press("Enter"); + await frames(page); + assert.equal(await page.evaluate(() => location.hash), "#fig-sequence"); + await page.close(); + }); + test("the cue: secondary at rest, primary and travelling on hover, never alone on a line; no scale on press; 44px on touch", async () => { + const { page } = await partsPage(); + const cue = (sel) => page.locator(sel).evaluate((e) => { const s = getComputedStyle(e, "::after"); return { bg: `${s.backgroundColor} ${s.opacity}`, transform: s.transform, w: s.width }; }); + const end = `#fig-architecture .${P}-node[data-node="svc"] .${P}-name-end`; + const rest = await cue(end); + assert.equal(rest.w, "16px"); + await page.locator(`#fig-architecture .${P}-node[data-node="svc"]`).hover(); + await page.waitForTimeout(250); + const hover = await cue(end); + assert.notEqual(hover.bg, rest.bg, "the focal card's cue lifts from its quiet ink"); + assert.notEqual(hover.transform, "none"); + assert.match(await page.locator(`#fig-architecture .${P}-node[data-node="svc"] .${P}-name`).evaluate((e) => getComputedStyle(e).textDecorationLine), /underline/); + assert.equal(await page.locator(end).evaluate((e) => getComputedStyle(e).whiteSpace), "nowrap", "the arrow holds the last word"); + await page.mouse.down(); + assert.equal(await page.locator(`#fig-architecture .${P}-node[data-node="svc"]`).evaluate((e) => getComputedStyle(e).transform), "none"); + await page.mouse.up(); + await page.close(); + const phone = await partsPage({ width: 390, touch: true }); + const h = await phone.page.locator(`#fig-architecture .${P}-node[data-node="svc"]`).evaluate((e) => e.getBoundingClientRect().height); + assert.ok(h >= 44); + await phone.page.close(); + }); +}); + +describe("two-line labels", () => { + for (const theme of ["dark", "light"]) test(`${theme}: both lines in one ink on one plate, 32 tall; the list joins them with a space`, async () => { + const { page } = await partsPage({ theme }); + const two = await page.locator(`#fig-architecture .${P}-label[data-lines="2"]`).evaluateAll((els) => els.map((e) => ({ h: e.getBoundingClientRect().height, text: e.innerText, colors: [...new Set([getComputedStyle(e).color])] }))); + assert.equal(two.length, 2); + for (const l of two) { assert.equal(Math.round(l.h), 32); assert.equal(l.text.split("\n").length, 2); assert.equal(l.colors.length, 1); } + const list = await page.locator(`#fig-architecture .${P}-list`).evaluate((e) => e.textContent); + assert.match(list, /SQL · NOTIFY one transaction/); + await page.close(); + }); +}); diff --git a/packages/react/test/diagram-sequence.test.mjs b/packages/react/test/diagram-sequence.test.mjs new file mode 100644 index 00000000..2a12729f --- /dev/null +++ b/packages/react/test/diagram-sequence.test.mjs @@ -0,0 +1,110 @@ +// A sequence's activations and frames (DECISIONS 306, 1.2; section 8's list for diagram-sequence.test.mjs), on the extended CIMIP sequence +// (test/fixtures/cimip-diagrams-b.json). In Chromium against the built package, both themes. The text variant is not built yet, so its tests are not here. +// The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { after, before, describe, test } from "node:test"; + +import { fixturePage, launch, pkg } from "./support.mjs"; + +const B = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams-b.json"), "utf8")); +const P = "basalt-diagram"; +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +const HOST = ` +import data from "./test/fixtures/cimip-diagrams-b.json"; +function Host() { + const [spec, setSpec] = React.useState(() => { const { type, ...props } = data.sequence; return props; }); + window.__set = (next) => flushSync(() => setSpec(next)); + return ; +} +createRoot(document.getElementById("root")).render();`; +const frames = (page, n = 3) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); +async function seqPage({ theme = "dark", width = 1440 } = {}) { + const { page, errors } = await fixturePage(browser, HOST, { theme, standards: true, viewport: { width, height: 1200 } }); + await page.addStyleTag({ content: "body{margin:0;padding:16px} #root{max-width:1104px;margin:0 auto}" }); + await page.evaluate(() => document.fonts.ready); + await frames(page, 4); + return { page, errors }; +} +const read = (page) => page.evaluate((P) => { + const fig = document.querySelector("#seq"); + const d = fig.querySelector(`.${P}-drawing`).getBoundingClientRect(); + const rel = (r) => ({ l: r.left - d.left, r: r.right - d.left, t: r.top - d.top, b: r.bottom - d.top }); + return { + layout: fig.getAttribute("data-layout"), w: d.width, h: d.height, + bars: [...fig.querySelectorAll(`.${P}-svg .${P}-bar`)].map((b) => ({ ...rel(b.getBoundingClientRect()), fill: getComputedStyle(b).fill, stroke: getComputedStyle(b).stroke })), + lives: [...fig.querySelectorAll(`.${P}-life`)].filter((l) => !l.closest(`.${P}-swatch`)).map((l) => rel(l.getBoundingClientRect()).l), + lines: [...fig.querySelectorAll(`.${P}-edge`)].map((g) => ({ i: g.dataset.edge, d: g.querySelector(`.${P}-line`).getAttribute("d"), tip: g.querySelector(`.${P}-tip`)?.getAttribute("d") })), + boxes: [...fig.querySelectorAll(`.${P}-fbox`)].map((b) => ({ ...rel(b.getBoundingClientRect()), depth: b.parentElement.dataset.depth, op: b.parentElement.dataset.op, border: getComputedStyle(b).borderTopWidth, style: getComputedStyle(b).borderTopStyle })), + heads: [...fig.querySelectorAll(`.${P}-node`)].map((n) => rel(n.getBoundingClientRect())), + nums: [...fig.querySelectorAll(`.${P}-drawing .${P}-num`)].map((n) => n.textContent), + key: [...fig.querySelectorAll(`.${P}-entry`)].filter((e) => getComputedStyle(e).display !== "none").map((e) => e.textContent), + list: [...fig.querySelectorAll(`.${P}-list .${P}-list-group`)].map((e) => e.textContent), + }; +}, P); + +describe("activations", () => { + for (const theme of ["dark", "light"]) test(`${theme}: bars are 8 wide on their lifelines, in the head's fill and a structure edge; lines end on a bar's edge`, async () => { + const { page, errors } = await seqPage({ theme }); + const g = await read(page); + assert.equal(g.layout, "drawn"); + assert.equal(g.bars.length, 2, "the service's bar and the sandbox's"); + for (const bar of g.bars) { + assert.ok(Math.abs(bar.r - bar.l - 8) <= 1, `width ${bar.r - bar.l}`); + assert.ok(g.lives.some((x) => Math.abs((bar.l + bar.r) / 2 - x) <= 1), "centred on a lifeline"); + assert.notEqual(bar.fill, "none"); + } + // Message 6 (POST /v1/runs) opens the sandbox's bar: its head's point is on the bar's start edge. + const six = g.lines.find((l) => l.i === "6"); + const endX = Number(/^M([\d.]+) /.exec(six.tip)[1]); + const agentBar = g.bars.sort((a, b) => b.l - a.l)[0]; + assert.ok(Math.abs(endX - agentBar.l) <= 1, `${endX} against ${agentBar.l}`); + assert.deepEqual(errors, []); + await page.close(); + }); +}); + +describe("frames", () => { + for (const theme of ["dark", "light"]) test(`${theme}: every frame has four solid sides inside the drawing and spans its participants; a nested frame is 8px inside where they share a side; the key and the list say the operators`, async () => { + const { page } = await seqPage({ theme }); + const g = await read(page); + assert.equal(g.boxes.length, 3); + for (const b of g.boxes) { + assert.equal(b.border, "1px"); + assert.equal(b.style, "solid"); + assert.ok(b.l >= -0.01 && b.r <= g.w + 0.01 && b.t >= -0.01 && b.b <= g.h + 0.01, `${b.op} inside the drawing`); + } + const opt = g.boxes.find((b) => b.op === "opt"), loop = g.boxes.find((b) => b.op === "loop"), alt = g.boxes.find((b) => b.op === "alt"); + // opt spans the service to the sandbox: from the service head's start edge to the sandbox head's end edge. + assert.ok(Math.abs(opt.l - g.heads[1].l) <= 1 && Math.abs(opt.r - g.heads[3].r) <= 1, "opt spans its participants"); + assert.ok(Math.abs(loop.l - opt.l - 8) <= 1, "the loop is 8 inside the opt at their shared start side"); + assert.ok(Math.abs(alt.l) <= 1 && Math.abs(alt.r - g.w) <= 1, "alt spans every participant"); + assert.deepEqual(g.nums, Array.from({ length: 13 }, (_, k) => String(k + 1)), "messages number straight through"); + for (const words of ["optOnly if", "loopRepeats", "altOne of these", "Working"]) assert.ok(g.key.some((k) => k.replace(/\s+/g, "") === words.replace(/\s+/g, "")), `the key says ${words}`); + assert.deepEqual(g.list.filter((t) => /^(Only if|Repeats|One of these|Otherwise):/.test(t)), ["Only if: First run on an incident only", "Repeats: Until private IP", "One of these: Approved", "Otherwise: Rejected or timed out"]); + await page.close(); + }); + test("stacked, the frames box their rows and messages keep their numbers", async () => { + const { page } = await seqPage({ width: 390 }); + const g = await read(page); + assert.equal(g.layout, "stacked"); + assert.equal(g.boxes.length, 3); + assert.deepEqual(g.nums, Array.from({ length: 13 }, (_, k) => String(k + 1))); + await page.close(); + }); + test("a header too long for its frame stacks the figure", async () => { + const { page } = await seqPage(); + await page.evaluate((spec) => { + const { type, ...props } = spec; + props.steps = [{ frame: "opt", label: "A condition far longer than the two columns of one self-call can ever hold on its own line", steps: [{ from: "svc", to: "svc", label: "x" }] }]; + window.__set(props); + }, B.sequence); + await frames(page, 4); + assert.equal((await read(page)).layout, "stacked"); + await page.close(); + }); +}); diff --git a/packages/react/test/diagrams.test.mjs b/packages/react/test/diagrams.test.mjs index debc0320..15c0e565 100644 --- a/packages/react/test/diagrams.test.mjs +++ b/packages/react/test/diagrams.test.mjs @@ -466,7 +466,9 @@ describe("accessibility (1.14)", () => { assert.equal(await page.locator(`#fig-architecture .${P}-svg`).evaluate((svg) => svg.closest("[aria-hidden='true']") !== null), true, "the SVG is hidden"); await page.focus(`#fig-architecture .${P}-node[data-node="browser"]`); const at = () => page.evaluate(() => document.activeElement?.dataset.node); - for (const [key, to] of [["ArrowRight", "alb"], ["ArrowDown", "svc"], ["ArrowLeft", "alb"], ["ArrowUp", "browser"], ["ArrowUp", "browser"], ["End", "sys"], ["ArrowRight", "sys"], ["Home", "browser"]]) { + // Drawn, the arrows are spatial (DECISIONS 306, 1.5; the decision's table in test/fixtures/diagram-spatial-cells.json): down from the ALB is ECS, up + // from Aurora goes nowhere. Home and End are the ends, as before. + for (const [key, to] of [["ArrowRight", "alb"], ["ArrowDown", "ecs"], ["ArrowLeft", "browser"], ["ArrowUp", "aurora"], ["ArrowUp", "aurora"], ["End", "sys"], ["ArrowRight", "cw"], ["Home", "browser"]]) { await page.keyboard.press(key); assert.equal(await at(), to, `${key}`); } diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx new file mode 100644 index 00000000..ecd498a4 --- /dev/null +++ b/tools/review/round66.tsx @@ -0,0 +1,131 @@ +// Round 66: Basalt's diagrams, batch B (DECISIONS 301; the decision is 306, revised by 313, with part 9, the viewer, as 310). A heavy council round: two +// drafts and one check, decided by Fable, revised after the final positions. Part 9 (the viewer) is the owner's own addition and skipped three steps: no +// draft, no check and no seat's position; every value in it is the decider's alone. Built by Opus from the decision; the implementation has not been +// reviewed. The content is CIMIP's figures extended as each part needs (test/fixtures/cimip-diagrams-b.json). Only the parts built so far are shown: +// cardinality and far keys, the text art, the touch trace, the first visit, dashed flow, marks on steps and participants, right to left, export and +// automatic layout are not built yet, so this round has no automatically placed figure. + +import * as React from "react"; + +import { ArchitectureDiagram, DataFlowDiagram, FlowchartDiagram, SchemaDiagram, SequenceDiagram } from "../../packages/react/src/index"; +import data from "../../packages/react/test/fixtures/cimip-diagrams-b.json"; +import type { Round } from "./rounds"; + +type Key = keyof typeof data; +const isShot = () => new URLSearchParams(window.location.search).get("shot") === "1"; +const frames = (n: number) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }); + +/** A figure from the extended fixture. A "viewer" state opens its viewer (and "viewer-200" zooms to 200%) once it is drawn, for the shot. */ +function Diagram({ k, state }: { k: Key; state: string }) { + const host = React.useRef(null); + React.useEffect(() => { + if (!isShot() || !state.startsWith("viewer")) return; + let ready: () => void = () => {}; + (window as unknown as { __BASALT_READY__?: Promise }).__BASALT_READY__ = new Promise((resolve) => { ready = resolve; }); + (async () => { + await frames(6); + host.current?.querySelector(".basalt-diagram-expand")?.click(); + for (let t = 0; t < 60 && !document.querySelector("dialog.basalt-diagram-viewer .basalt-diagram[data-layout]"); t++) await frames(2); + await new Promise((r) => setTimeout(r, 400)); + if (state === "viewer-200") { + const level = () => Number(document.querySelector(".basalt-diagram-level > span")?.textContent?.replace("%", "") ?? 0); + for (let i = 0; i < 12 && level() < 200; i++) document.querySelector('dialog.basalt-diagram-viewer button[aria-label="Zoom in"]')?.click(); + } + await frames(4); + ready(); + })(); + }, [state]); + const { type, ...props } = data[k] as unknown as { type: string } & Record; + const figure = (() => { + switch (type) { + case "architecture": return )} />; + case "flowchart": return )} />; + case "data-flow": return )} />; + case "sequence": return )} />; + default: return )} />; + } + })(); + return
{figure}
; +} + +const COMMON = [ + "Decided by the council (DECISIONS 306, revised by 313): the owner sees this PR before it merges. Built by Opus; the implementation has not been reviewed.", + "A figure that uses none of the new keys draws what it drew before, except the flowchart: a decision taller than wide is now a fit failure (section 4, call 1), so CIMIP's flowchart is stacked through 975 and drawn from 976.", +]; +const W = [1440, 390]; + +export const ROUND_66: Round = { + id: "66", + title: "Diagrams, batch B: the viewer, frames and activations, nested groups, link cards, two-line labels and spatial keys (DECISIONS 306 and 310)", + summary: "The first half of batch B. The viewer (part 9, the owner's addition) opens any figure's drawn layout in a dialog to zoom and pan; the sequence gains activation bars and opt, loop and alt frames; groups nest two deep; a card may be a link; an edge label may hold its author's break; the arrow keys move by the cards' columns and rows. Not built yet: cardinality and far keys, the text art, the touch trace, the first visit, dashed flow, marks on steps and participants, right to left, export and automatic layout (elkjs).", + reviewed: false, + steps: [ + { + id: "viewer", + name: "The viewer: Expand, Fit, zoom and pan", + intro: "\"Expand\" in every figure's foot opens the drawn layout in a dialog: the window less 16px from 720, the whole window under it. It opens at Fit; a phone gets the drawing its page cannot show.", + decisions: [ + "Part 9 skipped three steps: no draft, no check and no seat's position. Every value is the decider's alone (DECISIONS 310).", + "Laid out once at 100% in real CSS pixels and zoomed with one transform: never a viewBox, CSS zoom, a canvas or a picture. Fit is the whole drawing in the stage, 200% at most; the limits are Fit or 100% and 400%; steps 25 to 400 land at once.", + "Two deviations, for the owner: \"Expand\" is words only (Phosphor's ArrowsOutSimple cost every still figure 2.2 KB in six weights, and the core set draws no expand glyph), and the dialog is the form dialog's box on a native modal , as the HTML skill's is (Base UI's dialog in the viewer's chunk widened the Base UI chunk every component shares).", + "Under 100% the words are under 12px: an overview, with no size or contrast claim. Nothing moves in the viewer but a trace.", + ], + tryIt: ["Press Expand, then + and - (or Ctrl and the wheel, or pinch): the point under the pointer holds still. Drag to pan. 0 is Fit. Esc closes and focus returns to Expand.", "On a phone: two fingers zoom about their midpoint, one finger pans."], + states: ["viewer", "viewer-200"], + widths: W, + scales: [2], + height: 900, + touch: true, + demo: ({ state }) => , + }, + { + id: "architecture", + name: "Architecture: nested groups, a link card and two-line labels", + intro: "\"Data & logs\" sits inside AWS: 16px inside it at the sides and 32 below its top, radius 8. The cimip service card is a link, with the arrow after its name. Two labels carry their author's break.", + decisions: [...COMMON, "A stacked group's label sits on a ground plate over the lines (1.3). Where a turn into the inner group's first card runs at the label's height, the line runs behind the plate: a visual question for the owner."], + tryIt: ["Hover the cimip service card: its name underlines and the arrow lifts. Tab to the figure and press the arrows: they move by the cards' columns and rows. Enter on the service follows its link."], + states: ["viewer"], + widths: W, + scales: [2], + height: 1600, + touch: true, + demo: ({ state }) => , + }, + { + id: "sequence", + name: "Sequence: activations and frames", + intro: "The service works from the mention to the end, the sandbox from its run to \"done\". An opt holds a loop, and an alt has two branches.", + decisions: [...COMMON, "A frame is structure, never a panel: no fill, no rim, no level; every word of it sits on a ground plate, so a lifeline or a bar stops either side of it. An activation bar is the vertical bar nearest the one the owner ruled out (item 8 of the decision)."], + tryIt: ["Open View as list: the frames are sub-headings (\"Only if: ...\", \"Otherwise: ...\") and messages keep their numbers."], + widths: W, + scales: [2], + height: 1800, + touch: true, + demo: ({ state }) => , + }, + { + id: "schema", + name: "Schema: a link table", + intro: "The incidents table is a link. Cardinality and far keys are not built yet.", + decisions: [...COMMON], + tryIt: ["Tab to the schema: the link table is the figure's roving stop."], + widths: W, + scales: [2], + height: 1200, + touch: true, + demo: ({ state }) => , + }, + { + id: "print", + name: "Print: light and untraced", + intro: "The token CSS ends with a print block: any page printed from the dark theme prints in the light one, and a figure prints in its resting ink.", + decisions: ["The print theme is the whole package's, not the diagrams' alone (item 5 of the decision). An app that prints dark on purpose overrides it."], + tryIt: ["Print this page from the dark theme."], + states: ["print@1440"], + widths: [1440], + scales: [2], + height: 1200, + demo: ({ state }) => , + }, + ], +}; diff --git a/tools/review/rounds.tsx b/tools/review/rounds.tsx index 1585935c..9016081e 100644 --- a/tools/review/rounds.tsx +++ b/tools/review/rounds.tsx @@ -131,6 +131,7 @@ import { ROUND_62 } from "./round62"; import { ROUND_63 } from "./round63"; import { ROUND_64 } from "./round64"; import { ROUND_65 } from "./round65"; +import { ROUND_66 } from "./round66"; export interface Step { id: string; @@ -701,3 +702,4 @@ ROUNDS.push(ROUND_62); ROUNDS.push(ROUND_63); ROUNDS.push(ROUND_64); ROUNDS.push(ROUND_65); +ROUNDS.push(ROUND_66); From 3d757aa75a1afa5483918c9575b3eecbe1fa91d5 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:49:18 -0600 Subject: [PATCH 14/62] Core-glyph masks for the review page's source stylesheet, and round 66's 200% shot glyph-mask.mjs writes %glyph-mask:name% for the package's build and for the walkthrough, which reads the source stylesheet. Round 66's viewer demo waits a frame between steps. Co-Authored-By: Claude Opus 5.5 --- packages/react/build.mjs | 18 +++--------------- packages/react/glyph-mask.mjs | 19 +++++++++++++++++++ tools/review/build.mjs | 5 ++++- tools/review/round66.tsx | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 packages/react/glyph-mask.mjs diff --git a/packages/react/build.mjs b/packages/react/build.mjs index 6fee4adc..f91a3a72 100644 --- a/packages/react/build.mjs +++ b/packages/react/build.mjs @@ -234,21 +234,9 @@ fs.writeFileSync(path.join(dist, "head", "loops.js"), loopsBootstrap); // The accent classes are generated with the tokens and ship with the components, whose Badge is the one reader of them. const accents = fs.readFileSync(require.resolve("@srasyndicate/basalt-tokens/accents.css"), "utf8"); -// `%glyph-mask:name%` in the stylesheet is a data URI of that core glyph, drawn with the set's 2.25 round stroke on the 24 grid, for a CSS mask (a diagram's -// link cue, DECISIONS 306, 1.4): the same drawing as the HTML skill's (tools/html-skill/build.mjs), from the same source, never redrawn by hand. -const { GLYPHS: CORE_GLYPHS, slots: glyphSlots } = await import(pathToFileURL(path.join(here, "glyphs", "source.mjs")).href); -const glyphMaskUri = (name) => { - const glyph = CORE_GLYPHS[name]; - if (!glyph || !(glyph.s || glyph.of)) throw new Error(`build: "${name}" is not a core glyph with a drawing`); - const near = (a, b) => Math.abs(a - b) < 1e-6; - const d = (glyph.s ?? glyphSlots(name)).filter((slot) => slot[8]).map(([x0, y0, x1, y1, x2, y2, x3, y3]) => { - const straight = near(x1, x0 + (x3 - x0) / 3) && near(y1, y0 + (y3 - y0) / 3) && near(x2, x0 + (2 * (x3 - x0)) / 3) && near(y2, y0 + (2 * (y3 - y0)) / 3); - return straight ? `M${x0} ${y0}L${x3} ${y3}` : `M${x0} ${y0}C${x1} ${y1} ${x2} ${y2} ${x3} ${y3}`; - }).join(""); - const svg = ``; - return `data:image/svg+xml,${svg.replace(//g, "%3E")}`; -}; -const components = `${fs.readFileSync(path.join(here, "src/styles/components.css"), "utf8").replace(/%glyph-mask:([\w-]+)%/g, (_, name) => glyphMaskUri(name))}\n${accents}`; +// `%glyph-mask:name%` in the stylesheet is a core glyph's drawing as a mask (glyph-mask.mjs). +const { withGlyphMasks } = await import(pathToFileURL(path.join(here, "glyph-mask.mjs")).href); +const components = `${withGlyphMasks(fs.readFileSync(path.join(here, "src/styles/components.css"), "utf8"))}\n${accents}`; // Geist Sans and Mono, variable (SIL OFL 1.1, licence shipped beside the files). const geist = path.join(packageDir("geist"), "dist", "fonts"); diff --git a/packages/react/glyph-mask.mjs b/packages/react/glyph-mask.mjs new file mode 100644 index 00000000..a6129709 --- /dev/null +++ b/packages/react/glyph-mask.mjs @@ -0,0 +1,19 @@ +// `%glyph-mask:name%` in a stylesheet is a data URI of that core glyph, drawn with the set's 2.25 round stroke on the 24 grid, for a CSS mask (a diagram's +// link cue, DECISIONS 306, 1.4): the same drawing as the HTML skill's (tools/html-skill/build.mjs), from the same source, never redrawn by hand. The package's +// build and the review walkthrough (which reads the source stylesheet) both write it in. +import { GLYPHS, slots } from "./glyphs/source.mjs"; + +export function glyphMaskUri(name) { + const glyph = GLYPHS[name]; + if (!glyph || !(glyph.s || glyph.of)) throw new Error(`glyph-mask: "${name}" is not a core glyph with a drawing`); + const near = (a, b) => Math.abs(a - b) < 1e-6; + const d = (glyph.s ?? slots(name)).filter((slot) => slot[8]).map(([x0, y0, x1, y1, x2, y2, x3, y3]) => { + const straight = near(x1, x0 + (x3 - x0) / 3) && near(y1, y0 + (y3 - y0) / 3) && near(x2, x0 + (2 * (x3 - x0)) / 3) && near(y2, y0 + (2 * (y3 - y0)) / 3); + return straight ? `M${x0} ${y0}L${x3} ${y3}` : `M${x0} ${y0}C${x1} ${y1} ${x2} ${y2} ${x3} ${y3}`; + }).join(""); + const svg = ``; + return `data:image/svg+xml,${svg.replace(//g, "%3E")}`; +} + +/** The stylesheet with every `%glyph-mask:name%` written in. */ +export const withGlyphMasks = (css) => css.replace(/%glyph-mask:([\w-]+)%/g, (_, name) => glyphMaskUri(name)); diff --git a/tools/review/build.mjs b/tools/review/build.mjs index d228810e..805e9c74 100644 --- a/tools/review/build.mjs +++ b/tools/review/build.mjs @@ -12,6 +12,8 @@ import { execFileSync } from "node:child_process"; import fs from "node:fs"; + +import { withGlyphMasks } from "../../packages/react/glyph-mask.mjs"; import path from "node:path"; import { createRequire } from "node:module"; import { fileURLToPath } from "node:url"; @@ -134,7 +136,8 @@ const css = [ // comes after `basalt` on purpose: it is where a round shows an option the owner has not decided ("Option, not // shipped"), scoped to a wrapper that says so. "@layer review, basalt, review-options;", - fs.readFileSync(path.join(reactPkg, "src/styles/components.css"), "utf8"), + // The source stylesheet, with its core-glyph masks written in, as the package's build writes them. + withGlyphMasks(fs.readFileSync(path.join(reactPkg, "src/styles/components.css"), "utf8")), // The accent classes are generated with the tokens; Badge's accent tone reads them. fs.readFileSync(path.join(repo, "packages/tokens/dist/css/accents.css"), "utf8"), `@layer review {\n${fs.readFileSync(path.join(here, "walkthrough.css"), "utf8")}\n}`, diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx index ecd498a4..01f1a983 100644 --- a/tools/review/round66.tsx +++ b/tools/review/round66.tsx @@ -29,7 +29,7 @@ function Diagram({ k, state }: { k: Key; state: string }) { await new Promise((r) => setTimeout(r, 400)); if (state === "viewer-200") { const level = () => Number(document.querySelector(".basalt-diagram-level > span")?.textContent?.replace("%", "") ?? 0); - for (let i = 0; i < 12 && level() < 200; i++) document.querySelector('dialog.basalt-diagram-viewer button[aria-label="Zoom in"]')?.click(); + for (let i = 0; i < 12 && level() < 200; i++) { document.querySelector('dialog.basalt-diagram-viewer button[aria-label="Zoom in"]')?.click(); await frames(2); } } await frames(4); ready(); From 010e37d9ff0dd8683dfcbe0d8182e780cb95ce8d Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:51:01 -0600 Subject: [PATCH 15/62] Flow on a dashed line (DECISIONS 306, 1.5) flow: true is allowed on a dashed edge: its own 6-on-4 dashes march toward the head, one period at speed-diagram-flow on ease-linear, where 48px of line shows; still, held, traced, under reduced motion, in forced colours and in print they sit where the key draws them (the loops' own rules). Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-core.ts | 2 +- packages/react/src/diagram-motion-core.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index b72d7771..4bb2bf41 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -166,7 +166,7 @@ export interface MEdge { fromRow?: number; toRow?: number; fk?: boolean; - /** A live stream (DECISIONS 292, 1.6). */ + /** A live stream (DECISIONS 292, 1.6); on a dashed line its own dashes march (DECISIONS 306, 1.5). */ flow?: boolean; } export type MStep = { band: string } | { n: number; from: string; to: string; label: string; note?: string; kind: DiagramLineKind; activate?: boolean; deactivate?: boolean } diff --git a/packages/react/src/diagram-motion-core.ts b/packages/react/src/diagram-motion-core.ts index a4d20981..4ce229cb 100644 --- a/packages/react/src/diagram-motion-core.ts +++ b/packages/react/src/diagram-motion-core.ts @@ -573,6 +573,16 @@ class Figure implements MotionController { const l = geo.lines.find((x) => x.i === i); if (!l) return; const tk = this.host.tokens(); + // A dashed line's own dashes march toward the head (DECISIONS 306, 1.5): one period (its 6 on 4 off, 10px) at speed-diagram-flow on ease-linear. + // Its open head does not move, and still it is the line the key draws. The 48px rule holds as for cuts. + if (l.kind === "dashed") { + if (this.visible(l, trimmed(l, tk?.head ?? 8)) < 48) return; + const line = this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${i}"] .${this.host.P}-line`); + if (!line) return; + const period = (tk?.dash ?? 6) + (tk?.dashGap ?? 4); + this.track(line.animate([{ strokeDashoffset: "0px" }, { strokeDashoffset: `${-period}px` }], { duration: (period / this.t.flow) * 1000, iterations: Infinity, easing: "linear" }), this.loops); + return; + } let made = this.flowEls.get(i); // An overlay lives in the ink: one the host wrote over is made again. if (made && !made.isConnected) { this.flowEls.delete(i); made = undefined; } @@ -839,7 +849,6 @@ export function motionErrors(m: Model): { errors: string[]; warnings: string[] } } for (const e of m.edges) { if (!e.flow) continue; - if (e.kind === "dashed") errors.push(`the line from ${e.from} to ${e.to} is dashed and flows: flow is on a main or plain line only`); if (onPath.has(e.i)) errors.push(`the line from ${e.from} to ${e.to} flows and is on the ${what}'s route: flow never runs on a line the mover travels`); if (!e.label) warnings.push(`the line from ${e.from} to ${e.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`); } From b29dd144169ff32637610aec42acd62dc9b9cf4d Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:51:41 -0600 Subject: [PATCH 16/62] Marks on a data flow's steps and a sequence's participants (DECISIONS 306, 1.6) mark joins a step and a participant, with 292's section 2 whole. A step takes the architecture card's seat; a participant's head keeps space-6 clear on both sides of its first line, and the column's minimum counts both; a stacked chip draws the mark inline before the name, space-1-5 apart. The says warning reads a step's lane label. compose.mjs writes the marks a page names on steps and participants too. Round 66 marks the service and the sandbox, never Marcus. Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/compose.mjs | 6 ++++-- .agent/skills/basalt-html/parts/diagram-motion.js | 2 +- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 8 ++++++-- packages/react/src/diagram-core.ts | 14 +++++++++----- packages/react/src/styles/components.css | 6 ++++++ tools/html-skill/src/compose.mjs | 6 ++++-- tools/review/round66.tsx | 8 +++++++- 8 files changed, 38 insertions(+), 14 deletions(-) diff --git a/.agent/skills/basalt-html/compose.mjs b/.agent/skills/basalt-html/compose.mjs index 3e5722c6..384add0e 100644 --- a/.agent/skills/basalt-html/compose.mjs +++ b/.agent/skills/basalt-html/compose.mjs @@ -647,9 +647,11 @@ function writeDiagrams(markup, held, parts, notes, marks) { try { spec = JSON.parse(item.inner); } catch (e) { notes.push(`a diagram's JSON does not parse (${e.message}); the page's script will say so`); continue; } // Each card's mark: a bundled id is checked and its rule written once; the page's own mark is read into the page and named by an id, so the JSON // the script reads carries the id and never a path. - if (spec && spec.type === "architecture" && Array.isArray(spec.nodes)) { + // An architecture's cards, a data flow's steps and a sequence's participants may carry one (DECISIONS 306, 1.6). + const cards = spec && (spec.type === "architecture" || spec.type === "data-flow") ? spec.nodes : spec && spec.type === "sequence" ? spec.participants : null; + if (Array.isArray(cards)) { let rewrote = false; - for (const n of spec.nodes) { + for (const n of cards) { if (!n || n.mark === undefined || n.mark === null) continue; if (typeof n.mark === "string") useMark(marks, n.mark, n, notes); else { n.mark = ownMark(marks, n.mark); rewrote = true; } diff --git a/.agent/skills/basalt-html/parts/diagram-motion.js b/.agent/skills/basalt-html/parts/diagram-motion.js index 50fd9f89..5c7f07ab 100644 --- a/.agent/skills/basalt-html/parts/diagram-motion.js +++ b/.agent/skills/basalt-html/parts/diagram-motion.js @@ -1 +1 @@ -(()=>{var C=Object.defineProperty,T=(t,s,e)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s,e)=>T(t,typeof s!="symbol"?s+"":s,e);function P(t,s){const e=o=>String(Math.round(o*100)/100);let i=`M${e(t[0].x)} ${e(t[0].y)}`;for(let o=1;o{for(const h of p?.figs??[])h.sync()},e=()=>{for(const h of p?.figs??[])x(h.host.fig);s()},i=new IntersectionObserver(h=>{for(const r of h)for(const a of p?.figs??[])a.drawing===r.target&&a.seen(r)},{threshold:Array.from({length:21},(h,r)=>r/20)}),n=new MutationObserver(h=>{for(const r of h){if(r.target===document.documentElement){for(const a of p?.figs??[])a.holdChanged();continue}for(const a of p?.figs??[])a.host.fig===r.target&&a.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const o=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of o)h.addEventListener("change",s);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",s),p={figs:new Set,io:i,mo:n,media:o,onChange:s,onPrint:e}}return p.figs.add(t),t.drawing&&p.io.observe(t.drawing),p.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),p}function O(t){if(p&&(p.figs.delete(t),t.drawing&&p.io.unobserve(t.drawing),!p.figs.size)){p.io.disconnect(),p.mo.disconnect();for(const s of p.media)s.removeEventListener("change",p.onChange);window.removeEventListener("beforeprint",p.onPrint),document.removeEventListener("visibilitychange",p.onChange),p=void 0}}function _(t){const s=getComputedStyle(t),e=h=>s.getPropertyValue(`--basalt-${h}`).trim(),i=h=>{const r=e(h),a=parseFloat(r);return/ms$/.test(r)?a:/s$/.test(r)?a*1e3:a||0},n=h=>parseFloat(e(h))||0,o=h=>e(`ease-${h}`)||"ease";return{lineMin:i("duration-diagram-line-min"),lineMax:i("duration-diagram-line-max"),stagger:i("duration-diagram-stagger"),step:i("duration-diagram-step"),arrow:i("duration-diagram-arrow"),limit:i("duration-diagram-limit"),legMin:i("duration-diagram-leg-min"),legMax:i("duration-diagram-leg-max"),rest:i("duration-diagram-rest"),pause:i("duration-diagram-pause"),repeat:i("duration-diagram-repeat"),fast:i("duration-fast"),base:i("duration-base"),slow:i("duration-slow"),slower:i("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:o("in-out"),out:o("out"),in:o("in")}}var L=(t,s,e)=>Math.max(s,Math.min(e,t)),F="http://www.w3.org/2000/svg",w=(t,s,e)=>{const i=document.createElementNS(F,t);for(const[n,o]of Object.entries(s))i.setAttribute(n,String(o));return e?.appendChild(i),i},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",R={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function $(t,s){const e=t.pts.map(a=>({...a})),i=R[t.dir],n=e[e.length-1],o=e[e.length-2],h=Math.hypot(n.x-o.x,n.y-o.y),r=Math.min(s,Math.max(0,h-.5));return n.x-=i.x*r,n.y-=i.y*r,e}var M=t=>t.slice(1).reduce((s,e,i)=>s+Math.hypot(e.x-t[i].x,e.y-t[i].y),0),I=(t,s)=>{const e=t.map(n=>n.x),i=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-s),t:Math.floor(Math.min(...i)-s),r:Math.ceil(Math.max(...e)+s),b:Math.ceil(Math.max(...i)+s)}},V=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",s=>(this.listeners.add(s),()=>{this.listeners.delete(s)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const s of[...this.flowEls.values(),...this.beadEls.values()])s.remove();this.dot?.remove(),O(this)}}),c(this,"onSettle",()=>{this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const i=this.introEnd?.currentTime,n=i!=null?Number(i):E()-this.t0,o=new Set([...this.plans].filter(([,a])=>a.end<=n).map(([a])=>a)),{plans:h,factor:r}=this.plan(this.ordered(e),this.factor);for(const a of o){const l=this.plans.get(a);l&&h.set(a,l)}this.factor=r,this.plans=h,this.build(o,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const s=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(i=>!!i.flow)]);s!==this.signature&&(this.signature=s,x(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",s=>{if(!this.lastSend){this.lastSend={v:s};return}s===void 0||s===this.lastSend.v||(this.lastSend={v:s},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}x(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=_(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=G(this),this.sync()}publish(){const t=this.hasLines(),s=this.host.model(),e=this.modes(),i=s.edges.some(o=>o.flow)||!!s.motion.pulse||!!s.motion.packet?.repeat,n={canLoop:s.motion.animated&&i&&t&&!e.reduce&&!e.forced,runShown:s.motion.animated&&s.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const o of this.listeners)o()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const s=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=s-.5,this.sync()}holdChanged(){this.modes().held&&x(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,s=this.host.model(),e=this.modes(),i=this.entrance();(i==="pending"||i==="running")&&(e.held||e.print||e.reduce||e.forced)?x(t):i==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!i&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(s,e),this.publish()}ordered(t){const s=this.host.model(),e=[...t.lines];return s.type==="schema"?e.sort((i,n)=>i.pts[0].y-n.pts[0].y||i.pts[0].x-n.pts[0].x||i.i-n.i):e.sort((i,n)=>i.i-n.i),e}plan(t,s){const e=this.t,i=this.host.model().type==="sequence",n=i?e.step:e.stagger,o=t.map(a=>{const l=this.lineEl(a)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(a.pts),m=i?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=i?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,i?e.slower:0)}});let h=1;for(let a=1;a{const d=l*n*h;r.set(a.i,{start:d+o[l].lead,dur:o[l].dur,end:d+o[l].tail})}),{plans:r,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.t0=E();const{plans:s,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=s,this.build(new Set,!0)}build(t,s){const e=this.host.geo(),i=this.host.fig,{P:n}=this.host,o=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const r=i.querySelector(`.${n}-ink`),a=r?.querySelector(`.${n}-svg`);if(!r||!a)return;this.defs=w("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),a.after(this.defs);const l=w("defs",{},this.defs),d=(u,g=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),g.add(u),u);let m=0;for(const u of e.lines){const g=this.plans.get(u.i),f=this.lineEl(u);if(!g||!f)continue;if(m=Math.max(m,g.end),t.has(u.i)){f.removeAttribute("mask");continue}const y=`${this.host.base}-reveal-${u.i}`,k=w("mask",{id:y,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),A=f.querySelector(`.${n}-line`);if(A){const b=A.getTotalLength(),z=w("path",{d:A.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${b} ${b+8}`,"stroke-dashoffset":b},k);d(z.animate([{strokeDashoffset:`${b}px`},{strokeDashoffset:"0px"}],{duration:g.dur,delay:g.start,easing:o.inOut,fill:"both"}))}const S=f.querySelector(`.${n}-tip`);if(S){const b=w("path",{d:S.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:o.slow,delay:g.start+.85*g.dur,easing:o.out,fill:"both"}))}const v=f.querySelector(`.${n}-dot`);if(v){const b=w("circle",{cx:v.getAttribute("cx")??0,cy:v.getAttribute("cy")??0,r:Number(v.getAttribute("r")??3)+1,fill:"#fff"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:o.fast,delay:g.start,easing:o.out,fill:"both"}))}f.setAttribute("mask",`url(#${y})`)}if(s&&this.host.model().type==="sequence"){const u=getComputedStyle(i),g=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),y=i.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((k,A)=>{const S=y[A]?.querySelector(`.${n}-mlabel`),v=this.plans.get(k.i);S&&v&&g&&f&&d(S.animate([{color:g},{color:f}],{duration:o.slower,delay:v.start-o.base,easing:o.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(i.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,s){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||s.reduce||s.forced||s.print||s.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,s){s.add(t);const e=()=>{s.delete(t)};return t.finished.then(e,e),s===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,s){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),s).finished.then(e=>{e.cancel()})}overlay(t,s,e){const i=this.host.fig.querySelector(`.${this.host.P}-ink`),n=i?.querySelector(`.${this.host.P}-svg`);if(!i||!n)return null;const o=this.host.tokens(),h=$(t,o?.head??8),r=I(h,s),a=w("svg",{class:`${this.host.P}-${e}`,width:r.r-r.l,height:r.b-r.t,viewBox:`${r.l} ${r.t} ${r.r-r.l} ${r.b-r.t}`,"aria-hidden":"true",focusable:"false"});a.style.left=`${r.l}px`,a.style.top=`${r.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(a),{svg:a,d:P(h,t.from===t.to?o?.radiusXs??4:o?.radius??8),pts:h}}visible(t,s){const e=this.host.geo();let i=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const o=(n.box.t+n.box.b)/2,h=s.some((r,a)=>a>0&&Math.abs(r.y-s[a-1].y)<.5&&Math.abs(o-r.y)<1.5);i+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(s)-i}flow(t,s){const e=t.lines.find(r=>r.i===s);if(!e)return;const i=this.host.tokens();let n=this.flowEls.get(s);if(n&&!n.isConnected&&(this.flowEls.delete(s),n=void 0),!n){const r=i?.space("1")??4,a=this.overlay({...e,pts:$(e,r)},e.width+2,"flow");if(!a)return;if(this.visible(e,$(e,i?.head??8))<48){a.svg.remove();return}const l=i?.cut??2;w("path",{d:a.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},a.svg),n=a.svg,this.flowEls.set(s,n)}n.style.display="";const o=n.firstElementChild,h=this.t.flowPeriod;this.track(o.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,s){const i=this.host.model().edges.find(n=>n.from===t&&n.to===s);return i?this.host.geo()?.lines.find(n=>n.i===i.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,s){const e=this.host.tokens();for(;t===this.loopGen;){for(let i=1;it===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(s,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const i=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=i;try{await i.finished}finally{this.repeatGap===i&&(this.repeatGap=null),i.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),s=t.motion.packet?.path;if(!t.motion.animated||!s||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(s[s.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const i=++this.runGen;this.packetRun(s,this.runAnims,()=>i===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&i===this.runGen&&(this.waiting=!1,this.send())})}stopRun(){this.runGen++,this.runAt=-1;for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const s=this.host.geo();if(!s?.lines.length)return;for(const r of this.runAnims)r.cancel();this.runAnims.clear();const e=++this.runGen,i=()=>e===this.runGen,n=this.ordered(s),o=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let r=t;r{if(!q(r))throw r})}};function N(t){const s=[],e=[],{pulse:i,packet:n}=t.motion;i&&n&&s.push("a figure names both a pulse and a packet: it has one mover at most");const o=i??n?.path,h=i?"pulse":"packet",r=new Set;if(o){for(const a of o)t.byId.has(a)||s.push(`the ${h} names ${a}, which is not a node`);for(let a=1;ad.from===o[a-1]&&d.to===o[a]);l?r.add(l.i):s.push(`the ${h} goes from ${o[a-1]} to ${o[a]}, and no line joins them in that direction`)}}for(const a of t.edges)a.flow&&(a.kind==="dashed"&&s.push(`the line from ${a.from} to ${a.to} is dashed and flows: flow is on a main or plain line only`),r.has(a.i)&&s.push(`the line from ${a.from} to ${a.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),a.label||e.push(`the line from ${a.from} to ${a.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:s,warnings:e}}function D(t){return new V(t)}(function(t){"use strict";var s=t._;function e(i,n,o){var h=document.createElement("button");return h.type="button",h.className="btn "+i,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),o&&o(h),h.appendChild(document.createTextNode(n)),h}s.diagramMotion=function(i,n,o){var h=N(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var r=D(n),a=i.querySelector(".diagram-foot"),l=null,d=null;a&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){r.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var y=document.createElement("span");y.className="btn-check",y.setAttribute("aria-hidden","true"),f.appendChild(y)}),l.hidden=d.hidden=!0,a.appendChild(l),a.appendChild(d));function m(){var f=r.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=r.subscribe(m);m();var g=o&&o.packet?o.packet.send:void 0;return r.sendValue("__diagramSend"in i?i.__diagramSend:g),r.sendValue(g),i.__diagramSend=g,{redrawn:r.redrawn,sendValue:function(f){r.sendValue(f),i.__diagramSend=f},destroy:function(){u(),r.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); +(()=>{var C=Object.defineProperty,T=(t,s,e)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s,e)=>T(t,typeof s!="symbol"?s+"":s,e);function P(t,s){const e=r=>String(Math.round(r*100)/100);let i=`M${e(t[0].x)} ${e(t[0].y)}`;for(let r=1;r{for(const h of p?.figs??[])h.sync()},e=()=>{for(const h of p?.figs??[])x(h.host.fig);s()},i=new IntersectionObserver(h=>{for(const o of h)for(const a of p?.figs??[])a.drawing===o.target&&a.seen(o)},{threshold:Array.from({length:21},(h,o)=>o/20)}),n=new MutationObserver(h=>{for(const o of h){if(o.target===document.documentElement){for(const a of p?.figs??[])a.holdChanged();continue}for(const a of p?.figs??[])a.host.fig===o.target&&a.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const r=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of r)h.addEventListener("change",s);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",s),p={figs:new Set,io:i,mo:n,media:r,onChange:s,onPrint:e}}return p.figs.add(t),t.drawing&&p.io.observe(t.drawing),p.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),p}function O(t){if(p&&(p.figs.delete(t),t.drawing&&p.io.unobserve(t.drawing),!p.figs.size)){p.io.disconnect(),p.mo.disconnect();for(const s of p.media)s.removeEventListener("change",p.onChange);window.removeEventListener("beforeprint",p.onPrint),document.removeEventListener("visibilitychange",p.onChange),p=void 0}}function _(t){const s=getComputedStyle(t),e=h=>s.getPropertyValue(`--basalt-${h}`).trim(),i=h=>{const o=e(h),a=parseFloat(o);return/ms$/.test(o)?a:/s$/.test(o)?a*1e3:a||0},n=h=>parseFloat(e(h))||0,r=h=>e(`ease-${h}`)||"ease";return{lineMin:i("duration-diagram-line-min"),lineMax:i("duration-diagram-line-max"),stagger:i("duration-diagram-stagger"),step:i("duration-diagram-step"),arrow:i("duration-diagram-arrow"),limit:i("duration-diagram-limit"),legMin:i("duration-diagram-leg-min"),legMax:i("duration-diagram-leg-max"),rest:i("duration-diagram-rest"),pause:i("duration-diagram-pause"),repeat:i("duration-diagram-repeat"),fast:i("duration-fast"),base:i("duration-base"),slow:i("duration-slow"),slower:i("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:r("in-out"),out:r("out"),in:r("in")}}var L=(t,s,e)=>Math.max(s,Math.min(e,t)),F="http://www.w3.org/2000/svg",y=(t,s,e)=>{const i=document.createElementNS(F,t);for(const[n,r]of Object.entries(s))i.setAttribute(n,String(r));return e?.appendChild(i),i},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",I={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function v(t,s){const e=t.pts.map(a=>({...a})),i=I[t.dir],n=e[e.length-1],r=e[e.length-2],h=Math.hypot(n.x-r.x,n.y-r.y),o=Math.min(s,Math.max(0,h-.5));return n.x-=i.x*o,n.y-=i.y*o,e}var M=t=>t.slice(1).reduce((s,e,i)=>s+Math.hypot(e.x-t[i].x,e.y-t[i].y),0),R=(t,s)=>{const e=t.map(n=>n.x),i=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-s),t:Math.floor(Math.min(...i)-s),r:Math.ceil(Math.max(...e)+s),b:Math.ceil(Math.max(...i)+s)}},V=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",s=>(this.listeners.add(s),()=>{this.listeners.delete(s)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const s of[...this.flowEls.values(),...this.beadEls.values()])s.remove();this.dot?.remove(),O(this)}}),c(this,"onSettle",()=>{this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const i=this.introEnd?.currentTime,n=i!=null?Number(i):E()-this.t0,r=new Set([...this.plans].filter(([,a])=>a.end<=n).map(([a])=>a)),{plans:h,factor:o}=this.plan(this.ordered(e),this.factor);for(const a of r){const l=this.plans.get(a);l&&h.set(a,l)}this.factor=o,this.plans=h,this.build(r,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const s=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(i=>!!i.flow)]);s!==this.signature&&(this.signature=s,x(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",s=>{if(!this.lastSend){this.lastSend={v:s};return}s===void 0||s===this.lastSend.v||(this.lastSend={v:s},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}x(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=_(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=G(this),this.sync()}publish(){const t=this.hasLines(),s=this.host.model(),e=this.modes(),i=s.edges.some(r=>r.flow)||!!s.motion.pulse||!!s.motion.packet?.repeat,n={canLoop:s.motion.animated&&i&&t&&!e.reduce&&!e.forced,runShown:s.motion.animated&&s.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const r of this.listeners)r()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const s=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=s-.5,this.sync()}holdChanged(){this.modes().held&&x(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,s=this.host.model(),e=this.modes(),i=this.entrance();(i==="pending"||i==="running")&&(e.held||e.print||e.reduce||e.forced)?x(t):i==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!i&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(s,e),this.publish()}ordered(t){const s=this.host.model(),e=[...t.lines];return s.type==="schema"?e.sort((i,n)=>i.pts[0].y-n.pts[0].y||i.pts[0].x-n.pts[0].x||i.i-n.i):e.sort((i,n)=>i.i-n.i),e}plan(t,s){const e=this.t,i=this.host.model().type==="sequence",n=i?e.step:e.stagger,r=t.map(a=>{const l=this.lineEl(a)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(a.pts),m=i?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=i?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,i?e.slower:0)}});let h=1;for(let a=1;a{const d=l*n*h;o.set(a.i,{start:d+r[l].lead,dur:r[l].dur,end:d+r[l].tail})}),{plans:o,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.t0=E();const{plans:s,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=s,this.build(new Set,!0)}build(t,s){const e=this.host.geo(),i=this.host.fig,{P:n}=this.host,r=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const o=i.querySelector(`.${n}-ink`),a=o?.querySelector(`.${n}-svg`);if(!o||!a)return;this.defs=y("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),a.after(this.defs);const l=y("defs",{},this.defs),d=(u,g=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),g.add(u),u);let m=0;for(const u of e.lines){const g=this.plans.get(u.i),f=this.lineEl(u);if(!g||!f)continue;if(m=Math.max(m,g.end),t.has(u.i)){f.removeAttribute("mask");continue}const w=`${this.host.base}-reveal-${u.i}`,k=y("mask",{id:w,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),A=f.querySelector(`.${n}-line`);if(A){const b=A.getTotalLength(),z=y("path",{d:A.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${b} ${b+8}`,"stroke-dashoffset":b},k);d(z.animate([{strokeDashoffset:`${b}px`},{strokeDashoffset:"0px"}],{duration:g.dur,delay:g.start,easing:r.inOut,fill:"both"}))}const S=f.querySelector(`.${n}-tip`);if(S){const b=y("path",{d:S.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:r.slow,delay:g.start+.85*g.dur,easing:r.out,fill:"both"}))}const $=f.querySelector(`.${n}-dot`);if($){const b=y("circle",{cx:$.getAttribute("cx")??0,cy:$.getAttribute("cy")??0,r:Number($.getAttribute("r")??3)+1,fill:"#fff"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:r.fast,delay:g.start,easing:r.out,fill:"both"}))}f.setAttribute("mask",`url(#${w})`)}if(s&&this.host.model().type==="sequence"){const u=getComputedStyle(i),g=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),w=i.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((k,A)=>{const S=w[A]?.querySelector(`.${n}-mlabel`),$=this.plans.get(k.i);S&&$&&g&&f&&d(S.animate([{color:g},{color:f}],{duration:r.slower,delay:$.start-r.base,easing:r.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(i.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,s){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||s.reduce||s.forced||s.print||s.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,s){s.add(t);const e=()=>{s.delete(t)};return t.finished.then(e,e),s===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,s){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),s).finished.then(e=>{e.cancel()})}overlay(t,s,e){const i=this.host.fig.querySelector(`.${this.host.P}-ink`),n=i?.querySelector(`.${this.host.P}-svg`);if(!i||!n)return null;const r=this.host.tokens(),h=v(t,r?.head??8),o=R(h,s),a=y("svg",{class:`${this.host.P}-${e}`,width:o.r-o.l,height:o.b-o.t,viewBox:`${o.l} ${o.t} ${o.r-o.l} ${o.b-o.t}`,"aria-hidden":"true",focusable:"false"});a.style.left=`${o.l}px`,a.style.top=`${o.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(a),{svg:a,d:P(h,t.from===t.to?r?.radiusXs??4:r?.radius??8),pts:h}}visible(t,s){const e=this.host.geo();let i=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const r=(n.box.t+n.box.b)/2,h=s.some((o,a)=>a>0&&Math.abs(o.y-s[a-1].y)<.5&&Math.abs(r-o.y)<1.5);i+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(s)-i}flow(t,s){const e=t.lines.find(o=>o.i===s);if(!e)return;const i=this.host.tokens();if(e.kind==="dashed"){if(this.visible(e,v(e,i?.head??8))<48)return;const o=this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${s}"] .${this.host.P}-line`);if(!o)return;const a=(i?.dash??6)+(i?.dashGap??4);this.track(o.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-a}px`}],{duration:a/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops);return}let n=this.flowEls.get(s);if(n&&!n.isConnected&&(this.flowEls.delete(s),n=void 0),!n){const o=i?.space("1")??4,a=this.overlay({...e,pts:v(e,o)},e.width+2,"flow");if(!a)return;if(this.visible(e,v(e,i?.head??8))<48){a.svg.remove();return}const l=i?.cut??2;y("path",{d:a.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},a.svg),n=a.svg,this.flowEls.set(s,n)}n.style.display="";const r=n.firstElementChild,h=this.t.flowPeriod;this.track(r.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,s){const i=this.host.model().edges.find(n=>n.from===t&&n.to===s);return i?this.host.geo()?.lines.find(n=>n.i===i.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,s){const e=this.host.tokens();for(;t===this.loopGen;){for(let i=1;it===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(s,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const i=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=i;try{await i.finished}finally{this.repeatGap===i&&(this.repeatGap=null),i.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),s=t.motion.packet?.path;if(!t.motion.animated||!s||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(s[s.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const i=++this.runGen;this.packetRun(s,this.runAnims,()=>i===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&i===this.runGen&&(this.waiting=!1,this.send())})}stopRun(){this.runGen++,this.runAt=-1;for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const s=this.host.geo();if(!s?.lines.length)return;for(const o of this.runAnims)o.cancel();this.runAnims.clear();const e=++this.runGen,i=()=>e===this.runGen,n=this.ordered(s),r=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let o=t;o{if(!q(o))throw o})}};function D(t){const s=[],e=[],{pulse:i,packet:n}=t.motion;i&&n&&s.push("a figure names both a pulse and a packet: it has one mover at most");const r=i??n?.path,h=i?"pulse":"packet",o=new Set;if(r){for(const a of r)t.byId.has(a)||s.push(`the ${h} names ${a}, which is not a node`);for(let a=1;ad.from===r[a-1]&&d.to===r[a]);l?o.add(l.i):s.push(`the ${h} goes from ${r[a-1]} to ${r[a]}, and no line joins them in that direction`)}}for(const a of t.edges)a.flow&&(o.has(a.i)&&s.push(`the line from ${a.from} to ${a.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),a.label||e.push(`the line from ${a.from} to ${a.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:s,warnings:e}}function N(t){return new V(t)}(function(t){"use strict";var s=t._;function e(i,n,r){var h=document.createElement("button");return h.type="button",h.className="btn "+i,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),r&&r(h),h.appendChild(document.createTextNode(n)),h}s.diagramMotion=function(i,n,r){var h=D(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var o=N(n),a=i.querySelector(".diagram-foot"),l=null,d=null;a&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){o.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var w=document.createElement("span");w.className="btn-check",w.setAttribute("aria-hidden","true"),f.appendChild(w)}),l.hidden=d.hidden=!0,a.appendChild(l),a.appendChild(d));function m(){var f=o.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=o.subscribe(m);m();var g=r&&r.packet?r.packet.send:void 0;return o.sendValue("__diagramSend"in i?i.__diagramSend:g),o.sendValue(g),i.__diagramSend=g,{redrawn:o.redrawn,sendValue:function(f){o.sendValue(f),i.__diagramSend=f},destroy:function(){u(),o.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index 43ccb3a5..7906e7f4 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin:calc(-1 * var(--basalt-space-8)) calc(-1 * var(--basalt-space-4)) calc(-1 * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint{display:none}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint{display:none}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index ae949afa..653a8e03 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,2 +1,6 @@ -(()=>{var he=["top","right","bottom","left"],pe=["main","plain","dashed"],ge=[2,3,4,5,6],rt=t=>t==null||t===""?void 0:String(t),ft=t=>Object.assign(Object.create(null),t),pt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function At(t,e={}){const s=e.checks!==!1,r=[],o=d=>{r.push(d)},a=t.legend??{},i={};for(const d of["main","plain","dashed","focal","group"]){const y=rt(a[d]);y&&(i[d]=y)}const f=t.stepLabel,p=typeof f=="function"?d=>String(f(d)):typeof f=="string"?(d=>f.replace("{n}",String(d))):d=>`Step ${d}`,u=t.shapeLabels??{},g={terminal:rt(u.terminal)??"Start or end",step:rt(u.step)??"Step",decision:rt(u.decision)??"Decision"},c=t.heading===void 0?3:ge.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),m=(d,y)=>d==null?"plain":pe.includes(d)?d:(o(`"${String(d)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),$=d=>{if(d!=null){if(he.includes(d))return d;o(`"${String(d)}" is not a side (top, right, bottom or left): the derived side is used`)}},l=(d,y)=>typeof d=="number"&&Number.isInteger(d)&&d>=1?d:(o(`${y} is ${JSON.stringify(d)}, not a whole number from 1: it is placed at 1`),1),h=[],b=[];let q=[];const L=[],C=[],j=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(j)||o(`"${String(j)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),j==="architecture"||j==="flowchart"){for(const d of t.nodes??[]){const y=j==="flowchart"&&d.shape==="decision"?"decision":j==="flowchart"&&d.shape==="terminal"?"terminal":"box",M=String(d.id??""),B=l(d.row,`the row of ${M}`);h.push({id:M,i:h.length,name:String(d.name??""),kind:y==="decision"?void 0:rt(d.kind),detail:y==="decision"?void 0:rt(d.detail),mono:!!d.detailMono,focal:!!d.focal,col:l(d.col,`the column of ${M}`),row:B,row2:B,branch:!!d.branch,shape:y,group:j==="architecture"?rt(d.group):void 0,mark:j==="architecture"?me(d.mark):void 0})}if(j==="architecture")for(const d of t.groups??[]){const y=String(d.id??"");L.push({id:y,label:String(d.label??""),members:h.filter(M=>M.group===y).map(M=>M.id)})}}else if(j==="data-flow"){q=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const d=new Map(q.map((y,M)=>[y.id,M+1]));for(const y of t.nodes??[]){const M=String(y.id??""),B=String(y.lane??""),H=d.get(B);H===void 0&&o(`a node (${M}) names the lane "${B}", which is not in lanes`);const T=h.length+1;h.push({id:M,i:h.length,name:String(y.name??""),kind:p(T),detail:rt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:l(y.col,`the column of ${M}`),row:H??1,row2:H??1,branch:!1,shape:"box",lane:H??1,laneLabel:q[(H??1)-1]?.label??B,step:T})}}else if(j==="sequence"){(t.participants??[]).forEach((y,M)=>{const B=String(y.name??"");h.push({id:String(y.id??""),i:M,name:B,kind:rt(y.kind),mono:!1,focal:!!y.focal,col:M+1,row:1,row2:1,branch:!1,shape:"participant",short:rt(y.short)??B})});let d=0;for(const y of t.steps??[])"band"in y?C.push({band:String(y.band??"")}):(d++,C.push({n:d,from:String(y.from??""),to:String(y.to??""),label:String(y.label??""),note:rt(y.note),kind:m(y.kind,`message ${d}`)}))}else if(j==="schema")for(const d of t.tables??[]){const y=String(d.name??""),[M,B]=Array.isArray(d.row)?d.row:[d.row,d.row],H=l(M,`the row of ${y}`),T=Math.max(H,l(B,`the last row of ${y}`)),V=d.more===void 0||d.more===null?void 0:Number.isInteger(d.more)&&d.more>0?d.more:(o(`${y}'s "more" is ${JSON.stringify(d.more)}, not a whole number from 1: it is left out`),void 0);h.push({id:y,i:h.length,name:y,mono:!0,focal:!!d.focal,col:l(d.col,`the column of ${y}`),row:H,row2:T,branch:!1,shape:"table",more:V,columns:(d.columns??[]).map(v=>({name:String(v.name??""),type:rt(v.type),key:v.key==="PK"||v.key==="FK"?v.key:(v.key!==void 0&&v.key!==null&&o(`${y}.${String(v.name)}'s key is "${String(v.key)}", not PK or FK: it is left out`),void 0)}))})}const F=new Map;for(const d of h)d.id?F.has(d.id)&&o(`the id "${d.id}" is used twice`):o("a node has no id"),F.set(d.id,d);if(j==="schema")(t.tables??[]).forEach(d=>(d.columns??[]).forEach((y,M)=>{const B=rt(y.references);if(!B)return;const[H,T]=B.split("."),V=F.get(H??""),v=V?.columns?.findIndex(I=>I.name===T)??-1;if(!V||v<0){o(`${String(d.name)}.${String(y.name)} references ${B}, which is not a shown column`);return}const O=F.get(String(d.name??""));O.columns[M].ref={table:H,column:T,row:v},b.push({i:b.length,from:O.id,to:H,kind:"plain",fromRow:M,toRow:v,fk:!0})}));else if(j!=="sequence")for(const d of t.edges??[]){const y=String(d.from??""),M=String(d.to??"");if(!F.has(y)||!F.has(M)){o(`a line names ${F.has(y)?M:y}, which is not a node`);continue}const B=rt(d.label);B&&B.length>jt&&o(`the label "${B}" is over ${jt} characters: longer words belong in the node or the summary`),b.push({i:b.length,from:y,to:M,kind:m(d.kind,`the line from ${y} to ${M}`),label:B,fromSide:$(d.fromSide),toSide:$(d.toSide),flow:j!=="flowchart"&&d.flow===!0?!0:void 0})}else for(const d of C)"n"in d&&(!F.has(d.from)||!F.has(d.to))&&o(`message ${d.n} names ${F.has(d.from)?d.to:d.from}, which is not a participant`);if(s&&j!=="sequence"){const d=new Map;for(const y of h)for(let M=y.row;M<=y.row2;M++){const B=`${y.col}:${M}`;d.has(B)&&o(`${y.id} and ${d.get(B)} share the cell at column ${y.col}, row ${M}`),d.set(B,y.id)}}if(s){for(const y of L){const M=y.members.map(T=>F.get(T));if(!M.length)continue;const B={c1:Math.min(...M.map(T=>T.col)),c2:Math.max(...M.map(T=>T.col)),r1:Math.min(...M.map(T=>T.row)),r2:Math.max(...M.map(T=>T.row2))};for(const T of h)T.group!==y.id&&T.col>=B.c1&&T.col<=B.c2&&T.row>=B.r1&&T.row<=B.r2&&o(`${T.id} is inside the box of the group "${y.label}" but not a member`);const H=M.map(T=>T.i);Math.max(...H)-Math.min(...H)+1!==H.length&&o(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of h)y.group&&!L.some(M=>M.id===y.group)&&o(`${y.id} names the group "${y.group}", which is not in groups`);h.filter(y=>y.focal).length>1&&o("more than one node is focal: a diagram has one at most");const d=new Set(j==="sequence"?C.flatMap(y=>"n"in y?[y.kind]:[]):b.map(y=>y.kind));d.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),d.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),h.some(y=>y.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const Q=j==="architecture"||j==="data-flow",A=d=>Array.isArray(d)&&d.length>1?d.map(String):void 0,K=Q&&t.packet&&typeof t.packet=="object"?t.packet:void 0,k=K&&A(K.path),D={animated:t.motion==="animated",pulse:Q?A(t.pulse):void 0,packet:k?{path:k,repeat:K.repeat===!0,send:K.send}:void 0,run:j==="sequence"&&t.run===!0};if(s)for(const d of h){const y=d.mark?.says;if(!y?.length)continue;const M=[d.name,d.kind,d.detail].filter(Boolean).join(" ").toLowerCase();y.some(B=>M.includes(B.toLowerCase()))||o(`${d.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const E=Math.max(1,...h.map(d=>d.col)),x=j==="data-flow"?Math.max(1,q.length):Math.max(1,...h.map(d=>d.row2)),R={type:j,title:String(t.title??""),heading:c,legend:i,nodes:h,byId:F,edges:b,groups:L,lanes:q,steps:C,cols:E,rows:x,shapeLabels:g,stepWord:p,warnings:r,motion:D,memo:new Map};return s&&h.length>1&&!vt(R)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),R}function me(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=rt(e.onLight);if(n)return{onLight:n,onDark:rt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ct=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function yt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var jt=28,mt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Bt(t,e){return t.legend[e]}function ye(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function be(t,e){return yt(t,`sentence:${e.i}`,()=>$e(t,e))}function $e(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,r=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(mt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`)}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?ye(t,e):e.kind;if(n.push(mt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(mt(e.detail)),e.group){const a=t.groups.find(i=>i.id===e.group);a&&n.push(`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${a.label})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${a.label})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(mt(t.legend.focal)),n.join(" ")}function we(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function w(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var xe={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>xe[e]),ve=" br img input meta link hr path polygon polyline circle rect line ";function Et(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${it(String(r))}"`}return ve.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Et(s,e)).join("")}`}var ke=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function gt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Me(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Tt(t){let e=0;for(const n of t.groups){const s=n.members.map(r=>t.byId.get(r).col);s.length&&(Math.min(...s)===1&&(e|=1),Math.max(...s)===t.cols&&(e|=2))}return(e&1)+(e>>1&1)}function Lt(t){return t.type==="sequence"?t.nodes.length:t.cols}function Rt(t){return yt(t,"plan",()=>Se(t))}function Se(t){const e=t.nodes,n=l=>t.type==="data-flow"||!e[l].branch,s=t.edges.map(l=>{const h=t.byId.get(l.from).i,b=t.byId.get(l.to).i,L=e.slice(Math.min(h,b)+1,Math.max(h,b)).every(C=>!n(C.i));return b===h+1&&!(n(h)&&!n(b))?"down":b===h-1?"up":b>h&&n(h)&&!n(b)&&L?"trunk":b>h&&n(h)&&n(b)&&L?"rail":b>h?"end-down":"end-up"}),r=t.edges.map((l,h)=>({e:l,k:h})).filter(({k:l})=>s[l]==="end-down"||s[l]==="end-up"),o=l=>{const h=t.byId.get(l.from).i,b=t.byId.get(l.to).i;return[Math.min(h,b),Math.max(h,b)]},a=(l,h)=>{const[b,q]=o(l),[L,C]=o(h);return b{const h=t.byId.get(l.from).i,[b,q]=o(l);return!n(h)&&e.slice(b+1,q).every(L=>!n(L.i))&&r.every(L=>L.e===l||!a(L.e,l))}),f=r.length>0&&(t.type==="data-flow"||!i),p=l=>{const[h,b]=o(l);return b-h},u=t.edges.map(()=>0);let g=!1;const c=[];for(const l of[...r].sort((h,b)=>p(h.e)-p(b.e)||h.k-b.k)){let h=0;for(const b of c)a(b.e,l.e)&&(h=Math.max(h,u[b.k]+1));u[l.k]=h,h>1&&(g=!0),c.push(l)}const m=t.edges.map(()=>.5);for(const l of e){const h=r.filter(({e:L})=>L.from===l.id);if(h.length<2)continue;const b=h.filter(({k:L})=>s[L]==="end-down").sort((L,C)=>p(C.e)-p(L.e)||L.k-C.k);[...h.filter(({k:L})=>s[L]==="end-up").sort((L,C)=>p(L.e)-p(C.e)||C.k-L.k),...b].forEach(({k:L},C,j)=>{m[L]=j.length===2?C===0?1/3:2/3:(C+1)/(j.length+1)})}const $=ft();for(let l=1;l{const A=s[Q],K=t.byId.get(F.from).i,k=t.byId.get(F.to).i,D=k===l&&(A==="down"||A==="trunk"||A==="rail"||A==="end-down"),E=K===l&&k===l-1&&A==="up",x=k===l-1&&A==="end-up";D&&(A==="trunk"||A==="end-down")&&(C=!0),x&&(j=!0),(D||E||x)&&F.label&&(q++,L=Math.max(L,A==="trunk"?40:48))}),(q>1||C&&j)&&(L=64),$[h.id]=L}return{routes:s,gutter:f,lanes:u,exits:m,gaps:$,third:g}}var bt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Ft(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return w("svg",{class:`${t}-swatch`,"data-kind":n,...bt(24,16)},e==="fk"?w("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,w("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?w("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):w("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function $t(t,e){return e==="decision"?w("svg",{class:`${t}-swatch`,"data-shape":e,...bt(16,16)},w("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?w("svg",{class:`${t}-swatch`,"data-shape":e,...bt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):w("svg",{class:`${t}-swatch`,"data-shape":e,...bt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function zt(t,e){return yt(e,`key:${t}`,()=>Ee(t,e))}var Ae=zt;function Ee(t,e){const n=[],s=(o,a,i={})=>n.push(w("li",{class:`${t}-entry`,...i},o,w("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),w("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s($t(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s($t(t,"box"),e.shapeLabels.step),o.has("decision")&&s($t(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Ft(t,o),a,{"data-line":""})}return e.type==="schema"&&e.edges.length&&(s(Ft(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(w("li",{class:`${t}-entry`,"data-when":"stacked"},w("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),w("span",null,"The table a foreign key references")))),e.nodes.some(o=>o.focal)&&e.legend.focal&&s($t(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s($t(t,"group"),e.legend.group),n.length?w("div",{class:`${t}-key`},w("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Le(t,e){const n=e==="main"?6:6.5;return w("svg",{class:`${t}-arrow`,"data-kind":e,...bt(20,12)},w("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?w("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):w("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function qe(t,e,n){if(n.shape==="decision")return[w("span",{class:`${t}-words`},w("span",{class:`${t}-name`},n.name))];const s=[];return e.type==="data-flow"?s.push(w("span",{class:`${t}-kind`},n.kind,w("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(w("span",{class:`${t}-kind`},n.kind)),s.push(w("span",{class:`${t}-name`},n.name)),n.detail&&s.push(w("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Mt(n.detail).flatMap((r,o)=>[o?" ":"",w("span",{class:`${t}-run`},r)]):n.detail)),s}function Ie(t,e){return[w("span",{class:`${t}-th`},w("span",{class:`${t}-tname`},e.name)),w("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>w("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},w("span",{class:`${t}-keyseat`},n.key??""),w("span",{class:`${t}-cname`},n.name),n.ref?w("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?w("span",{class:`${t}-ctype`},n.type):null))),e.more?w("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ht=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function qt(t,e,n,s){const{P:r}=t,o=Me(e,s)||s.keep===n.id,a=gt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const f=t.plan;if(f&&n.i>0){const c=pt(f.gaps,n.id)??32,m=pt(s.grow,n.id)??0;i.push(`--_gap:${m?`calc(${Ht(c)} + var(--basalt-space-4) * ${m})`:Ht(c)}`)}const p=pt(s.heights,n.id);p&&i.push(`--_h:${p}px`);const u=pt(s.words,n.id);u&&i.push(`--_ww:${u}px`);const g=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return w("div",{class:`${r}-node`,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o?"img":void 0,"aria-label":o?be(e,n):void 0,tabindex:g},n.shape==="decision"?w("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},w("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?w("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ct(n.mark.onLight)};--_md:${Ct(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Ie(r,n):qe(r,e,n))}function Oe(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((a,i)=>w("div",{class:`${s}-lane`,style:`--_r:${i+1}`,"aria-hidden":"true"},w("span",{class:`${s}-lane-name`},a.label)))),e.type==="architecture")for(const a of e.groups){const i=a.members.map(c=>e.byId.get(c));if(!i.length)continue;const f=Math.min(...i.map(c=>c.col)),p=Math.max(...i.map(c=>c.col)),u=Math.min(...i.map(c=>c.row)),g=Math.max(...i.map(c=>c.row2));r.push(w("div",{class:`${s}-gbox`,"data-group":a.id,style:`--_c:${f};--_c2:${p+1};--_r:${u};--_r2:${g+1}`,"aria-hidden":"true"},w("span",{class:`${s}-glabel`},a.label)))}if(e.type==="sequence")return r.push(w("ul",{class:`${s}-cast`},e.nodes.map(a=>w("li",{class:`${s}-actor`},qt(t,e,a,n))))),r.push(_e(t,e)),r;let o=0;for(;ou.id===a.group):void 0;if(!i){r.push(qt(t,e,a,n)),o++;continue}const f=[];for(;oqt(t,e,u,n))))}return r}function _e(t,e){const{P:n}=t,s=[];let r=null;for(const o of e.steps){if("band"in o){r=null,s.push(w("p",{class:`${n}-band`},w("span",null,o.band)));continue}r||(r=w("ol",{class:`${n}-msgs`,start:o.n}),s.push(r));const a=e.byId.get(o.from),i=e.byId.get(o.to),f=a?.col??1,p=i?.col??1,u=f===p,g=u&&f===e.nodes.length,c=Bt(e,o.kind);r.c.push(w("li",{class:`${n}-msg`,"data-kind":o.kind,"data-from":o.from,"data-to":o.to,"data-self":u?g?"start":"end":void 0,style:`--_a:${Math.min(f,p)};--_b:${Math.max(f,p)+1}`},w("span",{class:`${n}-said`},w("span",{class:`${n}-num`},String(o.n)),w("span",{class:`${n}-mlabel`},o.label)),w("span",{class:`${n}-route`},a?.short??o.from," ",Le(n,o.kind),w("span",{class:t.hidden}," to ")," ",i?.short??o.to,c?` · ${c}`:""),o.note?w("span",{class:`${n}-note`},o.note):null))}return w("div",{class:`${n}-steps`},s)}function Nt(t,e){return yt(e,`list:${t}`,()=>je(t,e))}var Ce=Nt;function je(t,e){const n=Math.min(6,e.heading+1),s=u=>w(`h${n}`,{class:`${t}-list-head`},u),r=u=>w("strong",null,u),o=u=>w("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,i=u=>{const g=Bt(e,u);return g?` (${g})`:""},f=u=>u.focal&&e.legend.focal?` ${mt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=m=>w("li",null,r(m.name),m.kind?`, ${m.kind}`:"",m.detail?[". ",m.mono?o(m.detail):m.detail,/[.!?]$/.test(m.detail)?"":"."]:/[.!?]$/.test(m.kind??m.name)?"":".",f(m)),g=[s("Parts")],c=e.nodes.filter(m=>!m.group);c.length&&g.push(w("ul",{class:`${t}-list-items`},c.map(u)));for(const m of e.groups)g.push(w("p",{class:`${t}-list-group`},m.label)),g.push(w("ul",{class:`${t}-list-items`},m.members.map($=>u(e.byId.get($)))));return g.push(s("Connections")),g.push(w("ol",{class:`${t}-list-items`},e.edges.map(m=>w("li",null,r(a(m.from))," to ",r(a(m.to)),m.label?[": ",o(m.label)]:"",`${i(m.kind)}.`)))),g}if(e.type==="flowchart"){const u=g=>(e.byId.get(g)?.i??0)+1;return[w("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const c=e.edges.filter(l=>l.from===g.id),m=g.shape==="decision"?"Decision":g.shape==="terminal"?c.length?"Start":"End":"Step",$=!g.detail&&/[.!?]$/.test(g.name)?" ":". ";return w("li",null,r(g.name),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",`${$}${m}.`,f(g),c.length?w("ul",{class:`${t}-list-exits`},c.map(l=>w("li",null,l.label?`If ${l.label}: go to ${u(l.to)}, `:`Then: go to ${u(l.to)}, `,r(a(l.to)),i(l.kind)))):null)}))]}if(e.type==="data-flow")return[w("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const g=e.edges.filter(c=>c.from===u.id);return w("li",null,`${u.laneLabel}: `,r(u.name),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",f(u),g.length?[" Then ",...g.flatMap((c,m)=>[m?"; ":"",`to step ${e.byId.get(c.to).step}, `,r(a(c.to)),c.label?[": ",o(c.label)]:"",i(c.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),w("ul",{class:`${t}-list-items`},e.nodes.map(c=>w("li",null,r(c.name),c.kind?`, ${c.kind}`:"",".",f(c))))];u.push(s("Messages"));let g=null;for(const c of e.steps){if("band"in c){g=null,u.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},c.band));continue}g||(g=w("ol",{class:`${t}-list-items`,start:c.n}),u.push(g)),g.c.push(w("li",null,o(c.label),": ",r(a(c.from))," to ",r(a(c.to)),`${i(c.kind)}.`,c.note?` ${mt(c.note)}`:""))}return u}const p=[];for(const u of e.nodes)p.push(w(`h${n}`,{class:`${t}-list-group`},o(u.name),f(u))),p.push(w("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(g=>w("li",null,o(g.name),g.key==="PK"?", primary key":g.key==="FK"?", foreign key":"",g.ref?[", references ",o(`${g.ref.table}.${g.ref.column}`)]:g.type?`, ${g.type}`:"")),...u.more?[w("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return p}function Wt(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&vt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.`}function It(t,e=!1){return[{keys:e&&t.type!=="sequence"&&vt(t)&&t.cols>1&&t.rows>1?["←","↑","↓","→"]:["←","→"],words:we(t)},{keys:["Home","End"],words:"the ends"},{keys:["Esc"],words:"clear"}]}var Be=(t,e)=>{for(let n=0;n({col:t.type==="sequence"?e.i+1:e.col,rows:[e.row,e.row2]});function vt(t){return yt(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...Te(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",f=a==="right"||a==="down",p=$=>i?[$.col,$.col]:$.rows,u=$=>i?$.rows:[$.col,$.col],g=p(o),c=u(o);let m=null;return e.forEach(($,l)=>{if($===o)return;const h=p($),b=u($),q=f?h[0]-g[1]:g[0]-h[1];if(q<1)return;const L=Math.max(0,b[0]-c[1],c[0]-b[1]),C=[L===0?0:1,L===0?q:q+2*L,L,Math.abs(b[0]-c[0]),l];(!m||Be(C,m.rank))&&(m={id:$.id,rank:C})}),m?.id??null},s=ft();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const f of Object.values(s[i.pop()]))f&&!a.has(f)&&(a.add(f),i.push(f));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var Dt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Gt(t,e,n){const s=n.prefix,r=ke(n.base),o=t.type==="sequence"||t.type==="schema"?null:Rt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",f=gt(t,e),p=t.type==="sequence"||t.type==="schema"?i:!0,u=`h${t.heading}`,g=[`--_cols:${Lt(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const c=t.type==="architecture"?t.groups.flatMap(l=>l.members.map(h=>t.byId.get(h))):[],m=(l,h,b)=>l?`var(--basalt-space-${h})`:b?`var(--basalt-space-${b})`:"0px",$=i&&e.pad?"3":void 0;g.push(`--_gpad:${m(c.some(l=>l.row===1),"8",$)} ${m(c.some(l=>l.col===t.cols),"4")} ${m(c.some(l=>l.row2===t.rows),"4",$)} ${m(c.some(l=>l.col===1),"4")}`)}return Dt(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),w("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Lt(t),"data-reach":t.type==="architecture"?Tt(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},w("div",{class:`${s}-head`},w(u,{id:r.title,class:`${s}-title`},t.title),n.hasSource?w("p",{class:`${s}-source`},{slot:"source"}):null),w("div",{class:`${s}-drawing`,role:p?"group":void 0,"aria-roledescription":p?"diagram":void 0,"aria-labelledby":p?r.title:void 0,"aria-describedby":p?f?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":f?"":void 0},Oe(a,t,e),w("div",{class:`${s}-ink`,"aria-hidden":"true"}),w("span",{class:`${s}-ruler`,"aria-hidden":"true"})),zt(s,t),w("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),w("div",{class:`${s}-foot`},{slot:"toggle"}),w("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Nt(s,t)),w("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Wt(t,i)} ${n.viewer}`:Wt(t,i)),w("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Re(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4)}}var kt=(t,e)=>t==="main"?e.line:e.hair,dt=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Kt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,f=(r+a)/2,p=(o-s)/2,u=(a-r)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const $=n,l=u*Math.max(0,1-Math.abs($-i)/p);return{x:$,y:e==="top"?f-l:f+l}}const c=n,m=p*Math.max(0,1-Math.abs(c-f)/u);return{x:e==="left"?i-m:i+m,y:c}}if(t.shape==="terminal"){const c=Math.min(p,u);if(g){const h=n,b=Math.min(Math.max(h,s+c),o-c),q=h-b,L=Math.abs(q)>=c?0:Math.sqrt(c*c-q*q);return{x:h,y:Math.abs(q)<1e-6?e==="top"?r:a:e==="top"?f-L:f+L}}const m=n,$=m-f,l=Math.abs($)>=c?0:Math.sqrt(c*c-$*$);return{x:e==="left"?s+c-l:o-c+l,y:m}}return g?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Fe(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,f=(r+a)/2,p=(o-s)/2,u=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/p+Math.abs(t.y-f)/u<1-n/Math.min(p,u);if(e.shape==="terminal"){const g=Math.min(p,u),c=Math.min(Math.max(t.x,s+g),o-g);return Math.hypot(t.x-c,t.y-f)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Ne(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var Mt=t=>t?t.split(/\s+/).filter(Boolean):[];function We(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const f of t.nodes){if(f.shape==="table"){for(const m of f.columns??[]){const $=m.ref?`→ ${m.ref.table}`:m.type??"",l=s("6")+n(m.name,"mono")+($?s("3")+n($,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(l))}o=Math.max(o,Math.ceil(n(f.name,"table")+2*s("3")+2*e.hair));continue}const p=f.shape==="terminal"?2*s("5"):2*s("3"),u=f.mark&&!He()?s("6"):0;let g=0;for(const m of Mt(f.name))g=Math.max(g,n(m,f.shape==="decision"?"name-500":"name")+(f.kind?0:u));if(t.type!=="data-flow")for(const m of Mt(f.kind))g=Math.max(g,n(m,"mono")+u);for(const m of Mt(f.detail))g=Math.max(g,n(m,f.mono?"mono":"sans"));const c=f.shape==="decision"?g/.62:g+p+2*e.hair;r=Math.max(r,Math.ceil(c))}const a=Lt(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(Dt(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Tt(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function Zt(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Ot(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Ut(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const f=r[r.length-2];if(Math.abs(f.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(f.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ht=t=>t.slice(1).map((e,n)=>[t[n],e]);function St(t,e,n){const s=[];for(let o=0;oMath.min(l.x,h.x)+.75&&LMath.min(b.y,q.y)+.75&&Cr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let f=o;for(const p of r)i.push([f,f+p]),f+=p+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var Y=t=>t==="left"||t==="right",Jt={top:"bottom",bottom:"top",left:"right",right:"left"};function Ge(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Ke(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),f=t.byId.get(o.to),[p,u]=e[a],g=i.row===f.row&&Y(p)&&Y(u)&&p===Jt[u]||i.col===f.col&&!Y(p)&&!Y(u)&&p===Jt[u];s.push({edge:a,end:"from",node:i,side:p,far:f,straight:g,f:.5},{edge:a,end:"to",node:f,side:u,far:i,straight:g,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=l=>Y(l.side)?l.far.row-l.node.row:l.far.col-l.node.col,f=a.filter(l=>l.straight),p=a.filter(l=>!l.straight);if(p.sort((l,h)=>i(l)-i(h)||(Y(l.side)?l.far.col-h.far.col:l.far.row-h.far.row)*(i(l)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!f.length){p.length===2?(p[0].f=.25,p[1].f=.75):p.length===3?(p[0].f=.25,p[1].f=.5,p[2].f=.75):p.length>3&&p.forEach((l,h)=>{l.f=(h+1)/(p.length+1)});continue}const u=new Map;for(const l of f)u.has(l.far.id)||u.set(l.far.id,[]),u.get(l.far.id).push(l);for(const l of u.values())l.length>1&&l.sort((h,b)=>h.edge-b.edge).forEach((h,b)=>{h.f=l.length===2?b===0?.25:.75:(b+1)/(l.length+1)});const g=Math.min(...f.map(l=>l.f)),c=Math.max(...f.map(l=>l.f)),m=p.filter(l=>i(l)<0),$=p.filter(l=>i(l)>=0);m.forEach((l,h)=>{l.f=g*(h+1)/(m.length+1)}),$.forEach((l,h)=>{l.f=c+(1-c)*(h+1)/($.length+1)})}return s}function Xt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return Y(e)?lt(t,e,r+(a-r)*n):lt(t,e,s+(o-s)*n)}function Yt(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:dt(o,n),shape:a.shape,i:a.i})}),r}function Qt(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var Pt=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function te(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function Ve(t,e,n,s,r,o,a,i,f){const p=a.space,u=[],g=[],c=[],m=[],$=p("1"),l=e.filter(h=>t.edges[h.i]?.label).sort((h,b)=>+(t.edges[b.i].kind==="main")-+(t.edges[h.i].kind==="main")||h.i-b.i);for(const h of l){const b=t.edges[h.i].label,q=i(b,"label"),L=16,C=h.pts.length-2,j=[];ht(h.pts).forEach(([k,D],E)=>{const x=Math.abs(k.y-D.y)<.01,R=x?k.x:k.y;let d=x?D.x:D.y;const y=Math.sign(d-R)||1;E===C&&(d-=y*a.head);let M=[[R,d]];for(const T of r)for(const V of x?[T.l,T.r]:[T.t,T.b]){const v=x?k.y:k.x;(x?v>T.t&&vT.l&&vV>Math.min(I,S)+1&&V{const v=(T+V)/2,O=x?{x:v,y:k.y}:{x:k.x,y:v};return!r.some(I=>O.x>I.l&&O.xI.t&&O.y1&&B(T,V)?1:0})}),j.sort((k,D)=>D.pri-k.pri||D.len-k.len);let F=null,Q=!1;const A=(k,D=!0)=>{const E=Kt(k,$);return D&&(k.lo.r||k.to.b)||n.some(x=>Vt(E,x))||u.some(x=>ut(E,x))||s.heads.some(x=>ut(E,x))||s.rects.some(x=>ut(E,x))?!1:!e.some(x=>x.i!==h.i&&ht(x.pts).some(([R,d])=>ut(E,Pt(R,d,x.width))))};for(const k of j){for(const D of[1/2,1/3,2/3]){const E=k.p+(k.q-k.p)*D,x=[],R=p("2")+h.width/2;if(k.horiz?(k.len>=q+2*p("1")+p("3-5")&&x.push({box:{l:E-q/2-p("1"),r:E+q/2+p("1"),t:k.c-L/2,b:k.c+L/2},on:!0}),x.push({box:{l:E-q/2,r:E+q/2,t:k.c-R-L,b:k.c-R},on:!1}),x.push({box:{l:E-q/2,r:E+q/2,t:k.c+R,b:k.c+R+L},on:!1})):(k.len>=L+p("3")&&x.push({box:{l:k.c-q/2-p("1"),r:k.c+q/2+p("1"),t:E-L/2,b:E+L/2},on:!0}),x.push({box:{l:k.c+R,r:k.c+R+q,t:E-L/2,b:E+L/2},on:!1}),x.push({box:{l:k.c-R-q,r:k.c-R,t:E-L/2,b:E+L/2},on:!1})),F=x.find(d=>A(d.box))??null,F)break;!Q&&x.some(d=>A(d.box,!1))&&(Q=!0)}if(F)break}if(!F){c.push(h.i),Q&&m.push(h.i);continue}const K=te(F.box,f.ox,f.oy,k=>A(k));u.push(K),g.push({i:h.i,text:b,box:K,on:F.on})}return{labels:g,unseated:c,bounded:m}}function ee(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=dt(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const f=a.querySelector(`:scope > .${n}-glabel`);f&&f.getClientRects().length&&r.push(dt(f,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const f=dt(a,e);i>0&&r.push({l:f.l,r:f.r,t:f.t-s/2-.5,b:f.t-s/2+.5});const p=a.querySelector(`.${n}-lane-name`);p&&r.push(dt(p,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function Ze(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:f}=t,p=r.space,u=Yt(s,a,i,o),g=[...u.values()],c=De(a),m=i.left-Math.floor(i.left),$=i.top-Math.floor(i.top),l=Zt(m,$),h=a.clientWidth,b=a.clientHeight,q=v=>s.type==="data-flow"?v.col+1:v.col,L=parseFloat(getComputedStyle(a).rowGap)||0,C={w:h,h:b,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:m,oy:$};if(s.type==="sequence")return Je(t,C,l);let j,F=[];s.type==="schema"?j=s.edges.map(v=>{const O=s.byId.get(v.from),I=s.byId.get(v.to);if(O.col===I.col){const S=O.col===s.cols&&s.cols>1?"left":"right";return[S,S]}return I.col>O.col?["right","left"]:["left","right"]}):(j=s.edges.map(v=>{const O=s.byId.get(v.from),I=s.byId.get(v.to),[S,_]=Ge(O,I);return[v.fromSide??S,v.toSide??_]}),F=Ke(s,j,f||(()=>{})));const Q=(v,O)=>{const I=a.querySelector(`.${o}-node[data-node="${CSS.escape(v)}"] .${o}-row[data-row="${O}"]`);if(!I)return 0;const S=dt(I,i);return(S.t+S.b)/2},A=s.edges.map((v,O)=>{const[I,S]=j[O],_=u.get(v.from),z=u.get(v.to),Z=kt(v.kind,r);if(v.fk){const U=Q(v.from,v.fromRow),et=Q(v.to,v.toRow),J=l.y(U,Z),nt=l.y(et,Z);return{p1:{x:I==="right"?_.rect.r:_.rect.l,y:J},p2:{x:S==="right"?z.rect.r:z.rect.l,y:nt},r1:U,r2:Math.abs(J-nt)<.01?U:et}}const P=F.find(U=>U.edge===O&&U.end==="from").f,X=F.find(U=>U.edge===O&&U.end==="to").f;let W=Xt(_,I,P),G=Xt(z,S,X);const st=Y(I)?W.y:W.x;let tt=Y(S)?G.y:G.x;return Y(I)?W={...W,y:l.y(W.y,Z)}:W={...W,x:l.x(W.x,Z)},Y(S)?G={...G,y:l.y(G.y,Z)}:G={...G,x:l.x(G.x,Z)},Y(I)&&Y(S)&&Math.abs(W.y-G.y)<1.01&&(G={...G,y:W.y},tt=st),!Y(I)&&!Y(S)&&Math.abs(W.x-G.x)<1.01&&(G={...G,x:W.x},tt=st),W=Y(I)?lt(_,I,W.y):lt(_,I,W.x),G=Y(S)?lt(z,S,G.y):lt(z,S,G.x),{p1:W,p2:G,r1:st,r2:tt}}),K=new Set;s.type==="schema"&&s.edges.forEach((v,O)=>{Math.abs(s.byId.get(v.from).col-s.byId.get(v.to).col)>1&&K.add(O)});const k=new Map,D=new Set;s.edges.forEach((v,O)=>{if(K.has(O))return;const[I,S]=j[O],{p1:_,p2:z}=A[O],Z=s.byId.get(v.from),P=s.byId.get(v.to);let X=null,W=null,G=!1;if(I===S){if(Y(I)){const U=I==="right"?Math.max(q(Z),q(P)):Math.min(q(Z),q(P))-1,et=c.cols[U-1],J=c.cols[U];et&&J&&(X=`c${U}`,W=[et[1],J[0]],G=!0)}else{const U=I==="bottom"?Math.max(Z.row2,P.row2):Math.min(Z.row,P.row)-1,et=c.rows[U-1],J=c.rows[U];et&&J&&(X=`r${U}`,W=[et[1],J[0]],G=!1)}X&&D.add(O)}else if(Y(I)&&Y(S)&&Math.abs(_.y-z.y)>.5){const U=q(P),et=S==="left",J=c.cols[(et?U-1:U)-1],nt=c.cols[(et?U:U+1)-1];J&&nt&&(X=`c${et?U-1:U}`,W=[J[1],nt[0]],G=!0)}else if(!Y(I)&&!Y(S)&&Math.abs(_.x-z.x)>.5){const et=S==="top"?P.row-1:P.row2,J=c.rows[et-1],nt=c.rows[et];J&&nt&&(X=`r${et}`,W=[J[1],nt[0]],G=!1)}if(!X||!W)return;k.has(X)||k.set(X,{span:W,vertical:G,members:new Map});const st=`${v.to}.${S}.${Math.round(G?z.y:z.x)}`,tt=k.get(X);tt.members.has(st)||tt.members.set(st,[]),tt.members.get(st).push(O)});const E=new Map,x=v=>{const[O,I]=j[v],{p1:S,p2:_}=A[v];if(Y(O)&&Y(I)){if(O===I){const Z=E.get(v)??(O==="right"?Math.max(S.x,_.x)+p("4"):Math.min(S.x,_.x)-p("4"));return[S,{x:Z,y:S.y},{x:Z,y:_.y},_]}if(Math.abs(S.y-_.y)<=.5)return[S,{x:_.x,y:S.y}];const z=E.get(v)??(S.x+_.x)/2;return[S,{x:z,y:S.y},{x:z,y:_.y},_]}if(!Y(O)&&!Y(I)){if(O===I){const Z=E.get(v)??(O==="bottom"?Math.max(S.y,_.y)+p("4"):Math.min(S.y,_.y)-p("4"));return[S,{x:S.x,y:Z},{x:_.x,y:Z},_]}if(Math.abs(S.x-_.x)<=.5)return[S,{x:S.x,y:_.y}];const z=E.get(v)??(S.y+_.y)/2;return[S,{x:S.x,y:z},{x:_.x,y:z},_]}return Y(O)?[S,{x:_.x,y:S.y},_]:[S,{x:S.x,y:_.y},_]},R=v=>{const O=s.edges[v],I=kt(O.kind,r),S=x(v),_=Ut(S,I,l);let z;return S.length===_.length&&(z=ht(S).map(([Z,P])=>Math.abs(Z.y-P.y)<.75?(Z.y+P.y)/2:(Z.x+P.x)/2),z[0]=A[v].r1,z.length>1&&(z[z.length-1]=A[v].r2)),{i:v,from:O.from,to:O.to,kind:O.kind,pts:_,tip:_[_.length-1],dir:Ot(_),dot:O.fk?_[0]:void 0,width:I,axes:z}},d=()=>s.edges.flatMap((v,O)=>K.has(O)?[]:[R(O)]);let y=null;const M=v=>{y??(y=d());const O=y.map(I=>v.has(I.i)?R(I.i):I);return{lines:O,score:Ue(O,v)*1e5+St(O,void 0,v).length*1e3+_t(O.filter(I=>v.has(I.i)),g,s).length}},B=(v,O)=>{const I=v.flatMap(S=>{const{p1:_,p2:z}=A[S];return O?[_.y,z.y]:[_.x,z.x]});return[Math.min(...I),Math.max(...I)]};for(const[,v]of k){const O=[...v.members.values()].map(S=>({members:S,run:B(S,v.vertical)})).sort((S,_)=>S.run[0]-_.run[0]),I=[];for(const S of O){const _=I[I.length-1];_&&_.some(z=>z.run[0]D.has(st)))continue;const _=S.map(st=>st.members),z=_.length,Z=(v.span[1]-v.span[0])/(z+1);ZU.forEach(J=>E.set(J,v.span[0]+Z*(et+1))));const tt=M(P);tt.scorest.forEach(U=>E.set(U,v.span[0]+Z*(tt+1)))),y=G}}C.lines=d();for(const v of K)f?.(`${s.edges[v].from} to ${s.edges[v].to} is two columns apart, so its line is not drawn; its row still writes the target`);C.crossings=St(C.lines),C.through=_t(C.lines,g,s),C.outside=se(C.lines,h,b,r);const{obstacles:H,groups:T}=ee(a,i,o,L);H.heads=C.lines.map(v=>Qt(v,r));const V=Ve(s,C.lines,g,H,T,{l:0,t:0,r:h,b},r,e,{ox:m,oy:$});return C.labels=V.labels,C.unseated=V.unseated,C.bounded=V.bounded,C.overlaps=[...new Set(ne(C.lines,null).flat())],C}function Ue(t,e){return ne(t,e).length}function ne(t,e){const n=[];for(let s=0;s=i)continue;const[h,b]=c?[f.x,p.x]:[f.y,p.y],[q,L]=c?[u.x,g.x]:[u.y,g.y];Math.min(Math.max(h,b),Math.max(q,L))-Math.max(Math.min(h,b),Math.min(q,L))>1&&n.push([o.i,a.i])}}return n}function*oe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const f=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-f<-.5||a.x+f>e+.5||a.y-f<-.5||a.y+f>n+.5})&&r.push(o.i);return r}function _t(t,e,n){const s=[];for(const r of t){const o=ht(r.pts);e.some(a=>o.some(([i,f])=>ze(i,f,a)))&&s.push(r.i)}return s}function Je(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,f=r.space,p=new Map;a.querySelectorAll(`.${o}-node`).forEach($=>p.set($.dataset.node,dt($,i)));const u=a.querySelector(`.${o}-steps`),g=u?dt(u,i).b:e.h,c=$=>{const l=p.get($);return l?n.x((l.l+l.r)/2,r.hair):0};for(const $ of s.nodes){const l=p.get($.id);l&&e.lifelines.push({x:c($.id),y1:l.b,y2:g})}const m=$=>p.get($.id);return a.querySelectorAll(`.${o}-msg`).forEach($=>{const l=$.dataset.from,h=$.dataset.to,b=$.dataset.kind??"plain",q=kt(b,r),L=dt($,i),C=n.y((L.t+L.b)/2,q),j=Number($.querySelector(`.${o}-num`)?.textContent??0),F=c(l),Q=c(h);let A;if(l===h){const d=$.dataset.self==="start"?-f("6"):f("6"),y=n.y(C-f("2"),q),M=n.y(C+f("2"),q);A=[{x:F,y},{x:n.x(F+d,q),y},{x:n.x(F+d,q),y:M},{x:F,y:M}]}else A=[{x:F,y:C},{x:Q,y:C}];e.lines.push({i:j,from:l,to:h,kind:b,pts:A,tip:A[A.length-1],dir:Ot(A),width:q});const K=$.querySelector(`.${o}-said`),k=$.querySelector(`.${o}-note`),D=s.byId.get(l),E=s.byId.get(h);if(!D||!E)return;const x=l===h?(()=>{const d=s.nodes[D.i+($.dataset.self==="start"?-1:1)],y=d?c(d.id):$.dataset.self==="start"?0:e.w;return Math.abs(y-F)-f("6")-f("2-5")-f("2")})():Math.abs(Q-F)-2*f("2");Math.max(K?K.getBoundingClientRect().width:0,k?k.getBoundingClientRect().width:0)>x+.5&&e.unseated.push(j)}),e}function ae(t,e,n,s=ft()){const{m:r,tk:o,P:a,drawing:i,origin:f}=t,p=o.space,u=Yt(r,i,f,a),g=[...u.values()],c=f.left-Math.floor(f.left),m=f.top-Math.floor(f.top),$=Zt(c,m),l=i.clientWidth,h=i.clientHeight,b={w:l,h,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:m},q=ft();if(r.type==="sequence"||r.type==="schema")return{geo:b,grow:q};const L=l-(parseFloat(getComputedStyle(i).paddingRight)||0),C=(x,R,d)=>{const y=[x];for(let M=1;M<=(pt(s,R)??0);M++)y.push({...x,t:x.t+d*p("4")*M,b:x.b+d*p("4")*M});return y},j=new Map;i.querySelectorAll(`.${a}-node`).forEach(x=>{const R=x.parentElement,d=dt(R,f),y=getComputedStyle(R);j.set(x.dataset.node,d.r-(parseFloat(y.paddingRight)||0)-(parseFloat(y.borderRightWidth)||0))});const F=r.nodes,Q=x=>u.get(F[x].id),A=[],K=x=>kt(r.edges[x].kind,o);r.edges.forEach((x,R)=>{const d=n.routes[R],y=u.get(x.from),M=u.get(x.to),B=K(R);let H=[];const T=x.label,V=T?e(T,"label"):0,v=16,O=p("4");if(d==="down"||d==="up"){const S=Math.max(y.rect.l,M.rect.l),_=Math.min(y.rect.r,M.rect.r),z=r.edges.map((W,G)=>({o:W,j:G})).filter(({o:W,j:G})=>(n.routes[G]==="down"||n.routes[G]==="up")&&(W.from===x.from&&W.to===x.to||W.from===x.to&&W.to===x.from)),Z=z.findIndex(W=>W.j===R),P=z.length<2?.5:z.length===2?Z===0?.25:.75:(Z+1)/(z.length+1),X=$.x(S+(_-S)*P,B);if(H=d==="down"?[lt(y,"bottom",X),lt(M,"top",X)]:[lt(y,"top",X),lt(M,"bottom",X)],T){let W=Math.min(H[0].y,H[1].y),G=Math.max(H[0].y,H[1].y);d==="down"?G-=o.head:W+=o.head;const st=[...i.querySelectorAll(`.${a}-group`)].map(J=>dt(J,f));let tt=[[W,G]];for(const J of st)for(const nt of[J.t,J.b])tt=tt.flatMap(([at,N])=>nt>at+1&&ntst.some(at=>(J+nt)/2>at.t&&(J+nt)/2at.l&&X1){const J=tt.filter(([at,N])=>!U(at,N));[W,G]=(J.length?J:tt).reduce((at,N)=>N[1]-N[0]>at[1]-at[0]?N:at)}const et=[1/2,1/3,2/3].map(J=>{const nt=W+(G-W)*J;return{l:X-V/2-p("1"),r:X+V/2+p("1"),t:nt-v/2,b:nt+v/2}});A.push({k:R,cands:et,on:!0,card:d==="down"?x.to:x.from})}}else if(d==="trunk"||d==="rail"){const S=$.x(Math.max(y.rect.l,d==="rail"?M.rect.l:y.rect.l)+p(d==="trunk"?"8":"3"),B),_=lt(y,"bottom",S);if(d==="rail"){if(H=[_,lt(M,"top",S)],T){const z=M.rect.t-p("6");A.push({k:R,cands:C({l:S+p("2-5"),r:S+p("2-5")+V,t:z-v/2,b:z+v/2},x.to,-1),on:!1,card:x.to})}}else{const z=$.x(M.rect.l+p("6"),B),Z=$.y(M.rect.t-O,B);H=[_,{x:S,y:Z},{x:z,y:Z},lt(M,"top",z)],T&&A.push({k:R,cands:C({l:z+p("2-5"),r:z+p("2-5")+V,t:Z-v/2,b:Z+v/2},x.to,-1),on:!1,card:x.to})}}else{const S=Math.min(j.get(x.from)??l,j.get(x.to)??l),_=$.x(n.gutter?L+(n.lanes[R]?2*p("3-5"):p("3-5")):S-p("2-5"),B),z=$.y(y.rect.t+(y.rect.b-y.rect.t)*n.exits[R],B),Z=lt(y,"right",z),P=$.x(M.rect.r-p("6"),B),X=d==="end-down",W=$.y(X?M.rect.t-O:M.rect.b+O,B);H=[Z,{x:_,y:Z.y},{x:_,y:W},{x:P,y:W},lt(M,X?"top":"bottom",P)];const G=X?x.to:F[M.i+1]?.id??x.to;T&&A.push({k:R,cands:C({l:P-p("2-5")-V,r:P-p("2-5"),t:W-v/2,b:W+v/2},G,X?-1:1),on:!1,card:G})}const I=Ut(H,B,$);b.lines.push({i:R,from:x.from,to:x.to,kind:x.kind,pts:I,tip:I[I.length-1],dir:Ot(I),width:B})}),b.crossings=St(b.lines),b.through=_t(b.lines,g,r),b.outside=se(b.lines,l,h,o);const{obstacles:k}=ee(i,f,a,0);k.heads=b.lines.map(x=>Qt(x,o));const D=[],E={l:0,t:0,r:l,b:h};for(const x of A){const R=M=>{const B=Kt(M,p("1"));return M.lE.r+.5||M.tE.b+.5||g.some(H=>Vt(B,H))||D.some(H=>ut(B,H))||k.heads.some(H=>ut(B,H))||k.rects.some(H=>ut(B,H))||b.lines.some(H=>H.i!==x.k&&ht(H.pts).some(([T,V])=>ut(B,Pt(T,V,H.width))))},d=x.cands.find(M=>!R(M));d||(q[x.card]=(q[x.card]??0)+1,b.unseated.push(x.k));const y=d?te(d,c,m,M=>!R(M)):x.cands[0];D.push(y),b.labels.push({i:x.k,text:r.edges[x.k].label,box:y,on:x.on})}return{geo:b,grow:q}}function Xe(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...C})),g=u[u.length-1];g.x-=o.x*p,g.y-=o.y*p;const c=e.tip.x-o.x*i,m=e.tip.y-o.y*i,$=-o.y*f,l=o.x*f,h=C=>Math.round(C*100)/100,b=it(e.kind),q=a?``:``,L=e.dot?``:"";return`${q}${L}`}function re(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,f]of o){const p=`${s}-cut-${i}`;r.set(i,p);const u=f.map(g=>{const c=e.lines[g.top],m=e.lines[g.under],$=c.width/2+n.cut,l=m.width/2+1;return g.underVertical?``:``}).join("");a+=`${u}`}return{defs:a,ids:r}}function ie(t,e,n,s){const{defs:r,ids:o}=re(t,e,n,s),a=e.lifelines.map(u=>``).join(""),i=e.lines.map((u,g)=>Qe(t,u,n,o.get(g)??null,u.from===u.to?n.radiusXs:n.radius)).join(""),f=`${r?`${r}`:""}${a}${i}`,p=e.labels.map(u=>`${it(u.text)}`).join("");return f+p}function le(t,e,n,s,r,o,a,i){const p=t.querySelector(`.${n}-drawing`);if(!p||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const u=Re(t),g=Ne(p,n),c=We(e,u,g);i?.(c.least);const m=t.clientWidth,$=(()=>{const k=document.activeElement;return k&&p.contains(k)&&k.dataset.node?k.dataset.node:void 0})(),l=k=>gt(e,k)?{...k,stop:k.stop&&e.byId.has(k.stop)?k.stop:e.nodes[0]?.id,keep:void 0}:{...k,stop:k.stop??e.nodes[0]?.id,keep:$&&k.layout!=="drawn"?$:void 0};let h=!1;const b=k=>{if(h=!1,e.type!=="flowchart")return k;o({...k,heights:void 0,words:void 0});const D=ft(),E=ft();return p.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const R=x.querySelector(`.${n}-words`);if(!R)return;const d=x.getBoundingClientRect(),y=H=>{const T={w:H.width+2*u.space("2-5"),h:H.height+2*u.space("2")},V=1-T.w/d.width,v=V>.05?T.h/2/V:T.h*10;return Math.max(u.space("16"),Math.ceil(d.width/5),Math.ceil(2*v))},M=R.getBoundingClientRect();let B=y(M);if(B>d.width){const H=O=>(x.style.setProperty("--_ww",`${O}px`),R.getBoundingClientRect()),T=Math.floor(x.clientWidth-2*u.space("2-5"));let V=Math.ceil(M.width),v=M.height;for(;V1;){const z=O+I>>1;H(z).heightd.width&&(h=!0)}),{...k,heights:D,words:Object.keys(E).length?E:void 0}},q=()=>({m:e,tk:u,P:n,drawing:p,origin:p.getBoundingClientRect(),warn:a}),L=r.autoOpen?{open:!1,autoOpen:void 0}:{},C=(k,D)=>D.map(E=>wt(e,k.lines.find(x=>x.i===E))).join(", ");if(m>=c.least){const k=R=>{let d=l({...r,...L,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:R||void 0});return d=b(d),o(d),{dd:d,g:Ze(q(),g)}};let{dd:D,g:E}=k(!1);const x=R=>R.through.length>0||R.outside.length>0||(R.overlaps?.length??0)>0||h;if(!x(E)&&E.unseated.length&&E.unseated.every(R=>E.bounded?.includes(R))){const R=k(!0);!x(R.g)&&!R.g.unseated.length&&({dd:D,g:E}=R)}if(!x(E)&&!E.unseated.length)return E.crossings.length&&a?.(`${E.crossings.length} crossing${E.crossings.length===1?"":"s"} in the drawn layout: ${E.crossings.map(R=>`${wt(e,E.lines[R.top])} over ${wt(e,E.lines[R.under])}`).join("; ")}`),{dyn:D,geo:E,ink:ie(n,E,u,s),tokens:u,least:c.least};h&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: a decision would be taller than it is wide`),E.through.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${C(E,E.through)} would pass through a node`),E.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${C(E,E.overlaps)} would lie on one another`),E.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${C(E,E.outside)} would leave the drawing`),E.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: no clean seat for ${E.unseated.map(R=>e.type==="sequence"?`message ${R}`:`"${e.edges[R]?.label}"`).join(", ")}`)}let j=l({...r,...L,layout:"stacked",heights:void 0,grow:ft(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(j=b(j),o(j),e.type==="sequence"||e.type==="schema")return{dyn:j,geo:null,ink:"",tokens:u,least:c.least};const F=Rt(e);let Q=ae(q(),g,F,j.grow);for(let k=0;k<6&&Object.keys(Q.grow).length;k++){const D=ft(j.grow);for(const[E,x]of Object.entries(Q.grow))D[E]=(pt(D,E)??0)+x;j={...j,grow:D},o(j),Q=ae(q(),g,F,D)}const A=Q.geo;if(A.unseated.length>0||A.through.length>0||A.outside.length>0||F.third){A.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(A.unseated)].map(E=>`"${e.edges[E]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),A.through.length&&a?.(`in the stacked drawing ${C(A,A.through)} would pass through a node, so its lines are not drawn`),A.outside.length&&a?.(`in the stacked drawing ${C(A,A.outside)} would leave the drawing, so its lines are not drawn`),F.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const k={...A,lines:[],labels:[],crossings:[]};return{dyn:l({...j,grow:ft(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:k,ink:"",tokens:u,least:c.least}}return A.crossings.length&&a?.(`${A.crossings.length} crossing${A.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${A.crossings.map(k=>`${wt(e,A.lines[k.top])} over ${wt(e,A.lines[k.under])}`).join("; ")}`),{dyn:j,geo:A,ink:ie(n,A,u,s),tokens:u,least:c.least}}function wt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Pe(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const l of n?.lines??[])l.from===o&&a.add(l.to),l.to===o&&a.add(l.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(l=>l.toggleAttribute("data-near",a.has(l.dataset.node))),!n||!s)return;const i=l=>!!o&&(l.from===o||l.to===o),f=t.querySelector(`.${e}-edges`),p=new Map;t.querySelectorAll(`.${e}-edge`).forEach(l=>p.set(l.getAttribute("data-edge"),l));for(const l of n.lines){const h=p.get(String(l.i));h&&(h.toggleAttribute("data-lit",i(l)),h.toggleAttribute("data-dim",!!o&&!i(l)))}if(t.querySelectorAll(`.${e}-label`).forEach(l=>{const h=n.lines.find(b=>String(b.i)===l.dataset.edge);l.toggleAttribute("data-lit",!!(h&&i(h)))}),f){for(const l of n.lines)if(i(l)){const h=p.get(String(l.i));h&&f.appendChild(h)}}const u=St(n.lines,i),{defs:g,ids:c}=re(e,{...n,crossings:u},s,r),m=t.querySelector(`.${e}-svg`);if(!m)return;let $=m.querySelector("defs");!$&&g&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),m.insertBefore($,m.firstChild)),$&&($.innerHTML=g),n.lines.forEach((l,h)=>{const b=p.get(String(l.i))?.querySelector(`.${e}-line`);if(!b)return;const q=c.get(h);q?b.setAttribute("mask",`url(#${q})`):b.removeAttribute("mask")})}var tn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function en(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",tn()?"done":"pending")}}function ce(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function nn(t,e,n,s=!1,r=!1){const o=s?vt(t):null;if(o&&n.startsWith("Arrow")){const p={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return p?o[e]?.[p]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let f;if(n==="ArrowRight"||n==="ArrowDown")f=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")f=a-1;else if(n==="Home")f=0;else if(n==="End")f=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,f))].id}var on=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],de=["data-layout","data-measured","data-bare","data-motion"],sn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ue=t=>t==null||t===!1;function an(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function fe(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?de:on;for(const a of s)ue(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const p=t.style,u=new Map(String(i??"").split(";").map(g=>{const c=g.indexOf(":");return[g.slice(0,c).trim(),g.slice(c+1).trim()]}).filter(([g])=>g));for(const[g,c]of u)p.getPropertyValue(g).trim()!==c&&p.setProperty(g,c);for(const g of sn)u.has(g)||p.removeProperty(g);continue}if(n&&!de.includes(a))continue;if(ue(i)){t.removeAttribute(a);continue}const f=i===!0?"":String(i);t.getAttribute(a)!==f&&t.setAttribute(a,f)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(c,m,$){return{prefix:n,base:c,hasSource:m.source!==void 0&&m.source!==null&&m.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(c,m,$,l){var h=function(b){return''+it(b)+""};return{source:it(String(m.source||"")),summary:it(String(m.summary||"")),hint:It(c).map(function(b){return""+b.keys.map(h).join(" ")+" "+it(b.words)+""}).join(""),toggle:'"}}function a(c,m,$){var l=At(c),h=Gt(l,{},r(m,c,$)),b=Et(h,o(l,c,m,!1)),q=b.indexOf(">");return{open:b.slice(0,q+1),inner:b.slice(q+1,b.length-9),warnings:l.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],f=["--_cols","--_gpad","--_track"];function p(c,m,$,l){c.__diagram&&c.__diagram.stop();var h=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),b=At(m);if(!$||!h||!c.querySelector(":scope > .diagram-drawing")){if(!h||!c.querySelector("#"+CSS.escape(h+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););h="dg"+s}var q=a(m,h,l),L=document.createElement("div");L.innerHTML=q.open+"";var C=L.firstChild;i.forEach(function(N){c.removeAttribute(N)}),f.forEach(function(N){c.style.removeProperty(N)});for(var j=0;j :not(script[data-diagram])").forEach(function(N){N.remove()}),c.insertAdjacentHTML("beforeend",q.inner)}b.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var Q=r(h,m,l),A={},K=null,k=null,D=null,E=Object.create(null),x=function(N){E[N]||(E[N]=1,console.warn("Basalt diagram: "+N))},R=function(N){fe(c,Gt(b,N,Q))},d=c.querySelector(".diagram-ink"),y=c.querySelector(".diagram-toggle"),M=!l&&b.motion.animated&&typeof e.diagramMotion=="function",B=null,H=null,T=function(){M&&ce(c)};function V(){Pe(c,n,K&&K.geo,K&&K.tokens,h,k||D)}function v(){y&&(y.setAttribute("aria-expanded",String(!!A.open)),y.firstElementChild.textContent=A.open?"Hide the list":"View as list")}function O(){K=(l?l.measure:le)(c,b,n,h,A,R,x),A=K.dyn,R(A),v();var N=c.querySelector(":scope > .diagram-hint");if(N){var ot=It(b,A.layout==="drawn").map(function(xt){return""+xt.keys.map(function(ln){return''+it(ln)+""}).join(" ")+" "+it(xt.words)+""}).join("");N.innerHTML!==ot&&(N.innerHTML=ot)}gt(b,A)||(D=null);var ct=d&&K.ink!==H;ct&&(d.innerHTML=K.ink,H=K.ink),V(),M&&K.tokens&&(en(c,!!(K.geo&&K.geo.lines.length)),ct&&B&&B.redrawn()),l&&l.onMeasured&&K.tokens&&l.onMeasured(K,c)}function I(N){A=N,R(A)}function S(N){var ot=A.stop;A=Object.assign({},A,{stop:N}),rn(c,n,ot,N)}var _=function(N){var ot=N&&N.closest?N.closest(".diagram-node"):null;return ot&&c.contains(ot)?ot:null};function z(N){var ot=_(N.target);if(!(!ot||N.defaultPrevented)){if(T(),N.key==="Escape"){!l&&(k||D)&&(N.preventDefault(),k=D=null,V());return}if(gt(b,A)){var ct=nn(b,ot.getAttribute("data-node"),N.key,A.layout==="drawn",getComputedStyle(ot).direction==="rtl");if(ct){N.preventDefault(),S(ct);var xt=c.querySelector('.diagram-node[data-node="'+CSS.escape(ct)+'"]');xt&&xt.focus()}}}}function Z(N){var ot=_(N.target);if(ot){T();var ct=ot.getAttribute("data-node");k=ot.matches(":focus-visible")?ct:null,gt(b,A)&&A.stop!==ct&&S(ct),V()}}function P(N){var ot=_(N.target);ot&&(_(N.relatedTarget)||(k=null),A.keep===ot.getAttribute("data-node")&&I(Object.assign({},A,{keep:void 0})),V())}function X(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var ot=_(N.target);ot&&T();var ct=ot&>(b,A)?ot.getAttribute("data-node"):null;ct!==D&&(D=ct,V())}}function W(){D&&(D=null,V())}function G(){T(),I(Object.assign({},A,{open:!A.open,autoOpen:void 0})),v()}c.addEventListener("keydown",z),c.addEventListener("focusin",Z),c.addEventListener("focusout",P),c.addEventListener("pointerover",X),c.addEventListener("pointerleave",W),y&&y.addEventListener("click",G),O();var st=c.clientWidth,tt=0,U=!0,et=new ResizeObserver(function(){Math.abs(c.clientWidth-st)<.5||(st=c.clientWidth,cancelAnimationFrame(tt),tt=requestAnimationFrame(O))});et.observe(c),document.fonts&&document.fonts.ready.then(function(){U&&O()});var J=matchMedia("(forced-colors: active)"),nt=b.nodes.some(function(N){return N.mark});nt&&J.addEventListener("change",O),M&&(B=e.diagramMotion(c,{fig:c,P:n,base:h,model:function(){return b},geo:function(){return K&&K.geo},tokens:function(){return K&&K.tokens}},m));var at=!l&&m.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,m,{model:b,settle:T,animated:M}):null;c.__diagram={stop:function(){at&&at.destroy(),U=!1,et.disconnect(),cancelAnimationFrame(tt),nt&&J.removeEventListener("change",O),B&&B.destroy(),c.removeEventListener("keydown",z),c.removeEventListener("focusin",Z),c.removeEventListener("focusout",P),c.removeEventListener("pointerover",X),c.removeEventListener("pointerleave",W),y&&y.removeEventListener("click",G)},layout:O,key:u(m),send:B&&B.sendValue?B.sendValue:null}}function u(c){try{return JSON.stringify(c,function(m,$){return m==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var m=c.querySelector(":scope > script[data-diagram]");if(m)try{p(c,JSON.parse(m.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:p,buildModel:At,figureKey:Ae,figureList:Ce,hintEntries:It,toHtml:Et,escapeHtml:it,settleEntrance:ce,measureFigure:le},t.diagram=function(c,m){var $=c.__diagram,l=$&&$.send?u(m):null;if(l!==null&&l===$.key){$.send(m.packet?m.packet.send:void 0);return}p(c,m)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); +(()=>{var ve=["top","right","bottom","left"],xe=["main","plain","dashed"],ke=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ut=t=>Object.assign(Object.create(null),t),gt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function qt(t,e={}){const s=e.checks!==!1,r=[],o=p=>{r.push(p)},a=t.legend??{},i={};for(const p of["main","plain","dashed","focal","group","activation"]){const w=at(a[p]);w&&(i[p]=w)}const d=t.stepLabel,u=typeof d=="function"?p=>String(d(p)):typeof d=="string"?(p=>d.replace("{n}",String(p))):p=>`Step ${p}`,m=t.shapeLabels??{},h={terminal:at(m.terminal)??"Start or end",step:at(m.step)??"Step",decision:at(m.decision)??"Decision"},l=t.heading===void 0?3:ke.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),y=(p,w)=>p==null?"plain":xe.includes(p)?p:(o(`"${String(p)}" is not a kind of line (main, plain or dashed): ${w} is drawn plain`),"plain"),$=p=>{if(p!=null){if(ve.includes(p))return p;o(`"${String(p)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(p,w)=>typeof p=="number"&&Number.isInteger(p)&&p>=1?p:(o(`${w} is ${JSON.stringify(p)}, not a whole number from 1: it is placed at 1`),1),f=[],v=[];let B=[];const C=[],M=[],I=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(I)||o(`"${String(I)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),I==="architecture"||I==="flowchart"){for(const p of t.nodes??[]){const w=I==="flowchart"&&p.shape==="decision"?"decision":I==="flowchart"&&p.shape==="terminal"?"terminal":"box",S=String(p.id??""),g=c(p.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(p.name??""),kind:w==="decision"?void 0:at(p.kind),detail:w==="decision"?void 0:at(p.detail),mono:!!p.detailMono,focal:!!p.focal,col:c(p.col,`the column of ${S}`),row:g,row2:g,branch:!!p.branch,shape:w,group:I==="architecture"?at(p.group):void 0,mark:I==="architecture"?It(p.mark):void 0})}if(I==="architecture"){const p=(t.groups??[]).map(b=>({id:String(b.id??""),label:String(b.label??""),parent:at(b.parent)})),w=new Map(p.map(b=>[b.id,b])),S=b=>{if(!b.parent)return 1;const x=w.get(b.parent);return x?x.parent===b.id||x.id===b.id?(o(`the groups "${b.label}" and "${x.label}" are each other's parent`),b.parent=void 0,1):x.parent?(o(`the group "${b.label}" is a third level: groups nest two deep`),b.parent=void 0,1):2:(o(`the group "${b.label}" names the parent "${b.parent}", which is not a group`),b.parent=void 0,1)},g=p.map(S);p.forEach((b,x)=>C.push({...b,depth:g[x],members:f.filter(E=>E.group===b.id).map(E=>E.id),all:[]}));for(const b of C)b.all=[...b.members,...C.filter(x=>x.parent===b.id).flatMap(x=>x.members)];C.sort((b,x)=>b.depth-x.depth)}}else if(I==="data-flow"){B=(t.lanes??[]).map(w=>({id:String(w.id??""),label:String(w.label??"")}));const p=new Map(B.map((w,S)=>[w.id,S+1]));for(const w of t.nodes??[]){const S=String(w.id??""),g=String(w.lane??""),b=p.get(g);b===void 0&&o(`a node (${S}) names the lane "${g}", which is not in lanes`);const x=f.length+1;f.push({id:S,i:f.length,name:String(w.name??""),kind:u(x),detail:at(w.detail),mono:!!w.detailMono,focal:!!w.focal,col:c(w.col,`the column of ${S}`),row:b??1,row2:b??1,branch:!1,shape:"box",lane:b??1,laneLabel:B[(b??1)-1]?.label??g,step:x,mark:It(w.mark)})}}else if(I==="sequence"){(t.participants??[]).forEach((g,b)=>{const x=String(g.name??"");f.push({id:String(g.id??""),i:b,name:x,kind:at(g.kind),mono:!1,focal:!!g.focal,col:b+1,row:1,row2:1,branch:!1,shape:"participant",short:at(g.short)??x,mark:It(g.mark)})});let p=0;const w=new Map(f.map(g=>[g.id,g.col])),S=(g,b)=>{let x=1/0,E=-1/0;for(const A of g??[]){if(!A||typeof A!="object")continue;if("band"in A){b>0&&o(`the band "${String(A.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(A.band??"")});continue}if("frame"in A){if(b>=2){o("a frame is a third level: frames nest two deep");continue}const nt=A.frame==="alt"||A.frame==="loop"||A.frame==="opt"?A.frame:"opt",et=nt==="alt"?A.branches??[]:[{label:A.label,steps:A.steps}];nt==="alt"&&et.length<2&&o("an alt frame has one branch: it needs two or more");const X=String(et[0]?.label??"");X.length>40&&o(`the frame label "${X}" is over 40 characters`);const ot=M.length;M.push({open:nt,label:X,depth:b+1,a:0,b:0}),et.forEach((Y,st)=>{if(st){const it=String(Y.label??"");it.length>40&&o(`the frame label "${it}" is over 40 characters`),M.push({otherwise:it,depth:b+1})}Y.steps?.length||o(`a frame or branch ("${String(Y.label??"")}") is empty`);const[rt,R]=S(Y.steps??[],b+1);x=Math.min(x,rt),E=Math.max(E,R);const P=M[ot];P.a=Math.min(P.a||1/0,rt),P.b=Math.max(P.b,R)}),M.push({close:b+1});continue}p++;const T=String(A.label??"");T.includes(` +`)&&o(`message ${p}'s label has a break: a message's second line is its note`);const K=String(A.from??""),Q=String(A.to??"");M.push({n:p,from:K,to:Q,label:pt(T),note:at(A.note),kind:y(A.kind,`message ${p}`),activate:A.activate===!0||void 0,deactivate:A.deactivate===!0||void 0});const J=w.get(K)??1,z=w.get(Q)??1,G=J===z?J===f.length?J-1:J+1:J;x=Math.min(x,J,z,G),E=Math.max(E,J,z,G)}return[x,E]};S(t.steps??[],0);for(const g of M)"open"in g&&!Number.isFinite(g.a)&&(g.a=1,g.b=Math.max(1,f.length))}else if(I==="schema")for(const p of t.tables??[]){const w=String(p.name??""),[S,g]=Array.isArray(p.row)?p.row:[p.row,p.row],b=c(S,`the row of ${w}`),x=Math.max(b,c(g,`the last row of ${w}`)),E=p.more===void 0||p.more===null?void 0:Number.isInteger(p.more)&&p.more>0?p.more:(o(`${w}'s "more" is ${JSON.stringify(p.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:w,i:f.length,name:w,mono:!0,focal:!!p.focal,col:c(p.col,`the column of ${w}`),row:b,row2:x,branch:!1,shape:"table",more:E,columns:(p.columns??[]).map(A=>({name:String(A.name??""),type:at(A.type),key:A.key==="PK"||A.key==="FK"?A.key:(A.key!==void 0&&A.key!==null&&o(`${w}.${String(A.name)}'s key is "${String(A.key)}", not PK or FK: it is left out`),void 0)}))})}((I==="schema"?t.tables:I==="sequence"?t.participants:t.nodes)??[]).forEach((p,w)=>{if(!p||p.href===void 0||p.href===null)return;const S=String(p.href);if(I==="sequence"){o(`${f[w]?.id}: a participant cannot be a link (href)`);return}if(!S){o(`${f[w]?.id}'s href is empty`);return}const g=f[w];g&&(g.href=S,g.blank=p.target==="_blank")});const D=new Map;for(const p of f)p.id?D.has(p.id)&&o(`the id "${p.id}" is used twice`):o("a node has no id"),D.set(p.id,p);if(I==="schema")(t.tables??[]).forEach(p=>(p.columns??[]).forEach((w,S)=>{const g=at(w.references);if(!g)return;const[b,x]=g.split("."),E=D.get(b??""),A=E?.columns?.findIndex(K=>K.name===x)??-1;if(!E||A<0){o(`${String(p.name)}.${String(w.name)} references ${g}, which is not a shown column`);return}const T=D.get(String(p.name??""));T.columns[S].ref={table:b,column:x,row:A},v.push({i:v.length,from:T.id,to:b,kind:"plain",fromRow:S,toRow:A,fk:!0})}));else if(I!=="sequence")for(const p of t.edges??[]){const w=String(p.from??""),S=String(p.to??"");if(!D.has(w)||!D.has(S)){o(`a line names ${D.has(w)?S:w}, which is not a node`);continue}const g=at(p.label),b=g?.split(` +`)??[];b.length>2&&o(`the label "${pt(g)}" has more than one break: a label is two lines at most`),b.some(x=>x.length>zt)&&o(`a line of the label "${pt(g)}" is over ${zt} characters: longer words belong in the node or the summary`),v.push({i:v.length,from:w,to:S,kind:y(p.kind,`the line from ${w} to ${S}`),label:g,fromSide:$(p.fromSide),toSide:$(p.toSide),flow:I!=="flowchart"&&p.flow===!0?!0:void 0})}else for(const p of M)"n"in p&&(!D.has(p.from)||!D.has(p.to))&&o(`message ${p.n} names ${D.has(p.from)?p.to:p.from}, which is not a participant`);if(s&&I!=="sequence"){const p=new Map;for(const w of f)for(let S=w.row;S<=w.row2;S++){const g=`${w.col}:${S}`;p.has(g)&&o(`${w.id} and ${p.get(g)} share the cell at column ${w.col}, row ${S}`),p.set(g,w.id)}}if(s){for(const w of C){const S=w.all.map(x=>D.get(x));if(!S.length)continue;const g={c1:Math.min(...S.map(x=>x.col)),c2:Math.max(...S.map(x=>x.col)),r1:Math.min(...S.map(x=>x.row)),r2:Math.max(...S.map(x=>x.row2))};for(const x of f)!w.all.includes(x.id)&&x.col>=g.c1&&x.col<=g.c2&&x.row>=g.r1&&x.row<=g.r2&&o(`${x.id} is inside the box of the group "${w.label}" but not a member`);const b=S.map(x=>x.i);Math.max(...b)-Math.min(...b)+1!==b.length&&o(`the members of the group "${w.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const w of f)w.group&&!C.some(S=>S.id===w.group)&&o(`${w.id} names the group "${w.group}", which is not in groups`);f.filter(w=>w.focal).length>1&&o("more than one node is focal: a diagram has one at most");const p=new Set(I==="sequence"?M.flatMap(w=>"n"in w?[w.kind]:[]):v.map(w=>w.kind));p.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),p.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(w=>w.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const O=I==="architecture"||I==="data-flow",V=p=>Array.isArray(p)&&p.length>1?p.map(String):void 0,q=O&&t.packet&&typeof t.packet=="object"?t.packet:void 0,W=q&&V(q.path),_={animated:t.motion==="animated",pulse:O?V(t.pulse):void 0,packet:W?{path:W,repeat:q.repeat===!0,send:q.send}:void 0,run:I==="sequence"&&t.run===!0};if(s)for(const p of f){const w=p.mark?.says;if(!w?.length)continue;const S=[p.name,p.kind,p.detail,p.laneLabel].filter(Boolean).join(" ").toLowerCase();w.some(g=>S.includes(g.toLowerCase()))||o(`${p.id}'s mark stands for ${w.join(" or ")}, and none of its words say so`)}const L=[];if(I==="sequence"){const p=new Map,w=new Map;for(const S of M)"n"in S&&(w.set(S.from,S.n),w.set(S.to,S.n));for(const S of M)if("n"in S){if(S.activate){const g=p.get(S.to)??[];if(g.length>=3)o(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const b={who:S.to,from:S.n,to:S.n,depth:g.length+1};g.push(b),L.push(b),p.set(S.to,g)}}if(S.deactivate){const b=p.get(S.from)?.pop();b?b.to=S.n:o(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,g]of p)for(const b of g)b.to=Math.max(b.from,w.get(S)??b.from)}const j=t.frameLabels??{},F={opt:at(j.opt)??"Only if",loop:at(j.loop)??"Repeats",alt:at(j.alt)??"One of these",else:at(j.else)??"Otherwise"},Z=Math.max(1,...f.map(p=>p.col)),N=I==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(p=>p.row2)),U={type:I,title:String(t.title??""),heading:l,legend:i,nodes:f,byId:D,edges:v,groups:C,lanes:B,steps:M,bars:L,frameWords:F,cols:Z,rows:N,shapeLabels:h,stepWord:u,warnings:r,motion:_,memo:new Map};return s&&f.length>1&&!St(U)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),U}function It(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Wt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function yt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var zt=28,Ot=t=>t.includes(` +`)?2:1,pt=t=>t.replace(/\n/g," "),bt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Ft(t,e){return t.legend[e]}function Me(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Se(t,e){return yt(t,`sentence:${e.i}`,()=>Ee(t,e))}function Ee(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(bt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Nt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Me(t,e):e.kind;if(n.push(bt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(bt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${pt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${pt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(bt(t.legend.focal)),n.join(" ")}function Nt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function Ae(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var Le={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>Le[e]),qe=" br img input meta link hr path polygon polyline circle rect line ";function _t(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return qe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>_t(s,e)).join("")}`}var Ie=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Oe(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function kt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Ht(t){return yt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=kt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Dt(t,n,a)))})}return e})}function Dt(t,e,n){const s=kt(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=kt(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Gt(t){const e=Ht(t);return e[1]+e[3]}function Ct(t){return t.type==="sequence"?t.nodes.length:t.cols}function Kt(t){return yt(t,"plan",()=>_e(t))}function _e(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},m=t.edges.map(()=>0);let h=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,m[v.k]+1));m[c.k]=f,f>1&&(h=!0),l.push(c)}const y=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{y[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const $=ut();for(let c=1;c{const O=s[D],V=t.byId.get(H.from).i,q=t.byId.get(H.to).i,W=q===c&&(O==="down"||O==="trunk"||O==="rail"||O==="end-down"),_=V===c&&q===c-1&&O==="up",L=q===c-1&&O==="end-up";W&&(O==="trunk"||O==="end-down")&&(M=!0),L&&(I=!0),(W||_||L)&&H.label&&(B++,C=Math.max(C,O==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),$[f.id]=C}return{routes:s,gutter:d,lanes:m,exits:y,gaps:$,third:h}}var $t=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Vt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...$t(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function wt(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Zt(t,e){return yt(e,`key:${t}`,()=>je(t,e))}var Ce=Zt;function je(t,e){const n=[],s=(o,a,i={})=>n.push(k("li",{class:`${t}-entry`,...i},o,k("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),k("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(wt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(wt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(wt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Vt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Vt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...$t(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),k("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(wt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(wt(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Be(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...$t(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function jt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Te(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},jt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},jt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?At(n.detail).flatMap((r,o)=>[o?" ":"",k("span",{class:`${t}-run`},r)]):n.detail)),s}function Re(t,e){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},jt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>k("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},k("span",{class:`${t}-keyseat`},n.key??""),k("span",{class:`${t}-cname`},n.name),n.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?k("span",{class:`${t}-ctype`},n.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ut=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Mt(t,e,n,s){const{P:r}=t,o=Oe(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=gt(d.gaps,n.id)??32,y=gt(s.grow,n.id)??0;i.push(`--_gap:${y?`calc(${Ut(l)} + var(--basalt-space-4) * ${y})`:Ut(l)}`)}const u=gt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const m=gt(s.words,n.id);m&&i.push(`--_ww:${m}px`);const h=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?Se(e,n):void 0,tabindex:h},n.shape==="decision"?k("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Wt(n.mark.onLight)};--_md:${Wt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Re(r,n):Te(r,e,n))}function We(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=kt(e,d);if(!u)continue;const m=[0,1,2,3].map(h=>Dt(e,d,h));r.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`},Mt(t,e,d,n))))),r.push(ze(t,e)),r;const o=d=>{const u=d.group?e.groups.find(m=>m.id===d.group):void 0;return u?.parent?e.groups.find(m=>m.id===u.parent):u},a=(d,u,m)=>{const h=t.plan?gt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:h?`--_ggrow:${h}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),m)};let i=0;for(;ic.id===m[l].group):void 0;if(!y){h.push(Mt(t,e,m[l],n)),l++;continue}const $=[];for(;lMt(t,e,c,n))))}r.push(a(u,m,h))}return r}function ze(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(k("p",{class:`${n}-band`},k("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=k("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=k("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),m=d?.col??1,h=u?.col??1,l=m===h,y=l&&m===e.nodes.length,$=Ft(e,i.kind);a.c.push(k("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?y?"start":"end":void 0,style:`--_a:${Math.min(m,h)};--_b:${Math.max(m,h)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(i.n)),k("span",{class:`${n}-mlabel`},i.label)),k("span",{class:`${n}-route`},d?.short??i.from," ",Be(n,i.kind),k("span",{class:t.hidden}," to ")," ",u?.short??i.to,$?` · ${$}`:""),i.note?k("span",{class:`${n}-note`},i.note):null))}return k("div",{class:`${n}-steps`},s)}function Jt(t,e){return yt(e,`list:${t}`,()=>Ne(t,e))}var Fe=Jt;function Ne(t,e){const n=Math.min(6,e.heading+1),s=h=>k(`h${n}`,{class:`${t}-list-head`},h),r=h=>k("strong",null,h),o=h=>h.href?k("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},r(h.name)):r(h.name),a=h=>k("code",{class:`${t}-code`},h),i=h=>e.byId.get(h)?.name??h,d=h=>{const l=Ft(e,h);return l?` (${l})`:""},u=h=>h.focal&&e.legend.focal?` ${bt(e.legend.focal)}`:"";if(e.type==="architecture"){const h=$=>k("li",null,o($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?a($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",u($)),l=[s("Parts")],y=e.nodes.filter($=>!$.group);y.length&&l.push(k("ul",{class:`${t}-list-items`},y.map(h)));for(const $ of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},$.label)),$.members.length&&l.push(k("ul",{class:`${t}-list-items`},$.members.map(c=>h(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===$.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>h(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map($=>k("li",null,r(i($.from))," to ",r(i($.to)),$.label?[": ",a(pt($.label))]:"",`${d($.kind)}.`)))),l}if(e.type==="flowchart"){const h=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const y=e.edges.filter(f=>f.from===l.id),$=l.shape==="decision"?"Decision":l.shape==="terminal"?y.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${$}.`,u(l),y.length?k("ul",{class:`${t}-list-exits`},y.map(f=>k("li",null,f.label?`If ${pt(f.label)}: go to ${h(f.to)}, `:`Then: go to ${h(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(h=>{const l=e.edges.filter(y=>y.from===h.id);return k("li",null,`${h.laneLabel}: `,o(h),h.detail?[", ",h.mono?a(h.detail):h.detail]:"",".",u(h),l.length?[" Then ",...l.flatMap((y,$)=>[$?"; ":"",`to step ${e.byId.get(y.to).step}, `,r(i(y.to)),y.label?[": ",a(pt(y.label))]:"",d(y.kind)]),"."]:"")}))];if(e.type==="sequence"){const h=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(y=>k("li",null,r(y.name),y.kind?`, ${y.kind}`:"",".",u(y),Nt(e,y))))];h.push(s("Messages"));let l=null;for(const y of e.steps){if("band"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},y.band));continue}if("open"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":y.depth>1?y.depth:void 0},`${e.frameWords[y.open]}: ${y.label}`));continue}if("otherwise"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":y.depth>1?y.depth:void 0},`${e.frameWords.else}: ${y.otherwise}`));continue}if("close"in y){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:y.n}),h.push(l)),l.c.push(k("li",null,a(y.label),": ",r(i(y.from))," to ",r(i(y.to)),`${d(y.kind)}.`,y.note?` ${bt(y.note)}`:""))}return h}const m=[];for(const h of e.nodes)m.push(k(`h${n}`,{class:`${t}-list-group`},h.href?k("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},a(h.name)):a(h.name),u(h))),m.push(k("ul",{class:`${t}-list-items`},[...(h.columns??[]).map(l=>k("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...h.more?[k("li",null,`and ${h.more} more ${h.more===1?"column":"columns"}`)]:[]]));return m}function Xt(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&St(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Bt(t,e=!1){const n=e&&t.type!=="sequence"&&St(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Ae(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var He=(t,e)=>{for(let n=0;n({col:t.type==="sequence"?e.i+1:e.col,rows:[e.row,e.row2]});function St(t){return yt(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...De(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=$=>i?[$.col,$.col]:$.rows,m=$=>i?$.rows:[$.col,$.col],h=u(o),l=m(o);let y=null;return e.forEach(($,c)=>{if($===o)return;const f=u($),v=m($),B=d?f[0]-h[1]:h[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!y||He(M,y.rank))&&(y={id:$.id,rank:M})}),y?.id??null},s=ut();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var Yt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Qt(t,e,n){const s=n.prefix,r=Ie(n.base),o=t.type==="sequence"||t.type==="schema"?null:Kt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,m=`h${t.heading}`,h=[`--_cols:${Ct(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Ht(t):[0,0,0,0],y=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",$=i&&e.pad?"3":void 0;h.push(`--_gpad:${y(l[0],"8",$)} ${y(l[1],"4")} ${y(l[2],"4",$)} ${y(l[3],"4")}`)}return Yt(t)&&h.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&h.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Ct(t),"data-reach":t.type==="architecture"?Gt(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:h.join(";")},k("div",{class:`${s}-head`},k(m,{id:r.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},We(a,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Zt(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Jt(s,t)),k("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Xt(t,i)} ${n.viewer}`:Xt(t,i)),k("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Ge(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Et=(t,e)=>t==="main"?e.line:e.hair,dt=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ft=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Pt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function ct(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2,h=e==="top"||e==="bottom";if(t.shape==="decision"){if(h){const $=n,c=m*Math.max(0,1-Math.abs($-i)/u);return{x:$,y:e==="top"?d-c:d+c}}const l=n,y=u*Math.max(0,1-Math.abs(l-d)/m);return{x:e==="left"?i-y:i+y,y:l}}if(t.shape==="terminal"){const l=Math.min(u,m);if(h){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const y=n,$=y-d,c=Math.abs($)>=l?0:Math.sqrt(l*l-$*$);return{x:e==="left"?s+l-c:o-l+c,y}}return h?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Ke(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/m<1-n/Math.min(u,m);if(e.shape==="terminal"){const h=Math.min(u,m),l=Math.min(Math.max(t.x,s+h),o-h);return Math.hypot(t.x-l,t.y-d)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Ue(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var At=t=>t?t.split(/\s+/).filter(Boolean):[];function Je(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`→ ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),m=d.mark&&!Ze()?(d.shape==="participant"?2:1)*s("6"):0;let h=0;const l=d.href?16+s("1-5"):0,y=At(d.name);if(y.forEach((c,f)=>{h=Math.max(h,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:m)+(f===y.length-1?l:0))}),t.type!=="data-flow")for(const c of At(d.kind))h=Math.max(h,n(c,"mono")+m);for(const c of At(d.detail))h=Math.max(h,n(c,d.mono?"mono":"sans"));const $=d.shape==="decision"?h/.62:h+u+2*e.hair;r=Math.max(r,Math.ceil($))}const a=Ct(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(Yt(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Gt(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ee(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Tt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ne(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ht=t=>t.slice(1).map((e,n)=>[t[n],e]);function Lt(t,e,n){const s=[];for(let o=0;oMath.min(c.x,f.x)+.75&&CMath.min(v.y,B.y)+.75&&Mr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",oe={top:"bottom",bottom:"top",left:"right",right:"left"};function Ye(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Qe(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,m]=e[a],h=i.row===d.row&&tt(u)&&tt(m)&&u===oe[m]||i.col===d.col&&!tt(u)&&!tt(m)&&u===oe[m];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:h,f:.5},{edge:a,end:"to",node:d,side:m,far:i,straight:h,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const m=new Map;for(const c of d)m.has(c.far.id)||m.set(c.far.id,[]),m.get(c.far.id).push(c);for(const c of m.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const h=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),y=u.filter(c=>i(c)<0),$=u.filter(c=>i(c)>=0);y.forEach((c,f)=>{c.f=h*(f+1)/(y.length+1)}),$.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/($.length+1)})}return s}function se(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?ct(t,e,r+(a-r)*n):ct(t,e,s+(o-s)*n)}function ae(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:dt(o,n),shape:a.shape,i:a.i})}),r}function re(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var ie=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function le(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function Pe(t,e,n,s,r,o,a,i,d){const u=a.space,m=[],h=[],l=[],y=[],$=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*Ot(v),M=f.pts.length-2,I=[];ht(f.pts).forEach(([q,W],_)=>{const L=Math.abs(q.y-W.y)<.01,j=L?q.x:q.y;let F=L?W.x:W.y;const Z=Math.sign(F-j)||1;_===M&&(F-=Z*a.head);let N=[[j,F]];for(const w of r)for(const S of L?[w.l,w.r]:[w.t,w.b]){const g=L?q.y:q.x;(L?g>w.t&&gw.l&&gS>Math.min(x,E)+1&&S{const g=(w+S)/2,b=L?{x:g,y:q.y}:{x:q.x,y:g};return!r.some(x=>b.x>x.l&&b.xx.t&&b.y1&&U(w,S)?1:0})}),I.sort((q,W)=>W.pri-q.pri||W.len-q.len);let H=null,D=!1;const O=(q,W=!0)=>{const _=Pt(q,$);return W&&(q.lo.r||q.to.b)||n.some(L=>te(_,L))||m.some(L=>ft(_,L))||s.heads.some(L=>ft(_,L))||s.rects.some(L=>ft(_,L))?!1:!e.some(L=>L.i!==f.i&&ht(L.pts).some(([j,F])=>ft(_,ie(j,F,L.width))))};for(const q of I){for(const W of[1/2,1/3,2/3]){const _=q.p+(q.q-q.p)*W,L=[],j=u("2")+f.width/2;if(q.horiz?(q.len>=B+2*u("1")+u("3-5")&&L.push({box:{l:_-B/2-u("1"),r:_+B/2+u("1"),t:q.c-C/2,b:q.c+C/2},on:!0}),L.push({box:{l:_-B/2,r:_+B/2,t:q.c-j-C,b:q.c-j},on:!1}),L.push({box:{l:_-B/2,r:_+B/2,t:q.c+j,b:q.c+j+C},on:!1})):(q.len>=C+u("3")&&L.push({box:{l:q.c-B/2-u("1"),r:q.c+B/2+u("1"),t:_-C/2,b:_+C/2},on:!0}),L.push({box:{l:q.c+j,r:q.c+j+B,t:_-C/2,b:_+C/2},on:!1}),L.push({box:{l:q.c-j-B,r:q.c-j,t:_-C/2,b:_+C/2},on:!1})),H=L.find(F=>O(F.box))??null,H)break;!D&&L.some(F=>O(F.box,!1))&&(D=!0)}if(H)break}if(!H){l.push(f.i),D&&y.push(f.i);continue}const V=le(H.box,d.ox,d.oy,q=>O(q));m.push(V),h.push({i:f.i,text:v,box:V,on:H.on})}return{labels:h,unseated:l,bounded:y}}function ce(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=dt(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(dt(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=dt(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(dt(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function tn(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,m=ae(s,a,i,o),h=[...m.values()],l=Xe(a),y=i.left-Math.floor(i.left),$=i.top-Math.floor(i.top),c=ee(y,$),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:y,oy:$};if(s.type==="sequence")return nn(t,M,c);let I,H=[];s.type==="schema"?I=s.edges.map(g=>{const b=s.byId.get(g.from),x=s.byId.get(g.to);if(b.col===x.col){const E=b.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return x.col>b.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const b=s.byId.get(g.from),x=s.byId.get(g.to),[E,A]=Ye(b,x);return[g.fromSide??E,g.toSide??A]}),H=Qe(s,I,d||(()=>{})));const D=(g,b)=>{const x=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${b}"]`);if(!x)return 0;const E=dt(x,i);return(E.t+E.b)/2},O=s.edges.map((g,b)=>{const[x,E]=I[b],A=m.get(g.from),T=m.get(g.to),K=Et(g.kind,r);if(g.fk){const X=D(g.from,g.fromRow),ot=D(g.to,g.toRow),Y=c.y(X,K),st=c.y(ot,K);return{p1:{x:x==="right"?A.rect.r:A.rect.l,y:Y},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:X,r2:Math.abs(Y-st)<.01?X:ot}}const Q=H.find(X=>X.edge===b&&X.end==="from").f,J=H.find(X=>X.edge===b&&X.end==="to").f;let z=se(A,x,Q),G=se(T,E,J);const nt=tt(x)?z.y:z.x;let et=tt(E)?G.y:G.x;return tt(x)?z={...z,y:c.y(z.y,K)}:z={...z,x:c.x(z.x,K)},tt(E)?G={...G,y:c.y(G.y,K)}:G={...G,x:c.x(G.x,K)},tt(x)&&tt(E)&&Math.abs(z.y-G.y)<1.01&&(G={...G,y:z.y},et=nt),!tt(x)&&!tt(E)&&Math.abs(z.x-G.x)<1.01&&(G={...G,x:z.x},et=nt),z=tt(x)?ct(A,x,z.y):ct(A,x,z.x),G=tt(E)?ct(T,E,G.y):ct(T,E,G.x),{p1:z,p2:G,r1:nt,r2:et}}),V=new Set;s.type==="schema"&&s.edges.forEach((g,b)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&V.add(b)});const q=new Map,W=new Set;s.edges.forEach((g,b)=>{if(V.has(b))return;const[x,E]=I[b],{p1:A,p2:T}=O[b],K=s.byId.get(g.from),Q=s.byId.get(g.to);let J=null,z=null,G=!1;if(x===E){if(tt(x)){const X=x==="right"?Math.max(B(K),B(Q)):Math.min(B(K),B(Q))-1,ot=l.cols[X-1],Y=l.cols[X];ot&&Y&&(J=`c${X}`,z=[ot[1],Y[0]],G=!0)}else{const X=x==="bottom"?Math.max(K.row2,Q.row2):Math.min(K.row,Q.row)-1,ot=l.rows[X-1],Y=l.rows[X];ot&&Y&&(J=`r${X}`,z=[ot[1],Y[0]],G=!1)}J&&W.add(b)}else if(tt(x)&&tt(E)&&Math.abs(A.y-T.y)>.5){const X=B(Q),ot=E==="left",Y=l.cols[(ot?X-1:X)-1],st=l.cols[(ot?X:X+1)-1];Y&&st&&(J=`c${ot?X-1:X}`,z=[Y[1],st[0]],G=!0)}else if(!tt(x)&&!tt(E)&&Math.abs(A.x-T.x)>.5){const ot=E==="top"?Q.row-1:Q.row2,Y=l.rows[ot-1],st=l.rows[ot];Y&&st&&(J=`r${ot}`,z=[Y[1],st[0]],G=!1)}if(!J||!z)return;q.has(J)||q.set(J,{span:z,vertical:G,members:new Map});const nt=`${g.to}.${E}.${Math.round(G?T.y:T.x)}`,et=q.get(J);et.members.has(nt)||et.members.set(nt,[]),et.members.get(nt).push(b)});const _=new Map,L=g=>{const[b,x]=I[g],{p1:E,p2:A}=O[g];if(tt(b)&&tt(x)){if(b===x){const K=_.get(g)??(b==="right"?Math.max(E.x,A.x)+u("4"):Math.min(E.x,A.x)-u("4"));return[E,{x:K,y:E.y},{x:K,y:A.y},A]}if(Math.abs(E.y-A.y)<=.5)return[E,{x:A.x,y:E.y}];const T=_.get(g)??(E.x+A.x)/2;return[E,{x:T,y:E.y},{x:T,y:A.y},A]}if(!tt(b)&&!tt(x)){if(b===x){const K=_.get(g)??(b==="bottom"?Math.max(E.y,A.y)+u("4"):Math.min(E.y,A.y)-u("4"));return[E,{x:E.x,y:K},{x:A.x,y:K},A]}if(Math.abs(E.x-A.x)<=.5)return[E,{x:E.x,y:A.y}];const T=_.get(g)??(E.y+A.y)/2;return[E,{x:E.x,y:T},{x:A.x,y:T},A]}return tt(b)?[E,{x:A.x,y:E.y},A]:[E,{x:E.x,y:A.y},A]},j=g=>{const b=s.edges[g],x=Et(b.kind,r),E=L(g),A=ne(E,x,c);let T;return E.length===A.length&&(T=ht(E).map(([K,Q])=>Math.abs(K.y-Q.y)<.75?(K.y+Q.y)/2:(K.x+Q.x)/2),T[0]=O[g].r1,T.length>1&&(T[T.length-1]=O[g].r2)),{i:g,from:b.from,to:b.to,kind:b.kind,pts:A,tip:A[A.length-1],dir:Tt(A),dot:b.fk?A[0]:void 0,width:x,axes:T}},F=()=>s.edges.flatMap((g,b)=>V.has(b)?[]:[j(b)]);let Z=null;const N=g=>{Z??(Z=F());const b=Z.map(x=>g.has(x.i)?j(x.i):x);return{lines:b,score:en(b,g)*1e5+Lt(b,void 0,g).length*1e3+Rt(b.filter(x=>g.has(x.i)),h,s).length}},U=(g,b)=>{const x=g.flatMap(E=>{const{p1:A,p2:T}=O[E];return b?[A.y,T.y]:[A.x,T.x]});return[Math.min(...x),Math.max(...x)]};for(const[,g]of q){const b=[...g.members.values()].map(E=>({members:E,run:U(E,g.vertical)})).sort((E,A)=>E.run[0]-A.run[0]),x=[];for(const E of b){const A=x[x.length-1];A&&A.some(T=>T.run[0]W.has(nt)))continue;const A=E.map(nt=>nt.members),T=A.length,K=(g.span[1]-g.span[0])/(T+1);KX.forEach(Y=>_.set(Y,g.span[0]+K*(ot+1))));const et=N(Q);et.scorent.forEach(X=>_.set(X,g.span[0]+K*(et+1)))),Z=G}}M.lines=F();for(const g of V)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=Lt(M.lines),M.through=Rt(M.lines,h,s),M.outside=ue(M.lines,f,v,r);const{obstacles:p,groups:w}=ce(a,i,o,C);p.heads=M.lines.map(g=>re(g,r));const S=Pe(s,M.lines,h,p,w,{l:0,t:0,r:f,b:v},r,e,{ox:y,oy:$});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(de(M.lines,null).flat())],M}function en(t,e){return de(t,e).length}function de(t,e){const n=[];for(let s=0;s=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[m.x,h.x]:[m.y,h.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*fe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Rt(t,e,n){const s=[];for(const r of t){const o=ht(r.pts);e.some(a=>o.some(([i,d])=>Ve(i,d,a)))&&s.push(r.i)}return s}function nn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,dt(M,i)));const m=a.querySelector(`.${o}-steps`),h=m?dt(m,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:h})}const y=M=>u.get(M.id),$=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=dt(M,i);$.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const H=l(M.who),D=I.i===s.nodes.length-1&&s.nodes.length>1?-1:1,O=(M.depth-1)*d("1")*D,V=$.get(M.from)??0,q=$.get(M.to)??V,W=M.from===M.to;return{l:n.x(H-f+O,r.hair),r:n.x(H+f+O,r.hair),t:n.y(W?V-d("2")-d("1"):V,r.hair),b:n.y(W?V+d("2")+d("1"):q,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,H)=>B.filter(({bar:D})=>D.who===M&&D.to>=I&&(H?D.from<=I:D.fromO.bar.depth-D.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,H=M.dataset.to,D=M.dataset.kind??"plain",O=Et(D,r),V=dt(M,i),q=n.y((V.t+V.b)/2,O),W=Number(M.querySelector(`.${o}-num`)?.textContent??0);let _=l(I),L=l(H),j;if(I===H){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,W,!0),b=g?S>0?g.r:g.l:_,x=n.y(q-d("2"),O),E=n.y(q+d("2"),O);j=[{x:b,y:x},{x:n.x(_+S,O),y:x},{x:n.x(_+S,O),y:E},{x:b,y:E}]}else{const S=L>_?1:-1,g=C(I,W,!1),b=C(H,W,!0);g&&(_=S>0?g.r:g.l),b&&(L=S>0?b.l:b.r),j=[{x:_,y:q},{x:L,y:q}]}e.lines.push({i:W,from:I,to:H,kind:D,pts:j,tip:j[j.length-1],dir:Tt(j),width:O});const F=M.querySelector(`.${o}-said`),Z=M.querySelector(`.${o}-note`),N=s.byId.get(I),U=s.byId.get(H);if(!N||!U)return;const p=I===H?(()=>{const S=s.nodes[N.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-_)-d("6")-d("2-5")-d("2")})():Math.abs(L-_)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>p+.5&&e.unseated.push(W)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((D,O)=>D+O.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function he(t,e,n,s=ut()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,m=ae(r,i,d,a),h=[...m.values()],l=d.left-Math.floor(d.left),y=d.top-Math.floor(d.top),$=ee(l,y),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:y},B=ut();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(L,j,F)=>{const Z=[L];for(let N=1;N<=(gt(s,j)??0);N++)Z.push({...L,t:L.t+F*u("4")*N,b:L.b+F*u("4")*N});return Z},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(L=>{const j=L.parentElement,F=dt(j,d),Z=getComputedStyle(j);I.set(L.dataset.node,F.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const H=r.nodes,D=L=>m.get(H[L].id),O=[],V=L=>Et(r.edges[L].kind,o);r.edges.forEach((L,j)=>{const F=n.routes[j],Z=m.get(L.from),N=m.get(L.to),U=V(j);let p=[];const w=L.label,S=w?e(w,"label"):0,g=w?16*Ot(w):16,b=u("4");if(F==="down"||F==="up"){const E=Math.max(Z.rect.l,N.rect.l),A=Math.min(Z.rect.r,N.rect.r),T=r.edges.map((z,G)=>({o:z,j:G})).filter(({o:z,j:G})=>(n.routes[G]==="down"||n.routes[G]==="up")&&(z.from===L.from&&z.to===L.to||z.from===L.to&&z.to===L.from)),K=T.findIndex(z=>z.j===j),Q=T.length<2?.5:T.length===2?K===0?.25:.75:(K+1)/(T.length+1),J=$.x(E+(A-E)*Q,U);if(p=F==="down"?[ct(Z,"bottom",J),ct(N,"top",J)]:[ct(Z,"top",J),ct(N,"bottom",J)],w){let z=Math.min(p[0].y,p[1].y),G=Math.max(p[0].y,p[1].y);F==="down"?G-=o.head:z+=o.head;const nt=[...i.querySelectorAll(`.${a}-group`)].map(Y=>dt(Y,d));let et=[[z,G]];for(const Y of nt)for(const st of[Y.t,Y.b])et=et.flatMap(([rt,R])=>st>rt+1&&stnt.some(rt=>(Y+st)/2>rt.t&&(Y+st)/2rt.l&&J1){const Y=et.filter(([rt,R])=>!X(rt,R));[z,G]=(Y.length?Y:et).reduce((rt,R)=>R[1]-R[0]>rt[1]-rt[0]?R:rt)}const ot=[1/2,1/3,2/3].map(Y=>{const st=z+(G-z)*Y;return{l:J-S/2-u("1"),r:J+S/2+u("1"),t:st-g/2,b:st+g/2}});O.push({k:j,cands:ot,on:!0,card:F==="down"?L.to:L.from})}}else if(F==="trunk"||F==="rail"){const E=$.x(Math.max(Z.rect.l,F==="rail"?N.rect.l:Z.rect.l)+u(F==="trunk"?"8":"3"),U),A=ct(Z,"bottom",E);if(F==="rail"){if(p=[A,ct(N,"top",E)],w){const T=N.rect.t-u("6");O.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},L.to,-1),on:!1,card:L.to})}}else{const T=$.x(N.rect.l+u("6"),U),K=$.y(N.rect.t-b,U);p=[A,{x:E,y:K},{x:T,y:K},ct(N,"top",T)],w&&O.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:K-g/2,b:K+g/2},L.to,-1),on:!1,card:L.to})}}else{const E=Math.min(I.get(L.from)??c,I.get(L.to)??c),A=$.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),U),T=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[j],U),K=ct(Z,"right",T),Q=$.x(N.rect.r-u("6"),U),J=F==="end-down",z=$.y(J?N.rect.t-b:N.rect.b+b,U);p=[K,{x:A,y:K.y},{x:A,y:z},{x:Q,y:z},ct(N,J?"top":"bottom",Q)];const G=J?L.to:H[N.i+1]?.id??L.to;w&&O.push({k:j,cands:M({l:Q-u("2-5")-S,r:Q-u("2-5"),t:z-g/2,b:z+g/2},G,J?-1:1),on:!1,card:G})}const x=ne(p,U,$);v.lines.push({i:j,from:L.from,to:L.to,kind:L.kind,pts:x,tip:x[x.length-1],dir:Tt(x),width:U})}),v.crossings=Lt(v.lines),v.through=Rt(v.lines,h,r),v.outside=ue(v.lines,c,f,o);const{obstacles:q}=ce(i,d,a,0);q.heads=v.lines.map(L=>re(L,o));const W=[],_={l:0,t:0,r:c,b:f};for(const L of O){const j=N=>{const U=Pt(N,u("1"));return N.l<_.l-.5||N.r>_.r+.5||N.t<_.t-.5||N.b>_.b+.5||h.some(p=>te(U,p))||W.some(p=>ft(U,p))||q.heads.some(p=>ft(U,p))||q.rects.some(p=>ft(U,p))||v.lines.some(p=>p.i!==L.k&&ht(p.pts).some(([w,S])=>ft(U,ie(w,S,p.width))))},F=L.cands.find(N=>!j(N));F||(B[L.card]=(B[L.card]??0)+1,v.unseated.push(L.k));const Z=F?le(F,l,y,N=>!j(N)):L.cands[0];W.push(Z),v.labels.push({i:L.k,text:r.edges[L.k].label,box:Z,on:L.on})}return{geo:v,grow:B}}function on(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...M})),h=m[m.length-1];h.x-=o.x*u,h.y-=o.y*u;const l=e.tip.x-o.x*i,y=e.tip.y-o.y*i,$=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=lt(e.kind),B=a?``:``,C=e.dot?``:"";return`${B}${C}`}function pe(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const m=d.map(h=>{const l=e.lines[h.top],y=e.lines[h.under],$=l.width/2+n.cut,c=y.width/2+1;return h.underVertical?``:``}).join("");a+=`${m}`}return{defs:a,ids:r}}function ge(t,e,n,s){const{defs:r,ids:o}=pe(t,e,n,s),a=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),i=e.lines.map((m,h)=>an(t,m,n,o.get(h)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),d=`${r?`${r}`:""}${a}${i}`,u=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` +`).map(lt).join("
")}
`).join("");return d+u}function me(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const m=Ge(t),h=Ue(u,n),l=Je(e,m,h);i?.(l.least);const y=t.clientWidth,$=(()=>{const q=document.activeElement;return q&&u.contains(q)&&q.dataset.node?q.dataset.node:void 0})(),c=q=>mt(e,q)?{...q,stop:q.stop&&e.byId.has(q.stop)?q.stop:e.nodes[0]?.id,keep:void 0}:{...q,stop:q.stop??e.nodes[0]?.id,keep:$&&q.layout!=="drawn"?$:void 0};let f=!1;const v=q=>{if(f=!1,e.type!=="flowchart")return q;o({...q,heights:void 0,words:void 0});const W=ut(),_=ut();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(L=>{const j=L.querySelector(`.${n}-words`);if(!j)return;const F=L.getBoundingClientRect(),Z=p=>{const w={w:p.width+2*m.space("2-5"),h:p.height+2*m.space("2")},S=1-w.w/F.width,g=S>.05?w.h/2/S:w.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},N=j.getBoundingClientRect();let U=Z(N);if(U>F.width){const p=b=>(L.style.setProperty("--_ww",`${b}px`),j.getBoundingClientRect()),w=Math.floor(L.clientWidth-2*m.space("2-5"));let S=Math.ceil(N.width),g=N.height;for(;S1;){const T=b+x>>1;p(T).heightF.width&&(f=!0)}),{...q,heights:W,words:Object.keys(_).length?_:void 0}},B=()=>({m:e,tk:m,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(q,W)=>W.map(_=>vt(e,q.lines.find(L=>L.i===_))).join(", ");if(y>=l.least){const q=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:tn(B(),h)}};let{dd:W,g:_}=q(!1);const L=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!L(_)&&_.unseated.length&&_.unseated.every(j=>_.bounded?.includes(j))){const j=q(!0);!L(j.g)&&!j.g.unseated.length&&({dd:W,g:_}=j)}if(!L(_)&&!_.unseated.length)return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the drawn layout: ${_.crossings.map(j=>`${vt(e,_.lines[j.top])} over ${vt(e,_.lines[j.under])}`).join("; ")}`),{dyn:W,geo:_,ink:ge(n,_,m,s),tokens:m,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: a decision would be taller than it is wide`),_.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${_.misfit.join("; ")}`),_.through.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.through)} would pass through a node`),_.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.overlaps)} would lie on one another`),_.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.outside)} would leave the drawing`),_.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: no clean seat for ${_.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ut(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:m,least:l.least};const H=Kt(e);let D=he(B(),h,H,I.grow);for(let q=0;q<6&&Object.keys(D.grow).length;q++){const W=ut(I.grow);for(const[_,L]of Object.entries(D.grow))W[_]=(gt(W,_)??0)+L;I={...I,grow:W},o(I),D=he(B(),h,H,W)}const O=D.geo;if(O.unseated.length>0||O.through.length>0||O.outside.length>0||H.third){O.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(O.unseated)].map(_=>`"${e.edges[_]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),O.through.length&&a?.(`in the stacked drawing ${M(O,O.through)} would pass through a node, so its lines are not drawn`),O.outside.length&&a?.(`in the stacked drawing ${M(O,O.outside)} would leave the drawing, so its lines are not drawn`),H.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const q={...O,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ut(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:q,ink:"",tokens:m,least:l.least}}return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${O.crossings.map(q=>`${vt(e,O.lines[q.top])} over ${vt(e,O.lines[q.under])}`).join("; ")}`),{dyn:I,geo:O,ink:ge(n,O,m,s),tokens:m,least:l.least}}function vt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function rn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const m=Lt(n.lines,i),{defs:h,ids:l}=pe(e,{...n,crossings:m},s,r),y=t.querySelector(`.${e}-svg`);if(!y)return;let $=y.querySelector("defs");!$&&h&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),y.insertBefore($,y.firstChild)),$&&($.innerHTML=h),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var ln=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function cn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",ln()?"done":"pending")}}function ye(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function dn(t,e,n,s=!1,r=!1){const o=s?St(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var fn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],be=["data-layout","data-measured","data-bare","data-motion"],un=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],$e=t=>t==null||t===!1;function hn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function we(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?be:fn;for(const a of s)$e(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,m=new Map(String(i??"").split(";").map(h=>{const l=h.indexOf(":");return[h.slice(0,l).trim(),h.slice(l+1).trim()]}).filter(([h])=>h));for(const[h,l]of m)u.getPropertyValue(h).trim()!==l&&u.setProperty(h,l);for(const h of un)m.has(h)||u.removeProperty(h);continue}if(n&&!be.includes(a))continue;if($e(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,y,$){return{prefix:n,base:l,hasSource:y.source!==void 0&&y.source!==null&&y.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(l,y,$,c){var f=function(v){return''+lt(v)+""};return{source:lt(String(y.source||"")),summary:lt(String(y.summary||"")),hint:Bt(l).map(function(v){return""+v.keys.map(f).join(" ")+" "+lt(v.words)+""}).join(""),toggle:'"}}function a(l,y,$){var c=qt(l),f=Qt(c,{},r(y,l,$)),v=_t(f,o(c,l,y,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,y,$,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=qt(y);if(!$||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(y,f,c),C=document.createElement("div");C.innerHTML=B.open+"";var M=C.firstChild;i.forEach(function(R){l.removeAttribute(R)}),d.forEach(function(R){l.style.removeProperty(R)});for(var I=0;I :not(script[data-diagram])").forEach(function(R){R.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(R){console.warn("Basalt diagram: "+R)});var D=r(f,y,c),O={},V=null,q=null,W=null,_=Object.create(null),L=function(R){_[R]||(_[R]=1,console.warn("Basalt diagram: "+R))},j=function(R){we(l,Qt(v,R,D))},F=l.querySelector(".diagram-ink"),Z=l.querySelector(".diagram-toggle"),N=!c&&v.motion.animated&&typeof e.diagramMotion=="function",U=null,p=null,w=function(){N&&ye(l)};function S(){rn(l,n,V&&V.geo,V&&V.tokens,f,q||W)}function g(){Z&&(Z.setAttribute("aria-expanded",String(!!O.open)),Z.firstElementChild.textContent=O.open?"Hide the list":"View as list")}function b(){V=(c?c.measure:me)(l,v,n,f,O,j,L),O=V.dyn,j(O),g();var R=l.querySelector(":scope > .diagram-hint");if(R){var P=Bt(v,O.layout==="drawn").map(function(xt){return""+xt.keys.map(function(gn){return''+lt(gn)+""}).join(" ")+" "+lt(xt.words)+""}).join("");R.innerHTML!==P&&(R.innerHTML=P)}mt(v,O)||(W=null);var it=F&&V.ink!==p;it&&(F.innerHTML=V.ink,p=V.ink),S(),N&&V.tokens&&(cn(l,!!(V.geo&&V.geo.lines.length)),it&&U&&U.redrawn()),c&&c.onMeasured&&V.tokens&&c.onMeasured(V,l)}function x(R){O=R,j(O)}function E(R){var P=O.stop;O=Object.assign({},O,{stop:R}),pn(l,n,P,R)}var A=function(R){var P=R&&R.closest?R.closest(".diagram-node"):null;return P&&l.contains(P)?P:null};function T(R){var P=A(R.target);if(!(!P||R.defaultPrevented)){if(w(),R.key==="Escape"){!c&&(q||W)&&(R.preventDefault(),q=W=null,S());return}if(mt(v,O)){var it=dn(v,P.getAttribute("data-node"),R.key,O.layout==="drawn",getComputedStyle(P).direction==="rtl");if(it){R.preventDefault(),E(it);var xt=l.querySelector('.diagram-node[data-node="'+CSS.escape(it)+'"]');xt&&xt.focus()}}}}function K(R){var P=A(R.target);if(P){w();var it=P.getAttribute("data-node");q=P.matches(":focus-visible")?it:null,mt(v,O)&&O.stop!==it&&E(it),S()}}function Q(R){var P=A(R.target);P&&(A(R.relatedTarget)||(q=null),O.keep===P.getAttribute("data-node")&&x(Object.assign({},O,{keep:void 0})),S())}function J(R){if(!(R.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var P=A(R.target);P&&w();var it=P&&mt(v,O)?P.getAttribute("data-node"):null;it!==W&&(W=it,S())}}function z(){W&&(W=null,S())}function G(){w(),x(Object.assign({},O,{open:!O.open,autoOpen:void 0})),g()}l.addEventListener("keydown",T),l.addEventListener("focusin",K),l.addEventListener("focusout",Q),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",z),Z&&Z.addEventListener("click",G),b();var nt=l.clientWidth,et=0,X=!0,ot=new ResizeObserver(function(){Math.abs(l.clientWidth-nt)<.5||(nt=l.clientWidth,cancelAnimationFrame(et),et=requestAnimationFrame(b))});ot.observe(l),document.fonts&&document.fonts.ready.then(function(){X&&b()});var Y=matchMedia("(forced-colors: active)"),st=v.nodes.some(function(R){return R.mark});st&&Y.addEventListener("change",b),N&&(U=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},y));var rt=!c&&y.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,y,{model:v,settle:w,animated:N}):null;l.__diagram={stop:function(){rt&&rt.destroy(),X=!1,ot.disconnect(),cancelAnimationFrame(et),st&&Y.removeEventListener("change",b),U&&U.destroy(),l.removeEventListener("keydown",T),l.removeEventListener("focusin",K),l.removeEventListener("focusout",Q),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",z),Z&&Z.removeEventListener("click",G)},layout:b,key:m(y),send:U&&U.sendValue?U.sendValue:null}}function m(l){try{return JSON.stringify(l,function(y,$){return y==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function h(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var y=l.querySelector(":scope > script[data-diagram]");if(y)try{u(l,JSON.parse(y.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:qt,figureKey:Ce,figureList:Fe,hintEntries:Bt,toHtml:_t,escapeHtml:lt,settleEntrance:ye,measureFigure:me},t.diagram=function(l,y){var $=l.__diagram,c=$&&$.send?m(y):null;if(c!==null&&c===$.key){$.send(y.packet?y.packet.send:void 0);return}u(l,y)},e.step(62,"wireDiagrams",h)})(window.Basalt)})(); diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 4bb2bf41..fe317151 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -83,8 +83,9 @@ export interface DiagramPacket { export type DiagramMotion = "still" | "animated"; export type FlowchartNode = DiagramNode & { shape?: "step" | "decision" | "terminal" }; export interface DataFlowLane { id: string; label: string } -export type DataFlowNode = Omit & { lane: string }; -export interface SequenceParticipant { id: string; name: string; kind?: string; short?: string; focal?: boolean } +export type DataFlowNode = Omit & { lane: string; mark?: DiagramMark }; +/** A participant may carry its service's mark (DECISIONS 306, 1.6), never a person. */ +export interface SequenceParticipant { id: string; name: string; kind?: string; short?: string; focal?: boolean; mark?: DiagramMark } /** A message. `activate` starts its receiver working; `deactivate` stops its sender after it (DECISIONS 306, 1.2). */ export type SequenceMessage = { from: string; to: string; label: string; note?: string; kind?: DiagramLineKind; activate?: boolean; deactivate?: boolean }; /** A step: a message, a band, or a frame round a run of steps (`opt`, `loop`, or `alt` with two or more branches). Frames nest two deep. */ @@ -303,10 +304,11 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model nodes.push({ id, i: nodes.length, name: String(raw.name ?? ""), kind: stepWord(n), detail: txt(raw.detail), mono: Boolean(raw.detailMono), focal: Boolean(raw.focal), col: trackOf(raw.col, `the column of ${id}`), row: lane ?? 1, row2: lane ?? 1, branch: false, shape: "box", lane: lane ?? 1, laneLabel: lanes[(lane ?? 1) - 1]?.label ?? laneId, step: n, + mark: markOf((raw as { mark?: unknown }).mark), }); } } else if (type === "sequence") { - (spec.participants ?? []).forEach((p, k) => { const name = String(p.name ?? ""); nodes.push({ id: String(p.id ?? ""), i: k, name, kind: txt(p.kind), mono: false, focal: Boolean(p.focal), col: k + 1, row: 1, row2: 1, branch: false, shape: "participant", short: txt(p.short) ?? name }); }); + (spec.participants ?? []).forEach((p, k) => { const name = String(p.name ?? ""); nodes.push({ id: String(p.id ?? ""), i: k, name, kind: txt(p.kind), mono: false, focal: Boolean(p.focal), col: k + 1, row: 1, row2: 1, branch: false, shape: "participant", short: txt(p.short) ?? name, mark: markOf((p as { mark?: unknown }).mark) }); }); let n = 0; const colOf = new Map(nodes.map((p) => [p.id, p.col])); // Messages number straight through frames. A frame spans the columns of the participants that send or receive inside it, and the column a @@ -457,7 +459,8 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model if (checks) for (const n of nodes) { const says = n.mark?.says; if (!says?.length) continue; - const words = [n.name, n.kind, n.detail].filter(Boolean).join(" ").toLowerCase(); + // A step's lane label counts as its words (DECISIONS 306, 1.6). + const words = [n.name, n.kind, n.detail, n.laneLabel].filter(Boolean).join(" ").toLowerCase(); if (!says.some((w) => words.includes(w.toLowerCase()))) warn(`${n.id}'s mark stands for ${says.join(" or ")}, and none of its words say so`); } // Activation bars (1.2): a stack on each participant. `activate` opens one on the receiver, `deactivate` closes the sender's top one after its message; @@ -1416,7 +1419,8 @@ function minimums(m: Model, tk: Tokens, measure: ReturnType) { } const pad = n.shape === "terminal" ? 2 * s("5") : 2 * s("3"); // The first line (the kind, or the name on a card with no kind) keeps space-6 clear of a mark, except in forced colours, where none is drawn. - const seat = n.mark && !forced() ? s("6") : 0; + // A participant's head centres its words, so its first line keeps space-6 clear on both sides (1.6). + const seat = n.mark && !forced() ? (n.shape === "participant" ? 2 : 1) * s("6") : 0; let widest = 0; // A link card's last word carries its cue, 16 and space-1-5 before it (1.4). const cue = n.href ? 16 + s("1-5") : 0; diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index b8b1a28f..cf41795e 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4542,6 +4542,12 @@ /* A mark with one form for both grounds may set --_ml alone (the skill writes it once): the dark form falls back to it. */ .basalt-diagram-node[data-focal] > .basalt-diagram-mark { --_mf: var(--_dkm) var(--_ml); background-image: var(--_mf, var(--_md, var(--_ml))); } .basalt-diagram-node[data-mark] > .basalt-diagram-mark + :is(.basalt-diagram-kind, .basalt-diagram-name) { padding-inline-end: var(--basalt-space-6); } + /* A participant's head centres its words: its first line keeps space-6 clear on both sides. Stacked, the chip draws the mark inline before the name, + space-1-5 apart; the focal chip takes the other theme's form, as the focal card does (DECISIONS 306, 1.6). */ + .basalt-diagram-node[data-shape="participant"][data-mark] > .basalt-diagram-mark + :is(.basalt-diagram-kind, .basalt-diagram-name) { padding-inline: var(--basalt-space-6); } + .basalt-diagram-node[data-shape="participant"] > .basalt-diagram-mark { --_d-pmp: var(--_drawn) absolute; position: var(--_d-pmp, static); flex: none; margin-inline-end: var(--_d-pmm, var(--basalt-space-1-5)); --_d-pmm: var(--_drawn) 0; } + .basalt-diagram-node[data-shape="participant"][data-mark] { --_d-pfd: var(--_drawn) column; flex-direction: var(--_d-pfd, row); } + .basalt-diagram-node[data-shape="participant"][data-mark] > .basalt-diagram-mark + .basalt-diagram-name { --_d-pnp: var(--_drawn) var(--basalt-space-6); padding-inline: var(--_d-pnp, 0); } /* The focal node: inverted ink; its quiet lines at opacity-amount, at full strength under more contrast. */ .basalt-diagram-node[data-focal] { background: var(--basalt-diagram-focal); border-color: var(--basalt-diagram-focal); } diff --git a/tools/html-skill/src/compose.mjs b/tools/html-skill/src/compose.mjs index 3e5722c6..384add0e 100644 --- a/tools/html-skill/src/compose.mjs +++ b/tools/html-skill/src/compose.mjs @@ -647,9 +647,11 @@ function writeDiagrams(markup, held, parts, notes, marks) { try { spec = JSON.parse(item.inner); } catch (e) { notes.push(`a diagram's JSON does not parse (${e.message}); the page's script will say so`); continue; } // Each card's mark: a bundled id is checked and its rule written once; the page's own mark is read into the page and named by an id, so the JSON // the script reads carries the id and never a path. - if (spec && spec.type === "architecture" && Array.isArray(spec.nodes)) { + // An architecture's cards, a data flow's steps and a sequence's participants may carry one (DECISIONS 306, 1.6). + const cards = spec && (spec.type === "architecture" || spec.type === "data-flow") ? spec.nodes : spec && spec.type === "sequence" ? spec.participants : null; + if (Array.isArray(cards)) { let rewrote = false; - for (const n of spec.nodes) { + for (const n of cards) { if (!n || n.mark === undefined || n.mark === null) continue; if (typeof n.mark === "string") useMark(marks, n.mark, n, notes); else { n.mark = ownMark(marks, n.mark); rewrote = true; } diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx index 01f1a983..1d80e643 100644 --- a/tools/review/round66.tsx +++ b/tools/review/round66.tsx @@ -10,6 +10,11 @@ import * as React from "react"; import { ArchitectureDiagram, DataFlowDiagram, FlowchartDiagram, SchemaDiagram, SequenceDiagram } from "../../packages/react/src/index"; import data from "../../packages/react/test/fixtures/cimip-diagrams-b.json"; import type { Round } from "./rounds"; +import { awsEcsService } from "../../packages/react/src/marks/aws-ecs-service"; +import { awsEcsTask } from "../../packages/react/src/marks/aws-ecs-task"; + +// Marks on a sequence's participants (DECISIONS 306, 1.6): the service and the sandbox, and none on Marcus, who is a person. +const PARTICIPANT_MARKS: Record = { svc: awsEcsService, agent: awsEcsTask }; type Key = keyof typeof data; const isShot = () => new URLSearchParams(window.location.search).get("shot") === "1"; @@ -35,7 +40,8 @@ function Diagram({ k, state }: { k: Key; state: string }) { ready(); })(); }, [state]); - const { type, ...props } = data[k] as unknown as { type: string } & Record; + const { type, ...props } = structuredClone(data[k]) as unknown as { type: string } & Record; + if (type === "sequence") for (const p of props.participants as Array<{ id: string; mark?: unknown }>) if (PARTICIPANT_MARKS[p.id]) p.mark = PARTICIPANT_MARKS[p.id]; const figure = (() => { switch (type) { case "architecture": return )} />; From 6860c460f3d2f1910ad49efc9c1d1b7dc29b0ee9 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:52:48 -0600 Subject: [PATCH 17/62] An entrance only on a first visit (DECISIONS 306, 1.5) entrance="first-visit" (with an id): the mark basalt-diagram-entrance:# is written in localStorage when an entrance that played finishes or gives way to the reader, never on a visit at rest by mode; a later visit is at rest from its first frame (a few bytes in the still engine, the rest in the lazy motion module). Storage that throws plays again. A development build warns without an id. SequenceDiagram also takes frameLabels, and the new types are exported. Co-Authored-By: Claude Opus 5.5 --- .../basalt-html/parts/diagram-motion.js | 2 +- .agent/skills/basalt-html/parts/diagram.js | 6 +++--- packages/react/src/architecture-diagram.tsx | 6 +++--- packages/react/src/data-flow-diagram.tsx | 6 +++--- packages/react/src/diagram-core.ts | 19 ++++++++++++++++--- packages/react/src/diagram-figure.tsx | 7 +++++-- packages/react/src/diagram-motion-core.ts | 17 +++++++++++++++-- packages/react/src/flowchart-diagram.tsx | 6 +++--- packages/react/src/index.ts | 2 +- packages/react/src/schema-diagram.tsx | 6 +++--- packages/react/src/sequence-diagram.tsx | 14 +++++++++----- 11 files changed, 62 insertions(+), 29 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram-motion.js b/.agent/skills/basalt-html/parts/diagram-motion.js index 5c7f07ab..7aebfc97 100644 --- a/.agent/skills/basalt-html/parts/diagram-motion.js +++ b/.agent/skills/basalt-html/parts/diagram-motion.js @@ -1 +1 @@ -(()=>{var C=Object.defineProperty,T=(t,s,e)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s,e)=>T(t,typeof s!="symbol"?s+"":s,e);function P(t,s){const e=r=>String(Math.round(r*100)/100);let i=`M${e(t[0].x)} ${e(t[0].y)}`;for(let r=1;r{for(const h of p?.figs??[])h.sync()},e=()=>{for(const h of p?.figs??[])x(h.host.fig);s()},i=new IntersectionObserver(h=>{for(const o of h)for(const a of p?.figs??[])a.drawing===o.target&&a.seen(o)},{threshold:Array.from({length:21},(h,o)=>o/20)}),n=new MutationObserver(h=>{for(const o of h){if(o.target===document.documentElement){for(const a of p?.figs??[])a.holdChanged();continue}for(const a of p?.figs??[])a.host.fig===o.target&&a.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const r=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of r)h.addEventListener("change",s);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",s),p={figs:new Set,io:i,mo:n,media:r,onChange:s,onPrint:e}}return p.figs.add(t),t.drawing&&p.io.observe(t.drawing),p.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),p}function O(t){if(p&&(p.figs.delete(t),t.drawing&&p.io.unobserve(t.drawing),!p.figs.size)){p.io.disconnect(),p.mo.disconnect();for(const s of p.media)s.removeEventListener("change",p.onChange);window.removeEventListener("beforeprint",p.onPrint),document.removeEventListener("visibilitychange",p.onChange),p=void 0}}function _(t){const s=getComputedStyle(t),e=h=>s.getPropertyValue(`--basalt-${h}`).trim(),i=h=>{const o=e(h),a=parseFloat(o);return/ms$/.test(o)?a:/s$/.test(o)?a*1e3:a||0},n=h=>parseFloat(e(h))||0,r=h=>e(`ease-${h}`)||"ease";return{lineMin:i("duration-diagram-line-min"),lineMax:i("duration-diagram-line-max"),stagger:i("duration-diagram-stagger"),step:i("duration-diagram-step"),arrow:i("duration-diagram-arrow"),limit:i("duration-diagram-limit"),legMin:i("duration-diagram-leg-min"),legMax:i("duration-diagram-leg-max"),rest:i("duration-diagram-rest"),pause:i("duration-diagram-pause"),repeat:i("duration-diagram-repeat"),fast:i("duration-fast"),base:i("duration-base"),slow:i("duration-slow"),slower:i("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:r("in-out"),out:r("out"),in:r("in")}}var L=(t,s,e)=>Math.max(s,Math.min(e,t)),F="http://www.w3.org/2000/svg",y=(t,s,e)=>{const i=document.createElementNS(F,t);for(const[n,r]of Object.entries(s))i.setAttribute(n,String(r));return e?.appendChild(i),i},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",I={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function v(t,s){const e=t.pts.map(a=>({...a})),i=I[t.dir],n=e[e.length-1],r=e[e.length-2],h=Math.hypot(n.x-r.x,n.y-r.y),o=Math.min(s,Math.max(0,h-.5));return n.x-=i.x*o,n.y-=i.y*o,e}var M=t=>t.slice(1).reduce((s,e,i)=>s+Math.hypot(e.x-t[i].x,e.y-t[i].y),0),R=(t,s)=>{const e=t.map(n=>n.x),i=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-s),t:Math.floor(Math.min(...i)-s),r:Math.ceil(Math.max(...e)+s),b:Math.ceil(Math.max(...i)+s)}},V=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",s=>(this.listeners.add(s),()=>{this.listeners.delete(s)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const s of[...this.flowEls.values(),...this.beadEls.values()])s.remove();this.dot?.remove(),O(this)}}),c(this,"onSettle",()=>{this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const i=this.introEnd?.currentTime,n=i!=null?Number(i):E()-this.t0,r=new Set([...this.plans].filter(([,a])=>a.end<=n).map(([a])=>a)),{plans:h,factor:o}=this.plan(this.ordered(e),this.factor);for(const a of r){const l=this.plans.get(a);l&&h.set(a,l)}this.factor=o,this.plans=h,this.build(r,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const s=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(i=>!!i.flow)]);s!==this.signature&&(this.signature=s,x(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",s=>{if(!this.lastSend){this.lastSend={v:s};return}s===void 0||s===this.lastSend.v||(this.lastSend={v:s},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}x(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=_(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=G(this),this.sync()}publish(){const t=this.hasLines(),s=this.host.model(),e=this.modes(),i=s.edges.some(r=>r.flow)||!!s.motion.pulse||!!s.motion.packet?.repeat,n={canLoop:s.motion.animated&&i&&t&&!e.reduce&&!e.forced,runShown:s.motion.animated&&s.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const r of this.listeners)r()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const s=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=s-.5,this.sync()}holdChanged(){this.modes().held&&x(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,s=this.host.model(),e=this.modes(),i=this.entrance();(i==="pending"||i==="running")&&(e.held||e.print||e.reduce||e.forced)?x(t):i==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!i&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(s,e),this.publish()}ordered(t){const s=this.host.model(),e=[...t.lines];return s.type==="schema"?e.sort((i,n)=>i.pts[0].y-n.pts[0].y||i.pts[0].x-n.pts[0].x||i.i-n.i):e.sort((i,n)=>i.i-n.i),e}plan(t,s){const e=this.t,i=this.host.model().type==="sequence",n=i?e.step:e.stagger,r=t.map(a=>{const l=this.lineEl(a)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(a.pts),m=i?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=i?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,i?e.slower:0)}});let h=1;for(let a=1;a{const d=l*n*h;o.set(a.i,{start:d+r[l].lead,dur:r[l].dur,end:d+r[l].tail})}),{plans:o,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.t0=E();const{plans:s,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=s,this.build(new Set,!0)}build(t,s){const e=this.host.geo(),i=this.host.fig,{P:n}=this.host,r=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const o=i.querySelector(`.${n}-ink`),a=o?.querySelector(`.${n}-svg`);if(!o||!a)return;this.defs=y("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),a.after(this.defs);const l=y("defs",{},this.defs),d=(u,g=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),g.add(u),u);let m=0;for(const u of e.lines){const g=this.plans.get(u.i),f=this.lineEl(u);if(!g||!f)continue;if(m=Math.max(m,g.end),t.has(u.i)){f.removeAttribute("mask");continue}const w=`${this.host.base}-reveal-${u.i}`,k=y("mask",{id:w,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),A=f.querySelector(`.${n}-line`);if(A){const b=A.getTotalLength(),z=y("path",{d:A.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${b} ${b+8}`,"stroke-dashoffset":b},k);d(z.animate([{strokeDashoffset:`${b}px`},{strokeDashoffset:"0px"}],{duration:g.dur,delay:g.start,easing:r.inOut,fill:"both"}))}const S=f.querySelector(`.${n}-tip`);if(S){const b=y("path",{d:S.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:r.slow,delay:g.start+.85*g.dur,easing:r.out,fill:"both"}))}const $=f.querySelector(`.${n}-dot`);if($){const b=y("circle",{cx:$.getAttribute("cx")??0,cy:$.getAttribute("cy")??0,r:Number($.getAttribute("r")??3)+1,fill:"#fff"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:r.fast,delay:g.start,easing:r.out,fill:"both"}))}f.setAttribute("mask",`url(#${w})`)}if(s&&this.host.model().type==="sequence"){const u=getComputedStyle(i),g=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),w=i.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((k,A)=>{const S=w[A]?.querySelector(`.${n}-mlabel`),$=this.plans.get(k.i);S&&$&&g&&f&&d(S.animate([{color:g},{color:f}],{duration:r.slower,delay:$.start-r.base,easing:r.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(i.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,s){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||s.reduce||s.forced||s.print||s.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,s){s.add(t);const e=()=>{s.delete(t)};return t.finished.then(e,e),s===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,s){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),s).finished.then(e=>{e.cancel()})}overlay(t,s,e){const i=this.host.fig.querySelector(`.${this.host.P}-ink`),n=i?.querySelector(`.${this.host.P}-svg`);if(!i||!n)return null;const r=this.host.tokens(),h=v(t,r?.head??8),o=R(h,s),a=y("svg",{class:`${this.host.P}-${e}`,width:o.r-o.l,height:o.b-o.t,viewBox:`${o.l} ${o.t} ${o.r-o.l} ${o.b-o.t}`,"aria-hidden":"true",focusable:"false"});a.style.left=`${o.l}px`,a.style.top=`${o.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(a),{svg:a,d:P(h,t.from===t.to?r?.radiusXs??4:r?.radius??8),pts:h}}visible(t,s){const e=this.host.geo();let i=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const r=(n.box.t+n.box.b)/2,h=s.some((o,a)=>a>0&&Math.abs(o.y-s[a-1].y)<.5&&Math.abs(r-o.y)<1.5);i+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(s)-i}flow(t,s){const e=t.lines.find(o=>o.i===s);if(!e)return;const i=this.host.tokens();if(e.kind==="dashed"){if(this.visible(e,v(e,i?.head??8))<48)return;const o=this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${s}"] .${this.host.P}-line`);if(!o)return;const a=(i?.dash??6)+(i?.dashGap??4);this.track(o.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-a}px`}],{duration:a/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops);return}let n=this.flowEls.get(s);if(n&&!n.isConnected&&(this.flowEls.delete(s),n=void 0),!n){const o=i?.space("1")??4,a=this.overlay({...e,pts:v(e,o)},e.width+2,"flow");if(!a)return;if(this.visible(e,v(e,i?.head??8))<48){a.svg.remove();return}const l=i?.cut??2;y("path",{d:a.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},a.svg),n=a.svg,this.flowEls.set(s,n)}n.style.display="";const r=n.firstElementChild,h=this.t.flowPeriod;this.track(r.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,s){const i=this.host.model().edges.find(n=>n.from===t&&n.to===s);return i?this.host.geo()?.lines.find(n=>n.i===i.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,s){const e=this.host.tokens();for(;t===this.loopGen;){for(let i=1;it===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(s,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const i=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=i;try{await i.finished}finally{this.repeatGap===i&&(this.repeatGap=null),i.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),s=t.motion.packet?.path;if(!t.motion.animated||!s||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(s[s.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const i=++this.runGen;this.packetRun(s,this.runAnims,()=>i===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&i===this.runGen&&(this.waiting=!1,this.send())})}stopRun(){this.runGen++,this.runAt=-1;for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const s=this.host.geo();if(!s?.lines.length)return;for(const o of this.runAnims)o.cancel();this.runAnims.clear();const e=++this.runGen,i=()=>e===this.runGen,n=this.ordered(s),r=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let o=t;o{if(!q(o))throw o})}};function D(t){const s=[],e=[],{pulse:i,packet:n}=t.motion;i&&n&&s.push("a figure names both a pulse and a packet: it has one mover at most");const r=i??n?.path,h=i?"pulse":"packet",o=new Set;if(r){for(const a of r)t.byId.has(a)||s.push(`the ${h} names ${a}, which is not a node`);for(let a=1;ad.from===r[a-1]&&d.to===r[a]);l?o.add(l.i):s.push(`the ${h} goes from ${r[a-1]} to ${r[a]}, and no line joins them in that direction`)}}for(const a of t.edges)a.flow&&(o.has(a.i)&&s.push(`the line from ${a.from} to ${a.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),a.label||e.push(`the line from ${a.from} to ${a.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:s,warnings:e}}function N(t){return new V(t)}(function(t){"use strict";var s=t._;function e(i,n,r){var h=document.createElement("button");return h.type="button",h.className="btn "+i,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),r&&r(h),h.appendChild(document.createTextNode(n)),h}s.diagramMotion=function(i,n,r){var h=D(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var o=N(n),a=i.querySelector(".diagram-foot"),l=null,d=null;a&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){o.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var w=document.createElement("span");w.className="btn-check",w.setAttribute("aria-hidden","true"),f.appendChild(w)}),l.hidden=d.hidden=!0,a.appendChild(l),a.appendChild(d));function m(){var f=o.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=o.subscribe(m);m();var g=r&&r.packet?r.packet.send:void 0;return o.sendValue("__diagramSend"in i?i.__diagramSend:g),o.sendValue(g),i.__diagramSend=g,{redrawn:o.redrawn,sendValue:function(f){o.sendValue(f),i.__diagramSend=f},destroy:function(){u(),o.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); +(()=>{var C=Object.defineProperty,T=(t,s,e)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s,e)=>T(t,typeof s!="symbol"?s+"":s,e);function P(t,s){const e=r=>String(Math.round(r*100)/100);let i=`M${e(t[0].x)} ${e(t[0].y)}`;for(let r=1;r`basalt-diagram-entrance:${location.pathname}#${t.id}`;function k(t){const s=t.getAttribute("data-entrance");s!=="pending"&&s!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}var p;function O(t){if(!p){const s=()=>{for(const h of p?.figs??[])h.sync()},e=()=>{for(const h of p?.figs??[])k(h.host.fig);s()},i=new IntersectionObserver(h=>{for(const o of h)for(const a of p?.figs??[])a.drawing===o.target&&a.seen(o)},{threshold:Array.from({length:21},(h,o)=>o/20)}),n=new MutationObserver(h=>{for(const o of h){if(o.target===document.documentElement){for(const a of p?.figs??[])a.holdChanged();continue}for(const a of p?.figs??[])a.host.fig===o.target&&a.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const r=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of r)h.addEventListener("change",s);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",s),p={figs:new Set,io:i,mo:n,media:r,onChange:s,onPrint:e}}return p.figs.add(t),t.drawing&&p.io.observe(t.drawing),p.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),p}function _(t){if(p&&(p.figs.delete(t),t.drawing&&p.io.unobserve(t.drawing),!p.figs.size)){p.io.disconnect(),p.mo.disconnect();for(const s of p.media)s.removeEventListener("change",p.onChange);window.removeEventListener("beforeprint",p.onPrint),document.removeEventListener("visibilitychange",p.onChange),p=void 0}}function F(t){const s=getComputedStyle(t),e=h=>s.getPropertyValue(`--basalt-${h}`).trim(),i=h=>{const o=e(h),a=parseFloat(o);return/ms$/.test(o)?a:/s$/.test(o)?a*1e3:a||0},n=h=>parseFloat(e(h))||0,r=h=>e(`ease-${h}`)||"ease";return{lineMin:i("duration-diagram-line-min"),lineMax:i("duration-diagram-line-max"),stagger:i("duration-diagram-stagger"),step:i("duration-diagram-step"),arrow:i("duration-diagram-arrow"),limit:i("duration-diagram-limit"),legMin:i("duration-diagram-leg-min"),legMax:i("duration-diagram-leg-max"),rest:i("duration-diagram-rest"),pause:i("duration-diagram-pause"),repeat:i("duration-diagram-repeat"),fast:i("duration-fast"),base:i("duration-base"),slow:i("duration-slow"),slower:i("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:r("in-out"),out:r("out"),in:r("in")}}var L=(t,s,e)=>Math.max(s,Math.min(e,t)),I="http://www.w3.org/2000/svg",y=(t,s,e)=>{const i=document.createElementNS(I,t);for(const[n,r]of Object.entries(s))i.setAttribute(n,String(r));return e?.appendChild(i),i},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",V={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function v(t,s){const e=t.pts.map(a=>({...a})),i=V[t.dir],n=e[e.length-1],r=e[e.length-2],h=Math.hypot(n.x-r.x,n.y-r.y),o=Math.min(s,Math.max(0,h-.5));return n.x-=i.x*o,n.y-=i.y*o,e}var M=t=>t.slice(1).reduce((s,e,i)=>s+Math.hypot(e.x-t[i].x,e.y-t[i].y),0),R=(t,s)=>{const e=t.map(n=>n.x),i=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-s),t:Math.floor(Math.min(...i)-s),r:Math.ceil(Math.max(...e)+s),b:Math.ceil(Math.max(...i)+s)}},D=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",s=>(this.listeners.add(s),()=>{this.listeners.delete(s)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const s of[...this.flowEls.values(),...this.beadEls.values()])s.remove();this.dot?.remove(),_(this)}}),c(this,"played",!1),c(this,"onSettle",()=>{this.played&&!this.byMode()&&this.markVisit(),this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const i=this.introEnd?.currentTime,n=i!=null?Number(i):E()-this.t0,r=new Set([...this.plans].filter(([,a])=>a.end<=n).map(([a])=>a)),{plans:h,factor:o}=this.plan(this.ordered(e),this.factor);for(const a of r){const l=this.plans.get(a);l&&h.set(a,l)}this.factor=o,this.plans=h,this.build(r,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const s=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(i=>!!i.flow)]);s!==this.signature&&(this.signature=s,k(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",s=>{if(!this.lastSend){this.lastSend={v:s};return}s===void 0||s===this.lastSend.v||(this.lastSend={v:s},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}k(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=F(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=O(this),this.sync()}publish(){const t=this.hasLines(),s=this.host.model(),e=this.modes(),i=s.edges.some(r=>r.flow)||!!s.motion.pulse||!!s.motion.packet?.repeat,n={canLoop:s.motion.animated&&i&&t&&!e.reduce&&!e.forced,runShown:s.motion.animated&&s.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const r of this.listeners)r()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}byMode(){const t=this.modes();return t.held||t.print||t.reduce||t.forced}markVisit(){const t=this.host.fig;if(!(!t.hasAttribute("data-first-visit")||!t.id))try{localStorage.setItem(G(t),"1")}catch{}}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const s=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=s-.5,this.sync()}holdChanged(){this.modes().held&&k(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,s=this.host.model(),e=this.modes(),i=this.entrance();(i==="pending"||i==="running")&&(e.held||e.print||e.reduce||e.forced)?k(t):i==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!i&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(s,e),this.publish()}ordered(t){const s=this.host.model(),e=[...t.lines];return s.type==="schema"?e.sort((i,n)=>i.pts[0].y-n.pts[0].y||i.pts[0].x-n.pts[0].x||i.i-n.i):e.sort((i,n)=>i.i-n.i),e}plan(t,s){const e=this.t,i=this.host.model().type==="sequence",n=i?e.step:e.stagger,r=t.map(a=>{const l=this.lineEl(a)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(a.pts),m=i?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=i?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,i?e.slower:0)}});let h=1;for(let a=1;a{const d=l*n*h;o.set(a.i,{start:d+r[l].lead,dur:r[l].dur,end:d+r[l].tail})}),{plans:o,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.played=!0,this.t0=E();const{plans:s,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=s,this.build(new Set,!0)}build(t,s){const e=this.host.geo(),i=this.host.fig,{P:n}=this.host,r=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const o=i.querySelector(`.${n}-ink`),a=o?.querySelector(`.${n}-svg`);if(!o||!a)return;this.defs=y("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),a.after(this.defs);const l=y("defs",{},this.defs),d=(u,g=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),g.add(u),u);let m=0;for(const u of e.lines){const g=this.plans.get(u.i),f=this.lineEl(u);if(!g||!f)continue;if(m=Math.max(m,g.end),t.has(u.i)){f.removeAttribute("mask");continue}const w=`${this.host.base}-reveal-${u.i}`,x=y("mask",{id:w,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),A=f.querySelector(`.${n}-line`);if(A){const b=A.getTotalLength(),B=y("path",{d:A.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${b} ${b+8}`,"stroke-dashoffset":b},x);d(B.animate([{strokeDashoffset:`${b}px`},{strokeDashoffset:"0px"}],{duration:g.dur,delay:g.start,easing:r.inOut,fill:"both"}))}const S=f.querySelector(`.${n}-tip`);if(S){const b=y("path",{d:S.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},x);d(b.animate([{opacity:0},{opacity:1}],{duration:r.slow,delay:g.start+.85*g.dur,easing:r.out,fill:"both"}))}const $=f.querySelector(`.${n}-dot`);if($){const b=y("circle",{cx:$.getAttribute("cx")??0,cy:$.getAttribute("cy")??0,r:Number($.getAttribute("r")??3)+1,fill:"#fff"},x);d(b.animate([{opacity:0},{opacity:1}],{duration:r.fast,delay:g.start,easing:r.out,fill:"both"}))}f.setAttribute("mask",`url(#${w})`)}if(s&&this.host.model().type==="sequence"){const u=getComputedStyle(i),g=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),w=i.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((x,A)=>{const S=w[A]?.querySelector(`.${n}-mlabel`),$=this.plans.get(x.i);S&&$&&g&&f&&d(S.animate([{color:g},{color:f}],{duration:r.slower,delay:$.start-r.base,easing:r.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(i.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.markVisit(),this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,s){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||s.reduce||s.forced||s.print||s.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,s){s.add(t);const e=()=>{s.delete(t)};return t.finished.then(e,e),s===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,s){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),s).finished.then(e=>{e.cancel()})}overlay(t,s,e){const i=this.host.fig.querySelector(`.${this.host.P}-ink`),n=i?.querySelector(`.${this.host.P}-svg`);if(!i||!n)return null;const r=this.host.tokens(),h=v(t,r?.head??8),o=R(h,s),a=y("svg",{class:`${this.host.P}-${e}`,width:o.r-o.l,height:o.b-o.t,viewBox:`${o.l} ${o.t} ${o.r-o.l} ${o.b-o.t}`,"aria-hidden":"true",focusable:"false"});a.style.left=`${o.l}px`,a.style.top=`${o.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(a),{svg:a,d:P(h,t.from===t.to?r?.radiusXs??4:r?.radius??8),pts:h}}visible(t,s){const e=this.host.geo();let i=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const r=(n.box.t+n.box.b)/2,h=s.some((o,a)=>a>0&&Math.abs(o.y-s[a-1].y)<.5&&Math.abs(r-o.y)<1.5);i+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(s)-i}flow(t,s){const e=t.lines.find(o=>o.i===s);if(!e)return;const i=this.host.tokens();if(e.kind==="dashed"){if(this.visible(e,v(e,i?.head??8))<48)return;const o=this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${s}"] .${this.host.P}-line`);if(!o)return;const a=(i?.dash??6)+(i?.dashGap??4);this.track(o.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-a}px`}],{duration:a/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops);return}let n=this.flowEls.get(s);if(n&&!n.isConnected&&(this.flowEls.delete(s),n=void 0),!n){const o=i?.space("1")??4,a=this.overlay({...e,pts:v(e,o)},e.width+2,"flow");if(!a)return;if(this.visible(e,v(e,i?.head??8))<48){a.svg.remove();return}const l=i?.cut??2;y("path",{d:a.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},a.svg),n=a.svg,this.flowEls.set(s,n)}n.style.display="";const r=n.firstElementChild,h=this.t.flowPeriod;this.track(r.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,s){const i=this.host.model().edges.find(n=>n.from===t&&n.to===s);return i?this.host.geo()?.lines.find(n=>n.i===i.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,s){const e=this.host.tokens();for(;t===this.loopGen;){for(let i=1;it===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(s,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const i=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=i;try{await i.finished}finally{this.repeatGap===i&&(this.repeatGap=null),i.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),s=t.motion.packet?.path;if(!t.motion.animated||!s||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(s[s.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const i=++this.runGen;this.packetRun(s,this.runAnims,()=>i===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&i===this.runGen&&(this.waiting=!1,this.send())})}stopRun(){this.runGen++,this.runAt=-1;for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const s=this.host.geo();if(!s?.lines.length)return;for(const o of this.runAnims)o.cancel();this.runAnims.clear();const e=++this.runGen,i=()=>e===this.runGen,n=this.ordered(s),r=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let o=t;o{if(!q(o))throw o})}};function N(t){const s=[],e=[],{pulse:i,packet:n}=t.motion;i&&n&&s.push("a figure names both a pulse and a packet: it has one mover at most");const r=i??n?.path,h=i?"pulse":"packet",o=new Set;if(r){for(const a of r)t.byId.has(a)||s.push(`the ${h} names ${a}, which is not a node`);for(let a=1;ad.from===r[a-1]&&d.to===r[a]);l?o.add(l.i):s.push(`the ${h} goes from ${r[a-1]} to ${r[a]}, and no line joins them in that direction`)}}for(const a of t.edges)a.flow&&(o.has(a.i)&&s.push(`the line from ${a.from} to ${a.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),a.label||e.push(`the line from ${a.from} to ${a.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:s,warnings:e}}function z(t){return new D(t)}(function(t){"use strict";var s=t._;function e(i,n,r){var h=document.createElement("button");return h.type="button",h.className="btn "+i,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),r&&r(h),h.appendChild(document.createTextNode(n)),h}s.diagramMotion=function(i,n,r){var h=N(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var o=z(n),a=i.querySelector(".diagram-foot"),l=null,d=null;a&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){o.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var w=document.createElement("span");w.className="btn-check",w.setAttribute("aria-hidden","true"),f.appendChild(w)}),l.hidden=d.hidden=!0,a.appendChild(l),a.appendChild(d));function m(){var f=o.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=o.subscribe(m);m();var g=r&&r.packet?r.packet.send:void 0;return o.sendValue("__diagramSend"in i?i.__diagramSend:g),o.sendValue(g),i.__diagramSend=g,{redrawn:o.redrawn,sendValue:function(f){o.sendValue(f),i.__diagramSend=f},destroy:function(){u(),o.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 653a8e03..3169c517 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,6 +1,6 @@ (()=>{var ve=["top","right","bottom","left"],xe=["main","plain","dashed"],ke=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ut=t=>Object.assign(Object.create(null),t),gt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function qt(t,e={}){const s=e.checks!==!1,r=[],o=p=>{r.push(p)},a=t.legend??{},i={};for(const p of["main","plain","dashed","focal","group","activation"]){const w=at(a[p]);w&&(i[p]=w)}const d=t.stepLabel,u=typeof d=="function"?p=>String(d(p)):typeof d=="string"?(p=>d.replace("{n}",String(p))):p=>`Step ${p}`,m=t.shapeLabels??{},h={terminal:at(m.terminal)??"Start or end",step:at(m.step)??"Step",decision:at(m.decision)??"Decision"},l=t.heading===void 0?3:ke.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),y=(p,w)=>p==null?"plain":xe.includes(p)?p:(o(`"${String(p)}" is not a kind of line (main, plain or dashed): ${w} is drawn plain`),"plain"),$=p=>{if(p!=null){if(ve.includes(p))return p;o(`"${String(p)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(p,w)=>typeof p=="number"&&Number.isInteger(p)&&p>=1?p:(o(`${w} is ${JSON.stringify(p)}, not a whole number from 1: it is placed at 1`),1),f=[],v=[];let B=[];const C=[],M=[],I=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(I)||o(`"${String(I)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),I==="architecture"||I==="flowchart"){for(const p of t.nodes??[]){const w=I==="flowchart"&&p.shape==="decision"?"decision":I==="flowchart"&&p.shape==="terminal"?"terminal":"box",S=String(p.id??""),g=c(p.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(p.name??""),kind:w==="decision"?void 0:at(p.kind),detail:w==="decision"?void 0:at(p.detail),mono:!!p.detailMono,focal:!!p.focal,col:c(p.col,`the column of ${S}`),row:g,row2:g,branch:!!p.branch,shape:w,group:I==="architecture"?at(p.group):void 0,mark:I==="architecture"?It(p.mark):void 0})}if(I==="architecture"){const p=(t.groups??[]).map(b=>({id:String(b.id??""),label:String(b.label??""),parent:at(b.parent)})),w=new Map(p.map(b=>[b.id,b])),S=b=>{if(!b.parent)return 1;const x=w.get(b.parent);return x?x.parent===b.id||x.id===b.id?(o(`the groups "${b.label}" and "${x.label}" are each other's parent`),b.parent=void 0,1):x.parent?(o(`the group "${b.label}" is a third level: groups nest two deep`),b.parent=void 0,1):2:(o(`the group "${b.label}" names the parent "${b.parent}", which is not a group`),b.parent=void 0,1)},g=p.map(S);p.forEach((b,x)=>C.push({...b,depth:g[x],members:f.filter(E=>E.group===b.id).map(E=>E.id),all:[]}));for(const b of C)b.all=[...b.members,...C.filter(x=>x.parent===b.id).flatMap(x=>x.members)];C.sort((b,x)=>b.depth-x.depth)}}else if(I==="data-flow"){B=(t.lanes??[]).map(w=>({id:String(w.id??""),label:String(w.label??"")}));const p=new Map(B.map((w,S)=>[w.id,S+1]));for(const w of t.nodes??[]){const S=String(w.id??""),g=String(w.lane??""),b=p.get(g);b===void 0&&o(`a node (${S}) names the lane "${g}", which is not in lanes`);const x=f.length+1;f.push({id:S,i:f.length,name:String(w.name??""),kind:u(x),detail:at(w.detail),mono:!!w.detailMono,focal:!!w.focal,col:c(w.col,`the column of ${S}`),row:b??1,row2:b??1,branch:!1,shape:"box",lane:b??1,laneLabel:B[(b??1)-1]?.label??g,step:x,mark:It(w.mark)})}}else if(I==="sequence"){(t.participants??[]).forEach((g,b)=>{const x=String(g.name??"");f.push({id:String(g.id??""),i:b,name:x,kind:at(g.kind),mono:!1,focal:!!g.focal,col:b+1,row:1,row2:1,branch:!1,shape:"participant",short:at(g.short)??x,mark:It(g.mark)})});let p=0;const w=new Map(f.map(g=>[g.id,g.col])),S=(g,b)=>{let x=1/0,E=-1/0;for(const A of g??[]){if(!A||typeof A!="object")continue;if("band"in A){b>0&&o(`the band "${String(A.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(A.band??"")});continue}if("frame"in A){if(b>=2){o("a frame is a third level: frames nest two deep");continue}const nt=A.frame==="alt"||A.frame==="loop"||A.frame==="opt"?A.frame:"opt",et=nt==="alt"?A.branches??[]:[{label:A.label,steps:A.steps}];nt==="alt"&&et.length<2&&o("an alt frame has one branch: it needs two or more");const X=String(et[0]?.label??"");X.length>40&&o(`the frame label "${X}" is over 40 characters`);const ot=M.length;M.push({open:nt,label:X,depth:b+1,a:0,b:0}),et.forEach((Y,st)=>{if(st){const it=String(Y.label??"");it.length>40&&o(`the frame label "${it}" is over 40 characters`),M.push({otherwise:it,depth:b+1})}Y.steps?.length||o(`a frame or branch ("${String(Y.label??"")}") is empty`);const[rt,R]=S(Y.steps??[],b+1);x=Math.min(x,rt),E=Math.max(E,R);const P=M[ot];P.a=Math.min(P.a||1/0,rt),P.b=Math.max(P.b,R)}),M.push({close:b+1});continue}p++;const T=String(A.label??"");T.includes(` `)&&o(`message ${p}'s label has a break: a message's second line is its note`);const K=String(A.from??""),Q=String(A.to??"");M.push({n:p,from:K,to:Q,label:pt(T),note:at(A.note),kind:y(A.kind,`message ${p}`),activate:A.activate===!0||void 0,deactivate:A.deactivate===!0||void 0});const J=w.get(K)??1,z=w.get(Q)??1,G=J===z?J===f.length?J-1:J+1:J;x=Math.min(x,J,z,G),E=Math.max(E,J,z,G)}return[x,E]};S(t.steps??[],0);for(const g of M)"open"in g&&!Number.isFinite(g.a)&&(g.a=1,g.b=Math.max(1,f.length))}else if(I==="schema")for(const p of t.tables??[]){const w=String(p.name??""),[S,g]=Array.isArray(p.row)?p.row:[p.row,p.row],b=c(S,`the row of ${w}`),x=Math.max(b,c(g,`the last row of ${w}`)),E=p.more===void 0||p.more===null?void 0:Number.isInteger(p.more)&&p.more>0?p.more:(o(`${w}'s "more" is ${JSON.stringify(p.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:w,i:f.length,name:w,mono:!0,focal:!!p.focal,col:c(p.col,`the column of ${w}`),row:b,row2:x,branch:!1,shape:"table",more:E,columns:(p.columns??[]).map(A=>({name:String(A.name??""),type:at(A.type),key:A.key==="PK"||A.key==="FK"?A.key:(A.key!==void 0&&A.key!==null&&o(`${w}.${String(A.name)}'s key is "${String(A.key)}", not PK or FK: it is left out`),void 0)}))})}((I==="schema"?t.tables:I==="sequence"?t.participants:t.nodes)??[]).forEach((p,w)=>{if(!p||p.href===void 0||p.href===null)return;const S=String(p.href);if(I==="sequence"){o(`${f[w]?.id}: a participant cannot be a link (href)`);return}if(!S){o(`${f[w]?.id}'s href is empty`);return}const g=f[w];g&&(g.href=S,g.blank=p.target==="_blank")});const D=new Map;for(const p of f)p.id?D.has(p.id)&&o(`the id "${p.id}" is used twice`):o("a node has no id"),D.set(p.id,p);if(I==="schema")(t.tables??[]).forEach(p=>(p.columns??[]).forEach((w,S)=>{const g=at(w.references);if(!g)return;const[b,x]=g.split("."),E=D.get(b??""),A=E?.columns?.findIndex(K=>K.name===x)??-1;if(!E||A<0){o(`${String(p.name)}.${String(w.name)} references ${g}, which is not a shown column`);return}const T=D.get(String(p.name??""));T.columns[S].ref={table:b,column:x,row:A},v.push({i:v.length,from:T.id,to:b,kind:"plain",fromRow:S,toRow:A,fk:!0})}));else if(I!=="sequence")for(const p of t.edges??[]){const w=String(p.from??""),S=String(p.to??"");if(!D.has(w)||!D.has(S)){o(`a line names ${D.has(w)?S:w}, which is not a node`);continue}const g=at(p.label),b=g?.split(` -`)??[];b.length>2&&o(`the label "${pt(g)}" has more than one break: a label is two lines at most`),b.some(x=>x.length>zt)&&o(`a line of the label "${pt(g)}" is over ${zt} characters: longer words belong in the node or the summary`),v.push({i:v.length,from:w,to:S,kind:y(p.kind,`the line from ${w} to ${S}`),label:g,fromSide:$(p.fromSide),toSide:$(p.toSide),flow:I!=="flowchart"&&p.flow===!0?!0:void 0})}else for(const p of M)"n"in p&&(!D.has(p.from)||!D.has(p.to))&&o(`message ${p.n} names ${D.has(p.from)?p.to:p.from}, which is not a participant`);if(s&&I!=="sequence"){const p=new Map;for(const w of f)for(let S=w.row;S<=w.row2;S++){const g=`${w.col}:${S}`;p.has(g)&&o(`${w.id} and ${p.get(g)} share the cell at column ${w.col}, row ${S}`),p.set(g,w.id)}}if(s){for(const w of C){const S=w.all.map(x=>D.get(x));if(!S.length)continue;const g={c1:Math.min(...S.map(x=>x.col)),c2:Math.max(...S.map(x=>x.col)),r1:Math.min(...S.map(x=>x.row)),r2:Math.max(...S.map(x=>x.row2))};for(const x of f)!w.all.includes(x.id)&&x.col>=g.c1&&x.col<=g.c2&&x.row>=g.r1&&x.row<=g.r2&&o(`${x.id} is inside the box of the group "${w.label}" but not a member`);const b=S.map(x=>x.i);Math.max(...b)-Math.min(...b)+1!==b.length&&o(`the members of the group "${w.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const w of f)w.group&&!C.some(S=>S.id===w.group)&&o(`${w.id} names the group "${w.group}", which is not in groups`);f.filter(w=>w.focal).length>1&&o("more than one node is focal: a diagram has one at most");const p=new Set(I==="sequence"?M.flatMap(w=>"n"in w?[w.kind]:[]):v.map(w=>w.kind));p.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),p.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(w=>w.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const O=I==="architecture"||I==="data-flow",V=p=>Array.isArray(p)&&p.length>1?p.map(String):void 0,q=O&&t.packet&&typeof t.packet=="object"?t.packet:void 0,W=q&&V(q.path),_={animated:t.motion==="animated",pulse:O?V(t.pulse):void 0,packet:W?{path:W,repeat:q.repeat===!0,send:q.send}:void 0,run:I==="sequence"&&t.run===!0};if(s)for(const p of f){const w=p.mark?.says;if(!w?.length)continue;const S=[p.name,p.kind,p.detail,p.laneLabel].filter(Boolean).join(" ").toLowerCase();w.some(g=>S.includes(g.toLowerCase()))||o(`${p.id}'s mark stands for ${w.join(" or ")}, and none of its words say so`)}const L=[];if(I==="sequence"){const p=new Map,w=new Map;for(const S of M)"n"in S&&(w.set(S.from,S.n),w.set(S.to,S.n));for(const S of M)if("n"in S){if(S.activate){const g=p.get(S.to)??[];if(g.length>=3)o(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const b={who:S.to,from:S.n,to:S.n,depth:g.length+1};g.push(b),L.push(b),p.set(S.to,g)}}if(S.deactivate){const b=p.get(S.from)?.pop();b?b.to=S.n:o(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,g]of p)for(const b of g)b.to=Math.max(b.from,w.get(S)??b.from)}const j=t.frameLabels??{},F={opt:at(j.opt)??"Only if",loop:at(j.loop)??"Repeats",alt:at(j.alt)??"One of these",else:at(j.else)??"Otherwise"},Z=Math.max(1,...f.map(p=>p.col)),N=I==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(p=>p.row2)),U={type:I,title:String(t.title??""),heading:l,legend:i,nodes:f,byId:D,edges:v,groups:C,lanes:B,steps:M,bars:L,frameWords:F,cols:Z,rows:N,shapeLabels:h,stepWord:u,warnings:r,motion:_,memo:new Map};return s&&f.length>1&&!St(U)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),U}function It(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Wt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`)??[];b.length>2&&o(`the label "${pt(g)}" has more than one break: a label is two lines at most`),b.some(x=>x.length>zt)&&o(`a line of the label "${pt(g)}" is over ${zt} characters: longer words belong in the node or the summary`),v.push({i:v.length,from:w,to:S,kind:y(p.kind,`the line from ${w} to ${S}`),label:g,fromSide:$(p.fromSide),toSide:$(p.toSide),flow:I!=="flowchart"&&p.flow===!0?!0:void 0})}else for(const p of M)"n"in p&&(!D.has(p.from)||!D.has(p.to))&&o(`message ${p.n} names ${D.has(p.from)?p.to:p.from}, which is not a participant`);if(s&&I!=="sequence"){const p=new Map;for(const w of f)for(let S=w.row;S<=w.row2;S++){const g=`${w.col}:${S}`;p.has(g)&&o(`${w.id} and ${p.get(g)} share the cell at column ${w.col}, row ${S}`),p.set(g,w.id)}}if(s){for(const w of C){const S=w.all.map(x=>D.get(x));if(!S.length)continue;const g={c1:Math.min(...S.map(x=>x.col)),c2:Math.max(...S.map(x=>x.col)),r1:Math.min(...S.map(x=>x.row)),r2:Math.max(...S.map(x=>x.row2))};for(const x of f)!w.all.includes(x.id)&&x.col>=g.c1&&x.col<=g.c2&&x.row>=g.r1&&x.row<=g.r2&&o(`${x.id} is inside the box of the group "${w.label}" but not a member`);const b=S.map(x=>x.i);Math.max(...b)-Math.min(...b)+1!==b.length&&o(`the members of the group "${w.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const w of f)w.group&&!C.some(S=>S.id===w.group)&&o(`${w.id} names the group "${w.group}", which is not in groups`);f.filter(w=>w.focal).length>1&&o("more than one node is focal: a diagram has one at most");const p=new Set(I==="sequence"?M.flatMap(w=>"n"in w?[w.kind]:[]):v.map(w=>w.kind));p.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),p.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(w=>w.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const O=I==="architecture"||I==="data-flow",V=p=>Array.isArray(p)&&p.length>1?p.map(String):void 0,q=O&&t.packet&&typeof t.packet=="object"?t.packet:void 0,W=q&&V(q.path),_={animated:t.motion==="animated",pulse:O?V(t.pulse):void 0,packet:W?{path:W,repeat:q.repeat===!0,send:q.send}:void 0,run:I==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const p of f){const w=p.mark?.says;if(!w?.length)continue;const S=[p.name,p.kind,p.detail,p.laneLabel].filter(Boolean).join(" ").toLowerCase();w.some(g=>S.includes(g.toLowerCase()))||o(`${p.id}'s mark stands for ${w.join(" or ")}, and none of its words say so`)}const L=[];if(I==="sequence"){const p=new Map,w=new Map;for(const S of M)"n"in S&&(w.set(S.from,S.n),w.set(S.to,S.n));for(const S of M)if("n"in S){if(S.activate){const g=p.get(S.to)??[];if(g.length>=3)o(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const b={who:S.to,from:S.n,to:S.n,depth:g.length+1};g.push(b),L.push(b),p.set(S.to,g)}}if(S.deactivate){const b=p.get(S.from)?.pop();b?b.to=S.n:o(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,g]of p)for(const b of g)b.to=Math.max(b.from,w.get(S)??b.from)}const j=t.frameLabels??{},F={opt:at(j.opt)??"Only if",loop:at(j.loop)??"Repeats",alt:at(j.alt)??"One of these",else:at(j.else)??"Otherwise"},Z=Math.max(1,...f.map(p=>p.col)),N=I==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(p=>p.row2)),U={type:I,title:String(t.title??""),heading:l,legend:i,nodes:f,byId:D,edges:v,groups:C,lanes:B,steps:M,bars:L,frameWords:F,cols:Z,rows:N,shapeLabels:h,stepWord:u,warnings:r,motion:_,memo:new Map};return s&&f.length>1&&!St(U)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),U}function It(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Wt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` `?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function yt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var zt=28,Ot=t=>t.includes(` -`)?2:1,pt=t=>t.replace(/\n/g," "),bt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Ft(t,e){return t.legend[e]}function Me(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Se(t,e){return yt(t,`sentence:${e.i}`,()=>Ee(t,e))}function Ee(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(bt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Nt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Me(t,e):e.kind;if(n.push(bt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(bt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${pt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${pt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(bt(t.legend.focal)),n.join(" ")}function Nt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function Ae(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var Le={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>Le[e]),qe=" br img input meta link hr path polygon polyline circle rect line ";function _t(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return qe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>_t(s,e)).join("")}`}var Ie=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Oe(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function kt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Ht(t){return yt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=kt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Dt(t,n,a)))})}return e})}function Dt(t,e,n){const s=kt(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=kt(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Gt(t){const e=Ht(t);return e[1]+e[3]}function Ct(t){return t.type==="sequence"?t.nodes.length:t.cols}function Kt(t){return yt(t,"plan",()=>_e(t))}function _e(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},m=t.edges.map(()=>0);let h=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,m[v.k]+1));m[c.k]=f,f>1&&(h=!0),l.push(c)}const y=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{y[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const $=ut();for(let c=1;c{const O=s[D],V=t.byId.get(H.from).i,q=t.byId.get(H.to).i,W=q===c&&(O==="down"||O==="trunk"||O==="rail"||O==="end-down"),_=V===c&&q===c-1&&O==="up",L=q===c-1&&O==="end-up";W&&(O==="trunk"||O==="end-down")&&(M=!0),L&&(I=!0),(W||_||L)&&H.label&&(B++,C=Math.max(C,O==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),$[f.id]=C}return{routes:s,gutter:d,lanes:m,exits:y,gaps:$,third:h}}var $t=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Vt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...$t(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function wt(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Zt(t,e){return yt(e,`key:${t}`,()=>je(t,e))}var Ce=Zt;function je(t,e){const n=[],s=(o,a,i={})=>n.push(k("li",{class:`${t}-entry`,...i},o,k("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),k("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(wt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(wt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(wt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Vt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Vt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...$t(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),k("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(wt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(wt(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Be(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...$t(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function jt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Te(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},jt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},jt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?At(n.detail).flatMap((r,o)=>[o?" ":"",k("span",{class:`${t}-run`},r)]):n.detail)),s}function Re(t,e){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},jt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>k("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},k("span",{class:`${t}-keyseat`},n.key??""),k("span",{class:`${t}-cname`},n.name),n.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?k("span",{class:`${t}-ctype`},n.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ut=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Mt(t,e,n,s){const{P:r}=t,o=Oe(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=gt(d.gaps,n.id)??32,y=gt(s.grow,n.id)??0;i.push(`--_gap:${y?`calc(${Ut(l)} + var(--basalt-space-4) * ${y})`:Ut(l)}`)}const u=gt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const m=gt(s.words,n.id);m&&i.push(`--_ww:${m}px`);const h=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?Se(e,n):void 0,tabindex:h},n.shape==="decision"?k("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Wt(n.mark.onLight)};--_md:${Wt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Re(r,n):Te(r,e,n))}function We(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=kt(e,d);if(!u)continue;const m=[0,1,2,3].map(h=>Dt(e,d,h));r.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`},Mt(t,e,d,n))))),r.push(ze(t,e)),r;const o=d=>{const u=d.group?e.groups.find(m=>m.id===d.group):void 0;return u?.parent?e.groups.find(m=>m.id===u.parent):u},a=(d,u,m)=>{const h=t.plan?gt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:h?`--_ggrow:${h}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),m)};let i=0;for(;ic.id===m[l].group):void 0;if(!y){h.push(Mt(t,e,m[l],n)),l++;continue}const $=[];for(;lMt(t,e,c,n))))}r.push(a(u,m,h))}return r}function ze(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(k("p",{class:`${n}-band`},k("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=k("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=k("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),m=d?.col??1,h=u?.col??1,l=m===h,y=l&&m===e.nodes.length,$=Ft(e,i.kind);a.c.push(k("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?y?"start":"end":void 0,style:`--_a:${Math.min(m,h)};--_b:${Math.max(m,h)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(i.n)),k("span",{class:`${n}-mlabel`},i.label)),k("span",{class:`${n}-route`},d?.short??i.from," ",Be(n,i.kind),k("span",{class:t.hidden}," to ")," ",u?.short??i.to,$?` · ${$}`:""),i.note?k("span",{class:`${n}-note`},i.note):null))}return k("div",{class:`${n}-steps`},s)}function Jt(t,e){return yt(e,`list:${t}`,()=>Ne(t,e))}var Fe=Jt;function Ne(t,e){const n=Math.min(6,e.heading+1),s=h=>k(`h${n}`,{class:`${t}-list-head`},h),r=h=>k("strong",null,h),o=h=>h.href?k("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},r(h.name)):r(h.name),a=h=>k("code",{class:`${t}-code`},h),i=h=>e.byId.get(h)?.name??h,d=h=>{const l=Ft(e,h);return l?` (${l})`:""},u=h=>h.focal&&e.legend.focal?` ${bt(e.legend.focal)}`:"";if(e.type==="architecture"){const h=$=>k("li",null,o($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?a($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",u($)),l=[s("Parts")],y=e.nodes.filter($=>!$.group);y.length&&l.push(k("ul",{class:`${t}-list-items`},y.map(h)));for(const $ of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},$.label)),$.members.length&&l.push(k("ul",{class:`${t}-list-items`},$.members.map(c=>h(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===$.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>h(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map($=>k("li",null,r(i($.from))," to ",r(i($.to)),$.label?[": ",a(pt($.label))]:"",`${d($.kind)}.`)))),l}if(e.type==="flowchart"){const h=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const y=e.edges.filter(f=>f.from===l.id),$=l.shape==="decision"?"Decision":l.shape==="terminal"?y.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${$}.`,u(l),y.length?k("ul",{class:`${t}-list-exits`},y.map(f=>k("li",null,f.label?`If ${pt(f.label)}: go to ${h(f.to)}, `:`Then: go to ${h(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(h=>{const l=e.edges.filter(y=>y.from===h.id);return k("li",null,`${h.laneLabel}: `,o(h),h.detail?[", ",h.mono?a(h.detail):h.detail]:"",".",u(h),l.length?[" Then ",...l.flatMap((y,$)=>[$?"; ":"",`to step ${e.byId.get(y.to).step}, `,r(i(y.to)),y.label?[": ",a(pt(y.label))]:"",d(y.kind)]),"."]:"")}))];if(e.type==="sequence"){const h=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(y=>k("li",null,r(y.name),y.kind?`, ${y.kind}`:"",".",u(y),Nt(e,y))))];h.push(s("Messages"));let l=null;for(const y of e.steps){if("band"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},y.band));continue}if("open"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":y.depth>1?y.depth:void 0},`${e.frameWords[y.open]}: ${y.label}`));continue}if("otherwise"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":y.depth>1?y.depth:void 0},`${e.frameWords.else}: ${y.otherwise}`));continue}if("close"in y){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:y.n}),h.push(l)),l.c.push(k("li",null,a(y.label),": ",r(i(y.from))," to ",r(i(y.to)),`${d(y.kind)}.`,y.note?` ${bt(y.note)}`:""))}return h}const m=[];for(const h of e.nodes)m.push(k(`h${n}`,{class:`${t}-list-group`},h.href?k("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},a(h.name)):a(h.name),u(h))),m.push(k("ul",{class:`${t}-list-items`},[...(h.columns??[]).map(l=>k("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...h.more?[k("li",null,`and ${h.more} more ${h.more===1?"column":"columns"}`)]:[]]));return m}function Xt(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&St(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Bt(t,e=!1){const n=e&&t.type!=="sequence"&&St(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Ae(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var He=(t,e)=>{for(let n=0;n({col:t.type==="sequence"?e.i+1:e.col,rows:[e.row,e.row2]});function St(t){return yt(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...De(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=$=>i?[$.col,$.col]:$.rows,m=$=>i?$.rows:[$.col,$.col],h=u(o),l=m(o);let y=null;return e.forEach(($,c)=>{if($===o)return;const f=u($),v=m($),B=d?f[0]-h[1]:h[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!y||He(M,y.rank))&&(y={id:$.id,rank:M})}),y?.id??null},s=ut();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var Yt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Qt(t,e,n){const s=n.prefix,r=Ie(n.base),o=t.type==="sequence"||t.type==="schema"?null:Kt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,m=`h${t.heading}`,h=[`--_cols:${Ct(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Ht(t):[0,0,0,0],y=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",$=i&&e.pad?"3":void 0;h.push(`--_gpad:${y(l[0],"8",$)} ${y(l[1],"4")} ${y(l[2],"4",$)} ${y(l[3],"4")}`)}return Yt(t)&&h.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&h.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Ct(t),"data-reach":t.type==="architecture"?Gt(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-viewer":n.viewer?"":void 0,style:h.join(";")},k("div",{class:`${s}-head`},k(m,{id:r.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},We(a,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Zt(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Jt(s,t)),k("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Xt(t,i)} ${n.viewer}`:Xt(t,i)),k("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Ge(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Et=(t,e)=>t==="main"?e.line:e.hair,dt=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ft=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Pt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function ct(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2,h=e==="top"||e==="bottom";if(t.shape==="decision"){if(h){const $=n,c=m*Math.max(0,1-Math.abs($-i)/u);return{x:$,y:e==="top"?d-c:d+c}}const l=n,y=u*Math.max(0,1-Math.abs(l-d)/m);return{x:e==="left"?i-y:i+y,y:l}}if(t.shape==="terminal"){const l=Math.min(u,m);if(h){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const y=n,$=y-d,c=Math.abs($)>=l?0:Math.sqrt(l*l-$*$);return{x:e==="left"?s+l-c:o-l+c,y}}return h?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Ke(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/m<1-n/Math.min(u,m);if(e.shape==="terminal"){const h=Math.min(u,m),l=Math.min(Math.max(t.x,s+h),o-h);return Math.hypot(t.x-l,t.y-d)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Ue(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var At=t=>t?t.split(/\s+/).filter(Boolean):[];function Je(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`→ ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),m=d.mark&&!Ze()?(d.shape==="participant"?2:1)*s("6"):0;let h=0;const l=d.href?16+s("1-5"):0,y=At(d.name);if(y.forEach((c,f)=>{h=Math.max(h,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:m)+(f===y.length-1?l:0))}),t.type!=="data-flow")for(const c of At(d.kind))h=Math.max(h,n(c,"mono")+m);for(const c of At(d.detail))h=Math.max(h,n(c,d.mono?"mono":"sans"));const $=d.shape==="decision"?h/.62:h+u+2*e.hair;r=Math.max(r,Math.ceil($))}const a=Ct(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(Yt(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Gt(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ee(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Tt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ne(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ht=t=>t.slice(1).map((e,n)=>[t[n],e]);function Lt(t,e,n){const s=[];for(let o=0;oMath.min(c.x,f.x)+.75&&CMath.min(v.y,B.y)+.75&&Mr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",oe={top:"bottom",bottom:"top",left:"right",right:"left"};function Ye(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Qe(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,m]=e[a],h=i.row===d.row&&tt(u)&&tt(m)&&u===oe[m]||i.col===d.col&&!tt(u)&&!tt(m)&&u===oe[m];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:h,f:.5},{edge:a,end:"to",node:d,side:m,far:i,straight:h,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const m=new Map;for(const c of d)m.has(c.far.id)||m.set(c.far.id,[]),m.get(c.far.id).push(c);for(const c of m.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const h=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),y=u.filter(c=>i(c)<0),$=u.filter(c=>i(c)>=0);y.forEach((c,f)=>{c.f=h*(f+1)/(y.length+1)}),$.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/($.length+1)})}return s}function se(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?ct(t,e,r+(a-r)*n):ct(t,e,s+(o-s)*n)}function ae(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:dt(o,n),shape:a.shape,i:a.i})}),r}function re(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var ie=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function le(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function Pe(t,e,n,s,r,o,a,i,d){const u=a.space,m=[],h=[],l=[],y=[],$=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*Ot(v),M=f.pts.length-2,I=[];ht(f.pts).forEach(([q,W],_)=>{const L=Math.abs(q.y-W.y)<.01,j=L?q.x:q.y;let F=L?W.x:W.y;const Z=Math.sign(F-j)||1;_===M&&(F-=Z*a.head);let N=[[j,F]];for(const w of r)for(const S of L?[w.l,w.r]:[w.t,w.b]){const g=L?q.y:q.x;(L?g>w.t&&gw.l&&gS>Math.min(x,E)+1&&S{const g=(w+S)/2,b=L?{x:g,y:q.y}:{x:q.x,y:g};return!r.some(x=>b.x>x.l&&b.xx.t&&b.y1&&U(w,S)?1:0})}),I.sort((q,W)=>W.pri-q.pri||W.len-q.len);let H=null,D=!1;const O=(q,W=!0)=>{const _=Pt(q,$);return W&&(q.lo.r||q.to.b)||n.some(L=>te(_,L))||m.some(L=>ft(_,L))||s.heads.some(L=>ft(_,L))||s.rects.some(L=>ft(_,L))?!1:!e.some(L=>L.i!==f.i&&ht(L.pts).some(([j,F])=>ft(_,ie(j,F,L.width))))};for(const q of I){for(const W of[1/2,1/3,2/3]){const _=q.p+(q.q-q.p)*W,L=[],j=u("2")+f.width/2;if(q.horiz?(q.len>=B+2*u("1")+u("3-5")&&L.push({box:{l:_-B/2-u("1"),r:_+B/2+u("1"),t:q.c-C/2,b:q.c+C/2},on:!0}),L.push({box:{l:_-B/2,r:_+B/2,t:q.c-j-C,b:q.c-j},on:!1}),L.push({box:{l:_-B/2,r:_+B/2,t:q.c+j,b:q.c+j+C},on:!1})):(q.len>=C+u("3")&&L.push({box:{l:q.c-B/2-u("1"),r:q.c+B/2+u("1"),t:_-C/2,b:_+C/2},on:!0}),L.push({box:{l:q.c+j,r:q.c+j+B,t:_-C/2,b:_+C/2},on:!1}),L.push({box:{l:q.c-j-B,r:q.c-j,t:_-C/2,b:_+C/2},on:!1})),H=L.find(F=>O(F.box))??null,H)break;!D&&L.some(F=>O(F.box,!1))&&(D=!0)}if(H)break}if(!H){l.push(f.i),D&&y.push(f.i);continue}const V=le(H.box,d.ox,d.oy,q=>O(q));m.push(V),h.push({i:f.i,text:v,box:V,on:H.on})}return{labels:h,unseated:l,bounded:y}}function ce(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=dt(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(dt(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=dt(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(dt(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function tn(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,m=ae(s,a,i,o),h=[...m.values()],l=Xe(a),y=i.left-Math.floor(i.left),$=i.top-Math.floor(i.top),c=ee(y,$),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:y,oy:$};if(s.type==="sequence")return nn(t,M,c);let I,H=[];s.type==="schema"?I=s.edges.map(g=>{const b=s.byId.get(g.from),x=s.byId.get(g.to);if(b.col===x.col){const E=b.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return x.col>b.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const b=s.byId.get(g.from),x=s.byId.get(g.to),[E,A]=Ye(b,x);return[g.fromSide??E,g.toSide??A]}),H=Qe(s,I,d||(()=>{})));const D=(g,b)=>{const x=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${b}"]`);if(!x)return 0;const E=dt(x,i);return(E.t+E.b)/2},O=s.edges.map((g,b)=>{const[x,E]=I[b],A=m.get(g.from),T=m.get(g.to),K=Et(g.kind,r);if(g.fk){const X=D(g.from,g.fromRow),ot=D(g.to,g.toRow),Y=c.y(X,K),st=c.y(ot,K);return{p1:{x:x==="right"?A.rect.r:A.rect.l,y:Y},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:X,r2:Math.abs(Y-st)<.01?X:ot}}const Q=H.find(X=>X.edge===b&&X.end==="from").f,J=H.find(X=>X.edge===b&&X.end==="to").f;let z=se(A,x,Q),G=se(T,E,J);const nt=tt(x)?z.y:z.x;let et=tt(E)?G.y:G.x;return tt(x)?z={...z,y:c.y(z.y,K)}:z={...z,x:c.x(z.x,K)},tt(E)?G={...G,y:c.y(G.y,K)}:G={...G,x:c.x(G.x,K)},tt(x)&&tt(E)&&Math.abs(z.y-G.y)<1.01&&(G={...G,y:z.y},et=nt),!tt(x)&&!tt(E)&&Math.abs(z.x-G.x)<1.01&&(G={...G,x:z.x},et=nt),z=tt(x)?ct(A,x,z.y):ct(A,x,z.x),G=tt(E)?ct(T,E,G.y):ct(T,E,G.x),{p1:z,p2:G,r1:nt,r2:et}}),V=new Set;s.type==="schema"&&s.edges.forEach((g,b)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&V.add(b)});const q=new Map,W=new Set;s.edges.forEach((g,b)=>{if(V.has(b))return;const[x,E]=I[b],{p1:A,p2:T}=O[b],K=s.byId.get(g.from),Q=s.byId.get(g.to);let J=null,z=null,G=!1;if(x===E){if(tt(x)){const X=x==="right"?Math.max(B(K),B(Q)):Math.min(B(K),B(Q))-1,ot=l.cols[X-1],Y=l.cols[X];ot&&Y&&(J=`c${X}`,z=[ot[1],Y[0]],G=!0)}else{const X=x==="bottom"?Math.max(K.row2,Q.row2):Math.min(K.row,Q.row)-1,ot=l.rows[X-1],Y=l.rows[X];ot&&Y&&(J=`r${X}`,z=[ot[1],Y[0]],G=!1)}J&&W.add(b)}else if(tt(x)&&tt(E)&&Math.abs(A.y-T.y)>.5){const X=B(Q),ot=E==="left",Y=l.cols[(ot?X-1:X)-1],st=l.cols[(ot?X:X+1)-1];Y&&st&&(J=`c${ot?X-1:X}`,z=[Y[1],st[0]],G=!0)}else if(!tt(x)&&!tt(E)&&Math.abs(A.x-T.x)>.5){const ot=E==="top"?Q.row-1:Q.row2,Y=l.rows[ot-1],st=l.rows[ot];Y&&st&&(J=`r${ot}`,z=[Y[1],st[0]],G=!1)}if(!J||!z)return;q.has(J)||q.set(J,{span:z,vertical:G,members:new Map});const nt=`${g.to}.${E}.${Math.round(G?T.y:T.x)}`,et=q.get(J);et.members.has(nt)||et.members.set(nt,[]),et.members.get(nt).push(b)});const _=new Map,L=g=>{const[b,x]=I[g],{p1:E,p2:A}=O[g];if(tt(b)&&tt(x)){if(b===x){const K=_.get(g)??(b==="right"?Math.max(E.x,A.x)+u("4"):Math.min(E.x,A.x)-u("4"));return[E,{x:K,y:E.y},{x:K,y:A.y},A]}if(Math.abs(E.y-A.y)<=.5)return[E,{x:A.x,y:E.y}];const T=_.get(g)??(E.x+A.x)/2;return[E,{x:T,y:E.y},{x:T,y:A.y},A]}if(!tt(b)&&!tt(x)){if(b===x){const K=_.get(g)??(b==="bottom"?Math.max(E.y,A.y)+u("4"):Math.min(E.y,A.y)-u("4"));return[E,{x:E.x,y:K},{x:A.x,y:K},A]}if(Math.abs(E.x-A.x)<=.5)return[E,{x:E.x,y:A.y}];const T=_.get(g)??(E.y+A.y)/2;return[E,{x:E.x,y:T},{x:A.x,y:T},A]}return tt(b)?[E,{x:A.x,y:E.y},A]:[E,{x:E.x,y:A.y},A]},j=g=>{const b=s.edges[g],x=Et(b.kind,r),E=L(g),A=ne(E,x,c);let T;return E.length===A.length&&(T=ht(E).map(([K,Q])=>Math.abs(K.y-Q.y)<.75?(K.y+Q.y)/2:(K.x+Q.x)/2),T[0]=O[g].r1,T.length>1&&(T[T.length-1]=O[g].r2)),{i:g,from:b.from,to:b.to,kind:b.kind,pts:A,tip:A[A.length-1],dir:Tt(A),dot:b.fk?A[0]:void 0,width:x,axes:T}},F=()=>s.edges.flatMap((g,b)=>V.has(b)?[]:[j(b)]);let Z=null;const N=g=>{Z??(Z=F());const b=Z.map(x=>g.has(x.i)?j(x.i):x);return{lines:b,score:en(b,g)*1e5+Lt(b,void 0,g).length*1e3+Rt(b.filter(x=>g.has(x.i)),h,s).length}},U=(g,b)=>{const x=g.flatMap(E=>{const{p1:A,p2:T}=O[E];return b?[A.y,T.y]:[A.x,T.x]});return[Math.min(...x),Math.max(...x)]};for(const[,g]of q){const b=[...g.members.values()].map(E=>({members:E,run:U(E,g.vertical)})).sort((E,A)=>E.run[0]-A.run[0]),x=[];for(const E of b){const A=x[x.length-1];A&&A.some(T=>T.run[0]W.has(nt)))continue;const A=E.map(nt=>nt.members),T=A.length,K=(g.span[1]-g.span[0])/(T+1);KX.forEach(Y=>_.set(Y,g.span[0]+K*(ot+1))));const et=N(Q);et.scorent.forEach(X=>_.set(X,g.span[0]+K*(et+1)))),Z=G}}M.lines=F();for(const g of V)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=Lt(M.lines),M.through=Rt(M.lines,h,s),M.outside=ue(M.lines,f,v,r);const{obstacles:p,groups:w}=ce(a,i,o,C);p.heads=M.lines.map(g=>re(g,r));const S=Pe(s,M.lines,h,p,w,{l:0,t:0,r:f,b:v},r,e,{ox:y,oy:$});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(de(M.lines,null).flat())],M}function en(t,e){return de(t,e).length}function de(t,e){const n=[];for(let s=0;s=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[m.x,h.x]:[m.y,h.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*fe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Rt(t,e,n){const s=[];for(const r of t){const o=ht(r.pts);e.some(a=>o.some(([i,d])=>Ve(i,d,a)))&&s.push(r.i)}return s}function nn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,dt(M,i)));const m=a.querySelector(`.${o}-steps`),h=m?dt(m,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:h})}const y=M=>u.get(M.id),$=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=dt(M,i);$.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const H=l(M.who),D=I.i===s.nodes.length-1&&s.nodes.length>1?-1:1,O=(M.depth-1)*d("1")*D,V=$.get(M.from)??0,q=$.get(M.to)??V,W=M.from===M.to;return{l:n.x(H-f+O,r.hair),r:n.x(H+f+O,r.hair),t:n.y(W?V-d("2")-d("1"):V,r.hair),b:n.y(W?V+d("2")+d("1"):q,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,H)=>B.filter(({bar:D})=>D.who===M&&D.to>=I&&(H?D.from<=I:D.fromO.bar.depth-D.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,H=M.dataset.to,D=M.dataset.kind??"plain",O=Et(D,r),V=dt(M,i),q=n.y((V.t+V.b)/2,O),W=Number(M.querySelector(`.${o}-num`)?.textContent??0);let _=l(I),L=l(H),j;if(I===H){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,W,!0),b=g?S>0?g.r:g.l:_,x=n.y(q-d("2"),O),E=n.y(q+d("2"),O);j=[{x:b,y:x},{x:n.x(_+S,O),y:x},{x:n.x(_+S,O),y:E},{x:b,y:E}]}else{const S=L>_?1:-1,g=C(I,W,!1),b=C(H,W,!0);g&&(_=S>0?g.r:g.l),b&&(L=S>0?b.l:b.r),j=[{x:_,y:q},{x:L,y:q}]}e.lines.push({i:W,from:I,to:H,kind:D,pts:j,tip:j[j.length-1],dir:Tt(j),width:O});const F=M.querySelector(`.${o}-said`),Z=M.querySelector(`.${o}-note`),N=s.byId.get(I),U=s.byId.get(H);if(!N||!U)return;const p=I===H?(()=>{const S=s.nodes[N.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-_)-d("6")-d("2-5")-d("2")})():Math.abs(L-_)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>p+.5&&e.unseated.push(W)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((D,O)=>D+O.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function he(t,e,n,s=ut()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,m=ae(r,i,d,a),h=[...m.values()],l=d.left-Math.floor(d.left),y=d.top-Math.floor(d.top),$=ee(l,y),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:y},B=ut();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(L,j,F)=>{const Z=[L];for(let N=1;N<=(gt(s,j)??0);N++)Z.push({...L,t:L.t+F*u("4")*N,b:L.b+F*u("4")*N});return Z},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(L=>{const j=L.parentElement,F=dt(j,d),Z=getComputedStyle(j);I.set(L.dataset.node,F.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const H=r.nodes,D=L=>m.get(H[L].id),O=[],V=L=>Et(r.edges[L].kind,o);r.edges.forEach((L,j)=>{const F=n.routes[j],Z=m.get(L.from),N=m.get(L.to),U=V(j);let p=[];const w=L.label,S=w?e(w,"label"):0,g=w?16*Ot(w):16,b=u("4");if(F==="down"||F==="up"){const E=Math.max(Z.rect.l,N.rect.l),A=Math.min(Z.rect.r,N.rect.r),T=r.edges.map((z,G)=>({o:z,j:G})).filter(({o:z,j:G})=>(n.routes[G]==="down"||n.routes[G]==="up")&&(z.from===L.from&&z.to===L.to||z.from===L.to&&z.to===L.from)),K=T.findIndex(z=>z.j===j),Q=T.length<2?.5:T.length===2?K===0?.25:.75:(K+1)/(T.length+1),J=$.x(E+(A-E)*Q,U);if(p=F==="down"?[ct(Z,"bottom",J),ct(N,"top",J)]:[ct(Z,"top",J),ct(N,"bottom",J)],w){let z=Math.min(p[0].y,p[1].y),G=Math.max(p[0].y,p[1].y);F==="down"?G-=o.head:z+=o.head;const nt=[...i.querySelectorAll(`.${a}-group`)].map(Y=>dt(Y,d));let et=[[z,G]];for(const Y of nt)for(const st of[Y.t,Y.b])et=et.flatMap(([rt,R])=>st>rt+1&&stnt.some(rt=>(Y+st)/2>rt.t&&(Y+st)/2rt.l&&J1){const Y=et.filter(([rt,R])=>!X(rt,R));[z,G]=(Y.length?Y:et).reduce((rt,R)=>R[1]-R[0]>rt[1]-rt[0]?R:rt)}const ot=[1/2,1/3,2/3].map(Y=>{const st=z+(G-z)*Y;return{l:J-S/2-u("1"),r:J+S/2+u("1"),t:st-g/2,b:st+g/2}});O.push({k:j,cands:ot,on:!0,card:F==="down"?L.to:L.from})}}else if(F==="trunk"||F==="rail"){const E=$.x(Math.max(Z.rect.l,F==="rail"?N.rect.l:Z.rect.l)+u(F==="trunk"?"8":"3"),U),A=ct(Z,"bottom",E);if(F==="rail"){if(p=[A,ct(N,"top",E)],w){const T=N.rect.t-u("6");O.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},L.to,-1),on:!1,card:L.to})}}else{const T=$.x(N.rect.l+u("6"),U),K=$.y(N.rect.t-b,U);p=[A,{x:E,y:K},{x:T,y:K},ct(N,"top",T)],w&&O.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:K-g/2,b:K+g/2},L.to,-1),on:!1,card:L.to})}}else{const E=Math.min(I.get(L.from)??c,I.get(L.to)??c),A=$.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),U),T=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[j],U),K=ct(Z,"right",T),Q=$.x(N.rect.r-u("6"),U),J=F==="end-down",z=$.y(J?N.rect.t-b:N.rect.b+b,U);p=[K,{x:A,y:K.y},{x:A,y:z},{x:Q,y:z},ct(N,J?"top":"bottom",Q)];const G=J?L.to:H[N.i+1]?.id??L.to;w&&O.push({k:j,cands:M({l:Q-u("2-5")-S,r:Q-u("2-5"),t:z-g/2,b:z+g/2},G,J?-1:1),on:!1,card:G})}const x=ne(p,U,$);v.lines.push({i:j,from:L.from,to:L.to,kind:L.kind,pts:x,tip:x[x.length-1],dir:Tt(x),width:U})}),v.crossings=Lt(v.lines),v.through=Rt(v.lines,h,r),v.outside=ue(v.lines,c,f,o);const{obstacles:q}=ce(i,d,a,0);q.heads=v.lines.map(L=>re(L,o));const W=[],_={l:0,t:0,r:c,b:f};for(const L of O){const j=N=>{const U=Pt(N,u("1"));return N.l<_.l-.5||N.r>_.r+.5||N.t<_.t-.5||N.b>_.b+.5||h.some(p=>te(U,p))||W.some(p=>ft(U,p))||q.heads.some(p=>ft(U,p))||q.rects.some(p=>ft(U,p))||v.lines.some(p=>p.i!==L.k&&ht(p.pts).some(([w,S])=>ft(U,ie(w,S,p.width))))},F=L.cands.find(N=>!j(N));F||(B[L.card]=(B[L.card]??0)+1,v.unseated.push(L.k));const Z=F?le(F,l,y,N=>!j(N)):L.cands[0];W.push(Z),v.labels.push({i:L.k,text:r.edges[L.k].label,box:Z,on:L.on})}return{geo:v,grow:B}}function on(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...M})),h=m[m.length-1];h.x-=o.x*u,h.y-=o.y*u;const l=e.tip.x-o.x*i,y=e.tip.y-o.y*i,$=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=lt(e.kind),B=a?``:``,C=e.dot?``:"";return`${B}${C}`}function pe(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const m=d.map(h=>{const l=e.lines[h.top],y=e.lines[h.under],$=l.width/2+n.cut,c=y.width/2+1;return h.underVertical?``:``}).join("");a+=`${m}`}return{defs:a,ids:r}}function ge(t,e,n,s){const{defs:r,ids:o}=pe(t,e,n,s),a=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),i=e.lines.map((m,h)=>an(t,m,n,o.get(h)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),d=`${r?`${r}`:""}${a}${i}`,u=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` -`).map(lt).join("
")}
`).join("");return d+u}function me(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const m=Ge(t),h=Ue(u,n),l=Je(e,m,h);i?.(l.least);const y=t.clientWidth,$=(()=>{const q=document.activeElement;return q&&u.contains(q)&&q.dataset.node?q.dataset.node:void 0})(),c=q=>mt(e,q)?{...q,stop:q.stop&&e.byId.has(q.stop)?q.stop:e.nodes[0]?.id,keep:void 0}:{...q,stop:q.stop??e.nodes[0]?.id,keep:$&&q.layout!=="drawn"?$:void 0};let f=!1;const v=q=>{if(f=!1,e.type!=="flowchart")return q;o({...q,heights:void 0,words:void 0});const W=ut(),_=ut();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(L=>{const j=L.querySelector(`.${n}-words`);if(!j)return;const F=L.getBoundingClientRect(),Z=p=>{const w={w:p.width+2*m.space("2-5"),h:p.height+2*m.space("2")},S=1-w.w/F.width,g=S>.05?w.h/2/S:w.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},N=j.getBoundingClientRect();let U=Z(N);if(U>F.width){const p=b=>(L.style.setProperty("--_ww",`${b}px`),j.getBoundingClientRect()),w=Math.floor(L.clientWidth-2*m.space("2-5"));let S=Math.ceil(N.width),g=N.height;for(;S1;){const T=b+x>>1;p(T).heightF.width&&(f=!0)}),{...q,heights:W,words:Object.keys(_).length?_:void 0}},B=()=>({m:e,tk:m,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(q,W)=>W.map(_=>vt(e,q.lines.find(L=>L.i===_))).join(", ");if(y>=l.least){const q=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:tn(B(),h)}};let{dd:W,g:_}=q(!1);const L=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!L(_)&&_.unseated.length&&_.unseated.every(j=>_.bounded?.includes(j))){const j=q(!0);!L(j.g)&&!j.g.unseated.length&&({dd:W,g:_}=j)}if(!L(_)&&!_.unseated.length)return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the drawn layout: ${_.crossings.map(j=>`${vt(e,_.lines[j.top])} over ${vt(e,_.lines[j.under])}`).join("; ")}`),{dyn:W,geo:_,ink:ge(n,_,m,s),tokens:m,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: a decision would be taller than it is wide`),_.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${_.misfit.join("; ")}`),_.through.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.through)} would pass through a node`),_.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.overlaps)} would lie on one another`),_.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.outside)} would leave the drawing`),_.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: no clean seat for ${_.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ut(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:m,least:l.least};const H=Kt(e);let D=he(B(),h,H,I.grow);for(let q=0;q<6&&Object.keys(D.grow).length;q++){const W=ut(I.grow);for(const[_,L]of Object.entries(D.grow))W[_]=(gt(W,_)??0)+L;I={...I,grow:W},o(I),D=he(B(),h,H,W)}const O=D.geo;if(O.unseated.length>0||O.through.length>0||O.outside.length>0||H.third){O.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(O.unseated)].map(_=>`"${e.edges[_]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),O.through.length&&a?.(`in the stacked drawing ${M(O,O.through)} would pass through a node, so its lines are not drawn`),O.outside.length&&a?.(`in the stacked drawing ${M(O,O.outside)} would leave the drawing, so its lines are not drawn`),H.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const q={...O,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ut(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:q,ink:"",tokens:m,least:l.least}}return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${O.crossings.map(q=>`${vt(e,O.lines[q.top])} over ${vt(e,O.lines[q.under])}`).join("; ")}`),{dyn:I,geo:O,ink:ge(n,O,m,s),tokens:m,least:l.least}}function vt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function rn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const m=Lt(n.lines,i),{defs:h,ids:l}=pe(e,{...n,crossings:m},s,r),y=t.querySelector(`.${e}-svg`);if(!y)return;let $=y.querySelector("defs");!$&&h&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),y.insertBefore($,y.firstChild)),$&&($.innerHTML=h),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var ln=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function cn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",ln()?"done":"pending")}}function ye(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function dn(t,e,n,s=!1,r=!1){const o=s?St(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var fn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],be=["data-layout","data-measured","data-bare","data-motion"],un=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],$e=t=>t==null||t===!1;function hn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function we(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?be:fn;for(const a of s)$e(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,m=new Map(String(i??"").split(";").map(h=>{const l=h.indexOf(":");return[h.slice(0,l).trim(),h.slice(l+1).trim()]}).filter(([h])=>h));for(const[h,l]of m)u.getPropertyValue(h).trim()!==l&&u.setProperty(h,l);for(const h of un)m.has(h)||u.removeProperty(h);continue}if(n&&!be.includes(a))continue;if($e(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,y,$){return{prefix:n,base:l,hasSource:y.source!==void 0&&y.source!==null&&y.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(l,y,$,c){var f=function(v){return''+lt(v)+""};return{source:lt(String(y.source||"")),summary:lt(String(y.summary||"")),hint:Bt(l).map(function(v){return""+v.keys.map(f).join(" ")+" "+lt(v.words)+""}).join(""),toggle:'"}}function a(l,y,$){var c=qt(l),f=Qt(c,{},r(y,l,$)),v=_t(f,o(c,l,y,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,y,$,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=qt(y);if(!$||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(y,f,c),C=document.createElement("div");C.innerHTML=B.open+"";var M=C.firstChild;i.forEach(function(R){l.removeAttribute(R)}),d.forEach(function(R){l.style.removeProperty(R)});for(var I=0;I :not(script[data-diagram])").forEach(function(R){R.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(R){console.warn("Basalt diagram: "+R)});var D=r(f,y,c),O={},V=null,q=null,W=null,_=Object.create(null),L=function(R){_[R]||(_[R]=1,console.warn("Basalt diagram: "+R))},j=function(R){we(l,Qt(v,R,D))},F=l.querySelector(".diagram-ink"),Z=l.querySelector(".diagram-toggle"),N=!c&&v.motion.animated&&typeof e.diagramMotion=="function",U=null,p=null,w=function(){N&&ye(l)};function S(){rn(l,n,V&&V.geo,V&&V.tokens,f,q||W)}function g(){Z&&(Z.setAttribute("aria-expanded",String(!!O.open)),Z.firstElementChild.textContent=O.open?"Hide the list":"View as list")}function b(){V=(c?c.measure:me)(l,v,n,f,O,j,L),O=V.dyn,j(O),g();var R=l.querySelector(":scope > .diagram-hint");if(R){var P=Bt(v,O.layout==="drawn").map(function(xt){return""+xt.keys.map(function(gn){return''+lt(gn)+""}).join(" ")+" "+lt(xt.words)+""}).join("");R.innerHTML!==P&&(R.innerHTML=P)}mt(v,O)||(W=null);var it=F&&V.ink!==p;it&&(F.innerHTML=V.ink,p=V.ink),S(),N&&V.tokens&&(cn(l,!!(V.geo&&V.geo.lines.length)),it&&U&&U.redrawn()),c&&c.onMeasured&&V.tokens&&c.onMeasured(V,l)}function x(R){O=R,j(O)}function E(R){var P=O.stop;O=Object.assign({},O,{stop:R}),pn(l,n,P,R)}var A=function(R){var P=R&&R.closest?R.closest(".diagram-node"):null;return P&&l.contains(P)?P:null};function T(R){var P=A(R.target);if(!(!P||R.defaultPrevented)){if(w(),R.key==="Escape"){!c&&(q||W)&&(R.preventDefault(),q=W=null,S());return}if(mt(v,O)){var it=dn(v,P.getAttribute("data-node"),R.key,O.layout==="drawn",getComputedStyle(P).direction==="rtl");if(it){R.preventDefault(),E(it);var xt=l.querySelector('.diagram-node[data-node="'+CSS.escape(it)+'"]');xt&&xt.focus()}}}}function K(R){var P=A(R.target);if(P){w();var it=P.getAttribute("data-node");q=P.matches(":focus-visible")?it:null,mt(v,O)&&O.stop!==it&&E(it),S()}}function Q(R){var P=A(R.target);P&&(A(R.relatedTarget)||(q=null),O.keep===P.getAttribute("data-node")&&x(Object.assign({},O,{keep:void 0})),S())}function J(R){if(!(R.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var P=A(R.target);P&&w();var it=P&&mt(v,O)?P.getAttribute("data-node"):null;it!==W&&(W=it,S())}}function z(){W&&(W=null,S())}function G(){w(),x(Object.assign({},O,{open:!O.open,autoOpen:void 0})),g()}l.addEventListener("keydown",T),l.addEventListener("focusin",K),l.addEventListener("focusout",Q),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",z),Z&&Z.addEventListener("click",G),b();var nt=l.clientWidth,et=0,X=!0,ot=new ResizeObserver(function(){Math.abs(l.clientWidth-nt)<.5||(nt=l.clientWidth,cancelAnimationFrame(et),et=requestAnimationFrame(b))});ot.observe(l),document.fonts&&document.fonts.ready.then(function(){X&&b()});var Y=matchMedia("(forced-colors: active)"),st=v.nodes.some(function(R){return R.mark});st&&Y.addEventListener("change",b),N&&(U=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},y));var rt=!c&&y.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,y,{model:v,settle:w,animated:N}):null;l.__diagram={stop:function(){rt&&rt.destroy(),X=!1,ot.disconnect(),cancelAnimationFrame(et),st&&Y.removeEventListener("change",b),U&&U.destroy(),l.removeEventListener("keydown",T),l.removeEventListener("focusin",K),l.removeEventListener("focusout",Q),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",z),Z&&Z.removeEventListener("click",G)},layout:b,key:m(y),send:U&&U.sendValue?U.sendValue:null}}function m(l){try{return JSON.stringify(l,function(y,$){return y==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function h(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var y=l.querySelector(":scope > script[data-diagram]");if(y)try{u(l,JSON.parse(y.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:qt,figureKey:Ce,figureList:Fe,hintEntries:Bt,toHtml:_t,escapeHtml:lt,settleEntrance:ye,measureFigure:me},t.diagram=function(l,y){var $=l.__diagram,c=$&&$.send?m(y):null;if(c!==null&&c===$.key){$.send(y.packet?y.packet.send:void 0);return}u(l,y)},e.step(62,"wireDiagrams",h)})(window.Basalt)})(); +`)?2:1,pt=t=>t.replace(/\n/g," "),bt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Ft(t,e){return t.legend[e]}function Me(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Se(t,e){return yt(t,`sentence:${e.i}`,()=>Ee(t,e))}function Ee(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(bt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Nt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Me(t,e):e.kind;if(n.push(bt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(bt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${pt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${pt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(bt(t.legend.focal)),n.join(" ")}function Nt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function Ae(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var Le={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>Le[e]),qe=" br img input meta link hr path polygon polyline circle rect line ";function _t(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return qe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>_t(s,e)).join("")}`}var Ie=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Oe(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function kt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Ht(t){return yt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=kt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Dt(t,n,a)))})}return e})}function Dt(t,e,n){const s=kt(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=kt(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Gt(t){const e=Ht(t);return e[1]+e[3]}function Ct(t){return t.type==="sequence"?t.nodes.length:t.cols}function Kt(t){return yt(t,"plan",()=>_e(t))}function _e(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},m=t.edges.map(()=>0);let h=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,m[v.k]+1));m[c.k]=f,f>1&&(h=!0),l.push(c)}const y=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{y[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const $=ut();for(let c=1;c{const O=s[D],V=t.byId.get(H.from).i,q=t.byId.get(H.to).i,W=q===c&&(O==="down"||O==="trunk"||O==="rail"||O==="end-down"),_=V===c&&q===c-1&&O==="up",L=q===c-1&&O==="end-up";W&&(O==="trunk"||O==="end-down")&&(M=!0),L&&(I=!0),(W||_||L)&&H.label&&(B++,C=Math.max(C,O==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),$[f.id]=C}return{routes:s,gutter:d,lanes:m,exits:y,gaps:$,third:h}}var $t=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Vt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...$t(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function wt(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Zt(t,e){return yt(e,`key:${t}`,()=>je(t,e))}var Ce=Zt;function je(t,e){const n=[],s=(o,a,i={})=>n.push(k("li",{class:`${t}-entry`,...i},o,k("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),k("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(wt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(wt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(wt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Vt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Vt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...$t(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),k("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(wt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(wt(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Be(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...$t(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function jt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Te(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},jt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},jt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?At(n.detail).flatMap((r,o)=>[o?" ":"",k("span",{class:`${t}-run`},r)]):n.detail)),s}function Re(t,e){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},jt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>k("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},k("span",{class:`${t}-keyseat`},n.key??""),k("span",{class:`${t}-cname`},n.name),n.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?k("span",{class:`${t}-ctype`},n.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ut=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Mt(t,e,n,s){const{P:r}=t,o=Oe(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=gt(d.gaps,n.id)??32,y=gt(s.grow,n.id)??0;i.push(`--_gap:${y?`calc(${Ut(l)} + var(--basalt-space-4) * ${y})`:Ut(l)}`)}const u=gt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const m=gt(s.words,n.id);m&&i.push(`--_ww:${m}px`);const h=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?Se(e,n):void 0,tabindex:h},n.shape==="decision"?k("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Wt(n.mark.onLight)};--_md:${Wt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Re(r,n):Te(r,e,n))}function We(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=kt(e,d);if(!u)continue;const m=[0,1,2,3].map(h=>Dt(e,d,h));r.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`},Mt(t,e,d,n))))),r.push(ze(t,e)),r;const o=d=>{const u=d.group?e.groups.find(m=>m.id===d.group):void 0;return u?.parent?e.groups.find(m=>m.id===u.parent):u},a=(d,u,m)=>{const h=t.plan?gt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:h?`--_ggrow:${h}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),m)};let i=0;for(;ic.id===m[l].group):void 0;if(!y){h.push(Mt(t,e,m[l],n)),l++;continue}const $=[];for(;lMt(t,e,c,n))))}r.push(a(u,m,h))}return r}function ze(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(k("p",{class:`${n}-band`},k("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=k("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=k("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),m=d?.col??1,h=u?.col??1,l=m===h,y=l&&m===e.nodes.length,$=Ft(e,i.kind);a.c.push(k("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?y?"start":"end":void 0,style:`--_a:${Math.min(m,h)};--_b:${Math.max(m,h)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(i.n)),k("span",{class:`${n}-mlabel`},i.label)),k("span",{class:`${n}-route`},d?.short??i.from," ",Be(n,i.kind),k("span",{class:t.hidden}," to ")," ",u?.short??i.to,$?` · ${$}`:""),i.note?k("span",{class:`${n}-note`},i.note):null))}return k("div",{class:`${n}-steps`},s)}function Jt(t,e){return yt(e,`list:${t}`,()=>Ne(t,e))}var Fe=Jt;function Ne(t,e){const n=Math.min(6,e.heading+1),s=h=>k(`h${n}`,{class:`${t}-list-head`},h),r=h=>k("strong",null,h),o=h=>h.href?k("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},r(h.name)):r(h.name),a=h=>k("code",{class:`${t}-code`},h),i=h=>e.byId.get(h)?.name??h,d=h=>{const l=Ft(e,h);return l?` (${l})`:""},u=h=>h.focal&&e.legend.focal?` ${bt(e.legend.focal)}`:"";if(e.type==="architecture"){const h=$=>k("li",null,o($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?a($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",u($)),l=[s("Parts")],y=e.nodes.filter($=>!$.group);y.length&&l.push(k("ul",{class:`${t}-list-items`},y.map(h)));for(const $ of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},$.label)),$.members.length&&l.push(k("ul",{class:`${t}-list-items`},$.members.map(c=>h(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===$.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>h(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map($=>k("li",null,r(i($.from))," to ",r(i($.to)),$.label?[": ",a(pt($.label))]:"",`${d($.kind)}.`)))),l}if(e.type==="flowchart"){const h=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const y=e.edges.filter(f=>f.from===l.id),$=l.shape==="decision"?"Decision":l.shape==="terminal"?y.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${$}.`,u(l),y.length?k("ul",{class:`${t}-list-exits`},y.map(f=>k("li",null,f.label?`If ${pt(f.label)}: go to ${h(f.to)}, `:`Then: go to ${h(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(h=>{const l=e.edges.filter(y=>y.from===h.id);return k("li",null,`${h.laneLabel}: `,o(h),h.detail?[", ",h.mono?a(h.detail):h.detail]:"",".",u(h),l.length?[" Then ",...l.flatMap((y,$)=>[$?"; ":"",`to step ${e.byId.get(y.to).step}, `,r(i(y.to)),y.label?[": ",a(pt(y.label))]:"",d(y.kind)]),"."]:"")}))];if(e.type==="sequence"){const h=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(y=>k("li",null,r(y.name),y.kind?`, ${y.kind}`:"",".",u(y),Nt(e,y))))];h.push(s("Messages"));let l=null;for(const y of e.steps){if("band"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},y.band));continue}if("open"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":y.depth>1?y.depth:void 0},`${e.frameWords[y.open]}: ${y.label}`));continue}if("otherwise"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":y.depth>1?y.depth:void 0},`${e.frameWords.else}: ${y.otherwise}`));continue}if("close"in y){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:y.n}),h.push(l)),l.c.push(k("li",null,a(y.label),": ",r(i(y.from))," to ",r(i(y.to)),`${d(y.kind)}.`,y.note?` ${bt(y.note)}`:""))}return h}const m=[];for(const h of e.nodes)m.push(k(`h${n}`,{class:`${t}-list-group`},h.href?k("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},a(h.name)):a(h.name),u(h))),m.push(k("ul",{class:`${t}-list-items`},[...(h.columns??[]).map(l=>k("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...h.more?[k("li",null,`and ${h.more} more ${h.more===1?"column":"columns"}`)]:[]]));return m}function Xt(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&St(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Bt(t,e=!1){const n=e&&t.type!=="sequence"&&St(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Ae(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var He=(t,e)=>{for(let n=0;n({col:t.type==="sequence"?e.i+1:e.col,rows:[e.row,e.row2]});function St(t){return yt(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...De(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=$=>i?[$.col,$.col]:$.rows,m=$=>i?$.rows:[$.col,$.col],h=u(o),l=m(o);let y=null;return e.forEach(($,c)=>{if($===o)return;const f=u($),v=m($),B=d?f[0]-h[1]:h[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!y||He(M,y.rank))&&(y={id:$.id,rank:M})}),y?.id??null},s=ut();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var Yt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Qt(t,e,n){const s=n.prefix,r=Ie(n.base),o=t.type==="sequence"||t.type==="schema"?null:Kt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,m=`h${t.heading}`,h=[`--_cols:${Ct(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Ht(t):[0,0,0,0],y=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",$=i&&e.pad?"3":void 0;h.push(`--_gpad:${y(l[0],"8",$)} ${y(l[1],"4")} ${y(l[2],"4",$)} ${y(l[3],"4")}`)}return Yt(t)&&h.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&h.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Ct(t),"data-reach":t.type==="architecture"?Gt(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-viewer":n.viewer?"":void 0,style:h.join(";")},k("div",{class:`${s}-head`},k(m,{id:r.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},We(a,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Zt(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Jt(s,t)),k("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Xt(t,i)} ${n.viewer}`:Xt(t,i)),k("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Ge(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Et=(t,e)=>t==="main"?e.line:e.hair,dt=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ft=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Pt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function ct(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2,h=e==="top"||e==="bottom";if(t.shape==="decision"){if(h){const $=n,c=m*Math.max(0,1-Math.abs($-i)/u);return{x:$,y:e==="top"?d-c:d+c}}const l=n,y=u*Math.max(0,1-Math.abs(l-d)/m);return{x:e==="left"?i-y:i+y,y:l}}if(t.shape==="terminal"){const l=Math.min(u,m);if(h){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const y=n,$=y-d,c=Math.abs($)>=l?0:Math.sqrt(l*l-$*$);return{x:e==="left"?s+l-c:o-l+c,y}}return h?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Ke(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/m<1-n/Math.min(u,m);if(e.shape==="terminal"){const h=Math.min(u,m),l=Math.min(Math.max(t.x,s+h),o-h);return Math.hypot(t.x-l,t.y-d)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Ue(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var At=t=>t?t.split(/\s+/).filter(Boolean):[];function Je(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`→ ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),m=d.mark&&!Ze()?(d.shape==="participant"?2:1)*s("6"):0;let h=0;const l=d.href?16+s("1-5"):0,y=At(d.name);if(y.forEach((c,f)=>{h=Math.max(h,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:m)+(f===y.length-1?l:0))}),t.type!=="data-flow")for(const c of At(d.kind))h=Math.max(h,n(c,"mono")+m);for(const c of At(d.detail))h=Math.max(h,n(c,d.mono?"mono":"sans"));const $=d.shape==="decision"?h/.62:h+u+2*e.hair;r=Math.max(r,Math.ceil($))}const a=Ct(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(Yt(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Gt(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ee(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Tt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ne(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ht=t=>t.slice(1).map((e,n)=>[t[n],e]);function Lt(t,e,n){const s=[];for(let o=0;oMath.min(c.x,f.x)+.75&&CMath.min(v.y,B.y)+.75&&Mr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",oe={top:"bottom",bottom:"top",left:"right",right:"left"};function Ye(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Qe(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,m]=e[a],h=i.row===d.row&&tt(u)&&tt(m)&&u===oe[m]||i.col===d.col&&!tt(u)&&!tt(m)&&u===oe[m];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:h,f:.5},{edge:a,end:"to",node:d,side:m,far:i,straight:h,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const m=new Map;for(const c of d)m.has(c.far.id)||m.set(c.far.id,[]),m.get(c.far.id).push(c);for(const c of m.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const h=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),y=u.filter(c=>i(c)<0),$=u.filter(c=>i(c)>=0);y.forEach((c,f)=>{c.f=h*(f+1)/(y.length+1)}),$.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/($.length+1)})}return s}function se(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?ct(t,e,r+(a-r)*n):ct(t,e,s+(o-s)*n)}function ae(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:dt(o,n),shape:a.shape,i:a.i})}),r}function re(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var ie=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function le(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function Pe(t,e,n,s,r,o,a,i,d){const u=a.space,m=[],h=[],l=[],y=[],$=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*Ot(v),M=f.pts.length-2,I=[];ht(f.pts).forEach(([q,W],_)=>{const L=Math.abs(q.y-W.y)<.01,j=L?q.x:q.y;let F=L?W.x:W.y;const Z=Math.sign(F-j)||1;_===M&&(F-=Z*a.head);let N=[[j,F]];for(const w of r)for(const S of L?[w.l,w.r]:[w.t,w.b]){const g=L?q.y:q.x;(L?g>w.t&&gw.l&&gS>Math.min(x,E)+1&&S{const g=(w+S)/2,b=L?{x:g,y:q.y}:{x:q.x,y:g};return!r.some(x=>b.x>x.l&&b.xx.t&&b.y1&&U(w,S)?1:0})}),I.sort((q,W)=>W.pri-q.pri||W.len-q.len);let H=null,D=!1;const O=(q,W=!0)=>{const _=Pt(q,$);return W&&(q.lo.r||q.to.b)||n.some(L=>te(_,L))||m.some(L=>ft(_,L))||s.heads.some(L=>ft(_,L))||s.rects.some(L=>ft(_,L))?!1:!e.some(L=>L.i!==f.i&&ht(L.pts).some(([j,F])=>ft(_,ie(j,F,L.width))))};for(const q of I){for(const W of[1/2,1/3,2/3]){const _=q.p+(q.q-q.p)*W,L=[],j=u("2")+f.width/2;if(q.horiz?(q.len>=B+2*u("1")+u("3-5")&&L.push({box:{l:_-B/2-u("1"),r:_+B/2+u("1"),t:q.c-C/2,b:q.c+C/2},on:!0}),L.push({box:{l:_-B/2,r:_+B/2,t:q.c-j-C,b:q.c-j},on:!1}),L.push({box:{l:_-B/2,r:_+B/2,t:q.c+j,b:q.c+j+C},on:!1})):(q.len>=C+u("3")&&L.push({box:{l:q.c-B/2-u("1"),r:q.c+B/2+u("1"),t:_-C/2,b:_+C/2},on:!0}),L.push({box:{l:q.c+j,r:q.c+j+B,t:_-C/2,b:_+C/2},on:!1}),L.push({box:{l:q.c-j-B,r:q.c-j,t:_-C/2,b:_+C/2},on:!1})),H=L.find(F=>O(F.box))??null,H)break;!D&&L.some(F=>O(F.box,!1))&&(D=!0)}if(H)break}if(!H){l.push(f.i),D&&y.push(f.i);continue}const V=le(H.box,d.ox,d.oy,q=>O(q));m.push(V),h.push({i:f.i,text:v,box:V,on:H.on})}return{labels:h,unseated:l,bounded:y}}function ce(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=dt(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(dt(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=dt(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(dt(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function tn(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,m=ae(s,a,i,o),h=[...m.values()],l=Xe(a),y=i.left-Math.floor(i.left),$=i.top-Math.floor(i.top),c=ee(y,$),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:y,oy:$};if(s.type==="sequence")return nn(t,M,c);let I,H=[];s.type==="schema"?I=s.edges.map(g=>{const b=s.byId.get(g.from),x=s.byId.get(g.to);if(b.col===x.col){const E=b.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return x.col>b.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const b=s.byId.get(g.from),x=s.byId.get(g.to),[E,A]=Ye(b,x);return[g.fromSide??E,g.toSide??A]}),H=Qe(s,I,d||(()=>{})));const D=(g,b)=>{const x=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${b}"]`);if(!x)return 0;const E=dt(x,i);return(E.t+E.b)/2},O=s.edges.map((g,b)=>{const[x,E]=I[b],A=m.get(g.from),T=m.get(g.to),K=Et(g.kind,r);if(g.fk){const X=D(g.from,g.fromRow),ot=D(g.to,g.toRow),Y=c.y(X,K),st=c.y(ot,K);return{p1:{x:x==="right"?A.rect.r:A.rect.l,y:Y},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:X,r2:Math.abs(Y-st)<.01?X:ot}}const Q=H.find(X=>X.edge===b&&X.end==="from").f,J=H.find(X=>X.edge===b&&X.end==="to").f;let z=se(A,x,Q),G=se(T,E,J);const nt=tt(x)?z.y:z.x;let et=tt(E)?G.y:G.x;return tt(x)?z={...z,y:c.y(z.y,K)}:z={...z,x:c.x(z.x,K)},tt(E)?G={...G,y:c.y(G.y,K)}:G={...G,x:c.x(G.x,K)},tt(x)&&tt(E)&&Math.abs(z.y-G.y)<1.01&&(G={...G,y:z.y},et=nt),!tt(x)&&!tt(E)&&Math.abs(z.x-G.x)<1.01&&(G={...G,x:z.x},et=nt),z=tt(x)?ct(A,x,z.y):ct(A,x,z.x),G=tt(E)?ct(T,E,G.y):ct(T,E,G.x),{p1:z,p2:G,r1:nt,r2:et}}),V=new Set;s.type==="schema"&&s.edges.forEach((g,b)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&V.add(b)});const q=new Map,W=new Set;s.edges.forEach((g,b)=>{if(V.has(b))return;const[x,E]=I[b],{p1:A,p2:T}=O[b],K=s.byId.get(g.from),Q=s.byId.get(g.to);let J=null,z=null,G=!1;if(x===E){if(tt(x)){const X=x==="right"?Math.max(B(K),B(Q)):Math.min(B(K),B(Q))-1,ot=l.cols[X-1],Y=l.cols[X];ot&&Y&&(J=`c${X}`,z=[ot[1],Y[0]],G=!0)}else{const X=x==="bottom"?Math.max(K.row2,Q.row2):Math.min(K.row,Q.row)-1,ot=l.rows[X-1],Y=l.rows[X];ot&&Y&&(J=`r${X}`,z=[ot[1],Y[0]],G=!1)}J&&W.add(b)}else if(tt(x)&&tt(E)&&Math.abs(A.y-T.y)>.5){const X=B(Q),ot=E==="left",Y=l.cols[(ot?X-1:X)-1],st=l.cols[(ot?X:X+1)-1];Y&&st&&(J=`c${ot?X-1:X}`,z=[Y[1],st[0]],G=!0)}else if(!tt(x)&&!tt(E)&&Math.abs(A.x-T.x)>.5){const ot=E==="top"?Q.row-1:Q.row2,Y=l.rows[ot-1],st=l.rows[ot];Y&&st&&(J=`r${ot}`,z=[Y[1],st[0]],G=!1)}if(!J||!z)return;q.has(J)||q.set(J,{span:z,vertical:G,members:new Map});const nt=`${g.to}.${E}.${Math.round(G?T.y:T.x)}`,et=q.get(J);et.members.has(nt)||et.members.set(nt,[]),et.members.get(nt).push(b)});const _=new Map,L=g=>{const[b,x]=I[g],{p1:E,p2:A}=O[g];if(tt(b)&&tt(x)){if(b===x){const K=_.get(g)??(b==="right"?Math.max(E.x,A.x)+u("4"):Math.min(E.x,A.x)-u("4"));return[E,{x:K,y:E.y},{x:K,y:A.y},A]}if(Math.abs(E.y-A.y)<=.5)return[E,{x:A.x,y:E.y}];const T=_.get(g)??(E.x+A.x)/2;return[E,{x:T,y:E.y},{x:T,y:A.y},A]}if(!tt(b)&&!tt(x)){if(b===x){const K=_.get(g)??(b==="bottom"?Math.max(E.y,A.y)+u("4"):Math.min(E.y,A.y)-u("4"));return[E,{x:E.x,y:K},{x:A.x,y:K},A]}if(Math.abs(E.x-A.x)<=.5)return[E,{x:E.x,y:A.y}];const T=_.get(g)??(E.y+A.y)/2;return[E,{x:E.x,y:T},{x:A.x,y:T},A]}return tt(b)?[E,{x:A.x,y:E.y},A]:[E,{x:E.x,y:A.y},A]},j=g=>{const b=s.edges[g],x=Et(b.kind,r),E=L(g),A=ne(E,x,c);let T;return E.length===A.length&&(T=ht(E).map(([K,Q])=>Math.abs(K.y-Q.y)<.75?(K.y+Q.y)/2:(K.x+Q.x)/2),T[0]=O[g].r1,T.length>1&&(T[T.length-1]=O[g].r2)),{i:g,from:b.from,to:b.to,kind:b.kind,pts:A,tip:A[A.length-1],dir:Tt(A),dot:b.fk?A[0]:void 0,width:x,axes:T}},F=()=>s.edges.flatMap((g,b)=>V.has(b)?[]:[j(b)]);let Z=null;const N=g=>{Z??(Z=F());const b=Z.map(x=>g.has(x.i)?j(x.i):x);return{lines:b,score:en(b,g)*1e5+Lt(b,void 0,g).length*1e3+Rt(b.filter(x=>g.has(x.i)),h,s).length}},U=(g,b)=>{const x=g.flatMap(E=>{const{p1:A,p2:T}=O[E];return b?[A.y,T.y]:[A.x,T.x]});return[Math.min(...x),Math.max(...x)]};for(const[,g]of q){const b=[...g.members.values()].map(E=>({members:E,run:U(E,g.vertical)})).sort((E,A)=>E.run[0]-A.run[0]),x=[];for(const E of b){const A=x[x.length-1];A&&A.some(T=>T.run[0]W.has(nt)))continue;const A=E.map(nt=>nt.members),T=A.length,K=(g.span[1]-g.span[0])/(T+1);KX.forEach(Y=>_.set(Y,g.span[0]+K*(ot+1))));const et=N(Q);et.scorent.forEach(X=>_.set(X,g.span[0]+K*(et+1)))),Z=G}}M.lines=F();for(const g of V)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=Lt(M.lines),M.through=Rt(M.lines,h,s),M.outside=ue(M.lines,f,v,r);const{obstacles:p,groups:w}=ce(a,i,o,C);p.heads=M.lines.map(g=>re(g,r));const S=Pe(s,M.lines,h,p,w,{l:0,t:0,r:f,b:v},r,e,{ox:y,oy:$});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(de(M.lines,null).flat())],M}function en(t,e){return de(t,e).length}function de(t,e){const n=[];for(let s=0;s=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[m.x,h.x]:[m.y,h.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*fe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Rt(t,e,n){const s=[];for(const r of t){const o=ht(r.pts);e.some(a=>o.some(([i,d])=>Ve(i,d,a)))&&s.push(r.i)}return s}function nn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,dt(M,i)));const m=a.querySelector(`.${o}-steps`),h=m?dt(m,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:h})}const y=M=>u.get(M.id),$=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=dt(M,i);$.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const H=l(M.who),D=I.i===s.nodes.length-1&&s.nodes.length>1?-1:1,O=(M.depth-1)*d("1")*D,V=$.get(M.from)??0,q=$.get(M.to)??V,W=M.from===M.to;return{l:n.x(H-f+O,r.hair),r:n.x(H+f+O,r.hair),t:n.y(W?V-d("2")-d("1"):V,r.hair),b:n.y(W?V+d("2")+d("1"):q,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,H)=>B.filter(({bar:D})=>D.who===M&&D.to>=I&&(H?D.from<=I:D.fromO.bar.depth-D.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,H=M.dataset.to,D=M.dataset.kind??"plain",O=Et(D,r),V=dt(M,i),q=n.y((V.t+V.b)/2,O),W=Number(M.querySelector(`.${o}-num`)?.textContent??0);let _=l(I),L=l(H),j;if(I===H){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,W,!0),b=g?S>0?g.r:g.l:_,x=n.y(q-d("2"),O),E=n.y(q+d("2"),O);j=[{x:b,y:x},{x:n.x(_+S,O),y:x},{x:n.x(_+S,O),y:E},{x:b,y:E}]}else{const S=L>_?1:-1,g=C(I,W,!1),b=C(H,W,!0);g&&(_=S>0?g.r:g.l),b&&(L=S>0?b.l:b.r),j=[{x:_,y:q},{x:L,y:q}]}e.lines.push({i:W,from:I,to:H,kind:D,pts:j,tip:j[j.length-1],dir:Tt(j),width:O});const F=M.querySelector(`.${o}-said`),Z=M.querySelector(`.${o}-note`),N=s.byId.get(I),U=s.byId.get(H);if(!N||!U)return;const p=I===H?(()=>{const S=s.nodes[N.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-_)-d("6")-d("2-5")-d("2")})():Math.abs(L-_)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>p+.5&&e.unseated.push(W)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((D,O)=>D+O.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function he(t,e,n,s=ut()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,m=ae(r,i,d,a),h=[...m.values()],l=d.left-Math.floor(d.left),y=d.top-Math.floor(d.top),$=ee(l,y),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:y},B=ut();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(L,j,F)=>{const Z=[L];for(let N=1;N<=(gt(s,j)??0);N++)Z.push({...L,t:L.t+F*u("4")*N,b:L.b+F*u("4")*N});return Z},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(L=>{const j=L.parentElement,F=dt(j,d),Z=getComputedStyle(j);I.set(L.dataset.node,F.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const H=r.nodes,D=L=>m.get(H[L].id),O=[],V=L=>Et(r.edges[L].kind,o);r.edges.forEach((L,j)=>{const F=n.routes[j],Z=m.get(L.from),N=m.get(L.to),U=V(j);let p=[];const w=L.label,S=w?e(w,"label"):0,g=w?16*Ot(w):16,b=u("4");if(F==="down"||F==="up"){const E=Math.max(Z.rect.l,N.rect.l),A=Math.min(Z.rect.r,N.rect.r),T=r.edges.map((z,G)=>({o:z,j:G})).filter(({o:z,j:G})=>(n.routes[G]==="down"||n.routes[G]==="up")&&(z.from===L.from&&z.to===L.to||z.from===L.to&&z.to===L.from)),K=T.findIndex(z=>z.j===j),Q=T.length<2?.5:T.length===2?K===0?.25:.75:(K+1)/(T.length+1),J=$.x(E+(A-E)*Q,U);if(p=F==="down"?[ct(Z,"bottom",J),ct(N,"top",J)]:[ct(Z,"top",J),ct(N,"bottom",J)],w){let z=Math.min(p[0].y,p[1].y),G=Math.max(p[0].y,p[1].y);F==="down"?G-=o.head:z+=o.head;const nt=[...i.querySelectorAll(`.${a}-group`)].map(Y=>dt(Y,d));let et=[[z,G]];for(const Y of nt)for(const st of[Y.t,Y.b])et=et.flatMap(([rt,R])=>st>rt+1&&stnt.some(rt=>(Y+st)/2>rt.t&&(Y+st)/2rt.l&&J1){const Y=et.filter(([rt,R])=>!X(rt,R));[z,G]=(Y.length?Y:et).reduce((rt,R)=>R[1]-R[0]>rt[1]-rt[0]?R:rt)}const ot=[1/2,1/3,2/3].map(Y=>{const st=z+(G-z)*Y;return{l:J-S/2-u("1"),r:J+S/2+u("1"),t:st-g/2,b:st+g/2}});O.push({k:j,cands:ot,on:!0,card:F==="down"?L.to:L.from})}}else if(F==="trunk"||F==="rail"){const E=$.x(Math.max(Z.rect.l,F==="rail"?N.rect.l:Z.rect.l)+u(F==="trunk"?"8":"3"),U),A=ct(Z,"bottom",E);if(F==="rail"){if(p=[A,ct(N,"top",E)],w){const T=N.rect.t-u("6");O.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},L.to,-1),on:!1,card:L.to})}}else{const T=$.x(N.rect.l+u("6"),U),K=$.y(N.rect.t-b,U);p=[A,{x:E,y:K},{x:T,y:K},ct(N,"top",T)],w&&O.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:K-g/2,b:K+g/2},L.to,-1),on:!1,card:L.to})}}else{const E=Math.min(I.get(L.from)??c,I.get(L.to)??c),A=$.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),U),T=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[j],U),K=ct(Z,"right",T),Q=$.x(N.rect.r-u("6"),U),J=F==="end-down",z=$.y(J?N.rect.t-b:N.rect.b+b,U);p=[K,{x:A,y:K.y},{x:A,y:z},{x:Q,y:z},ct(N,J?"top":"bottom",Q)];const G=J?L.to:H[N.i+1]?.id??L.to;w&&O.push({k:j,cands:M({l:Q-u("2-5")-S,r:Q-u("2-5"),t:z-g/2,b:z+g/2},G,J?-1:1),on:!1,card:G})}const x=ne(p,U,$);v.lines.push({i:j,from:L.from,to:L.to,kind:L.kind,pts:x,tip:x[x.length-1],dir:Tt(x),width:U})}),v.crossings=Lt(v.lines),v.through=Rt(v.lines,h,r),v.outside=ue(v.lines,c,f,o);const{obstacles:q}=ce(i,d,a,0);q.heads=v.lines.map(L=>re(L,o));const W=[],_={l:0,t:0,r:c,b:f};for(const L of O){const j=N=>{const U=Pt(N,u("1"));return N.l<_.l-.5||N.r>_.r+.5||N.t<_.t-.5||N.b>_.b+.5||h.some(p=>te(U,p))||W.some(p=>ft(U,p))||q.heads.some(p=>ft(U,p))||q.rects.some(p=>ft(U,p))||v.lines.some(p=>p.i!==L.k&&ht(p.pts).some(([w,S])=>ft(U,ie(w,S,p.width))))},F=L.cands.find(N=>!j(N));F||(B[L.card]=(B[L.card]??0)+1,v.unseated.push(L.k));const Z=F?le(F,l,y,N=>!j(N)):L.cands[0];W.push(Z),v.labels.push({i:L.k,text:r.edges[L.k].label,box:Z,on:L.on})}return{geo:v,grow:B}}function on(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...M})),h=m[m.length-1];h.x-=o.x*u,h.y-=o.y*u;const l=e.tip.x-o.x*i,y=e.tip.y-o.y*i,$=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=lt(e.kind),B=a?``:``,C=e.dot?``:"";return`${B}${C}`}function pe(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const m=d.map(h=>{const l=e.lines[h.top],y=e.lines[h.under],$=l.width/2+n.cut,c=y.width/2+1;return h.underVertical?``:``}).join("");a+=`${m}`}return{defs:a,ids:r}}function ge(t,e,n,s){const{defs:r,ids:o}=pe(t,e,n,s),a=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),i=e.lines.map((m,h)=>an(t,m,n,o.get(h)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),d=`${r?`${r}`:""}${a}${i}`,u=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` +`).map(lt).join("
")}
`).join("");return d+u}function me(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const m=Ge(t),h=Ue(u,n),l=Je(e,m,h);i?.(l.least);const y=t.clientWidth,$=(()=>{const q=document.activeElement;return q&&u.contains(q)&&q.dataset.node?q.dataset.node:void 0})(),c=q=>mt(e,q)?{...q,stop:q.stop&&e.byId.has(q.stop)?q.stop:e.nodes[0]?.id,keep:void 0}:{...q,stop:q.stop??e.nodes[0]?.id,keep:$&&q.layout!=="drawn"?$:void 0};let f=!1;const v=q=>{if(f=!1,e.type!=="flowchart")return q;o({...q,heights:void 0,words:void 0});const W=ut(),_=ut();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(L=>{const j=L.querySelector(`.${n}-words`);if(!j)return;const F=L.getBoundingClientRect(),Z=p=>{const w={w:p.width+2*m.space("2-5"),h:p.height+2*m.space("2")},S=1-w.w/F.width,g=S>.05?w.h/2/S:w.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},N=j.getBoundingClientRect();let U=Z(N);if(U>F.width){const p=b=>(L.style.setProperty("--_ww",`${b}px`),j.getBoundingClientRect()),w=Math.floor(L.clientWidth-2*m.space("2-5"));let S=Math.ceil(N.width),g=N.height;for(;S1;){const T=b+x>>1;p(T).heightF.width&&(f=!0)}),{...q,heights:W,words:Object.keys(_).length?_:void 0}},B=()=>({m:e,tk:m,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(q,W)=>W.map(_=>vt(e,q.lines.find(L=>L.i===_))).join(", ");if(y>=l.least){const q=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:tn(B(),h)}};let{dd:W,g:_}=q(!1);const L=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!L(_)&&_.unseated.length&&_.unseated.every(j=>_.bounded?.includes(j))){const j=q(!0);!L(j.g)&&!j.g.unseated.length&&({dd:W,g:_}=j)}if(!L(_)&&!_.unseated.length)return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the drawn layout: ${_.crossings.map(j=>`${vt(e,_.lines[j.top])} over ${vt(e,_.lines[j.under])}`).join("; ")}`),{dyn:W,geo:_,ink:ge(n,_,m,s),tokens:m,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: a decision would be taller than it is wide`),_.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${_.misfit.join("; ")}`),_.through.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.through)} would pass through a node`),_.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.overlaps)} would lie on one another`),_.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.outside)} would leave the drawing`),_.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: no clean seat for ${_.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ut(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:m,least:l.least};const H=Kt(e);let D=he(B(),h,H,I.grow);for(let q=0;q<6&&Object.keys(D.grow).length;q++){const W=ut(I.grow);for(const[_,L]of Object.entries(D.grow))W[_]=(gt(W,_)??0)+L;I={...I,grow:W},o(I),D=he(B(),h,H,W)}const O=D.geo;if(O.unseated.length>0||O.through.length>0||O.outside.length>0||H.third){O.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(O.unseated)].map(_=>`"${e.edges[_]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),O.through.length&&a?.(`in the stacked drawing ${M(O,O.through)} would pass through a node, so its lines are not drawn`),O.outside.length&&a?.(`in the stacked drawing ${M(O,O.outside)} would leave the drawing, so its lines are not drawn`),H.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const q={...O,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ut(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:q,ink:"",tokens:m,least:l.least}}return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${O.crossings.map(q=>`${vt(e,O.lines[q.top])} over ${vt(e,O.lines[q.under])}`).join("; ")}`),{dyn:I,geo:O,ink:ge(n,O,m,s),tokens:m,least:l.least}}function vt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function rn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const m=Lt(n.lines,i),{defs:h,ids:l}=pe(e,{...n,crossings:m},s,r),y=t.querySelector(`.${e}-svg`);if(!y)return;let $=y.querySelector("defs");!$&&h&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),y.insertBefore($,y.firstChild)),$&&($.innerHTML=h),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var ln=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function cn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",ln()||fn(t)?"done":"pending")}}var dn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function fn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(dn(t))!==null}catch{return!1}}function ye(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function un(t,e,n,s=!1,r=!1){const o=s?St(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var hn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],be=["data-layout","data-measured","data-bare","data-motion","data-first-visit"],pn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],$e=t=>t==null||t===!1;function gn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function we(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?be:hn;for(const a of s)$e(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,m=new Map(String(i??"").split(";").map(h=>{const l=h.indexOf(":");return[h.slice(0,l).trim(),h.slice(l+1).trim()]}).filter(([h])=>h));for(const[h,l]of m)u.getPropertyValue(h).trim()!==l&&u.setProperty(h,l);for(const h of pn)m.has(h)||u.removeProperty(h);continue}if(n&&!be.includes(a))continue;if($e(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,y,$){return{prefix:n,base:l,hasSource:y.source!==void 0&&y.source!==null&&y.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(l,y,$,c){var f=function(v){return''+lt(v)+""};return{source:lt(String(y.source||"")),summary:lt(String(y.summary||"")),hint:Bt(l).map(function(v){return""+v.keys.map(f).join(" ")+" "+lt(v.words)+""}).join(""),toggle:'"}}function a(l,y,$){var c=qt(l),f=Qt(c,{},r(y,l,$)),v=_t(f,o(c,l,y,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,y,$,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=qt(y);if(!$||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(y,f,c),C=document.createElement("div");C.innerHTML=B.open+"";var M=C.firstChild;i.forEach(function(R){l.removeAttribute(R)}),d.forEach(function(R){l.style.removeProperty(R)});for(var I=0;I :not(script[data-diagram])").forEach(function(R){R.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(R){console.warn("Basalt diagram: "+R)});var D=r(f,y,c),O={},V=null,q=null,W=null,_=Object.create(null),L=function(R){_[R]||(_[R]=1,console.warn("Basalt diagram: "+R))},j=function(R){we(l,Qt(v,R,D))},F=l.querySelector(".diagram-ink"),Z=l.querySelector(".diagram-toggle"),N=!c&&v.motion.animated&&typeof e.diagramMotion=="function",U=null,p=null,w=function(){N&&ye(l)};function S(){rn(l,n,V&&V.geo,V&&V.tokens,f,q||W)}function g(){Z&&(Z.setAttribute("aria-expanded",String(!!O.open)),Z.firstElementChild.textContent=O.open?"Hide the list":"View as list")}function b(){V=(c?c.measure:me)(l,v,n,f,O,j,L),O=V.dyn,j(O),g();var R=l.querySelector(":scope > .diagram-hint");if(R){var P=Bt(v,O.layout==="drawn").map(function(xt){return""+xt.keys.map(function(yn){return''+lt(yn)+""}).join(" ")+" "+lt(xt.words)+""}).join("");R.innerHTML!==P&&(R.innerHTML=P)}mt(v,O)||(W=null);var it=F&&V.ink!==p;it&&(F.innerHTML=V.ink,p=V.ink),S(),N&&V.tokens&&(cn(l,!!(V.geo&&V.geo.lines.length)),it&&U&&U.redrawn()),c&&c.onMeasured&&V.tokens&&c.onMeasured(V,l)}function x(R){O=R,j(O)}function E(R){var P=O.stop;O=Object.assign({},O,{stop:R}),mn(l,n,P,R)}var A=function(R){var P=R&&R.closest?R.closest(".diagram-node"):null;return P&&l.contains(P)?P:null};function T(R){var P=A(R.target);if(!(!P||R.defaultPrevented)){if(w(),R.key==="Escape"){!c&&(q||W)&&(R.preventDefault(),q=W=null,S());return}if(mt(v,O)){var it=un(v,P.getAttribute("data-node"),R.key,O.layout==="drawn",getComputedStyle(P).direction==="rtl");if(it){R.preventDefault(),E(it);var xt=l.querySelector('.diagram-node[data-node="'+CSS.escape(it)+'"]');xt&&xt.focus()}}}}function K(R){var P=A(R.target);if(P){w();var it=P.getAttribute("data-node");q=P.matches(":focus-visible")?it:null,mt(v,O)&&O.stop!==it&&E(it),S()}}function Q(R){var P=A(R.target);P&&(A(R.relatedTarget)||(q=null),O.keep===P.getAttribute("data-node")&&x(Object.assign({},O,{keep:void 0})),S())}function J(R){if(!(R.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var P=A(R.target);P&&w();var it=P&&mt(v,O)?P.getAttribute("data-node"):null;it!==W&&(W=it,S())}}function z(){W&&(W=null,S())}function G(){w(),x(Object.assign({},O,{open:!O.open,autoOpen:void 0})),g()}l.addEventListener("keydown",T),l.addEventListener("focusin",K),l.addEventListener("focusout",Q),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",z),Z&&Z.addEventListener("click",G),b();var nt=l.clientWidth,et=0,X=!0,ot=new ResizeObserver(function(){Math.abs(l.clientWidth-nt)<.5||(nt=l.clientWidth,cancelAnimationFrame(et),et=requestAnimationFrame(b))});ot.observe(l),document.fonts&&document.fonts.ready.then(function(){X&&b()});var Y=matchMedia("(forced-colors: active)"),st=v.nodes.some(function(R){return R.mark});st&&Y.addEventListener("change",b),N&&(U=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},y));var rt=!c&&y.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,y,{model:v,settle:w,animated:N}):null;l.__diagram={stop:function(){rt&&rt.destroy(),X=!1,ot.disconnect(),cancelAnimationFrame(et),st&&Y.removeEventListener("change",b),U&&U.destroy(),l.removeEventListener("keydown",T),l.removeEventListener("focusin",K),l.removeEventListener("focusout",Q),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",z),Z&&Z.removeEventListener("click",G)},layout:b,key:m(y),send:U&&U.sendValue?U.sendValue:null}}function m(l){try{return JSON.stringify(l,function(y,$){return y==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function h(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var y=l.querySelector(":scope > script[data-diagram]");if(y)try{u(l,JSON.parse(y.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:qt,figureKey:Ce,figureList:Fe,hintEntries:Bt,toHtml:_t,escapeHtml:lt,settleEntrance:ye,measureFigure:me},t.diagram=function(l,y){var $=l.__diagram,c=$&&$.send?m(y):null;if(c!==null&&c===$.key){$.send(y.packet?y.packet.send:void 0);return}u(l,y)},e.step(62,"wireDiagrams",h)})(window.Basalt)})(); diff --git a/packages/react/src/architecture-diagram.tsx b/packages/react/src/architecture-diagram.tsx index 779c3b91..14d5f987 100644 --- a/packages/react/src/architecture-diagram.tsx +++ b/packages/react/src/architecture-diagram.tsx @@ -21,7 +21,7 @@ export interface ArchitectureDiagramProps extends DiagramFigureProps { } /** An architecture diagram (DECISIONS 281): nodes with a kind, a name and a detail, groups, and three kinds of line. */ -export function ArchitectureDiagram({ nodes, groups, edges, pulse, packet, motion, title, heading, legend, ...props }: ArchitectureDiagramProps) { - const spec = React.useMemo(() => ({ type: "architecture" as const, title, heading, legend, nodes, groups, edges, motion, pulse, packet }), [title, heading, legend, nodes, groups, edges, motion, pulse, packet]); - return ; +export function ArchitectureDiagram({ nodes, groups, edges, pulse, packet, motion, entrance, title, heading, legend, ...props }: ArchitectureDiagramProps) { + const spec = React.useMemo(() => ({ type: "architecture" as const, title, heading, legend, nodes, groups, edges, motion, entrance, pulse, packet }), [title, heading, legend, nodes, groups, edges, motion, entrance, pulse, packet]); + return ; } diff --git a/packages/react/src/data-flow-diagram.tsx b/packages/react/src/data-flow-diagram.tsx index 707c7039..166d9ecd 100644 --- a/packages/react/src/data-flow-diagram.tsx +++ b/packages/react/src/data-flow-diagram.tsx @@ -22,7 +22,7 @@ export interface DataFlowDiagramProps extends DiagramFigureProps { } /** A data flow (DECISIONS 281): lanes as bands, steps numbered in order; stacked, a step says its lane. */ -export function DataFlowDiagram({ lanes, nodes, edges, stepLabel, pulse, packet, motion, title, heading, legend, ...props }: DataFlowDiagramProps) { - const spec = React.useMemo(() => ({ type: "data-flow" as const, title, heading, legend, lanes, nodes, edges, stepLabel, motion, pulse, packet }), [title, heading, legend, lanes, nodes, edges, stepLabel, motion, pulse, packet]); - return ; +export function DataFlowDiagram({ lanes, nodes, edges, stepLabel, pulse, packet, motion, entrance, title, heading, legend, ...props }: DataFlowDiagramProps) { + const spec = React.useMemo(() => ({ type: "data-flow" as const, title, heading, legend, lanes, nodes, edges, stepLabel, motion, entrance, pulse, packet }), [title, heading, legend, lanes, nodes, edges, stepLabel, motion, entrance, pulse, packet]); + return ; } diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index fe317151..a5da9297 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -120,6 +120,10 @@ export interface DiagramSpec { run?: boolean; /** A sequence's frame words (DECISIONS 306, 1.2): "Only if", "Repeats", "One of these", "Otherwise". */ frameLabels?: DiagramFrameLabels; + /** `"first-visit"` (DECISIONS 306, 1.5): an animated figure's entrance plays until it has played once on this page, then is at rest. Needs an `id`. */ + entrance?: "always" | "first-visit"; + /** A sequence drawn as text art (DECISIONS 306, 1.2). */ + variant?: "drawn" | "text"; } // ============================================================================================================================================ @@ -199,7 +203,7 @@ export interface Model { stepWord: (n: number) => string; warnings: string[]; /** Motion (DECISIONS 292). Read and ignored when still. */ - motion: { animated: boolean; pulse?: string[]; packet?: { path: string[]; repeat: boolean; send?: number | string }; run: boolean }; + motion: { animated: boolean; pulse?: string[]; packet?: { path: string[]; repeat: boolean; send?: number | string }; run: boolean; firstVisit?: boolean }; /** Work that depends on the model alone, done once (see `memo`). */ memo: Map; } @@ -455,6 +459,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model pulse: movers ? route(spec.pulse) : undefined, packet: packetPath ? { path: packetPath, repeat: packetIn!.repeat === true, send: packetIn!.send } : undefined, run: type === "sequence" && spec.run === true, + firstVisit: spec.entrance === "first-visit" || undefined, }; if (checks) for (const n of nodes) { const says = n.mark?.says; @@ -1216,6 +1221,7 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { "data-measured": dyn.layout ? "" : undefined, "data-bare": dyn.bare ? "" : undefined, "data-motion": m.motion.animated ? "animated" : undefined, + "data-first-visit": m.motion.animated && m.motion.firstVisit ? "" : undefined, "data-viewer": o.viewer ? "" : undefined, style: style.join(";"), }, @@ -2447,7 +2453,14 @@ export function entranceDrawn(fig: HTMLElement, lines: boolean): void { const state = fig.getAttribute("data-entrance"); if (state === "running" || state === "done") return; if (!lines) { if (state) fig.removeAttribute("data-entrance"); return; } - if (!state) fig.setAttribute("data-entrance", entranceBlocked() ? "done" : "pending"); + if (!state) fig.setAttribute("data-entrance", entranceBlocked() || seenBefore(fig) ? "done" : "pending"); +} +/** The first visit's mark (DECISIONS 306, 1.5): where a figure's entrance has played on this page before. */ +export const visitKey = (fig: HTMLElement) => `basalt-diagram-entrance:${location.pathname}#${fig.id}`; +function seenBefore(fig: HTMLElement): boolean { + if (!fig.hasAttribute("data-first-visit") || !fig.id) return false; + // Storage that throws: it plays again. + try { return localStorage.getItem(visitKey(fig)) !== null; } catch { return false; } } /** Settles a pending or running entrance at once (a node hovered or focused, a key, a control used): every line whole, and the module told. */ @@ -2487,7 +2500,7 @@ export function keyTarget(m: Model, from: string, key: string, drawn = false, rt * script, first in the figure) is passed over, never mistaken for the heading. */ const MANAGED = ["data-layout", "data-measured", "role", "aria-roledescription", "aria-labelledby", "aria-describedby", "aria-label", "tabindex", "data-stops", "hidden"]; -const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion"]; +const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion", "data-first-visit"]; const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_gpad"]; const absent = (value: VAttrs[string]) => value === undefined || value === null || value === false; function pairs(el: Element, v: VElement): boolean { diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 73a74a90..73abb8b4 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -45,6 +45,8 @@ export interface DiagramFigureProps extends Omit, * where the reader zooms (from Fit or 100% to 400%) and pans it. `false` leaves both out. Before script there is no button: it does nothing without it. */ zoom?: boolean; + /** `"first-visit"` (DECISIONS 306, 1.5): an animated figure's entrance plays until it has played once on this page; later visits are at rest. Needs an `id`. */ + entrance?: "always" | "first-visit"; } const P = "basalt-diagram"; @@ -111,7 +113,7 @@ export interface DiagramFigureInternalProps extends DiagramFigureProps { viewer?: DiagramViewerMode; } -export function DiagramFigure({ spec, component, viewer, zoom = true, title: _title, heading: _heading, legend: _legend, motion: _motion, source, summary, className, style, onKeyDown, onFocus, onBlur, onPointerOver, onPointerLeave, ref: callerRef, ...props }: DiagramFigureInternalProps) { +export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: _entrance, title: _title, heading: _heading, legend: _legend, motion: _motion, source, summary, className, style, onKeyDown, onFocus, onBlur, onPointerOver, onPointerLeave, ref: callerRef, ...props }: DiagramFigureInternalProps) { const base = `dg${React.useId().replace(/[^a-zA-Z0-9_-]/g, "")}`; const level = usePanelLevel(); // The key hint is a data-kbd-hint legend, hidden on touch until a hardware key is pressed: this installs the listener that reveals it. @@ -150,7 +152,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, title: _ti // Development only: a bundler that sets NODE_ENV to production drops this block, strings included. React.useEffect(() => { if (process.env.NODE_ENV !== "production") for (const w of model.warnings) warnOnce(component, w); - }, [model, component]); + if (process.env.NODE_ENV !== "production" && model.motion.firstVisit && !props.id) warnOnce(component, 'entrance="first-visit" needs an id: without one the entrance plays on every visit'); + }, [model, component, props.id]); const measure = React.useCallback(() => { const fig = figRef.current; diff --git a/packages/react/src/diagram-motion-core.ts b/packages/react/src/diagram-motion-core.ts index 4ce229cb..dd1d861b 100644 --- a/packages/react/src/diagram-motion-core.ts +++ b/packages/react/src/diagram-motion-core.ts @@ -7,7 +7,7 @@ // This module plays that entrance when the figure comes into view, carries it across a re-measure on its one clock, settles it at once when the reader // acts or a mode turns on, and then runs the loops the data names while they may run. Every value is a token, read from the page. -import { entranceBlocked, pathD, settleEntrance } from "./diagram-core"; +import { entranceBlocked, pathD, settleEntrance, visitKey } from "./diagram-core"; import type { Geo, GLine, Model, Pt, Tokens } from "./diagram-core"; declare const process: { env: { NODE_ENV?: string } }; @@ -246,6 +246,15 @@ class Figure implements MotionController { }; } private entrance() { return this.host.fig.getAttribute("data-entrance"); } + /** The entrance ran on this visit (so a settle by the reader writes the first visit's mark). */ + private played = false; + private byMode() { const m = this.modes(); return m.held || m.print || m.reduce || m.forced; } + /** Writes the first visit's mark, where the figure asks for it (1.5). Storage that throws writes nothing: the entrance plays again next time. */ + private markVisit() { + const fig = this.host.fig; + if (!fig.hasAttribute("data-first-visit") || !fig.id) return; + try { localStorage.setItem(visitKey(fig), "1"); } catch { /* it plays again */ } + } private hasLines() { return Boolean(this.host.geo()?.lines.length); } // A figure whose viewer is open holds its loops as a traced one does (DECISIONS 310, 9.7), and they start again when it closes. private traced() { return this.host.fig.hasAttribute("data-tracing") || this.host.fig.hasAttribute("data-viewing"); } @@ -299,7 +308,9 @@ class Figure implements MotionController { // ---- The entrance (1.3 to 1.5) ---- private onSettle = () => { - // settleEntrance has already set data-entrance="done": every line whole, every label at rest, and then the loops may start. + // settleEntrance has already set data-entrance="done": every line whole, every label at rest, and then the loops may start. An entrance that played + // and gave way to the reader marks the first visit (1.5); one settled by a mode (the hold, print, reduced motion) does not. + if (this.played && !this.byMode()) this.markVisit(); this.clearIntro(); this.sync(); }; @@ -341,6 +352,7 @@ class Figure implements MotionController { const geo = this.host.geo(); if (!geo?.lines.length) return; this.host.fig.setAttribute("data-entrance", "running"); + this.played = true; this.t0 = now(); const { plans, factor } = this.plan(this.ordered(geo)); this.factor = factor; @@ -421,6 +433,7 @@ class Figure implements MotionController { private finishIntro() { if (this.entrance() !== "running") return; + this.markVisit(); this.host.fig.setAttribute("data-entrance", "done"); this.clearIntro(); this.sync(); diff --git a/packages/react/src/flowchart-diagram.tsx b/packages/react/src/flowchart-diagram.tsx index bd6115ec..b4a95b22 100644 --- a/packages/react/src/flowchart-diagram.tsx +++ b/packages/react/src/flowchart-diagram.tsx @@ -16,7 +16,7 @@ export interface FlowchartDiagramProps extends DiagramFigureProps { } /** A flowchart (DECISIONS 281): shape carries type, so every shape has a 3:1 contour; a decision is a diamond behind its words. */ -export function FlowchartDiagram({ nodes, edges, shapeLabels, motion, title, heading, legend, ...props }: FlowchartDiagramProps) { - const spec = React.useMemo(() => ({ type: "flowchart" as const, title, heading, legend, nodes, edges, shapeLabels, motion }), [title, heading, legend, nodes, edges, shapeLabels, motion]); - return ; +export function FlowchartDiagram({ nodes, edges, shapeLabels, motion, entrance, title, heading, legend, ...props }: FlowchartDiagramProps) { + const spec = React.useMemo(() => ({ type: "flowchart" as const, title, heading, legend, nodes, edges, shapeLabels, motion, entrance }), [title, heading, legend, nodes, edges, shapeLabels, motion, entrance]); + return ; } diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index c6930b42..f2a0909f 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -99,7 +99,7 @@ export type { DiagramShapeLabels, FlowchartDiagramProps, FlowchartNode } from ". export { DataFlowDiagram } from "./data-flow-diagram"; export type { DataFlowDiagramProps, DataFlowLane, DataFlowNode } from "./data-flow-diagram"; export { SequenceDiagram } from "./sequence-diagram"; -export type { SequenceDiagramProps, SequenceParticipant, SequenceStep } from "./sequence-diagram"; +export type { DiagramFrameLabels, SequenceDiagramProps, SequenceMessage, SequenceParticipant, SequenceStep } from "./sequence-diagram"; export { SchemaDiagram } from "./schema-diagram"; export type { SchemaColumn, SchemaDiagramProps, SchemaTable } from "./schema-diagram"; export { PhaseChart } from "./phase-chart"; diff --git a/packages/react/src/schema-diagram.tsx b/packages/react/src/schema-diagram.tsx index 41b451d5..834ec4c9 100644 --- a/packages/react/src/schema-diagram.tsx +++ b/packages/react/src/schema-diagram.tsx @@ -15,7 +15,7 @@ export interface SchemaDiagramProps extends DiagramFigureProps { } /** A database schema (DECISIONS 281): table cards with keys and a few columns; drawn, a line from each foreign key to the key it references. */ -export function SchemaDiagram({ tables, motion, title, heading, legend, ...props }: SchemaDiagramProps) { - const spec = React.useMemo(() => ({ type: "schema" as const, title, heading, legend, tables, motion }), [title, heading, legend, tables, motion]); - return ; +export function SchemaDiagram({ tables, motion, entrance, title, heading, legend, ...props }: SchemaDiagramProps) { + const spec = React.useMemo(() => ({ type: "schema" as const, title, heading, legend, tables, motion, entrance }), [title, heading, legend, tables, motion, entrance]); + return ; } diff --git a/packages/react/src/sequence-diagram.tsx b/packages/react/src/sequence-diagram.tsx index 157cbf36..8c4c55b5 100644 --- a/packages/react/src/sequence-diagram.tsx +++ b/packages/react/src/sequence-diagram.tsx @@ -2,9 +2,9 @@ import * as React from "react"; import { DiagramFigure } from "./diagram-figure"; import type { DiagramFigureProps } from "./diagram-figure"; -import type { SequenceParticipant, SequenceStep } from "./diagram-core"; +import type { SequenceParticipant, SequenceStep, DiagramFrameLabels } from "./diagram-core"; -export type { DiagramLegend, DiagramLineKind, SequenceParticipant, SequenceStep } from "./diagram-core"; +export type { DiagramFrameLabels, DiagramLegend, DiagramLineKind, SequenceMessage, SequenceParticipant, SequenceStep } from "./diagram-core"; export interface SequenceDiagramProps extends DiagramFigureProps { /** The participants, start to end. `short` names one in the stacked list. */ @@ -13,10 +13,14 @@ export interface SequenceDiagramProps extends DiagramFigureProps { steps: SequenceStep[]; /** Animated only: "Play the run" in the foot sends one packet through every message in order; while it runs it reads "Stop the run". */ run?: boolean; + /** The words for each frame operator and an alt's later branches (DECISIONS 306, 1.2): "Only if", "Repeats", "One of these", "Otherwise". */ + frameLabels?: DiagramFrameLabels; + /** `"text"` draws the same data as box-drawing characters in a code block, and a transcript where the art does not fit (1.2). Default `"drawn"`. */ + variant?: "drawn" | "text"; } /** A sequence diagram (DECISIONS 281): a head and a lifeline a participant, a 56px row a message; stacked, a numbered list. */ -export function SequenceDiagram({ participants, steps, run, motion, title, heading, legend, ...props }: SequenceDiagramProps) { - const spec = React.useMemo(() => ({ type: "sequence" as const, title, heading, legend, participants, steps, motion, run }), [title, heading, legend, participants, steps, motion, run]); - return ; +export function SequenceDiagram({ participants, steps, run, frameLabels, variant, motion, entrance, title, heading, legend, ...props }: SequenceDiagramProps) { + const spec = React.useMemo(() => ({ type: "sequence" as const, title, heading, legend, participants, steps, motion, entrance, run, frameLabels, variant }), [title, heading, legend, participants, steps, motion, entrance, run, frameLabels, variant]); + return ; } From 233413536077986e6567bc958d7ba32d5814fbcf Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:54:00 -0600 Subject: [PATCH 18/62] A trace on touch (DECISIONS 306, 1.5) Where lines are drawn, a tap (a click from a touch or a pen pointer) on a card traces it; the same card, the drawing's ground or "Clear highlight" clears it, and Esc. A linked card follows its link. "Clear highlight" is last in the foot, mounted whenever the figure is on touch (the media's, or after its first touch tap) and aria-disabled until a trace is up. The hint's seat says "Tap a part to highlight its lines. Tap it again to clear." on touch. No live region. A card that answers a tap is 44px tall on touch. None of it prints or shows in the viewer. React and the skill share tapTrace. The affordance is a few hundred bytes inline: a lazy chunk for one button and one line would cost more than it saves. Co-Authored-By: Claude Opus 5.5 --- .../skills/basalt-html/parts/diagram-zoom.css | 2 +- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 12 +++--- packages/react/src/diagram-core.ts | 18 ++++++++ packages/react/src/diagram-figure.tsx | 33 +++++++++++--- packages/react/src/styles/components.css | 11 ++++- tools/html-skill/src/modules/diagram.js | 43 ++++++++++++++++--- 7 files changed, 99 insertions(+), 22 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.css b/.agent/skills/basalt-html/parts/diagram-zoom.css index 24608262..8c319c02 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.css +++ b/.agent/skills/basalt-html/parts/diagram-zoom.css @@ -1 +1 @@ -@layer basalt{@media(pointer:coarse){.diagram-expand{min-height:var(--basalt-size-tap-min)}}@media(width>=720px){.dialog[data-form].diagram-viewer,.dialog[data-form][data-held].diagram-viewer{width:calc(100vw - 2 * var(--basalt-space-4));max-width:none;height:calc(100dvh - 2 * var(--basalt-space-4));max-height:none}}.diagram-viewer .sheet-head{flex:none}.diagram-viewer-source{overflow-wrap:break-word}.diagram-stage{--_pad: var(--basalt-space-4);--_travel: var(--basalt-space-1);--_clear: var(--basalt-space-4);--_rest: var(--basalt-duration-slower);position:relative;flex:1 1 auto;display:flex;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;touch-action:none;outline:none}@media(width>=720px){.diagram-stage{--_pad: var(--basalt-space-6)}}.diagram-stage:focus-visible{outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:calc(-1 * var(--basalt-size-focus-width))}.diagram-stage[data-pannable]{cursor:grab}.diagram-stage[data-pannable][data-dragging]{cursor:grabbing}.diagram-stage[data-list]{display:block;touch-action:pan-y}.diagram-probe{position:absolute;top:0;left:0;height:0;visibility:hidden;pointer-events:none}.diagram-probe[data-probe=row]{width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter))}.diagram-probe[data-probe=contain]{width:var(--basalt-size-breakpoint-container)}.diagram-sizer{position:relative;flex:none;box-sizing:content-box;margin:auto;padding:var(--_pad)}.diagram-sizer[hidden]{display:none}.diagram-layer{position:absolute;top:var(--_pad);inset-inline-start:var(--_pad);transform-origin:0 0;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}.diagram-layer:dir(rtl){transform-origin:100% 0}.diagram[data-viewer]{gap:0}.diagram[data-viewer]>:is(.diagram-head,.diagram-key,.diagram-hint,.diagram-foot,.diagram-list,.diagram-summary){display:none}.diagram-viewer-list{box-sizing:border-box;max-width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter) + 2 * var(--_pad));padding:var(--_pad)}.diagram-viewer-foot{display:flex;flex-direction:column;gap:var(--basalt-space-3);padding-block-start:var(--basalt-space-3)}.diagram-viewer-key{--_ground: var(--panel-bg, var(--basalt-surface-overlay))}.diagram-viewer-key .diagram-key{padding-block-start:0;border-top:0}.diagram-viewer-key[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram-viewer-key[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram-viewer-key[data-bare] .diagram-entry[data-line]{display:none}.diagram-viewer-row{display:flex;flex-wrap:wrap;align-items:center;gap:var(--basalt-space-2)}.diagram-zoom{display:flex;align-items:center;gap:var(--basalt-space-1)}.diagram-level{display:inline-grid;justify-items:center;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans);font-variant-numeric:tabular-nums}.diagram-level:before{content:attr(data-reserve);grid-area:1 / 1;visibility:hidden}.diagram-level>span{grid-area:1 / 1}.diagram-viewer-hint{flex:1 1 auto;min-width:0}.diagram-viewer-end{display:flex;gap:var(--basalt-space-2);margin-inline-start:auto}@media(pointer:coarse){.diagram-zoom .btn,.diagram-viewer-end .btn{min-height:var(--basalt-size-tap-min);min-width:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram-level{color:CanvasText}.diagram-viewer-foot [aria-disabled=true]{color:GrayText}}@media print{.diagram-expand,.diagram-viewer{display:none!important;transition:none!important}}} +@layer basalt{@media(pointer:coarse){.diagram-expand{min-height:var(--basalt-size-tap-min)}}@media(width>=720px){.dialog[data-form].diagram-viewer,.dialog[data-form][data-held].diagram-viewer{width:calc(100vw - 2 * var(--basalt-space-4));max-width:none;height:calc(100dvh - 2 * var(--basalt-space-4));max-height:none}}.diagram-viewer .sheet-head{flex:none}.diagram-viewer-source{overflow-wrap:break-word}.diagram-stage{--_pad: var(--basalt-space-4);--_travel: var(--basalt-space-1);--_clear: var(--basalt-space-4);--_rest: var(--basalt-duration-slower);position:relative;flex:1 1 auto;display:flex;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;touch-action:none;outline:none}@media(width>=720px){.diagram-stage{--_pad: var(--basalt-space-6)}}.diagram-stage:focus-visible{outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:calc(-1 * var(--basalt-size-focus-width))}.diagram-stage[data-pannable]{cursor:grab}.diagram-stage[data-pannable][data-dragging]{cursor:grabbing}.diagram-stage[data-list]{display:block;touch-action:pan-y}.diagram-probe{position:absolute;top:0;left:0;height:0;visibility:hidden;pointer-events:none}.diagram-probe[data-probe=row]{width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter))}.diagram-probe[data-probe=contain]{width:var(--basalt-size-breakpoint-container)}.diagram-sizer{position:relative;flex:none;box-sizing:content-box;margin:auto;padding:var(--_pad)}.diagram-sizer[hidden]{display:none}.diagram-layer{position:absolute;top:var(--_pad);inset-inline-start:var(--_pad);transform-origin:0 0;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}.diagram-layer:dir(rtl){transform-origin:100% 0}.diagram[data-viewer]{gap:0}.diagram[data-viewer]>:is(.diagram-head,.diagram-key,.diagram-hint,.diagram-tap-hint,.diagram-foot,.diagram-list,.diagram-summary){display:none}.diagram-viewer-list{box-sizing:border-box;max-width:calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter) + 2 * var(--_pad));padding:var(--_pad)}.diagram-viewer-foot{display:flex;flex-direction:column;gap:var(--basalt-space-3);padding-block-start:var(--basalt-space-3)}.diagram-viewer-key{--_ground: var(--panel-bg, var(--basalt-surface-overlay))}.diagram-viewer-key .diagram-key{padding-block-start:0;border-top:0}.diagram-viewer-key[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram-viewer-key[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram-viewer-key[data-bare] .diagram-entry[data-line]{display:none}.diagram-viewer-row{display:flex;flex-wrap:wrap;align-items:center;gap:var(--basalt-space-2)}.diagram-zoom{display:flex;align-items:center;gap:var(--basalt-space-1)}.diagram-level{display:inline-grid;justify-items:center;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans);font-variant-numeric:tabular-nums}.diagram-level:before{content:attr(data-reserve);grid-area:1 / 1;visibility:hidden}.diagram-level>span{grid-area:1 / 1}.diagram-viewer-hint{flex:1 1 auto;min-width:0}.diagram-viewer-end{display:flex;gap:var(--basalt-space-2);margin-inline-start:auto}@media(pointer:coarse){.diagram-zoom .btn,.diagram-viewer-end .btn{min-height:var(--basalt-size-tap-min);min-width:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram-level{color:CanvasText}.diagram-viewer-foot [aria-disabled=true]{color:GrayText}}@media print{.diagram-expand,.diagram-viewer{display:none!important;transition:none!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index 7906e7f4..fc597ece 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint{display:none}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 3169c517..f2162103 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,6 +1,6 @@ -(()=>{var ve=["top","right","bottom","left"],xe=["main","plain","dashed"],ke=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ut=t=>Object.assign(Object.create(null),t),gt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function qt(t,e={}){const s=e.checks!==!1,r=[],o=p=>{r.push(p)},a=t.legend??{},i={};for(const p of["main","plain","dashed","focal","group","activation"]){const w=at(a[p]);w&&(i[p]=w)}const d=t.stepLabel,u=typeof d=="function"?p=>String(d(p)):typeof d=="string"?(p=>d.replace("{n}",String(p))):p=>`Step ${p}`,m=t.shapeLabels??{},h={terminal:at(m.terminal)??"Start or end",step:at(m.step)??"Step",decision:at(m.decision)??"Decision"},l=t.heading===void 0?3:ke.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),y=(p,w)=>p==null?"plain":xe.includes(p)?p:(o(`"${String(p)}" is not a kind of line (main, plain or dashed): ${w} is drawn plain`),"plain"),$=p=>{if(p!=null){if(ve.includes(p))return p;o(`"${String(p)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(p,w)=>typeof p=="number"&&Number.isInteger(p)&&p>=1?p:(o(`${w} is ${JSON.stringify(p)}, not a whole number from 1: it is placed at 1`),1),f=[],v=[];let B=[];const C=[],M=[],I=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(I)||o(`"${String(I)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),I==="architecture"||I==="flowchart"){for(const p of t.nodes??[]){const w=I==="flowchart"&&p.shape==="decision"?"decision":I==="flowchart"&&p.shape==="terminal"?"terminal":"box",S=String(p.id??""),g=c(p.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(p.name??""),kind:w==="decision"?void 0:at(p.kind),detail:w==="decision"?void 0:at(p.detail),mono:!!p.detailMono,focal:!!p.focal,col:c(p.col,`the column of ${S}`),row:g,row2:g,branch:!!p.branch,shape:w,group:I==="architecture"?at(p.group):void 0,mark:I==="architecture"?It(p.mark):void 0})}if(I==="architecture"){const p=(t.groups??[]).map(b=>({id:String(b.id??""),label:String(b.label??""),parent:at(b.parent)})),w=new Map(p.map(b=>[b.id,b])),S=b=>{if(!b.parent)return 1;const x=w.get(b.parent);return x?x.parent===b.id||x.id===b.id?(o(`the groups "${b.label}" and "${x.label}" are each other's parent`),b.parent=void 0,1):x.parent?(o(`the group "${b.label}" is a third level: groups nest two deep`),b.parent=void 0,1):2:(o(`the group "${b.label}" names the parent "${b.parent}", which is not a group`),b.parent=void 0,1)},g=p.map(S);p.forEach((b,x)=>C.push({...b,depth:g[x],members:f.filter(E=>E.group===b.id).map(E=>E.id),all:[]}));for(const b of C)b.all=[...b.members,...C.filter(x=>x.parent===b.id).flatMap(x=>x.members)];C.sort((b,x)=>b.depth-x.depth)}}else if(I==="data-flow"){B=(t.lanes??[]).map(w=>({id:String(w.id??""),label:String(w.label??"")}));const p=new Map(B.map((w,S)=>[w.id,S+1]));for(const w of t.nodes??[]){const S=String(w.id??""),g=String(w.lane??""),b=p.get(g);b===void 0&&o(`a node (${S}) names the lane "${g}", which is not in lanes`);const x=f.length+1;f.push({id:S,i:f.length,name:String(w.name??""),kind:u(x),detail:at(w.detail),mono:!!w.detailMono,focal:!!w.focal,col:c(w.col,`the column of ${S}`),row:b??1,row2:b??1,branch:!1,shape:"box",lane:b??1,laneLabel:B[(b??1)-1]?.label??g,step:x,mark:It(w.mark)})}}else if(I==="sequence"){(t.participants??[]).forEach((g,b)=>{const x=String(g.name??"");f.push({id:String(g.id??""),i:b,name:x,kind:at(g.kind),mono:!1,focal:!!g.focal,col:b+1,row:1,row2:1,branch:!1,shape:"participant",short:at(g.short)??x,mark:It(g.mark)})});let p=0;const w=new Map(f.map(g=>[g.id,g.col])),S=(g,b)=>{let x=1/0,E=-1/0;for(const A of g??[]){if(!A||typeof A!="object")continue;if("band"in A){b>0&&o(`the band "${String(A.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(A.band??"")});continue}if("frame"in A){if(b>=2){o("a frame is a third level: frames nest two deep");continue}const nt=A.frame==="alt"||A.frame==="loop"||A.frame==="opt"?A.frame:"opt",et=nt==="alt"?A.branches??[]:[{label:A.label,steps:A.steps}];nt==="alt"&&et.length<2&&o("an alt frame has one branch: it needs two or more");const X=String(et[0]?.label??"");X.length>40&&o(`the frame label "${X}" is over 40 characters`);const ot=M.length;M.push({open:nt,label:X,depth:b+1,a:0,b:0}),et.forEach((Y,st)=>{if(st){const it=String(Y.label??"");it.length>40&&o(`the frame label "${it}" is over 40 characters`),M.push({otherwise:it,depth:b+1})}Y.steps?.length||o(`a frame or branch ("${String(Y.label??"")}") is empty`);const[rt,R]=S(Y.steps??[],b+1);x=Math.min(x,rt),E=Math.max(E,R);const P=M[ot];P.a=Math.min(P.a||1/0,rt),P.b=Math.max(P.b,R)}),M.push({close:b+1});continue}p++;const T=String(A.label??"");T.includes(` -`)&&o(`message ${p}'s label has a break: a message's second line is its note`);const K=String(A.from??""),Q=String(A.to??"");M.push({n:p,from:K,to:Q,label:pt(T),note:at(A.note),kind:y(A.kind,`message ${p}`),activate:A.activate===!0||void 0,deactivate:A.deactivate===!0||void 0});const J=w.get(K)??1,z=w.get(Q)??1,G=J===z?J===f.length?J-1:J+1:J;x=Math.min(x,J,z,G),E=Math.max(E,J,z,G)}return[x,E]};S(t.steps??[],0);for(const g of M)"open"in g&&!Number.isFinite(g.a)&&(g.a=1,g.b=Math.max(1,f.length))}else if(I==="schema")for(const p of t.tables??[]){const w=String(p.name??""),[S,g]=Array.isArray(p.row)?p.row:[p.row,p.row],b=c(S,`the row of ${w}`),x=Math.max(b,c(g,`the last row of ${w}`)),E=p.more===void 0||p.more===null?void 0:Number.isInteger(p.more)&&p.more>0?p.more:(o(`${w}'s "more" is ${JSON.stringify(p.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:w,i:f.length,name:w,mono:!0,focal:!!p.focal,col:c(p.col,`the column of ${w}`),row:b,row2:x,branch:!1,shape:"table",more:E,columns:(p.columns??[]).map(A=>({name:String(A.name??""),type:at(A.type),key:A.key==="PK"||A.key==="FK"?A.key:(A.key!==void 0&&A.key!==null&&o(`${w}.${String(A.name)}'s key is "${String(A.key)}", not PK or FK: it is left out`),void 0)}))})}((I==="schema"?t.tables:I==="sequence"?t.participants:t.nodes)??[]).forEach((p,w)=>{if(!p||p.href===void 0||p.href===null)return;const S=String(p.href);if(I==="sequence"){o(`${f[w]?.id}: a participant cannot be a link (href)`);return}if(!S){o(`${f[w]?.id}'s href is empty`);return}const g=f[w];g&&(g.href=S,g.blank=p.target==="_blank")});const D=new Map;for(const p of f)p.id?D.has(p.id)&&o(`the id "${p.id}" is used twice`):o("a node has no id"),D.set(p.id,p);if(I==="schema")(t.tables??[]).forEach(p=>(p.columns??[]).forEach((w,S)=>{const g=at(w.references);if(!g)return;const[b,x]=g.split("."),E=D.get(b??""),A=E?.columns?.findIndex(K=>K.name===x)??-1;if(!E||A<0){o(`${String(p.name)}.${String(w.name)} references ${g}, which is not a shown column`);return}const T=D.get(String(p.name??""));T.columns[S].ref={table:b,column:x,row:A},v.push({i:v.length,from:T.id,to:b,kind:"plain",fromRow:S,toRow:A,fk:!0})}));else if(I!=="sequence")for(const p of t.edges??[]){const w=String(p.from??""),S=String(p.to??"");if(!D.has(w)||!D.has(S)){o(`a line names ${D.has(w)?S:w}, which is not a node`);continue}const g=at(p.label),b=g?.split(` -`)??[];b.length>2&&o(`the label "${pt(g)}" has more than one break: a label is two lines at most`),b.some(x=>x.length>zt)&&o(`a line of the label "${pt(g)}" is over ${zt} characters: longer words belong in the node or the summary`),v.push({i:v.length,from:w,to:S,kind:y(p.kind,`the line from ${w} to ${S}`),label:g,fromSide:$(p.fromSide),toSide:$(p.toSide),flow:I!=="flowchart"&&p.flow===!0?!0:void 0})}else for(const p of M)"n"in p&&(!D.has(p.from)||!D.has(p.to))&&o(`message ${p.n} names ${D.has(p.from)?p.to:p.from}, which is not a participant`);if(s&&I!=="sequence"){const p=new Map;for(const w of f)for(let S=w.row;S<=w.row2;S++){const g=`${w.col}:${S}`;p.has(g)&&o(`${w.id} and ${p.get(g)} share the cell at column ${w.col}, row ${S}`),p.set(g,w.id)}}if(s){for(const w of C){const S=w.all.map(x=>D.get(x));if(!S.length)continue;const g={c1:Math.min(...S.map(x=>x.col)),c2:Math.max(...S.map(x=>x.col)),r1:Math.min(...S.map(x=>x.row)),r2:Math.max(...S.map(x=>x.row2))};for(const x of f)!w.all.includes(x.id)&&x.col>=g.c1&&x.col<=g.c2&&x.row>=g.r1&&x.row<=g.r2&&o(`${x.id} is inside the box of the group "${w.label}" but not a member`);const b=S.map(x=>x.i);Math.max(...b)-Math.min(...b)+1!==b.length&&o(`the members of the group "${w.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const w of f)w.group&&!C.some(S=>S.id===w.group)&&o(`${w.id} names the group "${w.group}", which is not in groups`);f.filter(w=>w.focal).length>1&&o("more than one node is focal: a diagram has one at most");const p=new Set(I==="sequence"?M.flatMap(w=>"n"in w?[w.kind]:[]):v.map(w=>w.kind));p.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),p.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(w=>w.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const O=I==="architecture"||I==="data-flow",V=p=>Array.isArray(p)&&p.length>1?p.map(String):void 0,q=O&&t.packet&&typeof t.packet=="object"?t.packet:void 0,W=q&&V(q.path),_={animated:t.motion==="animated",pulse:O?V(t.pulse):void 0,packet:W?{path:W,repeat:q.repeat===!0,send:q.send}:void 0,run:I==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const p of f){const w=p.mark?.says;if(!w?.length)continue;const S=[p.name,p.kind,p.detail,p.laneLabel].filter(Boolean).join(" ").toLowerCase();w.some(g=>S.includes(g.toLowerCase()))||o(`${p.id}'s mark stands for ${w.join(" or ")}, and none of its words say so`)}const L=[];if(I==="sequence"){const p=new Map,w=new Map;for(const S of M)"n"in S&&(w.set(S.from,S.n),w.set(S.to,S.n));for(const S of M)if("n"in S){if(S.activate){const g=p.get(S.to)??[];if(g.length>=3)o(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const b={who:S.to,from:S.n,to:S.n,depth:g.length+1};g.push(b),L.push(b),p.set(S.to,g)}}if(S.deactivate){const b=p.get(S.from)?.pop();b?b.to=S.n:o(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,g]of p)for(const b of g)b.to=Math.max(b.from,w.get(S)??b.from)}const j=t.frameLabels??{},F={opt:at(j.opt)??"Only if",loop:at(j.loop)??"Repeats",alt:at(j.alt)??"One of these",else:at(j.else)??"Otherwise"},Z=Math.max(1,...f.map(p=>p.col)),N=I==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(p=>p.row2)),U={type:I,title:String(t.title??""),heading:l,legend:i,nodes:f,byId:D,edges:v,groups:C,lanes:B,steps:M,bars:L,frameWords:F,cols:Z,rows:N,shapeLabels:h,stepWord:u,warnings:r,motion:_,memo:new Map};return s&&f.length>1&&!St(U)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),U}function It(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Wt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function yt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var zt=28,Ot=t=>t.includes(` -`)?2:1,pt=t=>t.replace(/\n/g," "),bt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Ft(t,e){return t.legend[e]}function Me(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Se(t,e){return yt(t,`sentence:${e.i}`,()=>Ee(t,e))}function Ee(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(bt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Nt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Me(t,e):e.kind;if(n.push(bt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(bt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${pt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${pt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(bt(t.legend.focal)),n.join(" ")}function Nt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function Ae(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var Le={"&":"&","<":"<",">":">",'"':""","'":"'"},lt=t=>t.replace(/[&<>"']/g,e=>Le[e]),qe=" br img input meta link hr path polygon polyline circle rect line ";function _t(t,e={}){if(typeof t=="string")return lt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${lt(String(r))}"`}return qe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>_t(s,e)).join("")}`}var Ie=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Oe(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function kt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Ht(t){return yt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=kt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Dt(t,n,a)))})}return e})}function Dt(t,e,n){const s=kt(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=kt(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Gt(t){const e=Ht(t);return e[1]+e[3]}function Ct(t){return t.type==="sequence"?t.nodes.length:t.cols}function Kt(t){return yt(t,"plan",()=>_e(t))}function _e(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},m=t.edges.map(()=>0);let h=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,m[v.k]+1));m[c.k]=f,f>1&&(h=!0),l.push(c)}const y=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{y[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const $=ut();for(let c=1;c{const O=s[D],V=t.byId.get(H.from).i,q=t.byId.get(H.to).i,W=q===c&&(O==="down"||O==="trunk"||O==="rail"||O==="end-down"),_=V===c&&q===c-1&&O==="up",L=q===c-1&&O==="end-up";W&&(O==="trunk"||O==="end-down")&&(M=!0),L&&(I=!0),(W||_||L)&&H.label&&(B++,C=Math.max(C,O==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),$[f.id]=C}return{routes:s,gutter:d,lanes:m,exits:y,gaps:$,third:h}}var $t=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Vt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...$t(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function wt(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...$t(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Zt(t,e){return yt(e,`key:${t}`,()=>je(t,e))}var Ce=Zt;function je(t,e){const n=[],s=(o,a,i={})=>n.push(k("li",{class:`${t}-entry`,...i},o,k("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),k("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(wt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(wt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(wt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Vt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Vt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...$t(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),k("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(wt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(wt(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Be(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...$t(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function jt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Te(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},jt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},jt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?At(n.detail).flatMap((r,o)=>[o?" ":"",k("span",{class:`${t}-run`},r)]):n.detail)),s}function Re(t,e){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},jt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>k("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},k("span",{class:`${t}-keyseat`},n.key??""),k("span",{class:`${t}-cname`},n.name),n.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?k("span",{class:`${t}-ctype`},n.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ut=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Mt(t,e,n,s){const{P:r}=t,o=Oe(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=gt(d.gaps,n.id)??32,y=gt(s.grow,n.id)??0;i.push(`--_gap:${y?`calc(${Ut(l)} + var(--basalt-space-4) * ${y})`:Ut(l)}`)}const u=gt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const m=gt(s.words,n.id);m&&i.push(`--_ww:${m}px`);const h=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?Se(e,n):void 0,tabindex:h},n.shape==="decision"?k("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Wt(n.mark.onLight)};--_md:${Wt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Re(r,n):Te(r,e,n))}function We(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=kt(e,d);if(!u)continue;const m=[0,1,2,3].map(h=>Dt(e,d,h));r.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`},Mt(t,e,d,n))))),r.push(ze(t,e)),r;const o=d=>{const u=d.group?e.groups.find(m=>m.id===d.group):void 0;return u?.parent?e.groups.find(m=>m.id===u.parent):u},a=(d,u,m)=>{const h=t.plan?gt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:h?`--_ggrow:${h}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),m)};let i=0;for(;ic.id===m[l].group):void 0;if(!y){h.push(Mt(t,e,m[l],n)),l++;continue}const $=[];for(;lMt(t,e,c,n))))}r.push(a(u,m,h))}return r}function ze(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(k("p",{class:`${n}-band`},k("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=k("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=k("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),m=d?.col??1,h=u?.col??1,l=m===h,y=l&&m===e.nodes.length,$=Ft(e,i.kind);a.c.push(k("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?y?"start":"end":void 0,style:`--_a:${Math.min(m,h)};--_b:${Math.max(m,h)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(i.n)),k("span",{class:`${n}-mlabel`},i.label)),k("span",{class:`${n}-route`},d?.short??i.from," ",Be(n,i.kind),k("span",{class:t.hidden}," to ")," ",u?.short??i.to,$?` · ${$}`:""),i.note?k("span",{class:`${n}-note`},i.note):null))}return k("div",{class:`${n}-steps`},s)}function Jt(t,e){return yt(e,`list:${t}`,()=>Ne(t,e))}var Fe=Jt;function Ne(t,e){const n=Math.min(6,e.heading+1),s=h=>k(`h${n}`,{class:`${t}-list-head`},h),r=h=>k("strong",null,h),o=h=>h.href?k("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},r(h.name)):r(h.name),a=h=>k("code",{class:`${t}-code`},h),i=h=>e.byId.get(h)?.name??h,d=h=>{const l=Ft(e,h);return l?` (${l})`:""},u=h=>h.focal&&e.legend.focal?` ${bt(e.legend.focal)}`:"";if(e.type==="architecture"){const h=$=>k("li",null,o($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?a($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",u($)),l=[s("Parts")],y=e.nodes.filter($=>!$.group);y.length&&l.push(k("ul",{class:`${t}-list-items`},y.map(h)));for(const $ of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},$.label)),$.members.length&&l.push(k("ul",{class:`${t}-list-items`},$.members.map(c=>h(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===$.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>h(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map($=>k("li",null,r(i($.from))," to ",r(i($.to)),$.label?[": ",a(pt($.label))]:"",`${d($.kind)}.`)))),l}if(e.type==="flowchart"){const h=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const y=e.edges.filter(f=>f.from===l.id),$=l.shape==="decision"?"Decision":l.shape==="terminal"?y.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${$}.`,u(l),y.length?k("ul",{class:`${t}-list-exits`},y.map(f=>k("li",null,f.label?`If ${pt(f.label)}: go to ${h(f.to)}, `:`Then: go to ${h(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(h=>{const l=e.edges.filter(y=>y.from===h.id);return k("li",null,`${h.laneLabel}: `,o(h),h.detail?[", ",h.mono?a(h.detail):h.detail]:"",".",u(h),l.length?[" Then ",...l.flatMap((y,$)=>[$?"; ":"",`to step ${e.byId.get(y.to).step}, `,r(i(y.to)),y.label?[": ",a(pt(y.label))]:"",d(y.kind)]),"."]:"")}))];if(e.type==="sequence"){const h=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(y=>k("li",null,r(y.name),y.kind?`, ${y.kind}`:"",".",u(y),Nt(e,y))))];h.push(s("Messages"));let l=null;for(const y of e.steps){if("band"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},y.band));continue}if("open"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":y.depth>1?y.depth:void 0},`${e.frameWords[y.open]}: ${y.label}`));continue}if("otherwise"in y){l=null,h.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":y.depth>1?y.depth:void 0},`${e.frameWords.else}: ${y.otherwise}`));continue}if("close"in y){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:y.n}),h.push(l)),l.c.push(k("li",null,a(y.label),": ",r(i(y.from))," to ",r(i(y.to)),`${d(y.kind)}.`,y.note?` ${bt(y.note)}`:""))}return h}const m=[];for(const h of e.nodes)m.push(k(`h${n}`,{class:`${t}-list-group`},h.href?k("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},a(h.name)):a(h.name),u(h))),m.push(k("ul",{class:`${t}-list-items`},[...(h.columns??[]).map(l=>k("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...h.more?[k("li",null,`and ${h.more} more ${h.more===1?"column":"columns"}`)]:[]]));return m}function Xt(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&St(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Bt(t,e=!1){const n=e&&t.type!=="sequence"&&St(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Ae(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var He=(t,e)=>{for(let n=0;n({col:t.type==="sequence"?e.i+1:e.col,rows:[e.row,e.row2]});function St(t){return yt(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...De(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=$=>i?[$.col,$.col]:$.rows,m=$=>i?$.rows:[$.col,$.col],h=u(o),l=m(o);let y=null;return e.forEach(($,c)=>{if($===o)return;const f=u($),v=m($),B=d?f[0]-h[1]:h[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!y||He(M,y.rank))&&(y={id:$.id,rank:M})}),y?.id??null},s=ut();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var Yt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Qt(t,e,n){const s=n.prefix,r=Ie(n.base),o=t.type==="sequence"||t.type==="schema"?null:Kt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,m=`h${t.heading}`,h=[`--_cols:${Ct(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Ht(t):[0,0,0,0],y=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",$=i&&e.pad?"3":void 0;h.push(`--_gpad:${y(l[0],"8",$)} ${y(l[1],"4")} ${y(l[2],"4",$)} ${y(l[3],"4")}`)}return Yt(t)&&h.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&h.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Ct(t),"data-reach":t.type==="architecture"?Gt(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-viewer":n.viewer?"":void 0,style:h.join(";")},k("div",{class:`${s}-head`},k(m,{id:r.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},We(a,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Zt(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Jt(s,t)),k("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${Xt(t,i)} ${n.viewer}`:Xt(t,i)),k("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Ge(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Et=(t,e)=>t==="main"?e.line:e.hair,dt=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ft=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Pt=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function ct(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2,h=e==="top"||e==="bottom";if(t.shape==="decision"){if(h){const $=n,c=m*Math.max(0,1-Math.abs($-i)/u);return{x:$,y:e==="top"?d-c:d+c}}const l=n,y=u*Math.max(0,1-Math.abs(l-d)/m);return{x:e==="left"?i-y:i+y,y:l}}if(t.shape==="terminal"){const l=Math.min(u,m);if(h){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const y=n,$=y-d,c=Math.abs($)>=l?0:Math.sqrt(l*l-$*$);return{x:e==="left"?s+l-c:o-l+c,y}}return h?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Ke(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/m<1-n/Math.min(u,m);if(e.shape==="terminal"){const h=Math.min(u,m),l=Math.min(Math.max(t.x,s+h),o-h);return Math.hypot(t.x-l,t.y-d)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function Ue(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var At=t=>t?t.split(/\s+/).filter(Boolean):[];function Je(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`→ ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),m=d.mark&&!Ze()?(d.shape==="participant"?2:1)*s("6"):0;let h=0;const l=d.href?16+s("1-5"):0,y=At(d.name);if(y.forEach((c,f)=>{h=Math.max(h,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:m)+(f===y.length-1?l:0))}),t.type!=="data-flow")for(const c of At(d.kind))h=Math.max(h,n(c,"mono")+m);for(const c of At(d.detail))h=Math.max(h,n(c,d.mono?"mono":"sans"));const $=d.shape==="decision"?h/.62:h+u+2*e.hair;r=Math.max(r,Math.ceil($))}const a=Ct(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(Yt(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Gt(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ee(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Tt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ne(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var ht=t=>t.slice(1).map((e,n)=>[t[n],e]);function Lt(t,e,n){const s=[];for(let o=0;oMath.min(c.x,f.x)+.75&&CMath.min(v.y,B.y)+.75&&Mr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",oe={top:"bottom",bottom:"top",left:"right",right:"left"};function Ye(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Qe(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,m]=e[a],h=i.row===d.row&&tt(u)&&tt(m)&&u===oe[m]||i.col===d.col&&!tt(u)&&!tt(m)&&u===oe[m];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:h,f:.5},{edge:a,end:"to",node:d,side:m,far:i,straight:h,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const m=new Map;for(const c of d)m.has(c.far.id)||m.set(c.far.id,[]),m.get(c.far.id).push(c);for(const c of m.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const h=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),y=u.filter(c=>i(c)<0),$=u.filter(c=>i(c)>=0);y.forEach((c,f)=>{c.f=h*(f+1)/(y.length+1)}),$.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/($.length+1)})}return s}function se(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?ct(t,e,r+(a-r)*n):ct(t,e,s+(o-s)*n)}function ae(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:dt(o,n),shape:a.shape,i:a.i})}),r}function re(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var ie=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function le(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function Pe(t,e,n,s,r,o,a,i,d){const u=a.space,m=[],h=[],l=[],y=[],$=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*Ot(v),M=f.pts.length-2,I=[];ht(f.pts).forEach(([q,W],_)=>{const L=Math.abs(q.y-W.y)<.01,j=L?q.x:q.y;let F=L?W.x:W.y;const Z=Math.sign(F-j)||1;_===M&&(F-=Z*a.head);let N=[[j,F]];for(const w of r)for(const S of L?[w.l,w.r]:[w.t,w.b]){const g=L?q.y:q.x;(L?g>w.t&&gw.l&&gS>Math.min(x,E)+1&&S{const g=(w+S)/2,b=L?{x:g,y:q.y}:{x:q.x,y:g};return!r.some(x=>b.x>x.l&&b.xx.t&&b.y1&&U(w,S)?1:0})}),I.sort((q,W)=>W.pri-q.pri||W.len-q.len);let H=null,D=!1;const O=(q,W=!0)=>{const _=Pt(q,$);return W&&(q.lo.r||q.to.b)||n.some(L=>te(_,L))||m.some(L=>ft(_,L))||s.heads.some(L=>ft(_,L))||s.rects.some(L=>ft(_,L))?!1:!e.some(L=>L.i!==f.i&&ht(L.pts).some(([j,F])=>ft(_,ie(j,F,L.width))))};for(const q of I){for(const W of[1/2,1/3,2/3]){const _=q.p+(q.q-q.p)*W,L=[],j=u("2")+f.width/2;if(q.horiz?(q.len>=B+2*u("1")+u("3-5")&&L.push({box:{l:_-B/2-u("1"),r:_+B/2+u("1"),t:q.c-C/2,b:q.c+C/2},on:!0}),L.push({box:{l:_-B/2,r:_+B/2,t:q.c-j-C,b:q.c-j},on:!1}),L.push({box:{l:_-B/2,r:_+B/2,t:q.c+j,b:q.c+j+C},on:!1})):(q.len>=C+u("3")&&L.push({box:{l:q.c-B/2-u("1"),r:q.c+B/2+u("1"),t:_-C/2,b:_+C/2},on:!0}),L.push({box:{l:q.c+j,r:q.c+j+B,t:_-C/2,b:_+C/2},on:!1}),L.push({box:{l:q.c-j-B,r:q.c-j,t:_-C/2,b:_+C/2},on:!1})),H=L.find(F=>O(F.box))??null,H)break;!D&&L.some(F=>O(F.box,!1))&&(D=!0)}if(H)break}if(!H){l.push(f.i),D&&y.push(f.i);continue}const V=le(H.box,d.ox,d.oy,q=>O(q));m.push(V),h.push({i:f.i,text:v,box:V,on:H.on})}return{labels:h,unseated:l,bounded:y}}function ce(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=dt(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(dt(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=dt(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(dt(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function tn(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,m=ae(s,a,i,o),h=[...m.values()],l=Xe(a),y=i.left-Math.floor(i.left),$=i.top-Math.floor(i.top),c=ee(y,$),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:y,oy:$};if(s.type==="sequence")return nn(t,M,c);let I,H=[];s.type==="schema"?I=s.edges.map(g=>{const b=s.byId.get(g.from),x=s.byId.get(g.to);if(b.col===x.col){const E=b.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return x.col>b.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const b=s.byId.get(g.from),x=s.byId.get(g.to),[E,A]=Ye(b,x);return[g.fromSide??E,g.toSide??A]}),H=Qe(s,I,d||(()=>{})));const D=(g,b)=>{const x=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${b}"]`);if(!x)return 0;const E=dt(x,i);return(E.t+E.b)/2},O=s.edges.map((g,b)=>{const[x,E]=I[b],A=m.get(g.from),T=m.get(g.to),K=Et(g.kind,r);if(g.fk){const X=D(g.from,g.fromRow),ot=D(g.to,g.toRow),Y=c.y(X,K),st=c.y(ot,K);return{p1:{x:x==="right"?A.rect.r:A.rect.l,y:Y},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:X,r2:Math.abs(Y-st)<.01?X:ot}}const Q=H.find(X=>X.edge===b&&X.end==="from").f,J=H.find(X=>X.edge===b&&X.end==="to").f;let z=se(A,x,Q),G=se(T,E,J);const nt=tt(x)?z.y:z.x;let et=tt(E)?G.y:G.x;return tt(x)?z={...z,y:c.y(z.y,K)}:z={...z,x:c.x(z.x,K)},tt(E)?G={...G,y:c.y(G.y,K)}:G={...G,x:c.x(G.x,K)},tt(x)&&tt(E)&&Math.abs(z.y-G.y)<1.01&&(G={...G,y:z.y},et=nt),!tt(x)&&!tt(E)&&Math.abs(z.x-G.x)<1.01&&(G={...G,x:z.x},et=nt),z=tt(x)?ct(A,x,z.y):ct(A,x,z.x),G=tt(E)?ct(T,E,G.y):ct(T,E,G.x),{p1:z,p2:G,r1:nt,r2:et}}),V=new Set;s.type==="schema"&&s.edges.forEach((g,b)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&V.add(b)});const q=new Map,W=new Set;s.edges.forEach((g,b)=>{if(V.has(b))return;const[x,E]=I[b],{p1:A,p2:T}=O[b],K=s.byId.get(g.from),Q=s.byId.get(g.to);let J=null,z=null,G=!1;if(x===E){if(tt(x)){const X=x==="right"?Math.max(B(K),B(Q)):Math.min(B(K),B(Q))-1,ot=l.cols[X-1],Y=l.cols[X];ot&&Y&&(J=`c${X}`,z=[ot[1],Y[0]],G=!0)}else{const X=x==="bottom"?Math.max(K.row2,Q.row2):Math.min(K.row,Q.row)-1,ot=l.rows[X-1],Y=l.rows[X];ot&&Y&&(J=`r${X}`,z=[ot[1],Y[0]],G=!1)}J&&W.add(b)}else if(tt(x)&&tt(E)&&Math.abs(A.y-T.y)>.5){const X=B(Q),ot=E==="left",Y=l.cols[(ot?X-1:X)-1],st=l.cols[(ot?X:X+1)-1];Y&&st&&(J=`c${ot?X-1:X}`,z=[Y[1],st[0]],G=!0)}else if(!tt(x)&&!tt(E)&&Math.abs(A.x-T.x)>.5){const ot=E==="top"?Q.row-1:Q.row2,Y=l.rows[ot-1],st=l.rows[ot];Y&&st&&(J=`r${ot}`,z=[Y[1],st[0]],G=!1)}if(!J||!z)return;q.has(J)||q.set(J,{span:z,vertical:G,members:new Map});const nt=`${g.to}.${E}.${Math.round(G?T.y:T.x)}`,et=q.get(J);et.members.has(nt)||et.members.set(nt,[]),et.members.get(nt).push(b)});const _=new Map,L=g=>{const[b,x]=I[g],{p1:E,p2:A}=O[g];if(tt(b)&&tt(x)){if(b===x){const K=_.get(g)??(b==="right"?Math.max(E.x,A.x)+u("4"):Math.min(E.x,A.x)-u("4"));return[E,{x:K,y:E.y},{x:K,y:A.y},A]}if(Math.abs(E.y-A.y)<=.5)return[E,{x:A.x,y:E.y}];const T=_.get(g)??(E.x+A.x)/2;return[E,{x:T,y:E.y},{x:T,y:A.y},A]}if(!tt(b)&&!tt(x)){if(b===x){const K=_.get(g)??(b==="bottom"?Math.max(E.y,A.y)+u("4"):Math.min(E.y,A.y)-u("4"));return[E,{x:E.x,y:K},{x:A.x,y:K},A]}if(Math.abs(E.x-A.x)<=.5)return[E,{x:E.x,y:A.y}];const T=_.get(g)??(E.y+A.y)/2;return[E,{x:E.x,y:T},{x:A.x,y:T},A]}return tt(b)?[E,{x:A.x,y:E.y},A]:[E,{x:E.x,y:A.y},A]},j=g=>{const b=s.edges[g],x=Et(b.kind,r),E=L(g),A=ne(E,x,c);let T;return E.length===A.length&&(T=ht(E).map(([K,Q])=>Math.abs(K.y-Q.y)<.75?(K.y+Q.y)/2:(K.x+Q.x)/2),T[0]=O[g].r1,T.length>1&&(T[T.length-1]=O[g].r2)),{i:g,from:b.from,to:b.to,kind:b.kind,pts:A,tip:A[A.length-1],dir:Tt(A),dot:b.fk?A[0]:void 0,width:x,axes:T}},F=()=>s.edges.flatMap((g,b)=>V.has(b)?[]:[j(b)]);let Z=null;const N=g=>{Z??(Z=F());const b=Z.map(x=>g.has(x.i)?j(x.i):x);return{lines:b,score:en(b,g)*1e5+Lt(b,void 0,g).length*1e3+Rt(b.filter(x=>g.has(x.i)),h,s).length}},U=(g,b)=>{const x=g.flatMap(E=>{const{p1:A,p2:T}=O[E];return b?[A.y,T.y]:[A.x,T.x]});return[Math.min(...x),Math.max(...x)]};for(const[,g]of q){const b=[...g.members.values()].map(E=>({members:E,run:U(E,g.vertical)})).sort((E,A)=>E.run[0]-A.run[0]),x=[];for(const E of b){const A=x[x.length-1];A&&A.some(T=>T.run[0]W.has(nt)))continue;const A=E.map(nt=>nt.members),T=A.length,K=(g.span[1]-g.span[0])/(T+1);KX.forEach(Y=>_.set(Y,g.span[0]+K*(ot+1))));const et=N(Q);et.scorent.forEach(X=>_.set(X,g.span[0]+K*(et+1)))),Z=G}}M.lines=F();for(const g of V)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=Lt(M.lines),M.through=Rt(M.lines,h,s),M.outside=ue(M.lines,f,v,r);const{obstacles:p,groups:w}=ce(a,i,o,C);p.heads=M.lines.map(g=>re(g,r));const S=Pe(s,M.lines,h,p,w,{l:0,t:0,r:f,b:v},r,e,{ox:y,oy:$});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(de(M.lines,null).flat())],M}function en(t,e){return de(t,e).length}function de(t,e){const n=[];for(let s=0;s=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[m.x,h.x]:[m.y,h.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*fe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Rt(t,e,n){const s=[];for(const r of t){const o=ht(r.pts);e.some(a=>o.some(([i,d])=>Ve(i,d,a)))&&s.push(r.i)}return s}function nn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,dt(M,i)));const m=a.querySelector(`.${o}-steps`),h=m?dt(m,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:h})}const y=M=>u.get(M.id),$=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=dt(M,i);$.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const H=l(M.who),D=I.i===s.nodes.length-1&&s.nodes.length>1?-1:1,O=(M.depth-1)*d("1")*D,V=$.get(M.from)??0,q=$.get(M.to)??V,W=M.from===M.to;return{l:n.x(H-f+O,r.hair),r:n.x(H+f+O,r.hair),t:n.y(W?V-d("2")-d("1"):V,r.hair),b:n.y(W?V+d("2")+d("1"):q,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,H)=>B.filter(({bar:D})=>D.who===M&&D.to>=I&&(H?D.from<=I:D.fromO.bar.depth-D.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,H=M.dataset.to,D=M.dataset.kind??"plain",O=Et(D,r),V=dt(M,i),q=n.y((V.t+V.b)/2,O),W=Number(M.querySelector(`.${o}-num`)?.textContent??0);let _=l(I),L=l(H),j;if(I===H){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,W,!0),b=g?S>0?g.r:g.l:_,x=n.y(q-d("2"),O),E=n.y(q+d("2"),O);j=[{x:b,y:x},{x:n.x(_+S,O),y:x},{x:n.x(_+S,O),y:E},{x:b,y:E}]}else{const S=L>_?1:-1,g=C(I,W,!1),b=C(H,W,!0);g&&(_=S>0?g.r:g.l),b&&(L=S>0?b.l:b.r),j=[{x:_,y:q},{x:L,y:q}]}e.lines.push({i:W,from:I,to:H,kind:D,pts:j,tip:j[j.length-1],dir:Tt(j),width:O});const F=M.querySelector(`.${o}-said`),Z=M.querySelector(`.${o}-note`),N=s.byId.get(I),U=s.byId.get(H);if(!N||!U)return;const p=I===H?(()=>{const S=s.nodes[N.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-_)-d("6")-d("2-5")-d("2")})():Math.abs(L-_)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>p+.5&&e.unseated.push(W)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((D,O)=>D+O.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function he(t,e,n,s=ut()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,m=ae(r,i,d,a),h=[...m.values()],l=d.left-Math.floor(d.left),y=d.top-Math.floor(d.top),$=ee(l,y),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:y},B=ut();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(L,j,F)=>{const Z=[L];for(let N=1;N<=(gt(s,j)??0);N++)Z.push({...L,t:L.t+F*u("4")*N,b:L.b+F*u("4")*N});return Z},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(L=>{const j=L.parentElement,F=dt(j,d),Z=getComputedStyle(j);I.set(L.dataset.node,F.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const H=r.nodes,D=L=>m.get(H[L].id),O=[],V=L=>Et(r.edges[L].kind,o);r.edges.forEach((L,j)=>{const F=n.routes[j],Z=m.get(L.from),N=m.get(L.to),U=V(j);let p=[];const w=L.label,S=w?e(w,"label"):0,g=w?16*Ot(w):16,b=u("4");if(F==="down"||F==="up"){const E=Math.max(Z.rect.l,N.rect.l),A=Math.min(Z.rect.r,N.rect.r),T=r.edges.map((z,G)=>({o:z,j:G})).filter(({o:z,j:G})=>(n.routes[G]==="down"||n.routes[G]==="up")&&(z.from===L.from&&z.to===L.to||z.from===L.to&&z.to===L.from)),K=T.findIndex(z=>z.j===j),Q=T.length<2?.5:T.length===2?K===0?.25:.75:(K+1)/(T.length+1),J=$.x(E+(A-E)*Q,U);if(p=F==="down"?[ct(Z,"bottom",J),ct(N,"top",J)]:[ct(Z,"top",J),ct(N,"bottom",J)],w){let z=Math.min(p[0].y,p[1].y),G=Math.max(p[0].y,p[1].y);F==="down"?G-=o.head:z+=o.head;const nt=[...i.querySelectorAll(`.${a}-group`)].map(Y=>dt(Y,d));let et=[[z,G]];for(const Y of nt)for(const st of[Y.t,Y.b])et=et.flatMap(([rt,R])=>st>rt+1&&stnt.some(rt=>(Y+st)/2>rt.t&&(Y+st)/2rt.l&&J1){const Y=et.filter(([rt,R])=>!X(rt,R));[z,G]=(Y.length?Y:et).reduce((rt,R)=>R[1]-R[0]>rt[1]-rt[0]?R:rt)}const ot=[1/2,1/3,2/3].map(Y=>{const st=z+(G-z)*Y;return{l:J-S/2-u("1"),r:J+S/2+u("1"),t:st-g/2,b:st+g/2}});O.push({k:j,cands:ot,on:!0,card:F==="down"?L.to:L.from})}}else if(F==="trunk"||F==="rail"){const E=$.x(Math.max(Z.rect.l,F==="rail"?N.rect.l:Z.rect.l)+u(F==="trunk"?"8":"3"),U),A=ct(Z,"bottom",E);if(F==="rail"){if(p=[A,ct(N,"top",E)],w){const T=N.rect.t-u("6");O.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},L.to,-1),on:!1,card:L.to})}}else{const T=$.x(N.rect.l+u("6"),U),K=$.y(N.rect.t-b,U);p=[A,{x:E,y:K},{x:T,y:K},ct(N,"top",T)],w&&O.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:K-g/2,b:K+g/2},L.to,-1),on:!1,card:L.to})}}else{const E=Math.min(I.get(L.from)??c,I.get(L.to)??c),A=$.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),U),T=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[j],U),K=ct(Z,"right",T),Q=$.x(N.rect.r-u("6"),U),J=F==="end-down",z=$.y(J?N.rect.t-b:N.rect.b+b,U);p=[K,{x:A,y:K.y},{x:A,y:z},{x:Q,y:z},ct(N,J?"top":"bottom",Q)];const G=J?L.to:H[N.i+1]?.id??L.to;w&&O.push({k:j,cands:M({l:Q-u("2-5")-S,r:Q-u("2-5"),t:z-g/2,b:z+g/2},G,J?-1:1),on:!1,card:G})}const x=ne(p,U,$);v.lines.push({i:j,from:L.from,to:L.to,kind:L.kind,pts:x,tip:x[x.length-1],dir:Tt(x),width:U})}),v.crossings=Lt(v.lines),v.through=Rt(v.lines,h,r),v.outside=ue(v.lines,c,f,o);const{obstacles:q}=ce(i,d,a,0);q.heads=v.lines.map(L=>re(L,o));const W=[],_={l:0,t:0,r:c,b:f};for(const L of O){const j=N=>{const U=Pt(N,u("1"));return N.l<_.l-.5||N.r>_.r+.5||N.t<_.t-.5||N.b>_.b+.5||h.some(p=>te(U,p))||W.some(p=>ft(U,p))||q.heads.some(p=>ft(U,p))||q.rects.some(p=>ft(U,p))||v.lines.some(p=>p.i!==L.k&&ht(p.pts).some(([w,S])=>ft(U,ie(w,S,p.width))))},F=L.cands.find(N=>!j(N));F||(B[L.card]=(B[L.card]??0)+1,v.unseated.push(L.k));const Z=F?le(F,l,y,N=>!j(N)):L.cands[0];W.push(Z),v.labels.push({i:L.k,text:r.edges[L.k].label,box:Z,on:L.on})}return{geo:v,grow:B}}function on(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...M})),h=m[m.length-1];h.x-=o.x*u,h.y-=o.y*u;const l=e.tip.x-o.x*i,y=e.tip.y-o.y*i,$=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=lt(e.kind),B=a?``:``,C=e.dot?``:"";return`${B}${C}`}function pe(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const m=d.map(h=>{const l=e.lines[h.top],y=e.lines[h.under],$=l.width/2+n.cut,c=y.width/2+1;return h.underVertical?``:``}).join("");a+=`${m}`}return{defs:a,ids:r}}function ge(t,e,n,s){const{defs:r,ids:o}=pe(t,e,n,s),a=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),i=e.lines.map((m,h)=>an(t,m,n,o.get(h)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),d=`${r?`${r}`:""}${a}${i}`,u=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` -`).map(lt).join("
")}
`).join("");return d+u}function me(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const m=Ge(t),h=Ue(u,n),l=Je(e,m,h);i?.(l.least);const y=t.clientWidth,$=(()=>{const q=document.activeElement;return q&&u.contains(q)&&q.dataset.node?q.dataset.node:void 0})(),c=q=>mt(e,q)?{...q,stop:q.stop&&e.byId.has(q.stop)?q.stop:e.nodes[0]?.id,keep:void 0}:{...q,stop:q.stop??e.nodes[0]?.id,keep:$&&q.layout!=="drawn"?$:void 0};let f=!1;const v=q=>{if(f=!1,e.type!=="flowchart")return q;o({...q,heights:void 0,words:void 0});const W=ut(),_=ut();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(L=>{const j=L.querySelector(`.${n}-words`);if(!j)return;const F=L.getBoundingClientRect(),Z=p=>{const w={w:p.width+2*m.space("2-5"),h:p.height+2*m.space("2")},S=1-w.w/F.width,g=S>.05?w.h/2/S:w.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},N=j.getBoundingClientRect();let U=Z(N);if(U>F.width){const p=b=>(L.style.setProperty("--_ww",`${b}px`),j.getBoundingClientRect()),w=Math.floor(L.clientWidth-2*m.space("2-5"));let S=Math.ceil(N.width),g=N.height;for(;S1;){const T=b+x>>1;p(T).heightF.width&&(f=!0)}),{...q,heights:W,words:Object.keys(_).length?_:void 0}},B=()=>({m:e,tk:m,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(q,W)=>W.map(_=>vt(e,q.lines.find(L=>L.i===_))).join(", ");if(y>=l.least){const q=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:tn(B(),h)}};let{dd:W,g:_}=q(!1);const L=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!L(_)&&_.unseated.length&&_.unseated.every(j=>_.bounded?.includes(j))){const j=q(!0);!L(j.g)&&!j.g.unseated.length&&({dd:W,g:_}=j)}if(!L(_)&&!_.unseated.length)return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the drawn layout: ${_.crossings.map(j=>`${vt(e,_.lines[j.top])} over ${vt(e,_.lines[j.under])}`).join("; ")}`),{dyn:W,geo:_,ink:ge(n,_,m,s),tokens:m,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: a decision would be taller than it is wide`),_.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${_.misfit.join("; ")}`),_.through.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.through)} would pass through a node`),_.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.overlaps)} would lie on one another`),_.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: ${M(_,_.outside)} would leave the drawing`),_.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(y)}px: no clean seat for ${_.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ut(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:m,least:l.least};const H=Kt(e);let D=he(B(),h,H,I.grow);for(let q=0;q<6&&Object.keys(D.grow).length;q++){const W=ut(I.grow);for(const[_,L]of Object.entries(D.grow))W[_]=(gt(W,_)??0)+L;I={...I,grow:W},o(I),D=he(B(),h,H,W)}const O=D.geo;if(O.unseated.length>0||O.through.length>0||O.outside.length>0||H.third){O.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(O.unseated)].map(_=>`"${e.edges[_]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),O.through.length&&a?.(`in the stacked drawing ${M(O,O.through)} would pass through a node, so its lines are not drawn`),O.outside.length&&a?.(`in the stacked drawing ${M(O,O.outside)} would leave the drawing, so its lines are not drawn`),H.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const q={...O,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ut(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:q,ink:"",tokens:m,least:l.least}}return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${O.crossings.map(q=>`${vt(e,O.lines[q.top])} over ${vt(e,O.lines[q.under])}`).join("; ")}`),{dyn:I,geo:O,ink:ge(n,O,m,s),tokens:m,least:l.least}}function vt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function rn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const m=Lt(n.lines,i),{defs:h,ids:l}=pe(e,{...n,crossings:m},s,r),y=t.querySelector(`.${e}-svg`);if(!y)return;let $=y.querySelector("defs");!$&&h&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),y.insertBefore($,y.firstChild)),$&&($.innerHTML=h),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var ln=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function cn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",ln()||fn(t)?"done":"pending")}}var dn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function fn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(dn(t))!==null}catch{return!1}}function ye(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function un(t,e,n,s=!1,r=!1){const o=s?St(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var hn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],be=["data-layout","data-measured","data-bare","data-motion","data-first-visit"],pn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],$e=t=>t==null||t===!1;function gn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function we(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?be:hn;for(const a of s)$e(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,m=new Map(String(i??"").split(";").map(h=>{const l=h.indexOf(":");return[h.slice(0,l).trim(),h.slice(l+1).trim()]}).filter(([h])=>h));for(const[h,l]of m)u.getPropertyValue(h).trim()!==l&&u.setProperty(h,l);for(const h of pn)m.has(h)||u.removeProperty(h);continue}if(n&&!be.includes(a))continue;if($e(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,y,$){return{prefix:n,base:l,hasSource:y.source!==void 0&&y.source!==null&&y.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(l,y,$,c){var f=function(v){return''+lt(v)+""};return{source:lt(String(y.source||"")),summary:lt(String(y.summary||"")),hint:Bt(l).map(function(v){return""+v.keys.map(f).join(" ")+" "+lt(v.words)+""}).join(""),toggle:'"}}function a(l,y,$){var c=qt(l),f=Qt(c,{},r(y,l,$)),v=_t(f,o(c,l,y,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,y,$,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=qt(y);if(!$||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(y,f,c),C=document.createElement("div");C.innerHTML=B.open+"";var M=C.firstChild;i.forEach(function(R){l.removeAttribute(R)}),d.forEach(function(R){l.style.removeProperty(R)});for(var I=0;I :not(script[data-diagram])").forEach(function(R){R.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(R){console.warn("Basalt diagram: "+R)});var D=r(f,y,c),O={},V=null,q=null,W=null,_=Object.create(null),L=function(R){_[R]||(_[R]=1,console.warn("Basalt diagram: "+R))},j=function(R){we(l,Qt(v,R,D))},F=l.querySelector(".diagram-ink"),Z=l.querySelector(".diagram-toggle"),N=!c&&v.motion.animated&&typeof e.diagramMotion=="function",U=null,p=null,w=function(){N&&ye(l)};function S(){rn(l,n,V&&V.geo,V&&V.tokens,f,q||W)}function g(){Z&&(Z.setAttribute("aria-expanded",String(!!O.open)),Z.firstElementChild.textContent=O.open?"Hide the list":"View as list")}function b(){V=(c?c.measure:me)(l,v,n,f,O,j,L),O=V.dyn,j(O),g();var R=l.querySelector(":scope > .diagram-hint");if(R){var P=Bt(v,O.layout==="drawn").map(function(xt){return""+xt.keys.map(function(yn){return''+lt(yn)+""}).join(" ")+" "+lt(xt.words)+""}).join("");R.innerHTML!==P&&(R.innerHTML=P)}mt(v,O)||(W=null);var it=F&&V.ink!==p;it&&(F.innerHTML=V.ink,p=V.ink),S(),N&&V.tokens&&(cn(l,!!(V.geo&&V.geo.lines.length)),it&&U&&U.redrawn()),c&&c.onMeasured&&V.tokens&&c.onMeasured(V,l)}function x(R){O=R,j(O)}function E(R){var P=O.stop;O=Object.assign({},O,{stop:R}),mn(l,n,P,R)}var A=function(R){var P=R&&R.closest?R.closest(".diagram-node"):null;return P&&l.contains(P)?P:null};function T(R){var P=A(R.target);if(!(!P||R.defaultPrevented)){if(w(),R.key==="Escape"){!c&&(q||W)&&(R.preventDefault(),q=W=null,S());return}if(mt(v,O)){var it=un(v,P.getAttribute("data-node"),R.key,O.layout==="drawn",getComputedStyle(P).direction==="rtl");if(it){R.preventDefault(),E(it);var xt=l.querySelector('.diagram-node[data-node="'+CSS.escape(it)+'"]');xt&&xt.focus()}}}}function K(R){var P=A(R.target);if(P){w();var it=P.getAttribute("data-node");q=P.matches(":focus-visible")?it:null,mt(v,O)&&O.stop!==it&&E(it),S()}}function Q(R){var P=A(R.target);P&&(A(R.relatedTarget)||(q=null),O.keep===P.getAttribute("data-node")&&x(Object.assign({},O,{keep:void 0})),S())}function J(R){if(!(R.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var P=A(R.target);P&&w();var it=P&&mt(v,O)?P.getAttribute("data-node"):null;it!==W&&(W=it,S())}}function z(){W&&(W=null,S())}function G(){w(),x(Object.assign({},O,{open:!O.open,autoOpen:void 0})),g()}l.addEventListener("keydown",T),l.addEventListener("focusin",K),l.addEventListener("focusout",Q),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",z),Z&&Z.addEventListener("click",G),b();var nt=l.clientWidth,et=0,X=!0,ot=new ResizeObserver(function(){Math.abs(l.clientWidth-nt)<.5||(nt=l.clientWidth,cancelAnimationFrame(et),et=requestAnimationFrame(b))});ot.observe(l),document.fonts&&document.fonts.ready.then(function(){X&&b()});var Y=matchMedia("(forced-colors: active)"),st=v.nodes.some(function(R){return R.mark});st&&Y.addEventListener("change",b),N&&(U=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},y));var rt=!c&&y.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,y,{model:v,settle:w,animated:N}):null;l.__diagram={stop:function(){rt&&rt.destroy(),X=!1,ot.disconnect(),cancelAnimationFrame(et),st&&Y.removeEventListener("change",b),U&&U.destroy(),l.removeEventListener("keydown",T),l.removeEventListener("focusin",K),l.removeEventListener("focusout",Q),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",z),Z&&Z.removeEventListener("click",G)},layout:b,key:m(y),send:U&&U.sendValue?U.sendValue:null}}function m(l){try{return JSON.stringify(l,function(y,$){return y==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function h(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var y=l.querySelector(":scope > script[data-diagram]");if(y)try{u(l,JSON.parse(y.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:qt,figureKey:Ce,figureList:Fe,hintEntries:Bt,toHtml:_t,escapeHtml:lt,settleEntrance:ye,measureFigure:me},t.diagram=function(l,y){var $=l.__diagram,c=$&&$.send?m(y):null;if(c!==null&&c===$.key){$.send(y.packet?y.packet.send:void 0);return}u(l,y)},e.step(62,"wireDiagrams",h)})(window.Basalt)})(); +(()=>{var Ae=["top","right","bottom","left"],Le=["main","plain","dashed"],qe=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function _t(t,e={}){const s=e.checks!==!1,r=[],o=p=>{r.push(p)},a=t.legend??{},i={};for(const p of["main","plain","dashed","focal","group","activation"]){const k=at(a[p]);k&&(i[p]=k)}const d=t.stepLabel,u=typeof d=="function"?p=>String(d(p)):typeof d=="string"?(p=>d.replace("{n}",String(p))):p=>`Step ${p}`,y=t.shapeLabels??{},h={terminal:at(y.terminal)??"Start or end",step:at(y.step)??"Step",decision:at(y.decision)??"Decision"},l=t.heading===void 0?3:qe.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),b=(p,k)=>p==null?"plain":Le.includes(p)?p:(o(`"${String(p)}" is not a kind of line (main, plain or dashed): ${k} is drawn plain`),"plain"),$=p=>{if(p!=null){if(Ae.includes(p))return p;o(`"${String(p)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(p,k)=>typeof p=="number"&&Number.isInteger(p)&&p>=1?p:(o(`${k} is ${JSON.stringify(p)}, not a whole number from 1: it is placed at 1`),1),f=[],v=[];let B=[];const C=[],M=[],I=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(I)||o(`"${String(I)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),I==="architecture"||I==="flowchart"){for(const p of t.nodes??[]){const k=I==="flowchart"&&p.shape==="decision"?"decision":I==="flowchart"&&p.shape==="terminal"?"terminal":"box",S=String(p.id??""),g=c(p.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(p.name??""),kind:k==="decision"?void 0:at(p.kind),detail:k==="decision"?void 0:at(p.detail),mono:!!p.detailMono,focal:!!p.focal,col:c(p.col,`the column of ${S}`),row:g,row2:g,branch:!!p.branch,shape:k,group:I==="architecture"?at(p.group):void 0,mark:I==="architecture"?Ct(p.mark):void 0})}if(I==="architecture"){const p=(t.groups??[]).map(m=>({id:String(m.id??""),label:String(m.label??""),parent:at(m.parent)})),k=new Map(p.map(m=>[m.id,m])),S=m=>{if(!m.parent)return 1;const w=k.get(m.parent);return w?w.parent===m.id||w.id===m.id?(o(`the groups "${m.label}" and "${w.label}" are each other's parent`),m.parent=void 0,1):w.parent?(o(`the group "${m.label}" is a third level: groups nest two deep`),m.parent=void 0,1):2:(o(`the group "${m.label}" names the parent "${m.parent}", which is not a group`),m.parent=void 0,1)},g=p.map(S);p.forEach((m,w)=>C.push({...m,depth:g[w],members:f.filter(E=>E.group===m.id).map(E=>E.id),all:[]}));for(const m of C)m.all=[...m.members,...C.filter(w=>w.parent===m.id).flatMap(w=>w.members)];C.sort((m,w)=>m.depth-w.depth)}}else if(I==="data-flow"){B=(t.lanes??[]).map(k=>({id:String(k.id??""),label:String(k.label??"")}));const p=new Map(B.map((k,S)=>[k.id,S+1]));for(const k of t.nodes??[]){const S=String(k.id??""),g=String(k.lane??""),m=p.get(g);m===void 0&&o(`a node (${S}) names the lane "${g}", which is not in lanes`);const w=f.length+1;f.push({id:S,i:f.length,name:String(k.name??""),kind:u(w),detail:at(k.detail),mono:!!k.detailMono,focal:!!k.focal,col:c(k.col,`the column of ${S}`),row:m??1,row2:m??1,branch:!1,shape:"box",lane:m??1,laneLabel:B[(m??1)-1]?.label??g,step:w,mark:Ct(k.mark)})}}else if(I==="sequence"){(t.participants??[]).forEach((g,m)=>{const w=String(g.name??"");f.push({id:String(g.id??""),i:m,name:w,kind:at(g.kind),mono:!1,focal:!!g.focal,col:m+1,row:1,row2:1,branch:!1,shape:"participant",short:at(g.short)??w,mark:Ct(g.mark)})});let p=0;const k=new Map(f.map(g=>[g.id,g.col])),S=(g,m)=>{let w=1/0,E=-1/0;for(const L of g??[]){if(!L||typeof L!="object")continue;if("band"in L){m>0&&o(`the band "${String(L.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(L.band??"")});continue}if("frame"in L){if(m>=2){o("a frame is a third level: frames nest two deep");continue}const et=L.frame==="alt"||L.frame==="loop"||L.frame==="opt"?L.frame:"opt",nt=et==="alt"?L.branches??[]:[{label:L.label,steps:L.steps}];et==="alt"&&nt.length<2&&o("an alt frame has one branch: it needs two or more");const J=String(nt[0]?.label??"");J.length>40&&o(`the frame label "${J}" is over 40 characters`);const ot=M.length;M.push({open:et,label:J,depth:m+1,a:0,b:0}),nt.forEach((X,st)=>{if(st){const xt=String(X.label??"");xt.length>40&&o(`the frame label "${xt}" is over 40 characters`),M.push({otherwise:xt,depth:m+1})}X.steps?.length||o(`a frame or branch ("${String(X.label??"")}") is empty`);const[rt,ct]=S(X.steps??[],m+1);w=Math.min(w,rt),E=Math.max(E,ct);const bt=M[ot];bt.a=Math.min(bt.a||1/0,rt),bt.b=Math.max(bt.b,ct)}),M.push({close:m+1});continue}p++;const T=String(L.label??"");T.includes(` +`)&&o(`message ${p}'s label has a break: a message's second line is its note`);const H=String(L.from??""),P=String(L.to??"");M.push({n:p,from:H,to:P,label:gt(T),note:at(L.note),kind:b(L.kind,`message ${p}`),activate:L.activate===!0||void 0,deactivate:L.deactivate===!0||void 0});const U=k.get(H)??1,R=k.get(P)??1,K=U===R?U===f.length?U-1:U+1:U;w=Math.min(w,U,R,K),E=Math.max(E,U,R,K)}return[w,E]};S(t.steps??[],0);for(const g of M)"open"in g&&!Number.isFinite(g.a)&&(g.a=1,g.b=Math.max(1,f.length))}else if(I==="schema")for(const p of t.tables??[]){const k=String(p.name??""),[S,g]=Array.isArray(p.row)?p.row:[p.row,p.row],m=c(S,`the row of ${k}`),w=Math.max(m,c(g,`the last row of ${k}`)),E=p.more===void 0||p.more===null?void 0:Number.isInteger(p.more)&&p.more>0?p.more:(o(`${k}'s "more" is ${JSON.stringify(p.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:k,i:f.length,name:k,mono:!0,focal:!!p.focal,col:c(p.col,`the column of ${k}`),row:m,row2:w,branch:!1,shape:"table",more:E,columns:(p.columns??[]).map(L=>({name:String(L.name??""),type:at(L.type),key:L.key==="PK"||L.key==="FK"?L.key:(L.key!==void 0&&L.key!==null&&o(`${k}.${String(L.name)}'s key is "${String(L.key)}", not PK or FK: it is left out`),void 0)}))})}((I==="schema"?t.tables:I==="sequence"?t.participants:t.nodes)??[]).forEach((p,k)=>{if(!p||p.href===void 0||p.href===null)return;const S=String(p.href);if(I==="sequence"){o(`${f[k]?.id}: a participant cannot be a link (href)`);return}if(!S){o(`${f[k]?.id}'s href is empty`);return}const g=f[k];g&&(g.href=S,g.blank=p.target==="_blank")});const G=new Map;for(const p of f)p.id?G.has(p.id)&&o(`the id "${p.id}" is used twice`):o("a node has no id"),G.set(p.id,p);if(I==="schema")(t.tables??[]).forEach(p=>(p.columns??[]).forEach((k,S)=>{const g=at(k.references);if(!g)return;const[m,w]=g.split("."),E=G.get(m??""),L=E?.columns?.findIndex(H=>H.name===w)??-1;if(!E||L<0){o(`${String(p.name)}.${String(k.name)} references ${g}, which is not a shown column`);return}const T=G.get(String(p.name??""));T.columns[S].ref={table:m,column:w,row:L},v.push({i:v.length,from:T.id,to:m,kind:"plain",fromRow:S,toRow:L,fk:!0})}));else if(I!=="sequence")for(const p of t.edges??[]){const k=String(p.from??""),S=String(p.to??"");if(!G.has(k)||!G.has(S)){o(`a line names ${G.has(k)?S:k}, which is not a node`);continue}const g=at(p.label),m=g?.split(` +`)??[];m.length>2&&o(`the label "${gt(g)}" has more than one break: a label is two lines at most`),m.some(w=>w.length>Nt)&&o(`a line of the label "${gt(g)}" is over ${Nt} characters: longer words belong in the node or the summary`),v.push({i:v.length,from:k,to:S,kind:b(p.kind,`the line from ${k} to ${S}`),label:g,fromSide:$(p.fromSide),toSide:$(p.toSide),flow:I!=="flowchart"&&p.flow===!0?!0:void 0})}else for(const p of M)"n"in p&&(!G.has(p.from)||!G.has(p.to))&&o(`message ${p.n} names ${G.has(p.from)?p.to:p.from}, which is not a participant`);if(s&&I!=="sequence"){const p=new Map;for(const k of f)for(let S=k.row;S<=k.row2;S++){const g=`${k.col}:${S}`;p.has(g)&&o(`${k.id} and ${p.get(g)} share the cell at column ${k.col}, row ${S}`),p.set(g,k.id)}}if(s){for(const k of C){const S=k.all.map(w=>G.get(w));if(!S.length)continue;const g={c1:Math.min(...S.map(w=>w.col)),c2:Math.max(...S.map(w=>w.col)),r1:Math.min(...S.map(w=>w.row)),r2:Math.max(...S.map(w=>w.row2))};for(const w of f)!k.all.includes(w.id)&&w.col>=g.c1&&w.col<=g.c2&&w.row>=g.r1&&w.row<=g.r2&&o(`${w.id} is inside the box of the group "${k.label}" but not a member`);const m=S.map(w=>w.i);Math.max(...m)-Math.min(...m)+1!==m.length&&o(`the members of the group "${k.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const k of f)k.group&&!C.some(S=>S.id===k.group)&&o(`${k.id} names the group "${k.group}", which is not in groups`);f.filter(k=>k.focal).length>1&&o("more than one node is focal: a diagram has one at most");const p=new Set(I==="sequence"?M.flatMap(k=>"n"in k?[k.kind]:[]):v.map(k=>k.kind));p.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),p.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(k=>k.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const _=I==="architecture"||I==="data-flow",V=p=>Array.isArray(p)&&p.length>1?p.map(String):void 0,q=_&&t.packet&&typeof t.packet=="object"?t.packet:void 0,W=q&&V(q.path),O={animated:t.motion==="animated",pulse:_?V(t.pulse):void 0,packet:W?{path:W,repeat:q.repeat===!0,send:q.send}:void 0,run:I==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const p of f){const k=p.mark?.says;if(!k?.length)continue;const S=[p.name,p.kind,p.detail,p.laneLabel].filter(Boolean).join(" ").toLowerCase();k.some(g=>S.includes(g.toLowerCase()))||o(`${p.id}'s mark stands for ${k.join(" or ")}, and none of its words say so`)}const A=[];if(I==="sequence"){const p=new Map,k=new Map;for(const S of M)"n"in S&&(k.set(S.from,S.n),k.set(S.to,S.n));for(const S of M)if("n"in S){if(S.activate){const g=p.get(S.to)??[];if(g.length>=3)o(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const m={who:S.to,from:S.n,to:S.n,depth:g.length+1};g.push(m),A.push(m),p.set(S.to,g)}}if(S.deactivate){const m=p.get(S.from)?.pop();m?m.to=S.n:o(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,g]of p)for(const m of g)m.to=Math.max(m.from,k.get(S)??m.from)}const j=t.frameLabels??{},F={opt:at(j.opt)??"Only if",loop:at(j.loop)??"Repeats",alt:at(j.alt)??"One of these",else:at(j.else)??"Otherwise"},Z=Math.max(1,...f.map(p=>p.col)),z=I==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(p=>p.row2)),Y={type:I,title:String(t.title??""),heading:l,legend:i,nodes:f,byId:G,edges:v,groups:C,lanes:B,steps:M,bars:A,frameWords:F,cols:Z,rows:z,shapeLabels:h,stepWord:u,warnings:r,motion:O,memo:new Map};return s&&f.length>1&&!Lt(Y)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),Y}function Ct(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ht=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function $t(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Nt=28,jt=t=>t.includes(` +`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Dt(t,e){return t.legend[e]}function Ie(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Oe(t,e){return $t(t,`sentence:${e.i}`,()=>_e(t,e))}function _e(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Gt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Ie(t,e):e.kind;if(n.push(wt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${gt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${gt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Gt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function Ce(t,e,n,s){const r=n.pointerType;if(r!=="touch"&&r!=="pen")return;const o=t.querySelector(`.${e}-drawing`),a=n.target;if(!o||!a||!o.contains(a)||!t.querySelector(`.${e}-edge`))return;const i=a.closest(`.${e}-node`);if(!i?.hasAttribute("href"))return i?i.dataset.node===s?null:i.dataset.node??null:null}function Kt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function x(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var je={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>je[e]),Be=" br img input meta link hr path polygon polyline circle rect line ";function Bt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${it(String(r))}"`}return Be.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Bt(s,e)).join("")}`}var Te=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Re(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Et(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Vt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=Et(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Zt(t,n,a)))})}return e})}function Zt(t,e,n){const s=Et(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=Et(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Ut(t){const e=Vt(t);return e[1]+e[3]}function Tt(t){return t.type==="sequence"?t.nodes.length:t.cols}function Jt(t){return $t(t,"plan",()=>We(t))}function We(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},y=t.edges.map(()=>0);let h=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,y[v.k]+1));y[c.k]=f,f>1&&(h=!0),l.push(c)}const b=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{b[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const $=ht();for(let c=1;c{const _=s[G],V=t.byId.get(D.from).i,q=t.byId.get(D.to).i,W=q===c&&(_==="down"||_==="trunk"||_==="rail"||_==="end-down"),O=V===c&&q===c-1&&_==="up",A=q===c-1&&_==="end-up";W&&(_==="trunk"||_==="end-down")&&(M=!0),A&&(I=!0),(W||O||A)&&D.label&&(B++,C=Math.max(C,_==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),$[f.id]=C}return{routes:s,gutter:d,lanes:y,exits:b,gaps:$,third:h}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Xt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return x("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?x("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,x("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?x("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):x("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function kt(t,e){return e==="decision"?x("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},x("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?x("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):x("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Yt(t,e){return $t(e,`key:${t}`,()=>Fe(t,e))}var ze=Yt;function Fe(t,e){const n=[],s=(o,a,i={})=>n.push(x("li",{class:`${t}-entry`,...i},o,x("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(x("li",{class:`${t}-entry`},x("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),x("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(kt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(kt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(kt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Xt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Xt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(x("li",{class:`${t}-entry`,"data-when":"stacked"},x("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),x("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(x("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},x("path",{class:`${t}-life`,d:"M8 0V16"}),x("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(x("li",{class:`${t}-entry`},x("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),x("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(kt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(kt(t,"group"),e.legend.group),n.length?x("div",{class:`${t}-key`},x("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function He(t,e){const n=e==="main"?6:6.5;return x("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},x("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?x("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):x("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Rt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),x("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Ne(t,e,n){if(n.shape==="decision")return[x("span",{class:`${t}-words`},x("span",{class:`${t}-name`},Rt(t,n)))];const s=[];return e.type==="data-flow"?s.push(x("span",{class:`${t}-kind`},n.kind,x("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(x("span",{class:`${t}-kind`},n.kind)),s.push(x("span",{class:`${t}-name`},Rt(t,n))),n.detail&&s.push(x("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?It(n.detail).flatMap((r,o)=>[o?" ":"",x("span",{class:`${t}-run`},r)]):n.detail)),s}function De(t,e){return[x("span",{class:`${t}-th`},x("span",{class:`${t}-tname`},Rt(t,e))),x("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>x("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},x("span",{class:`${t}-keyseat`},n.key??""),x("span",{class:`${t}-cname`},n.name),n.ref?x("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?x("span",{class:`${t}-ctype`},n.type):null))),e.more?x("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Qt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=Re(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=yt(d.gaps,n.id)??32,b=yt(s.grow,n.id)??0;i.push(`--_gap:${b?`calc(${Qt(l)} + var(--basalt-space-4) * ${b})`:Qt(l)}`)}const u=yt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const y=yt(s.words,n.id);y&&i.push(`--_ww:${y}px`);const h=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return x(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?Oe(e,n):void 0,tabindex:h},n.shape==="decision"?x("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},x("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?x("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ht(n.mark.onLight)};--_md:${Ht(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?De(r,n):Ne(r,e,n))}function Ge(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>x("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},x("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=Et(e,d);if(!u)continue;const y=[0,1,2,3].map(h=>Zt(e,d,h));r.push(x("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${y[0]>1?";--_gt:2":""}${y[1]>1?";--_ge:2":""}${y[2]>1?";--_gb:2":""}${y[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},x("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(x("ul",{class:`${s}-cast`},e.nodes.map(d=>x("li",{class:`${s}-actor`},At(t,e,d,n))))),r.push(Ke(t,e)),r;const o=d=>{const u=d.group?e.groups.find(y=>y.id===d.group):void 0;return u?.parent?e.groups.find(y=>y.id===u.parent):u},a=(d,u,y)=>{const h=t.plan?yt(n.grow,u[0].id)??0:0;return x("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:h?`--_ggrow:${h}`:void 0},x("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),y)};let i=0;for(;ic.id===y[l].group):void 0;if(!b){h.push(At(t,e,y[l],n)),l++;continue}const $=[];for(;lAt(t,e,c,n))))}r.push(a(u,y,h))}return r}function Ke(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(x("p",{class:`${n}-band`},x("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=x("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},x("span",{class:`${n}-fbox`,"aria-hidden":"true"}),x("p",{class:`${n}-fhead`},x("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),x("span",{class:`${n}-flabel`},x("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(x("p",{class:`${n}-felse`},x("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),x("span",{class:`${n}-flabel`},x("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=x("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),y=d?.col??1,h=u?.col??1,l=y===h,b=l&&y===e.nodes.length,$=Dt(e,i.kind);a.c.push(x("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?b?"start":"end":void 0,style:`--_a:${Math.min(y,h)};--_b:${Math.max(y,h)+1}`},x("span",{class:`${n}-said`},x("span",{class:`${n}-num`},String(i.n)),x("span",{class:`${n}-mlabel`},i.label)),x("span",{class:`${n}-route`},d?.short??i.from," ",He(n,i.kind),x("span",{class:t.hidden}," to ")," ",u?.short??i.to,$?` · ${$}`:""),i.note?x("span",{class:`${n}-note`},i.note):null))}return x("div",{class:`${n}-steps`},s)}function Pt(t,e){return $t(e,`list:${t}`,()=>Ze(t,e))}var Ve=Pt;function Ze(t,e){const n=Math.min(6,e.heading+1),s=h=>x(`h${n}`,{class:`${t}-list-head`},h),r=h=>x("strong",null,h),o=h=>h.href?x("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},r(h.name)):r(h.name),a=h=>x("code",{class:`${t}-code`},h),i=h=>e.byId.get(h)?.name??h,d=h=>{const l=Dt(e,h);return l?` (${l})`:""},u=h=>h.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const h=$=>x("li",null,o($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?a($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",u($)),l=[s("Parts")],b=e.nodes.filter($=>!$.group);b.length&&l.push(x("ul",{class:`${t}-list-items`},b.map(h)));for(const $ of e.groups.filter(c=>c.depth===1)){l.push(x("p",{class:`${t}-list-group`},$.label)),$.members.length&&l.push(x("ul",{class:`${t}-list-items`},$.members.map(c=>h(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===$.id))l.push(x("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(x("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>h(e.byId.get(f)))))}return l.push(s("Connections")),l.push(x("ol",{class:`${t}-list-items`},e.edges.map($=>x("li",null,r(i($.from))," to ",r(i($.to)),$.label?[": ",a(gt($.label))]:"",`${d($.kind)}.`)))),l}if(e.type==="flowchart"){const h=l=>(e.byId.get(l)?.i??0)+1;return[x("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const b=e.edges.filter(f=>f.from===l.id),$=l.shape==="decision"?"Decision":l.shape==="terminal"?b.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return x("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${$}.`,u(l),b.length?x("ul",{class:`${t}-list-exits`},b.map(f=>x("li",null,f.label?`If ${gt(f.label)}: go to ${h(f.to)}, `:`Then: go to ${h(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[x("ol",{class:`${t}-list-items`},e.nodes.map(h=>{const l=e.edges.filter(b=>b.from===h.id);return x("li",null,`${h.laneLabel}: `,o(h),h.detail?[", ",h.mono?a(h.detail):h.detail]:"",".",u(h),l.length?[" Then ",...l.flatMap((b,$)=>[$?"; ":"",`to step ${e.byId.get(b.to).step}, `,r(i(b.to)),b.label?[": ",a(gt(b.label))]:"",d(b.kind)]),"."]:"")}))];if(e.type==="sequence"){const h=[s("Participants"),x("ul",{class:`${t}-list-items`},e.nodes.map(b=>x("li",null,r(b.name),b.kind?`, ${b.kind}`:"",".",u(b),Gt(e,b))))];h.push(s("Messages"));let l=null;for(const b of e.steps){if("band"in b){l=null,h.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},b.band));continue}if("open"in b){l=null,h.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords[b.open]}: ${b.label}`));continue}if("otherwise"in b){l=null,h.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords.else}: ${b.otherwise}`));continue}if("close"in b){l=null;continue}l||(l=x("ol",{class:`${t}-list-items`,start:b.n}),h.push(l)),l.c.push(x("li",null,a(b.label),": ",r(i(b.from))," to ",r(i(b.to)),`${d(b.kind)}.`,b.note?` ${wt(b.note)}`:""))}return h}const y=[];for(const h of e.nodes)y.push(x(`h${n}`,{class:`${t}-list-group`},h.href?x("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},a(h.name)):a(h.name),u(h))),y.push(x("ul",{class:`${t}-list-items`},[...(h.columns??[]).map(l=>x("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...h.more?[x("li",null,`and ${h.more} more ${h.more===1?"column":"columns"}`)]:[]]));return y}function te(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Lt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Wt(t,e=!1){const n=e&&t.type!=="sequence"&&Lt(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Kt(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var Ue=(t,e)=>{for(let n=0;n({col:t.type==="sequence"?e.i+1:e.col,rows:[e.row,e.row2]});function Lt(t){return $t(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...Je(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=$=>i?[$.col,$.col]:$.rows,y=$=>i?$.rows:[$.col,$.col],h=u(o),l=y(o);let b=null;return e.forEach(($,c)=>{if($===o)return;const f=u($),v=y($),B=d?f[0]-h[1]:h[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!b||Ue(M,b.rank))&&(b={id:$.id,rank:M})}),b?.id??null},s=ht();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var ee=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function ne(t,e,n){const s=n.prefix,r=Te(n.base),o=t.type==="sequence"||t.type==="schema"?null:Jt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,y=`h${t.heading}`,h=[`--_cols:${Tt(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Vt(t):[0,0,0,0],b=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",$=i&&e.pad?"3":void 0;h.push(`--_gpad:${b(l[0],"8",$)} ${b(l[1],"4")} ${b(l[2],"4",$)} ${b(l[3],"4")}`)}return ee(t)&&h.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&h.push(`--_track:${e.track}px`),x("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Tt(t),"data-reach":t.type==="architecture"?Ut(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-viewer":n.viewer?"":void 0,style:h.join(";")},x("div",{class:`${s}-head`},x(y,{id:r.title,class:`${s}-title`},t.title),n.hasSource?x("p",{class:`${s}-source`},{slot:"source"}):null),x("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},Ge(a,t,e),x("div",{class:`${s}-ink`,"aria-hidden":"true"}),x("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Yt(s,t),x("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||i&&t.type==="sequence"?x("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${Kt(t)} to highlight its lines. Tap it again to clear.`):null,x("div",{class:`${s}-foot`},{slot:"toggle"}),x("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Pt(s,t)),x("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${te(t,i)} ${n.viewer}`:te(t,i)),x("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Xe(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var qt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,oe=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,y=(a-r)/2,h=e==="top"||e==="bottom";if(t.shape==="decision"){if(h){const $=n,c=y*Math.max(0,1-Math.abs($-i)/u);return{x:$,y:e==="top"?d-c:d+c}}const l=n,b=u*Math.max(0,1-Math.abs(l-d)/y);return{x:e==="left"?i-b:i+b,y:l}}if(t.shape==="terminal"){const l=Math.min(u,y);if(h){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const b=n,$=b-d,c=Math.abs($)>=l?0:Math.sqrt(l*l-$*$);return{x:e==="left"?s+l-c:o-l+c,y:b}}return h?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Ye(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,y=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/y<1-n/Math.min(u,y);if(e.shape==="terminal"){const h=Math.min(u,y),l=Math.min(Math.max(t.x,s+h),o-h);return Math.hypot(t.x-l,t.y-d)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function tn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var It=t=>t?t.split(/\s+/).filter(Boolean):[];function en(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`→ ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),y=d.mark&&!Pe()?(d.shape==="participant"?2:1)*s("6"):0;let h=0;const l=d.href?16+s("1-5"):0,b=It(d.name);if(b.forEach((c,f)=>{h=Math.max(h,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:y)+(f===b.length-1?l:0))}),t.type!=="data-flow")for(const c of It(d.kind))h=Math.max(h,n(c,"mono")+y);for(const c of It(d.detail))h=Math.max(h,n(c,d.mono?"mono":"sans"));const $=d.shape==="decision"?h/.62:h+u+2*e.hair;r=Math.max(r,Math.ceil($))}const a=Tt(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(ee(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Ut(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ae(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function zt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function re(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Ot(t,e,n){const s=[];for(let o=0;oMath.min(c.x,f.x)+.75&&CMath.min(v.y,B.y)+.75&&Mr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",ie={top:"bottom",bottom:"top",left:"right",right:"left"};function on(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function sn(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,y]=e[a],h=i.row===d.row&&tt(u)&&tt(y)&&u===ie[y]||i.col===d.col&&!tt(u)&&!tt(y)&&u===ie[y];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:h,f:.5},{edge:a,end:"to",node:d,side:y,far:i,straight:h,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const y=new Map;for(const c of d)y.has(c.far.id)||y.set(c.far.id,[]),y.get(c.far.id).push(c);for(const c of y.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const h=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),b=u.filter(c=>i(c)<0),$=u.filter(c=>i(c)>=0);b.forEach((c,f)=>{c.f=h*(f+1)/(b.length+1)}),$.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/($.length+1)})}return s}function le(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?lt(t,e,r+(a-r)*n):lt(t,e,s+(o-s)*n)}function ce(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ft(o,n),shape:a.shape,i:a.i})}),r}function de(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function ue(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function an(t,e,n,s,r,o,a,i,d){const u=a.space,y=[],h=[],l=[],b=[],$=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*jt(v),M=f.pts.length-2,I=[];pt(f.pts).forEach(([q,W],O)=>{const A=Math.abs(q.y-W.y)<.01,j=A?q.x:q.y;let F=A?W.x:W.y;const Z=Math.sign(F-j)||1;O===M&&(F-=Z*a.head);let z=[[j,F]];for(const k of r)for(const S of A?[k.l,k.r]:[k.t,k.b]){const g=A?q.y:q.x;(A?g>k.t&&gk.l&&gS>Math.min(w,E)+1&&S{const g=(k+S)/2,m=A?{x:g,y:q.y}:{x:q.x,y:g};return!r.some(w=>m.x>w.l&&m.xw.t&&m.y1&&Y(k,S)?1:0})}),I.sort((q,W)=>W.pri-q.pri||W.len-q.len);let D=null,G=!1;const _=(q,W=!0)=>{const O=oe(q,$);return W&&(q.lo.r||q.to.b)||n.some(A=>se(O,A))||y.some(A=>ut(O,A))||s.heads.some(A=>ut(O,A))||s.rects.some(A=>ut(O,A))?!1:!e.some(A=>A.i!==f.i&&pt(A.pts).some(([j,F])=>ut(O,fe(j,F,A.width))))};for(const q of I){for(const W of[1/2,1/3,2/3]){const O=q.p+(q.q-q.p)*W,A=[],j=u("2")+f.width/2;if(q.horiz?(q.len>=B+2*u("1")+u("3-5")&&A.push({box:{l:O-B/2-u("1"),r:O+B/2+u("1"),t:q.c-C/2,b:q.c+C/2},on:!0}),A.push({box:{l:O-B/2,r:O+B/2,t:q.c-j-C,b:q.c-j},on:!1}),A.push({box:{l:O-B/2,r:O+B/2,t:q.c+j,b:q.c+j+C},on:!1})):(q.len>=C+u("3")&&A.push({box:{l:q.c-B/2-u("1"),r:q.c+B/2+u("1"),t:O-C/2,b:O+C/2},on:!0}),A.push({box:{l:q.c+j,r:q.c+j+B,t:O-C/2,b:O+C/2},on:!1}),A.push({box:{l:q.c-j-B,r:q.c-j,t:O-C/2,b:O+C/2},on:!1})),D=A.find(F=>_(F.box))??null,D)break;!G&&A.some(F=>_(F.box,!1))&&(G=!0)}if(D)break}if(!D){l.push(f.i),G&&b.push(f.i);continue}const V=ue(D.box,d.ox,d.oy,q=>_(q));y.push(V),h.push({i:f.i,text:v,box:V,on:D.on})}return{labels:h,unseated:l,bounded:b}}function he(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=ft(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(ft(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=ft(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(ft(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function rn(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,y=ce(s,a,i,o),h=[...y.values()],l=nn(a),b=i.left-Math.floor(i.left),$=i.top-Math.floor(i.top),c=ae(b,$),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:b,oy:$};if(s.type==="sequence")return cn(t,M,c);let I,D=[];s.type==="schema"?I=s.edges.map(g=>{const m=s.byId.get(g.from),w=s.byId.get(g.to);if(m.col===w.col){const E=m.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return w.col>m.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const m=s.byId.get(g.from),w=s.byId.get(g.to),[E,L]=on(m,w);return[g.fromSide??E,g.toSide??L]}),D=sn(s,I,d||(()=>{})));const G=(g,m)=>{const w=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${m}"]`);if(!w)return 0;const E=ft(w,i);return(E.t+E.b)/2},_=s.edges.map((g,m)=>{const[w,E]=I[m],L=y.get(g.from),T=y.get(g.to),H=qt(g.kind,r);if(g.fk){const J=G(g.from,g.fromRow),ot=G(g.to,g.toRow),X=c.y(J,H),st=c.y(ot,H);return{p1:{x:w==="right"?L.rect.r:L.rect.l,y:X},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:J,r2:Math.abs(X-st)<.01?J:ot}}const P=D.find(J=>J.edge===m&&J.end==="from").f,U=D.find(J=>J.edge===m&&J.end==="to").f;let R=le(L,w,P),K=le(T,E,U);const et=tt(w)?R.y:R.x;let nt=tt(E)?K.y:K.x;return tt(w)?R={...R,y:c.y(R.y,H)}:R={...R,x:c.x(R.x,H)},tt(E)?K={...K,y:c.y(K.y,H)}:K={...K,x:c.x(K.x,H)},tt(w)&&tt(E)&&Math.abs(R.y-K.y)<1.01&&(K={...K,y:R.y},nt=et),!tt(w)&&!tt(E)&&Math.abs(R.x-K.x)<1.01&&(K={...K,x:R.x},nt=et),R=tt(w)?lt(L,w,R.y):lt(L,w,R.x),K=tt(E)?lt(T,E,K.y):lt(T,E,K.x),{p1:R,p2:K,r1:et,r2:nt}}),V=new Set;s.type==="schema"&&s.edges.forEach((g,m)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&V.add(m)});const q=new Map,W=new Set;s.edges.forEach((g,m)=>{if(V.has(m))return;const[w,E]=I[m],{p1:L,p2:T}=_[m],H=s.byId.get(g.from),P=s.byId.get(g.to);let U=null,R=null,K=!1;if(w===E){if(tt(w)){const J=w==="right"?Math.max(B(H),B(P)):Math.min(B(H),B(P))-1,ot=l.cols[J-1],X=l.cols[J];ot&&X&&(U=`c${J}`,R=[ot[1],X[0]],K=!0)}else{const J=w==="bottom"?Math.max(H.row2,P.row2):Math.min(H.row,P.row)-1,ot=l.rows[J-1],X=l.rows[J];ot&&X&&(U=`r${J}`,R=[ot[1],X[0]],K=!1)}U&&W.add(m)}else if(tt(w)&&tt(E)&&Math.abs(L.y-T.y)>.5){const J=B(P),ot=E==="left",X=l.cols[(ot?J-1:J)-1],st=l.cols[(ot?J:J+1)-1];X&&st&&(U=`c${ot?J-1:J}`,R=[X[1],st[0]],K=!0)}else if(!tt(w)&&!tt(E)&&Math.abs(L.x-T.x)>.5){const ot=E==="top"?P.row-1:P.row2,X=l.rows[ot-1],st=l.rows[ot];X&&st&&(U=`r${ot}`,R=[X[1],st[0]],K=!1)}if(!U||!R)return;q.has(U)||q.set(U,{span:R,vertical:K,members:new Map});const et=`${g.to}.${E}.${Math.round(K?T.y:T.x)}`,nt=q.get(U);nt.members.has(et)||nt.members.set(et,[]),nt.members.get(et).push(m)});const O=new Map,A=g=>{const[m,w]=I[g],{p1:E,p2:L}=_[g];if(tt(m)&&tt(w)){if(m===w){const H=O.get(g)??(m==="right"?Math.max(E.x,L.x)+u("4"):Math.min(E.x,L.x)-u("4"));return[E,{x:H,y:E.y},{x:H,y:L.y},L]}if(Math.abs(E.y-L.y)<=.5)return[E,{x:L.x,y:E.y}];const T=O.get(g)??(E.x+L.x)/2;return[E,{x:T,y:E.y},{x:T,y:L.y},L]}if(!tt(m)&&!tt(w)){if(m===w){const H=O.get(g)??(m==="bottom"?Math.max(E.y,L.y)+u("4"):Math.min(E.y,L.y)-u("4"));return[E,{x:E.x,y:H},{x:L.x,y:H},L]}if(Math.abs(E.x-L.x)<=.5)return[E,{x:E.x,y:L.y}];const T=O.get(g)??(E.y+L.y)/2;return[E,{x:E.x,y:T},{x:L.x,y:T},L]}return tt(m)?[E,{x:L.x,y:E.y},L]:[E,{x:E.x,y:L.y},L]},j=g=>{const m=s.edges[g],w=qt(m.kind,r),E=A(g),L=re(E,w,c);let T;return E.length===L.length&&(T=pt(E).map(([H,P])=>Math.abs(H.y-P.y)<.75?(H.y+P.y)/2:(H.x+P.x)/2),T[0]=_[g].r1,T.length>1&&(T[T.length-1]=_[g].r2)),{i:g,from:m.from,to:m.to,kind:m.kind,pts:L,tip:L[L.length-1],dir:zt(L),dot:m.fk?L[0]:void 0,width:w,axes:T}},F=()=>s.edges.flatMap((g,m)=>V.has(m)?[]:[j(m)]);let Z=null;const z=g=>{Z??(Z=F());const m=Z.map(w=>g.has(w.i)?j(w.i):w);return{lines:m,score:ln(m,g)*1e5+Ot(m,void 0,g).length*1e3+Ft(m.filter(w=>g.has(w.i)),h,s).length}},Y=(g,m)=>{const w=g.flatMap(E=>{const{p1:L,p2:T}=_[E];return m?[L.y,T.y]:[L.x,T.x]});return[Math.min(...w),Math.max(...w)]};for(const[,g]of q){const m=[...g.members.values()].map(E=>({members:E,run:Y(E,g.vertical)})).sort((E,L)=>E.run[0]-L.run[0]),w=[];for(const E of m){const L=w[w.length-1];L&&L.some(T=>T.run[0]W.has(et)))continue;const L=E.map(et=>et.members),T=L.length,H=(g.span[1]-g.span[0])/(T+1);HJ.forEach(X=>O.set(X,g.span[0]+H*(ot+1))));const nt=z(P);nt.scoreet.forEach(J=>O.set(J,g.span[0]+H*(nt+1)))),Z=K}}M.lines=F();for(const g of V)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=Ot(M.lines),M.through=Ft(M.lines,h,s),M.outside=me(M.lines,f,v,r);const{obstacles:p,groups:k}=he(a,i,o,C);p.heads=M.lines.map(g=>de(g,r));const S=an(s,M.lines,h,p,k,{l:0,t:0,r:f,b:v},r,e,{ox:b,oy:$});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(pe(M.lines,null).flat())],M}function ln(t,e){return pe(t,e).length}function pe(t,e){const n=[];for(let s=0;s=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[y.x,h.x]:[y.y,h.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*ge(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Ft(t,e,n){const s=[];for(const r of t){const o=pt(r.pts);e.some(a=>o.some(([i,d])=>Qe(i,d,a)))&&s.push(r.i)}return s}function cn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,ft(M,i)));const y=a.querySelector(`.${o}-steps`),h=y?ft(y,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:h})}const b=M=>u.get(M.id),$=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=ft(M,i);$.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const D=l(M.who),G=I.i===s.nodes.length-1&&s.nodes.length>1?-1:1,_=(M.depth-1)*d("1")*G,V=$.get(M.from)??0,q=$.get(M.to)??V,W=M.from===M.to;return{l:n.x(D-f+_,r.hair),r:n.x(D+f+_,r.hair),t:n.y(W?V-d("2")-d("1"):V,r.hair),b:n.y(W?V+d("2")+d("1"):q,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,D)=>B.filter(({bar:G})=>G.who===M&&G.to>=I&&(D?G.from<=I:G.from_.bar.depth-G.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,D=M.dataset.to,G=M.dataset.kind??"plain",_=qt(G,r),V=ft(M,i),q=n.y((V.t+V.b)/2,_),W=Number(M.querySelector(`.${o}-num`)?.textContent??0);let O=l(I),A=l(D),j;if(I===D){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,W,!0),m=g?S>0?g.r:g.l:O,w=n.y(q-d("2"),_),E=n.y(q+d("2"),_);j=[{x:m,y:w},{x:n.x(O+S,_),y:w},{x:n.x(O+S,_),y:E},{x:m,y:E}]}else{const S=A>O?1:-1,g=C(I,W,!1),m=C(D,W,!0);g&&(O=S>0?g.r:g.l),m&&(A=S>0?m.l:m.r),j=[{x:O,y:q},{x:A,y:q}]}e.lines.push({i:W,from:I,to:D,kind:G,pts:j,tip:j[j.length-1],dir:zt(j),width:_});const F=M.querySelector(`.${o}-said`),Z=M.querySelector(`.${o}-note`),z=s.byId.get(I),Y=s.byId.get(D);if(!z||!Y)return;const p=I===D?(()=>{const S=s.nodes[z.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-O)-d("6")-d("2-5")-d("2")})():Math.abs(A-O)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>p+.5&&e.unseated.push(W)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((G,_)=>G+_.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ye(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,y=ce(r,i,d,a),h=[...y.values()],l=d.left-Math.floor(d.left),b=d.top-Math.floor(d.top),$=ae(l,b),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:b},B=ht();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(A,j,F)=>{const Z=[A];for(let z=1;z<=(yt(s,j)??0);z++)Z.push({...A,t:A.t+F*u("4")*z,b:A.b+F*u("4")*z});return Z},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(A=>{const j=A.parentElement,F=ft(j,d),Z=getComputedStyle(j);I.set(A.dataset.node,F.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const D=r.nodes,G=A=>y.get(D[A].id),_=[],V=A=>qt(r.edges[A].kind,o);r.edges.forEach((A,j)=>{const F=n.routes[j],Z=y.get(A.from),z=y.get(A.to),Y=V(j);let p=[];const k=A.label,S=k?e(k,"label"):0,g=k?16*jt(k):16,m=u("4");if(F==="down"||F==="up"){const E=Math.max(Z.rect.l,z.rect.l),L=Math.min(Z.rect.r,z.rect.r),T=r.edges.map((R,K)=>({o:R,j:K})).filter(({o:R,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(R.from===A.from&&R.to===A.to||R.from===A.to&&R.to===A.from)),H=T.findIndex(R=>R.j===j),P=T.length<2?.5:T.length===2?H===0?.25:.75:(H+1)/(T.length+1),U=$.x(E+(L-E)*P,Y);if(p=F==="down"?[lt(Z,"bottom",U),lt(z,"top",U)]:[lt(Z,"top",U),lt(z,"bottom",U)],k){let R=Math.min(p[0].y,p[1].y),K=Math.max(p[0].y,p[1].y);F==="down"?K-=o.head:R+=o.head;const et=[...i.querySelectorAll(`.${a}-group`)].map(X=>ft(X,d));let nt=[[R,K]];for(const X of et)for(const st of[X.t,X.b])nt=nt.flatMap(([rt,ct])=>st>rt+1&&stet.some(rt=>(X+st)/2>rt.t&&(X+st)/2rt.l&&U1){const X=nt.filter(([rt,ct])=>!J(rt,ct));[R,K]=(X.length?X:nt).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const ot=[1/2,1/3,2/3].map(X=>{const st=R+(K-R)*X;return{l:U-S/2-u("1"),r:U+S/2+u("1"),t:st-g/2,b:st+g/2}});_.push({k:j,cands:ot,on:!0,card:F==="down"?A.to:A.from})}}else if(F==="trunk"||F==="rail"){const E=$.x(Math.max(Z.rect.l,F==="rail"?z.rect.l:Z.rect.l)+u(F==="trunk"?"8":"3"),Y),L=lt(Z,"bottom",E);if(F==="rail"){if(p=[L,lt(z,"top",E)],k){const T=z.rect.t-u("6");_.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},A.to,-1),on:!1,card:A.to})}}else{const T=$.x(z.rect.l+u("6"),Y),H=$.y(z.rect.t-m,Y);p=[L,{x:E,y:H},{x:T,y:H},lt(z,"top",T)],k&&_.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:H-g/2,b:H+g/2},A.to,-1),on:!1,card:A.to})}}else{const E=Math.min(I.get(A.from)??c,I.get(A.to)??c),L=$.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),Y),T=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[j],Y),H=lt(Z,"right",T),P=$.x(z.rect.r-u("6"),Y),U=F==="end-down",R=$.y(U?z.rect.t-m:z.rect.b+m,Y);p=[H,{x:L,y:H.y},{x:L,y:R},{x:P,y:R},lt(z,U?"top":"bottom",P)];const K=U?A.to:D[z.i+1]?.id??A.to;k&&_.push({k:j,cands:M({l:P-u("2-5")-S,r:P-u("2-5"),t:R-g/2,b:R+g/2},K,U?-1:1),on:!1,card:K})}const w=re(p,Y,$);v.lines.push({i:j,from:A.from,to:A.to,kind:A.kind,pts:w,tip:w[w.length-1],dir:zt(w),width:Y})}),v.crossings=Ot(v.lines),v.through=Ft(v.lines,h,r),v.outside=me(v.lines,c,f,o);const{obstacles:q}=he(i,d,a,0);q.heads=v.lines.map(A=>de(A,o));const W=[],O={l:0,t:0,r:c,b:f};for(const A of _){const j=z=>{const Y=oe(z,u("1"));return z.lO.r+.5||z.tO.b+.5||h.some(p=>se(Y,p))||W.some(p=>ut(Y,p))||q.heads.some(p=>ut(Y,p))||q.rects.some(p=>ut(Y,p))||v.lines.some(p=>p.i!==A.k&&pt(p.pts).some(([k,S])=>ut(Y,fe(k,S,p.width))))},F=A.cands.find(z=>!j(z));F||(B[A.card]=(B[A.card]??0)+1,v.unseated.push(A.k));const Z=F?ue(F,l,b,z=>!j(z)):A.cands[0];W.push(Z),v.labels.push({i:A.k,text:r.edges[A.k].label,box:Z,on:A.on})}return{geo:v,grow:B}}function dn(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...M})),h=y[y.length-1];h.x-=o.x*u,h.y-=o.y*u;const l=e.tip.x-o.x*i,b=e.tip.y-o.y*i,$=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=it(e.kind),B=a?``:``,C=e.dot?``:"";return`${B}${C}`}function be(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const y=d.map(h=>{const l=e.lines[h.top],b=e.lines[h.under],$=l.width/2+n.cut,c=b.width/2+1;return h.underVertical?``:``}).join("");a+=`${y}`}return{defs:a,ids:r}}function $e(t,e,n,s){const{defs:r,ids:o}=be(t,e,n,s),a=e.lifelines.map(y=>``).join("")+(e.bars??[]).map(y=>``).join(""),i=e.lines.map((y,h)=>un(t,y,n,o.get(h)??null,y.from===y.to?n.radiusXs:n.radius)).join(""),d=`${r?`${r}`:""}${a}${i}`,u=e.labels.map(y=>`1?' data-lines="2"':""} style="left:${Math.round(y.box.l*100)/100}px;top:${Math.round(y.box.t*100)/100}px;width:${Math.round((y.box.r-y.box.l)*100)/100}px">${y.text.split(` +`).map(it).join("
")}
`).join("");return d+u}function we(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const y=Xe(t),h=tn(u,n),l=en(e,y,h);i?.(l.least);const b=t.clientWidth,$=(()=>{const q=document.activeElement;return q&&u.contains(q)&&q.dataset.node?q.dataset.node:void 0})(),c=q=>mt(e,q)?{...q,stop:q.stop&&e.byId.has(q.stop)?q.stop:e.nodes[0]?.id,keep:void 0}:{...q,stop:q.stop??e.nodes[0]?.id,keep:$&&q.layout!=="drawn"?$:void 0};let f=!1;const v=q=>{if(f=!1,e.type!=="flowchart")return q;o({...q,heights:void 0,words:void 0});const W=ht(),O=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(A=>{const j=A.querySelector(`.${n}-words`);if(!j)return;const F=A.getBoundingClientRect(),Z=p=>{const k={w:p.width+2*y.space("2-5"),h:p.height+2*y.space("2")},S=1-k.w/F.width,g=S>.05?k.h/2/S:k.h*10;return Math.max(y.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},z=j.getBoundingClientRect();let Y=Z(z);if(Y>F.width){const p=m=>(A.style.setProperty("--_ww",`${m}px`),j.getBoundingClientRect()),k=Math.floor(A.clientWidth-2*y.space("2-5"));let S=Math.ceil(z.width),g=z.height;for(;S1;){const T=m+w>>1;p(T).heightF.width&&(f=!0)}),{...q,heights:W,words:Object.keys(O).length?O:void 0}},B=()=>({m:e,tk:y,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(q,W)=>W.map(O=>Mt(e,q.lines.find(A=>A.i===O))).join(", ");if(b>=l.least){const q=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:rn(B(),h)}};let{dd:W,g:O}=q(!1);const A=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!A(O)&&O.unseated.length&&O.unseated.every(j=>O.bounded?.includes(j))){const j=q(!0);!A(j.g)&&!j.g.unseated.length&&({dd:W,g:O}=j)}if(!A(O)&&!O.unseated.length)return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the drawn layout: ${O.crossings.map(j=>`${Mt(e,O.lines[j.top])} over ${Mt(e,O.lines[j.under])}`).join("; ")}`),{dyn:W,geo:O,ink:$e(n,O,y,s),tokens:y,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: a decision would be taller than it is wide`),O.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${O.misfit.join("; ")}`),O.through.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.through)} would pass through a node`),O.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.overlaps)} would lie on one another`),O.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.outside)} would leave the drawing`),O.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: no clean seat for ${O.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:y,least:l.least};const D=Jt(e);let G=ye(B(),h,D,I.grow);for(let q=0;q<6&&Object.keys(G.grow).length;q++){const W=ht(I.grow);for(const[O,A]of Object.entries(G.grow))W[O]=(yt(W,O)??0)+A;I={...I,grow:W},o(I),G=ye(B(),h,D,W)}const _=G.geo;if(_.unseated.length>0||_.through.length>0||_.outside.length>0||D.third){_.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(_.unseated)].map(O=>`"${e.edges[O]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),_.through.length&&a?.(`in the stacked drawing ${M(_,_.through)} would pass through a node, so its lines are not drawn`),_.outside.length&&a?.(`in the stacked drawing ${M(_,_.outside)} would leave the drawing, so its lines are not drawn`),D.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const q={..._,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:q,ink:"",tokens:y,least:l.least}}return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${_.crossings.map(q=>`${Mt(e,_.lines[q.top])} over ${Mt(e,_.lines[q.under])}`).join("; ")}`),{dyn:I,geo:_,ink:$e(n,_,y,s),tokens:y,least:l.least}}function Mt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function hn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const y=Ot(n.lines,i),{defs:h,ids:l}=be(e,{...n,crossings:y},s,r),b=t.querySelector(`.${e}-svg`);if(!b)return;let $=b.querySelector("defs");!$&&h&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),b.insertBefore($,b.firstChild)),$&&($.innerHTML=h),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var pn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function gn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",pn()||yn(t)?"done":"pending")}}var mn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function yn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(mn(t))!==null}catch{return!1}}function ve(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function bn(t,e,n,s=!1,r=!1){const o=s?Lt(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var $n=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],xe=["data-layout","data-measured","data-bare","data-motion","data-first-visit"],wn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ke=t=>t==null||t===!1;function vn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Me(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?xe:$n;for(const a of s)ke(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,y=new Map(String(i??"").split(";").map(h=>{const l=h.indexOf(":");return[h.slice(0,l).trim(),h.slice(l+1).trim()]}).filter(([h])=>h));for(const[h,l]of y)u.getPropertyValue(h).trim()!==l&&u.setProperty(h,l);for(const h of wn)y.has(h)||u.removeProperty(h);continue}if(n&&!xe.includes(a))continue;if(ke(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,b,$){return{prefix:n,base:l,hasSource:b.source!==void 0&&b.source!==null&&b.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(l,b,$,c){var f=function(v){return''+it(v)+""};return{source:it(String(b.source||"")),summary:it(String(b.summary||"")),hint:Wt(l).map(function(v){return""+v.keys.map(f).join(" ")+" "+it(v.words)+""}).join(""),toggle:'"}}function a(l,b,$){var c=_t(l),f=ne(c,{},r(b,l,$)),v=Bt(f,o(c,l,b,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,b,$,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=_t(b);if(!$||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(b,f,c),C=document.createElement("div");C.innerHTML=B.open+"";var M=C.firstChild;i.forEach(function(N){l.removeAttribute(N)}),d.forEach(function(N){l.style.removeProperty(N)});for(var I=0;I :not(script[data-diagram])").forEach(function(N){N.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var G=r(f,b,c),_={},V=null,q=null,W=null,O=null,A=Object.create(null),j=function(N){A[N]||(A[N]=1,console.warn("Basalt diagram: "+N))},F=function(N){Me(l,ne(v,N,G))},Z=l.querySelector(".diagram-ink"),z=l.querySelector(".diagram-toggle"),Y=!c&&v.motion.animated&&typeof e.diagramMotion=="function",p=null,k=null,S=function(){Y&&ve(l)};function g(){hn(l,n,V&&V.geo,V&&V.tokens,f,q||O||W),E()}var m=null,w=!c&&matchMedia("(hover: none), (pointer: coarse)").matches;function E(){var N=w&&!c&&Z&&Z.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(w&&!c)),N&&!m){var Q=l.querySelector(":scope > .diagram-foot");if(!Q)return;m=document.createElement("button"),m.type="button",m.className="btn diagram-clear",m.setAttribute("data-variant","secondary"),m.setAttribute("data-size","sm"),m.innerHTML="Clear highlight",m.addEventListener("click",function(){O&&(O=null,g())}),Q.appendChild(m)}else!N&&m&&(m.remove(),m=null);m&&(O?m.removeAttribute("aria-disabled"):m.setAttribute("aria-disabled","true"))}function L(N){if(!N.defaultPrevented){var Q=Ce(l,n,N,O);Q!==void 0&&(S(),w=!0,O=Q,g())}}function T(){z&&(z.setAttribute("aria-expanded",String(!!_.open)),z.firstElementChild.textContent=_.open?"Hide the list":"View as list")}function H(){V=(c?c.measure:we)(l,v,n,f,_,F,j),_=V.dyn,F(_),T();var N=l.querySelector(":scope > .diagram-hint");if(N){var Q=Wt(v,_.layout==="drawn").map(function(St){return""+St.keys.map(function(kn){return''+it(kn)+""}).join(" ")+" "+it(St.words)+""}).join("");N.innerHTML!==Q&&(N.innerHTML=Q)}mt(v,_)||(W=O=null);var dt=Z&&V.ink!==k;dt&&(Z.innerHTML=V.ink,k=V.ink),g(),Y&&V.tokens&&(gn(l,!!(V.geo&&V.geo.lines.length)),dt&&p&&p.redrawn()),c&&c.onMeasured&&V.tokens&&c.onMeasured(V,l)}function P(N){_=N,F(_)}function U(N){var Q=_.stop;_=Object.assign({},_,{stop:N}),xn(l,n,Q,N)}var R=function(N){var Q=N&&N.closest?N.closest(".diagram-node"):null;return Q&&l.contains(Q)?Q:null};function K(N){var Q=R(N.target);if(!(!Q||N.defaultPrevented)){if(S(),N.key==="Escape"){!c&&(q||W||O)&&(N.preventDefault(),q=W=O=null,g());return}if(mt(v,_)){var dt=bn(v,Q.getAttribute("data-node"),N.key,_.layout==="drawn",getComputedStyle(Q).direction==="rtl");if(dt){N.preventDefault(),U(dt);var St=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');St&&St.focus()}}}}function et(N){var Q=R(N.target);if(Q){S();var dt=Q.getAttribute("data-node");q=Q.matches(":focus-visible")?dt:null,mt(v,_)&&_.stop!==dt&&U(dt),g()}}function nt(N){var Q=R(N.target);Q&&(R(N.relatedTarget)||(q=null),_.keep===Q.getAttribute("data-node")&&P(Object.assign({},_,{keep:void 0})),g())}function J(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var Q=R(N.target);Q&&S();var dt=Q&&mt(v,_)?Q.getAttribute("data-node"):null;dt!==W&&(W=dt,g())}}function ot(){W&&(W=null,g())}function X(){S(),P(Object.assign({},_,{open:!_.open,autoOpen:void 0})),T()}l.addEventListener("keydown",K),l.addEventListener("focusin",et),l.addEventListener("focusout",nt),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",ot),l.addEventListener("click",L),z&&z.addEventListener("click",X),H();var st=l.clientWidth,rt=0,ct=!0,bt=new ResizeObserver(function(){Math.abs(l.clientWidth-st)<.5||(st=l.clientWidth,cancelAnimationFrame(rt),rt=requestAnimationFrame(H))});bt.observe(l),document.fonts&&document.fonts.ready.then(function(){ct&&H()});var xt=matchMedia("(forced-colors: active)"),Se=v.nodes.some(function(N){return N.mark});Se&&xt.addEventListener("change",H),Y&&(p=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},b));var Ee=!c&&b.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,b,{model:v,settle:S,animated:Y}):null;l.__diagram={stop:function(){Ee&&Ee.destroy(),ct=!1,bt.disconnect(),cancelAnimationFrame(rt),Se&&xt.removeEventListener("change",H),p&&p.destroy(),l.removeEventListener("keydown",K),l.removeEventListener("focusin",et),l.removeEventListener("focusout",nt),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",ot),l.removeEventListener("click",L),m&&m.remove(),z&&z.removeEventListener("click",X)},layout:H,key:y(b),send:p&&p.sendValue?p.sendValue:null}}function y(l){try{return JSON.stringify(l,function(b,$){return b==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function h(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var b=l.querySelector(":scope > script[data-diagram]");if(b)try{u(l,JSON.parse(b.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:_t,figureKey:ze,figureList:Ve,hintEntries:Wt,toHtml:Bt,escapeHtml:it,settleEntrance:ve,measureFigure:we},t.diagram=function(l,b){var $=l.__diagram,c=$&&$.send?y(b):null;if(c!==null&&c===$.key){$.send(b.packet?b.packet.send:void 0);return}u(l,b)},e.step(62,"wireDiagrams",h)})(window.Basalt)})(); diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index a5da9297..32b77884 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -582,6 +582,22 @@ function working(m: Model, n: MNode): string { return ` ${word} during ${bars.map((b) => (b.from === b.to ? `message ${b.from}` : `messages ${b.from} to ${b.to}`)).join(" and ")}.`; } +/** + * What a tap does (DECISIONS 306, 1.5): a `click` from a touch or a pen pointer on a card traces it, on the same card or the drawing's ground clears it. + * A linked card follows its link and is never traced. Returns the trace to show, or undefined where the tap changes nothing. + */ +export function tapTrace(fig: HTMLElement, P: string, event: MouseEvent, current: string | null): string | null | undefined { + const type = (event as PointerEvent).pointerType; + if (type !== "touch" && type !== "pen") return undefined; + const drawing = fig.querySelector(`.${P}-drawing`); + const target = event.target as Element | null; + if (!drawing || !target || !drawing.contains(target) || !fig.querySelector(`.${P}-edge`)) return undefined; + const node = target.closest(`.${P}-node`); + if (node?.hasAttribute("href")) return undefined; + if (!node) return null; + return node.dataset.node === current ? null : node.dataset.node ?? null; +} + /** The noun the key hint and the keys sentence use for one stop. */ function stopNoun(m: Model): string { return m.type === "architecture" ? "a part" : m.type === "sequence" ? "a participant" : m.type === "schema" ? "a table" : "a step"; @@ -1237,6 +1253,8 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { }, drawingChildren(ctx, m, dyn), h("div", { class: `${P}-ink`, "aria-hidden": "true" }), h("span", { class: `${P}-ruler`, "aria-hidden": "true" })), keyTree(P, m), h("p", { class: `${P}-hint`, "data-kbd-hint": "", "aria-hidden": "true" }, { slot: "hint" }), + // On touch, where lines are drawn, a line in the hint's seat and type says how to trace (DECISIONS 306, 1.5); the stylesheet shows it only then. + hasStops(m, dyn) && m.type !== "sequence" || (drawn && m.type === "sequence") ? h("p", { class: `${P}-tap-hint`, "aria-hidden": "true" }, `Tap ${stopNoun(m)} to highlight its lines. Tap it again to clear.`) : null, h("div", { class: `${P}-foot` }, { slot: "toggle" }), h("div", { id: ids.list, class: `${P}-list`, hidden: !dyn.open }, listTree(P, m)), h("span", { id: ids.keys, class: o.hiddenClass }, o.viewer ? `${keysSentence(m, drawn)} ${o.viewer}` : keysSentence(m, drawn)), diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 73abb8b4..75c50be4 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -4,7 +4,7 @@ import { Kbd } from "./kbd"; import { useShortcutsVisible } from "./keyboard"; import { inLevel, usePanelLevel } from "./layers"; import { - applyTrace, buildModel, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, + applyTrace, buildModel, tapTrace, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, } from "./diagram-core"; import type { DiagramLegend, DiagramMotion, DiagramSpec, Dyn, Measured, Model, VNode } from "./diagram-core"; import type { MotionController } from "./diagram-motion-core"; @@ -147,6 +147,9 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: modelRef.current = model; const [focusTrace, setFocusTrace] = React.useState(null); const [hoverTrace, setHoverTrace] = React.useState(null); + // A trace on touch (DECISIONS 306, 1.5), the third source after keyboard focus. "On touch" is the media's, or a figure that has taken a touch tap. + const [touchTrace, setTouchTrace] = React.useState(null); + const [touched, setTouched] = React.useState(false); const options = React.useMemo(() => ({ prefix: P, base, level, hasSource: source !== undefined && source !== null, hiddenClass: "basalt-visually-hidden", viewer: viewer?.keys }), [base, level, source, viewer]); // Development only: a bundler that sets NODE_ENV to production drops this block, strings included. @@ -167,7 +170,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: if (JSON.stringify(dynRef.current) !== JSON.stringify(result.dyn)) { dynRef.current = result.dyn; setDyn(result.dyn); } setInk(result.ink); // A layout with no stops traces nothing: a pointer resting on a node as the figure narrows into one leaves no trace behind. - if (!hasStops(model, result.dyn)) setHoverTrace(null); + if (!hasStops(model, result.dyn)) { setHoverTrace(null); setTouchTrace(null); } // A figure hidden (the viewer's list is open) was not measured: the viewer keeps the drawing's size and place it had. if (viewer && result.tokens) viewer.onMeasured(result, fig); }, [model, base, options, component, viewer]); @@ -195,7 +198,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: return () => { live = false; observer.disconnect(); cancelAnimationFrame(frame); if (marks) forced.removeEventListener("change", measure); }; }, [measure, model]); - const trace = focusTrace ?? hoverTrace; + const trace = focusTrace ?? touchTrace ?? hoverTrace; React.useLayoutEffect(() => { const fig = figRef.current; if (fig) applyTrace(fig, P, measured.current?.geo ?? null, measured.current?.tokens ?? null, base, trace); @@ -246,7 +249,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // The viewer (DECISIONS 310): "Expand" exists once script runs. Its module loads at the button's first hover, focus or touch; a press before it has // arrived makes the button busy until the dialog opens. While the viewer is open the page's figure holds its loops and settles a running entrance (9.7). const [scripted, setScripted] = React.useState(false); - React.useEffect(() => { if (!viewer) setScripted(true); }, [viewer]); + const [onTouch, setOnTouch] = React.useState(false); + React.useEffect(() => { if (!viewer) { setScripted(true); setOnTouch(matchMedia("(hover: none), (pointer: coarse)").matches); } }, [viewer]); const expandRef = React.useRef(null); const [viewerModule, setViewerModule] = React.useState(null); const [viewerOpen, setViewerOpen] = React.useState(false); @@ -288,7 +292,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: if (!node || event.defaultPrevented) return; settle(); // In the viewer Esc always closes the dialog, traced or not (9.8): the figure leaves it to the dialog. - if (event.key === "Escape") { if (!viewer && (focusTrace || hoverTrace)) { event.preventDefault(); setFocusTrace(null); setHoverTrace(null); } return; } + if (event.key === "Escape") { if (!viewer && (focusTrace || hoverTrace || touchTrace)) { event.preventDefault(); setFocusTrace(null); setHoverTrace(null); setTouchTrace(null); } return; } if (!stops) return; const to = keyTarget(model, node.dataset.node!, event.key, dynRef.current.layout === "drawn", getComputedStyle(node).direction === "rtl"); if (!to) return; @@ -324,6 +328,17 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: setHoverTrace(node && hasStops(model, dynRef.current) ? node.dataset.node! : null); }, onPointerLeave: (event: React.PointerEvent) => { onPointerLeave?.(event); setHoverTrace(null); }, + "data-touch": !viewer && (onTouch || touched) ? "" : undefined, + onClick: (event: React.MouseEvent) => { + props.onClick?.(event as React.MouseEvent); + const fig = figRef.current; + if (!fig || event.defaultPrevented) return; + const next = tapTrace(fig, P, event.nativeEvent, touchTrace); + if (next === undefined) return; + settle(); + setTouched(true); + setTouchTrace(next); + }, }; const toggle = ( @@ -373,6 +388,12 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: ) : null} ) : null; - const foot = <>{toggle}{expand}{Foot && controller ? : null}; + // "Clear highlight" (1.5): last in the foot, mounted whenever the figure is on touch and can be traced, aria-disabled until a trace is up. + const clear = !viewer && (onTouch || touched) && ink ? ( + + ) : null; + const foot = <>{toggle}{expand}{Foot && controller ? : null}{clear}; return toReact(tree, { source, summary, hint, toggle: foot }, inkHtml, root) as React.ReactElement; } diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index cf41795e..f377c0dd 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4833,6 +4833,13 @@ .basalt-diagram-hint { display: flex; flex-wrap: wrap; gap: var(--basalt-space-1) var(--basalt-space-4); margin: 0; color: var(--basalt-text-tertiary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); } .basalt-diagram-hint > span { display: inline-flex; align-items: center; gap: var(--basalt-space-1); } + /* On touch (DECISIONS 306, 1.5), where lines are drawn, the hint's seat says how to trace; nowhere else. */ + .basalt-diagram-tap-hint { display: none; margin: 0; color: var(--basalt-text-tertiary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); } + .basalt-diagram[data-touch][data-layout="drawn"] > .basalt-diagram-tap-hint, .basalt-diagram[data-touch][data-layout="stacked"]:not([data-bare], [data-type="sequence"], [data-type="schema"]) > .basalt-diagram-tap-hint { display: block; } + .basalt-diagram[data-touch] > .basalt-diagram-hint { display: none; } + /* A card that answers a tap is at least size-tap-min tall on touch. */ + .basalt-diagram[data-touch] .basalt-diagram-node { min-height: var(--basalt-size-tap-min); } + @media (pointer: coarse) { .basalt-diagram-clear { min-height: var(--basalt-size-tap-min); } } .basalt-diagram[data-layout="stacked"]:is([data-type="sequence"], [data-type="schema"]) .basalt-diagram-hint { display: none; } /* A stack drawn with no lines (1.13) is dressed as where scripting is off: no line in the key and no key hint (the list is open by script). */ .basalt-diagram[data-bare] :is(.basalt-diagram-entry[data-line], .basalt-diagram-hint) { display: none; } @@ -4970,7 +4977,7 @@ (DECISIONS 292, 2.6; every focal node, with a mark or without, DECISIONS 298). */ @media print { .basalt-diagram-svg, .basalt-diagram-swatch, .basalt-diagram-arrow, .basalt-diagram-mark, .basalt-diagram-node[data-focal] { -webkit-print-color-adjust: exact; print-color-adjust: exact; } - .basalt-diagram-hint { display: none; } + .basalt-diagram-hint, .basalt-diagram-tap-hint, .basalt-diagram-clear { display: none !important; } /* A figure prints untraced (DECISIONS 306, 1.7): every line, head and label in its resting ink, over a trace, a touch trace or a quiet run. */ .basalt-diagram .basalt-diagram-edge :is(.basalt-diagram-line, .basalt-diagram-tip[data-open]) { stroke: var(--basalt-diagram-edge) !important; } .basalt-diagram .basalt-diagram-edge .basalt-diagram-line[data-kind="main"] { stroke: var(--basalt-diagram-edge-main) !important; } @@ -5088,7 +5095,7 @@ .basalt-diagram-layer:dir(rtl) { transform-origin: 100% 0; } /* The viewer's figure shows its drawing alone: the dialog holds its title, its key, its hint and its controls. */ .basalt-diagram[data-viewer] { gap: 0; } - .basalt-diagram[data-viewer] > :is(.basalt-diagram-head, .basalt-diagram-key, .basalt-diagram-hint, .basalt-diagram-foot, .basalt-diagram-list, .basalt-diagram-summary) { display: none; } + .basalt-diagram[data-viewer] > :is(.basalt-diagram-head, .basalt-diagram-key, .basalt-diagram-hint, .basalt-diagram-tap-hint, .basalt-diagram-foot, .basalt-diagram-list, .basalt-diagram-summary) { display: none; } .basalt-diagram-viewer-list { box-sizing: border-box; max-width: calc(var(--basalt-size-page-width) - 2 * var(--basalt-size-gutter) + 2 * var(--_pad)); padding: var(--_pad); } .basalt-diagram-viewer-foot { display: flex; flex-direction: column; gap: var(--basalt-space-3); padding-block-start: var(--basalt-space-3); } .basalt-diagram-viewer-key { --_ground: var(--_surface, var(--basalt-surface-overlay)); } diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 73a74beb..4094c7b4 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -4,7 +4,7 @@ and draw the same pixels. compose.mjs runs `Basalt._.diagramMarkup` at build time and writes each figure's words into the page, so it reads before any script runs; this script then measures it, draws its lines and labels, and wires the keys, the trace and the list. Source: tools/html-skill/src/modules/diagram.js (do not edit the copy in the skill folder). */ -import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, moveStop, settleEntrance, syncAttributes, toHtml } from "../../../../packages/react/src/diagram-core.ts"; +import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, moveStop, settleEntrance, syncAttributes, toHtml } from "../../../../packages/react/src/diagram-core.ts"; (function (B) { 'use strict'; @@ -72,7 +72,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis var opts = options(base, spec, viewer); var state = {}; var measured = null; - var focusTrace = null, hoverTrace = null; + var focusTrace = null, hoverTrace = null, touchTrace = null; var warned = Object.create(null); var warn = function (m) { if (!warned[m]) { warned[m] = 1; console.warn('Basalt diagram: ' + m); } }; var apply = function (d) { syncAttributes(figure, figureTree(model, d, opts)); }; @@ -84,7 +84,36 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis var motion = null, drawn = null; var settle = function () { if (animated) settleEntrance(figure); }; - function retrace() { applyTrace(figure, P, measured && measured.geo, measured && measured.tokens, base, focusTrace || hoverTrace); } + function retrace() { applyTrace(figure, P, measured && measured.geo, measured && measured.tokens, base, focusTrace || touchTrace || hoverTrace); syncClear(); } + // A trace on touch (DECISIONS 306, 1.5): "Clear highlight", last in the foot, is mounted whenever the figure is on touch and drawn with lines, and + // aria-disabled until a trace is up. "On touch" is the media's, or a figure that has taken a touch tap. + var clearBtn = null, touched = !viewer && matchMedia('(hover: none), (pointer: coarse)').matches; + function syncClear() { + var want = touched && !viewer && ink && ink.innerHTML !== ''; + figure.toggleAttribute('data-touch', Boolean(touched && !viewer)); + if (want && !clearBtn) { + var foot = figure.querySelector(':scope > .diagram-foot'); + if (!foot) return; + clearBtn = document.createElement('button'); + clearBtn.type = 'button'; + clearBtn.className = 'btn diagram-clear'; + clearBtn.setAttribute('data-variant', 'secondary'); + clearBtn.setAttribute('data-size', 'sm'); + clearBtn.innerHTML = 'Clear highlight'; + clearBtn.addEventListener('click', function () { if (touchTrace) { touchTrace = null; retrace(); } }); + foot.appendChild(clearBtn); + } else if (!want && clearBtn) { clearBtn.remove(); clearBtn = null; } + if (clearBtn) { if (touchTrace) clearBtn.removeAttribute('aria-disabled'); else clearBtn.setAttribute('aria-disabled', 'true'); } + } + function onTap(event) { + if (event.defaultPrevented) return; + var next = tapTrace(figure, P, event, touchTrace); + if (next === undefined) return; + settle(); + touched = true; + touchTrace = next; + retrace(); + } // The toggle's words and state follow the list's (a stack drawn with no lines opens it). function syncToggle() { if (!toggle) return; @@ -101,7 +130,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis var hintEl = figure.querySelector(':scope > .diagram-hint'); if (hintEl) { var hintHtml = hintEntries(model, state.layout === 'drawn').map(function (e) { return '' + e.keys.map(function (k) { return '' + escapeHtml(k) + ''; }).join(' ') + ' ' + escapeHtml(e.words) + ''; }).join(''); if (hintEl.innerHTML !== hintHtml) hintEl.innerHTML = hintHtml; } // A layout with no stops traces nothing: a pointer resting on a node as the figure narrows into one leaves no trace behind. - if (!hasStops(model, state)) hoverTrace = null; + if (!hasStops(model, state)) hoverTrace = touchTrace = null; var fresh = ink && measured.ink !== drawn; if (fresh) { ink.innerHTML = measured.ink; drawn = measured.ink; } retrace(); @@ -119,7 +148,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis if (!node || event.defaultPrevented) return; settle(); // In the viewer Esc always closes the dialog, traced or not (DECISIONS 310, 9.8). - if (event.key === 'Escape') { if (!viewer && (focusTrace || hoverTrace)) { event.preventDefault(); focusTrace = hoverTrace = null; retrace(); } return; } + if (event.key === 'Escape') { if (!viewer && (focusTrace || hoverTrace || touchTrace)) { event.preventDefault(); focusTrace = hoverTrace = touchTrace = null; retrace(); } return; } if (!hasStops(model, state)) return; var to = keyTarget(model, node.getAttribute('data-node'), event.key, state.layout === 'drawn', getComputedStyle(node).direction === 'rtl'); if (!to) return; @@ -164,6 +193,7 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis figure.addEventListener('focusout', onFocusOut); figure.addEventListener('pointerover', onOver); figure.addEventListener('pointerleave', onLeave); + figure.addEventListener('click', onTap); if (toggle) toggle.addEventListener('click', onToggle); layout(); var width = figure.clientWidth, frame = 0, live = true; @@ -189,7 +219,8 @@ import { applyTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureLis if (marks) forced.removeEventListener('change', layout); if (motion) motion.destroy(); figure.removeEventListener('keydown', onKey); figure.removeEventListener('focusin', onFocusIn); figure.removeEventListener('focusout', onFocusOut); - figure.removeEventListener('pointerover', onOver); figure.removeEventListener('pointerleave', onLeave); + figure.removeEventListener('pointerover', onOver); figure.removeEventListener('pointerleave', onLeave); figure.removeEventListener('click', onTap); + if (clearBtn) clearBtn.remove(); if (toggle) toggle.removeEventListener('click', onToggle); }, layout: layout, From d58e50b2fee5e7bf4e42961229c9675001d58d6f Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:59:47 -0600 Subject: [PATCH 19/62] Right to left (DECISIONS 306, 1.7) No prop: a figure follows its computed direction, read as it is measured. The model is mirrored (column 1 at the right, a frame's span with it, a named left or right side swapped), and the engine lays it out on a left-to-right drawing, so every route, seat and lane is the one a left-to-right figure gets; what the drawing holds is set right to left again. A self-call and a nested bar take their logical sides. The foreign-key row's arrow and the stacked sequence's inline arrows turn; identifiers are isolated left to right as runs. Arrow keys stay physical (the table is the mirrored model's). The keys test's right-to-left half now passes (6/6). Not as written: the stack is not mirrored, because its rail and trunk are laid out on the left; it is drawn, with every line, where it had none before. Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 10 +++--- packages/react/src/diagram-core.ts | 38 +++++++++++++++------ packages/react/src/diagram-figure.tsx | 11 ++++-- packages/react/src/styles/components.css | 9 +++++ tools/html-skill/src/modules/diagram.js | 5 +-- 6 files changed, 53 insertions(+), 22 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index fc597ece..693a3fbf 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index f2162103..442afc63 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,6 +1,6 @@ -(()=>{var Ae=["top","right","bottom","left"],Le=["main","plain","dashed"],qe=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function _t(t,e={}){const s=e.checks!==!1,r=[],o=p=>{r.push(p)},a=t.legend??{},i={};for(const p of["main","plain","dashed","focal","group","activation"]){const k=at(a[p]);k&&(i[p]=k)}const d=t.stepLabel,u=typeof d=="function"?p=>String(d(p)):typeof d=="string"?(p=>d.replace("{n}",String(p))):p=>`Step ${p}`,y=t.shapeLabels??{},h={terminal:at(y.terminal)??"Start or end",step:at(y.step)??"Step",decision:at(y.decision)??"Decision"},l=t.heading===void 0?3:qe.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),b=(p,k)=>p==null?"plain":Le.includes(p)?p:(o(`"${String(p)}" is not a kind of line (main, plain or dashed): ${k} is drawn plain`),"plain"),$=p=>{if(p!=null){if(Ae.includes(p))return p;o(`"${String(p)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(p,k)=>typeof p=="number"&&Number.isInteger(p)&&p>=1?p:(o(`${k} is ${JSON.stringify(p)}, not a whole number from 1: it is placed at 1`),1),f=[],v=[];let B=[];const C=[],M=[],I=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(I)||o(`"${String(I)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),I==="architecture"||I==="flowchart"){for(const p of t.nodes??[]){const k=I==="flowchart"&&p.shape==="decision"?"decision":I==="flowchart"&&p.shape==="terminal"?"terminal":"box",S=String(p.id??""),g=c(p.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(p.name??""),kind:k==="decision"?void 0:at(p.kind),detail:k==="decision"?void 0:at(p.detail),mono:!!p.detailMono,focal:!!p.focal,col:c(p.col,`the column of ${S}`),row:g,row2:g,branch:!!p.branch,shape:k,group:I==="architecture"?at(p.group):void 0,mark:I==="architecture"?Ct(p.mark):void 0})}if(I==="architecture"){const p=(t.groups??[]).map(m=>({id:String(m.id??""),label:String(m.label??""),parent:at(m.parent)})),k=new Map(p.map(m=>[m.id,m])),S=m=>{if(!m.parent)return 1;const w=k.get(m.parent);return w?w.parent===m.id||w.id===m.id?(o(`the groups "${m.label}" and "${w.label}" are each other's parent`),m.parent=void 0,1):w.parent?(o(`the group "${m.label}" is a third level: groups nest two deep`),m.parent=void 0,1):2:(o(`the group "${m.label}" names the parent "${m.parent}", which is not a group`),m.parent=void 0,1)},g=p.map(S);p.forEach((m,w)=>C.push({...m,depth:g[w],members:f.filter(E=>E.group===m.id).map(E=>E.id),all:[]}));for(const m of C)m.all=[...m.members,...C.filter(w=>w.parent===m.id).flatMap(w=>w.members)];C.sort((m,w)=>m.depth-w.depth)}}else if(I==="data-flow"){B=(t.lanes??[]).map(k=>({id:String(k.id??""),label:String(k.label??"")}));const p=new Map(B.map((k,S)=>[k.id,S+1]));for(const k of t.nodes??[]){const S=String(k.id??""),g=String(k.lane??""),m=p.get(g);m===void 0&&o(`a node (${S}) names the lane "${g}", which is not in lanes`);const w=f.length+1;f.push({id:S,i:f.length,name:String(k.name??""),kind:u(w),detail:at(k.detail),mono:!!k.detailMono,focal:!!k.focal,col:c(k.col,`the column of ${S}`),row:m??1,row2:m??1,branch:!1,shape:"box",lane:m??1,laneLabel:B[(m??1)-1]?.label??g,step:w,mark:Ct(k.mark)})}}else if(I==="sequence"){(t.participants??[]).forEach((g,m)=>{const w=String(g.name??"");f.push({id:String(g.id??""),i:m,name:w,kind:at(g.kind),mono:!1,focal:!!g.focal,col:m+1,row:1,row2:1,branch:!1,shape:"participant",short:at(g.short)??w,mark:Ct(g.mark)})});let p=0;const k=new Map(f.map(g=>[g.id,g.col])),S=(g,m)=>{let w=1/0,E=-1/0;for(const L of g??[]){if(!L||typeof L!="object")continue;if("band"in L){m>0&&o(`the band "${String(L.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(L.band??"")});continue}if("frame"in L){if(m>=2){o("a frame is a third level: frames nest two deep");continue}const et=L.frame==="alt"||L.frame==="loop"||L.frame==="opt"?L.frame:"opt",nt=et==="alt"?L.branches??[]:[{label:L.label,steps:L.steps}];et==="alt"&&nt.length<2&&o("an alt frame has one branch: it needs two or more");const J=String(nt[0]?.label??"");J.length>40&&o(`the frame label "${J}" is over 40 characters`);const ot=M.length;M.push({open:et,label:J,depth:m+1,a:0,b:0}),nt.forEach((X,st)=>{if(st){const xt=String(X.label??"");xt.length>40&&o(`the frame label "${xt}" is over 40 characters`),M.push({otherwise:xt,depth:m+1})}X.steps?.length||o(`a frame or branch ("${String(X.label??"")}") is empty`);const[rt,ct]=S(X.steps??[],m+1);w=Math.min(w,rt),E=Math.max(E,ct);const bt=M[ot];bt.a=Math.min(bt.a||1/0,rt),bt.b=Math.max(bt.b,ct)}),M.push({close:m+1});continue}p++;const T=String(L.label??"");T.includes(` -`)&&o(`message ${p}'s label has a break: a message's second line is its note`);const H=String(L.from??""),P=String(L.to??"");M.push({n:p,from:H,to:P,label:gt(T),note:at(L.note),kind:b(L.kind,`message ${p}`),activate:L.activate===!0||void 0,deactivate:L.deactivate===!0||void 0});const U=k.get(H)??1,R=k.get(P)??1,K=U===R?U===f.length?U-1:U+1:U;w=Math.min(w,U,R,K),E=Math.max(E,U,R,K)}return[w,E]};S(t.steps??[],0);for(const g of M)"open"in g&&!Number.isFinite(g.a)&&(g.a=1,g.b=Math.max(1,f.length))}else if(I==="schema")for(const p of t.tables??[]){const k=String(p.name??""),[S,g]=Array.isArray(p.row)?p.row:[p.row,p.row],m=c(S,`the row of ${k}`),w=Math.max(m,c(g,`the last row of ${k}`)),E=p.more===void 0||p.more===null?void 0:Number.isInteger(p.more)&&p.more>0?p.more:(o(`${k}'s "more" is ${JSON.stringify(p.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:k,i:f.length,name:k,mono:!0,focal:!!p.focal,col:c(p.col,`the column of ${k}`),row:m,row2:w,branch:!1,shape:"table",more:E,columns:(p.columns??[]).map(L=>({name:String(L.name??""),type:at(L.type),key:L.key==="PK"||L.key==="FK"?L.key:(L.key!==void 0&&L.key!==null&&o(`${k}.${String(L.name)}'s key is "${String(L.key)}", not PK or FK: it is left out`),void 0)}))})}((I==="schema"?t.tables:I==="sequence"?t.participants:t.nodes)??[]).forEach((p,k)=>{if(!p||p.href===void 0||p.href===null)return;const S=String(p.href);if(I==="sequence"){o(`${f[k]?.id}: a participant cannot be a link (href)`);return}if(!S){o(`${f[k]?.id}'s href is empty`);return}const g=f[k];g&&(g.href=S,g.blank=p.target==="_blank")});const G=new Map;for(const p of f)p.id?G.has(p.id)&&o(`the id "${p.id}" is used twice`):o("a node has no id"),G.set(p.id,p);if(I==="schema")(t.tables??[]).forEach(p=>(p.columns??[]).forEach((k,S)=>{const g=at(k.references);if(!g)return;const[m,w]=g.split("."),E=G.get(m??""),L=E?.columns?.findIndex(H=>H.name===w)??-1;if(!E||L<0){o(`${String(p.name)}.${String(k.name)} references ${g}, which is not a shown column`);return}const T=G.get(String(p.name??""));T.columns[S].ref={table:m,column:w,row:L},v.push({i:v.length,from:T.id,to:m,kind:"plain",fromRow:S,toRow:L,fk:!0})}));else if(I!=="sequence")for(const p of t.edges??[]){const k=String(p.from??""),S=String(p.to??"");if(!G.has(k)||!G.has(S)){o(`a line names ${G.has(k)?S:k}, which is not a node`);continue}const g=at(p.label),m=g?.split(` -`)??[];m.length>2&&o(`the label "${gt(g)}" has more than one break: a label is two lines at most`),m.some(w=>w.length>Nt)&&o(`a line of the label "${gt(g)}" is over ${Nt} characters: longer words belong in the node or the summary`),v.push({i:v.length,from:k,to:S,kind:b(p.kind,`the line from ${k} to ${S}`),label:g,fromSide:$(p.fromSide),toSide:$(p.toSide),flow:I!=="flowchart"&&p.flow===!0?!0:void 0})}else for(const p of M)"n"in p&&(!G.has(p.from)||!G.has(p.to))&&o(`message ${p.n} names ${G.has(p.from)?p.to:p.from}, which is not a participant`);if(s&&I!=="sequence"){const p=new Map;for(const k of f)for(let S=k.row;S<=k.row2;S++){const g=`${k.col}:${S}`;p.has(g)&&o(`${k.id} and ${p.get(g)} share the cell at column ${k.col}, row ${S}`),p.set(g,k.id)}}if(s){for(const k of C){const S=k.all.map(w=>G.get(w));if(!S.length)continue;const g={c1:Math.min(...S.map(w=>w.col)),c2:Math.max(...S.map(w=>w.col)),r1:Math.min(...S.map(w=>w.row)),r2:Math.max(...S.map(w=>w.row2))};for(const w of f)!k.all.includes(w.id)&&w.col>=g.c1&&w.col<=g.c2&&w.row>=g.r1&&w.row<=g.r2&&o(`${w.id} is inside the box of the group "${k.label}" but not a member`);const m=S.map(w=>w.i);Math.max(...m)-Math.min(...m)+1!==m.length&&o(`the members of the group "${k.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const k of f)k.group&&!C.some(S=>S.id===k.group)&&o(`${k.id} names the group "${k.group}", which is not in groups`);f.filter(k=>k.focal).length>1&&o("more than one node is focal: a diagram has one at most");const p=new Set(I==="sequence"?M.flatMap(k=>"n"in k?[k.kind]:[]):v.map(k=>k.kind));p.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),p.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(k=>k.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const _=I==="architecture"||I==="data-flow",V=p=>Array.isArray(p)&&p.length>1?p.map(String):void 0,q=_&&t.packet&&typeof t.packet=="object"?t.packet:void 0,W=q&&V(q.path),O={animated:t.motion==="animated",pulse:_?V(t.pulse):void 0,packet:W?{path:W,repeat:q.repeat===!0,send:q.send}:void 0,run:I==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const p of f){const k=p.mark?.says;if(!k?.length)continue;const S=[p.name,p.kind,p.detail,p.laneLabel].filter(Boolean).join(" ").toLowerCase();k.some(g=>S.includes(g.toLowerCase()))||o(`${p.id}'s mark stands for ${k.join(" or ")}, and none of its words say so`)}const A=[];if(I==="sequence"){const p=new Map,k=new Map;for(const S of M)"n"in S&&(k.set(S.from,S.n),k.set(S.to,S.n));for(const S of M)if("n"in S){if(S.activate){const g=p.get(S.to)??[];if(g.length>=3)o(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const m={who:S.to,from:S.n,to:S.n,depth:g.length+1};g.push(m),A.push(m),p.set(S.to,g)}}if(S.deactivate){const m=p.get(S.from)?.pop();m?m.to=S.n:o(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,g]of p)for(const m of g)m.to=Math.max(m.from,k.get(S)??m.from)}const j=t.frameLabels??{},F={opt:at(j.opt)??"Only if",loop:at(j.loop)??"Repeats",alt:at(j.alt)??"One of these",else:at(j.else)??"Otherwise"},Z=Math.max(1,...f.map(p=>p.col)),z=I==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(p=>p.row2)),Y={type:I,title:String(t.title??""),heading:l,legend:i,nodes:f,byId:G,edges:v,groups:C,lanes:B,steps:M,bars:A,frameWords:F,cols:Z,rows:z,shapeLabels:h,stepWord:u,warnings:r,motion:O,memo:new Map};return s&&f.length>1&&!Lt(Y)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),Y}function Ct(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ht=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +(()=>{var Ae=["top","right","bottom","left"],Le=["main","plain","dashed"],qe=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function _t(t,e={}){const s=e.checks!==!1,r=[],o=h=>{r.push(h)},a=t.legend??{},i={};for(const h of["main","plain","dashed","focal","group","activation"]){const $=at(a[h]);$&&(i[h]=$)}const d=t.stepLabel,u=typeof d=="function"?h=>String(d(h)):typeof d=="string"?(h=>d.replace("{n}",String(h))):h=>`Step ${h}`,m=t.shapeLabels??{},p={terminal:at(m.terminal)??"Start or end",step:at(m.step)??"Step",decision:at(m.decision)??"Decision"},l=t.heading===void 0?3:qe.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),b=(h,$)=>h==null?"plain":Le.includes(h)?h:(o(`"${String(h)}" is not a kind of line (main, plain or dashed): ${$} is drawn plain`),"plain"),w=h=>{if(h!=null){if(Ae.includes(h))return h;o(`"${String(h)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(h,$)=>typeof h=="number"&&Number.isInteger(h)&&h>=1?h:(o(`${$} is ${JSON.stringify(h)}, not a whole number from 1: it is placed at 1`),1),f=[],v=[];let B=[];const C=[],M=[],I=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(I)||o(`"${String(I)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),I==="architecture"||I==="flowchart"){for(const h of t.nodes??[]){const $=I==="flowchart"&&h.shape==="decision"?"decision":I==="flowchart"&&h.shape==="terminal"?"terminal":"box",S=String(h.id??""),g=c(h.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(h.name??""),kind:$==="decision"?void 0:at(h.kind),detail:$==="decision"?void 0:at(h.detail),mono:!!h.detailMono,focal:!!h.focal,col:c(h.col,`the column of ${S}`),row:g,row2:g,branch:!!h.branch,shape:$,group:I==="architecture"?at(h.group):void 0,mark:I==="architecture"?Ct(h.mark):void 0})}if(I==="architecture"){const h=(t.groups??[]).map(y=>({id:String(y.id??""),label:String(y.label??""),parent:at(y.parent)})),$=new Map(h.map(y=>[y.id,y])),S=y=>{if(!y.parent)return 1;const x=$.get(y.parent);return x?x.parent===y.id||x.id===y.id?(o(`the groups "${y.label}" and "${x.label}" are each other's parent`),y.parent=void 0,1):x.parent?(o(`the group "${y.label}" is a third level: groups nest two deep`),y.parent=void 0,1):2:(o(`the group "${y.label}" names the parent "${y.parent}", which is not a group`),y.parent=void 0,1)},g=h.map(S);h.forEach((y,x)=>C.push({...y,depth:g[x],members:f.filter(E=>E.group===y.id).map(E=>E.id),all:[]}));for(const y of C)y.all=[...y.members,...C.filter(x=>x.parent===y.id).flatMap(x=>x.members)];C.sort((y,x)=>y.depth-x.depth)}}else if(I==="data-flow"){B=(t.lanes??[]).map($=>({id:String($.id??""),label:String($.label??"")}));const h=new Map(B.map(($,S)=>[$.id,S+1]));for(const $ of t.nodes??[]){const S=String($.id??""),g=String($.lane??""),y=h.get(g);y===void 0&&o(`a node (${S}) names the lane "${g}", which is not in lanes`);const x=f.length+1;f.push({id:S,i:f.length,name:String($.name??""),kind:u(x),detail:at($.detail),mono:!!$.detailMono,focal:!!$.focal,col:c($.col,`the column of ${S}`),row:y??1,row2:y??1,branch:!1,shape:"box",lane:y??1,laneLabel:B[(y??1)-1]?.label??g,step:x,mark:Ct($.mark)})}}else if(I==="sequence"){(t.participants??[]).forEach((g,y)=>{const x=String(g.name??"");f.push({id:String(g.id??""),i:y,name:x,kind:at(g.kind),mono:!1,focal:!!g.focal,col:y+1,row:1,row2:1,branch:!1,shape:"participant",short:at(g.short)??x,mark:Ct(g.mark)})});let h=0;const $=new Map(f.map(g=>[g.id,g.col])),S=(g,y)=>{let x=1/0,E=-1/0;for(const q of g??[]){if(!q||typeof q!="object")continue;if("band"in q){y>0&&o(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(q.band??"")});continue}if("frame"in q){if(y>=2){o("a frame is a third level: frames nest two deep");continue}const et=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",nt=et==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];et==="alt"&&nt.length<2&&o("an alt frame has one branch: it needs two or more");const J=String(nt[0]?.label??"");J.length>40&&o(`the frame label "${J}" is over 40 characters`);const ot=M.length;M.push({open:et,label:J,depth:y+1,a:0,b:0}),nt.forEach((X,st)=>{if(st){const xt=String(X.label??"");xt.length>40&&o(`the frame label "${xt}" is over 40 characters`),M.push({otherwise:xt,depth:y+1})}X.steps?.length||o(`a frame or branch ("${String(X.label??"")}") is empty`);const[rt,ct]=S(X.steps??[],y+1);x=Math.min(x,rt),E=Math.max(E,ct);const bt=M[ot];bt.a=Math.min(bt.a||1/0,rt),bt.b=Math.max(bt.b,ct)}),M.push({close:y+1});continue}h++;const T=String(q.label??"");T.includes(` +`)&&o(`message ${h}'s label has a break: a message's second line is its note`);const H=String(q.from??""),Q=String(q.to??"");M.push({n:h,from:H,to:Q,label:gt(T),note:at(q.note),kind:b(q.kind,`message ${h}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const U=$.get(H)??1,R=$.get(Q)??1,K=U===R?U===f.length?U-1:U+1:U;x=Math.min(x,U,R,K),E=Math.max(E,U,R,K)}return[x,E]};S(t.steps??[],0);for(const g of M)"open"in g&&!Number.isFinite(g.a)&&(g.a=1,g.b=Math.max(1,f.length))}else if(I==="schema")for(const h of t.tables??[]){const $=String(h.name??""),[S,g]=Array.isArray(h.row)?h.row:[h.row,h.row],y=c(S,`the row of ${$}`),x=Math.max(y,c(g,`the last row of ${$}`)),E=h.more===void 0||h.more===null?void 0:Number.isInteger(h.more)&&h.more>0?h.more:(o(`${$}'s "more" is ${JSON.stringify(h.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:$,i:f.length,name:$,mono:!0,focal:!!h.focal,col:c(h.col,`the column of ${$}`),row:y,row2:x,branch:!1,shape:"table",more:E,columns:(h.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&o(`${$}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}((I==="schema"?t.tables:I==="sequence"?t.participants:t.nodes)??[]).forEach((h,$)=>{if(!h||h.href===void 0||h.href===null)return;const S=String(h.href);if(I==="sequence"){o(`${f[$]?.id}: a participant cannot be a link (href)`);return}if(!S){o(`${f[$]?.id}'s href is empty`);return}const g=f[$];g&&(g.href=S,g.blank=h.target==="_blank")});const G=new Map;for(const h of f)h.id?G.has(h.id)&&o(`the id "${h.id}" is used twice`):o("a node has no id"),G.set(h.id,h);if(I==="schema")(t.tables??[]).forEach(h=>(h.columns??[]).forEach(($,S)=>{const g=at($.references);if(!g)return;const[y,x]=g.split("."),E=G.get(y??""),q=E?.columns?.findIndex(H=>H.name===x)??-1;if(!E||q<0){o(`${String(h.name)}.${String($.name)} references ${g}, which is not a shown column`);return}const T=G.get(String(h.name??""));T.columns[S].ref={table:y,column:x,row:q},v.push({i:v.length,from:T.id,to:y,kind:"plain",fromRow:S,toRow:q,fk:!0})}));else if(I!=="sequence")for(const h of t.edges??[]){const $=String(h.from??""),S=String(h.to??"");if(!G.has($)||!G.has(S)){o(`a line names ${G.has($)?S:$}, which is not a node`);continue}const g=at(h.label),y=g?.split(` +`)??[];y.length>2&&o(`the label "${gt(g)}" has more than one break: a label is two lines at most`),y.some(x=>x.length>Nt)&&o(`a line of the label "${gt(g)}" is over ${Nt} characters: longer words belong in the node or the summary`),v.push({i:v.length,from:$,to:S,kind:b(h.kind,`the line from ${$} to ${S}`),label:g,fromSide:w(h.fromSide),toSide:w(h.toSide),flow:I!=="flowchart"&&h.flow===!0?!0:void 0})}else for(const h of M)"n"in h&&(!G.has(h.from)||!G.has(h.to))&&o(`message ${h.n} names ${G.has(h.from)?h.to:h.from}, which is not a participant`);if(s&&I!=="sequence"){const h=new Map;for(const $ of f)for(let S=$.row;S<=$.row2;S++){const g=`${$.col}:${S}`;h.has(g)&&o(`${$.id} and ${h.get(g)} share the cell at column ${$.col}, row ${S}`),h.set(g,$.id)}}if(s){for(const $ of C){const S=$.all.map(x=>G.get(x));if(!S.length)continue;const g={c1:Math.min(...S.map(x=>x.col)),c2:Math.max(...S.map(x=>x.col)),r1:Math.min(...S.map(x=>x.row)),r2:Math.max(...S.map(x=>x.row2))};for(const x of f)!$.all.includes(x.id)&&x.col>=g.c1&&x.col<=g.c2&&x.row>=g.r1&&x.row<=g.r2&&o(`${x.id} is inside the box of the group "${$.label}" but not a member`);const y=S.map(x=>x.i);Math.max(...y)-Math.min(...y)+1!==y.length&&o(`the members of the group "${$.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const $ of f)$.group&&!C.some(S=>S.id===$.group)&&o(`${$.id} names the group "${$.group}", which is not in groups`);f.filter($=>$.focal).length>1&&o("more than one node is focal: a diagram has one at most");const h=new Set(I==="sequence"?M.flatMap($=>"n"in $?[$.kind]:[]):v.map($=>$.kind));h.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),h.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some($=>$.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const _=I==="architecture"||I==="data-flow",Z=h=>Array.isArray(h)&&h.length>1?h.map(String):void 0,L=_&&t.packet&&typeof t.packet=="object"?t.packet:void 0,z=L&&Z(L.path),O={animated:t.motion==="animated",pulse:_?Z(t.pulse):void 0,packet:z?{path:z,repeat:L.repeat===!0,send:L.send}:void 0,run:I==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const h of f){const $=h.mark?.says;if(!$?.length)continue;const S=[h.name,h.kind,h.detail,h.laneLabel].filter(Boolean).join(" ").toLowerCase();$.some(g=>S.includes(g.toLowerCase()))||o(`${h.id}'s mark stands for ${$.join(" or ")}, and none of its words say so`)}const A=[];if(I==="sequence"){const h=new Map,$=new Map;for(const S of M)"n"in S&&($.set(S.from,S.n),$.set(S.to,S.n));for(const S of M)if("n"in S){if(S.activate){const g=h.get(S.to)??[];if(g.length>=3)o(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const y={who:S.to,from:S.n,to:S.n,depth:g.length+1};g.push(y),A.push(y),h.set(S.to,g)}}if(S.deactivate){const y=h.get(S.from)?.pop();y?y.to=S.n:o(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,g]of h)for(const y of g)y.to=Math.max(y.from,$.get(S)??y.from)}const j=t.frameLabels??{},F={opt:at(j.opt)??"Only if",loop:at(j.loop)??"Repeats",alt:at(j.alt)??"One of these",else:at(j.else)??"Otherwise"};let V=Math.max(1,...f.map(h=>h.col));if(e.rtl){for(const $ of f)$.col=V-$.col+1;const h=$=>$==="left"?"right":$==="right"?"left":$;for(const $ of v)$.fromSide=h($.fromSide),$.toSide=h($.toSide);for(const $ of M)if("open"in $){const[S,g]=[V-$.b+1,V-$.a+1];$.a=S,$.b=g}V=Math.max(1,...f.map($=>$.col))}const W=I==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(h=>h.row2)),Y={type:I,title:String(t.title??""),heading:l,legend:i,nodes:f,byId:G,edges:v,groups:C,lanes:B,steps:M,bars:A,frameWords:F,cols:V,rows:W,shapeLabels:p,stepWord:u,warnings:r,motion:O,memo:new Map,rtl:e.rtl||void 0};return s&&f.length>1&&!Lt(Y)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),Y}function Ct(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ht=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` `?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function $t(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Nt=28,jt=t=>t.includes(` -`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Dt(t,e){return t.legend[e]}function Ie(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Oe(t,e){return $t(t,`sentence:${e.i}`,()=>_e(t,e))}function _e(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Gt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Ie(t,e):e.kind;if(n.push(wt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${gt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${gt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Gt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function Ce(t,e,n,s){const r=n.pointerType;if(r!=="touch"&&r!=="pen")return;const o=t.querySelector(`.${e}-drawing`),a=n.target;if(!o||!a||!o.contains(a)||!t.querySelector(`.${e}-edge`))return;const i=a.closest(`.${e}-node`);if(!i?.hasAttribute("href"))return i?i.dataset.node===s?null:i.dataset.node??null:null}function Kt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function x(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var je={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>je[e]),Be=" br img input meta link hr path polygon polyline circle rect line ";function Bt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${it(String(r))}"`}return Be.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Bt(s,e)).join("")}`}var Te=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Re(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Et(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Vt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=Et(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Zt(t,n,a)))})}return e})}function Zt(t,e,n){const s=Et(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=Et(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Ut(t){const e=Vt(t);return e[1]+e[3]}function Tt(t){return t.type==="sequence"?t.nodes.length:t.cols}function Jt(t){return $t(t,"plan",()=>We(t))}function We(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},y=t.edges.map(()=>0);let h=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,y[v.k]+1));y[c.k]=f,f>1&&(h=!0),l.push(c)}const b=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{b[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const $=ht();for(let c=1;c{const _=s[G],V=t.byId.get(D.from).i,q=t.byId.get(D.to).i,W=q===c&&(_==="down"||_==="trunk"||_==="rail"||_==="end-down"),O=V===c&&q===c-1&&_==="up",A=q===c-1&&_==="end-up";W&&(_==="trunk"||_==="end-down")&&(M=!0),A&&(I=!0),(W||O||A)&&D.label&&(B++,C=Math.max(C,_==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),$[f.id]=C}return{routes:s,gutter:d,lanes:y,exits:b,gaps:$,third:h}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Xt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return x("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?x("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,x("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?x("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):x("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function kt(t,e){return e==="decision"?x("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},x("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?x("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):x("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Yt(t,e){return $t(e,`key:${t}`,()=>Fe(t,e))}var ze=Yt;function Fe(t,e){const n=[],s=(o,a,i={})=>n.push(x("li",{class:`${t}-entry`,...i},o,x("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(x("li",{class:`${t}-entry`},x("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),x("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(kt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(kt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(kt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Xt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Xt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(x("li",{class:`${t}-entry`,"data-when":"stacked"},x("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},"→"),x("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(x("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},x("path",{class:`${t}-life`,d:"M8 0V16"}),x("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(x("li",{class:`${t}-entry`},x("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),x("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(kt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(kt(t,"group"),e.legend.group),n.length?x("div",{class:`${t}-key`},x("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function He(t,e){const n=e==="main"?6:6.5;return x("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},x("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?x("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):x("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Rt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),x("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Ne(t,e,n){if(n.shape==="decision")return[x("span",{class:`${t}-words`},x("span",{class:`${t}-name`},Rt(t,n)))];const s=[];return e.type==="data-flow"?s.push(x("span",{class:`${t}-kind`},n.kind,x("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(x("span",{class:`${t}-kind`},n.kind)),s.push(x("span",{class:`${t}-name`},Rt(t,n))),n.detail&&s.push(x("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?It(n.detail).flatMap((r,o)=>[o?" ":"",x("span",{class:`${t}-run`},r)]):n.detail)),s}function De(t,e){return[x("span",{class:`${t}-th`},x("span",{class:`${t}-tname`},Rt(t,e))),x("span",{class:`${t}-rows`},(e.columns??[]).map((n,s)=>x("span",{class:`${t}-row`,"data-row":s,"data-key":n.key},x("span",{class:`${t}-keyseat`},n.key??""),x("span",{class:`${t}-cname`},n.name),n.ref?x("span",{class:`${t}-ctype`,"data-ref":""},`→ ${n.ref.table}`):n.type?x("span",{class:`${t}-ctype`},n.type):null))),e.more?x("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Qt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=Re(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=yt(d.gaps,n.id)??32,b=yt(s.grow,n.id)??0;i.push(`--_gap:${b?`calc(${Qt(l)} + var(--basalt-space-4) * ${b})`:Qt(l)}`)}const u=yt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const y=yt(s.words,n.id);y&&i.push(`--_ww:${y}px`);const h=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return x(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?Oe(e,n):void 0,tabindex:h},n.shape==="decision"?x("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},x("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?x("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ht(n.mark.onLight)};--_md:${Ht(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?De(r,n):Ne(r,e,n))}function Ge(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>x("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},x("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=Et(e,d);if(!u)continue;const y=[0,1,2,3].map(h=>Zt(e,d,h));r.push(x("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${y[0]>1?";--_gt:2":""}${y[1]>1?";--_ge:2":""}${y[2]>1?";--_gb:2":""}${y[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},x("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(x("ul",{class:`${s}-cast`},e.nodes.map(d=>x("li",{class:`${s}-actor`},At(t,e,d,n))))),r.push(Ke(t,e)),r;const o=d=>{const u=d.group?e.groups.find(y=>y.id===d.group):void 0;return u?.parent?e.groups.find(y=>y.id===u.parent):u},a=(d,u,y)=>{const h=t.plan?yt(n.grow,u[0].id)??0:0;return x("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:h?`--_ggrow:${h}`:void 0},x("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),y)};let i=0;for(;ic.id===y[l].group):void 0;if(!b){h.push(At(t,e,y[l],n)),l++;continue}const $=[];for(;lAt(t,e,c,n))))}r.push(a(u,y,h))}return r}function Ke(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(x("p",{class:`${n}-band`},x("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=x("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},x("span",{class:`${n}-fbox`,"aria-hidden":"true"}),x("p",{class:`${n}-fhead`},x("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),x("span",{class:`${n}-flabel`},x("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(x("p",{class:`${n}-felse`},x("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),x("span",{class:`${n}-flabel`},x("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=x("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),y=d?.col??1,h=u?.col??1,l=y===h,b=l&&y===e.nodes.length,$=Dt(e,i.kind);a.c.push(x("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?b?"start":"end":void 0,style:`--_a:${Math.min(y,h)};--_b:${Math.max(y,h)+1}`},x("span",{class:`${n}-said`},x("span",{class:`${n}-num`},String(i.n)),x("span",{class:`${n}-mlabel`},i.label)),x("span",{class:`${n}-route`},d?.short??i.from," ",He(n,i.kind),x("span",{class:t.hidden}," to ")," ",u?.short??i.to,$?` · ${$}`:""),i.note?x("span",{class:`${n}-note`},i.note):null))}return x("div",{class:`${n}-steps`},s)}function Pt(t,e){return $t(e,`list:${t}`,()=>Ze(t,e))}var Ve=Pt;function Ze(t,e){const n=Math.min(6,e.heading+1),s=h=>x(`h${n}`,{class:`${t}-list-head`},h),r=h=>x("strong",null,h),o=h=>h.href?x("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},r(h.name)):r(h.name),a=h=>x("code",{class:`${t}-code`},h),i=h=>e.byId.get(h)?.name??h,d=h=>{const l=Dt(e,h);return l?` (${l})`:""},u=h=>h.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const h=$=>x("li",null,o($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?a($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",u($)),l=[s("Parts")],b=e.nodes.filter($=>!$.group);b.length&&l.push(x("ul",{class:`${t}-list-items`},b.map(h)));for(const $ of e.groups.filter(c=>c.depth===1)){l.push(x("p",{class:`${t}-list-group`},$.label)),$.members.length&&l.push(x("ul",{class:`${t}-list-items`},$.members.map(c=>h(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===$.id))l.push(x("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(x("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>h(e.byId.get(f)))))}return l.push(s("Connections")),l.push(x("ol",{class:`${t}-list-items`},e.edges.map($=>x("li",null,r(i($.from))," to ",r(i($.to)),$.label?[": ",a(gt($.label))]:"",`${d($.kind)}.`)))),l}if(e.type==="flowchart"){const h=l=>(e.byId.get(l)?.i??0)+1;return[x("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const b=e.edges.filter(f=>f.from===l.id),$=l.shape==="decision"?"Decision":l.shape==="terminal"?b.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return x("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${$}.`,u(l),b.length?x("ul",{class:`${t}-list-exits`},b.map(f=>x("li",null,f.label?`If ${gt(f.label)}: go to ${h(f.to)}, `:`Then: go to ${h(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[x("ol",{class:`${t}-list-items`},e.nodes.map(h=>{const l=e.edges.filter(b=>b.from===h.id);return x("li",null,`${h.laneLabel}: `,o(h),h.detail?[", ",h.mono?a(h.detail):h.detail]:"",".",u(h),l.length?[" Then ",...l.flatMap((b,$)=>[$?"; ":"",`to step ${e.byId.get(b.to).step}, `,r(i(b.to)),b.label?[": ",a(gt(b.label))]:"",d(b.kind)]),"."]:"")}))];if(e.type==="sequence"){const h=[s("Participants"),x("ul",{class:`${t}-list-items`},e.nodes.map(b=>x("li",null,r(b.name),b.kind?`, ${b.kind}`:"",".",u(b),Gt(e,b))))];h.push(s("Messages"));let l=null;for(const b of e.steps){if("band"in b){l=null,h.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},b.band));continue}if("open"in b){l=null,h.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords[b.open]}: ${b.label}`));continue}if("otherwise"in b){l=null,h.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords.else}: ${b.otherwise}`));continue}if("close"in b){l=null;continue}l||(l=x("ol",{class:`${t}-list-items`,start:b.n}),h.push(l)),l.c.push(x("li",null,a(b.label),": ",r(i(b.from))," to ",r(i(b.to)),`${d(b.kind)}.`,b.note?` ${wt(b.note)}`:""))}return h}const y=[];for(const h of e.nodes)y.push(x(`h${n}`,{class:`${t}-list-group`},h.href?x("a",{href:h.href,target:h.blank?"_blank":void 0,rel:h.blank?"noopener noreferrer":void 0},a(h.name)):a(h.name),u(h))),y.push(x("ul",{class:`${t}-list-items`},[...(h.columns??[]).map(l=>x("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...h.more?[x("li",null,`and ${h.more} more ${h.more===1?"column":"columns"}`)]:[]]));return y}function te(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Lt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Wt(t,e=!1){const n=e&&t.type!=="sequence"&&Lt(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Kt(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var Ue=(t,e)=>{for(let n=0;n({col:t.type==="sequence"?e.i+1:e.col,rows:[e.row,e.row2]});function Lt(t){return $t(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...Je(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=$=>i?[$.col,$.col]:$.rows,y=$=>i?$.rows:[$.col,$.col],h=u(o),l=y(o);let b=null;return e.forEach(($,c)=>{if($===o)return;const f=u($),v=y($),B=d?f[0]-h[1]:h[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!b||Ue(M,b.rank))&&(b={id:$.id,rank:M})}),b?.id??null},s=ht();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var ee=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function ne(t,e,n){const s=n.prefix,r=Te(n.base),o=t.type==="sequence"||t.type==="schema"?null:Jt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,y=`h${t.heading}`,h=[`--_cols:${Tt(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Vt(t):[0,0,0,0],b=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",$=i&&e.pad?"3":void 0;h.push(`--_gpad:${b(l[0],"8",$)} ${b(l[1],"4")} ${b(l[2],"4",$)} ${b(l[3],"4")}`)}return ee(t)&&h.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&h.push(`--_track:${e.track}px`),x("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Tt(t),"data-reach":t.type==="architecture"?Ut(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-viewer":n.viewer?"":void 0,style:h.join(";")},x("div",{class:`${s}-head`},x(y,{id:r.title,class:`${s}-title`},t.title),n.hasSource?x("p",{class:`${s}-source`},{slot:"source"}):null),x("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},Ge(a,t,e),x("div",{class:`${s}-ink`,"aria-hidden":"true"}),x("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Yt(s,t),x("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||i&&t.type==="sequence"?x("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${Kt(t)} to highlight its lines. Tap it again to clear.`):null,x("div",{class:`${s}-foot`},{slot:"toggle"}),x("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Pt(s,t)),x("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${te(t,i)} ${n.viewer}`:te(t,i)),x("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Xe(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var qt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,oe=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,y=(a-r)/2,h=e==="top"||e==="bottom";if(t.shape==="decision"){if(h){const $=n,c=y*Math.max(0,1-Math.abs($-i)/u);return{x:$,y:e==="top"?d-c:d+c}}const l=n,b=u*Math.max(0,1-Math.abs(l-d)/y);return{x:e==="left"?i-b:i+b,y:l}}if(t.shape==="terminal"){const l=Math.min(u,y);if(h){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const b=n,$=b-d,c=Math.abs($)>=l?0:Math.sqrt(l*l-$*$);return{x:e==="left"?s+l-c:o-l+c,y:b}}return h?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Ye(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,y=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/y<1-n/Math.min(u,y);if(e.shape==="terminal"){const h=Math.min(u,y),l=Math.min(Math.max(t.x,s+h),o-h);return Math.hypot(t.x-l,t.y-d)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function tn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var It=t=>t?t.split(/\s+/).filter(Boolean):[];function en(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`→ ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),y=d.mark&&!Pe()?(d.shape==="participant"?2:1)*s("6"):0;let h=0;const l=d.href?16+s("1-5"):0,b=It(d.name);if(b.forEach((c,f)=>{h=Math.max(h,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:y)+(f===b.length-1?l:0))}),t.type!=="data-flow")for(const c of It(d.kind))h=Math.max(h,n(c,"mono")+y);for(const c of It(d.detail))h=Math.max(h,n(c,d.mono?"mono":"sans"));const $=d.shape==="decision"?h/.62:h+u+2*e.hair;r=Math.max(r,Math.ceil($))}const a=Tt(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(ee(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Ut(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ae(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function zt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function re(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Ot(t,e,n){const s=[];for(let o=0;oMath.min(c.x,f.x)+.75&&CMath.min(v.y,B.y)+.75&&Mr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",ie={top:"bottom",bottom:"top",left:"right",right:"left"};function on(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function sn(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,y]=e[a],h=i.row===d.row&&tt(u)&&tt(y)&&u===ie[y]||i.col===d.col&&!tt(u)&&!tt(y)&&u===ie[y];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:h,f:.5},{edge:a,end:"to",node:d,side:y,far:i,straight:h,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const y=new Map;for(const c of d)y.has(c.far.id)||y.set(c.far.id,[]),y.get(c.far.id).push(c);for(const c of y.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const h=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),b=u.filter(c=>i(c)<0),$=u.filter(c=>i(c)>=0);b.forEach((c,f)=>{c.f=h*(f+1)/(b.length+1)}),$.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/($.length+1)})}return s}function le(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?lt(t,e,r+(a-r)*n):lt(t,e,s+(o-s)*n)}function ce(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ft(o,n),shape:a.shape,i:a.i})}),r}function de(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function ue(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function an(t,e,n,s,r,o,a,i,d){const u=a.space,y=[],h=[],l=[],b=[],$=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*jt(v),M=f.pts.length-2,I=[];pt(f.pts).forEach(([q,W],O)=>{const A=Math.abs(q.y-W.y)<.01,j=A?q.x:q.y;let F=A?W.x:W.y;const Z=Math.sign(F-j)||1;O===M&&(F-=Z*a.head);let z=[[j,F]];for(const k of r)for(const S of A?[k.l,k.r]:[k.t,k.b]){const g=A?q.y:q.x;(A?g>k.t&&gk.l&&gS>Math.min(w,E)+1&&S{const g=(k+S)/2,m=A?{x:g,y:q.y}:{x:q.x,y:g};return!r.some(w=>m.x>w.l&&m.xw.t&&m.y1&&Y(k,S)?1:0})}),I.sort((q,W)=>W.pri-q.pri||W.len-q.len);let D=null,G=!1;const _=(q,W=!0)=>{const O=oe(q,$);return W&&(q.lo.r||q.to.b)||n.some(A=>se(O,A))||y.some(A=>ut(O,A))||s.heads.some(A=>ut(O,A))||s.rects.some(A=>ut(O,A))?!1:!e.some(A=>A.i!==f.i&&pt(A.pts).some(([j,F])=>ut(O,fe(j,F,A.width))))};for(const q of I){for(const W of[1/2,1/3,2/3]){const O=q.p+(q.q-q.p)*W,A=[],j=u("2")+f.width/2;if(q.horiz?(q.len>=B+2*u("1")+u("3-5")&&A.push({box:{l:O-B/2-u("1"),r:O+B/2+u("1"),t:q.c-C/2,b:q.c+C/2},on:!0}),A.push({box:{l:O-B/2,r:O+B/2,t:q.c-j-C,b:q.c-j},on:!1}),A.push({box:{l:O-B/2,r:O+B/2,t:q.c+j,b:q.c+j+C},on:!1})):(q.len>=C+u("3")&&A.push({box:{l:q.c-B/2-u("1"),r:q.c+B/2+u("1"),t:O-C/2,b:O+C/2},on:!0}),A.push({box:{l:q.c+j,r:q.c+j+B,t:O-C/2,b:O+C/2},on:!1}),A.push({box:{l:q.c-j-B,r:q.c-j,t:O-C/2,b:O+C/2},on:!1})),D=A.find(F=>_(F.box))??null,D)break;!G&&A.some(F=>_(F.box,!1))&&(G=!0)}if(D)break}if(!D){l.push(f.i),G&&b.push(f.i);continue}const V=ue(D.box,d.ox,d.oy,q=>_(q));y.push(V),h.push({i:f.i,text:v,box:V,on:D.on})}return{labels:h,unseated:l,bounded:b}}function he(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=ft(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(ft(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=ft(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(ft(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function rn(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,y=ce(s,a,i,o),h=[...y.values()],l=nn(a),b=i.left-Math.floor(i.left),$=i.top-Math.floor(i.top),c=ae(b,$),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:b,oy:$};if(s.type==="sequence")return cn(t,M,c);let I,D=[];s.type==="schema"?I=s.edges.map(g=>{const m=s.byId.get(g.from),w=s.byId.get(g.to);if(m.col===w.col){const E=m.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return w.col>m.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const m=s.byId.get(g.from),w=s.byId.get(g.to),[E,L]=on(m,w);return[g.fromSide??E,g.toSide??L]}),D=sn(s,I,d||(()=>{})));const G=(g,m)=>{const w=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${m}"]`);if(!w)return 0;const E=ft(w,i);return(E.t+E.b)/2},_=s.edges.map((g,m)=>{const[w,E]=I[m],L=y.get(g.from),T=y.get(g.to),H=qt(g.kind,r);if(g.fk){const J=G(g.from,g.fromRow),ot=G(g.to,g.toRow),X=c.y(J,H),st=c.y(ot,H);return{p1:{x:w==="right"?L.rect.r:L.rect.l,y:X},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:J,r2:Math.abs(X-st)<.01?J:ot}}const P=D.find(J=>J.edge===m&&J.end==="from").f,U=D.find(J=>J.edge===m&&J.end==="to").f;let R=le(L,w,P),K=le(T,E,U);const et=tt(w)?R.y:R.x;let nt=tt(E)?K.y:K.x;return tt(w)?R={...R,y:c.y(R.y,H)}:R={...R,x:c.x(R.x,H)},tt(E)?K={...K,y:c.y(K.y,H)}:K={...K,x:c.x(K.x,H)},tt(w)&&tt(E)&&Math.abs(R.y-K.y)<1.01&&(K={...K,y:R.y},nt=et),!tt(w)&&!tt(E)&&Math.abs(R.x-K.x)<1.01&&(K={...K,x:R.x},nt=et),R=tt(w)?lt(L,w,R.y):lt(L,w,R.x),K=tt(E)?lt(T,E,K.y):lt(T,E,K.x),{p1:R,p2:K,r1:et,r2:nt}}),V=new Set;s.type==="schema"&&s.edges.forEach((g,m)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&V.add(m)});const q=new Map,W=new Set;s.edges.forEach((g,m)=>{if(V.has(m))return;const[w,E]=I[m],{p1:L,p2:T}=_[m],H=s.byId.get(g.from),P=s.byId.get(g.to);let U=null,R=null,K=!1;if(w===E){if(tt(w)){const J=w==="right"?Math.max(B(H),B(P)):Math.min(B(H),B(P))-1,ot=l.cols[J-1],X=l.cols[J];ot&&X&&(U=`c${J}`,R=[ot[1],X[0]],K=!0)}else{const J=w==="bottom"?Math.max(H.row2,P.row2):Math.min(H.row,P.row)-1,ot=l.rows[J-1],X=l.rows[J];ot&&X&&(U=`r${J}`,R=[ot[1],X[0]],K=!1)}U&&W.add(m)}else if(tt(w)&&tt(E)&&Math.abs(L.y-T.y)>.5){const J=B(P),ot=E==="left",X=l.cols[(ot?J-1:J)-1],st=l.cols[(ot?J:J+1)-1];X&&st&&(U=`c${ot?J-1:J}`,R=[X[1],st[0]],K=!0)}else if(!tt(w)&&!tt(E)&&Math.abs(L.x-T.x)>.5){const ot=E==="top"?P.row-1:P.row2,X=l.rows[ot-1],st=l.rows[ot];X&&st&&(U=`r${ot}`,R=[X[1],st[0]],K=!1)}if(!U||!R)return;q.has(U)||q.set(U,{span:R,vertical:K,members:new Map});const et=`${g.to}.${E}.${Math.round(K?T.y:T.x)}`,nt=q.get(U);nt.members.has(et)||nt.members.set(et,[]),nt.members.get(et).push(m)});const O=new Map,A=g=>{const[m,w]=I[g],{p1:E,p2:L}=_[g];if(tt(m)&&tt(w)){if(m===w){const H=O.get(g)??(m==="right"?Math.max(E.x,L.x)+u("4"):Math.min(E.x,L.x)-u("4"));return[E,{x:H,y:E.y},{x:H,y:L.y},L]}if(Math.abs(E.y-L.y)<=.5)return[E,{x:L.x,y:E.y}];const T=O.get(g)??(E.x+L.x)/2;return[E,{x:T,y:E.y},{x:T,y:L.y},L]}if(!tt(m)&&!tt(w)){if(m===w){const H=O.get(g)??(m==="bottom"?Math.max(E.y,L.y)+u("4"):Math.min(E.y,L.y)-u("4"));return[E,{x:E.x,y:H},{x:L.x,y:H},L]}if(Math.abs(E.x-L.x)<=.5)return[E,{x:E.x,y:L.y}];const T=O.get(g)??(E.y+L.y)/2;return[E,{x:E.x,y:T},{x:L.x,y:T},L]}return tt(m)?[E,{x:L.x,y:E.y},L]:[E,{x:E.x,y:L.y},L]},j=g=>{const m=s.edges[g],w=qt(m.kind,r),E=A(g),L=re(E,w,c);let T;return E.length===L.length&&(T=pt(E).map(([H,P])=>Math.abs(H.y-P.y)<.75?(H.y+P.y)/2:(H.x+P.x)/2),T[0]=_[g].r1,T.length>1&&(T[T.length-1]=_[g].r2)),{i:g,from:m.from,to:m.to,kind:m.kind,pts:L,tip:L[L.length-1],dir:zt(L),dot:m.fk?L[0]:void 0,width:w,axes:T}},F=()=>s.edges.flatMap((g,m)=>V.has(m)?[]:[j(m)]);let Z=null;const z=g=>{Z??(Z=F());const m=Z.map(w=>g.has(w.i)?j(w.i):w);return{lines:m,score:ln(m,g)*1e5+Ot(m,void 0,g).length*1e3+Ft(m.filter(w=>g.has(w.i)),h,s).length}},Y=(g,m)=>{const w=g.flatMap(E=>{const{p1:L,p2:T}=_[E];return m?[L.y,T.y]:[L.x,T.x]});return[Math.min(...w),Math.max(...w)]};for(const[,g]of q){const m=[...g.members.values()].map(E=>({members:E,run:Y(E,g.vertical)})).sort((E,L)=>E.run[0]-L.run[0]),w=[];for(const E of m){const L=w[w.length-1];L&&L.some(T=>T.run[0]W.has(et)))continue;const L=E.map(et=>et.members),T=L.length,H=(g.span[1]-g.span[0])/(T+1);HJ.forEach(X=>O.set(X,g.span[0]+H*(ot+1))));const nt=z(P);nt.scoreet.forEach(J=>O.set(J,g.span[0]+H*(nt+1)))),Z=K}}M.lines=F();for(const g of V)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=Ot(M.lines),M.through=Ft(M.lines,h,s),M.outside=me(M.lines,f,v,r);const{obstacles:p,groups:k}=he(a,i,o,C);p.heads=M.lines.map(g=>de(g,r));const S=an(s,M.lines,h,p,k,{l:0,t:0,r:f,b:v},r,e,{ox:b,oy:$});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(pe(M.lines,null).flat())],M}function ln(t,e){return pe(t,e).length}function pe(t,e){const n=[];for(let s=0;s=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[y.x,h.x]:[y.y,h.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*ge(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Ft(t,e,n){const s=[];for(const r of t){const o=pt(r.pts);e.some(a=>o.some(([i,d])=>Qe(i,d,a)))&&s.push(r.i)}return s}function cn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,ft(M,i)));const y=a.querySelector(`.${o}-steps`),h=y?ft(y,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:h})}const b=M=>u.get(M.id),$=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=ft(M,i);$.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const D=l(M.who),G=I.i===s.nodes.length-1&&s.nodes.length>1?-1:1,_=(M.depth-1)*d("1")*G,V=$.get(M.from)??0,q=$.get(M.to)??V,W=M.from===M.to;return{l:n.x(D-f+_,r.hair),r:n.x(D+f+_,r.hair),t:n.y(W?V-d("2")-d("1"):V,r.hair),b:n.y(W?V+d("2")+d("1"):q,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,D)=>B.filter(({bar:G})=>G.who===M&&G.to>=I&&(D?G.from<=I:G.from_.bar.depth-G.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,D=M.dataset.to,G=M.dataset.kind??"plain",_=qt(G,r),V=ft(M,i),q=n.y((V.t+V.b)/2,_),W=Number(M.querySelector(`.${o}-num`)?.textContent??0);let O=l(I),A=l(D),j;if(I===D){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,W,!0),m=g?S>0?g.r:g.l:O,w=n.y(q-d("2"),_),E=n.y(q+d("2"),_);j=[{x:m,y:w},{x:n.x(O+S,_),y:w},{x:n.x(O+S,_),y:E},{x:m,y:E}]}else{const S=A>O?1:-1,g=C(I,W,!1),m=C(D,W,!0);g&&(O=S>0?g.r:g.l),m&&(A=S>0?m.l:m.r),j=[{x:O,y:q},{x:A,y:q}]}e.lines.push({i:W,from:I,to:D,kind:G,pts:j,tip:j[j.length-1],dir:zt(j),width:_});const F=M.querySelector(`.${o}-said`),Z=M.querySelector(`.${o}-note`),z=s.byId.get(I),Y=s.byId.get(D);if(!z||!Y)return;const p=I===D?(()=>{const S=s.nodes[z.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-O)-d("6")-d("2-5")-d("2")})():Math.abs(A-O)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>p+.5&&e.unseated.push(W)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((G,_)=>G+_.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ye(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,y=ce(r,i,d,a),h=[...y.values()],l=d.left-Math.floor(d.left),b=d.top-Math.floor(d.top),$=ae(l,b),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:h,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:b},B=ht();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(A,j,F)=>{const Z=[A];for(let z=1;z<=(yt(s,j)??0);z++)Z.push({...A,t:A.t+F*u("4")*z,b:A.b+F*u("4")*z});return Z},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(A=>{const j=A.parentElement,F=ft(j,d),Z=getComputedStyle(j);I.set(A.dataset.node,F.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const D=r.nodes,G=A=>y.get(D[A].id),_=[],V=A=>qt(r.edges[A].kind,o);r.edges.forEach((A,j)=>{const F=n.routes[j],Z=y.get(A.from),z=y.get(A.to),Y=V(j);let p=[];const k=A.label,S=k?e(k,"label"):0,g=k?16*jt(k):16,m=u("4");if(F==="down"||F==="up"){const E=Math.max(Z.rect.l,z.rect.l),L=Math.min(Z.rect.r,z.rect.r),T=r.edges.map((R,K)=>({o:R,j:K})).filter(({o:R,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(R.from===A.from&&R.to===A.to||R.from===A.to&&R.to===A.from)),H=T.findIndex(R=>R.j===j),P=T.length<2?.5:T.length===2?H===0?.25:.75:(H+1)/(T.length+1),U=$.x(E+(L-E)*P,Y);if(p=F==="down"?[lt(Z,"bottom",U),lt(z,"top",U)]:[lt(Z,"top",U),lt(z,"bottom",U)],k){let R=Math.min(p[0].y,p[1].y),K=Math.max(p[0].y,p[1].y);F==="down"?K-=o.head:R+=o.head;const et=[...i.querySelectorAll(`.${a}-group`)].map(X=>ft(X,d));let nt=[[R,K]];for(const X of et)for(const st of[X.t,X.b])nt=nt.flatMap(([rt,ct])=>st>rt+1&&stet.some(rt=>(X+st)/2>rt.t&&(X+st)/2rt.l&&U1){const X=nt.filter(([rt,ct])=>!J(rt,ct));[R,K]=(X.length?X:nt).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const ot=[1/2,1/3,2/3].map(X=>{const st=R+(K-R)*X;return{l:U-S/2-u("1"),r:U+S/2+u("1"),t:st-g/2,b:st+g/2}});_.push({k:j,cands:ot,on:!0,card:F==="down"?A.to:A.from})}}else if(F==="trunk"||F==="rail"){const E=$.x(Math.max(Z.rect.l,F==="rail"?z.rect.l:Z.rect.l)+u(F==="trunk"?"8":"3"),Y),L=lt(Z,"bottom",E);if(F==="rail"){if(p=[L,lt(z,"top",E)],k){const T=z.rect.t-u("6");_.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},A.to,-1),on:!1,card:A.to})}}else{const T=$.x(z.rect.l+u("6"),Y),H=$.y(z.rect.t-m,Y);p=[L,{x:E,y:H},{x:T,y:H},lt(z,"top",T)],k&&_.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:H-g/2,b:H+g/2},A.to,-1),on:!1,card:A.to})}}else{const E=Math.min(I.get(A.from)??c,I.get(A.to)??c),L=$.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),Y),T=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[j],Y),H=lt(Z,"right",T),P=$.x(z.rect.r-u("6"),Y),U=F==="end-down",R=$.y(U?z.rect.t-m:z.rect.b+m,Y);p=[H,{x:L,y:H.y},{x:L,y:R},{x:P,y:R},lt(z,U?"top":"bottom",P)];const K=U?A.to:D[z.i+1]?.id??A.to;k&&_.push({k:j,cands:M({l:P-u("2-5")-S,r:P-u("2-5"),t:R-g/2,b:R+g/2},K,U?-1:1),on:!1,card:K})}const w=re(p,Y,$);v.lines.push({i:j,from:A.from,to:A.to,kind:A.kind,pts:w,tip:w[w.length-1],dir:zt(w),width:Y})}),v.crossings=Ot(v.lines),v.through=Ft(v.lines,h,r),v.outside=me(v.lines,c,f,o);const{obstacles:q}=he(i,d,a,0);q.heads=v.lines.map(A=>de(A,o));const W=[],O={l:0,t:0,r:c,b:f};for(const A of _){const j=z=>{const Y=oe(z,u("1"));return z.lO.r+.5||z.tO.b+.5||h.some(p=>se(Y,p))||W.some(p=>ut(Y,p))||q.heads.some(p=>ut(Y,p))||q.rects.some(p=>ut(Y,p))||v.lines.some(p=>p.i!==A.k&&pt(p.pts).some(([k,S])=>ut(Y,fe(k,S,p.width))))},F=A.cands.find(z=>!j(z));F||(B[A.card]=(B[A.card]??0)+1,v.unseated.push(A.k));const Z=F?ue(F,l,b,z=>!j(z)):A.cands[0];W.push(Z),v.labels.push({i:A.k,text:r.edges[A.k].label,box:Z,on:A.on})}return{geo:v,grow:B}}function dn(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...M})),h=y[y.length-1];h.x-=o.x*u,h.y-=o.y*u;const l=e.tip.x-o.x*i,b=e.tip.y-o.y*i,$=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=it(e.kind),B=a?``:``,C=e.dot?``:"";return`${B}${C}`}function be(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const y=d.map(h=>{const l=e.lines[h.top],b=e.lines[h.under],$=l.width/2+n.cut,c=b.width/2+1;return h.underVertical?``:``}).join("");a+=`${y}`}return{defs:a,ids:r}}function $e(t,e,n,s){const{defs:r,ids:o}=be(t,e,n,s),a=e.lifelines.map(y=>``).join("")+(e.bars??[]).map(y=>``).join(""),i=e.lines.map((y,h)=>un(t,y,n,o.get(h)??null,y.from===y.to?n.radiusXs:n.radius)).join(""),d=`${r?`${r}`:""}${a}${i}`,u=e.labels.map(y=>`1?' data-lines="2"':""} style="left:${Math.round(y.box.l*100)/100}px;top:${Math.round(y.box.t*100)/100}px;width:${Math.round((y.box.r-y.box.l)*100)/100}px">${y.text.split(` -`).map(it).join("
")}
`).join("");return d+u}function we(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const y=Xe(t),h=tn(u,n),l=en(e,y,h);i?.(l.least);const b=t.clientWidth,$=(()=>{const q=document.activeElement;return q&&u.contains(q)&&q.dataset.node?q.dataset.node:void 0})(),c=q=>mt(e,q)?{...q,stop:q.stop&&e.byId.has(q.stop)?q.stop:e.nodes[0]?.id,keep:void 0}:{...q,stop:q.stop??e.nodes[0]?.id,keep:$&&q.layout!=="drawn"?$:void 0};let f=!1;const v=q=>{if(f=!1,e.type!=="flowchart")return q;o({...q,heights:void 0,words:void 0});const W=ht(),O=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(A=>{const j=A.querySelector(`.${n}-words`);if(!j)return;const F=A.getBoundingClientRect(),Z=p=>{const k={w:p.width+2*y.space("2-5"),h:p.height+2*y.space("2")},S=1-k.w/F.width,g=S>.05?k.h/2/S:k.h*10;return Math.max(y.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},z=j.getBoundingClientRect();let Y=Z(z);if(Y>F.width){const p=m=>(A.style.setProperty("--_ww",`${m}px`),j.getBoundingClientRect()),k=Math.floor(A.clientWidth-2*y.space("2-5"));let S=Math.ceil(z.width),g=z.height;for(;S1;){const T=m+w>>1;p(T).heightF.width&&(f=!0)}),{...q,heights:W,words:Object.keys(O).length?O:void 0}},B=()=>({m:e,tk:y,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(q,W)=>W.map(O=>Mt(e,q.lines.find(A=>A.i===O))).join(", ");if(b>=l.least){const q=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:rn(B(),h)}};let{dd:W,g:O}=q(!1);const A=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!A(O)&&O.unseated.length&&O.unseated.every(j=>O.bounded?.includes(j))){const j=q(!0);!A(j.g)&&!j.g.unseated.length&&({dd:W,g:O}=j)}if(!A(O)&&!O.unseated.length)return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the drawn layout: ${O.crossings.map(j=>`${Mt(e,O.lines[j.top])} over ${Mt(e,O.lines[j.under])}`).join("; ")}`),{dyn:W,geo:O,ink:$e(n,O,y,s),tokens:y,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: a decision would be taller than it is wide`),O.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${O.misfit.join("; ")}`),O.through.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.through)} would pass through a node`),O.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.overlaps)} would lie on one another`),O.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.outside)} would leave the drawing`),O.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: no clean seat for ${O.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:y,least:l.least};const D=Jt(e);let G=ye(B(),h,D,I.grow);for(let q=0;q<6&&Object.keys(G.grow).length;q++){const W=ht(I.grow);for(const[O,A]of Object.entries(G.grow))W[O]=(yt(W,O)??0)+A;I={...I,grow:W},o(I),G=ye(B(),h,D,W)}const _=G.geo;if(_.unseated.length>0||_.through.length>0||_.outside.length>0||D.third){_.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(_.unseated)].map(O=>`"${e.edges[O]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),_.through.length&&a?.(`in the stacked drawing ${M(_,_.through)} would pass through a node, so its lines are not drawn`),_.outside.length&&a?.(`in the stacked drawing ${M(_,_.outside)} would leave the drawing, so its lines are not drawn`),D.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const q={..._,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:q,ink:"",tokens:y,least:l.least}}return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${_.crossings.map(q=>`${Mt(e,_.lines[q.top])} over ${Mt(e,_.lines[q.under])}`).join("; ")}`),{dyn:I,geo:_,ink:$e(n,_,y,s),tokens:y,least:l.least}}function Mt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function hn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const y=Ot(n.lines,i),{defs:h,ids:l}=be(e,{...n,crossings:y},s,r),b=t.querySelector(`.${e}-svg`);if(!b)return;let $=b.querySelector("defs");!$&&h&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),b.insertBefore($,b.firstChild)),$&&($.innerHTML=h),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var pn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function gn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",pn()||yn(t)?"done":"pending")}}var mn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function yn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(mn(t))!==null}catch{return!1}}function ve(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function bn(t,e,n,s=!1,r=!1){const o=s?Lt(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var $n=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],xe=["data-layout","data-measured","data-bare","data-motion","data-first-visit"],wn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ke=t=>t==null||t===!1;function vn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Me(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?xe:$n;for(const a of s)ke(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,y=new Map(String(i??"").split(";").map(h=>{const l=h.indexOf(":");return[h.slice(0,l).trim(),h.slice(l+1).trim()]}).filter(([h])=>h));for(const[h,l]of y)u.getPropertyValue(h).trim()!==l&&u.setProperty(h,l);for(const h of wn)y.has(h)||u.removeProperty(h);continue}if(n&&!xe.includes(a))continue;if(ke(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,b,$){return{prefix:n,base:l,hasSource:b.source!==void 0&&b.source!==null&&b.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function o(l,b,$,c){var f=function(v){return''+it(v)+""};return{source:it(String(b.source||"")),summary:it(String(b.summary||"")),hint:Wt(l).map(function(v){return""+v.keys.map(f).join(" ")+" "+it(v.words)+""}).join(""),toggle:'"}}function a(l,b,$){var c=_t(l),f=ne(c,{},r(b,l,$)),v=Bt(f,o(c,l,b,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,b,$,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=_t(b);if(!$||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(b,f,c),C=document.createElement("div");C.innerHTML=B.open+"";var M=C.firstChild;i.forEach(function(N){l.removeAttribute(N)}),d.forEach(function(N){l.style.removeProperty(N)});for(var I=0;I :not(script[data-diagram])").forEach(function(N){N.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var G=r(f,b,c),_={},V=null,q=null,W=null,O=null,A=Object.create(null),j=function(N){A[N]||(A[N]=1,console.warn("Basalt diagram: "+N))},F=function(N){Me(l,ne(v,N,G))},Z=l.querySelector(".diagram-ink"),z=l.querySelector(".diagram-toggle"),Y=!c&&v.motion.animated&&typeof e.diagramMotion=="function",p=null,k=null,S=function(){Y&&ve(l)};function g(){hn(l,n,V&&V.geo,V&&V.tokens,f,q||O||W),E()}var m=null,w=!c&&matchMedia("(hover: none), (pointer: coarse)").matches;function E(){var N=w&&!c&&Z&&Z.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(w&&!c)),N&&!m){var Q=l.querySelector(":scope > .diagram-foot");if(!Q)return;m=document.createElement("button"),m.type="button",m.className="btn diagram-clear",m.setAttribute("data-variant","secondary"),m.setAttribute("data-size","sm"),m.innerHTML="Clear highlight",m.addEventListener("click",function(){O&&(O=null,g())}),Q.appendChild(m)}else!N&&m&&(m.remove(),m=null);m&&(O?m.removeAttribute("aria-disabled"):m.setAttribute("aria-disabled","true"))}function L(N){if(!N.defaultPrevented){var Q=Ce(l,n,N,O);Q!==void 0&&(S(),w=!0,O=Q,g())}}function T(){z&&(z.setAttribute("aria-expanded",String(!!_.open)),z.firstElementChild.textContent=_.open?"Hide the list":"View as list")}function H(){V=(c?c.measure:we)(l,v,n,f,_,F,j),_=V.dyn,F(_),T();var N=l.querySelector(":scope > .diagram-hint");if(N){var Q=Wt(v,_.layout==="drawn").map(function(St){return""+St.keys.map(function(kn){return''+it(kn)+""}).join(" ")+" "+it(St.words)+""}).join("");N.innerHTML!==Q&&(N.innerHTML=Q)}mt(v,_)||(W=O=null);var dt=Z&&V.ink!==k;dt&&(Z.innerHTML=V.ink,k=V.ink),g(),Y&&V.tokens&&(gn(l,!!(V.geo&&V.geo.lines.length)),dt&&p&&p.redrawn()),c&&c.onMeasured&&V.tokens&&c.onMeasured(V,l)}function P(N){_=N,F(_)}function U(N){var Q=_.stop;_=Object.assign({},_,{stop:N}),xn(l,n,Q,N)}var R=function(N){var Q=N&&N.closest?N.closest(".diagram-node"):null;return Q&&l.contains(Q)?Q:null};function K(N){var Q=R(N.target);if(!(!Q||N.defaultPrevented)){if(S(),N.key==="Escape"){!c&&(q||W||O)&&(N.preventDefault(),q=W=O=null,g());return}if(mt(v,_)){var dt=bn(v,Q.getAttribute("data-node"),N.key,_.layout==="drawn",getComputedStyle(Q).direction==="rtl");if(dt){N.preventDefault(),U(dt);var St=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');St&&St.focus()}}}}function et(N){var Q=R(N.target);if(Q){S();var dt=Q.getAttribute("data-node");q=Q.matches(":focus-visible")?dt:null,mt(v,_)&&_.stop!==dt&&U(dt),g()}}function nt(N){var Q=R(N.target);Q&&(R(N.relatedTarget)||(q=null),_.keep===Q.getAttribute("data-node")&&P(Object.assign({},_,{keep:void 0})),g())}function J(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var Q=R(N.target);Q&&S();var dt=Q&&mt(v,_)?Q.getAttribute("data-node"):null;dt!==W&&(W=dt,g())}}function ot(){W&&(W=null,g())}function X(){S(),P(Object.assign({},_,{open:!_.open,autoOpen:void 0})),T()}l.addEventListener("keydown",K),l.addEventListener("focusin",et),l.addEventListener("focusout",nt),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",ot),l.addEventListener("click",L),z&&z.addEventListener("click",X),H();var st=l.clientWidth,rt=0,ct=!0,bt=new ResizeObserver(function(){Math.abs(l.clientWidth-st)<.5||(st=l.clientWidth,cancelAnimationFrame(rt),rt=requestAnimationFrame(H))});bt.observe(l),document.fonts&&document.fonts.ready.then(function(){ct&&H()});var xt=matchMedia("(forced-colors: active)"),Se=v.nodes.some(function(N){return N.mark});Se&&xt.addEventListener("change",H),Y&&(p=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return V&&V.geo},tokens:function(){return V&&V.tokens}},b));var Ee=!c&&b.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,b,{model:v,settle:S,animated:Y}):null;l.__diagram={stop:function(){Ee&&Ee.destroy(),ct=!1,bt.disconnect(),cancelAnimationFrame(rt),Se&&xt.removeEventListener("change",H),p&&p.destroy(),l.removeEventListener("keydown",K),l.removeEventListener("focusin",et),l.removeEventListener("focusout",nt),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",ot),l.removeEventListener("click",L),m&&m.remove(),z&&z.removeEventListener("click",X)},layout:H,key:y(b),send:p&&p.sendValue?p.sendValue:null}}function y(l){try{return JSON.stringify(l,function(b,$){return b==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function h(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var b=l.querySelector(":scope > script[data-diagram]");if(b)try{u(l,JSON.parse(b.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:_t,figureKey:ze,figureList:Ve,hintEntries:Wt,toHtml:Bt,escapeHtml:it,settleEntrance:ve,measureFigure:we},t.diagram=function(l,b){var $=l.__diagram,c=$&&$.send?y(b):null;if(c!==null&&c===$.key){$.send(b.packet?b.packet.send:void 0);return}u(l,b)},e.step(62,"wireDiagrams",h)})(window.Basalt)})(); +`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Dt(t,e){return t.legend[e]}function Oe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Ie(t,e){return $t(t,`sentence:${e.i}`,()=>_e(t,e))}function _e(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Gt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Oe(t,e):e.kind;if(n.push(wt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${gt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${gt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Gt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function Ce(t,e,n,s){const r=n.pointerType;if(r!=="touch"&&r!=="pen")return;const o=t.querySelector(`.${e}-drawing`),a=n.target;if(!o||!a||!o.contains(a)||!t.querySelector(`.${e}-edge`))return;const i=a.closest(`.${e}-node`);if(!i?.hasAttribute("href"))return i?i.dataset.node===s?null:i.dataset.node??null:null}function Kt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var je={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>je[e]),Be=" br img input meta link hr path polygon polyline circle rect line ";function Bt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${it(String(r))}"`}return Be.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Bt(s,e)).join("")}`}var Te=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Re(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Et(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Vt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=Et(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Zt(t,n,a)))})}return e})}function Zt(t,e,n){const s=Et(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=Et(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Ut(t){const e=Vt(t);return e[1]+e[3]}function Tt(t){return t.type==="sequence"?t.nodes.length:t.cols}function Jt(t){return $t(t,"plan",()=>We(t))}function We(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},m=t.edges.map(()=>0);let p=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,m[v.k]+1));m[c.k]=f,f>1&&(p=!0),l.push(c)}const b=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{b[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const w=ht();for(let c=1;c{const _=s[G],Z=t.byId.get(D.from).i,L=t.byId.get(D.to).i,z=L===c&&(_==="down"||_==="trunk"||_==="rail"||_==="end-down"),O=Z===c&&L===c-1&&_==="up",A=L===c-1&&_==="end-up";z&&(_==="trunk"||_==="end-down")&&(M=!0),A&&(I=!0),(z||O||A)&&D.label&&(B++,C=Math.max(C,_==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),w[f.id]=C}return{routes:s,gutter:d,lanes:m,exits:b,gaps:w,third:p}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Xt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function kt(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Yt(t,e){return $t(e,`key:${t}`,()=>Fe(t,e))}var ze=Yt;function Fe(t,e){const n=[],s=(o,a,i={})=>n.push(k("li",{class:`${t}-entry`,...i},o,k("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),k("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(kt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(kt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(kt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Xt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Xt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),k("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(kt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(kt(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function He(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Rt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Ne(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},Rt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},Rt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Ot(n.detail).flatMap((r,o)=>[o?" ":"",k("span",{class:`${t}-run`},r)]):n.detail)),s}function De(t,e,n){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},Rt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((s,r)=>k("span",{class:`${t}-row`,"data-row":r,"data-key":s.key},k("span",{class:`${t}-keyseat`},s.key??""),k("span",{class:`${t}-cname`},s.name),s.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?k("span",{class:`${t}-ctype`},s.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Qt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=Re(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=yt(d.gaps,n.id)??32,b=yt(s.grow,n.id)??0;i.push(`--_gap:${b?`calc(${Qt(l)} + var(--basalt-space-4) * ${b})`:Qt(l)}`)}const u=yt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const m=yt(s.words,n.id);m&&i.push(`--_ww:${m}px`);const p=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?Ie(e,n):void 0,tabindex:p},n.shape==="decision"?k("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ht(n.mark.onLight)};--_md:${Ht(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?De(r,n,e):Ne(r,e,n))}function Ge(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=Et(e,d);if(!u)continue;const m=[0,1,2,3].map(p=>Zt(e,d,p));r.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`},At(t,e,d,n))))),r.push(Ke(t,e)),r;const o=d=>{const u=d.group?e.groups.find(m=>m.id===d.group):void 0;return u?.parent?e.groups.find(m=>m.id===u.parent):u},a=(d,u,m)=>{const p=t.plan?yt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:p?`--_ggrow:${p}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),m)};let i=0;for(;ic.id===m[l].group):void 0;if(!b){p.push(At(t,e,m[l],n)),l++;continue}const w=[];for(;lAt(t,e,c,n))))}r.push(a(u,m,p))}return r}function Ke(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(k("p",{class:`${n}-band`},k("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=k("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=k("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),m=d?.col??1,p=u?.col??1,l=m===p,b=l&&(e.rtl?m!==1:m===e.nodes.length),w=Dt(e,i.kind);a.c.push(k("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?b?"start":"end":void 0,style:`--_a:${Math.min(m,p)};--_b:${Math.max(m,p)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(i.n)),k("span",{class:`${n}-mlabel`},i.label)),k("span",{class:`${n}-route`},d?.short??i.from," ",He(n,i.kind),k("span",{class:t.hidden}," to ")," ",u?.short??i.to,w?` · ${w}`:""),i.note?k("span",{class:`${n}-note`},i.note):null))}return k("div",{class:`${n}-steps`},s)}function Pt(t,e){return $t(e,`list:${t}`,()=>Ze(t,e))}var Ve=Pt;function Ze(t,e){const n=Math.min(6,e.heading+1),s=p=>k(`h${n}`,{class:`${t}-list-head`},p),r=p=>k("strong",null,p),o=p=>p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},r(p.name)):r(p.name),a=p=>k("code",{class:`${t}-code`},p),i=p=>e.byId.get(p)?.name??p,d=p=>{const l=Dt(e,p);return l?` (${l})`:""},u=p=>p.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const p=w=>k("li",null,o(w),w.kind?`, ${w.kind}`:"",w.detail?[". ",w.mono?a(w.detail):w.detail,/[.!?]$/.test(w.detail)?"":"."]:/[.!?]$/.test(w.kind??w.name)?"":".",u(w)),l=[s("Parts")],b=e.nodes.filter(w=>!w.group);b.length&&l.push(k("ul",{class:`${t}-list-items`},b.map(p)));for(const w of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},w.label)),w.members.length&&l.push(k("ul",{class:`${t}-list-items`},w.members.map(c=>p(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===w.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>p(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map(w=>k("li",null,r(i(w.from))," to ",r(i(w.to)),w.label?[": ",a(gt(w.label))]:"",`${d(w.kind)}.`)))),l}if(e.type==="flowchart"){const p=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const b=e.edges.filter(f=>f.from===l.id),w=l.shape==="decision"?"Decision":l.shape==="terminal"?b.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${w}.`,u(l),b.length?k("ul",{class:`${t}-list-exits`},b.map(f=>k("li",null,f.label?`If ${gt(f.label)}: go to ${p(f.to)}, `:`Then: go to ${p(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(p=>{const l=e.edges.filter(b=>b.from===p.id);return k("li",null,`${p.laneLabel}: `,o(p),p.detail?[", ",p.mono?a(p.detail):p.detail]:"",".",u(p),l.length?[" Then ",...l.flatMap((b,w)=>[w?"; ":"",`to step ${e.byId.get(b.to).step}, `,r(i(b.to)),b.label?[": ",a(gt(b.label))]:"",d(b.kind)]),"."]:"")}))];if(e.type==="sequence"){const p=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(b=>k("li",null,r(b.name),b.kind?`, ${b.kind}`:"",".",u(b),Gt(e,b))))];p.push(s("Messages"));let l=null;for(const b of e.steps){if("band"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},b.band));continue}if("open"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords[b.open]}: ${b.label}`));continue}if("otherwise"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords.else}: ${b.otherwise}`));continue}if("close"in b){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:b.n}),p.push(l)),l.c.push(k("li",null,a(b.label),": ",r(i(b.from))," to ",r(i(b.to)),`${d(b.kind)}.`,b.note?` ${wt(b.note)}`:""))}return p}const m=[];for(const p of e.nodes)m.push(k(`h${n}`,{class:`${t}-list-group`},p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},a(p.name)):a(p.name),u(p))),m.push(k("ul",{class:`${t}-list-items`},[...(p.columns??[]).map(l=>k("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...p.more?[k("li",null,`and ${p.more} more ${p.more===1?"column":"columns"}`)]:[]]));return m}function te(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Lt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Wt(t,e=!1){const n=e&&t.type!=="sequence"&&Lt(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Kt(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var Ue=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Lt(t){return $t(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...Je(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=w=>i?[w.col,w.col]:w.rows,m=w=>i?w.rows:[w.col,w.col],p=u(o),l=m(o);let b=null;return e.forEach((w,c)=>{if(w===o)return;const f=u(w),v=m(w),B=d?f[0]-p[1]:p[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!b||Ue(M,b.rank))&&(b={id:w.id,rank:M})}),b?.id??null},s=ht();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var ee=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function ne(t,e,n){const s=n.prefix,r=Te(n.base),o=t.type==="sequence"||t.type==="schema"?null:Jt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,m=`h${t.heading}`,p=[`--_cols:${Tt(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Vt(t):[0,0,0,0],b=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",w=i&&e.pad?"3":void 0;p.push(`--_gpad:${b(l[0],"8",w)} ${b(l[1],"4")} ${b(l[2],"4",w)} ${b(l[3],"4")}`)}return ee(t)&&p.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&p.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Tt(t),"data-reach":t.type==="architecture"?Ut(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:p.join(";")},k("div",{class:`${s}-head`},k(m,{id:r.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},Ge(a,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Yt(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||i&&t.type==="sequence"?k("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${Kt(t)} to highlight its lines. Tap it again to clear.`):null,k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Pt(s,t)),k("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${te(t,i)} ${n.viewer}`:te(t,i)),k("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Xe(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var qt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,oe=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2,p=e==="top"||e==="bottom";if(t.shape==="decision"){if(p){const w=n,c=m*Math.max(0,1-Math.abs(w-i)/u);return{x:w,y:e==="top"?d-c:d+c}}const l=n,b=u*Math.max(0,1-Math.abs(l-d)/m);return{x:e==="left"?i-b:i+b,y:l}}if(t.shape==="terminal"){const l=Math.min(u,m);if(p){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const b=n,w=b-d,c=Math.abs(w)>=l?0:Math.sqrt(l*l-w*w);return{x:e==="left"?s+l-c:o-l+c,y:b}}return p?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Ye(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/m<1-n/Math.min(u,m);if(e.shape==="terminal"){const p=Math.min(u,m),l=Math.min(Math.max(t.x,s+p),o-p);return Math.hypot(t.x-l,t.y-d)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function tn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var Ot=t=>t?t.split(/\s+/).filter(Boolean):[];function en(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`${t.rtl?"←":"→"} ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),m=d.mark&&!Pe()?(d.shape==="participant"?2:1)*s("6"):0;let p=0;const l=d.href?16+s("1-5"):0,b=Ot(d.name);if(b.forEach((c,f)=>{p=Math.max(p,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:m)+(f===b.length-1?l:0))}),t.type!=="data-flow")for(const c of Ot(d.kind))p=Math.max(p,n(c,"mono")+m);for(const c of Ot(d.detail))p=Math.max(p,n(c,d.mono?"mono":"sans"));const w=d.shape==="decision"?p/.62:p+u+2*e.hair;r=Math.max(r,Math.ceil(w))}const a=Tt(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(ee(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Ut(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ae(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function zt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function re(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function It(t,e,n){const s=[];for(let o=0;oMath.min(c.x,f.x)+.75&&CMath.min(v.y,B.y)+.75&&Mr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",ie={top:"bottom",bottom:"top",left:"right",right:"left"};function on(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function sn(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,m]=e[a],p=i.row===d.row&&tt(u)&&tt(m)&&u===ie[m]||i.col===d.col&&!tt(u)&&!tt(m)&&u===ie[m];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:p,f:.5},{edge:a,end:"to",node:d,side:m,far:i,straight:p,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const m=new Map;for(const c of d)m.has(c.far.id)||m.set(c.far.id,[]),m.get(c.far.id).push(c);for(const c of m.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const p=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),b=u.filter(c=>i(c)<0),w=u.filter(c=>i(c)>=0);b.forEach((c,f)=>{c.f=p*(f+1)/(b.length+1)}),w.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/(w.length+1)})}return s}function le(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?lt(t,e,r+(a-r)*n):lt(t,e,s+(o-s)*n)}function ce(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ft(o,n),shape:a.shape,i:a.i})}),r}function de(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function ue(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function an(t,e,n,s,r,o,a,i,d){const u=a.space,m=[],p=[],l=[],b=[],w=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*jt(v),M=f.pts.length-2,I=[];pt(f.pts).forEach(([L,z],O)=>{const A=Math.abs(L.y-z.y)<.01,j=A?L.x:L.y;let F=A?z.x:z.y;const V=Math.sign(F-j)||1;O===M&&(F-=V*a.head);let W=[[j,F]];for(const $ of r)for(const S of A?[$.l,$.r]:[$.t,$.b]){const g=A?L.y:L.x;(A?g>$.t&&g<$.b:g>$.l&&g<$.r)&&(W=W.flatMap(([x,E])=>S>Math.min(x,E)+1&&S{const g=($+S)/2,y=A?{x:g,y:L.y}:{x:L.x,y:g};return!r.some(x=>y.x>x.l&&y.xx.t&&y.y1&&Y($,S)?1:0})}),I.sort((L,z)=>z.pri-L.pri||z.len-L.len);let D=null,G=!1;const _=(L,z=!0)=>{const O=oe(L,w);return z&&(L.lo.r||L.to.b)||n.some(A=>se(O,A))||m.some(A=>ut(O,A))||s.heads.some(A=>ut(O,A))||s.rects.some(A=>ut(O,A))?!1:!e.some(A=>A.i!==f.i&&pt(A.pts).some(([j,F])=>ut(O,fe(j,F,A.width))))};for(const L of I){for(const z of[1/2,1/3,2/3]){const O=L.p+(L.q-L.p)*z,A=[],j=u("2")+f.width/2;if(L.horiz?(L.len>=B+2*u("1")+u("3-5")&&A.push({box:{l:O-B/2-u("1"),r:O+B/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),A.push({box:{l:O-B/2,r:O+B/2,t:L.c-j-C,b:L.c-j},on:!1}),A.push({box:{l:O-B/2,r:O+B/2,t:L.c+j,b:L.c+j+C},on:!1})):(L.len>=C+u("3")&&A.push({box:{l:L.c-B/2-u("1"),r:L.c+B/2+u("1"),t:O-C/2,b:O+C/2},on:!0}),A.push({box:{l:L.c+j,r:L.c+j+B,t:O-C/2,b:O+C/2},on:!1}),A.push({box:{l:L.c-j-B,r:L.c-j,t:O-C/2,b:O+C/2},on:!1})),D=A.find(F=>_(F.box))??null,D)break;!G&&A.some(F=>_(F.box,!1))&&(G=!0)}if(D)break}if(!D){l.push(f.i),G&&b.push(f.i);continue}const Z=ue(D.box,d.ox,d.oy,L=>_(L));m.push(Z),p.push({i:f.i,text:v,box:Z,on:D.on})}return{labels:p,unseated:l,bounded:b}}function he(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=ft(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(ft(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=ft(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(ft(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function rn(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,m=ce(s,a,i,o),p=[...m.values()],l=nn(a),b=i.left-Math.floor(i.left),w=i.top-Math.floor(i.top),c=ae(b,w),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:b,oy:w};if(s.type==="sequence")return cn(t,M,c);let I,D=[];s.type==="schema"?I=s.edges.map(g=>{const y=s.byId.get(g.from),x=s.byId.get(g.to);if(y.col===x.col){const E=y.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return x.col>y.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const y=s.byId.get(g.from),x=s.byId.get(g.to),[E,q]=on(y,x);return[g.fromSide??E,g.toSide??q]}),D=sn(s,I,d||(()=>{})));const G=(g,y)=>{const x=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${y}"]`);if(!x)return 0;const E=ft(x,i);return(E.t+E.b)/2},_=s.edges.map((g,y)=>{const[x,E]=I[y],q=m.get(g.from),T=m.get(g.to),H=qt(g.kind,r);if(g.fk){const J=G(g.from,g.fromRow),ot=G(g.to,g.toRow),X=c.y(J,H),st=c.y(ot,H);return{p1:{x:x==="right"?q.rect.r:q.rect.l,y:X},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:J,r2:Math.abs(X-st)<.01?J:ot}}const Q=D.find(J=>J.edge===y&&J.end==="from").f,U=D.find(J=>J.edge===y&&J.end==="to").f;let R=le(q,x,Q),K=le(T,E,U);const et=tt(x)?R.y:R.x;let nt=tt(E)?K.y:K.x;return tt(x)?R={...R,y:c.y(R.y,H)}:R={...R,x:c.x(R.x,H)},tt(E)?K={...K,y:c.y(K.y,H)}:K={...K,x:c.x(K.x,H)},tt(x)&&tt(E)&&Math.abs(R.y-K.y)<1.01&&(K={...K,y:R.y},nt=et),!tt(x)&&!tt(E)&&Math.abs(R.x-K.x)<1.01&&(K={...K,x:R.x},nt=et),R=tt(x)?lt(q,x,R.y):lt(q,x,R.x),K=tt(E)?lt(T,E,K.y):lt(T,E,K.x),{p1:R,p2:K,r1:et,r2:nt}}),Z=new Set;s.type==="schema"&&s.edges.forEach((g,y)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&Z.add(y)});const L=new Map,z=new Set;s.edges.forEach((g,y)=>{if(Z.has(y))return;const[x,E]=I[y],{p1:q,p2:T}=_[y],H=s.byId.get(g.from),Q=s.byId.get(g.to);let U=null,R=null,K=!1;if(x===E){if(tt(x)){const J=x==="right"?Math.max(B(H),B(Q)):Math.min(B(H),B(Q))-1,ot=l.cols[J-1],X=l.cols[J];ot&&X&&(U=`c${J}`,R=[ot[1],X[0]],K=!0)}else{const J=x==="bottom"?Math.max(H.row2,Q.row2):Math.min(H.row,Q.row)-1,ot=l.rows[J-1],X=l.rows[J];ot&&X&&(U=`r${J}`,R=[ot[1],X[0]],K=!1)}U&&z.add(y)}else if(tt(x)&&tt(E)&&Math.abs(q.y-T.y)>.5){const J=B(Q),ot=E==="left",X=l.cols[(ot?J-1:J)-1],st=l.cols[(ot?J:J+1)-1];X&&st&&(U=`c${ot?J-1:J}`,R=[X[1],st[0]],K=!0)}else if(!tt(x)&&!tt(E)&&Math.abs(q.x-T.x)>.5){const ot=E==="top"?Q.row-1:Q.row2,X=l.rows[ot-1],st=l.rows[ot];X&&st&&(U=`r${ot}`,R=[X[1],st[0]],K=!1)}if(!U||!R)return;L.has(U)||L.set(U,{span:R,vertical:K,members:new Map});const et=`${g.to}.${E}.${Math.round(K?T.y:T.x)}`,nt=L.get(U);nt.members.has(et)||nt.members.set(et,[]),nt.members.get(et).push(y)});const O=new Map,A=g=>{const[y,x]=I[g],{p1:E,p2:q}=_[g];if(tt(y)&&tt(x)){if(y===x){const H=O.get(g)??(y==="right"?Math.max(E.x,q.x)+u("4"):Math.min(E.x,q.x)-u("4"));return[E,{x:H,y:E.y},{x:H,y:q.y},q]}if(Math.abs(E.y-q.y)<=.5)return[E,{x:q.x,y:E.y}];const T=O.get(g)??(E.x+q.x)/2;return[E,{x:T,y:E.y},{x:T,y:q.y},q]}if(!tt(y)&&!tt(x)){if(y===x){const H=O.get(g)??(y==="bottom"?Math.max(E.y,q.y)+u("4"):Math.min(E.y,q.y)-u("4"));return[E,{x:E.x,y:H},{x:q.x,y:H},q]}if(Math.abs(E.x-q.x)<=.5)return[E,{x:E.x,y:q.y}];const T=O.get(g)??(E.y+q.y)/2;return[E,{x:E.x,y:T},{x:q.x,y:T},q]}return tt(y)?[E,{x:q.x,y:E.y},q]:[E,{x:E.x,y:q.y},q]},j=g=>{const y=s.edges[g],x=qt(y.kind,r),E=A(g),q=re(E,x,c);let T;return E.length===q.length&&(T=pt(E).map(([H,Q])=>Math.abs(H.y-Q.y)<.75?(H.y+Q.y)/2:(H.x+Q.x)/2),T[0]=_[g].r1,T.length>1&&(T[T.length-1]=_[g].r2)),{i:g,from:y.from,to:y.to,kind:y.kind,pts:q,tip:q[q.length-1],dir:zt(q),dot:y.fk?q[0]:void 0,width:x,axes:T}},F=()=>s.edges.flatMap((g,y)=>Z.has(y)?[]:[j(y)]);let V=null;const W=g=>{V??(V=F());const y=V.map(x=>g.has(x.i)?j(x.i):x);return{lines:y,score:ln(y,g)*1e5+It(y,void 0,g).length*1e3+Ft(y.filter(x=>g.has(x.i)),p,s).length}},Y=(g,y)=>{const x=g.flatMap(E=>{const{p1:q,p2:T}=_[E];return y?[q.y,T.y]:[q.x,T.x]});return[Math.min(...x),Math.max(...x)]};for(const[,g]of L){const y=[...g.members.values()].map(E=>({members:E,run:Y(E,g.vertical)})).sort((E,q)=>E.run[0]-q.run[0]),x=[];for(const E of y){const q=x[x.length-1];q&&q.some(T=>T.run[0]z.has(et)))continue;const q=E.map(et=>et.members),T=q.length,H=(g.span[1]-g.span[0])/(T+1);HJ.forEach(X=>O.set(X,g.span[0]+H*(ot+1))));const nt=W(Q);nt.scoreet.forEach(J=>O.set(J,g.span[0]+H*(nt+1)))),V=K}}M.lines=F();for(const g of Z)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=It(M.lines),M.through=Ft(M.lines,p,s),M.outside=me(M.lines,f,v,r);const{obstacles:h,groups:$}=he(a,i,o,C);h.heads=M.lines.map(g=>de(g,r));const S=an(s,M.lines,p,h,$,{l:0,t:0,r:f,b:v},r,e,{ox:b,oy:w});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(pe(M.lines,null).flat())],M}function ln(t,e){return pe(t,e).length}function pe(t,e){const n=[];for(let s=0;s=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[m.x,p.x]:[m.y,p.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*ge(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Ft(t,e,n){const s=[];for(const r of t){const o=pt(r.pts);e.some(a=>o.some(([i,d])=>Qe(i,d,a)))&&s.push(r.i)}return s}function cn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,ft(M,i)));const m=a.querySelector(`.${o}-steps`),p=m?ft(m,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:p})}const b=M=>u.get(M.id),w=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=ft(M,i);w.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const D=l(M.who),_=(I.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),Z=(M.depth-1)*d("1")*_,L=w.get(M.from)??0,z=w.get(M.to)??L,O=M.from===M.to;return{l:n.x(D-f+Z,r.hair),r:n.x(D+f+Z,r.hair),t:n.y(O?L-d("2")-d("1"):L,r.hair),b:n.y(O?L+d("2")+d("1"):z,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,D)=>B.filter(({bar:G})=>G.who===M&&G.to>=I&&(D?G.from<=I:G.from_.bar.depth-G.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,D=M.dataset.to,G=M.dataset.kind??"plain",_=qt(G,r),Z=ft(M,i),L=n.y((Z.t+Z.b)/2,_),z=Number(M.querySelector(`.${o}-num`)?.textContent??0);let O=l(I),A=l(D),j;if(I===D){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,z,!0),y=g?S>0?g.r:g.l:O,x=n.y(L-d("2"),_),E=n.y(L+d("2"),_);j=[{x:y,y:x},{x:n.x(O+S,_),y:x},{x:n.x(O+S,_),y:E},{x:y,y:E}]}else{const S=A>O?1:-1,g=C(I,z,!1),y=C(D,z,!0);g&&(O=S>0?g.r:g.l),y&&(A=S>0?y.l:y.r),j=[{x:O,y:L},{x:A,y:L}]}e.lines.push({i:z,from:I,to:D,kind:G,pts:j,tip:j[j.length-1],dir:zt(j),width:_});const F=M.querySelector(`.${o}-said`),V=M.querySelector(`.${o}-note`),W=s.byId.get(I),Y=s.byId.get(D);if(!W||!Y)return;const h=I===D?(()=>{const S=s.nodes[W.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-O)-d("6")-d("2-5")-d("2")})():Math.abs(A-O)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,V?V.getBoundingClientRect().width:0)>h+.5&&e.unseated.push(z)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((G,_)=>G+_.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ye(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,m=ce(r,i,d,a),p=[...m.values()],l=d.left-Math.floor(d.left),b=d.top-Math.floor(d.top),w=ae(l,b),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:b},B=ht();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(A,j,F)=>{const V=[A];for(let W=1;W<=(yt(s,j)??0);W++)V.push({...A,t:A.t+F*u("4")*W,b:A.b+F*u("4")*W});return V},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(A=>{const j=A.parentElement,F=ft(j,d),V=getComputedStyle(j);I.set(A.dataset.node,F.r-(parseFloat(V.paddingRight)||0)-(parseFloat(V.borderRightWidth)||0))});const D=r.nodes,G=A=>m.get(D[A].id),_=[],Z=A=>qt(r.edges[A].kind,o);r.edges.forEach((A,j)=>{const F=n.routes[j],V=m.get(A.from),W=m.get(A.to),Y=Z(j);let h=[];const $=A.label,S=$?e($,"label"):0,g=$?16*jt($):16,y=u("4");if(F==="down"||F==="up"){const E=Math.max(V.rect.l,W.rect.l),q=Math.min(V.rect.r,W.rect.r),T=r.edges.map((R,K)=>({o:R,j:K})).filter(({o:R,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(R.from===A.from&&R.to===A.to||R.from===A.to&&R.to===A.from)),H=T.findIndex(R=>R.j===j),Q=T.length<2?.5:T.length===2?H===0?.25:.75:(H+1)/(T.length+1),U=w.x(E+(q-E)*Q,Y);if(h=F==="down"?[lt(V,"bottom",U),lt(W,"top",U)]:[lt(V,"top",U),lt(W,"bottom",U)],$){let R=Math.min(h[0].y,h[1].y),K=Math.max(h[0].y,h[1].y);F==="down"?K-=o.head:R+=o.head;const et=[...i.querySelectorAll(`.${a}-group`)].map(X=>ft(X,d));let nt=[[R,K]];for(const X of et)for(const st of[X.t,X.b])nt=nt.flatMap(([rt,ct])=>st>rt+1&&stet.some(rt=>(X+st)/2>rt.t&&(X+st)/2rt.l&&U1){const X=nt.filter(([rt,ct])=>!J(rt,ct));[R,K]=(X.length?X:nt).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const ot=[1/2,1/3,2/3].map(X=>{const st=R+(K-R)*X;return{l:U-S/2-u("1"),r:U+S/2+u("1"),t:st-g/2,b:st+g/2}});_.push({k:j,cands:ot,on:!0,card:F==="down"?A.to:A.from})}}else if(F==="trunk"||F==="rail"){const E=w.x(Math.max(V.rect.l,F==="rail"?W.rect.l:V.rect.l)+u(F==="trunk"?"8":"3"),Y),q=lt(V,"bottom",E);if(F==="rail"){if(h=[q,lt(W,"top",E)],$){const T=W.rect.t-u("6");_.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},A.to,-1),on:!1,card:A.to})}}else{const T=w.x(W.rect.l+u("6"),Y),H=w.y(W.rect.t-y,Y);h=[q,{x:E,y:H},{x:T,y:H},lt(W,"top",T)],$&&_.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:H-g/2,b:H+g/2},A.to,-1),on:!1,card:A.to})}}else{const E=Math.min(I.get(A.from)??c,I.get(A.to)??c),q=w.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),Y),T=w.y(V.rect.t+(V.rect.b-V.rect.t)*n.exits[j],Y),H=lt(V,"right",T),Q=w.x(W.rect.r-u("6"),Y),U=F==="end-down",R=w.y(U?W.rect.t-y:W.rect.b+y,Y);h=[H,{x:q,y:H.y},{x:q,y:R},{x:Q,y:R},lt(W,U?"top":"bottom",Q)];const K=U?A.to:D[W.i+1]?.id??A.to;$&&_.push({k:j,cands:M({l:Q-u("2-5")-S,r:Q-u("2-5"),t:R-g/2,b:R+g/2},K,U?-1:1),on:!1,card:K})}const x=re(h,Y,w);v.lines.push({i:j,from:A.from,to:A.to,kind:A.kind,pts:x,tip:x[x.length-1],dir:zt(x),width:Y})}),v.crossings=It(v.lines),v.through=Ft(v.lines,p,r),v.outside=me(v.lines,c,f,o);const{obstacles:L}=he(i,d,a,0);L.heads=v.lines.map(A=>de(A,o));const z=[],O={l:0,t:0,r:c,b:f};for(const A of _){const j=W=>{const Y=oe(W,u("1"));return W.lO.r+.5||W.tO.b+.5||p.some(h=>se(Y,h))||z.some(h=>ut(Y,h))||L.heads.some(h=>ut(Y,h))||L.rects.some(h=>ut(Y,h))||v.lines.some(h=>h.i!==A.k&&pt(h.pts).some(([$,S])=>ut(Y,fe($,S,h.width))))},F=A.cands.find(W=>!j(W));F||(B[A.card]=(B[A.card]??0)+1,v.unseated.push(A.k));const V=F?ue(F,l,b,W=>!j(W)):A.cands[0];z.push(V),v.labels.push({i:A.k,text:r.edges[A.k].label,box:V,on:A.on})}return{geo:v,grow:B}}function dn(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...M})),p=m[m.length-1];p.x-=o.x*u,p.y-=o.y*u;const l=e.tip.x-o.x*i,b=e.tip.y-o.y*i,w=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=it(e.kind),B=a?``:``,C=e.dot?``:"";return`${B}${C}`}function be(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const m=d.map(p=>{const l=e.lines[p.top],b=e.lines[p.under],w=l.width/2+n.cut,c=b.width/2+1;return p.underVertical?``:``}).join("");a+=`${m}`}return{defs:a,ids:r}}function $e(t,e,n,s){const{defs:r,ids:o}=be(t,e,n,s),a=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),i=e.lines.map((m,p)=>un(t,m,n,o.get(p)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),d=`${r?`${r}`:""}${a}${i}`,u=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` +`).map(it).join("
")}
`).join("");return d+u}function we(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const m=Xe(t),p=tn(u,n),l=en(e,m,p);i?.(l.least);const b=t.clientWidth,w=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),c=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:w&&L.layout!=="drawn"?w:void 0};let f=!1;const v=L=>{if(f=!1,e.type!=="flowchart")return L;o({...L,heights:void 0,words:void 0});const z=ht(),O=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(A=>{const j=A.querySelector(`.${n}-words`);if(!j)return;const F=A.getBoundingClientRect(),V=h=>{const $={w:h.width+2*m.space("2-5"),h:h.height+2*m.space("2")},S=1-$.w/F.width,g=S>.05?$.h/2/S:$.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},W=j.getBoundingClientRect();let Y=V(W);if(Y>F.width){const h=y=>(A.style.setProperty("--_ww",`${y}px`),j.getBoundingClientRect()),$=Math.floor(A.clientWidth-2*m.space("2-5"));let S=Math.ceil(W.width),g=W.height;for(;S<$&&h($).height1;){const T=y+x>>1;h(T).heightF.width&&(f=!0)}),{...L,heights:z,words:Object.keys(O).length?O:void 0}},B=()=>({m:e,tk:m,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(L,z)=>z.map(O=>Mt(e,L.lines.find(A=>A.i===O))).join(", ");if(b>=l.least){const L=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:rn(B(),p)}};let{dd:z,g:O}=L(!1);const A=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!A(O)&&O.unseated.length&&O.unseated.every(j=>O.bounded?.includes(j))){const j=L(!0);!A(j.g)&&!j.g.unseated.length&&({dd:z,g:O}=j)}if(!A(O)&&!O.unseated.length)return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the drawn layout: ${O.crossings.map(j=>`${Mt(e,O.lines[j.top])} over ${Mt(e,O.lines[j.under])}`).join("; ")}`),{dyn:z,geo:O,ink:$e(n,O,m,s),tokens:m,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: a decision would be taller than it is wide`),O.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${O.misfit.join("; ")}`),O.through.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.through)} would pass through a node`),O.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.overlaps)} would lie on one another`),O.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.outside)} would leave the drawing`),O.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: no clean seat for ${O.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:m,least:l.least};const D=Jt(e);let G=ye(B(),p,D,I.grow);for(let L=0;L<6&&Object.keys(G.grow).length;L++){const z=ht(I.grow);for(const[O,A]of Object.entries(G.grow))z[O]=(yt(z,O)??0)+A;I={...I,grow:z},o(I),G=ye(B(),p,D,z)}const _=G.geo;if(_.unseated.length>0||_.through.length>0||_.outside.length>0||D.third){_.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(_.unseated)].map(O=>`"${e.edges[O]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),_.through.length&&a?.(`in the stacked drawing ${M(_,_.through)} would pass through a node, so its lines are not drawn`),_.outside.length&&a?.(`in the stacked drawing ${M(_,_.outside)} would leave the drawing, so its lines are not drawn`),D.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={..._,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:L,ink:"",tokens:m,least:l.least}}return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${_.crossings.map(L=>`${Mt(e,_.lines[L.top])} over ${Mt(e,_.lines[L.under])}`).join("; ")}`),{dyn:I,geo:_,ink:$e(n,_,m,s),tokens:m,least:l.least}}function Mt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function hn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const m=It(n.lines,i),{defs:p,ids:l}=be(e,{...n,crossings:m},s,r),b=t.querySelector(`.${e}-svg`);if(!b)return;let w=b.querySelector("defs");!w&&p&&(w=document.createElementNS("http://www.w3.org/2000/svg","defs"),b.insertBefore(w,b.firstChild)),w&&(w.innerHTML=p),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var pn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function gn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",pn()||yn(t)?"done":"pending")}}var mn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function yn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(mn(t))!==null}catch{return!1}}function ve(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function bn(t,e,n,s=!1,r=!1){const o=s?Lt(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var $n=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],xe=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],wn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ke=t=>t==null||t===!1;function vn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Me(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?xe:$n;for(const a of s)ke(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,m=new Map(String(i??"").split(";").map(p=>{const l=p.indexOf(":");return[p.slice(0,l).trim(),p.slice(l+1).trim()]}).filter(([p])=>p));for(const[p,l]of m)u.getPropertyValue(p).trim()!==l&&u.setProperty(p,l);for(const p of wn)m.has(p)||u.removeProperty(p);continue}if(n&&!xe.includes(a))continue;if(ke(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,b,w){return{prefix:n,base:l,hasSource:b.source!==void 0&&b.source!==null&&b.source!=="",hiddenClass:"visually-hidden",viewer:w?w.keys:void 0}}function o(l,b,w,c){var f=function(v){return''+it(v)+""};return{source:it(String(b.source||"")),summary:it(String(b.summary||"")),hint:Wt(l).map(function(v){return""+v.keys.map(f).join(" ")+" "+it(v.words)+""}).join(""),toggle:'"}}function a(l,b,w){var c=_t(l),f=ne(c,{},r(b,l,w)),v=Bt(f,o(c,l,b,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,b,w,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=_t(b,{rtl:getComputedStyle(l).direction==="rtl"});if(!w||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(b,f,c),C=document.createElement("div");C.innerHTML=B.open+"";var M=C.firstChild;i.forEach(function(N){l.removeAttribute(N)}),d.forEach(function(N){l.style.removeProperty(N)});for(var I=0;I :not(script[data-diagram])").forEach(function(N){N.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var G=r(f,b,c),_={},Z=null,L=null,z=null,O=null,A=Object.create(null),j=function(N){A[N]||(A[N]=1,console.warn("Basalt diagram: "+N))},F=function(N){Me(l,ne(v,N,G))},V=l.querySelector(".diagram-ink"),W=l.querySelector(".diagram-toggle"),Y=!c&&v.motion.animated&&typeof e.diagramMotion=="function",h=null,$=null,S=function(){Y&&ve(l)};function g(){hn(l,n,Z&&Z.geo,Z&&Z.tokens,f,L||O||z),E()}var y=null,x=!c&&matchMedia("(hover: none), (pointer: coarse)").matches;function E(){var N=x&&!c&&V&&V.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(x&&!c)),N&&!y){var P=l.querySelector(":scope > .diagram-foot");if(!P)return;y=document.createElement("button"),y.type="button",y.className="btn diagram-clear",y.setAttribute("data-variant","secondary"),y.setAttribute("data-size","sm"),y.innerHTML="Clear highlight",y.addEventListener("click",function(){O&&(O=null,g())}),P.appendChild(y)}else!N&&y&&(y.remove(),y=null);y&&(O?y.removeAttribute("aria-disabled"):y.setAttribute("aria-disabled","true"))}function q(N){if(!N.defaultPrevented){var P=Ce(l,n,N,O);P!==void 0&&(S(),x=!0,O=P,g())}}function T(){W&&(W.setAttribute("aria-expanded",String(!!_.open)),W.firstElementChild.textContent=_.open?"Hide the list":"View as list")}function H(){Z=(c?c.measure:we)(l,v,n,f,_,F,j),_=Z.dyn,F(_),T();var N=l.querySelector(":scope > .diagram-hint");if(N){var P=Wt(v,_.layout==="drawn").map(function(St){return""+St.keys.map(function(kn){return''+it(kn)+""}).join(" ")+" "+it(St.words)+""}).join("");N.innerHTML!==P&&(N.innerHTML=P)}mt(v,_)||(z=O=null);var dt=V&&Z.ink!==$;dt&&(V.innerHTML=Z.ink,$=Z.ink),g(),Y&&Z.tokens&&(gn(l,!!(Z.geo&&Z.geo.lines.length)),dt&&h&&h.redrawn()),c&&c.onMeasured&&Z.tokens&&c.onMeasured(Z,l)}function Q(N){_=N,F(_)}function U(N){var P=_.stop;_=Object.assign({},_,{stop:N}),xn(l,n,P,N)}var R=function(N){var P=N&&N.closest?N.closest(".diagram-node"):null;return P&&l.contains(P)?P:null};function K(N){var P=R(N.target);if(!(!P||N.defaultPrevented)){if(S(),N.key==="Escape"){!c&&(L||z||O)&&(N.preventDefault(),L=z=O=null,g());return}if(mt(v,_)){var dt=bn(v,P.getAttribute("data-node"),N.key,_.layout==="drawn");if(dt){N.preventDefault(),U(dt);var St=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');St&&St.focus()}}}}function et(N){var P=R(N.target);if(P){S();var dt=P.getAttribute("data-node");L=P.matches(":focus-visible")?dt:null,mt(v,_)&&_.stop!==dt&&U(dt),g()}}function nt(N){var P=R(N.target);P&&(R(N.relatedTarget)||(L=null),_.keep===P.getAttribute("data-node")&&Q(Object.assign({},_,{keep:void 0})),g())}function J(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var P=R(N.target);P&&S();var dt=P&&mt(v,_)?P.getAttribute("data-node"):null;dt!==z&&(z=dt,g())}}function ot(){z&&(z=null,g())}function X(){S(),Q(Object.assign({},_,{open:!_.open,autoOpen:void 0})),T()}l.addEventListener("keydown",K),l.addEventListener("focusin",et),l.addEventListener("focusout",nt),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",ot),l.addEventListener("click",q),W&&W.addEventListener("click",X),H();var st=l.clientWidth,rt=0,ct=!0,bt=new ResizeObserver(function(){Math.abs(l.clientWidth-st)<.5||(st=l.clientWidth,cancelAnimationFrame(rt),rt=requestAnimationFrame(H))});bt.observe(l),document.fonts&&document.fonts.ready.then(function(){ct&&H()});var xt=matchMedia("(forced-colors: active)"),Se=v.nodes.some(function(N){return N.mark});Se&&xt.addEventListener("change",H),Y&&(h=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return Z&&Z.geo},tokens:function(){return Z&&Z.tokens}},b));var Ee=!c&&b.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,b,{model:v,settle:S,animated:Y}):null;l.__diagram={stop:function(){Ee&&Ee.destroy(),ct=!1,bt.disconnect(),cancelAnimationFrame(rt),Se&&xt.removeEventListener("change",H),h&&h.destroy(),l.removeEventListener("keydown",K),l.removeEventListener("focusin",et),l.removeEventListener("focusout",nt),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",ot),l.removeEventListener("click",q),y&&y.remove(),W&&W.removeEventListener("click",X)},layout:H,key:m(b),send:h&&h.sendValue?h.sendValue:null}}function m(l){try{return JSON.stringify(l,function(b,w){return b==="packet"&&w&&typeof w=="object"?Object.assign({},w,{send:void 0}):w})}catch{return null}}function p(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var b=l.querySelector(":scope > script[data-diagram]");if(b)try{u(l,JSON.parse(b.textContent),!0)}catch(w){console.error("Basalt diagram: this figure could not be drawn",w)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:_t,figureKey:ze,figureList:Ve,hintEntries:Wt,toHtml:Bt,escapeHtml:it,settleEntrance:ve,measureFigure:we},t.diagram=function(l,b){var w=l.__diagram,c=w&&w.send?m(b):null;if(c!==null&&c===w.key){w.send(b.packet?b.packet.send:void 0);return}u(l,b)},e.step(62,"wireDiagrams",p)})(window.Basalt)})(); diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 32b77884..9c5c3269 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -206,6 +206,8 @@ export interface Model { motion: { animated: boolean; pulse?: string[]; packet?: { path: string[]; repeat: boolean; send?: number | string }; run: boolean; firstVisit?: boolean }; /** Work that depends on the model alone, done once (see `memo`). */ memo: Map; + /** Mirrored for a right-to-left figure (1.7). */ + rtl?: boolean; } const SIDES: DiagramSide[] = ["top", "right", "bottom", "left"]; @@ -220,6 +222,9 @@ const record = (from?: Record): Record => Object.assign const own = (r: Record | undefined, id: string): T | undefined => (r && Object.prototype.hasOwnProperty.call(r, id) ? r[id] : undefined); export interface BuildOptions { + /** The figure's computed direction is right to left (DECISIONS 306, 1.7): the model is mirrored, so column 1 is drawn at the right and a named left or + * right side swaps. The engine then lays out and routes as it does any figure; the words do not mirror. */ + rtl?: boolean; /** Run the checks a development build reports (placement, groups, the key's words). Off, the model is read the same and nothing is checked. */ checks?: boolean; } @@ -493,9 +498,17 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model } const fl = (spec.frameLabels ?? {}) as Record; const frameWords = { opt: txt(fl.opt) ?? "Only if", loop: txt(fl.loop) ?? "Repeats", alt: txt(fl.alt) ?? "One of these", else: txt(fl.else) ?? "Otherwise" }; - const cols = Math.max(1, ...nodes.map((n) => n.col)); + let cols = Math.max(1, ...nodes.map((n) => n.col)); + // Right to left (1.7): column 1 at the right. Columns are mirrored, a frame's span with them, and a named left or right side swaps. + if (options.rtl) { + for (const n of nodes) n.col = cols - n.col + 1; + const swap = (side?: DiagramSide) => (side === "left" ? "right" : side === "right" ? "left" : side); + for (const e of edges) { e.fromSide = swap(e.fromSide); e.toSide = swap(e.toSide); } + for (const st of steps) if ("open" in st) { const [a, b] = [cols - st.b + 1, cols - st.a + 1]; st.a = a; st.b = b; } + cols = Math.max(1, ...nodes.map((n) => n.col)); + } const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, ...nodes.map((n) => n.row2)); - const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map() }; + const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined }; if (checks && nodes.length > 1 && !spatialTable(model)) warn("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"); return model; } @@ -856,7 +869,7 @@ function buildKey(P: string, m: Model): VElement | null { if (m.type === "schema" && m.edges.length) { // The foreign-key line where it is drawn; where it is not, the row says it, and so does the key. entry(lineSwatch(P, "fk"), m.legend.plain ?? "A foreign key, to the key it references", { "data-line": "", "data-when": "drawn" }); - entries.push(h("li", { class: `${P}-entry`, "data-when": "stacked" }, h("span", { class: `${P}-fk-mark`, "aria-hidden": "true" }, "→"), h("span", null, "The table a foreign key references"))); + entries.push(h("li", { class: `${P}-entry`, "data-when": "stacked" }, h("span", { class: `${P}-fk-mark`, "aria-hidden": "true" }, m.rtl ? "←" : "→"), h("span", null, "The table a foreign key references"))); } if (m.type === "sequence") { // A bar on a dashed lifeline, where one is drawn (1.2); then each frame operator drawn, its letters set as the tab sets them, and its words. @@ -900,13 +913,13 @@ function nodeText(P: string, m: Model, n: MNode): VChild[] { return kids; } -function tableText(P: string, n: MNode): VChild[] { +function tableText(P: string, n: MNode, m: Model): VChild[] { return [ h("span", { class: `${P}-th` }, h("span", { class: `${P}-tname` }, linkName(P, n))), h("span", { class: `${P}-rows` }, (n.columns ?? []).map((c, k) => h("span", { class: `${P}-row`, "data-row": k, "data-key": c.key }, h("span", { class: `${P}-keyseat` }, c.key ?? ""), h("span", { class: `${P}-cname` }, c.name), - c.ref ? h("span", { class: `${P}-ctype`, "data-ref": "" }, `→ ${c.ref.table}`) : c.type ? h("span", { class: `${P}-ctype` }, c.type) : null))), + c.ref ? h("span", { class: `${P}-ctype`, "data-ref": "" }, `${m.rtl ? "←" : "→"} ${c.ref.table}`) : c.type ? h("span", { class: `${P}-ctype` }, c.type) : null))), n.more ? h("span", { class: `${P}-more` }, `+ ${n.more} more`) : null, ]; } @@ -957,7 +970,7 @@ function nodeTree(ctx: TreeContext, m: Model, n: MNode, dyn: Dyn): VElement { n.shape === "decision" ? h("svg", { class: `${P}-diamond`, viewBox: "0 0 100 100", preserveAspectRatio: "none", "aria-hidden": "true", focusable: "false" }, h("path", { d: "M50 0L100 50L50 100L0 50Z" })) : null, // A mark (DECISIONS 292, 2.6): an empty span, the form a background image, so its colours cannot be restyled and nothing of the file reaches the page. n.mark ? h("span", { class: `${P}-mark`, "aria-hidden": "true", style: n.mark.onLight ? `--_ml:${cssUrl(n.mark.onLight)};--_md:${cssUrl(n.mark.onDark ?? n.mark.onLight)}` : undefined }) : null, - n.shape === "table" ? tableText(P, n) : nodeText(P, m, n)); + n.shape === "table" ? tableText(P, n, m) : nodeText(P, m, n)); } function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { @@ -1039,7 +1052,8 @@ function sequenceSteps(ctx: TreeContext, m: Model): VElement { const a = m.byId.get(s.from), b = m.byId.get(s.to); const ca = a?.col ?? 1, cb = b?.col ?? 1; const self = ca === cb; - const last = self && ca === m.nodes.length; + // A self-call goes to the end side, the start side on the last participant: logical, so mirrored right to left (1.7). + const last = self && (m.rtl ? ca !== 1 : ca === m.nodes.length); const word = kindWord(m, s.kind); list.c.push(h("li", { class: `${P}-msg`, "data-kind": s.kind, "data-from": s.from, "data-to": s.to, "data-self": self ? (last ? "start" : "end") : undefined, style: `--_a:${Math.min(ca, cb)};--_b:${Math.max(ca, cb) + 1}` }, h("span", { class: `${P}-said` }, h("span", { class: `${P}-num` }, String(s.n)), h("span", { class: `${P}-mlabel` }, s.label)), @@ -1151,7 +1165,7 @@ type Way = "right" | "left" | "down" | "up"; /** Lexicographic order of two ranks. */ const less = (a: number[], b: number[]) => { for (let k = 0; k < a.length; k++) if (a[k] !== b[k]) return a[k]! < b[k]!; return false; }; /** A card's tracks: its column and its rows (a data flow's row is its lane, a sequence's heads are one row). */ -const tracksOf = (m: Model, n: MNode) => ({ col: m.type === "sequence" ? n.i + 1 : n.col, rows: [n.row, n.row2] as [number, number] }); +const tracksOf = (_m: Model, n: MNode) => ({ col: n.col, rows: [n.row, n.row2] as [number, number] }); /** * Where each arrow goes from each card, or null when some card cannot be reached from another by the arrows: then the arrows are the author's order. * A card is "that way" when it starts past the focused card's last track on the arrow's axis. Among those sharing a track across the arrow, the nearest; @@ -1238,6 +1252,7 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { "data-bare": dyn.bare ? "" : undefined, "data-motion": m.motion.animated ? "animated" : undefined, "data-first-visit": m.motion.animated && m.motion.firstVisit ? "" : undefined, + "data-rtl": m.rtl ? "" : undefined, "data-viewer": o.viewer ? "" : undefined, style: style.join(";"), }, @@ -1434,7 +1449,7 @@ function minimums(m: Model, tk: Tokens, measure: ReturnType) { for (const n of m.nodes) { if (n.shape === "table") { for (const c of n.columns ?? []) { - const type = c.ref ? `→ ${c.ref.table}` : c.type ?? ""; + const type = c.ref ? `${m.rtl ? "←" : "→"} ${c.ref.table}` : c.type ?? ""; const row = s("6") + measure(c.name, "mono") + (type ? s("3") + measure(type, "mono") : 0) + 2 * s("3") + 2 * tk.hair; table = Math.max(table, Math.ceil(row)); } @@ -2012,7 +2027,8 @@ function sequenceGeometry(input: DrawnInput, geo: Geo, sn: ReturnType 1 ? -1 : 1; + const lastOne = who.i === m.nodes.length - 1 && m.nodes.length > 1; + const dir = (lastOne ? -1 : 1) * (m.rtl ? -1 : 1); const off = (bar.depth - 1) * s("1") * dir; const y1 = rowY.get(bar.from) ?? 0, y2 = rowY.get(bar.to) ?? y1; const one = bar.from === bar.to; @@ -2518,7 +2534,7 @@ export function keyTarget(m: Model, from: string, key: string, drawn = false, rt * script, first in the figure) is passed over, never mistaken for the heading. */ const MANAGED = ["data-layout", "data-measured", "role", "aria-roledescription", "aria-labelledby", "aria-describedby", "aria-label", "tabindex", "data-stops", "hidden"]; -const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion", "data-first-visit"]; +const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion", "data-first-visit", "data-rtl"]; const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_gpad"]; const absent = (value: VAttrs[string]) => value === undefined || value === null || value === false; function pairs(el: Element, v: VElement): boolean { diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 75c50be4..4289701d 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -119,7 +119,9 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // The key hint is a data-kbd-hint legend, hidden on touch until a hardware key is pressed: this installs the listener that reveals it. useShortcutsVisible(); // The development checks (placement, groups, the key's words) cost production nothing: a bundler that sets NODE_ENV drops them. - const model = React.useMemo(() => buildModel(spec, { checks: process.env.NODE_ENV !== "production" }), [spec]); + // Right to left (DECISIONS 306, 1.7): no prop; the figure follows its computed direction, read as it is measured, and the model is mirrored. + const [rtl, setRtl] = React.useState(false); + const model = React.useMemo(() => buildModel(spec, { checks: process.env.NODE_ENV !== "production", rtl }), [spec, rtl]); const animated = model.motion.animated; const figRef = React.useRef(null); // The figure's own ref, which measuring reads, and the caller's, both set: a caller's ref never replaces the figure's. @@ -161,6 +163,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const measure = React.useCallback(() => { const fig = figRef.current; if (!fig) return; + const dirRtl = getComputedStyle(fig).direction === "rtl"; + if (dirRtl !== rtl) { setRtl(dirRtl); return; } const warn = process.env.NODE_ENV !== "production" ? (message: string) => warnOnce(component, message) : undefined; const apply = (d: Dyn) => syncAttributes(fig, figureTree(model, d, options)); const result = (viewer ? viewer.measure : measureFigure)(fig, model, P, base, dynRef.current, apply, warn); @@ -173,7 +177,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: if (!hasStops(model, result.dyn)) { setHoverTrace(null); setTouchTrace(null); } // A figure hidden (the viewer's list is open) was not measured: the viewer keeps the drawing's size and place it had. if (viewer && result.tokens) viewer.onMeasured(result, fig); - }, [model, base, options, component, viewer]); + }, [model, base, options, component, viewer, rtl]); // Measured before the first paint, then whenever the figure's width changes or the real faces arrive. React.useLayoutEffect(() => { @@ -294,7 +298,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // In the viewer Esc always closes the dialog, traced or not (9.8): the figure leaves it to the dialog. if (event.key === "Escape") { if (!viewer && (focusTrace || hoverTrace || touchTrace)) { event.preventDefault(); setFocusTrace(null); setHoverTrace(null); setTouchTrace(null); } return; } if (!stops) return; - const to = keyTarget(model, node.dataset.node!, event.key, dynRef.current.layout === "drawn", getComputedStyle(node).direction === "rtl"); + // The model is mirrored right to left, so the table is already physical. + const to = keyTarget(model, node.dataset.node!, event.key, dynRef.current.layout === "drawn"); if (!to) return; event.preventDefault(); const next = { ...dynRef.current, stop: to }; diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index f377c0dd..f499217f 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4481,6 +4481,15 @@ } .basalt-diagram[data-type="sequence"] > .basalt-diagram-drawing { display: flex; gap: 0; } + /* Right to left (DECISIONS 306, 1.7): the engine lays out a mirrored model on a left-to-right grid, so the drawing is set left to right and what is in it + is set right to left again; identifiers are isolated left to right as runs, never as blocks, so they keep the card's start edge. */ + .basalt-diagram[data-rtl] > .basalt-diagram-drawing { direction: ltr; } + .basalt-diagram[data-rtl] > .basalt-diagram-drawing :is(.basalt-diagram-node > :not(.basalt-diagram-mark), .basalt-diagram-lane-name, .basalt-diagram-said, .basalt-diagram-note, .basalt-diagram-band, .basalt-diagram-fhead, .basalt-diagram-felse) { direction: rtl; } + .basalt-diagram[data-rtl] .basalt-diagram-gbox > .basalt-diagram-glabel { inset-inline: auto var(--basalt-space-3); } + .basalt-diagram[data-rtl] :is(.basalt-diagram-run, .basalt-diagram-mlabel, .basalt-diagram-tname, .basalt-diagram-cname, .basalt-diagram-ctype, .basalt-diagram-label, .basalt-diagram-glabel, .basalt-diagram-kind) { unicode-bidi: isolate; } + .basalt-diagram[data-rtl] :is(.basalt-diagram-run, .basalt-diagram-mlabel, .basalt-diagram-cname, .basalt-diagram-label) { direction: ltr; } + .basalt-diagram[data-rtl] .basalt-diagram-arrow { scale: -1 1; } + /* A node: a panel with the rim, radius 8, space-2-5 by space-3; its kind, name and detail wrap inside it, with break-word only as the net. */ .basalt-diagram-node { --_d-gc: var(--_drawn) var(--_c); diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 4094c7b4..e0b1aea3 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -46,7 +46,8 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, function draw(figure, spec, attach, viewer) { if (figure.__diagram) figure.__diagram.stop(); var base = (figure.getAttribute('aria-labelledby') || '').replace(/-title$/, '').replace(/[^A-Za-z0-9_-]/g, ''); - var model = buildModel(spec); + // Right to left (DECISIONS 306, 1.7): the figure follows its computed direction, and the model is mirrored. + var model = buildModel(spec, { rtl: getComputedStyle(figure).direction === 'rtl' }); if (!attach || !base || !figure.querySelector(':scope > .diagram-drawing')) { // Keep the figure's base when it has ours, so its ids stay; otherwise take the next free one. if (!base || !figure.querySelector('#' + CSS.escape(base + '-title'))) { @@ -150,7 +151,7 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, // In the viewer Esc always closes the dialog, traced or not (DECISIONS 310, 9.8). if (event.key === 'Escape') { if (!viewer && (focusTrace || hoverTrace || touchTrace)) { event.preventDefault(); focusTrace = hoverTrace = touchTrace = null; retrace(); } return; } if (!hasStops(model, state)) return; - var to = keyTarget(model, node.getAttribute('data-node'), event.key, state.layout === 'drawn', getComputedStyle(node).direction === 'rtl'); + var to = keyTarget(model, node.getAttribute('data-node'), event.key, state.layout === 'drawn'); if (!to) return; event.preventDefault(); setStop(to); From a643c62c918e55d38963d6c1293e56bcb34a74dc Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:03:47 -0600 Subject: [PATCH 20/62] Export to SVG and PNG (DECISIONS 306, 1.7), and the sequence's heads right to left @srasyndicate/basalt/diagram-export: diagramToSvg and diagramToPng(figure, options), each a Blob, loaded on demand by the app and never by the index or a figure. The file holds the title and source, the drawing as laid out now and the key, on surface-page with space-4 round it, at rest (no trace, mover or pending entrance): native SVG only, never foreignObject, boxes as rects, the drawing's own SVG with its paint inlined, marks as images, and every word as SVG text at its measured box; the title is the SVG's title and the summary its desc. Options: theme (page, light, dark), fonts (embed, by default, or name), scale (PNG, 2). The skill's diagram-export module ("export": true) adds "Download SVG" and "Download PNG" to the foot and the viewer's foot. A sequence's heads take their mirrored columns. diagram-output.test.mjs covers print, right to left and export. Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/SKILL.md | 1 + .../basalt-html/parts/diagram-export.js | 1 + .../skills/basalt-html/parts/diagram-zoom.js | 2 +- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 8 +- .agent/skills/basalt-html/parts/manifest.json | 16 ++ .../basalt-html/parts/usage/diagram-export.md | 6 + packages/react/package.json | 8 + packages/react/src/diagram-core.ts | 3 +- packages/react/src/diagram-export.ts | 192 ++++++++++++++++++ packages/react/src/styles/components.css | 5 +- packages/react/test/diagram-output.test.mjs | 91 +++++++++ tools/html-skill/build.mjs | 2 +- tools/html-skill/src/modules.json | 16 ++ .../html-skill/src/modules/diagram-export.js | 41 ++++ tools/html-skill/src/modules/diagram-zoom.js | 2 + tools/html-skill/src/modules/diagram.js | 4 + tools/html-skill/src/usage/diagram-export.md | 6 + 18 files changed, 397 insertions(+), 9 deletions(-) create mode 100644 .agent/skills/basalt-html/parts/diagram-export.js create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-export.md create mode 100644 packages/react/src/diagram-export.ts create mode 100644 packages/react/test/diagram-output.test.mjs create mode 100644 tools/html-skill/src/modules/diagram-export.js create mode 100644 tools/html-skill/src/usage/diagram-export.md diff --git a/.agent/skills/basalt-html/SKILL.md b/.agent/skills/basalt-html/SKILL.md index fe994ce9..6cd6e4f7 100644 --- a/.agent/skills/basalt-html/SKILL.md +++ b/.agent/skills/basalt-html/SKILL.md @@ -65,6 +65,7 @@ Markup built only at run time (a `.row` your script writes) won't be seen: add ` - **diagram** `.diagram`: JSON in `script[data-diagram]`; sides only to change the default; needs a `summary`. - **diagram-motion** `"motion": "animated"`: added for you, with `loops`; a flow line needs a label; one mover a figure. - **diagram-zoom** `.diagram`: added for you, with `dialog`; `"zoom": false` drops Expand. +- **diagram-export** `"export": true`: added for you; "Download SVG" and "Download PNG" in the foot. - **sparkline** `.sparkline`: JSON in `script[data-sparkline]`; one line, no axes or series (that is a `chart`). - **palette** `data-open-palette`, `Basalt.init({ palette })`: `keys` is an array, `['⌘', 'S']`: ⌘, ⌃ or ⌥ plus one key. - **command-list** `.command-list`: the script builds it; items are the palette's; ⌘K goes to the palette when the page has one. diff --git a/.agent/skills/basalt-html/parts/diagram-export.js b/.agent/skills/basalt-html/parts/diagram-export.js new file mode 100644 index 00000000..ea8eb230 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-export.js @@ -0,0 +1 @@ +(()=>{var B="http://www.w3.org/2000/svg",w=t=>t.replace(/[&<>"']/g,r=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[r]),T=t=>!!t&&t!=="transparent"&&!/rgba\([^)]*,\s*0\)$/.test(t)&&!/\/\s*0\)$/.test(t),g=t=>Math.round(t*100)/100;function P(t){const r=s=>t.querySelector(`:scope > [class$="-${s}"], :scope > [class*="-${s} "]`);return["head","drawing","key"].map(r).filter(s=>!!(s&&s.getClientRects().length))}async function q(t){for(const r of Array.from(document.styleSheets)){let s;try{s=r.cssRules}catch{continue}for(const l of Array.from(s)){if(!(l instanceof CSSFontFaceRule)||l.style.getPropertyValue("font-family").replace(/["']/g,"").trim()!==t)continue;const n=/url\(["']?([^"')]+)["']?\)/.exec(l.style.getPropertyValue("src"))?.[1];if(n){if(n.startsWith("data:"))return n;try{const a=await(await fetch(new URL(n,r.href??location.href))).blob();return await new Promise((e,d)=>{const i=new FileReader;i.onload=()=>e(String(i.result)),i.onerror=d,i.readAsDataURL(a)})}catch{return null}}}}return null}function F(t,r,s){const l=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let n=l.nextNode();n;n=l.nextNode()){const a=n.parentElement;if(!a||!n.textContent?.trim()||a.closest("[aria-hidden='true'] .basalt-visually-hidden, .basalt-visually-hidden, .visually-hidden, [class$='-ruler'], [hidden]"))continue;const e=getComputedStyle(a);if(e.visibility==="hidden"||e.display==="none")continue;const d=n.textContent,i=document.createRange();for(const u of d.matchAll(/\S+/g)){i.setStart(n,u.index),i.setEnd(n,u.index+u[0].length);const o=i.getBoundingClientRect();if(!o.width)continue;const m=Number.parseFloat(e.fontSize),f=o.top-r.top+(o.height-m)/2+m*.8;s.push(`${w(u[0])}`)}}}function O(t,r,s){const l=[t,...Array.from(t.querySelectorAll("*"))];for(const n of l){if(n instanceof SVGElement){if(n.tagName.toLowerCase()!=="svg"||n.closest("svg")!==n)continue;const y=n.getBoundingClientRect();if(!y.width||!y.height)continue;const p=n.cloneNode(!0),b=[n,...Array.from(n.querySelectorAll("*"))],v=[p,...Array.from(p.querySelectorAll("*"))];b.forEach((k,x)=>{const A=getComputedStyle(k),C=v[x];for(const c of["fill","stroke","stroke-width","stroke-dasharray","stroke-linecap","stroke-linejoin","opacity"])C.setAttribute(c,A.getPropertyValue(c));C.removeAttribute("class"),A.display==="none"&&C.setAttribute("display","none")}),p.setAttribute("x",String(g(y.left-r.left))),p.setAttribute("y",String(g(y.top-r.top))),p.removeAttribute("style"),s.push(p.outerHTML);continue}const a=getComputedStyle(n);if(a.display==="none"||a.visibility==="hidden")continue;const e=n.getBoundingClientRect();if(!e.width||!e.height)continue;const d=g(e.left-r.left),i=g(e.top-r.top),u=g(e.width),o=g(e.height),m=Number.parseFloat(a.borderTopLeftRadius)||0,f=T(a.backgroundColor)?a.backgroundColor:"none",h=Number.parseFloat(a.borderTopWidth)||0,$=h&&a.borderTopStyle!=="none"&&T(a.borderTopColor)?a.borderTopColor:"none";if(f!=="none"||$!=="none"){const y=a.borderTopStyle==="dashed"?' stroke-dasharray="4 2"':"";s.push(``)}const S=/url\(["']?([^"')]+)["']?\)/.exec(a.backgroundImage)?.[1];S&&/-mark$/.test(String(n.getAttribute("class")))&&s.push(``)}}var L=t=>t.querySelector("[class$='-title']")?.textContent?.trim()??"",V=t=>t.querySelector("figcaption")?.textContent?.trim()??"",M=(t,r)=>`${L(t).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"diagram"}.${r}`;async function E(t,r,s){const l=r.theme??"page",n=t.getAttribute("data-theme"),a=Array.from(t.querySelectorAll("[data-lit], [data-dim], [data-near]")),e=a.map(o=>[o,o.getAttribute("data-lit"),o.getAttribute("data-dim"),o.getAttribute("data-near")]);a.forEach(o=>{o.removeAttribute("data-lit"),o.removeAttribute("data-dim"),o.removeAttribute("data-near")});const d=Array.from(t.querySelectorAll("[class*='-flow'], [class*='-bead'], [class*='-packet']"));d.forEach(o=>{o.dataset.exportHidden=o.style.display,o.style.display="none"});const i=t.getAttribute("data-entrance");i&&i!=="done"&&t.setAttribute("data-entrance","done"),l!=="page"&&t.setAttribute("data-theme",l);const u=t.style.getPropertyValue("--basalt-export");t.classList.add("basalt-exporting");try{t.offsetWidth;const o=Number.parseFloat(getComputedStyle(t).getPropertyValue("--basalt-space-4"))||16,m=P(t),f=m.map(c=>c.getBoundingClientRect()),h=Math.min(...f.map(c=>c.left)),$=Math.min(...f.map(c=>c.top)),S=Math.max(...f.map(c=>c.right)),y=Math.max(...f.map(c=>c.bottom)),p=new DOMRect(h-o,$-o,0,0),b=Math.ceil(S-h+2*o),v=Math.ceil(y-$+2*o),k=getComputedStyle(t).getPropertyValue("--basalt-surface-page").trim()||getComputedStyle(document.body).backgroundColor,x=[];for(const c of m)O(c,p,x);for(const c of m)F(c,p,x);let A="";if(s){const c=[];for(const R of["Geist","Geist Mono"]){const N=await q(R);N?c.push(`@font-face{font-family:"${R}";src:url(${N});font-weight:100 900}`):console.warn(`Basalt diagramToSvg: the face "${R}" could not be read, so the file names it`)}c.length&&(A=``)}return{svg:`${w(L(t))}${w(V(t))}${A}${x.join("")}`,w:b,h:v}}finally{t.classList.remove("basalt-exporting"),u&&t.style.setProperty("--basalt-export",u),l!=="page"&&(n===null?t.removeAttribute("data-theme"):t.setAttribute("data-theme",n)),i&&i!=="done"&&t.setAttribute("data-entrance",i),d.forEach(o=>{o.style.display=o.dataset.exportHidden??"",delete o.dataset.exportHidden});for(const[o,m,f,h]of e)m!==null&&o.setAttribute("data-lit",m),f!==null&&o.setAttribute("data-dim",f),h!==null&&o.setAttribute("data-near",h)}}async function U(t,r={}){const{svg:s}=await E(t,r,(r.fonts??"embed")==="embed");return new Blob([s],{type:"image/svg+xml"})}async function D(t,r={}){const{svg:s,w:l,h:n}=await E(t,r,!0),a=r.scale??2,e=new Image;e.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(s)}`,await e.decode();const d=document.createElement("canvas");d.width=Math.round(l*a),d.height=Math.round(n*a);const i=d.getContext("2d");return i.scale(a,a),i.drawImage(e,0,0,l,n),new Promise((u,o)=>d.toBlob(m=>m?u(m):o(new Error("the PNG could not be made")),"image/png"))}(function(t){"use strict";var r=t._;function s(n,a){var e=document.createElement("a");e.href=URL.createObjectURL(n),e.download=a,document.body.appendChild(e),e.click(),e.remove(),setTimeout(function(){URL.revokeObjectURL(e.href)},1e3)}function l(n,a){var e=document.createElement("button");return e.type="button",e.className="btn diagram-download",e.setAttribute("data-variant","secondary"),e.setAttribute("data-size","sm"),e.innerHTML=""+n+"",e.addEventListener("click",a),e}r.diagramExport=function(n,a){var e=l("Download SVG",function(){U(a).then(function(u){s(u,M(a,"svg"))})}),d=l("Download PNG",function(){D(a).then(function(u){s(u,M(a,"png"))})}),i=n.querySelector(".diagram-clear");return n.insertBefore(e,i),n.insertBefore(d,i),[e,d]}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.js b/.agent/skills/basalt-html/parts/diagram-zoom.js index ad5ade32..d14d8db2 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.js +++ b/.agent/skills/basalt-html/parts/diagram-zoom.js @@ -1 +1 @@ -(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(y=>y.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:y,layer:p,status:x}=l;let u=0,k=0,i=1,n=1,f=!1,d=!1,g=null,h="",w=0;const S=()=>Number.parseFloat(getComputedStyle(y).paddingTop)||0,T=()=>Math.min(n,1),q=t=>Math.min(j,Math.max(T(),t));function o(){if(!u||!k)return 1;const t=S(),a=e.clientWidth-2*t,b=e.clientHeight-2*t;if(a<=0||b<=0)return Math.min(1,J);const H=Math.min(a/u,b/k);return Math.min(J,Math.floor(H*100+1e-6)/100)}function s(){const t=T();return{zoom:i,level:Math.round(i*100),fit:n,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-n)e.clientWidth-2*S()+.5||k*i>e.clientHeight-2*S()+.5)}function A(){clearTimeout(w);const t=`Zoom ${Math.round(i*100)}%`;w=window.setTimeout(()=>{t!==h&&(h=t,x.textContent=t)},l.rest)}function v(){y.style.width=`${u*i}px`,y.style.height=`${k*i}px`,p.style.transform=`scale(${i})`}function I(t){const a=p.getBoundingClientRect();return{x:(t.x-a.left)/i,y:(t.y-a.top)/i}}function z(t,a){const b=p.getBoundingClientRect();e.scrollLeft+=b.left+t.x*i-a.x,e.scrollTop+=b.top+t.y*i-a.y}const m=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function _(t,a=m(),b){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){M();return}const ot=b??I(a);i=H,v(),z(ot,a),M(),A()}function L(t){f=!0;const a=i*100,b=t?G.find(H=>H>a+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,r=()=>{const[t,a]=[...c.values()];return{x:(t.x+a.x)/2,y:(t.y+a.y)/2}},E=()=>{const[t,a]=[...c.values()];return Math.hypot(t.x-a.x,t.y-a.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),c.size===1&&(O={x:t.clientX,y:t.clientY},C=O,B=!1,F=!1),c.size===2&&t.pointerType==="touch")){const a=r();$={d0:E()||1,z0:i,c:I(a)},F=!0,B=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!c.has(t.pointerId)||d)return;if(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),$&&c.size>=2){f=!0;const b=q($.z0*(E()/$.d0)),H=r();Math.abs(b-i)>1e-6&&(i=b,v(),M(),A()),z($.c,H);return}if(c.size!==1||!O||!C)return;const a={x:t.clientX,y:t.clientY};if(!B){if(Math.hypot(a.x-O.x,a.y-O.y)<=V())return;B=!0,F=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=a.x-C.x,e.scrollTop-=a.y-C.y,C=a,t.preventDefault()}function Z(t){if(c.has(t.pointerId)){if(c.delete(t.pointerId),c.size<2&&($=null),c.size===1){const[a]=[...c.values()];C=a,O=a,B=!0;return}c.size===0&&(B=!1,e.removeAttribute("data-dragging"),O=C=null)}}function P(t){F&&(F=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!u||!k)return;const t=f?I(m()):null;n=o(),f?(i=q(i),v(),t&&z(t,m())):(i=n,v()),M()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:K,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:W,state:s,list(t){t!==d&&(t?(g={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),v(),g&&(e.scrollLeft=g.left,e.scrollTop=g.top),g=null),M())},travelled:()=>F,destroy(){clearTimeout(w),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function nt(l,e,y){const p=l.getBoundingClientRect(),x=e.getBoundingClientRect(),u=p.left+y,k=p.left+l.clientWidth-y,i=p.top+y,n=p.top+l.clientHeight-y;x.leftk&&(l.scrollLeft+=Math.min(x.right-k,x.left-u)),x.topn&&(l.scrollTop+=Math.min(x.bottom-n,x.top-i))}function rt(l,e,y,p,x,u,k,i){const{layer:n,memo:f,measureFigure:d}=i;f.model!==e&&(f.model=e,f.least=void 0);const g=M=>{n.style.width=`${Math.max(f.least||M,Math.min(i.avail,i.row))}px`};n.style.width||(n.style.width=`${Math.min(i.avail,i.row)}px`);const h=n.style.transform;n.style.transform="none";const w=n.offsetWidth?n.getBoundingClientRect().width/n.offsetWidth:1,S=Math.abs(w-1)>1e-4?` scale(${1/w})`:"";n.style.transform=S||"none";const T=(l.querySelector(`.${y}-drawing`)??n).getBoundingClientRect(),q=T.left-Math.round(T.left),o=T.top-Math.round(T.top);(q||o)&&(n.style.transform=`translate(${-q/w}px, ${-o/w}px)${S}`);let s=d(l,e,y,p,x,u,f.least===void 0?void 0:k,g);if(s.dyn.layout==="stacked"&&f.least===void 0&&s.least!==void 0){const M=s.dyn,A=m=>{n.style.width=`${m}px`;const _=d(l,e,y,p,M,u);return _.dyn.layout==="drawn"?d(l,e,y,p,_.dyn,u):_},v=Math.max(s.least,Math.min(i.avail,i.row)),I=Math.max(i.row,v)*1.5;let z;for(let m=v+16;m<=I&&z===void 0;m+=16)A(m).dyn.layout==="drawn"&&(z=m);if(z!==void 0){for(let m=z-15;mi.contain&&(n.style.width=`${i.contain}px`,s=d(l,e,y,p,s.dyn,u,k)),n.style.transform=h,s}(function(l){"use strict";var e=l._,y=0;function p(i){return e.diagramKit.escapeHtml(String(i??""))}function x(i){return''+p(i)+""}function u(i,n){return parseFloat(getComputedStyle(i).getPropertyValue(n))||0}function k(i,n,f,d){var g=e.diagramKit,h=Object.assign({},n,{motion:"still"}),w=g.buildModel(h),S="dgv"+ ++y,T=g.figureKey("diagram",w),q=et(g.hintEntries(w,!0)).map(function(r){return""+r.keys.map(x).join(" ")+" "+p(r.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",S+"-summary"),o.innerHTML='

'+p(w.title)+"

"+(n.source?'

'+p(n.source)+"

":"")+'

'+p(n.summary)+'

'+(T?'
'+g.toHtml(T)+"
":"")+'
',document.body.appendChild(o);var s=o.querySelector(".diagram-stage"),M=o.querySelector(".diagram-sizer"),A=o.querySelector(".diagram-layer"),v=A.firstChild,I=o.querySelector('[role="status"]'),z=o.querySelector(".diagram-level > span"),m=o.querySelector(".diagram-viewer-key"),_=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},W=null,K=!1,R=!1,D=function(r,E){E?r.setAttribute("aria-disabled","true"):r.removeAttribute("aria-disabled")},c=at({stage:s,sizer:M,layer:A,status:I,rest:u(s,"--_rest")||300,onChange:function(r){z.textContent=r.level+"%",D(L.out,r.listOpen||r.atMin),D(L.in,r.listOpen||r.atMax),D(L.fit,r.listOpen||r.atFit)}}),O={},C={layer:A,avail:0,row:1104,contain:480,memo:O,measureFigure:g.measureFigure,keys:tt,measure:function(r,E,Y,N,Z,P,X){return rt(r,E,Y,N,Z,P,X,C)},onMeasured:function(r,E){s.setAttribute("data-layout",r.dyn.layout||""),m&&(m.setAttribute("data-layout",r.dyn.layout||""),m.toggleAttribute("data-bare",!!r.dyn.bare)),R=!!r.dyn.bare,_.hidden=R,F(K||R),c.size(E.offsetWidth,E.offsetHeight)}};function B(){C.avail=Math.max(0,Math.floor(s.clientWidth-2*(parseFloat(getComputedStyle(M).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function F(r){r&&!W&&(W=document.createElement("div"),W.className="diagram-list diagram-viewer-list",W.innerHTML=g.figureList("diagram",w).map(function(E){return g.toHtml(E)}).join(""),s.appendChild(W)),r&&c.list(!0),W&&(W.hidden=!r),M.hidden=r,r||c.list(!1)}_.addEventListener("click",function(){K=!K,_.setAttribute("aria-expanded",String(K)),_.firstElementChild.textContent=K?"Hide the list":"View as list",F(K||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||c.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||c.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||c.fit()}),s.addEventListener("focusin",function(r){var E=r.target.closest&&r.target.closest(".diagram-node");E&&s.contains(E)&&nt(s,E,u(s,"--_clear")||16)}),l.openDialog(o,d),B(),g.draw(v,h,!1,C),setTimeout(function(){s.focus({preventScroll:!0})},0);var $=s.clientWidth,V=new ResizeObserver(function(){Math.abs(s.clientWidth-$)<.5||($=s.clientWidth,B(),v.__diagram&&v.__diagram.layout())});V.observe(s),o.addEventListener("transitionend",function(r){r.target===o&&r.propertyName==="transform"&&o.open&&v.__diagram&&v.__diagram.layout()}),i.setAttribute("data-viewing",""),f.animated&&f.settle(),o.addEventListener("close",function(){V.disconnect(),c.destroy(),v.__diagram&&v.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},u(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,n,f){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var g=d.querySelector(".diagram-expand");g&&g.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var w=d.querySelector(".diagram-toggle");w&&w.nextSibling?d.insertBefore(h,w.nextSibling):d.appendChild(h);var S=function(){k(i,n,f,h)};return h.addEventListener("click",S),{destroy:function(){h.removeEventListener("click",S),h.remove()}}}})(window.Basalt)})(); +(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(v=>v.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:v,layer:p,status:x}=l;let u=0,k=0,i=1,a=1,f=!1,d=!1,g=null,h="",w=0;const S=()=>Number.parseFloat(getComputedStyle(v).paddingTop)||0,T=()=>Math.min(a,1),q=t=>Math.min(j,Math.max(T(),t));function o(){if(!u||!k)return 1;const t=S(),n=e.clientWidth-2*t,b=e.clientHeight-2*t;if(n<=0||b<=0)return Math.min(1,J);const H=Math.min(n/u,b/k);return Math.min(J,Math.floor(H*100+1e-6)/100)}function s(){const t=T();return{zoom:i,level:Math.round(i*100),fit:a,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-a)e.clientWidth-2*S()+.5||k*i>e.clientHeight-2*S()+.5)}function A(){clearTimeout(w);const t=`Zoom ${Math.round(i*100)}%`;w=window.setTimeout(()=>{t!==h&&(h=t,x.textContent=t)},l.rest)}function y(){v.style.width=`${u*i}px`,v.style.height=`${k*i}px`,p.style.transform=`scale(${i})`}function I(t){const n=p.getBoundingClientRect();return{x:(t.x-n.left)/i,y:(t.y-n.top)/i}}function z(t,n){const b=p.getBoundingClientRect();e.scrollLeft+=b.left+t.x*i-n.x,e.scrollTop+=b.top+t.y*i-n.y}const m=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function _(t,n=m(),b){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){M();return}const ot=b??I(n);i=H,y(),z(ot,n),M(),A()}function L(t){f=!0;const n=i*100,b=t?G.find(H=>H>n+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,r=()=>{const[t,n]=[...c.values()];return{x:(t.x+n.x)/2,y:(t.y+n.y)/2}},E=()=>{const[t,n]=[...c.values()];return Math.hypot(t.x-n.x,t.y-n.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),c.size===1&&(O={x:t.clientX,y:t.clientY},C=O,B=!1,F=!1),c.size===2&&t.pointerType==="touch")){const n=r();$={d0:E()||1,z0:i,c:I(n)},F=!0,B=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!c.has(t.pointerId)||d)return;if(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),$&&c.size>=2){f=!0;const b=q($.z0*(E()/$.d0)),H=r();Math.abs(b-i)>1e-6&&(i=b,y(),M(),A()),z($.c,H);return}if(c.size!==1||!O||!C)return;const n={x:t.clientX,y:t.clientY};if(!B){if(Math.hypot(n.x-O.x,n.y-O.y)<=V())return;B=!0,F=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=n.x-C.x,e.scrollTop-=n.y-C.y,C=n,t.preventDefault()}function Z(t){if(c.has(t.pointerId)){if(c.delete(t.pointerId),c.size<2&&($=null),c.size===1){const[n]=[...c.values()];C=n,O=n,B=!0;return}c.size===0&&(B=!1,e.removeAttribute("data-dragging"),O=C=null)}}function P(t){F&&(F=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!u||!k)return;const t=f?I(m()):null;a=o(),f?(i=q(i),y(),t&&z(t,m())):(i=a,y()),M()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:K,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:W,state:s,list(t){t!==d&&(t?(g={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),y(),g&&(e.scrollLeft=g.left,e.scrollTop=g.top),g=null),M())},travelled:()=>F,destroy(){clearTimeout(w),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function nt(l,e,v){const p=l.getBoundingClientRect(),x=e.getBoundingClientRect(),u=p.left+v,k=p.left+l.clientWidth-v,i=p.top+v,a=p.top+l.clientHeight-v;x.leftk&&(l.scrollLeft+=Math.min(x.right-k,x.left-u)),x.topa&&(l.scrollTop+=Math.min(x.bottom-a,x.top-i))}function rt(l,e,v,p,x,u,k,i){const{layer:a,memo:f,measureFigure:d}=i;f.model!==e&&(f.model=e,f.least=void 0);const g=M=>{a.style.width=`${Math.max(f.least||M,Math.min(i.avail,i.row))}px`};a.style.width||(a.style.width=`${Math.min(i.avail,i.row)}px`);const h=a.style.transform;a.style.transform="none";const w=a.offsetWidth?a.getBoundingClientRect().width/a.offsetWidth:1,S=Math.abs(w-1)>1e-4?` scale(${1/w})`:"";a.style.transform=S||"none";const T=(l.querySelector(`.${v}-drawing`)??a).getBoundingClientRect(),q=T.left-Math.round(T.left),o=T.top-Math.round(T.top);(q||o)&&(a.style.transform=`translate(${-q/w}px, ${-o/w}px)${S}`);let s=d(l,e,v,p,x,u,f.least===void 0?void 0:k,g);if(s.dyn.layout==="stacked"&&f.least===void 0&&s.least!==void 0){const M=s.dyn,A=m=>{a.style.width=`${m}px`;const _=d(l,e,v,p,M,u);return _.dyn.layout==="drawn"?d(l,e,v,p,_.dyn,u):_},y=Math.max(s.least,Math.min(i.avail,i.row)),I=Math.max(i.row,y)*1.5;let z;for(let m=y+16;m<=I&&z===void 0;m+=16)A(m).dyn.layout==="drawn"&&(z=m);if(z!==void 0){for(let m=z-15;mi.contain&&(a.style.width=`${i.contain}px`,s=d(l,e,v,p,s.dyn,u,k)),a.style.transform=h,s}(function(l){"use strict";var e=l._,v=0;function p(i){return e.diagramKit.escapeHtml(String(i??""))}function x(i){return''+p(i)+""}function u(i,a){return parseFloat(getComputedStyle(i).getPropertyValue(a))||0}function k(i,a,f,d){var g=e.diagramKit,h=Object.assign({},a,{motion:"still"}),w=g.buildModel(h),S="dgv"+ ++v,T=g.figureKey("diagram",w),q=et(g.hintEntries(w,!0)).map(function(r){return""+r.keys.map(x).join(" ")+" "+p(r.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",S+"-summary"),o.innerHTML='

'+p(w.title)+"

"+(a.source?'

'+p(a.source)+"

":"")+'

'+p(a.summary)+'

'+(T?'
'+g.toHtml(T)+"
":"")+'
',document.body.appendChild(o);var s=o.querySelector(".diagram-stage"),M=o.querySelector(".diagram-sizer"),A=o.querySelector(".diagram-layer"),y=A.firstChild,I=o.querySelector('[role="status"]'),z=o.querySelector(".diagram-level > span"),m=o.querySelector(".diagram-viewer-key"),_=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},W=null,K=!1,R=!1,D=function(r,E){E?r.setAttribute("aria-disabled","true"):r.removeAttribute("aria-disabled")},c=at({stage:s,sizer:M,layer:A,status:I,rest:u(s,"--_rest")||300,onChange:function(r){z.textContent=r.level+"%",D(L.out,r.listOpen||r.atMin),D(L.in,r.listOpen||r.atMax),D(L.fit,r.listOpen||r.atFit)}}),O={},C={layer:A,avail:0,row:1104,contain:480,memo:O,measureFigure:g.measureFigure,keys:tt,measure:function(r,E,Y,N,Z,P,X){return rt(r,E,Y,N,Z,P,X,C)},onMeasured:function(r,E){s.setAttribute("data-layout",r.dyn.layout||""),m&&(m.setAttribute("data-layout",r.dyn.layout||""),m.toggleAttribute("data-bare",!!r.dyn.bare)),R=!!r.dyn.bare,_.hidden=R,F(K||R),c.size(E.offsetWidth,E.offsetHeight)}};function B(){C.avail=Math.max(0,Math.floor(s.clientWidth-2*(parseFloat(getComputedStyle(M).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function F(r){r&&!W&&(W=document.createElement("div"),W.className="diagram-list diagram-viewer-list",W.innerHTML=g.figureList("diagram",w).map(function(E){return g.toHtml(E)}).join(""),s.appendChild(W)),r&&c.list(!0),W&&(W.hidden=!r),M.hidden=r,r||c.list(!1)}_.addEventListener("click",function(){K=!K,_.setAttribute("aria-expanded",String(K)),_.firstElementChild.textContent=K?"Hide the list":"View as list",F(K||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||c.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||c.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||c.fit()}),s.addEventListener("focusin",function(r){var E=r.target.closest&&r.target.closest(".diagram-node");E&&s.contains(E)&&nt(s,E,u(s,"--_clear")||16)}),a.export===!0&&typeof e.diagramExport=="function"&&e.diagramExport(o.querySelector(".diagram-viewer-end"),y),l.openDialog(o,d),B(),g.draw(y,h,!1,C),setTimeout(function(){s.focus({preventScroll:!0})},0);var $=s.clientWidth,V=new ResizeObserver(function(){Math.abs(s.clientWidth-$)<.5||($=s.clientWidth,B(),y.__diagram&&y.__diagram.layout())});V.observe(s),o.addEventListener("transitionend",function(r){r.target===o&&r.propertyName==="transform"&&o.open&&y.__diagram&&y.__diagram.layout()}),i.setAttribute("data-viewing",""),f.animated&&f.settle(),o.addEventListener("close",function(){V.disconnect(),c.destroy(),y.__diagram&&y.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},u(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,a,f){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var g=d.querySelector(".diagram-expand");g&&g.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var w=d.querySelector(".diagram-toggle");w&&w.nextSibling?d.insertBefore(h,w.nextSibling):d.appendChild(h);var S=function(){k(i,a,f,h)};return h.addEventListener("click",S),{destroy:function(){h.removeEventListener("click",S),h.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index 693a3fbf..c8511470 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{display:flex;min-width:0}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 442afc63..1c2ba007 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,6 +1,6 @@ -(()=>{var Ae=["top","right","bottom","left"],Le=["main","plain","dashed"],qe=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function _t(t,e={}){const s=e.checks!==!1,r=[],o=h=>{r.push(h)},a=t.legend??{},i={};for(const h of["main","plain","dashed","focal","group","activation"]){const $=at(a[h]);$&&(i[h]=$)}const d=t.stepLabel,u=typeof d=="function"?h=>String(d(h)):typeof d=="string"?(h=>d.replace("{n}",String(h))):h=>`Step ${h}`,m=t.shapeLabels??{},p={terminal:at(m.terminal)??"Start or end",step:at(m.step)??"Step",decision:at(m.decision)??"Decision"},l=t.heading===void 0?3:qe.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),b=(h,$)=>h==null?"plain":Le.includes(h)?h:(o(`"${String(h)}" is not a kind of line (main, plain or dashed): ${$} is drawn plain`),"plain"),w=h=>{if(h!=null){if(Ae.includes(h))return h;o(`"${String(h)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(h,$)=>typeof h=="number"&&Number.isInteger(h)&&h>=1?h:(o(`${$} is ${JSON.stringify(h)}, not a whole number from 1: it is placed at 1`),1),f=[],v=[];let B=[];const C=[],M=[],I=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(I)||o(`"${String(I)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),I==="architecture"||I==="flowchart"){for(const h of t.nodes??[]){const $=I==="flowchart"&&h.shape==="decision"?"decision":I==="flowchart"&&h.shape==="terminal"?"terminal":"box",S=String(h.id??""),g=c(h.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(h.name??""),kind:$==="decision"?void 0:at(h.kind),detail:$==="decision"?void 0:at(h.detail),mono:!!h.detailMono,focal:!!h.focal,col:c(h.col,`the column of ${S}`),row:g,row2:g,branch:!!h.branch,shape:$,group:I==="architecture"?at(h.group):void 0,mark:I==="architecture"?Ct(h.mark):void 0})}if(I==="architecture"){const h=(t.groups??[]).map(y=>({id:String(y.id??""),label:String(y.label??""),parent:at(y.parent)})),$=new Map(h.map(y=>[y.id,y])),S=y=>{if(!y.parent)return 1;const x=$.get(y.parent);return x?x.parent===y.id||x.id===y.id?(o(`the groups "${y.label}" and "${x.label}" are each other's parent`),y.parent=void 0,1):x.parent?(o(`the group "${y.label}" is a third level: groups nest two deep`),y.parent=void 0,1):2:(o(`the group "${y.label}" names the parent "${y.parent}", which is not a group`),y.parent=void 0,1)},g=h.map(S);h.forEach((y,x)=>C.push({...y,depth:g[x],members:f.filter(E=>E.group===y.id).map(E=>E.id),all:[]}));for(const y of C)y.all=[...y.members,...C.filter(x=>x.parent===y.id).flatMap(x=>x.members)];C.sort((y,x)=>y.depth-x.depth)}}else if(I==="data-flow"){B=(t.lanes??[]).map($=>({id:String($.id??""),label:String($.label??"")}));const h=new Map(B.map(($,S)=>[$.id,S+1]));for(const $ of t.nodes??[]){const S=String($.id??""),g=String($.lane??""),y=h.get(g);y===void 0&&o(`a node (${S}) names the lane "${g}", which is not in lanes`);const x=f.length+1;f.push({id:S,i:f.length,name:String($.name??""),kind:u(x),detail:at($.detail),mono:!!$.detailMono,focal:!!$.focal,col:c($.col,`the column of ${S}`),row:y??1,row2:y??1,branch:!1,shape:"box",lane:y??1,laneLabel:B[(y??1)-1]?.label??g,step:x,mark:Ct($.mark)})}}else if(I==="sequence"){(t.participants??[]).forEach((g,y)=>{const x=String(g.name??"");f.push({id:String(g.id??""),i:y,name:x,kind:at(g.kind),mono:!1,focal:!!g.focal,col:y+1,row:1,row2:1,branch:!1,shape:"participant",short:at(g.short)??x,mark:Ct(g.mark)})});let h=0;const $=new Map(f.map(g=>[g.id,g.col])),S=(g,y)=>{let x=1/0,E=-1/0;for(const q of g??[]){if(!q||typeof q!="object")continue;if("band"in q){y>0&&o(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(q.band??"")});continue}if("frame"in q){if(y>=2){o("a frame is a third level: frames nest two deep");continue}const et=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",nt=et==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];et==="alt"&&nt.length<2&&o("an alt frame has one branch: it needs two or more");const J=String(nt[0]?.label??"");J.length>40&&o(`the frame label "${J}" is over 40 characters`);const ot=M.length;M.push({open:et,label:J,depth:y+1,a:0,b:0}),nt.forEach((X,st)=>{if(st){const xt=String(X.label??"");xt.length>40&&o(`the frame label "${xt}" is over 40 characters`),M.push({otherwise:xt,depth:y+1})}X.steps?.length||o(`a frame or branch ("${String(X.label??"")}") is empty`);const[rt,ct]=S(X.steps??[],y+1);x=Math.min(x,rt),E=Math.max(E,ct);const bt=M[ot];bt.a=Math.min(bt.a||1/0,rt),bt.b=Math.max(bt.b,ct)}),M.push({close:y+1});continue}h++;const T=String(q.label??"");T.includes(` -`)&&o(`message ${h}'s label has a break: a message's second line is its note`);const H=String(q.from??""),Q=String(q.to??"");M.push({n:h,from:H,to:Q,label:gt(T),note:at(q.note),kind:b(q.kind,`message ${h}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const U=$.get(H)??1,R=$.get(Q)??1,K=U===R?U===f.length?U-1:U+1:U;x=Math.min(x,U,R,K),E=Math.max(E,U,R,K)}return[x,E]};S(t.steps??[],0);for(const g of M)"open"in g&&!Number.isFinite(g.a)&&(g.a=1,g.b=Math.max(1,f.length))}else if(I==="schema")for(const h of t.tables??[]){const $=String(h.name??""),[S,g]=Array.isArray(h.row)?h.row:[h.row,h.row],y=c(S,`the row of ${$}`),x=Math.max(y,c(g,`the last row of ${$}`)),E=h.more===void 0||h.more===null?void 0:Number.isInteger(h.more)&&h.more>0?h.more:(o(`${$}'s "more" is ${JSON.stringify(h.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:$,i:f.length,name:$,mono:!0,focal:!!h.focal,col:c(h.col,`the column of ${$}`),row:y,row2:x,branch:!1,shape:"table",more:E,columns:(h.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&o(`${$}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}((I==="schema"?t.tables:I==="sequence"?t.participants:t.nodes)??[]).forEach((h,$)=>{if(!h||h.href===void 0||h.href===null)return;const S=String(h.href);if(I==="sequence"){o(`${f[$]?.id}: a participant cannot be a link (href)`);return}if(!S){o(`${f[$]?.id}'s href is empty`);return}const g=f[$];g&&(g.href=S,g.blank=h.target==="_blank")});const G=new Map;for(const h of f)h.id?G.has(h.id)&&o(`the id "${h.id}" is used twice`):o("a node has no id"),G.set(h.id,h);if(I==="schema")(t.tables??[]).forEach(h=>(h.columns??[]).forEach(($,S)=>{const g=at($.references);if(!g)return;const[y,x]=g.split("."),E=G.get(y??""),q=E?.columns?.findIndex(H=>H.name===x)??-1;if(!E||q<0){o(`${String(h.name)}.${String($.name)} references ${g}, which is not a shown column`);return}const T=G.get(String(h.name??""));T.columns[S].ref={table:y,column:x,row:q},v.push({i:v.length,from:T.id,to:y,kind:"plain",fromRow:S,toRow:q,fk:!0})}));else if(I!=="sequence")for(const h of t.edges??[]){const $=String(h.from??""),S=String(h.to??"");if(!G.has($)||!G.has(S)){o(`a line names ${G.has($)?S:$}, which is not a node`);continue}const g=at(h.label),y=g?.split(` +(()=>{var Le=["top","right","bottom","left"],qe=["main","plain","dashed"],Oe=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function _t(t,e={}){const s=e.checks!==!1,r=[],o=h=>{r.push(h)},a=t.legend??{},i={};for(const h of["main","plain","dashed","focal","group","activation"]){const $=at(a[h]);$&&(i[h]=$)}const d=t.stepLabel,u=typeof d=="function"?h=>String(d(h)):typeof d=="string"?(h=>d.replace("{n}",String(h))):h=>`Step ${h}`,m=t.shapeLabels??{},p={terminal:at(m.terminal)??"Start or end",step:at(m.step)??"Step",decision:at(m.decision)??"Decision"},l=t.heading===void 0?3:Oe.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),b=(h,$)=>h==null?"plain":qe.includes(h)?h:(o(`"${String(h)}" is not a kind of line (main, plain or dashed): ${$} is drawn plain`),"plain"),w=h=>{if(h!=null){if(Le.includes(h))return h;o(`"${String(h)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(h,$)=>typeof h=="number"&&Number.isInteger(h)&&h>=1?h:(o(`${$} is ${JSON.stringify(h)}, not a whole number from 1: it is placed at 1`),1),f=[],v=[];let B=[];const C=[],M=[],I=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(I)||o(`"${String(I)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),I==="architecture"||I==="flowchart"){for(const h of t.nodes??[]){const $=I==="flowchart"&&h.shape==="decision"?"decision":I==="flowchart"&&h.shape==="terminal"?"terminal":"box",S=String(h.id??""),g=c(h.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(h.name??""),kind:$==="decision"?void 0:at(h.kind),detail:$==="decision"?void 0:at(h.detail),mono:!!h.detailMono,focal:!!h.focal,col:c(h.col,`the column of ${S}`),row:g,row2:g,branch:!!h.branch,shape:$,group:I==="architecture"?at(h.group):void 0,mark:I==="architecture"?Ct(h.mark):void 0})}if(I==="architecture"){const h=(t.groups??[]).map(y=>({id:String(y.id??""),label:String(y.label??""),parent:at(y.parent)})),$=new Map(h.map(y=>[y.id,y])),S=y=>{if(!y.parent)return 1;const x=$.get(y.parent);return x?x.parent===y.id||x.id===y.id?(o(`the groups "${y.label}" and "${x.label}" are each other's parent`),y.parent=void 0,1):x.parent?(o(`the group "${y.label}" is a third level: groups nest two deep`),y.parent=void 0,1):2:(o(`the group "${y.label}" names the parent "${y.parent}", which is not a group`),y.parent=void 0,1)},g=h.map(S);h.forEach((y,x)=>C.push({...y,depth:g[x],members:f.filter(E=>E.group===y.id).map(E=>E.id),all:[]}));for(const y of C)y.all=[...y.members,...C.filter(x=>x.parent===y.id).flatMap(x=>x.members)];C.sort((y,x)=>y.depth-x.depth)}}else if(I==="data-flow"){B=(t.lanes??[]).map($=>({id:String($.id??""),label:String($.label??"")}));const h=new Map(B.map(($,S)=>[$.id,S+1]));for(const $ of t.nodes??[]){const S=String($.id??""),g=String($.lane??""),y=h.get(g);y===void 0&&o(`a node (${S}) names the lane "${g}", which is not in lanes`);const x=f.length+1;f.push({id:S,i:f.length,name:String($.name??""),kind:u(x),detail:at($.detail),mono:!!$.detailMono,focal:!!$.focal,col:c($.col,`the column of ${S}`),row:y??1,row2:y??1,branch:!1,shape:"box",lane:y??1,laneLabel:B[(y??1)-1]?.label??g,step:x,mark:Ct($.mark)})}}else if(I==="sequence"){(t.participants??[]).forEach((g,y)=>{const x=String(g.name??"");f.push({id:String(g.id??""),i:y,name:x,kind:at(g.kind),mono:!1,focal:!!g.focal,col:y+1,row:1,row2:1,branch:!1,shape:"participant",short:at(g.short)??x,mark:Ct(g.mark)})});let h=0;const $=new Map(f.map(g=>[g.id,g.col])),S=(g,y)=>{let x=1/0,E=-1/0;for(const q of g??[]){if(!q||typeof q!="object")continue;if("band"in q){y>0&&o(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(q.band??"")});continue}if("frame"in q){if(y>=2){o("a frame is a third level: frames nest two deep");continue}const et=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",nt=et==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];et==="alt"&&nt.length<2&&o("an alt frame has one branch: it needs two or more");const J=String(nt[0]?.label??"");J.length>40&&o(`the frame label "${J}" is over 40 characters`);const ot=M.length;M.push({open:et,label:J,depth:y+1,a:0,b:0}),nt.forEach((X,st)=>{if(st){const xt=String(X.label??"");xt.length>40&&o(`the frame label "${xt}" is over 40 characters`),M.push({otherwise:xt,depth:y+1})}X.steps?.length||o(`a frame or branch ("${String(X.label??"")}") is empty`);const[rt,ct]=S(X.steps??[],y+1);x=Math.min(x,rt),E=Math.max(E,ct);const bt=M[ot];bt.a=Math.min(bt.a||1/0,rt),bt.b=Math.max(bt.b,ct)}),M.push({close:y+1});continue}h++;const T=String(q.label??"");T.includes(` +`)&&o(`message ${h}'s label has a break: a message's second line is its note`);const N=String(q.from??""),Q=String(q.to??"");M.push({n:h,from:N,to:Q,label:gt(T),note:at(q.note),kind:b(q.kind,`message ${h}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const U=$.get(N)??1,R=$.get(Q)??1,K=U===R?U===f.length?U-1:U+1:U;x=Math.min(x,U,R,K),E=Math.max(E,U,R,K)}return[x,E]};S(t.steps??[],0);for(const g of M)"open"in g&&!Number.isFinite(g.a)&&(g.a=1,g.b=Math.max(1,f.length))}else if(I==="schema")for(const h of t.tables??[]){const $=String(h.name??""),[S,g]=Array.isArray(h.row)?h.row:[h.row,h.row],y=c(S,`the row of ${$}`),x=Math.max(y,c(g,`the last row of ${$}`)),E=h.more===void 0||h.more===null?void 0:Number.isInteger(h.more)&&h.more>0?h.more:(o(`${$}'s "more" is ${JSON.stringify(h.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:$,i:f.length,name:$,mono:!0,focal:!!h.focal,col:c(h.col,`the column of ${$}`),row:y,row2:x,branch:!1,shape:"table",more:E,columns:(h.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&o(`${$}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}((I==="schema"?t.tables:I==="sequence"?t.participants:t.nodes)??[]).forEach((h,$)=>{if(!h||h.href===void 0||h.href===null)return;const S=String(h.href);if(I==="sequence"){o(`${f[$]?.id}: a participant cannot be a link (href)`);return}if(!S){o(`${f[$]?.id}'s href is empty`);return}const g=f[$];g&&(g.href=S,g.blank=h.target==="_blank")});const G=new Map;for(const h of f)h.id?G.has(h.id)&&o(`the id "${h.id}" is used twice`):o("a node has no id"),G.set(h.id,h);if(I==="schema")(t.tables??[]).forEach(h=>(h.columns??[]).forEach(($,S)=>{const g=at($.references);if(!g)return;const[y,x]=g.split("."),E=G.get(y??""),q=E?.columns?.findIndex(N=>N.name===x)??-1;if(!E||q<0){o(`${String(h.name)}.${String($.name)} references ${g}, which is not a shown column`);return}const T=G.get(String(h.name??""));T.columns[S].ref={table:y,column:x,row:q},v.push({i:v.length,from:T.id,to:y,kind:"plain",fromRow:S,toRow:q,fk:!0})}));else if(I!=="sequence")for(const h of t.edges??[]){const $=String(h.from??""),S=String(h.to??"");if(!G.has($)||!G.has(S)){o(`a line names ${G.has($)?S:$}, which is not a node`);continue}const g=at(h.label),y=g?.split(` `)??[];y.length>2&&o(`the label "${gt(g)}" has more than one break: a label is two lines at most`),y.some(x=>x.length>Nt)&&o(`a line of the label "${gt(g)}" is over ${Nt} characters: longer words belong in the node or the summary`),v.push({i:v.length,from:$,to:S,kind:b(h.kind,`the line from ${$} to ${S}`),label:g,fromSide:w(h.fromSide),toSide:w(h.toSide),flow:I!=="flowchart"&&h.flow===!0?!0:void 0})}else for(const h of M)"n"in h&&(!G.has(h.from)||!G.has(h.to))&&o(`message ${h.n} names ${G.has(h.from)?h.to:h.from}, which is not a participant`);if(s&&I!=="sequence"){const h=new Map;for(const $ of f)for(let S=$.row;S<=$.row2;S++){const g=`${$.col}:${S}`;h.has(g)&&o(`${$.id} and ${h.get(g)} share the cell at column ${$.col}, row ${S}`),h.set(g,$.id)}}if(s){for(const $ of C){const S=$.all.map(x=>G.get(x));if(!S.length)continue;const g={c1:Math.min(...S.map(x=>x.col)),c2:Math.max(...S.map(x=>x.col)),r1:Math.min(...S.map(x=>x.row)),r2:Math.max(...S.map(x=>x.row2))};for(const x of f)!$.all.includes(x.id)&&x.col>=g.c1&&x.col<=g.c2&&x.row>=g.r1&&x.row<=g.r2&&o(`${x.id} is inside the box of the group "${$.label}" but not a member`);const y=S.map(x=>x.i);Math.max(...y)-Math.min(...y)+1!==y.length&&o(`the members of the group "${$.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const $ of f)$.group&&!C.some(S=>S.id===$.group)&&o(`${$.id} names the group "${$.group}", which is not in groups`);f.filter($=>$.focal).length>1&&o("more than one node is focal: a diagram has one at most");const h=new Set(I==="sequence"?M.flatMap($=>"n"in $?[$.kind]:[]):v.map($=>$.kind));h.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),h.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some($=>$.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const _=I==="architecture"||I==="data-flow",Z=h=>Array.isArray(h)&&h.length>1?h.map(String):void 0,L=_&&t.packet&&typeof t.packet=="object"?t.packet:void 0,z=L&&Z(L.path),O={animated:t.motion==="animated",pulse:_?Z(t.pulse):void 0,packet:z?{path:z,repeat:L.repeat===!0,send:L.send}:void 0,run:I==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const h of f){const $=h.mark?.says;if(!$?.length)continue;const S=[h.name,h.kind,h.detail,h.laneLabel].filter(Boolean).join(" ").toLowerCase();$.some(g=>S.includes(g.toLowerCase()))||o(`${h.id}'s mark stands for ${$.join(" or ")}, and none of its words say so`)}const A=[];if(I==="sequence"){const h=new Map,$=new Map;for(const S of M)"n"in S&&($.set(S.from,S.n),$.set(S.to,S.n));for(const S of M)if("n"in S){if(S.activate){const g=h.get(S.to)??[];if(g.length>=3)o(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const y={who:S.to,from:S.n,to:S.n,depth:g.length+1};g.push(y),A.push(y),h.set(S.to,g)}}if(S.deactivate){const y=h.get(S.from)?.pop();y?y.to=S.n:o(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,g]of h)for(const y of g)y.to=Math.max(y.from,$.get(S)??y.from)}const j=t.frameLabels??{},F={opt:at(j.opt)??"Only if",loop:at(j.loop)??"Repeats",alt:at(j.alt)??"One of these",else:at(j.else)??"Otherwise"};let V=Math.max(1,...f.map(h=>h.col));if(e.rtl){for(const $ of f)$.col=V-$.col+1;const h=$=>$==="left"?"right":$==="right"?"left":$;for(const $ of v)$.fromSide=h($.fromSide),$.toSide=h($.toSide);for(const $ of M)if("open"in $){const[S,g]=[V-$.b+1,V-$.a+1];$.a=S,$.b=g}V=Math.max(1,...f.map($=>$.col))}const W=I==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(h=>h.row2)),Y={type:I,title:String(t.title??""),heading:l,legend:i,nodes:f,byId:G,edges:v,groups:C,lanes:B,steps:M,bars:A,frameWords:F,cols:V,rows:W,shapeLabels:p,stepWord:u,warnings:r,motion:O,memo:new Map,rtl:e.rtl||void 0};return s&&f.length>1&&!Lt(Y)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),Y}function Ct(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ht=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` `?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function $t(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Nt=28,jt=t=>t.includes(` -`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Dt(t,e){return t.legend[e]}function Oe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Ie(t,e){return $t(t,`sentence:${e.i}`,()=>_e(t,e))}function _e(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Gt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Oe(t,e):e.kind;if(n.push(wt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${gt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${gt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Gt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function Ce(t,e,n,s){const r=n.pointerType;if(r!=="touch"&&r!=="pen")return;const o=t.querySelector(`.${e}-drawing`),a=n.target;if(!o||!a||!o.contains(a)||!t.querySelector(`.${e}-edge`))return;const i=a.closest(`.${e}-node`);if(!i?.hasAttribute("href"))return i?i.dataset.node===s?null:i.dataset.node??null:null}function Kt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var je={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>je[e]),Be=" br img input meta link hr path polygon polyline circle rect line ";function Bt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${it(String(r))}"`}return Be.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Bt(s,e)).join("")}`}var Te=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Re(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Et(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Vt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=Et(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Zt(t,n,a)))})}return e})}function Zt(t,e,n){const s=Et(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=Et(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Ut(t){const e=Vt(t);return e[1]+e[3]}function Tt(t){return t.type==="sequence"?t.nodes.length:t.cols}function Jt(t){return $t(t,"plan",()=>We(t))}function We(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},m=t.edges.map(()=>0);let p=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,m[v.k]+1));m[c.k]=f,f>1&&(p=!0),l.push(c)}const b=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{b[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const w=ht();for(let c=1;c{const _=s[G],Z=t.byId.get(D.from).i,L=t.byId.get(D.to).i,z=L===c&&(_==="down"||_==="trunk"||_==="rail"||_==="end-down"),O=Z===c&&L===c-1&&_==="up",A=L===c-1&&_==="end-up";z&&(_==="trunk"||_==="end-down")&&(M=!0),A&&(I=!0),(z||O||A)&&D.label&&(B++,C=Math.max(C,_==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),w[f.id]=C}return{routes:s,gutter:d,lanes:m,exits:b,gaps:w,third:p}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Xt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function kt(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Yt(t,e){return $t(e,`key:${t}`,()=>Fe(t,e))}var ze=Yt;function Fe(t,e){const n=[],s=(o,a,i={})=>n.push(k("li",{class:`${t}-entry`,...i},o,k("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),k("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(kt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(kt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(kt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Xt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Xt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),k("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(kt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(kt(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function He(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Rt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Ne(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},Rt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},Rt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Ot(n.detail).flatMap((r,o)=>[o?" ":"",k("span",{class:`${t}-run`},r)]):n.detail)),s}function De(t,e,n){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},Rt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((s,r)=>k("span",{class:`${t}-row`,"data-row":r,"data-key":s.key},k("span",{class:`${t}-keyseat`},s.key??""),k("span",{class:`${t}-cname`},s.name),s.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?k("span",{class:`${t}-ctype`},s.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Qt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=Re(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=yt(d.gaps,n.id)??32,b=yt(s.grow,n.id)??0;i.push(`--_gap:${b?`calc(${Qt(l)} + var(--basalt-space-4) * ${b})`:Qt(l)}`)}const u=yt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const m=yt(s.words,n.id);m&&i.push(`--_ww:${m}px`);const p=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?Ie(e,n):void 0,tabindex:p},n.shape==="decision"?k("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ht(n.mark.onLight)};--_md:${Ht(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?De(r,n,e):Ne(r,e,n))}function Ge(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=Et(e,d);if(!u)continue;const m=[0,1,2,3].map(p=>Zt(e,d,p));r.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`},At(t,e,d,n))))),r.push(Ke(t,e)),r;const o=d=>{const u=d.group?e.groups.find(m=>m.id===d.group):void 0;return u?.parent?e.groups.find(m=>m.id===u.parent):u},a=(d,u,m)=>{const p=t.plan?yt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:p?`--_ggrow:${p}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),m)};let i=0;for(;ic.id===m[l].group):void 0;if(!b){p.push(At(t,e,m[l],n)),l++;continue}const w=[];for(;lAt(t,e,c,n))))}r.push(a(u,m,p))}return r}function Ke(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(k("p",{class:`${n}-band`},k("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=k("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=k("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),m=d?.col??1,p=u?.col??1,l=m===p,b=l&&(e.rtl?m!==1:m===e.nodes.length),w=Dt(e,i.kind);a.c.push(k("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?b?"start":"end":void 0,style:`--_a:${Math.min(m,p)};--_b:${Math.max(m,p)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(i.n)),k("span",{class:`${n}-mlabel`},i.label)),k("span",{class:`${n}-route`},d?.short??i.from," ",He(n,i.kind),k("span",{class:t.hidden}," to ")," ",u?.short??i.to,w?` · ${w}`:""),i.note?k("span",{class:`${n}-note`},i.note):null))}return k("div",{class:`${n}-steps`},s)}function Pt(t,e){return $t(e,`list:${t}`,()=>Ze(t,e))}var Ve=Pt;function Ze(t,e){const n=Math.min(6,e.heading+1),s=p=>k(`h${n}`,{class:`${t}-list-head`},p),r=p=>k("strong",null,p),o=p=>p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},r(p.name)):r(p.name),a=p=>k("code",{class:`${t}-code`},p),i=p=>e.byId.get(p)?.name??p,d=p=>{const l=Dt(e,p);return l?` (${l})`:""},u=p=>p.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const p=w=>k("li",null,o(w),w.kind?`, ${w.kind}`:"",w.detail?[". ",w.mono?a(w.detail):w.detail,/[.!?]$/.test(w.detail)?"":"."]:/[.!?]$/.test(w.kind??w.name)?"":".",u(w)),l=[s("Parts")],b=e.nodes.filter(w=>!w.group);b.length&&l.push(k("ul",{class:`${t}-list-items`},b.map(p)));for(const w of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},w.label)),w.members.length&&l.push(k("ul",{class:`${t}-list-items`},w.members.map(c=>p(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===w.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>p(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map(w=>k("li",null,r(i(w.from))," to ",r(i(w.to)),w.label?[": ",a(gt(w.label))]:"",`${d(w.kind)}.`)))),l}if(e.type==="flowchart"){const p=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const b=e.edges.filter(f=>f.from===l.id),w=l.shape==="decision"?"Decision":l.shape==="terminal"?b.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${w}.`,u(l),b.length?k("ul",{class:`${t}-list-exits`},b.map(f=>k("li",null,f.label?`If ${gt(f.label)}: go to ${p(f.to)}, `:`Then: go to ${p(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(p=>{const l=e.edges.filter(b=>b.from===p.id);return k("li",null,`${p.laneLabel}: `,o(p),p.detail?[", ",p.mono?a(p.detail):p.detail]:"",".",u(p),l.length?[" Then ",...l.flatMap((b,w)=>[w?"; ":"",`to step ${e.byId.get(b.to).step}, `,r(i(b.to)),b.label?[": ",a(gt(b.label))]:"",d(b.kind)]),"."]:"")}))];if(e.type==="sequence"){const p=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(b=>k("li",null,r(b.name),b.kind?`, ${b.kind}`:"",".",u(b),Gt(e,b))))];p.push(s("Messages"));let l=null;for(const b of e.steps){if("band"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},b.band));continue}if("open"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords[b.open]}: ${b.label}`));continue}if("otherwise"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords.else}: ${b.otherwise}`));continue}if("close"in b){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:b.n}),p.push(l)),l.c.push(k("li",null,a(b.label),": ",r(i(b.from))," to ",r(i(b.to)),`${d(b.kind)}.`,b.note?` ${wt(b.note)}`:""))}return p}const m=[];for(const p of e.nodes)m.push(k(`h${n}`,{class:`${t}-list-group`},p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},a(p.name)):a(p.name),u(p))),m.push(k("ul",{class:`${t}-list-items`},[...(p.columns??[]).map(l=>k("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...p.more?[k("li",null,`and ${p.more} more ${p.more===1?"column":"columns"}`)]:[]]));return m}function te(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Lt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Wt(t,e=!1){const n=e&&t.type!=="sequence"&&Lt(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Kt(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var Ue=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Lt(t){return $t(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...Je(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=w=>i?[w.col,w.col]:w.rows,m=w=>i?w.rows:[w.col,w.col],p=u(o),l=m(o);let b=null;return e.forEach((w,c)=>{if(w===o)return;const f=u(w),v=m(w),B=d?f[0]-p[1]:p[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!b||Ue(M,b.rank))&&(b={id:w.id,rank:M})}),b?.id??null},s=ht();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var ee=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function ne(t,e,n){const s=n.prefix,r=Te(n.base),o=t.type==="sequence"||t.type==="schema"?null:Jt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,m=`h${t.heading}`,p=[`--_cols:${Tt(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Vt(t):[0,0,0,0],b=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",w=i&&e.pad?"3":void 0;p.push(`--_gpad:${b(l[0],"8",w)} ${b(l[1],"4")} ${b(l[2],"4",w)} ${b(l[3],"4")}`)}return ee(t)&&p.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&p.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Tt(t),"data-reach":t.type==="architecture"?Ut(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:p.join(";")},k("div",{class:`${s}-head`},k(m,{id:r.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},Ge(a,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Yt(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||i&&t.type==="sequence"?k("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${Kt(t)} to highlight its lines. Tap it again to clear.`):null,k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Pt(s,t)),k("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${te(t,i)} ${n.viewer}`:te(t,i)),k("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Xe(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var qt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,oe=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2,p=e==="top"||e==="bottom";if(t.shape==="decision"){if(p){const w=n,c=m*Math.max(0,1-Math.abs(w-i)/u);return{x:w,y:e==="top"?d-c:d+c}}const l=n,b=u*Math.max(0,1-Math.abs(l-d)/m);return{x:e==="left"?i-b:i+b,y:l}}if(t.shape==="terminal"){const l=Math.min(u,m);if(p){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const b=n,w=b-d,c=Math.abs(w)>=l?0:Math.sqrt(l*l-w*w);return{x:e==="left"?s+l-c:o-l+c,y:b}}return p?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Ye(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/m<1-n/Math.min(u,m);if(e.shape==="terminal"){const p=Math.min(u,m),l=Math.min(Math.max(t.x,s+p),o-p);return Math.hypot(t.x-l,t.y-d)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function tn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var Ot=t=>t?t.split(/\s+/).filter(Boolean):[];function en(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`${t.rtl?"←":"→"} ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),m=d.mark&&!Pe()?(d.shape==="participant"?2:1)*s("6"):0;let p=0;const l=d.href?16+s("1-5"):0,b=Ot(d.name);if(b.forEach((c,f)=>{p=Math.max(p,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:m)+(f===b.length-1?l:0))}),t.type!=="data-flow")for(const c of Ot(d.kind))p=Math.max(p,n(c,"mono")+m);for(const c of Ot(d.detail))p=Math.max(p,n(c,d.mono?"mono":"sans"));const w=d.shape==="decision"?p/.62:p+u+2*e.hair;r=Math.max(r,Math.ceil(w))}const a=Tt(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(ee(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Ut(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ae(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function zt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function re(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function It(t,e,n){const s=[];for(let o=0;oMath.min(c.x,f.x)+.75&&CMath.min(v.y,B.y)+.75&&Mr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",ie={top:"bottom",bottom:"top",left:"right",right:"left"};function on(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function sn(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,m]=e[a],p=i.row===d.row&&tt(u)&&tt(m)&&u===ie[m]||i.col===d.col&&!tt(u)&&!tt(m)&&u===ie[m];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:p,f:.5},{edge:a,end:"to",node:d,side:m,far:i,straight:p,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const m=new Map;for(const c of d)m.has(c.far.id)||m.set(c.far.id,[]),m.get(c.far.id).push(c);for(const c of m.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const p=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),b=u.filter(c=>i(c)<0),w=u.filter(c=>i(c)>=0);b.forEach((c,f)=>{c.f=p*(f+1)/(b.length+1)}),w.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/(w.length+1)})}return s}function le(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?lt(t,e,r+(a-r)*n):lt(t,e,s+(o-s)*n)}function ce(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ft(o,n),shape:a.shape,i:a.i})}),r}function de(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function ue(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function an(t,e,n,s,r,o,a,i,d){const u=a.space,m=[],p=[],l=[],b=[],w=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*jt(v),M=f.pts.length-2,I=[];pt(f.pts).forEach(([L,z],O)=>{const A=Math.abs(L.y-z.y)<.01,j=A?L.x:L.y;let F=A?z.x:z.y;const V=Math.sign(F-j)||1;O===M&&(F-=V*a.head);let W=[[j,F]];for(const $ of r)for(const S of A?[$.l,$.r]:[$.t,$.b]){const g=A?L.y:L.x;(A?g>$.t&&g<$.b:g>$.l&&g<$.r)&&(W=W.flatMap(([x,E])=>S>Math.min(x,E)+1&&S{const g=($+S)/2,y=A?{x:g,y:L.y}:{x:L.x,y:g};return!r.some(x=>y.x>x.l&&y.xx.t&&y.y1&&Y($,S)?1:0})}),I.sort((L,z)=>z.pri-L.pri||z.len-L.len);let D=null,G=!1;const _=(L,z=!0)=>{const O=oe(L,w);return z&&(L.lo.r||L.to.b)||n.some(A=>se(O,A))||m.some(A=>ut(O,A))||s.heads.some(A=>ut(O,A))||s.rects.some(A=>ut(O,A))?!1:!e.some(A=>A.i!==f.i&&pt(A.pts).some(([j,F])=>ut(O,fe(j,F,A.width))))};for(const L of I){for(const z of[1/2,1/3,2/3]){const O=L.p+(L.q-L.p)*z,A=[],j=u("2")+f.width/2;if(L.horiz?(L.len>=B+2*u("1")+u("3-5")&&A.push({box:{l:O-B/2-u("1"),r:O+B/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),A.push({box:{l:O-B/2,r:O+B/2,t:L.c-j-C,b:L.c-j},on:!1}),A.push({box:{l:O-B/2,r:O+B/2,t:L.c+j,b:L.c+j+C},on:!1})):(L.len>=C+u("3")&&A.push({box:{l:L.c-B/2-u("1"),r:L.c+B/2+u("1"),t:O-C/2,b:O+C/2},on:!0}),A.push({box:{l:L.c+j,r:L.c+j+B,t:O-C/2,b:O+C/2},on:!1}),A.push({box:{l:L.c-j-B,r:L.c-j,t:O-C/2,b:O+C/2},on:!1})),D=A.find(F=>_(F.box))??null,D)break;!G&&A.some(F=>_(F.box,!1))&&(G=!0)}if(D)break}if(!D){l.push(f.i),G&&b.push(f.i);continue}const Z=ue(D.box,d.ox,d.oy,L=>_(L));m.push(Z),p.push({i:f.i,text:v,box:Z,on:D.on})}return{labels:p,unseated:l,bounded:b}}function he(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=ft(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(ft(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=ft(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(ft(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function rn(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,m=ce(s,a,i,o),p=[...m.values()],l=nn(a),b=i.left-Math.floor(i.left),w=i.top-Math.floor(i.top),c=ae(b,w),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:b,oy:w};if(s.type==="sequence")return cn(t,M,c);let I,D=[];s.type==="schema"?I=s.edges.map(g=>{const y=s.byId.get(g.from),x=s.byId.get(g.to);if(y.col===x.col){const E=y.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return x.col>y.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const y=s.byId.get(g.from),x=s.byId.get(g.to),[E,q]=on(y,x);return[g.fromSide??E,g.toSide??q]}),D=sn(s,I,d||(()=>{})));const G=(g,y)=>{const x=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${y}"]`);if(!x)return 0;const E=ft(x,i);return(E.t+E.b)/2},_=s.edges.map((g,y)=>{const[x,E]=I[y],q=m.get(g.from),T=m.get(g.to),H=qt(g.kind,r);if(g.fk){const J=G(g.from,g.fromRow),ot=G(g.to,g.toRow),X=c.y(J,H),st=c.y(ot,H);return{p1:{x:x==="right"?q.rect.r:q.rect.l,y:X},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:J,r2:Math.abs(X-st)<.01?J:ot}}const Q=D.find(J=>J.edge===y&&J.end==="from").f,U=D.find(J=>J.edge===y&&J.end==="to").f;let R=le(q,x,Q),K=le(T,E,U);const et=tt(x)?R.y:R.x;let nt=tt(E)?K.y:K.x;return tt(x)?R={...R,y:c.y(R.y,H)}:R={...R,x:c.x(R.x,H)},tt(E)?K={...K,y:c.y(K.y,H)}:K={...K,x:c.x(K.x,H)},tt(x)&&tt(E)&&Math.abs(R.y-K.y)<1.01&&(K={...K,y:R.y},nt=et),!tt(x)&&!tt(E)&&Math.abs(R.x-K.x)<1.01&&(K={...K,x:R.x},nt=et),R=tt(x)?lt(q,x,R.y):lt(q,x,R.x),K=tt(E)?lt(T,E,K.y):lt(T,E,K.x),{p1:R,p2:K,r1:et,r2:nt}}),Z=new Set;s.type==="schema"&&s.edges.forEach((g,y)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&Z.add(y)});const L=new Map,z=new Set;s.edges.forEach((g,y)=>{if(Z.has(y))return;const[x,E]=I[y],{p1:q,p2:T}=_[y],H=s.byId.get(g.from),Q=s.byId.get(g.to);let U=null,R=null,K=!1;if(x===E){if(tt(x)){const J=x==="right"?Math.max(B(H),B(Q)):Math.min(B(H),B(Q))-1,ot=l.cols[J-1],X=l.cols[J];ot&&X&&(U=`c${J}`,R=[ot[1],X[0]],K=!0)}else{const J=x==="bottom"?Math.max(H.row2,Q.row2):Math.min(H.row,Q.row)-1,ot=l.rows[J-1],X=l.rows[J];ot&&X&&(U=`r${J}`,R=[ot[1],X[0]],K=!1)}U&&z.add(y)}else if(tt(x)&&tt(E)&&Math.abs(q.y-T.y)>.5){const J=B(Q),ot=E==="left",X=l.cols[(ot?J-1:J)-1],st=l.cols[(ot?J:J+1)-1];X&&st&&(U=`c${ot?J-1:J}`,R=[X[1],st[0]],K=!0)}else if(!tt(x)&&!tt(E)&&Math.abs(q.x-T.x)>.5){const ot=E==="top"?Q.row-1:Q.row2,X=l.rows[ot-1],st=l.rows[ot];X&&st&&(U=`r${ot}`,R=[X[1],st[0]],K=!1)}if(!U||!R)return;L.has(U)||L.set(U,{span:R,vertical:K,members:new Map});const et=`${g.to}.${E}.${Math.round(K?T.y:T.x)}`,nt=L.get(U);nt.members.has(et)||nt.members.set(et,[]),nt.members.get(et).push(y)});const O=new Map,A=g=>{const[y,x]=I[g],{p1:E,p2:q}=_[g];if(tt(y)&&tt(x)){if(y===x){const H=O.get(g)??(y==="right"?Math.max(E.x,q.x)+u("4"):Math.min(E.x,q.x)-u("4"));return[E,{x:H,y:E.y},{x:H,y:q.y},q]}if(Math.abs(E.y-q.y)<=.5)return[E,{x:q.x,y:E.y}];const T=O.get(g)??(E.x+q.x)/2;return[E,{x:T,y:E.y},{x:T,y:q.y},q]}if(!tt(y)&&!tt(x)){if(y===x){const H=O.get(g)??(y==="bottom"?Math.max(E.y,q.y)+u("4"):Math.min(E.y,q.y)-u("4"));return[E,{x:E.x,y:H},{x:q.x,y:H},q]}if(Math.abs(E.x-q.x)<=.5)return[E,{x:E.x,y:q.y}];const T=O.get(g)??(E.y+q.y)/2;return[E,{x:E.x,y:T},{x:q.x,y:T},q]}return tt(y)?[E,{x:q.x,y:E.y},q]:[E,{x:E.x,y:q.y},q]},j=g=>{const y=s.edges[g],x=qt(y.kind,r),E=A(g),q=re(E,x,c);let T;return E.length===q.length&&(T=pt(E).map(([H,Q])=>Math.abs(H.y-Q.y)<.75?(H.y+Q.y)/2:(H.x+Q.x)/2),T[0]=_[g].r1,T.length>1&&(T[T.length-1]=_[g].r2)),{i:g,from:y.from,to:y.to,kind:y.kind,pts:q,tip:q[q.length-1],dir:zt(q),dot:y.fk?q[0]:void 0,width:x,axes:T}},F=()=>s.edges.flatMap((g,y)=>Z.has(y)?[]:[j(y)]);let V=null;const W=g=>{V??(V=F());const y=V.map(x=>g.has(x.i)?j(x.i):x);return{lines:y,score:ln(y,g)*1e5+It(y,void 0,g).length*1e3+Ft(y.filter(x=>g.has(x.i)),p,s).length}},Y=(g,y)=>{const x=g.flatMap(E=>{const{p1:q,p2:T}=_[E];return y?[q.y,T.y]:[q.x,T.x]});return[Math.min(...x),Math.max(...x)]};for(const[,g]of L){const y=[...g.members.values()].map(E=>({members:E,run:Y(E,g.vertical)})).sort((E,q)=>E.run[0]-q.run[0]),x=[];for(const E of y){const q=x[x.length-1];q&&q.some(T=>T.run[0]z.has(et)))continue;const q=E.map(et=>et.members),T=q.length,H=(g.span[1]-g.span[0])/(T+1);HJ.forEach(X=>O.set(X,g.span[0]+H*(ot+1))));const nt=W(Q);nt.scoreet.forEach(J=>O.set(J,g.span[0]+H*(nt+1)))),V=K}}M.lines=F();for(const g of Z)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=It(M.lines),M.through=Ft(M.lines,p,s),M.outside=me(M.lines,f,v,r);const{obstacles:h,groups:$}=he(a,i,o,C);h.heads=M.lines.map(g=>de(g,r));const S=an(s,M.lines,p,h,$,{l:0,t:0,r:f,b:v},r,e,{ox:b,oy:w});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(pe(M.lines,null).flat())],M}function ln(t,e){return pe(t,e).length}function pe(t,e){const n=[];for(let s=0;s=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[m.x,p.x]:[m.y,p.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*ge(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Ft(t,e,n){const s=[];for(const r of t){const o=pt(r.pts);e.some(a=>o.some(([i,d])=>Qe(i,d,a)))&&s.push(r.i)}return s}function cn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,ft(M,i)));const m=a.querySelector(`.${o}-steps`),p=m?ft(m,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:p})}const b=M=>u.get(M.id),w=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=ft(M,i);w.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const D=l(M.who),_=(I.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),Z=(M.depth-1)*d("1")*_,L=w.get(M.from)??0,z=w.get(M.to)??L,O=M.from===M.to;return{l:n.x(D-f+Z,r.hair),r:n.x(D+f+Z,r.hair),t:n.y(O?L-d("2")-d("1"):L,r.hair),b:n.y(O?L+d("2")+d("1"):z,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,D)=>B.filter(({bar:G})=>G.who===M&&G.to>=I&&(D?G.from<=I:G.from_.bar.depth-G.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,D=M.dataset.to,G=M.dataset.kind??"plain",_=qt(G,r),Z=ft(M,i),L=n.y((Z.t+Z.b)/2,_),z=Number(M.querySelector(`.${o}-num`)?.textContent??0);let O=l(I),A=l(D),j;if(I===D){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,z,!0),y=g?S>0?g.r:g.l:O,x=n.y(L-d("2"),_),E=n.y(L+d("2"),_);j=[{x:y,y:x},{x:n.x(O+S,_),y:x},{x:n.x(O+S,_),y:E},{x:y,y:E}]}else{const S=A>O?1:-1,g=C(I,z,!1),y=C(D,z,!0);g&&(O=S>0?g.r:g.l),y&&(A=S>0?y.l:y.r),j=[{x:O,y:L},{x:A,y:L}]}e.lines.push({i:z,from:I,to:D,kind:G,pts:j,tip:j[j.length-1],dir:zt(j),width:_});const F=M.querySelector(`.${o}-said`),V=M.querySelector(`.${o}-note`),W=s.byId.get(I),Y=s.byId.get(D);if(!W||!Y)return;const h=I===D?(()=>{const S=s.nodes[W.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-O)-d("6")-d("2-5")-d("2")})():Math.abs(A-O)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,V?V.getBoundingClientRect().width:0)>h+.5&&e.unseated.push(z)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((G,_)=>G+_.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ye(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,m=ce(r,i,d,a),p=[...m.values()],l=d.left-Math.floor(d.left),b=d.top-Math.floor(d.top),w=ae(l,b),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:b},B=ht();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(A,j,F)=>{const V=[A];for(let W=1;W<=(yt(s,j)??0);W++)V.push({...A,t:A.t+F*u("4")*W,b:A.b+F*u("4")*W});return V},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(A=>{const j=A.parentElement,F=ft(j,d),V=getComputedStyle(j);I.set(A.dataset.node,F.r-(parseFloat(V.paddingRight)||0)-(parseFloat(V.borderRightWidth)||0))});const D=r.nodes,G=A=>m.get(D[A].id),_=[],Z=A=>qt(r.edges[A].kind,o);r.edges.forEach((A,j)=>{const F=n.routes[j],V=m.get(A.from),W=m.get(A.to),Y=Z(j);let h=[];const $=A.label,S=$?e($,"label"):0,g=$?16*jt($):16,y=u("4");if(F==="down"||F==="up"){const E=Math.max(V.rect.l,W.rect.l),q=Math.min(V.rect.r,W.rect.r),T=r.edges.map((R,K)=>({o:R,j:K})).filter(({o:R,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(R.from===A.from&&R.to===A.to||R.from===A.to&&R.to===A.from)),H=T.findIndex(R=>R.j===j),Q=T.length<2?.5:T.length===2?H===0?.25:.75:(H+1)/(T.length+1),U=w.x(E+(q-E)*Q,Y);if(h=F==="down"?[lt(V,"bottom",U),lt(W,"top",U)]:[lt(V,"top",U),lt(W,"bottom",U)],$){let R=Math.min(h[0].y,h[1].y),K=Math.max(h[0].y,h[1].y);F==="down"?K-=o.head:R+=o.head;const et=[...i.querySelectorAll(`.${a}-group`)].map(X=>ft(X,d));let nt=[[R,K]];for(const X of et)for(const st of[X.t,X.b])nt=nt.flatMap(([rt,ct])=>st>rt+1&&stet.some(rt=>(X+st)/2>rt.t&&(X+st)/2rt.l&&U1){const X=nt.filter(([rt,ct])=>!J(rt,ct));[R,K]=(X.length?X:nt).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const ot=[1/2,1/3,2/3].map(X=>{const st=R+(K-R)*X;return{l:U-S/2-u("1"),r:U+S/2+u("1"),t:st-g/2,b:st+g/2}});_.push({k:j,cands:ot,on:!0,card:F==="down"?A.to:A.from})}}else if(F==="trunk"||F==="rail"){const E=w.x(Math.max(V.rect.l,F==="rail"?W.rect.l:V.rect.l)+u(F==="trunk"?"8":"3"),Y),q=lt(V,"bottom",E);if(F==="rail"){if(h=[q,lt(W,"top",E)],$){const T=W.rect.t-u("6");_.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},A.to,-1),on:!1,card:A.to})}}else{const T=w.x(W.rect.l+u("6"),Y),H=w.y(W.rect.t-y,Y);h=[q,{x:E,y:H},{x:T,y:H},lt(W,"top",T)],$&&_.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:H-g/2,b:H+g/2},A.to,-1),on:!1,card:A.to})}}else{const E=Math.min(I.get(A.from)??c,I.get(A.to)??c),q=w.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),Y),T=w.y(V.rect.t+(V.rect.b-V.rect.t)*n.exits[j],Y),H=lt(V,"right",T),Q=w.x(W.rect.r-u("6"),Y),U=F==="end-down",R=w.y(U?W.rect.t-y:W.rect.b+y,Y);h=[H,{x:q,y:H.y},{x:q,y:R},{x:Q,y:R},lt(W,U?"top":"bottom",Q)];const K=U?A.to:D[W.i+1]?.id??A.to;$&&_.push({k:j,cands:M({l:Q-u("2-5")-S,r:Q-u("2-5"),t:R-g/2,b:R+g/2},K,U?-1:1),on:!1,card:K})}const x=re(h,Y,w);v.lines.push({i:j,from:A.from,to:A.to,kind:A.kind,pts:x,tip:x[x.length-1],dir:zt(x),width:Y})}),v.crossings=It(v.lines),v.through=Ft(v.lines,p,r),v.outside=me(v.lines,c,f,o);const{obstacles:L}=he(i,d,a,0);L.heads=v.lines.map(A=>de(A,o));const z=[],O={l:0,t:0,r:c,b:f};for(const A of _){const j=W=>{const Y=oe(W,u("1"));return W.lO.r+.5||W.tO.b+.5||p.some(h=>se(Y,h))||z.some(h=>ut(Y,h))||L.heads.some(h=>ut(Y,h))||L.rects.some(h=>ut(Y,h))||v.lines.some(h=>h.i!==A.k&&pt(h.pts).some(([$,S])=>ut(Y,fe($,S,h.width))))},F=A.cands.find(W=>!j(W));F||(B[A.card]=(B[A.card]??0)+1,v.unseated.push(A.k));const V=F?ue(F,l,b,W=>!j(W)):A.cands[0];z.push(V),v.labels.push({i:A.k,text:r.edges[A.k].label,box:V,on:A.on})}return{geo:v,grow:B}}function dn(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...M})),p=m[m.length-1];p.x-=o.x*u,p.y-=o.y*u;const l=e.tip.x-o.x*i,b=e.tip.y-o.y*i,w=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=it(e.kind),B=a?``:``,C=e.dot?``:"";return`${B}${C}`}function be(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const m=d.map(p=>{const l=e.lines[p.top],b=e.lines[p.under],w=l.width/2+n.cut,c=b.width/2+1;return p.underVertical?``:``}).join("");a+=`${m}`}return{defs:a,ids:r}}function $e(t,e,n,s){const{defs:r,ids:o}=be(t,e,n,s),a=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),i=e.lines.map((m,p)=>un(t,m,n,o.get(p)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),d=`${r?`${r}`:""}${a}${i}`,u=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` -`).map(it).join("
")}
`).join("");return d+u}function we(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const m=Xe(t),p=tn(u,n),l=en(e,m,p);i?.(l.least);const b=t.clientWidth,w=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),c=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:w&&L.layout!=="drawn"?w:void 0};let f=!1;const v=L=>{if(f=!1,e.type!=="flowchart")return L;o({...L,heights:void 0,words:void 0});const z=ht(),O=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(A=>{const j=A.querySelector(`.${n}-words`);if(!j)return;const F=A.getBoundingClientRect(),V=h=>{const $={w:h.width+2*m.space("2-5"),h:h.height+2*m.space("2")},S=1-$.w/F.width,g=S>.05?$.h/2/S:$.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},W=j.getBoundingClientRect();let Y=V(W);if(Y>F.width){const h=y=>(A.style.setProperty("--_ww",`${y}px`),j.getBoundingClientRect()),$=Math.floor(A.clientWidth-2*m.space("2-5"));let S=Math.ceil(W.width),g=W.height;for(;S<$&&h($).height1;){const T=y+x>>1;h(T).heightF.width&&(f=!0)}),{...L,heights:z,words:Object.keys(O).length?O:void 0}},B=()=>({m:e,tk:m,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(L,z)=>z.map(O=>Mt(e,L.lines.find(A=>A.i===O))).join(", ");if(b>=l.least){const L=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:rn(B(),p)}};let{dd:z,g:O}=L(!1);const A=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!A(O)&&O.unseated.length&&O.unseated.every(j=>O.bounded?.includes(j))){const j=L(!0);!A(j.g)&&!j.g.unseated.length&&({dd:z,g:O}=j)}if(!A(O)&&!O.unseated.length)return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the drawn layout: ${O.crossings.map(j=>`${Mt(e,O.lines[j.top])} over ${Mt(e,O.lines[j.under])}`).join("; ")}`),{dyn:z,geo:O,ink:$e(n,O,m,s),tokens:m,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: a decision would be taller than it is wide`),O.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${O.misfit.join("; ")}`),O.through.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.through)} would pass through a node`),O.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.overlaps)} would lie on one another`),O.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.outside)} would leave the drawing`),O.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: no clean seat for ${O.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:m,least:l.least};const D=Jt(e);let G=ye(B(),p,D,I.grow);for(let L=0;L<6&&Object.keys(G.grow).length;L++){const z=ht(I.grow);for(const[O,A]of Object.entries(G.grow))z[O]=(yt(z,O)??0)+A;I={...I,grow:z},o(I),G=ye(B(),p,D,z)}const _=G.geo;if(_.unseated.length>0||_.through.length>0||_.outside.length>0||D.third){_.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(_.unseated)].map(O=>`"${e.edges[O]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),_.through.length&&a?.(`in the stacked drawing ${M(_,_.through)} would pass through a node, so its lines are not drawn`),_.outside.length&&a?.(`in the stacked drawing ${M(_,_.outside)} would leave the drawing, so its lines are not drawn`),D.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={..._,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:L,ink:"",tokens:m,least:l.least}}return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${_.crossings.map(L=>`${Mt(e,_.lines[L.top])} over ${Mt(e,_.lines[L.under])}`).join("; ")}`),{dyn:I,geo:_,ink:$e(n,_,m,s),tokens:m,least:l.least}}function Mt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function hn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const m=It(n.lines,i),{defs:p,ids:l}=be(e,{...n,crossings:m},s,r),b=t.querySelector(`.${e}-svg`);if(!b)return;let w=b.querySelector("defs");!w&&p&&(w=document.createElementNS("http://www.w3.org/2000/svg","defs"),b.insertBefore(w,b.firstChild)),w&&(w.innerHTML=p),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var pn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function gn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",pn()||yn(t)?"done":"pending")}}var mn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function yn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(mn(t))!==null}catch{return!1}}function ve(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function bn(t,e,n,s=!1,r=!1){const o=s?Lt(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var $n=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],xe=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],wn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ke=t=>t==null||t===!1;function vn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Me(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?xe:$n;for(const a of s)ke(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,m=new Map(String(i??"").split(";").map(p=>{const l=p.indexOf(":");return[p.slice(0,l).trim(),p.slice(l+1).trim()]}).filter(([p])=>p));for(const[p,l]of m)u.getPropertyValue(p).trim()!==l&&u.setProperty(p,l);for(const p of wn)m.has(p)||u.removeProperty(p);continue}if(n&&!xe.includes(a))continue;if(ke(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,b,w){return{prefix:n,base:l,hasSource:b.source!==void 0&&b.source!==null&&b.source!=="",hiddenClass:"visually-hidden",viewer:w?w.keys:void 0}}function o(l,b,w,c){var f=function(v){return''+it(v)+""};return{source:it(String(b.source||"")),summary:it(String(b.summary||"")),hint:Wt(l).map(function(v){return""+v.keys.map(f).join(" ")+" "+it(v.words)+""}).join(""),toggle:'"}}function a(l,b,w){var c=_t(l),f=ne(c,{},r(b,l,w)),v=Bt(f,o(c,l,b,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,b,w,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=_t(b,{rtl:getComputedStyle(l).direction==="rtl"});if(!w||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(b,f,c),C=document.createElement("div");C.innerHTML=B.open+"";var M=C.firstChild;i.forEach(function(N){l.removeAttribute(N)}),d.forEach(function(N){l.style.removeProperty(N)});for(var I=0;I :not(script[data-diagram])").forEach(function(N){N.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var G=r(f,b,c),_={},Z=null,L=null,z=null,O=null,A=Object.create(null),j=function(N){A[N]||(A[N]=1,console.warn("Basalt diagram: "+N))},F=function(N){Me(l,ne(v,N,G))},V=l.querySelector(".diagram-ink"),W=l.querySelector(".diagram-toggle"),Y=!c&&v.motion.animated&&typeof e.diagramMotion=="function",h=null,$=null,S=function(){Y&&ve(l)};function g(){hn(l,n,Z&&Z.geo,Z&&Z.tokens,f,L||O||z),E()}var y=null,x=!c&&matchMedia("(hover: none), (pointer: coarse)").matches;function E(){var N=x&&!c&&V&&V.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(x&&!c)),N&&!y){var P=l.querySelector(":scope > .diagram-foot");if(!P)return;y=document.createElement("button"),y.type="button",y.className="btn diagram-clear",y.setAttribute("data-variant","secondary"),y.setAttribute("data-size","sm"),y.innerHTML="Clear highlight",y.addEventListener("click",function(){O&&(O=null,g())}),P.appendChild(y)}else!N&&y&&(y.remove(),y=null);y&&(O?y.removeAttribute("aria-disabled"):y.setAttribute("aria-disabled","true"))}function q(N){if(!N.defaultPrevented){var P=Ce(l,n,N,O);P!==void 0&&(S(),x=!0,O=P,g())}}function T(){W&&(W.setAttribute("aria-expanded",String(!!_.open)),W.firstElementChild.textContent=_.open?"Hide the list":"View as list")}function H(){Z=(c?c.measure:we)(l,v,n,f,_,F,j),_=Z.dyn,F(_),T();var N=l.querySelector(":scope > .diagram-hint");if(N){var P=Wt(v,_.layout==="drawn").map(function(St){return""+St.keys.map(function(kn){return''+it(kn)+""}).join(" ")+" "+it(St.words)+""}).join("");N.innerHTML!==P&&(N.innerHTML=P)}mt(v,_)||(z=O=null);var dt=V&&Z.ink!==$;dt&&(V.innerHTML=Z.ink,$=Z.ink),g(),Y&&Z.tokens&&(gn(l,!!(Z.geo&&Z.geo.lines.length)),dt&&h&&h.redrawn()),c&&c.onMeasured&&Z.tokens&&c.onMeasured(Z,l)}function Q(N){_=N,F(_)}function U(N){var P=_.stop;_=Object.assign({},_,{stop:N}),xn(l,n,P,N)}var R=function(N){var P=N&&N.closest?N.closest(".diagram-node"):null;return P&&l.contains(P)?P:null};function K(N){var P=R(N.target);if(!(!P||N.defaultPrevented)){if(S(),N.key==="Escape"){!c&&(L||z||O)&&(N.preventDefault(),L=z=O=null,g());return}if(mt(v,_)){var dt=bn(v,P.getAttribute("data-node"),N.key,_.layout==="drawn");if(dt){N.preventDefault(),U(dt);var St=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');St&&St.focus()}}}}function et(N){var P=R(N.target);if(P){S();var dt=P.getAttribute("data-node");L=P.matches(":focus-visible")?dt:null,mt(v,_)&&_.stop!==dt&&U(dt),g()}}function nt(N){var P=R(N.target);P&&(R(N.relatedTarget)||(L=null),_.keep===P.getAttribute("data-node")&&Q(Object.assign({},_,{keep:void 0})),g())}function J(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var P=R(N.target);P&&S();var dt=P&&mt(v,_)?P.getAttribute("data-node"):null;dt!==z&&(z=dt,g())}}function ot(){z&&(z=null,g())}function X(){S(),Q(Object.assign({},_,{open:!_.open,autoOpen:void 0})),T()}l.addEventListener("keydown",K),l.addEventListener("focusin",et),l.addEventListener("focusout",nt),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",ot),l.addEventListener("click",q),W&&W.addEventListener("click",X),H();var st=l.clientWidth,rt=0,ct=!0,bt=new ResizeObserver(function(){Math.abs(l.clientWidth-st)<.5||(st=l.clientWidth,cancelAnimationFrame(rt),rt=requestAnimationFrame(H))});bt.observe(l),document.fonts&&document.fonts.ready.then(function(){ct&&H()});var xt=matchMedia("(forced-colors: active)"),Se=v.nodes.some(function(N){return N.mark});Se&&xt.addEventListener("change",H),Y&&(h=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return Z&&Z.geo},tokens:function(){return Z&&Z.tokens}},b));var Ee=!c&&b.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,b,{model:v,settle:S,animated:Y}):null;l.__diagram={stop:function(){Ee&&Ee.destroy(),ct=!1,bt.disconnect(),cancelAnimationFrame(rt),Se&&xt.removeEventListener("change",H),h&&h.destroy(),l.removeEventListener("keydown",K),l.removeEventListener("focusin",et),l.removeEventListener("focusout",nt),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",ot),l.removeEventListener("click",q),y&&y.remove(),W&&W.removeEventListener("click",X)},layout:H,key:m(b),send:h&&h.sendValue?h.sendValue:null}}function m(l){try{return JSON.stringify(l,function(b,w){return b==="packet"&&w&&typeof w=="object"?Object.assign({},w,{send:void 0}):w})}catch{return null}}function p(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var b=l.querySelector(":scope > script[data-diagram]");if(b)try{u(l,JSON.parse(b.textContent),!0)}catch(w){console.error("Basalt diagram: this figure could not be drawn",w)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:_t,figureKey:ze,figureList:Ve,hintEntries:Wt,toHtml:Bt,escapeHtml:it,settleEntrance:ve,measureFigure:we},t.diagram=function(l,b){var w=l.__diagram,c=w&&w.send?m(b):null;if(c!==null&&c===w.key){w.send(b.packet?b.packet.send:void 0);return}u(l,b)},e.step(62,"wireDiagrams",p)})(window.Basalt)})(); +`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Dt(t,e){return t.legend[e]}function Ie(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function _e(t,e){return $t(t,`sentence:${e.i}`,()=>Ce(t,e))}function Ce(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Gt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Ie(t,e):e.kind;if(n.push(wt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${gt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${gt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Gt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function je(t,e,n,s){const r=n.pointerType;if(r!=="touch"&&r!=="pen")return;const o=t.querySelector(`.${e}-drawing`),a=n.target;if(!o||!a||!o.contains(a)||!t.querySelector(`.${e}-edge`))return;const i=a.closest(`.${e}-node`);if(!i?.hasAttribute("href"))return i?i.dataset.node===s?null:i.dataset.node??null:null}function Kt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var Be={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>Be[e]),Te=" br img input meta link hr path polygon polyline circle rect line ";function Bt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${it(String(r))}"`}return Te.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Bt(s,e)).join("")}`}var Re=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function We(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Et(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Vt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=Et(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Zt(t,n,a)))})}return e})}function Zt(t,e,n){const s=Et(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=Et(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Ut(t){const e=Vt(t);return e[1]+e[3]}function Tt(t){return t.type==="sequence"?t.nodes.length:t.cols}function Jt(t){return $t(t,"plan",()=>ze(t))}function ze(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},m=t.edges.map(()=>0);let p=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,m[v.k]+1));m[c.k]=f,f>1&&(p=!0),l.push(c)}const b=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{b[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const w=ht();for(let c=1;c{const _=s[G],Z=t.byId.get(D.from).i,L=t.byId.get(D.to).i,z=L===c&&(_==="down"||_==="trunk"||_==="rail"||_==="end-down"),O=Z===c&&L===c-1&&_==="up",A=L===c-1&&_==="end-up";z&&(_==="trunk"||_==="end-down")&&(M=!0),A&&(I=!0),(z||O||A)&&D.label&&(B++,C=Math.max(C,_==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),w[f.id]=C}return{routes:s,gutter:d,lanes:m,exits:b,gaps:w,third:p}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Xt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function kt(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Yt(t,e){return $t(e,`key:${t}`,()=>He(t,e))}var Fe=Yt;function He(t,e){const n=[],s=(o,a,i={})=>n.push(k("li",{class:`${t}-entry`,...i},o,k("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),k("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(kt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(kt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(kt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Xt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Xt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),k("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(kt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(kt(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Ne(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Rt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function De(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},Rt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},Rt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Ot(n.detail).flatMap((r,o)=>[o?" ":"",k("span",{class:`${t}-run`},r)]):n.detail)),s}function Ge(t,e,n){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},Rt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((s,r)=>k("span",{class:`${t}-row`,"data-row":r,"data-key":s.key},k("span",{class:`${t}-keyseat`},s.key??""),k("span",{class:`${t}-cname`},s.name),s.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?k("span",{class:`${t}-ctype`},s.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Qt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=We(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=yt(d.gaps,n.id)??32,b=yt(s.grow,n.id)??0;i.push(`--_gap:${b?`calc(${Qt(l)} + var(--basalt-space-4) * ${b})`:Qt(l)}`)}const u=yt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const m=yt(s.words,n.id);m&&i.push(`--_ww:${m}px`);const p=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?_e(e,n):void 0,tabindex:p},n.shape==="decision"?k("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ht(n.mark.onLight)};--_md:${Ht(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Ge(r,n,e):De(r,e,n))}function Ke(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=Et(e,d);if(!u)continue;const m=[0,1,2,3].map(p=>Zt(e,d,p));r.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${d.col}`:void 0},At(t,e,d,n))))),r.push(Ve(t,e)),r;const o=d=>{const u=d.group?e.groups.find(m=>m.id===d.group):void 0;return u?.parent?e.groups.find(m=>m.id===u.parent):u},a=(d,u,m)=>{const p=t.plan?yt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:p?`--_ggrow:${p}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),m)};let i=0;for(;ic.id===m[l].group):void 0;if(!b){p.push(At(t,e,m[l],n)),l++;continue}const w=[];for(;lAt(t,e,c,n))))}r.push(a(u,m,p))}return r}function Ve(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(k("p",{class:`${n}-band`},k("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=k("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=k("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),m=d?.col??1,p=u?.col??1,l=m===p,b=l&&(e.rtl?m!==1:m===e.nodes.length),w=Dt(e,i.kind);a.c.push(k("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?b?"start":"end":void 0,style:`--_a:${Math.min(m,p)};--_b:${Math.max(m,p)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(i.n)),k("span",{class:`${n}-mlabel`},i.label)),k("span",{class:`${n}-route`},d?.short??i.from," ",Ne(n,i.kind),k("span",{class:t.hidden}," to ")," ",u?.short??i.to,w?` · ${w}`:""),i.note?k("span",{class:`${n}-note`},i.note):null))}return k("div",{class:`${n}-steps`},s)}function Pt(t,e){return $t(e,`list:${t}`,()=>Ue(t,e))}var Ze=Pt;function Ue(t,e){const n=Math.min(6,e.heading+1),s=p=>k(`h${n}`,{class:`${t}-list-head`},p),r=p=>k("strong",null,p),o=p=>p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},r(p.name)):r(p.name),a=p=>k("code",{class:`${t}-code`},p),i=p=>e.byId.get(p)?.name??p,d=p=>{const l=Dt(e,p);return l?` (${l})`:""},u=p=>p.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const p=w=>k("li",null,o(w),w.kind?`, ${w.kind}`:"",w.detail?[". ",w.mono?a(w.detail):w.detail,/[.!?]$/.test(w.detail)?"":"."]:/[.!?]$/.test(w.kind??w.name)?"":".",u(w)),l=[s("Parts")],b=e.nodes.filter(w=>!w.group);b.length&&l.push(k("ul",{class:`${t}-list-items`},b.map(p)));for(const w of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},w.label)),w.members.length&&l.push(k("ul",{class:`${t}-list-items`},w.members.map(c=>p(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===w.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>p(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map(w=>k("li",null,r(i(w.from))," to ",r(i(w.to)),w.label?[": ",a(gt(w.label))]:"",`${d(w.kind)}.`)))),l}if(e.type==="flowchart"){const p=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const b=e.edges.filter(f=>f.from===l.id),w=l.shape==="decision"?"Decision":l.shape==="terminal"?b.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${w}.`,u(l),b.length?k("ul",{class:`${t}-list-exits`},b.map(f=>k("li",null,f.label?`If ${gt(f.label)}: go to ${p(f.to)}, `:`Then: go to ${p(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(p=>{const l=e.edges.filter(b=>b.from===p.id);return k("li",null,`${p.laneLabel}: `,o(p),p.detail?[", ",p.mono?a(p.detail):p.detail]:"",".",u(p),l.length?[" Then ",...l.flatMap((b,w)=>[w?"; ":"",`to step ${e.byId.get(b.to).step}, `,r(i(b.to)),b.label?[": ",a(gt(b.label))]:"",d(b.kind)]),"."]:"")}))];if(e.type==="sequence"){const p=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(b=>k("li",null,r(b.name),b.kind?`, ${b.kind}`:"",".",u(b),Gt(e,b))))];p.push(s("Messages"));let l=null;for(const b of e.steps){if("band"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},b.band));continue}if("open"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords[b.open]}: ${b.label}`));continue}if("otherwise"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords.else}: ${b.otherwise}`));continue}if("close"in b){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:b.n}),p.push(l)),l.c.push(k("li",null,a(b.label),": ",r(i(b.from))," to ",r(i(b.to)),`${d(b.kind)}.`,b.note?` ${wt(b.note)}`:""))}return p}const m=[];for(const p of e.nodes)m.push(k(`h${n}`,{class:`${t}-list-group`},p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},a(p.name)):a(p.name),u(p))),m.push(k("ul",{class:`${t}-list-items`},[...(p.columns??[]).map(l=>k("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...p.more?[k("li",null,`and ${p.more} more ${p.more===1?"column":"columns"}`)]:[]]));return m}function te(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Lt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Wt(t,e=!1){const n=e&&t.type!=="sequence"&&Lt(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Kt(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var Je=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Lt(t){return $t(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...Xe(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=w=>i?[w.col,w.col]:w.rows,m=w=>i?w.rows:[w.col,w.col],p=u(o),l=m(o);let b=null;return e.forEach((w,c)=>{if(w===o)return;const f=u(w),v=m(w),B=d?f[0]-p[1]:p[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!b||Je(M,b.rank))&&(b={id:w.id,rank:M})}),b?.id??null},s=ht();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var ee=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function ne(t,e,n){const s=n.prefix,r=Re(n.base),o=t.type==="sequence"||t.type==="schema"?null:Jt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,m=`h${t.heading}`,p=[`--_cols:${Tt(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Vt(t):[0,0,0,0],b=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",w=i&&e.pad?"3":void 0;p.push(`--_gpad:${b(l[0],"8",w)} ${b(l[1],"4")} ${b(l[2],"4",w)} ${b(l[3],"4")}`)}return ee(t)&&p.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&p.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Tt(t),"data-reach":t.type==="architecture"?Ut(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:p.join(";")},k("div",{class:`${s}-head`},k(m,{id:r.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},Ke(a,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Yt(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||i&&t.type==="sequence"?k("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${Kt(t)} to highlight its lines. Tap it again to clear.`):null,k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Pt(s,t)),k("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${te(t,i)} ${n.viewer}`:te(t,i)),k("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Ye(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var qt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,oe=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2,p=e==="top"||e==="bottom";if(t.shape==="decision"){if(p){const w=n,c=m*Math.max(0,1-Math.abs(w-i)/u);return{x:w,y:e==="top"?d-c:d+c}}const l=n,b=u*Math.max(0,1-Math.abs(l-d)/m);return{x:e==="left"?i-b:i+b,y:l}}if(t.shape==="terminal"){const l=Math.min(u,m);if(p){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const b=n,w=b-d,c=Math.abs(w)>=l?0:Math.sqrt(l*l-w*w);return{x:e==="left"?s+l-c:o-l+c,y:b}}return p?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Qe(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/m<1-n/Math.min(u,m);if(e.shape==="terminal"){const p=Math.min(u,m),l=Math.min(Math.max(t.x,s+p),o-p);return Math.hypot(t.x-l,t.y-d)s+n&&t.xr+n&&t.ymatchMedia("(forced-colors: active)").matches;function en(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var Ot=t=>t?t.split(/\s+/).filter(Boolean):[];function nn(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`${t.rtl?"←":"→"} ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),m=d.mark&&!tn()?(d.shape==="participant"?2:1)*s("6"):0;let p=0;const l=d.href?16+s("1-5"):0,b=Ot(d.name);if(b.forEach((c,f)=>{p=Math.max(p,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:m)+(f===b.length-1?l:0))}),t.type!=="data-flow")for(const c of Ot(d.kind))p=Math.max(p,n(c,"mono")+m);for(const c of Ot(d.detail))p=Math.max(p,n(c,d.mono?"mono":"sans"));const w=d.shape==="decision"?p/.62:p+u+2*e.hair;r=Math.max(r,Math.ceil(w))}const a=Tt(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(ee(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Ut(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ae(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function zt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function re(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function It(t,e,n){const s=[];for(let o=0;oMath.min(c.x,f.x)+.75&&CMath.min(v.y,B.y)+.75&&Mr.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",ie={top:"bottom",bottom:"top",left:"right",right:"left"};function sn(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function an(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,m]=e[a],p=i.row===d.row&&tt(u)&&tt(m)&&u===ie[m]||i.col===d.col&&!tt(u)&&!tt(m)&&u===ie[m];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:p,f:.5},{edge:a,end:"to",node:d,side:m,far:i,straight:p,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const m=new Map;for(const c of d)m.has(c.far.id)||m.set(c.far.id,[]),m.get(c.far.id).push(c);for(const c of m.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const p=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),b=u.filter(c=>i(c)<0),w=u.filter(c=>i(c)>=0);b.forEach((c,f)=>{c.f=p*(f+1)/(b.length+1)}),w.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/(w.length+1)})}return s}function le(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?lt(t,e,r+(a-r)*n):lt(t,e,s+(o-s)*n)}function ce(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ft(o,n),shape:a.shape,i:a.i})}),r}function de(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function ue(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function rn(t,e,n,s,r,o,a,i,d){const u=a.space,m=[],p=[],l=[],b=[],w=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*jt(v),M=f.pts.length-2,I=[];pt(f.pts).forEach(([L,z],O)=>{const A=Math.abs(L.y-z.y)<.01,j=A?L.x:L.y;let F=A?z.x:z.y;const V=Math.sign(F-j)||1;O===M&&(F-=V*a.head);let W=[[j,F]];for(const $ of r)for(const S of A?[$.l,$.r]:[$.t,$.b]){const g=A?L.y:L.x;(A?g>$.t&&g<$.b:g>$.l&&g<$.r)&&(W=W.flatMap(([x,E])=>S>Math.min(x,E)+1&&S{const g=($+S)/2,y=A?{x:g,y:L.y}:{x:L.x,y:g};return!r.some(x=>y.x>x.l&&y.xx.t&&y.y1&&Y($,S)?1:0})}),I.sort((L,z)=>z.pri-L.pri||z.len-L.len);let D=null,G=!1;const _=(L,z=!0)=>{const O=oe(L,w);return z&&(L.lo.r||L.to.b)||n.some(A=>se(O,A))||m.some(A=>ut(O,A))||s.heads.some(A=>ut(O,A))||s.rects.some(A=>ut(O,A))?!1:!e.some(A=>A.i!==f.i&&pt(A.pts).some(([j,F])=>ut(O,fe(j,F,A.width))))};for(const L of I){for(const z of[1/2,1/3,2/3]){const O=L.p+(L.q-L.p)*z,A=[],j=u("2")+f.width/2;if(L.horiz?(L.len>=B+2*u("1")+u("3-5")&&A.push({box:{l:O-B/2-u("1"),r:O+B/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),A.push({box:{l:O-B/2,r:O+B/2,t:L.c-j-C,b:L.c-j},on:!1}),A.push({box:{l:O-B/2,r:O+B/2,t:L.c+j,b:L.c+j+C},on:!1})):(L.len>=C+u("3")&&A.push({box:{l:L.c-B/2-u("1"),r:L.c+B/2+u("1"),t:O-C/2,b:O+C/2},on:!0}),A.push({box:{l:L.c+j,r:L.c+j+B,t:O-C/2,b:O+C/2},on:!1}),A.push({box:{l:L.c-j-B,r:L.c-j,t:O-C/2,b:O+C/2},on:!1})),D=A.find(F=>_(F.box))??null,D)break;!G&&A.some(F=>_(F.box,!1))&&(G=!0)}if(D)break}if(!D){l.push(f.i),G&&b.push(f.i);continue}const Z=ue(D.box,d.ox,d.oy,L=>_(L));m.push(Z),p.push({i:f.i,text:v,box:Z,on:D.on})}return{labels:p,unseated:l,bounded:b}}function he(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=ft(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(ft(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=ft(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(ft(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function ln(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,m=ce(s,a,i,o),p=[...m.values()],l=on(a),b=i.left-Math.floor(i.left),w=i.top-Math.floor(i.top),c=ae(b,w),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:b,oy:w};if(s.type==="sequence")return dn(t,M,c);let I,D=[];s.type==="schema"?I=s.edges.map(g=>{const y=s.byId.get(g.from),x=s.byId.get(g.to);if(y.col===x.col){const E=y.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return x.col>y.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const y=s.byId.get(g.from),x=s.byId.get(g.to),[E,q]=sn(y,x);return[g.fromSide??E,g.toSide??q]}),D=an(s,I,d||(()=>{})));const G=(g,y)=>{const x=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${y}"]`);if(!x)return 0;const E=ft(x,i);return(E.t+E.b)/2},_=s.edges.map((g,y)=>{const[x,E]=I[y],q=m.get(g.from),T=m.get(g.to),N=qt(g.kind,r);if(g.fk){const J=G(g.from,g.fromRow),ot=G(g.to,g.toRow),X=c.y(J,N),st=c.y(ot,N);return{p1:{x:x==="right"?q.rect.r:q.rect.l,y:X},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:J,r2:Math.abs(X-st)<.01?J:ot}}const Q=D.find(J=>J.edge===y&&J.end==="from").f,U=D.find(J=>J.edge===y&&J.end==="to").f;let R=le(q,x,Q),K=le(T,E,U);const et=tt(x)?R.y:R.x;let nt=tt(E)?K.y:K.x;return tt(x)?R={...R,y:c.y(R.y,N)}:R={...R,x:c.x(R.x,N)},tt(E)?K={...K,y:c.y(K.y,N)}:K={...K,x:c.x(K.x,N)},tt(x)&&tt(E)&&Math.abs(R.y-K.y)<1.01&&(K={...K,y:R.y},nt=et),!tt(x)&&!tt(E)&&Math.abs(R.x-K.x)<1.01&&(K={...K,x:R.x},nt=et),R=tt(x)?lt(q,x,R.y):lt(q,x,R.x),K=tt(E)?lt(T,E,K.y):lt(T,E,K.x),{p1:R,p2:K,r1:et,r2:nt}}),Z=new Set;s.type==="schema"&&s.edges.forEach((g,y)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&Z.add(y)});const L=new Map,z=new Set;s.edges.forEach((g,y)=>{if(Z.has(y))return;const[x,E]=I[y],{p1:q,p2:T}=_[y],N=s.byId.get(g.from),Q=s.byId.get(g.to);let U=null,R=null,K=!1;if(x===E){if(tt(x)){const J=x==="right"?Math.max(B(N),B(Q)):Math.min(B(N),B(Q))-1,ot=l.cols[J-1],X=l.cols[J];ot&&X&&(U=`c${J}`,R=[ot[1],X[0]],K=!0)}else{const J=x==="bottom"?Math.max(N.row2,Q.row2):Math.min(N.row,Q.row)-1,ot=l.rows[J-1],X=l.rows[J];ot&&X&&(U=`r${J}`,R=[ot[1],X[0]],K=!1)}U&&z.add(y)}else if(tt(x)&&tt(E)&&Math.abs(q.y-T.y)>.5){const J=B(Q),ot=E==="left",X=l.cols[(ot?J-1:J)-1],st=l.cols[(ot?J:J+1)-1];X&&st&&(U=`c${ot?J-1:J}`,R=[X[1],st[0]],K=!0)}else if(!tt(x)&&!tt(E)&&Math.abs(q.x-T.x)>.5){const ot=E==="top"?Q.row-1:Q.row2,X=l.rows[ot-1],st=l.rows[ot];X&&st&&(U=`r${ot}`,R=[X[1],st[0]],K=!1)}if(!U||!R)return;L.has(U)||L.set(U,{span:R,vertical:K,members:new Map});const et=`${g.to}.${E}.${Math.round(K?T.y:T.x)}`,nt=L.get(U);nt.members.has(et)||nt.members.set(et,[]),nt.members.get(et).push(y)});const O=new Map,A=g=>{const[y,x]=I[g],{p1:E,p2:q}=_[g];if(tt(y)&&tt(x)){if(y===x){const N=O.get(g)??(y==="right"?Math.max(E.x,q.x)+u("4"):Math.min(E.x,q.x)-u("4"));return[E,{x:N,y:E.y},{x:N,y:q.y},q]}if(Math.abs(E.y-q.y)<=.5)return[E,{x:q.x,y:E.y}];const T=O.get(g)??(E.x+q.x)/2;return[E,{x:T,y:E.y},{x:T,y:q.y},q]}if(!tt(y)&&!tt(x)){if(y===x){const N=O.get(g)??(y==="bottom"?Math.max(E.y,q.y)+u("4"):Math.min(E.y,q.y)-u("4"));return[E,{x:E.x,y:N},{x:q.x,y:N},q]}if(Math.abs(E.x-q.x)<=.5)return[E,{x:E.x,y:q.y}];const T=O.get(g)??(E.y+q.y)/2;return[E,{x:E.x,y:T},{x:q.x,y:T},q]}return tt(y)?[E,{x:q.x,y:E.y},q]:[E,{x:E.x,y:q.y},q]},j=g=>{const y=s.edges[g],x=qt(y.kind,r),E=A(g),q=re(E,x,c);let T;return E.length===q.length&&(T=pt(E).map(([N,Q])=>Math.abs(N.y-Q.y)<.75?(N.y+Q.y)/2:(N.x+Q.x)/2),T[0]=_[g].r1,T.length>1&&(T[T.length-1]=_[g].r2)),{i:g,from:y.from,to:y.to,kind:y.kind,pts:q,tip:q[q.length-1],dir:zt(q),dot:y.fk?q[0]:void 0,width:x,axes:T}},F=()=>s.edges.flatMap((g,y)=>Z.has(y)?[]:[j(y)]);let V=null;const W=g=>{V??(V=F());const y=V.map(x=>g.has(x.i)?j(x.i):x);return{lines:y,score:cn(y,g)*1e5+It(y,void 0,g).length*1e3+Ft(y.filter(x=>g.has(x.i)),p,s).length}},Y=(g,y)=>{const x=g.flatMap(E=>{const{p1:q,p2:T}=_[E];return y?[q.y,T.y]:[q.x,T.x]});return[Math.min(...x),Math.max(...x)]};for(const[,g]of L){const y=[...g.members.values()].map(E=>({members:E,run:Y(E,g.vertical)})).sort((E,q)=>E.run[0]-q.run[0]),x=[];for(const E of y){const q=x[x.length-1];q&&q.some(T=>T.run[0]z.has(et)))continue;const q=E.map(et=>et.members),T=q.length,N=(g.span[1]-g.span[0])/(T+1);NJ.forEach(X=>O.set(X,g.span[0]+N*(ot+1))));const nt=W(Q);nt.scoreet.forEach(J=>O.set(J,g.span[0]+N*(nt+1)))),V=K}}M.lines=F();for(const g of Z)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=It(M.lines),M.through=Ft(M.lines,p,s),M.outside=me(M.lines,f,v,r);const{obstacles:h,groups:$}=he(a,i,o,C);h.heads=M.lines.map(g=>de(g,r));const S=rn(s,M.lines,p,h,$,{l:0,t:0,r:f,b:v},r,e,{ox:b,oy:w});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(pe(M.lines,null).flat())],M}function cn(t,e){return pe(t,e).length}function pe(t,e){const n=[];for(let s=0;s=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[m.x,p.x]:[m.y,p.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*ge(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Ft(t,e,n){const s=[];for(const r of t){const o=pt(r.pts);e.some(a=>o.some(([i,d])=>Pe(i,d,a)))&&s.push(r.i)}return s}function dn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,ft(M,i)));const m=a.querySelector(`.${o}-steps`),p=m?ft(m,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:p})}const b=M=>u.get(M.id),w=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=ft(M,i);w.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const D=l(M.who),_=(I.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),Z=(M.depth-1)*d("1")*_,L=w.get(M.from)??0,z=w.get(M.to)??L,O=M.from===M.to;return{l:n.x(D-f+Z,r.hair),r:n.x(D+f+Z,r.hair),t:n.y(O?L-d("2")-d("1"):L,r.hair),b:n.y(O?L+d("2")+d("1"):z,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,D)=>B.filter(({bar:G})=>G.who===M&&G.to>=I&&(D?G.from<=I:G.from_.bar.depth-G.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,D=M.dataset.to,G=M.dataset.kind??"plain",_=qt(G,r),Z=ft(M,i),L=n.y((Z.t+Z.b)/2,_),z=Number(M.querySelector(`.${o}-num`)?.textContent??0);let O=l(I),A=l(D),j;if(I===D){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,z,!0),y=g?S>0?g.r:g.l:O,x=n.y(L-d("2"),_),E=n.y(L+d("2"),_);j=[{x:y,y:x},{x:n.x(O+S,_),y:x},{x:n.x(O+S,_),y:E},{x:y,y:E}]}else{const S=A>O?1:-1,g=C(I,z,!1),y=C(D,z,!0);g&&(O=S>0?g.r:g.l),y&&(A=S>0?y.l:y.r),j=[{x:O,y:L},{x:A,y:L}]}e.lines.push({i:z,from:I,to:D,kind:G,pts:j,tip:j[j.length-1],dir:zt(j),width:_});const F=M.querySelector(`.${o}-said`),V=M.querySelector(`.${o}-note`),W=s.byId.get(I),Y=s.byId.get(D);if(!W||!Y)return;const h=I===D?(()=>{const S=s.nodes[W.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-O)-d("6")-d("2-5")-d("2")})():Math.abs(A-O)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,V?V.getBoundingClientRect().width:0)>h+.5&&e.unseated.push(z)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((G,_)=>G+_.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ye(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,m=ce(r,i,d,a),p=[...m.values()],l=d.left-Math.floor(d.left),b=d.top-Math.floor(d.top),w=ae(l,b),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:b},B=ht();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(A,j,F)=>{const V=[A];for(let W=1;W<=(yt(s,j)??0);W++)V.push({...A,t:A.t+F*u("4")*W,b:A.b+F*u("4")*W});return V},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(A=>{const j=A.parentElement,F=ft(j,d),V=getComputedStyle(j);I.set(A.dataset.node,F.r-(parseFloat(V.paddingRight)||0)-(parseFloat(V.borderRightWidth)||0))});const D=r.nodes,G=A=>m.get(D[A].id),_=[],Z=A=>qt(r.edges[A].kind,o);r.edges.forEach((A,j)=>{const F=n.routes[j],V=m.get(A.from),W=m.get(A.to),Y=Z(j);let h=[];const $=A.label,S=$?e($,"label"):0,g=$?16*jt($):16,y=u("4");if(F==="down"||F==="up"){const E=Math.max(V.rect.l,W.rect.l),q=Math.min(V.rect.r,W.rect.r),T=r.edges.map((R,K)=>({o:R,j:K})).filter(({o:R,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(R.from===A.from&&R.to===A.to||R.from===A.to&&R.to===A.from)),N=T.findIndex(R=>R.j===j),Q=T.length<2?.5:T.length===2?N===0?.25:.75:(N+1)/(T.length+1),U=w.x(E+(q-E)*Q,Y);if(h=F==="down"?[lt(V,"bottom",U),lt(W,"top",U)]:[lt(V,"top",U),lt(W,"bottom",U)],$){let R=Math.min(h[0].y,h[1].y),K=Math.max(h[0].y,h[1].y);F==="down"?K-=o.head:R+=o.head;const et=[...i.querySelectorAll(`.${a}-group`)].map(X=>ft(X,d));let nt=[[R,K]];for(const X of et)for(const st of[X.t,X.b])nt=nt.flatMap(([rt,ct])=>st>rt+1&&stet.some(rt=>(X+st)/2>rt.t&&(X+st)/2rt.l&&U1){const X=nt.filter(([rt,ct])=>!J(rt,ct));[R,K]=(X.length?X:nt).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const ot=[1/2,1/3,2/3].map(X=>{const st=R+(K-R)*X;return{l:U-S/2-u("1"),r:U+S/2+u("1"),t:st-g/2,b:st+g/2}});_.push({k:j,cands:ot,on:!0,card:F==="down"?A.to:A.from})}}else if(F==="trunk"||F==="rail"){const E=w.x(Math.max(V.rect.l,F==="rail"?W.rect.l:V.rect.l)+u(F==="trunk"?"8":"3"),Y),q=lt(V,"bottom",E);if(F==="rail"){if(h=[q,lt(W,"top",E)],$){const T=W.rect.t-u("6");_.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},A.to,-1),on:!1,card:A.to})}}else{const T=w.x(W.rect.l+u("6"),Y),N=w.y(W.rect.t-y,Y);h=[q,{x:E,y:N},{x:T,y:N},lt(W,"top",T)],$&&_.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:N-g/2,b:N+g/2},A.to,-1),on:!1,card:A.to})}}else{const E=Math.min(I.get(A.from)??c,I.get(A.to)??c),q=w.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),Y),T=w.y(V.rect.t+(V.rect.b-V.rect.t)*n.exits[j],Y),N=lt(V,"right",T),Q=w.x(W.rect.r-u("6"),Y),U=F==="end-down",R=w.y(U?W.rect.t-y:W.rect.b+y,Y);h=[N,{x:q,y:N.y},{x:q,y:R},{x:Q,y:R},lt(W,U?"top":"bottom",Q)];const K=U?A.to:D[W.i+1]?.id??A.to;$&&_.push({k:j,cands:M({l:Q-u("2-5")-S,r:Q-u("2-5"),t:R-g/2,b:R+g/2},K,U?-1:1),on:!1,card:K})}const x=re(h,Y,w);v.lines.push({i:j,from:A.from,to:A.to,kind:A.kind,pts:x,tip:x[x.length-1],dir:zt(x),width:Y})}),v.crossings=It(v.lines),v.through=Ft(v.lines,p,r),v.outside=me(v.lines,c,f,o);const{obstacles:L}=he(i,d,a,0);L.heads=v.lines.map(A=>de(A,o));const z=[],O={l:0,t:0,r:c,b:f};for(const A of _){const j=W=>{const Y=oe(W,u("1"));return W.lO.r+.5||W.tO.b+.5||p.some(h=>se(Y,h))||z.some(h=>ut(Y,h))||L.heads.some(h=>ut(Y,h))||L.rects.some(h=>ut(Y,h))||v.lines.some(h=>h.i!==A.k&&pt(h.pts).some(([$,S])=>ut(Y,fe($,S,h.width))))},F=A.cands.find(W=>!j(W));F||(B[A.card]=(B[A.card]??0)+1,v.unseated.push(A.k));const V=F?ue(F,l,b,W=>!j(W)):A.cands[0];z.push(V),v.labels.push({i:A.k,text:r.edges[A.k].label,box:V,on:A.on})}return{geo:v,grow:B}}function fn(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o({...M})),p=m[m.length-1];p.x-=o.x*u,p.y-=o.y*u;const l=e.tip.x-o.x*i,b=e.tip.y-o.y*i,w=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=it(e.kind),B=a?``:``,C=e.dot?``:"";return`${B}${C}`}function be(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const m=d.map(p=>{const l=e.lines[p.top],b=e.lines[p.under],w=l.width/2+n.cut,c=b.width/2+1;return p.underVertical?``:``}).join("");a+=`${m}`}return{defs:a,ids:r}}function $e(t,e,n,s){const{defs:r,ids:o}=be(t,e,n,s),a=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),i=e.lines.map((m,p)=>hn(t,m,n,o.get(p)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),d=`${r?`${r}`:""}${a}${i}`,u=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` +`).map(it).join("
")}
`).join("");return d+u}function we(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const m=Ye(t),p=en(u,n),l=nn(e,m,p);i?.(l.least);const b=t.clientWidth,w=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),c=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:w&&L.layout!=="drawn"?w:void 0};let f=!1;const v=L=>{if(f=!1,e.type!=="flowchart")return L;o({...L,heights:void 0,words:void 0});const z=ht(),O=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(A=>{const j=A.querySelector(`.${n}-words`);if(!j)return;const F=A.getBoundingClientRect(),V=h=>{const $={w:h.width+2*m.space("2-5"),h:h.height+2*m.space("2")},S=1-$.w/F.width,g=S>.05?$.h/2/S:$.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},W=j.getBoundingClientRect();let Y=V(W);if(Y>F.width){const h=y=>(A.style.setProperty("--_ww",`${y}px`),j.getBoundingClientRect()),$=Math.floor(A.clientWidth-2*m.space("2-5"));let S=Math.ceil(W.width),g=W.height;for(;S<$&&h($).height1;){const T=y+x>>1;h(T).heightF.width&&(f=!0)}),{...L,heights:z,words:Object.keys(O).length?O:void 0}},B=()=>({m:e,tk:m,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(L,z)=>z.map(O=>Mt(e,L.lines.find(A=>A.i===O))).join(", ");if(b>=l.least){const L=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:ln(B(),p)}};let{dd:z,g:O}=L(!1);const A=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!A(O)&&O.unseated.length&&O.unseated.every(j=>O.bounded?.includes(j))){const j=L(!0);!A(j.g)&&!j.g.unseated.length&&({dd:z,g:O}=j)}if(!A(O)&&!O.unseated.length)return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the drawn layout: ${O.crossings.map(j=>`${Mt(e,O.lines[j.top])} over ${Mt(e,O.lines[j.under])}`).join("; ")}`),{dyn:z,geo:O,ink:$e(n,O,m,s),tokens:m,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: a decision would be taller than it is wide`),O.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${O.misfit.join("; ")}`),O.through.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.through)} would pass through a node`),O.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.overlaps)} would lie on one another`),O.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.outside)} would leave the drawing`),O.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: no clean seat for ${O.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:m,least:l.least};const D=Jt(e);let G=ye(B(),p,D,I.grow);for(let L=0;L<6&&Object.keys(G.grow).length;L++){const z=ht(I.grow);for(const[O,A]of Object.entries(G.grow))z[O]=(yt(z,O)??0)+A;I={...I,grow:z},o(I),G=ye(B(),p,D,z)}const _=G.geo;if(_.unseated.length>0||_.through.length>0||_.outside.length>0||D.third){_.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(_.unseated)].map(O=>`"${e.edges[O]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),_.through.length&&a?.(`in the stacked drawing ${M(_,_.through)} would pass through a node, so its lines are not drawn`),_.outside.length&&a?.(`in the stacked drawing ${M(_,_.outside)} would leave the drawing, so its lines are not drawn`),D.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={..._,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:L,ink:"",tokens:m,least:l.least}}return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${_.crossings.map(L=>`${Mt(e,_.lines[L.top])} over ${Mt(e,_.lines[L.under])}`).join("; ")}`),{dyn:I,geo:_,ink:$e(n,_,m,s),tokens:m,least:l.least}}function Mt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function pn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const m=It(n.lines,i),{defs:p,ids:l}=be(e,{...n,crossings:m},s,r),b=t.querySelector(`.${e}-svg`);if(!b)return;let w=b.querySelector("defs");!w&&p&&(w=document.createElementNS("http://www.w3.org/2000/svg","defs"),b.insertBefore(w,b.firstChild)),w&&(w.innerHTML=p),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var gn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function mn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",gn()||bn(t)?"done":"pending")}}var yn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function bn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(yn(t))!==null}catch{return!1}}function ve(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function $n(t,e,n,s=!1,r=!1){const o=s?Lt(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var wn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],xe=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],vn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ke=t=>t==null||t===!1;function xn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Me(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?xe:wn;for(const a of s)ke(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,m=new Map(String(i??"").split(";").map(p=>{const l=p.indexOf(":");return[p.slice(0,l).trim(),p.slice(l+1).trim()]}).filter(([p])=>p));for(const[p,l]of m)u.getPropertyValue(p).trim()!==l&&u.setProperty(p,l);for(const p of vn)m.has(p)||u.removeProperty(p);continue}if(n&&!xe.includes(a))continue;if(ke(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;it.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,b,w){return{prefix:n,base:l,hasSource:b.source!==void 0&&b.source!==null&&b.source!=="",hiddenClass:"visually-hidden",viewer:w?w.keys:void 0}}function o(l,b,w,c){var f=function(v){return''+it(v)+""};return{source:it(String(b.source||"")),summary:it(String(b.summary||"")),hint:Wt(l).map(function(v){return""+v.keys.map(f).join(" ")+" "+it(v.words)+""}).join(""),toggle:'"}}function a(l,b,w){var c=_t(l),f=ne(c,{},r(b,l,w)),v=Bt(f,o(c,l,b,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,b,w,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=_t(b,{rtl:getComputedStyle(l).direction==="rtl"});if(!w||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(b,f,c),C=document.createElement("div");C.innerHTML=B.open+"";var M=C.firstChild;i.forEach(function(H){l.removeAttribute(H)}),d.forEach(function(H){l.style.removeProperty(H)});for(var I=0;I :not(script[data-diagram])").forEach(function(H){H.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var G=r(f,b,c),_={},Z=null,L=null,z=null,O=null,A=Object.create(null),j=function(H){A[H]||(A[H]=1,console.warn("Basalt diagram: "+H))},F=function(H){Me(l,ne(v,H,G))},V=l.querySelector(".diagram-ink"),W=l.querySelector(".diagram-toggle"),Y=!c&&v.motion.animated&&typeof e.diagramMotion=="function",h=null,$=null,S=function(){Y&&ve(l)};function g(){pn(l,n,Z&&Z.geo,Z&&Z.tokens,f,L||O||z),E()}var y=null,x=!c&&matchMedia("(hover: none), (pointer: coarse)").matches;function E(){var H=x&&!c&&V&&V.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(x&&!c)),H&&!y){var P=l.querySelector(":scope > .diagram-foot");if(!P)return;y=document.createElement("button"),y.type="button",y.className="btn diagram-clear",y.setAttribute("data-variant","secondary"),y.setAttribute("data-size","sm"),y.innerHTML="Clear highlight",y.addEventListener("click",function(){O&&(O=null,g())}),P.appendChild(y)}else!H&&y&&(y.remove(),y=null);y&&(O?y.removeAttribute("aria-disabled"):y.setAttribute("aria-disabled","true"))}function q(H){if(!H.defaultPrevented){var P=je(l,n,H,O);P!==void 0&&(S(),x=!0,O=P,g())}}function T(){W&&(W.setAttribute("aria-expanded",String(!!_.open)),W.firstElementChild.textContent=_.open?"Hide the list":"View as list")}function N(){Z=(c?c.measure:we)(l,v,n,f,_,F,j),_=Z.dyn,F(_),T();var H=l.querySelector(":scope > .diagram-hint");if(H){var P=Wt(v,_.layout==="drawn").map(function(St){return""+St.keys.map(function(Sn){return''+it(Sn)+""}).join(" ")+" "+it(St.words)+""}).join("");H.innerHTML!==P&&(H.innerHTML=P)}mt(v,_)||(z=O=null);var dt=V&&Z.ink!==$;dt&&(V.innerHTML=Z.ink,$=Z.ink),g(),Y&&Z.tokens&&(mn(l,!!(Z.geo&&Z.geo.lines.length)),dt&&h&&h.redrawn()),c&&c.onMeasured&&Z.tokens&&c.onMeasured(Z,l)}function Q(H){_=H,F(_)}function U(H){var P=_.stop;_=Object.assign({},_,{stop:H}),kn(l,n,P,H)}var R=function(H){var P=H&&H.closest?H.closest(".diagram-node"):null;return P&&l.contains(P)?P:null};function K(H){var P=R(H.target);if(!(!P||H.defaultPrevented)){if(S(),H.key==="Escape"){!c&&(L||z||O)&&(H.preventDefault(),L=z=O=null,g());return}if(mt(v,_)){var dt=$n(v,P.getAttribute("data-node"),H.key,_.layout==="drawn");if(dt){H.preventDefault(),U(dt);var St=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');St&&St.focus()}}}}function et(H){var P=R(H.target);if(P){S();var dt=P.getAttribute("data-node");L=P.matches(":focus-visible")?dt:null,mt(v,_)&&_.stop!==dt&&U(dt),g()}}function nt(H){var P=R(H.target);P&&(R(H.relatedTarget)||(L=null),_.keep===P.getAttribute("data-node")&&Q(Object.assign({},_,{keep:void 0})),g())}function J(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var P=R(H.target);P&&S();var dt=P&&mt(v,_)?P.getAttribute("data-node"):null;dt!==z&&(z=dt,g())}}function ot(){z&&(z=null,g())}function X(){S(),Q(Object.assign({},_,{open:!_.open,autoOpen:void 0})),T()}l.addEventListener("keydown",K),l.addEventListener("focusin",et),l.addEventListener("focusout",nt),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",ot),l.addEventListener("click",q),W&&W.addEventListener("click",X),N();var st=l.clientWidth,rt=0,ct=!0,bt=new ResizeObserver(function(){Math.abs(l.clientWidth-st)<.5||(st=l.clientWidth,cancelAnimationFrame(rt),rt=requestAnimationFrame(N))});bt.observe(l),document.fonts&&document.fonts.ready.then(function(){ct&&N()});var xt=matchMedia("(forced-colors: active)"),Se=v.nodes.some(function(H){return H.mark});Se&&xt.addEventListener("change",N),Y&&(h=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return Z&&Z.geo},tokens:function(){return Z&&Z.tokens}},b));var Ee=!c&&b.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,b,{model:v,settle:S,animated:Y}):null,Ae=l.querySelector(":scope > .diagram-foot"),Mn=!c&&b.export===!0&&Ae&&typeof e.diagramExport=="function"?e.diagramExport(Ae,l):[];l.__diagram={stop:function(){Ee&&Ee.destroy(),Mn.forEach(function(H){H.remove()}),ct=!1,bt.disconnect(),cancelAnimationFrame(rt),Se&&xt.removeEventListener("change",N),h&&h.destroy(),l.removeEventListener("keydown",K),l.removeEventListener("focusin",et),l.removeEventListener("focusout",nt),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",ot),l.removeEventListener("click",q),y&&y.remove(),W&&W.removeEventListener("click",X)},layout:N,key:m(b),send:h&&h.sendValue?h.sendValue:null}}function m(l){try{return JSON.stringify(l,function(b,w){return b==="packet"&&w&&typeof w=="object"?Object.assign({},w,{send:void 0}):w})}catch{return null}}function p(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var b=l.querySelector(":scope > script[data-diagram]");if(b)try{u(l,JSON.parse(b.textContent),!0)}catch(w){console.error("Basalt diagram: this figure could not be drawn",w)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:_t,figureKey:Fe,figureList:Ze,hintEntries:Wt,toHtml:Bt,escapeHtml:it,settleEntrance:ve,measureFigure:we},t.diagram=function(l,b){var w=l.__diagram,c=w&&w.send?m(b):null;if(c!==null&&c===w.key){w.send(b.packet?b.packet.send:void 0);return}u(l,b)},e.step(62,"wireDiagrams",p)})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index dccaf2f5..d1f26ee9 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -843,6 +843,22 @@ "sheet" ] }, + "diagram-export": { + "classes": [ + "diagram-download" + ], + "text": [ + "\"export\"\\s*:\\s*true" + ], + "textWords": [ + "a diagram's \"export\": true" + ], + "requires": [ + "diagram" + ], + "budget": 12000, + "usage": 700 + }, "sparkline": { "classes": [ "sparkline", diff --git a/.agent/skills/basalt-html/parts/usage/diagram-export.md b/.agent/skills/basalt-html/parts/usage/diagram-export.md new file mode 100644 index 00000000..511d845a --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-export.md @@ -0,0 +1,6 @@ +# diagram-export + +Added for you when a diagram's JSON says `"export": true`. + +- The figure's foot gets "Download SVG" and "Download PNG", and so does its viewer's (the drawn layout at 100%, whatever the zoom). Each writes the figure in the theme shown: the title and source, the drawing and the key, at rest; native SVG with its words as text and the faces embedded; the PNG at 2x. +- Without `"export": true` there are no buttons and no module. Don't add your own. diff --git a/packages/react/package.json b/packages/react/package.json index 471bf516..964d5f2a 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -25,6 +25,14 @@ "types": "./dist/tooling/imports.d.ts", "default": "./dist/tooling/imports.js" }, + "./diagram-export": { + "types": "./dist/diagram-export.d.ts", + "default": "./dist/diagram-export.js" + }, + "./diagram-layout": { + "types": "./dist/diagram-layout.d.ts", + "default": "./dist/diagram-layout.js" + }, "./marks/*": { "types": "./dist/marks/*.d.ts", "default": "./dist/marks/*.js" diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 9c5c3269..f354e2b5 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -989,7 +989,8 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { } } if (m.type === "sequence") { - out.push(h("ul", { class: `${P}-cast` }, m.nodes.map((n) => h("li", { class: `${P}-actor` }, nodeTree(ctx, m, n, dyn))))); + // Drawn, each head is in its column (mirrored right to left, 1.7). + out.push(h("ul", { class: `${P}-cast` }, m.nodes.map((n) => h("li", { class: `${P}-actor`, style: m.rtl ? `--_ac:${n.col}` : undefined }, nodeTree(ctx, m, n, dyn))))); out.push(sequenceSteps(ctx, m)); return out; } diff --git a/packages/react/src/diagram-export.ts b/packages/react/src/diagram-export.ts new file mode 100644 index 00000000..ff0f41bf --- /dev/null +++ b/packages/react/src/diagram-export.ts @@ -0,0 +1,192 @@ +// A diagram to a file (DECISIONS 306, 1.7): `@srasyndicate/basalt/diagram-export`, a module of its own that an app loads on demand and wires to its own +// button. Never imported by the index or by a figure. The file holds the title and source, the drawing as it is laid out now (drawn or stacked) and the +// key, on surface-page with space-4 round it, at rest: every line whole, no mover, no trace. Native SVG only, never foreignObject: boxes are rects, lines +// and marks are the drawing's own SVG and images, and words are SVG text set from the live figure's measured line boxes. Nothing here runs at load. +// The implementation hasn't been reviewed. + +/** The theme of the file: the page's (the default), or light or dark. */ +export interface DiagramExportOptions { + theme?: "page" | "light" | "dark"; + /** SVG only: "embed" (the default) writes the faces into the file, so it measures the same anywhere; "name" writes the font stack, for design tools. */ + fonts?: "embed" | "name"; + /** PNG only: device pixels per CSS pixel (default 2). */ + scale?: number; +} + +const NS = "http://www.w3.org/2000/svg"; +const esc = (s: string) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]!); +const visible = (c: string) => Boolean(c) && c !== "transparent" && !/rgba\([^)]*,\s*0\)$/.test(c) && !/\/\s*0\)$/.test(c); +const r2 = (n: number) => Math.round(n * 100) / 100; + +/** The parts of a figure a file holds: its head, its drawing and its key (no control, hint or list). */ +function partsOf(fig: HTMLElement): HTMLElement[] { + const pick = (cls: string) => fig.querySelector(`:scope > [class$="-${cls}"], :scope > [class*="-${cls} "]`); + return ["head", "drawing", "key"].map(pick).filter((el): el is HTMLElement => Boolean(el && el.getClientRects().length)); +} + +/** A face's file as a data URI, from the page's own @font-face rules; null where it cannot be read. */ +async function faceData(family: string): Promise { + for (const sheet of Array.from(document.styleSheets)) { + let rules: CSSRuleList; + try { rules = sheet.cssRules; } catch { continue; } + for (const rule of Array.from(rules)) { + if (!(rule instanceof CSSFontFaceRule)) continue; + if (rule.style.getPropertyValue("font-family").replace(/["']/g, "").trim() !== family) continue; + const url = /url\(["']?([^"')]+)["']?\)/.exec(rule.style.getPropertyValue("src"))?.[1]; + if (!url) continue; + if (url.startsWith("data:")) return url; + try { + const blob = await (await fetch(new URL(url, sheet.href ?? location.href))).blob(); + return await new Promise((resolve, reject) => { const r = new FileReader(); r.onload = () => resolve(String(r.result)); r.onerror = reject; r.readAsDataURL(blob); }); + } catch { return null; } + } + } + return null; +} + +/** Text as SVG text, one element per word, each at its own measured box, so the file is the figure's words where the figure set them. */ +function textOf(root: Element, origin: DOMRect, out: string[]) { + const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT); + for (let node = walker.nextNode(); node; node = walker.nextNode()) { + const el = node.parentElement; + if (!el || !node.textContent?.trim()) continue; + if (el.closest("[aria-hidden='true'] .basalt-visually-hidden, .basalt-visually-hidden, .visually-hidden, [class$='-ruler'], [hidden]")) continue; + const cs = getComputedStyle(el); + if (cs.visibility === "hidden" || cs.display === "none") continue; + const text = node.textContent; + const range = document.createRange(); + for (const m of text.matchAll(/\S+/g)) { + range.setStart(node, m.index!); + range.setEnd(node, m.index! + m[0].length); + const r = range.getBoundingClientRect(); + if (!r.width) continue; + const size = Number.parseFloat(cs.fontSize); + // The baseline: the line box's top plus the face's ascent, about four fifths of the size for Geist and Geist Mono. + const y = r.top - origin.top + (r.height - size) / 2 + size * 0.8; + out.push(`${esc(m[0])}`); + } + } +} + +/** Every box with a fill or an edge as a rect, the drawing's SVG as it is, and the marks as images. */ +function boxesOf(root: Element, origin: DOMRect, out: string[]) { + const all = [root, ...Array.from(root.querySelectorAll("*"))]; + for (const el of all) { + if (el instanceof SVGElement) { + if (el.tagName.toLowerCase() !== "svg" || el.closest("svg") !== el) continue; + const r = el.getBoundingClientRect(); + if (!r.width || !r.height) continue; + const clone = el.cloneNode(true) as SVGSVGElement; + // Every painted part takes its computed paint, so the file needs no stylesheet. + const src = [el, ...Array.from(el.querySelectorAll("*"))]; + const dst = [clone, ...Array.from(clone.querySelectorAll("*"))]; + src.forEach((s, k) => { + const cs = getComputedStyle(s); + const d = dst[k] as Element; + for (const p of ["fill", "stroke", "stroke-width", "stroke-dasharray", "stroke-linecap", "stroke-linejoin", "opacity"]) d.setAttribute(p, cs.getPropertyValue(p)); + d.removeAttribute("class"); + if (cs.display === "none") d.setAttribute("display", "none"); + }); + clone.setAttribute("x", String(r2(r.left - origin.left))); + clone.setAttribute("y", String(r2(r.top - origin.top))); + clone.removeAttribute("style"); + out.push(clone.outerHTML); + continue; + } + const cs = getComputedStyle(el); + if (cs.display === "none" || cs.visibility === "hidden") continue; + const r = el.getBoundingClientRect(); + if (!r.width || !r.height) continue; + const x = r2(r.left - origin.left), y = r2(r.top - origin.top), w = r2(r.width), h = r2(r.height); + const radius = Number.parseFloat(cs.borderTopLeftRadius) || 0; + const fill = visible(cs.backgroundColor) ? cs.backgroundColor : "none"; + const bw = Number.parseFloat(cs.borderTopWidth) || 0; + const stroke = bw && cs.borderTopStyle !== "none" && visible(cs.borderTopColor) ? cs.borderTopColor : "none"; + if (fill !== "none" || stroke !== "none") { + const dash = cs.borderTopStyle === "dashed" ? ` stroke-dasharray="4 2"` : ""; + out.push(``); + } + // A mark is its owner's file in the export theme's form. + const image = /url\(["']?([^"')]+)["']?\)/.exec(cs.backgroundImage)?.[1]; + if (image && /-mark$/.test(String(el.getAttribute("class")))) out.push(``); + } +} + +/** The figure's title and summary, for the SVG's own title and desc. */ +const titleOf = (fig: HTMLElement) => fig.querySelector("[class$='-title']")?.textContent?.trim() ?? ""; +const summaryOf = (fig: HTMLElement) => fig.querySelector("figcaption")?.textContent?.trim() ?? ""; +/** The file's name: the title's slug. */ +export const exportName = (fig: HTMLElement, ext: string) => `${(titleOf(fig).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "diagram")}.${ext}`; + +async function svgText(fig: HTMLElement, options: DiagramExportOptions, embed: boolean): Promise<{ svg: string; w: number; h: number }> { + const theme = options.theme ?? "page"; + const had = fig.getAttribute("data-theme"); + // A file is at rest: no trace, no pending entrance, no mover. The figure is shown so for the read and put back after. + const traced = Array.from(fig.querySelectorAll("[data-lit], [data-dim], [data-near]")); + const marks = traced.map((el) => [el, el.getAttribute("data-lit"), el.getAttribute("data-dim"), el.getAttribute("data-near")] as const); + traced.forEach((el) => { el.removeAttribute("data-lit"); el.removeAttribute("data-dim"); el.removeAttribute("data-near"); }); + const hidden = Array.from(fig.querySelectorAll("[class*='-flow'], [class*='-bead'], [class*='-packet']")); + hidden.forEach((el) => { el.dataset.exportHidden = el.style.display; el.style.display = "none"; }); + const entrance = fig.getAttribute("data-entrance"); + if (entrance && entrance !== "done") fig.setAttribute("data-entrance", "done"); + if (theme !== "page") fig.setAttribute("data-theme", theme); + const transitions = fig.style.getPropertyValue("--basalt-export"); + fig.classList.add("basalt-exporting"); + try { + void fig.offsetWidth; + const pad = Number.parseFloat(getComputedStyle(fig).getPropertyValue("--basalt-space-4")) || 16; + const parts = partsOf(fig); + const rects = parts.map((p) => p.getBoundingClientRect()); + const left = Math.min(...rects.map((r) => r.left)), top = Math.min(...rects.map((r) => r.top)); + const right = Math.max(...rects.map((r) => r.right)), bottom = Math.max(...rects.map((r) => r.bottom)); + const origin = new DOMRect(left - pad, top - pad, 0, 0); + const w = Math.ceil(right - left + 2 * pad), h = Math.ceil(bottom - top + 2 * pad); + const ground = getComputedStyle(fig).getPropertyValue("--basalt-surface-page").trim() || getComputedStyle(document.body).backgroundColor; + const body: string[] = []; + for (const p of parts) boxesOf(p, origin, body); + for (const p of parts) textOf(p, origin, body); + let style = ""; + if (embed) { + const faces: string[] = []; + for (const family of ["Geist", "Geist Mono"]) { + const data = await faceData(family); + if (data) faces.push(`@font-face{font-family:"${family}";src:url(${data});font-weight:100 900}`); + else if (process.env.NODE_ENV !== "production") console.warn(`Basalt diagramToSvg: the face "${family}" could not be read, so the file names it`); + } + if (faces.length) style = ``; + } + const svg = `${esc(titleOf(fig))}${esc(summaryOf(fig))}${style}${body.join("")}`; + return { svg, w, h }; + } finally { + fig.classList.remove("basalt-exporting"); + if (transitions) fig.style.setProperty("--basalt-export", transitions); + if (theme !== "page") { if (had === null) fig.removeAttribute("data-theme"); else fig.setAttribute("data-theme", had); } + if (entrance && entrance !== "done") fig.setAttribute("data-entrance", entrance); + hidden.forEach((el) => { el.style.display = el.dataset.exportHidden ?? ""; delete el.dataset.exportHidden; }); + for (const [el, lit, dim, near] of marks) { if (lit !== null) el.setAttribute("data-lit", lit); if (dim !== null) el.setAttribute("data-dim", dim); if (near !== null) el.setAttribute("data-near", near); } + } +} + +declare const process: { env: { NODE_ENV?: string } }; + +/** The figure as an SVG file: native SVG, its words as text, the faces embedded by default. */ +export async function diagramToSvg(figure: HTMLElement, options: DiagramExportOptions = {}): Promise { + const { svg } = await svgText(figure, options, (options.fonts ?? "embed") === "embed"); + return new Blob([svg], { type: "image/svg+xml" }); +} + +/** The figure as a PNG file, at `scale` (2 by default), always drawn with the faces embedded. */ +export async function diagramToPng(figure: HTMLElement, options: DiagramExportOptions = {}): Promise { + const { svg, w, h } = await svgText(figure, options, true); + const scale = options.scale ?? 2; + const img = new Image(); + img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`; + await img.decode(); + const canvas = document.createElement("canvas"); + canvas.width = Math.round(w * scale); + canvas.height = Math.round(h * scale); + const ctx = canvas.getContext("2d")!; + ctx.scale(scale, scale); + ctx.drawImage(img, 0, 0, w, h); + return new Promise((resolve, reject) => canvas.toBlob((b) => (b ? resolve(b) : reject(new Error("the PNG could not be made"))), "image/png")); +} diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index f499217f..cd6150d0 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4711,7 +4711,7 @@ padding: 0; list-style: none; } - .basalt-diagram-actor { display: flex; min-width: 0; } + .basalt-diagram-actor { --_d-ac: var(--_drawn) var(--_ac, auto); display: flex; min-width: 0; grid-column: var(--_d-ac, auto); grid-row: 1; } .basalt-diagram-node[data-shape="participant"] { --_d-pd: var(--_drawn) var(--basalt-space-2-5) var(--basalt-space-3); --_d-pr: var(--_drawn) var(--basalt-radius-md); @@ -4995,6 +4995,9 @@ .basalt-diagram .basalt-diagram-label { color: var(--basalt-diagram-edge) !important; } } + /* While a figure is read for a file (diagram-export), nothing in it transitions, so a theme it is read in applies at once. */ + .basalt-exporting, .basalt-exporting * { transition: none !important; } + /* ---- Diagram motion (DECISIONS 292): the entrance, flow, the pulse, the packet, the arrival step and the foot's two buttons ---- Only on a figure that asks for it (data-motion="animated"); a still figure is the drawing above, unchanged. The motion code is a module of its own (diagram-motion), loaded on demand; the still engine marks a figure pending in the frame its lines are first drawn (data-entrance). Every diff --git a/packages/react/test/diagram-output.test.mjs b/packages/react/test/diagram-output.test.mjs new file mode 100644 index 00000000..07a7819b --- /dev/null +++ b/packages/react/test/diagram-output.test.mjs @@ -0,0 +1,91 @@ +// Print, right to left and export (DECISIONS 306, 1.7; section 8's list for diagram-output.test.mjs), on the extended CIMIP figures. In Chromium against +// the built package. The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import { after, before, describe, test } from "node:test"; + +import { fixturePage, launch } from "./support.mjs"; + +const P = "basalt-diagram"; +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +const HOST = ` +import data from "./test/fixtures/cimip-diagrams-b.json"; +import { diagramToSvg, diagramToPng } from "./dist/diagram-export.js"; +window.__svg = (id, o) => diagramToSvg(document.getElementById(id), o).then((b) => b.text()); +window.__png = (id, o) => diagramToPng(document.getElementById(id), o).then((b) => createImageBitmap(b)).then((i) => [i.width, i.height]); +const C = { architecture: B.ArchitectureDiagram, flowchart: B.FlowchartDiagram, "data-flow": B.DataFlowDiagram, sequence: B.SequenceDiagram, schema: B.SchemaDiagram }; +createRoot(document.getElementById("root")).render(
{Object.entries(data).map(([key, d]) => { const { type, ...props } = d; const X = C[type]; return ; })}
);`; +const frames = (page, n = 3) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); +async function outPage({ theme = "dark", width = 1440, dir } = {}) { + const { page, errors } = await fixturePage(browser, HOST, { theme, standards: true, viewport: { width, height: 1200 } }); + if (dir) await page.evaluate((d) => { document.documentElement.dir = d; }, dir); + await page.addStyleTag({ content: "body{margin:0;padding:16px;background:var(--basalt-surface-page)} #root{max-width:1104px;margin:0 auto}" }); + await page.evaluate(() => document.fonts.ready); + await frames(page, 6); + return { page, errors }; +} + +describe("print", () => { + test("from the dark theme with no beforeprint: the page's tokens compute to light, and a traced figure's lines to their resting ink; no hint or control prints", async () => { + const { page } = await outPage({ theme: "dark" }); + await page.locator(`#fig-architecture .${P}-node[data-node="alb"]`).hover(); + await frames(page, 4); + const lightPrimary = await page.evaluate(() => { document.documentElement.dataset.theme = "light"; const v = getComputedStyle(document.documentElement).getPropertyValue("--basalt-text-primary"); document.documentElement.dataset.theme = "dark"; return v.trim(); }); + await page.emulateMedia({ media: "print" }); + const got = await page.evaluate((P) => { + const fig = document.querySelector("#fig-architecture"); + const lit = fig.querySelector(`.${P}-edge[data-lit] .${P}-line, .${P}-edge[data-dim] .${P}-line`); + const rest = fig.querySelector(`.${P}-edge:not([data-lit]):not([data-dim]) .${P}-line[data-kind="plain"]`) ?? fig.querySelector(`.${P}-line[data-kind="plain"]`); + return { primary: getComputedStyle(document.documentElement).getPropertyValue("--basalt-text-primary").trim(), scheme: getComputedStyle(document.documentElement).colorScheme, + hint: getComputedStyle(fig.querySelector(`.${P}-hint`)).display, expand: getComputedStyle(fig.querySelector(`.${P}-expand`)).display, + traced: lit ? [getComputedStyle(lit).stroke, lit.getAttribute("data-kind")] : null, plain: rest ? getComputedStyle(rest).stroke : null }; + }, P); + assert.equal(got.primary, lightPrimary); + assert.equal(got.scheme, "light"); + assert.equal(got.hint, "none"); + assert.equal(got.expand, "none"); + if (got.traced && got.traced[1] === "plain") assert.equal(got.traced[0], got.plain, "a traced line prints in its resting ink"); + await page.close(); + }); +}); + +describe("right to left", () => { + test("every CIMIP figure is drawn mirrored under dir=rtl, the first participant at the right; a Mono detail keeps the card's start edge", async () => { + const { page, errors } = await outPage({ dir: "rtl" }); + for (const key of ["architecture", "flowchart", "dataFlow", "sequence", "schema"]) assert.equal(await page.locator(`#fig-${key}`).getAttribute("data-layout"), "drawn", key); + const heads = await page.locator(`#fig-sequence .${P}-node`).evaluateAll((els) => els.map((e) => e.getBoundingClientRect().left)); + assert.ok(heads[0] > heads[heads.length - 1], "the first participant is at the right"); + const browserX = await page.locator(`#fig-architecture .${P}-node[data-node="browser"]`).evaluate((e) => e.getBoundingClientRect().left); + const albX = await page.locator(`#fig-architecture .${P}-node[data-node="alb"]`).evaluate((e) => e.getBoundingClientRect().left); + assert.ok(browserX > albX, "column 1 is at the right"); + const edge = await page.locator(`#fig-architecture .${P}-node[data-node="alb"]`).evaluate((card, P) => { const d = card.querySelector(`.${P}-detail`); return Math.abs(card.getBoundingClientRect().right - d.getBoundingClientRect().right); }, P); + assert.ok(edge < 16, `the detail keeps the card's start (right) edge: ${edge}`); + assert.deepEqual(errors, []); + await page.close(); + }); +}); + +describe("export", () => { + for (const theme of ["dark", "light"]) test(`${theme}: no foreignObject; a title and a desc; every node and label; no text under 12px; a traced figure exports at rest; the PNG is twice the SVG`, async () => { + const { page } = await outPage({ theme }); + await page.locator(`#fig-architecture .${P}-node[data-node="svc"]`).hover(); + await frames(page, 3); + const svg = await page.evaluate(() => window.__svg("fig-architecture")); + assert.ok(!svg.includes("foreignObject")); + assert.match(svg, /How a request reaches the agent<\/title>/); + assert.match(svg, /<desc>[^<]{20,}<\/desc>/); + for (const word of ["Browser", "ALB", "Aurora", "CloudWatch", "HTTPS", "RunTask", "Request", "Data"]) assert.ok(svg.includes(`>${word}<`), `the file has "${word}"`); + const sizes = [...svg.matchAll(/font-size="([\d.]+)"/g)].map((m) => Number(m[1])); + assert.ok(sizes.length > 50 && Math.min(...sizes) >= 12, `the smallest text is ${Math.min(...sizes)}px`); + assert.ok(!/data-lit|data-dim/.test(svg)); + const [w, h] = [Number(/ width="(\d+)"/.exec(svg)[1]), Number(/ height="(\d+)"/.exec(svg)[1])]; + const [pw, ph] = await page.evaluate(() => window.__png("fig-architecture")); + assert.deepEqual([pw, ph], [w * 2, h * 2]); + const other = theme === "dark" ? "light" : "dark"; + const svgOther = await page.evaluate((t) => window.__svg("fig-architecture", { theme: t }), other); + assert.notEqual(/<rect width="\d+" height="\d+" fill="([^"]+)"/.exec(svgOther)[1], /<rect width="\d+" height="\d+" fill="([^"]+)"/.exec(svg)[1], "the other theme's ground"); + await page.close(); + }); +}); diff --git a/tools/html-skill/build.mjs b/tools/html-skill/build.mjs index e5b95a02..ce08e1a9 100644 --- a/tools/html-skill/build.mjs +++ b/tools/html-skill/build.mjs @@ -315,7 +315,7 @@ export function build() { for (const ext of ["css", "js"]) { const file = path.join(srcDir, "modules", `${name}.${ext}`); if (!fs.existsSync(file)) continue; - if (ext === "js" && (name === "diagram" || name === "diagram-motion" || name === "diagram-zoom")) files[`parts/${name}.js`] = minifyJs(bundleModule(file)); + if (ext === "js" && (name === "diagram" || name === "diagram-motion" || name === "diagram-zoom" || name === "diagram-export")) files[`parts/${name}.js`] = minifyJs(bundleModule(file)); else files[`parts/${name}.${ext}`] = ext === "css" ? minifyCss(tokens + fs.readFileSync(file, "utf8")) : minifyJs(fs.readFileSync(file, "utf8")); } } diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index dccaf2f5..d1f26ee9 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -843,6 +843,22 @@ "sheet" ] }, + "diagram-export": { + "classes": [ + "diagram-download" + ], + "text": [ + "\"export\"\\s*:\\s*true" + ], + "textWords": [ + "a diagram's \"export\": true" + ], + "requires": [ + "diagram" + ], + "budget": 12000, + "usage": 700 + }, "sparkline": { "classes": [ "sparkline", diff --git a/tools/html-skill/src/modules/diagram-export.js b/tools/html-skill/src/modules/diagram-export.js new file mode 100644 index 00000000..8df8f413 --- /dev/null +++ b/tools/html-skill/src/modules/diagram-export.js @@ -0,0 +1,41 @@ +/* Basalt HTML script, diagram-export module (DECISIONS 306, 1.7): a figure whose JSON says "export": true gets "Download SVG" and "Download PNG" in its + foot (secondary small buttons, before "Clear highlight"), and in its viewer's foot, where they write the viewer's drawing at 100%. They write the figure in + the theme shown: native SVG, never foreignObject, its words as text, the faces embedded. The code is React's (packages/react/src/diagram-export.ts), + bundled into this module by build.mjs. compose.mjs adds it only to a page with such a figure. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-export.js (do not edit the copy in the skill folder). */ +import { diagramToPng, diagramToSvg, exportName } from "../../../../packages/react/src/diagram-export.ts"; + +(function (B) { + 'use strict'; + var _ = B._; + + function save(blob, name) { + var a = document.createElement('a'); + a.href = URL.createObjectURL(blob); + a.download = name; + document.body.appendChild(a); + a.click(); + a.remove(); + setTimeout(function () { URL.revokeObjectURL(a.href); }, 1000); + } + function button(words, run) { + var b = document.createElement('button'); + b.type = 'button'; + b.className = 'btn diagram-download'; + b.setAttribute('data-variant', 'secondary'); + b.setAttribute('data-size', 'sm'); + b.innerHTML = '<span>' + words + '</span>'; + b.addEventListener('click', run); + return b; + } + + /** Puts the two buttons in a foot, before "Clear highlight", for the figure `fig`. Returns them, so a redraw can take them out. */ + _.diagramExport = function (foot, fig) { + var svg = button('Download SVG', function () { diagramToSvg(fig).then(function (b) { save(b, exportName(fig, 'svg')); }); }); + var png = button('Download PNG', function () { diagramToPng(fig).then(function (b) { save(b, exportName(fig, 'png')); }); }); + var clear = foot.querySelector('.diagram-clear'); + foot.insertBefore(svg, clear); + foot.insertBefore(png, clear); + return [svg, png]; + }; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram-zoom.js b/tools/html-skill/src/modules/diagram-zoom.js index 7b7fc753..9746261f 100644 --- a/tools/html-skill/src/modules/diagram-zoom.js +++ b/tools/html-skill/src/modules/diagram-zoom.js @@ -106,6 +106,8 @@ import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } fr if (node && stage.contains(node)) revealIn(stage, node, px(stage, '--_clear') || 16); }); + // The viewer's foot has the downloads too, writing the viewer's drawing (DECISIONS 310, 9.11). + if (spec.export === true && typeof _.diagramExport === 'function') _.diagramExport(d.querySelector('.diagram-viewer-end'), fig); B.openDialog(d, opener); readStage(); kit.draw(fig, still, false, view); diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index e0b1aea3..94d5236a 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -213,9 +213,13 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, if (animated) motion = _.diagramMotion(figure, { fig: figure, P: P, base: base, model: function () { return model; }, geo: function () { return measured && measured.geo; }, tokens: function () { return measured && measured.tokens; } }, spec); // "Expand" and the viewer (DECISIONS 310) are the diagram-zoom module's: compose.mjs adds it to a page unless every figure on it says "zoom": false. var zoom = !viewer && spec.zoom !== false && typeof _.diagramZoom === 'function' ? _.diagramZoom(figure, spec, { model: model, settle: settle, animated: animated }) : null; + // "Download SVG" and "Download PNG" (DECISIONS 306, 1.7) are the diagram-export module's, for a figure that says "export": true. + var exportFoot = figure.querySelector(':scope > .diagram-foot'); + var exports = !viewer && spec.export === true && exportFoot && typeof _.diagramExport === 'function' ? _.diagramExport(exportFoot, figure) : []; figure.__diagram = { stop: function () { if (zoom) zoom.destroy(); + exports.forEach(function (b) { b.remove(); }); live = false; observer.disconnect(); cancelAnimationFrame(frame); if (marks) forced.removeEventListener('change', layout); if (motion) motion.destroy(); diff --git a/tools/html-skill/src/usage/diagram-export.md b/tools/html-skill/src/usage/diagram-export.md new file mode 100644 index 00000000..511d845a --- /dev/null +++ b/tools/html-skill/src/usage/diagram-export.md @@ -0,0 +1,6 @@ +# diagram-export + +Added for you when a diagram's JSON says `"export": true`. + +- The figure's foot gets "Download SVG" and "Download PNG", and so does its viewer's (the drawn layout at 100%, whatever the zoom). Each writes the figure in the theme shown: the title and source, the drawing and the key, at rest; native SVG with its words as text and the faces embedded; the PNG at 2x. +- Without `"export": true` there are no buttons and no module. Don't add your own. From 80f33ae2d2641b2caa8113ea8667e3c305f9c727 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:08:50 -0600 Subject: [PATCH 21/62] Automatic layout with elkjs (DECISIONS 306, 1.8) @srasyndicate/basalt/diagram-layout's placeDiagram(figure, direction) is the one module that imports elkjs (0.12.1, exact; EPL-2.0 OR GPL-3.0-or-later, used under EPL-2.0, unmodified; on the allowlist with its reason). It hands elk every card at one size, groups as hierarchy and the decision's fixed options, and reads back each card's column and row by bands, nothing else: CIMIP's architecture places as the proof's 6 by 3 (right) and 3 by 6 (down). layout="auto" on an architecture, flowchart or schema takes the cards' tracks from placement (one direction or both); a card's own col and row are not read (no hints; a development build says so). Each line's sides are chosen from the router's shapes, the line with the fewest clean ones first. The figure tries the type's direction, then the other, and stacks when neither fits. Without placement the module loads on demand at 640 or wider, never on a phone; until it answers the figure is stacked. The HTML skill places at build time: compose.mjs runs parts/diagram-place.mjs (React's placeDiagram, elkjs from the repository) and writes placement into the page, which never holds elkjs; Basalt.diagram with auto and no placement warns with the build path. Measured: CIMIP's automatic schema draws (3 by 5, laid down) at 1104. The automatic architecture and flowchart stack at 1104: a turn-back's label ("HTTP + SSE") finds no seat, and two lines from one decision lie on one another. The decision's proof routed on cells only and did not run seats. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- .agent/skills/basalt-html/compose.mjs | 10 + .../basalt-html/parts/diagram-place.mjs | 80 +++ .agent/skills/basalt-html/parts/diagram.js | 12 +- dependencies.allowed.json | 1 + package-lock.json | 7 + packages/react/build.mjs | 4 +- packages/react/package.json | 1 + packages/react/src/architecture-diagram.tsx | 16 +- packages/react/src/diagram-core.ts | 70 ++- packages/react/src/diagram-figure.tsx | 39 +- packages/react/src/diagram-layout.ts | 90 +++ packages/react/src/flowchart-diagram.tsx | 16 +- packages/react/src/schema-diagram.tsx | 16 +- .../react/test/fixtures/cimip-diagrams-b.json | 530 ++++++++++++++++++ tools/html-skill/build.mjs | 2 + tools/html-skill/src/compose.mjs | 10 + tools/html-skill/src/diagram-place.mjs | 14 + tools/html-skill/src/modules/diagram.js | 21 +- 18 files changed, 914 insertions(+), 25 deletions(-) create mode 100644 .agent/skills/basalt-html/parts/diagram-place.mjs create mode 100644 packages/react/src/diagram-layout.ts create mode 100644 tools/html-skill/src/diagram-place.mjs diff --git a/.agent/skills/basalt-html/compose.mjs b/.agent/skills/basalt-html/compose.mjs index 384add0e..92bf80a3 100644 --- a/.agent/skills/basalt-html/compose.mjs +++ b/.agent/skills/basalt-html/compose.mjs @@ -29,6 +29,7 @@ // file; PREFIX (aws, azure, gcp) keeps the ids that start with it. It reads parts/marks.json only, so the diagram usage need not list them. // // Source: tools/html-skill/src/compose.mjs (do not edit the copy in the skill folder). +import { execFileSync } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -647,6 +648,15 @@ function writeDiagrams(markup, held, parts, notes, marks) { try { spec = JSON.parse(item.inner); } catch (e) { notes.push(`a diagram's JSON does not parse (${e.message}); the page's script will say so`); continue; } // Each card's mark: a bundled id is checked and its rule written once; the page's own mark is read into the page and named by an id, so the JSON // the script reads carries the id and never a path. + // An automatic figure (DECISIONS 306, 1.8) is placed here, at build time, for both directions; the page holds the placement and never elkjs. + if (spec && spec.layout === "auto" && !spec.placement && ["architecture", "flowchart", "schema"].includes(spec.type)) { + try { + spec.placement = JSON.parse(execFileSync(process.execPath, [path.join(parts, "diagram-place.mjs")], { input: JSON.stringify(spec), encoding: "utf8" })); + const inner = `\n${JSON.stringify(spec).replace(/</g, "\\u003c")}\n`; + item.text = item.text.replace(item.inner, () => inner); + item.inner = inner; + } catch (e) { notes.push(`${spec.title ?? "a diagram"} could not be placed (${String(e.message).split("\n")[0]}); it is stacked`); } + } // An architecture's cards, a data flow's steps and a sequence's participants may carry one (DECISIONS 306, 1.6). const cards = spec && (spec.type === "architecture" || spec.type === "data-flow") ? spec.nodes : spec && spec.type === "sequence" ? spec.participants : null; if (Array.isArray(cards)) { diff --git a/.agent/skills/basalt-html/parts/diagram-place.mjs b/.agent/skills/basalt-html/parts/diagram-place.mjs new file mode 100644 index 00000000..5b5a34f4 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-place.mjs @@ -0,0 +1,80 @@ +// packages/react/src/diagram-layout.ts +var W = 200; +var H = 80; +var options = (direction) => ({ + "elk.algorithm": "layered", + "elk.direction": direction === "right" ? "RIGHT" : "DOWN", + "elk.randomSeed": "1", + "elk.hierarchyHandling": "INCLUDE_CHILDREN", + "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES", + "elk.layered.cycleBreaking.strategy": "MODEL_ORDER", + "elk.layered.nodePlacement.strategy": "BRANDES_KOEPF", + "elk.layered.spacing.nodeNodeBetweenLayers": "64", + "elk.spacing.nodeNode": "48", + "elk.edgeRouting": "ORTHOGONAL" +}); +function elkGraph(input2, direction) { + const cards = input2.type === "schema" ? (input2.tables ?? []).map((t) => ({ id: String(t.name), group: void 0 })) : (input2.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); + const edges = input2.type === "schema" ? (input2.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0] }))) : (input2.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to) })); + const groups = input2.type === "architecture" ? input2.groups ?? [] : []; + const kids = /* @__PURE__ */ new Map([["", []]]); + for (const g of groups) kids.set(g.id, []); + for (const c of cards) (kids.get(c.group ?? "") ?? kids.get("")).push({ id: c.id, width: W, height: H }); + const children = [...kids.get("")]; + for (const g of groups) { + const box = { id: `group:${g.id}`, children: kids.get(g.id), layoutOptions: { "elk.padding": "[top=32,left=16,bottom=16,right=16]" } }; + (g.parent && kids.has(g.parent) ? kids.get(g.parent) : children).push(box); + } + const ids = new Set(cards.map((c) => c.id)); + return { id: "root", layoutOptions: options(direction), children, edges: edges.filter((e) => ids.has(e.from) && ids.has(e.to)).map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to] })) }; +} +function absolute(node, ox = 0, oy = 0, out = /* @__PURE__ */ new Map()) { + for (const c of node.children ?? []) { + const x = ox + (c.x ?? 0), y = oy + (c.y ?? 0); + if (c.children) absolute(c, x, y, out); + else out.set(c.id, { x, y, w: c.width ?? W, h: c.height ?? H }); + } + return out; +} +function bands(rects, lo, hi) { + const ids = [...rects.keys()].sort((a, b) => lo(rects.get(a)) - lo(rects.get(b)) || (a < b ? -1 : a > b ? 1 : 0)); + const out = /* @__PURE__ */ new Map(); + let band = 0, end = Infinity; + for (const id of ids) { + const r = rects.get(id); + if (lo(r) >= end - 0.5) { + band++; + end = Infinity; + } + end = Math.min(end, hi(r)); + out.set(id, band + 1); + } + return out; +} +var elkMade; +async function placeDiagram(input2, direction) { + if (!elkMade) { + const mod = await import("elkjs/lib/elk.bundled.js"); + elkMade = new mod.default(); + } + const laid = await elkMade.layout(elkGraph(input2, direction)); + const rects = absolute(laid); + const col = bands(rects, (r) => r.x, (r) => r.x + r.w), row = bands(rects, (r) => r.y, (r) => r.y + r.h); + const cells = {}; + for (const id of rects.keys()) cells[id] = { col: col.get(id), row: row.get(id) }; + return { direction, cells }; +} + +// tools/html-skill/src/diagram-place.mjs +var input = ""; +process.stdin.setEncoding("utf8"); +process.stdin.on("data", (c) => { + input += c; +}); +process.stdin.on("end", async () => { + const spec = JSON.parse(input); + const directions = spec.direction ? [spec.direction] : spec.type === "flowchart" ? ["down", "right"] : ["right", "down"]; + const out = []; + for (const d of directions) out.push(await placeDiagram(spec, d)); + process.stdout.write(JSON.stringify(out)); +}); diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 1c2ba007..d29d5fd9 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,6 +1,6 @@ -(()=>{var Le=["top","right","bottom","left"],qe=["main","plain","dashed"],Oe=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function _t(t,e={}){const s=e.checks!==!1,r=[],o=h=>{r.push(h)},a=t.legend??{},i={};for(const h of["main","plain","dashed","focal","group","activation"]){const $=at(a[h]);$&&(i[h]=$)}const d=t.stepLabel,u=typeof d=="function"?h=>String(d(h)):typeof d=="string"?(h=>d.replace("{n}",String(h))):h=>`Step ${h}`,m=t.shapeLabels??{},p={terminal:at(m.terminal)??"Start or end",step:at(m.step)??"Step",decision:at(m.decision)??"Decision"},l=t.heading===void 0?3:Oe.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),b=(h,$)=>h==null?"plain":qe.includes(h)?h:(o(`"${String(h)}" is not a kind of line (main, plain or dashed): ${$} is drawn plain`),"plain"),w=h=>{if(h!=null){if(Le.includes(h))return h;o(`"${String(h)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(h,$)=>typeof h=="number"&&Number.isInteger(h)&&h>=1?h:(o(`${$} is ${JSON.stringify(h)}, not a whole number from 1: it is placed at 1`),1),f=[],v=[];let B=[];const C=[],M=[],I=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(I)||o(`"${String(I)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),I==="architecture"||I==="flowchart"){for(const h of t.nodes??[]){const $=I==="flowchart"&&h.shape==="decision"?"decision":I==="flowchart"&&h.shape==="terminal"?"terminal":"box",S=String(h.id??""),g=c(h.row,`the row of ${S}`);f.push({id:S,i:f.length,name:String(h.name??""),kind:$==="decision"?void 0:at(h.kind),detail:$==="decision"?void 0:at(h.detail),mono:!!h.detailMono,focal:!!h.focal,col:c(h.col,`the column of ${S}`),row:g,row2:g,branch:!!h.branch,shape:$,group:I==="architecture"?at(h.group):void 0,mark:I==="architecture"?Ct(h.mark):void 0})}if(I==="architecture"){const h=(t.groups??[]).map(y=>({id:String(y.id??""),label:String(y.label??""),parent:at(y.parent)})),$=new Map(h.map(y=>[y.id,y])),S=y=>{if(!y.parent)return 1;const x=$.get(y.parent);return x?x.parent===y.id||x.id===y.id?(o(`the groups "${y.label}" and "${x.label}" are each other's parent`),y.parent=void 0,1):x.parent?(o(`the group "${y.label}" is a third level: groups nest two deep`),y.parent=void 0,1):2:(o(`the group "${y.label}" names the parent "${y.parent}", which is not a group`),y.parent=void 0,1)},g=h.map(S);h.forEach((y,x)=>C.push({...y,depth:g[x],members:f.filter(E=>E.group===y.id).map(E=>E.id),all:[]}));for(const y of C)y.all=[...y.members,...C.filter(x=>x.parent===y.id).flatMap(x=>x.members)];C.sort((y,x)=>y.depth-x.depth)}}else if(I==="data-flow"){B=(t.lanes??[]).map($=>({id:String($.id??""),label:String($.label??"")}));const h=new Map(B.map(($,S)=>[$.id,S+1]));for(const $ of t.nodes??[]){const S=String($.id??""),g=String($.lane??""),y=h.get(g);y===void 0&&o(`a node (${S}) names the lane "${g}", which is not in lanes`);const x=f.length+1;f.push({id:S,i:f.length,name:String($.name??""),kind:u(x),detail:at($.detail),mono:!!$.detailMono,focal:!!$.focal,col:c($.col,`the column of ${S}`),row:y??1,row2:y??1,branch:!1,shape:"box",lane:y??1,laneLabel:B[(y??1)-1]?.label??g,step:x,mark:Ct($.mark)})}}else if(I==="sequence"){(t.participants??[]).forEach((g,y)=>{const x=String(g.name??"");f.push({id:String(g.id??""),i:y,name:x,kind:at(g.kind),mono:!1,focal:!!g.focal,col:y+1,row:1,row2:1,branch:!1,shape:"participant",short:at(g.short)??x,mark:Ct(g.mark)})});let h=0;const $=new Map(f.map(g=>[g.id,g.col])),S=(g,y)=>{let x=1/0,E=-1/0;for(const q of g??[]){if(!q||typeof q!="object")continue;if("band"in q){y>0&&o(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(q.band??"")});continue}if("frame"in q){if(y>=2){o("a frame is a third level: frames nest two deep");continue}const et=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",nt=et==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];et==="alt"&&nt.length<2&&o("an alt frame has one branch: it needs two or more");const J=String(nt[0]?.label??"");J.length>40&&o(`the frame label "${J}" is over 40 characters`);const ot=M.length;M.push({open:et,label:J,depth:y+1,a:0,b:0}),nt.forEach((X,st)=>{if(st){const xt=String(X.label??"");xt.length>40&&o(`the frame label "${xt}" is over 40 characters`),M.push({otherwise:xt,depth:y+1})}X.steps?.length||o(`a frame or branch ("${String(X.label??"")}") is empty`);const[rt,ct]=S(X.steps??[],y+1);x=Math.min(x,rt),E=Math.max(E,ct);const bt=M[ot];bt.a=Math.min(bt.a||1/0,rt),bt.b=Math.max(bt.b,ct)}),M.push({close:y+1});continue}h++;const T=String(q.label??"");T.includes(` -`)&&o(`message ${h}'s label has a break: a message's second line is its note`);const N=String(q.from??""),Q=String(q.to??"");M.push({n:h,from:N,to:Q,label:gt(T),note:at(q.note),kind:b(q.kind,`message ${h}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const U=$.get(N)??1,R=$.get(Q)??1,K=U===R?U===f.length?U-1:U+1:U;x=Math.min(x,U,R,K),E=Math.max(E,U,R,K)}return[x,E]};S(t.steps??[],0);for(const g of M)"open"in g&&!Number.isFinite(g.a)&&(g.a=1,g.b=Math.max(1,f.length))}else if(I==="schema")for(const h of t.tables??[]){const $=String(h.name??""),[S,g]=Array.isArray(h.row)?h.row:[h.row,h.row],y=c(S,`the row of ${$}`),x=Math.max(y,c(g,`the last row of ${$}`)),E=h.more===void 0||h.more===null?void 0:Number.isInteger(h.more)&&h.more>0?h.more:(o(`${$}'s "more" is ${JSON.stringify(h.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:$,i:f.length,name:$,mono:!0,focal:!!h.focal,col:c(h.col,`the column of ${$}`),row:y,row2:x,branch:!1,shape:"table",more:E,columns:(h.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&o(`${$}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}((I==="schema"?t.tables:I==="sequence"?t.participants:t.nodes)??[]).forEach((h,$)=>{if(!h||h.href===void 0||h.href===null)return;const S=String(h.href);if(I==="sequence"){o(`${f[$]?.id}: a participant cannot be a link (href)`);return}if(!S){o(`${f[$]?.id}'s href is empty`);return}const g=f[$];g&&(g.href=S,g.blank=h.target==="_blank")});const G=new Map;for(const h of f)h.id?G.has(h.id)&&o(`the id "${h.id}" is used twice`):o("a node has no id"),G.set(h.id,h);if(I==="schema")(t.tables??[]).forEach(h=>(h.columns??[]).forEach(($,S)=>{const g=at($.references);if(!g)return;const[y,x]=g.split("."),E=G.get(y??""),q=E?.columns?.findIndex(N=>N.name===x)??-1;if(!E||q<0){o(`${String(h.name)}.${String($.name)} references ${g}, which is not a shown column`);return}const T=G.get(String(h.name??""));T.columns[S].ref={table:y,column:x,row:q},v.push({i:v.length,from:T.id,to:y,kind:"plain",fromRow:S,toRow:q,fk:!0})}));else if(I!=="sequence")for(const h of t.edges??[]){const $=String(h.from??""),S=String(h.to??"");if(!G.has($)||!G.has(S)){o(`a line names ${G.has($)?S:$}, which is not a node`);continue}const g=at(h.label),y=g?.split(` -`)??[];y.length>2&&o(`the label "${gt(g)}" has more than one break: a label is two lines at most`),y.some(x=>x.length>Nt)&&o(`a line of the label "${gt(g)}" is over ${Nt} characters: longer words belong in the node or the summary`),v.push({i:v.length,from:$,to:S,kind:b(h.kind,`the line from ${$} to ${S}`),label:g,fromSide:w(h.fromSide),toSide:w(h.toSide),flow:I!=="flowchart"&&h.flow===!0?!0:void 0})}else for(const h of M)"n"in h&&(!G.has(h.from)||!G.has(h.to))&&o(`message ${h.n} names ${G.has(h.from)?h.to:h.from}, which is not a participant`);if(s&&I!=="sequence"){const h=new Map;for(const $ of f)for(let S=$.row;S<=$.row2;S++){const g=`${$.col}:${S}`;h.has(g)&&o(`${$.id} and ${h.get(g)} share the cell at column ${$.col}, row ${S}`),h.set(g,$.id)}}if(s){for(const $ of C){const S=$.all.map(x=>G.get(x));if(!S.length)continue;const g={c1:Math.min(...S.map(x=>x.col)),c2:Math.max(...S.map(x=>x.col)),r1:Math.min(...S.map(x=>x.row)),r2:Math.max(...S.map(x=>x.row2))};for(const x of f)!$.all.includes(x.id)&&x.col>=g.c1&&x.col<=g.c2&&x.row>=g.r1&&x.row<=g.r2&&o(`${x.id} is inside the box of the group "${$.label}" but not a member`);const y=S.map(x=>x.i);Math.max(...y)-Math.min(...y)+1!==y.length&&o(`the members of the group "${$.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const $ of f)$.group&&!C.some(S=>S.id===$.group)&&o(`${$.id} names the group "${$.group}", which is not in groups`);f.filter($=>$.focal).length>1&&o("more than one node is focal: a diagram has one at most");const h=new Set(I==="sequence"?M.flatMap($=>"n"in $?[$.kind]:[]):v.map($=>$.kind));h.has("main")&&!i.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),h.has("dashed")&&!i.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some($=>$.focal)&&!i.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const _=I==="architecture"||I==="data-flow",Z=h=>Array.isArray(h)&&h.length>1?h.map(String):void 0,L=_&&t.packet&&typeof t.packet=="object"?t.packet:void 0,z=L&&Z(L.path),O={animated:t.motion==="animated",pulse:_?Z(t.pulse):void 0,packet:z?{path:z,repeat:L.repeat===!0,send:L.send}:void 0,run:I==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const h of f){const $=h.mark?.says;if(!$?.length)continue;const S=[h.name,h.kind,h.detail,h.laneLabel].filter(Boolean).join(" ").toLowerCase();$.some(g=>S.includes(g.toLowerCase()))||o(`${h.id}'s mark stands for ${$.join(" or ")}, and none of its words say so`)}const A=[];if(I==="sequence"){const h=new Map,$=new Map;for(const S of M)"n"in S&&($.set(S.from,S.n),$.set(S.to,S.n));for(const S of M)if("n"in S){if(S.activate){const g=h.get(S.to)??[];if(g.length>=3)o(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const y={who:S.to,from:S.n,to:S.n,depth:g.length+1};g.push(y),A.push(y),h.set(S.to,g)}}if(S.deactivate){const y=h.get(S.from)?.pop();y?y.to=S.n:o(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,g]of h)for(const y of g)y.to=Math.max(y.from,$.get(S)??y.from)}const j=t.frameLabels??{},F={opt:at(j.opt)??"Only if",loop:at(j.loop)??"Repeats",alt:at(j.alt)??"One of these",else:at(j.else)??"Otherwise"};let V=Math.max(1,...f.map(h=>h.col));if(e.rtl){for(const $ of f)$.col=V-$.col+1;const h=$=>$==="left"?"right":$==="right"?"left":$;for(const $ of v)$.fromSide=h($.fromSide),$.toSide=h($.toSide);for(const $ of M)if("open"in $){const[S,g]=[V-$.b+1,V-$.a+1];$.a=S,$.b=g}V=Math.max(1,...f.map($=>$.col))}const W=I==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(h=>h.row2)),Y={type:I,title:String(t.title??""),heading:l,legend:i,nodes:f,byId:G,edges:v,groups:C,lanes:B,steps:M,bars:A,frameWords:F,cols:V,rows:W,shapeLabels:p,stepWord:u,warnings:r,motion:O,memo:new Map,rtl:e.rtl||void 0};return s&&f.length>1&&!Lt(Y)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),Y}function Ct(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ht=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function $t(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Nt=28,jt=t=>t.includes(` -`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Dt(t,e){return t.legend[e]}function Ie(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function _e(t,e){return $t(t,`sentence:${e.i}`,()=>Ce(t,e))}function Ce(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),r=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),r.length&&n.push(`Referenced by ${r.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(a=>"n"in a&&a.from===e.id).length,r=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${r}.`);const o=Gt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Ie(t,e):e.kind;if(n.push(wt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const a=t.groups.find(d=>d.id===e.group),i=a?.parent?t.groups.find(d=>d.id===a.parent):void 0;a&&n.push(i?`In ${a.label}, in ${i.label}.`:`In ${a.label}.`)}const r=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${gt(a.label)})`:""}`),o=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${gt(a.label)})`:""}`);r.length&&n.push(`From: ${r.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Gt(t,e){const n=t.bars.filter(r=>r.who===e.id&&r.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(r=>r.from===r.to?`message ${r.from}`:`messages ${r.from} to ${r.to}`).join(" and ")}.`:""}function je(t,e,n,s){const r=n.pointerType;if(r!=="touch"&&r!=="pen")return;const o=t.querySelector(`.${e}-drawing`),a=n.target;if(!o||!a||!o.contains(a)||!t.querySelector(`.${e}-edge`))return;const i=a.closest(`.${e}-node`);if(!i?.hasAttribute("href"))return i?i.dataset.node===s?null:i.dataset.node??null:null}function Kt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const r of n.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&s.push(r);return{t,a:e??{},c:s}}var Be={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>Be[e]),Te=" br img input meta link hr path polygon polyline circle rect line ";function Bt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,r]of Object.entries(t.a))if(!(r==null||r===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=r===!0?` ${s}`:` ${s}="${it(String(r))}"`}return Te.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Bt(s,e)).join("")}</${t.t}>`}var Re=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function We(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Et(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Vt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=Et(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,a)=>{o&&(e[a]=Math.max(e[a],Zt(t,n,a)))})}return e})}function Zt(t,e,n){const s=Et(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const i=Et(t,a);return i&&[i.r1===s.r1,i.c2===s.c2,i.r2===s.r2,i.c1===s.c1][n]})?2:1}function Ut(t){const e=Vt(t);return e[1]+e[3]}function Tt(t){return t.type==="sequence"?t.nodes.length:t.cols}function Jt(t){return $t(t,"plan",()=>ze(t))}function ze(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i,C=e.slice(Math.min(f,v)+1,Math.max(f,v)).every(M=>!n(M.i));return v===f+1&&!(n(f)&&!n(v))?"down":v===f-1?"up":v>f&&n(f)&&!n(v)&&C?"trunk":v>f&&n(f)&&n(v)&&C?"rail":v>f?"end-down":"end-up"}),r=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,v=t.byId.get(c.to).i;return[Math.min(f,v),Math.max(f,v)]},a=(c,f)=>{const[v,B]=o(c),[C,M]=o(f);return v<M&&C<B},i=r.every(({e:c})=>{const f=t.byId.get(c.from).i,[v,B]=o(c);return!n(f)&&e.slice(v+1,B).every(C=>!n(C.i))&&r.every(C=>C.e===c||!a(C.e,c))}),d=r.length>0&&(t.type==="data-flow"||!i),u=c=>{const[f,v]=o(c);return v-f},m=t.edges.map(()=>0);let p=!1;const l=[];for(const c of[...r].sort((f,v)=>u(f.e)-u(v.e)||f.k-v.k)){let f=0;for(const v of l)a(v.e,c.e)&&(f=Math.max(f,m[v.k]+1));m[c.k]=f,f>1&&(p=!0),l.push(c)}const b=t.edges.map(()=>.5);for(const c of e){const f=r.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const v=f.filter(({k:C})=>s[C]==="end-down").sort((C,M)=>u(M.e)-u(C.e)||C.k-M.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,M)=>u(C.e)-u(M.e)||M.k-C.k),...v].forEach(({k:C},M,I)=>{b[C]=I.length===2?M===0?1/3:2/3:(M+1)/(I.length+1)})}const w=ht();for(let c=1;c<e.length;c++){const f=e[c],v=e[c-1];let B=0,C=t.type==="data-flow"?48:32,M=!1,I=!1;t.edges.forEach((D,G)=>{const _=s[G],Z=t.byId.get(D.from).i,L=t.byId.get(D.to).i,z=L===c&&(_==="down"||_==="trunk"||_==="rail"||_==="end-down"),O=Z===c&&L===c-1&&_==="up",A=L===c-1&&_==="end-up";z&&(_==="trunk"||_==="end-down")&&(M=!0),A&&(I=!0),(z||O||A)&&D.label&&(B++,C=Math.max(C,_==="trunk"?40:48))}),(B>1||M&&I)&&(C=64),w[f.id]=C}return{routes:s,gutter:d,lanes:m,exits:b,gaps:w,third:p}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Xt(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,r=24,o=n==="dashed"?r-1:r-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${r-8} ${s-4}L${r} ${s}L${r-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${r} ${s}L${r-8} ${s-4}L${r-8} ${s+4}Z`}))}function kt(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Yt(t,e){return $t(e,`key:${t}`,()=>He(t,e))}var Fe=Yt;function He(t,e){const n=[],s=(o,a,i={})=>n.push(k("li",{class:`${t}-entry`,...i},o,k("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(i=>i.key)));for(const[a,i]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),k("span",null,i)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(kt(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(kt(t,"box"),e.shapeLabels.step),o.has("decision")&&s(kt(t,"decision"),e.shapeLabels.decision)}const r=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const a=e.legend[o];r.has(o)&&a&&s(Xt(t,o),a,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(Xt(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),k("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(kt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(kt(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Ne(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Rt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function De(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},Rt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},Rt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Ot(n.detail).flatMap((r,o)=>[o?" ":"",k("span",{class:`${t}-run`},r)]):n.detail)),s}function Ge(t,e,n){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},Rt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((s,r)=>k("span",{class:`${t}-row`,"data-row":r,"data-key":s.key},k("span",{class:`${t}-keyseat`},s.key??""),k("span",{class:`${t}-cname`},s.name),s.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?k("span",{class:`${t}-ctype`},s.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Qt=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function At(t,e,n,s){const{P:r}=t,o=We(e,s)||s.keep===n.id,a=mt(e,s),i=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=yt(d.gaps,n.id)??32,b=yt(s.grow,n.id)??0;i.push(`--_gap:${b?`calc(${Qt(l)} + var(--basalt-space-4) * ${b})`:Qt(l)}`)}const u=yt(s.heights,n.id);u&&i.push(`--_h:${u}px`);const m=yt(s.words,n.id);m&&i.push(`--_ww:${m}px`);const p=a?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${r}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?_e(e,n):void 0,tabindex:p},n.shape==="decision"?k("svg",{class:`${r}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${r}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ht(n.mark.onLight)};--_md:${Ht(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Ge(r,n,e):De(r,e,n))}function Ke(t,e,n){const{P:s}=t,r=[];if(e.type==="data-flow"&&r.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=Et(e,d);if(!u)continue;const m=[0,1,2,3].map(p=>Zt(e,d,p));r.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return r.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${d.col}`:void 0},At(t,e,d,n))))),r.push(Ve(t,e)),r;const o=d=>{const u=d.group?e.groups.find(m=>m.id===d.group):void 0;return u?.parent?e.groups.find(m=>m.id===u.parent):u},a=(d,u,m)=>{const p=t.plan?yt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:p?`--_ggrow:${p}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),m)};let i=0;for(;i<e.nodes.length;){const d=e.nodes[i],u=o(d);if(!u){r.push(At(t,e,d,n)),i++;continue}const m=[];for(;i<e.nodes.length&&o(e.nodes[i])?.id===u.id;)m.push(e.nodes[i++]);const p=[];for(let l=0;l<m.length;){const b=m[l].group!==u.id?e.groups.find(c=>c.id===m[l].group):void 0;if(!b){p.push(At(t,e,m[l],n)),l++;continue}const w=[];for(;l<m.length&&m[l].group===b.id;)w.push(m[l++]);p.push(a(b,w,w.map(c=>At(t,e,c,n))))}r.push(a(u,m,p))}return r}function Ve(t,e){const{P:n}=t,s=[],r=[],o=()=>r.length?r[r.length-1].el.c:s;let a=null;for(const i of e.steps){if("band"in i){a=null,o().push(k("p",{class:`${n}-band`},k("span",null,i.band)));continue}if("open"in i){a=null;const c=r[r.length-1],f=c?`;--_fis:${i.a===c.a?1:0};--_fie:${i.b===c.b?1:0}`:"",v=k("div",{class:`${n}-frame`,"data-op":i.open,"data-depth":i.depth,style:`--_a:${i.a};--_b:${i.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},i.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[i.open]}: `),i.label)));o().push(v),r.push({el:v,a:i.a,b:i.b});continue}if("otherwise"in i){a=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),i.otherwise)));continue}if("close"in i){a=null,r.pop();continue}a||(a=k("ol",{class:`${n}-msgs`,start:i.n}),o().push(a));const d=e.byId.get(i.from),u=e.byId.get(i.to),m=d?.col??1,p=u?.col??1,l=m===p,b=l&&(e.rtl?m!==1:m===e.nodes.length),w=Dt(e,i.kind);a.c.push(k("li",{class:`${n}-msg`,"data-kind":i.kind,"data-from":i.from,"data-to":i.to,"data-self":l?b?"start":"end":void 0,style:`--_a:${Math.min(m,p)};--_b:${Math.max(m,p)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(i.n)),k("span",{class:`${n}-mlabel`},i.label)),k("span",{class:`${n}-route`},d?.short??i.from," ",Ne(n,i.kind),k("span",{class:t.hidden}," to ")," ",u?.short??i.to,w?` · ${w}`:""),i.note?k("span",{class:`${n}-note`},i.note):null))}return k("div",{class:`${n}-steps`},s)}function Pt(t,e){return $t(e,`list:${t}`,()=>Ue(t,e))}var Ze=Pt;function Ue(t,e){const n=Math.min(6,e.heading+1),s=p=>k(`h${n}`,{class:`${t}-list-head`},p),r=p=>k("strong",null,p),o=p=>p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},r(p.name)):r(p.name),a=p=>k("code",{class:`${t}-code`},p),i=p=>e.byId.get(p)?.name??p,d=p=>{const l=Dt(e,p);return l?` (${l})`:""},u=p=>p.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const p=w=>k("li",null,o(w),w.kind?`, ${w.kind}`:"",w.detail?[". ",w.mono?a(w.detail):w.detail,/[.!?]$/.test(w.detail)?"":"."]:/[.!?]$/.test(w.kind??w.name)?"":".",u(w)),l=[s("Parts")],b=e.nodes.filter(w=>!w.group);b.length&&l.push(k("ul",{class:`${t}-list-items`},b.map(p)));for(const w of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},w.label)),w.members.length&&l.push(k("ul",{class:`${t}-list-items`},w.members.map(c=>p(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===w.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>p(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map(w=>k("li",null,r(i(w.from))," to ",r(i(w.to)),w.label?[": ",a(gt(w.label))]:"",`${d(w.kind)}.`)))),l}if(e.type==="flowchart"){const p=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const b=e.edges.filter(f=>f.from===l.id),w=l.shape==="decision"?"Decision":l.shape==="terminal"?b.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?a(l.detail):l.detail]:"",`${c}${w}.`,u(l),b.length?k("ul",{class:`${t}-list-exits`},b.map(f=>k("li",null,f.label?`If ${gt(f.label)}: go to ${p(f.to)}, `:`Then: go to ${p(f.to)}, `,r(i(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(p=>{const l=e.edges.filter(b=>b.from===p.id);return k("li",null,`${p.laneLabel}: `,o(p),p.detail?[", ",p.mono?a(p.detail):p.detail]:"",".",u(p),l.length?[" Then ",...l.flatMap((b,w)=>[w?"; ":"",`to step ${e.byId.get(b.to).step}, `,r(i(b.to)),b.label?[": ",a(gt(b.label))]:"",d(b.kind)]),"."]:"")}))];if(e.type==="sequence"){const p=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(b=>k("li",null,r(b.name),b.kind?`, ${b.kind}`:"",".",u(b),Gt(e,b))))];p.push(s("Messages"));let l=null;for(const b of e.steps){if("band"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},b.band));continue}if("open"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords[b.open]}: ${b.label}`));continue}if("otherwise"in b){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":b.depth>1?b.depth:void 0},`${e.frameWords.else}: ${b.otherwise}`));continue}if("close"in b){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:b.n}),p.push(l)),l.c.push(k("li",null,a(b.label),": ",r(i(b.from))," to ",r(i(b.to)),`${d(b.kind)}.`,b.note?` ${wt(b.note)}`:""))}return p}const m=[];for(const p of e.nodes)m.push(k(`h${n}`,{class:`${t}-list-group`},p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},a(p.name)):a(p.name),u(p))),m.push(k("ul",{class:`${t}-list-items`},[...(p.columns??[]).map(l=>k("li",null,a(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",a(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...p.more?[k("li",null,`and ${p.more} more ${p.more===1?"column":"columns"}`)]:[]]));return m}function te(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Lt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(r=>r.href)?" Enter opens a part that is a link.":""}`}function Wt(t,e=!1){const n=e&&t.type!=="sequence"&&Lt(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(r=>r.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Kt(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var Je=(t,e)=>{for(let n=0;n<t.length;n++)if(t[n]!==e[n])return t[n]<e[n];return!1},Xe=(t,e)=>({col:e.col,rows:[e.row,e.row2]});function Lt(t){return $t(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...Xe(t,o)})),n=(o,a)=>{const i=a==="right"||a==="left",d=a==="right"||a==="down",u=w=>i?[w.col,w.col]:w.rows,m=w=>i?w.rows:[w.col,w.col],p=u(o),l=m(o);let b=null;return e.forEach((w,c)=>{if(w===o)return;const f=u(w),v=m(w),B=d?f[0]-p[1]:p[0]-f[1];if(B<1)return;const C=Math.max(0,v[0]-l[1],l[0]-v[1]),M=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(v[0]-l[0]),c];(!b||Je(M,b.rank))&&(b={id:w.id,rank:M})}),b?.id??null},s=ht();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const r=o=>{const a=new Set([o]),i=[o];for(;i.length;)for(const d of Object.values(s[i.pop()]))d&&!a.has(d)&&(a.add(d),i.push(d));return a.size};return e.every(o=>r(o.id)===e.length)?s:null})}var ee=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function ne(t,e,n){const s=n.prefix,r=Re(n.base),o=t.type==="sequence"||t.type==="schema"?null:Jt(t),a={P:s,ids:r,level:n.level,plan:o,hidden:n.hiddenClass},i=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?i:!0,m=`h${t.heading}`,p=[`--_cols:${Tt(t)}`];if(t.type==="architecture"&&t.groups.length||i&&e.pad){const l=t.type==="architecture"?Vt(t):[0,0,0,0],b=(c,f,v)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:v?`var(--basalt-space-${v})`:"0px",w=i&&e.pad?"3":void 0;p.push(`--_gpad:${b(l[0],"8",w)} ${b(l[1],"4")} ${b(l[2],"4",w)} ${b(l[3],"4")}`)}return ee(t)&&p.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&p.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":r.title,"data-type":t.type,"data-cols":Tt(t),"data-reach":t.type==="architecture"?Ut(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:p.join(";")},k("div",{class:`${s}-head`},k(m,{id:r.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?r.title:void 0,"aria-describedby":u?d?`${r.summary} ${r.keys}`:r.summary:void 0,"data-stops":d?"":void 0},Ke(a,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),Yt(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||i&&t.type==="sequence"?k("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${Kt(t)} to highlight its lines. Tap it again to clear.`):null,k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:r.list,class:`${s}-list`,hidden:!e.open},Pt(s,t)),k("span",{id:r.keys,class:n.hiddenClass},n.viewer?`${te(t,i)} ${n.viewer}`:te(t,i)),k("figcaption",{id:r.summary,class:`${s}-summary`},{slot:"summary"}))}function Ye(t){const e=getComputedStyle(t),n=(r,o)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${r}`));return Number.isFinite(a)?a:o},s=new Map;return{space:r=>(s.has(r)||s.set(r,n(`space-${r}`,parseFloat(r.replace("-","."))*4)),s.get(r)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var qt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.l<e.r-n&&t.r>e.l+n&&t.t<e.b-n&&t.b>e.t+n,oe=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2,p=e==="top"||e==="bottom";if(t.shape==="decision"){if(p){const w=n,c=m*Math.max(0,1-Math.abs(w-i)/u);return{x:w,y:e==="top"?d-c:d+c}}const l=n,b=u*Math.max(0,1-Math.abs(l-d)/m);return{x:e==="left"?i-b:i+b,y:l}}if(t.shape==="terminal"){const l=Math.min(u,m);if(p){const f=n,v=Math.min(Math.max(f,s+l),o-l),B=f-v,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?r:a:e==="top"?d-C:d+C}}const b=n,w=b-d,c=Math.abs(w)>=l?0:Math.sqrt(l*l-w*w);return{x:e==="left"?s+l-c:o-l+c,y:b}}return p?{x:n,y:e==="top"?r:a}:{x:e==="left"?s:o,y:n}}function Qe(t,e,n){const{l:s,t:r,r:o,b:a}=e.rect,i=(s+o)/2,d=(r+a)/2,u=(o-s)/2,m=(a-r)/2;if(e.shape==="decision")return Math.abs(t.x-i)/u+Math.abs(t.y-d)/m<1-n/Math.min(u,m);if(e.shape==="terminal"){const p=Math.min(u,m),l=Math.min(Math.max(t.x,s+p),o-p);return Math.hypot(t.x-l,t.y-d)<p-n}return t.x>s+n&&t.x<o-n&&t.y>r+n&&t.y<a-n}function se(t,e){if(!ut(t,e.rect))return!1;if(e.shape!=="decision"&&e.shape!=="terminal")return!0;const{l:n,t:s,r,b:o}=e.rect,a=(n+r)/2,i=(s+o)/2,d=(r-n)/2,u=(o-s)/2;if(e.shape==="decision"){const p=Math.max(t.l,Math.min(a,t.r)),l=Math.max(t.t,Math.min(i,t.b));return Math.abs(p-a)/d+Math.abs(l-i)/u<1-1e-6}const m=Math.min(u,d);if(ut(t,{l:n+m,r:r-m,t:s,b:o}))return!0;for(const p of[n+m,r-m]){const l=Math.max(t.l,Math.min(p,t.r)),b=Math.max(t.t,Math.min(i,t.b));if(Math.hypot(l-p,b-i)<m-.01)return!0}return!1}function Pe(t,e,n){const s=Math.hypot(e.x-t.x,e.y-t.y),r=Math.max(2,Math.ceil(s/2));for(let o=1;o<r;o++){const a=o/r;if(!(a*s<1.5||(1-a)*s<1.5)&&Qe({x:t.x+(e.x-t.x)*a,y:t.y+(e.y-t.y)*a},n,1))return!0}return!1}var tn=()=>matchMedia("(forced-colors: active)").matches;function en(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(r,o)=>{const a=`${o}|${r}`;return s.has(a)||(n.setAttribute("data-f",o),n.textContent=r,s.set(a,n.getBoundingClientRect().width),n.textContent=""),s.get(a)}}var Ot=t=>t?t.split(/\s+/).filter(Boolean):[];function nn(t,e,n){const s=e.space;let r=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`${t.rtl?"←":"→"} ${c.ref.table}`:c.type??"",v=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(v))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),m=d.mark&&!tn()?(d.shape==="participant"?2:1)*s("6"):0;let p=0;const l=d.href?16+s("1-5"):0,b=Ot(d.name);if(b.forEach((c,f)=>{p=Math.max(p,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:m)+(f===b.length-1?l:0))}),t.type!=="data-flow")for(const c of Ot(d.kind))p=Math.max(p,n(c,"mono")+m);for(const c of Ot(d.detail))p=Math.max(p,n(c,d.mono?"mono":"sans"));const w=d.shape==="decision"?p/.62:p+u+2*e.hair;r=Math.max(r,Math.ceil(w))}const a=Tt(t);let i;return t.type==="data-flow"?i=e.lane+a*(r+s("12")):t.type==="schema"?i=a*o+(a-1)*s("12")+(ee(t)?s("5"):0):t.type==="sequence"?i=a*r+(a-1)*s("5"):i=a*r+(a-1)*s("16")+Ut(t)*s("4"),{track:r,table:o,least:Math.max(e.wide,i)}}function ae(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function zt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function re(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o<s.length;o++){const a=s[o-1],i=s[o];if(Math.abs(a.x-i.x)<.75){const d=n.x(a.x,e);a.x=d,i.x=d}else if(Math.abs(a.y-i.y)<.75){const d=n.y(a.y,e);a.y=d,i.y=d}}const r=[s[0]];for(let o=1;o<s.length;o++){const a=s[o],i=r[r.length-1];if(!(Math.abs(a.x-i.x)<.01&&Math.abs(a.y-i.y)<.01)){if(r.length>=2){const d=r[r.length-2];if(Math.abs(d.x-i.x)<.01&&Math.abs(i.x-a.x)<.01||Math.abs(d.y-i.y)<.01&&Math.abs(i.y-a.y)<.01){r[r.length-1]=a;continue}}r.push(a)}}return r}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function It(t,e,n){const s=[];for(let o=0;o<t.length;o++)for(let a=o+1;a<t.length;a++){const i=t[o],d=t[a];if(!(n&&!n.has(i.i)&&!n.has(d.i)))for(const[u,m]of pt(i.pts))for(const[p,l]of pt(d.pts)){const b=Math.abs(u.y-m.y)<.01,w=Math.abs(p.y-l.y)<.01;if(b===w)continue;const[c,f,v,B]=b?[u,m,p,l]:[p,l,u,m],C=v.x,M=c.y;if(C>Math.min(c.x,f.x)+.75&&C<Math.max(c.x,f.x)-.75&&M>Math.min(v.y,B.y)+.75&&M<Math.max(v.y,B.y)-.75){const I=b?o:a,D=b?a:o;let G=I,_=D;if(e){const Z=e(t[I]);e(t[D])&&!Z&&(G=D,_=I)}s.push({top:G,under:_,at:{x:C,y:M},underVertical:_===D})}}}return s}function on(t){const e=getComputedStyle(t),n=r=>r.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(r,o,a)=>{const i=[];let d=o;for(const u of r)i.push([d,d+u]),d+=u+a;return i};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var tt=t=>t==="left"||t==="right",ie={top:"bottom",bottom:"top",left:"right",right:"left"};function sn(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function an(t,e,n){const s=[];t.edges.forEach((o,a)=>{const i=t.byId.get(o.from),d=t.byId.get(o.to),[u,m]=e[a],p=i.row===d.row&&tt(u)&&tt(m)&&u===ie[m]||i.col===d.col&&!tt(u)&&!tt(m)&&u===ie[m];s.push({edge:a,end:"from",node:i,side:u,far:d,straight:p,f:.5},{edge:a,end:"to",node:d,side:m,far:i,straight:p,f:.5})});const r=new Map;for(const o of s){const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o)}for(const[o,a]of r){if(a[0].node.shape==="decision")continue;const i=c=>tt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=a.filter(c=>c.straight),u=a.filter(c=>!c.straight);if(u.sort((c,f)=>i(c)-i(f)||(tt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(i(c)<0?1:-1)),a.length>3&&n(`${o.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const m=new Map;for(const c of d)m.has(c.far.id)||m.set(c.far.id,[]),m.get(c.far.id).push(c);for(const c of m.values())c.length>1&&c.sort((f,v)=>f.edge-v.edge).forEach((f,v)=>{f.f=c.length===2?v===0?.25:.75:(v+1)/(c.length+1)});const p=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),b=u.filter(c=>i(c)<0),w=u.filter(c=>i(c)>=0);b.forEach((c,f)=>{c.f=p*(f+1)/(b.length+1)}),w.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/(w.length+1)})}return s}function le(t,e,n){const{l:s,t:r,r:o,b:a}=t.rect;return tt(e)?lt(t,e,r+(a-r)*n):lt(t,e,s+(o-s)*n)}function ce(t,e,n,s){const r=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const a=t.byId.get(o.dataset.node);a&&r.set(a.id,{id:a.id,rect:ft(o,n),shape:a.shape,i:a.i})}),r}function de(t,e){const n=e.head,s=e.head/2,{x:r,y:o}=t.tip;return t.dir==="down"?{l:r-s,r:r+s,t:o-n,b:o}:t.dir==="up"?{l:r-s,r:r+s,t:o,b:o+n}:t.dir==="right"?{l:r-n,r,t:o-s,b:o+s}:{l:r,r:r+n,t:o-s,b:o+s}}var fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function ue(t,e,n,s){const r=(o,a)=>{const i=o+a-Math.floor(o+a);return i<.005||i>.995?[0]:i<=.5?[-i,1-i]:[1-i,-i]};for(const o of r(t.t,n))for(const a of r(t.l,e)){if(!a&&!o)return t;const i={l:t.l+a,r:t.r+a,t:t.t+o,b:t.b+o};if(s(i))return i}return t}function rn(t,e,n,s,r,o,a,i,d){const u=a.space,m=[],p=[],l=[],b=[],w=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,v)=>+(t.edges[v.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-v.i);for(const f of c){const v=t.edges[f.i].label,B=i(v,"label"),C=16*jt(v),M=f.pts.length-2,I=[];pt(f.pts).forEach(([L,z],O)=>{const A=Math.abs(L.y-z.y)<.01,j=A?L.x:L.y;let F=A?z.x:z.y;const V=Math.sign(F-j)||1;O===M&&(F-=V*a.head);let W=[[j,F]];for(const $ of r)for(const S of A?[$.l,$.r]:[$.t,$.b]){const g=A?L.y:L.x;(A?g>$.t&&g<$.b:g>$.l&&g<$.r)&&(W=W.flatMap(([x,E])=>S>Math.min(x,E)+1&&S<Math.max(x,E)-1?[[x,S],[S,E]]:[[x,E]]))}const Y=($,S)=>{const g=($+S)/2,y=A?{x:g,y:L.y}:{x:L.x,y:g};return!r.some(x=>y.x>x.l&&y.x<x.r&&y.y>x.t&&y.y<x.b)},h=f.axes?.[O]??(A?L.y:L.x);for(const[$,S]of W)I.push({horiz:A,c:h,p:$,q:S,len:Math.abs(S-$),pri:W.length>1&&Y($,S)?1:0})}),I.sort((L,z)=>z.pri-L.pri||z.len-L.len);let D=null,G=!1;const _=(L,z=!0)=>{const O=oe(L,w);return z&&(L.l<o.l||L.r>o.r||L.t<o.t||L.b>o.b)||n.some(A=>se(O,A))||m.some(A=>ut(O,A))||s.heads.some(A=>ut(O,A))||s.rects.some(A=>ut(O,A))?!1:!e.some(A=>A.i!==f.i&&pt(A.pts).some(([j,F])=>ut(O,fe(j,F,A.width))))};for(const L of I){for(const z of[1/2,1/3,2/3]){const O=L.p+(L.q-L.p)*z,A=[],j=u("2")+f.width/2;if(L.horiz?(L.len>=B+2*u("1")+u("3-5")&&A.push({box:{l:O-B/2-u("1"),r:O+B/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),A.push({box:{l:O-B/2,r:O+B/2,t:L.c-j-C,b:L.c-j},on:!1}),A.push({box:{l:O-B/2,r:O+B/2,t:L.c+j,b:L.c+j+C},on:!1})):(L.len>=C+u("3")&&A.push({box:{l:L.c-B/2-u("1"),r:L.c+B/2+u("1"),t:O-C/2,b:O+C/2},on:!0}),A.push({box:{l:L.c+j,r:L.c+j+B,t:O-C/2,b:O+C/2},on:!1}),A.push({box:{l:L.c-j-B,r:L.c-j,t:O-C/2,b:O+C/2},on:!1})),D=A.find(F=>_(F.box))??null,D)break;!G&&A.some(F=>_(F.box,!1))&&(G=!0)}if(D)break}if(!D){l.push(f.i),G&&b.push(f.i);continue}const Z=ue(D.box,d.ox,d.oy,L=>_(L));m.push(Z),p.push({i:f.i,text:v,box:Z,on:D.on})}return{labels:p,unseated:l,bounded:b}}function he(t,e,n,s){const r=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const i=ft(a,e);o.push(i),r.push({l:i.l,r:i.r,t:i.t,b:i.t+1},{l:i.l,r:i.r,t:i.b-1,b:i.b},{l:i.l,r:i.l+1,t:i.t,b:i.b},{l:i.r-1,r:i.r,t:i.t,b:i.b});const d=a.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&r.push(ft(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,i)=>{if(!a.getClientRects().length)return;const d=ft(a,e);i>0&&r.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=a.querySelector(`.${n}-lane-name`);u&&r.push(ft(u,e))}),{obstacles:{rects:r,heads:[]},groups:o}}function ln(t,e){const{m:s,tk:r,P:o,drawing:a,origin:i,warn:d}=t,u=r.space,m=ce(s,a,i,o),p=[...m.values()],l=on(a),b=i.left-Math.floor(i.left),w=i.top-Math.floor(i.top),c=ae(b,w),f=a.clientWidth,v=a.clientHeight,B=g=>s.type==="data-flow"?g.col+1:g.col,C=parseFloat(getComputedStyle(a).rowGap)||0,M={w:f,h:v,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:b,oy:w};if(s.type==="sequence")return dn(t,M,c);let I,D=[];s.type==="schema"?I=s.edges.map(g=>{const y=s.byId.get(g.from),x=s.byId.get(g.to);if(y.col===x.col){const E=y.col===s.cols&&s.cols>1?"left":"right";return[E,E]}return x.col>y.col?["right","left"]:["left","right"]}):(I=s.edges.map(g=>{const y=s.byId.get(g.from),x=s.byId.get(g.to),[E,q]=sn(y,x);return[g.fromSide??E,g.toSide??q]}),D=an(s,I,d||(()=>{})));const G=(g,y)=>{const x=a.querySelector(`.${o}-node[data-node="${CSS.escape(g)}"] .${o}-row[data-row="${y}"]`);if(!x)return 0;const E=ft(x,i);return(E.t+E.b)/2},_=s.edges.map((g,y)=>{const[x,E]=I[y],q=m.get(g.from),T=m.get(g.to),N=qt(g.kind,r);if(g.fk){const J=G(g.from,g.fromRow),ot=G(g.to,g.toRow),X=c.y(J,N),st=c.y(ot,N);return{p1:{x:x==="right"?q.rect.r:q.rect.l,y:X},p2:{x:E==="right"?T.rect.r:T.rect.l,y:st},r1:J,r2:Math.abs(X-st)<.01?J:ot}}const Q=D.find(J=>J.edge===y&&J.end==="from").f,U=D.find(J=>J.edge===y&&J.end==="to").f;let R=le(q,x,Q),K=le(T,E,U);const et=tt(x)?R.y:R.x;let nt=tt(E)?K.y:K.x;return tt(x)?R={...R,y:c.y(R.y,N)}:R={...R,x:c.x(R.x,N)},tt(E)?K={...K,y:c.y(K.y,N)}:K={...K,x:c.x(K.x,N)},tt(x)&&tt(E)&&Math.abs(R.y-K.y)<1.01&&(K={...K,y:R.y},nt=et),!tt(x)&&!tt(E)&&Math.abs(R.x-K.x)<1.01&&(K={...K,x:R.x},nt=et),R=tt(x)?lt(q,x,R.y):lt(q,x,R.x),K=tt(E)?lt(T,E,K.y):lt(T,E,K.x),{p1:R,p2:K,r1:et,r2:nt}}),Z=new Set;s.type==="schema"&&s.edges.forEach((g,y)=>{Math.abs(s.byId.get(g.from).col-s.byId.get(g.to).col)>1&&Z.add(y)});const L=new Map,z=new Set;s.edges.forEach((g,y)=>{if(Z.has(y))return;const[x,E]=I[y],{p1:q,p2:T}=_[y],N=s.byId.get(g.from),Q=s.byId.get(g.to);let U=null,R=null,K=!1;if(x===E){if(tt(x)){const J=x==="right"?Math.max(B(N),B(Q)):Math.min(B(N),B(Q))-1,ot=l.cols[J-1],X=l.cols[J];ot&&X&&(U=`c${J}`,R=[ot[1],X[0]],K=!0)}else{const J=x==="bottom"?Math.max(N.row2,Q.row2):Math.min(N.row,Q.row)-1,ot=l.rows[J-1],X=l.rows[J];ot&&X&&(U=`r${J}`,R=[ot[1],X[0]],K=!1)}U&&z.add(y)}else if(tt(x)&&tt(E)&&Math.abs(q.y-T.y)>.5){const J=B(Q),ot=E==="left",X=l.cols[(ot?J-1:J)-1],st=l.cols[(ot?J:J+1)-1];X&&st&&(U=`c${ot?J-1:J}`,R=[X[1],st[0]],K=!0)}else if(!tt(x)&&!tt(E)&&Math.abs(q.x-T.x)>.5){const ot=E==="top"?Q.row-1:Q.row2,X=l.rows[ot-1],st=l.rows[ot];X&&st&&(U=`r${ot}`,R=[X[1],st[0]],K=!1)}if(!U||!R)return;L.has(U)||L.set(U,{span:R,vertical:K,members:new Map});const et=`${g.to}.${E}.${Math.round(K?T.y:T.x)}`,nt=L.get(U);nt.members.has(et)||nt.members.set(et,[]),nt.members.get(et).push(y)});const O=new Map,A=g=>{const[y,x]=I[g],{p1:E,p2:q}=_[g];if(tt(y)&&tt(x)){if(y===x){const N=O.get(g)??(y==="right"?Math.max(E.x,q.x)+u("4"):Math.min(E.x,q.x)-u("4"));return[E,{x:N,y:E.y},{x:N,y:q.y},q]}if(Math.abs(E.y-q.y)<=.5)return[E,{x:q.x,y:E.y}];const T=O.get(g)??(E.x+q.x)/2;return[E,{x:T,y:E.y},{x:T,y:q.y},q]}if(!tt(y)&&!tt(x)){if(y===x){const N=O.get(g)??(y==="bottom"?Math.max(E.y,q.y)+u("4"):Math.min(E.y,q.y)-u("4"));return[E,{x:E.x,y:N},{x:q.x,y:N},q]}if(Math.abs(E.x-q.x)<=.5)return[E,{x:E.x,y:q.y}];const T=O.get(g)??(E.y+q.y)/2;return[E,{x:E.x,y:T},{x:q.x,y:T},q]}return tt(y)?[E,{x:q.x,y:E.y},q]:[E,{x:E.x,y:q.y},q]},j=g=>{const y=s.edges[g],x=qt(y.kind,r),E=A(g),q=re(E,x,c);let T;return E.length===q.length&&(T=pt(E).map(([N,Q])=>Math.abs(N.y-Q.y)<.75?(N.y+Q.y)/2:(N.x+Q.x)/2),T[0]=_[g].r1,T.length>1&&(T[T.length-1]=_[g].r2)),{i:g,from:y.from,to:y.to,kind:y.kind,pts:q,tip:q[q.length-1],dir:zt(q),dot:y.fk?q[0]:void 0,width:x,axes:T}},F=()=>s.edges.flatMap((g,y)=>Z.has(y)?[]:[j(y)]);let V=null;const W=g=>{V??(V=F());const y=V.map(x=>g.has(x.i)?j(x.i):x);return{lines:y,score:cn(y,g)*1e5+It(y,void 0,g).length*1e3+Ft(y.filter(x=>g.has(x.i)),p,s).length}},Y=(g,y)=>{const x=g.flatMap(E=>{const{p1:q,p2:T}=_[E];return y?[q.y,T.y]:[q.x,T.x]});return[Math.min(...x),Math.max(...x)]};for(const[,g]of L){const y=[...g.members.values()].map(E=>({members:E,run:Y(E,g.vertical)})).sort((E,q)=>E.run[0]-q.run[0]),x=[];for(const E of y){const q=x[x.length-1];q&&q.some(T=>T.run[0]<E.run[1]+u("8")&&E.run[0]<T.run[1]+u("8"))?q.push(E):x.push([E])}for(const E of x){if(E.length===1&&E[0].members.every(et=>z.has(et)))continue;const q=E.map(et=>et.members),T=q.length,N=(g.span[1]-g.span[0])/(T+1);N<u("3")&&d?.(`a gutter holds ${T} lanes side by side, closer than space-3`);const Q=new Set(q.flat());let U=q,R=1/0,K=null;for(const et of ge(q)){et.forEach((J,ot)=>J.forEach(X=>O.set(X,g.span[0]+N*(ot+1))));const nt=W(Q);nt.score<R&&(R=nt.score,U=et,K=nt.lines)}U.forEach((et,nt)=>et.forEach(J=>O.set(J,g.span[0]+N*(nt+1)))),V=K}}M.lines=F();for(const g of Z)d?.(`${s.edges[g].from} to ${s.edges[g].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=It(M.lines),M.through=Ft(M.lines,p,s),M.outside=me(M.lines,f,v,r);const{obstacles:h,groups:$}=he(a,i,o,C);h.heads=M.lines.map(g=>de(g,r));const S=rn(s,M.lines,p,h,$,{l:0,t:0,r:f,b:v},r,e,{ox:b,oy:w});return M.labels=S.labels,M.unseated=S.unseated,M.bounded=S.bounded,M.overlaps=[...new Set(pe(M.lines,null).flat())],M}function cn(t,e){return pe(t,e).length}function pe(t,e){const n=[];for(let s=0;s<t.length;s++)for(let r=s+1;r<t.length;r++){const o=t[s],a=t[r];if(e&&!e.has(o.i)&&!e.has(a.i)||o.to===a.to&&Math.abs(o.tip.x-a.tip.x)<1&&Math.abs(o.tip.y-a.tip.y)<1)continue;const i=(o.width+a.width)/2+.5;for(const[d,u]of pt(o.pts))for(const[m,p]of pt(a.pts)){const l=Math.abs(d.y-u.y)<.01,b=Math.abs(m.y-p.y)<.01;if(l!==b)continue;const[w,c]=l?[d.y,m.y]:[d.x,m.x];if(Math.abs(w-c)>=i)continue;const[f,v]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[m.x,p.x]:[m.y,p.y];Math.min(Math.max(f,v),Math.max(B,C))-Math.max(Math.min(f,v),Math.min(B,C))>1&&n.push([o.i,a.i])}}return n}function*ge(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e<t.length;e++){const n=t.slice(0,e).concat(t.slice(e+1));for(const s of ge(n))yield[t[e],...s]}}function me(t,e,n,s){const r=[];for(const o of t)o.pts.some((a,i)=>{const d=i===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return a.x-d<-.5||a.x+d>e+.5||a.y-d<-.5||a.y+d>n+.5})&&r.push(o.i);return r}function Ft(t,e,n){const s=[];for(const r of t){const o=pt(r.pts);e.some(a=>o.some(([i,d])=>Pe(i,d,a)))&&s.push(r.i)}return s}function dn(t,e,n){const{m:s,tk:r,P:o,drawing:a,origin:i}=t,d=r.space,u=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>u.set(M.dataset.node,ft(M,i)));const m=a.querySelector(`.${o}-steps`),p=m?ft(m,i).b:e.h,l=M=>{const I=u.get(M);return I?n.x((I.l+I.r)/2,r.hair):0};for(const M of s.nodes){const I=u.get(M.id);I&&e.lifelines.push({x:l(M.id),y1:I.b,y2:p})}const b=M=>u.get(M.id),w=new Map;a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=ft(M,i);w.set(Number(M.querySelector(`.${o}-num`)?.textContent??0),(I.t+I.b)/2)});const c=r.activation,f=c/2,v=M=>{const I=s.byId.get(M.who);if(!I)return null;const D=l(M.who),_=(I.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),Z=(M.depth-1)*d("1")*_,L=w.get(M.from)??0,z=w.get(M.to)??L,O=M.from===M.to;return{l:n.x(D-f+Z,r.hair),r:n.x(D+f+Z,r.hair),t:n.y(O?L-d("2")-d("1"):L,r.hair),b:n.y(O?L+d("2")+d("1"):z,r.hair)}},B=s.bars.map(M=>({bar:M,rect:v(M)})).filter(M=>M.rect);e.bars=B.map(M=>M.rect);const C=(M,I,D)=>B.filter(({bar:G})=>G.who===M&&G.to>=I&&(D?G.from<=I:G.from<I||G.from===I&&G.to===I)).sort((G,_)=>_.bar.depth-G.bar.depth)[0]?.rect;return a.querySelectorAll(`.${o}-msg`).forEach(M=>{const I=M.dataset.from,D=M.dataset.to,G=M.dataset.kind??"plain",_=qt(G,r),Z=ft(M,i),L=n.y((Z.t+Z.b)/2,_),z=Number(M.querySelector(`.${o}-num`)?.textContent??0);let O=l(I),A=l(D),j;if(I===D){const S=M.dataset.self==="start"?-d("6"):d("6"),g=C(I,z,!0),y=g?S>0?g.r:g.l:O,x=n.y(L-d("2"),_),E=n.y(L+d("2"),_);j=[{x:y,y:x},{x:n.x(O+S,_),y:x},{x:n.x(O+S,_),y:E},{x:y,y:E}]}else{const S=A>O?1:-1,g=C(I,z,!1),y=C(D,z,!0);g&&(O=S>0?g.r:g.l),y&&(A=S>0?y.l:y.r),j=[{x:O,y:L},{x:A,y:L}]}e.lines.push({i:z,from:I,to:D,kind:G,pts:j,tip:j[j.length-1],dir:zt(j),width:_});const F=M.querySelector(`.${o}-said`),V=M.querySelector(`.${o}-note`),W=s.byId.get(I),Y=s.byId.get(D);if(!W||!Y)return;const h=I===D?(()=>{const S=s.nodes[W.i+(M.dataset.self==="start"?-1:1)],g=S?l(S.id):M.dataset.self==="start"?0:e.w;return Math.abs(g-O)-d("6")-d("2-5")-d("2")})():Math.abs(A-O)-2*d("2");Math.max(F?F.getBoundingClientRect().width:0,V?V.getBoundingClientRect().width:0)>h+.5&&e.unseated.push(z)}),a.querySelectorAll(`.${o}-fhead`).forEach(M=>{const I=M.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!I)return;[...M.children].reduce((G,_)=>G+_.getBoundingClientRect().width,0)+d("3")>I.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ye(t,e,n,s=ht()){const{m:r,tk:o,P:a,drawing:i,origin:d}=t,u=o.space,m=ce(r,i,d,a),p=[...m.values()],l=d.left-Math.floor(d.left),b=d.top-Math.floor(d.top),w=ae(l,b),c=i.clientWidth,f=i.clientHeight,v={w:c,h:f,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:b},B=ht();if(r.type==="sequence"||r.type==="schema")return{geo:v,grow:B};const C=c-(parseFloat(getComputedStyle(i).paddingRight)||0),M=(A,j,F)=>{const V=[A];for(let W=1;W<=(yt(s,j)??0);W++)V.push({...A,t:A.t+F*u("4")*W,b:A.b+F*u("4")*W});return V},I=new Map;i.querySelectorAll(`.${a}-node`).forEach(A=>{const j=A.parentElement,F=ft(j,d),V=getComputedStyle(j);I.set(A.dataset.node,F.r-(parseFloat(V.paddingRight)||0)-(parseFloat(V.borderRightWidth)||0))});const D=r.nodes,G=A=>m.get(D[A].id),_=[],Z=A=>qt(r.edges[A].kind,o);r.edges.forEach((A,j)=>{const F=n.routes[j],V=m.get(A.from),W=m.get(A.to),Y=Z(j);let h=[];const $=A.label,S=$?e($,"label"):0,g=$?16*jt($):16,y=u("4");if(F==="down"||F==="up"){const E=Math.max(V.rect.l,W.rect.l),q=Math.min(V.rect.r,W.rect.r),T=r.edges.map((R,K)=>({o:R,j:K})).filter(({o:R,j:K})=>(n.routes[K]==="down"||n.routes[K]==="up")&&(R.from===A.from&&R.to===A.to||R.from===A.to&&R.to===A.from)),N=T.findIndex(R=>R.j===j),Q=T.length<2?.5:T.length===2?N===0?.25:.75:(N+1)/(T.length+1),U=w.x(E+(q-E)*Q,Y);if(h=F==="down"?[lt(V,"bottom",U),lt(W,"top",U)]:[lt(V,"top",U),lt(W,"bottom",U)],$){let R=Math.min(h[0].y,h[1].y),K=Math.max(h[0].y,h[1].y);F==="down"?K-=o.head:R+=o.head;const et=[...i.querySelectorAll(`.${a}-group`)].map(X=>ft(X,d));let nt=[[R,K]];for(const X of et)for(const st of[X.t,X.b])nt=nt.flatMap(([rt,ct])=>st>rt+1&&st<ct-1?[[rt,st],[st,ct]]:[[rt,ct]]);const J=(X,st)=>et.some(rt=>(X+st)/2>rt.t&&(X+st)/2<rt.b&&U>rt.l&&U<rt.r);if(nt.length>1){const X=nt.filter(([rt,ct])=>!J(rt,ct));[R,K]=(X.length?X:nt).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const ot=[1/2,1/3,2/3].map(X=>{const st=R+(K-R)*X;return{l:U-S/2-u("1"),r:U+S/2+u("1"),t:st-g/2,b:st+g/2}});_.push({k:j,cands:ot,on:!0,card:F==="down"?A.to:A.from})}}else if(F==="trunk"||F==="rail"){const E=w.x(Math.max(V.rect.l,F==="rail"?W.rect.l:V.rect.l)+u(F==="trunk"?"8":"3"),Y),q=lt(V,"bottom",E);if(F==="rail"){if(h=[q,lt(W,"top",E)],$){const T=W.rect.t-u("6");_.push({k:j,cands:M({l:E+u("2-5"),r:E+u("2-5")+S,t:T-g/2,b:T+g/2},A.to,-1),on:!1,card:A.to})}}else{const T=w.x(W.rect.l+u("6"),Y),N=w.y(W.rect.t-y,Y);h=[q,{x:E,y:N},{x:T,y:N},lt(W,"top",T)],$&&_.push({k:j,cands:M({l:T+u("2-5"),r:T+u("2-5")+S,t:N-g/2,b:N+g/2},A.to,-1),on:!1,card:A.to})}}else{const E=Math.min(I.get(A.from)??c,I.get(A.to)??c),q=w.x(n.gutter?C+(n.lanes[j]?2*u("3-5"):u("3-5")):E-u("2-5"),Y),T=w.y(V.rect.t+(V.rect.b-V.rect.t)*n.exits[j],Y),N=lt(V,"right",T),Q=w.x(W.rect.r-u("6"),Y),U=F==="end-down",R=w.y(U?W.rect.t-y:W.rect.b+y,Y);h=[N,{x:q,y:N.y},{x:q,y:R},{x:Q,y:R},lt(W,U?"top":"bottom",Q)];const K=U?A.to:D[W.i+1]?.id??A.to;$&&_.push({k:j,cands:M({l:Q-u("2-5")-S,r:Q-u("2-5"),t:R-g/2,b:R+g/2},K,U?-1:1),on:!1,card:K})}const x=re(h,Y,w);v.lines.push({i:j,from:A.from,to:A.to,kind:A.kind,pts:x,tip:x[x.length-1],dir:zt(x),width:Y})}),v.crossings=It(v.lines),v.through=Ft(v.lines,p,r),v.outside=me(v.lines,c,f,o);const{obstacles:L}=he(i,d,a,0);L.heads=v.lines.map(A=>de(A,o));const z=[],O={l:0,t:0,r:c,b:f};for(const A of _){const j=W=>{const Y=oe(W,u("1"));return W.l<O.l-.5||W.r>O.r+.5||W.t<O.t-.5||W.b>O.b+.5||p.some(h=>se(Y,h))||z.some(h=>ut(Y,h))||L.heads.some(h=>ut(Y,h))||L.rects.some(h=>ut(Y,h))||v.lines.some(h=>h.i!==A.k&&pt(h.pts).some(([$,S])=>ut(Y,fe($,S,h.width))))},F=A.cands.find(W=>!j(W));F||(B[A.card]=(B[A.card]??0)+1,v.unseated.push(A.k));const V=F?ue(F,l,b,W=>!j(W)):A.cands[0];z.push(V),v.labels.push({i:A.k,text:r.edges[A.k].label,box:V,on:A.on})}return{geo:v,grow:B}}function fn(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o<t.length-1;o++){const a=t[o-1],i=t[o],d=t[o+1],u=Math.hypot(i.x-a.x,i.y-a.y),m=Math.hypot(d.x-i.x,d.y-i.y),p=Math.min(e,u/2,m/2);if(p<.5){s+=`L${n(i.x)} ${n(i.y)}`;continue}const l={x:i.x+(a.x-i.x)/u*p,y:i.y+(a.y-i.y)/u*p},b={x:i.x+(d.x-i.x)/m*p,y:i.y+(d.y-i.y)/m*p};s+=`L${n(l.x)} ${n(l.y)}Q${n(i.x)} ${n(i.y)} ${n(b.x)} ${n(b.y)}`}const r=t[t.length-1];return`${s}L${n(r.x)} ${n(r.y)}`}var un={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function hn(t,e,n,s,r){const o=un[e.dir],a=e.kind==="dashed",i=n.head,d=n.head/2,u=a?1:i-1,m=e.pts.map(M=>({...M})),p=m[m.length-1];p.x-=o.x*u,p.y-=o.y*u;const l=e.tip.x-o.x*i,b=e.tip.y-o.y*i,w=-o.y*d,c=o.x*d,f=M=>Math.round(M*100)/100,v=it(e.kind),B=a?`<path class="${t}-tip" data-kind="${v}" data-open="" d="M${f(l+w)} ${f(b+c)}L${f(e.tip.x)} ${f(e.tip.y)}L${f(l-w)} ${f(b-c)}"/>`:`<path class="${t}-tip" data-kind="${v}" d="M${f(e.tip.x)} ${f(e.tip.y)}L${f(l+w)} ${f(b+c)}L${f(l-w)} ${f(b-c)}Z"/>`,C=e.dot?`<circle class="${t}-dot" cx="${f(e.dot.x)}" cy="${f(e.dot.y)}" r="${n.dot/2}"/>`:"";return`<g class="${t}-edge" data-edge="${e.i}" data-from="${it(e.from)}" data-to="${it(e.to)}"><path class="${t}-line" data-kind="${v}" d="${fn(m,r)}"${s?` mask="url(#${it(s)})"`:""}/>${B}${C}</g>`}function be(t,e,n,s){const r=new Map,o=new Map;for(const i of e.crossings)o.has(i.under)||o.set(i.under,[]),o.get(i.under).push(i);let a="";for(const[i,d]of o){const u=`${s}-cut-${i}`;r.set(i,u);const m=d.map(p=>{const l=e.lines[p.top],b=e.lines[p.under],w=l.width/2+n.cut,c=b.width/2+1;return p.underVertical?`<rect x="${p.at.x-c}" y="${p.at.y-w}" width="${2*c}" height="${2*w}" fill="black"/>`:`<rect x="${p.at.x-w}" y="${p.at.y-c}" width="${2*w}" height="${2*c}" fill="black"/>`}).join("");a+=`<mask id="${it(u)}" maskUnits="userSpaceOnUse" x="0" y="0" width="${e.w}" height="${e.h}"><rect x="0" y="0" width="${e.w}" height="${e.h}" fill="white"/>${m}</mask>`}return{defs:a,ids:r}}function $e(t,e,n,s){const{defs:r,ids:o}=be(t,e,n,s),a=e.lifelines.map(m=>`<path class="${t}-life" d="M${m.x} ${m.y1}V${m.y2}"/>`).join("")+(e.bars??[]).map(m=>`<rect class="${t}-bar" x="${m.l}" y="${m.t}" width="${Math.round((m.r-m.l)*100)/100}" height="${Math.round((m.b-m.t)*100)/100}"/>`).join(""),i=e.lines.map((m,p)=>hn(t,m,n,o.get(p)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),d=`<svg class="${t}-svg" width="${e.w}" height="${e.h}" viewBox="0 0 ${e.w} ${e.h}" focusable="false">${r?`<defs>${r}</defs>`:""}${a}<g class="${t}-edges">${i}</g></svg>`,u=e.labels.map(m=>`<span class="${t}-label" data-edge="${m.i}"${m.on?' data-on=""':""}${jt(m.text)>1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` -`).map(it).join("<br>")}</span>`).join("");return d+u}function we(t,e,n,s,r,o,a,i){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:r,geo:null,ink:"",tokens:null};const m=Ye(t),p=en(u,n),l=nn(e,m,p);i?.(l.least);const b=t.clientWidth,w=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),c=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:w&&L.layout!=="drawn"?w:void 0};let f=!1;const v=L=>{if(f=!1,e.type!=="flowchart")return L;o({...L,heights:void 0,words:void 0});const z=ht(),O=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(A=>{const j=A.querySelector(`.${n}-words`);if(!j)return;const F=A.getBoundingClientRect(),V=h=>{const $={w:h.width+2*m.space("2-5"),h:h.height+2*m.space("2")},S=1-$.w/F.width,g=S>.05?$.h/2/S:$.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*g))},W=j.getBoundingClientRect();let Y=V(W);if(Y>F.width){const h=y=>(A.style.setProperty("--_ww",`${y}px`),j.getBoundingClientRect()),$=Math.floor(A.clientWidth-2*m.space("2-5"));let S=Math.ceil(W.width),g=W.height;for(;S<$&&h($).height<g-.5;){let y=S,x=$;for(;x-y>1;){const T=y+x>>1;h(T).height<g-.5?x=T:y=T}const E=h(x),q=V(E);if(q<=F.width){Y=q,O[A.dataset.node]=x;break}S=x,g=E.height}A.style.removeProperty("--_ww")}z[A.dataset.node]=Y,Y>F.width&&(f=!0)}),{...L,heights:z,words:Object.keys(O).length?O:void 0}},B=()=>({m:e,tk:m,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:a}),C=r.autoOpen?{open:!1,autoOpen:void 0}:{},M=(L,z)=>z.map(O=>Mt(e,L.lines.find(A=>A.i===O))).join(", ");if(b>=l.least){const L=j=>{let F=c({...r,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:j||void 0});return F=v(F),o(F),{dd:F,g:ln(B(),p)}};let{dd:z,g:O}=L(!1);const A=j=>j.through.length>0||j.outside.length>0||(j.overlaps?.length??0)>0||(j.misfit?.length??0)>0||f;if(!A(O)&&O.unseated.length&&O.unseated.every(j=>O.bounded?.includes(j))){const j=L(!0);!A(j.g)&&!j.g.unseated.length&&({dd:z,g:O}=j)}if(!A(O)&&!O.unseated.length)return O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the drawn layout: ${O.crossings.map(j=>`${Mt(e,O.lines[j.top])} over ${Mt(e,O.lines[j.under])}`).join("; ")}`),{dyn:z,geo:O,ink:$e(n,O,m,s),tokens:m,least:l.least};f&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: a decision would be taller than it is wide`),O.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${O.misfit.join("; ")}`),O.through.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.through)} would pass through a node`),O.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.overlaps)} would lie on one another`),O.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: ${M(O,O.outside)} would leave the drawing`),O.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(b)}px: no clean seat for ${O.unseated.map(j=>e.type==="sequence"?`message ${j}`:`"${e.edges[j]?.label}"`).join(", ")}`)}let I=c({...r,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(I=v(I),o(I),e.type==="sequence"||e.type==="schema")return{dyn:I,geo:null,ink:"",tokens:m,least:l.least};const D=Jt(e);let G=ye(B(),p,D,I.grow);for(let L=0;L<6&&Object.keys(G.grow).length;L++){const z=ht(I.grow);for(const[O,A]of Object.entries(G.grow))z[O]=(yt(z,O)??0)+A;I={...I,grow:z},o(I),G=ye(B(),p,D,z)}const _=G.geo;if(_.unseated.length>0||_.through.length>0||_.outside.length>0||D.third){_.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(_.unseated)].map(O=>`"${e.edges[O]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),_.through.length&&a?.(`in the stacked drawing ${M(_,_.through)} would pass through a node, so its lines are not drawn`),_.outside.length&&a?.(`in the stacked drawing ${M(_,_.outside)} would leave the drawing, so its lines are not drawn`),D.third&&a?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={..._,lines:[],labels:[],crossings:[]};return{dyn:c({...I,grow:ht(),bare:!0,open:r.bare?r.open:!0,autoOpen:r.bare?r.autoOpen:r.open?void 0:!0}),geo:L,ink:"",tokens:m,least:l.least}}return _.crossings.length&&a?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${_.crossings.map(L=>`${Mt(e,_.lines[L.top])} over ${Mt(e,_.lines[L.under])}`).join("; ")}`),{dyn:I,geo:_,ink:$e(n,_,m,s),tokens:m,least:l.least}}function Mt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function pn(t,e,n,s,r,o){const a=new Set;if(o){a.add(o);for(const c of n?.lines??[])c.from===o&&a.add(c.to),c.to===o&&a.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",a.has(c.dataset.node))),!n||!s)return;const i=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",i(c)),f.toggleAttribute("data-dim",!!o&&!i(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(v=>String(v.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&i(f)))}),d){for(const c of n.lines)if(i(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const m=It(n.lines,i),{defs:p,ids:l}=be(e,{...n,crossings:m},s,r),b=t.querySelector(`.${e}-svg`);if(!b)return;let w=b.querySelector("defs");!w&&p&&(w=document.createElementNS("http://www.w3.org/2000/svg","defs"),b.insertBefore(w,b.firstChild)),w&&(w.innerHTML=p),n.lines.forEach((c,f)=>{const v=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!v)return;const B=l.get(f);B?v.setAttribute("mask",`url(#${B})`):v.removeAttribute("mask")})}var gn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function mn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",gn()||bn(t)?"done":"pending")}}var yn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function bn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(yn(t))!==null}catch{return!1}}function ve(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function $n(t,e,n,s=!1,r=!1){const o=s?Lt(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:r?"left":"right",ArrowLeft:r?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const a=t.byId.get(e)?.i??0,i=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=a-1;else if(n==="Home")d=0;else if(n==="End")d=i-1;else return null;return t.nodes[Math.max(0,Math.min(i-1,d))].id}var wn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],xe=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],vn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],ke=t=>t==null||t===!1;function xn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Me(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?xe:wn;for(const a of s)ke(e.a[a])&&t.removeAttribute(a);for(const[a,i]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const u=t.style,m=new Map(String(i??"").split(";").map(p=>{const l=p.indexOf(":");return[p.slice(0,l).trim(),p.slice(l+1).trim()]}).filter(([p])=>p));for(const[p,l]of m)u.getPropertyValue(p).trim()!==l&&u.setProperty(p,l);for(const p of vn)m.has(p)||u.removeProperty(p);continue}if(n&&!xe.includes(a))continue;if(ke(i)){t.removeAttribute(a);continue}const d=i===!0?"":String(i);t.getAttribute(a)!==d&&t.setAttribute(a,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const r=[...t.children];let o=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let i=o;i<r.length;i++)if(xn(r[i],a)){Me(r[i],a,!1),o=i+1;break}}}function kn(t,e,n,s){if(n===s)return;const r=o=>t.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&r(n)?.setAttribute("tabindex","-1"),r(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function r(l,b,w){return{prefix:n,base:l,hasSource:b.source!==void 0&&b.source!==null&&b.source!=="",hiddenClass:"visually-hidden",viewer:w?w.keys:void 0}}function o(l,b,w,c){var f=function(v){return'<kbd class="kbd">'+it(v)+"</kbd>"};return{source:it(String(b.source||"")),summary:it(String(b.summary||"")),hint:Wt(l).map(function(v){return"<span>"+v.keys.map(f).join(" ")+" "+it(v.words)+"</span>"}).join(""),toggle:'<button type="button" class="btn diagram-toggle" data-variant="secondary" data-size="sm" aria-expanded="'+(c?"true":"false")+'" aria-controls="'+it(w)+'-list"><span>'+(c?"Hide the list":"View as list")+"</span></button>"}}function a(l,b,w){var c=_t(l),f=ne(c,{},r(b,l,w)),v=Bt(f,o(c,l,b,!1)),B=v.indexOf(">");return{open:v.slice(0,B+1),inner:v.slice(B+1,v.length-9),warnings:c.warnings}}var i=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,b,w,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),v=_t(b,{rtl:getComputedStyle(l).direction==="rtl"});if(!w||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var B=a(b,f,c),C=document.createElement("div");C.innerHTML=B.open+"</figure>";var M=C.firstChild;i.forEach(function(H){l.removeAttribute(H)}),d.forEach(function(H){l.style.removeProperty(H)});for(var I=0;I<M.attributes.length;I++){var D=M.attributes[I];D.name==="class"?l.classList.add.apply(l.classList,D.value.split(" ")):D.name==="style"?l.style.cssText=D.value+";"+l.style.cssText:l.setAttribute(D.name,D.value)}l.querySelectorAll(":scope > :not(script[data-diagram])").forEach(function(H){H.remove()}),l.insertAdjacentHTML("beforeend",B.inner)}v.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var G=r(f,b,c),_={},Z=null,L=null,z=null,O=null,A=Object.create(null),j=function(H){A[H]||(A[H]=1,console.warn("Basalt diagram: "+H))},F=function(H){Me(l,ne(v,H,G))},V=l.querySelector(".diagram-ink"),W=l.querySelector(".diagram-toggle"),Y=!c&&v.motion.animated&&typeof e.diagramMotion=="function",h=null,$=null,S=function(){Y&&ve(l)};function g(){pn(l,n,Z&&Z.geo,Z&&Z.tokens,f,L||O||z),E()}var y=null,x=!c&&matchMedia("(hover: none), (pointer: coarse)").matches;function E(){var H=x&&!c&&V&&V.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(x&&!c)),H&&!y){var P=l.querySelector(":scope > .diagram-foot");if(!P)return;y=document.createElement("button"),y.type="button",y.className="btn diagram-clear",y.setAttribute("data-variant","secondary"),y.setAttribute("data-size","sm"),y.innerHTML="<span>Clear highlight</span>",y.addEventListener("click",function(){O&&(O=null,g())}),P.appendChild(y)}else!H&&y&&(y.remove(),y=null);y&&(O?y.removeAttribute("aria-disabled"):y.setAttribute("aria-disabled","true"))}function q(H){if(!H.defaultPrevented){var P=je(l,n,H,O);P!==void 0&&(S(),x=!0,O=P,g())}}function T(){W&&(W.setAttribute("aria-expanded",String(!!_.open)),W.firstElementChild.textContent=_.open?"Hide the list":"View as list")}function N(){Z=(c?c.measure:we)(l,v,n,f,_,F,j),_=Z.dyn,F(_),T();var H=l.querySelector(":scope > .diagram-hint");if(H){var P=Wt(v,_.layout==="drawn").map(function(St){return"<span>"+St.keys.map(function(Sn){return'<kbd class="kbd">'+it(Sn)+"</kbd>"}).join(" ")+" "+it(St.words)+"</span>"}).join("");H.innerHTML!==P&&(H.innerHTML=P)}mt(v,_)||(z=O=null);var dt=V&&Z.ink!==$;dt&&(V.innerHTML=Z.ink,$=Z.ink),g(),Y&&Z.tokens&&(mn(l,!!(Z.geo&&Z.geo.lines.length)),dt&&h&&h.redrawn()),c&&c.onMeasured&&Z.tokens&&c.onMeasured(Z,l)}function Q(H){_=H,F(_)}function U(H){var P=_.stop;_=Object.assign({},_,{stop:H}),kn(l,n,P,H)}var R=function(H){var P=H&&H.closest?H.closest(".diagram-node"):null;return P&&l.contains(P)?P:null};function K(H){var P=R(H.target);if(!(!P||H.defaultPrevented)){if(S(),H.key==="Escape"){!c&&(L||z||O)&&(H.preventDefault(),L=z=O=null,g());return}if(mt(v,_)){var dt=$n(v,P.getAttribute("data-node"),H.key,_.layout==="drawn");if(dt){H.preventDefault(),U(dt);var St=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');St&&St.focus()}}}}function et(H){var P=R(H.target);if(P){S();var dt=P.getAttribute("data-node");L=P.matches(":focus-visible")?dt:null,mt(v,_)&&_.stop!==dt&&U(dt),g()}}function nt(H){var P=R(H.target);P&&(R(H.relatedTarget)||(L=null),_.keep===P.getAttribute("data-node")&&Q(Object.assign({},_,{keep:void 0})),g())}function J(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var P=R(H.target);P&&S();var dt=P&&mt(v,_)?P.getAttribute("data-node"):null;dt!==z&&(z=dt,g())}}function ot(){z&&(z=null,g())}function X(){S(),Q(Object.assign({},_,{open:!_.open,autoOpen:void 0})),T()}l.addEventListener("keydown",K),l.addEventListener("focusin",et),l.addEventListener("focusout",nt),l.addEventListener("pointerover",J),l.addEventListener("pointerleave",ot),l.addEventListener("click",q),W&&W.addEventListener("click",X),N();var st=l.clientWidth,rt=0,ct=!0,bt=new ResizeObserver(function(){Math.abs(l.clientWidth-st)<.5||(st=l.clientWidth,cancelAnimationFrame(rt),rt=requestAnimationFrame(N))});bt.observe(l),document.fonts&&document.fonts.ready.then(function(){ct&&N()});var xt=matchMedia("(forced-colors: active)"),Se=v.nodes.some(function(H){return H.mark});Se&&xt.addEventListener("change",N),Y&&(h=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return v},geo:function(){return Z&&Z.geo},tokens:function(){return Z&&Z.tokens}},b));var Ee=!c&&b.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,b,{model:v,settle:S,animated:Y}):null,Ae=l.querySelector(":scope > .diagram-foot"),Mn=!c&&b.export===!0&&Ae&&typeof e.diagramExport=="function"?e.diagramExport(Ae,l):[];l.__diagram={stop:function(){Ee&&Ee.destroy(),Mn.forEach(function(H){H.remove()}),ct=!1,bt.disconnect(),cancelAnimationFrame(rt),Se&&xt.removeEventListener("change",N),h&&h.destroy(),l.removeEventListener("keydown",K),l.removeEventListener("focusin",et),l.removeEventListener("focusout",nt),l.removeEventListener("pointerover",J),l.removeEventListener("pointerleave",ot),l.removeEventListener("click",q),y&&y.remove(),W&&W.removeEventListener("click",X)},layout:N,key:m(b),send:h&&h.sendValue?h.sendValue:null}}function m(l){try{return JSON.stringify(l,function(b,w){return b==="packet"&&w&&typeof w=="object"?Object.assign({},w,{send:void 0}):w})}catch{return null}}function p(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var b=l.querySelector(":scope > script[data-diagram]");if(b)try{u(l,JSON.parse(b.textContent),!0)}catch(w){console.error("Basalt diagram: this figure could not be drawn",w)}}})}e.diagramMarkup=a,e.diagramKit={draw:u,buildModel:_t,figureKey:Fe,figureList:Ze,hintEntries:Wt,toHtml:Bt,escapeHtml:it,settleEntrance:ve,measureFigure:we},t.diagram=function(l,b){var w=l.__diagram,c=w&&w.send?m(b):null;if(c!==null&&c===w.key){w.send(b.packet?b.packet.send:void 0);return}u(l,b)},e.step(62,"wireDiagrams",p)})(window.Basalt)})(); +(()=>{var Re=["top","right","bottom","left"],We=["main","plain","dashed"],Ne=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Mt(t,e={}){const s=e.checks!==!1,i=[],o=g=>{i.push(g)},r=t.legend??{},a={};for(const g of["main","plain","dashed","focal","group","activation"]){const b=at(r[g]);b&&(a[g]=b)}const d=t.stepLabel,u=typeof d=="function"?g=>String(d(g)):typeof d=="string"?(g=>d.replace("{n}",String(g))):g=>`Step ${g}`,y=t.shapeLabels??{},p={terminal:at(y.terminal)??"Start or end",step:at(y.step)??"Step",decision:at(y.decision)??"Decision"},l=t.heading===void 0?3:Ne.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),m=(g,b)=>g==null?"plain":We.includes(g)?g:(o(`"${String(g)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),v=g=>{if(g!=null){if(Re.includes(g))return g;o(`"${String(g)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(g,b)=>typeof g=="number"&&Number.isInteger(g)&&g>=1?g:(t.layout==="auto"&&g==null||o(`${b} is ${JSON.stringify(g)}, not a whole number from 1: it is placed at 1`),1),f=[],S=[];let B=[];const C=[],E=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||o(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const g of t.nodes??[]){const b=A==="flowchart"&&g.shape==="decision"?"decision":A==="flowchart"&&g.shape==="terminal"?"terminal":"box",h=String(g.id??""),x=c(g.row,`the row of ${h}`);f.push({id:h,i:f.length,name:String(g.name??""),kind:b==="decision"?void 0:at(g.kind),detail:b==="decision"?void 0:at(g.detail),mono:!!g.detailMono,focal:!!g.focal,col:c(g.col,`the column of ${h}`),row:x,row2:x,branch:!!g.branch,shape:b,group:A==="architecture"?at(g.group):void 0,mark:A==="architecture"?Bt(g.mark):void 0})}if(A==="architecture"){const g=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:at($.parent)})),b=new Map(g.map($=>[$.id,$])),h=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(o(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(o(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(o(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},x=g.map(h);g.forEach(($,w)=>C.push({...$,depth:x[w],members:f.filter(_=>_.group===$.id).map(_=>_.id),all:[]}));for(const $ of C)$.all=[...$.members,...C.filter(w=>w.parent===$.id).flatMap(w=>w.members)];C.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){B=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const g=new Map(B.map((b,h)=>[b.id,h+1]));for(const b of t.nodes??[]){const h=String(b.id??""),x=String(b.lane??""),$=g.get(x);$===void 0&&o(`a node (${h}) names the lane "${x}", which is not in lanes`);const w=f.length+1;f.push({id:h,i:f.length,name:String(b.name??""),kind:u(w),detail:at(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:c(b.col,`the column of ${h}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:B[($??1)-1]?.label??x,step:w,mark:Bt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((x,$)=>{const w=String(x.name??"");f.push({id:String(x.id??""),i:$,name:w,kind:at(x.kind),mono:!1,focal:!!x.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:at(x.short)??w,mark:Bt(x.mark)})});let g=0;const b=new Map(f.map(x=>[x.id,x.col])),h=(x,$)=>{let w=1/0,_=-1/0;for(const q of x??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&o(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),E.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){o("a frame is a third level: frames nest two deep");continue}const st=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=st==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];st==="alt"&&V.length<2&&o("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&o(`the frame label "${P}" is over 40 characters`);const U=E.length;E.push({open:st,label:P,depth:$+1,a:0,b:0}),V.forEach((et,rt)=>{if(rt){const xt=String(et.label??"");xt.length>40&&o(`the frame label "${xt}" is over 40 characters`),E.push({otherwise:xt,depth:$+1})}et.steps?.length||o(`a frame or branch ("${String(et.label??"")}") is empty`);const[ct,At]=h(et.steps??[],$+1);w=Math.min(w,ct),_=Math.max(_,At);const bt=E[U];bt.a=Math.min(bt.a||1/0,ct),bt.b=Math.max(bt.b,At)}),E.push({close:$+1});continue}g++;const R=String(q.label??"");R.includes(` +`)&&o(`message ${g}'s label has a break: a message's second line is its note`);const Q=String(q.from??""),X=String(q.to??"");E.push({n:g,from:Q,to:X,label:gt(R),note:at(q.note),kind:m(q.kind,`message ${g}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const z=b.get(Q)??1,D=b.get(X)??1,tt=z===D?z===f.length?z-1:z+1:z;w=Math.min(w,z,D,tt),_=Math.max(_,z,D,tt)}return[w,_]};h(t.steps??[],0);for(const x of E)"open"in x&&!Number.isFinite(x.a)&&(x.a=1,x.b=Math.max(1,f.length))}else if(A==="schema")for(const g of t.tables??[]){const b=String(g.name??""),[h,x]=Array.isArray(g.row)?g.row:[g.row,g.row],$=c(h,`the row of ${b}`),w=Math.max($,c(x,`the last row of ${b}`)),_=g.more===void 0||g.more===null?void 0:Number.isInteger(g.more)&&g.more>0?g.more:(o(`${b}'s "more" is ${JSON.stringify(g.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:b,i:f.length,name:b,mono:!0,focal:!!g.focal,col:c(g.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:_,columns:(g.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&o(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const g=A==="schema"?t.tables:t.nodes;s&&(g??[]).some(h=>h&&(h.col!==void 0||h.row!==void 0))&&o('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(T=!0);for(const h of f){const x=b?.[h.id];h.col=x?.col??1,h.row=h.row2=x?.row??1}}else t.layout==="auto"&&o(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((g,b)=>{if(!g||g.href===void 0||g.href===null)return;const h=String(g.href);if(A==="sequence"){o(`${f[b]?.id}: a participant cannot be a link (href)`);return}if(!h){o(`${f[b]?.id}'s href is empty`);return}const x=f[b];x&&(x.href=h,x.blank=g.target==="_blank")});const j=new Map;for(const g of f)g.id?j.has(g.id)&&o(`the id "${g.id}" is used twice`):o("a node has no id"),j.set(g.id,g);if(A==="schema")(t.tables??[]).forEach(g=>(g.columns??[]).forEach((b,h)=>{const x=at(b.references);if(!x)return;const[$,w]=x.split("."),_=j.get($??""),q=_?.columns?.findIndex(Q=>Q.name===w)??-1;if(!_||q<0){o(`${String(g.name)}.${String(b.name)} references ${x}, which is not a shown column`);return}const R=j.get(String(g.name??""));R.columns[h].ref={table:$,column:w,row:q},S.push({i:S.length,from:R.id,to:$,kind:"plain",fromRow:h,toRow:q,fk:!0})}));else if(A!=="sequence")for(const g of t.edges??[]){const b=String(g.from??""),h=String(g.to??"");if(!j.has(b)||!j.has(h)){o(`a line names ${j.has(b)?h:b}, which is not a node`);continue}const x=at(g.label),$=x?.split(` +`)??[];$.length>2&&o(`the label "${gt(x)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>Jt)&&o(`a line of the label "${gt(x)}" is over ${Jt} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:h,kind:m(g.kind,`the line from ${b} to ${h}`),label:x,fromSide:v(g.fromSide),toSide:v(g.toSide),flow:A!=="flowchart"&&g.flow===!0?!0:void 0})}else for(const g of E)"n"in g&&(!j.has(g.from)||!j.has(g.to))&&o(`message ${g.n} names ${j.has(g.from)?g.to:g.from}, which is not a participant`);if(s&&A!=="sequence"&&!T){const g=new Map;for(const b of f)for(let h=b.row;h<=b.row2;h++){const x=`${b.col}:${h}`;g.has(x)&&o(`${b.id} and ${g.get(x)} share the cell at column ${b.col}, row ${h}`),g.set(x,b.id)}}if(s&&!T){for(const b of C){const h=b.all.map(w=>j.get(w));if(!h.length)continue;const x={c1:Math.min(...h.map(w=>w.col)),c2:Math.max(...h.map(w=>w.col)),r1:Math.min(...h.map(w=>w.row)),r2:Math.max(...h.map(w=>w.row2))};for(const w of f)!b.all.includes(w.id)&&w.col>=x.c1&&w.col<=x.c2&&w.row>=x.r1&&w.row<=x.r2&&o(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=h.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&o(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of f)b.group&&!C.some(h=>h.id===b.group)&&o(`${b.id} names the group "${b.group}", which is not in groups`);f.filter(b=>b.focal).length>1&&o("more than one node is focal: a diagram has one at most");const g=new Set(A==="sequence"?E.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));g.has("main")&&!a.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),g.has("dashed")&&!a.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(b=>b.focal)&&!a.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const ot=A==="architecture"||A==="data-flow",L=g=>Array.isArray(g)&&g.length>1?g.map(String):void 0,F=ot&&t.packet&&typeof t.packet=="object"?t.packet:void 0,I=F&&L(F.path),M={animated:t.motion==="animated",pulse:ot?L(t.pulse):void 0,packet:I?{path:I,repeat:F.repeat===!0,send:F.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const g of f){const b=g.mark?.says;if(!b?.length)continue;const h=[g.name,g.kind,g.detail,g.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(x=>h.includes(x.toLowerCase()))||o(`${g.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const g=new Map,b=new Map;for(const h of E)"n"in h&&(b.set(h.from,h.n),b.set(h.to,h.n));for(const h of E)if("n"in h){if(h.activate){const x=g.get(h.to)??[];if(x.length>=3)o(`message ${h.n} opens a fourth bar on ${h.to}: three deep at most`);else{const $={who:h.to,from:h.n,to:h.n,depth:x.length+1};x.push($),O.push($),g.set(h.to,x)}}if(h.deactivate){const $=g.get(h.from)?.pop();$?$.to=h.n:o(`message ${h.n} closes a bar on ${h.from}, which has none open`)}}for(const[h,x]of g)for(const $ of x)$.to=Math.max($.from,b.get(h)??$.from)}const N=t.frameLabels??{},G={opt:at(N.opt)??"Only if",loop:at(N.loop)??"Repeats",alt:at(N.alt)??"One of these",else:at(N.else)??"Otherwise"};let W=Math.max(1,...f.map(g=>g.col));if(e.rtl){for(const b of f)b.col=W-b.col+1;const g=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=g(b.fromSide),b.toSide=g(b.toSide);for(const b of E)if("open"in b){const[h,x]=[W-b.b+1,W-b.a+1];b.a=h,b.b=x}W=Math.max(1,...f.map(b=>b.col))}const Y=A==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(g=>g.row2)),K={type:A,title:String(t.title??""),heading:l,legend:a,nodes:f,byId:j,edges:S,groups:C,lanes:B,steps:E,bars:O,frameWords:G,cols:W,rows:Y,shapeLabels:p,stepWord:u,warnings:i,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0};return t.layout==="auto"&&!T&&A!=="schema"&&ze(K),s&&f.length>1&&!It(K)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function ze(t){const e=new Set(t.nodes.map(r=>`${r.col},${r.row}`)),n=(r,a)=>{const d=[];for(let u=Math.min(r,a)+1;u<Math.max(r,a);u++)d.push(u);return d},s=r=>{const a=t.byId.get(r.from),d=t.byId.get(r.to),u=d.col>a.col?"right":"left",y=d.row>a.row?"bottom":"top",p=d.col>a.col?"left":"right",l=d.row>a.row?"top":"bottom",m=(c,f,S,B)=>n(c,f).map(C=>B?[C,S]:[S,C]);let v;return a.row===d.row?v=[{sides:[u,p],cells:m(a.col,d.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===d.col?v=[{sides:[y,l],cells:m(a.row,d.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:v=[{sides:[u,l],cells:[...m(a.col,d.col,a.row,!0),[d.col,a.row],...m(a.row,d.row,d.col,!1)]},{sides:[y,p],cells:[...m(a.row,d.row,a.col,!1),[a.col,d.row],...m(a.col,d.col,d.row,!0)]},{sides:[u,p],cells:m(a.col,d.col,a.row,!0)},{sides:[y,l],cells:m(a.row,d.row,a.col,!1)}],v.filter(c=>c.cells.every(([f,S])=>!e.has(`${f},${S}`)))},i=new Map,o=t.edges.map((r,a)=>a).sort((r,a)=>s(t.edges[r]).length-s(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[r].kind==="main")||r-a);for(const r of o){const a=t.edges[r];if(a.fromSide||a.toSide)continue;const d=s(a).find(u=>(i.get(`${a.from}.${u.sides[0]}`)??0)<3&&(i.get(`${a.to}.${u.sides[1]}`)??0)<3);if(d){for(const[u,y]of[[a.from,d.sides[0]],[a.to,d.sides[1]]])i.set(`${u}.${y}`,(i.get(`${u}.${y}`)??0)+1);a.fromSide=d.sides[0],a.toSide=d.sides[1]}}}function Bt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ut=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function $t(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Jt=28,Tt=t=>t.includes(` +`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Xt(t,e){return t.legend[e]}function Fe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function He(t,e){return $t(t,`sentence:${e.i}`,()=>De(t,e))}function De(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),i=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(r=>"n"in r&&r.from===e.id).length,i=t.steps.filter(r=>"n"in r&&r.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${i}.`);const o=Yt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Fe(t,e):e.kind;if(n.push(wt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const r=t.groups.find(d=>d.id===e.group),a=r?.parent?t.groups.find(d=>d.id===r.parent):void 0;r&&n.push(a?`In ${r.label}, in ${a.label}.`:`In ${r.label}.`)}const i=t.edges.filter(r=>r.to===e.id).map(r=>`${t.byId.get(r.from).name}${r.label?` (${gt(r.label)})`:""}`),o=t.edges.filter(r=>r.from===e.id).map(r=>`${t.byId.get(r.to).name}${r.label?` (${gt(r.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Yt(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function Ge(t,e,n,s){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const o=t.querySelector(`.${e}-drawing`),r=n.target;if(!o||!r||!o.contains(r)||!t.querySelector(`.${e}-edge`))return;const a=r.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===s?null:a.dataset.node??null:null}function Qt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&s.push(i);return{t,a:e??{},c:s}}var Ke={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>Ke[e]),Ve=" br img input meta link hr path polygon polyline circle rect line ";function Rt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=i===!0?` ${s}`:` ${s}="${it(String(i))}"`}return Ve.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Rt(s,e)).join("")}</${t.t}>`}var Ze=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Ue(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Lt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Pt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=Lt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,r)=>{o&&(e[r]=Math.max(e[r],te(t,n,r)))})}return e})}function te(t,e,n){const s=Lt(t,e);return t.groups.filter(r=>r.parent===e.id).some(r=>{const a=Lt(t,r);return a&&[a.r1===s.r1,a.c2===s.c2,a.r2===s.r2,a.c1===s.c1][n]})?2:1}function ee(t){const e=Pt(t);return e[1]+e[3]}function Wt(t){return t.type==="sequence"?t.nodes.length:t.cols}function ne(t){return $t(t,"plan",()=>Je(t))}function Je(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,S=t.byId.get(c.to).i,C=e.slice(Math.min(f,S)+1,Math.max(f,S)).every(E=>!n(E.i));return S===f+1&&!(n(f)&&!n(S))?"down":S===f-1?"up":S>f&&n(f)&&!n(S)&&C?"trunk":S>f&&n(f)&&n(S)&&C?"rail":S>f?"end-down":"end-up"}),i=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,S=t.byId.get(c.to).i;return[Math.min(f,S),Math.max(f,S)]},r=(c,f)=>{const[S,B]=o(c),[C,E]=o(f);return S<E&&C<B},a=i.every(({e:c})=>{const f=t.byId.get(c.from).i,[S,B]=o(c);return!n(f)&&e.slice(S+1,B).every(C=>!n(C.i))&&i.every(C=>C.e===c||!r(C.e,c))}),d=i.length>0&&(t.type==="data-flow"||!a),u=c=>{const[f,S]=o(c);return S-f},y=t.edges.map(()=>0);let p=!1;const l=[];for(const c of[...i].sort((f,S)=>u(f.e)-u(S.e)||f.k-S.k)){let f=0;for(const S of l)r(S.e,c.e)&&(f=Math.max(f,y[S.k]+1));y[c.k]=f,f>1&&(p=!0),l.push(c)}const m=t.edges.map(()=>.5);for(const c of e){const f=i.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const S=f.filter(({k:C})=>s[C]==="end-down").sort((C,E)=>u(E.e)-u(C.e)||C.k-E.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,E)=>u(C.e)-u(E.e)||E.k-C.k),...S].forEach(({k:C},E,A)=>{m[C]=A.length===2?E===0?1/3:2/3:(E+1)/(A.length+1)})}const v=ht();for(let c=1;c<e.length;c++){const f=e[c],S=e[c-1];let B=0,C=t.type==="data-flow"?48:32,E=!1,A=!1;t.edges.forEach((T,Z)=>{const j=s[Z],ot=t.byId.get(T.from).i,L=t.byId.get(T.to).i,F=L===c&&(j==="down"||j==="trunk"||j==="rail"||j==="end-down"),I=ot===c&&L===c-1&&j==="up",M=L===c-1&&j==="end-up";F&&(j==="trunk"||j==="end-down")&&(E=!0),M&&(A=!0),(F||I||M)&&T.label&&(B++,C=Math.max(C,j==="trunk"?40:48))}),(B>1||E&&A)&&(C=64),v[f.id]=C}return{routes:s,gutter:d,lanes:y,exits:m,gaps:v,third:p}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function oe(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,i=24,o=n==="dashed"?i-1:i-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${s-4}L${i} ${s}L${i-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${s}L${i-8} ${s-4}L${i-8} ${s+4}Z`}))}function St(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function se(t,e){return $t(e,`key:${t}`,()=>Ye(t,e))}var Xe=se;function Ye(t,e){const n=[],s=(o,r,a={})=>n.push(k("li",{class:`${t}-entry`,...a},o,k("span",null,r)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(r=>(r.columns??[]).map(a=>a.key)));for(const[r,a]of[["PK","Primary key"],["FK","Foreign key"]])o.has(r)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},r),k("span",null,a)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(r=>r.shape));o.has("terminal")&&s(St(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(St(t,"box"),e.shapeLabels.step),o.has("decision")&&s(St(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const r=e.legend[o];i.has(o)&&r&&s(oe(t,o),r,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(oe(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(r=>"open"in r?[r.open]:[]));for(const r of["opt","loop","alt"])o.has(r)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},r),k("span",null,e.frameWords[r])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(St(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(St(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Qe(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Nt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Pe(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},Nt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},Nt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?_t(n.detail).flatMap((i,o)=>[o?" ":"",k("span",{class:`${t}-run`},i)]):n.detail)),s}function tn(t,e,n){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},Nt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((s,i)=>k("span",{class:`${t}-row`,"data-row":i,"data-key":s.key},k("span",{class:`${t}-keyseat`},s.key??""),k("span",{class:`${t}-cname`},s.name),s.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?k("span",{class:`${t}-ctype`},s.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var ae=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function qt(t,e,n,s){const{P:i}=t,o=Ue(e,s)||s.keep===n.id,r=mt(e,s),a=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&a.push(`--_lc:${n.col+1}`),e.type==="sequence"&&a.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=yt(d.gaps,n.id)??32,m=yt(s.grow,n.id)??0;a.push(`--_gap:${m?`calc(${ae(l)} + var(--basalt-space-4) * ${m})`:ae(l)}`)}const u=yt(s.heights,n.id);u&&a.push(`--_h:${u}px`);const y=yt(s.words,n.id);y&&a.push(`--_ww:${y}px`);const p=r?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:a.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?He(e,n):void 0,tabindex:p},n.shape==="decision"?k("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ut(n.mark.onLight)};--_md:${Ut(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?tn(i,n,e):Pe(i,e,n))}function en(t,e,n){const{P:s}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=Lt(e,d);if(!u)continue;const y=[0,1,2,3].map(p=>te(e,d,p));i.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${y[0]>1?";--_gt:2":""}${y[1]>1?";--_ge:2":""}${y[2]>1?";--_gb:2":""}${y[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return i.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${d.col}`:void 0},qt(t,e,d,n))))),i.push(nn(t,e)),i;const o=d=>{const u=d.group?e.groups.find(y=>y.id===d.group):void 0;return u?.parent?e.groups.find(y=>y.id===u.parent):u},r=(d,u,y)=>{const p=t.plan?yt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:p?`--_ggrow:${p}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),y)};let a=0;for(;a<e.nodes.length;){const d=e.nodes[a],u=o(d);if(!u){i.push(qt(t,e,d,n)),a++;continue}const y=[];for(;a<e.nodes.length&&o(e.nodes[a])?.id===u.id;)y.push(e.nodes[a++]);const p=[];for(let l=0;l<y.length;){const m=y[l].group!==u.id?e.groups.find(c=>c.id===y[l].group):void 0;if(!m){p.push(qt(t,e,y[l],n)),l++;continue}const v=[];for(;l<y.length&&y[l].group===m.id;)v.push(y[l++]);p.push(r(m,v,v.map(c=>qt(t,e,c,n))))}i.push(r(u,y,p))}return i}function nn(t,e){const{P:n}=t,s=[],i=[],o=()=>i.length?i[i.length-1].el.c:s;let r=null;for(const a of e.steps){if("band"in a){r=null,o().push(k("p",{class:`${n}-band`},k("span",null,a.band)));continue}if("open"in a){r=null;const c=i[i.length-1],f=c?`;--_fis:${a.a===c.a?1:0};--_fie:${a.b===c.b?1:0}`:"",S=k("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));o().push(S),i.push({el:S,a:a.a,b:a.b});continue}if("otherwise"in a){r=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){r=null,i.pop();continue}r||(r=k("ol",{class:`${n}-msgs`,start:a.n}),o().push(r));const d=e.byId.get(a.from),u=e.byId.get(a.to),y=d?.col??1,p=u?.col??1,l=y===p,m=l&&(e.rtl?y!==1:y===e.nodes.length),v=Xt(e,a.kind);r.c.push(k("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":l?m?"start":"end":void 0,style:`--_a:${Math.min(y,p)};--_b:${Math.max(y,p)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(a.n)),k("span",{class:`${n}-mlabel`},a.label)),k("span",{class:`${n}-route`},d?.short??a.from," ",Qe(n,a.kind),k("span",{class:t.hidden}," to ")," ",u?.short??a.to,v?` · ${v}`:""),a.note?k("span",{class:`${n}-note`},a.note):null))}return k("div",{class:`${n}-steps`},s)}function re(t,e){return $t(e,`list:${t}`,()=>sn(t,e))}var on=re;function sn(t,e){const n=Math.min(6,e.heading+1),s=p=>k(`h${n}`,{class:`${t}-list-head`},p),i=p=>k("strong",null,p),o=p=>p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},i(p.name)):i(p.name),r=p=>k("code",{class:`${t}-code`},p),a=p=>e.byId.get(p)?.name??p,d=p=>{const l=Xt(e,p);return l?` (${l})`:""},u=p=>p.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const p=v=>k("li",null,o(v),v.kind?`, ${v.kind}`:"",v.detail?[". ",v.mono?r(v.detail):v.detail,/[.!?]$/.test(v.detail)?"":"."]:/[.!?]$/.test(v.kind??v.name)?"":".",u(v)),l=[s("Parts")],m=e.nodes.filter(v=>!v.group);m.length&&l.push(k("ul",{class:`${t}-list-items`},m.map(p)));for(const v of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},v.label)),v.members.length&&l.push(k("ul",{class:`${t}-list-items`},v.members.map(c=>p(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===v.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>p(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map(v=>k("li",null,i(a(v.from))," to ",i(a(v.to)),v.label?[": ",r(gt(v.label))]:"",`${d(v.kind)}.`)))),l}if(e.type==="flowchart"){const p=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const m=e.edges.filter(f=>f.from===l.id),v=l.shape==="decision"?"Decision":l.shape==="terminal"?m.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?r(l.detail):l.detail]:"",`${c}${v}.`,u(l),m.length?k("ul",{class:`${t}-list-exits`},m.map(f=>k("li",null,f.label?`If ${gt(f.label)}: go to ${p(f.to)}, `:`Then: go to ${p(f.to)}, `,i(a(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(p=>{const l=e.edges.filter(m=>m.from===p.id);return k("li",null,`${p.laneLabel}: `,o(p),p.detail?[", ",p.mono?r(p.detail):p.detail]:"",".",u(p),l.length?[" Then ",...l.flatMap((m,v)=>[v?"; ":"",`to step ${e.byId.get(m.to).step}, `,i(a(m.to)),m.label?[": ",r(gt(m.label))]:"",d(m.kind)]),"."]:"")}))];if(e.type==="sequence"){const p=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(m=>k("li",null,i(m.name),m.kind?`, ${m.kind}`:"",".",u(m),Yt(e,m))))];p.push(s("Messages"));let l=null;for(const m of e.steps){if("band"in m){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},m.band));continue}if("open"in m){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":m.depth>1?m.depth:void 0},`${e.frameWords[m.open]}: ${m.label}`));continue}if("otherwise"in m){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":m.depth>1?m.depth:void 0},`${e.frameWords.else}: ${m.otherwise}`));continue}if("close"in m){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:m.n}),p.push(l)),l.c.push(k("li",null,r(m.label),": ",i(a(m.from))," to ",i(a(m.to)),`${d(m.kind)}.`,m.note?` ${wt(m.note)}`:""))}return p}const y=[];for(const p of e.nodes)y.push(k(`h${n}`,{class:`${t}-list-group`},p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},r(p.name)):r(p.name),u(p))),y.push(k("ul",{class:`${t}-list-items`},[...(p.columns??[]).map(l=>k("li",null,r(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",r(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...p.more?[k("li",null,`and ${p.more} more ${p.more===1?"column":"columns"}`)]:[]]));return y}function ie(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&It(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function zt(t,e=!1){const n=e&&t.type!=="sequence"&&It(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Qt(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var an=(t,e)=>{for(let n=0;n<t.length;n++)if(t[n]!==e[n])return t[n]<e[n];return!1},rn=(t,e)=>({col:e.col,rows:[e.row,e.row2]});function It(t){return $t(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...rn(t,o)})),n=(o,r)=>{const a=r==="right"||r==="left",d=r==="right"||r==="down",u=v=>a?[v.col,v.col]:v.rows,y=v=>a?v.rows:[v.col,v.col],p=u(o),l=y(o);let m=null;return e.forEach((v,c)=>{if(v===o)return;const f=u(v),S=y(v),B=d?f[0]-p[1]:p[0]-f[1];if(B<1)return;const C=Math.max(0,S[0]-l[1],l[0]-S[1]),E=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(S[0]-l[0]),c];(!m||an(E,m.rank))&&(m={id:v.id,rank:E})}),m?.id??null},s=ht();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const i=o=>{const r=new Set([o]),a=[o];for(;a.length;)for(const d of Object.values(s[a.pop()]))d&&!r.has(d)&&(r.add(d),a.push(d));return r.size};return e.every(o=>i(o.id)===e.length)?s:null})}var le=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Ft(t,e,n){const s=n.prefix,i=Ze(n.base),o=t.type==="sequence"||t.type==="schema"?null:ne(t),r={P:s,ids:i,level:n.level,plan:o,hidden:n.hiddenClass},a=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?a:!0,y=`h${t.heading}`,p=[`--_cols:${Wt(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const l=t.type==="architecture"?Pt(t):[0,0,0,0],m=(c,f,S)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:S?`var(--basalt-space-${S})`:"0px",v=a&&e.pad?"3":void 0;p.push(`--_gpad:${m(l[0],"8",v)} ${m(l[1],"4")} ${m(l[2],"4",v)} ${m(l[3],"4")}`)}return le(t)&&p.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&p.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":i.title,"data-type":t.type,"data-cols":Wt(t),"data-reach":t.type==="architecture"?ee(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:p.join(";")},k("div",{class:`${s}-head`},k(y,{id:i.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?i.title:void 0,"aria-describedby":u?d?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":d?"":void 0},en(r,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),se(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?k("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${Qt(t)} to highlight its lines. Tap it again to clear.`):null,k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:i.list,class:`${s}-list`,hidden:!e.open},re(s,t)),k("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${ie(t,a)} ${n.viewer}`:ie(t,a)),k("figcaption",{id:i.summary,class:`${s}-summary`},{slot:"summary"}))}function ln(t){const e=getComputedStyle(t),n=(i,o)=>{const r=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(r)?r:o},s=new Map;return{space:i=>(s.has(i)||s.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),s.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ot=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.l<e.r-n&&t.r>e.l+n&&t.t<e.b-n&&t.b>e.t+n,ce=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:i,r:o,b:r}=t.rect,a=(s+o)/2,d=(i+r)/2,u=(o-s)/2,y=(r-i)/2,p=e==="top"||e==="bottom";if(t.shape==="decision"){if(p){const v=n,c=y*Math.max(0,1-Math.abs(v-a)/u);return{x:v,y:e==="top"?d-c:d+c}}const l=n,m=u*Math.max(0,1-Math.abs(l-d)/y);return{x:e==="left"?a-m:a+m,y:l}}if(t.shape==="terminal"){const l=Math.min(u,y);if(p){const f=n,S=Math.min(Math.max(f,s+l),o-l),B=f-S,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?i:r:e==="top"?d-C:d+C}}const m=n,v=m-d,c=Math.abs(v)>=l?0:Math.sqrt(l*l-v*v);return{x:e==="left"?s+l-c:o-l+c,y:m}}return p?{x:n,y:e==="top"?i:r}:{x:e==="left"?s:o,y:n}}function cn(t,e,n){const{l:s,t:i,r:o,b:r}=e.rect,a=(s+o)/2,d=(i+r)/2,u=(o-s)/2,y=(r-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/u+Math.abs(t.y-d)/y<1-n/Math.min(u,y);if(e.shape==="terminal"){const p=Math.min(u,y),l=Math.min(Math.max(t.x,s+p),o-p);return Math.hypot(t.x-l,t.y-d)<p-n}return t.x>s+n&&t.x<o-n&&t.y>i+n&&t.y<r-n}function de(t,e){if(!ut(t,e.rect))return!1;if(e.shape!=="decision"&&e.shape!=="terminal")return!0;const{l:n,t:s,r:i,b:o}=e.rect,r=(n+i)/2,a=(s+o)/2,d=(i-n)/2,u=(o-s)/2;if(e.shape==="decision"){const p=Math.max(t.l,Math.min(r,t.r)),l=Math.max(t.t,Math.min(a,t.b));return Math.abs(p-r)/d+Math.abs(l-a)/u<1-1e-6}const y=Math.min(u,d);if(ut(t,{l:n+y,r:i-y,t:s,b:o}))return!0;for(const p of[n+y,i-y]){const l=Math.max(t.l,Math.min(p,t.r)),m=Math.max(t.t,Math.min(a,t.b));if(Math.hypot(l-p,m-a)<y-.01)return!0}return!1}function dn(t,e,n){const s=Math.hypot(e.x-t.x,e.y-t.y),i=Math.max(2,Math.ceil(s/2));for(let o=1;o<i;o++){const r=o/i;if(!(r*s<1.5||(1-r)*s<1.5)&&cn({x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r},n,1))return!0}return!1}var fn=()=>matchMedia("(forced-colors: active)").matches;function un(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(i,o)=>{const r=`${o}|${i}`;return s.has(r)||(n.setAttribute("data-f",o),n.textContent=i,s.set(r,n.getBoundingClientRect().width),n.textContent=""),s.get(r)}}var _t=t=>t?t.split(/\s+/).filter(Boolean):[];function hn(t,e,n){const s=e.space;let i=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`${t.rtl?"←":"→"} ${c.ref.table}`:c.type??"",S=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(S))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),y=d.mark&&!fn()?(d.shape==="participant"?2:1)*s("6"):0;let p=0;const l=d.href?16+s("1-5"):0,m=_t(d.name);if(m.forEach((c,f)=>{p=Math.max(p,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:y)+(f===m.length-1?l:0))}),t.type!=="data-flow")for(const c of _t(d.kind))p=Math.max(p,n(c,"mono")+y);for(const c of _t(d.detail))p=Math.max(p,n(c,d.mono?"mono":"sans"));const v=d.shape==="decision"?p/.62:p+u+2*e.hair;i=Math.max(i,Math.ceil(v))}const r=Wt(t);let a;return t.type==="data-flow"?a=e.lane+r*(i+s("12")):t.type==="schema"?a=r*o+(r-1)*s("12")+(le(t)?s("5"):0):t.type==="sequence"?a=r*i+(r-1)*s("5"):a=r*i+(r-1)*s("16")+ee(t)*s("4"),{track:i,table:o,least:Math.max(e.wide,a)}}function fe(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Ht(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ue(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o<s.length;o++){const r=s[o-1],a=s[o];if(Math.abs(r.x-a.x)<.75){const d=n.x(r.x,e);r.x=d,a.x=d}else if(Math.abs(r.y-a.y)<.75){const d=n.y(r.y,e);r.y=d,a.y=d}}const i=[s[0]];for(let o=1;o<s.length;o++){const r=s[o],a=i[i.length-1];if(!(Math.abs(r.x-a.x)<.01&&Math.abs(r.y-a.y)<.01)){if(i.length>=2){const d=i[i.length-2];if(Math.abs(d.x-a.x)<.01&&Math.abs(a.x-r.x)<.01||Math.abs(d.y-a.y)<.01&&Math.abs(a.y-r.y)<.01){i[i.length-1]=r;continue}}i.push(r)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Ct(t,e,n){const s=[];for(let o=0;o<t.length;o++)for(let r=o+1;r<t.length;r++){const a=t[o],d=t[r];if(!(n&&!n.has(a.i)&&!n.has(d.i)))for(const[u,y]of pt(a.pts))for(const[p,l]of pt(d.pts)){const m=Math.abs(u.y-y.y)<.01,v=Math.abs(p.y-l.y)<.01;if(m===v)continue;const[c,f,S,B]=m?[u,y,p,l]:[p,l,u,y],C=S.x,E=c.y;if(C>Math.min(c.x,f.x)+.75&&C<Math.max(c.x,f.x)-.75&&E>Math.min(S.y,B.y)+.75&&E<Math.max(S.y,B.y)-.75){const A=m?o:r,T=m?r:o;let Z=A,j=T;if(e){const ot=e(t[A]);e(t[T])&&!ot&&(Z=T,j=A)}s.push({top:Z,under:j,at:{x:C,y:E},underVertical:j===T})}}}return s}function pn(t){const e=getComputedStyle(t),n=i=>i.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(i,o,r)=>{const a=[];let d=o;for(const u of i)a.push([d,d+u]),d+=u+r;return a};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var nt=t=>t==="left"||t==="right",he={top:"bottom",bottom:"top",left:"right",right:"left"};function gn(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function mn(t,e,n){const s=[];t.edges.forEach((o,r)=>{const a=t.byId.get(o.from),d=t.byId.get(o.to),[u,y]=e[r],p=a.row===d.row&&nt(u)&&nt(y)&&u===he[y]||a.col===d.col&&!nt(u)&&!nt(y)&&u===he[y];s.push({edge:r,end:"from",node:a,side:u,far:d,straight:p,f:.5},{edge:r,end:"to",node:d,side:y,far:a,straight:p,f:.5})});const i=new Map;for(const o of s){const r=`${o.node.id}.${o.side}`;i.has(r)||i.set(r,[]),i.get(r).push(o)}for(const[o,r]of i){if(r[0].node.shape==="decision")continue;const a=c=>nt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=r.filter(c=>c.straight),u=r.filter(c=>!c.straight);if(u.sort((c,f)=>a(c)-a(f)||(nt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(a(c)<0?1:-1)),r.length>3&&n(`${o.replace(".","'s ")} side has ${r.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const y=new Map;for(const c of d)y.has(c.far.id)||y.set(c.far.id,[]),y.get(c.far.id).push(c);for(const c of y.values())c.length>1&&c.sort((f,S)=>f.edge-S.edge).forEach((f,S)=>{f.f=c.length===2?S===0?.25:.75:(S+1)/(c.length+1)});const p=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),m=u.filter(c=>a(c)<0),v=u.filter(c=>a(c)>=0);m.forEach((c,f)=>{c.f=p*(f+1)/(m.length+1)}),v.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/(v.length+1)})}return s}function pe(t,e,n){const{l:s,t:i,r:o,b:r}=t.rect;return nt(e)?lt(t,e,i+(r-i)*n):lt(t,e,s+(o-s)*n)}function ge(t,e,n,s){const i=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const r=t.byId.get(o.dataset.node);r&&i.set(r.id,{id:r.id,rect:ft(o,n),shape:r.shape,i:r.i})}),i}function me(t,e){const n=e.head,s=e.head/2,{x:i,y:o}=t.tip;return t.dir==="down"?{l:i-s,r:i+s,t:o-n,b:o}:t.dir==="up"?{l:i-s,r:i+s,t:o,b:o+n}:t.dir==="right"?{l:i-n,r:i,t:o-s,b:o+s}:{l:i,r:i+n,t:o-s,b:o+s}}var ye=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function be(t,e,n,s){const i=(o,r)=>{const a=o+r-Math.floor(o+r);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const o of i(t.t,n))for(const r of i(t.l,e)){if(!r&&!o)return t;const a={l:t.l+r,r:t.r+r,t:t.t+o,b:t.b+o};if(s(a))return a}return t}function yn(t,e,n,s,i,o,r,a,d){const u=r.space,y=[],p=[],l=[],m=[],v=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-S.i);for(const f of c){const S=t.edges[f.i].label,B=a(S,"label"),C=16*Tt(S),E=f.pts.length-2,A=[];pt(f.pts).forEach(([L,F],I)=>{const M=Math.abs(L.y-F.y)<.01,O=M?L.x:L.y;let N=M?F.x:F.y;const G=Math.sign(N-O)||1;I===E&&(N-=G*r.head);let W=[[O,N]];for(const g of i)for(const b of M?[g.l,g.r]:[g.t,g.b]){const h=M?L.y:L.x;(M?h>g.t&&h<g.b:h>g.l&&h<g.r)&&(W=W.flatMap(([$,w])=>b>Math.min($,w)+1&&b<Math.max($,w)-1?[[$,b],[b,w]]:[[$,w]]))}const Y=(g,b)=>{const h=(g+b)/2,x=M?{x:h,y:L.y}:{x:L.x,y:h};return!i.some($=>x.x>$.l&&x.x<$.r&&x.y>$.t&&x.y<$.b)},K=f.axes?.[I]??(M?L.y:L.x);for(const[g,b]of W)A.push({horiz:M,c:K,p:g,q:b,len:Math.abs(b-g),pri:W.length>1&&Y(g,b)?1:0})}),A.sort((L,F)=>F.pri-L.pri||F.len-L.len);let T=null,Z=!1;const j=(L,F=!0)=>{const I=ce(L,v);return F&&(L.l<o.l||L.r>o.r||L.t<o.t||L.b>o.b)||n.some(M=>de(I,M))||y.some(M=>ut(I,M))||s.heads.some(M=>ut(I,M))||s.rects.some(M=>ut(I,M))?!1:!e.some(M=>M.i!==f.i&&pt(M.pts).some(([O,N])=>ut(I,ye(O,N,M.width))))};for(const L of A){for(const F of[1/2,1/3,2/3]){const I=L.p+(L.q-L.p)*F,M=[],O=u("2")+f.width/2;if(L.horiz?(L.len>=B+2*u("1")+u("3-5")&&M.push({box:{l:I-B/2-u("1"),r:I+B/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),M.push({box:{l:I-B/2,r:I+B/2,t:L.c-O-C,b:L.c-O},on:!1}),M.push({box:{l:I-B/2,r:I+B/2,t:L.c+O,b:L.c+O+C},on:!1})):(L.len>=C+u("3")&&M.push({box:{l:L.c-B/2-u("1"),r:L.c+B/2+u("1"),t:I-C/2,b:I+C/2},on:!0}),M.push({box:{l:L.c+O,r:L.c+O+B,t:I-C/2,b:I+C/2},on:!1}),M.push({box:{l:L.c-O-B,r:L.c-O,t:I-C/2,b:I+C/2},on:!1})),T=M.find(N=>j(N.box))??null,T)break;!Z&&M.some(N=>j(N.box,!1))&&(Z=!0)}if(T)break}if(!T){l.push(f.i),Z&&m.push(f.i);continue}const ot=be(T.box,d.ox,d.oy,L=>j(L));y.push(ot),p.push({i:f.i,text:S,box:ot,on:T.on})}return{labels:p,unseated:l,bounded:m}}function $e(t,e,n,s){const i=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(r=>{if(r.getClientRects().length===0||getComputedStyle(r).display==="contents")return;const a=ft(r,e);o.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const d=r.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&i.push(ft(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((r,a)=>{if(!r.getClientRects().length)return;const d=ft(r,e);a>0&&i.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=r.querySelector(`.${n}-lane-name`);u&&i.push(ft(u,e))}),{obstacles:{rects:i,heads:[]},groups:o}}function bn(t,e){const{m:s,tk:i,P:o,drawing:r,origin:a,warn:d}=t,u=i.space,y=ge(s,r,a,o),p=[...y.values()],l=pn(r),m=a.left-Math.floor(a.left),v=a.top-Math.floor(a.top),c=fe(m,v),f=r.clientWidth,S=r.clientHeight,B=h=>s.type==="data-flow"?h.col+1:h.col,C=parseFloat(getComputedStyle(r).rowGap)||0,E={w:f,h:S,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:m,oy:v};if(s.type==="sequence")return wn(t,E,c);let A,T=[];s.type==="schema"?A=s.edges.map(h=>{const x=s.byId.get(h.from),$=s.byId.get(h.to);if(x.col===$.col){const w=x.col===s.cols&&s.cols>1?"left":"right";return[w,w]}return $.col>x.col?["right","left"]:["left","right"]}):(A=s.edges.map(h=>{const x=s.byId.get(h.from),$=s.byId.get(h.to),[w,_]=gn(x,$);return[h.fromSide??w,h.toSide??_]}),T=mn(s,A,d||(()=>{})));const Z=(h,x)=>{const $=r.querySelector(`.${o}-node[data-node="${CSS.escape(h)}"] .${o}-row[data-row="${x}"]`);if(!$)return 0;const w=ft($,a);return(w.t+w.b)/2},j=s.edges.map((h,x)=>{const[$,w]=A[x],_=y.get(h.from),q=y.get(h.to),R=Ot(h.kind,i);if(h.fk){const V=Z(h.from,h.fromRow),P=Z(h.to,h.toRow),U=c.y(V,R),et=c.y(P,R);return{p1:{x:$==="right"?_.rect.r:_.rect.l,y:U},p2:{x:w==="right"?q.rect.r:q.rect.l,y:et},r1:V,r2:Math.abs(U-et)<.01?V:P}}const Q=T.find(V=>V.edge===x&&V.end==="from").f,X=T.find(V=>V.edge===x&&V.end==="to").f;let z=pe(_,$,Q),D=pe(q,w,X);const tt=nt($)?z.y:z.x;let st=nt(w)?D.y:D.x;return nt($)?z={...z,y:c.y(z.y,R)}:z={...z,x:c.x(z.x,R)},nt(w)?D={...D,y:c.y(D.y,R)}:D={...D,x:c.x(D.x,R)},nt($)&&nt(w)&&Math.abs(z.y-D.y)<1.01&&(D={...D,y:z.y},st=tt),!nt($)&&!nt(w)&&Math.abs(z.x-D.x)<1.01&&(D={...D,x:z.x},st=tt),z=nt($)?lt(_,$,z.y):lt(_,$,z.x),D=nt(w)?lt(q,w,D.y):lt(q,w,D.x),{p1:z,p2:D,r1:tt,r2:st}}),ot=new Set;s.type==="schema"&&s.edges.forEach((h,x)=>{Math.abs(s.byId.get(h.from).col-s.byId.get(h.to).col)>1&&ot.add(x)});const L=new Map,F=new Set;s.edges.forEach((h,x)=>{if(ot.has(x))return;const[$,w]=A[x],{p1:_,p2:q}=j[x],R=s.byId.get(h.from),Q=s.byId.get(h.to);let X=null,z=null,D=!1;if($===w){if(nt($)){const V=$==="right"?Math.max(B(R),B(Q)):Math.min(B(R),B(Q))-1,P=l.cols[V-1],U=l.cols[V];P&&U&&(X=`c${V}`,z=[P[1],U[0]],D=!0)}else{const V=$==="bottom"?Math.max(R.row2,Q.row2):Math.min(R.row,Q.row)-1,P=l.rows[V-1],U=l.rows[V];P&&U&&(X=`r${V}`,z=[P[1],U[0]],D=!1)}X&&F.add(x)}else if(nt($)&&nt(w)&&Math.abs(_.y-q.y)>.5){const V=B(Q),P=w==="left",U=l.cols[(P?V-1:V)-1],et=l.cols[(P?V:V+1)-1];U&&et&&(X=`c${P?V-1:V}`,z=[U[1],et[0]],D=!0)}else if(!nt($)&&!nt(w)&&Math.abs(_.x-q.x)>.5){const P=w==="top"?Q.row-1:Q.row2,U=l.rows[P-1],et=l.rows[P];U&&et&&(X=`r${P}`,z=[U[1],et[0]],D=!1)}if(!X||!z)return;L.has(X)||L.set(X,{span:z,vertical:D,members:new Map});const tt=`${h.to}.${w}.${Math.round(D?q.y:q.x)}`,st=L.get(X);st.members.has(tt)||st.members.set(tt,[]),st.members.get(tt).push(x)});const I=new Map,M=h=>{const[x,$]=A[h],{p1:w,p2:_}=j[h];if(nt(x)&&nt($)){if(x===$){const R=I.get(h)??(x==="right"?Math.max(w.x,_.x)+u("4"):Math.min(w.x,_.x)-u("4"));return[w,{x:R,y:w.y},{x:R,y:_.y},_]}if(Math.abs(w.y-_.y)<=.5)return[w,{x:_.x,y:w.y}];const q=I.get(h)??(w.x+_.x)/2;return[w,{x:q,y:w.y},{x:q,y:_.y},_]}if(!nt(x)&&!nt($)){if(x===$){const R=I.get(h)??(x==="bottom"?Math.max(w.y,_.y)+u("4"):Math.min(w.y,_.y)-u("4"));return[w,{x:w.x,y:R},{x:_.x,y:R},_]}if(Math.abs(w.x-_.x)<=.5)return[w,{x:w.x,y:_.y}];const q=I.get(h)??(w.y+_.y)/2;return[w,{x:w.x,y:q},{x:_.x,y:q},_]}return nt(x)?[w,{x:_.x,y:w.y},_]:[w,{x:w.x,y:_.y},_]},O=h=>{const x=s.edges[h],$=Ot(x.kind,i),w=M(h),_=ue(w,$,c);let q;return w.length===_.length&&(q=pt(w).map(([R,Q])=>Math.abs(R.y-Q.y)<.75?(R.y+Q.y)/2:(R.x+Q.x)/2),q[0]=j[h].r1,q.length>1&&(q[q.length-1]=j[h].r2)),{i:h,from:x.from,to:x.to,kind:x.kind,pts:_,tip:_[_.length-1],dir:Ht(_),dot:x.fk?_[0]:void 0,width:$,axes:q}},N=()=>s.edges.flatMap((h,x)=>ot.has(x)?[]:[O(x)]);let G=null;const W=h=>{G??(G=N());const x=G.map($=>h.has($.i)?O($.i):$);return{lines:x,score:$n(x,h)*1e5+Ct(x,void 0,h).length*1e3+Dt(x.filter($=>h.has($.i)),p,s).length}},Y=(h,x)=>{const $=h.flatMap(w=>{const{p1:_,p2:q}=j[w];return x?[_.y,q.y]:[_.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,h]of L){const x=[...h.members.values()].map(w=>({members:w,run:Y(w,h.vertical)})).sort((w,_)=>w.run[0]-_.run[0]),$=[];for(const w of x){const _=$[$.length-1];_&&_.some(q=>q.run[0]<w.run[1]+u("8")&&w.run[0]<q.run[1]+u("8"))?_.push(w):$.push([w])}for(const w of $){if(w.length===1&&w[0].members.every(tt=>F.has(tt)))continue;const _=w.map(tt=>tt.members),q=_.length,R=(h.span[1]-h.span[0])/(q+1);R<u("3")&&d?.(`a gutter holds ${q} lanes side by side, closer than space-3`);const Q=new Set(_.flat());let X=_,z=1/0,D=null;for(const tt of ve(_)){tt.forEach((V,P)=>V.forEach(U=>I.set(U,h.span[0]+R*(P+1))));const st=W(Q);st.score<z&&(z=st.score,X=tt,D=st.lines)}X.forEach((tt,st)=>tt.forEach(V=>I.set(V,h.span[0]+R*(st+1)))),G=D}}E.lines=N();for(const h of ot)d?.(`${s.edges[h].from} to ${s.edges[h].to} is two columns apart, so its line is not drawn; its row still writes the target`);E.crossings=Ct(E.lines),E.through=Dt(E.lines,p,s),E.outside=xe(E.lines,f,S,i);const{obstacles:K,groups:g}=$e(r,a,o,C);K.heads=E.lines.map(h=>me(h,i));const b=yn(s,E.lines,p,K,g,{l:0,t:0,r:f,b:S},i,e,{ox:m,oy:v});return E.labels=b.labels,E.unseated=b.unseated,E.bounded=b.bounded,E.overlaps=[...new Set(we(E.lines,null).flat())],E}function $n(t,e){return we(t,e).length}function we(t,e){const n=[];for(let s=0;s<t.length;s++)for(let i=s+1;i<t.length;i++){const o=t[s],r=t[i];if(e&&!e.has(o.i)&&!e.has(r.i)||o.to===r.to&&Math.abs(o.tip.x-r.tip.x)<1&&Math.abs(o.tip.y-r.tip.y)<1)continue;const a=(o.width+r.width)/2+.5;for(const[d,u]of pt(o.pts))for(const[y,p]of pt(r.pts)){const l=Math.abs(d.y-u.y)<.01,m=Math.abs(y.y-p.y)<.01;if(l!==m)continue;const[v,c]=l?[d.y,y.y]:[d.x,y.x];if(Math.abs(v-c)>=a)continue;const[f,S]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[y.x,p.x]:[y.y,p.y];Math.min(Math.max(f,S),Math.max(B,C))-Math.max(Math.min(f,S),Math.min(B,C))>1&&n.push([o.i,r.i])}}return n}function*ve(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e<t.length;e++){const n=t.slice(0,e).concat(t.slice(e+1));for(const s of ve(n))yield[t[e],...s]}}function xe(t,e,n,s){const i=[];for(const o of t)o.pts.some((r,a)=>{const d=a===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return r.x-d<-.5||r.x+d>e+.5||r.y-d<-.5||r.y+d>n+.5})&&i.push(o.i);return i}function Dt(t,e,n){const s=[];for(const i of t){const o=pt(i.pts);e.some(r=>o.some(([a,d])=>dn(a,d,r)))&&s.push(i.i)}return s}function wn(t,e,n){const{m:s,tk:i,P:o,drawing:r,origin:a}=t,d=i.space,u=new Map;r.querySelectorAll(`.${o}-node`).forEach(E=>u.set(E.dataset.node,ft(E,a)));const y=r.querySelector(`.${o}-steps`),p=y?ft(y,a).b:e.h,l=E=>{const A=u.get(E);return A?n.x((A.l+A.r)/2,i.hair):0};for(const E of s.nodes){const A=u.get(E.id);A&&e.lifelines.push({x:l(E.id),y1:A.b,y2:p})}const m=E=>u.get(E.id),v=new Map;r.querySelectorAll(`.${o}-msg`).forEach(E=>{const A=ft(E,a);v.set(Number(E.querySelector(`.${o}-num`)?.textContent??0),(A.t+A.b)/2)});const c=i.activation,f=c/2,S=E=>{const A=s.byId.get(E.who);if(!A)return null;const T=l(E.who),j=(A.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),ot=(E.depth-1)*d("1")*j,L=v.get(E.from)??0,F=v.get(E.to)??L,I=E.from===E.to;return{l:n.x(T-f+ot,i.hair),r:n.x(T+f+ot,i.hair),t:n.y(I?L-d("2")-d("1"):L,i.hair),b:n.y(I?L+d("2")+d("1"):F,i.hair)}},B=s.bars.map(E=>({bar:E,rect:S(E)})).filter(E=>E.rect);e.bars=B.map(E=>E.rect);const C=(E,A,T)=>B.filter(({bar:Z})=>Z.who===E&&Z.to>=A&&(T?Z.from<=A:Z.from<A||Z.from===A&&Z.to===A)).sort((Z,j)=>j.bar.depth-Z.bar.depth)[0]?.rect;return r.querySelectorAll(`.${o}-msg`).forEach(E=>{const A=E.dataset.from,T=E.dataset.to,Z=E.dataset.kind??"plain",j=Ot(Z,i),ot=ft(E,a),L=n.y((ot.t+ot.b)/2,j),F=Number(E.querySelector(`.${o}-num`)?.textContent??0);let I=l(A),M=l(T),O;if(A===T){const b=E.dataset.self==="start"?-d("6"):d("6"),h=C(A,F,!0),x=h?b>0?h.r:h.l:I,$=n.y(L-d("2"),j),w=n.y(L+d("2"),j);O=[{x,y:$},{x:n.x(I+b,j),y:$},{x:n.x(I+b,j),y:w},{x,y:w}]}else{const b=M>I?1:-1,h=C(A,F,!1),x=C(T,F,!0);h&&(I=b>0?h.r:h.l),x&&(M=b>0?x.l:x.r),O=[{x:I,y:L},{x:M,y:L}]}e.lines.push({i:F,from:A,to:T,kind:Z,pts:O,tip:O[O.length-1],dir:Ht(O),width:j});const N=E.querySelector(`.${o}-said`),G=E.querySelector(`.${o}-note`),W=s.byId.get(A),Y=s.byId.get(T);if(!W||!Y)return;const K=A===T?(()=>{const b=s.nodes[W.i+(E.dataset.self==="start"?-1:1)],h=b?l(b.id):E.dataset.self==="start"?0:e.w;return Math.abs(h-I)-d("6")-d("2-5")-d("2")})():Math.abs(M-I)-2*d("2");Math.max(N?N.getBoundingClientRect().width:0,G?G.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(F)}),r.querySelectorAll(`.${o}-fhead`).forEach(E=>{const A=E.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!A)return;[...E.children].reduce((Z,j)=>Z+j.getBoundingClientRect().width,0)+d("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${E.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ke(t,e,n,s=ht()){const{m:i,tk:o,P:r,drawing:a,origin:d}=t,u=o.space,y=ge(i,a,d,r),p=[...y.values()],l=d.left-Math.floor(d.left),m=d.top-Math.floor(d.top),v=fe(l,m),c=a.clientWidth,f=a.clientHeight,S={w:c,h:f,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:m},B=ht();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:B};const C=c-(parseFloat(getComputedStyle(a).paddingRight)||0),E=(M,O,N)=>{const G=[M];for(let W=1;W<=(yt(s,O)??0);W++)G.push({...M,t:M.t+N*u("4")*W,b:M.b+N*u("4")*W});return G},A=new Map;a.querySelectorAll(`.${r}-node`).forEach(M=>{const O=M.parentElement,N=ft(O,d),G=getComputedStyle(O);A.set(M.dataset.node,N.r-(parseFloat(G.paddingRight)||0)-(parseFloat(G.borderRightWidth)||0))});const T=i.nodes,Z=M=>y.get(T[M].id),j=[],ot=M=>Ot(i.edges[M].kind,o);i.edges.forEach((M,O)=>{const N=n.routes[O],G=y.get(M.from),W=y.get(M.to),Y=ot(O);let K=[];const g=M.label,b=g?e(g,"label"):0,h=g?16*Tt(g):16,x=u("4");if(N==="down"||N==="up"){const w=Math.max(G.rect.l,W.rect.l),_=Math.min(G.rect.r,W.rect.r),q=i.edges.map((z,D)=>({o:z,j:D})).filter(({o:z,j:D})=>(n.routes[D]==="down"||n.routes[D]==="up")&&(z.from===M.from&&z.to===M.to||z.from===M.to&&z.to===M.from)),R=q.findIndex(z=>z.j===O),Q=q.length<2?.5:q.length===2?R===0?.25:.75:(R+1)/(q.length+1),X=v.x(w+(_-w)*Q,Y);if(K=N==="down"?[lt(G,"bottom",X),lt(W,"top",X)]:[lt(G,"top",X),lt(W,"bottom",X)],g){let z=Math.min(K[0].y,K[1].y),D=Math.max(K[0].y,K[1].y);N==="down"?D-=o.head:z+=o.head;const tt=[...a.querySelectorAll(`.${r}-group`)].map(U=>ft(U,d));let st=[[z,D]];for(const U of tt)for(const et of[U.t,U.b])st=st.flatMap(([rt,ct])=>et>rt+1&&et<ct-1?[[rt,et],[et,ct]]:[[rt,ct]]);const V=(U,et)=>tt.some(rt=>(U+et)/2>rt.t&&(U+et)/2<rt.b&&X>rt.l&&X<rt.r);if(st.length>1){const U=st.filter(([rt,ct])=>!V(rt,ct));[z,D]=(U.length?U:st).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const P=[1/2,1/3,2/3].map(U=>{const et=z+(D-z)*U;return{l:X-b/2-u("1"),r:X+b/2+u("1"),t:et-h/2,b:et+h/2}});j.push({k:O,cands:P,on:!0,card:N==="down"?M.to:M.from})}}else if(N==="trunk"||N==="rail"){const w=v.x(Math.max(G.rect.l,N==="rail"?W.rect.l:G.rect.l)+u(N==="trunk"?"8":"3"),Y),_=lt(G,"bottom",w);if(N==="rail"){if(K=[_,lt(W,"top",w)],g){const q=W.rect.t-u("6");j.push({k:O,cands:E({l:w+u("2-5"),r:w+u("2-5")+b,t:q-h/2,b:q+h/2},M.to,-1),on:!1,card:M.to})}}else{const q=v.x(W.rect.l+u("6"),Y),R=v.y(W.rect.t-x,Y);K=[_,{x:w,y:R},{x:q,y:R},lt(W,"top",q)],g&&j.push({k:O,cands:E({l:q+u("2-5"),r:q+u("2-5")+b,t:R-h/2,b:R+h/2},M.to,-1),on:!1,card:M.to})}}else{const w=Math.min(A.get(M.from)??c,A.get(M.to)??c),_=v.x(n.gutter?C+(n.lanes[O]?2*u("3-5"):u("3-5")):w-u("2-5"),Y),q=v.y(G.rect.t+(G.rect.b-G.rect.t)*n.exits[O],Y),R=lt(G,"right",q),Q=v.x(W.rect.r-u("6"),Y),X=N==="end-down",z=v.y(X?W.rect.t-x:W.rect.b+x,Y);K=[R,{x:_,y:R.y},{x:_,y:z},{x:Q,y:z},lt(W,X?"top":"bottom",Q)];const D=X?M.to:T[W.i+1]?.id??M.to;g&&j.push({k:O,cands:E({l:Q-u("2-5")-b,r:Q-u("2-5"),t:z-h/2,b:z+h/2},D,X?-1:1),on:!1,card:D})}const $=ue(K,Y,v);S.lines.push({i:O,from:M.from,to:M.to,kind:M.kind,pts:$,tip:$[$.length-1],dir:Ht($),width:Y})}),S.crossings=Ct(S.lines),S.through=Dt(S.lines,p,i),S.outside=xe(S.lines,c,f,o);const{obstacles:L}=$e(a,d,r,0);L.heads=S.lines.map(M=>me(M,o));const F=[],I={l:0,t:0,r:c,b:f};for(const M of j){const O=W=>{const Y=ce(W,u("1"));return W.l<I.l-.5||W.r>I.r+.5||W.t<I.t-.5||W.b>I.b+.5||p.some(K=>de(Y,K))||F.some(K=>ut(Y,K))||L.heads.some(K=>ut(Y,K))||L.rects.some(K=>ut(Y,K))||S.lines.some(K=>K.i!==M.k&&pt(K.pts).some(([g,b])=>ut(Y,ye(g,b,K.width))))},N=M.cands.find(W=>!O(W));N||(B[M.card]=(B[M.card]??0)+1,S.unseated.push(M.k));const G=N?be(N,l,m,W=>!O(W)):M.cands[0];F.push(G),S.labels.push({i:M.k,text:i.edges[M.k].label,box:G,on:M.on})}return{geo:S,grow:B}}function vn(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o<t.length-1;o++){const r=t[o-1],a=t[o],d=t[o+1],u=Math.hypot(a.x-r.x,a.y-r.y),y=Math.hypot(d.x-a.x,d.y-a.y),p=Math.min(e,u/2,y/2);if(p<.5){s+=`L${n(a.x)} ${n(a.y)}`;continue}const l={x:a.x+(r.x-a.x)/u*p,y:a.y+(r.y-a.y)/u*p},m={x:a.x+(d.x-a.x)/y*p,y:a.y+(d.y-a.y)/y*p};s+=`L${n(l.x)} ${n(l.y)}Q${n(a.x)} ${n(a.y)} ${n(m.x)} ${n(m.y)}`}const i=t[t.length-1];return`${s}L${n(i.x)} ${n(i.y)}`}var xn={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function kn(t,e,n,s,i){const o=xn[e.dir],r=e.kind==="dashed",a=n.head,d=n.head/2,u=r?1:a-1,y=e.pts.map(E=>({...E})),p=y[y.length-1];p.x-=o.x*u,p.y-=o.y*u;const l=e.tip.x-o.x*a,m=e.tip.y-o.y*a,v=-o.y*d,c=o.x*d,f=E=>Math.round(E*100)/100,S=it(e.kind),B=r?`<path class="${t}-tip" data-kind="${S}" data-open="" d="M${f(l+v)} ${f(m+c)}L${f(e.tip.x)} ${f(e.tip.y)}L${f(l-v)} ${f(m-c)}"/>`:`<path class="${t}-tip" data-kind="${S}" d="M${f(e.tip.x)} ${f(e.tip.y)}L${f(l+v)} ${f(m+c)}L${f(l-v)} ${f(m-c)}Z"/>`,C=e.dot?`<circle class="${t}-dot" cx="${f(e.dot.x)}" cy="${f(e.dot.y)}" r="${n.dot/2}"/>`:"";return`<g class="${t}-edge" data-edge="${e.i}" data-from="${it(e.from)}" data-to="${it(e.to)}"><path class="${t}-line" data-kind="${S}" d="${vn(y,i)}"${s?` mask="url(#${it(s)})"`:""}/>${B}${C}</g>`}function Me(t,e,n,s){const i=new Map,o=new Map;for(const a of e.crossings)o.has(a.under)||o.set(a.under,[]),o.get(a.under).push(a);let r="";for(const[a,d]of o){const u=`${s}-cut-${a}`;i.set(a,u);const y=d.map(p=>{const l=e.lines[p.top],m=e.lines[p.under],v=l.width/2+n.cut,c=m.width/2+1;return p.underVertical?`<rect x="${p.at.x-c}" y="${p.at.y-v}" width="${2*c}" height="${2*v}" fill="black"/>`:`<rect x="${p.at.x-v}" y="${p.at.y-c}" width="${2*v}" height="${2*c}" fill="black"/>`}).join("");r+=`<mask id="${it(u)}" maskUnits="userSpaceOnUse" x="0" y="0" width="${e.w}" height="${e.h}"><rect x="0" y="0" width="${e.w}" height="${e.h}" fill="white"/>${y}</mask>`}return{defs:r,ids:i}}function Se(t,e,n,s){const{defs:i,ids:o}=Me(t,e,n,s),r=e.lifelines.map(y=>`<path class="${t}-life" d="M${y.x} ${y.y1}V${y.y2}"/>`).join("")+(e.bars??[]).map(y=>`<rect class="${t}-bar" x="${y.l}" y="${y.t}" width="${Math.round((y.r-y.l)*100)/100}" height="${Math.round((y.b-y.t)*100)/100}"/>`).join(""),a=e.lines.map((y,p)=>kn(t,y,n,o.get(p)??null,y.from===y.to?n.radiusXs:n.radius)).join(""),d=`<svg class="${t}-svg" width="${e.w}" height="${e.h}" viewBox="0 0 ${e.w} ${e.h}" focusable="false">${i?`<defs>${i}</defs>`:""}${r}<g class="${t}-edges">${a}</g></svg>`,u=e.labels.map(y=>`<span class="${t}-label" data-edge="${y.i}"${y.on?' data-on=""':""}${Tt(y.text)>1?' data-lines="2"':""} style="left:${Math.round(y.box.l*100)/100}px;top:${Math.round(y.box.t*100)/100}px;width:${Math.round((y.box.r-y.box.l)*100)/100}px">${y.text.split(` +`).map(it).join("<br>")}</span>`).join("");return d+u}function Gt(t,e,n,s,i,o,r,a){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const y=ln(t),p=un(u,n),l=hn(e,y,p);a?.(l.least);const m=t.clientWidth,v=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),c=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:v&&L.layout!=="drawn"?v:void 0};let f=!1;const S=L=>{if(f=!1,e.type!=="flowchart")return L;o({...L,heights:void 0,words:void 0});const F=ht(),I=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const O=M.querySelector(`.${n}-words`);if(!O)return;const N=M.getBoundingClientRect(),G=K=>{const g={w:K.width+2*y.space("2-5"),h:K.height+2*y.space("2")},b=1-g.w/N.width,h=b>.05?g.h/2/b:g.h*10;return Math.max(y.space("16"),Math.ceil(N.width/5),Math.ceil(2*h))},W=O.getBoundingClientRect();let Y=G(W);if(Y>N.width){const K=x=>(M.style.setProperty("--_ww",`${x}px`),O.getBoundingClientRect()),g=Math.floor(M.clientWidth-2*y.space("2-5"));let b=Math.ceil(W.width),h=W.height;for(;b<g&&K(g).height<h-.5;){let x=b,$=g;for(;$-x>1;){const q=x+$>>1;K(q).height<h-.5?$=q:x=q}const w=K($),_=G(w);if(_<=N.width){Y=_,I[M.dataset.node]=$;break}b=$,h=w.height}M.style.removeProperty("--_ww")}F[M.dataset.node]=Y,Y>N.width&&(f=!0)}),{...L,heights:F,words:Object.keys(I).length?I:void 0}},B=()=>({m:e,tk:y,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:r}),C=i.autoOpen?{open:!1,autoOpen:void 0}:{},E=(L,F)=>F.map(I=>Et(e,L.lines.find(M=>M.i===I))).join(", ");if(m>=l.least&&!e.unplaced){const L=O=>{let N=c({...i,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return N=S(N),o(N),{dd:N,g:bn(B(),p)}};let{dd:F,g:I}=L(!1);const M=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||f;if(!M(I)&&I.unseated.length&&I.unseated.every(O=>I.bounded?.includes(O))){const O=L(!0);!M(O.g)&&!O.g.unseated.length&&({dd:F,g:I}=O)}if(!M(I)&&!I.unseated.length)return I.crossings.length&&r?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(O=>`${Et(e,I.lines[O.top])} over ${Et(e,I.lines[O.under])}`).join("; ")}`),{dyn:F,geo:I,ink:Se(n,I,y,s),tokens:y,least:l.least};f&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: a decision would be taller than it is wide`),I.misfit?.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: ${I.misfit.join("; ")}`),I.through.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: ${E(I,I.through)} would pass through a node`),I.overlaps?.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: ${E(I,I.overlaps)} would lie on one another`),I.outside.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: ${E(I,I.outside)} would leave the drawing`),I.unseated.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: no clean seat for ${I.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=c({...i,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(A=S(A),o(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:y,least:l.least};const T=ne(e);let Z=ke(B(),p,T,A.grow);for(let L=0;L<6&&Object.keys(Z.grow).length;L++){const F=ht(A.grow);for(const[I,M]of Object.entries(Z.grow))F[I]=(yt(F,I)??0)+M;A={...A,grow:F},o(A),Z=ke(B(),p,T,F)}const j=Z.geo;if(j.unseated.length>0||j.through.length>0||j.outside.length>0||T.third){j.unseated.length&&r?.(`the stacked drawing has no clean seat for ${[...new Set(j.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),j.through.length&&r?.(`in the stacked drawing ${E(j,j.through)} would pass through a node, so its lines are not drawn`),j.outside.length&&r?.(`in the stacked drawing ${E(j,j.outside)} would leave the drawing, so its lines are not drawn`),T.third&&r?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={...j,lines:[],labels:[],crossings:[]};return{dyn:c({...A,grow:ht(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:y,least:l.least}}return j.crossings.length&&r?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${j.crossings.map(L=>`${Et(e,j.lines[L.top])} over ${Et(e,j.lines[L.under])}`).join("; ")}`),{dyn:A,geo:j,ink:Se(n,j,y,s),tokens:y,least:l.least}}function Et(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Mn(t,e,n,s,i,o){const r=new Set;if(o){r.add(o);for(const c of n?.lines??[])c.from===o&&r.add(c.to),c.to===o&&r.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",r.has(c.dataset.node))),!n||!s)return;const a=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",a(c)),f.toggleAttribute("data-dim",!!o&&!a(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(S=>String(S.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&a(f)))}),d){for(const c of n.lines)if(a(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const y=Ct(n.lines,a),{defs:p,ids:l}=Me(e,{...n,crossings:y},s,i),m=t.querySelector(`.${e}-svg`);if(!m)return;let v=m.querySelector("defs");!v&&p&&(v=document.createElementNS("http://www.w3.org/2000/svg","defs"),m.insertBefore(v,m.firstChild)),v&&(v.innerHTML=p),n.lines.forEach((c,f)=>{const S=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!S)return;const B=l.get(f);B?S.setAttribute("mask",`url(#${B})`):S.removeAttribute("mask")})}var Sn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function En(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Sn()||Ln(t)?"done":"pending")}}var An=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Ln(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(An(t))!==null}catch{return!1}}function Ee(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function qn(t,e,n,s=!1,i=!1){const o=s?It(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const r=t.byId.get(e)?.i??0,a=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=r+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=r-1;else if(n==="Home")d=0;else if(n==="End")d=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,d))].id}var In=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],Ae=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],On=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],Le=t=>t==null||t===!1;function _n(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Kt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?Ae:In;for(const r of s)Le(e.a[r])&&t.removeAttribute(r);for(const[r,a]of Object.entries(e.a)){if(r==="class")continue;if(r==="style"){const u=t.style,y=new Map(String(a??"").split(";").map(p=>{const l=p.indexOf(":");return[p.slice(0,l).trim(),p.slice(l+1).trim()]}).filter(([p])=>p));for(const[p,l]of y)u.getPropertyValue(p).trim()!==l&&u.setProperty(p,l);for(const p of On)y.has(p)||u.removeProperty(p);continue}if(n&&!Ae.includes(r))continue;if(Le(a)){t.removeAttribute(r);continue}const d=a===!0?"":String(a);t.getAttribute(r)!==d&&t.setAttribute(r,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(r=>typeof r!="string"&&"slot"in r))return;const i=[...t.children];let o=0;for(const r of e.c)if(!(typeof r=="string"||"slot"in r)){for(let a=o;a<i.length;a++)if(_n(i[a],r)){Kt(i[a],r,!1),o=a+1;break}}}function Cn(t,e,n,s){if(n===s)return;const i=o=>t.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function i(l,m,v){return{prefix:n,base:l,hasSource:m.source!==void 0&&m.source!==null&&m.source!=="",hiddenClass:"visually-hidden",viewer:v?v.keys:void 0}}function o(l,m,v,c){var f=function(S){return'<kbd class="kbd">'+it(S)+"</kbd>"};return{source:it(String(m.source||"")),summary:it(String(m.summary||"")),hint:zt(l).map(function(S){return"<span>"+S.keys.map(f).join(" ")+" "+it(S.words)+"</span>"}).join(""),toggle:'<button type="button" class="btn diagram-toggle" data-variant="secondary" data-size="sm" aria-expanded="'+(c?"true":"false")+'" aria-controls="'+it(v)+'-list"><span>'+(c?"Hide the list":"View as list")+"</span></button>"}}function r(l,m,v){var c=Mt(l),f=Ft(c,{},i(m,l,v)),S=Rt(f,o(c,l,m,!1)),B=S.indexOf(">");return{open:S.slice(0,B+1),inner:S.slice(B+1,S.length-9),warnings:c.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,m,v,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(l).direction==="rtl",B=m.layout==="auto"&&(m.type==="architecture"||m.type==="flowchart"||m.type==="schema"),C=B?Array.isArray(m.placement)?m.placement:m.placement?[m.placement]:[]:[];B&&!C.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var E=m.direction?[m.direction]:m.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var J=0;J<C.length;J++)if(C[J].direction===H)return C[J]},T=Mt(m,{rtl:S,placement:B?A(E[0]):void 0});if(!v||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var Z=r(m,f,c),j=document.createElement("div");j.innerHTML=Z.open+"</figure>";var ot=j.firstChild;a.forEach(function(H){l.removeAttribute(H)}),d.forEach(function(H){l.style.removeProperty(H)});for(var L=0;L<ot.attributes.length;L++){var F=ot.attributes[L];F.name==="class"?l.classList.add.apply(l.classList,F.value.split(" ")):F.name==="style"?l.style.cssText=F.value+";"+l.style.cssText:l.setAttribute(F.name,F.value)}l.querySelectorAll(":scope > :not(script[data-diagram])").forEach(function(H){H.remove()}),l.insertAdjacentHTML("beforeend",Z.inner)}T.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var I=i(f,m,c),M={},O=null,N=null,G=null,W=null,Y=Object.create(null),K=function(H){Y[H]||(Y[H]=1,console.warn("Basalt diagram: "+H))},g=function(H){Kt(l,Ft(T,H,I))},b=l.querySelector(".diagram-ink"),h=l.querySelector(".diagram-toggle"),x=!c&&T.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,_=function(){x&&Ee(l)};function q(){Mn(l,n,O&&O.geo,O&&O.tokens,f,N||W||G),X()}var R=null,Q=!c&&matchMedia("(hover: none), (pointer: coarse)").matches;function X(){var H=Q&&!c&&b&&b.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(Q&&!c)),H&&!R){var J=l.querySelector(":scope > .diagram-foot");if(!J)return;R=document.createElement("button"),R.type="button",R.className="btn diagram-clear",R.setAttribute("data-variant","secondary"),R.setAttribute("data-size","sm"),R.innerHTML="<span>Clear highlight</span>",R.addEventListener("click",function(){W&&(W=null,q())}),J.appendChild(R)}else!H&&R&&(R.remove(),R=null);R&&(W?R.removeAttribute("aria-disabled"):R.setAttribute("aria-disabled","true"))}function z(H){if(!H.defaultPrevented){var J=Ge(l,n,H,W);J!==void 0&&(_(),Q=!0,W=J,q())}}function D(){h&&(h.setAttribute("aria-expanded",String(!!M.open)),h.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function tt(){if(B&&C.length>1&&!c){for(var H=null,J=0;J<E.length&&!H;J++){var dt=A(E[J]);if(dt){var kt=Mt(m,{rtl:S,placement:dt}),Bn=Gt(l,kt,n,f,{},function(jt){Kt(l,Ft(kt,jt,I))});Bn.dyn.layout==="drawn"&&(H=kt)}}T=H||Mt(m,{rtl:S,placement:A(E[0])})}O=(c?c.measure:Gt)(l,T,n,f,M,g,K),M=O.dyn,g(M),D();var Zt=l.querySelector(":scope > .diagram-hint");if(Zt){var Be=zt(T,M.layout==="drawn").map(function(jt){return"<span>"+jt.keys.map(function(Tn){return'<kbd class="kbd">'+it(Tn)+"</kbd>"}).join(" ")+" "+it(jt.words)+"</span>"}).join("");Zt.innerHTML!==Be&&(Zt.innerHTML=Be)}mt(T,M)||(G=W=null);var Te=b&&O.ink!==w;Te&&(b.innerHTML=O.ink,w=O.ink),q(),x&&O.tokens&&(En(l,!!(O.geo&&O.geo.lines.length)),Te&&$&&$.redrawn()),c&&c.onMeasured&&O.tokens&&c.onMeasured(O,l)}function st(H){M=H,g(M)}function V(H){var J=M.stop;M=Object.assign({},M,{stop:H}),Cn(l,n,J,H)}var P=function(H){var J=H&&H.closest?H.closest(".diagram-node"):null;return J&&l.contains(J)?J:null};function U(H){var J=P(H.target);if(!(!J||H.defaultPrevented)){if(_(),H.key==="Escape"){!c&&(N||G||W)&&(H.preventDefault(),N=G=W=null,q());return}if(mt(T,M)){var dt=qn(T,J.getAttribute("data-node"),H.key,M.layout==="drawn");if(dt){H.preventDefault(),V(dt);var kt=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');kt&&kt.focus()}}}}function et(H){var J=P(H.target);if(J){_();var dt=J.getAttribute("data-node");N=J.matches(":focus-visible")?dt:null,mt(T,M)&&M.stop!==dt&&V(dt),q()}}function rt(H){var J=P(H.target);J&&(P(H.relatedTarget)||(N=null),M.keep===J.getAttribute("data-node")&&st(Object.assign({},M,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var J=P(H.target);J&&_();var dt=J&&mt(T,M)?J.getAttribute("data-node"):null;dt!==G&&(G=dt,q())}}function At(){G&&(G=null,q())}function bt(){_(),st(Object.assign({},M,{open:!M.open,autoOpen:void 0})),D()}l.addEventListener("keydown",U),l.addEventListener("focusin",et),l.addEventListener("focusout",rt),l.addEventListener("pointerover",ct),l.addEventListener("pointerleave",At),l.addEventListener("click",z),h&&h.addEventListener("click",bt),tt();var xt=l.clientWidth,Vt=0,qe=!0,Ie=new ResizeObserver(function(){Math.abs(l.clientWidth-xt)<.5||(xt=l.clientWidth,cancelAnimationFrame(Vt),Vt=requestAnimationFrame(tt))});Ie.observe(l),document.fonts&&document.fonts.ready.then(function(){qe&&tt()});var Oe=matchMedia("(forced-colors: active)"),_e=T.nodes.some(function(H){return H.mark});_e&&Oe.addEventListener("change",tt),x&&($=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return T},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},m));var Ce=!c&&m.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,m,{model:T,settle:_,animated:x}):null,je=l.querySelector(":scope > .diagram-foot"),jn=!c&&m.export===!0&&je&&typeof e.diagramExport=="function"?e.diagramExport(je,l):[];l.__diagram={stop:function(){Ce&&Ce.destroy(),jn.forEach(function(H){H.remove()}),qe=!1,Ie.disconnect(),cancelAnimationFrame(Vt),_e&&Oe.removeEventListener("change",tt),$&&$.destroy(),l.removeEventListener("keydown",U),l.removeEventListener("focusin",et),l.removeEventListener("focusout",rt),l.removeEventListener("pointerover",ct),l.removeEventListener("pointerleave",At),l.removeEventListener("click",z),R&&R.remove(),h&&h.removeEventListener("click",bt)},layout:tt,key:y(m),send:$&&$.sendValue?$.sendValue:null}}function y(l){try{return JSON.stringify(l,function(m,v){return m==="packet"&&v&&typeof v=="object"?Object.assign({},v,{send:void 0}):v})}catch{return null}}function p(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var m=l.querySelector(":scope > script[data-diagram]");if(m)try{u(l,JSON.parse(m.textContent),!0)}catch(v){console.error("Basalt diagram: this figure could not be drawn",v)}}})}e.diagramMarkup=r,e.diagramKit={draw:u,buildModel:Mt,figureKey:Xe,figureList:on,hintEntries:zt,toHtml:Rt,escapeHtml:it,settleEntrance:Ee,measureFigure:Gt},t.diagram=function(l,m){var v=l.__diagram,c=v&&v.send?y(m):null;if(c!==null&&c===v.key){v.send(m.packet?m.packet.send:void 0);return}u(l,m)},e.step(62,"wireDiagrams",p)})(window.Basalt)})(); diff --git a/dependencies.allowed.json b/dependencies.allowed.json index ba067917..419cf884 100644 --- a/dependencies.allowed.json +++ b/dependencies.allowed.json @@ -6,6 +6,7 @@ "@phosphor-icons/react": "The web icon set (foundations: Icons).", "@srasyndicate/basalt-tokens": "Basalt's own tokens.", "shiki": "CodeBlock syntax highlighting; loaded on demand, one grammar at a time.", + "elkjs": "Automatic diagram layout (`layout=\"auto\"`), loaded on demand through `diagram-layout` and never from the index. EPL-2.0 OR GPL-3.0-or-later; used under EPL-2.0, unmodified. The owner approved it (DECISIONS 301).", "react": "Peer: the host app's React.", "react-dom": "Peer: the host app's React DOM." }, diff --git a/package-lock.json b/package-lock.json index 9d420136..105e0bbf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3539,6 +3539,12 @@ "node": ">= 0.4" } }, + "node_modules/elkjs": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/elkjs/-/elkjs-0.12.1.tgz", + "integrity": "sha512-IhMYKHE4S2vtx0QrhBP3lYOIKDeIiJXBrdq9MGYkuB8ZHqhrBnHNfSUndjXFewrX1CPK8chwq+2NA0K0hliYuw==", + "license": "EPL-2.0 OR GPL-3.0-or-later" + }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -6338,6 +6344,7 @@ "@phosphor-icons/react": "2.1.10", "@srasyndicate/basalt-tokens": "0.1.0", "cmdk": "1.1.1", + "elkjs": "0.12.1", "shiki": "4.6.0" }, "devDependencies": { diff --git a/packages/react/build.mjs b/packages/react/build.mjs index f91a3a72..2405e48a 100644 --- a/packages/react/build.mjs +++ b/packages/react/build.mjs @@ -37,7 +37,7 @@ const packageDir = (name) => { // every file that entry shares with an ordinary import (utils, icon, kbd, Phosphor's icon base) is merged into one chunk // that the ordinary import then loads, whatever it needs: Spinner paid 12.7 KB for a 1 KB component, Skeleton 12 KB. // The panel is loaded on demand, so a second copy of those few files costs nothing until a menu opens. -const external = ["react", "react/*", "react-dom", "react-dom/*", "@base-ui/react", "@base-ui/react/*", "@phosphor-icons/react", "@phosphor-icons/react/*", "cmdk", "shiki", "shiki/*"]; +const external = ["react", "react/*", "react-dom", "react-dom/*", "@base-ui/react", "@base-ui/react/*", "@phosphor-icons/react", "@phosphor-icons/react/*", "cmdk", "shiki", "shiki/*", "elkjs", "elkjs/*"]; // The notice (without its comment marks) that the panel's banner carries and that the opt-in Phosphor plugin (src/tooling/phosphor.ts) puts // in front of the icons it trims. It is one string, so the two comments are identical and a bundler that holds both keeps one copy. const phosphorNotice = `Bundles four icons from @phosphor-icons/react.\n${fs.readFileSync(path.join(packageDir("@phosphor-icons/react"), "LICENSE"), "utf8").trim().replaceAll("*/", "* /")}`; @@ -163,7 +163,7 @@ await esbuild.build({ ...fs.readdirSync(path.join(here, "src", "tooling")).filter((f) => /\.ts$/.test(f)).map((f) => path.join(here, "src", "tooling", f)), ], define: { __PHOSPHOR_NOTICE__: JSON.stringify(phosphorNotice), __BASALT_ROOT_MAP__: JSON.stringify(JSON.stringify(rootMap)) }, - plugins: [{ name: "lazy-modules", setup(build) { build.onResolve({ filter: /^\.\/(command-panel|glyph-flight|diagram-motion|diagram-viewer)$/ }, (args) => (args.kind === "dynamic-import" ? { path: `${args.path}.js`, external: true } : undefined)); } }], + plugins: [{ name: "lazy-modules", setup(build) { build.onResolve({ filter: /^\.\/(command-panel|glyph-flight|diagram-motion|diagram-viewer|diagram-layout)$/ }, (args) => (args.kind === "dynamic-import" ? { path: `${args.path}.js`, external: true } : undefined)); } }], outdir: dist, bundle: true, splitting: true, diff --git a/packages/react/package.json b/packages/react/package.json index 964d5f2a..8e678ed1 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -62,6 +62,7 @@ "@phosphor-icons/react": "2.1.10", "@srasyndicate/basalt-tokens": "0.1.0", "cmdk": "1.1.1", + "elkjs": "0.12.1", "shiki": "4.6.0" }, "devDependencies": { diff --git a/packages/react/src/architecture-diagram.tsx b/packages/react/src/architecture-diagram.tsx index 14d5f987..1fbd235a 100644 --- a/packages/react/src/architecture-diagram.tsx +++ b/packages/react/src/architecture-diagram.tsx @@ -2,12 +2,22 @@ import * as React from "react"; import { DiagramFigure } from "./diagram-figure"; import type { DiagramFigureProps } from "./diagram-figure"; -import type { ArchitectureNode, DiagramFlowEdge, DiagramGroup, DiagramPacket } from "./diagram-core"; +import type { ArchitectureNode, DiagramFlowEdge, DiagramGroup, DiagramPacket, DiagramPlacement } from "./diagram-core"; export type { ArchitectureNode, DiagramEdge, DiagramFlowEdge, DiagramGroup, DiagramLegend, DiagramLineKind, DiagramMark, DiagramMotion, DiagramNode, DiagramPacket, DiagramSide } from "./diagram-core"; export type { DiagramFigureProps } from "./diagram-figure"; export interface ArchitectureDiagramProps extends DiagramFigureProps { + /** + * `"auto"` (DECISIONS 306, 1.8): elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one; a + * card's `col` and `row` are left out (and not read). Place at build time with `placeDiagram` from `@srasyndicate/basalt/diagram-layout` and pass + * `placement`: then elkjs never loads in the browser. Without it the layout module loads on demand at 640 or wider. + */ + layout?: "authored" | "auto"; + /** Under `"auto"`: the one direction tried. Left out, the type's own (right for an architecture and a schema, down for a flowchart), then the other. */ + direction?: "right" | "down"; + /** Under `"auto"`: `placeDiagram`'s answer for one direction or both. */ + placement?: DiagramPlacement | DiagramPlacement[]; /** The parts, in the author's order: the stacked order, the focus order and the list's. `col` and `row` place each in the drawn layout. */ nodes: ArchitectureNode[]; /** One level of grouping: `group: "aws"` on the members and `{ id, label }` here. The box is derived from its members. */ @@ -21,7 +31,7 @@ export interface ArchitectureDiagramProps extends DiagramFigureProps { } /** An architecture diagram (DECISIONS 281): nodes with a kind, a name and a detail, groups, and three kinds of line. */ -export function ArchitectureDiagram({ nodes, groups, edges, pulse, packet, motion, entrance, title, heading, legend, ...props }: ArchitectureDiagramProps) { - const spec = React.useMemo(() => ({ type: "architecture" as const, title, heading, legend, nodes, groups, edges, motion, entrance, pulse, packet }), [title, heading, legend, nodes, groups, edges, motion, entrance, pulse, packet]); +export function ArchitectureDiagram({ nodes, groups, edges, pulse, packet, motion, entrance, layout, direction, placement, title, heading, legend, ...props }: ArchitectureDiagramProps) { + const spec = React.useMemo(() => ({ type: "architecture" as const, title, heading, legend, nodes, groups, edges, motion, entrance, layout, direction, placement, pulse, packet }), [title, heading, legend, nodes, groups, edges, motion, entrance, layout, direction, placement, pulse, packet]); return <DiagramFigure {...props} entrance={entrance} title={title} heading={heading} legend={legend} spec={spec} component="ArchitectureDiagram" />; } diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index f354e2b5..f561012f 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -124,8 +124,15 @@ export interface DiagramSpec { entrance?: "always" | "first-visit"; /** A sequence drawn as text art (DECISIONS 306, 1.2). */ variant?: "drawn" | "text"; + /** Automatic layout (1.8): `"auto"` takes each card's column and row from `placement` (elkjs's, from `placeDiagram`), and a card's own are not read. */ + layout?: "authored" | "auto"; + direction?: "right" | "down"; + placement?: DiagramPlacement | DiagramPlacement[]; } +/** Where an automatic figure's cards go in one direction (1.8): `placeDiagram`'s answer. */ +export interface DiagramPlacement { direction: "right" | "down"; cells: Record<string, { col: number; row: number }> } + // ============================================================================================================================================ // The model // ============================================================================================================================================ @@ -208,6 +215,8 @@ export interface Model { memo: Map<string, unknown>; /** Mirrored for a right-to-left figure (1.7). */ rtl?: boolean; + /** An automatic figure with no placement yet (1.8): it is stacked, every word present, until one arrives. */ + unplaced?: boolean; } const SIDES: DiagramSide[] = ["top", "right", "bottom", "left"]; @@ -222,6 +231,8 @@ const record = <T>(from?: Record<string, T>): Record<string, T> => Object.assign const own = <T>(r: Record<string, T> | undefined, id: string): T | undefined => (r && Object.prototype.hasOwnProperty.call(r, id) ? r[id] : undefined); export interface BuildOptions { + /** The placement an automatic figure is drawn from (1.8), chosen by the figure from those it has. */ + placement?: DiagramPlacement; /** The figure's computed direction is right to left (DECISIONS 306, 1.7): the model is mirrored, so column 1 is drawn at the right and a named left or * right side swaps. The engine then lays out and routes as it does any figure; the words do not mirror. */ rtl?: boolean; @@ -262,6 +273,8 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model }; const trackOf = (v: unknown, what: string): number => { if (typeof v === "number" && Number.isInteger(v) && v >= 1) return v; + // An automatic figure's cards take the placement's tracks (1.8). + if (spec.layout === "auto" && (v === undefined || v === null)) return 1; dev && warn(`${what} is ${JSON.stringify(v)}, not a whole number from 1: it is placed at 1`); return 1; }; @@ -380,6 +393,15 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model } } + // Automatic layout (1.8): each card's column and row are the placement's; a card's own are not read (a development build says so once). + let unplaced = false; + if (spec.layout === "auto" && (type === "architecture" || type === "flowchart" || type === "schema")) { + const raw = (type === "schema" ? spec.tables : spec.nodes) as Array<{ col?: unknown; row?: unknown }> | undefined; + if (checks && (raw ?? []).some((n) => n && (n.col !== undefined || n.row !== undefined))) warn('a card under layout="auto" has a col or row, which is not read: there are no hints'); + const cells = options.placement?.cells; + if (!cells) unplaced = true; + for (const n of nodes) { const c = cells?.[n.id]; n.col = c?.col ?? 1; n.row = n.row2 = c?.row ?? 1; } + } else if (spec.layout === "auto") dev && warn(`layout="auto" is for an architecture, a flowchart or a schema, not a ${type}`); // Link cards (1.4): any card but a sequence's participant (its stacked chip has no room for a 44px target). const rawCards = (type === "schema" ? spec.tables : type === "sequence" ? spec.participants : spec.nodes) as Array<{ href?: unknown; target?: unknown }> | undefined; (rawCards ?? []).forEach((raw, k) => { @@ -427,7 +449,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model } // Placement checks (development only): two nodes in one cell, a non-member inside a group's box, more than one focal node. - if (checks && type !== "sequence") { + if (checks && type !== "sequence" && !unplaced) { const cells = new Map<string, string>(); for (const n of nodes) for (let r = n.row; r <= n.row2; r++) { const key = `${n.col}:${r}`; @@ -435,7 +457,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model cells.set(key, n.id); } } - if (checks) { + if (checks && !unplaced) { for (const g of groups) { const m = g.all.map((id) => byId.get(id)!); if (!m.length) continue; @@ -508,11 +530,51 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model cols = Math.max(1, ...nodes.map((n) => n.col)); } const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, ...nodes.map((n) => n.row2)); - const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined }; + const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined }; + if (spec.layout === "auto" && !unplaced && type !== "schema") chooseSides(model); if (checks && nodes.length > 1 && !spatialTable(model)) warn("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"); return model; } +/** + * An automatic figure's sides (1.8): nobody names one, so each line tries the router's shapes in order (sideways out and up or down in, up or down out + * and sideways in, then the two straight-on shapes; in one row or column the straight line, then a turn-back either side) and takes the first that + * passes through no card and puts no fourth line on a side. The line with the fewest clean shapes chooses first, then main lines, then the author's + * order. A side the author named is kept. + */ +function chooseSides(m: Model) { + const taken = new Set(m.nodes.map((n) => `${n.col},${n.row}`)); + const between = (p: number, q: number) => { const out: number[] = []; for (let k = Math.min(p, q) + 1; k < Math.max(p, q); k++) out.push(k); return out; }; + type Shape = { sides: [DiagramSide, DiagramSide]; cells: Array<[number, number]> }; + const shapes = (e: MEdge): Shape[] => { + const a = m.byId.get(e.from)!, b = m.byId.get(e.to)!; + const sx: DiagramSide = b.col > a.col ? "right" : "left", sy: DiagramSide = b.row > a.row ? "bottom" : "top"; + const ex: DiagramSide = b.col > a.col ? "left" : "right", ey: DiagramSide = b.row > a.row ? "top" : "bottom"; + const along = (lo: number, hi: number, at: number, horizontal: boolean) => between(lo, hi).map((k) => (horizontal ? [k, at] : [at, k]) as [number, number]); + let list: Shape[]; + if (a.row === b.row) list = [{ sides: [sx, ex], cells: along(a.col, b.col, a.row, true) }, { sides: ["bottom", "bottom"], cells: [] }, { sides: ["top", "top"], cells: [] }]; + else if (a.col === b.col) list = [{ sides: [sy, ey], cells: along(a.row, b.row, a.col, false) }, { sides: ["right", "right"], cells: [] }, { sides: ["left", "left"], cells: [] }]; + else list = [ + { sides: [sx, ey], cells: [...along(a.col, b.col, a.row, true), [b.col, a.row], ...along(a.row, b.row, b.col, false)] }, + { sides: [sy, ex], cells: [...along(a.row, b.row, a.col, false), [a.col, b.row], ...along(a.col, b.col, b.row, true)] }, + { sides: [sx, ex], cells: along(a.col, b.col, a.row, true) }, + { sides: [sy, ey], cells: along(a.row, b.row, a.col, false) }, + ]; + return list.filter((c) => c.cells.every(([x, y]) => !taken.has(`${x},${y}`))); + }; + const load = new Map<string, number>(); + const order = m.edges.map((_, k) => k).sort((p, q) => shapes(m.edges[p]!).length - shapes(m.edges[q]!).length || Number(m.edges[q]!.kind === "main") - Number(m.edges[p]!.kind === "main") || p - q); + for (const k of order) { + const e = m.edges[k]!; + if (e.fromSide || e.toSide) continue; + const ok = shapes(e).find((c) => (load.get(`${e.from}.${c.sides[0]}`) ?? 0) < 3 && (load.get(`${e.to}.${c.sides[1]}`) ?? 0) < 3); + if (!ok) continue; + for (const [id, side] of [[e.from, ok.sides[0]], [e.to, ok.sides[1]]] as const) load.set(`${id}.${side}`, (load.get(`${id}.${side}`) ?? 0) + 1); + e.fromSide = ok.sides[0]; + e.toSide = ok.sides[1]; + } +} + /** A card's mark from the author's data: a bundled id (a string), or `{ onLight, onDark }` (with the words a bundled one stands for, `says`). */ function markOf(v: unknown): MNode["mark"] { if (typeof v === "string") return v ? { id: v } : undefined; @@ -2360,7 +2422,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin // A list a bare stack opened closes when the figure is laid out again (it opens again if the stack is still bare). const closed: Dyn = current.autoOpen ? { open: false, autoOpen: undefined } : {}; const names = (geo: Geo, list: number[]) => list.map((k) => lineName(m, geo.lines.find((l) => l.i === k)!)).join(", "); - if (W >= mins.least) { + if (W >= mins.least && !m.unplaced) { const drawnTry = (pad: boolean) => { let dd = stopOf({ ...current, ...closed, layout: "drawn", grow: undefined, track: undefined, bare: undefined, pad: pad || undefined }); dd = heightsFor(dd); diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 4289701d..9901d083 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -6,7 +6,7 @@ import { inLevel, usePanelLevel } from "./layers"; import { applyTrace, buildModel, tapTrace, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, } from "./diagram-core"; -import type { DiagramLegend, DiagramMotion, DiagramSpec, Dyn, Measured, Model, VNode } from "./diagram-core"; +import type { DiagramLegend, DiagramMotion, DiagramPlacement, DiagramSpec, Dyn, Measured, Model, VNode } from "./diagram-core"; import type { MotionController } from "./diagram-motion-core"; type MotionModule = typeof import("./diagram-motion"); @@ -14,6 +14,11 @@ let motionLoading: Promise<MotionModule> | undefined; /** The motion code (DECISIONS 292, 2.6): a module of its own, loaded the first time a figure is animated, so a still figure never pays for it. */ const loadMotion = () => (motionLoading ??= import("./diagram-motion").catch((error) => { motionLoading = undefined; throw error; })); +type LayoutModule = typeof import("./diagram-layout"); +let layoutLoading: Promise<LayoutModule> | undefined; +/** Automatic layout (DECISIONS 306, 1.8): elkjs's module, loaded the first time an automatic figure with no placement is measured at 640 or wider. */ +const loadLayout = () => (layoutLoading ??= import("./diagram-layout").catch((error) => { layoutLoading = undefined; throw error; })); + type ViewerModule = typeof import("./diagram-viewer"); let viewerLoading: Promise<ViewerModule> | undefined; /** The viewer (DECISIONS 310, 9.13): a module of its own, with the Dialog it needs, loaded at the Expand button's first hover, focus or touch. */ @@ -121,7 +126,15 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // The development checks (placement, groups, the key's words) cost production nothing: a bundler that sets NODE_ENV drops them. // Right to left (DECISIONS 306, 1.7): no prop; the figure follows its computed direction, read as it is measured, and the model is mirrored. const [rtl, setRtl] = React.useState(false); - const model = React.useMemo(() => buildModel(spec, { checks: process.env.NODE_ENV !== "production", rtl }), [spec, rtl]); + // Automatic layout (1.8): the placements given or loaded, and the direction tried (the type's own, then the other, unless the author named one). + const auto = spec.layout === "auto" && (spec.type === "architecture" || spec.type === "flowchart" || spec.type === "schema"); + const given = React.useMemo(() => (spec.placement ? (Array.isArray(spec.placement) ? spec.placement : [spec.placement]) : []), [spec.placement]); + const [loaded, setLoaded] = React.useState<DiagramPlacement[] | null>(null); + const placements = given.length ? given : loaded ?? []; + const order = React.useMemo<Array<"right" | "down">>(() => (spec.direction ? [spec.direction] : spec.type === "flowchart" ? ["down", "right"] : ["right", "down"]), [spec.direction, spec.type]); + const [dirAt, setDirAt] = React.useState(0); + const placementFor = React.useCallback((k: number) => placements.find((p) => p.direction === order[k]), [placements, order]); + const model = React.useMemo(() => buildModel(spec, { checks: process.env.NODE_ENV !== "production", rtl, placement: auto ? placementFor(dirAt) : undefined }), [spec, rtl, auto, placementFor, dirAt]); const animated = model.motion.animated; const figRef = React.useRef<HTMLElement>(null); // The figure's own ref, which measuring reads, and the caller's, both set: a caller's ref never replaces the figure's. @@ -165,6 +178,26 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: if (!fig) return; const dirRtl = getComputedStyle(fig).direction === "rtl"; if (dirRtl !== rtl) { setRtl(dirRtl); return; } + // An automatic figure with no placement loads the layout module once it is measured at 640 or wider (never at a phone's width); until it answers, and + // if it fails, the figure is stacked with every word present. elk runs once a direction: a resize or the faces arriving never run it again. + if (auto && !given.length && !loaded && fig.clientWidth >= 640) { + const input = { type: spec.type as "architecture" | "flowchart" | "schema", nodes: spec.nodes as Array<{ id: string; group?: string }>, tables: spec.tables, edges: spec.edges, groups: spec.groups }; + loadLayout().then((mod) => Promise.all(order.map((d) => mod.placeDiagram(input, d)))).then((all) => setLoaded(all), (error: unknown) => { + if (process.env.NODE_ENV !== "production") warnOnce(component, `the automatic layout could not load (${String(error)}), so the figure is stacked`); + }); + } + // The direction: the first, in order, whose drawn layout fits at this width (each placement measured as it would be drawn); none fits, the first, stacked. + if (auto && placements.length > 1 && !viewer) { + let pick = 0; + for (let k = 0; k < order.length; k++) { + const place = placementFor(k); + if (!place) continue; + const trial = buildModel(spec, { rtl, placement: place }); + const t = measureFigure(fig, trial, P, base, {}, (d) => syncAttributes(fig, figureTree(trial, d, options))); + if (t.dyn.layout === "drawn") { pick = k; break; } + } + if (pick !== dirAt) { setDirAt(pick); return; } + } const warn = process.env.NODE_ENV !== "production" ? (message: string) => warnOnce(component, message) : undefined; const apply = (d: Dyn) => syncAttributes(fig, figureTree(model, d, options)); const result = (viewer ? viewer.measure : measureFigure)(fig, model, P, base, dynRef.current, apply, warn); @@ -177,7 +210,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: if (!hasStops(model, result.dyn)) { setHoverTrace(null); setTouchTrace(null); } // A figure hidden (the viewer's list is open) was not measured: the viewer keeps the drawing's size and place it had. if (viewer && result.tokens) viewer.onMeasured(result, fig); - }, [model, base, options, component, viewer, rtl]); + }, [model, base, options, component, viewer, rtl, auto, given, loaded, placements, order, placementFor, dirAt, spec]); // Measured before the first paint, then whenever the figure's width changes or the real faces arrive. React.useLayoutEffect(() => { diff --git a/packages/react/src/diagram-layout.ts b/packages/react/src/diagram-layout.ts new file mode 100644 index 00000000..ac499366 --- /dev/null +++ b/packages/react/src/diagram-layout.ts @@ -0,0 +1,90 @@ +// Automatic layout (DECISIONS 306, 1.8): `@srasyndicate/basalt/diagram-layout`, the one module that imports elkjs (EPL-2.0 OR GPL-3.0-or-later, used under +// EPL-2.0, unmodified). It gives each card a column and a row and nothing else: elk's routes, ports and group boxes are never read, and Basalt sizes, +// routes, seats and stacks the figure as it does an authored one. Lead with build time: an app or page that places at build time (and passes `placement`) +// ships none of elkjs. A figure without `placement` loads this module on demand, at 640 or wider, and never at a phone's width. Nothing runs at load. + +import type { DiagramEdge, DiagramGroup, DiagramPlacement, SchemaTable } from "./diagram-core"; + +/** What a figure is placed from: its type and the component's own props (cards, lines, groups). */ +export interface DiagramPlacementInput { + type: "architecture" | "flowchart" | "schema"; + nodes?: Array<{ id: string; group?: string }>; + tables?: SchemaTable[]; + edges?: DiagramEdge[]; + groups?: DiagramGroup[]; +} + +interface ElkNode { id: string; width?: number; height?: number; x?: number; y?: number; children?: ElkNode[]; layoutOptions?: Record<string, string>; edges?: Array<{ id: string; sources: string[]; targets: string[] }> } + +// Every card one box of one size (only the layer and the order are read, so the result never depends on a measured pixel), and one fixed set of options: +// layered, randomSeed 1, model order for nodes and edges, cycle breaking by model order, Brandes and Köpf placement. Partitioning is never switched on. +const W = 200, H = 80; +const options = (direction: "right" | "down"): Record<string, string> => ({ + "elk.algorithm": "layered", + "elk.direction": direction === "right" ? "RIGHT" : "DOWN", + "elk.randomSeed": "1", + "elk.hierarchyHandling": "INCLUDE_CHILDREN", + "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES", + "elk.layered.cycleBreaking.strategy": "MODEL_ORDER", + "elk.layered.nodePlacement.strategy": "BRANDES_KOEPF", + "elk.layered.spacing.nodeNodeBetweenLayers": "64", + "elk.spacing.nodeNode": "48", + "elk.edgeRouting": "ORTHOGONAL", +}); + +/** The graph handed to elk: cards in the author's order, groups as hierarchy, lines in the author's order. */ +export function elkGraph(input: DiagramPlacementInput, direction: "right" | "down"): ElkNode { + const cards = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name), group: undefined as string | undefined })) : (input.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); + const edges = input.type === "schema" + ? (input.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0]! }))) + : (input.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to) })); + const groups = input.type === "architecture" ? input.groups ?? [] : []; + const kids = new Map<string, ElkNode[]>([["", []]]); + for (const g of groups) kids.set(g.id, []); + for (const c of cards) (kids.get(c.group ?? "") ?? kids.get("")!).push({ id: c.id, width: W, height: H }); + const children = [...kids.get("")!]; + for (const g of groups) { + const box: ElkNode = { id: `group:${g.id}`, children: kids.get(g.id), layoutOptions: { "elk.padding": "[top=32,left=16,bottom=16,right=16]" } }; + (g.parent && kids.has(g.parent) ? kids.get(g.parent)! : children).push(box); + } + const ids = new Set(cards.map((c) => c.id)); + return { id: "root", layoutOptions: options(direction), children, edges: edges.filter((e) => ids.has(e.from) && ids.has(e.to)).map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to] })) }; +} + +/** Cards' boxes, absolute, from elk's result (a child's place is its parent's plus its own). */ +function absolute(node: ElkNode, ox = 0, oy = 0, out = new Map<string, { x: number; y: number; w: number; h: number }>()) { + for (const c of node.children ?? []) { + const x = ox + (c.x ?? 0), y = oy + (c.y ?? 0); + if (c.children) absolute(c, x, y, out); else out.set(c.id, { x, y, w: c.width ?? W, h: c.height ?? H }); + } + return out; +} +/** Bands along one axis: cards sorted by where they start; a card starts a new band when it begins at or after the band's earliest end. */ +function bands(rects: Map<string, { x: number; y: number; w: number; h: number }>, lo: (r: { x: number; y: number; w: number; h: number }) => number, hi: (r: { x: number; y: number; w: number; h: number }) => number) { + const ids = [...rects.keys()].sort((a, b) => lo(rects.get(a)!) - lo(rects.get(b)!) || (a < b ? -1 : a > b ? 1 : 0)); + const out = new Map<string, number>(); + let band = 0, end = Infinity; + for (const id of ids) { + const r = rects.get(id)!; + if (lo(r) >= end - 0.5) { band++; end = Infinity; } + end = Math.min(end, hi(r)); + out.set(id, band + 1); + } + return out; +} + +let elkMade: { layout: (graph: ElkNode) => Promise<ElkNode> } | undefined; + +/** Places a figure in one direction: each card's column and row. The same answer in Node and in a browser. */ +export async function placeDiagram(input: DiagramPlacementInput, direction: "right" | "down"): Promise<DiagramPlacement> { + if (!elkMade) { + const mod = (await import("elkjs/lib/elk.bundled.js")) as unknown as { default: new () => { layout: (graph: ElkNode) => Promise<ElkNode> } }; + elkMade = new mod.default(); + } + const laid = await elkMade.layout(elkGraph(input, direction)); + const rects = absolute(laid); + const col = bands(rects, (r) => r.x, (r) => r.x + r.w), row = bands(rects, (r) => r.y, (r) => r.y + r.h); + const cells: Record<string, { col: number; row: number }> = {}; + for (const id of rects.keys()) cells[id] = { col: col.get(id)!, row: row.get(id)! }; + return { direction, cells }; +} diff --git a/packages/react/src/flowchart-diagram.tsx b/packages/react/src/flowchart-diagram.tsx index b4a95b22..c9cf5544 100644 --- a/packages/react/src/flowchart-diagram.tsx +++ b/packages/react/src/flowchart-diagram.tsx @@ -2,11 +2,21 @@ import * as React from "react"; import { DiagramFigure } from "./diagram-figure"; import type { DiagramFigureProps } from "./diagram-figure"; -import type { DiagramEdge, DiagramShapeLabels, FlowchartNode } from "./diagram-core"; +import type { DiagramEdge, DiagramShapeLabels, FlowchartNode, DiagramPlacement } from "./diagram-core"; export type { DiagramEdge, DiagramLegend, DiagramLineKind, DiagramShapeLabels, DiagramSide, FlowchartNode } from "./diagram-core"; export interface FlowchartDiagramProps extends DiagramFigureProps { + /** + * `"auto"` (DECISIONS 306, 1.8): elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one; a + * card's `col` and `row` are left out (and not read). Place at build time with `placeDiagram` from `@srasyndicate/basalt/diagram-layout` and pass + * `placement`: then elkjs never loads in the browser. Without it the layout module loads on demand at 640 or wider. + */ + layout?: "authored" | "auto"; + /** Under `"auto"`: the one direction tried. Left out, the type's own (right for an architecture and a schema, down for a flowchart), then the other. */ + direction?: "right" | "down"; + /** Under `"auto"`: `placeDiagram`'s answer for one direction or both. */ + placement?: DiagramPlacement | DiagramPlacement[]; /** The steps in the author's order; the first is the start. A shape carries the type: a step (the default), a decision or a terminal. */ nodes: FlowchartNode[]; /** The lines, by node id. A branch's label is its condition; `main` is the usual path. */ @@ -16,7 +26,7 @@ export interface FlowchartDiagramProps extends DiagramFigureProps { } /** A flowchart (DECISIONS 281): shape carries type, so every shape has a 3:1 contour; a decision is a diamond behind its words. */ -export function FlowchartDiagram({ nodes, edges, shapeLabels, motion, entrance, title, heading, legend, ...props }: FlowchartDiagramProps) { - const spec = React.useMemo(() => ({ type: "flowchart" as const, title, heading, legend, nodes, edges, shapeLabels, motion, entrance }), [title, heading, legend, nodes, edges, shapeLabels, motion, entrance]); +export function FlowchartDiagram({ nodes, edges, shapeLabels, motion, entrance, layout, direction, placement, title, heading, legend, ...props }: FlowchartDiagramProps) { + const spec = React.useMemo(() => ({ type: "flowchart" as const, title, heading, legend, nodes, edges, shapeLabels, motion, entrance, layout, direction, placement }), [title, heading, legend, nodes, edges, shapeLabels, motion, entrance, layout, direction, placement]); return <DiagramFigure {...props} entrance={entrance} title={title} heading={heading} legend={legend} spec={spec} component="FlowchartDiagram" />; } diff --git a/packages/react/src/schema-diagram.tsx b/packages/react/src/schema-diagram.tsx index 834ec4c9..6231e4e8 100644 --- a/packages/react/src/schema-diagram.tsx +++ b/packages/react/src/schema-diagram.tsx @@ -2,11 +2,21 @@ import * as React from "react"; import { DiagramFigure } from "./diagram-figure"; import type { DiagramFigureProps } from "./diagram-figure"; -import type { SchemaTable } from "./diagram-core"; +import type { SchemaTable, DiagramPlacement } from "./diagram-core"; export type { DiagramLegend, SchemaColumn, SchemaTable } from "./diagram-core"; export interface SchemaDiagramProps extends DiagramFigureProps { + /** + * `"auto"` (DECISIONS 306, 1.8): elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one; a + * card's `col` and `row` are left out (and not read). Place at build time with `placeDiagram` from `@srasyndicate/basalt/diagram-layout` and pass + * `placement`: then elkjs never loads in the browser. Without it the layout module loads on demand at 640 or wider. + */ + layout?: "authored" | "auto"; + /** Under `"auto"`: the one direction tried. Left out, the type's own (right for an architecture and a schema, down for a flowchart), then the other. */ + direction?: "right" | "down"; + /** Under `"auto"`: `placeDiagram`'s answer for one direction or both. */ + placement?: DiagramPlacement | DiagramPlacement[]; /** * The tables in the author's order. A foreign key is `references: "incidents.id"` on its column and nothing else: the row's "→ incidents", * the line, the sentence and the list all come from it. The referenced column must be one of the shown columns. @@ -15,7 +25,7 @@ export interface SchemaDiagramProps extends DiagramFigureProps { } /** A database schema (DECISIONS 281): table cards with keys and a few columns; drawn, a line from each foreign key to the key it references. */ -export function SchemaDiagram({ tables, motion, entrance, title, heading, legend, ...props }: SchemaDiagramProps) { - const spec = React.useMemo(() => ({ type: "schema" as const, title, heading, legend, tables, motion, entrance }), [title, heading, legend, tables, motion, entrance]); +export function SchemaDiagram({ tables, motion, entrance, layout, direction, placement, title, heading, legend, ...props }: SchemaDiagramProps) { + const spec = React.useMemo(() => ({ type: "schema" as const, title, heading, legend, tables, motion, entrance, layout, direction, placement }), [title, heading, legend, tables, motion, entrance, layout, direction, placement]); return <DiagramFigure {...props} entrance={entrance} title={title} heading={heading} legend={legend} spec={spec} component="SchemaDiagram" />; } diff --git a/packages/react/test/fixtures/cimip-diagrams-b.json b/packages/react/test/fixtures/cimip-diagrams-b.json index 1c2ea07a..02efa777 100644 --- a/packages/react/test/fixtures/cimip-diagrams-b.json +++ b/packages/react/test/fixtures/cimip-diagrams-b.json @@ -897,5 +897,535 @@ ] } ] + }, + "autoArchitecture": { + "type": "architecture", + "title": "How a request reaches the agent (placed automatically)", + "source": "docs/architecture.md, \"The shape\"", + "summary": "Requests travel from the browser over HTTPS through the ALB to the cimip service. The service writes to Aurora PostgreSQL, puts sealed segments in S3, calls Bedrock for the scribe and has ECS start one agent sandbox per incident. It streams HTTP + SSE to the sandbox, which calls Bedrock for inference, sends its logs to CloudWatch and runs approved tools against production.", + "legend": { + "main": "Request path", + "plain": "Call", + "dashed": "Async or one-way", + "focal": "The service" + }, + "groups": [ + { + "id": "aws", + "label": "AWS · your account" + } + ], + "nodes": [ + { + "id": "browser", + "kind": "client", + "name": "Browser", + "detail": "Edge on iOS, Android" + }, + { + "id": "alb", + "kind": "load balancer", + "name": "ALB", + "detail": "OIDC sign-in · HTTP/2", + "detailMono": true, + "group": "aws" + }, + { + "id": "svc", + "kind": "ECS service", + "name": "cimip service", + "detail": "N tasks · stateless", + "detailMono": true, + "focal": true, + "group": "aws" + }, + { + "id": "aurora", + "kind": "database", + "name": "Aurora PostgreSQL", + "detail": "metadata · live window", + "detailMono": true, + "group": "aws", + "branch": true + }, + { + "id": "s3", + "kind": "object store", + "name": "S3", + "detail": "sealed segments · transcripts", + "detailMono": true, + "group": "aws", + "branch": true + }, + { + "id": "ecs", + "kind": "control plane", + "name": "ECS", + "detail": "RunTask · StopTask", + "detailMono": true, + "group": "aws", + "branch": true + }, + { + "id": "bedrock", + "kind": "model", + "name": "Bedrock", + "detail": "the scribe · the agent", + "group": "aws", + "branch": true + }, + { + "id": "agent", + "kind": "ECS task · one per incident", + "name": "Agent sandbox", + "detail": "private IP · :8080", + "detailMono": true, + "group": "aws" + }, + { + "id": "cw", + "kind": "logs", + "name": "CloudWatch", + "detail": "the agent's logs, traces", + "group": "aws", + "branch": true + }, + { + "id": "sys", + "kind": "your systems", + "name": "Production", + "detail": "read-only tools", + "group": "aws" + } + ], + "edges": [ + { + "from": "browser", + "to": "alb", + "kind": "main", + "label": "HTTPS" + }, + { + "from": "alb", + "to": "svc", + "kind": "main" + }, + { + "from": "svc", + "to": "aurora", + "label": "SQL · NOTIFY" + }, + { + "from": "svc", + "to": "s3", + "label": "PUT" + }, + { + "from": "svc", + "to": "ecs", + "label": "RunTask" + }, + { + "from": "svc", + "to": "bedrock", + "label": "scribe" + }, + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "HTTP + SSE" + }, + { + "from": "ecs", + "to": "agent", + "kind": "dashed", + "label": "starts" + }, + { + "from": "agent", + "to": "bedrock", + "label": "inference" + }, + { + "from": "agent", + "to": "cw", + "kind": "dashed", + "label": "logs" + }, + { + "from": "agent", + "to": "sys", + "label": "tools · approved actions" + } + ], + "layout": "auto" + }, + "autoFlowchart": { + "type": "flowchart", + "title": "Who may decide what the agent asks to run (placed automatically)", + "source": "docs/agent-contract.md and the approvals section of the architecture", + "summary": "When the agent asks to run a command, CIMIP sets the higher of the two risk levels, then checks the decider's role: observers cannot decide, commanders and deputies may always decide, responders may decide only at medium risk or lower, and the first recorded decision stands.", + "legend": { + "main": "Usual path", + "focal": "CIMIP's own step" + }, + "nodes": [ + { + "id": "req", + "shape": "terminal", + "name": "Agent asks to run a command", + "detail": "approval.requested", + "detailMono": true + }, + { + "id": "risk", + "name": "CIMIP sets the risk", + "detail": "higher of the agent's and its own", + "focal": true + }, + { + "id": "who", + "shape": "decision", + "name": "Who is deciding?" + }, + { + "id": "obs", + "shape": "terminal", + "name": "Can't decide", + "detail": "observers only read", + "branch": true + }, + { + "id": "med", + "shape": "decision", + "name": "Risk medium or lower?", + "branch": true + }, + { + "id": "wait", + "shape": "terminal", + "name": "Waits for the commander or deputy", + "branch": true + }, + { + "id": "may", + "name": "May decide", + "detail": "high risk asks twice" + }, + { + "id": "first", + "shape": "decision", + "name": "First decision?" + }, + { + "id": "told", + "shape": "terminal", + "name": "Told it was already decided", + "branch": true + }, + { + "id": "rec", + "shape": "terminal", + "name": "Recorded, then sent until acknowledged" + } + ], + "edges": [ + { + "from": "req", + "to": "risk", + "kind": "main" + }, + { + "from": "risk", + "to": "who", + "kind": "main" + }, + { + "from": "who", + "to": "obs", + "label": "observer" + }, + { + "from": "who", + "to": "med", + "label": "responder" + }, + { + "from": "who", + "to": "may", + "kind": "main", + "label": "commander or deputy" + }, + { + "from": "med", + "to": "wait", + "label": "no" + }, + { + "from": "med", + "to": "may", + "label": "yes" + }, + { + "from": "may", + "to": "first", + "kind": "main" + }, + { + "from": "first", + "to": "told", + "label": "no" + }, + { + "from": "first", + "to": "rec", + "kind": "main", + "label": "yes" + } + ], + "layout": "auto" + }, + "autoSchema": { + "type": "schema", + "title": "The tables an incident and its runs live in (placed automatically)", + "source": "server/db/schema.ts; each table shows its keys and a few columns", + "summary": "Eight PostgreSQL tables center on incidents: memberships, room_events, log_segments, sandboxes and agent_runs reference incidents.id; memberships and incidents reference users.id; agent_runs references sandboxes.id; and approvals references agent_runs.id.", + "legend": { + "plain": "A foreign key, to the key it references", + "focal": "The table most of the others reference" + }, + "tables": [ + { + "name": "memberships", + "more": 8, + "columns": [ + { + "name": "incident_id", + "key": "PK", + "references": "incidents.id" + }, + { + "name": "user_id", + "key": "PK", + "references": "users.id" + }, + { + "name": "role", + "type": "text" + }, + { + "name": "state", + "type": "text" + }, + { + "name": "deputy", + "type": "boolean" + } + ] + }, + { + "name": "room_events", + "more": 4, + "columns": [ + { + "name": "incident_id", + "key": "PK", + "references": "incidents.id" + }, + { + "name": "seq", + "key": "PK", + "type": "integer" + }, + { + "name": "channel", + "type": "room | bridge" + }, + { + "name": "body", + "type": "jsonb" + } + ] + }, + { + "name": "log_segments", + "more": 4, + "columns": [ + { + "name": "incident_id", + "key": "PK", + "references": "incidents.id" + }, + { + "name": "first_seq", + "key": "PK", + "type": "integer" + }, + { + "name": "key", + "type": "S3 key" + }, + { + "name": "sha256", + "type": "text" + } + ] + }, + { + "name": "incidents", + "focal": true, + "more": 10, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "number", + "type": "unique" + }, + { + "name": "title", + "type": "text" + }, + { + "name": "severity", + "type": "text" + }, + { + "name": "status", + "type": "text" + }, + { + "name": "commander_id", + "key": "FK", + "references": "users.id" + }, + { + "name": "last_seq", + "type": "integer" + }, + { + "name": "summary", + "type": "text" + } + ] + }, + { + "name": "users", + "more": 2, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "subject", + "type": "unique" + }, + { + "name": "name", + "type": "text" + }, + { + "name": "roles", + "type": "jsonb" + } + ] + }, + { + "name": "sandboxes", + "more": 5, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "incident_id", + "key": "FK", + "references": "incidents.id" + }, + { + "name": "state", + "type": "text" + }, + { + "name": "endpoint", + "type": "private IP" + } + ] + }, + { + "name": "agent_runs", + "more": 14, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "incident_id", + "key": "FK", + "references": "incidents.id" + }, + { + "name": "sandbox_id", + "key": "FK", + "references": "sandboxes.id" + }, + { + "name": "kind", + "type": "responder | ask" + }, + { + "name": "status", + "type": "text" + }, + { + "name": "agent_cursor", + "type": "integer" + }, + { + "name": "owner", + "type": "lease" + } + ] + }, + { + "name": "approvals", + "more": 8, + "columns": [ + { + "name": "id", + "key": "PK", + "type": "text" + }, + { + "name": "run_id", + "key": "FK", + "references": "agent_runs.id" + }, + { + "name": "command", + "type": "text" + }, + { + "name": "risk", + "type": "low | medium | high" + }, + { + "name": "status", + "type": "pending" + } + ] + } + ], + "layout": "auto" } } \ No newline at end of file diff --git a/tools/html-skill/build.mjs b/tools/html-skill/build.mjs index ce08e1a9..79bf303b 100644 --- a/tools/html-skill/build.mjs +++ b/tools/html-skill/build.mjs @@ -297,6 +297,8 @@ export function build() { const manifest = JSON.parse(src("modules.json")); const files = {}; files["compose.mjs"] = src("compose.mjs"); + // The placer compose.mjs runs for an automatic diagram (DECISIONS 306, 1.8): React's placeDiagram, with elkjs left to resolve from the repository. + files["parts/diagram-place.mjs"] = esbuild.buildSync({ entryPoints: [path.join(srcDir, "diagram-place.mjs")], bundle: true, format: "esm", platform: "node", target: "node20", write: false, logLevel: "silent", external: ["elkjs", "elkjs/*"] }).outputFiles[0].text; files["parts/manifest.json"] = `${JSON.stringify(manifest, null, 2)}\n`; files["parts/core.css"] = minifyCss(`${dedupeSystemDark(filterTokens(tokensCss(), inCore))}\n${src("core.css")}`); files["parts/core.js"] = minifyJs(src("core.js")); diff --git a/tools/html-skill/src/compose.mjs b/tools/html-skill/src/compose.mjs index 384add0e..92bf80a3 100644 --- a/tools/html-skill/src/compose.mjs +++ b/tools/html-skill/src/compose.mjs @@ -29,6 +29,7 @@ // file; PREFIX (aws, azure, gcp) keeps the ids that start with it. It reads parts/marks.json only, so the diagram usage need not list them. // // Source: tools/html-skill/src/compose.mjs (do not edit the copy in the skill folder). +import { execFileSync } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -647,6 +648,15 @@ function writeDiagrams(markup, held, parts, notes, marks) { try { spec = JSON.parse(item.inner); } catch (e) { notes.push(`a diagram's JSON does not parse (${e.message}); the page's script will say so`); continue; } // Each card's mark: a bundled id is checked and its rule written once; the page's own mark is read into the page and named by an id, so the JSON // the script reads carries the id and never a path. + // An automatic figure (DECISIONS 306, 1.8) is placed here, at build time, for both directions; the page holds the placement and never elkjs. + if (spec && spec.layout === "auto" && !spec.placement && ["architecture", "flowchart", "schema"].includes(spec.type)) { + try { + spec.placement = JSON.parse(execFileSync(process.execPath, [path.join(parts, "diagram-place.mjs")], { input: JSON.stringify(spec), encoding: "utf8" })); + const inner = `\n${JSON.stringify(spec).replace(/</g, "\\u003c")}\n`; + item.text = item.text.replace(item.inner, () => inner); + item.inner = inner; + } catch (e) { notes.push(`${spec.title ?? "a diagram"} could not be placed (${String(e.message).split("\n")[0]}); it is stacked`); } + } // An architecture's cards, a data flow's steps and a sequence's participants may carry one (DECISIONS 306, 1.6). const cards = spec && (spec.type === "architecture" || spec.type === "data-flow") ? spec.nodes : spec && spec.type === "sequence" ? spec.participants : null; if (Array.isArray(cards)) { diff --git a/tools/html-skill/src/diagram-place.mjs b/tools/html-skill/src/diagram-place.mjs new file mode 100644 index 00000000..8d154fd6 --- /dev/null +++ b/tools/html-skill/src/diagram-place.mjs @@ -0,0 +1,14 @@ +// compose.mjs's placer (DECISIONS 306, 1.8): reads a figure's JSON on stdin and writes its placement for both directions on stdout, through React's own +// placeDiagram (elkjs, a build-time dependency of the tool, resolved from the repository). A page never holds elkjs. Bundled into parts/ by build.mjs. +import { placeDiagram } from "../../../packages/react/src/diagram-layout.ts"; + +let input = ""; +process.stdin.setEncoding("utf8"); +process.stdin.on("data", (c) => { input += c; }); +process.stdin.on("end", async () => { + const spec = JSON.parse(input); + const directions = spec.direction ? [spec.direction] : spec.type === "flowchart" ? ["down", "right"] : ["right", "down"]; + const out = []; + for (const d of directions) out.push(await placeDiagram(spec, d)); + process.stdout.write(JSON.stringify(out)); +}); diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 94d5236a..7159dce3 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -47,7 +47,14 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, if (figure.__diagram) figure.__diagram.stop(); var base = (figure.getAttribute('aria-labelledby') || '').replace(/-title$/, '').replace(/[^A-Za-z0-9_-]/g, ''); // Right to left (DECISIONS 306, 1.7): the figure follows its computed direction, and the model is mirrored. - var model = buildModel(spec, { rtl: getComputedStyle(figure).direction === 'rtl' }); + var rtl = getComputedStyle(figure).direction === 'rtl'; + // Automatic layout (DECISIONS 306, 1.8): a page places at build time (compose.mjs writes `placement` for both directions); a page never holds elkjs. + var auto = spec.layout === 'auto' && (spec.type === 'architecture' || spec.type === 'flowchart' || spec.type === 'schema'); + var placements = auto ? (Array.isArray(spec.placement) ? spec.placement : spec.placement ? [spec.placement] : []) : []; + if (auto && !placements.length) console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked'); + var order = spec.direction ? [spec.direction] : spec.type === 'flowchart' ? ['down', 'right'] : ['right', 'down']; + var placeOf = function (d) { for (var i = 0; i < placements.length; i++) if (placements[i].direction === d) return placements[i]; return undefined; }; + var model = buildModel(spec, { rtl: rtl, placement: auto ? placeOf(order[0]) : undefined }); if (!attach || !base || !figure.querySelector(':scope > .diagram-drawing')) { // Keep the figure's base when it has ours, so its ids stay; otherwise take the next free one. if (!base || !figure.querySelector('#' + CSS.escape(base + '-title'))) { @@ -122,6 +129,18 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, toggle.firstElementChild.textContent = state.open ? 'Hide the list' : 'View as list'; } function layout() { + // An automatic figure: the first direction, in order, whose drawn layout fits at this width; none fits, the first, stacked. + if (auto && placements.length > 1 && !viewer) { + var chosen = null; + for (var k = 0; k < order.length && !chosen; k++) { + var place = placeOf(order[k]); + if (!place) continue; + var trial = buildModel(spec, { rtl: rtl, placement: place }); + var t = measureFigure(figure, trial, P, base, {}, function (d) { syncAttributes(figure, figureTree(trial, d, opts)); }); + if (t.dyn.layout === 'drawn') chosen = trial; + } + model = chosen || buildModel(spec, { rtl: rtl, placement: placeOf(order[0]) }); + } // The viewer's figure (DECISIONS 310, the diagram-zoom module) is laid out at the stage's width and measured only at 100%. measured = (viewer ? viewer.measure : measureFigure)(figure, model, P, base, state, apply, warn); state = measured.dyn; From 14d1ad119b84aa8c3cb435ab67ab51f40a3d0b02 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:12:13 -0600 Subject: [PATCH 22/62] A sequence as text art (DECISIONS 306, 1.2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit variant="text" draws the sequence's data as box-drawing characters in a code block (surface-sunken, the rim, radius 8, Mono text-xs), generated by a module of its own (diagram-text, loaded on demand; the skill's diagram-text module). The focal participant in a double-line box, lifelines and working stretches, ━━▶ ──▶ ┄┄▷ arrows, frames closed on four sides with the operator in primary, bands as ruled lines; no character over a word, and a copy is the art. Where its widest line does not fit, the block is the transcript, which the page holds before script: one line a message, frames as indented brackets, names never broken; nothing scrolls sideways. The pre is aria-hidden. The key's swatches are the art's glyphs. Under motion="animated" it builds by ink: labels and arrows lift in message order over duration-slower, no line hidden and no caret (on its first showing, not yet on coming into view). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- .agent/skills/basalt-html/SKILL.md | 1 + .../skills/basalt-html/parts/diagram-text.js | 2 + .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 16 +- .agent/skills/basalt-html/parts/manifest.json | 16 +- .../basalt-html/parts/usage/diagram-text.md | 6 + packages/react/build.mjs | 2 +- packages/react/src/diagram-core.ts | 43 ++++- packages/react/src/diagram-figure.tsx | 43 ++++- packages/react/src/diagram-text.ts | 166 ++++++++++++++++++ packages/react/src/styles/components.css | 31 ++++ .../react/test/fixtures/cimip-diagrams-b.json | 163 +++++++++++++++++ tools/html-skill/build.mjs | 2 +- tools/html-skill/src/modules.json | 16 +- tools/html-skill/src/modules/diagram-text.js | 32 ++++ tools/html-skill/src/modules/diagram.js | 2 + tools/html-skill/src/usage/diagram-text.md | 6 + 17 files changed, 527 insertions(+), 22 deletions(-) create mode 100644 .agent/skills/basalt-html/parts/diagram-text.js create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-text.md create mode 100644 packages/react/src/diagram-text.ts create mode 100644 tools/html-skill/src/modules/diagram-text.js create mode 100644 tools/html-skill/src/usage/diagram-text.md diff --git a/.agent/skills/basalt-html/SKILL.md b/.agent/skills/basalt-html/SKILL.md index 6cd6e4f7..7e6ae7c7 100644 --- a/.agent/skills/basalt-html/SKILL.md +++ b/.agent/skills/basalt-html/SKILL.md @@ -66,6 +66,7 @@ Markup built only at run time (a `.row` your script writes) won't be seen: add ` - **diagram-motion** `"motion": "animated"`: added for you, with `loops`; a flow line needs a label; one mover a figure. - **diagram-zoom** `.diagram`: added for you, with `dialog`; `"zoom": false` drops Expand. - **diagram-export** `"export": true`: added for you; "Download SVG" and "Download PNG" in the foot. +- **diagram-text** `"variant": "text"`: added for you; a sequence as box-drawing art, the transcript where it does not fit. - **sparkline** `.sparkline`: JSON in `script[data-sparkline]`; one line, no axes or series (that is a `chart`). - **palette** `data-open-palette`, `Basalt.init({ palette })`: `keys` is an array, `['⌘', 'S']`: ⌘, ⌃ or ⌥ plus one key. - **command-list** `.command-list`: the script builds it; items are the palette's; ⌘K goes to the palette when the page has one. diff --git a/.agent/skills/basalt-html/parts/diagram-text.js b/.agent/skills/basalt-html/parts/diagram-text.js new file mode 100644 index 00000000..d624dbe8 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-text.js @@ -0,0 +1,2 @@ +(()=>{var B={"&":"&","<":"<",">":">",'"':""","'":"'"},T=h=>h.replace(/[&<>"']/g,l=>B[l]);function F(h){const l=h.nodes,b=h.steps,c=t=>Array.from(t).length,m=l.map(t=>Math.max(8,c(t.name)+4)),i=l.map(()=>0);let S=0;l.forEach((t,n)=>{i[n]=S+Math.floor(m[n]/2),S+=m[n]+4});const k=(t,n,r)=>{const[s,p]=t<n?[t,n]:[n,t],f=r-(i[p]-i[s]);if(f>0)for(let u=p;u<l.length;u++)i[u]+=f};for(const t of b){if(!("n"in t))continue;const n=h.byId.get(t.from)?.i??0,r=h.byId.get(t.to)?.i??0,s=Math.max(c(`${t.n} ${t.label}`),c(t.note??""));n===r?n+1<l.length&&k(n,n+1,s+8):k(n,r,s+4)}const y=l.length-1,$=Math.max(0,...b.map(t=>"n"in t&&t.from===t.to&&(h.byId.get(t.from)?.i??0)===y?c(`${t.n} ${t.label}`)+8:0)),M=(i[y]??0)+Math.ceil((m[y]??8)/2)+$+2,x=[],d=()=>{const t={ch:Array(M).fill(" "),ink:Array(M).fill("")};return x.push(t),t},a=(t,n,r,s)=>{Array.from(r).forEach((p,f)=>{const u=n+f;u>=0&&u<M&&(t.ch[u]=p,t.ink[u]=s)})},q=(t,n)=>h.bars.some(r=>r.who===l[t].id&&r.from<=n&&r.to>=n);let L=0;const v=t=>l.forEach((n,r)=>a(t,i[r],q(r,L)?"┃":"│",q(r,L)?"working":"life")),V=d(),W=d(),R=d();l.forEach((t,n)=>{const r=i[n]-Math.floor(m[n]/2),s=m[n],[p,f,u,w,E,e]=t.focal?["╔","═","╗","║","╚","╝"]:["┌","─","┐","│","└","┘"],o=t.focal?"focal":"name";a(V,r,p+f.repeat(s-2)+u,o),a(W,r,w,o),a(W,r+s-1,w,o),a(W,r+Math.floor((s-c(t.name))/2),t.name,o),a(R,r,E+f.repeat(s-2)+e,o)});const j=[],_=t=>{for(const n of j)a(t,n.l,"│","frame"),a(t,n.r,"│","frame")},H=()=>{const t=d();return v(t),_(t),t};H();for(const t of b){if("band"in t){const e=d(),o=` ${t.band} `;a(e,0,"─".repeat(M),"band"),a(e,Math.max(0,Math.floor((M-c(o))/2)),o,"band"),H();continue}if("open"in t){const e=t.a-1,o=t.b-1,C=j.length*2,g={l:Math.max(0,i[e]-Math.floor(m[e]/2)-1+C),r:Math.min(M-1,i[o]+Math.ceil(m[o]/2)+(o===y&&b.some(I=>"n"in I&&I.from===I.to)?$:0)-C)},A=d();v(A),_(A),a(A,g.l,"┌"+"─".repeat(g.r-g.l-1)+"┐","frame"),a(A,g.l+1,`[${t.open}]`,"op"),a(A,g.l+c(t.open)+4,` ${t.label} `,"label"),j.push(g),H();continue}if("otherwise"in t){const e=j[j.length-1];if(!e)continue;const o=d();v(o),_(o),a(o,e.l,"├"+"┄".repeat(e.r-e.l-1)+"┤","frame"),a(o,e.l+1,"[else]","op"),a(o,e.l+8,` ${t.otherwise} `,"label"),H();continue}if("close"in t){const e=j.pop();if(!e)continue;const o=d();v(o),_(o),a(o,e.l,"└"+"─".repeat(e.r-e.l-1)+"┘","frame"),H();continue}L=t.n;const n=h.byId.get(t.from)?.i??0,r=h.byId.get(t.to)?.i??0,s=`${t.n} ${t.label}`,p=e=>e==="main"?"━":e==="dashed"?"┄":"─",f=(e,o)=>e==="dashed"?o?"▷":"◁":o?"▶":"◀",u=t.kind==="main"?"main":"plain",w=d(),E=d();if(w.n=t.n,E.n=t.n,v(w),_(w),v(E),_(E),n===r){const e=n===y&&l.length>1,o=e?i[n]-4:i[n]+1;a(w,o,e?"┌──":"──┐",u),a(E,o,e?"└─"+f(t.kind,!0):f(t.kind,!1)+"─┘",u);const C=e?o-c(s)-1:i[n]+5;if(a(w,C,s.slice(0,c(String(t.n))),"num"),a(w,C+c(String(t.n))+1,t.label,"label"),t.note){const g=d();v(g),_(g),a(g,e?o-c(t.note)-1:i[n]+5,t.note,"note")}}else{const e=Math.min(i[n],i[r]),o=Math.max(i[n],i[r]),C=i[r]>i[n],g=e+Math.max(2,Math.floor((o-e-c(s))/2));a(w,g-1," ",""),a(w,g,String(t.n),"num"),a(w,g+c(String(t.n))," "+t.label+" ","label");const A=p(t.kind).repeat(Math.max(1,o-e-2));if(a(E,e+1,C?A+f(t.kind,!0):f(t.kind,!1)+A,u),t.note){const I=d();v(I),_(I);const N=e+Math.max(2,Math.floor((o-e-c(t.note))/2));a(I,N-1,` ${t.note} `,"note")}}}return H(),{html:x.map(t=>{const n=t.ch.join("").trimEnd().length;let r="",s="",p=t.ink[0]??"";for(let f=0;f<n;f++)t.ink[f]!==p&&s&&(r+=p?`<span data-ink="${p}">${T(s)}</span>`:T(s),s=""),p=t.ink[f],s+=t.ch[f];return s&&(r+=p?`<span data-ink="${p}">${T(s)}</span>`:T(s)),t.n?`<span data-n="${t.n}">${r}</span>`:r}).join(` +`),width:Math.max(...x.map(t=>t.ch.join("").trimEnd().length))}}function P(h,l,b){if(matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held")return()=>{};const c=l>1?Math.min(b.step,(b.limit-b.slower)/(l-1)):0,m=[],i=getComputedStyle(h),S=i.getPropertyValue("--basalt-text-secondary").trim(),k=i.getPropertyValue("--basalt-text-tertiary").trim();return h.querySelectorAll("[data-n]").forEach(y=>{const $=Number(y.dataset.n);y.querySelectorAll('[data-ink="label"], [data-ink="main"], [data-ink="plain"]').forEach(M=>{const x=getComputedStyle(M).color,d=M.dataset.ink==="label"?S:k;m.push(M.animate([{color:d},{color:d,offset:.001},{color:x}],{duration:b.slower,delay:($-1)*c,easing:"ease-out",fill:"backwards"}))})}),()=>{for(const y of m)y.finish()}}(function(h){"use strict";h._.diagramText=function(l,b,c){var m=l.querySelector(".diagram-text"),i=m&&m.querySelector(".diagram-text-ink");if(i){l.__transcript||(l.__transcript=i.innerHTML);var S=F(b),k=document.createElement("span");k.textContent=new Array(41).join("─"),m.appendChild(k);var y=k.getBoundingClientRect().width/40;k.remove();var $=getComputedStyle(m),M=m.clientWidth-parseFloat($.paddingLeft)-parseFloat($.paddingRight),x=S.width*y<=M+.5,d=x?S.html:l.__transcript;if(i.innerHTML!==d&&(i.innerHTML=d),m.toggleAttribute("data-art",x),x&&c.motion==="animated"&&!l.__inked){l.__inked=!0;var a=function(q,L){return parseFloat($.getPropertyValue("--basalt-"+q))||L};P(i,b.steps.filter(function(q){return"n"in q}).length,{slower:a("duration-slower",300),step:a("duration-diagram-step",320),limit:a("duration-diagram-limit",5e3)})}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index c8511470..18886f6f 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index d29d5fd9..cc334f2e 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,6 +1,12 @@ -(()=>{var Re=["top","right","bottom","left"],We=["main","plain","dashed"],Ne=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Mt(t,e={}){const s=e.checks!==!1,i=[],o=g=>{i.push(g)},r=t.legend??{},a={};for(const g of["main","plain","dashed","focal","group","activation"]){const b=at(r[g]);b&&(a[g]=b)}const d=t.stepLabel,u=typeof d=="function"?g=>String(d(g)):typeof d=="string"?(g=>d.replace("{n}",String(g))):g=>`Step ${g}`,y=t.shapeLabels??{},p={terminal:at(y.terminal)??"Start or end",step:at(y.step)??"Step",decision:at(y.decision)??"Decision"},l=t.heading===void 0?3:Ne.includes(t.heading)?t.heading:(o(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),m=(g,b)=>g==null?"plain":We.includes(g)?g:(o(`"${String(g)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),v=g=>{if(g!=null){if(Re.includes(g))return g;o(`"${String(g)}" is not a side (top, right, bottom or left): the derived side is used`)}},c=(g,b)=>typeof g=="number"&&Number.isInteger(g)&&g>=1?g:(t.layout==="auto"&&g==null||o(`${b} is ${JSON.stringify(g)}, not a whole number from 1: it is placed at 1`),1),f=[],S=[];let B=[];const C=[],E=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||o(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const g of t.nodes??[]){const b=A==="flowchart"&&g.shape==="decision"?"decision":A==="flowchart"&&g.shape==="terminal"?"terminal":"box",h=String(g.id??""),x=c(g.row,`the row of ${h}`);f.push({id:h,i:f.length,name:String(g.name??""),kind:b==="decision"?void 0:at(g.kind),detail:b==="decision"?void 0:at(g.detail),mono:!!g.detailMono,focal:!!g.focal,col:c(g.col,`the column of ${h}`),row:x,row2:x,branch:!!g.branch,shape:b,group:A==="architecture"?at(g.group):void 0,mark:A==="architecture"?Bt(g.mark):void 0})}if(A==="architecture"){const g=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:at($.parent)})),b=new Map(g.map($=>[$.id,$])),h=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(o(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(o(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(o(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},x=g.map(h);g.forEach(($,w)=>C.push({...$,depth:x[w],members:f.filter(_=>_.group===$.id).map(_=>_.id),all:[]}));for(const $ of C)$.all=[...$.members,...C.filter(w=>w.parent===$.id).flatMap(w=>w.members)];C.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){B=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const g=new Map(B.map((b,h)=>[b.id,h+1]));for(const b of t.nodes??[]){const h=String(b.id??""),x=String(b.lane??""),$=g.get(x);$===void 0&&o(`a node (${h}) names the lane "${x}", which is not in lanes`);const w=f.length+1;f.push({id:h,i:f.length,name:String(b.name??""),kind:u(w),detail:at(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:c(b.col,`the column of ${h}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:B[($??1)-1]?.label??x,step:w,mark:Bt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((x,$)=>{const w=String(x.name??"");f.push({id:String(x.id??""),i:$,name:w,kind:at(x.kind),mono:!1,focal:!!x.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:at(x.short)??w,mark:Bt(x.mark)})});let g=0;const b=new Map(f.map(x=>[x.id,x.col])),h=(x,$)=>{let w=1/0,_=-1/0;for(const q of x??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&o(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),E.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){o("a frame is a third level: frames nest two deep");continue}const st=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=st==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];st==="alt"&&V.length<2&&o("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&o(`the frame label "${P}" is over 40 characters`);const U=E.length;E.push({open:st,label:P,depth:$+1,a:0,b:0}),V.forEach((et,rt)=>{if(rt){const xt=String(et.label??"");xt.length>40&&o(`the frame label "${xt}" is over 40 characters`),E.push({otherwise:xt,depth:$+1})}et.steps?.length||o(`a frame or branch ("${String(et.label??"")}") is empty`);const[ct,At]=h(et.steps??[],$+1);w=Math.min(w,ct),_=Math.max(_,At);const bt=E[U];bt.a=Math.min(bt.a||1/0,ct),bt.b=Math.max(bt.b,At)}),E.push({close:$+1});continue}g++;const R=String(q.label??"");R.includes(` -`)&&o(`message ${g}'s label has a break: a message's second line is its note`);const Q=String(q.from??""),X=String(q.to??"");E.push({n:g,from:Q,to:X,label:gt(R),note:at(q.note),kind:m(q.kind,`message ${g}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const z=b.get(Q)??1,D=b.get(X)??1,tt=z===D?z===f.length?z-1:z+1:z;w=Math.min(w,z,D,tt),_=Math.max(_,z,D,tt)}return[w,_]};h(t.steps??[],0);for(const x of E)"open"in x&&!Number.isFinite(x.a)&&(x.a=1,x.b=Math.max(1,f.length))}else if(A==="schema")for(const g of t.tables??[]){const b=String(g.name??""),[h,x]=Array.isArray(g.row)?g.row:[g.row,g.row],$=c(h,`the row of ${b}`),w=Math.max($,c(x,`the last row of ${b}`)),_=g.more===void 0||g.more===null?void 0:Number.isInteger(g.more)&&g.more>0?g.more:(o(`${b}'s "more" is ${JSON.stringify(g.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:b,i:f.length,name:b,mono:!0,focal:!!g.focal,col:c(g.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:_,columns:(g.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&o(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const g=A==="schema"?t.tables:t.nodes;s&&(g??[]).some(h=>h&&(h.col!==void 0||h.row!==void 0))&&o('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(T=!0);for(const h of f){const x=b?.[h.id];h.col=x?.col??1,h.row=h.row2=x?.row??1}}else t.layout==="auto"&&o(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((g,b)=>{if(!g||g.href===void 0||g.href===null)return;const h=String(g.href);if(A==="sequence"){o(`${f[b]?.id}: a participant cannot be a link (href)`);return}if(!h){o(`${f[b]?.id}'s href is empty`);return}const x=f[b];x&&(x.href=h,x.blank=g.target==="_blank")});const j=new Map;for(const g of f)g.id?j.has(g.id)&&o(`the id "${g.id}" is used twice`):o("a node has no id"),j.set(g.id,g);if(A==="schema")(t.tables??[]).forEach(g=>(g.columns??[]).forEach((b,h)=>{const x=at(b.references);if(!x)return;const[$,w]=x.split("."),_=j.get($??""),q=_?.columns?.findIndex(Q=>Q.name===w)??-1;if(!_||q<0){o(`${String(g.name)}.${String(b.name)} references ${x}, which is not a shown column`);return}const R=j.get(String(g.name??""));R.columns[h].ref={table:$,column:w,row:q},S.push({i:S.length,from:R.id,to:$,kind:"plain",fromRow:h,toRow:q,fk:!0})}));else if(A!=="sequence")for(const g of t.edges??[]){const b=String(g.from??""),h=String(g.to??"");if(!j.has(b)||!j.has(h)){o(`a line names ${j.has(b)?h:b}, which is not a node`);continue}const x=at(g.label),$=x?.split(` -`)??[];$.length>2&&o(`the label "${gt(x)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>Jt)&&o(`a line of the label "${gt(x)}" is over ${Jt} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:h,kind:m(g.kind,`the line from ${b} to ${h}`),label:x,fromSide:v(g.fromSide),toSide:v(g.toSide),flow:A!=="flowchart"&&g.flow===!0?!0:void 0})}else for(const g of E)"n"in g&&(!j.has(g.from)||!j.has(g.to))&&o(`message ${g.n} names ${j.has(g.from)?g.to:g.from}, which is not a participant`);if(s&&A!=="sequence"&&!T){const g=new Map;for(const b of f)for(let h=b.row;h<=b.row2;h++){const x=`${b.col}:${h}`;g.has(x)&&o(`${b.id} and ${g.get(x)} share the cell at column ${b.col}, row ${h}`),g.set(x,b.id)}}if(s&&!T){for(const b of C){const h=b.all.map(w=>j.get(w));if(!h.length)continue;const x={c1:Math.min(...h.map(w=>w.col)),c2:Math.max(...h.map(w=>w.col)),r1:Math.min(...h.map(w=>w.row)),r2:Math.max(...h.map(w=>w.row2))};for(const w of f)!b.all.includes(w.id)&&w.col>=x.c1&&w.col<=x.c2&&w.row>=x.r1&&w.row<=x.r2&&o(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=h.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&o(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of f)b.group&&!C.some(h=>h.id===b.group)&&o(`${b.id} names the group "${b.group}", which is not in groups`);f.filter(b=>b.focal).length>1&&o("more than one node is focal: a diagram has one at most");const g=new Set(A==="sequence"?E.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));g.has("main")&&!a.main&&o("main lines are drawn but the legend has no words for them (legend.main)"),g.has("dashed")&&!a.dashed&&o("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(b=>b.focal)&&!a.focal&&o("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const ot=A==="architecture"||A==="data-flow",L=g=>Array.isArray(g)&&g.length>1?g.map(String):void 0,F=ot&&t.packet&&typeof t.packet=="object"?t.packet:void 0,I=F&&L(F.path),M={animated:t.motion==="animated",pulse:ot?L(t.pulse):void 0,packet:I?{path:I,repeat:F.repeat===!0,send:F.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const g of f){const b=g.mark?.says;if(!b?.length)continue;const h=[g.name,g.kind,g.detail,g.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(x=>h.includes(x.toLowerCase()))||o(`${g.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const g=new Map,b=new Map;for(const h of E)"n"in h&&(b.set(h.from,h.n),b.set(h.to,h.n));for(const h of E)if("n"in h){if(h.activate){const x=g.get(h.to)??[];if(x.length>=3)o(`message ${h.n} opens a fourth bar on ${h.to}: three deep at most`);else{const $={who:h.to,from:h.n,to:h.n,depth:x.length+1};x.push($),O.push($),g.set(h.to,x)}}if(h.deactivate){const $=g.get(h.from)?.pop();$?$.to=h.n:o(`message ${h.n} closes a bar on ${h.from}, which has none open`)}}for(const[h,x]of g)for(const $ of x)$.to=Math.max($.from,b.get(h)??$.from)}const N=t.frameLabels??{},G={opt:at(N.opt)??"Only if",loop:at(N.loop)??"Repeats",alt:at(N.alt)??"One of these",else:at(N.else)??"Otherwise"};let W=Math.max(1,...f.map(g=>g.col));if(e.rtl){for(const b of f)b.col=W-b.col+1;const g=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=g(b.fromSide),b.toSide=g(b.toSide);for(const b of E)if("open"in b){const[h,x]=[W-b.b+1,W-b.a+1];b.a=h,b.b=x}W=Math.max(1,...f.map(b=>b.col))}const Y=A==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(g=>g.row2)),K={type:A,title:String(t.title??""),heading:l,legend:a,nodes:f,byId:j,edges:S,groups:C,lanes:B,steps:E,bars:O,frameWords:G,cols:W,rows:Y,shapeLabels:p,stepWord:u,warnings:i,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0};return t.layout==="auto"&&!T&&A!=="schema"&&ze(K),s&&f.length>1&&!It(K)&&o("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function ze(t){const e=new Set(t.nodes.map(r=>`${r.col},${r.row}`)),n=(r,a)=>{const d=[];for(let u=Math.min(r,a)+1;u<Math.max(r,a);u++)d.push(u);return d},s=r=>{const a=t.byId.get(r.from),d=t.byId.get(r.to),u=d.col>a.col?"right":"left",y=d.row>a.row?"bottom":"top",p=d.col>a.col?"left":"right",l=d.row>a.row?"top":"bottom",m=(c,f,S,B)=>n(c,f).map(C=>B?[C,S]:[S,C]);let v;return a.row===d.row?v=[{sides:[u,p],cells:m(a.col,d.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===d.col?v=[{sides:[y,l],cells:m(a.row,d.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:v=[{sides:[u,l],cells:[...m(a.col,d.col,a.row,!0),[d.col,a.row],...m(a.row,d.row,d.col,!1)]},{sides:[y,p],cells:[...m(a.row,d.row,a.col,!1),[a.col,d.row],...m(a.col,d.col,d.row,!0)]},{sides:[u,p],cells:m(a.col,d.col,a.row,!0)},{sides:[y,l],cells:m(a.row,d.row,a.col,!1)}],v.filter(c=>c.cells.every(([f,S])=>!e.has(`${f},${S}`)))},i=new Map,o=t.edges.map((r,a)=>a).sort((r,a)=>s(t.edges[r]).length-s(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[r].kind==="main")||r-a);for(const r of o){const a=t.edges[r];if(a.fromSide||a.toSide)continue;const d=s(a).find(u=>(i.get(`${a.from}.${u.sides[0]}`)??0)<3&&(i.get(`${a.to}.${u.sides[1]}`)??0)<3);if(d){for(const[u,y]of[[a.from,d.sides[0]],[a.to,d.sides[1]]])i.set(`${u}.${y}`,(i.get(`${u}.${y}`)??0)+1);a.fromSide=d.sides[0],a.toSide=d.sides[1]}}}function Bt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ut=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +(()=>{var Re=["top","right","bottom","left"],We=["main","plain","dashed"],Ne=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Mt(t,e={}){const a=e.checks!==!1,i=[],r=m=>{i.push(m)},o=t.legend??{},s={};for(const m of["main","plain","dashed","focal","group","activation"]){const b=at(o[m]);b&&(s[m]=b)}const c=t.stepLabel,u=typeof c=="function"?m=>String(c(m)):typeof c=="string"?(m=>c.replace("{n}",String(m))):m=>`Step ${m}`,y=t.shapeLabels??{},p={terminal:at(y.terminal)??"Start or end",step:at(y.step)??"Step",decision:at(y.decision)??"Decision"},l=t.heading===void 0?3:Ne.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),g=(m,b)=>m==null?"plain":We.includes(m)?m:(r(`"${String(m)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),x=m=>{if(m!=null){if(Re.includes(m))return m;r(`"${String(m)}" is not a side (top, right, bottom or left): the derived side is used`)}},d=(m,b)=>typeof m=="number"&&Number.isInteger(m)&&m>=1?m:(t.layout==="auto"&&m==null||r(`${b} is ${JSON.stringify(m)}, not a whole number from 1: it is placed at 1`),1),f=[],S=[];let B=[];const C=[],E=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||r(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const m of t.nodes??[]){const b=A==="flowchart"&&m.shape==="decision"?"decision":A==="flowchart"&&m.shape==="terminal"?"terminal":"box",h=String(m.id??""),k=d(m.row,`the row of ${h}`);f.push({id:h,i:f.length,name:String(m.name??""),kind:b==="decision"?void 0:at(m.kind),detail:b==="decision"?void 0:at(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:d(m.col,`the column of ${h}`),row:k,row2:k,branch:!!m.branch,shape:b,group:A==="architecture"?at(m.group):void 0,mark:A==="architecture"?Bt(m.mark):void 0})}if(A==="architecture"){const m=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:at($.parent)})),b=new Map(m.map($=>[$.id,$])),h=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(r(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(r(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(r(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},k=m.map(h);m.forEach(($,w)=>C.push({...$,depth:k[w],members:f.filter(_=>_.group===$.id).map(_=>_.id),all:[]}));for(const $ of C)$.all=[...$.members,...C.filter(w=>w.parent===$.id).flatMap(w=>w.members)];C.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){B=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const m=new Map(B.map((b,h)=>[b.id,h+1]));for(const b of t.nodes??[]){const h=String(b.id??""),k=String(b.lane??""),$=m.get(k);$===void 0&&r(`a node (${h}) names the lane "${k}", which is not in lanes`);const w=f.length+1;f.push({id:h,i:f.length,name:String(b.name??""),kind:u(w),detail:at(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:d(b.col,`the column of ${h}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:B[($??1)-1]?.label??k,step:w,mark:Bt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((k,$)=>{const w=String(k.name??"");f.push({id:String(k.id??""),i:$,name:w,kind:at(k.kind),mono:!1,focal:!!k.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:at(k.short)??w,mark:Bt(k.mark)})});let m=0;const b=new Map(f.map(k=>[k.id,k.col])),h=(k,$)=>{let w=1/0,_=-1/0;for(const q of k??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&r(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),E.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){r("a frame is a third level: frames nest two deep");continue}const st=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=st==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];st==="alt"&&V.length<2&&r("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&r(`the frame label "${P}" is over 40 characters`);const U=E.length;E.push({open:st,label:P,depth:$+1,a:0,b:0}),V.forEach((et,rt)=>{if(rt){const xt=String(et.label??"");xt.length>40&&r(`the frame label "${xt}" is over 40 characters`),E.push({otherwise:xt,depth:$+1})}et.steps?.length||r(`a frame or branch ("${String(et.label??"")}") is empty`);const[ct,At]=h(et.steps??[],$+1);w=Math.min(w,ct),_=Math.max(_,At);const bt=E[U];bt.a=Math.min(bt.a||1/0,ct),bt.b=Math.max(bt.b,At)}),E.push({close:$+1});continue}m++;const R=String(q.label??"");R.includes(` +`)&&r(`message ${m}'s label has a break: a message's second line is its note`);const Q=String(q.from??""),X=String(q.to??"");E.push({n:m,from:Q,to:X,label:gt(R),note:at(q.note),kind:g(q.kind,`message ${m}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const z=b.get(Q)??1,D=b.get(X)??1,tt=z===D?z===f.length?z-1:z+1:z;w=Math.min(w,z,D,tt),_=Math.max(_,z,D,tt)}return[w,_]};h(t.steps??[],0);for(const k of E)"open"in k&&!Number.isFinite(k.a)&&(k.a=1,k.b=Math.max(1,f.length))}else if(A==="schema")for(const m of t.tables??[]){const b=String(m.name??""),[h,k]=Array.isArray(m.row)?m.row:[m.row,m.row],$=d(h,`the row of ${b}`),w=Math.max($,d(k,`the last row of ${b}`)),_=m.more===void 0||m.more===null?void 0:Number.isInteger(m.more)&&m.more>0?m.more:(r(`${b}'s "more" is ${JSON.stringify(m.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:b,i:f.length,name:b,mono:!0,focal:!!m.focal,col:d(m.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:_,columns:(m.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&r(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const m=A==="schema"?t.tables:t.nodes;a&&(m??[]).some(h=>h&&(h.col!==void 0||h.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(T=!0);for(const h of f){const k=b?.[h.id];h.col=k?.col??1,h.row=h.row2=k?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((m,b)=>{if(!m||m.href===void 0||m.href===null)return;const h=String(m.href);if(A==="sequence"){r(`${f[b]?.id}: a participant cannot be a link (href)`);return}if(!h){r(`${f[b]?.id}'s href is empty`);return}const k=f[b];k&&(k.href=h,k.blank=m.target==="_blank")});const j=new Map;for(const m of f)m.id?j.has(m.id)&&r(`the id "${m.id}" is used twice`):r("a node has no id"),j.set(m.id,m);if(A==="schema")(t.tables??[]).forEach(m=>(m.columns??[]).forEach((b,h)=>{const k=at(b.references);if(!k)return;const[$,w]=k.split("."),_=j.get($??""),q=_?.columns?.findIndex(Q=>Q.name===w)??-1;if(!_||q<0){r(`${String(m.name)}.${String(b.name)} references ${k}, which is not a shown column`);return}const R=j.get(String(m.name??""));R.columns[h].ref={table:$,column:w,row:q},S.push({i:S.length,from:R.id,to:$,kind:"plain",fromRow:h,toRow:q,fk:!0})}));else if(A!=="sequence")for(const m of t.edges??[]){const b=String(m.from??""),h=String(m.to??"");if(!j.has(b)||!j.has(h)){r(`a line names ${j.has(b)?h:b}, which is not a node`);continue}const k=at(m.label),$=k?.split(` +`)??[];$.length>2&&r(`the label "${gt(k)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>Jt)&&r(`a line of the label "${gt(k)}" is over ${Jt} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:h,kind:g(m.kind,`the line from ${b} to ${h}`),label:k,fromSide:x(m.fromSide),toSide:x(m.toSide),flow:A!=="flowchart"&&m.flow===!0?!0:void 0})}else for(const m of E)"n"in m&&(!j.has(m.from)||!j.has(m.to))&&r(`message ${m.n} names ${j.has(m.from)?m.to:m.from}, which is not a participant`);if(a&&A!=="sequence"&&!T){const m=new Map;for(const b of f)for(let h=b.row;h<=b.row2;h++){const k=`${b.col}:${h}`;m.has(k)&&r(`${b.id} and ${m.get(k)} share the cell at column ${b.col}, row ${h}`),m.set(k,b.id)}}if(a&&!T){for(const b of C){const h=b.all.map(w=>j.get(w));if(!h.length)continue;const k={c1:Math.min(...h.map(w=>w.col)),c2:Math.max(...h.map(w=>w.col)),r1:Math.min(...h.map(w=>w.row)),r2:Math.max(...h.map(w=>w.row2))};for(const w of f)!b.all.includes(w.id)&&w.col>=k.c1&&w.col<=k.c2&&w.row>=k.r1&&w.row<=k.r2&&r(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=h.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&r(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of f)b.group&&!C.some(h=>h.id===b.group)&&r(`${b.id} names the group "${b.group}", which is not in groups`);f.filter(b=>b.focal).length>1&&r("more than one node is focal: a diagram has one at most");const m=new Set(A==="sequence"?E.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));m.has("main")&&!s.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),m.has("dashed")&&!s.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(b=>b.focal)&&!s.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const ot=A==="architecture"||A==="data-flow",L=m=>Array.isArray(m)&&m.length>1?m.map(String):void 0,F=ot&&t.packet&&typeof t.packet=="object"?t.packet:void 0,I=F&&L(F.path),M={animated:t.motion==="animated",pulse:ot?L(t.pulse):void 0,packet:I?{path:I,repeat:F.repeat===!0,send:F.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(a)for(const m of f){const b=m.mark?.says;if(!b?.length)continue;const h=[m.name,m.kind,m.detail,m.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(k=>h.includes(k.toLowerCase()))||r(`${m.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const m=new Map,b=new Map;for(const h of E)"n"in h&&(b.set(h.from,h.n),b.set(h.to,h.n));for(const h of E)if("n"in h){if(h.activate){const k=m.get(h.to)??[];if(k.length>=3)r(`message ${h.n} opens a fourth bar on ${h.to}: three deep at most`);else{const $={who:h.to,from:h.n,to:h.n,depth:k.length+1};k.push($),O.push($),m.set(h.to,k)}}if(h.deactivate){const $=m.get(h.from)?.pop();$?$.to=h.n:r(`message ${h.n} closes a bar on ${h.from}, which has none open`)}}for(const[h,k]of m)for(const $ of k)$.to=Math.max($.from,b.get(h)??$.from)}const N=t.frameLabels??{},G={opt:at(N.opt)??"Only if",loop:at(N.loop)??"Repeats",alt:at(N.alt)??"One of these",else:at(N.else)??"Otherwise"};let W=Math.max(1,...f.map(m=>m.col));if(e.rtl){for(const b of f)b.col=W-b.col+1;const m=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=m(b.fromSide),b.toSide=m(b.toSide);for(const b of E)if("open"in b){const[h,k]=[W-b.b+1,W-b.a+1];b.a=h,b.b=k}W=Math.max(1,...f.map(b=>b.col))}const Y=A==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(m=>m.row2)),K={type:A,title:String(t.title??""),heading:l,legend:s,nodes:f,byId:j,edges:S,groups:C,lanes:B,steps:E,bars:O,frameWords:G,cols:W,rows:Y,shapeLabels:p,stepWord:u,warnings:i,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0,text:A==="sequence"&&t.variant==="text"||void 0};return t.layout==="auto"&&!T&&A!=="schema"&&ze(K),a&&f.length>1&&!It(K)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function ze(t){const e=new Set(t.nodes.map(o=>`${o.col},${o.row}`)),n=(o,s)=>{const c=[];for(let u=Math.min(o,s)+1;u<Math.max(o,s);u++)c.push(u);return c},a=o=>{const s=t.byId.get(o.from),c=t.byId.get(o.to),u=c.col>s.col?"right":"left",y=c.row>s.row?"bottom":"top",p=c.col>s.col?"left":"right",l=c.row>s.row?"top":"bottom",g=(d,f,S,B)=>n(d,f).map(C=>B?[C,S]:[S,C]);let x;return s.row===c.row?x=[{sides:[u,p],cells:g(s.col,c.col,s.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:s.col===c.col?x=[{sides:[y,l],cells:g(s.row,c.row,s.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:x=[{sides:[u,l],cells:[...g(s.col,c.col,s.row,!0),[c.col,s.row],...g(s.row,c.row,c.col,!1)]},{sides:[y,p],cells:[...g(s.row,c.row,s.col,!1),[s.col,c.row],...g(s.col,c.col,c.row,!0)]},{sides:[u,p],cells:g(s.col,c.col,s.row,!0)},{sides:[y,l],cells:g(s.row,c.row,s.col,!1)}],x.filter(d=>d.cells.every(([f,S])=>!e.has(`${f},${S}`)))},i=new Map,r=t.edges.map((o,s)=>s).sort((o,s)=>a(t.edges[o]).length-a(t.edges[s]).length||+(t.edges[s].kind==="main")-+(t.edges[o].kind==="main")||o-s);for(const o of r){const s=t.edges[o];if(s.fromSide||s.toSide)continue;const c=a(s).find(u=>(i.get(`${s.from}.${u.sides[0]}`)??0)<3&&(i.get(`${s.to}.${u.sides[1]}`)??0)<3);if(c){for(const[u,y]of[[s.from,c.sides[0]],[s.to,c.sides[1]]])i.set(`${u}.${y}`,(i.get(`${u}.${y}`)??0)+1);s.fromSide=c.sides[0],s.toSide=c.sides[1]}}}function Bt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ut=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` `?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function $t(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Jt=28,Tt=t=>t.includes(` -`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Xt(t,e){return t.legend[e]}function Fe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function He(t,e){return $t(t,`sentence:${e.i}`,()=>De(t,e))}function De(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(o=>o.ref).map(o=>`${o.ref.table} (${o.name})`),i=t.edges.filter(o=>o.to===e.id).map(o=>`${o.from} (${t.byId.get(o.from).columns[o.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(r=>"n"in r&&r.from===e.id).length,i=t.steps.filter(r=>"n"in r&&r.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${i}.`);const o=Yt(t,e);o&&n.push(o.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Fe(t,e):e.kind;if(n.push(wt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const r=t.groups.find(d=>d.id===e.group),a=r?.parent?t.groups.find(d=>d.id===r.parent):void 0;r&&n.push(a?`In ${r.label}, in ${a.label}.`:`In ${r.label}.`)}const i=t.edges.filter(r=>r.to===e.id).map(r=>`${t.byId.get(r.from).name}${r.label?` (${gt(r.label)})`:""}`),o=t.edges.filter(r=>r.from===e.id).map(r=>`${t.byId.get(r.to).name}${r.label?` (${gt(r.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),o.length&&n.push(`To: ${o.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Yt(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function Ge(t,e,n,s){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const o=t.querySelector(`.${e}-drawing`),r=n.target;if(!o||!r||!o.contains(r)||!t.querySelector(`.${e}-edge`))return;const a=r.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===s?null:a.dataset.node??null:null}function Qt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function k(t,e,...n){const s=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&s.push(i);return{t,a:e??{},c:s}}var Ke={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>Ke[e]),Ve=" br img input meta link hr path polygon polyline circle rect line ";function Rt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=i===!0?` ${s}`:` ${s}="${it(String(i))}"`}return Ve.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Rt(s,e)).join("")}</${t.t}>`}var Ze=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Ue(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Lt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function Pt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=Lt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((o,r)=>{o&&(e[r]=Math.max(e[r],te(t,n,r)))})}return e})}function te(t,e,n){const s=Lt(t,e);return t.groups.filter(r=>r.parent===e.id).some(r=>{const a=Lt(t,r);return a&&[a.r1===s.r1,a.c2===s.c2,a.r2===s.r2,a.c1===s.c1][n]})?2:1}function ee(t){const e=Pt(t);return e[1]+e[3]}function Wt(t){return t.type==="sequence"?t.nodes.length:t.cols}function ne(t){return $t(t,"plan",()=>Je(t))}function Je(t){const e=t.nodes,n=c=>t.type==="data-flow"||!e[c].branch,s=t.edges.map(c=>{const f=t.byId.get(c.from).i,S=t.byId.get(c.to).i,C=e.slice(Math.min(f,S)+1,Math.max(f,S)).every(E=>!n(E.i));return S===f+1&&!(n(f)&&!n(S))?"down":S===f-1?"up":S>f&&n(f)&&!n(S)&&C?"trunk":S>f&&n(f)&&n(S)&&C?"rail":S>f?"end-down":"end-up"}),i=t.edges.map((c,f)=>({e:c,k:f})).filter(({k:c})=>s[c]==="end-down"||s[c]==="end-up"),o=c=>{const f=t.byId.get(c.from).i,S=t.byId.get(c.to).i;return[Math.min(f,S),Math.max(f,S)]},r=(c,f)=>{const[S,B]=o(c),[C,E]=o(f);return S<E&&C<B},a=i.every(({e:c})=>{const f=t.byId.get(c.from).i,[S,B]=o(c);return!n(f)&&e.slice(S+1,B).every(C=>!n(C.i))&&i.every(C=>C.e===c||!r(C.e,c))}),d=i.length>0&&(t.type==="data-flow"||!a),u=c=>{const[f,S]=o(c);return S-f},y=t.edges.map(()=>0);let p=!1;const l=[];for(const c of[...i].sort((f,S)=>u(f.e)-u(S.e)||f.k-S.k)){let f=0;for(const S of l)r(S.e,c.e)&&(f=Math.max(f,y[S.k]+1));y[c.k]=f,f>1&&(p=!0),l.push(c)}const m=t.edges.map(()=>.5);for(const c of e){const f=i.filter(({e:C})=>C.from===c.id);if(f.length<2)continue;const S=f.filter(({k:C})=>s[C]==="end-down").sort((C,E)=>u(E.e)-u(C.e)||C.k-E.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,E)=>u(C.e)-u(E.e)||E.k-C.k),...S].forEach(({k:C},E,A)=>{m[C]=A.length===2?E===0?1/3:2/3:(E+1)/(A.length+1)})}const v=ht();for(let c=1;c<e.length;c++){const f=e[c],S=e[c-1];let B=0,C=t.type==="data-flow"?48:32,E=!1,A=!1;t.edges.forEach((T,Z)=>{const j=s[Z],ot=t.byId.get(T.from).i,L=t.byId.get(T.to).i,F=L===c&&(j==="down"||j==="trunk"||j==="rail"||j==="end-down"),I=ot===c&&L===c-1&&j==="up",M=L===c-1&&j==="end-up";F&&(j==="trunk"||j==="end-down")&&(E=!0),M&&(A=!0),(F||I||M)&&T.label&&(B++,C=Math.max(C,j==="trunk"?40:48))}),(B>1||E&&A)&&(C=64),v[f.id]=C}return{routes:s,gutter:d,lanes:y,exits:m,gaps:v,third:p}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function oe(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,i=24,o=n==="dashed"?i-1:i-7;return k("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?k("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,k("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${o}`}),n==="dashed"?k("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${s-4}L${i} ${s}L${i-8} ${s+4}`}):k("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${s}L${i-8} ${s-4}L${i-8} ${s+4}Z`}))}function St(t,e){return e==="decision"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):k("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},k("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function se(t,e){return $t(e,`key:${t}`,()=>Ye(t,e))}var Xe=se;function Ye(t,e){const n=[],s=(o,r,a={})=>n.push(k("li",{class:`${t}-entry`,...a},o,k("span",null,r)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(r=>(r.columns??[]).map(a=>a.key)));for(const[r,a]of[["PK","Primary key"],["FK","Foreign key"]])o.has(r)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"aria-hidden":"true"},r),k("span",null,a)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(r=>r.shape));o.has("terminal")&&s(St(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(St(t,"box"),e.shapeLabels.step),o.has("decision")&&s(St(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind));for(const o of["main","plain","dashed"]){const r=e.legend[o];i.has(o)&&r&&s(oe(t,o),r,{"data-line":""})}if(e.type==="schema"&&e.edges.length&&(s(oe(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(k("li",{class:`${t}-entry`,"data-when":"stacked"},k("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),k("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(k("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},k("path",{class:`${t}-life`,d:"M8 0V16"}),k("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",{"data-when":"drawn"});const o=new Set(e.steps.flatMap(r=>"open"in r?[r.open]:[]));for(const r of["opt","loop","alt"])o.has(r)&&n.push(k("li",{class:`${t}-entry`},k("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},r),k("span",null,e.frameWords[r])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(St(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(St(t,"group"),e.legend.group),n.length?k("div",{class:`${t}-key`},k("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Qe(t,e){const n=e==="main"?6:6.5;return k("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},k("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?k("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):k("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Nt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),k("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Pe(t,e,n){if(n.shape==="decision")return[k("span",{class:`${t}-words`},k("span",{class:`${t}-name`},Nt(t,n)))];const s=[];return e.type==="data-flow"?s.push(k("span",{class:`${t}-kind`},n.kind,k("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(k("span",{class:`${t}-kind`},n.kind)),s.push(k("span",{class:`${t}-name`},Nt(t,n))),n.detail&&s.push(k("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?_t(n.detail).flatMap((i,o)=>[o?" ":"",k("span",{class:`${t}-run`},i)]):n.detail)),s}function tn(t,e,n){return[k("span",{class:`${t}-th`},k("span",{class:`${t}-tname`},Nt(t,e))),k("span",{class:`${t}-rows`},(e.columns??[]).map((s,i)=>k("span",{class:`${t}-row`,"data-row":i,"data-key":s.key},k("span",{class:`${t}-keyseat`},s.key??""),k("span",{class:`${t}-cname`},s.name),s.ref?k("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?k("span",{class:`${t}-ctype`},s.type):null))),e.more?k("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var ae=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function qt(t,e,n,s){const{P:i}=t,o=Ue(e,s)||s.keep===n.id,r=mt(e,s),a=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&a.push(`--_lc:${n.col+1}`),e.type==="sequence"&&a.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const l=yt(d.gaps,n.id)??32,m=yt(s.grow,n.id)??0;a.push(`--_gap:${m?`calc(${ae(l)} + var(--basalt-space-4) * ${m})`:ae(l)}`)}const u=yt(s.heights,n.id);u&&a.push(`--_h:${u}px`);const y=yt(s.words,n.id);y&&a.push(`--_ww:${y}px`);const p=r?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return k(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:a.join(";"),role:o&&!n.href?"img":void 0,"aria-label":o||n.href?He(e,n):void 0,tabindex:p},n.shape==="decision"?k("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},k("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?k("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ut(n.mark.onLight)};--_md:${Ut(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?tn(i,n,e):Pe(i,e,n))}function en(t,e,n){const{P:s}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((d,u)=>k("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},k("span",{class:`${s}-lane-name`},d.label)))),e.type==="architecture")for(const d of e.groups){const u=Lt(e,d);if(!u)continue;const y=[0,1,2,3].map(p=>te(e,d,p));i.push(k("div",{class:`${s}-gbox`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${y[0]>1?";--_gt:2":""}${y[1]>1?";--_ge:2":""}${y[2]>1?";--_gb:2":""}${y[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},k("span",{class:`${s}-glabel`},d.label)))}if(e.type==="sequence")return i.push(k("ul",{class:`${s}-cast`},e.nodes.map(d=>k("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${d.col}`:void 0},qt(t,e,d,n))))),i.push(nn(t,e)),i;const o=d=>{const u=d.group?e.groups.find(y=>y.id===d.group):void 0;return u?.parent?e.groups.find(y=>y.id===u.parent):u},r=(d,u,y)=>{const p=t.plan?yt(n.grow,u[0].id)??0:0;return k("div",{class:`${s}-group`,"data-group":d.id,"data-depth":d.depth>1?d.depth:void 0,style:p?`--_ggrow:${p}`:void 0},k("span",{class:`${s}-glabel`,"aria-hidden":"true"},d.label),y)};let a=0;for(;a<e.nodes.length;){const d=e.nodes[a],u=o(d);if(!u){i.push(qt(t,e,d,n)),a++;continue}const y=[];for(;a<e.nodes.length&&o(e.nodes[a])?.id===u.id;)y.push(e.nodes[a++]);const p=[];for(let l=0;l<y.length;){const m=y[l].group!==u.id?e.groups.find(c=>c.id===y[l].group):void 0;if(!m){p.push(qt(t,e,y[l],n)),l++;continue}const v=[];for(;l<y.length&&y[l].group===m.id;)v.push(y[l++]);p.push(r(m,v,v.map(c=>qt(t,e,c,n))))}i.push(r(u,y,p))}return i}function nn(t,e){const{P:n}=t,s=[],i=[],o=()=>i.length?i[i.length-1].el.c:s;let r=null;for(const a of e.steps){if("band"in a){r=null,o().push(k("p",{class:`${n}-band`},k("span",null,a.band)));continue}if("open"in a){r=null;const c=i[i.length-1],f=c?`;--_fis:${a.a===c.a?1:0};--_fie:${a.b===c.b?1:0}`:"",S=k("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${f}`},k("span",{class:`${n}-fbox`,"aria-hidden":"true"}),k("p",{class:`${n}-fhead`},k("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));o().push(S),i.push({el:S,a:a.a,b:a.b});continue}if("otherwise"in a){r=null,o().push(k("p",{class:`${n}-felse`},k("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),k("span",{class:`${n}-flabel`},k("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){r=null,i.pop();continue}r||(r=k("ol",{class:`${n}-msgs`,start:a.n}),o().push(r));const d=e.byId.get(a.from),u=e.byId.get(a.to),y=d?.col??1,p=u?.col??1,l=y===p,m=l&&(e.rtl?y!==1:y===e.nodes.length),v=Xt(e,a.kind);r.c.push(k("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":l?m?"start":"end":void 0,style:`--_a:${Math.min(y,p)};--_b:${Math.max(y,p)+1}`},k("span",{class:`${n}-said`},k("span",{class:`${n}-num`},String(a.n)),k("span",{class:`${n}-mlabel`},a.label)),k("span",{class:`${n}-route`},d?.short??a.from," ",Qe(n,a.kind),k("span",{class:t.hidden}," to ")," ",u?.short??a.to,v?` · ${v}`:""),a.note?k("span",{class:`${n}-note`},a.note):null))}return k("div",{class:`${n}-steps`},s)}function re(t,e){return $t(e,`list:${t}`,()=>sn(t,e))}var on=re;function sn(t,e){const n=Math.min(6,e.heading+1),s=p=>k(`h${n}`,{class:`${t}-list-head`},p),i=p=>k("strong",null,p),o=p=>p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},i(p.name)):i(p.name),r=p=>k("code",{class:`${t}-code`},p),a=p=>e.byId.get(p)?.name??p,d=p=>{const l=Xt(e,p);return l?` (${l})`:""},u=p=>p.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const p=v=>k("li",null,o(v),v.kind?`, ${v.kind}`:"",v.detail?[". ",v.mono?r(v.detail):v.detail,/[.!?]$/.test(v.detail)?"":"."]:/[.!?]$/.test(v.kind??v.name)?"":".",u(v)),l=[s("Parts")],m=e.nodes.filter(v=>!v.group);m.length&&l.push(k("ul",{class:`${t}-list-items`},m.map(p)));for(const v of e.groups.filter(c=>c.depth===1)){l.push(k("p",{class:`${t}-list-group`},v.label)),v.members.length&&l.push(k("ul",{class:`${t}-list-items`},v.members.map(c=>p(e.byId.get(c)))));for(const c of e.groups.filter(f=>f.parent===v.id))l.push(k("p",{class:`${t}-list-group`,"data-depth":2},c.label)),l.push(k("ul",{class:`${t}-list-items`,"data-depth":2},c.members.map(f=>p(e.byId.get(f)))))}return l.push(s("Connections")),l.push(k("ol",{class:`${t}-list-items`},e.edges.map(v=>k("li",null,i(a(v.from))," to ",i(a(v.to)),v.label?[": ",r(gt(v.label))]:"",`${d(v.kind)}.`)))),l}if(e.type==="flowchart"){const p=l=>(e.byId.get(l)?.i??0)+1;return[k("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const m=e.edges.filter(f=>f.from===l.id),v=l.shape==="decision"?"Decision":l.shape==="terminal"?m.length?"Start":"End":"Step",c=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return k("li",null,o(l),l.detail?[", ",l.mono?r(l.detail):l.detail]:"",`${c}${v}.`,u(l),m.length?k("ul",{class:`${t}-list-exits`},m.map(f=>k("li",null,f.label?`If ${gt(f.label)}: go to ${p(f.to)}, `:`Then: go to ${p(f.to)}, `,i(a(f.to)),d(f.kind)))):null)}))]}if(e.type==="data-flow")return[k("ol",{class:`${t}-list-items`},e.nodes.map(p=>{const l=e.edges.filter(m=>m.from===p.id);return k("li",null,`${p.laneLabel}: `,o(p),p.detail?[", ",p.mono?r(p.detail):p.detail]:"",".",u(p),l.length?[" Then ",...l.flatMap((m,v)=>[v?"; ":"",`to step ${e.byId.get(m.to).step}, `,i(a(m.to)),m.label?[": ",r(gt(m.label))]:"",d(m.kind)]),"."]:"")}))];if(e.type==="sequence"){const p=[s("Participants"),k("ul",{class:`${t}-list-items`},e.nodes.map(m=>k("li",null,i(m.name),m.kind?`, ${m.kind}`:"",".",u(m),Yt(e,m))))];p.push(s("Messages"));let l=null;for(const m of e.steps){if("band"in m){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},m.band));continue}if("open"in m){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":m.depth>1?m.depth:void 0},`${e.frameWords[m.open]}: ${m.label}`));continue}if("otherwise"in m){l=null,p.push(k(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":m.depth>1?m.depth:void 0},`${e.frameWords.else}: ${m.otherwise}`));continue}if("close"in m){l=null;continue}l||(l=k("ol",{class:`${t}-list-items`,start:m.n}),p.push(l)),l.c.push(k("li",null,r(m.label),": ",i(a(m.from))," to ",i(a(m.to)),`${d(m.kind)}.`,m.note?` ${wt(m.note)}`:""))}return p}const y=[];for(const p of e.nodes)y.push(k(`h${n}`,{class:`${t}-list-group`},p.href?k("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},r(p.name)):r(p.name),u(p))),y.push(k("ul",{class:`${t}-list-items`},[...(p.columns??[]).map(l=>k("li",null,r(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",r(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...p.more?[k("li",null,`and ${p.more} more ${p.more===1?"column":"columns"}`)]:[]]));return y}function ie(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&It(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function zt(t,e=!1){const n=e&&t.type!=="sequence"&&It(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Qt(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var an=(t,e)=>{for(let n=0;n<t.length;n++)if(t[n]!==e[n])return t[n]<e[n];return!1},rn=(t,e)=>({col:e.col,rows:[e.row,e.row2]});function It(t){return $t(t,"spatial",()=>{const e=t.nodes.map(o=>({id:o.id,...rn(t,o)})),n=(o,r)=>{const a=r==="right"||r==="left",d=r==="right"||r==="down",u=v=>a?[v.col,v.col]:v.rows,y=v=>a?v.rows:[v.col,v.col],p=u(o),l=y(o);let m=null;return e.forEach((v,c)=>{if(v===o)return;const f=u(v),S=y(v),B=d?f[0]-p[1]:p[0]-f[1];if(B<1)return;const C=Math.max(0,S[0]-l[1],l[0]-S[1]),E=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(S[0]-l[0]),c];(!m||an(E,m.rank))&&(m={id:v.id,rank:E})}),m?.id??null},s=ht();for(const o of e)s[o.id]={right:n(o,"right"),left:n(o,"left"),down:n(o,"down"),up:n(o,"up")};const i=o=>{const r=new Set([o]),a=[o];for(;a.length;)for(const d of Object.values(s[a.pop()]))d&&!r.has(d)&&(r.add(d),a.push(d));return r.size};return e.every(o=>i(o.id)===e.length)?s:null})}var le=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Ft(t,e,n){const s=n.prefix,i=Ze(n.base),o=t.type==="sequence"||t.type==="schema"?null:ne(t),r={P:s,ids:i,level:n.level,plan:o,hidden:n.hiddenClass},a=e.layout==="drawn",d=mt(t,e),u=t.type==="sequence"||t.type==="schema"?a:!0,y=`h${t.heading}`,p=[`--_cols:${Wt(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const l=t.type==="architecture"?Pt(t):[0,0,0,0],m=(c,f,S)=>c?c>1?`calc(${c} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:S?`var(--basalt-space-${S})`:"0px",v=a&&e.pad?"3":void 0;p.push(`--_gpad:${m(l[0],"8",v)} ${m(l[1],"4")} ${m(l[2],"4",v)} ${m(l[3],"4")}`)}return le(t)&&p.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&p.push(`--_track:${e.track}px`),k("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":i.title,"data-type":t.type,"data-cols":Wt(t),"data-reach":t.type==="architecture"?ee(t):void 0,"data-gutter":o?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:p.join(";")},k("div",{class:`${s}-head`},k(y,{id:i.title,class:`${s}-title`},t.title),n.hasSource?k("p",{class:`${s}-source`},{slot:"source"}):null),k("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?i.title:void 0,"aria-describedby":u?d?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":d?"":void 0},en(r,t,e),k("div",{class:`${s}-ink`,"aria-hidden":"true"}),k("span",{class:`${s}-ruler`,"aria-hidden":"true"})),se(s,t),k("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?k("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${Qt(t)} to highlight its lines. Tap it again to clear.`):null,k("div",{class:`${s}-foot`},{slot:"toggle"}),k("div",{id:i.list,class:`${s}-list`,hidden:!e.open},re(s,t)),k("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${ie(t,a)} ${n.viewer}`:ie(t,a)),k("figcaption",{id:i.summary,class:`${s}-summary`},{slot:"summary"}))}function ln(t){const e=getComputedStyle(t),n=(i,o)=>{const r=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(r)?r:o},s=new Map;return{space:i=>(s.has(i)||s.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),s.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ot=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.l<e.r-n&&t.r>e.l+n&&t.t<e.b-n&&t.b>e.t+n,ce=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:i,r:o,b:r}=t.rect,a=(s+o)/2,d=(i+r)/2,u=(o-s)/2,y=(r-i)/2,p=e==="top"||e==="bottom";if(t.shape==="decision"){if(p){const v=n,c=y*Math.max(0,1-Math.abs(v-a)/u);return{x:v,y:e==="top"?d-c:d+c}}const l=n,m=u*Math.max(0,1-Math.abs(l-d)/y);return{x:e==="left"?a-m:a+m,y:l}}if(t.shape==="terminal"){const l=Math.min(u,y);if(p){const f=n,S=Math.min(Math.max(f,s+l),o-l),B=f-S,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?i:r:e==="top"?d-C:d+C}}const m=n,v=m-d,c=Math.abs(v)>=l?0:Math.sqrt(l*l-v*v);return{x:e==="left"?s+l-c:o-l+c,y:m}}return p?{x:n,y:e==="top"?i:r}:{x:e==="left"?s:o,y:n}}function cn(t,e,n){const{l:s,t:i,r:o,b:r}=e.rect,a=(s+o)/2,d=(i+r)/2,u=(o-s)/2,y=(r-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/u+Math.abs(t.y-d)/y<1-n/Math.min(u,y);if(e.shape==="terminal"){const p=Math.min(u,y),l=Math.min(Math.max(t.x,s+p),o-p);return Math.hypot(t.x-l,t.y-d)<p-n}return t.x>s+n&&t.x<o-n&&t.y>i+n&&t.y<r-n}function de(t,e){if(!ut(t,e.rect))return!1;if(e.shape!=="decision"&&e.shape!=="terminal")return!0;const{l:n,t:s,r:i,b:o}=e.rect,r=(n+i)/2,a=(s+o)/2,d=(i-n)/2,u=(o-s)/2;if(e.shape==="decision"){const p=Math.max(t.l,Math.min(r,t.r)),l=Math.max(t.t,Math.min(a,t.b));return Math.abs(p-r)/d+Math.abs(l-a)/u<1-1e-6}const y=Math.min(u,d);if(ut(t,{l:n+y,r:i-y,t:s,b:o}))return!0;for(const p of[n+y,i-y]){const l=Math.max(t.l,Math.min(p,t.r)),m=Math.max(t.t,Math.min(a,t.b));if(Math.hypot(l-p,m-a)<y-.01)return!0}return!1}function dn(t,e,n){const s=Math.hypot(e.x-t.x,e.y-t.y),i=Math.max(2,Math.ceil(s/2));for(let o=1;o<i;o++){const r=o/i;if(!(r*s<1.5||(1-r)*s<1.5)&&cn({x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r},n,1))return!0}return!1}var fn=()=>matchMedia("(forced-colors: active)").matches;function un(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(i,o)=>{const r=`${o}|${i}`;return s.has(r)||(n.setAttribute("data-f",o),n.textContent=i,s.set(r,n.getBoundingClientRect().width),n.textContent=""),s.get(r)}}var _t=t=>t?t.split(/\s+/).filter(Boolean):[];function hn(t,e,n){const s=e.space;let i=e.node,o=e.table;for(const d of t.nodes){if(d.shape==="table"){for(const c of d.columns??[]){const f=c.ref?`${t.rtl?"←":"→"} ${c.ref.table}`:c.type??"",S=s("6")+n(c.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;o=Math.max(o,Math.ceil(S))}o=Math.max(o,Math.ceil(n(d.name,"table")+2*s("3")+2*e.hair+(d.href?16+s("1-5"):0)));continue}const u=d.shape==="terminal"?2*s("5"):2*s("3"),y=d.mark&&!fn()?(d.shape==="participant"?2:1)*s("6"):0;let p=0;const l=d.href?16+s("1-5"):0,m=_t(d.name);if(m.forEach((c,f)=>{p=Math.max(p,n(c,d.shape==="decision"?"name-500":"name")+(d.kind?0:y)+(f===m.length-1?l:0))}),t.type!=="data-flow")for(const c of _t(d.kind))p=Math.max(p,n(c,"mono")+y);for(const c of _t(d.detail))p=Math.max(p,n(c,d.mono?"mono":"sans"));const v=d.shape==="decision"?p/.62:p+u+2*e.hair;i=Math.max(i,Math.ceil(v))}const r=Wt(t);let a;return t.type==="data-flow"?a=e.lane+r*(i+s("12")):t.type==="schema"?a=r*o+(r-1)*s("12")+(le(t)?s("5"):0):t.type==="sequence"?a=r*i+(r-1)*s("5"):a=r*i+(r-1)*s("16")+ee(t)*s("4"),{track:i,table:o,least:Math.max(e.wide,a)}}function fe(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Ht(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ue(t,e,n){const s=t.map(o=>({...o}));for(let o=1;o<s.length;o++){const r=s[o-1],a=s[o];if(Math.abs(r.x-a.x)<.75){const d=n.x(r.x,e);r.x=d,a.x=d}else if(Math.abs(r.y-a.y)<.75){const d=n.y(r.y,e);r.y=d,a.y=d}}const i=[s[0]];for(let o=1;o<s.length;o++){const r=s[o],a=i[i.length-1];if(!(Math.abs(r.x-a.x)<.01&&Math.abs(r.y-a.y)<.01)){if(i.length>=2){const d=i[i.length-2];if(Math.abs(d.x-a.x)<.01&&Math.abs(a.x-r.x)<.01||Math.abs(d.y-a.y)<.01&&Math.abs(a.y-r.y)<.01){i[i.length-1]=r;continue}}i.push(r)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Ct(t,e,n){const s=[];for(let o=0;o<t.length;o++)for(let r=o+1;r<t.length;r++){const a=t[o],d=t[r];if(!(n&&!n.has(a.i)&&!n.has(d.i)))for(const[u,y]of pt(a.pts))for(const[p,l]of pt(d.pts)){const m=Math.abs(u.y-y.y)<.01,v=Math.abs(p.y-l.y)<.01;if(m===v)continue;const[c,f,S,B]=m?[u,y,p,l]:[p,l,u,y],C=S.x,E=c.y;if(C>Math.min(c.x,f.x)+.75&&C<Math.max(c.x,f.x)-.75&&E>Math.min(S.y,B.y)+.75&&E<Math.max(S.y,B.y)-.75){const A=m?o:r,T=m?r:o;let Z=A,j=T;if(e){const ot=e(t[A]);e(t[T])&&!ot&&(Z=T,j=A)}s.push({top:Z,under:j,at:{x:C,y:E},underVertical:j===T})}}}return s}function pn(t){const e=getComputedStyle(t),n=i=>i.split(/\s+/).map(parseFloat).filter(o=>Number.isFinite(o)),s=(i,o,r)=>{const a=[];let d=o;for(const u of i)a.push([d,d+u]),d+=u+r;return a};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var nt=t=>t==="left"||t==="right",he={top:"bottom",bottom:"top",left:"right",right:"left"};function gn(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function mn(t,e,n){const s=[];t.edges.forEach((o,r)=>{const a=t.byId.get(o.from),d=t.byId.get(o.to),[u,y]=e[r],p=a.row===d.row&&nt(u)&&nt(y)&&u===he[y]||a.col===d.col&&!nt(u)&&!nt(y)&&u===he[y];s.push({edge:r,end:"from",node:a,side:u,far:d,straight:p,f:.5},{edge:r,end:"to",node:d,side:y,far:a,straight:p,f:.5})});const i=new Map;for(const o of s){const r=`${o.node.id}.${o.side}`;i.has(r)||i.set(r,[]),i.get(r).push(o)}for(const[o,r]of i){if(r[0].node.shape==="decision")continue;const a=c=>nt(c.side)?c.far.row-c.node.row:c.far.col-c.node.col,d=r.filter(c=>c.straight),u=r.filter(c=>!c.straight);if(u.sort((c,f)=>a(c)-a(f)||(nt(c.side)?c.far.col-f.far.col:c.far.row-f.far.row)*(a(c)<0?1:-1)),r.length>3&&n(`${o.replace(".","'s ")} side has ${r.length} lines; more than three is an error: use another side`),!d.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((c,f)=>{c.f=(f+1)/(u.length+1)});continue}const y=new Map;for(const c of d)y.has(c.far.id)||y.set(c.far.id,[]),y.get(c.far.id).push(c);for(const c of y.values())c.length>1&&c.sort((f,S)=>f.edge-S.edge).forEach((f,S)=>{f.f=c.length===2?S===0?.25:.75:(S+1)/(c.length+1)});const p=Math.min(...d.map(c=>c.f)),l=Math.max(...d.map(c=>c.f)),m=u.filter(c=>a(c)<0),v=u.filter(c=>a(c)>=0);m.forEach((c,f)=>{c.f=p*(f+1)/(m.length+1)}),v.forEach((c,f)=>{c.f=l+(1-l)*(f+1)/(v.length+1)})}return s}function pe(t,e,n){const{l:s,t:i,r:o,b:r}=t.rect;return nt(e)?lt(t,e,i+(r-i)*n):lt(t,e,s+(o-s)*n)}function ge(t,e,n,s){const i=new Map;return e.querySelectorAll(`.${s}-node`).forEach(o=>{const r=t.byId.get(o.dataset.node);r&&i.set(r.id,{id:r.id,rect:ft(o,n),shape:r.shape,i:r.i})}),i}function me(t,e){const n=e.head,s=e.head/2,{x:i,y:o}=t.tip;return t.dir==="down"?{l:i-s,r:i+s,t:o-n,b:o}:t.dir==="up"?{l:i-s,r:i+s,t:o,b:o+n}:t.dir==="right"?{l:i-n,r:i,t:o-s,b:o+s}:{l:i,r:i+n,t:o-s,b:o+s}}var ye=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function be(t,e,n,s){const i=(o,r)=>{const a=o+r-Math.floor(o+r);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const o of i(t.t,n))for(const r of i(t.l,e)){if(!r&&!o)return t;const a={l:t.l+r,r:t.r+r,t:t.t+o,b:t.b+o};if(s(a))return a}return t}function yn(t,e,n,s,i,o,r,a,d){const u=r.space,y=[],p=[],l=[],m=[],v=u("1"),c=e.filter(f=>t.edges[f.i]?.label).sort((f,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-S.i);for(const f of c){const S=t.edges[f.i].label,B=a(S,"label"),C=16*Tt(S),E=f.pts.length-2,A=[];pt(f.pts).forEach(([L,F],I)=>{const M=Math.abs(L.y-F.y)<.01,O=M?L.x:L.y;let N=M?F.x:F.y;const G=Math.sign(N-O)||1;I===E&&(N-=G*r.head);let W=[[O,N]];for(const g of i)for(const b of M?[g.l,g.r]:[g.t,g.b]){const h=M?L.y:L.x;(M?h>g.t&&h<g.b:h>g.l&&h<g.r)&&(W=W.flatMap(([$,w])=>b>Math.min($,w)+1&&b<Math.max($,w)-1?[[$,b],[b,w]]:[[$,w]]))}const Y=(g,b)=>{const h=(g+b)/2,x=M?{x:h,y:L.y}:{x:L.x,y:h};return!i.some($=>x.x>$.l&&x.x<$.r&&x.y>$.t&&x.y<$.b)},K=f.axes?.[I]??(M?L.y:L.x);for(const[g,b]of W)A.push({horiz:M,c:K,p:g,q:b,len:Math.abs(b-g),pri:W.length>1&&Y(g,b)?1:0})}),A.sort((L,F)=>F.pri-L.pri||F.len-L.len);let T=null,Z=!1;const j=(L,F=!0)=>{const I=ce(L,v);return F&&(L.l<o.l||L.r>o.r||L.t<o.t||L.b>o.b)||n.some(M=>de(I,M))||y.some(M=>ut(I,M))||s.heads.some(M=>ut(I,M))||s.rects.some(M=>ut(I,M))?!1:!e.some(M=>M.i!==f.i&&pt(M.pts).some(([O,N])=>ut(I,ye(O,N,M.width))))};for(const L of A){for(const F of[1/2,1/3,2/3]){const I=L.p+(L.q-L.p)*F,M=[],O=u("2")+f.width/2;if(L.horiz?(L.len>=B+2*u("1")+u("3-5")&&M.push({box:{l:I-B/2-u("1"),r:I+B/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),M.push({box:{l:I-B/2,r:I+B/2,t:L.c-O-C,b:L.c-O},on:!1}),M.push({box:{l:I-B/2,r:I+B/2,t:L.c+O,b:L.c+O+C},on:!1})):(L.len>=C+u("3")&&M.push({box:{l:L.c-B/2-u("1"),r:L.c+B/2+u("1"),t:I-C/2,b:I+C/2},on:!0}),M.push({box:{l:L.c+O,r:L.c+O+B,t:I-C/2,b:I+C/2},on:!1}),M.push({box:{l:L.c-O-B,r:L.c-O,t:I-C/2,b:I+C/2},on:!1})),T=M.find(N=>j(N.box))??null,T)break;!Z&&M.some(N=>j(N.box,!1))&&(Z=!0)}if(T)break}if(!T){l.push(f.i),Z&&m.push(f.i);continue}const ot=be(T.box,d.ox,d.oy,L=>j(L));y.push(ot),p.push({i:f.i,text:S,box:ot,on:T.on})}return{labels:p,unseated:l,bounded:m}}function $e(t,e,n,s){const i=[],o=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(r=>{if(r.getClientRects().length===0||getComputedStyle(r).display==="contents")return;const a=ft(r,e);o.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const d=r.querySelector(`:scope > .${n}-glabel`);d&&d.getClientRects().length&&i.push(ft(d,e))}),t.querySelectorAll(`.${n}-lane`).forEach((r,a)=>{if(!r.getClientRects().length)return;const d=ft(r,e);a>0&&i.push({l:d.l,r:d.r,t:d.t-s/2-.5,b:d.t-s/2+.5});const u=r.querySelector(`.${n}-lane-name`);u&&i.push(ft(u,e))}),{obstacles:{rects:i,heads:[]},groups:o}}function bn(t,e){const{m:s,tk:i,P:o,drawing:r,origin:a,warn:d}=t,u=i.space,y=ge(s,r,a,o),p=[...y.values()],l=pn(r),m=a.left-Math.floor(a.left),v=a.top-Math.floor(a.top),c=fe(m,v),f=r.clientWidth,S=r.clientHeight,B=h=>s.type==="data-flow"?h.col+1:h.col,C=parseFloat(getComputedStyle(r).rowGap)||0,E={w:f,h:S,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:m,oy:v};if(s.type==="sequence")return wn(t,E,c);let A,T=[];s.type==="schema"?A=s.edges.map(h=>{const x=s.byId.get(h.from),$=s.byId.get(h.to);if(x.col===$.col){const w=x.col===s.cols&&s.cols>1?"left":"right";return[w,w]}return $.col>x.col?["right","left"]:["left","right"]}):(A=s.edges.map(h=>{const x=s.byId.get(h.from),$=s.byId.get(h.to),[w,_]=gn(x,$);return[h.fromSide??w,h.toSide??_]}),T=mn(s,A,d||(()=>{})));const Z=(h,x)=>{const $=r.querySelector(`.${o}-node[data-node="${CSS.escape(h)}"] .${o}-row[data-row="${x}"]`);if(!$)return 0;const w=ft($,a);return(w.t+w.b)/2},j=s.edges.map((h,x)=>{const[$,w]=A[x],_=y.get(h.from),q=y.get(h.to),R=Ot(h.kind,i);if(h.fk){const V=Z(h.from,h.fromRow),P=Z(h.to,h.toRow),U=c.y(V,R),et=c.y(P,R);return{p1:{x:$==="right"?_.rect.r:_.rect.l,y:U},p2:{x:w==="right"?q.rect.r:q.rect.l,y:et},r1:V,r2:Math.abs(U-et)<.01?V:P}}const Q=T.find(V=>V.edge===x&&V.end==="from").f,X=T.find(V=>V.edge===x&&V.end==="to").f;let z=pe(_,$,Q),D=pe(q,w,X);const tt=nt($)?z.y:z.x;let st=nt(w)?D.y:D.x;return nt($)?z={...z,y:c.y(z.y,R)}:z={...z,x:c.x(z.x,R)},nt(w)?D={...D,y:c.y(D.y,R)}:D={...D,x:c.x(D.x,R)},nt($)&&nt(w)&&Math.abs(z.y-D.y)<1.01&&(D={...D,y:z.y},st=tt),!nt($)&&!nt(w)&&Math.abs(z.x-D.x)<1.01&&(D={...D,x:z.x},st=tt),z=nt($)?lt(_,$,z.y):lt(_,$,z.x),D=nt(w)?lt(q,w,D.y):lt(q,w,D.x),{p1:z,p2:D,r1:tt,r2:st}}),ot=new Set;s.type==="schema"&&s.edges.forEach((h,x)=>{Math.abs(s.byId.get(h.from).col-s.byId.get(h.to).col)>1&&ot.add(x)});const L=new Map,F=new Set;s.edges.forEach((h,x)=>{if(ot.has(x))return;const[$,w]=A[x],{p1:_,p2:q}=j[x],R=s.byId.get(h.from),Q=s.byId.get(h.to);let X=null,z=null,D=!1;if($===w){if(nt($)){const V=$==="right"?Math.max(B(R),B(Q)):Math.min(B(R),B(Q))-1,P=l.cols[V-1],U=l.cols[V];P&&U&&(X=`c${V}`,z=[P[1],U[0]],D=!0)}else{const V=$==="bottom"?Math.max(R.row2,Q.row2):Math.min(R.row,Q.row)-1,P=l.rows[V-1],U=l.rows[V];P&&U&&(X=`r${V}`,z=[P[1],U[0]],D=!1)}X&&F.add(x)}else if(nt($)&&nt(w)&&Math.abs(_.y-q.y)>.5){const V=B(Q),P=w==="left",U=l.cols[(P?V-1:V)-1],et=l.cols[(P?V:V+1)-1];U&&et&&(X=`c${P?V-1:V}`,z=[U[1],et[0]],D=!0)}else if(!nt($)&&!nt(w)&&Math.abs(_.x-q.x)>.5){const P=w==="top"?Q.row-1:Q.row2,U=l.rows[P-1],et=l.rows[P];U&&et&&(X=`r${P}`,z=[U[1],et[0]],D=!1)}if(!X||!z)return;L.has(X)||L.set(X,{span:z,vertical:D,members:new Map});const tt=`${h.to}.${w}.${Math.round(D?q.y:q.x)}`,st=L.get(X);st.members.has(tt)||st.members.set(tt,[]),st.members.get(tt).push(x)});const I=new Map,M=h=>{const[x,$]=A[h],{p1:w,p2:_}=j[h];if(nt(x)&&nt($)){if(x===$){const R=I.get(h)??(x==="right"?Math.max(w.x,_.x)+u("4"):Math.min(w.x,_.x)-u("4"));return[w,{x:R,y:w.y},{x:R,y:_.y},_]}if(Math.abs(w.y-_.y)<=.5)return[w,{x:_.x,y:w.y}];const q=I.get(h)??(w.x+_.x)/2;return[w,{x:q,y:w.y},{x:q,y:_.y},_]}if(!nt(x)&&!nt($)){if(x===$){const R=I.get(h)??(x==="bottom"?Math.max(w.y,_.y)+u("4"):Math.min(w.y,_.y)-u("4"));return[w,{x:w.x,y:R},{x:_.x,y:R},_]}if(Math.abs(w.x-_.x)<=.5)return[w,{x:w.x,y:_.y}];const q=I.get(h)??(w.y+_.y)/2;return[w,{x:w.x,y:q},{x:_.x,y:q},_]}return nt(x)?[w,{x:_.x,y:w.y},_]:[w,{x:w.x,y:_.y},_]},O=h=>{const x=s.edges[h],$=Ot(x.kind,i),w=M(h),_=ue(w,$,c);let q;return w.length===_.length&&(q=pt(w).map(([R,Q])=>Math.abs(R.y-Q.y)<.75?(R.y+Q.y)/2:(R.x+Q.x)/2),q[0]=j[h].r1,q.length>1&&(q[q.length-1]=j[h].r2)),{i:h,from:x.from,to:x.to,kind:x.kind,pts:_,tip:_[_.length-1],dir:Ht(_),dot:x.fk?_[0]:void 0,width:$,axes:q}},N=()=>s.edges.flatMap((h,x)=>ot.has(x)?[]:[O(x)]);let G=null;const W=h=>{G??(G=N());const x=G.map($=>h.has($.i)?O($.i):$);return{lines:x,score:$n(x,h)*1e5+Ct(x,void 0,h).length*1e3+Dt(x.filter($=>h.has($.i)),p,s).length}},Y=(h,x)=>{const $=h.flatMap(w=>{const{p1:_,p2:q}=j[w];return x?[_.y,q.y]:[_.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,h]of L){const x=[...h.members.values()].map(w=>({members:w,run:Y(w,h.vertical)})).sort((w,_)=>w.run[0]-_.run[0]),$=[];for(const w of x){const _=$[$.length-1];_&&_.some(q=>q.run[0]<w.run[1]+u("8")&&w.run[0]<q.run[1]+u("8"))?_.push(w):$.push([w])}for(const w of $){if(w.length===1&&w[0].members.every(tt=>F.has(tt)))continue;const _=w.map(tt=>tt.members),q=_.length,R=(h.span[1]-h.span[0])/(q+1);R<u("3")&&d?.(`a gutter holds ${q} lanes side by side, closer than space-3`);const Q=new Set(_.flat());let X=_,z=1/0,D=null;for(const tt of ve(_)){tt.forEach((V,P)=>V.forEach(U=>I.set(U,h.span[0]+R*(P+1))));const st=W(Q);st.score<z&&(z=st.score,X=tt,D=st.lines)}X.forEach((tt,st)=>tt.forEach(V=>I.set(V,h.span[0]+R*(st+1)))),G=D}}E.lines=N();for(const h of ot)d?.(`${s.edges[h].from} to ${s.edges[h].to} is two columns apart, so its line is not drawn; its row still writes the target`);E.crossings=Ct(E.lines),E.through=Dt(E.lines,p,s),E.outside=xe(E.lines,f,S,i);const{obstacles:K,groups:g}=$e(r,a,o,C);K.heads=E.lines.map(h=>me(h,i));const b=yn(s,E.lines,p,K,g,{l:0,t:0,r:f,b:S},i,e,{ox:m,oy:v});return E.labels=b.labels,E.unseated=b.unseated,E.bounded=b.bounded,E.overlaps=[...new Set(we(E.lines,null).flat())],E}function $n(t,e){return we(t,e).length}function we(t,e){const n=[];for(let s=0;s<t.length;s++)for(let i=s+1;i<t.length;i++){const o=t[s],r=t[i];if(e&&!e.has(o.i)&&!e.has(r.i)||o.to===r.to&&Math.abs(o.tip.x-r.tip.x)<1&&Math.abs(o.tip.y-r.tip.y)<1)continue;const a=(o.width+r.width)/2+.5;for(const[d,u]of pt(o.pts))for(const[y,p]of pt(r.pts)){const l=Math.abs(d.y-u.y)<.01,m=Math.abs(y.y-p.y)<.01;if(l!==m)continue;const[v,c]=l?[d.y,y.y]:[d.x,y.x];if(Math.abs(v-c)>=a)continue;const[f,S]=l?[d.x,u.x]:[d.y,u.y],[B,C]=l?[y.x,p.x]:[y.y,p.y];Math.min(Math.max(f,S),Math.max(B,C))-Math.max(Math.min(f,S),Math.min(B,C))>1&&n.push([o.i,r.i])}}return n}function*ve(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e<t.length;e++){const n=t.slice(0,e).concat(t.slice(e+1));for(const s of ve(n))yield[t[e],...s]}}function xe(t,e,n,s){const i=[];for(const o of t)o.pts.some((r,a)=>{const d=a===o.pts.length-1?Math.max(o.width/2,s.head/2):o.width/2;return r.x-d<-.5||r.x+d>e+.5||r.y-d<-.5||r.y+d>n+.5})&&i.push(o.i);return i}function Dt(t,e,n){const s=[];for(const i of t){const o=pt(i.pts);e.some(r=>o.some(([a,d])=>dn(a,d,r)))&&s.push(i.i)}return s}function wn(t,e,n){const{m:s,tk:i,P:o,drawing:r,origin:a}=t,d=i.space,u=new Map;r.querySelectorAll(`.${o}-node`).forEach(E=>u.set(E.dataset.node,ft(E,a)));const y=r.querySelector(`.${o}-steps`),p=y?ft(y,a).b:e.h,l=E=>{const A=u.get(E);return A?n.x((A.l+A.r)/2,i.hair):0};for(const E of s.nodes){const A=u.get(E.id);A&&e.lifelines.push({x:l(E.id),y1:A.b,y2:p})}const m=E=>u.get(E.id),v=new Map;r.querySelectorAll(`.${o}-msg`).forEach(E=>{const A=ft(E,a);v.set(Number(E.querySelector(`.${o}-num`)?.textContent??0),(A.t+A.b)/2)});const c=i.activation,f=c/2,S=E=>{const A=s.byId.get(E.who);if(!A)return null;const T=l(E.who),j=(A.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),ot=(E.depth-1)*d("1")*j,L=v.get(E.from)??0,F=v.get(E.to)??L,I=E.from===E.to;return{l:n.x(T-f+ot,i.hair),r:n.x(T+f+ot,i.hair),t:n.y(I?L-d("2")-d("1"):L,i.hair),b:n.y(I?L+d("2")+d("1"):F,i.hair)}},B=s.bars.map(E=>({bar:E,rect:S(E)})).filter(E=>E.rect);e.bars=B.map(E=>E.rect);const C=(E,A,T)=>B.filter(({bar:Z})=>Z.who===E&&Z.to>=A&&(T?Z.from<=A:Z.from<A||Z.from===A&&Z.to===A)).sort((Z,j)=>j.bar.depth-Z.bar.depth)[0]?.rect;return r.querySelectorAll(`.${o}-msg`).forEach(E=>{const A=E.dataset.from,T=E.dataset.to,Z=E.dataset.kind??"plain",j=Ot(Z,i),ot=ft(E,a),L=n.y((ot.t+ot.b)/2,j),F=Number(E.querySelector(`.${o}-num`)?.textContent??0);let I=l(A),M=l(T),O;if(A===T){const b=E.dataset.self==="start"?-d("6"):d("6"),h=C(A,F,!0),x=h?b>0?h.r:h.l:I,$=n.y(L-d("2"),j),w=n.y(L+d("2"),j);O=[{x,y:$},{x:n.x(I+b,j),y:$},{x:n.x(I+b,j),y:w},{x,y:w}]}else{const b=M>I?1:-1,h=C(A,F,!1),x=C(T,F,!0);h&&(I=b>0?h.r:h.l),x&&(M=b>0?x.l:x.r),O=[{x:I,y:L},{x:M,y:L}]}e.lines.push({i:F,from:A,to:T,kind:Z,pts:O,tip:O[O.length-1],dir:Ht(O),width:j});const N=E.querySelector(`.${o}-said`),G=E.querySelector(`.${o}-note`),W=s.byId.get(A),Y=s.byId.get(T);if(!W||!Y)return;const K=A===T?(()=>{const b=s.nodes[W.i+(E.dataset.self==="start"?-1:1)],h=b?l(b.id):E.dataset.self==="start"?0:e.w;return Math.abs(h-I)-d("6")-d("2-5")-d("2")})():Math.abs(M-I)-2*d("2");Math.max(N?N.getBoundingClientRect().width:0,G?G.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(F)}),r.querySelectorAll(`.${o}-fhead`).forEach(E=>{const A=E.parentElement?.querySelector(`:scope > .${o}-fbox`);if(!A)return;[...E.children].reduce((Z,j)=>Z+j.getBoundingClientRect().width,0)+d("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${E.querySelector(`.${o}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ke(t,e,n,s=ht()){const{m:i,tk:o,P:r,drawing:a,origin:d}=t,u=o.space,y=ge(i,a,d,r),p=[...y.values()],l=d.left-Math.floor(d.left),m=d.top-Math.floor(d.top),v=fe(l,m),c=a.clientWidth,f=a.clientHeight,S={w:c,h:f,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:m},B=ht();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:B};const C=c-(parseFloat(getComputedStyle(a).paddingRight)||0),E=(M,O,N)=>{const G=[M];for(let W=1;W<=(yt(s,O)??0);W++)G.push({...M,t:M.t+N*u("4")*W,b:M.b+N*u("4")*W});return G},A=new Map;a.querySelectorAll(`.${r}-node`).forEach(M=>{const O=M.parentElement,N=ft(O,d),G=getComputedStyle(O);A.set(M.dataset.node,N.r-(parseFloat(G.paddingRight)||0)-(parseFloat(G.borderRightWidth)||0))});const T=i.nodes,Z=M=>y.get(T[M].id),j=[],ot=M=>Ot(i.edges[M].kind,o);i.edges.forEach((M,O)=>{const N=n.routes[O],G=y.get(M.from),W=y.get(M.to),Y=ot(O);let K=[];const g=M.label,b=g?e(g,"label"):0,h=g?16*Tt(g):16,x=u("4");if(N==="down"||N==="up"){const w=Math.max(G.rect.l,W.rect.l),_=Math.min(G.rect.r,W.rect.r),q=i.edges.map((z,D)=>({o:z,j:D})).filter(({o:z,j:D})=>(n.routes[D]==="down"||n.routes[D]==="up")&&(z.from===M.from&&z.to===M.to||z.from===M.to&&z.to===M.from)),R=q.findIndex(z=>z.j===O),Q=q.length<2?.5:q.length===2?R===0?.25:.75:(R+1)/(q.length+1),X=v.x(w+(_-w)*Q,Y);if(K=N==="down"?[lt(G,"bottom",X),lt(W,"top",X)]:[lt(G,"top",X),lt(W,"bottom",X)],g){let z=Math.min(K[0].y,K[1].y),D=Math.max(K[0].y,K[1].y);N==="down"?D-=o.head:z+=o.head;const tt=[...a.querySelectorAll(`.${r}-group`)].map(U=>ft(U,d));let st=[[z,D]];for(const U of tt)for(const et of[U.t,U.b])st=st.flatMap(([rt,ct])=>et>rt+1&&et<ct-1?[[rt,et],[et,ct]]:[[rt,ct]]);const V=(U,et)=>tt.some(rt=>(U+et)/2>rt.t&&(U+et)/2<rt.b&&X>rt.l&&X<rt.r);if(st.length>1){const U=st.filter(([rt,ct])=>!V(rt,ct));[z,D]=(U.length?U:st).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const P=[1/2,1/3,2/3].map(U=>{const et=z+(D-z)*U;return{l:X-b/2-u("1"),r:X+b/2+u("1"),t:et-h/2,b:et+h/2}});j.push({k:O,cands:P,on:!0,card:N==="down"?M.to:M.from})}}else if(N==="trunk"||N==="rail"){const w=v.x(Math.max(G.rect.l,N==="rail"?W.rect.l:G.rect.l)+u(N==="trunk"?"8":"3"),Y),_=lt(G,"bottom",w);if(N==="rail"){if(K=[_,lt(W,"top",w)],g){const q=W.rect.t-u("6");j.push({k:O,cands:E({l:w+u("2-5"),r:w+u("2-5")+b,t:q-h/2,b:q+h/2},M.to,-1),on:!1,card:M.to})}}else{const q=v.x(W.rect.l+u("6"),Y),R=v.y(W.rect.t-x,Y);K=[_,{x:w,y:R},{x:q,y:R},lt(W,"top",q)],g&&j.push({k:O,cands:E({l:q+u("2-5"),r:q+u("2-5")+b,t:R-h/2,b:R+h/2},M.to,-1),on:!1,card:M.to})}}else{const w=Math.min(A.get(M.from)??c,A.get(M.to)??c),_=v.x(n.gutter?C+(n.lanes[O]?2*u("3-5"):u("3-5")):w-u("2-5"),Y),q=v.y(G.rect.t+(G.rect.b-G.rect.t)*n.exits[O],Y),R=lt(G,"right",q),Q=v.x(W.rect.r-u("6"),Y),X=N==="end-down",z=v.y(X?W.rect.t-x:W.rect.b+x,Y);K=[R,{x:_,y:R.y},{x:_,y:z},{x:Q,y:z},lt(W,X?"top":"bottom",Q)];const D=X?M.to:T[W.i+1]?.id??M.to;g&&j.push({k:O,cands:E({l:Q-u("2-5")-b,r:Q-u("2-5"),t:z-h/2,b:z+h/2},D,X?-1:1),on:!1,card:D})}const $=ue(K,Y,v);S.lines.push({i:O,from:M.from,to:M.to,kind:M.kind,pts:$,tip:$[$.length-1],dir:Ht($),width:Y})}),S.crossings=Ct(S.lines),S.through=Dt(S.lines,p,i),S.outside=xe(S.lines,c,f,o);const{obstacles:L}=$e(a,d,r,0);L.heads=S.lines.map(M=>me(M,o));const F=[],I={l:0,t:0,r:c,b:f};for(const M of j){const O=W=>{const Y=ce(W,u("1"));return W.l<I.l-.5||W.r>I.r+.5||W.t<I.t-.5||W.b>I.b+.5||p.some(K=>de(Y,K))||F.some(K=>ut(Y,K))||L.heads.some(K=>ut(Y,K))||L.rects.some(K=>ut(Y,K))||S.lines.some(K=>K.i!==M.k&&pt(K.pts).some(([g,b])=>ut(Y,ye(g,b,K.width))))},N=M.cands.find(W=>!O(W));N||(B[M.card]=(B[M.card]??0)+1,S.unseated.push(M.k));const G=N?be(N,l,m,W=>!O(W)):M.cands[0];F.push(G),S.labels.push({i:M.k,text:i.edges[M.k].label,box:G,on:M.on})}return{geo:S,grow:B}}function vn(t,e){const n=o=>String(Math.round(o*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let o=1;o<t.length-1;o++){const r=t[o-1],a=t[o],d=t[o+1],u=Math.hypot(a.x-r.x,a.y-r.y),y=Math.hypot(d.x-a.x,d.y-a.y),p=Math.min(e,u/2,y/2);if(p<.5){s+=`L${n(a.x)} ${n(a.y)}`;continue}const l={x:a.x+(r.x-a.x)/u*p,y:a.y+(r.y-a.y)/u*p},m={x:a.x+(d.x-a.x)/y*p,y:a.y+(d.y-a.y)/y*p};s+=`L${n(l.x)} ${n(l.y)}Q${n(a.x)} ${n(a.y)} ${n(m.x)} ${n(m.y)}`}const i=t[t.length-1];return`${s}L${n(i.x)} ${n(i.y)}`}var xn={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function kn(t,e,n,s,i){const o=xn[e.dir],r=e.kind==="dashed",a=n.head,d=n.head/2,u=r?1:a-1,y=e.pts.map(E=>({...E})),p=y[y.length-1];p.x-=o.x*u,p.y-=o.y*u;const l=e.tip.x-o.x*a,m=e.tip.y-o.y*a,v=-o.y*d,c=o.x*d,f=E=>Math.round(E*100)/100,S=it(e.kind),B=r?`<path class="${t}-tip" data-kind="${S}" data-open="" d="M${f(l+v)} ${f(m+c)}L${f(e.tip.x)} ${f(e.tip.y)}L${f(l-v)} ${f(m-c)}"/>`:`<path class="${t}-tip" data-kind="${S}" d="M${f(e.tip.x)} ${f(e.tip.y)}L${f(l+v)} ${f(m+c)}L${f(l-v)} ${f(m-c)}Z"/>`,C=e.dot?`<circle class="${t}-dot" cx="${f(e.dot.x)}" cy="${f(e.dot.y)}" r="${n.dot/2}"/>`:"";return`<g class="${t}-edge" data-edge="${e.i}" data-from="${it(e.from)}" data-to="${it(e.to)}"><path class="${t}-line" data-kind="${S}" d="${vn(y,i)}"${s?` mask="url(#${it(s)})"`:""}/>${B}${C}</g>`}function Me(t,e,n,s){const i=new Map,o=new Map;for(const a of e.crossings)o.has(a.under)||o.set(a.under,[]),o.get(a.under).push(a);let r="";for(const[a,d]of o){const u=`${s}-cut-${a}`;i.set(a,u);const y=d.map(p=>{const l=e.lines[p.top],m=e.lines[p.under],v=l.width/2+n.cut,c=m.width/2+1;return p.underVertical?`<rect x="${p.at.x-c}" y="${p.at.y-v}" width="${2*c}" height="${2*v}" fill="black"/>`:`<rect x="${p.at.x-v}" y="${p.at.y-c}" width="${2*v}" height="${2*c}" fill="black"/>`}).join("");r+=`<mask id="${it(u)}" maskUnits="userSpaceOnUse" x="0" y="0" width="${e.w}" height="${e.h}"><rect x="0" y="0" width="${e.w}" height="${e.h}" fill="white"/>${y}</mask>`}return{defs:r,ids:i}}function Se(t,e,n,s){const{defs:i,ids:o}=Me(t,e,n,s),r=e.lifelines.map(y=>`<path class="${t}-life" d="M${y.x} ${y.y1}V${y.y2}"/>`).join("")+(e.bars??[]).map(y=>`<rect class="${t}-bar" x="${y.l}" y="${y.t}" width="${Math.round((y.r-y.l)*100)/100}" height="${Math.round((y.b-y.t)*100)/100}"/>`).join(""),a=e.lines.map((y,p)=>kn(t,y,n,o.get(p)??null,y.from===y.to?n.radiusXs:n.radius)).join(""),d=`<svg class="${t}-svg" width="${e.w}" height="${e.h}" viewBox="0 0 ${e.w} ${e.h}" focusable="false">${i?`<defs>${i}</defs>`:""}${r}<g class="${t}-edges">${a}</g></svg>`,u=e.labels.map(y=>`<span class="${t}-label" data-edge="${y.i}"${y.on?' data-on=""':""}${Tt(y.text)>1?' data-lines="2"':""} style="left:${Math.round(y.box.l*100)/100}px;top:${Math.round(y.box.t*100)/100}px;width:${Math.round((y.box.r-y.box.l)*100)/100}px">${y.text.split(` -`).map(it).join("<br>")}</span>`).join("");return d+u}function Gt(t,e,n,s,i,o,r,a){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const y=ln(t),p=un(u,n),l=hn(e,y,p);a?.(l.least);const m=t.clientWidth,v=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),c=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:v&&L.layout!=="drawn"?v:void 0};let f=!1;const S=L=>{if(f=!1,e.type!=="flowchart")return L;o({...L,heights:void 0,words:void 0});const F=ht(),I=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const O=M.querySelector(`.${n}-words`);if(!O)return;const N=M.getBoundingClientRect(),G=K=>{const g={w:K.width+2*y.space("2-5"),h:K.height+2*y.space("2")},b=1-g.w/N.width,h=b>.05?g.h/2/b:g.h*10;return Math.max(y.space("16"),Math.ceil(N.width/5),Math.ceil(2*h))},W=O.getBoundingClientRect();let Y=G(W);if(Y>N.width){const K=x=>(M.style.setProperty("--_ww",`${x}px`),O.getBoundingClientRect()),g=Math.floor(M.clientWidth-2*y.space("2-5"));let b=Math.ceil(W.width),h=W.height;for(;b<g&&K(g).height<h-.5;){let x=b,$=g;for(;$-x>1;){const q=x+$>>1;K(q).height<h-.5?$=q:x=q}const w=K($),_=G(w);if(_<=N.width){Y=_,I[M.dataset.node]=$;break}b=$,h=w.height}M.style.removeProperty("--_ww")}F[M.dataset.node]=Y,Y>N.width&&(f=!0)}),{...L,heights:F,words:Object.keys(I).length?I:void 0}},B=()=>({m:e,tk:y,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:r}),C=i.autoOpen?{open:!1,autoOpen:void 0}:{},E=(L,F)=>F.map(I=>Et(e,L.lines.find(M=>M.i===I))).join(", ");if(m>=l.least&&!e.unplaced){const L=O=>{let N=c({...i,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return N=S(N),o(N),{dd:N,g:bn(B(),p)}};let{dd:F,g:I}=L(!1);const M=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||f;if(!M(I)&&I.unseated.length&&I.unseated.every(O=>I.bounded?.includes(O))){const O=L(!0);!M(O.g)&&!O.g.unseated.length&&({dd:F,g:I}=O)}if(!M(I)&&!I.unseated.length)return I.crossings.length&&r?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(O=>`${Et(e,I.lines[O.top])} over ${Et(e,I.lines[O.under])}`).join("; ")}`),{dyn:F,geo:I,ink:Se(n,I,y,s),tokens:y,least:l.least};f&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: a decision would be taller than it is wide`),I.misfit?.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: ${I.misfit.join("; ")}`),I.through.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: ${E(I,I.through)} would pass through a node`),I.overlaps?.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: ${E(I,I.overlaps)} would lie on one another`),I.outside.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: ${E(I,I.outside)} would leave the drawing`),I.unseated.length&&r?.(`the drawn layout does not fit at ${Math.round(m)}px: no clean seat for ${I.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=c({...i,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(A=S(A),o(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:y,least:l.least};const T=ne(e);let Z=ke(B(),p,T,A.grow);for(let L=0;L<6&&Object.keys(Z.grow).length;L++){const F=ht(A.grow);for(const[I,M]of Object.entries(Z.grow))F[I]=(yt(F,I)??0)+M;A={...A,grow:F},o(A),Z=ke(B(),p,T,F)}const j=Z.geo;if(j.unseated.length>0||j.through.length>0||j.outside.length>0||T.third){j.unseated.length&&r?.(`the stacked drawing has no clean seat for ${[...new Set(j.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),j.through.length&&r?.(`in the stacked drawing ${E(j,j.through)} would pass through a node, so its lines are not drawn`),j.outside.length&&r?.(`in the stacked drawing ${E(j,j.outside)} would leave the drawing, so its lines are not drawn`),T.third&&r?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={...j,lines:[],labels:[],crossings:[]};return{dyn:c({...A,grow:ht(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:y,least:l.least}}return j.crossings.length&&r?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${j.crossings.map(L=>`${Et(e,j.lines[L.top])} over ${Et(e,j.lines[L.under])}`).join("; ")}`),{dyn:A,geo:j,ink:Se(n,j,y,s),tokens:y,least:l.least}}function Et(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Mn(t,e,n,s,i,o){const r=new Set;if(o){r.add(o);for(const c of n?.lines??[])c.from===o&&r.add(c.to),c.to===o&&r.add(c.from)}if(t.toggleAttribute("data-tracing",!!o),t.querySelectorAll(`.${e}-node`).forEach(c=>c.toggleAttribute("data-near",r.has(c.dataset.node))),!n||!s)return;const a=c=>!!o&&(c.from===o||c.to===o),d=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(c=>u.set(c.getAttribute("data-edge"),c));for(const c of n.lines){const f=u.get(String(c.i));f&&(f.toggleAttribute("data-lit",a(c)),f.toggleAttribute("data-dim",!!o&&!a(c)))}if(t.querySelectorAll(`.${e}-label`).forEach(c=>{const f=n.lines.find(S=>String(S.i)===c.dataset.edge);c.toggleAttribute("data-lit",!!(f&&a(f)))}),d){for(const c of n.lines)if(a(c)){const f=u.get(String(c.i));f&&d.appendChild(f)}}const y=Ct(n.lines,a),{defs:p,ids:l}=Me(e,{...n,crossings:y},s,i),m=t.querySelector(`.${e}-svg`);if(!m)return;let v=m.querySelector("defs");!v&&p&&(v=document.createElementNS("http://www.w3.org/2000/svg","defs"),m.insertBefore(v,m.firstChild)),v&&(v.innerHTML=p),n.lines.forEach((c,f)=>{const S=u.get(String(c.i))?.querySelector(`.${e}-line`);if(!S)return;const B=l.get(f);B?S.setAttribute("mask",`url(#${B})`):S.removeAttribute("mask")})}var Sn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function En(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Sn()||Ln(t)?"done":"pending")}}var An=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Ln(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(An(t))!==null}catch{return!1}}function Ee(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function qn(t,e,n,s=!1,i=!1){const o=s?It(t):null;if(o&&n.startsWith("Arrow")){const u={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?o[e]?.[u]??null:null}const r=t.byId.get(e)?.i??0,a=t.nodes.length;let d;if(n==="ArrowRight"||n==="ArrowDown")d=r+1;else if(n==="ArrowLeft"||n==="ArrowUp")d=r-1;else if(n==="Home")d=0;else if(n==="End")d=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,d))].id}var In=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden"],Ae=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],On=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],Le=t=>t==null||t===!1;function _n(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Kt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?Ae:In;for(const r of s)Le(e.a[r])&&t.removeAttribute(r);for(const[r,a]of Object.entries(e.a)){if(r==="class")continue;if(r==="style"){const u=t.style,y=new Map(String(a??"").split(";").map(p=>{const l=p.indexOf(":");return[p.slice(0,l).trim(),p.slice(l+1).trim()]}).filter(([p])=>p));for(const[p,l]of y)u.getPropertyValue(p).trim()!==l&&u.setProperty(p,l);for(const p of On)y.has(p)||u.removeProperty(p);continue}if(n&&!Ae.includes(r))continue;if(Le(a)){t.removeAttribute(r);continue}const d=a===!0?"":String(a);t.getAttribute(r)!==d&&t.setAttribute(r,d)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(r=>typeof r!="string"&&"slot"in r))return;const i=[...t.children];let o=0;for(const r of e.c)if(!(typeof r=="string"||"slot"in r)){for(let a=o;a<i.length;a++)if(_n(i[a],r)){Kt(i[a],r,!1),o=a+1;break}}}function Cn(t,e,n,s){if(n===s)return;const i=o=>t.querySelector(`.${e}-node[data-node="${CSS.escape(o)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function i(l,m,v){return{prefix:n,base:l,hasSource:m.source!==void 0&&m.source!==null&&m.source!=="",hiddenClass:"visually-hidden",viewer:v?v.keys:void 0}}function o(l,m,v,c){var f=function(S){return'<kbd class="kbd">'+it(S)+"</kbd>"};return{source:it(String(m.source||"")),summary:it(String(m.summary||"")),hint:zt(l).map(function(S){return"<span>"+S.keys.map(f).join(" ")+" "+it(S.words)+"</span>"}).join(""),toggle:'<button type="button" class="btn diagram-toggle" data-variant="secondary" data-size="sm" aria-expanded="'+(c?"true":"false")+'" aria-controls="'+it(v)+'-list"><span>'+(c?"Hide the list":"View as list")+"</span></button>"}}function r(l,m,v){var c=Mt(l),f=Ft(c,{},i(m,l,v)),S=Rt(f,o(c,l,m,!1)),B=S.indexOf(">");return{open:S.slice(0,B+1),inner:S.slice(B+1,S.length-9),warnings:c.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],d=["--_cols","--_gpad","--_track"];function u(l,m,v,c){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(l).direction==="rtl",B=m.layout==="auto"&&(m.type==="architecture"||m.type==="flowchart"||m.type==="schema"),C=B?Array.isArray(m.placement)?m.placement:m.placement?[m.placement]:[]:[];B&&!C.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var E=m.direction?[m.direction]:m.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var J=0;J<C.length;J++)if(C[J].direction===H)return C[J]},T=Mt(m,{rtl:S,placement:B?A(E[0]):void 0});if(!v||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var Z=r(m,f,c),j=document.createElement("div");j.innerHTML=Z.open+"</figure>";var ot=j.firstChild;a.forEach(function(H){l.removeAttribute(H)}),d.forEach(function(H){l.style.removeProperty(H)});for(var L=0;L<ot.attributes.length;L++){var F=ot.attributes[L];F.name==="class"?l.classList.add.apply(l.classList,F.value.split(" ")):F.name==="style"?l.style.cssText=F.value+";"+l.style.cssText:l.setAttribute(F.name,F.value)}l.querySelectorAll(":scope > :not(script[data-diagram])").forEach(function(H){H.remove()}),l.insertAdjacentHTML("beforeend",Z.inner)}T.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var I=i(f,m,c),M={},O=null,N=null,G=null,W=null,Y=Object.create(null),K=function(H){Y[H]||(Y[H]=1,console.warn("Basalt diagram: "+H))},g=function(H){Kt(l,Ft(T,H,I))},b=l.querySelector(".diagram-ink"),h=l.querySelector(".diagram-toggle"),x=!c&&T.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,_=function(){x&&Ee(l)};function q(){Mn(l,n,O&&O.geo,O&&O.tokens,f,N||W||G),X()}var R=null,Q=!c&&matchMedia("(hover: none), (pointer: coarse)").matches;function X(){var H=Q&&!c&&b&&b.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(Q&&!c)),H&&!R){var J=l.querySelector(":scope > .diagram-foot");if(!J)return;R=document.createElement("button"),R.type="button",R.className="btn diagram-clear",R.setAttribute("data-variant","secondary"),R.setAttribute("data-size","sm"),R.innerHTML="<span>Clear highlight</span>",R.addEventListener("click",function(){W&&(W=null,q())}),J.appendChild(R)}else!H&&R&&(R.remove(),R=null);R&&(W?R.removeAttribute("aria-disabled"):R.setAttribute("aria-disabled","true"))}function z(H){if(!H.defaultPrevented){var J=Ge(l,n,H,W);J!==void 0&&(_(),Q=!0,W=J,q())}}function D(){h&&(h.setAttribute("aria-expanded",String(!!M.open)),h.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function tt(){if(B&&C.length>1&&!c){for(var H=null,J=0;J<E.length&&!H;J++){var dt=A(E[J]);if(dt){var kt=Mt(m,{rtl:S,placement:dt}),Bn=Gt(l,kt,n,f,{},function(jt){Kt(l,Ft(kt,jt,I))});Bn.dyn.layout==="drawn"&&(H=kt)}}T=H||Mt(m,{rtl:S,placement:A(E[0])})}O=(c?c.measure:Gt)(l,T,n,f,M,g,K),M=O.dyn,g(M),D();var Zt=l.querySelector(":scope > .diagram-hint");if(Zt){var Be=zt(T,M.layout==="drawn").map(function(jt){return"<span>"+jt.keys.map(function(Tn){return'<kbd class="kbd">'+it(Tn)+"</kbd>"}).join(" ")+" "+it(jt.words)+"</span>"}).join("");Zt.innerHTML!==Be&&(Zt.innerHTML=Be)}mt(T,M)||(G=W=null);var Te=b&&O.ink!==w;Te&&(b.innerHTML=O.ink,w=O.ink),q(),x&&O.tokens&&(En(l,!!(O.geo&&O.geo.lines.length)),Te&&$&&$.redrawn()),c&&c.onMeasured&&O.tokens&&c.onMeasured(O,l)}function st(H){M=H,g(M)}function V(H){var J=M.stop;M=Object.assign({},M,{stop:H}),Cn(l,n,J,H)}var P=function(H){var J=H&&H.closest?H.closest(".diagram-node"):null;return J&&l.contains(J)?J:null};function U(H){var J=P(H.target);if(!(!J||H.defaultPrevented)){if(_(),H.key==="Escape"){!c&&(N||G||W)&&(H.preventDefault(),N=G=W=null,q());return}if(mt(T,M)){var dt=qn(T,J.getAttribute("data-node"),H.key,M.layout==="drawn");if(dt){H.preventDefault(),V(dt);var kt=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');kt&&kt.focus()}}}}function et(H){var J=P(H.target);if(J){_();var dt=J.getAttribute("data-node");N=J.matches(":focus-visible")?dt:null,mt(T,M)&&M.stop!==dt&&V(dt),q()}}function rt(H){var J=P(H.target);J&&(P(H.relatedTarget)||(N=null),M.keep===J.getAttribute("data-node")&&st(Object.assign({},M,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var J=P(H.target);J&&_();var dt=J&&mt(T,M)?J.getAttribute("data-node"):null;dt!==G&&(G=dt,q())}}function At(){G&&(G=null,q())}function bt(){_(),st(Object.assign({},M,{open:!M.open,autoOpen:void 0})),D()}l.addEventListener("keydown",U),l.addEventListener("focusin",et),l.addEventListener("focusout",rt),l.addEventListener("pointerover",ct),l.addEventListener("pointerleave",At),l.addEventListener("click",z),h&&h.addEventListener("click",bt),tt();var xt=l.clientWidth,Vt=0,qe=!0,Ie=new ResizeObserver(function(){Math.abs(l.clientWidth-xt)<.5||(xt=l.clientWidth,cancelAnimationFrame(Vt),Vt=requestAnimationFrame(tt))});Ie.observe(l),document.fonts&&document.fonts.ready.then(function(){qe&&tt()});var Oe=matchMedia("(forced-colors: active)"),_e=T.nodes.some(function(H){return H.mark});_e&&Oe.addEventListener("change",tt),x&&($=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return T},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},m));var Ce=!c&&m.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,m,{model:T,settle:_,animated:x}):null,je=l.querySelector(":scope > .diagram-foot"),jn=!c&&m.export===!0&&je&&typeof e.diagramExport=="function"?e.diagramExport(je,l):[];l.__diagram={stop:function(){Ce&&Ce.destroy(),jn.forEach(function(H){H.remove()}),qe=!1,Ie.disconnect(),cancelAnimationFrame(Vt),_e&&Oe.removeEventListener("change",tt),$&&$.destroy(),l.removeEventListener("keydown",U),l.removeEventListener("focusin",et),l.removeEventListener("focusout",rt),l.removeEventListener("pointerover",ct),l.removeEventListener("pointerleave",At),l.removeEventListener("click",z),R&&R.remove(),h&&h.removeEventListener("click",bt)},layout:tt,key:y(m),send:$&&$.sendValue?$.sendValue:null}}function y(l){try{return JSON.stringify(l,function(m,v){return m==="packet"&&v&&typeof v=="object"?Object.assign({},v,{send:void 0}):v})}catch{return null}}function p(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var m=l.querySelector(":scope > script[data-diagram]");if(m)try{u(l,JSON.parse(m.textContent),!0)}catch(v){console.error("Basalt diagram: this figure could not be drawn",v)}}})}e.diagramMarkup=r,e.diagramKit={draw:u,buildModel:Mt,figureKey:Xe,figureList:on,hintEntries:zt,toHtml:Rt,escapeHtml:it,settleEntrance:Ee,measureFigure:Gt},t.diagram=function(l,m){var v=l.__diagram,c=v&&v.send?y(m):null;if(c!==null&&c===v.key){v.send(m.packet?m.packet.send:void 0);return}u(l,m)},e.step(62,"wireDiagrams",p)})(window.Basalt)})(); +`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Xt(t,e){return t.legend[e]}function Fe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function He(t,e){return $t(t,`sentence:${e.i}`,()=>De(t,e))}function De(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const a=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name})`);a.length&&n.push(`References ${a.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const a=t.steps.filter(o=>"n"in o&&o.from===e.id).length,i=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${a} ${a===1?"message":"messages"} and receives ${i}.`);const r=Yt(t,e);r&&n.push(r.trim())}else{const a=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Fe(t,e):e.kind;if(n.push(wt(a?`${e.name}, ${a}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const o=t.groups.find(c=>c.id===e.group),s=o?.parent?t.groups.find(c=>c.id===o.parent):void 0;o&&n.push(s?`In ${o.label}, in ${s.label}.`:`In ${o.label}.`)}const i=t.edges.filter(o=>o.to===e.id).map(o=>`${t.byId.get(o.from).name}${o.label?` (${gt(o.label)})`:""}`),r=t.edges.filter(o=>o.from===e.id).map(o=>`${t.byId.get(o.to).name}${o.label?` (${gt(o.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Yt(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function Ge(t,e,n,a){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),o=n.target;if(!r||!o||!r.contains(o)||!t.querySelector(`.${e}-edge`))return;const s=o.closest(`.${e}-node`);if(!s?.hasAttribute("href"))return s?s.dataset.node===a?null:s.dataset.node??null:null}function Qt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const a=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&a.push(i);return{t,a:e??{},c:a}}var Ke={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>Ke[e]),Ve=" br img input meta link hr path polygon polyline circle rect line ";function Rt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[a,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(a))throw new Error(`diagram: "${a}" is not an attribute name`);n+=i===!0?` ${a}`:` ${a}="${it(String(i))}"`}return Ve.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(a=>Rt(a,e)).join("")}</${t.t}>`}var Ze=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Ue(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Lt(t,e){const n=e.all.map(a=>t.byId.get(a));return n.length?{c1:Math.min(...n.map(a=>a.col)),c2:Math.max(...n.map(a=>a.col)),r1:Math.min(...n.map(a=>a.row)),r2:Math.max(...n.map(a=>a.row2))}:null}function Pt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const a=Lt(t,n);if(!a)continue;[a.r1===1,a.c2===t.cols,a.r2===t.rows,a.c1===1].forEach((r,o)=>{r&&(e[o]=Math.max(e[o],te(t,n,o)))})}return e})}function te(t,e,n){const a=Lt(t,e);return t.groups.filter(o=>o.parent===e.id).some(o=>{const s=Lt(t,o);return s&&[s.r1===a.r1,s.c2===a.c2,s.r2===a.r2,s.c1===a.c1][n]})?2:1}function ee(t){const e=Pt(t);return e[1]+e[3]}function Wt(t){return t.type==="sequence"?t.nodes.length:t.cols}function ne(t){return $t(t,"plan",()=>Je(t))}function Je(t){const e=t.nodes,n=d=>t.type==="data-flow"||!e[d].branch,a=t.edges.map(d=>{const f=t.byId.get(d.from).i,S=t.byId.get(d.to).i,C=e.slice(Math.min(f,S)+1,Math.max(f,S)).every(E=>!n(E.i));return S===f+1&&!(n(f)&&!n(S))?"down":S===f-1?"up":S>f&&n(f)&&!n(S)&&C?"trunk":S>f&&n(f)&&n(S)&&C?"rail":S>f?"end-down":"end-up"}),i=t.edges.map((d,f)=>({e:d,k:f})).filter(({k:d})=>a[d]==="end-down"||a[d]==="end-up"),r=d=>{const f=t.byId.get(d.from).i,S=t.byId.get(d.to).i;return[Math.min(f,S),Math.max(f,S)]},o=(d,f)=>{const[S,B]=r(d),[C,E]=r(f);return S<E&&C<B},s=i.every(({e:d})=>{const f=t.byId.get(d.from).i,[S,B]=r(d);return!n(f)&&e.slice(S+1,B).every(C=>!n(C.i))&&i.every(C=>C.e===d||!o(C.e,d))}),c=i.length>0&&(t.type==="data-flow"||!s),u=d=>{const[f,S]=r(d);return S-f},y=t.edges.map(()=>0);let p=!1;const l=[];for(const d of[...i].sort((f,S)=>u(f.e)-u(S.e)||f.k-S.k)){let f=0;for(const S of l)o(S.e,d.e)&&(f=Math.max(f,y[S.k]+1));y[d.k]=f,f>1&&(p=!0),l.push(d)}const g=t.edges.map(()=>.5);for(const d of e){const f=i.filter(({e:C})=>C.from===d.id);if(f.length<2)continue;const S=f.filter(({k:C})=>a[C]==="end-down").sort((C,E)=>u(E.e)-u(C.e)||C.k-E.k);[...f.filter(({k:C})=>a[C]==="end-up").sort((C,E)=>u(C.e)-u(E.e)||E.k-C.k),...S].forEach(({k:C},E,A)=>{g[C]=A.length===2?E===0?1/3:2/3:(E+1)/(A.length+1)})}const x=ht();for(let d=1;d<e.length;d++){const f=e[d],S=e[d-1];let B=0,C=t.type==="data-flow"?48:32,E=!1,A=!1;t.edges.forEach((T,Z)=>{const j=a[Z],ot=t.byId.get(T.from).i,L=t.byId.get(T.to).i,F=L===d&&(j==="down"||j==="trunk"||j==="rail"||j==="end-down"),I=ot===d&&L===d-1&&j==="up",M=L===d-1&&j==="end-up";F&&(j==="trunk"||j==="end-down")&&(E=!0),M&&(A=!0),(F||I||M)&&T.label&&(B++,C=Math.max(C,j==="trunk"?40:48))}),(B>1||E&&A)&&(C=64),x[f.id]=C}return{routes:a,gutter:c,lanes:y,exits:g,gaps:x,third:p}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function oe(t,e){const n=e==="fk"?"plain":e,a=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:a,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${a}H${r}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${a-4}L${i} ${a}L${i-8} ${a+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${a}L${i-8} ${a-4}L${i-8} ${a+4}Z`}))}function St(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function se(t,e){return $t(e,`key:${t}`,()=>Ye(t,e))}var Xe=se;function Ye(t,e){const n=[],a=(o,s,c={})=>n.push(v("li",{class:`${t}-entry`,...c},o,v("span",null,s)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(s=>(s.columns??[]).map(c=>c.key)));for(const[s,c]of[["PK","Primary key"],["FK","Foreign key"]])o.has(s)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},s),v("span",null,c)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(s=>s.shape));o.has("terminal")&&a(St(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&a(St(t,"box"),e.shapeLabels.step),o.has("decision")&&a(St(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind)),r=(o,s)=>v("span",{class:`${t}-key-glyph`,"data-ink":s,"aria-hidden":"true"},o);for(const o of["main","plain","dashed"]){const s=e.legend[o];i.has(o)&&s&&a(e.text?r(o==="main"?"━━▶":o==="dashed"?"┄┄▷":"──▶",o==="main"?"main":"plain"):oe(t,o),s,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length&&(a(oe(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&a(e.text?r("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const o=new Set(e.steps.flatMap(s=>"open"in s?[s.open]:[]));for(const s of["opt","loop","alt"])o.has(s)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},s),v("span",null,e.frameWords[s])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&a(St(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&a(St(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Qe(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Nt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Pe(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},Nt(t,n)))];const a=[];return e.type==="data-flow"?a.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&a.push(v("span",{class:`${t}-kind`},n.kind)),a.push(v("span",{class:`${t}-name`},Nt(t,n))),n.detail&&a.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?_t(n.detail).flatMap((i,r)=>[r?" ":"",v("span",{class:`${t}-run`},i)]):n.detail)),a}function tn(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},Nt(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((a,i)=>v("span",{class:`${t}-row`,"data-row":i,"data-key":a.key},v("span",{class:`${t}-keyseat`},a.key??""),v("span",{class:`${t}-cname`},a.name),a.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${a.ref.table}`):a.type?v("span",{class:`${t}-ctype`},a.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var ae=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function qt(t,e,n,a){const{P:i}=t,r=Ue(e,a)||a.keep===n.id,o=mt(e,a),s=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&s.push(`--_lc:${n.col+1}`),e.type==="sequence"&&s.push(`--_c2:${n.col+1}`);const c=t.plan;if(c&&n.i>0){const l=yt(c.gaps,n.id)??32,g=yt(a.grow,n.id)??0;s.push(`--_gap:${g?`calc(${ae(l)} + var(--basalt-space-4) * ${g})`:ae(l)}`)}const u=yt(a.heights,n.id);u&&s.push(`--_h:${u}px`);const y=yt(a.words,n.id);y&&s.push(`--_ww:${y}px`);const p=o?a.stop===n.id?0:-1:a.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:s.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?He(e,n):void 0,tabindex:p},n.shape==="decision"?v("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ut(n.mark.onLight)};--_md:${Ut(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?tn(i,n,e):Pe(i,e,n))}function en(t,e,n){const{P:a}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((c,u)=>v("div",{class:`${a}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},v("span",{class:`${a}-lane-name`},c.label)))),e.type==="architecture")for(const c of e.groups){const u=Lt(e,c);if(!u)continue;const y=[0,1,2,3].map(p=>te(e,c,p));i.push(v("div",{class:`${a}-gbox`,"data-group":c.id,"data-depth":c.depth>1?c.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${y[0]>1?";--_gt:2":""}${y[1]>1?";--_ge:2":""}${y[2]>1?";--_gb:2":""}${y[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${a}-glabel`},c.label)))}if(e.text)return[v("pre",{class:`${a}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${a}-text-ink`},nn(a,e)))];if(e.type==="sequence")return i.push(v("ul",{class:`${a}-cast`},e.nodes.map(c=>v("li",{class:`${a}-actor`,style:e.rtl?`--_ac:${c.col}`:void 0},qt(t,e,c,n))))),i.push(on(t,e)),i;const r=c=>{const u=c.group?e.groups.find(y=>y.id===c.group):void 0;return u?.parent?e.groups.find(y=>y.id===u.parent):u},o=(c,u,y)=>{const p=t.plan?yt(n.grow,u[0].id)??0:0;return v("div",{class:`${a}-group`,"data-group":c.id,"data-depth":c.depth>1?c.depth:void 0,style:p?`--_ggrow:${p}`:void 0},v("span",{class:`${a}-glabel`,"aria-hidden":"true"},c.label),y)};let s=0;for(;s<e.nodes.length;){const c=e.nodes[s],u=r(c);if(!u){i.push(qt(t,e,c,n)),s++;continue}const y=[];for(;s<e.nodes.length&&r(e.nodes[s])?.id===u.id;)y.push(e.nodes[s++]);const p=[];for(let l=0;l<y.length;){const g=y[l].group!==u.id?e.groups.find(d=>d.id===y[l].group):void 0;if(!g){p.push(qt(t,e,y[l],n)),l++;continue}const x=[];for(;l<y.length&&y[l].group===g.id;)x.push(y[l++]);p.push(o(g,x,x.map(d=>qt(t,e,d,n))))}i.push(o(u,y,p))}return i}function nn(t,e){const n=[],a=o=>v("span",{class:`${t}-tx-name`},o),i=o=>o==="main"?"━▶":o==="dashed"?"┄▷":"─▶";n.push(v("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((o,s)=>[s?" · ":"",a(o.name)])),` +`);let r=0;for(const o of e.steps){const s=" ".repeat(r);if("band"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"band"},`${s}── ${o.band} ──`),` +`);continue}if("open"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},s,v("span",{"data-ink":"op"},`[${o.open}]`),` ${o.label}`),` +`),r++;continue}if("otherwise"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"}," ".repeat(r-1),v("span",{"data-ink":"op"},"[else]"),` ${o.otherwise}`),` +`);continue}if("close"in o){r=Math.max(0,r-1),n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},`${" ".repeat(r)}[end]`),` +`);continue}const c=e.byId.get(o.from)?.name??o.from,u=e.byId.get(o.to)?.name??o.to;n.push(v("span",{class:`${t}-tx-line`,"data-n":o.n},s,v("span",{"data-ink":"num"},`${o.n} `),a(c)," ",v("span",{"data-ink":o.kind==="main"?"main":"plain"},i(o.kind))," ",a(u)," ",v("span",{"data-ink":"label"},o.label),o.note?[" ",v("span",{"data-ink":"note"},`(${o.note})`)]:null),` +`)}return n}function on(t,e){const{P:n}=t,a=[],i=[],r=()=>i.length?i[i.length-1].el.c:a;let o=null;for(const s of e.steps){if("band"in s){o=null,r().push(v("p",{class:`${n}-band`},v("span",null,s.band)));continue}if("open"in s){o=null;const d=i[i.length-1],f=d?`;--_fis:${s.a===d.a?1:0};--_fie:${s.b===d.b?1:0}`:"",S=v("div",{class:`${n}-frame`,"data-op":s.open,"data-depth":s.depth,style:`--_a:${s.a};--_b:${s.b+1}${f}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},s.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[s.open]}: `),s.label)));r().push(S),i.push({el:S,a:s.a,b:s.b});continue}if("otherwise"in s){o=null,r().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),s.otherwise)));continue}if("close"in s){o=null,i.pop();continue}o||(o=v("ol",{class:`${n}-msgs`,start:s.n}),r().push(o));const c=e.byId.get(s.from),u=e.byId.get(s.to),y=c?.col??1,p=u?.col??1,l=y===p,g=l&&(e.rtl?y!==1:y===e.nodes.length),x=Xt(e,s.kind);o.c.push(v("li",{class:`${n}-msg`,"data-kind":s.kind,"data-from":s.from,"data-to":s.to,"data-self":l?g?"start":"end":void 0,style:`--_a:${Math.min(y,p)};--_b:${Math.max(y,p)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(s.n)),v("span",{class:`${n}-mlabel`},s.label)),v("span",{class:`${n}-route`},c?.short??s.from," ",Qe(n,s.kind),v("span",{class:t.hidden}," to ")," ",u?.short??s.to,x?` · ${x}`:""),s.note?v("span",{class:`${n}-note`},s.note):null))}return v("div",{class:`${n}-steps`},a)}function re(t,e){return $t(e,`list:${t}`,()=>an(t,e))}var sn=re;function an(t,e){const n=Math.min(6,e.heading+1),a=p=>v(`h${n}`,{class:`${t}-list-head`},p),i=p=>v("strong",null,p),r=p=>p.href?v("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},i(p.name)):i(p.name),o=p=>v("code",{class:`${t}-code`},p),s=p=>e.byId.get(p)?.name??p,c=p=>{const l=Xt(e,p);return l?` (${l})`:""},u=p=>p.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const p=x=>v("li",null,r(x),x.kind?`, ${x.kind}`:"",x.detail?[". ",x.mono?o(x.detail):x.detail,/[.!?]$/.test(x.detail)?"":"."]:/[.!?]$/.test(x.kind??x.name)?"":".",u(x)),l=[a("Parts")],g=e.nodes.filter(x=>!x.group);g.length&&l.push(v("ul",{class:`${t}-list-items`},g.map(p)));for(const x of e.groups.filter(d=>d.depth===1)){l.push(v("p",{class:`${t}-list-group`},x.label)),x.members.length&&l.push(v("ul",{class:`${t}-list-items`},x.members.map(d=>p(e.byId.get(d)))));for(const d of e.groups.filter(f=>f.parent===x.id))l.push(v("p",{class:`${t}-list-group`,"data-depth":2},d.label)),l.push(v("ul",{class:`${t}-list-items`,"data-depth":2},d.members.map(f=>p(e.byId.get(f)))))}return l.push(a("Connections")),l.push(v("ol",{class:`${t}-list-items`},e.edges.map(x=>v("li",null,i(s(x.from))," to ",i(s(x.to)),x.label?[": ",o(gt(x.label))]:"",`${c(x.kind)}.`)))),l}if(e.type==="flowchart"){const p=l=>(e.byId.get(l)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const g=e.edges.filter(f=>f.from===l.id),x=l.shape==="decision"?"Decision":l.shape==="terminal"?g.length?"Start":"End":"Step",d=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return v("li",null,r(l),l.detail?[", ",l.mono?o(l.detail):l.detail]:"",`${d}${x}.`,u(l),g.length?v("ul",{class:`${t}-list-exits`},g.map(f=>v("li",null,f.label?`If ${gt(f.label)}: go to ${p(f.to)}, `:`Then: go to ${p(f.to)}, `,i(s(f.to)),c(f.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(p=>{const l=e.edges.filter(g=>g.from===p.id);return v("li",null,`${p.laneLabel}: `,r(p),p.detail?[", ",p.mono?o(p.detail):p.detail]:"",".",u(p),l.length?[" Then ",...l.flatMap((g,x)=>[x?"; ":"",`to step ${e.byId.get(g.to).step}, `,i(s(g.to)),g.label?[": ",o(gt(g.label))]:"",c(g.kind)]),"."]:"")}))];if(e.type==="sequence"){const p=[a("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(g=>v("li",null,i(g.name),g.kind?`, ${g.kind}`:"",".",u(g),Yt(e,g))))];p.push(a("Messages"));let l=null;for(const g of e.steps){if("band"in g){l=null,p.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},g.band));continue}if("open"in g){l=null,p.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords[g.open]}: ${g.label}`));continue}if("otherwise"in g){l=null,p.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords.else}: ${g.otherwise}`));continue}if("close"in g){l=null;continue}l||(l=v("ol",{class:`${t}-list-items`,start:g.n}),p.push(l)),l.c.push(v("li",null,o(g.label),": ",i(s(g.from))," to ",i(s(g.to)),`${c(g.kind)}.`,g.note?` ${wt(g.note)}`:""))}return p}const y=[];for(const p of e.nodes)y.push(v(`h${n}`,{class:`${t}-list-group`},p.href?v("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},o(p.name)):o(p.name),u(p))),y.push(v("ul",{class:`${t}-list-items`},[...(p.columns??[]).map(l=>v("li",null,o(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",o(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...p.more?[v("li",null,`and ${p.more} more ${p.more===1?"column":"columns"}`)]:[]]));return y}function ie(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&It(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function zt(t,e=!1){const n=e&&t.type!=="sequence"&&It(t)&&t.cols>1&&t.rows>1,a=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Qt(t)},{keys:["Home","End"],words:"the ends"},...a,{keys:["Esc"],words:"clear"}]}var rn=(t,e)=>{for(let n=0;n<t.length;n++)if(t[n]!==e[n])return t[n]<e[n];return!1},ln=(t,e)=>({col:e.col,rows:[e.row,e.row2]});function It(t){return $t(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,...ln(t,r)})),n=(r,o)=>{const s=o==="right"||o==="left",c=o==="right"||o==="down",u=x=>s?[x.col,x.col]:x.rows,y=x=>s?x.rows:[x.col,x.col],p=u(r),l=y(r);let g=null;return e.forEach((x,d)=>{if(x===r)return;const f=u(x),S=y(x),B=c?f[0]-p[1]:p[0]-f[1];if(B<1)return;const C=Math.max(0,S[0]-l[1],l[0]-S[1]),E=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(S[0]-l[0]),d];(!g||rn(E,g.rank))&&(g={id:x.id,rank:E})}),g?.id??null},a=ht();for(const r of e)a[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const o=new Set([r]),s=[r];for(;s.length;)for(const c of Object.values(a[s.pop()]))c&&!o.has(c)&&(o.add(c),s.push(c));return o.size};return e.every(r=>i(r.id)===e.length)?a:null})}var le=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Ft(t,e,n){const a=n.prefix,i=Ze(n.base),r=t.type==="sequence"||t.type==="schema"?null:ne(t),o={P:a,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},s=e.layout==="drawn",c=mt(t,e),u=t.type==="sequence"||t.type==="schema"?s:!0,y=`h${t.heading}`,p=[`--_cols:${Wt(t)}`];if(t.type==="architecture"&&t.groups.length||s&&e.pad){const l=t.type==="architecture"?Pt(t):[0,0,0,0],g=(d,f,S)=>d?d>1?`calc(${d} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:S?`var(--basalt-space-${S})`:"0px",x=s&&e.pad?"3":void 0;p.push(`--_gpad:${g(l[0],"8",x)} ${g(l[1],"4")} ${g(l[2],"4",x)} ${g(l[3],"4")}`)}return le(t)&&p.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&p.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${a} ${n.className}`:a,"aria-labelledby":i.title,"data-type":t.type,"data-cols":Wt(t),"data-reach":t.type==="architecture"?ee(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:p.join(";")},v("div",{class:`${a}-head`},v(y,{id:i.title,class:`${a}-title`},t.title),n.hasSource?v("p",{class:`${a}-source`},{slot:"source"}):null),v("div",{class:`${a}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?i.title:void 0,"aria-describedby":u?c?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":c?"":void 0},en(o,t,e),t.text?null:v("div",{class:`${a}-ink`,"aria-hidden":"true"}),v("span",{class:`${a}-ruler`,"aria-hidden":"true"})),se(a,t),v("p",{class:`${a}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||s&&t.type==="sequence"?v("p",{class:`${a}-tap-hint`,"aria-hidden":"true"},`Tap ${Qt(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${a}-foot`},{slot:"toggle"}),v("div",{id:i.list,class:`${a}-list`,hidden:!e.open},re(a,t)),v("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${ie(t,s)} ${n.viewer}`:ie(t,s)),v("figcaption",{id:i.summary,class:`${a}-summary`},{slot:"summary"}))}function cn(t){const e=getComputedStyle(t),n=(i,r)=>{const o=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(o)?o:r},a=new Map;return{space:i=>(a.has(i)||a.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),a.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ot=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.l<e.r-n&&t.r>e.l+n&&t.t<e.b-n&&t.b>e.t+n,ce=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:a,t:i,r,b:o}=t.rect,s=(a+r)/2,c=(i+o)/2,u=(r-a)/2,y=(o-i)/2,p=e==="top"||e==="bottom";if(t.shape==="decision"){if(p){const x=n,d=y*Math.max(0,1-Math.abs(x-s)/u);return{x,y:e==="top"?c-d:c+d}}const l=n,g=u*Math.max(0,1-Math.abs(l-c)/y);return{x:e==="left"?s-g:s+g,y:l}}if(t.shape==="terminal"){const l=Math.min(u,y);if(p){const f=n,S=Math.min(Math.max(f,a+l),r-l),B=f-S,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?i:o:e==="top"?c-C:c+C}}const g=n,x=g-c,d=Math.abs(x)>=l?0:Math.sqrt(l*l-x*x);return{x:e==="left"?a+l-d:r-l+d,y:g}}return p?{x:n,y:e==="top"?i:o}:{x:e==="left"?a:r,y:n}}function dn(t,e,n){const{l:a,t:i,r,b:o}=e.rect,s=(a+r)/2,c=(i+o)/2,u=(r-a)/2,y=(o-i)/2;if(e.shape==="decision")return Math.abs(t.x-s)/u+Math.abs(t.y-c)/y<1-n/Math.min(u,y);if(e.shape==="terminal"){const p=Math.min(u,y),l=Math.min(Math.max(t.x,a+p),r-p);return Math.hypot(t.x-l,t.y-c)<p-n}return t.x>a+n&&t.x<r-n&&t.y>i+n&&t.y<o-n}function de(t,e){if(!ut(t,e.rect))return!1;if(e.shape!=="decision"&&e.shape!=="terminal")return!0;const{l:n,t:a,r:i,b:r}=e.rect,o=(n+i)/2,s=(a+r)/2,c=(i-n)/2,u=(r-a)/2;if(e.shape==="decision"){const p=Math.max(t.l,Math.min(o,t.r)),l=Math.max(t.t,Math.min(s,t.b));return Math.abs(p-o)/c+Math.abs(l-s)/u<1-1e-6}const y=Math.min(u,c);if(ut(t,{l:n+y,r:i-y,t:a,b:r}))return!0;for(const p of[n+y,i-y]){const l=Math.max(t.l,Math.min(p,t.r)),g=Math.max(t.t,Math.min(s,t.b));if(Math.hypot(l-p,g-s)<y-.01)return!0}return!1}function fn(t,e,n){const a=Math.hypot(e.x-t.x,e.y-t.y),i=Math.max(2,Math.ceil(a/2));for(let r=1;r<i;r++){const o=r/i;if(!(o*a<1.5||(1-o)*a<1.5)&&dn({x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o},n,1))return!0}return!1}var un=()=>matchMedia("(forced-colors: active)").matches;function hn(t,e){const n=t.querySelector(`.${e}-ruler`),a=new Map;return(i,r)=>{const o=`${r}|${i}`;return a.has(o)||(n.setAttribute("data-f",r),n.textContent=i,a.set(o,n.getBoundingClientRect().width),n.textContent=""),a.get(o)}}var _t=t=>t?t.split(/\s+/).filter(Boolean):[];function pn(t,e,n){const a=e.space;let i=e.node,r=e.table;for(const c of t.nodes){if(c.shape==="table"){for(const d of c.columns??[]){const f=d.ref?`${t.rtl?"←":"→"} ${d.ref.table}`:d.type??"",S=a("6")+n(d.name,"mono")+(f?a("3")+n(f,"mono"):0)+2*a("3")+2*e.hair;r=Math.max(r,Math.ceil(S))}r=Math.max(r,Math.ceil(n(c.name,"table")+2*a("3")+2*e.hair+(c.href?16+a("1-5"):0)));continue}const u=c.shape==="terminal"?2*a("5"):2*a("3"),y=c.mark&&!un()?(c.shape==="participant"?2:1)*a("6"):0;let p=0;const l=c.href?16+a("1-5"):0,g=_t(c.name);if(g.forEach((d,f)=>{p=Math.max(p,n(d,c.shape==="decision"?"name-500":"name")+(c.kind?0:y)+(f===g.length-1?l:0))}),t.type!=="data-flow")for(const d of _t(c.kind))p=Math.max(p,n(d,"mono")+y);for(const d of _t(c.detail))p=Math.max(p,n(d,c.mono?"mono":"sans"));const x=c.shape==="decision"?p/.62:p+u+2*e.hair;i=Math.max(i,Math.ceil(x))}const o=Wt(t);let s;return t.type==="data-flow"?s=e.lane+o*(i+a("12")):t.type==="schema"?s=o*r+(o-1)*a("12")+(le(t)?a("5"):0):t.type==="sequence"?s=o*i+(o-1)*a("5"):s=o*i+(o-1)*a("16")+ee(t)*a("4"),{track:i,table:r,least:Math.max(e.wide,s)}}function fe(t,e){return{x:(n,a)=>a%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,a)=>a%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Ht(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ue(t,e,n){const a=t.map(r=>({...r}));for(let r=1;r<a.length;r++){const o=a[r-1],s=a[r];if(Math.abs(o.x-s.x)<.75){const c=n.x(o.x,e);o.x=c,s.x=c}else if(Math.abs(o.y-s.y)<.75){const c=n.y(o.y,e);o.y=c,s.y=c}}const i=[a[0]];for(let r=1;r<a.length;r++){const o=a[r],s=i[i.length-1];if(!(Math.abs(o.x-s.x)<.01&&Math.abs(o.y-s.y)<.01)){if(i.length>=2){const c=i[i.length-2];if(Math.abs(c.x-s.x)<.01&&Math.abs(s.x-o.x)<.01||Math.abs(c.y-s.y)<.01&&Math.abs(s.y-o.y)<.01){i[i.length-1]=o;continue}}i.push(o)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Ct(t,e,n){const a=[];for(let r=0;r<t.length;r++)for(let o=r+1;o<t.length;o++){const s=t[r],c=t[o];if(!(n&&!n.has(s.i)&&!n.has(c.i)))for(const[u,y]of pt(s.pts))for(const[p,l]of pt(c.pts)){const g=Math.abs(u.y-y.y)<.01,x=Math.abs(p.y-l.y)<.01;if(g===x)continue;const[d,f,S,B]=g?[u,y,p,l]:[p,l,u,y],C=S.x,E=d.y;if(C>Math.min(d.x,f.x)+.75&&C<Math.max(d.x,f.x)-.75&&E>Math.min(S.y,B.y)+.75&&E<Math.max(S.y,B.y)-.75){const A=g?r:o,T=g?o:r;let Z=A,j=T;if(e){const ot=e(t[A]);e(t[T])&&!ot&&(Z=T,j=A)}a.push({top:Z,under:j,at:{x:C,y:E},underVertical:j===T})}}}return a}function gn(t){const e=getComputedStyle(t),n=i=>i.split(/\s+/).map(parseFloat).filter(r=>Number.isFinite(r)),a=(i,r,o)=>{const s=[];let c=r;for(const u of i)s.push([c,c+u]),c+=u+o;return s};return{cols:a(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:a(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var nt=t=>t==="left"||t==="right",he={top:"bottom",bottom:"top",left:"right",right:"left"};function mn(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function yn(t,e,n){const a=[];t.edges.forEach((r,o)=>{const s=t.byId.get(r.from),c=t.byId.get(r.to),[u,y]=e[o],p=s.row===c.row&&nt(u)&&nt(y)&&u===he[y]||s.col===c.col&&!nt(u)&&!nt(y)&&u===he[y];a.push({edge:o,end:"from",node:s,side:u,far:c,straight:p,f:.5},{edge:o,end:"to",node:c,side:y,far:s,straight:p,f:.5})});const i=new Map;for(const r of a){const o=`${r.node.id}.${r.side}`;i.has(o)||i.set(o,[]),i.get(o).push(r)}for(const[r,o]of i){if(o[0].node.shape==="decision")continue;const s=d=>nt(d.side)?d.far.row-d.node.row:d.far.col-d.node.col,c=o.filter(d=>d.straight),u=o.filter(d=>!d.straight);if(u.sort((d,f)=>s(d)-s(f)||(nt(d.side)?d.far.col-f.far.col:d.far.row-f.far.row)*(s(d)<0?1:-1)),o.length>3&&n(`${r.replace(".","'s ")} side has ${o.length} lines; more than three is an error: use another side`),!c.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((d,f)=>{d.f=(f+1)/(u.length+1)});continue}const y=new Map;for(const d of c)y.has(d.far.id)||y.set(d.far.id,[]),y.get(d.far.id).push(d);for(const d of y.values())d.length>1&&d.sort((f,S)=>f.edge-S.edge).forEach((f,S)=>{f.f=d.length===2?S===0?.25:.75:(S+1)/(d.length+1)});const p=Math.min(...c.map(d=>d.f)),l=Math.max(...c.map(d=>d.f)),g=u.filter(d=>s(d)<0),x=u.filter(d=>s(d)>=0);g.forEach((d,f)=>{d.f=p*(f+1)/(g.length+1)}),x.forEach((d,f)=>{d.f=l+(1-l)*(f+1)/(x.length+1)})}return a}function pe(t,e,n){const{l:a,t:i,r,b:o}=t.rect;return nt(e)?lt(t,e,i+(o-i)*n):lt(t,e,a+(r-a)*n)}function ge(t,e,n,a){const i=new Map;return e.querySelectorAll(`.${a}-node`).forEach(r=>{const o=t.byId.get(r.dataset.node);o&&i.set(o.id,{id:o.id,rect:ft(r,n),shape:o.shape,i:o.i})}),i}function me(t,e){const n=e.head,a=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-a,r:i+a,t:r-n,b:r}:t.dir==="up"?{l:i-a,r:i+a,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-a,b:r+a}:{l:i,r:i+n,t:r-a,b:r+a}}var ye=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function be(t,e,n,a){const i=(r,o)=>{const s=r+o-Math.floor(r+o);return s<.005||s>.995?[0]:s<=.5?[-s,1-s]:[1-s,-s]};for(const r of i(t.t,n))for(const o of i(t.l,e)){if(!o&&!r)return t;const s={l:t.l+o,r:t.r+o,t:t.t+r,b:t.b+r};if(a(s))return s}return t}function bn(t,e,n,a,i,r,o,s,c){const u=o.space,y=[],p=[],l=[],g=[],x=u("1"),d=e.filter(f=>t.edges[f.i]?.label).sort((f,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-S.i);for(const f of d){const S=t.edges[f.i].label,B=s(S,"label"),C=16*Tt(S),E=f.pts.length-2,A=[];pt(f.pts).forEach(([L,F],I)=>{const M=Math.abs(L.y-F.y)<.01,O=M?L.x:L.y;let N=M?F.x:F.y;const G=Math.sign(N-O)||1;I===E&&(N-=G*o.head);let W=[[O,N]];for(const m of i)for(const b of M?[m.l,m.r]:[m.t,m.b]){const h=M?L.y:L.x;(M?h>m.t&&h<m.b:h>m.l&&h<m.r)&&(W=W.flatMap(([$,w])=>b>Math.min($,w)+1&&b<Math.max($,w)-1?[[$,b],[b,w]]:[[$,w]]))}const Y=(m,b)=>{const h=(m+b)/2,k=M?{x:h,y:L.y}:{x:L.x,y:h};return!i.some($=>k.x>$.l&&k.x<$.r&&k.y>$.t&&k.y<$.b)},K=f.axes?.[I]??(M?L.y:L.x);for(const[m,b]of W)A.push({horiz:M,c:K,p:m,q:b,len:Math.abs(b-m),pri:W.length>1&&Y(m,b)?1:0})}),A.sort((L,F)=>F.pri-L.pri||F.len-L.len);let T=null,Z=!1;const j=(L,F=!0)=>{const I=ce(L,x);return F&&(L.l<r.l||L.r>r.r||L.t<r.t||L.b>r.b)||n.some(M=>de(I,M))||y.some(M=>ut(I,M))||a.heads.some(M=>ut(I,M))||a.rects.some(M=>ut(I,M))?!1:!e.some(M=>M.i!==f.i&&pt(M.pts).some(([O,N])=>ut(I,ye(O,N,M.width))))};for(const L of A){for(const F of[1/2,1/3,2/3]){const I=L.p+(L.q-L.p)*F,M=[],O=u("2")+f.width/2;if(L.horiz?(L.len>=B+2*u("1")+u("3-5")&&M.push({box:{l:I-B/2-u("1"),r:I+B/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),M.push({box:{l:I-B/2,r:I+B/2,t:L.c-O-C,b:L.c-O},on:!1}),M.push({box:{l:I-B/2,r:I+B/2,t:L.c+O,b:L.c+O+C},on:!1})):(L.len>=C+u("3")&&M.push({box:{l:L.c-B/2-u("1"),r:L.c+B/2+u("1"),t:I-C/2,b:I+C/2},on:!0}),M.push({box:{l:L.c+O,r:L.c+O+B,t:I-C/2,b:I+C/2},on:!1}),M.push({box:{l:L.c-O-B,r:L.c-O,t:I-C/2,b:I+C/2},on:!1})),T=M.find(N=>j(N.box))??null,T)break;!Z&&M.some(N=>j(N.box,!1))&&(Z=!0)}if(T)break}if(!T){l.push(f.i),Z&&g.push(f.i);continue}const ot=be(T.box,c.ox,c.oy,L=>j(L));y.push(ot),p.push({i:f.i,text:S,box:ot,on:T.on})}return{labels:p,unseated:l,bounded:g}}function $e(t,e,n,a){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(o=>{if(o.getClientRects().length===0||getComputedStyle(o).display==="contents")return;const s=ft(o,e);r.push(s),i.push({l:s.l,r:s.r,t:s.t,b:s.t+1},{l:s.l,r:s.r,t:s.b-1,b:s.b},{l:s.l,r:s.l+1,t:s.t,b:s.b},{l:s.r-1,r:s.r,t:s.t,b:s.b});const c=o.querySelector(`:scope > .${n}-glabel`);c&&c.getClientRects().length&&i.push(ft(c,e))}),t.querySelectorAll(`.${n}-lane`).forEach((o,s)=>{if(!o.getClientRects().length)return;const c=ft(o,e);s>0&&i.push({l:c.l,r:c.r,t:c.t-a/2-.5,b:c.t-a/2+.5});const u=o.querySelector(`.${n}-lane-name`);u&&i.push(ft(u,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function $n(t,e){const{m:a,tk:i,P:r,drawing:o,origin:s,warn:c}=t,u=i.space,y=ge(a,o,s,r),p=[...y.values()],l=gn(o),g=s.left-Math.floor(s.left),x=s.top-Math.floor(s.top),d=fe(g,x),f=o.clientWidth,S=o.clientHeight,B=h=>a.type==="data-flow"?h.col+1:h.col,C=parseFloat(getComputedStyle(o).rowGap)||0,E={w:f,h:S,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:g,oy:x};if(a.type==="sequence")return vn(t,E,d);let A,T=[];a.type==="schema"?A=a.edges.map(h=>{const k=a.byId.get(h.from),$=a.byId.get(h.to);if(k.col===$.col){const w=k.col===a.cols&&a.cols>1?"left":"right";return[w,w]}return $.col>k.col?["right","left"]:["left","right"]}):(A=a.edges.map(h=>{const k=a.byId.get(h.from),$=a.byId.get(h.to),[w,_]=mn(k,$);return[h.fromSide??w,h.toSide??_]}),T=yn(a,A,c||(()=>{})));const Z=(h,k)=>{const $=o.querySelector(`.${r}-node[data-node="${CSS.escape(h)}"] .${r}-row[data-row="${k}"]`);if(!$)return 0;const w=ft($,s);return(w.t+w.b)/2},j=a.edges.map((h,k)=>{const[$,w]=A[k],_=y.get(h.from),q=y.get(h.to),R=Ot(h.kind,i);if(h.fk){const V=Z(h.from,h.fromRow),P=Z(h.to,h.toRow),U=d.y(V,R),et=d.y(P,R);return{p1:{x:$==="right"?_.rect.r:_.rect.l,y:U},p2:{x:w==="right"?q.rect.r:q.rect.l,y:et},r1:V,r2:Math.abs(U-et)<.01?V:P}}const Q=T.find(V=>V.edge===k&&V.end==="from").f,X=T.find(V=>V.edge===k&&V.end==="to").f;let z=pe(_,$,Q),D=pe(q,w,X);const tt=nt($)?z.y:z.x;let st=nt(w)?D.y:D.x;return nt($)?z={...z,y:d.y(z.y,R)}:z={...z,x:d.x(z.x,R)},nt(w)?D={...D,y:d.y(D.y,R)}:D={...D,x:d.x(D.x,R)},nt($)&&nt(w)&&Math.abs(z.y-D.y)<1.01&&(D={...D,y:z.y},st=tt),!nt($)&&!nt(w)&&Math.abs(z.x-D.x)<1.01&&(D={...D,x:z.x},st=tt),z=nt($)?lt(_,$,z.y):lt(_,$,z.x),D=nt(w)?lt(q,w,D.y):lt(q,w,D.x),{p1:z,p2:D,r1:tt,r2:st}}),ot=new Set;a.type==="schema"&&a.edges.forEach((h,k)=>{Math.abs(a.byId.get(h.from).col-a.byId.get(h.to).col)>1&&ot.add(k)});const L=new Map,F=new Set;a.edges.forEach((h,k)=>{if(ot.has(k))return;const[$,w]=A[k],{p1:_,p2:q}=j[k],R=a.byId.get(h.from),Q=a.byId.get(h.to);let X=null,z=null,D=!1;if($===w){if(nt($)){const V=$==="right"?Math.max(B(R),B(Q)):Math.min(B(R),B(Q))-1,P=l.cols[V-1],U=l.cols[V];P&&U&&(X=`c${V}`,z=[P[1],U[0]],D=!0)}else{const V=$==="bottom"?Math.max(R.row2,Q.row2):Math.min(R.row,Q.row)-1,P=l.rows[V-1],U=l.rows[V];P&&U&&(X=`r${V}`,z=[P[1],U[0]],D=!1)}X&&F.add(k)}else if(nt($)&&nt(w)&&Math.abs(_.y-q.y)>.5){const V=B(Q),P=w==="left",U=l.cols[(P?V-1:V)-1],et=l.cols[(P?V:V+1)-1];U&&et&&(X=`c${P?V-1:V}`,z=[U[1],et[0]],D=!0)}else if(!nt($)&&!nt(w)&&Math.abs(_.x-q.x)>.5){const P=w==="top"?Q.row-1:Q.row2,U=l.rows[P-1],et=l.rows[P];U&&et&&(X=`r${P}`,z=[U[1],et[0]],D=!1)}if(!X||!z)return;L.has(X)||L.set(X,{span:z,vertical:D,members:new Map});const tt=`${h.to}.${w}.${Math.round(D?q.y:q.x)}`,st=L.get(X);st.members.has(tt)||st.members.set(tt,[]),st.members.get(tt).push(k)});const I=new Map,M=h=>{const[k,$]=A[h],{p1:w,p2:_}=j[h];if(nt(k)&&nt($)){if(k===$){const R=I.get(h)??(k==="right"?Math.max(w.x,_.x)+u("4"):Math.min(w.x,_.x)-u("4"));return[w,{x:R,y:w.y},{x:R,y:_.y},_]}if(Math.abs(w.y-_.y)<=.5)return[w,{x:_.x,y:w.y}];const q=I.get(h)??(w.x+_.x)/2;return[w,{x:q,y:w.y},{x:q,y:_.y},_]}if(!nt(k)&&!nt($)){if(k===$){const R=I.get(h)??(k==="bottom"?Math.max(w.y,_.y)+u("4"):Math.min(w.y,_.y)-u("4"));return[w,{x:w.x,y:R},{x:_.x,y:R},_]}if(Math.abs(w.x-_.x)<=.5)return[w,{x:w.x,y:_.y}];const q=I.get(h)??(w.y+_.y)/2;return[w,{x:w.x,y:q},{x:_.x,y:q},_]}return nt(k)?[w,{x:_.x,y:w.y},_]:[w,{x:w.x,y:_.y},_]},O=h=>{const k=a.edges[h],$=Ot(k.kind,i),w=M(h),_=ue(w,$,d);let q;return w.length===_.length&&(q=pt(w).map(([R,Q])=>Math.abs(R.y-Q.y)<.75?(R.y+Q.y)/2:(R.x+Q.x)/2),q[0]=j[h].r1,q.length>1&&(q[q.length-1]=j[h].r2)),{i:h,from:k.from,to:k.to,kind:k.kind,pts:_,tip:_[_.length-1],dir:Ht(_),dot:k.fk?_[0]:void 0,width:$,axes:q}},N=()=>a.edges.flatMap((h,k)=>ot.has(k)?[]:[O(k)]);let G=null;const W=h=>{G??(G=N());const k=G.map($=>h.has($.i)?O($.i):$);return{lines:k,score:wn(k,h)*1e5+Ct(k,void 0,h).length*1e3+Dt(k.filter($=>h.has($.i)),p,a).length}},Y=(h,k)=>{const $=h.flatMap(w=>{const{p1:_,p2:q}=j[w];return k?[_.y,q.y]:[_.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,h]of L){const k=[...h.members.values()].map(w=>({members:w,run:Y(w,h.vertical)})).sort((w,_)=>w.run[0]-_.run[0]),$=[];for(const w of k){const _=$[$.length-1];_&&_.some(q=>q.run[0]<w.run[1]+u("8")&&w.run[0]<q.run[1]+u("8"))?_.push(w):$.push([w])}for(const w of $){if(w.length===1&&w[0].members.every(tt=>F.has(tt)))continue;const _=w.map(tt=>tt.members),q=_.length,R=(h.span[1]-h.span[0])/(q+1);R<u("3")&&c?.(`a gutter holds ${q} lanes side by side, closer than space-3`);const Q=new Set(_.flat());let X=_,z=1/0,D=null;for(const tt of ve(_)){tt.forEach((V,P)=>V.forEach(U=>I.set(U,h.span[0]+R*(P+1))));const st=W(Q);st.score<z&&(z=st.score,X=tt,D=st.lines)}X.forEach((tt,st)=>tt.forEach(V=>I.set(V,h.span[0]+R*(st+1)))),G=D}}E.lines=N();for(const h of ot)c?.(`${a.edges[h].from} to ${a.edges[h].to} is two columns apart, so its line is not drawn; its row still writes the target`);E.crossings=Ct(E.lines),E.through=Dt(E.lines,p,a),E.outside=xe(E.lines,f,S,i);const{obstacles:K,groups:m}=$e(o,s,r,C);K.heads=E.lines.map(h=>me(h,i));const b=bn(a,E.lines,p,K,m,{l:0,t:0,r:f,b:S},i,e,{ox:g,oy:x});return E.labels=b.labels,E.unseated=b.unseated,E.bounded=b.bounded,E.overlaps=[...new Set(we(E.lines,null).flat())],E}function wn(t,e){return we(t,e).length}function we(t,e){const n=[];for(let a=0;a<t.length;a++)for(let i=a+1;i<t.length;i++){const r=t[a],o=t[i];if(e&&!e.has(r.i)&&!e.has(o.i)||r.to===o.to&&Math.abs(r.tip.x-o.tip.x)<1&&Math.abs(r.tip.y-o.tip.y)<1)continue;const s=(r.width+o.width)/2+.5;for(const[c,u]of pt(r.pts))for(const[y,p]of pt(o.pts)){const l=Math.abs(c.y-u.y)<.01,g=Math.abs(y.y-p.y)<.01;if(l!==g)continue;const[x,d]=l?[c.y,y.y]:[c.x,y.x];if(Math.abs(x-d)>=s)continue;const[f,S]=l?[c.x,u.x]:[c.y,u.y],[B,C]=l?[y.x,p.x]:[y.y,p.y];Math.min(Math.max(f,S),Math.max(B,C))-Math.max(Math.min(f,S),Math.min(B,C))>1&&n.push([r.i,o.i])}}return n}function*ve(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e<t.length;e++){const n=t.slice(0,e).concat(t.slice(e+1));for(const a of ve(n))yield[t[e],...a]}}function xe(t,e,n,a){const i=[];for(const r of t)r.pts.some((o,s)=>{const c=s===r.pts.length-1?Math.max(r.width/2,a.head/2):r.width/2;return o.x-c<-.5||o.x+c>e+.5||o.y-c<-.5||o.y+c>n+.5})&&i.push(r.i);return i}function Dt(t,e,n){const a=[];for(const i of t){const r=pt(i.pts);e.some(o=>r.some(([s,c])=>fn(s,c,o)))&&a.push(i.i)}return a}function vn(t,e,n){const{m:a,tk:i,P:r,drawing:o,origin:s}=t,c=i.space,u=new Map;o.querySelectorAll(`.${r}-node`).forEach(E=>u.set(E.dataset.node,ft(E,s)));const y=o.querySelector(`.${r}-steps`),p=y?ft(y,s).b:e.h,l=E=>{const A=u.get(E);return A?n.x((A.l+A.r)/2,i.hair):0};for(const E of a.nodes){const A=u.get(E.id);A&&e.lifelines.push({x:l(E.id),y1:A.b,y2:p})}const g=E=>u.get(E.id),x=new Map;o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=ft(E,s);x.set(Number(E.querySelector(`.${r}-num`)?.textContent??0),(A.t+A.b)/2)});const d=i.activation,f=d/2,S=E=>{const A=a.byId.get(E.who);if(!A)return null;const T=l(E.who),j=(A.i===a.nodes.length-1&&a.nodes.length>1?-1:1)*(a.rtl?-1:1),ot=(E.depth-1)*c("1")*j,L=x.get(E.from)??0,F=x.get(E.to)??L,I=E.from===E.to;return{l:n.x(T-f+ot,i.hair),r:n.x(T+f+ot,i.hair),t:n.y(I?L-c("2")-c("1"):L,i.hair),b:n.y(I?L+c("2")+c("1"):F,i.hair)}},B=a.bars.map(E=>({bar:E,rect:S(E)})).filter(E=>E.rect);e.bars=B.map(E=>E.rect);const C=(E,A,T)=>B.filter(({bar:Z})=>Z.who===E&&Z.to>=A&&(T?Z.from<=A:Z.from<A||Z.from===A&&Z.to===A)).sort((Z,j)=>j.bar.depth-Z.bar.depth)[0]?.rect;return o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=E.dataset.from,T=E.dataset.to,Z=E.dataset.kind??"plain",j=Ot(Z,i),ot=ft(E,s),L=n.y((ot.t+ot.b)/2,j),F=Number(E.querySelector(`.${r}-num`)?.textContent??0);let I=l(A),M=l(T),O;if(A===T){const b=E.dataset.self==="start"?-c("6"):c("6"),h=C(A,F,!0),k=h?b>0?h.r:h.l:I,$=n.y(L-c("2"),j),w=n.y(L+c("2"),j);O=[{x:k,y:$},{x:n.x(I+b,j),y:$},{x:n.x(I+b,j),y:w},{x:k,y:w}]}else{const b=M>I?1:-1,h=C(A,F,!1),k=C(T,F,!0);h&&(I=b>0?h.r:h.l),k&&(M=b>0?k.l:k.r),O=[{x:I,y:L},{x:M,y:L}]}e.lines.push({i:F,from:A,to:T,kind:Z,pts:O,tip:O[O.length-1],dir:Ht(O),width:j});const N=E.querySelector(`.${r}-said`),G=E.querySelector(`.${r}-note`),W=a.byId.get(A),Y=a.byId.get(T);if(!W||!Y)return;const K=A===T?(()=>{const b=a.nodes[W.i+(E.dataset.self==="start"?-1:1)],h=b?l(b.id):E.dataset.self==="start"?0:e.w;return Math.abs(h-I)-c("6")-c("2-5")-c("2")})():Math.abs(M-I)-2*c("2");Math.max(N?N.getBoundingClientRect().width:0,G?G.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(F)}),o.querySelectorAll(`.${r}-fhead`).forEach(E=>{const A=E.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!A)return;[...E.children].reduce((Z,j)=>Z+j.getBoundingClientRect().width,0)+c("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${E.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ke(t,e,n,a=ht()){const{m:i,tk:r,P:o,drawing:s,origin:c}=t,u=r.space,y=ge(i,s,c,o),p=[...y.values()],l=c.left-Math.floor(c.left),g=c.top-Math.floor(c.top),x=fe(l,g),d=s.clientWidth,f=s.clientHeight,S={w:d,h:f,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:g},B=ht();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:B};const C=d-(parseFloat(getComputedStyle(s).paddingRight)||0),E=(M,O,N)=>{const G=[M];for(let W=1;W<=(yt(a,O)??0);W++)G.push({...M,t:M.t+N*u("4")*W,b:M.b+N*u("4")*W});return G},A=new Map;s.querySelectorAll(`.${o}-node`).forEach(M=>{const O=M.parentElement,N=ft(O,c),G=getComputedStyle(O);A.set(M.dataset.node,N.r-(parseFloat(G.paddingRight)||0)-(parseFloat(G.borderRightWidth)||0))});const T=i.nodes,Z=M=>y.get(T[M].id),j=[],ot=M=>Ot(i.edges[M].kind,r);i.edges.forEach((M,O)=>{const N=n.routes[O],G=y.get(M.from),W=y.get(M.to),Y=ot(O);let K=[];const m=M.label,b=m?e(m,"label"):0,h=m?16*Tt(m):16,k=u("4");if(N==="down"||N==="up"){const w=Math.max(G.rect.l,W.rect.l),_=Math.min(G.rect.r,W.rect.r),q=i.edges.map((z,D)=>({o:z,j:D})).filter(({o:z,j:D})=>(n.routes[D]==="down"||n.routes[D]==="up")&&(z.from===M.from&&z.to===M.to||z.from===M.to&&z.to===M.from)),R=q.findIndex(z=>z.j===O),Q=q.length<2?.5:q.length===2?R===0?.25:.75:(R+1)/(q.length+1),X=x.x(w+(_-w)*Q,Y);if(K=N==="down"?[lt(G,"bottom",X),lt(W,"top",X)]:[lt(G,"top",X),lt(W,"bottom",X)],m){let z=Math.min(K[0].y,K[1].y),D=Math.max(K[0].y,K[1].y);N==="down"?D-=r.head:z+=r.head;const tt=[...s.querySelectorAll(`.${o}-group`)].map(U=>ft(U,c));let st=[[z,D]];for(const U of tt)for(const et of[U.t,U.b])st=st.flatMap(([rt,ct])=>et>rt+1&&et<ct-1?[[rt,et],[et,ct]]:[[rt,ct]]);const V=(U,et)=>tt.some(rt=>(U+et)/2>rt.t&&(U+et)/2<rt.b&&X>rt.l&&X<rt.r);if(st.length>1){const U=st.filter(([rt,ct])=>!V(rt,ct));[z,D]=(U.length?U:st).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const P=[1/2,1/3,2/3].map(U=>{const et=z+(D-z)*U;return{l:X-b/2-u("1"),r:X+b/2+u("1"),t:et-h/2,b:et+h/2}});j.push({k:O,cands:P,on:!0,card:N==="down"?M.to:M.from})}}else if(N==="trunk"||N==="rail"){const w=x.x(Math.max(G.rect.l,N==="rail"?W.rect.l:G.rect.l)+u(N==="trunk"?"8":"3"),Y),_=lt(G,"bottom",w);if(N==="rail"){if(K=[_,lt(W,"top",w)],m){const q=W.rect.t-u("6");j.push({k:O,cands:E({l:w+u("2-5"),r:w+u("2-5")+b,t:q-h/2,b:q+h/2},M.to,-1),on:!1,card:M.to})}}else{const q=x.x(W.rect.l+u("6"),Y),R=x.y(W.rect.t-k,Y);K=[_,{x:w,y:R},{x:q,y:R},lt(W,"top",q)],m&&j.push({k:O,cands:E({l:q+u("2-5"),r:q+u("2-5")+b,t:R-h/2,b:R+h/2},M.to,-1),on:!1,card:M.to})}}else{const w=Math.min(A.get(M.from)??d,A.get(M.to)??d),_=x.x(n.gutter?C+(n.lanes[O]?2*u("3-5"):u("3-5")):w-u("2-5"),Y),q=x.y(G.rect.t+(G.rect.b-G.rect.t)*n.exits[O],Y),R=lt(G,"right",q),Q=x.x(W.rect.r-u("6"),Y),X=N==="end-down",z=x.y(X?W.rect.t-k:W.rect.b+k,Y);K=[R,{x:_,y:R.y},{x:_,y:z},{x:Q,y:z},lt(W,X?"top":"bottom",Q)];const D=X?M.to:T[W.i+1]?.id??M.to;m&&j.push({k:O,cands:E({l:Q-u("2-5")-b,r:Q-u("2-5"),t:z-h/2,b:z+h/2},D,X?-1:1),on:!1,card:D})}const $=ue(K,Y,x);S.lines.push({i:O,from:M.from,to:M.to,kind:M.kind,pts:$,tip:$[$.length-1],dir:Ht($),width:Y})}),S.crossings=Ct(S.lines),S.through=Dt(S.lines,p,i),S.outside=xe(S.lines,d,f,r);const{obstacles:L}=$e(s,c,o,0);L.heads=S.lines.map(M=>me(M,r));const F=[],I={l:0,t:0,r:d,b:f};for(const M of j){const O=W=>{const Y=ce(W,u("1"));return W.l<I.l-.5||W.r>I.r+.5||W.t<I.t-.5||W.b>I.b+.5||p.some(K=>de(Y,K))||F.some(K=>ut(Y,K))||L.heads.some(K=>ut(Y,K))||L.rects.some(K=>ut(Y,K))||S.lines.some(K=>K.i!==M.k&&pt(K.pts).some(([m,b])=>ut(Y,ye(m,b,K.width))))},N=M.cands.find(W=>!O(W));N||(B[M.card]=(B[M.card]??0)+1,S.unseated.push(M.k));const G=N?be(N,l,g,W=>!O(W)):M.cands[0];F.push(G),S.labels.push({i:M.k,text:i.edges[M.k].label,box:G,on:M.on})}return{geo:S,grow:B}}function xn(t,e){const n=r=>String(Math.round(r*100)/100);let a=`M${n(t[0].x)} ${n(t[0].y)}`;for(let r=1;r<t.length-1;r++){const o=t[r-1],s=t[r],c=t[r+1],u=Math.hypot(s.x-o.x,s.y-o.y),y=Math.hypot(c.x-s.x,c.y-s.y),p=Math.min(e,u/2,y/2);if(p<.5){a+=`L${n(s.x)} ${n(s.y)}`;continue}const l={x:s.x+(o.x-s.x)/u*p,y:s.y+(o.y-s.y)/u*p},g={x:s.x+(c.x-s.x)/y*p,y:s.y+(c.y-s.y)/y*p};a+=`L${n(l.x)} ${n(l.y)}Q${n(s.x)} ${n(s.y)} ${n(g.x)} ${n(g.y)}`}const i=t[t.length-1];return`${a}L${n(i.x)} ${n(i.y)}`}var kn={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function Mn(t,e,n,a,i){const r=kn[e.dir],o=e.kind==="dashed",s=n.head,c=n.head/2,u=o?1:s-1,y=e.pts.map(E=>({...E})),p=y[y.length-1];p.x-=r.x*u,p.y-=r.y*u;const l=e.tip.x-r.x*s,g=e.tip.y-r.y*s,x=-r.y*c,d=r.x*c,f=E=>Math.round(E*100)/100,S=it(e.kind),B=o?`<path class="${t}-tip" data-kind="${S}" data-open="" d="M${f(l+x)} ${f(g+d)}L${f(e.tip.x)} ${f(e.tip.y)}L${f(l-x)} ${f(g-d)}"/>`:`<path class="${t}-tip" data-kind="${S}" d="M${f(e.tip.x)} ${f(e.tip.y)}L${f(l+x)} ${f(g+d)}L${f(l-x)} ${f(g-d)}Z"/>`,C=e.dot?`<circle class="${t}-dot" cx="${f(e.dot.x)}" cy="${f(e.dot.y)}" r="${n.dot/2}"/>`:"";return`<g class="${t}-edge" data-edge="${e.i}" data-from="${it(e.from)}" data-to="${it(e.to)}"><path class="${t}-line" data-kind="${S}" d="${xn(y,i)}"${a?` mask="url(#${it(a)})"`:""}/>${B}${C}</g>`}function Me(t,e,n,a){const i=new Map,r=new Map;for(const s of e.crossings)r.has(s.under)||r.set(s.under,[]),r.get(s.under).push(s);let o="";for(const[s,c]of r){const u=`${a}-cut-${s}`;i.set(s,u);const y=c.map(p=>{const l=e.lines[p.top],g=e.lines[p.under],x=l.width/2+n.cut,d=g.width/2+1;return p.underVertical?`<rect x="${p.at.x-d}" y="${p.at.y-x}" width="${2*d}" height="${2*x}" fill="black"/>`:`<rect x="${p.at.x-x}" y="${p.at.y-d}" width="${2*x}" height="${2*d}" fill="black"/>`}).join("");o+=`<mask id="${it(u)}" maskUnits="userSpaceOnUse" x="0" y="0" width="${e.w}" height="${e.h}"><rect x="0" y="0" width="${e.w}" height="${e.h}" fill="white"/>${y}</mask>`}return{defs:o,ids:i}}function Se(t,e,n,a){const{defs:i,ids:r}=Me(t,e,n,a),o=e.lifelines.map(y=>`<path class="${t}-life" d="M${y.x} ${y.y1}V${y.y2}"/>`).join("")+(e.bars??[]).map(y=>`<rect class="${t}-bar" x="${y.l}" y="${y.t}" width="${Math.round((y.r-y.l)*100)/100}" height="${Math.round((y.b-y.t)*100)/100}"/>`).join(""),s=e.lines.map((y,p)=>Mn(t,y,n,r.get(p)??null,y.from===y.to?n.radiusXs:n.radius)).join(""),c=`<svg class="${t}-svg" width="${e.w}" height="${e.h}" viewBox="0 0 ${e.w} ${e.h}" focusable="false">${i?`<defs>${i}</defs>`:""}${o}<g class="${t}-edges">${s}</g></svg>`,u=e.labels.map(y=>`<span class="${t}-label" data-edge="${y.i}"${y.on?' data-on=""':""}${Tt(y.text)>1?' data-lines="2"':""} style="left:${Math.round(y.box.l*100)/100}px;top:${Math.round(y.box.t*100)/100}px;width:${Math.round((y.box.r-y.box.l)*100)/100}px">${y.text.split(` +`).map(it).join("<br>")}</span>`).join("");return c+u}function Gt(t,e,n,a,i,r,o,s){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const y=cn(t),p=hn(u,n),l=pn(e,y,p);s?.(l.least);const g=t.clientWidth,x=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),d=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:x&&L.layout!=="drawn"?x:void 0};let f=!1;const S=L=>{if(f=!1,e.type!=="flowchart")return L;r({...L,heights:void 0,words:void 0});const F=ht(),I=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const O=M.querySelector(`.${n}-words`);if(!O)return;const N=M.getBoundingClientRect(),G=K=>{const m={w:K.width+2*y.space("2-5"),h:K.height+2*y.space("2")},b=1-m.w/N.width,h=b>.05?m.h/2/b:m.h*10;return Math.max(y.space("16"),Math.ceil(N.width/5),Math.ceil(2*h))},W=O.getBoundingClientRect();let Y=G(W);if(Y>N.width){const K=k=>(M.style.setProperty("--_ww",`${k}px`),O.getBoundingClientRect()),m=Math.floor(M.clientWidth-2*y.space("2-5"));let b=Math.ceil(W.width),h=W.height;for(;b<m&&K(m).height<h-.5;){let k=b,$=m;for(;$-k>1;){const q=k+$>>1;K(q).height<h-.5?$=q:k=q}const w=K($),_=G(w);if(_<=N.width){Y=_,I[M.dataset.node]=$;break}b=$,h=w.height}M.style.removeProperty("--_ww")}F[M.dataset.node]=Y,Y>N.width&&(f=!0)}),{...L,heights:F,words:Object.keys(I).length?I:void 0}},B=()=>({m:e,tk:y,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:o}),C=i.autoOpen?{open:!1,autoOpen:void 0}:{},E=(L,F)=>F.map(I=>Et(e,L.lines.find(M=>M.i===I))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:y,least:l.least};if(g>=l.least&&!e.unplaced){const L=O=>{let N=d({...i,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return N=S(N),r(N),{dd:N,g:$n(B(),p)}};let{dd:F,g:I}=L(!1);const M=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||f;if(!M(I)&&I.unseated.length&&I.unseated.every(O=>I.bounded?.includes(O))){const O=L(!0);!M(O.g)&&!O.g.unseated.length&&({dd:F,g:I}=O)}if(!M(I)&&!I.unseated.length)return I.crossings.length&&o?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(O=>`${Et(e,I.lines[O.top])} over ${Et(e,I.lines[O.under])}`).join("; ")}`),{dyn:F,geo:I,ink:Se(n,I,y,a),tokens:y,least:l.least};f&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: a decision would be taller than it is wide`),I.misfit?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${I.misfit.join("; ")}`),I.through.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.through)} would pass through a node`),I.overlaps?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.overlaps)} would lie on one another`),I.outside.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.outside)} would leave the drawing`),I.unseated.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: no clean seat for ${I.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=d({...i,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(A=S(A),r(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:y,least:l.least};const T=ne(e);let Z=ke(B(),p,T,A.grow);for(let L=0;L<6&&Object.keys(Z.grow).length;L++){const F=ht(A.grow);for(const[I,M]of Object.entries(Z.grow))F[I]=(yt(F,I)??0)+M;A={...A,grow:F},r(A),Z=ke(B(),p,T,F)}const j=Z.geo;if(j.unseated.length>0||j.through.length>0||j.outside.length>0||T.third){j.unseated.length&&o?.(`the stacked drawing has no clean seat for ${[...new Set(j.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),j.through.length&&o?.(`in the stacked drawing ${E(j,j.through)} would pass through a node, so its lines are not drawn`),j.outside.length&&o?.(`in the stacked drawing ${E(j,j.outside)} would leave the drawing, so its lines are not drawn`),T.third&&o?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={...j,lines:[],labels:[],crossings:[]};return{dyn:d({...A,grow:ht(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:y,least:l.least}}return j.crossings.length&&o?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${j.crossings.map(L=>`${Et(e,j.lines[L.top])} over ${Et(e,j.lines[L.under])}`).join("; ")}`),{dyn:A,geo:j,ink:Se(n,j,y,a),tokens:y,least:l.least}}function Et(t,e){const n=t.byId.get(e.from)?.name??e.from,a=t.byId.get(e.to)?.name??e.to;return`${n} to ${a}`}function Sn(t,e,n,a,i,r){const o=new Set;if(r){o.add(r);for(const d of n?.lines??[])d.from===r&&o.add(d.to),d.to===r&&o.add(d.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(d=>d.toggleAttribute("data-near",o.has(d.dataset.node))),!n||!a)return;const s=d=>!!r&&(d.from===r||d.to===r),c=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(d=>u.set(d.getAttribute("data-edge"),d));for(const d of n.lines){const f=u.get(String(d.i));f&&(f.toggleAttribute("data-lit",s(d)),f.toggleAttribute("data-dim",!!r&&!s(d)))}if(t.querySelectorAll(`.${e}-label`).forEach(d=>{const f=n.lines.find(S=>String(S.i)===d.dataset.edge);d.toggleAttribute("data-lit",!!(f&&s(f)))}),c){for(const d of n.lines)if(s(d)){const f=u.get(String(d.i));f&&c.appendChild(f)}}const y=Ct(n.lines,s),{defs:p,ids:l}=Me(e,{...n,crossings:y},a,i),g=t.querySelector(`.${e}-svg`);if(!g)return;let x=g.querySelector("defs");!x&&p&&(x=document.createElementNS("http://www.w3.org/2000/svg","defs"),g.insertBefore(x,g.firstChild)),x&&(x.innerHTML=p),n.lines.forEach((d,f)=>{const S=u.get(String(d.i))?.querySelector(`.${e}-line`);if(!S)return;const B=l.get(f);B?S.setAttribute("mask",`url(#${B})`):S.removeAttribute("mask")})}var En=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function An(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",En()||qn(t)?"done":"pending")}}var Ln=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function qn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Ln(t))!==null}catch{return!1}}function Ee(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function In(t,e,n,a=!1,i=!1){const r=a?It(t):null;if(r&&n.startsWith("Arrow")){const u={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?r[e]?.[u]??null:null}const o=t.byId.get(e)?.i??0,s=t.nodes.length;let c;if(n==="ArrowRight"||n==="ArrowDown")c=o+1;else if(n==="ArrowLeft"||n==="ArrowUp")c=o-1;else if(n==="Home")c=0;else if(n==="End")c=s-1;else return null;return t.nodes[Math.max(0,Math.min(s-1,c))].id}var On=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Ae=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],_n=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],Le=t=>t==null||t===!1;function Cn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Kt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const a=n?Ae:On;for(const o of a)Le(e.a[o])&&t.removeAttribute(o);for(const[o,s]of Object.entries(e.a)){if(o==="class")continue;if(o==="style"){const u=t.style,y=new Map(String(s??"").split(";").map(p=>{const l=p.indexOf(":");return[p.slice(0,l).trim(),p.slice(l+1).trim()]}).filter(([p])=>p));for(const[p,l]of y)u.getPropertyValue(p).trim()!==l&&u.setProperty(p,l);for(const p of _n)y.has(p)||u.removeProperty(p);continue}if(n&&!Ae.includes(o))continue;if(Le(s)){t.removeAttribute(o);continue}const c=s===!0?"":String(s);t.getAttribute(o)!==c&&t.setAttribute(o,c)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(o=>typeof o!="string"&&"slot"in o))return;const i=[...t.children];let r=0;for(const o of e.c)if(!(typeof o=="string"||"slot"in o)){for(let s=r;s<i.length;s++)if(Cn(i[s],o)){Kt(i[s],o,!1),r=s+1;break}}}function jn(t,e,n,a){if(n===a)return;const i=r=>t.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(a)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",a=0;function i(l,g,x){return{prefix:n,base:l,hasSource:g.source!==void 0&&g.source!==null&&g.source!=="",hiddenClass:"visually-hidden",viewer:x?x.keys:void 0}}function r(l,g,x,d){var f=function(S){return'<kbd class="kbd">'+it(S)+"</kbd>"};return{source:it(String(g.source||"")),summary:it(String(g.summary||"")),hint:zt(l).map(function(S){return"<span>"+S.keys.map(f).join(" ")+" "+it(S.words)+"</span>"}).join(""),toggle:'<button type="button" class="btn diagram-toggle" data-variant="secondary" data-size="sm" aria-expanded="'+(d?"true":"false")+'" aria-controls="'+it(x)+'-list"><span>'+(d?"Hide the list":"View as list")+"</span></button>"}}function o(l,g,x){var d=Mt(l),f=Ft(d,{},i(g,l,x)),S=Rt(f,r(d,l,g,!1)),B=S.indexOf(">");return{open:S.slice(0,B+1),inner:S.slice(B+1,S.length-9),warnings:d.warnings}}var s=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],c=["--_cols","--_gpad","--_track"];function u(l,g,x,d){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(l).direction==="rtl",B=g.layout==="auto"&&(g.type==="architecture"||g.type==="flowchart"||g.type==="schema"),C=B?Array.isArray(g.placement)?g.placement:g.placement?[g.placement]:[]:[];B&&!C.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var E=g.direction?[g.direction]:g.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var J=0;J<C.length;J++)if(C[J].direction===H)return C[J]},T=Mt(g,{rtl:S,placement:B?A(E[0]):void 0});if(!x||!f||!l.querySelector(":scope > .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++a+"-title"););f="dg"+a}var Z=o(g,f,d),j=document.createElement("div");j.innerHTML=Z.open+"</figure>";var ot=j.firstChild;s.forEach(function(H){l.removeAttribute(H)}),c.forEach(function(H){l.style.removeProperty(H)});for(var L=0;L<ot.attributes.length;L++){var F=ot.attributes[L];F.name==="class"?l.classList.add.apply(l.classList,F.value.split(" ")):F.name==="style"?l.style.cssText=F.value+";"+l.style.cssText:l.setAttribute(F.name,F.value)}l.querySelectorAll(":scope > :not(script[data-diagram])").forEach(function(H){H.remove()}),l.insertAdjacentHTML("beforeend",Z.inner)}T.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var I=i(f,g,d),M={},O=null,N=null,G=null,W=null,Y=Object.create(null),K=function(H){Y[H]||(Y[H]=1,console.warn("Basalt diagram: "+H))},m=function(H){Kt(l,Ft(T,H,I))},b=l.querySelector(".diagram-ink"),h=l.querySelector(".diagram-toggle"),k=!d&&T.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,_=function(){k&&Ee(l)};function q(){Sn(l,n,O&&O.geo,O&&O.tokens,f,N||W||G),X()}var R=null,Q=!d&&matchMedia("(hover: none), (pointer: coarse)").matches;function X(){var H=Q&&!d&&b&&b.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(Q&&!d)),H&&!R){var J=l.querySelector(":scope > .diagram-foot");if(!J)return;R=document.createElement("button"),R.type="button",R.className="btn diagram-clear",R.setAttribute("data-variant","secondary"),R.setAttribute("data-size","sm"),R.innerHTML="<span>Clear highlight</span>",R.addEventListener("click",function(){W&&(W=null,q())}),J.appendChild(R)}else!H&&R&&(R.remove(),R=null);R&&(W?R.removeAttribute("aria-disabled"):R.setAttribute("aria-disabled","true"))}function z(H){if(!H.defaultPrevented){var J=Ge(l,n,H,W);J!==void 0&&(_(),Q=!0,W=J,q())}}function D(){h&&(h.setAttribute("aria-expanded",String(!!M.open)),h.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function tt(){if(B&&C.length>1&&!d){for(var H=null,J=0;J<E.length&&!H;J++){var dt=A(E[J]);if(dt){var kt=Mt(g,{rtl:S,placement:dt}),Tn=Gt(l,kt,n,f,{},function(jt){Kt(l,Ft(kt,jt,I))});Tn.dyn.layout==="drawn"&&(H=kt)}}T=H||Mt(g,{rtl:S,placement:A(E[0])})}O=(d?d.measure:Gt)(l,T,n,f,M,m,K),M=O.dyn,m(M),D();var Zt=l.querySelector(":scope > .diagram-hint");if(Zt){var Be=zt(T,M.layout==="drawn").map(function(jt){return"<span>"+jt.keys.map(function(Rn){return'<kbd class="kbd">'+it(Rn)+"</kbd>"}).join(" ")+" "+it(jt.words)+"</span>"}).join("");Zt.innerHTML!==Be&&(Zt.innerHTML=Be)}mt(T,M)||(G=W=null);var Te=b&&O.ink!==w;Te&&(b.innerHTML=O.ink,w=O.ink),q(),k&&O.tokens&&(An(l,!!(O.geo&&O.geo.lines.length)),Te&&$&&$.redrawn()),d&&d.onMeasured&&O.tokens&&d.onMeasured(O,l),T.text&&typeof e.diagramText=="function"&&e.diagramText(l,T,g)}function st(H){M=H,m(M)}function V(H){var J=M.stop;M=Object.assign({},M,{stop:H}),jn(l,n,J,H)}var P=function(H){var J=H&&H.closest?H.closest(".diagram-node"):null;return J&&l.contains(J)?J:null};function U(H){var J=P(H.target);if(!(!J||H.defaultPrevented)){if(_(),H.key==="Escape"){!d&&(N||G||W)&&(H.preventDefault(),N=G=W=null,q());return}if(mt(T,M)){var dt=In(T,J.getAttribute("data-node"),H.key,M.layout==="drawn");if(dt){H.preventDefault(),V(dt);var kt=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');kt&&kt.focus()}}}}function et(H){var J=P(H.target);if(J){_();var dt=J.getAttribute("data-node");N=J.matches(":focus-visible")?dt:null,mt(T,M)&&M.stop!==dt&&V(dt),q()}}function rt(H){var J=P(H.target);J&&(P(H.relatedTarget)||(N=null),M.keep===J.getAttribute("data-node")&&st(Object.assign({},M,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var J=P(H.target);J&&_();var dt=J&&mt(T,M)?J.getAttribute("data-node"):null;dt!==G&&(G=dt,q())}}function At(){G&&(G=null,q())}function bt(){_(),st(Object.assign({},M,{open:!M.open,autoOpen:void 0})),D()}l.addEventListener("keydown",U),l.addEventListener("focusin",et),l.addEventListener("focusout",rt),l.addEventListener("pointerover",ct),l.addEventListener("pointerleave",At),l.addEventListener("click",z),h&&h.addEventListener("click",bt),tt();var xt=l.clientWidth,Vt=0,qe=!0,Ie=new ResizeObserver(function(){Math.abs(l.clientWidth-xt)<.5||(xt=l.clientWidth,cancelAnimationFrame(Vt),Vt=requestAnimationFrame(tt))});Ie.observe(l),document.fonts&&document.fonts.ready.then(function(){qe&&tt()});var Oe=matchMedia("(forced-colors: active)"),_e=T.nodes.some(function(H){return H.mark});_e&&Oe.addEventListener("change",tt),k&&($=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return T},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},g));var Ce=!d&&g.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,g,{model:T,settle:_,animated:k}):null,je=l.querySelector(":scope > .diagram-foot"),Bn=!d&&g.export===!0&&je&&typeof e.diagramExport=="function"?e.diagramExport(je,l):[];l.__diagram={stop:function(){Ce&&Ce.destroy(),Bn.forEach(function(H){H.remove()}),qe=!1,Ie.disconnect(),cancelAnimationFrame(Vt),_e&&Oe.removeEventListener("change",tt),$&&$.destroy(),l.removeEventListener("keydown",U),l.removeEventListener("focusin",et),l.removeEventListener("focusout",rt),l.removeEventListener("pointerover",ct),l.removeEventListener("pointerleave",At),l.removeEventListener("click",z),R&&R.remove(),h&&h.removeEventListener("click",bt)},layout:tt,key:y(g),send:$&&$.sendValue?$.sendValue:null}}function y(l){try{return JSON.stringify(l,function(g,x){return g==="packet"&&x&&typeof x=="object"?Object.assign({},x,{send:void 0}):x})}catch{return null}}function p(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var g=l.querySelector(":scope > script[data-diagram]");if(g)try{u(l,JSON.parse(g.textContent),!0)}catch(x){console.error("Basalt diagram: this figure could not be drawn",x)}}})}e.diagramMarkup=o,e.diagramKit={draw:u,buildModel:Mt,figureKey:Xe,figureList:sn,hintEntries:zt,toHtml:Rt,escapeHtml:it,settleEntrance:Ee,measureFigure:Gt},t.diagram=function(l,g){var x=l.__diagram,d=x&&x.send?y(g):null;if(d!==null&&d===x.key){x.send(g.packet?g.packet.send:void 0);return}u(l,g)},e.step(62,"wireDiagrams",p)})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index d1f26ee9..d415d989 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -844,9 +844,6 @@ ] }, "diagram-export": { - "classes": [ - "diagram-download" - ], "text": [ "\"export\"\\s*:\\s*true" ], @@ -859,6 +856,19 @@ "budget": 12000, "usage": 700 }, + "diagram-text": { + "text": [ + "\"variant\"\\s*:\\s*\"text\"" + ], + "textWords": [ + "a sequence's \"variant\": \"text\"" + ], + "requires": [ + "diagram" + ], + "budget": 8000, + "usage": 700 + }, "sparkline": { "classes": [ "sparkline", diff --git a/.agent/skills/basalt-html/parts/usage/diagram-text.md b/.agent/skills/basalt-html/parts/usage/diagram-text.md new file mode 100644 index 00000000..fdc9beb4 --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-text.md @@ -0,0 +1,6 @@ +# diagram-text + +Added for you when a sequence's JSON says `"variant": "text"`. + +- The same data as box-drawing characters in a code block, where its widest line fits; elsewhere the transcript (one line a message), which the page holds before script. Nothing scrolls sideways, and the block is hidden from assistive technology: the title, the summary and "View as list" carry it. +- With `"motion": "animated"` it builds by ink: labels and arrows lift in message order, no line hidden, no caret. diff --git a/packages/react/build.mjs b/packages/react/build.mjs index 2405e48a..fc25e0e8 100644 --- a/packages/react/build.mjs +++ b/packages/react/build.mjs @@ -163,7 +163,7 @@ await esbuild.build({ ...fs.readdirSync(path.join(here, "src", "tooling")).filter((f) => /\.ts$/.test(f)).map((f) => path.join(here, "src", "tooling", f)), ], define: { __PHOSPHOR_NOTICE__: JSON.stringify(phosphorNotice), __BASALT_ROOT_MAP__: JSON.stringify(JSON.stringify(rootMap)) }, - plugins: [{ name: "lazy-modules", setup(build) { build.onResolve({ filter: /^\.\/(command-panel|glyph-flight|diagram-motion|diagram-viewer|diagram-layout)$/ }, (args) => (args.kind === "dynamic-import" ? { path: `${args.path}.js`, external: true } : undefined)); } }], + plugins: [{ name: "lazy-modules", setup(build) { build.onResolve({ filter: /^\.\/(command-panel|glyph-flight|diagram-motion|diagram-viewer|diagram-layout|diagram-text)$/ }, (args) => (args.kind === "dynamic-import" ? { path: `${args.path}.js`, external: true } : undefined)); } }], outdir: dist, bundle: true, splitting: true, diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index f561012f..c3c53c88 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -217,6 +217,8 @@ export interface Model { rtl?: boolean; /** An automatic figure with no placement yet (1.8): it is stacked, every word present, until one arrives. */ unplaced?: boolean; + /** A sequence drawn as text art (1.2): a code block holding the art where it fits and the transcript where it does not. */ + text?: boolean; } const SIDES: DiagramSide[] = ["top", "right", "bottom", "left"]; @@ -530,7 +532,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model cols = Math.max(1, ...nodes.map((n) => n.col)); } const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, ...nodes.map((n) => n.row2)); - const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined }; + const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined, text: (type === "sequence" && spec.variant === "text") || undefined }; if (spec.layout === "auto" && !unplaced && type !== "schema") chooseSides(model); if (checks && nodes.length > 1 && !spatialTable(model)) warn("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"); return model; @@ -737,6 +739,8 @@ export interface Dyn { bare?: boolean; /** The list was opened by a bare stack, not by the reader: it closes again when lines are drawn. A press of the toggle clears it. */ autoOpen?: boolean; + /** The text variant shows its art (1.2): its widest line fits the block. */ + art?: boolean; /** The drawn layout keeps space-3 above its first row and below its last, so a label beside a line in a 40px row has a seat (1.8). */ pad?: boolean; } @@ -924,9 +928,11 @@ function buildKey(P: string, m: Model): VElement | null { if (used.has("decision")) entry(boxSwatch(P, "decision"), m.shapeLabels.decision); } const kinds = new Set<DiagramLineKind>(m.type === "sequence" ? m.steps.flatMap((s) => ("n" in s ? [s.kind] : [])) : m.edges.filter((e) => !e.fk).map((e) => e.kind)); + // The text art's key is its own glyphs (1.2): the key is built from what is drawn. + const glyph = (g: string, ink: string) => h("span", { class: `${P}-key-glyph`, "data-ink": ink, "aria-hidden": "true" }, g); for (const k of ["main", "plain", "dashed"] as const) { const words = m.legend[k]; - if (kinds.has(k) && words) entry(lineSwatch(P, k), words, { "data-line": "" }); + if (kinds.has(k) && words) entry(m.text ? glyph(k === "main" ? "━━▶" : k === "dashed" ? "┄┄▷" : "──▶", k === "main" ? "main" : "plain") : lineSwatch(P, k), words, { "data-line": m.text ? undefined : "" }); } if (m.type === "schema" && m.edges.length) { // The foreign-key line where it is drawn; where it is not, the row says it, and so does the key. @@ -935,7 +941,7 @@ function buildKey(P: string, m: Model): VElement | null { } if (m.type === "sequence") { // A bar on a dashed lifeline, where one is drawn (1.2); then each frame operator drawn, its letters set as the tab sets them, and its words. - if (m.bars.length) entry(h("svg", { class: `${P}-swatch`, "data-shape": "bar", ...svgA(16, 16) }, h("path", { class: `${P}-life`, d: "M8 0V16" }), h("rect", { class: `${P}-bar`, x: 4.5, y: 2.5, width: 7, height: 11, rx: 1.5 })), m.legend.activation ?? "Working", { "data-when": "drawn" }); + if (m.bars.length) entry(m.text ? glyph("┃", "working") : h("svg", { class: `${P}-swatch`, "data-shape": "bar", ...svgA(16, 16) }, h("path", { class: `${P}-life`, d: "M8 0V16" }), h("rect", { class: `${P}-bar`, x: 4.5, y: 2.5, width: 7, height: 11, rx: 1.5 })), m.legend.activation ?? "Working", m.text ? {} : { "data-when": "drawn" }); const ops = new Set(m.steps.flatMap((st) => ("open" in st ? [st.open] : []))); for (const op of ["opt", "loop", "alt"] as const) if (ops.has(op)) entries.push(h("li", { class: `${P}-entry` }, h("span", { class: `${P}-key-letters`, "data-op": "" , "aria-hidden": "true" }, op), h("span", null, m.frameWords[op]))); } @@ -1050,6 +1056,9 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { out.push(h("div", { class: `${P}-gbox`, "data-group": g.id, "data-depth": g.depth > 1 ? g.depth : undefined, style: `--_c:${c.c1};--_c2:${c.c2 + 1};--_r:${c.r1};--_r2:${c.r2 + 1}${lv[0]! > 1 ? ";--_gt:2" : ""}${lv[1]! > 1 ? ";--_ge:2" : ""}${lv[2]! > 1 ? ";--_gb:2" : ""}${lv[3]! > 1 ? ";--_gs:2" : ""}`, "aria-hidden": "true" }, h("span", { class: `${P}-glabel` }, g.label))); } } + // The text variant (1.2): one code block, aria-hidden (the title, the summary and the list carry the figure). Before script it holds the transcript; + // script writes the art where its widest line fits (the diagram-text module). + if (m.text) return [h("pre", { class: `${P}-text`, "aria-hidden": "true", "data-art": dyn.art ? "" : undefined }, h("code", { class: `${P}-text-ink` }, transcript(P, m)))]; if (m.type === "sequence") { // Drawn, each head is in its column (mirrored right to left, 1.7). out.push(h("ul", { class: `${P}-cast` }, m.nodes.map((n) => h("li", { class: `${P}-actor`, style: m.rtl ? `--_ac:${n.col}` : undefined }, nodeTree(ctx, m, n, dyn))))); @@ -1084,6 +1093,28 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { return out; } +/** + * The text variant's transcript (1.2), where the art does not fit: the participants on a line, then each message as number, sender, arrow, receiver, + * label and note; frames as indented brackets. A line breaks between participants and between words, never inside a name (each name is held whole). + */ +export function transcript(P: string, m: Model): VNode[] { + const out: VNode[] = []; + const held = (s: string) => h("span", { class: `${P}-tx-name` }, s); + const arrow = (k: DiagramLineKind) => (k === "main" ? "━▶" : k === "dashed" ? "┄▷" : "─▶"); + out.push(h("span", { class: `${P}-tx-line`, "data-ink": "names" }, m.nodes.flatMap((n, k) => [k ? " · " : "", held(n.name)])), "\n"); + let indent = 0; + for (const s of m.steps) { + const pad = " ".repeat(indent); + if ("band" in s) { out.push(h("span", { class: `${P}-tx-line`, "data-ink": "band" }, `${pad}── ${s.band} ──`), "\n"); continue; } + if ("open" in s) { out.push(h("span", { class: `${P}-tx-line`, "data-ink": "frame" }, pad, h("span", { "data-ink": "op" }, `[${s.open}]`), ` ${s.label}`), "\n"); indent++; continue; } + if ("otherwise" in s) { out.push(h("span", { class: `${P}-tx-line`, "data-ink": "frame" }, " ".repeat(indent - 1), h("span", { "data-ink": "op" }, "[else]"), ` ${s.otherwise}`), "\n"); continue; } + if ("close" in s) { indent = Math.max(0, indent - 1); out.push(h("span", { class: `${P}-tx-line`, "data-ink": "frame" }, `${" ".repeat(indent)}[end]`), "\n"); continue; } + const a = m.byId.get(s.from)?.name ?? s.from, b = m.byId.get(s.to)?.name ?? s.to; + out.push(h("span", { class: `${P}-tx-line`, "data-n": s.n }, pad, h("span", { "data-ink": "num" }, `${s.n} `), held(a), " ", h("span", { "data-ink": s.kind === "main" ? "main" : "plain" }, arrow(s.kind)), " ", held(b), " ", h("span", { "data-ink": "label" }, s.label), s.note ? [" ", h("span", { "data-ink": "note" }, `(${s.note})`)] : null), "\n"); + } + return out; +} + function sequenceSteps(ctx: TreeContext, m: Model): VElement { const { P } = ctx; const root: VNode[] = []; @@ -1328,7 +1359,7 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { // The keys sentence describes the drawing only where it has stops (a bare stack has none). "aria-describedby": group ? (stops ? `${ids.summary} ${ids.keys}` : ids.summary) : undefined, "data-stops": stops ? "" : undefined, - }, drawingChildren(ctx, m, dyn), h("div", { class: `${P}-ink`, "aria-hidden": "true" }), h("span", { class: `${P}-ruler`, "aria-hidden": "true" })), + }, drawingChildren(ctx, m, dyn), m.text ? null : h("div", { class: `${P}-ink`, "aria-hidden": "true" }), h("span", { class: `${P}-ruler`, "aria-hidden": "true" })), keyTree(P, m), h("p", { class: `${P}-hint`, "data-kbd-hint": "", "aria-hidden": "true" }, { slot: "hint" }), // On touch, where lines are drawn, a line in the hint's seat and type says how to trace (DECISIONS 306, 1.5); the stylesheet shows it only then. @@ -2422,6 +2453,8 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin // A list a bare stack opened closes when the figure is laid out again (it opens again if the stack is still bare). const closed: Dyn = current.autoOpen ? { open: false, autoOpen: undefined } : {}; const names = (geo: Geo, list: number[]) => list.map((k) => lineName(m, geo.lines.find((l) => l.i === k)!)).join(", "); + // The text variant is one code block: no drawn layout and no lines; the art module chooses art or transcript by width (1.2). + if (m.text) return { dyn: { ...current, layout: "stacked", bare: undefined }, geo: null, ink: "", tokens: tk, least: mins.least }; if (W >= mins.least && !m.unplaced) { const drawnTry = (pad: boolean) => { let dd = stopOf({ ...current, ...closed, layout: "drawn", grow: undefined, track: undefined, bare: undefined, pad: pad || undefined }); @@ -2596,7 +2629,7 @@ export function keyTarget(m: Model, from: string, key: string, drawn = false, rt * A tree element is paired with the next DOM element of its tag and class, so an element the tree does not hold (the HTML skill's JSON * script, first in the figure) is passed over, never mistaken for the heading. */ -const MANAGED = ["data-layout", "data-measured", "role", "aria-roledescription", "aria-labelledby", "aria-describedby", "aria-label", "tabindex", "data-stops", "hidden"]; +const MANAGED = ["data-layout", "data-measured", "role", "aria-roledescription", "aria-labelledby", "aria-describedby", "aria-label", "tabindex", "data-stops", "hidden", "data-art"]; const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion", "data-first-visit", "data-rtl"]; const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_gpad"]; const absent = (value: VAttrs[string]) => value === undefined || value === null || value === false; diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 9901d083..9418f9df 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -4,7 +4,7 @@ import { Kbd } from "./kbd"; import { useShortcutsVisible } from "./keyboard"; import { inLevel, usePanelLevel } from "./layers"; import { - applyTrace, buildModel, tapTrace, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, + applyTrace, buildModel, tapTrace, transcript, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, } from "./diagram-core"; import type { DiagramLegend, DiagramMotion, DiagramPlacement, DiagramSpec, Dyn, Measured, Model, VNode } from "./diagram-core"; import type { MotionController } from "./diagram-motion-core"; @@ -14,6 +14,11 @@ let motionLoading: Promise<MotionModule> | undefined; /** The motion code (DECISIONS 292, 2.6): a module of its own, loaded the first time a figure is animated, so a still figure never pays for it. */ const loadMotion = () => (motionLoading ??= import("./diagram-motion").catch((error) => { motionLoading = undefined; throw error; })); +type TextModule = typeof import("./diagram-text"); +let textLoading: Promise<TextModule> | undefined; +/** The text art (DECISIONS 306, 1.2): generated by a module of its own, loaded by a figure with variant="text". */ +const loadText = () => (textLoading ??= import("./diagram-text").catch((error) => { textLoading = undefined; throw error; })); + type LayoutModule = typeof import("./diagram-layout"); let layoutLoading: Promise<LayoutModule> | undefined; /** Automatic layout (DECISIONS 306, 1.8): elkjs's module, loaded the first time an automatic figure with no placement is measured at 640 or wider. */ @@ -144,7 +149,10 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: else if (callerRef) callerRef.current = el; }, [callerRef]); const [dyn, setDyn] = React.useState<Dyn>({}); - const [ink, setInk] = React.useState(""); + // A text figure's block holds its transcript before script (and on the server), its art once script finds it fits (1.2). + const transcriptHtml = React.useMemo(() => (model.text ? transcript(P, model).map((v) => toHtml(v)).join("") : ""), [model]); + const [ink, setInk] = React.useState(() => transcriptHtml); + const [textModule, setTextModule] = React.useState<TextModule | null>(null); const inkHtml = React.useMemo(() => ({ __html: ink }), [ink]); const measured = React.useRef<Measured | null>(null); const dynRef = React.useRef(dyn); @@ -201,6 +209,25 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const warn = process.env.NODE_ENV !== "production" ? (message: string) => warnOnce(component, message) : undefined; const apply = (d: Dyn) => syncAttributes(fig, figureTree(model, d, options)); const result = (viewer ? viewer.measure : measureFigure)(fig, model, P, base, dynRef.current, apply, warn); + // The text variant (1.2): the art where its widest line fits the block, the transcript otherwise; the art's module loads the first time. + if (model.text) { + const pre = fig.querySelector<HTMLElement>(`.${P}-text`); + if (!textModule) { void loadText().then((mod) => setTextModule(() => mod), () => {}); } + let html = transcriptHtml, art = false; + if (pre && textModule) { + const made = textModule.textArt(model); + const probe = document.createElement("span"); + probe.textContent = "─".repeat(40); + pre.append(probe); + const cw = probe.getBoundingClientRect().width / 40; + probe.remove(); + const cs = getComputedStyle(pre); + const room = pre.clientWidth - Number.parseFloat(cs.paddingLeft) - Number.parseFloat(cs.paddingRight); + if (made.width * cw <= room + 0.5) { html = made.html; art = true; } + } + result.dyn = { ...result.dyn, art: art || undefined }; + result.ink = html; + } measured.current = result; // The same layout is the same state: a measure that changes nothing renders nothing. // (A layout is plain data that the engine builds in one order, so its text is a fair test.) @@ -210,7 +237,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: if (!hasStops(model, result.dyn)) { setHoverTrace(null); setTouchTrace(null); } // A figure hidden (the viewer's list is open) was not measured: the viewer keeps the drawing's size and place it had. if (viewer && result.tokens) viewer.onMeasured(result, fig); - }, [model, base, options, component, viewer, rtl, auto, given, loaded, placements, order, placementFor, dirAt, spec]); + }, [model, base, options, component, viewer, rtl, auto, given, loaded, placements, order, placementFor, dirAt, spec, textModule, transcriptHtml]); // Measured before the first paint, then whenever the figure's width changes or the real faces arrive. React.useLayoutEffect(() => { @@ -235,6 +262,16 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: return () => { live = false; observer.disconnect(); cancelAnimationFrame(frame); if (marks) forced.removeEventListener("change", measure); }; }, [measure, model]); + // An animated text figure builds by ink once its art is first shown (1.2): every line present from the first frame, labels and arrows lifting in order. + const inked = React.useRef(false); + React.useLayoutEffect(() => { + const code = figRef.current?.querySelector<HTMLElement>(`.${P}-text-ink`); + if (!model.text || !animated || !textModule || !dyn.art || inked.current || !code) return; + inked.current = true; + const cs = getComputedStyle(code); + const ms = (name: string, fallback: number) => Number.parseFloat(cs.getPropertyValue(`--basalt-${name}`)) || fallback; + textModule.buildByInk(code, model.steps.filter((st) => "n" in st).length, { slower: ms("duration-slower", 300), step: ms("duration-diagram-step", 250), limit: ms("duration-diagram-limit", 5000) }); + }); const trace = focusTrace ?? touchTrace ?? hoverTrace; React.useLayoutEffect(() => { const fig = figRef.current; diff --git a/packages/react/src/diagram-text.ts b/packages/react/src/diagram-text.ts new file mode 100644 index 00000000..7bb17ec2 --- /dev/null +++ b/packages/react/src/diagram-text.ts @@ -0,0 +1,166 @@ +// A sequence as text art (DECISIONS 306, 1.2): the same data as box-drawing characters, generated here and loaded on demand by a figure with +// variant="text" (React) or by the HTML skill's diagram-text module. The focal participant in a double-line box, the others single-line; lifelines │, a +// working stretch ┃; a main arrow ━━▶, a plain one ──▶, a dashed one ┄┄▷; frames in their own ink with the operator in primary. No character is ever +// written over a word, every frame closes on all four sides, and selecting the block copies the art exactly. Nothing runs at load. + +import type { DiagramLineKind, MBar, Model } from "./diagram-core"; +import { escapeHtml } from "./diagram-core"; + +type Ink = "focal" | "name" | "life" | "working" | "main" | "plain" | "label" | "num" | "note" | "frame" | "op" | "band" | ""; +interface Row { ch: string[]; ink: Ink[]; n?: number } + +/** The art: its HTML (one span a run of one ink, a line a row) and its widest line in characters. */ +export function textArt(m: Model): { html: string; width: number } { + const nodes = m.nodes; + const steps = m.steps; + const len = (s: string) => Array.from(s).length; + // Columns: each head a box round its name; centres far enough apart for every label between them, and for a self-call's words. + const boxW = nodes.map((n) => Math.max(8, len(n.name) + 4)); + const x = nodes.map(() => 0); + let at = 0; + nodes.forEach((_, k) => { x[k] = at + Math.floor(boxW[k]! / 2); at += boxW[k]! + 4; }); + const need = (a: number, b: number, chars: number) => { + const [lo, hi] = a < b ? [a, b] : [b, a]; + const short = chars - (x[hi]! - x[lo]!); + if (short > 0) for (let k = hi; k < nodes.length; k++) x[k]! += short; + }; + for (const s of steps) { + if (!("n" in s)) continue; + const a = m.byId.get(s.from)?.i ?? 0, b = m.byId.get(s.to)?.i ?? 0; + const words = Math.max(len(`${s.n} ${s.label}`), len(s.note ?? "")); + if (a === b) { if (a + 1 < nodes.length) need(a, a + 1, words + 8); } else need(a, b, words + 4); + } + const last = nodes.length - 1; + const selfWidth = Math.max(0, ...steps.map((s) => ("n" in s && s.from === s.to && (m.byId.get(s.from)?.i ?? 0) === last ? len(`${s.n} ${s.label}`) + 8 : 0))); + const W = (x[last] ?? 0) + Math.ceil((boxW[last] ?? 8) / 2) + selfWidth + 2; + const rows: Row[] = []; + const row = (): Row => { const r = { ch: Array<string>(W).fill(" "), ink: Array<Ink>(W).fill("") }; rows.push(r); return r; }; + const put = (r: Row, from: number, text: string, ink: Ink) => { Array.from(text).forEach((c, k) => { const i = from + k; if (i >= 0 && i < W) { r.ch[i] = c; r.ink[i] = ink; } }); }; + // Which participants are working at a message (a bar on its lifeline). + const working = (k: number, n: number) => m.bars.some((bar: MBar) => bar.who === nodes[k]!.id && bar.from <= n && bar.to >= n); + let current = 0; + const lifelines = (r: Row) => nodes.forEach((_, k) => put(r, x[k]!, working(k, current) ? "┃" : "│", working(k, current) ? "working" : "life")); + // Heads. + const top = row(), mid = row(), bottom = row(); + nodes.forEach((n, k) => { + const left = x[k]! - Math.floor(boxW[k]! / 2), w = boxW[k]!; + const [tl, h, tr, v, bl, br] = n.focal ? ["╔", "═", "╗", "║", "╚", "╝"] : ["┌", "─", "┐", "│", "└", "┘"]; + const ink: Ink = n.focal ? "focal" : "name"; + put(top, left, tl + h.repeat(w - 2) + tr, ink); + put(mid, left, v, ink); put(mid, left + w - 1, v, ink); + put(mid, left + Math.floor((w - len(n.name)) / 2), n.name, ink); + put(bottom, left, bl + h.repeat(w - 2) + br, ink); + }); + // Frames: their columns' outer edges, a step inside for a nested one; their sides on every row while open. + const open: Array<{ l: number; r: number }> = []; + const sides = (r: Row) => { for (const f of open) { put(r, f.l, "│", "frame"); put(r, f.r, "│", "frame"); } }; + const spacer = () => { const r = row(); lifelines(r); sides(r); return r; }; + spacer(); + for (const s of steps) { + if ("band" in s) { + const r = row(); + const words = ` ${s.band} `; + put(r, 0, "─".repeat(W), "band"); + put(r, Math.max(0, Math.floor((W - len(words)) / 2)), words, "band"); + spacer(); + continue; + } + if ("open" in s) { + const a = s.a - 1, b = s.b - 1; + const inset = open.length * 2; + const f = { l: Math.max(0, x[a]! - Math.floor(boxW[a]! / 2) - 1 + inset), r: Math.min(W - 1, x[b]! + Math.ceil(boxW[b]! / 2) + (b === last && steps.some((t) => "n" in t && t.from === t.to) ? selfWidth : 0) - inset) }; + const r = row(); + lifelines(r); sides(r); + put(r, f.l, "┌" + "─".repeat(f.r - f.l - 1) + "┐", "frame"); + put(r, f.l + 1, `[${s.open}]`, "op"); + put(r, f.l + len(s.open) + 4, ` ${s.label} `, "label"); + open.push(f); + spacer(); + continue; + } + if ("otherwise" in s) { + const f = open[open.length - 1]; + if (!f) continue; + const r = row(); + lifelines(r); sides(r); + put(r, f.l, "├" + "┄".repeat(f.r - f.l - 1) + "┤", "frame"); + put(r, f.l + 1, "[else]", "op"); + put(r, f.l + 8, ` ${s.otherwise} `, "label"); + spacer(); + continue; + } + if ("close" in s) { + const f = open.pop(); + if (!f) continue; + const r = row(); + lifelines(r); sides(r); + put(r, f.l, "└" + "─".repeat(f.r - f.l - 1) + "┘", "frame"); + spacer(); + continue; + } + current = s.n; + const a = m.byId.get(s.from)?.i ?? 0, b = m.byId.get(s.to)?.i ?? 0; + const said = `${s.n} ${s.label}`; + const shaft = (k: DiagramLineKind) => (k === "main" ? "━" : k === "dashed" ? "┄" : "─"); + const head = (k: DiagramLineKind, right: boolean) => (k === "dashed" ? (right ? "▷" : "◁") : right ? "▶" : "◀"); + const ink: Ink = s.kind === "main" ? "main" : "plain"; + const r1 = row(), r2 = row(); + r1.n = s.n; r2.n = s.n; + lifelines(r1); sides(r1); lifelines(r2); sides(r2); + if (a === b) { + const left = a === last && nodes.length > 1; + const from = left ? x[a]! - 4 : x[a]! + 1; + put(r1, from, left ? "┌──" : "──┐", ink); + put(r2, from, left ? "└─" + head(s.kind, true) : head(s.kind, false) + "─┘", ink); + const wordsAt = left ? from - len(said) - 1 : x[a]! + 5; + put(r1, wordsAt, said.slice(0, len(String(s.n))), "num"); + put(r1, wordsAt + len(String(s.n)) + 1, s.label, "label"); + if (s.note) { const r3 = row(); lifelines(r3); sides(r3); put(r3, left ? from - len(s.note) - 1 : x[a]! + 5, s.note, "note"); } + } else { + const lo = Math.min(x[a]!, x[b]!), hi = Math.max(x[a]!, x[b]!), right = x[b]! > x[a]!; + const wordsAt = lo + Math.max(2, Math.floor((hi - lo - len(said)) / 2)); + put(r1, wordsAt - 1, " ", ""); + put(r1, wordsAt, String(s.n), "num"); + put(r1, wordsAt + len(String(s.n)), " " + s.label + " ", "label"); + const body = shaft(s.kind).repeat(Math.max(1, hi - lo - 2)); + put(r2, lo + 1, right ? body + head(s.kind, true) : head(s.kind, false) + body, ink); + if (s.note) { const r3 = row(); lifelines(r3); sides(r3); const at3 = lo + Math.max(2, Math.floor((hi - lo - len(s.note)) / 2)); put(r3, at3 - 1, ` ${s.note} `, "note"); } + } + } + spacer(); + // One span a run of one ink; a row's trailing spaces dropped, so a copy is the art and no more. + const html = rows.map((r) => { + const end = r.ch.join("").trimEnd().length; + let out = "", run = "", ink: Ink = r.ink[0] ?? ""; + for (let i = 0; i < end; i++) { + if (r.ink[i] !== ink && run) { out += ink ? `<span data-ink="${ink}">${escapeHtml(run)}</span>` : escapeHtml(run); run = ""; } + ink = r.ink[i]!; + run += r.ch[i]; + } + if (run) out += ink ? `<span data-ink="${ink}">${escapeHtml(run)}</span>` : escapeHtml(run); + return r.n ? `<span data-n="${r.n}">${out}</span>` : out; + }).join("\n"); + return { html, width: Math.max(...rows.map((r) => r.ch.join("").trimEnd().length)) }; +} + +/** + * The build by ink (1.2), under motion="animated": before its turn a message's label is secondary and its arrow tertiary; at its turn both lift to their + * resting ink over duration-slower, messages duration-diagram-step apart inside duration-diagram-limit. No line is hidden and there is no caret. It never + * plays under reduced motion, in forced colours, under the hold or in print. Returns a function that settles it at once. + */ +export function buildByInk(code: HTMLElement, steps: number, t: { slower: number; step: number; limit: number }): () => void { + if (matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches || document.documentElement.getAttribute("data-loops") === "held") return () => {}; + const gap = steps > 1 ? Math.min(t.step, (t.limit - t.slower) / (steps - 1)) : 0; + const animations: Animation[] = []; + const cs = getComputedStyle(code); + const secondary = cs.getPropertyValue("--basalt-text-secondary").trim(), tertiary = cs.getPropertyValue("--basalt-text-tertiary").trim(); + code.querySelectorAll<HTMLElement>("[data-n]").forEach((line) => { + const n = Number(line.dataset.n); + line.querySelectorAll<HTMLElement>('[data-ink="label"], [data-ink="main"], [data-ink="plain"]').forEach((el) => { + const rest = getComputedStyle(el).color; + const before = el.dataset.ink === "label" ? secondary : tertiary; + animations.push(el.animate([{ color: before }, { color: before, offset: 0.001 }, { color: rest }], { duration: t.slower, delay: (n - 1) * gap, easing: "ease-out", fill: "backwards" })); + }); + }); + return () => { for (const a of animations) a.finish(); }; +} diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index cd6150d0..3a4a9a55 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4797,6 +4797,37 @@ .basalt-diagram-fword { margin-inline-start: calc(-1 * var(--basalt-space-1-5)); padding-inline: var(--basalt-space-1-5); background: var(--_ground); color: var(--basalt-text-tertiary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); } .basalt-diagram-fword + .basalt-diagram-flabel { margin-inline-start: calc(-1 * var(--basalt-space-1-5)); } .basalt-diagram-key-letters[data-op] { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-semibold); } + /* A sequence as text (DECISIONS 306, 1.2): a code block (surface-sunken, the rim, radius 8, space-4 padding; Geist Mono text-xs on the code line height), + always left to right. The art where its widest line fits, the transcript where it does not: nothing scrolls sideways, and a transcript's line breaks + between participants and words, never inside a name. Inks: the focal participant primary 600, others secondary; lifelines tertiary, a working stretch + secondary; a main arrow primary, plain and dashed secondary; labels primary; numbers, notes and frames tertiary, the operator primary 600. */ + .basalt-diagram-text { + box-sizing: border-box; + margin: 0; + padding: var(--basalt-space-4); + overflow: hidden; + border: var(--basalt-size-hairline) solid var(--basalt-border-rim); + border-top-color: var(--basalt-border-rim-top); + border-radius: var(--basalt-radius-md); + background: var(--basalt-surface-sunken); + color: var(--basalt-text-secondary); + direction: ltr; + font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono); + white-space: pre-wrap; + overflow-wrap: break-word; + } + .basalt-diagram-text[data-art] { white-space: pre; overflow-wrap: normal; } + .basalt-diagram-drawing:has(> .basalt-diagram-text) { max-width: none; } + .basalt-diagram-text-ink { font: inherit; } + .basalt-diagram-tx-name { white-space: nowrap; color: var(--basalt-text-primary); } + .basalt-diagram-text [data-ink="focal"], .basalt-diagram-text [data-ink="op"] { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-semibold); } + .basalt-diagram-text :is([data-ink="name"], [data-ink="working"], [data-ink="plain"]) { color: var(--basalt-text-secondary); } + .basalt-diagram-text :is([data-ink="main"], [data-ink="label"]) { color: var(--basalt-text-primary); } + .basalt-diagram-text :is([data-ink="life"], [data-ink="num"], [data-ink="note"], [data-ink="frame"], [data-ink="band"]) { color: var(--basalt-text-tertiary); } + .basalt-diagram-key-glyph { font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); color: var(--basalt-text-secondary); } + .basalt-diagram-key-glyph[data-ink="main"] { color: var(--basalt-text-primary); } + @media (forced-colors: active) { .basalt-diagram-text :is([data-ink]) { color: CanvasText; } } + /* A band names a phase: drawn, a 36px row with a full-width divider rule and its words on a plate; stacked, a line of words. */ .basalt-diagram-band { --_d-bh: var(--_drawn) var(--basalt-size-control-lg); diff --git a/packages/react/test/fixtures/cimip-diagrams-b.json b/packages/react/test/fixtures/cimip-diagrams-b.json index 02efa777..1a4d5cf6 100644 --- a/packages/react/test/fixtures/cimip-diagrams-b.json +++ b/packages/react/test/fixtures/cimip-diagrams-b.json @@ -1427,5 +1427,168 @@ } ], "layout": "auto" + }, + "textSequence": { + "type": "sequence", + "title": "An agent run, as text art", + "source": "\"Runs and sandboxes\" and the agent contract", + "summary": "Marcus mentions @agent in the room. The cimip service records the run, starts and health-checks an ECS sandbox on the incident's first run, posts the run, streams the turn back to Marcus, and relays Marcus's approval until the sandbox says it is done.", + "legend": { + "main": "Request", + "plain": "Setup", + "dashed": "Stream or reply", + "focal": "The service", + "activation": "Working" + }, + "participants": [ + { + "id": "marcus", + "kind": "person", + "name": "Marcus, in the room", + "short": "Marcus" + }, + { + "id": "svc", + "kind": "ECS service", + "name": "cimip service", + "focal": true + }, + { + "id": "ecs", + "kind": "control plane", + "name": "ECS" + }, + { + "id": "agent", + "kind": "ECS task", + "name": "Agent sandbox" + } + ], + "steps": [ + { + "from": "marcus", + "to": "svc", + "kind": "main", + "label": "@agent check the proxy", + "note": "a message in the room", + "activate": true + }, + { + "from": "svc", + "to": "svc", + "label": "records the run", + "note": "run.started, one transaction" + }, + { + "frame": "opt", + "label": "First run on an incident only", + "steps": [ + { + "from": "svc", + "to": "ecs", + "label": "RunTask", + "note": "idempotency token = sandbox id" + }, + { + "frame": "loop", + "label": "Until private IP", + "steps": [ + { + "from": "svc", + "to": "ecs", + "label": "DescribeTasks", + "note": "until it has a private IP" + } + ] + }, + { + "from": "svc", + "to": "agent", + "label": "GET /healthz", + "note": "up to a minute" + } + ] + }, + { + "band": "Every run" + }, + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "POST /v1/runs", + "note": "facts, recent transcript, prompt", + "activate": true + }, + { + "from": "agent", + "to": "svc", + "kind": "dashed", + "label": "events, over SSE", + "note": "status · tool.started · finding" + }, + { + "from": "svc", + "to": "marcus", + "kind": "dashed", + "label": "the turn, as it happens", + "note": "text in 40 ms frames, not stored" + }, + { + "from": "agent", + "to": "svc", + "kind": "main", + "label": "approval.requested", + "note": "the exact command · risk: medium" + }, + { + "band": "The agent waits for a person" + }, + { + "frame": "alt", + "branches": [ + { + "label": "Approved", + "steps": [ + { + "from": "marcus", + "to": "svc", + "kind": "main", + "label": "Approve", + "note": "first decision stands" + }, + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "POST /v1/runs/{id}/input", + "note": "sent until acknowledged" + } + ] + }, + { + "label": "Rejected or timed out", + "steps": [ + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "POST /v1/runs/{id}/input", + "note": "the run stops" + } + ] + } + ] + }, + { + "from": "agent", + "to": "svc", + "kind": "dashed", + "label": "done", + "note": "outcome: completed", + "deactivate": true + } + ], + "variant": "text" } } \ No newline at end of file diff --git a/tools/html-skill/build.mjs b/tools/html-skill/build.mjs index 79bf303b..94c185b1 100644 --- a/tools/html-skill/build.mjs +++ b/tools/html-skill/build.mjs @@ -317,7 +317,7 @@ export function build() { for (const ext of ["css", "js"]) { const file = path.join(srcDir, "modules", `${name}.${ext}`); if (!fs.existsSync(file)) continue; - if (ext === "js" && (name === "diagram" || name === "diagram-motion" || name === "diagram-zoom" || name === "diagram-export")) files[`parts/${name}.js`] = minifyJs(bundleModule(file)); + if (ext === "js" && (name === "diagram" || name === "diagram-motion" || name === "diagram-zoom" || name === "diagram-export" || name === "diagram-text")) files[`parts/${name}.js`] = minifyJs(bundleModule(file)); else files[`parts/${name}.${ext}`] = ext === "css" ? minifyCss(tokens + fs.readFileSync(file, "utf8")) : minifyJs(fs.readFileSync(file, "utf8")); } } diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index d1f26ee9..d415d989 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -844,9 +844,6 @@ ] }, "diagram-export": { - "classes": [ - "diagram-download" - ], "text": [ "\"export\"\\s*:\\s*true" ], @@ -859,6 +856,19 @@ "budget": 12000, "usage": 700 }, + "diagram-text": { + "text": [ + "\"variant\"\\s*:\\s*\"text\"" + ], + "textWords": [ + "a sequence's \"variant\": \"text\"" + ], + "requires": [ + "diagram" + ], + "budget": 8000, + "usage": 700 + }, "sparkline": { "classes": [ "sparkline", diff --git a/tools/html-skill/src/modules/diagram-text.js b/tools/html-skill/src/modules/diagram-text.js new file mode 100644 index 00000000..2b199168 --- /dev/null +++ b/tools/html-skill/src/modules/diagram-text.js @@ -0,0 +1,32 @@ +/* Basalt HTML script, diagram-text module (DECISIONS 306, 1.2): a sequence whose JSON says "variant": "text" is a code block of box-drawing characters + where its widest line fits, and its transcript (written into the page by compose.mjs) where it does not. The art is React's own + (packages/react/src/diagram-text.ts), bundled here by build.mjs. Under "motion": "animated" it builds by ink once. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-text.js (do not edit the copy in the skill folder). */ +import { buildByInk, textArt } from "../../../../packages/react/src/diagram-text.ts"; + +(function (B) { + 'use strict'; + B._.diagramText = function (figure, model, spec) { + var pre = figure.querySelector('.diagram-text'); + var code = pre && pre.querySelector('.diagram-text-ink'); + if (!code) return; + if (!figure.__transcript) figure.__transcript = code.innerHTML; + var made = textArt(model); + var probe = document.createElement('span'); + probe.textContent = new Array(41).join('─'); + pre.appendChild(probe); + var cw = probe.getBoundingClientRect().width / 40; + probe.remove(); + var cs = getComputedStyle(pre); + var room = pre.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight); + var art = made.width * cw <= room + 0.5; + var html = art ? made.html : figure.__transcript; + if (code.innerHTML !== html) code.innerHTML = html; + pre.toggleAttribute('data-art', art); + if (art && spec.motion === 'animated' && !figure.__inked) { + figure.__inked = true; + var ms = function (n, f) { return parseFloat(cs.getPropertyValue('--basalt-' + n)) || f; }; + buildByInk(code, model.steps.filter(function (st) { return 'n' in st; }).length, { slower: ms('duration-slower', 300), step: ms('duration-diagram-step', 320), limit: ms('duration-diagram-limit', 5000) }); + } + }; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 7159dce3..68fc030b 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -157,6 +157,8 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, // In the frame an animated figure's lines are first drawn it is pending; after that the motion module follows a drawing that changed. if (animated && measured.tokens) { entranceDrawn(figure, Boolean(measured.geo && measured.geo.lines.length)); if (fresh && motion) motion.redrawn(); } if (viewer && viewer.onMeasured && measured.tokens) viewer.onMeasured(measured, figure); + // The text variant (DECISIONS 306, 1.2): the art where its widest line fits the block (the diagram-text module's), the transcript otherwise. + if (model.text && typeof _.diagramText === 'function') _.diagramText(figure, model, spec); } function setState(next) { state = next; apply(state); } // A move of the roving stop touches the two nodes it moves between, not the whole figure. diff --git a/tools/html-skill/src/usage/diagram-text.md b/tools/html-skill/src/usage/diagram-text.md new file mode 100644 index 00000000..fdc9beb4 --- /dev/null +++ b/tools/html-skill/src/usage/diagram-text.md @@ -0,0 +1,6 @@ +# diagram-text + +Added for you when a sequence's JSON says `"variant": "text"`. + +- The same data as box-drawing characters in a code block, where its widest line fits; elsewhere the transcript (one line a message), which the page holds before script. Nothing scrolls sideways, and the block is hidden from assistive technology: the title, the summary and "View as list" carry it. +- With `"motion": "animated"` it builds by ink: labels and arrows lift in message order, no line hidden, no caret. From 2d0cd9fdf2a40566f63afef459cd9881dfae2cda Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:13:34 -0600 Subject: [PATCH 23/62] Record the five diagrams' sizes after batch B (DECISIONS 318: the owner approved the raise) Each still diagram is about 87.1 KB against 67.5 KB recorded (+28.9%), the whole package up front +2.3% and styles.css +6.3%. The PR gives the growth part by part. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- packages/react/test/export-sizes.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/react/test/export-sizes.json b/packages/react/test/export-sizes.json index 3e1a4eee..13765c50 100644 --- a/packages/react/test/export-sizes.json +++ b/packages/react/test/export-sizes.json @@ -18,7 +18,7 @@ "AppHeader": 1285, "AppShell": 103887, "AppTile": 1112, - "ArchitectureDiagram": 67580, + "ArchitectureDiagram": 87133, "ArrowDownGlyph": 2868, "ArrowLeftGlyph": 2869, "ArrowRightGlyph": 2859, @@ -70,7 +70,7 @@ "CopyGlyph": 2884, "Countdown": 3016, "CoverageStrip": 1570, - "DataFlowDiagram": 67597, + "DataFlowDiagram": 87080, "DateAge": 2527, "DescriptionColumns": 216, "DescriptionItem": 593, @@ -105,7 +105,7 @@ "Fieldset": 6390, "FilterResult": 698, "FilterToolbar": 774, - "FlowchartDiagram": 67546, + "FlowchartDiagram": 87101, "Form": 8730, "FormGrid": 438, "FormGridItem": 628, @@ -224,7 +224,7 @@ "RunsGlyph": 3128, "STATUS_MESSAGE_MS": 26, "SandboxesGlyph": 2963, - "SchemaDiagram": 67494, + "SchemaDiagram": 87049, "SearchDialog": 88277, "SearchField": 18301, "SearchGlyph": 3181, @@ -243,7 +243,7 @@ "SelectableList": 821, "SelectionBar": 25913, "Separator": 4531, - "SequenceDiagram": 67542, + "SequenceDiagram": 87077, "SettingsGlyph": 3100, "ShareBar": 1411, "Sheet": 70793, @@ -323,7 +323,7 @@ "TabsPanels": 385, "Terminal": 32267, "Text": 922, - "TextButton": 10421, + "TextButton": 10420, "TextMorph": 4504, "Textarea": 26941, "ThemeChoiceControl": 4794, @@ -412,11 +412,11 @@ "useWaitMark": 303 }, "package": { - "bytes": 870189, - "gzip": 288896 + "bytes": 890053, + "gzip": 296141 }, "styles": { - "bytes": 382510, - "gzip": 49971 + "bytes": 406744, + "gzip": 52867 } } From c880624b75060ce255757fb68252b4bf36ffb380 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:13:57 -0600 Subject: [PATCH 24/62] The skill's caps after batch B (DECISIONS 318: the owner approved the raise) diagram 92,650 -> 123,200 bytes (the engine's new parts, in the skill's development build, and their stylesheet), diagram-motion 26,850 -> 27,500, SKILL.md's index 12,650 -> 12,950 (three new module lines); caps recorded for the new modules at their measured sizes: diagram-zoom 16,900, diagram-export 7,450, diagram-text 5,450. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- .agent/skills/basalt-html/parts/manifest.json | 12 ++++++------ tools/html-skill/src/modules.json | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index d415d989..e37ab081 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -1,7 +1,7 @@ { "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a <!-- basalt:use name --> comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused).", "budgets": { - "skillMd": 12650, + "skillMd": 12950, "core": 35400 }, "core": { @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 92650, + "budget": 123200, "usage": 4300, "builds": [ "kbd" @@ -804,7 +804,7 @@ "loops", "toggle" ], - "budget": 26850, + "budget": 27500, "usage": 1300, "builds": [ "loops", @@ -835,7 +835,7 @@ "dialog-form", "sheet" ], - "budget": 12000, + "budget": 16900, "usage": 900, "builds": [ "dialog", @@ -853,7 +853,7 @@ "requires": [ "diagram" ], - "budget": 12000, + "budget": 7450, "usage": 700 }, "diagram-text": { @@ -866,7 +866,7 @@ "requires": [ "diagram" ], - "budget": 8000, + "budget": 5450, "usage": 700 }, "sparkline": { diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index d415d989..e37ab081 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -1,7 +1,7 @@ { "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a <!-- basalt:use name --> comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused).", "budgets": { - "skillMd": 12650, + "skillMd": 12950, "core": 35400 }, "core": { @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 92650, + "budget": 123200, "usage": 4300, "builds": [ "kbd" @@ -804,7 +804,7 @@ "loops", "toggle" ], - "budget": 26850, + "budget": 27500, "usage": 1300, "builds": [ "loops", @@ -835,7 +835,7 @@ "dialog-form", "sheet" ], - "budget": 12000, + "budget": 16900, "usage": 900, "builds": [ "dialog", @@ -853,7 +853,7 @@ "requires": [ "diagram" ], - "budget": 12000, + "budget": 7450, "usage": 700 }, "diagram-text": { @@ -866,7 +866,7 @@ "requires": [ "diagram" ], - "budget": 8000, + "budget": 5450, "usage": 700 }, "sparkline": { From 0bdf9bd684832e13b265de260663c5ba1af28344 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:14:50 -0600 Subject: [PATCH 25/62] elkjs in the package's third-party notices (DECISIONS 306, 1.8) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- packages/react/THIRD-PARTY-NOTICES.md | 11 +++++++++++ packages/react/package.json | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 packages/react/THIRD-PARTY-NOTICES.md diff --git a/packages/react/THIRD-PARTY-NOTICES.md b/packages/react/THIRD-PARTY-NOTICES.md new file mode 100644 index 00000000..48f5f5df --- /dev/null +++ b/packages/react/THIRD-PARTY-NOTICES.md @@ -0,0 +1,11 @@ +# Third-party code + +## elkjs + +`@srasyndicate/basalt/diagram-layout` (automatic diagram layout, DECISIONS 306, 1.8) imports [elkjs](https://github.com/kieler/elkjs) 0.12.1, +the Eclipse Layout Kernel compiled to JavaScript, unmodified. elkjs is a dependency of this package and is not copied into it. + +- Licence: EPL-2.0 OR GPL-3.0-or-later. Basalt uses it under the Eclipse Public License 2.0 (https://www.eclipse.org/legal/epl-2.0/). +- Source: https://github.com/kieler/elkjs (the Eclipse Layout Kernel's own source: https://github.com/eclipse/elk). +- It is loaded only when an automatic figure has no `placement`. An app or page that places at build time with `placeDiagram` and passes `placement` + ships none of it. An app whose browser bundle holds elkjs distributes it, and owes its notice and a pointer to its source. diff --git a/packages/react/package.json b/packages/react/package.json index 8e678ed1..0f240054 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -45,7 +45,8 @@ }, "files": [ "dist", - "THIRD-PARTY-MARKS.md" + "THIRD-PARTY-MARKS.md", + "THIRD-PARTY-NOTICES.md" ], "scripts": { "build": "node build.mjs", From cf2fcd625f9e130a0f04f8c0abcc46a9f728480c Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:15:18 -0600 Subject: [PATCH 26/62] Round 66: automatic layout, text art, right to left and export Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- tools/review/round66.tsx | 85 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 5 deletions(-) diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx index 1d80e643..a69b0dc3 100644 --- a/tools/review/round66.tsx +++ b/tools/review/round66.tsx @@ -1,15 +1,15 @@ // Round 66: Basalt's diagrams, batch B (DECISIONS 301; the decision is 306, revised by 313, with part 9, the viewer, as 310). A heavy council round: two // drafts and one check, decided by Fable, revised after the final positions. Part 9 (the viewer) is the owner's own addition and skipped three steps: no // draft, no check and no seat's position; every value in it is the decider's alone. Built by Opus from the decision; the implementation has not been -// reviewed. The content is CIMIP's figures extended as each part needs (test/fixtures/cimip-diagrams-b.json). Only the parts built so far are shown: -// cardinality and far keys, the text art, the touch trace, the first visit, dashed flow, marks on steps and participants, right to left, export and -// automatic layout are not built yet, so this round has no automatically placed figure. +// reviewed. The content is CIMIP's figures extended as each part needs (test/fixtures/cimip-diagrams-b.json), with automatic and text-art versions. +// Cardinality, far keys and section 4's calls 2 and 3 are not built. import * as React from "react"; import { ArchitectureDiagram, DataFlowDiagram, FlowchartDiagram, SchemaDiagram, SequenceDiagram } from "../../packages/react/src/index"; import data from "../../packages/react/test/fixtures/cimip-diagrams-b.json"; import type { Round } from "./rounds"; +import { diagramToSvg } from "../../packages/react/src/diagram-export"; import { awsEcsService } from "../../packages/react/src/marks/aws-ecs-service"; import { awsEcsTask } from "../../packages/react/src/marks/aws-ecs-task"; @@ -20,6 +20,31 @@ type Key = keyof typeof data; const isShot = () => new URLSearchParams(window.location.search).get("shot") === "1"; const frames = (n: number) => new Promise<void>((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }); +/** A figure exported to SVG (diagram-export) and shown as the file, beside nothing else: what an app's own Download button would write. */ +function Exported({ k, theme }: { k: Key; theme: "light" | "dark" }) { + const host = React.useRef<HTMLDivElement>(null); + const [url, setUrl] = React.useState<string | null>(null); + React.useEffect(() => { + let ready: () => void = () => {}; + if (isShot()) (window as unknown as { __BASALT_READY__?: Promise<void> }).__BASALT_READY__ = new Promise<void>((resolve) => { ready = resolve; }); + (async () => { + await frames(8); + const fig = host.current?.querySelector<HTMLElement>("figure"); + if (!fig) return; + const blob = await diagramToSvg(fig, { theme }); + setUrl(URL.createObjectURL(blob)); + await frames(4); + ready(); + })(); + }, [theme]); + return ( + <div style={{ display: "grid", gap: 24 }}> + <div ref={host} style={{ position: "absolute", left: -10000, width: 1104 }}><Diagram k={k} state="" /></div> + {url ? <img src={url} alt="" style={{ maxWidth: "100%", border: "1px dashed var(--basalt-border-divider)" }} /> : null} + </div> + ); +} + /** A figure from the extended fixture. A "viewer" state opens its viewer (and "viewer-200" zooms to 200%) once it is drawn, for the shot. */ function Diagram({ k, state }: { k: Key; state: string }) { const host = React.useRef<HTMLDivElement>(null); @@ -62,8 +87,8 @@ const W = [1440, 390]; export const ROUND_66: Round = { id: "66", - title: "Diagrams, batch B: the viewer, frames and activations, nested groups, link cards, two-line labels and spatial keys (DECISIONS 306 and 310)", - summary: "The first half of batch B. The viewer (part 9, the owner's addition) opens any figure's drawn layout in a dialog to zoom and pan; the sequence gains activation bars and opt, loop and alt frames; groups nest two deep; a card may be a link; an edge label may hold its author's break; the arrow keys move by the cards' columns and rows. Not built yet: cardinality and far keys, the text art, the touch trace, the first visit, dashed flow, marks on steps and participants, right to left, export and automatic layout (elkjs).", + title: "Diagrams, batch B: the viewer, frames and activations, nested groups, link cards, two-line labels, spatial keys, text art, automatic layout, right to left and export (DECISIONS 306 and 310)", + summary: "The first half of batch B. The viewer (part 9, the owner's addition) opens any figure's drawn layout in a dialog to zoom and pan; the sequence gains activation bars and opt, loop and alt frames; groups nest two deep; a card may be a link; an edge label may hold its author's break; the arrow keys move by the cards' columns and rows. Also: a trace on touch, an entrance on a first visit, flow on a dashed line, marks on steps and participants, and print. Not built: cardinality and far keys, and section 4's calls 2 and 3.", reviewed: false, steps: [ { @@ -121,6 +146,56 @@ export const ROUND_66: Round = { touch: true, demo: ({ state }) => <Diagram k="schema" state={state} />, }, + { + id: "auto", + name: "Automatic layout: elkjs places, Basalt draws", + intro: "The CIMIP schema and architecture with layout=\"auto\" and no col or row: elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one.", + decisions: [ + "elkjs (EPL-2.0 OR GPL-3.0-or-later, used under EPL-2.0) loads on demand here; an app that places at build time and passes placement ships none of it, and the HTML skill always places at build time.", + "The schema draws laid down (3 columns by 5 rows) through Basalt's router. The architecture places as the proof's 6 by 3 and 3 by 6, but stacks at 1104: the turn-back that carries \"HTTP + SSE\" finds no seat. The decision's proof routed on cells only; this is the first drawing of one, for the decider.", + ], + tryIt: ["Narrow the window: under 640 nothing is loaded and the figure is stacked."], + widths: W, + scales: [2], + height: 1800, + touch: true, + demo: ({ state }) => <><Diagram k="autoSchema" state={state} /><Diagram k="autoArchitecture" state={state} /></>, + }, + { + id: "text", + name: "A sequence as text art", + intro: "variant=\"text\": the same data as box-drawing characters, where its widest line fits; on a phone the transcript.", + decisions: [...COMMON, "No line-by-line reveal and no caret (item 1 for the owner): under motion=\"animated\" it builds by ink, as the drawn sequence does."], + tryIt: ["Select the art and copy it: the clipboard holds the art exactly."], + widths: W, + scales: [2], + height: 2000, + touch: true, + demo: ({ state }) => <Diagram k="textSequence" state={state} />, + }, + { + id: "rtl", + name: "Right to left", + intro: "The architecture and the sequence in a right-to-left page: the figure mirrors, its words do not.", + decisions: ["Column 1 is at the right and the first participant at the right; named sides swap; the arrow keys stay physical. The stack is not mirrored (its rail is laid out on the left): drawn, with every line."], + tryIt: ["Tab into the architecture and press the arrows: they move where they point."], + widths: W, + scales: [2], + height: 2600, + touch: true, + demo: ({ state }) => <div dir="rtl"><Diagram k="architecture" state={state} /><Diagram k="sequence" state={state} /></div>, + }, + { + id: "export", + name: "Export: the file an app's Download button writes", + intro: "diagramToSvg on the extended architecture, shown as the SVG file it wrote: native SVG, words as text, the faces embedded, at rest.", + decisions: ["@srasyndicate/basalt/diagram-export is a module the app loads on demand and wires to its own button; a figure grows no control. The HTML skill's \"export\": true adds the two buttons."], + tryIt: ["Open the image in a new tab: it is an SVG whose words select as text."], + widths: [1440], + scales: [2], + height: 1100, + demo: () => <Exported k="architecture" theme={(document.documentElement.getAttribute("data-theme") as "light" | "dark") ?? "dark"} />, + }, { id: "print", name: "Print: light and untraced", From 26dd3a7c678457059c11c7005e1edae56b0a866f Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:32:42 -0600 Subject: [PATCH 27/62] Fixes from the full run: elkjs out of the shared chunk, the viewer's loop, the skill's placer elkjs's file, verbatim and unmodified, is wrapped as an ES module of its own (dist/diagram-elk.js, with its notice): bundled as CommonJS by an app, it had put the bundler's CommonJS helpers in the chunk every component's bundle shares (Button 17,991 against 17,650). An automatic figure's placements are memoised, so the viewer's figure no longer re-measures without end. The else rule's dashes are an SVG mask, not a gradient. compose.mjs places an automatic diagram in a worker it waits for (node:worker_threads), not a child process. Tests follow what the decision changed: the dashed-flow check is gone, the motion test's "no mark" reads a mark's rule, and compose's imports name the worker. The diagram module's cap is 123,300 (measured 123,248). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- .agent/skills/basalt-html/compose.mjs | 20 +++++- .../basalt-html/parts/diagram-place.mjs | 64 ++++++++++++++----- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/manifest.json | 2 +- packages/react/build.mjs | 21 +++++- packages/react/src/diagram-elk.ts | 5 ++ packages/react/src/diagram-figure.tsx | 2 +- packages/react/src/diagram-layout.ts | 2 +- packages/react/src/styles/components.css | 2 +- packages/react/test/diagram-fixes.test.mjs | 2 +- tools/html-skill/src/compose.mjs | 20 +++++- tools/html-skill/src/diagram-place.mjs | 23 ++++--- tools/html-skill/src/modules.json | 2 +- tools/html-skill/test/compose.test.mjs | 5 +- tools/html-skill/test/diagram-motion.test.mjs | 3 +- 15 files changed, 133 insertions(+), 42 deletions(-) create mode 100644 packages/react/src/diagram-elk.ts diff --git a/.agent/skills/basalt-html/compose.mjs b/.agent/skills/basalt-html/compose.mjs index 92bf80a3..2c05398b 100644 --- a/.agent/skills/basalt-html/compose.mjs +++ b/.agent/skills/basalt-html/compose.mjs @@ -29,11 +29,11 @@ // file; PREFIX (aws, azure, gcp) keeps the ids that start with it. It reads parts/marks.json only, so the diagram usage need not list them. // // Source: tools/html-skill/src/compose.mjs (do not edit the copy in the skill folder). -import { execFileSync } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import vm from "node:vm"; +import { MessageChannel, receiveMessageOnPort, Worker } from "node:worker_threads"; const here = path.dirname(fileURLToPath(import.meta.url)); @@ -609,6 +609,22 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts = return { html, modules: chosen.modules, icons: chosen.icons, glyphs: chosen.glyphs, built, external: externalReferences(held, markup), diagrams: diagramNotes, bytes: Buffer.byteLength(html) }; } +/** + * An automatic diagram's placement for both directions (DECISIONS 306, 1.8), from parts/diagram-place.mjs run in a worker, waited for here: elk answers with + * a promise and compose is synchronous, so this thread sleeps on a shared flag until the worker has posted its answer and woken it. + */ +function placeNow(parts, spec) { + const signal = new SharedArrayBuffer(4); + const { port1, port2 } = new MessageChannel(); + const worker = new Worker(path.join(parts, "diagram-place.mjs"), { workerData: { spec, port: port2, signal }, transferList: [port2] }); + Atomics.wait(new Int32Array(signal), 0, 0, 60_000); + const got = receiveMessageOnPort(port1)?.message; + worker.terminate(); + port1.close(); + if (!got || got.error) throw new Error(got?.error ?? "the placer did not answer"); + return got.placement; +} + /** Whether any figure on the page keeps its viewer: a `data-diagram` JSON without `"zoom": false`, or a figure drawn from script. */ function zoomWanted(held, code) { if (/Basalt\s*\.\s*diagram\b/.test(code)) return true; @@ -651,7 +667,7 @@ function writeDiagrams(markup, held, parts, notes, marks) { // An automatic figure (DECISIONS 306, 1.8) is placed here, at build time, for both directions; the page holds the placement and never elkjs. if (spec && spec.layout === "auto" && !spec.placement && ["architecture", "flowchart", "schema"].includes(spec.type)) { try { - spec.placement = JSON.parse(execFileSync(process.execPath, [path.join(parts, "diagram-place.mjs")], { input: JSON.stringify(spec), encoding: "utf8" })); + spec.placement = placeNow(parts, spec); const inner = `\n${JSON.stringify(spec).replace(/</g, "\\u003c")}\n`; item.text = item.text.replace(item.inner, () => inner); item.inner = inner; diff --git a/.agent/skills/basalt-html/parts/diagram-place.mjs b/.agent/skills/basalt-html/parts/diagram-place.mjs index 5b5a34f4..e19ffbd9 100644 --- a/.agent/skills/basalt-html/parts/diagram-place.mjs +++ b/.agent/skills/basalt-html/parts/diagram-place.mjs @@ -1,3 +1,35 @@ +var __defProp = Object.defineProperty; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __esm = (fn, res, err) => function __init() { + if (err) throw err[0]; + try { + return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; + } catch (e) { + throw err = [e], e; + } +}; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; + +// packages/react/src/diagram-elk.ts +var diagram_elk_exports = {}; +__export(diagram_elk_exports, { + default: () => diagram_elk_default +}); +import ELK from "elkjs/lib/elk.bundled.js"; +var diagram_elk_default; +var init_diagram_elk = __esm({ + "packages/react/src/diagram-elk.ts"() { + "use strict"; + diagram_elk_default = ELK; + } +}); + +// tools/html-skill/src/diagram-place.mjs +import { workerData } from "node:worker_threads"; + // packages/react/src/diagram-layout.ts var W = 200; var H = 80; @@ -13,10 +45,10 @@ var options = (direction) => ({ "elk.spacing.nodeNode": "48", "elk.edgeRouting": "ORTHOGONAL" }); -function elkGraph(input2, direction) { - const cards = input2.type === "schema" ? (input2.tables ?? []).map((t) => ({ id: String(t.name), group: void 0 })) : (input2.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); - const edges = input2.type === "schema" ? (input2.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0] }))) : (input2.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to) })); - const groups = input2.type === "architecture" ? input2.groups ?? [] : []; +function elkGraph(input, direction) { + const cards = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name), group: void 0 })) : (input.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); + const edges = input.type === "schema" ? (input.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0] }))) : (input.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to) })); + const groups = input.type === "architecture" ? input.groups ?? [] : []; const kids = /* @__PURE__ */ new Map([["", []]]); for (const g of groups) kids.set(g.id, []); for (const c of cards) (kids.get(c.group ?? "") ?? kids.get("")).push({ id: c.id, width: W, height: H }); @@ -52,12 +84,12 @@ function bands(rects, lo, hi) { return out; } var elkMade; -async function placeDiagram(input2, direction) { +async function placeDiagram(input, direction) { if (!elkMade) { - const mod = await import("elkjs/lib/elk.bundled.js"); + const mod = await Promise.resolve().then(() => (init_diagram_elk(), diagram_elk_exports)); elkMade = new mod.default(); } - const laid = await elkMade.layout(elkGraph(input2, direction)); + const laid = await elkMade.layout(elkGraph(input, direction)); const rects = absolute(laid); const col = bands(rects, (r) => r.x, (r) => r.x + r.w), row = bands(rects, (r) => r.y, (r) => r.y + r.h); const cells = {}; @@ -66,15 +98,15 @@ async function placeDiagram(input2, direction) { } // tools/html-skill/src/diagram-place.mjs -var input = ""; -process.stdin.setEncoding("utf8"); -process.stdin.on("data", (c) => { - input += c; -}); -process.stdin.on("end", async () => { - const spec = JSON.parse(input); +var { spec, port, signal } = workerData; +var flag = new Int32Array(signal); +try { const directions = spec.direction ? [spec.direction] : spec.type === "flowchart" ? ["down", "right"] : ["right", "down"]; const out = []; for (const d of directions) out.push(await placeDiagram(spec, d)); - process.stdout.write(JSON.stringify(out)); -}); + port.postMessage({ placement: out }); +} catch (e) { + port.postMessage({ error: String(e && e.message ? e.message : e) }); +} +Atomics.store(flag, 0, 1); +Atomics.notify(flag, 0); diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index 18886f6f..a3ee3c4c 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:linear-gradient(to right,currentColor 50%,transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}} diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index e37ab081..56e01f2b 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 123200, + "budget": 123300, "usage": 4300, "builds": [ "kbd" diff --git a/packages/react/build.mjs b/packages/react/build.mjs index fc25e0e8..684324a3 100644 --- a/packages/react/build.mjs +++ b/packages/react/build.mjs @@ -95,6 +95,21 @@ await esbuild.build({ banner: { js: `"use client";` }, }); +// elkjs as an ES module of its own (DECISIONS 306, 1.8): elkjs's own file, verbatim and unmodified, inside a wrapper that gives it a module and no global +// require, written to dist/diagram-elk.js with its notice. Imported only by diagram-layout, on demand: bundled as CommonJS by an app, elkjs put the +// bundler's CommonJS helpers in the chunk every component's bundle shares. +fs.mkdirSync(dist, { recursive: true }); +{ + const elk = fs.readFileSync(path.join(packageDir("elkjs"), "lib", "elk.bundled.js"), "utf8"); + fs.writeFileSync(path.join(dist, "diagram-elk.js"), `/*! elkjs 0.12.1 (https://github.com/kieler/elkjs), the Eclipse Layout Kernel: EPL-2.0 OR GPL-3.0-or-later, used under EPL-2.0, unmodified. */ +const elkModule = { exports: {} }; +(function (module, exports, require, define) { +${elk} +}).call(globalThis, elkModule, elkModule.exports, undefined, undefined); +export default elkModule.exports; +`); +} + // The diagram viewer is the fourth (DECISIONS 310, 9.13): "Expand" loads it at its first hover, focus or touch, and it brings Dialog, the sheet's parts and the // buttons with it, inlined for the same reason as the motion's. It imports the figure and the engine only as types: the figure hands them over when it opens // the viewer (ViewerKit), so this chunk never holds a second copy of the engine. @@ -152,7 +167,7 @@ await esbuild.build({ // The core glyphs are modules of their own (src/glyphs), so an app that imports HomeGlyph bundles only HomeGlyph. entryPoints: [ // index.ts is not bundled: it is a barrel of `export { … } from "./module"` and is written as one, below, so each export comes from the module that holds it. - ...fs.readdirSync(path.join(here, "src")).filter((f) => /\.tsx?$/.test(f) && !f.endsWith(".d.ts") && !["command-panel.tsx", "glyph-flight.tsx", "diagram-motion.tsx", "diagram-motion-core.ts", "diagram-viewer.tsx", "diagram-zoom-core.ts", "index.ts"].includes(f)).map((f) => path.join(here, "src", f)), + ...fs.readdirSync(path.join(here, "src")).filter((f) => /\.tsx?$/.test(f) && !f.endsWith(".d.ts") && !["command-panel.tsx", "glyph-flight.tsx", "diagram-motion.tsx", "diagram-motion-core.ts", "diagram-viewer.tsx", "diagram-zoom-core.ts", "diagram-elk.ts", "index.ts"].includes(f)).map((f) => path.join(here, "src", f)), ...fs.readdirSync(path.join(here, "src", "glyphs")).filter((f) => /\.ts$/.test(f)).map((f) => path.join(here, "src", "glyphs", f)), // The service marks (DECISIONS 292, 2.6): one module a mark under dist/marks, at @srasyndicate/basalt/marks/<id>, never imported by the index, so an // app pays for the marks it imports and no others. Generated by marks/generate.mjs. @@ -163,7 +178,7 @@ await esbuild.build({ ...fs.readdirSync(path.join(here, "src", "tooling")).filter((f) => /\.ts$/.test(f)).map((f) => path.join(here, "src", "tooling", f)), ], define: { __PHOSPHOR_NOTICE__: JSON.stringify(phosphorNotice), __BASALT_ROOT_MAP__: JSON.stringify(JSON.stringify(rootMap)) }, - plugins: [{ name: "lazy-modules", setup(build) { build.onResolve({ filter: /^\.\/(command-panel|glyph-flight|diagram-motion|diagram-viewer|diagram-layout|diagram-text)$/ }, (args) => (args.kind === "dynamic-import" ? { path: `${args.path}.js`, external: true } : undefined)); } }], + plugins: [{ name: "lazy-modules", setup(build) { build.onResolve({ filter: /^\.\/(command-panel|glyph-flight|diagram-motion|diagram-viewer|diagram-layout|diagram-text|diagram-elk)$/ }, (args) => (args.kind === "dynamic-import" ? { path: `${args.path}.js`, external: true } : undefined)); } }], outdir: dist, bundle: true, splitting: true, @@ -216,7 +231,7 @@ const needsClient = (file, seen = new Set()) => { seen.add(file); return staticImports(fs.readFileSync(path.join(dist, file), "utf8")).some((specifier) => clientImport.test(specifier) || (/^\.\/chunk-/.test(specifier) && needsClient(specifier.slice(2), seen))); }; -for (const file of fs.readdirSync(dist, { recursive: true }).filter((f) => f.endsWith(".js") && !path.basename(f).startsWith("chunk-") && !["command-panel.js", "glyph-flight.js", "diagram-motion.js", "diagram-viewer.js"].includes(f))) { +for (const file of fs.readdirSync(dist, { recursive: true }).filter((f) => f.endsWith(".js") && !path.basename(f).startsWith("chunk-") && !["command-panel.js", "glyph-flight.js", "diagram-motion.js", "diagram-viewer.js", "diagram-elk.js"].includes(f))) { const code = fs.readFileSync(path.join(dist, file), "utf8"); if (needsClient(file)) fs.writeFileSync(path.join(dist, file), `"use client";\n${code}`); } diff --git a/packages/react/src/diagram-elk.ts b/packages/react/src/diagram-elk.ts new file mode 100644 index 00000000..fbcc63a7 --- /dev/null +++ b/packages/react/src/diagram-elk.ts @@ -0,0 +1,5 @@ +// elkjs (EPL-2.0 OR GPL-3.0-or-later, used under EPL-2.0, unmodified), as an ES module of its own: build.mjs bundles elkjs's own file into +// dist/diagram-elk.js, so its CommonJS wrapper lives in this one file and never in an app's shared chunk. Only diagram-layout imports it, on demand. +import ELK from "elkjs/lib/elk.bundled.js"; + +export default ELK; diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 9418f9df..1f9ebeab 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -135,7 +135,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const auto = spec.layout === "auto" && (spec.type === "architecture" || spec.type === "flowchart" || spec.type === "schema"); const given = React.useMemo(() => (spec.placement ? (Array.isArray(spec.placement) ? spec.placement : [spec.placement]) : []), [spec.placement]); const [loaded, setLoaded] = React.useState<DiagramPlacement[] | null>(null); - const placements = given.length ? given : loaded ?? []; + const placements = React.useMemo(() => (given.length ? given : loaded ?? []), [given, loaded]); const order = React.useMemo<Array<"right" | "down">>(() => (spec.direction ? [spec.direction] : spec.type === "flowchart" ? ["down", "right"] : ["right", "down"]), [spec.direction, spec.type]); const [dirAt, setDirAt] = React.useState(0); const placementFor = React.useCallback((k: number) => placements.find((p) => p.direction === order[k]), [placements, order]); diff --git a/packages/react/src/diagram-layout.ts b/packages/react/src/diagram-layout.ts index ac499366..61467163 100644 --- a/packages/react/src/diagram-layout.ts +++ b/packages/react/src/diagram-layout.ts @@ -78,7 +78,7 @@ let elkMade: { layout: (graph: ElkNode) => Promise<ElkNode> } | undefined; /** Places a figure in one direction: each card's column and row. The same answer in Node and in a browser. */ export async function placeDiagram(input: DiagramPlacementInput, direction: "right" | "down"): Promise<DiagramPlacement> { if (!elkMade) { - const mod = (await import("elkjs/lib/elk.bundled.js")) as unknown as { default: new () => { layout: (graph: ElkNode) => Promise<ElkNode> } }; + const mod = (await import("./diagram-elk")) as unknown as { default: new () => { layout: (graph: ElkNode) => Promise<ElkNode> } }; elkMade = new mod.default(); } const laid = await elkMade.layout(elkGraph(input, direction)); diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 3a4a9a55..0d9079af 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4792,7 +4792,7 @@ .basalt-diagram-ftab { padding: var(--basalt-space-1) var(--basalt-space-3); border-inline-end: var(--basalt-size-hairline) solid var(--basalt-diagram-structure); border-block-end: var(--basalt-size-hairline) solid var(--basalt-diagram-structure); border-end-end-radius: var(--basalt-radius-xs); background: var(--_ground); color: var(--basalt-text-primary); font: var(--basalt-font-weight-semibold) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); } .basalt-diagram-flabel { margin-block-start: var(--basalt-space-1); margin-inline-start: calc(-1 * var(--basalt-space-1-5)); padding-inline: var(--basalt-space-1-5); background: var(--_ground); color: var(--basalt-text-secondary); font: var(--basalt-font-weight-medium) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); } .basalt-diagram-felse { position: relative; display: flex; align-items: center; gap: var(--basalt-space-1-5); height: var(--basalt-size-control-sm); margin: 0; padding-inline-start: calc(var(--_fl) + var(--basalt-space-3)); white-space: nowrap; } - .basalt-diagram-felse::before { content: ""; position: absolute; top: 0; inset-inline-start: var(--_fl); width: var(--_fw); height: var(--basalt-size-hairline); background: var(--basalt-diagram-structure); mask: linear-gradient(to right, currentColor 50%, transparent 50%) 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x; } + .basalt-diagram-felse::before { content: ""; position: absolute; top: 0; inset-inline-start: var(--_fl); width: var(--_fw); height: var(--basalt-size-hairline); background: var(--basalt-diagram-structure); mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x; } .basalt-diagram-felse .basalt-diagram-flabel { margin-block-start: 0; margin-inline-start: 0; } .basalt-diagram-fword { margin-inline-start: calc(-1 * var(--basalt-space-1-5)); padding-inline: var(--basalt-space-1-5); background: var(--_ground); color: var(--basalt-text-tertiary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); } .basalt-diagram-fword + .basalt-diagram-flabel { margin-inline-start: calc(-1 * var(--basalt-space-1-5)); } diff --git a/packages/react/test/diagram-fixes.test.mjs b/packages/react/test/diagram-fixes.test.mjs index 88a364bd..93acec99 100644 --- a/packages/react/test/diagram-fixes.test.mjs +++ b/packages/react/test/diagram-fixes.test.mjs @@ -119,7 +119,7 @@ describe("the development checks cost production nothing (Neon's finding 14)", ( test("the motion module's production build holds none of its checks' words", async () => { const entry = `import { motionErrors } from "./dist/diagram-motion.js"; console.log(motionErrors);`; const [prod, dev] = [await bundle(entry, "production"), await bundle(entry, "development")]; - for (const w of ["names both a pulse and a packet", "flows but has no label", "is dashed and flows", "no line joins them in that direction"]) { + for (const w of ["names both a pulse and a packet", "flows but has no label", "no line joins them in that direction"]) { assert.ok(!prod.includes(w), `production holds "${w}"`); assert.ok(dev.includes(w), `development lacks "${w}"`); } diff --git a/tools/html-skill/src/compose.mjs b/tools/html-skill/src/compose.mjs index 92bf80a3..2c05398b 100644 --- a/tools/html-skill/src/compose.mjs +++ b/tools/html-skill/src/compose.mjs @@ -29,11 +29,11 @@ // file; PREFIX (aws, azure, gcp) keeps the ids that start with it. It reads parts/marks.json only, so the diagram usage need not list them. // // Source: tools/html-skill/src/compose.mjs (do not edit the copy in the skill folder). -import { execFileSync } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import vm from "node:vm"; +import { MessageChannel, receiveMessageOnPort, Worker } from "node:worker_threads"; const here = path.dirname(fileURLToPath(import.meta.url)); @@ -609,6 +609,22 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts = return { html, modules: chosen.modules, icons: chosen.icons, glyphs: chosen.glyphs, built, external: externalReferences(held, markup), diagrams: diagramNotes, bytes: Buffer.byteLength(html) }; } +/** + * An automatic diagram's placement for both directions (DECISIONS 306, 1.8), from parts/diagram-place.mjs run in a worker, waited for here: elk answers with + * a promise and compose is synchronous, so this thread sleeps on a shared flag until the worker has posted its answer and woken it. + */ +function placeNow(parts, spec) { + const signal = new SharedArrayBuffer(4); + const { port1, port2 } = new MessageChannel(); + const worker = new Worker(path.join(parts, "diagram-place.mjs"), { workerData: { spec, port: port2, signal }, transferList: [port2] }); + Atomics.wait(new Int32Array(signal), 0, 0, 60_000); + const got = receiveMessageOnPort(port1)?.message; + worker.terminate(); + port1.close(); + if (!got || got.error) throw new Error(got?.error ?? "the placer did not answer"); + return got.placement; +} + /** Whether any figure on the page keeps its viewer: a `data-diagram` JSON without `"zoom": false`, or a figure drawn from script. */ function zoomWanted(held, code) { if (/Basalt\s*\.\s*diagram\b/.test(code)) return true; @@ -651,7 +667,7 @@ function writeDiagrams(markup, held, parts, notes, marks) { // An automatic figure (DECISIONS 306, 1.8) is placed here, at build time, for both directions; the page holds the placement and never elkjs. if (spec && spec.layout === "auto" && !spec.placement && ["architecture", "flowchart", "schema"].includes(spec.type)) { try { - spec.placement = JSON.parse(execFileSync(process.execPath, [path.join(parts, "diagram-place.mjs")], { input: JSON.stringify(spec), encoding: "utf8" })); + spec.placement = placeNow(parts, spec); const inner = `\n${JSON.stringify(spec).replace(/</g, "\\u003c")}\n`; item.text = item.text.replace(item.inner, () => inner); item.inner = inner; diff --git a/tools/html-skill/src/diagram-place.mjs b/tools/html-skill/src/diagram-place.mjs index 8d154fd6..674da6ac 100644 --- a/tools/html-skill/src/diagram-place.mjs +++ b/tools/html-skill/src/diagram-place.mjs @@ -1,14 +1,19 @@ -// compose.mjs's placer (DECISIONS 306, 1.8): reads a figure's JSON on stdin and writes its placement for both directions on stdout, through React's own -// placeDiagram (elkjs, a build-time dependency of the tool, resolved from the repository). A page never holds elkjs. Bundled into parts/ by build.mjs. +// compose.mjs's placer (DECISIONS 306, 1.8): run as a worker, it places one figure for both directions through React's own placeDiagram (elkjs, a +// build-time dependency of the tool, resolved from the repository) and hands the placement back on its port, then wakes compose.mjs, which waits for it +// (compose is synchronous). A page never holds elkjs. Bundled into parts/ by build.mjs. +import { workerData } from "node:worker_threads"; + import { placeDiagram } from "../../../packages/react/src/diagram-layout.ts"; -let input = ""; -process.stdin.setEncoding("utf8"); -process.stdin.on("data", (c) => { input += c; }); -process.stdin.on("end", async () => { - const spec = JSON.parse(input); +const { spec, port, signal } = workerData; +const flag = new Int32Array(signal); +try { const directions = spec.direction ? [spec.direction] : spec.type === "flowchart" ? ["down", "right"] : ["right", "down"]; const out = []; for (const d of directions) out.push(await placeDiagram(spec, d)); - process.stdout.write(JSON.stringify(out)); -}); + port.postMessage({ placement: out }); +} catch (e) { + port.postMessage({ error: String(e && e.message ? e.message : e) }); +} +Atomics.store(flag, 0, 1); +Atomics.notify(flag, 0); diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index e37ab081..56e01f2b 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 123200, + "budget": 123300, "usage": 4300, "builds": [ "kbd" diff --git a/tools/html-skill/test/compose.test.mjs b/tools/html-skill/test/compose.test.mjs index 1c336567..9e77bd64 100644 --- a/tools/html-skill/test/compose.test.mjs +++ b/tools/html-skill/test/compose.test.mjs @@ -417,8 +417,9 @@ describe("the command line", () => { test("uses no network and no module outside node:, so it runs from the skill folder anywhere", () => { const source = read(skillDir, "compose.mjs"); - // node:vm runs the diagram module's own script to write a figure's words into the page (DECISIONS 281, 1.19): still Node's own, no network. - assert.deepEqual([...source.matchAll(/^import .* from "([^"]+)"/gm)].map((m) => m[1]).sort(), ["node:fs", "node:path", "node:url", "node:vm"]); + // node:vm runs the diagram module's own script to write a figure's words into the page (DECISIONS 281, 1.19); node:worker_threads runs the placer + // for an automatic diagram (DECISIONS 306, 1.8), whose elkjs resolves from the repository only when a page asks for one: still Node's own, no network. + assert.deepEqual([...source.matchAll(/^import .* from "([^"]+)"/gm)].map((m) => m[1]).sort(), ["node:fs", "node:path", "node:url", "node:vm", "node:worker_threads"]); assert.doesNotMatch(source, /\bfetch\(|https?\.request|node:(net|http|https|dns|child_process)/); }); }); diff --git a/tools/html-skill/test/diagram-motion.test.mjs b/tools/html-skill/test/diagram-motion.test.mjs index b1966e82..5445f351 100644 --- a/tools/html-skill/test/diagram-motion.test.mjs +++ b/tools/html-skill/test/diagram-motion.test.mjs @@ -25,7 +25,8 @@ describe("compose.mjs", () => { test("a still diagram brings in no motion module, no loops and no mark; an animated one brings both modules", () => { const still = compose(page([figure(STILL.architecture)])); assert.ok(!still.modules.includes("diagram-motion") && !still.modules.includes("loops")); - assert.ok(!still.html.includes("data:image/svg+xml,%3Csvg")); + // No service mark's rule (a link card's cue is a core glyph's mask in the stylesheet, DECISIONS 306, 1.4, and is not a mark). + assert.ok(!/\.diagram-node\[data-mark=/.test(still.html)); const moving = compose(page([figure(animated("dataFlow"))])); assert.ok(moving.modules.includes("diagram-motion") && moving.modules.includes("loops")); assert.match(moving.html, /<figure[^>]*data-motion="animated"/); From 53064b3f76cf0dd070d3ca06fc6780349b5500b2 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:34:09 -0600 Subject: [PATCH 28/62] Export: an edge on some sides only is drawn as lines; round 66 exports in the theme shown Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- .agent/skills/basalt-html/parts/diagram-export.js | 2 +- packages/react/src/diagram-export.ts | 13 ++++++++++++- tools/review/round66.tsx | 9 +++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram-export.js b/.agent/skills/basalt-html/parts/diagram-export.js index ea8eb230..3f343f95 100644 --- a/.agent/skills/basalt-html/parts/diagram-export.js +++ b/.agent/skills/basalt-html/parts/diagram-export.js @@ -1 +1 @@ -(()=>{var B="http://www.w3.org/2000/svg",w=t=>t.replace(/[&<>"']/g,r=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[r]),T=t=>!!t&&t!=="transparent"&&!/rgba\([^)]*,\s*0\)$/.test(t)&&!/\/\s*0\)$/.test(t),g=t=>Math.round(t*100)/100;function P(t){const r=s=>t.querySelector(`:scope > [class$="-${s}"], :scope > [class*="-${s} "]`);return["head","drawing","key"].map(r).filter(s=>!!(s&&s.getClientRects().length))}async function q(t){for(const r of Array.from(document.styleSheets)){let s;try{s=r.cssRules}catch{continue}for(const l of Array.from(s)){if(!(l instanceof CSSFontFaceRule)||l.style.getPropertyValue("font-family").replace(/["']/g,"").trim()!==t)continue;const n=/url\(["']?([^"')]+)["']?\)/.exec(l.style.getPropertyValue("src"))?.[1];if(n){if(n.startsWith("data:"))return n;try{const a=await(await fetch(new URL(n,r.href??location.href))).blob();return await new Promise((e,d)=>{const i=new FileReader;i.onload=()=>e(String(i.result)),i.onerror=d,i.readAsDataURL(a)})}catch{return null}}}}return null}function F(t,r,s){const l=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let n=l.nextNode();n;n=l.nextNode()){const a=n.parentElement;if(!a||!n.textContent?.trim()||a.closest("[aria-hidden='true'] .basalt-visually-hidden, .basalt-visually-hidden, .visually-hidden, [class$='-ruler'], [hidden]"))continue;const e=getComputedStyle(a);if(e.visibility==="hidden"||e.display==="none")continue;const d=n.textContent,i=document.createRange();for(const u of d.matchAll(/\S+/g)){i.setStart(n,u.index),i.setEnd(n,u.index+u[0].length);const o=i.getBoundingClientRect();if(!o.width)continue;const m=Number.parseFloat(e.fontSize),f=o.top-r.top+(o.height-m)/2+m*.8;s.push(`<text x="${g(o.left-r.left)}" y="${g(f)}" font-family="${w(e.fontFamily)}" font-size="${m}" font-weight="${e.fontWeight}" fill="${e.color}"${e.textDecorationLine.includes("underline")?' text-decoration="underline"':""}>${w(u[0])}</text>`)}}}function O(t,r,s){const l=[t,...Array.from(t.querySelectorAll("*"))];for(const n of l){if(n instanceof SVGElement){if(n.tagName.toLowerCase()!=="svg"||n.closest("svg")!==n)continue;const y=n.getBoundingClientRect();if(!y.width||!y.height)continue;const p=n.cloneNode(!0),b=[n,...Array.from(n.querySelectorAll("*"))],v=[p,...Array.from(p.querySelectorAll("*"))];b.forEach((k,x)=>{const A=getComputedStyle(k),C=v[x];for(const c of["fill","stroke","stroke-width","stroke-dasharray","stroke-linecap","stroke-linejoin","opacity"])C.setAttribute(c,A.getPropertyValue(c));C.removeAttribute("class"),A.display==="none"&&C.setAttribute("display","none")}),p.setAttribute("x",String(g(y.left-r.left))),p.setAttribute("y",String(g(y.top-r.top))),p.removeAttribute("style"),s.push(p.outerHTML);continue}const a=getComputedStyle(n);if(a.display==="none"||a.visibility==="hidden")continue;const e=n.getBoundingClientRect();if(!e.width||!e.height)continue;const d=g(e.left-r.left),i=g(e.top-r.top),u=g(e.width),o=g(e.height),m=Number.parseFloat(a.borderTopLeftRadius)||0,f=T(a.backgroundColor)?a.backgroundColor:"none",h=Number.parseFloat(a.borderTopWidth)||0,$=h&&a.borderTopStyle!=="none"&&T(a.borderTopColor)?a.borderTopColor:"none";if(f!=="none"||$!=="none"){const y=a.borderTopStyle==="dashed"?' stroke-dasharray="4 2"':"";s.push(`<rect x="${d+h/2}" y="${i+h/2}" width="${Math.max(0,u-h)}" height="${Math.max(0,o-h)}" rx="${m}" fill="${f}" stroke="${$}" stroke-width="${h||0}"${y}/>`)}const S=/url\(["']?([^"')]+)["']?\)/.exec(a.backgroundImage)?.[1];S&&/-mark$/.test(String(n.getAttribute("class")))&&s.push(`<image href="${w(S)}" x="${d}" y="${i}" width="${u}" height="${o}"/>`)}}var L=t=>t.querySelector("[class$='-title']")?.textContent?.trim()??"",V=t=>t.querySelector("figcaption")?.textContent?.trim()??"",M=(t,r)=>`${L(t).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"diagram"}.${r}`;async function E(t,r,s){const l=r.theme??"page",n=t.getAttribute("data-theme"),a=Array.from(t.querySelectorAll("[data-lit], [data-dim], [data-near]")),e=a.map(o=>[o,o.getAttribute("data-lit"),o.getAttribute("data-dim"),o.getAttribute("data-near")]);a.forEach(o=>{o.removeAttribute("data-lit"),o.removeAttribute("data-dim"),o.removeAttribute("data-near")});const d=Array.from(t.querySelectorAll("[class*='-flow'], [class*='-bead'], [class*='-packet']"));d.forEach(o=>{o.dataset.exportHidden=o.style.display,o.style.display="none"});const i=t.getAttribute("data-entrance");i&&i!=="done"&&t.setAttribute("data-entrance","done"),l!=="page"&&t.setAttribute("data-theme",l);const u=t.style.getPropertyValue("--basalt-export");t.classList.add("basalt-exporting");try{t.offsetWidth;const o=Number.parseFloat(getComputedStyle(t).getPropertyValue("--basalt-space-4"))||16,m=P(t),f=m.map(c=>c.getBoundingClientRect()),h=Math.min(...f.map(c=>c.left)),$=Math.min(...f.map(c=>c.top)),S=Math.max(...f.map(c=>c.right)),y=Math.max(...f.map(c=>c.bottom)),p=new DOMRect(h-o,$-o,0,0),b=Math.ceil(S-h+2*o),v=Math.ceil(y-$+2*o),k=getComputedStyle(t).getPropertyValue("--basalt-surface-page").trim()||getComputedStyle(document.body).backgroundColor,x=[];for(const c of m)O(c,p,x);for(const c of m)F(c,p,x);let A="";if(s){const c=[];for(const R of["Geist","Geist Mono"]){const N=await q(R);N?c.push(`@font-face{font-family:"${R}";src:url(${N});font-weight:100 900}`):console.warn(`Basalt diagramToSvg: the face "${R}" could not be read, so the file names it`)}c.length&&(A=`<style>${c.join("")}</style>`)}return{svg:`<svg xmlns="${B}" width="${b}" height="${v}" viewBox="0 0 ${b} ${v}"><title>${w(L(t))}${w(V(t))}${A}${x.join("")}`,w:b,h:v}}finally{t.classList.remove("basalt-exporting"),u&&t.style.setProperty("--basalt-export",u),l!=="page"&&(n===null?t.removeAttribute("data-theme"):t.setAttribute("data-theme",n)),i&&i!=="done"&&t.setAttribute("data-entrance",i),d.forEach(o=>{o.style.display=o.dataset.exportHidden??"",delete o.dataset.exportHidden});for(const[o,m,f,h]of e)m!==null&&o.setAttribute("data-lit",m),f!==null&&o.setAttribute("data-dim",f),h!==null&&o.setAttribute("data-near",h)}}async function U(t,r={}){const{svg:s}=await E(t,r,(r.fonts??"embed")==="embed");return new Blob([s],{type:"image/svg+xml"})}async function D(t,r={}){const{svg:s,w:l,h:n}=await E(t,r,!0),a=r.scale??2,e=new Image;e.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(s)}`,await e.decode();const d=document.createElement("canvas");d.width=Math.round(l*a),d.height=Math.round(n*a);const i=d.getContext("2d");return i.scale(a,a),i.drawImage(e,0,0,l,n),new Promise((u,o)=>d.toBlob(m=>m?u(m):o(new Error("the PNG could not be made")),"image/png"))}(function(t){"use strict";var r=t._;function s(n,a){var e=document.createElement("a");e.href=URL.createObjectURL(n),e.download=a,document.body.appendChild(e),e.click(),e.remove(),setTimeout(function(){URL.revokeObjectURL(e.href)},1e3)}function l(n,a){var e=document.createElement("button");return e.type="button",e.className="btn diagram-download",e.setAttribute("data-variant","secondary"),e.setAttribute("data-size","sm"),e.innerHTML=""+n+"",e.addEventListener("click",a),e}r.diagramExport=function(n,a){var e=l("Download SVG",function(){U(a).then(function(u){s(u,M(a,"svg"))})}),d=l("Download PNG",function(){D(a).then(function(u){s(u,M(a,"png"))})}),i=n.querySelector(".diagram-clear");return n.insertBefore(e,i),n.insertBefore(d,i),[e,d]}})(window.Basalt)})(); +(()=>{var N="http://www.w3.org/2000/svg",S=t=>t.replace(/[&<>"']/g,s=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[s]),T=t=>!!t&&t!=="transparent"&&!/rgba\([^)]*,\s*0\)$/.test(t)&&!/\/\s*0\)$/.test(t),v=t=>Math.round(t*100)/100;function P(t){const s=c=>t.querySelector(`:scope > [class$="-${c}"], :scope > [class*="-${c} "]`);return["head","drawing","key"].map(s).filter(c=>!!(c&&c.getClientRects().length))}async function q(t){for(const s of Array.from(document.styleSheets)){let c;try{c=s.cssRules}catch{continue}for(const m of Array.from(c)){if(!(m instanceof CSSFontFaceRule)||m.style.getPropertyValue("font-family").replace(/["']/g,"").trim()!==t)continue;const r=/url\(["']?([^"')]+)["']?\)/.exec(m.style.getPropertyValue("src"))?.[1];if(r){if(r.startsWith("data:"))return r;try{const e=await(await fetch(new URL(r,s.href??location.href))).blob();return await new Promise((o,i)=>{const a=new FileReader;a.onload=()=>o(String(a.result)),a.onerror=i,a.readAsDataURL(e)})}catch{return null}}}}return null}function W(t,s,c){const m=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let r=m.nextNode();r;r=m.nextNode()){const e=r.parentElement;if(!e||!r.textContent?.trim()||e.closest("[aria-hidden='true'] .basalt-visually-hidden, .basalt-visually-hidden, .visually-hidden, [class$='-ruler'], [hidden]"))continue;const o=getComputedStyle(e);if(o.visibility==="hidden"||o.display==="none")continue;const i=r.textContent,a=document.createRange();for(const d of i.matchAll(/\S+/g)){a.setStart(r,d.index),a.setEnd(r,d.index+d[0].length);const n=a.getBoundingClientRect();if(!n.width)continue;const f=Number.parseFloat(o.fontSize),p=n.top-s.top+(n.height-f)/2+f*.8;c.push(`${S(d[0])}`)}}}function F(t,s,c){const m=[t,...Array.from(t.querySelectorAll("*"))];for(const r of m){if(r instanceof SVGElement){if(r.tagName.toLowerCase()!=="svg"||r.closest("svg")!==r)continue;const u=r.getBoundingClientRect();if(!u.width||!u.height)continue;const h=r.cloneNode(!0),x=[r,...Array.from(r.querySelectorAll("*"))],y=[h,...Array.from(h.querySelectorAll("*"))];x.forEach((b,R)=>{const l=getComputedStyle(b),$=y[R];for(const A of["fill","stroke","stroke-width","stroke-dasharray","stroke-linecap","stroke-linejoin","opacity"])$.setAttribute(A,l.getPropertyValue(A));$.removeAttribute("class"),l.display==="none"&&$.setAttribute("display","none")}),h.setAttribute("x",String(v(u.left-s.left))),h.setAttribute("y",String(v(u.top-s.top))),h.removeAttribute("style"),c.push(h.outerHTML);continue}const e=getComputedStyle(r);if(e.display==="none"||e.visibility==="hidden")continue;const o=r.getBoundingClientRect();if(!o.width||!o.height)continue;const i=v(o.left-s.left),a=v(o.top-s.top),d=v(o.width),n=v(o.height),f=Number.parseFloat(e.borderTopLeftRadius)||0,p=T(e.backgroundColor)?e.backgroundColor:"none",g=[e.borderTopWidth,e.borderRightWidth,e.borderBottomWidth,e.borderLeftWidth].map(u=>Number.parseFloat(u)||0),C=g.every(u=>u===g[0]);if(!C){const[u,h,x,y]=g,b=(R,l,$,A,D,G)=>{R&&T(l)&&c.push(``)};b(u,e.borderTopColor,i,a+u/2,i+d,a+u/2),b(x,e.borderBottomColor,i,a+n-x/2,i+d,a+n-x/2),b(y,e.borderLeftColor,i+y/2,a,i+y/2,a+n),b(h,e.borderRightColor,i+d-h/2,a,i+d-h/2,a+n)}const w=C?g[0]:0,L=w&&e.borderTopStyle!=="none"&&T(e.borderTopColor)?e.borderTopColor:"none";if(p!=="none"||L!=="none"){const u=e.borderTopStyle==="dashed"?' stroke-dasharray="4 2"':"";c.push(``)}const k=/url\(["']?([^"')]+)["']?\)/.exec(e.backgroundImage)?.[1];k&&/-mark$/.test(String(r.getAttribute("class")))&&c.push(``)}}var B=t=>t.querySelector("[class$='-title']")?.textContent?.trim()??"",O=t=>t.querySelector("figcaption")?.textContent?.trim()??"",M=(t,s)=>`${B(t).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"diagram"}.${s}`;async function E(t,s,c){const m=s.theme??"page",r=t.getAttribute("data-theme"),e=Array.from(t.querySelectorAll("[data-lit], [data-dim], [data-near]")),o=e.map(n=>[n,n.getAttribute("data-lit"),n.getAttribute("data-dim"),n.getAttribute("data-near")]);e.forEach(n=>{n.removeAttribute("data-lit"),n.removeAttribute("data-dim"),n.removeAttribute("data-near")});const i=Array.from(t.querySelectorAll("[class*='-flow'], [class*='-bead'], [class*='-packet']"));i.forEach(n=>{n.dataset.exportHidden=n.style.display,n.style.display="none"});const a=t.getAttribute("data-entrance");a&&a!=="done"&&t.setAttribute("data-entrance","done"),m!=="page"&&t.setAttribute("data-theme",m);const d=t.style.getPropertyValue("--basalt-export");t.classList.add("basalt-exporting");try{t.offsetWidth;const n=Number.parseFloat(getComputedStyle(t).getPropertyValue("--basalt-space-4"))||16,f=P(t),p=f.map(l=>l.getBoundingClientRect()),g=Math.min(...p.map(l=>l.left)),C=Math.min(...p.map(l=>l.top)),w=Math.max(...p.map(l=>l.right)),L=Math.max(...p.map(l=>l.bottom)),k=new DOMRect(g-n,C-n,0,0),u=Math.ceil(w-g+2*n),h=Math.ceil(L-C+2*n),x=getComputedStyle(t).getPropertyValue("--basalt-surface-page").trim()||getComputedStyle(document.body).backgroundColor,y=[];for(const l of f)F(l,k,y);for(const l of f)W(l,k,y);let b="";if(c){const l=[];for(const $ of["Geist","Geist Mono"]){const A=await q($);A?l.push(`@font-face{font-family:"${$}";src:url(${A});font-weight:100 900}`):console.warn(`Basalt diagramToSvg: the face "${$}" could not be read, so the file names it`)}l.length&&(b=``)}return{svg:`${S(B(t))}${S(O(t))}${b}${y.join("")}`,w:u,h}}finally{t.classList.remove("basalt-exporting"),d&&t.style.setProperty("--basalt-export",d),m!=="page"&&(r===null?t.removeAttribute("data-theme"):t.setAttribute("data-theme",r)),a&&a!=="done"&&t.setAttribute("data-entrance",a),i.forEach(n=>{n.style.display=n.dataset.exportHidden??"",delete n.dataset.exportHidden});for(const[n,f,p,g]of o)f!==null&&n.setAttribute("data-lit",f),p!==null&&n.setAttribute("data-dim",p),g!==null&&n.setAttribute("data-near",g)}}async function V(t,s={}){const{svg:c}=await E(t,s,(s.fonts??"embed")==="embed");return new Blob([c],{type:"image/svg+xml"})}async function U(t,s={}){const{svg:c,w:m,h:r}=await E(t,s,!0),e=s.scale??2,o=new Image;o.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c)}`,await o.decode();const i=document.createElement("canvas");i.width=Math.round(m*e),i.height=Math.round(r*e);const a=i.getContext("2d");return a.scale(e,e),a.drawImage(o,0,0,m,r),new Promise((d,n)=>i.toBlob(f=>f?d(f):n(new Error("the PNG could not be made")),"image/png"))}(function(t){"use strict";var s=t._;function c(r,e){var o=document.createElement("a");o.href=URL.createObjectURL(r),o.download=e,document.body.appendChild(o),o.click(),o.remove(),setTimeout(function(){URL.revokeObjectURL(o.href)},1e3)}function m(r,e){var o=document.createElement("button");return o.type="button",o.className="btn diagram-download",o.setAttribute("data-variant","secondary"),o.setAttribute("data-size","sm"),o.innerHTML=""+r+"",o.addEventListener("click",e),o}s.diagramExport=function(r,e){var o=m("Download SVG",function(){V(e).then(function(d){c(d,M(e,"svg"))})}),i=m("Download PNG",function(){U(e).then(function(d){c(d,M(e,"png"))})}),a=r.querySelector(".diagram-clear");return r.insertBefore(o,a),r.insertBefore(i,a),[o,i]}})(window.Basalt)})(); diff --git a/packages/react/src/diagram-export.ts b/packages/react/src/diagram-export.ts index ff0f41bf..e58bb99a 100644 --- a/packages/react/src/diagram-export.ts +++ b/packages/react/src/diagram-export.ts @@ -100,7 +100,18 @@ function boxesOf(root: Element, origin: DOMRect, out: string[]) { const x = r2(r.left - origin.left), y = r2(r.top - origin.top), w = r2(r.width), h = r2(r.height); const radius = Number.parseFloat(cs.borderTopLeftRadius) || 0; const fill = visible(cs.backgroundColor) ? cs.backgroundColor : "none"; - const bw = Number.parseFloat(cs.borderTopWidth) || 0; + const sidesW = [cs.borderTopWidth, cs.borderRightWidth, cs.borderBottomWidth, cs.borderLeftWidth].map((v) => Number.parseFloat(v) || 0); + const uniform = sidesW.every((v) => v === sidesW[0]); + // An edge on some sides only (the key's divider) is drawn as those lines, not a box. + if (!uniform) { + const [t, r, b, l] = sidesW; + const edge = (on: number, color: string, x1: number, y1: number, x2: number, y2: number) => { if (on && visible(color)) out.push(``); }; + edge(t!, cs.borderTopColor, x, y + t! / 2, x + w, y + t! / 2); + edge(b!, cs.borderBottomColor, x, y + h - b! / 2, x + w, y + h - b! / 2); + edge(l!, cs.borderLeftColor, x + l! / 2, y, x + l! / 2, y + h); + edge(r!, cs.borderRightColor, x + w - r! / 2, y, x + w - r! / 2, y + h); + } + const bw = uniform ? sidesW[0]! : 0; const stroke = bw && cs.borderTopStyle !== "none" && visible(cs.borderTopColor) ? cs.borderTopColor : "none"; if (fill !== "none" || stroke !== "none") { const dash = cs.borderTopStyle === "dashed" ? ` stroke-dasharray="4 2"` : ""; diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx index a69b0dc3..a98fe460 100644 --- a/tools/review/round66.tsx +++ b/tools/review/round66.tsx @@ -21,7 +21,7 @@ const isShot = () => new URLSearchParams(window.location.search).get("shot") === const frames = (n: number) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }); /** A figure exported to SVG (diagram-export) and shown as the file, beside nothing else: what an app's own Download button would write. */ -function Exported({ k, theme }: { k: Key; theme: "light" | "dark" }) { +function Exported({ k }: { k: Key }) { const host = React.useRef(null); const [url, setUrl] = React.useState(null); React.useEffect(() => { @@ -31,12 +31,13 @@ function Exported({ k, theme }: { k: Key; theme: "light" | "dark" }) { await frames(8); const fig = host.current?.querySelector("figure"); if (!fig) return; - const blob = await diagramToSvg(fig, { theme }); + // The theme shown (the default), read when the shot has set it. + const blob = await diagramToSvg(fig); setUrl(URL.createObjectURL(blob)); await frames(4); ready(); })(); - }, [theme]); + }, []); return (
@@ -194,7 +195,7 @@ export const ROUND_66: Round = { widths: [1440], scales: [2], height: 1100, - demo: () => , + demo: () => , }, { id: "print", From 2b15c9ec96fa05c483d49e66fa3de3f8fd71d23e Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:54:01 -0600 Subject: [PATCH 29/62] Two merged tests follow the decision: a tap traces on touch, and a dashed line may flow diagrams.test.mjs: on touch a tap traces, the same tap clears, Clear highlight enables, and nothing is a live region (1.5 brings the touch trace back). diagram-motion.test.mjs: flow on a dashed line is no longer an error; its own dashes march. The diagram-export module's cap is 7,850 (measured 7,832). Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/manifest.json | 2 +- packages/react/test/diagram-motion.test.mjs | 12 +++++++++++- packages/react/test/diagrams.test.mjs | 10 +++++++++- tools/html-skill/src/modules.json | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index 56e01f2b..18e08e6f 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -853,7 +853,7 @@ "requires": [ "diagram" ], - "budget": 7450, + "budget": 7850, "usage": 700 }, "diagram-text": { diff --git a/packages/react/test/diagram-motion.test.mjs b/packages/react/test/diagram-motion.test.mjs index a298da3e..c399f4d6 100644 --- a/packages/react/test/diagram-motion.test.mjs +++ b/packages/react/test/diagram-motion.test.mjs @@ -528,7 +528,6 @@ describe("one mover (then)", () => { "a pulse id that is no node": `{ ...S.animated("architecture"), pulse: ["browser", "nowhere"] }`, "two ids no line joins that way": `{ ...S.animated("architecture"), pulse: ["svc", "alb"] }`, "both a pulse and a packet": `{ ...S.animated("architecture"), packet: { path: ["browser", "alb"] } }`, - "flow on a dashed line": `{ ...S.animated("architecture"), edges: S.animated("architecture").edges.map((e) => (e.kind === "dashed" ? { ...e, flow: true } : e)) }`, "flow on the mover's line": `{ ...S.animated("architecture"), edges: S.animated("architecture").edges.map((e) => (e.from === "alb" ? { ...e, flow: true } : e)) }`, }; for (const [name, expr] of Object.entries(cases)) { @@ -540,6 +539,17 @@ describe("one mover (then)", () => { }); } + // Flow on a dashed line is allowed (DECISIONS 306, 1.5): its own dashes march toward the head, one period at speed-diagram-flow; no error. + test("a dashed line that flows marches its own dashes, with no error", async () => { + const { page, warnings } = await devPage(); + await draw(page, [["arch", `{ ...S.animated("architecture"), pulse: undefined, edges: S.animated("architecture").edges.map((e) => (e.kind === "dashed" ? { ...e, flow: true } : e)) }`]]); + await until(page, () => document.querySelector("#fig-arch .basalt-diagram-pause")); + await page.evaluate(() => { const f = document.getElementById("fig-arch"); f.setAttribute("data-entrance", "done"); f.dispatchEvent(new Event("basalt-diagram-settle")); }); + await until(page, () => [...document.querySelectorAll('#fig-arch .basalt-diagram-line[data-kind="dashed"]')].some((l) => l.getAnimations().length > 0)); + assert.equal(await page.locator("#error-arch").count(), 0); + assert.ok(!warnings.some((w) => /dashed and flows/.test(w))); + }); + test("a flow line with no label warns", async () => { const { page, warnings } = await devPage(); await draw(page, [["arch", `{ ...S.animated("architecture"), edges: S.animated("architecture").edges.map((e) => (e.from === "svc" && e.to === "s3" ? { ...e, flow: true, label: undefined } : e)) }`]]); diff --git a/packages/react/test/diagrams.test.mjs b/packages/react/test/diagrams.test.mjs index 15c0e565..393632ce 100644 --- a/packages/react/test/diagrams.test.mjs +++ b/packages/react/test/diagrams.test.mjs @@ -588,11 +588,19 @@ describe("tracing (1.15)", () => { await page.close(); }); - test("on touch (no hover) a tap traces nothing", async () => { + // A trace on touch comes back (DECISIONS 306, 1.5): a tap traces a card, the same card clears it, and "Clear highlight" is mounted, aria-disabled until then. + test("on touch (no hover) a tap traces, the same tap clears, and Clear highlight follows", async () => { const { page } = await diagramPage({ hasTouch: true, isMobile: true, viewport: { width: 1440, height: 1000 } }); + const clear = page.locator(`#fig-architecture .${P}-clear`); + assert.equal(await clear.getAttribute("aria-disabled"), "true"); + await page.tap(`#fig-architecture .${P}-node[data-node="svc"]`); + await page.waitForTimeout(150); + assert.ok((await page.locator(`#fig-architecture .${P}-edge[data-lit]`).count()) > 0); + assert.equal(await clear.getAttribute("aria-disabled"), null); await page.tap(`#fig-architecture .${P}-node[data-node="svc"]`); await page.waitForTimeout(150); assert.equal(await page.locator(`#fig-architecture .${P}-edge[data-lit]`).count(), 0); + assert.equal(await page.locator(`#fig-architecture [aria-live]`).count(), 0); await page.close(); }); }); diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index 56e01f2b..18e08e6f 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -853,7 +853,7 @@ "requires": [ "diagram" ], - "budget": 7450, + "budget": 7850, "usage": 700 }, "diagram-text": { From 116c922a6d628271ce0d7e4e44df88a09a1abee2 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:54:31 -0600 Subject: [PATCH 30/62] Re-record the five diagrams' sizes at the batch's head (+22 bytes each) Co-Authored-By: Claude Opus 5.5 --- packages/react/test/export-sizes.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/react/test/export-sizes.json b/packages/react/test/export-sizes.json index 13765c50..6774907d 100644 --- a/packages/react/test/export-sizes.json +++ b/packages/react/test/export-sizes.json @@ -18,7 +18,7 @@ "AppHeader": 1285, "AppShell": 103887, "AppTile": 1112, - "ArchitectureDiagram": 87133, + "ArchitectureDiagram": 87155, "ArrowDownGlyph": 2868, "ArrowLeftGlyph": 2869, "ArrowRightGlyph": 2859, @@ -70,7 +70,7 @@ "CopyGlyph": 2884, "Countdown": 3016, "CoverageStrip": 1570, - "DataFlowDiagram": 87080, + "DataFlowDiagram": 87102, "DateAge": 2527, "DescriptionColumns": 216, "DescriptionItem": 593, @@ -105,7 +105,7 @@ "Fieldset": 6390, "FilterResult": 698, "FilterToolbar": 774, - "FlowchartDiagram": 87101, + "FlowchartDiagram": 87123, "Form": 8730, "FormGrid": 438, "FormGridItem": 628, @@ -224,7 +224,7 @@ "RunsGlyph": 3128, "STATUS_MESSAGE_MS": 26, "SandboxesGlyph": 2963, - "SchemaDiagram": 87049, + "SchemaDiagram": 87071, "SearchDialog": 88277, "SearchField": 18301, "SearchGlyph": 3181, @@ -243,7 +243,7 @@ "SelectableList": 821, "SelectionBar": 25913, "Separator": 4531, - "SequenceDiagram": 87077, + "SequenceDiagram": 87099, "SettingsGlyph": 3100, "ShareBar": 1411, "Sheet": 70793, @@ -412,11 +412,11 @@ "useWaitMark": 303 }, "package": { - "bytes": 890053, - "gzip": 296141 + "bytes": 890075, + "gzip": 296147 }, "styles": { - "bytes": 406744, - "gzip": 52867 + "bytes": 406843, + "gzip": 52878 } } From a7cb435718221815006ef51ba52ef67fdfe723ab Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:58:04 -0600 Subject: [PATCH 31/62] The quiet run, layout="auto" in the types, and the viewer's automatic direction A run's unreached messages are quiet (DECISIONS 306, 1.2): while "Play the run" runs, every message after the current one has its label in secondary ink and its line and head in diagram-edge-dim; stopping, finishing, printing or tracing restores them at once. The architecture, flowchart and schema props are a union on layout: authored cards carry col and row as before, and under layout="auto" no card needs them (DiagramUnplaced). In the viewer an automatic figure with no named direction takes the direction with the larger Fit in the stage, a tie keeping the type's own (9.3), in React and the skill. Co-Authored-By: Claude Opus 5.5 --- .../basalt-html/parts/diagram-motion.js | 2 +- .../skills/basalt-html/parts/diagram-zoom.js | 2 +- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 20 +++++----- packages/react/src/architecture-diagram.tsx | 38 ++++++++++++------- packages/react/src/diagram-core.ts | 3 ++ packages/react/src/diagram-figure.tsx | 17 +++++++++ packages/react/src/diagram-motion-core.ts | 18 ++++++++- packages/react/src/diagram-viewer.tsx | 5 +++ packages/react/src/flowchart-diagram.tsx | 36 +++++++++++------- packages/react/src/index.ts | 2 +- packages/react/src/schema-diagram.tsx | 36 +++++++++++------- packages/react/src/styles/components.css | 14 +++++++ tools/html-skill/src/modules/diagram-zoom.js | 1 + tools/html-skill/src/modules/diagram.js | 14 +++++++ 15 files changed, 155 insertions(+), 55 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram-motion.js b/.agent/skills/basalt-html/parts/diagram-motion.js index 7aebfc97..c8c2cab6 100644 --- a/.agent/skills/basalt-html/parts/diagram-motion.js +++ b/.agent/skills/basalt-html/parts/diagram-motion.js @@ -1 +1 @@ -(()=>{var C=Object.defineProperty,T=(t,s,e)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s,e)=>T(t,typeof s!="symbol"?s+"":s,e);function P(t,s){const e=r=>String(Math.round(r*100)/100);let i=`M${e(t[0].x)} ${e(t[0].y)}`;for(let r=1;r`basalt-diagram-entrance:${location.pathname}#${t.id}`;function k(t){const s=t.getAttribute("data-entrance");s!=="pending"&&s!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}var p;function O(t){if(!p){const s=()=>{for(const h of p?.figs??[])h.sync()},e=()=>{for(const h of p?.figs??[])k(h.host.fig);s()},i=new IntersectionObserver(h=>{for(const o of h)for(const a of p?.figs??[])a.drawing===o.target&&a.seen(o)},{threshold:Array.from({length:21},(h,o)=>o/20)}),n=new MutationObserver(h=>{for(const o of h){if(o.target===document.documentElement){for(const a of p?.figs??[])a.holdChanged();continue}for(const a of p?.figs??[])a.host.fig===o.target&&a.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const r=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of r)h.addEventListener("change",s);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",s),p={figs:new Set,io:i,mo:n,media:r,onChange:s,onPrint:e}}return p.figs.add(t),t.drawing&&p.io.observe(t.drawing),p.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),p}function _(t){if(p&&(p.figs.delete(t),t.drawing&&p.io.unobserve(t.drawing),!p.figs.size)){p.io.disconnect(),p.mo.disconnect();for(const s of p.media)s.removeEventListener("change",p.onChange);window.removeEventListener("beforeprint",p.onPrint),document.removeEventListener("visibilitychange",p.onChange),p=void 0}}function F(t){const s=getComputedStyle(t),e=h=>s.getPropertyValue(`--basalt-${h}`).trim(),i=h=>{const o=e(h),a=parseFloat(o);return/ms$/.test(o)?a:/s$/.test(o)?a*1e3:a||0},n=h=>parseFloat(e(h))||0,r=h=>e(`ease-${h}`)||"ease";return{lineMin:i("duration-diagram-line-min"),lineMax:i("duration-diagram-line-max"),stagger:i("duration-diagram-stagger"),step:i("duration-diagram-step"),arrow:i("duration-diagram-arrow"),limit:i("duration-diagram-limit"),legMin:i("duration-diagram-leg-min"),legMax:i("duration-diagram-leg-max"),rest:i("duration-diagram-rest"),pause:i("duration-diagram-pause"),repeat:i("duration-diagram-repeat"),fast:i("duration-fast"),base:i("duration-base"),slow:i("duration-slow"),slower:i("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:r("in-out"),out:r("out"),in:r("in")}}var L=(t,s,e)=>Math.max(s,Math.min(e,t)),I="http://www.w3.org/2000/svg",y=(t,s,e)=>{const i=document.createElementNS(I,t);for(const[n,r]of Object.entries(s))i.setAttribute(n,String(r));return e?.appendChild(i),i},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",V={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function v(t,s){const e=t.pts.map(a=>({...a})),i=V[t.dir],n=e[e.length-1],r=e[e.length-2],h=Math.hypot(n.x-r.x,n.y-r.y),o=Math.min(s,Math.max(0,h-.5));return n.x-=i.x*o,n.y-=i.y*o,e}var M=t=>t.slice(1).reduce((s,e,i)=>s+Math.hypot(e.x-t[i].x,e.y-t[i].y),0),R=(t,s)=>{const e=t.map(n=>n.x),i=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-s),t:Math.floor(Math.min(...i)-s),r:Math.ceil(Math.max(...e)+s),b:Math.ceil(Math.max(...i)+s)}},D=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",s=>(this.listeners.add(s),()=>{this.listeners.delete(s)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const s of[...this.flowEls.values(),...this.beadEls.values()])s.remove();this.dot?.remove(),_(this)}}),c(this,"played",!1),c(this,"onSettle",()=>{this.played&&!this.byMode()&&this.markVisit(),this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const i=this.introEnd?.currentTime,n=i!=null?Number(i):E()-this.t0,r=new Set([...this.plans].filter(([,a])=>a.end<=n).map(([a])=>a)),{plans:h,factor:o}=this.plan(this.ordered(e),this.factor);for(const a of r){const l=this.plans.get(a);l&&h.set(a,l)}this.factor=o,this.plans=h,this.build(r,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const s=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(i=>!!i.flow)]);s!==this.signature&&(this.signature=s,k(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",s=>{if(!this.lastSend){this.lastSend={v:s};return}s===void 0||s===this.lastSend.v||(this.lastSend={v:s},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}k(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=F(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=O(this),this.sync()}publish(){const t=this.hasLines(),s=this.host.model(),e=this.modes(),i=s.edges.some(r=>r.flow)||!!s.motion.pulse||!!s.motion.packet?.repeat,n={canLoop:s.motion.animated&&i&&t&&!e.reduce&&!e.forced,runShown:s.motion.animated&&s.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const r of this.listeners)r()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}byMode(){const t=this.modes();return t.held||t.print||t.reduce||t.forced}markVisit(){const t=this.host.fig;if(!(!t.hasAttribute("data-first-visit")||!t.id))try{localStorage.setItem(G(t),"1")}catch{}}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const s=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=s-.5,this.sync()}holdChanged(){this.modes().held&&k(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,s=this.host.model(),e=this.modes(),i=this.entrance();(i==="pending"||i==="running")&&(e.held||e.print||e.reduce||e.forced)?k(t):i==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!i&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(s,e),this.publish()}ordered(t){const s=this.host.model(),e=[...t.lines];return s.type==="schema"?e.sort((i,n)=>i.pts[0].y-n.pts[0].y||i.pts[0].x-n.pts[0].x||i.i-n.i):e.sort((i,n)=>i.i-n.i),e}plan(t,s){const e=this.t,i=this.host.model().type==="sequence",n=i?e.step:e.stagger,r=t.map(a=>{const l=this.lineEl(a)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(a.pts),m=i?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=i?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,i?e.slower:0)}});let h=1;for(let a=1;a{const d=l*n*h;o.set(a.i,{start:d+r[l].lead,dur:r[l].dur,end:d+r[l].tail})}),{plans:o,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.played=!0,this.t0=E();const{plans:s,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=s,this.build(new Set,!0)}build(t,s){const e=this.host.geo(),i=this.host.fig,{P:n}=this.host,r=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const o=i.querySelector(`.${n}-ink`),a=o?.querySelector(`.${n}-svg`);if(!o||!a)return;this.defs=y("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),a.after(this.defs);const l=y("defs",{},this.defs),d=(u,g=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),g.add(u),u);let m=0;for(const u of e.lines){const g=this.plans.get(u.i),f=this.lineEl(u);if(!g||!f)continue;if(m=Math.max(m,g.end),t.has(u.i)){f.removeAttribute("mask");continue}const w=`${this.host.base}-reveal-${u.i}`,x=y("mask",{id:w,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),A=f.querySelector(`.${n}-line`);if(A){const b=A.getTotalLength(),B=y("path",{d:A.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${b} ${b+8}`,"stroke-dashoffset":b},x);d(B.animate([{strokeDashoffset:`${b}px`},{strokeDashoffset:"0px"}],{duration:g.dur,delay:g.start,easing:r.inOut,fill:"both"}))}const S=f.querySelector(`.${n}-tip`);if(S){const b=y("path",{d:S.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},x);d(b.animate([{opacity:0},{opacity:1}],{duration:r.slow,delay:g.start+.85*g.dur,easing:r.out,fill:"both"}))}const $=f.querySelector(`.${n}-dot`);if($){const b=y("circle",{cx:$.getAttribute("cx")??0,cy:$.getAttribute("cy")??0,r:Number($.getAttribute("r")??3)+1,fill:"#fff"},x);d(b.animate([{opacity:0},{opacity:1}],{duration:r.fast,delay:g.start,easing:r.out,fill:"both"}))}f.setAttribute("mask",`url(#${w})`)}if(s&&this.host.model().type==="sequence"){const u=getComputedStyle(i),g=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),w=i.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((x,A)=>{const S=w[A]?.querySelector(`.${n}-mlabel`),$=this.plans.get(x.i);S&&$&&g&&f&&d(S.animate([{color:g},{color:f}],{duration:r.slower,delay:$.start-r.base,easing:r.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(i.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.markVisit(),this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,s){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||s.reduce||s.forced||s.print||s.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,s){s.add(t);const e=()=>{s.delete(t)};return t.finished.then(e,e),s===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,s){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),s).finished.then(e=>{e.cancel()})}overlay(t,s,e){const i=this.host.fig.querySelector(`.${this.host.P}-ink`),n=i?.querySelector(`.${this.host.P}-svg`);if(!i||!n)return null;const r=this.host.tokens(),h=v(t,r?.head??8),o=R(h,s),a=y("svg",{class:`${this.host.P}-${e}`,width:o.r-o.l,height:o.b-o.t,viewBox:`${o.l} ${o.t} ${o.r-o.l} ${o.b-o.t}`,"aria-hidden":"true",focusable:"false"});a.style.left=`${o.l}px`,a.style.top=`${o.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(a),{svg:a,d:P(h,t.from===t.to?r?.radiusXs??4:r?.radius??8),pts:h}}visible(t,s){const e=this.host.geo();let i=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const r=(n.box.t+n.box.b)/2,h=s.some((o,a)=>a>0&&Math.abs(o.y-s[a-1].y)<.5&&Math.abs(r-o.y)<1.5);i+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(s)-i}flow(t,s){const e=t.lines.find(o=>o.i===s);if(!e)return;const i=this.host.tokens();if(e.kind==="dashed"){if(this.visible(e,v(e,i?.head??8))<48)return;const o=this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${s}"] .${this.host.P}-line`);if(!o)return;const a=(i?.dash??6)+(i?.dashGap??4);this.track(o.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-a}px`}],{duration:a/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops);return}let n=this.flowEls.get(s);if(n&&!n.isConnected&&(this.flowEls.delete(s),n=void 0),!n){const o=i?.space("1")??4,a=this.overlay({...e,pts:v(e,o)},e.width+2,"flow");if(!a)return;if(this.visible(e,v(e,i?.head??8))<48){a.svg.remove();return}const l=i?.cut??2;y("path",{d:a.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},a.svg),n=a.svg,this.flowEls.set(s,n)}n.style.display="";const r=n.firstElementChild,h=this.t.flowPeriod;this.track(r.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,s){const i=this.host.model().edges.find(n=>n.from===t&&n.to===s);return i?this.host.geo()?.lines.find(n=>n.i===i.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,s){const e=this.host.tokens();for(;t===this.loopGen;){for(let i=1;it===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(s,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const i=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=i;try{await i.finished}finally{this.repeatGap===i&&(this.repeatGap=null),i.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),s=t.motion.packet?.path;if(!t.motion.animated||!s||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(s[s.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const i=++this.runGen;this.packetRun(s,this.runAnims,()=>i===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&i===this.runGen&&(this.waiting=!1,this.send())})}stopRun(){this.runGen++,this.runAt=-1;for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const s=this.host.geo();if(!s?.lines.length)return;for(const o of this.runAnims)o.cancel();this.runAnims.clear();const e=++this.runGen,i=()=>e===this.runGen,n=this.ordered(s),r=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let o=t;o{if(!q(o))throw o})}};function N(t){const s=[],e=[],{pulse:i,packet:n}=t.motion;i&&n&&s.push("a figure names both a pulse and a packet: it has one mover at most");const r=i??n?.path,h=i?"pulse":"packet",o=new Set;if(r){for(const a of r)t.byId.has(a)||s.push(`the ${h} names ${a}, which is not a node`);for(let a=1;ad.from===r[a-1]&&d.to===r[a]);l?o.add(l.i):s.push(`the ${h} goes from ${r[a-1]} to ${r[a]}, and no line joins them in that direction`)}}for(const a of t.edges)a.flow&&(o.has(a.i)&&s.push(`the line from ${a.from} to ${a.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),a.label||e.push(`the line from ${a.from} to ${a.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:s,warnings:e}}function z(t){return new D(t)}(function(t){"use strict";var s=t._;function e(i,n,r){var h=document.createElement("button");return h.type="button",h.className="btn "+i,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),r&&r(h),h.appendChild(document.createTextNode(n)),h}s.diagramMotion=function(i,n,r){var h=N(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var o=z(n),a=i.querySelector(".diagram-foot"),l=null,d=null;a&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){o.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var w=document.createElement("span");w.className="btn-check",w.setAttribute("aria-hidden","true"),f.appendChild(w)}),l.hidden=d.hidden=!0,a.appendChild(l),a.appendChild(d));function m(){var f=o.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=o.subscribe(m);m();var g=r&&r.packet?r.packet.send:void 0;return o.sendValue("__diagramSend"in i?i.__diagramSend:g),o.sendValue(g),i.__diagramSend=g,{redrawn:o.redrawn,sendValue:function(f){o.sendValue(f),i.__diagramSend=f},destroy:function(){u(),o.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); +(()=>{var C=Object.defineProperty,T=(t,s,e)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s,e)=>T(t,typeof s!="symbol"?s+"":s,e);function P(t,s){const e=r=>String(Math.round(r*100)/100);let i=`M${e(t[0].x)} ${e(t[0].y)}`;for(let r=1;r`basalt-diagram-entrance:${location.pathname}#${t.id}`;function A(t){const s=t.getAttribute("data-entrance");s!=="pending"&&s!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}var g;function O(t){if(!g){const s=()=>{for(const h of g?.figs??[])h.sync()},e=()=>{for(const h of g?.figs??[])A(h.host.fig);s()},i=new IntersectionObserver(h=>{for(const o of h)for(const a of g?.figs??[])a.drawing===o.target&&a.seen(o)},{threshold:Array.from({length:21},(h,o)=>o/20)}),n=new MutationObserver(h=>{for(const o of h){if(o.target===document.documentElement){for(const a of g?.figs??[])a.holdChanged();continue}for(const a of g?.figs??[])a.host.fig===o.target&&a.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const r=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of r)h.addEventListener("change",s);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",s),g={figs:new Set,io:i,mo:n,media:r,onChange:s,onPrint:e}}return g.figs.add(t),t.drawing&&g.io.observe(t.drawing),g.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),g}function _(t){if(g&&(g.figs.delete(t),t.drawing&&g.io.unobserve(t.drawing),!g.figs.size)){g.io.disconnect(),g.mo.disconnect();for(const s of g.media)s.removeEventListener("change",g.onChange);window.removeEventListener("beforeprint",g.onPrint),document.removeEventListener("visibilitychange",g.onChange),g=void 0}}function F(t){const s=getComputedStyle(t),e=h=>s.getPropertyValue(`--basalt-${h}`).trim(),i=h=>{const o=e(h),a=parseFloat(o);return/ms$/.test(o)?a:/s$/.test(o)?a*1e3:a||0},n=h=>parseFloat(e(h))||0,r=h=>e(`ease-${h}`)||"ease";return{lineMin:i("duration-diagram-line-min"),lineMax:i("duration-diagram-line-max"),stagger:i("duration-diagram-stagger"),step:i("duration-diagram-step"),arrow:i("duration-diagram-arrow"),limit:i("duration-diagram-limit"),legMin:i("duration-diagram-leg-min"),legMax:i("duration-diagram-leg-max"),rest:i("duration-diagram-rest"),pause:i("duration-diagram-pause"),repeat:i("duration-diagram-repeat"),fast:i("duration-fast"),base:i("duration-base"),slow:i("duration-slow"),slower:i("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:r("in-out"),out:r("out"),in:r("in")}}var L=(t,s,e)=>Math.max(s,Math.min(e,t)),I="http://www.w3.org/2000/svg",y=(t,s,e)=>{const i=document.createElementNS(I,t);for(const[n,r]of Object.entries(s))i.setAttribute(n,String(r));return e?.appendChild(i),i},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",V={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function v(t,s){const e=t.pts.map(a=>({...a})),i=V[t.dir],n=e[e.length-1],r=e[e.length-2],h=Math.hypot(n.x-r.x,n.y-r.y),o=Math.min(s,Math.max(0,h-.5));return n.x-=i.x*o,n.y-=i.y*o,e}var M=t=>t.slice(1).reduce((s,e,i)=>s+Math.hypot(e.x-t[i].x,e.y-t[i].y),0),R=(t,s)=>{const e=t.map(n=>n.x),i=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-s),t:Math.floor(Math.min(...i)-s),r:Math.ceil(Math.max(...e)+s),b:Math.ceil(Math.max(...i)+s)}},D=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",s=>(this.listeners.add(s),()=>{this.listeners.delete(s)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const s of[...this.flowEls.values(),...this.beadEls.values()])s.remove();this.dot?.remove(),_(this)}}),c(this,"played",!1),c(this,"onSettle",()=>{this.played&&!this.byMode()&&this.markVisit(),this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const i=this.introEnd?.currentTime,n=i!=null?Number(i):E()-this.t0,r=new Set([...this.plans].filter(([,a])=>a.end<=n).map(([a])=>a)),{plans:h,factor:o}=this.plan(this.ordered(e),this.factor);for(const a of r){const l=this.plans.get(a);l&&h.set(a,l)}this.factor=o,this.plans=h,this.build(r,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const s=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(i=>!!i.flow)]);s!==this.signature&&(this.signature=s,A(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",s=>{if(!this.lastSend){this.lastSend={v:s};return}s===void 0||s===this.lastSend.v||(this.lastSend={v:s},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}A(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=F(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=O(this),this.sync()}publish(){const t=this.hasLines(),s=this.host.model(),e=this.modes(),i=s.edges.some(r=>r.flow)||!!s.motion.pulse||!!s.motion.packet?.repeat,n={canLoop:s.motion.animated&&i&&t&&!e.reduce&&!e.forced,runShown:s.motion.animated&&s.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const r of this.listeners)r()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}byMode(){const t=this.modes();return t.held||t.print||t.reduce||t.forced}markVisit(){const t=this.host.fig;if(!(!t.hasAttribute("data-first-visit")||!t.id))try{localStorage.setItem(G(t),"1")}catch{}}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const s=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=s-.5,this.sync()}holdChanged(){this.modes().held&&A(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,s=this.host.model(),e=this.modes(),i=this.entrance();(i==="pending"||i==="running")&&(e.held||e.print||e.reduce||e.forced)?A(t):i==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!i&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(s,e),this.publish()}ordered(t){const s=this.host.model(),e=[...t.lines];return s.type==="schema"?e.sort((i,n)=>i.pts[0].y-n.pts[0].y||i.pts[0].x-n.pts[0].x||i.i-n.i):e.sort((i,n)=>i.i-n.i),e}plan(t,s){const e=this.t,i=this.host.model().type==="sequence",n=i?e.step:e.stagger,r=t.map(a=>{const l=this.lineEl(a)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(a.pts),m=i?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=i?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,i?e.slower:0)}});let h=1;for(let a=1;a{const d=l*n*h;o.set(a.i,{start:d+r[l].lead,dur:r[l].dur,end:d+r[l].tail})}),{plans:o,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.played=!0,this.t0=E();const{plans:s,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=s,this.build(new Set,!0)}build(t,s){const e=this.host.geo(),i=this.host.fig,{P:n}=this.host,r=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const o=i.querySelector(`.${n}-ink`),a=o?.querySelector(`.${n}-svg`);if(!o||!a)return;this.defs=y("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),a.after(this.defs);const l=y("defs",{},this.defs),d=(u,p=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),p.add(u),u);let m=0;for(const u of e.lines){const p=this.plans.get(u.i),f=this.lineEl(u);if(!p||!f)continue;if(m=Math.max(m,p.end),t.has(u.i)){f.removeAttribute("mask");continue}const w=`${this.host.base}-reveal-${u.i}`,k=y("mask",{id:w,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),x=f.querySelector(`.${n}-line`);if(x){const b=x.getTotalLength(),B=y("path",{d:x.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${b} ${b+8}`,"stroke-dashoffset":b},k);d(B.animate([{strokeDashoffset:`${b}px`},{strokeDashoffset:"0px"}],{duration:p.dur,delay:p.start,easing:r.inOut,fill:"both"}))}const S=f.querySelector(`.${n}-tip`);if(S){const b=y("path",{d:S.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:r.slow,delay:p.start+.85*p.dur,easing:r.out,fill:"both"}))}const $=f.querySelector(`.${n}-dot`);if($){const b=y("circle",{cx:$.getAttribute("cx")??0,cy:$.getAttribute("cy")??0,r:Number($.getAttribute("r")??3)+1,fill:"#fff"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:r.fast,delay:p.start,easing:r.out,fill:"both"}))}f.setAttribute("mask",`url(#${w})`)}if(s&&this.host.model().type==="sequence"){const u=getComputedStyle(i),p=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),w=i.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((k,x)=>{const S=w[x]?.querySelector(`.${n}-mlabel`),$=this.plans.get(k.i);S&&$&&p&&f&&d(S.animate([{color:p},{color:f}],{duration:r.slower,delay:$.start-r.base,easing:r.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(i.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.markVisit(),this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,s){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||s.reduce||s.forced||s.print||s.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,s){s.add(t);const e=()=>{s.delete(t)};return t.finished.then(e,e),s===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,s){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),s).finished.then(e=>{e.cancel()})}overlay(t,s,e){const i=this.host.fig.querySelector(`.${this.host.P}-ink`),n=i?.querySelector(`.${this.host.P}-svg`);if(!i||!n)return null;const r=this.host.tokens(),h=v(t,r?.head??8),o=R(h,s),a=y("svg",{class:`${this.host.P}-${e}`,width:o.r-o.l,height:o.b-o.t,viewBox:`${o.l} ${o.t} ${o.r-o.l} ${o.b-o.t}`,"aria-hidden":"true",focusable:"false"});a.style.left=`${o.l}px`,a.style.top=`${o.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(a),{svg:a,d:P(h,t.from===t.to?r?.radiusXs??4:r?.radius??8),pts:h}}visible(t,s){const e=this.host.geo();let i=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const r=(n.box.t+n.box.b)/2,h=s.some((o,a)=>a>0&&Math.abs(o.y-s[a-1].y)<.5&&Math.abs(r-o.y)<1.5);i+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(s)-i}flow(t,s){const e=t.lines.find(o=>o.i===s);if(!e)return;const i=this.host.tokens();if(e.kind==="dashed"){if(this.visible(e,v(e,i?.head??8))<48)return;const o=this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${s}"] .${this.host.P}-line`);if(!o)return;const a=(i?.dash??6)+(i?.dashGap??4);this.track(o.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-a}px`}],{duration:a/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops);return}let n=this.flowEls.get(s);if(n&&!n.isConnected&&(this.flowEls.delete(s),n=void 0),!n){const o=i?.space("1")??4,a=this.overlay({...e,pts:v(e,o)},e.width+2,"flow");if(!a)return;if(this.visible(e,v(e,i?.head??8))<48){a.svg.remove();return}const l=i?.cut??2;y("path",{d:a.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},a.svg),n=a.svg,this.flowEls.set(s,n)}n.style.display="";const r=n.firstElementChild,h=this.t.flowPeriod;this.track(r.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,s){const i=this.host.model().edges.find(n=>n.from===t&&n.to===s);return i?this.host.geo()?.lines.find(n=>n.i===i.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,s){const e=this.host.tokens();for(;t===this.loopGen;){for(let i=1;it===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(s,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const i=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=i;try{await i.finished}finally{this.repeatGap===i&&(this.repeatGap=null),i.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),s=t.motion.packet?.path;if(!t.motion.animated||!s||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(s[s.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const i=++this.runGen;this.packetRun(s,this.runAnims,()=>i===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&i===this.runGen&&(this.waiting=!1,this.send())})}quiet(t,s){const e=this.host.P,i=this.host.fig,n=i.querySelectorAll(`.${e}-msg`);s.forEach((r,h)=>{const o=t>=0&&h>t;n[h]?.toggleAttribute("data-ahead",o),i.querySelector(`.${e}-edge[data-edge="${r.i}"]`)?.toggleAttribute("data-ahead",o)})}stopRun(){this.runGen++,this.runAt=-1,this.host.fig.querySelectorAll("[data-ahead]").forEach(t=>t.removeAttribute("data-ahead"));for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const s=this.host.geo();if(!s?.lines.length)return;for(const o of this.runAnims)o.cancel();this.runAnims.clear();const e=++this.runGen,i=()=>e===this.runGen,n=this.ordered(s),r=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let o=t;o{if(!q(o))throw o})}};function N(t){const s=[],e=[],{pulse:i,packet:n}=t.motion;i&&n&&s.push("a figure names both a pulse and a packet: it has one mover at most");const r=i??n?.path,h=i?"pulse":"packet",o=new Set;if(r){for(const a of r)t.byId.has(a)||s.push(`the ${h} names ${a}, which is not a node`);for(let a=1;ad.from===r[a-1]&&d.to===r[a]);l?o.add(l.i):s.push(`the ${h} goes from ${r[a-1]} to ${r[a]}, and no line joins them in that direction`)}}for(const a of t.edges)a.flow&&(o.has(a.i)&&s.push(`the line from ${a.from} to ${a.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),a.label||e.push(`the line from ${a.from} to ${a.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:s,warnings:e}}function z(t){return new D(t)}(function(t){"use strict";var s=t._;function e(i,n,r){var h=document.createElement("button");return h.type="button",h.className="btn "+i,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),r&&r(h),h.appendChild(document.createTextNode(n)),h}s.diagramMotion=function(i,n,r){var h=N(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var o=z(n),a=i.querySelector(".diagram-foot"),l=null,d=null;a&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){o.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var w=document.createElement("span");w.className="btn-check",w.setAttribute("aria-hidden","true"),f.appendChild(w)}),l.hidden=d.hidden=!0,a.appendChild(l),a.appendChild(d));function m(){var f=o.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=o.subscribe(m);m();var p=r&&r.packet?r.packet.send:void 0;return o.sendValue("__diagramSend"in i?i.__diagramSend:p),o.sendValue(p),i.__diagramSend=p,{redrawn:o.redrawn,sendValue:function(f){o.sendValue(f),i.__diagramSend=f},destroy:function(){u(),o.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.js b/.agent/skills/basalt-html/parts/diagram-zoom.js index d14d8db2..ce5053bc 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.js +++ b/.agent/skills/basalt-html/parts/diagram-zoom.js @@ -1 +1 @@ -(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(v=>v.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:v,layer:p,status:x}=l;let u=0,k=0,i=1,a=1,f=!1,d=!1,g=null,h="",w=0;const S=()=>Number.parseFloat(getComputedStyle(v).paddingTop)||0,T=()=>Math.min(a,1),q=t=>Math.min(j,Math.max(T(),t));function o(){if(!u||!k)return 1;const t=S(),n=e.clientWidth-2*t,b=e.clientHeight-2*t;if(n<=0||b<=0)return Math.min(1,J);const H=Math.min(n/u,b/k);return Math.min(J,Math.floor(H*100+1e-6)/100)}function s(){const t=T();return{zoom:i,level:Math.round(i*100),fit:a,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-a)e.clientWidth-2*S()+.5||k*i>e.clientHeight-2*S()+.5)}function A(){clearTimeout(w);const t=`Zoom ${Math.round(i*100)}%`;w=window.setTimeout(()=>{t!==h&&(h=t,x.textContent=t)},l.rest)}function y(){v.style.width=`${u*i}px`,v.style.height=`${k*i}px`,p.style.transform=`scale(${i})`}function I(t){const n=p.getBoundingClientRect();return{x:(t.x-n.left)/i,y:(t.y-n.top)/i}}function z(t,n){const b=p.getBoundingClientRect();e.scrollLeft+=b.left+t.x*i-n.x,e.scrollTop+=b.top+t.y*i-n.y}const m=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function _(t,n=m(),b){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){M();return}const ot=b??I(n);i=H,y(),z(ot,n),M(),A()}function L(t){f=!0;const n=i*100,b=t?G.find(H=>H>n+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,r=()=>{const[t,n]=[...c.values()];return{x:(t.x+n.x)/2,y:(t.y+n.y)/2}},E=()=>{const[t,n]=[...c.values()];return Math.hypot(t.x-n.x,t.y-n.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),c.size===1&&(O={x:t.clientX,y:t.clientY},C=O,B=!1,F=!1),c.size===2&&t.pointerType==="touch")){const n=r();$={d0:E()||1,z0:i,c:I(n)},F=!0,B=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!c.has(t.pointerId)||d)return;if(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),$&&c.size>=2){f=!0;const b=q($.z0*(E()/$.d0)),H=r();Math.abs(b-i)>1e-6&&(i=b,y(),M(),A()),z($.c,H);return}if(c.size!==1||!O||!C)return;const n={x:t.clientX,y:t.clientY};if(!B){if(Math.hypot(n.x-O.x,n.y-O.y)<=V())return;B=!0,F=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=n.x-C.x,e.scrollTop-=n.y-C.y,C=n,t.preventDefault()}function Z(t){if(c.has(t.pointerId)){if(c.delete(t.pointerId),c.size<2&&($=null),c.size===1){const[n]=[...c.values()];C=n,O=n,B=!0;return}c.size===0&&(B=!1,e.removeAttribute("data-dragging"),O=C=null)}}function P(t){F&&(F=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!u||!k)return;const t=f?I(m()):null;a=o(),f?(i=q(i),y(),t&&z(t,m())):(i=a,y()),M()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:K,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:W,state:s,list(t){t!==d&&(t?(g={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),y(),g&&(e.scrollLeft=g.left,e.scrollTop=g.top),g=null),M())},travelled:()=>F,destroy(){clearTimeout(w),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function nt(l,e,v){const p=l.getBoundingClientRect(),x=e.getBoundingClientRect(),u=p.left+v,k=p.left+l.clientWidth-v,i=p.top+v,a=p.top+l.clientHeight-v;x.leftk&&(l.scrollLeft+=Math.min(x.right-k,x.left-u)),x.topa&&(l.scrollTop+=Math.min(x.bottom-a,x.top-i))}function rt(l,e,v,p,x,u,k,i){const{layer:a,memo:f,measureFigure:d}=i;f.model!==e&&(f.model=e,f.least=void 0);const g=M=>{a.style.width=`${Math.max(f.least||M,Math.min(i.avail,i.row))}px`};a.style.width||(a.style.width=`${Math.min(i.avail,i.row)}px`);const h=a.style.transform;a.style.transform="none";const w=a.offsetWidth?a.getBoundingClientRect().width/a.offsetWidth:1,S=Math.abs(w-1)>1e-4?` scale(${1/w})`:"";a.style.transform=S||"none";const T=(l.querySelector(`.${v}-drawing`)??a).getBoundingClientRect(),q=T.left-Math.round(T.left),o=T.top-Math.round(T.top);(q||o)&&(a.style.transform=`translate(${-q/w}px, ${-o/w}px)${S}`);let s=d(l,e,v,p,x,u,f.least===void 0?void 0:k,g);if(s.dyn.layout==="stacked"&&f.least===void 0&&s.least!==void 0){const M=s.dyn,A=m=>{a.style.width=`${m}px`;const _=d(l,e,v,p,M,u);return _.dyn.layout==="drawn"?d(l,e,v,p,_.dyn,u):_},y=Math.max(s.least,Math.min(i.avail,i.row)),I=Math.max(i.row,y)*1.5;let z;for(let m=y+16;m<=I&&z===void 0;m+=16)A(m).dyn.layout==="drawn"&&(z=m);if(z!==void 0){for(let m=z-15;mi.contain&&(a.style.width=`${i.contain}px`,s=d(l,e,v,p,s.dyn,u,k)),a.style.transform=h,s}(function(l){"use strict";var e=l._,v=0;function p(i){return e.diagramKit.escapeHtml(String(i??""))}function x(i){return''+p(i)+""}function u(i,a){return parseFloat(getComputedStyle(i).getPropertyValue(a))||0}function k(i,a,f,d){var g=e.diagramKit,h=Object.assign({},a,{motion:"still"}),w=g.buildModel(h),S="dgv"+ ++v,T=g.figureKey("diagram",w),q=et(g.hintEntries(w,!0)).map(function(r){return""+r.keys.map(x).join(" ")+" "+p(r.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",S+"-summary"),o.innerHTML='

'+p(w.title)+"

"+(a.source?'

'+p(a.source)+"

":"")+'

'+p(a.summary)+'

'+(T?'
'+g.toHtml(T)+"
":"")+'
',document.body.appendChild(o);var s=o.querySelector(".diagram-stage"),M=o.querySelector(".diagram-sizer"),A=o.querySelector(".diagram-layer"),y=A.firstChild,I=o.querySelector('[role="status"]'),z=o.querySelector(".diagram-level > span"),m=o.querySelector(".diagram-viewer-key"),_=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},W=null,K=!1,R=!1,D=function(r,E){E?r.setAttribute("aria-disabled","true"):r.removeAttribute("aria-disabled")},c=at({stage:s,sizer:M,layer:A,status:I,rest:u(s,"--_rest")||300,onChange:function(r){z.textContent=r.level+"%",D(L.out,r.listOpen||r.atMin),D(L.in,r.listOpen||r.atMax),D(L.fit,r.listOpen||r.atFit)}}),O={},C={layer:A,avail:0,row:1104,contain:480,memo:O,measureFigure:g.measureFigure,keys:tt,measure:function(r,E,Y,N,Z,P,X){return rt(r,E,Y,N,Z,P,X,C)},onMeasured:function(r,E){s.setAttribute("data-layout",r.dyn.layout||""),m&&(m.setAttribute("data-layout",r.dyn.layout||""),m.toggleAttribute("data-bare",!!r.dyn.bare)),R=!!r.dyn.bare,_.hidden=R,F(K||R),c.size(E.offsetWidth,E.offsetHeight)}};function B(){C.avail=Math.max(0,Math.floor(s.clientWidth-2*(parseFloat(getComputedStyle(M).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function F(r){r&&!W&&(W=document.createElement("div"),W.className="diagram-list diagram-viewer-list",W.innerHTML=g.figureList("diagram",w).map(function(E){return g.toHtml(E)}).join(""),s.appendChild(W)),r&&c.list(!0),W&&(W.hidden=!r),M.hidden=r,r||c.list(!1)}_.addEventListener("click",function(){K=!K,_.setAttribute("aria-expanded",String(K)),_.firstElementChild.textContent=K?"Hide the list":"View as list",F(K||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||c.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||c.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||c.fit()}),s.addEventListener("focusin",function(r){var E=r.target.closest&&r.target.closest(".diagram-node");E&&s.contains(E)&&nt(s,E,u(s,"--_clear")||16)}),a.export===!0&&typeof e.diagramExport=="function"&&e.diagramExport(o.querySelector(".diagram-viewer-end"),y),l.openDialog(o,d),B(),g.draw(y,h,!1,C),setTimeout(function(){s.focus({preventScroll:!0})},0);var $=s.clientWidth,V=new ResizeObserver(function(){Math.abs(s.clientWidth-$)<.5||($=s.clientWidth,B(),y.__diagram&&y.__diagram.layout())});V.observe(s),o.addEventListener("transitionend",function(r){r.target===o&&r.propertyName==="transform"&&o.open&&y.__diagram&&y.__diagram.layout()}),i.setAttribute("data-viewing",""),f.animated&&f.settle(),o.addEventListener("close",function(){V.disconnect(),c.destroy(),y.__diagram&&y.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},u(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,a,f){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var g=d.querySelector(".diagram-expand");g&&g.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var w=d.querySelector(".diagram-toggle");w&&w.nextSibling?d.insertBefore(h,w.nextSibling):d.appendChild(h);var S=function(){k(i,a,f,h)};return h.addEventListener("click",S),{destroy:function(){h.removeEventListener("click",S),h.remove()}}}})(window.Basalt)})(); +(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(v=>v.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:v,layer:p,status:k}=l;let u=0,M=0,i=1,n=1,f=!1,d=!1,g=null,h="",w=0;const S=()=>Number.parseFloat(getComputedStyle(v).paddingTop)||0,T=()=>Math.min(n,1),q=t=>Math.min(j,Math.max(T(),t));function o(){if(!u||!M)return 1;const t=S(),r=e.clientWidth-2*t,b=e.clientHeight-2*t;if(r<=0||b<=0)return Math.min(1,J);const H=Math.min(r/u,b/M);return Math.min(J,Math.floor(H*100+1e-6)/100)}function s(){const t=T();return{zoom:i,level:Math.round(i*100),fit:n,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-n)e.clientWidth-2*S()+.5||M*i>e.clientHeight-2*S()+.5)}function A(){clearTimeout(w);const t=`Zoom ${Math.round(i*100)}%`;w=window.setTimeout(()=>{t!==h&&(h=t,k.textContent=t)},l.rest)}function y(){v.style.width=`${u*i}px`,v.style.height=`${M*i}px`,p.style.transform=`scale(${i})`}function I(t){const r=p.getBoundingClientRect();return{x:(t.x-r.left)/i,y:(t.y-r.top)/i}}function z(t,r){const b=p.getBoundingClientRect();e.scrollLeft+=b.left+t.x*i-r.x,e.scrollTop+=b.top+t.y*i-r.y}const m=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function _(t,r=m(),b){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){x();return}const ot=b??I(r);i=H,y(),z(ot,r),x(),A()}function L(t){f=!0;const r=i*100,b=t?G.find(H=>H>r+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,a=()=>{const[t,r]=[...c.values()];return{x:(t.x+r.x)/2,y:(t.y+r.y)/2}},E=()=>{const[t,r]=[...c.values()];return Math.hypot(t.x-r.x,t.y-r.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),c.size===1&&(F={x:t.clientX,y:t.clientY},C=F,O=!1,B=!1),c.size===2&&t.pointerType==="touch")){const r=a();$={d0:E()||1,z0:i,c:I(r)},B=!0,O=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!c.has(t.pointerId)||d)return;if(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),$&&c.size>=2){f=!0;const b=q($.z0*(E()/$.d0)),H=a();Math.abs(b-i)>1e-6&&(i=b,y(),x(),A()),z($.c,H);return}if(c.size!==1||!F||!C)return;const r={x:t.clientX,y:t.clientY};if(!O){if(Math.hypot(r.x-F.x,r.y-F.y)<=V())return;O=!0,B=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=r.x-C.x,e.scrollTop-=r.y-C.y,C=r,t.preventDefault()}function Z(t){if(c.has(t.pointerId)){if(c.delete(t.pointerId),c.size<2&&($=null),c.size===1){const[r]=[...c.values()];C=r,F=r,O=!0;return}c.size===0&&(O=!1,e.removeAttribute("data-dragging"),F=C=null)}}function P(t){B&&(B=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!u||!M)return;const t=f?I(m()):null;n=o(),f?(i=q(i),y(),t&&z(t,m())):(i=n,y()),x()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:K,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:W,state:s,list(t){t!==d&&(t?(g={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),y(),g&&(e.scrollLeft=g.left,e.scrollTop=g.top),g=null),x())},travelled:()=>B,destroy(){clearTimeout(w),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function nt(l,e,v){const p=l.getBoundingClientRect(),k=e.getBoundingClientRect(),u=p.left+v,M=p.left+l.clientWidth-v,i=p.top+v,n=p.top+l.clientHeight-v;k.leftM&&(l.scrollLeft+=Math.min(k.right-M,k.left-u)),k.topn&&(l.scrollTop+=Math.min(k.bottom-n,k.top-i))}function rt(l,e,v,p,k,u,M,i){const{layer:n,memo:f,measureFigure:d}=i;f.model!==e&&(f.model=e,f.least=void 0);const g=x=>{n.style.width=`${Math.max(f.least||x,Math.min(i.avail,i.row))}px`};n.style.width||(n.style.width=`${Math.min(i.avail,i.row)}px`);const h=n.style.transform;n.style.transform="none";const w=n.offsetWidth?n.getBoundingClientRect().width/n.offsetWidth:1,S=Math.abs(w-1)>1e-4?` scale(${1/w})`:"";n.style.transform=S||"none";const T=(l.querySelector(`.${v}-drawing`)??n).getBoundingClientRect(),q=T.left-Math.round(T.left),o=T.top-Math.round(T.top);(q||o)&&(n.style.transform=`translate(${-q/w}px, ${-o/w}px)${S}`);let s=d(l,e,v,p,k,u,f.least===void 0?void 0:M,g);if(s.dyn.layout==="stacked"&&f.least===void 0&&s.least!==void 0){const x=s.dyn,A=m=>{n.style.width=`${m}px`;const _=d(l,e,v,p,x,u);return _.dyn.layout==="drawn"?d(l,e,v,p,_.dyn,u):_},y=Math.max(s.least,Math.min(i.avail,i.row)),I=Math.max(i.row,y)*1.5;let z;for(let m=y+16;m<=I&&z===void 0;m+=16)A(m).dyn.layout==="drawn"&&(z=m);if(z!==void 0){for(let m=z-15;mi.contain&&(n.style.width=`${i.contain}px`,s=d(l,e,v,p,s.dyn,u,M)),n.style.transform=h,s}(function(l){"use strict";var e=l._,v=0;function p(i){return e.diagramKit.escapeHtml(String(i??""))}function k(i){return''+p(i)+""}function u(i,n){return parseFloat(getComputedStyle(i).getPropertyValue(n))||0}function M(i,n,f,d){var g=e.diagramKit,h=Object.assign({},n,{motion:"still"}),w=g.buildModel(h),S="dgv"+ ++v,T=g.figureKey("diagram",w),q=et(g.hintEntries(w,!0)).map(function(a){return""+a.keys.map(k).join(" ")+" "+p(a.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",S+"-summary"),o.innerHTML='

'+p(w.title)+"

"+(n.source?'

'+p(n.source)+"

":"")+'

'+p(n.summary)+'

'+(T?'
'+g.toHtml(T)+"
":"")+'
',document.body.appendChild(o);var s=o.querySelector(".diagram-stage"),x=o.querySelector(".diagram-sizer"),A=o.querySelector(".diagram-layer"),y=A.firstChild,I=o.querySelector('[role="status"]'),z=o.querySelector(".diagram-level > span"),m=o.querySelector(".diagram-viewer-key"),_=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},W=null,K=!1,R=!1,D=function(a,E){E?a.setAttribute("aria-disabled","true"):a.removeAttribute("aria-disabled")},c=at({stage:s,sizer:x,layer:A,status:I,rest:u(s,"--_rest")||300,onChange:function(a){z.textContent=a.level+"%",D(L.out,a.listOpen||a.atMin),D(L.in,a.listOpen||a.atMax),D(L.fit,a.listOpen||a.atFit)}}),F={},C={layer:A,avail:0,row:1104,contain:480,memo:F,measureFigure:g.measureFigure,keys:tt,room:function(){var a=parseFloat(getComputedStyle(x).paddingTop)||0;return{w:s.clientWidth-2*a,h:s.clientHeight-2*a}},measure:function(a,E,Y,N,Z,P,X){return rt(a,E,Y,N,Z,P,X,C)},onMeasured:function(a,E){s.setAttribute("data-layout",a.dyn.layout||""),m&&(m.setAttribute("data-layout",a.dyn.layout||""),m.toggleAttribute("data-bare",!!a.dyn.bare)),R=!!a.dyn.bare,_.hidden=R,B(K||R),c.size(E.offsetWidth,E.offsetHeight)}};function O(){C.avail=Math.max(0,Math.floor(s.clientWidth-2*(parseFloat(getComputedStyle(x).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function B(a){a&&!W&&(W=document.createElement("div"),W.className="diagram-list diagram-viewer-list",W.innerHTML=g.figureList("diagram",w).map(function(E){return g.toHtml(E)}).join(""),s.appendChild(W)),a&&c.list(!0),W&&(W.hidden=!a),x.hidden=a,a||c.list(!1)}_.addEventListener("click",function(){K=!K,_.setAttribute("aria-expanded",String(K)),_.firstElementChild.textContent=K?"Hide the list":"View as list",B(K||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||c.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||c.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||c.fit()}),s.addEventListener("focusin",function(a){var E=a.target.closest&&a.target.closest(".diagram-node");E&&s.contains(E)&&nt(s,E,u(s,"--_clear")||16)}),n.export===!0&&typeof e.diagramExport=="function"&&e.diagramExport(o.querySelector(".diagram-viewer-end"),y),l.openDialog(o,d),O(),g.draw(y,h,!1,C),setTimeout(function(){s.focus({preventScroll:!0})},0);var $=s.clientWidth,V=new ResizeObserver(function(){Math.abs(s.clientWidth-$)<.5||($=s.clientWidth,O(),y.__diagram&&y.__diagram.layout())});V.observe(s),o.addEventListener("transitionend",function(a){a.target===o&&a.propertyName==="transform"&&o.open&&y.__diagram&&y.__diagram.layout()}),i.setAttribute("data-viewing",""),f.animated&&f.settle(),o.addEventListener("close",function(){V.disconnect(),c.destroy(),y.__diagram&&y.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},u(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,n,f){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var g=d.querySelector(".diagram-expand");g&&g.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var w=d.querySelector(".diagram-toggle");w&&w.nextSibling?d.insertBefore(h,w.nextSibling):d.appendChild(h);var S=function(){M(i,n,f,h)};return h.addEventListener("click",S),{destroy:function(){h.removeEventListener("click",S),h.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index a3ee3c4c..61a2ed1c 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index cc334f2e..d137f230 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,12 +1,12 @@ -(()=>{var Re=["top","right","bottom","left"],We=["main","plain","dashed"],Ne=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Mt(t,e={}){const a=e.checks!==!1,i=[],r=m=>{i.push(m)},o=t.legend??{},s={};for(const m of["main","plain","dashed","focal","group","activation"]){const b=at(o[m]);b&&(s[m]=b)}const c=t.stepLabel,u=typeof c=="function"?m=>String(c(m)):typeof c=="string"?(m=>c.replace("{n}",String(m))):m=>`Step ${m}`,y=t.shapeLabels??{},p={terminal:at(y.terminal)??"Start or end",step:at(y.step)??"Step",decision:at(y.decision)??"Decision"},l=t.heading===void 0?3:Ne.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),g=(m,b)=>m==null?"plain":We.includes(m)?m:(r(`"${String(m)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),x=m=>{if(m!=null){if(Re.includes(m))return m;r(`"${String(m)}" is not a side (top, right, bottom or left): the derived side is used`)}},d=(m,b)=>typeof m=="number"&&Number.isInteger(m)&&m>=1?m:(t.layout==="auto"&&m==null||r(`${b} is ${JSON.stringify(m)}, not a whole number from 1: it is placed at 1`),1),f=[],S=[];let B=[];const C=[],E=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||r(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const m of t.nodes??[]){const b=A==="flowchart"&&m.shape==="decision"?"decision":A==="flowchart"&&m.shape==="terminal"?"terminal":"box",h=String(m.id??""),k=d(m.row,`the row of ${h}`);f.push({id:h,i:f.length,name:String(m.name??""),kind:b==="decision"?void 0:at(m.kind),detail:b==="decision"?void 0:at(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:d(m.col,`the column of ${h}`),row:k,row2:k,branch:!!m.branch,shape:b,group:A==="architecture"?at(m.group):void 0,mark:A==="architecture"?Bt(m.mark):void 0})}if(A==="architecture"){const m=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:at($.parent)})),b=new Map(m.map($=>[$.id,$])),h=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(r(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(r(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(r(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},k=m.map(h);m.forEach(($,w)=>C.push({...$,depth:k[w],members:f.filter(_=>_.group===$.id).map(_=>_.id),all:[]}));for(const $ of C)$.all=[...$.members,...C.filter(w=>w.parent===$.id).flatMap(w=>w.members)];C.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){B=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const m=new Map(B.map((b,h)=>[b.id,h+1]));for(const b of t.nodes??[]){const h=String(b.id??""),k=String(b.lane??""),$=m.get(k);$===void 0&&r(`a node (${h}) names the lane "${k}", which is not in lanes`);const w=f.length+1;f.push({id:h,i:f.length,name:String(b.name??""),kind:u(w),detail:at(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:d(b.col,`the column of ${h}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:B[($??1)-1]?.label??k,step:w,mark:Bt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((k,$)=>{const w=String(k.name??"");f.push({id:String(k.id??""),i:$,name:w,kind:at(k.kind),mono:!1,focal:!!k.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:at(k.short)??w,mark:Bt(k.mark)})});let m=0;const b=new Map(f.map(k=>[k.id,k.col])),h=(k,$)=>{let w=1/0,_=-1/0;for(const q of k??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&r(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),E.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){r("a frame is a third level: frames nest two deep");continue}const st=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=st==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];st==="alt"&&V.length<2&&r("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&r(`the frame label "${P}" is over 40 characters`);const U=E.length;E.push({open:st,label:P,depth:$+1,a:0,b:0}),V.forEach((et,rt)=>{if(rt){const xt=String(et.label??"");xt.length>40&&r(`the frame label "${xt}" is over 40 characters`),E.push({otherwise:xt,depth:$+1})}et.steps?.length||r(`a frame or branch ("${String(et.label??"")}") is empty`);const[ct,At]=h(et.steps??[],$+1);w=Math.min(w,ct),_=Math.max(_,At);const bt=E[U];bt.a=Math.min(bt.a||1/0,ct),bt.b=Math.max(bt.b,At)}),E.push({close:$+1});continue}m++;const R=String(q.label??"");R.includes(` -`)&&r(`message ${m}'s label has a break: a message's second line is its note`);const Q=String(q.from??""),X=String(q.to??"");E.push({n:m,from:Q,to:X,label:gt(R),note:at(q.note),kind:g(q.kind,`message ${m}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const z=b.get(Q)??1,D=b.get(X)??1,tt=z===D?z===f.length?z-1:z+1:z;w=Math.min(w,z,D,tt),_=Math.max(_,z,D,tt)}return[w,_]};h(t.steps??[],0);for(const k of E)"open"in k&&!Number.isFinite(k.a)&&(k.a=1,k.b=Math.max(1,f.length))}else if(A==="schema")for(const m of t.tables??[]){const b=String(m.name??""),[h,k]=Array.isArray(m.row)?m.row:[m.row,m.row],$=d(h,`the row of ${b}`),w=Math.max($,d(k,`the last row of ${b}`)),_=m.more===void 0||m.more===null?void 0:Number.isInteger(m.more)&&m.more>0?m.more:(r(`${b}'s "more" is ${JSON.stringify(m.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:b,i:f.length,name:b,mono:!0,focal:!!m.focal,col:d(m.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:_,columns:(m.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&r(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const m=A==="schema"?t.tables:t.nodes;a&&(m??[]).some(h=>h&&(h.col!==void 0||h.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(T=!0);for(const h of f){const k=b?.[h.id];h.col=k?.col??1,h.row=h.row2=k?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((m,b)=>{if(!m||m.href===void 0||m.href===null)return;const h=String(m.href);if(A==="sequence"){r(`${f[b]?.id}: a participant cannot be a link (href)`);return}if(!h){r(`${f[b]?.id}'s href is empty`);return}const k=f[b];k&&(k.href=h,k.blank=m.target==="_blank")});const j=new Map;for(const m of f)m.id?j.has(m.id)&&r(`the id "${m.id}" is used twice`):r("a node has no id"),j.set(m.id,m);if(A==="schema")(t.tables??[]).forEach(m=>(m.columns??[]).forEach((b,h)=>{const k=at(b.references);if(!k)return;const[$,w]=k.split("."),_=j.get($??""),q=_?.columns?.findIndex(Q=>Q.name===w)??-1;if(!_||q<0){r(`${String(m.name)}.${String(b.name)} references ${k}, which is not a shown column`);return}const R=j.get(String(m.name??""));R.columns[h].ref={table:$,column:w,row:q},S.push({i:S.length,from:R.id,to:$,kind:"plain",fromRow:h,toRow:q,fk:!0})}));else if(A!=="sequence")for(const m of t.edges??[]){const b=String(m.from??""),h=String(m.to??"");if(!j.has(b)||!j.has(h)){r(`a line names ${j.has(b)?h:b}, which is not a node`);continue}const k=at(m.label),$=k?.split(` -`)??[];$.length>2&&r(`the label "${gt(k)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>Jt)&&r(`a line of the label "${gt(k)}" is over ${Jt} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:h,kind:g(m.kind,`the line from ${b} to ${h}`),label:k,fromSide:x(m.fromSide),toSide:x(m.toSide),flow:A!=="flowchart"&&m.flow===!0?!0:void 0})}else for(const m of E)"n"in m&&(!j.has(m.from)||!j.has(m.to))&&r(`message ${m.n} names ${j.has(m.from)?m.to:m.from}, which is not a participant`);if(a&&A!=="sequence"&&!T){const m=new Map;for(const b of f)for(let h=b.row;h<=b.row2;h++){const k=`${b.col}:${h}`;m.has(k)&&r(`${b.id} and ${m.get(k)} share the cell at column ${b.col}, row ${h}`),m.set(k,b.id)}}if(a&&!T){for(const b of C){const h=b.all.map(w=>j.get(w));if(!h.length)continue;const k={c1:Math.min(...h.map(w=>w.col)),c2:Math.max(...h.map(w=>w.col)),r1:Math.min(...h.map(w=>w.row)),r2:Math.max(...h.map(w=>w.row2))};for(const w of f)!b.all.includes(w.id)&&w.col>=k.c1&&w.col<=k.c2&&w.row>=k.r1&&w.row<=k.r2&&r(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=h.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&r(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of f)b.group&&!C.some(h=>h.id===b.group)&&r(`${b.id} names the group "${b.group}", which is not in groups`);f.filter(b=>b.focal).length>1&&r("more than one node is focal: a diagram has one at most");const m=new Set(A==="sequence"?E.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));m.has("main")&&!s.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),m.has("dashed")&&!s.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(b=>b.focal)&&!s.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const ot=A==="architecture"||A==="data-flow",L=m=>Array.isArray(m)&&m.length>1?m.map(String):void 0,F=ot&&t.packet&&typeof t.packet=="object"?t.packet:void 0,I=F&&L(F.path),M={animated:t.motion==="animated",pulse:ot?L(t.pulse):void 0,packet:I?{path:I,repeat:F.repeat===!0,send:F.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(a)for(const m of f){const b=m.mark?.says;if(!b?.length)continue;const h=[m.name,m.kind,m.detail,m.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(k=>h.includes(k.toLowerCase()))||r(`${m.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const m=new Map,b=new Map;for(const h of E)"n"in h&&(b.set(h.from,h.n),b.set(h.to,h.n));for(const h of E)if("n"in h){if(h.activate){const k=m.get(h.to)??[];if(k.length>=3)r(`message ${h.n} opens a fourth bar on ${h.to}: three deep at most`);else{const $={who:h.to,from:h.n,to:h.n,depth:k.length+1};k.push($),O.push($),m.set(h.to,k)}}if(h.deactivate){const $=m.get(h.from)?.pop();$?$.to=h.n:r(`message ${h.n} closes a bar on ${h.from}, which has none open`)}}for(const[h,k]of m)for(const $ of k)$.to=Math.max($.from,b.get(h)??$.from)}const N=t.frameLabels??{},G={opt:at(N.opt)??"Only if",loop:at(N.loop)??"Repeats",alt:at(N.alt)??"One of these",else:at(N.else)??"Otherwise"};let W=Math.max(1,...f.map(m=>m.col));if(e.rtl){for(const b of f)b.col=W-b.col+1;const m=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=m(b.fromSide),b.toSide=m(b.toSide);for(const b of E)if("open"in b){const[h,k]=[W-b.b+1,W-b.a+1];b.a=h,b.b=k}W=Math.max(1,...f.map(b=>b.col))}const Y=A==="data-flow"?Math.max(1,B.length):Math.max(1,...f.map(m=>m.row2)),K={type:A,title:String(t.title??""),heading:l,legend:s,nodes:f,byId:j,edges:S,groups:C,lanes:B,steps:E,bars:O,frameWords:G,cols:W,rows:Y,shapeLabels:p,stepWord:u,warnings:i,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0,text:A==="sequence"&&t.variant==="text"||void 0};return t.layout==="auto"&&!T&&A!=="schema"&&ze(K),a&&f.length>1&&!It(K)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function ze(t){const e=new Set(t.nodes.map(o=>`${o.col},${o.row}`)),n=(o,s)=>{const c=[];for(let u=Math.min(o,s)+1;u{const s=t.byId.get(o.from),c=t.byId.get(o.to),u=c.col>s.col?"right":"left",y=c.row>s.row?"bottom":"top",p=c.col>s.col?"left":"right",l=c.row>s.row?"top":"bottom",g=(d,f,S,B)=>n(d,f).map(C=>B?[C,S]:[S,C]);let x;return s.row===c.row?x=[{sides:[u,p],cells:g(s.col,c.col,s.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:s.col===c.col?x=[{sides:[y,l],cells:g(s.row,c.row,s.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:x=[{sides:[u,l],cells:[...g(s.col,c.col,s.row,!0),[c.col,s.row],...g(s.row,c.row,c.col,!1)]},{sides:[y,p],cells:[...g(s.row,c.row,s.col,!1),[s.col,c.row],...g(s.col,c.col,c.row,!0)]},{sides:[u,p],cells:g(s.col,c.col,s.row,!0)},{sides:[y,l],cells:g(s.row,c.row,s.col,!1)}],x.filter(d=>d.cells.every(([f,S])=>!e.has(`${f},${S}`)))},i=new Map,r=t.edges.map((o,s)=>s).sort((o,s)=>a(t.edges[o]).length-a(t.edges[s]).length||+(t.edges[s].kind==="main")-+(t.edges[o].kind==="main")||o-s);for(const o of r){const s=t.edges[o];if(s.fromSide||s.toSide)continue;const c=a(s).find(u=>(i.get(`${s.from}.${u.sides[0]}`)??0)<3&&(i.get(`${s.to}.${u.sides[1]}`)??0)<3);if(c){for(const[u,y]of[[s.from,c.sides[0]],[s.to,c.sides[1]]])i.set(`${u}.${y}`,(i.get(`${u}.${y}`)??0)+1);s.fromSide=c.sides[0],s.toSide=c.sides[1]}}}function Bt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Ut=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function $t(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Jt=28,Tt=t=>t.includes(` -`)?2:1,gt=t=>t.replace(/\n/g," "),wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Xt(t,e){return t.legend[e]}function Fe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function He(t,e){return $t(t,`sentence:${e.i}`,()=>De(t,e))}function De(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const a=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name})`);a.length&&n.push(`References ${a.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const a=t.steps.filter(o=>"n"in o&&o.from===e.id).length,i=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${a} ${a===1?"message":"messages"} and receives ${i}.`);const r=Yt(t,e);r&&n.push(r.trim())}else{const a=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Fe(t,e):e.kind;if(n.push(wt(a?`${e.name}, ${a}`:e.name)),e.detail&&n.push(wt(e.detail)),e.group){const o=t.groups.find(c=>c.id===e.group),s=o?.parent?t.groups.find(c=>c.id===o.parent):void 0;o&&n.push(s?`In ${o.label}, in ${s.label}.`:`In ${o.label}.`)}const i=t.edges.filter(o=>o.to===e.id).map(o=>`${t.byId.get(o.from).name}${o.label?` (${gt(o.label)})`:""}`),r=t.edges.filter(o=>o.from===e.id).map(o=>`${t.byId.get(o.to).name}${o.label?` (${gt(o.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(wt(t.legend.focal)),n.join(" ")}function Yt(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function Ge(t,e,n,a){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),o=n.target;if(!r||!o||!r.contains(o)||!t.querySelector(`.${e}-edge`))return;const s=o.closest(`.${e}-node`);if(!s?.hasAttribute("href"))return s?s.dataset.node===a?null:s.dataset.node??null:null}function Qt(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const a=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&a.push(i);return{t,a:e??{},c:a}}var Ke={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>Ke[e]),Ve=" br img input meta link hr path polygon polyline circle rect line ";function Rt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[a,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(a))throw new Error(`diagram: "${a}" is not an attribute name`);n+=i===!0?` ${a}`:` ${a}="${it(String(i))}"`}return Ve.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(a=>Rt(a,e)).join("")}`}var Ze=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function Ue(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Lt(t,e){const n=e.all.map(a=>t.byId.get(a));return n.length?{c1:Math.min(...n.map(a=>a.col)),c2:Math.max(...n.map(a=>a.col)),r1:Math.min(...n.map(a=>a.row)),r2:Math.max(...n.map(a=>a.row2))}:null}function Pt(t){return $t(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const a=Lt(t,n);if(!a)continue;[a.r1===1,a.c2===t.cols,a.r2===t.rows,a.c1===1].forEach((r,o)=>{r&&(e[o]=Math.max(e[o],te(t,n,o)))})}return e})}function te(t,e,n){const a=Lt(t,e);return t.groups.filter(o=>o.parent===e.id).some(o=>{const s=Lt(t,o);return s&&[s.r1===a.r1,s.c2===a.c2,s.r2===a.r2,s.c1===a.c1][n]})?2:1}function ee(t){const e=Pt(t);return e[1]+e[3]}function Wt(t){return t.type==="sequence"?t.nodes.length:t.cols}function ne(t){return $t(t,"plan",()=>Je(t))}function Je(t){const e=t.nodes,n=d=>t.type==="data-flow"||!e[d].branch,a=t.edges.map(d=>{const f=t.byId.get(d.from).i,S=t.byId.get(d.to).i,C=e.slice(Math.min(f,S)+1,Math.max(f,S)).every(E=>!n(E.i));return S===f+1&&!(n(f)&&!n(S))?"down":S===f-1?"up":S>f&&n(f)&&!n(S)&&C?"trunk":S>f&&n(f)&&n(S)&&C?"rail":S>f?"end-down":"end-up"}),i=t.edges.map((d,f)=>({e:d,k:f})).filter(({k:d})=>a[d]==="end-down"||a[d]==="end-up"),r=d=>{const f=t.byId.get(d.from).i,S=t.byId.get(d.to).i;return[Math.min(f,S),Math.max(f,S)]},o=(d,f)=>{const[S,B]=r(d),[C,E]=r(f);return S{const f=t.byId.get(d.from).i,[S,B]=r(d);return!n(f)&&e.slice(S+1,B).every(C=>!n(C.i))&&i.every(C=>C.e===d||!o(C.e,d))}),c=i.length>0&&(t.type==="data-flow"||!s),u=d=>{const[f,S]=r(d);return S-f},y=t.edges.map(()=>0);let p=!1;const l=[];for(const d of[...i].sort((f,S)=>u(f.e)-u(S.e)||f.k-S.k)){let f=0;for(const S of l)o(S.e,d.e)&&(f=Math.max(f,y[S.k]+1));y[d.k]=f,f>1&&(p=!0),l.push(d)}const g=t.edges.map(()=>.5);for(const d of e){const f=i.filter(({e:C})=>C.from===d.id);if(f.length<2)continue;const S=f.filter(({k:C})=>a[C]==="end-down").sort((C,E)=>u(E.e)-u(C.e)||C.k-E.k);[...f.filter(({k:C})=>a[C]==="end-up").sort((C,E)=>u(C.e)-u(E.e)||E.k-C.k),...S].forEach(({k:C},E,A)=>{g[C]=A.length===2?E===0?1/3:2/3:(E+1)/(A.length+1)})}const x=ht();for(let d=1;d{const j=a[Z],ot=t.byId.get(T.from).i,L=t.byId.get(T.to).i,F=L===d&&(j==="down"||j==="trunk"||j==="rail"||j==="end-down"),I=ot===d&&L===d-1&&j==="up",M=L===d-1&&j==="end-up";F&&(j==="trunk"||j==="end-down")&&(E=!0),M&&(A=!0),(F||I||M)&&T.label&&(B++,C=Math.max(C,j==="trunk"?40:48))}),(B>1||E&&A)&&(C=64),x[f.id]=C}return{routes:a,gutter:c,lanes:y,exits:g,gaps:x,third:p}}var vt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function oe(t,e){const n=e==="fk"?"plain":e,a=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...vt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:a,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${a}H${r}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${a-4}L${i} ${a}L${i-8} ${a+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${a}L${i-8} ${a-4}L${i-8} ${a+4}Z`}))}function St(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...vt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function se(t,e){return $t(e,`key:${t}`,()=>Ye(t,e))}var Xe=se;function Ye(t,e){const n=[],a=(o,s,c={})=>n.push(v("li",{class:`${t}-entry`,...c},o,v("span",null,s)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(s=>(s.columns??[]).map(c=>c.key)));for(const[s,c]of[["PK","Primary key"],["FK","Foreign key"]])o.has(s)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},s),v("span",null,c)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(s=>s.shape));o.has("terminal")&&a(St(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&a(St(t,"box"),e.shapeLabels.step),o.has("decision")&&a(St(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind)),r=(o,s)=>v("span",{class:`${t}-key-glyph`,"data-ink":s,"aria-hidden":"true"},o);for(const o of["main","plain","dashed"]){const s=e.legend[o];i.has(o)&&s&&a(e.text?r(o==="main"?"━━▶":o==="dashed"?"┄┄▷":"──▶",o==="main"?"main":"plain"):oe(t,o),s,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length&&(a(oe(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&a(e.text?r("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...vt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const o=new Set(e.steps.flatMap(s=>"open"in s?[s.open]:[]));for(const s of["opt","loop","alt"])o.has(s)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},s),v("span",null,e.frameWords[s])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&a(St(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&a(St(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Qe(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...vt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Nt(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function Pe(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},Nt(t,n)))];const a=[];return e.type==="data-flow"?a.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&a.push(v("span",{class:`${t}-kind`},n.kind)),a.push(v("span",{class:`${t}-name`},Nt(t,n))),n.detail&&a.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?_t(n.detail).flatMap((i,r)=>[r?" ":"",v("span",{class:`${t}-run`},i)]):n.detail)),a}function tn(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},Nt(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((a,i)=>v("span",{class:`${t}-row`,"data-row":i,"data-key":a.key},v("span",{class:`${t}-keyseat`},a.key??""),v("span",{class:`${t}-cname`},a.name),a.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${a.ref.table}`):a.type?v("span",{class:`${t}-ctype`},a.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var ae=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function qt(t,e,n,a){const{P:i}=t,r=Ue(e,a)||a.keep===n.id,o=mt(e,a),s=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&s.push(`--_lc:${n.col+1}`),e.type==="sequence"&&s.push(`--_c2:${n.col+1}`);const c=t.plan;if(c&&n.i>0){const l=yt(c.gaps,n.id)??32,g=yt(a.grow,n.id)??0;s.push(`--_gap:${g?`calc(${ae(l)} + var(--basalt-space-4) * ${g})`:ae(l)}`)}const u=yt(a.heights,n.id);u&&s.push(`--_h:${u}px`);const y=yt(a.words,n.id);y&&s.push(`--_ww:${y}px`);const p=o?a.stop===n.id?0:-1:a.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:s.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?He(e,n):void 0,tabindex:p},n.shape==="decision"?v("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Ut(n.mark.onLight)};--_md:${Ut(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?tn(i,n,e):Pe(i,e,n))}function en(t,e,n){const{P:a}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((c,u)=>v("div",{class:`${a}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},v("span",{class:`${a}-lane-name`},c.label)))),e.type==="architecture")for(const c of e.groups){const u=Lt(e,c);if(!u)continue;const y=[0,1,2,3].map(p=>te(e,c,p));i.push(v("div",{class:`${a}-gbox`,"data-group":c.id,"data-depth":c.depth>1?c.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${y[0]>1?";--_gt:2":""}${y[1]>1?";--_ge:2":""}${y[2]>1?";--_gb:2":""}${y[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${a}-glabel`},c.label)))}if(e.text)return[v("pre",{class:`${a}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${a}-text-ink`},nn(a,e)))];if(e.type==="sequence")return i.push(v("ul",{class:`${a}-cast`},e.nodes.map(c=>v("li",{class:`${a}-actor`,style:e.rtl?`--_ac:${c.col}`:void 0},qt(t,e,c,n))))),i.push(on(t,e)),i;const r=c=>{const u=c.group?e.groups.find(y=>y.id===c.group):void 0;return u?.parent?e.groups.find(y=>y.id===u.parent):u},o=(c,u,y)=>{const p=t.plan?yt(n.grow,u[0].id)??0:0;return v("div",{class:`${a}-group`,"data-group":c.id,"data-depth":c.depth>1?c.depth:void 0,style:p?`--_ggrow:${p}`:void 0},v("span",{class:`${a}-glabel`,"aria-hidden":"true"},c.label),y)};let s=0;for(;sd.id===y[l].group):void 0;if(!g){p.push(qt(t,e,y[l],n)),l++;continue}const x=[];for(;lqt(t,e,d,n))))}i.push(o(u,y,p))}return i}function nn(t,e){const n=[],a=o=>v("span",{class:`${t}-tx-name`},o),i=o=>o==="main"?"━▶":o==="dashed"?"┄▷":"─▶";n.push(v("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((o,s)=>[s?" · ":"",a(o.name)])),` -`);let r=0;for(const o of e.steps){const s=" ".repeat(r);if("band"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"band"},`${s}── ${o.band} ──`),` -`);continue}if("open"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},s,v("span",{"data-ink":"op"},`[${o.open}]`),` ${o.label}`),` +(()=>{var Ge=["top","right","bottom","left"],Ke=["main","plain","dashed"],Ve=[2,3,4,5,6],st=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function $t(t,e={}){const s=e.checks!==!1,i=[],r=m=>{i.push(m)},o=t.legend??{},a={};for(const m of["main","plain","dashed","focal","group","activation"]){const b=st(o[m]);b&&(a[m]=b)}const c=t.stepLabel,u=typeof c=="function"?m=>String(c(m)):typeof c=="string"?(m=>c.replace("{n}",String(m))):m=>`Step ${m}`,y=t.shapeLabels??{},g={terminal:st(y.terminal)??"Start or end",step:st(y.step)??"Step",decision:st(y.decision)??"Decision"},l=t.heading===void 0?3:Ve.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),p=(m,b)=>m==null?"plain":Ke.includes(m)?m:(r(`"${String(m)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),x=m=>{if(m!=null){if(Ge.includes(m))return m;r(`"${String(m)}" is not a side (top, right, bottom or left): the derived side is used`)}},d=(m,b)=>typeof m=="number"&&Number.isInteger(m)&&m>=1?m:(t.layout==="auto"&&m==null||r(`${b} is ${JSON.stringify(m)}, not a whole number from 1: it is placed at 1`),1),f=[],S=[];let T=[];const C=[],E=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||r(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const m of t.nodes??[]){const b=A==="flowchart"&&m.shape==="decision"?"decision":A==="flowchart"&&m.shape==="terminal"?"terminal":"box",h=String(m.id??""),k=d(m.row,`the row of ${h}`);f.push({id:h,i:f.length,name:String(m.name??""),kind:b==="decision"?void 0:st(m.kind),detail:b==="decision"?void 0:st(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:d(m.col,`the column of ${h}`),row:k,row2:k,branch:!!m.branch,shape:b,group:A==="architecture"?st(m.group):void 0,mark:A==="architecture"?Rt(m.mark):void 0})}if(A==="architecture"){const m=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:st($.parent)})),b=new Map(m.map($=>[$.id,$])),h=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(r(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(r(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(r(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},k=m.map(h);m.forEach(($,w)=>C.push({...$,depth:k[w],members:f.filter(_=>_.group===$.id).map(_=>_.id),all:[]}));for(const $ of C)$.all=[...$.members,...C.filter(w=>w.parent===$.id).flatMap(w=>w.members)];C.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){T=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const m=new Map(T.map((b,h)=>[b.id,h+1]));for(const b of t.nodes??[]){const h=String(b.id??""),k=String(b.lane??""),$=m.get(k);$===void 0&&r(`a node (${h}) names the lane "${k}", which is not in lanes`);const w=f.length+1;f.push({id:h,i:f.length,name:String(b.name??""),kind:u(w),detail:st(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:d(b.col,`the column of ${h}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:T[($??1)-1]?.label??k,step:w,mark:Rt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((k,$)=>{const w=String(k.name??"");f.push({id:String(k.id??""),i:$,name:w,kind:st(k.kind),mono:!1,focal:!!k.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:st(k.short)??w,mark:Rt(k.mark)})});let m=0;const b=new Map(f.map(k=>[k.id,k.col])),h=(k,$)=>{let w=1/0,_=-1/0;for(const q of k??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&r(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),E.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){r("a frame is a third level: frames nest two deep");continue}const at=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=at==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];at==="alt"&&V.length<2&&r("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&r(`the frame label "${P}" is over 40 characters`);const U=E.length;E.push({open:at,label:P,depth:$+1,a:0,b:0}),V.forEach((et,rt)=>{if(rt){const kt=String(et.label??"");kt.length>40&&r(`the frame label "${kt}" is over 40 characters`),E.push({otherwise:kt,depth:$+1})}et.steps?.length||r(`a frame or branch ("${String(et.label??"")}") is empty`);const[ct,Lt]=h(et.steps??[],$+1);w=Math.min(w,ct),_=Math.max(_,Lt);const bt=E[U];bt.a=Math.min(bt.a||1/0,ct),bt.b=Math.max(bt.b,Lt)}),E.push({close:$+1});continue}m++;const R=String(q.label??"");R.includes(` +`)&&r(`message ${m}'s label has a break: a message's second line is its note`);const Q=String(q.from??""),X=String(q.to??"");E.push({n:m,from:Q,to:X,label:gt(R),note:st(q.note),kind:p(q.kind,`message ${m}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const z=b.get(Q)??1,D=b.get(X)??1,tt=z===D?z===f.length?z-1:z+1:z;w=Math.min(w,z,D,tt),_=Math.max(_,z,D,tt)}return[w,_]};h(t.steps??[],0);for(const k of E)"open"in k&&!Number.isFinite(k.a)&&(k.a=1,k.b=Math.max(1,f.length))}else if(A==="schema")for(const m of t.tables??[]){const b=String(m.name??""),[h,k]=Array.isArray(m.row)?m.row:[m.row,m.row],$=d(h,`the row of ${b}`),w=Math.max($,d(k,`the last row of ${b}`)),_=m.more===void 0||m.more===null?void 0:Number.isInteger(m.more)&&m.more>0?m.more:(r(`${b}'s "more" is ${JSON.stringify(m.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:b,i:f.length,name:b,mono:!0,focal:!!m.focal,col:d(m.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:_,columns:(m.columns??[]).map(q=>({name:String(q.name??""),type:st(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&r(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let j=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const m=A==="schema"?t.tables:t.nodes;s&&(m??[]).some(h=>h&&(h.col!==void 0||h.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(j=!0);for(const h of f){const k=b?.[h.id];h.col=k?.col??1,h.row=h.row2=k?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((m,b)=>{if(!m||m.href===void 0||m.href===null)return;const h=String(m.href);if(A==="sequence"){r(`${f[b]?.id}: a participant cannot be a link (href)`);return}if(!h){r(`${f[b]?.id}'s href is empty`);return}const k=f[b];k&&(k.href=h,k.blank=m.target==="_blank")});const B=new Map;for(const m of f)m.id?B.has(m.id)&&r(`the id "${m.id}" is used twice`):r("a node has no id"),B.set(m.id,m);if(A==="schema")(t.tables??[]).forEach(m=>(m.columns??[]).forEach((b,h)=>{const k=st(b.references);if(!k)return;const[$,w]=k.split("."),_=B.get($??""),q=_?.columns?.findIndex(Q=>Q.name===w)??-1;if(!_||q<0){r(`${String(m.name)}.${String(b.name)} references ${k}, which is not a shown column`);return}const R=B.get(String(m.name??""));R.columns[h].ref={table:$,column:w,row:q},S.push({i:S.length,from:R.id,to:$,kind:"plain",fromRow:h,toRow:q,fk:!0})}));else if(A!=="sequence")for(const m of t.edges??[]){const b=String(m.from??""),h=String(m.to??"");if(!B.has(b)||!B.has(h)){r(`a line names ${B.has(b)?h:b}, which is not a node`);continue}const k=st(m.label),$=k?.split(` +`)??[];$.length>2&&r(`the label "${gt(k)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>Qt)&&r(`a line of the label "${gt(k)}" is over ${Qt} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:h,kind:p(m.kind,`the line from ${b} to ${h}`),label:k,fromSide:x(m.fromSide),toSide:x(m.toSide),flow:A!=="flowchart"&&m.flow===!0?!0:void 0})}else for(const m of E)"n"in m&&(!B.has(m.from)||!B.has(m.to))&&r(`message ${m.n} names ${B.has(m.from)?m.to:m.from}, which is not a participant`);if(s&&A!=="sequence"&&!j){const m=new Map;for(const b of f)for(let h=b.row;h<=b.row2;h++){const k=`${b.col}:${h}`;m.has(k)&&r(`${b.id} and ${m.get(k)} share the cell at column ${b.col}, row ${h}`),m.set(k,b.id)}}if(s&&!j){for(const b of C){const h=b.all.map(w=>B.get(w));if(!h.length)continue;const k={c1:Math.min(...h.map(w=>w.col)),c2:Math.max(...h.map(w=>w.col)),r1:Math.min(...h.map(w=>w.row)),r2:Math.max(...h.map(w=>w.row2))};for(const w of f)!b.all.includes(w.id)&&w.col>=k.c1&&w.col<=k.c2&&w.row>=k.r1&&w.row<=k.r2&&r(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=h.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&r(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of f)b.group&&!C.some(h=>h.id===b.group)&&r(`${b.id} names the group "${b.group}", which is not in groups`);f.filter(b=>b.focal).length>1&&r("more than one node is focal: a diagram has one at most");const m=new Set(A==="sequence"?E.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));m.has("main")&&!a.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),m.has("dashed")&&!a.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(b=>b.focal)&&!a.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const ot=A==="architecture"||A==="data-flow",L=m=>Array.isArray(m)&&m.length>1?m.map(String):void 0,F=ot&&t.packet&&typeof t.packet=="object"?t.packet:void 0,I=F&&L(F.path),M={animated:t.motion==="animated",pulse:ot?L(t.pulse):void 0,packet:I?{path:I,repeat:F.repeat===!0,send:F.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const m of f){const b=m.mark?.says;if(!b?.length)continue;const h=[m.name,m.kind,m.detail,m.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(k=>h.includes(k.toLowerCase()))||r(`${m.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const m=new Map,b=new Map;for(const h of E)"n"in h&&(b.set(h.from,h.n),b.set(h.to,h.n));for(const h of E)if("n"in h){if(h.activate){const k=m.get(h.to)??[];if(k.length>=3)r(`message ${h.n} opens a fourth bar on ${h.to}: three deep at most`);else{const $={who:h.to,from:h.n,to:h.n,depth:k.length+1};k.push($),O.push($),m.set(h.to,k)}}if(h.deactivate){const $=m.get(h.from)?.pop();$?$.to=h.n:r(`message ${h.n} closes a bar on ${h.from}, which has none open`)}}for(const[h,k]of m)for(const $ of k)$.to=Math.max($.from,b.get(h)??$.from)}const N=t.frameLabels??{},G={opt:st(N.opt)??"Only if",loop:st(N.loop)??"Repeats",alt:st(N.alt)??"One of these",else:st(N.else)??"Otherwise"};let W=Math.max(1,...f.map(m=>m.col));if(e.rtl){for(const b of f)b.col=W-b.col+1;const m=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=m(b.fromSide),b.toSide=m(b.toSide);for(const b of E)if("open"in b){const[h,k]=[W-b.b+1,W-b.a+1];b.a=h,b.b=k}W=Math.max(1,...f.map(b=>b.col))}const Y=A==="data-flow"?Math.max(1,T.length):Math.max(1,...f.map(m=>m.row2)),K={type:A,title:String(t.title??""),heading:l,legend:a,nodes:f,byId:B,edges:S,groups:C,lanes:T,steps:E,bars:O,frameWords:G,cols:W,rows:Y,shapeLabels:g,stepWord:u,warnings:i,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:j||void 0,text:A==="sequence"&&t.variant==="text"||void 0};return t.layout==="auto"&&!j&&A!=="schema"&&Ze(K),s&&f.length>1&&!Ot(K)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function Ze(t){const e=new Set(t.nodes.map(o=>`${o.col},${o.row}`)),n=(o,a)=>{const c=[];for(let u=Math.min(o,a)+1;u{const a=t.byId.get(o.from),c=t.byId.get(o.to),u=c.col>a.col?"right":"left",y=c.row>a.row?"bottom":"top",g=c.col>a.col?"left":"right",l=c.row>a.row?"top":"bottom",p=(d,f,S,T)=>n(d,f).map(C=>T?[C,S]:[S,C]);let x;return a.row===c.row?x=[{sides:[u,g],cells:p(a.col,c.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===c.col?x=[{sides:[y,l],cells:p(a.row,c.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:x=[{sides:[u,l],cells:[...p(a.col,c.col,a.row,!0),[c.col,a.row],...p(a.row,c.row,c.col,!1)]},{sides:[y,g],cells:[...p(a.row,c.row,a.col,!1),[a.col,c.row],...p(a.col,c.col,c.row,!0)]},{sides:[u,g],cells:p(a.col,c.col,a.row,!0)},{sides:[y,l],cells:p(a.row,c.row,a.col,!1)}],x.filter(d=>d.cells.every(([f,S])=>!e.has(`${f},${S}`)))},i=new Map,r=t.edges.map((o,a)=>a).sort((o,a)=>s(t.edges[o]).length-s(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[o].kind==="main")||o-a);for(const o of r){const a=t.edges[o];if(a.fromSide||a.toSide)continue;const c=s(a).find(u=>(i.get(`${a.from}.${u.sides[0]}`)??0)<3&&(i.get(`${a.to}.${u.sides[1]}`)??0)<3);if(c){for(const[u,y]of[[a.from,c.sides[0]],[a.to,c.sides[1]]])i.set(`${u}.${y}`,(i.get(`${u}.${y}`)??0)+1);a.fromSide=c.sides[0],a.toSide=c.sides[1]}}}function Rt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=st(e.onLight);if(n)return{onLight:n,onDark:st(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Yt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function wt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Qt=28,Wt=t=>t.includes(` +`)?2:1,gt=t=>t.replace(/\n/g," "),vt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Pt(t,e){return t.legend[e]}function Ue(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Je(t,e){return wt(t,`sentence:${e.i}`,()=>Xe(t,e))}function Xe(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,i=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(vt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${i}.`);const r=te(t,e);r&&n.push(r.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Ue(t,e):e.kind;if(n.push(vt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(vt(e.detail)),e.group){const o=t.groups.find(c=>c.id===e.group),a=o?.parent?t.groups.find(c=>c.id===o.parent):void 0;o&&n.push(a?`In ${o.label}, in ${a.label}.`:`In ${o.label}.`)}const i=t.edges.filter(o=>o.to===e.id).map(o=>`${t.byId.get(o.from).name}${o.label?` (${gt(o.label)})`:""}`),r=t.edges.filter(o=>o.from===e.id).map(o=>`${t.byId.get(o.to).name}${o.label?` (${gt(o.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(vt(t.legend.focal)),n.join(" ")}function te(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function Ye(t,e,n,s){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),o=n.target;if(!r||!o||!r.contains(o)||!t.querySelector(`.${e}-edge`))return;const a=o.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===s?null:a.dataset.node??null:null}function ee(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const s=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&s.push(i);return{t,a:e??{},c:s}}var Qe={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>Qe[e]),Pe=" br img input meta link hr path polygon polyline circle rect line ";function Nt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=i===!0?` ${s}`:` ${s}="${it(String(i))}"`}return Pe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Nt(s,e)).join("")}`}var tn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function en(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function qt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function ne(t){return wt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=qt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((r,o)=>{r&&(e[o]=Math.max(e[o],oe(t,n,o)))})}return e})}function oe(t,e,n){const s=qt(t,e);return t.groups.filter(o=>o.parent===e.id).some(o=>{const a=qt(t,o);return a&&[a.r1===s.r1,a.c2===s.c2,a.r2===s.r2,a.c1===s.c1][n]})?2:1}function ae(t){const e=ne(t);return e[1]+e[3]}function zt(t){return t.type==="sequence"?t.nodes.length:t.cols}function se(t){return wt(t,"plan",()=>nn(t))}function nn(t){const e=t.nodes,n=d=>t.type==="data-flow"||!e[d].branch,s=t.edges.map(d=>{const f=t.byId.get(d.from).i,S=t.byId.get(d.to).i,C=e.slice(Math.min(f,S)+1,Math.max(f,S)).every(E=>!n(E.i));return S===f+1&&!(n(f)&&!n(S))?"down":S===f-1?"up":S>f&&n(f)&&!n(S)&&C?"trunk":S>f&&n(f)&&n(S)&&C?"rail":S>f?"end-down":"end-up"}),i=t.edges.map((d,f)=>({e:d,k:f})).filter(({k:d})=>s[d]==="end-down"||s[d]==="end-up"),r=d=>{const f=t.byId.get(d.from).i,S=t.byId.get(d.to).i;return[Math.min(f,S),Math.max(f,S)]},o=(d,f)=>{const[S,T]=r(d),[C,E]=r(f);return S{const f=t.byId.get(d.from).i,[S,T]=r(d);return!n(f)&&e.slice(S+1,T).every(C=>!n(C.i))&&i.every(C=>C.e===d||!o(C.e,d))}),c=i.length>0&&(t.type==="data-flow"||!a),u=d=>{const[f,S]=r(d);return S-f},y=t.edges.map(()=>0);let g=!1;const l=[];for(const d of[...i].sort((f,S)=>u(f.e)-u(S.e)||f.k-S.k)){let f=0;for(const S of l)o(S.e,d.e)&&(f=Math.max(f,y[S.k]+1));y[d.k]=f,f>1&&(g=!0),l.push(d)}const p=t.edges.map(()=>.5);for(const d of e){const f=i.filter(({e:C})=>C.from===d.id);if(f.length<2)continue;const S=f.filter(({k:C})=>s[C]==="end-down").sort((C,E)=>u(E.e)-u(C.e)||C.k-E.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,E)=>u(C.e)-u(E.e)||E.k-C.k),...S].forEach(({k:C},E,A)=>{p[C]=A.length===2?E===0?1/3:2/3:(E+1)/(A.length+1)})}const x=ht();for(let d=1;d{const B=s[Z],ot=t.byId.get(j.from).i,L=t.byId.get(j.to).i,F=L===d&&(B==="down"||B==="trunk"||B==="rail"||B==="end-down"),I=ot===d&&L===d-1&&B==="up",M=L===d-1&&B==="end-up";F&&(B==="trunk"||B==="end-down")&&(E=!0),M&&(A=!0),(F||I||M)&&j.label&&(T++,C=Math.max(C,B==="trunk"?40:48))}),(T>1||E&&A)&&(C=64),x[f.id]=C}return{routes:s,gutter:c,lanes:y,exits:p,gaps:x,third:g}}var xt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function re(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...xt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${r}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${s-4}L${i} ${s}L${i-8} ${s+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${s}L${i-8} ${s-4}L${i-8} ${s+4}Z`}))}function Et(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function ie(t,e){return wt(e,`key:${t}`,()=>an(t,e))}var on=ie;function an(t,e){const n=[],s=(o,a,c={})=>n.push(v("li",{class:`${t}-entry`,...c},o,v("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(c=>c.key)));for(const[a,c]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),v("span",null,c)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(Et(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(Et(t,"box"),e.shapeLabels.step),o.has("decision")&&s(Et(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind)),r=(o,a)=>v("span",{class:`${t}-key-glyph`,"data-ink":a,"aria-hidden":"true"},o);for(const o of["main","plain","dashed"]){const a=e.legend[o];i.has(o)&&a&&s(e.text?r(o==="main"?"━━▶":o==="dashed"?"┄┄▷":"──▶",o==="main"?"main":"plain"):re(t,o),a,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length&&(s(re(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(e.text?r("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...xt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),v("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(Et(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(Et(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function sn(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...xt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Ft(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function rn(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},Ft(t,n)))];const s=[];return e.type==="data-flow"?s.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(v("span",{class:`${t}-kind`},n.kind)),s.push(v("span",{class:`${t}-name`},Ft(t,n))),n.detail&&s.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Bt(n.detail).flatMap((i,r)=>[r?" ":"",v("span",{class:`${t}-run`},i)]):n.detail)),s}function ln(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},Ft(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((s,i)=>v("span",{class:`${t}-row`,"data-row":i,"data-key":s.key},v("span",{class:`${t}-keyseat`},s.key??""),v("span",{class:`${t}-cname`},s.name),s.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?v("span",{class:`${t}-ctype`},s.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var le=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function It(t,e,n,s){const{P:i}=t,r=en(e,s)||s.keep===n.id,o=mt(e,s),a=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&a.push(`--_lc:${n.col+1}`),e.type==="sequence"&&a.push(`--_c2:${n.col+1}`);const c=t.plan;if(c&&n.i>0){const l=yt(c.gaps,n.id)??32,p=yt(s.grow,n.id)??0;a.push(`--_gap:${p?`calc(${le(l)} + var(--basalt-space-4) * ${p})`:le(l)}`)}const u=yt(s.heights,n.id);u&&a.push(`--_h:${u}px`);const y=yt(s.words,n.id);y&&a.push(`--_ww:${y}px`);const g=o?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:a.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?Je(e,n):void 0,tabindex:g},n.shape==="decision"?v("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Yt(n.mark.onLight)};--_md:${Yt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?ln(i,n,e):rn(i,e,n))}function cn(t,e,n){const{P:s}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((c,u)=>v("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},v("span",{class:`${s}-lane-name`},c.label)))),e.type==="architecture")for(const c of e.groups){const u=qt(e,c);if(!u)continue;const y=[0,1,2,3].map(g=>oe(e,c,g));i.push(v("div",{class:`${s}-gbox`,"data-group":c.id,"data-depth":c.depth>1?c.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${y[0]>1?";--_gt:2":""}${y[1]>1?";--_ge:2":""}${y[2]>1?";--_gb:2":""}${y[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${s}-glabel`},c.label)))}if(e.text)return[v("pre",{class:`${s}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${s}-text-ink`},dn(s,e)))];if(e.type==="sequence")return i.push(v("ul",{class:`${s}-cast`},e.nodes.map(c=>v("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${c.col}`:void 0},It(t,e,c,n))))),i.push(fn(t,e)),i;const r=c=>{const u=c.group?e.groups.find(y=>y.id===c.group):void 0;return u?.parent?e.groups.find(y=>y.id===u.parent):u},o=(c,u,y)=>{const g=t.plan?yt(n.grow,u[0].id)??0:0;return v("div",{class:`${s}-group`,"data-group":c.id,"data-depth":c.depth>1?c.depth:void 0,style:g?`--_ggrow:${g}`:void 0},v("span",{class:`${s}-glabel`,"aria-hidden":"true"},c.label),y)};let a=0;for(;ad.id===y[l].group):void 0;if(!p){g.push(It(t,e,y[l],n)),l++;continue}const x=[];for(;lIt(t,e,d,n))))}i.push(o(u,y,g))}return i}function dn(t,e){const n=[],s=o=>v("span",{class:`${t}-tx-name`},o),i=o=>o==="main"?"━▶":o==="dashed"?"┄▷":"─▶";n.push(v("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((o,a)=>[a?" · ":"",s(o.name)])),` +`);let r=0;for(const o of e.steps){const a=" ".repeat(r);if("band"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"band"},`${a}── ${o.band} ──`),` +`);continue}if("open"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},a,v("span",{"data-ink":"op"},`[${o.open}]`),` ${o.label}`),` `),r++;continue}if("otherwise"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"}," ".repeat(r-1),v("span",{"data-ink":"op"},"[else]"),` ${o.otherwise}`),` `);continue}if("close"in o){r=Math.max(0,r-1),n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},`${" ".repeat(r)}[end]`),` -`);continue}const c=e.byId.get(o.from)?.name??o.from,u=e.byId.get(o.to)?.name??o.to;n.push(v("span",{class:`${t}-tx-line`,"data-n":o.n},s,v("span",{"data-ink":"num"},`${o.n} `),a(c)," ",v("span",{"data-ink":o.kind==="main"?"main":"plain"},i(o.kind))," ",a(u)," ",v("span",{"data-ink":"label"},o.label),o.note?[" ",v("span",{"data-ink":"note"},`(${o.note})`)]:null),` -`)}return n}function on(t,e){const{P:n}=t,a=[],i=[],r=()=>i.length?i[i.length-1].el.c:a;let o=null;for(const s of e.steps){if("band"in s){o=null,r().push(v("p",{class:`${n}-band`},v("span",null,s.band)));continue}if("open"in s){o=null;const d=i[i.length-1],f=d?`;--_fis:${s.a===d.a?1:0};--_fie:${s.b===d.b?1:0}`:"",S=v("div",{class:`${n}-frame`,"data-op":s.open,"data-depth":s.depth,style:`--_a:${s.a};--_b:${s.b+1}${f}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},s.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[s.open]}: `),s.label)));r().push(S),i.push({el:S,a:s.a,b:s.b});continue}if("otherwise"in s){o=null,r().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),s.otherwise)));continue}if("close"in s){o=null,i.pop();continue}o||(o=v("ol",{class:`${n}-msgs`,start:s.n}),r().push(o));const c=e.byId.get(s.from),u=e.byId.get(s.to),y=c?.col??1,p=u?.col??1,l=y===p,g=l&&(e.rtl?y!==1:y===e.nodes.length),x=Xt(e,s.kind);o.c.push(v("li",{class:`${n}-msg`,"data-kind":s.kind,"data-from":s.from,"data-to":s.to,"data-self":l?g?"start":"end":void 0,style:`--_a:${Math.min(y,p)};--_b:${Math.max(y,p)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(s.n)),v("span",{class:`${n}-mlabel`},s.label)),v("span",{class:`${n}-route`},c?.short??s.from," ",Qe(n,s.kind),v("span",{class:t.hidden}," to ")," ",u?.short??s.to,x?` · ${x}`:""),s.note?v("span",{class:`${n}-note`},s.note):null))}return v("div",{class:`${n}-steps`},a)}function re(t,e){return $t(e,`list:${t}`,()=>an(t,e))}var sn=re;function an(t,e){const n=Math.min(6,e.heading+1),a=p=>v(`h${n}`,{class:`${t}-list-head`},p),i=p=>v("strong",null,p),r=p=>p.href?v("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},i(p.name)):i(p.name),o=p=>v("code",{class:`${t}-code`},p),s=p=>e.byId.get(p)?.name??p,c=p=>{const l=Xt(e,p);return l?` (${l})`:""},u=p=>p.focal&&e.legend.focal?` ${wt(e.legend.focal)}`:"";if(e.type==="architecture"){const p=x=>v("li",null,r(x),x.kind?`, ${x.kind}`:"",x.detail?[". ",x.mono?o(x.detail):x.detail,/[.!?]$/.test(x.detail)?"":"."]:/[.!?]$/.test(x.kind??x.name)?"":".",u(x)),l=[a("Parts")],g=e.nodes.filter(x=>!x.group);g.length&&l.push(v("ul",{class:`${t}-list-items`},g.map(p)));for(const x of e.groups.filter(d=>d.depth===1)){l.push(v("p",{class:`${t}-list-group`},x.label)),x.members.length&&l.push(v("ul",{class:`${t}-list-items`},x.members.map(d=>p(e.byId.get(d)))));for(const d of e.groups.filter(f=>f.parent===x.id))l.push(v("p",{class:`${t}-list-group`,"data-depth":2},d.label)),l.push(v("ul",{class:`${t}-list-items`,"data-depth":2},d.members.map(f=>p(e.byId.get(f)))))}return l.push(a("Connections")),l.push(v("ol",{class:`${t}-list-items`},e.edges.map(x=>v("li",null,i(s(x.from))," to ",i(s(x.to)),x.label?[": ",o(gt(x.label))]:"",`${c(x.kind)}.`)))),l}if(e.type==="flowchart"){const p=l=>(e.byId.get(l)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const g=e.edges.filter(f=>f.from===l.id),x=l.shape==="decision"?"Decision":l.shape==="terminal"?g.length?"Start":"End":"Step",d=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return v("li",null,r(l),l.detail?[", ",l.mono?o(l.detail):l.detail]:"",`${d}${x}.`,u(l),g.length?v("ul",{class:`${t}-list-exits`},g.map(f=>v("li",null,f.label?`If ${gt(f.label)}: go to ${p(f.to)}, `:`Then: go to ${p(f.to)}, `,i(s(f.to)),c(f.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(p=>{const l=e.edges.filter(g=>g.from===p.id);return v("li",null,`${p.laneLabel}: `,r(p),p.detail?[", ",p.mono?o(p.detail):p.detail]:"",".",u(p),l.length?[" Then ",...l.flatMap((g,x)=>[x?"; ":"",`to step ${e.byId.get(g.to).step}, `,i(s(g.to)),g.label?[": ",o(gt(g.label))]:"",c(g.kind)]),"."]:"")}))];if(e.type==="sequence"){const p=[a("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(g=>v("li",null,i(g.name),g.kind?`, ${g.kind}`:"",".",u(g),Yt(e,g))))];p.push(a("Messages"));let l=null;for(const g of e.steps){if("band"in g){l=null,p.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},g.band));continue}if("open"in g){l=null,p.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords[g.open]}: ${g.label}`));continue}if("otherwise"in g){l=null,p.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords.else}: ${g.otherwise}`));continue}if("close"in g){l=null;continue}l||(l=v("ol",{class:`${t}-list-items`,start:g.n}),p.push(l)),l.c.push(v("li",null,o(g.label),": ",i(s(g.from))," to ",i(s(g.to)),`${c(g.kind)}.`,g.note?` ${wt(g.note)}`:""))}return p}const y=[];for(const p of e.nodes)y.push(v(`h${n}`,{class:`${t}-list-group`},p.href?v("a",{href:p.href,target:p.blank?"_blank":void 0,rel:p.blank?"noopener noreferrer":void 0},o(p.name)):o(p.name),u(p))),y.push(v("ul",{class:`${t}-list-items`},[...(p.columns??[]).map(l=>v("li",null,o(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",o(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...p.more?[v("li",null,`and ${p.more} more ${p.more===1?"column":"columns"}`)]:[]]));return y}function ie(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&It(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function zt(t,e=!1){const n=e&&t.type!=="sequence"&&It(t)&&t.cols>1&&t.rows>1,a=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Qt(t)},{keys:["Home","End"],words:"the ends"},...a,{keys:["Esc"],words:"clear"}]}var rn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function It(t){return $t(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,...ln(t,r)})),n=(r,o)=>{const s=o==="right"||o==="left",c=o==="right"||o==="down",u=x=>s?[x.col,x.col]:x.rows,y=x=>s?x.rows:[x.col,x.col],p=u(r),l=y(r);let g=null;return e.forEach((x,d)=>{if(x===r)return;const f=u(x),S=y(x),B=c?f[0]-p[1]:p[0]-f[1];if(B<1)return;const C=Math.max(0,S[0]-l[1],l[0]-S[1]),E=[C===0?0:1,C===0?B:B+2*C,C,Math.abs(S[0]-l[0]),d];(!g||rn(E,g.rank))&&(g={id:x.id,rank:E})}),g?.id??null},a=ht();for(const r of e)a[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const o=new Set([r]),s=[r];for(;s.length;)for(const c of Object.values(a[s.pop()]))c&&!o.has(c)&&(o.add(c),s.push(c));return o.size};return e.every(r=>i(r.id)===e.length)?a:null})}var le=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Ft(t,e,n){const a=n.prefix,i=Ze(n.base),r=t.type==="sequence"||t.type==="schema"?null:ne(t),o={P:a,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},s=e.layout==="drawn",c=mt(t,e),u=t.type==="sequence"||t.type==="schema"?s:!0,y=`h${t.heading}`,p=[`--_cols:${Wt(t)}`];if(t.type==="architecture"&&t.groups.length||s&&e.pad){const l=t.type==="architecture"?Pt(t):[0,0,0,0],g=(d,f,S)=>d?d>1?`calc(${d} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:S?`var(--basalt-space-${S})`:"0px",x=s&&e.pad?"3":void 0;p.push(`--_gpad:${g(l[0],"8",x)} ${g(l[1],"4")} ${g(l[2],"4",x)} ${g(l[3],"4")}`)}return le(t)&&p.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&p.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${a} ${n.className}`:a,"aria-labelledby":i.title,"data-type":t.type,"data-cols":Wt(t),"data-reach":t.type==="architecture"?ee(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:p.join(";")},v("div",{class:`${a}-head`},v(y,{id:i.title,class:`${a}-title`},t.title),n.hasSource?v("p",{class:`${a}-source`},{slot:"source"}):null),v("div",{class:`${a}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?i.title:void 0,"aria-describedby":u?c?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":c?"":void 0},en(o,t,e),t.text?null:v("div",{class:`${a}-ink`,"aria-hidden":"true"}),v("span",{class:`${a}-ruler`,"aria-hidden":"true"})),se(a,t),v("p",{class:`${a}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||s&&t.type==="sequence"?v("p",{class:`${a}-tap-hint`,"aria-hidden":"true"},`Tap ${Qt(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${a}-foot`},{slot:"toggle"}),v("div",{id:i.list,class:`${a}-list`,hidden:!e.open},re(a,t)),v("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${ie(t,s)} ${n.viewer}`:ie(t,s)),v("figcaption",{id:i.summary,class:`${a}-summary`},{slot:"summary"}))}function cn(t){const e=getComputedStyle(t),n=(i,r)=>{const o=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(o)?o:r},a=new Map;return{space:i=>(a.has(i)||a.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),a.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ot=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,ce=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:a,t:i,r,b:o}=t.rect,s=(a+r)/2,c=(i+o)/2,u=(r-a)/2,y=(o-i)/2,p=e==="top"||e==="bottom";if(t.shape==="decision"){if(p){const x=n,d=y*Math.max(0,1-Math.abs(x-s)/u);return{x,y:e==="top"?c-d:c+d}}const l=n,g=u*Math.max(0,1-Math.abs(l-c)/y);return{x:e==="left"?s-g:s+g,y:l}}if(t.shape==="terminal"){const l=Math.min(u,y);if(p){const f=n,S=Math.min(Math.max(f,a+l),r-l),B=f-S,C=Math.abs(B)>=l?0:Math.sqrt(l*l-B*B);return{x:f,y:Math.abs(B)<1e-6?e==="top"?i:o:e==="top"?c-C:c+C}}const g=n,x=g-c,d=Math.abs(x)>=l?0:Math.sqrt(l*l-x*x);return{x:e==="left"?a+l-d:r-l+d,y:g}}return p?{x:n,y:e==="top"?i:o}:{x:e==="left"?a:r,y:n}}function dn(t,e,n){const{l:a,t:i,r,b:o}=e.rect,s=(a+r)/2,c=(i+o)/2,u=(r-a)/2,y=(o-i)/2;if(e.shape==="decision")return Math.abs(t.x-s)/u+Math.abs(t.y-c)/y<1-n/Math.min(u,y);if(e.shape==="terminal"){const p=Math.min(u,y),l=Math.min(Math.max(t.x,a+p),r-p);return Math.hypot(t.x-l,t.y-c)a+n&&t.xi+n&&t.ymatchMedia("(forced-colors: active)").matches;function hn(t,e){const n=t.querySelector(`.${e}-ruler`),a=new Map;return(i,r)=>{const o=`${r}|${i}`;return a.has(o)||(n.setAttribute("data-f",r),n.textContent=i,a.set(o,n.getBoundingClientRect().width),n.textContent=""),a.get(o)}}var _t=t=>t?t.split(/\s+/).filter(Boolean):[];function pn(t,e,n){const a=e.space;let i=e.node,r=e.table;for(const c of t.nodes){if(c.shape==="table"){for(const d of c.columns??[]){const f=d.ref?`${t.rtl?"←":"→"} ${d.ref.table}`:d.type??"",S=a("6")+n(d.name,"mono")+(f?a("3")+n(f,"mono"):0)+2*a("3")+2*e.hair;r=Math.max(r,Math.ceil(S))}r=Math.max(r,Math.ceil(n(c.name,"table")+2*a("3")+2*e.hair+(c.href?16+a("1-5"):0)));continue}const u=c.shape==="terminal"?2*a("5"):2*a("3"),y=c.mark&&!un()?(c.shape==="participant"?2:1)*a("6"):0;let p=0;const l=c.href?16+a("1-5"):0,g=_t(c.name);if(g.forEach((d,f)=>{p=Math.max(p,n(d,c.shape==="decision"?"name-500":"name")+(c.kind?0:y)+(f===g.length-1?l:0))}),t.type!=="data-flow")for(const d of _t(c.kind))p=Math.max(p,n(d,"mono")+y);for(const d of _t(c.detail))p=Math.max(p,n(d,c.mono?"mono":"sans"));const x=c.shape==="decision"?p/.62:p+u+2*e.hair;i=Math.max(i,Math.ceil(x))}const o=Wt(t);let s;return t.type==="data-flow"?s=e.lane+o*(i+a("12")):t.type==="schema"?s=o*r+(o-1)*a("12")+(le(t)?a("5"):0):t.type==="sequence"?s=o*i+(o-1)*a("5"):s=o*i+(o-1)*a("16")+ee(t)*a("4"),{track:i,table:r,least:Math.max(e.wide,s)}}function fe(t,e){return{x:(n,a)=>a%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,a)=>a%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Ht(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ue(t,e,n){const a=t.map(r=>({...r}));for(let r=1;r=2){const c=i[i.length-2];if(Math.abs(c.x-s.x)<.01&&Math.abs(s.x-o.x)<.01||Math.abs(c.y-s.y)<.01&&Math.abs(s.y-o.y)<.01){i[i.length-1]=o;continue}}i.push(o)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Ct(t,e,n){const a=[];for(let r=0;rMath.min(d.x,f.x)+.75&&CMath.min(S.y,B.y)+.75&&Ei.split(/\s+/).map(parseFloat).filter(r=>Number.isFinite(r)),a=(i,r,o)=>{const s=[];let c=r;for(const u of i)s.push([c,c+u]),c+=u+o;return s};return{cols:a(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:a(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var nt=t=>t==="left"||t==="right",he={top:"bottom",bottom:"top",left:"right",right:"left"};function mn(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function yn(t,e,n){const a=[];t.edges.forEach((r,o)=>{const s=t.byId.get(r.from),c=t.byId.get(r.to),[u,y]=e[o],p=s.row===c.row&&nt(u)&&nt(y)&&u===he[y]||s.col===c.col&&!nt(u)&&!nt(y)&&u===he[y];a.push({edge:o,end:"from",node:s,side:u,far:c,straight:p,f:.5},{edge:o,end:"to",node:c,side:y,far:s,straight:p,f:.5})});const i=new Map;for(const r of a){const o=`${r.node.id}.${r.side}`;i.has(o)||i.set(o,[]),i.get(o).push(r)}for(const[r,o]of i){if(o[0].node.shape==="decision")continue;const s=d=>nt(d.side)?d.far.row-d.node.row:d.far.col-d.node.col,c=o.filter(d=>d.straight),u=o.filter(d=>!d.straight);if(u.sort((d,f)=>s(d)-s(f)||(nt(d.side)?d.far.col-f.far.col:d.far.row-f.far.row)*(s(d)<0?1:-1)),o.length>3&&n(`${r.replace(".","'s ")} side has ${o.length} lines; more than three is an error: use another side`),!c.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((d,f)=>{d.f=(f+1)/(u.length+1)});continue}const y=new Map;for(const d of c)y.has(d.far.id)||y.set(d.far.id,[]),y.get(d.far.id).push(d);for(const d of y.values())d.length>1&&d.sort((f,S)=>f.edge-S.edge).forEach((f,S)=>{f.f=d.length===2?S===0?.25:.75:(S+1)/(d.length+1)});const p=Math.min(...c.map(d=>d.f)),l=Math.max(...c.map(d=>d.f)),g=u.filter(d=>s(d)<0),x=u.filter(d=>s(d)>=0);g.forEach((d,f)=>{d.f=p*(f+1)/(g.length+1)}),x.forEach((d,f)=>{d.f=l+(1-l)*(f+1)/(x.length+1)})}return a}function pe(t,e,n){const{l:a,t:i,r,b:o}=t.rect;return nt(e)?lt(t,e,i+(o-i)*n):lt(t,e,a+(r-a)*n)}function ge(t,e,n,a){const i=new Map;return e.querySelectorAll(`.${a}-node`).forEach(r=>{const o=t.byId.get(r.dataset.node);o&&i.set(o.id,{id:o.id,rect:ft(r,n),shape:o.shape,i:o.i})}),i}function me(t,e){const n=e.head,a=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-a,r:i+a,t:r-n,b:r}:t.dir==="up"?{l:i-a,r:i+a,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-a,b:r+a}:{l:i,r:i+n,t:r-a,b:r+a}}var ye=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function be(t,e,n,a){const i=(r,o)=>{const s=r+o-Math.floor(r+o);return s<.005||s>.995?[0]:s<=.5?[-s,1-s]:[1-s,-s]};for(const r of i(t.t,n))for(const o of i(t.l,e)){if(!o&&!r)return t;const s={l:t.l+o,r:t.r+o,t:t.t+r,b:t.b+r};if(a(s))return s}return t}function bn(t,e,n,a,i,r,o,s,c){const u=o.space,y=[],p=[],l=[],g=[],x=u("1"),d=e.filter(f=>t.edges[f.i]?.label).sort((f,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-S.i);for(const f of d){const S=t.edges[f.i].label,B=s(S,"label"),C=16*Tt(S),E=f.pts.length-2,A=[];pt(f.pts).forEach(([L,F],I)=>{const M=Math.abs(L.y-F.y)<.01,O=M?L.x:L.y;let N=M?F.x:F.y;const G=Math.sign(N-O)||1;I===E&&(N-=G*o.head);let W=[[O,N]];for(const m of i)for(const b of M?[m.l,m.r]:[m.t,m.b]){const h=M?L.y:L.x;(M?h>m.t&&hm.l&&hb>Math.min($,w)+1&&b{const h=(m+b)/2,k=M?{x:h,y:L.y}:{x:L.x,y:h};return!i.some($=>k.x>$.l&&k.x<$.r&&k.y>$.t&&k.y<$.b)},K=f.axes?.[I]??(M?L.y:L.x);for(const[m,b]of W)A.push({horiz:M,c:K,p:m,q:b,len:Math.abs(b-m),pri:W.length>1&&Y(m,b)?1:0})}),A.sort((L,F)=>F.pri-L.pri||F.len-L.len);let T=null,Z=!1;const j=(L,F=!0)=>{const I=ce(L,x);return F&&(L.lr.r||L.tr.b)||n.some(M=>de(I,M))||y.some(M=>ut(I,M))||a.heads.some(M=>ut(I,M))||a.rects.some(M=>ut(I,M))?!1:!e.some(M=>M.i!==f.i&&pt(M.pts).some(([O,N])=>ut(I,ye(O,N,M.width))))};for(const L of A){for(const F of[1/2,1/3,2/3]){const I=L.p+(L.q-L.p)*F,M=[],O=u("2")+f.width/2;if(L.horiz?(L.len>=B+2*u("1")+u("3-5")&&M.push({box:{l:I-B/2-u("1"),r:I+B/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),M.push({box:{l:I-B/2,r:I+B/2,t:L.c-O-C,b:L.c-O},on:!1}),M.push({box:{l:I-B/2,r:I+B/2,t:L.c+O,b:L.c+O+C},on:!1})):(L.len>=C+u("3")&&M.push({box:{l:L.c-B/2-u("1"),r:L.c+B/2+u("1"),t:I-C/2,b:I+C/2},on:!0}),M.push({box:{l:L.c+O,r:L.c+O+B,t:I-C/2,b:I+C/2},on:!1}),M.push({box:{l:L.c-O-B,r:L.c-O,t:I-C/2,b:I+C/2},on:!1})),T=M.find(N=>j(N.box))??null,T)break;!Z&&M.some(N=>j(N.box,!1))&&(Z=!0)}if(T)break}if(!T){l.push(f.i),Z&&g.push(f.i);continue}const ot=be(T.box,c.ox,c.oy,L=>j(L));y.push(ot),p.push({i:f.i,text:S,box:ot,on:T.on})}return{labels:p,unseated:l,bounded:g}}function $e(t,e,n,a){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(o=>{if(o.getClientRects().length===0||getComputedStyle(o).display==="contents")return;const s=ft(o,e);r.push(s),i.push({l:s.l,r:s.r,t:s.t,b:s.t+1},{l:s.l,r:s.r,t:s.b-1,b:s.b},{l:s.l,r:s.l+1,t:s.t,b:s.b},{l:s.r-1,r:s.r,t:s.t,b:s.b});const c=o.querySelector(`:scope > .${n}-glabel`);c&&c.getClientRects().length&&i.push(ft(c,e))}),t.querySelectorAll(`.${n}-lane`).forEach((o,s)=>{if(!o.getClientRects().length)return;const c=ft(o,e);s>0&&i.push({l:c.l,r:c.r,t:c.t-a/2-.5,b:c.t-a/2+.5});const u=o.querySelector(`.${n}-lane-name`);u&&i.push(ft(u,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function $n(t,e){const{m:a,tk:i,P:r,drawing:o,origin:s,warn:c}=t,u=i.space,y=ge(a,o,s,r),p=[...y.values()],l=gn(o),g=s.left-Math.floor(s.left),x=s.top-Math.floor(s.top),d=fe(g,x),f=o.clientWidth,S=o.clientHeight,B=h=>a.type==="data-flow"?h.col+1:h.col,C=parseFloat(getComputedStyle(o).rowGap)||0,E={w:f,h:S,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:g,oy:x};if(a.type==="sequence")return vn(t,E,d);let A,T=[];a.type==="schema"?A=a.edges.map(h=>{const k=a.byId.get(h.from),$=a.byId.get(h.to);if(k.col===$.col){const w=k.col===a.cols&&a.cols>1?"left":"right";return[w,w]}return $.col>k.col?["right","left"]:["left","right"]}):(A=a.edges.map(h=>{const k=a.byId.get(h.from),$=a.byId.get(h.to),[w,_]=mn(k,$);return[h.fromSide??w,h.toSide??_]}),T=yn(a,A,c||(()=>{})));const Z=(h,k)=>{const $=o.querySelector(`.${r}-node[data-node="${CSS.escape(h)}"] .${r}-row[data-row="${k}"]`);if(!$)return 0;const w=ft($,s);return(w.t+w.b)/2},j=a.edges.map((h,k)=>{const[$,w]=A[k],_=y.get(h.from),q=y.get(h.to),R=Ot(h.kind,i);if(h.fk){const V=Z(h.from,h.fromRow),P=Z(h.to,h.toRow),U=d.y(V,R),et=d.y(P,R);return{p1:{x:$==="right"?_.rect.r:_.rect.l,y:U},p2:{x:w==="right"?q.rect.r:q.rect.l,y:et},r1:V,r2:Math.abs(U-et)<.01?V:P}}const Q=T.find(V=>V.edge===k&&V.end==="from").f,X=T.find(V=>V.edge===k&&V.end==="to").f;let z=pe(_,$,Q),D=pe(q,w,X);const tt=nt($)?z.y:z.x;let st=nt(w)?D.y:D.x;return nt($)?z={...z,y:d.y(z.y,R)}:z={...z,x:d.x(z.x,R)},nt(w)?D={...D,y:d.y(D.y,R)}:D={...D,x:d.x(D.x,R)},nt($)&&nt(w)&&Math.abs(z.y-D.y)<1.01&&(D={...D,y:z.y},st=tt),!nt($)&&!nt(w)&&Math.abs(z.x-D.x)<1.01&&(D={...D,x:z.x},st=tt),z=nt($)?lt(_,$,z.y):lt(_,$,z.x),D=nt(w)?lt(q,w,D.y):lt(q,w,D.x),{p1:z,p2:D,r1:tt,r2:st}}),ot=new Set;a.type==="schema"&&a.edges.forEach((h,k)=>{Math.abs(a.byId.get(h.from).col-a.byId.get(h.to).col)>1&&ot.add(k)});const L=new Map,F=new Set;a.edges.forEach((h,k)=>{if(ot.has(k))return;const[$,w]=A[k],{p1:_,p2:q}=j[k],R=a.byId.get(h.from),Q=a.byId.get(h.to);let X=null,z=null,D=!1;if($===w){if(nt($)){const V=$==="right"?Math.max(B(R),B(Q)):Math.min(B(R),B(Q))-1,P=l.cols[V-1],U=l.cols[V];P&&U&&(X=`c${V}`,z=[P[1],U[0]],D=!0)}else{const V=$==="bottom"?Math.max(R.row2,Q.row2):Math.min(R.row,Q.row)-1,P=l.rows[V-1],U=l.rows[V];P&&U&&(X=`r${V}`,z=[P[1],U[0]],D=!1)}X&&F.add(k)}else if(nt($)&&nt(w)&&Math.abs(_.y-q.y)>.5){const V=B(Q),P=w==="left",U=l.cols[(P?V-1:V)-1],et=l.cols[(P?V:V+1)-1];U&&et&&(X=`c${P?V-1:V}`,z=[U[1],et[0]],D=!0)}else if(!nt($)&&!nt(w)&&Math.abs(_.x-q.x)>.5){const P=w==="top"?Q.row-1:Q.row2,U=l.rows[P-1],et=l.rows[P];U&&et&&(X=`r${P}`,z=[U[1],et[0]],D=!1)}if(!X||!z)return;L.has(X)||L.set(X,{span:z,vertical:D,members:new Map});const tt=`${h.to}.${w}.${Math.round(D?q.y:q.x)}`,st=L.get(X);st.members.has(tt)||st.members.set(tt,[]),st.members.get(tt).push(k)});const I=new Map,M=h=>{const[k,$]=A[h],{p1:w,p2:_}=j[h];if(nt(k)&&nt($)){if(k===$){const R=I.get(h)??(k==="right"?Math.max(w.x,_.x)+u("4"):Math.min(w.x,_.x)-u("4"));return[w,{x:R,y:w.y},{x:R,y:_.y},_]}if(Math.abs(w.y-_.y)<=.5)return[w,{x:_.x,y:w.y}];const q=I.get(h)??(w.x+_.x)/2;return[w,{x:q,y:w.y},{x:q,y:_.y},_]}if(!nt(k)&&!nt($)){if(k===$){const R=I.get(h)??(k==="bottom"?Math.max(w.y,_.y)+u("4"):Math.min(w.y,_.y)-u("4"));return[w,{x:w.x,y:R},{x:_.x,y:R},_]}if(Math.abs(w.x-_.x)<=.5)return[w,{x:w.x,y:_.y}];const q=I.get(h)??(w.y+_.y)/2;return[w,{x:w.x,y:q},{x:_.x,y:q},_]}return nt(k)?[w,{x:_.x,y:w.y},_]:[w,{x:w.x,y:_.y},_]},O=h=>{const k=a.edges[h],$=Ot(k.kind,i),w=M(h),_=ue(w,$,d);let q;return w.length===_.length&&(q=pt(w).map(([R,Q])=>Math.abs(R.y-Q.y)<.75?(R.y+Q.y)/2:(R.x+Q.x)/2),q[0]=j[h].r1,q.length>1&&(q[q.length-1]=j[h].r2)),{i:h,from:k.from,to:k.to,kind:k.kind,pts:_,tip:_[_.length-1],dir:Ht(_),dot:k.fk?_[0]:void 0,width:$,axes:q}},N=()=>a.edges.flatMap((h,k)=>ot.has(k)?[]:[O(k)]);let G=null;const W=h=>{G??(G=N());const k=G.map($=>h.has($.i)?O($.i):$);return{lines:k,score:wn(k,h)*1e5+Ct(k,void 0,h).length*1e3+Dt(k.filter($=>h.has($.i)),p,a).length}},Y=(h,k)=>{const $=h.flatMap(w=>{const{p1:_,p2:q}=j[w];return k?[_.y,q.y]:[_.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,h]of L){const k=[...h.members.values()].map(w=>({members:w,run:Y(w,h.vertical)})).sort((w,_)=>w.run[0]-_.run[0]),$=[];for(const w of k){const _=$[$.length-1];_&&_.some(q=>q.run[0]F.has(tt)))continue;const _=w.map(tt=>tt.members),q=_.length,R=(h.span[1]-h.span[0])/(q+1);RV.forEach(U=>I.set(U,h.span[0]+R*(P+1))));const st=W(Q);st.scorett.forEach(V=>I.set(V,h.span[0]+R*(st+1)))),G=D}}E.lines=N();for(const h of ot)c?.(`${a.edges[h].from} to ${a.edges[h].to} is two columns apart, so its line is not drawn; its row still writes the target`);E.crossings=Ct(E.lines),E.through=Dt(E.lines,p,a),E.outside=xe(E.lines,f,S,i);const{obstacles:K,groups:m}=$e(o,s,r,C);K.heads=E.lines.map(h=>me(h,i));const b=bn(a,E.lines,p,K,m,{l:0,t:0,r:f,b:S},i,e,{ox:g,oy:x});return E.labels=b.labels,E.unseated=b.unseated,E.bounded=b.bounded,E.overlaps=[...new Set(we(E.lines,null).flat())],E}function wn(t,e){return we(t,e).length}function we(t,e){const n=[];for(let a=0;a=s)continue;const[f,S]=l?[c.x,u.x]:[c.y,u.y],[B,C]=l?[y.x,p.x]:[y.y,p.y];Math.min(Math.max(f,S),Math.max(B,C))-Math.max(Math.min(f,S),Math.min(B,C))>1&&n.push([r.i,o.i])}}return n}function*ve(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const c=s===r.pts.length-1?Math.max(r.width/2,a.head/2):r.width/2;return o.x-c<-.5||o.x+c>e+.5||o.y-c<-.5||o.y+c>n+.5})&&i.push(r.i);return i}function Dt(t,e,n){const a=[];for(const i of t){const r=pt(i.pts);e.some(o=>r.some(([s,c])=>fn(s,c,o)))&&a.push(i.i)}return a}function vn(t,e,n){const{m:a,tk:i,P:r,drawing:o,origin:s}=t,c=i.space,u=new Map;o.querySelectorAll(`.${r}-node`).forEach(E=>u.set(E.dataset.node,ft(E,s)));const y=o.querySelector(`.${r}-steps`),p=y?ft(y,s).b:e.h,l=E=>{const A=u.get(E);return A?n.x((A.l+A.r)/2,i.hair):0};for(const E of a.nodes){const A=u.get(E.id);A&&e.lifelines.push({x:l(E.id),y1:A.b,y2:p})}const g=E=>u.get(E.id),x=new Map;o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=ft(E,s);x.set(Number(E.querySelector(`.${r}-num`)?.textContent??0),(A.t+A.b)/2)});const d=i.activation,f=d/2,S=E=>{const A=a.byId.get(E.who);if(!A)return null;const T=l(E.who),j=(A.i===a.nodes.length-1&&a.nodes.length>1?-1:1)*(a.rtl?-1:1),ot=(E.depth-1)*c("1")*j,L=x.get(E.from)??0,F=x.get(E.to)??L,I=E.from===E.to;return{l:n.x(T-f+ot,i.hair),r:n.x(T+f+ot,i.hair),t:n.y(I?L-c("2")-c("1"):L,i.hair),b:n.y(I?L+c("2")+c("1"):F,i.hair)}},B=a.bars.map(E=>({bar:E,rect:S(E)})).filter(E=>E.rect);e.bars=B.map(E=>E.rect);const C=(E,A,T)=>B.filter(({bar:Z})=>Z.who===E&&Z.to>=A&&(T?Z.from<=A:Z.fromj.bar.depth-Z.bar.depth)[0]?.rect;return o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=E.dataset.from,T=E.dataset.to,Z=E.dataset.kind??"plain",j=Ot(Z,i),ot=ft(E,s),L=n.y((ot.t+ot.b)/2,j),F=Number(E.querySelector(`.${r}-num`)?.textContent??0);let I=l(A),M=l(T),O;if(A===T){const b=E.dataset.self==="start"?-c("6"):c("6"),h=C(A,F,!0),k=h?b>0?h.r:h.l:I,$=n.y(L-c("2"),j),w=n.y(L+c("2"),j);O=[{x:k,y:$},{x:n.x(I+b,j),y:$},{x:n.x(I+b,j),y:w},{x:k,y:w}]}else{const b=M>I?1:-1,h=C(A,F,!1),k=C(T,F,!0);h&&(I=b>0?h.r:h.l),k&&(M=b>0?k.l:k.r),O=[{x:I,y:L},{x:M,y:L}]}e.lines.push({i:F,from:A,to:T,kind:Z,pts:O,tip:O[O.length-1],dir:Ht(O),width:j});const N=E.querySelector(`.${r}-said`),G=E.querySelector(`.${r}-note`),W=a.byId.get(A),Y=a.byId.get(T);if(!W||!Y)return;const K=A===T?(()=>{const b=a.nodes[W.i+(E.dataset.self==="start"?-1:1)],h=b?l(b.id):E.dataset.self==="start"?0:e.w;return Math.abs(h-I)-c("6")-c("2-5")-c("2")})():Math.abs(M-I)-2*c("2");Math.max(N?N.getBoundingClientRect().width:0,G?G.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(F)}),o.querySelectorAll(`.${r}-fhead`).forEach(E=>{const A=E.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!A)return;[...E.children].reduce((Z,j)=>Z+j.getBoundingClientRect().width,0)+c("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${E.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function ke(t,e,n,a=ht()){const{m:i,tk:r,P:o,drawing:s,origin:c}=t,u=r.space,y=ge(i,s,c,o),p=[...y.values()],l=c.left-Math.floor(c.left),g=c.top-Math.floor(c.top),x=fe(l,g),d=s.clientWidth,f=s.clientHeight,S={w:d,h:f,nodes:p,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:g},B=ht();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:B};const C=d-(parseFloat(getComputedStyle(s).paddingRight)||0),E=(M,O,N)=>{const G=[M];for(let W=1;W<=(yt(a,O)??0);W++)G.push({...M,t:M.t+N*u("4")*W,b:M.b+N*u("4")*W});return G},A=new Map;s.querySelectorAll(`.${o}-node`).forEach(M=>{const O=M.parentElement,N=ft(O,c),G=getComputedStyle(O);A.set(M.dataset.node,N.r-(parseFloat(G.paddingRight)||0)-(parseFloat(G.borderRightWidth)||0))});const T=i.nodes,Z=M=>y.get(T[M].id),j=[],ot=M=>Ot(i.edges[M].kind,r);i.edges.forEach((M,O)=>{const N=n.routes[O],G=y.get(M.from),W=y.get(M.to),Y=ot(O);let K=[];const m=M.label,b=m?e(m,"label"):0,h=m?16*Tt(m):16,k=u("4");if(N==="down"||N==="up"){const w=Math.max(G.rect.l,W.rect.l),_=Math.min(G.rect.r,W.rect.r),q=i.edges.map((z,D)=>({o:z,j:D})).filter(({o:z,j:D})=>(n.routes[D]==="down"||n.routes[D]==="up")&&(z.from===M.from&&z.to===M.to||z.from===M.to&&z.to===M.from)),R=q.findIndex(z=>z.j===O),Q=q.length<2?.5:q.length===2?R===0?.25:.75:(R+1)/(q.length+1),X=x.x(w+(_-w)*Q,Y);if(K=N==="down"?[lt(G,"bottom",X),lt(W,"top",X)]:[lt(G,"top",X),lt(W,"bottom",X)],m){let z=Math.min(K[0].y,K[1].y),D=Math.max(K[0].y,K[1].y);N==="down"?D-=r.head:z+=r.head;const tt=[...s.querySelectorAll(`.${o}-group`)].map(U=>ft(U,c));let st=[[z,D]];for(const U of tt)for(const et of[U.t,U.b])st=st.flatMap(([rt,ct])=>et>rt+1&&ettt.some(rt=>(U+et)/2>rt.t&&(U+et)/2rt.l&&X1){const U=st.filter(([rt,ct])=>!V(rt,ct));[z,D]=(U.length?U:st).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const P=[1/2,1/3,2/3].map(U=>{const et=z+(D-z)*U;return{l:X-b/2-u("1"),r:X+b/2+u("1"),t:et-h/2,b:et+h/2}});j.push({k:O,cands:P,on:!0,card:N==="down"?M.to:M.from})}}else if(N==="trunk"||N==="rail"){const w=x.x(Math.max(G.rect.l,N==="rail"?W.rect.l:G.rect.l)+u(N==="trunk"?"8":"3"),Y),_=lt(G,"bottom",w);if(N==="rail"){if(K=[_,lt(W,"top",w)],m){const q=W.rect.t-u("6");j.push({k:O,cands:E({l:w+u("2-5"),r:w+u("2-5")+b,t:q-h/2,b:q+h/2},M.to,-1),on:!1,card:M.to})}}else{const q=x.x(W.rect.l+u("6"),Y),R=x.y(W.rect.t-k,Y);K=[_,{x:w,y:R},{x:q,y:R},lt(W,"top",q)],m&&j.push({k:O,cands:E({l:q+u("2-5"),r:q+u("2-5")+b,t:R-h/2,b:R+h/2},M.to,-1),on:!1,card:M.to})}}else{const w=Math.min(A.get(M.from)??d,A.get(M.to)??d),_=x.x(n.gutter?C+(n.lanes[O]?2*u("3-5"):u("3-5")):w-u("2-5"),Y),q=x.y(G.rect.t+(G.rect.b-G.rect.t)*n.exits[O],Y),R=lt(G,"right",q),Q=x.x(W.rect.r-u("6"),Y),X=N==="end-down",z=x.y(X?W.rect.t-k:W.rect.b+k,Y);K=[R,{x:_,y:R.y},{x:_,y:z},{x:Q,y:z},lt(W,X?"top":"bottom",Q)];const D=X?M.to:T[W.i+1]?.id??M.to;m&&j.push({k:O,cands:E({l:Q-u("2-5")-b,r:Q-u("2-5"),t:z-h/2,b:z+h/2},D,X?-1:1),on:!1,card:D})}const $=ue(K,Y,x);S.lines.push({i:O,from:M.from,to:M.to,kind:M.kind,pts:$,tip:$[$.length-1],dir:Ht($),width:Y})}),S.crossings=Ct(S.lines),S.through=Dt(S.lines,p,i),S.outside=xe(S.lines,d,f,r);const{obstacles:L}=$e(s,c,o,0);L.heads=S.lines.map(M=>me(M,r));const F=[],I={l:0,t:0,r:d,b:f};for(const M of j){const O=W=>{const Y=ce(W,u("1"));return W.lI.r+.5||W.tI.b+.5||p.some(K=>de(Y,K))||F.some(K=>ut(Y,K))||L.heads.some(K=>ut(Y,K))||L.rects.some(K=>ut(Y,K))||S.lines.some(K=>K.i!==M.k&&pt(K.pts).some(([m,b])=>ut(Y,ye(m,b,K.width))))},N=M.cands.find(W=>!O(W));N||(B[M.card]=(B[M.card]??0)+1,S.unseated.push(M.k));const G=N?be(N,l,g,W=>!O(W)):M.cands[0];F.push(G),S.labels.push({i:M.k,text:i.edges[M.k].label,box:G,on:M.on})}return{geo:S,grow:B}}function xn(t,e){const n=r=>String(Math.round(r*100)/100);let a=`M${n(t[0].x)} ${n(t[0].y)}`;for(let r=1;r({...E})),p=y[y.length-1];p.x-=r.x*u,p.y-=r.y*u;const l=e.tip.x-r.x*s,g=e.tip.y-r.y*s,x=-r.y*c,d=r.x*c,f=E=>Math.round(E*100)/100,S=it(e.kind),B=o?``:``,C=e.dot?``:"";return`${B}${C}`}function Me(t,e,n,a){const i=new Map,r=new Map;for(const s of e.crossings)r.has(s.under)||r.set(s.under,[]),r.get(s.under).push(s);let o="";for(const[s,c]of r){const u=`${a}-cut-${s}`;i.set(s,u);const y=c.map(p=>{const l=e.lines[p.top],g=e.lines[p.under],x=l.width/2+n.cut,d=g.width/2+1;return p.underVertical?``:``}).join("");o+=`${y}`}return{defs:o,ids:i}}function Se(t,e,n,a){const{defs:i,ids:r}=Me(t,e,n,a),o=e.lifelines.map(y=>``).join("")+(e.bars??[]).map(y=>``).join(""),s=e.lines.map((y,p)=>Mn(t,y,n,r.get(p)??null,y.from===y.to?n.radiusXs:n.radius)).join(""),c=`${i?`${i}`:""}${o}${s}`,u=e.labels.map(y=>`1?' data-lines="2"':""} style="left:${Math.round(y.box.l*100)/100}px;top:${Math.round(y.box.t*100)/100}px;width:${Math.round((y.box.r-y.box.l)*100)/100}px">${y.text.split(` -`).map(it).join("
")}
`).join("");return c+u}function Gt(t,e,n,a,i,r,o,s){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const y=cn(t),p=hn(u,n),l=pn(e,y,p);s?.(l.least);const g=t.clientWidth,x=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),d=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:x&&L.layout!=="drawn"?x:void 0};let f=!1;const S=L=>{if(f=!1,e.type!=="flowchart")return L;r({...L,heights:void 0,words:void 0});const F=ht(),I=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const O=M.querySelector(`.${n}-words`);if(!O)return;const N=M.getBoundingClientRect(),G=K=>{const m={w:K.width+2*y.space("2-5"),h:K.height+2*y.space("2")},b=1-m.w/N.width,h=b>.05?m.h/2/b:m.h*10;return Math.max(y.space("16"),Math.ceil(N.width/5),Math.ceil(2*h))},W=O.getBoundingClientRect();let Y=G(W);if(Y>N.width){const K=k=>(M.style.setProperty("--_ww",`${k}px`),O.getBoundingClientRect()),m=Math.floor(M.clientWidth-2*y.space("2-5"));let b=Math.ceil(W.width),h=W.height;for(;b1;){const q=k+$>>1;K(q).heightN.width&&(f=!0)}),{...L,heights:F,words:Object.keys(I).length?I:void 0}},B=()=>({m:e,tk:y,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:o}),C=i.autoOpen?{open:!1,autoOpen:void 0}:{},E=(L,F)=>F.map(I=>Et(e,L.lines.find(M=>M.i===I))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:y,least:l.least};if(g>=l.least&&!e.unplaced){const L=O=>{let N=d({...i,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return N=S(N),r(N),{dd:N,g:$n(B(),p)}};let{dd:F,g:I}=L(!1);const M=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||f;if(!M(I)&&I.unseated.length&&I.unseated.every(O=>I.bounded?.includes(O))){const O=L(!0);!M(O.g)&&!O.g.unseated.length&&({dd:F,g:I}=O)}if(!M(I)&&!I.unseated.length)return I.crossings.length&&o?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(O=>`${Et(e,I.lines[O.top])} over ${Et(e,I.lines[O.under])}`).join("; ")}`),{dyn:F,geo:I,ink:Se(n,I,y,a),tokens:y,least:l.least};f&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: a decision would be taller than it is wide`),I.misfit?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${I.misfit.join("; ")}`),I.through.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.through)} would pass through a node`),I.overlaps?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.overlaps)} would lie on one another`),I.outside.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.outside)} would leave the drawing`),I.unseated.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: no clean seat for ${I.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=d({...i,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(A=S(A),r(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:y,least:l.least};const T=ne(e);let Z=ke(B(),p,T,A.grow);for(let L=0;L<6&&Object.keys(Z.grow).length;L++){const F=ht(A.grow);for(const[I,M]of Object.entries(Z.grow))F[I]=(yt(F,I)??0)+M;A={...A,grow:F},r(A),Z=ke(B(),p,T,F)}const j=Z.geo;if(j.unseated.length>0||j.through.length>0||j.outside.length>0||T.third){j.unseated.length&&o?.(`the stacked drawing has no clean seat for ${[...new Set(j.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),j.through.length&&o?.(`in the stacked drawing ${E(j,j.through)} would pass through a node, so its lines are not drawn`),j.outside.length&&o?.(`in the stacked drawing ${E(j,j.outside)} would leave the drawing, so its lines are not drawn`),T.third&&o?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={...j,lines:[],labels:[],crossings:[]};return{dyn:d({...A,grow:ht(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:y,least:l.least}}return j.crossings.length&&o?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${j.crossings.map(L=>`${Et(e,j.lines[L.top])} over ${Et(e,j.lines[L.under])}`).join("; ")}`),{dyn:A,geo:j,ink:Se(n,j,y,a),tokens:y,least:l.least}}function Et(t,e){const n=t.byId.get(e.from)?.name??e.from,a=t.byId.get(e.to)?.name??e.to;return`${n} to ${a}`}function Sn(t,e,n,a,i,r){const o=new Set;if(r){o.add(r);for(const d of n?.lines??[])d.from===r&&o.add(d.to),d.to===r&&o.add(d.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(d=>d.toggleAttribute("data-near",o.has(d.dataset.node))),!n||!a)return;const s=d=>!!r&&(d.from===r||d.to===r),c=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(d=>u.set(d.getAttribute("data-edge"),d));for(const d of n.lines){const f=u.get(String(d.i));f&&(f.toggleAttribute("data-lit",s(d)),f.toggleAttribute("data-dim",!!r&&!s(d)))}if(t.querySelectorAll(`.${e}-label`).forEach(d=>{const f=n.lines.find(S=>String(S.i)===d.dataset.edge);d.toggleAttribute("data-lit",!!(f&&s(f)))}),c){for(const d of n.lines)if(s(d)){const f=u.get(String(d.i));f&&c.appendChild(f)}}const y=Ct(n.lines,s),{defs:p,ids:l}=Me(e,{...n,crossings:y},a,i),g=t.querySelector(`.${e}-svg`);if(!g)return;let x=g.querySelector("defs");!x&&p&&(x=document.createElementNS("http://www.w3.org/2000/svg","defs"),g.insertBefore(x,g.firstChild)),x&&(x.innerHTML=p),n.lines.forEach((d,f)=>{const S=u.get(String(d.i))?.querySelector(`.${e}-line`);if(!S)return;const B=l.get(f);B?S.setAttribute("mask",`url(#${B})`):S.removeAttribute("mask")})}var En=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function An(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",En()||qn(t)?"done":"pending")}}var Ln=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function qn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Ln(t))!==null}catch{return!1}}function Ee(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function In(t,e,n,a=!1,i=!1){const r=a?It(t):null;if(r&&n.startsWith("Arrow")){const u={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?r[e]?.[u]??null:null}const o=t.byId.get(e)?.i??0,s=t.nodes.length;let c;if(n==="ArrowRight"||n==="ArrowDown")c=o+1;else if(n==="ArrowLeft"||n==="ArrowUp")c=o-1;else if(n==="Home")c=0;else if(n==="End")c=s-1;else return null;return t.nodes[Math.max(0,Math.min(s-1,c))].id}var On=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Ae=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],_n=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],Le=t=>t==null||t===!1;function Cn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Kt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const a=n?Ae:On;for(const o of a)Le(e.a[o])&&t.removeAttribute(o);for(const[o,s]of Object.entries(e.a)){if(o==="class")continue;if(o==="style"){const u=t.style,y=new Map(String(s??"").split(";").map(p=>{const l=p.indexOf(":");return[p.slice(0,l).trim(),p.slice(l+1).trim()]}).filter(([p])=>p));for(const[p,l]of y)u.getPropertyValue(p).trim()!==l&&u.setProperty(p,l);for(const p of _n)y.has(p)||u.removeProperty(p);continue}if(n&&!Ae.includes(o))continue;if(Le(s)){t.removeAttribute(o);continue}const c=s===!0?"":String(s);t.getAttribute(o)!==c&&t.setAttribute(o,c)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(o=>typeof o!="string"&&"slot"in o))return;const i=[...t.children];let r=0;for(const o of e.c)if(!(typeof o=="string"||"slot"in o)){for(let s=r;st.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(a)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",a=0;function i(l,g,x){return{prefix:n,base:l,hasSource:g.source!==void 0&&g.source!==null&&g.source!=="",hiddenClass:"visually-hidden",viewer:x?x.keys:void 0}}function r(l,g,x,d){var f=function(S){return''+it(S)+""};return{source:it(String(g.source||"")),summary:it(String(g.summary||"")),hint:zt(l).map(function(S){return""+S.keys.map(f).join(" ")+" "+it(S.words)+""}).join(""),toggle:'"}}function o(l,g,x){var d=Mt(l),f=Ft(d,{},i(g,l,x)),S=Rt(f,r(d,l,g,!1)),B=S.indexOf(">");return{open:S.slice(0,B+1),inner:S.slice(B+1,S.length-9),warnings:d.warnings}}var s=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],c=["--_cols","--_gpad","--_track"];function u(l,g,x,d){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(l).direction==="rtl",B=g.layout==="auto"&&(g.type==="architecture"||g.type==="flowchart"||g.type==="schema"),C=B?Array.isArray(g.placement)?g.placement:g.placement?[g.placement]:[]:[];B&&!C.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var E=g.direction?[g.direction]:g.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var J=0;J .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++a+"-title"););f="dg"+a}var Z=o(g,f,d),j=document.createElement("div");j.innerHTML=Z.open+"";var ot=j.firstChild;s.forEach(function(H){l.removeAttribute(H)}),c.forEach(function(H){l.style.removeProperty(H)});for(var L=0;L :not(script[data-diagram])").forEach(function(H){H.remove()}),l.insertAdjacentHTML("beforeend",Z.inner)}T.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var I=i(f,g,d),M={},O=null,N=null,G=null,W=null,Y=Object.create(null),K=function(H){Y[H]||(Y[H]=1,console.warn("Basalt diagram: "+H))},m=function(H){Kt(l,Ft(T,H,I))},b=l.querySelector(".diagram-ink"),h=l.querySelector(".diagram-toggle"),k=!d&&T.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,_=function(){k&&Ee(l)};function q(){Sn(l,n,O&&O.geo,O&&O.tokens,f,N||W||G),X()}var R=null,Q=!d&&matchMedia("(hover: none), (pointer: coarse)").matches;function X(){var H=Q&&!d&&b&&b.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(Q&&!d)),H&&!R){var J=l.querySelector(":scope > .diagram-foot");if(!J)return;R=document.createElement("button"),R.type="button",R.className="btn diagram-clear",R.setAttribute("data-variant","secondary"),R.setAttribute("data-size","sm"),R.innerHTML="Clear highlight",R.addEventListener("click",function(){W&&(W=null,q())}),J.appendChild(R)}else!H&&R&&(R.remove(),R=null);R&&(W?R.removeAttribute("aria-disabled"):R.setAttribute("aria-disabled","true"))}function z(H){if(!H.defaultPrevented){var J=Ge(l,n,H,W);J!==void 0&&(_(),Q=!0,W=J,q())}}function D(){h&&(h.setAttribute("aria-expanded",String(!!M.open)),h.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function tt(){if(B&&C.length>1&&!d){for(var H=null,J=0;J .diagram-hint");if(Zt){var Be=zt(T,M.layout==="drawn").map(function(jt){return""+jt.keys.map(function(Rn){return''+it(Rn)+""}).join(" ")+" "+it(jt.words)+""}).join("");Zt.innerHTML!==Be&&(Zt.innerHTML=Be)}mt(T,M)||(G=W=null);var Te=b&&O.ink!==w;Te&&(b.innerHTML=O.ink,w=O.ink),q(),k&&O.tokens&&(An(l,!!(O.geo&&O.geo.lines.length)),Te&&$&&$.redrawn()),d&&d.onMeasured&&O.tokens&&d.onMeasured(O,l),T.text&&typeof e.diagramText=="function"&&e.diagramText(l,T,g)}function st(H){M=H,m(M)}function V(H){var J=M.stop;M=Object.assign({},M,{stop:H}),jn(l,n,J,H)}var P=function(H){var J=H&&H.closest?H.closest(".diagram-node"):null;return J&&l.contains(J)?J:null};function U(H){var J=P(H.target);if(!(!J||H.defaultPrevented)){if(_(),H.key==="Escape"){!d&&(N||G||W)&&(H.preventDefault(),N=G=W=null,q());return}if(mt(T,M)){var dt=In(T,J.getAttribute("data-node"),H.key,M.layout==="drawn");if(dt){H.preventDefault(),V(dt);var kt=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');kt&&kt.focus()}}}}function et(H){var J=P(H.target);if(J){_();var dt=J.getAttribute("data-node");N=J.matches(":focus-visible")?dt:null,mt(T,M)&&M.stop!==dt&&V(dt),q()}}function rt(H){var J=P(H.target);J&&(P(H.relatedTarget)||(N=null),M.keep===J.getAttribute("data-node")&&st(Object.assign({},M,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var J=P(H.target);J&&_();var dt=J&&mt(T,M)?J.getAttribute("data-node"):null;dt!==G&&(G=dt,q())}}function At(){G&&(G=null,q())}function bt(){_(),st(Object.assign({},M,{open:!M.open,autoOpen:void 0})),D()}l.addEventListener("keydown",U),l.addEventListener("focusin",et),l.addEventListener("focusout",rt),l.addEventListener("pointerover",ct),l.addEventListener("pointerleave",At),l.addEventListener("click",z),h&&h.addEventListener("click",bt),tt();var xt=l.clientWidth,Vt=0,qe=!0,Ie=new ResizeObserver(function(){Math.abs(l.clientWidth-xt)<.5||(xt=l.clientWidth,cancelAnimationFrame(Vt),Vt=requestAnimationFrame(tt))});Ie.observe(l),document.fonts&&document.fonts.ready.then(function(){qe&&tt()});var Oe=matchMedia("(forced-colors: active)"),_e=T.nodes.some(function(H){return H.mark});_e&&Oe.addEventListener("change",tt),k&&($=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return T},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},g));var Ce=!d&&g.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,g,{model:T,settle:_,animated:k}):null,je=l.querySelector(":scope > .diagram-foot"),Bn=!d&&g.export===!0&&je&&typeof e.diagramExport=="function"?e.diagramExport(je,l):[];l.__diagram={stop:function(){Ce&&Ce.destroy(),Bn.forEach(function(H){H.remove()}),qe=!1,Ie.disconnect(),cancelAnimationFrame(Vt),_e&&Oe.removeEventListener("change",tt),$&&$.destroy(),l.removeEventListener("keydown",U),l.removeEventListener("focusin",et),l.removeEventListener("focusout",rt),l.removeEventListener("pointerover",ct),l.removeEventListener("pointerleave",At),l.removeEventListener("click",z),R&&R.remove(),h&&h.removeEventListener("click",bt)},layout:tt,key:y(g),send:$&&$.sendValue?$.sendValue:null}}function y(l){try{return JSON.stringify(l,function(g,x){return g==="packet"&&x&&typeof x=="object"?Object.assign({},x,{send:void 0}):x})}catch{return null}}function p(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var g=l.querySelector(":scope > script[data-diagram]");if(g)try{u(l,JSON.parse(g.textContent),!0)}catch(x){console.error("Basalt diagram: this figure could not be drawn",x)}}})}e.diagramMarkup=o,e.diagramKit={draw:u,buildModel:Mt,figureKey:Xe,figureList:sn,hintEntries:zt,toHtml:Rt,escapeHtml:it,settleEntrance:Ee,measureFigure:Gt},t.diagram=function(l,g){var x=l.__diagram,d=x&&x.send?y(g):null;if(d!==null&&d===x.key){x.send(g.packet?g.packet.send:void 0);return}u(l,g)},e.step(62,"wireDiagrams",p)})(window.Basalt)})(); +`);continue}const c=e.byId.get(o.from)?.name??o.from,u=e.byId.get(o.to)?.name??o.to;n.push(v("span",{class:`${t}-tx-line`,"data-n":o.n},a,v("span",{"data-ink":"num"},`${o.n} `),s(c)," ",v("span",{"data-ink":o.kind==="main"?"main":"plain"},i(o.kind))," ",s(u)," ",v("span",{"data-ink":"label"},o.label),o.note?[" ",v("span",{"data-ink":"note"},`(${o.note})`)]:null),` +`)}return n}function fn(t,e){const{P:n}=t,s=[],i=[],r=()=>i.length?i[i.length-1].el.c:s;let o=null;for(const a of e.steps){if("band"in a){o=null,r().push(v("p",{class:`${n}-band`},v("span",null,a.band)));continue}if("open"in a){o=null;const d=i[i.length-1],f=d?`;--_fis:${a.a===d.a?1:0};--_fie:${a.b===d.b?1:0}`:"",S=v("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${f}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));r().push(S),i.push({el:S,a:a.a,b:a.b});continue}if("otherwise"in a){o=null,r().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){o=null,i.pop();continue}o||(o=v("ol",{class:`${n}-msgs`,start:a.n}),r().push(o));const c=e.byId.get(a.from),u=e.byId.get(a.to),y=c?.col??1,g=u?.col??1,l=y===g,p=l&&(e.rtl?y!==1:y===e.nodes.length),x=Pt(e,a.kind);o.c.push(v("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":l?p?"start":"end":void 0,style:`--_a:${Math.min(y,g)};--_b:${Math.max(y,g)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(a.n)),v("span",{class:`${n}-mlabel`},a.label)),v("span",{class:`${n}-route`},c?.short??a.from," ",sn(n,a.kind),v("span",{class:t.hidden}," to ")," ",u?.short??a.to,x?` · ${x}`:""),a.note?v("span",{class:`${n}-note`},a.note):null))}return v("div",{class:`${n}-steps`},s)}function ce(t,e){return wt(e,`list:${t}`,()=>hn(t,e))}var un=ce;function hn(t,e){const n=Math.min(6,e.heading+1),s=g=>v(`h${n}`,{class:`${t}-list-head`},g),i=g=>v("strong",null,g),r=g=>g.href?v("a",{href:g.href,target:g.blank?"_blank":void 0,rel:g.blank?"noopener noreferrer":void 0},i(g.name)):i(g.name),o=g=>v("code",{class:`${t}-code`},g),a=g=>e.byId.get(g)?.name??g,c=g=>{const l=Pt(e,g);return l?` (${l})`:""},u=g=>g.focal&&e.legend.focal?` ${vt(e.legend.focal)}`:"";if(e.type==="architecture"){const g=x=>v("li",null,r(x),x.kind?`, ${x.kind}`:"",x.detail?[". ",x.mono?o(x.detail):x.detail,/[.!?]$/.test(x.detail)?"":"."]:/[.!?]$/.test(x.kind??x.name)?"":".",u(x)),l=[s("Parts")],p=e.nodes.filter(x=>!x.group);p.length&&l.push(v("ul",{class:`${t}-list-items`},p.map(g)));for(const x of e.groups.filter(d=>d.depth===1)){l.push(v("p",{class:`${t}-list-group`},x.label)),x.members.length&&l.push(v("ul",{class:`${t}-list-items`},x.members.map(d=>g(e.byId.get(d)))));for(const d of e.groups.filter(f=>f.parent===x.id))l.push(v("p",{class:`${t}-list-group`,"data-depth":2},d.label)),l.push(v("ul",{class:`${t}-list-items`,"data-depth":2},d.members.map(f=>g(e.byId.get(f)))))}return l.push(s("Connections")),l.push(v("ol",{class:`${t}-list-items`},e.edges.map(x=>v("li",null,i(a(x.from))," to ",i(a(x.to)),x.label?[": ",o(gt(x.label))]:"",`${c(x.kind)}.`)))),l}if(e.type==="flowchart"){const g=l=>(e.byId.get(l)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const p=e.edges.filter(f=>f.from===l.id),x=l.shape==="decision"?"Decision":l.shape==="terminal"?p.length?"Start":"End":"Step",d=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return v("li",null,r(l),l.detail?[", ",l.mono?o(l.detail):l.detail]:"",`${d}${x}.`,u(l),p.length?v("ul",{class:`${t}-list-exits`},p.map(f=>v("li",null,f.label?`If ${gt(f.label)}: go to ${g(f.to)}, `:`Then: go to ${g(f.to)}, `,i(a(f.to)),c(f.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const l=e.edges.filter(p=>p.from===g.id);return v("li",null,`${g.laneLabel}: `,r(g),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",".",u(g),l.length?[" Then ",...l.flatMap((p,x)=>[x?"; ":"",`to step ${e.byId.get(p.to).step}, `,i(a(p.to)),p.label?[": ",o(gt(p.label))]:"",c(p.kind)]),"."]:"")}))];if(e.type==="sequence"){const g=[s("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(p=>v("li",null,i(p.name),p.kind?`, ${p.kind}`:"",".",u(p),te(e,p))))];g.push(s("Messages"));let l=null;for(const p of e.steps){if("band"in p){l=null,g.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},p.band));continue}if("open"in p){l=null,g.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":p.depth>1?p.depth:void 0},`${e.frameWords[p.open]}: ${p.label}`));continue}if("otherwise"in p){l=null,g.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":p.depth>1?p.depth:void 0},`${e.frameWords.else}: ${p.otherwise}`));continue}if("close"in p){l=null;continue}l||(l=v("ol",{class:`${t}-list-items`,start:p.n}),g.push(l)),l.c.push(v("li",null,o(p.label),": ",i(a(p.from))," to ",i(a(p.to)),`${c(p.kind)}.`,p.note?` ${vt(p.note)}`:""))}return g}const y=[];for(const g of e.nodes)y.push(v(`h${n}`,{class:`${t}-list-group`},g.href?v("a",{href:g.href,target:g.blank?"_blank":void 0,rel:g.blank?"noopener noreferrer":void 0},o(g.name)):o(g.name),u(g))),y.push(v("ul",{class:`${t}-list-items`},[...(g.columns??[]).map(l=>v("li",null,o(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",o(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...g.more?[v("li",null,`and ${g.more} more ${g.more===1?"column":"columns"}`)]:[]]));return y}function de(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Ot(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function Ht(t,e=!1){const n=e&&t.type!=="sequence"&&Ot(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:ee(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var pn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Ot(t){return wt(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,...gn(t,r)})),n=(r,o)=>{const a=o==="right"||o==="left",c=o==="right"||o==="down",u=x=>a?[x.col,x.col]:x.rows,y=x=>a?x.rows:[x.col,x.col],g=u(r),l=y(r);let p=null;return e.forEach((x,d)=>{if(x===r)return;const f=u(x),S=y(x),T=c?f[0]-g[1]:g[0]-f[1];if(T<1)return;const C=Math.max(0,S[0]-l[1],l[0]-S[1]),E=[C===0?0:1,C===0?T:T+2*C,C,Math.abs(S[0]-l[0]),d];(!p||pn(E,p.rank))&&(p={id:x.id,rank:E})}),p?.id??null},s=ht();for(const r of e)s[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const o=new Set([r]),a=[r];for(;a.length;)for(const c of Object.values(s[a.pop()]))c&&!o.has(c)&&(o.add(c),a.push(c));return o.size};return e.every(r=>i(r.id)===e.length)?s:null})}var fe=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function _t(t,e,n){const s=n.prefix,i=tn(n.base),r=t.type==="sequence"||t.type==="schema"?null:se(t),o={P:s,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},a=e.layout==="drawn",c=mt(t,e),u=t.type==="sequence"||t.type==="schema"?a:!0,y=`h${t.heading}`,g=[`--_cols:${zt(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const l=t.type==="architecture"?ne(t):[0,0,0,0],p=(d,f,S)=>d?d>1?`calc(${d} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:S?`var(--basalt-space-${S})`:"0px",x=a&&e.pad?"3":void 0;g.push(`--_gpad:${p(l[0],"8",x)} ${p(l[1],"4")} ${p(l[2],"4",x)} ${p(l[3],"4")}`)}return fe(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":i.title,"data-type":t.type,"data-cols":zt(t),"data-reach":t.type==="architecture"?ae(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},v("div",{class:`${s}-head`},v(y,{id:i.title,class:`${s}-title`},t.title),n.hasSource?v("p",{class:`${s}-source`},{slot:"source"}):null),v("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?i.title:void 0,"aria-describedby":u?c?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":c?"":void 0},cn(o,t,e),t.text?null:v("div",{class:`${s}-ink`,"aria-hidden":"true"}),v("span",{class:`${s}-ruler`,"aria-hidden":"true"})),ie(s,t),v("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?v("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${ee(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${s}-foot`},{slot:"toggle"}),v("div",{id:i.list,class:`${s}-list`,hidden:!e.open},ce(s,t)),v("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${de(t,a)} ${n.viewer}`:de(t,a)),v("figcaption",{id:i.summary,class:`${s}-summary`},{slot:"summary"}))}function mn(t){const e=getComputedStyle(t),n=(i,r)=>{const o=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(o)?o:r},s=new Map;return{space:i=>(s.has(i)||s.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),s.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ct=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,ue=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:i,r,b:o}=t.rect,a=(s+r)/2,c=(i+o)/2,u=(r-s)/2,y=(o-i)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const x=n,d=y*Math.max(0,1-Math.abs(x-a)/u);return{x,y:e==="top"?c-d:c+d}}const l=n,p=u*Math.max(0,1-Math.abs(l-c)/y);return{x:e==="left"?a-p:a+p,y:l}}if(t.shape==="terminal"){const l=Math.min(u,y);if(g){const f=n,S=Math.min(Math.max(f,s+l),r-l),T=f-S,C=Math.abs(T)>=l?0:Math.sqrt(l*l-T*T);return{x:f,y:Math.abs(T)<1e-6?e==="top"?i:o:e==="top"?c-C:c+C}}const p=n,x=p-c,d=Math.abs(x)>=l?0:Math.sqrt(l*l-x*x);return{x:e==="left"?s+l-d:r-l+d,y:p}}return g?{x:n,y:e==="top"?i:o}:{x:e==="left"?s:r,y:n}}function yn(t,e,n){const{l:s,t:i,r,b:o}=e.rect,a=(s+r)/2,c=(i+o)/2,u=(r-s)/2,y=(o-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/u+Math.abs(t.y-c)/y<1-n/Math.min(u,y);if(e.shape==="terminal"){const g=Math.min(u,y),l=Math.min(Math.max(t.x,s+g),r-g);return Math.hypot(t.x-l,t.y-c)s+n&&t.xi+n&&t.ymatchMedia("(forced-colors: active)").matches;function wn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(i,r)=>{const o=`${r}|${i}`;return s.has(o)||(n.setAttribute("data-f",r),n.textContent=i,s.set(o,n.getBoundingClientRect().width),n.textContent=""),s.get(o)}}var Bt=t=>t?t.split(/\s+/).filter(Boolean):[];function vn(t,e,n){const s=e.space;let i=e.node,r=e.table;for(const c of t.nodes){if(c.shape==="table"){for(const d of c.columns??[]){const f=d.ref?`${t.rtl?"←":"→"} ${d.ref.table}`:d.type??"",S=s("6")+n(d.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;r=Math.max(r,Math.ceil(S))}r=Math.max(r,Math.ceil(n(c.name,"table")+2*s("3")+2*e.hair+(c.href?16+s("1-5"):0)));continue}const u=c.shape==="terminal"?2*s("5"):2*s("3"),y=c.mark&&!$n()?(c.shape==="participant"?2:1)*s("6"):0;let g=0;const l=c.href?16+s("1-5"):0,p=Bt(c.name);if(p.forEach((d,f)=>{g=Math.max(g,n(d,c.shape==="decision"?"name-500":"name")+(c.kind?0:y)+(f===p.length-1?l:0))}),t.type!=="data-flow")for(const d of Bt(c.kind))g=Math.max(g,n(d,"mono")+y);for(const d of Bt(c.detail))g=Math.max(g,n(d,c.mono?"mono":"sans"));const x=c.shape==="decision"?g/.62:g+u+2*e.hair;i=Math.max(i,Math.ceil(x))}const o=zt(t);let a;return t.type==="data-flow"?a=e.lane+o*(i+s("12")):t.type==="schema"?a=o*r+(o-1)*s("12")+(fe(t)?s("5"):0):t.type==="sequence"?a=o*i+(o-1)*s("5"):a=o*i+(o-1)*s("16")+ae(t)*s("4"),{track:i,table:r,least:Math.max(e.wide,a)}}function pe(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Dt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ge(t,e,n){const s=t.map(r=>({...r}));for(let r=1;r=2){const c=i[i.length-2];if(Math.abs(c.x-a.x)<.01&&Math.abs(a.x-o.x)<.01||Math.abs(c.y-a.y)<.01&&Math.abs(a.y-o.y)<.01){i[i.length-1]=o;continue}}i.push(o)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Tt(t,e,n){const s=[];for(let r=0;rMath.min(d.x,f.x)+.75&&CMath.min(S.y,T.y)+.75&&Ei.split(/\s+/).map(parseFloat).filter(r=>Number.isFinite(r)),s=(i,r,o)=>{const a=[];let c=r;for(const u of i)a.push([c,c+u]),c+=u+o;return a};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var nt=t=>t==="left"||t==="right",me={top:"bottom",bottom:"top",left:"right",right:"left"};function kn(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Mn(t,e,n){const s=[];t.edges.forEach((r,o)=>{const a=t.byId.get(r.from),c=t.byId.get(r.to),[u,y]=e[o],g=a.row===c.row&&nt(u)&&nt(y)&&u===me[y]||a.col===c.col&&!nt(u)&&!nt(y)&&u===me[y];s.push({edge:o,end:"from",node:a,side:u,far:c,straight:g,f:.5},{edge:o,end:"to",node:c,side:y,far:a,straight:g,f:.5})});const i=new Map;for(const r of s){const o=`${r.node.id}.${r.side}`;i.has(o)||i.set(o,[]),i.get(o).push(r)}for(const[r,o]of i){if(o[0].node.shape==="decision")continue;const a=d=>nt(d.side)?d.far.row-d.node.row:d.far.col-d.node.col,c=o.filter(d=>d.straight),u=o.filter(d=>!d.straight);if(u.sort((d,f)=>a(d)-a(f)||(nt(d.side)?d.far.col-f.far.col:d.far.row-f.far.row)*(a(d)<0?1:-1)),o.length>3&&n(`${r.replace(".","'s ")} side has ${o.length} lines; more than three is an error: use another side`),!c.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((d,f)=>{d.f=(f+1)/(u.length+1)});continue}const y=new Map;for(const d of c)y.has(d.far.id)||y.set(d.far.id,[]),y.get(d.far.id).push(d);for(const d of y.values())d.length>1&&d.sort((f,S)=>f.edge-S.edge).forEach((f,S)=>{f.f=d.length===2?S===0?.25:.75:(S+1)/(d.length+1)});const g=Math.min(...c.map(d=>d.f)),l=Math.max(...c.map(d=>d.f)),p=u.filter(d=>a(d)<0),x=u.filter(d=>a(d)>=0);p.forEach((d,f)=>{d.f=g*(f+1)/(p.length+1)}),x.forEach((d,f)=>{d.f=l+(1-l)*(f+1)/(x.length+1)})}return s}function ye(t,e,n){const{l:s,t:i,r,b:o}=t.rect;return nt(e)?lt(t,e,i+(o-i)*n):lt(t,e,s+(r-s)*n)}function be(t,e,n,s){const i=new Map;return e.querySelectorAll(`.${s}-node`).forEach(r=>{const o=t.byId.get(r.dataset.node);o&&i.set(o.id,{id:o.id,rect:ft(r,n),shape:o.shape,i:o.i})}),i}function $e(t,e){const n=e.head,s=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-s,r:i+s,t:r-n,b:r}:t.dir==="up"?{l:i-s,r:i+s,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-s,b:r+s}:{l:i,r:i+n,t:r-s,b:r+s}}var we=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function ve(t,e,n,s){const i=(r,o)=>{const a=r+o-Math.floor(r+o);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const r of i(t.t,n))for(const o of i(t.l,e)){if(!o&&!r)return t;const a={l:t.l+o,r:t.r+o,t:t.t+r,b:t.b+r};if(s(a))return a}return t}function Sn(t,e,n,s,i,r,o,a,c){const u=o.space,y=[],g=[],l=[],p=[],x=u("1"),d=e.filter(f=>t.edges[f.i]?.label).sort((f,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-S.i);for(const f of d){const S=t.edges[f.i].label,T=a(S,"label"),C=16*Wt(S),E=f.pts.length-2,A=[];pt(f.pts).forEach(([L,F],I)=>{const M=Math.abs(L.y-F.y)<.01,O=M?L.x:L.y;let N=M?F.x:F.y;const G=Math.sign(N-O)||1;I===E&&(N-=G*o.head);let W=[[O,N]];for(const m of i)for(const b of M?[m.l,m.r]:[m.t,m.b]){const h=M?L.y:L.x;(M?h>m.t&&hm.l&&hb>Math.min($,w)+1&&b{const h=(m+b)/2,k=M?{x:h,y:L.y}:{x:L.x,y:h};return!i.some($=>k.x>$.l&&k.x<$.r&&k.y>$.t&&k.y<$.b)},K=f.axes?.[I]??(M?L.y:L.x);for(const[m,b]of W)A.push({horiz:M,c:K,p:m,q:b,len:Math.abs(b-m),pri:W.length>1&&Y(m,b)?1:0})}),A.sort((L,F)=>F.pri-L.pri||F.len-L.len);let j=null,Z=!1;const B=(L,F=!0)=>{const I=ue(L,x);return F&&(L.lr.r||L.tr.b)||n.some(M=>he(I,M))||y.some(M=>ut(I,M))||s.heads.some(M=>ut(I,M))||s.rects.some(M=>ut(I,M))?!1:!e.some(M=>M.i!==f.i&&pt(M.pts).some(([O,N])=>ut(I,we(O,N,M.width))))};for(const L of A){for(const F of[1/2,1/3,2/3]){const I=L.p+(L.q-L.p)*F,M=[],O=u("2")+f.width/2;if(L.horiz?(L.len>=T+2*u("1")+u("3-5")&&M.push({box:{l:I-T/2-u("1"),r:I+T/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),M.push({box:{l:I-T/2,r:I+T/2,t:L.c-O-C,b:L.c-O},on:!1}),M.push({box:{l:I-T/2,r:I+T/2,t:L.c+O,b:L.c+O+C},on:!1})):(L.len>=C+u("3")&&M.push({box:{l:L.c-T/2-u("1"),r:L.c+T/2+u("1"),t:I-C/2,b:I+C/2},on:!0}),M.push({box:{l:L.c+O,r:L.c+O+T,t:I-C/2,b:I+C/2},on:!1}),M.push({box:{l:L.c-O-T,r:L.c-O,t:I-C/2,b:I+C/2},on:!1})),j=M.find(N=>B(N.box))??null,j)break;!Z&&M.some(N=>B(N.box,!1))&&(Z=!0)}if(j)break}if(!j){l.push(f.i),Z&&p.push(f.i);continue}const ot=ve(j.box,c.ox,c.oy,L=>B(L));y.push(ot),g.push({i:f.i,text:S,box:ot,on:j.on})}return{labels:g,unseated:l,bounded:p}}function xe(t,e,n,s){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(o=>{if(o.getClientRects().length===0||getComputedStyle(o).display==="contents")return;const a=ft(o,e);r.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const c=o.querySelector(`:scope > .${n}-glabel`);c&&c.getClientRects().length&&i.push(ft(c,e))}),t.querySelectorAll(`.${n}-lane`).forEach((o,a)=>{if(!o.getClientRects().length)return;const c=ft(o,e);a>0&&i.push({l:c.l,r:c.r,t:c.t-s/2-.5,b:c.t-s/2+.5});const u=o.querySelector(`.${n}-lane-name`);u&&i.push(ft(u,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function En(t,e){const{m:s,tk:i,P:r,drawing:o,origin:a,warn:c}=t,u=i.space,y=be(s,o,a,r),g=[...y.values()],l=xn(o),p=a.left-Math.floor(a.left),x=a.top-Math.floor(a.top),d=pe(p,x),f=o.clientWidth,S=o.clientHeight,T=h=>s.type==="data-flow"?h.col+1:h.col,C=parseFloat(getComputedStyle(o).rowGap)||0,E={w:f,h:S,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:p,oy:x};if(s.type==="sequence")return Ln(t,E,d);let A,j=[];s.type==="schema"?A=s.edges.map(h=>{const k=s.byId.get(h.from),$=s.byId.get(h.to);if(k.col===$.col){const w=k.col===s.cols&&s.cols>1?"left":"right";return[w,w]}return $.col>k.col?["right","left"]:["left","right"]}):(A=s.edges.map(h=>{const k=s.byId.get(h.from),$=s.byId.get(h.to),[w,_]=kn(k,$);return[h.fromSide??w,h.toSide??_]}),j=Mn(s,A,c||(()=>{})));const Z=(h,k)=>{const $=o.querySelector(`.${r}-node[data-node="${CSS.escape(h)}"] .${r}-row[data-row="${k}"]`);if(!$)return 0;const w=ft($,a);return(w.t+w.b)/2},B=s.edges.map((h,k)=>{const[$,w]=A[k],_=y.get(h.from),q=y.get(h.to),R=Ct(h.kind,i);if(h.fk){const V=Z(h.from,h.fromRow),P=Z(h.to,h.toRow),U=d.y(V,R),et=d.y(P,R);return{p1:{x:$==="right"?_.rect.r:_.rect.l,y:U},p2:{x:w==="right"?q.rect.r:q.rect.l,y:et},r1:V,r2:Math.abs(U-et)<.01?V:P}}const Q=j.find(V=>V.edge===k&&V.end==="from").f,X=j.find(V=>V.edge===k&&V.end==="to").f;let z=ye(_,$,Q),D=ye(q,w,X);const tt=nt($)?z.y:z.x;let at=nt(w)?D.y:D.x;return nt($)?z={...z,y:d.y(z.y,R)}:z={...z,x:d.x(z.x,R)},nt(w)?D={...D,y:d.y(D.y,R)}:D={...D,x:d.x(D.x,R)},nt($)&&nt(w)&&Math.abs(z.y-D.y)<1.01&&(D={...D,y:z.y},at=tt),!nt($)&&!nt(w)&&Math.abs(z.x-D.x)<1.01&&(D={...D,x:z.x},at=tt),z=nt($)?lt(_,$,z.y):lt(_,$,z.x),D=nt(w)?lt(q,w,D.y):lt(q,w,D.x),{p1:z,p2:D,r1:tt,r2:at}}),ot=new Set;s.type==="schema"&&s.edges.forEach((h,k)=>{Math.abs(s.byId.get(h.from).col-s.byId.get(h.to).col)>1&&ot.add(k)});const L=new Map,F=new Set;s.edges.forEach((h,k)=>{if(ot.has(k))return;const[$,w]=A[k],{p1:_,p2:q}=B[k],R=s.byId.get(h.from),Q=s.byId.get(h.to);let X=null,z=null,D=!1;if($===w){if(nt($)){const V=$==="right"?Math.max(T(R),T(Q)):Math.min(T(R),T(Q))-1,P=l.cols[V-1],U=l.cols[V];P&&U&&(X=`c${V}`,z=[P[1],U[0]],D=!0)}else{const V=$==="bottom"?Math.max(R.row2,Q.row2):Math.min(R.row,Q.row)-1,P=l.rows[V-1],U=l.rows[V];P&&U&&(X=`r${V}`,z=[P[1],U[0]],D=!1)}X&&F.add(k)}else if(nt($)&&nt(w)&&Math.abs(_.y-q.y)>.5){const V=T(Q),P=w==="left",U=l.cols[(P?V-1:V)-1],et=l.cols[(P?V:V+1)-1];U&&et&&(X=`c${P?V-1:V}`,z=[U[1],et[0]],D=!0)}else if(!nt($)&&!nt(w)&&Math.abs(_.x-q.x)>.5){const P=w==="top"?Q.row-1:Q.row2,U=l.rows[P-1],et=l.rows[P];U&&et&&(X=`r${P}`,z=[U[1],et[0]],D=!1)}if(!X||!z)return;L.has(X)||L.set(X,{span:z,vertical:D,members:new Map});const tt=`${h.to}.${w}.${Math.round(D?q.y:q.x)}`,at=L.get(X);at.members.has(tt)||at.members.set(tt,[]),at.members.get(tt).push(k)});const I=new Map,M=h=>{const[k,$]=A[h],{p1:w,p2:_}=B[h];if(nt(k)&&nt($)){if(k===$){const R=I.get(h)??(k==="right"?Math.max(w.x,_.x)+u("4"):Math.min(w.x,_.x)-u("4"));return[w,{x:R,y:w.y},{x:R,y:_.y},_]}if(Math.abs(w.y-_.y)<=.5)return[w,{x:_.x,y:w.y}];const q=I.get(h)??(w.x+_.x)/2;return[w,{x:q,y:w.y},{x:q,y:_.y},_]}if(!nt(k)&&!nt($)){if(k===$){const R=I.get(h)??(k==="bottom"?Math.max(w.y,_.y)+u("4"):Math.min(w.y,_.y)-u("4"));return[w,{x:w.x,y:R},{x:_.x,y:R},_]}if(Math.abs(w.x-_.x)<=.5)return[w,{x:w.x,y:_.y}];const q=I.get(h)??(w.y+_.y)/2;return[w,{x:w.x,y:q},{x:_.x,y:q},_]}return nt(k)?[w,{x:_.x,y:w.y},_]:[w,{x:w.x,y:_.y},_]},O=h=>{const k=s.edges[h],$=Ct(k.kind,i),w=M(h),_=ge(w,$,d);let q;return w.length===_.length&&(q=pt(w).map(([R,Q])=>Math.abs(R.y-Q.y)<.75?(R.y+Q.y)/2:(R.x+Q.x)/2),q[0]=B[h].r1,q.length>1&&(q[q.length-1]=B[h].r2)),{i:h,from:k.from,to:k.to,kind:k.kind,pts:_,tip:_[_.length-1],dir:Dt(_),dot:k.fk?_[0]:void 0,width:$,axes:q}},N=()=>s.edges.flatMap((h,k)=>ot.has(k)?[]:[O(k)]);let G=null;const W=h=>{G??(G=N());const k=G.map($=>h.has($.i)?O($.i):$);return{lines:k,score:An(k,h)*1e5+Tt(k,void 0,h).length*1e3+Gt(k.filter($=>h.has($.i)),g,s).length}},Y=(h,k)=>{const $=h.flatMap(w=>{const{p1:_,p2:q}=B[w];return k?[_.y,q.y]:[_.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,h]of L){const k=[...h.members.values()].map(w=>({members:w,run:Y(w,h.vertical)})).sort((w,_)=>w.run[0]-_.run[0]),$=[];for(const w of k){const _=$[$.length-1];_&&_.some(q=>q.run[0]F.has(tt)))continue;const _=w.map(tt=>tt.members),q=_.length,R=(h.span[1]-h.span[0])/(q+1);RV.forEach(U=>I.set(U,h.span[0]+R*(P+1))));const at=W(Q);at.scorett.forEach(V=>I.set(V,h.span[0]+R*(at+1)))),G=D}}E.lines=N();for(const h of ot)c?.(`${s.edges[h].from} to ${s.edges[h].to} is two columns apart, so its line is not drawn; its row still writes the target`);E.crossings=Tt(E.lines),E.through=Gt(E.lines,g,s),E.outside=Se(E.lines,f,S,i);const{obstacles:K,groups:m}=xe(o,a,r,C);K.heads=E.lines.map(h=>$e(h,i));const b=Sn(s,E.lines,g,K,m,{l:0,t:0,r:f,b:S},i,e,{ox:p,oy:x});return E.labels=b.labels,E.unseated=b.unseated,E.bounded=b.bounded,E.overlaps=[...new Set(ke(E.lines,null).flat())],E}function An(t,e){return ke(t,e).length}function ke(t,e){const n=[];for(let s=0;s=a)continue;const[f,S]=l?[c.x,u.x]:[c.y,u.y],[T,C]=l?[y.x,g.x]:[y.y,g.y];Math.min(Math.max(f,S),Math.max(T,C))-Math.max(Math.min(f,S),Math.min(T,C))>1&&n.push([r.i,o.i])}}return n}function*Me(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const c=a===r.pts.length-1?Math.max(r.width/2,s.head/2):r.width/2;return o.x-c<-.5||o.x+c>e+.5||o.y-c<-.5||o.y+c>n+.5})&&i.push(r.i);return i}function Gt(t,e,n){const s=[];for(const i of t){const r=pt(i.pts);e.some(o=>r.some(([a,c])=>bn(a,c,o)))&&s.push(i.i)}return s}function Ln(t,e,n){const{m:s,tk:i,P:r,drawing:o,origin:a}=t,c=i.space,u=new Map;o.querySelectorAll(`.${r}-node`).forEach(E=>u.set(E.dataset.node,ft(E,a)));const y=o.querySelector(`.${r}-steps`),g=y?ft(y,a).b:e.h,l=E=>{const A=u.get(E);return A?n.x((A.l+A.r)/2,i.hair):0};for(const E of s.nodes){const A=u.get(E.id);A&&e.lifelines.push({x:l(E.id),y1:A.b,y2:g})}const p=E=>u.get(E.id),x=new Map;o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=ft(E,a);x.set(Number(E.querySelector(`.${r}-num`)?.textContent??0),(A.t+A.b)/2)});const d=i.activation,f=d/2,S=E=>{const A=s.byId.get(E.who);if(!A)return null;const j=l(E.who),B=(A.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),ot=(E.depth-1)*c("1")*B,L=x.get(E.from)??0,F=x.get(E.to)??L,I=E.from===E.to;return{l:n.x(j-f+ot,i.hair),r:n.x(j+f+ot,i.hair),t:n.y(I?L-c("2")-c("1"):L,i.hair),b:n.y(I?L+c("2")+c("1"):F,i.hair)}},T=s.bars.map(E=>({bar:E,rect:S(E)})).filter(E=>E.rect);e.bars=T.map(E=>E.rect);const C=(E,A,j)=>T.filter(({bar:Z})=>Z.who===E&&Z.to>=A&&(j?Z.from<=A:Z.fromB.bar.depth-Z.bar.depth)[0]?.rect;return o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=E.dataset.from,j=E.dataset.to,Z=E.dataset.kind??"plain",B=Ct(Z,i),ot=ft(E,a),L=n.y((ot.t+ot.b)/2,B),F=Number(E.querySelector(`.${r}-num`)?.textContent??0);let I=l(A),M=l(j),O;if(A===j){const b=E.dataset.self==="start"?-c("6"):c("6"),h=C(A,F,!0),k=h?b>0?h.r:h.l:I,$=n.y(L-c("2"),B),w=n.y(L+c("2"),B);O=[{x:k,y:$},{x:n.x(I+b,B),y:$},{x:n.x(I+b,B),y:w},{x:k,y:w}]}else{const b=M>I?1:-1,h=C(A,F,!1),k=C(j,F,!0);h&&(I=b>0?h.r:h.l),k&&(M=b>0?k.l:k.r),O=[{x:I,y:L},{x:M,y:L}]}e.lines.push({i:F,from:A,to:j,kind:Z,pts:O,tip:O[O.length-1],dir:Dt(O),width:B});const N=E.querySelector(`.${r}-said`),G=E.querySelector(`.${r}-note`),W=s.byId.get(A),Y=s.byId.get(j);if(!W||!Y)return;const K=A===j?(()=>{const b=s.nodes[W.i+(E.dataset.self==="start"?-1:1)],h=b?l(b.id):E.dataset.self==="start"?0:e.w;return Math.abs(h-I)-c("6")-c("2-5")-c("2")})():Math.abs(M-I)-2*c("2");Math.max(N?N.getBoundingClientRect().width:0,G?G.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(F)}),o.querySelectorAll(`.${r}-fhead`).forEach(E=>{const A=E.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!A)return;[...E.children].reduce((Z,B)=>Z+B.getBoundingClientRect().width,0)+c("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${E.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function Ee(t,e,n,s=ht()){const{m:i,tk:r,P:o,drawing:a,origin:c}=t,u=r.space,y=be(i,a,c,o),g=[...y.values()],l=c.left-Math.floor(c.left),p=c.top-Math.floor(c.top),x=pe(l,p),d=a.clientWidth,f=a.clientHeight,S={w:d,h:f,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:p},T=ht();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:T};const C=d-(parseFloat(getComputedStyle(a).paddingRight)||0),E=(M,O,N)=>{const G=[M];for(let W=1;W<=(yt(s,O)??0);W++)G.push({...M,t:M.t+N*u("4")*W,b:M.b+N*u("4")*W});return G},A=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>{const O=M.parentElement,N=ft(O,c),G=getComputedStyle(O);A.set(M.dataset.node,N.r-(parseFloat(G.paddingRight)||0)-(parseFloat(G.borderRightWidth)||0))});const j=i.nodes,Z=M=>y.get(j[M].id),B=[],ot=M=>Ct(i.edges[M].kind,r);i.edges.forEach((M,O)=>{const N=n.routes[O],G=y.get(M.from),W=y.get(M.to),Y=ot(O);let K=[];const m=M.label,b=m?e(m,"label"):0,h=m?16*Wt(m):16,k=u("4");if(N==="down"||N==="up"){const w=Math.max(G.rect.l,W.rect.l),_=Math.min(G.rect.r,W.rect.r),q=i.edges.map((z,D)=>({o:z,j:D})).filter(({o:z,j:D})=>(n.routes[D]==="down"||n.routes[D]==="up")&&(z.from===M.from&&z.to===M.to||z.from===M.to&&z.to===M.from)),R=q.findIndex(z=>z.j===O),Q=q.length<2?.5:q.length===2?R===0?.25:.75:(R+1)/(q.length+1),X=x.x(w+(_-w)*Q,Y);if(K=N==="down"?[lt(G,"bottom",X),lt(W,"top",X)]:[lt(G,"top",X),lt(W,"bottom",X)],m){let z=Math.min(K[0].y,K[1].y),D=Math.max(K[0].y,K[1].y);N==="down"?D-=r.head:z+=r.head;const tt=[...a.querySelectorAll(`.${o}-group`)].map(U=>ft(U,c));let at=[[z,D]];for(const U of tt)for(const et of[U.t,U.b])at=at.flatMap(([rt,ct])=>et>rt+1&&ettt.some(rt=>(U+et)/2>rt.t&&(U+et)/2rt.l&&X1){const U=at.filter(([rt,ct])=>!V(rt,ct));[z,D]=(U.length?U:at).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const P=[1/2,1/3,2/3].map(U=>{const et=z+(D-z)*U;return{l:X-b/2-u("1"),r:X+b/2+u("1"),t:et-h/2,b:et+h/2}});B.push({k:O,cands:P,on:!0,card:N==="down"?M.to:M.from})}}else if(N==="trunk"||N==="rail"){const w=x.x(Math.max(G.rect.l,N==="rail"?W.rect.l:G.rect.l)+u(N==="trunk"?"8":"3"),Y),_=lt(G,"bottom",w);if(N==="rail"){if(K=[_,lt(W,"top",w)],m){const q=W.rect.t-u("6");B.push({k:O,cands:E({l:w+u("2-5"),r:w+u("2-5")+b,t:q-h/2,b:q+h/2},M.to,-1),on:!1,card:M.to})}}else{const q=x.x(W.rect.l+u("6"),Y),R=x.y(W.rect.t-k,Y);K=[_,{x:w,y:R},{x:q,y:R},lt(W,"top",q)],m&&B.push({k:O,cands:E({l:q+u("2-5"),r:q+u("2-5")+b,t:R-h/2,b:R+h/2},M.to,-1),on:!1,card:M.to})}}else{const w=Math.min(A.get(M.from)??d,A.get(M.to)??d),_=x.x(n.gutter?C+(n.lanes[O]?2*u("3-5"):u("3-5")):w-u("2-5"),Y),q=x.y(G.rect.t+(G.rect.b-G.rect.t)*n.exits[O],Y),R=lt(G,"right",q),Q=x.x(W.rect.r-u("6"),Y),X=N==="end-down",z=x.y(X?W.rect.t-k:W.rect.b+k,Y);K=[R,{x:_,y:R.y},{x:_,y:z},{x:Q,y:z},lt(W,X?"top":"bottom",Q)];const D=X?M.to:j[W.i+1]?.id??M.to;m&&B.push({k:O,cands:E({l:Q-u("2-5")-b,r:Q-u("2-5"),t:z-h/2,b:z+h/2},D,X?-1:1),on:!1,card:D})}const $=ge(K,Y,x);S.lines.push({i:O,from:M.from,to:M.to,kind:M.kind,pts:$,tip:$[$.length-1],dir:Dt($),width:Y})}),S.crossings=Tt(S.lines),S.through=Gt(S.lines,g,i),S.outside=Se(S.lines,d,f,r);const{obstacles:L}=xe(a,c,o,0);L.heads=S.lines.map(M=>$e(M,r));const F=[],I={l:0,t:0,r:d,b:f};for(const M of B){const O=W=>{const Y=ue(W,u("1"));return W.lI.r+.5||W.tI.b+.5||g.some(K=>he(Y,K))||F.some(K=>ut(Y,K))||L.heads.some(K=>ut(Y,K))||L.rects.some(K=>ut(Y,K))||S.lines.some(K=>K.i!==M.k&&pt(K.pts).some(([m,b])=>ut(Y,we(m,b,K.width))))},N=M.cands.find(W=>!O(W));N||(T[M.card]=(T[M.card]??0)+1,S.unseated.push(M.k));const G=N?ve(N,l,p,W=>!O(W)):M.cands[0];F.push(G),S.labels.push({i:M.k,text:i.edges[M.k].label,box:G,on:M.on})}return{geo:S,grow:T}}function qn(t,e){const n=r=>String(Math.round(r*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let r=1;r({...E})),g=y[y.length-1];g.x-=r.x*u,g.y-=r.y*u;const l=e.tip.x-r.x*a,p=e.tip.y-r.y*a,x=-r.y*c,d=r.x*c,f=E=>Math.round(E*100)/100,S=it(e.kind),T=o?``:``,C=e.dot?``:"";return`${T}${C}`}function Ae(t,e,n,s){const i=new Map,r=new Map;for(const a of e.crossings)r.has(a.under)||r.set(a.under,[]),r.get(a.under).push(a);let o="";for(const[a,c]of r){const u=`${s}-cut-${a}`;i.set(a,u);const y=c.map(g=>{const l=e.lines[g.top],p=e.lines[g.under],x=l.width/2+n.cut,d=p.width/2+1;return g.underVertical?``:``}).join("");o+=`${y}`}return{defs:o,ids:i}}function Le(t,e,n,s){const{defs:i,ids:r}=Ae(t,e,n,s),o=e.lifelines.map(y=>``).join("")+(e.bars??[]).map(y=>``).join(""),a=e.lines.map((y,g)=>On(t,y,n,r.get(g)??null,y.from===y.to?n.radiusXs:n.radius)).join(""),c=`${i?`${i}`:""}${o}${a}`,u=e.labels.map(y=>`1?' data-lines="2"':""} style="left:${Math.round(y.box.l*100)/100}px;top:${Math.round(y.box.t*100)/100}px;width:${Math.round((y.box.r-y.box.l)*100)/100}px">${y.text.split(` +`).map(it).join("
")}
`).join("");return c+u}function Kt(t,e,n,s,i,r,o,a){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const y=mn(t),g=wn(u,n),l=vn(e,y,g);a?.(l.least);const p=t.clientWidth,x=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),d=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:x&&L.layout!=="drawn"?x:void 0};let f=!1;const S=L=>{if(f=!1,e.type!=="flowchart")return L;r({...L,heights:void 0,words:void 0});const F=ht(),I=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const O=M.querySelector(`.${n}-words`);if(!O)return;const N=M.getBoundingClientRect(),G=K=>{const m={w:K.width+2*y.space("2-5"),h:K.height+2*y.space("2")},b=1-m.w/N.width,h=b>.05?m.h/2/b:m.h*10;return Math.max(y.space("16"),Math.ceil(N.width/5),Math.ceil(2*h))},W=O.getBoundingClientRect();let Y=G(W);if(Y>N.width){const K=k=>(M.style.setProperty("--_ww",`${k}px`),O.getBoundingClientRect()),m=Math.floor(M.clientWidth-2*y.space("2-5"));let b=Math.ceil(W.width),h=W.height;for(;b1;){const q=k+$>>1;K(q).heightN.width&&(f=!0)}),{...L,heights:F,words:Object.keys(I).length?I:void 0}},T=()=>({m:e,tk:y,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:o}),C=i.autoOpen?{open:!1,autoOpen:void 0}:{},E=(L,F)=>F.map(I=>At(e,L.lines.find(M=>M.i===I))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:y,least:l.least};if(p>=l.least&&!e.unplaced){const L=O=>{let N=d({...i,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return N=S(N),r(N),{dd:N,g:En(T(),g)}};let{dd:F,g:I}=L(!1);const M=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||f;if(!M(I)&&I.unseated.length&&I.unseated.every(O=>I.bounded?.includes(O))){const O=L(!0);!M(O.g)&&!O.g.unseated.length&&({dd:F,g:I}=O)}if(!M(I)&&!I.unseated.length)return I.crossings.length&&o?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(O=>`${At(e,I.lines[O.top])} over ${At(e,I.lines[O.under])}`).join("; ")}`),{dyn:F,geo:I,ink:Le(n,I,y,s),tokens:y,least:l.least};f&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: a decision would be taller than it is wide`),I.misfit?.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: ${I.misfit.join("; ")}`),I.through.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: ${E(I,I.through)} would pass through a node`),I.overlaps?.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: ${E(I,I.overlaps)} would lie on one another`),I.outside.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: ${E(I,I.outside)} would leave the drawing`),I.unseated.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: no clean seat for ${I.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=d({...i,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(A=S(A),r(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:y,least:l.least};const j=se(e);let Z=Ee(T(),g,j,A.grow);for(let L=0;L<6&&Object.keys(Z.grow).length;L++){const F=ht(A.grow);for(const[I,M]of Object.entries(Z.grow))F[I]=(yt(F,I)??0)+M;A={...A,grow:F},r(A),Z=Ee(T(),g,j,F)}const B=Z.geo;if(B.unseated.length>0||B.through.length>0||B.outside.length>0||j.third){B.unseated.length&&o?.(`the stacked drawing has no clean seat for ${[...new Set(B.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),B.through.length&&o?.(`in the stacked drawing ${E(B,B.through)} would pass through a node, so its lines are not drawn`),B.outside.length&&o?.(`in the stacked drawing ${E(B,B.outside)} would leave the drawing, so its lines are not drawn`),j.third&&o?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={...B,lines:[],labels:[],crossings:[]};return{dyn:d({...A,grow:ht(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:y,least:l.least}}return B.crossings.length&&o?.(`${B.crossings.length} crossing${B.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${B.crossings.map(L=>`${At(e,B.lines[L.top])} over ${At(e,B.lines[L.under])}`).join("; ")}`),{dyn:A,geo:B,ink:Le(n,B,y,s),tokens:y,least:l.least}}function At(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function _n(t,e,n,s,i,r){const o=new Set;if(r){o.add(r);for(const d of n?.lines??[])d.from===r&&o.add(d.to),d.to===r&&o.add(d.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(d=>d.toggleAttribute("data-near",o.has(d.dataset.node))),!n||!s)return;const a=d=>!!r&&(d.from===r||d.to===r),c=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(d=>u.set(d.getAttribute("data-edge"),d));for(const d of n.lines){const f=u.get(String(d.i));f&&(f.toggleAttribute("data-lit",a(d)),f.toggleAttribute("data-dim",!!r&&!a(d)))}if(t.querySelectorAll(`.${e}-label`).forEach(d=>{const f=n.lines.find(S=>String(S.i)===d.dataset.edge);d.toggleAttribute("data-lit",!!(f&&a(f)))}),c){for(const d of n.lines)if(a(d)){const f=u.get(String(d.i));f&&c.appendChild(f)}}const y=Tt(n.lines,a),{defs:g,ids:l}=Ae(e,{...n,crossings:y},s,i),p=t.querySelector(`.${e}-svg`);if(!p)return;let x=p.querySelector("defs");!x&&g&&(x=document.createElementNS("http://www.w3.org/2000/svg","defs"),p.insertBefore(x,p.firstChild)),x&&(x.innerHTML=g),n.lines.forEach((d,f)=>{const S=u.get(String(d.i))?.querySelector(`.${e}-line`);if(!S)return;const T=l.get(f);T?S.setAttribute("mask",`url(#${T})`):S.removeAttribute("mask")})}var Cn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Bn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Cn()||jn(t)?"done":"pending")}}var Tn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function jn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Tn(t))!==null}catch{return!1}}function qe(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Rn(t,e,n,s=!1,i=!1){const r=s?Ot(t):null;if(r&&n.startsWith("Arrow")){const u={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?r[e]?.[u]??null:null}const o=t.byId.get(e)?.i??0,a=t.nodes.length;let c;if(n==="ArrowRight"||n==="ArrowDown")c=o+1;else if(n==="ArrowLeft"||n==="ArrowUp")c=o-1;else if(n==="Home")c=0;else if(n==="End")c=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,c))].id}var Wn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Ie=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],Nn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],Oe=t=>t==null||t===!1;function zn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function jt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?Ie:Wn;for(const o of s)Oe(e.a[o])&&t.removeAttribute(o);for(const[o,a]of Object.entries(e.a)){if(o==="class")continue;if(o==="style"){const u=t.style,y=new Map(String(a??"").split(";").map(g=>{const l=g.indexOf(":");return[g.slice(0,l).trim(),g.slice(l+1).trim()]}).filter(([g])=>g));for(const[g,l]of y)u.getPropertyValue(g).trim()!==l&&u.setProperty(g,l);for(const g of Nn)y.has(g)||u.removeProperty(g);continue}if(n&&!Ie.includes(o))continue;if(Oe(a)){t.removeAttribute(o);continue}const c=a===!0?"":String(a);t.getAttribute(o)!==c&&t.setAttribute(o,c)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(o=>typeof o!="string"&&"slot"in o))return;const i=[...t.children];let r=0;for(const o of e.c)if(!(typeof o=="string"||"slot"in o)){for(let a=r;at.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function i(l,p,x){return{prefix:n,base:l,hasSource:p.source!==void 0&&p.source!==null&&p.source!=="",hiddenClass:"visually-hidden",viewer:x?x.keys:void 0}}function r(l,p,x,d){var f=function(S){return''+it(S)+""};return{source:it(String(p.source||"")),summary:it(String(p.summary||"")),hint:Ht(l).map(function(S){return""+S.keys.map(f).join(" ")+" "+it(S.words)+""}).join(""),toggle:'"}}function o(l,p,x){var d=$t(l),f=_t(d,{},i(p,l,x)),S=Nt(f,r(d,l,p,!1)),T=S.indexOf(">");return{open:S.slice(0,T+1),inner:S.slice(T+1,S.length-9),warnings:d.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],c=["--_cols","--_gpad","--_track"];function u(l,p,x,d){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(l).direction==="rtl",T=p.layout==="auto"&&(p.type==="architecture"||p.type==="flowchart"||p.type==="schema"),C=T?Array.isArray(p.placement)?p.placement:p.placement?[p.placement]:[]:[];T&&!C.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var E=p.direction?[p.direction]:p.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var J=0;J .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var Z=o(p,f,d),B=document.createElement("div");B.innerHTML=Z.open+"";var ot=B.firstChild;a.forEach(function(H){l.removeAttribute(H)}),c.forEach(function(H){l.style.removeProperty(H)});for(var L=0;L :not(script[data-diagram])").forEach(function(H){H.remove()}),l.insertAdjacentHTML("beforeend",Z.inner)}j.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var I=i(f,p,d),M={},O=null,N=null,G=null,W=null,Y=Object.create(null),K=function(H){Y[H]||(Y[H]=1,console.warn("Basalt diagram: "+H))},m=function(H){jt(l,_t(j,H,I))},b=l.querySelector(".diagram-ink"),h=l.querySelector(".diagram-toggle"),k=!d&&j.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,_=function(){k&&qe(l)};function q(){_n(l,n,O&&O.geo,O&&O.tokens,f,N||W||G),X()}var R=null,Q=!d&&matchMedia("(hover: none), (pointer: coarse)").matches;function X(){var H=Q&&!d&&b&&b.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(Q&&!d)),H&&!R){var J=l.querySelector(":scope > .diagram-foot");if(!J)return;R=document.createElement("button"),R.type="button",R.className="btn diagram-clear",R.setAttribute("data-variant","secondary"),R.setAttribute("data-size","sm"),R.innerHTML="Clear highlight",R.addEventListener("click",function(){W&&(W=null,q())}),J.appendChild(R)}else!H&&R&&(R.remove(),R=null);R&&(W?R.removeAttribute("aria-disabled"):R.setAttribute("aria-disabled","true"))}function z(H){if(!H.defaultPrevented){var J=Ye(l,n,H,W);J!==void 0&&(_(),Q=!0,W=J,q())}}function D(){h&&(h.setAttribute("aria-expanded",String(!!M.open)),h.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function tt(){if(T&&C.length>1&&!d){for(var H=null,J=0;J1&&d&&!p.direction&&d.room){for(var We=d.room(),Ne=-1,Zt=null,Ut=0;UtNe+1e-6&&(Ne=Fe,Zt=Jt)}}}Zt&&(j=Zt)}O=(d?d.measure:Kt)(l,j,n,f,M,m,K),M=O.dyn,m(M),D();var Xt=l.querySelector(":scope > .diagram-hint");if(Xt){var He=Ht(j,M.layout==="drawn").map(function(St){return""+St.keys.map(function(Kn){return''+it(Kn)+""}).join(" ")+" "+it(St.words)+""}).join("");Xt.innerHTML!==He&&(Xt.innerHTML=He)}mt(j,M)||(G=W=null);var De=b&&O.ink!==w;De&&(b.innerHTML=O.ink,w=O.ink),q(),k&&O.tokens&&(Bn(l,!!(O.geo&&O.geo.lines.length)),De&&$&&$.redrawn()),d&&d.onMeasured&&O.tokens&&d.onMeasured(O,l),j.text&&typeof e.diagramText=="function"&&e.diagramText(l,j,p)}function at(H){M=H,m(M)}function V(H){var J=M.stop;M=Object.assign({},M,{stop:H}),Fn(l,n,J,H)}var P=function(H){var J=H&&H.closest?H.closest(".diagram-node"):null;return J&&l.contains(J)?J:null};function U(H){var J=P(H.target);if(!(!J||H.defaultPrevented)){if(_(),H.key==="Escape"){!d&&(N||G||W)&&(H.preventDefault(),N=G=W=null,q());return}if(mt(j,M)){var dt=Rn(j,J.getAttribute("data-node"),H.key,M.layout==="drawn");if(dt){H.preventDefault(),V(dt);var Mt=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');Mt&&Mt.focus()}}}}function et(H){var J=P(H.target);if(J){_();var dt=J.getAttribute("data-node");N=J.matches(":focus-visible")?dt:null,mt(j,M)&&M.stop!==dt&&V(dt),q()}}function rt(H){var J=P(H.target);J&&(P(H.relatedTarget)||(N=null),M.keep===J.getAttribute("data-node")&&at(Object.assign({},M,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var J=P(H.target);J&&_();var dt=J&&mt(j,M)?J.getAttribute("data-node"):null;dt!==G&&(G=dt,q())}}function Lt(){G&&(G=null,q())}function bt(){_(),at(Object.assign({},M,{open:!M.open,autoOpen:void 0})),D()}l.addEventListener("keydown",U),l.addEventListener("focusin",et),l.addEventListener("focusout",rt),l.addEventListener("pointerover",ct),l.addEventListener("pointerleave",Lt),l.addEventListener("click",z),h&&h.addEventListener("click",bt),tt();var kt=l.clientWidth,Vt=0,_e=!0,Ce=new ResizeObserver(function(){Math.abs(l.clientWidth-kt)<.5||(kt=l.clientWidth,cancelAnimationFrame(Vt),Vt=requestAnimationFrame(tt))});Ce.observe(l),document.fonts&&document.fonts.ready.then(function(){_e&&tt()});var Be=matchMedia("(forced-colors: active)"),Te=j.nodes.some(function(H){return H.mark});Te&&Be.addEventListener("change",tt),k&&($=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return j},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},p));var je=!d&&p.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,p,{model:j,settle:_,animated:k}):null,Re=l.querySelector(":scope > .diagram-foot"),Hn=!d&&p.export===!0&&Re&&typeof e.diagramExport=="function"?e.diagramExport(Re,l):[];l.__diagram={stop:function(){je&&je.destroy(),Hn.forEach(function(H){H.remove()}),_e=!1,Ce.disconnect(),cancelAnimationFrame(Vt),Te&&Be.removeEventListener("change",tt),$&&$.destroy(),l.removeEventListener("keydown",U),l.removeEventListener("focusin",et),l.removeEventListener("focusout",rt),l.removeEventListener("pointerover",ct),l.removeEventListener("pointerleave",Lt),l.removeEventListener("click",z),R&&R.remove(),h&&h.removeEventListener("click",bt)},layout:tt,key:y(p),send:$&&$.sendValue?$.sendValue:null}}function y(l){try{return JSON.stringify(l,function(p,x){return p==="packet"&&x&&typeof x=="object"?Object.assign({},x,{send:void 0}):x})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var p=l.querySelector(":scope > script[data-diagram]");if(p)try{u(l,JSON.parse(p.textContent),!0)}catch(x){console.error("Basalt diagram: this figure could not be drawn",x)}}})}e.diagramMarkup=o,e.diagramKit={draw:u,buildModel:$t,figureKey:on,figureList:un,hintEntries:Ht,toHtml:Nt,escapeHtml:it,settleEntrance:qe,measureFigure:Kt},t.diagram=function(l,p){var x=l.__diagram,d=x&&x.send?y(p):null;if(d!==null&&d===x.key){x.send(p.packet?p.packet.send:void 0);return}u(l,p)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); diff --git a/packages/react/src/architecture-diagram.tsx b/packages/react/src/architecture-diagram.tsx index 1fbd235a..b6d0eec4 100644 --- a/packages/react/src/architecture-diagram.tsx +++ b/packages/react/src/architecture-diagram.tsx @@ -2,22 +2,12 @@ import * as React from "react"; import { DiagramFigure } from "./diagram-figure"; import type { DiagramFigureProps } from "./diagram-figure"; -import type { ArchitectureNode, DiagramFlowEdge, DiagramGroup, DiagramPacket, DiagramPlacement } from "./diagram-core"; +import type { ArchitectureNode, DiagramFlowEdge, DiagramGroup, DiagramPacket, DiagramPlacement, DiagramUnplaced } from "./diagram-core"; -export type { ArchitectureNode, DiagramEdge, DiagramFlowEdge, DiagramGroup, DiagramLegend, DiagramLineKind, DiagramMark, DiagramMotion, DiagramNode, DiagramPacket, DiagramSide } from "./diagram-core"; +export type { ArchitectureNode, DiagramEdge, DiagramFlowEdge, DiagramGroup, DiagramLegend, DiagramLineKind, DiagramMark, DiagramMotion, DiagramNode, DiagramPacket, DiagramPlacement, DiagramSide, DiagramUnplaced } from "./diagram-core"; export type { DiagramFigureProps } from "./diagram-figure"; -export interface ArchitectureDiagramProps extends DiagramFigureProps { - /** - * `"auto"` (DECISIONS 306, 1.8): elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one; a - * card's `col` and `row` are left out (and not read). Place at build time with `placeDiagram` from `@srasyndicate/basalt/diagram-layout` and pass - * `placement`: then elkjs never loads in the browser. Without it the layout module loads on demand at 640 or wider. - */ - layout?: "authored" | "auto"; - /** Under `"auto"`: the one direction tried. Left out, the type's own (right for an architecture and a schema, down for a flowchart), then the other. */ - direction?: "right" | "down"; - /** Under `"auto"`: `placeDiagram`'s answer for one direction or both. */ - placement?: DiagramPlacement | DiagramPlacement[]; +interface ArchitectureDiagramBase extends DiagramFigureProps { /** The parts, in the author's order: the stacked order, the focus order and the list's. `col` and `row` place each in the drawn layout. */ nodes: ArchitectureNode[]; /** One level of grouping: `group: "aws"` on the members and `{ id, label }` here. The box is derived from its members. */ @@ -30,8 +20,28 @@ export interface ArchitectureDiagramProps extends DiagramFigureProps { packet?: DiagramPacket; } +/** + * Authored (the default): every card carries its `col` and `row`. Automatic (`layout: "auto"`, DECISIONS 306, 1.8): no card needs them, and none are read. + */ +export type ArchitectureDiagramProps = Omit & ( + | { layout?: "authored"; direction?: never; placement?: never; nodes: ArchitectureNode[] } + | { + /** + * `"auto"` (DECISIONS 306, 1.8): elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one; a + * card's `col` and `row` are left out (and not read). Place at build time with `placeDiagram` from `@srasyndicate/basalt/diagram-layout` and pass + * `placement`: then elkjs never loads in the browser. Without it the layout module loads on demand at 640 or wider. + */ + layout: "auto"; + /** Under `"auto"`: the one direction tried. Left out, the type's own (right for an architecture and a schema, down for a flowchart), then the other. */ + direction?: "right" | "down"; + /** Under `"auto"`: `placeDiagram`'s answer for one direction or both. */ + placement?: DiagramPlacement | DiagramPlacement[]; + nodes: Array>; + } +); + /** An architecture diagram (DECISIONS 281): nodes with a kind, a name and a detail, groups, and three kinds of line. */ export function ArchitectureDiagram({ nodes, groups, edges, pulse, packet, motion, entrance, layout, direction, placement, title, heading, legend, ...props }: ArchitectureDiagramProps) { - const spec = React.useMemo(() => ({ type: "architecture" as const, title, heading, legend, nodes, groups, edges, motion, entrance, layout, direction, placement, pulse, packet }), [title, heading, legend, nodes, groups, edges, motion, entrance, layout, direction, placement, pulse, packet]); + const spec = React.useMemo(() => ({ type: "architecture" as const, title, heading, legend, nodes: nodes as ArchitectureNode[], groups, edges, motion, entrance, layout, direction, placement, pulse, packet }), [title, heading, legend, nodes, groups, edges, motion, entrance, layout, direction, placement, pulse, packet]); return ; } diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index c3c53c88..2eec1e4e 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -130,6 +130,9 @@ export interface DiagramSpec { placement?: DiagramPlacement | DiagramPlacement[]; } +/** A card of an automatic figure (1.8): its `col` and `row` may be left out (and are not read). */ +export type DiagramUnplaced = Omit & { col?: number; row?: number | [number, number] }; + /** Where an automatic figure's cards go in one direction (1.8): `placeDiagram`'s answer. */ export interface DiagramPlacement { direction: "right" | "down"; cells: Record } diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 1f9ebeab..d7f5b6bc 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -112,6 +112,8 @@ export interface DiagramViewerMode { measure: (fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn?: (s: string) => void) => Measured; /** The words the keys sentence ends with. */ keys: string; + /** The stage's inner size: an automatic figure takes the direction with the larger Fit in it (9.3). */ + room: () => { w: number; h: number }; /** After every layout: what was measured, and the figure. */ onMeasured: (measured: Measured, fig: HTMLElement) => void; } @@ -206,6 +208,21 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: } if (pick !== dirAt) { setDirAt(pick); return; } } + // In the viewer, an automatic figure with no named direction takes the direction with the larger Fit in this stage; a tie keeps the type's own (9.3). + if (auto && placements.length > 1 && viewer && !spec.direction) { + const room = viewer.room(); + let pick = 0, best = -1; + for (let k = 0; k < order.length; k++) { + const place = placementFor(k); + if (!place) continue; + const trial = buildModel(spec, { rtl, placement: place }); + const t = viewer.measure(fig, trial, P, base, {}, (d) => syncAttributes(fig, figureTree(trial, d, options))); + if (t.dyn.layout !== "drawn") continue; + const fit = Math.min(room.w / fig.offsetWidth, room.h / fig.offsetHeight); + if (fit > best + 1e-6) { best = fit; pick = k; } + } + if (pick !== dirAt) { setDirAt(pick); return; } + } const warn = process.env.NODE_ENV !== "production" ? (message: string) => warnOnce(component, message) : undefined; const apply = (d: Dyn) => syncAttributes(fig, figureTree(model, d, options)); const result = (viewer ? viewer.measure : measureFigure)(fig, model, P, base, dynRef.current, apply, warn); diff --git a/packages/react/src/diagram-motion-core.ts b/packages/react/src/diagram-motion-core.ts index dd1d861b..079253c4 100644 --- a/packages/react/src/diagram-motion-core.ts +++ b/packages/react/src/diagram-motion-core.ts @@ -792,9 +792,24 @@ class Figure implements MotionController { this.publish(); }; + /** + * A run's unreached messages are quiet (DECISIONS 306, 1.2): every message after the current one has its label in secondary ink and its line and head in + * diagram-edge-dim; its number and note are unchanged. -1 restores them all at once. + */ + private quiet(current: number, lines: GLine[]) { + const P = this.host.P, fig = this.host.fig; + const msgs = fig.querySelectorAll(`.${P}-msg`); + lines.forEach((l, k) => { + const ahead = current >= 0 && k > current; + msgs[k]?.toggleAttribute("data-ahead", ahead); + fig.querySelector(`.${P}-edge[data-edge="${l.i}"]`)?.toggleAttribute("data-ahead", ahead); + }); + } + private stopRun() { this.runGen++; this.runAt = -1; + this.host.fig.querySelectorAll("[data-ahead]").forEach((el) => el.removeAttribute("data-ahead")); for (const a of this.runAnims) a.cancel(); this.runAnims.clear(); if (this.dot && this.dotOwner === "run") { this.dot.style.display = "none"; this.dotOwner = null; } @@ -818,6 +833,7 @@ class Figure implements MotionController { for (let k = from; k < lines.length; k++) { if (!live()) return; this.runAt = k; + this.quiet(k, lines); const l = lines[k]!; const stops = [msgs[k] ?? null, this.node(l.to)]; if (matchMedia("(prefers-reduced-motion: reduce)").matches) { @@ -831,7 +847,7 @@ class Figure implements MotionController { for (const s of stops) this.depart(s); } else await this.leg(l, this.runAnims, live, stops); } - if (live()) { this.runAt = -1; this.publish(); } + if (live()) { this.runAt = -1; this.quiet(-1, lines); this.publish(); } }; go().catch((e) => { if (!aborted(e)) throw e; }); } diff --git a/packages/react/src/diagram-viewer.tsx b/packages/react/src/diagram-viewer.tsx index 2dd66d9a..67fd7a55 100644 --- a/packages/react/src/diagram-viewer.tsx +++ b/packages/react/src/diagram-viewer.tsx @@ -115,6 +115,11 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o if (!(avail > 0) || !layer) return undefined; return { keys: VIEWER_KEYS, + room: () => { + const stage = stageRef.current, sizer = sizerRef.current; + const pad = sizer ? Number.parseFloat(getComputedStyle(sizer).paddingTop) || 0 : 0; + return { w: (stage?.clientWidth ?? 0) - 2 * pad, h: (stage?.clientHeight ?? 0) - 2 * pad }; + }, onMeasured, measure: (fig, m, p, base, current, apply, warn) => measureViewerFigure(fig, m, p, base, current, apply, warn, { layer, avail, row: dims.row, contain: dims.contain, memo: memo.current, measureFigure }), }; diff --git a/packages/react/src/flowchart-diagram.tsx b/packages/react/src/flowchart-diagram.tsx index c9cf5544..585d37da 100644 --- a/packages/react/src/flowchart-diagram.tsx +++ b/packages/react/src/flowchart-diagram.tsx @@ -2,21 +2,11 @@ import * as React from "react"; import { DiagramFigure } from "./diagram-figure"; import type { DiagramFigureProps } from "./diagram-figure"; -import type { DiagramEdge, DiagramShapeLabels, FlowchartNode, DiagramPlacement } from "./diagram-core"; +import type { DiagramEdge, DiagramShapeLabels, FlowchartNode, DiagramPlacement, DiagramUnplaced } from "./diagram-core"; export type { DiagramEdge, DiagramLegend, DiagramLineKind, DiagramShapeLabels, DiagramSide, FlowchartNode } from "./diagram-core"; -export interface FlowchartDiagramProps extends DiagramFigureProps { - /** - * `"auto"` (DECISIONS 306, 1.8): elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one; a - * card's `col` and `row` are left out (and not read). Place at build time with `placeDiagram` from `@srasyndicate/basalt/diagram-layout` and pass - * `placement`: then elkjs never loads in the browser. Without it the layout module loads on demand at 640 or wider. - */ - layout?: "authored" | "auto"; - /** Under `"auto"`: the one direction tried. Left out, the type's own (right for an architecture and a schema, down for a flowchart), then the other. */ - direction?: "right" | "down"; - /** Under `"auto"`: `placeDiagram`'s answer for one direction or both. */ - placement?: DiagramPlacement | DiagramPlacement[]; +interface FlowchartDiagramBase extends DiagramFigureProps { /** The steps in the author's order; the first is the start. A shape carries the type: a step (the default), a decision or a terminal. */ nodes: FlowchartNode[]; /** The lines, by node id. A branch's label is its condition; `main` is the usual path. */ @@ -25,8 +15,28 @@ export interface FlowchartDiagramProps extends DiagramFigureProps { shapeLabels?: DiagramShapeLabels; } +/** + * Authored (the default): every card carries its `col` and `row`. Automatic (`layout: "auto"`, DECISIONS 306, 1.8): no card needs them, and none are read. + */ +export type FlowchartDiagramProps = Omit & ( + | { layout?: "authored"; direction?: never; placement?: never; nodes: FlowchartNode[] } + | { + /** + * `"auto"` (DECISIONS 306, 1.8): elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one; a + * card's `col` and `row` are left out (and not read). Place at build time with `placeDiagram` from `@srasyndicate/basalt/diagram-layout` and pass + * `placement`: then elkjs never loads in the browser. Without it the layout module loads on demand at 640 or wider. + */ + layout: "auto"; + /** Under `"auto"`: the one direction tried. Left out, the type's own (right for an architecture and a schema, down for a flowchart), then the other. */ + direction?: "right" | "down"; + /** Under `"auto"`: `placeDiagram`'s answer for one direction or both. */ + placement?: DiagramPlacement | DiagramPlacement[]; + nodes: Array>; + } +); + /** A flowchart (DECISIONS 281): shape carries type, so every shape has a 3:1 contour; a decision is a diamond behind its words. */ export function FlowchartDiagram({ nodes, edges, shapeLabels, motion, entrance, layout, direction, placement, title, heading, legend, ...props }: FlowchartDiagramProps) { - const spec = React.useMemo(() => ({ type: "flowchart" as const, title, heading, legend, nodes, edges, shapeLabels, motion, entrance, layout, direction, placement }), [title, heading, legend, nodes, edges, shapeLabels, motion, entrance, layout, direction, placement]); + const spec = React.useMemo(() => ({ type: "flowchart" as const, title, heading, legend, nodes: nodes as FlowchartNode[], edges, shapeLabels, motion, entrance, layout, direction, placement }), [title, heading, legend, nodes, edges, shapeLabels, motion, entrance, layout, direction, placement]); return ; } diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index f2a0909f..d55cf43e 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -93,7 +93,7 @@ export { ChartGroup, TimeChart } from "./chart"; export { trailingMean } from "./trailing-mean"; export type { ChartGroupProps, ChartKind, ChartLaneGeometry, ChartPlan, ChartSeries, TimeChartProps } from "./chart"; export { ArchitectureDiagram } from "./architecture-diagram"; -export type { ArchitectureDiagramProps, ArchitectureNode, DiagramEdge, DiagramFigureProps, DiagramFlowEdge, DiagramGroup, DiagramLegend, DiagramLineKind, DiagramMark, DiagramMotion, DiagramNode, DiagramPacket, DiagramSide } from "./architecture-diagram"; +export type { ArchitectureDiagramProps, ArchitectureNode, DiagramEdge, DiagramFigureProps, DiagramFlowEdge, DiagramGroup, DiagramLegend, DiagramLineKind, DiagramMark, DiagramMotion, DiagramNode, DiagramPacket, DiagramPlacement, DiagramSide, DiagramUnplaced } from "./architecture-diagram"; export { FlowchartDiagram } from "./flowchart-diagram"; export type { DiagramShapeLabels, FlowchartDiagramProps, FlowchartNode } from "./flowchart-diagram"; export { DataFlowDiagram } from "./data-flow-diagram"; diff --git a/packages/react/src/schema-diagram.tsx b/packages/react/src/schema-diagram.tsx index 6231e4e8..5b8fd2b0 100644 --- a/packages/react/src/schema-diagram.tsx +++ b/packages/react/src/schema-diagram.tsx @@ -2,21 +2,11 @@ import * as React from "react"; import { DiagramFigure } from "./diagram-figure"; import type { DiagramFigureProps } from "./diagram-figure"; -import type { SchemaTable, DiagramPlacement } from "./diagram-core"; +import type { SchemaTable, DiagramPlacement, DiagramUnplaced } from "./diagram-core"; export type { DiagramLegend, SchemaColumn, SchemaTable } from "./diagram-core"; -export interface SchemaDiagramProps extends DiagramFigureProps { - /** - * `"auto"` (DECISIONS 306, 1.8): elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one; a - * card's `col` and `row` are left out (and not read). Place at build time with `placeDiagram` from `@srasyndicate/basalt/diagram-layout` and pass - * `placement`: then elkjs never loads in the browser. Without it the layout module loads on demand at 640 or wider. - */ - layout?: "authored" | "auto"; - /** Under `"auto"`: the one direction tried. Left out, the type's own (right for an architecture and a schema, down for a flowchart), then the other. */ - direction?: "right" | "down"; - /** Under `"auto"`: `placeDiagram`'s answer for one direction or both. */ - placement?: DiagramPlacement | DiagramPlacement[]; +interface SchemaDiagramBase extends DiagramFigureProps { /** * The tables in the author's order. A foreign key is `references: "incidents.id"` on its column and nothing else: the row's "→ incidents", * the line, the sentence and the list all come from it. The referenced column must be one of the shown columns. @@ -24,8 +14,28 @@ export interface SchemaDiagramProps extends DiagramFigureProps { tables: SchemaTable[]; } +/** + * Authored (the default): every card carries its `col` and `row`. Automatic (`layout: "auto"`, DECISIONS 306, 1.8): no card needs them, and none are read. + */ +export type SchemaDiagramProps = Omit & ( + | { layout?: "authored"; direction?: never; placement?: never; tables: SchemaTable[] } + | { + /** + * `"auto"` (DECISIONS 306, 1.8): elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one; a + * card's `col` and `row` are left out (and not read). Place at build time with `placeDiagram` from `@srasyndicate/basalt/diagram-layout` and pass + * `placement`: then elkjs never loads in the browser. Without it the layout module loads on demand at 640 or wider. + */ + layout: "auto"; + /** Under `"auto"`: the one direction tried. Left out, the type's own (right for an architecture and a schema, down for a flowchart), then the other. */ + direction?: "right" | "down"; + /** Under `"auto"`: `placeDiagram`'s answer for one direction or both. */ + placement?: DiagramPlacement | DiagramPlacement[]; + tables: Array>; + } +); + /** A database schema (DECISIONS 281): table cards with keys and a few columns; drawn, a line from each foreign key to the key it references. */ export function SchemaDiagram({ tables, motion, entrance, layout, direction, placement, title, heading, legend, ...props }: SchemaDiagramProps) { - const spec = React.useMemo(() => ({ type: "schema" as const, title, heading, legend, tables, motion, entrance, layout, direction, placement }), [title, heading, legend, tables, motion, entrance, layout, direction, placement]); + const spec = React.useMemo(() => ({ type: "schema" as const, title, heading, legend, tables: tables as SchemaTable[], motion, entrance, layout, direction, placement }), [title, heading, legend, tables, motion, entrance, layout, direction, placement]); return ; } diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 0d9079af..52dc3740 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -5029,6 +5029,20 @@ /* While a figure is read for a file (diagram-export), nothing in it transitions, so a theme it is read in applies at once. */ .basalt-exporting, .basalt-exporting * { transition: none !important; } + /* A run's unreached messages are quiet (DECISIONS 306, 1.2): label secondary, line and head diagram-edge-dim; number and note unchanged. Stopping, + finishing, printing or tracing restores them at once; the ink changes over duration-fast on ease-out. No opacity. */ + .basalt-diagram-msg[data-ahead] .basalt-diagram-mlabel { color: var(--basalt-text-secondary); transition: color var(--basalt-duration-fast) var(--basalt-ease-out); } + .basalt-diagram-edge[data-ahead] .basalt-diagram-line { stroke: var(--basalt-diagram-edge-dim); } + .basalt-diagram-edge[data-ahead] .basalt-diagram-tip:not([data-open]) { fill: var(--basalt-diagram-edge-dim); } + .basalt-diagram-edge[data-ahead] .basalt-diagram-tip[data-open] { stroke: var(--basalt-diagram-edge-dim); } + @media (forced-colors: active) { + .basalt-diagram .basalt-diagram-msg[data-ahead] .basalt-diagram-mlabel { color: GrayText; } + .basalt-diagram .basalt-diagram-edge[data-ahead] .basalt-diagram-line { stroke: GrayText; } + } + @media print { + .basalt-diagram .basalt-diagram-msg[data-ahead] .basalt-diagram-mlabel { color: var(--basalt-text-primary) !important; } + } + /* ---- Diagram motion (DECISIONS 292): the entrance, flow, the pulse, the packet, the arrival step and the foot's two buttons ---- Only on a figure that asks for it (data-motion="animated"); a still figure is the drawing above, unchanged. The motion code is a module of its own (diagram-motion), loaded on demand; the still engine marks a figure pending in the frame its lines are first drawn (data-entrance). Every diff --git a/tools/html-skill/src/modules/diagram-zoom.js b/tools/html-skill/src/modules/diagram-zoom.js index 9746261f..512901b2 100644 --- a/tools/html-skill/src/modules/diagram-zoom.js +++ b/tools/html-skill/src/modules/diagram-zoom.js @@ -64,6 +64,7 @@ import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } fr var memo = {}; var view = { layer: layer, avail: 0, row: 1104, contain: 480, memo: memo, measureFigure: kit.measureFigure, keys: VIEWER_KEYS, + room: function () { var pad = parseFloat(getComputedStyle(sizer).paddingTop) || 0; return { w: stage.clientWidth - 2 * pad, h: stage.clientHeight - 2 * pad }; }, measure: function (f, m, p, base, current, apply, warn) { return measureViewerFigure(f, m, p, base, current, apply, warn, view); }, onMeasured: function (measured, f) { stage.setAttribute('data-layout', measured.dyn.layout || ''); diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 68fc030b..74909a79 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -141,6 +141,20 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, } model = chosen || buildModel(spec, { rtl: rtl, placement: placeOf(order[0]) }); } + // In the viewer, the direction with the larger Fit in the stage; a tie keeps the type's own (DECISIONS 310, 9.3). + if (auto && placements.length > 1 && viewer && !spec.direction && viewer.room) { + var room = viewer.room(), best = -1, pickM = null; + for (var j = 0; j < order.length; j++) { + var pl = placeOf(order[j]); + if (!pl) continue; + var tm = buildModel(spec, { rtl: rtl, placement: pl }); + var tr = viewer.measure(figure, tm, P, base, {}, function (d) { syncAttributes(figure, figureTree(tm, d, opts)); }); + if (tr.dyn.layout !== 'drawn') continue; + var fit = Math.min(room.w / figure.offsetWidth, room.h / figure.offsetHeight); + if (fit > best + 1e-6) { best = fit; pickM = tm; } + } + if (pickM) model = pickM; + } // The viewer's figure (DECISIONS 310, the diagram-zoom module) is laid out at the stage's width and measured only at 100%. measured = (viewer ? viewer.measure : measureFigure)(figure, model, P, base, state, apply, warn); state = measured.dyn; From 9f725c1da3a935f755bd533988aa267e7e253ca3 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:59:36 -0600 Subject: [PATCH 32/62] Section 4's calls 2 and 3: a one-column schema's turn-back lanes, and cards that grow to hold their ports Call 2: a one-column schema's turn-backs that run beside each other take lanes space-3 apart, nested (the farther-going outermost), lines to one key sharing one; two lanes at most, the padding growing from space-5 to space-5 plus space-3, and a third line not drawn (its row still writes the target; a development build names it). Call 3: the builder's slot sharing stands, and a card grows to the least height at which every port on its start or end side is off its corners and size-diagram-head from the next (48 for a straight line and two others, 64 for an extra beside a straight pair), from the data alone, so a side never stacks a figure; a development build says "use another side". Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 16 ++-- packages/react/src/diagram-core.ts | 86 ++++++++++++++++++++- packages/react/src/styles/components.css | 3 + 4 files changed, 94 insertions(+), 13 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index 61a2ed1c..b56f9625 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node{--_Mh: var(--_D) var(--_mh, auto);min-height:var(--_Mh, auto)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index d137f230..3cfde76d 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,12 +1,12 @@ -(()=>{var Ge=["top","right","bottom","left"],Ke=["main","plain","dashed"],Ve=[2,3,4,5,6],st=t=>t==null||t===""?void 0:String(t),ht=t=>Object.assign(Object.create(null),t),yt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function $t(t,e={}){const s=e.checks!==!1,i=[],r=m=>{i.push(m)},o=t.legend??{},a={};for(const m of["main","plain","dashed","focal","group","activation"]){const b=st(o[m]);b&&(a[m]=b)}const c=t.stepLabel,u=typeof c=="function"?m=>String(c(m)):typeof c=="string"?(m=>c.replace("{n}",String(m))):m=>`Step ${m}`,y=t.shapeLabels??{},g={terminal:st(y.terminal)??"Start or end",step:st(y.step)??"Step",decision:st(y.decision)??"Decision"},l=t.heading===void 0?3:Ve.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),p=(m,b)=>m==null?"plain":Ke.includes(m)?m:(r(`"${String(m)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),x=m=>{if(m!=null){if(Ge.includes(m))return m;r(`"${String(m)}" is not a side (top, right, bottom or left): the derived side is used`)}},d=(m,b)=>typeof m=="number"&&Number.isInteger(m)&&m>=1?m:(t.layout==="auto"&&m==null||r(`${b} is ${JSON.stringify(m)}, not a whole number from 1: it is placed at 1`),1),f=[],S=[];let T=[];const C=[],E=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||r(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const m of t.nodes??[]){const b=A==="flowchart"&&m.shape==="decision"?"decision":A==="flowchart"&&m.shape==="terminal"?"terminal":"box",h=String(m.id??""),k=d(m.row,`the row of ${h}`);f.push({id:h,i:f.length,name:String(m.name??""),kind:b==="decision"?void 0:st(m.kind),detail:b==="decision"?void 0:st(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:d(m.col,`the column of ${h}`),row:k,row2:k,branch:!!m.branch,shape:b,group:A==="architecture"?st(m.group):void 0,mark:A==="architecture"?Rt(m.mark):void 0})}if(A==="architecture"){const m=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:st($.parent)})),b=new Map(m.map($=>[$.id,$])),h=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(r(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(r(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(r(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},k=m.map(h);m.forEach(($,w)=>C.push({...$,depth:k[w],members:f.filter(_=>_.group===$.id).map(_=>_.id),all:[]}));for(const $ of C)$.all=[...$.members,...C.filter(w=>w.parent===$.id).flatMap(w=>w.members)];C.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){T=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const m=new Map(T.map((b,h)=>[b.id,h+1]));for(const b of t.nodes??[]){const h=String(b.id??""),k=String(b.lane??""),$=m.get(k);$===void 0&&r(`a node (${h}) names the lane "${k}", which is not in lanes`);const w=f.length+1;f.push({id:h,i:f.length,name:String(b.name??""),kind:u(w),detail:st(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:d(b.col,`the column of ${h}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:T[($??1)-1]?.label??k,step:w,mark:Rt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((k,$)=>{const w=String(k.name??"");f.push({id:String(k.id??""),i:$,name:w,kind:st(k.kind),mono:!1,focal:!!k.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:st(k.short)??w,mark:Rt(k.mark)})});let m=0;const b=new Map(f.map(k=>[k.id,k.col])),h=(k,$)=>{let w=1/0,_=-1/0;for(const q of k??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&r(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),E.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){r("a frame is a third level: frames nest two deep");continue}const at=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=at==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];at==="alt"&&V.length<2&&r("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&r(`the frame label "${P}" is over 40 characters`);const U=E.length;E.push({open:at,label:P,depth:$+1,a:0,b:0}),V.forEach((et,rt)=>{if(rt){const kt=String(et.label??"");kt.length>40&&r(`the frame label "${kt}" is over 40 characters`),E.push({otherwise:kt,depth:$+1})}et.steps?.length||r(`a frame or branch ("${String(et.label??"")}") is empty`);const[ct,Lt]=h(et.steps??[],$+1);w=Math.min(w,ct),_=Math.max(_,Lt);const bt=E[U];bt.a=Math.min(bt.a||1/0,ct),bt.b=Math.max(bt.b,Lt)}),E.push({close:$+1});continue}m++;const R=String(q.label??"");R.includes(` -`)&&r(`message ${m}'s label has a break: a message's second line is its note`);const Q=String(q.from??""),X=String(q.to??"");E.push({n:m,from:Q,to:X,label:gt(R),note:st(q.note),kind:p(q.kind,`message ${m}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const z=b.get(Q)??1,D=b.get(X)??1,tt=z===D?z===f.length?z-1:z+1:z;w=Math.min(w,z,D,tt),_=Math.max(_,z,D,tt)}return[w,_]};h(t.steps??[],0);for(const k of E)"open"in k&&!Number.isFinite(k.a)&&(k.a=1,k.b=Math.max(1,f.length))}else if(A==="schema")for(const m of t.tables??[]){const b=String(m.name??""),[h,k]=Array.isArray(m.row)?m.row:[m.row,m.row],$=d(h,`the row of ${b}`),w=Math.max($,d(k,`the last row of ${b}`)),_=m.more===void 0||m.more===null?void 0:Number.isInteger(m.more)&&m.more>0?m.more:(r(`${b}'s "more" is ${JSON.stringify(m.more)}, not a whole number from 1: it is left out`),void 0);f.push({id:b,i:f.length,name:b,mono:!0,focal:!!m.focal,col:d(m.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:_,columns:(m.columns??[]).map(q=>({name:String(q.name??""),type:st(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&r(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let j=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const m=A==="schema"?t.tables:t.nodes;s&&(m??[]).some(h=>h&&(h.col!==void 0||h.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(j=!0);for(const h of f){const k=b?.[h.id];h.col=k?.col??1,h.row=h.row2=k?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((m,b)=>{if(!m||m.href===void 0||m.href===null)return;const h=String(m.href);if(A==="sequence"){r(`${f[b]?.id}: a participant cannot be a link (href)`);return}if(!h){r(`${f[b]?.id}'s href is empty`);return}const k=f[b];k&&(k.href=h,k.blank=m.target==="_blank")});const B=new Map;for(const m of f)m.id?B.has(m.id)&&r(`the id "${m.id}" is used twice`):r("a node has no id"),B.set(m.id,m);if(A==="schema")(t.tables??[]).forEach(m=>(m.columns??[]).forEach((b,h)=>{const k=st(b.references);if(!k)return;const[$,w]=k.split("."),_=B.get($??""),q=_?.columns?.findIndex(Q=>Q.name===w)??-1;if(!_||q<0){r(`${String(m.name)}.${String(b.name)} references ${k}, which is not a shown column`);return}const R=B.get(String(m.name??""));R.columns[h].ref={table:$,column:w,row:q},S.push({i:S.length,from:R.id,to:$,kind:"plain",fromRow:h,toRow:q,fk:!0})}));else if(A!=="sequence")for(const m of t.edges??[]){const b=String(m.from??""),h=String(m.to??"");if(!B.has(b)||!B.has(h)){r(`a line names ${B.has(b)?h:b}, which is not a node`);continue}const k=st(m.label),$=k?.split(` -`)??[];$.length>2&&r(`the label "${gt(k)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>Qt)&&r(`a line of the label "${gt(k)}" is over ${Qt} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:h,kind:p(m.kind,`the line from ${b} to ${h}`),label:k,fromSide:x(m.fromSide),toSide:x(m.toSide),flow:A!=="flowchart"&&m.flow===!0?!0:void 0})}else for(const m of E)"n"in m&&(!B.has(m.from)||!B.has(m.to))&&r(`message ${m.n} names ${B.has(m.from)?m.to:m.from}, which is not a participant`);if(s&&A!=="sequence"&&!j){const m=new Map;for(const b of f)for(let h=b.row;h<=b.row2;h++){const k=`${b.col}:${h}`;m.has(k)&&r(`${b.id} and ${m.get(k)} share the cell at column ${b.col}, row ${h}`),m.set(k,b.id)}}if(s&&!j){for(const b of C){const h=b.all.map(w=>B.get(w));if(!h.length)continue;const k={c1:Math.min(...h.map(w=>w.col)),c2:Math.max(...h.map(w=>w.col)),r1:Math.min(...h.map(w=>w.row)),r2:Math.max(...h.map(w=>w.row2))};for(const w of f)!b.all.includes(w.id)&&w.col>=k.c1&&w.col<=k.c2&&w.row>=k.r1&&w.row<=k.r2&&r(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=h.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&r(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of f)b.group&&!C.some(h=>h.id===b.group)&&r(`${b.id} names the group "${b.group}", which is not in groups`);f.filter(b=>b.focal).length>1&&r("more than one node is focal: a diagram has one at most");const m=new Set(A==="sequence"?E.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));m.has("main")&&!a.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),m.has("dashed")&&!a.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),f.some(b=>b.focal)&&!a.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const ot=A==="architecture"||A==="data-flow",L=m=>Array.isArray(m)&&m.length>1?m.map(String):void 0,F=ot&&t.packet&&typeof t.packet=="object"?t.packet:void 0,I=F&&L(F.path),M={animated:t.motion==="animated",pulse:ot?L(t.pulse):void 0,packet:I?{path:I,repeat:F.repeat===!0,send:F.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const m of f){const b=m.mark?.says;if(!b?.length)continue;const h=[m.name,m.kind,m.detail,m.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(k=>h.includes(k.toLowerCase()))||r(`${m.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const m=new Map,b=new Map;for(const h of E)"n"in h&&(b.set(h.from,h.n),b.set(h.to,h.n));for(const h of E)if("n"in h){if(h.activate){const k=m.get(h.to)??[];if(k.length>=3)r(`message ${h.n} opens a fourth bar on ${h.to}: three deep at most`);else{const $={who:h.to,from:h.n,to:h.n,depth:k.length+1};k.push($),O.push($),m.set(h.to,k)}}if(h.deactivate){const $=m.get(h.from)?.pop();$?$.to=h.n:r(`message ${h.n} closes a bar on ${h.from}, which has none open`)}}for(const[h,k]of m)for(const $ of k)$.to=Math.max($.from,b.get(h)??$.from)}const N=t.frameLabels??{},G={opt:st(N.opt)??"Only if",loop:st(N.loop)??"Repeats",alt:st(N.alt)??"One of these",else:st(N.else)??"Otherwise"};let W=Math.max(1,...f.map(m=>m.col));if(e.rtl){for(const b of f)b.col=W-b.col+1;const m=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=m(b.fromSide),b.toSide=m(b.toSide);for(const b of E)if("open"in b){const[h,k]=[W-b.b+1,W-b.a+1];b.a=h,b.b=k}W=Math.max(1,...f.map(b=>b.col))}const Y=A==="data-flow"?Math.max(1,T.length):Math.max(1,...f.map(m=>m.row2)),K={type:A,title:String(t.title??""),heading:l,legend:a,nodes:f,byId:B,edges:S,groups:C,lanes:T,steps:E,bars:O,frameWords:G,cols:W,rows:Y,shapeLabels:g,stepWord:u,warnings:i,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:j||void 0,text:A==="sequence"&&t.variant==="text"||void 0};return t.layout==="auto"&&!j&&A!=="schema"&&Ze(K),s&&f.length>1&&!Ot(K)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function Ze(t){const e=new Set(t.nodes.map(o=>`${o.col},${o.row}`)),n=(o,a)=>{const c=[];for(let u=Math.min(o,a)+1;u{const a=t.byId.get(o.from),c=t.byId.get(o.to),u=c.col>a.col?"right":"left",y=c.row>a.row?"bottom":"top",g=c.col>a.col?"left":"right",l=c.row>a.row?"top":"bottom",p=(d,f,S,T)=>n(d,f).map(C=>T?[C,S]:[S,C]);let x;return a.row===c.row?x=[{sides:[u,g],cells:p(a.col,c.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===c.col?x=[{sides:[y,l],cells:p(a.row,c.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:x=[{sides:[u,l],cells:[...p(a.col,c.col,a.row,!0),[c.col,a.row],...p(a.row,c.row,c.col,!1)]},{sides:[y,g],cells:[...p(a.row,c.row,a.col,!1),[a.col,c.row],...p(a.col,c.col,c.row,!0)]},{sides:[u,g],cells:p(a.col,c.col,a.row,!0)},{sides:[y,l],cells:p(a.row,c.row,a.col,!1)}],x.filter(d=>d.cells.every(([f,S])=>!e.has(`${f},${S}`)))},i=new Map,r=t.edges.map((o,a)=>a).sort((o,a)=>s(t.edges[o]).length-s(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[o].kind==="main")||o-a);for(const o of r){const a=t.edges[o];if(a.fromSide||a.toSide)continue;const c=s(a).find(u=>(i.get(`${a.from}.${u.sides[0]}`)??0)<3&&(i.get(`${a.to}.${u.sides[1]}`)??0)<3);if(c){for(const[u,y]of[[a.from,c.sides[0]],[a.to,c.sides[1]]])i.set(`${u}.${y}`,(i.get(`${u}.${y}`)??0)+1);a.fromSide=c.sides[0],a.toSide=c.sides[1]}}}function Rt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=st(e.onLight);if(n)return{onLight:n,onDark:st(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Yt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function wt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var Qt=28,Wt=t=>t.includes(` -`)?2:1,gt=t=>t.replace(/\n/g," "),vt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Pt(t,e){return t.legend[e]}function Ue(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Je(t,e){return wt(t,`sentence:${e.i}`,()=>Xe(t,e))}function Xe(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,i=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(vt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${i}.`);const r=te(t,e);r&&n.push(r.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Ue(t,e):e.kind;if(n.push(vt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(vt(e.detail)),e.group){const o=t.groups.find(c=>c.id===e.group),a=o?.parent?t.groups.find(c=>c.id===o.parent):void 0;o&&n.push(a?`In ${o.label}, in ${a.label}.`:`In ${o.label}.`)}const i=t.edges.filter(o=>o.to===e.id).map(o=>`${t.byId.get(o.from).name}${o.label?` (${gt(o.label)})`:""}`),r=t.edges.filter(o=>o.from===e.id).map(o=>`${t.byId.get(o.to).name}${o.label?` (${gt(o.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(vt(t.legend.focal)),n.join(" ")}function te(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function Ye(t,e,n,s){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),o=n.target;if(!r||!o||!r.contains(o)||!t.querySelector(`.${e}-edge`))return;const a=o.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===s?null:a.dataset.node??null:null}function ee(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const s=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&s.push(i);return{t,a:e??{},c:s}}var Qe={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>Qe[e]),Pe=" br img input meta link hr path polygon polyline circle rect line ";function Nt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=i===!0?` ${s}`:` ${s}="${it(String(i))}"`}return Pe.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Nt(s,e)).join("")}`}var tn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function mt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function en(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function qt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function ne(t){return wt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=qt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((r,o)=>{r&&(e[o]=Math.max(e[o],oe(t,n,o)))})}return e})}function oe(t,e,n){const s=qt(t,e);return t.groups.filter(o=>o.parent===e.id).some(o=>{const a=qt(t,o);return a&&[a.r1===s.r1,a.c2===s.c2,a.r2===s.r2,a.c1===s.c1][n]})?2:1}function ae(t){const e=ne(t);return e[1]+e[3]}function zt(t){return t.type==="sequence"?t.nodes.length:t.cols}function se(t){return wt(t,"plan",()=>nn(t))}function nn(t){const e=t.nodes,n=d=>t.type==="data-flow"||!e[d].branch,s=t.edges.map(d=>{const f=t.byId.get(d.from).i,S=t.byId.get(d.to).i,C=e.slice(Math.min(f,S)+1,Math.max(f,S)).every(E=>!n(E.i));return S===f+1&&!(n(f)&&!n(S))?"down":S===f-1?"up":S>f&&n(f)&&!n(S)&&C?"trunk":S>f&&n(f)&&n(S)&&C?"rail":S>f?"end-down":"end-up"}),i=t.edges.map((d,f)=>({e:d,k:f})).filter(({k:d})=>s[d]==="end-down"||s[d]==="end-up"),r=d=>{const f=t.byId.get(d.from).i,S=t.byId.get(d.to).i;return[Math.min(f,S),Math.max(f,S)]},o=(d,f)=>{const[S,T]=r(d),[C,E]=r(f);return S{const f=t.byId.get(d.from).i,[S,T]=r(d);return!n(f)&&e.slice(S+1,T).every(C=>!n(C.i))&&i.every(C=>C.e===d||!o(C.e,d))}),c=i.length>0&&(t.type==="data-flow"||!a),u=d=>{const[f,S]=r(d);return S-f},y=t.edges.map(()=>0);let g=!1;const l=[];for(const d of[...i].sort((f,S)=>u(f.e)-u(S.e)||f.k-S.k)){let f=0;for(const S of l)o(S.e,d.e)&&(f=Math.max(f,y[S.k]+1));y[d.k]=f,f>1&&(g=!0),l.push(d)}const p=t.edges.map(()=>.5);for(const d of e){const f=i.filter(({e:C})=>C.from===d.id);if(f.length<2)continue;const S=f.filter(({k:C})=>s[C]==="end-down").sort((C,E)=>u(E.e)-u(C.e)||C.k-E.k);[...f.filter(({k:C})=>s[C]==="end-up").sort((C,E)=>u(C.e)-u(E.e)||E.k-C.k),...S].forEach(({k:C},E,A)=>{p[C]=A.length===2?E===0?1/3:2/3:(E+1)/(A.length+1)})}const x=ht();for(let d=1;d{const B=s[Z],ot=t.byId.get(j.from).i,L=t.byId.get(j.to).i,F=L===d&&(B==="down"||B==="trunk"||B==="rail"||B==="end-down"),I=ot===d&&L===d-1&&B==="up",M=L===d-1&&B==="end-up";F&&(B==="trunk"||B==="end-down")&&(E=!0),M&&(A=!0),(F||I||M)&&j.label&&(T++,C=Math.max(C,B==="trunk"?40:48))}),(T>1||E&&A)&&(C=64),x[f.id]=C}return{routes:s,gutter:c,lanes:y,exits:p,gaps:x,third:g}}var xt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function re(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...xt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${r}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${s-4}L${i} ${s}L${i-8} ${s+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${s}L${i-8} ${s-4}L${i-8} ${s+4}Z`}))}function Et(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function ie(t,e){return wt(e,`key:${t}`,()=>an(t,e))}var on=ie;function an(t,e){const n=[],s=(o,a,c={})=>n.push(v("li",{class:`${t}-entry`,...c},o,v("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(c=>c.key)));for(const[a,c]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),v("span",null,c)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(Et(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(Et(t,"box"),e.shapeLabels.step),o.has("decision")&&s(Et(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind)),r=(o,a)=>v("span",{class:`${t}-key-glyph`,"data-ink":a,"aria-hidden":"true"},o);for(const o of["main","plain","dashed"]){const a=e.legend[o];i.has(o)&&a&&s(e.text?r(o==="main"?"━━▶":o==="dashed"?"┄┄▷":"──▶",o==="main"?"main":"plain"):re(t,o),a,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length&&(s(re(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(e.text?r("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...xt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),v("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(Et(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(Et(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function sn(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...xt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Ft(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function rn(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},Ft(t,n)))];const s=[];return e.type==="data-flow"?s.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(v("span",{class:`${t}-kind`},n.kind)),s.push(v("span",{class:`${t}-name`},Ft(t,n))),n.detail&&s.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Bt(n.detail).flatMap((i,r)=>[r?" ":"",v("span",{class:`${t}-run`},i)]):n.detail)),s}function ln(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},Ft(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((s,i)=>v("span",{class:`${t}-row`,"data-row":i,"data-key":s.key},v("span",{class:`${t}-keyseat`},s.key??""),v("span",{class:`${t}-cname`},s.name),s.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?v("span",{class:`${t}-ctype`},s.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var le=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function It(t,e,n,s){const{P:i}=t,r=en(e,s)||s.keep===n.id,o=mt(e,s),a=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&a.push(`--_lc:${n.col+1}`),e.type==="sequence"&&a.push(`--_c2:${n.col+1}`);const c=t.plan;if(c&&n.i>0){const l=yt(c.gaps,n.id)??32,p=yt(s.grow,n.id)??0;a.push(`--_gap:${p?`calc(${le(l)} + var(--basalt-space-4) * ${p})`:le(l)}`)}const u=yt(s.heights,n.id);u&&a.push(`--_h:${u}px`);const y=yt(s.words,n.id);y&&a.push(`--_ww:${y}px`);const g=o?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:a.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?Je(e,n):void 0,tabindex:g},n.shape==="decision"?v("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Yt(n.mark.onLight)};--_md:${Yt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?ln(i,n,e):rn(i,e,n))}function cn(t,e,n){const{P:s}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((c,u)=>v("div",{class:`${s}-lane`,style:`--_r:${u+1}`,"aria-hidden":"true"},v("span",{class:`${s}-lane-name`},c.label)))),e.type==="architecture")for(const c of e.groups){const u=qt(e,c);if(!u)continue;const y=[0,1,2,3].map(g=>oe(e,c,g));i.push(v("div",{class:`${s}-gbox`,"data-group":c.id,"data-depth":c.depth>1?c.depth:void 0,style:`--_c:${u.c1};--_c2:${u.c2+1};--_r:${u.r1};--_r2:${u.r2+1}${y[0]>1?";--_gt:2":""}${y[1]>1?";--_ge:2":""}${y[2]>1?";--_gb:2":""}${y[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${s}-glabel`},c.label)))}if(e.text)return[v("pre",{class:`${s}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${s}-text-ink`},dn(s,e)))];if(e.type==="sequence")return i.push(v("ul",{class:`${s}-cast`},e.nodes.map(c=>v("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${c.col}`:void 0},It(t,e,c,n))))),i.push(fn(t,e)),i;const r=c=>{const u=c.group?e.groups.find(y=>y.id===c.group):void 0;return u?.parent?e.groups.find(y=>y.id===u.parent):u},o=(c,u,y)=>{const g=t.plan?yt(n.grow,u[0].id)??0:0;return v("div",{class:`${s}-group`,"data-group":c.id,"data-depth":c.depth>1?c.depth:void 0,style:g?`--_ggrow:${g}`:void 0},v("span",{class:`${s}-glabel`,"aria-hidden":"true"},c.label),y)};let a=0;for(;ad.id===y[l].group):void 0;if(!p){g.push(It(t,e,y[l],n)),l++;continue}const x=[];for(;lIt(t,e,d,n))))}i.push(o(u,y,g))}return i}function dn(t,e){const n=[],s=o=>v("span",{class:`${t}-tx-name`},o),i=o=>o==="main"?"━▶":o==="dashed"?"┄▷":"─▶";n.push(v("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((o,a)=>[a?" · ":"",s(o.name)])),` +(()=>{var Ue=["top","right","bottom","left"],Je=["main","plain","dashed"],Xe=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ut=t=>Object.assign(Object.create(null),t),gt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function wt(t,e={}){const s=e.checks!==!1,i=[],r=y=>{i.push(y)},o=t.legend??{},a={};for(const y of["main","plain","dashed","focal","group","activation"]){const b=at(o[y]);b&&(a[y]=b)}const l=t.stepLabel,f=typeof l=="function"?y=>String(l(y)):typeof l=="string"?(y=>l.replace("{n}",String(y))):y=>`Step ${y}`,m=t.shapeLabels??{},u={terminal:at(m.terminal)??"Start or end",step:at(m.step)??"Step",decision:at(m.decision)??"Decision"},c=t.heading===void 0?3:Xe.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),g=(y,b)=>y==null?"plain":Je.includes(y)?y:(r(`"${String(y)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),x=y=>{if(y!=null){if(Ue.includes(y))return y;r(`"${String(y)}" is not a side (top, right, bottom or left): the derived side is used`)}},d=(y,b)=>typeof y=="number"&&Number.isInteger(y)&&y>=1?y:(t.layout==="auto"&&y==null||r(`${b} is ${JSON.stringify(y)}, not a whole number from 1: it is placed at 1`),1),h=[],S=[];let j=[];const C=[],E=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||r(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const y of t.nodes??[]){const b=A==="flowchart"&&y.shape==="decision"?"decision":A==="flowchart"&&y.shape==="terminal"?"terminal":"box",p=String(y.id??""),k=d(y.row,`the row of ${p}`);h.push({id:p,i:h.length,name:String(y.name??""),kind:b==="decision"?void 0:at(y.kind),detail:b==="decision"?void 0:at(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:d(y.col,`the column of ${p}`),row:k,row2:k,branch:!!y.branch,shape:b,group:A==="architecture"?at(y.group):void 0,mark:A==="architecture"?Wt(y.mark):void 0})}if(A==="architecture"){const y=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:at($.parent)})),b=new Map(y.map($=>[$.id,$])),p=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(r(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(r(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(r(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},k=y.map(p);y.forEach(($,w)=>C.push({...$,depth:k[w],members:h.filter(_=>_.group===$.id).map(_=>_.id),all:[]}));for(const $ of C)$.all=[...$.members,...C.filter(w=>w.parent===$.id).flatMap(w=>w.members)];C.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){j=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const y=new Map(j.map((b,p)=>[b.id,p+1]));for(const b of t.nodes??[]){const p=String(b.id??""),k=String(b.lane??""),$=y.get(k);$===void 0&&r(`a node (${p}) names the lane "${k}", which is not in lanes`);const w=h.length+1;h.push({id:p,i:h.length,name:String(b.name??""),kind:f(w),detail:at(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:d(b.col,`the column of ${p}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:j[($??1)-1]?.label??k,step:w,mark:Wt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((k,$)=>{const w=String(k.name??"");h.push({id:String(k.id??""),i:$,name:w,kind:at(k.kind),mono:!1,focal:!!k.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:at(k.short)??w,mark:Wt(k.mark)})});let y=0;const b=new Map(h.map(k=>[k.id,k.col])),p=(k,$)=>{let w=1/0,_=-1/0;for(const q of k??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&r(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),E.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){r("a frame is a third level: frames nest two deep");continue}const st=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=st==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];st==="alt"&&V.length<2&&r("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&r(`the frame label "${P}" is over 40 characters`);const J=E.length;E.push({open:st,label:P,depth:$+1,a:0,b:0}),V.forEach((nt,rt)=>{if(rt){const kt=String(nt.label??"");kt.length>40&&r(`the frame label "${kt}" is over 40 characters`),E.push({otherwise:kt,depth:$+1})}nt.steps?.length||r(`a frame or branch ("${String(nt.label??"")}") is empty`);const[ct,qt]=p(nt.steps??[],$+1);w=Math.min(w,ct),_=Math.max(_,qt);const $t=E[J];$t.a=Math.min($t.a||1/0,ct),$t.b=Math.max($t.b,qt)}),E.push({close:$+1});continue}y++;const R=String(q.label??"");R.includes(` +`)&&r(`message ${y}'s label has a break: a message's second line is its note`);const U=String(q.from??""),Y=String(q.to??"");E.push({n:y,from:U,to:Y,label:yt(R),note:at(q.note),kind:g(q.kind,`message ${y}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const N=b.get(U)??1,D=b.get(Y)??1,tt=N===D?N===h.length?N-1:N+1:N;w=Math.min(w,N,D,tt),_=Math.max(_,N,D,tt)}return[w,_]};p(t.steps??[],0);for(const k of E)"open"in k&&!Number.isFinite(k.a)&&(k.a=1,k.b=Math.max(1,h.length))}else if(A==="schema")for(const y of t.tables??[]){const b=String(y.name??""),[p,k]=Array.isArray(y.row)?y.row:[y.row,y.row],$=d(p,`the row of ${b}`),w=Math.max($,d(k,`the last row of ${b}`)),_=y.more===void 0||y.more===null?void 0:Number.isInteger(y.more)&&y.more>0?y.more:(r(`${b}'s "more" is ${JSON.stringify(y.more)}, not a whole number from 1: it is left out`),void 0);h.push({id:b,i:h.length,name:b,mono:!0,focal:!!y.focal,col:d(y.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:_,columns:(y.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&r(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const y=A==="schema"?t.tables:t.nodes;s&&(y??[]).some(p=>p&&(p.col!==void 0||p.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(T=!0);for(const p of h){const k=b?.[p.id];p.col=k?.col??1,p.row=p.row2=k?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((y,b)=>{if(!y||y.href===void 0||y.href===null)return;const p=String(y.href);if(A==="sequence"){r(`${h[b]?.id}: a participant cannot be a link (href)`);return}if(!p){r(`${h[b]?.id}'s href is empty`);return}const k=h[b];k&&(k.href=p,k.blank=y.target==="_blank")});const B=new Map;for(const y of h)y.id?B.has(y.id)&&r(`the id "${y.id}" is used twice`):r("a node has no id"),B.set(y.id,y);if(A==="schema")(t.tables??[]).forEach(y=>(y.columns??[]).forEach((b,p)=>{const k=at(b.references);if(!k)return;const[$,w]=k.split("."),_=B.get($??""),q=_?.columns?.findIndex(U=>U.name===w)??-1;if(!_||q<0){r(`${String(y.name)}.${String(b.name)} references ${k}, which is not a shown column`);return}const R=B.get(String(y.name??""));R.columns[p].ref={table:$,column:w,row:q},S.push({i:S.length,from:R.id,to:$,kind:"plain",fromRow:p,toRow:q,fk:!0})}));else if(A!=="sequence")for(const y of t.edges??[]){const b=String(y.from??""),p=String(y.to??"");if(!B.has(b)||!B.has(p)){r(`a line names ${B.has(b)?p:b}, which is not a node`);continue}const k=at(y.label),$=k?.split(` +`)??[];$.length>2&&r(`the label "${yt(k)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>te)&&r(`a line of the label "${yt(k)}" is over ${te} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:p,kind:g(y.kind,`the line from ${b} to ${p}`),label:k,fromSide:x(y.fromSide),toSide:x(y.toSide),flow:A!=="flowchart"&&y.flow===!0?!0:void 0})}else for(const y of E)"n"in y&&(!B.has(y.from)||!B.has(y.to))&&r(`message ${y.n} names ${B.has(y.from)?y.to:y.from}, which is not a participant`);if(s&&A!=="sequence"&&!T){const y=new Map;for(const b of h)for(let p=b.row;p<=b.row2;p++){const k=`${b.col}:${p}`;y.has(k)&&r(`${b.id} and ${y.get(k)} share the cell at column ${b.col}, row ${p}`),y.set(k,b.id)}}if(s&&!T){for(const b of C){const p=b.all.map(w=>B.get(w));if(!p.length)continue;const k={c1:Math.min(...p.map(w=>w.col)),c2:Math.max(...p.map(w=>w.col)),r1:Math.min(...p.map(w=>w.row)),r2:Math.max(...p.map(w=>w.row2))};for(const w of h)!b.all.includes(w.id)&&w.col>=k.c1&&w.col<=k.c2&&w.row>=k.r1&&w.row<=k.r2&&r(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=p.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&r(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of h)b.group&&!C.some(p=>p.id===b.group)&&r(`${b.id} names the group "${b.group}", which is not in groups`);h.filter(b=>b.focal).length>1&&r("more than one node is focal: a diagram has one at most");const y=new Set(A==="sequence"?E.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));y.has("main")&&!a.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),y.has("dashed")&&!a.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),h.some(b=>b.focal)&&!a.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const ot=A==="architecture"||A==="data-flow",L=y=>Array.isArray(y)&&y.length>1?y.map(String):void 0,z=ot&&t.packet&&typeof t.packet=="object"?t.packet:void 0,I=z&&L(z.path),M={animated:t.motion==="animated",pulse:ot?L(t.pulse):void 0,packet:I?{path:I,repeat:z.repeat===!0,send:z.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const y of h){const b=y.mark?.says;if(!b?.length)continue;const p=[y.name,y.kind,y.detail,y.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(k=>p.includes(k.toLowerCase()))||r(`${y.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const y=new Map,b=new Map;for(const p of E)"n"in p&&(b.set(p.from,p.n),b.set(p.to,p.n));for(const p of E)if("n"in p){if(p.activate){const k=y.get(p.to)??[];if(k.length>=3)r(`message ${p.n} opens a fourth bar on ${p.to}: three deep at most`);else{const $={who:p.to,from:p.n,to:p.n,depth:k.length+1};k.push($),O.push($),y.set(p.to,k)}}if(p.deactivate){const $=y.get(p.from)?.pop();$?$.to=p.n:r(`message ${p.n} closes a bar on ${p.from}, which has none open`)}}for(const[p,k]of y)for(const $ of k)$.to=Math.max($.from,b.get(p)??$.from)}const F=t.frameLabels??{},G={opt:at(F.opt)??"Only if",loop:at(F.loop)??"Repeats",alt:at(F.alt)??"One of these",else:at(F.else)??"Otherwise"};let W=Math.max(1,...h.map(y=>y.col));if(e.rtl){for(const b of h)b.col=W-b.col+1;const y=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=y(b.fromSide),b.toSide=y(b.toSide);for(const b of E)if("open"in b){const[p,k]=[W-b.b+1,W-b.a+1];b.a=p,b.b=k}W=Math.max(1,...h.map(b=>b.col))}const Q=A==="data-flow"?Math.max(1,j.length):Math.max(1,...h.map(y=>y.row2)),K={type:A,title:String(t.title??""),heading:c,legend:a,nodes:h,byId:B,edges:S,groups:C,lanes:j,steps:E,bars:O,frameWords:G,cols:W,rows:Q,shapeLabels:u,stepWord:f,warnings:i,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0,text:A==="sequence"&&t.variant==="text"||void 0};if(t.layout==="auto"&&!T&&A!=="schema"&&Ye(K),s)for(const[y,b]of Object.entries(we(K)))b>=48&&r(`${y} grows to ${b}px to hold the lines on one side: use another side`);return s&&h.length>1&&!_t(K)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function Ye(t){const e=new Set(t.nodes.map(o=>`${o.col},${o.row}`)),n=(o,a)=>{const l=[];for(let f=Math.min(o,a)+1;f{const a=t.byId.get(o.from),l=t.byId.get(o.to),f=l.col>a.col?"right":"left",m=l.row>a.row?"bottom":"top",u=l.col>a.col?"left":"right",c=l.row>a.row?"top":"bottom",g=(d,h,S,j)=>n(d,h).map(C=>j?[C,S]:[S,C]);let x;return a.row===l.row?x=[{sides:[f,u],cells:g(a.col,l.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===l.col?x=[{sides:[m,c],cells:g(a.row,l.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:x=[{sides:[f,c],cells:[...g(a.col,l.col,a.row,!0),[l.col,a.row],...g(a.row,l.row,l.col,!1)]},{sides:[m,u],cells:[...g(a.row,l.row,a.col,!1),[a.col,l.row],...g(a.col,l.col,l.row,!0)]},{sides:[f,u],cells:g(a.col,l.col,a.row,!0)},{sides:[m,c],cells:g(a.row,l.row,a.col,!1)}],x.filter(d=>d.cells.every(([h,S])=>!e.has(`${h},${S}`)))},i=new Map,r=t.edges.map((o,a)=>a).sort((o,a)=>s(t.edges[o]).length-s(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[o].kind==="main")||o-a);for(const o of r){const a=t.edges[o];if(a.fromSide||a.toSide)continue;const l=s(a).find(f=>(i.get(`${a.from}.${f.sides[0]}`)??0)<3&&(i.get(`${a.to}.${f.sides[1]}`)??0)<3);if(l){for(const[f,m]of[[a.from,l.sides[0]],[a.to,l.sides[1]]])i.set(`${f}.${m}`,(i.get(`${f}.${m}`)??0)+1);a.fromSide=l.sides[0],a.toSide=l.sides[1]}}}function Wt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Pt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function mt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var te=28,Ft=t=>t.includes(` +`)?2:1,yt=t=>t.replace(/\n/g," "),vt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function ee(t,e){return t.legend[e]}function Qe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Pe(t,e){return mt(t,`sentence:${e.i}`,()=>tn(t,e))}function tn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,i=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(vt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${i}.`);const r=ne(t,e);r&&n.push(r.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Qe(t,e):e.kind;if(n.push(vt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(vt(e.detail)),e.group){const o=t.groups.find(l=>l.id===e.group),a=o?.parent?t.groups.find(l=>l.id===o.parent):void 0;o&&n.push(a?`In ${o.label}, in ${a.label}.`:`In ${o.label}.`)}const i=t.edges.filter(o=>o.to===e.id).map(o=>`${t.byId.get(o.from).name}${o.label?` (${yt(o.label)})`:""}`),r=t.edges.filter(o=>o.from===e.id).map(o=>`${t.byId.get(o.to).name}${o.label?` (${yt(o.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(vt(t.legend.focal)),n.join(" ")}function ne(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function en(t,e,n,s){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),o=n.target;if(!r||!o||!r.contains(o)||!t.querySelector(`.${e}-edge`))return;const a=o.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===s?null:a.dataset.node??null:null}function oe(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const s=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&s.push(i);return{t,a:e??{},c:s}}var nn={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>nn[e]),on=" br img input meta link hr path polygon polyline circle rect line ";function Nt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=i===!0?` ${s}`:` ${s}="${it(String(i))}"`}return on.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Nt(s,e)).join("")}`}var sn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function bt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function an(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function It(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function se(t){return mt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=It(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((r,o)=>{r&&(e[o]=Math.max(e[o],ae(t,n,o)))})}return e})}function ae(t,e,n){const s=It(t,e);return t.groups.filter(o=>o.parent===e.id).some(o=>{const a=It(t,o);return a&&[a.r1===s.r1,a.c2===s.c2,a.r2===s.r2,a.c1===s.c1][n]})?2:1}function re(t){const e=se(t);return e[1]+e[3]}function zt(t){return t.type==="sequence"?t.nodes.length:t.cols}function ie(t){return mt(t,"plan",()=>rn(t))}function rn(t){const e=t.nodes,n=d=>t.type==="data-flow"||!e[d].branch,s=t.edges.map(d=>{const h=t.byId.get(d.from).i,S=t.byId.get(d.to).i,C=e.slice(Math.min(h,S)+1,Math.max(h,S)).every(E=>!n(E.i));return S===h+1&&!(n(h)&&!n(S))?"down":S===h-1?"up":S>h&&n(h)&&!n(S)&&C?"trunk":S>h&&n(h)&&n(S)&&C?"rail":S>h?"end-down":"end-up"}),i=t.edges.map((d,h)=>({e:d,k:h})).filter(({k:d})=>s[d]==="end-down"||s[d]==="end-up"),r=d=>{const h=t.byId.get(d.from).i,S=t.byId.get(d.to).i;return[Math.min(h,S),Math.max(h,S)]},o=(d,h)=>{const[S,j]=r(d),[C,E]=r(h);return S{const h=t.byId.get(d.from).i,[S,j]=r(d);return!n(h)&&e.slice(S+1,j).every(C=>!n(C.i))&&i.every(C=>C.e===d||!o(C.e,d))}),l=i.length>0&&(t.type==="data-flow"||!a),f=d=>{const[h,S]=r(d);return S-h},m=t.edges.map(()=>0);let u=!1;const c=[];for(const d of[...i].sort((h,S)=>f(h.e)-f(S.e)||h.k-S.k)){let h=0;for(const S of c)o(S.e,d.e)&&(h=Math.max(h,m[S.k]+1));m[d.k]=h,h>1&&(u=!0),c.push(d)}const g=t.edges.map(()=>.5);for(const d of e){const h=i.filter(({e:C})=>C.from===d.id);if(h.length<2)continue;const S=h.filter(({k:C})=>s[C]==="end-down").sort((C,E)=>f(E.e)-f(C.e)||C.k-E.k);[...h.filter(({k:C})=>s[C]==="end-up").sort((C,E)=>f(C.e)-f(E.e)||E.k-C.k),...S].forEach(({k:C},E,A)=>{g[C]=A.length===2?E===0?1/3:2/3:(E+1)/(A.length+1)})}const x=ut();for(let d=1;d{const B=s[Z],ot=t.byId.get(T.from).i,L=t.byId.get(T.to).i,z=L===d&&(B==="down"||B==="trunk"||B==="rail"||B==="end-down"),I=ot===d&&L===d-1&&B==="up",M=L===d-1&&B==="end-up";z&&(B==="trunk"||B==="end-down")&&(E=!0),M&&(A=!0),(z||I||M)&&T.label&&(j++,C=Math.max(C,B==="trunk"?40:48))}),(j>1||E&&A)&&(C=64),x[h.id]=C}return{routes:s,gutter:l,lanes:m,exits:g,gaps:x,third:u}}var xt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function le(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...xt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${r}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${s-4}L${i} ${s}L${i-8} ${s+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${s}L${i-8} ${s-4}L${i-8} ${s+4}Z`}))}function Et(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function ce(t,e){return mt(e,`key:${t}`,()=>cn(t,e))}var ln=ce;function cn(t,e){const n=[],s=(o,a,l={})=>n.push(v("li",{class:`${t}-entry`,...l},o,v("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),v("span",null,l)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(Et(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(Et(t,"box"),e.shapeLabels.step),o.has("decision")&&s(Et(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind)),r=(o,a)=>v("span",{class:`${t}-key-glyph`,"data-ink":a,"aria-hidden":"true"},o);for(const o of["main","plain","dashed"]){const a=e.legend[o];i.has(o)&&a&&s(e.text?r(o==="main"?"━━▶":o==="dashed"?"┄┄▷":"──▶",o==="main"?"main":"plain"):le(t,o),a,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length&&(s(le(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(e.text?r("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...xt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),v("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(Et(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(Et(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function dn(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...xt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Ht(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function fn(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},Ht(t,n)))];const s=[];return e.type==="data-flow"?s.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(v("span",{class:`${t}-kind`},n.kind)),s.push(v("span",{class:`${t}-name`},Ht(t,n))),n.detail&&s.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?jt(n.detail).flatMap((i,r)=>[r?" ":"",v("span",{class:`${t}-run`},i)]):n.detail)),s}function un(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},Ht(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((s,i)=>v("span",{class:`${t}-row`,"data-row":i,"data-key":s.key},v("span",{class:`${t}-keyseat`},s.key??""),v("span",{class:`${t}-cname`},s.name),s.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?v("span",{class:`${t}-ctype`},s.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var de=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Ot(t,e,n,s){const{P:i}=t,r=an(e,s)||s.keep===n.id,o=bt(e,s),a=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&a.push(`--_lc:${n.col+1}`),e.type==="sequence"&&a.push(`--_c2:${n.col+1}`);const l=t.plan;if(l&&n.i>0){const g=gt(l.gaps,n.id)??32,x=gt(s.grow,n.id)??0;a.push(`--_gap:${x?`calc(${de(g)} + var(--basalt-space-4) * ${x})`:de(g)}`)}const f=gt(s.heights,n.id);f&&a.push(`--_h:${f}px`);const m=gt(we(e),n.id);m&&a.push(`--_mh:${m}px`);const u=gt(s.words,n.id);u&&a.push(`--_ww:${u}px`);const c=o?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:a.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?Pe(e,n):void 0,tabindex:c},n.shape==="decision"?v("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Pt(n.mark.onLight)};--_md:${Pt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?un(i,n,e):fn(i,e,n))}function hn(t,e,n){const{P:s}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((l,f)=>v("div",{class:`${s}-lane`,style:`--_r:${f+1}`,"aria-hidden":"true"},v("span",{class:`${s}-lane-name`},l.label)))),e.type==="architecture")for(const l of e.groups){const f=It(e,l);if(!f)continue;const m=[0,1,2,3].map(u=>ae(e,l,u));i.push(v("div",{class:`${s}-gbox`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:`--_c:${f.c1};--_c2:${f.c2+1};--_r:${f.r1};--_r2:${f.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${s}-glabel`},l.label)))}if(e.text)return[v("pre",{class:`${s}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${s}-text-ink`},pn(s,e)))];if(e.type==="sequence")return i.push(v("ul",{class:`${s}-cast`},e.nodes.map(l=>v("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${l.col}`:void 0},Ot(t,e,l,n))))),i.push(gn(t,e)),i;const r=l=>{const f=l.group?e.groups.find(m=>m.id===l.group):void 0;return f?.parent?e.groups.find(m=>m.id===f.parent):f},o=(l,f,m)=>{const u=t.plan?gt(n.grow,f[0].id)??0:0;return v("div",{class:`${s}-group`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:u?`--_ggrow:${u}`:void 0},v("span",{class:`${s}-glabel`,"aria-hidden":"true"},l.label),m)};let a=0;for(;ad.id===m[c].group):void 0;if(!g){u.push(Ot(t,e,m[c],n)),c++;continue}const x=[];for(;cOt(t,e,d,n))))}i.push(o(f,m,u))}return i}function pn(t,e){const n=[],s=o=>v("span",{class:`${t}-tx-name`},o),i=o=>o==="main"?"━▶":o==="dashed"?"┄▷":"─▶";n.push(v("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((o,a)=>[a?" · ":"",s(o.name)])),` `);let r=0;for(const o of e.steps){const a=" ".repeat(r);if("band"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"band"},`${a}── ${o.band} ──`),` `);continue}if("open"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},a,v("span",{"data-ink":"op"},`[${o.open}]`),` ${o.label}`),` `),r++;continue}if("otherwise"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"}," ".repeat(r-1),v("span",{"data-ink":"op"},"[else]"),` ${o.otherwise}`),` `);continue}if("close"in o){r=Math.max(0,r-1),n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},`${" ".repeat(r)}[end]`),` -`);continue}const c=e.byId.get(o.from)?.name??o.from,u=e.byId.get(o.to)?.name??o.to;n.push(v("span",{class:`${t}-tx-line`,"data-n":o.n},a,v("span",{"data-ink":"num"},`${o.n} `),s(c)," ",v("span",{"data-ink":o.kind==="main"?"main":"plain"},i(o.kind))," ",s(u)," ",v("span",{"data-ink":"label"},o.label),o.note?[" ",v("span",{"data-ink":"note"},`(${o.note})`)]:null),` -`)}return n}function fn(t,e){const{P:n}=t,s=[],i=[],r=()=>i.length?i[i.length-1].el.c:s;let o=null;for(const a of e.steps){if("band"in a){o=null,r().push(v("p",{class:`${n}-band`},v("span",null,a.band)));continue}if("open"in a){o=null;const d=i[i.length-1],f=d?`;--_fis:${a.a===d.a?1:0};--_fie:${a.b===d.b?1:0}`:"",S=v("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${f}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));r().push(S),i.push({el:S,a:a.a,b:a.b});continue}if("otherwise"in a){o=null,r().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){o=null,i.pop();continue}o||(o=v("ol",{class:`${n}-msgs`,start:a.n}),r().push(o));const c=e.byId.get(a.from),u=e.byId.get(a.to),y=c?.col??1,g=u?.col??1,l=y===g,p=l&&(e.rtl?y!==1:y===e.nodes.length),x=Pt(e,a.kind);o.c.push(v("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":l?p?"start":"end":void 0,style:`--_a:${Math.min(y,g)};--_b:${Math.max(y,g)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(a.n)),v("span",{class:`${n}-mlabel`},a.label)),v("span",{class:`${n}-route`},c?.short??a.from," ",sn(n,a.kind),v("span",{class:t.hidden}," to ")," ",u?.short??a.to,x?` · ${x}`:""),a.note?v("span",{class:`${n}-note`},a.note):null))}return v("div",{class:`${n}-steps`},s)}function ce(t,e){return wt(e,`list:${t}`,()=>hn(t,e))}var un=ce;function hn(t,e){const n=Math.min(6,e.heading+1),s=g=>v(`h${n}`,{class:`${t}-list-head`},g),i=g=>v("strong",null,g),r=g=>g.href?v("a",{href:g.href,target:g.blank?"_blank":void 0,rel:g.blank?"noopener noreferrer":void 0},i(g.name)):i(g.name),o=g=>v("code",{class:`${t}-code`},g),a=g=>e.byId.get(g)?.name??g,c=g=>{const l=Pt(e,g);return l?` (${l})`:""},u=g=>g.focal&&e.legend.focal?` ${vt(e.legend.focal)}`:"";if(e.type==="architecture"){const g=x=>v("li",null,r(x),x.kind?`, ${x.kind}`:"",x.detail?[". ",x.mono?o(x.detail):x.detail,/[.!?]$/.test(x.detail)?"":"."]:/[.!?]$/.test(x.kind??x.name)?"":".",u(x)),l=[s("Parts")],p=e.nodes.filter(x=>!x.group);p.length&&l.push(v("ul",{class:`${t}-list-items`},p.map(g)));for(const x of e.groups.filter(d=>d.depth===1)){l.push(v("p",{class:`${t}-list-group`},x.label)),x.members.length&&l.push(v("ul",{class:`${t}-list-items`},x.members.map(d=>g(e.byId.get(d)))));for(const d of e.groups.filter(f=>f.parent===x.id))l.push(v("p",{class:`${t}-list-group`,"data-depth":2},d.label)),l.push(v("ul",{class:`${t}-list-items`,"data-depth":2},d.members.map(f=>g(e.byId.get(f)))))}return l.push(s("Connections")),l.push(v("ol",{class:`${t}-list-items`},e.edges.map(x=>v("li",null,i(a(x.from))," to ",i(a(x.to)),x.label?[": ",o(gt(x.label))]:"",`${c(x.kind)}.`)))),l}if(e.type==="flowchart"){const g=l=>(e.byId.get(l)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(l=>{const p=e.edges.filter(f=>f.from===l.id),x=l.shape==="decision"?"Decision":l.shape==="terminal"?p.length?"Start":"End":"Step",d=!l.detail&&/[.!?]$/.test(l.name)?" ":". ";return v("li",null,r(l),l.detail?[", ",l.mono?o(l.detail):l.detail]:"",`${d}${x}.`,u(l),p.length?v("ul",{class:`${t}-list-exits`},p.map(f=>v("li",null,f.label?`If ${gt(f.label)}: go to ${g(f.to)}, `:`Then: go to ${g(f.to)}, `,i(a(f.to)),c(f.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(g=>{const l=e.edges.filter(p=>p.from===g.id);return v("li",null,`${g.laneLabel}: `,r(g),g.detail?[", ",g.mono?o(g.detail):g.detail]:"",".",u(g),l.length?[" Then ",...l.flatMap((p,x)=>[x?"; ":"",`to step ${e.byId.get(p.to).step}, `,i(a(p.to)),p.label?[": ",o(gt(p.label))]:"",c(p.kind)]),"."]:"")}))];if(e.type==="sequence"){const g=[s("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(p=>v("li",null,i(p.name),p.kind?`, ${p.kind}`:"",".",u(p),te(e,p))))];g.push(s("Messages"));let l=null;for(const p of e.steps){if("band"in p){l=null,g.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},p.band));continue}if("open"in p){l=null,g.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":p.depth>1?p.depth:void 0},`${e.frameWords[p.open]}: ${p.label}`));continue}if("otherwise"in p){l=null,g.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":p.depth>1?p.depth:void 0},`${e.frameWords.else}: ${p.otherwise}`));continue}if("close"in p){l=null;continue}l||(l=v("ol",{class:`${t}-list-items`,start:p.n}),g.push(l)),l.c.push(v("li",null,o(p.label),": ",i(a(p.from))," to ",i(a(p.to)),`${c(p.kind)}.`,p.note?` ${vt(p.note)}`:""))}return g}const y=[];for(const g of e.nodes)y.push(v(`h${n}`,{class:`${t}-list-group`},g.href?v("a",{href:g.href,target:g.blank?"_blank":void 0,rel:g.blank?"noopener noreferrer":void 0},o(g.name)):o(g.name),u(g))),y.push(v("ul",{class:`${t}-list-items`},[...(g.columns??[]).map(l=>v("li",null,o(l.name),l.key==="PK"?", primary key":l.key==="FK"?", foreign key":"",l.ref?[", references ",o(`${l.ref.table}.${l.ref.column}`)]:l.type?`, ${l.type}`:"")),...g.more?[v("li",null,`and ${g.more} more ${g.more===1?"column":"columns"}`)]:[]]));return y}function de(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Ot(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function Ht(t,e=!1){const n=e&&t.type!=="sequence"&&Ot(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:ee(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var pn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Ot(t){return wt(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,...gn(t,r)})),n=(r,o)=>{const a=o==="right"||o==="left",c=o==="right"||o==="down",u=x=>a?[x.col,x.col]:x.rows,y=x=>a?x.rows:[x.col,x.col],g=u(r),l=y(r);let p=null;return e.forEach((x,d)=>{if(x===r)return;const f=u(x),S=y(x),T=c?f[0]-g[1]:g[0]-f[1];if(T<1)return;const C=Math.max(0,S[0]-l[1],l[0]-S[1]),E=[C===0?0:1,C===0?T:T+2*C,C,Math.abs(S[0]-l[0]),d];(!p||pn(E,p.rank))&&(p={id:x.id,rank:E})}),p?.id??null},s=ht();for(const r of e)s[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const o=new Set([r]),a=[r];for(;a.length;)for(const c of Object.values(s[a.pop()]))c&&!o.has(c)&&(o.add(c),a.push(c));return o.size};return e.every(r=>i(r.id)===e.length)?s:null})}var fe=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function _t(t,e,n){const s=n.prefix,i=tn(n.base),r=t.type==="sequence"||t.type==="schema"?null:se(t),o={P:s,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},a=e.layout==="drawn",c=mt(t,e),u=t.type==="sequence"||t.type==="schema"?a:!0,y=`h${t.heading}`,g=[`--_cols:${zt(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const l=t.type==="architecture"?ne(t):[0,0,0,0],p=(d,f,S)=>d?d>1?`calc(${d} * var(--basalt-space-${f}))`:`var(--basalt-space-${f})`:S?`var(--basalt-space-${S})`:"0px",x=a&&e.pad?"3":void 0;g.push(`--_gpad:${p(l[0],"8",x)} ${p(l[1],"4")} ${p(l[2],"4",x)} ${p(l[3],"4")}`)}return fe(t)&&g.push("--_gpad:0px var(--basalt-space-5) 0px 0px"),t.type==="schema"&&e.track&&g.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":i.title,"data-type":t.type,"data-cols":zt(t),"data-reach":t.type==="architecture"?ae(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:g.join(";")},v("div",{class:`${s}-head`},v(y,{id:i.title,class:`${s}-title`},t.title),n.hasSource?v("p",{class:`${s}-source`},{slot:"source"}):null),v("div",{class:`${s}-drawing`,role:u?"group":void 0,"aria-roledescription":u?"diagram":void 0,"aria-labelledby":u?i.title:void 0,"aria-describedby":u?c?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":c?"":void 0},cn(o,t,e),t.text?null:v("div",{class:`${s}-ink`,"aria-hidden":"true"}),v("span",{class:`${s}-ruler`,"aria-hidden":"true"})),ie(s,t),v("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),mt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?v("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${ee(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${s}-foot`},{slot:"toggle"}),v("div",{id:i.list,class:`${s}-list`,hidden:!e.open},ce(s,t)),v("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${de(t,a)} ${n.viewer}`:de(t,a)),v("figcaption",{id:i.summary,class:`${s}-summary`},{slot:"summary"}))}function mn(t){const e=getComputedStyle(t),n=(i,r)=>{const o=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(o)?o:r},s=new Map;return{space:i=>(s.has(i)||s.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),s.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ct=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ut=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,ue=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:i,r,b:o}=t.rect,a=(s+r)/2,c=(i+o)/2,u=(r-s)/2,y=(o-i)/2,g=e==="top"||e==="bottom";if(t.shape==="decision"){if(g){const x=n,d=y*Math.max(0,1-Math.abs(x-a)/u);return{x,y:e==="top"?c-d:c+d}}const l=n,p=u*Math.max(0,1-Math.abs(l-c)/y);return{x:e==="left"?a-p:a+p,y:l}}if(t.shape==="terminal"){const l=Math.min(u,y);if(g){const f=n,S=Math.min(Math.max(f,s+l),r-l),T=f-S,C=Math.abs(T)>=l?0:Math.sqrt(l*l-T*T);return{x:f,y:Math.abs(T)<1e-6?e==="top"?i:o:e==="top"?c-C:c+C}}const p=n,x=p-c,d=Math.abs(x)>=l?0:Math.sqrt(l*l-x*x);return{x:e==="left"?s+l-d:r-l+d,y:p}}return g?{x:n,y:e==="top"?i:o}:{x:e==="left"?s:r,y:n}}function yn(t,e,n){const{l:s,t:i,r,b:o}=e.rect,a=(s+r)/2,c=(i+o)/2,u=(r-s)/2,y=(o-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/u+Math.abs(t.y-c)/y<1-n/Math.min(u,y);if(e.shape==="terminal"){const g=Math.min(u,y),l=Math.min(Math.max(t.x,s+g),r-g);return Math.hypot(t.x-l,t.y-c)s+n&&t.xi+n&&t.ymatchMedia("(forced-colors: active)").matches;function wn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(i,r)=>{const o=`${r}|${i}`;return s.has(o)||(n.setAttribute("data-f",r),n.textContent=i,s.set(o,n.getBoundingClientRect().width),n.textContent=""),s.get(o)}}var Bt=t=>t?t.split(/\s+/).filter(Boolean):[];function vn(t,e,n){const s=e.space;let i=e.node,r=e.table;for(const c of t.nodes){if(c.shape==="table"){for(const d of c.columns??[]){const f=d.ref?`${t.rtl?"←":"→"} ${d.ref.table}`:d.type??"",S=s("6")+n(d.name,"mono")+(f?s("3")+n(f,"mono"):0)+2*s("3")+2*e.hair;r=Math.max(r,Math.ceil(S))}r=Math.max(r,Math.ceil(n(c.name,"table")+2*s("3")+2*e.hair+(c.href?16+s("1-5"):0)));continue}const u=c.shape==="terminal"?2*s("5"):2*s("3"),y=c.mark&&!$n()?(c.shape==="participant"?2:1)*s("6"):0;let g=0;const l=c.href?16+s("1-5"):0,p=Bt(c.name);if(p.forEach((d,f)=>{g=Math.max(g,n(d,c.shape==="decision"?"name-500":"name")+(c.kind?0:y)+(f===p.length-1?l:0))}),t.type!=="data-flow")for(const d of Bt(c.kind))g=Math.max(g,n(d,"mono")+y);for(const d of Bt(c.detail))g=Math.max(g,n(d,c.mono?"mono":"sans"));const x=c.shape==="decision"?g/.62:g+u+2*e.hair;i=Math.max(i,Math.ceil(x))}const o=zt(t);let a;return t.type==="data-flow"?a=e.lane+o*(i+s("12")):t.type==="schema"?a=o*r+(o-1)*s("12")+(fe(t)?s("5"):0):t.type==="sequence"?a=o*i+(o-1)*s("5"):a=o*i+(o-1)*s("16")+ae(t)*s("4"),{track:i,table:r,least:Math.max(e.wide,a)}}function pe(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Dt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function ge(t,e,n){const s=t.map(r=>({...r}));for(let r=1;r=2){const c=i[i.length-2];if(Math.abs(c.x-a.x)<.01&&Math.abs(a.x-o.x)<.01||Math.abs(c.y-a.y)<.01&&Math.abs(a.y-o.y)<.01){i[i.length-1]=o;continue}}i.push(o)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Tt(t,e,n){const s=[];for(let r=0;rMath.min(d.x,f.x)+.75&&CMath.min(S.y,T.y)+.75&&Ei.split(/\s+/).map(parseFloat).filter(r=>Number.isFinite(r)),s=(i,r,o)=>{const a=[];let c=r;for(const u of i)a.push([c,c+u]),c+=u+o;return a};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var nt=t=>t==="left"||t==="right",me={top:"bottom",bottom:"top",left:"right",right:"left"};function kn(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Mn(t,e,n){const s=[];t.edges.forEach((r,o)=>{const a=t.byId.get(r.from),c=t.byId.get(r.to),[u,y]=e[o],g=a.row===c.row&&nt(u)&&nt(y)&&u===me[y]||a.col===c.col&&!nt(u)&&!nt(y)&&u===me[y];s.push({edge:o,end:"from",node:a,side:u,far:c,straight:g,f:.5},{edge:o,end:"to",node:c,side:y,far:a,straight:g,f:.5})});const i=new Map;for(const r of s){const o=`${r.node.id}.${r.side}`;i.has(o)||i.set(o,[]),i.get(o).push(r)}for(const[r,o]of i){if(o[0].node.shape==="decision")continue;const a=d=>nt(d.side)?d.far.row-d.node.row:d.far.col-d.node.col,c=o.filter(d=>d.straight),u=o.filter(d=>!d.straight);if(u.sort((d,f)=>a(d)-a(f)||(nt(d.side)?d.far.col-f.far.col:d.far.row-f.far.row)*(a(d)<0?1:-1)),o.length>3&&n(`${r.replace(".","'s ")} side has ${o.length} lines; more than three is an error: use another side`),!c.length){u.length===2?(u[0].f=.25,u[1].f=.75):u.length===3?(u[0].f=.25,u[1].f=.5,u[2].f=.75):u.length>3&&u.forEach((d,f)=>{d.f=(f+1)/(u.length+1)});continue}const y=new Map;for(const d of c)y.has(d.far.id)||y.set(d.far.id,[]),y.get(d.far.id).push(d);for(const d of y.values())d.length>1&&d.sort((f,S)=>f.edge-S.edge).forEach((f,S)=>{f.f=d.length===2?S===0?.25:.75:(S+1)/(d.length+1)});const g=Math.min(...c.map(d=>d.f)),l=Math.max(...c.map(d=>d.f)),p=u.filter(d=>a(d)<0),x=u.filter(d=>a(d)>=0);p.forEach((d,f)=>{d.f=g*(f+1)/(p.length+1)}),x.forEach((d,f)=>{d.f=l+(1-l)*(f+1)/(x.length+1)})}return s}function ye(t,e,n){const{l:s,t:i,r,b:o}=t.rect;return nt(e)?lt(t,e,i+(o-i)*n):lt(t,e,s+(r-s)*n)}function be(t,e,n,s){const i=new Map;return e.querySelectorAll(`.${s}-node`).forEach(r=>{const o=t.byId.get(r.dataset.node);o&&i.set(o.id,{id:o.id,rect:ft(r,n),shape:o.shape,i:o.i})}),i}function $e(t,e){const n=e.head,s=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-s,r:i+s,t:r-n,b:r}:t.dir==="up"?{l:i-s,r:i+s,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-s,b:r+s}:{l:i,r:i+n,t:r-s,b:r+s}}var we=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function ve(t,e,n,s){const i=(r,o)=>{const a=r+o-Math.floor(r+o);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const r of i(t.t,n))for(const o of i(t.l,e)){if(!o&&!r)return t;const a={l:t.l+o,r:t.r+o,t:t.t+r,b:t.b+r};if(s(a))return a}return t}function Sn(t,e,n,s,i,r,o,a,c){const u=o.space,y=[],g=[],l=[],p=[],x=u("1"),d=e.filter(f=>t.edges[f.i]?.label).sort((f,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[f.i].kind==="main")||f.i-S.i);for(const f of d){const S=t.edges[f.i].label,T=a(S,"label"),C=16*Wt(S),E=f.pts.length-2,A=[];pt(f.pts).forEach(([L,F],I)=>{const M=Math.abs(L.y-F.y)<.01,O=M?L.x:L.y;let N=M?F.x:F.y;const G=Math.sign(N-O)||1;I===E&&(N-=G*o.head);let W=[[O,N]];for(const m of i)for(const b of M?[m.l,m.r]:[m.t,m.b]){const h=M?L.y:L.x;(M?h>m.t&&hm.l&&hb>Math.min($,w)+1&&b{const h=(m+b)/2,k=M?{x:h,y:L.y}:{x:L.x,y:h};return!i.some($=>k.x>$.l&&k.x<$.r&&k.y>$.t&&k.y<$.b)},K=f.axes?.[I]??(M?L.y:L.x);for(const[m,b]of W)A.push({horiz:M,c:K,p:m,q:b,len:Math.abs(b-m),pri:W.length>1&&Y(m,b)?1:0})}),A.sort((L,F)=>F.pri-L.pri||F.len-L.len);let j=null,Z=!1;const B=(L,F=!0)=>{const I=ue(L,x);return F&&(L.lr.r||L.tr.b)||n.some(M=>he(I,M))||y.some(M=>ut(I,M))||s.heads.some(M=>ut(I,M))||s.rects.some(M=>ut(I,M))?!1:!e.some(M=>M.i!==f.i&&pt(M.pts).some(([O,N])=>ut(I,we(O,N,M.width))))};for(const L of A){for(const F of[1/2,1/3,2/3]){const I=L.p+(L.q-L.p)*F,M=[],O=u("2")+f.width/2;if(L.horiz?(L.len>=T+2*u("1")+u("3-5")&&M.push({box:{l:I-T/2-u("1"),r:I+T/2+u("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),M.push({box:{l:I-T/2,r:I+T/2,t:L.c-O-C,b:L.c-O},on:!1}),M.push({box:{l:I-T/2,r:I+T/2,t:L.c+O,b:L.c+O+C},on:!1})):(L.len>=C+u("3")&&M.push({box:{l:L.c-T/2-u("1"),r:L.c+T/2+u("1"),t:I-C/2,b:I+C/2},on:!0}),M.push({box:{l:L.c+O,r:L.c+O+T,t:I-C/2,b:I+C/2},on:!1}),M.push({box:{l:L.c-O-T,r:L.c-O,t:I-C/2,b:I+C/2},on:!1})),j=M.find(N=>B(N.box))??null,j)break;!Z&&M.some(N=>B(N.box,!1))&&(Z=!0)}if(j)break}if(!j){l.push(f.i),Z&&p.push(f.i);continue}const ot=ve(j.box,c.ox,c.oy,L=>B(L));y.push(ot),g.push({i:f.i,text:S,box:ot,on:j.on})}return{labels:g,unseated:l,bounded:p}}function xe(t,e,n,s){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(o=>{if(o.getClientRects().length===0||getComputedStyle(o).display==="contents")return;const a=ft(o,e);r.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const c=o.querySelector(`:scope > .${n}-glabel`);c&&c.getClientRects().length&&i.push(ft(c,e))}),t.querySelectorAll(`.${n}-lane`).forEach((o,a)=>{if(!o.getClientRects().length)return;const c=ft(o,e);a>0&&i.push({l:c.l,r:c.r,t:c.t-s/2-.5,b:c.t-s/2+.5});const u=o.querySelector(`.${n}-lane-name`);u&&i.push(ft(u,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function En(t,e){const{m:s,tk:i,P:r,drawing:o,origin:a,warn:c}=t,u=i.space,y=be(s,o,a,r),g=[...y.values()],l=xn(o),p=a.left-Math.floor(a.left),x=a.top-Math.floor(a.top),d=pe(p,x),f=o.clientWidth,S=o.clientHeight,T=h=>s.type==="data-flow"?h.col+1:h.col,C=parseFloat(getComputedStyle(o).rowGap)||0,E={w:f,h:S,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:p,oy:x};if(s.type==="sequence")return Ln(t,E,d);let A,j=[];s.type==="schema"?A=s.edges.map(h=>{const k=s.byId.get(h.from),$=s.byId.get(h.to);if(k.col===$.col){const w=k.col===s.cols&&s.cols>1?"left":"right";return[w,w]}return $.col>k.col?["right","left"]:["left","right"]}):(A=s.edges.map(h=>{const k=s.byId.get(h.from),$=s.byId.get(h.to),[w,_]=kn(k,$);return[h.fromSide??w,h.toSide??_]}),j=Mn(s,A,c||(()=>{})));const Z=(h,k)=>{const $=o.querySelector(`.${r}-node[data-node="${CSS.escape(h)}"] .${r}-row[data-row="${k}"]`);if(!$)return 0;const w=ft($,a);return(w.t+w.b)/2},B=s.edges.map((h,k)=>{const[$,w]=A[k],_=y.get(h.from),q=y.get(h.to),R=Ct(h.kind,i);if(h.fk){const V=Z(h.from,h.fromRow),P=Z(h.to,h.toRow),U=d.y(V,R),et=d.y(P,R);return{p1:{x:$==="right"?_.rect.r:_.rect.l,y:U},p2:{x:w==="right"?q.rect.r:q.rect.l,y:et},r1:V,r2:Math.abs(U-et)<.01?V:P}}const Q=j.find(V=>V.edge===k&&V.end==="from").f,X=j.find(V=>V.edge===k&&V.end==="to").f;let z=ye(_,$,Q),D=ye(q,w,X);const tt=nt($)?z.y:z.x;let at=nt(w)?D.y:D.x;return nt($)?z={...z,y:d.y(z.y,R)}:z={...z,x:d.x(z.x,R)},nt(w)?D={...D,y:d.y(D.y,R)}:D={...D,x:d.x(D.x,R)},nt($)&&nt(w)&&Math.abs(z.y-D.y)<1.01&&(D={...D,y:z.y},at=tt),!nt($)&&!nt(w)&&Math.abs(z.x-D.x)<1.01&&(D={...D,x:z.x},at=tt),z=nt($)?lt(_,$,z.y):lt(_,$,z.x),D=nt(w)?lt(q,w,D.y):lt(q,w,D.x),{p1:z,p2:D,r1:tt,r2:at}}),ot=new Set;s.type==="schema"&&s.edges.forEach((h,k)=>{Math.abs(s.byId.get(h.from).col-s.byId.get(h.to).col)>1&&ot.add(k)});const L=new Map,F=new Set;s.edges.forEach((h,k)=>{if(ot.has(k))return;const[$,w]=A[k],{p1:_,p2:q}=B[k],R=s.byId.get(h.from),Q=s.byId.get(h.to);let X=null,z=null,D=!1;if($===w){if(nt($)){const V=$==="right"?Math.max(T(R),T(Q)):Math.min(T(R),T(Q))-1,P=l.cols[V-1],U=l.cols[V];P&&U&&(X=`c${V}`,z=[P[1],U[0]],D=!0)}else{const V=$==="bottom"?Math.max(R.row2,Q.row2):Math.min(R.row,Q.row)-1,P=l.rows[V-1],U=l.rows[V];P&&U&&(X=`r${V}`,z=[P[1],U[0]],D=!1)}X&&F.add(k)}else if(nt($)&&nt(w)&&Math.abs(_.y-q.y)>.5){const V=T(Q),P=w==="left",U=l.cols[(P?V-1:V)-1],et=l.cols[(P?V:V+1)-1];U&&et&&(X=`c${P?V-1:V}`,z=[U[1],et[0]],D=!0)}else if(!nt($)&&!nt(w)&&Math.abs(_.x-q.x)>.5){const P=w==="top"?Q.row-1:Q.row2,U=l.rows[P-1],et=l.rows[P];U&&et&&(X=`r${P}`,z=[U[1],et[0]],D=!1)}if(!X||!z)return;L.has(X)||L.set(X,{span:z,vertical:D,members:new Map});const tt=`${h.to}.${w}.${Math.round(D?q.y:q.x)}`,at=L.get(X);at.members.has(tt)||at.members.set(tt,[]),at.members.get(tt).push(k)});const I=new Map,M=h=>{const[k,$]=A[h],{p1:w,p2:_}=B[h];if(nt(k)&&nt($)){if(k===$){const R=I.get(h)??(k==="right"?Math.max(w.x,_.x)+u("4"):Math.min(w.x,_.x)-u("4"));return[w,{x:R,y:w.y},{x:R,y:_.y},_]}if(Math.abs(w.y-_.y)<=.5)return[w,{x:_.x,y:w.y}];const q=I.get(h)??(w.x+_.x)/2;return[w,{x:q,y:w.y},{x:q,y:_.y},_]}if(!nt(k)&&!nt($)){if(k===$){const R=I.get(h)??(k==="bottom"?Math.max(w.y,_.y)+u("4"):Math.min(w.y,_.y)-u("4"));return[w,{x:w.x,y:R},{x:_.x,y:R},_]}if(Math.abs(w.x-_.x)<=.5)return[w,{x:w.x,y:_.y}];const q=I.get(h)??(w.y+_.y)/2;return[w,{x:w.x,y:q},{x:_.x,y:q},_]}return nt(k)?[w,{x:_.x,y:w.y},_]:[w,{x:w.x,y:_.y},_]},O=h=>{const k=s.edges[h],$=Ct(k.kind,i),w=M(h),_=ge(w,$,d);let q;return w.length===_.length&&(q=pt(w).map(([R,Q])=>Math.abs(R.y-Q.y)<.75?(R.y+Q.y)/2:(R.x+Q.x)/2),q[0]=B[h].r1,q.length>1&&(q[q.length-1]=B[h].r2)),{i:h,from:k.from,to:k.to,kind:k.kind,pts:_,tip:_[_.length-1],dir:Dt(_),dot:k.fk?_[0]:void 0,width:$,axes:q}},N=()=>s.edges.flatMap((h,k)=>ot.has(k)?[]:[O(k)]);let G=null;const W=h=>{G??(G=N());const k=G.map($=>h.has($.i)?O($.i):$);return{lines:k,score:An(k,h)*1e5+Tt(k,void 0,h).length*1e3+Gt(k.filter($=>h.has($.i)),g,s).length}},Y=(h,k)=>{const $=h.flatMap(w=>{const{p1:_,p2:q}=B[w];return k?[_.y,q.y]:[_.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,h]of L){const k=[...h.members.values()].map(w=>({members:w,run:Y(w,h.vertical)})).sort((w,_)=>w.run[0]-_.run[0]),$=[];for(const w of k){const _=$[$.length-1];_&&_.some(q=>q.run[0]F.has(tt)))continue;const _=w.map(tt=>tt.members),q=_.length,R=(h.span[1]-h.span[0])/(q+1);RV.forEach(U=>I.set(U,h.span[0]+R*(P+1))));const at=W(Q);at.scorett.forEach(V=>I.set(V,h.span[0]+R*(at+1)))),G=D}}E.lines=N();for(const h of ot)c?.(`${s.edges[h].from} to ${s.edges[h].to} is two columns apart, so its line is not drawn; its row still writes the target`);E.crossings=Tt(E.lines),E.through=Gt(E.lines,g,s),E.outside=Se(E.lines,f,S,i);const{obstacles:K,groups:m}=xe(o,a,r,C);K.heads=E.lines.map(h=>$e(h,i));const b=Sn(s,E.lines,g,K,m,{l:0,t:0,r:f,b:S},i,e,{ox:p,oy:x});return E.labels=b.labels,E.unseated=b.unseated,E.bounded=b.bounded,E.overlaps=[...new Set(ke(E.lines,null).flat())],E}function An(t,e){return ke(t,e).length}function ke(t,e){const n=[];for(let s=0;s=a)continue;const[f,S]=l?[c.x,u.x]:[c.y,u.y],[T,C]=l?[y.x,g.x]:[y.y,g.y];Math.min(Math.max(f,S),Math.max(T,C))-Math.max(Math.min(f,S),Math.min(T,C))>1&&n.push([r.i,o.i])}}return n}function*Me(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const c=a===r.pts.length-1?Math.max(r.width/2,s.head/2):r.width/2;return o.x-c<-.5||o.x+c>e+.5||o.y-c<-.5||o.y+c>n+.5})&&i.push(r.i);return i}function Gt(t,e,n){const s=[];for(const i of t){const r=pt(i.pts);e.some(o=>r.some(([a,c])=>bn(a,c,o)))&&s.push(i.i)}return s}function Ln(t,e,n){const{m:s,tk:i,P:r,drawing:o,origin:a}=t,c=i.space,u=new Map;o.querySelectorAll(`.${r}-node`).forEach(E=>u.set(E.dataset.node,ft(E,a)));const y=o.querySelector(`.${r}-steps`),g=y?ft(y,a).b:e.h,l=E=>{const A=u.get(E);return A?n.x((A.l+A.r)/2,i.hair):0};for(const E of s.nodes){const A=u.get(E.id);A&&e.lifelines.push({x:l(E.id),y1:A.b,y2:g})}const p=E=>u.get(E.id),x=new Map;o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=ft(E,a);x.set(Number(E.querySelector(`.${r}-num`)?.textContent??0),(A.t+A.b)/2)});const d=i.activation,f=d/2,S=E=>{const A=s.byId.get(E.who);if(!A)return null;const j=l(E.who),B=(A.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),ot=(E.depth-1)*c("1")*B,L=x.get(E.from)??0,F=x.get(E.to)??L,I=E.from===E.to;return{l:n.x(j-f+ot,i.hair),r:n.x(j+f+ot,i.hair),t:n.y(I?L-c("2")-c("1"):L,i.hair),b:n.y(I?L+c("2")+c("1"):F,i.hair)}},T=s.bars.map(E=>({bar:E,rect:S(E)})).filter(E=>E.rect);e.bars=T.map(E=>E.rect);const C=(E,A,j)=>T.filter(({bar:Z})=>Z.who===E&&Z.to>=A&&(j?Z.from<=A:Z.fromB.bar.depth-Z.bar.depth)[0]?.rect;return o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=E.dataset.from,j=E.dataset.to,Z=E.dataset.kind??"plain",B=Ct(Z,i),ot=ft(E,a),L=n.y((ot.t+ot.b)/2,B),F=Number(E.querySelector(`.${r}-num`)?.textContent??0);let I=l(A),M=l(j),O;if(A===j){const b=E.dataset.self==="start"?-c("6"):c("6"),h=C(A,F,!0),k=h?b>0?h.r:h.l:I,$=n.y(L-c("2"),B),w=n.y(L+c("2"),B);O=[{x:k,y:$},{x:n.x(I+b,B),y:$},{x:n.x(I+b,B),y:w},{x:k,y:w}]}else{const b=M>I?1:-1,h=C(A,F,!1),k=C(j,F,!0);h&&(I=b>0?h.r:h.l),k&&(M=b>0?k.l:k.r),O=[{x:I,y:L},{x:M,y:L}]}e.lines.push({i:F,from:A,to:j,kind:Z,pts:O,tip:O[O.length-1],dir:Dt(O),width:B});const N=E.querySelector(`.${r}-said`),G=E.querySelector(`.${r}-note`),W=s.byId.get(A),Y=s.byId.get(j);if(!W||!Y)return;const K=A===j?(()=>{const b=s.nodes[W.i+(E.dataset.self==="start"?-1:1)],h=b?l(b.id):E.dataset.self==="start"?0:e.w;return Math.abs(h-I)-c("6")-c("2-5")-c("2")})():Math.abs(M-I)-2*c("2");Math.max(N?N.getBoundingClientRect().width:0,G?G.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(F)}),o.querySelectorAll(`.${r}-fhead`).forEach(E=>{const A=E.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!A)return;[...E.children].reduce((Z,B)=>Z+B.getBoundingClientRect().width,0)+c("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${E.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function Ee(t,e,n,s=ht()){const{m:i,tk:r,P:o,drawing:a,origin:c}=t,u=r.space,y=be(i,a,c,o),g=[...y.values()],l=c.left-Math.floor(c.left),p=c.top-Math.floor(c.top),x=pe(l,p),d=a.clientWidth,f=a.clientHeight,S={w:d,h:f,nodes:g,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:l,oy:p},T=ht();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:T};const C=d-(parseFloat(getComputedStyle(a).paddingRight)||0),E=(M,O,N)=>{const G=[M];for(let W=1;W<=(yt(s,O)??0);W++)G.push({...M,t:M.t+N*u("4")*W,b:M.b+N*u("4")*W});return G},A=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>{const O=M.parentElement,N=ft(O,c),G=getComputedStyle(O);A.set(M.dataset.node,N.r-(parseFloat(G.paddingRight)||0)-(parseFloat(G.borderRightWidth)||0))});const j=i.nodes,Z=M=>y.get(j[M].id),B=[],ot=M=>Ct(i.edges[M].kind,r);i.edges.forEach((M,O)=>{const N=n.routes[O],G=y.get(M.from),W=y.get(M.to),Y=ot(O);let K=[];const m=M.label,b=m?e(m,"label"):0,h=m?16*Wt(m):16,k=u("4");if(N==="down"||N==="up"){const w=Math.max(G.rect.l,W.rect.l),_=Math.min(G.rect.r,W.rect.r),q=i.edges.map((z,D)=>({o:z,j:D})).filter(({o:z,j:D})=>(n.routes[D]==="down"||n.routes[D]==="up")&&(z.from===M.from&&z.to===M.to||z.from===M.to&&z.to===M.from)),R=q.findIndex(z=>z.j===O),Q=q.length<2?.5:q.length===2?R===0?.25:.75:(R+1)/(q.length+1),X=x.x(w+(_-w)*Q,Y);if(K=N==="down"?[lt(G,"bottom",X),lt(W,"top",X)]:[lt(G,"top",X),lt(W,"bottom",X)],m){let z=Math.min(K[0].y,K[1].y),D=Math.max(K[0].y,K[1].y);N==="down"?D-=r.head:z+=r.head;const tt=[...a.querySelectorAll(`.${o}-group`)].map(U=>ft(U,c));let at=[[z,D]];for(const U of tt)for(const et of[U.t,U.b])at=at.flatMap(([rt,ct])=>et>rt+1&&ettt.some(rt=>(U+et)/2>rt.t&&(U+et)/2rt.l&&X1){const U=at.filter(([rt,ct])=>!V(rt,ct));[z,D]=(U.length?U:at).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const P=[1/2,1/3,2/3].map(U=>{const et=z+(D-z)*U;return{l:X-b/2-u("1"),r:X+b/2+u("1"),t:et-h/2,b:et+h/2}});B.push({k:O,cands:P,on:!0,card:N==="down"?M.to:M.from})}}else if(N==="trunk"||N==="rail"){const w=x.x(Math.max(G.rect.l,N==="rail"?W.rect.l:G.rect.l)+u(N==="trunk"?"8":"3"),Y),_=lt(G,"bottom",w);if(N==="rail"){if(K=[_,lt(W,"top",w)],m){const q=W.rect.t-u("6");B.push({k:O,cands:E({l:w+u("2-5"),r:w+u("2-5")+b,t:q-h/2,b:q+h/2},M.to,-1),on:!1,card:M.to})}}else{const q=x.x(W.rect.l+u("6"),Y),R=x.y(W.rect.t-k,Y);K=[_,{x:w,y:R},{x:q,y:R},lt(W,"top",q)],m&&B.push({k:O,cands:E({l:q+u("2-5"),r:q+u("2-5")+b,t:R-h/2,b:R+h/2},M.to,-1),on:!1,card:M.to})}}else{const w=Math.min(A.get(M.from)??d,A.get(M.to)??d),_=x.x(n.gutter?C+(n.lanes[O]?2*u("3-5"):u("3-5")):w-u("2-5"),Y),q=x.y(G.rect.t+(G.rect.b-G.rect.t)*n.exits[O],Y),R=lt(G,"right",q),Q=x.x(W.rect.r-u("6"),Y),X=N==="end-down",z=x.y(X?W.rect.t-k:W.rect.b+k,Y);K=[R,{x:_,y:R.y},{x:_,y:z},{x:Q,y:z},lt(W,X?"top":"bottom",Q)];const D=X?M.to:j[W.i+1]?.id??M.to;m&&B.push({k:O,cands:E({l:Q-u("2-5")-b,r:Q-u("2-5"),t:z-h/2,b:z+h/2},D,X?-1:1),on:!1,card:D})}const $=ge(K,Y,x);S.lines.push({i:O,from:M.from,to:M.to,kind:M.kind,pts:$,tip:$[$.length-1],dir:Dt($),width:Y})}),S.crossings=Tt(S.lines),S.through=Gt(S.lines,g,i),S.outside=Se(S.lines,d,f,r);const{obstacles:L}=xe(a,c,o,0);L.heads=S.lines.map(M=>$e(M,r));const F=[],I={l:0,t:0,r:d,b:f};for(const M of B){const O=W=>{const Y=ue(W,u("1"));return W.lI.r+.5||W.tI.b+.5||g.some(K=>he(Y,K))||F.some(K=>ut(Y,K))||L.heads.some(K=>ut(Y,K))||L.rects.some(K=>ut(Y,K))||S.lines.some(K=>K.i!==M.k&&pt(K.pts).some(([m,b])=>ut(Y,we(m,b,K.width))))},N=M.cands.find(W=>!O(W));N||(T[M.card]=(T[M.card]??0)+1,S.unseated.push(M.k));const G=N?ve(N,l,p,W=>!O(W)):M.cands[0];F.push(G),S.labels.push({i:M.k,text:i.edges[M.k].label,box:G,on:M.on})}return{geo:S,grow:T}}function qn(t,e){const n=r=>String(Math.round(r*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let r=1;r({...E})),g=y[y.length-1];g.x-=r.x*u,g.y-=r.y*u;const l=e.tip.x-r.x*a,p=e.tip.y-r.y*a,x=-r.y*c,d=r.x*c,f=E=>Math.round(E*100)/100,S=it(e.kind),T=o?``:``,C=e.dot?``:"";return`${T}${C}`}function Ae(t,e,n,s){const i=new Map,r=new Map;for(const a of e.crossings)r.has(a.under)||r.set(a.under,[]),r.get(a.under).push(a);let o="";for(const[a,c]of r){const u=`${s}-cut-${a}`;i.set(a,u);const y=c.map(g=>{const l=e.lines[g.top],p=e.lines[g.under],x=l.width/2+n.cut,d=p.width/2+1;return g.underVertical?``:``}).join("");o+=`${y}`}return{defs:o,ids:i}}function Le(t,e,n,s){const{defs:i,ids:r}=Ae(t,e,n,s),o=e.lifelines.map(y=>``).join("")+(e.bars??[]).map(y=>``).join(""),a=e.lines.map((y,g)=>On(t,y,n,r.get(g)??null,y.from===y.to?n.radiusXs:n.radius)).join(""),c=`${i?`${i}`:""}${o}${a}`,u=e.labels.map(y=>`1?' data-lines="2"':""} style="left:${Math.round(y.box.l*100)/100}px;top:${Math.round(y.box.t*100)/100}px;width:${Math.round((y.box.r-y.box.l)*100)/100}px">${y.text.split(` -`).map(it).join("
")}
`).join("");return c+u}function Kt(t,e,n,s,i,r,o,a){const u=t.querySelector(`.${n}-drawing`);if(!u||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const y=mn(t),g=wn(u,n),l=vn(e,y,g);a?.(l.least);const p=t.clientWidth,x=(()=>{const L=document.activeElement;return L&&u.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),d=L=>mt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:x&&L.layout!=="drawn"?x:void 0};let f=!1;const S=L=>{if(f=!1,e.type!=="flowchart")return L;r({...L,heights:void 0,words:void 0});const F=ht(),I=ht();return u.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const O=M.querySelector(`.${n}-words`);if(!O)return;const N=M.getBoundingClientRect(),G=K=>{const m={w:K.width+2*y.space("2-5"),h:K.height+2*y.space("2")},b=1-m.w/N.width,h=b>.05?m.h/2/b:m.h*10;return Math.max(y.space("16"),Math.ceil(N.width/5),Math.ceil(2*h))},W=O.getBoundingClientRect();let Y=G(W);if(Y>N.width){const K=k=>(M.style.setProperty("--_ww",`${k}px`),O.getBoundingClientRect()),m=Math.floor(M.clientWidth-2*y.space("2-5"));let b=Math.ceil(W.width),h=W.height;for(;b1;){const q=k+$>>1;K(q).heightN.width&&(f=!0)}),{...L,heights:F,words:Object.keys(I).length?I:void 0}},T=()=>({m:e,tk:y,P:n,drawing:u,origin:u.getBoundingClientRect(),warn:o}),C=i.autoOpen?{open:!1,autoOpen:void 0}:{},E=(L,F)=>F.map(I=>At(e,L.lines.find(M=>M.i===I))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:y,least:l.least};if(p>=l.least&&!e.unplaced){const L=O=>{let N=d({...i,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return N=S(N),r(N),{dd:N,g:En(T(),g)}};let{dd:F,g:I}=L(!1);const M=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||f;if(!M(I)&&I.unseated.length&&I.unseated.every(O=>I.bounded?.includes(O))){const O=L(!0);!M(O.g)&&!O.g.unseated.length&&({dd:F,g:I}=O)}if(!M(I)&&!I.unseated.length)return I.crossings.length&&o?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(O=>`${At(e,I.lines[O.top])} over ${At(e,I.lines[O.under])}`).join("; ")}`),{dyn:F,geo:I,ink:Le(n,I,y,s),tokens:y,least:l.least};f&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: a decision would be taller than it is wide`),I.misfit?.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: ${I.misfit.join("; ")}`),I.through.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: ${E(I,I.through)} would pass through a node`),I.overlaps?.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: ${E(I,I.overlaps)} would lie on one another`),I.outside.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: ${E(I,I.outside)} would leave the drawing`),I.unseated.length&&o?.(`the drawn layout does not fit at ${Math.round(p)}px: no clean seat for ${I.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=d({...i,...C,layout:"stacked",heights:void 0,grow:ht(),track:e.type==="schema"?l.table:void 0,bare:void 0,pad:void 0});if(A=S(A),r(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:y,least:l.least};const j=se(e);let Z=Ee(T(),g,j,A.grow);for(let L=0;L<6&&Object.keys(Z.grow).length;L++){const F=ht(A.grow);for(const[I,M]of Object.entries(Z.grow))F[I]=(yt(F,I)??0)+M;A={...A,grow:F},r(A),Z=Ee(T(),g,j,F)}const B=Z.geo;if(B.unseated.length>0||B.through.length>0||B.outside.length>0||j.third){B.unseated.length&&o?.(`the stacked drawing has no clean seat for ${[...new Set(B.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),B.through.length&&o?.(`in the stacked drawing ${E(B,B.through)} would pass through a node, so its lines are not drawn`),B.outside.length&&o?.(`in the stacked drawing ${E(B,B.outside)} would leave the drawing, so its lines are not drawn`),j.third&&o?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={...B,lines:[],labels:[],crossings:[]};return{dyn:d({...A,grow:ht(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:y,least:l.least}}return B.crossings.length&&o?.(`${B.crossings.length} crossing${B.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${B.crossings.map(L=>`${At(e,B.lines[L.top])} over ${At(e,B.lines[L.under])}`).join("; ")}`),{dyn:A,geo:B,ink:Le(n,B,y,s),tokens:y,least:l.least}}function At(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function _n(t,e,n,s,i,r){const o=new Set;if(r){o.add(r);for(const d of n?.lines??[])d.from===r&&o.add(d.to),d.to===r&&o.add(d.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(d=>d.toggleAttribute("data-near",o.has(d.dataset.node))),!n||!s)return;const a=d=>!!r&&(d.from===r||d.to===r),c=t.querySelector(`.${e}-edges`),u=new Map;t.querySelectorAll(`.${e}-edge`).forEach(d=>u.set(d.getAttribute("data-edge"),d));for(const d of n.lines){const f=u.get(String(d.i));f&&(f.toggleAttribute("data-lit",a(d)),f.toggleAttribute("data-dim",!!r&&!a(d)))}if(t.querySelectorAll(`.${e}-label`).forEach(d=>{const f=n.lines.find(S=>String(S.i)===d.dataset.edge);d.toggleAttribute("data-lit",!!(f&&a(f)))}),c){for(const d of n.lines)if(a(d)){const f=u.get(String(d.i));f&&c.appendChild(f)}}const y=Tt(n.lines,a),{defs:g,ids:l}=Ae(e,{...n,crossings:y},s,i),p=t.querySelector(`.${e}-svg`);if(!p)return;let x=p.querySelector("defs");!x&&g&&(x=document.createElementNS("http://www.w3.org/2000/svg","defs"),p.insertBefore(x,p.firstChild)),x&&(x.innerHTML=g),n.lines.forEach((d,f)=>{const S=u.get(String(d.i))?.querySelector(`.${e}-line`);if(!S)return;const T=l.get(f);T?S.setAttribute("mask",`url(#${T})`):S.removeAttribute("mask")})}var Cn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Bn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Cn()||jn(t)?"done":"pending")}}var Tn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function jn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Tn(t))!==null}catch{return!1}}function qe(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Rn(t,e,n,s=!1,i=!1){const r=s?Ot(t):null;if(r&&n.startsWith("Arrow")){const u={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return u?r[e]?.[u]??null:null}const o=t.byId.get(e)?.i??0,a=t.nodes.length;let c;if(n==="ArrowRight"||n==="ArrowDown")c=o+1;else if(n==="ArrowLeft"||n==="ArrowUp")c=o-1;else if(n==="Home")c=0;else if(n==="End")c=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,c))].id}var Wn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Ie=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],Nn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],Oe=t=>t==null||t===!1;function zn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function jt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?Ie:Wn;for(const o of s)Oe(e.a[o])&&t.removeAttribute(o);for(const[o,a]of Object.entries(e.a)){if(o==="class")continue;if(o==="style"){const u=t.style,y=new Map(String(a??"").split(";").map(g=>{const l=g.indexOf(":");return[g.slice(0,l).trim(),g.slice(l+1).trim()]}).filter(([g])=>g));for(const[g,l]of y)u.getPropertyValue(g).trim()!==l&&u.setProperty(g,l);for(const g of Nn)y.has(g)||u.removeProperty(g);continue}if(n&&!Ie.includes(o))continue;if(Oe(a)){t.removeAttribute(o);continue}const c=a===!0?"":String(a);t.getAttribute(o)!==c&&t.setAttribute(o,c)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(o=>typeof o!="string"&&"slot"in o))return;const i=[...t.children];let r=0;for(const o of e.c)if(!(typeof o=="string"||"slot"in o)){for(let a=r;at.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function i(l,p,x){return{prefix:n,base:l,hasSource:p.source!==void 0&&p.source!==null&&p.source!=="",hiddenClass:"visually-hidden",viewer:x?x.keys:void 0}}function r(l,p,x,d){var f=function(S){return''+it(S)+""};return{source:it(String(p.source||"")),summary:it(String(p.summary||"")),hint:Ht(l).map(function(S){return""+S.keys.map(f).join(" ")+" "+it(S.words)+""}).join(""),toggle:'"}}function o(l,p,x){var d=$t(l),f=_t(d,{},i(p,l,x)),S=Nt(f,r(d,l,p,!1)),T=S.indexOf(">");return{open:S.slice(0,T+1),inner:S.slice(T+1,S.length-9),warnings:d.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],c=["--_cols","--_gpad","--_track"];function u(l,p,x,d){l.__diagram&&l.__diagram.stop();var f=(l.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(l).direction==="rtl",T=p.layout==="auto"&&(p.type==="architecture"||p.type==="flowchart"||p.type==="schema"),C=T?Array.isArray(p.placement)?p.placement:p.placement?[p.placement]:[]:[];T&&!C.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var E=p.direction?[p.direction]:p.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var J=0;J .diagram-drawing")){if(!f||!l.querySelector("#"+CSS.escape(f+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););f="dg"+s}var Z=o(p,f,d),B=document.createElement("div");B.innerHTML=Z.open+"";var ot=B.firstChild;a.forEach(function(H){l.removeAttribute(H)}),c.forEach(function(H){l.style.removeProperty(H)});for(var L=0;L :not(script[data-diagram])").forEach(function(H){H.remove()}),l.insertAdjacentHTML("beforeend",Z.inner)}j.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var I=i(f,p,d),M={},O=null,N=null,G=null,W=null,Y=Object.create(null),K=function(H){Y[H]||(Y[H]=1,console.warn("Basalt diagram: "+H))},m=function(H){jt(l,_t(j,H,I))},b=l.querySelector(".diagram-ink"),h=l.querySelector(".diagram-toggle"),k=!d&&j.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,_=function(){k&&qe(l)};function q(){_n(l,n,O&&O.geo,O&&O.tokens,f,N||W||G),X()}var R=null,Q=!d&&matchMedia("(hover: none), (pointer: coarse)").matches;function X(){var H=Q&&!d&&b&&b.innerHTML!=="";if(l.toggleAttribute("data-touch",!!(Q&&!d)),H&&!R){var J=l.querySelector(":scope > .diagram-foot");if(!J)return;R=document.createElement("button"),R.type="button",R.className="btn diagram-clear",R.setAttribute("data-variant","secondary"),R.setAttribute("data-size","sm"),R.innerHTML="Clear highlight",R.addEventListener("click",function(){W&&(W=null,q())}),J.appendChild(R)}else!H&&R&&(R.remove(),R=null);R&&(W?R.removeAttribute("aria-disabled"):R.setAttribute("aria-disabled","true"))}function z(H){if(!H.defaultPrevented){var J=Ye(l,n,H,W);J!==void 0&&(_(),Q=!0,W=J,q())}}function D(){h&&(h.setAttribute("aria-expanded",String(!!M.open)),h.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function tt(){if(T&&C.length>1&&!d){for(var H=null,J=0;J1&&d&&!p.direction&&d.room){for(var We=d.room(),Ne=-1,Zt=null,Ut=0;UtNe+1e-6&&(Ne=Fe,Zt=Jt)}}}Zt&&(j=Zt)}O=(d?d.measure:Kt)(l,j,n,f,M,m,K),M=O.dyn,m(M),D();var Xt=l.querySelector(":scope > .diagram-hint");if(Xt){var He=Ht(j,M.layout==="drawn").map(function(St){return""+St.keys.map(function(Kn){return''+it(Kn)+""}).join(" ")+" "+it(St.words)+""}).join("");Xt.innerHTML!==He&&(Xt.innerHTML=He)}mt(j,M)||(G=W=null);var De=b&&O.ink!==w;De&&(b.innerHTML=O.ink,w=O.ink),q(),k&&O.tokens&&(Bn(l,!!(O.geo&&O.geo.lines.length)),De&&$&&$.redrawn()),d&&d.onMeasured&&O.tokens&&d.onMeasured(O,l),j.text&&typeof e.diagramText=="function"&&e.diagramText(l,j,p)}function at(H){M=H,m(M)}function V(H){var J=M.stop;M=Object.assign({},M,{stop:H}),Fn(l,n,J,H)}var P=function(H){var J=H&&H.closest?H.closest(".diagram-node"):null;return J&&l.contains(J)?J:null};function U(H){var J=P(H.target);if(!(!J||H.defaultPrevented)){if(_(),H.key==="Escape"){!d&&(N||G||W)&&(H.preventDefault(),N=G=W=null,q());return}if(mt(j,M)){var dt=Rn(j,J.getAttribute("data-node"),H.key,M.layout==="drawn");if(dt){H.preventDefault(),V(dt);var Mt=l.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');Mt&&Mt.focus()}}}}function et(H){var J=P(H.target);if(J){_();var dt=J.getAttribute("data-node");N=J.matches(":focus-visible")?dt:null,mt(j,M)&&M.stop!==dt&&V(dt),q()}}function rt(H){var J=P(H.target);J&&(P(H.relatedTarget)||(N=null),M.keep===J.getAttribute("data-node")&&at(Object.assign({},M,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var J=P(H.target);J&&_();var dt=J&&mt(j,M)?J.getAttribute("data-node"):null;dt!==G&&(G=dt,q())}}function Lt(){G&&(G=null,q())}function bt(){_(),at(Object.assign({},M,{open:!M.open,autoOpen:void 0})),D()}l.addEventListener("keydown",U),l.addEventListener("focusin",et),l.addEventListener("focusout",rt),l.addEventListener("pointerover",ct),l.addEventListener("pointerleave",Lt),l.addEventListener("click",z),h&&h.addEventListener("click",bt),tt();var kt=l.clientWidth,Vt=0,_e=!0,Ce=new ResizeObserver(function(){Math.abs(l.clientWidth-kt)<.5||(kt=l.clientWidth,cancelAnimationFrame(Vt),Vt=requestAnimationFrame(tt))});Ce.observe(l),document.fonts&&document.fonts.ready.then(function(){_e&&tt()});var Be=matchMedia("(forced-colors: active)"),Te=j.nodes.some(function(H){return H.mark});Te&&Be.addEventListener("change",tt),k&&($=e.diagramMotion(l,{fig:l,P:n,base:f,model:function(){return j},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},p));var je=!d&&p.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(l,p,{model:j,settle:_,animated:k}):null,Re=l.querySelector(":scope > .diagram-foot"),Hn=!d&&p.export===!0&&Re&&typeof e.diagramExport=="function"?e.diagramExport(Re,l):[];l.__diagram={stop:function(){je&&je.destroy(),Hn.forEach(function(H){H.remove()}),_e=!1,Ce.disconnect(),cancelAnimationFrame(Vt),Te&&Be.removeEventListener("change",tt),$&&$.destroy(),l.removeEventListener("keydown",U),l.removeEventListener("focusin",et),l.removeEventListener("focusout",rt),l.removeEventListener("pointerover",ct),l.removeEventListener("pointerleave",Lt),l.removeEventListener("click",z),R&&R.remove(),h&&h.removeEventListener("click",bt)},layout:tt,key:y(p),send:$&&$.sendValue?$.sendValue:null}}function y(l){try{return JSON.stringify(l,function(p,x){return p==="packet"&&x&&typeof x=="object"?Object.assign({},x,{send:void 0}):x})}catch{return null}}function g(){document.querySelectorAll("figure.diagram").forEach(function(l){if(!l.__diagram){var p=l.querySelector(":scope > script[data-diagram]");if(p)try{u(l,JSON.parse(p.textContent),!0)}catch(x){console.error("Basalt diagram: this figure could not be drawn",x)}}})}e.diagramMarkup=o,e.diagramKit={draw:u,buildModel:$t,figureKey:on,figureList:un,hintEntries:Ht,toHtml:Nt,escapeHtml:it,settleEntrance:qe,measureFigure:Kt},t.diagram=function(l,p){var x=l.__diagram,d=x&&x.send?y(p):null;if(d!==null&&d===x.key){x.send(p.packet?p.packet.send:void 0);return}u(l,p)},e.step(62,"wireDiagrams",g)})(window.Basalt)})(); +`);continue}const l=e.byId.get(o.from)?.name??o.from,f=e.byId.get(o.to)?.name??o.to;n.push(v("span",{class:`${t}-tx-line`,"data-n":o.n},a,v("span",{"data-ink":"num"},`${o.n} `),s(l)," ",v("span",{"data-ink":o.kind==="main"?"main":"plain"},i(o.kind))," ",s(f)," ",v("span",{"data-ink":"label"},o.label),o.note?[" ",v("span",{"data-ink":"note"},`(${o.note})`)]:null),` +`)}return n}function gn(t,e){const{P:n}=t,s=[],i=[],r=()=>i.length?i[i.length-1].el.c:s;let o=null;for(const a of e.steps){if("band"in a){o=null,r().push(v("p",{class:`${n}-band`},v("span",null,a.band)));continue}if("open"in a){o=null;const d=i[i.length-1],h=d?`;--_fis:${a.a===d.a?1:0};--_fie:${a.b===d.b?1:0}`:"",S=v("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${h}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));r().push(S),i.push({el:S,a:a.a,b:a.b});continue}if("otherwise"in a){o=null,r().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){o=null,i.pop();continue}o||(o=v("ol",{class:`${n}-msgs`,start:a.n}),r().push(o));const l=e.byId.get(a.from),f=e.byId.get(a.to),m=l?.col??1,u=f?.col??1,c=m===u,g=c&&(e.rtl?m!==1:m===e.nodes.length),x=ee(e,a.kind);o.c.push(v("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":c?g?"start":"end":void 0,style:`--_a:${Math.min(m,u)};--_b:${Math.max(m,u)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(a.n)),v("span",{class:`${n}-mlabel`},a.label)),v("span",{class:`${n}-route`},l?.short??a.from," ",dn(n,a.kind),v("span",{class:t.hidden}," to ")," ",f?.short??a.to,x?` · ${x}`:""),a.note?v("span",{class:`${n}-note`},a.note):null))}return v("div",{class:`${n}-steps`},s)}function fe(t,e){return mt(e,`list:${t}`,()=>yn(t,e))}var mn=fe;function yn(t,e){const n=Math.min(6,e.heading+1),s=u=>v(`h${n}`,{class:`${t}-list-head`},u),i=u=>v("strong",null,u),r=u=>u.href?v("a",{href:u.href,target:u.blank?"_blank":void 0,rel:u.blank?"noopener noreferrer":void 0},i(u.name)):i(u.name),o=u=>v("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,l=u=>{const c=ee(e,u);return c?` (${c})`:""},f=u=>u.focal&&e.legend.focal?` ${vt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=x=>v("li",null,r(x),x.kind?`, ${x.kind}`:"",x.detail?[". ",x.mono?o(x.detail):x.detail,/[.!?]$/.test(x.detail)?"":"."]:/[.!?]$/.test(x.kind??x.name)?"":".",f(x)),c=[s("Parts")],g=e.nodes.filter(x=>!x.group);g.length&&c.push(v("ul",{class:`${t}-list-items`},g.map(u)));for(const x of e.groups.filter(d=>d.depth===1)){c.push(v("p",{class:`${t}-list-group`},x.label)),x.members.length&&c.push(v("ul",{class:`${t}-list-items`},x.members.map(d=>u(e.byId.get(d)))));for(const d of e.groups.filter(h=>h.parent===x.id))c.push(v("p",{class:`${t}-list-group`,"data-depth":2},d.label)),c.push(v("ul",{class:`${t}-list-items`,"data-depth":2},d.members.map(h=>u(e.byId.get(h)))))}return c.push(s("Connections")),c.push(v("ol",{class:`${t}-list-items`},e.edges.map(x=>v("li",null,i(a(x.from))," to ",i(a(x.to)),x.label?[": ",o(yt(x.label))]:"",`${l(x.kind)}.`)))),c}if(e.type==="flowchart"){const u=c=>(e.byId.get(c)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(c=>{const g=e.edges.filter(h=>h.from===c.id),x=c.shape==="decision"?"Decision":c.shape==="terminal"?g.length?"Start":"End":"Step",d=!c.detail&&/[.!?]$/.test(c.name)?" ":". ";return v("li",null,r(c),c.detail?[", ",c.mono?o(c.detail):c.detail]:"",`${d}${x}.`,f(c),g.length?v("ul",{class:`${t}-list-exits`},g.map(h=>v("li",null,h.label?`If ${yt(h.label)}: go to ${u(h.to)}, `:`Then: go to ${u(h.to)}, `,i(a(h.to)),l(h.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const c=e.edges.filter(g=>g.from===u.id);return v("li",null,`${u.laneLabel}: `,r(u),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",f(u),c.length?[" Then ",...c.flatMap((g,x)=>[x?"; ":"",`to step ${e.byId.get(g.to).step}, `,i(a(g.to)),g.label?[": ",o(yt(g.label))]:"",l(g.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(g=>v("li",null,i(g.name),g.kind?`, ${g.kind}`:"",".",f(g),ne(e,g))))];u.push(s("Messages"));let c=null;for(const g of e.steps){if("band"in g){c=null,u.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},g.band));continue}if("open"in g){c=null,u.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords[g.open]}: ${g.label}`));continue}if("otherwise"in g){c=null,u.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords.else}: ${g.otherwise}`));continue}if("close"in g){c=null;continue}c||(c=v("ol",{class:`${t}-list-items`,start:g.n}),u.push(c)),c.c.push(v("li",null,o(g.label),": ",i(a(g.from))," to ",i(a(g.to)),`${l(g.kind)}.`,g.note?` ${vt(g.note)}`:""))}return u}const m=[];for(const u of e.nodes)m.push(v(`h${n}`,{class:`${t}-list-group`},u.href?v("a",{href:u.href,target:u.blank?"_blank":void 0,rel:u.blank?"noopener noreferrer":void 0},o(u.name)):o(u.name),f(u))),m.push(v("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(c=>v("li",null,o(c.name),c.key==="PK"?", primary key":c.key==="FK"?", foreign key":"",c.ref?[", references ",o(`${c.ref.table}.${c.ref.column}`)]:c.type?`, ${c.type}`:"")),...u.more?[v("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return m}function ue(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&_t(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function Dt(t,e=!1){const n=e&&t.type!=="sequence"&&_t(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:oe(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var bn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function _t(t){return mt(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,...$n(t,r)})),n=(r,o)=>{const a=o==="right"||o==="left",l=o==="right"||o==="down",f=x=>a?[x.col,x.col]:x.rows,m=x=>a?x.rows:[x.col,x.col],u=f(r),c=m(r);let g=null;return e.forEach((x,d)=>{if(x===r)return;const h=f(x),S=m(x),j=l?h[0]-u[1]:u[0]-h[1];if(j<1)return;const C=Math.max(0,S[0]-c[1],c[0]-S[1]),E=[C===0?0:1,C===0?j:j+2*C,C,Math.abs(S[0]-c[0]),d];(!g||bn(E,g.rank))&&(g={id:x.id,rank:E})}),g?.id??null},s=ut();for(const r of e)s[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const o=new Set([r]),a=[r];for(;a.length;)for(const l of Object.values(s[a.pop()]))l&&!o.has(l)&&(o.add(l),a.push(l));return o.size};return e.every(r=>i(r.id)===e.length)?s:null})}function At(t){return mt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!Gt(t))return{lane:e,dropped:n,lanes:0};const s=(l,f)=>(t.byId.get(l)?.row??0)*1e3+f,i=new Map;t.edges.forEach((l,f)=>{const m=`${l.to}.${l.toRow}`,u=s(l.from,l.fromRow??0),c=s(l.to,l.toRow??0),g=i.get(m)??{members:[],lo:1/0,hi:-1/0};g.members.push(f),g.lo=Math.min(g.lo,u,c),g.hi=Math.max(g.hi,u,c),i.set(m,g)});const r=[...i.values()].sort((l,f)=>f.hi-f.lo-(l.hi-l.lo)),o=[];let a=0;for(const l of r.reverse()){const f=new Set(o.filter(u=>u.lo<=l.hi&&l.lo<=u.hi).map(u=>u.lane));let m=0;for(;f.has(m);)m++;if(m>1){for(const u of l.members)n.add(u);continue}o.push({lo:l.lo,hi:l.hi,lane:m});for(const u of l.members)e.set(u,m);a=Math.max(a,m+1)}return{lane:e,dropped:n,lanes:a}})}var Gt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Ct(t,e,n){const s=n.prefix,i=sn(n.base),r=t.type==="sequence"||t.type==="schema"?null:ie(t),o={P:s,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},a=e.layout==="drawn",l=bt(t,e),f=t.type==="sequence"||t.type==="schema"?a:!0,m=`h${t.heading}`,u=[`--_cols:${zt(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const c=t.type==="architecture"?se(t):[0,0,0,0],g=(d,h,S)=>d?d>1?`calc(${d} * var(--basalt-space-${h}))`:`var(--basalt-space-${h})`:S?`var(--basalt-space-${S})`:"0px",x=a&&e.pad?"3":void 0;u.push(`--_gpad:${g(c[0],"8",x)} ${g(c[1],"4")} ${g(c[2],"4",x)} ${g(c[3],"4")}`)}return Gt(t)&&u.push(`--_gpad:0px ${At(t).lanes>1?"calc(var(--basalt-space-5) + var(--basalt-space-3))":"var(--basalt-space-5)"} 0px 0px`),t.type==="schema"&&e.track&&u.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":i.title,"data-type":t.type,"data-cols":zt(t),"data-reach":t.type==="architecture"?re(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:u.join(";")},v("div",{class:`${s}-head`},v(m,{id:i.title,class:`${s}-title`},t.title),n.hasSource?v("p",{class:`${s}-source`},{slot:"source"}):null),v("div",{class:`${s}-drawing`,role:f?"group":void 0,"aria-roledescription":f?"diagram":void 0,"aria-labelledby":f?i.title:void 0,"aria-describedby":f?l?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":l?"":void 0},hn(o,t,e),t.text?null:v("div",{class:`${s}-ink`,"aria-hidden":"true"}),v("span",{class:`${s}-ruler`,"aria-hidden":"true"})),ce(s,t),v("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),bt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?v("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${oe(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${s}-foot`},{slot:"toggle"}),v("div",{id:i.list,class:`${s}-list`,hidden:!e.open},fe(s,t)),v("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${ue(t,a)} ${n.viewer}`:ue(t,a)),v("figcaption",{id:i.summary,class:`${s}-summary`},{slot:"summary"}))}function wn(t){const e=getComputedStyle(t),n=(i,r)=>{const o=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(o)?o:r},s=new Map;return{space:i=>(s.has(i)||s.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),s.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Bt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ht=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,he=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:i,r,b:o}=t.rect,a=(s+r)/2,l=(i+o)/2,f=(r-s)/2,m=(o-i)/2,u=e==="top"||e==="bottom";if(t.shape==="decision"){if(u){const x=n,d=m*Math.max(0,1-Math.abs(x-a)/f);return{x,y:e==="top"?l-d:l+d}}const c=n,g=f*Math.max(0,1-Math.abs(c-l)/m);return{x:e==="left"?a-g:a+g,y:c}}if(t.shape==="terminal"){const c=Math.min(f,m);if(u){const h=n,S=Math.min(Math.max(h,s+c),r-c),j=h-S,C=Math.abs(j)>=c?0:Math.sqrt(c*c-j*j);return{x:h,y:Math.abs(j)<1e-6?e==="top"?i:o:e==="top"?l-C:l+C}}const g=n,x=g-l,d=Math.abs(x)>=c?0:Math.sqrt(c*c-x*x);return{x:e==="left"?s+c-d:r-c+d,y:g}}return u?{x:n,y:e==="top"?i:o}:{x:e==="left"?s:r,y:n}}function vn(t,e,n){const{l:s,t:i,r,b:o}=e.rect,a=(s+r)/2,l=(i+o)/2,f=(r-s)/2,m=(o-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/f+Math.abs(t.y-l)/m<1-n/Math.min(f,m);if(e.shape==="terminal"){const u=Math.min(f,m),c=Math.min(Math.max(t.x,s+u),r-u);return Math.hypot(t.x-c,t.y-l)s+n&&t.xi+n&&t.ymatchMedia("(forced-colors: active)").matches;function Mn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(i,r)=>{const o=`${r}|${i}`;return s.has(o)||(n.setAttribute("data-f",r),n.textContent=i,s.set(o,n.getBoundingClientRect().width),n.textContent=""),s.get(o)}}var jt=t=>t?t.split(/\s+/).filter(Boolean):[];function Sn(t,e,n){const s=e.space;let i=e.node,r=e.table;for(const l of t.nodes){if(l.shape==="table"){for(const d of l.columns??[]){const h=d.ref?`${t.rtl?"←":"→"} ${d.ref.table}`:d.type??"",S=s("6")+n(d.name,"mono")+(h?s("3")+n(h,"mono"):0)+2*s("3")+2*e.hair;r=Math.max(r,Math.ceil(S))}r=Math.max(r,Math.ceil(n(l.name,"table")+2*s("3")+2*e.hair+(l.href?16+s("1-5"):0)));continue}const f=l.shape==="terminal"?2*s("5"):2*s("3"),m=l.mark&&!kn()?(l.shape==="participant"?2:1)*s("6"):0;let u=0;const c=l.href?16+s("1-5"):0,g=jt(l.name);if(g.forEach((d,h)=>{u=Math.max(u,n(d,l.shape==="decision"?"name-500":"name")+(l.kind?0:m)+(h===g.length-1?c:0))}),t.type!=="data-flow")for(const d of jt(l.kind))u=Math.max(u,n(d,"mono")+m);for(const d of jt(l.detail))u=Math.max(u,n(d,l.mono?"mono":"sans"));const x=l.shape==="decision"?u/.62:u+f+2*e.hair;i=Math.max(i,Math.ceil(x))}const o=zt(t);let a;return t.type==="data-flow"?a=e.lane+o*(i+s("12")):t.type==="schema"?a=o*r+(o-1)*s("12")+(Gt(t)?s("5")+(At(t).lanes>1?s("3"):0):0):t.type==="sequence"?a=o*i+(o-1)*s("5"):a=o*i+(o-1)*s("16")+re(t)*s("4"),{track:i,table:r,least:Math.max(e.wide,a)}}function ge(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Kt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function me(t,e,n){const s=t.map(r=>({...r}));for(let r=1;r=2){const l=i[i.length-2];if(Math.abs(l.x-a.x)<.01&&Math.abs(a.x-o.x)<.01||Math.abs(l.y-a.y)<.01&&Math.abs(a.y-o.y)<.01){i[i.length-1]=o;continue}}i.push(o)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Tt(t,e,n){const s=[];for(let r=0;rMath.min(d.x,h.x)+.75&&CMath.min(S.y,j.y)+.75&&Ei.split(/\s+/).map(parseFloat).filter(r=>Number.isFinite(r)),s=(i,r,o)=>{const a=[];let l=r;for(const f of i)a.push([l,l+f]),l+=f+o;return a};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var et=t=>t==="left"||t==="right",ye={top:"bottom",bottom:"top",left:"right",right:"left"};function be(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function $e(t,e,n){const s=[];t.edges.forEach((r,o)=>{const a=t.byId.get(r.from),l=t.byId.get(r.to),[f,m]=e[o],u=a.row===l.row&&et(f)&&et(m)&&f===ye[m]||a.col===l.col&&!et(f)&&!et(m)&&f===ye[m];s.push({edge:o,end:"from",node:a,side:f,far:l,straight:u,f:.5},{edge:o,end:"to",node:l,side:m,far:a,straight:u,f:.5})});const i=new Map;for(const r of s){const o=`${r.node.id}.${r.side}`;i.has(o)||i.set(o,[]),i.get(o).push(r)}for(const[r,o]of i){if(o[0].node.shape==="decision")continue;const a=d=>et(d.side)?d.far.row-d.node.row:d.far.col-d.node.col,l=o.filter(d=>d.straight),f=o.filter(d=>!d.straight);if(f.sort((d,h)=>a(d)-a(h)||(et(d.side)?d.far.col-h.far.col:d.far.row-h.far.row)*(a(d)<0?1:-1)),o.length>3&&n(`${r.replace(".","'s ")} side has ${o.length} lines; more than three is an error: use another side`),!l.length){f.length===2?(f[0].f=.25,f[1].f=.75):f.length===3?(f[0].f=.25,f[1].f=.5,f[2].f=.75):f.length>3&&f.forEach((d,h)=>{d.f=(h+1)/(f.length+1)});continue}const m=new Map;for(const d of l)m.has(d.far.id)||m.set(d.far.id,[]),m.get(d.far.id).push(d);for(const d of m.values())d.length>1&&d.sort((h,S)=>h.edge-S.edge).forEach((h,S)=>{h.f=d.length===2?S===0?.25:.75:(S+1)/(d.length+1)});const u=Math.min(...l.map(d=>d.f)),c=Math.max(...l.map(d=>d.f)),g=f.filter(d=>a(d)<0),x=f.filter(d=>a(d)>=0);g.forEach((d,h)=>{d.f=u*(h+1)/(g.length+1)}),x.forEach((d,h)=>{d.f=c+(1-c)*(h+1)/(x.length+1)})}return s}function we(t,e=8,n=8){return mt(t,`port-floors:${e}:${n}`,()=>{const s=ut();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return s;const i=t.edges.map(o=>{const a=t.byId.get(o.from),l=t.byId.get(o.to),[f,m]=be(a,l);return[o.fromSide??f,o.toSide??m]}),r=new Map;for(const o of $e(t,i,()=>{})){if(!et(o.side)||o.node.shape!=="box")continue;const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o.f)}for(const[o,a]of r){if(a.length<2)continue;const l=[...new Set(a.map(u=>Math.round(u*1e6)/1e6))].sort((u,c)=>u-c);let f=Math.max(e/l[0],e/(1-l[l.length-1]));for(let u=1;u{const o=t.byId.get(r.dataset.node);o&&i.set(o.id,{id:o.id,rect:ft(r,n),shape:o.shape,i:o.i})}),i}function ke(t,e){const n=e.head,s=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-s,r:i+s,t:r-n,b:r}:t.dir==="up"?{l:i-s,r:i+s,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-s,b:r+s}:{l:i,r:i+n,t:r-s,b:r+s}}var Me=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Se(t,e,n,s){const i=(r,o)=>{const a=r+o-Math.floor(r+o);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const r of i(t.t,n))for(const o of i(t.l,e)){if(!o&&!r)return t;const a={l:t.l+o,r:t.r+o,t:t.t+r,b:t.b+r};if(s(a))return a}return t}function An(t,e,n,s,i,r,o,a,l){const f=o.space,m=[],u=[],c=[],g=[],x=f("1"),d=e.filter(h=>t.edges[h.i]?.label).sort((h,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[h.i].kind==="main")||h.i-S.i);for(const h of d){const S=t.edges[h.i].label,j=a(S,"label"),C=16*Ft(S),E=h.pts.length-2,A=[];pt(h.pts).forEach(([L,z],I)=>{const M=Math.abs(L.y-z.y)<.01,O=M?L.x:L.y;let F=M?z.x:z.y;const G=Math.sign(F-O)||1;I===E&&(F-=G*o.head);let W=[[O,F]];for(const y of i)for(const b of M?[y.l,y.r]:[y.t,y.b]){const p=M?L.y:L.x;(M?p>y.t&&py.l&&pb>Math.min($,w)+1&&b{const p=(y+b)/2,k=M?{x:p,y:L.y}:{x:L.x,y:p};return!i.some($=>k.x>$.l&&k.x<$.r&&k.y>$.t&&k.y<$.b)},K=h.axes?.[I]??(M?L.y:L.x);for(const[y,b]of W)A.push({horiz:M,c:K,p:y,q:b,len:Math.abs(b-y),pri:W.length>1&&Q(y,b)?1:0})}),A.sort((L,z)=>z.pri-L.pri||z.len-L.len);let T=null,Z=!1;const B=(L,z=!0)=>{const I=he(L,x);return z&&(L.lr.r||L.tr.b)||n.some(M=>pe(I,M))||m.some(M=>ht(I,M))||s.heads.some(M=>ht(I,M))||s.rects.some(M=>ht(I,M))?!1:!e.some(M=>M.i!==h.i&&pt(M.pts).some(([O,F])=>ht(I,Me(O,F,M.width))))};for(const L of A){for(const z of[1/2,1/3,2/3]){const I=L.p+(L.q-L.p)*z,M=[],O=f("2")+h.width/2;if(L.horiz?(L.len>=j+2*f("1")+f("3-5")&&M.push({box:{l:I-j/2-f("1"),r:I+j/2+f("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),M.push({box:{l:I-j/2,r:I+j/2,t:L.c-O-C,b:L.c-O},on:!1}),M.push({box:{l:I-j/2,r:I+j/2,t:L.c+O,b:L.c+O+C},on:!1})):(L.len>=C+f("3")&&M.push({box:{l:L.c-j/2-f("1"),r:L.c+j/2+f("1"),t:I-C/2,b:I+C/2},on:!0}),M.push({box:{l:L.c+O,r:L.c+O+j,t:I-C/2,b:I+C/2},on:!1}),M.push({box:{l:L.c-O-j,r:L.c-O,t:I-C/2,b:I+C/2},on:!1})),T=M.find(F=>B(F.box))??null,T)break;!Z&&M.some(F=>B(F.box,!1))&&(Z=!0)}if(T)break}if(!T){c.push(h.i),Z&&g.push(h.i);continue}const ot=Se(T.box,l.ox,l.oy,L=>B(L));m.push(ot),u.push({i:h.i,text:S,box:ot,on:T.on})}return{labels:u,unseated:c,bounded:g}}function Ee(t,e,n,s){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(o=>{if(o.getClientRects().length===0||getComputedStyle(o).display==="contents")return;const a=ft(o,e);r.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const l=o.querySelector(`:scope > .${n}-glabel`);l&&l.getClientRects().length&&i.push(ft(l,e))}),t.querySelectorAll(`.${n}-lane`).forEach((o,a)=>{if(!o.getClientRects().length)return;const l=ft(o,e);a>0&&i.push({l:l.l,r:l.r,t:l.t-s/2-.5,b:l.t-s/2+.5});const f=o.querySelector(`.${n}-lane-name`);f&&i.push(ft(f,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function Ln(t,e){const{m:s,tk:i,P:r,drawing:o,origin:a,warn:l}=t,f=i.space,m=xe(s,o,a,r),u=[...m.values()],c=En(o),g=a.left-Math.floor(a.left),x=a.top-Math.floor(a.top),d=ge(g,x),h=o.clientWidth,S=o.clientHeight,j=p=>s.type==="data-flow"?p.col+1:p.col,C=parseFloat(getComputedStyle(o).rowGap)||0,E={w:h,h:S,nodes:u,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:g,oy:x};if(s.type==="sequence")return In(t,E,d);let A,T=[];s.type==="schema"?A=s.edges.map(p=>{const k=s.byId.get(p.from),$=s.byId.get(p.to);if(k.col===$.col){const w=k.col===s.cols&&s.cols>1?"left":"right";return[w,w]}return $.col>k.col?["right","left"]:["left","right"]}):(A=s.edges.map(p=>{const k=s.byId.get(p.from),$=s.byId.get(p.to),[w,_]=be(k,$);return[p.fromSide??w,p.toSide??_]}),T=$e(s,A,l||(()=>{})));const Z=(p,k)=>{const $=o.querySelector(`.${r}-node[data-node="${CSS.escape(p)}"] .${r}-row[data-row="${k}"]`);if(!$)return 0;const w=ft($,a);return(w.t+w.b)/2},B=s.edges.map((p,k)=>{const[$,w]=A[k],_=m.get(p.from),q=m.get(p.to),R=Bt(p.kind,i);if(p.fk){const V=Z(p.from,p.fromRow),P=Z(p.to,p.toRow),J=d.y(V,R),nt=d.y(P,R);return{p1:{x:$==="right"?_.rect.r:_.rect.l,y:J},p2:{x:w==="right"?q.rect.r:q.rect.l,y:nt},r1:V,r2:Math.abs(J-nt)<.01?V:P}}const U=T.find(V=>V.edge===k&&V.end==="from").f,Y=T.find(V=>V.edge===k&&V.end==="to").f;let N=ve(_,$,U),D=ve(q,w,Y);const tt=et($)?N.y:N.x;let st=et(w)?D.y:D.x;return et($)?N={...N,y:d.y(N.y,R)}:N={...N,x:d.x(N.x,R)},et(w)?D={...D,y:d.y(D.y,R)}:D={...D,x:d.x(D.x,R)},et($)&&et(w)&&Math.abs(N.y-D.y)<1.01&&(D={...D,y:N.y},st=tt),!et($)&&!et(w)&&Math.abs(N.x-D.x)<1.01&&(D={...D,x:N.x},st=tt),N=et($)?lt(_,$,N.y):lt(_,$,N.x),D=et(w)?lt(q,w,D.y):lt(q,w,D.x),{p1:N,p2:D,r1:tt,r2:st}}),ot=new Set;s.type==="schema"&&s.edges.forEach((p,k)=>{Math.abs(s.byId.get(p.from).col-s.byId.get(p.to).col)>1&&ot.add(k)});for(const p of At(s).dropped)ot.add(p),l?.(`${s.edges[p].from} to ${s.edges[p].to} would need a third lane of turn-backs, so its line is not drawn; its row still writes the target`);const L=new Map,z=new Set;s.edges.forEach((p,k)=>{if(ot.has(k))return;const[$,w]=A[k],{p1:_,p2:q}=B[k],R=s.byId.get(p.from),U=s.byId.get(p.to);let Y=null,N=null,D=!1;if($===w){if(et($)){const V=$==="right"?Math.max(j(R),j(U)):Math.min(j(R),j(U))-1,P=c.cols[V-1],J=c.cols[V];P&&J&&(Y=`c${V}`,N=[P[1],J[0]],D=!0)}else{const V=$==="bottom"?Math.max(R.row2,U.row2):Math.min(R.row,U.row)-1,P=c.rows[V-1],J=c.rows[V];P&&J&&(Y=`r${V}`,N=[P[1],J[0]],D=!1)}Y&&z.add(k)}else if(et($)&&et(w)&&Math.abs(_.y-q.y)>.5){const V=j(U),P=w==="left",J=c.cols[(P?V-1:V)-1],nt=c.cols[(P?V:V+1)-1];J&&nt&&(Y=`c${P?V-1:V}`,N=[J[1],nt[0]],D=!0)}else if(!et($)&&!et(w)&&Math.abs(_.x-q.x)>.5){const P=w==="top"?U.row-1:U.row2,J=c.rows[P-1],nt=c.rows[P];J&&nt&&(Y=`r${P}`,N=[J[1],nt[0]],D=!1)}if(!Y||!N)return;L.has(Y)||L.set(Y,{span:N,vertical:D,members:new Map});const tt=`${p.to}.${w}.${Math.round(D?q.y:q.x)}`,st=L.get(Y);st.members.has(tt)||st.members.set(tt,[]),st.members.get(tt).push(k)});const I=new Map,M=p=>{const[k,$]=A[p],{p1:w,p2:_}=B[p];if(et(k)&&et($)){if(k===$){const R=f("4")+(s.type==="schema"&&s.cols===1?(At(s).lane.get(p)??0)*f("3"):0),U=I.get(p)??(k==="right"?Math.max(w.x,_.x)+R:Math.min(w.x,_.x)-R);return[w,{x:U,y:w.y},{x:U,y:_.y},_]}if(Math.abs(w.y-_.y)<=.5)return[w,{x:_.x,y:w.y}];const q=I.get(p)??(w.x+_.x)/2;return[w,{x:q,y:w.y},{x:q,y:_.y},_]}if(!et(k)&&!et($)){if(k===$){const R=I.get(p)??(k==="bottom"?Math.max(w.y,_.y)+f("4"):Math.min(w.y,_.y)-f("4"));return[w,{x:w.x,y:R},{x:_.x,y:R},_]}if(Math.abs(w.x-_.x)<=.5)return[w,{x:w.x,y:_.y}];const q=I.get(p)??(w.y+_.y)/2;return[w,{x:w.x,y:q},{x:_.x,y:q},_]}return et(k)?[w,{x:_.x,y:w.y},_]:[w,{x:w.x,y:_.y},_]},O=p=>{const k=s.edges[p],$=Bt(k.kind,i),w=M(p),_=me(w,$,d);let q;return w.length===_.length&&(q=pt(w).map(([R,U])=>Math.abs(R.y-U.y)<.75?(R.y+U.y)/2:(R.x+U.x)/2),q[0]=B[p].r1,q.length>1&&(q[q.length-1]=B[p].r2)),{i:p,from:k.from,to:k.to,kind:k.kind,pts:_,tip:_[_.length-1],dir:Kt(_),dot:k.fk?_[0]:void 0,width:$,axes:q}},F=()=>s.edges.flatMap((p,k)=>ot.has(k)?[]:[O(k)]);let G=null;const W=p=>{G??(G=F());const k=G.map($=>p.has($.i)?O($.i):$);return{lines:k,score:qn(k,p)*1e5+Tt(k,void 0,p).length*1e3+Vt(k.filter($=>p.has($.i)),u,s).length}},Q=(p,k)=>{const $=p.flatMap(w=>{const{p1:_,p2:q}=B[w];return k?[_.y,q.y]:[_.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,p]of L){const k=[...p.members.values()].map(w=>({members:w,run:Q(w,p.vertical)})).sort((w,_)=>w.run[0]-_.run[0]),$=[];for(const w of k){const _=$[$.length-1];_&&_.some(q=>q.run[0]z.has(tt)))continue;const _=w.map(tt=>tt.members),q=_.length,R=(p.span[1]-p.span[0])/(q+1);RV.forEach(J=>I.set(J,p.span[0]+R*(P+1))));const st=W(U);st.scorett.forEach(V=>I.set(V,p.span[0]+R*(st+1)))),G=D}}E.lines=F();for(const p of ot)At(s).dropped.has(p)||l?.(`${s.edges[p].from} to ${s.edges[p].to} is two columns apart, so its line is not drawn; its row still writes the target`);E.crossings=Tt(E.lines),E.through=Vt(E.lines,u,s),E.outside=qe(E.lines,h,S,i);const{obstacles:K,groups:y}=Ee(o,a,r,C);K.heads=E.lines.map(p=>ke(p,i));const b=An(s,E.lines,u,K,y,{l:0,t:0,r:h,b:S},i,e,{ox:g,oy:x});return E.labels=b.labels,E.unseated=b.unseated,E.bounded=b.bounded,E.overlaps=[...new Set(Ae(E.lines,null).flat())],E}function qn(t,e){return Ae(t,e).length}function Ae(t,e){const n=[];for(let s=0;s=a)continue;const[h,S]=c?[l.x,f.x]:[l.y,f.y],[j,C]=c?[m.x,u.x]:[m.y,u.y];Math.min(Math.max(h,S),Math.max(j,C))-Math.max(Math.min(h,S),Math.min(j,C))>1&&n.push([r.i,o.i])}}return n}function*Le(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const l=a===r.pts.length-1?Math.max(r.width/2,s.head/2):r.width/2;return o.x-l<-.5||o.x+l>e+.5||o.y-l<-.5||o.y+l>n+.5})&&i.push(r.i);return i}function Vt(t,e,n){const s=[];for(const i of t){const r=pt(i.pts);e.some(o=>r.some(([a,l])=>xn(a,l,o)))&&s.push(i.i)}return s}function In(t,e,n){const{m:s,tk:i,P:r,drawing:o,origin:a}=t,l=i.space,f=new Map;o.querySelectorAll(`.${r}-node`).forEach(E=>f.set(E.dataset.node,ft(E,a)));const m=o.querySelector(`.${r}-steps`),u=m?ft(m,a).b:e.h,c=E=>{const A=f.get(E);return A?n.x((A.l+A.r)/2,i.hair):0};for(const E of s.nodes){const A=f.get(E.id);A&&e.lifelines.push({x:c(E.id),y1:A.b,y2:u})}const g=E=>f.get(E.id),x=new Map;o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=ft(E,a);x.set(Number(E.querySelector(`.${r}-num`)?.textContent??0),(A.t+A.b)/2)});const d=i.activation,h=d/2,S=E=>{const A=s.byId.get(E.who);if(!A)return null;const T=c(E.who),B=(A.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),ot=(E.depth-1)*l("1")*B,L=x.get(E.from)??0,z=x.get(E.to)??L,I=E.from===E.to;return{l:n.x(T-h+ot,i.hair),r:n.x(T+h+ot,i.hair),t:n.y(I?L-l("2")-l("1"):L,i.hair),b:n.y(I?L+l("2")+l("1"):z,i.hair)}},j=s.bars.map(E=>({bar:E,rect:S(E)})).filter(E=>E.rect);e.bars=j.map(E=>E.rect);const C=(E,A,T)=>j.filter(({bar:Z})=>Z.who===E&&Z.to>=A&&(T?Z.from<=A:Z.fromB.bar.depth-Z.bar.depth)[0]?.rect;return o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=E.dataset.from,T=E.dataset.to,Z=E.dataset.kind??"plain",B=Bt(Z,i),ot=ft(E,a),L=n.y((ot.t+ot.b)/2,B),z=Number(E.querySelector(`.${r}-num`)?.textContent??0);let I=c(A),M=c(T),O;if(A===T){const b=E.dataset.self==="start"?-l("6"):l("6"),p=C(A,z,!0),k=p?b>0?p.r:p.l:I,$=n.y(L-l("2"),B),w=n.y(L+l("2"),B);O=[{x:k,y:$},{x:n.x(I+b,B),y:$},{x:n.x(I+b,B),y:w},{x:k,y:w}]}else{const b=M>I?1:-1,p=C(A,z,!1),k=C(T,z,!0);p&&(I=b>0?p.r:p.l),k&&(M=b>0?k.l:k.r),O=[{x:I,y:L},{x:M,y:L}]}e.lines.push({i:z,from:A,to:T,kind:Z,pts:O,tip:O[O.length-1],dir:Kt(O),width:B});const F=E.querySelector(`.${r}-said`),G=E.querySelector(`.${r}-note`),W=s.byId.get(A),Q=s.byId.get(T);if(!W||!Q)return;const K=A===T?(()=>{const b=s.nodes[W.i+(E.dataset.self==="start"?-1:1)],p=b?c(b.id):E.dataset.self==="start"?0:e.w;return Math.abs(p-I)-l("6")-l("2-5")-l("2")})():Math.abs(M-I)-2*l("2");Math.max(F?F.getBoundingClientRect().width:0,G?G.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(z)}),o.querySelectorAll(`.${r}-fhead`).forEach(E=>{const A=E.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!A)return;[...E.children].reduce((Z,B)=>Z+B.getBoundingClientRect().width,0)+l("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${E.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function Ie(t,e,n,s=ut()){const{m:i,tk:r,P:o,drawing:a,origin:l}=t,f=r.space,m=xe(i,a,l,o),u=[...m.values()],c=l.left-Math.floor(l.left),g=l.top-Math.floor(l.top),x=ge(c,g),d=a.clientWidth,h=a.clientHeight,S={w:d,h,nodes:u,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:g},j=ut();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:j};const C=d-(parseFloat(getComputedStyle(a).paddingRight)||0),E=(M,O,F)=>{const G=[M];for(let W=1;W<=(gt(s,O)??0);W++)G.push({...M,t:M.t+F*f("4")*W,b:M.b+F*f("4")*W});return G},A=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>{const O=M.parentElement,F=ft(O,l),G=getComputedStyle(O);A.set(M.dataset.node,F.r-(parseFloat(G.paddingRight)||0)-(parseFloat(G.borderRightWidth)||0))});const T=i.nodes,Z=M=>m.get(T[M].id),B=[],ot=M=>Bt(i.edges[M].kind,r);i.edges.forEach((M,O)=>{const F=n.routes[O],G=m.get(M.from),W=m.get(M.to),Q=ot(O);let K=[];const y=M.label,b=y?e(y,"label"):0,p=y?16*Ft(y):16,k=f("4");if(F==="down"||F==="up"){const w=Math.max(G.rect.l,W.rect.l),_=Math.min(G.rect.r,W.rect.r),q=i.edges.map((N,D)=>({o:N,j:D})).filter(({o:N,j:D})=>(n.routes[D]==="down"||n.routes[D]==="up")&&(N.from===M.from&&N.to===M.to||N.from===M.to&&N.to===M.from)),R=q.findIndex(N=>N.j===O),U=q.length<2?.5:q.length===2?R===0?.25:.75:(R+1)/(q.length+1),Y=x.x(w+(_-w)*U,Q);if(K=F==="down"?[lt(G,"bottom",Y),lt(W,"top",Y)]:[lt(G,"top",Y),lt(W,"bottom",Y)],y){let N=Math.min(K[0].y,K[1].y),D=Math.max(K[0].y,K[1].y);F==="down"?D-=r.head:N+=r.head;const tt=[...a.querySelectorAll(`.${o}-group`)].map(J=>ft(J,l));let st=[[N,D]];for(const J of tt)for(const nt of[J.t,J.b])st=st.flatMap(([rt,ct])=>nt>rt+1&&nttt.some(rt=>(J+nt)/2>rt.t&&(J+nt)/2rt.l&&Y1){const J=st.filter(([rt,ct])=>!V(rt,ct));[N,D]=(J.length?J:st).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const P=[1/2,1/3,2/3].map(J=>{const nt=N+(D-N)*J;return{l:Y-b/2-f("1"),r:Y+b/2+f("1"),t:nt-p/2,b:nt+p/2}});B.push({k:O,cands:P,on:!0,card:F==="down"?M.to:M.from})}}else if(F==="trunk"||F==="rail"){const w=x.x(Math.max(G.rect.l,F==="rail"?W.rect.l:G.rect.l)+f(F==="trunk"?"8":"3"),Q),_=lt(G,"bottom",w);if(F==="rail"){if(K=[_,lt(W,"top",w)],y){const q=W.rect.t-f("6");B.push({k:O,cands:E({l:w+f("2-5"),r:w+f("2-5")+b,t:q-p/2,b:q+p/2},M.to,-1),on:!1,card:M.to})}}else{const q=x.x(W.rect.l+f("6"),Q),R=x.y(W.rect.t-k,Q);K=[_,{x:w,y:R},{x:q,y:R},lt(W,"top",q)],y&&B.push({k:O,cands:E({l:q+f("2-5"),r:q+f("2-5")+b,t:R-p/2,b:R+p/2},M.to,-1),on:!1,card:M.to})}}else{const w=Math.min(A.get(M.from)??d,A.get(M.to)??d),_=x.x(n.gutter?C+(n.lanes[O]?2*f("3-5"):f("3-5")):w-f("2-5"),Q),q=x.y(G.rect.t+(G.rect.b-G.rect.t)*n.exits[O],Q),R=lt(G,"right",q),U=x.x(W.rect.r-f("6"),Q),Y=F==="end-down",N=x.y(Y?W.rect.t-k:W.rect.b+k,Q);K=[R,{x:_,y:R.y},{x:_,y:N},{x:U,y:N},lt(W,Y?"top":"bottom",U)];const D=Y?M.to:T[W.i+1]?.id??M.to;y&&B.push({k:O,cands:E({l:U-f("2-5")-b,r:U-f("2-5"),t:N-p/2,b:N+p/2},D,Y?-1:1),on:!1,card:D})}const $=me(K,Q,x);S.lines.push({i:O,from:M.from,to:M.to,kind:M.kind,pts:$,tip:$[$.length-1],dir:Kt($),width:Q})}),S.crossings=Tt(S.lines),S.through=Vt(S.lines,u,i),S.outside=qe(S.lines,d,h,r);const{obstacles:L}=Ee(a,l,o,0);L.heads=S.lines.map(M=>ke(M,r));const z=[],I={l:0,t:0,r:d,b:h};for(const M of B){const O=W=>{const Q=he(W,f("1"));return W.lI.r+.5||W.tI.b+.5||u.some(K=>pe(Q,K))||z.some(K=>ht(Q,K))||L.heads.some(K=>ht(Q,K))||L.rects.some(K=>ht(Q,K))||S.lines.some(K=>K.i!==M.k&&pt(K.pts).some(([y,b])=>ht(Q,Me(y,b,K.width))))},F=M.cands.find(W=>!O(W));F||(j[M.card]=(j[M.card]??0)+1,S.unseated.push(M.k));const G=F?Se(F,c,g,W=>!O(W)):M.cands[0];z.push(G),S.labels.push({i:M.k,text:i.edges[M.k].label,box:G,on:M.on})}return{geo:S,grow:j}}function On(t,e){const n=r=>String(Math.round(r*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let r=1;r({...E})),u=m[m.length-1];u.x-=r.x*f,u.y-=r.y*f;const c=e.tip.x-r.x*a,g=e.tip.y-r.y*a,x=-r.y*l,d=r.x*l,h=E=>Math.round(E*100)/100,S=it(e.kind),j=o?``:``,C=e.dot?``:"";return`${j}${C}`}function Oe(t,e,n,s){const i=new Map,r=new Map;for(const a of e.crossings)r.has(a.under)||r.set(a.under,[]),r.get(a.under).push(a);let o="";for(const[a,l]of r){const f=`${s}-cut-${a}`;i.set(a,f);const m=l.map(u=>{const c=e.lines[u.top],g=e.lines[u.under],x=c.width/2+n.cut,d=g.width/2+1;return u.underVertical?``:``}).join("");o+=`${m}`}return{defs:o,ids:i}}function _e(t,e,n,s){const{defs:i,ids:r}=Oe(t,e,n,s),o=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),a=e.lines.map((m,u)=>Cn(t,m,n,r.get(u)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),l=`${i?`${i}`:""}${o}${a}`,f=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` +`).map(it).join("
")}
`).join("");return l+f}function Zt(t,e,n,s,i,r,o,a){const f=t.querySelector(`.${n}-drawing`);if(!f||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const m=wn(t),u=Mn(f,n),c=Sn(e,m,u);a?.(c.least);const g=t.clientWidth,x=(()=>{const L=document.activeElement;return L&&f.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),d=L=>bt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:x&&L.layout!=="drawn"?x:void 0};let h=!1;const S=L=>{if(h=!1,e.type!=="flowchart")return L;r({...L,heights:void 0,words:void 0});const z=ut(),I=ut();return f.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const O=M.querySelector(`.${n}-words`);if(!O)return;const F=M.getBoundingClientRect(),G=K=>{const y={w:K.width+2*m.space("2-5"),h:K.height+2*m.space("2")},b=1-y.w/F.width,p=b>.05?y.h/2/b:y.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*p))},W=O.getBoundingClientRect();let Q=G(W);if(Q>F.width){const K=k=>(M.style.setProperty("--_ww",`${k}px`),O.getBoundingClientRect()),y=Math.floor(M.clientWidth-2*m.space("2-5"));let b=Math.ceil(W.width),p=W.height;for(;b1;){const q=k+$>>1;K(q).heightF.width&&(h=!0)}),{...L,heights:z,words:Object.keys(I).length?I:void 0}},j=()=>({m:e,tk:m,P:n,drawing:f,origin:f.getBoundingClientRect(),warn:o}),C=i.autoOpen?{open:!1,autoOpen:void 0}:{},E=(L,z)=>z.map(I=>Lt(e,L.lines.find(M=>M.i===I))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:m,least:c.least};if(g>=c.least&&!e.unplaced){const L=O=>{let F=d({...i,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return F=S(F),r(F),{dd:F,g:Ln(j(),u)}};let{dd:z,g:I}=L(!1);const M=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||h;if(!M(I)&&I.unseated.length&&I.unseated.every(O=>I.bounded?.includes(O))){const O=L(!0);!M(O.g)&&!O.g.unseated.length&&({dd:z,g:I}=O)}if(!M(I)&&!I.unseated.length)return I.crossings.length&&o?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(O=>`${Lt(e,I.lines[O.top])} over ${Lt(e,I.lines[O.under])}`).join("; ")}`),{dyn:z,geo:I,ink:_e(n,I,m,s),tokens:m,least:c.least};h&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: a decision would be taller than it is wide`),I.misfit?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${I.misfit.join("; ")}`),I.through.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.through)} would pass through a node`),I.overlaps?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.overlaps)} would lie on one another`),I.outside.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.outside)} would leave the drawing`),I.unseated.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: no clean seat for ${I.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=d({...i,...C,layout:"stacked",heights:void 0,grow:ut(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(A=S(A),r(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:m,least:c.least};const T=ie(e);let Z=Ie(j(),u,T,A.grow);for(let L=0;L<6&&Object.keys(Z.grow).length;L++){const z=ut(A.grow);for(const[I,M]of Object.entries(Z.grow))z[I]=(gt(z,I)??0)+M;A={...A,grow:z},r(A),Z=Ie(j(),u,T,z)}const B=Z.geo;if(B.unseated.length>0||B.through.length>0||B.outside.length>0||T.third){B.unseated.length&&o?.(`the stacked drawing has no clean seat for ${[...new Set(B.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),B.through.length&&o?.(`in the stacked drawing ${E(B,B.through)} would pass through a node, so its lines are not drawn`),B.outside.length&&o?.(`in the stacked drawing ${E(B,B.outside)} would leave the drawing, so its lines are not drawn`),T.third&&o?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={...B,lines:[],labels:[],crossings:[]};return{dyn:d({...A,grow:ut(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:m,least:c.least}}return B.crossings.length&&o?.(`${B.crossings.length} crossing${B.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${B.crossings.map(L=>`${Lt(e,B.lines[L.top])} over ${Lt(e,B.lines[L.under])}`).join("; ")}`),{dyn:A,geo:B,ink:_e(n,B,m,s),tokens:m,least:c.least}}function Lt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Bn(t,e,n,s,i,r){const o=new Set;if(r){o.add(r);for(const d of n?.lines??[])d.from===r&&o.add(d.to),d.to===r&&o.add(d.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(d=>d.toggleAttribute("data-near",o.has(d.dataset.node))),!n||!s)return;const a=d=>!!r&&(d.from===r||d.to===r),l=t.querySelector(`.${e}-edges`),f=new Map;t.querySelectorAll(`.${e}-edge`).forEach(d=>f.set(d.getAttribute("data-edge"),d));for(const d of n.lines){const h=f.get(String(d.i));h&&(h.toggleAttribute("data-lit",a(d)),h.toggleAttribute("data-dim",!!r&&!a(d)))}if(t.querySelectorAll(`.${e}-label`).forEach(d=>{const h=n.lines.find(S=>String(S.i)===d.dataset.edge);d.toggleAttribute("data-lit",!!(h&&a(h)))}),l){for(const d of n.lines)if(a(d)){const h=f.get(String(d.i));h&&l.appendChild(h)}}const m=Tt(n.lines,a),{defs:u,ids:c}=Oe(e,{...n,crossings:m},s,i),g=t.querySelector(`.${e}-svg`);if(!g)return;let x=g.querySelector("defs");!x&&u&&(x=document.createElementNS("http://www.w3.org/2000/svg","defs"),g.insertBefore(x,g.firstChild)),x&&(x.innerHTML=u),n.lines.forEach((d,h)=>{const S=f.get(String(d.i))?.querySelector(`.${e}-line`);if(!S)return;const j=c.get(h);j?S.setAttribute("mask",`url(#${j})`):S.removeAttribute("mask")})}var jn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Tn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",jn()||Wn(t)?"done":"pending")}}var Rn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Wn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Rn(t))!==null}catch{return!1}}function Ce(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Fn(t,e,n,s=!1,i=!1){const r=s?_t(t):null;if(r&&n.startsWith("Arrow")){const f={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return f?r[e]?.[f]??null:null}const o=t.byId.get(e)?.i??0,a=t.nodes.length;let l;if(n==="ArrowRight"||n==="ArrowDown")l=o+1;else if(n==="ArrowLeft"||n==="ArrowUp")l=o-1;else if(n==="Home")l=0;else if(n==="End")l=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,l))].id}var Nn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Be=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],zn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],je=t=>t==null||t===!1;function Hn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Rt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?Be:Nn;for(const o of s)je(e.a[o])&&t.removeAttribute(o);for(const[o,a]of Object.entries(e.a)){if(o==="class")continue;if(o==="style"){const f=t.style,m=new Map(String(a??"").split(";").map(u=>{const c=u.indexOf(":");return[u.slice(0,c).trim(),u.slice(c+1).trim()]}).filter(([u])=>u));for(const[u,c]of m)f.getPropertyValue(u).trim()!==c&&f.setProperty(u,c);for(const u of zn)m.has(u)||f.removeProperty(u);continue}if(n&&!Be.includes(o))continue;if(je(a)){t.removeAttribute(o);continue}const l=a===!0?"":String(a);t.getAttribute(o)!==l&&t.setAttribute(o,l)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(o=>typeof o!="string"&&"slot"in o))return;const i=[...t.children];let r=0;for(const o of e.c)if(!(typeof o=="string"||"slot"in o)){for(let a=r;at.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function i(c,g,x){return{prefix:n,base:c,hasSource:g.source!==void 0&&g.source!==null&&g.source!=="",hiddenClass:"visually-hidden",viewer:x?x.keys:void 0}}function r(c,g,x,d){var h=function(S){return''+it(S)+""};return{source:it(String(g.source||"")),summary:it(String(g.summary||"")),hint:Dt(c).map(function(S){return""+S.keys.map(h).join(" ")+" "+it(S.words)+""}).join(""),toggle:'"}}function o(c,g,x){var d=wt(c),h=Ct(d,{},i(g,c,x)),S=Nt(h,r(d,c,g,!1)),j=S.indexOf(">");return{open:S.slice(0,j+1),inner:S.slice(j+1,S.length-9),warnings:d.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],l=["--_cols","--_gpad","--_track"];function f(c,g,x,d){c.__diagram&&c.__diagram.stop();var h=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(c).direction==="rtl",j=g.layout==="auto"&&(g.type==="architecture"||g.type==="flowchart"||g.type==="schema"),C=j?Array.isArray(g.placement)?g.placement:g.placement?[g.placement]:[]:[];j&&!C.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var E=g.direction?[g.direction]:g.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var X=0;X .diagram-drawing")){if(!h||!c.querySelector("#"+CSS.escape(h+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););h="dg"+s}var Z=o(g,h,d),B=document.createElement("div");B.innerHTML=Z.open+"";var ot=B.firstChild;a.forEach(function(H){c.removeAttribute(H)}),l.forEach(function(H){c.style.removeProperty(H)});for(var L=0;L :not(script[data-diagram])").forEach(function(H){H.remove()}),c.insertAdjacentHTML("beforeend",Z.inner)}T.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var I=i(h,g,d),M={},O=null,F=null,G=null,W=null,Q=Object.create(null),K=function(H){Q[H]||(Q[H]=1,console.warn("Basalt diagram: "+H))},y=function(H){Rt(c,Ct(T,H,I))},b=c.querySelector(".diagram-ink"),p=c.querySelector(".diagram-toggle"),k=!d&&T.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,_=function(){k&&Ce(c)};function q(){Bn(c,n,O&&O.geo,O&&O.tokens,h,F||W||G),Y()}var R=null,U=!d&&matchMedia("(hover: none), (pointer: coarse)").matches;function Y(){var H=U&&!d&&b&&b.innerHTML!=="";if(c.toggleAttribute("data-touch",!!(U&&!d)),H&&!R){var X=c.querySelector(":scope > .diagram-foot");if(!X)return;R=document.createElement("button"),R.type="button",R.className="btn diagram-clear",R.setAttribute("data-variant","secondary"),R.setAttribute("data-size","sm"),R.innerHTML="Clear highlight",R.addEventListener("click",function(){W&&(W=null,q())}),X.appendChild(R)}else!H&&R&&(R.remove(),R=null);R&&(W?R.removeAttribute("aria-disabled"):R.setAttribute("aria-disabled","true"))}function N(H){if(!H.defaultPrevented){var X=en(c,n,H,W);X!==void 0&&(_(),U=!0,W=X,q())}}function D(){p&&(p.setAttribute("aria-expanded",String(!!M.open)),p.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function tt(){if(j&&C.length>1&&!d){for(var H=null,X=0;X1&&d&&!g.direction&&d.room){for(var He=d.room(),De=-1,Jt=null,Xt=0;XtDe+1e-6&&(De=Ke,Jt=Yt)}}}Jt&&(T=Jt)}O=(d?d.measure:Zt)(c,T,n,h,M,y,K),M=O.dyn,y(M),D();var Qt=c.querySelector(":scope > .diagram-hint");if(Qt){var Ve=Dt(T,M.layout==="drawn").map(function(St){return""+St.keys.map(function(Zn){return''+it(Zn)+""}).join(" ")+" "+it(St.words)+""}).join("");Qt.innerHTML!==Ve&&(Qt.innerHTML=Ve)}bt(T,M)||(G=W=null);var Ze=b&&O.ink!==w;Ze&&(b.innerHTML=O.ink,w=O.ink),q(),k&&O.tokens&&(Tn(c,!!(O.geo&&O.geo.lines.length)),Ze&&$&&$.redrawn()),d&&d.onMeasured&&O.tokens&&d.onMeasured(O,c),T.text&&typeof e.diagramText=="function"&&e.diagramText(c,T,g)}function st(H){M=H,y(M)}function V(H){var X=M.stop;M=Object.assign({},M,{stop:H}),Dn(c,n,X,H)}var P=function(H){var X=H&&H.closest?H.closest(".diagram-node"):null;return X&&c.contains(X)?X:null};function J(H){var X=P(H.target);if(!(!X||H.defaultPrevented)){if(_(),H.key==="Escape"){!d&&(F||G||W)&&(H.preventDefault(),F=G=W=null,q());return}if(bt(T,M)){var dt=Fn(T,X.getAttribute("data-node"),H.key,M.layout==="drawn");if(dt){H.preventDefault(),V(dt);var Mt=c.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');Mt&&Mt.focus()}}}}function nt(H){var X=P(H.target);if(X){_();var dt=X.getAttribute("data-node");F=X.matches(":focus-visible")?dt:null,bt(T,M)&&M.stop!==dt&&V(dt),q()}}function rt(H){var X=P(H.target);X&&(P(H.relatedTarget)||(F=null),M.keep===X.getAttribute("data-node")&&st(Object.assign({},M,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var X=P(H.target);X&&_();var dt=X&&bt(T,M)?X.getAttribute("data-node"):null;dt!==G&&(G=dt,q())}}function qt(){G&&(G=null,q())}function $t(){_(),st(Object.assign({},M,{open:!M.open,autoOpen:void 0})),D()}c.addEventListener("keydown",J),c.addEventListener("focusin",nt),c.addEventListener("focusout",rt),c.addEventListener("pointerover",ct),c.addEventListener("pointerleave",qt),c.addEventListener("click",N),p&&p.addEventListener("click",$t),tt();var kt=c.clientWidth,Ut=0,Te=!0,Re=new ResizeObserver(function(){Math.abs(c.clientWidth-kt)<.5||(kt=c.clientWidth,cancelAnimationFrame(Ut),Ut=requestAnimationFrame(tt))});Re.observe(c),document.fonts&&document.fonts.ready.then(function(){Te&&tt()});var We=matchMedia("(forced-colors: active)"),Fe=T.nodes.some(function(H){return H.mark});Fe&&We.addEventListener("change",tt),k&&($=e.diagramMotion(c,{fig:c,P:n,base:h,model:function(){return T},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},g));var Ne=!d&&g.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,g,{model:T,settle:_,animated:k}):null,ze=c.querySelector(":scope > .diagram-foot"),Gn=!d&&g.export===!0&&ze&&typeof e.diagramExport=="function"?e.diagramExport(ze,c):[];c.__diagram={stop:function(){Ne&&Ne.destroy(),Gn.forEach(function(H){H.remove()}),Te=!1,Re.disconnect(),cancelAnimationFrame(Ut),Fe&&We.removeEventListener("change",tt),$&&$.destroy(),c.removeEventListener("keydown",J),c.removeEventListener("focusin",nt),c.removeEventListener("focusout",rt),c.removeEventListener("pointerover",ct),c.removeEventListener("pointerleave",qt),c.removeEventListener("click",N),R&&R.remove(),p&&p.removeEventListener("click",$t)},layout:tt,key:m(g),send:$&&$.sendValue?$.sendValue:null}}function m(c){try{return JSON.stringify(c,function(g,x){return g==="packet"&&x&&typeof x=="object"?Object.assign({},x,{send:void 0}):x})}catch{return null}}function u(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var g=c.querySelector(":scope > script[data-diagram]");if(g)try{f(c,JSON.parse(g.textContent),!0)}catch(x){console.error("Basalt diagram: this figure could not be drawn",x)}}})}e.diagramMarkup=o,e.diagramKit={draw:f,buildModel:wt,figureKey:ln,figureList:mn,hintEntries:Dt,toHtml:Nt,escapeHtml:it,settleEntrance:Ce,measureFigure:Zt},t.diagram=function(c,g){var x=c.__diagram,d=x&&x.send?m(g):null;if(d!==null&&d===x.key){x.send(g.packet?g.packet.send:void 0);return}f(c,g)},e.step(62,"wireDiagrams",u)})(window.Basalt)})(); diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 2eec1e4e..a7c88325 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -537,6 +537,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, ...nodes.map((n) => n.row2)); const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined, text: (type === "sequence" && spec.variant === "text") || undefined }; if (spec.layout === "auto" && !unplaced && type !== "schema") chooseSides(model); + if (checks) for (const [id, h0] of Object.entries(portFloors(model))) if (h0 >= 48) warn(`${id} grows to ${h0}px to hold the lines on one side: use another side`); if (checks && nodes.length > 1 && !spatialTable(model)) warn("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"); return model; } @@ -1017,6 +1018,9 @@ function nodeTree(ctx: TreeContext, m: Model, n: MNode, dyn: Dyn): VElement { } const height = own(dyn.heights, n.id); if (height) style.push(`--_h:${height}px`); + // The least height its ports need (call 3); the stylesheet applies it to the drawn layout alone. + const floor = own(portFloors(m), n.id); + if (floor) style.push(`--_mh:${floor}px`); const wordsWidth = own(dyn.words, n.id); if (wordsWidth) style.push(`--_ww:${wordsWidth}px`); const tabbable = stops ? (dyn.stop === n.id ? 0 : -1) : dyn.keep === n.id ? -1 : undefined; @@ -1311,6 +1315,42 @@ export interface FigureOptions { } /** The whole figure. Before script runs `dyn` is empty; the same tree, with the measured `dyn`, is what script settles on. */ +/** + * A one-column schema's turn-backs (DECISIONS 306, section 4, call 2): turn-backs that run beside each other take lanes space-3 apart, nested (the + * farther-going outermost), lines to one key sharing one; two lanes at most in the padding, and a third line is not drawn. Worked out from the data alone + * (a line's place down the column is its table's row and its key's row), so the padding is known before anything is measured. + */ +export function turnBackLanes(m: Model): { lane: Map; dropped: Set; lanes: number } { + return memo(m, "turn-back-lanes", () => { + const lane = new Map(), dropped = new Set(); + if (!oneColumnTurnBacks(m)) return { lane, dropped, lanes: 0 }; + const at = (id: string, row: number) => (m.byId.get(id)?.row ?? 0) * 1000 + row; + // One group a key; its run from its highest to its lowest end. + const groups = new Map(); + m.edges.forEach((e, k) => { + const key = `${e.to}.${e.toRow}`; + const a = at(e.from, e.fromRow ?? 0), b = at(e.to, e.toRow ?? 0); + const g = groups.get(key) ?? { members: [], lo: Infinity, hi: -Infinity }; + g.members.push(k); g.lo = Math.min(g.lo, a, b); g.hi = Math.max(g.hi, a, b); + groups.set(key, g); + }); + // Longest first, so the farther-going is outermost; each takes the innermost lane no group beside it holds. + const order = [...groups.values()].sort((x, y) => (y.hi - y.lo) - (x.hi - x.lo)); + const placed: Array<{ lo: number; hi: number; lane: number }> = []; + let most = 0; + for (const g of order.reverse()) { + const used = new Set(placed.filter((p) => p.lo <= g.hi && g.lo <= p.hi).map((p) => p.lane)); + let l = 0; + while (used.has(l)) l++; + if (l > 1) { for (const k of g.members) dropped.add(k); continue; } + placed.push({ lo: g.lo, hi: g.hi, lane: l }); + for (const k of g.members) lane.set(k, l); + most = Math.max(most, l + 1); + } + return { lane, dropped, lanes: most }; + }); +} + /** A schema of one column whose foreign keys are drawn as turn-backs on its end side, where it has no gutter. */ const oneColumnTurnBacks = (m: Model) => m.type === "schema" && m.cols === 1 && m.edges.length > 0; @@ -1335,7 +1375,8 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { } // A schema of one column with a foreign key: its turn-backs run space-4 out on the end side, past the cards, so the drawn layout keeps space-5 there // (the turn-back and its stroke on the pixel grid); the fit rule counts it (minimums). - if (oneColumnTurnBacks(m)) style.push("--_gpad:0px var(--basalt-space-5) 0px 0px"); + // Two lanes of turn-backs take space-3 more (call 2). + if (oneColumnTurnBacks(m)) style.push(`--_gpad:0px ${turnBackLanes(m).lanes > 1 ? "calc(var(--basalt-space-5) + var(--basalt-space-3))" : "var(--basalt-space-5)"} 0px 0px`); if (m.type === "schema" && dyn.track) style.push(`--_track:${dyn.track}px`); return h("figure", { class: o.className ? `${P} ${o.className}` : P, @@ -1570,7 +1611,7 @@ function minimums(m: Model, tk: Tokens, measure: ReturnType) { const n = columnCount(m); let least: number; if (m.type === "data-flow") least = tk.lane + n * (track + s("12")); - else if (m.type === "schema") least = n * table + (n - 1) * s("12") + (oneColumnTurnBacks(m) ? s("5") : 0); + else if (m.type === "schema") least = n * table + (n - 1) * s("12") + (oneColumnTurnBacks(m) ? s("5") + (turnBackLanes(m).lanes > 1 ? s("3") : 0) : 0); // A sequence's columns hold its participants: measured once script runs (the stylesheet before script has only the token floor). else if (m.type === "sequence") least = n * track + (n - 1) * s("5"); else least = n * track + (n - 1) * s("16") + groupReach(m) * s("4"); @@ -1704,6 +1745,36 @@ function assignSlots(m: Model, sides: Array<[DiagramSide, DiagramSide]>, warn: ( return ports; } +/** + * A card's least height for its ports (DECISIONS 306, section 4, call 3): a port sits on the flat part of its side, never nearer a corner than the corner's + * radius, and two ports on a side are at least size-diagram-head apart. A card whose start or end side holds more than its height allows grows to the least + * height at which both hold (48 for a straight line and two others, 64 for an extra beside a straight pair), and its row takes it. From the data alone, so + * it is the same at every width: a side never stacks a figure. By node id; only cards that need more than nothing are named. + */ +export function portFloors(m: Model, radius = 8, head = 8): Record { + return memo(m, `port-floors:${radius}:${head}`, () => { + const out: Record = record(); + if (m.type !== "architecture" && m.type !== "flowchart" && m.type !== "data-flow") return out; + const sides = m.edges.map((e) => { const a = m.byId.get(e.from)!, b = m.byId.get(e.to)!; const [d1, d2] = defaultSides(a, b); return [e.fromSide ?? d1, e.toSide ?? d2] as [DiagramSide, DiagramSide]; }); + const bySide = new Map(); + for (const p of assignSlots(m, sides, () => {})) { + if (!isH(p.side) || p.node.shape !== "box") continue; + const key = `${p.node.id}.${p.side}`; + if (!bySide.has(key)) bySide.set(key, []); + bySide.get(key)!.push(p.f); + } + for (const [key, fs] of bySide) { + if (fs.length < 2) continue; + const f = [...new Set(fs.map((x) => Math.round(x * 1e6) / 1e6))].sort((a, b) => a - b); + let need = Math.max(radius / f[0]!, radius / (1 - f[f.length - 1]!)); + for (let j = 1; j < f.length; j++) need = Math.max(need, head / (f[j]! - f[j - 1]!)); + const id = key.slice(0, key.lastIndexOf(".")); + out[id] = Math.max(out[id] ?? 0, Math.ceil(need - 1e-6)); + } + return out; + }); +} + /** The derived ports of a drawn layout (1.6), for the derivation table: each line's sides and its slot on each (a fraction along the side). */ export function derivedPorts(m: Model): Array<{ from: string; to: string; fromSide: DiagramSide; toSide: DiagramSide; fromSlot: number; toSlot: number }> { const sides = m.edges.map((e) => { const a = m.byId.get(e.from)!, b = m.byId.get(e.to)!; const [d1, d2] = defaultSides(a, b); return [e.fromSide ?? d1, e.toSide ?? d2] as [DiagramSide, DiagramSide]; }); @@ -1913,6 +1984,8 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge // Relations two columns apart are not drawn: the row writes its target (1.12). They are left out before any lane is given, so they take none. const dropped = new Set(); if (m.type === "schema") m.edges.forEach((e, k) => { if (Math.abs(m.byId.get(e.from)!.col - m.byId.get(e.to)!.col) > 1) dropped.add(k); }); + // A one-column schema's third lane of turn-backs is not drawn; its row still writes the target (call 2). + for (const k of turnBackLanes(m).dropped) { dropped.add(k); if (dev) warn?.(`${m.edges[k]!.from} to ${m.edges[k]!.to} would need a third lane of turn-backs, so its line is not drawn; its row still writes the target`); } // Jogs: which gutter each two-elbow line turns in, and which lines share a lane (lines to one port, a foreign key's bus). A turn-back (out and // back in on one side) runs in the gutter beside that side too, so it is given a lane with the jogs it runs beside. @@ -1960,7 +2033,12 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge const [s1, s2] = sides[k]!; const { p1, p2 } = ends[k]!; if (isH(s1) && isH(s2)) { - if (s1 === s2) { const x = lanes.get(k) ?? (s1 === "right" ? Math.max(p1.x, p2.x) + s("4") : Math.min(p1.x, p2.x) - s("4")); return [p1, { x, y: p1.y }, { x, y: p2.y }, p2]; } + if (s1 === s2) { + // A one-column schema's turn-back takes its lane: space-4 out, the second space-3 further (call 2). + const out = s("4") + (m.type === "schema" && m.cols === 1 ? (turnBackLanes(m).lane.get(k) ?? 0) * s("3") : 0); + const x = lanes.get(k) ?? (s1 === "right" ? Math.max(p1.x, p2.x) + out : Math.min(p1.x, p2.x) - out); + return [p1, { x, y: p1.y }, { x, y: p2.y }, p2]; + } if (Math.abs(p1.y - p2.y) <= 0.5) return [p1, { x: p2.x, y: p1.y }]; const x = lanes.get(k) ?? (p1.x + p2.x) / 2; return [p1, { x, y: p1.y }, { x, y: p2.y }, p2]; @@ -2031,7 +2109,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge } } geo.lines = build(); - if (dev) for (const k of dropped) warn?.(`${m.edges[k]!.from} to ${m.edges[k]!.to} is two columns apart, so its line is not drawn; its row still writes the target`); + if (dev) for (const k of dropped) if (!turnBackLanes(m).dropped.has(k)) warn?.(`${m.edges[k]!.from} to ${m.edges[k]!.to} is two columns apart, so its line is not drawn; its row still writes the target`); geo.crossings = findCrossings(geo.lines); geo.through = throughOf(geo.lines, nodes, m); geo.outside = outsideOf(geo.lines, W, H, tk); diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 52dc3740..2bb203a1 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4517,6 +4517,9 @@ transition: border-color var(--basalt-duration-fast) var(--basalt-ease-out); } .basalt-diagram[data-type="data-flow"] .basalt-diagram-node { --_d-gc: var(--_drawn) var(--_lc); } + /* A card grows to hold its ports (DECISIONS 306, section 4, call 3): the least height at which every port is on the flat part of its side and + size-diagram-head from the next, drawn layout only. */ + .basalt-diagram-node { --_d-mh: var(--_drawn) var(--_mh, auto); min-height: var(--_d-mh, auto); } .basalt-diagram-node[data-branch] { --_d-mi: var(--_drawn) 0; margin-inline: var(--_d-mi, var(--basalt-space-12) var(--basalt-space-6)); } .basalt-diagram-node:focus-visible { z-index: 2; outline: var(--basalt-size-focus-width) solid var(--basalt-border-focus); outline-offset: var(--basalt-size-focus-offset); } .basalt-diagram-node[data-near] { border-color: var(--basalt-border-hover); } From b2f473eb9ae0ce6b5fcecffd690637cd6103eab0 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:00:59 -0600 Subject: [PATCH 33/62] End lanes past two, and several entries into one card (DECISIONS 306, 1.3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stacked end gutter grows by lanes, one pitch (space-3-5 apart; lanes × space-3-5 + space-3: 40, 54, 68), four at most: a fifth is the merged last resort (no lines, the list open), and a development build warns from the third. Several end lines into one card nest: the outermost lane's line turns lowest (the merged turn) and enters nearest the end edge (space-6 in), each further in turns space-5 higher and enters space-3 further in; their labels are seated space-2-5 clear of the innermost entry, each centred on its own turn's height before the half-pixel snap, and the gap at that card grows space-5 an entry. Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 14 ++++---- packages/react/src/diagram-core.ts | 38 +++++++++++++++------ packages/react/src/styles/components.css | 2 +- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index b56f9625..2fc4a0b6 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--basalt-space-10)}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node{--_Mh: var(--_D) var(--_mh, auto);min-height:var(--_Mh, auto)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--_gw, var(--basalt-space-10))}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node{--_Mh: var(--_D) var(--_mh, auto);min-height:var(--_Mh, auto)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 3cfde76d..037903f1 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,12 +1,12 @@ -(()=>{var Ue=["top","right","bottom","left"],Je=["main","plain","dashed"],Xe=[2,3,4,5,6],at=t=>t==null||t===""?void 0:String(t),ut=t=>Object.assign(Object.create(null),t),gt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function wt(t,e={}){const s=e.checks!==!1,i=[],r=y=>{i.push(y)},o=t.legend??{},a={};for(const y of["main","plain","dashed","focal","group","activation"]){const b=at(o[y]);b&&(a[y]=b)}const l=t.stepLabel,f=typeof l=="function"?y=>String(l(y)):typeof l=="string"?(y=>l.replace("{n}",String(y))):y=>`Step ${y}`,m=t.shapeLabels??{},u={terminal:at(m.terminal)??"Start or end",step:at(m.step)??"Step",decision:at(m.decision)??"Decision"},c=t.heading===void 0?3:Xe.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),g=(y,b)=>y==null?"plain":Je.includes(y)?y:(r(`"${String(y)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),x=y=>{if(y!=null){if(Ue.includes(y))return y;r(`"${String(y)}" is not a side (top, right, bottom or left): the derived side is used`)}},d=(y,b)=>typeof y=="number"&&Number.isInteger(y)&&y>=1?y:(t.layout==="auto"&&y==null||r(`${b} is ${JSON.stringify(y)}, not a whole number from 1: it is placed at 1`),1),h=[],S=[];let j=[];const C=[],E=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||r(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const y of t.nodes??[]){const b=A==="flowchart"&&y.shape==="decision"?"decision":A==="flowchart"&&y.shape==="terminal"?"terminal":"box",p=String(y.id??""),k=d(y.row,`the row of ${p}`);h.push({id:p,i:h.length,name:String(y.name??""),kind:b==="decision"?void 0:at(y.kind),detail:b==="decision"?void 0:at(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:d(y.col,`the column of ${p}`),row:k,row2:k,branch:!!y.branch,shape:b,group:A==="architecture"?at(y.group):void 0,mark:A==="architecture"?Wt(y.mark):void 0})}if(A==="architecture"){const y=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:at($.parent)})),b=new Map(y.map($=>[$.id,$])),p=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(r(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(r(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(r(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},k=y.map(p);y.forEach(($,w)=>C.push({...$,depth:k[w],members:h.filter(_=>_.group===$.id).map(_=>_.id),all:[]}));for(const $ of C)$.all=[...$.members,...C.filter(w=>w.parent===$.id).flatMap(w=>w.members)];C.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){j=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const y=new Map(j.map((b,p)=>[b.id,p+1]));for(const b of t.nodes??[]){const p=String(b.id??""),k=String(b.lane??""),$=y.get(k);$===void 0&&r(`a node (${p}) names the lane "${k}", which is not in lanes`);const w=h.length+1;h.push({id:p,i:h.length,name:String(b.name??""),kind:f(w),detail:at(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:d(b.col,`the column of ${p}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:j[($??1)-1]?.label??k,step:w,mark:Wt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((k,$)=>{const w=String(k.name??"");h.push({id:String(k.id??""),i:$,name:w,kind:at(k.kind),mono:!1,focal:!!k.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:at(k.short)??w,mark:Wt(k.mark)})});let y=0;const b=new Map(h.map(k=>[k.id,k.col])),p=(k,$)=>{let w=1/0,_=-1/0;for(const q of k??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&r(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),E.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){r("a frame is a third level: frames nest two deep");continue}const st=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=st==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];st==="alt"&&V.length<2&&r("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&r(`the frame label "${P}" is over 40 characters`);const J=E.length;E.push({open:st,label:P,depth:$+1,a:0,b:0}),V.forEach((nt,rt)=>{if(rt){const kt=String(nt.label??"");kt.length>40&&r(`the frame label "${kt}" is over 40 characters`),E.push({otherwise:kt,depth:$+1})}nt.steps?.length||r(`a frame or branch ("${String(nt.label??"")}") is empty`);const[ct,qt]=p(nt.steps??[],$+1);w=Math.min(w,ct),_=Math.max(_,qt);const $t=E[J];$t.a=Math.min($t.a||1/0,ct),$t.b=Math.max($t.b,qt)}),E.push({close:$+1});continue}y++;const R=String(q.label??"");R.includes(` -`)&&r(`message ${y}'s label has a break: a message's second line is its note`);const U=String(q.from??""),Y=String(q.to??"");E.push({n:y,from:U,to:Y,label:yt(R),note:at(q.note),kind:g(q.kind,`message ${y}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const N=b.get(U)??1,D=b.get(Y)??1,tt=N===D?N===h.length?N-1:N+1:N;w=Math.min(w,N,D,tt),_=Math.max(_,N,D,tt)}return[w,_]};p(t.steps??[],0);for(const k of E)"open"in k&&!Number.isFinite(k.a)&&(k.a=1,k.b=Math.max(1,h.length))}else if(A==="schema")for(const y of t.tables??[]){const b=String(y.name??""),[p,k]=Array.isArray(y.row)?y.row:[y.row,y.row],$=d(p,`the row of ${b}`),w=Math.max($,d(k,`the last row of ${b}`)),_=y.more===void 0||y.more===null?void 0:Number.isInteger(y.more)&&y.more>0?y.more:(r(`${b}'s "more" is ${JSON.stringify(y.more)}, not a whole number from 1: it is left out`),void 0);h.push({id:b,i:h.length,name:b,mono:!0,focal:!!y.focal,col:d(y.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:_,columns:(y.columns??[]).map(q=>({name:String(q.name??""),type:at(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&r(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const y=A==="schema"?t.tables:t.nodes;s&&(y??[]).some(p=>p&&(p.col!==void 0||p.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(T=!0);for(const p of h){const k=b?.[p.id];p.col=k?.col??1,p.row=p.row2=k?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((y,b)=>{if(!y||y.href===void 0||y.href===null)return;const p=String(y.href);if(A==="sequence"){r(`${h[b]?.id}: a participant cannot be a link (href)`);return}if(!p){r(`${h[b]?.id}'s href is empty`);return}const k=h[b];k&&(k.href=p,k.blank=y.target==="_blank")});const B=new Map;for(const y of h)y.id?B.has(y.id)&&r(`the id "${y.id}" is used twice`):r("a node has no id"),B.set(y.id,y);if(A==="schema")(t.tables??[]).forEach(y=>(y.columns??[]).forEach((b,p)=>{const k=at(b.references);if(!k)return;const[$,w]=k.split("."),_=B.get($??""),q=_?.columns?.findIndex(U=>U.name===w)??-1;if(!_||q<0){r(`${String(y.name)}.${String(b.name)} references ${k}, which is not a shown column`);return}const R=B.get(String(y.name??""));R.columns[p].ref={table:$,column:w,row:q},S.push({i:S.length,from:R.id,to:$,kind:"plain",fromRow:p,toRow:q,fk:!0})}));else if(A!=="sequence")for(const y of t.edges??[]){const b=String(y.from??""),p=String(y.to??"");if(!B.has(b)||!B.has(p)){r(`a line names ${B.has(b)?p:b}, which is not a node`);continue}const k=at(y.label),$=k?.split(` -`)??[];$.length>2&&r(`the label "${yt(k)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>te)&&r(`a line of the label "${yt(k)}" is over ${te} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:p,kind:g(y.kind,`the line from ${b} to ${p}`),label:k,fromSide:x(y.fromSide),toSide:x(y.toSide),flow:A!=="flowchart"&&y.flow===!0?!0:void 0})}else for(const y of E)"n"in y&&(!B.has(y.from)||!B.has(y.to))&&r(`message ${y.n} names ${B.has(y.from)?y.to:y.from}, which is not a participant`);if(s&&A!=="sequence"&&!T){const y=new Map;for(const b of h)for(let p=b.row;p<=b.row2;p++){const k=`${b.col}:${p}`;y.has(k)&&r(`${b.id} and ${y.get(k)} share the cell at column ${b.col}, row ${p}`),y.set(k,b.id)}}if(s&&!T){for(const b of C){const p=b.all.map(w=>B.get(w));if(!p.length)continue;const k={c1:Math.min(...p.map(w=>w.col)),c2:Math.max(...p.map(w=>w.col)),r1:Math.min(...p.map(w=>w.row)),r2:Math.max(...p.map(w=>w.row2))};for(const w of h)!b.all.includes(w.id)&&w.col>=k.c1&&w.col<=k.c2&&w.row>=k.r1&&w.row<=k.r2&&r(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=p.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&r(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of h)b.group&&!C.some(p=>p.id===b.group)&&r(`${b.id} names the group "${b.group}", which is not in groups`);h.filter(b=>b.focal).length>1&&r("more than one node is focal: a diagram has one at most");const y=new Set(A==="sequence"?E.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));y.has("main")&&!a.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),y.has("dashed")&&!a.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),h.some(b=>b.focal)&&!a.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const ot=A==="architecture"||A==="data-flow",L=y=>Array.isArray(y)&&y.length>1?y.map(String):void 0,z=ot&&t.packet&&typeof t.packet=="object"?t.packet:void 0,I=z&&L(z.path),M={animated:t.motion==="animated",pulse:ot?L(t.pulse):void 0,packet:I?{path:I,repeat:z.repeat===!0,send:z.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const y of h){const b=y.mark?.says;if(!b?.length)continue;const p=[y.name,y.kind,y.detail,y.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(k=>p.includes(k.toLowerCase()))||r(`${y.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const y=new Map,b=new Map;for(const p of E)"n"in p&&(b.set(p.from,p.n),b.set(p.to,p.n));for(const p of E)if("n"in p){if(p.activate){const k=y.get(p.to)??[];if(k.length>=3)r(`message ${p.n} opens a fourth bar on ${p.to}: three deep at most`);else{const $={who:p.to,from:p.n,to:p.n,depth:k.length+1};k.push($),O.push($),y.set(p.to,k)}}if(p.deactivate){const $=y.get(p.from)?.pop();$?$.to=p.n:r(`message ${p.n} closes a bar on ${p.from}, which has none open`)}}for(const[p,k]of y)for(const $ of k)$.to=Math.max($.from,b.get(p)??$.from)}const F=t.frameLabels??{},G={opt:at(F.opt)??"Only if",loop:at(F.loop)??"Repeats",alt:at(F.alt)??"One of these",else:at(F.else)??"Otherwise"};let W=Math.max(1,...h.map(y=>y.col));if(e.rtl){for(const b of h)b.col=W-b.col+1;const y=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=y(b.fromSide),b.toSide=y(b.toSide);for(const b of E)if("open"in b){const[p,k]=[W-b.b+1,W-b.a+1];b.a=p,b.b=k}W=Math.max(1,...h.map(b=>b.col))}const Q=A==="data-flow"?Math.max(1,j.length):Math.max(1,...h.map(y=>y.row2)),K={type:A,title:String(t.title??""),heading:c,legend:a,nodes:h,byId:B,edges:S,groups:C,lanes:j,steps:E,bars:O,frameWords:G,cols:W,rows:Q,shapeLabels:u,stepWord:f,warnings:i,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0,text:A==="sequence"&&t.variant==="text"||void 0};if(t.layout==="auto"&&!T&&A!=="schema"&&Ye(K),s)for(const[y,b]of Object.entries(we(K)))b>=48&&r(`${y} grows to ${b}px to hold the lines on one side: use another side`);return s&&h.length>1&&!_t(K)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function Ye(t){const e=new Set(t.nodes.map(o=>`${o.col},${o.row}`)),n=(o,a)=>{const l=[];for(let f=Math.min(o,a)+1;f{const a=t.byId.get(o.from),l=t.byId.get(o.to),f=l.col>a.col?"right":"left",m=l.row>a.row?"bottom":"top",u=l.col>a.col?"left":"right",c=l.row>a.row?"top":"bottom",g=(d,h,S,j)=>n(d,h).map(C=>j?[C,S]:[S,C]);let x;return a.row===l.row?x=[{sides:[f,u],cells:g(a.col,l.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===l.col?x=[{sides:[m,c],cells:g(a.row,l.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:x=[{sides:[f,c],cells:[...g(a.col,l.col,a.row,!0),[l.col,a.row],...g(a.row,l.row,l.col,!1)]},{sides:[m,u],cells:[...g(a.row,l.row,a.col,!1),[a.col,l.row],...g(a.col,l.col,l.row,!0)]},{sides:[f,u],cells:g(a.col,l.col,a.row,!0)},{sides:[m,c],cells:g(a.row,l.row,a.col,!1)}],x.filter(d=>d.cells.every(([h,S])=>!e.has(`${h},${S}`)))},i=new Map,r=t.edges.map((o,a)=>a).sort((o,a)=>s(t.edges[o]).length-s(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[o].kind==="main")||o-a);for(const o of r){const a=t.edges[o];if(a.fromSide||a.toSide)continue;const l=s(a).find(f=>(i.get(`${a.from}.${f.sides[0]}`)??0)<3&&(i.get(`${a.to}.${f.sides[1]}`)??0)<3);if(l){for(const[f,m]of[[a.from,l.sides[0]],[a.to,l.sides[1]]])i.set(`${f}.${m}`,(i.get(`${f}.${m}`)??0)+1);a.fromSide=l.sides[0],a.toSide=l.sides[1]}}}function Wt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=at(e.onLight);if(n)return{onLight:n,onDark:at(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Pt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +(()=>{var Ue=["top","right","bottom","left"],Je=["main","plain","dashed"],Xe=[2,3,4,5,6],rt=t=>t==null||t===""?void 0:String(t),ut=t=>Object.assign(Object.create(null),t),gt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function wt(t,e={}){const s=e.checks!==!1,i=[],r=y=>{i.push(y)},o=t.legend??{},a={};for(const y of["main","plain","dashed","focal","group","activation"]){const b=rt(o[y]);b&&(a[y]=b)}const l=t.stepLabel,d=typeof l=="function"?y=>String(l(y)):typeof l=="string"?(y=>l.replace("{n}",String(y))):y=>`Step ${y}`,m=t.shapeLabels??{},f={terminal:rt(m.terminal)??"Start or end",step:rt(m.step)??"Step",decision:rt(m.decision)??"Decision"},c=t.heading===void 0?3:Xe.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),g=(y,b)=>y==null?"plain":Je.includes(y)?y:(r(`"${String(y)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),x=y=>{if(y!=null){if(Ue.includes(y))return y;r(`"${String(y)}" is not a side (top, right, bottom or left): the derived side is used`)}},h=(y,b)=>typeof y=="number"&&Number.isInteger(y)&&y>=1?y:(t.layout==="auto"&&y==null||r(`${b} is ${JSON.stringify(y)}, not a whole number from 1: it is placed at 1`),1),u=[],S=[];let I=[];const T=[],M=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||r(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const y of t.nodes??[]){const b=A==="flowchart"&&y.shape==="decision"?"decision":A==="flowchart"&&y.shape==="terminal"?"terminal":"box",p=String(y.id??""),k=h(y.row,`the row of ${p}`);u.push({id:p,i:u.length,name:String(y.name??""),kind:b==="decision"?void 0:rt(y.kind),detail:b==="decision"?void 0:rt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:h(y.col,`the column of ${p}`),row:k,row2:k,branch:!!y.branch,shape:b,group:A==="architecture"?rt(y.group):void 0,mark:A==="architecture"?Wt(y.mark):void 0})}if(A==="architecture"){const y=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:rt($.parent)})),b=new Map(y.map($=>[$.id,$])),p=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(r(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(r(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(r(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},k=y.map(p);y.forEach(($,w)=>T.push({...$,depth:k[w],members:u.filter(C=>C.group===$.id).map(C=>C.id),all:[]}));for(const $ of T)$.all=[...$.members,...T.filter(w=>w.parent===$.id).flatMap(w=>w.members)];T.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){I=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const y=new Map(I.map((b,p)=>[b.id,p+1]));for(const b of t.nodes??[]){const p=String(b.id??""),k=String(b.lane??""),$=y.get(k);$===void 0&&r(`a node (${p}) names the lane "${k}", which is not in lanes`);const w=u.length+1;u.push({id:p,i:u.length,name:String(b.name??""),kind:d(w),detail:rt(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:h(b.col,`the column of ${p}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:I[($??1)-1]?.label??k,step:w,mark:Wt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((k,$)=>{const w=String(k.name??"");u.push({id:String(k.id??""),i:$,name:w,kind:rt(k.kind),mono:!1,focal:!!k.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:rt(k.short)??w,mark:Wt(k.mark)})});let y=0;const b=new Map(u.map(k=>[k.id,k.col])),p=(k,$)=>{let w=1/0,C=-1/0;for(const q of k??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&r(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){r("a frame is a third level: frames nest two deep");continue}const ot=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=ot==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];ot==="alt"&&V.length<2&&r("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&r(`the frame label "${P}" is over 40 characters`);const Z=M.length;M.push({open:ot,label:P,depth:$+1,a:0,b:0}),V.forEach((U,at)=>{if(at){const kt=String(U.label??"");kt.length>40&&r(`the frame label "${kt}" is over 40 characters`),M.push({otherwise:kt,depth:$+1})}U.steps?.length||r(`a frame or branch ("${String(U.label??"")}") is empty`);const[ct,It]=p(U.steps??[],$+1);w=Math.min(w,ct),C=Math.max(C,It);const $t=M[Z];$t.a=Math.min($t.a||1/0,ct),$t.b=Math.max($t.b,It)}),M.push({close:$+1});continue}y++;const F=String(q.label??"");F.includes(` +`)&&r(`message ${y}'s label has a break: a message's second line is its note`);const X=String(q.from??""),nt=String(q.to??"");M.push({n:y,from:X,to:nt,label:yt(F),note:rt(q.note),kind:g(q.kind,`message ${y}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const z=b.get(X)??1,G=b.get(nt)??1,et=z===G?z===u.length?z-1:z+1:z;w=Math.min(w,z,G,et),C=Math.max(C,z,G,et)}return[w,C]};p(t.steps??[],0);for(const k of M)"open"in k&&!Number.isFinite(k.a)&&(k.a=1,k.b=Math.max(1,u.length))}else if(A==="schema")for(const y of t.tables??[]){const b=String(y.name??""),[p,k]=Array.isArray(y.row)?y.row:[y.row,y.row],$=h(p,`the row of ${b}`),w=Math.max($,h(k,`the last row of ${b}`)),C=y.more===void 0||y.more===null?void 0:Number.isInteger(y.more)&&y.more>0?y.more:(r(`${b}'s "more" is ${JSON.stringify(y.more)}, not a whole number from 1: it is left out`),void 0);u.push({id:b,i:u.length,name:b,mono:!0,focal:!!y.focal,col:h(y.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:C,columns:(y.columns??[]).map(q=>({name:String(q.name??""),type:rt(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&r(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let B=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const y=A==="schema"?t.tables:t.nodes;s&&(y??[]).some(p=>p&&(p.col!==void 0||p.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(B=!0);for(const p of u){const k=b?.[p.id];p.col=k?.col??1,p.row=p.row2=k?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((y,b)=>{if(!y||y.href===void 0||y.href===null)return;const p=String(y.href);if(A==="sequence"){r(`${u[b]?.id}: a participant cannot be a link (href)`);return}if(!p){r(`${u[b]?.id}'s href is empty`);return}const k=u[b];k&&(k.href=p,k.blank=y.target==="_blank")});const j=new Map;for(const y of u)y.id?j.has(y.id)&&r(`the id "${y.id}" is used twice`):r("a node has no id"),j.set(y.id,y);if(A==="schema")(t.tables??[]).forEach(y=>(y.columns??[]).forEach((b,p)=>{const k=rt(b.references);if(!k)return;const[$,w]=k.split("."),C=j.get($??""),q=C?.columns?.findIndex(X=>X.name===w)??-1;if(!C||q<0){r(`${String(y.name)}.${String(b.name)} references ${k}, which is not a shown column`);return}const F=j.get(String(y.name??""));F.columns[p].ref={table:$,column:w,row:q},S.push({i:S.length,from:F.id,to:$,kind:"plain",fromRow:p,toRow:q,fk:!0})}));else if(A!=="sequence")for(const y of t.edges??[]){const b=String(y.from??""),p=String(y.to??"");if(!j.has(b)||!j.has(p)){r(`a line names ${j.has(b)?p:b}, which is not a node`);continue}const k=rt(y.label),$=k?.split(` +`)??[];$.length>2&&r(`the label "${yt(k)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>te)&&r(`a line of the label "${yt(k)}" is over ${te} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:p,kind:g(y.kind,`the line from ${b} to ${p}`),label:k,fromSide:x(y.fromSide),toSide:x(y.toSide),flow:A!=="flowchart"&&y.flow===!0?!0:void 0})}else for(const y of M)"n"in y&&(!j.has(y.from)||!j.has(y.to))&&r(`message ${y.n} names ${j.has(y.from)?y.to:y.from}, which is not a participant`);if(s&&A!=="sequence"&&!B){const y=new Map;for(const b of u)for(let p=b.row;p<=b.row2;p++){const k=`${b.col}:${p}`;y.has(k)&&r(`${b.id} and ${y.get(k)} share the cell at column ${b.col}, row ${p}`),y.set(k,b.id)}}if(s&&!B){for(const b of T){const p=b.all.map(w=>j.get(w));if(!p.length)continue;const k={c1:Math.min(...p.map(w=>w.col)),c2:Math.max(...p.map(w=>w.col)),r1:Math.min(...p.map(w=>w.row)),r2:Math.max(...p.map(w=>w.row2))};for(const w of u)!b.all.includes(w.id)&&w.col>=k.c1&&w.col<=k.c2&&w.row>=k.r1&&w.row<=k.r2&&r(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=p.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&r(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of u)b.group&&!T.some(p=>p.id===b.group)&&r(`${b.id} names the group "${b.group}", which is not in groups`);u.filter(b=>b.focal).length>1&&r("more than one node is focal: a diagram has one at most");const y=new Set(A==="sequence"?M.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));y.has("main")&&!a.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),y.has("dashed")&&!a.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),u.some(b=>b.focal)&&!a.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const Q=A==="architecture"||A==="data-flow",L=y=>Array.isArray(y)&&y.length>1?y.map(String):void 0,N=Q&&t.packet&&typeof t.packet=="object"?t.packet:void 0,_=N&&L(N.path),E={animated:t.motion==="animated",pulse:Q?L(t.pulse):void 0,packet:_?{path:_,repeat:N.repeat===!0,send:N.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const y of u){const b=y.mark?.says;if(!b?.length)continue;const p=[y.name,y.kind,y.detail,y.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(k=>p.includes(k.toLowerCase()))||r(`${y.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const y=new Map,b=new Map;for(const p of M)"n"in p&&(b.set(p.from,p.n),b.set(p.to,p.n));for(const p of M)if("n"in p){if(p.activate){const k=y.get(p.to)??[];if(k.length>=3)r(`message ${p.n} opens a fourth bar on ${p.to}: three deep at most`);else{const $={who:p.to,from:p.n,to:p.n,depth:k.length+1};k.push($),O.push($),y.set(p.to,k)}}if(p.deactivate){const $=y.get(p.from)?.pop();$?$.to=p.n:r(`message ${p.n} closes a bar on ${p.from}, which has none open`)}}for(const[p,k]of y)for(const $ of k)$.to=Math.max($.from,b.get(p)??$.from)}const R=t.frameLabels??{},D={opt:rt(R.opt)??"Only if",loop:rt(R.loop)??"Repeats",alt:rt(R.alt)??"One of these",else:rt(R.else)??"Otherwise"};let W=Math.max(1,...u.map(y=>y.col));if(e.rtl){for(const b of u)b.col=W-b.col+1;const y=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=y(b.fromSide),b.toSide=y(b.toSide);for(const b of M)if("open"in b){const[p,k]=[W-b.b+1,W-b.a+1];b.a=p,b.b=k}W=Math.max(1,...u.map(b=>b.col))}const tt=A==="data-flow"?Math.max(1,I.length):Math.max(1,...u.map(y=>y.row2)),K={type:A,title:String(t.title??""),heading:c,legend:a,nodes:u,byId:j,edges:S,groups:T,lanes:I,steps:M,bars:O,frameWords:D,cols:W,rows:tt,shapeLabels:f,stepWord:d,warnings:i,motion:E,memo:new Map,rtl:e.rtl||void 0,unplaced:B||void 0,text:A==="sequence"&&t.variant==="text"||void 0};if(t.layout==="auto"&&!B&&A!=="schema"&&Ye(K),s)for(const[y,b]of Object.entries(we(K)))b>=48&&r(`${y} grows to ${b}px to hold the lines on one side: use another side`);return s&&u.length>1&&!Ot(K)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function Ye(t){const e=new Set(t.nodes.map(o=>`${o.col},${o.row}`)),n=(o,a)=>{const l=[];for(let d=Math.min(o,a)+1;d{const a=t.byId.get(o.from),l=t.byId.get(o.to),d=l.col>a.col?"right":"left",m=l.row>a.row?"bottom":"top",f=l.col>a.col?"left":"right",c=l.row>a.row?"top":"bottom",g=(h,u,S,I)=>n(h,u).map(T=>I?[T,S]:[S,T]);let x;return a.row===l.row?x=[{sides:[d,f],cells:g(a.col,l.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===l.col?x=[{sides:[m,c],cells:g(a.row,l.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:x=[{sides:[d,c],cells:[...g(a.col,l.col,a.row,!0),[l.col,a.row],...g(a.row,l.row,l.col,!1)]},{sides:[m,f],cells:[...g(a.row,l.row,a.col,!1),[a.col,l.row],...g(a.col,l.col,l.row,!0)]},{sides:[d,f],cells:g(a.col,l.col,a.row,!0)},{sides:[m,c],cells:g(a.row,l.row,a.col,!1)}],x.filter(h=>h.cells.every(([u,S])=>!e.has(`${u},${S}`)))},i=new Map,r=t.edges.map((o,a)=>a).sort((o,a)=>s(t.edges[o]).length-s(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[o].kind==="main")||o-a);for(const o of r){const a=t.edges[o];if(a.fromSide||a.toSide)continue;const l=s(a).find(d=>(i.get(`${a.from}.${d.sides[0]}`)??0)<3&&(i.get(`${a.to}.${d.sides[1]}`)??0)<3);if(l){for(const[d,m]of[[a.from,l.sides[0]],[a.to,l.sides[1]]])i.set(`${d}.${m}`,(i.get(`${d}.${m}`)??0)+1);a.fromSide=l.sides[0],a.toSide=l.sides[1]}}}function Wt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=rt(e.onLight);if(n)return{onLight:n,onDark:rt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Pt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` `?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function mt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var te=28,Ft=t=>t.includes(` -`)?2:1,yt=t=>t.replace(/\n/g," "),vt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function ee(t,e){return t.legend[e]}function Qe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Pe(t,e){return mt(t,`sentence:${e.i}`,()=>tn(t,e))}function tn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,i=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(vt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${i}.`);const r=ne(t,e);r&&n.push(r.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Qe(t,e):e.kind;if(n.push(vt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(vt(e.detail)),e.group){const o=t.groups.find(l=>l.id===e.group),a=o?.parent?t.groups.find(l=>l.id===o.parent):void 0;o&&n.push(a?`In ${o.label}, in ${a.label}.`:`In ${o.label}.`)}const i=t.edges.filter(o=>o.to===e.id).map(o=>`${t.byId.get(o.from).name}${o.label?` (${yt(o.label)})`:""}`),r=t.edges.filter(o=>o.from===e.id).map(o=>`${t.byId.get(o.to).name}${o.label?` (${yt(o.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(vt(t.legend.focal)),n.join(" ")}function ne(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function en(t,e,n,s){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),o=n.target;if(!r||!o||!r.contains(o)||!t.querySelector(`.${e}-edge`))return;const a=o.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===s?null:a.dataset.node??null:null}function oe(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const s=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&s.push(i);return{t,a:e??{},c:s}}var nn={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>nn[e]),on=" br img input meta link hr path polygon polyline circle rect line ";function Nt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=i===!0?` ${s}`:` ${s}="${it(String(i))}"`}return on.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Nt(s,e)).join("")}`}var sn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function bt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function an(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function It(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function se(t){return mt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=It(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((r,o)=>{r&&(e[o]=Math.max(e[o],ae(t,n,o)))})}return e})}function ae(t,e,n){const s=It(t,e);return t.groups.filter(o=>o.parent===e.id).some(o=>{const a=It(t,o);return a&&[a.r1===s.r1,a.c2===s.c2,a.r2===s.r2,a.c1===s.c1][n]})?2:1}function re(t){const e=se(t);return e[1]+e[3]}function zt(t){return t.type==="sequence"?t.nodes.length:t.cols}function ie(t){return mt(t,"plan",()=>rn(t))}function rn(t){const e=t.nodes,n=d=>t.type==="data-flow"||!e[d].branch,s=t.edges.map(d=>{const h=t.byId.get(d.from).i,S=t.byId.get(d.to).i,C=e.slice(Math.min(h,S)+1,Math.max(h,S)).every(E=>!n(E.i));return S===h+1&&!(n(h)&&!n(S))?"down":S===h-1?"up":S>h&&n(h)&&!n(S)&&C?"trunk":S>h&&n(h)&&n(S)&&C?"rail":S>h?"end-down":"end-up"}),i=t.edges.map((d,h)=>({e:d,k:h})).filter(({k:d})=>s[d]==="end-down"||s[d]==="end-up"),r=d=>{const h=t.byId.get(d.from).i,S=t.byId.get(d.to).i;return[Math.min(h,S),Math.max(h,S)]},o=(d,h)=>{const[S,j]=r(d),[C,E]=r(h);return S{const h=t.byId.get(d.from).i,[S,j]=r(d);return!n(h)&&e.slice(S+1,j).every(C=>!n(C.i))&&i.every(C=>C.e===d||!o(C.e,d))}),l=i.length>0&&(t.type==="data-flow"||!a),f=d=>{const[h,S]=r(d);return S-h},m=t.edges.map(()=>0);let u=!1;const c=[];for(const d of[...i].sort((h,S)=>f(h.e)-f(S.e)||h.k-S.k)){let h=0;for(const S of c)o(S.e,d.e)&&(h=Math.max(h,m[S.k]+1));m[d.k]=h,h>1&&(u=!0),c.push(d)}const g=t.edges.map(()=>.5);for(const d of e){const h=i.filter(({e:C})=>C.from===d.id);if(h.length<2)continue;const S=h.filter(({k:C})=>s[C]==="end-down").sort((C,E)=>f(E.e)-f(C.e)||C.k-E.k);[...h.filter(({k:C})=>s[C]==="end-up").sort((C,E)=>f(C.e)-f(E.e)||E.k-C.k),...S].forEach(({k:C},E,A)=>{g[C]=A.length===2?E===0?1/3:2/3:(E+1)/(A.length+1)})}const x=ut();for(let d=1;d{const B=s[Z],ot=t.byId.get(T.from).i,L=t.byId.get(T.to).i,z=L===d&&(B==="down"||B==="trunk"||B==="rail"||B==="end-down"),I=ot===d&&L===d-1&&B==="up",M=L===d-1&&B==="end-up";z&&(B==="trunk"||B==="end-down")&&(E=!0),M&&(A=!0),(z||I||M)&&T.label&&(j++,C=Math.max(C,B==="trunk"?40:48))}),(j>1||E&&A)&&(C=64),x[h.id]=C}return{routes:s,gutter:l,lanes:m,exits:g,gaps:x,third:u}}var xt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function le(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...xt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${r}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${s-4}L${i} ${s}L${i-8} ${s+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${s}L${i-8} ${s-4}L${i-8} ${s+4}Z`}))}function Et(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function ce(t,e){return mt(e,`key:${t}`,()=>cn(t,e))}var ln=ce;function cn(t,e){const n=[],s=(o,a,l={})=>n.push(v("li",{class:`${t}-entry`,...l},o,v("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),v("span",null,l)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(Et(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(Et(t,"box"),e.shapeLabels.step),o.has("decision")&&s(Et(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind)),r=(o,a)=>v("span",{class:`${t}-key-glyph`,"data-ink":a,"aria-hidden":"true"},o);for(const o of["main","plain","dashed"]){const a=e.legend[o];i.has(o)&&a&&s(e.text?r(o==="main"?"━━▶":o==="dashed"?"┄┄▷":"──▶",o==="main"?"main":"plain"):le(t,o),a,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length&&(s(le(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(e.text?r("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...xt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),v("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(Et(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(Et(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function dn(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...xt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Ht(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function fn(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},Ht(t,n)))];const s=[];return e.type==="data-flow"?s.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(v("span",{class:`${t}-kind`},n.kind)),s.push(v("span",{class:`${t}-name`},Ht(t,n))),n.detail&&s.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?jt(n.detail).flatMap((i,r)=>[r?" ":"",v("span",{class:`${t}-run`},i)]):n.detail)),s}function un(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},Ht(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((s,i)=>v("span",{class:`${t}-row`,"data-row":i,"data-key":s.key},v("span",{class:`${t}-keyseat`},s.key??""),v("span",{class:`${t}-cname`},s.name),s.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?v("span",{class:`${t}-ctype`},s.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var de=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Ot(t,e,n,s){const{P:i}=t,r=an(e,s)||s.keep===n.id,o=bt(e,s),a=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&a.push(`--_lc:${n.col+1}`),e.type==="sequence"&&a.push(`--_c2:${n.col+1}`);const l=t.plan;if(l&&n.i>0){const g=gt(l.gaps,n.id)??32,x=gt(s.grow,n.id)??0;a.push(`--_gap:${x?`calc(${de(g)} + var(--basalt-space-4) * ${x})`:de(g)}`)}const f=gt(s.heights,n.id);f&&a.push(`--_h:${f}px`);const m=gt(we(e),n.id);m&&a.push(`--_mh:${m}px`);const u=gt(s.words,n.id);u&&a.push(`--_ww:${u}px`);const c=o?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:a.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?Pe(e,n):void 0,tabindex:c},n.shape==="decision"?v("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Pt(n.mark.onLight)};--_md:${Pt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?un(i,n,e):fn(i,e,n))}function hn(t,e,n){const{P:s}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((l,f)=>v("div",{class:`${s}-lane`,style:`--_r:${f+1}`,"aria-hidden":"true"},v("span",{class:`${s}-lane-name`},l.label)))),e.type==="architecture")for(const l of e.groups){const f=It(e,l);if(!f)continue;const m=[0,1,2,3].map(u=>ae(e,l,u));i.push(v("div",{class:`${s}-gbox`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:`--_c:${f.c1};--_c2:${f.c2+1};--_r:${f.r1};--_r2:${f.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${s}-glabel`},l.label)))}if(e.text)return[v("pre",{class:`${s}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${s}-text-ink`},pn(s,e)))];if(e.type==="sequence")return i.push(v("ul",{class:`${s}-cast`},e.nodes.map(l=>v("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${l.col}`:void 0},Ot(t,e,l,n))))),i.push(gn(t,e)),i;const r=l=>{const f=l.group?e.groups.find(m=>m.id===l.group):void 0;return f?.parent?e.groups.find(m=>m.id===f.parent):f},o=(l,f,m)=>{const u=t.plan?gt(n.grow,f[0].id)??0:0;return v("div",{class:`${s}-group`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:u?`--_ggrow:${u}`:void 0},v("span",{class:`${s}-glabel`,"aria-hidden":"true"},l.label),m)};let a=0;for(;ad.id===m[c].group):void 0;if(!g){u.push(Ot(t,e,m[c],n)),c++;continue}const x=[];for(;cOt(t,e,d,n))))}i.push(o(f,m,u))}return i}function pn(t,e){const n=[],s=o=>v("span",{class:`${t}-tx-name`},o),i=o=>o==="main"?"━▶":o==="dashed"?"┄▷":"─▶";n.push(v("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((o,a)=>[a?" · ":"",s(o.name)])),` +`)?2:1,yt=t=>t.replace(/\n/g," "),vt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function ee(t,e){return t.legend[e]}function Qe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Pe(t,e){return mt(t,`sentence:${e.i}`,()=>tn(t,e))}function tn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,i=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(vt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${i}.`);const r=ne(t,e);r&&n.push(r.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Qe(t,e):e.kind;if(n.push(vt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(vt(e.detail)),e.group){const o=t.groups.find(l=>l.id===e.group),a=o?.parent?t.groups.find(l=>l.id===o.parent):void 0;o&&n.push(a?`In ${o.label}, in ${a.label}.`:`In ${o.label}.`)}const i=t.edges.filter(o=>o.to===e.id).map(o=>`${t.byId.get(o.from).name}${o.label?` (${yt(o.label)})`:""}`),r=t.edges.filter(o=>o.from===e.id).map(o=>`${t.byId.get(o.to).name}${o.label?` (${yt(o.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(vt(t.legend.focal)),n.join(" ")}function ne(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function en(t,e,n,s){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),o=n.target;if(!r||!o||!r.contains(o)||!t.querySelector(`.${e}-edge`))return;const a=o.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===s?null:a.dataset.node??null:null}function oe(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const s=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&s.push(i);return{t,a:e??{},c:s}}var nn={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>nn[e]),on=" br img input meta link hr path polygon polyline circle rect line ";function Nt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=i===!0?` ${s}`:` ${s}="${it(String(i))}"`}return on.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Nt(s,e)).join("")}`}var sn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function bt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function an(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function qt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function se(t){return mt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=qt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((r,o)=>{r&&(e[o]=Math.max(e[o],ae(t,n,o)))})}return e})}function ae(t,e,n){const s=qt(t,e);return t.groups.filter(o=>o.parent===e.id).some(o=>{const a=qt(t,o);return a&&[a.r1===s.r1,a.c2===s.c2,a.r2===s.r2,a.c1===s.c1][n]})?2:1}function re(t){const e=se(t);return e[1]+e[3]}function zt(t){return t.type==="sequence"?t.nodes.length:t.cols}function ie(t){return mt(t,"plan",()=>rn(t))}function rn(t){const e=t.nodes,n=u=>t.type==="data-flow"||!e[u].branch,s=t.edges.map(u=>{const S=t.byId.get(u.from).i,I=t.byId.get(u.to).i,M=e.slice(Math.min(S,I)+1,Math.max(S,I)).every(A=>!n(A.i));return I===S+1&&!(n(S)&&!n(I))?"down":I===S-1?"up":I>S&&n(S)&&!n(I)&&M?"trunk":I>S&&n(S)&&n(I)&&M?"rail":I>S?"end-down":"end-up"}),i=t.edges.map((u,S)=>({e:u,k:S})).filter(({k:u})=>s[u]==="end-down"||s[u]==="end-up"),r=u=>{const S=t.byId.get(u.from).i,I=t.byId.get(u.to).i;return[Math.min(S,I),Math.max(S,I)]},o=(u,S)=>{const[I,T]=r(u),[M,A]=r(S);return I{const S=t.byId.get(u.from).i,[I,T]=r(u);return!n(S)&&e.slice(I+1,T).every(M=>!n(M.i))&&i.every(M=>M.e===u||!o(M.e,u))}),l=i.length>0&&(t.type==="data-flow"||!a),d=u=>{const[S,I]=r(u);return I-S},m=t.edges.map(()=>0);let f=!1;const c=[];for(const u of[...i].sort((S,I)=>d(S.e)-d(I.e)||S.k-I.k)){let S=0;for(const I of c)o(I.e,u.e)&&(S=Math.max(S,m[I.k]+1));m[u.k]=S,S>3&&(f=!0),c.push(u)}const g=Math.max(0,...i.map(({k:u})=>m[u]+1)),x=t.edges.map(()=>.5);for(const u of e){const S=i.filter(({e:M})=>M.from===u.id);if(S.length<2)continue;const I=S.filter(({k:M})=>s[M]==="end-down").sort((M,A)=>d(A.e)-d(M.e)||M.k-A.k);[...S.filter(({k:M})=>s[M]==="end-up").sort((M,A)=>d(M.e)-d(A.e)||A.k-M.k),...I].forEach(({k:M},A,B)=>{x[M]=B.length===2?A===0?1/3:2/3:(A+1)/(B.length+1)})}const h=ut();for(let u=1;u{const N=s[L],_=t.byId.get(Q.from).i,E=t.byId.get(Q.to).i,O=E===u&&(N==="down"||N==="trunk"||N==="rail"||N==="end-down"),R=_===u&&E===u-1&&N==="up",D=E===u-1&&N==="end-up";O&&(N==="trunk"||N==="end-down")&&(A=!0),D&&(B=!0),(O||R||D)&&Q.label&&(T++,M=Math.max(M,N==="trunk"?40:48))}),(T>1||A&&B)&&(M=64);const J=i.filter(({e:Q,k:L})=>s[L]==="end-down"&&t.byId.get(Q.to).i===u).length,j=i.filter(({e:Q,k:L})=>s[L]==="end-up"&&t.byId.get(Q.to).i===u-1).length;M+=20*Math.max(0,J-1)+20*Math.max(0,j-1),h[S.id]=M}return{routes:s,gutter:l,lanes:m,exits:x,gaps:h,third:f,laneCount:g}}var xt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function le(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...xt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${r}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${s-4}L${i} ${s}L${i-8} ${s+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${s}L${i-8} ${s-4}L${i-8} ${s+4}Z`}))}function Et(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function ce(t,e){return mt(e,`key:${t}`,()=>cn(t,e))}var ln=ce;function cn(t,e){const n=[],s=(o,a,l={})=>n.push(v("li",{class:`${t}-entry`,...l},o,v("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),v("span",null,l)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(Et(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(Et(t,"box"),e.shapeLabels.step),o.has("decision")&&s(Et(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind)),r=(o,a)=>v("span",{class:`${t}-key-glyph`,"data-ink":a,"aria-hidden":"true"},o);for(const o of["main","plain","dashed"]){const a=e.legend[o];i.has(o)&&a&&s(e.text?r(o==="main"?"━━▶":o==="dashed"?"┄┄▷":"──▶",o==="main"?"main":"plain"):le(t,o),a,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length&&(s(le(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(e.text?r("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...xt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),v("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(Et(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(Et(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function dn(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...xt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Ht(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function fn(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},Ht(t,n)))];const s=[];return e.type==="data-flow"?s.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(v("span",{class:`${t}-kind`},n.kind)),s.push(v("span",{class:`${t}-name`},Ht(t,n))),n.detail&&s.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Bt(n.detail).flatMap((i,r)=>[r?" ":"",v("span",{class:`${t}-run`},i)]):n.detail)),s}function un(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},Ht(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((s,i)=>v("span",{class:`${t}-row`,"data-row":i,"data-key":s.key},v("span",{class:`${t}-keyseat`},s.key??""),v("span",{class:`${t}-cname`},s.name),s.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?v("span",{class:`${t}-ctype`},s.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var de=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function _t(t,e,n,s){const{P:i}=t,r=an(e,s)||s.keep===n.id,o=bt(e,s),a=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&a.push(`--_lc:${n.col+1}`),e.type==="sequence"&&a.push(`--_c2:${n.col+1}`);const l=t.plan;if(l&&n.i>0){const g=gt(l.gaps,n.id)??32,x=gt(s.grow,n.id)??0;a.push(`--_gap:${x?`calc(${de(g)} + var(--basalt-space-4) * ${x})`:de(g)}`)}const d=gt(s.heights,n.id);d&&a.push(`--_h:${d}px`);const m=gt(we(e),n.id);m&&a.push(`--_mh:${m}px`);const f=gt(s.words,n.id);f&&a.push(`--_ww:${f}px`);const c=o?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:a.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?Pe(e,n):void 0,tabindex:c},n.shape==="decision"?v("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Pt(n.mark.onLight)};--_md:${Pt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?un(i,n,e):fn(i,e,n))}function hn(t,e,n){const{P:s}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((l,d)=>v("div",{class:`${s}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},v("span",{class:`${s}-lane-name`},l.label)))),e.type==="architecture")for(const l of e.groups){const d=qt(e,l);if(!d)continue;const m=[0,1,2,3].map(f=>ae(e,l,f));i.push(v("div",{class:`${s}-gbox`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:`--_c:${d.c1};--_c2:${d.c2+1};--_r:${d.r1};--_r2:${d.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${s}-glabel`},l.label)))}if(e.text)return[v("pre",{class:`${s}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${s}-text-ink`},pn(s,e)))];if(e.type==="sequence")return i.push(v("ul",{class:`${s}-cast`},e.nodes.map(l=>v("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${l.col}`:void 0},_t(t,e,l,n))))),i.push(gn(t,e)),i;const r=l=>{const d=l.group?e.groups.find(m=>m.id===l.group):void 0;return d?.parent?e.groups.find(m=>m.id===d.parent):d},o=(l,d,m)=>{const f=t.plan?gt(n.grow,d[0].id)??0:0;return v("div",{class:`${s}-group`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:f?`--_ggrow:${f}`:void 0},v("span",{class:`${s}-glabel`,"aria-hidden":"true"},l.label),m)};let a=0;for(;ah.id===m[c].group):void 0;if(!g){f.push(_t(t,e,m[c],n)),c++;continue}const x=[];for(;c_t(t,e,h,n))))}i.push(o(d,m,f))}return i}function pn(t,e){const n=[],s=o=>v("span",{class:`${t}-tx-name`},o),i=o=>o==="main"?"━▶":o==="dashed"?"┄▷":"─▶";n.push(v("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((o,a)=>[a?" · ":"",s(o.name)])),` `);let r=0;for(const o of e.steps){const a=" ".repeat(r);if("band"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"band"},`${a}── ${o.band} ──`),` `);continue}if("open"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},a,v("span",{"data-ink":"op"},`[${o.open}]`),` ${o.label}`),` `),r++;continue}if("otherwise"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"}," ".repeat(r-1),v("span",{"data-ink":"op"},"[else]"),` ${o.otherwise}`),` `);continue}if("close"in o){r=Math.max(0,r-1),n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},`${" ".repeat(r)}[end]`),` -`);continue}const l=e.byId.get(o.from)?.name??o.from,f=e.byId.get(o.to)?.name??o.to;n.push(v("span",{class:`${t}-tx-line`,"data-n":o.n},a,v("span",{"data-ink":"num"},`${o.n} `),s(l)," ",v("span",{"data-ink":o.kind==="main"?"main":"plain"},i(o.kind))," ",s(f)," ",v("span",{"data-ink":"label"},o.label),o.note?[" ",v("span",{"data-ink":"note"},`(${o.note})`)]:null),` -`)}return n}function gn(t,e){const{P:n}=t,s=[],i=[],r=()=>i.length?i[i.length-1].el.c:s;let o=null;for(const a of e.steps){if("band"in a){o=null,r().push(v("p",{class:`${n}-band`},v("span",null,a.band)));continue}if("open"in a){o=null;const d=i[i.length-1],h=d?`;--_fis:${a.a===d.a?1:0};--_fie:${a.b===d.b?1:0}`:"",S=v("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${h}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));r().push(S),i.push({el:S,a:a.a,b:a.b});continue}if("otherwise"in a){o=null,r().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){o=null,i.pop();continue}o||(o=v("ol",{class:`${n}-msgs`,start:a.n}),r().push(o));const l=e.byId.get(a.from),f=e.byId.get(a.to),m=l?.col??1,u=f?.col??1,c=m===u,g=c&&(e.rtl?m!==1:m===e.nodes.length),x=ee(e,a.kind);o.c.push(v("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":c?g?"start":"end":void 0,style:`--_a:${Math.min(m,u)};--_b:${Math.max(m,u)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(a.n)),v("span",{class:`${n}-mlabel`},a.label)),v("span",{class:`${n}-route`},l?.short??a.from," ",dn(n,a.kind),v("span",{class:t.hidden}," to ")," ",f?.short??a.to,x?` · ${x}`:""),a.note?v("span",{class:`${n}-note`},a.note):null))}return v("div",{class:`${n}-steps`},s)}function fe(t,e){return mt(e,`list:${t}`,()=>yn(t,e))}var mn=fe;function yn(t,e){const n=Math.min(6,e.heading+1),s=u=>v(`h${n}`,{class:`${t}-list-head`},u),i=u=>v("strong",null,u),r=u=>u.href?v("a",{href:u.href,target:u.blank?"_blank":void 0,rel:u.blank?"noopener noreferrer":void 0},i(u.name)):i(u.name),o=u=>v("code",{class:`${t}-code`},u),a=u=>e.byId.get(u)?.name??u,l=u=>{const c=ee(e,u);return c?` (${c})`:""},f=u=>u.focal&&e.legend.focal?` ${vt(e.legend.focal)}`:"";if(e.type==="architecture"){const u=x=>v("li",null,r(x),x.kind?`, ${x.kind}`:"",x.detail?[". ",x.mono?o(x.detail):x.detail,/[.!?]$/.test(x.detail)?"":"."]:/[.!?]$/.test(x.kind??x.name)?"":".",f(x)),c=[s("Parts")],g=e.nodes.filter(x=>!x.group);g.length&&c.push(v("ul",{class:`${t}-list-items`},g.map(u)));for(const x of e.groups.filter(d=>d.depth===1)){c.push(v("p",{class:`${t}-list-group`},x.label)),x.members.length&&c.push(v("ul",{class:`${t}-list-items`},x.members.map(d=>u(e.byId.get(d)))));for(const d of e.groups.filter(h=>h.parent===x.id))c.push(v("p",{class:`${t}-list-group`,"data-depth":2},d.label)),c.push(v("ul",{class:`${t}-list-items`,"data-depth":2},d.members.map(h=>u(e.byId.get(h)))))}return c.push(s("Connections")),c.push(v("ol",{class:`${t}-list-items`},e.edges.map(x=>v("li",null,i(a(x.from))," to ",i(a(x.to)),x.label?[": ",o(yt(x.label))]:"",`${l(x.kind)}.`)))),c}if(e.type==="flowchart"){const u=c=>(e.byId.get(c)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(c=>{const g=e.edges.filter(h=>h.from===c.id),x=c.shape==="decision"?"Decision":c.shape==="terminal"?g.length?"Start":"End":"Step",d=!c.detail&&/[.!?]$/.test(c.name)?" ":". ";return v("li",null,r(c),c.detail?[", ",c.mono?o(c.detail):c.detail]:"",`${d}${x}.`,f(c),g.length?v("ul",{class:`${t}-list-exits`},g.map(h=>v("li",null,h.label?`If ${yt(h.label)}: go to ${u(h.to)}, `:`Then: go to ${u(h.to)}, `,i(a(h.to)),l(h.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const c=e.edges.filter(g=>g.from===u.id);return v("li",null,`${u.laneLabel}: `,r(u),u.detail?[", ",u.mono?o(u.detail):u.detail]:"",".",f(u),c.length?[" Then ",...c.flatMap((g,x)=>[x?"; ":"",`to step ${e.byId.get(g.to).step}, `,i(a(g.to)),g.label?[": ",o(yt(g.label))]:"",l(g.kind)]),"."]:"")}))];if(e.type==="sequence"){const u=[s("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(g=>v("li",null,i(g.name),g.kind?`, ${g.kind}`:"",".",f(g),ne(e,g))))];u.push(s("Messages"));let c=null;for(const g of e.steps){if("band"in g){c=null,u.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},g.band));continue}if("open"in g){c=null,u.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords[g.open]}: ${g.label}`));continue}if("otherwise"in g){c=null,u.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords.else}: ${g.otherwise}`));continue}if("close"in g){c=null;continue}c||(c=v("ol",{class:`${t}-list-items`,start:g.n}),u.push(c)),c.c.push(v("li",null,o(g.label),": ",i(a(g.from))," to ",i(a(g.to)),`${l(g.kind)}.`,g.note?` ${vt(g.note)}`:""))}return u}const m=[];for(const u of e.nodes)m.push(v(`h${n}`,{class:`${t}-list-group`},u.href?v("a",{href:u.href,target:u.blank?"_blank":void 0,rel:u.blank?"noopener noreferrer":void 0},o(u.name)):o(u.name),f(u))),m.push(v("ul",{class:`${t}-list-items`},[...(u.columns??[]).map(c=>v("li",null,o(c.name),c.key==="PK"?", primary key":c.key==="FK"?", foreign key":"",c.ref?[", references ",o(`${c.ref.table}.${c.ref.column}`)]:c.type?`, ${c.type}`:"")),...u.more?[v("li",null,`and ${u.more} more ${u.more===1?"column":"columns"}`)]:[]]));return m}function ue(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&_t(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function Dt(t,e=!1){const n=e&&t.type!=="sequence"&&_t(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:oe(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var bn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function _t(t){return mt(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,...$n(t,r)})),n=(r,o)=>{const a=o==="right"||o==="left",l=o==="right"||o==="down",f=x=>a?[x.col,x.col]:x.rows,m=x=>a?x.rows:[x.col,x.col],u=f(r),c=m(r);let g=null;return e.forEach((x,d)=>{if(x===r)return;const h=f(x),S=m(x),j=l?h[0]-u[1]:u[0]-h[1];if(j<1)return;const C=Math.max(0,S[0]-c[1],c[0]-S[1]),E=[C===0?0:1,C===0?j:j+2*C,C,Math.abs(S[0]-c[0]),d];(!g||bn(E,g.rank))&&(g={id:x.id,rank:E})}),g?.id??null},s=ut();for(const r of e)s[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const o=new Set([r]),a=[r];for(;a.length;)for(const l of Object.values(s[a.pop()]))l&&!o.has(l)&&(o.add(l),a.push(l));return o.size};return e.every(r=>i(r.id)===e.length)?s:null})}function At(t){return mt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!Gt(t))return{lane:e,dropped:n,lanes:0};const s=(l,f)=>(t.byId.get(l)?.row??0)*1e3+f,i=new Map;t.edges.forEach((l,f)=>{const m=`${l.to}.${l.toRow}`,u=s(l.from,l.fromRow??0),c=s(l.to,l.toRow??0),g=i.get(m)??{members:[],lo:1/0,hi:-1/0};g.members.push(f),g.lo=Math.min(g.lo,u,c),g.hi=Math.max(g.hi,u,c),i.set(m,g)});const r=[...i.values()].sort((l,f)=>f.hi-f.lo-(l.hi-l.lo)),o=[];let a=0;for(const l of r.reverse()){const f=new Set(o.filter(u=>u.lo<=l.hi&&l.lo<=u.hi).map(u=>u.lane));let m=0;for(;f.has(m);)m++;if(m>1){for(const u of l.members)n.add(u);continue}o.push({lo:l.lo,hi:l.hi,lane:m});for(const u of l.members)e.set(u,m);a=Math.max(a,m+1)}return{lane:e,dropped:n,lanes:a}})}var Gt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Ct(t,e,n){const s=n.prefix,i=sn(n.base),r=t.type==="sequence"||t.type==="schema"?null:ie(t),o={P:s,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},a=e.layout==="drawn",l=bt(t,e),f=t.type==="sequence"||t.type==="schema"?a:!0,m=`h${t.heading}`,u=[`--_cols:${zt(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const c=t.type==="architecture"?se(t):[0,0,0,0],g=(d,h,S)=>d?d>1?`calc(${d} * var(--basalt-space-${h}))`:`var(--basalt-space-${h})`:S?`var(--basalt-space-${S})`:"0px",x=a&&e.pad?"3":void 0;u.push(`--_gpad:${g(c[0],"8",x)} ${g(c[1],"4")} ${g(c[2],"4",x)} ${g(c[3],"4")}`)}return Gt(t)&&u.push(`--_gpad:0px ${At(t).lanes>1?"calc(var(--basalt-space-5) + var(--basalt-space-3))":"var(--basalt-space-5)"} 0px 0px`),t.type==="schema"&&e.track&&u.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":i.title,"data-type":t.type,"data-cols":zt(t),"data-reach":t.type==="architecture"?re(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:u.join(";")},v("div",{class:`${s}-head`},v(m,{id:i.title,class:`${s}-title`},t.title),n.hasSource?v("p",{class:`${s}-source`},{slot:"source"}):null),v("div",{class:`${s}-drawing`,role:f?"group":void 0,"aria-roledescription":f?"diagram":void 0,"aria-labelledby":f?i.title:void 0,"aria-describedby":f?l?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":l?"":void 0},hn(o,t,e),t.text?null:v("div",{class:`${s}-ink`,"aria-hidden":"true"}),v("span",{class:`${s}-ruler`,"aria-hidden":"true"})),ce(s,t),v("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),bt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?v("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${oe(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${s}-foot`},{slot:"toggle"}),v("div",{id:i.list,class:`${s}-list`,hidden:!e.open},fe(s,t)),v("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${ue(t,a)} ${n.viewer}`:ue(t,a)),v("figcaption",{id:i.summary,class:`${s}-summary`},{slot:"summary"}))}function wn(t){const e=getComputedStyle(t),n=(i,r)=>{const o=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(o)?o:r},s=new Map;return{space:i=>(s.has(i)||s.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),s.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Bt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ht=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,he=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:i,r,b:o}=t.rect,a=(s+r)/2,l=(i+o)/2,f=(r-s)/2,m=(o-i)/2,u=e==="top"||e==="bottom";if(t.shape==="decision"){if(u){const x=n,d=m*Math.max(0,1-Math.abs(x-a)/f);return{x,y:e==="top"?l-d:l+d}}const c=n,g=f*Math.max(0,1-Math.abs(c-l)/m);return{x:e==="left"?a-g:a+g,y:c}}if(t.shape==="terminal"){const c=Math.min(f,m);if(u){const h=n,S=Math.min(Math.max(h,s+c),r-c),j=h-S,C=Math.abs(j)>=c?0:Math.sqrt(c*c-j*j);return{x:h,y:Math.abs(j)<1e-6?e==="top"?i:o:e==="top"?l-C:l+C}}const g=n,x=g-l,d=Math.abs(x)>=c?0:Math.sqrt(c*c-x*x);return{x:e==="left"?s+c-d:r-c+d,y:g}}return u?{x:n,y:e==="top"?i:o}:{x:e==="left"?s:r,y:n}}function vn(t,e,n){const{l:s,t:i,r,b:o}=e.rect,a=(s+r)/2,l=(i+o)/2,f=(r-s)/2,m=(o-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/f+Math.abs(t.y-l)/m<1-n/Math.min(f,m);if(e.shape==="terminal"){const u=Math.min(f,m),c=Math.min(Math.max(t.x,s+u),r-u);return Math.hypot(t.x-c,t.y-l)s+n&&t.xi+n&&t.ymatchMedia("(forced-colors: active)").matches;function Mn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(i,r)=>{const o=`${r}|${i}`;return s.has(o)||(n.setAttribute("data-f",r),n.textContent=i,s.set(o,n.getBoundingClientRect().width),n.textContent=""),s.get(o)}}var jt=t=>t?t.split(/\s+/).filter(Boolean):[];function Sn(t,e,n){const s=e.space;let i=e.node,r=e.table;for(const l of t.nodes){if(l.shape==="table"){for(const d of l.columns??[]){const h=d.ref?`${t.rtl?"←":"→"} ${d.ref.table}`:d.type??"",S=s("6")+n(d.name,"mono")+(h?s("3")+n(h,"mono"):0)+2*s("3")+2*e.hair;r=Math.max(r,Math.ceil(S))}r=Math.max(r,Math.ceil(n(l.name,"table")+2*s("3")+2*e.hair+(l.href?16+s("1-5"):0)));continue}const f=l.shape==="terminal"?2*s("5"):2*s("3"),m=l.mark&&!kn()?(l.shape==="participant"?2:1)*s("6"):0;let u=0;const c=l.href?16+s("1-5"):0,g=jt(l.name);if(g.forEach((d,h)=>{u=Math.max(u,n(d,l.shape==="decision"?"name-500":"name")+(l.kind?0:m)+(h===g.length-1?c:0))}),t.type!=="data-flow")for(const d of jt(l.kind))u=Math.max(u,n(d,"mono")+m);for(const d of jt(l.detail))u=Math.max(u,n(d,l.mono?"mono":"sans"));const x=l.shape==="decision"?u/.62:u+f+2*e.hair;i=Math.max(i,Math.ceil(x))}const o=zt(t);let a;return t.type==="data-flow"?a=e.lane+o*(i+s("12")):t.type==="schema"?a=o*r+(o-1)*s("12")+(Gt(t)?s("5")+(At(t).lanes>1?s("3"):0):0):t.type==="sequence"?a=o*i+(o-1)*s("5"):a=o*i+(o-1)*s("16")+re(t)*s("4"),{track:i,table:r,least:Math.max(e.wide,a)}}function ge(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Kt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function me(t,e,n){const s=t.map(r=>({...r}));for(let r=1;r=2){const l=i[i.length-2];if(Math.abs(l.x-a.x)<.01&&Math.abs(a.x-o.x)<.01||Math.abs(l.y-a.y)<.01&&Math.abs(a.y-o.y)<.01){i[i.length-1]=o;continue}}i.push(o)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Tt(t,e,n){const s=[];for(let r=0;rMath.min(d.x,h.x)+.75&&CMath.min(S.y,j.y)+.75&&Ei.split(/\s+/).map(parseFloat).filter(r=>Number.isFinite(r)),s=(i,r,o)=>{const a=[];let l=r;for(const f of i)a.push([l,l+f]),l+=f+o;return a};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var et=t=>t==="left"||t==="right",ye={top:"bottom",bottom:"top",left:"right",right:"left"};function be(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function $e(t,e,n){const s=[];t.edges.forEach((r,o)=>{const a=t.byId.get(r.from),l=t.byId.get(r.to),[f,m]=e[o],u=a.row===l.row&&et(f)&&et(m)&&f===ye[m]||a.col===l.col&&!et(f)&&!et(m)&&f===ye[m];s.push({edge:o,end:"from",node:a,side:f,far:l,straight:u,f:.5},{edge:o,end:"to",node:l,side:m,far:a,straight:u,f:.5})});const i=new Map;for(const r of s){const o=`${r.node.id}.${r.side}`;i.has(o)||i.set(o,[]),i.get(o).push(r)}for(const[r,o]of i){if(o[0].node.shape==="decision")continue;const a=d=>et(d.side)?d.far.row-d.node.row:d.far.col-d.node.col,l=o.filter(d=>d.straight),f=o.filter(d=>!d.straight);if(f.sort((d,h)=>a(d)-a(h)||(et(d.side)?d.far.col-h.far.col:d.far.row-h.far.row)*(a(d)<0?1:-1)),o.length>3&&n(`${r.replace(".","'s ")} side has ${o.length} lines; more than three is an error: use another side`),!l.length){f.length===2?(f[0].f=.25,f[1].f=.75):f.length===3?(f[0].f=.25,f[1].f=.5,f[2].f=.75):f.length>3&&f.forEach((d,h)=>{d.f=(h+1)/(f.length+1)});continue}const m=new Map;for(const d of l)m.has(d.far.id)||m.set(d.far.id,[]),m.get(d.far.id).push(d);for(const d of m.values())d.length>1&&d.sort((h,S)=>h.edge-S.edge).forEach((h,S)=>{h.f=d.length===2?S===0?.25:.75:(S+1)/(d.length+1)});const u=Math.min(...l.map(d=>d.f)),c=Math.max(...l.map(d=>d.f)),g=f.filter(d=>a(d)<0),x=f.filter(d=>a(d)>=0);g.forEach((d,h)=>{d.f=u*(h+1)/(g.length+1)}),x.forEach((d,h)=>{d.f=c+(1-c)*(h+1)/(x.length+1)})}return s}function we(t,e=8,n=8){return mt(t,`port-floors:${e}:${n}`,()=>{const s=ut();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return s;const i=t.edges.map(o=>{const a=t.byId.get(o.from),l=t.byId.get(o.to),[f,m]=be(a,l);return[o.fromSide??f,o.toSide??m]}),r=new Map;for(const o of $e(t,i,()=>{})){if(!et(o.side)||o.node.shape!=="box")continue;const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o.f)}for(const[o,a]of r){if(a.length<2)continue;const l=[...new Set(a.map(u=>Math.round(u*1e6)/1e6))].sort((u,c)=>u-c);let f=Math.max(e/l[0],e/(1-l[l.length-1]));for(let u=1;u{const o=t.byId.get(r.dataset.node);o&&i.set(o.id,{id:o.id,rect:ft(r,n),shape:o.shape,i:o.i})}),i}function ke(t,e){const n=e.head,s=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-s,r:i+s,t:r-n,b:r}:t.dir==="up"?{l:i-s,r:i+s,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-s,b:r+s}:{l:i,r:i+n,t:r-s,b:r+s}}var Me=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Se(t,e,n,s){const i=(r,o)=>{const a=r+o-Math.floor(r+o);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const r of i(t.t,n))for(const o of i(t.l,e)){if(!o&&!r)return t;const a={l:t.l+o,r:t.r+o,t:t.t+r,b:t.b+r};if(s(a))return a}return t}function An(t,e,n,s,i,r,o,a,l){const f=o.space,m=[],u=[],c=[],g=[],x=f("1"),d=e.filter(h=>t.edges[h.i]?.label).sort((h,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[h.i].kind==="main")||h.i-S.i);for(const h of d){const S=t.edges[h.i].label,j=a(S,"label"),C=16*Ft(S),E=h.pts.length-2,A=[];pt(h.pts).forEach(([L,z],I)=>{const M=Math.abs(L.y-z.y)<.01,O=M?L.x:L.y;let F=M?z.x:z.y;const G=Math.sign(F-O)||1;I===E&&(F-=G*o.head);let W=[[O,F]];for(const y of i)for(const b of M?[y.l,y.r]:[y.t,y.b]){const p=M?L.y:L.x;(M?p>y.t&&py.l&&pb>Math.min($,w)+1&&b{const p=(y+b)/2,k=M?{x:p,y:L.y}:{x:L.x,y:p};return!i.some($=>k.x>$.l&&k.x<$.r&&k.y>$.t&&k.y<$.b)},K=h.axes?.[I]??(M?L.y:L.x);for(const[y,b]of W)A.push({horiz:M,c:K,p:y,q:b,len:Math.abs(b-y),pri:W.length>1&&Q(y,b)?1:0})}),A.sort((L,z)=>z.pri-L.pri||z.len-L.len);let T=null,Z=!1;const B=(L,z=!0)=>{const I=he(L,x);return z&&(L.lr.r||L.tr.b)||n.some(M=>pe(I,M))||m.some(M=>ht(I,M))||s.heads.some(M=>ht(I,M))||s.rects.some(M=>ht(I,M))?!1:!e.some(M=>M.i!==h.i&&pt(M.pts).some(([O,F])=>ht(I,Me(O,F,M.width))))};for(const L of A){for(const z of[1/2,1/3,2/3]){const I=L.p+(L.q-L.p)*z,M=[],O=f("2")+h.width/2;if(L.horiz?(L.len>=j+2*f("1")+f("3-5")&&M.push({box:{l:I-j/2-f("1"),r:I+j/2+f("1"),t:L.c-C/2,b:L.c+C/2},on:!0}),M.push({box:{l:I-j/2,r:I+j/2,t:L.c-O-C,b:L.c-O},on:!1}),M.push({box:{l:I-j/2,r:I+j/2,t:L.c+O,b:L.c+O+C},on:!1})):(L.len>=C+f("3")&&M.push({box:{l:L.c-j/2-f("1"),r:L.c+j/2+f("1"),t:I-C/2,b:I+C/2},on:!0}),M.push({box:{l:L.c+O,r:L.c+O+j,t:I-C/2,b:I+C/2},on:!1}),M.push({box:{l:L.c-O-j,r:L.c-O,t:I-C/2,b:I+C/2},on:!1})),T=M.find(F=>B(F.box))??null,T)break;!Z&&M.some(F=>B(F.box,!1))&&(Z=!0)}if(T)break}if(!T){c.push(h.i),Z&&g.push(h.i);continue}const ot=Se(T.box,l.ox,l.oy,L=>B(L));m.push(ot),u.push({i:h.i,text:S,box:ot,on:T.on})}return{labels:u,unseated:c,bounded:g}}function Ee(t,e,n,s){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(o=>{if(o.getClientRects().length===0||getComputedStyle(o).display==="contents")return;const a=ft(o,e);r.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const l=o.querySelector(`:scope > .${n}-glabel`);l&&l.getClientRects().length&&i.push(ft(l,e))}),t.querySelectorAll(`.${n}-lane`).forEach((o,a)=>{if(!o.getClientRects().length)return;const l=ft(o,e);a>0&&i.push({l:l.l,r:l.r,t:l.t-s/2-.5,b:l.t-s/2+.5});const f=o.querySelector(`.${n}-lane-name`);f&&i.push(ft(f,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function Ln(t,e){const{m:s,tk:i,P:r,drawing:o,origin:a,warn:l}=t,f=i.space,m=xe(s,o,a,r),u=[...m.values()],c=En(o),g=a.left-Math.floor(a.left),x=a.top-Math.floor(a.top),d=ge(g,x),h=o.clientWidth,S=o.clientHeight,j=p=>s.type==="data-flow"?p.col+1:p.col,C=parseFloat(getComputedStyle(o).rowGap)||0,E={w:h,h:S,nodes:u,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:g,oy:x};if(s.type==="sequence")return In(t,E,d);let A,T=[];s.type==="schema"?A=s.edges.map(p=>{const k=s.byId.get(p.from),$=s.byId.get(p.to);if(k.col===$.col){const w=k.col===s.cols&&s.cols>1?"left":"right";return[w,w]}return $.col>k.col?["right","left"]:["left","right"]}):(A=s.edges.map(p=>{const k=s.byId.get(p.from),$=s.byId.get(p.to),[w,_]=be(k,$);return[p.fromSide??w,p.toSide??_]}),T=$e(s,A,l||(()=>{})));const Z=(p,k)=>{const $=o.querySelector(`.${r}-node[data-node="${CSS.escape(p)}"] .${r}-row[data-row="${k}"]`);if(!$)return 0;const w=ft($,a);return(w.t+w.b)/2},B=s.edges.map((p,k)=>{const[$,w]=A[k],_=m.get(p.from),q=m.get(p.to),R=Bt(p.kind,i);if(p.fk){const V=Z(p.from,p.fromRow),P=Z(p.to,p.toRow),J=d.y(V,R),nt=d.y(P,R);return{p1:{x:$==="right"?_.rect.r:_.rect.l,y:J},p2:{x:w==="right"?q.rect.r:q.rect.l,y:nt},r1:V,r2:Math.abs(J-nt)<.01?V:P}}const U=T.find(V=>V.edge===k&&V.end==="from").f,Y=T.find(V=>V.edge===k&&V.end==="to").f;let N=ve(_,$,U),D=ve(q,w,Y);const tt=et($)?N.y:N.x;let st=et(w)?D.y:D.x;return et($)?N={...N,y:d.y(N.y,R)}:N={...N,x:d.x(N.x,R)},et(w)?D={...D,y:d.y(D.y,R)}:D={...D,x:d.x(D.x,R)},et($)&&et(w)&&Math.abs(N.y-D.y)<1.01&&(D={...D,y:N.y},st=tt),!et($)&&!et(w)&&Math.abs(N.x-D.x)<1.01&&(D={...D,x:N.x},st=tt),N=et($)?lt(_,$,N.y):lt(_,$,N.x),D=et(w)?lt(q,w,D.y):lt(q,w,D.x),{p1:N,p2:D,r1:tt,r2:st}}),ot=new Set;s.type==="schema"&&s.edges.forEach((p,k)=>{Math.abs(s.byId.get(p.from).col-s.byId.get(p.to).col)>1&&ot.add(k)});for(const p of At(s).dropped)ot.add(p),l?.(`${s.edges[p].from} to ${s.edges[p].to} would need a third lane of turn-backs, so its line is not drawn; its row still writes the target`);const L=new Map,z=new Set;s.edges.forEach((p,k)=>{if(ot.has(k))return;const[$,w]=A[k],{p1:_,p2:q}=B[k],R=s.byId.get(p.from),U=s.byId.get(p.to);let Y=null,N=null,D=!1;if($===w){if(et($)){const V=$==="right"?Math.max(j(R),j(U)):Math.min(j(R),j(U))-1,P=c.cols[V-1],J=c.cols[V];P&&J&&(Y=`c${V}`,N=[P[1],J[0]],D=!0)}else{const V=$==="bottom"?Math.max(R.row2,U.row2):Math.min(R.row,U.row)-1,P=c.rows[V-1],J=c.rows[V];P&&J&&(Y=`r${V}`,N=[P[1],J[0]],D=!1)}Y&&z.add(k)}else if(et($)&&et(w)&&Math.abs(_.y-q.y)>.5){const V=j(U),P=w==="left",J=c.cols[(P?V-1:V)-1],nt=c.cols[(P?V:V+1)-1];J&&nt&&(Y=`c${P?V-1:V}`,N=[J[1],nt[0]],D=!0)}else if(!et($)&&!et(w)&&Math.abs(_.x-q.x)>.5){const P=w==="top"?U.row-1:U.row2,J=c.rows[P-1],nt=c.rows[P];J&&nt&&(Y=`r${P}`,N=[J[1],nt[0]],D=!1)}if(!Y||!N)return;L.has(Y)||L.set(Y,{span:N,vertical:D,members:new Map});const tt=`${p.to}.${w}.${Math.round(D?q.y:q.x)}`,st=L.get(Y);st.members.has(tt)||st.members.set(tt,[]),st.members.get(tt).push(k)});const I=new Map,M=p=>{const[k,$]=A[p],{p1:w,p2:_}=B[p];if(et(k)&&et($)){if(k===$){const R=f("4")+(s.type==="schema"&&s.cols===1?(At(s).lane.get(p)??0)*f("3"):0),U=I.get(p)??(k==="right"?Math.max(w.x,_.x)+R:Math.min(w.x,_.x)-R);return[w,{x:U,y:w.y},{x:U,y:_.y},_]}if(Math.abs(w.y-_.y)<=.5)return[w,{x:_.x,y:w.y}];const q=I.get(p)??(w.x+_.x)/2;return[w,{x:q,y:w.y},{x:q,y:_.y},_]}if(!et(k)&&!et($)){if(k===$){const R=I.get(p)??(k==="bottom"?Math.max(w.y,_.y)+f("4"):Math.min(w.y,_.y)-f("4"));return[w,{x:w.x,y:R},{x:_.x,y:R},_]}if(Math.abs(w.x-_.x)<=.5)return[w,{x:w.x,y:_.y}];const q=I.get(p)??(w.y+_.y)/2;return[w,{x:w.x,y:q},{x:_.x,y:q},_]}return et(k)?[w,{x:_.x,y:w.y},_]:[w,{x:w.x,y:_.y},_]},O=p=>{const k=s.edges[p],$=Bt(k.kind,i),w=M(p),_=me(w,$,d);let q;return w.length===_.length&&(q=pt(w).map(([R,U])=>Math.abs(R.y-U.y)<.75?(R.y+U.y)/2:(R.x+U.x)/2),q[0]=B[p].r1,q.length>1&&(q[q.length-1]=B[p].r2)),{i:p,from:k.from,to:k.to,kind:k.kind,pts:_,tip:_[_.length-1],dir:Kt(_),dot:k.fk?_[0]:void 0,width:$,axes:q}},F=()=>s.edges.flatMap((p,k)=>ot.has(k)?[]:[O(k)]);let G=null;const W=p=>{G??(G=F());const k=G.map($=>p.has($.i)?O($.i):$);return{lines:k,score:qn(k,p)*1e5+Tt(k,void 0,p).length*1e3+Vt(k.filter($=>p.has($.i)),u,s).length}},Q=(p,k)=>{const $=p.flatMap(w=>{const{p1:_,p2:q}=B[w];return k?[_.y,q.y]:[_.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,p]of L){const k=[...p.members.values()].map(w=>({members:w,run:Q(w,p.vertical)})).sort((w,_)=>w.run[0]-_.run[0]),$=[];for(const w of k){const _=$[$.length-1];_&&_.some(q=>q.run[0]z.has(tt)))continue;const _=w.map(tt=>tt.members),q=_.length,R=(p.span[1]-p.span[0])/(q+1);RV.forEach(J=>I.set(J,p.span[0]+R*(P+1))));const st=W(U);st.scorett.forEach(V=>I.set(V,p.span[0]+R*(st+1)))),G=D}}E.lines=F();for(const p of ot)At(s).dropped.has(p)||l?.(`${s.edges[p].from} to ${s.edges[p].to} is two columns apart, so its line is not drawn; its row still writes the target`);E.crossings=Tt(E.lines),E.through=Vt(E.lines,u,s),E.outside=qe(E.lines,h,S,i);const{obstacles:K,groups:y}=Ee(o,a,r,C);K.heads=E.lines.map(p=>ke(p,i));const b=An(s,E.lines,u,K,y,{l:0,t:0,r:h,b:S},i,e,{ox:g,oy:x});return E.labels=b.labels,E.unseated=b.unseated,E.bounded=b.bounded,E.overlaps=[...new Set(Ae(E.lines,null).flat())],E}function qn(t,e){return Ae(t,e).length}function Ae(t,e){const n=[];for(let s=0;s=a)continue;const[h,S]=c?[l.x,f.x]:[l.y,f.y],[j,C]=c?[m.x,u.x]:[m.y,u.y];Math.min(Math.max(h,S),Math.max(j,C))-Math.max(Math.min(h,S),Math.min(j,C))>1&&n.push([r.i,o.i])}}return n}function*Le(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const l=a===r.pts.length-1?Math.max(r.width/2,s.head/2):r.width/2;return o.x-l<-.5||o.x+l>e+.5||o.y-l<-.5||o.y+l>n+.5})&&i.push(r.i);return i}function Vt(t,e,n){const s=[];for(const i of t){const r=pt(i.pts);e.some(o=>r.some(([a,l])=>xn(a,l,o)))&&s.push(i.i)}return s}function In(t,e,n){const{m:s,tk:i,P:r,drawing:o,origin:a}=t,l=i.space,f=new Map;o.querySelectorAll(`.${r}-node`).forEach(E=>f.set(E.dataset.node,ft(E,a)));const m=o.querySelector(`.${r}-steps`),u=m?ft(m,a).b:e.h,c=E=>{const A=f.get(E);return A?n.x((A.l+A.r)/2,i.hair):0};for(const E of s.nodes){const A=f.get(E.id);A&&e.lifelines.push({x:c(E.id),y1:A.b,y2:u})}const g=E=>f.get(E.id),x=new Map;o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=ft(E,a);x.set(Number(E.querySelector(`.${r}-num`)?.textContent??0),(A.t+A.b)/2)});const d=i.activation,h=d/2,S=E=>{const A=s.byId.get(E.who);if(!A)return null;const T=c(E.who),B=(A.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),ot=(E.depth-1)*l("1")*B,L=x.get(E.from)??0,z=x.get(E.to)??L,I=E.from===E.to;return{l:n.x(T-h+ot,i.hair),r:n.x(T+h+ot,i.hair),t:n.y(I?L-l("2")-l("1"):L,i.hair),b:n.y(I?L+l("2")+l("1"):z,i.hair)}},j=s.bars.map(E=>({bar:E,rect:S(E)})).filter(E=>E.rect);e.bars=j.map(E=>E.rect);const C=(E,A,T)=>j.filter(({bar:Z})=>Z.who===E&&Z.to>=A&&(T?Z.from<=A:Z.fromB.bar.depth-Z.bar.depth)[0]?.rect;return o.querySelectorAll(`.${r}-msg`).forEach(E=>{const A=E.dataset.from,T=E.dataset.to,Z=E.dataset.kind??"plain",B=Bt(Z,i),ot=ft(E,a),L=n.y((ot.t+ot.b)/2,B),z=Number(E.querySelector(`.${r}-num`)?.textContent??0);let I=c(A),M=c(T),O;if(A===T){const b=E.dataset.self==="start"?-l("6"):l("6"),p=C(A,z,!0),k=p?b>0?p.r:p.l:I,$=n.y(L-l("2"),B),w=n.y(L+l("2"),B);O=[{x:k,y:$},{x:n.x(I+b,B),y:$},{x:n.x(I+b,B),y:w},{x:k,y:w}]}else{const b=M>I?1:-1,p=C(A,z,!1),k=C(T,z,!0);p&&(I=b>0?p.r:p.l),k&&(M=b>0?k.l:k.r),O=[{x:I,y:L},{x:M,y:L}]}e.lines.push({i:z,from:A,to:T,kind:Z,pts:O,tip:O[O.length-1],dir:Kt(O),width:B});const F=E.querySelector(`.${r}-said`),G=E.querySelector(`.${r}-note`),W=s.byId.get(A),Q=s.byId.get(T);if(!W||!Q)return;const K=A===T?(()=>{const b=s.nodes[W.i+(E.dataset.self==="start"?-1:1)],p=b?c(b.id):E.dataset.self==="start"?0:e.w;return Math.abs(p-I)-l("6")-l("2-5")-l("2")})():Math.abs(M-I)-2*l("2");Math.max(F?F.getBoundingClientRect().width:0,G?G.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(z)}),o.querySelectorAll(`.${r}-fhead`).forEach(E=>{const A=E.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!A)return;[...E.children].reduce((Z,B)=>Z+B.getBoundingClientRect().width,0)+l("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${E.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function Ie(t,e,n,s=ut()){const{m:i,tk:r,P:o,drawing:a,origin:l}=t,f=r.space,m=xe(i,a,l,o),u=[...m.values()],c=l.left-Math.floor(l.left),g=l.top-Math.floor(l.top),x=ge(c,g),d=a.clientWidth,h=a.clientHeight,S={w:d,h,nodes:u,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:g},j=ut();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:j};const C=d-(parseFloat(getComputedStyle(a).paddingRight)||0),E=(M,O,F)=>{const G=[M];for(let W=1;W<=(gt(s,O)??0);W++)G.push({...M,t:M.t+F*f("4")*W,b:M.b+F*f("4")*W});return G},A=new Map;a.querySelectorAll(`.${o}-node`).forEach(M=>{const O=M.parentElement,F=ft(O,l),G=getComputedStyle(O);A.set(M.dataset.node,F.r-(parseFloat(G.paddingRight)||0)-(parseFloat(G.borderRightWidth)||0))});const T=i.nodes,Z=M=>m.get(T[M].id),B=[],ot=M=>Bt(i.edges[M].kind,r);i.edges.forEach((M,O)=>{const F=n.routes[O],G=m.get(M.from),W=m.get(M.to),Q=ot(O);let K=[];const y=M.label,b=y?e(y,"label"):0,p=y?16*Ft(y):16,k=f("4");if(F==="down"||F==="up"){const w=Math.max(G.rect.l,W.rect.l),_=Math.min(G.rect.r,W.rect.r),q=i.edges.map((N,D)=>({o:N,j:D})).filter(({o:N,j:D})=>(n.routes[D]==="down"||n.routes[D]==="up")&&(N.from===M.from&&N.to===M.to||N.from===M.to&&N.to===M.from)),R=q.findIndex(N=>N.j===O),U=q.length<2?.5:q.length===2?R===0?.25:.75:(R+1)/(q.length+1),Y=x.x(w+(_-w)*U,Q);if(K=F==="down"?[lt(G,"bottom",Y),lt(W,"top",Y)]:[lt(G,"top",Y),lt(W,"bottom",Y)],y){let N=Math.min(K[0].y,K[1].y),D=Math.max(K[0].y,K[1].y);F==="down"?D-=r.head:N+=r.head;const tt=[...a.querySelectorAll(`.${o}-group`)].map(J=>ft(J,l));let st=[[N,D]];for(const J of tt)for(const nt of[J.t,J.b])st=st.flatMap(([rt,ct])=>nt>rt+1&&nttt.some(rt=>(J+nt)/2>rt.t&&(J+nt)/2rt.l&&Y1){const J=st.filter(([rt,ct])=>!V(rt,ct));[N,D]=(J.length?J:st).reduce((rt,ct)=>ct[1]-ct[0]>rt[1]-rt[0]?ct:rt)}const P=[1/2,1/3,2/3].map(J=>{const nt=N+(D-N)*J;return{l:Y-b/2-f("1"),r:Y+b/2+f("1"),t:nt-p/2,b:nt+p/2}});B.push({k:O,cands:P,on:!0,card:F==="down"?M.to:M.from})}}else if(F==="trunk"||F==="rail"){const w=x.x(Math.max(G.rect.l,F==="rail"?W.rect.l:G.rect.l)+f(F==="trunk"?"8":"3"),Q),_=lt(G,"bottom",w);if(F==="rail"){if(K=[_,lt(W,"top",w)],y){const q=W.rect.t-f("6");B.push({k:O,cands:E({l:w+f("2-5"),r:w+f("2-5")+b,t:q-p/2,b:q+p/2},M.to,-1),on:!1,card:M.to})}}else{const q=x.x(W.rect.l+f("6"),Q),R=x.y(W.rect.t-k,Q);K=[_,{x:w,y:R},{x:q,y:R},lt(W,"top",q)],y&&B.push({k:O,cands:E({l:q+f("2-5"),r:q+f("2-5")+b,t:R-p/2,b:R+p/2},M.to,-1),on:!1,card:M.to})}}else{const w=Math.min(A.get(M.from)??d,A.get(M.to)??d),_=x.x(n.gutter?C+(n.lanes[O]?2*f("3-5"):f("3-5")):w-f("2-5"),Q),q=x.y(G.rect.t+(G.rect.b-G.rect.t)*n.exits[O],Q),R=lt(G,"right",q),U=x.x(W.rect.r-f("6"),Q),Y=F==="end-down",N=x.y(Y?W.rect.t-k:W.rect.b+k,Q);K=[R,{x:_,y:R.y},{x:_,y:N},{x:U,y:N},lt(W,Y?"top":"bottom",U)];const D=Y?M.to:T[W.i+1]?.id??M.to;y&&B.push({k:O,cands:E({l:U-f("2-5")-b,r:U-f("2-5"),t:N-p/2,b:N+p/2},D,Y?-1:1),on:!1,card:D})}const $=me(K,Q,x);S.lines.push({i:O,from:M.from,to:M.to,kind:M.kind,pts:$,tip:$[$.length-1],dir:Kt($),width:Q})}),S.crossings=Tt(S.lines),S.through=Vt(S.lines,u,i),S.outside=qe(S.lines,d,h,r);const{obstacles:L}=Ee(a,l,o,0);L.heads=S.lines.map(M=>ke(M,r));const z=[],I={l:0,t:0,r:d,b:h};for(const M of B){const O=W=>{const Q=he(W,f("1"));return W.lI.r+.5||W.tI.b+.5||u.some(K=>pe(Q,K))||z.some(K=>ht(Q,K))||L.heads.some(K=>ht(Q,K))||L.rects.some(K=>ht(Q,K))||S.lines.some(K=>K.i!==M.k&&pt(K.pts).some(([y,b])=>ht(Q,Me(y,b,K.width))))},F=M.cands.find(W=>!O(W));F||(j[M.card]=(j[M.card]??0)+1,S.unseated.push(M.k));const G=F?Se(F,c,g,W=>!O(W)):M.cands[0];z.push(G),S.labels.push({i:M.k,text:i.edges[M.k].label,box:G,on:M.on})}return{geo:S,grow:j}}function On(t,e){const n=r=>String(Math.round(r*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let r=1;r({...E})),u=m[m.length-1];u.x-=r.x*f,u.y-=r.y*f;const c=e.tip.x-r.x*a,g=e.tip.y-r.y*a,x=-r.y*l,d=r.x*l,h=E=>Math.round(E*100)/100,S=it(e.kind),j=o?``:``,C=e.dot?``:"";return`${j}${C}`}function Oe(t,e,n,s){const i=new Map,r=new Map;for(const a of e.crossings)r.has(a.under)||r.set(a.under,[]),r.get(a.under).push(a);let o="";for(const[a,l]of r){const f=`${s}-cut-${a}`;i.set(a,f);const m=l.map(u=>{const c=e.lines[u.top],g=e.lines[u.under],x=c.width/2+n.cut,d=g.width/2+1;return u.underVertical?``:``}).join("");o+=`${m}`}return{defs:o,ids:i}}function _e(t,e,n,s){const{defs:i,ids:r}=Oe(t,e,n,s),o=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),a=e.lines.map((m,u)=>Cn(t,m,n,r.get(u)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),l=`${i?`${i}`:""}${o}${a}`,f=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` -`).map(it).join("
")}
`).join("");return l+f}function Zt(t,e,n,s,i,r,o,a){const f=t.querySelector(`.${n}-drawing`);if(!f||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const m=wn(t),u=Mn(f,n),c=Sn(e,m,u);a?.(c.least);const g=t.clientWidth,x=(()=>{const L=document.activeElement;return L&&f.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),d=L=>bt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:x&&L.layout!=="drawn"?x:void 0};let h=!1;const S=L=>{if(h=!1,e.type!=="flowchart")return L;r({...L,heights:void 0,words:void 0});const z=ut(),I=ut();return f.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const O=M.querySelector(`.${n}-words`);if(!O)return;const F=M.getBoundingClientRect(),G=K=>{const y={w:K.width+2*m.space("2-5"),h:K.height+2*m.space("2")},b=1-y.w/F.width,p=b>.05?y.h/2/b:y.h*10;return Math.max(m.space("16"),Math.ceil(F.width/5),Math.ceil(2*p))},W=O.getBoundingClientRect();let Q=G(W);if(Q>F.width){const K=k=>(M.style.setProperty("--_ww",`${k}px`),O.getBoundingClientRect()),y=Math.floor(M.clientWidth-2*m.space("2-5"));let b=Math.ceil(W.width),p=W.height;for(;b1;){const q=k+$>>1;K(q).heightF.width&&(h=!0)}),{...L,heights:z,words:Object.keys(I).length?I:void 0}},j=()=>({m:e,tk:m,P:n,drawing:f,origin:f.getBoundingClientRect(),warn:o}),C=i.autoOpen?{open:!1,autoOpen:void 0}:{},E=(L,z)=>z.map(I=>Lt(e,L.lines.find(M=>M.i===I))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:m,least:c.least};if(g>=c.least&&!e.unplaced){const L=O=>{let F=d({...i,...C,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return F=S(F),r(F),{dd:F,g:Ln(j(),u)}};let{dd:z,g:I}=L(!1);const M=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||h;if(!M(I)&&I.unseated.length&&I.unseated.every(O=>I.bounded?.includes(O))){const O=L(!0);!M(O.g)&&!O.g.unseated.length&&({dd:z,g:I}=O)}if(!M(I)&&!I.unseated.length)return I.crossings.length&&o?.(`${I.crossings.length} crossing${I.crossings.length===1?"":"s"} in the drawn layout: ${I.crossings.map(O=>`${Lt(e,I.lines[O.top])} over ${Lt(e,I.lines[O.under])}`).join("; ")}`),{dyn:z,geo:I,ink:_e(n,I,m,s),tokens:m,least:c.least};h&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: a decision would be taller than it is wide`),I.misfit?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${I.misfit.join("; ")}`),I.through.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.through)} would pass through a node`),I.overlaps?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.overlaps)} would lie on one another`),I.outside.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${E(I,I.outside)} would leave the drawing`),I.unseated.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: no clean seat for ${I.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=d({...i,...C,layout:"stacked",heights:void 0,grow:ut(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(A=S(A),r(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:m,least:c.least};const T=ie(e);let Z=Ie(j(),u,T,A.grow);for(let L=0;L<6&&Object.keys(Z.grow).length;L++){const z=ut(A.grow);for(const[I,M]of Object.entries(Z.grow))z[I]=(gt(z,I)??0)+M;A={...A,grow:z},r(A),Z=Ie(j(),u,T,z)}const B=Z.geo;if(B.unseated.length>0||B.through.length>0||B.outside.length>0||T.third){B.unseated.length&&o?.(`the stacked drawing has no clean seat for ${[...new Set(B.unseated)].map(I=>`"${e.edges[I]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),B.through.length&&o?.(`in the stacked drawing ${E(B,B.through)} would pass through a node, so its lines are not drawn`),B.outside.length&&o?.(`in the stacked drawing ${E(B,B.outside)} would leave the drawing, so its lines are not drawn`),T.third&&o?.("the stacked drawing would need a third end lane, so its lines are not drawn");const L={...B,lines:[],labels:[],crossings:[]};return{dyn:d({...A,grow:ut(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:m,least:c.least}}return B.crossings.length&&o?.(`${B.crossings.length} crossing${B.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${B.crossings.map(L=>`${Lt(e,B.lines[L.top])} over ${Lt(e,B.lines[L.under])}`).join("; ")}`),{dyn:A,geo:B,ink:_e(n,B,m,s),tokens:m,least:c.least}}function Lt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function Bn(t,e,n,s,i,r){const o=new Set;if(r){o.add(r);for(const d of n?.lines??[])d.from===r&&o.add(d.to),d.to===r&&o.add(d.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(d=>d.toggleAttribute("data-near",o.has(d.dataset.node))),!n||!s)return;const a=d=>!!r&&(d.from===r||d.to===r),l=t.querySelector(`.${e}-edges`),f=new Map;t.querySelectorAll(`.${e}-edge`).forEach(d=>f.set(d.getAttribute("data-edge"),d));for(const d of n.lines){const h=f.get(String(d.i));h&&(h.toggleAttribute("data-lit",a(d)),h.toggleAttribute("data-dim",!!r&&!a(d)))}if(t.querySelectorAll(`.${e}-label`).forEach(d=>{const h=n.lines.find(S=>String(S.i)===d.dataset.edge);d.toggleAttribute("data-lit",!!(h&&a(h)))}),l){for(const d of n.lines)if(a(d)){const h=f.get(String(d.i));h&&l.appendChild(h)}}const m=Tt(n.lines,a),{defs:u,ids:c}=Oe(e,{...n,crossings:m},s,i),g=t.querySelector(`.${e}-svg`);if(!g)return;let x=g.querySelector("defs");!x&&u&&(x=document.createElementNS("http://www.w3.org/2000/svg","defs"),g.insertBefore(x,g.firstChild)),x&&(x.innerHTML=u),n.lines.forEach((d,h)=>{const S=f.get(String(d.i))?.querySelector(`.${e}-line`);if(!S)return;const j=c.get(h);j?S.setAttribute("mask",`url(#${j})`):S.removeAttribute("mask")})}var jn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Tn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",jn()||Wn(t)?"done":"pending")}}var Rn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Wn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Rn(t))!==null}catch{return!1}}function Ce(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Fn(t,e,n,s=!1,i=!1){const r=s?_t(t):null;if(r&&n.startsWith("Arrow")){const f={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return f?r[e]?.[f]??null:null}const o=t.byId.get(e)?.i??0,a=t.nodes.length;let l;if(n==="ArrowRight"||n==="ArrowDown")l=o+1;else if(n==="ArrowLeft"||n==="ArrowUp")l=o-1;else if(n==="Home")l=0;else if(n==="End")l=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,l))].id}var Nn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Be=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],zn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad"],je=t=>t==null||t===!1;function Hn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Rt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?Be:Nn;for(const o of s)je(e.a[o])&&t.removeAttribute(o);for(const[o,a]of Object.entries(e.a)){if(o==="class")continue;if(o==="style"){const f=t.style,m=new Map(String(a??"").split(";").map(u=>{const c=u.indexOf(":");return[u.slice(0,c).trim(),u.slice(c+1).trim()]}).filter(([u])=>u));for(const[u,c]of m)f.getPropertyValue(u).trim()!==c&&f.setProperty(u,c);for(const u of zn)m.has(u)||f.removeProperty(u);continue}if(n&&!Be.includes(o))continue;if(je(a)){t.removeAttribute(o);continue}const l=a===!0?"":String(a);t.getAttribute(o)!==l&&t.setAttribute(o,l)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(o=>typeof o!="string"&&"slot"in o))return;const i=[...t.children];let r=0;for(const o of e.c)if(!(typeof o=="string"||"slot"in o)){for(let a=r;at.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function i(c,g,x){return{prefix:n,base:c,hasSource:g.source!==void 0&&g.source!==null&&g.source!=="",hiddenClass:"visually-hidden",viewer:x?x.keys:void 0}}function r(c,g,x,d){var h=function(S){return''+it(S)+""};return{source:it(String(g.source||"")),summary:it(String(g.summary||"")),hint:Dt(c).map(function(S){return""+S.keys.map(h).join(" ")+" "+it(S.words)+""}).join(""),toggle:'"}}function o(c,g,x){var d=wt(c),h=Ct(d,{},i(g,c,x)),S=Nt(h,r(d,c,g,!1)),j=S.indexOf(">");return{open:S.slice(0,j+1),inner:S.slice(j+1,S.length-9),warnings:d.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],l=["--_cols","--_gpad","--_track"];function f(c,g,x,d){c.__diagram&&c.__diagram.stop();var h=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(c).direction==="rtl",j=g.layout==="auto"&&(g.type==="architecture"||g.type==="flowchart"||g.type==="schema"),C=j?Array.isArray(g.placement)?g.placement:g.placement?[g.placement]:[]:[];j&&!C.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var E=g.direction?[g.direction]:g.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var X=0;X .diagram-drawing")){if(!h||!c.querySelector("#"+CSS.escape(h+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););h="dg"+s}var Z=o(g,h,d),B=document.createElement("div");B.innerHTML=Z.open+"";var ot=B.firstChild;a.forEach(function(H){c.removeAttribute(H)}),l.forEach(function(H){c.style.removeProperty(H)});for(var L=0;L :not(script[data-diagram])").forEach(function(H){H.remove()}),c.insertAdjacentHTML("beforeend",Z.inner)}T.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var I=i(h,g,d),M={},O=null,F=null,G=null,W=null,Q=Object.create(null),K=function(H){Q[H]||(Q[H]=1,console.warn("Basalt diagram: "+H))},y=function(H){Rt(c,Ct(T,H,I))},b=c.querySelector(".diagram-ink"),p=c.querySelector(".diagram-toggle"),k=!d&&T.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,_=function(){k&&Ce(c)};function q(){Bn(c,n,O&&O.geo,O&&O.tokens,h,F||W||G),Y()}var R=null,U=!d&&matchMedia("(hover: none), (pointer: coarse)").matches;function Y(){var H=U&&!d&&b&&b.innerHTML!=="";if(c.toggleAttribute("data-touch",!!(U&&!d)),H&&!R){var X=c.querySelector(":scope > .diagram-foot");if(!X)return;R=document.createElement("button"),R.type="button",R.className="btn diagram-clear",R.setAttribute("data-variant","secondary"),R.setAttribute("data-size","sm"),R.innerHTML="Clear highlight",R.addEventListener("click",function(){W&&(W=null,q())}),X.appendChild(R)}else!H&&R&&(R.remove(),R=null);R&&(W?R.removeAttribute("aria-disabled"):R.setAttribute("aria-disabled","true"))}function N(H){if(!H.defaultPrevented){var X=en(c,n,H,W);X!==void 0&&(_(),U=!0,W=X,q())}}function D(){p&&(p.setAttribute("aria-expanded",String(!!M.open)),p.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function tt(){if(j&&C.length>1&&!d){for(var H=null,X=0;X1&&d&&!g.direction&&d.room){for(var He=d.room(),De=-1,Jt=null,Xt=0;XtDe+1e-6&&(De=Ke,Jt=Yt)}}}Jt&&(T=Jt)}O=(d?d.measure:Zt)(c,T,n,h,M,y,K),M=O.dyn,y(M),D();var Qt=c.querySelector(":scope > .diagram-hint");if(Qt){var Ve=Dt(T,M.layout==="drawn").map(function(St){return""+St.keys.map(function(Zn){return''+it(Zn)+""}).join(" ")+" "+it(St.words)+""}).join("");Qt.innerHTML!==Ve&&(Qt.innerHTML=Ve)}bt(T,M)||(G=W=null);var Ze=b&&O.ink!==w;Ze&&(b.innerHTML=O.ink,w=O.ink),q(),k&&O.tokens&&(Tn(c,!!(O.geo&&O.geo.lines.length)),Ze&&$&&$.redrawn()),d&&d.onMeasured&&O.tokens&&d.onMeasured(O,c),T.text&&typeof e.diagramText=="function"&&e.diagramText(c,T,g)}function st(H){M=H,y(M)}function V(H){var X=M.stop;M=Object.assign({},M,{stop:H}),Dn(c,n,X,H)}var P=function(H){var X=H&&H.closest?H.closest(".diagram-node"):null;return X&&c.contains(X)?X:null};function J(H){var X=P(H.target);if(!(!X||H.defaultPrevented)){if(_(),H.key==="Escape"){!d&&(F||G||W)&&(H.preventDefault(),F=G=W=null,q());return}if(bt(T,M)){var dt=Fn(T,X.getAttribute("data-node"),H.key,M.layout==="drawn");if(dt){H.preventDefault(),V(dt);var Mt=c.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');Mt&&Mt.focus()}}}}function nt(H){var X=P(H.target);if(X){_();var dt=X.getAttribute("data-node");F=X.matches(":focus-visible")?dt:null,bt(T,M)&&M.stop!==dt&&V(dt),q()}}function rt(H){var X=P(H.target);X&&(P(H.relatedTarget)||(F=null),M.keep===X.getAttribute("data-node")&&st(Object.assign({},M,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var X=P(H.target);X&&_();var dt=X&&bt(T,M)?X.getAttribute("data-node"):null;dt!==G&&(G=dt,q())}}function qt(){G&&(G=null,q())}function $t(){_(),st(Object.assign({},M,{open:!M.open,autoOpen:void 0})),D()}c.addEventListener("keydown",J),c.addEventListener("focusin",nt),c.addEventListener("focusout",rt),c.addEventListener("pointerover",ct),c.addEventListener("pointerleave",qt),c.addEventListener("click",N),p&&p.addEventListener("click",$t),tt();var kt=c.clientWidth,Ut=0,Te=!0,Re=new ResizeObserver(function(){Math.abs(c.clientWidth-kt)<.5||(kt=c.clientWidth,cancelAnimationFrame(Ut),Ut=requestAnimationFrame(tt))});Re.observe(c),document.fonts&&document.fonts.ready.then(function(){Te&&tt()});var We=matchMedia("(forced-colors: active)"),Fe=T.nodes.some(function(H){return H.mark});Fe&&We.addEventListener("change",tt),k&&($=e.diagramMotion(c,{fig:c,P:n,base:h,model:function(){return T},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},g));var Ne=!d&&g.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,g,{model:T,settle:_,animated:k}):null,ze=c.querySelector(":scope > .diagram-foot"),Gn=!d&&g.export===!0&&ze&&typeof e.diagramExport=="function"?e.diagramExport(ze,c):[];c.__diagram={stop:function(){Ne&&Ne.destroy(),Gn.forEach(function(H){H.remove()}),Te=!1,Re.disconnect(),cancelAnimationFrame(Ut),Fe&&We.removeEventListener("change",tt),$&&$.destroy(),c.removeEventListener("keydown",J),c.removeEventListener("focusin",nt),c.removeEventListener("focusout",rt),c.removeEventListener("pointerover",ct),c.removeEventListener("pointerleave",qt),c.removeEventListener("click",N),R&&R.remove(),p&&p.removeEventListener("click",$t)},layout:tt,key:m(g),send:$&&$.sendValue?$.sendValue:null}}function m(c){try{return JSON.stringify(c,function(g,x){return g==="packet"&&x&&typeof x=="object"?Object.assign({},x,{send:void 0}):x})}catch{return null}}function u(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var g=c.querySelector(":scope > script[data-diagram]");if(g)try{f(c,JSON.parse(g.textContent),!0)}catch(x){console.error("Basalt diagram: this figure could not be drawn",x)}}})}e.diagramMarkup=o,e.diagramKit={draw:f,buildModel:wt,figureKey:ln,figureList:mn,hintEntries:Dt,toHtml:Nt,escapeHtml:it,settleEntrance:Ce,measureFigure:Zt},t.diagram=function(c,g){var x=c.__diagram,d=x&&x.send?m(g):null;if(d!==null&&d===x.key){x.send(g.packet?g.packet.send:void 0);return}f(c,g)},e.step(62,"wireDiagrams",u)})(window.Basalt)})(); +`);continue}const l=e.byId.get(o.from)?.name??o.from,d=e.byId.get(o.to)?.name??o.to;n.push(v("span",{class:`${t}-tx-line`,"data-n":o.n},a,v("span",{"data-ink":"num"},`${o.n} `),s(l)," ",v("span",{"data-ink":o.kind==="main"?"main":"plain"},i(o.kind))," ",s(d)," ",v("span",{"data-ink":"label"},o.label),o.note?[" ",v("span",{"data-ink":"note"},`(${o.note})`)]:null),` +`)}return n}function gn(t,e){const{P:n}=t,s=[],i=[],r=()=>i.length?i[i.length-1].el.c:s;let o=null;for(const a of e.steps){if("band"in a){o=null,r().push(v("p",{class:`${n}-band`},v("span",null,a.band)));continue}if("open"in a){o=null;const h=i[i.length-1],u=h?`;--_fis:${a.a===h.a?1:0};--_fie:${a.b===h.b?1:0}`:"",S=v("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${u}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));r().push(S),i.push({el:S,a:a.a,b:a.b});continue}if("otherwise"in a){o=null,r().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){o=null,i.pop();continue}o||(o=v("ol",{class:`${n}-msgs`,start:a.n}),r().push(o));const l=e.byId.get(a.from),d=e.byId.get(a.to),m=l?.col??1,f=d?.col??1,c=m===f,g=c&&(e.rtl?m!==1:m===e.nodes.length),x=ee(e,a.kind);o.c.push(v("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":c?g?"start":"end":void 0,style:`--_a:${Math.min(m,f)};--_b:${Math.max(m,f)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(a.n)),v("span",{class:`${n}-mlabel`},a.label)),v("span",{class:`${n}-route`},l?.short??a.from," ",dn(n,a.kind),v("span",{class:t.hidden}," to ")," ",d?.short??a.to,x?` · ${x}`:""),a.note?v("span",{class:`${n}-note`},a.note):null))}return v("div",{class:`${n}-steps`},s)}function fe(t,e){return mt(e,`list:${t}`,()=>yn(t,e))}var mn=fe;function yn(t,e){const n=Math.min(6,e.heading+1),s=f=>v(`h${n}`,{class:`${t}-list-head`},f),i=f=>v("strong",null,f),r=f=>f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},i(f.name)):i(f.name),o=f=>v("code",{class:`${t}-code`},f),a=f=>e.byId.get(f)?.name??f,l=f=>{const c=ee(e,f);return c?` (${c})`:""},d=f=>f.focal&&e.legend.focal?` ${vt(e.legend.focal)}`:"";if(e.type==="architecture"){const f=x=>v("li",null,r(x),x.kind?`, ${x.kind}`:"",x.detail?[". ",x.mono?o(x.detail):x.detail,/[.!?]$/.test(x.detail)?"":"."]:/[.!?]$/.test(x.kind??x.name)?"":".",d(x)),c=[s("Parts")],g=e.nodes.filter(x=>!x.group);g.length&&c.push(v("ul",{class:`${t}-list-items`},g.map(f)));for(const x of e.groups.filter(h=>h.depth===1)){c.push(v("p",{class:`${t}-list-group`},x.label)),x.members.length&&c.push(v("ul",{class:`${t}-list-items`},x.members.map(h=>f(e.byId.get(h)))));for(const h of e.groups.filter(u=>u.parent===x.id))c.push(v("p",{class:`${t}-list-group`,"data-depth":2},h.label)),c.push(v("ul",{class:`${t}-list-items`,"data-depth":2},h.members.map(u=>f(e.byId.get(u)))))}return c.push(s("Connections")),c.push(v("ol",{class:`${t}-list-items`},e.edges.map(x=>v("li",null,i(a(x.from))," to ",i(a(x.to)),x.label?[": ",o(yt(x.label))]:"",`${l(x.kind)}.`)))),c}if(e.type==="flowchart"){const f=c=>(e.byId.get(c)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(c=>{const g=e.edges.filter(u=>u.from===c.id),x=c.shape==="decision"?"Decision":c.shape==="terminal"?g.length?"Start":"End":"Step",h=!c.detail&&/[.!?]$/.test(c.name)?" ":". ";return v("li",null,r(c),c.detail?[", ",c.mono?o(c.detail):c.detail]:"",`${h}${x}.`,d(c),g.length?v("ul",{class:`${t}-list-exits`},g.map(u=>v("li",null,u.label?`If ${yt(u.label)}: go to ${f(u.to)}, `:`Then: go to ${f(u.to)}, `,i(a(u.to)),l(u.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const c=e.edges.filter(g=>g.from===f.id);return v("li",null,`${f.laneLabel}: `,r(f),f.detail?[", ",f.mono?o(f.detail):f.detail]:"",".",d(f),c.length?[" Then ",...c.flatMap((g,x)=>[x?"; ":"",`to step ${e.byId.get(g.to).step}, `,i(a(g.to)),g.label?[": ",o(yt(g.label))]:"",l(g.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[s("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(g=>v("li",null,i(g.name),g.kind?`, ${g.kind}`:"",".",d(g),ne(e,g))))];f.push(s("Messages"));let c=null;for(const g of e.steps){if("band"in g){c=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},g.band));continue}if("open"in g){c=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords[g.open]}: ${g.label}`));continue}if("otherwise"in g){c=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords.else}: ${g.otherwise}`));continue}if("close"in g){c=null;continue}c||(c=v("ol",{class:`${t}-list-items`,start:g.n}),f.push(c)),c.c.push(v("li",null,o(g.label),": ",i(a(g.from))," to ",i(a(g.to)),`${l(g.kind)}.`,g.note?` ${vt(g.note)}`:""))}return f}const m=[];for(const f of e.nodes)m.push(v(`h${n}`,{class:`${t}-list-group`},f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},o(f.name)):o(f.name),d(f))),m.push(v("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(c=>v("li",null,o(c.name),c.key==="PK"?", primary key":c.key==="FK"?", foreign key":"",c.ref?[", references ",o(`${c.ref.table}.${c.ref.column}`)]:c.type?`, ${c.type}`:"")),...f.more?[v("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return m}function ue(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Ot(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function Dt(t,e=!1){const n=e&&t.type!=="sequence"&&Ot(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:oe(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var bn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Ot(t){return mt(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,...$n(t,r)})),n=(r,o)=>{const a=o==="right"||o==="left",l=o==="right"||o==="down",d=x=>a?[x.col,x.col]:x.rows,m=x=>a?x.rows:[x.col,x.col],f=d(r),c=m(r);let g=null;return e.forEach((x,h)=>{if(x===r)return;const u=d(x),S=m(x),I=l?u[0]-f[1]:f[0]-u[1];if(I<1)return;const T=Math.max(0,S[0]-c[1],c[0]-S[1]),M=[T===0?0:1,T===0?I:I+2*T,T,Math.abs(S[0]-c[0]),h];(!g||bn(M,g.rank))&&(g={id:x.id,rank:M})}),g?.id??null},s=ut();for(const r of e)s[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const o=new Set([r]),a=[r];for(;a.length;)for(const l of Object.values(s[a.pop()]))l&&!o.has(l)&&(o.add(l),a.push(l));return o.size};return e.every(r=>i(r.id)===e.length)?s:null})}function At(t){return mt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!Gt(t))return{lane:e,dropped:n,lanes:0};const s=(l,d)=>(t.byId.get(l)?.row??0)*1e3+d,i=new Map;t.edges.forEach((l,d)=>{const m=`${l.to}.${l.toRow}`,f=s(l.from,l.fromRow??0),c=s(l.to,l.toRow??0),g=i.get(m)??{members:[],lo:1/0,hi:-1/0};g.members.push(d),g.lo=Math.min(g.lo,f,c),g.hi=Math.max(g.hi,f,c),i.set(m,g)});const r=[...i.values()].sort((l,d)=>d.hi-d.lo-(l.hi-l.lo)),o=[];let a=0;for(const l of r.reverse()){const d=new Set(o.filter(f=>f.lo<=l.hi&&l.lo<=f.hi).map(f=>f.lane));let m=0;for(;d.has(m);)m++;if(m>1){for(const f of l.members)n.add(f);continue}o.push({lo:l.lo,hi:l.hi,lane:m});for(const f of l.members)e.set(f,m);a=Math.max(a,m+1)}return{lane:e,dropped:n,lanes:a}})}var Gt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Ct(t,e,n){const s=n.prefix,i=sn(n.base),r=t.type==="sequence"||t.type==="schema"?null:ie(t),o={P:s,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},a=e.layout==="drawn",l=bt(t,e),d=t.type==="sequence"||t.type==="schema"?a:!0,m=`h${t.heading}`,f=[`--_cols:${zt(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const c=t.type==="architecture"?se(t):[0,0,0,0],g=(h,u,S)=>h?h>1?`calc(${h} * var(--basalt-space-${u}))`:`var(--basalt-space-${u})`:S?`var(--basalt-space-${S})`:"0px",x=a&&e.pad?"3":void 0;f.push(`--_gpad:${g(c[0],"8",x)} ${g(c[1],"4")} ${g(c[2],"4",x)} ${g(c[3],"4")}`)}return r?.gutter&&r.laneCount>2&&f.push(`--_gw:calc(${r.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),Gt(t)&&f.push(`--_gpad:0px ${At(t).lanes>1?"calc(var(--basalt-space-5) + var(--basalt-space-3))":"var(--basalt-space-5)"} 0px 0px`),t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":i.title,"data-type":t.type,"data-cols":zt(t),"data-reach":t.type==="architecture"?re(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:f.join(";")},v("div",{class:`${s}-head`},v(m,{id:i.title,class:`${s}-title`},t.title),n.hasSource?v("p",{class:`${s}-source`},{slot:"source"}):null),v("div",{class:`${s}-drawing`,role:d?"group":void 0,"aria-roledescription":d?"diagram":void 0,"aria-labelledby":d?i.title:void 0,"aria-describedby":d?l?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":l?"":void 0},hn(o,t,e),t.text?null:v("div",{class:`${s}-ink`,"aria-hidden":"true"}),v("span",{class:`${s}-ruler`,"aria-hidden":"true"})),ce(s,t),v("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),bt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?v("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${oe(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${s}-foot`},{slot:"toggle"}),v("div",{id:i.list,class:`${s}-list`,hidden:!e.open},fe(s,t)),v("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${ue(t,a)} ${n.viewer}`:ue(t,a)),v("figcaption",{id:i.summary,class:`${s}-summary`},{slot:"summary"}))}function wn(t){const e=getComputedStyle(t),n=(i,r)=>{const o=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(o)?o:r},s=new Map;return{space:i=>(s.has(i)||s.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),s.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var jt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ht=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,he=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:i,r,b:o}=t.rect,a=(s+r)/2,l=(i+o)/2,d=(r-s)/2,m=(o-i)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const x=n,h=m*Math.max(0,1-Math.abs(x-a)/d);return{x,y:e==="top"?l-h:l+h}}const c=n,g=d*Math.max(0,1-Math.abs(c-l)/m);return{x:e==="left"?a-g:a+g,y:c}}if(t.shape==="terminal"){const c=Math.min(d,m);if(f){const u=n,S=Math.min(Math.max(u,s+c),r-c),I=u-S,T=Math.abs(I)>=c?0:Math.sqrt(c*c-I*I);return{x:u,y:Math.abs(I)<1e-6?e==="top"?i:o:e==="top"?l-T:l+T}}const g=n,x=g-l,h=Math.abs(x)>=c?0:Math.sqrt(c*c-x*x);return{x:e==="left"?s+c-h:r-c+h,y:g}}return f?{x:n,y:e==="top"?i:o}:{x:e==="left"?s:r,y:n}}function vn(t,e,n){const{l:s,t:i,r,b:o}=e.rect,a=(s+r)/2,l=(i+o)/2,d=(r-s)/2,m=(o-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/d+Math.abs(t.y-l)/m<1-n/Math.min(d,m);if(e.shape==="terminal"){const f=Math.min(d,m),c=Math.min(Math.max(t.x,s+f),r-f);return Math.hypot(t.x-c,t.y-l)s+n&&t.xi+n&&t.ymatchMedia("(forced-colors: active)").matches;function Mn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(i,r)=>{const o=`${r}|${i}`;return s.has(o)||(n.setAttribute("data-f",r),n.textContent=i,s.set(o,n.getBoundingClientRect().width),n.textContent=""),s.get(o)}}var Bt=t=>t?t.split(/\s+/).filter(Boolean):[];function Sn(t,e,n){const s=e.space;let i=e.node,r=e.table;for(const l of t.nodes){if(l.shape==="table"){for(const h of l.columns??[]){const u=h.ref?`${t.rtl?"←":"→"} ${h.ref.table}`:h.type??"",S=s("6")+n(h.name,"mono")+(u?s("3")+n(u,"mono"):0)+2*s("3")+2*e.hair;r=Math.max(r,Math.ceil(S))}r=Math.max(r,Math.ceil(n(l.name,"table")+2*s("3")+2*e.hair+(l.href?16+s("1-5"):0)));continue}const d=l.shape==="terminal"?2*s("5"):2*s("3"),m=l.mark&&!kn()?(l.shape==="participant"?2:1)*s("6"):0;let f=0;const c=l.href?16+s("1-5"):0,g=Bt(l.name);if(g.forEach((h,u)=>{f=Math.max(f,n(h,l.shape==="decision"?"name-500":"name")+(l.kind?0:m)+(u===g.length-1?c:0))}),t.type!=="data-flow")for(const h of Bt(l.kind))f=Math.max(f,n(h,"mono")+m);for(const h of Bt(l.detail))f=Math.max(f,n(h,l.mono?"mono":"sans"));const x=l.shape==="decision"?f/.62:f+d+2*e.hair;i=Math.max(i,Math.ceil(x))}const o=zt(t);let a;return t.type==="data-flow"?a=e.lane+o*(i+s("12")):t.type==="schema"?a=o*r+(o-1)*s("12")+(Gt(t)?s("5")+(At(t).lanes>1?s("3"):0):0):t.type==="sequence"?a=o*i+(o-1)*s("5"):a=o*i+(o-1)*s("16")+re(t)*s("4"),{track:i,table:r,least:Math.max(e.wide,a)}}function ge(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Kt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function me(t,e,n){const s=t.map(r=>({...r}));for(let r=1;r=2){const l=i[i.length-2];if(Math.abs(l.x-a.x)<.01&&Math.abs(a.x-o.x)<.01||Math.abs(l.y-a.y)<.01&&Math.abs(a.y-o.y)<.01){i[i.length-1]=o;continue}}i.push(o)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Tt(t,e,n){const s=[];for(let r=0;rMath.min(h.x,u.x)+.75&&TMath.min(S.y,I.y)+.75&&Mi.split(/\s+/).map(parseFloat).filter(r=>Number.isFinite(r)),s=(i,r,o)=>{const a=[];let l=r;for(const d of i)a.push([l,l+d]),l+=d+o;return a};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var st=t=>t==="left"||t==="right",ye={top:"bottom",bottom:"top",left:"right",right:"left"};function be(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function $e(t,e,n){const s=[];t.edges.forEach((r,o)=>{const a=t.byId.get(r.from),l=t.byId.get(r.to),[d,m]=e[o],f=a.row===l.row&&st(d)&&st(m)&&d===ye[m]||a.col===l.col&&!st(d)&&!st(m)&&d===ye[m];s.push({edge:o,end:"from",node:a,side:d,far:l,straight:f,f:.5},{edge:o,end:"to",node:l,side:m,far:a,straight:f,f:.5})});const i=new Map;for(const r of s){const o=`${r.node.id}.${r.side}`;i.has(o)||i.set(o,[]),i.get(o).push(r)}for(const[r,o]of i){if(o[0].node.shape==="decision")continue;const a=h=>st(h.side)?h.far.row-h.node.row:h.far.col-h.node.col,l=o.filter(h=>h.straight),d=o.filter(h=>!h.straight);if(d.sort((h,u)=>a(h)-a(u)||(st(h.side)?h.far.col-u.far.col:h.far.row-u.far.row)*(a(h)<0?1:-1)),o.length>3&&n(`${r.replace(".","'s ")} side has ${o.length} lines; more than three is an error: use another side`),!l.length){d.length===2?(d[0].f=.25,d[1].f=.75):d.length===3?(d[0].f=.25,d[1].f=.5,d[2].f=.75):d.length>3&&d.forEach((h,u)=>{h.f=(u+1)/(d.length+1)});continue}const m=new Map;for(const h of l)m.has(h.far.id)||m.set(h.far.id,[]),m.get(h.far.id).push(h);for(const h of m.values())h.length>1&&h.sort((u,S)=>u.edge-S.edge).forEach((u,S)=>{u.f=h.length===2?S===0?.25:.75:(S+1)/(h.length+1)});const f=Math.min(...l.map(h=>h.f)),c=Math.max(...l.map(h=>h.f)),g=d.filter(h=>a(h)<0),x=d.filter(h=>a(h)>=0);g.forEach((h,u)=>{h.f=f*(u+1)/(g.length+1)}),x.forEach((h,u)=>{h.f=c+(1-c)*(u+1)/(x.length+1)})}return s}function we(t,e=8,n=8){return mt(t,`port-floors:${e}:${n}`,()=>{const s=ut();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return s;const i=t.edges.map(o=>{const a=t.byId.get(o.from),l=t.byId.get(o.to),[d,m]=be(a,l);return[o.fromSide??d,o.toSide??m]}),r=new Map;for(const o of $e(t,i,()=>{})){if(!st(o.side)||o.node.shape!=="box")continue;const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o.f)}for(const[o,a]of r){if(a.length<2)continue;const l=[...new Set(a.map(f=>Math.round(f*1e6)/1e6))].sort((f,c)=>f-c);let d=Math.max(e/l[0],e/(1-l[l.length-1]));for(let f=1;f{const o=t.byId.get(r.dataset.node);o&&i.set(o.id,{id:o.id,rect:ft(r,n),shape:o.shape,i:o.i})}),i}function ke(t,e){const n=e.head,s=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-s,r:i+s,t:r-n,b:r}:t.dir==="up"?{l:i-s,r:i+s,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-s,b:r+s}:{l:i,r:i+n,t:r-s,b:r+s}}var Me=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Se(t,e,n,s){const i=(r,o)=>{const a=r+o-Math.floor(r+o);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const r of i(t.t,n))for(const o of i(t.l,e)){if(!o&&!r)return t;const a={l:t.l+o,r:t.r+o,t:t.t+r,b:t.b+r};if(s(a))return a}return t}function An(t,e,n,s,i,r,o,a,l){const d=o.space,m=[],f=[],c=[],g=[],x=d("1"),h=e.filter(u=>t.edges[u.i]?.label).sort((u,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[u.i].kind==="main")||u.i-S.i);for(const u of h){const S=t.edges[u.i].label,I=a(S,"label"),T=16*Ft(S),M=u.pts.length-2,A=[];pt(u.pts).forEach(([L,N],_)=>{const E=Math.abs(L.y-N.y)<.01,O=E?L.x:L.y;let R=E?N.x:N.y;const D=Math.sign(R-O)||1;_===M&&(R-=D*o.head);let W=[[O,R]];for(const y of i)for(const b of E?[y.l,y.r]:[y.t,y.b]){const p=E?L.y:L.x;(E?p>y.t&&py.l&&pb>Math.min($,w)+1&&b{const p=(y+b)/2,k=E?{x:p,y:L.y}:{x:L.x,y:p};return!i.some($=>k.x>$.l&&k.x<$.r&&k.y>$.t&&k.y<$.b)},K=u.axes?.[_]??(E?L.y:L.x);for(const[y,b]of W)A.push({horiz:E,c:K,p:y,q:b,len:Math.abs(b-y),pri:W.length>1&&tt(y,b)?1:0})}),A.sort((L,N)=>N.pri-L.pri||N.len-L.len);let B=null,J=!1;const j=(L,N=!0)=>{const _=he(L,x);return N&&(L.lr.r||L.tr.b)||n.some(E=>pe(_,E))||m.some(E=>ht(_,E))||s.heads.some(E=>ht(_,E))||s.rects.some(E=>ht(_,E))?!1:!e.some(E=>E.i!==u.i&&pt(E.pts).some(([O,R])=>ht(_,Me(O,R,E.width))))};for(const L of A){for(const N of[1/2,1/3,2/3]){const _=L.p+(L.q-L.p)*N,E=[],O=d("2")+u.width/2;if(L.horiz?(L.len>=I+2*d("1")+d("3-5")&&E.push({box:{l:_-I/2-d("1"),r:_+I/2+d("1"),t:L.c-T/2,b:L.c+T/2},on:!0}),E.push({box:{l:_-I/2,r:_+I/2,t:L.c-O-T,b:L.c-O},on:!1}),E.push({box:{l:_-I/2,r:_+I/2,t:L.c+O,b:L.c+O+T},on:!1})):(L.len>=T+d("3")&&E.push({box:{l:L.c-I/2-d("1"),r:L.c+I/2+d("1"),t:_-T/2,b:_+T/2},on:!0}),E.push({box:{l:L.c+O,r:L.c+O+I,t:_-T/2,b:_+T/2},on:!1}),E.push({box:{l:L.c-O-I,r:L.c-O,t:_-T/2,b:_+T/2},on:!1})),B=E.find(R=>j(R.box))??null,B)break;!J&&E.some(R=>j(R.box,!1))&&(J=!0)}if(B)break}if(!B){c.push(u.i),J&&g.push(u.i);continue}const Q=Se(B.box,l.ox,l.oy,L=>j(L));m.push(Q),f.push({i:u.i,text:S,box:Q,on:B.on})}return{labels:f,unseated:c,bounded:g}}function Ee(t,e,n,s){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(o=>{if(o.getClientRects().length===0||getComputedStyle(o).display==="contents")return;const a=ft(o,e);r.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const l=o.querySelector(`:scope > .${n}-glabel`);l&&l.getClientRects().length&&i.push(ft(l,e))}),t.querySelectorAll(`.${n}-lane`).forEach((o,a)=>{if(!o.getClientRects().length)return;const l=ft(o,e);a>0&&i.push({l:l.l,r:l.r,t:l.t-s/2-.5,b:l.t-s/2+.5});const d=o.querySelector(`.${n}-lane-name`);d&&i.push(ft(d,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function Ln(t,e){const{m:s,tk:i,P:r,drawing:o,origin:a,warn:l}=t,d=i.space,m=xe(s,o,a,r),f=[...m.values()],c=En(o),g=a.left-Math.floor(a.left),x=a.top-Math.floor(a.top),h=ge(g,x),u=o.clientWidth,S=o.clientHeight,I=p=>s.type==="data-flow"?p.col+1:p.col,T=parseFloat(getComputedStyle(o).rowGap)||0,M={w:u,h:S,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:g,oy:x};if(s.type==="sequence")return qn(t,M,h);let A,B=[];s.type==="schema"?A=s.edges.map(p=>{const k=s.byId.get(p.from),$=s.byId.get(p.to);if(k.col===$.col){const w=k.col===s.cols&&s.cols>1?"left":"right";return[w,w]}return $.col>k.col?["right","left"]:["left","right"]}):(A=s.edges.map(p=>{const k=s.byId.get(p.from),$=s.byId.get(p.to),[w,C]=be(k,$);return[p.fromSide??w,p.toSide??C]}),B=$e(s,A,l||(()=>{})));const J=(p,k)=>{const $=o.querySelector(`.${r}-node[data-node="${CSS.escape(p)}"] .${r}-row[data-row="${k}"]`);if(!$)return 0;const w=ft($,a);return(w.t+w.b)/2},j=s.edges.map((p,k)=>{const[$,w]=A[k],C=m.get(p.from),q=m.get(p.to),F=jt(p.kind,i);if(p.fk){const V=J(p.from,p.fromRow),P=J(p.to,p.toRow),Z=h.y(V,F),U=h.y(P,F);return{p1:{x:$==="right"?C.rect.r:C.rect.l,y:Z},p2:{x:w==="right"?q.rect.r:q.rect.l,y:U},r1:V,r2:Math.abs(Z-U)<.01?V:P}}const X=B.find(V=>V.edge===k&&V.end==="from").f,nt=B.find(V=>V.edge===k&&V.end==="to").f;let z=ve(C,$,X),G=ve(q,w,nt);const et=st($)?z.y:z.x;let ot=st(w)?G.y:G.x;return st($)?z={...z,y:h.y(z.y,F)}:z={...z,x:h.x(z.x,F)},st(w)?G={...G,y:h.y(G.y,F)}:G={...G,x:h.x(G.x,F)},st($)&&st(w)&&Math.abs(z.y-G.y)<1.01&&(G={...G,y:z.y},ot=et),!st($)&&!st(w)&&Math.abs(z.x-G.x)<1.01&&(G={...G,x:z.x},ot=et),z=st($)?lt(C,$,z.y):lt(C,$,z.x),G=st(w)?lt(q,w,G.y):lt(q,w,G.x),{p1:z,p2:G,r1:et,r2:ot}}),Q=new Set;s.type==="schema"&&s.edges.forEach((p,k)=>{Math.abs(s.byId.get(p.from).col-s.byId.get(p.to).col)>1&&Q.add(k)});for(const p of At(s).dropped)Q.add(p),l?.(`${s.edges[p].from} to ${s.edges[p].to} would need a third lane of turn-backs, so its line is not drawn; its row still writes the target`);const L=new Map,N=new Set;s.edges.forEach((p,k)=>{if(Q.has(k))return;const[$,w]=A[k],{p1:C,p2:q}=j[k],F=s.byId.get(p.from),X=s.byId.get(p.to);let nt=null,z=null,G=!1;if($===w){if(st($)){const V=$==="right"?Math.max(I(F),I(X)):Math.min(I(F),I(X))-1,P=c.cols[V-1],Z=c.cols[V];P&&Z&&(nt=`c${V}`,z=[P[1],Z[0]],G=!0)}else{const V=$==="bottom"?Math.max(F.row2,X.row2):Math.min(F.row,X.row)-1,P=c.rows[V-1],Z=c.rows[V];P&&Z&&(nt=`r${V}`,z=[P[1],Z[0]],G=!1)}nt&&N.add(k)}else if(st($)&&st(w)&&Math.abs(C.y-q.y)>.5){const V=I(X),P=w==="left",Z=c.cols[(P?V-1:V)-1],U=c.cols[(P?V:V+1)-1];Z&&U&&(nt=`c${P?V-1:V}`,z=[Z[1],U[0]],G=!0)}else if(!st($)&&!st(w)&&Math.abs(C.x-q.x)>.5){const P=w==="top"?X.row-1:X.row2,Z=c.rows[P-1],U=c.rows[P];Z&&U&&(nt=`r${P}`,z=[Z[1],U[0]],G=!1)}if(!nt||!z)return;L.has(nt)||L.set(nt,{span:z,vertical:G,members:new Map});const et=`${p.to}.${w}.${Math.round(G?q.y:q.x)}`,ot=L.get(nt);ot.members.has(et)||ot.members.set(et,[]),ot.members.get(et).push(k)});const _=new Map,E=p=>{const[k,$]=A[p],{p1:w,p2:C}=j[p];if(st(k)&&st($)){if(k===$){const F=d("4")+(s.type==="schema"&&s.cols===1?(At(s).lane.get(p)??0)*d("3"):0),X=_.get(p)??(k==="right"?Math.max(w.x,C.x)+F:Math.min(w.x,C.x)-F);return[w,{x:X,y:w.y},{x:X,y:C.y},C]}if(Math.abs(w.y-C.y)<=.5)return[w,{x:C.x,y:w.y}];const q=_.get(p)??(w.x+C.x)/2;return[w,{x:q,y:w.y},{x:q,y:C.y},C]}if(!st(k)&&!st($)){if(k===$){const F=_.get(p)??(k==="bottom"?Math.max(w.y,C.y)+d("4"):Math.min(w.y,C.y)-d("4"));return[w,{x:w.x,y:F},{x:C.x,y:F},C]}if(Math.abs(w.x-C.x)<=.5)return[w,{x:w.x,y:C.y}];const q=_.get(p)??(w.y+C.y)/2;return[w,{x:w.x,y:q},{x:C.x,y:q},C]}return st(k)?[w,{x:C.x,y:w.y},C]:[w,{x:w.x,y:C.y},C]},O=p=>{const k=s.edges[p],$=jt(k.kind,i),w=E(p),C=me(w,$,h);let q;return w.length===C.length&&(q=pt(w).map(([F,X])=>Math.abs(F.y-X.y)<.75?(F.y+X.y)/2:(F.x+X.x)/2),q[0]=j[p].r1,q.length>1&&(q[q.length-1]=j[p].r2)),{i:p,from:k.from,to:k.to,kind:k.kind,pts:C,tip:C[C.length-1],dir:Kt(C),dot:k.fk?C[0]:void 0,width:$,axes:q}},R=()=>s.edges.flatMap((p,k)=>Q.has(k)?[]:[O(k)]);let D=null;const W=p=>{D??(D=R());const k=D.map($=>p.has($.i)?O($.i):$);return{lines:k,score:In(k,p)*1e5+Tt(k,void 0,p).length*1e3+Vt(k.filter($=>p.has($.i)),f,s).length}},tt=(p,k)=>{const $=p.flatMap(w=>{const{p1:C,p2:q}=j[w];return k?[C.y,q.y]:[C.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,p]of L){const k=[...p.members.values()].map(w=>({members:w,run:tt(w,p.vertical)})).sort((w,C)=>w.run[0]-C.run[0]),$=[];for(const w of k){const C=$[$.length-1];C&&C.some(q=>q.run[0]N.has(et)))continue;const C=w.map(et=>et.members),q=C.length,F=(p.span[1]-p.span[0])/(q+1);FV.forEach(Z=>_.set(Z,p.span[0]+F*(P+1))));const ot=W(X);ot.scoreet.forEach(V=>_.set(V,p.span[0]+F*(ot+1)))),D=G}}M.lines=R();for(const p of Q)At(s).dropped.has(p)||l?.(`${s.edges[p].from} to ${s.edges[p].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=Tt(M.lines),M.through=Vt(M.lines,f,s),M.outside=Ie(M.lines,u,S,i);const{obstacles:K,groups:y}=Ee(o,a,r,T);K.heads=M.lines.map(p=>ke(p,i));const b=An(s,M.lines,f,K,y,{l:0,t:0,r:u,b:S},i,e,{ox:g,oy:x});return M.labels=b.labels,M.unseated=b.unseated,M.bounded=b.bounded,M.overlaps=[...new Set(Ae(M.lines,null).flat())],M}function In(t,e){return Ae(t,e).length}function Ae(t,e){const n=[];for(let s=0;s=a)continue;const[u,S]=c?[l.x,d.x]:[l.y,d.y],[I,T]=c?[m.x,f.x]:[m.y,f.y];Math.min(Math.max(u,S),Math.max(I,T))-Math.max(Math.min(u,S),Math.min(I,T))>1&&n.push([r.i,o.i])}}return n}function*Le(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const l=a===r.pts.length-1?Math.max(r.width/2,s.head/2):r.width/2;return o.x-l<-.5||o.x+l>e+.5||o.y-l<-.5||o.y+l>n+.5})&&i.push(r.i);return i}function Vt(t,e,n){const s=[];for(const i of t){const r=pt(i.pts);e.some(o=>r.some(([a,l])=>xn(a,l,o)))&&s.push(i.i)}return s}function qn(t,e,n){const{m:s,tk:i,P:r,drawing:o,origin:a}=t,l=i.space,d=new Map;o.querySelectorAll(`.${r}-node`).forEach(M=>d.set(M.dataset.node,ft(M,a)));const m=o.querySelector(`.${r}-steps`),f=m?ft(m,a).b:e.h,c=M=>{const A=d.get(M);return A?n.x((A.l+A.r)/2,i.hair):0};for(const M of s.nodes){const A=d.get(M.id);A&&e.lifelines.push({x:c(M.id),y1:A.b,y2:f})}const g=M=>d.get(M.id),x=new Map;o.querySelectorAll(`.${r}-msg`).forEach(M=>{const A=ft(M,a);x.set(Number(M.querySelector(`.${r}-num`)?.textContent??0),(A.t+A.b)/2)});const h=i.activation,u=h/2,S=M=>{const A=s.byId.get(M.who);if(!A)return null;const B=c(M.who),j=(A.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),Q=(M.depth-1)*l("1")*j,L=x.get(M.from)??0,N=x.get(M.to)??L,_=M.from===M.to;return{l:n.x(B-u+Q,i.hair),r:n.x(B+u+Q,i.hair),t:n.y(_?L-l("2")-l("1"):L,i.hair),b:n.y(_?L+l("2")+l("1"):N,i.hair)}},I=s.bars.map(M=>({bar:M,rect:S(M)})).filter(M=>M.rect);e.bars=I.map(M=>M.rect);const T=(M,A,B)=>I.filter(({bar:J})=>J.who===M&&J.to>=A&&(B?J.from<=A:J.fromj.bar.depth-J.bar.depth)[0]?.rect;return o.querySelectorAll(`.${r}-msg`).forEach(M=>{const A=M.dataset.from,B=M.dataset.to,J=M.dataset.kind??"plain",j=jt(J,i),Q=ft(M,a),L=n.y((Q.t+Q.b)/2,j),N=Number(M.querySelector(`.${r}-num`)?.textContent??0);let _=c(A),E=c(B),O;if(A===B){const b=M.dataset.self==="start"?-l("6"):l("6"),p=T(A,N,!0),k=p?b>0?p.r:p.l:_,$=n.y(L-l("2"),j),w=n.y(L+l("2"),j);O=[{x:k,y:$},{x:n.x(_+b,j),y:$},{x:n.x(_+b,j),y:w},{x:k,y:w}]}else{const b=E>_?1:-1,p=T(A,N,!1),k=T(B,N,!0);p&&(_=b>0?p.r:p.l),k&&(E=b>0?k.l:k.r),O=[{x:_,y:L},{x:E,y:L}]}e.lines.push({i:N,from:A,to:B,kind:J,pts:O,tip:O[O.length-1],dir:Kt(O),width:j});const R=M.querySelector(`.${r}-said`),D=M.querySelector(`.${r}-note`),W=s.byId.get(A),tt=s.byId.get(B);if(!W||!tt)return;const K=A===B?(()=>{const b=s.nodes[W.i+(M.dataset.self==="start"?-1:1)],p=b?c(b.id):M.dataset.self==="start"?0:e.w;return Math.abs(p-_)-l("6")-l("2-5")-l("2")})():Math.abs(E-_)-2*l("2");Math.max(R?R.getBoundingClientRect().width:0,D?D.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(N)}),o.querySelectorAll(`.${r}-fhead`).forEach(M=>{const A=M.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!A)return;[...M.children].reduce((J,j)=>J+j.getBoundingClientRect().width,0)+l("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function qe(t,e,n,s=ut()){const{m:i,tk:r,P:o,drawing:a,origin:l}=t,d=r.space,m=xe(i,a,l,o),f=[...m.values()],c=l.left-Math.floor(l.left),g=l.top-Math.floor(l.top),x=ge(c,g),h=a.clientWidth,u=a.clientHeight,S={w:h,h:u,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:g},I=ut();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:I};const T=h-(parseFloat(getComputedStyle(a).paddingRight)||0),M=(E,O,R)=>{const D=[E];for(let W=1;W<=(gt(s,O)??0);W++)D.push({...E,t:E.t+R*d("4")*W,b:E.b+R*d("4")*W});return D},A=new Map;a.querySelectorAll(`.${o}-node`).forEach(E=>{const O=E.parentElement,R=ft(O,l),D=getComputedStyle(O);A.set(E.dataset.node,R.r-(parseFloat(D.paddingRight)||0)-(parseFloat(D.borderRightWidth)||0))});const B=i.nodes,J=E=>m.get(B[E].id),j=[],Q=E=>jt(i.edges[E].kind,r);i.edges.forEach((E,O)=>{const R=n.routes[O],D=m.get(E.from),W=m.get(E.to),tt=Q(O);let K=[];const y=E.label,b=y?e(y,"label"):0,p=y?16*Ft(y):16,k=d("4");if(R==="down"||R==="up"){const w=Math.max(D.rect.l,W.rect.l),C=Math.min(D.rect.r,W.rect.r),q=i.edges.map((z,G)=>({o:z,j:G})).filter(({o:z,j:G})=>(n.routes[G]==="down"||n.routes[G]==="up")&&(z.from===E.from&&z.to===E.to||z.from===E.to&&z.to===E.from)),F=q.findIndex(z=>z.j===O),X=q.length<2?.5:q.length===2?F===0?.25:.75:(F+1)/(q.length+1),nt=x.x(w+(C-w)*X,tt);if(K=R==="down"?[lt(D,"bottom",nt),lt(W,"top",nt)]:[lt(D,"top",nt),lt(W,"bottom",nt)],y){let z=Math.min(K[0].y,K[1].y),G=Math.max(K[0].y,K[1].y);R==="down"?G-=r.head:z+=r.head;const et=[...a.querySelectorAll(`.${o}-group`)].map(Z=>ft(Z,l));let ot=[[z,G]];for(const Z of et)for(const U of[Z.t,Z.b])ot=ot.flatMap(([at,ct])=>U>at+1&&Uet.some(at=>(Z+U)/2>at.t&&(Z+U)/2at.l&&nt1){const Z=ot.filter(([at,ct])=>!V(at,ct));[z,G]=(Z.length?Z:ot).reduce((at,ct)=>ct[1]-ct[0]>at[1]-at[0]?ct:at)}const P=[1/2,1/3,2/3].map(Z=>{const U=z+(G-z)*Z;return{l:nt-b/2-d("1"),r:nt+b/2+d("1"),t:U-p/2,b:U+p/2}});j.push({k:O,cands:P,on:!0,card:R==="down"?E.to:E.from})}}else if(R==="trunk"||R==="rail"){const w=x.x(Math.max(D.rect.l,R==="rail"?W.rect.l:D.rect.l)+d(R==="trunk"?"8":"3"),tt),C=lt(D,"bottom",w);if(R==="rail"){if(K=[C,lt(W,"top",w)],y){const q=W.rect.t-d("6");j.push({k:O,cands:M({l:w+d("2-5"),r:w+d("2-5")+b,t:q-p/2,b:q+p/2},E.to,-1),on:!1,card:E.to})}}else{const q=x.x(W.rect.l+d("6"),tt),F=x.y(W.rect.t-k,tt);K=[C,{x:w,y:F},{x:q,y:F},lt(W,"top",q)],y&&j.push({k:O,cands:M({l:q+d("2-5"),r:q+d("2-5")+b,t:F-p/2,b:F+p/2},E.to,-1),on:!1,card:E.to})}}else{const w=Math.min(A.get(E.from)??h,A.get(E.to)??h),C=x.x(n.gutter?T+(n.lanes[O]+1)*d("3-5"):w-d("2-5"),tt),q=x.y(D.rect.t+(D.rect.b-D.rect.t)*n.exits[O],tt),F=lt(D,"right",q),X=R==="end-down",nt=i.edges.map((U,at)=>({o:U,j:at})).filter(({o:U,j:at})=>n.routes[at]===R&&U.to===E.to).sort((U,at)=>n.lanes[at.j]-n.lanes[U.j]||U.j-at.j),z=Math.max(0,nt.findIndex(({j:U})=>U===O)),G=W.rect.r-d("6")-z*d("3"),et=W.rect.r-d("6")-(nt.length-1)*d("3"),ot=x.x(G,tt),V=X?W.rect.t-k-z*d("5"):W.rect.b+k+z*d("5"),P=x.y(V,tt);K=[F,{x:C,y:F.y},{x:C,y:P},{x:ot,y:P},lt(W,X?"top":"bottom",ot)];const Z=X?E.to:B[W.i+1]?.id??E.to;y&&j.push({k:O,cands:M({l:et-d("2-5")-b,r:et-d("2-5"),t:V-p/2,b:V+p/2},Z,X?-1:1),on:!1,card:Z})}const $=me(K,tt,x);S.lines.push({i:O,from:E.from,to:E.to,kind:E.kind,pts:$,tip:$[$.length-1],dir:Kt($),width:tt})}),S.crossings=Tt(S.lines),S.through=Vt(S.lines,f,i),S.outside=Ie(S.lines,h,u,r);const{obstacles:L}=Ee(a,l,o,0);L.heads=S.lines.map(E=>ke(E,r));const N=[],_={l:0,t:0,r:h,b:u};for(const E of j){const O=W=>{const tt=he(W,d("1"));return W.l<_.l-.5||W.r>_.r+.5||W.t<_.t-.5||W.b>_.b+.5||f.some(K=>pe(tt,K))||N.some(K=>ht(tt,K))||L.heads.some(K=>ht(tt,K))||L.rects.some(K=>ht(tt,K))||S.lines.some(K=>K.i!==E.k&&pt(K.pts).some(([y,b])=>ht(tt,Me(y,b,K.width))))},R=E.cands.find(W=>!O(W));R||(I[E.card]=(I[E.card]??0)+1,S.unseated.push(E.k));const D=R?Se(R,c,g,W=>!O(W)):E.cands[0];N.push(D),S.labels.push({i:E.k,text:i.edges[E.k].label,box:D,on:E.on})}return{geo:S,grow:I}}function _n(t,e){const n=r=>String(Math.round(r*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let r=1;r({...M})),f=m[m.length-1];f.x-=r.x*d,f.y-=r.y*d;const c=e.tip.x-r.x*a,g=e.tip.y-r.y*a,x=-r.y*l,h=r.x*l,u=M=>Math.round(M*100)/100,S=it(e.kind),I=o?``:``,T=e.dot?``:"";return`${I}${T}`}function _e(t,e,n,s){const i=new Map,r=new Map;for(const a of e.crossings)r.has(a.under)||r.set(a.under,[]),r.get(a.under).push(a);let o="";for(const[a,l]of r){const d=`${s}-cut-${a}`;i.set(a,d);const m=l.map(f=>{const c=e.lines[f.top],g=e.lines[f.under],x=c.width/2+n.cut,h=g.width/2+1;return f.underVertical?``:``}).join("");o+=`${m}`}return{defs:o,ids:i}}function Oe(t,e,n,s){const{defs:i,ids:r}=_e(t,e,n,s),o=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),a=e.lines.map((m,f)=>Cn(t,m,n,r.get(f)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),l=`${i?`${i}`:""}${o}${a}`,d=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` +`).map(it).join("
")}
`).join("");return l+d}function Zt(t,e,n,s,i,r,o,a){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const m=wn(t),f=Mn(d,n),c=Sn(e,m,f);a?.(c.least);const g=t.clientWidth,x=(()=>{const L=document.activeElement;return L&&d.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),h=L=>bt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:x&&L.layout!=="drawn"?x:void 0};let u=!1;const S=L=>{if(u=!1,e.type!=="flowchart")return L;r({...L,heights:void 0,words:void 0});const N=ut(),_=ut();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(E=>{const O=E.querySelector(`.${n}-words`);if(!O)return;const R=E.getBoundingClientRect(),D=K=>{const y={w:K.width+2*m.space("2-5"),h:K.height+2*m.space("2")},b=1-y.w/R.width,p=b>.05?y.h/2/b:y.h*10;return Math.max(m.space("16"),Math.ceil(R.width/5),Math.ceil(2*p))},W=O.getBoundingClientRect();let tt=D(W);if(tt>R.width){const K=k=>(E.style.setProperty("--_ww",`${k}px`),O.getBoundingClientRect()),y=Math.floor(E.clientWidth-2*m.space("2-5"));let b=Math.ceil(W.width),p=W.height;for(;b1;){const q=k+$>>1;K(q).heightR.width&&(u=!0)}),{...L,heights:N,words:Object.keys(_).length?_:void 0}},I=()=>({m:e,tk:m,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:o}),T=i.autoOpen?{open:!1,autoOpen:void 0}:{},M=(L,N)=>N.map(_=>Lt(e,L.lines.find(E=>E.i===_))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:m,least:c.least};if(g>=c.least&&!e.unplaced){const L=O=>{let R=h({...i,...T,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return R=S(R),r(R),{dd:R,g:Ln(I(),f)}};let{dd:N,g:_}=L(!1);const E=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||u;if(!E(_)&&_.unseated.length&&_.unseated.every(O=>_.bounded?.includes(O))){const O=L(!0);!E(O.g)&&!O.g.unseated.length&&({dd:N,g:_}=O)}if(!E(_)&&!_.unseated.length)return _.crossings.length&&o?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the drawn layout: ${_.crossings.map(O=>`${Lt(e,_.lines[O.top])} over ${Lt(e,_.lines[O.under])}`).join("; ")}`),{dyn:N,geo:_,ink:Oe(n,_,m,s),tokens:m,least:c.least};u&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: a decision would be taller than it is wide`),_.misfit?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${_.misfit.join("; ")}`),_.through.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${M(_,_.through)} would pass through a node`),_.overlaps?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${M(_,_.overlaps)} would lie on one another`),_.outside.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${M(_,_.outside)} would leave the drawing`),_.unseated.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: no clean seat for ${_.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=h({...i,...T,layout:"stacked",heights:void 0,grow:ut(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(A=S(A),r(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:m,least:c.least};const B=ie(e);let J=qe(I(),f,B,A.grow);for(let L=0;L<6&&Object.keys(J.grow).length;L++){const N=ut(A.grow);for(const[_,E]of Object.entries(J.grow))N[_]=(gt(N,_)??0)+E;A={...A,grow:N},r(A),J=qe(I(),f,B,N)}const j=J.geo;if(!B.third&&B.laneCount>2&&o?.(`the stacked drawing uses ${B.laneCount} end lanes (four at most)`),j.unseated.length>0||j.through.length>0||j.outside.length>0||B.third){j.unseated.length&&o?.(`the stacked drawing has no clean seat for ${[...new Set(j.unseated)].map(_=>`"${e.edges[_]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),j.through.length&&o?.(`in the stacked drawing ${M(j,j.through)} would pass through a node, so its lines are not drawn`),j.outside.length&&o?.(`in the stacked drawing ${M(j,j.outside)} would leave the drawing, so its lines are not drawn`),B.third&&o?.("the stacked drawing would need a fifth end lane, so its lines are not drawn");const L={...j,lines:[],labels:[],crossings:[]};return{dyn:h({...A,grow:ut(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:m,least:c.least}}return j.crossings.length&&o?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${j.crossings.map(L=>`${Lt(e,j.lines[L.top])} over ${Lt(e,j.lines[L.under])}`).join("; ")}`),{dyn:A,geo:j,ink:Oe(n,j,m,s),tokens:m,least:c.least}}function Lt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function jn(t,e,n,s,i,r){const o=new Set;if(r){o.add(r);for(const h of n?.lines??[])h.from===r&&o.add(h.to),h.to===r&&o.add(h.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(h=>h.toggleAttribute("data-near",o.has(h.dataset.node))),!n||!s)return;const a=h=>!!r&&(h.from===r||h.to===r),l=t.querySelector(`.${e}-edges`),d=new Map;t.querySelectorAll(`.${e}-edge`).forEach(h=>d.set(h.getAttribute("data-edge"),h));for(const h of n.lines){const u=d.get(String(h.i));u&&(u.toggleAttribute("data-lit",a(h)),u.toggleAttribute("data-dim",!!r&&!a(h)))}if(t.querySelectorAll(`.${e}-label`).forEach(h=>{const u=n.lines.find(S=>String(S.i)===h.dataset.edge);h.toggleAttribute("data-lit",!!(u&&a(u)))}),l){for(const h of n.lines)if(a(h)){const u=d.get(String(h.i));u&&l.appendChild(u)}}const m=Tt(n.lines,a),{defs:f,ids:c}=_e(e,{...n,crossings:m},s,i),g=t.querySelector(`.${e}-svg`);if(!g)return;let x=g.querySelector("defs");!x&&f&&(x=document.createElementNS("http://www.w3.org/2000/svg","defs"),g.insertBefore(x,g.firstChild)),x&&(x.innerHTML=f),n.lines.forEach((h,u)=>{const S=d.get(String(h.i))?.querySelector(`.${e}-line`);if(!S)return;const I=c.get(u);I?S.setAttribute("mask",`url(#${I})`):S.removeAttribute("mask")})}var Bn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Tn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Bn()||Wn(t)?"done":"pending")}}var Rn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Wn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Rn(t))!==null}catch{return!1}}function Ce(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Fn(t,e,n,s=!1,i=!1){const r=s?Ot(t):null;if(r&&n.startsWith("Arrow")){const d={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return d?r[e]?.[d]??null:null}const o=t.byId.get(e)?.i??0,a=t.nodes.length;let l;if(n==="ArrowRight"||n==="ArrowDown")l=o+1;else if(n==="ArrowLeft"||n==="ArrowUp")l=o-1;else if(n==="Home")l=0;else if(n==="End")l=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,l))].id}var Nn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],je=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],zn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad","--_gw","--_mh"],Be=t=>t==null||t===!1;function Hn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Rt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?je:Nn;for(const o of s)Be(e.a[o])&&t.removeAttribute(o);for(const[o,a]of Object.entries(e.a)){if(o==="class")continue;if(o==="style"){const d=t.style,m=new Map(String(a??"").split(";").map(f=>{const c=f.indexOf(":");return[f.slice(0,c).trim(),f.slice(c+1).trim()]}).filter(([f])=>f));for(const[f,c]of m)d.getPropertyValue(f).trim()!==c&&d.setProperty(f,c);for(const f of zn)m.has(f)||d.removeProperty(f);continue}if(n&&!je.includes(o))continue;if(Be(a)){t.removeAttribute(o);continue}const l=a===!0?"":String(a);t.getAttribute(o)!==l&&t.setAttribute(o,l)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(o=>typeof o!="string"&&"slot"in o))return;const i=[...t.children];let r=0;for(const o of e.c)if(!(typeof o=="string"||"slot"in o)){for(let a=r;at.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function i(c,g,x){return{prefix:n,base:c,hasSource:g.source!==void 0&&g.source!==null&&g.source!=="",hiddenClass:"visually-hidden",viewer:x?x.keys:void 0}}function r(c,g,x,h){var u=function(S){return''+it(S)+""};return{source:it(String(g.source||"")),summary:it(String(g.summary||"")),hint:Dt(c).map(function(S){return""+S.keys.map(u).join(" ")+" "+it(S.words)+""}).join(""),toggle:'"}}function o(c,g,x){var h=wt(c),u=Ct(h,{},i(g,c,x)),S=Nt(u,r(h,c,g,!1)),I=S.indexOf(">");return{open:S.slice(0,I+1),inner:S.slice(I+1,S.length-9),warnings:h.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],l=["--_cols","--_gpad","--_track"];function d(c,g,x,h){c.__diagram&&c.__diagram.stop();var u=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(c).direction==="rtl",I=g.layout==="auto"&&(g.type==="architecture"||g.type==="flowchart"||g.type==="schema"),T=I?Array.isArray(g.placement)?g.placement:g.placement?[g.placement]:[]:[];I&&!T.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var M=g.direction?[g.direction]:g.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var Y=0;Y .diagram-drawing")){if(!u||!c.querySelector("#"+CSS.escape(u+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););u="dg"+s}var J=o(g,u,h),j=document.createElement("div");j.innerHTML=J.open+"";var Q=j.firstChild;a.forEach(function(H){c.removeAttribute(H)}),l.forEach(function(H){c.style.removeProperty(H)});for(var L=0;L :not(script[data-diagram])").forEach(function(H){H.remove()}),c.insertAdjacentHTML("beforeend",J.inner)}B.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var _=i(u,g,h),E={},O=null,R=null,D=null,W=null,tt=Object.create(null),K=function(H){tt[H]||(tt[H]=1,console.warn("Basalt diagram: "+H))},y=function(H){Rt(c,Ct(B,H,_))},b=c.querySelector(".diagram-ink"),p=c.querySelector(".diagram-toggle"),k=!h&&B.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,C=function(){k&&Ce(c)};function q(){jn(c,n,O&&O.geo,O&&O.tokens,u,R||W||D),nt()}var F=null,X=!h&&matchMedia("(hover: none), (pointer: coarse)").matches;function nt(){var H=X&&!h&&b&&b.innerHTML!=="";if(c.toggleAttribute("data-touch",!!(X&&!h)),H&&!F){var Y=c.querySelector(":scope > .diagram-foot");if(!Y)return;F=document.createElement("button"),F.type="button",F.className="btn diagram-clear",F.setAttribute("data-variant","secondary"),F.setAttribute("data-size","sm"),F.innerHTML="Clear highlight",F.addEventListener("click",function(){W&&(W=null,q())}),Y.appendChild(F)}else!H&&F&&(F.remove(),F=null);F&&(W?F.removeAttribute("aria-disabled"):F.setAttribute("aria-disabled","true"))}function z(H){if(!H.defaultPrevented){var Y=en(c,n,H,W);Y!==void 0&&(C(),X=!0,W=Y,q())}}function G(){p&&(p.setAttribute("aria-expanded",String(!!E.open)),p.firstElementChild.textContent=E.open?"Hide the list":"View as list")}function et(){if(I&&T.length>1&&!h){for(var H=null,Y=0;Y1&&h&&!g.direction&&h.room){for(var He=h.room(),De=-1,Jt=null,Xt=0;XtDe+1e-6&&(De=Ke,Jt=Yt)}}}Jt&&(B=Jt)}O=(h?h.measure:Zt)(c,B,n,u,E,y,K),E=O.dyn,y(E),G();var Qt=c.querySelector(":scope > .diagram-hint");if(Qt){var Ve=Dt(B,E.layout==="drawn").map(function(St){return""+St.keys.map(function(Zn){return''+it(Zn)+""}).join(" ")+" "+it(St.words)+""}).join("");Qt.innerHTML!==Ve&&(Qt.innerHTML=Ve)}bt(B,E)||(D=W=null);var Ze=b&&O.ink!==w;Ze&&(b.innerHTML=O.ink,w=O.ink),q(),k&&O.tokens&&(Tn(c,!!(O.geo&&O.geo.lines.length)),Ze&&$&&$.redrawn()),h&&h.onMeasured&&O.tokens&&h.onMeasured(O,c),B.text&&typeof e.diagramText=="function"&&e.diagramText(c,B,g)}function ot(H){E=H,y(E)}function V(H){var Y=E.stop;E=Object.assign({},E,{stop:H}),Dn(c,n,Y,H)}var P=function(H){var Y=H&&H.closest?H.closest(".diagram-node"):null;return Y&&c.contains(Y)?Y:null};function Z(H){var Y=P(H.target);if(!(!Y||H.defaultPrevented)){if(C(),H.key==="Escape"){!h&&(R||D||W)&&(H.preventDefault(),R=D=W=null,q());return}if(bt(B,E)){var dt=Fn(B,Y.getAttribute("data-node"),H.key,E.layout==="drawn");if(dt){H.preventDefault(),V(dt);var Mt=c.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');Mt&&Mt.focus()}}}}function U(H){var Y=P(H.target);if(Y){C();var dt=Y.getAttribute("data-node");R=Y.matches(":focus-visible")?dt:null,bt(B,E)&&E.stop!==dt&&V(dt),q()}}function at(H){var Y=P(H.target);Y&&(P(H.relatedTarget)||(R=null),E.keep===Y.getAttribute("data-node")&&ot(Object.assign({},E,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var Y=P(H.target);Y&&C();var dt=Y&&bt(B,E)?Y.getAttribute("data-node"):null;dt!==D&&(D=dt,q())}}function It(){D&&(D=null,q())}function $t(){C(),ot(Object.assign({},E,{open:!E.open,autoOpen:void 0})),G()}c.addEventListener("keydown",Z),c.addEventListener("focusin",U),c.addEventListener("focusout",at),c.addEventListener("pointerover",ct),c.addEventListener("pointerleave",It),c.addEventListener("click",z),p&&p.addEventListener("click",$t),et();var kt=c.clientWidth,Ut=0,Te=!0,Re=new ResizeObserver(function(){Math.abs(c.clientWidth-kt)<.5||(kt=c.clientWidth,cancelAnimationFrame(Ut),Ut=requestAnimationFrame(et))});Re.observe(c),document.fonts&&document.fonts.ready.then(function(){Te&&et()});var We=matchMedia("(forced-colors: active)"),Fe=B.nodes.some(function(H){return H.mark});Fe&&We.addEventListener("change",et),k&&($=e.diagramMotion(c,{fig:c,P:n,base:u,model:function(){return B},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},g));var Ne=!h&&g.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,g,{model:B,settle:C,animated:k}):null,ze=c.querySelector(":scope > .diagram-foot"),Gn=!h&&g.export===!0&&ze&&typeof e.diagramExport=="function"?e.diagramExport(ze,c):[];c.__diagram={stop:function(){Ne&&Ne.destroy(),Gn.forEach(function(H){H.remove()}),Te=!1,Re.disconnect(),cancelAnimationFrame(Ut),Fe&&We.removeEventListener("change",et),$&&$.destroy(),c.removeEventListener("keydown",Z),c.removeEventListener("focusin",U),c.removeEventListener("focusout",at),c.removeEventListener("pointerover",ct),c.removeEventListener("pointerleave",It),c.removeEventListener("click",z),F&&F.remove(),p&&p.removeEventListener("click",$t)},layout:et,key:m(g),send:$&&$.sendValue?$.sendValue:null}}function m(c){try{return JSON.stringify(c,function(g,x){return g==="packet"&&x&&typeof x=="object"?Object.assign({},x,{send:void 0}):x})}catch{return null}}function f(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var g=c.querySelector(":scope > script[data-diagram]");if(g)try{d(c,JSON.parse(g.textContent),!0)}catch(x){console.error("Basalt diagram: this figure could not be drawn",x)}}})}e.diagramMarkup=o,e.diagramKit={draw:d,buildModel:wt,figureKey:ln,figureList:mn,hintEntries:Dt,toHtml:Nt,escapeHtml:it,settleEntrance:Ce,measureFigure:Zt},t.diagram=function(c,g){var x=c.__diagram,h=x&&x.send?m(g):null;if(h!==null&&h===x.key){x.send(g.packet?g.packet.send:void 0);return}d(c,g)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index a7c88325..33b34ddd 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -806,7 +806,7 @@ export function columnCount(m: Model): number { return m.type === "sequence" ? m // ---- The stacked drawing's plan: routes and gaps from the order alone (1.13) ---- export type StackRoute = "down" | "up" | "trunk" | "rail" | "end-down" | "end-up"; -export interface StackPlan { routes: StackRoute[]; gutter: boolean; lanes: number[]; exits: number[]; gaps: Record; third: boolean } +export interface StackPlan { routes: StackRoute[]; gutter: boolean; lanes: number[]; exits: number[]; gaps: Record; third: boolean; laneCount: number } /** The stacked drawing's routes, end lanes and the gap above each card (in px of the space scale), from the author's order. */ export function stackPlan(m: Model): StackPlan { @@ -837,7 +837,7 @@ function planStack(m: Model): StackPlan { const gutter = ends.length > 0 && (m.type === "data-flow" || !laneOk); // Lanes in the gutter, nested (1.7 rule 3): of two overlapping lines the one that travels farther takes the outer lane; equal travel, the // earlier is inside. Allocated across each overlapping set: shortest first, each one lane outside every overlapping line already placed, - // so no two overlapping lines share a lane. A line that would need a third lane is the development error (`third`). + // so no two overlapping lines share a lane. A line that would need a fifth lane is the development error (`third`). const travel = (e: MEdge) => { const [a, b] = span(e); return b - a; }; const lanes = m.edges.map(() => 0); let third = false; @@ -846,9 +846,11 @@ function planStack(m: Model): StackPlan { let lane = 0; for (const o of placed) if (overlaps(o.e, it.e)) lane = Math.max(lane, lanes[o.k]! + 1); lanes[it.k] = lane; - if (lane > 1) third = true; + // Four lanes at most (DECISIONS 306, 1.3): a fifth is the last resort, no lines and the list open. + if (lane > 3) third = true; placed.push(it); } + const laneCount = Math.max(0, ...ends.map(({ k }) => lanes[k]! + 1)); // Where an end line leaves its card: the middle, or the thirds when two leave one card (the farther one nearer the top going down, nearer the bottom going up). const exits = m.edges.map(() => 0.5); for (const n of order) { @@ -880,10 +882,15 @@ function planStack(m: Model): StackPlan { } }); if (labelled > 1 || (turnInto && turnFrom)) gap = 64; + // Several end lines into one card (1.3) turn space-5 apart: the gap above it grows space-5 for each entry past the first (and below a card for lines + // that enter it from below). + const downInto = ends.filter(({ e, k }) => routes[k] === "end-down" && m.byId.get(e.to)!.i === b).length; + const upInto = ends.filter(({ e, k }) => routes[k] === "end-up" && m.byId.get(e.to)!.i === b - 1).length; + gap += 20 * Math.max(0, downInto - 1) + 20 * Math.max(0, upInto - 1); gaps[card.id] = gap; void above; } - return { routes, gutter, lanes, exits, gaps, third }; + return { routes, gutter, lanes, exits, gaps, third, laneCount }; } // ---- Swatches: each drawn exactly as its mark ---- @@ -1376,6 +1383,8 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { // A schema of one column with a foreign key: its turn-backs run space-4 out on the end side, past the cards, so the drawn layout keeps space-5 there // (the turn-back and its stroke on the pixel grid); the fit rule counts it (minimums). // Two lanes of turn-backs take space-3 more (call 2). + // The end gutter grows by lanes (1.3): lanes × space-3-5 + space-3 (40, 54, 68). + if (plan?.gutter && plan.laneCount > 2) style.push(`--_gw:calc(${plan.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`); if (oneColumnTurnBacks(m)) style.push(`--_gpad:0px ${turnBackLanes(m).lanes > 1 ? "calc(var(--basalt-space-5) + var(--basalt-space-3))" : "var(--basalt-space-5)"} 0px 0px`); if (m.type === "schema" && dyn.track) style.push(`--_track:${dyn.track}px`); return h("figure", { @@ -2344,15 +2353,23 @@ function stackedGeometry(input: DrawnInput, measure: ReturnType, p } else { // An end line: out the end side, along the end lane or the gutter, into the card's top (down) or bottom (up), space-6 in from its end edge. const right = Math.min(columnRight.get(e.from) ?? W, columnRight.get(e.to) ?? W); - const laneX = sn.x(plan.gutter ? spineEnd + (plan.lanes[k] ? 2 * s("3-5") : s("3-5")) : right - s("2-5"), w); + // Lanes space-3-5 apart, one pitch (DECISIONS 306, 1.3). + const laneX = sn.x(plan.gutter ? spineEnd + (plan.lanes[k]! + 1) * s("3-5") : right - s("2-5"), w); const yExit = sn.y(a.rect.t + (a.rect.b - a.rect.t) * plan.exits[k]!, w); const exit = contour(a, "right", yExit); - const ex = sn.x(b.rect.r - s("6"), w); const down = r === "end-down"; - const ty = sn.y(down ? b.rect.t - turn : b.rect.b + turn, w); + // Several end lines into one card nest (1.3): the line from the outermost lane turns lowest (the merged turn) and enters nearest the end edge + // (space-6 in); each from a lane further in turns space-5 higher and enters space-3 further in. Their labels are seated space-2-5 clear of the + // innermost entry, each centred on its own turn's height, taken before the half-pixel snap. + const mates = m.edges.map((o, j) => ({ o, j })).filter(({ o, j }) => (plan.routes[j] === r) && o.to === e.to).sort((x, y) => plan.lanes[y.j]! - plan.lanes[x.j]! || x.j - y.j); + const at = Math.max(0, mates.findIndex(({ j }) => j === k)); + const exRaw = b.rect.r - s("6") - at * s("3"), innerEx = b.rect.r - s("6") - (mates.length - 1) * s("3"); + const ex = sn.x(exRaw, w); + const tyRaw = down ? b.rect.t - turn - at * s("5") : b.rect.b + turn + at * s("5"); + const ty = sn.y(tyRaw, w); pts = [exit, { x: laneX, y: exit.y }, { x: laneX, y: ty }, { x: ex, y: ty }, contour(b, down ? "top" : "bottom", ex)]; const into = down ? e.to : order[b.i + 1]?.id ?? e.to; - if (label) labelSeats.push({ k, cands: lineSeats({ l: ex - s("2-5") - lw, r: ex - s("2-5"), t: ty - lh / 2, b: ty + lh / 2 }, into, down ? -1 : 1), on: false, card: into }); + if (label) labelSeats.push({ k, cands: lineSeats({ l: innerEx - s("2-5") - lw, r: innerEx - s("2-5"), t: tyRaw - lh / 2, b: tyRaw + lh / 2 }, into, down ? -1 : 1), on: false, card: into }); } const snapped = snapRoute(pts, w, sn); geo.lines.push({ i: k, from: e.from, to: e.to, kind: e.kind, pts: snapped, tip: snapped[snapped.length - 1]!, dir: finish(snapped), width: w }); @@ -2580,12 +2597,13 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin // The stack is the last layout there is. If it still holds an overlap (a label with no clean seat after every try, a line through a node or // off the drawing, or a third end lane), no drawing is returned that is known to overlap: the cards stay, in order, with no lines and no // labels, as the stacked schema's do, and the list holds every connection. + if (dev && !plan.third && plan.laneCount > 2) warn?.(`the stacked drawing uses ${plan.laneCount} end lanes (four at most)`); const failed = geo.unseated.length > 0 || geo.through.length > 0 || geo.outside.length > 0 || plan.third; if (failed) { if (geo.unseated.length) dev && warn?.(`the stacked drawing has no clean seat for ${[...new Set(geo.unseated)].map((k) => `"${m.edges[k]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`); if (geo.through.length) dev && warn?.(`in the stacked drawing ${names(geo, geo.through)} would pass through a node, so its lines are not drawn`); if (geo.outside.length) dev && warn?.(`in the stacked drawing ${names(geo, geo.outside)} would leave the drawing, so its lines are not drawn`); - if (dev && plan.third) warn?.("the stacked drawing would need a third end lane, so its lines are not drawn"); + if (dev && plan.third) warn?.("the stacked drawing would need a fifth end lane, so its lines are not drawn"); // Dressed as where scripting is off (1.13): no line in the key, no key hint, no stops, and the list open when the figure becomes bare. const bare: Geo = { ...geo, lines: [], labels: [], crossings: [] }; const dyn = stopOf({ ...d, grow: record(), bare: true, open: current.bare ? current.open : true, autoOpen: current.bare ? current.autoOpen : current.open ? undefined : true }); @@ -2712,7 +2730,7 @@ export function keyTarget(m: Model, from: string, key: string, drawn = false, rt */ const MANAGED = ["data-layout", "data-measured", "role", "aria-roledescription", "aria-labelledby", "aria-describedby", "aria-label", "tabindex", "data-stops", "hidden", "data-art"]; const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion", "data-first-visit", "data-rtl"]; -const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_gpad"]; +const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_gpad", "--_gw", "--_mh"]; const absent = (value: VAttrs[string]) => value === undefined || value === null || value === false; function pairs(el: Element, v: VElement): boolean { if (el.tagName.toLowerCase() !== v.t) return false; diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 2bb203a1..186af262 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4464,7 +4464,7 @@ } .basalt-diagram[data-layout="drawn"] > .basalt-diagram-drawing { --_drawn: ; } .basalt-diagram[data-layout="stacked"] > .basalt-diagram-drawing { --_drawn: initial; } - .basalt-diagram[data-gutter] > .basalt-diagram-drawing { --_gutter: var(--basalt-space-10); } + .basalt-diagram[data-gutter] > .basalt-diagram-drawing { --_gutter: var(--_gw, var(--basalt-space-10)); } .basalt-diagram[data-type="data-flow"] > .basalt-diagram-drawing { --_d-cols: var(--_drawn) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr)); --_row-gap: var(--basalt-space-10); From 493042045589c370dede068147dcc2d6cd03e42f Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:01:33 -0600 Subject: [PATCH 34/62] Section 6's text for what is built: AGENTS.md, docs/motion.md, and foundations' opening, the figure and the viewer The rest of section 6 (the per-type bullets, the key, keyboard and touch, forced colours, tokens, colour, vertical lines and icons) is still to come; cardinality and far keys are named as not built. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 13 ++++++++++--- docs/foundations.md | 38 ++++++++++++++++++++++++++++++++++++-- docs/motion.md | 6 ++++++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5da0e2a6..592c451d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -123,7 +123,7 @@ Basalt has one owner (Bailey) and a design panel of two independent design revie tabs that scrolls, a sortable header cell (a header band that is itself a button), a phone tab bar cell, and a cut cell of a still table (a focus stop, which shows its own ring after Esc has closed its plate). These structural vertical lines are allowed, each named and never a selection, sort, active or status mark: the 1px divider at a pinned table column's edge while the table is scrolled, the app sidebar's 1px edge, a meter's labelled target tick, the vertical - `Separator` between groups of controls, the edges between a `NumberField`'s value and its steppers, a diagram's connector and a sequence diagram's lifeline. The active row in a menu, select, combobox or command menu is a rounded plate + `Separator` between groups of controls, the edges between a `NumberField`'s value and its steppers, a diagram's connector, a sequence diagram's lifeline with its activation bar, and a frame's sides. The active row in a menu, select, combobox or command menu is a rounded plate (radius 8, one solid fill per level) plus a lift from secondary ink to primary, with no weight change: it is the row the keyboard is on, and it changes with every arrow key (WCAG 1.4.1). A selected table row is the wash band, and its checked box carries the state. A wash over an opaque fill (a pinned cell) is one colour from `color-mix`, never a gradient, an image or a @@ -164,7 +164,7 @@ Basalt has one owner (Bailey) and a design panel of two independent design revie filtered or sorted list or grid moves what stays by transform and never replaces an item (past 48 items that would move, it lands at once); a number beside a figure never counts up. The hold or printing settles a running entrance at once, and a page change without a reload counts as a load. Under reduced motion, opacity only. See `docs/motion.md`. - **Density and touch:** compact moves controls one step down, with a floor of 24px. Touch - targets stay at least 44px whatever the density, on touch and in any window under 720 whatever the pointer (16px text entry stays touch-only), except a chart's day, reached by drag and by the keys (the phase lane's marks keep 44px). Text entry is 16px on touch. A one-line notification entry is at least 44 tall on + targets stay at least 44px whatever the density, on touch and in any window under 720 whatever the pointer (16px text entry stays touch-only), except a chart's day, reached by drag and by the keys (the phase lane's marks keep 44px); a diagram's card that answers a tap is 44px tall. Text entry is 16px on touch. A one-line notification entry is at least 44 tall on touch, and a `Link` on a line of its own has a 44px hit box with no change to layout, its words raised over a stacked neighbour's box; a link in a sentence keeps its line. - **The phone and what is pinned:** while an on-screen keyboard is up (`data-screen-keyboard`) the tab bar and the phone's status bar are covered, and the foot, sheets, dialogs, the command menu and the toasts are laid out on what is seen. A page that pins more than the bar opts into measured sizes @@ -198,7 +198,14 @@ Basalt has one owner (Bailey) and a design panel of two independent design revie (the faces arriving, a resize) never restarts, hides or cuts short an entrance. An architecture card may carry its service's own mark, 16px in the top end corner: the owner's file, never recoloured, a form for each ground, decoration beside the name, recorded in `packages/react/marks/manifest.json`; a service without one is its name alone. In print a mark prints, and so does the fill of a - focal node that carries one (`print-color-adjust: exact`). + focal node that carries one (`print-color-adjust: exact`). A sequence may show a participant working (a bar) and frame a run of messages + (`opt`, `loop`, `alt`: structure, never a panel, every word plated), and may be written as text art, which never hides a line and has no caret. + Groups nest two deep; four end lanes at most. A card may be a link (the card is the stop; the arrow is the cue). A label breaks only where its + author breaks it. Arrow keys are spatial, on tracks. On touch a tap traces and "Clear highlight" clears. In print a figure is untraced and light. + Right to left mirrors the figure, not the words. Automatic layout asks elkjs for a column and a row and nothing else; Basalt routes, and a figure + is never scaled. elkjs loads on demand or not at all: place at build time. "Expand" opens the viewer: the drawn layout in a dialog (full screen under + 720), laid out at 100% and zoomed by the reader with one transform, from Fit or 100% to 400%, in steps that land at once; it pans by scrolling; it + is never a picture, a `viewBox` or CSS `zoom`; it is still, and it does not print. Cardinality and far keys (DECISIONS 306, 1.1) are not built yet. - **Type:** Geist and Geist Mono at 400, 500 and 600 only, and a `Geist Fallback` face (local Arial, one face per weight) that reduces the shift when Geist arrives; it does not promise the same wrap at every width. - **Display type:** two roles a page writes, hero (96/96; 72/76 from 720 to 1023; 44/48 under 720) and display (72/76; 56/60; 36/40), made of the fixed diff --git a/docs/foundations.md b/docs/foundations.md index bb0c3758..8c912f1a 100644 --- a/docs/foundations.md +++ b/docs/foundations.md @@ -1682,6 +1682,12 @@ owner's prototype, one draft, a check and a decision, revised after the final po **Status:** decided by the council (DECISIONS 281, a handoff); the implementation has not been reviewed. +The parts of DECISIONS 301 (cardinality and far keys, activations and frames, the text art, nested groups, four end lanes, link cards, +two-line labels, spatial keys, a trace on touch, marks on steps and participants, right to left, export and automatic layout) were +decided by the council from two drafts and a check (DECISIONS 306, revised by 313). **Status:** the implementation has not been reviewed, +and cardinality and far keys are not built yet. Automatic layout leads with build time: place with `placeDiagram` and pass `placement`, and +elkjs (EPL-2.0 OR GPL-3.0-or-later, used under EPL-2.0) never reaches the browser. + **The idea: the words are in the boxes, the lines say how they connect, and the key says what each line means.** A diagram is monochrome. Nothing takes a colour, the accent or a status, with one exception: a service's own mark on an architecture card keeps its owner's colours ([Service marks](#service-marks)). One node may be focal, and it is inverted ink. @@ -1689,9 +1695,10 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b ### The figure - Its order is the chart's: the title and source, the drawing, the key, the key hint, the summary (a required `figcaption`), then - "View as list" and the list. + "View as list" and the list, with "Expand" beside "View as list". - Text is `text-xs` or `text-sm`. Nothing is under 12px. The drawing is laid out in real CSS pixels at its own measured width, never - scaled through a `viewBox`, and nothing scrolls sideways. + scaled through a `viewBox`, and nothing scrolls sideways. The one place a reader may scale and scroll it is its viewer (below), where the + scale is theirs, as a browser's zoom is. - A node is a panel one level above what the figure sits in: the rim, no shadow, radius 8, `space-2-5` by `space-3`. Its lines are a kind (`text-xs` Mono, tertiary), a name (`text-sm` 600) and a detail (`text-xs` secondary, Mono only for an identifier). A Mono detail breaks only at its spaces, never at a hyphen, and keeps the ordinary hyphen so a copy is exact (the decider's answers, review round 64). @@ -1768,6 +1775,33 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b - A diagram is still unless its author asks for motion (`motion="animated"`); see [Motion in a diagram](#motion-in-a-diagram). A trace's ink changes over `duration-fast`, at once under reduced motion. + +### The viewer + +"Expand", in the figure's foot beside "View as list", opens the figure in a dialog: the window less `space-4` from 720, the whole +window under it, in the form dialog's box with the sheet's head, body and foot. Decided by the council's decider alone as part 9 +of DECISIONS 301 (DECISIONS 310, the owner's ask); no draft and no check. **Status:** the implementation has not been reviewed. Built +words only (no glyph) and on a native modal ``, deviations the PR records. + +- **What it holds** is the drawn layout, drawn again from the same data at the stage's inner width, never under the figure's least + drawn width and never over the page row unless that is more. The stack is held only when nothing is drawn. +- **Laid out at 100%, zoomed by the reader.** The layout is made in real CSS pixels and never measured while zoomed. The zoom is + one `transform: scale()` on that layer: never a `viewBox`, CSS `zoom`, a canvas or a picture, and no layer is held at an old + size. Under `scale(3)` the figure is the pixels a 3x screen draws. +- **Fit** is the whole drawing in the stage (padding `space-6`, `space-4` under 720), 200% at most, and is how it opens. The limits + are Fit or 100%, whichever is less, and 400%. Buttons and keys step through 25, 33, 50, 67, 75, 100, 125, 150, 200, 300 and 400, + and a step lands at once. The level is written between the buttons and spoken once it rests. +- **Zoom:** "Zoom out", "Zoom in" and "Fit"; `+`, `−` and `0` while focus is in the stage; Ctrl or Command with the wheel and a + trackpad pinch, about the pointer; two fingers on touch, about their midpoint. +- **Pan is a scroll:** the stage scrolls both ways. A drag past `space-1`, one finger on touch, the wheel, and the scrolling keys + with the stage focused. No momentum and no rubber band. A drag does not select. +- **The foot** holds the figure's key at its real size, the key hint, and "View as list", which puts the list in the stage in + place of the drawing. +- **Focus** opens on the stage (the flush field's inset ring). Esc always closes, and focus returns to "Expand". +- **A trace works. Nothing else moves:** no entrance, flow, mover or run plays in the viewer, and the page's figure holds its + loops while it is open. +- **Under 100%** the words are under 12px and a hairline may be thinner than a device pixel: an overview, with no size or + contrast claim. It does not print: the page prints as always. ### Motion in a diagram Decided by the council for the owner's handoff (DECISIONS 287 to 291 and 292). **Status:** the implementation has not been reviewed. diff --git a/docs/motion.md b/docs/motion.md index 29ff3f12..061f6797 100644 --- a/docs/motion.md +++ b/docs/motion.md @@ -85,6 +85,12 @@ only where lines are drawn. The entrance plays when the figure comes into view a The rules and the tokens are in [Motion in a diagram](foundations.md#motion-in-a-diagram). Status: decided by the council (DECISIONS 287 to 291 and 292); the implementation hasn't been reviewed. +DECISIONS 306 adds three things. An entrance is not stored between visits unless the figure asks for `entrance: "first-visit"`: then a +mark is stored when an entrance that played finishes or gives way to the reader, and later visits are at rest; a visit at rest by mode stores +nothing. Flow is on any edge: a dashed line's own dashes march, one period every 625ms, and sit where the key draws them whenever they are not +moving. A text sequence builds by ink: a message's label and arrow lift to their resting ink at its turn. No line is hidden and there is no caret. +There is no blinking caret. The diagram's viewer (DECISIONS 310) is still: no entrance, flow, mover or run plays in it, and a zoom lands at once. + ## The hover glide Menu, Select, Combobox and CommandMenu draw one plate per popup, and navigation draws one pill per list, which follows the pointer between rows on `duration-base` and `ease-out`, whatever the distance. Each row's own plate is the fallback and stays correct with no script. Base UI's `data-highlighted` (and cmdk's `data-selected`) stays the authority for which row is active; the glide only paints it, and an input-modality check decides whether the plate travels (pointer) or snaps (keyboard). From f4250f67c43a72e16a475acf77f80f77b087f1d3 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:16:15 -0600 Subject: [PATCH 35/62] Tests follow 1.3 and call 2, and the sizes and caps at the batch's head diagrams.test.mjs: four end lanes (a third is drawn, a fifth is the error) and a one-column schema's overlapping turn-backs drawn in two lanes; diagram-fixes reads "fifth end lane". Recorded sizes: each still diagram 89.8 KB (+3.1% on the last record, for the quiet run, calls 2 and 3, end lanes and the automatic direction in the viewer). Skill caps at their measured sizes: diagram 127,150, diagram-motion 27,850, diagram-zoom 17,000 (DECISIONS 318: the owner approved the raise). Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/manifest.json | 6 +++--- packages/react/test/diagram-fixes.test.mjs | 2 +- packages/react/test/diagrams.test.mjs | 20 +++++++++++-------- packages/react/test/export-sizes.json | 18 ++++++++--------- tools/html-skill/src/modules.json | 6 +++--- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index 18e08e6f..ae602381 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 123300, + "budget": 127150, "usage": 4300, "builds": [ "kbd" @@ -804,7 +804,7 @@ "loops", "toggle" ], - "budget": 27500, + "budget": 27850, "usage": 1300, "builds": [ "loops", @@ -835,7 +835,7 @@ "dialog-form", "sheet" ], - "budget": 16900, + "budget": 17000, "usage": 900, "builds": [ "dialog", diff --git a/packages/react/test/diagram-fixes.test.mjs b/packages/react/test/diagram-fixes.test.mjs index 93acec99..8045253b 100644 --- a/packages/react/test/diagram-fixes.test.mjs +++ b/packages/react/test/diagram-fixes.test.mjs @@ -97,7 +97,7 @@ describe("slots on a side (Neon's finding 13)", () => { describe("the development checks cost production nothing (Neon's finding 14)", () => { // Phrases only the checks write (a property name such as `crossings` is code, not a check's words). const WORDS = ["share the cell at column", "main lines are drawn but", "is not a kind of line", "more than three is an error", "would leave the drawing", "in the drawn layout", - "third end lane", "stands for", "is used twice", "two columns apart", "closer than space-3"]; + "fifth end lane", "stands for", "is used twice", "two columns apart", "closer than space-3"]; const bundle = async (entry, mode) => (await esbuild.build({ stdin: { contents: entry, resolveDir: pkg, loader: "js" }, bundle: true, minify: true, format: "esm", write: false, logLevel: "silent", external: ["react", "react-dom", "react/jsx-runtime"], define: { "process.env.NODE_ENV": JSON.stringify(mode) }, diff --git a/packages/react/test/diagrams.test.mjs b/packages/react/test/diagrams.test.mjs index 393632ce..099b6ca5 100644 --- a/packages/react/test/diagrams.test.mjs +++ b/packages/react/test/diagrams.test.mjs @@ -281,7 +281,7 @@ describe("the fit rule (1.11) and seats (1.8)", () => { }); // Neon's blocking finding 1 on #126: two turn-backs to different keys, beside each other, were drawn on one lane. - test("turn-backs to different keys never lie on one another: in a gutter each takes a lane; with no gutter (one column) the schema stays stacked", async () => { + test("turn-backs to different keys never lie on one another: in a gutter each takes a lane; with no gutter (one column) each takes a lane of the padding (call 2)", async () => { const { page } = await diagramPage(); const t = (name, col, row, refs = []) => ({ name, col, row, columns: [{ name: "id", key: "PK" }, ...refs.map((r) => ({ name: `${r}_id`, key: "FK", references: `${r}.id` }))] }); const schema = (key, tables) => ({ key, type: "schema", props: { title: key, summary: "Keys.", legend: { plain: "A foreign key" }, tables } }); @@ -297,7 +297,8 @@ describe("the fit rule (1.11) and seats (1.8)", () => { const lanes = (key) => page.evaluate((key) => [...document.querySelectorAll(`#fig-${key} .basalt-diagram-svg .basalt-diagram-line`)].map((p) => { const n = p.getAttribute("d").match(/-?[\d.]+/g).map(Number); return Math.min(...n.filter((_, k) => k % 2 === 0)); }), key); for (const width of [1440, 1000]) { await resize(page, width); - assert.equal(await page.getAttribute("#fig-crossed", "data-layout"), "stacked", `at ${width}: no lane for both, so no drawing`); + // A one-column schema's overlapping turn-backs take two lanes (DECISIONS 306, section 4, call 2), so the figure is drawn. + assert.equal(await page.getAttribute("#fig-crossed", "data-layout"), "drawn", `at ${width}: a lane each, so drawn`); assert.equal(await page.getAttribute("#fig-apart", "data-layout"), "drawn", `at ${width}`); assert.equal(await page.getAttribute("#fig-gutter", "data-layout"), "drawn", `at ${width}`); for (const key of ["crossed", "apart", "gutter"]) assert.deepEqual((await inspect(page, key)).problems, [], `${key} at ${width}`); @@ -403,14 +404,17 @@ describe("derivation (1.6, 1.13): the sides, slots and stacked routes of the exa // 6 of the 27 edges name a side (the decision's count). const named = ["architecture", "flowchart", "dataFlow"].flatMap((k) => DATA[k].edges).filter((e) => e.fromSide || e.toSide).length; assert.equal(named, 6); - // A third overlapping end line is a development error. - const third = core.buildModel({ type: "architecture", title: "t", nodes: ["a", "b", "c", "d", "e"].map((id, k) => node(id, 1, k + 1)), edges: [{ from: "a", to: "d" }, { from: "b", to: "e" }, { from: "a", to: "e" }] }); - assert.equal(core.stackPlan(third).third, true); - // Lanes are allocated across each overlapping set: A to C, B to E and D to H overlap in a chain, so each takes the lane outside the one before, and the - // third lane is reported, never laid on the second. + // Four end lanes at most (DECISIONS 306, 1.3): three overlapping end lines take three lanes; a fifth is the development error. + const three = core.buildModel({ type: "architecture", title: "t", nodes: ["a", "b", "c", "d", "e"].map((id, k) => node(id, 1, k + 1)), edges: [{ from: "a", to: "d" }, { from: "b", to: "e" }, { from: "a", to: "e" }] }); + assert.equal(core.stackPlan(three).third, false); + assert.equal(core.stackPlan(three).laneCount, 3); + const five = core.buildModel({ type: "architecture", title: "t", nodes: "abcdefghij".split("").map((id, k) => node(id, 1, k + 1)), edges: [{ from: "a", to: "j" }, { from: "a", to: "i" }, { from: "b", to: "h" }, { from: "b", to: "g" }, { from: "c", to: "f" }] }); + assert.equal(core.stackPlan(five).third, true); + // Lanes are allocated across each overlapping set: A to C, B to E and D to H overlap in a chain, so each takes the lane outside the one before; a + // third lane is drawn now (four at most, DECISIONS 306, 1.3), never laid on the second. const chain = core.stackPlan(core.buildModel({ type: "architecture", title: "t", nodes: "abcdefgh".split("").map((id, k) => node(id, 1, k + 1)), edges: [{ from: "a", to: "c" }, { from: "b", to: "e" }, { from: "d", to: "h" }] })); assert.deepEqual(chain.lanes, [0, 1, 2]); - assert.equal(chain.third, true); + assert.equal(chain.third, false); // Two that do not overlap share the inner lane; two that do take one each. assert.deepEqual(core.stackPlan(core.buildModel({ type: "architecture", title: "t", nodes: "abcdef".split("").map((id, k) => node(id, 1, k + 1)), edges: [{ from: "a", to: "c" }, { from: "d", to: "f" }, { from: "b", to: "e" }] })).lanes, [0, 0, 1]); // Two straight lines between one pair, one each way, take the quarter points at both ends, so neither lies on the other. diff --git a/packages/react/test/export-sizes.json b/packages/react/test/export-sizes.json index 6774907d..4722b9ca 100644 --- a/packages/react/test/export-sizes.json +++ b/packages/react/test/export-sizes.json @@ -18,7 +18,7 @@ "AppHeader": 1285, "AppShell": 103887, "AppTile": 1112, - "ArchitectureDiagram": 87155, + "ArchitectureDiagram": 89846, "ArrowDownGlyph": 2868, "ArrowLeftGlyph": 2869, "ArrowRightGlyph": 2859, @@ -70,7 +70,7 @@ "CopyGlyph": 2884, "Countdown": 3016, "CoverageStrip": 1570, - "DataFlowDiagram": 87102, + "DataFlowDiagram": 89791, "DateAge": 2527, "DescriptionColumns": 216, "DescriptionItem": 593, @@ -105,7 +105,7 @@ "Fieldset": 6390, "FilterResult": 698, "FilterToolbar": 774, - "FlowchartDiagram": 87123, + "FlowchartDiagram": 89812, "Form": 8730, "FormGrid": 438, "FormGridItem": 628, @@ -224,7 +224,7 @@ "RunsGlyph": 3128, "STATUS_MESSAGE_MS": 26, "SandboxesGlyph": 2963, - "SchemaDiagram": 87071, + "SchemaDiagram": 89760, "SearchDialog": 88277, "SearchField": 18301, "SearchGlyph": 3181, @@ -243,7 +243,7 @@ "SelectableList": 821, "SelectionBar": 25913, "Separator": 4531, - "SequenceDiagram": 87099, + "SequenceDiagram": 89788, "SettingsGlyph": 3100, "ShareBar": 1411, "Sheet": 70793, @@ -412,11 +412,11 @@ "useWaitMark": 303 }, "package": { - "bytes": 890075, - "gzip": 296147 + "bytes": 892757, + "gzip": 297209 }, "styles": { - "bytes": 406843, - "gzip": 52878 + "bytes": 407734, + "gzip": 52946 } } diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index 18e08e6f..ae602381 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 123300, + "budget": 127150, "usage": 4300, "builds": [ "kbd" @@ -804,7 +804,7 @@ "loops", "toggle" ], - "budget": 27500, + "budget": 27850, "usage": 1300, "builds": [ "loops", @@ -835,7 +835,7 @@ "dialog-form", "sheet" ], - "budget": 16900, + "budget": 17000, "usage": 900, "builds": [ "dialog", From 88618e0f9eaf55f4b4d911894b05e2a1e93e359b Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:35:38 -0600 Subject: [PATCH 36/62] Cardinality and far keys in a schema (DECISIONS 306, 1.1, revised by 313) Cardinality: `cardinality: { from, to }` on a foreign key column (from one, zero-or-one, one-or-many or zero-or-many; to one, the default, or zero-or-one). Its line runs edge to edge through Information Engineering's marks in its own ink, in place of the dot and the head: bars at 4 and 8, a foot from a point at 7.5 to the edge (space-1 either side), a ring centred at 10.5 filled with the ground; every mark inside size-diagram-foot, and no elbow starts inside it (pathD's zone). A marked schema's column gap is space-12 plus space-3 (60), its gutter lanes 30; 20 and 40; 18, 30 and 42, none nearer a table than 18, three at most (a fourth: a far line, then the later in the author's order, is left out and named). A marked gutter counts lanes by what runs beside what (closer than space-8, the merged rule), so a line shares a lane with one it does not run beside; without that the extended CIMIP schema needs four lanes beside agent_runs. Two statements at one key arrive space-2 apart, each in its own lane; the same statement shares the bus. A turn-back is space-6 out with marks; a one-column schema's padding space-6 plus space-1. The key shows each form drawn ("Exactly one" ...) in place of the foreign key's line; the list and the sentences carry "zero or many approvals to zero or one users"; the row is unchanged. Development errors: cardinality without references, a "to" of many, a bad form, some keys stated and not all (in production an unstated line draws as today). Entrance: the foreign-key end's marks fade as the dot does, the referenced end's as a head. Forced colours, trace, dim and print follow the line; a ring's fill is Canvas. data-marks, and container rules at 792, 1076, 1360 and 1644 before script. Far keys: a key two or more columns away is drawn, out to its own gutter, along a corridor (a row gap no table of the columns between stands in, or the margin above or below; the one nearest the middle of the two rows, an interior gap winning a tie, then the upper), and into the referenced table's gutter, where it joins the key's bus. Two lanes a corridor, space-3 apart; a third is left out and named. The layout change: a schema with a drawn far key writes --_rows, spacer tracks round the author's rows (space-10 for a gap that carries a corridor, space-8 otherwise, space-8 for a margin corridor, 0 else) with the grid's row gap at 0, and each card's row doubles; the corridor is chosen on the grid without them, and the figure is measured again. A figure with no far key writes no --_rows and keeps its grid. The extended CIMIP schema (fixture b) takes cardinality on every key and approvals.incident_id and approvals.decided_by, as Draft B extended it. The geometry reader takes a marked line's end as its tip. Builder's readings where the decision is silent: a bar's 1px ink is the pixel that ends at its distance; two far lines to one key share a corridor lane; an interior corridor's two lanes take the order that crosses least, a margin's nest farther-going outermost; a marked gutter's lane count as above. Co-Authored-By: Claude Opus 5.5 --- .../basalt-html/parts/diagram-motion.js | 2 +- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 24 +- .../skills/basalt-html/parts/usage/diagram.md | 2 +- packages/react/src/diagram-core.ts | 376 +++++++++++++++--- packages/react/src/diagram-motion-core.ts | 9 + packages/react/src/styles/components.css | 36 +- packages/react/test/diagram-geometry.mjs | 5 +- .../react/test/fixtures/cimip-diagrams-b.json | 76 +++- tools/html-skill/src/modules/diagram.js | 2 +- tools/html-skill/src/usage/diagram.md | 2 +- 11 files changed, 454 insertions(+), 82 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram-motion.js b/.agent/skills/basalt-html/parts/diagram-motion.js index c8c2cab6..0096a735 100644 --- a/.agent/skills/basalt-html/parts/diagram-motion.js +++ b/.agent/skills/basalt-html/parts/diagram-motion.js @@ -1 +1 @@ -(()=>{var C=Object.defineProperty,T=(t,s,e)=>s in t?C(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s,e)=>T(t,typeof s!="symbol"?s+"":s,e);function P(t,s){const e=r=>String(Math.round(r*100)/100);let i=`M${e(t[0].x)} ${e(t[0].y)}`;for(let r=1;r`basalt-diagram-entrance:${location.pathname}#${t.id}`;function A(t){const s=t.getAttribute("data-entrance");s!=="pending"&&s!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}var g;function O(t){if(!g){const s=()=>{for(const h of g?.figs??[])h.sync()},e=()=>{for(const h of g?.figs??[])A(h.host.fig);s()},i=new IntersectionObserver(h=>{for(const o of h)for(const a of g?.figs??[])a.drawing===o.target&&a.seen(o)},{threshold:Array.from({length:21},(h,o)=>o/20)}),n=new MutationObserver(h=>{for(const o of h){if(o.target===document.documentElement){for(const a of g?.figs??[])a.holdChanged();continue}for(const a of g?.figs??[])a.host.fig===o.target&&a.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const r=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of r)h.addEventListener("change",s);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",s),g={figs:new Set,io:i,mo:n,media:r,onChange:s,onPrint:e}}return g.figs.add(t),t.drawing&&g.io.observe(t.drawing),g.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),g}function _(t){if(g&&(g.figs.delete(t),t.drawing&&g.io.unobserve(t.drawing),!g.figs.size)){g.io.disconnect(),g.mo.disconnect();for(const s of g.media)s.removeEventListener("change",g.onChange);window.removeEventListener("beforeprint",g.onPrint),document.removeEventListener("visibilitychange",g.onChange),g=void 0}}function F(t){const s=getComputedStyle(t),e=h=>s.getPropertyValue(`--basalt-${h}`).trim(),i=h=>{const o=e(h),a=parseFloat(o);return/ms$/.test(o)?a:/s$/.test(o)?a*1e3:a||0},n=h=>parseFloat(e(h))||0,r=h=>e(`ease-${h}`)||"ease";return{lineMin:i("duration-diagram-line-min"),lineMax:i("duration-diagram-line-max"),stagger:i("duration-diagram-stagger"),step:i("duration-diagram-step"),arrow:i("duration-diagram-arrow"),limit:i("duration-diagram-limit"),legMin:i("duration-diagram-leg-min"),legMax:i("duration-diagram-leg-max"),rest:i("duration-diagram-rest"),pause:i("duration-diagram-pause"),repeat:i("duration-diagram-repeat"),fast:i("duration-fast"),base:i("duration-base"),slow:i("duration-slow"),slower:i("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:r("in-out"),out:r("out"),in:r("in")}}var L=(t,s,e)=>Math.max(s,Math.min(e,t)),I="http://www.w3.org/2000/svg",y=(t,s,e)=>{const i=document.createElementNS(I,t);for(const[n,r]of Object.entries(s))i.setAttribute(n,String(r));return e?.appendChild(i),i},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",V={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function v(t,s){const e=t.pts.map(a=>({...a})),i=V[t.dir],n=e[e.length-1],r=e[e.length-2],h=Math.hypot(n.x-r.x,n.y-r.y),o=Math.min(s,Math.max(0,h-.5));return n.x-=i.x*o,n.y-=i.y*o,e}var M=t=>t.slice(1).reduce((s,e,i)=>s+Math.hypot(e.x-t[i].x,e.y-t[i].y),0),R=(t,s)=>{const e=t.map(n=>n.x),i=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-s),t:Math.floor(Math.min(...i)-s),r:Math.ceil(Math.max(...e)+s),b:Math.ceil(Math.max(...i)+s)}},D=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",s=>(this.listeners.add(s),()=>{this.listeners.delete(s)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const s of[...this.flowEls.values(),...this.beadEls.values()])s.remove();this.dot?.remove(),_(this)}}),c(this,"played",!1),c(this,"onSettle",()=>{this.played&&!this.byMode()&&this.markVisit(),this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const i=this.introEnd?.currentTime,n=i!=null?Number(i):E()-this.t0,r=new Set([...this.plans].filter(([,a])=>a.end<=n).map(([a])=>a)),{plans:h,factor:o}=this.plan(this.ordered(e),this.factor);for(const a of r){const l=this.plans.get(a);l&&h.set(a,l)}this.factor=o,this.plans=h,this.build(r,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const s=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(i=>!!i.flow)]);s!==this.signature&&(this.signature=s,A(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",s=>{if(!this.lastSend){this.lastSend={v:s};return}s===void 0||s===this.lastSend.v||(this.lastSend={v:s},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}A(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=F(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=O(this),this.sync()}publish(){const t=this.hasLines(),s=this.host.model(),e=this.modes(),i=s.edges.some(r=>r.flow)||!!s.motion.pulse||!!s.motion.packet?.repeat,n={canLoop:s.motion.animated&&i&&t&&!e.reduce&&!e.forced,runShown:s.motion.animated&&s.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const r of this.listeners)r()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}byMode(){const t=this.modes();return t.held||t.print||t.reduce||t.forced}markVisit(){const t=this.host.fig;if(!(!t.hasAttribute("data-first-visit")||!t.id))try{localStorage.setItem(G(t),"1")}catch{}}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const s=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=s-.5,this.sync()}holdChanged(){this.modes().held&&A(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,s=this.host.model(),e=this.modes(),i=this.entrance();(i==="pending"||i==="running")&&(e.held||e.print||e.reduce||e.forced)?A(t):i==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!i&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(s,e),this.publish()}ordered(t){const s=this.host.model(),e=[...t.lines];return s.type==="schema"?e.sort((i,n)=>i.pts[0].y-n.pts[0].y||i.pts[0].x-n.pts[0].x||i.i-n.i):e.sort((i,n)=>i.i-n.i),e}plan(t,s){const e=this.t,i=this.host.model().type==="sequence",n=i?e.step:e.stagger,r=t.map(a=>{const l=this.lineEl(a)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(a.pts),m=i?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=i?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,i?e.slower:0)}});let h=1;for(let a=1;a{const d=l*n*h;o.set(a.i,{start:d+r[l].lead,dur:r[l].dur,end:d+r[l].tail})}),{plans:o,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.played=!0,this.t0=E();const{plans:s,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=s,this.build(new Set,!0)}build(t,s){const e=this.host.geo(),i=this.host.fig,{P:n}=this.host,r=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const o=i.querySelector(`.${n}-ink`),a=o?.querySelector(`.${n}-svg`);if(!o||!a)return;this.defs=y("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),a.after(this.defs);const l=y("defs",{},this.defs),d=(u,p=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),p.add(u),u);let m=0;for(const u of e.lines){const p=this.plans.get(u.i),f=this.lineEl(u);if(!p||!f)continue;if(m=Math.max(m,p.end),t.has(u.i)){f.removeAttribute("mask");continue}const w=`${this.host.base}-reveal-${u.i}`,k=y("mask",{id:w,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),x=f.querySelector(`.${n}-line`);if(x){const b=x.getTotalLength(),B=y("path",{d:x.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${b} ${b+8}`,"stroke-dashoffset":b},k);d(B.animate([{strokeDashoffset:`${b}px`},{strokeDashoffset:"0px"}],{duration:p.dur,delay:p.start,easing:r.inOut,fill:"both"}))}const S=f.querySelector(`.${n}-tip`);if(S){const b=y("path",{d:S.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:r.slow,delay:p.start+.85*p.dur,easing:r.out,fill:"both"}))}const $=f.querySelector(`.${n}-dot`);if($){const b=y("circle",{cx:$.getAttribute("cx")??0,cy:$.getAttribute("cy")??0,r:Number($.getAttribute("r")??3)+1,fill:"#fff"},k);d(b.animate([{opacity:0},{opacity:1}],{duration:r.fast,delay:p.start,easing:r.out,fill:"both"}))}f.setAttribute("mask",`url(#${w})`)}if(s&&this.host.model().type==="sequence"){const u=getComputedStyle(i),p=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),w=i.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((k,x)=>{const S=w[x]?.querySelector(`.${n}-mlabel`),$=this.plans.get(k.i);S&&$&&p&&f&&d(S.animate([{color:p},{color:f}],{duration:r.slower,delay:$.start-r.base,easing:r.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(i.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.markVisit(),this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,s){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||s.reduce||s.forced||s.print||s.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,s){s.add(t);const e=()=>{s.delete(t)};return t.finished.then(e,e),s===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,s){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),s).finished.then(e=>{e.cancel()})}overlay(t,s,e){const i=this.host.fig.querySelector(`.${this.host.P}-ink`),n=i?.querySelector(`.${this.host.P}-svg`);if(!i||!n)return null;const r=this.host.tokens(),h=v(t,r?.head??8),o=R(h,s),a=y("svg",{class:`${this.host.P}-${e}`,width:o.r-o.l,height:o.b-o.t,viewBox:`${o.l} ${o.t} ${o.r-o.l} ${o.b-o.t}`,"aria-hidden":"true",focusable:"false"});a.style.left=`${o.l}px`,a.style.top=`${o.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(a),{svg:a,d:P(h,t.from===t.to?r?.radiusXs??4:r?.radius??8),pts:h}}visible(t,s){const e=this.host.geo();let i=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const r=(n.box.t+n.box.b)/2,h=s.some((o,a)=>a>0&&Math.abs(o.y-s[a-1].y)<.5&&Math.abs(r-o.y)<1.5);i+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(s)-i}flow(t,s){const e=t.lines.find(o=>o.i===s);if(!e)return;const i=this.host.tokens();if(e.kind==="dashed"){if(this.visible(e,v(e,i?.head??8))<48)return;const o=this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${s}"] .${this.host.P}-line`);if(!o)return;const a=(i?.dash??6)+(i?.dashGap??4);this.track(o.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-a}px`}],{duration:a/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops);return}let n=this.flowEls.get(s);if(n&&!n.isConnected&&(this.flowEls.delete(s),n=void 0),!n){const o=i?.space("1")??4,a=this.overlay({...e,pts:v(e,o)},e.width+2,"flow");if(!a)return;if(this.visible(e,v(e,i?.head??8))<48){a.svg.remove();return}const l=i?.cut??2;y("path",{d:a.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},a.svg),n=a.svg,this.flowEls.set(s,n)}n.style.display="";const r=n.firstElementChild,h=this.t.flowPeriod;this.track(r.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,s){const i=this.host.model().edges.find(n=>n.from===t&&n.to===s);return i?this.host.geo()?.lines.find(n=>n.i===i.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,s){const e=this.host.tokens();for(;t===this.loopGen;){for(let i=1;it===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(s,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const i=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=i;try{await i.finished}finally{this.repeatGap===i&&(this.repeatGap=null),i.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),s=t.motion.packet?.path;if(!t.motion.animated||!s||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(s[s.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const i=++this.runGen;this.packetRun(s,this.runAnims,()=>i===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&i===this.runGen&&(this.waiting=!1,this.send())})}quiet(t,s){const e=this.host.P,i=this.host.fig,n=i.querySelectorAll(`.${e}-msg`);s.forEach((r,h)=>{const o=t>=0&&h>t;n[h]?.toggleAttribute("data-ahead",o),i.querySelector(`.${e}-edge[data-edge="${r.i}"]`)?.toggleAttribute("data-ahead",o)})}stopRun(){this.runGen++,this.runAt=-1,this.host.fig.querySelectorAll("[data-ahead]").forEach(t=>t.removeAttribute("data-ahead"));for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const s=this.host.geo();if(!s?.lines.length)return;for(const o of this.runAnims)o.cancel();this.runAnims.clear();const e=++this.runGen,i=()=>e===this.runGen,n=this.ordered(s),r=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let o=t;o{if(!q(o))throw o})}};function N(t){const s=[],e=[],{pulse:i,packet:n}=t.motion;i&&n&&s.push("a figure names both a pulse and a packet: it has one mover at most");const r=i??n?.path,h=i?"pulse":"packet",o=new Set;if(r){for(const a of r)t.byId.has(a)||s.push(`the ${h} names ${a}, which is not a node`);for(let a=1;ad.from===r[a-1]&&d.to===r[a]);l?o.add(l.i):s.push(`the ${h} goes from ${r[a-1]} to ${r[a]}, and no line joins them in that direction`)}}for(const a of t.edges)a.flow&&(o.has(a.i)&&s.push(`the line from ${a.from} to ${a.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),a.label||e.push(`the line from ${a.from} to ${a.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:s,warnings:e}}function z(t){return new D(t)}(function(t){"use strict";var s=t._;function e(i,n,r){var h=document.createElement("button");return h.type="button",h.className="btn "+i,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),r&&r(h),h.appendChild(document.createTextNode(n)),h}s.diagramMotion=function(i,n,r){var h=N(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var o=z(n),a=i.querySelector(".diagram-foot"),l=null,d=null;a&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){o.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var w=document.createElement("span");w.className="btn-check",w.setAttribute("aria-hidden","true"),f.appendChild(w)}),l.hidden=d.hidden=!0,a.appendChild(l),a.appendChild(d));function m(){var f=o.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=o.subscribe(m);m();var p=r&&r.packet?r.packet.send:void 0;return o.sendValue("__diagramSend"in i?i.__diagramSend:p),o.sendValue(p),i.__diagramSend=p,{redrawn:o.redrawn,sendValue:function(f){o.sendValue(f),i.__diagramSend=f},destroy:function(){u(),o.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); +(()=>{var T=Object.defineProperty,G=(t,i,e)=>i in t?T(t,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[i]=e,c=(t,i,e)=>G(t,typeof i!="symbol"?i+"":i,e);function P(t,i,e=0){const s=h=>String(Math.round(h*100)/100);let n=`M${s(t[0].x)} ${s(t[0].y)}`;for(let h=1;h`basalt-diagram-entrance:${location.pathname}#${t.id}`;function x(t){const i=t.getAttribute("data-entrance");i!=="pending"&&i!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}var g;function _(t){if(!g){const i=()=>{for(const h of g?.figs??[])h.sync()},e=()=>{for(const h of g?.figs??[])x(h.host.fig);i()},s=new IntersectionObserver(h=>{for(const a of h)for(const o of g?.figs??[])o.drawing===a.target&&o.seen(a)},{threshold:Array.from({length:21},(h,a)=>a/20)}),n=new MutationObserver(h=>{for(const a of h){if(a.target===document.documentElement){for(const o of g?.figs??[])o.holdChanged();continue}for(const o of g?.figs??[])o.host.fig===a.target&&o.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const r=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of r)h.addEventListener("change",i);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",i),g={figs:new Set,io:s,mo:n,media:r,onChange:i,onPrint:e}}return g.figs.add(t),t.drawing&&g.io.observe(t.drawing),g.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),g}function F(t){if(g&&(g.figs.delete(t),t.drawing&&g.io.unobserve(t.drawing),!g.figs.size)){g.io.disconnect(),g.mo.disconnect();for(const i of g.media)i.removeEventListener("change",g.onChange);window.removeEventListener("beforeprint",g.onPrint),document.removeEventListener("visibilitychange",g.onChange),g=void 0}}function I(t){const i=getComputedStyle(t),e=h=>i.getPropertyValue(`--basalt-${h}`).trim(),s=h=>{const a=e(h),o=parseFloat(a);return/ms$/.test(a)?o:/s$/.test(a)?o*1e3:o||0},n=h=>parseFloat(e(h))||0,r=h=>e(`ease-${h}`)||"ease";return{lineMin:s("duration-diagram-line-min"),lineMax:s("duration-diagram-line-max"),stagger:s("duration-diagram-stagger"),step:s("duration-diagram-step"),arrow:s("duration-diagram-arrow"),limit:s("duration-diagram-limit"),legMin:s("duration-diagram-leg-min"),legMax:s("duration-diagram-leg-max"),rest:s("duration-diagram-rest"),pause:s("duration-diagram-pause"),repeat:s("duration-diagram-repeat"),fast:s("duration-fast"),base:s("duration-base"),slow:s("duration-slow"),slower:s("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:r("in-out"),out:r("out"),in:r("in")}}var L=(t,i,e)=>Math.max(i,Math.min(e,t)),V="http://www.w3.org/2000/svg",w=(t,i,e)=>{const s=document.createElementNS(V,t);for(const[n,r]of Object.entries(i))s.setAttribute(n,String(r));return e?.appendChild(s),s},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",R={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function v(t,i){const e=t.pts.map(o=>({...o})),s=R[t.dir],n=e[e.length-1],r=e[e.length-2],h=Math.hypot(n.x-r.x,n.y-r.y),a=Math.min(i,Math.max(0,h-.5));return n.x-=s.x*a,n.y-=s.y*a,e}var M=t=>t.slice(1).reduce((i,e,s)=>i+Math.hypot(e.x-t[s].x,e.y-t[s].y),0),N=(t,i)=>{const e=t.map(n=>n.x),s=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-i),t:Math.floor(Math.min(...s)-i),r:Math.ceil(Math.max(...e)+i),b:Math.ceil(Math.max(...s)+i)}},D=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",i=>(this.listeners.add(i),()=>{this.listeners.delete(i)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const i of[...this.flowEls.values(),...this.beadEls.values()])i.remove();this.dot?.remove(),F(this)}}),c(this,"played",!1),c(this,"onSettle",()=>{this.played&&!this.byMode()&&this.markVisit(),this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const s=this.introEnd?.currentTime,n=s!=null?Number(s):E()-this.t0,r=new Set([...this.plans].filter(([,o])=>o.end<=n).map(([o])=>o)),{plans:h,factor:a}=this.plan(this.ordered(e),this.factor);for(const o of r){const l=this.plans.get(o);l&&h.set(o,l)}this.factor=a,this.plans=h,this.build(r,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const i=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(s=>!!s.flow)]);i!==this.signature&&(this.signature=i,x(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",i=>{if(!this.lastSend){this.lastSend={v:i};return}i===void 0||i===this.lastSend.v||(this.lastSend={v:i},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}x(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=I(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=_(this),this.sync()}publish(){const t=this.hasLines(),i=this.host.model(),e=this.modes(),s=i.edges.some(r=>r.flow)||!!i.motion.pulse||!!i.motion.packet?.repeat,n={canLoop:i.motion.animated&&s&&t&&!e.reduce&&!e.forced,runShown:i.motion.animated&&i.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const r of this.listeners)r()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}byMode(){const t=this.modes();return t.held||t.print||t.reduce||t.forced}markVisit(){const t=this.host.fig;if(!(!t.hasAttribute("data-first-visit")||!t.id))try{localStorage.setItem(O(t),"1")}catch{}}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const i=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=i-.5,this.sync()}holdChanged(){this.modes().held&&x(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,i=this.host.model(),e=this.modes(),s=this.entrance();(s==="pending"||s==="running")&&(e.held||e.print||e.reduce||e.forced)?x(t):s==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!s&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(i,e),this.publish()}ordered(t){const i=this.host.model(),e=[...t.lines];return i.type==="schema"?e.sort((s,n)=>s.pts[0].y-n.pts[0].y||s.pts[0].x-n.pts[0].x||s.i-n.i):e.sort((s,n)=>s.i-n.i),e}plan(t,i){const e=this.t,s=this.host.model().type==="sequence",n=s?e.step:e.stagger,r=t.map(o=>{const l=this.lineEl(o)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(o.pts),m=s?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=s?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,s?e.slower:0)}});let h=1;for(let o=1;o{const d=l*n*h;a.set(o.i,{start:d+r[l].lead,dur:r[l].dur,end:d+r[l].tail})}),{plans:a,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.played=!0,this.t0=E();const{plans:i,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=i,this.build(new Set,!0)}build(t,i){const e=this.host.geo(),s=this.host.fig,{P:n}=this.host,r=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const a=s.querySelector(`.${n}-ink`),o=a?.querySelector(`.${n}-svg`);if(!a||!o)return;this.defs=w("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),o.after(this.defs);const l=w("defs",{},this.defs),d=(u,p=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),p.add(u),u);let m=0;for(const u of e.lines){const p=this.plans.get(u.i),f=this.lineEl(u);if(!p||!f)continue;if(m=Math.max(m,p.end),t.has(u.i)){f.removeAttribute("mask");continue}const b=`${this.host.base}-reveal-${u.i}`,$=w("mask",{id:b,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),S=f.querySelector(`.${n}-line`);if(S){const y=S.getTotalLength(),C=w("path",{d:S.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${y} ${y+8}`,"stroke-dashoffset":y},$);d(C.animate([{strokeDashoffset:`${y}px`},{strokeDashoffset:"0px"}],{duration:p.dur,delay:p.start,easing:r.inOut,fill:"both"}))}const k=f.querySelector(`.${n}-tip`);if(k){const y=w("path",{d:k.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},$);d(y.animate([{opacity:0},{opacity:1}],{duration:r.slow,delay:p.start+.85*p.dur,easing:r.out,fill:"both"}))}const A=f.querySelector(`.${n}-dot`);if(A){const y=w("circle",{cx:A.getAttribute("cx")??0,cy:A.getAttribute("cy")??0,r:Number(A.getAttribute("r")??3)+1,fill:"#fff"},$);d(y.animate([{opacity:0},{opacity:1}],{duration:r.fast,delay:p.start,easing:r.out,fill:"both"}))}f.querySelectorAll(`.${n}-crow, .${n}-ring`).forEach(y=>{const z=y.tagName.toLowerCase()==="circle"?w("circle",{cx:y.getAttribute("cx")??0,cy:y.getAttribute("cy")??0,r:Number(y.getAttribute("r")??3)+1,fill:"#fff"},$):w("path",{d:y.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":3},$),U=y.getAttribute("data-end")==="from";d(z.animate([{opacity:0},{opacity:1}],U?{duration:r.fast,delay:p.start,easing:r.out,fill:"both"}:{duration:r.slow,delay:p.start+.85*p.dur,easing:r.out,fill:"both"}))}),f.setAttribute("mask",`url(#${b})`)}if(i&&this.host.model().type==="sequence"){const u=getComputedStyle(s),p=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),b=s.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach(($,S)=>{const k=b[S]?.querySelector(`.${n}-mlabel`),A=this.plans.get($.i);k&&A&&p&&f&&d(k.animate([{color:p},{color:f}],{duration:r.slower,delay:A.start-r.base,easing:r.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(s.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.markVisit(),this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,i){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||i.reduce||i.forced||i.print||i.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,i){i.add(t);const e=()=>{i.delete(t)};return t.finished.then(e,e),i===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,i){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),i).finished.then(e=>{e.cancel()})}overlay(t,i,e){const s=this.host.fig.querySelector(`.${this.host.P}-ink`),n=s?.querySelector(`.${this.host.P}-svg`);if(!s||!n)return null;const r=this.host.tokens(),h=v(t,r?.head??8),a=N(h,i),o=w("svg",{class:`${this.host.P}-${e}`,width:a.r-a.l,height:a.b-a.t,viewBox:`${a.l} ${a.t} ${a.r-a.l} ${a.b-a.t}`,"aria-hidden":"true",focusable:"false"});o.style.left=`${a.l}px`,o.style.top=`${a.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(o),{svg:o,d:P(h,t.from===t.to?r?.radiusXs??4:r?.radius??8),pts:h}}visible(t,i){const e=this.host.geo();let s=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const r=(n.box.t+n.box.b)/2,h=i.some((a,o)=>o>0&&Math.abs(a.y-i[o-1].y)<.5&&Math.abs(r-a.y)<1.5);s+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(i)-s}flow(t,i){const e=t.lines.find(a=>a.i===i);if(!e)return;const s=this.host.tokens();if(e.kind==="dashed"){if(this.visible(e,v(e,s?.head??8))<48)return;const a=this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${i}"] .${this.host.P}-line`);if(!a)return;const o=(s?.dash??6)+(s?.dashGap??4);this.track(a.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-o}px`}],{duration:o/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops);return}let n=this.flowEls.get(i);if(n&&!n.isConnected&&(this.flowEls.delete(i),n=void 0),!n){const a=s?.space("1")??4,o=this.overlay({...e,pts:v(e,a)},e.width+2,"flow");if(!o)return;if(this.visible(e,v(e,s?.head??8))<48){o.svg.remove();return}const l=s?.cut??2;w("path",{d:o.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},o.svg),n=o.svg,this.flowEls.set(i,n)}n.style.display="";const r=n.firstElementChild,h=this.t.flowPeriod;this.track(r.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,i){const s=this.host.model().edges.find(n=>n.from===t&&n.to===i);return s?this.host.geo()?.lines.find(n=>n.i===s.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,i){const e=this.host.tokens();for(;t===this.loopGen;){for(let s=1;st===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(i,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const s=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=s;try{await s.finished}finally{this.repeatGap===s&&(this.repeatGap=null),s.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),i=t.motion.packet?.path;if(!t.motion.animated||!i||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(i[i.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const s=++this.runGen;this.packetRun(i,this.runAnims,()=>s===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&s===this.runGen&&(this.waiting=!1,this.send())})}quiet(t,i){const e=this.host.P,s=this.host.fig,n=s.querySelectorAll(`.${e}-msg`);i.forEach((r,h)=>{const a=t>=0&&h>t;n[h]?.toggleAttribute("data-ahead",a),s.querySelector(`.${e}-edge[data-edge="${r.i}"]`)?.toggleAttribute("data-ahead",a)})}stopRun(){this.runGen++,this.runAt=-1,this.host.fig.querySelectorAll("[data-ahead]").forEach(t=>t.removeAttribute("data-ahead"));for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const i=this.host.geo();if(!i?.lines.length)return;for(const a of this.runAnims)a.cancel();this.runAnims.clear();const e=++this.runGen,s=()=>e===this.runGen,n=this.ordered(i),r=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let a=t;a{if(!q(a))throw a})}};function B(t){const i=[],e=[],{pulse:s,packet:n}=t.motion;s&&n&&i.push("a figure names both a pulse and a packet: it has one mover at most");const r=s??n?.path,h=s?"pulse":"packet",a=new Set;if(r){for(const o of r)t.byId.has(o)||i.push(`the ${h} names ${o}, which is not a node`);for(let o=1;od.from===r[o-1]&&d.to===r[o]);l?a.add(l.i):i.push(`the ${h} goes from ${r[o-1]} to ${r[o]}, and no line joins them in that direction`)}}for(const o of t.edges)o.flow&&(a.has(o.i)&&i.push(`the line from ${o.from} to ${o.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),o.label||e.push(`the line from ${o.from} to ${o.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:i,warnings:e}}function j(t){return new D(t)}(function(t){"use strict";var i=t._;function e(s,n,r){var h=document.createElement("button");return h.type="button",h.className="btn "+s,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),r&&r(h),h.appendChild(document.createTextNode(n)),h}i.diagramMotion=function(s,n,r){var h=B(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var a=j(n),o=s.querySelector(".diagram-foot"),l=null,d=null;o&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){a.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var b=document.createElement("span");b.className="btn-check",b.setAttribute("aria-hidden","true"),f.appendChild(b)}),l.hidden=d.hidden=!0,o.appendChild(l),o.appendChild(d));function m(){var f=a.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=a.subscribe(m);m();var p=r&&r.packet?r.packet.send:void 0;return a.sendValue("__diagramSend"in s?s.__diagramSend:p),a.sendValue(p),s.__diagramSend=p,{redrawn:a.redrawn,sendValue:function(f){a.sendValue(f),s.__diagramSend=f},destroy:function(){u(),a.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index 2fc4a0b6..544c37a9 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--_gw, var(--basalt-space-10))}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node{--_Mh: var(--_D) var(--_mh, auto);min-height:var(--_Mh, auto)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"])>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--_gw, var(--basalt-space-10))}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);--_Rows: var(--_D) var(--_rows, none);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));grid-template-rows:var(--_Rows, none);gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=schema][data-marks]>.diagram-drawing{--_col-gap: calc(var(--basalt-space-12) + var(--basalt-space-3))}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node{--_Mh: var(--_D) var(--_mh, auto);min-height:var(--_Mh, auto)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-crow{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:butt;stroke-linejoin:miter;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-ring{fill:var(--_ground);stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-crow,.diagram-ring,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"]:not([data-marks]))>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 792px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 1076px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1360px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1644px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram :is(.diagram-crow,.diagram-ring){stroke:CanvasText}.diagram .diagram-ring{fill:Canvas}.diagram .diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:GrayText}.diagram .diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 037903f1..0586e834 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,12 +1,12 @@ -(()=>{var Ue=["top","right","bottom","left"],Je=["main","plain","dashed"],Xe=[2,3,4,5,6],rt=t=>t==null||t===""?void 0:String(t),ut=t=>Object.assign(Object.create(null),t),gt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function wt(t,e={}){const s=e.checks!==!1,i=[],r=y=>{i.push(y)},o=t.legend??{},a={};for(const y of["main","plain","dashed","focal","group","activation"]){const b=rt(o[y]);b&&(a[y]=b)}const l=t.stepLabel,d=typeof l=="function"?y=>String(l(y)):typeof l=="string"?(y=>l.replace("{n}",String(y))):y=>`Step ${y}`,m=t.shapeLabels??{},f={terminal:rt(m.terminal)??"Start or end",step:rt(m.step)??"Step",decision:rt(m.decision)??"Decision"},c=t.heading===void 0?3:Xe.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),g=(y,b)=>y==null?"plain":Je.includes(y)?y:(r(`"${String(y)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),x=y=>{if(y!=null){if(Ue.includes(y))return y;r(`"${String(y)}" is not a side (top, right, bottom or left): the derived side is used`)}},h=(y,b)=>typeof y=="number"&&Number.isInteger(y)&&y>=1?y:(t.layout==="auto"&&y==null||r(`${b} is ${JSON.stringify(y)}, not a whole number from 1: it is placed at 1`),1),u=[],S=[];let I=[];const T=[],M=[],A=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(A)||r(`"${String(A)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),A==="architecture"||A==="flowchart"){for(const y of t.nodes??[]){const b=A==="flowchart"&&y.shape==="decision"?"decision":A==="flowchart"&&y.shape==="terminal"?"terminal":"box",p=String(y.id??""),k=h(y.row,`the row of ${p}`);u.push({id:p,i:u.length,name:String(y.name??""),kind:b==="decision"?void 0:rt(y.kind),detail:b==="decision"?void 0:rt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:h(y.col,`the column of ${p}`),row:k,row2:k,branch:!!y.branch,shape:b,group:A==="architecture"?rt(y.group):void 0,mark:A==="architecture"?Wt(y.mark):void 0})}if(A==="architecture"){const y=(t.groups??[]).map($=>({id:String($.id??""),label:String($.label??""),parent:rt($.parent)})),b=new Map(y.map($=>[$.id,$])),p=$=>{if(!$.parent)return 1;const w=b.get($.parent);return w?w.parent===$.id||w.id===$.id?(r(`the groups "${$.label}" and "${w.label}" are each other's parent`),$.parent=void 0,1):w.parent?(r(`the group "${$.label}" is a third level: groups nest two deep`),$.parent=void 0,1):2:(r(`the group "${$.label}" names the parent "${$.parent}", which is not a group`),$.parent=void 0,1)},k=y.map(p);y.forEach(($,w)=>T.push({...$,depth:k[w],members:u.filter(C=>C.group===$.id).map(C=>C.id),all:[]}));for(const $ of T)$.all=[...$.members,...T.filter(w=>w.parent===$.id).flatMap(w=>w.members)];T.sort(($,w)=>$.depth-w.depth)}}else if(A==="data-flow"){I=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const y=new Map(I.map((b,p)=>[b.id,p+1]));for(const b of t.nodes??[]){const p=String(b.id??""),k=String(b.lane??""),$=y.get(k);$===void 0&&r(`a node (${p}) names the lane "${k}", which is not in lanes`);const w=u.length+1;u.push({id:p,i:u.length,name:String(b.name??""),kind:d(w),detail:rt(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:h(b.col,`the column of ${p}`),row:$??1,row2:$??1,branch:!1,shape:"box",lane:$??1,laneLabel:I[($??1)-1]?.label??k,step:w,mark:Wt(b.mark)})}}else if(A==="sequence"){(t.participants??[]).forEach((k,$)=>{const w=String(k.name??"");u.push({id:String(k.id??""),i:$,name:w,kind:rt(k.kind),mono:!1,focal:!!k.focal,col:$+1,row:1,row2:1,branch:!1,shape:"participant",short:rt(k.short)??w,mark:Wt(k.mark)})});let y=0;const b=new Map(u.map(k=>[k.id,k.col])),p=(k,$)=>{let w=1/0,C=-1/0;for(const q of k??[]){if(!q||typeof q!="object")continue;if("band"in q){$>0&&r(`the band "${String(q.band)}" is inside a frame: a band is the whole figure's`),M.push({band:String(q.band??"")});continue}if("frame"in q){if($>=2){r("a frame is a third level: frames nest two deep");continue}const ot=q.frame==="alt"||q.frame==="loop"||q.frame==="opt"?q.frame:"opt",V=ot==="alt"?q.branches??[]:[{label:q.label,steps:q.steps}];ot==="alt"&&V.length<2&&r("an alt frame has one branch: it needs two or more");const P=String(V[0]?.label??"");P.length>40&&r(`the frame label "${P}" is over 40 characters`);const Z=M.length;M.push({open:ot,label:P,depth:$+1,a:0,b:0}),V.forEach((U,at)=>{if(at){const kt=String(U.label??"");kt.length>40&&r(`the frame label "${kt}" is over 40 characters`),M.push({otherwise:kt,depth:$+1})}U.steps?.length||r(`a frame or branch ("${String(U.label??"")}") is empty`);const[ct,It]=p(U.steps??[],$+1);w=Math.min(w,ct),C=Math.max(C,It);const $t=M[Z];$t.a=Math.min($t.a||1/0,ct),$t.b=Math.max($t.b,It)}),M.push({close:$+1});continue}y++;const F=String(q.label??"");F.includes(` -`)&&r(`message ${y}'s label has a break: a message's second line is its note`);const X=String(q.from??""),nt=String(q.to??"");M.push({n:y,from:X,to:nt,label:yt(F),note:rt(q.note),kind:g(q.kind,`message ${y}`),activate:q.activate===!0||void 0,deactivate:q.deactivate===!0||void 0});const z=b.get(X)??1,G=b.get(nt)??1,et=z===G?z===u.length?z-1:z+1:z;w=Math.min(w,z,G,et),C=Math.max(C,z,G,et)}return[w,C]};p(t.steps??[],0);for(const k of M)"open"in k&&!Number.isFinite(k.a)&&(k.a=1,k.b=Math.max(1,u.length))}else if(A==="schema")for(const y of t.tables??[]){const b=String(y.name??""),[p,k]=Array.isArray(y.row)?y.row:[y.row,y.row],$=h(p,`the row of ${b}`),w=Math.max($,h(k,`the last row of ${b}`)),C=y.more===void 0||y.more===null?void 0:Number.isInteger(y.more)&&y.more>0?y.more:(r(`${b}'s "more" is ${JSON.stringify(y.more)}, not a whole number from 1: it is left out`),void 0);u.push({id:b,i:u.length,name:b,mono:!0,focal:!!y.focal,col:h(y.col,`the column of ${b}`),row:$,row2:w,branch:!1,shape:"table",more:C,columns:(y.columns??[]).map(q=>({name:String(q.name??""),type:rt(q.type),key:q.key==="PK"||q.key==="FK"?q.key:(q.key!==void 0&&q.key!==null&&r(`${b}.${String(q.name)}'s key is "${String(q.key)}", not PK or FK: it is left out`),void 0)}))})}let B=!1;if(t.layout==="auto"&&(A==="architecture"||A==="flowchart"||A==="schema")){const y=A==="schema"?t.tables:t.nodes;s&&(y??[]).some(p=>p&&(p.col!==void 0||p.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(B=!0);for(const p of u){const k=b?.[p.id];p.col=k?.col??1,p.row=p.row2=k?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${A}`);((A==="schema"?t.tables:A==="sequence"?t.participants:t.nodes)??[]).forEach((y,b)=>{if(!y||y.href===void 0||y.href===null)return;const p=String(y.href);if(A==="sequence"){r(`${u[b]?.id}: a participant cannot be a link (href)`);return}if(!p){r(`${u[b]?.id}'s href is empty`);return}const k=u[b];k&&(k.href=p,k.blank=y.target==="_blank")});const j=new Map;for(const y of u)y.id?j.has(y.id)&&r(`the id "${y.id}" is used twice`):r("a node has no id"),j.set(y.id,y);if(A==="schema")(t.tables??[]).forEach(y=>(y.columns??[]).forEach((b,p)=>{const k=rt(b.references);if(!k)return;const[$,w]=k.split("."),C=j.get($??""),q=C?.columns?.findIndex(X=>X.name===w)??-1;if(!C||q<0){r(`${String(y.name)}.${String(b.name)} references ${k}, which is not a shown column`);return}const F=j.get(String(y.name??""));F.columns[p].ref={table:$,column:w,row:q},S.push({i:S.length,from:F.id,to:$,kind:"plain",fromRow:p,toRow:q,fk:!0})}));else if(A!=="sequence")for(const y of t.edges??[]){const b=String(y.from??""),p=String(y.to??"");if(!j.has(b)||!j.has(p)){r(`a line names ${j.has(b)?p:b}, which is not a node`);continue}const k=rt(y.label),$=k?.split(` -`)??[];$.length>2&&r(`the label "${yt(k)}" has more than one break: a label is two lines at most`),$.some(w=>w.length>te)&&r(`a line of the label "${yt(k)}" is over ${te} characters: longer words belong in the node or the summary`),S.push({i:S.length,from:b,to:p,kind:g(y.kind,`the line from ${b} to ${p}`),label:k,fromSide:x(y.fromSide),toSide:x(y.toSide),flow:A!=="flowchart"&&y.flow===!0?!0:void 0})}else for(const y of M)"n"in y&&(!j.has(y.from)||!j.has(y.to))&&r(`message ${y.n} names ${j.has(y.from)?y.to:y.from}, which is not a participant`);if(s&&A!=="sequence"&&!B){const y=new Map;for(const b of u)for(let p=b.row;p<=b.row2;p++){const k=`${b.col}:${p}`;y.has(k)&&r(`${b.id} and ${y.get(k)} share the cell at column ${b.col}, row ${p}`),y.set(k,b.id)}}if(s&&!B){for(const b of T){const p=b.all.map(w=>j.get(w));if(!p.length)continue;const k={c1:Math.min(...p.map(w=>w.col)),c2:Math.max(...p.map(w=>w.col)),r1:Math.min(...p.map(w=>w.row)),r2:Math.max(...p.map(w=>w.row2))};for(const w of u)!b.all.includes(w.id)&&w.col>=k.c1&&w.col<=k.c2&&w.row>=k.r1&&w.row<=k.r2&&r(`${w.id} is inside the box of the group "${b.label}" but not a member`);const $=p.map(w=>w.i);Math.max(...$)-Math.min(...$)+1!==$.length&&r(`the members of the group "${b.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const b of u)b.group&&!T.some(p=>p.id===b.group)&&r(`${b.id} names the group "${b.group}", which is not in groups`);u.filter(b=>b.focal).length>1&&r("more than one node is focal: a diagram has one at most");const y=new Set(A==="sequence"?M.flatMap(b=>"n"in b?[b.kind]:[]):S.map(b=>b.kind));y.has("main")&&!a.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),y.has("dashed")&&!a.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),u.some(b=>b.focal)&&!a.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const Q=A==="architecture"||A==="data-flow",L=y=>Array.isArray(y)&&y.length>1?y.map(String):void 0,N=Q&&t.packet&&typeof t.packet=="object"?t.packet:void 0,_=N&&L(N.path),E={animated:t.motion==="animated",pulse:Q?L(t.pulse):void 0,packet:_?{path:_,repeat:N.repeat===!0,send:N.send}:void 0,run:A==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(s)for(const y of u){const b=y.mark?.says;if(!b?.length)continue;const p=[y.name,y.kind,y.detail,y.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(k=>p.includes(k.toLowerCase()))||r(`${y.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const O=[];if(A==="sequence"){const y=new Map,b=new Map;for(const p of M)"n"in p&&(b.set(p.from,p.n),b.set(p.to,p.n));for(const p of M)if("n"in p){if(p.activate){const k=y.get(p.to)??[];if(k.length>=3)r(`message ${p.n} opens a fourth bar on ${p.to}: three deep at most`);else{const $={who:p.to,from:p.n,to:p.n,depth:k.length+1};k.push($),O.push($),y.set(p.to,k)}}if(p.deactivate){const $=y.get(p.from)?.pop();$?$.to=p.n:r(`message ${p.n} closes a bar on ${p.from}, which has none open`)}}for(const[p,k]of y)for(const $ of k)$.to=Math.max($.from,b.get(p)??$.from)}const R=t.frameLabels??{},D={opt:rt(R.opt)??"Only if",loop:rt(R.loop)??"Repeats",alt:rt(R.alt)??"One of these",else:rt(R.else)??"Otherwise"};let W=Math.max(1,...u.map(y=>y.col));if(e.rtl){for(const b of u)b.col=W-b.col+1;const y=b=>b==="left"?"right":b==="right"?"left":b;for(const b of S)b.fromSide=y(b.fromSide),b.toSide=y(b.toSide);for(const b of M)if("open"in b){const[p,k]=[W-b.b+1,W-b.a+1];b.a=p,b.b=k}W=Math.max(1,...u.map(b=>b.col))}const tt=A==="data-flow"?Math.max(1,I.length):Math.max(1,...u.map(y=>y.row2)),K={type:A,title:String(t.title??""),heading:c,legend:a,nodes:u,byId:j,edges:S,groups:T,lanes:I,steps:M,bars:O,frameWords:D,cols:W,rows:tt,shapeLabels:f,stepWord:d,warnings:i,motion:E,memo:new Map,rtl:e.rtl||void 0,unplaced:B||void 0,text:A==="sequence"&&t.variant==="text"||void 0};if(t.layout==="auto"&&!B&&A!=="schema"&&Ye(K),s)for(const[y,b]of Object.entries(we(K)))b>=48&&r(`${y} grows to ${b}px to hold the lines on one side: use another side`);return s&&u.length>1&&!Ot(K)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),K}function Ye(t){const e=new Set(t.nodes.map(o=>`${o.col},${o.row}`)),n=(o,a)=>{const l=[];for(let d=Math.min(o,a)+1;d{const a=t.byId.get(o.from),l=t.byId.get(o.to),d=l.col>a.col?"right":"left",m=l.row>a.row?"bottom":"top",f=l.col>a.col?"left":"right",c=l.row>a.row?"top":"bottom",g=(h,u,S,I)=>n(h,u).map(T=>I?[T,S]:[S,T]);let x;return a.row===l.row?x=[{sides:[d,f],cells:g(a.col,l.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===l.col?x=[{sides:[m,c],cells:g(a.row,l.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:x=[{sides:[d,c],cells:[...g(a.col,l.col,a.row,!0),[l.col,a.row],...g(a.row,l.row,l.col,!1)]},{sides:[m,f],cells:[...g(a.row,l.row,a.col,!1),[a.col,l.row],...g(a.col,l.col,l.row,!0)]},{sides:[d,f],cells:g(a.col,l.col,a.row,!0)},{sides:[m,c],cells:g(a.row,l.row,a.col,!1)}],x.filter(h=>h.cells.every(([u,S])=>!e.has(`${u},${S}`)))},i=new Map,r=t.edges.map((o,a)=>a).sort((o,a)=>s(t.edges[o]).length-s(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[o].kind==="main")||o-a);for(const o of r){const a=t.edges[o];if(a.fromSide||a.toSide)continue;const l=s(a).find(d=>(i.get(`${a.from}.${d.sides[0]}`)??0)<3&&(i.get(`${a.to}.${d.sides[1]}`)??0)<3);if(l){for(const[d,m]of[[a.from,l.sides[0]],[a.to,l.sides[1]]])i.set(`${d}.${m}`,(i.get(`${d}.${m}`)??0)+1);a.fromSide=l.sides[0],a.toSide=l.sides[1]}}}function Wt(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=rt(e.onLight);if(n)return{onLight:n,onDark:rt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var Pt=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function mt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var te=28,Ft=t=>t.includes(` -`)?2:1,yt=t=>t.replace(/\n/g," "),vt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function ee(t,e){return t.legend[e]}function Qe(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function Pe(t,e){return mt(t,`sentence:${e.i}`,()=>tn(t,e))}function tn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const s=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name})`);s.length&&n.push(`References ${s.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const s=t.steps.filter(o=>"n"in o&&o.from===e.id).length,i=t.steps.filter(o=>"n"in o&&o.to===e.id).length;n.push(vt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${s} ${s===1?"message":"messages"} and receives ${i}.`);const r=ne(t,e);r&&n.push(r.trim())}else{const s=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?Qe(t,e):e.kind;if(n.push(vt(s?`${e.name}, ${s}`:e.name)),e.detail&&n.push(vt(e.detail)),e.group){const o=t.groups.find(l=>l.id===e.group),a=o?.parent?t.groups.find(l=>l.id===o.parent):void 0;o&&n.push(a?`In ${o.label}, in ${a.label}.`:`In ${o.label}.`)}const i=t.edges.filter(o=>o.to===e.id).map(o=>`${t.byId.get(o.from).name}${o.label?` (${yt(o.label)})`:""}`),r=t.edges.filter(o=>o.from===e.id).map(o=>`${t.byId.get(o.to).name}${o.label?` (${yt(o.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(vt(t.legend.focal)),n.join(" ")}function ne(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function en(t,e,n,s){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),o=n.target;if(!r||!o||!r.contains(o)||!t.querySelector(`.${e}-edge`))return;const a=o.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===s?null:a.dataset.node??null:null}function oe(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const s=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&s.push(i);return{t,a:e??{},c:s}}var nn={"&":"&","<":"<",">":">",'"':""","'":"'"},it=t=>t.replace(/[&<>"']/g,e=>nn[e]),on=" br img input meta link hr path polygon polyline circle rect line ";function Nt(t,e={}){if(typeof t=="string")return it(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[s,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(s))throw new Error(`diagram: "${s}" is not an attribute name`);n+=i===!0?` ${s}`:` ${s}="${it(String(i))}"`}return on.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(s=>Nt(s,e)).join("")}`}var sn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function bt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function an(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function qt(t,e){const n=e.all.map(s=>t.byId.get(s));return n.length?{c1:Math.min(...n.map(s=>s.col)),c2:Math.max(...n.map(s=>s.col)),r1:Math.min(...n.map(s=>s.row)),r2:Math.max(...n.map(s=>s.row2))}:null}function se(t){return mt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const s=qt(t,n);if(!s)continue;[s.r1===1,s.c2===t.cols,s.r2===t.rows,s.c1===1].forEach((r,o)=>{r&&(e[o]=Math.max(e[o],ae(t,n,o)))})}return e})}function ae(t,e,n){const s=qt(t,e);return t.groups.filter(o=>o.parent===e.id).some(o=>{const a=qt(t,o);return a&&[a.r1===s.r1,a.c2===s.c2,a.r2===s.r2,a.c1===s.c1][n]})?2:1}function re(t){const e=se(t);return e[1]+e[3]}function zt(t){return t.type==="sequence"?t.nodes.length:t.cols}function ie(t){return mt(t,"plan",()=>rn(t))}function rn(t){const e=t.nodes,n=u=>t.type==="data-flow"||!e[u].branch,s=t.edges.map(u=>{const S=t.byId.get(u.from).i,I=t.byId.get(u.to).i,M=e.slice(Math.min(S,I)+1,Math.max(S,I)).every(A=>!n(A.i));return I===S+1&&!(n(S)&&!n(I))?"down":I===S-1?"up":I>S&&n(S)&&!n(I)&&M?"trunk":I>S&&n(S)&&n(I)&&M?"rail":I>S?"end-down":"end-up"}),i=t.edges.map((u,S)=>({e:u,k:S})).filter(({k:u})=>s[u]==="end-down"||s[u]==="end-up"),r=u=>{const S=t.byId.get(u.from).i,I=t.byId.get(u.to).i;return[Math.min(S,I),Math.max(S,I)]},o=(u,S)=>{const[I,T]=r(u),[M,A]=r(S);return I{const S=t.byId.get(u.from).i,[I,T]=r(u);return!n(S)&&e.slice(I+1,T).every(M=>!n(M.i))&&i.every(M=>M.e===u||!o(M.e,u))}),l=i.length>0&&(t.type==="data-flow"||!a),d=u=>{const[S,I]=r(u);return I-S},m=t.edges.map(()=>0);let f=!1;const c=[];for(const u of[...i].sort((S,I)=>d(S.e)-d(I.e)||S.k-I.k)){let S=0;for(const I of c)o(I.e,u.e)&&(S=Math.max(S,m[I.k]+1));m[u.k]=S,S>3&&(f=!0),c.push(u)}const g=Math.max(0,...i.map(({k:u})=>m[u]+1)),x=t.edges.map(()=>.5);for(const u of e){const S=i.filter(({e:M})=>M.from===u.id);if(S.length<2)continue;const I=S.filter(({k:M})=>s[M]==="end-down").sort((M,A)=>d(A.e)-d(M.e)||M.k-A.k);[...S.filter(({k:M})=>s[M]==="end-up").sort((M,A)=>d(M.e)-d(A.e)||A.k-M.k),...I].forEach(({k:M},A,B)=>{x[M]=B.length===2?A===0?1/3:2/3:(A+1)/(B.length+1)})}const h=ut();for(let u=1;u{const N=s[L],_=t.byId.get(Q.from).i,E=t.byId.get(Q.to).i,O=E===u&&(N==="down"||N==="trunk"||N==="rail"||N==="end-down"),R=_===u&&E===u-1&&N==="up",D=E===u-1&&N==="end-up";O&&(N==="trunk"||N==="end-down")&&(A=!0),D&&(B=!0),(O||R||D)&&Q.label&&(T++,M=Math.max(M,N==="trunk"?40:48))}),(T>1||A&&B)&&(M=64);const J=i.filter(({e:Q,k:L})=>s[L]==="end-down"&&t.byId.get(Q.to).i===u).length,j=i.filter(({e:Q,k:L})=>s[L]==="end-up"&&t.byId.get(Q.to).i===u-1).length;M+=20*Math.max(0,J-1)+20*Math.max(0,j-1),h[S.id]=M}return{routes:s,gutter:l,lanes:m,exits:x,gaps:h,third:f,laneCount:g}}var xt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function le(t,e){const n=e==="fk"?"plain":e,s=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...xt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:s,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${s}H${r}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${s-4}L${i} ${s}L${i-8} ${s+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${s}L${i-8} ${s-4}L${i-8} ${s+4}Z`}))}function Et(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...xt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function ce(t,e){return mt(e,`key:${t}`,()=>cn(t,e))}var ln=ce;function cn(t,e){const n=[],s=(o,a,l={})=>n.push(v("li",{class:`${t}-entry`,...l},o,v("span",null,a)));if(e.type==="schema"){const o=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),v("span",null,l)))}if(e.type==="flowchart"){const o=new Set(e.nodes.map(a=>a.shape));o.has("terminal")&&s(Et(t,"terminal"),e.shapeLabels.terminal),o.has("box")&&s(Et(t,"box"),e.shapeLabels.step),o.has("decision")&&s(Et(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(o=>"n"in o?[o.kind]:[]):e.edges.filter(o=>!o.fk).map(o=>o.kind)),r=(o,a)=>v("span",{class:`${t}-key-glyph`,"data-ink":a,"aria-hidden":"true"},o);for(const o of["main","plain","dashed"]){const a=e.legend[o];i.has(o)&&a&&s(e.text?r(o==="main"?"━━▶":o==="dashed"?"┄┄▷":"──▶",o==="main"?"main":"plain"):le(t,o),a,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length&&(s(le(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"}),n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))),e.type==="sequence"){e.bars.length&&s(e.text?r("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...xt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const o=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])o.has(a)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),v("span",null,e.frameWords[a])))}return e.nodes.some(o=>o.focal)&&e.legend.focal&&s(Et(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&s(Et(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function dn(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...xt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function Ht(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function fn(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},Ht(t,n)))];const s=[];return e.type==="data-flow"?s.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&s.push(v("span",{class:`${t}-kind`},n.kind)),s.push(v("span",{class:`${t}-name`},Ht(t,n))),n.detail&&s.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Bt(n.detail).flatMap((i,r)=>[r?" ":"",v("span",{class:`${t}-run`},i)]):n.detail)),s}function un(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},Ht(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((s,i)=>v("span",{class:`${t}-row`,"data-row":i,"data-key":s.key},v("span",{class:`${t}-keyseat`},s.key??""),v("span",{class:`${t}-cname`},s.name),s.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${s.ref.table}`):s.type?v("span",{class:`${t}-ctype`},s.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var de=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function _t(t,e,n,s){const{P:i}=t,r=an(e,s)||s.keep===n.id,o=bt(e,s),a=[`--_c:${n.col}`,`--_r:${n.row}`,`--_r2:${n.row2+1}`];e.type==="data-flow"&&a.push(`--_lc:${n.col+1}`),e.type==="sequence"&&a.push(`--_c2:${n.col+1}`);const l=t.plan;if(l&&n.i>0){const g=gt(l.gaps,n.id)??32,x=gt(s.grow,n.id)??0;a.push(`--_gap:${x?`calc(${de(g)} + var(--basalt-space-4) * ${x})`:de(g)}`)}const d=gt(s.heights,n.id);d&&a.push(`--_h:${d}px`);const m=gt(we(e),n.id);m&&a.push(`--_mh:${m}px`);const f=gt(s.words,n.id);f&&a.push(`--_ww:${f}px`);const c=o?s.stop===n.id?0:-1:s.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:a.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?Pe(e,n):void 0,tabindex:c},n.shape==="decision"?v("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${Pt(n.mark.onLight)};--_md:${Pt(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?un(i,n,e):fn(i,e,n))}function hn(t,e,n){const{P:s}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((l,d)=>v("div",{class:`${s}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},v("span",{class:`${s}-lane-name`},l.label)))),e.type==="architecture")for(const l of e.groups){const d=qt(e,l);if(!d)continue;const m=[0,1,2,3].map(f=>ae(e,l,f));i.push(v("div",{class:`${s}-gbox`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:`--_c:${d.c1};--_c2:${d.c2+1};--_r:${d.r1};--_r2:${d.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${s}-glabel`},l.label)))}if(e.text)return[v("pre",{class:`${s}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${s}-text-ink`},pn(s,e)))];if(e.type==="sequence")return i.push(v("ul",{class:`${s}-cast`},e.nodes.map(l=>v("li",{class:`${s}-actor`,style:e.rtl?`--_ac:${l.col}`:void 0},_t(t,e,l,n))))),i.push(gn(t,e)),i;const r=l=>{const d=l.group?e.groups.find(m=>m.id===l.group):void 0;return d?.parent?e.groups.find(m=>m.id===d.parent):d},o=(l,d,m)=>{const f=t.plan?gt(n.grow,d[0].id)??0:0;return v("div",{class:`${s}-group`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:f?`--_ggrow:${f}`:void 0},v("span",{class:`${s}-glabel`,"aria-hidden":"true"},l.label),m)};let a=0;for(;ah.id===m[c].group):void 0;if(!g){f.push(_t(t,e,m[c],n)),c++;continue}const x=[];for(;c_t(t,e,h,n))))}i.push(o(d,m,f))}return i}function pn(t,e){const n=[],s=o=>v("span",{class:`${t}-tx-name`},o),i=o=>o==="main"?"━▶":o==="dashed"?"┄▷":"─▶";n.push(v("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((o,a)=>[a?" · ":"",s(o.name)])),` -`);let r=0;for(const o of e.steps){const a=" ".repeat(r);if("band"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"band"},`${a}── ${o.band} ──`),` -`);continue}if("open"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},a,v("span",{"data-ink":"op"},`[${o.open}]`),` ${o.label}`),` -`),r++;continue}if("otherwise"in o){n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"}," ".repeat(r-1),v("span",{"data-ink":"op"},"[else]"),` ${o.otherwise}`),` -`);continue}if("close"in o){r=Math.max(0,r-1),n.push(v("span",{class:`${t}-tx-line`,"data-ink":"frame"},`${" ".repeat(r)}[end]`),` -`);continue}const l=e.byId.get(o.from)?.name??o.from,d=e.byId.get(o.to)?.name??o.to;n.push(v("span",{class:`${t}-tx-line`,"data-n":o.n},a,v("span",{"data-ink":"num"},`${o.n} `),s(l)," ",v("span",{"data-ink":o.kind==="main"?"main":"plain"},i(o.kind))," ",s(d)," ",v("span",{"data-ink":"label"},o.label),o.note?[" ",v("span",{"data-ink":"note"},`(${o.note})`)]:null),` -`)}return n}function gn(t,e){const{P:n}=t,s=[],i=[],r=()=>i.length?i[i.length-1].el.c:s;let o=null;for(const a of e.steps){if("band"in a){o=null,r().push(v("p",{class:`${n}-band`},v("span",null,a.band)));continue}if("open"in a){o=null;const h=i[i.length-1],u=h?`;--_fis:${a.a===h.a?1:0};--_fie:${a.b===h.b?1:0}`:"",S=v("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${u}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));r().push(S),i.push({el:S,a:a.a,b:a.b});continue}if("otherwise"in a){o=null,r().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){o=null,i.pop();continue}o||(o=v("ol",{class:`${n}-msgs`,start:a.n}),r().push(o));const l=e.byId.get(a.from),d=e.byId.get(a.to),m=l?.col??1,f=d?.col??1,c=m===f,g=c&&(e.rtl?m!==1:m===e.nodes.length),x=ee(e,a.kind);o.c.push(v("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":c?g?"start":"end":void 0,style:`--_a:${Math.min(m,f)};--_b:${Math.max(m,f)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(a.n)),v("span",{class:`${n}-mlabel`},a.label)),v("span",{class:`${n}-route`},l?.short??a.from," ",dn(n,a.kind),v("span",{class:t.hidden}," to ")," ",d?.short??a.to,x?` · ${x}`:""),a.note?v("span",{class:`${n}-note`},a.note):null))}return v("div",{class:`${n}-steps`},s)}function fe(t,e){return mt(e,`list:${t}`,()=>yn(t,e))}var mn=fe;function yn(t,e){const n=Math.min(6,e.heading+1),s=f=>v(`h${n}`,{class:`${t}-list-head`},f),i=f=>v("strong",null,f),r=f=>f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},i(f.name)):i(f.name),o=f=>v("code",{class:`${t}-code`},f),a=f=>e.byId.get(f)?.name??f,l=f=>{const c=ee(e,f);return c?` (${c})`:""},d=f=>f.focal&&e.legend.focal?` ${vt(e.legend.focal)}`:"";if(e.type==="architecture"){const f=x=>v("li",null,r(x),x.kind?`, ${x.kind}`:"",x.detail?[". ",x.mono?o(x.detail):x.detail,/[.!?]$/.test(x.detail)?"":"."]:/[.!?]$/.test(x.kind??x.name)?"":".",d(x)),c=[s("Parts")],g=e.nodes.filter(x=>!x.group);g.length&&c.push(v("ul",{class:`${t}-list-items`},g.map(f)));for(const x of e.groups.filter(h=>h.depth===1)){c.push(v("p",{class:`${t}-list-group`},x.label)),x.members.length&&c.push(v("ul",{class:`${t}-list-items`},x.members.map(h=>f(e.byId.get(h)))));for(const h of e.groups.filter(u=>u.parent===x.id))c.push(v("p",{class:`${t}-list-group`,"data-depth":2},h.label)),c.push(v("ul",{class:`${t}-list-items`,"data-depth":2},h.members.map(u=>f(e.byId.get(u)))))}return c.push(s("Connections")),c.push(v("ol",{class:`${t}-list-items`},e.edges.map(x=>v("li",null,i(a(x.from))," to ",i(a(x.to)),x.label?[": ",o(yt(x.label))]:"",`${l(x.kind)}.`)))),c}if(e.type==="flowchart"){const f=c=>(e.byId.get(c)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(c=>{const g=e.edges.filter(u=>u.from===c.id),x=c.shape==="decision"?"Decision":c.shape==="terminal"?g.length?"Start":"End":"Step",h=!c.detail&&/[.!?]$/.test(c.name)?" ":". ";return v("li",null,r(c),c.detail?[", ",c.mono?o(c.detail):c.detail]:"",`${h}${x}.`,d(c),g.length?v("ul",{class:`${t}-list-exits`},g.map(u=>v("li",null,u.label?`If ${yt(u.label)}: go to ${f(u.to)}, `:`Then: go to ${f(u.to)}, `,i(a(u.to)),l(u.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const c=e.edges.filter(g=>g.from===f.id);return v("li",null,`${f.laneLabel}: `,r(f),f.detail?[", ",f.mono?o(f.detail):f.detail]:"",".",d(f),c.length?[" Then ",...c.flatMap((g,x)=>[x?"; ":"",`to step ${e.byId.get(g.to).step}, `,i(a(g.to)),g.label?[": ",o(yt(g.label))]:"",l(g.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[s("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(g=>v("li",null,i(g.name),g.kind?`, ${g.kind}`:"",".",d(g),ne(e,g))))];f.push(s("Messages"));let c=null;for(const g of e.steps){if("band"in g){c=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},g.band));continue}if("open"in g){c=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords[g.open]}: ${g.label}`));continue}if("otherwise"in g){c=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords.else}: ${g.otherwise}`));continue}if("close"in g){c=null;continue}c||(c=v("ol",{class:`${t}-list-items`,start:g.n}),f.push(c)),c.c.push(v("li",null,o(g.label),": ",i(a(g.from))," to ",i(a(g.to)),`${l(g.kind)}.`,g.note?` ${vt(g.note)}`:""))}return f}const m=[];for(const f of e.nodes)m.push(v(`h${n}`,{class:`${t}-list-group`},f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},o(f.name)):o(f.name),d(f))),m.push(v("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(c=>v("li",null,o(c.name),c.key==="PK"?", primary key":c.key==="FK"?", foreign key":"",c.ref?[", references ",o(`${c.ref.table}.${c.ref.column}`)]:c.type?`, ${c.type}`:"")),...f.more?[v("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return m}function ue(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Ot(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function Dt(t,e=!1){const n=e&&t.type!=="sequence"&&Ot(t)&&t.cols>1&&t.rows>1,s=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:oe(t)},{keys:["Home","End"],words:"the ends"},...s,{keys:["Esc"],words:"clear"}]}var bn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Ot(t){return mt(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,...$n(t,r)})),n=(r,o)=>{const a=o==="right"||o==="left",l=o==="right"||o==="down",d=x=>a?[x.col,x.col]:x.rows,m=x=>a?x.rows:[x.col,x.col],f=d(r),c=m(r);let g=null;return e.forEach((x,h)=>{if(x===r)return;const u=d(x),S=m(x),I=l?u[0]-f[1]:f[0]-u[1];if(I<1)return;const T=Math.max(0,S[0]-c[1],c[0]-S[1]),M=[T===0?0:1,T===0?I:I+2*T,T,Math.abs(S[0]-c[0]),h];(!g||bn(M,g.rank))&&(g={id:x.id,rank:M})}),g?.id??null},s=ut();for(const r of e)s[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const o=new Set([r]),a=[r];for(;a.length;)for(const l of Object.values(s[a.pop()]))l&&!o.has(l)&&(o.add(l),a.push(l));return o.size};return e.every(r=>i(r.id)===e.length)?s:null})}function At(t){return mt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!Gt(t))return{lane:e,dropped:n,lanes:0};const s=(l,d)=>(t.byId.get(l)?.row??0)*1e3+d,i=new Map;t.edges.forEach((l,d)=>{const m=`${l.to}.${l.toRow}`,f=s(l.from,l.fromRow??0),c=s(l.to,l.toRow??0),g=i.get(m)??{members:[],lo:1/0,hi:-1/0};g.members.push(d),g.lo=Math.min(g.lo,f,c),g.hi=Math.max(g.hi,f,c),i.set(m,g)});const r=[...i.values()].sort((l,d)=>d.hi-d.lo-(l.hi-l.lo)),o=[];let a=0;for(const l of r.reverse()){const d=new Set(o.filter(f=>f.lo<=l.hi&&l.lo<=f.hi).map(f=>f.lane));let m=0;for(;d.has(m);)m++;if(m>1){for(const f of l.members)n.add(f);continue}o.push({lo:l.lo,hi:l.hi,lane:m});for(const f of l.members)e.set(f,m);a=Math.max(a,m+1)}return{lane:e,dropped:n,lanes:a}})}var Gt=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Ct(t,e,n){const s=n.prefix,i=sn(n.base),r=t.type==="sequence"||t.type==="schema"?null:ie(t),o={P:s,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},a=e.layout==="drawn",l=bt(t,e),d=t.type==="sequence"||t.type==="schema"?a:!0,m=`h${t.heading}`,f=[`--_cols:${zt(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const c=t.type==="architecture"?se(t):[0,0,0,0],g=(h,u,S)=>h?h>1?`calc(${h} * var(--basalt-space-${u}))`:`var(--basalt-space-${u})`:S?`var(--basalt-space-${S})`:"0px",x=a&&e.pad?"3":void 0;f.push(`--_gpad:${g(c[0],"8",x)} ${g(c[1],"4")} ${g(c[2],"4",x)} ${g(c[3],"4")}`)}return r?.gutter&&r.laneCount>2&&f.push(`--_gw:calc(${r.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),Gt(t)&&f.push(`--_gpad:0px ${At(t).lanes>1?"calc(var(--basalt-space-5) + var(--basalt-space-3))":"var(--basalt-space-5)"} 0px 0px`),t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${s} ${n.className}`:s,"aria-labelledby":i.title,"data-type":t.type,"data-cols":zt(t),"data-reach":t.type==="architecture"?re(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:f.join(";")},v("div",{class:`${s}-head`},v(m,{id:i.title,class:`${s}-title`},t.title),n.hasSource?v("p",{class:`${s}-source`},{slot:"source"}):null),v("div",{class:`${s}-drawing`,role:d?"group":void 0,"aria-roledescription":d?"diagram":void 0,"aria-labelledby":d?i.title:void 0,"aria-describedby":d?l?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":l?"":void 0},hn(o,t,e),t.text?null:v("div",{class:`${s}-ink`,"aria-hidden":"true"}),v("span",{class:`${s}-ruler`,"aria-hidden":"true"})),ce(s,t),v("p",{class:`${s}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),bt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?v("p",{class:`${s}-tap-hint`,"aria-hidden":"true"},`Tap ${oe(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${s}-foot`},{slot:"toggle"}),v("div",{id:i.list,class:`${s}-list`,hidden:!e.open},fe(s,t)),v("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${ue(t,a)} ${n.viewer}`:ue(t,a)),v("figcaption",{id:i.summary,class:`${s}-summary`},{slot:"summary"}))}function wn(t){const e=getComputedStyle(t),n=(i,r)=>{const o=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(o)?o:r},s=new Map;return{space:i=>(s.has(i)||s.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),s.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var jt=(t,e)=>t==="main"?e.line:e.hair,ft=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},ht=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,he=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function lt(t,e,n){const{l:s,t:i,r,b:o}=t.rect,a=(s+r)/2,l=(i+o)/2,d=(r-s)/2,m=(o-i)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const x=n,h=m*Math.max(0,1-Math.abs(x-a)/d);return{x,y:e==="top"?l-h:l+h}}const c=n,g=d*Math.max(0,1-Math.abs(c-l)/m);return{x:e==="left"?a-g:a+g,y:c}}if(t.shape==="terminal"){const c=Math.min(d,m);if(f){const u=n,S=Math.min(Math.max(u,s+c),r-c),I=u-S,T=Math.abs(I)>=c?0:Math.sqrt(c*c-I*I);return{x:u,y:Math.abs(I)<1e-6?e==="top"?i:o:e==="top"?l-T:l+T}}const g=n,x=g-l,h=Math.abs(x)>=c?0:Math.sqrt(c*c-x*x);return{x:e==="left"?s+c-h:r-c+h,y:g}}return f?{x:n,y:e==="top"?i:o}:{x:e==="left"?s:r,y:n}}function vn(t,e,n){const{l:s,t:i,r,b:o}=e.rect,a=(s+r)/2,l=(i+o)/2,d=(r-s)/2,m=(o-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/d+Math.abs(t.y-l)/m<1-n/Math.min(d,m);if(e.shape==="terminal"){const f=Math.min(d,m),c=Math.min(Math.max(t.x,s+f),r-f);return Math.hypot(t.x-c,t.y-l)s+n&&t.xi+n&&t.ymatchMedia("(forced-colors: active)").matches;function Mn(t,e){const n=t.querySelector(`.${e}-ruler`),s=new Map;return(i,r)=>{const o=`${r}|${i}`;return s.has(o)||(n.setAttribute("data-f",r),n.textContent=i,s.set(o,n.getBoundingClientRect().width),n.textContent=""),s.get(o)}}var Bt=t=>t?t.split(/\s+/).filter(Boolean):[];function Sn(t,e,n){const s=e.space;let i=e.node,r=e.table;for(const l of t.nodes){if(l.shape==="table"){for(const h of l.columns??[]){const u=h.ref?`${t.rtl?"←":"→"} ${h.ref.table}`:h.type??"",S=s("6")+n(h.name,"mono")+(u?s("3")+n(u,"mono"):0)+2*s("3")+2*e.hair;r=Math.max(r,Math.ceil(S))}r=Math.max(r,Math.ceil(n(l.name,"table")+2*s("3")+2*e.hair+(l.href?16+s("1-5"):0)));continue}const d=l.shape==="terminal"?2*s("5"):2*s("3"),m=l.mark&&!kn()?(l.shape==="participant"?2:1)*s("6"):0;let f=0;const c=l.href?16+s("1-5"):0,g=Bt(l.name);if(g.forEach((h,u)=>{f=Math.max(f,n(h,l.shape==="decision"?"name-500":"name")+(l.kind?0:m)+(u===g.length-1?c:0))}),t.type!=="data-flow")for(const h of Bt(l.kind))f=Math.max(f,n(h,"mono")+m);for(const h of Bt(l.detail))f=Math.max(f,n(h,l.mono?"mono":"sans"));const x=l.shape==="decision"?f/.62:f+d+2*e.hair;i=Math.max(i,Math.ceil(x))}const o=zt(t);let a;return t.type==="data-flow"?a=e.lane+o*(i+s("12")):t.type==="schema"?a=o*r+(o-1)*s("12")+(Gt(t)?s("5")+(At(t).lanes>1?s("3"):0):0):t.type==="sequence"?a=o*i+(o-1)*s("5"):a=o*i+(o-1)*s("16")+re(t)*s("4"),{track:i,table:r,least:Math.max(e.wide,a)}}function ge(t,e){return{x:(n,s)=>s%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,s)=>s%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function Kt(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function me(t,e,n){const s=t.map(r=>({...r}));for(let r=1;r=2){const l=i[i.length-2];if(Math.abs(l.x-a.x)<.01&&Math.abs(a.x-o.x)<.01||Math.abs(l.y-a.y)<.01&&Math.abs(a.y-o.y)<.01){i[i.length-1]=o;continue}}i.push(o)}}return i}var pt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Tt(t,e,n){const s=[];for(let r=0;rMath.min(h.x,u.x)+.75&&TMath.min(S.y,I.y)+.75&&Mi.split(/\s+/).map(parseFloat).filter(r=>Number.isFinite(r)),s=(i,r,o)=>{const a=[];let l=r;for(const d of i)a.push([l,l+d]),l+=d+o;return a};return{cols:s(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:s(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0)}}var st=t=>t==="left"||t==="right",ye={top:"bottom",bottom:"top",left:"right",right:"left"};function be(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function $e(t,e,n){const s=[];t.edges.forEach((r,o)=>{const a=t.byId.get(r.from),l=t.byId.get(r.to),[d,m]=e[o],f=a.row===l.row&&st(d)&&st(m)&&d===ye[m]||a.col===l.col&&!st(d)&&!st(m)&&d===ye[m];s.push({edge:o,end:"from",node:a,side:d,far:l,straight:f,f:.5},{edge:o,end:"to",node:l,side:m,far:a,straight:f,f:.5})});const i=new Map;for(const r of s){const o=`${r.node.id}.${r.side}`;i.has(o)||i.set(o,[]),i.get(o).push(r)}for(const[r,o]of i){if(o[0].node.shape==="decision")continue;const a=h=>st(h.side)?h.far.row-h.node.row:h.far.col-h.node.col,l=o.filter(h=>h.straight),d=o.filter(h=>!h.straight);if(d.sort((h,u)=>a(h)-a(u)||(st(h.side)?h.far.col-u.far.col:h.far.row-u.far.row)*(a(h)<0?1:-1)),o.length>3&&n(`${r.replace(".","'s ")} side has ${o.length} lines; more than three is an error: use another side`),!l.length){d.length===2?(d[0].f=.25,d[1].f=.75):d.length===3?(d[0].f=.25,d[1].f=.5,d[2].f=.75):d.length>3&&d.forEach((h,u)=>{h.f=(u+1)/(d.length+1)});continue}const m=new Map;for(const h of l)m.has(h.far.id)||m.set(h.far.id,[]),m.get(h.far.id).push(h);for(const h of m.values())h.length>1&&h.sort((u,S)=>u.edge-S.edge).forEach((u,S)=>{u.f=h.length===2?S===0?.25:.75:(S+1)/(h.length+1)});const f=Math.min(...l.map(h=>h.f)),c=Math.max(...l.map(h=>h.f)),g=d.filter(h=>a(h)<0),x=d.filter(h=>a(h)>=0);g.forEach((h,u)=>{h.f=f*(u+1)/(g.length+1)}),x.forEach((h,u)=>{h.f=c+(1-c)*(u+1)/(x.length+1)})}return s}function we(t,e=8,n=8){return mt(t,`port-floors:${e}:${n}`,()=>{const s=ut();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return s;const i=t.edges.map(o=>{const a=t.byId.get(o.from),l=t.byId.get(o.to),[d,m]=be(a,l);return[o.fromSide??d,o.toSide??m]}),r=new Map;for(const o of $e(t,i,()=>{})){if(!st(o.side)||o.node.shape!=="box")continue;const a=`${o.node.id}.${o.side}`;r.has(a)||r.set(a,[]),r.get(a).push(o.f)}for(const[o,a]of r){if(a.length<2)continue;const l=[...new Set(a.map(f=>Math.round(f*1e6)/1e6))].sort((f,c)=>f-c);let d=Math.max(e/l[0],e/(1-l[l.length-1]));for(let f=1;f{const o=t.byId.get(r.dataset.node);o&&i.set(o.id,{id:o.id,rect:ft(r,n),shape:o.shape,i:o.i})}),i}function ke(t,e){const n=e.head,s=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-s,r:i+s,t:r-n,b:r}:t.dir==="up"?{l:i-s,r:i+s,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-s,b:r+s}:{l:i,r:i+n,t:r-s,b:r+s}}var Me=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Se(t,e,n,s){const i=(r,o)=>{const a=r+o-Math.floor(r+o);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const r of i(t.t,n))for(const o of i(t.l,e)){if(!o&&!r)return t;const a={l:t.l+o,r:t.r+o,t:t.t+r,b:t.b+r};if(s(a))return a}return t}function An(t,e,n,s,i,r,o,a,l){const d=o.space,m=[],f=[],c=[],g=[],x=d("1"),h=e.filter(u=>t.edges[u.i]?.label).sort((u,S)=>+(t.edges[S.i].kind==="main")-+(t.edges[u.i].kind==="main")||u.i-S.i);for(const u of h){const S=t.edges[u.i].label,I=a(S,"label"),T=16*Ft(S),M=u.pts.length-2,A=[];pt(u.pts).forEach(([L,N],_)=>{const E=Math.abs(L.y-N.y)<.01,O=E?L.x:L.y;let R=E?N.x:N.y;const D=Math.sign(R-O)||1;_===M&&(R-=D*o.head);let W=[[O,R]];for(const y of i)for(const b of E?[y.l,y.r]:[y.t,y.b]){const p=E?L.y:L.x;(E?p>y.t&&py.l&&pb>Math.min($,w)+1&&b{const p=(y+b)/2,k=E?{x:p,y:L.y}:{x:L.x,y:p};return!i.some($=>k.x>$.l&&k.x<$.r&&k.y>$.t&&k.y<$.b)},K=u.axes?.[_]??(E?L.y:L.x);for(const[y,b]of W)A.push({horiz:E,c:K,p:y,q:b,len:Math.abs(b-y),pri:W.length>1&&tt(y,b)?1:0})}),A.sort((L,N)=>N.pri-L.pri||N.len-L.len);let B=null,J=!1;const j=(L,N=!0)=>{const _=he(L,x);return N&&(L.lr.r||L.tr.b)||n.some(E=>pe(_,E))||m.some(E=>ht(_,E))||s.heads.some(E=>ht(_,E))||s.rects.some(E=>ht(_,E))?!1:!e.some(E=>E.i!==u.i&&pt(E.pts).some(([O,R])=>ht(_,Me(O,R,E.width))))};for(const L of A){for(const N of[1/2,1/3,2/3]){const _=L.p+(L.q-L.p)*N,E=[],O=d("2")+u.width/2;if(L.horiz?(L.len>=I+2*d("1")+d("3-5")&&E.push({box:{l:_-I/2-d("1"),r:_+I/2+d("1"),t:L.c-T/2,b:L.c+T/2},on:!0}),E.push({box:{l:_-I/2,r:_+I/2,t:L.c-O-T,b:L.c-O},on:!1}),E.push({box:{l:_-I/2,r:_+I/2,t:L.c+O,b:L.c+O+T},on:!1})):(L.len>=T+d("3")&&E.push({box:{l:L.c-I/2-d("1"),r:L.c+I/2+d("1"),t:_-T/2,b:_+T/2},on:!0}),E.push({box:{l:L.c+O,r:L.c+O+I,t:_-T/2,b:_+T/2},on:!1}),E.push({box:{l:L.c-O-I,r:L.c-O,t:_-T/2,b:_+T/2},on:!1})),B=E.find(R=>j(R.box))??null,B)break;!J&&E.some(R=>j(R.box,!1))&&(J=!0)}if(B)break}if(!B){c.push(u.i),J&&g.push(u.i);continue}const Q=Se(B.box,l.ox,l.oy,L=>j(L));m.push(Q),f.push({i:u.i,text:S,box:Q,on:B.on})}return{labels:f,unseated:c,bounded:g}}function Ee(t,e,n,s){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(o=>{if(o.getClientRects().length===0||getComputedStyle(o).display==="contents")return;const a=ft(o,e);r.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const l=o.querySelector(`:scope > .${n}-glabel`);l&&l.getClientRects().length&&i.push(ft(l,e))}),t.querySelectorAll(`.${n}-lane`).forEach((o,a)=>{if(!o.getClientRects().length)return;const l=ft(o,e);a>0&&i.push({l:l.l,r:l.r,t:l.t-s/2-.5,b:l.t-s/2+.5});const d=o.querySelector(`.${n}-lane-name`);d&&i.push(ft(d,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function Ln(t,e){const{m:s,tk:i,P:r,drawing:o,origin:a,warn:l}=t,d=i.space,m=xe(s,o,a,r),f=[...m.values()],c=En(o),g=a.left-Math.floor(a.left),x=a.top-Math.floor(a.top),h=ge(g,x),u=o.clientWidth,S=o.clientHeight,I=p=>s.type==="data-flow"?p.col+1:p.col,T=parseFloat(getComputedStyle(o).rowGap)||0,M={w:u,h:S,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:g,oy:x};if(s.type==="sequence")return qn(t,M,h);let A,B=[];s.type==="schema"?A=s.edges.map(p=>{const k=s.byId.get(p.from),$=s.byId.get(p.to);if(k.col===$.col){const w=k.col===s.cols&&s.cols>1?"left":"right";return[w,w]}return $.col>k.col?["right","left"]:["left","right"]}):(A=s.edges.map(p=>{const k=s.byId.get(p.from),$=s.byId.get(p.to),[w,C]=be(k,$);return[p.fromSide??w,p.toSide??C]}),B=$e(s,A,l||(()=>{})));const J=(p,k)=>{const $=o.querySelector(`.${r}-node[data-node="${CSS.escape(p)}"] .${r}-row[data-row="${k}"]`);if(!$)return 0;const w=ft($,a);return(w.t+w.b)/2},j=s.edges.map((p,k)=>{const[$,w]=A[k],C=m.get(p.from),q=m.get(p.to),F=jt(p.kind,i);if(p.fk){const V=J(p.from,p.fromRow),P=J(p.to,p.toRow),Z=h.y(V,F),U=h.y(P,F);return{p1:{x:$==="right"?C.rect.r:C.rect.l,y:Z},p2:{x:w==="right"?q.rect.r:q.rect.l,y:U},r1:V,r2:Math.abs(Z-U)<.01?V:P}}const X=B.find(V=>V.edge===k&&V.end==="from").f,nt=B.find(V=>V.edge===k&&V.end==="to").f;let z=ve(C,$,X),G=ve(q,w,nt);const et=st($)?z.y:z.x;let ot=st(w)?G.y:G.x;return st($)?z={...z,y:h.y(z.y,F)}:z={...z,x:h.x(z.x,F)},st(w)?G={...G,y:h.y(G.y,F)}:G={...G,x:h.x(G.x,F)},st($)&&st(w)&&Math.abs(z.y-G.y)<1.01&&(G={...G,y:z.y},ot=et),!st($)&&!st(w)&&Math.abs(z.x-G.x)<1.01&&(G={...G,x:z.x},ot=et),z=st($)?lt(C,$,z.y):lt(C,$,z.x),G=st(w)?lt(q,w,G.y):lt(q,w,G.x),{p1:z,p2:G,r1:et,r2:ot}}),Q=new Set;s.type==="schema"&&s.edges.forEach((p,k)=>{Math.abs(s.byId.get(p.from).col-s.byId.get(p.to).col)>1&&Q.add(k)});for(const p of At(s).dropped)Q.add(p),l?.(`${s.edges[p].from} to ${s.edges[p].to} would need a third lane of turn-backs, so its line is not drawn; its row still writes the target`);const L=new Map,N=new Set;s.edges.forEach((p,k)=>{if(Q.has(k))return;const[$,w]=A[k],{p1:C,p2:q}=j[k],F=s.byId.get(p.from),X=s.byId.get(p.to);let nt=null,z=null,G=!1;if($===w){if(st($)){const V=$==="right"?Math.max(I(F),I(X)):Math.min(I(F),I(X))-1,P=c.cols[V-1],Z=c.cols[V];P&&Z&&(nt=`c${V}`,z=[P[1],Z[0]],G=!0)}else{const V=$==="bottom"?Math.max(F.row2,X.row2):Math.min(F.row,X.row)-1,P=c.rows[V-1],Z=c.rows[V];P&&Z&&(nt=`r${V}`,z=[P[1],Z[0]],G=!1)}nt&&N.add(k)}else if(st($)&&st(w)&&Math.abs(C.y-q.y)>.5){const V=I(X),P=w==="left",Z=c.cols[(P?V-1:V)-1],U=c.cols[(P?V:V+1)-1];Z&&U&&(nt=`c${P?V-1:V}`,z=[Z[1],U[0]],G=!0)}else if(!st($)&&!st(w)&&Math.abs(C.x-q.x)>.5){const P=w==="top"?X.row-1:X.row2,Z=c.rows[P-1],U=c.rows[P];Z&&U&&(nt=`r${P}`,z=[Z[1],U[0]],G=!1)}if(!nt||!z)return;L.has(nt)||L.set(nt,{span:z,vertical:G,members:new Map});const et=`${p.to}.${w}.${Math.round(G?q.y:q.x)}`,ot=L.get(nt);ot.members.has(et)||ot.members.set(et,[]),ot.members.get(et).push(k)});const _=new Map,E=p=>{const[k,$]=A[p],{p1:w,p2:C}=j[p];if(st(k)&&st($)){if(k===$){const F=d("4")+(s.type==="schema"&&s.cols===1?(At(s).lane.get(p)??0)*d("3"):0),X=_.get(p)??(k==="right"?Math.max(w.x,C.x)+F:Math.min(w.x,C.x)-F);return[w,{x:X,y:w.y},{x:X,y:C.y},C]}if(Math.abs(w.y-C.y)<=.5)return[w,{x:C.x,y:w.y}];const q=_.get(p)??(w.x+C.x)/2;return[w,{x:q,y:w.y},{x:q,y:C.y},C]}if(!st(k)&&!st($)){if(k===$){const F=_.get(p)??(k==="bottom"?Math.max(w.y,C.y)+d("4"):Math.min(w.y,C.y)-d("4"));return[w,{x:w.x,y:F},{x:C.x,y:F},C]}if(Math.abs(w.x-C.x)<=.5)return[w,{x:w.x,y:C.y}];const q=_.get(p)??(w.y+C.y)/2;return[w,{x:w.x,y:q},{x:C.x,y:q},C]}return st(k)?[w,{x:C.x,y:w.y},C]:[w,{x:w.x,y:C.y},C]},O=p=>{const k=s.edges[p],$=jt(k.kind,i),w=E(p),C=me(w,$,h);let q;return w.length===C.length&&(q=pt(w).map(([F,X])=>Math.abs(F.y-X.y)<.75?(F.y+X.y)/2:(F.x+X.x)/2),q[0]=j[p].r1,q.length>1&&(q[q.length-1]=j[p].r2)),{i:p,from:k.from,to:k.to,kind:k.kind,pts:C,tip:C[C.length-1],dir:Kt(C),dot:k.fk?C[0]:void 0,width:$,axes:q}},R=()=>s.edges.flatMap((p,k)=>Q.has(k)?[]:[O(k)]);let D=null;const W=p=>{D??(D=R());const k=D.map($=>p.has($.i)?O($.i):$);return{lines:k,score:In(k,p)*1e5+Tt(k,void 0,p).length*1e3+Vt(k.filter($=>p.has($.i)),f,s).length}},tt=(p,k)=>{const $=p.flatMap(w=>{const{p1:C,p2:q}=j[w];return k?[C.y,q.y]:[C.x,q.x]});return[Math.min(...$),Math.max(...$)]};for(const[,p]of L){const k=[...p.members.values()].map(w=>({members:w,run:tt(w,p.vertical)})).sort((w,C)=>w.run[0]-C.run[0]),$=[];for(const w of k){const C=$[$.length-1];C&&C.some(q=>q.run[0]N.has(et)))continue;const C=w.map(et=>et.members),q=C.length,F=(p.span[1]-p.span[0])/(q+1);FV.forEach(Z=>_.set(Z,p.span[0]+F*(P+1))));const ot=W(X);ot.scoreet.forEach(V=>_.set(V,p.span[0]+F*(ot+1)))),D=G}}M.lines=R();for(const p of Q)At(s).dropped.has(p)||l?.(`${s.edges[p].from} to ${s.edges[p].to} is two columns apart, so its line is not drawn; its row still writes the target`);M.crossings=Tt(M.lines),M.through=Vt(M.lines,f,s),M.outside=Ie(M.lines,u,S,i);const{obstacles:K,groups:y}=Ee(o,a,r,T);K.heads=M.lines.map(p=>ke(p,i));const b=An(s,M.lines,f,K,y,{l:0,t:0,r:u,b:S},i,e,{ox:g,oy:x});return M.labels=b.labels,M.unseated=b.unseated,M.bounded=b.bounded,M.overlaps=[...new Set(Ae(M.lines,null).flat())],M}function In(t,e){return Ae(t,e).length}function Ae(t,e){const n=[];for(let s=0;s=a)continue;const[u,S]=c?[l.x,d.x]:[l.y,d.y],[I,T]=c?[m.x,f.x]:[m.y,f.y];Math.min(Math.max(u,S),Math.max(I,T))-Math.max(Math.min(u,S),Math.min(I,T))>1&&n.push([r.i,o.i])}}return n}function*Le(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const l=a===r.pts.length-1?Math.max(r.width/2,s.head/2):r.width/2;return o.x-l<-.5||o.x+l>e+.5||o.y-l<-.5||o.y+l>n+.5})&&i.push(r.i);return i}function Vt(t,e,n){const s=[];for(const i of t){const r=pt(i.pts);e.some(o=>r.some(([a,l])=>xn(a,l,o)))&&s.push(i.i)}return s}function qn(t,e,n){const{m:s,tk:i,P:r,drawing:o,origin:a}=t,l=i.space,d=new Map;o.querySelectorAll(`.${r}-node`).forEach(M=>d.set(M.dataset.node,ft(M,a)));const m=o.querySelector(`.${r}-steps`),f=m?ft(m,a).b:e.h,c=M=>{const A=d.get(M);return A?n.x((A.l+A.r)/2,i.hair):0};for(const M of s.nodes){const A=d.get(M.id);A&&e.lifelines.push({x:c(M.id),y1:A.b,y2:f})}const g=M=>d.get(M.id),x=new Map;o.querySelectorAll(`.${r}-msg`).forEach(M=>{const A=ft(M,a);x.set(Number(M.querySelector(`.${r}-num`)?.textContent??0),(A.t+A.b)/2)});const h=i.activation,u=h/2,S=M=>{const A=s.byId.get(M.who);if(!A)return null;const B=c(M.who),j=(A.i===s.nodes.length-1&&s.nodes.length>1?-1:1)*(s.rtl?-1:1),Q=(M.depth-1)*l("1")*j,L=x.get(M.from)??0,N=x.get(M.to)??L,_=M.from===M.to;return{l:n.x(B-u+Q,i.hair),r:n.x(B+u+Q,i.hair),t:n.y(_?L-l("2")-l("1"):L,i.hair),b:n.y(_?L+l("2")+l("1"):N,i.hair)}},I=s.bars.map(M=>({bar:M,rect:S(M)})).filter(M=>M.rect);e.bars=I.map(M=>M.rect);const T=(M,A,B)=>I.filter(({bar:J})=>J.who===M&&J.to>=A&&(B?J.from<=A:J.fromj.bar.depth-J.bar.depth)[0]?.rect;return o.querySelectorAll(`.${r}-msg`).forEach(M=>{const A=M.dataset.from,B=M.dataset.to,J=M.dataset.kind??"plain",j=jt(J,i),Q=ft(M,a),L=n.y((Q.t+Q.b)/2,j),N=Number(M.querySelector(`.${r}-num`)?.textContent??0);let _=c(A),E=c(B),O;if(A===B){const b=M.dataset.self==="start"?-l("6"):l("6"),p=T(A,N,!0),k=p?b>0?p.r:p.l:_,$=n.y(L-l("2"),j),w=n.y(L+l("2"),j);O=[{x:k,y:$},{x:n.x(_+b,j),y:$},{x:n.x(_+b,j),y:w},{x:k,y:w}]}else{const b=E>_?1:-1,p=T(A,N,!1),k=T(B,N,!0);p&&(_=b>0?p.r:p.l),k&&(E=b>0?k.l:k.r),O=[{x:_,y:L},{x:E,y:L}]}e.lines.push({i:N,from:A,to:B,kind:J,pts:O,tip:O[O.length-1],dir:Kt(O),width:j});const R=M.querySelector(`.${r}-said`),D=M.querySelector(`.${r}-note`),W=s.byId.get(A),tt=s.byId.get(B);if(!W||!tt)return;const K=A===B?(()=>{const b=s.nodes[W.i+(M.dataset.self==="start"?-1:1)],p=b?c(b.id):M.dataset.self==="start"?0:e.w;return Math.abs(p-_)-l("6")-l("2-5")-l("2")})():Math.abs(E-_)-2*l("2");Math.max(R?R.getBoundingClientRect().width:0,D?D.getBoundingClientRect().width:0)>K+.5&&e.unseated.push(N)}),o.querySelectorAll(`.${r}-fhead`).forEach(M=>{const A=M.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!A)return;[...M.children].reduce((J,j)=>J+j.getBoundingClientRect().width,0)+l("3")>A.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${M.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function qe(t,e,n,s=ut()){const{m:i,tk:r,P:o,drawing:a,origin:l}=t,d=r.space,m=xe(i,a,l,o),f=[...m.values()],c=l.left-Math.floor(l.left),g=l.top-Math.floor(l.top),x=ge(c,g),h=a.clientWidth,u=a.clientHeight,S={w:h,h:u,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:g},I=ut();if(i.type==="sequence"||i.type==="schema")return{geo:S,grow:I};const T=h-(parseFloat(getComputedStyle(a).paddingRight)||0),M=(E,O,R)=>{const D=[E];for(let W=1;W<=(gt(s,O)??0);W++)D.push({...E,t:E.t+R*d("4")*W,b:E.b+R*d("4")*W});return D},A=new Map;a.querySelectorAll(`.${o}-node`).forEach(E=>{const O=E.parentElement,R=ft(O,l),D=getComputedStyle(O);A.set(E.dataset.node,R.r-(parseFloat(D.paddingRight)||0)-(parseFloat(D.borderRightWidth)||0))});const B=i.nodes,J=E=>m.get(B[E].id),j=[],Q=E=>jt(i.edges[E].kind,r);i.edges.forEach((E,O)=>{const R=n.routes[O],D=m.get(E.from),W=m.get(E.to),tt=Q(O);let K=[];const y=E.label,b=y?e(y,"label"):0,p=y?16*Ft(y):16,k=d("4");if(R==="down"||R==="up"){const w=Math.max(D.rect.l,W.rect.l),C=Math.min(D.rect.r,W.rect.r),q=i.edges.map((z,G)=>({o:z,j:G})).filter(({o:z,j:G})=>(n.routes[G]==="down"||n.routes[G]==="up")&&(z.from===E.from&&z.to===E.to||z.from===E.to&&z.to===E.from)),F=q.findIndex(z=>z.j===O),X=q.length<2?.5:q.length===2?F===0?.25:.75:(F+1)/(q.length+1),nt=x.x(w+(C-w)*X,tt);if(K=R==="down"?[lt(D,"bottom",nt),lt(W,"top",nt)]:[lt(D,"top",nt),lt(W,"bottom",nt)],y){let z=Math.min(K[0].y,K[1].y),G=Math.max(K[0].y,K[1].y);R==="down"?G-=r.head:z+=r.head;const et=[...a.querySelectorAll(`.${o}-group`)].map(Z=>ft(Z,l));let ot=[[z,G]];for(const Z of et)for(const U of[Z.t,Z.b])ot=ot.flatMap(([at,ct])=>U>at+1&&Uet.some(at=>(Z+U)/2>at.t&&(Z+U)/2at.l&&nt1){const Z=ot.filter(([at,ct])=>!V(at,ct));[z,G]=(Z.length?Z:ot).reduce((at,ct)=>ct[1]-ct[0]>at[1]-at[0]?ct:at)}const P=[1/2,1/3,2/3].map(Z=>{const U=z+(G-z)*Z;return{l:nt-b/2-d("1"),r:nt+b/2+d("1"),t:U-p/2,b:U+p/2}});j.push({k:O,cands:P,on:!0,card:R==="down"?E.to:E.from})}}else if(R==="trunk"||R==="rail"){const w=x.x(Math.max(D.rect.l,R==="rail"?W.rect.l:D.rect.l)+d(R==="trunk"?"8":"3"),tt),C=lt(D,"bottom",w);if(R==="rail"){if(K=[C,lt(W,"top",w)],y){const q=W.rect.t-d("6");j.push({k:O,cands:M({l:w+d("2-5"),r:w+d("2-5")+b,t:q-p/2,b:q+p/2},E.to,-1),on:!1,card:E.to})}}else{const q=x.x(W.rect.l+d("6"),tt),F=x.y(W.rect.t-k,tt);K=[C,{x:w,y:F},{x:q,y:F},lt(W,"top",q)],y&&j.push({k:O,cands:M({l:q+d("2-5"),r:q+d("2-5")+b,t:F-p/2,b:F+p/2},E.to,-1),on:!1,card:E.to})}}else{const w=Math.min(A.get(E.from)??h,A.get(E.to)??h),C=x.x(n.gutter?T+(n.lanes[O]+1)*d("3-5"):w-d("2-5"),tt),q=x.y(D.rect.t+(D.rect.b-D.rect.t)*n.exits[O],tt),F=lt(D,"right",q),X=R==="end-down",nt=i.edges.map((U,at)=>({o:U,j:at})).filter(({o:U,j:at})=>n.routes[at]===R&&U.to===E.to).sort((U,at)=>n.lanes[at.j]-n.lanes[U.j]||U.j-at.j),z=Math.max(0,nt.findIndex(({j:U})=>U===O)),G=W.rect.r-d("6")-z*d("3"),et=W.rect.r-d("6")-(nt.length-1)*d("3"),ot=x.x(G,tt),V=X?W.rect.t-k-z*d("5"):W.rect.b+k+z*d("5"),P=x.y(V,tt);K=[F,{x:C,y:F.y},{x:C,y:P},{x:ot,y:P},lt(W,X?"top":"bottom",ot)];const Z=X?E.to:B[W.i+1]?.id??E.to;y&&j.push({k:O,cands:M({l:et-d("2-5")-b,r:et-d("2-5"),t:V-p/2,b:V+p/2},Z,X?-1:1),on:!1,card:Z})}const $=me(K,tt,x);S.lines.push({i:O,from:E.from,to:E.to,kind:E.kind,pts:$,tip:$[$.length-1],dir:Kt($),width:tt})}),S.crossings=Tt(S.lines),S.through=Vt(S.lines,f,i),S.outside=Ie(S.lines,h,u,r);const{obstacles:L}=Ee(a,l,o,0);L.heads=S.lines.map(E=>ke(E,r));const N=[],_={l:0,t:0,r:h,b:u};for(const E of j){const O=W=>{const tt=he(W,d("1"));return W.l<_.l-.5||W.r>_.r+.5||W.t<_.t-.5||W.b>_.b+.5||f.some(K=>pe(tt,K))||N.some(K=>ht(tt,K))||L.heads.some(K=>ht(tt,K))||L.rects.some(K=>ht(tt,K))||S.lines.some(K=>K.i!==E.k&&pt(K.pts).some(([y,b])=>ht(tt,Me(y,b,K.width))))},R=E.cands.find(W=>!O(W));R||(I[E.card]=(I[E.card]??0)+1,S.unseated.push(E.k));const D=R?Se(R,c,g,W=>!O(W)):E.cands[0];N.push(D),S.labels.push({i:E.k,text:i.edges[E.k].label,box:D,on:E.on})}return{geo:S,grow:I}}function _n(t,e){const n=r=>String(Math.round(r*100)/100);let s=`M${n(t[0].x)} ${n(t[0].y)}`;for(let r=1;r({...M})),f=m[m.length-1];f.x-=r.x*d,f.y-=r.y*d;const c=e.tip.x-r.x*a,g=e.tip.y-r.y*a,x=-r.y*l,h=r.x*l,u=M=>Math.round(M*100)/100,S=it(e.kind),I=o?``:``,T=e.dot?``:"";return`${I}${T}`}function _e(t,e,n,s){const i=new Map,r=new Map;for(const a of e.crossings)r.has(a.under)||r.set(a.under,[]),r.get(a.under).push(a);let o="";for(const[a,l]of r){const d=`${s}-cut-${a}`;i.set(a,d);const m=l.map(f=>{const c=e.lines[f.top],g=e.lines[f.under],x=c.width/2+n.cut,h=g.width/2+1;return f.underVertical?``:``}).join("");o+=`${m}`}return{defs:o,ids:i}}function Oe(t,e,n,s){const{defs:i,ids:r}=_e(t,e,n,s),o=e.lifelines.map(m=>``).join("")+(e.bars??[]).map(m=>``).join(""),a=e.lines.map((m,f)=>Cn(t,m,n,r.get(f)??null,m.from===m.to?n.radiusXs:n.radius)).join(""),l=`${i?`${i}`:""}${o}${a}`,d=e.labels.map(m=>`1?' data-lines="2"':""} style="left:${Math.round(m.box.l*100)/100}px;top:${Math.round(m.box.t*100)/100}px;width:${Math.round((m.box.r-m.box.l)*100)/100}px">${m.text.split(` -`).map(it).join("
")}
`).join("");return l+d}function Zt(t,e,n,s,i,r,o,a){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const m=wn(t),f=Mn(d,n),c=Sn(e,m,f);a?.(c.least);const g=t.clientWidth,x=(()=>{const L=document.activeElement;return L&&d.contains(L)&&L.dataset.node?L.dataset.node:void 0})(),h=L=>bt(e,L)?{...L,stop:L.stop&&e.byId.has(L.stop)?L.stop:e.nodes[0]?.id,keep:void 0}:{...L,stop:L.stop??e.nodes[0]?.id,keep:x&&L.layout!=="drawn"?x:void 0};let u=!1;const S=L=>{if(u=!1,e.type!=="flowchart")return L;r({...L,heights:void 0,words:void 0});const N=ut(),_=ut();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(E=>{const O=E.querySelector(`.${n}-words`);if(!O)return;const R=E.getBoundingClientRect(),D=K=>{const y={w:K.width+2*m.space("2-5"),h:K.height+2*m.space("2")},b=1-y.w/R.width,p=b>.05?y.h/2/b:y.h*10;return Math.max(m.space("16"),Math.ceil(R.width/5),Math.ceil(2*p))},W=O.getBoundingClientRect();let tt=D(W);if(tt>R.width){const K=k=>(E.style.setProperty("--_ww",`${k}px`),O.getBoundingClientRect()),y=Math.floor(E.clientWidth-2*m.space("2-5"));let b=Math.ceil(W.width),p=W.height;for(;b1;){const q=k+$>>1;K(q).heightR.width&&(u=!0)}),{...L,heights:N,words:Object.keys(_).length?_:void 0}},I=()=>({m:e,tk:m,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:o}),T=i.autoOpen?{open:!1,autoOpen:void 0}:{},M=(L,N)=>N.map(_=>Lt(e,L.lines.find(E=>E.i===_))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:m,least:c.least};if(g>=c.least&&!e.unplaced){const L=O=>{let R=h({...i,...T,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:O||void 0});return R=S(R),r(R),{dd:R,g:Ln(I(),f)}};let{dd:N,g:_}=L(!1);const E=O=>O.through.length>0||O.outside.length>0||(O.overlaps?.length??0)>0||(O.misfit?.length??0)>0||u;if(!E(_)&&_.unseated.length&&_.unseated.every(O=>_.bounded?.includes(O))){const O=L(!0);!E(O.g)&&!O.g.unseated.length&&({dd:N,g:_}=O)}if(!E(_)&&!_.unseated.length)return _.crossings.length&&o?.(`${_.crossings.length} crossing${_.crossings.length===1?"":"s"} in the drawn layout: ${_.crossings.map(O=>`${Lt(e,_.lines[O.top])} over ${Lt(e,_.lines[O.under])}`).join("; ")}`),{dyn:N,geo:_,ink:Oe(n,_,m,s),tokens:m,least:c.least};u&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: a decision would be taller than it is wide`),_.misfit?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${_.misfit.join("; ")}`),_.through.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${M(_,_.through)} would pass through a node`),_.overlaps?.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${M(_,_.overlaps)} would lie on one another`),_.outside.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: ${M(_,_.outside)} would leave the drawing`),_.unseated.length&&o?.(`the drawn layout does not fit at ${Math.round(g)}px: no clean seat for ${_.unseated.map(O=>e.type==="sequence"?`message ${O}`:`"${e.edges[O]?.label}"`).join(", ")}`)}let A=h({...i,...T,layout:"stacked",heights:void 0,grow:ut(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0});if(A=S(A),r(A),e.type==="sequence"||e.type==="schema")return{dyn:A,geo:null,ink:"",tokens:m,least:c.least};const B=ie(e);let J=qe(I(),f,B,A.grow);for(let L=0;L<6&&Object.keys(J.grow).length;L++){const N=ut(A.grow);for(const[_,E]of Object.entries(J.grow))N[_]=(gt(N,_)??0)+E;A={...A,grow:N},r(A),J=qe(I(),f,B,N)}const j=J.geo;if(!B.third&&B.laneCount>2&&o?.(`the stacked drawing uses ${B.laneCount} end lanes (four at most)`),j.unseated.length>0||j.through.length>0||j.outside.length>0||B.third){j.unseated.length&&o?.(`the stacked drawing has no clean seat for ${[...new Set(j.unseated)].map(_=>`"${e.edges[_]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),j.through.length&&o?.(`in the stacked drawing ${M(j,j.through)} would pass through a node, so its lines are not drawn`),j.outside.length&&o?.(`in the stacked drawing ${M(j,j.outside)} would leave the drawing, so its lines are not drawn`),B.third&&o?.("the stacked drawing would need a fifth end lane, so its lines are not drawn");const L={...j,lines:[],labels:[],crossings:[]};return{dyn:h({...A,grow:ut(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:L,ink:"",tokens:m,least:c.least}}return j.crossings.length&&o?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${j.crossings.map(L=>`${Lt(e,j.lines[L.top])} over ${Lt(e,j.lines[L.under])}`).join("; ")}`),{dyn:A,geo:j,ink:Oe(n,j,m,s),tokens:m,least:c.least}}function Lt(t,e){const n=t.byId.get(e.from)?.name??e.from,s=t.byId.get(e.to)?.name??e.to;return`${n} to ${s}`}function jn(t,e,n,s,i,r){const o=new Set;if(r){o.add(r);for(const h of n?.lines??[])h.from===r&&o.add(h.to),h.to===r&&o.add(h.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(h=>h.toggleAttribute("data-near",o.has(h.dataset.node))),!n||!s)return;const a=h=>!!r&&(h.from===r||h.to===r),l=t.querySelector(`.${e}-edges`),d=new Map;t.querySelectorAll(`.${e}-edge`).forEach(h=>d.set(h.getAttribute("data-edge"),h));for(const h of n.lines){const u=d.get(String(h.i));u&&(u.toggleAttribute("data-lit",a(h)),u.toggleAttribute("data-dim",!!r&&!a(h)))}if(t.querySelectorAll(`.${e}-label`).forEach(h=>{const u=n.lines.find(S=>String(S.i)===h.dataset.edge);h.toggleAttribute("data-lit",!!(u&&a(u)))}),l){for(const h of n.lines)if(a(h)){const u=d.get(String(h.i));u&&l.appendChild(u)}}const m=Tt(n.lines,a),{defs:f,ids:c}=_e(e,{...n,crossings:m},s,i),g=t.querySelector(`.${e}-svg`);if(!g)return;let x=g.querySelector("defs");!x&&f&&(x=document.createElementNS("http://www.w3.org/2000/svg","defs"),g.insertBefore(x,g.firstChild)),x&&(x.innerHTML=f),n.lines.forEach((h,u)=>{const S=d.get(String(h.i))?.querySelector(`.${e}-line`);if(!S)return;const I=c.get(u);I?S.setAttribute("mask",`url(#${I})`):S.removeAttribute("mask")})}var Bn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Tn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Bn()||Wn(t)?"done":"pending")}}var Rn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Wn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Rn(t))!==null}catch{return!1}}function Ce(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Fn(t,e,n,s=!1,i=!1){const r=s?Ot(t):null;if(r&&n.startsWith("Arrow")){const d={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return d?r[e]?.[d]??null:null}const o=t.byId.get(e)?.i??0,a=t.nodes.length;let l;if(n==="ArrowRight"||n==="ArrowDown")l=o+1;else if(n==="ArrowLeft"||n==="ArrowUp")l=o-1;else if(n==="Home")l=0;else if(n==="End")l=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,l))].id}var Nn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],je=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],zn=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad","--_gw","--_mh"],Be=t=>t==null||t===!1;function Hn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Rt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const s=n?je:Nn;for(const o of s)Be(e.a[o])&&t.removeAttribute(o);for(const[o,a]of Object.entries(e.a)){if(o==="class")continue;if(o==="style"){const d=t.style,m=new Map(String(a??"").split(";").map(f=>{const c=f.indexOf(":");return[f.slice(0,c).trim(),f.slice(c+1).trim()]}).filter(([f])=>f));for(const[f,c]of m)d.getPropertyValue(f).trim()!==c&&d.setProperty(f,c);for(const f of zn)m.has(f)||d.removeProperty(f);continue}if(n&&!je.includes(o))continue;if(Be(a)){t.removeAttribute(o);continue}const l=a===!0?"":String(a);t.getAttribute(o)!==l&&t.setAttribute(o,l)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(o=>typeof o!="string"&&"slot"in o))return;const i=[...t.children];let r=0;for(const o of e.c)if(!(typeof o=="string"||"slot"in o)){for(let a=r;at.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(s)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",s=0;function i(c,g,x){return{prefix:n,base:c,hasSource:g.source!==void 0&&g.source!==null&&g.source!=="",hiddenClass:"visually-hidden",viewer:x?x.keys:void 0}}function r(c,g,x,h){var u=function(S){return''+it(S)+""};return{source:it(String(g.source||"")),summary:it(String(g.summary||"")),hint:Dt(c).map(function(S){return""+S.keys.map(u).join(" ")+" "+it(S.words)+""}).join(""),toggle:'"}}function o(c,g,x){var h=wt(c),u=Ct(h,{},i(g,c,x)),S=Nt(u,r(h,c,g,!1)),I=S.indexOf(">");return{open:S.slice(0,I+1),inner:S.slice(I+1,S.length-9),warnings:h.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-layout","data-measured","data-bare"],l=["--_cols","--_gpad","--_track"];function d(c,g,x,h){c.__diagram&&c.__diagram.stop();var u=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),S=getComputedStyle(c).direction==="rtl",I=g.layout==="auto"&&(g.type==="architecture"||g.type==="flowchart"||g.type==="schema"),T=I?Array.isArray(g.placement)?g.placement:g.placement?[g.placement]:[]:[];I&&!T.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var M=g.direction?[g.direction]:g.type==="flowchart"?["down","right"]:["right","down"],A=function(H){for(var Y=0;Y .diagram-drawing")){if(!u||!c.querySelector("#"+CSS.escape(u+"-title"))){for(;document.getElementById("dg"+ ++s+"-title"););u="dg"+s}var J=o(g,u,h),j=document.createElement("div");j.innerHTML=J.open+"";var Q=j.firstChild;a.forEach(function(H){c.removeAttribute(H)}),l.forEach(function(H){c.style.removeProperty(H)});for(var L=0;L :not(script[data-diagram])").forEach(function(H){H.remove()}),c.insertAdjacentHTML("beforeend",J.inner)}B.warnings.forEach(function(H){console.warn("Basalt diagram: "+H)});var _=i(u,g,h),E={},O=null,R=null,D=null,W=null,tt=Object.create(null),K=function(H){tt[H]||(tt[H]=1,console.warn("Basalt diagram: "+H))},y=function(H){Rt(c,Ct(B,H,_))},b=c.querySelector(".diagram-ink"),p=c.querySelector(".diagram-toggle"),k=!h&&B.motion.animated&&typeof e.diagramMotion=="function",$=null,w=null,C=function(){k&&Ce(c)};function q(){jn(c,n,O&&O.geo,O&&O.tokens,u,R||W||D),nt()}var F=null,X=!h&&matchMedia("(hover: none), (pointer: coarse)").matches;function nt(){var H=X&&!h&&b&&b.innerHTML!=="";if(c.toggleAttribute("data-touch",!!(X&&!h)),H&&!F){var Y=c.querySelector(":scope > .diagram-foot");if(!Y)return;F=document.createElement("button"),F.type="button",F.className="btn diagram-clear",F.setAttribute("data-variant","secondary"),F.setAttribute("data-size","sm"),F.innerHTML="Clear highlight",F.addEventListener("click",function(){W&&(W=null,q())}),Y.appendChild(F)}else!H&&F&&(F.remove(),F=null);F&&(W?F.removeAttribute("aria-disabled"):F.setAttribute("aria-disabled","true"))}function z(H){if(!H.defaultPrevented){var Y=en(c,n,H,W);Y!==void 0&&(C(),X=!0,W=Y,q())}}function G(){p&&(p.setAttribute("aria-expanded",String(!!E.open)),p.firstElementChild.textContent=E.open?"Hide the list":"View as list")}function et(){if(I&&T.length>1&&!h){for(var H=null,Y=0;Y1&&h&&!g.direction&&h.room){for(var He=h.room(),De=-1,Jt=null,Xt=0;XtDe+1e-6&&(De=Ke,Jt=Yt)}}}Jt&&(B=Jt)}O=(h?h.measure:Zt)(c,B,n,u,E,y,K),E=O.dyn,y(E),G();var Qt=c.querySelector(":scope > .diagram-hint");if(Qt){var Ve=Dt(B,E.layout==="drawn").map(function(St){return""+St.keys.map(function(Zn){return''+it(Zn)+""}).join(" ")+" "+it(St.words)+""}).join("");Qt.innerHTML!==Ve&&(Qt.innerHTML=Ve)}bt(B,E)||(D=W=null);var Ze=b&&O.ink!==w;Ze&&(b.innerHTML=O.ink,w=O.ink),q(),k&&O.tokens&&(Tn(c,!!(O.geo&&O.geo.lines.length)),Ze&&$&&$.redrawn()),h&&h.onMeasured&&O.tokens&&h.onMeasured(O,c),B.text&&typeof e.diagramText=="function"&&e.diagramText(c,B,g)}function ot(H){E=H,y(E)}function V(H){var Y=E.stop;E=Object.assign({},E,{stop:H}),Dn(c,n,Y,H)}var P=function(H){var Y=H&&H.closest?H.closest(".diagram-node"):null;return Y&&c.contains(Y)?Y:null};function Z(H){var Y=P(H.target);if(!(!Y||H.defaultPrevented)){if(C(),H.key==="Escape"){!h&&(R||D||W)&&(H.preventDefault(),R=D=W=null,q());return}if(bt(B,E)){var dt=Fn(B,Y.getAttribute("data-node"),H.key,E.layout==="drawn");if(dt){H.preventDefault(),V(dt);var Mt=c.querySelector('.diagram-node[data-node="'+CSS.escape(dt)+'"]');Mt&&Mt.focus()}}}}function U(H){var Y=P(H.target);if(Y){C();var dt=Y.getAttribute("data-node");R=Y.matches(":focus-visible")?dt:null,bt(B,E)&&E.stop!==dt&&V(dt),q()}}function at(H){var Y=P(H.target);Y&&(P(H.relatedTarget)||(R=null),E.keep===Y.getAttribute("data-node")&&ot(Object.assign({},E,{keep:void 0})),q())}function ct(H){if(!(H.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var Y=P(H.target);Y&&C();var dt=Y&&bt(B,E)?Y.getAttribute("data-node"):null;dt!==D&&(D=dt,q())}}function It(){D&&(D=null,q())}function $t(){C(),ot(Object.assign({},E,{open:!E.open,autoOpen:void 0})),G()}c.addEventListener("keydown",Z),c.addEventListener("focusin",U),c.addEventListener("focusout",at),c.addEventListener("pointerover",ct),c.addEventListener("pointerleave",It),c.addEventListener("click",z),p&&p.addEventListener("click",$t),et();var kt=c.clientWidth,Ut=0,Te=!0,Re=new ResizeObserver(function(){Math.abs(c.clientWidth-kt)<.5||(kt=c.clientWidth,cancelAnimationFrame(Ut),Ut=requestAnimationFrame(et))});Re.observe(c),document.fonts&&document.fonts.ready.then(function(){Te&&et()});var We=matchMedia("(forced-colors: active)"),Fe=B.nodes.some(function(H){return H.mark});Fe&&We.addEventListener("change",et),k&&($=e.diagramMotion(c,{fig:c,P:n,base:u,model:function(){return B},geo:function(){return O&&O.geo},tokens:function(){return O&&O.tokens}},g));var Ne=!h&&g.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,g,{model:B,settle:C,animated:k}):null,ze=c.querySelector(":scope > .diagram-foot"),Gn=!h&&g.export===!0&&ze&&typeof e.diagramExport=="function"?e.diagramExport(ze,c):[];c.__diagram={stop:function(){Ne&&Ne.destroy(),Gn.forEach(function(H){H.remove()}),Te=!1,Re.disconnect(),cancelAnimationFrame(Ut),Fe&&We.removeEventListener("change",et),$&&$.destroy(),c.removeEventListener("keydown",Z),c.removeEventListener("focusin",U),c.removeEventListener("focusout",at),c.removeEventListener("pointerover",ct),c.removeEventListener("pointerleave",It),c.removeEventListener("click",z),F&&F.remove(),p&&p.removeEventListener("click",$t)},layout:et,key:m(g),send:$&&$.sendValue?$.sendValue:null}}function m(c){try{return JSON.stringify(c,function(g,x){return g==="packet"&&x&&typeof x=="object"?Object.assign({},x,{send:void 0}):x})}catch{return null}}function f(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var g=c.querySelector(":scope > script[data-diagram]");if(g)try{d(c,JSON.parse(g.textContent),!0)}catch(x){console.error("Basalt diagram: this figure could not be drawn",x)}}})}e.diagramMarkup=o,e.diagramKit={draw:d,buildModel:wt,figureKey:ln,figureList:mn,hintEntries:Dt,toHtml:Nt,escapeHtml:it,settleEntrance:Ce,measureFigure:Zt},t.diagram=function(c,g){var x=c.__diagram,h=x&&x.send?m(g):null;if(h!==null&&h===x.key){x.send(g.packet?g.packet.send:void 0);return}d(c,g)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); +(()=>{var on=["top","right","bottom","left"],sn=["main","plain","dashed"],he=["one","zero-or-one","one-or-many","zero-or-many"],Ft={one:"Exactly one","zero-or-one":"Zero or one","one-or-many":"One or many","zero-or-many":"Zero or many"},an=[2,3,4,5,6],gt=t=>t==null||t===""?void 0:String(t),At=t=>Object.assign(Object.create(null),t),Ot=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function zt(t,e={}){const o=e.checks!==!1,i=[],r=m=>{i.push(m)},s=t.legend??{},a={};for(const m of["main","plain","dashed","focal","group","activation"]){const y=gt(s[m]);y&&(a[m]=y)}const l=t.stepLabel,d=typeof l=="function"?m=>String(l(m)):typeof l=="string"?(m=>l.replace("{n}",String(m))):m=>`Step ${m}`,g=t.shapeLabels??{},f={terminal:gt(g.terminal)??"Start or end",step:gt(g.step)??"Step",decision:gt(g.decision)??"Decision"},c=t.heading===void 0?3:an.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),p=(m,y)=>m==null?"plain":sn.includes(m)?m:(r(`"${String(m)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),w=m=>{if(m!=null){if(on.includes(m))return m;r(`"${String(m)}" is not a side (top, right, bottom or left): the derived side is used`)}},h=(m,y)=>typeof m=="number"&&Number.isInteger(m)&&m>=1?m:(t.layout==="auto"&&m==null||r(`${y} is ${JSON.stringify(m)}, not a whole number from 1: it is placed at 1`),1),u=[],M=[];let C=[];const H=[],v=[],E=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(E)||r(`"${String(E)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),E==="architecture"||E==="flowchart"){for(const m of t.nodes??[]){const y=E==="flowchart"&&m.shape==="decision"?"decision":E==="flowchart"&&m.shape==="terminal"?"terminal":"box",k=String(m.id??""),q=h(m.row,`the row of ${k}`);u.push({id:k,i:u.length,name:String(m.name??""),kind:y==="decision"?void 0:gt(m.kind),detail:y==="decision"?void 0:gt(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:h(m.col,`the column of ${k}`),row:q,row2:q,branch:!!m.branch,shape:y,group:E==="architecture"?gt(m.group):void 0,mark:E==="architecture"?ee(m.mark):void 0})}if(E==="architecture"){const m=(t.groups??[]).map(I=>({id:String(I.id??""),label:String(I.label??""),parent:gt(I.parent)})),y=new Map(m.map(I=>[I.id,I])),k=I=>{if(!I.parent)return 1;const B=y.get(I.parent);return B?B.parent===I.id||B.id===I.id?(r(`the groups "${I.label}" and "${B.label}" are each other's parent`),I.parent=void 0,1):B.parent?(r(`the group "${I.label}" is a third level: groups nest two deep`),I.parent=void 0,1):2:(r(`the group "${I.label}" names the parent "${I.parent}", which is not a group`),I.parent=void 0,1)},q=m.map(k);m.forEach((I,B)=>H.push({...I,depth:q[B],members:u.filter(ot=>ot.group===I.id).map(ot=>ot.id),all:[]}));for(const I of H)I.all=[...I.members,...H.filter(B=>B.parent===I.id).flatMap(B=>B.members)];H.sort((I,B)=>I.depth-B.depth)}}else if(E==="data-flow"){C=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const m=new Map(C.map((y,k)=>[y.id,k+1]));for(const y of t.nodes??[]){const k=String(y.id??""),q=String(y.lane??""),I=m.get(q);I===void 0&&r(`a node (${k}) names the lane "${q}", which is not in lanes`);const B=u.length+1;u.push({id:k,i:u.length,name:String(y.name??""),kind:d(B),detail:gt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:h(y.col,`the column of ${k}`),row:I??1,row2:I??1,branch:!1,shape:"box",lane:I??1,laneLabel:C[(I??1)-1]?.label??q,step:B,mark:ee(y.mark)})}}else if(E==="sequence"){(t.participants??[]).forEach((q,I)=>{const B=String(q.name??"");u.push({id:String(q.id??""),i:I,name:B,kind:gt(q.kind),mono:!1,focal:!!q.focal,col:I+1,row:1,row2:1,branch:!1,shape:"participant",short:gt(q.short)??B,mark:ee(q.mark)})});let m=0;const y=new Map(u.map(q=>[q.id,q.col])),k=(q,I)=>{let B=1/0,ot=-1/0;for(const G of q??[]){if(!G||typeof G!="object")continue;if("band"in G){I>0&&r(`the band "${String(G.band)}" is inside a frame: a band is the whole figure's`),v.push({band:String(G.band??"")});continue}if("frame"in G){if(I>=2){r("a frame is a third level: frames nest two deep");continue}const wt=G.frame==="alt"||G.frame==="loop"||G.frame==="opt"?G.frame:"opt",Mt=wt==="alt"?G.branches??[]:[{label:G.label,steps:G.steps}];wt==="alt"&&Mt.length<2&&r("an alt frame has one branch: it needs two or more");const vt=String(Mt[0]?.label??"");vt.length>40&&r(`the frame label "${vt}" is over 40 characters`);const pt=v.length;v.push({open:wt,label:vt,depth:I+1,a:0,b:0}),Mt.forEach((lt,dt)=>{if(dt){const L=String(lt.label??"");L.length>40&&r(`the frame label "${L}" is over 40 characters`),v.push({otherwise:L,depth:I+1})}lt.steps?.length||r(`a frame or branch ("${String(lt.label??"")}") is empty`);const[$t,$]=k(lt.steps??[],I+1);B=Math.min(B,$t),ot=Math.max(ot,$);const A=v[pt];A.a=Math.min(A.a||1/0,$t),A.b=Math.max(A.b,$)}),v.push({close:I+1});continue}m++;const nt=String(G.label??"");nt.includes(` +`)&&r(`message ${m}'s label has a break: a message's second line is its note`);const ft=String(G.from??""),ut=String(G.to??"");v.push({n:m,from:ft,to:ut,label:Ct(nt),note:gt(G.note),kind:p(G.kind,`message ${m}`),activate:G.activate===!0||void 0,deactivate:G.deactivate===!0||void 0});const st=y.get(ft)??1,ht=y.get(ut)??1,bt=st===ht?st===u.length?st-1:st+1:st;B=Math.min(B,st,ht,bt),ot=Math.max(ot,st,ht,bt)}return[B,ot]};k(t.steps??[],0);for(const q of v)"open"in q&&!Number.isFinite(q.a)&&(q.a=1,q.b=Math.max(1,u.length))}else if(E==="schema")for(const m of t.tables??[]){const y=String(m.name??""),[k,q]=Array.isArray(m.row)?m.row:[m.row,m.row],I=h(k,`the row of ${y}`),B=Math.max(I,h(q,`the last row of ${y}`)),ot=m.more===void 0||m.more===null?void 0:Number.isInteger(m.more)&&m.more>0?m.more:(r(`${y}'s "more" is ${JSON.stringify(m.more)}, not a whole number from 1: it is left out`),void 0);u.push({id:y,i:u.length,name:y,mono:!0,focal:!!m.focal,col:h(m.col,`the column of ${y}`),row:I,row2:B,branch:!1,shape:"table",more:ot,columns:(m.columns??[]).map(G=>({name:String(G.name??""),type:gt(G.type),key:G.key==="PK"||G.key==="FK"?G.key:(G.key!==void 0&&G.key!==null&&r(`${y}.${String(G.name)}'s key is "${String(G.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(E==="architecture"||E==="flowchart"||E==="schema")){const m=E==="schema"?t.tables:t.nodes;o&&(m??[]).some(k=>k&&(k.col!==void 0||k.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const y=e.placement?.cells;y||(T=!0);for(const k of u){const q=y?.[k.id];k.col=q?.col??1,k.row=k.row2=q?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${E}`);((E==="schema"?t.tables:E==="sequence"?t.participants:t.nodes)??[]).forEach((m,y)=>{if(!m||m.href===void 0||m.href===null)return;const k=String(m.href);if(E==="sequence"){r(`${u[y]?.id}: a participant cannot be a link (href)`);return}if(!k){r(`${u[y]?.id}'s href is empty`);return}const q=u[y];q&&(q.href=k,q.blank=m.target==="_blank")});const z=new Map;for(const m of u)m.id?z.has(m.id)&&r(`the id "${m.id}" is used twice`):r("a node has no id"),z.set(m.id,m);if(E==="schema"){const m=(k,q)=>{if(k==null)return;const I=k,B=he.includes(I.from)?I.from:void 0;if(!B){r(`${q}'s cardinality "from" is ${JSON.stringify(I.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`);return}return I.to===void 0||I.to===null?{from:B,to:"one"}:I.to==="one"||I.to==="zero-or-one"?{from:B,to:I.to}:(r(`${q}'s cardinality "to" is ${JSON.stringify(I.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`),{from:B,to:"one"})};(t.tables??[]).forEach(k=>(k.columns??[]).forEach((q,I)=>{const B=gt(q.references);if(!B&&q.cardinality!==void 0&&q.cardinality!==null&&r(`${String(k.name)}.${String(q.name)} states a cardinality but references nothing`),!B)return;const[ot,G]=B.split("."),nt=z.get(ot??""),ft=nt?.columns?.findIndex(ht=>ht.name===G)??-1;if(!nt||ft<0){r(`${String(k.name)}.${String(q.name)} references ${B}, which is not a shown column`);return}const ut=z.get(String(k.name??""));ut.columns[I].ref={table:ot,column:G,row:ft};const st=m(q.cardinality,`${String(k.name)}.${String(q.name)}`);st&&(ut.columns[I].card=st),M.push({i:M.length,from:ut.id,to:ot,kind:"plain",fromRow:I,toRow:ft,fk:!0,card:st})}));const y=M.filter(k=>k.card).length;y&&y!k.card).map(k=>`${k.from}.${z.get(k.from).columns[k.fromRow].name}`).join(", ")} ${M.length-y===1?"has":"have"} none)`)}else if(E!=="sequence")for(const m of t.edges??[]){const y=String(m.from??""),k=String(m.to??"");if(!z.has(y)||!z.has(k)){r(`a line names ${z.has(y)?k:y}, which is not a node`);continue}const q=gt(m.label),I=q?.split(` +`)??[];I.length>2&&r(`the label "${Ct(q)}" has more than one break: a label is two lines at most`),I.some(B=>B.length>ge)&&r(`a line of the label "${Ct(q)}" is over ${ge} characters: longer words belong in the node or the summary`),M.push({i:M.length,from:y,to:k,kind:p(m.kind,`the line from ${y} to ${k}`),label:q,fromSide:w(m.fromSide),toSide:w(m.toSide),flow:E!=="flowchart"&&m.flow===!0?!0:void 0})}else for(const m of v)"n"in m&&(!z.has(m.from)||!z.has(m.to))&&r(`message ${m.n} names ${z.has(m.from)?m.to:m.from}, which is not a participant`);if(o&&E!=="sequence"&&!T){const m=new Map;for(const y of u)for(let k=y.row;k<=y.row2;k++){const q=`${y.col}:${k}`;m.has(q)&&r(`${y.id} and ${m.get(q)} share the cell at column ${y.col}, row ${k}`),m.set(q,y.id)}}if(o&&!T){for(const y of H){const k=y.all.map(B=>z.get(B));if(!k.length)continue;const q={c1:Math.min(...k.map(B=>B.col)),c2:Math.max(...k.map(B=>B.col)),r1:Math.min(...k.map(B=>B.row)),r2:Math.max(...k.map(B=>B.row2))};for(const B of u)!y.all.includes(B.id)&&B.col>=q.c1&&B.col<=q.c2&&B.row>=q.r1&&B.row<=q.r2&&r(`${B.id} is inside the box of the group "${y.label}" but not a member`);const I=k.map(B=>B.i);Math.max(...I)-Math.min(...I)+1!==I.length&&r(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of u)y.group&&!H.some(k=>k.id===y.group)&&r(`${y.id} names the group "${y.group}", which is not in groups`);u.filter(y=>y.focal).length>1&&r("more than one node is focal: a diagram has one at most");const m=new Set(E==="sequence"?v.flatMap(y=>"n"in y?[y.kind]:[]):M.map(y=>y.kind));m.has("main")&&!a.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),m.has("dashed")&&!a.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),u.some(y=>y.focal)&&!a.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const it=E==="architecture"||E==="data-flow",_=m=>Array.isArray(m)&&m.length>1?m.map(String):void 0,D=it&&t.packet&&typeof t.packet=="object"?t.packet:void 0,j=D&&_(D.path),x={animated:t.motion==="animated",pulse:it?_(t.pulse):void 0,packet:j?{path:j,repeat:D.repeat===!0,send:D.send}:void 0,run:E==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(o)for(const m of u){const y=m.mark?.says;if(!y?.length)continue;const k=[m.name,m.kind,m.detail,m.laneLabel].filter(Boolean).join(" ").toLowerCase();y.some(q=>k.includes(q.toLowerCase()))||r(`${m.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const R=[];if(E==="sequence"){const m=new Map,y=new Map;for(const k of v)"n"in k&&(y.set(k.from,k.n),y.set(k.to,k.n));for(const k of v)if("n"in k){if(k.activate){const q=m.get(k.to)??[];if(q.length>=3)r(`message ${k.n} opens a fourth bar on ${k.to}: three deep at most`);else{const I={who:k.to,from:k.n,to:k.n,depth:q.length+1};q.push(I),R.push(I),m.set(k.to,q)}}if(k.deactivate){const I=m.get(k.from)?.pop();I?I.to=k.n:r(`message ${k.n} closes a bar on ${k.from}, which has none open`)}}for(const[k,q]of m)for(const I of q)I.to=Math.max(I.from,y.get(k)??I.from)}const F=t.frameLabels??{},Z={opt:gt(F.opt)??"Only if",loop:gt(F.loop)??"Repeats",alt:gt(F.alt)??"One of these",else:gt(F.else)??"Otherwise"};let K=Math.max(1,...u.map(m=>m.col));if(e.rtl){for(const y of u)y.col=K-y.col+1;const m=y=>y==="left"?"right":y==="right"?"left":y;for(const y of M)y.fromSide=m(y.fromSide),y.toSide=m(y.toSide);for(const y of v)if("open"in y){const[k,q]=[K-y.b+1,K-y.a+1];y.a=k,y.b=q}K=Math.max(1,...u.map(y=>y.col))}const rt=E==="data-flow"?Math.max(1,C.length):Math.max(1,...u.map(m=>m.row2)),U={type:E,title:String(t.title??""),heading:c,legend:a,nodes:u,byId:z,edges:M,groups:H,lanes:C,steps:v,bars:R,frameWords:Z,cols:K,rows:rt,shapeLabels:f,stepWord:d,warnings:i,motion:x,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0,text:E==="sequence"&&t.variant==="text"||void 0,marks:M.some(m=>m.card)||void 0};if(t.layout==="auto"&&!T&&E!=="schema"&&rn(U),o)for(const[m,y]of Object.entries(Te(U)))y>=48&&r(`${m} grows to ${y}px to hold the lines on one side: use another side`);return o&&u.length>1&&!Zt(U)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),U}function rn(t){const e=new Set(t.nodes.map(s=>`${s.col},${s.row}`)),n=(s,a)=>{const l=[];for(let d=Math.min(s,a)+1;d{const a=t.byId.get(s.from),l=t.byId.get(s.to),d=l.col>a.col?"right":"left",g=l.row>a.row?"bottom":"top",f=l.col>a.col?"left":"right",c=l.row>a.row?"top":"bottom",p=(h,u,M,C)=>n(h,u).map(H=>C?[H,M]:[M,H]);let w;return a.row===l.row?w=[{sides:[d,f],cells:p(a.col,l.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===l.col?w=[{sides:[g,c],cells:p(a.row,l.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:w=[{sides:[d,c],cells:[...p(a.col,l.col,a.row,!0),[l.col,a.row],...p(a.row,l.row,l.col,!1)]},{sides:[g,f],cells:[...p(a.row,l.row,a.col,!1),[a.col,l.row],...p(a.col,l.col,l.row,!0)]},{sides:[d,f],cells:p(a.col,l.col,a.row,!0)},{sides:[g,c],cells:p(a.row,l.row,a.col,!1)}],w.filter(h=>h.cells.every(([u,M])=>!e.has(`${u},${M}`)))},i=new Map,r=t.edges.map((s,a)=>a).sort((s,a)=>o(t.edges[s]).length-o(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[s].kind==="main")||s-a);for(const s of r){const a=t.edges[s];if(a.fromSide||a.toSide)continue;const l=o(a).find(d=>(i.get(`${a.from}.${d.sides[0]}`)??0)<3&&(i.get(`${a.to}.${d.sides[1]}`)??0)<3);if(l){for(const[d,g]of[[a.from,l.sides[0]],[a.to,l.sides[1]]])i.set(`${d}.${g}`,(i.get(`${d}.${g}`)??0)+1);a.fromSide=l.sides[0],a.toSide=l.sides[1]}}}function ee(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=gt(e.onLight);if(n)return{onLight:n,onDark:gt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var pe=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function qt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var ge=28,ne=t=>t.includes(` +`)?2:1,Ct=t=>t.replace(/\n/g," "),Nt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function me(t,e){return t.legend[e]}function ln(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function cn(t,e){return qt(t,`sentence:${e.i}`,()=>dn(t,e))}function dn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const o=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name}${r.card?`: ${ye(e.id,r.ref.table,r.card)}`:""})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name}${r.card?`: ${ye(r.from,r.to,r.card)}`:""})`);o.length&&n.push(`References ${o.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const o=t.steps.filter(s=>"n"in s&&s.from===e.id).length,i=t.steps.filter(s=>"n"in s&&s.to===e.id).length;n.push(Nt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${o} ${o===1?"message":"messages"} and receives ${i}.`);const r=$e(t,e);r&&n.push(r.trim())}else{const o=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?ln(t,e):e.kind;if(n.push(Nt(o?`${e.name}, ${o}`:e.name)),e.detail&&n.push(Nt(e.detail)),e.group){const s=t.groups.find(l=>l.id===e.group),a=s?.parent?t.groups.find(l=>l.id===s.parent):void 0;s&&n.push(a?`In ${s.label}, in ${a.label}.`:`In ${s.label}.`)}const i=t.edges.filter(s=>s.to===e.id).map(s=>`${t.byId.get(s.from).name}${s.label?` (${Ct(s.label)})`:""}`),r=t.edges.filter(s=>s.from===e.id).map(s=>`${t.byId.get(s.to).name}${s.label?` (${Ct(s.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(Nt(t.legend.focal)),n.join(" ")}var fn=(t,e,n,o)=>[`${Ft[n.from].toLowerCase()} `,o(t),` to ${Ft[n.to].toLowerCase()} `,o(e)],ye=(t,e,n)=>`${Ft[n.from].toLowerCase()} ${t} to ${Ft[n.to].toLowerCase()} ${e}`;function $e(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function un(t,e,n,o){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),s=n.target;if(!r||!s||!r.contains(s)||!t.querySelector(`.${e}-edge`))return;const a=s.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===o?null:a.dataset.node??null:null}function be(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function b(t,e,...n){const o=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&o.push(i);return{t,a:e??{},c:o}}var hn={"&":"&","<":"<",">":">",'"':""","'":"'"},mt=t=>t.replace(/[&<>"']/g,e=>hn[e]),pn=" br img input meta link hr path polygon polyline circle rect line ";function oe(t,e={}){if(typeof t=="string")return mt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[o,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(o))throw new Error(`diagram: "${o}" is not an attribute name`);n+=i===!0?` ${o}`:` ${o}="${mt(String(i))}"`}return pn.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(o=>oe(o,e)).join("")}`}var gn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function jt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function mn(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Vt(t,e){const n=e.all.map(o=>t.byId.get(o));return n.length?{c1:Math.min(...n.map(o=>o.col)),c2:Math.max(...n.map(o=>o.col)),r1:Math.min(...n.map(o=>o.row)),r2:Math.max(...n.map(o=>o.row2))}:null}function we(t){return qt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const o=Vt(t,n);if(!o)continue;[o.r1===1,o.c2===t.cols,o.r2===t.rows,o.c1===1].forEach((r,s)=>{r&&(e[s]=Math.max(e[s],ve(t,n,s)))})}return e})}function ve(t,e,n){const o=Vt(t,e);return t.groups.filter(s=>s.parent===e.id).some(s=>{const a=Vt(t,s);return a&&[a.r1===o.r1,a.c2===o.c2,a.r2===o.r2,a.c1===o.c1][n]})?2:1}function xe(t){const e=we(t);return e[1]+e[3]}function se(t){return t.type==="sequence"?t.nodes.length:t.cols}function ke(t){return qt(t,"plan",()=>yn(t))}function yn(t){const e=t.nodes,n=u=>t.type==="data-flow"||!e[u].branch,o=t.edges.map(u=>{const M=t.byId.get(u.from).i,C=t.byId.get(u.to).i,v=e.slice(Math.min(M,C)+1,Math.max(M,C)).every(E=>!n(E.i));return C===M+1&&!(n(M)&&!n(C))?"down":C===M-1?"up":C>M&&n(M)&&!n(C)&&v?"trunk":C>M&&n(M)&&n(C)&&v?"rail":C>M?"end-down":"end-up"}),i=t.edges.map((u,M)=>({e:u,k:M})).filter(({k:u})=>o[u]==="end-down"||o[u]==="end-up"),r=u=>{const M=t.byId.get(u.from).i,C=t.byId.get(u.to).i;return[Math.min(M,C),Math.max(M,C)]},s=(u,M)=>{const[C,H]=r(u),[v,E]=r(M);return C{const M=t.byId.get(u.from).i,[C,H]=r(u);return!n(M)&&e.slice(C+1,H).every(v=>!n(v.i))&&i.every(v=>v.e===u||!s(v.e,u))}),l=i.length>0&&(t.type==="data-flow"||!a),d=u=>{const[M,C]=r(u);return C-M},g=t.edges.map(()=>0);let f=!1;const c=[];for(const u of[...i].sort((M,C)=>d(M.e)-d(C.e)||M.k-C.k)){let M=0;for(const C of c)s(C.e,u.e)&&(M=Math.max(M,g[C.k]+1));g[u.k]=M,M>3&&(f=!0),c.push(u)}const p=Math.max(0,...i.map(({k:u})=>g[u]+1)),w=t.edges.map(()=>.5);for(const u of e){const M=i.filter(({e:v})=>v.from===u.id);if(M.length<2)continue;const C=M.filter(({k:v})=>o[v]==="end-down").sort((v,E)=>d(E.e)-d(v.e)||v.k-E.k);[...M.filter(({k:v})=>o[v]==="end-up").sort((v,E)=>d(v.e)-d(E.e)||E.k-v.k),...C].forEach(({k:v},E,T)=>{w[v]=T.length===2?E===0?1/3:2/3:(E+1)/(T.length+1)})}const h=At();for(let u=1;u{const D=o[_],j=t.byId.get(it.from).i,x=t.byId.get(it.to).i,R=x===u&&(D==="down"||D==="trunk"||D==="rail"||D==="end-down"),F=j===u&&x===u-1&&D==="up",Z=x===u-1&&D==="end-up";R&&(D==="trunk"||D==="end-down")&&(E=!0),Z&&(T=!0),(R||F||Z)&&it.label&&(H++,v=Math.max(v,D==="trunk"?40:48))}),(H>1||E&&T)&&(v=64);const tt=i.filter(({e:it,k:_})=>o[_]==="end-down"&&t.byId.get(it.to).i===u).length,z=i.filter(({e:it,k:_})=>o[_]==="end-up"&&t.byId.get(it.to).i===u-1).length;v+=20*Math.max(0,tt-1)+20*Math.max(0,z-1),h[M.id]=v}return{routes:o,gutter:l,lanes:g,exits:w,gaps:h,third:f,laneCount:p}}var Tt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Me(t,e){const n=e==="fk"?"plain":e,o=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return b("svg",{class:`${t}-swatch`,"data-kind":n,...Tt(24,16)},e==="fk"?b("circle",{class:`${t}-dot`,cx:3,cy:o,r:3}):null,b("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${o}H${r}`}),n==="dashed"?b("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${o-4}L${i} ${o}L${i-8} ${o+4}`}):b("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${o}L${i-8} ${o-4}L${i-8} ${o+4}Z`}))}function $n(t,e){const{crow:n,ring:o}=Se(e,24,8.5,-1);return b("svg",{class:`${t}-swatch`,"data-card":e,...Tt(24,16)},b("path",{class:`${t}-line`,"data-kind":"plain",d:"M0 8.5H24"}),b("path",{class:`${t}-crow`,d:n}),o?b("circle",{class:`${t}-ring`,cx:o.x,cy:o.y,r:o.r}):null)}function Se(t,e,n,o,i=8,r=6){const s=p=>String(Math.round(p*100)/100),a=p=>e+o*p,l=i/2,d=p=>`M${s(a(p-.5))} ${s(n-l)}V${s(n+l)}`,g=t==="one-or-many"||t==="zero-or-many",f=t==="zero-or-one"||t==="zero-or-many";let c=g?`M${s(e)} ${s(n-l)}L${s(a(7.5))} ${s(n)}L${s(e)} ${s(n+l)}`:d(4);return f||(c+=d(g?11:8)),{crow:c,ring:f?{x:Math.round(a(10.5)*100)/100,y:n,r:r/2}:void 0}}function Ht(t,e){return e==="decision"?b("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},b("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?b("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},b("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):b("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},b("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Ee(t,e){return qt(e,`key:${t}`,()=>wn(t,e))}var bn=Ee;function wn(t,e){const n=[],o=(s,a,l={})=>n.push(b("li",{class:`${t}-entry`,...l},s,b("span",null,a)));if(e.type==="schema"){const s=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])s.has(a)&&n.push(b("li",{class:`${t}-entry`},b("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),b("span",null,l)))}if(e.type==="flowchart"){const s=new Set(e.nodes.map(a=>a.shape));s.has("terminal")&&o(Ht(t,"terminal"),e.shapeLabels.terminal),s.has("box")&&o(Ht(t,"box"),e.shapeLabels.step),s.has("decision")&&o(Ht(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(s=>"n"in s?[s.kind]:[]):e.edges.filter(s=>!s.fk).map(s=>s.kind)),r=(s,a)=>b("span",{class:`${t}-key-glyph`,"data-ink":a,"aria-hidden":"true"},s);for(const s of["main","plain","dashed"]){const a=e.legend[s];i.has(s)&&a&&o(e.text?r(s==="main"?"━━▶":s==="dashed"?"┄┄▷":"──▶",s==="main"?"main":"plain"):Me(t,s),a,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length){e.edges.some(a=>!a.card)&&o(Me(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"});const s=new Set(e.edges.flatMap(a=>a.card?[a.card.from,a.card.to]:[]));for(const a of he)s.has(a)&&o($n(t,a),Ft[a],{"data-line":"","data-when":"drawn","data-card":a});n.push(b("li",{class:`${t}-entry`,"data-when":"stacked"},b("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),b("span",null,"The table a foreign key references")))}if(e.type==="sequence"){e.bars.length&&o(e.text?r("┃","working"):b("svg",{class:`${t}-swatch`,"data-shape":"bar",...Tt(16,16)},b("path",{class:`${t}-life`,d:"M8 0V16"}),b("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const s=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])s.has(a)&&n.push(b("li",{class:`${t}-entry`},b("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),b("span",null,e.frameWords[a])))}return e.nodes.some(s=>s.focal)&&e.legend.focal&&o(Ht(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&o(Ht(t,"group"),e.legend.group),n.length?b("div",{class:`${t}-key`},b("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function vn(t,e){const n=e==="main"?6:6.5;return b("svg",{class:`${t}-arrow`,"data-kind":e,...Tt(20,12)},b("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?b("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):b("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function ae(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),b("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function xn(t,e,n){if(n.shape==="decision")return[b("span",{class:`${t}-words`},b("span",{class:`${t}-name`},ae(t,n)))];const o=[];return e.type==="data-flow"?o.push(b("span",{class:`${t}-kind`},n.kind,b("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&o.push(b("span",{class:`${t}-kind`},n.kind)),o.push(b("span",{class:`${t}-name`},ae(t,n))),n.detail&&o.push(b("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Yt(n.detail).flatMap((i,r)=>[r?" ":"",b("span",{class:`${t}-run`},i)]):n.detail)),o}function kn(t,e,n){return[b("span",{class:`${t}-th`},b("span",{class:`${t}-tname`},ae(t,e))),b("span",{class:`${t}-rows`},(e.columns??[]).map((o,i)=>b("span",{class:`${t}-row`,"data-row":i,"data-key":o.key},b("span",{class:`${t}-keyseat`},o.key??""),b("span",{class:`${t}-cname`},o.name),o.ref?b("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${o.ref.table}`):o.type?b("span",{class:`${t}-ctype`},o.type):null))),e.more?b("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ae=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Kt(t,e,n,o){const{P:i}=t,r=mn(e,o)||o.keep===n.id,s=jt(e,o),a=o.layout==="drawn"&&o.rows,l=[`--_c:${n.col}`,`--_r:${a?2*n.row:n.row}`,`--_r2:${a?2*n.row2+1:n.row2+1}`];e.type==="data-flow"&&l.push(`--_lc:${n.col+1}`),e.type==="sequence"&&l.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const w=Ot(d.gaps,n.id)??32,h=Ot(o.grow,n.id)??0;l.push(`--_gap:${h?`calc(${Ae(w)} + var(--basalt-space-4) * ${h})`:Ae(w)}`)}const g=Ot(o.heights,n.id);g&&l.push(`--_h:${g}px`);const f=Ot(Te(e),n.id);f&&l.push(`--_mh:${f}px`);const c=Ot(o.words,n.id);c&&l.push(`--_ww:${c}px`);const p=s?o.stop===n.id?0:-1:o.keep===n.id?-1:void 0;return b(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:l.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?cn(e,n):void 0,tabindex:p},n.shape==="decision"?b("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},b("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?b("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${pe(n.mark.onLight)};--_md:${pe(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?kn(i,n,e):xn(i,e,n))}function Mn(t,e,n){const{P:o}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((l,d)=>b("div",{class:`${o}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},b("span",{class:`${o}-lane-name`},l.label)))),e.type==="architecture")for(const l of e.groups){const d=Vt(e,l);if(!d)continue;const g=[0,1,2,3].map(f=>ve(e,l,f));i.push(b("div",{class:`${o}-gbox`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:`--_c:${d.c1};--_c2:${d.c2+1};--_r:${d.r1};--_r2:${d.r2+1}${g[0]>1?";--_gt:2":""}${g[1]>1?";--_ge:2":""}${g[2]>1?";--_gb:2":""}${g[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},b("span",{class:`${o}-glabel`},l.label)))}if(e.text)return[b("pre",{class:`${o}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},b("code",{class:`${o}-text-ink`},Sn(o,e)))];if(e.type==="sequence")return i.push(b("ul",{class:`${o}-cast`},e.nodes.map(l=>b("li",{class:`${o}-actor`,style:e.rtl?`--_ac:${l.col}`:void 0},Kt(t,e,l,n))))),i.push(En(t,e)),i;const r=l=>{const d=l.group?e.groups.find(g=>g.id===l.group):void 0;return d?.parent?e.groups.find(g=>g.id===d.parent):d},s=(l,d,g)=>{const f=t.plan?Ot(n.grow,d[0].id)??0:0;return b("div",{class:`${o}-group`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:f?`--_ggrow:${f}`:void 0},b("span",{class:`${o}-glabel`,"aria-hidden":"true"},l.label),g)};let a=0;for(;ah.id===g[c].group):void 0;if(!p){f.push(Kt(t,e,g[c],n)),c++;continue}const w=[];for(;cKt(t,e,h,n))))}i.push(s(d,g,f))}return i}function Sn(t,e){const n=[],o=s=>b("span",{class:`${t}-tx-name`},s),i=s=>s==="main"?"━▶":s==="dashed"?"┄▷":"─▶";n.push(b("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((s,a)=>[a?" · ":"",o(s.name)])),` +`);let r=0;for(const s of e.steps){const a=" ".repeat(r);if("band"in s){n.push(b("span",{class:`${t}-tx-line`,"data-ink":"band"},`${a}── ${s.band} ──`),` +`);continue}if("open"in s){n.push(b("span",{class:`${t}-tx-line`,"data-ink":"frame"},a,b("span",{"data-ink":"op"},`[${s.open}]`),` ${s.label}`),` +`),r++;continue}if("otherwise"in s){n.push(b("span",{class:`${t}-tx-line`,"data-ink":"frame"}," ".repeat(r-1),b("span",{"data-ink":"op"},"[else]"),` ${s.otherwise}`),` +`);continue}if("close"in s){r=Math.max(0,r-1),n.push(b("span",{class:`${t}-tx-line`,"data-ink":"frame"},`${" ".repeat(r)}[end]`),` +`);continue}const l=e.byId.get(s.from)?.name??s.from,d=e.byId.get(s.to)?.name??s.to;n.push(b("span",{class:`${t}-tx-line`,"data-n":s.n},a,b("span",{"data-ink":"num"},`${s.n} `),o(l)," ",b("span",{"data-ink":s.kind==="main"?"main":"plain"},i(s.kind))," ",o(d)," ",b("span",{"data-ink":"label"},s.label),s.note?[" ",b("span",{"data-ink":"note"},`(${s.note})`)]:null),` +`)}return n}function En(t,e){const{P:n}=t,o=[],i=[],r=()=>i.length?i[i.length-1].el.c:o;let s=null;for(const a of e.steps){if("band"in a){s=null,r().push(b("p",{class:`${n}-band`},b("span",null,a.band)));continue}if("open"in a){s=null;const h=i[i.length-1],u=h?`;--_fis:${a.a===h.a?1:0};--_fie:${a.b===h.b?1:0}`:"",M=b("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${u}`},b("span",{class:`${n}-fbox`,"aria-hidden":"true"}),b("p",{class:`${n}-fhead`},b("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),b("span",{class:`${n}-flabel`},b("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));r().push(M),i.push({el:M,a:a.a,b:a.b});continue}if("otherwise"in a){s=null,r().push(b("p",{class:`${n}-felse`},b("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),b("span",{class:`${n}-flabel`},b("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){s=null,i.pop();continue}s||(s=b("ol",{class:`${n}-msgs`,start:a.n}),r().push(s));const l=e.byId.get(a.from),d=e.byId.get(a.to),g=l?.col??1,f=d?.col??1,c=g===f,p=c&&(e.rtl?g!==1:g===e.nodes.length),w=me(e,a.kind);s.c.push(b("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":c?p?"start":"end":void 0,style:`--_a:${Math.min(g,f)};--_b:${Math.max(g,f)+1}`},b("span",{class:`${n}-said`},b("span",{class:`${n}-num`},String(a.n)),b("span",{class:`${n}-mlabel`},a.label)),b("span",{class:`${n}-route`},l?.short??a.from," ",vn(n,a.kind),b("span",{class:t.hidden}," to ")," ",d?.short??a.to,w?` · ${w}`:""),a.note?b("span",{class:`${n}-note`},a.note):null))}return b("div",{class:`${n}-steps`},o)}function Le(t,e){return qt(e,`list:${t}`,()=>Ln(t,e))}var An=Le;function Ln(t,e){const n=Math.min(6,e.heading+1),o=f=>b(`h${n}`,{class:`${t}-list-head`},f),i=f=>b("strong",null,f),r=f=>f.href?b("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},i(f.name)):i(f.name),s=f=>b("code",{class:`${t}-code`},f),a=f=>e.byId.get(f)?.name??f,l=f=>{const c=me(e,f);return c?` (${c})`:""},d=f=>f.focal&&e.legend.focal?` ${Nt(e.legend.focal)}`:"";if(e.type==="architecture"){const f=w=>b("li",null,r(w),w.kind?`, ${w.kind}`:"",w.detail?[". ",w.mono?s(w.detail):w.detail,/[.!?]$/.test(w.detail)?"":"."]:/[.!?]$/.test(w.kind??w.name)?"":".",d(w)),c=[o("Parts")],p=e.nodes.filter(w=>!w.group);p.length&&c.push(b("ul",{class:`${t}-list-items`},p.map(f)));for(const w of e.groups.filter(h=>h.depth===1)){c.push(b("p",{class:`${t}-list-group`},w.label)),w.members.length&&c.push(b("ul",{class:`${t}-list-items`},w.members.map(h=>f(e.byId.get(h)))));for(const h of e.groups.filter(u=>u.parent===w.id))c.push(b("p",{class:`${t}-list-group`,"data-depth":2},h.label)),c.push(b("ul",{class:`${t}-list-items`,"data-depth":2},h.members.map(u=>f(e.byId.get(u)))))}return c.push(o("Connections")),c.push(b("ol",{class:`${t}-list-items`},e.edges.map(w=>b("li",null,i(a(w.from))," to ",i(a(w.to)),w.label?[": ",s(Ct(w.label))]:"",`${l(w.kind)}.`)))),c}if(e.type==="flowchart"){const f=c=>(e.byId.get(c)?.i??0)+1;return[b("ol",{class:`${t}-list-items`},e.nodes.map(c=>{const p=e.edges.filter(u=>u.from===c.id),w=c.shape==="decision"?"Decision":c.shape==="terminal"?p.length?"Start":"End":"Step",h=!c.detail&&/[.!?]$/.test(c.name)?" ":". ";return b("li",null,r(c),c.detail?[", ",c.mono?s(c.detail):c.detail]:"",`${h}${w}.`,d(c),p.length?b("ul",{class:`${t}-list-exits`},p.map(u=>b("li",null,u.label?`If ${Ct(u.label)}: go to ${f(u.to)}, `:`Then: go to ${f(u.to)}, `,i(a(u.to)),l(u.kind)))):null)}))]}if(e.type==="data-flow")return[b("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const c=e.edges.filter(p=>p.from===f.id);return b("li",null,`${f.laneLabel}: `,r(f),f.detail?[", ",f.mono?s(f.detail):f.detail]:"",".",d(f),c.length?[" Then ",...c.flatMap((p,w)=>[w?"; ":"",`to step ${e.byId.get(p.to).step}, `,i(a(p.to)),p.label?[": ",s(Ct(p.label))]:"",l(p.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[o("Participants"),b("ul",{class:`${t}-list-items`},e.nodes.map(p=>b("li",null,i(p.name),p.kind?`, ${p.kind}`:"",".",d(p),$e(e,p))))];f.push(o("Messages"));let c=null;for(const p of e.steps){if("band"in p){c=null,f.push(b(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},p.band));continue}if("open"in p){c=null,f.push(b(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":p.depth>1?p.depth:void 0},`${e.frameWords[p.open]}: ${p.label}`));continue}if("otherwise"in p){c=null,f.push(b(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":p.depth>1?p.depth:void 0},`${e.frameWords.else}: ${p.otherwise}`));continue}if("close"in p){c=null;continue}c||(c=b("ol",{class:`${t}-list-items`,start:p.n}),f.push(c)),c.c.push(b("li",null,s(p.label),": ",i(a(p.from))," to ",i(a(p.to)),`${l(p.kind)}.`,p.note?` ${Nt(p.note)}`:""))}return f}const g=[];for(const f of e.nodes)g.push(b(`h${n}`,{class:`${t}-list-group`},f.href?b("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},s(f.name)):s(f.name),d(f))),g.push(b("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(c=>b("li",null,s(c.name),c.key==="PK"?", primary key":c.key==="FK"?", foreign key":"",c.ref?[", references ",s(`${c.ref.table}.${c.ref.column}`),c.card?[" (",fn(f.id,c.ref.table,c.card,s),")"]:""]:c.type?`, ${c.type}`:"")),...f.more?[b("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return g}function Ie(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Zt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function re(t,e=!1){const n=e&&t.type!=="sequence"&&Zt(t)&&t.cols>1&&t.rows>1,o=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:be(t)},{keys:["Home","End"],words:"the ends"},...o,{keys:["Esc"],words:"clear"}]}var In=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Zt(t){return qt(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,..._n(t,r)})),n=(r,s)=>{const a=s==="right"||s==="left",l=s==="right"||s==="down",d=w=>a?[w.col,w.col]:w.rows,g=w=>a?w.rows:[w.col,w.col],f=d(r),c=g(r);let p=null;return e.forEach((w,h)=>{if(w===r)return;const u=d(w),M=g(w),C=l?u[0]-f[1]:f[0]-u[1];if(C<1)return;const H=Math.max(0,M[0]-c[1],c[0]-M[1]),v=[H===0?0:1,H===0?C:C+2*H,H,Math.abs(M[0]-c[0]),h];(!p||In(v,p.rank))&&(p={id:w.id,rank:v})}),p?.id??null},o=At();for(const r of e)o[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const s=new Set([r]),a=[r];for(;a.length;)for(const l of Object.values(o[a.pop()]))l&&!s.has(l)&&(s.add(l),a.push(l));return s.size};return e.every(r=>i(r.id)===e.length)?o:null})}function Jt(t){return qt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!ie(t))return{lane:e,dropped:n,lanes:0};const o=(l,d)=>(t.byId.get(l)?.row??0)*1e3+d,i=new Map;t.edges.forEach((l,d)=>{const g=`${l.to}.${l.toRow}`,f=o(l.from,l.fromRow??0),c=o(l.to,l.toRow??0),p=i.get(g)??{members:[],lo:1/0,hi:-1/0};p.members.push(d),p.lo=Math.min(p.lo,f,c),p.hi=Math.max(p.hi,f,c),i.set(g,p)});const r=[...i.values()].sort((l,d)=>d.hi-d.lo-(l.hi-l.lo)),s=[];let a=0;for(const l of r.reverse()){const d=new Set(s.filter(f=>f.lo<=l.hi&&l.lo<=f.hi).map(f=>f.lane));let g=0;for(;d.has(g);)g++;if(g>1){for(const f of l.members)n.add(f);continue}s.push({lo:l.lo,hi:l.hi,lane:g});for(const f of l.members)e.set(f,g);a=Math.max(a,g+1)}return{lane:e,dropped:n,lanes:a}})}var ie=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Xt(t,e,n){const o=n.prefix,i=gn(n.base),r=t.type==="sequence"||t.type==="schema"?null:ke(t),s={P:o,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},a=e.layout==="drawn",l=jt(t,e),d=t.type==="sequence"||t.type==="schema"?a:!0,g=`h${t.heading}`,f=[`--_cols:${se(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const c=t.type==="architecture"?we(t):[0,0,0,0],p=(h,u,M)=>h?h>1?`calc(${h} * var(--basalt-space-${u}))`:`var(--basalt-space-${u})`:M?`var(--basalt-space-${M})`:"0px",w=a&&e.pad?"3":void 0;f.push(`--_gpad:${p(c[0],"8",w)} ${p(c[1],"4")} ${p(c[2],"4",w)} ${p(c[3],"4")}`)}if(r?.gutter&&r.laneCount>2&&f.push(`--_gw:calc(${r.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),ie(t)){const c=t.marks?"var(--basalt-space-6) + var(--basalt-space-1)":"var(--basalt-space-5)";f.push(`--_gpad:0px ${Jt(t).lanes>1?`calc(${c} + var(--basalt-space-3))`:t.marks?`calc(${c})`:c} 0px 0px`)}return t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),b("figure",{class:n.className?`${o} ${n.className}`:o,"aria-labelledby":i.title,"data-type":t.type,"data-cols":se(t),"data-reach":t.type==="architecture"?xe(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-marks":t.marks?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:f.join(";")},b("div",{class:`${o}-head`},b(g,{id:i.title,class:`${o}-title`},t.title),n.hasSource?b("p",{class:`${o}-source`},{slot:"source"}):null),b("div",{class:`${o}-drawing`,style:a&&e.rows?`--_rows:${e.rows};--_row-gap:0px`:void 0,role:d?"group":void 0,"aria-roledescription":d?"diagram":void 0,"aria-labelledby":d?i.title:void 0,"aria-describedby":d?l?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":l?"":void 0},Mn(s,t,e),t.text?null:b("div",{class:`${o}-ink`,"aria-hidden":"true"}),b("span",{class:`${o}-ruler`,"aria-hidden":"true"})),Ee(o,t),b("p",{class:`${o}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),jt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?b("p",{class:`${o}-tap-hint`,"aria-hidden":"true"},`Tap ${be(t)} to highlight its lines. Tap it again to clear.`):null,b("div",{class:`${o}-foot`},{slot:"toggle"}),b("div",{id:i.list,class:`${o}-list`,hidden:!e.open},Le(o,t)),b("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${Ie(t,a)} ${n.viewer}`:Ie(t,a)),b("figcaption",{id:i.summary,class:`${o}-summary`},{slot:"summary"}))}function On(t){const e=getComputedStyle(t),n=(i,r)=>{const s=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(s)?s:r},o=new Map;return{space:i=>(o.has(i)||o.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),o.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ut=(t,e)=>t==="main"?e.line:e.hair,Et=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},Lt=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,_e=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function kt(t,e,n){const{l:o,t:i,r,b:s}=t.rect,a=(o+r)/2,l=(i+s)/2,d=(r-o)/2,g=(s-i)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const w=n,h=g*Math.max(0,1-Math.abs(w-a)/d);return{x:w,y:e==="top"?l-h:l+h}}const c=n,p=d*Math.max(0,1-Math.abs(c-l)/g);return{x:e==="left"?a-p:a+p,y:c}}if(t.shape==="terminal"){const c=Math.min(d,g);if(f){const u=n,M=Math.min(Math.max(u,o+c),r-c),C=u-M,H=Math.abs(C)>=c?0:Math.sqrt(c*c-C*C);return{x:u,y:Math.abs(C)<1e-6?e==="top"?i:s:e==="top"?l-H:l+H}}const p=n,w=p-l,h=Math.abs(w)>=c?0:Math.sqrt(c*c-w*w);return{x:e==="left"?o+c-h:r-c+h,y:p}}return f?{x:n,y:e==="top"?i:s}:{x:e==="left"?o:r,y:n}}function qn(t,e,n){const{l:o,t:i,r,b:s}=e.rect,a=(o+r)/2,l=(i+s)/2,d=(r-o)/2,g=(s-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/d+Math.abs(t.y-l)/g<1-n/Math.min(d,g);if(e.shape==="terminal"){const f=Math.min(d,g),c=Math.min(Math.max(t.x,o+f),r-f);return Math.hypot(t.x-c,t.y-l)o+n&&t.xi+n&&t.ymatchMedia("(forced-colors: active)").matches;function Bn(t,e){const n=t.querySelector(`.${e}-ruler`),o=new Map;return(i,r)=>{const s=`${r}|${i}`;return o.has(s)||(n.setAttribute("data-f",r),n.textContent=i,o.set(s,n.getBoundingClientRect().width),n.textContent=""),o.get(s)}}var Yt=t=>t?t.split(/\s+/).filter(Boolean):[];function Rn(t,e,n){const o=e.space;let i=e.node,r=e.table;for(const l of t.nodes){if(l.shape==="table"){for(const h of l.columns??[]){const u=h.ref?`${t.rtl?"←":"→"} ${h.ref.table}`:h.type??"",M=o("6")+n(h.name,"mono")+(u?o("3")+n(u,"mono"):0)+2*o("3")+2*e.hair;r=Math.max(r,Math.ceil(M))}r=Math.max(r,Math.ceil(n(l.name,"table")+2*o("3")+2*e.hair+(l.href?16+o("1-5"):0)));continue}const d=l.shape==="terminal"?2*o("5"):2*o("3"),g=l.mark&&!jn()?(l.shape==="participant"?2:1)*o("6"):0;let f=0;const c=l.href?16+o("1-5"):0,p=Yt(l.name);if(p.forEach((h,u)=>{f=Math.max(f,n(h,l.shape==="decision"?"name-500":"name")+(l.kind?0:g)+(u===p.length-1?c:0))}),t.type!=="data-flow")for(const h of Yt(l.kind))f=Math.max(f,n(h,"mono")+g);for(const h of Yt(l.detail))f=Math.max(f,n(h,l.mono?"mono":"sans"));const w=l.shape==="decision"?f/.62:f+d+2*e.hair;i=Math.max(i,Math.ceil(w))}const s=se(t);let a;return t.type==="data-flow"?a=e.lane+s*(i+o("12")):t.type==="schema"?a=s*r+(s-1)*(o("12")+(t.marks?o("3"):0))+(ie(t)?(t.marks?o("6")+o("1"):o("5"))+(Jt(t).lanes>1?o("3"):0):0):t.type==="sequence"?a=s*i+(s-1)*o("5"):a=s*i+(s-1)*o("16")+xe(t)*o("4"),{track:i,table:r,least:Math.max(e.wide,a)}}function qe(t,e){return{x:(n,o)=>o%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,o)=>o%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function le(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Ce(t,e,n){const o=t.map(r=>({...r}));for(let r=1;r=2){const l=i[i.length-2];if(Math.abs(l.x-a.x)<.01&&Math.abs(a.x-s.x)<.01||Math.abs(l.y-a.y)<.01&&Math.abs(a.y-s.y)<.01){i[i.length-1]=s;continue}}i.push(s)}}return i}var It=t=>t.slice(1).map((e,n)=>[t[n],e]);function Qt(t,e,n){const o=[];for(let r=0;rMath.min(h.x,u.x)+.75&&HMath.min(M.y,C.y)+.75&&vr.split(/\s+/).map(parseFloat).filter(s=>Number.isFinite(s)),o=(r,s,a)=>{const l=[];let d=s;for(const g of r)l.push([d,d+g]),d+=g+a;return l},i=o(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0);return{cols:o(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:t.style.getPropertyValue("--_rows").trim()?i.filter((r,s)=>s%2===1):i}}var ct=t=>t==="left"||t==="right",je={top:"bottom",bottom:"top",left:"right",right:"left"};function Be(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Re(t,e,n){const o=[];t.edges.forEach((r,s)=>{const a=t.byId.get(r.from),l=t.byId.get(r.to),[d,g]=e[s],f=a.row===l.row&&ct(d)&&ct(g)&&d===je[g]||a.col===l.col&&!ct(d)&&!ct(g)&&d===je[g];o.push({edge:s,end:"from",node:a,side:d,far:l,straight:f,f:.5},{edge:s,end:"to",node:l,side:g,far:a,straight:f,f:.5})});const i=new Map;for(const r of o){const s=`${r.node.id}.${r.side}`;i.has(s)||i.set(s,[]),i.get(s).push(r)}for(const[r,s]of i){if(s[0].node.shape==="decision")continue;const a=h=>ct(h.side)?h.far.row-h.node.row:h.far.col-h.node.col,l=s.filter(h=>h.straight),d=s.filter(h=>!h.straight);if(d.sort((h,u)=>a(h)-a(u)||(ct(h.side)?h.far.col-u.far.col:h.far.row-u.far.row)*(a(h)<0?1:-1)),s.length>3&&n(`${r.replace(".","'s ")} side has ${s.length} lines; more than three is an error: use another side`),!l.length){d.length===2?(d[0].f=.25,d[1].f=.75):d.length===3?(d[0].f=.25,d[1].f=.5,d[2].f=.75):d.length>3&&d.forEach((h,u)=>{h.f=(u+1)/(d.length+1)});continue}const g=new Map;for(const h of l)g.has(h.far.id)||g.set(h.far.id,[]),g.get(h.far.id).push(h);for(const h of g.values())h.length>1&&h.sort((u,M)=>u.edge-M.edge).forEach((u,M)=>{u.f=h.length===2?M===0?.25:.75:(M+1)/(h.length+1)});const f=Math.min(...l.map(h=>h.f)),c=Math.max(...l.map(h=>h.f)),p=d.filter(h=>a(h)<0),w=d.filter(h=>a(h)>=0);p.forEach((h,u)=>{h.f=f*(u+1)/(p.length+1)}),w.forEach((h,u)=>{h.f=c+(1-c)*(u+1)/(w.length+1)})}return o}function Te(t,e=8,n=8){return qt(t,`port-floors:${e}:${n}`,()=>{const o=At();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return o;const i=t.edges.map(s=>{const a=t.byId.get(s.from),l=t.byId.get(s.to),[d,g]=Be(a,l);return[s.fromSide??d,s.toSide??g]}),r=new Map;for(const s of Re(t,i,()=>{})){if(!ct(s.side)||s.node.shape!=="box")continue;const a=`${s.node.id}.${s.side}`;r.has(a)||r.set(a,[]),r.get(a).push(s.f)}for(const[s,a]of r){if(a.length<2)continue;const l=[...new Set(a.map(f=>Math.round(f*1e6)/1e6))].sort((f,c)=>f-c);let d=Math.max(e/l[0],e/(1-l[l.length-1]));for(let f=1;f{const s=t.byId.get(r.dataset.node);s&&i.set(s.id,{id:s.id,rect:Et(r,n),shape:s.shape,i:s.i})}),i}function We(t,e){const n=e.head,o=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-o,r:i+o,t:r-n,b:r}:t.dir==="up"?{l:i-o,r:i+o,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-o,b:r+o}:{l:i,r:i+n,t:r-o,b:r+o}}var Fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function He(t,e,n,o){const i=(r,s)=>{const a=r+s-Math.floor(r+s);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const r of i(t.t,n))for(const s of i(t.l,e)){if(!s&&!r)return t;const a={l:t.l+s,r:t.r+s,t:t.t+r,b:t.b+r};if(o(a))return a}return t}function zn(t,e,n,o,i,r,s,a,l){const d=s.space,g=[],f=[],c=[],p=[],w=d("1"),h=e.filter(u=>t.edges[u.i]?.label).sort((u,M)=>+(t.edges[M.i].kind==="main")-+(t.edges[u.i].kind==="main")||u.i-M.i);for(const u of h){const M=t.edges[u.i].label,C=a(M,"label"),H=16*ne(M),v=u.pts.length-2,E=[];It(u.pts).forEach(([_,D],j)=>{const x=Math.abs(_.y-D.y)<.01,R=x?_.x:_.y;let F=x?D.x:D.y;const Z=Math.sign(F-R)||1;j===v&&(F-=Z*s.head);let K=[[R,F]];for(const m of i)for(const y of x?[m.l,m.r]:[m.t,m.b]){const k=x?_.y:_.x;(x?k>m.t&&km.l&&ky>Math.min(I,B)+1&&y{const k=(m+y)/2,q=x?{x:k,y:_.y}:{x:_.x,y:k};return!i.some(I=>q.x>I.l&&q.xI.t&&q.y1&&rt(m,y)?1:0})}),E.sort((_,D)=>D.pri-_.pri||D.len-_.len);let T=null,tt=!1;const z=(_,D=!0)=>{const j=_e(_,w);return D&&(_.lr.r||_.tr.b)||n.some(x=>Oe(j,x))||g.some(x=>Lt(j,x))||o.heads.some(x=>Lt(j,x))||o.rects.some(x=>Lt(j,x))?!1:!e.some(x=>x.i!==u.i&&It(x.pts).some(([R,F])=>Lt(j,Fe(R,F,x.width))))};for(const _ of E){for(const D of[1/2,1/3,2/3]){const j=_.p+(_.q-_.p)*D,x=[],R=d("2")+u.width/2;if(_.horiz?(_.len>=C+2*d("1")+d("3-5")&&x.push({box:{l:j-C/2-d("1"),r:j+C/2+d("1"),t:_.c-H/2,b:_.c+H/2},on:!0}),x.push({box:{l:j-C/2,r:j+C/2,t:_.c-R-H,b:_.c-R},on:!1}),x.push({box:{l:j-C/2,r:j+C/2,t:_.c+R,b:_.c+R+H},on:!1})):(_.len>=H+d("3")&&x.push({box:{l:_.c-C/2-d("1"),r:_.c+C/2+d("1"),t:j-H/2,b:j+H/2},on:!0}),x.push({box:{l:_.c+R,r:_.c+R+C,t:j-H/2,b:j+H/2},on:!1}),x.push({box:{l:_.c-R-C,r:_.c-R,t:j-H/2,b:j+H/2},on:!1})),T=x.find(F=>z(F.box))??null,T)break;!tt&&x.some(F=>z(F.box,!1))&&(tt=!0)}if(T)break}if(!T){c.push(u.i),tt&&p.push(u.i);continue}const it=He(T.box,l.ox,l.oy,_=>z(_));g.push(it),f.push({i:u.i,text:M,box:it,on:T.on})}return{labels:f,unseated:c,bounded:p}}function De(t,e,n,o){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(s=>{if(s.getClientRects().length===0||getComputedStyle(s).display==="contents")return;const a=Et(s,e);r.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const l=s.querySelector(`:scope > .${n}-glabel`);l&&l.getClientRects().length&&i.push(Et(l,e))}),t.querySelectorAll(`.${n}-lane`).forEach((s,a)=>{if(!s.getClientRects().length)return;const l=Et(s,e);a>0&&i.push({l:l.l,r:l.r,t:l.t-o/2-.5,b:l.t-o/2+.5});const d=s.querySelector(`.${n}-lane-name`);d&&i.push(Et(d,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function Ge(t,e){const{m:o,tk:i,P:r,drawing:s,origin:a,warn:l}=t,d=i.space,g=Ne(o,s,a,r),f=[...g.values()],c=Tn(s),p=a.left-Math.floor(a.left),w=a.top-Math.floor(a.top),h=qe(p,w),u=s.clientWidth,M=s.clientHeight,C=$=>o.type==="data-flow"?$.col+1:$.col,H=parseFloat(getComputedStyle(s).rowGap)||0,v={w:u,h:M,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:p,oy:w};if(o.type==="sequence")return Wn(t,v,h);let E,T=[];o.type==="schema"?E=o.edges.map($=>{const A=o.byId.get($.from),L=o.byId.get($.to);if(A.col===L.col){const S=A.col===o.cols&&o.cols>1?"left":"right";return[S,S]}return L.col>A.col?["right","left"]:["left","right"]}):(E=o.edges.map($=>{const A=o.byId.get($.from),L=o.byId.get($.to),[S,O]=Be(A,L);return[$.fromSide??S,$.toSide??O]}),T=Re(o,E,l||(()=>{})));const tt=($,A)=>{const L=s.querySelector(`.${r}-node[data-node="${CSS.escape($)}"] .${r}-row[data-row="${A}"]`);if(!L)return 0;const S=Et(L,a);return(S.t+S.b)/2},z=new Map;if(o.type==="schema"){const $=new Map;o.edges.forEach((L,S)=>{const O=`${L.to}.${L.toRow}.${E[S][1]}`;$.set(O,[...$.get(O)??[],S])});const A=L=>{const S=o.edges[L].card?.to;return S==="one"?0:S==="zero-or-one"?1:2};for(const L of $.values()){const S=[...new Set(L.map(A))].sort((O,W)=>O-W);if(S.length>1)for(const O of L)z.set(O,(S.indexOf(A(O))-(S.length-1)/2)*d("2"))}}const it=$=>Math.round($+p)-p,_=o.edges.map(($,A)=>{const[L,S]=E[A],O=g.get($.from),W=g.get($.to),J=Ut($.kind,i);if($.fk){const X=tt($.from,$.fromRow),P=tt($.to,$.toRow)+(z.get(A)??0),yt=h.y(X,J),Bt=h.y(P,J),St=L==="right"?O.rect.r:O.rect.l,xt=S==="right"?W.rect.r:W.rect.l;return{p1:{x:$.card?it(St):St,y:yt},p2:{x:$.card?it(xt):xt,y:Bt},r1:X,r2:Math.abs(yt-Bt)<.01?X:P}}const Y=T.find(X=>X.edge===A&&X.end==="from").f,at=T.find(X=>X.edge===A&&X.end==="to").f;let et=ze(O,L,Y),Q=ze(W,S,at);const N=ct(L)?et.y:et.x;let V=ct(S)?Q.y:Q.x;return ct(L)?et={...et,y:h.y(et.y,J)}:et={...et,x:h.x(et.x,J)},ct(S)?Q={...Q,y:h.y(Q.y,J)}:Q={...Q,x:h.x(Q.x,J)},ct(L)&&ct(S)&&Math.abs(et.y-Q.y)<1.01&&(Q={...Q,y:et.y},V=N),!ct(L)&&!ct(S)&&Math.abs(et.x-Q.x)<1.01&&(Q={...Q,x:et.x},V=N),et=ct(L)?kt(O,L,et.y):kt(O,L,et.x),Q=ct(S)?kt(W,S,Q.y):kt(W,S,Q.x),{p1:et,p2:Q,r1:N,r2:V}}),D=new Set,j=($,A)=>{D.has($)||(D.add($),l?.(`${o.edges[$].from} to ${o.edges[$].to} ${A}, so its line is not drawn; its row still writes the target`))};for(const $ of Jt(o).dropped)j($,"would need a third lane of turn-backs");const x=new Map,R=At();o.type==="schema"&&o.edges.forEach(($,A)=>{const L=o.byId.get($.from),S=o.byId.get($.to);if(Math.abs(L.col-S.col)<2)return;const O=Math.min(L.col,S.col),W=Math.max(L.col,S.col),J=o.nodes.filter(P=>P.col>O&&P.colyt.row<=P&&yt.row2>=P+1)||at.push({key:`g${P}`,y:(Y[P-1][1]+Y[P][0])/2,inner:!0});at.push({key:"top",y:Y[0][0]-d("4"),inner:!1},{key:"bottom",y:Y[Y.length-1][1]+d("4"),inner:!1});const et=(_[A].r1+_[A].r2)/2,Q=t.pick?.[A]??at.slice().sort((P,yt)=>Math.abs(P.y-et)-Math.abs(yt.y-et)||Number(yt.inner)-Number(P.inner)||P.y-yt.y)[0].key;R[A]=Q;const N=E[A][0]==="right"?L.col:L.col-1,V=c.cols[N-1],X=c.cols[N];x.set(A,{corridor:Q,first:V&&X?{key:`c${N}`,span:[V[1],X[0]]}:null,y:0})});const F=new Map;for(const[$,A]of x){const L=o.edges[$],S=F.get(A.corridor)??[],O=S.find(W=>{const J=o.edges[W[0]];return J.to===L.to&&J.toRow===L.toRow&&E[W[0]][1]===E[$][1]&&Math.abs(_[W[0]].p2.y-_[$].p2.y)<.5});O?O.push($):S.length>=2?j($,"would need a third lane in its corridor"):S.push([$]),F.set(A.corridor,S)}for(const $ of[...x.keys()])D.has($)&&x.delete($);const Z=$=>{const A=o.edges[$[0]];return Math.abs(o.byId.get(A.from).col-o.byId.get(A.to).col)*1e4+Math.abs(_[$[0]].p1.x-_[$[0]].p2.x)},K=($,A,L)=>{const S=c.rows;if($==="top")return S[0][0]-d("4")-A*d("3");if($==="bottom")return S[S.length-1][1]+d("4")+A*d("3");const O=Number($.slice(1));return(S[O-1][1]+S[O][0])/2+(A-(L-1)/2)*d("3")},rt=($,A)=>A.forEach((L,S)=>L.forEach(O=>{x.get(O).y=K($,S,A.length)})),U=()=>{for(const[$,A]of F){const L=A.map(S=>S.filter(O=>x.has(O))).filter(S=>S.length);F.set($,L),rt($,$==="top"||$==="bottom"?L.slice().sort((S,O)=>Z(S)-Z(O)):L.slice().sort((S,O)=>Z(O)-Z(S)))}};U();const m=new Map,y=new Set,k=new Map,q=($,A,L,S,O)=>{m.has($)||m.set($,{span:A,vertical:L,members:new Map});const W=m.get($);W.members.has(S)||W.members.set(S,[]),W.members.get(S).push(O)},I=()=>{m.clear(),y.clear(),k.clear(),o.edges.forEach(($,A)=>{if(D.has(A))return;const L=x.get(A);L?.first&&q(L.first.key,L.first.span,!0,`far:${A}`,-(A+1));const[S,O]=E[A],{p1:W,p2:J}=_[A],Y=o.byId.get($.from),at=o.byId.get($.to);let et=null,Q=null,N=!1;if(S===O){if(ct(S)){const V=S==="right"?Math.max(C(Y),C(at)):Math.min(C(Y),C(at))-1,X=c.cols[V-1],P=c.cols[V];X&&P&&(et=`c${V}`,Q=[X[1],P[0]],N=!0)}else{const V=S==="bottom"?Math.max(Y.row2,at.row2):Math.min(Y.row,at.row)-1,X=c.rows[V-1],P=c.rows[V];X&&P&&(et=`r${V}`,Q=[X[1],P[0]],N=!1)}et&&y.add(A)}else if(ct(S)&&ct(O)&&(L||Math.abs(W.y-J.y)>.5)){const V=C(at),X=O==="left",P=c.cols[(X?V-1:V)-1],yt=c.cols[(X?V:V+1)-1];P&&yt&&(et=`c${X?V-1:V}`,Q=[P[1],yt[0]],N=!0)}else if(!ct(S)&&!ct(O)&&Math.abs(W.x-J.x)>.5){const X=O==="top"?at.row-1:at.row2,P=c.rows[X-1],yt=c.rows[X];P&&yt&&(et=`r${X}`,Q=[P[1],yt[0]],N=!1)}!et||!Q||(L&&k.set(A,Q),q(et,Q,N,`${$.to}.${O}.${Math.round(N?J.y:J.x)}`,A))})};I();const B=new Map,ot=$=>{const[A,L]=E[$],{p1:S,p2:O}=_[$],W=x.get($);if(W){const J=k.get($),Y=B.get(-($+1))??(W.first?(W.first.span[0]+W.first.span[1])/2:S.x),at=B.get($)??(J?(J[0]+J[1])/2:O.x);return[S,{x:Y,y:S.y},{x:Y,y:W.y},{x:at,y:W.y},{x:at,y:O.y},O]}if(ct(A)&&ct(L)){if(A===L){const Y=d(o.marks?"6":"4")+(o.type==="schema"&&o.cols===1?(Jt(o).lane.get($)??0)*d("3"):0),at=B.get($)??(A==="right"?Math.max(S.x,O.x)+Y:Math.min(S.x,O.x)-Y);return[S,{x:at,y:S.y},{x:at,y:O.y},O]}if(Math.abs(S.y-O.y)<=.5)return[S,{x:O.x,y:S.y}];const J=B.get($)??(S.x+O.x)/2;return[S,{x:J,y:S.y},{x:J,y:O.y},O]}if(!ct(A)&&!ct(L)){if(A===L){const Y=B.get($)??(A==="bottom"?Math.max(S.y,O.y)+d("4"):Math.min(S.y,O.y)-d("4"));return[S,{x:S.x,y:Y},{x:O.x,y:Y},O]}if(Math.abs(S.x-O.x)<=.5)return[S,{x:S.x,y:O.y}];const J=B.get($)??(S.y+O.y)/2;return[S,{x:S.x,y:J},{x:O.x,y:J},O]}return ct(A)?[S,{x:O.x,y:S.y},O]:[S,{x:S.x,y:O.y},O]},G=$=>{const A=o.edges[$],L=Ut(A.kind,i),S=ot($),O=Ce(S,L,h);let W;return S.length===O.length&&(W=It(S).map(([J,Y])=>Math.abs(J.y-Y.y)<.75?(J.y+Y.y)/2:(J.x+Y.x)/2),W[0]=_[$].r1,W.length>1&&(W[W.length-1]=_[$].r2)),{i:$,from:A.from,to:A.to,kind:A.kind,pts:O,tip:O[O.length-1],dir:le(O),dot:A.fk&&!A.card?O[0]:void 0,card:A.card,width:L,axes:W}},nt=()=>o.edges.flatMap(($,A)=>D.has(A)?[]:[G(A)]);let ft=null;const ut=$=>{ft??(ft=nt());const A=ft.map(L=>$.has(L.i)?G(L.i):L);return{lines:A,score:Nn(A,$)*1e5+Qt(A,void 0,$).length*1e3+de(A.filter(L=>$.has(L.i)),f,o).length}},st=($,A)=>{const L=$.flatMap(S=>{const O=S<0?-S-1:S,{p1:W,p2:J}=_[O],Y=x.get(O);return Y?S<0?[W.y,Y.y]:[Y.y,J.y]:A?[W.y,J.y]:[W.x,J.x]});return[Math.min(...L),Math.max(...L)]},ht=$=>$<0?-$-1:$,bt=$=>{const A=[...$.members.values()].map(S=>({members:S,run:st(S,$.vertical)})).sort((S,O)=>S.run[0]-O.run[0]),L=[];for(const S of A){const O=L[L.length-1];O&&O.some(W=>W.run[0]!(S.length===1&&S[0].members.every(O=>y.has(O))))},wt=$=>(A,L)=>$[A].run[0]<$[L].run[1]+d("8")&&$[L].run[0]<$[A].run[1]+d("8"),Mt=$=>{const A=wt($),L=[];return $.forEach((S,O)=>{let W=0;for(;L.some((J,Y)=>J===W&&A(O,Y));)W++;L.push(W)}),L},vt=$=>Math.max(0,...Mt($))+1;if(o.marks)for(let $=0;$3){A=W.map(J=>J.members.map(ht));break}if(!A)break;const L=O=>Math.max(...O),S=A.filter(O=>O.some(W=>x.has(W))).sort((O,W)=>L(W)-L(O))[0]??A.slice().sort((O,W)=>L(W)-L(O))[0];for(const O of S)j(O,"would need a fourth lane in a marked gutter"),x.delete(O);I()}const pt=($,A,L)=>{const S=$[1]-$[0];if(!o.marks)return $[0]+S/(L+1)*(A+1);const O=i.foot+i.radiusXs,W=L>1?Math.min(S/(L+1),(S-2*O)/(L-1)):0;return($[0]+$[1])/2+(A-(L-1)/2)*W};U();for(const[$,A]of F){if($==="top"||$==="bottom"||A.length<2)continue;const L=new Set(A.flat());let S=A,O=1/0;for(const W of ce(A.slice().sort((J,Y)=>Z(Y)-Z(J)))){rt($,W),ft=null;const J=ut(L);J.scoreat.members);if(o.marks){const at=vt(A),et=wt(A),Q=A.length,N=new Set(L.flat().map(ht)),V=St=>St.forEach((xt,Rt)=>L[Rt].forEach(_t=>B.set(_t,pt($.span,xt,at))));let X=Mt(A),P=1/0,yt=null;const Bt=[X];if(at**Q<=729)for(let St=0;StMath.floor(St/at**_t)%at);xt.every((Rt,_t)=>xt.every((Gt,te)=>te<=_t||Rt!==Gt||!et(_t,te)))&&Bt.push(xt)}for(const St of Bt){V(St);const xt=ut(N);xt.scoreQ.forEach(V=>B.set(V,pt($.span,N,S))));const et=ut(O);et.scoreat.forEach(Q=>B.set(Q,pt($.span,et,S)))),ft=Y}if(v.lines=nt(),o.marks&&(v.lines=v.lines.filter($=>{if(!$.card)return!0;const A=It($.pts),L=([O,W])=>Math.hypot(W.x-O.x,W.y-O.y),S=A.length===1?2*i.foot:i.foot+i.radiusXs-.5;return L(A[0])>=S&&L(A[A.length-1])>=S?!0:(j($.i,"has no room for its marks at an end"),!1)})),x.size){const $=new Set([...x.values()].map(L=>L.corridor)),A=[$.has("top")?"var(--basalt-space-8)":"0px"];for(let L=1;L<=o.rows;L++)A.push("auto",LWe($,i));const $t=zn(o,v.lines,f,lt,dt,{l:0,t:0,r:u,b:M},i,e,{ox:p,oy:w});return v.labels=$t.labels,v.unseated=$t.unseated,v.bounded=$t.bounded,v.overlaps=[...new Set(Ve(v.lines,null).flat())],v}function Nn(t,e){return Ve(t,e).length}function Ve(t,e){const n=[];for(let o=0;o=a)continue;const[u,M]=c?[l.x,d.x]:[l.y,d.y],[C,H]=c?[g.x,f.x]:[g.y,f.y];Math.min(Math.max(u,M),Math.max(C,H))-Math.max(Math.min(u,M),Math.min(C,H))>1&&n.push([r.i,s.i])}}return n}function*ce(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const l=a===r.pts.length-1?Math.max(r.width/2,o.head/2):r.width/2;return s.x-l<-.5||s.x+l>e+.5||s.y-l<-.5||s.y+l>n+.5})&&i.push(r.i);return i}function de(t,e,n){const o=[];for(const i of t){const r=It(i.pts);e.some(s=>r.some(([a,l])=>Cn(a,l,s)))&&o.push(i.i)}return o}function Wn(t,e,n){const{m:o,tk:i,P:r,drawing:s,origin:a}=t,l=i.space,d=new Map;s.querySelectorAll(`.${r}-node`).forEach(v=>d.set(v.dataset.node,Et(v,a)));const g=s.querySelector(`.${r}-steps`),f=g?Et(g,a).b:e.h,c=v=>{const E=d.get(v);return E?n.x((E.l+E.r)/2,i.hair):0};for(const v of o.nodes){const E=d.get(v.id);E&&e.lifelines.push({x:c(v.id),y1:E.b,y2:f})}const p=v=>d.get(v.id),w=new Map;s.querySelectorAll(`.${r}-msg`).forEach(v=>{const E=Et(v,a);w.set(Number(v.querySelector(`.${r}-num`)?.textContent??0),(E.t+E.b)/2)});const h=i.activation,u=h/2,M=v=>{const E=o.byId.get(v.who);if(!E)return null;const T=c(v.who),z=(E.i===o.nodes.length-1&&o.nodes.length>1?-1:1)*(o.rtl?-1:1),it=(v.depth-1)*l("1")*z,_=w.get(v.from)??0,D=w.get(v.to)??_,j=v.from===v.to;return{l:n.x(T-u+it,i.hair),r:n.x(T+u+it,i.hair),t:n.y(j?_-l("2")-l("1"):_,i.hair),b:n.y(j?_+l("2")+l("1"):D,i.hair)}},C=o.bars.map(v=>({bar:v,rect:M(v)})).filter(v=>v.rect);e.bars=C.map(v=>v.rect);const H=(v,E,T)=>C.filter(({bar:tt})=>tt.who===v&&tt.to>=E&&(T?tt.from<=E:tt.fromz.bar.depth-tt.bar.depth)[0]?.rect;return s.querySelectorAll(`.${r}-msg`).forEach(v=>{const E=v.dataset.from,T=v.dataset.to,tt=v.dataset.kind??"plain",z=Ut(tt,i),it=Et(v,a),_=n.y((it.t+it.b)/2,z),D=Number(v.querySelector(`.${r}-num`)?.textContent??0);let j=c(E),x=c(T),R;if(E===T){const y=v.dataset.self==="start"?-l("6"):l("6"),k=H(E,D,!0),q=k?y>0?k.r:k.l:j,I=n.y(_-l("2"),z),B=n.y(_+l("2"),z);R=[{x:q,y:I},{x:n.x(j+y,z),y:I},{x:n.x(j+y,z),y:B},{x:q,y:B}]}else{const y=x>j?1:-1,k=H(E,D,!1),q=H(T,D,!0);k&&(j=y>0?k.r:k.l),q&&(x=y>0?q.l:q.r),R=[{x:j,y:_},{x,y:_}]}e.lines.push({i:D,from:E,to:T,kind:tt,pts:R,tip:R[R.length-1],dir:le(R),width:z});const F=v.querySelector(`.${r}-said`),Z=v.querySelector(`.${r}-note`),K=o.byId.get(E),rt=o.byId.get(T);if(!K||!rt)return;const U=E===T?(()=>{const y=o.nodes[K.i+(v.dataset.self==="start"?-1:1)],k=y?c(y.id):v.dataset.self==="start"?0:e.w;return Math.abs(k-j)-l("6")-l("2-5")-l("2")})():Math.abs(x-j)-2*l("2");Math.max(F?F.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>U+.5&&e.unseated.push(D)}),s.querySelectorAll(`.${r}-fhead`).forEach(v=>{const E=v.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!E)return;[...v.children].reduce((tt,z)=>tt+z.getBoundingClientRect().width,0)+l("3")>E.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${v.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function Ze(t,e,n,o=At()){const{m:i,tk:r,P:s,drawing:a,origin:l}=t,d=r.space,g=Ne(i,a,l,s),f=[...g.values()],c=l.left-Math.floor(l.left),p=l.top-Math.floor(l.top),w=qe(c,p),h=a.clientWidth,u=a.clientHeight,M={w:h,h:u,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:p},C=At();if(i.type==="sequence"||i.type==="schema")return{geo:M,grow:C};const H=h-(parseFloat(getComputedStyle(a).paddingRight)||0),v=(x,R,F)=>{const Z=[x];for(let K=1;K<=(Ot(o,R)??0);K++)Z.push({...x,t:x.t+F*d("4")*K,b:x.b+F*d("4")*K});return Z},E=new Map;a.querySelectorAll(`.${s}-node`).forEach(x=>{const R=x.parentElement,F=Et(R,l),Z=getComputedStyle(R);E.set(x.dataset.node,F.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const T=i.nodes,tt=x=>g.get(T[x].id),z=[],it=x=>Ut(i.edges[x].kind,r);i.edges.forEach((x,R)=>{const F=n.routes[R],Z=g.get(x.from),K=g.get(x.to),rt=it(R);let U=[];const m=x.label,y=m?e(m,"label"):0,k=m?16*ne(m):16,q=d("4");if(F==="down"||F==="up"){const B=Math.max(Z.rect.l,K.rect.l),ot=Math.min(Z.rect.r,K.rect.r),G=i.edges.map((st,ht)=>({o:st,j:ht})).filter(({o:st,j:ht})=>(n.routes[ht]==="down"||n.routes[ht]==="up")&&(st.from===x.from&&st.to===x.to||st.from===x.to&&st.to===x.from)),nt=G.findIndex(st=>st.j===R),ft=G.length<2?.5:G.length===2?nt===0?.25:.75:(nt+1)/(G.length+1),ut=w.x(B+(ot-B)*ft,rt);if(U=F==="down"?[kt(Z,"bottom",ut),kt(K,"top",ut)]:[kt(Z,"top",ut),kt(K,"bottom",ut)],m){let st=Math.min(U[0].y,U[1].y),ht=Math.max(U[0].y,U[1].y);F==="down"?ht-=r.head:st+=r.head;const bt=[...a.querySelectorAll(`.${s}-group`)].map(pt=>Et(pt,l));let wt=[[st,ht]];for(const pt of bt)for(const lt of[pt.t,pt.b])wt=wt.flatMap(([dt,$t])=>lt>dt+1&<<$t-1?[[dt,lt],[lt,$t]]:[[dt,$t]]);const Mt=(pt,lt)=>bt.some(dt=>(pt+lt)/2>dt.t&&(pt+lt)/2dt.l&&ut1){const pt=wt.filter(([dt,$t])=>!Mt(dt,$t));[st,ht]=(pt.length?pt:wt).reduce((dt,$t)=>$t[1]-$t[0]>dt[1]-dt[0]?$t:dt)}const vt=[1/2,1/3,2/3].map(pt=>{const lt=st+(ht-st)*pt;return{l:ut-y/2-d("1"),r:ut+y/2+d("1"),t:lt-k/2,b:lt+k/2}});z.push({k:R,cands:vt,on:!0,card:F==="down"?x.to:x.from})}}else if(F==="trunk"||F==="rail"){const B=w.x(Math.max(Z.rect.l,F==="rail"?K.rect.l:Z.rect.l)+d(F==="trunk"?"8":"3"),rt),ot=kt(Z,"bottom",B);if(F==="rail"){if(U=[ot,kt(K,"top",B)],m){const G=K.rect.t-d("6");z.push({k:R,cands:v({l:B+d("2-5"),r:B+d("2-5")+y,t:G-k/2,b:G+k/2},x.to,-1),on:!1,card:x.to})}}else{const G=w.x(K.rect.l+d("6"),rt),nt=w.y(K.rect.t-q,rt);U=[ot,{x:B,y:nt},{x:G,y:nt},kt(K,"top",G)],m&&z.push({k:R,cands:v({l:G+d("2-5"),r:G+d("2-5")+y,t:nt-k/2,b:nt+k/2},x.to,-1),on:!1,card:x.to})}}else{const B=Math.min(E.get(x.from)??h,E.get(x.to)??h),ot=w.x(n.gutter?H+(n.lanes[R]+1)*d("3-5"):B-d("2-5"),rt),G=w.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[R],rt),nt=kt(Z,"right",G),ft=F==="end-down",ut=i.edges.map((lt,dt)=>({o:lt,j:dt})).filter(({o:lt,j:dt})=>n.routes[dt]===F&<.to===x.to).sort((lt,dt)=>n.lanes[dt.j]-n.lanes[lt.j]||lt.j-dt.j),st=Math.max(0,ut.findIndex(({j:lt})=>lt===R)),ht=K.rect.r-d("6")-st*d("3"),bt=K.rect.r-d("6")-(ut.length-1)*d("3"),wt=w.x(ht,rt),Mt=ft?K.rect.t-q-st*d("5"):K.rect.b+q+st*d("5"),vt=w.y(Mt,rt);U=[nt,{x:ot,y:nt.y},{x:ot,y:vt},{x:wt,y:vt},kt(K,ft?"top":"bottom",wt)];const pt=ft?x.to:T[K.i+1]?.id??x.to;m&&z.push({k:R,cands:v({l:bt-d("2-5")-y,r:bt-d("2-5"),t:Mt-k/2,b:Mt+k/2},pt,ft?-1:1),on:!1,card:pt})}const I=Ce(U,rt,w);M.lines.push({i:R,from:x.from,to:x.to,kind:x.kind,pts:I,tip:I[I.length-1],dir:le(I),width:rt})}),M.crossings=Qt(M.lines),M.through=de(M.lines,f,i),M.outside=Ke(M.lines,h,u,r);const{obstacles:_}=De(a,l,s,0);_.heads=M.lines.map(x=>We(x,r));const D=[],j={l:0,t:0,r:h,b:u};for(const x of z){const R=K=>{const rt=_e(K,d("1"));return K.lj.r+.5||K.tj.b+.5||f.some(U=>Oe(rt,U))||D.some(U=>Lt(rt,U))||_.heads.some(U=>Lt(rt,U))||_.rects.some(U=>Lt(rt,U))||M.lines.some(U=>U.i!==x.k&&It(U.pts).some(([m,y])=>Lt(rt,Fe(m,y,U.width))))},F=x.cands.find(K=>!R(K));F||(C[x.card]=(C[x.card]??0)+1,M.unseated.push(x.k));const Z=F?He(F,c,p,K=>!R(K)):x.cands[0];D.push(Z),M.labels.push({i:x.k,text:i.edges[x.k].label,box:Z,on:x.on})}return{geo:M,grow:C}}function Je(t,e,n=0){const o=s=>String(Math.round(s*100)/100);let i=`M${o(t[0].x)} ${o(t[0].y)}`;for(let s=1;s{const{crow:D,ring:j}=Se(tt,z.x,z.y,it,n.head,n.dot);return`${j?``:""}`};return`${T(e.card.from,v,Math.sign(E.x-v.x)||1,"from")}${T(e.card.to,e.tip,-r.x||1,"to")}`}const s=e.kind==="dashed",a=n.head,l=n.head/2,d=s?1:a-1,g=e.pts.map(v=>({...v})),f=g[g.length-1];f.x-=r.x*d,f.y-=r.y*d;const c=e.tip.x-r.x*a,p=e.tip.y-r.y*a,w=-r.y*l,h=r.x*l,u=v=>Math.round(v*100)/100,M=mt(e.kind),C=s?``:``,H=e.dot?``:"";return`${C}${H}`}function Xe(t,e,n,o){const i=new Map,r=new Map;for(const a of e.crossings)r.has(a.under)||r.set(a.under,[]),r.get(a.under).push(a);let s="";for(const[a,l]of r){const d=`${o}-cut-${a}`;i.set(a,d);const g=l.map(f=>{const c=e.lines[f.top],p=e.lines[f.under],w=c.width/2+n.cut,h=p.width/2+1;return f.underVertical?``:``}).join("");s+=`${g}`}return{defs:s,ids:i}}function Ue(t,e,n,o){const{defs:i,ids:r}=Xe(t,e,n,o),s=e.lifelines.map(g=>``).join("")+(e.bars??[]).map(g=>``).join(""),a=e.lines.map((g,f)=>Hn(t,g,n,r.get(f)??null,g.from===g.to?n.radiusXs:n.radius)).join(""),l=`${i?`${i}`:""}${s}${a}`,d=e.labels.map(g=>`1?' data-lines="2"':""} style="left:${Math.round(g.box.l*100)/100}px;top:${Math.round(g.box.t*100)/100}px;width:${Math.round((g.box.r-g.box.l)*100)/100}px">${g.text.split(` +`).map(mt).join("
")}
`).join("");return l+d}function fe(t,e,n,o,i,r,s,a){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const g=On(t),f=Bn(d,n),c=Rn(e,g,f);a?.(c.least);const p=t.clientWidth,w=(()=>{const _=document.activeElement;return _&&d.contains(_)&&_.dataset.node?_.dataset.node:void 0})(),h=_=>jt(e,_)?{..._,stop:_.stop&&e.byId.has(_.stop)?_.stop:e.nodes[0]?.id,keep:void 0}:{..._,stop:_.stop??e.nodes[0]?.id,keep:w&&_.layout!=="drawn"?w:void 0};let u=!1;const M=_=>{if(u=!1,e.type!=="flowchart")return _;r({..._,heights:void 0,words:void 0});const D=At(),j=At();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const R=x.querySelector(`.${n}-words`);if(!R)return;const F=x.getBoundingClientRect(),Z=U=>{const m={w:U.width+2*g.space("2-5"),h:U.height+2*g.space("2")},y=1-m.w/F.width,k=y>.05?m.h/2/y:m.h*10;return Math.max(g.space("16"),Math.ceil(F.width/5),Math.ceil(2*k))},K=R.getBoundingClientRect();let rt=Z(K);if(rt>F.width){const U=q=>(x.style.setProperty("--_ww",`${q}px`),R.getBoundingClientRect()),m=Math.floor(x.clientWidth-2*g.space("2-5"));let y=Math.ceil(K.width),k=K.height;for(;y1;){const G=q+I>>1;U(G).heightF.width&&(u=!0)}),{..._,heights:D,words:Object.keys(j).length?j:void 0}},C=()=>({m:e,tk:g,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:s}),H=i.autoOpen?{open:!1,autoOpen:void 0}:{},v=(_,D)=>D.map(j=>Dt(e,_.lines.find(x=>x.i===j))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:g,least:c.least};if(p>=c.least&&!e.unplaced){const _=R=>{let F=h({...i,...H,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:R||void 0,rows:void 0});F=M(F),r(F);let Z=Ge(C(),f);return Z.corridors&&(F={...F,rows:Z.corridors.rows},r(F),Z=Ge({...C(),pick:Z.corridors.pick},f)),{dd:F,g:Z}};let{dd:D,g:j}=_(!1);const x=R=>R.through.length>0||R.outside.length>0||(R.overlaps?.length??0)>0||(R.misfit?.length??0)>0||u;if(!x(j)&&j.unseated.length&&j.unseated.every(R=>j.bounded?.includes(R))){const R=_(!0);!x(R.g)&&!R.g.unseated.length&&({dd:D,g:j}=R)}if(!x(j)&&!j.unseated.length)return j.crossings.length&&s?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the drawn layout: ${j.crossings.map(R=>`${Dt(e,j.lines[R.top])} over ${Dt(e,j.lines[R.under])}`).join("; ")}`),{dyn:D,geo:j,ink:Ue(n,j,g,o),tokens:g,least:c.least};u&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: a decision would be taller than it is wide`),j.misfit?.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: ${j.misfit.join("; ")}`),j.through.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: ${v(j,j.through)} would pass through a node`),j.overlaps?.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: ${v(j,j.overlaps)} would lie on one another`),j.outside.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: ${v(j,j.outside)} would leave the drawing`),j.unseated.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: no clean seat for ${j.unseated.map(R=>e.type==="sequence"?`message ${R}`:`"${e.edges[R]?.label}"`).join(", ")}`)}let E=h({...i,...H,layout:"stacked",heights:void 0,grow:At(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0,rows:void 0});if(E=M(E),r(E),e.type==="sequence"||e.type==="schema")return{dyn:E,geo:null,ink:"",tokens:g,least:c.least};const T=ke(e);let tt=Ze(C(),f,T,E.grow);for(let _=0;_<6&&Object.keys(tt.grow).length;_++){const D=At(E.grow);for(const[j,x]of Object.entries(tt.grow))D[j]=(Ot(D,j)??0)+x;E={...E,grow:D},r(E),tt=Ze(C(),f,T,D)}const z=tt.geo;if(!T.third&&T.laneCount>2&&s?.(`the stacked drawing uses ${T.laneCount} end lanes (four at most)`),z.unseated.length>0||z.through.length>0||z.outside.length>0||T.third){z.unseated.length&&s?.(`the stacked drawing has no clean seat for ${[...new Set(z.unseated)].map(j=>`"${e.edges[j]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),z.through.length&&s?.(`in the stacked drawing ${v(z,z.through)} would pass through a node, so its lines are not drawn`),z.outside.length&&s?.(`in the stacked drawing ${v(z,z.outside)} would leave the drawing, so its lines are not drawn`),T.third&&s?.("the stacked drawing would need a fifth end lane, so its lines are not drawn");const _={...z,lines:[],labels:[],crossings:[]};return{dyn:h({...E,grow:At(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:_,ink:"",tokens:g,least:c.least}}return z.crossings.length&&s?.(`${z.crossings.length} crossing${z.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${z.crossings.map(_=>`${Dt(e,z.lines[_.top])} over ${Dt(e,z.lines[_.under])}`).join("; ")}`),{dyn:E,geo:z,ink:Ue(n,z,g,o),tokens:g,least:c.least}}function Dt(t,e){const n=t.byId.get(e.from)?.name??e.from,o=t.byId.get(e.to)?.name??e.to;return`${n} to ${o}`}function Dn(t,e,n,o,i,r){const s=new Set;if(r){s.add(r);for(const h of n?.lines??[])h.from===r&&s.add(h.to),h.to===r&&s.add(h.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(h=>h.toggleAttribute("data-near",s.has(h.dataset.node))),!n||!o)return;const a=h=>!!r&&(h.from===r||h.to===r),l=t.querySelector(`.${e}-edges`),d=new Map;t.querySelectorAll(`.${e}-edge`).forEach(h=>d.set(h.getAttribute("data-edge"),h));for(const h of n.lines){const u=d.get(String(h.i));u&&(u.toggleAttribute("data-lit",a(h)),u.toggleAttribute("data-dim",!!r&&!a(h)))}if(t.querySelectorAll(`.${e}-label`).forEach(h=>{const u=n.lines.find(M=>String(M.i)===h.dataset.edge);h.toggleAttribute("data-lit",!!(u&&a(u)))}),l){for(const h of n.lines)if(a(h)){const u=d.get(String(h.i));u&&l.appendChild(u)}}const g=Qt(n.lines,a),{defs:f,ids:c}=Xe(e,{...n,crossings:g},o,i),p=t.querySelector(`.${e}-svg`);if(!p)return;let w=p.querySelector("defs");!w&&f&&(w=document.createElementNS("http://www.w3.org/2000/svg","defs"),p.insertBefore(w,p.firstChild)),w&&(w.innerHTML=f),n.lines.forEach((h,u)=>{const M=d.get(String(h.i))?.querySelector(`.${e}-line`);if(!M)return;const C=c.get(u);C?M.setAttribute("mask",`url(#${C})`):M.removeAttribute("mask")})}var Gn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Vn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Gn()||Zn(t)?"done":"pending")}}var Kn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Zn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Kn(t))!==null}catch{return!1}}function Ye(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Jn(t,e,n,o=!1,i=!1){const r=o?Zt(t):null;if(r&&n.startsWith("Arrow")){const d={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return d?r[e]?.[d]??null:null}const s=t.byId.get(e)?.i??0,a=t.nodes.length;let l;if(n==="ArrowRight"||n==="ArrowDown")l=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")l=s-1;else if(n==="Home")l=0;else if(n==="End")l=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,l))].id}var Xn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Qe=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],Un=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad","--_gw","--_mh","--_rows","--_row-gap"],Pe=t=>t==null||t===!1;function Yn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Pt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const o=n?Qe:Xn;for(const s of o)Pe(e.a[s])&&t.removeAttribute(s);for(const[s,a]of Object.entries(e.a)){if(s==="class")continue;if(s==="style"){const d=t.style,g=new Map(String(a??"").split(";").map(f=>{const c=f.indexOf(":");return[f.slice(0,c).trim(),f.slice(c+1).trim()]}).filter(([f])=>f));for(const[f,c]of g)d.getPropertyValue(f).trim()!==c&&d.setProperty(f,c);for(const f of Un)g.has(f)||d.removeProperty(f);continue}if(n&&!Qe.includes(s))continue;if(Pe(a)){t.removeAttribute(s);continue}const l=a===!0?"":String(a);t.getAttribute(s)!==l&&t.setAttribute(s,l)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(s=>typeof s!="string"&&"slot"in s))return;const i=[...t.children];let r=0;for(const s of e.c)if(!(typeof s=="string"||"slot"in s)){for(let a=r;at.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(o)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",o=0;function i(c,p,w){return{prefix:n,base:c,hasSource:p.source!==void 0&&p.source!==null&&p.source!=="",hiddenClass:"visually-hidden",viewer:w?w.keys:void 0}}function r(c,p,w,h){var u=function(M){return''+mt(M)+""};return{source:mt(String(p.source||"")),summary:mt(String(p.summary||"")),hint:re(c).map(function(M){return""+M.keys.map(u).join(" ")+" "+mt(M.words)+""}).join(""),toggle:'"}}function s(c,p,w){var h=zt(c),u=Xt(h,{},i(p,c,w)),M=oe(u,r(h,c,p,!1)),C=M.indexOf(">");return{open:M.slice(0,C+1),inner:M.slice(C+1,M.length-9),warnings:h.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-marks","data-layout","data-measured","data-bare"],l=["--_cols","--_gpad","--_track"];function d(c,p,w,h){c.__diagram&&c.__diagram.stop();var u=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),M=getComputedStyle(c).direction==="rtl",C=p.layout==="auto"&&(p.type==="architecture"||p.type==="flowchart"||p.type==="schema"),H=C?Array.isArray(p.placement)?p.placement:p.placement?[p.placement]:[]:[];C&&!H.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var v=p.direction?[p.direction]:p.type==="flowchart"?["down","right"]:["right","down"],E=function(N){for(var V=0;V .diagram-drawing")){if(!u||!c.querySelector("#"+CSS.escape(u+"-title"))){for(;document.getElementById("dg"+ ++o+"-title"););u="dg"+o}var tt=s(p,u,h),z=document.createElement("div");z.innerHTML=tt.open+"";var it=z.firstChild;a.forEach(function(N){c.removeAttribute(N)}),l.forEach(function(N){c.style.removeProperty(N)});for(var _=0;_ :not(script[data-diagram])").forEach(function(N){N.remove()}),c.insertAdjacentHTML("beforeend",tt.inner)}T.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var j=i(u,p,h),x={},R=null,F=null,Z=null,K=null,rt=Object.create(null),U=function(N){rt[N]||(rt[N]=1,console.warn("Basalt diagram: "+N))},m=function(N){Pt(c,Xt(T,N,j))},y=c.querySelector(".diagram-ink"),k=c.querySelector(".diagram-toggle"),q=!h&&T.motion.animated&&typeof e.diagramMotion=="function",I=null,B=null,ot=function(){q&&Ye(c)};function G(){Dn(c,n,R&&R.geo,R&&R.tokens,u,F||K||Z),ut()}var nt=null,ft=!h&&matchMedia("(hover: none), (pointer: coarse)").matches;function ut(){var N=ft&&!h&&y&&y.innerHTML!=="";if(c.toggleAttribute("data-touch",!!(ft&&!h)),N&&!nt){var V=c.querySelector(":scope > .diagram-foot");if(!V)return;nt=document.createElement("button"),nt.type="button",nt.className="btn diagram-clear",nt.setAttribute("data-variant","secondary"),nt.setAttribute("data-size","sm"),nt.innerHTML="Clear highlight",nt.addEventListener("click",function(){K&&(K=null,G())}),V.appendChild(nt)}else!N&&nt&&(nt.remove(),nt=null);nt&&(K?nt.removeAttribute("aria-disabled"):nt.setAttribute("aria-disabled","true"))}function st(N){if(!N.defaultPrevented){var V=un(c,n,N,K);V!==void 0&&(ot(),ft=!0,K=V,G())}}function ht(){k&&(k.setAttribute("aria-expanded",String(!!x.open)),k.firstElementChild.textContent=x.open?"Hide the list":"View as list")}function bt(){if(C&&H.length>1&&!h){for(var N=null,V=0;V1&&h&&!p.direction&&h.room){for(var Bt=h.room(),St=-1,xt=null,Rt=0;RtSt+1e-6&&(St=tn,xt=Gt)}}}xt&&(T=xt)}R=(h?h.measure:fe)(c,T,n,u,x,m,U),x=R.dyn,m(x),ht();var ue=c.querySelector(":scope > .diagram-hint");if(ue){var en=re(T,x.layout==="drawn").map(function(Wt){return""+Wt.keys.map(function(Pn){return''+mt(Pn)+""}).join(" ")+" "+mt(Wt.words)+""}).join("");ue.innerHTML!==en&&(ue.innerHTML=en)}jt(T,x)||(Z=K=null);var nn=y&&R.ink!==B;nn&&(y.innerHTML=R.ink,B=R.ink),G(),q&&R.tokens&&(Vn(c,!!(R.geo&&R.geo.lines.length)),nn&&I&&I.redrawn()),h&&h.onMeasured&&R.tokens&&h.onMeasured(R,c),T.text&&typeof e.diagramText=="function"&&e.diagramText(c,T,p)}function wt(N){x=N,m(x)}function Mt(N){var V=x.stop;x=Object.assign({},x,{stop:N}),Qn(c,n,V,N)}var vt=function(N){var V=N&&N.closest?N.closest(".diagram-node"):null;return V&&c.contains(V)?V:null};function pt(N){var V=vt(N.target);if(!(!V||N.defaultPrevented)){if(ot(),N.key==="Escape"){!h&&(F||Z||K)&&(N.preventDefault(),F=Z=K=null,G());return}if(jt(T,x)){var X=Jn(T,V.getAttribute("data-node"),N.key,x.layout==="drawn");if(X){N.preventDefault(),Mt(X);var P=c.querySelector('.diagram-node[data-node="'+CSS.escape(X)+'"]');P&&P.focus()}}}}function lt(N){var V=vt(N.target);if(V){ot();var X=V.getAttribute("data-node");F=V.matches(":focus-visible")?X:null,jt(T,x)&&x.stop!==X&&Mt(X),G()}}function dt(N){var V=vt(N.target);V&&(vt(N.relatedTarget)||(F=null),x.keep===V.getAttribute("data-node")&&wt(Object.assign({},x,{keep:void 0})),G())}function $t(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var V=vt(N.target);V&&ot();var X=V&&jt(T,x)?V.getAttribute("data-node"):null;X!==Z&&(Z=X,G())}}function $(){Z&&(Z=null,G())}function A(){ot(),wt(Object.assign({},x,{open:!x.open,autoOpen:void 0})),ht()}c.addEventListener("keydown",pt),c.addEventListener("focusin",lt),c.addEventListener("focusout",dt),c.addEventListener("pointerover",$t),c.addEventListener("pointerleave",$),c.addEventListener("click",st),k&&k.addEventListener("click",A),bt();var L=c.clientWidth,S=0,O=!0,W=new ResizeObserver(function(){Math.abs(c.clientWidth-L)<.5||(L=c.clientWidth,cancelAnimationFrame(S),S=requestAnimationFrame(bt))});W.observe(c),document.fonts&&document.fonts.ready.then(function(){O&&bt()});var J=matchMedia("(forced-colors: active)"),Y=T.nodes.some(function(N){return N.mark});Y&&J.addEventListener("change",bt),q&&(I=e.diagramMotion(c,{fig:c,P:n,base:u,model:function(){return T},geo:function(){return R&&R.geo},tokens:function(){return R&&R.tokens}},p));var at=!h&&p.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,p,{model:T,settle:ot,animated:q}):null,et=c.querySelector(":scope > .diagram-foot"),Q=!h&&p.export===!0&&et&&typeof e.diagramExport=="function"?e.diagramExport(et,c):[];c.__diagram={stop:function(){at&&at.destroy(),Q.forEach(function(N){N.remove()}),O=!1,W.disconnect(),cancelAnimationFrame(S),Y&&J.removeEventListener("change",bt),I&&I.destroy(),c.removeEventListener("keydown",pt),c.removeEventListener("focusin",lt),c.removeEventListener("focusout",dt),c.removeEventListener("pointerover",$t),c.removeEventListener("pointerleave",$),c.removeEventListener("click",st),nt&&nt.remove(),k&&k.removeEventListener("click",A)},layout:bt,key:g(p),send:I&&I.sendValue?I.sendValue:null}}function g(c){try{return JSON.stringify(c,function(p,w){return p==="packet"&&w&&typeof w=="object"?Object.assign({},w,{send:void 0}):w})}catch{return null}}function f(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var p=c.querySelector(":scope > script[data-diagram]");if(p)try{d(c,JSON.parse(p.textContent),!0)}catch(w){console.error("Basalt diagram: this figure could not be drawn",w)}}})}e.diagramMarkup=s,e.diagramKit={draw:d,buildModel:zt,figureKey:bn,figureList:An,hintEntries:re,toHtml:oe,escapeHtml:mt,settleEntrance:Ye,measureFigure:fe},t.diagram=function(c,p){var w=c.__diagram,h=w&&w.send?g(p):null;if(h!==null&&h===w.key){w.send(p.packet?p.packet.send:void 0);return}d(c,p)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/usage/diagram.md b/.agent/skills/basalt-html/parts/usage/diagram.md index e50d6a93..de16bf0b 100644 --- a/.agent/skills/basalt-html/parts/usage/diagram.md +++ b/.agent/skills/basalt-html/parts/usage/diagram.md @@ -16,7 +16,7 @@ Boxes and the lines between them. `compose.mjs` writes the figure's words into the page (it reads before script); the script draws the lines, the labels, the keys and "View as list". `Basalt.diagram(figure, spec)` draws one from script. -- **Five shapes of data** (`type`): `architecture` (`nodes` with `group`, `groups`, `edges`); `flowchart` (`nodes` with `shape`: `step`, `decision` or `terminal`, the first node the start; `edges`, a branch's `label` its condition); `data-flow` (`lanes`, `nodes` with `lane` and `col`, its step columns; `edges`); `sequence` (`participants` with `short`; `steps`: `{ from, to, label, note, kind }` or `{ band }`); `schema` (`tables`: `name`, `col`, `row` or `[first, last]`, `columns` with `key` `PK`/`FK` and `references: "table.column"`, `more`). +- **Five shapes of data** (`type`): `architecture` (`nodes` with `group`, `groups`, `edges`); `flowchart` (`nodes` with `shape`: `step`, `decision` or `terminal`, the first node the start; `edges`, a branch's `label` its condition); `data-flow` (`lanes`, `nodes` with `lane` and `col`, its step columns; `edges`); `sequence` (`participants` with `short`; `steps`: `{ from, to, label, note, kind }` or `{ band }`); `schema` (`tables`: `name`, `col`, `row` or `[first, last]`, `columns` with `key` `PK`/`FK` and `references: "table.column"`, `more`; `cardinality: { "from", "to" }` on every foreign key or none draws crow's feet: `from` is `one`, `zero-or-one`, `one-or-many` or `zero-or-many`, `to` is `one` or `zero-or-one`). - **Order is one thing:** the array's order is the stacked order, the focus order, the list's, a data flow's step numbers and a sequence's message numbers. - **Place, don't route:** `col` and `row` are whole tracks from 1. Sides, slots, jogs, lanes, the group's box and a foreign key's line are derived. Write `fromSide` or `toSide` (`top`, `right`, `bottom`, `left`) only to change the default. `branch: true` indents a node in the stacked drawing. - **Lines:** `kind` is `main` (2px), `plain` (default) or `dashed` (a reply, a stream). One `label` each, at most 28 characters. `legend` gives each kind its words; `main`, `dashed` and a `focal` node must have words. One node at most is `focal`. diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 33b34ddd..9183b9b6 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -94,7 +94,10 @@ export type SequenceStep = SequenceMessage | { band: string } | { frame: "alt"; branches: Array<{ label: string; steps: SequenceStep[] }> }; /** The words the key and the list say for each frame operator, and for an alt's later branches. */ export interface DiagramFrameLabels { opt?: string; loop?: string; alt?: string; else?: string } -export interface SchemaColumn { name: string; type?: string; key?: "PK" | "FK"; references?: string } +/** How many rows each end of a foreign key allows (DECISIONS 306, 1.1): `from` is the column's own table, `to` the referenced one, which is one row at most. */ +export type DiagramCardinality = "one" | "zero-or-one" | "one-or-many" | "zero-or-many"; +export interface DiagramCardinalityPair { from: DiagramCardinality; to?: "one" | "zero-or-one" } +export interface SchemaColumn { name: string; type?: string; key?: "PK" | "FK"; references?: string; cardinality?: DiagramCardinalityPair } export interface SchemaTable { name: string; col: number; row: number | [number, number]; focal?: boolean; more?: number; columns: SchemaColumn[]; href?: string; target?: "_blank" } export interface DiagramShapeLabels { terminal?: string; step?: string; decision?: string } @@ -142,7 +145,7 @@ export interface DiagramPlacement { direction: "right" | "down"; cells: Record = { one: "Exactly one", "zero-or-one": "Zero or one", "one-or-many": "One or many", "zero-or-many": "Zero or many" }; const HEADINGS = [2, 3, 4, 5, 6]; /** Text from the author's data: always a string (or nothing), so a value that is not one can never be read as markup. */ @@ -426,8 +436,20 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model // Schema: a foreign key is one record, `references` on the column; its line, its row's words, the sentence and the list all come from it. if (type === "schema") { + const cardOf = (v: unknown, where: string): MEdge["card"] => { + if (v === undefined || v === null) return undefined; + const o = v as { from?: unknown; to?: unknown }; + const from = CARDS.includes(o.from as DiagramCardinality) ? (o.from as DiagramCardinality) : undefined; + if (!from) { dev && warn(`${where}'s cardinality "from" is ${JSON.stringify(o.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`); return undefined; } + if (o.to === undefined || o.to === null) return { from, to: "one" }; + if (o.to === "one" || o.to === "zero-or-one") return { from, to: o.to }; + // A foreign key points at one row at most. + dev && warn(`${where}'s cardinality "to" is ${JSON.stringify(o.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`); + return { from, to: "one" }; + }; (spec.tables ?? []).forEach((t) => (t.columns ?? []).forEach((c, k) => { const ref = txt(c.references); + if (!ref && c.cardinality !== undefined && c.cardinality !== null) dev && warn(`${String(t.name)}.${String(c.name)} states a cardinality but references nothing`); if (!ref) return; const [table, column] = ref.split("."); const target = byId.get(table ?? ""); @@ -435,8 +457,13 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model if (!target || row < 0) { dev && warn(`${String(t.name)}.${String(c.name)} references ${ref}, which is not a shown column`); return; } const source = byId.get(String(t.name ?? ""))!; source.columns![k]!.ref = { table: table!, column: column!, row }; - edges.push({ i: edges.length, from: source.id, to: table!, kind: "plain", fromRow: k, toRow: row, fk: true }); + const card = cardOf(c.cardinality, `${String(t.name)}.${String(c.name)}`); + if (card) source.columns![k]!.card = card; + edges.push({ i: edges.length, from: source.id, to: table!, kind: "plain", fromRow: k, toRow: row, fk: true, card }); })); + // All of a figure's foreign keys state how many, or none (1.1). In production an unstated line draws as today, and the key shows both. + const stated = edges.filter((e) => e.card).length; + if (stated && stated < edges.length) dev && warn(`cardinality is stated on ${stated} of ${edges.length} foreign keys: state it on every one or none (${edges.filter((e) => !e.card).map((e) => `${e.from}.${byId.get(e.from)!.columns![e.fromRow!]!.name}`).join(", ")} ${edges.length - stated === 1 ? "has" : "have"} none)`); } else if (type !== "sequence") { for (const e of spec.edges ?? []) { const from = String(e.from ?? ""), to = String(e.to ?? ""); @@ -535,7 +562,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model cols = Math.max(1, ...nodes.map((n) => n.col)); } const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, ...nodes.map((n) => n.row2)); - const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined, text: (type === "sequence" && spec.variant === "text") || undefined }; + const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined, text: (type === "sequence" && spec.variant === "text") || undefined, marks: edges.some((e) => e.card) || undefined }; if (spec.layout === "auto" && !unplaced && type !== "schema") chooseSides(model); if (checks) for (const [id, h0] of Object.entries(portFloors(model))) if (h0 >= 48) warn(`${id} grows to ${h0}px to hold the lines on one side: use another side`); if (checks && nodes.length > 1 && !spatialTable(model)) warn("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"); @@ -629,8 +656,9 @@ function writeSentence(m: Model, n: MNode): string { const parts: string[] = []; if (m.type === "schema") { parts.push(`${n.name}, table.`); - const refs = (n.columns ?? []).filter((c) => c.ref).map((c) => `${c.ref!.table} (${c.name})`); - const by = m.edges.filter((e) => e.to === n.id).map((e) => `${e.from} (${m.byId.get(e.from)!.columns![e.fromRow!]!.name})`); + // A stated cardinality adds its clause (1.1): "users (decided_by: zero or many approvals to zero or one users)". + const refs = (n.columns ?? []).filter((c) => c.ref).map((c) => `${c.ref!.table} (${c.name}${c.card ? `: ${cardClause(n.id, c.ref!.table, c.card)}` : ""})`); + const by = m.edges.filter((e) => e.to === n.id).map((e) => `${e.from} (${m.byId.get(e.from)!.columns![e.fromRow!]!.name}${e.card ? `: ${cardClause(e.from, e.to, e.card)}` : ""})`); if (refs.length) parts.push(`References ${refs.join(", ")}.`); if (by.length) parts.push(`Referenced by ${by.join(", ")}.`); } else if (m.type === "sequence") { @@ -655,6 +683,11 @@ function writeSentence(m: Model, n: MNode): string { return parts.join(" "); } +/** A foreign key's cardinality in words (1.1): "zero or many approvals to zero or one users". Table names are written as given. */ +/** The same clause in the list, its table names as code. */ +const cardClauseCode = (from: string, to: string, card: { from: DiagramCardinality; to: DiagramCardinality }, code: (s: string) => VElement): VChild[] => [`${CARD_WORDS[card.from].toLowerCase()} `, code(from), ` to ${CARD_WORDS[card.to].toLowerCase()} `, code(to)]; +const cardClause = (from: string, to: string, card: { from: DiagramCardinality; to: DiagramCardinality }) => `${CARD_WORDS[card.from].toLowerCase()} ${from} to ${CARD_WORDS[card.to].toLowerCase()} ${to}`; + /** A participant's working stretches in words (1.2): " Working during messages 6 to 12." (and "message 3" for one). */ function working(m: Model, n: MNode): string { const bars = m.bars.filter((b) => b.who === n.id && b.depth === 1); @@ -747,6 +780,8 @@ export interface Dyn { art?: boolean; /** The drawn layout keeps space-3 above its first row and below its last, so a label beside a line in a 40px row has a seat (1.8). */ pad?: boolean; + /** A schema's rows with its corridors (DECISIONS 306, 1.1): a grid-template-rows of spacer tracks round the author's rows, set only where a far key is drawn. */ + rows?: string; } export interface TreeIds { base: string } @@ -910,6 +945,31 @@ function lineSwatch(P: string, kind: DiagramLineKind | "fk"): VElement { ? h("path", { class: `${P}-tip`, "data-kind": k, "data-open": "", d: `M${end - 8} ${y - 4}L${end} ${y}L${end - 8} ${y + 4}` }) : h("path", { class: `${P}-tip`, "data-kind": k, d: `M${end} ${y}L${end - 8} ${y - 4}L${end - 8} ${y + 4}Z` })); } +/** A cardinality swatch (1.1): a 24px line carrying the form, its table's edge at the end. */ +function cardSwatch(P: string, form: DiagramCardinality): VElement { + const { crow, ring } = cardMarks(form, 24, 8.5, -1); + return h("svg", { class: `${P}-swatch`, "data-card": form, ...svgA(24, 16) }, + h("path", { class: `${P}-line`, "data-kind": "plain", d: "M0 8.5H24" }), + h("path", { class: `${P}-crow`, d: crow }), + ring ? h("circle", { class: `${P}-ring`, cx: ring.x, cy: ring.y, r: ring.r }) : null); +} + +/** + * A form's marks at one end of a line (1.1), Information Engineering's, from the table's edge `edge` along the line at `y`, `out` the way away from + * the table (+1 or -1). Each bar is a 1px tick size-diagram-head across, its ink the pixel that ends at its distance; a foot is three spokes from a + * point at 7.5 to the edge, space-1 either side of the line; a ring is size-dot across its stroke's middle, centred at 10.5, so its ink runs 7 to 14. + */ +export function cardMarks(form: DiagramCardinality, edge: number, y: number, out: number, head = 8, dot = 6): { crow: string; ring?: { x: number; y: number; r: number } } { + const r2 = (n: number) => String(Math.round(n * 100) / 100); + const at = (d: number) => edge + out * d; + const half = head / 2; + const bar = (d: number) => `M${r2(at(d - 0.5))} ${r2(y - half)}V${r2(y + half)}`; + const many = form === "one-or-many" || form === "zero-or-many"; + const zero = form === "zero-or-one" || form === "zero-or-many"; + let crow = many ? `M${r2(edge)} ${r2(y - half)}L${r2(at(7.5))} ${r2(y)}L${r2(edge)} ${r2(y + half)}` : bar(4); + if (!zero) crow += bar(many ? 11 : 8); + return { crow, ring: zero ? { x: Math.round(at(10.5) * 100) / 100, y, r: dot / 2 } : undefined }; +} function boxSwatch(P: string, shape: "box" | "terminal" | "decision" | "focal" | "group"): VElement { if (shape === "decision") return h("svg", { class: `${P}-swatch`, "data-shape": shape, ...svgA(16, 16) }, h("path", { class: `${P}-swatch-shape`, d: "M8 2.5L14.5 8L8 13.5L1.5 8Z" })); if (shape === "terminal") return h("svg", { class: `${P}-swatch`, "data-shape": shape, ...svgA(16, 16) }, h("rect", { class: `${P}-swatch-shape`, x: 0.5, y: 3.5, width: 15, height: 9, rx: 4.5 })); @@ -946,8 +1006,11 @@ function buildKey(P: string, m: Model): VElement | null { if (kinds.has(k) && words) entry(m.text ? glyph(k === "main" ? "━━▶" : k === "dashed" ? "┄┄▷" : "──▶", k === "main" ? "main" : "plain") : lineSwatch(P, k), words, { "data-line": m.text ? undefined : "" }); } if (m.type === "schema" && m.edges.length) { - // The foreign-key line where it is drawn; where it is not, the row says it, and so does the key. - entry(lineSwatch(P, "fk"), m.legend.plain ?? "A foreign key, to the key it references", { "data-line": "", "data-when": "drawn" }); + // The foreign-key line where it is drawn; where it is not, the row says it, and so does the key. A schema that states how many shows each form + // drawn in its place (1.1), built in because the forms are notation; an unstated line (production, a figure that states some) keeps its entry. + if (m.edges.some((e) => !e.card)) entry(lineSwatch(P, "fk"), m.legend.plain ?? "A foreign key, to the key it references", { "data-line": "", "data-when": "drawn" }); + const forms = new Set(m.edges.flatMap((e) => (e.card ? [e.card.from, e.card.to] : []))); + for (const f of CARDS) if (forms.has(f)) entry(cardSwatch(P, f), CARD_WORDS[f], { "data-line": "", "data-when": "drawn", "data-card": f }); entries.push(h("li", { class: `${P}-entry`, "data-when": "stacked" }, h("span", { class: `${P}-fk-mark`, "aria-hidden": "true" }, m.rtl ? "←" : "→"), h("span", null, "The table a foreign key references"))); } if (m.type === "sequence") { @@ -1014,7 +1077,9 @@ function nodeTree(ctx: TreeContext, m: Model, n: MNode, dyn: Dyn): VElement { const { P } = ctx; const images = nodesAreImages(m, dyn) || dyn.keep === n.id; const stops = hasStops(m, dyn); - const style: string[] = [`--_c:${n.col}`, `--_r:${n.row}`, `--_r2:${n.row2 + 1}`]; + // Where a schema's corridors are spacer tracks (1.1), the author's row r is track 2r. + const spaced = dyn.layout === "drawn" && dyn.rows; + const style: string[] = [`--_c:${n.col}`, `--_r:${spaced ? 2 * n.row : n.row}`, `--_r2:${spaced ? 2 * n.row2 + 1 : n.row2 + 1}`]; if (m.type === "data-flow") style.push(`--_lc:${n.col + 1}`); if (m.type === "sequence") style.push(`--_c2:${n.col + 1}`); const plan = ctx.plan; @@ -1245,7 +1310,7 @@ function buildList(P: string, m: Model): VNode[] { // A table's name is a sub-heading one level under the title's, as "Parts" and "Connections" are. out.push(h(`h${sub}`, { class: `${P}-list-group` }, n.href ? h("a", { href: n.href, target: n.blank ? "_blank" : undefined, rel: n.blank ? "noopener noreferrer" : undefined }, code(n.name)) : code(n.name), focal(n))); out.push(h("ul", { class: `${P}-list-items` }, [ - ...(n.columns ?? []).map((c) => h("li", null, code(c.name), c.key === "PK" ? ", primary key" : c.key === "FK" ? ", foreign key" : "", c.ref ? [", references ", code(`${c.ref.table}.${c.ref.column}`)] : c.type ? `, ${c.type}` : "")), + ...(n.columns ?? []).map((c) => h("li", null, code(c.name), c.key === "PK" ? ", primary key" : c.key === "FK" ? ", foreign key" : "", c.ref ? [", references ", code(`${c.ref.table}.${c.ref.column}`), c.card ? [" (", cardClauseCode(n.id, c.ref.table, c.card, code), ")"] : ""] : c.type ? `, ${c.type}` : "")), ...(n.more ? [h("li", null, `and ${n.more} more ${n.more === 1 ? "column" : "columns"}`)] : []), ])); } @@ -1385,7 +1450,11 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { // Two lanes of turn-backs take space-3 more (call 2). // The end gutter grows by lanes (1.3): lanes × space-3-5 + space-3 (40, 54, 68). if (plan?.gutter && plan.laneCount > 2) style.push(`--_gw:calc(${plan.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`); - if (oneColumnTurnBacks(m)) style.push(`--_gpad:0px ${turnBackLanes(m).lanes > 1 ? "calc(var(--basalt-space-5) + var(--basalt-space-3))" : "var(--basalt-space-5)"} 0px 0px`); + if (oneColumnTurnBacks(m)) { + // Where marks are drawn the first lane is space-6 out, so the padding is space-6 plus space-1 (1.1). + const first = m.marks ? "var(--basalt-space-6) + var(--basalt-space-1)" : "var(--basalt-space-5)"; + style.push(`--_gpad:0px ${turnBackLanes(m).lanes > 1 ? `calc(${first} + var(--basalt-space-3))` : m.marks ? `calc(${first})` : first} 0px 0px`); + } if (m.type === "schema" && dyn.track) style.push(`--_track:${dyn.track}px`); return h("figure", { class: o.className ? `${P} ${o.className}` : P, @@ -1394,6 +1463,7 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { "data-cols": columnCount(m), "data-reach": m.type === "architecture" ? groupReach(m) : undefined, "data-gutter": plan?.gutter ? "" : undefined, + "data-marks": m.marks ? "" : undefined, "data-layout": dyn.layout, "data-measured": dyn.layout ? "" : undefined, "data-bare": dyn.bare ? "" : undefined, @@ -1406,6 +1476,8 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { h("div", { class: `${P}-head` }, h(Head, { id: ids.title, class: `${P}-title` }, m.title), o.hasSource ? h("p", { class: `${P}-source` }, { slot: "source" }) : null), h("div", { class: `${P}-drawing`, + // A schema's far keys run in corridors (1.1): its rows are spacer tracks round the author's, and the grid's own row gap is none. + style: drawn && dyn.rows ? `--_rows:${dyn.rows};--_row-gap:0px` : undefined, role: group ? "group" : undefined, "aria-roledescription": group ? "diagram" : undefined, "aria-labelledby": group ? ids.title : undefined, @@ -1445,6 +1517,8 @@ export interface GLine { dir: Dir; /** A foreign key's dot, on the row it leaves. */ dot?: Pt; + /** A foreign key's stated cardinality (1.1): marks at both ends in place of the dot and the head. */ + card?: { from: DiagramCardinality; to: DiagramCardinality }; width: number; /** Each run's place across its axis before it was snapped (a run out of a decision is on the diamond's own centre line), by segment: labels * are seated against these, so a seat never turns on which way a half pixel fell. */ @@ -1476,6 +1550,8 @@ export interface Geo { /** The offset of the drawing's origin from the device pixel grid, so lines can be snapped to it. */ ox: number; oy: number; + /** A schema's far keys (1.1): the rows their corridors need, and each far line's corridor, chosen once on the grid without them. */ + corridors?: { rows: string; pick: Record }; } export interface Tokens { @@ -1620,7 +1696,8 @@ function minimums(m: Model, tk: Tokens, measure: ReturnType) { const n = columnCount(m); let least: number; if (m.type === "data-flow") least = tk.lane + n * (track + s("12")); - else if (m.type === "schema") least = n * table + (n - 1) * s("12") + (oneColumnTurnBacks(m) ? s("5") + (turnBackLanes(m).lanes > 1 ? s("3") : 0) : 0); + // Where marks are drawn the gap is space-12 plus space-3, and a one-column schema's first turn-back is space-6 out (1.1). + else if (m.type === "schema") least = n * table + (n - 1) * (s("12") + (m.marks ? s("3") : 0)) + (oneColumnTurnBacks(m) ? (m.marks ? s("6") + s("1") : s("5")) + (turnBackLanes(m).lanes > 1 ? s("3") : 0) : 0); // A sequence's columns hold its participants: measured once script runs (the stylesheet before script has only the token floor). else if (m.type === "sequence") least = n * track + (n - 1) * s("5"); else least = n * track + (n - 1) * s("16") + groupReach(m) * s("4"); @@ -1698,9 +1775,11 @@ function readGrid(drawing: HTMLElement): Grid { const cs = getComputedStyle(drawing); const list = (v: string) => v.split(/\s+/).map(parseFloat).filter((x) => Number.isFinite(x)); const tracks = (sizes: number[], start: number, gap: number) => { const out: Array<[number, number]> = []; let x = start; for (const s of sizes) { out.push([x, x + s]); x += s + gap; } return out; }; + const rows = tracks(list(cs.gridTemplateRows), parseFloat(cs.paddingTop) || 0, parseFloat(cs.rowGap) || 0); return { cols: tracks(list(cs.gridTemplateColumns), parseFloat(cs.paddingLeft) || 0, parseFloat(cs.columnGap) || 0), - rows: tracks(list(cs.gridTemplateRows), parseFloat(cs.paddingTop) || 0, parseFloat(cs.rowGap) || 0), + // A schema's corridors (1.1) are spacer tracks round the author's rows: its rows are every other track. + rows: drawing.style.getPropertyValue("--_rows").trim() ? rows.filter((_, j) => j % 2 === 1) : rows, }; } @@ -1796,7 +1875,7 @@ function portPoint(n: GNode, side: DiagramSide, f: number): Pt { return isH(side) ? contour(n, side, t + (b - t) * f) : contour(n, side, l + (r - l) * f); } -interface DrawnInput { m: Model; tk: Tokens; P: string; drawing: HTMLElement; origin: DOMRect; warn?: (s: string) => void } +interface DrawnInput { m: Model; tk: Tokens; P: string; drawing: HTMLElement; origin: DOMRect; warn?: (s: string) => void; pick?: Record } function gNodes(m: Model, drawing: HTMLElement, origin: DOMRect, P: string): Map { const out = new Map(); @@ -1966,15 +2045,30 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge const r = rectOf(el, origin); return (r.t + r.b) / 2; }; + // One key, two statements (1.1): lines that state different things at one key arrive space-2 apart, centred on the row, each in its own lane; + // lines that state the same thing share a bus. + const arrivals = new Map(); + if (m.type === "schema") { + const at = new Map(); + m.edges.forEach((e, k) => { const key = `${e.to}.${e.toRow}.${sides[k]![1]}`; at.set(key, [...(at.get(key) ?? []), k]); }); + const rank = (k: number) => { const t = m.edges[k]!.card?.to; return t === "one" ? 0 : t === "zero-or-one" ? 1 : 2; }; + for (const list of at.values()) { + const says = [...new Set(list.map(rank))].sort((x, y) => x - y); + if (says.length > 1) for (const k of list) arrivals.set(k, (says.indexOf(rank(k)) - (says.length - 1) / 2) * s("2")); + } + } + // A marked line's ends are on whole pixels of the table's edge, so its marks are measured from it (1.1). + const whole = (x: number) => Math.round(x + ox) - ox; // Each end's place across the axis it leaves or enters on, before it is snapped (`r1`, `r2`): what its label is seated against. const ends = m.edges.map((e, k) => { const [s1, s2] = sides[k]!; const a = map.get(e.from)!, b = map.get(e.to)!; const w = strokeOf(e.kind, tk); if (e.fk) { - const r1 = rowY(e.from, e.fromRow!), r2 = rowY(e.to, e.toRow!); + const r1 = rowY(e.from, e.fromRow!), r2 = rowY(e.to, e.toRow!) + (arrivals.get(k) ?? 0); const y1 = sn.y(r1, w), y2 = sn.y(r2, w); - return { p1: { x: s1 === "right" ? a.rect.r : a.rect.l, y: y1 }, p2: { x: s2 === "right" ? b.rect.r : b.rect.l, y: y2 }, r1, r2: Math.abs(y1 - y2) < 0.01 ? r1 : r2 }; + const x1 = s1 === "right" ? a.rect.r : a.rect.l, x2 = s2 === "right" ? b.rect.r : b.rect.l; + return { p1: { x: e.card ? whole(x1) : x1, y: y1 }, p2: { x: e.card ? whole(x2) : x2, y: y2 }, r1, r2: Math.abs(y1 - y2) < 0.01 ? r1 : r2 }; } const f1 = ports.find((p) => p.edge === k && p.end === "from")!.f, f2 = ports.find((p) => p.edge === k && p.end === "to")!.f; let p1 = portPoint(a, s1, f1), p2 = portPoint(b, s2, f2); @@ -1990,18 +2084,86 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge p2 = isH(s2) ? contour(b, s2, p2.y) : contour(b, s2, p2.x); return { p1, p2, r1, r2 }; }); - // Relations two columns apart are not drawn: the row writes its target (1.12). They are left out before any lane is given, so they take none. const dropped = new Set(); - if (m.type === "schema") m.edges.forEach((e, k) => { if (Math.abs(m.byId.get(e.from)!.col - m.byId.get(e.to)!.col) > 1) dropped.add(k); }); - // A one-column schema's third lane of turn-backs is not drawn; its row still writes the target (call 2). - for (const k of turnBackLanes(m).dropped) { dropped.add(k); if (dev) warn?.(`${m.edges[k]!.from} to ${m.edges[k]!.to} would need a third lane of turn-backs, so its line is not drawn; its row still writes the target`); } + // A line that is not drawn: its row still writes the target, and a development build names it. One tight line never stacks the figure. + const drop = (k: number, why: string) => { if (dropped.has(k)) return; dropped.add(k); if (dev) warn?.(`${m.edges[k]!.from} to ${m.edges[k]!.to} ${why}, so its line is not drawn; its row still writes the target`); }; + // A one-column schema's third lane of turn-backs is not drawn (call 2). + for (const k of turnBackLanes(m).dropped) drop(k, "would need a third lane of turn-backs"); + + // Foreign keys two or more columns away (1.1): out of the row's facing side, a turn in the gutter beside its own table, a run along a corridor (a + // row gap no table of the columns between stands in, or the margin above or below), a turn in the gutter beside the referenced table into the key. + const far = new Map(); + const pick: Record = record(); + if (m.type === "schema") m.edges.forEach((e, k) => { + const a = m.byId.get(e.from)!, b = m.byId.get(e.to)!; + if (Math.abs(a.col - b.col) < 2) return; + const lo = Math.min(a.col, b.col), hi = Math.max(a.col, b.col); + const between = m.nodes.filter((n) => n.col > lo && n.col < hi); + const rows = grid.rows; + if (!rows.length) return; + // Each corridor's height: an interior gap's middle; a margin's first lane, space-4 out. + const cands: Array<{ key: string; y: number; inner: boolean }> = []; + for (let g = 1; g < rows.length; g++) if (!between.some((n) => n.row <= g && n.row2 >= g + 1)) cands.push({ key: `g${g}`, y: (rows[g - 1]![1] + rows[g]![0]) / 2, inner: true }); + cands.push({ key: "top", y: rows[0]![0] - s("4"), inner: false }, { key: "bottom", y: rows[rows.length - 1]![1] + s("4"), inner: false }); + // The one nearest the middle of the two rows' heights; an interior gap wins a tie with a margin, then the upper. Chosen once, on the grid + // without corridors (the second measure, with them, keeps it). + const mid = (ends[k]!.r1 + ends[k]!.r2) / 2; + const chosen = input.pick?.[k] ?? cands.slice().sort((p, q) => Math.abs(p.y - mid) - Math.abs(q.y - mid) || Number(q.inner) - Number(p.inner) || p.y - q.y)[0]!.key; + pick[k] = chosen; + const ti = sides[k]![0] === "right" ? a.col : a.col - 1; + const t1 = grid.cols[ti - 1], t2 = grid.cols[ti]; + far.set(k, { corridor: chosen, first: t1 && t2 ? { key: `c${ti}`, span: [t1[1], t2[0]] } : null, y: 0 }); + }); + // A corridor's lanes (1.1): two at most, space-3 apart, lines to one key sharing one; a third line is not drawn, the later in the author's order. + // An interior gap's lanes are centred in it (space-3-5 clear of the tables in its space-10); a margin's are space-4 and space-4 plus space-3 out. + const corridorGroups = new Map(); + for (const [k, f] of far) { + const e = m.edges[k]!; + const groups = corridorGroups.get(f.corridor) ?? []; + const bus = groups.find((g) => { const o = m.edges[g[0]!]!; return o.to === e.to && o.toRow === e.toRow && sides[g[0]!]![1] === sides[k]![1] && Math.abs(ends[g[0]!]!.p2.y - ends[k]!.p2.y) < 0.5; }); + if (bus) bus.push(k); + else if (groups.length >= 2) drop(k, "would need a third lane in its corridor"); + else groups.push([k]); + corridorGroups.set(f.corridor, groups); + } + for (const k of [...far.keys()]) if (dropped.has(k)) far.delete(k); + // How far a line goes: its columns, then its run across. + const reach = (g: number[]) => { const e = m.edges[g[0]!]!; return Math.abs(m.byId.get(e.from)!.col - m.byId.get(e.to)!.col) * 1e4 + Math.abs(ends[g[0]!]!.p1.x - ends[g[0]!]!.p2.x); }; + const corridorY = (key: string, j: number, count: number) => { + const rows = grid.rows; + if (key === "top") return rows[0]![0] - s("4") - j * s("3"); + if (key === "bottom") return rows[rows.length - 1]![1] + s("4") + j * s("3"); + const g = Number(key.slice(1)); + return (rows[g - 1]![1] + rows[g]![0]) / 2 + (j - (count - 1) / 2) * s("3"); + }; + // A margin's lanes nest by the merged rule: the farther-going outermost. An interior gap's take the order that crosses least (below). + const setCorridor = (key: string, order: number[][]) => order.forEach((g, j) => g.forEach((k) => { far.get(k)!.y = corridorY(key, j, order.length); })); + const nestCorridors = () => { + for (const [key, groups] of corridorGroups) { + const live = groups.map((g) => g.filter((k) => far.has(k))).filter((g) => g.length); + corridorGroups.set(key, live); + setCorridor(key, key === "top" || key === "bottom" ? live.slice().sort((p, q) => reach(p) - reach(q)) : live.slice().sort((p, q) => reach(q) - reach(p))); + } + }; + nestCorridors(); // Jogs: which gutter each two-elbow line turns in, and which lines share a lane (lines to one port, a foreign key's bus). A turn-back (out and // back in on one side) runs in the gutter beside that side too, so it is given a lane with the jogs it runs beside. const jogs = new Map }>(); const turnBacks = new Set(); - m.edges.forEach((e, k) => { + // A far line's last gutter (its bus's), by edge. + const farLast = new Map(); + const join = (key: string, span: [number, number], vertical: boolean, port: string, id: number) => { + if (!jogs.has(key)) jogs.set(key, { span, vertical, members: new Map() }); + const g = jogs.get(key)!; + if (!g.members.has(port)) g.members.set(port, []); + g.members.get(port)!.push(id); + }; + const gather = () => { jogs.clear(); turnBacks.clear(); farLast.clear(); m.edges.forEach((e, k) => { if (dropped.has(k)) return; + // A far line turns in two gutters: its own (a lane of its own, keyed by -(k + 1)) and the referenced table's, where it joins the key's bus. + const f = far.get(k); + if (f?.first) join(f.first.key, f.first.span, true, `far:${k}`, -(k + 1)); const [s1, s2] = sides[k]!; const { p1, p2 } = ends[k]!; const a = m.byId.get(e.from)!, b = m.byId.get(e.to)!; @@ -2017,7 +2179,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge if (r1 && r2) { key = `r${ri}`; span = [r1[1], r2[0]]; vertical = false; } } if (key) turnBacks.add(k); - } else if (isH(s1) && isH(s2) && Math.abs(p1.y - p2.y) > 0.5) { + } else if (isH(s1) && isH(s2) && (f || Math.abs(p1.y - p2.y) > 0.5)) { const ti = trackOf(b); const leftSide = s2 === "left"; const t1 = grid.cols[(leftSide ? ti - 1 : ti) - 1], t2 = grid.cols[(leftSide ? ti : ti + 1) - 1]; @@ -2030,21 +2192,27 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge if (r1 && r2) { key = `r${ri}`; span = [r1[1], r2[0]]; vertical = false; } } if (!key || !span) return; - if (!jogs.has(key)) jogs.set(key, { span, vertical, members: new Map() }); - const port = `${e.to}.${s2}.${Math.round(vertical ? p2.y : p2.x)}`; - const g = jogs.get(key)!; - if (!g.members.has(port)) g.members.set(port, []); - g.members.get(port)!.push(k); - }); + if (f) farLast.set(k, span); + join(key, span, vertical, `${e.to}.${s2}.${Math.round(vertical ? p2.y : p2.x)}`, k); + }); }; + gather(); const lanes = new Map(); const route = (k: number): Pt[] => { const [s1, s2] = sides[k]!; const { p1, p2 } = ends[k]!; + const f = far.get(k); + if (f) { + // Out to its own gutter's lane, along its corridor, into the referenced table's gutter (the bus there) and the key. + const last = farLast.get(k); + const x1 = lanes.get(-(k + 1)) ?? (f.first ? (f.first.span[0] + f.first.span[1]) / 2 : p1.x); + const x2 = lanes.get(k) ?? (last ? (last[0] + last[1]) / 2 : p2.x); + return [p1, { x: x1, y: p1.y }, { x: x1, y: f.y }, { x: x2, y: f.y }, { x: x2, y: p2.y }, p2]; + } if (isH(s1) && isH(s2)) { if (s1 === s2) { - // A one-column schema's turn-back takes its lane: space-4 out, the second space-3 further (call 2). - const out = s("4") + (m.type === "schema" && m.cols === 1 ? (turnBackLanes(m).lane.get(k) ?? 0) * s("3") : 0); + // A one-column schema's turn-back takes its lane: space-4 out, the second space-3 further (call 2); space-6 out where marks are drawn (1.1). + const out = s(m.marks ? "6" : "4") + (m.type === "schema" && m.cols === 1 ? (turnBackLanes(m).lane.get(k) ?? 0) * s("3") : 0); const x = lanes.get(k) ?? (s1 === "right" ? Math.max(p1.x, p2.x) + out : Math.min(p1.x, p2.x) - out); return [p1, { x, y: p1.y }, { x, y: p2.y }, p2]; } @@ -2073,7 +2241,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge axes[0] = ends[k]!.r1; if (axes.length > 1) axes[axes.length - 1] = ends[k]!.r2; } - return { i: k, from: e.from, to: e.to, kind: e.kind, pts, tip: pts[pts.length - 1]!, dir: finish(pts), dot: e.fk ? pts[0] : undefined, width: w, axes }; + return { i: k, from: e.from, to: e.to, kind: e.kind, pts, tip: pts[pts.length - 1]!, dir: finish(pts), dot: e.fk && !e.card ? pts[0] : undefined, card: e.card, width: w, axes }; }; const build = (): GLine[] => m.edges.flatMap((_, k) => (dropped.has(k) ? [] : [buildOne(k)])); // A gutter's lanes are scored by the lines in it alone: their crossings with every line, and the nodes they pass through. The other @@ -2087,11 +2255,19 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge }; // Each gutter: its lanes evenly spaced (at least space-3 apart), in the order that crosses least. // Lanes are needed only where jogs run beside each other: jogs whose runs along the gutter do not overlap each take its middle. + // A member's run along its gutter: a line's from end to end; a far line's from its row to its corridor (its own gutter) or on to its key. const runOf = (members: number[], vertical: boolean): [number, number] => { - const ys = members.flatMap((k) => { const { p1, p2 } = ends[k]!; return vertical ? [p1.y, p2.y] : [p1.x, p2.x]; }); + const ys = members.flatMap((id) => { + const k = id < 0 ? -id - 1 : id; + const { p1, p2 } = ends[k]!; + const f = far.get(k); + if (f) return id < 0 ? [p1.y, f.y] : [f.y, p2.y]; + return vertical ? [p1.y, p2.y] : [p1.x, p2.x]; + }); return [Math.min(...ys), Math.max(...ys)]; }; - for (const [, g] of jogs) { + const edgeOf = (id: number) => (id < 0 ? -id - 1 : id); + const clustersOf = (g: { span: [number, number]; vertical: boolean; members: Map }) => { const ports = [...g.members.values()].map((members) => ({ members, run: runOf(members, g.vertical) })).sort((a, b) => a.run[0] - b.run[0]); const clusters: Array = []; for (const p of ports) { @@ -2099,26 +2275,111 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge // Two jogs share the middle only when a clear space-8 parts them; closer, they would read as one line. if (last && last.some((q) => q.run[0] < p.run[1] + s("8") && p.run[0] < q.run[1] + s("8"))) last.push(p); else clusters.push([p]); } - for (const cluster of clusters) { - // A turn-back alone keeps its own place, space-4 out from the side; beside a jog or another turn-back, they share the gutter's lanes. - if (cluster.length === 1 && cluster[0]!.members.every((k) => turnBacks.has(k))) continue; + // A turn-back alone keeps its own place, space-4 out from the side (space-6 where marks are drawn); beside a jog or another turn-back, they share the gutter's lanes. + return clusters.filter((cluster) => !(cluster.length === 1 && cluster[0]!.members.every((k) => turnBacks.has(k)))); + }; + // A marked gutter's lanes are counted by what runs beside what (1.1): a line needs a lane apart only from the lines its run is beside (closer than + // space-8, the merged rule for sharing the middle), so the lanes a cluster needs are the most runs beside each other at one height. Each run takes the first lane + // free of the runs beside it, in the order the runs start: as few lanes as the most beside one another. + type Cluster = ReturnType[number]; + const besideIn = (cluster: Cluster) => (i: number, j: number) => cluster[i]!.run[0] < cluster[j]!.run[1] + s("8") && cluster[j]!.run[0] < cluster[i]!.run[1] + s("8"); + const firstFit = (cluster: Cluster) => { + const beside = besideIn(cluster); + const slot: number[] = []; + cluster.forEach((_, i) => { let l = 0; while (slot.some((x, j) => x === l && beside(i, j))) l++; slot.push(l); }); + return slot; + }; + const needOf = (cluster: Cluster) => Math.max(0, ...firstFit(cluster)) + 1; + // A marked gutter (1.1) holds three lanes at most: a line that would need a fourth is not drawn, a far line first and then the later in the + // author's order (its lane and its bus go with it). + if (m.marks) for (let guard = 0; guard < m.edges.length; guard++) { + let over: number[][] | null = null; + for (const [, g] of jogs) for (const cluster of clustersOf(g)) if (needOf(cluster) > 3) { over = cluster.map((c) => c.members.map(edgeOf)); break; } + if (!over) break; + const latest = (group: number[]) => Math.max(...group); + const victim = over.filter((group) => group.some((k) => far.has(k))).sort((p, q) => latest(q) - latest(p))[0] ?? over.slice().sort((p, q) => latest(q) - latest(p))[0]!; + for (const k of victim) { drop(k, "would need a fourth lane in a marked gutter"); far.delete(k); } + gather(); + } + // Lanes in a marked gutter (1.1): none nearer a table than the zone plus radius-xs (18), centred and evenly spaced at the merged pitch or the pitch + // that puts the outer lanes 18 from the tables, whichever is less: one at 30, two at 20 and 40, three at 18, 30 and 42 in the 60 gap. + const laneAt = (span: [number, number], j: number, count: number) => { + const width = span[1] - span[0]; + if (!m.marks) return span[0] + (width / (count + 1)) * (j + 1); + const room = tk.foot + tk.radiusXs; + const step = count > 1 ? Math.min(width / (count + 1), (width - 2 * room) / (count - 1)) : 0; + return (span[0] + span[1]) / 2 + (j - (count - 1) / 2) * step; + }; + // An interior corridor's two lanes: the order that crosses least. + nestCorridors(); + for (const [key, groups] of corridorGroups) { + if (key === "top" || key === "bottom" || groups.length < 2) continue; + const members = new Set(groups.flat()); + let best = groups, bestScore = Infinity; + for (const perm of permutations(groups.slice().sort((p, q) => reach(q) - reach(p)))) { + setCorridor(key, perm); + current = null; + const tried = score(members); + if (tried.score < bestScore) { bestScore = tried.score; best = perm; } + } + setCorridor(key, best); + current = null; + } + for (const [, g] of jogs) { + for (const cluster of clustersOf(g)) { const groupsOf = cluster.map((c) => c.members); + if (m.marks) { + // A marked gutter: its lanes by what runs beside what, each assignment that keeps runs beside each other apart tried, the one that crosses + // least kept (the first-fit one wins a tie). + const need = needOf(cluster), beside = besideIn(cluster), n = cluster.length; + const inGutter = new Set(groupsOf.flat().map(edgeOf)); + const set = (slots: number[]) => slots.forEach((l, i) => groupsOf[i]!.forEach((k) => lanes.set(k, laneAt(g.span, l, need)))); + let best = firstFit(cluster), bestScore = Infinity, bestLines: GLine[] | null = null; + const tries: number[][] = [best]; + if (need ** n <= 729) for (let code = 0; code < need ** n; code++) { + const slots = Array.from({ length: n }, (_, i) => Math.floor(code / need ** i) % need); + if (slots.every((x, i) => slots.every((y, j) => j <= i || x !== y || !beside(i, j)))) tries.push(slots); + } + for (const slots of tries) { + set(slots); + const tried = score(inGutter); + if (tried.score < bestScore) { bestScore = tried.score; best = slots; bestLines = tried.lines; } + } + set(best); + current = bestLines; + continue; + } const count = groupsOf.length; - const step = (g.span[1] - g.span[0]) / (count + 1); - if (dev && step < s("3")) warn?.(`a gutter holds ${count} lanes side by side, closer than space-3`); - const inGutter = new Set(groupsOf.flat()); + if (dev && !m.marks && (g.span[1] - g.span[0]) / (count + 1) < s("3")) warn?.(`a gutter holds ${count} lanes side by side, closer than space-3`); + const inGutter = new Set(groupsOf.flat().map(edgeOf)); let best: number[][] = groupsOf, bestScore = Infinity, bestLines: GLine[] | null = null; for (const perm of permutations(groupsOf)) { - perm.forEach((members, j) => members.forEach((k) => lanes.set(k, g.span[0] + step * (j + 1)))); + perm.forEach((members, j) => members.forEach((k) => lanes.set(k, laneAt(g.span, j, count)))); const tried = score(inGutter); if (tried.score < bestScore) { bestScore = tried.score; best = perm; bestLines = tried.lines; } } - best.forEach((members, j) => members.forEach((k) => lanes.set(k, g.span[0] + step * (j + 1)))); + best.forEach((members, j) => members.forEach((k) => lanes.set(k, laneAt(g.span, j, count)))); current = bestLines; } } geo.lines = build(); - if (dev) for (const k of dropped) if (!turnBackLanes(m).dropped.has(k)) warn?.(`${m.edges[k]!.from} to ${m.edges[k]!.to} is two columns apart, so its line is not drawn; its row still writes the target`); + // A marked line whose end run cannot hold its zone (1.1): the marks and an elbow's room past them, or both zones on a straight line. + if (m.marks) geo.lines = geo.lines.filter((l) => { + if (!l.card) return true; + const segs = segmentsOf(l.pts); + const len = ([a, b]: readonly [Pt, Pt]) => Math.hypot(b.x - a.x, b.y - a.y); + const need = segs.length === 1 ? 2 * tk.foot : tk.foot + tk.radiusXs - 0.5; + if (len(segs[0]!) >= need && len(segs[segs.length - 1]!) >= need) return true; + drop(l.i, "has no room for its marks at an end"); + return false; + }); + // The rows a far line's corridor needs (1.1): a row gap that carries one is space-10 (space-8 otherwise); a margin corridor adds space-8. + if (far.size) { + const used = new Set([...far.values()].map((f) => f.corridor)); + const tracks = [used.has("top") ? "var(--basalt-space-8)" : "0px"]; + for (let r = 1; r <= m.rows; r++) tracks.push("auto", r < m.rows ? (used.has(`g${r}`) ? "var(--basalt-space-10)" : "var(--basalt-space-8)") : used.has("bottom") ? "var(--basalt-space-8)" : "0px"); + geo.corridors = { rows: tracks.join(" "), pick }; + } geo.crossings = findCrossings(geo.lines); geo.through = throughOf(geo.lines, nodes, m); geo.outside = outsideOf(geo.lines, W, H, tk); @@ -2404,13 +2665,16 @@ function stackedGeometry(input: DrawnInput, measure: ReturnType, p // ---- The ink: one string of SVG and labels, the same in React and in the skill ---- -export function pathD(pts: Pt[], radius: number): string { +/** A route as a path, its corners rounded. `zone` (a marked line's, 1.1): no elbow starts within it of either end. */ +export function pathD(pts: Pt[], radius: number, zone = 0): string { const f = (n: number) => String(Math.round(n * 100) / 100); let d = `M${f(pts[0]!.x)} ${f(pts[0]!.y)}`; for (let k = 1; k < pts.length - 1; k++) { const a = pts[k - 1]!, b = pts[k]!, c = pts[k + 1]!; const d1 = Math.hypot(b.x - a.x, b.y - a.y), d2 = Math.hypot(c.x - b.x, c.y - b.y); - const r = Math.min(radius, d1 / 2, d2 / 2); + let r = Math.min(radius, d1 / 2, d2 / 2); + if (zone && k === 1) r = Math.min(r, Math.max(0, d1 - zone)); + if (zone && k === pts.length - 2) r = Math.min(r, Math.max(0, d2 - zone)); if (r < 0.5) { d += `L${f(b.x)} ${f(b.y)}`; continue; } const p0 = { x: b.x + ((a.x - b.x) / d1) * r, y: b.y + ((a.y - b.y) / d1) * r }; const p3 = { x: b.x + ((c.x - b.x) / d2) * r, y: b.y + ((c.y - b.y) / d2) * r }; @@ -2424,6 +2688,15 @@ const unit: Record = { up: { x: 0, y: -1 }, down: { x: 0, y: 1 }, left: function lineMarkup(P: string, l: GLine, tk: Tokens, maskId: string | null, radius: number): string { const u = unit[l.dir]; + // A line that states how many (1.1): its shaft runs to both tables' edges, through crow's-foot marks in its own ink, with no dot and no head. + if (l.card) { + const a = l.pts[0]!, b = l.pts[1]!; + const end = (form: DiagramCardinality, at: Pt, out: number, which: string) => { + const { crow, ring } = cardMarks(form, at.x, at.y, out, tk.head, tk.dot); + return `${ring ? `` : ""}`; + }; + return `${end(l.card.from, a, Math.sign(b.x - a.x) || 1, "from")}${end(l.card.to, l.tip, -u.x || 1, "to")}`; + } const open = l.kind === "dashed"; const L = tk.head, W2 = tk.head / 2; // The head's tip touches the contour; the line stops under the head (an open head's shaft runs on into it). @@ -2555,10 +2828,17 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin if (m.text) return { dyn: { ...current, layout: "stacked", bare: undefined }, geo: null, ink: "", tokens: tk, least: mins.least }; if (W >= mins.least && !m.unplaced) { const drawnTry = (pad: boolean) => { - let dd = stopOf({ ...current, ...closed, layout: "drawn", grow: undefined, track: undefined, bare: undefined, pad: pad || undefined }); + let dd = stopOf({ ...current, ...closed, layout: "drawn", grow: undefined, track: undefined, bare: undefined, pad: pad || undefined, rows: undefined }); dd = heightsFor(dd); apply(dd); - return { dd, g: drawnGeometry(input(), measure) }; + let g = drawnGeometry(input(), measure); + // A schema's far keys (1.1): their corridors are chosen on the grid without them, then the rows grow to hold them and the figure is measured again. + if (g.corridors) { + dd = { ...dd, rows: g.corridors.rows }; + apply(dd); + g = drawnGeometry({ ...input(), pick: g.corridors.pick }, measure); + } + return { dd, g }; }; let { dd: d, g: geo } = drawnTry(false); // A label refused only because its seats leave the drawing (beside a line in a 40px first or last row) is given space-3 above and below. @@ -2580,7 +2860,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin if (geo.outside.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.outside)} would leave the drawing`); if (geo.unseated.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: no clean seat for ${geo.unseated.map((k) => (m.type === "sequence" ? `message ${k}` : `"${m.edges[k]?.label}"`)).join(", ")}`); } - let d = stopOf({ ...current, ...closed, layout: "stacked", heights: undefined, grow: record(), track: m.type === "schema" ? mins.table : undefined, bare: undefined, pad: undefined }); + let d = stopOf({ ...current, ...closed, layout: "stacked", heights: undefined, grow: record(), track: m.type === "schema" ? mins.table : undefined, bare: undefined, pad: undefined, rows: undefined }); d = heightsFor(d); apply(d); if (m.type === "sequence" || m.type === "schema") return { dyn: d, geo: null, ink: "", tokens: tk, least: mins.least }; @@ -2730,7 +3010,7 @@ export function keyTarget(m: Model, from: string, key: string, drawn = false, rt */ const MANAGED = ["data-layout", "data-measured", "role", "aria-roledescription", "aria-labelledby", "aria-describedby", "aria-label", "tabindex", "data-stops", "hidden", "data-art"]; const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion", "data-first-visit", "data-rtl"]; -const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_gpad", "--_gw", "--_mh"]; +const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_gpad", "--_gw", "--_mh", "--_rows", "--_row-gap"]; const absent = (value: VAttrs[string]) => value === undefined || value === null || value === false; function pairs(el: Element, v: VElement): boolean { if (el.tagName.toLowerCase() !== v.t) return false; diff --git a/packages/react/src/diagram-motion-core.ts b/packages/react/src/diagram-motion-core.ts index 079253c4..f7650dbf 100644 --- a/packages/react/src/diagram-motion-core.ts +++ b/packages/react/src/diagram-motion-core.ts @@ -412,6 +412,15 @@ class Figure implements MotionController { const copy = svgEl("circle", { cx: dot.getAttribute("cx") ?? 0, cy: dot.getAttribute("cy") ?? 0, r: Number(dot.getAttribute("r") ?? 3) + 1, fill: "#fff" }, mask); clocked(copy.animate([{ opacity: 0 }, { opacity: 1 }], { duration: t.fast, delay: plan.start, easing: t.out, fill: "both" })); } + // Cardinality marks (DECISIONS 306, 1.1): the foreign-key end's fade in as the dot does, the referenced end's as a head does. + g.querySelectorAll(`.${P}-crow, .${P}-ring`).forEach((mark) => { + const ring = mark.tagName.toLowerCase() === "circle"; + const copy = ring + ? svgEl("circle", { cx: mark.getAttribute("cx") ?? 0, cy: mark.getAttribute("cy") ?? 0, r: Number(mark.getAttribute("r") ?? 3) + 1, fill: "#fff" }, mask) + : svgEl("path", { d: mark.getAttribute("d") ?? "", fill: "none", stroke: "#fff", "stroke-width": 3 }, mask); + const from = mark.getAttribute("data-end") === "from"; + clocked(copy.animate([{ opacity: 0 }, { opacity: 1 }], from ? { duration: t.fast, delay: plan.start, easing: t.out, fill: "both" } : { duration: t.slow, delay: plan.start + 0.85 * plan.dur, easing: t.out, fill: "both" })); + }); g.setAttribute("mask", `url(#${id})`); } // A sequence's labels are drawn in secondary ink before their turn and lift to primary over duration-slower (1.4). Built once, on the clock. diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 186af262..b5ac7d26 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4473,12 +4473,17 @@ .basalt-diagram[data-type="schema"] > .basalt-diagram-drawing { --_row-gap: var(--basalt-space-8); --_col-gap: var(--basalt-space-12); + /* Far keys' corridors (DECISIONS 306, 1.1): the engine writes spacer tracks round the author's rows (--_rows) on the drawn layout alone. */ + --_d-rows: var(--_drawn) var(--_rows, none); display: grid; grid-template-columns: var(--_d-cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr))); + grid-template-rows: var(--_d-rows, none); gap: var(--_d-gap, var(--basalt-space-4)); align-items: start; max-width: none; } + /* A schema that draws cardinality marks (DECISIONS 306, 1.1): its column gap is space-12 plus space-3, so three lanes keep 18 from its tables. */ + .basalt-diagram[data-type="schema"][data-marks] > .basalt-diagram-drawing { --_col-gap: calc(var(--basalt-space-12) + var(--basalt-space-3)); } .basalt-diagram[data-type="sequence"] > .basalt-diagram-drawing { display: flex; gap: 0; } /* Right to left (DECISIONS 306, 1.7): the engine lays out a mirrored model on a left-to-right grid, so the drawing is set left to right and what is in it @@ -4686,6 +4691,10 @@ .basalt-diagram-tip[data-kind="main"] { fill: var(--basalt-diagram-edge-main); } .basalt-diagram-tip[data-open] { fill: none; stroke: var(--basalt-diagram-edge); stroke-width: var(--basalt-size-hairline); stroke-linecap: round; stroke-linejoin: round; } .basalt-diagram-dot { fill: var(--basalt-diagram-edge); } + /* Cardinality marks (DECISIONS 306, 1.1): 1px in the line's own ink, on a shaft that runs through them; a ring is filled with the ground so the + shaft does not show through it. */ + .basalt-diagram-crow { fill: none; stroke: var(--basalt-diagram-edge); stroke-width: var(--basalt-size-hairline); stroke-linecap: butt; stroke-linejoin: miter; transition: stroke var(--basalt-duration-fast) var(--basalt-ease-out); } + .basalt-diagram-ring { fill: var(--_ground); stroke: var(--basalt-diagram-edge); stroke-width: var(--basalt-size-hairline); transition: stroke var(--basalt-duration-fast) var(--basalt-ease-out); } .basalt-diagram-life { fill: none; stroke: var(--basalt-diagram-structure); stroke-width: var(--basalt-size-hairline); stroke-dasharray: var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash); } /* A trace changes ink, never weight, dash or head: the node's own lines take the main ink, every other line dims to the input boundary. */ .basalt-diagram-edge[data-lit] .basalt-diagram-line { stroke: var(--basalt-diagram-edge-main); } @@ -4694,6 +4703,8 @@ .basalt-diagram-edge[data-dim] .basalt-diagram-line { stroke: var(--basalt-diagram-edge-dim); } .basalt-diagram-edge[data-dim] .basalt-diagram-tip:not([data-open]), .basalt-diagram-edge[data-dim] .basalt-diagram-dot { fill: var(--basalt-diagram-edge-dim); } .basalt-diagram-edge[data-dim] .basalt-diagram-tip[data-open] { stroke: var(--basalt-diagram-edge-dim); } + .basalt-diagram-edge[data-lit] :is(.basalt-diagram-crow, .basalt-diagram-ring) { stroke: var(--basalt-diagram-edge-main); } + .basalt-diagram-edge[data-dim] :is(.basalt-diagram-crow, .basalt-diagram-ring) { stroke: var(--basalt-diagram-edge-dim); } /* An edge label: one line of Mono in the line's secondary ink; on its own line it sits on a plate of the ground, with no radius. */ .basalt-diagram-label { position: absolute; box-sizing: border-box; height: var(--basalt-text-xs-line-height); color: var(--basalt-diagram-edge); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); text-align: center; white-space: nowrap; transition: color var(--basalt-duration-fast) var(--basalt-ease-out); } .basalt-diagram-label[data-on] { background: var(--_ground); } @@ -4904,7 +4915,7 @@ .basalt-diagram-toggle { min-height: var(--basalt-size-tap-min); } } @media (prefers-reduced-motion: reduce) { - .basalt-diagram-node, .basalt-diagram-line, .basalt-diagram-tip, .basalt-diagram-label, .basalt-diagram-diamond path { transition: none; } + .basalt-diagram-node, .basalt-diagram-line, .basalt-diagram-tip, .basalt-diagram-crow, .basalt-diagram-ring, .basalt-diagram-label, .basalt-diagram-diamond path { transition: none; } } @media (prefers-contrast: more) { .basalt-diagram-node[data-focal] :is(.basalt-diagram-kind, .basalt-diagram-detail, .basalt-diagram-keyseat, .basalt-diagram-ctype, .basalt-diagram-more) { opacity: 1; } @@ -4917,7 +4928,7 @@ /* stylelint-disable-next-line basalt/container-length -- a data flow of 3 step columns: size-diagram-lane (120) + 3 × (size-diagram-node 144 + space-12 48) = 696px */ @container (width >= 696px) { .basalt-diagram:not([data-layout])[data-type="data-flow"][data-cols="3"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- 4 columns: 4 × size-diagram-node (144) + 3 × space-16 (64) = 768px; and a schema of 3: 3 × size-diagram-table (224) + 2 × space-12 (48) = 768px */ - @container (width >= 768px) { .basalt-diagram:not([data-layout]):is([data-type="architecture"][data-cols="4"][data-reach="0"], [data-type="flowchart"][data-cols="4"], [data-type="schema"][data-cols="3"]) > .basalt-diagram-drawing { --_drawn: ; } } + @container (width >= 768px) { .basalt-diagram:not([data-layout]):is([data-type="architecture"][data-cols="4"][data-reach="0"], [data-type="flowchart"][data-cols="4"], [data-type="schema"][data-cols="3"]:not([data-marks])) > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- an architecture of 4 columns whose group reaches one side: 4 × 144 + 3 × 64 + space-4 (16) = 784px */ @container (width >= 784px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="4"][data-reach="1"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- an architecture of 4 columns reaching both sides: 4 × 144 + 3 × 64 + 2 × 16 = 800px; a sequence of 5: 5 × size-diagram-node (144) + 4 × space-5 (20) = 800px */ @@ -4941,7 +4952,7 @@ /* stylelint-disable-next-line basalt/container-length -- an architecture of 5 columns with four group levels: 5 × 144 + 4 × 64 + 4 × 16 = 1040px */ @container (width >= 1040px) { .basalt-diagram:not([data-layout])[data-type="architecture"][data-cols="5"][data-reach="4"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a schema of 4: 4 × size-diagram-table (224) + 3 × space-12 (48) = 1040px */ - @container (width >= 1040px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-cols="4"] > .basalt-diagram-drawing { --_drawn: ; } } + @container (width >= 1040px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-cols="4"]:not([data-marks]) > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a data flow of 5 step columns: 120 + 5 × (144 + 48) = 1080px */ @container (width >= 1080px) { .basalt-diagram:not([data-layout])[data-type="data-flow"][data-cols="5"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- 6 columns: 6 × 144 + 5 × 64 = 1184px */ @@ -4957,9 +4968,18 @@ /* stylelint-disable-next-line basalt/container-length -- a data flow of 6 step columns: 120 + 6 × (144 + 48) = 1272px */ @container (width >= 1272px) { .basalt-diagram:not([data-layout])[data-type="data-flow"][data-cols="6"] > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a schema of 5: 5 × 224 + 4 × 48 = 1312px */ - @container (width >= 1312px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-cols="5"] > .basalt-diagram-drawing { --_drawn: ; } } + @container (width >= 1312px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-cols="5"]:not([data-marks]) > .basalt-diagram-drawing { --_drawn: ; } } /* stylelint-disable-next-line basalt/container-length -- a schema of 6: 6 × 224 + 5 × 48 = 1584px */ - @container (width >= 1584px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-cols="6"] > .basalt-diagram-drawing { --_drawn: ; } } + @container (width >= 1584px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-cols="6"]:not([data-marks]) > .basalt-diagram-drawing { --_drawn: ; } } + /* A schema that draws cardinality marks has gaps of space-12 plus space-3 (60, DECISIONS 306, 1.1); two columns are under the 640 floor. */ + /* stylelint-disable-next-line basalt/container-length -- a marked schema of 3: 3 × size-diagram-table (224) + 2 × 60 = 792px */ + @container (width >= 792px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-marks][data-cols="3"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- a marked schema of 4: 4 × 224 + 3 × 60 = 1076px */ + @container (width >= 1076px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-marks][data-cols="4"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- a marked schema of 5: 5 × 224 + 4 × 60 = 1360px */ + @container (width >= 1360px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-marks][data-cols="5"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- a marked schema of 6: 6 × 224 + 5 × 60 = 1644px */ + @container (width >= 1644px) { .basalt-diagram:not([data-layout])[data-type="schema"][data-marks][data-cols="6"] > .basalt-diagram-drawing { --_drawn: ; } } /* Where scripting is off: always stacked, the list open, no toggle and no line in the key (no line is drawn). */ @media (scripting: none) { /* An id's weight in a :not(), so this outweighs every least-width rule above. */ @@ -4981,6 +5001,11 @@ .basalt-diagram .basalt-diagram-edge[data-lit] .basalt-diagram-line { stroke: Highlight; } .basalt-diagram .basalt-diagram-edge[data-lit] :is(.basalt-diagram-tip:not([data-open]), .basalt-diagram-dot) { fill: Highlight; } .basalt-diagram .basalt-diagram-edge[data-lit] .basalt-diagram-tip[data-open] { stroke: Highlight; } + /* Cardinality marks follow their line; a ring's fill is Canvas (DECISIONS 306, 1.10). */ + .basalt-diagram :is(.basalt-diagram-crow, .basalt-diagram-ring) { stroke: CanvasText; } + .basalt-diagram .basalt-diagram-ring { fill: Canvas; } + .basalt-diagram .basalt-diagram-edge[data-dim] :is(.basalt-diagram-crow, .basalt-diagram-ring) { stroke: GrayText; } + .basalt-diagram .basalt-diagram-edge[data-lit] :is(.basalt-diagram-crow, .basalt-diagram-ring) { stroke: Highlight; } .basalt-diagram .basalt-diagram-life { stroke: GrayText; } .basalt-diagram .basalt-diagram-label { color: CanvasText; forced-color-adjust: none; } .basalt-diagram .basalt-diagram-label[data-on] { background: Canvas; } @@ -5026,6 +5051,7 @@ .basalt-diagram .basalt-diagram-edge .basalt-diagram-line[data-kind="main"] { stroke: var(--basalt-diagram-edge-main) !important; } .basalt-diagram .basalt-diagram-edge :is(.basalt-diagram-tip:not([data-open]), .basalt-diagram-dot) { fill: var(--basalt-diagram-edge) !important; } .basalt-diagram .basalt-diagram-edge .basalt-diagram-tip[data-kind="main"]:not([data-open]) { fill: var(--basalt-diagram-edge-main) !important; } + .basalt-diagram .basalt-diagram-edge :is(.basalt-diagram-crow, .basalt-diagram-ring) { stroke: var(--basalt-diagram-edge) !important; } .basalt-diagram .basalt-diagram-label { color: var(--basalt-diagram-edge) !important; } } diff --git a/packages/react/test/diagram-geometry.mjs b/packages/react/test/diagram-geometry.mjs index 80e10c83..4ab9db19 100644 --- a/packages/react/test/diagram-geometry.mjs +++ b/packages/react/test/diagram-geometry.mjs @@ -41,11 +41,14 @@ function inspect(P, selector) { const n = m[2].trim().split(/[ ,]+/).map(Number); if (m[1] === "Q") { pts.pop(); pts.push({ x: n[0], y: n[1] }); } else pts.push({ x: n[0], y: n[1] }); } + const width = parseFloat(getComputedStyle(g.querySelector(`.${P}-line`)).strokeWidth); + // A line that states its cardinality (DECISIONS 306, 1.1) has no head: its shaft runs to the table's edge, and its referenced end's marks stand for the head. + const marks = g.querySelector(`.${P}-crow[data-end="to"]`); + if (marks) { const tip = pts[pts.length - 1]; return { i: g.dataset.edge, from: g.dataset.from, to: g.dataset.to, pts, stop: tip, tip, width, tipEl: marks }; } const tipEl = g.querySelector(`.${P}-tip`); const tn = tipEl.getAttribute("d").match(/-?[\d.]+/g).map(Number); const open = tipEl.hasAttribute("data-open"); const tip = open ? { x: tn[2], y: tn[3] } : { x: tn[0], y: tn[1] }; - const width = parseFloat(getComputedStyle(g.querySelector(`.${P}-line`)).strokeWidth); const full = pts.slice(0, -1).concat([tip]); return { i: g.dataset.edge, from: g.dataset.from, to: g.dataset.to, pts: full, stop: pts[pts.length - 1], tip, width, tipEl }; }); diff --git a/packages/react/test/fixtures/cimip-diagrams-b.json b/packages/react/test/fixtures/cimip-diagrams-b.json index 1a4d5cf6..0d3856a1 100644 --- a/packages/react/test/fixtures/cimip-diagrams-b.json +++ b/packages/react/test/fixtures/cimip-diagrams-b.json @@ -638,7 +638,7 @@ "type": "schema", "title": "The tables an incident and its runs live in", "source": "server/db/schema.ts; each table shows its keys and a few columns", - "summary": "Eight PostgreSQL tables center on incidents: memberships, room_events, log_segments, sandboxes and agent_runs reference incidents.id; memberships and incidents reference users.id; agent_runs references sandboxes.id; and approvals references agent_runs.id.", + "summary": "Eight PostgreSQL tables center on incidents: memberships, room_events, log_segments, sandboxes, agent_runs and approvals reference incidents.id; memberships, incidents and approvals reference users.id; agent_runs references sandboxes.id; and approvals references agent_runs.id. Each foreign key says how many rows each end allows.", "legend": { "plain": "A foreign key, to the key it references", "focal": "The table most of the others reference" @@ -653,12 +653,20 @@ { "name": "incident_id", "key": "PK", - "references": "incidents.id" + "references": "incidents.id", + "cardinality": { + "from": "one-or-many", + "to": "one" + } }, { "name": "user_id", "key": "PK", - "references": "users.id" + "references": "users.id", + "cardinality": { + "from": "zero-or-many", + "to": "one" + } }, { "name": "role", @@ -683,7 +691,11 @@ { "name": "incident_id", "key": "PK", - "references": "incidents.id" + "references": "incidents.id", + "cardinality": { + "from": "zero-or-many", + "to": "one" + } }, { "name": "seq", @@ -709,7 +721,11 @@ { "name": "incident_id", "key": "PK", - "references": "incidents.id" + "references": "incidents.id", + "cardinality": { + "from": "zero-or-many", + "to": "one" + } }, { "name": "first_seq", @@ -760,7 +776,11 @@ { "name": "commander_id", "key": "FK", - "references": "users.id" + "references": "users.id", + "cardinality": { + "from": "zero-or-many", + "to": "zero-or-one" + } }, { "name": "last_seq", @@ -812,7 +832,11 @@ { "name": "incident_id", "key": "FK", - "references": "incidents.id" + "references": "incidents.id", + "cardinality": { + "from": "zero-or-one", + "to": "one" + } }, { "name": "state", @@ -841,12 +865,20 @@ { "name": "incident_id", "key": "FK", - "references": "incidents.id" + "references": "incidents.id", + "cardinality": { + "from": "zero-or-many", + "to": "one" + } }, { "name": "sandbox_id", "key": "FK", - "references": "sandboxes.id" + "references": "sandboxes.id", + "cardinality": { + "from": "zero-or-many", + "to": "one" + } }, { "name": "kind", @@ -870,17 +902,39 @@ "name": "approvals", "col": 4, "row": 1, - "more": 8, + "more": 6, "columns": [ { "name": "id", "key": "PK", "type": "text" }, + { + "name": "incident_id", + "key": "FK", + "references": "incidents.id", + "cardinality": { + "from": "zero-or-many", + "to": "one" + } + }, { "name": "run_id", "key": "FK", - "references": "agent_runs.id" + "references": "agent_runs.id", + "cardinality": { + "from": "zero-or-many", + "to": "one" + } + }, + { + "name": "decided_by", + "key": "FK", + "references": "users.id", + "cardinality": { + "from": "zero-or-many", + "to": "zero-or-one" + } }, { "name": "command", diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 74909a79..9445c6c4 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -35,7 +35,7 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, } // The attributes the figure's markup sets on the figure itself; a redraw clears them before it writes the new ones. - var OWN = ['aria-labelledby', 'data-type', 'data-cols', 'data-reach', 'data-gutter', 'data-layout', 'data-measured', 'data-bare']; + var OWN = ['aria-labelledby', 'data-type', 'data-cols', 'data-reach', 'data-gutter', 'data-marks', 'data-layout', 'data-measured', 'data-bare']; var OWN_STYLE = ['--_cols', '--_gpad', '--_track']; /** diff --git a/tools/html-skill/src/usage/diagram.md b/tools/html-skill/src/usage/diagram.md index e50d6a93..de16bf0b 100644 --- a/tools/html-skill/src/usage/diagram.md +++ b/tools/html-skill/src/usage/diagram.md @@ -16,7 +16,7 @@ Boxes and the lines between them. `compose.mjs` writes the figure's words into the page (it reads before script); the script draws the lines, the labels, the keys and "View as list". `Basalt.diagram(figure, spec)` draws one from script. -- **Five shapes of data** (`type`): `architecture` (`nodes` with `group`, `groups`, `edges`); `flowchart` (`nodes` with `shape`: `step`, `decision` or `terminal`, the first node the start; `edges`, a branch's `label` its condition); `data-flow` (`lanes`, `nodes` with `lane` and `col`, its step columns; `edges`); `sequence` (`participants` with `short`; `steps`: `{ from, to, label, note, kind }` or `{ band }`); `schema` (`tables`: `name`, `col`, `row` or `[first, last]`, `columns` with `key` `PK`/`FK` and `references: "table.column"`, `more`). +- **Five shapes of data** (`type`): `architecture` (`nodes` with `group`, `groups`, `edges`); `flowchart` (`nodes` with `shape`: `step`, `decision` or `terminal`, the first node the start; `edges`, a branch's `label` its condition); `data-flow` (`lanes`, `nodes` with `lane` and `col`, its step columns; `edges`); `sequence` (`participants` with `short`; `steps`: `{ from, to, label, note, kind }` or `{ band }`); `schema` (`tables`: `name`, `col`, `row` or `[first, last]`, `columns` with `key` `PK`/`FK` and `references: "table.column"`, `more`; `cardinality: { "from", "to" }` on every foreign key or none draws crow's feet: `from` is `one`, `zero-or-one`, `one-or-many` or `zero-or-many`, `to` is `one` or `zero-or-one`). - **Order is one thing:** the array's order is the stacked order, the focus order, the list's, a data flow's step numbers and a sequence's message numbers. - **Place, don't route:** `col` and `row` are whole tracks from 1. Sides, slots, jogs, lanes, the group's box and a foreign key's line are derived. Write `fromSide` or `toSide` (`top`, `right`, `bottom`, `left`) only to change the default. `branch: true` indents a node in the stacked drawing. - **Lines:** `kind` is `main` (2px), `plain` (default) or `dashed` (a reply, a stream). One `label` each, at most 28 characters. `legend` gives each kind its words; `main`, `dashed` and a `focal` node must have words. One node at most is `focal`. From b05ed38d19cef8f03a1863866def220018dd4583 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:35:49 -0600 Subject: [PATCH 37/62] Tests for cardinality and far keys: diagram-schema.test.mjs (section 8) The four forms at their distances, on the shaft, snapped, in the line's ink at rest, traced and dimmed; the zone and no elbow inside it; the gap 60 against 48; a marked gutter's lanes at 30, 20 and 40, 18, 30 and 42 and a fourth left out with its warning; the extended CIMIP schema drawn at 1,104 and 1,096 with every key, its far keys in the margin above and the gap between rows 2 and 3 (space-10), every crossing cut before and during a trace; two statements at one key 8 apart, one statement on one bus; a third corridor line left out and named; the key's forms (none stacked), the list's and the sentence's words, the row unchanged; forced colours and print; the development errors, and a mixed figure in production. diagram-fixes: the far-key warning is no longer "two columns apart" (the decision drops it); the words a development build must hold are the corridor's and the cardinality's. Co-Authored-By: Claude Opus 5.5 --- packages/react/test/diagram-fixes.test.mjs | 2 +- packages/react/test/diagram-schema.test.mjs | 374 ++++++++++++++++++++ 2 files changed, 375 insertions(+), 1 deletion(-) create mode 100644 packages/react/test/diagram-schema.test.mjs diff --git a/packages/react/test/diagram-fixes.test.mjs b/packages/react/test/diagram-fixes.test.mjs index 8045253b..c9c50151 100644 --- a/packages/react/test/diagram-fixes.test.mjs +++ b/packages/react/test/diagram-fixes.test.mjs @@ -97,7 +97,7 @@ describe("slots on a side (Neon's finding 13)", () => { describe("the development checks cost production nothing (Neon's finding 14)", () => { // Phrases only the checks write (a property name such as `crossings` is code, not a check's words). const WORDS = ["share the cell at column", "main lines are drawn but", "is not a kind of line", "more than three is an error", "would leave the drawing", "in the drawn layout", - "fifth end lane", "stands for", "is used twice", "two columns apart", "closer than space-3"]; + "fifth end lane", "stands for", "is used twice", "a third lane in its corridor", "closer than space-3", "states a cardinality but references nothing"]; const bundle = async (entry, mode) => (await esbuild.build({ stdin: { contents: entry, resolveDir: pkg, loader: "js" }, bundle: true, minify: true, format: "esm", write: false, logLevel: "silent", external: ["react", "react-dom", "react/jsx-runtime"], define: { "process.env.NODE_ENV": JSON.stringify(mode) }, diff --git a/packages/react/test/diagram-schema.test.mjs b/packages/react/test/diagram-schema.test.mjs new file mode 100644 index 00000000..469463f4 --- /dev/null +++ b/packages/react/test/diagram-schema.test.mjs @@ -0,0 +1,374 @@ +// A schema's cardinality and its far keys (DECISIONS 306, 1.1, revised by 313; section 8's list for diagram-schema.test.mjs), on the extended CIMIP +// schema (test/fixtures/cimip-diagrams-b.json: cardinality on every key, approvals.incident_id and approvals.decided_by two columns away) and small +// fixtures. In Chromium against the built package, both themes. The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { after, before, describe, test } from "node:test"; +import { pathToFileURL } from "node:url"; + +import * as esbuild from "esbuild"; + +import { inspectSource } from "./diagram-geometry.mjs"; +import { fixturePage, launch, pkg } from "./support.mjs"; + +const B = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams-b.json"), "utf8")); +const A = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams.json"), "utf8")); +const P = "basalt-diagram"; +const font = (file) => fs.readFileSync(path.join(pkg, "dist", "fonts", file)).toString("base64"); +const FONTS = `@font-face{font-family:"Geist";src:url(data:font/woff2;base64,${font("Geist-Variable.woff2")}) format("woff2");font-weight:100 900}@font-face{font-family:"Geist Mono";src:url(data:font/woff2;base64,${font("GeistMono-Variable.woff2")}) format("woff2");font-weight:100 900}`; +const PAGE = `${FONTS} body{background:var(--basalt-surface-page);margin:0;padding:0 16px} #root{width:var(--w,1104px)}`; + +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +const HOST = ` +function Host() { + const [list, setList] = React.useState([]); + window.__set = (next) => flushSync(() => setList(next)); + return
{list.map(({ key, spec }) => { const { type, ...props } = spec; return ; })}
; +} +createRoot(document.getElementById("root")).render();`; + +const frames = (page, n = 3) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); +async function figurePage({ theme = "dark", width = 1440, dev = false } = {}) { + // A development build, so the warnings are written; the fixtures are production builds, which drop them. + const { page, errors } = await fixturePage(browser, "", { theme, viewport: { width, height: 1400 }, standards: true }); + const built = await esbuild.build({ + stdin: { contents: `import * as React from "react"; import { createRoot } from "react-dom/client"; import { flushSync } from "react-dom"; import * as B from "./dist/index.js"; ${HOST}`, resolveDir: pkg, loader: "tsx" }, + bundle: true, format: "iife", write: false, jsx: "automatic", platform: "browser", logLevel: "silent", define: { "process.env.NODE_ENV": dev ? '"development"' : '"production"' }, + }); + const warnings = []; + page.on("console", (m) => { if (m.type() === "warning" || m.type() === "error") warnings.push(m.text()); }); + await page.addScriptTag({ content: built.outputFiles[0].text }); + await page.addStyleTag({ content: PAGE }); + await page.evaluate(() => document.fonts.ready); + return { page, errors, warnings }; +} +const draw = async (page, items) => { await page.evaluate((items) => window.__set(items), items); await frames(page, 5); }; +const widthTo = async (page, w) => { await page.evaluate((w) => document.getElementById("root").style.setProperty("--w", `${w}px`), w); await frames(page, 5); }; +const inspect = (page, key) => page.evaluate(`${inspectSource()}("${P}", "#fig-${key}")`); + +/** Each drawn foreign key: its path's points, its marks (bars' x, a foot's point, a ring), the tables' edges, and computed inks. */ +const readLines = (page, key) => page.evaluate(({ P, key }) => { + const fig = document.querySelector(`#fig-${key}`); + const drawing = fig.querySelector(`.${P}-drawing`); + const o = drawing.getBoundingClientRect(); + const rect = (id) => { const r = fig.querySelector(`.${P}-node[data-node="${id}"]`).getBoundingClientRect(); return { l: r.left - o.left, r: r.right - o.left, t: r.top - o.top, b: r.bottom - o.top }; }; + const nums = (d) => d.match(/-?[\d.]+/g).map(Number); + return [...fig.querySelectorAll(`.${P}-edge`)].map((g) => { + const line = g.querySelector(`.${P}-line`); + const d = line.getAttribute("d"); + // The route's points (a Q's control point is the corner) and the runs written between corners (L … then Q): where each elbow starts and ends. + const pts = [], straight = []; + for (const m of d.matchAll(/([MLQ])([^MLQ]*)/g)) { + const n = m[2].trim().split(/[ ,]+/).map(Number); + if (m[1] === "Q") { straight.push({ x: n[2], y: n[3] }); pts.pop(); pts.push({ x: n[0], y: n[1] }); } else { pts.push({ x: n[0], y: n[1] }); straight.push({ x: n[0], y: n[1] }); } + } + const end = (which) => { + const crow = g.querySelector(`.${P}-crow[data-end="${which}"]`); + const ring = g.querySelector(`.${P}-ring[data-end="${which}"]`); + return crow ? { crow: crow.getAttribute("d"), segs: [...crow.getAttribute("d").matchAll(/M([^M]*)/g)].map((s) => nums(s[1])), ring: ring ? { cx: +ring.getAttribute("cx"), cy: +ring.getAttribute("cy"), r: +ring.getAttribute("r") } : null, stroke: getComputedStyle(crow).stroke, ringStroke: ring ? getComputedStyle(ring).stroke : null, ringFill: ring ? getComputedStyle(ring).fill : null } : null; + }; + return { i: g.dataset.edge, from: g.dataset.from, to: g.dataset.to, d, pts, straight, stroke: getComputedStyle(line).stroke, tip: !!g.querySelector(`.${P}-tip`), dot: !!g.querySelector(`.${P}-dot`), fromEnd: end("from"), toEnd: end("to"), a: rect(g.dataset.from), b: rect(g.dataset.to), ox: o.left - Math.floor(o.left), oy: o.top - Math.floor(o.top) }; + }); +}, { P, key }); + +const col = (name, extra = {}) => ({ name, type: "text", ...extra }); +const fk = (name, references, from, to) => ({ name, key: "FK", references, ...(from ? { cardinality: { from, ...(to ? { to } : {}) } } : {}) }); +const table = (name, c, r, columns) => ({ name, col: c, row: r, columns }); +const schema = (tables, extra = {}) => ({ type: "schema", title: "A schema", summary: "Tables and their keys.", legend: { plain: "A foreign key" }, tables, ...extra }); + +// Four forms on straight lines, each from its own row to the row level with it. +const FORMS = [["one", "one"], ["zero-or-one", "zero-or-one"], ["one-or-many", "one"], ["zero-or-many", "zero-or-one"]]; +const formsSpec = schema([ + table("a", 1, 1, FORMS.map(([from, to], k) => fk(`k${k}`, `b.c${k}`, from, to))), + table("b", 2, 1, FORMS.map((_, k) => col(`c${k}`, { key: k ? undefined : "PK" }))), +]); +// n lines from a's first rows to b's rows below them: their runs in the gutter overlap, so they take n lanes. +const lanesSpec = (n) => schema([ + table("a", 1, 1, Array.from({ length: n }, (_, k) => fk(`f${k}`, `b.x${n + k}`, "zero-or-many", "one"))), + table("b", 2, 1, Array.from({ length: 2 * n }, (_, k) => col(`x${k}`))), +]); +// Three far lines from z to three keys of x, over a table that spans both rows of column 2: all three take the margin above. +const corridorSpec = schema([ + table("x", 1, 1, [col("p0", { key: "PK" }), col("p1"), col("p2")]), + table("y", 2, [1, 2], [col("id", { key: "PK" })]), + table("w", 1, 2, [col("id", { key: "PK" })]), + table("z", 3, 1, [fk("r0", "x.p0"), fk("r1", "x.p1"), fk("r2", "x.p2")]), +]); + +describe("the four forms", () => { + for (const theme of ["dark", "light"]) test(`${theme}: each form's marks at its distances, on the shaft, snapped with the line, in the line's ink at rest, traced and dimmed`, async () => { + const { page, errors } = await figurePage({ theme }); + await draw(page, [{ key: "forms", spec: formsSpec }]); + assert.equal(await page.locator("#fig-forms").getAttribute("data-layout"), "drawn"); + const lines = await readLines(page, "forms"); + assert.equal(lines.length, 4); + // Where each mark's ink is, from its table's edge along the line: a bar is the pixel ending at its distance; a foot's point; a ring's middle. + const read = (end, edge, y, out) => { + const bars = [], foot = []; + for (const s of end.segs) { + if (s.length === 3) bars.push((s[0] - edge) * out + 0.5); // M x y V y2: x is the bar's middle + else foot.push(s); + } + return { bars: bars.sort((p, q) => p - q), foot: foot.length ? (foot[0][2] - edge) * out : null, footSpread: foot.length ? [foot[0][1] - y, foot[0][5] - y] : null, ring: end.ring ? (end.ring.cx - edge) * out : null, ringR: end.ring?.r }; + }; + const want = { + one: { bars: [4, 8], foot: null, ring: null }, + "zero-or-one": { bars: [4], foot: null, ring: 10.5 }, + "one-or-many": { bars: [11], foot: 7.5, ring: null }, + "zero-or-many": { bars: [], foot: 7.5, ring: 10.5 }, + }; + lines.sort((p, q) => p.pts[0].y - q.pts[0].y); + lines.forEach((l, k) => { + const [fromForm, toForm] = FORMS[k]; + assert.ok(!l.tip && !l.dot, "no head and no dot where the cardinality is stated"); + const y = l.pts[0].y; + assert.equal(l.pts.length, 2, "a straight line"); + // The shaft runs from table edge to table edge, on whole pixels of the edge. + assert.ok(Math.abs(l.pts[0].x - l.a.r) <= 0.5 && Math.abs(l.pts[1].x - l.b.l) <= 0.5, "the shaft runs to both tables' edges"); + const f = read(l.fromEnd, l.pts[0].x, y, 1), t = read(l.toEnd, l.pts[1].x, y, -1); + for (const [got, form] of [[f, fromForm], [t, toForm]]) { + assert.deepEqual(got.bars, want[form].bars, `${form}: its bars`); + assert.equal(got.foot, want[form].foot, `${form}: its foot's point`); + if (got.foot !== null) assert.deepEqual(got.footSpread, [-4, 4], `${form}: its spokes end space-1 either side`); + assert.equal(got.ring, want[form].ring, `${form}: its ring`); + if (got.ring !== null) { + assert.equal(got.ringR, 3, "a ring is size-dot across its stroke's middle"); + assert.deepEqual([got.ring - got.ringR - 0.5, got.ring + got.ringR + 0.5], [7, 14], "its ink runs from 7 to 14, inside the zone"); + } + // Every mark's ink inside the 14px zone. + for (const b of got.bars) assert.ok(b - 1 >= 0 && b <= 14, `${form}: a bar inside the zone`); + } + // Snapped with the line: the line on a half pixel, a bar's middle on a half pixel, both in the page's grid. + const half = (v, off) => Math.abs(((v + off) % 1 + 1) % 1 - 0.5) < 0.02; + assert.ok(half(y, l.oy), `the line is on a half pixel (${y})`); + for (const s of [...l.fromEnd.segs, ...l.toEnd.segs].filter((s) => s.length === 3)) assert.ok(half(s[0], l.ox), `a bar is on a half pixel (${s[0]})`); + // In the line's own ink at rest; the ring is filled with the ground. + for (const e of [l.fromEnd, l.toEnd]) { assert.equal(e.stroke, l.stroke); if (e.ring) assert.equal(e.ringStroke, l.stroke); } + }); + const ground = await page.evaluate((P) => getComputedStyle(document.querySelector("#fig-forms")).getPropertyValue("--_ground").trim(), P); + assert.ok(ground, "the figure has a ground"); + // Traced (a hovered table) the marks take the main ink, and every other line's marks dim with their line. + const inks = await page.evaluate((P) => { const s = getComputedStyle(document.querySelector("#fig-forms")); return { main: s.getPropertyValue("--basalt-diagram-edge-main").trim(), dim: s.getPropertyValue("--basalt-diagram-edge-dim").trim() }; }, P); + await page.hover(`#fig-forms .${P}-node[data-node="a"]`); + await page.waitForTimeout(250); + const lit = await readLines(page, "forms"); + for (const l of lit) for (const e of [l.fromEnd, l.toEnd]) { assert.equal(e.stroke, l.stroke, "traced: the marks keep the line's ink"); if (e.ring) assert.equal(e.ringStroke, l.stroke); } + const litStroke = lit[0].stroke; + // Dimmed: draw a second figure's line... a table with no lines dims every line: use a schema where one table has its own line. + await draw(page, [{ key: "forms", spec: schema([...formsSpec.tables, table("c", 3, 1, [col("id", { key: "PK" }), fk("b0", "b.c0", "zero-or-many", "one")])]) }]); + await page.hover(`#fig-forms .${P}-node[data-node="c"]`); + await page.waitForTimeout(250); + const dim = (await readLines(page, "forms")).filter((l) => l.from === "a"); + assert.ok(dim.length === 4); + for (const l of dim) { assert.notEqual(l.stroke, litStroke, "the other lines dim"); for (const e of [l.fromEnd, l.toEnd]) assert.equal(e.stroke, l.stroke, "dimmed: the marks keep the line's ink"); } + void inks; + assert.deepEqual(errors, []); + await page.close(); + }); +}); + +describe("the zone, the gap and the lanes", () => { + test("no elbow starts inside the 14px zone; the gap is 60 with marks and 48 without", async () => { + const { page } = await figurePage(); + await draw(page, [{ key: "marked", spec: B.schema }, { key: "plain", spec: A.schema }]); + const gap = (key) => page.evaluate(({ P, key }) => parseFloat(getComputedStyle(document.querySelector(`#fig-${key} .${P}-drawing`)).columnGap), { P, key }); + assert.equal(await gap("marked"), 60); + assert.equal(await gap("plain"), 48); + assert.equal(await page.locator("#fig-marked").getAttribute("data-marks"), ""); + assert.equal(await page.locator("#fig-plain").getAttribute("data-marks"), null); + for (const l of await readLines(page, "marked")) { + // The written runs: the first L after M, and the last point before the end, are where the first and last elbows start. + const s = l.straight; + if (s.length < 3) continue; + const first = Math.hypot(s[1].x - s[0].x, s[1].y - s[0].y), last = Math.hypot(s[s.length - 1].x - s[s.length - 2].x, s[s.length - 1].y - s[s.length - 2].y); + assert.ok(first >= 14 - 0.01, `${l.from} to ${l.to}: its first elbow starts ${first.toFixed(2)} from the edge`); + assert.ok(last >= 14 - 0.01, `${l.from} to ${l.to}: its last elbow ends ${last.toFixed(2)} from the edge`); + } + await page.close(); + }); + + for (const theme of ["dark", "light"]) test(`${theme}: a marked gutter's lanes are at 30; 20 and 40; 18, 30 and 42, every elbow 3.5 or more outside the zone; a fourth leaves one line out and warns`, async () => { + const { page, warnings } = await figurePage({ theme, dev: true }); + for (const [n, want] of [[1, [30]], [2, [20, 40]], [3, [18, 30, 42]]]) { + await draw(page, [{ key: "lanes", spec: lanesSpec(n) }]); + assert.equal(await page.locator("#fig-lanes").getAttribute("data-layout"), "drawn", `${n} lanes: drawn`); + const lines = await readLines(page, "lanes"); + assert.equal(lines.length, n); + const xs = lines.map((l) => l.pts[1].x - l.a.r).sort((p, q) => p - q); + xs.forEach((x, k) => assert.ok(Math.abs(x - want[k]) <= 0.5, `${n} lanes: lane ${k + 1} at ${x} (${want[k]})`)); + for (const l of lines) { + const s = l.straight; + const first = Math.hypot(s[1].x - s[0].x, s[1].y - s[0].y), last = Math.hypot(s[s.length - 1].x - s[s.length - 2].x, s[s.length - 1].y - s[s.length - 2].y); + assert.ok(first >= 14 && last >= 14, `${n} lanes: the elbows start outside the zone (${first}, ${last})`); + // The lane's room outside the zone: its distance from either table less 14. + assert.ok(Math.min(l.pts[1].x - l.a.r, l.b.l - l.pts[1].x) - 14 >= 3.5, `${n} lanes: 3.5 or more outside the zone`); + } + } + warnings.length = 0; + await draw(page, [{ key: "lanes", spec: lanesSpec(4) }]); + assert.equal(await page.locator("#fig-lanes").getAttribute("data-layout"), "drawn", "a tight line never stacks the figure"); + const four = await readLines(page, "lanes"); + assert.equal(four.length, 3, "one line is left out"); + assert.ok(!four.some((l) => l.i === "3"), "the later in the author's order"); + assert.ok(warnings.some((w) => /a\.f3|a to b would need a fourth lane in a marked gutter/.test(w)), JSON.stringify(warnings)); + // Its row still writes the target. + assert.match(await page.locator(`#fig-lanes .${P}-node[data-node="a"] .${P}-row[data-row="3"] .${P}-ctype`).textContent(), /→ b/); + await page.close(); + }); +}); + +describe("the extended CIMIP schema", () => { + for (const theme of ["dark", "light"]) test(`${theme}: drawn at 1,104 with every key drawn, and at 1,096; its far keys pass through no table and every crossing is cut, before and during a trace`, async () => { + const { page, errors } = await figurePage({ theme }); + await draw(page, [{ key: "schema", spec: B.schema }]); + const keys = B.schema.tables.flatMap((t) => t.columns.filter((c) => c.references).map((c) => `${t.name}>${c.references.split(".")[0]}`)); + for (const w of [1104, 1096]) { + await widthTo(page, w); + const g = await inspect(page, "schema"); + assert.equal(g.layout, "drawn", `drawn at ${w}`); + assert.deepEqual(g.problems, [], `${w}: ${JSON.stringify(g.problems)}`); + assert.deepEqual(g.lines.map((l) => `${l.from}>${l.to}`).sort(), keys.slice().sort(), `${w}: every key is drawn`); + assert.ok(g.crossings.every((c) => c.cut), JSON.stringify(g.crossings)); + } + await widthTo(page, 1104); + // The far keys: approvals to incidents along the margin above, approvals to users along the gap between rows 2 and 3. + const lines = await readLines(page, "schema"); + const far = (to) => lines.find((l) => l.from === "approvals" && l.to === to && Math.abs(l.a.l - l.b.r) > 300); + const inc = far("incidents"), users = far("users"); + assert.ok(inc && users, "both far keys are drawn"); + const rects = await page.evaluate((P) => { const o = document.querySelector(`#fig-schema .${P}-drawing`).getBoundingClientRect(); return Object.fromEntries([...document.querySelectorAll(`#fig-schema .${P}-node`)].map((n) => { const r = n.getBoundingClientRect(); return [n.dataset.node, { t: r.top - o.top, b: r.bottom - o.top }]; })); }, P); + const runY = (l) => l.pts[2].y; + assert.ok(runY(inc) < rects.agent_runs.t, "approvals to incidents runs above the first row"); + assert.ok(runY(inc) > 0, "inside the drawing"); + assert.ok(runY(users) > rects.agent_runs.b && runY(users) < rects.sandboxes.t, "approvals to users runs in the gap between rows 2 and 3"); + // The rows: a margin corridor adds space-8 above the first row, the gap that carries a corridor is space-10, the other stays space-8, and no + // margin below. One lane in the gap's middle (space-3-5 clear of each side with two); the margin's lane space-4 above the first row. + const tracks = await page.evaluate((P) => getComputedStyle(document.querySelector(`#fig-schema .${P}-drawing`)).gridTemplateRows.split(" ").map(parseFloat), P); + assert.deepEqual([tracks.length, tracks[0], tracks[2], tracks[4], tracks[6]], [7, 32, 32, 40, 0]); + const gapTop = tracks[0] + tracks[1] + tracks[2] + tracks[3]; + assert.ok(Math.abs(runY(users) - (gapTop + 20)) <= 0.5, `one lane, in the gap's middle (${runY(users)}, ${gapTop})`); + assert.ok(Math.abs(rects.room_events.t - runY(inc) - 16) <= 0.5, "the margin's lane is space-4 out"); + assert.equal(rects.sandboxes.t, gapTop + 40); + // During a trace every crossing is still cut, the traced line on top. + await page.hover(`#fig-schema .${P}-node[data-node="approvals"]`); + await page.waitForTimeout(250); + const traced = await inspect(page, "schema"); + assert.deepEqual(traced.problems, [], JSON.stringify(traced.problems)); + assert.ok(traced.crossings.every((c) => c.cut)); + assert.deepEqual(errors, []); + await page.close(); + }); + + test("two arrivals at one key that state different things are 8px apart; the same thing shares a bus", async () => { + const { page } = await figurePage(); + await draw(page, [{ key: "two", spec: schema([ + table("a", 1, 1, [col("id", { key: "PK" }), fk("u", "b.id", "zero-or-many", "one")]), + table("c", 1, 2, [col("id", { key: "PK" }), fk("u", "b.id", "zero-or-many", "zero-or-one")]), + table("d", 1, 3, [col("id", { key: "PK" }), fk("u", "b.id", "zero-or-many", "one")]), + table("b", 2, 2, [col("id", { key: "PK" })]), + ]) }]); + const lines = await readLines(page, "two"); + assert.equal(lines.length, 3); + const tip = (from) => lines.find((l) => l.from === from).pts.at(-1); + assert.equal(tip("c").y - tip("a").y, 8, "the two statements arrive 8 apart"); + assert.equal(tip("a").y, tip("d").y, "the same statement shares its arrival"); + const lastX = (from) => lines.find((l) => l.from === from).pts.at(-2).x; + assert.equal(lastX("a"), lastX("d"), "and its bus"); + assert.notEqual(lastX("a"), lastX("c"), "a different statement takes its own lane"); + await page.close(); + }); + + test("a third line in one corridor is left out alone, and a development build names it", async () => { + const { page, warnings } = await figurePage({ dev: true }); + await draw(page, [{ key: "corr", spec: corridorSpec }]); + assert.equal(await page.locator("#fig-corr").getAttribute("data-layout"), "drawn"); + const lines = await readLines(page, "corr"); + assert.deepEqual(lines.map((l) => l.i).sort(), ["0", "1"], "the third, in the author's order, is left out"); + assert.ok(warnings.some((w) => /z to x would need a third lane in its corridor/.test(w)), JSON.stringify(warnings)); + const g = await inspect(page, "corr"); + assert.deepEqual(g.problems, []); + // Two lanes in the margin, space-4 and space-4 plus space-3 above the first row; the farther-going outermost (here: equal, so nested by its run). + const top = await page.evaluate((P) => { const o = document.querySelector(`#fig-corr .${P}-drawing`).getBoundingClientRect(); return document.querySelector(`#fig-corr .${P}-node[data-node="x"]`).getBoundingClientRect().top - o.top; }, P); + assert.deepEqual(lines.map((l) => Math.round(top - l.pts[2].y)).sort((p, q) => p - q), [16, 28]); + await page.close(); + }); +}); + +describe("the key, the list and the row", () => { + for (const theme of ["dark", "light"]) test(`${theme}: the key shows exactly the forms drawn, and none stacked; the list and the sentence carry the words; the row is unchanged`, async () => { + const { page } = await figurePage({ theme }); + await draw(page, [{ key: "schema", spec: B.schema }, { key: "half", spec: schema([table("a", 1, 1, [col("id", { key: "PK" }), fk("b_id", "b.id", "one", "one")]), table("b", 2, 1, [col("id", { key: "PK" })])]) }]); + const shown = (key) => page.evaluate(({ P, key }) => [...document.querySelectorAll(`#fig-${key} .${P}-entry`)].filter((e) => getComputedStyle(e).display !== "none").map((e) => e.textContent), { P, key }); + assert.deepEqual(await shown("schema"), ["PKPrimary key", "FKForeign key", "Exactly one", "Zero or one", "One or many", "Zero or many", "The table most of the others reference"]); + assert.deepEqual(await shown("half"), ["PKPrimary key", "FKForeign key", "Exactly one"], "only the forms drawn"); + // Each swatch is a 24px line carrying its form. + const sw = await page.evaluate((P) => [...document.querySelectorAll(`#fig-schema .${P}-swatch[data-card]`)].map((s) => [s.dataset.card, s.getAttribute("width"), !!s.querySelector(`.${P}-crow`), !!s.querySelector(`.${P}-ring`)]), P); + assert.deepEqual(sw, [["one", "24", true, false], ["zero-or-one", "24", true, true], ["one-or-many", "24", true, false], ["zero-or-many", "24", true, true]]); + // The list: "decided_by, foreign key, references users.id (zero or many approvals to zero or one users)". + const item = await page.evaluate((P) => [...document.querySelectorAll(`#fig-schema .${P}-list li`)].map((li) => li.textContent).find((t) => t.startsWith("decided_by")), P); + assert.equal(item, "decided_by, foreign key, references users.id (zero or many approvals to zero or one users)"); + const sentence = await page.locator(`#fig-schema .${P}-node[data-node="approvals"]`).getAttribute("aria-label"); + assert.match(sentence, /users \(decided_by: zero or many approvals to zero or one users\)/); + assert.match(await page.locator(`#fig-schema .${P}-node[data-node="users"]`).getAttribute("aria-label"), /approvals \(decided_by: zero or many approvals to zero or one users\)/); + // The row writes its target, as it did; no tag. + const row = await page.evaluate((P) => [...document.querySelectorAll(`#fig-schema .${P}-node[data-node="approvals"] .${P}-row`)].map((r) => r.textContent), P); + assert.deepEqual(row, ["PKidtext", "FKincident_id→ incidents", "FKrun_id→ agent_runs", "FKdecided_by→ users", "commandtext", "risklow | medium | high", "statuspending"]); + // Stacked: no lines, so no marks, and the key keeps the foreign key's arrow. + await widthTo(page, 390); + assert.equal(await page.locator("#fig-schema").getAttribute("data-layout"), "stacked"); + const stacked = await shown("schema"); + assert.ok(!stacked.some((t) => /Exactly one|Zero or|One or many/.test(t)), JSON.stringify(stacked)); + assert.ok(stacked.includes("→The table a foreign key references"), JSON.stringify(stacked)); + assert.equal(await page.locator(`#fig-schema .${P}-drawing .${P}-crow`).count(), 0); + await page.close(); + }); +}); + +describe("modes", () => { + test("forced colours: the marks follow their line and a ring's fill is Canvas; print: the resting ink over a trace", async () => { + const { page } = await figurePage(); + await draw(page, [{ key: "forms", spec: formsSpec }]); + await page.emulateMedia({ forcedColors: "active" }); + await frames(page, 3); + let l = (await readLines(page, "forms"))[1]; + assert.equal(l.fromEnd.stroke, l.stroke); + assert.equal(l.toEnd.ringFill, await page.evaluate(() => { const d = document.createElement("div"); d.style.color = "Canvas"; document.body.append(d); const c = getComputedStyle(d).color; d.remove(); return c; })); + await page.emulateMedia({ forcedColors: "none", media: "print" }); + await page.hover(`#fig-forms .${P}-node[data-node="a"]`); + await frames(page, 3); + const rest = await page.evaluate(() => getComputedStyle(document.querySelector("#fig-forms")).getPropertyValue("--basalt-diagram-edge").trim()); + l = (await readLines(page, "forms"))[0]; + const probe = await page.evaluate((c) => { const d = document.createElement("div"); d.style.color = c; document.querySelector("#fig-forms").append(d); const v = getComputedStyle(d).color; d.remove(); return v; }, rest); + assert.equal(l.fromEnd.stroke, probe, "printed untraced, in the resting ink"); + await page.close(); + }); +}); + +describe("development errors", () => { + test("cardinality without references, a referenced end of many, and some keys stated and not all", async () => { + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const warns = (tables) => core.buildModel(schema(tables)).warnings; + const b = table("b", 2, 1, [col("id", { key: "PK" })]); + assert.ok(warns([table("a", 1, 1, [{ name: "x", cardinality: { from: "one" } }]), b]).some((w) => /a\.x states a cardinality but references nothing/.test(w))); + assert.ok(warns([table("a", 1, 1, [fk("x", "b.id", "one", "one-or-many")]), b]).some((w) => /references one row at most/.test(w))); + assert.ok(warns([table("a", 1, 1, [fk("x", "b.id", "one"), fk("y", "b.id")]), b]).some((w) => /stated on 1 of 2 foreign keys.*a\.y has none/.test(w))); + assert.ok(warns([table("a", 1, 1, [fk("x", "b.id", "many")]), b]).some((w) => /not one, zero-or-one, one-or-many or zero-or-many/.test(w))); + // None of them in a figure that states every key. + assert.deepEqual(core.buildModel(B.schema).warnings, []); + // The referenced end defaults to one. + assert.deepEqual(core.buildModel(schema([table("a", 1, 1, [fk("x", "b.id", "zero-or-many")]), b])).edges[0].card, { from: "zero-or-many", to: "one" }); + }); + test("production: an unstated line in a figure that states some draws as today, and the key shows both", async () => { + const { page } = await figurePage(); + await draw(page, [{ key: "mixed", spec: schema([table("a", 1, 1, [fk("x", "b.id", "one"), fk("y", "b.k")]), table("b", 2, 1, [col("id", { key: "PK" }), col("k")])]) }]); + const lines = await readLines(page, "mixed"); + assert.deepEqual(lines.map((l) => [l.tip, l.dot, !!l.fromEnd]), [[false, false, true], [true, true, false]]); + const shown = await page.evaluate((P) => [...document.querySelectorAll(`#fig-mixed .${P}-entry`)].filter((e) => getComputedStyle(e).display !== "none").map((e) => e.textContent), P); + assert.deepEqual(shown, ["PKPrimary key", "FKForeign key", "A foreign key", "Exactly one"]); + await page.close(); + }); +}); From 76489778c6e5d20b99af207e1f48036923394e81 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:35:51 -0600 Subject: [PATCH 38/62] The rest of section 6 in foundations (6.2 to 6.12, 6.16), and cardinality and far keys in AGENTS.md Foundations: the ports and two-line labels (6.2), the end gutter's lanes, several entries into one card and automatic layout (6.3, with DECISIONS 322's sentence on ways, a decision's points and turn-backs), the four type bullets (6.4), the key's built-in forms and operators (6.5), the spatial keys, link cards and the touch trace (6.6), first visit, dashed flow and the text sequence's build (6.7), marks on steps and participants (6.8), forced colours, print and right to left (6.9), the two tokens and what is not a token (6.10), the print theme (6.11), the activation bar and a frame's sides as vertical lines (6.12), and the viewer in Lists and modals and Icons (6.16; Icons says "Expand" is built with words only for now, the deviation the PR records). The opening no longer says cardinality and far keys are not built. AGENTS.md: the schema sentence of 6.14, and the "not built yet" note goes. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 5 ++- docs/foundations.md | 106 +++++++++++++++++++++++++++++++++----------- 2 files changed, 83 insertions(+), 28 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 592c451d..dd2f8508 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -198,14 +198,15 @@ Basalt has one owner (Bailey) and a design panel of two independent design revie (the faces arriving, a resize) never restarts, hides or cuts short an entrance. An architecture card may carry its service's own mark, 16px in the top end corner: the owner's file, never recoloured, a form for each ground, decoration beside the name, recorded in `packages/react/marks/manifest.json`; a service without one is its name alone. In print a mark prints, and so does the fill of a - focal node that carries one (`print-color-adjust: exact`). A sequence may show a participant working (a bar) and frame a run of messages + focal node that carries one (`print-color-adjust: exact`). A schema may state how many (crow's foot in the line's ink, on every key or none) and + draws far keys along a corridor. A sequence may show a participant working (a bar) and frame a run of messages (`opt`, `loop`, `alt`: structure, never a panel, every word plated), and may be written as text art, which never hides a line and has no caret. Groups nest two deep; four end lanes at most. A card may be a link (the card is the stop; the arrow is the cue). A label breaks only where its author breaks it. Arrow keys are spatial, on tracks. On touch a tap traces and "Clear highlight" clears. In print a figure is untraced and light. Right to left mirrors the figure, not the words. Automatic layout asks elkjs for a column and a row and nothing else; Basalt routes, and a figure is never scaled. elkjs loads on demand or not at all: place at build time. "Expand" opens the viewer: the drawn layout in a dialog (full screen under 720), laid out at 100% and zoomed by the reader with one transform, from Fit or 100% to 400%, in steps that land at once; it pans by scrolling; it - is never a picture, a `viewBox` or CSS `zoom`; it is still, and it does not print. Cardinality and far keys (DECISIONS 306, 1.1) are not built yet. + is never a picture, a `viewBox` or CSS `zoom`; it is still, and it does not print. - **Type:** Geist and Geist Mono at 400, 500 and 600 only, and a `Geist Fallback` face (local Arial, one face per weight) that reduces the shift when Geist arrives; it does not promise the same wrap at every width. - **Display type:** two roles a page writes, hero (96/96; 72/76 from 720 to 1023; 44/48 under 720) and display (72/76; 56/60; 36/40), made of the fixed diff --git a/docs/foundations.md b/docs/foundations.md index 8c912f1a..2a5e3a65 100644 --- a/docs/foundations.md +++ b/docs/foundations.md @@ -62,7 +62,8 @@ levels changed no pixel. Dark steps up from true black in small increments, as Linear does. Nothing above the page is pure black, so large moving surfaces never smear on OLED (pixels at `#000` switch fully off and lag when they turn back on). Light sits the page just below white, as Vercel does, -so white cards lift without a shadow. +so white cards lift without a shadow. In print the tokens are the light set, whatever theme the screen shows: the tokens build writes +it, and an app that prints dark on purpose overrides it. **Depth is by level, and the level is not a prop.** It is a private context, rendered as `data-level`, that crosses portals as the modal depth does: @@ -1460,8 +1461,8 @@ Basalt allows a short list of vertical lines. Each is structure, and none is a s ruling against the vertical bar is about marks): the 1px divider at a pinned table column's edge while the table is scrolled, the app sidebar's 1px edge, a meter's labelled target tick, the vertical `Separator` between groups of controls (1px `border-divider`, as tall as the controls), the edges between a `NumberField`'s value and its steppers (part of the -field's own boundary), a diagram's connector (a line that joins two nodes and ends in a head, with its stems, rails and buses) and a -sequence diagram's lifeline. A connector is never drawn without both its nodes and its head, and neither is ever a mark of state. +field's own boundary), a diagram's connector (a line that joins two nodes and ends in a head, with its stems, rails and buses), a +sequence diagram's lifeline and the activation bar on it, and a frame's sides. A connector is never drawn without both its nodes and its head, and neither is ever a mark of state. Status: decided by the council and approved by the owner (DECISIONS 138 and 139); the diagram's connector and lifeline decided by the council (DECISIONS 281, a handoff); the implementation hasn't been reviewed. @@ -1684,8 +1685,8 @@ owner's prototype, one draft, a check and a decision, revised after the final po The parts of DECISIONS 301 (cardinality and far keys, activations and frames, the text art, nested groups, four end lanes, link cards, two-line labels, spatial keys, a trace on touch, marks on steps and participants, right to left, export and automatic layout) were -decided by the council from two drafts and a check (DECISIONS 306, revised by 313). **Status:** the implementation has not been reviewed, -and cardinality and far keys are not built yet. Automatic layout leads with build time: place with `placeDiagram` and pass `placement`, and +decided by the council from two drafts and a check (DECISIONS 306, revised by 313). **Status:** the implementation has not been reviewed. +Automatic layout leads with build time: place with `placeDiagram` and pass `placement`, and elkjs (EPL-2.0 OR GPL-3.0-or-later, used under EPL-2.0) never reaches the browser. **The idea: the words are in the boxes, the lines say how they connect, and the key says what each line means.** A diagram is @@ -1712,12 +1713,15 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b - Lines are orthogonal, with elbows of 8 or half the shorter leg. One head, `size-diagram-head`, at the far end. A line ends on the shape drawn, not on its box. A 1px line sits on half pixels, a 2px line on whole ones, and a head snaps with its line. - **Ports are derived.** Nodes in a row or a column face each other; otherwise a line leaves sideways and enters from above or below. - A side's one line is at its middle; a straight line keeps the middle and others take the quarter points. An author names a side only - to change that. + A side's one line is at its middle. A straight line keeps the middle; one other takes the quarter point toward its far end, and + two or more share that half evenly. A port is on the flat part of its side, never nearer a corner than the corner's radius, and + two ports on a side are at least `size-diagram-head` apart: a card whose side holds more than its height allows grows to the least + height at which both hold (48 for a straight line and two others), and its row takes that height. A side never stacks a figure. An + author names a side only to change that. - **Crossings:** place to avoid them; lines to one port share one lane and join; of two bypasses from one side, the farther-going leaves higher and takes the outer lane. A crossing that is left is cut: the line underneath breaks `size-cut` each side of the one on top. The horizontal run is on top, and a traced line is on top of an untraced one. -- **A label** is `text-xs` Mono in secondary ink, one line, never cut. On its own line it has a ground-colour plate; beside its line +- **A label** is `text-xs` Mono in secondary ink, one line, or two where the author writes a break (never a break of the engine's), never cut. On its own line it has a ground-colour plate; beside its line it is `space-2` clear of the stroke. Seats are taken along the run's clear shaft (the run without its head). A seat is taken only if the label, grown `space-1`, overlaps no node as drawn (the diamond or the capsule, not its box), label, head, boundary, rule or other line. A seat is measured from its line's place before the half-pixel snap, so whether it fits never turns on which way a half pixel @@ -1730,9 +1734,19 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b and no line passes through a node. Otherwise the figure is stacked. This is a measured fit, not a breakpoint. - **Stacked** is one column in the author's order, at most 480 wide (`size-breakpoint-container`) on the start edge. Architecture and flowchart are a spine with indented branches: a rail and a trunk at the start, one lane at the end, every route taken from the order. - A line that leaves or passes a spine card runs in an end gutter outside the cards (`space-10`, two lanes at most), down into a card's - top or up into its bottom. A data flow is its steps in order with bypasses in that gutter. A sequence is a strip of participants and a numbered list that names each message's sender, + A line that leaves or passes a spine card runs in an end gutter outside the cards (lanes `space-3-5` apart, four at most; the gutter is + its lanes and `space-3`), down into a card's top or up into its bottom. A data flow is its steps in order with bypasses in that gutter. A sequence is a strip of participants and a numbered list that names each message's sender, receiver and kind. A schema is its cards in an auto-fit grid with no lines, because every foreign-key row writes its target. +- **Several end lines into one card nest:** the line from the outermost lane turns lowest and enters nearest the end edge; each + line from a lane further in turns `space-5` higher and enters `space-3` further in. Their labels are seated `space-2-5` clear of + the innermost entry, each on its own turn's height, taken before the half-pixel snap. +- **Automatic layout** (`layout: "auto"`): the author leaves placement out and elkjs gives each card a column and a row. Nothing + else of elk's is read. Basalt sizes, routes, seats and stacks the figure as it does an authored one, and chooses each line's sides + from its router's four shapes, the line with the fewest clean shapes first. A main line that passes a layer keeps a way there: + cells no card takes. A decision's point that a line leaves takes no other line, and a line turns back only where there is a gutter + (DECISIONS 322). It tries the type's direction, then the other, then + stacks; a figure is never scaled. A `col` or `row` left on a card is not read: there are no hints. elkjs is loaded on demand, or + not at all where `placement` is given; the HTML skill places at build time. - **A stack that would still overlap draws no lines** (the decider's answers, review round 64): a drawing known to overlap is never drawn, and all its lines go, not some. It is dressed as where scripting is off: no line in the key, no key hint, no roving stops, and the list open (the toggle stays and reads "Hide the list"). This is the one exception to every edge and label being present at every width; a development @@ -1741,23 +1755,37 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b ### The types -- **Architecture:** a group is a transparent box with a 1px dashed `diagram-structure` edge, radius 12, its label at the top start. Its - extent is its members'. One level of grouping. +- **Architecture:** a group is a transparent box with a 1px dashed `diagram-structure` edge, radius 12, its label at the top start. + Its extent is its members'. A group may hold groups, two levels in all; an inner group is `space-4` inside the outer and radius 8. - **Flowchart:** shape carries type: a step is the box, a start or end a capsule, a decision a diamond behind its words. **Every flowchart shape has a 1px `diagram-structure` contour** in place of the rim, because the shape has to be seen at 3:1. A decision is - at least `space-16` tall and never flatter than 5:1. + at least `space-16` tall and never flatter than 5:1. A decision is never taller than it is wide: a width at which one would be is not + a width the flowchart is drawn at. - **Data flow:** lanes are bands ruled apart with the divider, named at the start. A node's kind line is its step number. - **Sequence:** a head per participant; a lifeline is 1px `diagram-structure`, dashed 4 on 4 off; a message is a 56px row with its number and label above the line and a note below, on plates that mask the lifelines; a self-call is a small loop; a reply is dashed; - a band is a ruled line of words, never a frame. + a band is a ruled line of words. **A bar** on a lifeline (`size-diagram-activation`, the head's fill, a 1px `diagram-structure` + edge) shows a participant working, from the message that starts it to the one that ends it. **A frame** (`opt`, `loop`, `alt`) is a + transparent box round a run of messages, 1px solid `diagram-structure`, radius 12, as wide as the participants inside it: structure, + never a panel. Its operator is in a tab at its top start, its condition beside it, and an `alt`'s later branches start under a + dashed rule and the word `else`. Every word of a frame is plated. Frames nest two deep. In a run, messages not yet reached are + quiet: label `text-secondary`, line `diagram-edge-dim`. **As text** (`variant: "text"`) the same data is box-drawing characters in a + code block, and a transcript where the art does not fit; it never scrolls sideways, no character is written over a word, and no + line is ever hidden. - **Schema:** a table is a card with a header band and 28px rows (a key seat, the name, the type or "→ table"). A foreign key is a - plain line from a dot on its row to a head on the referenced row. It comes from the column's own record. + plain line from a dot on its row to a head on the referenced row. It comes from the column's own record. Where the author states + how many (`cardinality`, on every foreign key or none), the dot and the head give way to crow's-foot marks in the line's ink, inside + `size-diagram-foot` at each end, and the column gap is `space-12` plus `space-3`: three lanes at most, none nearer a table than the + zone plus `radius-xs`. A key two or more columns away is drawn along a corridor: a row gap clear of the tables between, or the margin + above or below. A line that cannot be drawn clean is left out alone, and its row still writes the target. ### The key, the summary and the list - The key is under the drawing and is built from the marks actually drawn, each swatch drawn like its mark. The author writes the words. Main, dashed and the focal node must have them. A schema's key starts with the key seats it uses, the letters set as the - seat sets them, then "Primary key" and "Foreign key" (built in; the decider's answers, review round 64). + seat sets them, then "Primary key" and "Foreign key" (built in; the decider's answers, review round 64). A schema that draws + cardinality shows each form drawn ("Exactly one", "Zero or one", "One or many", "Zero or many"), and a sequence each frame operator + drawn, the letters set as the tab sets them ("Only if", "Repeats", "One of these"): built in, because they are notation. - The summary is required. "View as list" opens the same facts as real lists in the same figure: the parts and connections, a flowchart's steps with each exit written once, a data flow's steps, a sequence's messages, a schema's tables. - The figure's words are in the HTML before script runs, and where scripting is off the list is open. Before script the figure is @@ -1768,10 +1796,17 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b - Where lines are drawn the drawing is one tab stop: a `role="group"` with `aria-roledescription="diagram"`, named by the title and described by the summary and a sentence about the keys. Each node is a focusable `role="img"` named by a sentence that says what it - is, where it sits, and what it connects from and to. → ↓ the next, ← ↑ the one before, Home and End the ends, Esc clears. No live - region. The SVG is `aria-hidden`. A layout change keeps focus on the same node, and never moves it, even into a stack with no stops. + is, where it sits, and what it connects from and to. → ↓ ← ↑ move to the nearest part in that direction: first a part in the same row + or column, then the lowest of tracks along the arrow plus twice the tracks across it. The rule runs on a part's column and rows, + never on its measured centre, and a figure whose parts cannot all be reached that way keeps the author's order. Stacked, the keys + are the author's order. Home and End the ends, Esc clears. No live region. The SVG is `aria-hidden`. A layout change keeps focus on the same node, and never moves it, even into a stack with no stops. - **Tracing** a node (hover, or keyboard focus) lifts its lines to primary ink and dims the rest to `diagram-edge-dim`. It changes ink - and never weight, dash or head, so the key stays true. There is no trace on touch, and a node is not a target. + and never weight, dash or head, so the key stays true. +- **A card may be a link** (`href`): the card is the link and the figure's roving stop, Enter follows it, and its cue is the arrow + after its name ([Links and rows](#links-and-rows)); a press is a colour step. +- **On touch a tap traces,** where lines are drawn. It clears by a tap on the same card, a tap on the ground or "Clear highlight", a + button that stays in the foot and is `aria-disabled` until a trace is up. A hint line says so. A card that answers a tap is at + least 44px tall. A linked card follows its link and is never traced by a tap. Nothing is announced. - A diagram is still unless its author asks for motion (`motion="animated"`); see [Motion in a diagram](#motion-in-a-diagram). A trace's ink changes over `duration-fast`, at once under reduced motion. @@ -1810,7 +1845,9 @@ Still is the default and is the drawing above, unchanged. Animated adds an entra or a packet. Motion never carries a fact alone, and it runs only where lines are drawn. - **The entrance plays when the figure comes into view** (two fifths of the drawing, or of the window for a taller one), once a figure - a page load, on every figure that asks for it. It is not the page's one entrance and is not stored between visits. + a page load, on every figure that asks for it. It is not the page's one entrance and is not stored between visits, unless the figure + asks for `entrance: "first-visit"`: then a mark is stored when an entrance that played finishes or gives way to the reader, and later + visits are at rest. A visit at rest by mode stores nothing. - **Trace:** each line draws along its length at `speed-diagram-trace`, between `duration-diagram-line-min` and `-line-max`, on `ease-in-out`, in the author's order (a schema's by where each starts), `duration-diagram-stagger` apart. A head fades in over `duration-slow` as its line is 85% drawn. Each line is revealed on its own. @@ -1824,9 +1861,10 @@ or a packet. Motion never carries a fact alone, and it runs only where lines are - **Measured again** (the faces arriving, a change of width, a parent's render), a figure whose lines are the same is not written to; a pending figure stays pending on its new lines; a running entrance carries on, on the new lines, from the clock it started on, with every line that was whole still whole; a layout with no lines is at rest. A loop starts again on the new lines. -- **Flow** (`flow` on a main or plain edge): cuts of `size-cut` in the ground colour every `size-diagram-flow` march toward the head at +- **Flow** (`flow` on an edge): cuts of `size-cut` in the ground colour every `size-diagram-flow` march toward the head at `speed-diagram-flow`. Cuts exist only while they move: held, traced, still and printed, the line is solid, so the key stays true. A line - with under 48px showing does not flow. + with under 48px showing does not flow. A dashed line's own dashes march, one period every 625ms, and sit where the key draws them + whenever they are not moving. - **Pulse** (`pulse`, a route of nodes): a solid bead of `size-diagram-bead`, at most two fifths of the line showing, one hairline proud of its line on each side, at `speed-diagram-pulse`. It leaves from a card's edge and is taken in at the line's end, rests `duration-diagram-rest` at each card, and starts again `duration-diagram-pause` after the route. @@ -1841,6 +1879,8 @@ or a packet. Motion never carries a fact alone, and it runs only where lines are `data-loops="held"` clears them to rest. A figure that can loop draws "Pause animations", the hold's own button (`LoopsToggle`'s Button form at `size="sm"`), in its foot after "View as list" (WCAG 2.2.2). A trace stops them; they start again `duration-diagram-pause` after it ends. Neither motion button prints. +- **A text sequence** builds by ink: a message's label and arrow lift to their resting ink at its turn. No line is hidden and there is + no caret. - **A sequence's run** (`run`): "Play the run" sends one packet through every message in order. It may pass five seconds; while it runs the button reads "Stop the run" and stops it. The hold does not stop it. - **Reduced motion:** the figure is still; a run steps through its messages by colour alone. **Forced colours:** the figure is still; a @@ -1851,8 +1891,9 @@ or a packet. Motion never carries a fact alone, and it runs only where lines are Decided by the council for the owner's handoff (DECISIONS 287 to 291 and 292). **Status:** the implementation has not been reviewed. -An architecture card may carry its service's own mark: 16px (`size-icon-sm`), in the top end corner inside the padding, with nothing -behind it. The card's first line keeps `space-6` clear of it. +An architecture card, a data flow's step and a sequence's participant may carry its service's own mark: 16px (`size-icon-sm`), in the top end corner inside the padding, with nothing +behind it. The card's first line keeps `space-6` clear of it. A participant's head keeps `space-6` clear on both sides, so its name stays +over its lifeline; a stacked chip draws the mark before the name. - **A mark is its owner's file and Basalt never recolours it.** It has a form for light grounds and a form for dark grounds; a card takes the form for its ground, and the focal card the other theme's. A one-colour mark with one published file and no rule against it gets its @@ -1881,6 +1922,11 @@ behind it. The card's first line keeps `space-6` clear of it. the input boundary and do not step. - Print: the lines, the key's swatches, a card's mark and every focal node's fill (with a mark or without, DECISIONS 298) print whatever the reader's "Background graphics" setting (`print-color-adjust: exact`, with the `-webkit-` form). +- Forced colours: cardinality marks follow their line; an activation's edge is `CanvasText`; a frame's edges are `GrayText`; a + linked name is `LinkText`, underlined. +- Print: a figure prints untraced, in its resting ink, and in the light theme whatever the screen shows. +- Right to left: the figure mirrors and its words do not. Identifiers are isolated left to right as runs; named sides swap; the + arrow keys stay physical; the text art stays left to right. ### Diagram tokens @@ -1902,6 +1948,8 @@ behind it. The card's first line keeps `space-6` clear of it. | `size-diagram-step` | 56px | A sequence's message row | | `size-diagram-head` | 8px | An arrowhead's length and its width | | `size-diagram-guide-dash` | 4px | A lifeline's dash, on and off | +| `size-diagram-activation` | 8px | An activation bar's width | +| `size-diagram-foot` | 14px | The room of a cardinality mark at a line's end | The motion tokens (DECISIONS 292). The motion tokens do not collapse under reduced motion: nothing they time runs there. @@ -1931,7 +1979,9 @@ Under more contrast `diagram-focal-rule` is drawn as `diagram-focal-rule-contras theme's input boundary, 1.18), the way the other aliases of that mode are declared. **Not tokens, by choice:** the gaps, the rail (`space-3`), the trunk (`space-8`), the branch indent (`space-12`), the entry inset -(`space-6`), the end gutter (`space-10`, lanes at `space-3-5`) and the quarter-point slots are rules made of the space scale. +(`space-6`), the end gutter (lanes at `space-3-5`, four at most), the turn stagger (`space-5`), the schema's gap where marks are drawn +(`space-12` plus `space-3`), a corridor's lanes (`space-3`), the viewer's zoom steps and limits (ratios, the reader's) and the +quarter-point slots are rules made of the space scale. ## Layout @@ -2264,7 +2314,8 @@ A product's own logo is its own; the social marks are Phosphor's (below). A diag - **Which set draws a glyph.** Wherever a component draws check, close, the chevrons, copy, plus, minus or search, it draws the core set's glyph; Phosphor Bold draws what the core set lacks (the status marks, the sort caret, the social - marks), and the key glyphs ⌘ ⌥ ⌃ stay Phosphor's. A component never draws Phosphor's version of a core glyph. **Status:** decided by the + marks, a diagram's "Expand", `ArrowsOutSimple`, until the core set draws one; built with words only for now, a deviation the + diagrams PR records), and the key glyphs ⌘ ⌥ ⌃ stay Phosphor's. A component never draws Phosphor's version of a core glyph. **Status:** decided by the council (DECISIONS 138) and approved by the owner (DECISIONS 139); the implementation has not been reviewed. - **Drawing.** Actions are exactly three straight lines (copy, edit, trash and download are the agreed exceptions, drawn richer). Every other glyph is eight cubic slots on the 24 grid, and an @@ -2420,6 +2471,9 @@ form of a column the page docks when it is wide enough, and it opens from the si from the bottom of the screen. The top `Sheet` stays the site's narrow menu. (The owner's DECISIONS 222: lists are paginated with a choice of how many to show, and can be filtered; a form or task opens as a centered modal over a darkened page, not a side panel.) +A diagram's viewer is not a task: it is a figure at the window's size ([Diagrams](#the-viewer)). It uses the dialog's box and the +full-screen modal under 720, and the scrim always closes it. + ### Everything that changes a list sits above it The filters come first (`FilterToolbar`), then one band (`ListBand`) with the count, the pager and the page size. Only the rows below change, so nothing above can be pushed. A bar From 38323708efb11ef9d4163013bf2f4f237348f33f Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:36:03 -0600 Subject: [PATCH 39/62] Automatic layout by the decider's ruling (DECISIONS 322): a main line keeps a way, and both CIMIP figures draw placeDiagram (from the ruling's reference, auto-ruling/ruled): network simplex node placement with a straightness priority of 10 on main lines and on each link of a way; a card with three or more leaving lines, one main, hands elk the main one in the middle; a main line two or more layers long is placed again as a chain of boxes, one a layer, grouped by the ruling's rule, and the boxes are read for bands and left out, with the second run kept only if it is usable and adds no layer. A placement carries cols and rows (optional), and the model's tracks are the larger of those and the cards' own; the HTML skill's placer writes them as placeDiagram returns them. The side choice: a decision's point that a line leaves takes no other line, and a line arrives only where none leaves; sides the author named count first; a turn-back is a shape only where a track lies beyond its side. When no direction draws and one had the width, a development build warns once for a figure and its reasons, each direction's reason given; a label's break is a space in a warning. Already decided, not built: the viewer's figure takes the placements the page loaded, and on a phone, where the page's figure is stacked and loaded nothing, it loads them itself (it is laid out at its least drawn width). 9.3's larger-Fit direction choice was already in (a7cb4357). A dropped line's reasons are written only in a development build (diagram-fixes found them in production). diagram-layout.test.mjs: the ruling's list, on its proof figures (fixtures/diagram-layout.json): the cells, cols and rows of proof/cells-ruled.json on five fresh runs in Node and in the browser; the graph (network simplex, straightness on main lines only, no partitioning, at most two layouts a direction); a way-only track; at 1104 the architecture in 4 columns and the flowchart in 3 with every line and label and no geometry problem, and each stacked when named right; drawn at every 16px from 800 and 720 to 1,440; rule 3 on given cells and a named side counted; rule 4 right to left; rule 5's one warning; the viewer with no placement at 1440 by 900 (laid right) and 390 by 844 (laid down). Co-Authored-By: Claude Opus 5.5 --- .../basalt-html/parts/diagram-place.mjs | 110 +- .agent/skills/basalt-html/parts/diagram.js | 24 +- packages/react/src/diagram-core.ts | 52 +- packages/react/src/diagram-figure.tsx | 31 +- packages/react/src/diagram-layout.ts | 134 +- packages/react/test/diagram-layout.test.mjs | 250 +++ .../react/test/fixtures/diagram-layout.json | 1478 +++++++++++++++++ 7 files changed, 2021 insertions(+), 58 deletions(-) create mode 100644 packages/react/test/diagram-layout.test.mjs create mode 100644 packages/react/test/fixtures/diagram-layout.json diff --git a/.agent/skills/basalt-html/parts/diagram-place.mjs b/.agent/skills/basalt-html/parts/diagram-place.mjs index e19ffbd9..5ebc5796 100644 --- a/.agent/skills/basalt-html/parts/diagram-place.mjs +++ b/.agent/skills/basalt-html/parts/diagram-place.mjs @@ -33,6 +33,7 @@ import { workerData } from "node:worker_threads"; // packages/react/src/diagram-layout.ts var W = 200; var H = 80; +var STRAIGHT = "10"; var options = (direction) => ({ "elk.algorithm": "layered", "elk.direction": direction === "right" ? "RIGHT" : "DOWN", @@ -40,15 +41,37 @@ var options = (direction) => ({ "elk.hierarchyHandling": "INCLUDE_CHILDREN", "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES", "elk.layered.cycleBreaking.strategy": "MODEL_ORDER", - "elk.layered.nodePlacement.strategy": "BRANDES_KOEPF", + "elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX", "elk.layered.spacing.nodeNodeBetweenLayers": "64", "elk.spacing.nodeNode": "48", "elk.edgeRouting": "ORTHOGONAL" }); -function elkGraph(input, direction) { - const cards = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name), group: void 0 })) : (input.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); - const edges = input.type === "schema" ? (input.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0] }))) : (input.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to) })); - const groups = input.type === "architecture" ? input.groups ?? [] : []; +function partsOf(input) { + const cards = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name) })) : (input.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); + const raw = input.type === "schema" ? (input.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0], main: false }))) : (input.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to), main: e.kind === "main" })); + const ids = new Set(cards.map((c) => c.id)); + const lines = raw.filter((e) => ids.has(e.from) && ids.has(e.to)).map((e, k) => ({ ...e, k })); + return { cards, lines, groups: input.type === "architecture" ? input.groups ?? [] : [] }; +} +function mainInTheMiddle(lines) { + const bySource = /* @__PURE__ */ new Map(); + lines.forEach((e, k) => { + if (!bySource.has(e.from)) bySource.set(e.from, []); + bySource.get(e.from).push(k); + }); + const out = lines.slice(); + for (const slots of bySource.values()) { + const main = slots.filter((k) => lines[k].main); + if (slots.length < 3 || main.length !== 1) continue; + const rest = slots.filter((k) => k !== main[0]); + const order = [...rest.slice(0, Math.floor(rest.length / 2)), main[0], ...rest.slice(Math.floor(rest.length / 2))]; + slots.forEach((slot, j) => { + out[slot] = lines[order[j]]; + }); + } + return out; +} +function graphOf(cards, lines, groups, direction) { const kids = /* @__PURE__ */ new Map([["", []]]); for (const g of groups) kids.set(g.id, []); for (const c of cards) (kids.get(c.group ?? "") ?? kids.get("")).push({ id: c.id, width: W, height: H }); @@ -57,8 +80,7 @@ function elkGraph(input, direction) { const box = { id: `group:${g.id}`, children: kids.get(g.id), layoutOptions: { "elk.padding": "[top=32,left=16,bottom=16,right=16]" } }; (g.parent && kids.has(g.parent) ? kids.get(g.parent) : children).push(box); } - const ids = new Set(cards.map((c) => c.id)); - return { id: "root", layoutOptions: options(direction), children, edges: edges.filter((e) => ids.has(e.from) && ids.has(e.to)).map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to] })) }; + return { id: "root", layoutOptions: options(direction), children, edges: lines.map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to], ...e.main ? { layoutOptions: { "elk.layered.priority.straightness": STRAIGHT } } : {} })) }; } function absolute(node, ox = 0, oy = 0, out = /* @__PURE__ */ new Map()) { for (const c of node.children ?? []) { @@ -84,17 +106,83 @@ function bands(rects, lo, hi) { return out; } var elkMade; -async function placeDiagram(input, direction) { +async function cellsOf(graph) { if (!elkMade) { const mod = await Promise.resolve().then(() => (init_diagram_elk(), diagram_elk_exports)); elkMade = new mod.default(); } - const laid = await elkMade.layout(elkGraph(input, direction)); - const rects = absolute(laid); + const rects = absolute(await elkMade.layout(graph)); const col = bands(rects, (r) => r.x, (r) => r.x + r.w), row = bands(rects, (r) => r.y, (r) => r.y + r.h); const cells = {}; for (const id of rects.keys()) cells[id] = { col: col.get(id), row: row.get(id) }; - return { direction, cells }; + return cells; +} +function unusable(cards, groups, cells) { + const seen = /* @__PURE__ */ new Set(); + for (const c of cards) { + const at = cells[c.id]; + if (!at) return true; + const key = `${at.col},${at.row}`; + if (seen.has(key)) return true; + seen.add(key); + } + const chain = (id) => { + const out = []; + for (let g = id; g; g = groups.find((x) => x.id === g)?.parent) out.push(g); + return out; + }; + for (const g of groups) { + const mine = cards.filter((c) => chain(c.group).includes(g.id)); + if (!mine.length) continue; + const at = mine.map((c) => cells[c.id]); + const box = { c1: Math.min(...at.map((a) => a.col)), c2: Math.max(...at.map((a) => a.col)), r1: Math.min(...at.map((a) => a.row)), r2: Math.max(...at.map((a) => a.row)) }; + if (cards.some((c) => !mine.includes(c) && cells[c.id].col >= box.c1 && cells[c.id].col <= box.c2 && cells[c.id].row >= box.r1 && cells[c.id].row <= box.r2)) return true; + } + return false; +} +async function placeDiagram(input, direction) { + const { cards, lines: authored, groups } = partsOf(input); + const lines = mainInTheMiddle(authored); + const first = await cellsOf(graphOf(cards, lines, groups, direction)); + const layer = (id) => direction === "down" ? first[id].row : first[id].col; + const chain = (id) => { + const out = []; + for (let g = id; g; g = groups.find((x) => x.id === g)?.parent) out.push(g); + return out; + }; + const groupOf = new Map(cards.map((c) => [c.id, c.group])); + const all = cards.slice(); + const chained = []; + let ways = 0; + for (const e of lines) { + const a = layer(e.from), b = layer(e.to); + if (!e.main || Math.abs(b - a) < 2) { + chained.push(e); + continue; + } + const inA = chain(groupOf.get(e.from)), inB = chain(groupOf.get(e.to)); + const both = inA.find((g) => inB.includes(g)); + const boxes = []; + let prev = e.from; + for (let l = a + Math.sign(b - a); l !== b; l += Math.sign(b - a)) { + const id = `way:${e.k}:${l}`; + const here = new Set(cards.filter((c) => layer(c.id) === l).flatMap((c) => chain(c.group))); + const group = inB.find((g) => here.has(g)) ?? inA.find((g) => here.has(g)) ?? both; + boxes.push({ id, group, way: true }); + chained.push({ ...e, from: prev, to: id }); + prev = id; + } + chained.push({ ...e, from: prev }); + all.splice(all.findIndex((c) => c.id === e.to), 0, ...boxes); + ways++; + } + const span = (c) => ({ cols: Math.max(...Object.values(c).map((x) => x.col)), rows: Math.max(...Object.values(c).map((x) => x.row)) }); + if (!ways) return { direction, ...span(first), cells: first }; + const second = await cellsOf(graphOf(all, chained, groups, direction)); + const cells = {}; + for (const c of cards) cells[c.id] = second[c.id]; + const layers = (c) => Math.max(...cards.map((x) => direction === "down" ? c[x.id].row : c[x.id].col)); + return unusable(cards, groups, cells) || layers(cells) > layers(first) ? { direction, ...span(first), cells: first } : { direction, ...span(second), cells }; } // tools/html-skill/src/diagram-place.mjs diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 0586e834..904c12f5 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,12 +1,12 @@ -(()=>{var on=["top","right","bottom","left"],sn=["main","plain","dashed"],he=["one","zero-or-one","one-or-many","zero-or-many"],Ft={one:"Exactly one","zero-or-one":"Zero or one","one-or-many":"One or many","zero-or-many":"Zero or many"},an=[2,3,4,5,6],gt=t=>t==null||t===""?void 0:String(t),At=t=>Object.assign(Object.create(null),t),Ot=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function zt(t,e={}){const o=e.checks!==!1,i=[],r=m=>{i.push(m)},s=t.legend??{},a={};for(const m of["main","plain","dashed","focal","group","activation"]){const y=gt(s[m]);y&&(a[m]=y)}const l=t.stepLabel,d=typeof l=="function"?m=>String(l(m)):typeof l=="string"?(m=>l.replace("{n}",String(m))):m=>`Step ${m}`,g=t.shapeLabels??{},f={terminal:gt(g.terminal)??"Start or end",step:gt(g.step)??"Step",decision:gt(g.decision)??"Decision"},c=t.heading===void 0?3:an.includes(t.heading)?t.heading:(r(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),p=(m,y)=>m==null?"plain":sn.includes(m)?m:(r(`"${String(m)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),w=m=>{if(m!=null){if(on.includes(m))return m;r(`"${String(m)}" is not a side (top, right, bottom or left): the derived side is used`)}},h=(m,y)=>typeof m=="number"&&Number.isInteger(m)&&m>=1?m:(t.layout==="auto"&&m==null||r(`${y} is ${JSON.stringify(m)}, not a whole number from 1: it is placed at 1`),1),u=[],M=[];let C=[];const H=[],v=[],E=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(E)||r(`"${String(E)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),E==="architecture"||E==="flowchart"){for(const m of t.nodes??[]){const y=E==="flowchart"&&m.shape==="decision"?"decision":E==="flowchart"&&m.shape==="terminal"?"terminal":"box",k=String(m.id??""),q=h(m.row,`the row of ${k}`);u.push({id:k,i:u.length,name:String(m.name??""),kind:y==="decision"?void 0:gt(m.kind),detail:y==="decision"?void 0:gt(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:h(m.col,`the column of ${k}`),row:q,row2:q,branch:!!m.branch,shape:y,group:E==="architecture"?gt(m.group):void 0,mark:E==="architecture"?ee(m.mark):void 0})}if(E==="architecture"){const m=(t.groups??[]).map(I=>({id:String(I.id??""),label:String(I.label??""),parent:gt(I.parent)})),y=new Map(m.map(I=>[I.id,I])),k=I=>{if(!I.parent)return 1;const B=y.get(I.parent);return B?B.parent===I.id||B.id===I.id?(r(`the groups "${I.label}" and "${B.label}" are each other's parent`),I.parent=void 0,1):B.parent?(r(`the group "${I.label}" is a third level: groups nest two deep`),I.parent=void 0,1):2:(r(`the group "${I.label}" names the parent "${I.parent}", which is not a group`),I.parent=void 0,1)},q=m.map(k);m.forEach((I,B)=>H.push({...I,depth:q[B],members:u.filter(ot=>ot.group===I.id).map(ot=>ot.id),all:[]}));for(const I of H)I.all=[...I.members,...H.filter(B=>B.parent===I.id).flatMap(B=>B.members)];H.sort((I,B)=>I.depth-B.depth)}}else if(E==="data-flow"){C=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const m=new Map(C.map((y,k)=>[y.id,k+1]));for(const y of t.nodes??[]){const k=String(y.id??""),q=String(y.lane??""),I=m.get(q);I===void 0&&r(`a node (${k}) names the lane "${q}", which is not in lanes`);const B=u.length+1;u.push({id:k,i:u.length,name:String(y.name??""),kind:d(B),detail:gt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:h(y.col,`the column of ${k}`),row:I??1,row2:I??1,branch:!1,shape:"box",lane:I??1,laneLabel:C[(I??1)-1]?.label??q,step:B,mark:ee(y.mark)})}}else if(E==="sequence"){(t.participants??[]).forEach((q,I)=>{const B=String(q.name??"");u.push({id:String(q.id??""),i:I,name:B,kind:gt(q.kind),mono:!1,focal:!!q.focal,col:I+1,row:1,row2:1,branch:!1,shape:"participant",short:gt(q.short)??B,mark:ee(q.mark)})});let m=0;const y=new Map(u.map(q=>[q.id,q.col])),k=(q,I)=>{let B=1/0,ot=-1/0;for(const G of q??[]){if(!G||typeof G!="object")continue;if("band"in G){I>0&&r(`the band "${String(G.band)}" is inside a frame: a band is the whole figure's`),v.push({band:String(G.band??"")});continue}if("frame"in G){if(I>=2){r("a frame is a third level: frames nest two deep");continue}const wt=G.frame==="alt"||G.frame==="loop"||G.frame==="opt"?G.frame:"opt",Mt=wt==="alt"?G.branches??[]:[{label:G.label,steps:G.steps}];wt==="alt"&&Mt.length<2&&r("an alt frame has one branch: it needs two or more");const vt=String(Mt[0]?.label??"");vt.length>40&&r(`the frame label "${vt}" is over 40 characters`);const pt=v.length;v.push({open:wt,label:vt,depth:I+1,a:0,b:0}),Mt.forEach((lt,dt)=>{if(dt){const L=String(lt.label??"");L.length>40&&r(`the frame label "${L}" is over 40 characters`),v.push({otherwise:L,depth:I+1})}lt.steps?.length||r(`a frame or branch ("${String(lt.label??"")}") is empty`);const[$t,$]=k(lt.steps??[],I+1);B=Math.min(B,$t),ot=Math.max(ot,$);const A=v[pt];A.a=Math.min(A.a||1/0,$t),A.b=Math.max(A.b,$)}),v.push({close:I+1});continue}m++;const nt=String(G.label??"");nt.includes(` -`)&&r(`message ${m}'s label has a break: a message's second line is its note`);const ft=String(G.from??""),ut=String(G.to??"");v.push({n:m,from:ft,to:ut,label:Ct(nt),note:gt(G.note),kind:p(G.kind,`message ${m}`),activate:G.activate===!0||void 0,deactivate:G.deactivate===!0||void 0});const st=y.get(ft)??1,ht=y.get(ut)??1,bt=st===ht?st===u.length?st-1:st+1:st;B=Math.min(B,st,ht,bt),ot=Math.max(ot,st,ht,bt)}return[B,ot]};k(t.steps??[],0);for(const q of v)"open"in q&&!Number.isFinite(q.a)&&(q.a=1,q.b=Math.max(1,u.length))}else if(E==="schema")for(const m of t.tables??[]){const y=String(m.name??""),[k,q]=Array.isArray(m.row)?m.row:[m.row,m.row],I=h(k,`the row of ${y}`),B=Math.max(I,h(q,`the last row of ${y}`)),ot=m.more===void 0||m.more===null?void 0:Number.isInteger(m.more)&&m.more>0?m.more:(r(`${y}'s "more" is ${JSON.stringify(m.more)}, not a whole number from 1: it is left out`),void 0);u.push({id:y,i:u.length,name:y,mono:!0,focal:!!m.focal,col:h(m.col,`the column of ${y}`),row:I,row2:B,branch:!1,shape:"table",more:ot,columns:(m.columns??[]).map(G=>({name:String(G.name??""),type:gt(G.type),key:G.key==="PK"||G.key==="FK"?G.key:(G.key!==void 0&&G.key!==null&&r(`${y}.${String(G.name)}'s key is "${String(G.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(E==="architecture"||E==="flowchart"||E==="schema")){const m=E==="schema"?t.tables:t.nodes;o&&(m??[]).some(k=>k&&(k.col!==void 0||k.row!==void 0))&&r('a card under layout="auto" has a col or row, which is not read: there are no hints');const y=e.placement?.cells;y||(T=!0);for(const k of u){const q=y?.[k.id];k.col=q?.col??1,k.row=k.row2=q?.row??1}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${E}`);((E==="schema"?t.tables:E==="sequence"?t.participants:t.nodes)??[]).forEach((m,y)=>{if(!m||m.href===void 0||m.href===null)return;const k=String(m.href);if(E==="sequence"){r(`${u[y]?.id}: a participant cannot be a link (href)`);return}if(!k){r(`${u[y]?.id}'s href is empty`);return}const q=u[y];q&&(q.href=k,q.blank=m.target==="_blank")});const z=new Map;for(const m of u)m.id?z.has(m.id)&&r(`the id "${m.id}" is used twice`):r("a node has no id"),z.set(m.id,m);if(E==="schema"){const m=(k,q)=>{if(k==null)return;const I=k,B=he.includes(I.from)?I.from:void 0;if(!B){r(`${q}'s cardinality "from" is ${JSON.stringify(I.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`);return}return I.to===void 0||I.to===null?{from:B,to:"one"}:I.to==="one"||I.to==="zero-or-one"?{from:B,to:I.to}:(r(`${q}'s cardinality "to" is ${JSON.stringify(I.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`),{from:B,to:"one"})};(t.tables??[]).forEach(k=>(k.columns??[]).forEach((q,I)=>{const B=gt(q.references);if(!B&&q.cardinality!==void 0&&q.cardinality!==null&&r(`${String(k.name)}.${String(q.name)} states a cardinality but references nothing`),!B)return;const[ot,G]=B.split("."),nt=z.get(ot??""),ft=nt?.columns?.findIndex(ht=>ht.name===G)??-1;if(!nt||ft<0){r(`${String(k.name)}.${String(q.name)} references ${B}, which is not a shown column`);return}const ut=z.get(String(k.name??""));ut.columns[I].ref={table:ot,column:G,row:ft};const st=m(q.cardinality,`${String(k.name)}.${String(q.name)}`);st&&(ut.columns[I].card=st),M.push({i:M.length,from:ut.id,to:ot,kind:"plain",fromRow:I,toRow:ft,fk:!0,card:st})}));const y=M.filter(k=>k.card).length;y&&y!k.card).map(k=>`${k.from}.${z.get(k.from).columns[k.fromRow].name}`).join(", ")} ${M.length-y===1?"has":"have"} none)`)}else if(E!=="sequence")for(const m of t.edges??[]){const y=String(m.from??""),k=String(m.to??"");if(!z.has(y)||!z.has(k)){r(`a line names ${z.has(y)?k:y}, which is not a node`);continue}const q=gt(m.label),I=q?.split(` -`)??[];I.length>2&&r(`the label "${Ct(q)}" has more than one break: a label is two lines at most`),I.some(B=>B.length>ge)&&r(`a line of the label "${Ct(q)}" is over ${ge} characters: longer words belong in the node or the summary`),M.push({i:M.length,from:y,to:k,kind:p(m.kind,`the line from ${y} to ${k}`),label:q,fromSide:w(m.fromSide),toSide:w(m.toSide),flow:E!=="flowchart"&&m.flow===!0?!0:void 0})}else for(const m of v)"n"in m&&(!z.has(m.from)||!z.has(m.to))&&r(`message ${m.n} names ${z.has(m.from)?m.to:m.from}, which is not a participant`);if(o&&E!=="sequence"&&!T){const m=new Map;for(const y of u)for(let k=y.row;k<=y.row2;k++){const q=`${y.col}:${k}`;m.has(q)&&r(`${y.id} and ${m.get(q)} share the cell at column ${y.col}, row ${k}`),m.set(q,y.id)}}if(o&&!T){for(const y of H){const k=y.all.map(B=>z.get(B));if(!k.length)continue;const q={c1:Math.min(...k.map(B=>B.col)),c2:Math.max(...k.map(B=>B.col)),r1:Math.min(...k.map(B=>B.row)),r2:Math.max(...k.map(B=>B.row2))};for(const B of u)!y.all.includes(B.id)&&B.col>=q.c1&&B.col<=q.c2&&B.row>=q.r1&&B.row<=q.r2&&r(`${B.id} is inside the box of the group "${y.label}" but not a member`);const I=k.map(B=>B.i);Math.max(...I)-Math.min(...I)+1!==I.length&&r(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of u)y.group&&!H.some(k=>k.id===y.group)&&r(`${y.id} names the group "${y.group}", which is not in groups`);u.filter(y=>y.focal).length>1&&r("more than one node is focal: a diagram has one at most");const m=new Set(E==="sequence"?v.flatMap(y=>"n"in y?[y.kind]:[]):M.map(y=>y.kind));m.has("main")&&!a.main&&r("main lines are drawn but the legend has no words for them (legend.main)"),m.has("dashed")&&!a.dashed&&r("dashed lines are drawn but the legend has no words for them (legend.dashed)"),u.some(y=>y.focal)&&!a.focal&&r("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const it=E==="architecture"||E==="data-flow",_=m=>Array.isArray(m)&&m.length>1?m.map(String):void 0,D=it&&t.packet&&typeof t.packet=="object"?t.packet:void 0,j=D&&_(D.path),x={animated:t.motion==="animated",pulse:it?_(t.pulse):void 0,packet:j?{path:j,repeat:D.repeat===!0,send:D.send}:void 0,run:E==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(o)for(const m of u){const y=m.mark?.says;if(!y?.length)continue;const k=[m.name,m.kind,m.detail,m.laneLabel].filter(Boolean).join(" ").toLowerCase();y.some(q=>k.includes(q.toLowerCase()))||r(`${m.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const R=[];if(E==="sequence"){const m=new Map,y=new Map;for(const k of v)"n"in k&&(y.set(k.from,k.n),y.set(k.to,k.n));for(const k of v)if("n"in k){if(k.activate){const q=m.get(k.to)??[];if(q.length>=3)r(`message ${k.n} opens a fourth bar on ${k.to}: three deep at most`);else{const I={who:k.to,from:k.n,to:k.n,depth:q.length+1};q.push(I),R.push(I),m.set(k.to,q)}}if(k.deactivate){const I=m.get(k.from)?.pop();I?I.to=k.n:r(`message ${k.n} closes a bar on ${k.from}, which has none open`)}}for(const[k,q]of m)for(const I of q)I.to=Math.max(I.from,y.get(k)??I.from)}const F=t.frameLabels??{},Z={opt:gt(F.opt)??"Only if",loop:gt(F.loop)??"Repeats",alt:gt(F.alt)??"One of these",else:gt(F.else)??"Otherwise"};let K=Math.max(1,...u.map(m=>m.col));if(e.rtl){for(const y of u)y.col=K-y.col+1;const m=y=>y==="left"?"right":y==="right"?"left":y;for(const y of M)y.fromSide=m(y.fromSide),y.toSide=m(y.toSide);for(const y of v)if("open"in y){const[k,q]=[K-y.b+1,K-y.a+1];y.a=k,y.b=q}K=Math.max(1,...u.map(y=>y.col))}const rt=E==="data-flow"?Math.max(1,C.length):Math.max(1,...u.map(m=>m.row2)),U={type:E,title:String(t.title??""),heading:c,legend:a,nodes:u,byId:z,edges:M,groups:H,lanes:C,steps:v,bars:R,frameWords:Z,cols:K,rows:rt,shapeLabels:f,stepWord:d,warnings:i,motion:x,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0,text:E==="sequence"&&t.variant==="text"||void 0,marks:M.some(m=>m.card)||void 0};if(t.layout==="auto"&&!T&&E!=="schema"&&rn(U),o)for(const[m,y]of Object.entries(Te(U)))y>=48&&r(`${m} grows to ${y}px to hold the lines on one side: use another side`);return o&&u.length>1&&!Zt(U)&&r("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),U}function rn(t){const e=new Set(t.nodes.map(s=>`${s.col},${s.row}`)),n=(s,a)=>{const l=[];for(let d=Math.min(s,a)+1;d{const a=t.byId.get(s.from),l=t.byId.get(s.to),d=l.col>a.col?"right":"left",g=l.row>a.row?"bottom":"top",f=l.col>a.col?"left":"right",c=l.row>a.row?"top":"bottom",p=(h,u,M,C)=>n(h,u).map(H=>C?[H,M]:[M,H]);let w;return a.row===l.row?w=[{sides:[d,f],cells:p(a.col,l.col,a.row,!0)},{sides:["bottom","bottom"],cells:[]},{sides:["top","top"],cells:[]}]:a.col===l.col?w=[{sides:[g,c],cells:p(a.row,l.row,a.col,!1)},{sides:["right","right"],cells:[]},{sides:["left","left"],cells:[]}]:w=[{sides:[d,c],cells:[...p(a.col,l.col,a.row,!0),[l.col,a.row],...p(a.row,l.row,l.col,!1)]},{sides:[g,f],cells:[...p(a.row,l.row,a.col,!1),[a.col,l.row],...p(a.col,l.col,l.row,!0)]},{sides:[d,f],cells:p(a.col,l.col,a.row,!0)},{sides:[g,c],cells:p(a.row,l.row,a.col,!1)}],w.filter(h=>h.cells.every(([u,M])=>!e.has(`${u},${M}`)))},i=new Map,r=t.edges.map((s,a)=>a).sort((s,a)=>o(t.edges[s]).length-o(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[s].kind==="main")||s-a);for(const s of r){const a=t.edges[s];if(a.fromSide||a.toSide)continue;const l=o(a).find(d=>(i.get(`${a.from}.${d.sides[0]}`)??0)<3&&(i.get(`${a.to}.${d.sides[1]}`)??0)<3);if(l){for(const[d,g]of[[a.from,l.sides[0]],[a.to,l.sides[1]]])i.set(`${d}.${g}`,(i.get(`${d}.${g}`)??0)+1);a.fromSide=l.sides[0],a.toSide=l.sides[1]}}}function ee(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=gt(e.onLight);if(n)return{onLight:n,onDark:gt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var pe=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function qt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var ge=28,ne=t=>t.includes(` -`)?2:1,Ct=t=>t.replace(/\n/g," "),Nt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function me(t,e){return t.legend[e]}function ln(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function cn(t,e){return qt(t,`sentence:${e.i}`,()=>dn(t,e))}function dn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const o=(e.columns??[]).filter(r=>r.ref).map(r=>`${r.ref.table} (${r.name}${r.card?`: ${ye(e.id,r.ref.table,r.card)}`:""})`),i=t.edges.filter(r=>r.to===e.id).map(r=>`${r.from} (${t.byId.get(r.from).columns[r.fromRow].name}${r.card?`: ${ye(r.from,r.to,r.card)}`:""})`);o.length&&n.push(`References ${o.join(", ")}.`),i.length&&n.push(`Referenced by ${i.join(", ")}.`)}else if(t.type==="sequence"){const o=t.steps.filter(s=>"n"in s&&s.from===e.id).length,i=t.steps.filter(s=>"n"in s&&s.to===e.id).length;n.push(Nt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${o} ${o===1?"message":"messages"} and receives ${i}.`);const r=$e(t,e);r&&n.push(r.trim())}else{const o=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?ln(t,e):e.kind;if(n.push(Nt(o?`${e.name}, ${o}`:e.name)),e.detail&&n.push(Nt(e.detail)),e.group){const s=t.groups.find(l=>l.id===e.group),a=s?.parent?t.groups.find(l=>l.id===s.parent):void 0;s&&n.push(a?`In ${s.label}, in ${a.label}.`:`In ${s.label}.`)}const i=t.edges.filter(s=>s.to===e.id).map(s=>`${t.byId.get(s.from).name}${s.label?` (${Ct(s.label)})`:""}`),r=t.edges.filter(s=>s.from===e.id).map(s=>`${t.byId.get(s.to).name}${s.label?` (${Ct(s.label)})`:""}`);i.length&&n.push(`From: ${i.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(Nt(t.legend.focal)),n.join(" ")}var fn=(t,e,n,o)=>[`${Ft[n.from].toLowerCase()} `,o(t),` to ${Ft[n.to].toLowerCase()} `,o(e)],ye=(t,e,n)=>`${Ft[n.from].toLowerCase()} ${t} to ${Ft[n.to].toLowerCase()} ${e}`;function $e(t,e){const n=t.bars.filter(i=>i.who===e.id&&i.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(i=>i.from===i.to?`message ${i.from}`:`messages ${i.from} to ${i.to}`).join(" and ")}.`:""}function un(t,e,n,o){const i=n.pointerType;if(i!=="touch"&&i!=="pen")return;const r=t.querySelector(`.${e}-drawing`),s=n.target;if(!r||!s||!r.contains(s)||!t.querySelector(`.${e}-edge`))return;const a=s.closest(`.${e}-node`);if(!a?.hasAttribute("href"))return a?a.dataset.node===o?null:a.dataset.node??null:null}function be(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function b(t,e,...n){const o=[];for(const i of n.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&o.push(i);return{t,a:e??{},c:o}}var hn={"&":"&","<":"<",">":">",'"':""","'":"'"},mt=t=>t.replace(/[&<>"']/g,e=>hn[e]),pn=" br img input meta link hr path polygon polyline circle rect line ";function oe(t,e={}){if(typeof t=="string")return mt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[o,i]of Object.entries(t.a))if(!(i==null||i===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(o))throw new Error(`diagram: "${o}" is not an attribute name`);n+=i===!0?` ${o}`:` ${o}="${mt(String(i))}"`}return pn.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(o=>oe(o,e)).join("")}`}var gn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function jt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function mn(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Vt(t,e){const n=e.all.map(o=>t.byId.get(o));return n.length?{c1:Math.min(...n.map(o=>o.col)),c2:Math.max(...n.map(o=>o.col)),r1:Math.min(...n.map(o=>o.row)),r2:Math.max(...n.map(o=>o.row2))}:null}function we(t){return qt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const o=Vt(t,n);if(!o)continue;[o.r1===1,o.c2===t.cols,o.r2===t.rows,o.c1===1].forEach((r,s)=>{r&&(e[s]=Math.max(e[s],ve(t,n,s)))})}return e})}function ve(t,e,n){const o=Vt(t,e);return t.groups.filter(s=>s.parent===e.id).some(s=>{const a=Vt(t,s);return a&&[a.r1===o.r1,a.c2===o.c2,a.r2===o.r2,a.c1===o.c1][n]})?2:1}function xe(t){const e=we(t);return e[1]+e[3]}function se(t){return t.type==="sequence"?t.nodes.length:t.cols}function ke(t){return qt(t,"plan",()=>yn(t))}function yn(t){const e=t.nodes,n=u=>t.type==="data-flow"||!e[u].branch,o=t.edges.map(u=>{const M=t.byId.get(u.from).i,C=t.byId.get(u.to).i,v=e.slice(Math.min(M,C)+1,Math.max(M,C)).every(E=>!n(E.i));return C===M+1&&!(n(M)&&!n(C))?"down":C===M-1?"up":C>M&&n(M)&&!n(C)&&v?"trunk":C>M&&n(M)&&n(C)&&v?"rail":C>M?"end-down":"end-up"}),i=t.edges.map((u,M)=>({e:u,k:M})).filter(({k:u})=>o[u]==="end-down"||o[u]==="end-up"),r=u=>{const M=t.byId.get(u.from).i,C=t.byId.get(u.to).i;return[Math.min(M,C),Math.max(M,C)]},s=(u,M)=>{const[C,H]=r(u),[v,E]=r(M);return C{const M=t.byId.get(u.from).i,[C,H]=r(u);return!n(M)&&e.slice(C+1,H).every(v=>!n(v.i))&&i.every(v=>v.e===u||!s(v.e,u))}),l=i.length>0&&(t.type==="data-flow"||!a),d=u=>{const[M,C]=r(u);return C-M},g=t.edges.map(()=>0);let f=!1;const c=[];for(const u of[...i].sort((M,C)=>d(M.e)-d(C.e)||M.k-C.k)){let M=0;for(const C of c)s(C.e,u.e)&&(M=Math.max(M,g[C.k]+1));g[u.k]=M,M>3&&(f=!0),c.push(u)}const p=Math.max(0,...i.map(({k:u})=>g[u]+1)),w=t.edges.map(()=>.5);for(const u of e){const M=i.filter(({e:v})=>v.from===u.id);if(M.length<2)continue;const C=M.filter(({k:v})=>o[v]==="end-down").sort((v,E)=>d(E.e)-d(v.e)||v.k-E.k);[...M.filter(({k:v})=>o[v]==="end-up").sort((v,E)=>d(v.e)-d(E.e)||E.k-v.k),...C].forEach(({k:v},E,T)=>{w[v]=T.length===2?E===0?1/3:2/3:(E+1)/(T.length+1)})}const h=At();for(let u=1;u{const D=o[_],j=t.byId.get(it.from).i,x=t.byId.get(it.to).i,R=x===u&&(D==="down"||D==="trunk"||D==="rail"||D==="end-down"),F=j===u&&x===u-1&&D==="up",Z=x===u-1&&D==="end-up";R&&(D==="trunk"||D==="end-down")&&(E=!0),Z&&(T=!0),(R||F||Z)&&it.label&&(H++,v=Math.max(v,D==="trunk"?40:48))}),(H>1||E&&T)&&(v=64);const tt=i.filter(({e:it,k:_})=>o[_]==="end-down"&&t.byId.get(it.to).i===u).length,z=i.filter(({e:it,k:_})=>o[_]==="end-up"&&t.byId.get(it.to).i===u-1).length;v+=20*Math.max(0,tt-1)+20*Math.max(0,z-1),h[M.id]=v}return{routes:o,gutter:l,lanes:g,exits:w,gaps:h,third:f,laneCount:p}}var Tt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Me(t,e){const n=e==="fk"?"plain":e,o=n==="main"?8:8.5,i=24,r=n==="dashed"?i-1:i-7;return b("svg",{class:`${t}-swatch`,"data-kind":n,...Tt(24,16)},e==="fk"?b("circle",{class:`${t}-dot`,cx:3,cy:o,r:3}):null,b("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${o}H${r}`}),n==="dashed"?b("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${i-8} ${o-4}L${i} ${o}L${i-8} ${o+4}`}):b("path",{class:`${t}-tip`,"data-kind":n,d:`M${i} ${o}L${i-8} ${o-4}L${i-8} ${o+4}Z`}))}function $n(t,e){const{crow:n,ring:o}=Se(e,24,8.5,-1);return b("svg",{class:`${t}-swatch`,"data-card":e,...Tt(24,16)},b("path",{class:`${t}-line`,"data-kind":"plain",d:"M0 8.5H24"}),b("path",{class:`${t}-crow`,d:n}),o?b("circle",{class:`${t}-ring`,cx:o.x,cy:o.y,r:o.r}):null)}function Se(t,e,n,o,i=8,r=6){const s=p=>String(Math.round(p*100)/100),a=p=>e+o*p,l=i/2,d=p=>`M${s(a(p-.5))} ${s(n-l)}V${s(n+l)}`,g=t==="one-or-many"||t==="zero-or-many",f=t==="zero-or-one"||t==="zero-or-many";let c=g?`M${s(e)} ${s(n-l)}L${s(a(7.5))} ${s(n)}L${s(e)} ${s(n+l)}`:d(4);return f||(c+=d(g?11:8)),{crow:c,ring:f?{x:Math.round(a(10.5)*100)/100,y:n,r:r/2}:void 0}}function Ht(t,e){return e==="decision"?b("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},b("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?b("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},b("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):b("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},b("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Ee(t,e){return qt(e,`key:${t}`,()=>wn(t,e))}var bn=Ee;function wn(t,e){const n=[],o=(s,a,l={})=>n.push(b("li",{class:`${t}-entry`,...l},s,b("span",null,a)));if(e.type==="schema"){const s=new Set(e.nodes.flatMap(a=>(a.columns??[]).map(l=>l.key)));for(const[a,l]of[["PK","Primary key"],["FK","Foreign key"]])s.has(a)&&n.push(b("li",{class:`${t}-entry`},b("span",{class:`${t}-key-letters`,"aria-hidden":"true"},a),b("span",null,l)))}if(e.type==="flowchart"){const s=new Set(e.nodes.map(a=>a.shape));s.has("terminal")&&o(Ht(t,"terminal"),e.shapeLabels.terminal),s.has("box")&&o(Ht(t,"box"),e.shapeLabels.step),s.has("decision")&&o(Ht(t,"decision"),e.shapeLabels.decision)}const i=new Set(e.type==="sequence"?e.steps.flatMap(s=>"n"in s?[s.kind]:[]):e.edges.filter(s=>!s.fk).map(s=>s.kind)),r=(s,a)=>b("span",{class:`${t}-key-glyph`,"data-ink":a,"aria-hidden":"true"},s);for(const s of["main","plain","dashed"]){const a=e.legend[s];i.has(s)&&a&&o(e.text?r(s==="main"?"━━▶":s==="dashed"?"┄┄▷":"──▶",s==="main"?"main":"plain"):Me(t,s),a,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length){e.edges.some(a=>!a.card)&&o(Me(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"});const s=new Set(e.edges.flatMap(a=>a.card?[a.card.from,a.card.to]:[]));for(const a of he)s.has(a)&&o($n(t,a),Ft[a],{"data-line":"","data-when":"drawn","data-card":a});n.push(b("li",{class:`${t}-entry`,"data-when":"stacked"},b("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),b("span",null,"The table a foreign key references")))}if(e.type==="sequence"){e.bars.length&&o(e.text?r("┃","working"):b("svg",{class:`${t}-swatch`,"data-shape":"bar",...Tt(16,16)},b("path",{class:`${t}-life`,d:"M8 0V16"}),b("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const s=new Set(e.steps.flatMap(a=>"open"in a?[a.open]:[]));for(const a of["opt","loop","alt"])s.has(a)&&n.push(b("li",{class:`${t}-entry`},b("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},a),b("span",null,e.frameWords[a])))}return e.nodes.some(s=>s.focal)&&e.legend.focal&&o(Ht(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&o(Ht(t,"group"),e.legend.group),n.length?b("div",{class:`${t}-key`},b("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function vn(t,e){const n=e==="main"?6:6.5;return b("svg",{class:`${t}-arrow`,"data-kind":e,...Tt(20,12)},b("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?b("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):b("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function ae(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),b("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function xn(t,e,n){if(n.shape==="decision")return[b("span",{class:`${t}-words`},b("span",{class:`${t}-name`},ae(t,n)))];const o=[];return e.type==="data-flow"?o.push(b("span",{class:`${t}-kind`},n.kind,b("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&o.push(b("span",{class:`${t}-kind`},n.kind)),o.push(b("span",{class:`${t}-name`},ae(t,n))),n.detail&&o.push(b("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Yt(n.detail).flatMap((i,r)=>[r?" ":"",b("span",{class:`${t}-run`},i)]):n.detail)),o}function kn(t,e,n){return[b("span",{class:`${t}-th`},b("span",{class:`${t}-tname`},ae(t,e))),b("span",{class:`${t}-rows`},(e.columns??[]).map((o,i)=>b("span",{class:`${t}-row`,"data-row":i,"data-key":o.key},b("span",{class:`${t}-keyseat`},o.key??""),b("span",{class:`${t}-cname`},o.name),o.ref?b("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${o.ref.table}`):o.type?b("span",{class:`${t}-ctype`},o.type):null))),e.more?b("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Ae=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Kt(t,e,n,o){const{P:i}=t,r=mn(e,o)||o.keep===n.id,s=jt(e,o),a=o.layout==="drawn"&&o.rows,l=[`--_c:${n.col}`,`--_r:${a?2*n.row:n.row}`,`--_r2:${a?2*n.row2+1:n.row2+1}`];e.type==="data-flow"&&l.push(`--_lc:${n.col+1}`),e.type==="sequence"&&l.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const w=Ot(d.gaps,n.id)??32,h=Ot(o.grow,n.id)??0;l.push(`--_gap:${h?`calc(${Ae(w)} + var(--basalt-space-4) * ${h})`:Ae(w)}`)}const g=Ot(o.heights,n.id);g&&l.push(`--_h:${g}px`);const f=Ot(Te(e),n.id);f&&l.push(`--_mh:${f}px`);const c=Ot(o.words,n.id);c&&l.push(`--_ww:${c}px`);const p=s?o.stop===n.id?0:-1:o.keep===n.id?-1:void 0;return b(n.href?"a":"div",{class:`${i}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:l.join(";"),role:r&&!n.href?"img":void 0,"aria-label":r||n.href?cn(e,n):void 0,tabindex:p},n.shape==="decision"?b("svg",{class:`${i}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},b("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?b("span",{class:`${i}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${pe(n.mark.onLight)};--_md:${pe(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?kn(i,n,e):xn(i,e,n))}function Mn(t,e,n){const{P:o}=t,i=[];if(e.type==="data-flow"&&i.push(...e.lanes.map((l,d)=>b("div",{class:`${o}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},b("span",{class:`${o}-lane-name`},l.label)))),e.type==="architecture")for(const l of e.groups){const d=Vt(e,l);if(!d)continue;const g=[0,1,2,3].map(f=>ve(e,l,f));i.push(b("div",{class:`${o}-gbox`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:`--_c:${d.c1};--_c2:${d.c2+1};--_r:${d.r1};--_r2:${d.r2+1}${g[0]>1?";--_gt:2":""}${g[1]>1?";--_ge:2":""}${g[2]>1?";--_gb:2":""}${g[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},b("span",{class:`${o}-glabel`},l.label)))}if(e.text)return[b("pre",{class:`${o}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},b("code",{class:`${o}-text-ink`},Sn(o,e)))];if(e.type==="sequence")return i.push(b("ul",{class:`${o}-cast`},e.nodes.map(l=>b("li",{class:`${o}-actor`,style:e.rtl?`--_ac:${l.col}`:void 0},Kt(t,e,l,n))))),i.push(En(t,e)),i;const r=l=>{const d=l.group?e.groups.find(g=>g.id===l.group):void 0;return d?.parent?e.groups.find(g=>g.id===d.parent):d},s=(l,d,g)=>{const f=t.plan?Ot(n.grow,d[0].id)??0:0;return b("div",{class:`${o}-group`,"data-group":l.id,"data-depth":l.depth>1?l.depth:void 0,style:f?`--_ggrow:${f}`:void 0},b("span",{class:`${o}-glabel`,"aria-hidden":"true"},l.label),g)};let a=0;for(;ah.id===g[c].group):void 0;if(!p){f.push(Kt(t,e,g[c],n)),c++;continue}const w=[];for(;cKt(t,e,h,n))))}i.push(s(d,g,f))}return i}function Sn(t,e){const n=[],o=s=>b("span",{class:`${t}-tx-name`},s),i=s=>s==="main"?"━▶":s==="dashed"?"┄▷":"─▶";n.push(b("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((s,a)=>[a?" · ":"",o(s.name)])),` -`);let r=0;for(const s of e.steps){const a=" ".repeat(r);if("band"in s){n.push(b("span",{class:`${t}-tx-line`,"data-ink":"band"},`${a}── ${s.band} ──`),` -`);continue}if("open"in s){n.push(b("span",{class:`${t}-tx-line`,"data-ink":"frame"},a,b("span",{"data-ink":"op"},`[${s.open}]`),` ${s.label}`),` -`),r++;continue}if("otherwise"in s){n.push(b("span",{class:`${t}-tx-line`,"data-ink":"frame"}," ".repeat(r-1),b("span",{"data-ink":"op"},"[else]"),` ${s.otherwise}`),` -`);continue}if("close"in s){r=Math.max(0,r-1),n.push(b("span",{class:`${t}-tx-line`,"data-ink":"frame"},`${" ".repeat(r)}[end]`),` -`);continue}const l=e.byId.get(s.from)?.name??s.from,d=e.byId.get(s.to)?.name??s.to;n.push(b("span",{class:`${t}-tx-line`,"data-n":s.n},a,b("span",{"data-ink":"num"},`${s.n} `),o(l)," ",b("span",{"data-ink":s.kind==="main"?"main":"plain"},i(s.kind))," ",o(d)," ",b("span",{"data-ink":"label"},s.label),s.note?[" ",b("span",{"data-ink":"note"},`(${s.note})`)]:null),` -`)}return n}function En(t,e){const{P:n}=t,o=[],i=[],r=()=>i.length?i[i.length-1].el.c:o;let s=null;for(const a of e.steps){if("band"in a){s=null,r().push(b("p",{class:`${n}-band`},b("span",null,a.band)));continue}if("open"in a){s=null;const h=i[i.length-1],u=h?`;--_fis:${a.a===h.a?1:0};--_fie:${a.b===h.b?1:0}`:"",M=b("div",{class:`${n}-frame`,"data-op":a.open,"data-depth":a.depth,style:`--_a:${a.a};--_b:${a.b+1}${u}`},b("span",{class:`${n}-fbox`,"aria-hidden":"true"}),b("p",{class:`${n}-fhead`},b("span",{class:`${n}-ftab`,"aria-hidden":"true"},a.open),b("span",{class:`${n}-flabel`},b("span",{class:t.hidden},`${e.frameWords[a.open]}: `),a.label)));r().push(M),i.push({el:M,a:a.a,b:a.b});continue}if("otherwise"in a){s=null,r().push(b("p",{class:`${n}-felse`},b("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),b("span",{class:`${n}-flabel`},b("span",{class:t.hidden},`${e.frameWords.else}: `),a.otherwise)));continue}if("close"in a){s=null,i.pop();continue}s||(s=b("ol",{class:`${n}-msgs`,start:a.n}),r().push(s));const l=e.byId.get(a.from),d=e.byId.get(a.to),g=l?.col??1,f=d?.col??1,c=g===f,p=c&&(e.rtl?g!==1:g===e.nodes.length),w=me(e,a.kind);s.c.push(b("li",{class:`${n}-msg`,"data-kind":a.kind,"data-from":a.from,"data-to":a.to,"data-self":c?p?"start":"end":void 0,style:`--_a:${Math.min(g,f)};--_b:${Math.max(g,f)+1}`},b("span",{class:`${n}-said`},b("span",{class:`${n}-num`},String(a.n)),b("span",{class:`${n}-mlabel`},a.label)),b("span",{class:`${n}-route`},l?.short??a.from," ",vn(n,a.kind),b("span",{class:t.hidden}," to ")," ",d?.short??a.to,w?` · ${w}`:""),a.note?b("span",{class:`${n}-note`},a.note):null))}return b("div",{class:`${n}-steps`},o)}function Le(t,e){return qt(e,`list:${t}`,()=>Ln(t,e))}var An=Le;function Ln(t,e){const n=Math.min(6,e.heading+1),o=f=>b(`h${n}`,{class:`${t}-list-head`},f),i=f=>b("strong",null,f),r=f=>f.href?b("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},i(f.name)):i(f.name),s=f=>b("code",{class:`${t}-code`},f),a=f=>e.byId.get(f)?.name??f,l=f=>{const c=me(e,f);return c?` (${c})`:""},d=f=>f.focal&&e.legend.focal?` ${Nt(e.legend.focal)}`:"";if(e.type==="architecture"){const f=w=>b("li",null,r(w),w.kind?`, ${w.kind}`:"",w.detail?[". ",w.mono?s(w.detail):w.detail,/[.!?]$/.test(w.detail)?"":"."]:/[.!?]$/.test(w.kind??w.name)?"":".",d(w)),c=[o("Parts")],p=e.nodes.filter(w=>!w.group);p.length&&c.push(b("ul",{class:`${t}-list-items`},p.map(f)));for(const w of e.groups.filter(h=>h.depth===1)){c.push(b("p",{class:`${t}-list-group`},w.label)),w.members.length&&c.push(b("ul",{class:`${t}-list-items`},w.members.map(h=>f(e.byId.get(h)))));for(const h of e.groups.filter(u=>u.parent===w.id))c.push(b("p",{class:`${t}-list-group`,"data-depth":2},h.label)),c.push(b("ul",{class:`${t}-list-items`,"data-depth":2},h.members.map(u=>f(e.byId.get(u)))))}return c.push(o("Connections")),c.push(b("ol",{class:`${t}-list-items`},e.edges.map(w=>b("li",null,i(a(w.from))," to ",i(a(w.to)),w.label?[": ",s(Ct(w.label))]:"",`${l(w.kind)}.`)))),c}if(e.type==="flowchart"){const f=c=>(e.byId.get(c)?.i??0)+1;return[b("ol",{class:`${t}-list-items`},e.nodes.map(c=>{const p=e.edges.filter(u=>u.from===c.id),w=c.shape==="decision"?"Decision":c.shape==="terminal"?p.length?"Start":"End":"Step",h=!c.detail&&/[.!?]$/.test(c.name)?" ":". ";return b("li",null,r(c),c.detail?[", ",c.mono?s(c.detail):c.detail]:"",`${h}${w}.`,d(c),p.length?b("ul",{class:`${t}-list-exits`},p.map(u=>b("li",null,u.label?`If ${Ct(u.label)}: go to ${f(u.to)}, `:`Then: go to ${f(u.to)}, `,i(a(u.to)),l(u.kind)))):null)}))]}if(e.type==="data-flow")return[b("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const c=e.edges.filter(p=>p.from===f.id);return b("li",null,`${f.laneLabel}: `,r(f),f.detail?[", ",f.mono?s(f.detail):f.detail]:"",".",d(f),c.length?[" Then ",...c.flatMap((p,w)=>[w?"; ":"",`to step ${e.byId.get(p.to).step}, `,i(a(p.to)),p.label?[": ",s(Ct(p.label))]:"",l(p.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[o("Participants"),b("ul",{class:`${t}-list-items`},e.nodes.map(p=>b("li",null,i(p.name),p.kind?`, ${p.kind}`:"",".",d(p),$e(e,p))))];f.push(o("Messages"));let c=null;for(const p of e.steps){if("band"in p){c=null,f.push(b(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},p.band));continue}if("open"in p){c=null,f.push(b(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":p.depth>1?p.depth:void 0},`${e.frameWords[p.open]}: ${p.label}`));continue}if("otherwise"in p){c=null,f.push(b(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":p.depth>1?p.depth:void 0},`${e.frameWords.else}: ${p.otherwise}`));continue}if("close"in p){c=null;continue}c||(c=b("ol",{class:`${t}-list-items`,start:p.n}),f.push(c)),c.c.push(b("li",null,s(p.label),": ",i(a(p.from))," to ",i(a(p.to)),`${l(p.kind)}.`,p.note?` ${Nt(p.note)}`:""))}return f}const g=[];for(const f of e.nodes)g.push(b(`h${n}`,{class:`${t}-list-group`},f.href?b("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},s(f.name)):s(f.name),d(f))),g.push(b("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(c=>b("li",null,s(c.name),c.key==="PK"?", primary key":c.key==="FK"?", foreign key":"",c.ref?[", references ",s(`${c.ref.table}.${c.ref.column}`),c.card?[" (",fn(f.id,c.ref.table,c.card,s),")"]:""]:c.type?`, ${c.type}`:"")),...f.more?[b("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return g}function Ie(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Zt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(i=>i.href)?" Enter opens a part that is a link.":""}`}function re(t,e=!1){const n=e&&t.type!=="sequence"&&Zt(t)&&t.cols>1&&t.rows>1,o=t.nodes.some(i=>i.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:be(t)},{keys:["Home","End"],words:"the ends"},...o,{keys:["Esc"],words:"clear"}]}var In=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Zt(t){return qt(t,"spatial",()=>{const e=t.nodes.map(r=>({id:r.id,..._n(t,r)})),n=(r,s)=>{const a=s==="right"||s==="left",l=s==="right"||s==="down",d=w=>a?[w.col,w.col]:w.rows,g=w=>a?w.rows:[w.col,w.col],f=d(r),c=g(r);let p=null;return e.forEach((w,h)=>{if(w===r)return;const u=d(w),M=g(w),C=l?u[0]-f[1]:f[0]-u[1];if(C<1)return;const H=Math.max(0,M[0]-c[1],c[0]-M[1]),v=[H===0?0:1,H===0?C:C+2*H,H,Math.abs(M[0]-c[0]),h];(!p||In(v,p.rank))&&(p={id:w.id,rank:v})}),p?.id??null},o=At();for(const r of e)o[r.id]={right:n(r,"right"),left:n(r,"left"),down:n(r,"down"),up:n(r,"up")};const i=r=>{const s=new Set([r]),a=[r];for(;a.length;)for(const l of Object.values(o[a.pop()]))l&&!s.has(l)&&(s.add(l),a.push(l));return s.size};return e.every(r=>i(r.id)===e.length)?o:null})}function Jt(t){return qt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!ie(t))return{lane:e,dropped:n,lanes:0};const o=(l,d)=>(t.byId.get(l)?.row??0)*1e3+d,i=new Map;t.edges.forEach((l,d)=>{const g=`${l.to}.${l.toRow}`,f=o(l.from,l.fromRow??0),c=o(l.to,l.toRow??0),p=i.get(g)??{members:[],lo:1/0,hi:-1/0};p.members.push(d),p.lo=Math.min(p.lo,f,c),p.hi=Math.max(p.hi,f,c),i.set(g,p)});const r=[...i.values()].sort((l,d)=>d.hi-d.lo-(l.hi-l.lo)),s=[];let a=0;for(const l of r.reverse()){const d=new Set(s.filter(f=>f.lo<=l.hi&&l.lo<=f.hi).map(f=>f.lane));let g=0;for(;d.has(g);)g++;if(g>1){for(const f of l.members)n.add(f);continue}s.push({lo:l.lo,hi:l.hi,lane:g});for(const f of l.members)e.set(f,g);a=Math.max(a,g+1)}return{lane:e,dropped:n,lanes:a}})}var ie=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Xt(t,e,n){const o=n.prefix,i=gn(n.base),r=t.type==="sequence"||t.type==="schema"?null:ke(t),s={P:o,ids:i,level:n.level,plan:r,hidden:n.hiddenClass},a=e.layout==="drawn",l=jt(t,e),d=t.type==="sequence"||t.type==="schema"?a:!0,g=`h${t.heading}`,f=[`--_cols:${se(t)}`];if(t.type==="architecture"&&t.groups.length||a&&e.pad){const c=t.type==="architecture"?we(t):[0,0,0,0],p=(h,u,M)=>h?h>1?`calc(${h} * var(--basalt-space-${u}))`:`var(--basalt-space-${u})`:M?`var(--basalt-space-${M})`:"0px",w=a&&e.pad?"3":void 0;f.push(`--_gpad:${p(c[0],"8",w)} ${p(c[1],"4")} ${p(c[2],"4",w)} ${p(c[3],"4")}`)}if(r?.gutter&&r.laneCount>2&&f.push(`--_gw:calc(${r.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),ie(t)){const c=t.marks?"var(--basalt-space-6) + var(--basalt-space-1)":"var(--basalt-space-5)";f.push(`--_gpad:0px ${Jt(t).lanes>1?`calc(${c} + var(--basalt-space-3))`:t.marks?`calc(${c})`:c} 0px 0px`)}return t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),b("figure",{class:n.className?`${o} ${n.className}`:o,"aria-labelledby":i.title,"data-type":t.type,"data-cols":se(t),"data-reach":t.type==="architecture"?xe(t):void 0,"data-gutter":r?.gutter?"":void 0,"data-marks":t.marks?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:f.join(";")},b("div",{class:`${o}-head`},b(g,{id:i.title,class:`${o}-title`},t.title),n.hasSource?b("p",{class:`${o}-source`},{slot:"source"}):null),b("div",{class:`${o}-drawing`,style:a&&e.rows?`--_rows:${e.rows};--_row-gap:0px`:void 0,role:d?"group":void 0,"aria-roledescription":d?"diagram":void 0,"aria-labelledby":d?i.title:void 0,"aria-describedby":d?l?`${i.summary} ${i.keys}`:i.summary:void 0,"data-stops":l?"":void 0},Mn(s,t,e),t.text?null:b("div",{class:`${o}-ink`,"aria-hidden":"true"}),b("span",{class:`${o}-ruler`,"aria-hidden":"true"})),Ee(o,t),b("p",{class:`${o}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),jt(t,e)&&t.type!=="sequence"||a&&t.type==="sequence"?b("p",{class:`${o}-tap-hint`,"aria-hidden":"true"},`Tap ${be(t)} to highlight its lines. Tap it again to clear.`):null,b("div",{class:`${o}-foot`},{slot:"toggle"}),b("div",{id:i.list,class:`${o}-list`,hidden:!e.open},Le(o,t)),b("span",{id:i.keys,class:n.hiddenClass},n.viewer?`${Ie(t,a)} ${n.viewer}`:Ie(t,a)),b("figcaption",{id:i.summary,class:`${o}-summary`},{slot:"summary"}))}function On(t){const e=getComputedStyle(t),n=(i,r)=>{const s=parseFloat(e.getPropertyValue(`--basalt-${i}`));return Number.isFinite(s)?s:r},o=new Map;return{space:i=>(o.has(i)||o.set(i,n(`space-${i}`,parseFloat(i.replace("-","."))*4)),o.get(i)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ut=(t,e)=>t==="main"?e.line:e.hair,Et=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},Lt=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,_e=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function kt(t,e,n){const{l:o,t:i,r,b:s}=t.rect,a=(o+r)/2,l=(i+s)/2,d=(r-o)/2,g=(s-i)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const w=n,h=g*Math.max(0,1-Math.abs(w-a)/d);return{x:w,y:e==="top"?l-h:l+h}}const c=n,p=d*Math.max(0,1-Math.abs(c-l)/g);return{x:e==="left"?a-p:a+p,y:c}}if(t.shape==="terminal"){const c=Math.min(d,g);if(f){const u=n,M=Math.min(Math.max(u,o+c),r-c),C=u-M,H=Math.abs(C)>=c?0:Math.sqrt(c*c-C*C);return{x:u,y:Math.abs(C)<1e-6?e==="top"?i:s:e==="top"?l-H:l+H}}const p=n,w=p-l,h=Math.abs(w)>=c?0:Math.sqrt(c*c-w*w);return{x:e==="left"?o+c-h:r-c+h,y:p}}return f?{x:n,y:e==="top"?i:s}:{x:e==="left"?o:r,y:n}}function qn(t,e,n){const{l:o,t:i,r,b:s}=e.rect,a=(o+r)/2,l=(i+s)/2,d=(r-o)/2,g=(s-i)/2;if(e.shape==="decision")return Math.abs(t.x-a)/d+Math.abs(t.y-l)/g<1-n/Math.min(d,g);if(e.shape==="terminal"){const f=Math.min(d,g),c=Math.min(Math.max(t.x,o+f),r-f);return Math.hypot(t.x-c,t.y-l)o+n&&t.xi+n&&t.ymatchMedia("(forced-colors: active)").matches;function Bn(t,e){const n=t.querySelector(`.${e}-ruler`),o=new Map;return(i,r)=>{const s=`${r}|${i}`;return o.has(s)||(n.setAttribute("data-f",r),n.textContent=i,o.set(s,n.getBoundingClientRect().width),n.textContent=""),o.get(s)}}var Yt=t=>t?t.split(/\s+/).filter(Boolean):[];function Rn(t,e,n){const o=e.space;let i=e.node,r=e.table;for(const l of t.nodes){if(l.shape==="table"){for(const h of l.columns??[]){const u=h.ref?`${t.rtl?"←":"→"} ${h.ref.table}`:h.type??"",M=o("6")+n(h.name,"mono")+(u?o("3")+n(u,"mono"):0)+2*o("3")+2*e.hair;r=Math.max(r,Math.ceil(M))}r=Math.max(r,Math.ceil(n(l.name,"table")+2*o("3")+2*e.hair+(l.href?16+o("1-5"):0)));continue}const d=l.shape==="terminal"?2*o("5"):2*o("3"),g=l.mark&&!jn()?(l.shape==="participant"?2:1)*o("6"):0;let f=0;const c=l.href?16+o("1-5"):0,p=Yt(l.name);if(p.forEach((h,u)=>{f=Math.max(f,n(h,l.shape==="decision"?"name-500":"name")+(l.kind?0:g)+(u===p.length-1?c:0))}),t.type!=="data-flow")for(const h of Yt(l.kind))f=Math.max(f,n(h,"mono")+g);for(const h of Yt(l.detail))f=Math.max(f,n(h,l.mono?"mono":"sans"));const w=l.shape==="decision"?f/.62:f+d+2*e.hair;i=Math.max(i,Math.ceil(w))}const s=se(t);let a;return t.type==="data-flow"?a=e.lane+s*(i+o("12")):t.type==="schema"?a=s*r+(s-1)*(o("12")+(t.marks?o("3"):0))+(ie(t)?(t.marks?o("6")+o("1"):o("5"))+(Jt(t).lanes>1?o("3"):0):0):t.type==="sequence"?a=s*i+(s-1)*o("5"):a=s*i+(s-1)*o("16")+xe(t)*o("4"),{track:i,table:r,least:Math.max(e.wide,a)}}function qe(t,e){return{x:(n,o)=>o%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,o)=>o%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function le(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Ce(t,e,n){const o=t.map(r=>({...r}));for(let r=1;r=2){const l=i[i.length-2];if(Math.abs(l.x-a.x)<.01&&Math.abs(a.x-s.x)<.01||Math.abs(l.y-a.y)<.01&&Math.abs(a.y-s.y)<.01){i[i.length-1]=s;continue}}i.push(s)}}return i}var It=t=>t.slice(1).map((e,n)=>[t[n],e]);function Qt(t,e,n){const o=[];for(let r=0;rMath.min(h.x,u.x)+.75&&HMath.min(M.y,C.y)+.75&&vr.split(/\s+/).map(parseFloat).filter(s=>Number.isFinite(s)),o=(r,s,a)=>{const l=[];let d=s;for(const g of r)l.push([d,d+g]),d+=g+a;return l},i=o(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0);return{cols:o(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:t.style.getPropertyValue("--_rows").trim()?i.filter((r,s)=>s%2===1):i}}var ct=t=>t==="left"||t==="right",je={top:"bottom",bottom:"top",left:"right",right:"left"};function Be(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Re(t,e,n){const o=[];t.edges.forEach((r,s)=>{const a=t.byId.get(r.from),l=t.byId.get(r.to),[d,g]=e[s],f=a.row===l.row&&ct(d)&&ct(g)&&d===je[g]||a.col===l.col&&!ct(d)&&!ct(g)&&d===je[g];o.push({edge:s,end:"from",node:a,side:d,far:l,straight:f,f:.5},{edge:s,end:"to",node:l,side:g,far:a,straight:f,f:.5})});const i=new Map;for(const r of o){const s=`${r.node.id}.${r.side}`;i.has(s)||i.set(s,[]),i.get(s).push(r)}for(const[r,s]of i){if(s[0].node.shape==="decision")continue;const a=h=>ct(h.side)?h.far.row-h.node.row:h.far.col-h.node.col,l=s.filter(h=>h.straight),d=s.filter(h=>!h.straight);if(d.sort((h,u)=>a(h)-a(u)||(ct(h.side)?h.far.col-u.far.col:h.far.row-u.far.row)*(a(h)<0?1:-1)),s.length>3&&n(`${r.replace(".","'s ")} side has ${s.length} lines; more than three is an error: use another side`),!l.length){d.length===2?(d[0].f=.25,d[1].f=.75):d.length===3?(d[0].f=.25,d[1].f=.5,d[2].f=.75):d.length>3&&d.forEach((h,u)=>{h.f=(u+1)/(d.length+1)});continue}const g=new Map;for(const h of l)g.has(h.far.id)||g.set(h.far.id,[]),g.get(h.far.id).push(h);for(const h of g.values())h.length>1&&h.sort((u,M)=>u.edge-M.edge).forEach((u,M)=>{u.f=h.length===2?M===0?.25:.75:(M+1)/(h.length+1)});const f=Math.min(...l.map(h=>h.f)),c=Math.max(...l.map(h=>h.f)),p=d.filter(h=>a(h)<0),w=d.filter(h=>a(h)>=0);p.forEach((h,u)=>{h.f=f*(u+1)/(p.length+1)}),w.forEach((h,u)=>{h.f=c+(1-c)*(u+1)/(w.length+1)})}return o}function Te(t,e=8,n=8){return qt(t,`port-floors:${e}:${n}`,()=>{const o=At();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return o;const i=t.edges.map(s=>{const a=t.byId.get(s.from),l=t.byId.get(s.to),[d,g]=Be(a,l);return[s.fromSide??d,s.toSide??g]}),r=new Map;for(const s of Re(t,i,()=>{})){if(!ct(s.side)||s.node.shape!=="box")continue;const a=`${s.node.id}.${s.side}`;r.has(a)||r.set(a,[]),r.get(a).push(s.f)}for(const[s,a]of r){if(a.length<2)continue;const l=[...new Set(a.map(f=>Math.round(f*1e6)/1e6))].sort((f,c)=>f-c);let d=Math.max(e/l[0],e/(1-l[l.length-1]));for(let f=1;f{const s=t.byId.get(r.dataset.node);s&&i.set(s.id,{id:s.id,rect:Et(r,n),shape:s.shape,i:s.i})}),i}function We(t,e){const n=e.head,o=e.head/2,{x:i,y:r}=t.tip;return t.dir==="down"?{l:i-o,r:i+o,t:r-n,b:r}:t.dir==="up"?{l:i-o,r:i+o,t:r,b:r+n}:t.dir==="right"?{l:i-n,r:i,t:r-o,b:r+o}:{l:i,r:i+n,t:r-o,b:r+o}}var Fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function He(t,e,n,o){const i=(r,s)=>{const a=r+s-Math.floor(r+s);return a<.005||a>.995?[0]:a<=.5?[-a,1-a]:[1-a,-a]};for(const r of i(t.t,n))for(const s of i(t.l,e)){if(!s&&!r)return t;const a={l:t.l+s,r:t.r+s,t:t.t+r,b:t.b+r};if(o(a))return a}return t}function zn(t,e,n,o,i,r,s,a,l){const d=s.space,g=[],f=[],c=[],p=[],w=d("1"),h=e.filter(u=>t.edges[u.i]?.label).sort((u,M)=>+(t.edges[M.i].kind==="main")-+(t.edges[u.i].kind==="main")||u.i-M.i);for(const u of h){const M=t.edges[u.i].label,C=a(M,"label"),H=16*ne(M),v=u.pts.length-2,E=[];It(u.pts).forEach(([_,D],j)=>{const x=Math.abs(_.y-D.y)<.01,R=x?_.x:_.y;let F=x?D.x:D.y;const Z=Math.sign(F-R)||1;j===v&&(F-=Z*s.head);let K=[[R,F]];for(const m of i)for(const y of x?[m.l,m.r]:[m.t,m.b]){const k=x?_.y:_.x;(x?k>m.t&&km.l&&ky>Math.min(I,B)+1&&y{const k=(m+y)/2,q=x?{x:k,y:_.y}:{x:_.x,y:k};return!i.some(I=>q.x>I.l&&q.xI.t&&q.y1&&rt(m,y)?1:0})}),E.sort((_,D)=>D.pri-_.pri||D.len-_.len);let T=null,tt=!1;const z=(_,D=!0)=>{const j=_e(_,w);return D&&(_.lr.r||_.tr.b)||n.some(x=>Oe(j,x))||g.some(x=>Lt(j,x))||o.heads.some(x=>Lt(j,x))||o.rects.some(x=>Lt(j,x))?!1:!e.some(x=>x.i!==u.i&&It(x.pts).some(([R,F])=>Lt(j,Fe(R,F,x.width))))};for(const _ of E){for(const D of[1/2,1/3,2/3]){const j=_.p+(_.q-_.p)*D,x=[],R=d("2")+u.width/2;if(_.horiz?(_.len>=C+2*d("1")+d("3-5")&&x.push({box:{l:j-C/2-d("1"),r:j+C/2+d("1"),t:_.c-H/2,b:_.c+H/2},on:!0}),x.push({box:{l:j-C/2,r:j+C/2,t:_.c-R-H,b:_.c-R},on:!1}),x.push({box:{l:j-C/2,r:j+C/2,t:_.c+R,b:_.c+R+H},on:!1})):(_.len>=H+d("3")&&x.push({box:{l:_.c-C/2-d("1"),r:_.c+C/2+d("1"),t:j-H/2,b:j+H/2},on:!0}),x.push({box:{l:_.c+R,r:_.c+R+C,t:j-H/2,b:j+H/2},on:!1}),x.push({box:{l:_.c-R-C,r:_.c-R,t:j-H/2,b:j+H/2},on:!1})),T=x.find(F=>z(F.box))??null,T)break;!tt&&x.some(F=>z(F.box,!1))&&(tt=!0)}if(T)break}if(!T){c.push(u.i),tt&&p.push(u.i);continue}const it=He(T.box,l.ox,l.oy,_=>z(_));g.push(it),f.push({i:u.i,text:M,box:it,on:T.on})}return{labels:f,unseated:c,bounded:p}}function De(t,e,n,o){const i=[],r=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(s=>{if(s.getClientRects().length===0||getComputedStyle(s).display==="contents")return;const a=Et(s,e);r.push(a),i.push({l:a.l,r:a.r,t:a.t,b:a.t+1},{l:a.l,r:a.r,t:a.b-1,b:a.b},{l:a.l,r:a.l+1,t:a.t,b:a.b},{l:a.r-1,r:a.r,t:a.t,b:a.b});const l=s.querySelector(`:scope > .${n}-glabel`);l&&l.getClientRects().length&&i.push(Et(l,e))}),t.querySelectorAll(`.${n}-lane`).forEach((s,a)=>{if(!s.getClientRects().length)return;const l=Et(s,e);a>0&&i.push({l:l.l,r:l.r,t:l.t-o/2-.5,b:l.t-o/2+.5});const d=s.querySelector(`.${n}-lane-name`);d&&i.push(Et(d,e))}),{obstacles:{rects:i,heads:[]},groups:r}}function Ge(t,e){const{m:o,tk:i,P:r,drawing:s,origin:a,warn:l}=t,d=i.space,g=Ne(o,s,a,r),f=[...g.values()],c=Tn(s),p=a.left-Math.floor(a.left),w=a.top-Math.floor(a.top),h=qe(p,w),u=s.clientWidth,M=s.clientHeight,C=$=>o.type==="data-flow"?$.col+1:$.col,H=parseFloat(getComputedStyle(s).rowGap)||0,v={w:u,h:M,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:p,oy:w};if(o.type==="sequence")return Wn(t,v,h);let E,T=[];o.type==="schema"?E=o.edges.map($=>{const A=o.byId.get($.from),L=o.byId.get($.to);if(A.col===L.col){const S=A.col===o.cols&&o.cols>1?"left":"right";return[S,S]}return L.col>A.col?["right","left"]:["left","right"]}):(E=o.edges.map($=>{const A=o.byId.get($.from),L=o.byId.get($.to),[S,O]=Be(A,L);return[$.fromSide??S,$.toSide??O]}),T=Re(o,E,l||(()=>{})));const tt=($,A)=>{const L=s.querySelector(`.${r}-node[data-node="${CSS.escape($)}"] .${r}-row[data-row="${A}"]`);if(!L)return 0;const S=Et(L,a);return(S.t+S.b)/2},z=new Map;if(o.type==="schema"){const $=new Map;o.edges.forEach((L,S)=>{const O=`${L.to}.${L.toRow}.${E[S][1]}`;$.set(O,[...$.get(O)??[],S])});const A=L=>{const S=o.edges[L].card?.to;return S==="one"?0:S==="zero-or-one"?1:2};for(const L of $.values()){const S=[...new Set(L.map(A))].sort((O,W)=>O-W);if(S.length>1)for(const O of L)z.set(O,(S.indexOf(A(O))-(S.length-1)/2)*d("2"))}}const it=$=>Math.round($+p)-p,_=o.edges.map(($,A)=>{const[L,S]=E[A],O=g.get($.from),W=g.get($.to),J=Ut($.kind,i);if($.fk){const X=tt($.from,$.fromRow),P=tt($.to,$.toRow)+(z.get(A)??0),yt=h.y(X,J),Bt=h.y(P,J),St=L==="right"?O.rect.r:O.rect.l,xt=S==="right"?W.rect.r:W.rect.l;return{p1:{x:$.card?it(St):St,y:yt},p2:{x:$.card?it(xt):xt,y:Bt},r1:X,r2:Math.abs(yt-Bt)<.01?X:P}}const Y=T.find(X=>X.edge===A&&X.end==="from").f,at=T.find(X=>X.edge===A&&X.end==="to").f;let et=ze(O,L,Y),Q=ze(W,S,at);const N=ct(L)?et.y:et.x;let V=ct(S)?Q.y:Q.x;return ct(L)?et={...et,y:h.y(et.y,J)}:et={...et,x:h.x(et.x,J)},ct(S)?Q={...Q,y:h.y(Q.y,J)}:Q={...Q,x:h.x(Q.x,J)},ct(L)&&ct(S)&&Math.abs(et.y-Q.y)<1.01&&(Q={...Q,y:et.y},V=N),!ct(L)&&!ct(S)&&Math.abs(et.x-Q.x)<1.01&&(Q={...Q,x:et.x},V=N),et=ct(L)?kt(O,L,et.y):kt(O,L,et.x),Q=ct(S)?kt(W,S,Q.y):kt(W,S,Q.x),{p1:et,p2:Q,r1:N,r2:V}}),D=new Set,j=($,A)=>{D.has($)||(D.add($),l?.(`${o.edges[$].from} to ${o.edges[$].to} ${A}, so its line is not drawn; its row still writes the target`))};for(const $ of Jt(o).dropped)j($,"would need a third lane of turn-backs");const x=new Map,R=At();o.type==="schema"&&o.edges.forEach(($,A)=>{const L=o.byId.get($.from),S=o.byId.get($.to);if(Math.abs(L.col-S.col)<2)return;const O=Math.min(L.col,S.col),W=Math.max(L.col,S.col),J=o.nodes.filter(P=>P.col>O&&P.colyt.row<=P&&yt.row2>=P+1)||at.push({key:`g${P}`,y:(Y[P-1][1]+Y[P][0])/2,inner:!0});at.push({key:"top",y:Y[0][0]-d("4"),inner:!1},{key:"bottom",y:Y[Y.length-1][1]+d("4"),inner:!1});const et=(_[A].r1+_[A].r2)/2,Q=t.pick?.[A]??at.slice().sort((P,yt)=>Math.abs(P.y-et)-Math.abs(yt.y-et)||Number(yt.inner)-Number(P.inner)||P.y-yt.y)[0].key;R[A]=Q;const N=E[A][0]==="right"?L.col:L.col-1,V=c.cols[N-1],X=c.cols[N];x.set(A,{corridor:Q,first:V&&X?{key:`c${N}`,span:[V[1],X[0]]}:null,y:0})});const F=new Map;for(const[$,A]of x){const L=o.edges[$],S=F.get(A.corridor)??[],O=S.find(W=>{const J=o.edges[W[0]];return J.to===L.to&&J.toRow===L.toRow&&E[W[0]][1]===E[$][1]&&Math.abs(_[W[0]].p2.y-_[$].p2.y)<.5});O?O.push($):S.length>=2?j($,"would need a third lane in its corridor"):S.push([$]),F.set(A.corridor,S)}for(const $ of[...x.keys()])D.has($)&&x.delete($);const Z=$=>{const A=o.edges[$[0]];return Math.abs(o.byId.get(A.from).col-o.byId.get(A.to).col)*1e4+Math.abs(_[$[0]].p1.x-_[$[0]].p2.x)},K=($,A,L)=>{const S=c.rows;if($==="top")return S[0][0]-d("4")-A*d("3");if($==="bottom")return S[S.length-1][1]+d("4")+A*d("3");const O=Number($.slice(1));return(S[O-1][1]+S[O][0])/2+(A-(L-1)/2)*d("3")},rt=($,A)=>A.forEach((L,S)=>L.forEach(O=>{x.get(O).y=K($,S,A.length)})),U=()=>{for(const[$,A]of F){const L=A.map(S=>S.filter(O=>x.has(O))).filter(S=>S.length);F.set($,L),rt($,$==="top"||$==="bottom"?L.slice().sort((S,O)=>Z(S)-Z(O)):L.slice().sort((S,O)=>Z(O)-Z(S)))}};U();const m=new Map,y=new Set,k=new Map,q=($,A,L,S,O)=>{m.has($)||m.set($,{span:A,vertical:L,members:new Map});const W=m.get($);W.members.has(S)||W.members.set(S,[]),W.members.get(S).push(O)},I=()=>{m.clear(),y.clear(),k.clear(),o.edges.forEach(($,A)=>{if(D.has(A))return;const L=x.get(A);L?.first&&q(L.first.key,L.first.span,!0,`far:${A}`,-(A+1));const[S,O]=E[A],{p1:W,p2:J}=_[A],Y=o.byId.get($.from),at=o.byId.get($.to);let et=null,Q=null,N=!1;if(S===O){if(ct(S)){const V=S==="right"?Math.max(C(Y),C(at)):Math.min(C(Y),C(at))-1,X=c.cols[V-1],P=c.cols[V];X&&P&&(et=`c${V}`,Q=[X[1],P[0]],N=!0)}else{const V=S==="bottom"?Math.max(Y.row2,at.row2):Math.min(Y.row,at.row)-1,X=c.rows[V-1],P=c.rows[V];X&&P&&(et=`r${V}`,Q=[X[1],P[0]],N=!1)}et&&y.add(A)}else if(ct(S)&&ct(O)&&(L||Math.abs(W.y-J.y)>.5)){const V=C(at),X=O==="left",P=c.cols[(X?V-1:V)-1],yt=c.cols[(X?V:V+1)-1];P&&yt&&(et=`c${X?V-1:V}`,Q=[P[1],yt[0]],N=!0)}else if(!ct(S)&&!ct(O)&&Math.abs(W.x-J.x)>.5){const X=O==="top"?at.row-1:at.row2,P=c.rows[X-1],yt=c.rows[X];P&&yt&&(et=`r${X}`,Q=[P[1],yt[0]],N=!1)}!et||!Q||(L&&k.set(A,Q),q(et,Q,N,`${$.to}.${O}.${Math.round(N?J.y:J.x)}`,A))})};I();const B=new Map,ot=$=>{const[A,L]=E[$],{p1:S,p2:O}=_[$],W=x.get($);if(W){const J=k.get($),Y=B.get(-($+1))??(W.first?(W.first.span[0]+W.first.span[1])/2:S.x),at=B.get($)??(J?(J[0]+J[1])/2:O.x);return[S,{x:Y,y:S.y},{x:Y,y:W.y},{x:at,y:W.y},{x:at,y:O.y},O]}if(ct(A)&&ct(L)){if(A===L){const Y=d(o.marks?"6":"4")+(o.type==="schema"&&o.cols===1?(Jt(o).lane.get($)??0)*d("3"):0),at=B.get($)??(A==="right"?Math.max(S.x,O.x)+Y:Math.min(S.x,O.x)-Y);return[S,{x:at,y:S.y},{x:at,y:O.y},O]}if(Math.abs(S.y-O.y)<=.5)return[S,{x:O.x,y:S.y}];const J=B.get($)??(S.x+O.x)/2;return[S,{x:J,y:S.y},{x:J,y:O.y},O]}if(!ct(A)&&!ct(L)){if(A===L){const Y=B.get($)??(A==="bottom"?Math.max(S.y,O.y)+d("4"):Math.min(S.y,O.y)-d("4"));return[S,{x:S.x,y:Y},{x:O.x,y:Y},O]}if(Math.abs(S.x-O.x)<=.5)return[S,{x:S.x,y:O.y}];const J=B.get($)??(S.y+O.y)/2;return[S,{x:S.x,y:J},{x:O.x,y:J},O]}return ct(A)?[S,{x:O.x,y:S.y},O]:[S,{x:S.x,y:O.y},O]},G=$=>{const A=o.edges[$],L=Ut(A.kind,i),S=ot($),O=Ce(S,L,h);let W;return S.length===O.length&&(W=It(S).map(([J,Y])=>Math.abs(J.y-Y.y)<.75?(J.y+Y.y)/2:(J.x+Y.x)/2),W[0]=_[$].r1,W.length>1&&(W[W.length-1]=_[$].r2)),{i:$,from:A.from,to:A.to,kind:A.kind,pts:O,tip:O[O.length-1],dir:le(O),dot:A.fk&&!A.card?O[0]:void 0,card:A.card,width:L,axes:W}},nt=()=>o.edges.flatMap(($,A)=>D.has(A)?[]:[G(A)]);let ft=null;const ut=$=>{ft??(ft=nt());const A=ft.map(L=>$.has(L.i)?G(L.i):L);return{lines:A,score:Nn(A,$)*1e5+Qt(A,void 0,$).length*1e3+de(A.filter(L=>$.has(L.i)),f,o).length}},st=($,A)=>{const L=$.flatMap(S=>{const O=S<0?-S-1:S,{p1:W,p2:J}=_[O],Y=x.get(O);return Y?S<0?[W.y,Y.y]:[Y.y,J.y]:A?[W.y,J.y]:[W.x,J.x]});return[Math.min(...L),Math.max(...L)]},ht=$=>$<0?-$-1:$,bt=$=>{const A=[...$.members.values()].map(S=>({members:S,run:st(S,$.vertical)})).sort((S,O)=>S.run[0]-O.run[0]),L=[];for(const S of A){const O=L[L.length-1];O&&O.some(W=>W.run[0]!(S.length===1&&S[0].members.every(O=>y.has(O))))},wt=$=>(A,L)=>$[A].run[0]<$[L].run[1]+d("8")&&$[L].run[0]<$[A].run[1]+d("8"),Mt=$=>{const A=wt($),L=[];return $.forEach((S,O)=>{let W=0;for(;L.some((J,Y)=>J===W&&A(O,Y));)W++;L.push(W)}),L},vt=$=>Math.max(0,...Mt($))+1;if(o.marks)for(let $=0;$3){A=W.map(J=>J.members.map(ht));break}if(!A)break;const L=O=>Math.max(...O),S=A.filter(O=>O.some(W=>x.has(W))).sort((O,W)=>L(W)-L(O))[0]??A.slice().sort((O,W)=>L(W)-L(O))[0];for(const O of S)j(O,"would need a fourth lane in a marked gutter"),x.delete(O);I()}const pt=($,A,L)=>{const S=$[1]-$[0];if(!o.marks)return $[0]+S/(L+1)*(A+1);const O=i.foot+i.radiusXs,W=L>1?Math.min(S/(L+1),(S-2*O)/(L-1)):0;return($[0]+$[1])/2+(A-(L-1)/2)*W};U();for(const[$,A]of F){if($==="top"||$==="bottom"||A.length<2)continue;const L=new Set(A.flat());let S=A,O=1/0;for(const W of ce(A.slice().sort((J,Y)=>Z(Y)-Z(J)))){rt($,W),ft=null;const J=ut(L);J.scoreat.members);if(o.marks){const at=vt(A),et=wt(A),Q=A.length,N=new Set(L.flat().map(ht)),V=St=>St.forEach((xt,Rt)=>L[Rt].forEach(_t=>B.set(_t,pt($.span,xt,at))));let X=Mt(A),P=1/0,yt=null;const Bt=[X];if(at**Q<=729)for(let St=0;StMath.floor(St/at**_t)%at);xt.every((Rt,_t)=>xt.every((Gt,te)=>te<=_t||Rt!==Gt||!et(_t,te)))&&Bt.push(xt)}for(const St of Bt){V(St);const xt=ut(N);xt.scoreQ.forEach(V=>B.set(V,pt($.span,N,S))));const et=ut(O);et.scoreat.forEach(Q=>B.set(Q,pt($.span,et,S)))),ft=Y}if(v.lines=nt(),o.marks&&(v.lines=v.lines.filter($=>{if(!$.card)return!0;const A=It($.pts),L=([O,W])=>Math.hypot(W.x-O.x,W.y-O.y),S=A.length===1?2*i.foot:i.foot+i.radiusXs-.5;return L(A[0])>=S&&L(A[A.length-1])>=S?!0:(j($.i,"has no room for its marks at an end"),!1)})),x.size){const $=new Set([...x.values()].map(L=>L.corridor)),A=[$.has("top")?"var(--basalt-space-8)":"0px"];for(let L=1;L<=o.rows;L++)A.push("auto",LWe($,i));const $t=zn(o,v.lines,f,lt,dt,{l:0,t:0,r:u,b:M},i,e,{ox:p,oy:w});return v.labels=$t.labels,v.unseated=$t.unseated,v.bounded=$t.bounded,v.overlaps=[...new Set(Ve(v.lines,null).flat())],v}function Nn(t,e){return Ve(t,e).length}function Ve(t,e){const n=[];for(let o=0;o=a)continue;const[u,M]=c?[l.x,d.x]:[l.y,d.y],[C,H]=c?[g.x,f.x]:[g.y,f.y];Math.min(Math.max(u,M),Math.max(C,H))-Math.max(Math.min(u,M),Math.min(C,H))>1&&n.push([r.i,s.i])}}return n}function*ce(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const l=a===r.pts.length-1?Math.max(r.width/2,o.head/2):r.width/2;return s.x-l<-.5||s.x+l>e+.5||s.y-l<-.5||s.y+l>n+.5})&&i.push(r.i);return i}function de(t,e,n){const o=[];for(const i of t){const r=It(i.pts);e.some(s=>r.some(([a,l])=>Cn(a,l,s)))&&o.push(i.i)}return o}function Wn(t,e,n){const{m:o,tk:i,P:r,drawing:s,origin:a}=t,l=i.space,d=new Map;s.querySelectorAll(`.${r}-node`).forEach(v=>d.set(v.dataset.node,Et(v,a)));const g=s.querySelector(`.${r}-steps`),f=g?Et(g,a).b:e.h,c=v=>{const E=d.get(v);return E?n.x((E.l+E.r)/2,i.hair):0};for(const v of o.nodes){const E=d.get(v.id);E&&e.lifelines.push({x:c(v.id),y1:E.b,y2:f})}const p=v=>d.get(v.id),w=new Map;s.querySelectorAll(`.${r}-msg`).forEach(v=>{const E=Et(v,a);w.set(Number(v.querySelector(`.${r}-num`)?.textContent??0),(E.t+E.b)/2)});const h=i.activation,u=h/2,M=v=>{const E=o.byId.get(v.who);if(!E)return null;const T=c(v.who),z=(E.i===o.nodes.length-1&&o.nodes.length>1?-1:1)*(o.rtl?-1:1),it=(v.depth-1)*l("1")*z,_=w.get(v.from)??0,D=w.get(v.to)??_,j=v.from===v.to;return{l:n.x(T-u+it,i.hair),r:n.x(T+u+it,i.hair),t:n.y(j?_-l("2")-l("1"):_,i.hair),b:n.y(j?_+l("2")+l("1"):D,i.hair)}},C=o.bars.map(v=>({bar:v,rect:M(v)})).filter(v=>v.rect);e.bars=C.map(v=>v.rect);const H=(v,E,T)=>C.filter(({bar:tt})=>tt.who===v&&tt.to>=E&&(T?tt.from<=E:tt.fromz.bar.depth-tt.bar.depth)[0]?.rect;return s.querySelectorAll(`.${r}-msg`).forEach(v=>{const E=v.dataset.from,T=v.dataset.to,tt=v.dataset.kind??"plain",z=Ut(tt,i),it=Et(v,a),_=n.y((it.t+it.b)/2,z),D=Number(v.querySelector(`.${r}-num`)?.textContent??0);let j=c(E),x=c(T),R;if(E===T){const y=v.dataset.self==="start"?-l("6"):l("6"),k=H(E,D,!0),q=k?y>0?k.r:k.l:j,I=n.y(_-l("2"),z),B=n.y(_+l("2"),z);R=[{x:q,y:I},{x:n.x(j+y,z),y:I},{x:n.x(j+y,z),y:B},{x:q,y:B}]}else{const y=x>j?1:-1,k=H(E,D,!1),q=H(T,D,!0);k&&(j=y>0?k.r:k.l),q&&(x=y>0?q.l:q.r),R=[{x:j,y:_},{x,y:_}]}e.lines.push({i:D,from:E,to:T,kind:tt,pts:R,tip:R[R.length-1],dir:le(R),width:z});const F=v.querySelector(`.${r}-said`),Z=v.querySelector(`.${r}-note`),K=o.byId.get(E),rt=o.byId.get(T);if(!K||!rt)return;const U=E===T?(()=>{const y=o.nodes[K.i+(v.dataset.self==="start"?-1:1)],k=y?c(y.id):v.dataset.self==="start"?0:e.w;return Math.abs(k-j)-l("6")-l("2-5")-l("2")})():Math.abs(x-j)-2*l("2");Math.max(F?F.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>U+.5&&e.unseated.push(D)}),s.querySelectorAll(`.${r}-fhead`).forEach(v=>{const E=v.parentElement?.querySelector(`:scope > .${r}-fbox`);if(!E)return;[...v.children].reduce((tt,z)=>tt+z.getBoundingClientRect().width,0)+l("3")>E.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${v.querySelector(`.${r}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function Ze(t,e,n,o=At()){const{m:i,tk:r,P:s,drawing:a,origin:l}=t,d=r.space,g=Ne(i,a,l,s),f=[...g.values()],c=l.left-Math.floor(l.left),p=l.top-Math.floor(l.top),w=qe(c,p),h=a.clientWidth,u=a.clientHeight,M={w:h,h:u,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:p},C=At();if(i.type==="sequence"||i.type==="schema")return{geo:M,grow:C};const H=h-(parseFloat(getComputedStyle(a).paddingRight)||0),v=(x,R,F)=>{const Z=[x];for(let K=1;K<=(Ot(o,R)??0);K++)Z.push({...x,t:x.t+F*d("4")*K,b:x.b+F*d("4")*K});return Z},E=new Map;a.querySelectorAll(`.${s}-node`).forEach(x=>{const R=x.parentElement,F=Et(R,l),Z=getComputedStyle(R);E.set(x.dataset.node,F.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const T=i.nodes,tt=x=>g.get(T[x].id),z=[],it=x=>Ut(i.edges[x].kind,r);i.edges.forEach((x,R)=>{const F=n.routes[R],Z=g.get(x.from),K=g.get(x.to),rt=it(R);let U=[];const m=x.label,y=m?e(m,"label"):0,k=m?16*ne(m):16,q=d("4");if(F==="down"||F==="up"){const B=Math.max(Z.rect.l,K.rect.l),ot=Math.min(Z.rect.r,K.rect.r),G=i.edges.map((st,ht)=>({o:st,j:ht})).filter(({o:st,j:ht})=>(n.routes[ht]==="down"||n.routes[ht]==="up")&&(st.from===x.from&&st.to===x.to||st.from===x.to&&st.to===x.from)),nt=G.findIndex(st=>st.j===R),ft=G.length<2?.5:G.length===2?nt===0?.25:.75:(nt+1)/(G.length+1),ut=w.x(B+(ot-B)*ft,rt);if(U=F==="down"?[kt(Z,"bottom",ut),kt(K,"top",ut)]:[kt(Z,"top",ut),kt(K,"bottom",ut)],m){let st=Math.min(U[0].y,U[1].y),ht=Math.max(U[0].y,U[1].y);F==="down"?ht-=r.head:st+=r.head;const bt=[...a.querySelectorAll(`.${s}-group`)].map(pt=>Et(pt,l));let wt=[[st,ht]];for(const pt of bt)for(const lt of[pt.t,pt.b])wt=wt.flatMap(([dt,$t])=>lt>dt+1&<<$t-1?[[dt,lt],[lt,$t]]:[[dt,$t]]);const Mt=(pt,lt)=>bt.some(dt=>(pt+lt)/2>dt.t&&(pt+lt)/2dt.l&&ut1){const pt=wt.filter(([dt,$t])=>!Mt(dt,$t));[st,ht]=(pt.length?pt:wt).reduce((dt,$t)=>$t[1]-$t[0]>dt[1]-dt[0]?$t:dt)}const vt=[1/2,1/3,2/3].map(pt=>{const lt=st+(ht-st)*pt;return{l:ut-y/2-d("1"),r:ut+y/2+d("1"),t:lt-k/2,b:lt+k/2}});z.push({k:R,cands:vt,on:!0,card:F==="down"?x.to:x.from})}}else if(F==="trunk"||F==="rail"){const B=w.x(Math.max(Z.rect.l,F==="rail"?K.rect.l:Z.rect.l)+d(F==="trunk"?"8":"3"),rt),ot=kt(Z,"bottom",B);if(F==="rail"){if(U=[ot,kt(K,"top",B)],m){const G=K.rect.t-d("6");z.push({k:R,cands:v({l:B+d("2-5"),r:B+d("2-5")+y,t:G-k/2,b:G+k/2},x.to,-1),on:!1,card:x.to})}}else{const G=w.x(K.rect.l+d("6"),rt),nt=w.y(K.rect.t-q,rt);U=[ot,{x:B,y:nt},{x:G,y:nt},kt(K,"top",G)],m&&z.push({k:R,cands:v({l:G+d("2-5"),r:G+d("2-5")+y,t:nt-k/2,b:nt+k/2},x.to,-1),on:!1,card:x.to})}}else{const B=Math.min(E.get(x.from)??h,E.get(x.to)??h),ot=w.x(n.gutter?H+(n.lanes[R]+1)*d("3-5"):B-d("2-5"),rt),G=w.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[R],rt),nt=kt(Z,"right",G),ft=F==="end-down",ut=i.edges.map((lt,dt)=>({o:lt,j:dt})).filter(({o:lt,j:dt})=>n.routes[dt]===F&<.to===x.to).sort((lt,dt)=>n.lanes[dt.j]-n.lanes[lt.j]||lt.j-dt.j),st=Math.max(0,ut.findIndex(({j:lt})=>lt===R)),ht=K.rect.r-d("6")-st*d("3"),bt=K.rect.r-d("6")-(ut.length-1)*d("3"),wt=w.x(ht,rt),Mt=ft?K.rect.t-q-st*d("5"):K.rect.b+q+st*d("5"),vt=w.y(Mt,rt);U=[nt,{x:ot,y:nt.y},{x:ot,y:vt},{x:wt,y:vt},kt(K,ft?"top":"bottom",wt)];const pt=ft?x.to:T[K.i+1]?.id??x.to;m&&z.push({k:R,cands:v({l:bt-d("2-5")-y,r:bt-d("2-5"),t:Mt-k/2,b:Mt+k/2},pt,ft?-1:1),on:!1,card:pt})}const I=Ce(U,rt,w);M.lines.push({i:R,from:x.from,to:x.to,kind:x.kind,pts:I,tip:I[I.length-1],dir:le(I),width:rt})}),M.crossings=Qt(M.lines),M.through=de(M.lines,f,i),M.outside=Ke(M.lines,h,u,r);const{obstacles:_}=De(a,l,s,0);_.heads=M.lines.map(x=>We(x,r));const D=[],j={l:0,t:0,r:h,b:u};for(const x of z){const R=K=>{const rt=_e(K,d("1"));return K.lj.r+.5||K.tj.b+.5||f.some(U=>Oe(rt,U))||D.some(U=>Lt(rt,U))||_.heads.some(U=>Lt(rt,U))||_.rects.some(U=>Lt(rt,U))||M.lines.some(U=>U.i!==x.k&&It(U.pts).some(([m,y])=>Lt(rt,Fe(m,y,U.width))))},F=x.cands.find(K=>!R(K));F||(C[x.card]=(C[x.card]??0)+1,M.unseated.push(x.k));const Z=F?He(F,c,p,K=>!R(K)):x.cands[0];D.push(Z),M.labels.push({i:x.k,text:i.edges[x.k].label,box:Z,on:x.on})}return{geo:M,grow:C}}function Je(t,e,n=0){const o=s=>String(Math.round(s*100)/100);let i=`M${o(t[0].x)} ${o(t[0].y)}`;for(let s=1;s{const{crow:D,ring:j}=Se(tt,z.x,z.y,it,n.head,n.dot);return`${j?``:""}`};return`${T(e.card.from,v,Math.sign(E.x-v.x)||1,"from")}${T(e.card.to,e.tip,-r.x||1,"to")}`}const s=e.kind==="dashed",a=n.head,l=n.head/2,d=s?1:a-1,g=e.pts.map(v=>({...v})),f=g[g.length-1];f.x-=r.x*d,f.y-=r.y*d;const c=e.tip.x-r.x*a,p=e.tip.y-r.y*a,w=-r.y*l,h=r.x*l,u=v=>Math.round(v*100)/100,M=mt(e.kind),C=s?``:``,H=e.dot?``:"";return`${C}${H}`}function Xe(t,e,n,o){const i=new Map,r=new Map;for(const a of e.crossings)r.has(a.under)||r.set(a.under,[]),r.get(a.under).push(a);let s="";for(const[a,l]of r){const d=`${o}-cut-${a}`;i.set(a,d);const g=l.map(f=>{const c=e.lines[f.top],p=e.lines[f.under],w=c.width/2+n.cut,h=p.width/2+1;return f.underVertical?``:``}).join("");s+=`${g}`}return{defs:s,ids:i}}function Ue(t,e,n,o){const{defs:i,ids:r}=Xe(t,e,n,o),s=e.lifelines.map(g=>``).join("")+(e.bars??[]).map(g=>``).join(""),a=e.lines.map((g,f)=>Hn(t,g,n,r.get(f)??null,g.from===g.to?n.radiusXs:n.radius)).join(""),l=`${i?`${i}`:""}${s}${a}`,d=e.labels.map(g=>`1?' data-lines="2"':""} style="left:${Math.round(g.box.l*100)/100}px;top:${Math.round(g.box.t*100)/100}px;width:${Math.round((g.box.r-g.box.l)*100)/100}px">${g.text.split(` -`).map(mt).join("
")}
`).join("");return l+d}function fe(t,e,n,o,i,r,s,a){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:i,geo:null,ink:"",tokens:null};const g=On(t),f=Bn(d,n),c=Rn(e,g,f);a?.(c.least);const p=t.clientWidth,w=(()=>{const _=document.activeElement;return _&&d.contains(_)&&_.dataset.node?_.dataset.node:void 0})(),h=_=>jt(e,_)?{..._,stop:_.stop&&e.byId.has(_.stop)?_.stop:e.nodes[0]?.id,keep:void 0}:{..._,stop:_.stop??e.nodes[0]?.id,keep:w&&_.layout!=="drawn"?w:void 0};let u=!1;const M=_=>{if(u=!1,e.type!=="flowchart")return _;r({..._,heights:void 0,words:void 0});const D=At(),j=At();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const R=x.querySelector(`.${n}-words`);if(!R)return;const F=x.getBoundingClientRect(),Z=U=>{const m={w:U.width+2*g.space("2-5"),h:U.height+2*g.space("2")},y=1-m.w/F.width,k=y>.05?m.h/2/y:m.h*10;return Math.max(g.space("16"),Math.ceil(F.width/5),Math.ceil(2*k))},K=R.getBoundingClientRect();let rt=Z(K);if(rt>F.width){const U=q=>(x.style.setProperty("--_ww",`${q}px`),R.getBoundingClientRect()),m=Math.floor(x.clientWidth-2*g.space("2-5"));let y=Math.ceil(K.width),k=K.height;for(;y1;){const G=q+I>>1;U(G).heightF.width&&(u=!0)}),{..._,heights:D,words:Object.keys(j).length?j:void 0}},C=()=>({m:e,tk:g,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:s}),H=i.autoOpen?{open:!1,autoOpen:void 0}:{},v=(_,D)=>D.map(j=>Dt(e,_.lines.find(x=>x.i===j))).join(", ");if(e.text)return{dyn:{...i,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:g,least:c.least};if(p>=c.least&&!e.unplaced){const _=R=>{let F=h({...i,...H,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:R||void 0,rows:void 0});F=M(F),r(F);let Z=Ge(C(),f);return Z.corridors&&(F={...F,rows:Z.corridors.rows},r(F),Z=Ge({...C(),pick:Z.corridors.pick},f)),{dd:F,g:Z}};let{dd:D,g:j}=_(!1);const x=R=>R.through.length>0||R.outside.length>0||(R.overlaps?.length??0)>0||(R.misfit?.length??0)>0||u;if(!x(j)&&j.unseated.length&&j.unseated.every(R=>j.bounded?.includes(R))){const R=_(!0);!x(R.g)&&!R.g.unseated.length&&({dd:D,g:j}=R)}if(!x(j)&&!j.unseated.length)return j.crossings.length&&s?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the drawn layout: ${j.crossings.map(R=>`${Dt(e,j.lines[R.top])} over ${Dt(e,j.lines[R.under])}`).join("; ")}`),{dyn:D,geo:j,ink:Ue(n,j,g,o),tokens:g,least:c.least};u&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: a decision would be taller than it is wide`),j.misfit?.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: ${j.misfit.join("; ")}`),j.through.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: ${v(j,j.through)} would pass through a node`),j.overlaps?.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: ${v(j,j.overlaps)} would lie on one another`),j.outside.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: ${v(j,j.outside)} would leave the drawing`),j.unseated.length&&s?.(`the drawn layout does not fit at ${Math.round(p)}px: no clean seat for ${j.unseated.map(R=>e.type==="sequence"?`message ${R}`:`"${e.edges[R]?.label}"`).join(", ")}`)}let E=h({...i,...H,layout:"stacked",heights:void 0,grow:At(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0,rows:void 0});if(E=M(E),r(E),e.type==="sequence"||e.type==="schema")return{dyn:E,geo:null,ink:"",tokens:g,least:c.least};const T=ke(e);let tt=Ze(C(),f,T,E.grow);for(let _=0;_<6&&Object.keys(tt.grow).length;_++){const D=At(E.grow);for(const[j,x]of Object.entries(tt.grow))D[j]=(Ot(D,j)??0)+x;E={...E,grow:D},r(E),tt=Ze(C(),f,T,D)}const z=tt.geo;if(!T.third&&T.laneCount>2&&s?.(`the stacked drawing uses ${T.laneCount} end lanes (four at most)`),z.unseated.length>0||z.through.length>0||z.outside.length>0||T.third){z.unseated.length&&s?.(`the stacked drawing has no clean seat for ${[...new Set(z.unseated)].map(j=>`"${e.edges[j]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),z.through.length&&s?.(`in the stacked drawing ${v(z,z.through)} would pass through a node, so its lines are not drawn`),z.outside.length&&s?.(`in the stacked drawing ${v(z,z.outside)} would leave the drawing, so its lines are not drawn`),T.third&&s?.("the stacked drawing would need a fifth end lane, so its lines are not drawn");const _={...z,lines:[],labels:[],crossings:[]};return{dyn:h({...E,grow:At(),bare:!0,open:i.bare?i.open:!0,autoOpen:i.bare?i.autoOpen:i.open?void 0:!0}),geo:_,ink:"",tokens:g,least:c.least}}return z.crossings.length&&s?.(`${z.crossings.length} crossing${z.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${z.crossings.map(_=>`${Dt(e,z.lines[_.top])} over ${Dt(e,z.lines[_.under])}`).join("; ")}`),{dyn:E,geo:z,ink:Ue(n,z,g,o),tokens:g,least:c.least}}function Dt(t,e){const n=t.byId.get(e.from)?.name??e.from,o=t.byId.get(e.to)?.name??e.to;return`${n} to ${o}`}function Dn(t,e,n,o,i,r){const s=new Set;if(r){s.add(r);for(const h of n?.lines??[])h.from===r&&s.add(h.to),h.to===r&&s.add(h.from)}if(t.toggleAttribute("data-tracing",!!r),t.querySelectorAll(`.${e}-node`).forEach(h=>h.toggleAttribute("data-near",s.has(h.dataset.node))),!n||!o)return;const a=h=>!!r&&(h.from===r||h.to===r),l=t.querySelector(`.${e}-edges`),d=new Map;t.querySelectorAll(`.${e}-edge`).forEach(h=>d.set(h.getAttribute("data-edge"),h));for(const h of n.lines){const u=d.get(String(h.i));u&&(u.toggleAttribute("data-lit",a(h)),u.toggleAttribute("data-dim",!!r&&!a(h)))}if(t.querySelectorAll(`.${e}-label`).forEach(h=>{const u=n.lines.find(M=>String(M.i)===h.dataset.edge);h.toggleAttribute("data-lit",!!(u&&a(u)))}),l){for(const h of n.lines)if(a(h)){const u=d.get(String(h.i));u&&l.appendChild(u)}}const g=Qt(n.lines,a),{defs:f,ids:c}=Xe(e,{...n,crossings:g},o,i),p=t.querySelector(`.${e}-svg`);if(!p)return;let w=p.querySelector("defs");!w&&f&&(w=document.createElementNS("http://www.w3.org/2000/svg","defs"),p.insertBefore(w,p.firstChild)),w&&(w.innerHTML=f),n.lines.forEach((h,u)=>{const M=d.get(String(h.i))?.querySelector(`.${e}-line`);if(!M)return;const C=c.get(u);C?M.setAttribute("mask",`url(#${C})`):M.removeAttribute("mask")})}var Gn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Vn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Gn()||Zn(t)?"done":"pending")}}var Kn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Zn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Kn(t))!==null}catch{return!1}}function Ye(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Jn(t,e,n,o=!1,i=!1){const r=o?Zt(t):null;if(r&&n.startsWith("Arrow")){const d={ArrowRight:i?"left":"right",ArrowLeft:i?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return d?r[e]?.[d]??null:null}const s=t.byId.get(e)?.i??0,a=t.nodes.length;let l;if(n==="ArrowRight"||n==="ArrowDown")l=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")l=s-1;else if(n==="Home")l=0;else if(n==="End")l=a-1;else return null;return t.nodes[Math.max(0,Math.min(a-1,l))].id}var Xn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Qe=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],Un=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad","--_gw","--_mh","--_rows","--_row-gap"],Pe=t=>t==null||t===!1;function Yn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Pt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const o=n?Qe:Xn;for(const s of o)Pe(e.a[s])&&t.removeAttribute(s);for(const[s,a]of Object.entries(e.a)){if(s==="class")continue;if(s==="style"){const d=t.style,g=new Map(String(a??"").split(";").map(f=>{const c=f.indexOf(":");return[f.slice(0,c).trim(),f.slice(c+1).trim()]}).filter(([f])=>f));for(const[f,c]of g)d.getPropertyValue(f).trim()!==c&&d.setProperty(f,c);for(const f of Un)g.has(f)||d.removeProperty(f);continue}if(n&&!Qe.includes(s))continue;if(Pe(a)){t.removeAttribute(s);continue}const l=a===!0?"":String(a);t.getAttribute(s)!==l&&t.setAttribute(s,l)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(s=>typeof s!="string"&&"slot"in s))return;const i=[...t.children];let r=0;for(const s of e.c)if(!(typeof s=="string"||"slot"in s)){for(let a=r;at.querySelector(`.${e}-node[data-node="${CSS.escape(r)}"]`);n&&i(n)?.setAttribute("tabindex","-1"),i(o)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",o=0;function i(c,p,w){return{prefix:n,base:c,hasSource:p.source!==void 0&&p.source!==null&&p.source!=="",hiddenClass:"visually-hidden",viewer:w?w.keys:void 0}}function r(c,p,w,h){var u=function(M){return''+mt(M)+""};return{source:mt(String(p.source||"")),summary:mt(String(p.summary||"")),hint:re(c).map(function(M){return""+M.keys.map(u).join(" ")+" "+mt(M.words)+""}).join(""),toggle:'"}}function s(c,p,w){var h=zt(c),u=Xt(h,{},i(p,c,w)),M=oe(u,r(h,c,p,!1)),C=M.indexOf(">");return{open:M.slice(0,C+1),inner:M.slice(C+1,M.length-9),warnings:h.warnings}}var a=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-marks","data-layout","data-measured","data-bare"],l=["--_cols","--_gpad","--_track"];function d(c,p,w,h){c.__diagram&&c.__diagram.stop();var u=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),M=getComputedStyle(c).direction==="rtl",C=p.layout==="auto"&&(p.type==="architecture"||p.type==="flowchart"||p.type==="schema"),H=C?Array.isArray(p.placement)?p.placement:p.placement?[p.placement]:[]:[];C&&!H.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var v=p.direction?[p.direction]:p.type==="flowchart"?["down","right"]:["right","down"],E=function(N){for(var V=0;V .diagram-drawing")){if(!u||!c.querySelector("#"+CSS.escape(u+"-title"))){for(;document.getElementById("dg"+ ++o+"-title"););u="dg"+o}var tt=s(p,u,h),z=document.createElement("div");z.innerHTML=tt.open+"";var it=z.firstChild;a.forEach(function(N){c.removeAttribute(N)}),l.forEach(function(N){c.style.removeProperty(N)});for(var _=0;_ :not(script[data-diagram])").forEach(function(N){N.remove()}),c.insertAdjacentHTML("beforeend",tt.inner)}T.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var j=i(u,p,h),x={},R=null,F=null,Z=null,K=null,rt=Object.create(null),U=function(N){rt[N]||(rt[N]=1,console.warn("Basalt diagram: "+N))},m=function(N){Pt(c,Xt(T,N,j))},y=c.querySelector(".diagram-ink"),k=c.querySelector(".diagram-toggle"),q=!h&&T.motion.animated&&typeof e.diagramMotion=="function",I=null,B=null,ot=function(){q&&Ye(c)};function G(){Dn(c,n,R&&R.geo,R&&R.tokens,u,F||K||Z),ut()}var nt=null,ft=!h&&matchMedia("(hover: none), (pointer: coarse)").matches;function ut(){var N=ft&&!h&&y&&y.innerHTML!=="";if(c.toggleAttribute("data-touch",!!(ft&&!h)),N&&!nt){var V=c.querySelector(":scope > .diagram-foot");if(!V)return;nt=document.createElement("button"),nt.type="button",nt.className="btn diagram-clear",nt.setAttribute("data-variant","secondary"),nt.setAttribute("data-size","sm"),nt.innerHTML="Clear highlight",nt.addEventListener("click",function(){K&&(K=null,G())}),V.appendChild(nt)}else!N&&nt&&(nt.remove(),nt=null);nt&&(K?nt.removeAttribute("aria-disabled"):nt.setAttribute("aria-disabled","true"))}function st(N){if(!N.defaultPrevented){var V=un(c,n,N,K);V!==void 0&&(ot(),ft=!0,K=V,G())}}function ht(){k&&(k.setAttribute("aria-expanded",String(!!x.open)),k.firstElementChild.textContent=x.open?"Hide the list":"View as list")}function bt(){if(C&&H.length>1&&!h){for(var N=null,V=0;V1&&h&&!p.direction&&h.room){for(var Bt=h.room(),St=-1,xt=null,Rt=0;RtSt+1e-6&&(St=tn,xt=Gt)}}}xt&&(T=xt)}R=(h?h.measure:fe)(c,T,n,u,x,m,U),x=R.dyn,m(x),ht();var ue=c.querySelector(":scope > .diagram-hint");if(ue){var en=re(T,x.layout==="drawn").map(function(Wt){return""+Wt.keys.map(function(Pn){return''+mt(Pn)+""}).join(" ")+" "+mt(Wt.words)+""}).join("");ue.innerHTML!==en&&(ue.innerHTML=en)}jt(T,x)||(Z=K=null);var nn=y&&R.ink!==B;nn&&(y.innerHTML=R.ink,B=R.ink),G(),q&&R.tokens&&(Vn(c,!!(R.geo&&R.geo.lines.length)),nn&&I&&I.redrawn()),h&&h.onMeasured&&R.tokens&&h.onMeasured(R,c),T.text&&typeof e.diagramText=="function"&&e.diagramText(c,T,p)}function wt(N){x=N,m(x)}function Mt(N){var V=x.stop;x=Object.assign({},x,{stop:N}),Qn(c,n,V,N)}var vt=function(N){var V=N&&N.closest?N.closest(".diagram-node"):null;return V&&c.contains(V)?V:null};function pt(N){var V=vt(N.target);if(!(!V||N.defaultPrevented)){if(ot(),N.key==="Escape"){!h&&(F||Z||K)&&(N.preventDefault(),F=Z=K=null,G());return}if(jt(T,x)){var X=Jn(T,V.getAttribute("data-node"),N.key,x.layout==="drawn");if(X){N.preventDefault(),Mt(X);var P=c.querySelector('.diagram-node[data-node="'+CSS.escape(X)+'"]');P&&P.focus()}}}}function lt(N){var V=vt(N.target);if(V){ot();var X=V.getAttribute("data-node");F=V.matches(":focus-visible")?X:null,jt(T,x)&&x.stop!==X&&Mt(X),G()}}function dt(N){var V=vt(N.target);V&&(vt(N.relatedTarget)||(F=null),x.keep===V.getAttribute("data-node")&&wt(Object.assign({},x,{keep:void 0})),G())}function $t(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var V=vt(N.target);V&&ot();var X=V&&jt(T,x)?V.getAttribute("data-node"):null;X!==Z&&(Z=X,G())}}function $(){Z&&(Z=null,G())}function A(){ot(),wt(Object.assign({},x,{open:!x.open,autoOpen:void 0})),ht()}c.addEventListener("keydown",pt),c.addEventListener("focusin",lt),c.addEventListener("focusout",dt),c.addEventListener("pointerover",$t),c.addEventListener("pointerleave",$),c.addEventListener("click",st),k&&k.addEventListener("click",A),bt();var L=c.clientWidth,S=0,O=!0,W=new ResizeObserver(function(){Math.abs(c.clientWidth-L)<.5||(L=c.clientWidth,cancelAnimationFrame(S),S=requestAnimationFrame(bt))});W.observe(c),document.fonts&&document.fonts.ready.then(function(){O&&bt()});var J=matchMedia("(forced-colors: active)"),Y=T.nodes.some(function(N){return N.mark});Y&&J.addEventListener("change",bt),q&&(I=e.diagramMotion(c,{fig:c,P:n,base:u,model:function(){return T},geo:function(){return R&&R.geo},tokens:function(){return R&&R.tokens}},p));var at=!h&&p.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,p,{model:T,settle:ot,animated:q}):null,et=c.querySelector(":scope > .diagram-foot"),Q=!h&&p.export===!0&&et&&typeof e.diagramExport=="function"?e.diagramExport(et,c):[];c.__diagram={stop:function(){at&&at.destroy(),Q.forEach(function(N){N.remove()}),O=!1,W.disconnect(),cancelAnimationFrame(S),Y&&J.removeEventListener("change",bt),I&&I.destroy(),c.removeEventListener("keydown",pt),c.removeEventListener("focusin",lt),c.removeEventListener("focusout",dt),c.removeEventListener("pointerover",$t),c.removeEventListener("pointerleave",$),c.removeEventListener("click",st),nt&&nt.remove(),k&&k.removeEventListener("click",A)},layout:bt,key:g(p),send:I&&I.sendValue?I.sendValue:null}}function g(c){try{return JSON.stringify(c,function(p,w){return p==="packet"&&w&&typeof w=="object"?Object.assign({},w,{send:void 0}):w})}catch{return null}}function f(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var p=c.querySelector(":scope > script[data-diagram]");if(p)try{d(c,JSON.parse(p.textContent),!0)}catch(w){console.error("Basalt diagram: this figure could not be drawn",w)}}})}e.diagramMarkup=s,e.diagramKit={draw:d,buildModel:zt,figureKey:bn,figureList:An,hintEntries:re,toHtml:oe,escapeHtml:mt,settleEntrance:Ye,measureFigure:fe},t.diagram=function(c,p){var w=c.__diagram,h=w&&w.send?g(p):null;if(h!==null&&h===w.key){w.send(p.packet?p.packet.send:void 0);return}d(c,p)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); +(()=>{var on=["top","right","bottom","left"],sn=["main","plain","dashed"],pe=["one","zero-or-one","one-or-many","zero-or-many"],Ft={one:"Exactly one","zero-or-one":"Zero or one","one-or-many":"One or many","zero-or-many":"Zero or many"},an=[2,3,4,5,6],gt=t=>t==null||t===""?void 0:String(t),At=t=>Object.assign(Object.create(null),t),qt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function zt(t,e={}){const o=e.checks!==!1,l=[],a=m=>{l.push(m)},s=t.legend??{},r={};for(const m of["main","plain","dashed","focal","group","activation"]){const y=gt(s[m]);y&&(r[m]=y)}const i=t.stepLabel,d=typeof i=="function"?m=>String(i(m)):typeof i=="string"?(m=>i.replace("{n}",String(m))):m=>`Step ${m}`,h=t.shapeLabels??{},f={terminal:gt(h.terminal)??"Start or end",step:gt(h.step)??"Step",decision:gt(h.decision)??"Decision"},c=t.heading===void 0?3:an.includes(t.heading)?t.heading:(a(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),g=(m,y)=>m==null?"plain":sn.includes(m)?m:(a(`"${String(m)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),$=m=>{if(m!=null){if(on.includes(m))return m;a(`"${String(m)}" is not a side (top, right, bottom or left): the derived side is used`)}},p=(m,y)=>typeof m=="number"&&Number.isInteger(m)&&m>=1?m:(t.layout==="auto"&&m==null||a(`${y} is ${JSON.stringify(m)}, not a whole number from 1: it is placed at 1`),1),u=[],x=[];let C=[];const W=[],v=[],S=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(S)||a(`"${String(S)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),S==="architecture"||S==="flowchart"){for(const m of t.nodes??[]){const y=S==="flowchart"&&m.shape==="decision"?"decision":S==="flowchart"&&m.shape==="terminal"?"terminal":"box",E=String(m.id??""),q=p(m.row,`the row of ${E}`);u.push({id:E,i:u.length,name:String(m.name??""),kind:y==="decision"?void 0:gt(m.kind),detail:y==="decision"?void 0:gt(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:p(m.col,`the column of ${E}`),row:q,row2:q,branch:!!m.branch,shape:y,group:S==="architecture"?gt(m.group):void 0,mark:S==="architecture"?ee(m.mark):void 0})}if(S==="architecture"){const m=(t.groups??[]).map(_=>({id:String(_.id??""),label:String(_.label??""),parent:gt(_.parent)})),y=new Map(m.map(_=>[_.id,_])),E=_=>{if(!_.parent)return 1;const R=y.get(_.parent);return R?R.parent===_.id||R.id===_.id?(a(`the groups "${_.label}" and "${R.label}" are each other's parent`),_.parent=void 0,1):R.parent?(a(`the group "${_.label}" is a third level: groups nest two deep`),_.parent=void 0,1):2:(a(`the group "${_.label}" names the parent "${_.parent}", which is not a group`),_.parent=void 0,1)},q=m.map(E);m.forEach((_,R)=>W.push({..._,depth:q[R],members:u.filter(U=>U.group===_.id).map(U=>U.id),all:[]}));for(const _ of W)_.all=[..._.members,...W.filter(R=>R.parent===_.id).flatMap(R=>R.members)];W.sort((_,R)=>_.depth-R.depth)}}else if(S==="data-flow"){C=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const m=new Map(C.map((y,E)=>[y.id,E+1]));for(const y of t.nodes??[]){const E=String(y.id??""),q=String(y.lane??""),_=m.get(q);_===void 0&&a(`a node (${E}) names the lane "${q}", which is not in lanes`);const R=u.length+1;u.push({id:E,i:u.length,name:String(y.name??""),kind:d(R),detail:gt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:p(y.col,`the column of ${E}`),row:_??1,row2:_??1,branch:!1,shape:"box",lane:_??1,laneLabel:C[(_??1)-1]?.label??q,step:R,mark:ee(y.mark)})}}else if(S==="sequence"){(t.participants??[]).forEach((q,_)=>{const R=String(q.name??"");u.push({id:String(q.id??""),i:_,name:R,kind:gt(q.kind),mono:!1,focal:!!q.focal,col:_+1,row:1,row2:1,branch:!1,shape:"participant",short:gt(q.short)??R,mark:ee(q.mark)})});let m=0;const y=new Map(u.map(q=>[q.id,q.col])),E=(q,_)=>{let R=1/0,U=-1/0;for(const G of q??[]){if(!G||typeof G!="object")continue;if("band"in G){_>0&&a(`the band "${String(G.band)}" is inside a frame: a band is the whole figure's`),v.push({band:String(G.band??"")});continue}if("frame"in G){if(_>=2){a("a frame is a third level: frames nest two deep");continue}const Mt=G.frame==="alt"||G.frame==="loop"||G.frame==="opt"?G.frame:"opt",vt=Mt==="alt"?G.branches??[]:[{label:G.label,steps:G.steps}];Mt==="alt"&&vt.length<2&&a("an alt frame has one branch: it needs two or more");const ut=String(vt[0]?.label??"");ut.length>40&&a(`the frame label "${ut}" is over 40 characters`);const ft=v.length;v.push({open:Mt,label:ut,depth:_+1,a:0,b:0}),vt.forEach((it,bt)=>{if(bt){const k=String(it.label??"");k.length>40&&a(`the frame label "${k}" is over 40 characters`),v.push({otherwise:k,depth:_+1})}it.steps?.length||a(`a frame or branch ("${String(it.label??"")}") is empty`);const[b,A]=E(it.steps??[],_+1);R=Math.min(R,b),U=Math.max(U,A);const L=v[ft];L.a=Math.min(L.a||1/0,b),L.b=Math.max(L.b,A)}),v.push({close:_+1});continue}m++;const ht=String(G.label??"");ht.includes(` +`)&&a(`message ${m}'s label has a break: a message's second line is its note`);const pt=String(G.from??""),lt=String(G.to??"");v.push({n:m,from:pt,to:lt,label:Lt(ht),note:gt(G.note),kind:g(G.kind,`message ${m}`),activate:G.activate===!0||void 0,deactivate:G.deactivate===!0||void 0});const ct=y.get(pt)??1,mt=y.get(lt)??1,wt=ct===mt?ct===u.length?ct-1:ct+1:ct;R=Math.min(R,ct,mt,wt),U=Math.max(U,ct,mt,wt)}return[R,U]};E(t.steps??[],0);for(const q of v)"open"in q&&!Number.isFinite(q.a)&&(q.a=1,q.b=Math.max(1,u.length))}else if(S==="schema")for(const m of t.tables??[]){const y=String(m.name??""),[E,q]=Array.isArray(m.row)?m.row:[m.row,m.row],_=p(E,`the row of ${y}`),R=Math.max(_,p(q,`the last row of ${y}`)),U=m.more===void 0||m.more===null?void 0:Number.isInteger(m.more)&&m.more>0?m.more:(a(`${y}'s "more" is ${JSON.stringify(m.more)}, not a whole number from 1: it is left out`),void 0);u.push({id:y,i:u.length,name:y,mono:!0,focal:!!m.focal,col:p(m.col,`the column of ${y}`),row:_,row2:R,branch:!1,shape:"table",more:U,columns:(m.columns??[]).map(G=>({name:String(G.name??""),type:gt(G.type),key:G.key==="PK"||G.key==="FK"?G.key:(G.key!==void 0&&G.key!==null&&a(`${y}.${String(G.name)}'s key is "${String(G.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(S==="architecture"||S==="flowchart"||S==="schema")){const m=S==="schema"?t.tables:t.nodes;o&&(m??[]).some(E=>E&&(E.col!==void 0||E.row!==void 0))&&a('a card under layout="auto" has a col or row, which is not read: there are no hints');const y=e.placement?.cells;y||(T=!0);for(const E of u){const q=y?.[E.id];E.col=q?.col??1,E.row=E.row2=q?.row??1}}else t.layout==="auto"&&a(`layout="auto" is for an architecture, a flowchart or a schema, not a ${S}`);((S==="schema"?t.tables:S==="sequence"?t.participants:t.nodes)??[]).forEach((m,y)=>{if(!m||m.href===void 0||m.href===null)return;const E=String(m.href);if(S==="sequence"){a(`${u[y]?.id}: a participant cannot be a link (href)`);return}if(!E){a(`${u[y]?.id}'s href is empty`);return}const q=u[y];q&&(q.href=E,q.blank=m.target==="_blank")});const z=new Map;for(const m of u)m.id?z.has(m.id)&&a(`the id "${m.id}" is used twice`):a("a node has no id"),z.set(m.id,m);if(S==="schema"){const m=(E,q)=>{if(E==null)return;const _=E,R=pe.includes(_.from)?_.from:void 0;if(!R){a(`${q}'s cardinality "from" is ${JSON.stringify(_.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`);return}return _.to===void 0||_.to===null?{from:R,to:"one"}:_.to==="one"||_.to==="zero-or-one"?{from:R,to:_.to}:(a(`${q}'s cardinality "to" is ${JSON.stringify(_.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`),{from:R,to:"one"})};(t.tables??[]).forEach(E=>(E.columns??[]).forEach((q,_)=>{const R=gt(q.references);if(!R&&q.cardinality!==void 0&&q.cardinality!==null&&a(`${String(E.name)}.${String(q.name)} states a cardinality but references nothing`),!R)return;const[U,G]=R.split("."),ht=z.get(U??""),pt=ht?.columns?.findIndex(mt=>mt.name===G)??-1;if(!ht||pt<0){a(`${String(E.name)}.${String(q.name)} references ${R}, which is not a shown column`);return}const lt=z.get(String(E.name??""));lt.columns[_].ref={table:U,column:G,row:pt};const ct=m(q.cardinality,`${String(E.name)}.${String(q.name)}`);ct&&(lt.columns[_].card=ct),x.push({i:x.length,from:lt.id,to:U,kind:"plain",fromRow:_,toRow:pt,fk:!0,card:ct})}));const y=x.filter(E=>E.card).length;y&&y!E.card).map(E=>`${E.from}.${z.get(E.from).columns[E.fromRow].name}`).join(", ")} ${x.length-y===1?"has":"have"} none)`)}else if(S!=="sequence")for(const m of t.edges??[]){const y=String(m.from??""),E=String(m.to??"");if(!z.has(y)||!z.has(E)){a(`a line names ${z.has(y)?E:y}, which is not a node`);continue}const q=gt(m.label),_=q?.split(` +`)??[];_.length>2&&a(`the label "${Lt(q)}" has more than one break: a label is two lines at most`),_.some(R=>R.length>me)&&a(`a line of the label "${Lt(q)}" is over ${me} characters: longer words belong in the node or the summary`),x.push({i:x.length,from:y,to:E,kind:g(m.kind,`the line from ${y} to ${E}`),label:q,fromSide:$(m.fromSide),toSide:$(m.toSide),flow:S!=="flowchart"&&m.flow===!0?!0:void 0})}else for(const m of v)"n"in m&&(!z.has(m.from)||!z.has(m.to))&&a(`message ${m.n} names ${z.has(m.from)?m.to:m.from}, which is not a participant`);if(o&&S!=="sequence"&&!T){const m=new Map;for(const y of u)for(let E=y.row;E<=y.row2;E++){const q=`${y.col}:${E}`;m.has(q)&&a(`${y.id} and ${m.get(q)} share the cell at column ${y.col}, row ${E}`),m.set(q,y.id)}}if(o&&!T){for(const y of W){const E=y.all.map(R=>z.get(R));if(!E.length)continue;const q={c1:Math.min(...E.map(R=>R.col)),c2:Math.max(...E.map(R=>R.col)),r1:Math.min(...E.map(R=>R.row)),r2:Math.max(...E.map(R=>R.row2))};for(const R of u)!y.all.includes(R.id)&&R.col>=q.c1&&R.col<=q.c2&&R.row>=q.r1&&R.row<=q.r2&&a(`${R.id} is inside the box of the group "${y.label}" but not a member`);const _=E.map(R=>R.i);Math.max(..._)-Math.min(..._)+1!==_.length&&a(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of u)y.group&&!W.some(E=>E.id===y.group)&&a(`${y.id} names the group "${y.group}", which is not in groups`);u.filter(y=>y.focal).length>1&&a("more than one node is focal: a diagram has one at most");const m=new Set(S==="sequence"?v.flatMap(y=>"n"in y?[y.kind]:[]):x.map(y=>y.kind));m.has("main")&&!r.main&&a("main lines are drawn but the legend has no words for them (legend.main)"),m.has("dashed")&&!r.dashed&&a("dashed lines are drawn but the legend has no words for them (legend.dashed)"),u.some(y=>y.focal)&&!r.focal&&a("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const rt=S==="architecture"||S==="data-flow",I=m=>Array.isArray(m)&&m.length>1?m.map(String):void 0,D=rt&&t.packet&&typeof t.packet=="object"?t.packet:void 0,j=D&&I(D.path),M={animated:t.motion==="animated",pulse:rt?I(t.pulse):void 0,packet:j?{path:j,repeat:D.repeat===!0,send:D.send}:void 0,run:S==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(o)for(const m of u){const y=m.mark?.says;if(!y?.length)continue;const E=[m.name,m.kind,m.detail,m.laneLabel].filter(Boolean).join(" ").toLowerCase();y.some(q=>E.includes(q.toLowerCase()))||a(`${m.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const B=[];if(S==="sequence"){const m=new Map,y=new Map;for(const E of v)"n"in E&&(y.set(E.from,E.n),y.set(E.to,E.n));for(const E of v)if("n"in E){if(E.activate){const q=m.get(E.to)??[];if(q.length>=3)a(`message ${E.n} opens a fourth bar on ${E.to}: three deep at most`);else{const _={who:E.to,from:E.n,to:E.n,depth:q.length+1};q.push(_),B.push(_),m.set(E.to,q)}}if(E.deactivate){const _=m.get(E.from)?.pop();_?_.to=E.n:a(`message ${E.n} closes a bar on ${E.from}, which has none open`)}}for(const[E,q]of m)for(const _ of q)_.to=Math.max(_.from,y.get(E)??_.from)}const H=t.frameLabels??{},Z={opt:gt(H.opt)??"Only if",loop:gt(H.loop)??"Repeats",alt:gt(H.alt)??"One of these",else:gt(H.else)??"Otherwise"},K=t.layout==="auto"&&!T?e.placement:void 0;let ot=Math.max(1,K?.cols??1,...u.map(m=>m.col));if(e.rtl){for(const y of u)y.col=ot-y.col+1;const m=y=>y==="left"?"right":y==="right"?"left":y;for(const y of x)y.fromSide=m(y.fromSide),y.toSide=m(y.toSide);for(const y of v)if("open"in y){const[E,q]=[ot-y.b+1,ot-y.a+1];y.a=E,y.b=q}ot=Math.max(1,...u.map(y=>y.col))}const P=S==="data-flow"?Math.max(1,C.length):Math.max(1,K?.rows??1,...u.map(m=>m.row2)),J={type:S,title:String(t.title??""),heading:c,legend:r,nodes:u,byId:z,edges:x,groups:W,lanes:C,steps:v,bars:B,frameWords:Z,cols:ot,rows:P,shapeLabels:f,stepWord:d,warnings:l,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0,text:S==="sequence"&&t.variant==="text"||void 0,marks:x.some(m=>m.card)||void 0};if(t.layout==="auto"&&!T&&S!=="schema"&&rn(J),o)for(const[m,y]of Object.entries(Te(J)))y>=48&&a(`${m} grows to ${y}px to hold the lines on one side: use another side`);return o&&u.length>1&&!Zt(J)&&a("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),J}function rn(t){const e=new Set(t.nodes.map(r=>`${r.col},${r.row}`)),n=(r,i)=>{const d=[];for(let h=Math.min(r,i)+1;h{const i=t.byId.get(r.from),d=t.byId.get(r.to),h=d.col>i.col?"right":"left",f=d.row>i.row?"bottom":"top",c=d.col>i.col?"left":"right",g=d.row>i.row?"top":"bottom",$=(x,C,W,v)=>n(x,C).map(S=>v?[S,W]:[W,S]);let p;const u=x=>(x==="right"?i.col1:x==="bottom"?i.row1)?[{sides:[x,x],cells:[]}]:[];return i.row===d.row?p=[{sides:[h,c],cells:$(i.col,d.col,i.row,!0)},...u("bottom"),...u("top")]:i.col===d.col?p=[{sides:[f,g],cells:$(i.row,d.row,i.col,!1)},...u("right"),...u("left")]:p=[{sides:[h,g],cells:[...$(i.col,d.col,i.row,!0),[d.col,i.row],...$(i.row,d.row,d.col,!1)]},{sides:[f,c],cells:[...$(i.row,d.row,i.col,!1),[i.col,d.row],...$(i.col,d.col,d.row,!0)]},{sides:[h,c],cells:$(i.col,d.col,i.row,!0)},{sides:[f,g],cells:$(i.row,d.row,i.col,!1)}],p.filter(x=>x.cells.every(([C,W])=>!e.has(`${C},${W}`)))},l=new Map,a=new Set;for(const r of t.edges)if(r.fromSide||r.toSide){const[i,d]=ce(t.byId.get(r.from),t.byId.get(r.to)),h=r.fromSide??i,f=r.toSide??d;a.add(`${r.from}.${h}`);for(const[c,g]of[[r.from,h],[r.to,f]])l.set(`${c}.${g}`,(l.get(`${c}.${g}`)??0)+1)}const s=t.edges.map((r,i)=>i).sort((r,i)=>o(t.edges[r]).length-o(t.edges[i]).length||+(t.edges[i].kind==="main")-+(t.edges[r].kind==="main")||r-i);for(const r of s){const i=t.edges[r];if(i.fromSide||i.toSide)continue;const d=(f,c,g)=>{const $=`${f}.${c}`;return(l.get($)??0)>=3?!1:t.byId.get(f).shape!=="decision"?!0:g?!l.has($):!a.has($)},h=o(i).find(f=>d(i.from,f.sides[0],!0)&&d(i.to,f.sides[1],!1));if(h){a.add(`${i.from}.${h.sides[0]}`);for(const[f,c]of[[i.from,h.sides[0]],[i.to,h.sides[1]]])l.set(`${f}.${c}`,(l.get(`${f}.${c}`)??0)+1);i.fromSide=h.sides[0],i.toSide=h.sides[1]}}}function ee(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=gt(e.onLight);if(n)return{onLight:n,onDark:gt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var ge=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function Ct(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var me=28,ne=t=>t.includes(` +`)?2:1,Lt=t=>t.replace(/\n/g," "),Nt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function ye(t,e){return t.legend[e]}function ln(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function cn(t,e){return Ct(t,`sentence:${e.i}`,()=>dn(t,e))}function dn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const o=(e.columns??[]).filter(a=>a.ref).map(a=>`${a.ref.table} (${a.name}${a.card?`: ${$e(e.id,a.ref.table,a.card)}`:""})`),l=t.edges.filter(a=>a.to===e.id).map(a=>`${a.from} (${t.byId.get(a.from).columns[a.fromRow].name}${a.card?`: ${$e(a.from,a.to,a.card)}`:""})`);o.length&&n.push(`References ${o.join(", ")}.`),l.length&&n.push(`Referenced by ${l.join(", ")}.`)}else if(t.type==="sequence"){const o=t.steps.filter(s=>"n"in s&&s.from===e.id).length,l=t.steps.filter(s=>"n"in s&&s.to===e.id).length;n.push(Nt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${o} ${o===1?"message":"messages"} and receives ${l}.`);const a=be(t,e);a&&n.push(a.trim())}else{const o=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?ln(t,e):e.kind;if(n.push(Nt(o?`${e.name}, ${o}`:e.name)),e.detail&&n.push(Nt(e.detail)),e.group){const s=t.groups.find(i=>i.id===e.group),r=s?.parent?t.groups.find(i=>i.id===s.parent):void 0;s&&n.push(r?`In ${s.label}, in ${r.label}.`:`In ${s.label}.`)}const l=t.edges.filter(s=>s.to===e.id).map(s=>`${t.byId.get(s.from).name}${s.label?` (${Lt(s.label)})`:""}`),a=t.edges.filter(s=>s.from===e.id).map(s=>`${t.byId.get(s.to).name}${s.label?` (${Lt(s.label)})`:""}`);l.length&&n.push(`From: ${l.join(", ")}.`),a.length&&n.push(`To: ${a.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(Nt(t.legend.focal)),n.join(" ")}var fn=(t,e,n,o)=>[`${Ft[n.from].toLowerCase()} `,o(t),` to ${Ft[n.to].toLowerCase()} `,o(e)],$e=(t,e,n)=>`${Ft[n.from].toLowerCase()} ${t} to ${Ft[n.to].toLowerCase()} ${e}`;function be(t,e){const n=t.bars.filter(l=>l.who===e.id&&l.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(l=>l.from===l.to?`message ${l.from}`:`messages ${l.from} to ${l.to}`).join(" and ")}.`:""}function un(t,e,n,o){const l=n.pointerType;if(l!=="touch"&&l!=="pen")return;const a=t.querySelector(`.${e}-drawing`),s=n.target;if(!a||!s||!a.contains(s)||!t.querySelector(`.${e}-edge`))return;const r=s.closest(`.${e}-node`);if(!r?.hasAttribute("href"))return r?r.dataset.node===o?null:r.dataset.node??null:null}function we(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function w(t,e,...n){const o=[];for(const l of n.flat(1/0))l!=null&&l!==!1&&!Array.isArray(l)&&o.push(l);return{t,a:e??{},c:o}}var hn={"&":"&","<":"<",">":">",'"':""","'":"'"},yt=t=>t.replace(/[&<>"']/g,e=>hn[e]),pn=" br img input meta link hr path polygon polyline circle rect line ";function oe(t,e={}){if(typeof t=="string")return yt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[o,l]of Object.entries(t.a))if(!(l==null||l===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(o))throw new Error(`diagram: "${o}" is not an attribute name`);n+=l===!0?` ${o}`:` ${o}="${yt(String(l))}"`}return pn.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(o=>oe(o,e)).join("")}`}var gn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function jt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function mn(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Vt(t,e){const n=e.all.map(o=>t.byId.get(o));return n.length?{c1:Math.min(...n.map(o=>o.col)),c2:Math.max(...n.map(o=>o.col)),r1:Math.min(...n.map(o=>o.row)),r2:Math.max(...n.map(o=>o.row2))}:null}function ve(t){return Ct(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const o=Vt(t,n);if(!o)continue;[o.r1===1,o.c2===t.cols,o.r2===t.rows,o.c1===1].forEach((a,s)=>{a&&(e[s]=Math.max(e[s],xe(t,n,s)))})}return e})}function xe(t,e,n){const o=Vt(t,e);return t.groups.filter(s=>s.parent===e.id).some(s=>{const r=Vt(t,s);return r&&[r.r1===o.r1,r.c2===o.c2,r.r2===o.r2,r.c1===o.c1][n]})?2:1}function ke(t){const e=ve(t);return e[1]+e[3]}function se(t){return t.type==="sequence"?t.nodes.length:t.cols}function Me(t){return Ct(t,"plan",()=>yn(t))}function yn(t){const e=t.nodes,n=u=>t.type==="data-flow"||!e[u].branch,o=t.edges.map(u=>{const x=t.byId.get(u.from).i,C=t.byId.get(u.to).i,v=e.slice(Math.min(x,C)+1,Math.max(x,C)).every(S=>!n(S.i));return C===x+1&&!(n(x)&&!n(C))?"down":C===x-1?"up":C>x&&n(x)&&!n(C)&&v?"trunk":C>x&&n(x)&&n(C)&&v?"rail":C>x?"end-down":"end-up"}),l=t.edges.map((u,x)=>({e:u,k:x})).filter(({k:u})=>o[u]==="end-down"||o[u]==="end-up"),a=u=>{const x=t.byId.get(u.from).i,C=t.byId.get(u.to).i;return[Math.min(x,C),Math.max(x,C)]},s=(u,x)=>{const[C,W]=a(u),[v,S]=a(x);return C{const x=t.byId.get(u.from).i,[C,W]=a(u);return!n(x)&&e.slice(C+1,W).every(v=>!n(v.i))&&l.every(v=>v.e===u||!s(v.e,u))}),i=l.length>0&&(t.type==="data-flow"||!r),d=u=>{const[x,C]=a(u);return C-x},h=t.edges.map(()=>0);let f=!1;const c=[];for(const u of[...l].sort((x,C)=>d(x.e)-d(C.e)||x.k-C.k)){let x=0;for(const C of c)s(C.e,u.e)&&(x=Math.max(x,h[C.k]+1));h[u.k]=x,x>3&&(f=!0),c.push(u)}const g=Math.max(0,...l.map(({k:u})=>h[u]+1)),$=t.edges.map(()=>.5);for(const u of e){const x=l.filter(({e:v})=>v.from===u.id);if(x.length<2)continue;const C=x.filter(({k:v})=>o[v]==="end-down").sort((v,S)=>d(S.e)-d(v.e)||v.k-S.k);[...x.filter(({k:v})=>o[v]==="end-up").sort((v,S)=>d(v.e)-d(S.e)||S.k-v.k),...C].forEach(({k:v},S,T)=>{$[v]=T.length===2?S===0?1/3:2/3:(S+1)/(T.length+1)})}const p=At();for(let u=1;u{const D=o[I],j=t.byId.get(rt.from).i,M=t.byId.get(rt.to).i,B=M===u&&(D==="down"||D==="trunk"||D==="rail"||D==="end-down"),H=j===u&&M===u-1&&D==="up",Z=M===u-1&&D==="end-up";B&&(D==="trunk"||D==="end-down")&&(S=!0),Z&&(T=!0),(B||H||Z)&&rt.label&&(W++,v=Math.max(v,D==="trunk"?40:48))}),(W>1||S&&T)&&(v=64);const nt=l.filter(({e:rt,k:I})=>o[I]==="end-down"&&t.byId.get(rt.to).i===u).length,z=l.filter(({e:rt,k:I})=>o[I]==="end-up"&&t.byId.get(rt.to).i===u-1).length;v+=20*Math.max(0,nt-1)+20*Math.max(0,z-1),p[x.id]=v}return{routes:o,gutter:i,lanes:h,exits:$,gaps:p,third:f,laneCount:g}}var Tt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Se(t,e){const n=e==="fk"?"plain":e,o=n==="main"?8:8.5,l=24,a=n==="dashed"?l-1:l-7;return w("svg",{class:`${t}-swatch`,"data-kind":n,...Tt(24,16)},e==="fk"?w("circle",{class:`${t}-dot`,cx:3,cy:o,r:3}):null,w("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${o}H${a}`}),n==="dashed"?w("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${l-8} ${o-4}L${l} ${o}L${l-8} ${o+4}`}):w("path",{class:`${t}-tip`,"data-kind":n,d:`M${l} ${o}L${l-8} ${o-4}L${l-8} ${o+4}Z`}))}function $n(t,e){const{crow:n,ring:o}=Ee(e,24,8.5,-1);return w("svg",{class:`${t}-swatch`,"data-card":e,...Tt(24,16)},w("path",{class:`${t}-line`,"data-kind":"plain",d:"M0 8.5H24"}),w("path",{class:`${t}-crow`,d:n}),o?w("circle",{class:`${t}-ring`,cx:o.x,cy:o.y,r:o.r}):null)}function Ee(t,e,n,o,l=8,a=6){const s=g=>String(Math.round(g*100)/100),r=g=>e+o*g,i=l/2,d=g=>`M${s(r(g-.5))} ${s(n-i)}V${s(n+i)}`,h=t==="one-or-many"||t==="zero-or-many",f=t==="zero-or-one"||t==="zero-or-many";let c=h?`M${s(e)} ${s(n-i)}L${s(r(7.5))} ${s(n)}L${s(e)} ${s(n+i)}`:d(4);return f||(c+=d(h?11:8)),{crow:c,ring:f?{x:Math.round(r(10.5)*100)/100,y:n,r:a/2}:void 0}}function Ht(t,e){return e==="decision"?w("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},w("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?w("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):w("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Ae(t,e){return Ct(e,`key:${t}`,()=>wn(t,e))}var bn=Ae;function wn(t,e){const n=[],o=(s,r,i={})=>n.push(w("li",{class:`${t}-entry`,...i},s,w("span",null,r)));if(e.type==="schema"){const s=new Set(e.nodes.flatMap(r=>(r.columns??[]).map(i=>i.key)));for(const[r,i]of[["PK","Primary key"],["FK","Foreign key"]])s.has(r)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"aria-hidden":"true"},r),w("span",null,i)))}if(e.type==="flowchart"){const s=new Set(e.nodes.map(r=>r.shape));s.has("terminal")&&o(Ht(t,"terminal"),e.shapeLabels.terminal),s.has("box")&&o(Ht(t,"box"),e.shapeLabels.step),s.has("decision")&&o(Ht(t,"decision"),e.shapeLabels.decision)}const l=new Set(e.type==="sequence"?e.steps.flatMap(s=>"n"in s?[s.kind]:[]):e.edges.filter(s=>!s.fk).map(s=>s.kind)),a=(s,r)=>w("span",{class:`${t}-key-glyph`,"data-ink":r,"aria-hidden":"true"},s);for(const s of["main","plain","dashed"]){const r=e.legend[s];l.has(s)&&r&&o(e.text?a(s==="main"?"━━▶":s==="dashed"?"┄┄▷":"──▶",s==="main"?"main":"plain"):Se(t,s),r,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length){e.edges.some(r=>!r.card)&&o(Se(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"});const s=new Set(e.edges.flatMap(r=>r.card?[r.card.from,r.card.to]:[]));for(const r of pe)s.has(r)&&o($n(t,r),Ft[r],{"data-line":"","data-when":"drawn","data-card":r});n.push(w("li",{class:`${t}-entry`,"data-when":"stacked"},w("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),w("span",null,"The table a foreign key references")))}if(e.type==="sequence"){e.bars.length&&o(e.text?a("┃","working"):w("svg",{class:`${t}-swatch`,"data-shape":"bar",...Tt(16,16)},w("path",{class:`${t}-life`,d:"M8 0V16"}),w("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const s=new Set(e.steps.flatMap(r=>"open"in r?[r.open]:[]));for(const r of["opt","loop","alt"])s.has(r)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},r),w("span",null,e.frameWords[r])))}return e.nodes.some(s=>s.focal)&&e.legend.focal&&o(Ht(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&o(Ht(t,"group"),e.legend.group),n.length?w("div",{class:`${t}-key`},w("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function vn(t,e){const n=e==="main"?6:6.5;return w("svg",{class:`${t}-arrow`,"data-kind":e,...Tt(20,12)},w("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?w("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):w("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function ae(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),w("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function xn(t,e,n){if(n.shape==="decision")return[w("span",{class:`${t}-words`},w("span",{class:`${t}-name`},ae(t,n)))];const o=[];return e.type==="data-flow"?o.push(w("span",{class:`${t}-kind`},n.kind,w("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&o.push(w("span",{class:`${t}-kind`},n.kind)),o.push(w("span",{class:`${t}-name`},ae(t,n))),n.detail&&o.push(w("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Yt(n.detail).flatMap((l,a)=>[a?" ":"",w("span",{class:`${t}-run`},l)]):n.detail)),o}function kn(t,e,n){return[w("span",{class:`${t}-th`},w("span",{class:`${t}-tname`},ae(t,e))),w("span",{class:`${t}-rows`},(e.columns??[]).map((o,l)=>w("span",{class:`${t}-row`,"data-row":l,"data-key":o.key},w("span",{class:`${t}-keyseat`},o.key??""),w("span",{class:`${t}-cname`},o.name),o.ref?w("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${o.ref.table}`):o.type?w("span",{class:`${t}-ctype`},o.type):null))),e.more?w("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Le=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Kt(t,e,n,o){const{P:l}=t,a=mn(e,o)||o.keep===n.id,s=jt(e,o),r=o.layout==="drawn"&&o.rows,i=[`--_c:${n.col}`,`--_r:${r?2*n.row:n.row}`,`--_r2:${r?2*n.row2+1:n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const $=qt(d.gaps,n.id)??32,p=qt(o.grow,n.id)??0;i.push(`--_gap:${p?`calc(${Le($)} + var(--basalt-space-4) * ${p})`:Le($)}`)}const h=qt(o.heights,n.id);h&&i.push(`--_h:${h}px`);const f=qt(Te(e),n.id);f&&i.push(`--_mh:${f}px`);const c=qt(o.words,n.id);c&&i.push(`--_ww:${c}px`);const g=s?o.stop===n.id?0:-1:o.keep===n.id?-1:void 0;return w(n.href?"a":"div",{class:`${l}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:a&&!n.href?"img":void 0,"aria-label":a||n.href?cn(e,n):void 0,tabindex:g},n.shape==="decision"?w("svg",{class:`${l}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},w("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?w("span",{class:`${l}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${ge(n.mark.onLight)};--_md:${ge(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?kn(l,n,e):xn(l,e,n))}function Mn(t,e,n){const{P:o}=t,l=[];if(e.type==="data-flow"&&l.push(...e.lanes.map((i,d)=>w("div",{class:`${o}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},w("span",{class:`${o}-lane-name`},i.label)))),e.type==="architecture")for(const i of e.groups){const d=Vt(e,i);if(!d)continue;const h=[0,1,2,3].map(f=>xe(e,i,f));l.push(w("div",{class:`${o}-gbox`,"data-group":i.id,"data-depth":i.depth>1?i.depth:void 0,style:`--_c:${d.c1};--_c2:${d.c2+1};--_r:${d.r1};--_r2:${d.r2+1}${h[0]>1?";--_gt:2":""}${h[1]>1?";--_ge:2":""}${h[2]>1?";--_gb:2":""}${h[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},w("span",{class:`${o}-glabel`},i.label)))}if(e.text)return[w("pre",{class:`${o}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},w("code",{class:`${o}-text-ink`},Sn(o,e)))];if(e.type==="sequence")return l.push(w("ul",{class:`${o}-cast`},e.nodes.map(i=>w("li",{class:`${o}-actor`,style:e.rtl?`--_ac:${i.col}`:void 0},Kt(t,e,i,n))))),l.push(En(t,e)),l;const a=i=>{const d=i.group?e.groups.find(h=>h.id===i.group):void 0;return d?.parent?e.groups.find(h=>h.id===d.parent):d},s=(i,d,h)=>{const f=t.plan?qt(n.grow,d[0].id)??0:0;return w("div",{class:`${o}-group`,"data-group":i.id,"data-depth":i.depth>1?i.depth:void 0,style:f?`--_ggrow:${f}`:void 0},w("span",{class:`${o}-glabel`,"aria-hidden":"true"},i.label),h)};let r=0;for(;rp.id===h[c].group):void 0;if(!g){f.push(Kt(t,e,h[c],n)),c++;continue}const $=[];for(;cKt(t,e,p,n))))}l.push(s(d,h,f))}return l}function Sn(t,e){const n=[],o=s=>w("span",{class:`${t}-tx-name`},s),l=s=>s==="main"?"━▶":s==="dashed"?"┄▷":"─▶";n.push(w("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((s,r)=>[r?" · ":"",o(s.name)])),` +`);let a=0;for(const s of e.steps){const r=" ".repeat(a);if("band"in s){n.push(w("span",{class:`${t}-tx-line`,"data-ink":"band"},`${r}── ${s.band} ──`),` +`);continue}if("open"in s){n.push(w("span",{class:`${t}-tx-line`,"data-ink":"frame"},r,w("span",{"data-ink":"op"},`[${s.open}]`),` ${s.label}`),` +`),a++;continue}if("otherwise"in s){n.push(w("span",{class:`${t}-tx-line`,"data-ink":"frame"}," ".repeat(a-1),w("span",{"data-ink":"op"},"[else]"),` ${s.otherwise}`),` +`);continue}if("close"in s){a=Math.max(0,a-1),n.push(w("span",{class:`${t}-tx-line`,"data-ink":"frame"},`${" ".repeat(a)}[end]`),` +`);continue}const i=e.byId.get(s.from)?.name??s.from,d=e.byId.get(s.to)?.name??s.to;n.push(w("span",{class:`${t}-tx-line`,"data-n":s.n},r,w("span",{"data-ink":"num"},`${s.n} `),o(i)," ",w("span",{"data-ink":s.kind==="main"?"main":"plain"},l(s.kind))," ",o(d)," ",w("span",{"data-ink":"label"},s.label),s.note?[" ",w("span",{"data-ink":"note"},`(${s.note})`)]:null),` +`)}return n}function En(t,e){const{P:n}=t,o=[],l=[],a=()=>l.length?l[l.length-1].el.c:o;let s=null;for(const r of e.steps){if("band"in r){s=null,a().push(w("p",{class:`${n}-band`},w("span",null,r.band)));continue}if("open"in r){s=null;const p=l[l.length-1],u=p?`;--_fis:${r.a===p.a?1:0};--_fie:${r.b===p.b?1:0}`:"",x=w("div",{class:`${n}-frame`,"data-op":r.open,"data-depth":r.depth,style:`--_a:${r.a};--_b:${r.b+1}${u}`},w("span",{class:`${n}-fbox`,"aria-hidden":"true"}),w("p",{class:`${n}-fhead`},w("span",{class:`${n}-ftab`,"aria-hidden":"true"},r.open),w("span",{class:`${n}-flabel`},w("span",{class:t.hidden},`${e.frameWords[r.open]}: `),r.label)));a().push(x),l.push({el:x,a:r.a,b:r.b});continue}if("otherwise"in r){s=null,a().push(w("p",{class:`${n}-felse`},w("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),w("span",{class:`${n}-flabel`},w("span",{class:t.hidden},`${e.frameWords.else}: `),r.otherwise)));continue}if("close"in r){s=null,l.pop();continue}s||(s=w("ol",{class:`${n}-msgs`,start:r.n}),a().push(s));const i=e.byId.get(r.from),d=e.byId.get(r.to),h=i?.col??1,f=d?.col??1,c=h===f,g=c&&(e.rtl?h!==1:h===e.nodes.length),$=ye(e,r.kind);s.c.push(w("li",{class:`${n}-msg`,"data-kind":r.kind,"data-from":r.from,"data-to":r.to,"data-self":c?g?"start":"end":void 0,style:`--_a:${Math.min(h,f)};--_b:${Math.max(h,f)+1}`},w("span",{class:`${n}-said`},w("span",{class:`${n}-num`},String(r.n)),w("span",{class:`${n}-mlabel`},r.label)),w("span",{class:`${n}-route`},i?.short??r.from," ",vn(n,r.kind),w("span",{class:t.hidden}," to ")," ",d?.short??r.to,$?` · ${$}`:""),r.note?w("span",{class:`${n}-note`},r.note):null))}return w("div",{class:`${n}-steps`},o)}function Ie(t,e){return Ct(e,`list:${t}`,()=>Ln(t,e))}var An=Ie;function Ln(t,e){const n=Math.min(6,e.heading+1),o=f=>w(`h${n}`,{class:`${t}-list-head`},f),l=f=>w("strong",null,f),a=f=>f.href?w("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},l(f.name)):l(f.name),s=f=>w("code",{class:`${t}-code`},f),r=f=>e.byId.get(f)?.name??f,i=f=>{const c=ye(e,f);return c?` (${c})`:""},d=f=>f.focal&&e.legend.focal?` ${Nt(e.legend.focal)}`:"";if(e.type==="architecture"){const f=$=>w("li",null,a($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?s($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",d($)),c=[o("Parts")],g=e.nodes.filter($=>!$.group);g.length&&c.push(w("ul",{class:`${t}-list-items`},g.map(f)));for(const $ of e.groups.filter(p=>p.depth===1)){c.push(w("p",{class:`${t}-list-group`},$.label)),$.members.length&&c.push(w("ul",{class:`${t}-list-items`},$.members.map(p=>f(e.byId.get(p)))));for(const p of e.groups.filter(u=>u.parent===$.id))c.push(w("p",{class:`${t}-list-group`,"data-depth":2},p.label)),c.push(w("ul",{class:`${t}-list-items`,"data-depth":2},p.members.map(u=>f(e.byId.get(u)))))}return c.push(o("Connections")),c.push(w("ol",{class:`${t}-list-items`},e.edges.map($=>w("li",null,l(r($.from))," to ",l(r($.to)),$.label?[": ",s(Lt($.label))]:"",`${i($.kind)}.`)))),c}if(e.type==="flowchart"){const f=c=>(e.byId.get(c)?.i??0)+1;return[w("ol",{class:`${t}-list-items`},e.nodes.map(c=>{const g=e.edges.filter(u=>u.from===c.id),$=c.shape==="decision"?"Decision":c.shape==="terminal"?g.length?"Start":"End":"Step",p=!c.detail&&/[.!?]$/.test(c.name)?" ":". ";return w("li",null,a(c),c.detail?[", ",c.mono?s(c.detail):c.detail]:"",`${p}${$}.`,d(c),g.length?w("ul",{class:`${t}-list-exits`},g.map(u=>w("li",null,u.label?`If ${Lt(u.label)}: go to ${f(u.to)}, `:`Then: go to ${f(u.to)}, `,l(r(u.to)),i(u.kind)))):null)}))]}if(e.type==="data-flow")return[w("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const c=e.edges.filter(g=>g.from===f.id);return w("li",null,`${f.laneLabel}: `,a(f),f.detail?[", ",f.mono?s(f.detail):f.detail]:"",".",d(f),c.length?[" Then ",...c.flatMap((g,$)=>[$?"; ":"",`to step ${e.byId.get(g.to).step}, `,l(r(g.to)),g.label?[": ",s(Lt(g.label))]:"",i(g.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[o("Participants"),w("ul",{class:`${t}-list-items`},e.nodes.map(g=>w("li",null,l(g.name),g.kind?`, ${g.kind}`:"",".",d(g),be(e,g))))];f.push(o("Messages"));let c=null;for(const g of e.steps){if("band"in g){c=null,f.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},g.band));continue}if("open"in g){c=null,f.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords[g.open]}: ${g.label}`));continue}if("otherwise"in g){c=null,f.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords.else}: ${g.otherwise}`));continue}if("close"in g){c=null;continue}c||(c=w("ol",{class:`${t}-list-items`,start:g.n}),f.push(c)),c.c.push(w("li",null,s(g.label),": ",l(r(g.from))," to ",l(r(g.to)),`${i(g.kind)}.`,g.note?` ${Nt(g.note)}`:""))}return f}const h=[];for(const f of e.nodes)h.push(w(`h${n}`,{class:`${t}-list-group`},f.href?w("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},s(f.name)):s(f.name),d(f))),h.push(w("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(c=>w("li",null,s(c.name),c.key==="PK"?", primary key":c.key==="FK"?", foreign key":"",c.ref?[", references ",s(`${c.ref.table}.${c.ref.column}`),c.card?[" (",fn(f.id,c.ref.table,c.card,s),")"]:""]:c.type?`, ${c.type}`:"")),...f.more?[w("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return h}function _e(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Zt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(l=>l.href)?" Enter opens a part that is a link.":""}`}function re(t,e=!1){const n=e&&t.type!=="sequence"&&Zt(t)&&t.cols>1&&t.rows>1,o=t.nodes.some(l=>l.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:we(t)},{keys:["Home","End"],words:"the ends"},...o,{keys:["Esc"],words:"clear"}]}var In=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Zt(t){return Ct(t,"spatial",()=>{const e=t.nodes.map(a=>({id:a.id,..._n(t,a)})),n=(a,s)=>{const r=s==="right"||s==="left",i=s==="right"||s==="down",d=$=>r?[$.col,$.col]:$.rows,h=$=>r?$.rows:[$.col,$.col],f=d(a),c=h(a);let g=null;return e.forEach(($,p)=>{if($===a)return;const u=d($),x=h($),C=i?u[0]-f[1]:f[0]-u[1];if(C<1)return;const W=Math.max(0,x[0]-c[1],c[0]-x[1]),v=[W===0?0:1,W===0?C:C+2*W,W,Math.abs(x[0]-c[0]),p];(!g||In(v,g.rank))&&(g={id:$.id,rank:v})}),g?.id??null},o=At();for(const a of e)o[a.id]={right:n(a,"right"),left:n(a,"left"),down:n(a,"down"),up:n(a,"up")};const l=a=>{const s=new Set([a]),r=[a];for(;r.length;)for(const i of Object.values(o[r.pop()]))i&&!s.has(i)&&(s.add(i),r.push(i));return s.size};return e.every(a=>l(a.id)===e.length)?o:null})}function Jt(t){return Ct(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!ie(t))return{lane:e,dropped:n,lanes:0};const o=(i,d)=>(t.byId.get(i)?.row??0)*1e3+d,l=new Map;t.edges.forEach((i,d)=>{const h=`${i.to}.${i.toRow}`,f=o(i.from,i.fromRow??0),c=o(i.to,i.toRow??0),g=l.get(h)??{members:[],lo:1/0,hi:-1/0};g.members.push(d),g.lo=Math.min(g.lo,f,c),g.hi=Math.max(g.hi,f,c),l.set(h,g)});const a=[...l.values()].sort((i,d)=>d.hi-d.lo-(i.hi-i.lo)),s=[];let r=0;for(const i of a.reverse()){const d=new Set(s.filter(f=>f.lo<=i.hi&&i.lo<=f.hi).map(f=>f.lane));let h=0;for(;d.has(h);)h++;if(h>1){for(const f of i.members)n.add(f);continue}s.push({lo:i.lo,hi:i.hi,lane:h});for(const f of i.members)e.set(f,h);r=Math.max(r,h+1)}return{lane:e,dropped:n,lanes:r}})}var ie=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Xt(t,e,n){const o=n.prefix,l=gn(n.base),a=t.type==="sequence"||t.type==="schema"?null:Me(t),s={P:o,ids:l,level:n.level,plan:a,hidden:n.hiddenClass},r=e.layout==="drawn",i=jt(t,e),d=t.type==="sequence"||t.type==="schema"?r:!0,h=`h${t.heading}`,f=[`--_cols:${se(t)}`];if(t.type==="architecture"&&t.groups.length||r&&e.pad){const c=t.type==="architecture"?ve(t):[0,0,0,0],g=(p,u,x)=>p?p>1?`calc(${p} * var(--basalt-space-${u}))`:`var(--basalt-space-${u})`:x?`var(--basalt-space-${x})`:"0px",$=r&&e.pad?"3":void 0;f.push(`--_gpad:${g(c[0],"8",$)} ${g(c[1],"4")} ${g(c[2],"4",$)} ${g(c[3],"4")}`)}if(a?.gutter&&a.laneCount>2&&f.push(`--_gw:calc(${a.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),ie(t)){const c=t.marks?"var(--basalt-space-6) + var(--basalt-space-1)":"var(--basalt-space-5)";f.push(`--_gpad:0px ${Jt(t).lanes>1?`calc(${c} + var(--basalt-space-3))`:t.marks?`calc(${c})`:c} 0px 0px`)}return t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),w("figure",{class:n.className?`${o} ${n.className}`:o,"aria-labelledby":l.title,"data-type":t.type,"data-cols":se(t),"data-reach":t.type==="architecture"?ke(t):void 0,"data-gutter":a?.gutter?"":void 0,"data-marks":t.marks?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:f.join(";")},w("div",{class:`${o}-head`},w(h,{id:l.title,class:`${o}-title`},t.title),n.hasSource?w("p",{class:`${o}-source`},{slot:"source"}):null),w("div",{class:`${o}-drawing`,style:r&&e.rows?`--_rows:${e.rows};--_row-gap:0px`:void 0,role:d?"group":void 0,"aria-roledescription":d?"diagram":void 0,"aria-labelledby":d?l.title:void 0,"aria-describedby":d?i?`${l.summary} ${l.keys}`:l.summary:void 0,"data-stops":i?"":void 0},Mn(s,t,e),t.text?null:w("div",{class:`${o}-ink`,"aria-hidden":"true"}),w("span",{class:`${o}-ruler`,"aria-hidden":"true"})),Ae(o,t),w("p",{class:`${o}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),jt(t,e)&&t.type!=="sequence"||r&&t.type==="sequence"?w("p",{class:`${o}-tap-hint`,"aria-hidden":"true"},`Tap ${we(t)} to highlight its lines. Tap it again to clear.`):null,w("div",{class:`${o}-foot`},{slot:"toggle"}),w("div",{id:l.list,class:`${o}-list`,hidden:!e.open},Ie(o,t)),w("span",{id:l.keys,class:n.hiddenClass},n.viewer?`${_e(t,r)} ${n.viewer}`:_e(t,r)),w("figcaption",{id:l.summary,class:`${o}-summary`},{slot:"summary"}))}function On(t){const e=getComputedStyle(t),n=(l,a)=>{const s=parseFloat(e.getPropertyValue(`--basalt-${l}`));return Number.isFinite(s)?s:a},o=new Map;return{space:l=>(o.has(l)||o.set(l,n(`space-${l}`,parseFloat(l.replace("-","."))*4)),o.get(l)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ut=(t,e)=>t==="main"?e.line:e.hair,Et=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},It=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Oe=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function kt(t,e,n){const{l:o,t:l,r:a,b:s}=t.rect,r=(o+a)/2,i=(l+s)/2,d=(a-o)/2,h=(s-l)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const $=n,p=h*Math.max(0,1-Math.abs($-r)/d);return{x:$,y:e==="top"?i-p:i+p}}const c=n,g=d*Math.max(0,1-Math.abs(c-i)/h);return{x:e==="left"?r-g:r+g,y:c}}if(t.shape==="terminal"){const c=Math.min(d,h);if(f){const u=n,x=Math.min(Math.max(u,o+c),a-c),C=u-x,W=Math.abs(C)>=c?0:Math.sqrt(c*c-C*C);return{x:u,y:Math.abs(C)<1e-6?e==="top"?l:s:e==="top"?i-W:i+W}}const g=n,$=g-i,p=Math.abs($)>=c?0:Math.sqrt(c*c-$*$);return{x:e==="left"?o+c-p:a-c+p,y:g}}return f?{x:n,y:e==="top"?l:s}:{x:e==="left"?o:a,y:n}}function qn(t,e,n){const{l:o,t:l,r:a,b:s}=e.rect,r=(o+a)/2,i=(l+s)/2,d=(a-o)/2,h=(s-l)/2;if(e.shape==="decision")return Math.abs(t.x-r)/d+Math.abs(t.y-i)/h<1-n/Math.min(d,h);if(e.shape==="terminal"){const f=Math.min(d,h),c=Math.min(Math.max(t.x,o+f),a-f);return Math.hypot(t.x-c,t.y-i)o+n&&t.xl+n&&t.ymatchMedia("(forced-colors: active)").matches;function Bn(t,e){const n=t.querySelector(`.${e}-ruler`),o=new Map;return(l,a)=>{const s=`${a}|${l}`;return o.has(s)||(n.setAttribute("data-f",a),n.textContent=l,o.set(s,n.getBoundingClientRect().width),n.textContent=""),o.get(s)}}var Yt=t=>t?t.split(/\s+/).filter(Boolean):[];function Rn(t,e,n){const o=e.space;let l=e.node,a=e.table;for(const i of t.nodes){if(i.shape==="table"){for(const p of i.columns??[]){const u=p.ref?`${t.rtl?"←":"→"} ${p.ref.table}`:p.type??"",x=o("6")+n(p.name,"mono")+(u?o("3")+n(u,"mono"):0)+2*o("3")+2*e.hair;a=Math.max(a,Math.ceil(x))}a=Math.max(a,Math.ceil(n(i.name,"table")+2*o("3")+2*e.hair+(i.href?16+o("1-5"):0)));continue}const d=i.shape==="terminal"?2*o("5"):2*o("3"),h=i.mark&&!jn()?(i.shape==="participant"?2:1)*o("6"):0;let f=0;const c=i.href?16+o("1-5"):0,g=Yt(i.name);if(g.forEach((p,u)=>{f=Math.max(f,n(p,i.shape==="decision"?"name-500":"name")+(i.kind?0:h)+(u===g.length-1?c:0))}),t.type!=="data-flow")for(const p of Yt(i.kind))f=Math.max(f,n(p,"mono")+h);for(const p of Yt(i.detail))f=Math.max(f,n(p,i.mono?"mono":"sans"));const $=i.shape==="decision"?f/.62:f+d+2*e.hair;l=Math.max(l,Math.ceil($))}const s=se(t);let r;return t.type==="data-flow"?r=e.lane+s*(l+o("12")):t.type==="schema"?r=s*a+(s-1)*(o("12")+(t.marks?o("3"):0))+(ie(t)?(t.marks?o("6")+o("1"):o("5"))+(Jt(t).lanes>1?o("3"):0):0):t.type==="sequence"?r=s*l+(s-1)*o("5"):r=s*l+(s-1)*o("16")+ke(t)*o("4"),{track:l,table:a,least:Math.max(e.wide,r)}}function Ce(t,e){return{x:(n,o)=>o%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,o)=>o%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function le(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function je(t,e,n){const o=t.map(a=>({...a}));for(let a=1;a=2){const i=l[l.length-2];if(Math.abs(i.x-r.x)<.01&&Math.abs(r.x-s.x)<.01||Math.abs(i.y-r.y)<.01&&Math.abs(r.y-s.y)<.01){l[l.length-1]=s;continue}}l.push(s)}}return l}var _t=t=>t.slice(1).map((e,n)=>[t[n],e]);function Qt(t,e,n){const o=[];for(let a=0;aMath.min(p.x,u.x)+.75&&WMath.min(x.y,C.y)+.75&&va.split(/\s+/).map(parseFloat).filter(s=>Number.isFinite(s)),o=(a,s,r)=>{const i=[];let d=s;for(const h of a)i.push([d,d+h]),d+=h+r;return i},l=o(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0);return{cols:o(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:t.style.getPropertyValue("--_rows").trim()?l.filter((a,s)=>s%2===1):l}}var dt=t=>t==="left"||t==="right",Be={top:"bottom",bottom:"top",left:"right",right:"left"};function ce(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Re(t,e,n){const o=[];t.edges.forEach((a,s)=>{const r=t.byId.get(a.from),i=t.byId.get(a.to),[d,h]=e[s],f=r.row===i.row&&dt(d)&&dt(h)&&d===Be[h]||r.col===i.col&&!dt(d)&&!dt(h)&&d===Be[h];o.push({edge:s,end:"from",node:r,side:d,far:i,straight:f,f:.5},{edge:s,end:"to",node:i,side:h,far:r,straight:f,f:.5})});const l=new Map;for(const a of o){const s=`${a.node.id}.${a.side}`;l.has(s)||l.set(s,[]),l.get(s).push(a)}for(const[a,s]of l){if(s[0].node.shape==="decision")continue;const r=p=>dt(p.side)?p.far.row-p.node.row:p.far.col-p.node.col,i=s.filter(p=>p.straight),d=s.filter(p=>!p.straight);if(d.sort((p,u)=>r(p)-r(u)||(dt(p.side)?p.far.col-u.far.col:p.far.row-u.far.row)*(r(p)<0?1:-1)),s.length>3&&n(`${a.replace(".","'s ")} side has ${s.length} lines; more than three is an error: use another side`),!i.length){d.length===2?(d[0].f=.25,d[1].f=.75):d.length===3?(d[0].f=.25,d[1].f=.5,d[2].f=.75):d.length>3&&d.forEach((p,u)=>{p.f=(u+1)/(d.length+1)});continue}const h=new Map;for(const p of i)h.has(p.far.id)||h.set(p.far.id,[]),h.get(p.far.id).push(p);for(const p of h.values())p.length>1&&p.sort((u,x)=>u.edge-x.edge).forEach((u,x)=>{u.f=p.length===2?x===0?.25:.75:(x+1)/(p.length+1)});const f=Math.min(...i.map(p=>p.f)),c=Math.max(...i.map(p=>p.f)),g=d.filter(p=>r(p)<0),$=d.filter(p=>r(p)>=0);g.forEach((p,u)=>{p.f=f*(u+1)/(g.length+1)}),$.forEach((p,u)=>{p.f=c+(1-c)*(u+1)/($.length+1)})}return o}function Te(t,e=8,n=8){return Ct(t,`port-floors:${e}:${n}`,()=>{const o=At();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return o;const l=t.edges.map(s=>{const r=t.byId.get(s.from),i=t.byId.get(s.to),[d,h]=ce(r,i);return[s.fromSide??d,s.toSide??h]}),a=new Map;for(const s of Re(t,l,()=>{})){if(!dt(s.side)||s.node.shape!=="box")continue;const r=`${s.node.id}.${s.side}`;a.has(r)||a.set(r,[]),a.get(r).push(s.f)}for(const[s,r]of a){if(r.length<2)continue;const i=[...new Set(r.map(f=>Math.round(f*1e6)/1e6))].sort((f,c)=>f-c);let d=Math.max(e/i[0],e/(1-i[i.length-1]));for(let f=1;f{const s=t.byId.get(a.dataset.node);s&&l.set(s.id,{id:s.id,rect:Et(a,n),shape:s.shape,i:s.i})}),l}function We(t,e){const n=e.head,o=e.head/2,{x:l,y:a}=t.tip;return t.dir==="down"?{l:l-o,r:l+o,t:a-n,b:a}:t.dir==="up"?{l:l-o,r:l+o,t:a,b:a+n}:t.dir==="right"?{l:l-n,r:l,t:a-o,b:a+o}:{l,r:l+n,t:a-o,b:a+o}}var Fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function He(t,e,n,o){const l=(a,s)=>{const r=a+s-Math.floor(a+s);return r<.005||r>.995?[0]:r<=.5?[-r,1-r]:[1-r,-r]};for(const a of l(t.t,n))for(const s of l(t.l,e)){if(!s&&!a)return t;const r={l:t.l+s,r:t.r+s,t:t.t+a,b:t.b+a};if(o(r))return r}return t}function zn(t,e,n,o,l,a,s,r,i){const d=s.space,h=[],f=[],c=[],g=[],$=d("1"),p=e.filter(u=>t.edges[u.i]?.label).sort((u,x)=>+(t.edges[x.i].kind==="main")-+(t.edges[u.i].kind==="main")||u.i-x.i);for(const u of p){const x=t.edges[u.i].label,C=r(x,"label"),W=16*ne(x),v=u.pts.length-2,S=[];_t(u.pts).forEach(([I,D],j)=>{const M=Math.abs(I.y-D.y)<.01,B=M?I.x:I.y;let H=M?D.x:D.y;const Z=Math.sign(H-B)||1;j===v&&(H-=Z*s.head);let K=[[B,H]];for(const J of l)for(const m of M?[J.l,J.r]:[J.t,J.b]){const y=M?I.y:I.x;(M?y>J.t&&yJ.l&&ym>Math.min(q,_)+1&&m{const y=(J+m)/2,E=M?{x:y,y:I.y}:{x:I.x,y};return!l.some(q=>E.x>q.l&&E.xq.t&&E.y1&&ot(J,m)?1:0})}),S.sort((I,D)=>D.pri-I.pri||D.len-I.len);let T=null,nt=!1;const z=(I,D=!0)=>{const j=Oe(I,$);return D&&(I.la.r||I.ta.b)||n.some(M=>qe(j,M))||h.some(M=>It(j,M))||o.heads.some(M=>It(j,M))||o.rects.some(M=>It(j,M))?!1:!e.some(M=>M.i!==u.i&&_t(M.pts).some(([B,H])=>It(j,Fe(B,H,M.width))))};for(const I of S){for(const D of[1/2,1/3,2/3]){const j=I.p+(I.q-I.p)*D,M=[],B=d("2")+u.width/2;if(I.horiz?(I.len>=C+2*d("1")+d("3-5")&&M.push({box:{l:j-C/2-d("1"),r:j+C/2+d("1"),t:I.c-W/2,b:I.c+W/2},on:!0}),M.push({box:{l:j-C/2,r:j+C/2,t:I.c-B-W,b:I.c-B},on:!1}),M.push({box:{l:j-C/2,r:j+C/2,t:I.c+B,b:I.c+B+W},on:!1})):(I.len>=W+d("3")&&M.push({box:{l:I.c-C/2-d("1"),r:I.c+C/2+d("1"),t:j-W/2,b:j+W/2},on:!0}),M.push({box:{l:I.c+B,r:I.c+B+C,t:j-W/2,b:j+W/2},on:!1}),M.push({box:{l:I.c-B-C,r:I.c-B,t:j-W/2,b:j+W/2},on:!1})),T=M.find(H=>z(H.box))??null,T)break;!nt&&M.some(H=>z(H.box,!1))&&(nt=!0)}if(T)break}if(!T){c.push(u.i),nt&&g.push(u.i);continue}const rt=He(T.box,i.ox,i.oy,I=>z(I));h.push(rt),f.push({i:u.i,text:x,box:rt,on:T.on})}return{labels:f,unseated:c,bounded:g}}function De(t,e,n,o){const l=[],a=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(s=>{if(s.getClientRects().length===0||getComputedStyle(s).display==="contents")return;const r=Et(s,e);a.push(r),l.push({l:r.l,r:r.r,t:r.t,b:r.t+1},{l:r.l,r:r.r,t:r.b-1,b:r.b},{l:r.l,r:r.l+1,t:r.t,b:r.b},{l:r.r-1,r:r.r,t:r.t,b:r.b});const i=s.querySelector(`:scope > .${n}-glabel`);i&&i.getClientRects().length&&l.push(Et(i,e))}),t.querySelectorAll(`.${n}-lane`).forEach((s,r)=>{if(!s.getClientRects().length)return;const i=Et(s,e);r>0&&l.push({l:i.l,r:i.r,t:i.t-o/2-.5,b:i.t-o/2+.5});const d=s.querySelector(`.${n}-lane-name`);d&&l.push(Et(d,e))}),{obstacles:{rects:l,heads:[]},groups:a}}function Ge(t,e){const{m:o,tk:l,P:a,drawing:s,origin:r,warn:i}=t,d=l.space,h=Ne(o,s,r,a),f=[...h.values()],c=Tn(s),g=r.left-Math.floor(r.left),$=r.top-Math.floor(r.top),p=Ce(g,$),u=s.clientWidth,x=s.clientHeight,C=b=>o.type==="data-flow"?b.col+1:b.col,W=parseFloat(getComputedStyle(s).rowGap)||0,v={w:u,h:x,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:g,oy:$};if(o.type==="sequence")return Wn(t,v,p);let S,T=[];o.type==="schema"?S=o.edges.map(b=>{const A=o.byId.get(b.from),L=o.byId.get(b.to);if(A.col===L.col){const k=A.col===o.cols&&o.cols>1?"left":"right";return[k,k]}return L.col>A.col?["right","left"]:["left","right"]}):(S=o.edges.map(b=>{const A=o.byId.get(b.from),L=o.byId.get(b.to),[k,O]=ce(A,L);return[b.fromSide??k,b.toSide??O]}),T=Re(o,S,i||(()=>{})));const nt=(b,A)=>{const L=s.querySelector(`.${a}-node[data-node="${CSS.escape(b)}"] .${a}-row[data-row="${A}"]`);if(!L)return 0;const k=Et(L,r);return(k.t+k.b)/2},z=new Map;if(o.type==="schema"){const b=new Map;o.edges.forEach((L,k)=>{const O=`${L.to}.${L.toRow}.${S[k][1]}`;b.set(O,[...b.get(O)??[],k])});const A=L=>{const k=o.edges[L].card?.to;return k==="one"?0:k==="zero-or-one"?1:2};for(const L of b.values()){const k=[...new Set(L.map(A))].sort((O,F)=>O-F);if(k.length>1)for(const O of L)z.set(O,(k.indexOf(A(O))-(k.length-1)/2)*d("2"))}}const rt=b=>Math.round(b+g)-g,I=o.edges.map((b,A)=>{const[L,k]=S[A],O=h.get(b.from),F=h.get(b.to),X=Ut(b.kind,l);if(b.fk){const Y=nt(b.from,b.fromRow),et=nt(b.to,b.toRow)+(z.get(A)??0),$t=p.y(Y,X),Bt=p.y(et,X),St=L==="right"?O.rect.r:O.rect.l,xt=k==="right"?F.rect.r:F.rect.l;return{p1:{x:b.card?rt(St):St,y:$t},p2:{x:b.card?rt(xt):xt,y:Bt},r1:Y,r2:Math.abs($t-Bt)<.01?Y:et}}const Q=T.find(Y=>Y.edge===A&&Y.end==="from").f,at=T.find(Y=>Y.edge===A&&Y.end==="to").f;let st=ze(O,L,Q),tt=ze(F,k,at);const N=dt(L)?st.y:st.x;let V=dt(k)?tt.y:tt.x;return dt(L)?st={...st,y:p.y(st.y,X)}:st={...st,x:p.x(st.x,X)},dt(k)?tt={...tt,y:p.y(tt.y,X)}:tt={...tt,x:p.x(tt.x,X)},dt(L)&&dt(k)&&Math.abs(st.y-tt.y)<1.01&&(tt={...tt,y:st.y},V=N),!dt(L)&&!dt(k)&&Math.abs(st.x-tt.x)<1.01&&(tt={...tt,x:st.x},V=N),st=dt(L)?kt(O,L,st.y):kt(O,L,st.x),tt=dt(k)?kt(F,k,tt.y):kt(F,k,tt.x),{p1:st,p2:tt,r1:N,r2:V}}),D=new Set,j=(b,A)=>{D.has(b)||(D.add(b),i?.(`${o.edges[b].from} to ${o.edges[b].to} ${A}, so its line is not drawn; its row still writes the target`))};for(const b of Jt(o).dropped)j(b,"would need a third lane of turn-backs");const M=new Map,B=At();o.type==="schema"&&o.edges.forEach((b,A)=>{const L=o.byId.get(b.from),k=o.byId.get(b.to);if(Math.abs(L.col-k.col)<2)return;const O=Math.min(L.col,k.col),F=Math.max(L.col,k.col),X=o.nodes.filter(et=>et.col>O&&et.col$t.row<=et&&$t.row2>=et+1)||at.push({key:`g${et}`,y:(Q[et-1][1]+Q[et][0])/2,inner:!0});at.push({key:"top",y:Q[0][0]-d("4"),inner:!1},{key:"bottom",y:Q[Q.length-1][1]+d("4"),inner:!1});const st=(I[A].r1+I[A].r2)/2,tt=t.pick?.[A]??at.slice().sort((et,$t)=>Math.abs(et.y-st)-Math.abs($t.y-st)||Number($t.inner)-Number(et.inner)||et.y-$t.y)[0].key;B[A]=tt;const N=S[A][0]==="right"?L.col:L.col-1,V=c.cols[N-1],Y=c.cols[N];M.set(A,{corridor:tt,first:V&&Y?{key:`c${N}`,span:[V[1],Y[0]]}:null,y:0})});const H=new Map;for(const[b,A]of M){const L=o.edges[b],k=H.get(A.corridor)??[],O=k.find(F=>{const X=o.edges[F[0]];return X.to===L.to&&X.toRow===L.toRow&&S[F[0]][1]===S[b][1]&&Math.abs(I[F[0]].p2.y-I[b].p2.y)<.5});O?O.push(b):k.length>=2?j(b,"would need a third lane in its corridor"):k.push([b]),H.set(A.corridor,k)}for(const b of[...M.keys()])D.has(b)&&M.delete(b);const Z=b=>{const A=o.edges[b[0]];return Math.abs(o.byId.get(A.from).col-o.byId.get(A.to).col)*1e4+Math.abs(I[b[0]].p1.x-I[b[0]].p2.x)},K=(b,A,L)=>{const k=c.rows;if(b==="top")return k[0][0]-d("4")-A*d("3");if(b==="bottom")return k[k.length-1][1]+d("4")+A*d("3");const O=Number(b.slice(1));return(k[O-1][1]+k[O][0])/2+(A-(L-1)/2)*d("3")},ot=(b,A)=>A.forEach((L,k)=>L.forEach(O=>{M.get(O).y=K(b,k,A.length)})),P=()=>{for(const[b,A]of H){const L=A.map(k=>k.filter(O=>M.has(O))).filter(k=>k.length);H.set(b,L),ot(b,b==="top"||b==="bottom"?L.slice().sort((k,O)=>Z(k)-Z(O)):L.slice().sort((k,O)=>Z(O)-Z(k)))}};P();const J=new Map,m=new Set,y=new Map,E=(b,A,L,k,O)=>{J.has(b)||J.set(b,{span:A,vertical:L,members:new Map});const F=J.get(b);F.members.has(k)||F.members.set(k,[]),F.members.get(k).push(O)},q=()=>{J.clear(),m.clear(),y.clear(),o.edges.forEach((b,A)=>{if(D.has(A))return;const L=M.get(A);L?.first&&E(L.first.key,L.first.span,!0,`far:${A}`,-(A+1));const[k,O]=S[A],{p1:F,p2:X}=I[A],Q=o.byId.get(b.from),at=o.byId.get(b.to);let st=null,tt=null,N=!1;if(k===O){if(dt(k)){const V=k==="right"?Math.max(C(Q),C(at)):Math.min(C(Q),C(at))-1,Y=c.cols[V-1],et=c.cols[V];Y&&et&&(st=`c${V}`,tt=[Y[1],et[0]],N=!0)}else{const V=k==="bottom"?Math.max(Q.row2,at.row2):Math.min(Q.row,at.row)-1,Y=c.rows[V-1],et=c.rows[V];Y&&et&&(st=`r${V}`,tt=[Y[1],et[0]],N=!1)}st&&m.add(A)}else if(dt(k)&&dt(O)&&(L||Math.abs(F.y-X.y)>.5)){const V=C(at),Y=O==="left",et=c.cols[(Y?V-1:V)-1],$t=c.cols[(Y?V:V+1)-1];et&&$t&&(st=`c${Y?V-1:V}`,tt=[et[1],$t[0]],N=!0)}else if(!dt(k)&&!dt(O)&&Math.abs(F.x-X.x)>.5){const Y=O==="top"?at.row-1:at.row2,et=c.rows[Y-1],$t=c.rows[Y];et&&$t&&(st=`r${Y}`,tt=[et[1],$t[0]],N=!1)}!st||!tt||(L&&y.set(A,tt),E(st,tt,N,`${b.to}.${O}.${Math.round(N?X.y:X.x)}`,A))})};q();const _=new Map,R=b=>{const[A,L]=S[b],{p1:k,p2:O}=I[b],F=M.get(b);if(F){const X=y.get(b),Q=_.get(-(b+1))??(F.first?(F.first.span[0]+F.first.span[1])/2:k.x),at=_.get(b)??(X?(X[0]+X[1])/2:O.x);return[k,{x:Q,y:k.y},{x:Q,y:F.y},{x:at,y:F.y},{x:at,y:O.y},O]}if(dt(A)&&dt(L)){if(A===L){const Q=d(o.marks?"6":"4")+(o.type==="schema"&&o.cols===1?(Jt(o).lane.get(b)??0)*d("3"):0),at=_.get(b)??(A==="right"?Math.max(k.x,O.x)+Q:Math.min(k.x,O.x)-Q);return[k,{x:at,y:k.y},{x:at,y:O.y},O]}if(Math.abs(k.y-O.y)<=.5)return[k,{x:O.x,y:k.y}];const X=_.get(b)??(k.x+O.x)/2;return[k,{x:X,y:k.y},{x:X,y:O.y},O]}if(!dt(A)&&!dt(L)){if(A===L){const Q=_.get(b)??(A==="bottom"?Math.max(k.y,O.y)+d("4"):Math.min(k.y,O.y)-d("4"));return[k,{x:k.x,y:Q},{x:O.x,y:Q},O]}if(Math.abs(k.x-O.x)<=.5)return[k,{x:k.x,y:O.y}];const X=_.get(b)??(k.y+O.y)/2;return[k,{x:k.x,y:X},{x:O.x,y:X},O]}return dt(A)?[k,{x:O.x,y:k.y},O]:[k,{x:k.x,y:O.y},O]},U=b=>{const A=o.edges[b],L=Ut(A.kind,l),k=R(b),O=je(k,L,p);let F;return k.length===O.length&&(F=_t(k).map(([X,Q])=>Math.abs(X.y-Q.y)<.75?(X.y+Q.y)/2:(X.x+Q.x)/2),F[0]=I[b].r1,F.length>1&&(F[F.length-1]=I[b].r2)),{i:b,from:A.from,to:A.to,kind:A.kind,pts:O,tip:O[O.length-1],dir:le(O),dot:A.fk&&!A.card?O[0]:void 0,card:A.card,width:L,axes:F}},G=()=>o.edges.flatMap((b,A)=>D.has(A)?[]:[U(A)]);let ht=null;const pt=b=>{ht??(ht=G());const A=ht.map(L=>b.has(L.i)?U(L.i):L);return{lines:A,score:Nn(A,b)*1e5+Qt(A,void 0,b).length*1e3+fe(A.filter(L=>b.has(L.i)),f,o).length}},lt=(b,A)=>{const L=b.flatMap(k=>{const O=k<0?-k-1:k,{p1:F,p2:X}=I[O],Q=M.get(O);return Q?k<0?[F.y,Q.y]:[Q.y,X.y]:A?[F.y,X.y]:[F.x,X.x]});return[Math.min(...L),Math.max(...L)]},ct=b=>b<0?-b-1:b,mt=b=>{const A=[...b.members.values()].map(k=>({members:k,run:lt(k,b.vertical)})).sort((k,O)=>k.run[0]-O.run[0]),L=[];for(const k of A){const O=L[L.length-1];O&&O.some(F=>F.run[0]!(k.length===1&&k[0].members.every(O=>m.has(O))))},wt=b=>(A,L)=>b[A].run[0]{const A=wt(b),L=[];return b.forEach((k,O)=>{let F=0;for(;L.some((X,Q)=>X===F&&A(O,Q));)F++;L.push(F)}),L},vt=b=>Math.max(0,...Mt(b))+1;if(o.marks)for(let b=0;b3){A=F.map(X=>X.members.map(ct));break}if(!A)break;const L=O=>Math.max(...O),k=A.filter(O=>O.some(F=>M.has(F))).sort((O,F)=>L(F)-L(O))[0]??A.slice().sort((O,F)=>L(F)-L(O))[0];for(const O of k)j(O,"would need a fourth lane in a marked gutter"),M.delete(O);q()}const ut=(b,A,L)=>{const k=b[1]-b[0];if(!o.marks)return b[0]+k/(L+1)*(A+1);const O=l.foot+l.radiusXs,F=L>1?Math.min(k/(L+1),(k-2*O)/(L-1)):0;return(b[0]+b[1])/2+(A-(L-1)/2)*F};P();for(const[b,A]of H){if(b==="top"||b==="bottom"||A.length<2)continue;const L=new Set(A.flat());let k=A,O=1/0;for(const F of de(A.slice().sort((X,Q)=>Z(Q)-Z(X)))){ot(b,F),ht=null;const X=pt(L);X.scoreat.members);if(o.marks){const at=vt(A),st=wt(A),tt=A.length,N=new Set(L.flat().map(ct)),V=St=>St.forEach((xt,Rt)=>L[Rt].forEach(Ot=>_.set(Ot,ut(b.span,xt,at))));let Y=Mt(A),et=1/0,$t=null;const Bt=[Y];if(at**tt<=729)for(let St=0;StMath.floor(St/at**Ot)%at);xt.every((Rt,Ot)=>xt.every((Gt,te)=>te<=Ot||Rt!==Gt||!st(Ot,te)))&&Bt.push(xt)}for(const St of Bt){V(St);const xt=pt(N);xt.scorett.forEach(V=>_.set(V,ut(b.span,N,k))));const st=pt(O);st.scoreat.forEach(tt=>_.set(tt,ut(b.span,st,k)))),ht=Q}if(v.lines=G(),o.marks&&(v.lines=v.lines.filter(b=>{if(!b.card)return!0;const A=_t(b.pts),L=([O,F])=>Math.hypot(F.x-O.x,F.y-O.y),k=A.length===1?2*l.foot:l.foot+l.radiusXs-.5;return L(A[0])>=k&&L(A[A.length-1])>=k?!0:(j(b.i,"has no room for its marks at an end"),!1)})),M.size){const b=new Set([...M.values()].map(L=>L.corridor)),A=[b.has("top")?"var(--basalt-space-8)":"0px"];for(let L=1;L<=o.rows;L++)A.push("auto",LWe(b,l));const bt=zn(o,v.lines,f,ft,it,{l:0,t:0,r:u,b:x},l,e,{ox:g,oy:$});return v.labels=bt.labels,v.unseated=bt.unseated,v.bounded=bt.bounded,v.overlaps=[...new Set(Ve(v.lines,null).flat())],v}function Nn(t,e){return Ve(t,e).length}function Ve(t,e){const n=[];for(let o=0;o=r)continue;const[u,x]=c?[i.x,d.x]:[i.y,d.y],[C,W]=c?[h.x,f.x]:[h.y,f.y];Math.min(Math.max(u,x),Math.max(C,W))-Math.max(Math.min(u,x),Math.min(C,W))>1&&n.push([a.i,s.i])}}return n}function*de(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const i=r===a.pts.length-1?Math.max(a.width/2,o.head/2):a.width/2;return s.x-i<-.5||s.x+i>e+.5||s.y-i<-.5||s.y+i>n+.5})&&l.push(a.i);return l}function fe(t,e,n){const o=[];for(const l of t){const a=_t(l.pts);e.some(s=>a.some(([r,i])=>Cn(r,i,s)))&&o.push(l.i)}return o}function Wn(t,e,n){const{m:o,tk:l,P:a,drawing:s,origin:r}=t,i=l.space,d=new Map;s.querySelectorAll(`.${a}-node`).forEach(v=>d.set(v.dataset.node,Et(v,r)));const h=s.querySelector(`.${a}-steps`),f=h?Et(h,r).b:e.h,c=v=>{const S=d.get(v);return S?n.x((S.l+S.r)/2,l.hair):0};for(const v of o.nodes){const S=d.get(v.id);S&&e.lifelines.push({x:c(v.id),y1:S.b,y2:f})}const g=v=>d.get(v.id),$=new Map;s.querySelectorAll(`.${a}-msg`).forEach(v=>{const S=Et(v,r);$.set(Number(v.querySelector(`.${a}-num`)?.textContent??0),(S.t+S.b)/2)});const p=l.activation,u=p/2,x=v=>{const S=o.byId.get(v.who);if(!S)return null;const T=c(v.who),z=(S.i===o.nodes.length-1&&o.nodes.length>1?-1:1)*(o.rtl?-1:1),rt=(v.depth-1)*i("1")*z,I=$.get(v.from)??0,D=$.get(v.to)??I,j=v.from===v.to;return{l:n.x(T-u+rt,l.hair),r:n.x(T+u+rt,l.hair),t:n.y(j?I-i("2")-i("1"):I,l.hair),b:n.y(j?I+i("2")+i("1"):D,l.hair)}},C=o.bars.map(v=>({bar:v,rect:x(v)})).filter(v=>v.rect);e.bars=C.map(v=>v.rect);const W=(v,S,T)=>C.filter(({bar:nt})=>nt.who===v&&nt.to>=S&&(T?nt.from<=S:nt.fromz.bar.depth-nt.bar.depth)[0]?.rect;return s.querySelectorAll(`.${a}-msg`).forEach(v=>{const S=v.dataset.from,T=v.dataset.to,nt=v.dataset.kind??"plain",z=Ut(nt,l),rt=Et(v,r),I=n.y((rt.t+rt.b)/2,z),D=Number(v.querySelector(`.${a}-num`)?.textContent??0);let j=c(S),M=c(T),B;if(S===T){const m=v.dataset.self==="start"?-i("6"):i("6"),y=W(S,D,!0),E=y?m>0?y.r:y.l:j,q=n.y(I-i("2"),z),_=n.y(I+i("2"),z);B=[{x:E,y:q},{x:n.x(j+m,z),y:q},{x:n.x(j+m,z),y:_},{x:E,y:_}]}else{const m=M>j?1:-1,y=W(S,D,!1),E=W(T,D,!0);y&&(j=m>0?y.r:y.l),E&&(M=m>0?E.l:E.r),B=[{x:j,y:I},{x:M,y:I}]}e.lines.push({i:D,from:S,to:T,kind:nt,pts:B,tip:B[B.length-1],dir:le(B),width:z});const H=v.querySelector(`.${a}-said`),Z=v.querySelector(`.${a}-note`),K=o.byId.get(S),ot=o.byId.get(T);if(!K||!ot)return;const P=S===T?(()=>{const m=o.nodes[K.i+(v.dataset.self==="start"?-1:1)],y=m?c(m.id):v.dataset.self==="start"?0:e.w;return Math.abs(y-j)-i("6")-i("2-5")-i("2")})():Math.abs(M-j)-2*i("2");Math.max(H?H.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>P+.5&&e.unseated.push(D)}),s.querySelectorAll(`.${a}-fhead`).forEach(v=>{const S=v.parentElement?.querySelector(`:scope > .${a}-fbox`);if(!S)return;[...v.children].reduce((nt,z)=>nt+z.getBoundingClientRect().width,0)+i("3")>S.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${v.querySelector(`.${a}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function Ze(t,e,n,o=At()){const{m:l,tk:a,P:s,drawing:r,origin:i}=t,d=a.space,h=Ne(l,r,i,s),f=[...h.values()],c=i.left-Math.floor(i.left),g=i.top-Math.floor(i.top),$=Ce(c,g),p=r.clientWidth,u=r.clientHeight,x={w:p,h:u,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:g},C=At();if(l.type==="sequence"||l.type==="schema")return{geo:x,grow:C};const W=p-(parseFloat(getComputedStyle(r).paddingRight)||0),v=(M,B,H)=>{const Z=[M];for(let K=1;K<=(qt(o,B)??0);K++)Z.push({...M,t:M.t+H*d("4")*K,b:M.b+H*d("4")*K});return Z},S=new Map;r.querySelectorAll(`.${s}-node`).forEach(M=>{const B=M.parentElement,H=Et(B,i),Z=getComputedStyle(B);S.set(M.dataset.node,H.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const T=l.nodes,nt=M=>h.get(T[M].id),z=[],rt=M=>Ut(l.edges[M].kind,a);l.edges.forEach((M,B)=>{const H=n.routes[B],Z=h.get(M.from),K=h.get(M.to),ot=rt(B);let P=[];const J=M.label,m=J?e(J,"label"):0,y=J?16*ne(J):16,E=d("4");if(H==="down"||H==="up"){const _=Math.max(Z.rect.l,K.rect.l),R=Math.min(Z.rect.r,K.rect.r),U=l.edges.map((lt,ct)=>({o:lt,j:ct})).filter(({o:lt,j:ct})=>(n.routes[ct]==="down"||n.routes[ct]==="up")&&(lt.from===M.from&<.to===M.to||lt.from===M.to&<.to===M.from)),G=U.findIndex(lt=>lt.j===B),ht=U.length<2?.5:U.length===2?G===0?.25:.75:(G+1)/(U.length+1),pt=$.x(_+(R-_)*ht,ot);if(P=H==="down"?[kt(Z,"bottom",pt),kt(K,"top",pt)]:[kt(Z,"top",pt),kt(K,"bottom",pt)],J){let lt=Math.min(P[0].y,P[1].y),ct=Math.max(P[0].y,P[1].y);H==="down"?ct-=a.head:lt+=a.head;const mt=[...r.querySelectorAll(`.${s}-group`)].map(ut=>Et(ut,i));let wt=[[lt,ct]];for(const ut of mt)for(const ft of[ut.t,ut.b])wt=wt.flatMap(([it,bt])=>ft>it+1&&ftmt.some(it=>(ut+ft)/2>it.t&&(ut+ft)/2it.l&&pt1){const ut=wt.filter(([it,bt])=>!Mt(it,bt));[lt,ct]=(ut.length?ut:wt).reduce((it,bt)=>bt[1]-bt[0]>it[1]-it[0]?bt:it)}const vt=[1/2,1/3,2/3].map(ut=>{const ft=lt+(ct-lt)*ut;return{l:pt-m/2-d("1"),r:pt+m/2+d("1"),t:ft-y/2,b:ft+y/2}});z.push({k:B,cands:vt,on:!0,card:H==="down"?M.to:M.from})}}else if(H==="trunk"||H==="rail"){const _=$.x(Math.max(Z.rect.l,H==="rail"?K.rect.l:Z.rect.l)+d(H==="trunk"?"8":"3"),ot),R=kt(Z,"bottom",_);if(H==="rail"){if(P=[R,kt(K,"top",_)],J){const U=K.rect.t-d("6");z.push({k:B,cands:v({l:_+d("2-5"),r:_+d("2-5")+m,t:U-y/2,b:U+y/2},M.to,-1),on:!1,card:M.to})}}else{const U=$.x(K.rect.l+d("6"),ot),G=$.y(K.rect.t-E,ot);P=[R,{x:_,y:G},{x:U,y:G},kt(K,"top",U)],J&&z.push({k:B,cands:v({l:U+d("2-5"),r:U+d("2-5")+m,t:G-y/2,b:G+y/2},M.to,-1),on:!1,card:M.to})}}else{const _=Math.min(S.get(M.from)??p,S.get(M.to)??p),R=$.x(n.gutter?W+(n.lanes[B]+1)*d("3-5"):_-d("2-5"),ot),U=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[B],ot),G=kt(Z,"right",U),ht=H==="end-down",pt=l.edges.map((ft,it)=>({o:ft,j:it})).filter(({o:ft,j:it})=>n.routes[it]===H&&ft.to===M.to).sort((ft,it)=>n.lanes[it.j]-n.lanes[ft.j]||ft.j-it.j),lt=Math.max(0,pt.findIndex(({j:ft})=>ft===B)),ct=K.rect.r-d("6")-lt*d("3"),mt=K.rect.r-d("6")-(pt.length-1)*d("3"),wt=$.x(ct,ot),Mt=ht?K.rect.t-E-lt*d("5"):K.rect.b+E+lt*d("5"),vt=$.y(Mt,ot);P=[G,{x:R,y:G.y},{x:R,y:vt},{x:wt,y:vt},kt(K,ht?"top":"bottom",wt)];const ut=ht?M.to:T[K.i+1]?.id??M.to;J&&z.push({k:B,cands:v({l:mt-d("2-5")-m,r:mt-d("2-5"),t:Mt-y/2,b:Mt+y/2},ut,ht?-1:1),on:!1,card:ut})}const q=je(P,ot,$);x.lines.push({i:B,from:M.from,to:M.to,kind:M.kind,pts:q,tip:q[q.length-1],dir:le(q),width:ot})}),x.crossings=Qt(x.lines),x.through=fe(x.lines,f,l),x.outside=Ke(x.lines,p,u,a);const{obstacles:I}=De(r,i,s,0);I.heads=x.lines.map(M=>We(M,a));const D=[],j={l:0,t:0,r:p,b:u};for(const M of z){const B=K=>{const ot=Oe(K,d("1"));return K.lj.r+.5||K.tj.b+.5||f.some(P=>qe(ot,P))||D.some(P=>It(ot,P))||I.heads.some(P=>It(ot,P))||I.rects.some(P=>It(ot,P))||x.lines.some(P=>P.i!==M.k&&_t(P.pts).some(([J,m])=>It(ot,Fe(J,m,P.width))))},H=M.cands.find(K=>!B(K));H||(C[M.card]=(C[M.card]??0)+1,x.unseated.push(M.k));const Z=H?He(H,c,g,K=>!B(K)):M.cands[0];D.push(Z),x.labels.push({i:M.k,text:l.edges[M.k].label,box:Z,on:M.on})}return{geo:x,grow:C}}function Je(t,e,n=0){const o=s=>String(Math.round(s*100)/100);let l=`M${o(t[0].x)} ${o(t[0].y)}`;for(let s=1;s{const{crow:D,ring:j}=Ee(nt,z.x,z.y,rt,n.head,n.dot);return`${j?``:""}`};return`${T(e.card.from,v,Math.sign(S.x-v.x)||1,"from")}${T(e.card.to,e.tip,-a.x||1,"to")}`}const s=e.kind==="dashed",r=n.head,i=n.head/2,d=s?1:r-1,h=e.pts.map(v=>({...v})),f=h[h.length-1];f.x-=a.x*d,f.y-=a.y*d;const c=e.tip.x-a.x*r,g=e.tip.y-a.y*r,$=-a.y*i,p=a.x*i,u=v=>Math.round(v*100)/100,x=yt(e.kind),C=s?``:``,W=e.dot?``:"";return`${C}${W}`}function Xe(t,e,n,o){const l=new Map,a=new Map;for(const r of e.crossings)a.has(r.under)||a.set(r.under,[]),a.get(r.under).push(r);let s="";for(const[r,i]of a){const d=`${o}-cut-${r}`;l.set(r,d);const h=i.map(f=>{const c=e.lines[f.top],g=e.lines[f.under],$=c.width/2+n.cut,p=g.width/2+1;return f.underVertical?``:``}).join("");s+=`${h}`}return{defs:s,ids:l}}function Ue(t,e,n,o){const{defs:l,ids:a}=Xe(t,e,n,o),s=e.lifelines.map(h=>``).join("")+(e.bars??[]).map(h=>``).join(""),r=e.lines.map((h,f)=>Hn(t,h,n,a.get(f)??null,h.from===h.to?n.radiusXs:n.radius)).join(""),i=`${l?`${l}`:""}${s}${r}`,d=e.labels.map(h=>`1?' data-lines="2"':""} style="left:${Math.round(h.box.l*100)/100}px;top:${Math.round(h.box.t*100)/100}px;width:${Math.round((h.box.r-h.box.l)*100)/100}px">${h.text.split(` +`).map(yt).join("
")}
`).join("");return i+d}function ue(t,e,n,o,l,a,s,r){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:l,geo:null,ink:"",tokens:null};const h=On(t),f=Bn(d,n),c=Rn(e,h,f);r?.(c.least);const g=t.clientWidth,$=(()=>{const I=document.activeElement;return I&&d.contains(I)&&I.dataset.node?I.dataset.node:void 0})(),p=I=>jt(e,I)?{...I,stop:I.stop&&e.byId.has(I.stop)?I.stop:e.nodes[0]?.id,keep:void 0}:{...I,stop:I.stop??e.nodes[0]?.id,keep:$&&I.layout!=="drawn"?$:void 0};let u=!1;const x=I=>{if(u=!1,e.type!=="flowchart")return I;a({...I,heights:void 0,words:void 0});const D=At(),j=At();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const B=M.querySelector(`.${n}-words`);if(!B)return;const H=M.getBoundingClientRect(),Z=P=>{const J={w:P.width+2*h.space("2-5"),h:P.height+2*h.space("2")},m=1-J.w/H.width,y=m>.05?J.h/2/m:J.h*10;return Math.max(h.space("16"),Math.ceil(H.width/5),Math.ceil(2*y))},K=B.getBoundingClientRect();let ot=Z(K);if(ot>H.width){const P=E=>(M.style.setProperty("--_ww",`${E}px`),B.getBoundingClientRect()),J=Math.floor(M.clientWidth-2*h.space("2-5"));let m=Math.ceil(K.width),y=K.height;for(;m1;){const U=E+q>>1;P(U).heightH.width&&(u=!0)}),{...I,heights:D,words:Object.keys(j).length?j:void 0}},C=()=>({m:e,tk:h,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:s}),W=l.autoOpen?{open:!1,autoOpen:void 0}:{},v=(I,D)=>D.map(j=>Dt(e,I.lines.find(M=>M.i===j))).join(", ");if(e.text)return{dyn:{...l,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:h,least:c.least};if(g>=c.least&&!e.unplaced){const I=B=>{let H=p({...l,...W,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:B||void 0,rows:void 0});H=x(H),a(H);let Z=Ge(C(),f);return Z.corridors&&(H={...H,rows:Z.corridors.rows},a(H),Z=Ge({...C(),pick:Z.corridors.pick},f)),{dd:H,g:Z}};let{dd:D,g:j}=I(!1);const M=B=>B.through.length>0||B.outside.length>0||(B.overlaps?.length??0)>0||(B.misfit?.length??0)>0||u;if(!M(j)&&j.unseated.length&&j.unseated.every(B=>j.bounded?.includes(B))){const B=I(!0);!M(B.g)&&!B.g.unseated.length&&({dd:D,g:j}=B)}if(!M(j)&&!j.unseated.length)return j.crossings.length&&s?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the drawn layout: ${j.crossings.map(B=>`${Dt(e,j.lines[B.top])} over ${Dt(e,j.lines[B.under])}`).join("; ")}`),{dyn:D,geo:j,ink:Ue(n,j,h,o),tokens:h,least:c.least};u&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: a decision would be taller than it is wide`),j.misfit?.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: ${j.misfit.join("; ")}`),j.through.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: ${v(j,j.through)} would pass through a node`),j.overlaps?.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: ${v(j,j.overlaps)} would lie on one another`),j.outside.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: ${v(j,j.outside)} would leave the drawing`),j.unseated.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: no clean seat for ${j.unseated.map(B=>e.type==="sequence"?`message ${B}`:`"${Lt(e.edges[B]?.label??"")}"`).join(", ")}`)}let S=p({...l,...W,layout:"stacked",heights:void 0,grow:At(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0,rows:void 0});if(S=x(S),a(S),e.type==="sequence"||e.type==="schema")return{dyn:S,geo:null,ink:"",tokens:h,least:c.least};const T=Me(e);let nt=Ze(C(),f,T,S.grow);for(let I=0;I<6&&Object.keys(nt.grow).length;I++){const D=At(S.grow);for(const[j,M]of Object.entries(nt.grow))D[j]=(qt(D,j)??0)+M;S={...S,grow:D},a(S),nt=Ze(C(),f,T,D)}const z=nt.geo;if(!T.third&&T.laneCount>2&&s?.(`the stacked drawing uses ${T.laneCount} end lanes (four at most)`),z.unseated.length>0||z.through.length>0||z.outside.length>0||T.third){z.unseated.length&&s?.(`the stacked drawing has no clean seat for ${[...new Set(z.unseated)].map(j=>`"${Lt(e.edges[j]?.label??"")}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),z.through.length&&s?.(`in the stacked drawing ${v(z,z.through)} would pass through a node, so its lines are not drawn`),z.outside.length&&s?.(`in the stacked drawing ${v(z,z.outside)} would leave the drawing, so its lines are not drawn`),T.third&&s?.("the stacked drawing would need a fifth end lane, so its lines are not drawn");const I={...z,lines:[],labels:[],crossings:[]};return{dyn:p({...S,grow:At(),bare:!0,open:l.bare?l.open:!0,autoOpen:l.bare?l.autoOpen:l.open?void 0:!0}),geo:I,ink:"",tokens:h,least:c.least}}return z.crossings.length&&s?.(`${z.crossings.length} crossing${z.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${z.crossings.map(I=>`${Dt(e,z.lines[I.top])} over ${Dt(e,z.lines[I.under])}`).join("; ")}`),{dyn:S,geo:z,ink:Ue(n,z,h,o),tokens:h,least:c.least}}function Dt(t,e){const n=t.byId.get(e.from)?.name??e.from,o=t.byId.get(e.to)?.name??e.to;return`${n} to ${o}`}function Dn(t,e,n,o,l,a){const s=new Set;if(a){s.add(a);for(const p of n?.lines??[])p.from===a&&s.add(p.to),p.to===a&&s.add(p.from)}if(t.toggleAttribute("data-tracing",!!a),t.querySelectorAll(`.${e}-node`).forEach(p=>p.toggleAttribute("data-near",s.has(p.dataset.node))),!n||!o)return;const r=p=>!!a&&(p.from===a||p.to===a),i=t.querySelector(`.${e}-edges`),d=new Map;t.querySelectorAll(`.${e}-edge`).forEach(p=>d.set(p.getAttribute("data-edge"),p));for(const p of n.lines){const u=d.get(String(p.i));u&&(u.toggleAttribute("data-lit",r(p)),u.toggleAttribute("data-dim",!!a&&!r(p)))}if(t.querySelectorAll(`.${e}-label`).forEach(p=>{const u=n.lines.find(x=>String(x.i)===p.dataset.edge);p.toggleAttribute("data-lit",!!(u&&r(u)))}),i){for(const p of n.lines)if(r(p)){const u=d.get(String(p.i));u&&i.appendChild(u)}}const h=Qt(n.lines,r),{defs:f,ids:c}=Xe(e,{...n,crossings:h},o,l),g=t.querySelector(`.${e}-svg`);if(!g)return;let $=g.querySelector("defs");!$&&f&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),g.insertBefore($,g.firstChild)),$&&($.innerHTML=f),n.lines.forEach((p,u)=>{const x=d.get(String(p.i))?.querySelector(`.${e}-line`);if(!x)return;const C=c.get(u);C?x.setAttribute("mask",`url(#${C})`):x.removeAttribute("mask")})}var Gn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Vn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Gn()||Zn(t)?"done":"pending")}}var Kn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Zn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Kn(t))!==null}catch{return!1}}function Ye(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Jn(t,e,n,o=!1,l=!1){const a=o?Zt(t):null;if(a&&n.startsWith("Arrow")){const d={ArrowRight:l?"left":"right",ArrowLeft:l?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return d?a[e]?.[d]??null:null}const s=t.byId.get(e)?.i??0,r=t.nodes.length;let i;if(n==="ArrowRight"||n==="ArrowDown")i=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")i=s-1;else if(n==="Home")i=0;else if(n==="End")i=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,i))].id}var Xn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Qe=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],Un=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad","--_gw","--_mh","--_rows","--_row-gap"],Pe=t=>t==null||t===!1;function Yn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Pt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const o=n?Qe:Xn;for(const s of o)Pe(e.a[s])&&t.removeAttribute(s);for(const[s,r]of Object.entries(e.a)){if(s==="class")continue;if(s==="style"){const d=t.style,h=new Map(String(r??"").split(";").map(f=>{const c=f.indexOf(":");return[f.slice(0,c).trim(),f.slice(c+1).trim()]}).filter(([f])=>f));for(const[f,c]of h)d.getPropertyValue(f).trim()!==c&&d.setProperty(f,c);for(const f of Un)h.has(f)||d.removeProperty(f);continue}if(n&&!Qe.includes(s))continue;if(Pe(r)){t.removeAttribute(s);continue}const i=r===!0?"":String(r);t.getAttribute(s)!==i&&t.setAttribute(s,i)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(s=>typeof s!="string"&&"slot"in s))return;const l=[...t.children];let a=0;for(const s of e.c)if(!(typeof s=="string"||"slot"in s)){for(let r=a;rt.querySelector(`.${e}-node[data-node="${CSS.escape(a)}"]`);n&&l(n)?.setAttribute("tabindex","-1"),l(o)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",o=0;function l(c,g,$){return{prefix:n,base:c,hasSource:g.source!==void 0&&g.source!==null&&g.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function a(c,g,$,p){var u=function(x){return''+yt(x)+""};return{source:yt(String(g.source||"")),summary:yt(String(g.summary||"")),hint:re(c).map(function(x){return""+x.keys.map(u).join(" ")+" "+yt(x.words)+""}).join(""),toggle:'"}}function s(c,g,$){var p=zt(c),u=Xt(p,{},l(g,c,$)),x=oe(u,a(p,c,g,!1)),C=x.indexOf(">");return{open:x.slice(0,C+1),inner:x.slice(C+1,x.length-9),warnings:p.warnings}}var r=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-marks","data-layout","data-measured","data-bare"],i=["--_cols","--_gpad","--_track"];function d(c,g,$,p){c.__diagram&&c.__diagram.stop();var u=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),x=getComputedStyle(c).direction==="rtl",C=g.layout==="auto"&&(g.type==="architecture"||g.type==="flowchart"||g.type==="schema"),W=C?Array.isArray(g.placement)?g.placement:g.placement?[g.placement]:[]:[];C&&!W.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var v=g.direction?[g.direction]:g.type==="flowchart"?["down","right"]:["right","down"],S=function(N){for(var V=0;V .diagram-drawing")){if(!u||!c.querySelector("#"+CSS.escape(u+"-title"))){for(;document.getElementById("dg"+ ++o+"-title"););u="dg"+o}var nt=s(g,u,p),z=document.createElement("div");z.innerHTML=nt.open+"";var rt=z.firstChild;r.forEach(function(N){c.removeAttribute(N)}),i.forEach(function(N){c.style.removeProperty(N)});for(var I=0;I :not(script[data-diagram])").forEach(function(N){N.remove()}),c.insertAdjacentHTML("beforeend",nt.inner)}T.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var j=l(u,g,p),M={},B=null,H=null,Z=null,K=null,ot=Object.create(null),P=function(N){ot[N]||(ot[N]=1,console.warn("Basalt diagram: "+N))},J=function(N){Pt(c,Xt(T,N,j))},m=c.querySelector(".diagram-ink"),y=c.querySelector(".diagram-toggle"),E=!p&&T.motion.animated&&typeof e.diagramMotion=="function",q=null,_=null,R=function(){E&&Ye(c)};function U(){Dn(c,n,B&&B.geo,B&&B.tokens,u,H||K||Z),pt()}var G=null,ht=!p&&matchMedia("(hover: none), (pointer: coarse)").matches;function pt(){var N=ht&&!p&&m&&m.innerHTML!=="";if(c.toggleAttribute("data-touch",!!(ht&&!p)),N&&!G){var V=c.querySelector(":scope > .diagram-foot");if(!V)return;G=document.createElement("button"),G.type="button",G.className="btn diagram-clear",G.setAttribute("data-variant","secondary"),G.setAttribute("data-size","sm"),G.innerHTML="Clear highlight",G.addEventListener("click",function(){K&&(K=null,U())}),V.appendChild(G)}else!N&&G&&(G.remove(),G=null);G&&(K?G.removeAttribute("aria-disabled"):G.setAttribute("aria-disabled","true"))}function lt(N){if(!N.defaultPrevented){var V=un(c,n,N,K);V!==void 0&&(R(),ht=!0,K=V,U())}}function ct(){y&&(y.setAttribute("aria-expanded",String(!!M.open)),y.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function mt(){if(C&&W.length>1&&!p){for(var N=null,V=0;V1&&p&&!g.direction&&p.room){for(var Bt=p.room(),St=-1,xt=null,Rt=0;RtSt+1e-6&&(St=tn,xt=Gt)}}}xt&&(T=xt)}B=(p?p.measure:ue)(c,T,n,u,M,J,P),M=B.dyn,J(M),ct();var he=c.querySelector(":scope > .diagram-hint");if(he){var en=re(T,M.layout==="drawn").map(function(Wt){return""+Wt.keys.map(function(Pn){return''+yt(Pn)+""}).join(" ")+" "+yt(Wt.words)+""}).join("");he.innerHTML!==en&&(he.innerHTML=en)}jt(T,M)||(Z=K=null);var nn=m&&B.ink!==_;nn&&(m.innerHTML=B.ink,_=B.ink),U(),E&&B.tokens&&(Vn(c,!!(B.geo&&B.geo.lines.length)),nn&&q&&q.redrawn()),p&&p.onMeasured&&B.tokens&&p.onMeasured(B,c),T.text&&typeof e.diagramText=="function"&&e.diagramText(c,T,g)}function wt(N){M=N,J(M)}function Mt(N){var V=M.stop;M=Object.assign({},M,{stop:N}),Qn(c,n,V,N)}var vt=function(N){var V=N&&N.closest?N.closest(".diagram-node"):null;return V&&c.contains(V)?V:null};function ut(N){var V=vt(N.target);if(!(!V||N.defaultPrevented)){if(R(),N.key==="Escape"){!p&&(H||Z||K)&&(N.preventDefault(),H=Z=K=null,U());return}if(jt(T,M)){var Y=Jn(T,V.getAttribute("data-node"),N.key,M.layout==="drawn");if(Y){N.preventDefault(),Mt(Y);var et=c.querySelector('.diagram-node[data-node="'+CSS.escape(Y)+'"]');et&&et.focus()}}}}function ft(N){var V=vt(N.target);if(V){R();var Y=V.getAttribute("data-node");H=V.matches(":focus-visible")?Y:null,jt(T,M)&&M.stop!==Y&&Mt(Y),U()}}function it(N){var V=vt(N.target);V&&(vt(N.relatedTarget)||(H=null),M.keep===V.getAttribute("data-node")&&wt(Object.assign({},M,{keep:void 0})),U())}function bt(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var V=vt(N.target);V&&R();var Y=V&&jt(T,M)?V.getAttribute("data-node"):null;Y!==Z&&(Z=Y,U())}}function b(){Z&&(Z=null,U())}function A(){R(),wt(Object.assign({},M,{open:!M.open,autoOpen:void 0})),ct()}c.addEventListener("keydown",ut),c.addEventListener("focusin",ft),c.addEventListener("focusout",it),c.addEventListener("pointerover",bt),c.addEventListener("pointerleave",b),c.addEventListener("click",lt),y&&y.addEventListener("click",A),mt();var L=c.clientWidth,k=0,O=!0,F=new ResizeObserver(function(){Math.abs(c.clientWidth-L)<.5||(L=c.clientWidth,cancelAnimationFrame(k),k=requestAnimationFrame(mt))});F.observe(c),document.fonts&&document.fonts.ready.then(function(){O&&mt()});var X=matchMedia("(forced-colors: active)"),Q=T.nodes.some(function(N){return N.mark});Q&&X.addEventListener("change",mt),E&&(q=e.diagramMotion(c,{fig:c,P:n,base:u,model:function(){return T},geo:function(){return B&&B.geo},tokens:function(){return B&&B.tokens}},g));var at=!p&&g.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,g,{model:T,settle:R,animated:E}):null,st=c.querySelector(":scope > .diagram-foot"),tt=!p&&g.export===!0&&st&&typeof e.diagramExport=="function"?e.diagramExport(st,c):[];c.__diagram={stop:function(){at&&at.destroy(),tt.forEach(function(N){N.remove()}),O=!1,F.disconnect(),cancelAnimationFrame(k),Q&&X.removeEventListener("change",mt),q&&q.destroy(),c.removeEventListener("keydown",ut),c.removeEventListener("focusin",ft),c.removeEventListener("focusout",it),c.removeEventListener("pointerover",bt),c.removeEventListener("pointerleave",b),c.removeEventListener("click",lt),G&&G.remove(),y&&y.removeEventListener("click",A)},layout:mt,key:h(g),send:q&&q.sendValue?q.sendValue:null}}function h(c){try{return JSON.stringify(c,function(g,$){return g==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function f(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var g=c.querySelector(":scope > script[data-diagram]");if(g)try{d(c,JSON.parse(g.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=s,e.diagramKit={draw:d,buildModel:zt,figureKey:bn,figureList:An,hintEntries:re,toHtml:oe,escapeHtml:yt,settleEntrance:Ye,measureFigure:ue},t.diagram=function(c,g){var $=c.__diagram,p=$&&$.send?h(g):null;if(p!==null&&p===$.key){$.send(g.packet?g.packet.send:void 0);return}d(c,g)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 9183b9b6..4f0ebf4f 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -137,7 +137,13 @@ export interface DiagramSpec { export type DiagramUnplaced = Omit & { col?: number; row?: number | [number, number] }; /** Where an automatic figure's cards go in one direction (1.8): `placeDiagram`'s answer. */ -export interface DiagramPlacement { direction: "right" | "down"; cells: Record } +export interface DiagramPlacement { + direction: "right" | "down"; + cells: Record; + /** The grid's tracks (DECISIONS 322, rule 1): at least the cards' own, and more where a track holds only a main line's way. */ + cols?: number; + rows?: number; +} // ============================================================================================================================================ // The model @@ -552,7 +558,9 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model } const fl = (spec.frameLabels ?? {}) as Record; const frameWords = { opt: txt(fl.opt) ?? "Only if", loop: txt(fl.loop) ?? "Repeats", alt: txt(fl.alt) ?? "One of these", else: txt(fl.else) ?? "Otherwise" }; - let cols = Math.max(1, ...nodes.map((n) => n.col)); + // An automatic figure's tracks include those that hold only a main line's way (DECISIONS 322, rule 1). + const placed = spec.layout === "auto" && !unplaced ? options.placement : undefined; + let cols = Math.max(1, placed?.cols ?? 1, ...nodes.map((n) => n.col)); // Right to left (1.7): column 1 at the right. Columns are mirrored, a frame's span with them, and a named left or right side swaps. if (options.rtl) { for (const n of nodes) n.col = cols - n.col + 1; @@ -561,7 +569,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model for (const st of steps) if ("open" in st) { const [a, b] = [cols - st.b + 1, cols - st.a + 1]; st.a = a; st.b = b; } cols = Math.max(1, ...nodes.map((n) => n.col)); } - const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, ...nodes.map((n) => n.row2)); + const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, placed?.rows ?? 1, ...nodes.map((n) => n.row2)); const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined, text: (type === "sequence" && spec.variant === "text") || undefined, marks: edges.some((e) => e.card) || undefined }; if (spec.layout === "auto" && !unplaced && type !== "schema") chooseSides(model); if (checks) for (const [id, h0] of Object.entries(portFloors(model))) if (h0 >= 48) warn(`${id} grows to ${h0}px to hold the lines on one side: use another side`); @@ -585,8 +593,11 @@ function chooseSides(m: Model) { const ex: DiagramSide = b.col > a.col ? "left" : "right", ey: DiagramSide = b.row > a.row ? "top" : "bottom"; const along = (lo: number, hi: number, at: number, horizontal: boolean) => between(lo, hi).map((k) => (horizontal ? [k, at] : [at, k]) as [number, number]); let list: Shape[]; - if (a.row === b.row) list = [{ sides: [sx, ex], cells: along(a.col, b.col, a.row, true) }, { sides: ["bottom", "bottom"], cells: [] }, { sides: ["top", "top"], cells: [] }]; - else if (a.col === b.col) list = [{ sides: [sy, ey], cells: along(a.row, b.row, a.col, false) }, { sides: ["right", "right"], cells: [] }, { sides: ["left", "left"], cells: [] }]; + // A turn-back runs in the gutter beside its side (DECISIONS 322, rule 4): it is a shape only where a track lies beyond that side, so none is chosen on + // the drawing's own edge, where it would leave the drawing. + const turn = (side: DiagramSide): Shape[] => ((side === "right" ? a.col < m.cols : side === "left" ? a.col > 1 : side === "bottom" ? a.row < m.rows : a.row > 1) ? [{ sides: [side, side], cells: [] }] : []); + if (a.row === b.row) list = [{ sides: [sx, ex], cells: along(a.col, b.col, a.row, true) }, ...turn("bottom"), ...turn("top")]; + else if (a.col === b.col) list = [{ sides: [sy, ey], cells: along(a.row, b.row, a.col, false) }, ...turn("right"), ...turn("left")]; else list = [ { sides: [sx, ey], cells: [...along(a.col, b.col, a.row, true), [b.col, a.row], ...along(a.row, b.row, b.col, false)] }, { sides: [sy, ex], cells: [...along(a.row, b.row, a.col, false), [a.col, b.row], ...along(a.col, b.col, b.row, true)] }, @@ -596,12 +607,29 @@ function chooseSides(m: Model) { return list.filter((c) => c.cells.every(([x, y]) => !taken.has(`${x},${y}`))); }; const load = new Map(); + const left = new Set(); + // Sides the author named count before any line chooses (DECISIONS 322, rule 3). + for (const e of m.edges) if (e.fromSide || e.toSide) { + const [d1, d2] = defaultSides(m.byId.get(e.from)!, m.byId.get(e.to)!); + const s1 = e.fromSide ?? d1, s2 = e.toSide ?? d2; + left.add(`${e.from}.${s1}`); + for (const [id, side] of [[e.from, s1], [e.to, s2]] as const) load.set(`${id}.${side}`, (load.get(`${id}.${side}`) ?? 0) + 1); + } const order = m.edges.map((_, k) => k).sort((p, q) => shapes(m.edges[p]!).length - shapes(m.edges[q]!).length || Number(m.edges[q]!.kind === "main") - Number(m.edges[p]!.kind === "main") || p - q); for (const k of order) { const e = m.edges[k]!; if (e.fromSide || e.toSide) continue; - const ok = shapes(e).find((c) => (load.get(`${e.from}.${c.sides[0]}`) ?? 0) < 3 && (load.get(`${e.to}.${c.sides[1]}`) ?? 0) < 3); + // A decision's lines meet at its four points (DECISIONS 322, rule 3): a point a line leaves takes no other line, so two lines never leave one point on + // one another and a line never arrives where one leaves. Lines that arrive at one point join, three at most, as on any side. + const room = (id: string, side: DiagramSide, leaving: boolean) => { + const key = `${id}.${side}`; + if ((load.get(key) ?? 0) >= 3) return false; + if (m.byId.get(id)!.shape !== "decision") return true; + return leaving ? !load.has(key) : !left.has(key); + }; + const ok = shapes(e).find((c) => room(e.from, c.sides[0], true) && room(e.to, c.sides[1], false)); if (!ok) continue; + left.add(`${e.from}.${ok.sides[0]}`); for (const [id, side] of [[e.from, ok.sides[0]], [e.to, ok.sides[1]]] as const) load.set(`${id}.${side}`, (load.get(`${id}.${side}`) ?? 0) + 1); e.fromSide = ok.sides[0]; e.toSide = ok.sides[1]; @@ -2088,7 +2116,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge // A line that is not drawn: its row still writes the target, and a development build names it. One tight line never stacks the figure. const drop = (k: number, why: string) => { if (dropped.has(k)) return; dropped.add(k); if (dev) warn?.(`${m.edges[k]!.from} to ${m.edges[k]!.to} ${why}, so its line is not drawn; its row still writes the target`); }; // A one-column schema's third lane of turn-backs is not drawn (call 2). - for (const k of turnBackLanes(m).dropped) drop(k, "would need a third lane of turn-backs"); + for (const k of turnBackLanes(m).dropped) drop(k, dev ? "would need a third lane of turn-backs" : ""); // Foreign keys two or more columns away (1.1): out of the row's facing side, a turn in the gutter beside its own table, a run along a corridor (a // row gap no table of the columns between stands in, or the margin above or below), a turn in the gutter beside the referenced table into the key. @@ -2122,7 +2150,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge const groups = corridorGroups.get(f.corridor) ?? []; const bus = groups.find((g) => { const o = m.edges[g[0]!]!; return o.to === e.to && o.toRow === e.toRow && sides[g[0]!]![1] === sides[k]![1] && Math.abs(ends[g[0]!]!.p2.y - ends[k]!.p2.y) < 0.5; }); if (bus) bus.push(k); - else if (groups.length >= 2) drop(k, "would need a third lane in its corridor"); + else if (groups.length >= 2) drop(k, dev ? "would need a third lane in its corridor" : ""); else groups.push([k]); corridorGroups.set(f.corridor, groups); } @@ -2298,7 +2326,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge if (!over) break; const latest = (group: number[]) => Math.max(...group); const victim = over.filter((group) => group.some((k) => far.has(k))).sort((p, q) => latest(q) - latest(p))[0] ?? over.slice().sort((p, q) => latest(q) - latest(p))[0]!; - for (const k of victim) { drop(k, "would need a fourth lane in a marked gutter"); far.delete(k); } + for (const k of victim) { drop(k, dev ? "would need a fourth lane in a marked gutter" : ""); far.delete(k); } gather(); } // Lanes in a marked gutter (1.1): none nearer a table than the zone plus radius-xs (18), centred and evenly spaced at the merged pitch or the pitch @@ -2370,7 +2398,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge const len = ([a, b]: readonly [Pt, Pt]) => Math.hypot(b.x - a.x, b.y - a.y); const need = segs.length === 1 ? 2 * tk.foot : tk.foot + tk.radiusXs - 0.5; if (len(segs[0]!) >= need && len(segs[segs.length - 1]!) >= need) return true; - drop(l.i, "has no room for its marks at an end"); + drop(l.i, dev ? "has no room for its marks at an end" : ""); return false; }); // The rows a far line's corridor needs (1.1): a row gap that carries one is space-10 (space-8 otherwise); a margin corridor adds space-8. @@ -2858,7 +2886,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin if (geo.through.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.through)} would pass through a node`); if (geo.overlaps?.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.overlaps)} would lie on one another`); if (geo.outside.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: ${names(geo, geo.outside)} would leave the drawing`); - if (geo.unseated.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: no clean seat for ${geo.unseated.map((k) => (m.type === "sequence" ? `message ${k}` : `"${m.edges[k]?.label}"`)).join(", ")}`); + if (geo.unseated.length) dev && warn?.(`the drawn layout does not fit at ${Math.round(W)}px: no clean seat for ${geo.unseated.map((k) => (m.type === "sequence" ? `message ${k}` : `"${said(m.edges[k]?.label ?? "")}"`)).join(", ")}`); } let d = stopOf({ ...current, ...closed, layout: "stacked", heights: undefined, grow: record(), track: m.type === "schema" ? mins.table : undefined, bare: undefined, pad: undefined, rows: undefined }); d = heightsFor(d); @@ -2880,7 +2908,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin if (dev && !plan.third && plan.laneCount > 2) warn?.(`the stacked drawing uses ${plan.laneCount} end lanes (four at most)`); const failed = geo.unseated.length > 0 || geo.through.length > 0 || geo.outside.length > 0 || plan.third; if (failed) { - if (geo.unseated.length) dev && warn?.(`the stacked drawing has no clean seat for ${[...new Set(geo.unseated)].map((k) => `"${m.edges[k]?.label}"`).join(", ")}, so its lines are not drawn; the list holds every connection`); + if (geo.unseated.length) dev && warn?.(`the stacked drawing has no clean seat for ${[...new Set(geo.unseated)].map((k) => `"${said(m.edges[k]?.label ?? "")}"`).join(", ")}, so its lines are not drawn; the list holds every connection`); if (geo.through.length) dev && warn?.(`in the stacked drawing ${names(geo, geo.through)} would pass through a node, so its lines are not drawn`); if (geo.outside.length) dev && warn?.(`in the stacked drawing ${names(geo, geo.outside)} would leave the drawing, so its lines are not drawn`); if (dev && plan.third) warn?.("the stacked drawing would need a fifth end lane, so its lines are not drawn"); diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index d7f5b6bc..08ce2594 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -140,6 +140,10 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const placements = React.useMemo(() => (given.length ? given : loaded ?? []), [given, loaded]); const order = React.useMemo>(() => (spec.direction ? [spec.direction] : spec.type === "flowchart" ? ["down", "right"] : ["right", "down"]), [spec.direction, spec.type]); const [dirAt, setDirAt] = React.useState(0); + // The reasons last warned when no direction draws (DECISIONS 322, rule 5): a new width with the same reasons is not a new warning. + const autoWarned = React.useRef(null); + // The viewer's figure takes the placements this figure has (DECISIONS 306, 8.4: elk runs once a direction), loaded ones included (DECISIONS 322). + const viewerSpec = React.useMemo(() => (auto && !given.length && loaded ? { ...spec, placement: loaded } : spec), [auto, given, loaded, spec]); const placementFor = React.useCallback((k: number) => placements.find((p) => p.direction === order[k]), [placements, order]); const model = React.useMemo(() => buildModel(spec, { checks: process.env.NODE_ENV !== "production", rtl, placement: auto ? placementFor(dirAt) : undefined }), [spec, rtl, auto, placementFor, dirAt]); const animated = model.motion.animated; @@ -190,7 +194,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: if (dirRtl !== rtl) { setRtl(dirRtl); return; } // An automatic figure with no placement loads the layout module once it is measured at 640 or wider (never at a phone's width); until it answers, and // if it fails, the figure is stacked with every word present. elk runs once a direction: a resize or the faces arriving never run it again. - if (auto && !given.length && !loaded && fig.clientWidth >= 640) { + // The viewer's figure is laid out at its least drawn width whatever the window (9.3), so on a phone it loads the module the page's stacked figure did not. + if (auto && !given.length && !loaded && (viewer || fig.clientWidth >= 640)) { const input = { type: spec.type as "architecture" | "flowchart" | "schema", nodes: spec.nodes as Array<{ id: string; group?: string }>, tables: spec.tables, edges: spec.edges, groups: spec.groups }; loadLayout().then((mod) => Promise.all(order.map((d) => mod.placeDiagram(input, d)))).then((all) => setLoaded(all), (error: unknown) => { if (process.env.NODE_ENV !== "production") warnOnce(component, `the automatic layout could not load (${String(error)}), so the figure is stacked`); @@ -198,13 +203,29 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: } // The direction: the first, in order, whose drawn layout fits at this width (each placement measured as it would be drawn); none fits, the first, stacked. if (auto && placements.length > 1 && !viewer) { - let pick = 0; + let pick = 0, drew = false, fitsByWidth = false; + // What an author sees when no direction draws (DECISIONS 322, rule 5): one warning that gives each direction's reason, where at least one direction + // had the width it needs. A figure that is only too narrow for both says nothing, as an authored figure does. + const why: string[] = []; for (let k = 0; k < order.length; k++) { const place = placementFor(k); if (!place) continue; const trial = buildModel(spec, { rtl, placement: place }); - const t = measureFigure(fig, trial, P, base, {}, (d) => syncAttributes(fig, figureTree(trial, d, options))); - if (t.dyn.layout === "drawn") { pick = k; break; } + const said: string[] = []; + const t = measureFigure(fig, trial, P, base, {}, (d) => syncAttributes(fig, figureTree(trial, d, options)), process.env.NODE_ENV !== "production" ? (w) => said.push(w) : undefined); + if (t.dyn.layout === "drawn") { pick = k; drew = true; break; } + if (process.env.NODE_ENV !== "production") { + const reasons = said.filter((w) => w.startsWith("the drawn layout does not fit")).map((w) => w.replace(/^the drawn layout does not fit at \d+px: /, "")); + if (reasons.length) fitsByWidth = true; + why.push(`laid ${order[k]} ${reasons.length ? reasons.join("; ") : `it needs ${Math.ceil(t.least ?? 0)}px`}`); + } + } + if (process.env.NODE_ENV !== "production" && !drew && fitsByWidth) { + const reasons = why.join("; ").replace(/\d+px/g, ""); + if (autoWarned.current !== reasons) { + autoWarned.current = reasons; + console.warn(`Basalt ${component}: layout="auto" draws in neither direction at ${Math.round(fig.clientWidth)}px, so the figure is stacked: ${why.join("; ")}. Name a side on a line named here (fromSide, toSide), shorten a label named here, or write the figure authored: placeDiagram returns every cell to start from`); + } } if (pick !== dirAt) { setDirAt(pick); return; } } @@ -476,7 +497,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: {opening ? : null} {viewerOpen && viewerModule ? ( - + ) : null} ) : null; diff --git a/packages/react/src/diagram-layout.ts b/packages/react/src/diagram-layout.ts index 61467163..fca7dd7f 100644 --- a/packages/react/src/diagram-layout.ts +++ b/packages/react/src/diagram-layout.ts @@ -17,8 +17,11 @@ export interface DiagramPlacementInput { interface ElkNode { id: string; width?: number; height?: number; x?: number; y?: number; children?: ElkNode[]; layoutOptions?: Record; edges?: Array<{ id: string; sources: string[]; targets: string[] }> } // Every card one box of one size (only the layer and the order are read, so the result never depends on a measured pixel), and one fixed set of options: -// layered, randomSeed 1, model order for nodes and edges, cycle breaking by model order, Brandes and Köpf placement. Partitioning is never switched on. +// layered, randomSeed 1, model order for nodes and edges, cycle breaking by model order, node placement by network simplex. Partitioning is never switched on. +// The ruling on DECISIONS 306 and 313 (automatic layout): network simplex in place of Brandes and Köpf, because it reads a line's straightness priority, and a +// main line carries one (STRAIGHT): the main path comes out as one straight run in both directions. const W = 200, H = 80; +const STRAIGHT = "10"; const options = (direction: "right" | "down"): Record => ({ "elk.algorithm": "layered", "elk.direction": direction === "right" ? "RIGHT" : "DOWN", @@ -26,19 +29,46 @@ const options = (direction: "right" | "down"): Record => ({ "elk.hierarchyHandling": "INCLUDE_CHILDREN", "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES", "elk.layered.cycleBreaking.strategy": "MODEL_ORDER", - "elk.layered.nodePlacement.strategy": "BRANDES_KOEPF", + "elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX", "elk.layered.spacing.nodeNodeBetweenLayers": "64", "elk.spacing.nodeNode": "48", "elk.edgeRouting": "ORTHOGONAL", }); -/** The graph handed to elk: cards in the author's order, groups as hierarchy, lines in the author's order. */ -export function elkGraph(input: DiagramPlacementInput, direction: "right" | "down"): ElkNode { - const cards = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name), group: undefined as string | undefined })) : (input.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); - const edges = input.type === "schema" - ? (input.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0]! }))) - : (input.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to) })); - const groups = input.type === "architecture" ? input.groups ?? [] : []; +interface Card { id: string; group?: string; way?: boolean } +interface Line { from: string; to: string; main: boolean; k: number } + +/** The cards and the lines a figure is placed from, in the author's order. */ +function partsOf(input: DiagramPlacementInput): { cards: Card[]; lines: Line[]; groups: DiagramGroup[] } { + const cards: Card[] = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name) })) : (input.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); + const raw = input.type === "schema" + ? (input.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0]!, main: false }))) + : (input.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to), main: e.kind === "main" })); + const ids = new Set(cards.map((c) => c.id)); + const lines = raw.filter((e) => ids.has(e.from) && ids.has(e.to)).map((e, k) => ({ ...e, k })); + return { cards, lines, groups: input.type === "architecture" ? input.groups ?? [] : [] }; +} + +/** + * The main line goes straight on (the ruling, rule 2): a card with three or more leaving lines, exactly one of them main, hands elk its leaving lines with + * the main one in the middle (half the others, rounded down, before it), each of the others in the author's order. Every other line keeps its place. + */ +export function mainInTheMiddle(lines: T[]): T[] { + const bySource = new Map(); + lines.forEach((e, k) => { if (!bySource.has(e.from)) bySource.set(e.from, []); bySource.get(e.from)!.push(k); }); + const out = lines.slice(); + for (const slots of bySource.values()) { + const main = slots.filter((k) => lines[k]!.main); + if (slots.length < 3 || main.length !== 1) continue; + const rest = slots.filter((k) => k !== main[0]); + const order = [...rest.slice(0, Math.floor(rest.length / 2)), main[0]!, ...rest.slice(Math.floor(rest.length / 2))]; + slots.forEach((slot, j) => { out[slot] = lines[order[j]!]!; }); + } + return out; +} + +/** The graph handed to elk: cards in the author's order (a way's boxes before the card its line ends on), groups as hierarchy, lines as ordered above. */ +function graphOf(cards: Card[], lines: Line[], groups: DiagramGroup[], direction: "right" | "down"): ElkNode { const kids = new Map([["", []]]); for (const g of groups) kids.set(g.id, []); for (const c of cards) (kids.get(c.group ?? "") ?? kids.get("")!).push({ id: c.id, width: W, height: H }); @@ -47,8 +77,13 @@ export function elkGraph(input: DiagramPlacementInput, direction: "right" | "dow const box: ElkNode = { id: `group:${g.id}`, children: kids.get(g.id), layoutOptions: { "elk.padding": "[top=32,left=16,bottom=16,right=16]" } }; (g.parent && kids.has(g.parent) ? kids.get(g.parent)! : children).push(box); } - const ids = new Set(cards.map((c) => c.id)); - return { id: "root", layoutOptions: options(direction), children, edges: edges.filter((e) => ids.has(e.from) && ids.has(e.to)).map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to] })) }; + return { id: "root", layoutOptions: options(direction), children, edges: lines.map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to], ...(e.main ? { layoutOptions: { "elk.layered.priority.straightness": STRAIGHT } } : {}) })) }; +} + +/** The graph of the first run, as the first decision's tests read it. */ +export function elkGraph(input: DiagramPlacementInput, direction: "right" | "down"): ElkNode { + const { cards, lines, groups } = partsOf(input); + return graphOf(cards, mainInTheMiddle(lines), groups, direction); } /** Cards' boxes, absolute, from elk's result (a child's place is its parent's plus its own). */ @@ -73,18 +108,81 @@ function bands(rects: Map; let elkMade: { layout: (graph: ElkNode) => Promise } | undefined; - -/** Places a figure in one direction: each card's column and row. The same answer in Node and in a browser. */ -export async function placeDiagram(input: DiagramPlacementInput, direction: "right" | "down"): Promise { +async function cellsOf(graph: ElkNode): Promise { if (!elkMade) { const mod = (await import("./diagram-elk")) as unknown as { default: new () => { layout: (graph: ElkNode) => Promise } }; elkMade = new mod.default(); } - const laid = await elkMade.layout(elkGraph(input, direction)); - const rects = absolute(laid); + const rects = absolute(await elkMade.layout(graph)); const col = bands(rects, (r) => r.x, (r) => r.x + r.w), row = bands(rects, (r) => r.y, (r) => r.y + r.h); - const cells: Record = {}; + const cells: Cells = {}; for (const id of rects.keys()) cells[id] = { col: col.get(id)!, row: row.get(id)! }; - return { direction, cells }; + return cells; +} + +/** A placement that cannot be used (1.8, 8.5): two cards in one cell, or a card inside the box of a group it is not in. */ +function unusable(cards: Card[], groups: DiagramGroup[], cells: Cells): boolean { + const seen = new Set(); + for (const c of cards) { const at = cells[c.id]; if (!at) return true; const key = `${at.col},${at.row}`; if (seen.has(key)) return true; seen.add(key); } + const chain = (id?: string) => { const out: string[] = []; for (let g = id; g; g = groups.find((x) => x.id === g)?.parent) out.push(g); return out; }; + for (const g of groups) { + const mine = cards.filter((c) => chain(c.group).includes(g.id)); + if (!mine.length) continue; + const at = mine.map((c) => cells[c.id]!); + const box = { c1: Math.min(...at.map((a) => a.col)), c2: Math.max(...at.map((a) => a.col)), r1: Math.min(...at.map((a) => a.row)), r2: Math.max(...at.map((a) => a.row)) }; + if (cards.some((c) => !mine.includes(c) && cells[c.id]!.col >= box.c1 && cells[c.id]!.col <= box.c2 && cells[c.id]!.row >= box.r1 && cells[c.id]!.row <= box.r2)) return true; + } + return false; +} + +/** + * Places a figure in one direction: each card's column and row. The same answer in Node and in a browser. + * + * Two runs where a main line skips a layer (the ruling, rule 1). The first run gives every card its layer (its row laid down, its column laid right). A main + * line whose ends are two or more layers apart is then handed to elk as a chain through one box of a card's size in each layer it passes (its way), each box in + * a group by the rule below, and elk runs again. The way's boxes are read with the cards and then left out: their cells stay empty, so the main + * line has a way no card stands in. If the second run cannot be used or adds a layer, the first is. + */ +export async function placeDiagram(input: DiagramPlacementInput, direction: "right" | "down"): Promise { + const { cards, lines: authored, groups } = partsOf(input); + const lines = mainInTheMiddle(authored); + const first = await cellsOf(graphOf(cards, lines, groups, direction)); + const layer = (id: string) => (direction === "down" ? first[id]!.row : first[id]!.col); + const chain = (id?: string) => { const out: string[] = []; for (let g = id; g; g = groups.find((x) => x.id === g)?.parent) out.push(g); return out; }; + const groupOf = new Map(cards.map((c) => [c.id, c.group])); + const all = cards.slice(); + const chained: Line[] = []; + let ways = 0; + for (const e of lines) { + const a = layer(e.from), b = layer(e.to); + if (!e.main || Math.abs(b - a) < 2) { chained.push(e); continue; } + const inA = chain(groupOf.get(e.from)), inB = chain(groupOf.get(e.to)); + const both = inA.find((g) => inB.includes(g)); + const boxes: Card[] = []; + let prev = e.from; + for (let l = a + Math.sign(b - a); l !== b; l += Math.sign(b - a)) { + const id = `way:${e.k}:${l}`; + // The box's group: the innermost group that holds either end and has a card in this layer (the target's side first), so the box stands beside the + // cards the line passes; with none, the innermost group that holds both ends, or no group. + const here = new Set(cards.filter((c) => layer(c.id) === l).flatMap((c) => chain(c.group))); + const group = inB.find((g) => here.has(g)) ?? inA.find((g) => here.has(g)) ?? both; + boxes.push({ id, group, way: true }); + chained.push({ ...e, from: prev, to: id }); + prev = id; + } + chained.push({ ...e, from: prev }); + all.splice(all.findIndex((c) => c.id === e.to), 0, ...boxes); + ways++; + } + const span = (c: Cells) => ({ cols: Math.max(...Object.values(c).map((x) => x.col)), rows: Math.max(...Object.values(c).map((x) => x.row)) }); + if (!ways) return { direction, ...span(first), cells: first }; + const second = await cellsOf(graphOf(all, chained, groups, direction)); + const cells: Cells = {}; + for (const c of cards) cells[c.id] = second[c.id]!; + // The second run stands only if it can be used and has no more layers than the first: a way fills layers that exist and never adds one. + const layers = (c: Cells) => Math.max(...cards.map((x) => (direction === "down" ? c[x.id]!.row : c[x.id]!.col))); + // The tracks are counted over the cards and the ways together (`cols`, `rows`), so a track that holds only a way is still a track. + return unusable(cards, groups, cells) || layers(cells) > layers(first) ? { direction, ...span(first), cells: first } : { direction, ...span(second), cells }; } diff --git a/packages/react/test/diagram-layout.test.mjs b/packages/react/test/diagram-layout.test.mjs new file mode 100644 index 00000000..5fd91907 --- /dev/null +++ b/packages/react/test/diagram-layout.test.mjs @@ -0,0 +1,250 @@ +// Automatic layout after the decider's ruling (DECISIONS 322, on DECISIONS 306 and 313, section 1.8): a main line keeps a way, network simplex with a +// straightness priority on main lines, a decision's point that a line leaves takes no other line, a turn-back needs a gutter, and one warning when +// neither direction draws. The ruling's list of tests; the figures are its proof's (test/fixtures/diagram-layout.json, the CIMIP ones in +// cimip-diagrams-b.json). In Node and in Chromium against the built package. The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { after, before, describe, test } from "node:test"; +import { pathToFileURL } from "node:url"; + +import * as esbuild from "esbuild"; + +import { inspectSource } from "./diagram-geometry.mjs"; +import { fixturePage, launch, pkg } from "./support.mjs"; + +const B = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams-b.json"), "utf8")); +const L = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "diagram-layout.json"), "utf8")); +const FIG = { autoArchitecture: B.autoArchitecture, autoFlowchart: B.autoFlowchart, autoSchema: B.autoSchema, ...L.figures }; +const P = "basalt-diagram"; +const font = (file) => fs.readFileSync(path.join(pkg, "dist", "fonts", file)).toString("base64"); +const FONTS = `@font-face{font-family:"Geist";src:url(data:font/woff2;base64,${font("Geist-Variable.woff2")}) format("woff2");font-weight:100 900}@font-face{font-family:"Geist Mono";src:url(data:font/woff2;base64,${font("GeistMono-Variable.woff2")}) format("woff2");font-weight:100 900}`; +const PAGE = `${FONTS} body{background:var(--basalt-surface-page);margin:0;padding:0 16px} #root{width:var(--w,1104px)}`; + +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +const HOST = ` +import * as Layout from "./dist/diagram-layout.js"; +window.__place = Layout.placeDiagram; +const C = { architecture: B.ArchitectureDiagram, flowchart: B.FlowchartDiagram, schema: B.SchemaDiagram }; +function Host() { + const [list, setList] = React.useState([]); + window.__set = (next) => flushSync(() => setList(next)); + return
{list.map(({ key, spec, dir }) => { const { type, ...props } = spec; const X = C[type]; return
; })}
; +} +createRoot(document.getElementById("root")).render();`; + +const frames = (page, n = 3) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); +async function figurePage({ theme = "dark", width = 1440, height = 1000, dev = true } = {}) { + const { page, errors } = await fixturePage(browser, "", { theme, viewport: { width, height }, standards: true }); + const built = await esbuild.build({ + stdin: { contents: `import * as React from "react"; import { createRoot } from "react-dom/client"; import { flushSync } from "react-dom"; import * as B from "./dist/index.js"; ${HOST}`, resolveDir: pkg, loader: "tsx" }, + bundle: true, format: "iife", write: false, jsx: "automatic", platform: "browser", logLevel: "silent", define: { "process.env.NODE_ENV": dev ? '"development"' : '"production"' }, + }); + const warnings = []; + page.on("console", (m) => { if (m.type() === "warning" || m.type() === "error") warnings.push(m.text()); }); + await page.addScriptTag({ content: built.outputFiles[0].text }); + await page.addStyleTag({ content: PAGE }); + await page.evaluate(() => document.fonts.ready); + return { page, errors, warnings }; +} +/** Draws the figures and waits until each automatic one has its placement (the layout module loads at 640 or wider) and is laid out. */ +const draw = async (page, items) => { + await page.evaluate((items) => window.__set(items), items); + await page.waitForFunction((n) => document.querySelectorAll(".basalt-diagram[data-layout]").length >= n, items.length); + await page.waitForTimeout(400); + await frames(page, 4); +}; +const widthTo = async (page, w) => { await page.evaluate((w) => document.getElementById("root").style.setProperty("--w", `${w}px`), w); await frames(page, 4); }; +const inspect = (page, key) => page.evaluate(`${inspectSource()}("${P}", "#fig-${key}")`); +const strip = (p) => ({ cols: p.cols, rows: p.rows, cells: p.cells }); + +describe("placeDiagram", () => { + test("the cells, cols and rows of the ruling's proof, in both directions, on five fresh runs in Node", async () => { + for (let run = 0; run < 5; run++) { + // A fresh module each run: a query string makes Node load it again, with its own elk. + const { placeDiagram } = await import(`${pathToFileURL(path.join(pkg, "dist", "diagram-layout.js")).href}?run=${run}`); + for (const key of ["autoArchitecture", "nestedArchitecture", "autoFlowchart", "autoSchema"]) for (const d of ["down", "right"]) { + const got = await placeDiagram(FIG[key], d); + assert.equal(got.direction, d); + assert.deepEqual(strip(got), L.cells[key][d], `${key} laid ${d}, run ${run + 1}`); + } + } + }); + + test("the graph handed to elk: network simplex, straightness 10 on main lines only, no partitioning; at most two layouts a direction", async () => { + const layout = await import(pathToFileURL(path.join(pkg, "dist", "diagram-layout.js")).href); + const g = layout.elkGraph(FIG.autoArchitecture, "down"); + assert.equal(g.layoutOptions["elk.layered.nodePlacement.strategy"], "NETWORK_SIMPLEX"); + assert.ok(!JSON.stringify(g).includes("partitioning"), "no elk.partitioning option anywhere"); + const main = new Set(FIG.autoArchitecture.edges.map((e, k) => (e.kind === "main" ? `${e.from}>${e.to}` : null)).filter(Boolean)); + for (const e of g.edges) { + const isMain = main.has(`${e.sources[0]}>${e.targets[0]}`); + assert.equal(e.layoutOptions?.["elk.layered.priority.straightness"], isMain ? "10" : undefined, `${e.sources[0]} to ${e.targets[0]}`); + } + // The main line in the middle: a card with three or more leaving lines, one of them main. + const order = layout.mainInTheMiddle([{ from: "a", main: false, n: 1 }, { from: "a", main: false, n: 2 }, { from: "a", main: true, n: 3 }, { from: "b", main: false, n: 4 }]); + assert.deepEqual(order.map((e) => e.n), [1, 3, 2, 4]); + // Count elk's layouts: the class diagram-layout imports is this module's default. + const ELK = (await import(pathToFileURL(path.join(pkg, "dist", "diagram-elk.js")).href)).default; + const real = ELK.prototype.layout; + let calls = 0; + ELK.prototype.layout = function (...args) { calls++; return real.apply(this, args); }; + try { + for (const key of Object.keys(FIG)) for (const d of ["down", "right"]) { + calls = 0; + await layout.placeDiagram(FIG[key], d); + assert.ok(calls >= 1 && calls <= 2, `${key} laid ${d}: ${calls} layouts`); + } + } finally { ELK.prototype.layout = real; } + }); + + test("a way-only track is kept: the two-main-lines figure laid down is 2 columns with every card in the first", async () => { + const { placeDiagram } = await import(pathToFileURL(path.join(pkg, "dist", "diagram-layout.js")).href); + const got = await placeDiagram(FIG.twoMains, "down"); + assert.equal(got.cols, 2); + assert.ok(Object.values(got.cells).every((c) => c.col === 1), JSON.stringify(got.cells)); + // The engine's tracks are the placement's, not the cards' own. + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + assert.equal(core.buildModel(FIG.twoMains, { placement: got }).cols, 2); + }); + + test("in the browser, placeDiagram returns Node's cells", async () => { + const { page } = await figurePage(); + for (const key of ["autoArchitecture", "nestedArchitecture", "autoFlowchart", "autoSchema"]) for (const d of ["down", "right"]) { + const got = await page.evaluate(({ spec, d }) => window.__place(spec, d), { spec: FIG[key], d }); + assert.deepEqual(strip(got), L.cells[key][d], `${key} laid ${d} in the browser`); + } + await page.close(); + }); +}); + +describe("the CIMIP figures draw", () => { + for (const theme of ["dark", "light"]) test(`${theme}: at 1104 the architecture is drawn laid down in 4 columns and the flowchart in 3, every line and label, no problem; named right, each stacks`, async () => { + const { page, errors } = await figurePage({ theme }); + await draw(page, [{ key: "arch", spec: FIG.autoArchitecture }, { key: "flow", spec: FIG.autoFlowchart }]); + for (const [key, cols, spec] of [["arch", "4", FIG.autoArchitecture], ["flow", "3", FIG.autoFlowchart]]) { + const g = await inspect(page, key); + assert.equal(g.layout, "drawn", key); + assert.equal(await page.locator(`#fig-${key}`).getAttribute("data-cols"), cols, `${key}: columns`); + assert.equal(g.lines.length, spec.edges.length, `${key}: every line`); + assert.equal(g.labels.length, spec.edges.filter((e) => e.label).length, `${key}: every label`); + assert.deepEqual(g.problems, [], `${key}: ${JSON.stringify(g.problems)}`); + } + await draw(page, [{ key: "arch", spec: { ...FIG.autoArchitecture, direction: "right" } }, { key: "flow", spec: { ...FIG.autoFlowchart, direction: "right" } }]); + assert.equal(await page.locator("#fig-arch").getAttribute("data-layout"), "stacked"); + assert.equal(await page.locator("#fig-flow").getAttribute("data-layout"), "stacked"); + assert.deepEqual(errors, []); + await page.close(); + }); + + test("from 800 (the architecture) and 720 (the flowchart) to 1,440, in steps of 16, each is drawn at every width", async () => { + const { page } = await figurePage({ width: 1500, dev: false }); + await page.addStyleTag({ content: "#root{display:grid;gap:64px}" }); + await draw(page, [{ key: "arch", spec: FIG.autoArchitecture }, { key: "flow", spec: FIG.autoFlowchart }]); + const off = []; + for (let w = 720; w <= 1440; w += 16) { + await widthTo(page, w); + await page.waitForTimeout(60); + if (w >= 800 && (await page.locator("#fig-arch").getAttribute("data-layout")) !== "drawn") off.push(`architecture at ${w}`); + if ((await page.locator("#fig-flow").getAttribute("data-layout")) !== "drawn") off.push(`flowchart at ${w}`); + } + assert.deepEqual(off, []); + await page.close(); + }); +}); + +describe("the side choice", () => { + test("rule 3: two answers to one side draw, four ways out of one decision stack and warn; a named side counts toward its side's three", async () => { + const { page, warnings } = await figurePage(); + await draw(page, [{ key: "two", spec: L.fixed.twoToOneSide }, { key: "four", spec: L.fixed.fourWaysOut }]); + assert.equal(await page.locator("#fig-two").getAttribute("data-layout"), "drawn"); + assert.deepEqual((await inspect(page, "two")).problems, []); + assert.equal(await page.locator("#fig-four").getAttribute("data-layout"), "stacked"); + assert.ok(warnings.some((w) => /would lie on one another/.test(w)), JSON.stringify(warnings)); + await page.close(); + // A card with three lines named out of its right side: a line that chooses takes another side. + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const n = (id) => ({ id, name: id, kind: "part" }); + const spec = { type: "architecture", layout: "auto", title: "t", summary: "s", nodes: ["a", "b", "c", "d", "e"].map(n), + edges: [{ from: "a", to: "b", fromSide: "right" }, { from: "a", to: "c", fromSide: "right" }, { from: "a", to: "d", fromSide: "right" }, { from: "a", to: "e" }] }; + const placement = { direction: "down", cells: { a: { col: 1, row: 2 }, b: { col: 2, row: 1 }, c: { col: 2, row: 2 }, d: { col: 2, row: 3 }, e: { col: 2, row: 4 } } }; + const m = core.buildModel(spec, { placement }); + assert.notEqual(m.edges[3].fromSide, "right", "the right side already holds three named lines"); + assert.equal(m.edges[3].fromSide, "bottom"); + }); + + test("rule 4: the two-main-lines figure draws right to left at 1104, no turn-back on the drawing's edge", async () => { + const { page } = await figurePage(); + await draw(page, [{ key: "rtl", spec: FIG.twoMains, dir: "rtl" }]); + const g = await inspect(page, "rtl"); + assert.equal(g.layout, "drawn"); + assert.deepEqual(g.problems, []); + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const { placeDiagram } = await import(pathToFileURL(path.join(pkg, "dist", "diagram-layout.js")).href); + for (const d of ["down", "right"]) { + const placement = await placeDiagram(FIG.twoMains, d); + for (const rtl of [false, true]) { + const m = core.buildModel(FIG.twoMains, { placement, rtl }); + for (const e of m.edges) { + if (!e.fromSide || e.fromSide !== e.toSide) continue; + const a = m.byId.get(e.from); + const beyond = e.fromSide === "right" ? a.col < m.cols : e.fromSide === "left" ? a.col > 1 : e.fromSide === "bottom" ? a.row < m.rows : a.row > 1; + assert.ok(beyond, `${e.from} to ${e.to} turns back on the drawing's ${e.fromSide} edge (laid ${d}${rtl ? ", right to left" : ""})`); + } + } + } + await page.close(); + }); +}); + +describe("rule 5: the author is told why", () => { + test("the nested-group architecture with two-line labels warns once at 1104 with both directions' reasons, not again after a resize; at 390 nothing", async () => { + const { page, warnings } = await figurePage(); + await draw(page, [{ key: "nested", spec: FIG.nestedArchitecture }]); + assert.equal(await page.locator("#fig-nested").getAttribute("data-layout"), "stacked"); + const said = () => warnings.filter((w) => /draws in neither direction/.test(w)); + assert.equal(said().length, 1, JSON.stringify(warnings)); + assert.match(said()[0], /layout="auto" draws in neither direction at 1104px, so the figure is stacked: laid right it needs \d+px; laid down no clean seat for "SQL · NOTIFY one transaction"\. Name a side/); + assert.ok(!said()[0].includes("\n"), "a label's break is a space in the warning"); + await widthTo(page, 1096); + await page.waitForTimeout(200); + assert.equal(said().length, 1, "the same reasons at a new width are not a new warning"); + await page.close(); + const small = await figurePage({ width: 390 }); + await widthTo(small.page, 358); + await small.page.evaluate((spec) => window.__set([{ key: "nested", spec }]), FIG.nestedArchitecture); + await small.page.waitForTimeout(500); + assert.deepEqual(small.warnings.filter((w) => /draws in neither direction/.test(w)), []); + await small.page.close(); + }); +}); + +describe("the viewer", () => { + async function openViewer(page, key) { + const button = page.locator(`#fig-${key} .${P}-expand`); + await button.scrollIntoViewIfNeeded(); + await button.click(); + await page.waitForSelector(`dialog.${P}-viewer[open] .${P}[data-layout]`); + await page.evaluate(() => Promise.all(document.getAnimations().map((a) => a.finished.catch(() => {})))); + await page.waitForTimeout(500); + await frames(page, 4); + return page.evaluate((P) => { const f = document.querySelector(`dialog.${P}-viewer .${P}-layer .${P}`); return { layout: f.getAttribute("data-layout"), cols: f.getAttribute("data-cols") }; }, P); + } + test("with no placement prop, the viewer's figure is drawn where the page's is: laid right at 1440 by 900, laid down at 390 by 844", async () => { + const wide = await figurePage({ width: 1440, height: 900 }); + await draw(wide.page, [{ key: "arch", spec: FIG.autoArchitecture }]); + assert.equal(await wide.page.locator("#fig-arch").getAttribute("data-layout"), "drawn"); + assert.deepEqual(await openViewer(wide.page, "arch"), { layout: "drawn", cols: String(L.cells.autoArchitecture.right.cols) }); + await wide.page.close(); + // At 390 the page's figure is stacked and loads nothing; the viewer's figure is laid out at its least drawn width, and places itself. + const phone = await figurePage({ width: 390, height: 844 }); + await widthTo(phone.page, 358); + await phone.page.evaluate((spec) => window.__set([{ key: "arch", spec }]), FIG.autoArchitecture); + await phone.page.waitForSelector("#fig-arch[data-layout]"); + assert.deepEqual(await openViewer(phone.page, "arch"), { layout: "drawn", cols: String(L.cells.autoArchitecture.down.cols) }); + await phone.page.close(); + }); +}); diff --git a/packages/react/test/fixtures/diagram-layout.json b/packages/react/test/fixtures/diagram-layout.json new file mode 100644 index 00000000..2dd9db50 --- /dev/null +++ b/packages/react/test/fixtures/diagram-layout.json @@ -0,0 +1,1478 @@ +{ + "about": "DECISIONS 322 (the ruling on automatic layout): the proof figures (auto-ruling/proof-figures.json; the CIMIP ones are cimip-diagrams-b.json), the two flowcharts on given cells (fixed-figures.json) and the ruled cells (proof/cells-ruled.json).", + "figures": { + "nestedArchitecture": { + "type": "architecture", + "title": "How a request reaches the agent (nested groups, placed automatically)", + "source": "docs/architecture.md, \"The shape\"", + "summary": "Requests travel from the browser over HTTPS through the ALB to the cimip service. The service writes to Aurora PostgreSQL, puts sealed segments in S3, calls Bedrock for the scribe and has ECS start one agent sandbox per incident. It streams HTTP + SSE to the sandbox, which calls Bedrock for inference, sends its logs to CloudWatch and runs approved tools against production.", + "legend": { + "main": "Request path", + "plain": "Call", + "dashed": "Async or one-way", + "focal": "The service" + }, + "groups": [ + { + "id": "aws", + "label": "AWS · your account" + }, + { + "id": "data", + "label": "Data & logs", + "parent": "aws" + } + ], + "nodes": [ + { + "id": "browser", + "kind": "client", + "name": "Browser", + "detail": "Edge on iOS, Android" + }, + { + "id": "alb", + "kind": "load balancer", + "name": "ALB", + "detail": "OIDC sign-in · HTTP/2", + "detailMono": true, + "group": "aws" + }, + { + "id": "svc", + "kind": "ECS service", + "name": "cimip service", + "detail": "N tasks · stateless", + "detailMono": true, + "focal": true, + "group": "aws", + "href": "#fig-sequence" + }, + { + "id": "aurora", + "kind": "database", + "name": "Aurora PostgreSQL", + "detail": "metadata · live window", + "detailMono": true, + "group": "data", + "branch": true + }, + { + "id": "s3", + "kind": "object store", + "name": "S3", + "detail": "sealed segments · transcripts", + "detailMono": true, + "group": "data", + "branch": true + }, + { + "id": "ecs", + "kind": "control plane", + "name": "ECS", + "detail": "RunTask · StopTask", + "detailMono": true, + "group": "aws", + "branch": true + }, + { + "id": "bedrock", + "kind": "model", + "name": "Bedrock", + "detail": "the scribe · the agent", + "group": "aws", + "branch": true + }, + { + "id": "agent", + "kind": "ECS task · one per incident", + "name": "Agent sandbox", + "detail": "private IP · :8080", + "detailMono": true, + "group": "aws" + }, + { + "id": "cw", + "kind": "logs", + "name": "CloudWatch", + "detail": "the agent's logs, traces", + "group": "aws", + "branch": true + }, + { + "id": "sys", + "kind": "your systems", + "name": "Production", + "detail": "read-only tools", + "group": "aws" + } + ], + "edges": [ + { + "from": "browser", + "to": "alb", + "kind": "main", + "label": "HTTPS" + }, + { + "from": "alb", + "to": "svc", + "kind": "main" + }, + { + "from": "svc", + "to": "aurora", + "label": "SQL · NOTIFY\none transaction" + }, + { + "from": "svc", + "to": "s3", + "label": "PUT" + }, + { + "from": "svc", + "to": "ecs", + "label": "RunTask" + }, + { + "from": "svc", + "to": "bedrock", + "label": "scribe" + }, + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "HTTP + SSE\none stream a tab" + }, + { + "from": "ecs", + "to": "agent", + "kind": "dashed", + "label": "starts" + }, + { + "from": "agent", + "to": "bedrock", + "label": "inference" + }, + { + "from": "agent", + "to": "cw", + "kind": "dashed", + "label": "logs" + }, + { + "from": "agent", + "to": "sys", + "label": "tools · approved actions" + } + ], + "layout": "auto" + }, + "nestedOneLine": { + "type": "architecture", + "title": "How a request reaches the agent (nested groups, one-line labels, placed automatically)", + "source": "docs/architecture.md, \"The shape\"", + "summary": "Requests travel from the browser over HTTPS through the ALB to the cimip service. The service writes to Aurora PostgreSQL, puts sealed segments in S3, calls Bedrock for the scribe and has ECS start one agent sandbox per incident. It streams HTTP + SSE to the sandbox, which calls Bedrock for inference, sends its logs to CloudWatch and runs approved tools against production.", + "legend": { + "main": "Request path", + "plain": "Call", + "dashed": "Async or one-way", + "focal": "The service" + }, + "groups": [ + { + "id": "aws", + "label": "AWS · your account" + }, + { + "id": "data", + "label": "Data & logs", + "parent": "aws" + } + ], + "nodes": [ + { + "id": "browser", + "kind": "client", + "name": "Browser", + "detail": "Edge on iOS, Android" + }, + { + "id": "alb", + "kind": "load balancer", + "name": "ALB", + "detail": "OIDC sign-in · HTTP/2", + "detailMono": true, + "group": "aws" + }, + { + "id": "svc", + "kind": "ECS service", + "name": "cimip service", + "detail": "N tasks · stateless", + "detailMono": true, + "focal": true, + "group": "aws", + "href": "#fig-sequence" + }, + { + "id": "aurora", + "kind": "database", + "name": "Aurora PostgreSQL", + "detail": "metadata · live window", + "detailMono": true, + "group": "data", + "branch": true + }, + { + "id": "s3", + "kind": "object store", + "name": "S3", + "detail": "sealed segments · transcripts", + "detailMono": true, + "group": "data", + "branch": true + }, + { + "id": "ecs", + "kind": "control plane", + "name": "ECS", + "detail": "RunTask · StopTask", + "detailMono": true, + "group": "aws", + "branch": true + }, + { + "id": "bedrock", + "kind": "model", + "name": "Bedrock", + "detail": "the scribe · the agent", + "group": "aws", + "branch": true + }, + { + "id": "agent", + "kind": "ECS task · one per incident", + "name": "Agent sandbox", + "detail": "private IP · :8080", + "detailMono": true, + "group": "aws" + }, + { + "id": "cw", + "kind": "logs", + "name": "CloudWatch", + "detail": "the agent's logs, traces", + "group": "aws", + "branch": true + }, + { + "id": "sys", + "kind": "your systems", + "name": "Production", + "detail": "read-only tools", + "group": "aws" + } + ], + "edges": [ + { + "from": "browser", + "to": "alb", + "kind": "main", + "label": "HTTPS" + }, + { + "from": "alb", + "to": "svc", + "kind": "main" + }, + { + "from": "svc", + "to": "aurora", + "label": "SQL · NOTIFY" + }, + { + "from": "svc", + "to": "s3", + "label": "PUT" + }, + { + "from": "svc", + "to": "ecs", + "label": "RunTask" + }, + { + "from": "svc", + "to": "bedrock", + "label": "scribe" + }, + { + "from": "svc", + "to": "agent", + "kind": "main", + "label": "HTTP + SSE" + }, + { + "from": "ecs", + "to": "agent", + "kind": "dashed", + "label": "starts" + }, + { + "from": "agent", + "to": "bedrock", + "label": "inference" + }, + { + "from": "agent", + "to": "cw", + "kind": "dashed", + "label": "logs" + }, + { + "from": "agent", + "to": "sys", + "label": "tools · approved actions" + } + ], + "layout": "auto" + }, + "loopBack": { + "type": "flowchart", + "layout": "auto", + "title": "A retry loop", + "legend": { + "main": "Usual path" + }, + "summary": "A test figure.", + "nodes": [ + { + "id": "start", + "shape": "terminal", + "name": "Start" + }, + { + "id": "try", + "name": "Try the call" + }, + { + "id": "ok", + "shape": "decision", + "name": "Did it work?" + }, + { + "id": "wait", + "name": "Wait and count", + "branch": true + }, + { + "id": "done", + "shape": "terminal", + "name": "Done" + } + ], + "edges": [ + { + "from": "start", + "to": "try", + "kind": "main" + }, + { + "from": "try", + "to": "ok", + "kind": "main" + }, + { + "from": "ok", + "to": "wait", + "label": "no" + }, + { + "from": "wait", + "to": "try", + "label": "again" + }, + { + "from": "ok", + "to": "done", + "kind": "main", + "label": "yes" + } + ] + }, + "threePlain": { + "type": "flowchart", + "layout": "auto", + "title": "Three ways out, none usual", + "legend": { + "main": "Usual path" + }, + "summary": "A test figure.", + "nodes": [ + { + "id": "in", + "shape": "terminal", + "name": "A request" + }, + { + "id": "kind", + "shape": "decision", + "name": "What kind?" + }, + { + "id": "a", + "name": "Read", + "branch": true + }, + { + "id": "b", + "name": "Write", + "branch": true + }, + { + "id": "c", + "name": "Delete", + "branch": true + }, + { + "id": "log", + "shape": "terminal", + "name": "Logged" + } + ], + "edges": [ + { + "from": "in", + "to": "kind", + "kind": "main" + }, + { + "from": "kind", + "to": "a", + "label": "read" + }, + { + "from": "kind", + "to": "b", + "label": "write" + }, + { + "from": "kind", + "to": "c", + "label": "delete" + }, + { + "from": "a", + "to": "log" + }, + { + "from": "b", + "to": "log" + }, + { + "from": "c", + "to": "log" + } + ] + }, + "longWay": { + "type": "flowchart", + "layout": "auto", + "title": "A main line past two steps", + "legend": { + "main": "Usual path" + }, + "summary": "A test figure.", + "nodes": [ + { + "id": "s", + "shape": "terminal", + "name": "Start" + }, + { + "id": "gate", + "shape": "decision", + "name": "Checked before?" + }, + { + "id": "p1", + "name": "Look it up", + "branch": true + }, + { + "id": "p2", + "name": "Score it", + "branch": true + }, + { + "id": "end", + "shape": "terminal", + "name": "Answer" + } + ], + "edges": [ + { + "from": "s", + "to": "gate", + "kind": "main" + }, + { + "from": "gate", + "to": "p1", + "label": "no" + }, + { + "from": "p1", + "to": "p2" + }, + { + "from": "p2", + "to": "end" + }, + { + "from": "gate", + "to": "end", + "kind": "main", + "label": "yes" + } + ] + }, + "twoMains": { + "type": "architecture", + "layout": "auto", + "title": "Two request paths", + "legend": { + "main": "Request path", + "dashed": "Async" + }, + "summary": "A test figure.", + "groups": [ + { + "id": "edge", + "label": "Edge" + }, + { + "id": "core", + "label": "Core" + } + ], + "nodes": [ + { + "id": "user", + "kind": "client", + "name": "User" + }, + { + "id": "cdn", + "kind": "cache", + "name": "CDN", + "group": "edge" + }, + { + "id": "gw", + "kind": "gateway", + "name": "Gateway", + "group": "edge" + }, + { + "id": "api", + "kind": "service", + "name": "API", + "group": "core" + }, + { + "id": "jobs", + "kind": "queue", + "name": "Jobs", + "group": "core" + }, + { + "id": "db", + "kind": "database", + "name": "Store", + "group": "core" + } + ], + "edges": [ + { + "from": "user", + "to": "cdn", + "kind": "main", + "label": "GET" + }, + { + "from": "user", + "to": "gw", + "kind": "main", + "label": "POST" + }, + { + "from": "cdn", + "to": "gw", + "label": "miss" + }, + { + "from": "gw", + "to": "api", + "kind": "main" + }, + { + "from": "api", + "to": "jobs", + "kind": "dashed", + "label": "enqueue" + }, + { + "from": "api", + "to": "db", + "label": "SQL" + }, + { + "from": "jobs", + "to": "db", + "label": "SQL" + } + ] + } + }, + "fixed": { + "twoToOneSide": { + "type": "flowchart", + "layout": "auto", + "direction": "down", + "title": "Two ways out, both to the end side", + "legend": { + "main": "Usual path" + }, + "summary": "A test figure.", + "nodes": [ + { + "id": "d", + "shape": "decision", + "name": "Which?" + }, + { + "id": "a", + "name": "First" + }, + { + "id": "b", + "name": "Second" + } + ], + "edges": [ + { + "from": "d", + "to": "a", + "label": "one" + }, + { + "from": "d", + "to": "b", + "label": "two" + } + ], + "placement": { + "direction": "down", + "cells": { + "d": { + "col": 1, + "row": 1 + }, + "a": { + "col": 2, + "row": 2 + }, + "b": { + "col": 3, + "row": 2 + } + } + } + }, + "fourWaysOut": { + "type": "flowchart", + "layout": "auto", + "direction": "down", + "title": "Four ways out of one decision", + "legend": { + "main": "Usual path" + }, + "summary": "A test figure.", + "nodes": [ + { + "id": "in", + "shape": "terminal", + "name": "In" + }, + { + "id": "d", + "shape": "decision", + "name": "Which?" + }, + { + "id": "a", + "name": "First" + }, + { + "id": "b", + "name": "Second" + }, + { + "id": "c", + "name": "Third" + }, + { + "id": "e", + "name": "Fourth" + } + ], + "edges": [ + { + "from": "in", + "to": "d", + "kind": "main" + }, + { + "from": "d", + "to": "a", + "label": "one" + }, + { + "from": "d", + "to": "b", + "label": "two" + }, + { + "from": "d", + "to": "c", + "label": "three" + }, + { + "from": "d", + "to": "e", + "label": "four" + } + ], + "placement": { + "direction": "down", + "cells": { + "in": { + "col": 2, + "row": 1 + }, + "d": { + "col": 2, + "row": 2 + }, + "a": { + "col": 1, + "row": 3 + }, + "b": { + "col": 2, + "row": 3 + }, + "c": { + "col": 3, + "row": 3 + }, + "e": { + "col": 4, + "row": 3 + } + } + } + } + }, + "cells": { + "autoArchitecture": { + "down": { + "cols": 4, + "rows": 6, + "cells": { + "browser": { + "col": 3, + "row": 1 + }, + "alb": { + "col": 3, + "row": 2 + }, + "svc": { + "col": 3, + "row": 3 + }, + "aurora": { + "col": 4, + "row": 4 + }, + "s3": { + "col": 1, + "row": 4 + }, + "ecs": { + "col": 2, + "row": 4 + }, + "bedrock": { + "col": 3, + "row": 6 + }, + "agent": { + "col": 2, + "row": 5 + }, + "cw": { + "col": 2, + "row": 6 + }, + "sys": { + "col": 1, + "row": 6 + } + } + }, + "right": { + "cols": 6, + "rows": 4, + "cells": { + "browser": { + "col": 1, + "row": 3 + }, + "alb": { + "col": 2, + "row": 3 + }, + "svc": { + "col": 3, + "row": 3 + }, + "aurora": { + "col": 4, + "row": 4 + }, + "s3": { + "col": 4, + "row": 1 + }, + "ecs": { + "col": 4, + "row": 2 + }, + "bedrock": { + "col": 6, + "row": 3 + }, + "agent": { + "col": 5, + "row": 2 + }, + "cw": { + "col": 6, + "row": 2 + }, + "sys": { + "col": 6, + "row": 1 + } + } + } + }, + "autoFlowchart": { + "down": { + "cols": 3, + "rows": 7, + "cells": { + "req": { + "col": 2, + "row": 1 + }, + "risk": { + "col": 2, + "row": 2 + }, + "who": { + "col": 2, + "row": 3 + }, + "obs": { + "col": 1, + "row": 4 + }, + "med": { + "col": 3, + "row": 4 + }, + "wait": { + "col": 3, + "row": 5 + }, + "may": { + "col": 2, + "row": 5 + }, + "first": { + "col": 2, + "row": 6 + }, + "told": { + "col": 1, + "row": 7 + }, + "rec": { + "col": 2, + "row": 7 + } + } + }, + "right": { + "cols": 7, + "rows": 3, + "cells": { + "req": { + "col": 1, + "row": 2 + }, + "risk": { + "col": 2, + "row": 2 + }, + "who": { + "col": 3, + "row": 2 + }, + "obs": { + "col": 4, + "row": 1 + }, + "med": { + "col": 4, + "row": 3 + }, + "wait": { + "col": 5, + "row": 3 + }, + "may": { + "col": 5, + "row": 2 + }, + "first": { + "col": 6, + "row": 2 + }, + "told": { + "col": 7, + "row": 1 + }, + "rec": { + "col": 7, + "row": 2 + } + } + } + }, + "autoSchema": { + "down": { + "cols": 3, + "rows": 5, + "cells": { + "memberships": { + "col": 1, + "row": 1 + }, + "room_events": { + "col": 2, + "row": 1 + }, + "log_segments": { + "col": 3, + "row": 1 + }, + "incidents": { + "col": 2, + "row": 2 + }, + "users": { + "col": 1, + "row": 3 + }, + "sandboxes": { + "col": 2, + "row": 3 + }, + "agent_runs": { + "col": 2, + "row": 4 + }, + "approvals": { + "col": 2, + "row": 5 + } + } + }, + "right": { + "cols": 5, + "rows": 3, + "cells": { + "memberships": { + "col": 1, + "row": 1 + }, + "room_events": { + "col": 1, + "row": 2 + }, + "log_segments": { + "col": 1, + "row": 3 + }, + "incidents": { + "col": 2, + "row": 2 + }, + "users": { + "col": 3, + "row": 1 + }, + "sandboxes": { + "col": 3, + "row": 2 + }, + "agent_runs": { + "col": 4, + "row": 2 + }, + "approvals": { + "col": 5, + "row": 2 + } + } + } + }, + "nestedArchitecture": { + "down": { + "cols": 4, + "rows": 6, + "cells": { + "browser": { + "col": 3, + "row": 1 + }, + "alb": { + "col": 3, + "row": 2 + }, + "svc": { + "col": 3, + "row": 3 + }, + "aurora": { + "col": 3, + "row": 4 + }, + "s3": { + "col": 4, + "row": 4 + }, + "ecs": { + "col": 1, + "row": 4 + }, + "bedrock": { + "col": 3, + "row": 6 + }, + "agent": { + "col": 2, + "row": 5 + }, + "cw": { + "col": 2, + "row": 6 + }, + "sys": { + "col": 1, + "row": 6 + } + } + }, + "right": { + "cols": 6, + "rows": 5, + "cells": { + "browser": { + "col": 1, + "row": 4 + }, + "alb": { + "col": 2, + "row": 4 + }, + "svc": { + "col": 3, + "row": 4 + }, + "aurora": { + "col": 4, + "row": 4 + }, + "s3": { + "col": 4, + "row": 5 + }, + "ecs": { + "col": 4, + "row": 1 + }, + "bedrock": { + "col": 6, + "row": 3 + }, + "agent": { + "col": 5, + "row": 2 + }, + "cw": { + "col": 6, + "row": 2 + }, + "sys": { + "col": 6, + "row": 1 + } + } + } + }, + "nestedOneLine": { + "down": { + "cols": 4, + "rows": 6, + "cells": { + "browser": { + "col": 3, + "row": 1 + }, + "alb": { + "col": 3, + "row": 2 + }, + "svc": { + "col": 3, + "row": 3 + }, + "aurora": { + "col": 3, + "row": 4 + }, + "s3": { + "col": 4, + "row": 4 + }, + "ecs": { + "col": 1, + "row": 4 + }, + "bedrock": { + "col": 3, + "row": 6 + }, + "agent": { + "col": 2, + "row": 5 + }, + "cw": { + "col": 2, + "row": 6 + }, + "sys": { + "col": 1, + "row": 6 + } + } + }, + "right": { + "cols": 6, + "rows": 5, + "cells": { + "browser": { + "col": 1, + "row": 4 + }, + "alb": { + "col": 2, + "row": 4 + }, + "svc": { + "col": 3, + "row": 4 + }, + "aurora": { + "col": 4, + "row": 4 + }, + "s3": { + "col": 4, + "row": 5 + }, + "ecs": { + "col": 4, + "row": 1 + }, + "bedrock": { + "col": 6, + "row": 3 + }, + "agent": { + "col": 5, + "row": 2 + }, + "cw": { + "col": 6, + "row": 2 + }, + "sys": { + "col": 6, + "row": 1 + } + } + } + }, + "loopBack": { + "down": { + "cols": 2, + "rows": 4, + "cells": { + "start": { + "col": 1, + "row": 1 + }, + "try": { + "col": 1, + "row": 2 + }, + "ok": { + "col": 1, + "row": 3 + }, + "wait": { + "col": 2, + "row": 4 + }, + "done": { + "col": 1, + "row": 4 + } + } + }, + "right": { + "cols": 4, + "rows": 2, + "cells": { + "start": { + "col": 1, + "row": 1 + }, + "try": { + "col": 2, + "row": 1 + }, + "ok": { + "col": 3, + "row": 1 + }, + "wait": { + "col": 4, + "row": 2 + }, + "done": { + "col": 4, + "row": 1 + } + } + } + }, + "threePlain": { + "down": { + "cols": 3, + "rows": 4, + "cells": { + "in": { + "col": 2, + "row": 1 + }, + "kind": { + "col": 2, + "row": 2 + }, + "a": { + "col": 1, + "row": 3 + }, + "b": { + "col": 2, + "row": 3 + }, + "c": { + "col": 3, + "row": 3 + }, + "log": { + "col": 2, + "row": 4 + } + } + }, + "right": { + "cols": 4, + "rows": 3, + "cells": { + "in": { + "col": 1, + "row": 2 + }, + "kind": { + "col": 2, + "row": 2 + }, + "a": { + "col": 3, + "row": 1 + }, + "b": { + "col": 3, + "row": 2 + }, + "c": { + "col": 3, + "row": 3 + }, + "log": { + "col": 4, + "row": 2 + } + } + } + }, + "longWay": { + "down": { + "cols": 2, + "rows": 5, + "cells": { + "s": { + "col": 2, + "row": 1 + }, + "gate": { + "col": 2, + "row": 2 + }, + "p1": { + "col": 1, + "row": 3 + }, + "p2": { + "col": 1, + "row": 4 + }, + "end": { + "col": 2, + "row": 5 + } + } + }, + "right": { + "cols": 5, + "rows": 2, + "cells": { + "s": { + "col": 1, + "row": 2 + }, + "gate": { + "col": 2, + "row": 2 + }, + "p1": { + "col": 3, + "row": 1 + }, + "p2": { + "col": 4, + "row": 1 + }, + "end": { + "col": 5, + "row": 2 + } + } + } + }, + "twoMains": { + "down": { + "cols": 2, + "rows": 6, + "cells": { + "user": { + "col": 1, + "row": 1 + }, + "cdn": { + "col": 1, + "row": 2 + }, + "gw": { + "col": 1, + "row": 3 + }, + "api": { + "col": 1, + "row": 4 + }, + "jobs": { + "col": 1, + "row": 5 + }, + "db": { + "col": 1, + "row": 6 + } + } + }, + "right": { + "cols": 6, + "rows": 2, + "cells": { + "user": { + "col": 1, + "row": 2 + }, + "cdn": { + "col": 2, + "row": 1 + }, + "gw": { + "col": 3, + "row": 2 + }, + "api": { + "col": 4, + "row": 2 + }, + "jobs": { + "col": 5, + "row": 1 + }, + "db": { + "col": 6, + "row": 2 + } + } + } + } + } +} \ No newline at end of file From e0cf7b88cb52ad9a6c621c2ff07d36e2f7ee536e Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:36:45 -0600 Subject: [PATCH 40/62] Sizes and caps after cardinality, far keys and the ruling (DECISIONS 318: the owner approved the raise) Recorded sizes: each still diagram 97,960 to 98,046 bytes, +9.1% on the last record (89.8 KB), for the cardinality marks, the corridors and lane counting, the key's forms and words, and the ruling's side choice and warning in the shared engine; the whole package up front 900,954 bytes (+0.9%), styles.css 409,760 (+0.5%). The skill's caps at their measured sizes: diagram 137,700 (measured 137,653, from 127,118) and diagram-motion 28,450 (measured 28,443: the marks' entrance). Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/manifest.json | 4 ++-- packages/react/test/export-sizes.json | 18 +++++++++--------- tools/html-skill/src/modules.json | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index ae602381..749007b4 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 127150, + "budget": 137700, "usage": 4300, "builds": [ "kbd" @@ -804,7 +804,7 @@ "loops", "toggle" ], - "budget": 27850, + "budget": 28450, "usage": 1300, "builds": [ "loops", diff --git a/packages/react/test/export-sizes.json b/packages/react/test/export-sizes.json index 4722b9ca..b213d04d 100644 --- a/packages/react/test/export-sizes.json +++ b/packages/react/test/export-sizes.json @@ -18,7 +18,7 @@ "AppHeader": 1285, "AppShell": 103887, "AppTile": 1112, - "ArchitectureDiagram": 89846, + "ArchitectureDiagram": 98046, "ArrowDownGlyph": 2868, "ArrowLeftGlyph": 2869, "ArrowRightGlyph": 2859, @@ -70,7 +70,7 @@ "CopyGlyph": 2884, "Countdown": 3016, "CoverageStrip": 1570, - "DataFlowDiagram": 89791, + "DataFlowDiagram": 97991, "DateAge": 2527, "DescriptionColumns": 216, "DescriptionItem": 593, @@ -105,7 +105,7 @@ "Fieldset": 6390, "FilterResult": 698, "FilterToolbar": 774, - "FlowchartDiagram": 89812, + "FlowchartDiagram": 98012, "Form": 8730, "FormGrid": 438, "FormGridItem": 628, @@ -224,7 +224,7 @@ "RunsGlyph": 3128, "STATUS_MESSAGE_MS": 26, "SandboxesGlyph": 2963, - "SchemaDiagram": 89760, + "SchemaDiagram": 97960, "SearchDialog": 88277, "SearchField": 18301, "SearchGlyph": 3181, @@ -243,7 +243,7 @@ "SelectableList": 821, "SelectionBar": 25913, "Separator": 4531, - "SequenceDiagram": 89788, + "SequenceDiagram": 97988, "SettingsGlyph": 3100, "ShareBar": 1411, "Sheet": 70793, @@ -412,11 +412,11 @@ "useWaitMark": 303 }, "package": { - "bytes": 892757, - "gzip": 297209 + "bytes": 900954, + "gzip": 300417 }, "styles": { - "bytes": 407734, - "gzip": 52946 + "bytes": 409760, + "gzip": 53141 } } diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index ae602381..749007b4 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 127150, + "budget": 137700, "usage": 4300, "builds": [ "kbd" @@ -804,7 +804,7 @@ "loops", "toggle" ], - "budget": 27850, + "budget": 28450, "usage": 1300, "builds": [ "loops", From 65fa32bd2637f432fb130339011db4d1606098c3 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:42:34 -0600 Subject: [PATCH 41/62] Round 66: the schema's cardinality and far keys, and the automatic architecture and flowchart drawn The schema section says what cardinality and far keys draw and the builder's readings where the decision is silent; the automatic section shows the architecture, flowchart and schema, each drawn laid down at 1104 after DECISIONS 322, and says what the ruling changed. The header no longer says cardinality, far keys and section 4's calls are not built. Co-Authored-By: Claude Opus 5.5 --- tools/review/round66.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx index a98fe460..58e3af85 100644 --- a/tools/review/round66.tsx +++ b/tools/review/round66.tsx @@ -2,7 +2,6 @@ // drafts and one check, decided by Fable, revised after the final positions. Part 9 (the viewer) is the owner's own addition and skipped three steps: no // draft, no check and no seat's position; every value in it is the decider's alone. Built by Opus from the decision; the implementation has not been // reviewed. The content is CIMIP's figures extended as each part needs (test/fixtures/cimip-diagrams-b.json), with automatic and text-art versions. -// Cardinality, far keys and section 4's calls 2 and 3 are not built. import * as React from "react"; @@ -137,10 +136,15 @@ export const ROUND_66: Round = { }, { id: "schema", - name: "Schema: a link table", - intro: "The incidents table is a link. Cardinality and far keys are not built yet.", - decisions: [...COMMON], - tryIt: ["Tab to the schema: the link table is the figure's roving stop."], + name: "Schema: cardinality, far keys and a link table", + intro: "Every foreign key states how many rows each end allows, so its dot and head give way to crow's-foot marks in the line's ink. approvals references incidents and users two columns away: the first runs along the margin above the first row, the second along the gap between rows 2 and 3, which grows to 40. The incidents table is a link.", + decisions: [ + ...COMMON, + "Cardinality (1.1): bars at 4 and 8, a foot from a point at 7.5, a ring centred at 10.5, every mark inside the 14px zone; the column gap is 60 where marks are drawn, and a marked gutter's lanes keep 18 from the tables (three at most).", + "Far keys (1.1): a corridor is a row gap clear of the tables between, or the margin above or below, the one nearest the middle of the two rows. A gap that carries one is space-10; a margin adds space-8. A line with no lane left is not drawn, and its row still writes the target.", + "Builder's readings where the decision is silent: a bar's 1px ink is the pixel that ends at its distance (so 3 to 4 for \"a bar at 4\"); two far lines to one key share a corridor lane; an interior corridor's two lanes take the order that crosses least.", + ], + tryIt: ["Hover approvals: its three lines, marks included, take the main ink and the rest dim. Narrow to 390: the stack draws no lines, and the key keeps the foreign key's arrow. Open View as list: decided_by reads \"zero or many approvals to zero or one users\"."], widths: W, scales: [2], height: 1200, @@ -150,17 +154,18 @@ export const ROUND_66: Round = { { id: "auto", name: "Automatic layout: elkjs places, Basalt draws", - intro: "The CIMIP schema and architecture with layout=\"auto\" and no col or row: elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one.", + intro: "The CIMIP architecture, flowchart and schema with layout=\"auto\" and no col or row: elkjs gives each card a column and a row, and Basalt sizes, routes and seats the figure as it does an authored one.", decisions: [ "elkjs (EPL-2.0 OR GPL-3.0-or-later, used under EPL-2.0) loads on demand here; an app that places at build time and passes placement ships none of it, and the HTML skill always places at build time.", - "The schema draws laid down (3 columns by 5 rows) through Basalt's router. The architecture places as the proof's 6 by 3 and 3 by 6, but stacks at 1104: the turn-back that carries \"HTTP + SSE\" finds no seat. The decision's proof routed on cells only; this is the first drawing of one, for the decider.", + "After the decider's ruling (DECISIONS 322): a main line that skips a layer keeps a way (a second elk run, its cells left empty), network simplex places the main path straight, a decision's point that a line leaves takes no other line, and a turn-back needs a gutter. At 1104 the architecture draws laid down (4 by 6, all 11 lines and 10 labels, one crossing, cut), the flowchart laid down (3 by 7) and the schema laid down (3 by 5), as the ruling's proof drew them.", + "When neither direction draws, a development build says why, once, with each direction's reason. The viewer takes the placements the page loaded and the direction with the larger Fit in its stage.", ], tryIt: ["Narrow the window: under 640 nothing is loaded and the figure is stacked."], widths: W, scales: [2], - height: 1800, + height: 3000, touch: true, - demo: ({ state }) => <>, + demo: ({ state }) => <>, }, { id: "text", From f47a0657485d0feb08b9cd6036b733bd0248163c Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:23:46 -0600 Subject: [PATCH 42/62] elkjs's copy carries its licence, and no declaration names elkjs or the graph's helpers (Neon B11, P2) The package keeps its copy of elkjs's file in dist/diagram-elk.js (the reason in build.mjs stands: bundled as CommonJS by an app, elkjs put the bundler's helpers in the chunk every component shares), so it now ships elkjs's licence beside it (dist/elkjs/LICENSE.md) and the notice says the file is copied, unchanged. diagram-elk.ts types elkjs's class as Basalt's own, so dist/diagram-elk.d.ts imports nothing of elkjs. The graph handed to elk (its options, the cards and lines, mainInTheMiddle and elkGraph) moves to diagram-layout-graph.ts, which is not an export of the package: diagram-layout.d.ts declares placeDiagram and DiagramPlacementInput and nothing else. placeDiagram answers an empty figure with one track (not -Infinity), and a cycle of groups no longer hangs it (a group's chain stops where it repeats). elkjs stays in the package's dependencies (for the build and for build-time placement); whether a package that ships a copy should also depend on it is the owner's call, and is reported, not changed. Co-Authored-By: Claude Opus 5.5 --- packages/react/THIRD-PARTY-NOTICES.md | 4 +- packages/react/build.mjs | 7 +- packages/react/src/diagram-elk.ts | 9 ++- packages/react/src/diagram-layout-graph.ts | 77 ++++++++++++++++++++ packages/react/src/diagram-layout.ts | 83 +++------------------- 5 files changed, 99 insertions(+), 81 deletions(-) create mode 100644 packages/react/src/diagram-layout-graph.ts diff --git a/packages/react/THIRD-PARTY-NOTICES.md b/packages/react/THIRD-PARTY-NOTICES.md index 48f5f5df..3271e2b4 100644 --- a/packages/react/THIRD-PARTY-NOTICES.md +++ b/packages/react/THIRD-PARTY-NOTICES.md @@ -3,7 +3,9 @@ ## elkjs `@srasyndicate/basalt/diagram-layout` (automatic diagram layout, DECISIONS 306, 1.8) imports [elkjs](https://github.com/kieler/elkjs) 0.12.1, -the Eclipse Layout Kernel compiled to JavaScript, unmodified. elkjs is a dependency of this package and is not copied into it. +the Eclipse Layout Kernel compiled to JavaScript, unmodified. Its file, `lib/elk.bundled.js`, is copied unchanged into this package as +`dist/diagram-elk.js` (inside a small module wrapper), and its licence is beside it in `dist/elkjs/LICENSE.md`. elkjs is also listed among the +package's dependencies, for the build and for placing at build time. - Licence: EPL-2.0 OR GPL-3.0-or-later. Basalt uses it under the Eclipse Public License 2.0 (https://www.eclipse.org/legal/epl-2.0/). - Source: https://github.com/kieler/elkjs (the Eclipse Layout Kernel's own source: https://github.com/eclipse/elk). diff --git a/packages/react/build.mjs b/packages/react/build.mjs index 684324a3..029e1950 100644 --- a/packages/react/build.mjs +++ b/packages/react/build.mjs @@ -108,10 +108,13 @@ ${elk} }).call(globalThis, elkModule, elkModule.exports, undefined, undefined); export default elkModule.exports; `); + // Its licence goes with the copy (Neon's B11 of the code review): the package redistributes the file, so it carries the text it is distributed under. + fs.mkdirSync(path.join(dist, "elkjs"), { recursive: true }); + fs.copyFileSync(path.join(packageDir("elkjs"), "LICENSE.md"), path.join(dist, "elkjs", "LICENSE.md")); } -// The diagram viewer is the fourth (DECISIONS 310, 9.13): "Expand" loads it at its first hover, focus or touch, and it brings Dialog, the sheet's parts and the -// buttons with it, inlined for the same reason as the motion's. It imports the figure and the engine only as types: the figure hands them over when it opens +// The diagram viewer is the fourth (DECISIONS 310, 9.13): "Expand" loads it at its first hover, focus or touch, and it brings the form dialog's box (on a native +// , no Base UI dialog), the sheet's parts and the buttons with it, inlined for the same reason as the motion's. It imports the figure and the engine only as types: the figure hands them over when it opens // the viewer (ViewerKit), so this chunk never holds a second copy of the engine. await esbuild.build({ bundle: true, diff --git a/packages/react/src/diagram-elk.ts b/packages/react/src/diagram-elk.ts index fbcc63a7..ae346ced 100644 --- a/packages/react/src/diagram-elk.ts +++ b/packages/react/src/diagram-elk.ts @@ -1,5 +1,8 @@ -// elkjs (EPL-2.0 OR GPL-3.0-or-later, used under EPL-2.0, unmodified), as an ES module of its own: build.mjs bundles elkjs's own file into -// dist/diagram-elk.js, so its CommonJS wrapper lives in this one file and never in an app's shared chunk. Only diagram-layout imports it, on demand. +// elkjs (EPL-2.0 OR GPL-3.0-or-later, used under EPL-2.0, unmodified), as an ES module of its own: build.mjs copies elkjs's own file into +// dist/diagram-elk.js, with its licence beside it (dist/elkjs/LICENSE.md), so its CommonJS wrapper lives in this one file and never in an app's shared +// chunk. Only diagram-layout imports it, on demand. Its type here is Basalt's own: no elkjs type is in any declaration (AGENTS.md). import ELK from "elkjs/lib/elk.bundled.js"; -export default ELK; +/** elkjs's layout, as diagram-layout calls it. */ +const Elk = ELK as unknown as new () => { layout: (graph: object) => Promise }; +export default Elk; diff --git a/packages/react/src/diagram-layout-graph.ts b/packages/react/src/diagram-layout-graph.ts new file mode 100644 index 00000000..0541430f --- /dev/null +++ b/packages/react/src/diagram-layout-graph.ts @@ -0,0 +1,77 @@ +// The graph automatic layout hands elk (DECISIONS 306, 1.8, and the ruling, DECISIONS 322): the cards, the lines and the groups, and the one fixed set of +// options. Internal to diagram-layout: not an export of the package, so its helpers and elk's graph shape are in no public declaration. Nothing runs at load. + +import type { DiagramGroup } from "./diagram-core"; +import type { DiagramPlacementInput } from "./diagram-layout"; + +export interface ElkNode { id: string; width?: number; height?: number; x?: number; y?: number; children?: ElkNode[]; layoutOptions?: Record; edges?: Array<{ id: string; sources: string[]; targets: string[] }> } + +// Every card one box of one size (only the layer and the order are read, so the result never depends on a measured pixel), and one fixed set of options: +// layered, randomSeed 1, model order for nodes and edges, cycle breaking by model order, node placement by network simplex. Partitioning is never switched on. +// The ruling on DECISIONS 306 and 313 (automatic layout): network simplex in place of Brandes and Köpf, because it reads a line's straightness priority, and a +// main line carries one (STRAIGHT): the main path comes out as one straight run in both directions. +export const W = 200, H = 80; +const STRAIGHT = "10"; +const options = (direction: "right" | "down"): Record => ({ + "elk.algorithm": "layered", + "elk.direction": direction === "right" ? "RIGHT" : "DOWN", + "elk.randomSeed": "1", + "elk.hierarchyHandling": "INCLUDE_CHILDREN", + "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES", + "elk.layered.cycleBreaking.strategy": "MODEL_ORDER", + "elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX", + "elk.layered.spacing.nodeNodeBetweenLayers": "64", + "elk.spacing.nodeNode": "48", + "elk.edgeRouting": "ORTHOGONAL", +}); + +export interface Card { id: string; group?: string; way?: boolean } +export interface Line { from: string; to: string; main: boolean; k: number } + +/** The cards and the lines a figure is placed from, in the author's order. */ +export function partsOf(input: DiagramPlacementInput): { cards: Card[]; lines: Line[]; groups: DiagramGroup[] } { + const cards: Card[] = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name) })) : (input.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); + const raw = input.type === "schema" + ? (input.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0]!, main: false }))) + : (input.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to), main: e.kind === "main" })); + const ids = new Set(cards.map((c) => c.id)); + const lines = raw.filter((e) => ids.has(e.from) && ids.has(e.to)).map((e, k) => ({ ...e, k })); + return { cards, lines, groups: input.type === "architecture" ? input.groups ?? [] : [] }; +} + +/** + * The main line goes straight on (the ruling, rule 2): a card with three or more leaving lines, exactly one of them main, hands elk its leaving lines with + * the main one in the middle (half the others, rounded down, before it), each of the others in the author's order. Every other line keeps its place. + */ +export function mainInTheMiddle(lines: T[]): T[] { + const bySource = new Map(); + lines.forEach((e, k) => { if (!bySource.has(e.from)) bySource.set(e.from, []); bySource.get(e.from)!.push(k); }); + const out = lines.slice(); + for (const slots of bySource.values()) { + const main = slots.filter((k) => lines[k]!.main); + if (slots.length < 3 || main.length !== 1) continue; + const rest = slots.filter((k) => k !== main[0]); + const order = [...rest.slice(0, Math.floor(rest.length / 2)), main[0]!, ...rest.slice(Math.floor(rest.length / 2))]; + slots.forEach((slot, j) => { out[slot] = lines[order[j]!]!; }); + } + return out; +} + +/** The graph handed to elk: cards in the author's order (a way's boxes before the card its line ends on), groups as hierarchy, lines as ordered above. */ +export function graphOf(cards: Card[], lines: Line[], groups: DiagramGroup[], direction: "right" | "down"): ElkNode { + const kids = new Map([["", []]]); + for (const g of groups) kids.set(g.id, []); + for (const c of cards) (kids.get(c.group ?? "") ?? kids.get("")!).push({ id: c.id, width: W, height: H }); + const children = [...kids.get("")!]; + for (const g of groups) { + const box: ElkNode = { id: `group:${g.id}`, children: kids.get(g.id), layoutOptions: { "elk.padding": "[top=32,left=16,bottom=16,right=16]" } }; + (g.parent && kids.has(g.parent) ? kids.get(g.parent)! : children).push(box); + } + return { id: "root", layoutOptions: options(direction), children, edges: lines.map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to], ...(e.main ? { layoutOptions: { "elk.layered.priority.straightness": STRAIGHT } } : {}) })) }; +} + +/** The graph of the first run, as the first decision's tests read it. */ +export function elkGraph(input: DiagramPlacementInput, direction: "right" | "down"): ElkNode { + const { cards, lines, groups } = partsOf(input); + return graphOf(cards, mainInTheMiddle(lines), groups, direction); +} diff --git a/packages/react/src/diagram-layout.ts b/packages/react/src/diagram-layout.ts index fca7dd7f..7a126c7b 100644 --- a/packages/react/src/diagram-layout.ts +++ b/packages/react/src/diagram-layout.ts @@ -4,6 +4,8 @@ // ships none of elkjs. A figure without `placement` loads this module on demand, at 640 or wider, and never at a phone's width. Nothing runs at load. import type { DiagramEdge, DiagramGroup, DiagramPlacement, SchemaTable } from "./diagram-core"; +import { graphOf, H, mainInTheMiddle, partsOf, W } from "./diagram-layout-graph"; +import type { Card, ElkNode, Line } from "./diagram-layout-graph"; /** What a figure is placed from: its type and the component's own props (cards, lines, groups). */ export interface DiagramPlacementInput { @@ -14,77 +16,6 @@ export interface DiagramPlacementInput { groups?: DiagramGroup[]; } -interface ElkNode { id: string; width?: number; height?: number; x?: number; y?: number; children?: ElkNode[]; layoutOptions?: Record; edges?: Array<{ id: string; sources: string[]; targets: string[] }> } - -// Every card one box of one size (only the layer and the order are read, so the result never depends on a measured pixel), and one fixed set of options: -// layered, randomSeed 1, model order for nodes and edges, cycle breaking by model order, node placement by network simplex. Partitioning is never switched on. -// The ruling on DECISIONS 306 and 313 (automatic layout): network simplex in place of Brandes and Köpf, because it reads a line's straightness priority, and a -// main line carries one (STRAIGHT): the main path comes out as one straight run in both directions. -const W = 200, H = 80; -const STRAIGHT = "10"; -const options = (direction: "right" | "down"): Record => ({ - "elk.algorithm": "layered", - "elk.direction": direction === "right" ? "RIGHT" : "DOWN", - "elk.randomSeed": "1", - "elk.hierarchyHandling": "INCLUDE_CHILDREN", - "elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES", - "elk.layered.cycleBreaking.strategy": "MODEL_ORDER", - "elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX", - "elk.layered.spacing.nodeNodeBetweenLayers": "64", - "elk.spacing.nodeNode": "48", - "elk.edgeRouting": "ORTHOGONAL", -}); - -interface Card { id: string; group?: string; way?: boolean } -interface Line { from: string; to: string; main: boolean; k: number } - -/** The cards and the lines a figure is placed from, in the author's order. */ -function partsOf(input: DiagramPlacementInput): { cards: Card[]; lines: Line[]; groups: DiagramGroup[] } { - const cards: Card[] = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name) })) : (input.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); - const raw = input.type === "schema" - ? (input.tables ?? []).flatMap((t) => (t.columns ?? []).filter((c) => c.references).map((c) => ({ from: String(t.name), to: String(c.references).split(".")[0]!, main: false }))) - : (input.edges ?? []).map((e) => ({ from: String(e.from), to: String(e.to), main: e.kind === "main" })); - const ids = new Set(cards.map((c) => c.id)); - const lines = raw.filter((e) => ids.has(e.from) && ids.has(e.to)).map((e, k) => ({ ...e, k })); - return { cards, lines, groups: input.type === "architecture" ? input.groups ?? [] : [] }; -} - -/** - * The main line goes straight on (the ruling, rule 2): a card with three or more leaving lines, exactly one of them main, hands elk its leaving lines with - * the main one in the middle (half the others, rounded down, before it), each of the others in the author's order. Every other line keeps its place. - */ -export function mainInTheMiddle(lines: T[]): T[] { - const bySource = new Map(); - lines.forEach((e, k) => { if (!bySource.has(e.from)) bySource.set(e.from, []); bySource.get(e.from)!.push(k); }); - const out = lines.slice(); - for (const slots of bySource.values()) { - const main = slots.filter((k) => lines[k]!.main); - if (slots.length < 3 || main.length !== 1) continue; - const rest = slots.filter((k) => k !== main[0]); - const order = [...rest.slice(0, Math.floor(rest.length / 2)), main[0]!, ...rest.slice(Math.floor(rest.length / 2))]; - slots.forEach((slot, j) => { out[slot] = lines[order[j]!]!; }); - } - return out; -} - -/** The graph handed to elk: cards in the author's order (a way's boxes before the card its line ends on), groups as hierarchy, lines as ordered above. */ -function graphOf(cards: Card[], lines: Line[], groups: DiagramGroup[], direction: "right" | "down"): ElkNode { - const kids = new Map([["", []]]); - for (const g of groups) kids.set(g.id, []); - for (const c of cards) (kids.get(c.group ?? "") ?? kids.get("")!).push({ id: c.id, width: W, height: H }); - const children = [...kids.get("")!]; - for (const g of groups) { - const box: ElkNode = { id: `group:${g.id}`, children: kids.get(g.id), layoutOptions: { "elk.padding": "[top=32,left=16,bottom=16,right=16]" } }; - (g.parent && kids.has(g.parent) ? kids.get(g.parent)! : children).push(box); - } - return { id: "root", layoutOptions: options(direction), children, edges: lines.map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to], ...(e.main ? { layoutOptions: { "elk.layered.priority.straightness": STRAIGHT } } : {}) })) }; -} - -/** The graph of the first run, as the first decision's tests read it. */ -export function elkGraph(input: DiagramPlacementInput, direction: "right" | "down"): ElkNode { - const { cards, lines, groups } = partsOf(input); - return graphOf(cards, mainInTheMiddle(lines), groups, direction); -} /** Cards' boxes, absolute, from elk's result (a child's place is its parent's plus its own). */ function absolute(node: ElkNode, ox = 0, oy = 0, out = new Map()) { @@ -126,7 +57,8 @@ async function cellsOf(graph: ElkNode): Promise { function unusable(cards: Card[], groups: DiagramGroup[], cells: Cells): boolean { const seen = new Set(); for (const c of cards) { const at = cells[c.id]; if (!at) return true; const key = `${at.col},${at.row}`; if (seen.has(key)) return true; seen.add(key); } - const chain = (id?: string) => { const out: string[] = []; for (let g = id; g; g = groups.find((x) => x.id === g)?.parent) out.push(g); return out; }; + // A group's chain, outermost last; a parent named twice (a cycle) ends it (Neon's P2 of the code review). + const chain = (id?: string) => { const out: string[] = []; for (let g = id; g && !out.includes(g); g = groups.find((x) => x.id === g)?.parent) out.push(g); return out; }; for (const g of groups) { const mine = cards.filter((c) => chain(c.group).includes(g.id)); if (!mine.length) continue; @@ -150,7 +82,8 @@ export async function placeDiagram(input: DiagramPlacementInput, direction: "rig const lines = mainInTheMiddle(authored); const first = await cellsOf(graphOf(cards, lines, groups, direction)); const layer = (id: string) => (direction === "down" ? first[id]!.row : first[id]!.col); - const chain = (id?: string) => { const out: string[] = []; for (let g = id; g; g = groups.find((x) => x.id === g)?.parent) out.push(g); return out; }; + // A group's chain, outermost last; a parent named twice (a cycle) ends it (Neon's P2 of the code review). + const chain = (id?: string) => { const out: string[] = []; for (let g = id; g && !out.includes(g); g = groups.find((x) => x.id === g)?.parent) out.push(g); return out; }; const groupOf = new Map(cards.map((c) => [c.id, c.group])); const all = cards.slice(); const chained: Line[] = []; @@ -176,13 +109,13 @@ export async function placeDiagram(input: DiagramPlacementInput, direction: "rig all.splice(all.findIndex((c) => c.id === e.to), 0, ...boxes); ways++; } - const span = (c: Cells) => ({ cols: Math.max(...Object.values(c).map((x) => x.col)), rows: Math.max(...Object.values(c).map((x) => x.row)) }); + const span = (c: Cells) => ({ cols: Math.max(1, ...Object.values(c).map((x) => x.col)), rows: Math.max(1, ...Object.values(c).map((x) => x.row)) }); if (!ways) return { direction, ...span(first), cells: first }; const second = await cellsOf(graphOf(all, chained, groups, direction)); const cells: Cells = {}; for (const c of cards) cells[c.id] = second[c.id]!; // The second run stands only if it can be used and has no more layers than the first: a way fills layers that exist and never adds one. - const layers = (c: Cells) => Math.max(...cards.map((x) => (direction === "down" ? c[x.id]!.row : c[x.id]!.col))); + const layers = (c: Cells) => Math.max(1, ...cards.map((x) => (direction === "down" ? c[x.id]!.row : c[x.id]!.col))); // The tracks are counted over the cards and the ways together (`cols`, `rows`), so a track that holds only a way is still a track. return unusable(cards, groups, cells) || layers(cells) > layers(first) ? { direction, ...span(first), cells: first } : { direction, ...span(second), cells }; } From 619ee9b1bf388dd16d0306a9cfa5e412f60e3bc2 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:23:59 -0600 Subject: [PATCH 43/62] The viewer and the text sequence after both reviews (Fable B1 to B4, B6, P4, P7; Neon B1, B2, B3, B6, P5, P6) The viewer: a control at a limit, or with the list open, is disabled as Basalt's are (disabled with focusableWhenDisabled: it stays mounted and focusable, loses its ink, and takes no hover, press or scale), and "Clear highlight" with no trace is the same (data-disabled). The dialog keeps the form dialog's rim (no border reset), and its inline and block end insets are reset so right to left it is placed by its top and left and stays inside the window. A linked card that stays in this tab closes the viewer as its click (or Enter, or tap) is handled, and the browser follows it; a new tab's link leaves the viewer open, in React and the skill. A text sequence in the viewer holds the art at its own width, never the transcript: the figure reports the width its widest line needs (textWidth) and the layer takes it; React reads the figure's size once the art is written, and the skill writes the art before the viewer reads it. The viewer's figure takes the placements the page loaded and, on a phone, loads its own. Its key hint is read from a placed model (it said two arrows for a figure with rows and columns). Fit for the direction choice is the viewer's own (whole per cents, 200% at most), so a tie keeps the type's direction. One placement is in flight a figure at a time. The text sequence: its build by ink is the motion module's, as a drawn figure's entrance: it waits until the art is in view, plays on the entrance's clock, settles as any entrance settles, and keeps the first visit's mark. "Play the run" shows on a text figure with run: true, and the run is the colour-only run with the quiet: each message in turn is current (its number primary), every later one quiet (label secondary, arrow tertiary). textArt widens a frame too narrow for its header or else row, pushing the columns after it (an inner frame on the same last column passes its width to the outer), and holds the neighbour of a last participant's self-call far enough off for its words and note. The transcript and the key's focal glyph are in the engine's commit. Rule 5's warning gathers its reasons only in a development build. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-figure.tsx | 59 +++++++++------ packages/react/src/diagram-motion-core.ts | 76 +++++++++++++++++++- packages/react/src/diagram-text.ts | 58 ++++++++------- packages/react/src/diagram-viewer.tsx | 25 +++++-- packages/react/src/diagram-zoom-core.ts | 19 ++++- tools/html-skill/src/modules/diagram-text.js | 17 ++--- tools/html-skill/src/modules/diagram-zoom.js | 12 +++- 7 files changed, 198 insertions(+), 68 deletions(-) diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 08ce2594..c20d41cb 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -116,6 +116,8 @@ export interface DiagramViewerMode { room: () => { w: number; h: number }; /** After every layout: what was measured, and the figure. */ onMeasured: (measured: Measured, fig: HTMLElement) => void; + /** A text sequence (9.3): the figure's width at which the art's widest line just fits; the viewer lays it out at that width. */ + textWidth?: (need: number) => void; } export interface DiagramFigureInternalProps extends DiagramFigureProps { @@ -137,6 +139,9 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const auto = spec.layout === "auto" && (spec.type === "architecture" || spec.type === "flowchart" || spec.type === "schema"); const given = React.useMemo(() => (spec.placement ? (Array.isArray(spec.placement) ? spec.placement : [spec.placement]) : []), [spec.placement]); const [loaded, setLoaded] = React.useState(null); + const placing = React.useRef(null); + // A figure that unmounts drops an answer still in flight. + React.useEffect(() => () => { placing.current = null; }, []); const placements = React.useMemo(() => (given.length ? given : loaded ?? []), [given, loaded]); const order = React.useMemo>(() => (spec.direction ? [spec.direction] : spec.type === "flowchart" ? ["down", "right"] : ["right", "down"]), [spec.direction, spec.type]); const [dirAt, setDirAt] = React.useState(0); @@ -195,9 +200,14 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // An automatic figure with no placement loads the layout module once it is measured at 640 or wider (never at a phone's width); until it answers, and // if it fails, the figure is stacked with every word present. elk runs once a direction: a resize or the faces arriving never run it again. // The viewer's figure is laid out at its least drawn width whatever the window (9.3), so on a phone it loads the module the page's stacked figure did not. - if (auto && !given.length && !loaded && (viewer || fig.clientWidth >= 640)) { + // One placement in flight a figure (P5 of the code review): a resize or the faces arriving while it runs do not start another, and an answer for a figure + // that has gone is dropped. + if (auto && !given.length && !loaded && !placing.current && (viewer || fig.clientWidth >= 640)) { const input = { type: spec.type as "architecture" | "flowchart" | "schema", nodes: spec.nodes as Array<{ id: string; group?: string }>, tables: spec.tables, edges: spec.edges, groups: spec.groups }; - loadLayout().then((mod) => Promise.all(order.map((d) => mod.placeDiagram(input, d)))).then((all) => setLoaded(all), (error: unknown) => { + const ask = spec; + placing.current = ask; + loadLayout().then((mod) => Promise.all(order.map((d) => mod.placeDiagram(input, d)))).then((all) => { if (placing.current === ask) { placing.current = null; setLoaded(all); } }, (error: unknown) => { + if (placing.current === ask) placing.current = null; if (process.env.NODE_ENV !== "production") warnOnce(component, `the automatic layout could not load (${String(error)}), so the figure is stacked`); }); } @@ -239,7 +249,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const trial = buildModel(spec, { rtl, placement: place }); const t = viewer.measure(fig, trial, P, base, {}, (d) => syncAttributes(fig, figureTree(trial, d, options))); if (t.dyn.layout !== "drawn") continue; - const fit = Math.min(room.w / fig.offsetWidth, room.h / fig.offsetHeight); + // Fit as the viewer takes it (whole per cents, 200% at most), so two directions that both fit at 200% tie and the type's own stays. + const fit = Math.min(2, Math.floor(Math.min(room.w / fig.offsetWidth, room.h / fig.offsetHeight) * 100 + 1e-6) / 100); if (fit > best + 1e-6) { best = fit; pick = k; } } if (pick !== dirAt) { setDirAt(pick); return; } @@ -260,7 +271,12 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const cw = probe.getBoundingClientRect().width / 40; probe.remove(); const cs = getComputedStyle(pre); - const room = pre.clientWidth - Number.parseFloat(cs.paddingLeft) - Number.parseFloat(cs.paddingRight); + let room = pre.clientWidth - Number.parseFloat(cs.paddingLeft) - Number.parseFloat(cs.paddingRight); + // In the viewer the art is held at its own width, never the transcript (9.3): the layer takes the width the widest line needs. + if (viewer?.textWidth) { + viewer.textWidth(made.width * cw + (fig.clientWidth - room) + 1); + room = pre.clientWidth - Number.parseFloat(cs.paddingLeft) - Number.parseFloat(cs.paddingRight); + } if (made.width * cw <= room + 0.5) { html = made.html; art = true; } } result.dyn = { ...result.dyn, art: art || undefined }; @@ -273,10 +289,17 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: setInk(result.ink); // A layout with no stops traces nothing: a pointer resting on a node as the figure narrows into one leaves no trace behind. if (!hasStops(model, result.dyn)) { setHoverTrace(null); setTouchTrace(null); } - // A figure hidden (the viewer's list is open) was not measured: the viewer keeps the drawing's size and place it had. - if (viewer && result.tokens) viewer.onMeasured(result, fig); + // A figure hidden (the viewer's list is open) was not measured: the viewer keeps the drawing's size and place it had. A text figure's art is in the DOM + // only once React has written it, so its size is read after that (below). + if (viewer && result.tokens && !model.text) viewer.onMeasured(result, fig); }, [model, base, options, component, viewer, rtl, auto, given, loaded, placements, order, placementFor, dirAt, spec, textModule, transcriptHtml]); + // The viewer's text figure (9.3): its size is read once React has written the art it measured, so the zoom fits the art and not the transcript. + React.useLayoutEffect(() => { + const fig = figRef.current; + if (viewer && model.text && fig && measured.current?.tokens) viewer.onMeasured(measured.current, fig); + }, [viewer, model, ink]); + // Measured before the first paint, then whenever the figure's width changes or the real faces arrive. React.useLayoutEffect(() => { measure(); @@ -300,16 +323,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: return () => { live = false; observer.disconnect(); cancelAnimationFrame(frame); if (marks) forced.removeEventListener("change", measure); }; }, [measure, model]); - // An animated text figure builds by ink once its art is first shown (1.2): every line present from the first frame, labels and arrows lifting in order. - const inked = React.useRef(false); - React.useLayoutEffect(() => { - const code = figRef.current?.querySelector(`.${P}-text-ink`); - if (!model.text || !animated || !textModule || !dyn.art || inked.current || !code) return; - inked.current = true; - const cs = getComputedStyle(code); - const ms = (name: string, fallback: number) => Number.parseFloat(cs.getPropertyValue(`--basalt-${name}`)) || fallback; - textModule.buildByInk(code, model.steps.filter((st) => "n" in st).length, { slower: ms("duration-slower", 300), step: ms("duration-diagram-step", 250), limit: ms("duration-diagram-limit", 5000) }); - }); + // An animated text figure builds by ink (1.2) as a drawn figure's entrance plays: the motion module plays it when it comes into view, settles it as it + // settles any entrance, and keeps the first visit's mark (below, its art counts as its lines). const trace = focusTrace ?? touchTrace ?? hoverTrace; React.useLayoutEffect(() => { const fig = figRef.current; @@ -318,7 +333,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // In the frame an animated figure's lines are first drawn it is marked pending, before any paint (DECISIONS 292, 1.5); the module, once loaded, // follows the lines each time they are drawn again. What it follows is the drawing itself, not the string: if React wrote the ink again for any reason // (a remount, the faces arriving with the same lines), the reveal and the loops are built again on the new elements. - const drawn = React.useRef<{ svg: Element | null; controller: MotionController | null } | null>(null); + const drawn = React.useRef<{ svg: Element | null; art: Element | null; controller: MotionController | null } | null>(null); // The motion code failed to load. A figure hidden when it failed (inside a closed disclosure, an unselected tab) had no lines and no entrance to settle // then: the lines it draws when it is shown are settled in the frame they are drawn, so they are never left pending. const motionFailed = React.useRef(false); @@ -326,9 +341,11 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const fig = figRef.current; if (!fig || !animated || !measured.current?.tokens) return; const svg = fig.querySelector(`.${P}-ink > .${P}-svg`); - if (drawn.current && drawn.current.svg === svg && drawn.current.controller === controller) return; - drawn.current = { svg, controller }; - entranceDrawn(fig, Boolean(measured.current.geo?.lines.length)); + // A text sequence's art is its lines (1.2): the build waits for it, as an entrance waits for drawn lines. + const art = model.text ? fig.querySelector(`.${P}-text[data-art]`) : null; + if (drawn.current && drawn.current.svg === svg && drawn.current.art === art && drawn.current.controller === controller) return; + drawn.current = { svg, art, controller }; + entranceDrawn(fig, Boolean(measured.current.geo?.lines.length) || Boolean(art)); if (motionFailed.current) settleEntrance(fig); controller?.redrawn(); }); @@ -503,7 +520,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: ) : null; // "Clear highlight" (1.5): last in the foot, mounted whenever the figure is on touch and can be traced, aria-disabled until a trace is up. const clear = !viewer && (onTouch || touched) && ink ? ( - ) : null; diff --git a/packages/react/src/diagram-motion-core.ts b/packages/react/src/diagram-motion-core.ts index f7650dbf..b2c88945 100644 --- a/packages/react/src/diagram-motion-core.ts +++ b/packages/react/src/diagram-motion-core.ts @@ -255,7 +255,9 @@ class Figure implements MotionController { if (!fig.hasAttribute("data-first-visit") || !fig.id) return; try { localStorage.setItem(visitKey(fig), "1"); } catch { /* it plays again */ } } - private hasLines() { return Boolean(this.host.geo()?.lines.length); } + /** A text sequence's art, where it is shown (DECISIONS 306, 1.2): its build by ink and its run are this module's, as the drawn sequence's are. */ + private textCode(): HTMLElement | null { return this.host.model().text ? this.host.fig.querySelector(`.${this.host.P}-text[data-art] .${this.host.P}-text-ink`) : null; } + private hasLines() { return Boolean(this.host.geo()?.lines.length) || Boolean(this.textCode()); } // A figure whose viewer is open holds its loops as a traced one does (DECISIONS 310, 9.7), and they start again when it closes. private traced() { return this.host.fig.hasAttribute("data-tracing") || this.host.fig.hasAttribute("data-viewing"); } @@ -349,6 +351,7 @@ class Figure implements MotionController { private lineEl(l: GLine) { return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${l.i}"]`); } private play() { + if (this.textCode()) { this.playText(); return; } const geo = this.host.geo(); if (!geo?.lines.length) return; this.host.fig.setAttribute("data-entrance", "running"); @@ -448,6 +451,38 @@ class Figure implements MotionController { this.sync(); } + /** + * A text sequence builds by ink (1.2), when it comes into view as a drawn figure's entrance does, on the same clock and with the same settling, first visit + * and limit: before its turn a message's label is secondary and its arrow tertiary, and at its turn both lift to their resting ink over duration-slower, + * messages duration-diagram-step apart inside duration-diagram-limit. No line is hidden and there is no caret. + */ + private playText() { + const code = this.textCode(); + if (!code) return; + const fig = this.host.fig, t = this.t; + fig.setAttribute("data-entrance", "running"); + this.played = true; + this.t0 = now(); + const lines = [...code.querySelectorAll("[data-n]")]; + const count = Math.max(0, ...lines.map((l) => Number(l.dataset.n))); + const gap = count > 1 ? Math.min(t.step, (t.limit - t.slower) / (count - 1)) : 0; + const cs = getComputedStyle(fig); + const secondary = cs.getPropertyValue("--basalt-text-secondary").trim(), tertiary = cs.getPropertyValue("--basalt-text-tertiary").trim(); + for (const line of lines) { + const n = Number(line.dataset.n); + line.querySelectorAll('[data-ink="label"], [data-ink="main"], [data-ink="plain"]').forEach((el) => { + const before = el.dataset.ink === "label" ? secondary : tertiary; + const a = el.animate([{ color: before }, { color: before, offset: 0.001 }, { color: getComputedStyle(el).color }], { duration: t.slower, delay: (n - 1) * gap, easing: "ease-out", fill: "backwards" }); + a.startTime = this.t0; + this.intro.add(a); + }); + } + this.introEnd?.cancel(); + this.introEnd = fig.animate([], { duration: Math.max(1, (count - 1) * gap + t.slower) }); + this.introEnd.startTime = this.t0; + this.introEnd.finished.then(() => this.finishIntro(), () => {}); + } + private clearIntro() { for (const a of [...this.intro, ...this.labels]) a.cancel(); this.intro.clear(); @@ -464,7 +499,9 @@ class Figure implements MotionController { const state = this.entrance(); if (state === "running") { const geo = this.host.geo(); - if (!geo?.lines.length) { + if (this.textCode()) { + // A text sequence's build carries on: its art is the same rows, written again. + } else if (!geo?.lines.length) { // Narrowed to a layout with no lines: at rest, with no control (1.5). this.clearIntro(); this.host.fig.setAttribute("data-entrance", "done"); @@ -829,6 +866,7 @@ class Figure implements MotionController { /** The run: a packet through every message in order, each arrow a leg; at each arrival the number lifts and the receiver's head steps (1.10). */ private playRun(from: number) { + if (this.textCode()) { this.playTextRun(from); return; } const geo = this.host.geo(); if (!geo?.lines.length) return; for (const a of this.runAnims) a.cancel(); @@ -860,11 +898,43 @@ class Figure implements MotionController { }; go().catch((e) => { if (!aborted(e)) throw e; }); } + + /** + * A text sequence's run (Neon's B6 of the code review): the colour-only run reduced motion already has, with the quiet. Each message in turn is current: + * its number lifts to primary, and every message after it is quiet (its label secondary, its arrow tertiary) until the run reaches it. + */ + private playTextRun(from: number) { + const code = this.textCode(); + if (!code) return; + for (const a of this.runAnims) a.cancel(); + this.runAnims.clear(); + const gen = ++this.runGen; + const live = () => gen === this.runGen; + const lines = [...code.querySelectorAll("[data-n]")]; + const count = Math.max(0, ...lines.map((l) => Number(l.dataset.n))); + const quiet = (current: number) => { for (const l of lines) l.toggleAttribute("data-ahead", current >= 0 && Number(l.dataset.n) > current); }; + this.runAt = from; + const go = async () => { + for (let k = from; k < count; k++) { + if (!live()) return; + this.runAt = k; + quiet(k + 1); + const these = lines.filter((l) => Number(l.dataset.n) === k + 1); + await this.wait(this.t.legMin + this.t.base, this.runAnims); + if (!live()) return; + for (const l of these) l.setAttribute("data-arrival", ""); + await this.wait(this.t.rest, this.runAnims); + for (const l of these) l.removeAttribute("data-arrival"); + } + if (live()) { this.runAt = -1; quiet(-1); this.publish(); } + }; + go().catch((e) => { if (!aborted(e)) throw e; }); + } } /** * What a development build throws on (DECISIONS 292, 4.1): an id in the pulse or the packet's path that no node has, two neighbouring ids no line joins in - * that direction, both a pulse and a packet, flow on a dashed line, and flow on a line of the mover's route. And what it warns on: a flow line with no + * that direction, both a pulse and a packet, and flow on a line of the mover's route (flow on a dashed line marches its own dashes, DECISIONS 306, 1.5). And what it warns on: a flow line with no * label. Here, and not in the still engine, because only an animated figure reads them. */ export function motionErrors(m: Model): { errors: string[]; warnings: string[] } { diff --git a/packages/react/src/diagram-text.ts b/packages/react/src/diagram-text.ts index 7bb17ec2..08e1b9be 100644 --- a/packages/react/src/diagram-text.ts +++ b/packages/react/src/diagram-text.ts @@ -28,11 +28,39 @@ export function textArt(m: Model): { html: string; width: number } { if (!("n" in s)) continue; const a = m.byId.get(s.from)?.i ?? 0, b = m.byId.get(s.to)?.i ?? 0; const words = Math.max(len(`${s.n} ${s.label}`), len(s.note ?? "")); - if (a === b) { if (a + 1 < nodes.length) need(a, a + 1, words + 8); } else need(a, b, words + 4); + // A self-call's words go to the end side, the start side on the last participant: the neighbour there is held far enough off for them. + if (a === b) { if (a + 1 < nodes.length) need(a, a + 1, words + 8); else if (a > 0) need(a - 1, a, words + 8); } else need(a, b, words + 4); } const last = nodes.length - 1; + // A frame's header and an else row hold their words inside the frame, with both corners: a frame too narrow for them pushes the columns after it out (an + // inner frame by its inset too), and one on the last column widens the art (Neon's B6 of the code review). + const frameExtra = new Map(); + { + let depth = 0; + const stack: Array<{ at: number; a: number; b: number; inset: number; need: number }> = []; + const edgeL = (a: number, inset: number) => x[a]! - Math.floor(boxW[a]! / 2) - 1 + inset; + const edgeR = (b: number, inset: number) => x[b]! + Math.ceil(boxW[b]! / 2) - inset; + steps.forEach((s, at) => { + if ("open" in s) { stack.push({ at, a: s.a - 1, b: s.b - 1, inset: depth * 2, need: len(`[${s.open}]`) + 1 + len(` ${s.label} `) + 2 }); depth++; return; } + if ("otherwise" in s) { const f = stack[stack.length - 1]; if (f) f.need = Math.max(f.need, len("[else]") + 1 + len(` ${s.otherwise} `) + 2); return; } + if ("close" in s) { + depth = Math.max(0, depth - 1); + const f = stack.pop(); + if (!f) return; + // What an inner frame on the same last column already took is this frame's too; only the rest pushes the columns out again. + const have = frameExtra.get(f.at) ?? 0; + const short = f.need - (edgeR(f.b, f.inset) - edgeL(f.a, f.inset)) - have; + if (short > 0) { + if (f.b < last) for (let k = f.b + 1; k < nodes.length; k++) x[k]! += short; + frameExtra.set(f.at, have + short); + } + const total = frameExtra.get(f.at) ?? 0; + if (total) for (const p of stack) if (p.b === f.b) frameExtra.set(p.at, Math.max(frameExtra.get(p.at) ?? 0, total)); + } + }); + } const selfWidth = Math.max(0, ...steps.map((s) => ("n" in s && s.from === s.to && (m.byId.get(s.from)?.i ?? 0) === last ? len(`${s.n} ${s.label}`) + 8 : 0))); - const W = (x[last] ?? 0) + Math.ceil((boxW[last] ?? 8) / 2) + selfWidth + 2; + const W = (x[last] ?? 0) + Math.ceil((boxW[last] ?? 8) / 2) + selfWidth + 2 + Math.max(0, ...frameExtra.values()); const rows: Row[] = []; const row = (): Row => { const r = { ch: Array(W).fill(" "), ink: Array(W).fill("") }; rows.push(r); return r; }; const put = (r: Row, from: number, text: string, ink: Ink) => { Array.from(text).forEach((c, k) => { const i = from + k; if (i >= 0 && i < W) { r.ch[i] = c; r.ink[i] = ink; } }); }; @@ -56,7 +84,7 @@ export function textArt(m: Model): { html: string; width: number } { const sides = (r: Row) => { for (const f of open) { put(r, f.l, "│", "frame"); put(r, f.r, "│", "frame"); } }; const spacer = () => { const r = row(); lifelines(r); sides(r); return r; }; spacer(); - for (const s of steps) { + for (const [at, s] of steps.entries()) { if ("band" in s) { const r = row(); const words = ` ${s.band} `; @@ -68,7 +96,7 @@ export function textArt(m: Model): { html: string; width: number } { if ("open" in s) { const a = s.a - 1, b = s.b - 1; const inset = open.length * 2; - const f = { l: Math.max(0, x[a]! - Math.floor(boxW[a]! / 2) - 1 + inset), r: Math.min(W - 1, x[b]! + Math.ceil(boxW[b]! / 2) + (b === last && steps.some((t) => "n" in t && t.from === t.to) ? selfWidth : 0) - inset) }; + const f = { l: Math.max(0, x[a]! - Math.floor(boxW[a]! / 2) - 1 + inset), r: Math.min(W - 1, x[b]! + Math.ceil(boxW[b]! / 2) + (b === last && steps.some((t) => "n" in t && t.from === t.to) ? selfWidth : 0) - inset + (frameExtra.get(at) ?? 0)) }; const r = row(); lifelines(r); sides(r); put(r, f.l, "┌" + "─".repeat(f.r - f.l - 1) + "┐", "frame"); @@ -142,25 +170,3 @@ export function textArt(m: Model): { html: string; width: number } { }).join("\n"); return { html, width: Math.max(...rows.map((r) => r.ch.join("").trimEnd().length)) }; } - -/** - * The build by ink (1.2), under motion="animated": before its turn a message's label is secondary and its arrow tertiary; at its turn both lift to their - * resting ink over duration-slower, messages duration-diagram-step apart inside duration-diagram-limit. No line is hidden and there is no caret. It never - * plays under reduced motion, in forced colours, under the hold or in print. Returns a function that settles it at once. - */ -export function buildByInk(code: HTMLElement, steps: number, t: { slower: number; step: number; limit: number }): () => void { - if (matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches || document.documentElement.getAttribute("data-loops") === "held") return () => {}; - const gap = steps > 1 ? Math.min(t.step, (t.limit - t.slower) / (steps - 1)) : 0; - const animations: Animation[] = []; - const cs = getComputedStyle(code); - const secondary = cs.getPropertyValue("--basalt-text-secondary").trim(), tertiary = cs.getPropertyValue("--basalt-text-tertiary").trim(); - code.querySelectorAll("[data-n]").forEach((line) => { - const n = Number(line.dataset.n); - line.querySelectorAll('[data-ink="label"], [data-ink="main"], [data-ink="plain"]').forEach((el) => { - const rest = getComputedStyle(el).color; - const before = el.dataset.ink === "label" ? secondary : tertiary; - animations.push(el.animate([{ color: before }, { color: before, offset: 0.001 }, { color: rest }], { duration: t.slower, delay: (n - 1) * gap, easing: "ease-out", fill: "backwards" })); - }); - }); - return () => { for (const a of animations) a.finish(); }; -} diff --git a/packages/react/src/diagram-viewer.tsx b/packages/react/src/diagram-viewer.tsx index 67fd7a55..cb2c247b 100644 --- a/packages/react/src/diagram-viewer.tsx +++ b/packages/react/src/diagram-viewer.tsx @@ -3,7 +3,7 @@ import * as React from "react"; import { Button, IconButton } from "./button"; import type { DiagramFigureInternalProps, DiagramViewerMode } from "./diagram-figure"; import type { buildModel, DiagramSpec, figureKey, figureList, hintEntries, Measured, measureFigure, Model, toHtml } from "./diagram-core"; -import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } from "./diagram-zoom-core"; +import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint, viewerTextWidth } from "./diagram-zoom-core"; import type { ViewerMemo, ZoomController, ZoomState } from "./diagram-zoom-core"; import { createPortal } from "react-dom"; @@ -57,7 +57,9 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o const { Figure: DiagramFigure, Kbd, buildModel, figureKey, figureList, hintEntries, toHtml, inLevel, measureFigure } = kit; // The viewer's figure is still (9.7): no entrance, flow, mover or run, so no motion code is loaded for it. const still = React.useMemo(() => ({ ...spec, motion: "still" }), [spec]); - const model = React.useMemo(() => buildModel(still), [still]); + // An automatic figure's foot (its key hint) is read from a placed model: unplaced, every card is in one cell and the hint would say two arrows where the + // drawing has rows and columns (the pixel review's check on the viewer's hint). + const model = React.useMemo(() => buildModel(still, { placement: Array.isArray(still.placement) ? still.placement[0] : still.placement }), [still]); const stageRef = React.useRef(null); const sizerRef = React.useRef(null); const layerRef = React.useRef(null); @@ -122,6 +124,7 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o }, onMeasured, measure: (fig, m, p, base, current, apply, warn) => measureViewerFigure(fig, m, p, base, current, apply, warn, { layer, avail, row: dims.row, contain: dims.contain, memo: memo.current, measureFigure }), + textWidth: (need) => viewerTextWidth({ layer, avail, row: dims.row, contain: dims.contain, memo: memo.current, measureFigure }, need), }; }, [avail, dims, onMeasured, measureFigure, settled]); @@ -174,13 +177,21 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o const first = all[0]!, last = all[all.length - 1]!, at = document.activeElement; if (e.shiftKey && (at === first || at === d)) { e.preventDefault(); last.focus(); } else if (!e.shiftKey && at === last) { e.preventDefault(); first.focus(); } }; + // A linked card is followed on a click, a tap or Enter; a link that stays in this tab closes the viewer first (9.7). The dialog closes as the click is + // handled, and the browser then follows the link as it would anywhere: a new tab's link leaves the viewer open. + const onLink = (e: MouseEvent) => { + const a = (e.target as Element | null)?.closest?.(`a.${P}-node[href]`) as HTMLAnchorElement | null; + if (!a || !d.contains(a) || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || (a.target && a.target !== "_self")) return; + close(); + }; const onEntered = (e: TransitionEvent) => { if (e.target === d && e.propertyName === "transform" && d.open && !closing.current) setSettled((n) => n + 1); }; d.addEventListener("transitionend", onEntered); d.addEventListener("close", onClose); d.addEventListener("pointerdown", onDown); d.addEventListener("click", onClick); + d.addEventListener("click", onLink); d.addEventListener("keydown", onKey); - return () => { clearTimeout(timer); d.removeEventListener("transitionend", onEntered); d.removeEventListener("close", onClose); d.removeEventListener("pointerdown", onDown); d.removeEventListener("click", onClick); d.removeEventListener("keydown", onKey); if (d.open) d.close(); }; + return () => { clearTimeout(timer); d.removeEventListener("transitionend", onEntered); d.removeEventListener("close", onClose); d.removeEventListener("pointerdown", onDown); d.removeEventListener("click", onClick); d.removeEventListener("click", onLink); d.removeEventListener("keydown", onKey); if (d.open) d.close(); }; }, [opener, close]); return createPortal( @@ -208,10 +219,12 @@ export function DiagramViewer({ kit, spec, component, source, summary, opener, o {key ?
: null}
- { if (!off && !zoom.atMin) z()?.zoomOut(); }} /> + {/* At a limit, or with the list open, a control is disabled as Basalt's are (B1 of the pixel review): it stays mounted and focusable, loses its + ink, and takes no hover, press or scale. */} + { if (!off && !zoom.atMin) z()?.zoomOut(); }} /> - { if (!off && !zoom.atMax) z()?.zoomIn(); }} /> - + { if (!off && !zoom.atMax) z()?.zoomIn(); }} /> +
diff --git a/packages/react/src/diagram-zoom-core.ts b/packages/react/src/diagram-zoom-core.ts index aa3c73f1..2c26e5c7 100644 --- a/packages/react/src/diagram-zoom-core.ts +++ b/packages/react/src/diagram-zoom-core.ts @@ -335,8 +335,14 @@ export function revealIn(stage: HTMLElement, el: Element, margin: number): void if (r.top < top) stage.scrollTop -= top - r.top; else if (r.bottom > bottom) stage.scrollTop += Math.min(r.bottom - bottom, r.top - top); } +/** A text sequence in the viewer (9.3): the layer is the art's own width, `need` being the figure's width at which the widest line just fits. */ +export function viewerTextWidth(v: ViewerLayout, need: number): void { + v.memo.art = Math.ceil(need); + v.layer.style.width = `${v.memo.art}px`; +} + /** What the viewer's figure remembers between layouts: the least width the engine was found to draw this data at (0: none). */ -export interface ViewerMemo { model?: unknown; least?: number } +export interface ViewerMemo { model?: unknown; least?: number; art?: number } export interface ViewerLayout { /** The layer the figure is laid out in: its width is the layout width; its transform (the zoom) is taken off while it is measured. */ layer: HTMLElement; @@ -356,7 +362,16 @@ export interface ViewerLayout { */ export function measureViewerFigure(fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn: ((s: string) => void) | undefined, v: ViewerLayout): Measured { const { layer, memo, measureFigure } = v; - if (memo.model !== m) { memo.model = m; memo.least = undefined; } + if (memo.model !== m) { memo.model = m; memo.least = undefined; memo.art = undefined; } + // A text sequence holds the art at its own width, never the transcript (9.3): the figure reports the art's width (textWidth) and the layer takes it. + if (m.text) { + layer.style.width = `${memo.art ?? Math.min(v.avail, v.row)}px`; + const zoomedText = layer.style.transform; + layer.style.transform = "none"; + const out = measureFigure(fig, m, P, base, current, apply, warn); + layer.style.transform = zoomedText; + return out; + } const sizeTo = (least: number) => { layer.style.width = `${Math.max(memo.least || least, Math.min(v.avail, v.row))}px`; }; // The layer has no width of its own until the first layout: it starts at the stage's, so the figure can be measured. if (!layer.style.width) layer.style.width = `${Math.min(v.avail, v.row)}px`; diff --git a/tools/html-skill/src/modules/diagram-text.js b/tools/html-skill/src/modules/diagram-text.js index 2b199168..30335a08 100644 --- a/tools/html-skill/src/modules/diagram-text.js +++ b/tools/html-skill/src/modules/diagram-text.js @@ -1,12 +1,12 @@ /* Basalt HTML script, diagram-text module (DECISIONS 306, 1.2): a sequence whose JSON says "variant": "text" is a code block of box-drawing characters where its widest line fits, and its transcript (written into the page by compose.mjs) where it does not. The art is React's own - (packages/react/src/diagram-text.ts), bundled here by build.mjs. Under "motion": "animated" it builds by ink once. The implementation hasn't been reviewed. + (packages/react/src/diagram-text.ts), bundled here by build.mjs. Under "motion": "animated" it builds by ink as it comes into view (the diagram-motion module). The implementation hasn't been reviewed. Source: tools/html-skill/src/modules/diagram-text.js (do not edit the copy in the skill folder). */ -import { buildByInk, textArt } from "../../../../packages/react/src/diagram-text.ts"; +import { textArt } from "../../../../packages/react/src/diagram-text.ts"; (function (B) { 'use strict'; - B._.diagramText = function (figure, model, spec) { + B._.diagramText = function (figure, model, spec, viewer) { var pre = figure.querySelector('.diagram-text'); var code = pre && pre.querySelector('.diagram-text-ink'); if (!code) return; @@ -19,14 +19,15 @@ import { buildByInk, textArt } from "../../../../packages/react/src/diagram-text probe.remove(); var cs = getComputedStyle(pre); var room = pre.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight); + // In the viewer the art is held at its own width, never the transcript (DECISIONS 310, 9.3). + if (viewer && viewer.textWidth) { + viewer.textWidth(made.width * cw + (figure.clientWidth - room) + 1); + room = pre.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight); + } var art = made.width * cw <= room + 0.5; var html = art ? made.html : figure.__transcript; if (code.innerHTML !== html) code.innerHTML = html; pre.toggleAttribute('data-art', art); - if (art && spec.motion === 'animated' && !figure.__inked) { - figure.__inked = true; - var ms = function (n, f) { return parseFloat(cs.getPropertyValue('--basalt-' + n)) || f; }; - buildByInk(code, model.steps.filter(function (st) { return 'n' in st; }).length, { slower: ms('duration-slower', 300), step: ms('duration-diagram-step', 320), limit: ms('duration-diagram-limit', 5000) }); - } + // Under "motion": "animated" the art builds by ink when it comes into view: the diagram-motion module's, as a drawn figure's entrance is. }; })(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram-zoom.js b/tools/html-skill/src/modules/diagram-zoom.js index 512901b2..c90798b4 100644 --- a/tools/html-skill/src/modules/diagram-zoom.js +++ b/tools/html-skill/src/modules/diagram-zoom.js @@ -4,7 +4,7 @@ bundled into this module by build.mjs); the figure is drawn by the diagram module's engine (Basalt._.diagramKit), so this holds no second copy of it. compose.mjs adds this module to a page with a figure unless every figure on it says "zoom": false. The implementation hasn't been reviewed. Source: tools/html-skill/src/modules/diagram-zoom.js (do not edit the copy in the skill folder). */ -import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } from "../../../../packages/react/src/diagram-zoom-core.ts"; +import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint, viewerTextWidth } from "../../../../packages/react/src/diagram-zoom-core.ts"; (function (B) { 'use strict'; @@ -19,7 +19,8 @@ import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } fr function openViewer(page, spec, ctx, opener) { var kit = _.diagramKit; var still = Object.assign({}, spec, { motion: 'still' }); - var model = kit.buildModel(still); + // An automatic figure's key hint is read from a placed model, as React's (unplaced, every card is in one cell). + var model = kit.buildModel(still, { placement: Array.isArray(still.placement) ? still.placement[0] : still.placement }); var id = 'dgv' + (++serial); var key = kit.figureKey('diagram', model); var hint = viewerHint(kit.hintEntries(model, true)).map(function (e) { return '' + e.keys.map(kbd).join(' ') + ' ' + esc(e.words) + ''; }).join(''); @@ -66,6 +67,7 @@ import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } fr layer: layer, avail: 0, row: 1104, contain: 480, memo: memo, measureFigure: kit.measureFigure, keys: VIEWER_KEYS, room: function () { var pad = parseFloat(getComputedStyle(sizer).paddingTop) || 0; return { w: stage.clientWidth - 2 * pad, h: stage.clientHeight - 2 * pad }; }, measure: function (f, m, p, base, current, apply, warn) { return measureViewerFigure(f, m, p, base, current, apply, warn, view); }, + textWidth: function (need) { viewerTextWidth(view, need); }, onMeasured: function (measured, f) { stage.setAttribute('data-layout', measured.dyn.layout || ''); if (keyBox) { keyBox.setAttribute('data-layout', measured.dyn.layout || ''); keyBox.toggleAttribute('data-bare', Boolean(measured.dyn.bare)); } @@ -102,6 +104,12 @@ import { attachZoom, measureViewerFigure, revealIn, VIEWER_KEYS, viewerHint } fr buttons.out.addEventListener('click', function () { if (!buttons.out.hasAttribute('aria-disabled')) zoom.zoomOut(); }); buttons.in.addEventListener('click', function () { if (!buttons.in.hasAttribute('aria-disabled')) zoom.zoomIn(); }); buttons.fit.addEventListener('click', function () { if (!buttons.fit.hasAttribute('aria-disabled')) zoom.fit(); }); + // A linked card is followed on a click, a tap or Enter; a link that stays in this tab closes the viewer first (DECISIONS 310, 9.7). + d.addEventListener('click', function (e) { + var a = e.target.closest && e.target.closest('a.diagram-node[href]'); + if (!a || !d.contains(a) || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || (a.target && a.target !== '_self')) return; + if (d.open) d.close(); + }); stage.addEventListener('focusin', function (e) { var node = e.target.closest && e.target.closest('.diagram-node'); if (node && stage.contains(node)) revealIn(stage, node, px(stage, '--_clear') || 16); From e459629662803f84625fd1a5eb77080d3b947761 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:24:16 -0600 Subject: [PATCH 44/62] The engine, the stylesheet and export after both reviews and the sweep (Fable B5, B6, B7, P2, P3; Neon B4, B5, B7 to B10, P1, P3, P4, P7, P8, P9; 66-1 to 66-3) Right to left, drawn: a frame's tab, its else row and its rule are placed from the frame's end edge in the grid's own coordinates, so the tab is in the frame's top start corner (the right) and the rule spans the frame; a self-call's words sit beside its loop by the loop's physical side; a self-call's room is measured to its neighbour by column; a Mono detail is one left-to-right run, so its words keep their order; stacked, a group's label is on its start side (66-3). The stacked drawing itself is still not mirrored: a named gap (foundations 6.9 says so). Stacked: the else rule runs edge to edge of its frame (P2); a row that follows a frame draws no divider (P3); a group whose first card is entered by a turn has space-12 above, its label in the first space-8 (the decider's answer 1, B7); a node held taller than its words (the 44px touch floor) centres them (66-1); a route's arrow and the name it points at are one unbreakable item, and its lines keep the 16px pitch (66-2). The transcript is Draft B's reference (B6): number, sender, arrow and receiver; then the label and the note on lines of their own, every line hanging under the sender inside its frame's indent. The text art's key draws the focal participant as the art does, a double box (P4). The sequence: a text box grown space-1 that would lie on a frame's side fails the fit rule (Neon B7); its lifelines are a layer under its frames, and its bars, lines and plates over them (P8); a quiet run's head goes with its line in forced colours, and its label does not transition under reduced motion. Automatic layout and the schema: a placement with two cards in one cell, a card left out or a card inside a group's box it is not in is not used (the figure tries its other direction, then stacks, and a development build names the cards); the skill writes an automatic figure's words on its placement, so before script its cards are in their cells; the figure's grid attributes are synced with the model (data-cols and its kin), and an automatic figure with no placement is stacked before script (B8). A one-column schema's turn-backs to one key share a lane only when they state the same thing (B9). A card grows to 48, not 49 (P1). Right to left keeps a way-only column (P3). A dropped tight far line gives up its corridor (P8). The skill's says-check reads a data flow step's lane label (B10). Development checks: a whitespace href is empty; more than 100 cards warns; an automatic figure with no cells has no spatial keys to check; the skill warns on "first-visit" with no id and gives rule 5's warning, as React does (P4). The 5.1 list's "throws" stays a warning, as batch A's checks are: changing it is a decision, reported. A ground tap with no trace up does nothing (P7). The skill's downloads do not print, and "Clear highlight" stays last in its foot (P7). Export: every drawing SVG is sized and placed, a stretched one keeps its strokes (vector-effect), an entrance's reveal masks are left out; the drawing's lines are written under the cards; the structural rules drawn by pseudo-elements (a lane's, a band's, a frame's else) are lines in the file, and a linked card's arrow is not; a running entrance's or a run's colours are read at their end and every state (trace, quiet run, arrival) is taken off for the read and put back at once, before the faces are fetched; a figure inside a zoomed layer is read at 100% with its head and key (the skill's viewer, 9.11); a face that is not there is not embedded; a panel's lit top edge is its own line (B5, P8). Types: DiagramCardinality and DiagramCardinalityPair are exported (P9). Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/compose.mjs | 6 +- .../basalt-html/parts/diagram-export.js | 2 +- .../basalt-html/parts/diagram-motion.js | 2 +- .../basalt-html/parts/diagram-place.mjs | 17 ++- .../skills/basalt-html/parts/diagram-text.js | 4 +- .../skills/basalt-html/parts/diagram-zoom.js | 2 +- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 18 +-- .agent/skills/basalt-html/parts/manifest.json | 4 +- .../basalt-html/parts/usage/diagram-motion.md | 1 + .../skills/basalt-html/parts/usage/diagram.md | 5 +- packages/react/src/diagram-core.ts | 104 ++++++++++--- packages/react/src/diagram-export.ts | 143 +++++++++++++----- packages/react/src/index.ts | 2 +- packages/react/src/schema-diagram.tsx | 2 +- packages/react/src/styles/components.css | 68 ++++++++- tools/html-skill/src/compose.mjs | 6 +- tools/html-skill/src/modules/diagram.js | 39 ++++- 18 files changed, 313 insertions(+), 114 deletions(-) diff --git a/.agent/skills/basalt-html/compose.mjs b/.agent/skills/basalt-html/compose.mjs index 2c05398b..8271b793 100644 --- a/.agent/skills/basalt-html/compose.mjs +++ b/.agent/skills/basalt-html/compose.mjs @@ -679,7 +679,9 @@ function writeDiagrams(markup, held, parts, notes, marks) { let rewrote = false; for (const n of cards) { if (!n || n.mark === undefined || n.mark === null) continue; - if (typeof n.mark === "string") useMark(marks, n.mark, n, notes); + // A data flow's step counts its lane's label as its words, as React's check does (DECISIONS 306, 1.6; Neon's B10 of the code review). + const lane = spec.type === "data-flow" && Array.isArray(spec.lanes) ? spec.lanes.find((l) => l && l.id === n.lane) : null; + if (typeof n.mark === "string") useMark(marks, n.mark, lane ? { ...n, laneLabel: lane.label } : n, notes); else { n.mark = ownMark(marks, n.mark); rewrote = true; } } if (rewrote) { @@ -729,7 +731,7 @@ function useMark(marks, id, node, notes) { } function checkSays(file, id, node, notes) { const says = (Object.hasOwn(file.says, id) ? file.says[id] : undefined) ?? []; - const words = [node.name, node.kind, node.detail].filter(Boolean).join(" ").toLowerCase(); + const words = [node.name, node.kind, node.detail, node.laneLabel].filter(Boolean).join(" ").toLowerCase(); if (says.length && !says.some((w) => words.includes(w.toLowerCase()))) notes.push(`${node.id}'s mark (${id}) stands for ${says.join(" or ")}, and none of its words say so: a mark never carries a fact alone`); } diff --git a/.agent/skills/basalt-html/parts/diagram-export.js b/.agent/skills/basalt-html/parts/diagram-export.js index 3f343f95..586ac96d 100644 --- a/.agent/skills/basalt-html/parts/diagram-export.js +++ b/.agent/skills/basalt-html/parts/diagram-export.js @@ -1 +1 @@ -(()=>{var N="http://www.w3.org/2000/svg",S=t=>t.replace(/[&<>"']/g,s=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[s]),T=t=>!!t&&t!=="transparent"&&!/rgba\([^)]*,\s*0\)$/.test(t)&&!/\/\s*0\)$/.test(t),v=t=>Math.round(t*100)/100;function P(t){const s=c=>t.querySelector(`:scope > [class$="-${c}"], :scope > [class*="-${c} "]`);return["head","drawing","key"].map(s).filter(c=>!!(c&&c.getClientRects().length))}async function q(t){for(const s of Array.from(document.styleSheets)){let c;try{c=s.cssRules}catch{continue}for(const m of Array.from(c)){if(!(m instanceof CSSFontFaceRule)||m.style.getPropertyValue("font-family").replace(/["']/g,"").trim()!==t)continue;const r=/url\(["']?([^"')]+)["']?\)/.exec(m.style.getPropertyValue("src"))?.[1];if(r){if(r.startsWith("data:"))return r;try{const e=await(await fetch(new URL(r,s.href??location.href))).blob();return await new Promise((o,i)=>{const a=new FileReader;a.onload=()=>o(String(a.result)),a.onerror=i,a.readAsDataURL(e)})}catch{return null}}}}return null}function W(t,s,c){const m=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let r=m.nextNode();r;r=m.nextNode()){const e=r.parentElement;if(!e||!r.textContent?.trim()||e.closest("[aria-hidden='true'] .basalt-visually-hidden, .basalt-visually-hidden, .visually-hidden, [class$='-ruler'], [hidden]"))continue;const o=getComputedStyle(e);if(o.visibility==="hidden"||o.display==="none")continue;const i=r.textContent,a=document.createRange();for(const d of i.matchAll(/\S+/g)){a.setStart(r,d.index),a.setEnd(r,d.index+d[0].length);const n=a.getBoundingClientRect();if(!n.width)continue;const f=Number.parseFloat(o.fontSize),p=n.top-s.top+(n.height-f)/2+f*.8;c.push(`${S(d[0])}`)}}}function F(t,s,c){const m=[t,...Array.from(t.querySelectorAll("*"))];for(const r of m){if(r instanceof SVGElement){if(r.tagName.toLowerCase()!=="svg"||r.closest("svg")!==r)continue;const u=r.getBoundingClientRect();if(!u.width||!u.height)continue;const h=r.cloneNode(!0),x=[r,...Array.from(r.querySelectorAll("*"))],y=[h,...Array.from(h.querySelectorAll("*"))];x.forEach((b,R)=>{const l=getComputedStyle(b),$=y[R];for(const A of["fill","stroke","stroke-width","stroke-dasharray","stroke-linecap","stroke-linejoin","opacity"])$.setAttribute(A,l.getPropertyValue(A));$.removeAttribute("class"),l.display==="none"&&$.setAttribute("display","none")}),h.setAttribute("x",String(v(u.left-s.left))),h.setAttribute("y",String(v(u.top-s.top))),h.removeAttribute("style"),c.push(h.outerHTML);continue}const e=getComputedStyle(r);if(e.display==="none"||e.visibility==="hidden")continue;const o=r.getBoundingClientRect();if(!o.width||!o.height)continue;const i=v(o.left-s.left),a=v(o.top-s.top),d=v(o.width),n=v(o.height),f=Number.parseFloat(e.borderTopLeftRadius)||0,p=T(e.backgroundColor)?e.backgroundColor:"none",g=[e.borderTopWidth,e.borderRightWidth,e.borderBottomWidth,e.borderLeftWidth].map(u=>Number.parseFloat(u)||0),C=g.every(u=>u===g[0]);if(!C){const[u,h,x,y]=g,b=(R,l,$,A,D,G)=>{R&&T(l)&&c.push(``)};b(u,e.borderTopColor,i,a+u/2,i+d,a+u/2),b(x,e.borderBottomColor,i,a+n-x/2,i+d,a+n-x/2),b(y,e.borderLeftColor,i+y/2,a,i+y/2,a+n),b(h,e.borderRightColor,i+d-h/2,a,i+d-h/2,a+n)}const w=C?g[0]:0,L=w&&e.borderTopStyle!=="none"&&T(e.borderTopColor)?e.borderTopColor:"none";if(p!=="none"||L!=="none"){const u=e.borderTopStyle==="dashed"?' stroke-dasharray="4 2"':"";c.push(``)}const k=/url\(["']?([^"')]+)["']?\)/.exec(e.backgroundImage)?.[1];k&&/-mark$/.test(String(r.getAttribute("class")))&&c.push(``)}}var B=t=>t.querySelector("[class$='-title']")?.textContent?.trim()??"",O=t=>t.querySelector("figcaption")?.textContent?.trim()??"",M=(t,s)=>`${B(t).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"diagram"}.${s}`;async function E(t,s,c){const m=s.theme??"page",r=t.getAttribute("data-theme"),e=Array.from(t.querySelectorAll("[data-lit], [data-dim], [data-near]")),o=e.map(n=>[n,n.getAttribute("data-lit"),n.getAttribute("data-dim"),n.getAttribute("data-near")]);e.forEach(n=>{n.removeAttribute("data-lit"),n.removeAttribute("data-dim"),n.removeAttribute("data-near")});const i=Array.from(t.querySelectorAll("[class*='-flow'], [class*='-bead'], [class*='-packet']"));i.forEach(n=>{n.dataset.exportHidden=n.style.display,n.style.display="none"});const a=t.getAttribute("data-entrance");a&&a!=="done"&&t.setAttribute("data-entrance","done"),m!=="page"&&t.setAttribute("data-theme",m);const d=t.style.getPropertyValue("--basalt-export");t.classList.add("basalt-exporting");try{t.offsetWidth;const n=Number.parseFloat(getComputedStyle(t).getPropertyValue("--basalt-space-4"))||16,f=P(t),p=f.map(l=>l.getBoundingClientRect()),g=Math.min(...p.map(l=>l.left)),C=Math.min(...p.map(l=>l.top)),w=Math.max(...p.map(l=>l.right)),L=Math.max(...p.map(l=>l.bottom)),k=new DOMRect(g-n,C-n,0,0),u=Math.ceil(w-g+2*n),h=Math.ceil(L-C+2*n),x=getComputedStyle(t).getPropertyValue("--basalt-surface-page").trim()||getComputedStyle(document.body).backgroundColor,y=[];for(const l of f)F(l,k,y);for(const l of f)W(l,k,y);let b="";if(c){const l=[];for(const $ of["Geist","Geist Mono"]){const A=await q($);A?l.push(`@font-face{font-family:"${$}";src:url(${A});font-weight:100 900}`):console.warn(`Basalt diagramToSvg: the face "${$}" could not be read, so the file names it`)}l.length&&(b=``)}return{svg:`${S(B(t))}${S(O(t))}${b}${y.join("")}`,w:u,h}}finally{t.classList.remove("basalt-exporting"),d&&t.style.setProperty("--basalt-export",d),m!=="page"&&(r===null?t.removeAttribute("data-theme"):t.setAttribute("data-theme",r)),a&&a!=="done"&&t.setAttribute("data-entrance",a),i.forEach(n=>{n.style.display=n.dataset.exportHidden??"",delete n.dataset.exportHidden});for(const[n,f,p,g]of o)f!==null&&n.setAttribute("data-lit",f),p!==null&&n.setAttribute("data-dim",p),g!==null&&n.setAttribute("data-near",g)}}async function V(t,s={}){const{svg:c}=await E(t,s,(s.fonts??"embed")==="embed");return new Blob([c],{type:"image/svg+xml"})}async function U(t,s={}){const{svg:c,w:m,h:r}=await E(t,s,!0),e=s.scale??2,o=new Image;o.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c)}`,await o.decode();const i=document.createElement("canvas");i.width=Math.round(m*e),i.height=Math.round(r*e);const a=i.getContext("2d");return a.scale(e,e),a.drawImage(o,0,0,m,r),new Promise((d,n)=>i.toBlob(f=>f?d(f):n(new Error("the PNG could not be made")),"image/png"))}(function(t){"use strict";var s=t._;function c(r,e){var o=document.createElement("a");o.href=URL.createObjectURL(r),o.download=e,document.body.appendChild(o),o.click(),o.remove(),setTimeout(function(){URL.revokeObjectURL(o.href)},1e3)}function m(r,e){var o=document.createElement("button");return o.type="button",o.className="btn diagram-download",o.setAttribute("data-variant","secondary"),o.setAttribute("data-size","sm"),o.innerHTML=""+r+"",o.addEventListener("click",e),o}s.diagramExport=function(r,e){var o=m("Download SVG",function(){V(e).then(function(d){c(d,M(e,"svg"))})}),i=m("Download PNG",function(){U(e).then(function(d){c(d,M(e,"png"))})}),a=r.querySelector(".diagram-clear");return r.insertBefore(o,a),r.insertBefore(i,a),[o,i]}})(window.Basalt)})(); +(()=>{var G="http://www.w3.org/2000/svg",C=t=>t.replace(/[&<>"']/g,i=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[i]),k=t=>!!t&&t!=="transparent"&&!/rgba\([^)]*,\s*0\)$/.test(t)&&!/\/\s*0\)$/.test(t),h=t=>Math.round(t*100)/100;function z(t){const i=c=>t.querySelector(`:scope > [class$="-${c}"], :scope > [class*="-${c} "]`);return["head","drawing","key"].map(i).filter(c=>!!(c&&c.getClientRects().length))}async function U(t){for(const i of Array.from(document.styleSheets)){let c;try{c=i.cssRules}catch{continue}for(const l of Array.from(c)){if(!(l instanceof CSSFontFaceRule)||l.style.getPropertyValue("font-family").replace(/["']/g,"").trim()!==t)continue;const e=/url\(["']?([^"')]+)["']?\)/.exec(l.style.getPropertyValue("src"))?.[1];if(e){if(e.startsWith("data:"))return e;try{const n=await fetch(new URL(e,i.href??location.href));if(!n.ok)return null;const o=await n.blob();return await new Promise((d,s)=>{const a=new FileReader;a.onload=()=>d(String(a.result)),a.onerror=s,a.readAsDataURL(o)})}catch{return null}}}}return null}function j(t,i,c){const l=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let e=l.nextNode();e;e=l.nextNode()){const n=e.parentElement;if(!n||!e.textContent?.trim()||n.closest("[aria-hidden='true'] .basalt-visually-hidden, .basalt-visually-hidden, .visually-hidden, [class$='-ruler'], [hidden]"))continue;const o=getComputedStyle(n);if(o.visibility==="hidden"||o.display==="none")continue;const d=e.textContent,s=document.createRange();for(const a of d.matchAll(/\S+/g)){s.setStart(e,a.index),s.setEnd(e,a.index+a[0].length);const f=s.getBoundingClientRect();if(!f.width)continue;const m=Number.parseFloat(o.fontSize),b=f.top-i.top+(f.height-m)/2+m*.8;c.push(`${C(a[0])}`)}}}function D(t,i,c){if(/-(lane|band|felse)(\s|$)/.test(` ${t.getAttribute("class")??""}`))for(const l of["::before","::after"]){const e=getComputedStyle(t,l);if(!e.content||e.content==="none"||e.content==="normal"||e.display==="none"||e.position!=="absolute")continue;const n=t.getBoundingClientRect(),o=getComputedStyle(t),d=n.left+(Number.parseFloat(o.borderLeftWidth)||0)+(Number.parseFloat(e.left)||0)-i.left,s=n.top+(Number.parseFloat(o.borderTopWidth)||0)+(Number.parseFloat(e.top)||0)-i.top,a=Number.parseFloat(e.width)||0,f=Number.parseFloat(e.height)||0,m=Number.parseFloat(e.borderTopWidth)||0,b=e.maskImage&&e.maskImage!=="none"?` stroke-dasharray="${Number.parseFloat(e.maskSize)/2||4} ${Number.parseFloat(e.maskSize)/2||4}"`:"";k(e.backgroundColor)&&a&&f?c.push(``):m&&k(e.borderTopColor)&&c.push(``)}}function O(t,i,c){const l=t.getBoundingClientRect();if(!l.width||!l.height||t.getAttribute("class")?.endsWith("-motion-defs"))return;const e=t.cloneNode(!0),n=[t,...Array.from(t.querySelectorAll("*"))],o=[e,...Array.from(e.querySelectorAll("*"))],d=t.viewBox?.baseVal,s=!!(d&&d.width&&(Math.abs(d.width-l.width)>.5||Math.abs(d.height-l.height)>.5));n.forEach((a,f)=>{const m=getComputedStyle(a),b=o[f];for(const w of["fill","stroke","stroke-width","stroke-dasharray","stroke-linecap","stroke-linejoin","opacity"])b.setAttribute(w,m.getPropertyValue(w));b.removeAttribute("class"),/-reveal-/.test(b.getAttribute("mask")??"")&&b.removeAttribute("mask"),s&&f>0&&b.setAttribute("vector-effect","non-scaling-stroke"),m.display==="none"&&b.setAttribute("display","none")}),e.setAttribute("x",String(h(l.left-i.left))),e.setAttribute("y",String(h(l.top-i.top))),e.setAttribute("width",String(h(l.width))),e.setAttribute("height",String(h(l.height))),e.removeAttribute("style"),c.push(e.outerHTML)}function H(t,i,c){const l=[t,...Array.from(t.querySelectorAll("*"))],e=l.filter(n=>n instanceof SVGSVGElement&&n.closest("svg")===n&&!!n.closest("[class$='-ink']"));for(const n of e)O(n,i,c);for(const n of l){if(n instanceof SVGElement){if(n.tagName.toLowerCase()!=="svg"||n.closest("svg")!==n||e.includes(n))continue;O(n,i,c);continue}const o=getComputedStyle(n);if(o.display==="none"||o.visibility==="hidden")continue;const d=n.getBoundingClientRect();if(!d.width||!d.height)continue;const s=h(d.left-i.left),a=h(d.top-i.top),f=h(d.width),m=h(d.height),b=Number.parseFloat(o.borderTopLeftRadius)||0,w=k(o.backgroundColor)?o.backgroundColor:"none",A=[o.borderTopWidth,o.borderRightWidth,o.borderBottomWidth,o.borderLeftWidth].map(r=>Number.parseFloat(r)||0),x=A.every(r=>r===A[0]);if(!x){const[r,u,p,v]=A,$=(T,R,F,B,M,E)=>{T&&k(R)&&c.push(``)};$(r,o.borderTopColor,s,a+r/2,s+f,a+r/2),$(p,o.borderBottomColor,s,a+m-p/2,s+f,a+m-p/2),$(v,o.borderLeftColor,s+v/2,a,s+v/2,a+m),$(u,o.borderRightColor,s+f-u/2,a,s+f-u/2,a+m)}const g=x?A[0]:0,N=o.borderLeftColor,S=g&&o.borderTopStyle!=="none"&&k(N)?N:"none";if(w!=="none"||S!=="none"){const r=o.borderTopStyle==="dashed"?' stroke-dasharray="4 2"':"";c.push(``),S!=="none"&&!r&&o.borderTopColor!==N&&k(o.borderTopColor)&&c.push(``)}D(n,i,c);const L=/url\(["']?([^"')]+)["']?\)/.exec(o.backgroundImage)?.[1];L&&/-mark$/.test(String(n.getAttribute("class")))&&c.push(``)}}var q=t=>t.querySelector("[class$='-title']")?.textContent?.trim()??"",I=t=>t.querySelector("figcaption")?.textContent?.trim()??"",P=(t,i)=>`${q(t).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"diagram"}.${i}`;async function V(t,i,c){const l=i.theme??"page",e=t.getAttribute("data-theme"),n=["data-lit","data-dim","data-near","data-ahead","data-arrival","data-arrival-out"],o=Array.from(t.querySelectorAll(n.map(r=>`[${r}]`).join(", "))),d=o.map(r=>[r,n.map(u=>r.getAttribute(u))]);o.forEach(r=>{for(const u of n)r.removeAttribute(u)});const s=Array.from(t.querySelectorAll("[class*='-flow'], [class*='-bead'], [class*='-packet']"));s.forEach(r=>{r.dataset.exportHidden=r.style.display,r.style.display="none"});const a=t.getAttribute("data-entrance");a&&a!=="done"&&t.setAttribute("data-entrance","done");const f=t.getAnimations({subtree:!0}).map(r=>({a:r,at:r.currentTime,running:r.playState==="running"}));for(const{a:r}of f){const u=r.effect?.getComputedTiming().endTime;r.pause(),typeof u=="number"&&Number.isFinite(u)&&(r.currentTime=u)}const m=t.getAttribute("data-viewer");m!==null&&t.removeAttribute("data-viewer");const b=[];for(let r=t.parentElement;r;r=r.parentElement){const u=getComputedStyle(r).transform,p=/^matrix\(([^,]+),[^,]+,[^,]+,([^,]+),/.exec(u);p&&(Math.abs(Number(p[1])-1)>1e-6||Math.abs(Number(p[2])-1)>1e-6)&&(b.push([r,r.style.transform]),r.style.transform="none")}l!=="page"&&t.setAttribute("data-theme",l),t.classList.add("basalt-exporting");let w;try{t.offsetWidth;const r=Number.parseFloat(getComputedStyle(t).getPropertyValue("--basalt-space-4"))||16,u=z(t),p=u.map(y=>y.getBoundingClientRect()),v=Math.min(...p.map(y=>y.left)),$=Math.min(...p.map(y=>y.top)),T=Math.max(...p.map(y=>y.right)),R=Math.max(...p.map(y=>y.bottom)),F=new DOMRect(v-r,$-r,0,0),B=Math.ceil(T-v+2*r),M=Math.ceil(R-$+2*r),E=getComputedStyle(t).getPropertyValue("--basalt-surface-page").trim()||getComputedStyle(document.body).backgroundColor,W=[];for(const y of u)H(y,F,W);for(const y of u)j(y,F,W);w={body:W,w:B,h:M,ground:E}}finally{t.classList.remove("basalt-exporting"),l!=="page"&&(e===null?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e));for(const[r,u]of b)r.style.transform=u;m!==null&&t.setAttribute("data-viewer",m);for(const{a:r,at:u,running:p}of f)r.currentTime=u,p&&r.play();a&&a!=="done"&&t.setAttribute("data-entrance",a),s.forEach(r=>{r.style.display=r.dataset.exportHidden??"",delete r.dataset.exportHidden});for(const[r,u]of d)n.forEach((p,v)=>{const $=u[v];$!=null&&r.setAttribute(p,$)})}const{body:A,w:x,h:g,ground:N}=w;let S="";if(c){const r=[];for(const u of["Geist","Geist Mono"]){const p=await U(u);p?r.push(`@font-face{font-family:"${u}";src:url(${p});font-weight:100 900}`):console.warn(`Basalt diagramToSvg: the face "${u}" could not be read, so the file names it`)}r.length&&(S=``)}return{svg:`${C(q(t))}${C(I(t))}${S}${A.join("")}`,w:x,h:g}}async function _(t,i={}){const{svg:c}=await V(t,i,(i.fonts??"embed")==="embed");return new Blob([c],{type:"image/svg+xml"})}async function X(t,i={}){const{svg:c,w:l,h:e}=await V(t,i,!0),n=i.scale??2,o=new Image;o.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c)}`,await o.decode();const d=document.createElement("canvas");d.width=Math.round(l*n),d.height=Math.round(e*n);const s=d.getContext("2d");return s.scale(n,n),s.drawImage(o,0,0,l,e),new Promise((a,f)=>d.toBlob(m=>m?a(m):f(new Error("the PNG could not be made")),"image/png"))}(function(t){"use strict";var i=t._;function c(e,n){var o=document.createElement("a");o.href=URL.createObjectURL(e),o.download=n,document.body.appendChild(o),o.click(),o.remove(),setTimeout(function(){URL.revokeObjectURL(o.href)},1e3)}function l(e,n){var o=document.createElement("button");return o.type="button",o.className="btn diagram-download",o.setAttribute("data-variant","secondary"),o.setAttribute("data-size","sm"),o.innerHTML=""+e+"",o.addEventListener("click",n),o}i.diagramExport=function(e,n){var o=l("Download SVG",function(){_(n).then(function(a){c(a,P(n,"svg"))})}),d=l("Download PNG",function(){X(n).then(function(a){c(a,P(n,"png"))})}),s=e.querySelector(".diagram-clear");return e.insertBefore(o,s),e.insertBefore(d,s),[o,d]}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-motion.js b/.agent/skills/basalt-html/parts/diagram-motion.js index 0096a735..32555478 100644 --- a/.agent/skills/basalt-html/parts/diagram-motion.js +++ b/.agent/skills/basalt-html/parts/diagram-motion.js @@ -1 +1 @@ -(()=>{var T=Object.defineProperty,G=(t,i,e)=>i in t?T(t,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[i]=e,c=(t,i,e)=>G(t,typeof i!="symbol"?i+"":i,e);function P(t,i,e=0){const s=h=>String(Math.round(h*100)/100);let n=`M${s(t[0].x)} ${s(t[0].y)}`;for(let h=1;h`basalt-diagram-entrance:${location.pathname}#${t.id}`;function x(t){const i=t.getAttribute("data-entrance");i!=="pending"&&i!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}var g;function _(t){if(!g){const i=()=>{for(const h of g?.figs??[])h.sync()},e=()=>{for(const h of g?.figs??[])x(h.host.fig);i()},s=new IntersectionObserver(h=>{for(const a of h)for(const o of g?.figs??[])o.drawing===a.target&&o.seen(a)},{threshold:Array.from({length:21},(h,a)=>a/20)}),n=new MutationObserver(h=>{for(const a of h){if(a.target===document.documentElement){for(const o of g?.figs??[])o.holdChanged();continue}for(const o of g?.figs??[])o.host.fig===a.target&&o.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const r=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(h=>matchMedia(h));for(const h of r)h.addEventListener("change",i);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",i),g={figs:new Set,io:s,mo:n,media:r,onChange:i,onPrint:e}}return g.figs.add(t),t.drawing&&g.io.observe(t.drawing),g.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),g}function F(t){if(g&&(g.figs.delete(t),t.drawing&&g.io.unobserve(t.drawing),!g.figs.size)){g.io.disconnect(),g.mo.disconnect();for(const i of g.media)i.removeEventListener("change",g.onChange);window.removeEventListener("beforeprint",g.onPrint),document.removeEventListener("visibilitychange",g.onChange),g=void 0}}function I(t){const i=getComputedStyle(t),e=h=>i.getPropertyValue(`--basalt-${h}`).trim(),s=h=>{const a=e(h),o=parseFloat(a);return/ms$/.test(a)?o:/s$/.test(a)?o*1e3:o||0},n=h=>parseFloat(e(h))||0,r=h=>e(`ease-${h}`)||"ease";return{lineMin:s("duration-diagram-line-min"),lineMax:s("duration-diagram-line-max"),stagger:s("duration-diagram-stagger"),step:s("duration-diagram-step"),arrow:s("duration-diagram-arrow"),limit:s("duration-diagram-limit"),legMin:s("duration-diagram-leg-min"),legMax:s("duration-diagram-leg-max"),rest:s("duration-diagram-rest"),pause:s("duration-diagram-pause"),repeat:s("duration-diagram-repeat"),fast:s("duration-fast"),base:s("duration-base"),slow:s("duration-slow"),slower:s("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:r("in-out"),out:r("out"),in:r("in")}}var L=(t,i,e)=>Math.max(i,Math.min(e,t)),V="http://www.w3.org/2000/svg",w=(t,i,e)=>{const s=document.createElementNS(V,t);for(const[n,r]of Object.entries(i))s.setAttribute(n,String(r));return e?.appendChild(s),s},E=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",R={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function v(t,i){const e=t.pts.map(o=>({...o})),s=R[t.dir],n=e[e.length-1],r=e[e.length-2],h=Math.hypot(n.x-r.x,n.y-r.y),a=Math.min(i,Math.max(0,h-.5));return n.x-=s.x*a,n.y-=s.y*a,e}var M=t=>t.slice(1).reduce((i,e,s)=>i+Math.hypot(e.x-t[s].x,e.y-t[s].y),0),N=(t,i)=>{const e=t.map(n=>n.x),s=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-i),t:Math.floor(Math.min(...s)-i),r:Math.ceil(Math.max(...e)+i),b:Math.ceil(Math.max(...s)+i)}},D=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",i=>(this.listeners.add(i),()=>{this.listeners.delete(i)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const i of[...this.flowEls.values(),...this.beadEls.values()])i.remove();this.dot?.remove(),F(this)}}),c(this,"played",!1),c(this,"onSettle",()=>{this.played&&!this.byMode()&&this.markVisit(),this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const s=this.introEnd?.currentTime,n=s!=null?Number(s):E()-this.t0,r=new Set([...this.plans].filter(([,o])=>o.end<=n).map(([o])=>o)),{plans:h,factor:a}=this.plan(this.ordered(e),this.factor);for(const o of r){const l=this.plans.get(o);l&&h.set(o,l)}this.factor=a,this.plans=h,this.build(r,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const i=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(s=>!!s.flow)]);i!==this.signature&&(this.signature=i,x(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",i=>{if(!this.lastSend){this.lastSend={v:i};return}i===void 0||i===this.lastSend.v||(this.lastSend={v:i},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}x(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=I(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=_(this),this.sync()}publish(){const t=this.hasLines(),i=this.host.model(),e=this.modes(),s=i.edges.some(r=>r.flow)||!!i.motion.pulse||!!i.motion.packet?.repeat,n={canLoop:i.motion.animated&&s&&t&&!e.reduce&&!e.forced,runShown:i.motion.animated&&i.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const r of this.listeners)r()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}byMode(){const t=this.modes();return t.held||t.print||t.reduce||t.forced}markVisit(){const t=this.host.fig;if(!(!t.hasAttribute("data-first-visit")||!t.id))try{localStorage.setItem(O(t),"1")}catch{}}hasLines(){return!!this.host.geo()?.lines.length}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const i=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=i-.5,this.sync()}holdChanged(){this.modes().held&&x(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=E()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,i=this.host.model(),e=this.modes(),s=this.entrance();(s==="pending"||s==="running")&&(e.held||e.print||e.reduce||e.forced)?x(t):s==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!s&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(i,e),this.publish()}ordered(t){const i=this.host.model(),e=[...t.lines];return i.type==="schema"?e.sort((s,n)=>s.pts[0].y-n.pts[0].y||s.pts[0].x-n.pts[0].x||s.i-n.i):e.sort((s,n)=>s.i-n.i),e}plan(t,i){const e=this.t,s=this.host.model().type==="sequence",n=s?e.step:e.stagger,r=t.map(o=>{const l=this.lineEl(o)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(o.pts),m=s?e.arrow:L(d/e.trace*1e3,e.lineMin,e.lineMax),u=s?e.base:0;return{lead:u,dur:m,tail:u+Math.max(m,.85*m+e.slow,s?e.slower:0)}});let h=1;for(let o=1;o{const d=l*n*h;a.set(o.i,{start:d+r[l].lead,dur:r[l].dur,end:d+r[l].tail})}),{plans:a,factor:h}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.played=!0,this.t0=E();const{plans:i,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=i,this.build(new Set,!0)}build(t,i){const e=this.host.geo(),s=this.host.fig,{P:n}=this.host,r=this.t;if(!e)return;const h=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const a=s.querySelector(`.${n}-ink`),o=a?.querySelector(`.${n}-svg`);if(!a||!o)return;this.defs=w("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),o.after(this.defs);const l=w("defs",{},this.defs),d=(u,p=this.intro)=>(h===null?u.startTime=this.t0:(u.pause(),u.currentTime=h),p.add(u),u);let m=0;for(const u of e.lines){const p=this.plans.get(u.i),f=this.lineEl(u);if(!p||!f)continue;if(m=Math.max(m,p.end),t.has(u.i)){f.removeAttribute("mask");continue}const b=`${this.host.base}-reveal-${u.i}`,$=w("mask",{id:b,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),S=f.querySelector(`.${n}-line`);if(S){const y=S.getTotalLength(),C=w("path",{d:S.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${y} ${y+8}`,"stroke-dashoffset":y},$);d(C.animate([{strokeDashoffset:`${y}px`},{strokeDashoffset:"0px"}],{duration:p.dur,delay:p.start,easing:r.inOut,fill:"both"}))}const k=f.querySelector(`.${n}-tip`);if(k){const y=w("path",{d:k.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},$);d(y.animate([{opacity:0},{opacity:1}],{duration:r.slow,delay:p.start+.85*p.dur,easing:r.out,fill:"both"}))}const A=f.querySelector(`.${n}-dot`);if(A){const y=w("circle",{cx:A.getAttribute("cx")??0,cy:A.getAttribute("cy")??0,r:Number(A.getAttribute("r")??3)+1,fill:"#fff"},$);d(y.animate([{opacity:0},{opacity:1}],{duration:r.fast,delay:p.start,easing:r.out,fill:"both"}))}f.querySelectorAll(`.${n}-crow, .${n}-ring`).forEach(y=>{const z=y.tagName.toLowerCase()==="circle"?w("circle",{cx:y.getAttribute("cx")??0,cy:y.getAttribute("cy")??0,r:Number(y.getAttribute("r")??3)+1,fill:"#fff"},$):w("path",{d:y.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":3},$),U=y.getAttribute("data-end")==="from";d(z.animate([{opacity:0},{opacity:1}],U?{duration:r.fast,delay:p.start,easing:r.out,fill:"both"}:{duration:r.slow,delay:p.start+.85*p.dur,easing:r.out,fill:"both"}))}),f.setAttribute("mask",`url(#${b})`)}if(i&&this.host.model().type==="sequence"){const u=getComputedStyle(s),p=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),b=s.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach(($,S)=>{const k=b[S]?.querySelector(`.${n}-mlabel`),A=this.plans.get($.i);k&&A&&p&&f&&d(k.animate([{color:p},{color:f}],{duration:r.slower,delay:A.start-r.base,easing:r.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(s.animate([],{duration:Math.max(1,m)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.markVisit(),this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,i){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||i.reduce||i.forced||i.print||i.held||this.traced()||E(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,i){i.add(t);const e=()=>{i.delete(t)};return t.finished.then(e,e),i===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,i){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),i).finished.then(e=>{e.cancel()})}overlay(t,i,e){const s=this.host.fig.querySelector(`.${this.host.P}-ink`),n=s?.querySelector(`.${this.host.P}-svg`);if(!s||!n)return null;const r=this.host.tokens(),h=v(t,r?.head??8),a=N(h,i),o=w("svg",{class:`${this.host.P}-${e}`,width:a.r-a.l,height:a.b-a.t,viewBox:`${a.l} ${a.t} ${a.r-a.l} ${a.b-a.t}`,"aria-hidden":"true",focusable:"false"});o.style.left=`${a.l}px`,o.style.top=`${a.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(o),{svg:o,d:P(h,t.from===t.to?r?.radiusXs??4:r?.radius??8),pts:h}}visible(t,i){const e=this.host.geo();let s=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const r=(n.box.t+n.box.b)/2,h=i.some((a,o)=>o>0&&Math.abs(a.y-i[o-1].y)<.5&&Math.abs(r-a.y)<1.5);s+=h?n.box.r-n.box.l:n.box.b-n.box.t}return M(i)-s}flow(t,i){const e=t.lines.find(a=>a.i===i);if(!e)return;const s=this.host.tokens();if(e.kind==="dashed"){if(this.visible(e,v(e,s?.head??8))<48)return;const a=this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${i}"] .${this.host.P}-line`);if(!a)return;const o=(s?.dash??6)+(s?.dashGap??4);this.track(a.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-o}px`}],{duration:o/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops);return}let n=this.flowEls.get(i);if(n&&!n.isConnected&&(this.flowEls.delete(i),n=void 0),!n){const a=s?.space("1")??4,o=this.overlay({...e,pts:v(e,a)},e.width+2,"flow");if(!o)return;if(this.visible(e,v(e,s?.head??8))<48){o.svg.remove();return}const l=s?.cut??2;w("path",{d:o.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},o.svg),n=o.svg,this.flowEls.set(i,n)}n.style.display="";const r=n.firstElementChild,h=this.t.flowPeriod;this.track(r.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-h}px`}],{duration:h/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,i){const s=this.host.model().edges.find(n=>n.from===t&&n.to===i);return s?this.host.geo()?.lines.find(n=>n.i===s.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,i){const e=this.host.tokens();for(;t===this.loopGen;){for(let s=1;st===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(i,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const s=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=s;try{await s.finished}finally{this.repeatGap===s&&(this.repeatGap=null),s.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),i=t.motion.packet?.path;if(!t.motion.animated||!i||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(i[i.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const s=++this.runGen;this.packetRun(i,this.runAnims,()=>s===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&s===this.runGen&&(this.waiting=!1,this.send())})}quiet(t,i){const e=this.host.P,s=this.host.fig,n=s.querySelectorAll(`.${e}-msg`);i.forEach((r,h)=>{const a=t>=0&&h>t;n[h]?.toggleAttribute("data-ahead",a),s.querySelector(`.${e}-edge[data-edge="${r.i}"]`)?.toggleAttribute("data-ahead",a)})}stopRun(){this.runGen++,this.runAt=-1,this.host.fig.querySelectorAll("[data-ahead]").forEach(t=>t.removeAttribute("data-ahead"));for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){const i=this.host.geo();if(!i?.lines.length)return;for(const a of this.runAnims)a.cancel();this.runAnims.clear();const e=++this.runGen,s=()=>e===this.runGen,n=this.ordered(i),r=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let a=t;a{if(!q(a))throw a})}};function B(t){const i=[],e=[],{pulse:s,packet:n}=t.motion;s&&n&&i.push("a figure names both a pulse and a packet: it has one mover at most");const r=s??n?.path,h=s?"pulse":"packet",a=new Set;if(r){for(const o of r)t.byId.has(o)||i.push(`the ${h} names ${o}, which is not a node`);for(let o=1;od.from===r[o-1]&&d.to===r[o]);l?a.add(l.i):i.push(`the ${h} goes from ${r[o-1]} to ${r[o]}, and no line joins them in that direction`)}}for(const o of t.edges)o.flow&&(a.has(o.i)&&i.push(`the line from ${o.from} to ${o.to} flows and is on the ${h}'s route: flow never runs on a line the mover travels`),o.label||e.push(`the line from ${o.from} to ${o.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:i,warnings:e}}function j(t){return new D(t)}(function(t){"use strict";var i=t._;function e(s,n,r){var h=document.createElement("button");return h.type="button",h.className="btn "+s,h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),r&&r(h),h.appendChild(document.createTextNode(n)),h}i.diagramMotion=function(s,n,r){var h=B(n.model());h.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),h.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var a=j(n),o=s.querySelector(".diagram-foot"),l=null,d=null;o&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){a.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var b=document.createElement("span");b.className="btn-check",b.setAttribute("aria-hidden","true"),f.appendChild(b)}),l.hidden=d.hidden=!0,o.appendChild(l),o.appendChild(d));function m(){var f=a.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=a.subscribe(m);m();var p=r&&r.packet?r.packet.send:void 0;return a.sendValue("__diagramSend"in s?s.__diagramSend:p),a.sendValue(p),s.__diagramSend=p,{redrawn:a.redrawn,sendValue:function(f){a.sendValue(f),s.__diagramSend=f},destroy:function(){u(),a.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); +(()=>{var T=Object.defineProperty,G=(t,i,e)=>i in t?T(t,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[i]=e,c=(t,i,e)=>G(t,typeof i!="symbol"?i+"":i,e);function L(t,i,e=0){const s=r=>String(Math.round(r*100)/100);let n=`M${s(t[0].x)} ${s(t[0].y)}`;for(let r=1;r`basalt-diagram-entrance:${location.pathname}#${t.id}`;function $(t){const i=t.getAttribute("data-entrance");i!=="pending"&&i!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}var m;function N(t){if(!m){const i=()=>{for(const r of m?.figs??[])r.sync()},e=()=>{for(const r of m?.figs??[])$(r.host.fig);i()},s=new IntersectionObserver(r=>{for(const h of r)for(const o of m?.figs??[])o.drawing===h.target&&o.seen(h)},{threshold:Array.from({length:21},(r,h)=>h/20)}),n=new MutationObserver(r=>{for(const h of r){if(h.target===document.documentElement){for(const o of m?.figs??[])o.holdChanged();continue}for(const o of m?.figs??[])o.host.fig===h.target&&o.traceChanged()}});n.observe(document.documentElement,{attributes:!0,attributeFilter:["data-loops"]});const a=["(prefers-reduced-motion: reduce)","(forced-colors: active)","print"].map(r=>matchMedia(r));for(const r of a)r.addEventListener("change",i);window.addEventListener("beforeprint",e),document.addEventListener("visibilitychange",i),m={figs:new Set,io:s,mo:n,media:a,onChange:i,onPrint:e}}return m.figs.add(t),t.drawing&&m.io.observe(t.drawing),m.mo.observe(t.host.fig,{attributes:!0,attributeFilter:["data-tracing","data-viewing"]}),m}function V(t){if(m&&(m.figs.delete(t),t.drawing&&m.io.unobserve(t.drawing),!m.figs.size)){m.io.disconnect(),m.mo.disconnect();for(const i of m.media)i.removeEventListener("change",m.onChange);window.removeEventListener("beforeprint",m.onPrint),document.removeEventListener("visibilitychange",m.onChange),m=void 0}}function I(t){const i=getComputedStyle(t),e=r=>i.getPropertyValue(`--basalt-${r}`).trim(),s=r=>{const h=e(r),o=parseFloat(h);return/ms$/.test(h)?o:/s$/.test(h)?o*1e3:o||0},n=r=>parseFloat(e(r))||0,a=r=>e(`ease-${r}`)||"ease";return{lineMin:s("duration-diagram-line-min"),lineMax:s("duration-diagram-line-max"),stagger:s("duration-diagram-stagger"),step:s("duration-diagram-step"),arrow:s("duration-diagram-arrow"),limit:s("duration-diagram-limit"),legMin:s("duration-diagram-leg-min"),legMax:s("duration-diagram-leg-max"),rest:s("duration-diagram-rest"),pause:s("duration-diagram-pause"),repeat:s("duration-diagram-repeat"),fast:s("duration-fast"),base:s("duration-base"),slow:s("duration-slow"),slower:s("duration-slower"),trace:n("speed-diagram-trace"),packet:n("speed-diagram-packet"),pulse:n("speed-diagram-pulse"),flow:n("speed-diagram-flow"),bead:n("size-diagram-bead"),flowPeriod:n("size-diagram-flow"),inOut:a("in-out"),out:a("out"),in:a("in")}}var P=(t,i,e)=>Math.max(i,Math.min(e,t)),R="http://www.w3.org/2000/svg",b=(t,i,e)=>{const s=document.createElementNS(R,t);for(const[n,a]of Object.entries(i))s.setAttribute(n,String(a));return e?.appendChild(s),s},S=()=>Number(document.timeline.currentTime??performance.now()),q=t=>t instanceof DOMException&&t.name==="AbortError",_={up:{x:0,y:-1},down:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0}};function v(t,i){const e=t.pts.map(o=>({...o})),s=_[t.dir],n=e[e.length-1],a=e[e.length-2],r=Math.hypot(n.x-a.x,n.y-a.y),h=Math.min(i,Math.max(0,r-.5));return n.x-=s.x*h,n.y-=s.y*h,e}var M=t=>t.slice(1).reduce((i,e,s)=>i+Math.hypot(e.x-t[s].x,e.y-t[s].y),0),F=(t,i)=>{const e=t.map(n=>n.x),s=t.map(n=>n.y);return{l:Math.floor(Math.min(...e)-i),t:Math.floor(Math.min(...s)-i),r:Math.ceil(Math.max(...e)+i),b:Math.ceil(Math.max(...s)+i)}},D=class{constructor(t){c(this,"host"),c(this,"drawing"),c(this,"page"),c(this,"t"),c(this,"listeners",new Set),c(this,"snapshot",{canLoop:!1,runShown:!1,running:!1}),c(this,"destroyed",!1),c(this,"t0",0),c(this,"factor",1),c(this,"plans",new Map),c(this,"intro",new Set),c(this,"labels",new Set),c(this,"introEnd",null),c(this,"defs",null),c(this,"signature",""),c(this,"inView",!1),c(this,"enough",!1),c(this,"loopGen",0),c(this,"loops",new Set),c(this,"looping",!1),c(this,"flowEls",new Map),c(this,"beadEls",new Map),c(this,"dot",null),c(this,"dotOwner",null),c(this,"resumeAt",0),c(this,"resumeTimer",0),c(this,"runGen",0),c(this,"runAnims",new Set),c(this,"runAt",-1),c(this,"inFlight",!1),c(this,"waiting",!1),c(this,"lastSend",null),c(this,"arrivals",new Map),c(this,"state",()=>this.snapshot),c(this,"subscribe",i=>(this.listeners.add(i),()=>{this.listeners.delete(i)})),c(this,"destroy",()=>{if(!this.destroyed){this.destroyed=!0,this.stopRun(),this.clearLoops(),this.entrance()==="running"&&this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.host.fig.removeEventListener("basalt-diagram-settle",this.onSettle),clearTimeout(this.resumeTimer);for(const i of[...this.flowEls.values(),...this.beadEls.values()])i.remove();this.dot?.remove(),V(this)}}),c(this,"played",!1),c(this,"onSettle",()=>{this.played&&!this.byMode()&&this.markVisit(),this.clearIntro(),this.sync()}),c(this,"redrawn",()=>{if(this.destroyed)return;if(this.entrance()==="running"){const e=this.host.geo();if(!this.textCode())if(!e?.lines.length)this.clearIntro(),this.host.fig.setAttribute("data-entrance","done");else{const s=this.introEnd?.currentTime,n=s!=null?Number(s):S()-this.t0,a=new Set([...this.plans].filter(([,o])=>o.end<=n).map(([o])=>o)),{plans:r,factor:h}=this.plan(this.ordered(e),this.factor);for(const o of a){const l=this.plans.get(o);l&&r.set(o,l)}this.factor=h,this.plans=r,this.build(a,!1)}}this.looping&&this.clearLoops();for(const e of[...this.flowEls.values(),...this.beadEls.values()])e.remove();this.flowEls.clear(),this.beadEls.clear(),this.runAt>=0&&this.playRun(this.runAt),this.sync()}),c(this,"changed",()=>{const i=this.edgeSignature(),e=JSON.stringify([this.host.model().motion.pulse,this.host.model().motion.packet?.path,this.host.model().edges.map(s=>!!s.flow)]);i!==this.signature&&(this.signature=i,$(this.host.fig),this.stopRun()),e!==this.route&&(this.route=e,this.looping&&this.clearLoops()),this.sync()}),c(this,"route",""),c(this,"repeatGap",null),c(this,"sendValue",i=>{if(!this.lastSend){this.lastSend={v:i};return}i===void 0||i===this.lastSend.v||(this.lastSend={v:i},this.send())}),c(this,"toggleRun",()=>{if(this.runAt>=0){this.stopRun(),this.publish();return}$(this.host.fig),this.playRun(0),this.publish()}),this.host=t,this.drawing=t.fig.querySelector(`.${t.P}-drawing`),this.t=I(t.fig),this.signature=this.edgeSignature(),t.fig.addEventListener("basalt-diagram-settle",this.onSettle),this.page=N(this),this.sync()}publish(){const t=this.hasLines(),i=this.host.model(),e=this.modes(),s=i.edges.some(a=>a.flow)||!!i.motion.pulse||!!i.motion.packet?.repeat,n={canLoop:i.motion.animated&&s&&t&&!e.reduce&&!e.forced,runShown:i.motion.animated&&i.motion.run&&t,running:this.runAt>=0};if(!(n.canLoop===this.snapshot.canLoop&&n.runShown===this.snapshot.runShown&&n.running===this.snapshot.running)){this.snapshot=n;for(const a of this.listeners)a()}}modes(){return{reduce:matchMedia("(prefers-reduced-motion: reduce)").matches,forced:matchMedia("(forced-colors: active)").matches,print:matchMedia("print").matches,held:document.documentElement.getAttribute("data-loops")==="held"}}entrance(){return this.host.fig.getAttribute("data-entrance")}byMode(){const t=this.modes();return t.held||t.print||t.reduce||t.forced}markVisit(){const t=this.host.fig;if(!(!t.hasAttribute("data-first-visit")||!t.id))try{localStorage.setItem(O(t),"1")}catch{}}textCode(){return this.host.model().text?this.host.fig.querySelector(`.${this.host.P}-text[data-art] .${this.host.P}-text-ink`):null}hasLines(){return!!this.host.geo()?.lines.length||!!this.textCode()}traced(){return this.host.fig.hasAttribute("data-tracing")||this.host.fig.hasAttribute("data-viewing")}seen(t){this.inView=t.isIntersecting;const i=Math.min(t.boundingClientRect.height,window.innerHeight)*.4;this.enough=t.isIntersecting&&t.intersectionRect.height>=i-.5,this.sync()}holdChanged(){this.modes().held&&$(this.host.fig),this.sync()}traceChanged(){this.traced()?(this.stopRun(),clearTimeout(this.resumeTimer),this.resumeAt=1/0):this.resumeAt===1/0&&(this.resumeAt=S()+this.t.pause,clearTimeout(this.resumeTimer),this.resumeTimer=window.setTimeout(()=>{this.resumeAt=0,this.sync()},this.t.pause)),this.sync()}sync(){if(this.destroyed)return;const t=this.host.fig,i=this.host.model(),e=this.modes(),s=this.entrance();(s==="pending"||s==="running")&&(e.held||e.print||e.reduce||e.forced)?$(t):s==="pending"&&this.enough&&!document.hidden&&this.hasLines()&&this.play(),!s&&this.enough&&this.hasLines()&&t.setAttribute("data-entrance","done"),this.syncLoops(i,e),this.publish()}ordered(t){const i=this.host.model(),e=[...t.lines];return i.type==="schema"?e.sort((s,n)=>s.pts[0].y-n.pts[0].y||s.pts[0].x-n.pts[0].x||s.i-n.i):e.sort((s,n)=>s.i-n.i),e}plan(t,i){const e=this.t,s=this.host.model().type==="sequence",n=s?e.step:e.stagger,a=t.map(o=>{const l=this.lineEl(o)?.querySelector(`.${this.host.P}-line`),d=l?l.getTotalLength():M(o.pts),p=s?e.arrow:P(d/e.trace*1e3,e.lineMin,e.lineMax),u=s?e.base:0;return{lead:u,dur:p,tail:u+Math.max(p,.85*p+e.slow,s?e.slower:0)}});let r=1;for(let o=1;o{const d=l*n*r;h.set(o.i,{start:d+a[l].lead,dur:a[l].dur,end:d+a[l].tail})}),{plans:h,factor:r}}lineEl(t){return this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${t.i}"]`)}play(){if(this.textCode()){this.playText();return}const t=this.host.geo();if(!t?.lines.length)return;this.host.fig.setAttribute("data-entrance","running"),this.played=!0,this.t0=S();const{plans:i,factor:e}=this.plan(this.ordered(t));this.factor=e,this.plans=i,this.build(new Set,!0)}build(t,i){const e=this.host.geo(),s=this.host.fig,{P:n}=this.host,a=this.t;if(!e)return;const r=this.introEnd?.playState==="paused"&&this.introEnd.currentTime!==null?Number(this.introEnd.currentTime):null;for(const u of this.intro)u.cancel();this.intro.clear(),this.defs?.remove();const h=s.querySelector(`.${n}-ink`),o=h?.querySelector(`.${n}-svg`);if(!h||!o)return;this.defs=b("svg",{class:`${n}-motion-defs`,width:0,height:0,"aria-hidden":"true",focusable:"false"}),o.after(this.defs);const l=b("defs",{},this.defs),d=(u,g=this.intro)=>(r===null?u.startTime=this.t0:(u.pause(),u.currentTime=r),g.add(u),u);let p=0;for(const u of e.lines){const g=this.plans.get(u.i),f=this.lineEl(u);if(!g||!f)continue;if(p=Math.max(p,g.end),t.has(u.i)){f.removeAttribute("mask");continue}const w=`${this.host.base}-reveal-${u.i}`,x=b("mask",{id:w,maskUnits:"userSpaceOnUse",x:-e.w,y:-e.h,width:3*e.w,height:3*e.h},l),k=f.querySelector(`.${n}-line`);if(k){const y=k.getTotalLength(),C=b("path",{d:k.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":u.width+6,"stroke-dasharray":`${y} ${y+8}`,"stroke-dashoffset":y},x);d(C.animate([{strokeDashoffset:`${y}px`},{strokeDashoffset:"0px"}],{duration:g.dur,delay:g.start,easing:a.inOut,fill:"both"}))}const E=f.querySelector(`.${n}-tip`);if(E){const y=b("path",{d:E.getAttribute("d")??"",fill:"#fff",stroke:"#fff","stroke-width":3,"stroke-linejoin":"round"},x);d(y.animate([{opacity:0},{opacity:1}],{duration:a.slow,delay:g.start+.85*g.dur,easing:a.out,fill:"both"}))}const A=f.querySelector(`.${n}-dot`);if(A){const y=b("circle",{cx:A.getAttribute("cx")??0,cy:A.getAttribute("cy")??0,r:Number(A.getAttribute("r")??3)+1,fill:"#fff"},x);d(y.animate([{opacity:0},{opacity:1}],{duration:a.fast,delay:g.start,easing:a.out,fill:"both"}))}f.querySelectorAll(`.${n}-crow, .${n}-ring`).forEach(y=>{const z=y.tagName.toLowerCase()==="circle"?b("circle",{cx:y.getAttribute("cx")??0,cy:y.getAttribute("cy")??0,r:Number(y.getAttribute("r")??3)+1,fill:"#fff"},x):b("path",{d:y.getAttribute("d")??"",fill:"none",stroke:"#fff","stroke-width":3},x),U=y.getAttribute("data-end")==="from";d(z.animate([{opacity:0},{opacity:1}],U?{duration:a.fast,delay:g.start,easing:a.out,fill:"both"}:{duration:a.slow,delay:g.start+.85*g.dur,easing:a.out,fill:"both"}))}),f.setAttribute("mask",`url(#${w})`)}if(i&&this.host.model().type==="sequence"){const u=getComputedStyle(s),g=u.getPropertyValue("--basalt-text-secondary").trim(),f=u.getPropertyValue("--basalt-text-primary").trim(),w=s.querySelectorAll(`.${n}-msg`);this.ordered(e).forEach((x,k)=>{const E=w[k]?.querySelector(`.${n}-mlabel`),A=this.plans.get(x.i);E&&A&&g&&f&&d(E.animate([{color:g},{color:f}],{duration:a.slower,delay:A.start-a.base,easing:a.out,fill:"both"}),this.labels)})}this.introEnd?.cancel(),this.introEnd=d(s.animate([],{duration:Math.max(1,p)}),new Set),this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}finishIntro(){this.entrance()==="running"&&(this.markVisit(),this.host.fig.setAttribute("data-entrance","done"),this.clearIntro(),this.sync())}playText(){const t=this.textCode();if(!t)return;const i=this.host.fig,e=this.t;i.setAttribute("data-entrance","running"),this.played=!0,this.t0=S();const s=[...t.querySelectorAll("[data-n]")],n=Math.max(0,...s.map(l=>Number(l.dataset.n))),a=n>1?Math.min(e.step,(e.limit-e.slower)/(n-1)):0,r=getComputedStyle(i),h=r.getPropertyValue("--basalt-text-secondary").trim(),o=r.getPropertyValue("--basalt-text-tertiary").trim();for(const l of s){const d=Number(l.dataset.n);l.querySelectorAll('[data-ink="label"], [data-ink="main"], [data-ink="plain"]').forEach(p=>{const u=p.dataset.ink==="label"?h:o,g=p.animate([{color:u},{color:u,offset:.001},{color:getComputedStyle(p).color}],{duration:e.slower,delay:(d-1)*a,easing:"ease-out",fill:"backwards"});g.startTime=this.t0,this.intro.add(g)})}this.introEnd?.cancel(),this.introEnd=i.animate([],{duration:Math.max(1,(n-1)*a+e.slower)}),this.introEnd.startTime=this.t0,this.introEnd.finished.then(()=>this.finishIntro(),()=>{})}clearIntro(){for(const t of[...this.intro,...this.labels])t.cancel();this.intro.clear(),this.labels.clear(),this.introEnd?.cancel(),this.introEnd=null,this.defs?.remove(),this.defs=null,this.host.fig.querySelectorAll(`.${this.host.P}-edge[mask]`).forEach(t=>t.removeAttribute("mask"))}edgeSignature(){const t=this.host.model();return(t.type==="sequence"?t.steps.flatMap(e=>"n"in e?[`${e.from}>${e.to}:${e.kind}`]:[]):t.edges.map(e=>`${e.from}>${e.to}:${e.kind}`)).join("|")}syncLoops(t,i){const e=this.entrance()==="done";if(!t.motion.animated||!e||!this.hasLines()||i.reduce||i.forced||i.print||i.held||this.traced()||S(){}):t.motion.packet?.repeat&&this.repeat(e,t.motion.packet.path).catch(()=>{})}clearLoops(){this.looping=!1,this.loopGen++;for(const t of this.loops)t.cancel();this.loops.clear();for(const t of[...this.flowEls.values(),...this.beadEls.values()])t.style.display="none";this.dotOwner==="loop"&&this.dot&&(this.dot.style.display="none",this.dotOwner=null),this.runAt<0&&this.dotOwner!=="run"&&this.clearArrivals()}track(t,i){i.add(t);const e=()=>{i.delete(t)};return t.finished.then(e,e),i===this.loops&&(!this.inView||document.hidden)&&t.pause(),t}wait(t,i){return this.track(this.host.fig.animate([],{duration:Math.max(1,t)}),i).finished.then(e=>{e.cancel()})}overlay(t,i,e){const s=this.host.fig.querySelector(`.${this.host.P}-ink`),n=s?.querySelector(`.${this.host.P}-svg`);if(!s||!n)return null;const a=this.host.tokens(),r=v(t,a?.head??8),h=F(r,i),o=b("svg",{class:`${this.host.P}-${e}`,width:h.r-h.l,height:h.b-h.t,viewBox:`${h.l} ${h.t} ${h.r-h.l} ${h.b-h.t}`,"aria-hidden":"true",focusable:"false"});o.style.left=`${h.l}px`,o.style.top=`${h.t}px`;let d=this.defs??n;for(;d.nextElementSibling&&!d.nextElementSibling.classList.contains(`${this.host.P}-label`);)d=d.nextElementSibling;return d.after(o),{svg:o,d:L(r,t.from===t.to?a?.radiusXs??4:a?.radius??8),pts:r}}visible(t,i){const e=this.host.geo();let s=0;for(const n of e?.labels??[])if(n.i===t.i&&n.on){const a=(n.box.t+n.box.b)/2,r=i.some((h,o)=>o>0&&Math.abs(h.y-i[o-1].y)<.5&&Math.abs(a-h.y)<1.5);s+=r?n.box.r-n.box.l:n.box.b-n.box.t}return M(i)-s}flow(t,i){const e=t.lines.find(h=>h.i===i);if(!e)return;const s=this.host.tokens();if(e.kind==="dashed"){if(this.visible(e,v(e,s?.head??8))<48)return;const h=this.host.fig.querySelector(`.${this.host.P}-edge[data-edge="${i}"] .${this.host.P}-line`);if(!h)return;const o=(s?.dash??6)+(s?.dashGap??4);this.track(h.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-o}px`}],{duration:o/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops);return}let n=this.flowEls.get(i);if(n&&!n.isConnected&&(this.flowEls.delete(i),n=void 0),!n){const h=s?.space("1")??4,o=this.overlay({...e,pts:v(e,h)},e.width+2,"flow");if(!o)return;if(this.visible(e,v(e,s?.head??8))<48){o.svg.remove();return}const l=s?.cut??2;b("path",{d:o.d,"stroke-width":e.width+2,"stroke-dasharray":`${l} ${this.t.flowPeriod-l}`},o.svg),n=o.svg,this.flowEls.set(i,n)}n.style.display="";const a=n.firstElementChild,r=this.t.flowPeriod;this.track(a.animate([{strokeDashoffset:"0px"},{strokeDashoffset:`${-r}px`}],{duration:r/this.t.flow*1e3,iterations:1/0,easing:"linear"}),this.loops)}edgeFor(t,i){const s=this.host.model().edges.find(n=>n.from===t&&n.to===i);return s?this.host.geo()?.lines.find(n=>n.i===s.i):void 0}node(t){return this.host.fig.querySelector(`.${this.host.P}-node[data-node="${CSS.escape(t)}"]`)}arrive(t){!t||this.traced()||(clearTimeout(this.arrivals.get(t)),t.removeAttribute("data-arrival-out"),t.setAttribute("data-arrival",""))}depart(t){!t||!t.hasAttribute("data-arrival")||(t.removeAttribute("data-arrival"),t.setAttribute("data-arrival-out",""),this.arrivals.set(t,window.setTimeout(()=>{t.removeAttribute("data-arrival-out"),this.arrivals.delete(t)},this.t.slower*.75)))}clearArrivals(){this.host.fig.querySelectorAll("[data-arrival], [data-arrival-out]").forEach(t=>{t.removeAttribute("data-arrival"),t.removeAttribute("data-arrival-out")});for(const t of this.arrivals.values())clearTimeout(t);this.arrivals.clear()}async pulse(t,i){const e=this.host.tokens();for(;t===this.loopGen;){for(let s=1;st===this.loopGen;try{for(;e();){this.inFlight=!0,this.waiting=!1;try{await this.packetRun(i,this.loops,e)}finally{this.inFlight=!1}if(!e())return;if(this.waiting)continue;const s=this.track(this.host.fig.animate([],{duration:Math.max(1,this.t.repeat)}),this.loops);this.repeatGap=s;try{await s.finished}finally{this.repeatGap===s&&(this.repeatGap=null),s.cancel()}}}finally{!e()&&!this.looping&&(this.waiting=!1)}}send(){const t=this.host.model(),i=t.motion.packet?.path;if(!t.motion.animated||!i||!this.hasLines())return;if(this.inFlight){this.waiting=!0;return}const e=this.modes();if(e.held||e.reduce){const n=this.node(i[i.length-1]);this.arrive(n),this.wait(this.t.rest,this.runAnims).then(()=>this.depart(n),()=>this.depart(n));return}if(this.looping&&t.motion.packet?.repeat){this.waiting=!0,this.repeatGap?.finish();return}this.inFlight=!0;const s=++this.runGen;this.packetRun(i,this.runAnims,()=>s===this.runGen).catch(n=>{if(!q(n))throw n}).finally(()=>{this.inFlight=!1,this.waiting&&s===this.runGen&&(this.waiting=!1,this.send())})}quiet(t,i){const e=this.host.P,s=this.host.fig,n=s.querySelectorAll(`.${e}-msg`);i.forEach((a,r)=>{const h=t>=0&&r>t;n[r]?.toggleAttribute("data-ahead",h),s.querySelector(`.${e}-edge[data-edge="${a.i}"]`)?.toggleAttribute("data-ahead",h)})}stopRun(){this.runGen++,this.runAt=-1,this.host.fig.querySelectorAll("[data-ahead]").forEach(t=>t.removeAttribute("data-ahead"));for(const t of this.runAnims)t.cancel();this.runAnims.clear(),this.dot&&this.dotOwner==="run"&&(this.dot.style.display="none",this.dotOwner=null),this.looping||(this.inFlight=!1),this.looping?this.host.fig.querySelectorAll(`.${this.host.P}-msg[data-arrival]`).forEach(t=>t.removeAttribute("data-arrival")):this.clearArrivals()}playRun(t){if(this.textCode()){this.playTextRun(t);return}const i=this.host.geo();if(!i?.lines.length)return;for(const h of this.runAnims)h.cancel();this.runAnims.clear();const e=++this.runGen,s=()=>e===this.runGen,n=this.ordered(i),a=this.host.fig.querySelectorAll(`.${this.host.P}-msg`);this.runAt=t,(async()=>{for(let h=t;h{if(!q(h))throw h})}playTextRun(t){const i=this.textCode();if(!i)return;for(const o of this.runAnims)o.cancel();this.runAnims.clear();const e=++this.runGen,s=()=>e===this.runGen,n=[...i.querySelectorAll("[data-n]")],a=Math.max(0,...n.map(o=>Number(o.dataset.n))),r=o=>{for(const l of n)l.toggleAttribute("data-ahead",o>=0&&Number(l.dataset.n)>o)};this.runAt=t,(async()=>{for(let o=t;oNumber(d.dataset.n)===o+1);if(await this.wait(this.t.legMin+this.t.base,this.runAnims),!s())return;for(const d of l)d.setAttribute("data-arrival","");await this.wait(this.t.rest,this.runAnims);for(const d of l)d.removeAttribute("data-arrival")}s()&&(this.runAt=-1,r(-1),this.publish())})().catch(o=>{if(!q(o))throw o})}};function B(t){const i=[],e=[],{pulse:s,packet:n}=t.motion;s&&n&&i.push("a figure names both a pulse and a packet: it has one mover at most");const a=s??n?.path,r=s?"pulse":"packet",h=new Set;if(a){for(const o of a)t.byId.has(o)||i.push(`the ${r} names ${o}, which is not a node`);for(let o=1;od.from===a[o-1]&&d.to===a[o]);l?h.add(l.i):i.push(`the ${r} goes from ${a[o-1]} to ${a[o]}, and no line joins them in that direction`)}}for(const o of t.edges)o.flow&&(h.has(o.i)&&i.push(`the line from ${o.from} to ${o.to} flows and is on the ${r}'s route: flow never runs on a line the mover travels`),o.label||e.push(`the line from ${o.from} to ${o.to} flows but has no label: motion never carries a fact alone, so its label says it is a stream`));return{errors:i,warnings:e}}function j(t){return new D(t)}(function(t){"use strict";var i=t._;function e(s,n,a){var r=document.createElement("button");return r.type="button",r.className="btn "+s,r.setAttribute("data-variant","secondary"),r.setAttribute("data-size","sm"),a&&a(r),r.appendChild(document.createTextNode(n)),r}i.diagramMotion=function(s,n,a){var r=B(n.model());r.errors.forEach(function(f){console.error("Basalt diagram: "+f)}),r.warnings.forEach(function(f){console.warn("Basalt diagram: "+f)});var h=j(n),o=s.querySelector(".diagram-foot"),l=null,d=null;o&&(l=e("diagram-play","Play the run"),l.addEventListener("click",function(){h.toggleRun()}),d=e("diagram-pause","Pause animations",function(f){f.setAttribute("data-loops-toggle",""),f.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held())));var w=document.createElement("span");w.className="btn-check",w.setAttribute("aria-hidden","true"),f.appendChild(w)}),l.hidden=d.hidden=!0,o.appendChild(l),o.appendChild(d));function p(){var f=h.state();l&&(l.hidden=!f.runShown,l.lastChild.textContent=f.running?"Stop the run":"Play the run"),d&&(d.hidden=!f.canLoop,d.setAttribute("aria-pressed",String(!!(t.loops&&t.loops.held()))))}var u=h.subscribe(p);p();var g=a&&a.packet?a.packet.send:void 0;return h.sendValue("__diagramSend"in s?s.__diagramSend:g),h.sendValue(g),s.__diagramSend=g,{redrawn:h.redrawn,sendValue:function(f){h.sendValue(f),s.__diagramSend=f},destroy:function(){u(),h.destroy(),l&&l.remove(),d&&d.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-place.mjs b/.agent/skills/basalt-html/parts/diagram-place.mjs index 5ebc5796..39c2dd03 100644 --- a/.agent/skills/basalt-html/parts/diagram-place.mjs +++ b/.agent/skills/basalt-html/parts/diagram-place.mjs @@ -19,18 +19,19 @@ __export(diagram_elk_exports, { default: () => diagram_elk_default }); import ELK from "elkjs/lib/elk.bundled.js"; -var diagram_elk_default; +var Elk, diagram_elk_default; var init_diagram_elk = __esm({ "packages/react/src/diagram-elk.ts"() { "use strict"; - diagram_elk_default = ELK; + Elk = ELK; + diagram_elk_default = Elk; } }); // tools/html-skill/src/diagram-place.mjs import { workerData } from "node:worker_threads"; -// packages/react/src/diagram-layout.ts +// packages/react/src/diagram-layout-graph.ts var W = 200; var H = 80; var STRAIGHT = "10"; @@ -82,6 +83,8 @@ function graphOf(cards, lines, groups, direction) { } return { id: "root", layoutOptions: options(direction), children, edges: lines.map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to], ...e.main ? { layoutOptions: { "elk.layered.priority.straightness": STRAIGHT } } : {} })) }; } + +// packages/react/src/diagram-layout.ts function absolute(node, ox = 0, oy = 0, out = /* @__PURE__ */ new Map()) { for (const c of node.children ?? []) { const x = ox + (c.x ?? 0), y = oy + (c.y ?? 0); @@ -128,7 +131,7 @@ function unusable(cards, groups, cells) { } const chain = (id) => { const out = []; - for (let g = id; g; g = groups.find((x) => x.id === g)?.parent) out.push(g); + for (let g = id; g && !out.includes(g); g = groups.find((x) => x.id === g)?.parent) out.push(g); return out; }; for (const g of groups) { @@ -147,7 +150,7 @@ async function placeDiagram(input, direction) { const layer = (id) => direction === "down" ? first[id].row : first[id].col; const chain = (id) => { const out = []; - for (let g = id; g; g = groups.find((x) => x.id === g)?.parent) out.push(g); + for (let g = id; g && !out.includes(g); g = groups.find((x) => x.id === g)?.parent) out.push(g); return out; }; const groupOf = new Map(cards.map((c) => [c.id, c.group])); @@ -176,12 +179,12 @@ async function placeDiagram(input, direction) { all.splice(all.findIndex((c) => c.id === e.to), 0, ...boxes); ways++; } - const span = (c) => ({ cols: Math.max(...Object.values(c).map((x) => x.col)), rows: Math.max(...Object.values(c).map((x) => x.row)) }); + const span = (c) => ({ cols: Math.max(1, ...Object.values(c).map((x) => x.col)), rows: Math.max(1, ...Object.values(c).map((x) => x.row)) }); if (!ways) return { direction, ...span(first), cells: first }; const second = await cellsOf(graphOf(all, chained, groups, direction)); const cells = {}; for (const c of cards) cells[c.id] = second[c.id]; - const layers = (c) => Math.max(...cards.map((x) => direction === "down" ? c[x.id].row : c[x.id].col)); + const layers = (c) => Math.max(1, ...cards.map((x) => direction === "down" ? c[x.id].row : c[x.id].col)); return unusable(cards, groups, cells) || layers(cells) > layers(first) ? { direction, ...span(first), cells: first } : { direction, ...span(second), cells }; } diff --git a/.agent/skills/basalt-html/parts/diagram-text.js b/.agent/skills/basalt-html/parts/diagram-text.js index d624dbe8..5b89224c 100644 --- a/.agent/skills/basalt-html/parts/diagram-text.js +++ b/.agent/skills/basalt-html/parts/diagram-text.js @@ -1,2 +1,2 @@ -(()=>{var B={"&":"&","<":"<",">":">",'"':""","'":"'"},T=h=>h.replace(/[&<>"']/g,l=>B[l]);function F(h){const l=h.nodes,b=h.steps,c=t=>Array.from(t).length,m=l.map(t=>Math.max(8,c(t.name)+4)),i=l.map(()=>0);let S=0;l.forEach((t,n)=>{i[n]=S+Math.floor(m[n]/2),S+=m[n]+4});const k=(t,n,r)=>{const[s,p]=t0)for(let u=p;u"n"in t&&t.from===t.to&&(h.byId.get(t.from)?.i??0)===y?c(`${t.n} ${t.label}`)+8:0)),M=(i[y]??0)+Math.ceil((m[y]??8)/2)+$+2,x=[],d=()=>{const t={ch:Array(M).fill(" "),ink:Array(M).fill("")};return x.push(t),t},a=(t,n,r,s)=>{Array.from(r).forEach((p,f)=>{const u=n+f;u>=0&&uh.bars.some(r=>r.who===l[t].id&&r.from<=n&&r.to>=n);let L=0;const v=t=>l.forEach((n,r)=>a(t,i[r],q(r,L)?"┃":"│",q(r,L)?"working":"life")),V=d(),W=d(),R=d();l.forEach((t,n)=>{const r=i[n]-Math.floor(m[n]/2),s=m[n],[p,f,u,w,E,e]=t.focal?["╔","═","╗","║","╚","╝"]:["┌","─","┐","│","└","┘"],o=t.focal?"focal":"name";a(V,r,p+f.repeat(s-2)+u,o),a(W,r,w,o),a(W,r+s-1,w,o),a(W,r+Math.floor((s-c(t.name))/2),t.name,o),a(R,r,E+f.repeat(s-2)+e,o)});const j=[],_=t=>{for(const n of j)a(t,n.l,"│","frame"),a(t,n.r,"│","frame")},H=()=>{const t=d();return v(t),_(t),t};H();for(const t of b){if("band"in t){const e=d(),o=` ${t.band} `;a(e,0,"─".repeat(M),"band"),a(e,Math.max(0,Math.floor((M-c(o))/2)),o,"band"),H();continue}if("open"in t){const e=t.a-1,o=t.b-1,C=j.length*2,g={l:Math.max(0,i[e]-Math.floor(m[e]/2)-1+C),r:Math.min(M-1,i[o]+Math.ceil(m[o]/2)+(o===y&&b.some(I=>"n"in I&&I.from===I.to)?$:0)-C)},A=d();v(A),_(A),a(A,g.l,"┌"+"─".repeat(g.r-g.l-1)+"┐","frame"),a(A,g.l+1,`[${t.open}]`,"op"),a(A,g.l+c(t.open)+4,` ${t.label} `,"label"),j.push(g),H();continue}if("otherwise"in t){const e=j[j.length-1];if(!e)continue;const o=d();v(o),_(o),a(o,e.l,"├"+"┄".repeat(e.r-e.l-1)+"┤","frame"),a(o,e.l+1,"[else]","op"),a(o,e.l+8,` ${t.otherwise} `,"label"),H();continue}if("close"in t){const e=j.pop();if(!e)continue;const o=d();v(o),_(o),a(o,e.l,"└"+"─".repeat(e.r-e.l-1)+"┘","frame"),H();continue}L=t.n;const n=h.byId.get(t.from)?.i??0,r=h.byId.get(t.to)?.i??0,s=`${t.n} ${t.label}`,p=e=>e==="main"?"━":e==="dashed"?"┄":"─",f=(e,o)=>e==="dashed"?o?"▷":"◁":o?"▶":"◀",u=t.kind==="main"?"main":"plain",w=d(),E=d();if(w.n=t.n,E.n=t.n,v(w),_(w),v(E),_(E),n===r){const e=n===y&&l.length>1,o=e?i[n]-4:i[n]+1;a(w,o,e?"┌──":"──┐",u),a(E,o,e?"└─"+f(t.kind,!0):f(t.kind,!1)+"─┘",u);const C=e?o-c(s)-1:i[n]+5;if(a(w,C,s.slice(0,c(String(t.n))),"num"),a(w,C+c(String(t.n))+1,t.label,"label"),t.note){const g=d();v(g),_(g),a(g,e?o-c(t.note)-1:i[n]+5,t.note,"note")}}else{const e=Math.min(i[n],i[r]),o=Math.max(i[n],i[r]),C=i[r]>i[n],g=e+Math.max(2,Math.floor((o-e-c(s))/2));a(w,g-1," ",""),a(w,g,String(t.n),"num"),a(w,g+c(String(t.n))," "+t.label+" ","label");const A=p(t.kind).repeat(Math.max(1,o-e-2));if(a(E,e+1,C?A+f(t.kind,!0):f(t.kind,!1)+A,u),t.note){const I=d();v(I),_(I);const N=e+Math.max(2,Math.floor((o-e-c(t.note))/2));a(I,N-1,` ${t.note} `,"note")}}}return H(),{html:x.map(t=>{const n=t.ch.join("").trimEnd().length;let r="",s="",p=t.ink[0]??"";for(let f=0;f${T(s)}`:T(s),s=""),p=t.ink[f],s+=t.ch[f];return s&&(r+=p?`${T(s)}`:T(s)),t.n?`${r}`:r}).join(` -`),width:Math.max(...x.map(t=>t.ch.join("").trimEnd().length))}}function P(h,l,b){if(matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held")return()=>{};const c=l>1?Math.min(b.step,(b.limit-b.slower)/(l-1)):0,m=[],i=getComputedStyle(h),S=i.getPropertyValue("--basalt-text-secondary").trim(),k=i.getPropertyValue("--basalt-text-tertiary").trim();return h.querySelectorAll("[data-n]").forEach(y=>{const $=Number(y.dataset.n);y.querySelectorAll('[data-ink="label"], [data-ink="main"], [data-ink="plain"]').forEach(M=>{const x=getComputedStyle(M).color,d=M.dataset.ink==="label"?S:k;m.push(M.animate([{color:d},{color:d,offset:.001},{color:x}],{duration:b.slower,delay:($-1)*c,easing:"ease-out",fill:"backwards"}))})}),()=>{for(const y of m)y.finish()}}(function(h){"use strict";h._.diagramText=function(l,b,c){var m=l.querySelector(".diagram-text"),i=m&&m.querySelector(".diagram-text-ink");if(i){l.__transcript||(l.__transcript=i.innerHTML);var S=F(b),k=document.createElement("span");k.textContent=new Array(41).join("─"),m.appendChild(k);var y=k.getBoundingClientRect().width/40;k.remove();var $=getComputedStyle(m),M=m.clientWidth-parseFloat($.paddingLeft)-parseFloat($.paddingRight),x=S.width*y<=M+.5,d=x?S.html:l.__transcript;if(i.innerHTML!==d&&(i.innerHTML=d),m.toggleAttribute("data-art",x),x&&c.motion==="animated"&&!l.__inked){l.__inked=!0;var a=function(q,L){return parseFloat($.getPropertyValue("--basalt-"+q))||L};P(i,b.steps.filter(function(q){return"n"in q}).length,{slower:a("duration-slower",300),step:a("duration-diagram-step",320),limit:a("duration-diagram-limit",5e3)})}}}})(window.Basalt)})(); +(()=>{var B={"&":"&","<":"<",">":">",'"':""","'":"'"},H=u=>u.replace(/[&<>"']/g,h=>B[h]);function z(u){const h=u.nodes,A=u.steps,d=n=>Array.from(n).length,b=h.map(n=>Math.max(8,d(n.name)+4)),r=h.map(()=>0);let _=0;h.forEach((n,t)=>{r[t]=_+Math.floor(b[t]/2),_+=b[t]+4});const S=(n,t,o)=>{const[s,a]=n0)for(let i=a;i0&&S(t-1,t,s+8):S(t,o,s+4)}const M=h.length-1,x=new Map;{let n=0;const t=[],o=(a,f)=>r[a]-Math.floor(b[a]/2)-1+f,s=(a,f)=>r[a]+Math.ceil(b[a]/2)-f;A.forEach((a,f)=>{if("open"in a){t.push({at:f,a:a.a-1,b:a.b-1,inset:n*2,need:d(`[${a.open}]`)+1+d(` ${a.label} `)+2}),n++;return}if("otherwise"in a){const i=t[t.length-1];i&&(i.need=Math.max(i.need,d("[else]")+1+d(` ${a.otherwise} `)+2));return}if("close"in a){n=Math.max(0,n-1);const i=t.pop();if(!i)return;const k=x.get(i.at)??0,m=i.need-(s(i.b,i.inset)-o(i.a,i.inset))-k;if(m>0){if(i.b"n"in n&&n.from===n.to&&(u.byId.get(n.from)?.i??0)===M?d(`${n.n} ${n.label}`)+8:0)),w=(r[M]??0)+Math.ceil((b[M]??8)/2)+W+2+Math.max(0,...x.values()),I=[],p=()=>{const n={ch:Array(w).fill(" "),ink:Array(w).fill("")};return I.push(n),n},l=(n,t,o,s)=>{Array.from(o).forEach((a,f)=>{const i=t+f;i>=0&&iu.bars.some(o=>o.who===h[n].id&&o.from<=t&&o.to>=t);let R=0;const y=n=>h.forEach((t,o)=>l(n,r[o],q(o,R)?"┃":"│",q(o,R)?"working":"life")),D=p(),T=p(),G=p();h.forEach((n,t)=>{const o=r[t]-Math.floor(b[t]/2),s=b[t],[a,f,i,k,m,$]=n.focal?["╔","═","╗","║","╚","╝"]:["┌","─","┐","│","└","┘"],e=n.focal?"focal":"name";l(D,o,a+f.repeat(s-2)+i,e),l(T,o,k,e),l(T,o+s-1,k,e),l(T,o+Math.floor((s-d(n.name))/2),n.name,e),l(G,o,m+f.repeat(s-2)+$,e)});const j=[],v=n=>{for(const t of j)l(n,t.l,"│","frame"),l(n,t.r,"│","frame")},F=()=>{const n=p();return y(n),v(n),n};F();for(const[n,t]of A.entries()){if("band"in t){const e=p(),c=` ${t.band} `;l(e,0,"─".repeat(w),"band"),l(e,Math.max(0,Math.floor((w-d(c))/2)),c,"band"),F();continue}if("open"in t){const e=t.a-1,c=t.b-1,L=j.length*2,g={l:Math.max(0,r[e]-Math.floor(b[e]/2)-1+L),r:Math.min(w-1,r[c]+Math.ceil(b[c]/2)+(c===M&&A.some(C=>"n"in C&&C.from===C.to)?W:0)-L+(x.get(n)??0))},E=p();y(E),v(E),l(E,g.l,"┌"+"─".repeat(g.r-g.l-1)+"┐","frame"),l(E,g.l+1,`[${t.open}]`,"op"),l(E,g.l+d(t.open)+4,` ${t.label} `,"label"),j.push(g),F();continue}if("otherwise"in t){const e=j[j.length-1];if(!e)continue;const c=p();y(c),v(c),l(c,e.l,"├"+"┄".repeat(e.r-e.l-1)+"┤","frame"),l(c,e.l+1,"[else]","op"),l(c,e.l+8,` ${t.otherwise} `,"label"),F();continue}if("close"in t){const e=j.pop();if(!e)continue;const c=p();y(c),v(c),l(c,e.l,"└"+"─".repeat(e.r-e.l-1)+"┘","frame"),F();continue}R=t.n;const o=u.byId.get(t.from)?.i??0,s=u.byId.get(t.to)?.i??0,a=`${t.n} ${t.label}`,f=e=>e==="main"?"━":e==="dashed"?"┄":"─",i=(e,c)=>e==="dashed"?c?"▷":"◁":c?"▶":"◀",k=t.kind==="main"?"main":"plain",m=p(),$=p();if(m.n=t.n,$.n=t.n,y(m),v(m),y($),v($),o===s){const e=o===M&&h.length>1,c=e?r[o]-4:r[o]+1;l(m,c,e?"┌──":"──┐",k),l($,c,e?"└─"+i(t.kind,!0):i(t.kind,!1)+"─┘",k);const L=e?c-d(a)-1:r[o]+5;if(l(m,L,a.slice(0,d(String(t.n))),"num"),l(m,L+d(String(t.n))+1,t.label,"label"),t.note){const g=p();y(g),v(g),l(g,e?c-d(t.note)-1:r[o]+5,t.note,"note")}}else{const e=Math.min(r[o],r[s]),c=Math.max(r[o],r[s]),L=r[s]>r[o],g=e+Math.max(2,Math.floor((c-e-d(a))/2));l(m,g-1," ",""),l(m,g,String(t.n),"num"),l(m,g+d(String(t.n))," "+t.label+" ","label");const E=f(t.kind).repeat(Math.max(1,c-e-2));if(l($,e+1,L?E+i(t.kind,!0):i(t.kind,!1)+E,k),t.note){const C=p();y(C),v(C);const J=e+Math.max(2,Math.floor((c-e-d(t.note))/2));l(C,J-1,` ${t.note} `,"note")}}}return F(),{html:I.map(n=>{const t=n.ch.join("").trimEnd().length;let o="",s="",a=n.ink[0]??"";for(let f=0;f${H(s)}`:H(s),s=""),a=n.ink[f],s+=n.ch[f];return s&&(o+=a?`${H(s)}`:H(s)),n.n?`${o}`:o}).join(` +`),width:Math.max(...I.map(n=>n.ch.join("").trimEnd().length))}}(function(u){"use strict";u._.diagramText=function(h,A,d,b){var r=h.querySelector(".diagram-text"),_=r&&r.querySelector(".diagram-text-ink");if(_){h.__transcript||(h.__transcript=_.innerHTML);var S=z(A),M=document.createElement("span");M.textContent=new Array(41).join("─"),r.appendChild(M);var x=M.getBoundingClientRect().width/40;M.remove();var W=getComputedStyle(r),w=r.clientWidth-parseFloat(W.paddingLeft)-parseFloat(W.paddingRight);b&&b.textWidth&&(b.textWidth(S.width*x+(h.clientWidth-w)+1),w=r.clientWidth-parseFloat(W.paddingLeft)-parseFloat(W.paddingRight));var I=S.width*x<=w+.5,p=I?S.html:h.__transcript;_.innerHTML!==p&&(_.innerHTML=p),r.toggleAttribute("data-art",I)}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.js b/.agent/skills/basalt-html/parts/diagram-zoom.js index ce5053bc..5cf5a444 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.js +++ b/.agent/skills/basalt-html/parts/diagram-zoom.js @@ -1 +1 @@ -(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(l){return[...l.filter(v=>v.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(l){const{stage:e,sizer:v,layer:p,status:k}=l;let u=0,M=0,i=1,n=1,f=!1,d=!1,g=null,h="",w=0;const S=()=>Number.parseFloat(getComputedStyle(v).paddingTop)||0,T=()=>Math.min(n,1),q=t=>Math.min(j,Math.max(T(),t));function o(){if(!u||!M)return 1;const t=S(),r=e.clientWidth-2*t,b=e.clientHeight-2*t;if(r<=0||b<=0)return Math.min(1,J);const H=Math.min(r/u,b/M);return Math.min(J,Math.floor(H*100+1e-6)/100)}function s(){const t=T();return{zoom:i,level:Math.round(i*100),fit:n,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-n)e.clientWidth-2*S()+.5||M*i>e.clientHeight-2*S()+.5)}function A(){clearTimeout(w);const t=`Zoom ${Math.round(i*100)}%`;w=window.setTimeout(()=>{t!==h&&(h=t,k.textContent=t)},l.rest)}function y(){v.style.width=`${u*i}px`,v.style.height=`${M*i}px`,p.style.transform=`scale(${i})`}function I(t){const r=p.getBoundingClientRect();return{x:(t.x-r.left)/i,y:(t.y-r.top)/i}}function z(t,r){const b=p.getBoundingClientRect();e.scrollLeft+=b.left+t.x*i-r.x,e.scrollTop+=b.top+t.y*i-r.y}const m=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function _(t,r=m(),b){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){x();return}const ot=b??I(r);i=H,y(),z(ot,r),x(),A()}function L(t){f=!0;const r=i*100,b=t?G.find(H=>H>r+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,a=()=>{const[t,r]=[...c.values()];return{x:(t.x+r.x)/2,y:(t.y+r.y)/2}},E=()=>{const[t,r]=[...c.values()];return Math.hypot(t.x-r.x,t.y-r.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),c.size===1&&(F={x:t.clientX,y:t.clientY},C=F,O=!1,B=!1),c.size===2&&t.pointerType==="touch")){const r=a();$={d0:E()||1,z0:i,c:I(r)},B=!0,O=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!c.has(t.pointerId)||d)return;if(c.set(t.pointerId,{x:t.clientX,y:t.clientY}),$&&c.size>=2){f=!0;const b=q($.z0*(E()/$.d0)),H=a();Math.abs(b-i)>1e-6&&(i=b,y(),x(),A()),z($.c,H);return}if(c.size!==1||!F||!C)return;const r={x:t.clientX,y:t.clientY};if(!O){if(Math.hypot(r.x-F.x,r.y-F.y)<=V())return;O=!0,B=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=r.x-C.x,e.scrollTop-=r.y-C.y,C=r,t.preventDefault()}function Z(t){if(c.has(t.pointerId)){if(c.delete(t.pointerId),c.size<2&&($=null),c.size===1){const[r]=[...c.values()];C=r,F=r,O=!0;return}c.size===0&&(O=!1,e.removeAttribute("data-dragging"),F=C=null)}}function P(t){B&&(B=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!u||!M)return;const t=f?I(m()):null;n=o(),f?(i=q(i),y(),t&&z(t,m())):(i=n,y()),x()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:K,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:W,state:s,list(t){t!==d&&(t?(g={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),y(),g&&(e.scrollLeft=g.left,e.scrollTop=g.top),g=null),x())},travelled:()=>B,destroy(){clearTimeout(w),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function nt(l,e,v){const p=l.getBoundingClientRect(),k=e.getBoundingClientRect(),u=p.left+v,M=p.left+l.clientWidth-v,i=p.top+v,n=p.top+l.clientHeight-v;k.leftM&&(l.scrollLeft+=Math.min(k.right-M,k.left-u)),k.topn&&(l.scrollTop+=Math.min(k.bottom-n,k.top-i))}function rt(l,e,v,p,k,u,M,i){const{layer:n,memo:f,measureFigure:d}=i;f.model!==e&&(f.model=e,f.least=void 0);const g=x=>{n.style.width=`${Math.max(f.least||x,Math.min(i.avail,i.row))}px`};n.style.width||(n.style.width=`${Math.min(i.avail,i.row)}px`);const h=n.style.transform;n.style.transform="none";const w=n.offsetWidth?n.getBoundingClientRect().width/n.offsetWidth:1,S=Math.abs(w-1)>1e-4?` scale(${1/w})`:"";n.style.transform=S||"none";const T=(l.querySelector(`.${v}-drawing`)??n).getBoundingClientRect(),q=T.left-Math.round(T.left),o=T.top-Math.round(T.top);(q||o)&&(n.style.transform=`translate(${-q/w}px, ${-o/w}px)${S}`);let s=d(l,e,v,p,k,u,f.least===void 0?void 0:M,g);if(s.dyn.layout==="stacked"&&f.least===void 0&&s.least!==void 0){const x=s.dyn,A=m=>{n.style.width=`${m}px`;const _=d(l,e,v,p,x,u);return _.dyn.layout==="drawn"?d(l,e,v,p,_.dyn,u):_},y=Math.max(s.least,Math.min(i.avail,i.row)),I=Math.max(i.row,y)*1.5;let z;for(let m=y+16;m<=I&&z===void 0;m+=16)A(m).dyn.layout==="drawn"&&(z=m);if(z!==void 0){for(let m=z-15;mi.contain&&(n.style.width=`${i.contain}px`,s=d(l,e,v,p,s.dyn,u,M)),n.style.transform=h,s}(function(l){"use strict";var e=l._,v=0;function p(i){return e.diagramKit.escapeHtml(String(i??""))}function k(i){return''+p(i)+""}function u(i,n){return parseFloat(getComputedStyle(i).getPropertyValue(n))||0}function M(i,n,f,d){var g=e.diagramKit,h=Object.assign({},n,{motion:"still"}),w=g.buildModel(h),S="dgv"+ ++v,T=g.figureKey("diagram",w),q=et(g.hintEntries(w,!0)).map(function(a){return""+a.keys.map(k).join(" ")+" "+p(a.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",S+"-summary"),o.innerHTML='

'+p(w.title)+"

"+(n.source?'

'+p(n.source)+"

":"")+'

'+p(n.summary)+'

'+(T?'
'+g.toHtml(T)+"
":"")+'
',document.body.appendChild(o);var s=o.querySelector(".diagram-stage"),x=o.querySelector(".diagram-sizer"),A=o.querySelector(".diagram-layer"),y=A.firstChild,I=o.querySelector('[role="status"]'),z=o.querySelector(".diagram-level > span"),m=o.querySelector(".diagram-viewer-key"),_=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},W=null,K=!1,R=!1,D=function(a,E){E?a.setAttribute("aria-disabled","true"):a.removeAttribute("aria-disabled")},c=at({stage:s,sizer:x,layer:A,status:I,rest:u(s,"--_rest")||300,onChange:function(a){z.textContent=a.level+"%",D(L.out,a.listOpen||a.atMin),D(L.in,a.listOpen||a.atMax),D(L.fit,a.listOpen||a.atFit)}}),F={},C={layer:A,avail:0,row:1104,contain:480,memo:F,measureFigure:g.measureFigure,keys:tt,room:function(){var a=parseFloat(getComputedStyle(x).paddingTop)||0;return{w:s.clientWidth-2*a,h:s.clientHeight-2*a}},measure:function(a,E,Y,N,Z,P,X){return rt(a,E,Y,N,Z,P,X,C)},onMeasured:function(a,E){s.setAttribute("data-layout",a.dyn.layout||""),m&&(m.setAttribute("data-layout",a.dyn.layout||""),m.toggleAttribute("data-bare",!!a.dyn.bare)),R=!!a.dyn.bare,_.hidden=R,B(K||R),c.size(E.offsetWidth,E.offsetHeight)}};function O(){C.avail=Math.max(0,Math.floor(s.clientWidth-2*(parseFloat(getComputedStyle(x).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function B(a){a&&!W&&(W=document.createElement("div"),W.className="diagram-list diagram-viewer-list",W.innerHTML=g.figureList("diagram",w).map(function(E){return g.toHtml(E)}).join(""),s.appendChild(W)),a&&c.list(!0),W&&(W.hidden=!a),x.hidden=a,a||c.list(!1)}_.addEventListener("click",function(){K=!K,_.setAttribute("aria-expanded",String(K)),_.firstElementChild.textContent=K?"Hide the list":"View as list",B(K||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||c.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||c.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||c.fit()}),s.addEventListener("focusin",function(a){var E=a.target.closest&&a.target.closest(".diagram-node");E&&s.contains(E)&&nt(s,E,u(s,"--_clear")||16)}),n.export===!0&&typeof e.diagramExport=="function"&&e.diagramExport(o.querySelector(".diagram-viewer-end"),y),l.openDialog(o,d),O(),g.draw(y,h,!1,C),setTimeout(function(){s.focus({preventScroll:!0})},0);var $=s.clientWidth,V=new ResizeObserver(function(){Math.abs(s.clientWidth-$)<.5||($=s.clientWidth,O(),y.__diagram&&y.__diagram.layout())});V.observe(s),o.addEventListener("transitionend",function(a){a.target===o&&a.propertyName==="transform"&&o.open&&y.__diagram&&y.__diagram.layout()}),i.setAttribute("data-viewing",""),f.animated&&f.settle(),o.addEventListener("close",function(){V.disconnect(),c.destroy(),y.__diagram&&y.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},u(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,n,f){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var g=d.querySelector(".diagram-expand");g&&g.remove();var h=document.createElement("button");h.type="button",h.className="btn diagram-expand",h.setAttribute("data-variant","secondary"),h.setAttribute("data-size","sm"),h.setAttribute("aria-haspopup","dialog"),h.innerHTML="Expand";var w=d.querySelector(".diagram-toggle");w&&w.nextSibling?d.insertBefore(h,w.nextSibling):d.appendChild(h);var S=function(){M(i,n,f,h)};return h.addEventListener("click",S),{destroy:function(){h.removeEventListener("click",S),h.remove()}}}})(window.Basalt)})(); +(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(s){return[...s.filter(g=>g.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(s){const{stage:e,sizer:g,layer:m,status:k}=s;let f=0,M=0,i=1,r=1,c=!1,d=!1,h=null,y="",z=0;const T=()=>Number.parseFloat(getComputedStyle(g).paddingTop)||0,A=()=>Math.min(r,1),q=t=>Math.min(j,Math.max(A(),t));function o(){if(!f||!M)return 1;const t=T(),n=e.clientWidth-2*t,x=e.clientHeight-2*t;if(n<=0||x<=0)return Math.min(1,J);const H=Math.min(n/f,x/M);return Math.min(J,Math.floor(H*100+1e-6)/100)}function l(){const t=A();return{zoom:i,level:Math.round(i*100),fit:r,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-r)e.clientWidth-2*T()+.5||M*i>e.clientHeight-2*T()+.5)}function S(){clearTimeout(z);const t=`Zoom ${Math.round(i*100)}%`;z=window.setTimeout(()=>{t!==y&&(y=t,k.textContent=t)},s.rest)}function v(){g.style.width=`${f*i}px`,g.style.height=`${M*i}px`,m.style.transform=`scale(${i})`}function K(t){const n=m.getBoundingClientRect();return{x:(t.x-n.left)/i,y:(t.y-n.top)/i}}function E(t,n){const x=m.getBoundingClientRect();e.scrollLeft+=x.left+t.x*i-n.x,e.scrollTop+=x.top+t.y*i-n.y}const p=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function W(t,n=p(),x){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){w();return}const st=x??K(n);i=H,v(),E(st,n),w(),S()}function L(t){c=!0;const n=i*100,x=t?G.find(H=>H>n+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,a=()=>{const[t,n]=[...u.values()];return{x:(t.x+n.x)/2,y:(t.y+n.y)/2}},b=()=>{const[t,n]=[...u.values()];return Math.hypot(t.x-n.x,t.y-n.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(u.set(t.pointerId,{x:t.clientX,y:t.clientY}),u.size===1&&(F={x:t.clientX,y:t.clientY},C=F,O=!1,$=!1),u.size===2&&t.pointerType==="touch")){const n=a();B={d0:b()||1,z0:i,c:K(n)},$=!0,O=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!u.has(t.pointerId)||d)return;if(u.set(t.pointerId,{x:t.clientX,y:t.clientY}),B&&u.size>=2){c=!0;const x=q(B.z0*(b()/B.d0)),H=a();Math.abs(x-i)>1e-6&&(i=x,v(),w(),S()),E(B.c,H);return}if(u.size!==1||!F||!C)return;const n={x:t.clientX,y:t.clientY};if(!O){if(Math.hypot(n.x-F.x,n.y-F.y)<=V())return;O=!0,$=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=n.x-C.x,e.scrollTop-=n.y-C.y,C=n,t.preventDefault()}function Z(t){if(u.has(t.pointerId)){if(u.delete(t.pointerId),u.size<2&&(B=null),u.size===1){const[n]=[...u.values()];C=n,F=n,O=!0;return}u.size===0&&(O=!1,e.removeAttribute("data-dragging"),F=C=null)}}function P(t){$&&($=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!f||!M)return;const t=c?K(p()):null;r=o(),c?(i=q(i),v(),t&&E(t,p())):(i=r,v()),w()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:I,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:_,state:l,list(t){t!==d&&(t?(h={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),v(),h&&(e.scrollLeft=h.left,e.scrollTop=h.top),h=null),w())},travelled:()=>$,destroy(){clearTimeout(z),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function rt(s,e,g){const m=s.getBoundingClientRect(),k=e.getBoundingClientRect(),f=m.left+g,M=m.left+s.clientWidth-g,i=m.top+g,r=m.top+s.clientHeight-g;k.leftM&&(s.scrollLeft+=Math.min(k.right-M,k.left-f)),k.topr&&(s.scrollTop+=Math.min(k.bottom-r,k.top-i))}function nt(s,e){s.memo.art=Math.ceil(e),s.layer.style.width=`${s.memo.art}px`}function ot(s,e,g,m,k,f,M,i){const{layer:r,memo:c,measureFigure:d}=i;if(c.model!==e&&(c.model=e,c.least=void 0,c.art=void 0),e.text){r.style.width=`${c.art??Math.min(i.avail,i.row)}px`;const w=r.style.transform;r.style.transform="none";const S=d(s,e,g,m,k,f,M);return r.style.transform=w,S}const h=w=>{r.style.width=`${Math.max(c.least||w,Math.min(i.avail,i.row))}px`};r.style.width||(r.style.width=`${Math.min(i.avail,i.row)}px`);const y=r.style.transform;r.style.transform="none";const z=r.offsetWidth?r.getBoundingClientRect().width/r.offsetWidth:1,T=Math.abs(z-1)>1e-4?` scale(${1/z})`:"";r.style.transform=T||"none";const A=(s.querySelector(`.${g}-drawing`)??r).getBoundingClientRect(),q=A.left-Math.round(A.left),o=A.top-Math.round(A.top);(q||o)&&(r.style.transform=`translate(${-q/z}px, ${-o/z}px)${T}`);let l=d(s,e,g,m,k,f,c.least===void 0?void 0:M,h);if(l.dyn.layout==="stacked"&&c.least===void 0&&l.least!==void 0){const w=l.dyn,S=p=>{r.style.width=`${p}px`;const W=d(s,e,g,m,w,f);return W.dyn.layout==="drawn"?d(s,e,g,m,W.dyn,f):W},v=Math.max(l.least,Math.min(i.avail,i.row)),K=Math.max(i.row,v)*1.5;let E;for(let p=v+16;p<=K&&E===void 0;p+=16)S(p).dyn.layout==="drawn"&&(E=p);if(E!==void 0){for(let p=E-15;pi.contain&&(r.style.width=`${i.contain}px`,l=d(s,e,g,m,l.dyn,f,M)),r.style.transform=y,l}(function(s){"use strict";var e=s._,g=0;function m(i){return e.diagramKit.escapeHtml(String(i??""))}function k(i){return''+m(i)+""}function f(i,r){return parseFloat(getComputedStyle(i).getPropertyValue(r))||0}function M(i,r,c,d){var h=e.diagramKit,y=Object.assign({},r,{motion:"still"}),z=h.buildModel(y),T="dgv"+ ++g,A=h.figureKey("diagram",z),q=et(h.hintEntries(z,!0)).map(function(a){return""+a.keys.map(k).join(" ")+" "+m(a.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",T+"-summary"),o.innerHTML='

'+m(z.title)+"

"+(r.source?'

'+m(r.source)+"

":"")+'

'+m(r.summary)+'

'+(A?'
'+h.toHtml(A)+"
":"")+'
',document.body.appendChild(o);var l=o.querySelector(".diagram-stage"),w=o.querySelector(".diagram-sizer"),S=o.querySelector(".diagram-layer"),v=S.firstChild,K=o.querySelector('[role="status"]'),E=o.querySelector(".diagram-level > span"),p=o.querySelector(".diagram-viewer-key"),W=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},_=null,I=!1,R=!1,D=function(a,b){b?a.setAttribute("aria-disabled","true"):a.removeAttribute("aria-disabled")},u=at({stage:l,sizer:w,layer:S,status:K,rest:f(l,"--_rest")||300,onChange:function(a){E.textContent=a.level+"%",D(L.out,a.listOpen||a.atMin),D(L.in,a.listOpen||a.atMax),D(L.fit,a.listOpen||a.atFit)}}),F={},C={layer:S,avail:0,row:1104,contain:480,memo:F,measureFigure:h.measureFigure,keys:tt,room:function(){var a=parseFloat(getComputedStyle(w).paddingTop)||0;return{w:l.clientWidth-2*a,h:l.clientHeight-2*a}},measure:function(a,b,Y,N,Z,P,X){return ot(a,b,Y,N,Z,P,X,C)},textWidth:function(a){nt(C,a)},onMeasured:function(a,b){l.setAttribute("data-layout",a.dyn.layout||""),p&&(p.setAttribute("data-layout",a.dyn.layout||""),p.toggleAttribute("data-bare",!!a.dyn.bare)),R=!!a.dyn.bare,W.hidden=R,$(I||R),u.size(b.offsetWidth,b.offsetHeight)}};function O(){C.avail=Math.max(0,Math.floor(l.clientWidth-2*(parseFloat(getComputedStyle(w).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function $(a){a&&!_&&(_=document.createElement("div"),_.className="diagram-list diagram-viewer-list",_.innerHTML=h.figureList("diagram",z).map(function(b){return h.toHtml(b)}).join(""),l.appendChild(_)),a&&u.list(!0),_&&(_.hidden=!a),w.hidden=a,a||u.list(!1)}W.addEventListener("click",function(){I=!I,W.setAttribute("aria-expanded",String(I)),W.firstElementChild.textContent=I?"Hide the list":"View as list",$(I||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||u.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||u.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||u.fit()}),o.addEventListener("click",function(a){var b=a.target.closest&&a.target.closest("a.diagram-node[href]");!b||!o.contains(b)||a.defaultPrevented||a.button!==0||a.metaKey||a.ctrlKey||a.shiftKey||a.altKey||b.target&&b.target!=="_self"||o.open&&o.close()}),l.addEventListener("focusin",function(a){var b=a.target.closest&&a.target.closest(".diagram-node");b&&l.contains(b)&&rt(l,b,f(l,"--_clear")||16)}),r.export===!0&&typeof e.diagramExport=="function"&&e.diagramExport(o.querySelector(".diagram-viewer-end"),v),s.openDialog(o,d),O(),h.draw(v,y,!1,C),setTimeout(function(){l.focus({preventScroll:!0})},0);var B=l.clientWidth,V=new ResizeObserver(function(){Math.abs(l.clientWidth-B)<.5||(B=l.clientWidth,O(),v.__diagram&&v.__diagram.layout())});V.observe(l),o.addEventListener("transitionend",function(a){a.target===o&&a.propertyName==="transform"&&o.open&&v.__diagram&&v.__diagram.layout()}),i.setAttribute("data-viewing",""),c.animated&&c.settle(),o.addEventListener("close",function(){V.disconnect(),u.destroy(),v.__diagram&&v.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},f(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,r,c){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var h=d.querySelector(".diagram-expand");h&&h.remove();var y=document.createElement("button");y.type="button",y.className="btn diagram-expand",y.setAttribute("data-variant","secondary"),y.setAttribute("data-size","sm"),y.setAttribute("aria-haspopup","dialog"),y.innerHTML="Expand";var z=d.querySelector(".diagram-toggle");z&&z.nextSibling?d.insertBefore(y,z.nextSibling):d.appendChild(y);var T=function(){M(i,r,c,y)};return y.addEventListener("click",T),{destroy:function(){y.removeEventListener("click",T),y.remove()}}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index 544c37a9..69ce8bdd 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--_gw, var(--basalt-space-10))}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);--_Rows: var(--_D) var(--_rows, none);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));grid-template-rows:var(--_Rows, none);gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=schema][data-marks]>.diagram-drawing{--_col-gap: calc(var(--basalt-space-12) + var(--basalt-space-3))}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node{--_Mh: var(--_D) var(--_mh, auto);min-height:var(--_Mh, auto)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-crow{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:butt;stroke-linejoin:miter;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-ring{fill:var(--_ground);stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;gap:var(--basalt-space-1);flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_fl);width:var(--_fw);height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-crow,.diagram-ring,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"]:not([data-marks]))>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 792px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 1076px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1360px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1644px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram :is(.diagram-crow,.diagram-ring){stroke:CanvasText}.diagram .diagram-ring{fill:Canvas}.diagram .diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:GrayText}.diagram .diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--_gw, var(--basalt-space-10))}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);--_Rows: var(--_D) var(--_rows, none);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));grid-template-rows:var(--_Rows, none);gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=schema][data-marks]>.diagram-drawing{--_col-gap: calc(var(--basalt-space-12) + var(--basalt-space-3))}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] .diagram-group>.diagram-glabel{inset-inline:auto var(--basalt-space-3);margin-inline:0 calc(-1 * var(--basalt-space-1-5))}.diagram[data-rtl] .diagram-runs{direction:ltr;unicode-bidi:isolate}.diagram[data-rtl] .diagram-fhead{inset-inline-start:calc(100% - var(--_fl) - var(--_fw) + var(--basalt-size-hairline))}.diagram[data-rtl] .diagram-felse{padding-inline-start:calc(100% - var(--_fl) - var(--_fw) + var(--basalt-space-3))}.diagram[data-rtl] .diagram-felse:before{inset-inline-start:var(--_Fer, calc(-1 * var(--basalt-space-4)))}.diagram[data-rtl] .diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) left;margin-inline-start:0;margin-inline-end:var(--_Sm, 0)}.diagram[data-rtl] .diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) right;margin-inline-end:0;margin-inline-start:var(--_Sm, 0)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node{--_Mh: var(--_D) var(--_mh, auto);min-height:var(--_Mh, auto)}.diagram-node{--_Jc: var(--_D) normal;justify-content:var(--_Jc, center)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group[data-turn]{padding-block-start:calc(var(--basalt-space-8) + var(--basalt-space-4))}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram[data-type=sequence]>.diagram-drawing>.diagram-ink{z-index:auto}.diagram-lifes{position:absolute;top:0;left:0;z-index:0;overflow:visible}.diagram[data-type=sequence] .diagram-ink>.diagram-svg{z-index:2}.diagram[data-type=sequence] .diagram-steps{z-index:auto}.diagram[data-type=sequence] .diagram-msg :is(.diagram-said,.diagram-note){position:relative;z-index:3}.diagram[data-type=sequence] :is(.diagram-fhead,.diagram-felse){z-index:3}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-crow{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:butt;stroke-linejoin:miter;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-ring{fill:var(--_ground);stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-frame+.diagram-msgs>.diagram-msg:first-child{border-top-color:transparent}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;column-gap:var(--basalt-space-1);row-gap:0;flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-to{display:inline-flex;align-items:center;gap:var(--basalt-space-1);white-space:nowrap}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);--_Fel: var(--_D) var(--_fl);--_Few: var(--_D) var(--_fw);--_Fer: var(--_D) calc(100% - var(--_fl) - var(--_fw));position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_Fel, calc(-1 * var(--basalt-space-4)));width:var(--_Few, calc(100% + 2 * var(--basalt-space-4)));height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-tx-line{display:block;padding-inline-start:calc(var(--_in, 0) * 1ch);text-indent:calc(-1 * var(--_hang, 0) * 1ch)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}.diagram-key-glyph[data-ink=focal]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-crow,.diagram-ring,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"]:not([data-marks]))>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 792px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 1076px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1360px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1644px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-lifes,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram :is(.diagram-crow,.diagram-ring){stroke:CanvasText}.diagram .diagram-ring{fill:Canvas}.diagram .diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:GrayText}.diagram .diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-lifes,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear,.diagram-download{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-text [data-n][data-ahead] [data-ink=label],.diagram[data-motion=animated][data-entrance=pending] .diagram-text [data-n] [data-ink=label]{color:var(--basalt-text-secondary)}.diagram-text [data-n][data-ahead] :is([data-ink=main],[data-ink=plain]),.diagram[data-motion=animated][data-entrance=pending] .diagram-text [data-n] :is([data-ink=main],[data-ink=plain]){color:var(--basalt-text-tertiary)}.diagram-text [data-n][data-arrival] [data-ink=num]{color:var(--basalt-text-primary)}@media(prefers-reduced-motion:reduce){.diagram-msg[data-ahead] .diagram-mlabel{transition:none}}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:GrayText}.diagram .diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-text [data-n][data-ahead] [data-ink]{color:GrayText}.diagram .diagram-text [data-n][data-arrival] [data-ink=num]{color:Highlight}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 904c12f5..10052fde 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,12 +1,6 @@ -(()=>{var on=["top","right","bottom","left"],sn=["main","plain","dashed"],pe=["one","zero-or-one","one-or-many","zero-or-many"],Ft={one:"Exactly one","zero-or-one":"Zero or one","one-or-many":"One or many","zero-or-many":"Zero or many"},an=[2,3,4,5,6],gt=t=>t==null||t===""?void 0:String(t),At=t=>Object.assign(Object.create(null),t),qt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function zt(t,e={}){const o=e.checks!==!1,l=[],a=m=>{l.push(m)},s=t.legend??{},r={};for(const m of["main","plain","dashed","focal","group","activation"]){const y=gt(s[m]);y&&(r[m]=y)}const i=t.stepLabel,d=typeof i=="function"?m=>String(i(m)):typeof i=="string"?(m=>i.replace("{n}",String(m))):m=>`Step ${m}`,h=t.shapeLabels??{},f={terminal:gt(h.terminal)??"Start or end",step:gt(h.step)??"Step",decision:gt(h.decision)??"Decision"},c=t.heading===void 0?3:an.includes(t.heading)?t.heading:(a(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),g=(m,y)=>m==null?"plain":sn.includes(m)?m:(a(`"${String(m)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),$=m=>{if(m!=null){if(on.includes(m))return m;a(`"${String(m)}" is not a side (top, right, bottom or left): the derived side is used`)}},p=(m,y)=>typeof m=="number"&&Number.isInteger(m)&&m>=1?m:(t.layout==="auto"&&m==null||a(`${y} is ${JSON.stringify(m)}, not a whole number from 1: it is placed at 1`),1),u=[],x=[];let C=[];const W=[],v=[],S=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(S)||a(`"${String(S)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),S==="architecture"||S==="flowchart"){for(const m of t.nodes??[]){const y=S==="flowchart"&&m.shape==="decision"?"decision":S==="flowchart"&&m.shape==="terminal"?"terminal":"box",E=String(m.id??""),q=p(m.row,`the row of ${E}`);u.push({id:E,i:u.length,name:String(m.name??""),kind:y==="decision"?void 0:gt(m.kind),detail:y==="decision"?void 0:gt(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:p(m.col,`the column of ${E}`),row:q,row2:q,branch:!!m.branch,shape:y,group:S==="architecture"?gt(m.group):void 0,mark:S==="architecture"?ee(m.mark):void 0})}if(S==="architecture"){const m=(t.groups??[]).map(_=>({id:String(_.id??""),label:String(_.label??""),parent:gt(_.parent)})),y=new Map(m.map(_=>[_.id,_])),E=_=>{if(!_.parent)return 1;const R=y.get(_.parent);return R?R.parent===_.id||R.id===_.id?(a(`the groups "${_.label}" and "${R.label}" are each other's parent`),_.parent=void 0,1):R.parent?(a(`the group "${_.label}" is a third level: groups nest two deep`),_.parent=void 0,1):2:(a(`the group "${_.label}" names the parent "${_.parent}", which is not a group`),_.parent=void 0,1)},q=m.map(E);m.forEach((_,R)=>W.push({..._,depth:q[R],members:u.filter(U=>U.group===_.id).map(U=>U.id),all:[]}));for(const _ of W)_.all=[..._.members,...W.filter(R=>R.parent===_.id).flatMap(R=>R.members)];W.sort((_,R)=>_.depth-R.depth)}}else if(S==="data-flow"){C=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const m=new Map(C.map((y,E)=>[y.id,E+1]));for(const y of t.nodes??[]){const E=String(y.id??""),q=String(y.lane??""),_=m.get(q);_===void 0&&a(`a node (${E}) names the lane "${q}", which is not in lanes`);const R=u.length+1;u.push({id:E,i:u.length,name:String(y.name??""),kind:d(R),detail:gt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:p(y.col,`the column of ${E}`),row:_??1,row2:_??1,branch:!1,shape:"box",lane:_??1,laneLabel:C[(_??1)-1]?.label??q,step:R,mark:ee(y.mark)})}}else if(S==="sequence"){(t.participants??[]).forEach((q,_)=>{const R=String(q.name??"");u.push({id:String(q.id??""),i:_,name:R,kind:gt(q.kind),mono:!1,focal:!!q.focal,col:_+1,row:1,row2:1,branch:!1,shape:"participant",short:gt(q.short)??R,mark:ee(q.mark)})});let m=0;const y=new Map(u.map(q=>[q.id,q.col])),E=(q,_)=>{let R=1/0,U=-1/0;for(const G of q??[]){if(!G||typeof G!="object")continue;if("band"in G){_>0&&a(`the band "${String(G.band)}" is inside a frame: a band is the whole figure's`),v.push({band:String(G.band??"")});continue}if("frame"in G){if(_>=2){a("a frame is a third level: frames nest two deep");continue}const Mt=G.frame==="alt"||G.frame==="loop"||G.frame==="opt"?G.frame:"opt",vt=Mt==="alt"?G.branches??[]:[{label:G.label,steps:G.steps}];Mt==="alt"&&vt.length<2&&a("an alt frame has one branch: it needs two or more");const ut=String(vt[0]?.label??"");ut.length>40&&a(`the frame label "${ut}" is over 40 characters`);const ft=v.length;v.push({open:Mt,label:ut,depth:_+1,a:0,b:0}),vt.forEach((it,bt)=>{if(bt){const k=String(it.label??"");k.length>40&&a(`the frame label "${k}" is over 40 characters`),v.push({otherwise:k,depth:_+1})}it.steps?.length||a(`a frame or branch ("${String(it.label??"")}") is empty`);const[b,A]=E(it.steps??[],_+1);R=Math.min(R,b),U=Math.max(U,A);const L=v[ft];L.a=Math.min(L.a||1/0,b),L.b=Math.max(L.b,A)}),v.push({close:_+1});continue}m++;const ht=String(G.label??"");ht.includes(` -`)&&a(`message ${m}'s label has a break: a message's second line is its note`);const pt=String(G.from??""),lt=String(G.to??"");v.push({n:m,from:pt,to:lt,label:Lt(ht),note:gt(G.note),kind:g(G.kind,`message ${m}`),activate:G.activate===!0||void 0,deactivate:G.deactivate===!0||void 0});const ct=y.get(pt)??1,mt=y.get(lt)??1,wt=ct===mt?ct===u.length?ct-1:ct+1:ct;R=Math.min(R,ct,mt,wt),U=Math.max(U,ct,mt,wt)}return[R,U]};E(t.steps??[],0);for(const q of v)"open"in q&&!Number.isFinite(q.a)&&(q.a=1,q.b=Math.max(1,u.length))}else if(S==="schema")for(const m of t.tables??[]){const y=String(m.name??""),[E,q]=Array.isArray(m.row)?m.row:[m.row,m.row],_=p(E,`the row of ${y}`),R=Math.max(_,p(q,`the last row of ${y}`)),U=m.more===void 0||m.more===null?void 0:Number.isInteger(m.more)&&m.more>0?m.more:(a(`${y}'s "more" is ${JSON.stringify(m.more)}, not a whole number from 1: it is left out`),void 0);u.push({id:y,i:u.length,name:y,mono:!0,focal:!!m.focal,col:p(m.col,`the column of ${y}`),row:_,row2:R,branch:!1,shape:"table",more:U,columns:(m.columns??[]).map(G=>({name:String(G.name??""),type:gt(G.type),key:G.key==="PK"||G.key==="FK"?G.key:(G.key!==void 0&&G.key!==null&&a(`${y}.${String(G.name)}'s key is "${String(G.key)}", not PK or FK: it is left out`),void 0)}))})}let T=!1;if(t.layout==="auto"&&(S==="architecture"||S==="flowchart"||S==="schema")){const m=S==="schema"?t.tables:t.nodes;o&&(m??[]).some(E=>E&&(E.col!==void 0||E.row!==void 0))&&a('a card under layout="auto" has a col or row, which is not read: there are no hints');const y=e.placement?.cells;y||(T=!0);for(const E of u){const q=y?.[E.id];E.col=q?.col??1,E.row=E.row2=q?.row??1}}else t.layout==="auto"&&a(`layout="auto" is for an architecture, a flowchart or a schema, not a ${S}`);((S==="schema"?t.tables:S==="sequence"?t.participants:t.nodes)??[]).forEach((m,y)=>{if(!m||m.href===void 0||m.href===null)return;const E=String(m.href);if(S==="sequence"){a(`${u[y]?.id}: a participant cannot be a link (href)`);return}if(!E){a(`${u[y]?.id}'s href is empty`);return}const q=u[y];q&&(q.href=E,q.blank=m.target==="_blank")});const z=new Map;for(const m of u)m.id?z.has(m.id)&&a(`the id "${m.id}" is used twice`):a("a node has no id"),z.set(m.id,m);if(S==="schema"){const m=(E,q)=>{if(E==null)return;const _=E,R=pe.includes(_.from)?_.from:void 0;if(!R){a(`${q}'s cardinality "from" is ${JSON.stringify(_.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`);return}return _.to===void 0||_.to===null?{from:R,to:"one"}:_.to==="one"||_.to==="zero-or-one"?{from:R,to:_.to}:(a(`${q}'s cardinality "to" is ${JSON.stringify(_.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`),{from:R,to:"one"})};(t.tables??[]).forEach(E=>(E.columns??[]).forEach((q,_)=>{const R=gt(q.references);if(!R&&q.cardinality!==void 0&&q.cardinality!==null&&a(`${String(E.name)}.${String(q.name)} states a cardinality but references nothing`),!R)return;const[U,G]=R.split("."),ht=z.get(U??""),pt=ht?.columns?.findIndex(mt=>mt.name===G)??-1;if(!ht||pt<0){a(`${String(E.name)}.${String(q.name)} references ${R}, which is not a shown column`);return}const lt=z.get(String(E.name??""));lt.columns[_].ref={table:U,column:G,row:pt};const ct=m(q.cardinality,`${String(E.name)}.${String(q.name)}`);ct&&(lt.columns[_].card=ct),x.push({i:x.length,from:lt.id,to:U,kind:"plain",fromRow:_,toRow:pt,fk:!0,card:ct})}));const y=x.filter(E=>E.card).length;y&&y!E.card).map(E=>`${E.from}.${z.get(E.from).columns[E.fromRow].name}`).join(", ")} ${x.length-y===1?"has":"have"} none)`)}else if(S!=="sequence")for(const m of t.edges??[]){const y=String(m.from??""),E=String(m.to??"");if(!z.has(y)||!z.has(E)){a(`a line names ${z.has(y)?E:y}, which is not a node`);continue}const q=gt(m.label),_=q?.split(` -`)??[];_.length>2&&a(`the label "${Lt(q)}" has more than one break: a label is two lines at most`),_.some(R=>R.length>me)&&a(`a line of the label "${Lt(q)}" is over ${me} characters: longer words belong in the node or the summary`),x.push({i:x.length,from:y,to:E,kind:g(m.kind,`the line from ${y} to ${E}`),label:q,fromSide:$(m.fromSide),toSide:$(m.toSide),flow:S!=="flowchart"&&m.flow===!0?!0:void 0})}else for(const m of v)"n"in m&&(!z.has(m.from)||!z.has(m.to))&&a(`message ${m.n} names ${z.has(m.from)?m.to:m.from}, which is not a participant`);if(o&&S!=="sequence"&&!T){const m=new Map;for(const y of u)for(let E=y.row;E<=y.row2;E++){const q=`${y.col}:${E}`;m.has(q)&&a(`${y.id} and ${m.get(q)} share the cell at column ${y.col}, row ${E}`),m.set(q,y.id)}}if(o&&!T){for(const y of W){const E=y.all.map(R=>z.get(R));if(!E.length)continue;const q={c1:Math.min(...E.map(R=>R.col)),c2:Math.max(...E.map(R=>R.col)),r1:Math.min(...E.map(R=>R.row)),r2:Math.max(...E.map(R=>R.row2))};for(const R of u)!y.all.includes(R.id)&&R.col>=q.c1&&R.col<=q.c2&&R.row>=q.r1&&R.row<=q.r2&&a(`${R.id} is inside the box of the group "${y.label}" but not a member`);const _=E.map(R=>R.i);Math.max(..._)-Math.min(..._)+1!==_.length&&a(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of u)y.group&&!W.some(E=>E.id===y.group)&&a(`${y.id} names the group "${y.group}", which is not in groups`);u.filter(y=>y.focal).length>1&&a("more than one node is focal: a diagram has one at most");const m=new Set(S==="sequence"?v.flatMap(y=>"n"in y?[y.kind]:[]):x.map(y=>y.kind));m.has("main")&&!r.main&&a("main lines are drawn but the legend has no words for them (legend.main)"),m.has("dashed")&&!r.dashed&&a("dashed lines are drawn but the legend has no words for them (legend.dashed)"),u.some(y=>y.focal)&&!r.focal&&a("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const rt=S==="architecture"||S==="data-flow",I=m=>Array.isArray(m)&&m.length>1?m.map(String):void 0,D=rt&&t.packet&&typeof t.packet=="object"?t.packet:void 0,j=D&&I(D.path),M={animated:t.motion==="animated",pulse:rt?I(t.pulse):void 0,packet:j?{path:j,repeat:D.repeat===!0,send:D.send}:void 0,run:S==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(o)for(const m of u){const y=m.mark?.says;if(!y?.length)continue;const E=[m.name,m.kind,m.detail,m.laneLabel].filter(Boolean).join(" ").toLowerCase();y.some(q=>E.includes(q.toLowerCase()))||a(`${m.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const B=[];if(S==="sequence"){const m=new Map,y=new Map;for(const E of v)"n"in E&&(y.set(E.from,E.n),y.set(E.to,E.n));for(const E of v)if("n"in E){if(E.activate){const q=m.get(E.to)??[];if(q.length>=3)a(`message ${E.n} opens a fourth bar on ${E.to}: three deep at most`);else{const _={who:E.to,from:E.n,to:E.n,depth:q.length+1};q.push(_),B.push(_),m.set(E.to,q)}}if(E.deactivate){const _=m.get(E.from)?.pop();_?_.to=E.n:a(`message ${E.n} closes a bar on ${E.from}, which has none open`)}}for(const[E,q]of m)for(const _ of q)_.to=Math.max(_.from,y.get(E)??_.from)}const H=t.frameLabels??{},Z={opt:gt(H.opt)??"Only if",loop:gt(H.loop)??"Repeats",alt:gt(H.alt)??"One of these",else:gt(H.else)??"Otherwise"},K=t.layout==="auto"&&!T?e.placement:void 0;let ot=Math.max(1,K?.cols??1,...u.map(m=>m.col));if(e.rtl){for(const y of u)y.col=ot-y.col+1;const m=y=>y==="left"?"right":y==="right"?"left":y;for(const y of x)y.fromSide=m(y.fromSide),y.toSide=m(y.toSide);for(const y of v)if("open"in y){const[E,q]=[ot-y.b+1,ot-y.a+1];y.a=E,y.b=q}ot=Math.max(1,...u.map(y=>y.col))}const P=S==="data-flow"?Math.max(1,C.length):Math.max(1,K?.rows??1,...u.map(m=>m.row2)),J={type:S,title:String(t.title??""),heading:c,legend:r,nodes:u,byId:z,edges:x,groups:W,lanes:C,steps:v,bars:B,frameWords:Z,cols:ot,rows:P,shapeLabels:f,stepWord:d,warnings:l,motion:M,memo:new Map,rtl:e.rtl||void 0,unplaced:T||void 0,text:S==="sequence"&&t.variant==="text"||void 0,marks:x.some(m=>m.card)||void 0};if(t.layout==="auto"&&!T&&S!=="schema"&&rn(J),o)for(const[m,y]of Object.entries(Te(J)))y>=48&&a(`${m} grows to ${y}px to hold the lines on one side: use another side`);return o&&u.length>1&&!Zt(J)&&a("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),J}function rn(t){const e=new Set(t.nodes.map(r=>`${r.col},${r.row}`)),n=(r,i)=>{const d=[];for(let h=Math.min(r,i)+1;h{const i=t.byId.get(r.from),d=t.byId.get(r.to),h=d.col>i.col?"right":"left",f=d.row>i.row?"bottom":"top",c=d.col>i.col?"left":"right",g=d.row>i.row?"top":"bottom",$=(x,C,W,v)=>n(x,C).map(S=>v?[S,W]:[W,S]);let p;const u=x=>(x==="right"?i.col1:x==="bottom"?i.row1)?[{sides:[x,x],cells:[]}]:[];return i.row===d.row?p=[{sides:[h,c],cells:$(i.col,d.col,i.row,!0)},...u("bottom"),...u("top")]:i.col===d.col?p=[{sides:[f,g],cells:$(i.row,d.row,i.col,!1)},...u("right"),...u("left")]:p=[{sides:[h,g],cells:[...$(i.col,d.col,i.row,!0),[d.col,i.row],...$(i.row,d.row,d.col,!1)]},{sides:[f,c],cells:[...$(i.row,d.row,i.col,!1),[i.col,d.row],...$(i.col,d.col,d.row,!0)]},{sides:[h,c],cells:$(i.col,d.col,i.row,!0)},{sides:[f,g],cells:$(i.row,d.row,i.col,!1)}],p.filter(x=>x.cells.every(([C,W])=>!e.has(`${C},${W}`)))},l=new Map,a=new Set;for(const r of t.edges)if(r.fromSide||r.toSide){const[i,d]=ce(t.byId.get(r.from),t.byId.get(r.to)),h=r.fromSide??i,f=r.toSide??d;a.add(`${r.from}.${h}`);for(const[c,g]of[[r.from,h],[r.to,f]])l.set(`${c}.${g}`,(l.get(`${c}.${g}`)??0)+1)}const s=t.edges.map((r,i)=>i).sort((r,i)=>o(t.edges[r]).length-o(t.edges[i]).length||+(t.edges[i].kind==="main")-+(t.edges[r].kind==="main")||r-i);for(const r of s){const i=t.edges[r];if(i.fromSide||i.toSide)continue;const d=(f,c,g)=>{const $=`${f}.${c}`;return(l.get($)??0)>=3?!1:t.byId.get(f).shape!=="decision"?!0:g?!l.has($):!a.has($)},h=o(i).find(f=>d(i.from,f.sides[0],!0)&&d(i.to,f.sides[1],!1));if(h){a.add(`${i.from}.${h.sides[0]}`);for(const[f,c]of[[i.from,h.sides[0]],[i.to,h.sides[1]]])l.set(`${f}.${c}`,(l.get(`${f}.${c}`)??0)+1);i.fromSide=h.sides[0],i.toSide=h.sides[1]}}}function ee(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=gt(e.onLight);if(n)return{onLight:n,onDark:gt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var ge=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function Ct(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var me=28,ne=t=>t.includes(` -`)?2:1,Lt=t=>t.replace(/\n/g," "),Nt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function ye(t,e){return t.legend[e]}function ln(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function cn(t,e){return Ct(t,`sentence:${e.i}`,()=>dn(t,e))}function dn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const o=(e.columns??[]).filter(a=>a.ref).map(a=>`${a.ref.table} (${a.name}${a.card?`: ${$e(e.id,a.ref.table,a.card)}`:""})`),l=t.edges.filter(a=>a.to===e.id).map(a=>`${a.from} (${t.byId.get(a.from).columns[a.fromRow].name}${a.card?`: ${$e(a.from,a.to,a.card)}`:""})`);o.length&&n.push(`References ${o.join(", ")}.`),l.length&&n.push(`Referenced by ${l.join(", ")}.`)}else if(t.type==="sequence"){const o=t.steps.filter(s=>"n"in s&&s.from===e.id).length,l=t.steps.filter(s=>"n"in s&&s.to===e.id).length;n.push(Nt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${o} ${o===1?"message":"messages"} and receives ${l}.`);const a=be(t,e);a&&n.push(a.trim())}else{const o=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?ln(t,e):e.kind;if(n.push(Nt(o?`${e.name}, ${o}`:e.name)),e.detail&&n.push(Nt(e.detail)),e.group){const s=t.groups.find(i=>i.id===e.group),r=s?.parent?t.groups.find(i=>i.id===s.parent):void 0;s&&n.push(r?`In ${s.label}, in ${r.label}.`:`In ${s.label}.`)}const l=t.edges.filter(s=>s.to===e.id).map(s=>`${t.byId.get(s.from).name}${s.label?` (${Lt(s.label)})`:""}`),a=t.edges.filter(s=>s.from===e.id).map(s=>`${t.byId.get(s.to).name}${s.label?` (${Lt(s.label)})`:""}`);l.length&&n.push(`From: ${l.join(", ")}.`),a.length&&n.push(`To: ${a.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(Nt(t.legend.focal)),n.join(" ")}var fn=(t,e,n,o)=>[`${Ft[n.from].toLowerCase()} `,o(t),` to ${Ft[n.to].toLowerCase()} `,o(e)],$e=(t,e,n)=>`${Ft[n.from].toLowerCase()} ${t} to ${Ft[n.to].toLowerCase()} ${e}`;function be(t,e){const n=t.bars.filter(l=>l.who===e.id&&l.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(l=>l.from===l.to?`message ${l.from}`:`messages ${l.from} to ${l.to}`).join(" and ")}.`:""}function un(t,e,n,o){const l=n.pointerType;if(l!=="touch"&&l!=="pen")return;const a=t.querySelector(`.${e}-drawing`),s=n.target;if(!a||!s||!a.contains(s)||!t.querySelector(`.${e}-edge`))return;const r=s.closest(`.${e}-node`);if(!r?.hasAttribute("href"))return r?r.dataset.node===o?null:r.dataset.node??null:null}function we(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function w(t,e,...n){const o=[];for(const l of n.flat(1/0))l!=null&&l!==!1&&!Array.isArray(l)&&o.push(l);return{t,a:e??{},c:o}}var hn={"&":"&","<":"<",">":">",'"':""","'":"'"},yt=t=>t.replace(/[&<>"']/g,e=>hn[e]),pn=" br img input meta link hr path polygon polyline circle rect line ";function oe(t,e={}){if(typeof t=="string")return yt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[o,l]of Object.entries(t.a))if(!(l==null||l===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(o))throw new Error(`diagram: "${o}" is not an attribute name`);n+=l===!0?` ${o}`:` ${o}="${yt(String(l))}"`}return pn.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(o=>oe(o,e)).join("")}`}var gn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function jt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function mn(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Vt(t,e){const n=e.all.map(o=>t.byId.get(o));return n.length?{c1:Math.min(...n.map(o=>o.col)),c2:Math.max(...n.map(o=>o.col)),r1:Math.min(...n.map(o=>o.row)),r2:Math.max(...n.map(o=>o.row2))}:null}function ve(t){return Ct(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const o=Vt(t,n);if(!o)continue;[o.r1===1,o.c2===t.cols,o.r2===t.rows,o.c1===1].forEach((a,s)=>{a&&(e[s]=Math.max(e[s],xe(t,n,s)))})}return e})}function xe(t,e,n){const o=Vt(t,e);return t.groups.filter(s=>s.parent===e.id).some(s=>{const r=Vt(t,s);return r&&[r.r1===o.r1,r.c2===o.c2,r.r2===o.r2,r.c1===o.c1][n]})?2:1}function ke(t){const e=ve(t);return e[1]+e[3]}function se(t){return t.type==="sequence"?t.nodes.length:t.cols}function Me(t){return Ct(t,"plan",()=>yn(t))}function yn(t){const e=t.nodes,n=u=>t.type==="data-flow"||!e[u].branch,o=t.edges.map(u=>{const x=t.byId.get(u.from).i,C=t.byId.get(u.to).i,v=e.slice(Math.min(x,C)+1,Math.max(x,C)).every(S=>!n(S.i));return C===x+1&&!(n(x)&&!n(C))?"down":C===x-1?"up":C>x&&n(x)&&!n(C)&&v?"trunk":C>x&&n(x)&&n(C)&&v?"rail":C>x?"end-down":"end-up"}),l=t.edges.map((u,x)=>({e:u,k:x})).filter(({k:u})=>o[u]==="end-down"||o[u]==="end-up"),a=u=>{const x=t.byId.get(u.from).i,C=t.byId.get(u.to).i;return[Math.min(x,C),Math.max(x,C)]},s=(u,x)=>{const[C,W]=a(u),[v,S]=a(x);return C{const x=t.byId.get(u.from).i,[C,W]=a(u);return!n(x)&&e.slice(C+1,W).every(v=>!n(v.i))&&l.every(v=>v.e===u||!s(v.e,u))}),i=l.length>0&&(t.type==="data-flow"||!r),d=u=>{const[x,C]=a(u);return C-x},h=t.edges.map(()=>0);let f=!1;const c=[];for(const u of[...l].sort((x,C)=>d(x.e)-d(C.e)||x.k-C.k)){let x=0;for(const C of c)s(C.e,u.e)&&(x=Math.max(x,h[C.k]+1));h[u.k]=x,x>3&&(f=!0),c.push(u)}const g=Math.max(0,...l.map(({k:u})=>h[u]+1)),$=t.edges.map(()=>.5);for(const u of e){const x=l.filter(({e:v})=>v.from===u.id);if(x.length<2)continue;const C=x.filter(({k:v})=>o[v]==="end-down").sort((v,S)=>d(S.e)-d(v.e)||v.k-S.k);[...x.filter(({k:v})=>o[v]==="end-up").sort((v,S)=>d(v.e)-d(S.e)||S.k-v.k),...C].forEach(({k:v},S,T)=>{$[v]=T.length===2?S===0?1/3:2/3:(S+1)/(T.length+1)})}const p=At();for(let u=1;u{const D=o[I],j=t.byId.get(rt.from).i,M=t.byId.get(rt.to).i,B=M===u&&(D==="down"||D==="trunk"||D==="rail"||D==="end-down"),H=j===u&&M===u-1&&D==="up",Z=M===u-1&&D==="end-up";B&&(D==="trunk"||D==="end-down")&&(S=!0),Z&&(T=!0),(B||H||Z)&&rt.label&&(W++,v=Math.max(v,D==="trunk"?40:48))}),(W>1||S&&T)&&(v=64);const nt=l.filter(({e:rt,k:I})=>o[I]==="end-down"&&t.byId.get(rt.to).i===u).length,z=l.filter(({e:rt,k:I})=>o[I]==="end-up"&&t.byId.get(rt.to).i===u-1).length;v+=20*Math.max(0,nt-1)+20*Math.max(0,z-1),p[x.id]=v}return{routes:o,gutter:i,lanes:h,exits:$,gaps:p,third:f,laneCount:g}}var Tt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Se(t,e){const n=e==="fk"?"plain":e,o=n==="main"?8:8.5,l=24,a=n==="dashed"?l-1:l-7;return w("svg",{class:`${t}-swatch`,"data-kind":n,...Tt(24,16)},e==="fk"?w("circle",{class:`${t}-dot`,cx:3,cy:o,r:3}):null,w("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${o}H${a}`}),n==="dashed"?w("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${l-8} ${o-4}L${l} ${o}L${l-8} ${o+4}`}):w("path",{class:`${t}-tip`,"data-kind":n,d:`M${l} ${o}L${l-8} ${o-4}L${l-8} ${o+4}Z`}))}function $n(t,e){const{crow:n,ring:o}=Ee(e,24,8.5,-1);return w("svg",{class:`${t}-swatch`,"data-card":e,...Tt(24,16)},w("path",{class:`${t}-line`,"data-kind":"plain",d:"M0 8.5H24"}),w("path",{class:`${t}-crow`,d:n}),o?w("circle",{class:`${t}-ring`,cx:o.x,cy:o.y,r:o.r}):null)}function Ee(t,e,n,o,l=8,a=6){const s=g=>String(Math.round(g*100)/100),r=g=>e+o*g,i=l/2,d=g=>`M${s(r(g-.5))} ${s(n-i)}V${s(n+i)}`,h=t==="one-or-many"||t==="zero-or-many",f=t==="zero-or-one"||t==="zero-or-many";let c=h?`M${s(e)} ${s(n-i)}L${s(r(7.5))} ${s(n)}L${s(e)} ${s(n+i)}`:d(4);return f||(c+=d(h?11:8)),{crow:c,ring:f?{x:Math.round(r(10.5)*100)/100,y:n,r:a/2}:void 0}}function Ht(t,e){return e==="decision"?w("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},w("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?w("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):w("svg",{class:`${t}-swatch`,"data-shape":e,...Tt(16,16)},w("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Ae(t,e){return Ct(e,`key:${t}`,()=>wn(t,e))}var bn=Ae;function wn(t,e){const n=[],o=(s,r,i={})=>n.push(w("li",{class:`${t}-entry`,...i},s,w("span",null,r)));if(e.type==="schema"){const s=new Set(e.nodes.flatMap(r=>(r.columns??[]).map(i=>i.key)));for(const[r,i]of[["PK","Primary key"],["FK","Foreign key"]])s.has(r)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"aria-hidden":"true"},r),w("span",null,i)))}if(e.type==="flowchart"){const s=new Set(e.nodes.map(r=>r.shape));s.has("terminal")&&o(Ht(t,"terminal"),e.shapeLabels.terminal),s.has("box")&&o(Ht(t,"box"),e.shapeLabels.step),s.has("decision")&&o(Ht(t,"decision"),e.shapeLabels.decision)}const l=new Set(e.type==="sequence"?e.steps.flatMap(s=>"n"in s?[s.kind]:[]):e.edges.filter(s=>!s.fk).map(s=>s.kind)),a=(s,r)=>w("span",{class:`${t}-key-glyph`,"data-ink":r,"aria-hidden":"true"},s);for(const s of["main","plain","dashed"]){const r=e.legend[s];l.has(s)&&r&&o(e.text?a(s==="main"?"━━▶":s==="dashed"?"┄┄▷":"──▶",s==="main"?"main":"plain"):Se(t,s),r,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length){e.edges.some(r=>!r.card)&&o(Se(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"});const s=new Set(e.edges.flatMap(r=>r.card?[r.card.from,r.card.to]:[]));for(const r of pe)s.has(r)&&o($n(t,r),Ft[r],{"data-line":"","data-when":"drawn","data-card":r});n.push(w("li",{class:`${t}-entry`,"data-when":"stacked"},w("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),w("span",null,"The table a foreign key references")))}if(e.type==="sequence"){e.bars.length&&o(e.text?a("┃","working"):w("svg",{class:`${t}-swatch`,"data-shape":"bar",...Tt(16,16)},w("path",{class:`${t}-life`,d:"M8 0V16"}),w("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const s=new Set(e.steps.flatMap(r=>"open"in r?[r.open]:[]));for(const r of["opt","loop","alt"])s.has(r)&&n.push(w("li",{class:`${t}-entry`},w("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},r),w("span",null,e.frameWords[r])))}return e.nodes.some(s=>s.focal)&&e.legend.focal&&o(Ht(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&o(Ht(t,"group"),e.legend.group),n.length?w("div",{class:`${t}-key`},w("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function vn(t,e){const n=e==="main"?6:6.5;return w("svg",{class:`${t}-arrow`,"data-kind":e,...Tt(20,12)},w("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?w("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):w("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function ae(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),w("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function xn(t,e,n){if(n.shape==="decision")return[w("span",{class:`${t}-words`},w("span",{class:`${t}-name`},ae(t,n)))];const o=[];return e.type==="data-flow"?o.push(w("span",{class:`${t}-kind`},n.kind,w("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&o.push(w("span",{class:`${t}-kind`},n.kind)),o.push(w("span",{class:`${t}-name`},ae(t,n))),n.detail&&o.push(w("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?Yt(n.detail).flatMap((l,a)=>[a?" ":"",w("span",{class:`${t}-run`},l)]):n.detail)),o}function kn(t,e,n){return[w("span",{class:`${t}-th`},w("span",{class:`${t}-tname`},ae(t,e))),w("span",{class:`${t}-rows`},(e.columns??[]).map((o,l)=>w("span",{class:`${t}-row`,"data-row":l,"data-key":o.key},w("span",{class:`${t}-keyseat`},o.key??""),w("span",{class:`${t}-cname`},o.name),o.ref?w("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${o.ref.table}`):o.type?w("span",{class:`${t}-ctype`},o.type):null))),e.more?w("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Le=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Kt(t,e,n,o){const{P:l}=t,a=mn(e,o)||o.keep===n.id,s=jt(e,o),r=o.layout==="drawn"&&o.rows,i=[`--_c:${n.col}`,`--_r:${r?2*n.row:n.row}`,`--_r2:${r?2*n.row2+1:n.row2+1}`];e.type==="data-flow"&&i.push(`--_lc:${n.col+1}`),e.type==="sequence"&&i.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const $=qt(d.gaps,n.id)??32,p=qt(o.grow,n.id)??0;i.push(`--_gap:${p?`calc(${Le($)} + var(--basalt-space-4) * ${p})`:Le($)}`)}const h=qt(o.heights,n.id);h&&i.push(`--_h:${h}px`);const f=qt(Te(e),n.id);f&&i.push(`--_mh:${f}px`);const c=qt(o.words,n.id);c&&i.push(`--_ww:${c}px`);const g=s?o.stop===n.id?0:-1:o.keep===n.id?-1:void 0;return w(n.href?"a":"div",{class:`${l}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:i.join(";"),role:a&&!n.href?"img":void 0,"aria-label":a||n.href?cn(e,n):void 0,tabindex:g},n.shape==="decision"?w("svg",{class:`${l}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},w("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?w("span",{class:`${l}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${ge(n.mark.onLight)};--_md:${ge(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?kn(l,n,e):xn(l,e,n))}function Mn(t,e,n){const{P:o}=t,l=[];if(e.type==="data-flow"&&l.push(...e.lanes.map((i,d)=>w("div",{class:`${o}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},w("span",{class:`${o}-lane-name`},i.label)))),e.type==="architecture")for(const i of e.groups){const d=Vt(e,i);if(!d)continue;const h=[0,1,2,3].map(f=>xe(e,i,f));l.push(w("div",{class:`${o}-gbox`,"data-group":i.id,"data-depth":i.depth>1?i.depth:void 0,style:`--_c:${d.c1};--_c2:${d.c2+1};--_r:${d.r1};--_r2:${d.r2+1}${h[0]>1?";--_gt:2":""}${h[1]>1?";--_ge:2":""}${h[2]>1?";--_gb:2":""}${h[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},w("span",{class:`${o}-glabel`},i.label)))}if(e.text)return[w("pre",{class:`${o}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},w("code",{class:`${o}-text-ink`},Sn(o,e)))];if(e.type==="sequence")return l.push(w("ul",{class:`${o}-cast`},e.nodes.map(i=>w("li",{class:`${o}-actor`,style:e.rtl?`--_ac:${i.col}`:void 0},Kt(t,e,i,n))))),l.push(En(t,e)),l;const a=i=>{const d=i.group?e.groups.find(h=>h.id===i.group):void 0;return d?.parent?e.groups.find(h=>h.id===d.parent):d},s=(i,d,h)=>{const f=t.plan?qt(n.grow,d[0].id)??0:0;return w("div",{class:`${o}-group`,"data-group":i.id,"data-depth":i.depth>1?i.depth:void 0,style:f?`--_ggrow:${f}`:void 0},w("span",{class:`${o}-glabel`,"aria-hidden":"true"},i.label),h)};let r=0;for(;rp.id===h[c].group):void 0;if(!g){f.push(Kt(t,e,h[c],n)),c++;continue}const $=[];for(;cKt(t,e,p,n))))}l.push(s(d,h,f))}return l}function Sn(t,e){const n=[],o=s=>w("span",{class:`${t}-tx-name`},s),l=s=>s==="main"?"━▶":s==="dashed"?"┄▷":"─▶";n.push(w("span",{class:`${t}-tx-line`,"data-ink":"names"},e.nodes.flatMap((s,r)=>[r?" · ":"",o(s.name)])),` -`);let a=0;for(const s of e.steps){const r=" ".repeat(a);if("band"in s){n.push(w("span",{class:`${t}-tx-line`,"data-ink":"band"},`${r}── ${s.band} ──`),` -`);continue}if("open"in s){n.push(w("span",{class:`${t}-tx-line`,"data-ink":"frame"},r,w("span",{"data-ink":"op"},`[${s.open}]`),` ${s.label}`),` -`),a++;continue}if("otherwise"in s){n.push(w("span",{class:`${t}-tx-line`,"data-ink":"frame"}," ".repeat(a-1),w("span",{"data-ink":"op"},"[else]"),` ${s.otherwise}`),` -`);continue}if("close"in s){a=Math.max(0,a-1),n.push(w("span",{class:`${t}-tx-line`,"data-ink":"frame"},`${" ".repeat(a)}[end]`),` -`);continue}const i=e.byId.get(s.from)?.name??s.from,d=e.byId.get(s.to)?.name??s.to;n.push(w("span",{class:`${t}-tx-line`,"data-n":s.n},r,w("span",{"data-ink":"num"},`${s.n} `),o(i)," ",w("span",{"data-ink":s.kind==="main"?"main":"plain"},l(s.kind))," ",o(d)," ",w("span",{"data-ink":"label"},s.label),s.note?[" ",w("span",{"data-ink":"note"},`(${s.note})`)]:null),` -`)}return n}function En(t,e){const{P:n}=t,o=[],l=[],a=()=>l.length?l[l.length-1].el.c:o;let s=null;for(const r of e.steps){if("band"in r){s=null,a().push(w("p",{class:`${n}-band`},w("span",null,r.band)));continue}if("open"in r){s=null;const p=l[l.length-1],u=p?`;--_fis:${r.a===p.a?1:0};--_fie:${r.b===p.b?1:0}`:"",x=w("div",{class:`${n}-frame`,"data-op":r.open,"data-depth":r.depth,style:`--_a:${r.a};--_b:${r.b+1}${u}`},w("span",{class:`${n}-fbox`,"aria-hidden":"true"}),w("p",{class:`${n}-fhead`},w("span",{class:`${n}-ftab`,"aria-hidden":"true"},r.open),w("span",{class:`${n}-flabel`},w("span",{class:t.hidden},`${e.frameWords[r.open]}: `),r.label)));a().push(x),l.push({el:x,a:r.a,b:r.b});continue}if("otherwise"in r){s=null,a().push(w("p",{class:`${n}-felse`},w("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),w("span",{class:`${n}-flabel`},w("span",{class:t.hidden},`${e.frameWords.else}: `),r.otherwise)));continue}if("close"in r){s=null,l.pop();continue}s||(s=w("ol",{class:`${n}-msgs`,start:r.n}),a().push(s));const i=e.byId.get(r.from),d=e.byId.get(r.to),h=i?.col??1,f=d?.col??1,c=h===f,g=c&&(e.rtl?h!==1:h===e.nodes.length),$=ye(e,r.kind);s.c.push(w("li",{class:`${n}-msg`,"data-kind":r.kind,"data-from":r.from,"data-to":r.to,"data-self":c?g?"start":"end":void 0,style:`--_a:${Math.min(h,f)};--_b:${Math.max(h,f)+1}`},w("span",{class:`${n}-said`},w("span",{class:`${n}-num`},String(r.n)),w("span",{class:`${n}-mlabel`},r.label)),w("span",{class:`${n}-route`},i?.short??r.from," ",vn(n,r.kind),w("span",{class:t.hidden}," to ")," ",d?.short??r.to,$?` · ${$}`:""),r.note?w("span",{class:`${n}-note`},r.note):null))}return w("div",{class:`${n}-steps`},o)}function Ie(t,e){return Ct(e,`list:${t}`,()=>Ln(t,e))}var An=Ie;function Ln(t,e){const n=Math.min(6,e.heading+1),o=f=>w(`h${n}`,{class:`${t}-list-head`},f),l=f=>w("strong",null,f),a=f=>f.href?w("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},l(f.name)):l(f.name),s=f=>w("code",{class:`${t}-code`},f),r=f=>e.byId.get(f)?.name??f,i=f=>{const c=ye(e,f);return c?` (${c})`:""},d=f=>f.focal&&e.legend.focal?` ${Nt(e.legend.focal)}`:"";if(e.type==="architecture"){const f=$=>w("li",null,a($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?s($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",d($)),c=[o("Parts")],g=e.nodes.filter($=>!$.group);g.length&&c.push(w("ul",{class:`${t}-list-items`},g.map(f)));for(const $ of e.groups.filter(p=>p.depth===1)){c.push(w("p",{class:`${t}-list-group`},$.label)),$.members.length&&c.push(w("ul",{class:`${t}-list-items`},$.members.map(p=>f(e.byId.get(p)))));for(const p of e.groups.filter(u=>u.parent===$.id))c.push(w("p",{class:`${t}-list-group`,"data-depth":2},p.label)),c.push(w("ul",{class:`${t}-list-items`,"data-depth":2},p.members.map(u=>f(e.byId.get(u)))))}return c.push(o("Connections")),c.push(w("ol",{class:`${t}-list-items`},e.edges.map($=>w("li",null,l(r($.from))," to ",l(r($.to)),$.label?[": ",s(Lt($.label))]:"",`${i($.kind)}.`)))),c}if(e.type==="flowchart"){const f=c=>(e.byId.get(c)?.i??0)+1;return[w("ol",{class:`${t}-list-items`},e.nodes.map(c=>{const g=e.edges.filter(u=>u.from===c.id),$=c.shape==="decision"?"Decision":c.shape==="terminal"?g.length?"Start":"End":"Step",p=!c.detail&&/[.!?]$/.test(c.name)?" ":". ";return w("li",null,a(c),c.detail?[", ",c.mono?s(c.detail):c.detail]:"",`${p}${$}.`,d(c),g.length?w("ul",{class:`${t}-list-exits`},g.map(u=>w("li",null,u.label?`If ${Lt(u.label)}: go to ${f(u.to)}, `:`Then: go to ${f(u.to)}, `,l(r(u.to)),i(u.kind)))):null)}))]}if(e.type==="data-flow")return[w("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const c=e.edges.filter(g=>g.from===f.id);return w("li",null,`${f.laneLabel}: `,a(f),f.detail?[", ",f.mono?s(f.detail):f.detail]:"",".",d(f),c.length?[" Then ",...c.flatMap((g,$)=>[$?"; ":"",`to step ${e.byId.get(g.to).step}, `,l(r(g.to)),g.label?[": ",s(Lt(g.label))]:"",i(g.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[o("Participants"),w("ul",{class:`${t}-list-items`},e.nodes.map(g=>w("li",null,l(g.name),g.kind?`, ${g.kind}`:"",".",d(g),be(e,g))))];f.push(o("Messages"));let c=null;for(const g of e.steps){if("band"in g){c=null,f.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},g.band));continue}if("open"in g){c=null,f.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords[g.open]}: ${g.label}`));continue}if("otherwise"in g){c=null,f.push(w(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":g.depth>1?g.depth:void 0},`${e.frameWords.else}: ${g.otherwise}`));continue}if("close"in g){c=null;continue}c||(c=w("ol",{class:`${t}-list-items`,start:g.n}),f.push(c)),c.c.push(w("li",null,s(g.label),": ",l(r(g.from))," to ",l(r(g.to)),`${i(g.kind)}.`,g.note?` ${Nt(g.note)}`:""))}return f}const h=[];for(const f of e.nodes)h.push(w(`h${n}`,{class:`${t}-list-group`},f.href?w("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},s(f.name)):s(f.name),d(f))),h.push(w("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(c=>w("li",null,s(c.name),c.key==="PK"?", primary key":c.key==="FK"?", foreign key":"",c.ref?[", references ",s(`${c.ref.table}.${c.ref.column}`),c.card?[" (",fn(f.id,c.ref.table,c.card,s),")"]:""]:c.type?`, ${c.type}`:"")),...f.more?[w("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return h}function _e(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Zt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(l=>l.href)?" Enter opens a part that is a link.":""}`}function re(t,e=!1){const n=e&&t.type!=="sequence"&&Zt(t)&&t.cols>1&&t.rows>1,o=t.nodes.some(l=>l.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:we(t)},{keys:["Home","End"],words:"the ends"},...o,{keys:["Esc"],words:"clear"}]}var In=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Zt(t){return Ct(t,"spatial",()=>{const e=t.nodes.map(a=>({id:a.id,..._n(t,a)})),n=(a,s)=>{const r=s==="right"||s==="left",i=s==="right"||s==="down",d=$=>r?[$.col,$.col]:$.rows,h=$=>r?$.rows:[$.col,$.col],f=d(a),c=h(a);let g=null;return e.forEach(($,p)=>{if($===a)return;const u=d($),x=h($),C=i?u[0]-f[1]:f[0]-u[1];if(C<1)return;const W=Math.max(0,x[0]-c[1],c[0]-x[1]),v=[W===0?0:1,W===0?C:C+2*W,W,Math.abs(x[0]-c[0]),p];(!g||In(v,g.rank))&&(g={id:$.id,rank:v})}),g?.id??null},o=At();for(const a of e)o[a.id]={right:n(a,"right"),left:n(a,"left"),down:n(a,"down"),up:n(a,"up")};const l=a=>{const s=new Set([a]),r=[a];for(;r.length;)for(const i of Object.values(o[r.pop()]))i&&!s.has(i)&&(s.add(i),r.push(i));return s.size};return e.every(a=>l(a.id)===e.length)?o:null})}function Jt(t){return Ct(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!ie(t))return{lane:e,dropped:n,lanes:0};const o=(i,d)=>(t.byId.get(i)?.row??0)*1e3+d,l=new Map;t.edges.forEach((i,d)=>{const h=`${i.to}.${i.toRow}`,f=o(i.from,i.fromRow??0),c=o(i.to,i.toRow??0),g=l.get(h)??{members:[],lo:1/0,hi:-1/0};g.members.push(d),g.lo=Math.min(g.lo,f,c),g.hi=Math.max(g.hi,f,c),l.set(h,g)});const a=[...l.values()].sort((i,d)=>d.hi-d.lo-(i.hi-i.lo)),s=[];let r=0;for(const i of a.reverse()){const d=new Set(s.filter(f=>f.lo<=i.hi&&i.lo<=f.hi).map(f=>f.lane));let h=0;for(;d.has(h);)h++;if(h>1){for(const f of i.members)n.add(f);continue}s.push({lo:i.lo,hi:i.hi,lane:h});for(const f of i.members)e.set(f,h);r=Math.max(r,h+1)}return{lane:e,dropped:n,lanes:r}})}var ie=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Xt(t,e,n){const o=n.prefix,l=gn(n.base),a=t.type==="sequence"||t.type==="schema"?null:Me(t),s={P:o,ids:l,level:n.level,plan:a,hidden:n.hiddenClass},r=e.layout==="drawn",i=jt(t,e),d=t.type==="sequence"||t.type==="schema"?r:!0,h=`h${t.heading}`,f=[`--_cols:${se(t)}`];if(t.type==="architecture"&&t.groups.length||r&&e.pad){const c=t.type==="architecture"?ve(t):[0,0,0,0],g=(p,u,x)=>p?p>1?`calc(${p} * var(--basalt-space-${u}))`:`var(--basalt-space-${u})`:x?`var(--basalt-space-${x})`:"0px",$=r&&e.pad?"3":void 0;f.push(`--_gpad:${g(c[0],"8",$)} ${g(c[1],"4")} ${g(c[2],"4",$)} ${g(c[3],"4")}`)}if(a?.gutter&&a.laneCount>2&&f.push(`--_gw:calc(${a.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),ie(t)){const c=t.marks?"var(--basalt-space-6) + var(--basalt-space-1)":"var(--basalt-space-5)";f.push(`--_gpad:0px ${Jt(t).lanes>1?`calc(${c} + var(--basalt-space-3))`:t.marks?`calc(${c})`:c} 0px 0px`)}return t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),w("figure",{class:n.className?`${o} ${n.className}`:o,"aria-labelledby":l.title,"data-type":t.type,"data-cols":se(t),"data-reach":t.type==="architecture"?ke(t):void 0,"data-gutter":a?.gutter?"":void 0,"data-marks":t.marks?"":void 0,"data-layout":e.layout,"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:f.join(";")},w("div",{class:`${o}-head`},w(h,{id:l.title,class:`${o}-title`},t.title),n.hasSource?w("p",{class:`${o}-source`},{slot:"source"}):null),w("div",{class:`${o}-drawing`,style:r&&e.rows?`--_rows:${e.rows};--_row-gap:0px`:void 0,role:d?"group":void 0,"aria-roledescription":d?"diagram":void 0,"aria-labelledby":d?l.title:void 0,"aria-describedby":d?i?`${l.summary} ${l.keys}`:l.summary:void 0,"data-stops":i?"":void 0},Mn(s,t,e),t.text?null:w("div",{class:`${o}-ink`,"aria-hidden":"true"}),w("span",{class:`${o}-ruler`,"aria-hidden":"true"})),Ae(o,t),w("p",{class:`${o}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),jt(t,e)&&t.type!=="sequence"||r&&t.type==="sequence"?w("p",{class:`${o}-tap-hint`,"aria-hidden":"true"},`Tap ${we(t)} to highlight its lines. Tap it again to clear.`):null,w("div",{class:`${o}-foot`},{slot:"toggle"}),w("div",{id:l.list,class:`${o}-list`,hidden:!e.open},Ie(o,t)),w("span",{id:l.keys,class:n.hiddenClass},n.viewer?`${_e(t,r)} ${n.viewer}`:_e(t,r)),w("figcaption",{id:l.summary,class:`${o}-summary`},{slot:"summary"}))}function On(t){const e=getComputedStyle(t),n=(l,a)=>{const s=parseFloat(e.getPropertyValue(`--basalt-${l}`));return Number.isFinite(s)?s:a},o=new Map;return{space:l=>(o.has(l)||o.set(l,n(`space-${l}`,parseFloat(l.replace("-","."))*4)),o.get(l)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ut=(t,e)=>t==="main"?e.line:e.hair,Et=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},It=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,Oe=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function kt(t,e,n){const{l:o,t:l,r:a,b:s}=t.rect,r=(o+a)/2,i=(l+s)/2,d=(a-o)/2,h=(s-l)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const $=n,p=h*Math.max(0,1-Math.abs($-r)/d);return{x:$,y:e==="top"?i-p:i+p}}const c=n,g=d*Math.max(0,1-Math.abs(c-i)/h);return{x:e==="left"?r-g:r+g,y:c}}if(t.shape==="terminal"){const c=Math.min(d,h);if(f){const u=n,x=Math.min(Math.max(u,o+c),a-c),C=u-x,W=Math.abs(C)>=c?0:Math.sqrt(c*c-C*C);return{x:u,y:Math.abs(C)<1e-6?e==="top"?l:s:e==="top"?i-W:i+W}}const g=n,$=g-i,p=Math.abs($)>=c?0:Math.sqrt(c*c-$*$);return{x:e==="left"?o+c-p:a-c+p,y:g}}return f?{x:n,y:e==="top"?l:s}:{x:e==="left"?o:a,y:n}}function qn(t,e,n){const{l:o,t:l,r:a,b:s}=e.rect,r=(o+a)/2,i=(l+s)/2,d=(a-o)/2,h=(s-l)/2;if(e.shape==="decision")return Math.abs(t.x-r)/d+Math.abs(t.y-i)/h<1-n/Math.min(d,h);if(e.shape==="terminal"){const f=Math.min(d,h),c=Math.min(Math.max(t.x,o+f),a-f);return Math.hypot(t.x-c,t.y-i)o+n&&t.xl+n&&t.ymatchMedia("(forced-colors: active)").matches;function Bn(t,e){const n=t.querySelector(`.${e}-ruler`),o=new Map;return(l,a)=>{const s=`${a}|${l}`;return o.has(s)||(n.setAttribute("data-f",a),n.textContent=l,o.set(s,n.getBoundingClientRect().width),n.textContent=""),o.get(s)}}var Yt=t=>t?t.split(/\s+/).filter(Boolean):[];function Rn(t,e,n){const o=e.space;let l=e.node,a=e.table;for(const i of t.nodes){if(i.shape==="table"){for(const p of i.columns??[]){const u=p.ref?`${t.rtl?"←":"→"} ${p.ref.table}`:p.type??"",x=o("6")+n(p.name,"mono")+(u?o("3")+n(u,"mono"):0)+2*o("3")+2*e.hair;a=Math.max(a,Math.ceil(x))}a=Math.max(a,Math.ceil(n(i.name,"table")+2*o("3")+2*e.hair+(i.href?16+o("1-5"):0)));continue}const d=i.shape==="terminal"?2*o("5"):2*o("3"),h=i.mark&&!jn()?(i.shape==="participant"?2:1)*o("6"):0;let f=0;const c=i.href?16+o("1-5"):0,g=Yt(i.name);if(g.forEach((p,u)=>{f=Math.max(f,n(p,i.shape==="decision"?"name-500":"name")+(i.kind?0:h)+(u===g.length-1?c:0))}),t.type!=="data-flow")for(const p of Yt(i.kind))f=Math.max(f,n(p,"mono")+h);for(const p of Yt(i.detail))f=Math.max(f,n(p,i.mono?"mono":"sans"));const $=i.shape==="decision"?f/.62:f+d+2*e.hair;l=Math.max(l,Math.ceil($))}const s=se(t);let r;return t.type==="data-flow"?r=e.lane+s*(l+o("12")):t.type==="schema"?r=s*a+(s-1)*(o("12")+(t.marks?o("3"):0))+(ie(t)?(t.marks?o("6")+o("1"):o("5"))+(Jt(t).lanes>1?o("3"):0):0):t.type==="sequence"?r=s*l+(s-1)*o("5"):r=s*l+(s-1)*o("16")+ke(t)*o("4"),{track:l,table:a,least:Math.max(e.wide,r)}}function Ce(t,e){return{x:(n,o)=>o%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,o)=>o%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function le(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function je(t,e,n){const o=t.map(a=>({...a}));for(let a=1;a=2){const i=l[l.length-2];if(Math.abs(i.x-r.x)<.01&&Math.abs(r.x-s.x)<.01||Math.abs(i.y-r.y)<.01&&Math.abs(r.y-s.y)<.01){l[l.length-1]=s;continue}}l.push(s)}}return l}var _t=t=>t.slice(1).map((e,n)=>[t[n],e]);function Qt(t,e,n){const o=[];for(let a=0;aMath.min(p.x,u.x)+.75&&WMath.min(x.y,C.y)+.75&&va.split(/\s+/).map(parseFloat).filter(s=>Number.isFinite(s)),o=(a,s,r)=>{const i=[];let d=s;for(const h of a)i.push([d,d+h]),d+=h+r;return i},l=o(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0);return{cols:o(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:t.style.getPropertyValue("--_rows").trim()?l.filter((a,s)=>s%2===1):l}}var dt=t=>t==="left"||t==="right",Be={top:"bottom",bottom:"top",left:"right",right:"left"};function ce(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Re(t,e,n){const o=[];t.edges.forEach((a,s)=>{const r=t.byId.get(a.from),i=t.byId.get(a.to),[d,h]=e[s],f=r.row===i.row&&dt(d)&&dt(h)&&d===Be[h]||r.col===i.col&&!dt(d)&&!dt(h)&&d===Be[h];o.push({edge:s,end:"from",node:r,side:d,far:i,straight:f,f:.5},{edge:s,end:"to",node:i,side:h,far:r,straight:f,f:.5})});const l=new Map;for(const a of o){const s=`${a.node.id}.${a.side}`;l.has(s)||l.set(s,[]),l.get(s).push(a)}for(const[a,s]of l){if(s[0].node.shape==="decision")continue;const r=p=>dt(p.side)?p.far.row-p.node.row:p.far.col-p.node.col,i=s.filter(p=>p.straight),d=s.filter(p=>!p.straight);if(d.sort((p,u)=>r(p)-r(u)||(dt(p.side)?p.far.col-u.far.col:p.far.row-u.far.row)*(r(p)<0?1:-1)),s.length>3&&n(`${a.replace(".","'s ")} side has ${s.length} lines; more than three is an error: use another side`),!i.length){d.length===2?(d[0].f=.25,d[1].f=.75):d.length===3?(d[0].f=.25,d[1].f=.5,d[2].f=.75):d.length>3&&d.forEach((p,u)=>{p.f=(u+1)/(d.length+1)});continue}const h=new Map;for(const p of i)h.has(p.far.id)||h.set(p.far.id,[]),h.get(p.far.id).push(p);for(const p of h.values())p.length>1&&p.sort((u,x)=>u.edge-x.edge).forEach((u,x)=>{u.f=p.length===2?x===0?.25:.75:(x+1)/(p.length+1)});const f=Math.min(...i.map(p=>p.f)),c=Math.max(...i.map(p=>p.f)),g=d.filter(p=>r(p)<0),$=d.filter(p=>r(p)>=0);g.forEach((p,u)=>{p.f=f*(u+1)/(g.length+1)}),$.forEach((p,u)=>{p.f=c+(1-c)*(u+1)/($.length+1)})}return o}function Te(t,e=8,n=8){return Ct(t,`port-floors:${e}:${n}`,()=>{const o=At();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return o;const l=t.edges.map(s=>{const r=t.byId.get(s.from),i=t.byId.get(s.to),[d,h]=ce(r,i);return[s.fromSide??d,s.toSide??h]}),a=new Map;for(const s of Re(t,l,()=>{})){if(!dt(s.side)||s.node.shape!=="box")continue;const r=`${s.node.id}.${s.side}`;a.has(r)||a.set(r,[]),a.get(r).push(s.f)}for(const[s,r]of a){if(r.length<2)continue;const i=[...new Set(r.map(f=>Math.round(f*1e6)/1e6))].sort((f,c)=>f-c);let d=Math.max(e/i[0],e/(1-i[i.length-1]));for(let f=1;f{const s=t.byId.get(a.dataset.node);s&&l.set(s.id,{id:s.id,rect:Et(a,n),shape:s.shape,i:s.i})}),l}function We(t,e){const n=e.head,o=e.head/2,{x:l,y:a}=t.tip;return t.dir==="down"?{l:l-o,r:l+o,t:a-n,b:a}:t.dir==="up"?{l:l-o,r:l+o,t:a,b:a+n}:t.dir==="right"?{l:l-n,r:l,t:a-o,b:a+o}:{l,r:l+n,t:a-o,b:a+o}}var Fe=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function He(t,e,n,o){const l=(a,s)=>{const r=a+s-Math.floor(a+s);return r<.005||r>.995?[0]:r<=.5?[-r,1-r]:[1-r,-r]};for(const a of l(t.t,n))for(const s of l(t.l,e)){if(!s&&!a)return t;const r={l:t.l+s,r:t.r+s,t:t.t+a,b:t.b+a};if(o(r))return r}return t}function zn(t,e,n,o,l,a,s,r,i){const d=s.space,h=[],f=[],c=[],g=[],$=d("1"),p=e.filter(u=>t.edges[u.i]?.label).sort((u,x)=>+(t.edges[x.i].kind==="main")-+(t.edges[u.i].kind==="main")||u.i-x.i);for(const u of p){const x=t.edges[u.i].label,C=r(x,"label"),W=16*ne(x),v=u.pts.length-2,S=[];_t(u.pts).forEach(([I,D],j)=>{const M=Math.abs(I.y-D.y)<.01,B=M?I.x:I.y;let H=M?D.x:D.y;const Z=Math.sign(H-B)||1;j===v&&(H-=Z*s.head);let K=[[B,H]];for(const J of l)for(const m of M?[J.l,J.r]:[J.t,J.b]){const y=M?I.y:I.x;(M?y>J.t&&yJ.l&&ym>Math.min(q,_)+1&&m{const y=(J+m)/2,E=M?{x:y,y:I.y}:{x:I.x,y};return!l.some(q=>E.x>q.l&&E.xq.t&&E.y1&&ot(J,m)?1:0})}),S.sort((I,D)=>D.pri-I.pri||D.len-I.len);let T=null,nt=!1;const z=(I,D=!0)=>{const j=Oe(I,$);return D&&(I.la.r||I.ta.b)||n.some(M=>qe(j,M))||h.some(M=>It(j,M))||o.heads.some(M=>It(j,M))||o.rects.some(M=>It(j,M))?!1:!e.some(M=>M.i!==u.i&&_t(M.pts).some(([B,H])=>It(j,Fe(B,H,M.width))))};for(const I of S){for(const D of[1/2,1/3,2/3]){const j=I.p+(I.q-I.p)*D,M=[],B=d("2")+u.width/2;if(I.horiz?(I.len>=C+2*d("1")+d("3-5")&&M.push({box:{l:j-C/2-d("1"),r:j+C/2+d("1"),t:I.c-W/2,b:I.c+W/2},on:!0}),M.push({box:{l:j-C/2,r:j+C/2,t:I.c-B-W,b:I.c-B},on:!1}),M.push({box:{l:j-C/2,r:j+C/2,t:I.c+B,b:I.c+B+W},on:!1})):(I.len>=W+d("3")&&M.push({box:{l:I.c-C/2-d("1"),r:I.c+C/2+d("1"),t:j-W/2,b:j+W/2},on:!0}),M.push({box:{l:I.c+B,r:I.c+B+C,t:j-W/2,b:j+W/2},on:!1}),M.push({box:{l:I.c-B-C,r:I.c-B,t:j-W/2,b:j+W/2},on:!1})),T=M.find(H=>z(H.box))??null,T)break;!nt&&M.some(H=>z(H.box,!1))&&(nt=!0)}if(T)break}if(!T){c.push(u.i),nt&&g.push(u.i);continue}const rt=He(T.box,i.ox,i.oy,I=>z(I));h.push(rt),f.push({i:u.i,text:x,box:rt,on:T.on})}return{labels:f,unseated:c,bounded:g}}function De(t,e,n,o){const l=[],a=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(s=>{if(s.getClientRects().length===0||getComputedStyle(s).display==="contents")return;const r=Et(s,e);a.push(r),l.push({l:r.l,r:r.r,t:r.t,b:r.t+1},{l:r.l,r:r.r,t:r.b-1,b:r.b},{l:r.l,r:r.l+1,t:r.t,b:r.b},{l:r.r-1,r:r.r,t:r.t,b:r.b});const i=s.querySelector(`:scope > .${n}-glabel`);i&&i.getClientRects().length&&l.push(Et(i,e))}),t.querySelectorAll(`.${n}-lane`).forEach((s,r)=>{if(!s.getClientRects().length)return;const i=Et(s,e);r>0&&l.push({l:i.l,r:i.r,t:i.t-o/2-.5,b:i.t-o/2+.5});const d=s.querySelector(`.${n}-lane-name`);d&&l.push(Et(d,e))}),{obstacles:{rects:l,heads:[]},groups:a}}function Ge(t,e){const{m:o,tk:l,P:a,drawing:s,origin:r,warn:i}=t,d=l.space,h=Ne(o,s,r,a),f=[...h.values()],c=Tn(s),g=r.left-Math.floor(r.left),$=r.top-Math.floor(r.top),p=Ce(g,$),u=s.clientWidth,x=s.clientHeight,C=b=>o.type==="data-flow"?b.col+1:b.col,W=parseFloat(getComputedStyle(s).rowGap)||0,v={w:u,h:x,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:g,oy:$};if(o.type==="sequence")return Wn(t,v,p);let S,T=[];o.type==="schema"?S=o.edges.map(b=>{const A=o.byId.get(b.from),L=o.byId.get(b.to);if(A.col===L.col){const k=A.col===o.cols&&o.cols>1?"left":"right";return[k,k]}return L.col>A.col?["right","left"]:["left","right"]}):(S=o.edges.map(b=>{const A=o.byId.get(b.from),L=o.byId.get(b.to),[k,O]=ce(A,L);return[b.fromSide??k,b.toSide??O]}),T=Re(o,S,i||(()=>{})));const nt=(b,A)=>{const L=s.querySelector(`.${a}-node[data-node="${CSS.escape(b)}"] .${a}-row[data-row="${A}"]`);if(!L)return 0;const k=Et(L,r);return(k.t+k.b)/2},z=new Map;if(o.type==="schema"){const b=new Map;o.edges.forEach((L,k)=>{const O=`${L.to}.${L.toRow}.${S[k][1]}`;b.set(O,[...b.get(O)??[],k])});const A=L=>{const k=o.edges[L].card?.to;return k==="one"?0:k==="zero-or-one"?1:2};for(const L of b.values()){const k=[...new Set(L.map(A))].sort((O,F)=>O-F);if(k.length>1)for(const O of L)z.set(O,(k.indexOf(A(O))-(k.length-1)/2)*d("2"))}}const rt=b=>Math.round(b+g)-g,I=o.edges.map((b,A)=>{const[L,k]=S[A],O=h.get(b.from),F=h.get(b.to),X=Ut(b.kind,l);if(b.fk){const Y=nt(b.from,b.fromRow),et=nt(b.to,b.toRow)+(z.get(A)??0),$t=p.y(Y,X),Bt=p.y(et,X),St=L==="right"?O.rect.r:O.rect.l,xt=k==="right"?F.rect.r:F.rect.l;return{p1:{x:b.card?rt(St):St,y:$t},p2:{x:b.card?rt(xt):xt,y:Bt},r1:Y,r2:Math.abs($t-Bt)<.01?Y:et}}const Q=T.find(Y=>Y.edge===A&&Y.end==="from").f,at=T.find(Y=>Y.edge===A&&Y.end==="to").f;let st=ze(O,L,Q),tt=ze(F,k,at);const N=dt(L)?st.y:st.x;let V=dt(k)?tt.y:tt.x;return dt(L)?st={...st,y:p.y(st.y,X)}:st={...st,x:p.x(st.x,X)},dt(k)?tt={...tt,y:p.y(tt.y,X)}:tt={...tt,x:p.x(tt.x,X)},dt(L)&&dt(k)&&Math.abs(st.y-tt.y)<1.01&&(tt={...tt,y:st.y},V=N),!dt(L)&&!dt(k)&&Math.abs(st.x-tt.x)<1.01&&(tt={...tt,x:st.x},V=N),st=dt(L)?kt(O,L,st.y):kt(O,L,st.x),tt=dt(k)?kt(F,k,tt.y):kt(F,k,tt.x),{p1:st,p2:tt,r1:N,r2:V}}),D=new Set,j=(b,A)=>{D.has(b)||(D.add(b),i?.(`${o.edges[b].from} to ${o.edges[b].to} ${A}, so its line is not drawn; its row still writes the target`))};for(const b of Jt(o).dropped)j(b,"would need a third lane of turn-backs");const M=new Map,B=At();o.type==="schema"&&o.edges.forEach((b,A)=>{const L=o.byId.get(b.from),k=o.byId.get(b.to);if(Math.abs(L.col-k.col)<2)return;const O=Math.min(L.col,k.col),F=Math.max(L.col,k.col),X=o.nodes.filter(et=>et.col>O&&et.col$t.row<=et&&$t.row2>=et+1)||at.push({key:`g${et}`,y:(Q[et-1][1]+Q[et][0])/2,inner:!0});at.push({key:"top",y:Q[0][0]-d("4"),inner:!1},{key:"bottom",y:Q[Q.length-1][1]+d("4"),inner:!1});const st=(I[A].r1+I[A].r2)/2,tt=t.pick?.[A]??at.slice().sort((et,$t)=>Math.abs(et.y-st)-Math.abs($t.y-st)||Number($t.inner)-Number(et.inner)||et.y-$t.y)[0].key;B[A]=tt;const N=S[A][0]==="right"?L.col:L.col-1,V=c.cols[N-1],Y=c.cols[N];M.set(A,{corridor:tt,first:V&&Y?{key:`c${N}`,span:[V[1],Y[0]]}:null,y:0})});const H=new Map;for(const[b,A]of M){const L=o.edges[b],k=H.get(A.corridor)??[],O=k.find(F=>{const X=o.edges[F[0]];return X.to===L.to&&X.toRow===L.toRow&&S[F[0]][1]===S[b][1]&&Math.abs(I[F[0]].p2.y-I[b].p2.y)<.5});O?O.push(b):k.length>=2?j(b,"would need a third lane in its corridor"):k.push([b]),H.set(A.corridor,k)}for(const b of[...M.keys()])D.has(b)&&M.delete(b);const Z=b=>{const A=o.edges[b[0]];return Math.abs(o.byId.get(A.from).col-o.byId.get(A.to).col)*1e4+Math.abs(I[b[0]].p1.x-I[b[0]].p2.x)},K=(b,A,L)=>{const k=c.rows;if(b==="top")return k[0][0]-d("4")-A*d("3");if(b==="bottom")return k[k.length-1][1]+d("4")+A*d("3");const O=Number(b.slice(1));return(k[O-1][1]+k[O][0])/2+(A-(L-1)/2)*d("3")},ot=(b,A)=>A.forEach((L,k)=>L.forEach(O=>{M.get(O).y=K(b,k,A.length)})),P=()=>{for(const[b,A]of H){const L=A.map(k=>k.filter(O=>M.has(O))).filter(k=>k.length);H.set(b,L),ot(b,b==="top"||b==="bottom"?L.slice().sort((k,O)=>Z(k)-Z(O)):L.slice().sort((k,O)=>Z(O)-Z(k)))}};P();const J=new Map,m=new Set,y=new Map,E=(b,A,L,k,O)=>{J.has(b)||J.set(b,{span:A,vertical:L,members:new Map});const F=J.get(b);F.members.has(k)||F.members.set(k,[]),F.members.get(k).push(O)},q=()=>{J.clear(),m.clear(),y.clear(),o.edges.forEach((b,A)=>{if(D.has(A))return;const L=M.get(A);L?.first&&E(L.first.key,L.first.span,!0,`far:${A}`,-(A+1));const[k,O]=S[A],{p1:F,p2:X}=I[A],Q=o.byId.get(b.from),at=o.byId.get(b.to);let st=null,tt=null,N=!1;if(k===O){if(dt(k)){const V=k==="right"?Math.max(C(Q),C(at)):Math.min(C(Q),C(at))-1,Y=c.cols[V-1],et=c.cols[V];Y&&et&&(st=`c${V}`,tt=[Y[1],et[0]],N=!0)}else{const V=k==="bottom"?Math.max(Q.row2,at.row2):Math.min(Q.row,at.row)-1,Y=c.rows[V-1],et=c.rows[V];Y&&et&&(st=`r${V}`,tt=[Y[1],et[0]],N=!1)}st&&m.add(A)}else if(dt(k)&&dt(O)&&(L||Math.abs(F.y-X.y)>.5)){const V=C(at),Y=O==="left",et=c.cols[(Y?V-1:V)-1],$t=c.cols[(Y?V:V+1)-1];et&&$t&&(st=`c${Y?V-1:V}`,tt=[et[1],$t[0]],N=!0)}else if(!dt(k)&&!dt(O)&&Math.abs(F.x-X.x)>.5){const Y=O==="top"?at.row-1:at.row2,et=c.rows[Y-1],$t=c.rows[Y];et&&$t&&(st=`r${Y}`,tt=[et[1],$t[0]],N=!1)}!st||!tt||(L&&y.set(A,tt),E(st,tt,N,`${b.to}.${O}.${Math.round(N?X.y:X.x)}`,A))})};q();const _=new Map,R=b=>{const[A,L]=S[b],{p1:k,p2:O}=I[b],F=M.get(b);if(F){const X=y.get(b),Q=_.get(-(b+1))??(F.first?(F.first.span[0]+F.first.span[1])/2:k.x),at=_.get(b)??(X?(X[0]+X[1])/2:O.x);return[k,{x:Q,y:k.y},{x:Q,y:F.y},{x:at,y:F.y},{x:at,y:O.y},O]}if(dt(A)&&dt(L)){if(A===L){const Q=d(o.marks?"6":"4")+(o.type==="schema"&&o.cols===1?(Jt(o).lane.get(b)??0)*d("3"):0),at=_.get(b)??(A==="right"?Math.max(k.x,O.x)+Q:Math.min(k.x,O.x)-Q);return[k,{x:at,y:k.y},{x:at,y:O.y},O]}if(Math.abs(k.y-O.y)<=.5)return[k,{x:O.x,y:k.y}];const X=_.get(b)??(k.x+O.x)/2;return[k,{x:X,y:k.y},{x:X,y:O.y},O]}if(!dt(A)&&!dt(L)){if(A===L){const Q=_.get(b)??(A==="bottom"?Math.max(k.y,O.y)+d("4"):Math.min(k.y,O.y)-d("4"));return[k,{x:k.x,y:Q},{x:O.x,y:Q},O]}if(Math.abs(k.x-O.x)<=.5)return[k,{x:k.x,y:O.y}];const X=_.get(b)??(k.y+O.y)/2;return[k,{x:k.x,y:X},{x:O.x,y:X},O]}return dt(A)?[k,{x:O.x,y:k.y},O]:[k,{x:k.x,y:O.y},O]},U=b=>{const A=o.edges[b],L=Ut(A.kind,l),k=R(b),O=je(k,L,p);let F;return k.length===O.length&&(F=_t(k).map(([X,Q])=>Math.abs(X.y-Q.y)<.75?(X.y+Q.y)/2:(X.x+Q.x)/2),F[0]=I[b].r1,F.length>1&&(F[F.length-1]=I[b].r2)),{i:b,from:A.from,to:A.to,kind:A.kind,pts:O,tip:O[O.length-1],dir:le(O),dot:A.fk&&!A.card?O[0]:void 0,card:A.card,width:L,axes:F}},G=()=>o.edges.flatMap((b,A)=>D.has(A)?[]:[U(A)]);let ht=null;const pt=b=>{ht??(ht=G());const A=ht.map(L=>b.has(L.i)?U(L.i):L);return{lines:A,score:Nn(A,b)*1e5+Qt(A,void 0,b).length*1e3+fe(A.filter(L=>b.has(L.i)),f,o).length}},lt=(b,A)=>{const L=b.flatMap(k=>{const O=k<0?-k-1:k,{p1:F,p2:X}=I[O],Q=M.get(O);return Q?k<0?[F.y,Q.y]:[Q.y,X.y]:A?[F.y,X.y]:[F.x,X.x]});return[Math.min(...L),Math.max(...L)]},ct=b=>b<0?-b-1:b,mt=b=>{const A=[...b.members.values()].map(k=>({members:k,run:lt(k,b.vertical)})).sort((k,O)=>k.run[0]-O.run[0]),L=[];for(const k of A){const O=L[L.length-1];O&&O.some(F=>F.run[0]!(k.length===1&&k[0].members.every(O=>m.has(O))))},wt=b=>(A,L)=>b[A].run[0]{const A=wt(b),L=[];return b.forEach((k,O)=>{let F=0;for(;L.some((X,Q)=>X===F&&A(O,Q));)F++;L.push(F)}),L},vt=b=>Math.max(0,...Mt(b))+1;if(o.marks)for(let b=0;b3){A=F.map(X=>X.members.map(ct));break}if(!A)break;const L=O=>Math.max(...O),k=A.filter(O=>O.some(F=>M.has(F))).sort((O,F)=>L(F)-L(O))[0]??A.slice().sort((O,F)=>L(F)-L(O))[0];for(const O of k)j(O,"would need a fourth lane in a marked gutter"),M.delete(O);q()}const ut=(b,A,L)=>{const k=b[1]-b[0];if(!o.marks)return b[0]+k/(L+1)*(A+1);const O=l.foot+l.radiusXs,F=L>1?Math.min(k/(L+1),(k-2*O)/(L-1)):0;return(b[0]+b[1])/2+(A-(L-1)/2)*F};P();for(const[b,A]of H){if(b==="top"||b==="bottom"||A.length<2)continue;const L=new Set(A.flat());let k=A,O=1/0;for(const F of de(A.slice().sort((X,Q)=>Z(Q)-Z(X)))){ot(b,F),ht=null;const X=pt(L);X.scoreat.members);if(o.marks){const at=vt(A),st=wt(A),tt=A.length,N=new Set(L.flat().map(ct)),V=St=>St.forEach((xt,Rt)=>L[Rt].forEach(Ot=>_.set(Ot,ut(b.span,xt,at))));let Y=Mt(A),et=1/0,$t=null;const Bt=[Y];if(at**tt<=729)for(let St=0;StMath.floor(St/at**Ot)%at);xt.every((Rt,Ot)=>xt.every((Gt,te)=>te<=Ot||Rt!==Gt||!st(Ot,te)))&&Bt.push(xt)}for(const St of Bt){V(St);const xt=pt(N);xt.scorett.forEach(V=>_.set(V,ut(b.span,N,k))));const st=pt(O);st.scoreat.forEach(tt=>_.set(tt,ut(b.span,st,k)))),ht=Q}if(v.lines=G(),o.marks&&(v.lines=v.lines.filter(b=>{if(!b.card)return!0;const A=_t(b.pts),L=([O,F])=>Math.hypot(F.x-O.x,F.y-O.y),k=A.length===1?2*l.foot:l.foot+l.radiusXs-.5;return L(A[0])>=k&&L(A[A.length-1])>=k?!0:(j(b.i,"has no room for its marks at an end"),!1)})),M.size){const b=new Set([...M.values()].map(L=>L.corridor)),A=[b.has("top")?"var(--basalt-space-8)":"0px"];for(let L=1;L<=o.rows;L++)A.push("auto",LWe(b,l));const bt=zn(o,v.lines,f,ft,it,{l:0,t:0,r:u,b:x},l,e,{ox:g,oy:$});return v.labels=bt.labels,v.unseated=bt.unseated,v.bounded=bt.bounded,v.overlaps=[...new Set(Ve(v.lines,null).flat())],v}function Nn(t,e){return Ve(t,e).length}function Ve(t,e){const n=[];for(let o=0;o=r)continue;const[u,x]=c?[i.x,d.x]:[i.y,d.y],[C,W]=c?[h.x,f.x]:[h.y,f.y];Math.min(Math.max(u,x),Math.max(C,W))-Math.max(Math.min(u,x),Math.min(C,W))>1&&n.push([a.i,s.i])}}return n}function*de(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const i=r===a.pts.length-1?Math.max(a.width/2,o.head/2):a.width/2;return s.x-i<-.5||s.x+i>e+.5||s.y-i<-.5||s.y+i>n+.5})&&l.push(a.i);return l}function fe(t,e,n){const o=[];for(const l of t){const a=_t(l.pts);e.some(s=>a.some(([r,i])=>Cn(r,i,s)))&&o.push(l.i)}return o}function Wn(t,e,n){const{m:o,tk:l,P:a,drawing:s,origin:r}=t,i=l.space,d=new Map;s.querySelectorAll(`.${a}-node`).forEach(v=>d.set(v.dataset.node,Et(v,r)));const h=s.querySelector(`.${a}-steps`),f=h?Et(h,r).b:e.h,c=v=>{const S=d.get(v);return S?n.x((S.l+S.r)/2,l.hair):0};for(const v of o.nodes){const S=d.get(v.id);S&&e.lifelines.push({x:c(v.id),y1:S.b,y2:f})}const g=v=>d.get(v.id),$=new Map;s.querySelectorAll(`.${a}-msg`).forEach(v=>{const S=Et(v,r);$.set(Number(v.querySelector(`.${a}-num`)?.textContent??0),(S.t+S.b)/2)});const p=l.activation,u=p/2,x=v=>{const S=o.byId.get(v.who);if(!S)return null;const T=c(v.who),z=(S.i===o.nodes.length-1&&o.nodes.length>1?-1:1)*(o.rtl?-1:1),rt=(v.depth-1)*i("1")*z,I=$.get(v.from)??0,D=$.get(v.to)??I,j=v.from===v.to;return{l:n.x(T-u+rt,l.hair),r:n.x(T+u+rt,l.hair),t:n.y(j?I-i("2")-i("1"):I,l.hair),b:n.y(j?I+i("2")+i("1"):D,l.hair)}},C=o.bars.map(v=>({bar:v,rect:x(v)})).filter(v=>v.rect);e.bars=C.map(v=>v.rect);const W=(v,S,T)=>C.filter(({bar:nt})=>nt.who===v&&nt.to>=S&&(T?nt.from<=S:nt.fromz.bar.depth-nt.bar.depth)[0]?.rect;return s.querySelectorAll(`.${a}-msg`).forEach(v=>{const S=v.dataset.from,T=v.dataset.to,nt=v.dataset.kind??"plain",z=Ut(nt,l),rt=Et(v,r),I=n.y((rt.t+rt.b)/2,z),D=Number(v.querySelector(`.${a}-num`)?.textContent??0);let j=c(S),M=c(T),B;if(S===T){const m=v.dataset.self==="start"?-i("6"):i("6"),y=W(S,D,!0),E=y?m>0?y.r:y.l:j,q=n.y(I-i("2"),z),_=n.y(I+i("2"),z);B=[{x:E,y:q},{x:n.x(j+m,z),y:q},{x:n.x(j+m,z),y:_},{x:E,y:_}]}else{const m=M>j?1:-1,y=W(S,D,!1),E=W(T,D,!0);y&&(j=m>0?y.r:y.l),E&&(M=m>0?E.l:E.r),B=[{x:j,y:I},{x:M,y:I}]}e.lines.push({i:D,from:S,to:T,kind:nt,pts:B,tip:B[B.length-1],dir:le(B),width:z});const H=v.querySelector(`.${a}-said`),Z=v.querySelector(`.${a}-note`),K=o.byId.get(S),ot=o.byId.get(T);if(!K||!ot)return;const P=S===T?(()=>{const m=o.nodes[K.i+(v.dataset.self==="start"?-1:1)],y=m?c(m.id):v.dataset.self==="start"?0:e.w;return Math.abs(y-j)-i("6")-i("2-5")-i("2")})():Math.abs(M-j)-2*i("2");Math.max(H?H.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>P+.5&&e.unseated.push(D)}),s.querySelectorAll(`.${a}-fhead`).forEach(v=>{const S=v.parentElement?.querySelector(`:scope > .${a}-fbox`);if(!S)return;[...v.children].reduce((nt,z)=>nt+z.getBoundingClientRect().width,0)+i("3")>S.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${v.querySelector(`.${a}-flabel`)?.textContent??""}" is wider than its participants`)}),e}function Ze(t,e,n,o=At()){const{m:l,tk:a,P:s,drawing:r,origin:i}=t,d=a.space,h=Ne(l,r,i,s),f=[...h.values()],c=i.left-Math.floor(i.left),g=i.top-Math.floor(i.top),$=Ce(c,g),p=r.clientWidth,u=r.clientHeight,x={w:p,h:u,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:c,oy:g},C=At();if(l.type==="sequence"||l.type==="schema")return{geo:x,grow:C};const W=p-(parseFloat(getComputedStyle(r).paddingRight)||0),v=(M,B,H)=>{const Z=[M];for(let K=1;K<=(qt(o,B)??0);K++)Z.push({...M,t:M.t+H*d("4")*K,b:M.b+H*d("4")*K});return Z},S=new Map;r.querySelectorAll(`.${s}-node`).forEach(M=>{const B=M.parentElement,H=Et(B,i),Z=getComputedStyle(B);S.set(M.dataset.node,H.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const T=l.nodes,nt=M=>h.get(T[M].id),z=[],rt=M=>Ut(l.edges[M].kind,a);l.edges.forEach((M,B)=>{const H=n.routes[B],Z=h.get(M.from),K=h.get(M.to),ot=rt(B);let P=[];const J=M.label,m=J?e(J,"label"):0,y=J?16*ne(J):16,E=d("4");if(H==="down"||H==="up"){const _=Math.max(Z.rect.l,K.rect.l),R=Math.min(Z.rect.r,K.rect.r),U=l.edges.map((lt,ct)=>({o:lt,j:ct})).filter(({o:lt,j:ct})=>(n.routes[ct]==="down"||n.routes[ct]==="up")&&(lt.from===M.from&<.to===M.to||lt.from===M.to&<.to===M.from)),G=U.findIndex(lt=>lt.j===B),ht=U.length<2?.5:U.length===2?G===0?.25:.75:(G+1)/(U.length+1),pt=$.x(_+(R-_)*ht,ot);if(P=H==="down"?[kt(Z,"bottom",pt),kt(K,"top",pt)]:[kt(Z,"top",pt),kt(K,"bottom",pt)],J){let lt=Math.min(P[0].y,P[1].y),ct=Math.max(P[0].y,P[1].y);H==="down"?ct-=a.head:lt+=a.head;const mt=[...r.querySelectorAll(`.${s}-group`)].map(ut=>Et(ut,i));let wt=[[lt,ct]];for(const ut of mt)for(const ft of[ut.t,ut.b])wt=wt.flatMap(([it,bt])=>ft>it+1&&ftmt.some(it=>(ut+ft)/2>it.t&&(ut+ft)/2it.l&&pt1){const ut=wt.filter(([it,bt])=>!Mt(it,bt));[lt,ct]=(ut.length?ut:wt).reduce((it,bt)=>bt[1]-bt[0]>it[1]-it[0]?bt:it)}const vt=[1/2,1/3,2/3].map(ut=>{const ft=lt+(ct-lt)*ut;return{l:pt-m/2-d("1"),r:pt+m/2+d("1"),t:ft-y/2,b:ft+y/2}});z.push({k:B,cands:vt,on:!0,card:H==="down"?M.to:M.from})}}else if(H==="trunk"||H==="rail"){const _=$.x(Math.max(Z.rect.l,H==="rail"?K.rect.l:Z.rect.l)+d(H==="trunk"?"8":"3"),ot),R=kt(Z,"bottom",_);if(H==="rail"){if(P=[R,kt(K,"top",_)],J){const U=K.rect.t-d("6");z.push({k:B,cands:v({l:_+d("2-5"),r:_+d("2-5")+m,t:U-y/2,b:U+y/2},M.to,-1),on:!1,card:M.to})}}else{const U=$.x(K.rect.l+d("6"),ot),G=$.y(K.rect.t-E,ot);P=[R,{x:_,y:G},{x:U,y:G},kt(K,"top",U)],J&&z.push({k:B,cands:v({l:U+d("2-5"),r:U+d("2-5")+m,t:G-y/2,b:G+y/2},M.to,-1),on:!1,card:M.to})}}else{const _=Math.min(S.get(M.from)??p,S.get(M.to)??p),R=$.x(n.gutter?W+(n.lanes[B]+1)*d("3-5"):_-d("2-5"),ot),U=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[B],ot),G=kt(Z,"right",U),ht=H==="end-down",pt=l.edges.map((ft,it)=>({o:ft,j:it})).filter(({o:ft,j:it})=>n.routes[it]===H&&ft.to===M.to).sort((ft,it)=>n.lanes[it.j]-n.lanes[ft.j]||ft.j-it.j),lt=Math.max(0,pt.findIndex(({j:ft})=>ft===B)),ct=K.rect.r-d("6")-lt*d("3"),mt=K.rect.r-d("6")-(pt.length-1)*d("3"),wt=$.x(ct,ot),Mt=ht?K.rect.t-E-lt*d("5"):K.rect.b+E+lt*d("5"),vt=$.y(Mt,ot);P=[G,{x:R,y:G.y},{x:R,y:vt},{x:wt,y:vt},kt(K,ht?"top":"bottom",wt)];const ut=ht?M.to:T[K.i+1]?.id??M.to;J&&z.push({k:B,cands:v({l:mt-d("2-5")-m,r:mt-d("2-5"),t:Mt-y/2,b:Mt+y/2},ut,ht?-1:1),on:!1,card:ut})}const q=je(P,ot,$);x.lines.push({i:B,from:M.from,to:M.to,kind:M.kind,pts:q,tip:q[q.length-1],dir:le(q),width:ot})}),x.crossings=Qt(x.lines),x.through=fe(x.lines,f,l),x.outside=Ke(x.lines,p,u,a);const{obstacles:I}=De(r,i,s,0);I.heads=x.lines.map(M=>We(M,a));const D=[],j={l:0,t:0,r:p,b:u};for(const M of z){const B=K=>{const ot=Oe(K,d("1"));return K.lj.r+.5||K.tj.b+.5||f.some(P=>qe(ot,P))||D.some(P=>It(ot,P))||I.heads.some(P=>It(ot,P))||I.rects.some(P=>It(ot,P))||x.lines.some(P=>P.i!==M.k&&_t(P.pts).some(([J,m])=>It(ot,Fe(J,m,P.width))))},H=M.cands.find(K=>!B(K));H||(C[M.card]=(C[M.card]??0)+1,x.unseated.push(M.k));const Z=H?He(H,c,g,K=>!B(K)):M.cands[0];D.push(Z),x.labels.push({i:M.k,text:l.edges[M.k].label,box:Z,on:M.on})}return{geo:x,grow:C}}function Je(t,e,n=0){const o=s=>String(Math.round(s*100)/100);let l=`M${o(t[0].x)} ${o(t[0].y)}`;for(let s=1;s{const{crow:D,ring:j}=Ee(nt,z.x,z.y,rt,n.head,n.dot);return`${j?``:""}`};return`${T(e.card.from,v,Math.sign(S.x-v.x)||1,"from")}${T(e.card.to,e.tip,-a.x||1,"to")}`}const s=e.kind==="dashed",r=n.head,i=n.head/2,d=s?1:r-1,h=e.pts.map(v=>({...v})),f=h[h.length-1];f.x-=a.x*d,f.y-=a.y*d;const c=e.tip.x-a.x*r,g=e.tip.y-a.y*r,$=-a.y*i,p=a.x*i,u=v=>Math.round(v*100)/100,x=yt(e.kind),C=s?``:``,W=e.dot?``:"";return`${C}${W}`}function Xe(t,e,n,o){const l=new Map,a=new Map;for(const r of e.crossings)a.has(r.under)||a.set(r.under,[]),a.get(r.under).push(r);let s="";for(const[r,i]of a){const d=`${o}-cut-${r}`;l.set(r,d);const h=i.map(f=>{const c=e.lines[f.top],g=e.lines[f.under],$=c.width/2+n.cut,p=g.width/2+1;return f.underVertical?``:``}).join("");s+=`${h}`}return{defs:s,ids:l}}function Ue(t,e,n,o){const{defs:l,ids:a}=Xe(t,e,n,o),s=e.lifelines.map(h=>``).join("")+(e.bars??[]).map(h=>``).join(""),r=e.lines.map((h,f)=>Hn(t,h,n,a.get(f)??null,h.from===h.to?n.radiusXs:n.radius)).join(""),i=`${l?`${l}`:""}${s}${r}`,d=e.labels.map(h=>`1?' data-lines="2"':""} style="left:${Math.round(h.box.l*100)/100}px;top:${Math.round(h.box.t*100)/100}px;width:${Math.round((h.box.r-h.box.l)*100)/100}px">${h.text.split(` -`).map(yt).join("
")}
`).join("");return i+d}function ue(t,e,n,o,l,a,s,r){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:l,geo:null,ink:"",tokens:null};const h=On(t),f=Bn(d,n),c=Rn(e,h,f);r?.(c.least);const g=t.clientWidth,$=(()=>{const I=document.activeElement;return I&&d.contains(I)&&I.dataset.node?I.dataset.node:void 0})(),p=I=>jt(e,I)?{...I,stop:I.stop&&e.byId.has(I.stop)?I.stop:e.nodes[0]?.id,keep:void 0}:{...I,stop:I.stop??e.nodes[0]?.id,keep:$&&I.layout!=="drawn"?$:void 0};let u=!1;const x=I=>{if(u=!1,e.type!=="flowchart")return I;a({...I,heights:void 0,words:void 0});const D=At(),j=At();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(M=>{const B=M.querySelector(`.${n}-words`);if(!B)return;const H=M.getBoundingClientRect(),Z=P=>{const J={w:P.width+2*h.space("2-5"),h:P.height+2*h.space("2")},m=1-J.w/H.width,y=m>.05?J.h/2/m:J.h*10;return Math.max(h.space("16"),Math.ceil(H.width/5),Math.ceil(2*y))},K=B.getBoundingClientRect();let ot=Z(K);if(ot>H.width){const P=E=>(M.style.setProperty("--_ww",`${E}px`),B.getBoundingClientRect()),J=Math.floor(M.clientWidth-2*h.space("2-5"));let m=Math.ceil(K.width),y=K.height;for(;m1;){const U=E+q>>1;P(U).heightH.width&&(u=!0)}),{...I,heights:D,words:Object.keys(j).length?j:void 0}},C=()=>({m:e,tk:h,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:s}),W=l.autoOpen?{open:!1,autoOpen:void 0}:{},v=(I,D)=>D.map(j=>Dt(e,I.lines.find(M=>M.i===j))).join(", ");if(e.text)return{dyn:{...l,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:h,least:c.least};if(g>=c.least&&!e.unplaced){const I=B=>{let H=p({...l,...W,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:B||void 0,rows:void 0});H=x(H),a(H);let Z=Ge(C(),f);return Z.corridors&&(H={...H,rows:Z.corridors.rows},a(H),Z=Ge({...C(),pick:Z.corridors.pick},f)),{dd:H,g:Z}};let{dd:D,g:j}=I(!1);const M=B=>B.through.length>0||B.outside.length>0||(B.overlaps?.length??0)>0||(B.misfit?.length??0)>0||u;if(!M(j)&&j.unseated.length&&j.unseated.every(B=>j.bounded?.includes(B))){const B=I(!0);!M(B.g)&&!B.g.unseated.length&&({dd:D,g:j}=B)}if(!M(j)&&!j.unseated.length)return j.crossings.length&&s?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the drawn layout: ${j.crossings.map(B=>`${Dt(e,j.lines[B.top])} over ${Dt(e,j.lines[B.under])}`).join("; ")}`),{dyn:D,geo:j,ink:Ue(n,j,h,o),tokens:h,least:c.least};u&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: a decision would be taller than it is wide`),j.misfit?.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: ${j.misfit.join("; ")}`),j.through.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: ${v(j,j.through)} would pass through a node`),j.overlaps?.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: ${v(j,j.overlaps)} would lie on one another`),j.outside.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: ${v(j,j.outside)} would leave the drawing`),j.unseated.length&&s?.(`the drawn layout does not fit at ${Math.round(g)}px: no clean seat for ${j.unseated.map(B=>e.type==="sequence"?`message ${B}`:`"${Lt(e.edges[B]?.label??"")}"`).join(", ")}`)}let S=p({...l,...W,layout:"stacked",heights:void 0,grow:At(),track:e.type==="schema"?c.table:void 0,bare:void 0,pad:void 0,rows:void 0});if(S=x(S),a(S),e.type==="sequence"||e.type==="schema")return{dyn:S,geo:null,ink:"",tokens:h,least:c.least};const T=Me(e);let nt=Ze(C(),f,T,S.grow);for(let I=0;I<6&&Object.keys(nt.grow).length;I++){const D=At(S.grow);for(const[j,M]of Object.entries(nt.grow))D[j]=(qt(D,j)??0)+M;S={...S,grow:D},a(S),nt=Ze(C(),f,T,D)}const z=nt.geo;if(!T.third&&T.laneCount>2&&s?.(`the stacked drawing uses ${T.laneCount} end lanes (four at most)`),z.unseated.length>0||z.through.length>0||z.outside.length>0||T.third){z.unseated.length&&s?.(`the stacked drawing has no clean seat for ${[...new Set(z.unseated)].map(j=>`"${Lt(e.edges[j]?.label??"")}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),z.through.length&&s?.(`in the stacked drawing ${v(z,z.through)} would pass through a node, so its lines are not drawn`),z.outside.length&&s?.(`in the stacked drawing ${v(z,z.outside)} would leave the drawing, so its lines are not drawn`),T.third&&s?.("the stacked drawing would need a fifth end lane, so its lines are not drawn");const I={...z,lines:[],labels:[],crossings:[]};return{dyn:p({...S,grow:At(),bare:!0,open:l.bare?l.open:!0,autoOpen:l.bare?l.autoOpen:l.open?void 0:!0}),geo:I,ink:"",tokens:h,least:c.least}}return z.crossings.length&&s?.(`${z.crossings.length} crossing${z.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${z.crossings.map(I=>`${Dt(e,z.lines[I.top])} over ${Dt(e,z.lines[I.under])}`).join("; ")}`),{dyn:S,geo:z,ink:Ue(n,z,h,o),tokens:h,least:c.least}}function Dt(t,e){const n=t.byId.get(e.from)?.name??e.from,o=t.byId.get(e.to)?.name??e.to;return`${n} to ${o}`}function Dn(t,e,n,o,l,a){const s=new Set;if(a){s.add(a);for(const p of n?.lines??[])p.from===a&&s.add(p.to),p.to===a&&s.add(p.from)}if(t.toggleAttribute("data-tracing",!!a),t.querySelectorAll(`.${e}-node`).forEach(p=>p.toggleAttribute("data-near",s.has(p.dataset.node))),!n||!o)return;const r=p=>!!a&&(p.from===a||p.to===a),i=t.querySelector(`.${e}-edges`),d=new Map;t.querySelectorAll(`.${e}-edge`).forEach(p=>d.set(p.getAttribute("data-edge"),p));for(const p of n.lines){const u=d.get(String(p.i));u&&(u.toggleAttribute("data-lit",r(p)),u.toggleAttribute("data-dim",!!a&&!r(p)))}if(t.querySelectorAll(`.${e}-label`).forEach(p=>{const u=n.lines.find(x=>String(x.i)===p.dataset.edge);p.toggleAttribute("data-lit",!!(u&&r(u)))}),i){for(const p of n.lines)if(r(p)){const u=d.get(String(p.i));u&&i.appendChild(u)}}const h=Qt(n.lines,r),{defs:f,ids:c}=Xe(e,{...n,crossings:h},o,l),g=t.querySelector(`.${e}-svg`);if(!g)return;let $=g.querySelector("defs");!$&&f&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),g.insertBefore($,g.firstChild)),$&&($.innerHTML=f),n.lines.forEach((p,u)=>{const x=d.get(String(p.i))?.querySelector(`.${e}-line`);if(!x)return;const C=c.get(u);C?x.setAttribute("mask",`url(#${C})`):x.removeAttribute("mask")})}var Gn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Vn(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Gn()||Zn(t)?"done":"pending")}}var Kn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Zn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Kn(t))!==null}catch{return!1}}function Ye(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Jn(t,e,n,o=!1,l=!1){const a=o?Zt(t):null;if(a&&n.startsWith("Arrow")){const d={ArrowRight:l?"left":"right",ArrowLeft:l?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return d?a[e]?.[d]??null:null}const s=t.byId.get(e)?.i??0,r=t.nodes.length;let i;if(n==="ArrowRight"||n==="ArrowDown")i=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")i=s-1;else if(n==="Home")i=0;else if(n==="End")i=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,i))].id}var Xn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],Qe=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl"],Un=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad","--_gw","--_mh","--_rows","--_row-gap"],Pe=t=>t==null||t===!1;function Yn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Pt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const o=n?Qe:Xn;for(const s of o)Pe(e.a[s])&&t.removeAttribute(s);for(const[s,r]of Object.entries(e.a)){if(s==="class")continue;if(s==="style"){const d=t.style,h=new Map(String(r??"").split(";").map(f=>{const c=f.indexOf(":");return[f.slice(0,c).trim(),f.slice(c+1).trim()]}).filter(([f])=>f));for(const[f,c]of h)d.getPropertyValue(f).trim()!==c&&d.setProperty(f,c);for(const f of Un)h.has(f)||d.removeProperty(f);continue}if(n&&!Qe.includes(s))continue;if(Pe(r)){t.removeAttribute(s);continue}const i=r===!0?"":String(r);t.getAttribute(s)!==i&&t.setAttribute(s,i)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(s=>typeof s!="string"&&"slot"in s))return;const l=[...t.children];let a=0;for(const s of e.c)if(!(typeof s=="string"||"slot"in s)){for(let r=a;rt.querySelector(`.${e}-node[data-node="${CSS.escape(a)}"]`);n&&l(n)?.setAttribute("tabindex","-1"),l(o)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",o=0;function l(c,g,$){return{prefix:n,base:c,hasSource:g.source!==void 0&&g.source!==null&&g.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function a(c,g,$,p){var u=function(x){return''+yt(x)+""};return{source:yt(String(g.source||"")),summary:yt(String(g.summary||"")),hint:re(c).map(function(x){return""+x.keys.map(u).join(" ")+" "+yt(x.words)+""}).join(""),toggle:'"}}function s(c,g,$){var p=zt(c),u=Xt(p,{},l(g,c,$)),x=oe(u,a(p,c,g,!1)),C=x.indexOf(">");return{open:x.slice(0,C+1),inner:x.slice(C+1,x.length-9),warnings:p.warnings}}var r=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-marks","data-layout","data-measured","data-bare"],i=["--_cols","--_gpad","--_track"];function d(c,g,$,p){c.__diagram&&c.__diagram.stop();var u=(c.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),x=getComputedStyle(c).direction==="rtl",C=g.layout==="auto"&&(g.type==="architecture"||g.type==="flowchart"||g.type==="schema"),W=C?Array.isArray(g.placement)?g.placement:g.placement?[g.placement]:[]:[];C&&!W.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var v=g.direction?[g.direction]:g.type==="flowchart"?["down","right"]:["right","down"],S=function(N){for(var V=0;V .diagram-drawing")){if(!u||!c.querySelector("#"+CSS.escape(u+"-title"))){for(;document.getElementById("dg"+ ++o+"-title"););u="dg"+o}var nt=s(g,u,p),z=document.createElement("div");z.innerHTML=nt.open+"";var rt=z.firstChild;r.forEach(function(N){c.removeAttribute(N)}),i.forEach(function(N){c.style.removeProperty(N)});for(var I=0;I :not(script[data-diagram])").forEach(function(N){N.remove()}),c.insertAdjacentHTML("beforeend",nt.inner)}T.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)});var j=l(u,g,p),M={},B=null,H=null,Z=null,K=null,ot=Object.create(null),P=function(N){ot[N]||(ot[N]=1,console.warn("Basalt diagram: "+N))},J=function(N){Pt(c,Xt(T,N,j))},m=c.querySelector(".diagram-ink"),y=c.querySelector(".diagram-toggle"),E=!p&&T.motion.animated&&typeof e.diagramMotion=="function",q=null,_=null,R=function(){E&&Ye(c)};function U(){Dn(c,n,B&&B.geo,B&&B.tokens,u,H||K||Z),pt()}var G=null,ht=!p&&matchMedia("(hover: none), (pointer: coarse)").matches;function pt(){var N=ht&&!p&&m&&m.innerHTML!=="";if(c.toggleAttribute("data-touch",!!(ht&&!p)),N&&!G){var V=c.querySelector(":scope > .diagram-foot");if(!V)return;G=document.createElement("button"),G.type="button",G.className="btn diagram-clear",G.setAttribute("data-variant","secondary"),G.setAttribute("data-size","sm"),G.innerHTML="Clear highlight",G.addEventListener("click",function(){K&&(K=null,U())}),V.appendChild(G)}else!N&&G&&(G.remove(),G=null);G&&(K?G.removeAttribute("aria-disabled"):G.setAttribute("aria-disabled","true"))}function lt(N){if(!N.defaultPrevented){var V=un(c,n,N,K);V!==void 0&&(R(),ht=!0,K=V,U())}}function ct(){y&&(y.setAttribute("aria-expanded",String(!!M.open)),y.firstElementChild.textContent=M.open?"Hide the list":"View as list")}function mt(){if(C&&W.length>1&&!p){for(var N=null,V=0;V1&&p&&!g.direction&&p.room){for(var Bt=p.room(),St=-1,xt=null,Rt=0;RtSt+1e-6&&(St=tn,xt=Gt)}}}xt&&(T=xt)}B=(p?p.measure:ue)(c,T,n,u,M,J,P),M=B.dyn,J(M),ct();var he=c.querySelector(":scope > .diagram-hint");if(he){var en=re(T,M.layout==="drawn").map(function(Wt){return""+Wt.keys.map(function(Pn){return''+yt(Pn)+""}).join(" ")+" "+yt(Wt.words)+""}).join("");he.innerHTML!==en&&(he.innerHTML=en)}jt(T,M)||(Z=K=null);var nn=m&&B.ink!==_;nn&&(m.innerHTML=B.ink,_=B.ink),U(),E&&B.tokens&&(Vn(c,!!(B.geo&&B.geo.lines.length)),nn&&q&&q.redrawn()),p&&p.onMeasured&&B.tokens&&p.onMeasured(B,c),T.text&&typeof e.diagramText=="function"&&e.diagramText(c,T,g)}function wt(N){M=N,J(M)}function Mt(N){var V=M.stop;M=Object.assign({},M,{stop:N}),Qn(c,n,V,N)}var vt=function(N){var V=N&&N.closest?N.closest(".diagram-node"):null;return V&&c.contains(V)?V:null};function ut(N){var V=vt(N.target);if(!(!V||N.defaultPrevented)){if(R(),N.key==="Escape"){!p&&(H||Z||K)&&(N.preventDefault(),H=Z=K=null,U());return}if(jt(T,M)){var Y=Jn(T,V.getAttribute("data-node"),N.key,M.layout==="drawn");if(Y){N.preventDefault(),Mt(Y);var et=c.querySelector('.diagram-node[data-node="'+CSS.escape(Y)+'"]');et&&et.focus()}}}}function ft(N){var V=vt(N.target);if(V){R();var Y=V.getAttribute("data-node");H=V.matches(":focus-visible")?Y:null,jt(T,M)&&M.stop!==Y&&Mt(Y),U()}}function it(N){var V=vt(N.target);V&&(vt(N.relatedTarget)||(H=null),M.keep===V.getAttribute("data-node")&&wt(Object.assign({},M,{keep:void 0})),U())}function bt(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var V=vt(N.target);V&&R();var Y=V&&jt(T,M)?V.getAttribute("data-node"):null;Y!==Z&&(Z=Y,U())}}function b(){Z&&(Z=null,U())}function A(){R(),wt(Object.assign({},M,{open:!M.open,autoOpen:void 0})),ct()}c.addEventListener("keydown",ut),c.addEventListener("focusin",ft),c.addEventListener("focusout",it),c.addEventListener("pointerover",bt),c.addEventListener("pointerleave",b),c.addEventListener("click",lt),y&&y.addEventListener("click",A),mt();var L=c.clientWidth,k=0,O=!0,F=new ResizeObserver(function(){Math.abs(c.clientWidth-L)<.5||(L=c.clientWidth,cancelAnimationFrame(k),k=requestAnimationFrame(mt))});F.observe(c),document.fonts&&document.fonts.ready.then(function(){O&&mt()});var X=matchMedia("(forced-colors: active)"),Q=T.nodes.some(function(N){return N.mark});Q&&X.addEventListener("change",mt),E&&(q=e.diagramMotion(c,{fig:c,P:n,base:u,model:function(){return T},geo:function(){return B&&B.geo},tokens:function(){return B&&B.tokens}},g));var at=!p&&g.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(c,g,{model:T,settle:R,animated:E}):null,st=c.querySelector(":scope > .diagram-foot"),tt=!p&&g.export===!0&&st&&typeof e.diagramExport=="function"?e.diagramExport(st,c):[];c.__diagram={stop:function(){at&&at.destroy(),tt.forEach(function(N){N.remove()}),O=!1,F.disconnect(),cancelAnimationFrame(k),Q&&X.removeEventListener("change",mt),q&&q.destroy(),c.removeEventListener("keydown",ut),c.removeEventListener("focusin",ft),c.removeEventListener("focusout",it),c.removeEventListener("pointerover",bt),c.removeEventListener("pointerleave",b),c.removeEventListener("click",lt),G&&G.remove(),y&&y.removeEventListener("click",A)},layout:mt,key:h(g),send:q&&q.sendValue?q.sendValue:null}}function h(c){try{return JSON.stringify(c,function(g,$){return g==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function f(){document.querySelectorAll("figure.diagram").forEach(function(c){if(!c.__diagram){var g=c.querySelector(":scope > script[data-diagram]");if(g)try{d(c,JSON.parse(g.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=s,e.diagramKit={draw:d,buildModel:zt,figureKey:bn,figureList:An,hintEntries:re,toHtml:oe,escapeHtml:yt,settleEntrance:Ye,measureFigure:ue},t.diagram=function(c,g){var $=c.__diagram,p=$&&$.send?h(g):null;if(p!==null&&p===$.key){$.send(g.packet?g.packet.send:void 0);return}d(c,g)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); +(()=>{var cn=["top","right","bottom","left"],dn=["main","plain","dashed"],$e=["one","zero-or-one","one-or-many","zero-or-many"],Ft={one:"Exactly one","zero-or-one":"Zero or one","one-or-many":"One or many","zero-or-many":"Zero or many"},fn=[2,3,4,5,6],gt=t=>t==null||t===""?void 0:String(t),Lt=t=>Object.assign(Object.create(null),t),Ot=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Nt(t,e={}){const o=e.checks!==!1,c=[],s=g=>{c.push(g)},a=t.legend??{},l={};for(const g of["main","plain","dashed","focal","group","activation"]){const y=gt(a[g]);y&&(l[g]=y)}const r=t.stepLabel,d=typeof r=="function"?g=>String(r(g)):typeof r=="string"?(g=>r.replace("{n}",String(g))):g=>`Step ${g}`,m=t.shapeLabels??{},f={terminal:gt(m.terminal)??"Start or end",step:gt(m.step)??"Step",decision:gt(m.decision)??"Decision"},i=t.heading===void 0?3:fn.includes(t.heading)?t.heading:(s(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),h=(g,y)=>g==null?"plain":dn.includes(g)?g:(s(`"${String(g)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),$=g=>{if(g!=null){if(cn.includes(g))return g;s(`"${String(g)}" is not a side (top, right, bottom or left): the derived side is used`)}},p=(g,y)=>typeof g=="number"&&Number.isInteger(g)&&g>=1?g:(t.layout==="auto"&&g==null||s(`${y} is ${JSON.stringify(g)}, not a whole number from 1: it is placed at 1`),1),u=[],M=[];let C=[];const z=[],w=[],S=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(S)||s(`"${String(S)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),S==="architecture"||S==="flowchart"){for(const g of t.nodes??[]){const y=S==="flowchart"&&g.shape==="decision"?"decision":S==="flowchart"&&g.shape==="terminal"?"terminal":"box",E=String(g.id??""),A=p(g.row,`the row of ${E}`);u.push({id:E,i:u.length,name:String(g.name??""),kind:y==="decision"?void 0:gt(g.kind),detail:y==="decision"?void 0:gt(g.detail),mono:!!g.detailMono,focal:!!g.focal,col:p(g.col,`the column of ${E}`),row:A,row2:A,branch:!!g.branch,shape:y,group:S==="architecture"?gt(g.group):void 0,mark:S==="architecture"?ee(g.mark):void 0})}if(S==="architecture"){const g=(t.groups??[]).map(L=>({id:String(L.id??""),label:String(L.label??""),parent:gt(L.parent)})),y=new Map(g.map(L=>[L.id,L])),E=L=>{if(!L.parent)return 1;const T=y.get(L.parent);return T?T.parent===L.id||T.id===L.id?(s(`the groups "${L.label}" and "${T.label}" are each other's parent`),L.parent=void 0,1):T.parent?(s(`the group "${L.label}" is a third level: groups nest two deep`),L.parent=void 0,1):2:(s(`the group "${L.label}" names the parent "${L.parent}", which is not a group`),L.parent=void 0,1)},A=g.map(E);g.forEach((L,T)=>z.push({...L,depth:A[T],members:u.filter(U=>U.group===L.id).map(U=>U.id),all:[]}));for(const L of z)L.all=[...L.members,...z.filter(T=>T.parent===L.id).flatMap(T=>T.members)];z.sort((L,T)=>L.depth-T.depth)}}else if(S==="data-flow"){C=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const g=new Map(C.map((y,E)=>[y.id,E+1]));for(const y of t.nodes??[]){const E=String(y.id??""),A=String(y.lane??""),L=g.get(A);L===void 0&&s(`a node (${E}) names the lane "${A}", which is not in lanes`);const T=u.length+1;u.push({id:E,i:u.length,name:String(y.name??""),kind:d(T),detail:gt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:p(y.col,`the column of ${E}`),row:L??1,row2:L??1,branch:!1,shape:"box",lane:L??1,laneLabel:C[(L??1)-1]?.label??A,step:T,mark:ee(y.mark)})}}else if(S==="sequence"){(t.participants??[]).forEach((A,L)=>{const T=String(A.name??"");u.push({id:String(A.id??""),i:L,name:T,kind:gt(A.kind),mono:!1,focal:!!A.focal,col:L+1,row:1,row2:1,branch:!1,shape:"participant",short:gt(A.short)??T,mark:ee(A.mark)})});let g=0;const y=new Map(u.map(A=>[A.id,A.col])),E=(A,L)=>{let T=1/0,U=-1/0;for(const N of A??[]){if(!N||typeof N!="object")continue;if("band"in N){L>0&&s(`the band "${String(N.band)}" is inside a frame: a band is the whole figure's`),w.push({band:String(N.band??"")});continue}if("frame"in N){if(L>=2){s("a frame is a third level: frames nest two deep");continue}const kt=N.frame==="alt"||N.frame==="loop"||N.frame==="opt"?N.frame:"opt",vt=kt==="alt"?N.branches??[]:[{label:N.label,steps:N.steps}];kt==="alt"&&vt.length<2&&s("an alt frame has one branch: it needs two or more");const pt=String(vt[0]?.label??"");pt.length>40&&s(`the frame label "${pt}" is over 40 characters`);const ut=w.length;w.push({open:kt,label:pt,depth:L+1,a:0,b:0}),vt.forEach((ct,bt)=>{if(bt){const k=String(ct.label??"");k.length>40&&s(`the frame label "${k}" is over 40 characters`),w.push({otherwise:k,depth:L+1})}ct.steps?.length||s(`a frame or branch ("${String(ct.label??"")}") is empty`);const[b,I]=E(ct.steps??[],L+1);T=Math.min(T,b),U=Math.max(U,I);const _=w[ut];_.a=Math.min(_.a||1/0,b),_.b=Math.max(_.b,I)}),w.push({close:L+1});continue}g++;const ht=String(N.label??"");ht.includes(` +`)&&s(`message ${g}'s label has a break: a message's second line is its note`);const P=String(N.from??""),lt=String(N.to??"");w.push({n:g,from:P,to:lt,label:It(ht),note:gt(N.note),kind:h(N.kind,`message ${g}`),activate:N.activate===!0||void 0,deactivate:N.deactivate===!0||void 0});const dt=y.get(P)??1,mt=y.get(lt)??1,wt=dt===mt?dt===u.length?dt-1:dt+1:dt;T=Math.min(T,dt,mt,wt),U=Math.max(U,dt,mt,wt)}return[T,U]};E(t.steps??[],0);for(const A of w)"open"in A&&!Number.isFinite(A.a)&&(A.a=1,A.b=Math.max(1,u.length))}else if(S==="schema")for(const g of t.tables??[]){const y=String(g.name??""),[E,A]=Array.isArray(g.row)?g.row:[g.row,g.row],L=p(E,`the row of ${y}`),T=Math.max(L,p(A,`the last row of ${y}`)),U=g.more===void 0||g.more===null?void 0:Number.isInteger(g.more)&&g.more>0?g.more:(s(`${y}'s "more" is ${JSON.stringify(g.more)}, not a whole number from 1: it is left out`),void 0);u.push({id:y,i:u.length,name:y,mono:!0,focal:!!g.focal,col:p(g.col,`the column of ${y}`),row:L,row2:T,branch:!1,shape:"table",more:U,columns:(g.columns??[]).map(N=>({name:String(N.name??""),type:gt(N.type),key:N.key==="PK"||N.key==="FK"?N.key:(N.key!==void 0&&N.key!==null&&s(`${y}.${String(N.name)}'s key is "${String(N.key)}", not PK or FK: it is left out`),void 0)}))})}let B=!1;if(t.layout==="auto"&&(S==="architecture"||S==="flowchart"||S==="schema")){const g=S==="schema"?t.tables:t.nodes;o&&(g??[]).some(E=>E&&(E.col!==void 0||E.row!==void 0))&&s('a card under layout="auto" has a col or row, which is not read: there are no hints');const y=e.placement?.cells;y||(B=!0);for(const E of u){const A=y?.[E.id];E.col=A?.col??1,E.row=E.row2=A?.row??1}if(y){const E=new Map;for(const A of u){const L=Ot(y,A.id);if(!L){B=!0,s(`the placement has no cell for ${A.id}, so it is not used`);continue}const T=`${L.col},${L.row}`;E.has(T)&&(B=!0,s(`the placement puts ${E.get(T)} and ${A.id} in one cell, so it is not used`)),E.set(T,A.id)}}if(y&&!B)for(const E of z){const A=E.all.map(P=>u.find(lt=>lt.id===P)).filter(Boolean);if(!A.length)continue;const L=Math.min(...A.map(P=>P.col)),T=Math.max(...A.map(P=>P.col)),U=Math.min(...A.map(P=>P.row)),N=Math.max(...A.map(P=>P.row)),ht=u.filter(P=>!E.all.includes(P.id)&&P.col>=L&&P.col<=T&&P.row>=U&&P.row<=N);ht.length&&(B=!0,s(`the placement puts ${ht.map(P=>P.id).join(", ")} inside the box of the group "${E.label}", so it is not used`))}}else t.layout==="auto"&&s(`layout="auto" is for an architecture, a flowchart or a schema, not a ${S}`);((S==="schema"?t.tables:S==="sequence"?t.participants:t.nodes)??[]).forEach((g,y)=>{if(!g||g.href===void 0||g.href===null)return;const E=String(g.href);if(S==="sequence"){s(`${u[y]?.id}: a participant cannot be a link (href)`);return}if(!E.trim()){s(`${u[y]?.id}'s href is empty`);return}const A=u[y];A&&(A.href=E,A.blank=g.target==="_blank")});const F=new Map;for(const g of u)g.id?F.has(g.id)&&s(`the id "${g.id}" is used twice`):s("a node has no id"),F.set(g.id,g);if(S==="schema"){const g=(E,A)=>{if(E==null)return;const L=E,T=$e.includes(L.from)?L.from:void 0;if(!T){s(`${A}'s cardinality "from" is ${JSON.stringify(L.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`);return}return L.to===void 0||L.to===null?{from:T,to:"one"}:L.to==="one"||L.to==="zero-or-one"?{from:T,to:L.to}:(s(`${A}'s cardinality "to" is ${JSON.stringify(L.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`),{from:T,to:"one"})};(t.tables??[]).forEach(E=>(E.columns??[]).forEach((A,L)=>{const T=gt(A.references);if(!T&&A.cardinality!==void 0&&A.cardinality!==null&&s(`${String(E.name)}.${String(A.name)} states a cardinality but references nothing`),!T)return;const[U,N]=T.split("."),ht=F.get(U??""),P=ht?.columns?.findIndex(mt=>mt.name===N)??-1;if(!ht||P<0){s(`${String(E.name)}.${String(A.name)} references ${T}, which is not a shown column`);return}const lt=F.get(String(E.name??""));lt.columns[L].ref={table:U,column:N,row:P};const dt=g(A.cardinality,`${String(E.name)}.${String(A.name)}`);dt&&(lt.columns[L].card=dt),M.push({i:M.length,from:lt.id,to:U,kind:"plain",fromRow:L,toRow:P,fk:!0,card:dt})}));const y=M.filter(E=>E.card).length;y&&y!E.card).map(E=>`${E.from}.${F.get(E.from).columns[E.fromRow].name}`).join(", ")} ${M.length-y===1?"has":"have"} none)`)}else if(S!=="sequence")for(const g of t.edges??[]){const y=String(g.from??""),E=String(g.to??"");if(!F.has(y)||!F.has(E)){s(`a line names ${F.has(y)?E:y}, which is not a node`);continue}const A=gt(g.label),L=A?.split(` +`)??[];L.length>2&&s(`the label "${It(A)}" has more than one break: a label is two lines at most`),L.some(T=>T.length>we)&&s(`a line of the label "${It(A)}" is over ${we} characters: longer words belong in the node or the summary`),M.push({i:M.length,from:y,to:E,kind:h(g.kind,`the line from ${y} to ${E}`),label:A,fromSide:$(g.fromSide),toSide:$(g.toSide),flow:S!=="flowchart"&&g.flow===!0?!0:void 0})}else for(const g of w)"n"in g&&(!F.has(g.from)||!F.has(g.to))&&s(`message ${g.n} names ${F.has(g.from)?g.to:g.from}, which is not a participant`);if(o&&S!=="sequence"&&!B){const g=new Map;for(const y of u)for(let E=y.row;E<=y.row2;E++){const A=`${y.col}:${E}`;g.has(A)&&s(`${y.id} and ${g.get(A)} share the cell at column ${y.col}, row ${E}`),g.set(A,y.id)}}if(o&&!B){for(const y of z){const E=y.all.map(T=>F.get(T));if(!E.length)continue;const A={c1:Math.min(...E.map(T=>T.col)),c2:Math.max(...E.map(T=>T.col)),r1:Math.min(...E.map(T=>T.row)),r2:Math.max(...E.map(T=>T.row2))};for(const T of u)!y.all.includes(T.id)&&T.col>=A.c1&&T.col<=A.c2&&T.row>=A.r1&&T.row<=A.r2&&s(`${T.id} is inside the box of the group "${y.label}" but not a member`);const L=E.map(T=>T.i);Math.max(...L)-Math.min(...L)+1!==L.length&&s(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of u)y.group&&!z.some(E=>E.id===y.group)&&s(`${y.id} names the group "${y.group}", which is not in groups`);u.filter(y=>y.focal).length>1&&s("more than one node is focal: a diagram has one at most");const g=new Set(S==="sequence"?w.flatMap(y=>"n"in y?[y.kind]:[]):M.map(y=>y.kind));g.has("main")&&!l.main&&s("main lines are drawn but the legend has no words for them (legend.main)"),g.has("dashed")&&!l.dashed&&s("dashed lines are drawn but the legend has no words for them (legend.dashed)"),u.some(y=>y.focal)&&!l.focal&&s("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const it=S==="architecture"||S==="data-flow",q=g=>Array.isArray(g)&&g.length>1?g.map(String):void 0,G=it&&t.packet&&typeof t.packet=="object"?t.packet:void 0,j=G&&q(G.path),x={animated:t.motion==="animated",pulse:it?q(t.pulse):void 0,packet:j?{path:j,repeat:G.repeat===!0,send:G.send}:void 0,run:S==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(o)for(const g of u){const y=g.mark?.says;if(!y?.length)continue;const E=[g.name,g.kind,g.detail,g.laneLabel].filter(Boolean).join(" ").toLowerCase();y.some(A=>E.includes(A.toLowerCase()))||s(`${g.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const R=[];if(S==="sequence"){const g=new Map,y=new Map;for(const E of w)"n"in E&&(y.set(E.from,E.n),y.set(E.to,E.n));for(const E of w)if("n"in E){if(E.activate){const A=g.get(E.to)??[];if(A.length>=3)s(`message ${E.n} opens a fourth bar on ${E.to}: three deep at most`);else{const L={who:E.to,from:E.n,to:E.n,depth:A.length+1};A.push(L),R.push(L),g.set(E.to,A)}}if(E.deactivate){const L=g.get(E.from)?.pop();L?L.to=E.n:s(`message ${E.n} closes a bar on ${E.from}, which has none open`)}}for(const[E,A]of g)for(const L of A)L.to=Math.max(L.from,y.get(E)??L.from)}const D=t.frameLabels??{},Z={opt:gt(D.opt)??"Only if",loop:gt(D.loop)??"Repeats",alt:gt(D.alt)??"One of these",else:gt(D.else)??"Otherwise"},K=t.layout==="auto"&&!B?e.placement:void 0;let at=Math.max(1,K?.cols??1,...u.map(g=>g.col));if(e.rtl){for(const y of u)y.col=at-y.col+1;const g=y=>y==="left"?"right":y==="right"?"left":y;for(const y of M)y.fromSide=g(y.fromSide),y.toSide=g(y.toSide);for(const y of w)if("open"in y){const[E,A]=[at-y.b+1,at-y.a+1];y.a=E,y.b=A}at=Math.max(1,K?.cols??1,...u.map(y=>y.col))}const nt=S==="data-flow"?Math.max(1,C.length):Math.max(1,K?.rows??1,...u.map(g=>g.row2)),J={type:S,title:String(t.title??""),heading:i,legend:l,nodes:u,byId:F,edges:M,groups:z,lanes:C,steps:w,bars:R,frameWords:Z,cols:at,rows:nt,shapeLabels:f,stepWord:d,warnings:c,motion:x,memo:new Map,rtl:e.rtl||void 0,unplaced:B||void 0,text:S==="sequence"&&t.variant==="text"||void 0,marks:M.some(g=>g.card)||void 0};if(t.layout==="auto"&&!B&&S!=="schema"&&un(J),o)for(const[g,y]of Object.entries(We(J)))y>=48&&s(`${g} grows to ${y}px to hold the lines on one side: use another side`);return o&&u.length>100&&s(`the figure has ${u.length} cards: more than 100, which automatic layout places on the main thread`),o&&u.length>1&&!B&&!Zt(J)&&s("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),J}function un(t){const e=new Set(t.nodes.map(l=>`${l.col},${l.row}`)),n=(l,r)=>{const d=[];for(let m=Math.min(l,r)+1;m{const r=t.byId.get(l.from),d=t.byId.get(l.to),m=d.col>r.col?"right":"left",f=d.row>r.row?"bottom":"top",i=d.col>r.col?"left":"right",h=d.row>r.row?"top":"bottom",$=(M,C,z,w)=>n(M,C).map(S=>w?[S,z]:[z,S]);let p;const u=M=>(M==="right"?r.col1:M==="bottom"?r.row1)?[{sides:[M,M],cells:[]}]:[];return r.row===d.row?p=[{sides:[m,i],cells:$(r.col,d.col,r.row,!0)},...u("bottom"),...u("top")]:r.col===d.col?p=[{sides:[f,h],cells:$(r.row,d.row,r.col,!1)},...u("right"),...u("left")]:p=[{sides:[m,h],cells:[...$(r.col,d.col,r.row,!0),[d.col,r.row],...$(r.row,d.row,d.col,!1)]},{sides:[f,i],cells:[...$(r.row,d.row,r.col,!1),[r.col,d.row],...$(r.col,d.col,d.row,!0)]},{sides:[m,i],cells:$(r.col,d.col,r.row,!0)},{sides:[f,h],cells:$(r.row,d.row,r.col,!1)}],p.filter(M=>M.cells.every(([C,z])=>!e.has(`${C},${z}`)))},c=new Map,s=new Set;for(const l of t.edges)if(l.fromSide||l.toSide){const[r,d]=de(t.byId.get(l.from),t.byId.get(l.to)),m=l.fromSide??r,f=l.toSide??d;s.add(`${l.from}.${m}`);for(const[i,h]of[[l.from,m],[l.to,f]])c.set(`${i}.${h}`,(c.get(`${i}.${h}`)??0)+1)}const a=t.edges.map((l,r)=>r).sort((l,r)=>o(t.edges[l]).length-o(t.edges[r]).length||+(t.edges[r].kind==="main")-+(t.edges[l].kind==="main")||l-r);for(const l of a){const r=t.edges[l];if(r.fromSide||r.toSide)continue;const d=(f,i,h)=>{const $=`${f}.${i}`;return(c.get($)??0)>=3?!1:t.byId.get(f).shape!=="decision"?!0:h?!c.has($):!s.has($)},m=o(r).find(f=>d(r.from,f.sides[0],!0)&&d(r.to,f.sides[1],!1));if(m){s.add(`${r.from}.${m.sides[0]}`);for(const[f,i]of[[r.from,m.sides[0]],[r.to,m.sides[1]]])c.set(`${f}.${i}`,(c.get(`${f}.${i}`)??0)+1);r.fromSide=m.sides[0],r.toSide=m.sides[1]}}}function ee(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=gt(e.onLight);if(n)return{onLight:n,onDark:gt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var be=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function jt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var we=28,ne=t=>t.includes(` +`)?2:1,It=t=>t.replace(/\n/g," "),Wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function ve(t,e){return t.legend[e]}function hn(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function pn(t,e){return jt(t,`sentence:${e.i}`,()=>gn(t,e))}function gn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const o=(e.columns??[]).filter(s=>s.ref).map(s=>`${s.ref.table} (${s.name}${s.card?`: ${xe(e.id,s.ref.table,s.card)}`:""})`),c=t.edges.filter(s=>s.to===e.id).map(s=>`${s.from} (${t.byId.get(s.from).columns[s.fromRow].name}${s.card?`: ${xe(s.from,s.to,s.card)}`:""})`);o.length&&n.push(`References ${o.join(", ")}.`),c.length&&n.push(`Referenced by ${c.join(", ")}.`)}else if(t.type==="sequence"){const o=t.steps.filter(a=>"n"in a&&a.from===e.id).length,c=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(Wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${o} ${o===1?"message":"messages"} and receives ${c}.`);const s=ke(t,e);s&&n.push(s.trim())}else{const o=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?hn(t,e):e.kind;if(n.push(Wt(o?`${e.name}, ${o}`:e.name)),e.detail&&n.push(Wt(e.detail)),e.group){const a=t.groups.find(r=>r.id===e.group),l=a?.parent?t.groups.find(r=>r.id===a.parent):void 0;a&&n.push(l?`In ${a.label}, in ${l.label}.`:`In ${a.label}.`)}const c=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${It(a.label)})`:""}`),s=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${It(a.label)})`:""}`);c.length&&n.push(`From: ${c.join(", ")}.`),s.length&&n.push(`To: ${s.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(Wt(t.legend.focal)),n.join(" ")}var mn=(t,e,n,o)=>[`${Ft[n.from].toLowerCase()} `,o(t),` to ${Ft[n.to].toLowerCase()} `,o(e)],xe=(t,e,n)=>`${Ft[n.from].toLowerCase()} ${t} to ${Ft[n.to].toLowerCase()} ${e}`;function ke(t,e){const n=t.bars.filter(c=>c.who===e.id&&c.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(c=>c.from===c.to?`message ${c.from}`:`messages ${c.from} to ${c.to}`).join(" and ")}.`:""}function yn(t,e,n,o){const c=n.pointerType;if(c!=="touch"&&c!=="pen")return;const s=t.querySelector(`.${e}-drawing`),a=n.target;if(!s||!a||!s.contains(a)||!t.querySelector(`.${e}-edge`))return;const l=a.closest(`.${e}-node`);if(!l?.hasAttribute("href"))return l?l.dataset.node===o?null:l.dataset.node??null:o===null?void 0:null}function Me(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const o=[];for(const c of n.flat(1/0))c!=null&&c!==!1&&!Array.isArray(c)&&o.push(c);return{t,a:e??{},c:o}}var $n={"&":"&","<":"<",">":">",'"':""","'":"'"},$t=t=>t.replace(/[&<>"']/g,e=>$n[e]),bn=" br img input meta link hr path polygon polyline circle rect line ";function oe(t,e={}){if(typeof t=="string")return $t(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[o,c]of Object.entries(t.a))if(!(c==null||c===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(o))throw new Error(`diagram: "${o}" is not an attribute name`);n+=c===!0?` ${o}`:` ${o}="${$t(String(c))}"`}return bn.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(o=>oe(o,e)).join("")}`}var wn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function Rt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function vn(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Vt(t,e){const n=e.all.map(o=>t.byId.get(o));return n.length?{c1:Math.min(...n.map(o=>o.col)),c2:Math.max(...n.map(o=>o.col)),r1:Math.min(...n.map(o=>o.row)),r2:Math.max(...n.map(o=>o.row2))}:null}function Se(t){return jt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const o=Vt(t,n);if(!o)continue;[o.r1===1,o.c2===t.cols,o.r2===t.rows,o.c1===1].forEach((s,a)=>{s&&(e[a]=Math.max(e[a],Ee(t,n,a)))})}return e})}function Ee(t,e,n){const o=Vt(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const l=Vt(t,a);return l&&[l.r1===o.r1,l.c2===o.c2,l.r2===o.r2,l.c1===o.c1][n]})?2:1}function Ae(t){const e=Se(t);return e[1]+e[3]}function ae(t){return t.type==="sequence"?t.nodes.length:t.cols}function Le(t){return jt(t,"plan",()=>xn(t))}function xn(t){const e=t.nodes,n=u=>t.type==="data-flow"||!e[u].branch,o=t.edges.map(u=>{const M=t.byId.get(u.from).i,C=t.byId.get(u.to).i,w=e.slice(Math.min(M,C)+1,Math.max(M,C)).every(S=>!n(S.i));return C===M+1&&!(n(M)&&!n(C))?"down":C===M-1?"up":C>M&&n(M)&&!n(C)&&w?"trunk":C>M&&n(M)&&n(C)&&w?"rail":C>M?"end-down":"end-up"}),c=t.edges.map((u,M)=>({e:u,k:M})).filter(({k:u})=>o[u]==="end-down"||o[u]==="end-up"),s=u=>{const M=t.byId.get(u.from).i,C=t.byId.get(u.to).i;return[Math.min(M,C),Math.max(M,C)]},a=(u,M)=>{const[C,z]=s(u),[w,S]=s(M);return C{const M=t.byId.get(u.from).i,[C,z]=s(u);return!n(M)&&e.slice(C+1,z).every(w=>!n(w.i))&&c.every(w=>w.e===u||!a(w.e,u))}),r=c.length>0&&(t.type==="data-flow"||!l),d=u=>{const[M,C]=s(u);return C-M},m=t.edges.map(()=>0);let f=!1;const i=[];for(const u of[...c].sort((M,C)=>d(M.e)-d(C.e)||M.k-C.k)){let M=0;for(const C of i)a(C.e,u.e)&&(M=Math.max(M,m[C.k]+1));m[u.k]=M,M>3&&(f=!0),i.push(u)}const h=Math.max(0,...c.map(({k:u})=>m[u]+1)),$=t.edges.map(()=>.5);for(const u of e){const M=c.filter(({e:w})=>w.from===u.id);if(M.length<2)continue;const C=M.filter(({k:w})=>o[w]==="end-down").sort((w,S)=>d(S.e)-d(w.e)||w.k-S.k);[...M.filter(({k:w})=>o[w]==="end-up").sort((w,S)=>d(w.e)-d(S.e)||S.k-w.k),...C].forEach(({k:w},S,B)=>{$[w]=B.length===2?S===0?1/3:2/3:(S+1)/(B.length+1)})}const p=Lt();for(let u=1;u{const G=o[q],j=t.byId.get(it.from).i,x=t.byId.get(it.to).i,R=x===u&&(G==="down"||G==="trunk"||G==="rail"||G==="end-down"),D=j===u&&x===u-1&&G==="up",Z=x===u-1&&G==="end-up";R&&(G==="trunk"||G==="end-down")&&(S=!0),Z&&(B=!0),(R||D||Z)&&it.label&&(z++,w=Math.max(w,G==="trunk"?40:48))}),(z>1||S&&B)&&(w=64);const Y=c.filter(({e:it,k:q})=>o[q]==="end-down"&&t.byId.get(it.to).i===u).length,F=c.filter(({e:it,k:q})=>o[q]==="end-up"&&t.byId.get(it.to).i===u-1).length;w+=20*Math.max(0,Y-1)+20*Math.max(0,F-1),p[M.id]=w}return{routes:o,gutter:r,lanes:m,exits:$,gaps:p,third:f,laneCount:h}}var zt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Ie(t,e){const n=e==="fk"?"plain":e,o=n==="main"?8:8.5,c=24,s=n==="dashed"?c-1:c-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...zt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:o,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${o}H${s}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${c-8} ${o-4}L${c} ${o}L${c-8} ${o+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${c} ${o}L${c-8} ${o-4}L${c-8} ${o+4}Z`}))}function kn(t,e){const{crow:n,ring:o}=_e(e,24,8.5,-1);return v("svg",{class:`${t}-swatch`,"data-card":e,...zt(24,16)},v("path",{class:`${t}-line`,"data-kind":"plain",d:"M0 8.5H24"}),v("path",{class:`${t}-crow`,d:n}),o?v("circle",{class:`${t}-ring`,cx:o.x,cy:o.y,r:o.r}):null)}function _e(t,e,n,o,c=8,s=6){const a=h=>String(Math.round(h*100)/100),l=h=>e+o*h,r=c/2,d=h=>`M${a(l(h-.5))} ${a(n-r)}V${a(n+r)}`,m=t==="one-or-many"||t==="zero-or-many",f=t==="zero-or-one"||t==="zero-or-many";let i=m?`M${a(e)} ${a(n-r)}L${a(l(7.5))} ${a(n)}L${a(e)} ${a(n+r)}`:d(4);return f||(i+=d(m?11:8)),{crow:i,ring:f?{x:Math.round(l(10.5)*100)/100,y:n,r:s/2}:void 0}}function Ht(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...zt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...zt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...zt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function qe(t,e){return jt(e,`key:${t}`,()=>Sn(t,e))}var Mn=qe;function Sn(t,e){const n=[],o=(a,l,r={})=>n.push(v("li",{class:`${t}-entry`,...r},a,v("span",null,l)));if(e.type==="schema"){const a=new Set(e.nodes.flatMap(l=>(l.columns??[]).map(r=>r.key)));for(const[l,r]of[["PK","Primary key"],["FK","Foreign key"]])a.has(l)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},l),v("span",null,r)))}if(e.type==="flowchart"){const a=new Set(e.nodes.map(l=>l.shape));a.has("terminal")&&o(Ht(t,"terminal"),e.shapeLabels.terminal),a.has("box")&&o(Ht(t,"box"),e.shapeLabels.step),a.has("decision")&&o(Ht(t,"decision"),e.shapeLabels.decision)}const c=new Set(e.type==="sequence"?e.steps.flatMap(a=>"n"in a?[a.kind]:[]):e.edges.filter(a=>!a.fk).map(a=>a.kind)),s=(a,l)=>v("span",{class:`${t}-key-glyph`,"data-ink":l,"aria-hidden":"true"},a);for(const a of["main","plain","dashed"]){const l=e.legend[a];c.has(a)&&l&&o(e.text?s(a==="main"?"━━▶":a==="dashed"?"┄┄▷":"──▶",a==="main"?"main":"plain"):Ie(t,a),l,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length){e.edges.some(l=>!l.card)&&o(Ie(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"});const a=new Set(e.edges.flatMap(l=>l.card?[l.card.from,l.card.to]:[]));for(const l of $e)a.has(l)&&o(kn(t,l),Ft[l],{"data-line":"","data-when":"drawn","data-card":l});n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))}if(e.type==="sequence"){e.bars.length&&o(e.text?s("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...zt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const a=new Set(e.steps.flatMap(l=>"open"in l?[l.open]:[]));for(const l of["opt","loop","alt"])a.has(l)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},l),v("span",null,e.frameWords[l])))}return e.nodes.some(a=>a.focal)&&e.legend.focal&&o(e.text?s("╔═╗","focal"):Ht(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&o(Ht(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function En(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...zt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function se(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function An(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},se(t,n)))];const o=[];return e.type==="data-flow"?o.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&o.push(v("span",{class:`${t}-kind`},n.kind)),o.push(v("span",{class:`${t}-name`},se(t,n))),n.detail&&o.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?v("span",{class:`${t}-runs`},Yt(n.detail).flatMap((c,s)=>[s?" ":"",v("span",{class:`${t}-run`},c)])):n.detail)),o}function Ln(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},se(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((o,c)=>v("span",{class:`${t}-row`,"data-row":c,"data-key":o.key},v("span",{class:`${t}-keyseat`},o.key??""),v("span",{class:`${t}-cname`},o.name),o.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${o.ref.table}`):o.type?v("span",{class:`${t}-ctype`},o.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Oe=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Kt(t,e,n,o){const{P:c}=t,s=vn(e,o)||o.keep===n.id,a=Rt(e,o),l=o.layout==="drawn"&&o.rows,r=[`--_c:${n.col}`,`--_r:${l?2*n.row:n.row}`,`--_r2:${l?2*n.row2+1:n.row2+1}`];e.type==="data-flow"&&r.push(`--_lc:${n.col+1}`),e.type==="sequence"&&r.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const $=Ot(d.gaps,n.id)??32,p=Ot(o.grow,n.id)??0;r.push(`--_gap:${p?`calc(${Oe($)} + var(--basalt-space-4) * ${p})`:Oe($)}`)}const m=Ot(o.heights,n.id);m&&r.push(`--_h:${m}px`);const f=Ot(We(e),n.id);f&&r.push(`--_mh:${f}px`);const i=Ot(o.words,n.id);i&&r.push(`--_ww:${i}px`);const h=a?o.stop===n.id?0:-1:o.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${c}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:r.join(";"),role:s&&!n.href?"img":void 0,"aria-label":s||n.href?pn(e,n):void 0,tabindex:h},n.shape==="decision"?v("svg",{class:`${c}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${c}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${be(n.mark.onLight)};--_md:${be(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Ln(c,n,e):An(c,e,n))}function In(t,e,n){const{P:o}=t,c=[];if(e.type==="data-flow"&&c.push(...e.lanes.map((r,d)=>v("div",{class:`${o}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},v("span",{class:`${o}-lane-name`},r.label)))),e.type==="architecture")for(const r of e.groups){const d=Vt(e,r);if(!d)continue;const m=[0,1,2,3].map(f=>Ee(e,r,f));c.push(v("div",{class:`${o}-gbox`,"data-group":r.id,"data-depth":r.depth>1?r.depth:void 0,style:`--_c:${d.c1};--_c2:${d.c2+1};--_r:${d.r1};--_r2:${d.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${o}-glabel`},r.label)))}if(e.text)return[v("pre",{class:`${o}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${o}-text-ink`},_n(o,e)))];if(e.type==="sequence")return c.push(v("ul",{class:`${o}-cast`},e.nodes.map(r=>v("li",{class:`${o}-actor`,style:e.rtl?`--_ac:${r.col}`:void 0},Kt(t,e,r,n))))),c.push(qn(t,e)),c;const s=r=>{const d=r.group?e.groups.find(m=>m.id===r.group):void 0;return d?.parent?e.groups.find(m=>m.id===d.parent):d},a=(r,d,m)=>{const f=t.plan?Ot(n.grow,d[0].id)??0:0,i=d[0],h=!!t.plan&&i.group===r.id&&e.edges.some(($,p)=>$.to===i.id&&(t.plan.routes[p]==="trunk"||t.plan.routes[p]==="end-down"));return v("div",{class:`${o}-group`,"data-group":r.id,"data-depth":r.depth>1?r.depth:void 0,"data-turn":h?"":void 0,style:f?`--_ggrow:${f}`:void 0},v("span",{class:`${o}-glabel`,"aria-hidden":"true"},r.label),m)};let l=0;for(;lp.id===m[i].group):void 0;if(!h){f.push(Kt(t,e,m[i],n)),i++;continue}const $=[];for(;iKt(t,e,p,n))))}c.push(a(d,m,f))}return c}function _n(t,e){const n=[],o=r=>v("span",{class:`${t}-tx-name`},r),c=r=>r==="main"?"━▶":r==="dashed"?"┄▷":"─▶",s=(r,d,m,...f)=>v("span",{class:`${t}-tx-line`,...r,style:m?`--_in:${d+m};--_hang:${m}`:`--_in:${d}`},...f);n.push(s({"data-ink":"names"},0,0,e.nodes.flatMap((r,d)=>[d?" · ":"",o(r.name)])));const a=String(Math.max(1,...e.steps.map(r=>"n"in r?r.n:0))).length;let l=0;for(const r of e.steps){const d=2*l;if("band"in r){n.push(s({"data-ink":"band"},d,0,`── ${r.band} ──`));continue}if("open"in r){n.push(s({"data-ink":"frame"},d,0,v("span",{"data-ink":"op"},`[${r.open}]`),` ${r.label}`)),l++;continue}if("otherwise"in r){n.push(s({"data-ink":"frame"},2*Math.max(0,l-1),0,v("span",{"data-ink":"op"},"[else]"),` ${r.otherwise}`));continue}if("close"in r){l=Math.max(0,l-1),n.push(s({"data-ink":"frame"},2*l,0,"[end]"));continue}const m=e.byId.get(r.from)?.name??r.from,f=e.byId.get(r.to)?.name??r.to,i=a+2;n.push(s({"data-n":r.n},d,i,v("span",{"data-ink":"num"},String(r.n).padStart(a,"0"))," ",o(m)," ",v("span",{"data-ink":r.kind==="main"?"main":"plain"},c(r.kind))," ",o(f))),n.push(s({"data-n":r.n},d+i,0,v("span",{"data-ink":"label"},r.label))),r.note&&n.push(s({"data-n":r.n},d+i,0,v("span",{"data-ink":"note"},r.note)))}return n}function qn(t,e){const{P:n}=t,o=[],c=[],s=()=>c.length?c[c.length-1].el.c:o;let a=null;for(const l of e.steps){if("band"in l){a=null,s().push(v("p",{class:`${n}-band`},v("span",null,l.band)));continue}if("open"in l){a=null;const p=c[c.length-1],u=p?`;--_fis:${l.a===p.a?1:0};--_fie:${l.b===p.b?1:0}`:"",M=v("div",{class:`${n}-frame`,"data-op":l.open,"data-depth":l.depth,style:`--_a:${l.a};--_b:${l.b+1}${u}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},l.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[l.open]}: `),l.label)));s().push(M),c.push({el:M,a:l.a,b:l.b});continue}if("otherwise"in l){a=null,s().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),l.otherwise)));continue}if("close"in l){a=null,c.pop();continue}a||(a=v("ol",{class:`${n}-msgs`,start:l.n}),s().push(a));const r=e.byId.get(l.from),d=e.byId.get(l.to),m=r?.col??1,f=d?.col??1,i=m===f,h=i&&(e.rtl?m!==1:m===e.nodes.length),$=ve(e,l.kind);a.c.push(v("li",{class:`${n}-msg`,"data-kind":l.kind,"data-from":l.from,"data-to":l.to,"data-self":i?h?"start":"end":void 0,style:`--_a:${Math.min(m,f)};--_b:${Math.max(m,f)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(l.n)),v("span",{class:`${n}-mlabel`},l.label)),v("span",{class:`${n}-route`},r?.short??l.from," ",v("span",{class:`${n}-to`},En(n,l.kind),v("span",{class:t.hidden}," to ")," ",d?.short??l.to,$?` · ${$}`:"")),l.note?v("span",{class:`${n}-note`},l.note):null))}return v("div",{class:`${n}-steps`},o)}function Ce(t,e){return jt(e,`list:${t}`,()=>Cn(t,e))}var On=Ce;function Cn(t,e){const n=Math.min(6,e.heading+1),o=f=>v(`h${n}`,{class:`${t}-list-head`},f),c=f=>v("strong",null,f),s=f=>f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},c(f.name)):c(f.name),a=f=>v("code",{class:`${t}-code`},f),l=f=>e.byId.get(f)?.name??f,r=f=>{const i=ve(e,f);return i?` (${i})`:""},d=f=>f.focal&&e.legend.focal?` ${Wt(e.legend.focal)}`:"";if(e.type==="architecture"){const f=$=>v("li",null,s($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?a($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",d($)),i=[o("Parts")],h=e.nodes.filter($=>!$.group);h.length&&i.push(v("ul",{class:`${t}-list-items`},h.map(f)));for(const $ of e.groups.filter(p=>p.depth===1)){i.push(v("p",{class:`${t}-list-group`},$.label)),$.members.length&&i.push(v("ul",{class:`${t}-list-items`},$.members.map(p=>f(e.byId.get(p)))));for(const p of e.groups.filter(u=>u.parent===$.id))i.push(v("p",{class:`${t}-list-group`,"data-depth":2},p.label)),i.push(v("ul",{class:`${t}-list-items`,"data-depth":2},p.members.map(u=>f(e.byId.get(u)))))}return i.push(o("Connections")),i.push(v("ol",{class:`${t}-list-items`},e.edges.map($=>v("li",null,c(l($.from))," to ",c(l($.to)),$.label?[": ",a(It($.label))]:"",`${r($.kind)}.`)))),i}if(e.type==="flowchart"){const f=i=>(e.byId.get(i)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(i=>{const h=e.edges.filter(u=>u.from===i.id),$=i.shape==="decision"?"Decision":i.shape==="terminal"?h.length?"Start":"End":"Step",p=!i.detail&&/[.!?]$/.test(i.name)?" ":". ";return v("li",null,s(i),i.detail?[", ",i.mono?a(i.detail):i.detail]:"",`${p}${$}.`,d(i),h.length?v("ul",{class:`${t}-list-exits`},h.map(u=>v("li",null,u.label?`If ${It(u.label)}: go to ${f(u.to)}, `:`Then: go to ${f(u.to)}, `,c(l(u.to)),r(u.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const i=e.edges.filter(h=>h.from===f.id);return v("li",null,`${f.laneLabel}: `,s(f),f.detail?[", ",f.mono?a(f.detail):f.detail]:"",".",d(f),i.length?[" Then ",...i.flatMap((h,$)=>[$?"; ":"",`to step ${e.byId.get(h.to).step}, `,c(l(h.to)),h.label?[": ",a(It(h.label))]:"",r(h.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[o("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(h=>v("li",null,c(h.name),h.kind?`, ${h.kind}`:"",".",d(h),ke(e,h))))];f.push(o("Messages"));let i=null;for(const h of e.steps){if("band"in h){i=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},h.band));continue}if("open"in h){i=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":h.depth>1?h.depth:void 0},`${e.frameWords[h.open]}: ${h.label}`));continue}if("otherwise"in h){i=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":h.depth>1?h.depth:void 0},`${e.frameWords.else}: ${h.otherwise}`));continue}if("close"in h){i=null;continue}i||(i=v("ol",{class:`${t}-list-items`,start:h.n}),f.push(i)),i.c.push(v("li",null,a(h.label),": ",c(l(h.from))," to ",c(l(h.to)),`${r(h.kind)}.`,h.note?` ${Wt(h.note)}`:""))}return f}const m=[];for(const f of e.nodes)m.push(v(`h${n}`,{class:`${t}-list-group`},f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},a(f.name)):a(f.name),d(f))),m.push(v("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(i=>v("li",null,a(i.name),i.key==="PK"?", primary key":i.key==="FK"?", foreign key":"",i.ref?[", references ",a(`${i.ref.table}.${i.ref.column}`),i.card?[" (",mn(f.id,i.ref.table,i.card,a),")"]:""]:i.type?`, ${i.type}`:"")),...f.more?[v("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return m}function Be(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Zt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(c=>c.href)?" Enter opens a part that is a link.":""}`}function re(t,e=!1){const n=e&&t.type!=="sequence"&&Zt(t)&&t.cols>1&&t.rows>1,o=t.nodes.some(c=>c.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Me(t)},{keys:["Home","End"],words:"the ends"},...o,{keys:["Esc"],words:"clear"}]}var Bn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Zt(t){return jt(t,"spatial",()=>{const e=t.nodes.map(s=>({id:s.id,...jn(t,s)})),n=(s,a)=>{const l=a==="right"||a==="left",r=a==="right"||a==="down",d=$=>l?[$.col,$.col]:$.rows,m=$=>l?$.rows:[$.col,$.col],f=d(s),i=m(s);let h=null;return e.forEach(($,p)=>{if($===s)return;const u=d($),M=m($),C=r?u[0]-f[1]:f[0]-u[1];if(C<1)return;const z=Math.max(0,M[0]-i[1],i[0]-M[1]),w=[z===0?0:1,z===0?C:C+2*z,z,Math.abs(M[0]-i[0]),p];(!h||Bn(w,h.rank))&&(h={id:$.id,rank:w})}),h?.id??null},o=Lt();for(const s of e)o[s.id]={right:n(s,"right"),left:n(s,"left"),down:n(s,"down"),up:n(s,"up")};const c=s=>{const a=new Set([s]),l=[s];for(;l.length;)for(const r of Object.values(o[l.pop()]))r&&!a.has(r)&&(a.add(r),l.push(r));return a.size};return e.every(s=>c(s.id)===e.length)?o:null})}function Jt(t){return jt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!ie(t))return{lane:e,dropped:n,lanes:0};const o=(r,d)=>(t.byId.get(r)?.row??0)*1e3+d,c=new Map;t.edges.forEach((r,d)=>{const m=`${r.to}.${r.toRow}.${r.card?.to??""}`,f=o(r.from,r.fromRow??0),i=o(r.to,r.toRow??0),h=c.get(m)??{members:[],lo:1/0,hi:-1/0};h.members.push(d),h.lo=Math.min(h.lo,f,i),h.hi=Math.max(h.hi,f,i),c.set(m,h)});const s=[...c.values()].sort((r,d)=>d.hi-d.lo-(r.hi-r.lo)),a=[];let l=0;for(const r of s.reverse()){const d=new Set(a.filter(f=>f.lo<=r.hi&&r.lo<=f.hi).map(f=>f.lane));let m=0;for(;d.has(m);)m++;if(m>1){for(const f of r.members)n.add(f);continue}a.push({lo:r.lo,hi:r.hi,lane:m});for(const f of r.members)e.set(f,m);l=Math.max(l,m+1)}return{lane:e,dropped:n,lanes:l}})}var ie=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Xt(t,e,n){const o=n.prefix,c=wn(n.base),s=t.type==="sequence"||t.type==="schema"?null:Le(t),a={P:o,ids:c,level:n.level,plan:s,hidden:n.hiddenClass},l=e.layout==="drawn",r=Rt(t,e),d=t.type==="sequence"||t.type==="schema"?l:!0,m=`h${t.heading}`,f=[`--_cols:${ae(t)}`];if(t.type==="architecture"&&t.groups.length||l&&e.pad){const i=t.type==="architecture"?Se(t):[0,0,0,0],h=(p,u,M)=>p?p>1?`calc(${p} * var(--basalt-space-${u}))`:`var(--basalt-space-${u})`:M?`var(--basalt-space-${M})`:"0px",$=l&&e.pad?"3":void 0;f.push(`--_gpad:${h(i[0],"8",$)} ${h(i[1],"4")} ${h(i[2],"4",$)} ${h(i[3],"4")}`)}if(s?.gutter&&s.laneCount>2&&f.push(`--_gw:calc(${s.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),ie(t)){const i=t.marks?"var(--basalt-space-6) + var(--basalt-space-1)":"var(--basalt-space-5)";f.push(`--_gpad:0px ${Jt(t).lanes>1?`calc(${i} + var(--basalt-space-3))`:t.marks?`calc(${i})`:i} 0px 0px`)}return t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${o} ${n.className}`:o,"aria-labelledby":c.title,"data-type":t.type,"data-cols":ae(t),"data-reach":t.type==="architecture"?Ae(t):void 0,"data-gutter":s?.gutter?"":void 0,"data-marks":t.marks?"":void 0,"data-layout":e.layout??(t.unplaced?"stacked":void 0),"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:f.join(";")},v("div",{class:`${o}-head`},v(m,{id:c.title,class:`${o}-title`},t.title),n.hasSource?v("p",{class:`${o}-source`},{slot:"source"}):null),v("div",{class:`${o}-drawing`,style:l&&e.rows?`--_rows:${e.rows};--_row-gap:0px`:void 0,role:d?"group":void 0,"aria-roledescription":d?"diagram":void 0,"aria-labelledby":d?c.title:void 0,"aria-describedby":d?r?`${c.summary} ${c.keys}`:c.summary:void 0,"data-stops":r?"":void 0},In(a,t,e),t.text?null:v("div",{class:`${o}-ink`,"aria-hidden":"true"}),v("span",{class:`${o}-ruler`,"aria-hidden":"true"})),qe(o,t),v("p",{class:`${o}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),Rt(t,e)&&t.type!=="sequence"||l&&t.type==="sequence"?v("p",{class:`${o}-tap-hint`,"aria-hidden":"true"},`Tap ${Me(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${o}-foot`},{slot:"toggle"}),v("div",{id:c.list,class:`${o}-list`,hidden:!e.open},Ce(o,t)),v("span",{id:c.keys,class:n.hiddenClass},n.viewer?`${Be(t,l)} ${n.viewer}`:Be(t,l)),v("figcaption",{id:c.summary,class:`${o}-summary`},{slot:"summary"}))}function Rn(t){const e=getComputedStyle(t),n=(c,s)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${c}`));return Number.isFinite(a)?a:s},o=new Map;return{space:c=>(o.has(c)||o.set(c,n(`space-${c}`,parseFloat(c.replace("-","."))*4)),o.get(c)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ut=(t,e)=>t==="main"?e.line:e.hair,St=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},_t=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,le=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function xt(t,e,n){const{l:o,t:c,r:s,b:a}=t.rect,l=(o+s)/2,r=(c+a)/2,d=(s-o)/2,m=(a-c)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const $=n,p=m*Math.max(0,1-Math.abs($-l)/d);return{x:$,y:e==="top"?r-p:r+p}}const i=n,h=d*Math.max(0,1-Math.abs(i-r)/m);return{x:e==="left"?l-h:l+h,y:i}}if(t.shape==="terminal"){const i=Math.min(d,m);if(f){const u=n,M=Math.min(Math.max(u,o+i),s-i),C=u-M,z=Math.abs(C)>=i?0:Math.sqrt(i*i-C*C);return{x:u,y:Math.abs(C)<1e-6?e==="top"?c:a:e==="top"?r-z:r+z}}const h=n,$=h-r,p=Math.abs($)>=i?0:Math.sqrt(i*i-$*$);return{x:e==="left"?o+i-p:s-i+p,y:h}}return f?{x:n,y:e==="top"?c:a}:{x:e==="left"?o:s,y:n}}function Tn(t,e,n){const{l:o,t:c,r:s,b:a}=e.rect,l=(o+s)/2,r=(c+a)/2,d=(s-o)/2,m=(a-c)/2;if(e.shape==="decision")return Math.abs(t.x-l)/d+Math.abs(t.y-r)/m<1-n/Math.min(d,m);if(e.shape==="terminal"){const f=Math.min(d,m),i=Math.min(Math.max(t.x,o+f),s-f);return Math.hypot(t.x-i,t.y-r)o+n&&t.xc+n&&t.ymatchMedia("(forced-colors: active)").matches;function Wn(t,e){const n=t.querySelector(`.${e}-ruler`),o=new Map;return(c,s)=>{const a=`${s}|${c}`;return o.has(a)||(n.setAttribute("data-f",s),n.textContent=c,o.set(a,n.getBoundingClientRect().width),n.textContent=""),o.get(a)}}var Yt=t=>t?t.split(/\s+/).filter(Boolean):[];function Fn(t,e,n){const o=e.space;let c=e.node,s=e.table;for(const r of t.nodes){if(r.shape==="table"){for(const p of r.columns??[]){const u=p.ref?`${t.rtl?"←":"→"} ${p.ref.table}`:p.type??"",M=o("6")+n(p.name,"mono")+(u?o("3")+n(u,"mono"):0)+2*o("3")+2*e.hair;s=Math.max(s,Math.ceil(M))}s=Math.max(s,Math.ceil(n(r.name,"table")+2*o("3")+2*e.hair+(r.href?16+o("1-5"):0)));continue}const d=r.shape==="terminal"?2*o("5"):2*o("3"),m=r.mark&&!Nn()?(r.shape==="participant"?2:1)*o("6"):0;let f=0;const i=r.href?16+o("1-5"):0,h=Yt(r.name);if(h.forEach((p,u)=>{f=Math.max(f,n(p,r.shape==="decision"?"name-500":"name")+(r.kind?0:m)+(u===h.length-1?i:0))}),t.type!=="data-flow")for(const p of Yt(r.kind))f=Math.max(f,n(p,"mono")+m);for(const p of Yt(r.detail))f=Math.max(f,n(p,r.mono?"mono":"sans"));const $=r.shape==="decision"?f/.62:f+d+2*e.hair;c=Math.max(c,Math.ceil($))}const a=ae(t);let l;return t.type==="data-flow"?l=e.lane+a*(c+o("12")):t.type==="schema"?l=a*s+(a-1)*(o("12")+(t.marks?o("3"):0))+(ie(t)?(t.marks?o("6")+o("1"):o("5"))+(Jt(t).lanes>1?o("3"):0):0):t.type==="sequence"?l=a*c+(a-1)*o("5"):l=a*c+(a-1)*o("16")+Ae(t)*o("4"),{track:c,table:s,least:Math.max(e.wide,l)}}function Re(t,e){return{x:(n,o)=>o%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,o)=>o%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function ce(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Te(t,e,n){const o=t.map(s=>({...s}));for(let s=1;s=2){const r=c[c.length-2];if(Math.abs(r.x-l.x)<.01&&Math.abs(l.x-a.x)<.01||Math.abs(r.y-l.y)<.01&&Math.abs(l.y-a.y)<.01){c[c.length-1]=a;continue}}c.push(a)}}return c}var qt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Qt(t,e,n){const o=[];for(let s=0;sMath.min(p.x,u.x)+.75&&zMath.min(M.y,C.y)+.75&&ws.split(/\s+/).map(parseFloat).filter(a=>Number.isFinite(a)),o=(s,a,l)=>{const r=[];let d=a;for(const m of s)r.push([d,d+m]),d+=m+l;return r},c=o(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0);return{cols:o(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:t.style.getPropertyValue("--_rows").trim()?c.filter((s,a)=>a%2===1):c}}var ft=t=>t==="left"||t==="right",ze={top:"bottom",bottom:"top",left:"right",right:"left"};function de(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Ne(t,e,n){const o=[];t.edges.forEach((s,a)=>{const l=t.byId.get(s.from),r=t.byId.get(s.to),[d,m]=e[a],f=l.row===r.row&&ft(d)&&ft(m)&&d===ze[m]||l.col===r.col&&!ft(d)&&!ft(m)&&d===ze[m];o.push({edge:a,end:"from",node:l,side:d,far:r,straight:f,f:.5},{edge:a,end:"to",node:r,side:m,far:l,straight:f,f:.5})});const c=new Map;for(const s of o){const a=`${s.node.id}.${s.side}`;c.has(a)||c.set(a,[]),c.get(a).push(s)}for(const[s,a]of c){if(a[0].node.shape==="decision")continue;const l=p=>ft(p.side)?p.far.row-p.node.row:p.far.col-p.node.col,r=a.filter(p=>p.straight),d=a.filter(p=>!p.straight);if(d.sort((p,u)=>l(p)-l(u)||(ft(p.side)?p.far.col-u.far.col:p.far.row-u.far.row)*(l(p)<0?1:-1)),a.length>3&&n(`${s.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!r.length){d.length===2?(d[0].f=.25,d[1].f=.75):d.length===3?(d[0].f=.25,d[1].f=.5,d[2].f=.75):d.length>3&&d.forEach((p,u)=>{p.f=(u+1)/(d.length+1)});continue}const m=new Map;for(const p of r)m.has(p.far.id)||m.set(p.far.id,[]),m.get(p.far.id).push(p);for(const p of m.values())p.length>1&&p.sort((u,M)=>u.edge-M.edge).forEach((u,M)=>{u.f=p.length===2?M===0?.25:.75:(M+1)/(p.length+1)});const f=Math.min(...r.map(p=>p.f)),i=Math.max(...r.map(p=>p.f)),h=d.filter(p=>l(p)<0),$=d.filter(p=>l(p)>=0);h.forEach((p,u)=>{p.f=f*(u+1)/(h.length+1)}),$.forEach((p,u)=>{p.f=i+(1-i)*(u+1)/($.length+1)})}return o}function We(t,e=8,n=8){return jt(t,`port-floors:${e}:${n}`,()=>{const o=Lt();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return o;const c=t.edges.map(a=>{const l=t.byId.get(a.from),r=t.byId.get(a.to),[d,m]=de(l,r);return[a.fromSide??d,a.toSide??m]}),s=new Map;for(const a of Ne(t,c,()=>{})){if(!ft(a.side)||a.node.shape!=="box")continue;const l=`${a.node.id}.${a.side}`;s.has(l)||s.set(l,[]),s.get(l).push(a.f)}for(const[a,l]of s){if(l.length<2)continue;const r=l.slice().sort((f,i)=>f-i).filter((f,i,h)=>i===0||f-h[i-1]>1e-9);let d=Math.max(e/r[0],e/(1-r[r.length-1]));for(let f=1;f{const a=t.byId.get(s.dataset.node);a&&c.set(a.id,{id:a.id,rect:St(s,n),shape:a.shape,i:a.i})}),c}function De(t,e){const n=e.head,o=e.head/2,{x:c,y:s}=t.tip;return t.dir==="down"?{l:c-o,r:c+o,t:s-n,b:s}:t.dir==="up"?{l:c-o,r:c+o,t:s,b:s+n}:t.dir==="right"?{l:c-n,r:c,t:s-o,b:s+o}:{l:c,r:c+n,t:s-o,b:s+o}}var Ge=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Ve(t,e,n,o){const c=(s,a)=>{const l=s+a-Math.floor(s+a);return l<.005||l>.995?[0]:l<=.5?[-l,1-l]:[1-l,-l]};for(const s of c(t.t,n))for(const a of c(t.l,e)){if(!a&&!s)return t;const l={l:t.l+a,r:t.r+a,t:t.t+s,b:t.b+s};if(o(l))return l}return t}function Dn(t,e,n,o,c,s,a,l,r){const d=a.space,m=[],f=[],i=[],h=[],$=d("1"),p=e.filter(u=>t.edges[u.i]?.label).sort((u,M)=>+(t.edges[M.i].kind==="main")-+(t.edges[u.i].kind==="main")||u.i-M.i);for(const u of p){const M=t.edges[u.i].label,C=l(M,"label"),z=16*ne(M),w=u.pts.length-2,S=[];qt(u.pts).forEach(([q,G],j)=>{const x=Math.abs(q.y-G.y)<.01,R=x?q.x:q.y;let D=x?G.x:G.y;const Z=Math.sign(D-R)||1;j===w&&(D-=Z*a.head);let K=[[R,D]];for(const J of c)for(const g of x?[J.l,J.r]:[J.t,J.b]){const y=x?q.y:q.x;(x?y>J.t&&yJ.l&&yg>Math.min(A,L)+1&&g{const y=(J+g)/2,E=x?{x:y,y:q.y}:{x:q.x,y};return!c.some(A=>E.x>A.l&&E.xA.t&&E.y1&&at(J,g)?1:0})}),S.sort((q,G)=>G.pri-q.pri||G.len-q.len);let B=null,Y=!1;const F=(q,G=!0)=>{const j=le(q,$);return G&&(q.ls.r||q.ts.b)||n.some(x=>je(j,x))||m.some(x=>_t(j,x))||o.heads.some(x=>_t(j,x))||o.rects.some(x=>_t(j,x))?!1:!e.some(x=>x.i!==u.i&&qt(x.pts).some(([R,D])=>_t(j,Ge(R,D,x.width))))};for(const q of S){for(const G of[1/2,1/3,2/3]){const j=q.p+(q.q-q.p)*G,x=[],R=d("2")+u.width/2;if(q.horiz?(q.len>=C+2*d("1")+d("3-5")&&x.push({box:{l:j-C/2-d("1"),r:j+C/2+d("1"),t:q.c-z/2,b:q.c+z/2},on:!0}),x.push({box:{l:j-C/2,r:j+C/2,t:q.c-R-z,b:q.c-R},on:!1}),x.push({box:{l:j-C/2,r:j+C/2,t:q.c+R,b:q.c+R+z},on:!1})):(q.len>=z+d("3")&&x.push({box:{l:q.c-C/2-d("1"),r:q.c+C/2+d("1"),t:j-z/2,b:j+z/2},on:!0}),x.push({box:{l:q.c+R,r:q.c+R+C,t:j-z/2,b:j+z/2},on:!1}),x.push({box:{l:q.c-R-C,r:q.c-R,t:j-z/2,b:j+z/2},on:!1})),B=x.find(D=>F(D.box))??null,B)break;!Y&&x.some(D=>F(D.box,!1))&&(Y=!0)}if(B)break}if(!B){i.push(u.i),Y&&h.push(u.i);continue}const it=Ve(B.box,r.ox,r.oy,q=>F(q));m.push(it),f.push({i:u.i,text:M,box:it,on:B.on})}return{labels:f,unseated:i,bounded:h}}function Ke(t,e,n,o){const c=[],s=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const l=St(a,e);s.push(l),c.push({l:l.l,r:l.r,t:l.t,b:l.t+1},{l:l.l,r:l.r,t:l.b-1,b:l.b},{l:l.l,r:l.l+1,t:l.t,b:l.b},{l:l.r-1,r:l.r,t:l.t,b:l.b});const r=a.querySelector(`:scope > .${n}-glabel`);r&&r.getClientRects().length&&c.push(St(r,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,l)=>{if(!a.getClientRects().length)return;const r=St(a,e);l>0&&c.push({l:r.l,r:r.r,t:r.t-o/2-.5,b:r.t-o/2+.5});const d=a.querySelector(`.${n}-lane-name`);d&&c.push(St(d,e))}),{obstacles:{rects:c,heads:[]},groups:s}}function Ze(t,e){const{m:o,tk:c,P:s,drawing:a,origin:l,warn:r}=t,d=c.space,m=He(o,a,l,s),f=[...m.values()],i=Hn(a),h=l.left-Math.floor(l.left),$=l.top-Math.floor(l.top),p=Re(h,$),u=a.clientWidth,M=a.clientHeight,C=b=>o.type==="data-flow"?b.col+1:b.col,z=parseFloat(getComputedStyle(a).rowGap)||0,w={w:u,h:M,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:h,oy:$};if(o.type==="sequence")return Vn(t,w,p);let S,B=[];o.type==="schema"?S=o.edges.map(b=>{const I=o.byId.get(b.from),_=o.byId.get(b.to);if(I.col===_.col){const k=I.col===o.cols&&o.cols>1?"left":"right";return[k,k]}return _.col>I.col?["right","left"]:["left","right"]}):(S=o.edges.map(b=>{const I=o.byId.get(b.from),_=o.byId.get(b.to),[k,O]=de(I,_);return[b.fromSide??k,b.toSide??O]}),B=Ne(o,S,r||(()=>{})));const Y=(b,I)=>{const _=a.querySelector(`.${s}-node[data-node="${CSS.escape(b)}"] .${s}-row[data-row="${I}"]`);if(!_)return 0;const k=St(_,l);return(k.t+k.b)/2},F=new Map;if(o.type==="schema"){const b=new Map;o.edges.forEach((_,k)=>{const O=`${_.to}.${_.toRow}.${S[k][1]}`;b.set(O,[...b.get(O)??[],k])});const I=_=>{const k=o.edges[_].card?.to;return k==="one"?0:k==="zero-or-one"?1:2};for(const _ of b.values()){const k=[...new Set(_.map(I))].sort((O,H)=>O-H);if(k.length>1)for(const O of _)F.set(O,(k.indexOf(I(O))-(k.length-1)/2)*d("2"))}}const it=b=>Math.round(b+h)-h,q=o.edges.map((b,I)=>{const[_,k]=S[I],O=m.get(b.from),H=m.get(b.to),X=Ut(b.kind,c);if(b.fk){const Q=Y(b.from,b.fromRow),et=Y(b.to,b.toRow)+(F.get(I)??0),yt=p.y(Q,X),Ct=p.y(et,X),Et=_==="right"?O.rect.r:O.rect.l,Mt=k==="right"?H.rect.r:H.rect.l;return{p1:{x:b.card?it(Et):Et,y:yt},p2:{x:b.card?it(Mt):Mt,y:Ct},r1:Q,r2:Math.abs(yt-Ct)<.01?Q:et}}const tt=B.find(Q=>Q.edge===I&&Q.end==="from").f,rt=B.find(Q=>Q.edge===I&&Q.end==="to").f;let st=Fe(O,_,tt),ot=Fe(H,k,rt);const W=ft(_)?st.y:st.x;let V=ft(k)?ot.y:ot.x;return ft(_)?st={...st,y:p.y(st.y,X)}:st={...st,x:p.x(st.x,X)},ft(k)?ot={...ot,y:p.y(ot.y,X)}:ot={...ot,x:p.x(ot.x,X)},ft(_)&&ft(k)&&Math.abs(st.y-ot.y)<1.01&&(ot={...ot,y:st.y},V=W),!ft(_)&&!ft(k)&&Math.abs(st.x-ot.x)<1.01&&(ot={...ot,x:st.x},V=W),st=ft(_)?xt(O,_,st.y):xt(O,_,st.x),ot=ft(k)?xt(H,k,ot.y):xt(H,k,ot.x),{p1:st,p2:ot,r1:W,r2:V}}),G=new Set,j=(b,I)=>{G.has(b)||(G.add(b),r?.(`${o.edges[b].from} to ${o.edges[b].to} ${I}, so its line is not drawn; its row still writes the target`))};for(const b of Jt(o).dropped)j(b,"would need a third lane of turn-backs");const x=new Map,R=Lt();o.type==="schema"&&o.edges.forEach((b,I)=>{const _=o.byId.get(b.from),k=o.byId.get(b.to);if(Math.abs(_.col-k.col)<2)return;const O=Math.min(_.col,k.col),H=Math.max(_.col,k.col),X=o.nodes.filter(et=>et.col>O&&et.colyt.row<=et&&yt.row2>=et+1)||rt.push({key:`g${et}`,y:(tt[et-1][1]+tt[et][0])/2,inner:!0});rt.push({key:"top",y:tt[0][0]-d("4"),inner:!1},{key:"bottom",y:tt[tt.length-1][1]+d("4"),inner:!1});const st=(q[I].r1+q[I].r2)/2,ot=t.pick?.[I]??rt.slice().sort((et,yt)=>Math.abs(et.y-st)-Math.abs(yt.y-st)||Number(yt.inner)-Number(et.inner)||et.y-yt.y)[0].key;R[I]=ot;const W=S[I][0]==="right"?_.col:_.col-1,V=i.cols[W-1],Q=i.cols[W];x.set(I,{corridor:ot,first:V&&Q?{key:`c${W}`,span:[V[1],Q[0]]}:null,y:0})});const D=new Map;for(const[b,I]of x){const _=o.edges[b],k=D.get(I.corridor)??[],O=k.find(H=>{const X=o.edges[H[0]];return X.to===_.to&&X.toRow===_.toRow&&S[H[0]][1]===S[b][1]&&Math.abs(q[H[0]].p2.y-q[b].p2.y)<.5});O?O.push(b):k.length>=2?j(b,"would need a third lane in its corridor"):k.push([b]),D.set(I.corridor,k)}for(const b of[...x.keys()])G.has(b)&&x.delete(b);const Z=b=>{const I=o.edges[b[0]];return Math.abs(o.byId.get(I.from).col-o.byId.get(I.to).col)*1e4+Math.abs(q[b[0]].p1.x-q[b[0]].p2.x)},K=(b,I,_)=>{const k=i.rows;if(b==="top")return k[0][0]-d("4")-I*d("3");if(b==="bottom")return k[k.length-1][1]+d("4")+I*d("3");const O=Number(b.slice(1));return(k[O-1][1]+k[O][0])/2+(I-(_-1)/2)*d("3")},at=(b,I)=>I.forEach((_,k)=>_.forEach(O=>{x.get(O).y=K(b,k,I.length)})),nt=()=>{for(const[b,I]of D){const _=I.map(k=>k.filter(O=>x.has(O))).filter(k=>k.length);D.set(b,_),at(b,b==="top"||b==="bottom"?_.slice().sort((k,O)=>Z(k)-Z(O)):_.slice().sort((k,O)=>Z(O)-Z(k)))}};nt();const J=new Map,g=new Set,y=new Map,E=(b,I,_,k,O)=>{J.has(b)||J.set(b,{span:I,vertical:_,members:new Map});const H=J.get(b);H.members.has(k)||H.members.set(k,[]),H.members.get(k).push(O)},A=()=>{J.clear(),g.clear(),y.clear(),o.edges.forEach((b,I)=>{if(G.has(I))return;const _=x.get(I);_?.first&&E(_.first.key,_.first.span,!0,`far:${I}`,-(I+1));const[k,O]=S[I],{p1:H,p2:X}=q[I],tt=o.byId.get(b.from),rt=o.byId.get(b.to);let st=null,ot=null,W=!1;if(k===O){if(ft(k)){const V=k==="right"?Math.max(C(tt),C(rt)):Math.min(C(tt),C(rt))-1,Q=i.cols[V-1],et=i.cols[V];Q&&et&&(st=`c${V}`,ot=[Q[1],et[0]],W=!0)}else{const V=k==="bottom"?Math.max(tt.row2,rt.row2):Math.min(tt.row,rt.row)-1,Q=i.rows[V-1],et=i.rows[V];Q&&et&&(st=`r${V}`,ot=[Q[1],et[0]],W=!1)}st&&g.add(I)}else if(ft(k)&&ft(O)&&(_||Math.abs(H.y-X.y)>.5)){const V=C(rt),Q=O==="left",et=i.cols[(Q?V-1:V)-1],yt=i.cols[(Q?V:V+1)-1];et&&yt&&(st=`c${Q?V-1:V}`,ot=[et[1],yt[0]],W=!0)}else if(!ft(k)&&!ft(O)&&Math.abs(H.x-X.x)>.5){const Q=O==="top"?rt.row-1:rt.row2,et=i.rows[Q-1],yt=i.rows[Q];et&&yt&&(st=`r${Q}`,ot=[et[1],yt[0]],W=!1)}!st||!ot||(_&&y.set(I,ot),E(st,ot,W,`${b.to}.${O}.${Math.round(W?X.y:X.x)}`,I))})};A();const L=new Map,T=b=>{const[I,_]=S[b],{p1:k,p2:O}=q[b],H=x.get(b);if(H){const X=y.get(b),tt=L.get(-(b+1))??(H.first?(H.first.span[0]+H.first.span[1])/2:k.x),rt=L.get(b)??(X?(X[0]+X[1])/2:O.x);return[k,{x:tt,y:k.y},{x:tt,y:H.y},{x:rt,y:H.y},{x:rt,y:O.y},O]}if(ft(I)&&ft(_)){if(I===_){const tt=d(o.marks?"6":"4")+(o.type==="schema"&&o.cols===1?(Jt(o).lane.get(b)??0)*d("3"):0),rt=L.get(b)??(I==="right"?Math.max(k.x,O.x)+tt:Math.min(k.x,O.x)-tt);return[k,{x:rt,y:k.y},{x:rt,y:O.y},O]}if(Math.abs(k.y-O.y)<=.5)return[k,{x:O.x,y:k.y}];const X=L.get(b)??(k.x+O.x)/2;return[k,{x:X,y:k.y},{x:X,y:O.y},O]}if(!ft(I)&&!ft(_)){if(I===_){const tt=L.get(b)??(I==="bottom"?Math.max(k.y,O.y)+d("4"):Math.min(k.y,O.y)-d("4"));return[k,{x:k.x,y:tt},{x:O.x,y:tt},O]}if(Math.abs(k.x-O.x)<=.5)return[k,{x:k.x,y:O.y}];const X=L.get(b)??(k.y+O.y)/2;return[k,{x:k.x,y:X},{x:O.x,y:X},O]}return ft(I)?[k,{x:O.x,y:k.y},O]:[k,{x:k.x,y:O.y},O]},U=b=>{const I=o.edges[b],_=Ut(I.kind,c),k=T(b),O=Te(k,_,p);let H;return k.length===O.length&&(H=qt(k).map(([X,tt])=>Math.abs(X.y-tt.y)<.75?(X.y+tt.y)/2:(X.x+tt.x)/2),H[0]=q[b].r1,H.length>1&&(H[H.length-1]=q[b].r2)),{i:b,from:I.from,to:I.to,kind:I.kind,pts:O,tip:O[O.length-1],dir:ce(O),dot:I.fk&&!I.card?O[0]:void 0,card:I.card,width:_,axes:H}},N=()=>o.edges.flatMap((b,I)=>G.has(I)?[]:[U(I)]);let ht=null;const P=b=>{ht??(ht=N());const I=ht.map(_=>b.has(_.i)?U(_.i):_);return{lines:I,score:Gn(I,b)*1e5+Qt(I,void 0,b).length*1e3+ue(I.filter(_=>b.has(_.i)),f,o).length}},lt=(b,I)=>{const _=b.flatMap(k=>{const O=k<0?-k-1:k,{p1:H,p2:X}=q[O],tt=x.get(O);return tt?k<0?[H.y,tt.y]:[tt.y,X.y]:I?[H.y,X.y]:[H.x,X.x]});return[Math.min(..._),Math.max(..._)]},dt=b=>b<0?-b-1:b,mt=b=>{const I=[...b.members.values()].map(k=>({members:k,run:lt(k,b.vertical)})).sort((k,O)=>k.run[0]-O.run[0]),_=[];for(const k of I){const O=_[_.length-1];O&&O.some(H=>H.run[0]!(k.length===1&&k[0].members.every(O=>g.has(O))))},wt=b=>(I,_)=>b[I].run[0]{const I=wt(b),_=[];return b.forEach((k,O)=>{let H=0;for(;_.some((X,tt)=>X===H&&I(O,tt));)H++;_.push(H)}),_},vt=b=>Math.max(0,...kt(b))+1;if(o.marks)for(let b=0;b3){I=H.map(X=>X.members.map(dt));break}if(!I)break;const _=O=>Math.max(...O),k=I.filter(O=>O.some(H=>x.has(H))).sort((O,H)=>_(H)-_(O))[0]??I.slice().sort((O,H)=>_(H)-_(O))[0];for(const O of k)j(O,"would need a fourth lane in a marked gutter"),x.delete(O);A()}const pt=(b,I,_)=>{const k=b[1]-b[0];if(!o.marks)return b[0]+k/(_+1)*(I+1);const O=c.foot+c.radiusXs,H=_>1?Math.min(k/(_+1),(k-2*O)/(_-1)):0;return(b[0]+b[1])/2+(I-(_-1)/2)*H};nt();for(const[b,I]of D){if(b==="top"||b==="bottom"||I.length<2)continue;const _=new Set(I.flat());let k=I,O=1/0;for(const H of fe(I.slice().sort((X,tt)=>Z(tt)-Z(X)))){at(b,H),ht=null;const X=P(_);X.scorert.members);if(o.marks){const rt=vt(I),st=wt(I),ot=I.length,W=new Set(_.flat().map(dt)),V=Et=>Et.forEach((Mt,Tt)=>_[Tt].forEach(Bt=>L.set(Bt,pt(b.span,Mt,rt))));let Q=kt(I),et=1/0,yt=null;const Ct=[Q];if(rt**ot<=729)for(let Et=0;EtMath.floor(Et/rt**Bt)%rt);Mt.every((Tt,Bt)=>Mt.every((te,Gt)=>Gt<=Bt||Tt!==te||!st(Bt,Gt)))&&Ct.push(Mt)}for(const Et of Ct){V(Et);const Mt=P(W);Mt.scoreot.forEach(V=>L.set(V,pt(b.span,W,k))));const st=P(O);st.scorert.forEach(ot=>L.set(ot,pt(b.span,st,k)))),ht=tt}if(w.lines=N(),o.marks&&(w.lines=w.lines.filter(b=>{if(!b.card)return!0;const I=qt(b.pts),_=([O,H])=>Math.hypot(H.x-O.x,H.y-O.y),k=I.length===1?2*c.foot:c.foot+c.radiusXs-.5;return _(I[0])>=k&&_(I[I.length-1])>=k?!0:(j(b.i,"has no room for its marks at an end"),x.delete(b.i),!1)})),x.size){const b=new Set([...x.values()].map(_=>_.corridor)),I=[b.has("top")?"var(--basalt-space-8)":"0px"];for(let _=1;_<=o.rows;_++)I.push("auto",_De(b,c));const bt=Dn(o,w.lines,f,ut,ct,{l:0,t:0,r:u,b:M},c,e,{ox:h,oy:$});return w.labels=bt.labels,w.unseated=bt.unseated,w.bounded=bt.bounded,w.overlaps=[...new Set(Je(w.lines,null).flat())],w}function Gn(t,e){return Je(t,e).length}function Je(t,e){const n=[];for(let o=0;o=l)continue;const[u,M]=i?[r.x,d.x]:[r.y,d.y],[C,z]=i?[m.x,f.x]:[m.y,f.y];Math.min(Math.max(u,M),Math.max(C,z))-Math.max(Math.min(u,M),Math.min(C,z))>1&&n.push([s.i,a.i])}}return n}function*fe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const r=l===s.pts.length-1?Math.max(s.width/2,o.head/2):s.width/2;return a.x-r<-.5||a.x+r>e+.5||a.y-r<-.5||a.y+r>n+.5})&&c.push(s.i);return c}function ue(t,e,n){const o=[];for(const c of t){const s=qt(c.pts);e.some(a=>s.some(([l,r])=>zn(l,r,a)))&&o.push(c.i)}return o}function Vn(t,e,n){const{m:o,tk:c,P:s,drawing:a,origin:l}=t,r=c.space,d=new Map;a.querySelectorAll(`.${s}-node`).forEach(w=>d.set(w.dataset.node,St(w,l)));const m=a.querySelector(`.${s}-steps`),f=m?St(m,l).b:e.h,i=w=>{const S=d.get(w);return S?n.x((S.l+S.r)/2,c.hair):0};for(const w of o.nodes){const S=d.get(w.id);S&&e.lifelines.push({x:i(w.id),y1:S.b,y2:f})}const h=w=>d.get(w.id),$=new Map;a.querySelectorAll(`.${s}-msg`).forEach(w=>{const S=St(w,l);$.set(Number(w.querySelector(`.${s}-num`)?.textContent??0),(S.t+S.b)/2)});const p=c.activation,u=p/2,M=w=>{const S=o.byId.get(w.who);if(!S)return null;const B=i(w.who),F=(S.i===o.nodes.length-1&&o.nodes.length>1?-1:1)*(o.rtl?-1:1),it=(w.depth-1)*r("1")*F,q=$.get(w.from)??0,G=$.get(w.to)??q,j=w.from===w.to;return{l:n.x(B-u+it,c.hair),r:n.x(B+u+it,c.hair),t:n.y(j?q-r("2")-r("1"):q,c.hair),b:n.y(j?q+r("2")+r("1"):G,c.hair)}},C=o.bars.map(w=>({bar:w,rect:M(w)})).filter(w=>w.rect);e.bars=C.map(w=>w.rect);const z=(w,S,B)=>C.filter(({bar:Y})=>Y.who===w&&Y.to>=S&&(B?Y.from<=S:Y.fromF.bar.depth-Y.bar.depth)[0]?.rect;a.querySelectorAll(`.${s}-msg`).forEach(w=>{const S=w.dataset.from,B=w.dataset.to,Y=w.dataset.kind??"plain",F=Ut(Y,c),it=St(w,l),q=n.y((it.t+it.b)/2,F),G=Number(w.querySelector(`.${s}-num`)?.textContent??0);let j=i(S),x=i(B),R;if(S===B){const g=w.dataset.self==="start"?-r("6"):r("6"),y=z(S,G,!0),E=y?g>0?y.r:y.l:j,A=n.y(q-r("2"),F),L=n.y(q+r("2"),F);R=[{x:E,y:A},{x:n.x(j+g,F),y:A},{x:n.x(j+g,F),y:L},{x:E,y:L}]}else{const g=x>j?1:-1,y=z(S,G,!1),E=z(B,G,!0);y&&(j=g>0?y.r:y.l),E&&(x=g>0?E.l:E.r),R=[{x:j,y:q},{x,y:q}]}e.lines.push({i:G,from:S,to:B,kind:Y,pts:R,tip:R[R.length-1],dir:ce(R),width:F});const D=w.querySelector(`.${s}-said`),Z=w.querySelector(`.${s}-note`),K=o.byId.get(S),at=o.byId.get(B);if(!K||!at)return;const nt=S===B?(()=>{const g=o.nodes.find(E=>E.col===K.col+(w.dataset.self==="start"?-1:1)),y=g?i(g.id):w.dataset.self==="start"?0:e.w;return Math.abs(y-j)-r("6")-r("2-5")-r("2")})():Math.abs(x-j)-2*r("2");Math.max(D?D.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>nt+.5&&e.unseated.push(G)}),a.querySelectorAll(`.${s}-fhead`).forEach(w=>{const S=w.parentElement?.querySelector(`:scope > .${s}-fbox`);if(!S)return;[...w.children].reduce((Y,F)=>Y+F.getBoundingClientRect().width,0)+r("3")>S.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${w.querySelector(`.${s}-flabel`)?.textContent??""}" is wider than its participants`)});{const w=[...a.querySelectorAll(`.${s}-fbox`)].flatMap(S=>{const B=St(S,l);return[{x:B.l+.5,t:B.t,b:B.b},{x:B.r-.5,t:B.t,b:B.b}]});w.length&&a.querySelectorAll(`.${s}-said, .${s}-note, .${s}-band > span`).forEach(S=>{if(!S.getClientRects().length)return;const B=le(St(S,l),r("1"));w.some(Y=>B.lY.x&&B.tY.t)&&(e.misfit??(e.misfit=[])).push(`"${S.textContent?.trim()??""}" would lie on a frame's side`)})}return e}function Ue(t,e,n,o=Lt()){const{m:c,tk:s,P:a,drawing:l,origin:r}=t,d=s.space,m=He(c,l,r,a),f=[...m.values()],i=r.left-Math.floor(r.left),h=r.top-Math.floor(r.top),$=Re(i,h),p=l.clientWidth,u=l.clientHeight,M={w:p,h:u,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:i,oy:h},C=Lt();if(c.type==="sequence"||c.type==="schema")return{geo:M,grow:C};const z=p-(parseFloat(getComputedStyle(l).paddingRight)||0),w=(x,R,D)=>{const Z=[x];for(let K=1;K<=(Ot(o,R)??0);K++)Z.push({...x,t:x.t+D*d("4")*K,b:x.b+D*d("4")*K});return Z},S=new Map;l.querySelectorAll(`.${a}-node`).forEach(x=>{const R=x.parentElement,D=St(R,r),Z=getComputedStyle(R);S.set(x.dataset.node,D.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const B=c.nodes,Y=x=>m.get(B[x].id),F=[],it=x=>Ut(c.edges[x].kind,s);c.edges.forEach((x,R)=>{const D=n.routes[R],Z=m.get(x.from),K=m.get(x.to),at=it(R);let nt=[];const J=x.label,g=J?e(J,"label"):0,y=J?16*ne(J):16,E=d("4");if(D==="down"||D==="up"){const L=Math.max(Z.rect.l,K.rect.l),T=Math.min(Z.rect.r,K.rect.r),U=c.edges.map((lt,dt)=>({o:lt,j:dt})).filter(({o:lt,j:dt})=>(n.routes[dt]==="down"||n.routes[dt]==="up")&&(lt.from===x.from&<.to===x.to||lt.from===x.to&<.to===x.from)),N=U.findIndex(lt=>lt.j===R),ht=U.length<2?.5:U.length===2?N===0?.25:.75:(N+1)/(U.length+1),P=$.x(L+(T-L)*ht,at);if(nt=D==="down"?[xt(Z,"bottom",P),xt(K,"top",P)]:[xt(Z,"top",P),xt(K,"bottom",P)],J){let lt=Math.min(nt[0].y,nt[1].y),dt=Math.max(nt[0].y,nt[1].y);D==="down"?dt-=s.head:lt+=s.head;const mt=[...l.querySelectorAll(`.${a}-group`)].map(pt=>St(pt,r));let wt=[[lt,dt]];for(const pt of mt)for(const ut of[pt.t,pt.b])wt=wt.flatMap(([ct,bt])=>ut>ct+1&&utmt.some(ct=>(pt+ut)/2>ct.t&&(pt+ut)/2ct.l&&P1){const pt=wt.filter(([ct,bt])=>!kt(ct,bt));[lt,dt]=(pt.length?pt:wt).reduce((ct,bt)=>bt[1]-bt[0]>ct[1]-ct[0]?bt:ct)}const vt=[1/2,1/3,2/3].map(pt=>{const ut=lt+(dt-lt)*pt;return{l:P-g/2-d("1"),r:P+g/2+d("1"),t:ut-y/2,b:ut+y/2}});F.push({k:R,cands:vt,on:!0,card:D==="down"?x.to:x.from})}}else if(D==="trunk"||D==="rail"){const L=$.x(Math.max(Z.rect.l,D==="rail"?K.rect.l:Z.rect.l)+d(D==="trunk"?"8":"3"),at),T=xt(Z,"bottom",L);if(D==="rail"){if(nt=[T,xt(K,"top",L)],J){const U=K.rect.t-d("6");F.push({k:R,cands:w({l:L+d("2-5"),r:L+d("2-5")+g,t:U-y/2,b:U+y/2},x.to,-1),on:!1,card:x.to})}}else{const U=$.x(K.rect.l+d("6"),at),N=$.y(K.rect.t-E,at);nt=[T,{x:L,y:N},{x:U,y:N},xt(K,"top",U)],J&&F.push({k:R,cands:w({l:U+d("2-5"),r:U+d("2-5")+g,t:N-y/2,b:N+y/2},x.to,-1),on:!1,card:x.to})}}else{const L=Math.min(S.get(x.from)??p,S.get(x.to)??p),T=$.x(n.gutter?z+(n.lanes[R]+1)*d("3-5"):L-d("2-5"),at),U=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[R],at),N=xt(Z,"right",U),ht=D==="end-down",P=c.edges.map((ut,ct)=>({o:ut,j:ct})).filter(({o:ut,j:ct})=>n.routes[ct]===D&&ut.to===x.to).sort((ut,ct)=>n.lanes[ct.j]-n.lanes[ut.j]||ut.j-ct.j),lt=Math.max(0,P.findIndex(({j:ut})=>ut===R)),dt=K.rect.r-d("6")-lt*d("3"),mt=K.rect.r-d("6")-(P.length-1)*d("3"),wt=$.x(dt,at),kt=ht?K.rect.t-E-lt*d("5"):K.rect.b+E+lt*d("5"),vt=$.y(kt,at);nt=[N,{x:T,y:N.y},{x:T,y:vt},{x:wt,y:vt},xt(K,ht?"top":"bottom",wt)];const pt=ht?x.to:B[K.i+1]?.id??x.to;J&&F.push({k:R,cands:w({l:mt-d("2-5")-g,r:mt-d("2-5"),t:kt-y/2,b:kt+y/2},pt,ht?-1:1),on:!1,card:pt})}const A=Te(nt,at,$);M.lines.push({i:R,from:x.from,to:x.to,kind:x.kind,pts:A,tip:A[A.length-1],dir:ce(A),width:at})}),M.crossings=Qt(M.lines),M.through=ue(M.lines,f,c),M.outside=Xe(M.lines,p,u,s);const{obstacles:q}=Ke(l,r,a,0);q.heads=M.lines.map(x=>De(x,s));const G=[],j={l:0,t:0,r:p,b:u};for(const x of F){const R=K=>{const at=le(K,d("1"));return K.lj.r+.5||K.tj.b+.5||f.some(nt=>je(at,nt))||G.some(nt=>_t(at,nt))||q.heads.some(nt=>_t(at,nt))||q.rects.some(nt=>_t(at,nt))||M.lines.some(nt=>nt.i!==x.k&&qt(nt.pts).some(([J,g])=>_t(at,Ge(J,g,nt.width))))},D=x.cands.find(K=>!R(K));D||(C[x.card]=(C[x.card]??0)+1,M.unseated.push(x.k));const Z=D?Ve(D,i,h,K=>!R(K)):x.cands[0];G.push(Z),M.labels.push({i:x.k,text:c.edges[x.k].label,box:Z,on:x.on})}return{geo:M,grow:C}}function Ye(t,e,n=0){const o=a=>String(Math.round(a*100)/100);let c=`M${o(t[0].x)} ${o(t[0].y)}`;for(let a=1;a{const{crow:G,ring:j}=_e(Y,F.x,F.y,it,n.head,n.dot);return`${j?``:""}`};return`${B(e.card.from,w,Math.sign(S.x-w.x)||1,"from")}${B(e.card.to,e.tip,-s.x||1,"to")}`}const a=e.kind==="dashed",l=n.head,r=n.head/2,d=a?1:l-1,m=e.pts.map(w=>({...w})),f=m[m.length-1];f.x-=s.x*d,f.y-=s.y*d;const i=e.tip.x-s.x*l,h=e.tip.y-s.y*l,$=-s.y*r,p=s.x*r,u=w=>Math.round(w*100)/100,M=$t(e.kind),C=a?``:``,z=e.dot?``:"";return`${C}${z}`}function Qe(t,e,n,o){const c=new Map,s=new Map;for(const l of e.crossings)s.has(l.under)||s.set(l.under,[]),s.get(l.under).push(l);let a="";for(const[l,r]of s){const d=`${o}-cut-${l}`;c.set(l,d);const m=r.map(f=>{const i=e.lines[f.top],h=e.lines[f.under],$=i.width/2+n.cut,p=h.width/2+1;return f.underVertical?``:``}).join("");a+=`${m}`}return{defs:a,ids:c}}function Pe(t,e,n,o){const{defs:c,ids:s}=Qe(t,e,n,o),a=e.lifelines.map(i=>``).join(""),l=(e.bars??[]).map(i=>``).join(""),r=e.lines.map((i,h)=>Zn(t,i,n,s.get(h)??null,i.from===i.to?n.radiusXs:n.radius)).join(""),m=`${a?`${a}`:""}${c?`${c}`:""}${l}${r}`,f=e.labels.map(i=>`1?' data-lines="2"':""} style="left:${Math.round(i.box.l*100)/100}px;top:${Math.round(i.box.t*100)/100}px;width:${Math.round((i.box.r-i.box.l)*100)/100}px">${i.text.split(` +`).map($t).join("
")}
`).join("");return m+f}function he(t,e,n,o,c,s,a,l){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:c,geo:null,ink:"",tokens:null};const m=Rn(t),f=Wn(d,n),i=Fn(e,m,f);l?.(i.least);const h=t.clientWidth,$=(()=>{const q=document.activeElement;return q&&d.contains(q)&&q.dataset.node?q.dataset.node:void 0})(),p=q=>Rt(e,q)?{...q,stop:q.stop&&e.byId.has(q.stop)?q.stop:e.nodes[0]?.id,keep:void 0}:{...q,stop:q.stop??e.nodes[0]?.id,keep:$&&q.layout!=="drawn"?$:void 0};let u=!1;const M=q=>{if(u=!1,e.type!=="flowchart")return q;s({...q,heights:void 0,words:void 0});const G=Lt(),j=Lt();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const R=x.querySelector(`.${n}-words`);if(!R)return;const D=x.getBoundingClientRect(),Z=nt=>{const J={w:nt.width+2*m.space("2-5"),h:nt.height+2*m.space("2")},g=1-J.w/D.width,y=g>.05?J.h/2/g:J.h*10;return Math.max(m.space("16"),Math.ceil(D.width/5),Math.ceil(2*y))},K=R.getBoundingClientRect();let at=Z(K);if(at>D.width){const nt=E=>(x.style.setProperty("--_ww",`${E}px`),R.getBoundingClientRect()),J=Math.floor(x.clientWidth-2*m.space("2-5"));let g=Math.ceil(K.width),y=K.height;for(;g1;){const U=E+A>>1;nt(U).heightD.width&&(u=!0)}),{...q,heights:G,words:Object.keys(j).length?j:void 0}},C=()=>({m:e,tk:m,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:a}),z=c.autoOpen?{open:!1,autoOpen:void 0}:{},w=(q,G)=>G.map(j=>Dt(e,q.lines.find(x=>x.i===j))).join(", ");if(e.text)return{dyn:{...c,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:m,least:i.least};if(h>=i.least&&!e.unplaced){const q=R=>{let D=p({...c,...z,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:R||void 0,rows:void 0});D=M(D),s(D);let Z=Ze(C(),f);return Z.corridors&&(D={...D,rows:Z.corridors.rows},s(D),Z=Ze({...C(),pick:Z.corridors.pick},f)),{dd:D,g:Z}};let{dd:G,g:j}=q(!1);const x=R=>R.through.length>0||R.outside.length>0||(R.overlaps?.length??0)>0||(R.misfit?.length??0)>0||u;if(!x(j)&&j.unseated.length&&j.unseated.every(R=>j.bounded?.includes(R))){const R=q(!0);!x(R.g)&&!R.g.unseated.length&&({dd:G,g:j}=R)}if(!x(j)&&!j.unseated.length)return j.crossings.length&&a?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the drawn layout: ${j.crossings.map(R=>`${Dt(e,j.lines[R.top])} over ${Dt(e,j.lines[R.under])}`).join("; ")}`),{dyn:G,geo:j,ink:Pe(n,j,m,o),tokens:m,least:i.least};u&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: a decision would be taller than it is wide`),j.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: ${j.misfit.join("; ")}`),j.through.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: ${w(j,j.through)} would pass through a node`),j.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: ${w(j,j.overlaps)} would lie on one another`),j.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: ${w(j,j.outside)} would leave the drawing`),j.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: no clean seat for ${j.unseated.map(R=>e.type==="sequence"?`message ${R}`:`"${It(e.edges[R]?.label??"")}"`).join(", ")}`)}let S=p({...c,...z,layout:"stacked",heights:void 0,grow:Lt(),track:e.type==="schema"?i.table:void 0,bare:void 0,pad:void 0,rows:void 0});if(S=M(S),s(S),e.type==="sequence"||e.type==="schema")return{dyn:S,geo:null,ink:"",tokens:m,least:i.least};const B=Le(e);let Y=Ue(C(),f,B,S.grow);for(let q=0;q<6&&Object.keys(Y.grow).length;q++){const G=Lt(S.grow);for(const[j,x]of Object.entries(Y.grow))G[j]=(Ot(G,j)??0)+x;S={...S,grow:G},s(S),Y=Ue(C(),f,B,G)}const F=Y.geo;if(!B.third&&B.laneCount>2&&a?.(`the stacked drawing uses ${B.laneCount} end lanes (four at most)`),F.unseated.length>0||F.through.length>0||F.outside.length>0||B.third){F.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(F.unseated)].map(j=>`"${It(e.edges[j]?.label??"")}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),F.through.length&&a?.(`in the stacked drawing ${w(F,F.through)} would pass through a node, so its lines are not drawn`),F.outside.length&&a?.(`in the stacked drawing ${w(F,F.outside)} would leave the drawing, so its lines are not drawn`),B.third&&a?.("the stacked drawing would need a fifth end lane, so its lines are not drawn");const q={...F,lines:[],labels:[],crossings:[]};return{dyn:p({...S,grow:Lt(),bare:!0,open:c.bare?c.open:!0,autoOpen:c.bare?c.autoOpen:c.open?void 0:!0}),geo:q,ink:"",tokens:m,least:i.least}}return F.crossings.length&&a?.(`${F.crossings.length} crossing${F.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${F.crossings.map(q=>`${Dt(e,F.lines[q.top])} over ${Dt(e,F.lines[q.under])}`).join("; ")}`),{dyn:S,geo:F,ink:Pe(n,F,m,o),tokens:m,least:i.least}}function Dt(t,e){const n=t.byId.get(e.from)?.name??e.from,o=t.byId.get(e.to)?.name??e.to;return`${n} to ${o}`}function Jn(t,e,n,o,c,s){const a=new Set;if(s){a.add(s);for(const p of n?.lines??[])p.from===s&&a.add(p.to),p.to===s&&a.add(p.from)}if(t.toggleAttribute("data-tracing",!!s),t.querySelectorAll(`.${e}-node`).forEach(p=>p.toggleAttribute("data-near",a.has(p.dataset.node))),!n||!o)return;const l=p=>!!s&&(p.from===s||p.to===s),r=t.querySelector(`.${e}-edges`),d=new Map;t.querySelectorAll(`.${e}-edge`).forEach(p=>d.set(p.getAttribute("data-edge"),p));for(const p of n.lines){const u=d.get(String(p.i));u&&(u.toggleAttribute("data-lit",l(p)),u.toggleAttribute("data-dim",!!s&&!l(p)))}if(t.querySelectorAll(`.${e}-label`).forEach(p=>{const u=n.lines.find(M=>String(M.i)===p.dataset.edge);p.toggleAttribute("data-lit",!!(u&&l(u)))}),r){for(const p of n.lines)if(l(p)){const u=d.get(String(p.i));u&&r.appendChild(u)}}const m=Qt(n.lines,l),{defs:f,ids:i}=Qe(e,{...n,crossings:m},o,c),h=t.querySelector(`.${e}-svg`);if(!h)return;let $=h.querySelector("defs");!$&&f&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),h.insertBefore($,h.firstChild)),$&&($.innerHTML=f),n.lines.forEach((p,u)=>{const M=d.get(String(p.i))?.querySelector(`.${e}-line`);if(!M)return;const C=i.get(u);C?M.setAttribute("mask",`url(#${C})`):M.removeAttribute("mask")})}var Xn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Un(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Xn()||Qn(t)?"done":"pending")}}var Yn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Qn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Yn(t))!==null}catch{return!1}}function tn(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Pn(t,e,n,o=!1,c=!1){const s=o?Zt(t):null;if(s&&n.startsWith("Arrow")){const d={ArrowRight:c?"left":"right",ArrowLeft:c?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return d?s[e]?.[d]??null:null}const a=t.byId.get(e)?.i??0,l=t.nodes.length;let r;if(n==="ArrowRight"||n==="ArrowDown")r=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")r=a-1;else if(n==="Home")r=0;else if(n==="End")r=l-1;else return null;return t.nodes[Math.max(0,Math.min(l-1,r))].id}var to=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],en=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl","data-cols","data-reach","data-gutter","data-marks"],eo=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad","--_gw","--_mh","--_rows","--_row-gap"],nn=t=>t==null||t===!1;function no(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Pt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const o=n?en:to;for(const a of o)nn(e.a[a])&&t.removeAttribute(a);for(const[a,l]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const d=t.style,m=new Map(String(l??"").split(";").map(f=>{const i=f.indexOf(":");return[f.slice(0,i).trim(),f.slice(i+1).trim()]}).filter(([f])=>f));for(const[f,i]of m)d.getPropertyValue(f).trim()!==i&&d.setProperty(f,i);for(const f of eo)m.has(f)||d.removeProperty(f);continue}if(n&&!en.includes(a))continue;if(nn(l)){t.removeAttribute(a);continue}const r=l===!0?"":String(l);t.getAttribute(a)!==r&&t.setAttribute(a,r)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const c=[...t.children];let s=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let l=s;lt.querySelector(`.${e}-node[data-node="${CSS.escape(s)}"]`);n&&c(n)?.setAttribute("tabindex","-1"),c(o)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",o=0;function c(i,h,$){return{prefix:n,base:i,hasSource:h.source!==void 0&&h.source!==null&&h.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function s(i,h,$,p){var u=function(M){return''+$t(M)+""};return{source:$t(String(h.source||"")),summary:$t(String(h.summary||"")),hint:re(i).map(function(M){return""+M.keys.map(u).join(" ")+" "+$t(M.words)+""}).join(""),toggle:'"}}function a(i,h,$){for(var p=i.layout==="auto"&&(i.type==="architecture"||i.type==="flowchart"||i.type==="schema"),u=p?Array.isArray(i.placement)?i.placement:i.placement?[i.placement]:[]:[],M=i.direction||(i.type==="flowchart"?"down":"right"),C=null,z=0;z");return{open:B.slice(0,Y+1),inner:B.slice(Y+1,B.length-9),warnings:w.warnings}}var l=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-marks","data-layout","data-measured","data-bare"],r=["--_cols","--_gpad","--_track"];function d(i,h,$,p){i.__diagram&&i.__diagram.stop();var u=(i.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),M=getComputedStyle(i).direction==="rtl",C=h.layout==="auto"&&(h.type==="architecture"||h.type==="flowchart"||h.type==="schema"),z=C?Array.isArray(h.placement)?h.placement:h.placement?[h.placement]:[]:[];C&&!z.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var w=h.direction?[h.direction]:h.type==="flowchart"?["down","right"]:["right","down"],S=function(W){for(var V=0;V .diagram-drawing")){if(!u||!i.querySelector("#"+CSS.escape(u+"-title"))){for(;document.getElementById("dg"+ ++o+"-title"););u="dg"+o}var Y=a(h,u,p),F=document.createElement("div");F.innerHTML=Y.open+"";var it=F.firstChild;l.forEach(function(W){i.removeAttribute(W)}),r.forEach(function(W){i.style.removeProperty(W)});for(var q=0;q :not(script[data-diagram])").forEach(function(W){W.remove()}),i.insertAdjacentHTML("beforeend",Y.inner)}B.warnings.forEach(function(W){console.warn("Basalt diagram: "+W)}),B.motion.animated&&B.motion.firstVisit&&!i.id&&console.warn('Basalt diagram: "entrance": "first-visit" needs an id on the figure: without one the entrance plays on every visit');var j=c(u,h,p),x={},R=null,D=null,Z=null,K=null,at=Object.create(null),nt=function(W){at[W]||(at[W]=1,console.warn("Basalt diagram: "+W))},J=function(W){Pt(i,Xt(B,W,j))},g=i.querySelector(".diagram-ink"),y=i.querySelector(".diagram-toggle"),E=!p&&B.motion.animated&&typeof e.diagramMotion=="function",A=null,L=null,T=function(){E&&tn(i)};function U(){Jn(i,n,R&&R.geo,R&&R.tokens,u,D||K||Z),P()}var N=null,ht=!p&&matchMedia("(hover: none), (pointer: coarse)").matches;function P(){var W=ht&&!p&&g&&g.innerHTML!=="";if(i.toggleAttribute("data-touch",!!(ht&&!p)),W&&!N){var V=i.querySelector(":scope > .diagram-foot");if(!V)return;N=document.createElement("button"),N.type="button",N.className="btn diagram-clear",N.setAttribute("data-variant","secondary"),N.setAttribute("data-size","sm"),N.innerHTML="Clear highlight",N.addEventListener("click",function(){K&&(K=null,U())}),V.appendChild(N)}else!W&&N&&(N.remove(),N=null);N&&N!==N.parentNode.lastElementChild&&document.activeElement!==N&&N.parentNode.appendChild(N),N&&(K?N.removeAttribute("aria-disabled"):N.setAttribute("aria-disabled","true"))}function lt(W){if(!W.defaultPrevented){var V=yn(i,n,W,K);V!==void 0&&(T(),ht=!0,K=V,U())}}function dt(){y&&(y.setAttribute("aria-expanded",String(!!x.open)),y.firstElementChild.textContent=x.open?"Hide the list":"View as list")}function mt(){if(C&&z.length>1&&!p){for(var W=null,V=[],Q=!1,et=0;et1&&p&&!h.direction&&p.room){for(var te=p.room(),Gt=-1,pe=null,ge=0;geGt+1e-6&&(Gt=an,pe=me)}}}pe&&(B=pe)}R=(p?p.measure:he)(i,B,n,u,x,J,nt),x=R.dyn,J(x),dt();var ye=i.querySelector(":scope > .diagram-hint");if(ye){var sn=re(B,x.layout==="drawn").map(function(At){return""+At.keys.map(function(ro){return''+$t(ro)+""}).join(" ")+" "+$t(At.words)+""}).join("");ye.innerHTML!==sn&&(ye.innerHTML=sn)}Rt(B,x)||(Z=K=null);var rn=g&&R.ink!==L;rn&&(g.innerHTML=R.ink,L=R.ink),U();var so=B.text?i.querySelector(".diagram-text[data-art]"):null;B.text&&typeof e.diagramText=="function"&&e.diagramText(i,B,h,p);var ln=B.text?i.querySelector(".diagram-text[data-art]"):null;E&&R.tokens&&(Un(i,!!(R.geo&&R.geo.lines.length)||!!ln),(rn||ln!==so)&&A&&A.redrawn()),p&&p.onMeasured&&R.tokens&&p.onMeasured(R,i)}function wt(W){x=W,J(x)}function kt(W){var V=x.stop;x=Object.assign({},x,{stop:W}),oo(i,n,V,W)}var vt=function(W){var V=W&&W.closest?W.closest(".diagram-node"):null;return V&&i.contains(V)?V:null};function pt(W){var V=vt(W.target);if(!(!V||W.defaultPrevented)){if(T(),W.key==="Escape"){!p&&(D||Z||K)&&(W.preventDefault(),D=Z=K=null,U());return}if(Rt(B,x)){var Q=Pn(B,V.getAttribute("data-node"),W.key,x.layout==="drawn");if(Q){W.preventDefault(),kt(Q);var et=i.querySelector('.diagram-node[data-node="'+CSS.escape(Q)+'"]');et&&et.focus()}}}}function ut(W){var V=vt(W.target);if(V){T();var Q=V.getAttribute("data-node");D=V.matches(":focus-visible")?Q:null,Rt(B,x)&&x.stop!==Q&&kt(Q),U()}}function ct(W){var V=vt(W.target);V&&(vt(W.relatedTarget)||(D=null),x.keep===V.getAttribute("data-node")&&wt(Object.assign({},x,{keep:void 0})),U())}function bt(W){if(!(W.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var V=vt(W.target);V&&T();var Q=V&&Rt(B,x)?V.getAttribute("data-node"):null;Q!==Z&&(Z=Q,U())}}function b(){Z&&(Z=null,U())}function I(){T(),wt(Object.assign({},x,{open:!x.open,autoOpen:void 0})),dt()}i.addEventListener("keydown",pt),i.addEventListener("focusin",ut),i.addEventListener("focusout",ct),i.addEventListener("pointerover",bt),i.addEventListener("pointerleave",b),i.addEventListener("click",lt),y&&y.addEventListener("click",I),mt();var _=i.clientWidth,k=0,O=!0,H=new ResizeObserver(function(){Math.abs(i.clientWidth-_)<.5||(_=i.clientWidth,cancelAnimationFrame(k),k=requestAnimationFrame(mt))});H.observe(i),document.fonts&&document.fonts.ready.then(function(){O&&mt()});var X=matchMedia("(forced-colors: active)"),tt=B.nodes.some(function(W){return W.mark});tt&&X.addEventListener("change",mt),E&&(A=e.diagramMotion(i,{fig:i,P:n,base:u,model:function(){return B},geo:function(){return R&&R.geo},tokens:function(){return R&&R.tokens}},h));var rt=!p&&h.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(i,h,{model:B,settle:T,animated:E}):null,st=i.querySelector(":scope > .diagram-foot"),ot=!p&&h.export===!0&&st&&typeof e.diagramExport=="function"?e.diagramExport(st,i):[];i.__diagram={stop:function(){rt&&rt.destroy(),ot.forEach(function(W){W.remove()}),O=!1,H.disconnect(),cancelAnimationFrame(k),tt&&X.removeEventListener("change",mt),A&&A.destroy(),i.removeEventListener("keydown",pt),i.removeEventListener("focusin",ut),i.removeEventListener("focusout",ct),i.removeEventListener("pointerover",bt),i.removeEventListener("pointerleave",b),i.removeEventListener("click",lt),N&&N.remove(),y&&y.removeEventListener("click",I)},layout:mt,key:m(h),send:A&&A.sendValue?A.sendValue:null}}function m(i){try{return JSON.stringify(i,function(h,$){return h==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function f(){document.querySelectorAll("figure.diagram").forEach(function(i){if(!i.__diagram){var h=i.querySelector(":scope > script[data-diagram]");if(h)try{d(i,JSON.parse(h.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:d,buildModel:Nt,figureKey:Mn,figureList:On,hintEntries:re,toHtml:oe,escapeHtml:$t,settleEntrance:tn,measureFigure:he},t.diagram=function(i,h){var $=i.__diagram,p=$&&$.send?m(h):null;if(p!==null&&p===$.key){$.send(h.packet?h.packet.send:void 0);return}d(i,h)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index 749007b4..4137941a 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -779,7 +779,7 @@ "kbd" ], "budget": 137700, - "usage": 4300, + "usage": 4600, "builds": [ "kbd" ] @@ -805,7 +805,7 @@ "toggle" ], "budget": 28450, - "usage": 1300, + "usage": 1450, "builds": [ "loops", "toggle" diff --git a/.agent/skills/basalt-html/parts/usage/diagram-motion.md b/.agent/skills/basalt-html/parts/usage/diagram-motion.md index 479364ef..efba91b7 100644 --- a/.agent/skills/basalt-html/parts/usage/diagram-motion.md +++ b/.agent/skills/basalt-html/parts/usage/diagram-motion.md @@ -5,5 +5,6 @@ Added for you when a diagram's JSON says `"motion": "animated"` (with `loops`); - **Entrance:** in view (two fifths of it), each line draws once in the author's order, inside five seconds; a sequence's arrows go in message order and each label lifts from secondary to primary. Every word is at rest from the first frame. It never plays under reduced motion, in forced colours, under the hold or in print, and settles at once on a hover, a focus, a key or a control. - **Loops:** a flow line's cuts, a pulse's bead, a repeating packet. They run only in view, never while a node is traced, and stop under the page's hold. The figure's foot then has "Pause animations" (the hold's own button, built for you) after "View as list". Don't add a second one for the diagram. - **One mover a figure:** a pulse or a packet, never both. Flow is a state of a line and never runs on a line the mover travels. +- **First visit:** `"entrance": "first-visit"` with an `id` on the figure plays the entrance once; later visits are at rest. A text sequence builds by ink instead, in view. - **Run:** "Play the run" sends one dot through a sequence's messages; it reads "Stop the run" while it runs. It works under the hold and under reduced motion (by colour alone). - `Basalt.diagram(figure, spec)` with a new `packet.send` value sends one message. diff --git a/.agent/skills/basalt-html/parts/usage/diagram.md b/.agent/skills/basalt-html/parts/usage/diagram.md index de16bf0b..eb31b43e 100644 --- a/.agent/skills/basalt-html/parts/usage/diagram.md +++ b/.agent/skills/basalt-html/parts/usage/diagram.md @@ -23,7 +23,8 @@ Boxes and the lines between them. `compose.mjs` writes the figure's words into t - **Required:** `title`, `summary` (what it shows, in a sentence). `source`, `heading` (2 to 6, default 3). - Monochrome: nothing takes a colour but a card's service mark. The drawn layout is used only where it fits; otherwise the figure is stacked, one column at most 480 wide. - **Motion:** `"motion": "animated"` (default still) draws each line once in view, every word at rest; it brings in `diagram-motion` (its usage says the rest). Motion never carries a fact alone. -- **Flow, pulse, packet:** `"flow": true` on a `main` or `plain` edge marches it (give it a label). `"pulse": ["a", "b", "c"]` runs a bead along a route; `"packet": { "path": [...], "repeat": true }` sends a dot. One of pulse and packet; never flow on the mover's route. Architecture and data flow only. +- **Flow, pulse, packet:** `"flow": true` on an edge marches it (a dashed line's own dashes) (give it a label). `"pulse": ["a", "b", "c"]` runs a bead along a route; `"packet": { "path": [...], "repeat": true }` sends a dot. One of pulse and packet; never flow on the mover's route. Architecture and data flow only. - **Run:** `"run": true` on a sequence adds "Play the run", a dot through every message. -- **Mark:** `"mark": "aws-ecs-service"` on an architecture node, 16px in the card's top end corner, the owner's file and colours; the card's words still name the service. Your own: `{ "onLight": "logo.svg", "onDark": "logo-dark.svg" }`, read into the page. A page drawing from script names its marks: ``. +- **Parts:** a group's `parent` (two levels); `href` (and `"target": "_blank"`) makes a card a link; a label's `"\n"` is its one break; a sequence's message `activate`/`deactivate` (a bar) and steps `{ "frame": "opt" | "loop", "label", "steps" }` or `{ "frame": "alt", "branches": [...] }`; `"variant": "text"` draws it as text art; `"layout": "auto"` places the cards for you (compose.mjs, at build time); `"entrance": "first-visit"` with an `id` plays the entrance once. +- **Mark:** `"mark": "aws-ecs-service"` on an architecture node, a data flow's step or a sequence's participant, 16px in the card's top end corner, the owner's file and colours; the card's words still name the service. Your own: `{ "onLight": "logo.svg", "onDark": "logo-dark.svg" }`, read into the page. A page drawing from script names its marks: ``. - **Marks:** `aws-*`, `azure-*`, `gcp-*`, `kubernetes`, `temporal`, `sonarqube`, `github`, `coderabbit`, `greptile`, `blacksmith`, `jenkins`, `servicenow`, `blazemeter`. `node .agent/skills/basalt-html/compose.mjs --marks [aws azure gcp ...]` prints each id with the words its card must say and which are unofficial; a database card (Aurora, RDS) takes `aws-database`. diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 4f0ebf4f..c28e1748 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -422,6 +422,25 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const cells = options.placement?.cells; if (!cells) unplaced = true; for (const n of nodes) { const c = cells?.[n.id]; n.col = c?.col ?? 1; n.row = n.row2 = c?.row ?? 1; } + // A placement that puts two cards in one cell, or leaves a card out, is not used (8.5; Neon's B8 of the code review): the figure tries its other + // direction, then stacks, and a development build names the cards. (A card inside a group's box it is not in is checked below, with the groups.) + if (cells) { + const seen = new Map(); + for (const n of nodes) { + const c = own(cells, n.id); + if (!c) { unplaced = true; dev && warn(`the placement has no cell for ${n.id}, so it is not used`); continue; } + const key = `${c.col},${c.row}`; + if (seen.has(key)) { unplaced = true; dev && warn(`the placement puts ${seen.get(key)} and ${n.id} in one cell, so it is not used`); } + seen.set(key, n.id); + } + } + if (cells && !unplaced) for (const g of groups) { + const mem = g.all.map((id) => nodes.find((n) => n.id === id)!).filter(Boolean); + if (!mem.length) continue; + const c1 = Math.min(...mem.map((n) => n.col)), c2 = Math.max(...mem.map((n) => n.col)), r1 = Math.min(...mem.map((n) => n.row)), r2 = Math.max(...mem.map((n) => n.row)); + const inside = nodes.filter((n) => !g.all.includes(n.id) && n.col >= c1 && n.col <= c2 && n.row >= r1 && n.row <= r2); + if (inside.length) { unplaced = true; dev && warn(`the placement puts ${inside.map((n) => n.id).join(", ")} inside the box of the group "${g.label}", so it is not used`); } + } } else if (spec.layout === "auto") dev && warn(`layout="auto" is for an architecture, a flowchart or a schema, not a ${type}`); // Link cards (1.4): any card but a sequence's participant (its stacked chip has no room for a 44px target). const rawCards = (type === "schema" ? spec.tables : type === "sequence" ? spec.participants : spec.nodes) as Array<{ href?: unknown; target?: unknown }> | undefined; @@ -429,7 +448,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model if (!raw || raw.href === undefined || raw.href === null) return; const href = String(raw.href); if (type === "sequence") { dev && warn(`${nodes[k]?.id}: a participant cannot be a link (href)`); return; } - if (!href) { dev && warn(`${nodes[k]?.id}'s href is empty`); return; } + if (!href.trim()) { dev && warn(`${nodes[k]?.id}'s href is empty`); return; } const n = nodes[k]; if (n) { n.href = href; n.blank = raw.target === "_blank"; } }); @@ -567,13 +586,16 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const swap = (side?: DiagramSide) => (side === "left" ? "right" : side === "right" ? "left" : side); for (const e of edges) { e.fromSide = swap(e.fromSide); e.toSide = swap(e.toSide); } for (const st of steps) if ("open" in st) { const [a, b] = [cols - st.b + 1, cols - st.a + 1]; st.a = a; st.b = b; } - cols = Math.max(1, ...nodes.map((n) => n.col)); + // A way-only track (DECISIONS 322) is a track right to left too (Neon's P3 of the code review). + cols = Math.max(1, placed?.cols ?? 1, ...nodes.map((n) => n.col)); } const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, placed?.rows ?? 1, ...nodes.map((n) => n.row2)); const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined, text: (type === "sequence" && spec.variant === "text") || undefined, marks: edges.some((e) => e.card) || undefined }; if (spec.layout === "auto" && !unplaced && type !== "schema") chooseSides(model); if (checks) for (const [id, h0] of Object.entries(portFloors(model))) if (h0 >= 48) warn(`${id} grows to ${h0}px to hold the lines on one side: use another side`); - if (checks && nodes.length > 1 && !spatialTable(model)) warn("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"); + // A figure with no cells yet (an automatic one before its placement) has no spatial keys to check. + if (checks && nodes.length > 100) warn(`the figure has ${nodes.length} cards: more than 100, which automatic layout places on the main thread`); + if (checks && nodes.length > 1 && !unplaced && !spatialTable(model)) warn("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"); return model; } @@ -736,7 +758,8 @@ export function tapTrace(fig: HTMLElement, P: string, event: MouseEvent, current if (!drawing || !target || !drawing.contains(target) || !fig.querySelector(`.${P}-edge`)) return undefined; const node = target.closest(`.${P}-node`); if (node?.hasAttribute("href")) return undefined; - if (!node) return null; + // A tap on the ground clears a trace; with none up it is nothing, so it never makes a figure "on touch" (Neon's P7 of the code review). + if (!node) return current === null ? undefined : null; return node.dataset.node === current ? null : node.dataset.node ?? null; } @@ -1047,7 +1070,8 @@ function buildKey(P: string, m: Model): VElement | null { const ops = new Set(m.steps.flatMap((st) => ("open" in st ? [st.open] : []))); for (const op of ["opt", "loop", "alt"] as const) if (ops.has(op)) entries.push(h("li", { class: `${P}-entry` }, h("span", { class: `${P}-key-letters`, "data-op": "" , "aria-hidden": "true" }, op), h("span", null, m.frameWords[op]))); } - if (m.nodes.some((n) => n.focal) && m.legend.focal) entry(boxSwatch(P, "focal"), m.legend.focal, { "data-focal": "" }); + // The text art draws the focal participant in a double-line box: its key shows that glyph (P4 of the pixel review). + if (m.nodes.some((n) => n.focal) && m.legend.focal) entry(m.text ? glyph("╔═╗", "focal") : boxSwatch(P, "focal"), m.legend.focal, { "data-focal": "" }); if (m.groups.length && m.legend.group) entry(boxSwatch(P, "group"), m.legend.group); if (!entries.length) return null; return h("div", { class: `${P}-key` }, h("ul", { class: `${P}-legend`, "aria-label": "Key" }, entries)); @@ -1079,7 +1103,8 @@ function nodeText(P: string, m: Model, n: MNode): VChild[] { else if (n.kind) kids.push(h("span", { class: `${P}-kind` }, n.kind)); kids.push(h("span", { class: `${P}-name` }, linkName(P, n))); // An identifier breaks only at its spaces: each run between them is kept whole (an ordinary hyphen stays, so a copy is exact). - if (n.detail) kids.push(h("span", { class: `${P}-detail`, "data-mono": n.mono ? "" : undefined }, n.mono ? words(n.detail).flatMap((w, j) => [j ? " " : "", h("span", { class: `${P}-run` }, w)]) : n.detail)); + // The runs are held in one span, a single left-to-right run right to left (1.7). + if (n.detail) kids.push(h("span", { class: `${P}-detail`, "data-mono": n.mono ? "" : undefined }, n.mono ? h("span", { class: `${P}-runs` }, words(n.detail).flatMap((w, j) => [j ? " " : "", h("span", { class: `${P}-run` }, w)])) : n.detail)); return kids; } @@ -1178,7 +1203,11 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { const wrap = (g: Model["groups"][number], run: MNode[], kids: VNode[]) => { // A stacked group takes its first member's grown gap above its box (the member itself sits at the top of the box's padding). const grow = ctx.plan ? own(dyn.grow, run[0]!.id) ?? 0 : 0; - return h("div", { class: `${P}-group`, "data-group": g.id, "data-depth": g.depth > 1 ? g.depth : undefined, style: grow ? `--_ggrow:${grow}` : undefined }, h("span", { class: `${P}-glabel`, "aria-hidden": "true" }, g.label), kids); + // A group whose first card is entered by a turn (a trunk or an end line) has space-12 above it, so the turn runs under its label, not behind it + // (DECISIONS 306, 1.3, the decider's answer 1 to the pixel review). The label keeps its place in the first space-8. + const first = run[0]!; + const turn = Boolean(ctx.plan) && first.group === g.id && m.edges.some((e, k) => e.to === first.id && (ctx.plan!.routes[k] === "trunk" || ctx.plan!.routes[k] === "end-down")); + return h("div", { class: `${P}-group`, "data-group": g.id, "data-depth": g.depth > 1 ? g.depth : undefined, "data-turn": turn ? "" : undefined, style: grow ? `--_ggrow:${grow}` : undefined }, h("span", { class: `${P}-glabel`, "aria-hidden": "true" }, g.label), kids); }; let k = 0; while (k < m.nodes.length) { @@ -1201,23 +1230,30 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { } /** - * The text variant's transcript (1.2), where the art does not fit: the participants on a line, then each message as number, sender, arrow, receiver, - * label and note; frames as indented brackets. A line breaks between participants and between words, never inside a name (each name is held whole). + * The text variant's transcript (1.2), where the art does not fit, as Draft B's reference (B6 of the pixel review): the participants on a line; then each + * message as its number, sender, arrow and receiver, its label on a line of its own and its note on another, every line of it hanging under the sender + * inside its frame's indent; frames as indented brackets. A line breaks between participants and between words, never inside a name (each name is held + * whole). Each line is a block: `--_in` is its indent in characters, `--_hang` how far its first line starts before it. */ export function transcript(P: string, m: Model): VNode[] { const out: VNode[] = []; const held = (s: string) => h("span", { class: `${P}-tx-name` }, s); const arrow = (k: DiagramLineKind) => (k === "main" ? "━▶" : k === "dashed" ? "┄▷" : "─▶"); - out.push(h("span", { class: `${P}-tx-line`, "data-ink": "names" }, m.nodes.flatMap((n, k) => [k ? " · " : "", held(n.name)])), "\n"); + const line = (attrs: VAttrs, indent: number, hang: number, ...kids: VChild[]) => h("span", { class: `${P}-tx-line`, ...attrs, style: hang ? `--_in:${indent + hang};--_hang:${hang}` : `--_in:${indent}` }, ...kids); + out.push(line({ "data-ink": "names" }, 0, 0, m.nodes.flatMap((n, k) => [k ? " · " : "", held(n.name)]))); + const digits = String(Math.max(1, ...m.steps.map((s) => ("n" in s ? s.n : 0)))).length; let indent = 0; for (const s of m.steps) { - const pad = " ".repeat(indent); - if ("band" in s) { out.push(h("span", { class: `${P}-tx-line`, "data-ink": "band" }, `${pad}── ${s.band} ──`), "\n"); continue; } - if ("open" in s) { out.push(h("span", { class: `${P}-tx-line`, "data-ink": "frame" }, pad, h("span", { "data-ink": "op" }, `[${s.open}]`), ` ${s.label}`), "\n"); indent++; continue; } - if ("otherwise" in s) { out.push(h("span", { class: `${P}-tx-line`, "data-ink": "frame" }, " ".repeat(indent - 1), h("span", { "data-ink": "op" }, "[else]"), ` ${s.otherwise}`), "\n"); continue; } - if ("close" in s) { indent = Math.max(0, indent - 1); out.push(h("span", { class: `${P}-tx-line`, "data-ink": "frame" }, `${" ".repeat(indent)}[end]`), "\n"); continue; } + const pad = 2 * indent; + if ("band" in s) { out.push(line({ "data-ink": "band" }, pad, 0, `── ${s.band} ──`)); continue; } + if ("open" in s) { out.push(line({ "data-ink": "frame" }, pad, 0, h("span", { "data-ink": "op" }, `[${s.open}]`), ` ${s.label}`)); indent++; continue; } + if ("otherwise" in s) { out.push(line({ "data-ink": "frame" }, 2 * Math.max(0, indent - 1), 0, h("span", { "data-ink": "op" }, "[else]"), ` ${s.otherwise}`)); continue; } + if ("close" in s) { indent = Math.max(0, indent - 1); out.push(line({ "data-ink": "frame" }, 2 * indent, 0, "[end]")); continue; } const a = m.byId.get(s.from)?.name ?? s.from, b = m.byId.get(s.to)?.name ?? s.to; - out.push(h("span", { class: `${P}-tx-line`, "data-n": s.n }, pad, h("span", { "data-ink": "num" }, `${s.n} `), held(a), " ", h("span", { "data-ink": s.kind === "main" ? "main" : "plain" }, arrow(s.kind)), " ", held(b), " ", h("span", { "data-ink": "label" }, s.label), s.note ? [" ", h("span", { "data-ink": "note" }, `(${s.note})`)] : null), "\n"); + const hang = digits + 2; + out.push(line({ "data-n": s.n }, pad, hang, h("span", { "data-ink": "num" }, String(s.n).padStart(digits, "0")), " ", held(a), " ", h("span", { "data-ink": s.kind === "main" ? "main" : "plain" }, arrow(s.kind)), " ", held(b))); + out.push(line({ "data-n": s.n }, pad + hang, 0, h("span", { "data-ink": "label" }, s.label))); + if (s.note) out.push(line({ "data-n": s.n }, pad + hang, 0, h("span", { "data-ink": "note" }, s.note))); } return out; } @@ -1258,7 +1294,7 @@ function sequenceSteps(ctx: TreeContext, m: Model): VElement { const word = kindWord(m, s.kind); list.c.push(h("li", { class: `${P}-msg`, "data-kind": s.kind, "data-from": s.from, "data-to": s.to, "data-self": self ? (last ? "start" : "end") : undefined, style: `--_a:${Math.min(ca, cb)};--_b:${Math.max(ca, cb) + 1}` }, h("span", { class: `${P}-said` }, h("span", { class: `${P}-num` }, String(s.n)), h("span", { class: `${P}-mlabel` }, s.label)), - h("span", { class: `${P}-route` }, a?.short ?? s.from, " ", inlineArrow(P, s.kind), h("span", { class: ctx.hidden }, " to "), " ", b?.short ?? s.to, word ? ` · ${word}` : ""), + h("span", { class: `${P}-route` }, a?.short ?? s.from, " ", h("span", { class: `${P}-to` }, inlineArrow(P, s.kind), h("span", { class: ctx.hidden }, " to "), " ", b?.short ?? s.to, word ? ` · ${word}` : "")), s.note ? h("span", { class: `${P}-note` }, s.note) : null)); } return h("div", { class: `${P}-steps` }, root); @@ -1428,7 +1464,8 @@ export function turnBackLanes(m: Model): { lane: Map; dropped: S // One group a key; its run from its highest to its lowest end. const groups = new Map(); m.edges.forEach((e, k) => { - const key = `${e.to}.${e.toRow}`; + // Lines to one key share a lane only when they state the same thing there (1.1; Neon's B9 of the code review). + const key = `${e.to}.${e.toRow}.${e.card?.to ?? ""}`; const a = at(e.from, e.fromRow ?? 0), b = at(e.to, e.toRow ?? 0); const g = groups.get(key) ?? { members: [], lo: Infinity, hi: -Infinity }; g.members.push(k); g.lo = Math.min(g.lo, a, b); g.hi = Math.max(g.hi, a, b); @@ -1492,7 +1529,8 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { "data-reach": m.type === "architecture" ? groupReach(m) : undefined, "data-gutter": plan?.gutter ? "" : undefined, "data-marks": m.marks ? "" : undefined, - "data-layout": dyn.layout, + // An automatic figure with no placement is stacked before script too: its cards have no cells yet. + "data-layout": dyn.layout ?? (m.unplaced ? "stacked" : undefined), "data-measured": dyn.layout ? "" : undefined, "data-bare": dyn.bare ? "" : undefined, "data-motion": m.motion.animated ? "animated" : undefined, @@ -1881,7 +1919,8 @@ export function portFloors(m: Model, radius = 8, head = 8): Record Math.round(x * 1e6) / 1e6))].sort((a, b) => a - b); + // Slots that share a point are one (a bus); the fractions are kept unrounded, so 48 is 48 and not 49 (Neon's P1 of the code review). + const f = fs.slice().sort((a, b) => a - b).filter((x, j, all) => j === 0 || x - all[j - 1]! > 1e-9); let need = Math.max(radius / f[0]!, radius / (1 - f[f.length - 1]!)); for (let j = 1; j < f.length; j++) need = Math.max(need, head / (f[j]! - f[j - 1]!)); const id = key.slice(0, key.lastIndexOf(".")); @@ -2399,6 +2438,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge const need = segs.length === 1 ? 2 * tk.foot : tk.foot + tk.radiusXs - 0.5; if (len(segs[0]!) >= need && len(segs[segs.length - 1]!) >= need) return true; drop(l.i, dev ? "has no room for its marks at an end" : ""); + far.delete(l.i); return false; }); // The rows a far line's corridor needs (1.1): a row gap that carries one is space-10 (space-8 otherwise); a margin corridor adds space-8. @@ -2541,7 +2581,8 @@ function sequenceGeometry(input: DrawnInput, geo: Geo, sn: ReturnType { const next = m.nodes[a.i + (li.dataset.self === "start" ? -1 : 1)]; const limit = next ? xOf(next.id) : li.dataset.self === "start" ? 0 : geo.w; return Math.abs(limit - x1) - s("6") - s("2-5") - s("2"); })() + // The neighbour on the loop's side, by column (right to left the author's order runs the other way). + ? (() => { const next = m.nodes.find((n) => n.col === a.col + (li.dataset.self === "start" ? -1 : 1)); const limit = next ? xOf(next.id) : li.dataset.self === "start" ? 0 : geo.w; return Math.abs(limit - x1) - s("6") - s("2-5") - s("2"); })() : Math.abs(x2 - x1) - 2 * s("2"); const need = Math.max(said ? said.getBoundingClientRect().width : 0, note ? note.getBoundingClientRect().width : 0); if (need > room + 0.5) geo.unseated.push(num); @@ -2554,6 +2595,15 @@ function sequenceGeometry(input: DrawnInput, geo: Geo, sn: ReturnType sum + c.getBoundingClientRect().width, 0) + s("3"); if (need > box.getBoundingClientRect().width + 0.5) (geo.misfit ??= []).push(`the frame "${head.querySelector(`.${P}-flabel`)?.textContent ?? ""}" is wider than its participants`); }); + // Any text box, grown space-1, that would lie on a frame's side fails the fit rule too (1.2; Neon's B7 of the code review): the figure stacks. + { + const sides = [...drawing.querySelectorAll(`.${P}-fbox`)].flatMap((el) => { const r = rectOf(el, origin); return [{ x: r.l + 0.5, t: r.t, b: r.b }, { x: r.r - 0.5, t: r.t, b: r.b }]; }); + if (sides.length) drawing.querySelectorAll(`.${P}-said, .${P}-note, .${P}-band > span`).forEach((el) => { + if (!el.getClientRects().length) return; + const r = grow(rectOf(el, origin), s("1")); + if (sides.some((f) => r.l < f.x && r.r > f.x && r.t < f.b && r.b > f.t)) (geo.misfit ??= []).push(`"${el.textContent?.trim() ?? ""}" would lie on a frame's side`); + }); + } return geo; } @@ -2768,10 +2818,13 @@ function masksMarkup(P: string, geo: Geo, tk: Tokens, base: string): { defs: str /** The drawing's ink: the SVG (lines, heads, dots, lifelines, cuts) and the labels, as one string. */ export function inkHtml(P: string, geo: Geo, tk: Tokens, base: string): string { const { defs, ids } = masksMarkup(P, geo, tk, base); - const lifelines = geo.lifelines.map((l) => ``).join("") - + (geo.bars ?? []).map((b) => ``).join(""); + // A sequence's lifelines are their own layer, under its frames; the bars, lines and heads are over them (1.2's order: lifelines, frames, bars, lines, + // plates and labels; Neon's P8 of the code review). + const lifelines = geo.lifelines.map((l) => ``).join(""); + const bars = (geo.bars ?? []).map((b) => ``).join(""); const lines = geo.lines.map((l, k) => lineMarkup(P, l, tk, ids.get(k) ?? null, l.from === l.to ? tk.radiusXs : tk.radius)).join(""); - const svg = `${defs ? `${defs}` : ""}${lifelines}${lines}`; + const under = lifelines ? `${lifelines}` : ""; + const svg = `${under}${defs ? `${defs}` : ""}${bars}${lines}`; const labels = geo.labels.map((l) => ` 1 ? ' data-lines="2"' : ""} style="left:${Math.round(l.box.l * 100) / 100}px;top:${Math.round(l.box.t * 100) / 100}px;width:${Math.round((l.box.r - l.box.l) * 100) / 100}px">${l.text.split("\n").map(escapeHtml).join("
")}
`).join(""); return svg + labels; } @@ -3037,7 +3090,8 @@ export function keyTarget(m: Model, from: string, key: string, drawn = false, rt * script, first in the figure) is passed over, never mistaken for the heading. */ const MANAGED = ["data-layout", "data-measured", "role", "aria-roledescription", "aria-labelledby", "aria-describedby", "aria-label", "tabindex", "data-stops", "hidden", "data-art"]; -const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion", "data-first-visit", "data-rtl"]; +// The figure's grid attributes follow the model too: an automatic figure's direction can change its columns after script (Neon's B8 of the code review). +const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion", "data-first-visit", "data-rtl", "data-cols", "data-reach", "data-gutter", "data-marks"]; const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_gpad", "--_gw", "--_mh", "--_rows", "--_row-gap"]; const absent = (value: VAttrs[string]) => value === undefined || value === null || value === false; function pairs(el: Element, v: VElement): boolean { diff --git a/packages/react/src/diagram-export.ts b/packages/react/src/diagram-export.ts index e58bb99a..bd5bc9ed 100644 --- a/packages/react/src/diagram-export.ts +++ b/packages/react/src/diagram-export.ts @@ -36,7 +36,10 @@ async function faceData(family: string): Promise { if (!url) continue; if (url.startsWith("data:")) return url; try { - const blob = await (await fetch(new URL(url, sheet.href ?? location.href))).blob(); + const res = await fetch(new URL(url, sheet.href ?? location.href)); + // A face that is not there (a 404's page) is not embedded: the file names the face instead. + if (!res.ok) return null; + const blob = await res.blob(); return await new Promise((resolve, reject) => { const r = new FileReader(); r.onload = () => resolve(String(r.result)); r.onerror = reject; r.readAsDataURL(blob); }); } catch { return null; } } @@ -68,29 +71,67 @@ function textOf(root: Element, origin: DOMRect, out: string[]) { } } -/** Every box with a fill or an edge as a rect, the drawing's SVG as it is, and the marks as images. */ +/** A rule drawn by a ::before or ::after (a lane's rule, a band's, a frame's else rule): its box from its own computed place, as a line or a rect. */ +function pseudoOf(el: Element, origin: DOMRect, out: string[]) { + // The structural rules only: a linked card's arrow (its name's ::after) is not drawn in a file (1.7, the decider's text edit). + if (!/-(lane|band|felse)(\s|$)/.test(` ${el.getAttribute("class") ?? ""}`)) return; + for (const which of ["::before", "::after"] as const) { + const cs = getComputedStyle(el, which); + if (!cs.content || cs.content === "none" || cs.content === "normal" || cs.display === "none") continue; + if (cs.position !== "absolute") continue; + const host = el.getBoundingClientRect(), hs = getComputedStyle(el); + const x = host.left + (Number.parseFloat(hs.borderLeftWidth) || 0) + (Number.parseFloat(cs.left) || 0) - origin.left; + const y = host.top + (Number.parseFloat(hs.borderTopWidth) || 0) + (Number.parseFloat(cs.top) || 0) - origin.top; + const w = Number.parseFloat(cs.width) || 0, h = Number.parseFloat(cs.height) || 0; + const bt = Number.parseFloat(cs.borderTopWidth) || 0; + // A dashed rule is drawn as its mask draws it: on and off at the rule's own height times its dash. + const dashed = cs.maskImage && cs.maskImage !== "none" ? ` stroke-dasharray="${Number.parseFloat(cs.maskSize) / 2 || 4} ${Number.parseFloat(cs.maskSize) / 2 || 4}"` : ""; + if (visible(cs.backgroundColor) && w && h) out.push(``); + else if (bt && visible(cs.borderTopColor)) out.push(``); + } +} + +/** An SVG of the figure as it is drawn: every painted part with its computed paint, sized and placed, and no motion's mask left on it. */ +function svgOf(el: SVGSVGElement, origin: DOMRect, out: string[]) { + const r = el.getBoundingClientRect(); + if (!r.width || !r.height) return; + if (el.getAttribute("class")?.endsWith("-motion-defs")) return; + const clone = el.cloneNode(true) as SVGSVGElement; + const src = [el, ...Array.from(el.querySelectorAll("*"))]; + const dst = [clone, ...Array.from(clone.querySelectorAll("*"))]; + // A viewBox drawn at another size (the flowchart's diamond): its strokes keep their width. + const vb = el.viewBox?.baseVal; + const stretched = Boolean(vb && vb.width && (Math.abs(vb.width - r.width) > 0.5 || Math.abs(vb.height - r.height) > 0.5)); + src.forEach((s, k) => { + const cs = getComputedStyle(s); + const d = dst[k] as Element; + for (const p of ["fill", "stroke", "stroke-width", "stroke-dasharray", "stroke-linecap", "stroke-linejoin", "opacity"]) d.setAttribute(p, cs.getPropertyValue(p)); + d.removeAttribute("class"); + // An entrance's reveal is its own mask: a file is at rest, every line whole. + if (/-reveal-/.test(d.getAttribute("mask") ?? "")) d.removeAttribute("mask"); + if (stretched && k > 0) d.setAttribute("vector-effect", "non-scaling-stroke"); + if (cs.display === "none") d.setAttribute("display", "none"); + }); + clone.setAttribute("x", String(r2(r.left - origin.left))); + clone.setAttribute("y", String(r2(r.top - origin.top))); + clone.setAttribute("width", String(r2(r.width))); + clone.setAttribute("height", String(r2(r.height))); + clone.removeAttribute("style"); + out.push(clone.outerHTML); +} + +/** + * Every box with a fill or an edge as a rect, the drawing's SVG as it is, the rules drawn by pseudo-elements, and the marks as images. The drawing's + * lines go first, under its cards and plates, as the page paints them (the ink is behind the nodes). + */ function boxesOf(root: Element, origin: DOMRect, out: string[]) { const all = [root, ...Array.from(root.querySelectorAll("*"))]; + const inks = all.filter((el): el is SVGSVGElement => el instanceof SVGSVGElement && el.closest("svg") === el && Boolean(el.closest("[class$='-ink']"))); + for (const svg of inks) svgOf(svg, origin, out); for (const el of all) { if (el instanceof SVGElement) { - if (el.tagName.toLowerCase() !== "svg" || el.closest("svg") !== el) continue; - const r = el.getBoundingClientRect(); - if (!r.width || !r.height) continue; - const clone = el.cloneNode(true) as SVGSVGElement; - // Every painted part takes its computed paint, so the file needs no stylesheet. - const src = [el, ...Array.from(el.querySelectorAll("*"))]; - const dst = [clone, ...Array.from(clone.querySelectorAll("*"))]; - src.forEach((s, k) => { - const cs = getComputedStyle(s); - const d = dst[k] as Element; - for (const p of ["fill", "stroke", "stroke-width", "stroke-dasharray", "stroke-linecap", "stroke-linejoin", "opacity"]) d.setAttribute(p, cs.getPropertyValue(p)); - d.removeAttribute("class"); - if (cs.display === "none") d.setAttribute("display", "none"); - }); - clone.setAttribute("x", String(r2(r.left - origin.left))); - clone.setAttribute("y", String(r2(r.top - origin.top))); - clone.removeAttribute("style"); - out.push(clone.outerHTML); + if (el.tagName.toLowerCase() !== "svg" || el.closest("svg") !== el || inks.includes(el as SVGSVGElement)) continue; + svgOf(el as SVGSVGElement, origin, out); continue; } const cs = getComputedStyle(el); @@ -112,11 +153,15 @@ function boxesOf(root: Element, origin: DOMRect, out: string[]) { edge(r!, cs.borderRightColor, x + w - r! / 2, y, x + w - r! / 2, y + h); } const bw = uniform ? sidesW[0]! : 0; - const stroke = bw && cs.borderTopStyle !== "none" && visible(cs.borderTopColor) ? cs.borderTopColor : "none"; + // A panel's rim is the sides' colour with its top lit (Neon's P8 of the code review): the box in the sides' colour, then the top edge in its own. + const sideColor = cs.borderLeftColor; + const stroke = bw && cs.borderTopStyle !== "none" && visible(sideColor) ? sideColor : "none"; if (fill !== "none" || stroke !== "none") { const dash = cs.borderTopStyle === "dashed" ? ` stroke-dasharray="4 2"` : ""; out.push(``); + if (stroke !== "none" && !dash && cs.borderTopColor !== sideColor && visible(cs.borderTopColor)) out.push(``); } + pseudoOf(el, origin, out); // A mark is its owner's file in the export theme's form. const image = /url\(["']?([^"')]+)["']?\)/.exec(cs.backgroundImage)?.[1]; if (image && /-mark$/.test(String(el.getAttribute("class")))) out.push(``); @@ -132,17 +177,31 @@ export const exportName = (fig: HTMLElement, ext: string) => `${(titleOf(fig).to async function svgText(fig: HTMLElement, options: DiagramExportOptions, embed: boolean): Promise<{ svg: string; w: number; h: number }> { const theme = options.theme ?? "page"; const had = fig.getAttribute("data-theme"); - // A file is at rest: no trace, no pending entrance, no mover. The figure is shown so for the read and put back after. - const traced = Array.from(fig.querySelectorAll("[data-lit], [data-dim], [data-near]")); - const marks = traced.map((el) => [el, el.getAttribute("data-lit"), el.getAttribute("data-dim"), el.getAttribute("data-near")] as const); - traced.forEach((el) => { el.removeAttribute("data-lit"); el.removeAttribute("data-dim"); el.removeAttribute("data-near"); }); + // A file is at rest: no trace, no pending or running entrance, no mover, no quiet run (Neon's B5 of the code review). The figure is shown so for the read + // and put back at once, before anything waits. + const states = ["data-lit", "data-dim", "data-near", "data-ahead", "data-arrival", "data-arrival-out"]; + const marked = Array.from(fig.querySelectorAll(states.map((a) => `[${a}]`).join(", "))); + const marks = marked.map((el) => [el, states.map((a) => el.getAttribute(a))] as const); + marked.forEach((el) => { for (const a of states) el.removeAttribute(a); }); const hidden = Array.from(fig.querySelectorAll("[class*='-flow'], [class*='-bead'], [class*='-packet']")); hidden.forEach((el) => { el.dataset.exportHidden = el.style.display; el.style.display = "none"; }); const entrance = fig.getAttribute("data-entrance"); if (entrance && entrance !== "done") fig.setAttribute("data-entrance", "done"); + // An entrance's or a run's colour animations are read at their end, and put back where they were. + const anims = fig.getAnimations({ subtree: true }).map((a) => ({ a, at: a.currentTime, running: a.playState === "running" })); + for (const { a } of anims) { const end = a.effect?.getComputedTiming().endTime; a.pause(); if (typeof end === "number" && Number.isFinite(end)) a.currentTime = end; } + // The viewer's figure (the skill's 9.11): its head and key, which the stage hides, are in the file, and it is read at 100% whatever the zoom. + const viewer = fig.getAttribute("data-viewer"); + if (viewer !== null) fig.removeAttribute("data-viewer"); + const scaled: Array<[HTMLElement, string]> = []; + for (let el = fig.parentElement; el; el = el.parentElement) { + const t = getComputedStyle(el).transform; + const m = /^matrix\(([^,]+),[^,]+,[^,]+,([^,]+),/.exec(t); + if (m && (Math.abs(Number(m[1]) - 1) > 1e-6 || Math.abs(Number(m[2]) - 1) > 1e-6)) { scaled.push([el, el.style.transform]); el.style.transform = "none"; } + } if (theme !== "page") fig.setAttribute("data-theme", theme); - const transitions = fig.style.getPropertyValue("--basalt-export"); fig.classList.add("basalt-exporting"); + let read: { body: string[]; w: number; h: number; ground: string }; try { void fig.offsetWidth; const pad = Number.parseFloat(getComputedStyle(fig).getPropertyValue("--basalt-space-4")) || 16; @@ -156,26 +215,30 @@ async function svgText(fig: HTMLElement, options: DiagramExportOptions, embed: b const body: string[] = []; for (const p of parts) boxesOf(p, origin, body); for (const p of parts) textOf(p, origin, body); - let style = ""; - if (embed) { - const faces: string[] = []; - for (const family of ["Geist", "Geist Mono"]) { - const data = await faceData(family); - if (data) faces.push(`@font-face{font-family:"${family}";src:url(${data});font-weight:100 900}`); - else if (process.env.NODE_ENV !== "production") console.warn(`Basalt diagramToSvg: the face "${family}" could not be read, so the file names it`); - } - if (faces.length) style = ``; - } - const svg = `${esc(titleOf(fig))}${esc(summaryOf(fig))}${style}${body.join("")}`; - return { svg, w, h }; + read = { body, w, h, ground }; } finally { fig.classList.remove("basalt-exporting"); - if (transitions) fig.style.setProperty("--basalt-export", transitions); if (theme !== "page") { if (had === null) fig.removeAttribute("data-theme"); else fig.setAttribute("data-theme", had); } + for (const [el, t] of scaled) el.style.transform = t; + if (viewer !== null) fig.setAttribute("data-viewer", viewer); + for (const { a, at, running } of anims) { a.currentTime = at; if (running) a.play(); } if (entrance && entrance !== "done") fig.setAttribute("data-entrance", entrance); hidden.forEach((el) => { el.style.display = el.dataset.exportHidden ?? ""; delete el.dataset.exportHidden; }); - for (const [el, lit, dim, near] of marks) { if (lit !== null) el.setAttribute("data-lit", lit); if (dim !== null) el.setAttribute("data-dim", dim); if (near !== null) el.setAttribute("data-near", near); } + for (const [el, values] of marks) states.forEach((a, k) => { const v = values[k]; if (v !== null && v !== undefined) el.setAttribute(a, v); }); + } + const { body, w, h, ground } = read; + let style = ""; + if (embed) { + const faces: string[] = []; + for (const family of ["Geist", "Geist Mono"]) { + const data = await faceData(family); + if (data) faces.push(`@font-face{font-family:"${family}";src:url(${data});font-weight:100 900}`); + else if (process.env.NODE_ENV !== "production") console.warn(`Basalt diagramToSvg: the face "${family}" could not be read, so the file names it`); + } + if (faces.length) style = ``; } + const svg = `${esc(titleOf(fig))}${esc(summaryOf(fig))}${style}${body.join("")}`; + return { svg, w, h }; } declare const process: { env: { NODE_ENV?: string } }; diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index d55cf43e..14c4bc96 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -101,7 +101,7 @@ export type { DataFlowDiagramProps, DataFlowLane, DataFlowNode } from "./data-fl export { SequenceDiagram } from "./sequence-diagram"; export type { DiagramFrameLabels, SequenceDiagramProps, SequenceMessage, SequenceParticipant, SequenceStep } from "./sequence-diagram"; export { SchemaDiagram } from "./schema-diagram"; -export type { SchemaColumn, SchemaDiagramProps, SchemaTable } from "./schema-diagram"; +export type { DiagramCardinality, DiagramCardinalityPair, SchemaColumn, SchemaDiagramProps, SchemaTable } from "./schema-diagram"; export { PhaseChart } from "./phase-chart"; export type { PhaseCall, PhaseChartProps } from "./phase-chart"; export { ShareBar } from "./share-bar"; diff --git a/packages/react/src/schema-diagram.tsx b/packages/react/src/schema-diagram.tsx index 5b8fd2b0..6a272d58 100644 --- a/packages/react/src/schema-diagram.tsx +++ b/packages/react/src/schema-diagram.tsx @@ -4,7 +4,7 @@ import { DiagramFigure } from "./diagram-figure"; import type { DiagramFigureProps } from "./diagram-figure"; import type { SchemaTable, DiagramPlacement, DiagramUnplaced } from "./diagram-core"; -export type { DiagramLegend, SchemaColumn, SchemaTable } from "./diagram-core"; +export type { DiagramCardinality, DiagramCardinalityPair, DiagramLegend, SchemaColumn, SchemaTable } from "./diagram-core"; interface SchemaDiagramBase extends DiagramFigureProps { /** diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index b5ac7d26..33240f4d 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4491,6 +4491,18 @@ .basalt-diagram[data-rtl] > .basalt-diagram-drawing { direction: ltr; } .basalt-diagram[data-rtl] > .basalt-diagram-drawing :is(.basalt-diagram-node > :not(.basalt-diagram-mark), .basalt-diagram-lane-name, .basalt-diagram-said, .basalt-diagram-note, .basalt-diagram-band, .basalt-diagram-fhead, .basalt-diagram-felse) { direction: rtl; } .basalt-diagram[data-rtl] .basalt-diagram-gbox > .basalt-diagram-glabel { inset-inline: auto var(--basalt-space-3); } + /* Stacked, a group's label is on its start side too (the sweep's 66-3), its masking margin mirrored. */ + .basalt-diagram[data-rtl] .basalt-diagram-group > .basalt-diagram-glabel { inset-inline: auto var(--basalt-space-3); margin-inline: 0 calc(-1 * var(--basalt-space-1-5)); } + /* A Mono detail is one left-to-right run in a right-to-left card (B5 of the pixel review), so its words keep their order and the card's start edge. */ + .basalt-diagram[data-rtl] .basalt-diagram-runs { direction: ltr; unicode-bidi: isolate; } + /* A frame's header, its else row and its rule are set right to left, so their place across the mirrored grid is measured from the frame's end edge in + the grid's own coordinates (--_fl and --_fw are left-to-right): the tab is in the frame's top start corner, on the right. */ + .basalt-diagram[data-rtl] .basalt-diagram-fhead { inset-inline-start: calc(100% - var(--_fl) - var(--_fw) + var(--basalt-size-hairline)); } + .basalt-diagram[data-rtl] .basalt-diagram-felse { padding-inline-start: calc(100% - var(--_fl) - var(--_fw) + var(--basalt-space-3)); } + .basalt-diagram[data-rtl] .basalt-diagram-felse::before { inset-inline-start: var(--_d-fer, calc(-1 * var(--basalt-space-4))); } + /* A self-call's words beside its loop, by the loop's physical side (data-self is the grid's own, left to right), in a label set right to left. */ + .basalt-diagram[data-rtl] .basalt-diagram-msg[data-self="end"] :is(.basalt-diagram-said, .basalt-diagram-note) { --_d-sj: var(--_drawn) left; margin-inline-start: 0; margin-inline-end: var(--_d-sm, 0); } + .basalt-diagram[data-rtl] .basalt-diagram-msg[data-self="start"] :is(.basalt-diagram-said, .basalt-diagram-note) { --_d-sj: var(--_drawn) right; margin-inline-end: 0; margin-inline-start: var(--_d-sm, 0); } .basalt-diagram[data-rtl] :is(.basalt-diagram-run, .basalt-diagram-mlabel, .basalt-diagram-tname, .basalt-diagram-cname, .basalt-diagram-ctype, .basalt-diagram-label, .basalt-diagram-glabel, .basalt-diagram-kind) { unicode-bidi: isolate; } .basalt-diagram[data-rtl] :is(.basalt-diagram-run, .basalt-diagram-mlabel, .basalt-diagram-cname, .basalt-diagram-label) { direction: ltr; } .basalt-diagram[data-rtl] .basalt-diagram-arrow { scale: -1 1; } @@ -4525,6 +4537,8 @@ /* A card grows to hold its ports (DECISIONS 306, section 4, call 3): the least height at which every port is on the flat part of its side and size-diagram-head from the next, drawn layout only. */ .basalt-diagram-node { --_d-mh: var(--_drawn) var(--_mh, auto); min-height: var(--_d-mh, auto); } + /* Stacked, a node held taller than its words (the 44px touch floor) centres them on the block axis (the sweep's 66-1). */ + .basalt-diagram-node { --_d-jc: var(--_drawn) normal; justify-content: var(--_d-jc, center); } .basalt-diagram-node[data-branch] { --_d-mi: var(--_drawn) 0; margin-inline: var(--_d-mi, var(--basalt-space-12) var(--basalt-space-6)); } .basalt-diagram-node:focus-visible { z-index: 2; outline: var(--basalt-size-focus-width) solid var(--basalt-border-focus); outline-offset: var(--basalt-size-focus-offset); } .basalt-diagram-node[data-near] { border-color: var(--basalt-border-hover); } @@ -4648,6 +4662,7 @@ border-radius: var(--basalt-radius-lg); } .basalt-diagram-group:first-child { margin-block-start: 0; } + .basalt-diagram-group[data-turn] { padding-block-start: calc(var(--basalt-space-8) + var(--basalt-space-4)); } .basalt-diagram-group > .basalt-diagram-glabel + .basalt-diagram-node { --_d-mt: 0; } .basalt-diagram-glabel { position: absolute; top: var(--basalt-space-2); inset-inline-start: var(--basalt-space-3); color: var(--basalt-text-secondary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); white-space: nowrap; } .basalt-diagram-group > .basalt-diagram-glabel { --_d-gl: var(--_drawn) none; display: var(--_d-gl, block); } @@ -4677,6 +4692,14 @@ /* The ink: lines, heads, dots, lifelines and labels, drawn by script over the drawing (and under the nodes). */ .basalt-diagram-ink { position: absolute; inset: 0; z-index: 0; pointer-events: none; } + /* A sequence's layers (1.2: lifelines, frames, bars, lines, plates and labels): its ink and its steps are not layers of their own, so its lifelines sit + under its frames and its bars and lines over them, and every plate over those. */ + .basalt-diagram[data-type="sequence"] > .basalt-diagram-drawing > .basalt-diagram-ink { z-index: auto; } + .basalt-diagram-lifes { position: absolute; top: 0; left: 0; z-index: 0; overflow: visible; } + .basalt-diagram[data-type="sequence"] .basalt-diagram-ink > .basalt-diagram-svg { z-index: 2; } + .basalt-diagram[data-type="sequence"] .basalt-diagram-steps { z-index: auto; } + .basalt-diagram[data-type="sequence"] .basalt-diagram-msg :is(.basalt-diagram-said, .basalt-diagram-note) { position: relative; z-index: 3; } + .basalt-diagram[data-type="sequence"] :is(.basalt-diagram-fhead, .basalt-diagram-felse) { z-index: 3; } .basalt-diagram-svg { position: absolute; top: 0; left: 0; overflow: visible; } .basalt-diagram-ruler { position: absolute; visibility: hidden; white-space: pre; pointer-events: none; } .basalt-diagram-ruler[data-f="name"] { font: var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans); } @@ -4770,11 +4793,15 @@ --_d-mb: var(--_drawn) 0; font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); } + /* Stacked, a row that follows a frame draws no divider: the frame's own edge parts them (P3 of the pixel review). */ + .basalt-diagram-frame + .basalt-diagram-msgs > .basalt-diagram-msg:first-child { border-top-color: transparent; } .basalt-diagram-said { --_d-sd: var(--_drawn) block; display: var(--_d-sd, contents); grid-column: var(--_a) / var(--_b); grid-row: 1; align-self: end; justify-self: center; margin-block-end: calc(var(--basalt-space-1) + var(--basalt-size-hairline)); padding-inline: var(--basalt-space-1-5); background: var(--_ground); white-space: nowrap; } .basalt-diagram-num { grid-column: 1; color: var(--basalt-text-tertiary); font-variant-numeric: tabular-nums; } .basalt-diagram-said .basalt-diagram-num { margin-inline-end: var(--_d-nm, 0); --_d-nm: var(--_drawn) var(--basalt-space-1-5); } .basalt-diagram-mlabel { grid-column: 2; color: var(--basalt-text-primary); font-family: var(--basalt-font-family-mono); } - .basalt-diagram-route { --_d-rd: var(--_drawn) none; display: var(--_d-rd, inline-flex); grid-column: 2; align-items: center; gap: var(--basalt-space-1); flex-wrap: wrap; color: var(--basalt-text-secondary); } + .basalt-diagram-route { --_d-rd: var(--_drawn) none; display: var(--_d-rd, inline-flex); grid-column: 2; align-items: center; column-gap: var(--basalt-space-1); row-gap: 0; flex-wrap: wrap; color: var(--basalt-text-secondary); } + /* The arrow and the name it points at are one unbreakable item, so a route that wraps breaks before the arrow (the sweep's 66-2). */ + .basalt-diagram-to { display: inline-flex; align-items: center; gap: var(--basalt-space-1); white-space: nowrap; } .basalt-diagram-note { --_d-nd: var(--_drawn) 2; grid-column: var(--_d-nc, 2); --_d-nc: var(--_drawn) var(--_a) / var(--_b); grid-row: var(--_d-nd, auto); align-self: start; justify-self: var(--_d-nj, stretch); --_d-nj: var(--_drawn) center; margin-block-start: var(--_d-nmt, 0); --_d-nmt: var(--_drawn) calc(var(--basalt-space-1) + var(--basalt-size-hairline)); padding-inline: var(--_d-npi, 0); --_d-npi: var(--_drawn) var(--basalt-space-1-5); background: var(--_d-nbg, none); --_d-nbg: var(--_drawn) var(--_ground); color: var(--basalt-text-tertiary); white-space: var(--_d-nws, normal); --_d-nws: var(--_drawn) nowrap; } /* A self-call's words start space-2-5 after its loop (the plate's own padding is part of that); on the last participant they go on the start side. */ .basalt-diagram-msg[data-self="end"] :is(.basalt-diagram-said, .basalt-diagram-note) { --_d-sj: var(--_drawn) start; justify-self: var(--_d-sj, stretch); --_d-sm: var(--_drawn) calc(50% + var(--basalt-space-6) + var(--basalt-space-1)); margin-inline-start: var(--_d-sm, 0); } @@ -4794,6 +4821,10 @@ --_d-fw: var(--_drawn) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2)); --_fl: var(--_d-fl, 0%); --_fw: var(--_d-fw, 100%); + /* The else rule runs edge to edge of the frame (P2 of the pixel review): drawn, the frame's columns; stacked, the frame's whole box, past its padding. */ + --_d-fel: var(--_drawn) var(--_fl); + --_d-few: var(--_drawn) var(--_fw); + --_d-fer: var(--_drawn) calc(100% - var(--_fl) - var(--_fw)); position: relative; padding-block: var(--basalt-size-control-lg) var(--basalt-space-2); padding-inline: var(--_d-fpi, var(--basalt-space-4)); @@ -4806,7 +4837,7 @@ .basalt-diagram-ftab { padding: var(--basalt-space-1) var(--basalt-space-3); border-inline-end: var(--basalt-size-hairline) solid var(--basalt-diagram-structure); border-block-end: var(--basalt-size-hairline) solid var(--basalt-diagram-structure); border-end-end-radius: var(--basalt-radius-xs); background: var(--_ground); color: var(--basalt-text-primary); font: var(--basalt-font-weight-semibold) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); } .basalt-diagram-flabel { margin-block-start: var(--basalt-space-1); margin-inline-start: calc(-1 * var(--basalt-space-1-5)); padding-inline: var(--basalt-space-1-5); background: var(--_ground); color: var(--basalt-text-secondary); font: var(--basalt-font-weight-medium) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); } .basalt-diagram-felse { position: relative; display: flex; align-items: center; gap: var(--basalt-space-1-5); height: var(--basalt-size-control-sm); margin: 0; padding-inline-start: calc(var(--_fl) + var(--basalt-space-3)); white-space: nowrap; } - .basalt-diagram-felse::before { content: ""; position: absolute; top: 0; inset-inline-start: var(--_fl); width: var(--_fw); height: var(--basalt-size-hairline); background: var(--basalt-diagram-structure); mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x; } + .basalt-diagram-felse::before { content: ""; position: absolute; top: 0; inset-inline-start: var(--_d-fel, calc(-1 * var(--basalt-space-4))); width: var(--_d-few, calc(100% + 2 * var(--basalt-space-4))); height: var(--basalt-size-hairline); background: var(--basalt-diagram-structure); mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x; } .basalt-diagram-felse .basalt-diagram-flabel { margin-block-start: 0; margin-inline-start: 0; } .basalt-diagram-fword { margin-inline-start: calc(-1 * var(--basalt-space-1-5)); padding-inline: var(--basalt-space-1-5); background: var(--_ground); color: var(--basalt-text-tertiary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); } .basalt-diagram-fword + .basalt-diagram-flabel { margin-inline-start: calc(-1 * var(--basalt-space-1-5)); } @@ -4834,12 +4865,21 @@ .basalt-diagram-drawing:has(> .basalt-diagram-text) { max-width: none; } .basalt-diagram-text-ink { font: inherit; } .basalt-diagram-tx-name { white-space: nowrap; color: var(--basalt-text-primary); } + /* A transcript's line (B6 of the pixel review): a block indented by its frame, its message's lines hanging under the sender. */ + .basalt-diagram-tx-line { + display: block; + /* stylelint-disable-next-line unit-disallowed-list -- characters of the Mono transcript: its indents are counted in characters, as the art's columns are */ + padding-inline-start: calc(var(--_in, 0) * 1ch); + /* stylelint-disable-next-line unit-disallowed-list -- characters of the Mono transcript: the number's width before the sender it hangs under */ + text-indent: calc(-1 * var(--_hang, 0) * 1ch); + } .basalt-diagram-text [data-ink="focal"], .basalt-diagram-text [data-ink="op"] { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-semibold); } .basalt-diagram-text :is([data-ink="name"], [data-ink="working"], [data-ink="plain"]) { color: var(--basalt-text-secondary); } .basalt-diagram-text :is([data-ink="main"], [data-ink="label"]) { color: var(--basalt-text-primary); } .basalt-diagram-text :is([data-ink="life"], [data-ink="num"], [data-ink="note"], [data-ink="frame"], [data-ink="band"]) { color: var(--basalt-text-tertiary); } .basalt-diagram-key-glyph { font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); color: var(--basalt-text-secondary); } .basalt-diagram-key-glyph[data-ink="main"] { color: var(--basalt-text-primary); } + .basalt-diagram-key-glyph[data-ink="focal"] { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-semibold); } @media (forced-colors: active) { .basalt-diagram-text :is([data-ink]) { color: CanvasText; } } /* A band names a phase: drawn, a 36px row with a full-width divider rule and its words on a plate; stacked, a line of words. */ @@ -4991,7 +5031,7 @@ @media (forced-colors: active) { /* After the rules above, at their specificity or more, for every kind, text role and trace state (1.17). */ - .basalt-diagram-svg, .basalt-diagram-swatch, .basalt-diagram-arrow { forced-color-adjust: none; } + .basalt-diagram-svg, .basalt-diagram-lifes, .basalt-diagram-swatch, .basalt-diagram-arrow { forced-color-adjust: none; } .basalt-diagram .basalt-diagram-line, .basalt-diagram .basalt-diagram-line[data-kind] { stroke: CanvasText; } .basalt-diagram .basalt-diagram-tip, .basalt-diagram .basalt-diagram-tip[data-kind], .basalt-diagram .basalt-diagram-dot { fill: CanvasText; } .basalt-diagram .basalt-diagram-tip[data-open], .basalt-diagram .basalt-diagram-tip[data-kind][data-open] { fill: none; stroke: CanvasText; } @@ -5044,8 +5084,8 @@ /* Print: the lines, the key's swatches, a card's mark and every focal node's fill print whatever the reader's "Background graphics" setting (DECISIONS 292, 2.6; every focal node, with a mark or without, DECISIONS 298). */ @media print { - .basalt-diagram-svg, .basalt-diagram-swatch, .basalt-diagram-arrow, .basalt-diagram-mark, .basalt-diagram-node[data-focal] { -webkit-print-color-adjust: exact; print-color-adjust: exact; } - .basalt-diagram-hint, .basalt-diagram-tap-hint, .basalt-diagram-clear { display: none !important; } + .basalt-diagram-svg, .basalt-diagram-lifes, .basalt-diagram-swatch, .basalt-diagram-arrow, .basalt-diagram-mark, .basalt-diagram-node[data-focal] { -webkit-print-color-adjust: exact; print-color-adjust: exact; } + .basalt-diagram-hint, .basalt-diagram-tap-hint, .basalt-diagram-clear, .basalt-diagram-download { display: none !important; } /* A figure prints untraced (DECISIONS 306, 1.7): every line, head and label in its resting ink, over a trace, a touch trace or a quiet run. */ .basalt-diagram .basalt-diagram-edge :is(.basalt-diagram-line, .basalt-diagram-tip[data-open]) { stroke: var(--basalt-diagram-edge) !important; } .basalt-diagram .basalt-diagram-edge .basalt-diagram-line[data-kind="main"] { stroke: var(--basalt-diagram-edge-main) !important; } @@ -5064,9 +5104,22 @@ .basalt-diagram-edge[data-ahead] .basalt-diagram-line { stroke: var(--basalt-diagram-edge-dim); } .basalt-diagram-edge[data-ahead] .basalt-diagram-tip:not([data-open]) { fill: var(--basalt-diagram-edge-dim); } .basalt-diagram-edge[data-ahead] .basalt-diagram-tip[data-open] { stroke: var(--basalt-diagram-edge-dim); } + /* The text art's run and its build (1.2): an unreached message's label secondary and its arrow tertiary, the current one's number primary; before the build + reaches a message (pending), the same quiet. */ + .basalt-diagram-text [data-n][data-ahead] [data-ink="label"], .basalt-diagram[data-motion="animated"][data-entrance="pending"] .basalt-diagram-text [data-n] [data-ink="label"] { color: var(--basalt-text-secondary); } + .basalt-diagram-text [data-n][data-ahead] :is([data-ink="main"], [data-ink="plain"]), .basalt-diagram[data-motion="animated"][data-entrance="pending"] .basalt-diagram-text [data-n] :is([data-ink="main"], [data-ink="plain"]) { color: var(--basalt-text-tertiary); } + .basalt-diagram-text [data-n][data-arrival] [data-ink="num"] { color: var(--basalt-text-primary); } + @media (prefers-reduced-motion: reduce) { + .basalt-diagram-msg[data-ahead] .basalt-diagram-mlabel { transition: none; } + } @media (forced-colors: active) { .basalt-diagram .basalt-diagram-msg[data-ahead] .basalt-diagram-mlabel { color: GrayText; } .basalt-diagram .basalt-diagram-edge[data-ahead] .basalt-diagram-line { stroke: GrayText; } + /* The head goes with its line (Neon's B7 of the code review). */ + .basalt-diagram .basalt-diagram-edge[data-ahead] .basalt-diagram-tip:not([data-open]) { fill: GrayText; } + .basalt-diagram .basalt-diagram-edge[data-ahead] .basalt-diagram-tip[data-open] { stroke: GrayText; } + .basalt-diagram .basalt-diagram-text [data-n][data-ahead] [data-ink] { color: GrayText; } + .basalt-diagram .basalt-diagram-text [data-n][data-arrival] [data-ink="num"] { color: Highlight; } } @media print { .basalt-diagram .basalt-diagram-msg[data-ahead] .basalt-diagram-mlabel { color: var(--basalt-text-primary) !important; } @@ -5215,7 +5268,10 @@ dialog.basalt-dialog.basalt-diagram-viewer { --_out: calc(var(--basalt-duration-slow) * 0.75); margin: 0; - border: 0; + /* The rim stays (the form dialog's own, B4 of the pixel review): only the browser's dialog margin and its inline and block insets are reset, so the box is + placed by its top and left in either direction (right to left, the browser's inset-inline-end would otherwise win and push it off the window). */ + right: auto; + bottom: auto; max-width: none; max-height: none; opacity: 0; diff --git a/tools/html-skill/src/compose.mjs b/tools/html-skill/src/compose.mjs index 2c05398b..8271b793 100644 --- a/tools/html-skill/src/compose.mjs +++ b/tools/html-skill/src/compose.mjs @@ -679,7 +679,9 @@ function writeDiagrams(markup, held, parts, notes, marks) { let rewrote = false; for (const n of cards) { if (!n || n.mark === undefined || n.mark === null) continue; - if (typeof n.mark === "string") useMark(marks, n.mark, n, notes); + // A data flow's step counts its lane's label as its words, as React's check does (DECISIONS 306, 1.6; Neon's B10 of the code review). + const lane = spec.type === "data-flow" && Array.isArray(spec.lanes) ? spec.lanes.find((l) => l && l.id === n.lane) : null; + if (typeof n.mark === "string") useMark(marks, n.mark, lane ? { ...n, laneLabel: lane.label } : n, notes); else { n.mark = ownMark(marks, n.mark); rewrote = true; } } if (rewrote) { @@ -729,7 +731,7 @@ function useMark(marks, id, node, notes) { } function checkSays(file, id, node, notes) { const says = (Object.hasOwn(file.says, id) ? file.says[id] : undefined) ?? []; - const words = [node.name, node.kind, node.detail].filter(Boolean).join(" ").toLowerCase(); + const words = [node.name, node.kind, node.detail, node.laneLabel].filter(Boolean).join(" ").toLowerCase(); if (says.length && !says.some((w) => words.includes(w.toLowerCase()))) notes.push(`${node.id}'s mark (${id}) stands for ${says.join(" or ")}, and none of its words say so: a mark never carries a fact alone`); } diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 9445c6c4..04a2f6c8 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -27,7 +27,14 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, /** The figure's markup before script runs: its attributes and its inside, as compose.mjs writes it (and as this script writes it for a figure that has none). */ function markup(spec, base, viewer) { - var model = buildModel(spec); + // An automatic figure's words are written on the placement compose.mjs made, in the type's own direction, so before script its cards are in their + // cells and not piled into one (Neon's B8 of the code review). + var auto = spec.layout === 'auto' && (spec.type === 'architecture' || spec.type === 'flowchart' || spec.type === 'schema'); + var list = auto ? (Array.isArray(spec.placement) ? spec.placement : spec.placement ? [spec.placement] : []) : []; + var first = spec.direction || (spec.type === 'flowchart' ? 'down' : 'right'); + var placed = null; + for (var i = 0; i < list.length; i++) if (list[i].direction === first) placed = list[i]; + var model = buildModel(spec, { placement: placed || list[0] }); var tree = figureTree(model, {}, options(base, spec, viewer)); var html = toHtml(tree, slots(model, spec, base, false)); var open = html.indexOf('>'); @@ -77,6 +84,7 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figure.insertAdjacentHTML('beforeend', made.inner); } model.warnings.forEach(function (w) { console.warn('Basalt diagram: ' + w); }); + if (model.motion.animated && model.motion.firstVisit && !figure.id) console.warn('Basalt diagram: "entrance": "first-visit" needs an id on the figure: without one the entrance plays on every visit'); var opts = options(base, spec, viewer); var state = {}; var measured = null; @@ -111,6 +119,8 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, clearBtn.addEventListener('click', function () { if (touchTrace) { touchTrace = null; retrace(); } }); foot.appendChild(clearBtn); } else if (!want && clearBtn) { clearBtn.remove(); clearBtn = null; } + // "Clear highlight" is last in the foot, after the motion module's buttons, which may be added after it (Neon's P7); never moved while it has focus. + if (clearBtn && clearBtn !== clearBtn.parentNode.lastElementChild && document.activeElement !== clearBtn) clearBtn.parentNode.appendChild(clearBtn); if (clearBtn) { if (touchTrace) clearBtn.removeAttribute('aria-disabled'); else clearBtn.setAttribute('aria-disabled', 'true'); } } function onTap(event) { @@ -131,13 +141,22 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, function layout() { // An automatic figure: the first direction, in order, whose drawn layout fits at this width; none fits, the first, stacked. if (auto && placements.length > 1 && !viewer) { - var chosen = null; + var chosen = null, why = [], fitsByWidth = false; for (var k = 0; k < order.length && !chosen; k++) { var place = placeOf(order[k]); if (!place) continue; var trial = buildModel(spec, { rtl: rtl, placement: place }); - var t = measureFigure(figure, trial, P, base, {}, function (d) { syncAttributes(figure, figureTree(trial, d, opts)); }); - if (t.dyn.layout === 'drawn') chosen = trial; + var said = []; + var t = measureFigure(figure, trial, P, base, {}, function (d) { syncAttributes(figure, figureTree(trial, d, opts)); }, function (w) { said.push(w); }); + if (t.dyn.layout === 'drawn') { chosen = trial; break; } + var reasons = said.filter(function (w) { return w.indexOf('the drawn layout does not fit') === 0; }).map(function (w) { return w.replace(/^the drawn layout does not fit at \d+px: /, ''); }); + if (reasons.length) fitsByWidth = true; + why.push('laid ' + order[k] + ' ' + (reasons.length ? reasons.join('; ') : 'it needs ' + Math.ceil(t.least || 0) + 'px')); + } + // When no direction draws and one had the width, one warning for the figure and its reasons (DECISIONS 322, rule 5), as React's. + if (!chosen && fitsByWidth) { + var key = why.join('; ').replace(/\d+px/g, ''); + if (figure.__autoWarned !== key) { figure.__autoWarned = key; console.warn('Basalt diagram: layout="auto" draws in neither direction at ' + Math.round(figure.clientWidth) + 'px, so the figure is stacked: ' + why.join('; ') + '. Name a side on a line named here (fromSide, toSide), shorten a label named here, or write the figure authored: placeDiagram returns every cell to start from'); } } model = chosen || buildModel(spec, { rtl: rtl, placement: placeOf(order[0]) }); } @@ -150,7 +169,8 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, var tm = buildModel(spec, { rtl: rtl, placement: pl }); var tr = viewer.measure(figure, tm, P, base, {}, function (d) { syncAttributes(figure, figureTree(tm, d, opts)); }); if (tr.dyn.layout !== 'drawn') continue; - var fit = Math.min(room.w / figure.offsetWidth, room.h / figure.offsetHeight); + // Fit as the viewer takes it (whole per cents, 200% at most), so a tie at 200% keeps the type's own direction. + var fit = Math.min(2, Math.floor(Math.min(room.w / figure.offsetWidth, room.h / figure.offsetHeight) * 100 + 1e-6) / 100); if (fit > best + 1e-6) { best = fit; pickM = tm; } } if (pickM) model = pickM; @@ -169,10 +189,13 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, if (fresh) { ink.innerHTML = measured.ink; drawn = measured.ink; } retrace(); // In the frame an animated figure's lines are first drawn it is pending; after that the motion module follows a drawing that changed. - if (animated && measured.tokens) { entranceDrawn(figure, Boolean(measured.geo && measured.geo.lines.length)); if (fresh && motion) motion.redrawn(); } + // The text variant (DECISIONS 306, 1.2): the art where its widest line fits the block (the diagram-text module's), the transcript otherwise; in the + // viewer, the art at its own width (9.3). Written before the entrance reads it (its art is its lines) and before the viewer reads the figure's size. + var hadArt = model.text ? figure.querySelector('.diagram-text[data-art]') : null; + if (model.text && typeof _.diagramText === 'function') _.diagramText(figure, model, spec, viewer); + var art = model.text ? figure.querySelector('.diagram-text[data-art]') : null; + if (animated && measured.tokens) { entranceDrawn(figure, Boolean(measured.geo && measured.geo.lines.length) || Boolean(art)); if ((fresh || art !== hadArt) && motion) motion.redrawn(); } if (viewer && viewer.onMeasured && measured.tokens) viewer.onMeasured(measured, figure); - // The text variant (DECISIONS 306, 1.2): the art where its widest line fits the block (the diagram-text module's), the transcript otherwise. - if (model.text && typeof _.diagramText === 'function') _.diagramText(figure, model, spec); } function setState(next) { state = next; apply(state); } // A move of the roving stop touches the two nodes it moves between, not the whole figure. From ca505f6acdf46fd36a95f0fab0aa11a581e6a76c Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:24:26 -0600 Subject: [PATCH 45/62] The decider's text edits after the build, in foundations, and the skill's usage texts (Neon P9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Foundations: a lane is shared by runs never beside each other, and a bar's ink is the pixel that ends at its distance (1.1); a stacked group entered by a turn has space-12 above, its label in the first space-8 (1.3); the viewer is the form dialog's box on a native modal in its own chunk, drawing and behaving as Dialog does, the rim included, and "Expand" is words only (9.1, 9.2, and the Phosphor glyph struck from Icons); the least drawn width is the first width the engine draws the figure at, found once for its data, a text sequence holds its art, and a same-tab link closes the viewer first (9.3, 9.7); right to left, drawn the figure mirrors and stacked not yet, a named gap (6.9); a linked card's arrow is not drawn in a file (1.7). The ruling's sentence on ways, a decision's points and turn-backs went in with section 6. The decision's own 1.8 and 5.1 edits are the decider's document's. The skill's usage texts say what batch B added: flow on any edge, a mark on a step or a participant, a group's parent, href, a label's break, bars and frames, the text variant, automatic layout and the first visit. Their caps are their measured sizes and a little more (diagram 4,554 → 4,600; diagram-motion 1,428 → 1,450). Co-Authored-By: Claude Opus 5.5 --- docs/foundations.md | 27 ++++++++++++-------- tools/html-skill/src/modules.json | 4 +-- tools/html-skill/src/usage/diagram-motion.md | 1 + tools/html-skill/src/usage/diagram.md | 5 ++-- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/foundations.md b/docs/foundations.md index 2a5e3a65..a5571f08 100644 --- a/docs/foundations.md +++ b/docs/foundations.md @@ -1736,7 +1736,8 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b flowchart are a spine with indented branches: a rail and a trunk at the start, one lane at the end, every route taken from the order. A line that leaves or passes a spine card runs in an end gutter outside the cards (lanes `space-3-5` apart, four at most; the gutter is its lanes and `space-3`), down into a card's top or up into its bottom. A data flow is its steps in order with bypasses in that gutter. A sequence is a strip of participants and a numbered list that names each message's sender, - receiver and kind. A schema is its cards in an auto-fit grid with no lines, because every foreign-key row writes its target. + receiver and kind. A schema is its cards in an auto-fit grid with no lines, because every foreign-key row writes its target. A stacked + group whose first card is entered by a turn has `space-12` above; its label stays in the first `space-8`. - **Several end lines into one card nest:** the line from the outermost lane turns lowest and enters nearest the end edge; each line from a lane further in turns `space-5` higher and enters `space-3` further in. Their labels are seated `space-2-5` clear of the innermost entry, each on its own turn's height, taken before the half-pixel snap. @@ -1776,8 +1777,9 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b plain line from a dot on its row to a head on the referenced row. It comes from the column's own record. Where the author states how many (`cardinality`, on every foreign key or none), the dot and the head give way to crow's-foot marks in the line's ink, inside `size-diagram-foot` at each end, and the column gap is `space-12` plus `space-3`: three lanes at most, none nearer a table than the - zone plus `radius-xs`. A key two or more columns away is drawn along a corridor: a row gap clear of the tables between, or the margin - above or below. A line that cannot be drawn clean is left out alone, and its row still writes the target. + zone plus `radius-xs`. A lane is shared by runs that are never beside each other (their spans overlap or come within `space-8`). A + bar's ink is the pixel that ends at its distance. A key two or more columns away is drawn along a corridor: a row gap clear of the + tables between, or the margin above or below. A line that cannot be drawn clean is left out alone, and its row still writes the target. ### The key, the summary and the list @@ -1814,12 +1816,14 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b ### The viewer "Expand", in the figure's foot beside "View as list", opens the figure in a dialog: the window less `space-4` from 720, the whole -window under it, in the form dialog's box with the sheet's head, body and foot. Decided by the council's decider alone as part 9 -of DECISIONS 301 (DECISIONS 310, the owner's ask); no draft and no check. **Status:** the implementation has not been reviewed. Built -words only (no glyph) and on a native modal ``, deviations the PR records. +window under it, in the form dialog's box, on a native modal `` in the viewer's own chunk, drawing and behaving as `Dialog` does, the +rim included, with the sheet's head, body and foot. "Expand" is words only. Decided by the council's decider alone as part 9 of DECISIONS 301 +(DECISIONS 310, the owner's ask), revised after the pixel review; no draft and no check. **Status:** the implementation has not been reviewed. - **What it holds** is the drawn layout, drawn again from the same data at the stage's inner width, never under the figure's least - drawn width and never over the page row unless that is more. The stack is held only when nothing is drawn. + drawn width and never over the page row unless that is more. The least drawn width is the first width the engine draws the figure + at, found once for its data. The stack is held only when nothing is drawn. A text sequence holds the art at its own width, never the + transcript. A linked card is followed on a click, a tap or Enter, and a link that stays in this tab closes the viewer first. - **Laid out at 100%, zoomed by the reader.** The layout is made in real CSS pixels and never measured while zoomed. The zoom is one `transform: scale()` on that layer: never a `viewBox`, CSS `zoom`, a canvas or a picture, and no layer is held at an old size. Under `scale(3)` the figure is the pixels a 3x screen draws. @@ -1925,8 +1929,10 @@ over its lifeline; a stacked chip draws the mark before the name. - Forced colours: cardinality marks follow their line; an activation's edge is `CanvasText`; a frame's edges are `GrayText`; a linked name is `LinkText`, underlined. - Print: a figure prints untraced, in its resting ink, and in the light theme whatever the screen shows. -- Right to left: the figure mirrors and its words do not. Identifiers are isolated left to right as runs; named sides swap; the - arrow keys stay physical; the text art stays left to right. +- Right to left: drawn, the figure mirrors and its words do not; stacked, not yet (the rail, the trunk and the end gutter stay on their + left-to-right sides: a named gap, on the backlog). Identifiers are isolated left to right as runs; named sides swap; the arrow keys + stay physical; the text art stays left to right. +- Export: a linked card's arrow is not drawn in a file. ### Diagram tokens @@ -2314,8 +2320,7 @@ A product's own logo is its own; the social marks are Phosphor's (below). A diag - **Which set draws a glyph.** Wherever a component draws check, close, the chevrons, copy, plus, minus or search, it draws the core set's glyph; Phosphor Bold draws what the core set lacks (the status marks, the sort caret, the social - marks, a diagram's "Expand", `ArrowsOutSimple`, until the core set draws one; built with words only for now, a deviation the - diagrams PR records), and the key glyphs ⌘ ⌥ ⌃ stay Phosphor's. A component never draws Phosphor's version of a core glyph. **Status:** decided by the + marks), and the key glyphs ⌘ ⌥ ⌃ stay Phosphor's. A component never draws Phosphor's version of a core glyph. **Status:** decided by the council (DECISIONS 138) and approved by the owner (DECISIONS 139); the implementation has not been reviewed. - **Drawing.** Actions are exactly three straight lines (copy, edit, trash and download are the agreed exceptions, drawn richer). Every other glyph is eight cubic slots on the 24 grid, and an diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index 749007b4..4137941a 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -779,7 +779,7 @@ "kbd" ], "budget": 137700, - "usage": 4300, + "usage": 4600, "builds": [ "kbd" ] @@ -805,7 +805,7 @@ "toggle" ], "budget": 28450, - "usage": 1300, + "usage": 1450, "builds": [ "loops", "toggle" diff --git a/tools/html-skill/src/usage/diagram-motion.md b/tools/html-skill/src/usage/diagram-motion.md index 479364ef..efba91b7 100644 --- a/tools/html-skill/src/usage/diagram-motion.md +++ b/tools/html-skill/src/usage/diagram-motion.md @@ -5,5 +5,6 @@ Added for you when a diagram's JSON says `"motion": "animated"` (with `loops`); - **Entrance:** in view (two fifths of it), each line draws once in the author's order, inside five seconds; a sequence's arrows go in message order and each label lifts from secondary to primary. Every word is at rest from the first frame. It never plays under reduced motion, in forced colours, under the hold or in print, and settles at once on a hover, a focus, a key or a control. - **Loops:** a flow line's cuts, a pulse's bead, a repeating packet. They run only in view, never while a node is traced, and stop under the page's hold. The figure's foot then has "Pause animations" (the hold's own button, built for you) after "View as list". Don't add a second one for the diagram. - **One mover a figure:** a pulse or a packet, never both. Flow is a state of a line and never runs on a line the mover travels. +- **First visit:** `"entrance": "first-visit"` with an `id` on the figure plays the entrance once; later visits are at rest. A text sequence builds by ink instead, in view. - **Run:** "Play the run" sends one dot through a sequence's messages; it reads "Stop the run" while it runs. It works under the hold and under reduced motion (by colour alone). - `Basalt.diagram(figure, spec)` with a new `packet.send` value sends one message. diff --git a/tools/html-skill/src/usage/diagram.md b/tools/html-skill/src/usage/diagram.md index de16bf0b..eb31b43e 100644 --- a/tools/html-skill/src/usage/diagram.md +++ b/tools/html-skill/src/usage/diagram.md @@ -23,7 +23,8 @@ Boxes and the lines between them. `compose.mjs` writes the figure's words into t - **Required:** `title`, `summary` (what it shows, in a sentence). `source`, `heading` (2 to 6, default 3). - Monochrome: nothing takes a colour but a card's service mark. The drawn layout is used only where it fits; otherwise the figure is stacked, one column at most 480 wide. - **Motion:** `"motion": "animated"` (default still) draws each line once in view, every word at rest; it brings in `diagram-motion` (its usage says the rest). Motion never carries a fact alone. -- **Flow, pulse, packet:** `"flow": true` on a `main` or `plain` edge marches it (give it a label). `"pulse": ["a", "b", "c"]` runs a bead along a route; `"packet": { "path": [...], "repeat": true }` sends a dot. One of pulse and packet; never flow on the mover's route. Architecture and data flow only. +- **Flow, pulse, packet:** `"flow": true` on an edge marches it (a dashed line's own dashes) (give it a label). `"pulse": ["a", "b", "c"]` runs a bead along a route; `"packet": { "path": [...], "repeat": true }` sends a dot. One of pulse and packet; never flow on the mover's route. Architecture and data flow only. - **Run:** `"run": true` on a sequence adds "Play the run", a dot through every message. -- **Mark:** `"mark": "aws-ecs-service"` on an architecture node, 16px in the card's top end corner, the owner's file and colours; the card's words still name the service. Your own: `{ "onLight": "logo.svg", "onDark": "logo-dark.svg" }`, read into the page. A page drawing from script names its marks: ``. +- **Parts:** a group's `parent` (two levels); `href` (and `"target": "_blank"`) makes a card a link; a label's `"\n"` is its one break; a sequence's message `activate`/`deactivate` (a bar) and steps `{ "frame": "opt" | "loop", "label", "steps" }` or `{ "frame": "alt", "branches": [...] }`; `"variant": "text"` draws it as text art; `"layout": "auto"` places the cards for you (compose.mjs, at build time); `"entrance": "first-visit"` with an `id` plays the entrance once. +- **Mark:** `"mark": "aws-ecs-service"` on an architecture node, a data flow's step or a sequence's participant, 16px in the card's top end corner, the owner's file and colours; the card's words still name the service. Your own: `{ "onLight": "logo.svg", "onDark": "logo-dark.svg" }`, read into the page. A page drawing from script names its marks: ``. - **Marks:** `aws-*`, `azure-*`, `gcp-*`, `kubernetes`, `temporal`, `sonarqube`, `github`, `coderabbit`, `greptile`, `blacksmith`, `jenkins`, `servicenow`, `blazemeter`. `node .agent/skills/basalt-html/compose.mjs --marks [aws azure gcp ...]` prints each id with the words its card must say and which are unofficial; a database card (Aurora, RDS) takes `aws-database`. From 78a9904397bfcf0288d5f2e05280ae33def0593e Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:24:34 -0600 Subject: [PATCH 46/62] Round 66: the summary as built, the five parts with no picture, and the viewer shots' focus ring said (Fable P1, P5, P6) The summary says batch B is whole and fixed after both reviews and the sweep (P1). Two steps for the parts nobody had seen drawn (P5): the data flow with a mark on a step (S3's, on the sealed segment in the S3 lane), its batch line as a dashed flow, and two more lines so two cards are each entered by two end lines when stacked; and section 4's calls 2 and 3 (a one-column schema's two turn-back lanes, and a card grown to 48 for a straight line and two others). The viewer step says its shots open the viewer by script, so the stage shows its keyboard ring, which a click or a tap does not (P6). Co-Authored-By: Claude Opus 5.5 --- tools/review/round66.tsx | 56 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx index 58e3af85..4b54e10f 100644 --- a/tools/review/round66.tsx +++ b/tools/review/round66.tsx @@ -11,6 +11,7 @@ import type { Round } from "./rounds"; import { diagramToSvg } from "../../packages/react/src/diagram-export"; import { awsEcsService } from "../../packages/react/src/marks/aws-ecs-service"; import { awsEcsTask } from "../../packages/react/src/marks/aws-ecs-task"; +import { awsS3Bucket } from "../../packages/react/src/marks/aws-s3-bucket"; // Marks on a sequence's participants (DECISIONS 306, 1.6): the service and the sandbox, and none on Marcus, who is a person. const PARTICIPANT_MARKS: Record = { svc: awsEcsService, agent: awsEcsTask }; @@ -45,6 +46,29 @@ function Exported({ k }: { k: Key }) { ); } +/** Figures the fixture does not hold, for the parts that had no picture (the pixel review's P5). */ +type Inline = { type: "architecture" | "data-flow" | "schema" } & Record; +const DATA_FLOW_PARTS: Inline = (() => { + const d = structuredClone(data.dataFlow) as unknown as Inline & { nodes: Array>; edges: Array> }; + // A mark on a step (1.6): the sealed segment, in the S3 lane, carries S3's own mark; the lane's label says S3. + for (const n of d.nodes) if (n.id === "seg") n.mark = awsS3Bucket; + // A dashed flow (1.5): the batch line's own dashes march. Two more lines make two cards entered by several end lines (1.3), seen stacked. + d.edges = [...d.edges.map((e) => (e.kind === "dashed" ? { ...e, flow: true } : e)), { from: "append", to: "seal", label: "window check" }, { from: "hear", to: "seg", label: "cursor sync" }]; + return { ...d, title: "How one message reaches everyone in the room (extended)", motion: "animated", summary: `${String(d.summary)} Two more lines show several end lines entering one card when it is stacked.` }; +})(); +const schemaTable = (name: string, row: number, refs: string[] = []) => ({ name, col: 1, row, columns: [{ name: "id", key: "PK" }, ...refs.map((r) => ({ name: `${r}_id`, key: "FK", references: `${r}.id` }))] }); +const CALL_2: Inline = { type: "schema", title: "One column: turn-backs beside each other take lanes (section 4, call 2)", summary: "b references c and c references a; their turn-backs run beside each other down the column's end side, so each takes a lane.", legend: { plain: "A foreign key" }, tables: [schemaTable("a", 1), schemaTable("b", 2, ["c"]), schemaTable("c", 3, ["a"])] }; +const CALL_3: Inline = { type: "architecture", title: "A card grows to hold its ports (section 4, call 3)", summary: "The coordinator's end side holds a straight line and two others, so it is 48 tall at every width.", legend: { main: "Request", plain: "Call" }, + nodes: [{ id: "a", name: "Incident response coordinator", col: 1, row: 2 }, { id: "b", name: "Queue", col: 2, row: 2 }, { id: "c", name: "Store", col: 2, row: 3 }, { id: "d", name: "Audit", col: 2, row: 4 }, { id: "e", name: "Search", col: 3, row: 2 }, { id: "f", name: "Mail", col: 4, row: 2 }], + edges: [{ from: "a", to: "b", kind: "main" }, { from: "a", to: "c", toSide: "left" }, { from: "a", to: "d", toSide: "left" }, { from: "b", to: "e" }, { from: "e", to: "f" }] }; +function InlineFigure({ spec }: { spec: Inline }) { + const { type, ...props } = spec; + const figure = type === "architecture" ? )} /> + : type === "data-flow" ? )} /> + : )} />; + return
{figure}
; +} + /** A figure from the extended fixture. A "viewer" state opens its viewer (and "viewer-200" zooms to 200%) once it is drawn, for the shot. */ function Diagram({ k, state }: { k: Key; state: string }) { const host = React.useRef(null); @@ -88,7 +112,7 @@ const W = [1440, 390]; export const ROUND_66: Round = { id: "66", title: "Diagrams, batch B: the viewer, frames and activations, nested groups, link cards, two-line labels, spatial keys, text art, automatic layout, right to left and export (DECISIONS 306 and 310)", - summary: "The first half of batch B. The viewer (part 9, the owner's addition) opens any figure's drawn layout in a dialog to zoom and pan; the sequence gains activation bars and opt, loop and alt frames; groups nest two deep; a card may be a link; an edge label may hold its author's break; the arrow keys move by the cards' columns and rows. Also: a trace on touch, an entrance on a first visit, flow on a dashed line, marks on steps and participants, and print. Not built: cardinality and far keys, and section 4's calls 2 and 3.", + summary: "Batch B, whole. The viewer (part 9, the owner's addition) opens any figure's drawn layout in a dialog to zoom and pan; the sequence gains activation bars and opt, loop and alt frames, and a text-art form; groups nest two deep; a card may be a link; an edge label may hold its author's break; the arrow keys move by the cards' columns and rows; a schema states how many and draws keys two columns away; automatic layout places a figure for you. Also: a trace on touch, an entrance on a first visit, flow on a dashed line, marks on steps and participants, right to left, export and print, and section 4's three calls. Fixed after both reviews and the spacing sweep (DECISIONS 326).", reviewed: false, steps: [ { @@ -101,7 +125,7 @@ export const ROUND_66: Round = { "Two deviations, for the owner: \"Expand\" is words only (Phosphor's ArrowsOutSimple cost every still figure 2.2 KB in six weights, and the core set draws no expand glyph), and the dialog is the form dialog's box on a native modal , as the HTML skill's is (Base UI's dialog in the viewer's chunk widened the Base UI chunk every component shares).", "Under 100% the words are under 12px: an overview, with no size or contrast claim. Nothing moves in the viewer but a trace.", ], - tryIt: ["Press Expand, then + and - (or Ctrl and the wheel, or pinch): the point under the pointer holds still. Drag to pan. 0 is Fit. Esc closes and focus returns to Expand.", "On a phone: two fingers zoom about their midpoint, one finger pans."], + tryIt: ["Press Expand, then + and - (or Ctrl and the wheel, or pinch): the point under the pointer holds still. Drag to pan. 0 is Fit. Esc closes and focus returns to Expand.", "On a phone: two fingers zoom about their midpoint, one finger pans.", "These shots open the viewer by script, so the stage shows its keyboard focus ring (2px, drawn inside at −2). A mouse click or a tap opens it with no ring; the keyboard shows the ring, as decided."], states: ["viewer", "viewer-200"], widths: W, scales: [2], @@ -214,5 +238,33 @@ export const ROUND_66: Round = { height: 1200, demo: ({ state }) => , }, + { + id: "data-flow", + name: "Data flow: a step's mark, a dashed flow, and several end lines into one card", + intro: "The CIMIP data flow with two more lines. The sealed segment, in the S3 lane, carries S3's mark. The batch line is dashed and flows: its own dashes march. Stacked, two cards are each entered by two end lines, which nest.", + decisions: [ + ...COMMON, + "A step's mark (1.6) is 16px in its top end corner; the lane's label counts as the step's words, so \"S3\" says what the mark stands for.", + "A dashed flow (1.5): one period every 625ms, the dashes where the key draws them whenever they rest.", + "Several end lines into one card (1.3): the outermost lane's line turns lowest and enters nearest the end edge; each further in turns space-5 higher and enters space-3 further in; their labels sit space-2-5 clear of the innermost entry, each on its own turn's height.", + ], + tryIt: ["Narrow to 390: the two cards entered by two end lines show the nesting and the labels' seats."], + widths: W, + scales: [2], + height: 1700, + touch: true, + demo: () => , + }, + { + id: "calls", + name: "Section 4's calls 2 and 3: a one-column schema's lanes, and a card grown to hold its ports", + intro: "A one-column schema whose two turn-backs run beside each other takes two lanes in its end padding. A card whose side holds a straight line and two others grows to 48, so each port is on the flat part and 8 from the next, at every width.", + decisions: [...COMMON, "Call 2: lanes space-3 apart, nested, the padding space-5 then space-5 plus space-3. Call 3: the card is never shorter than its ports need, so a side never stacks the figure."], + tryIt: ["Narrow the window from 1440: the coordinator keeps its 48 while its name wraps and unwraps."], + widths: W, + scales: [2], + height: 900, + demo: () => <>, + }, ], }; From 17c865ab83dd599342414d0f3da0e3ea7f71b1ab Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:30:55 -0600 Subject: [PATCH 47/62] A cycle of groups is handed to elk as groups of the root, so placing it answers; elkjs's class is described without its name Found by a node-only check of Neon's P2: with the chain fixed, elk itself threw on a hierarchy that held itself. The skill's built viewer part follows its source (the placed model for the key hint). Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/diagram-place.mjs | 10 +++++++++- .agent/skills/basalt-html/parts/diagram-zoom.js | 2 +- packages/react/src/diagram-elk.ts | 2 +- packages/react/src/diagram-layout-graph.ts | 5 ++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram-place.mjs b/.agent/skills/basalt-html/parts/diagram-place.mjs index 39c2dd03..392458d8 100644 --- a/.agent/skills/basalt-html/parts/diagram-place.mjs +++ b/.agent/skills/basalt-html/parts/diagram-place.mjs @@ -77,9 +77,17 @@ function graphOf(cards, lines, groups, direction) { for (const g of groups) kids.set(g.id, []); for (const c of cards) (kids.get(c.group ?? "") ?? kids.get("")).push({ id: c.id, width: W, height: H }); const children = [...kids.get("")]; + const cycles = (g) => { + const seen = /* @__PURE__ */ new Set([g.id]); + for (let p = g.parent; p; p = groups.find((x) => x.id === p)?.parent) { + if (seen.has(p)) return true; + seen.add(p); + } + return false; + }; for (const g of groups) { const box = { id: `group:${g.id}`, children: kids.get(g.id), layoutOptions: { "elk.padding": "[top=32,left=16,bottom=16,right=16]" } }; - (g.parent && kids.has(g.parent) ? kids.get(g.parent) : children).push(box); + (g.parent && kids.has(g.parent) && !cycles(g) ? kids.get(g.parent) : children).push(box); } return { id: "root", layoutOptions: options(direction), children, edges: lines.map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to], ...e.main ? { layoutOptions: { "elk.layered.priority.straightness": STRAIGHT } } : {} })) }; } diff --git a/.agent/skills/basalt-html/parts/diagram-zoom.js b/.agent/skills/basalt-html/parts/diagram-zoom.js index 5cf5a444..ed356211 100644 --- a/.agent/skills/basalt-html/parts/diagram-zoom.js +++ b/.agent/skills/basalt-html/parts/diagram-zoom.js @@ -1 +1 @@ -(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(s){return[...s.filter(g=>g.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,it=100,Q=25,U=5e-4;function at(s){const{stage:e,sizer:g,layer:m,status:k}=s;let f=0,M=0,i=1,r=1,c=!1,d=!1,h=null,y="",z=0;const T=()=>Number.parseFloat(getComputedStyle(g).paddingTop)||0,A=()=>Math.min(r,1),q=t=>Math.min(j,Math.max(A(),t));function o(){if(!f||!M)return 1;const t=T(),n=e.clientWidth-2*t,x=e.clientHeight-2*t;if(n<=0||x<=0)return Math.min(1,J);const H=Math.min(n/f,x/M);return Math.min(J,Math.floor(H*100+1e-6)/100)}function l(){const t=A();return{zoom:i,level:Math.round(i*100),fit:r,min:t,max:j,atMin:i<=t+U,atMax:i>=j-U,atFit:Math.abs(i-r)e.clientWidth-2*T()+.5||M*i>e.clientHeight-2*T()+.5)}function S(){clearTimeout(z);const t=`Zoom ${Math.round(i*100)}%`;z=window.setTimeout(()=>{t!==y&&(y=t,k.textContent=t)},s.rest)}function v(){g.style.width=`${f*i}px`,g.style.height=`${M*i}px`,m.style.transform=`scale(${i})`}function K(t){const n=m.getBoundingClientRect();return{x:(t.x-n.left)/i,y:(t.y-n.top)/i}}function E(t,n){const x=m.getBoundingClientRect();e.scrollLeft+=x.left+t.x*i-n.x,e.scrollTop+=x.top+t.y*i-n.y}const p=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function W(t,n=p(),x){if(d)return;const H=q(t);if(Math.abs(H-i)<1e-6){w();return}const st=x??K(n);i=H,v(),E(st,n),w(),S()}function L(t){c=!0;const n=i*100,x=t?G.find(H=>H>n+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,a=()=>{const[t,n]=[...u.values()];return{x:(t.x+n.x)/2,y:(t.y+n.y)/2}},b=()=>{const[t,n]=[...u.values()];return Math.hypot(t.x-n.x,t.y-n.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(u.set(t.pointerId,{x:t.clientX,y:t.clientY}),u.size===1&&(F={x:t.clientX,y:t.clientY},C=F,O=!1,$=!1),u.size===2&&t.pointerType==="touch")){const n=a();B={d0:b()||1,z0:i,c:K(n)},$=!0,O=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!u.has(t.pointerId)||d)return;if(u.set(t.pointerId,{x:t.clientX,y:t.clientY}),B&&u.size>=2){c=!0;const x=q(B.z0*(b()/B.d0)),H=a();Math.abs(x-i)>1e-6&&(i=x,v(),w(),S()),E(B.c,H);return}if(u.size!==1||!F||!C)return;const n={x:t.clientX,y:t.clientY};if(!O){if(Math.hypot(n.x-F.x,n.y-F.y)<=V())return;O=!0,$=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=n.x-C.x,e.scrollTop-=n.y-C.y,C=n,t.preventDefault()}function Z(t){if(u.has(t.pointerId)){if(u.delete(t.pointerId),u.size<2&&(B=null),u.size===1){const[n]=[...u.values()];C=n,F=n,O=!0;return}u.size===0&&(O=!1,e.removeAttribute("data-dragging"),F=C=null)}}function P(t){$&&($=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!f||!M)return;const t=c?K(p()):null;r=o(),c?(i=q(i),v(),t&&E(t,p())):(i=r,v()),w()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:I,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:_,state:l,list(t){t!==d&&(t?(h={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),v(),h&&(e.scrollLeft=h.left,e.scrollTop=h.top),h=null),w())},travelled:()=>$,destroy(){clearTimeout(z),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function rt(s,e,g){const m=s.getBoundingClientRect(),k=e.getBoundingClientRect(),f=m.left+g,M=m.left+s.clientWidth-g,i=m.top+g,r=m.top+s.clientHeight-g;k.leftM&&(s.scrollLeft+=Math.min(k.right-M,k.left-f)),k.topr&&(s.scrollTop+=Math.min(k.bottom-r,k.top-i))}function nt(s,e){s.memo.art=Math.ceil(e),s.layer.style.width=`${s.memo.art}px`}function ot(s,e,g,m,k,f,M,i){const{layer:r,memo:c,measureFigure:d}=i;if(c.model!==e&&(c.model=e,c.least=void 0,c.art=void 0),e.text){r.style.width=`${c.art??Math.min(i.avail,i.row)}px`;const w=r.style.transform;r.style.transform="none";const S=d(s,e,g,m,k,f,M);return r.style.transform=w,S}const h=w=>{r.style.width=`${Math.max(c.least||w,Math.min(i.avail,i.row))}px`};r.style.width||(r.style.width=`${Math.min(i.avail,i.row)}px`);const y=r.style.transform;r.style.transform="none";const z=r.offsetWidth?r.getBoundingClientRect().width/r.offsetWidth:1,T=Math.abs(z-1)>1e-4?` scale(${1/z})`:"";r.style.transform=T||"none";const A=(s.querySelector(`.${g}-drawing`)??r).getBoundingClientRect(),q=A.left-Math.round(A.left),o=A.top-Math.round(A.top);(q||o)&&(r.style.transform=`translate(${-q/z}px, ${-o/z}px)${T}`);let l=d(s,e,g,m,k,f,c.least===void 0?void 0:M,h);if(l.dyn.layout==="stacked"&&c.least===void 0&&l.least!==void 0){const w=l.dyn,S=p=>{r.style.width=`${p}px`;const W=d(s,e,g,m,w,f);return W.dyn.layout==="drawn"?d(s,e,g,m,W.dyn,f):W},v=Math.max(l.least,Math.min(i.avail,i.row)),K=Math.max(i.row,v)*1.5;let E;for(let p=v+16;p<=K&&E===void 0;p+=16)S(p).dyn.layout==="drawn"&&(E=p);if(E!==void 0){for(let p=E-15;pi.contain&&(r.style.width=`${i.contain}px`,l=d(s,e,g,m,l.dyn,f,M)),r.style.transform=y,l}(function(s){"use strict";var e=s._,g=0;function m(i){return e.diagramKit.escapeHtml(String(i??""))}function k(i){return''+m(i)+""}function f(i,r){return parseFloat(getComputedStyle(i).getPropertyValue(r))||0}function M(i,r,c,d){var h=e.diagramKit,y=Object.assign({},r,{motion:"still"}),z=h.buildModel(y),T="dgv"+ ++g,A=h.figureKey("diagram",z),q=et(h.hintEntries(z,!0)).map(function(a){return""+a.keys.map(k).join(" ")+" "+m(a.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",T+"-summary"),o.innerHTML='

'+m(z.title)+"

"+(r.source?'

'+m(r.source)+"

":"")+'

'+m(r.summary)+'

'+(A?'
'+h.toHtml(A)+"
":"")+'
',document.body.appendChild(o);var l=o.querySelector(".diagram-stage"),w=o.querySelector(".diagram-sizer"),S=o.querySelector(".diagram-layer"),v=S.firstChild,K=o.querySelector('[role="status"]'),E=o.querySelector(".diagram-level > span"),p=o.querySelector(".diagram-viewer-key"),W=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},_=null,I=!1,R=!1,D=function(a,b){b?a.setAttribute("aria-disabled","true"):a.removeAttribute("aria-disabled")},u=at({stage:l,sizer:w,layer:S,status:K,rest:f(l,"--_rest")||300,onChange:function(a){E.textContent=a.level+"%",D(L.out,a.listOpen||a.atMin),D(L.in,a.listOpen||a.atMax),D(L.fit,a.listOpen||a.atFit)}}),F={},C={layer:S,avail:0,row:1104,contain:480,memo:F,measureFigure:h.measureFigure,keys:tt,room:function(){var a=parseFloat(getComputedStyle(w).paddingTop)||0;return{w:l.clientWidth-2*a,h:l.clientHeight-2*a}},measure:function(a,b,Y,N,Z,P,X){return ot(a,b,Y,N,Z,P,X,C)},textWidth:function(a){nt(C,a)},onMeasured:function(a,b){l.setAttribute("data-layout",a.dyn.layout||""),p&&(p.setAttribute("data-layout",a.dyn.layout||""),p.toggleAttribute("data-bare",!!a.dyn.bare)),R=!!a.dyn.bare,W.hidden=R,$(I||R),u.size(b.offsetWidth,b.offsetHeight)}};function O(){C.avail=Math.max(0,Math.floor(l.clientWidth-2*(parseFloat(getComputedStyle(w).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function $(a){a&&!_&&(_=document.createElement("div"),_.className="diagram-list diagram-viewer-list",_.innerHTML=h.figureList("diagram",z).map(function(b){return h.toHtml(b)}).join(""),l.appendChild(_)),a&&u.list(!0),_&&(_.hidden=!a),w.hidden=a,a||u.list(!1)}W.addEventListener("click",function(){I=!I,W.setAttribute("aria-expanded",String(I)),W.firstElementChild.textContent=I?"Hide the list":"View as list",$(I||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||u.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||u.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||u.fit()}),o.addEventListener("click",function(a){var b=a.target.closest&&a.target.closest("a.diagram-node[href]");!b||!o.contains(b)||a.defaultPrevented||a.button!==0||a.metaKey||a.ctrlKey||a.shiftKey||a.altKey||b.target&&b.target!=="_self"||o.open&&o.close()}),l.addEventListener("focusin",function(a){var b=a.target.closest&&a.target.closest(".diagram-node");b&&l.contains(b)&&rt(l,b,f(l,"--_clear")||16)}),r.export===!0&&typeof e.diagramExport=="function"&&e.diagramExport(o.querySelector(".diagram-viewer-end"),v),s.openDialog(o,d),O(),h.draw(v,y,!1,C),setTimeout(function(){l.focus({preventScroll:!0})},0);var B=l.clientWidth,V=new ResizeObserver(function(){Math.abs(l.clientWidth-B)<.5||(B=l.clientWidth,O(),v.__diagram&&v.__diagram.layout())});V.observe(l),o.addEventListener("transitionend",function(a){a.target===o&&a.propertyName==="transform"&&o.open&&v.__diagram&&v.__diagram.layout()}),i.setAttribute("data-viewing",""),c.animated&&c.settle(),o.addEventListener("close",function(){V.disconnect(),u.destroy(),v.__diagram&&v.__diagram.stop(),i.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},f(o,"--_dur")*.75||300)})}e.diagramZoom=function(i,r,c){var d=i.querySelector(":scope > .diagram-foot");if(!d)return null;var h=d.querySelector(".diagram-expand");h&&h.remove();var y=document.createElement("button");y.type="button",y.className="btn diagram-expand",y.setAttribute("data-variant","secondary"),y.setAttribute("data-size","sm"),y.setAttribute("aria-haspopup","dialog"),y.innerHTML="Expand";var z=d.querySelector(".diagram-toggle");z&&z.nextSibling?d.insertBefore(y,z.nextSibling):d.appendChild(y);var T=function(){M(i,r,c,y)};return y.addEventListener("click",T),{destroy:function(){y.removeEventListener("click",T),y.remove()}}}})(window.Basalt)})(); +(()=>{var tt="Plus and minus zoom, zero fits the drawing, Escape closes.";function et(s){return[...s.filter(h=>h.keys[0]!=="Esc"),{keys:["+","−"],words:"zoom"},{keys:["0"],words:"fit"},{keys:["Esc"],words:"close"}]}var G=[25,33,50,67,75,100,125,150,200,300,400],j=4,J=2,at=100,Q=25,U=5e-4;function it(s){const{stage:e,sizer:h,layer:p,status:k}=s;let m=0,M=0,a=1,r=1,c=!1,d=!1,y=null,u="",z=0;const T=()=>Number.parseFloat(getComputedStyle(h).paddingTop)||0,A=()=>Math.min(r,1),q=t=>Math.min(j,Math.max(A(),t));function o(){if(!m||!M)return 1;const t=T(),n=e.clientWidth-2*t,x=e.clientHeight-2*t;if(n<=0||x<=0)return Math.min(1,J);const H=Math.min(n/m,x/M);return Math.min(J,Math.floor(H*100+1e-6)/100)}function l(){const t=A();return{zoom:a,level:Math.round(a*100),fit:r,min:t,max:j,atMin:a<=t+U,atMax:a>=j-U,atFit:Math.abs(a-r)e.clientWidth-2*T()+.5||M*a>e.clientHeight-2*T()+.5)}function S(){clearTimeout(z);const t=`Zoom ${Math.round(a*100)}%`;z=window.setTimeout(()=>{t!==u&&(u=t,k.textContent=t)},s.rest)}function v(){h.style.width=`${m*a}px`,h.style.height=`${M*a}px`,p.style.transform=`scale(${a})`}function K(t){const n=p.getBoundingClientRect();return{x:(t.x-n.left)/a,y:(t.y-n.top)/a}}function E(t,n){const x=p.getBoundingClientRect();e.scrollLeft+=x.left+t.x*a-n.x,e.scrollTop+=x.top+t.y*a-n.y}const g=()=>{const t=e.getBoundingClientRect();return{x:t.left+e.clientWidth/2,y:t.top+e.clientHeight/2}};function W(t,n=g(),x){if(d)return;const H=q(t);if(Math.abs(H-a)<1e-6){w();return}const st=x??K(n);a=H,v(),E(st,n),w(),S()}function L(t){c=!0;const n=a*100,x=t?G.find(H=>H>n+.5):[...G].reverse().find(H=>HNumber.parseFloat(getComputedStyle(e).getPropertyValue("--_travel"))||4,i=()=>{const[t,n]=[...f.values()];return{x:(t.x+n.x)/2,y:(t.y+n.y)/2}},b=()=>{const[t,n]=[...f.values()];return Math.hypot(t.x-n.x,t.y-n.y)};function Y(t){if(!d&&!(t.pointerType==="mouse"&&t.button!==0)&&(f.set(t.pointerId,{x:t.clientX,y:t.clientY}),f.size===1&&(F={x:t.clientX,y:t.clientY},C=F,O=!1,$=!1),f.size===2&&t.pointerType==="touch")){const n=i();B={d0:b()||1,z0:a,c:K(n)},$=!0,O=!1;try{e.setPointerCapture(t.pointerId)}catch{}}}function N(t){if(!f.has(t.pointerId)||d)return;if(f.set(t.pointerId,{x:t.clientX,y:t.clientY}),B&&f.size>=2){c=!0;const x=q(B.z0*(b()/B.d0)),H=i();Math.abs(x-a)>1e-6&&(a=x,v(),w(),S()),E(B.c,H);return}if(f.size!==1||!F||!C)return;const n={x:t.clientX,y:t.clientY};if(!O){if(Math.hypot(n.x-F.x,n.y-F.y)<=V())return;O=!0,$=!0,e.setAttribute("data-dragging","");try{e.setPointerCapture(t.pointerId)}catch{}}e.scrollLeft-=n.x-C.x,e.scrollTop-=n.y-C.y,C=n,t.preventDefault()}function Z(t){if(f.has(t.pointerId)){if(f.delete(t.pointerId),f.size<2&&(B=null),f.size===1){const[n]=[...f.values()];C=n,F=n,O=!0;return}f.size===0&&(O=!1,e.removeAttribute("data-dragging"),F=C=null)}}function P(t){$&&($=!1,t.preventDefault(),t.stopPropagation())}const X=new ResizeObserver(()=>{if(!m||!M)return;const t=c?K(g()):null;r=o(),c?(a=q(a),v(),t&&E(t,g())):(a=r,v()),w()});return X.observe(e),e.addEventListener("wheel",R,{passive:!1}),e.addEventListener("keydown",D),e.addEventListener("pointerdown",Y),e.addEventListener("pointermove",N),e.addEventListener("pointerup",Z),e.addEventListener("pointercancel",Z),e.addEventListener("click",P,!0),{size:I,zoomIn:()=>L(!0),zoomOut:()=>L(!1),fit:_,state:l,list(t){t!==d&&(t?(y={left:e.scrollLeft,top:e.scrollTop},d=!0,e.setAttribute("data-list",""),e.scrollTop=0):(d=!1,e.removeAttribute("data-list"),v(),y&&(e.scrollLeft=y.left,e.scrollTop=y.top),y=null),w())},travelled:()=>$,destroy(){clearTimeout(z),X.disconnect(),e.removeEventListener("wheel",R),e.removeEventListener("keydown",D),e.removeEventListener("pointerdown",Y),e.removeEventListener("pointermove",N),e.removeEventListener("pointerup",Z),e.removeEventListener("pointercancel",Z),e.removeEventListener("click",P,!0)}}}function rt(s,e,h){const p=s.getBoundingClientRect(),k=e.getBoundingClientRect(),m=p.left+h,M=p.left+s.clientWidth-h,a=p.top+h,r=p.top+s.clientHeight-h;k.leftM&&(s.scrollLeft+=Math.min(k.right-M,k.left-m)),k.topr&&(s.scrollTop+=Math.min(k.bottom-r,k.top-a))}function nt(s,e){s.memo.art=Math.ceil(e),s.layer.style.width=`${s.memo.art}px`}function ot(s,e,h,p,k,m,M,a){const{layer:r,memo:c,measureFigure:d}=a;if(c.model!==e&&(c.model=e,c.least=void 0,c.art=void 0),e.text){r.style.width=`${c.art??Math.min(a.avail,a.row)}px`;const w=r.style.transform;r.style.transform="none";const S=d(s,e,h,p,k,m,M);return r.style.transform=w,S}const y=w=>{r.style.width=`${Math.max(c.least||w,Math.min(a.avail,a.row))}px`};r.style.width||(r.style.width=`${Math.min(a.avail,a.row)}px`);const u=r.style.transform;r.style.transform="none";const z=r.offsetWidth?r.getBoundingClientRect().width/r.offsetWidth:1,T=Math.abs(z-1)>1e-4?` scale(${1/z})`:"";r.style.transform=T||"none";const A=(s.querySelector(`.${h}-drawing`)??r).getBoundingClientRect(),q=A.left-Math.round(A.left),o=A.top-Math.round(A.top);(q||o)&&(r.style.transform=`translate(${-q/z}px, ${-o/z}px)${T}`);let l=d(s,e,h,p,k,m,c.least===void 0?void 0:M,y);if(l.dyn.layout==="stacked"&&c.least===void 0&&l.least!==void 0){const w=l.dyn,S=g=>{r.style.width=`${g}px`;const W=d(s,e,h,p,w,m);return W.dyn.layout==="drawn"?d(s,e,h,p,W.dyn,m):W},v=Math.max(l.least,Math.min(a.avail,a.row)),K=Math.max(a.row,v)*1.5;let E;for(let g=v+16;g<=K&&E===void 0;g+=16)S(g).dyn.layout==="drawn"&&(E=g);if(E!==void 0){for(let g=E-15;ga.contain&&(r.style.width=`${a.contain}px`,l=d(s,e,h,p,l.dyn,m,M)),r.style.transform=u,l}(function(s){"use strict";var e=s._,h=0;function p(a){return e.diagramKit.escapeHtml(String(a??""))}function k(a){return''+p(a)+""}function m(a,r){return parseFloat(getComputedStyle(a).getPropertyValue(r))||0}function M(a,r,c,d){var y=e.diagramKit,u=Object.assign({},r,{motion:"still"}),z=y.buildModel(u,{placement:Array.isArray(u.placement)?u.placement[0]:u.placement}),T="dgv"+ ++h,A=y.figureKey("diagram",z),q=et(y.hintEntries(z,!0)).map(function(i){return""+i.keys.map(k).join(" ")+" "+p(i.words)+""}).join(""),o=document.createElement("dialog");o.className="panel float modal dialog diagram-viewer",o.setAttribute("data-form",""),o.setAttribute("aria-describedby",T+"-summary"),o.innerHTML='

'+p(z.title)+"

"+(r.source?'

'+p(r.source)+"

":"")+'

'+p(r.summary)+'

'+(A?'
'+y.toHtml(A)+"
":"")+'
',document.body.appendChild(o);var l=o.querySelector(".diagram-stage"),w=o.querySelector(".diagram-sizer"),S=o.querySelector(".diagram-layer"),v=S.firstChild,K=o.querySelector('[role="status"]'),E=o.querySelector(".diagram-level > span"),g=o.querySelector(".diagram-viewer-key"),W=o.querySelector(".diagram-toggle"),L={out:o.querySelector('[data-zoom="out"]'),in:o.querySelector('[data-zoom="in"]'),fit:o.querySelector('[data-zoom="fit"]')},_=null,I=!1,R=!1,D=function(i,b){b?i.setAttribute("aria-disabled","true"):i.removeAttribute("aria-disabled")},f=it({stage:l,sizer:w,layer:S,status:K,rest:m(l,"--_rest")||300,onChange:function(i){E.textContent=i.level+"%",D(L.out,i.listOpen||i.atMin),D(L.in,i.listOpen||i.atMax),D(L.fit,i.listOpen||i.atFit)}}),F={},C={layer:S,avail:0,row:1104,contain:480,memo:F,measureFigure:y.measureFigure,keys:tt,room:function(){var i=parseFloat(getComputedStyle(w).paddingTop)||0;return{w:l.clientWidth-2*i,h:l.clientHeight-2*i}},measure:function(i,b,Y,N,Z,P,X){return ot(i,b,Y,N,Z,P,X,C)},textWidth:function(i){nt(C,i)},onMeasured:function(i,b){l.setAttribute("data-layout",i.dyn.layout||""),g&&(g.setAttribute("data-layout",i.dyn.layout||""),g.toggleAttribute("data-bare",!!i.dyn.bare)),R=!!i.dyn.bare,W.hidden=R,$(I||R),f.size(b.offsetWidth,b.offsetHeight)}};function O(){C.avail=Math.max(0,Math.floor(l.clientWidth-2*(parseFloat(getComputedStyle(w).paddingLeft)||0))),C.row=o.querySelector('[data-probe="row"]').offsetWidth||1104,C.contain=o.querySelector('[data-probe="contain"]').offsetWidth||480}function $(i){i&&!_&&(_=document.createElement("div"),_.className="diagram-list diagram-viewer-list",_.innerHTML=y.figureList("diagram",z).map(function(b){return y.toHtml(b)}).join(""),l.appendChild(_)),i&&f.list(!0),_&&(_.hidden=!i),w.hidden=i,i||f.list(!1)}W.addEventListener("click",function(){I=!I,W.setAttribute("aria-expanded",String(I)),W.firstElementChild.textContent=I?"Hide the list":"View as list",$(I||R)}),L.out.addEventListener("click",function(){L.out.hasAttribute("aria-disabled")||f.zoomOut()}),L.in.addEventListener("click",function(){L.in.hasAttribute("aria-disabled")||f.zoomIn()}),L.fit.addEventListener("click",function(){L.fit.hasAttribute("aria-disabled")||f.fit()}),o.addEventListener("click",function(i){var b=i.target.closest&&i.target.closest("a.diagram-node[href]");!b||!o.contains(b)||i.defaultPrevented||i.button!==0||i.metaKey||i.ctrlKey||i.shiftKey||i.altKey||b.target&&b.target!=="_self"||o.open&&o.close()}),l.addEventListener("focusin",function(i){var b=i.target.closest&&i.target.closest(".diagram-node");b&&l.contains(b)&&rt(l,b,m(l,"--_clear")||16)}),r.export===!0&&typeof e.diagramExport=="function"&&e.diagramExport(o.querySelector(".diagram-viewer-end"),v),s.openDialog(o,d),O(),y.draw(v,u,!1,C),setTimeout(function(){l.focus({preventScroll:!0})},0);var B=l.clientWidth,V=new ResizeObserver(function(){Math.abs(l.clientWidth-B)<.5||(B=l.clientWidth,O(),v.__diagram&&v.__diagram.layout())});V.observe(l),o.addEventListener("transitionend",function(i){i.target===o&&i.propertyName==="transform"&&o.open&&v.__diagram&&v.__diagram.layout()}),a.setAttribute("data-viewing",""),c.animated&&c.settle(),o.addEventListener("close",function(){V.disconnect(),f.destroy(),v.__diagram&&v.__diagram.stop(),a.removeAttribute("data-viewing"),setTimeout(function(){o.remove()},m(o,"--_dur")*.75||300)})}e.diagramZoom=function(a,r,c){var d=a.querySelector(":scope > .diagram-foot");if(!d)return null;var y=d.querySelector(".diagram-expand");y&&y.remove();var u=document.createElement("button");u.type="button",u.className="btn diagram-expand",u.setAttribute("data-variant","secondary"),u.setAttribute("data-size","sm"),u.setAttribute("aria-haspopup","dialog"),u.innerHTML="Expand";var z=d.querySelector(".diagram-toggle");z&&z.nextSibling?d.insertBefore(u,z.nextSibling):d.appendChild(u);var T=function(){M(a,r,c,u)};return u.addEventListener("click",T),{destroy:function(){u.removeEventListener("click",T),u.remove()}}}})(window.Basalt)})(); diff --git a/packages/react/src/diagram-elk.ts b/packages/react/src/diagram-elk.ts index ae346ced..b0f1ea11 100644 --- a/packages/react/src/diagram-elk.ts +++ b/packages/react/src/diagram-elk.ts @@ -3,6 +3,6 @@ // chunk. Only diagram-layout imports it, on demand. Its type here is Basalt's own: no elkjs type is in any declaration (AGENTS.md). import ELK from "elkjs/lib/elk.bundled.js"; -/** elkjs's layout, as diagram-layout calls it. */ +/** The layout class, as diagram-layout calls it. */ const Elk = ELK as unknown as new () => { layout: (graph: object) => Promise }; export default Elk; diff --git a/packages/react/src/diagram-layout-graph.ts b/packages/react/src/diagram-layout-graph.ts index 0541430f..97a34df4 100644 --- a/packages/react/src/diagram-layout-graph.ts +++ b/packages/react/src/diagram-layout-graph.ts @@ -63,9 +63,12 @@ export function graphOf(cards: Card[], lines: Line[], groups: DiagramGroup[], di for (const g of groups) kids.set(g.id, []); for (const c of cards) (kids.get(c.group ?? "") ?? kids.get("")!).push({ id: c.id, width: W, height: H }); const children = [...kids.get("")!]; + // A group goes into its parent unless its chain of parents comes back to it (a cycle, the engine's development error): then it is a group of the root, + // so elk is never handed a hierarchy that holds itself (Neon's P2 of the code review). + const cycles = (g: DiagramGroup) => { const seen = new Set([g.id]); for (let p = g.parent; p; p = groups.find((x) => x.id === p)?.parent) { if (seen.has(p)) return true; seen.add(p); } return false; }; for (const g of groups) { const box: ElkNode = { id: `group:${g.id}`, children: kids.get(g.id), layoutOptions: { "elk.padding": "[top=32,left=16,bottom=16,right=16]" } }; - (g.parent && kids.has(g.parent) ? kids.get(g.parent)! : children).push(box); + (g.parent && kids.has(g.parent) && !cycles(g) ? kids.get(g.parent)! : children).push(box); } return { id: "root", layoutOptions: options(direction), children, edges: lines.map((e, k) => ({ id: `e${k}`, sources: [e.from], targets: [e.to], ...(e.main ? { layoutOptions: { "elk.layered.priority.straightness": STRAIGHT } } : {}) })) }; } From dcba5153975d5617044cda78c87f26efd890441b Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:30:57 -0600 Subject: [PATCH 48/62] Sizes and the skill's caps after the fix round (DECISIONS 318, 326) Recorded sizes: each still diagram 99,589 to 99,677 bytes, +1.7% on batch B's last record (the reviews' fixes in the shared engine, the figure and the stylesheet); the whole package up front 902,562 bytes (+0.2%); styles.css 413,315 (+0.9%). The skill's caps at their measured sizes, the reason in modules.json's $comment: diagram 137,700 to 144,100 (measured 144,056), diagram-motion 28,450 to 30,450 (30,418), diagram-zoom 17,000 to 17,600 (17,575), diagram-export 7,850 to 10,450 (10,402); diagram-text stays (5,177 of 5,450). Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/parts/manifest.json | 10 +++++----- packages/react/test/export-sizes.json | 18 +++++++++--------- tools/html-skill/src/modules.json | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index 4137941a..510d6fbe 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -1,5 +1,5 @@ { - "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused).", + "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused). Raised in diagram batch B's fix round (DECISIONS 318, the owner's diagram raise; and 326's sweep), each to its measured size: diagram 137700 to 144100 (the two reviews' fixes in the shared engine: right to left frames and self-calls, the corridors' and lanes' development words, the unusable-placement check, the transcript's hanging lines, the text art's frame widening, the frame-side fit check, the sequence's layers, the stacked group's turn room), diagram-motion 28450 to 30450 (the text sequence's build by ink and its colour-only run, moved into the motion module), diagram-zoom 17000 to 17600 (a linked card closes the viewer; the text art's own width; a placed model for the key hint), diagram-export 7850 to 10450 (an export at rest: sized drawing SVGs, no reveal masks, the pseudo-element rules, the lines under the cards, a viewer's figure read at 100% with its head and key, the rim's lit top).", "budgets": { "skillMd": 12950, "core": 35400 @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 137700, + "budget": 144100, "usage": 4600, "builds": [ "kbd" @@ -804,7 +804,7 @@ "loops", "toggle" ], - "budget": 28450, + "budget": 30450, "usage": 1450, "builds": [ "loops", @@ -835,7 +835,7 @@ "dialog-form", "sheet" ], - "budget": 17000, + "budget": 17600, "usage": 900, "builds": [ "dialog", @@ -853,7 +853,7 @@ "requires": [ "diagram" ], - "budget": 7850, + "budget": 10450, "usage": 700 }, "diagram-text": { diff --git a/packages/react/test/export-sizes.json b/packages/react/test/export-sizes.json index b213d04d..8fc7c27a 100644 --- a/packages/react/test/export-sizes.json +++ b/packages/react/test/export-sizes.json @@ -18,7 +18,7 @@ "AppHeader": 1285, "AppShell": 103887, "AppTile": 1112, - "ArchitectureDiagram": 98046, + "ArchitectureDiagram": 99677, "ArrowDownGlyph": 2868, "ArrowLeftGlyph": 2869, "ArrowRightGlyph": 2859, @@ -70,7 +70,7 @@ "CopyGlyph": 2884, "Countdown": 3016, "CoverageStrip": 1570, - "DataFlowDiagram": 97991, + "DataFlowDiagram": 99620, "DateAge": 2527, "DescriptionColumns": 216, "DescriptionItem": 593, @@ -105,7 +105,7 @@ "Fieldset": 6390, "FilterResult": 698, "FilterToolbar": 774, - "FlowchartDiagram": 98012, + "FlowchartDiagram": 99641, "Form": 8730, "FormGrid": 438, "FormGridItem": 628, @@ -224,7 +224,7 @@ "RunsGlyph": 3128, "STATUS_MESSAGE_MS": 26, "SandboxesGlyph": 2963, - "SchemaDiagram": 97960, + "SchemaDiagram": 99589, "SearchDialog": 88277, "SearchField": 18301, "SearchGlyph": 3181, @@ -243,7 +243,7 @@ "SelectableList": 821, "SelectionBar": 25913, "Separator": 4531, - "SequenceDiagram": 97988, + "SequenceDiagram": 99617, "SettingsGlyph": 3100, "ShareBar": 1411, "Sheet": 70793, @@ -412,11 +412,11 @@ "useWaitMark": 303 }, "package": { - "bytes": 900954, - "gzip": 300417 + "bytes": 902562, + "gzip": 300934 }, "styles": { - "bytes": 409760, - "gzip": 53141 + "bytes": 413315, + "gzip": 53590 } } diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index 4137941a..510d6fbe 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -1,5 +1,5 @@ { - "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused).", + "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused). Raised in diagram batch B's fix round (DECISIONS 318, the owner's diagram raise; and 326's sweep), each to its measured size: diagram 137700 to 144100 (the two reviews' fixes in the shared engine: right to left frames and self-calls, the corridors' and lanes' development words, the unusable-placement check, the transcript's hanging lines, the text art's frame widening, the frame-side fit check, the sequence's layers, the stacked group's turn room), diagram-motion 28450 to 30450 (the text sequence's build by ink and its colour-only run, moved into the motion module), diagram-zoom 17000 to 17600 (a linked card closes the viewer; the text art's own width; a placed model for the key hint), diagram-export 7850 to 10450 (an export at rest: sized drawing SVGs, no reveal masks, the pseudo-element rules, the lines under the cards, a viewer's figure read at 100% with its head and key, the rim's lit top).", "budgets": { "skillMd": 12950, "core": 35400 @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 137700, + "budget": 144100, "usage": 4600, "builds": [ "kbd" @@ -804,7 +804,7 @@ "loops", "toggle" ], - "budget": 28450, + "budget": 30450, "usage": 1450, "builds": [ "loops", @@ -835,7 +835,7 @@ "dialog-form", "sheet" ], - "budget": 17000, + "budget": 17600, "usage": 900, "builds": [ "dialog", @@ -853,7 +853,7 @@ "requires": [ "diagram" ], - "budget": 7850, + "budget": 10450, "usage": 700 }, "diagram-text": { From d89c2470449acb23bebb973995981cf8e726c971 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:31:26 -0600 Subject: [PATCH 49/62] Tests for both reviews' findings and the sweep, and section 8's missing coverage (Fable's section 8 additions; Neon B12) Written; the browser tests are not run (the owner paused them, DECISIONS 330). Node-only: the contrast pairs pass (200 of 200). - diagram-review.test.mjs (new): the viewer's disabled controls and "Clear highlight" (no hover, press or scale, another ink), a linked card closing the viewer by a click and Enter, a text sequence's art in the viewer at 1440 by 900 and 390 by 844, the rim and the dialog inside the window right to left (Fable B1 to B4); right to left frames, else rules, a self-call's words and a Mono detail (B5); stacked else rule, no divider after a frame, the group entered by a turn (P2, P3, answer 1); 66-1 to 66-3; the transcript's lines and the key's focal glyph (B6, P4); textArt's widened frame and a last participant's self-call; the text build in view and its run; export of a flowchart, mid-entrance and mid-run (Neon B5); an unusable placement, a one-column schema's two statements, empty and cyclic placements, a way-only column right to left, 48 not 49; the frame-side fit and the sequence's layers; forced colours on a quiet run's head; the lazy parts reached only dynamically; the quiet run; the first visit; the five figures right to left. - Tautological tests replaced, each now failing when its feature breaks: the stranded card (an X of five strands one, and the arrows keep the author's order), the viewer's bare stack (a figure that is never drawn and whose stack is bare opens the list), and print's traced line (read whatever kind the first lit line is). - diagram-sequence: the text variant (stable art, closed frames, no scroll at 1440, 390 and 360, aria-hidden, glyph swatches), bars and frame errors. diagram-parts: three and four end lanes, the fifth, two entries into one card, marks read the lane label. diagram-fixes: call 1 at every whole width from 930 to 1,440, call 2's lanes and padding, call 3 at every fourth width to 1,440. diagram-layout: no declaration names elkjs or the graph's helpers, and elkjs's licence ships. contrast: batch B's seats on levels 0 to 3 and under more contrast, the text art's inks on surface-sunken, a linked card's words on its press step. The skill: an automatic figure's static markup on its placement, and the lane label in the says-check. Their node-level logic was checked by a script outside the suite (the cells against the ruling's, the text art, the placements, the development checks, the declarations, the import graph, compose): it passes. Co-Authored-By: Claude Opus 5.5 --- packages/react/test/diagram-fixes.test.mjs | 65 +++ packages/react/test/diagram-keys.test.mjs | 20 +- packages/react/test/diagram-layout.test.mjs | 16 +- packages/react/test/diagram-output.test.mjs | 6 +- packages/react/test/diagram-parts.test.mjs | 64 ++- packages/react/test/diagram-review.test.mjs | 486 ++++++++++++++++++ packages/react/test/diagram-sequence.test.mjs | 55 +- packages/react/test/diagram-viewer.test.mjs | 16 +- packages/tokens/test/contrast.test.mjs | 34 ++ tools/html-skill/test/diagrams.test.mjs | 18 + 10 files changed, 761 insertions(+), 19 deletions(-) create mode 100644 packages/react/test/diagram-review.test.mjs diff --git a/packages/react/test/diagram-fixes.test.mjs b/packages/react/test/diagram-fixes.test.mjs index c9c50151..dadb2d7e 100644 --- a/packages/react/test/diagram-fixes.test.mjs +++ b/packages/react/test/diagram-fixes.test.mjs @@ -198,3 +198,68 @@ describe("a decision no taller than it is wide (Fable's polish P4)", () => { await page.close(); }); }); + +describe("section 4's three calls (DECISIONS 306; Neon's B12 of the code review)", () => { + test("call 1: from its first drawn width the CIMIP flowchart is drawn at every whole width to 1,440, and no decision is taller than it is wide", async () => { + const { page } = await figurePage(); + await draw(page, [{ key: "flow", spec: DATA.flowchart }]); + let first = null; + const off = []; + for (let w = 930; w <= 1440; w++) { + await page.evaluate((w) => document.getElementById("root").style.setProperty("--w", `${w}px`), w); + await frames(page, 2); + const layout = await page.getAttribute("#fig-flow", "data-layout"); + if (layout === "drawn") { + first ??= w; + const tall = await page.evaluate(() => [...document.querySelectorAll("#fig-flow .basalt-diagram-node[data-shape='decision']")].some((n) => { const r = n.getBoundingClientRect(); return r.height > r.width + 0.5; })); + if (tall) off.push(`${w}: a decision taller than wide`); + } else if (first !== null) off.push(`${w}: stacked after drawing at ${first}`); + } + assert.ok(first !== null && first <= 976, `first drawn at ${first}`); + assert.deepEqual(off, []); + await page.close(); + }); + + test("call 2: a one-column schema's two overlapping turn-backs take two lanes space-3 apart, and the padding is the outermost lane plus space-1", async () => { + const { page } = await figurePage(); + const t = (name, row, refs = []) => ({ name, col: 1, row, columns: [{ name: "id", key: "PK" }, ...refs.map((r) => ({ name: `${r}_id`, key: "FK", references: `${r}.id` }))] }); + await draw(page, [{ key: "one", spec: { type: "schema", title: "One column", summary: "Keys.", legend: { plain: "A foreign key" }, tables: [t("a", 1), t("b", 2, ["c"]), t("c", 3, ["a"])] } }]); + assert.equal(await page.getAttribute("#fig-one", "data-layout"), "drawn"); + const got = await page.evaluate(() => { + const fig = document.querySelector("#fig-one"), d = fig.querySelector(".basalt-diagram-drawing").getBoundingClientRect(); + const right = Math.max(...[...fig.querySelectorAll(".basalt-diagram-node")].map((n) => n.getBoundingClientRect().right)) - d.left; + const lanes = [...fig.querySelectorAll(".basalt-diagram-svg .basalt-diagram-line")].map((p) => Math.max(...p.getAttribute("d").match(/-?[\d.]+/g).map(Number).filter((_, k) => k % 2 === 0)) - right).sort((a, b) => a - b); + return { lanes, pad: d.width - right }; + }); + assert.equal(got.lanes.length, 2); + assert.ok(Math.abs(got.lanes[0] - 16) <= 0.5 && Math.abs(got.lanes[1] - 28) <= 0.5, JSON.stringify(got)); + assert.ok(Math.abs(got.pad - 32) <= 0.5, `the padding is space-5 plus space-3 (${got.pad})`); + await page.close(); + }); + + test("call 3: a card whose side holds a straight line and two others is 48 tall at every width from its first drawn one, its ports on the flat part and 8 apart", async () => { + const { page } = await figurePage(); + const spec = { type: "architecture", title: "Ports", summary: "A fixture for the fit rule.", legend: { main: "Request", plain: "Call" }, + nodes: [{ id: "a", name: "Incident response coordinator", col: 1, row: 2 }, { id: "b", name: "Queue", col: 2, row: 2 }, { id: "c", name: "Store", col: 2, row: 3 }, { id: "d", name: "Audit", col: 2, row: 4 }, { id: "e", name: "Search", col: 3, row: 2 }, { id: "f", name: "Mail", col: 4, row: 2 }], + edges: [{ from: "a", to: "b", kind: "main" }, { from: "a", to: "c", toSide: "left" }, { from: "a", to: "d", toSide: "left" }, { from: "b", to: "e" }, { from: "e", to: "f" }] }; + await draw(page, [{ key: "ports", spec }]); + let first = null; + const off = []; + for (let w = 760; w <= 1440; w += 4) { + await page.evaluate((w) => document.getElementById("root").style.setProperty("--w", `${w}px`), w); + await frames(page, 2); + if ((await page.getAttribute("#fig-ports", "data-layout")) !== "drawn") { if (first !== null) off.push(`${w}: stacked`); continue; } + first ??= w; + const a = await page.evaluate(() => { + const n = document.querySelector('#fig-ports .basalt-diagram-node[data-node="a"]').getBoundingClientRect(); + const ys = [...document.querySelectorAll("#fig-ports .basalt-diagram-edge")].filter((g) => g.dataset.from === "a").map((g) => Number(g.querySelector(".basalt-diagram-line").getAttribute("d").match(/-?[\d.]+/g)[1]) + document.querySelector("#fig-ports .basalt-diagram-drawing").getBoundingClientRect().top - n.top).sort((p, q) => p - q); + return { h: n.height, ys }; + }); + if (a.h < 48 - 0.5) off.push(`${w}: ${a.h} tall`); + if (a.ys[0] < 8 - 0.5 || a.ys[a.ys.length - 1] > a.h - 8 + 0.5 || a.ys.some((y, k) => k && y - a.ys[k - 1] < 8 - 0.5)) off.push(`${w}: ports ${a.ys.join(", ")} on ${a.h}`); + } + assert.ok(first !== null); + assert.deepEqual(off, []); + await page.close(); + }); +}); diff --git a/packages/react/test/diagram-keys.test.mjs b/packages/react/test/diagram-keys.test.mjs index 6a5c8b9a..240b7ce2 100644 --- a/packages/react/test/diagram-keys.test.mjs +++ b/packages/react/test/diagram-keys.test.mjs @@ -5,6 +5,7 @@ import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; import { after, before, describe, test } from "node:test"; +import { pathToFileURL } from "node:url"; import { fixturePage, launch, pkg } from "./support.mjs"; @@ -65,13 +66,20 @@ describe("drawn: the four-direction table", () => { const { page } = await keysPage(); const warnings = []; page.on("console", (m) => { if (m.type() === "warning") warnings.push(m.text()); }); - // b sits two columns right of a and two rows down: no arrow from a reaches it along a shared track, and c is only reached from b. - await page.evaluate(() => window.__set([{ key: "strand", type: "architecture", props: { title: "Stranded", summary: "A card no arrow reaches.", - nodes: [{ id: "a", name: "A", col: 1, row: 1 }, { id: "b", name: "B", col: 2, row: 2 }, { id: "c", name: "C", col: 3, row: 1 }], edges: [] } }])); + // Five cards in an X: the middle one is reached from no corner by the rule (each corner's nearest card along an arrow is another corner), so the figure keeps + // the author's order (Neon's B12: the earlier fixture stranded nothing, and the test accepted either answer). + const X = [[1, 1], [1, 3], [2, 2], [3, 1], [3, 3]]; + const spec = { title: "Stranded", summary: "A card no arrow reaches.", nodes: X.map(([col, row], k) => ({ id: `n${k}`, name: `N${k}`, col, row })), edges: [] }; + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const m = core.buildModel({ type: "architecture", ...spec }); + assert.equal(core.spatialTable(m), null, "the X strands a card"); + assert.ok(m.warnings.some((w) => /cannot be reached from another by the arrow keys/.test(w)), "and a development build says so"); + await page.evaluate((spec) => window.__set([{ key: "strand", type: "architecture", props: spec }]), spec); await frames(page, 4); - // Whether the rule strands this layout or not, the arrows either move spatially or keep the author's order: right from a is the next card. - const right = await press(page, "strand", "a", "ArrowRight"); - assert.ok(["b", "c"].includes(right)); + assert.equal(await page.locator("#fig-strand").getAttribute("data-layout"), "drawn"); + // n0 is at column 1, row 1: spatially → would go to n3 (column 3, row 1); in the author's order it goes to n1. + assert.equal(await press(page, "strand", "n0", "ArrowRight"), "n1"); + assert.equal(await press(page, "strand", "n1", "ArrowRight"), "n2"); await page.close(); }); }); diff --git a/packages/react/test/diagram-layout.test.mjs b/packages/react/test/diagram-layout.test.mjs index 5fd91907..40ce2e7d 100644 --- a/packages/react/test/diagram-layout.test.mjs +++ b/packages/react/test/diagram-layout.test.mjs @@ -76,7 +76,10 @@ describe("placeDiagram", () => { test("the graph handed to elk: network simplex, straightness 10 on main lines only, no partitioning; at most two layouts a direction", async () => { const layout = await import(pathToFileURL(path.join(pkg, "dist", "diagram-layout.js")).href); - const g = layout.elkGraph(FIG.autoArchitecture, "down"); + // The graph's helpers are internal (diagram-layout-graph, in no public declaration: Neon's B11); the module is read straight from dist. + const graph = await import(pathToFileURL(path.join(pkg, "dist", "diagram-layout-graph.js")).href); + assert.ok(!("elkGraph" in layout) && !("mainInTheMiddle" in layout), "the public module exports placeDiagram and no helper"); + const g = graph.elkGraph(FIG.autoArchitecture, "down"); assert.equal(g.layoutOptions["elk.layered.nodePlacement.strategy"], "NETWORK_SIMPLEX"); assert.ok(!JSON.stringify(g).includes("partitioning"), "no elk.partitioning option anywhere"); const main = new Set(FIG.autoArchitecture.edges.map((e, k) => (e.kind === "main" ? `${e.from}>${e.to}` : null)).filter(Boolean)); @@ -85,7 +88,7 @@ describe("placeDiagram", () => { assert.equal(e.layoutOptions?.["elk.layered.priority.straightness"], isMain ? "10" : undefined, `${e.sources[0]} to ${e.targets[0]}`); } // The main line in the middle: a card with three or more leaving lines, one of them main. - const order = layout.mainInTheMiddle([{ from: "a", main: false, n: 1 }, { from: "a", main: false, n: 2 }, { from: "a", main: true, n: 3 }, { from: "b", main: false, n: 4 }]); + const order = graph.mainInTheMiddle([{ from: "a", main: false, n: 1 }, { from: "a", main: false, n: 2 }, { from: "a", main: true, n: 3 }, { from: "b", main: false, n: 4 }]); assert.deepEqual(order.map((e) => e.n), [1, 3, 2, 4]); // Count elk's layouts: the class diagram-layout imports is this module's default. const ELK = (await import(pathToFileURL(path.join(pkg, "dist", "diagram-elk.js")).href)).default; @@ -121,6 +124,15 @@ describe("placeDiagram", () => { }); }); +describe("the package (Neon B11)", () => { + test("no declaration names elkjs or the graph's helpers, and elkjs's licence ships beside its copy", () => { + const read = (f) => fs.readFileSync(path.join(pkg, "dist", f), "utf8"); + for (const f of ["diagram-elk.d.ts", "diagram-layout.d.ts"]) assert.doesNotMatch(read(f), /["']elkjs|ElkNode|elkGraph|mainInTheMiddle/, f); + assert.match(read("elkjs/LICENSE.md"), /Eclipse Public License/); + assert.match(fs.readFileSync(path.join(pkg, "THIRD-PARTY-NOTICES.md"), "utf8"), /copied unchanged into this package/); + }); +}); + describe("the CIMIP figures draw", () => { for (const theme of ["dark", "light"]) test(`${theme}: at 1104 the architecture is drawn laid down in 4 columns and the flowchart in 3, every line and label, no problem; named right, each stacks`, async () => { const { page, errors } = await figurePage({ theme }); diff --git a/packages/react/test/diagram-output.test.mjs b/packages/react/test/diagram-output.test.mjs index 07a7819b..62cc5c46 100644 --- a/packages/react/test/diagram-output.test.mjs +++ b/packages/react/test/diagram-output.test.mjs @@ -36,7 +36,8 @@ describe("print", () => { await page.emulateMedia({ media: "print" }); const got = await page.evaluate((P) => { const fig = document.querySelector("#fig-architecture"); - const lit = fig.querySelector(`.${P}-edge[data-lit] .${P}-line, .${P}-edge[data-dim] .${P}-line`); + // A traced plain line (ALB's line to the service is plain): read as it prints. (Neon's B12: the check was skipped when a main line was found first.) + const lit = fig.querySelector(`.${P}-edge[data-lit] .${P}-line[data-kind="plain"], .${P}-edge[data-dim] .${P}-line[data-kind="plain"]`); const rest = fig.querySelector(`.${P}-edge:not([data-lit]):not([data-dim]) .${P}-line[data-kind="plain"]`) ?? fig.querySelector(`.${P}-line[data-kind="plain"]`); return { primary: getComputedStyle(document.documentElement).getPropertyValue("--basalt-text-primary").trim(), scheme: getComputedStyle(document.documentElement).colorScheme, hint: getComputedStyle(fig.querySelector(`.${P}-hint`)).display, expand: getComputedStyle(fig.querySelector(`.${P}-expand`)).display, @@ -46,7 +47,8 @@ describe("print", () => { assert.equal(got.scheme, "light"); assert.equal(got.hint, "none"); assert.equal(got.expand, "none"); - if (got.traced && got.traced[1] === "plain") assert.equal(got.traced[0], got.plain, "a traced line prints in its resting ink"); + assert.ok(got.traced, "a traced plain line is there to read"); + assert.equal(got.traced[0], got.plain, "a traced line prints in its resting ink"); await page.close(); }); }); diff --git a/packages/react/test/diagram-parts.test.mjs b/packages/react/test/diagram-parts.test.mjs index 101b45af..f3f90fe4 100644 --- a/packages/react/test/diagram-parts.test.mjs +++ b/packages/react/test/diagram-parts.test.mjs @@ -1,10 +1,14 @@ // Nested groups, link cards and two-line labels (DECISIONS 306, 1.3 and 1.4; part of section 8's list for diagram-parts.test.mjs), on the extended CIMIP -// architecture (test/fixtures/cimip-diagrams-b.json). In Chromium against the built package, both themes. End lanes and marks on steps are not built yet. +// architecture (test/fixtures/cimip-diagrams-b.json), end lanes and several entries into one card, and marks on steps and participants. In Chromium against +// the built package, both themes. // The implementation hasn't been reviewed. import assert from "node:assert/strict"; import { after, before, describe, test } from "node:test"; -import { fixturePage, launch } from "./support.mjs"; +import path from "node:path"; +import { pathToFileURL } from "node:url"; + +import { fixturePage, launch, pkg } from "./support.mjs"; const P = "basalt-diagram"; let browser; @@ -104,3 +108,59 @@ describe("two-line labels", () => { await page.close(); }); }); + +// A stacked spine of eight cards with end lines out of the first: n lines that overlap need n lanes (DECISIONS 306, 1.3). +const SPINE = (lines) => ({ title: "Lanes", summary: "End lines.", legend: { plain: "Call" }, nodes: Array.from({ length: 8 }, (_, k) => ({ id: `n${k}`, name: `N${k}`, col: 1, row: k + 1 })), edges: lines.map(([a, b]) => ({ from: `n${a}`, to: `n${b}` })) }); +const SET_HOST = ` +function Host() { + const [spec, setSpec] = React.useState(null); + window.__set = (next) => flushSync(() => setSpec(next)); + return spec ? : null; +} +createRoot(document.getElementById("root")).render();`; + +describe("end lanes and several entries into one card (1.3; Neon's B12)", () => { + test("three and four lanes at a space-3-5 pitch, the gutter its lanes and space-3; a fifth draws no lines and opens the list; several entries into one card turn space-5 apart, outermost lowest", async () => { + const { page } = await fixturePage(browser, SET_HOST, { standards: true, viewport: { width: 390, height: 1400 } }); + await page.evaluate(() => document.fonts.ready); + const lanes = async (lines) => { + await page.evaluate((spec) => window.__set(spec), SPINE(lines)); + await frames(page, 5); + return page.evaluate(() => { + const fig = document.querySelector("#fig-lanes"); + const d = fig.querySelector(".basalt-diagram-drawing").getBoundingClientRect(); + const cardsR = Math.max(...[...fig.querySelectorAll(".basalt-diagram-node")].map((n) => n.getBoundingClientRect().right)) - d.left; + const xs = [...new Set([...fig.querySelectorAll(".basalt-diagram-svg .basalt-diagram-line")].map((p) => Math.max(...p.getAttribute("d").match(/-?[\d.]+/g).map(Number).filter((_, k) => k % 2 === 0))))].map((x) => Math.round((x - cardsR) * 2) / 2).sort((a, b) => a - b); + return { bare: fig.hasAttribute("data-bare"), open: !fig.querySelector(".basalt-diagram-list").hidden, gutter: d.right - d.left - cardsR, xs }; + }); + }; + // Lines that all pass n1..n2 overlap: three of them, then four. + const three = await lanes([[0, 3], [0, 4], [0, 5]]); + assert.ok(!three.bare && Math.abs(three.gutter - 54) <= 0.5, JSON.stringify(three)); + assert.deepEqual(three.xs.map((x, k) => (k ? x - three.xs[k - 1] : 0)).slice(1), [14, 14]); + const four = await lanes([[0, 3], [0, 4], [0, 5], [0, 6]]); + assert.ok(!four.bare && Math.abs(four.gutter - 68) <= 0.5, JSON.stringify(four)); + const five = await lanes([[0, 3], [0, 4], [0, 5], [0, 6], [0, 7]]); + assert.ok(five.bare && five.open, JSON.stringify(five)); + // Two end lines into one card (n5, from n0 and n1): the outer line turns lowest, the inner space-5 higher. + await page.evaluate((spec) => window.__set(spec), SPINE([[0, 5], [1, 5]])); + await frames(page, 5); + const turns = await page.evaluate(() => [...document.querySelectorAll("#fig-lanes .basalt-diagram-edge")].filter((g) => g.dataset.to === "n5").map((g) => { const n = g.querySelector(".basalt-diagram-line").getAttribute("d").match(/-?[\d.]+/g).map(Number); const pts = []; for (let k = 0; k + 1 < n.length; k += 2) pts.push([n[k], n[k + 1]]); let turn = null; for (let k = 1; k < pts.length; k++) if (Math.abs(pts[k][1] - pts[k - 1][1]) < 0.01 && Math.abs(pts[k][0] - pts[k - 1][0]) > 2) turn = pts[k][1]; return { lane: Math.max(...pts.map((p) => p[0])), turn }; }).sort((a, b) => b.lane - a.lane)); + assert.equal(turns.length, 2); + assert.ok(turns[0].turn > turns[1].turn, `the outermost lane turns lowest ${JSON.stringify(turns)}`); + assert.ok(Math.abs(turns[0].turn - turns[1].turn - 20) <= 1, `space-5 apart ${JSON.stringify(turns)}`); + await page.close(); + }); +}); + +describe("marks on steps and participants (1.6; Neon's B10 and B12)", () => { + test("a data flow step's mark counts its lane's label as its words; a participant may carry a mark and a person never needs one", async () => { + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const flow = (lane) => core.buildModel({ type: "data-flow", title: "t", summary: "s", lanes: [{ id: "s3", label: lane }], nodes: [{ id: "seg", lane: "s3", col: 1, name: "Sealed segment", mark: { onLight: "a.svg", says: ["S3"] } }], edges: [] }); + assert.deepEqual(flow("S3").warnings, [], "the lane's label says S3"); + assert.ok(flow("Storage").warnings.some((w) => /stands for S3/.test(w)), "and without it the mark carries a fact alone"); + const seq = core.buildModel({ type: "sequence", title: "t", summary: "s", participants: [{ id: "a", name: "Amazon S3", mark: { onLight: "a.svg", says: ["S3"] } }, { id: "p", name: "Marcus" }], steps: [{ from: "p", to: "a", label: "put" }] }); + assert.deepEqual(seq.warnings, []); + assert.ok(seq.nodes[0].mark && !seq.nodes[1].mark); + }); +}); diff --git a/packages/react/test/diagram-review.test.mjs b/packages/react/test/diagram-review.test.mjs new file mode 100644 index 00000000..13d0942b --- /dev/null +++ b/packages/react/test/diagram-review.test.mjs @@ -0,0 +1,486 @@ +// The fix round for diagram batch B (DECISIONS 306, 313, 322 and 326): a test for each finding of Fable's pixel review and Neon's code review of 65fa32bd +// that this round fixed, and for the decider's spacing sweep (66-1 to 66-3), each written to fail when its feature breaks. In Chromium against the built +// package, both themes where a colour is read. The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { after, before, describe, test } from "node:test"; +import { pathToFileURL } from "node:url"; + +import * as esbuild from "esbuild"; + +import { inspectSource } from "./diagram-geometry.mjs"; +import { fixturePage, launch, pkg } from "./support.mjs"; + +const B = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams-b.json"), "utf8")); +const P = "basalt-diagram"; +const font = (file) => fs.readFileSync(path.join(pkg, "dist", "fonts", file)).toString("base64"); +const FONTS = `@font-face{font-family:"Geist";src:url(data:font/woff2;base64,${font("Geist-Variable.woff2")}) format("woff2");font-weight:100 900}@font-face{font-family:"Geist Mono";src:url(data:font/woff2;base64,${font("GeistMono-Variable.woff2")}) format("woff2");font-weight:100 900}`; +const PAGE = `${FONTS} body{background:var(--basalt-surface-page);margin:0;padding:16px;box-sizing:border-box} #root{max-width:1104px;margin:0 auto}`; + +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +const HOST = ` +import * as Export from "./dist/diagram-export.js"; +window.__export = Export; +const C = { architecture: B.ArchitectureDiagram, flowchart: B.FlowchartDiagram, "data-flow": B.DataFlowDiagram, sequence: B.SequenceDiagram, schema: B.SchemaDiagram }; +function Host() { + const [list, setList] = React.useState([]); + window.__set = (next) => flushSync(() => setList(next)); + return
{list.map(({ key, spec, dir }) => { const { type, ...props } = spec; const X = C[type]; return
; })}
; +} +createRoot(document.getElementById("root")).render();`; + +const frames = (page, n = 3) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); +async function reviewPage({ theme = "dark", width = 1440, height = 900, touch = false, dev = false, media } = {}) { + const { page, errors } = await fixturePage(browser, "", { theme, viewport: { width, height }, standards: true, hasTouch: touch, isMobile: touch }); + const built = await esbuild.build({ + stdin: { contents: `import * as React from "react"; import { createRoot } from "react-dom/client"; import { flushSync } from "react-dom"; import * as B from "./dist/index.js"; ${HOST}`, resolveDir: pkg, loader: "tsx" }, + bundle: true, format: "iife", write: false, jsx: "automatic", platform: "browser", logLevel: "silent", define: { "process.env.NODE_ENV": dev ? '"development"' : '"production"' }, + }); + const warnings = []; + page.on("console", (m) => { if (m.type() === "warning" || m.type() === "error") warnings.push(m.text()); }); + if (touch) await page.evaluate(() => { const meta = document.createElement("meta"); meta.name = "viewport"; meta.content = "width=device-width, initial-scale=1"; document.head.append(meta); }); + if (media) await page.emulateMedia(media); + await page.addScriptTag({ content: built.outputFiles[0].text }); + await page.addStyleTag({ content: PAGE }); + await page.evaluate(() => document.fonts.ready); + return { page, errors, warnings }; +} +const draw = async (page, items) => { await page.evaluate((items) => window.__set(items), items); await page.waitForFunction((n) => document.querySelectorAll(".basalt-diagram[data-layout]").length >= n, items.length); await frames(page, 5); }; +const inspect = (page, key) => page.evaluate(`${inspectSource()}("${P}", "#fig-${key}")`); +async function openViewer(page, key, how = "click") { + const button = page.locator(`#fig-${key} .${P}-expand`); + await button.scrollIntoViewIfNeeded(); + if (how === "tap") await button.tap(); else await button.click(); + await page.waitForSelector(`dialog.${P}-viewer[open] .${P}[data-layout]`); + await page.evaluate(() => Promise.all(document.getAnimations().map((a) => a.finished.catch(() => {})))); + await page.waitForTimeout(300); + await frames(page, 4); +} +const rect = (page, sel) => page.locator(sel).first().evaluate((e) => { const r = e.getBoundingClientRect(); return { l: r.left, r: r.right, t: r.top, b: r.bottom, w: r.width, h: r.height }; }); + +describe("the viewer (Fable B1 to B4, Neon B1 to B3)", () => { + for (const theme of ["dark", "light"]) test(`${theme}: a disabled control takes no hover, press or scale and does not match an enabled one's ink; "Clear highlight" with no trace is disabled the same way`, async () => { + const { page } = await reviewPage({ theme }); + await draw(page, [{ key: "schema", spec: B.schema }]); + await openViewer(page, "schema"); + const out = `dialog.${P}-viewer button[aria-label="Zoom out"]`, zin = `dialog.${P}-viewer button[aria-label="Zoom in"]`; + const look = (sel) => page.locator(sel).evaluate((e) => { const s = getComputedStyle(e); return { color: s.color, bg: s.backgroundColor, transform: s.transform, cursor: s.cursor, disabled: e.hasAttribute("data-disabled"), aria: e.getAttribute("aria-disabled"), focusable: e.tabIndex >= 0 }; }); + const rest = await look(out), live = await look(zin); + assert.equal(rest.aria, "true"); + assert.ok(rest.disabled && rest.focusable, "disabled, and still focusable"); + assert.notEqual(rest.color, live.color, "a disabled control loses its ink"); + await page.hover(out); + await page.waitForTimeout(200); + const hovered = await look(out); + assert.equal(hovered.color, rest.color, "no hover lift"); + assert.equal(hovered.bg, rest.bg, "no hover wash"); + await page.mouse.down(); + await page.waitForTimeout(150); + const pressed = await look(out); + assert.equal(pressed.transform, "none", "no press scale"); + assert.equal(pressed.bg, rest.bg, "no press step"); + await page.mouse.up(); + await page.close(); + const touch = await reviewPage({ theme, width: 390, height: 844, touch: true }); + await touch.page.evaluate(() => document.getElementById("root").style.setProperty("max-width", "1104px")); + await draw(touch.page, [{ key: "arch", spec: B.architecture }]); + await touch.page.setViewportSize({ width: 1200, height: 900 }); + await touch.page.waitForTimeout(400); + const clear = touch.page.locator(`#fig-arch .${P}-clear`); + assert.equal(await clear.count(), 1, "Clear highlight is in the foot on touch"); + const c = await clear.evaluate((e) => ({ disabled: e.hasAttribute("data-disabled"), color: getComputedStyle(e).color })); + const toggle = await touch.page.locator(`#fig-arch .${P}-toggle`).evaluate((e) => getComputedStyle(e).color); + assert.ok(c.disabled, "Clear highlight is disabled with no trace"); + assert.notEqual(c.color, toggle, "and does not look like a live control"); + await touch.page.close(); + }); + + test("a linked card in the viewer closes the viewer and is followed, by a click and by Enter; a new tab's link leaves it open", async () => { + const { page } = await reviewPage(); + await draw(page, [{ key: "arch", spec: B.architecture }]); + await openViewer(page, "arch"); + const link = page.locator(`dialog.${P}-viewer a.${P}-node[data-node="svc"]`); + assert.equal(await link.getAttribute("href"), "#fig-sequence"); + await link.click(); + await page.waitForTimeout(400); + assert.equal(await page.evaluate(() => location.hash), "#fig-sequence"); + assert.equal(await page.locator(`dialog.${P}-viewer[open]`).count(), 0, "the viewer is closed"); + await page.evaluate(() => { location.hash = ""; }); + await openViewer(page, "arch"); + await page.locator(`dialog.${P}-viewer a.${P}-node[data-node="svc"]`).focus(); + await page.keyboard.press("Enter"); + await page.waitForTimeout(400); + assert.equal(await page.locator(`dialog.${P}-viewer[open]`).count(), 0, "Enter closes it too"); + await page.close(); + }); + + for (const [w, h] of [[1440, 900], [390, 844]]) test(`at ${w} by ${h}, a text sequence's viewer holds the art at its own width, never the transcript`, async () => { + const { page } = await reviewPage({ width: w, height: h }); + await draw(page, [{ key: "text", spec: B.textSequence }]); + await openViewer(page, "text"); + await page.waitForSelector(`dialog.${P}-viewer .${P}-text[data-art]`); + const got = await page.evaluate((P) => { + const pre = document.querySelector(`dialog.${P}-viewer .${P}-text`); + return { art: pre.hasAttribute("data-art"), scrolls: pre.scrollWidth > pre.clientWidth + 1, tx: pre.querySelectorAll(`.${P}-tx-line`).length, width: pre.getBoundingClientRect().width }; + }, P); + assert.ok(got.art && !got.scrolls && got.tx === 0, JSON.stringify(got)); + assert.ok(got.width > 480, "wider than the stack's 480"); + await page.close(); + }); + + for (const theme of ["dark", "light"]) test(`${theme}: the viewer's dialog has the form dialog's rim, and right to left it is inside the window`, async () => { + const { page } = await reviewPage({ theme }); + await draw(page, [{ key: "schema", spec: B.schema }]); + await openViewer(page, "schema"); + const rim = await page.locator(`dialog.${P}-viewer`).evaluate((d) => { const s = getComputedStyle(d); return { w: s.borderTopWidth, style: s.borderTopStyle, top: s.borderTopColor, side: s.borderLeftColor }; }); + const panel = await page.evaluate(() => { const d = document.createElement("div"); d.className = "basalt-card"; document.body.append(d); const s = getComputedStyle(d); const out = { top: s.borderTopColor, side: s.borderLeftColor }; d.remove(); return out; }); + assert.deepEqual(rim, { w: "1px", style: "solid", top: panel.top, side: panel.side }); + await page.keyboard.press("Escape"); + await page.waitForTimeout(400); + await page.evaluate(() => { document.documentElement.dir = "rtl"; }); + await frames(page, 4); + await openViewer(page, "schema"); + const r = await rect(page, `dialog.${P}-viewer`); + assert.ok(r.l >= 15.5 && r.r <= 1440 - 15.5, `inside the window: ${JSON.stringify(r)}`); + await page.close(); + }); +}); + +describe("right to left, drawn (Fable B5, Neon B4)", () => { + test("a frame's tab is in its frame's top start corner, the else rule inside its frame, a self-call's words beside its loop, and a Mono detail reads in order", async () => { + const { page } = await reviewPage(); + await draw(page, [{ key: "seq", spec: B.sequence, dir: "rtl" }, { key: "arch", spec: B.architecture, dir: "rtl" }]); + assert.equal(await page.locator("#fig-seq").getAttribute("data-layout"), "drawn"); + const frames2 = await page.evaluate((P) => [...document.querySelectorAll(`#fig-seq .${P}-frame`)].map((f) => { + const box = f.querySelector(`:scope > .${P}-fbox`).getBoundingClientRect(), head = f.querySelector(`:scope > .${P}-fhead`).getBoundingClientRect(); + const rules = [...f.querySelectorAll(`:scope > .${P}-felse`)].map((e) => { const s = getComputedStyle(e, "::before"); const r = e.getBoundingClientRect(); return { l: r.left + parseFloat(s.left), w: parseFloat(s.width) }; }); + return { op: f.dataset.op, box: [box.left, box.right], head: [head.left, head.right], rules }; + }), P); + for (const f of frames2) { + assert.ok(f.head[0] >= f.box[0] - 0.5 && f.head[1] <= f.box[1] + 0.5, `${f.op}: the header is inside its frame ${JSON.stringify(f)}`); + assert.ok(Math.abs(f.head[1] - (f.box[1] - 1)) <= 1, `${f.op}: at the frame's start (right) edge`); + for (const r of f.rules) assert.ok(Math.abs(r.l - f.box[0]) <= 1 && Math.abs(r.w - (f.box[1] - f.box[0])) <= 1, `${f.op}: the else rule spans the frame`); + } + // Message 2 is the service's self-call: its loop goes to the left (the end side right to left), and its words are beside the loop, on the left. + const self = await page.evaluate((P) => { + const li = document.querySelector(`#fig-seq .${P}-msg[data-self]`); + const said = li.querySelector(`.${P}-said`).getBoundingClientRect(); + const o = document.querySelector(`#fig-seq .${P}-drawing`).getBoundingClientRect(); + const line = [...document.querySelectorAll(`#fig-seq .${P}-edge`)].find((g) => g.dataset.from === li.dataset.from && g.dataset.to === li.dataset.to); + const xs = line.querySelector(`.${P}-line`).getAttribute("d").match(/-?[\d.]+/g).map(Number).filter((_, k) => k % 2 === 0); + return { side: li.dataset.self, said: [said.left - o.left, said.right - o.left], loop: [Math.min(...xs), Math.max(...xs)] }; + }, P); + if (self.side === "start") assert.ok(self.said[1] <= self.loop[0] + 0.5, `the words are left of the loop ${JSON.stringify(self)}`); + else assert.ok(self.said[0] >= self.loop[1] - 0.5, `the words are right of the loop ${JSON.stringify(self)}`); + // "N tasks · stateless" reads in that order, left to right. + const order = await page.evaluate((P) => [...document.querySelectorAll(`#fig-arch .${P}-node[data-node="svc"] .${P}-run`)].sort((a, b) => a.getBoundingClientRect().left - b.getBoundingClientRect().left || a.getBoundingClientRect().top - b.getBoundingClientRect().top).map((r) => r.textContent).join(" "), P); + assert.equal(order, "N tasks · stateless"); + await page.close(); + }); +}); + +describe("stacked (Fable P2, P3, answer 1; the sweep's 66-1 to 66-3)", () => { + for (const theme of ["dark", "light"]) test(`${theme}: at 390 the else rule runs edge to edge of its frame, no row divider lies on a frame's edge, and no turn into a group's first card is under its label`, async () => { + const { page } = await reviewPage({ theme, width: 390, height: 900 }); + await draw(page, [{ key: "seq", spec: B.sequence }, { key: "arch", spec: B.architecture }]); + const got = await page.evaluate((P) => { + const out = { rules: [], after: [] }; + for (const f of document.querySelectorAll(`#fig-seq .${P}-frame`)) { + const box = f.getBoundingClientRect(); + for (const e of f.querySelectorAll(`:scope > .${P}-felse`)) { const s = getComputedStyle(e, "::before"); const r = e.getBoundingClientRect(); out.rules.push({ l: r.left + parseFloat(s.left), w: parseFloat(s.width), box: [box.left, box.width] }); } + const next = f.nextElementSibling; + if (next?.matches(`.${P}-msgs`)) out.after.push(getComputedStyle(next.firstElementChild).borderTopColor); + } + return out; + }, P); + assert.ok(got.rules.length > 0); + for (const r of got.rules) assert.ok(Math.abs(r.l - r.box[0]) <= 1 && Math.abs(r.w - r.box[1]) <= 1, JSON.stringify(r)); + assert.ok(got.after.length > 0); + for (const c of got.after) assert.match(c, /rgba\(0, 0, 0, 0\)|transparent/, "the row after a frame draws no divider"); + // Answer 1: the inner group "Data & logs" is entered by a turn: its label's plate and the turn do not meet. + const g = await page.evaluate((P) => { + const group = [...document.querySelectorAll(`#fig-arch .${P}-group`)].find((x) => x.hasAttribute("data-turn")); + if (!group) return null; + const label = group.querySelector(`:scope > .${P}-glabel`).getBoundingClientRect(); + const first = group.querySelector(`.${P}-node`); + const o = document.querySelector(`#fig-arch .${P}-drawing`).getBoundingClientRect(); + const turns = [...document.querySelectorAll(`#fig-arch .${P}-edge`)].filter((e) => e.dataset.to === first.dataset.node).map((e) => { + const n = e.querySelector(`.${P}-line`).getAttribute("d").match(/-?[\d.]+/g).map(Number); + const pts = []; for (let k = 0; k + 1 < n.length; k += 2) pts.push({ x: n[k] + o.left, y: n[k + 1] + o.top }); + return pts; + }); + return { pad: getComputedStyle(group).paddingTop, label: { t: label.top, b: label.bottom, l: label.left, r: label.right }, turns }; + }, P); + assert.ok(g, "a group whose first card is entered by a turn is marked"); + assert.equal(g.pad, "48px"); + for (const pts of g.turns) for (const p of pts) assert.ok(!(p.y > g.label.t && p.y < g.label.b && p.x > g.label.l && p.x < g.label.r), `no turn point under the label ${JSON.stringify(p)}`); + await page.close(); + }); + + test("66-1: on touch a one-line end node's words are centred in its 44px box; 66-2: a wrapped route breaks before its arrow and keeps the 16px pitch", async () => { + const { page } = await reviewPage({ width: 390, height: 900, touch: true }); + await draw(page, [{ key: "flow", spec: B.flowchart }, { key: "seq", spec: B.sequence }]); + const node = await page.evaluate((P) => { + const n = [...document.querySelectorAll(`#fig-flow .${P}-node`)].find((e) => e.textContent.includes("Told it was already decided")); + const r = n.getBoundingClientRect(), w = n.querySelector(`.${P}-name`).getBoundingClientRect(); + return { h: r.height, above: w.top - r.top, below: r.bottom - w.bottom }; + }, P); + assert.ok(node.h >= 44 - 0.5); + assert.ok(Math.abs(node.above - node.below) <= 0.5, JSON.stringify(node)); + const routes = await page.evaluate((P) => [...document.querySelectorAll(`#fig-seq .${P}-route`)].map((r) => { + const to = r.querySelector(`.${P}-to`), arrow = r.querySelector("svg"); + const lines = new Set([...r.getClientRects()].map((x) => Math.round(x.top))); + return { to: Boolean(to), arrowWithName: to && to.contains(arrow), gap: getComputedStyle(r).rowGap, wrapped: to && to.getBoundingClientRect().top > r.getBoundingClientRect().top + 1, ok: !to || [...to.getClientRects()].length === 1 }; + }), P); + for (const r of routes) { assert.ok(r.to && r.arrowWithName && r.ok); assert.equal(r.gap, "0px"); } + await page.close(); + }); + + test("66-3: right to left, a stacked group's label is on its start side (the right)", async () => { + const { page } = await reviewPage({ width: 390, height: 900 }); + await draw(page, [{ key: "arch", spec: B.architecture, dir: "rtl" }]); + const g = await page.evaluate((P) => [...document.querySelectorAll(`#fig-arch .${P}-group`)].map((x) => { const r = x.getBoundingClientRect(), l = x.querySelector(`:scope > .${P}-glabel`).getBoundingClientRect(); return { start: l.left - r.left, end: r.right - l.right }; }), P); + assert.ok(g.length > 0); + for (const x of g) assert.ok(x.end < x.start, JSON.stringify(x)); + await page.close(); + }); +}); + +describe("the text sequence (Fable B6, P4, P7; Neon B6)", () => { + test("the transcript: a message's label and note on lines of their own, each hanging under the sender inside its frame's indent; the key's focal swatch is the art's double box", async () => { + const { page } = await reviewPage({ width: 390, height: 900 }); + await draw(page, [{ key: "text", spec: B.textSequence }]); + const got = await page.evaluate((P) => { + const lines = [...document.querySelectorAll(`#fig-text .${P}-tx-line[data-n]`)]; + const byN = new Map(); + for (const l of lines) { const n = l.dataset.n; if (!byN.has(n)) byN.set(n, []); byN.get(n).push(l); } + return [...byN.values()].map((ls) => { + const first = ls[0], sender = first.querySelector(`.${P}-tx-name`).getBoundingClientRect().left; + return { n: first.dataset.n, lines: ls.length, label: ls[1]?.textContent, hang: ls.slice(1).map((l) => { const r = document.createRange(); r.selectNodeContents(l); return r.getClientRects()[0].left - sender; }), labelInLine1: first.textContent.includes(ls[1]?.textContent ?? "\u0000") }; + }); + }, P); + assert.ok(got.length >= 10); + for (const m of got) { + assert.ok(m.lines >= 2 && m.label && !m.labelInLine1, JSON.stringify(m)); + for (const x of m.hang) assert.ok(Math.abs(x) <= 1, `message ${m.n} hangs under its sender (${x})`); + } + const focal = await page.locator(`#fig-text .${P}-entry[data-focal] .${P}-key-glyph`).textContent(); + assert.equal(focal, "╔═╗"); + await page.close(); + }); + + test("textArt: a frame's header too long for its columns widens the frame, with both corners; a self-call on the last participant keeps its words off the next lifeline", async () => { + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const text = await import(pathToFileURL(path.join(pkg, "dist", "diagram-text.js")).href); + const m = core.buildModel({ type: "sequence", variant: "text", title: "t", summary: "s", participants: [{ id: "a", name: "A" }, { id: "b", name: "B" }], + steps: [{ frame: "opt", label: "a very long condition header for it", steps: [{ from: "a", to: "b", label: "go" }, { from: "b", to: "b", label: "self", note: "a much longer note than the self label" }] }] }); + const rows = text.textArt(m).html.replace(/<[^>]+>/g, "").replace(/&/g, "&").split("\n"); + const top = rows.find((r) => r.includes("[opt]")); + assert.match(top, /┌.*\[opt\].*a very long condition header for it.*┐/); + const bottom = rows.filter((r) => r.trimStart().startsWith("└─") && r.includes("┘")).pop(); + assert.equal(top.indexOf("┌"), bottom.indexOf("└")); + assert.equal(top.lastIndexOf("┐"), bottom.lastIndexOf("┘")); + const noteRow = rows.find((r) => r.includes("a much longer note than the self label")); + assert.ok(noteRow, "the note is whole"); + assert.equal(noteRow[top.indexOf("┌")], "│", "the frame's side is not written over"); + }); + + test("animated: the build waits until the art is in view, then plays; run: true shows Play the run, and the run quiets the messages not yet reached", async () => { + const { page } = await reviewPage({ width: 1440, height: 600 }); + const spec = { ...B.textSequence, motion: "animated", run: true }; + await page.evaluate((spec) => window.__set([{ key: "spacer", spec: { type: "schema", title: "Spacer", summary: "s", tables: Array.from({ length: 6 }, (_, k) => ({ name: `t${k}`, col: 1, row: k + 1, columns: [{ name: "id" }] })) } }, { key: "text", spec }]), spec); + await page.waitForSelector(`#fig-text .${P}-text[data-art]`); + await page.waitForTimeout(600); + assert.equal(await page.locator("#fig-text").getAttribute("data-entrance"), "pending", "out of view, the build waits"); + await page.locator("#fig-text").scrollIntoViewIfNeeded(); + await page.waitForFunction(() => ["running", "done"].includes(document.querySelector("#fig-text").getAttribute("data-entrance"))); + const play = page.locator(`#fig-text button`, { hasText: "Play the run" }); + assert.equal(await play.count(), 1, "Play the run"); + await page.evaluate(() => document.getAnimations().forEach((a) => a.finish())); + await play.click(); + await page.waitForTimeout(200); + const ahead = await page.locator(`#fig-text .${P}-text [data-n][data-ahead]`).count(); + assert.ok(ahead > 0, "messages not yet reached are quiet"); + await page.close(); + }); +}); + +describe("export (Neon B5)", () => { + test("a flowchart's diamonds keep their size and stroke; a running entrance and a quiet run export at rest; the else rule is drawn; the lines are under the cards", async () => { + const { page } = await reviewPage(); + await draw(page, [{ key: "flow", spec: B.flowchart }, { key: "seq", spec: { ...B.sequence, motion: "animated", run: true } }]); + const svg = await page.evaluate(async () => await (await window.__export.diagramToSvg(document.querySelector("#fig-flow"), { fonts: "name" })).text()); + const diamonds = [...svg.matchAll(/]*>/g)].map((m) => m[0]); + assert.ok(diamonds.length > 0); + for (const d of diamonds) assert.match(d, /width="[\d.]+" height="[\d.]+"/); + assert.match(svg, /vector-effect="non-scaling-stroke"/); + const ink = svg.indexOf(' await (await window.__export.diagramToSvg(document.querySelector("#fig-seq"), { fonts: "name" })).text()); + assert.doesNotMatch(mid, /-reveal-/); + assert.match(mid, /stroke-dasharray="4 4"/, "the else rule is in the file"); + await page.evaluate(() => document.getAnimations().forEach((a) => a.finish())); + await page.locator(`#fig-seq button`, { hasText: "Play the run" }).click(); + await page.waitForTimeout(300); + assert.ok(await page.locator(`#fig-seq [data-ahead]`).count() > 0); + const run = await page.evaluate(async () => await (await window.__export.diagramToSvg(document.querySelector("#fig-seq"), { fonts: "name" })).text()); + const secondary = await page.evaluate(() => getComputedStyle(document.querySelector("#fig-seq")).getPropertyValue("--basalt-text-secondary").trim()); + const labels = await page.evaluate((P) => [...document.querySelectorAll(`#fig-seq .${P}-mlabel`)].map((e) => e.textContent), P); + assert.ok(await page.locator(`#fig-seq [data-ahead]`).count() > 0, "the run is put back after the read"); + const last = labels[labels.length - 1].split(" ")[0]; + const fill = new RegExp(`fill="([^"]+)"[^>]*>${last.replace(/[{}/]/g, (c) => `\\${c}`)}<`).exec(run)?.[1]; + assert.ok(fill && fill !== secondary, `an unreached message exports in its resting ink (${fill})`); + await page.close(); + }); +}); + +describe("automatic layout and the schema (Neon B8, B9, P1 to P3)", () => { + test("a placement with two cards in one cell is not used: the figure stacks and a development build names the cards", async () => { + const { page, warnings } = await reviewPage({ dev: true }); + await draw(page, [{ key: "bad", spec: { type: "architecture", layout: "auto", title: "Two in one", summary: "s", nodes: [{ id: "a", name: "A" }, { id: "b", name: "B" }], edges: [{ from: "a", to: "b" }], placement: { direction: "right", cells: { a: { col: 1, row: 1 }, b: { col: 1, row: 1 } } } } }]); + assert.equal(await page.locator("#fig-bad").getAttribute("data-layout"), "stacked"); + assert.ok(warnings.some((w) => /puts a and b in one cell/.test(w)), JSON.stringify(warnings)); + await page.close(); + }); + + test("a one-column marked schema: turn-backs that state different things at one key take lanes of their own and draw", async () => { + const { page } = await reviewPage(); + await draw(page, [{ key: "one", spec: { type: "schema", title: "One column", summary: "s", tables: [ + { name: "users", col: 1, row: 1, columns: [{ name: "id", key: "PK" }] }, + { name: "a", col: 1, row: 2, columns: [{ name: "x", key: "FK", references: "users.id", cardinality: { from: "zero-or-many", to: "one" } }] }, + { name: "b", col: 1, row: 3, columns: [{ name: "y", key: "FK", references: "users.id", cardinality: { from: "zero-or-many", to: "zero-or-one" } }] }, + ] } }]); + const g = await inspect(page, "one"); + assert.equal(g.layout, "drawn"); + assert.equal(g.lines.length, 2); + assert.deepEqual(g.problems, []); + await page.close(); + }); + + test("placeDiagram: an empty figure and a cycle of groups answer; right to left a way-only column stays", async () => { + const { placeDiagram } = await import(pathToFileURL(path.join(pkg, "dist", "diagram-layout.js")).href); + const empty = await placeDiagram({ type: "architecture", nodes: [], edges: [] }, "right"); + assert.deepEqual([empty.cols, empty.rows], [1, 1]); + const cyc = await Promise.race([placeDiagram({ type: "architecture", groups: [{ id: "g", label: "G", parent: "h" }, { id: "h", label: "H", parent: "g" }], nodes: [{ id: "a", group: "g" }, { id: "b", group: "h" }], edges: [{ from: "a", to: "b", kind: "main" }] }, "down"), new Promise((r) => setTimeout(() => r("hung"), 5000))]); + assert.notEqual(cyc, "hung"); + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const placement = { direction: "down", cols: 2, rows: 2, cells: { a: { col: 2, row: 1 }, b: { col: 2, row: 2 } } }; + const spec = { type: "architecture", layout: "auto", title: "t", summary: "s", nodes: [{ id: "a", name: "A" }, { id: "b", name: "B" }], edges: [{ from: "a", to: "b", kind: "main" }] }; + assert.equal(core.buildModel(spec, { placement }).cols, 2); + assert.equal(core.buildModel(spec, { placement, rtl: true }).cols, 2); + }); + + test("a straight line and two others on one half grow a card to 48, not 49 (Neon P1)", async () => { + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const n = (id, col, row) => ({ id, name: id, kind: "part", col, row }); + const m = core.buildModel({ type: "architecture", title: "t", summary: "s", nodes: [n("a", 1, 1), n("b", 2, 1), n("c", 2, 2), n("d", 2, 3)], edges: [{ from: "a", to: "b" }, { from: "a", to: "c" }, { from: "a", to: "d" }] }, { checks: false }); + assert.equal(core.portFloors(m).a, 48); + }); +}); + +describe("the sequence's fit and order (Neon B7, P8)", () => { + test("a self-call's words that would lie on a frame's side stack the figure; the lifelines are under the frames, the bars and lines over them", async () => { + const { page } = await reviewPage(); + const spec = { type: "sequence", title: "t", summary: "s", participants: [{ id: "a", name: "A" }, { id: "b", name: "B" }, { id: "c", name: "C" }], + steps: [{ frame: "opt", label: "only", steps: [{ from: "a", to: "b", label: "go" }, { from: "b", to: "b", label: "a self-call whose words are long" }] }, { from: "b", to: "c", label: "on" }] }; + await draw(page, [{ key: "fit", spec }, { key: "seq", spec: B.sequence }]); + const fit = await page.evaluate((P) => { + const said = document.querySelector(`#fig-fit .${P}-msg[data-self] .${P}-said`); + const box = document.querySelector(`#fig-fit .${P}-fbox`); + if (!said || !box) return { layout: document.querySelector("#fig-fit").dataset.layout }; + const s = said.getBoundingClientRect(), b = box.getBoundingClientRect(); + return { layout: document.querySelector("#fig-fit").dataset.layout, crosses: s.left < b.right && s.right > b.right }; + }, P); + assert.ok(fit.layout === "stacked" || !fit.crosses, JSON.stringify(fit)); + const z = await page.evaluate((P) => { + const fig = document.querySelector("#fig-seq"); + const zi = (sel) => getComputedStyle(fig.querySelector(sel)).zIndex; + return { lifes: zi(`.${P}-lifes`), frame: zi(`.${P}-fbox`), lines: zi(`.${P}-ink > .${P}-svg`), said: zi(`.${P}-msg .${P}-said`), steps: zi(`.${P}-steps`), ink: zi(`.${P}-ink`) }; + }, P); + assert.deepEqual(z, { lifes: "0", frame: "1", lines: "2", said: "3", steps: "auto", ink: "auto" }); + await page.close(); + }); + + test("forced colours: a quiet run's head goes with its line", async () => { + const { page } = await reviewPage({ media: { forcedColors: "active" } }); + await draw(page, [{ key: "seq", spec: { ...B.sequence, motion: "animated", run: true } }]); + await page.evaluate(() => { const g = document.querySelector("#fig-seq .basalt-diagram-edge"); g.setAttribute("data-ahead", ""); }); + const c = await page.evaluate((P) => { const g = document.querySelector(`#fig-seq .${P}-edge[data-ahead]`); return { line: getComputedStyle(g.querySelector(`.${P}-line`)).stroke, tip: getComputedStyle(g.querySelector(`.${P}-tip`)).fill }; }, P); + assert.ok(c.line === c.tip || (c.tip === "none"), JSON.stringify(c)); + await page.close(); + }); +}); + +describe("the package's lazy parts (Neon B12)", () => { + test("the index and every diagram component reach diagram-layout, its graph, elkjs, export, the viewer, motion and the text art only by a dynamic import", () => { + const dist = path.join(pkg, "dist"); + const statics = (file) => [...fs.readFileSync(path.join(dist, file), "utf8").matchAll(/(?:^|[;\n])\s*(?:import|export)\s[^;]*?from\s*"(\.\/[^"]+)"|(?:^|[;\n])\s*import\s*"(\.\/[^"]+)"/g)].map((m) => path.normalize(path.join(path.dirname(file), m[1] ?? m[2]))); + const lazy = ["diagram-layout.js", "diagram-layout-graph.js", "diagram-elk.js", "diagram-export.js", "diagram-viewer.js", "diagram-motion.js", "diagram-text.js"]; + for (const entry of ["index.js", "architecture-diagram.js", "flowchart-diagram.js", "data-flow-diagram.js", "sequence-diagram.js", "schema-diagram.js"]) { + const seen = new Set([entry]); + const todo = [entry]; + while (todo.length) for (const next of statics(todo.pop())) if (!seen.has(next) && fs.existsSync(path.join(dist, next))) { seen.add(next); todo.push(next); } + for (const name of lazy) assert.ok(!seen.has(name), `${entry} reaches ${name} statically`); + for (const file of seen) assert.doesNotMatch(fs.readFileSync(path.join(dist, file), "utf8"), /Eclipse Layout Kernel/, `${entry} reaches elkjs through ${file}`); + } + }); +}); + +describe("motion (Neon B12: the quiet run and the first visit)", () => { + test("a drawn run quiets every message after the current one and restores them all when stopped", async () => { + const { page } = await reviewPage(); + await draw(page, [{ key: "seq", spec: { ...B.sequence, motion: "animated", run: true } }]); + await page.evaluate(() => document.getAnimations().forEach((a) => a.finish())); + await page.locator(`#fig-seq button`, { hasText: "Play the run" }).click(); + await page.waitForTimeout(250); + const during = await page.evaluate((P) => { const msgs = [...document.querySelectorAll(`#fig-seq .${P}-msg`)]; const k = msgs.findIndex((m) => m.hasAttribute("data-ahead")); return { first: k, after: msgs.slice(k).every((m) => m.hasAttribute("data-ahead")), label: k >= 0 ? getComputedStyle(msgs[k].querySelector(`.${P}-mlabel`)).color : null, rest: getComputedStyle(msgs[0].querySelector(`.${P}-mlabel`)).color }; }, P); + assert.ok(during.first > 0 && during.after, JSON.stringify(during)); + assert.notEqual(during.label, during.rest, "a quiet label is in another ink"); + await page.locator(`#fig-seq button`, { hasText: "Stop the run" }).click(); + await frames(page, 3); + assert.equal(await page.locator(`#fig-seq [data-ahead]`).count(), 0); + await page.close(); + }); + + test("entrance: first-visit stores a mark when the entrance finishes, and the next visit is at rest", async () => { + const { page } = await reviewPage(); + // On a real (fake-host) origin, so localStorage works: the fixture's own page, served there. + const html = await page.evaluate(() => { document.getElementById("root").replaceChildren(); return `${document.documentElement.outerHTML}`; }); + await page.route("https://basalt.test/**", (route) => route.fulfill({ contentType: "text/html", body: html })); + await page.goto("https://basalt.test/"); + await page.evaluate(() => document.fonts.ready); + const spec = { ...B.architecture, motion: "animated", entrance: "first-visit" }; + await draw(page, [{ key: "arch", spec }]); + await page.waitForFunction(() => document.querySelector("#fig-arch").getAttribute("data-entrance") === "running"); + await page.evaluate(() => document.getAnimations().forEach((a) => a.finish())); + await page.waitForFunction(() => document.querySelector("#fig-arch").getAttribute("data-entrance") === "done"); + const key = await page.evaluate(() => Object.keys(localStorage).find((k) => k.startsWith("basalt-diagram-entrance:"))); + assert.ok(key && key.endsWith("#fig-arch"), String(key)); + await page.evaluate(() => window.__set([])); + await frames(page, 2); + await draw(page, [{ key: "arch", spec }]); + assert.equal(await page.locator("#fig-arch").getAttribute("data-entrance"), "done", "the second visit is at rest from its first frame"); + await page.close(); + }); +}); + +describe("right to left, every figure (Neon B12)", () => { + for (const theme of ["dark", "light"]) test(`${theme}: the five extended figures drawn right to left pass the merged geometry suite at 1104`, async () => { + const { page } = await reviewPage({ theme }); + const keys = ["architecture", "flowchart", "dataFlow", "sequence", "schema"]; + await draw(page, keys.map((k) => ({ key: k, spec: B[k], dir: "rtl" }))); + for (const k of keys) { + const g = await inspect(page, k); + assert.equal(g.layout, "drawn", k); + assert.deepEqual(g.problems, [], `${k}: ${JSON.stringify(g.problems)}`); + } + await page.close(); + }); +}); diff --git a/packages/react/test/diagram-sequence.test.mjs b/packages/react/test/diagram-sequence.test.mjs index 2a12729f..fa451237 100644 --- a/packages/react/test/diagram-sequence.test.mjs +++ b/packages/react/test/diagram-sequence.test.mjs @@ -1,10 +1,11 @@ // A sequence's activations and frames (DECISIONS 306, 1.2; section 8's list for diagram-sequence.test.mjs), on the extended CIMIP sequence -// (test/fixtures/cimip-diagrams-b.json). In Chromium against the built package, both themes. The text variant is not built yet, so its tests are not here. +// (test/fixtures/cimip-diagrams-b.json), and the text variant. In Chromium against the built package, both themes. // The implementation hasn't been reviewed. import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; import { after, before, describe, test } from "node:test"; +import { pathToFileURL } from "node:url"; import { fixturePage, launch, pkg } from "./support.mjs"; @@ -108,3 +109,55 @@ describe("frames", () => { await page.close(); }); }); + +describe("the text variant (1.2; section 8)", () => { + test("the art is byte-stable for fixed data, every frame has its four corners, and no lifeline glyph is inside a word", async () => { + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const text = await import(pathToFileURL(path.join(pkg, "dist", "diagram-text.js")).href); + const m = () => core.buildModel(B.textSequence); + const a = text.textArt(m()).html, b = text.textArt(m()).html; + assert.equal(a, b, "the same data writes the same art"); + const rows = a.replace(/<[^>]+>/g, "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").split("\n"); + const count = (c) => rows.join("").split(c).length - 1; + assert.equal(count("┌"), count("└"), "every frame that opens closes"); + assert.equal(count("┐"), count("┘")); + // A word (a label) is never cut by a lifeline glyph: each label is found whole on one row. + for (const st of B.textSequence.steps.flatMap(function flat(s) { return s.steps ? s.steps.flatMap(flat) : s.branches ? s.branches.flatMap((x) => x.steps.flatMap(flat)) : [s]; })) { + if (st.label) assert.ok(rows.some((r) => r.includes(st.label)), `"${st.label}" is whole`); + } + }); + + for (const width of [1440, 390, 360]) test(`at ${width} the block never scrolls sideways; the pre is aria-hidden; the key's swatches are glyphs`, async () => { + const { page } = await fixturePage(browser, ` +import data from "./test/fixtures/cimip-diagrams-b.json"; +const { type, ...props } = data.textSequence; +createRoot(document.getElementById("root")).render();`, { standards: true, viewport: { width, height: 1200 } }); + await page.addStyleTag({ content: "body{margin:0;padding:16px} #root{max-width:1104px;margin:0 auto}" }); + await page.evaluate(() => document.fonts.ready); + await frames(page, 6); + const got = await page.evaluate((P) => { + const pre = document.querySelector(`#text .${P}-text`); + const names = [...pre.querySelectorAll(`.${P}-tx-name`)].map((n) => n.getClientRects().length); + return { scroll: pre.scrollWidth - pre.clientWidth, hidden: pre.getAttribute("aria-hidden"), art: pre.hasAttribute("data-art"), broken: names.filter((n) => n > 1).length, swatches: document.querySelectorAll(`#text .${P}-swatch`).length, glyphs: document.querySelectorAll(`#text .${P}-key-glyph`).length }; + }, P); + assert.ok(got.scroll <= 1, JSON.stringify(got)); + assert.equal(got.hidden, "true"); + assert.equal(got.broken, 0, "no name breaks across lines"); + assert.equal(got.swatches, 0); + assert.ok(got.glyphs > 0); + if (width === 1440) assert.ok(got.art, "at 1440 the art fits"); + else assert.ok(!got.art, "on a phone, the transcript"); + await page.close(); + }); + + test("the bars: a bar left open closes at its participant's last message; development errors for a deactivate with no bar, a fourth bar and frames", async () => { + const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + const seq = (steps) => core.buildModel({ type: "sequence", title: "t", summary: "s", participants: [{ id: "a", name: "A" }, { id: "b", name: "B" }], steps }); + const open = seq([{ from: "a", to: "b", label: "1", activate: true }, { from: "a", to: "b", label: "2" }, { from: "b", to: "a", label: "3" }]); + assert.deepEqual(open.bars.map((x) => [x.who, x.from, x.to]), [["b", 1, 3]]); + assert.ok(seq([{ from: "a", to: "b", label: "1", deactivate: true }]).warnings.some((w) => /closes a bar on a, which has none open/.test(w))); + assert.ok(seq([1, 2, 3, 4].map((n) => ({ from: "a", to: "b", label: String(n), activate: true }))).warnings.some((w) => /fourth bar/.test(w))); + assert.ok(seq([{ frame: "alt", branches: [{ label: "one", steps: [{ from: "a", to: "b", label: "x" }] }] }]).warnings.some((w) => /alt frame has one branch/.test(w))); + assert.ok(seq([{ frame: "opt", label: "o", steps: [{ frame: "opt", label: "p", steps: [{ frame: "opt", label: "q", steps: [{ from: "a", to: "b", label: "x" }] }] }] }]).warnings.some((w) => /third level/.test(w))); + }); +}); diff --git a/packages/react/test/diagram-viewer.test.mjs b/packages/react/test/diagram-viewer.test.mjs index aceca0ba..51aacb5f 100644 --- a/packages/react/test/diagram-viewer.test.mjs +++ b/packages/react/test/diagram-viewer.test.mjs @@ -175,15 +175,19 @@ describe("the layout width and Fit", () => { } test("a figure with no drawn layout holds its stack, and a stack with no lines has its list open", async () => { const { page } = await viewerPage({ width: 1440, height: 900 }); - // Two cards whose one line would pass through a third: every drawn layout is refused, and the stack draws no lines. + // Seven cards in a row and five lines out of the first: every line passes through a card, so no drawn layout is used, and its stack would need a fifth + // end lane, so it draws no lines (Neon's B12: the earlier fixture was drawn, and the test passed either way). await page.evaluate(() => window.__set([{ key: "bad", type: "architecture", props: { title: "Refused", summary: "A figure with no drawn layout.", legend: { plain: "Call" }, - nodes: [{ id: "a", name: "A", col: 1, row: 1 }, { id: "b", name: "B", col: 2, row: 1 }, { id: "c", name: "C", col: 3, row: 1 }], - edges: [{ from: "a", to: "c", fromSide: "right", toSide: "left", kind: "plain" }] } }])); - await frames(page); - const pageLayout = await page.locator("#fig-bad").getAttribute("data-layout"); + nodes: Array.from({ length: 7 }, (_, k) => ({ id: `n${k}`, name: `N${k}`, col: k + 1, row: 1 })), + edges: [2, 3, 4, 5, 6].map((k) => ({ from: "n0", to: `n${k}`, kind: "plain" })) } }])); + await frames(page, 4); + assert.equal(await page.locator("#fig-bad").getAttribute("data-layout"), "stacked"); + assert.equal(await page.locator("#fig-bad").getAttribute("data-bare"), "", "the page's stack is bare"); await open(page, "bad"); const s = await state(page); - assert.equal(s.layout, pageLayout === "drawn" ? "drawn" : "stacked"); + assert.equal(s.layout, "stacked", "the viewer holds the stack"); + const list = await page.evaluate((P) => { const d = document.querySelector(`dialog.${P}-viewer`); const l = d.querySelector(`.${P}-viewer-list`); return { list: Boolean(l && !l.hidden && l.getClientRects().length), sizer: d.querySelector(`.${P}-sizer`).hidden }; }, P); + assert.deepEqual(list, { list: true, sizer: true }, "and a stack with no lines has its list open"); await page.close(); }); }); diff --git a/packages/tokens/test/contrast.test.mjs b/packages/tokens/test/contrast.test.mjs index f393267e..0dfd2a70 100644 --- a/packages/tokens/test/contrast.test.mjs +++ b/packages/tokens/test/contrast.test.mjs @@ -1059,3 +1059,37 @@ test("print: the token CSS ends with a print block that sets every light colour assert.ok(Object.keys(light).length > 50); for (const [name, value] of Object.entries(light)) assert.equal(print[name], value, `${name} in print`); }); + +// DECISIONS 306, 1.0 (Neon's B12 on the batch's code review): every colour in a new seat of batch B joins these tests on levels 0 to 3, in both themes and +// under more contrast. Cardinality marks are the line's own ink; an activation bar's edge is the structure role on its fill (the figure's level) and on the +// ground beside it; a frame's and a nested group's edges are the structure role; a quiet run's line is edge-dim; the text art's inks are on surface-sunken; +// a linked card's words hold on the press step (state-hover) over each level. +for (const theme of THEMES) { + const onLevels = LEVELS.map((n) => [n, color(theme, n)]); + test(`${theme}: batch B's seats: marks, a bar's edge, frames and nested groups, a quiet run, at 3:1 on levels 0 to 3 and under more contrast`, () => { + for (const name of ["diagram-edge-main", "diagram-edge", "diagram-edge-dim", "diagram-structure"]) { + atLeast(theme, name, 3, onLevels); + for (const [bgName, bg] of onLevels) assert.ok(ratio(over(more(theme, name), bg), bg) >= 3, `${theme}: ${name} on ${bgName} under more contrast`); + } + // A bar's fill is the figure's level (surface-1 on the page); its edge holds against that fill and against the page beside it. + const fill = color(theme, "surface-1"); + assert.ok(ratio(over(color(theme, "diagram-structure"), fill), fill) >= 3, `${theme}: a bar's edge on its fill`); + assert.ok(ratio(over(color(theme, "diagram-structure"), color(theme, "surface-0")), color(theme, "surface-0")) >= 3, `${theme}: a bar's edge on the ground`); + }); + test(`${theme}: the text art's inks on surface-sunken (tertiary, secondary, primary) hold 4.5:1, and under more contrast`, () => { + const sunken = [["surface-sunken", color(theme, "surface-sunken")]]; + for (const name of ["text-tertiary", "text-secondary", "text-primary"]) { + atLeast(theme, name, 4.5, sunken); + assert.ok(ratio(over(more(theme, name), sunken[0][1]), sunken[0][1]) >= 4.5, `${theme}: ${name} on surface-sunken under more contrast`); + } + }); + test(`${theme}: a linked card's words hold 4.5:1 on its press step (state-hover) over levels 0 to 3`, () => { + for (const [bgName, bg] of onLevels) { + const step = over(color(theme, "state-hover"), bg); + for (const name of ["text-primary", "text-secondary", "text-tertiary"]) { + const r = ratio(over(more(theme, name), step), step); + assert.ok(r >= 4.5 || (name === "text-tertiary" && ratio(over(color(theme, "text-secondary"), step), step) >= 4.5), `${theme}: ${name} on the press step over ${bgName} is ${fmt(r)}:1`); + } + } + }); +} diff --git a/tools/html-skill/test/diagrams.test.mjs b/tools/html-skill/test/diagrams.test.mjs index bf296f43..03a54f57 100644 --- a/tools/html-skill/test/diagrams.test.mjs +++ b/tools/html-skill/test/diagrams.test.mjs @@ -218,3 +218,21 @@ describe("behaviour", () => { assert.match(js, /diagramMarkup/); }); }); + +describe("batch B's fix round in the skill (Neon B8, B10)", () => { + const B = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams-b.json"), "utf8")); + test("an automatic figure's words are written on its placement before script: no two cards in one cell, and the columns are the placement's", () => { + const html = compose(`D
`).html; + const fig = /]*id="fig-a"[^>]*>/.exec(html)[0]; + assert.match(fig, /data-cols="(\d+)"/); + assert.notEqual(/data-cols="(\d+)"/.exec(fig)[1], "1"); + const cells = [...html.matchAll(/data-node="([^"]+)"[^>]*style="--_c:(\d+);--_r:(\d+)/g)].map((m) => `${m[2]},${m[3]}`); + assert.ok(cells.length >= 10, `${cells.length} cards`); + assert.equal(new Set(cells).size, cells.length, "no two cards in one cell"); + }); + test("a data flow step's mark counts its lane's label as its words, as React's check does", () => { + const spec = { type: "data-flow", title: "t", summary: "s", lanes: [{ id: "s3", label: "Amazon S3" }], nodes: [{ id: "n1", lane: "s3", col: 1, name: "Store logs", mark: "aws-s3-bucket" }], edges: [] }; + const out = compose(`D
`); + assert.ok(!JSON.stringify(out.diagrams ?? []).includes("none of its words say so"), JSON.stringify(out.diagrams)); + }); +}); From 19d23b20d22a020f4ecb9bfac5e5892f7958df84 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:35:37 -0600 Subject: [PATCH 50/62] Round 66: the extended data flow is still, so its shot shows every line Animated, its lines waited for the figure to come into view, and the shot caught them pending. The step says the batch line's dashes march where motion is asked for. Co-Authored-By: Claude Opus 5.5 --- tools/review/round66.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx index 4b54e10f..a9aa0209 100644 --- a/tools/review/round66.tsx +++ b/tools/review/round66.tsx @@ -54,7 +54,8 @@ const DATA_FLOW_PARTS: Inline = (() => { for (const n of d.nodes) if (n.id === "seg") n.mark = awsS3Bucket; // A dashed flow (1.5): the batch line's own dashes march. Two more lines make two cards entered by several end lines (1.3), seen stacked. d.edges = [...d.edges.map((e) => (e.kind === "dashed" ? { ...e, flow: true } : e)), { from: "append", to: "seal", label: "window check" }, { from: "hear", to: "seg", label: "cursor sync" }]; - return { ...d, title: "How one message reaches everyone in the room (extended)", motion: "animated", summary: `${String(d.summary)} Two more lines show several end lines entering one card when it is stacked.` }; + // Still, so the shot shows every line (an animated figure's lines wait until it comes into view); its flow marches where motion is asked for. + return { ...d, title: "How one message reaches everyone in the room (extended)", summary: `${String(d.summary)} Two more lines show several end lines entering one card when it is stacked.` }; })(); const schemaTable = (name: string, row: number, refs: string[] = []) => ({ name, col: 1, row, columns: [{ name: "id", key: "PK" }, ...refs.map((r) => ({ name: `${r}_id`, key: "FK", references: `${r}.id` }))] }); const CALL_2: Inline = { type: "schema", title: "One column: turn-backs beside each other take lanes (section 4, call 2)", summary: "b references c and c references a; their turn-backs run beside each other down the column's end side, so each takes a lane.", legend: { plain: "A foreign key" }, tables: [schemaTable("a", 1), schemaTable("b", 2, ["c"]), schemaTable("c", 3, ["a"])] }; @@ -245,7 +246,7 @@ export const ROUND_66: Round = { decisions: [ ...COMMON, "A step's mark (1.6) is 16px in its top end corner; the lane's label counts as the step's words, so \"S3\" says what the mark stands for.", - "A dashed flow (1.5): one period every 625ms, the dashes where the key draws them whenever they rest.", + "A dashed flow (1.5): one period every 625ms, the dashes where the key draws them whenever they rest. The figure here is still, so its lines show in the shot: with motion=\"animated\" the batch line's dashes march.", "Several end lines into one card (1.3): the outermost lane's line turns lowest and enters nearest the end edge; each further in turns space-5 higher and enters space-3 further in; their labels sit space-2-5 clear of the innermost entry, each on its own turn's height.", ], tryIt: ["Narrow to 390: the two cards entered by two end lines show the nesting and the labels' seats."], From 3b2d116883ef99340eac57283063bd8730765b64 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:41:46 -0600 Subject: [PATCH 51/62] Text art in the viewer: the glyph measured at 100%; the skill's rows not banded The art's character width was read with getBoundingClientRect after the viewer had put its zoom back on the layer, so at Fit the art was laid out for a width scaled by the zoom and cut off (both re-checks' B3/B2/R1). The probe is now one unbreakable inline-block run read with offsetWidth, which no transform scales, in React and the skill alike: the width is the same at every zoom. The skill's viewer banded every text row: the core's inline code rule (code:not(.code code)) gave the art's code element a chip fill and 0.92em. The art's code element is reset to the block's own text (P-R2 of the code re-check). The implementation hasn't been reviewed. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-figure.tsx | 4 +++- packages/react/src/styles/components.css | 4 +++- tools/html-skill/src/modules/diagram-text.js | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index c20d41cb..dee5c4ca 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -265,10 +265,12 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: let html = transcriptHtml, art = false; if (pre && textModule) { const made = textModule.textArt(model); + // A glyph's width at 100%: offsetWidth, which no transform scales (the viewer's layer is zoomed when this runs), on one unbreakable run. const probe = document.createElement("span"); + probe.style.cssText = "display:inline-block;white-space:pre"; probe.textContent = "─".repeat(40); pre.append(probe); - const cw = probe.getBoundingClientRect().width / 40; + const cw = probe.offsetWidth / 40; probe.remove(); const cs = getComputedStyle(pre); let room = pre.clientWidth - Number.parseFloat(cs.paddingLeft) - Number.parseFloat(cs.paddingRight); diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 33240f4d..d19a9210 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4863,7 +4863,9 @@ } .basalt-diagram-text[data-art] { white-space: pre; overflow-wrap: normal; } .basalt-diagram-drawing:has(> .basalt-diagram-text) { max-width: none; } - .basalt-diagram-text-ink { font: inherit; } + /* The art's code element is the block's text, never an inline code chip: a page's own code style (the skill's core gives inline code a fill) would band + every row (P-R2 of the code re-check). */ + .basalt-diagram-text .basalt-diagram-text-ink { font: inherit; padding: 0; border: 0; border-radius: 0; background: none; color: inherit; } .basalt-diagram-tx-name { white-space: nowrap; color: var(--basalt-text-primary); } /* A transcript's line (B6 of the pixel review): a block indented by its frame, its message's lines hanging under the sender. */ .basalt-diagram-tx-line { diff --git a/tools/html-skill/src/modules/diagram-text.js b/tools/html-skill/src/modules/diagram-text.js index 30335a08..1f692576 100644 --- a/tools/html-skill/src/modules/diagram-text.js +++ b/tools/html-skill/src/modules/diagram-text.js @@ -12,10 +12,12 @@ import { textArt } from "../../../../packages/react/src/diagram-text.ts"; if (!code) return; if (!figure.__transcript) figure.__transcript = code.innerHTML; var made = textArt(model); + // A glyph's width at 100%: offsetWidth, which no transform scales (the viewer's layer is zoomed when this runs), on one unbreakable run. var probe = document.createElement('span'); + probe.style.cssText = 'display:inline-block;white-space:pre'; probe.textContent = new Array(41).join('─'); pre.appendChild(probe); - var cw = probe.getBoundingClientRect().width / 40; + var cw = probe.offsetWidth / 40; probe.remove(); var cs = getComputedStyle(pre); var room = pre.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight); From e8b895d3153483bcd4cd1e37ccf5eecf7521c505 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:41:47 -0600 Subject: [PATCH 52/62] The bare stack is written: a stack with no lines is dressed bare and its list open The viewer's "bare stack" test failed as written at the re-check (Opus R2, P-R3), and the fault was the engine's. measureFigure's tries wrote each layout they tried; the bare stack was returned without being written, so the figure kept the last try's attributes (stacked, not bare, its list closed) and a host seeing a state equal to the one before rendered nothing. The bare state is now applied before it is returned. The fixture was right. The implementation hasn't been reviewed. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-core.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index c28e1748..d0ca91c7 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -2968,6 +2968,9 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin // Dressed as where scripting is off (1.13): no line in the key, no key hint, no stops, and the list open when the figure becomes bare. const bare: Geo = { ...geo, lines: [], labels: [], crossings: [] }; const dyn = stopOf({ ...d, grow: record(), bare: true, open: current.bare ? current.open : true, autoOpen: current.bare ? current.autoOpen : current.open ? undefined : true }); + // Written as it is returned: the tries above wrote a state that is not bare, and a host that sees the same state as before renders nothing, so the + // figure would keep their markup (a stack with no lines, not dressed bare, its list closed: P-R3 of the code re-check). + apply(dyn); return { dyn, geo: bare, ink: "", tokens: tk, least: mins.least }; } if (geo.crossings.length) dev && warn?.(`${geo.crossings.length} crossing${geo.crossings.length === 1 ? "" : "s"} in the stacked drawing (each is cut): ${geo.crossings.map((c) => `${lineName(m, geo.lines[c.top]!)} over ${lineName(m, geo.lines[c.under]!)}`).join("; ")}`); From dd7ca44c9112cee7e132f41db10e37ea7c183d5e Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:42:09 -0600 Subject: [PATCH 53/62] Ruling 1: 5.1's first list is an error, said once, and the figure draws as production draws it The decider's ruling on the batch B re-check: the 5.1 checks an author must fix (a group's unknown parent, a cycle or a third level; a band in a frame; a third frame level; an alt with one branch; a frame label over 40; an empty frame or branch; a break in a message's label; layout auto on a type without it; an href on a participant or an empty one; cardinality that is not a form, a referenced end of many, cardinality without references or on some keys and not all; a label with two breaks or a line over 28; a fourth bar; a deactivate with no bar; a stack that would need a fifth end lane; entrance first-visit without an id) go to Model.errors and are reported with console.error, once for a figure and message, in React and the skill (compose.mjs marks them "error: "). The second list stays console.warn. Motion's errors still throw. The markup is the same with the checks on or off. Tests: diagram-checks.test.mjs (node, run: 22 pass) proves each first-list item lands in errors and not warnings and the markup equals production's; the sequence and schema tests read errors now (browser files, written, not run). The implementation hasn't been reviewed. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-core.ts | 53 +++++++++------- packages/react/src/diagram-figure.tsx | 16 ++++- packages/react/test/diagram-checks.test.mjs | 62 +++++++++++++++++++ packages/react/test/diagram-schema.test.mjs | 4 +- packages/react/test/diagram-sequence.test.mjs | 10 +-- tools/html-skill/src/modules/diagram.js | 8 ++- 6 files changed, 117 insertions(+), 36 deletions(-) create mode 100644 packages/react/test/diagram-checks.test.mjs diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index d0ca91c7..73ae61d3 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -235,6 +235,8 @@ export interface Model { text?: boolean; /** A schema that draws cardinality marks (1.1): its column gap is space-12 plus space-3. */ marks?: boolean; + /** 5.1's first list, in a development build: reported as errors (console.error), the figure drawn as production draws it. */ + errors: string[]; } const SIDES: DiagramSide[] = ["top", "right", "bottom", "left"]; @@ -272,6 +274,9 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const checks = dev && options.checks !== false; const warnings: string[] = []; const warn = (message: string) => { warnings.push(message); }; + // 5.1's first list (the decider's ruling 1 on the re-check): reported as an error, once for a figure, and the figure is drawn as production draws it. + const errors: string[] = []; + const error = (message: string) => { errors.push(message); }; const legendIn = (spec.legend ?? {}) as Record; const legend: DiagramLegend = {}; for (const k of ["main", "plain", "dashed", "focal", "group", "activation"] as const) { const w = txt(legendIn[k]); if (w) legend[k] = w; } @@ -325,9 +330,9 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const depthOf = (g: (typeof raw)[number]): number => { if (!g.parent) return 1; const p = byGroup.get(g.parent); - if (!p) { dev && warn(`the group "${g.label}" names the parent "${g.parent}", which is not a group`); g.parent = undefined; return 1; } - if (p.parent === g.id || p.id === g.id) { dev && warn(`the groups "${g.label}" and "${p.label}" are each other's parent`); g.parent = undefined; return 1; } - if (p.parent) { dev && warn(`the group "${g.label}" is a third level: groups nest two deep`); g.parent = undefined; return 1; } + if (!p) { dev && error(`the group "${g.label}" names the parent "${g.parent}", which is not a group`); g.parent = undefined; return 1; } + if (p.parent === g.id || p.id === g.id) { dev && error(`the groups "${g.label}" and "${p.label}" are each other's parent`); g.parent = undefined; return 1; } + if (p.parent) { dev && error(`the group "${g.label}" is a third level: groups nest two deep`); g.parent = undefined; return 1; } return 2; }; const depths = raw.map(depthOf); @@ -361,22 +366,22 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model for (const s of list ?? []) { if (!s || typeof s !== "object") continue; if ("band" in s) { - if (depth > 0) dev && warn(`the band "${String(s.band)}" is inside a frame: a band is the whole figure's`); + if (depth > 0) dev && error(`the band "${String(s.band)}" is inside a frame: a band is the whole figure's`); steps.push({ band: String(s.band ?? "") }); continue; } if ("frame" in s) { - if (depth >= 2) { dev && warn("a frame is a third level: frames nest two deep"); continue; } + if (depth >= 2) { dev && error("a frame is a third level: frames nest two deep"); continue; } const op = s.frame === "alt" || s.frame === "loop" || s.frame === "opt" ? s.frame : "opt"; const branches = op === "alt" ? ((s as { branches?: Array<{ label: string; steps: SequenceStep[] }> }).branches ?? []) : [{ label: (s as { label: string }).label, steps: (s as { steps: SequenceStep[] }).steps }]; - if (op === "alt" && branches.length < 2) dev && warn("an alt frame has one branch: it needs two or more"); + if (op === "alt" && branches.length < 2) dev && error("an alt frame has one branch: it needs two or more"); const label = String(branches[0]?.label ?? ""); - if (label.length > 40) dev && warn(`the frame label "${label}" is over 40 characters`); + if (label.length > 40) dev && error(`the frame label "${label}" is over 40 characters`); const at = steps.length; steps.push({ open: op, label, depth: depth + 1, a: 0, b: 0 }); branches.forEach((br, k) => { - if (k) { const l = String(br.label ?? ""); if (l.length > 40) dev && warn(`the frame label "${l}" is over 40 characters`); steps.push({ otherwise: l, depth: depth + 1 }); } - if (!br.steps?.length) dev && warn(`a frame or branch ("${String(br.label ?? "")}") is empty`); + if (k) { const l = String(br.label ?? ""); if (l.length > 40) dev && error(`the frame label "${l}" is over 40 characters`); steps.push({ otherwise: l, depth: depth + 1 }); } + if (!br.steps?.length) dev && error(`a frame or branch ("${String(br.label ?? "")}") is empty`); const [x, y] = walk(br.steps ?? [], depth + 1); a = Math.min(a, x); b = Math.max(b, y); const open = steps[at] as { a: number; b: number }; @@ -388,7 +393,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model n++; const label = String(s.label ?? ""); // A message's second line is its note (1.4): a break in its label is an error, and it is drawn on one line. - if (label.includes("\n")) dev && warn(`message ${n}'s label has a break: a message's second line is its note`); + if (label.includes("\n")) dev && error(`message ${n}'s label has a break: a message's second line is its note`); const from = String(s.from ?? ""), to = String(s.to ?? ""); steps.push({ n, from, to, label: said(label), note: txt(s.note), kind: kindOf(s.kind, `message ${n}`), activate: s.activate === true || undefined, deactivate: s.deactivate === true || undefined }); const ca = colOf.get(from) ?? 1, cb = colOf.get(to) ?? 1; @@ -441,14 +446,14 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const inside = nodes.filter((n) => !g.all.includes(n.id) && n.col >= c1 && n.col <= c2 && n.row >= r1 && n.row <= r2); if (inside.length) { unplaced = true; dev && warn(`the placement puts ${inside.map((n) => n.id).join(", ")} inside the box of the group "${g.label}", so it is not used`); } } - } else if (spec.layout === "auto") dev && warn(`layout="auto" is for an architecture, a flowchart or a schema, not a ${type}`); + } else if (spec.layout === "auto") dev && error(`layout="auto" is for an architecture, a flowchart or a schema, not a ${type}`); // Link cards (1.4): any card but a sequence's participant (its stacked chip has no room for a 44px target). const rawCards = (type === "schema" ? spec.tables : type === "sequence" ? spec.participants : spec.nodes) as Array<{ href?: unknown; target?: unknown }> | undefined; (rawCards ?? []).forEach((raw, k) => { if (!raw || raw.href === undefined || raw.href === null) return; const href = String(raw.href); - if (type === "sequence") { dev && warn(`${nodes[k]?.id}: a participant cannot be a link (href)`); return; } - if (!href.trim()) { dev && warn(`${nodes[k]?.id}'s href is empty`); return; } + if (type === "sequence") { dev && error(`${nodes[k]?.id}: a participant cannot be a link (href)`); return; } + if (!href.trim()) { dev && error(`${nodes[k]?.id}'s href is empty`); return; } const n = nodes[k]; if (n) { n.href = href; n.blank = raw.target === "_blank"; } }); @@ -465,16 +470,16 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model if (v === undefined || v === null) return undefined; const o = v as { from?: unknown; to?: unknown }; const from = CARDS.includes(o.from as DiagramCardinality) ? (o.from as DiagramCardinality) : undefined; - if (!from) { dev && warn(`${where}'s cardinality "from" is ${JSON.stringify(o.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`); return undefined; } + if (!from) { dev && error(`${where}'s cardinality "from" is ${JSON.stringify(o.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`); return undefined; } if (o.to === undefined || o.to === null) return { from, to: "one" }; if (o.to === "one" || o.to === "zero-or-one") return { from, to: o.to }; // A foreign key points at one row at most. - dev && warn(`${where}'s cardinality "to" is ${JSON.stringify(o.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`); + dev && error(`${where}'s cardinality "to" is ${JSON.stringify(o.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`); return { from, to: "one" }; }; (spec.tables ?? []).forEach((t) => (t.columns ?? []).forEach((c, k) => { const ref = txt(c.references); - if (!ref && c.cardinality !== undefined && c.cardinality !== null) dev && warn(`${String(t.name)}.${String(c.name)} states a cardinality but references nothing`); + if (!ref && c.cardinality !== undefined && c.cardinality !== null) dev && error(`${String(t.name)}.${String(c.name)} states a cardinality but references nothing`); if (!ref) return; const [table, column] = ref.split("."); const target = byId.get(table ?? ""); @@ -488,15 +493,15 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model })); // All of a figure's foreign keys state how many, or none (1.1). In production an unstated line draws as today, and the key shows both. const stated = edges.filter((e) => e.card).length; - if (stated && stated < edges.length) dev && warn(`cardinality is stated on ${stated} of ${edges.length} foreign keys: state it on every one or none (${edges.filter((e) => !e.card).map((e) => `${e.from}.${byId.get(e.from)!.columns![e.fromRow!]!.name}`).join(", ")} ${edges.length - stated === 1 ? "has" : "have"} none)`); + if (stated && stated < edges.length) dev && error(`cardinality is stated on ${stated} of ${edges.length} foreign keys: state it on every one or none (${edges.filter((e) => !e.card).map((e) => `${e.from}.${byId.get(e.from)!.columns![e.fromRow!]!.name}`).join(", ")} ${edges.length - stated === 1 ? "has" : "have"} none)`); } else if (type !== "sequence") { for (const e of spec.edges ?? []) { const from = String(e.from ?? ""), to = String(e.to ?? ""); if (!byId.has(from) || !byId.has(to)) { dev && warn(`a line names ${!byId.has(from) ? from : to}, which is not a node`); continue; } const label = txt(e.label); const lines = label?.split("\n") ?? []; - if (lines.length > 2) dev && warn(`the label "${said(label!)}" has more than one break: a label is two lines at most`); - if (lines.some((l) => l.length > MAX_LABEL)) dev && warn(`a line of the label "${said(label!)}" is over ${MAX_LABEL} characters: longer words belong in the node or the summary`); + if (lines.length > 2) dev && error(`the label "${said(label!)}" has more than one break: a label is two lines at most`); + if (lines.some((l) => l.length > MAX_LABEL)) dev && error(`a line of the label "${said(label!)}" is over ${MAX_LABEL} characters: longer words belong in the node or the summary`); edges.push({ i: edges.length, from, to, kind: kindOf(e.kind, `the line from ${from} to ${to}`), label, fromSide: sideOf(e.fromSide), toSide: sideOf(e.toSide), flow: type !== "flowchart" && (e as DiagramFlowEdge).flow === true ? true : undefined }); } } else if (dev) { @@ -563,13 +568,13 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model if (!("n" in st)) continue; if (st.activate) { const stack = open.get(st.to) ?? []; - if (stack.length >= 3) dev && warn(`message ${st.n} opens a fourth bar on ${st.to}: three deep at most`); + if (stack.length >= 3) dev && error(`message ${st.n} opens a fourth bar on ${st.to}: three deep at most`); else { const bar = { who: st.to, from: st.n, to: st.n, depth: stack.length + 1 }; stack.push(bar); bars.push(bar); open.set(st.to, stack); } } if (st.deactivate) { const stack = open.get(st.from); const top = stack?.pop(); - if (!top) dev && warn(`message ${st.n} closes a bar on ${st.from}, which has none open`); + if (!top) dev && error(`message ${st.n} closes a bar on ${st.from}, which has none open`); else top.to = st.n; } } @@ -590,7 +595,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model cols = Math.max(1, placed?.cols ?? 1, ...nodes.map((n) => n.col)); } const rows = type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, placed?.rows ?? 1, ...nodes.map((n) => n.row2)); - const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined, text: (type === "sequence" && spec.variant === "text") || undefined, marks: edges.some((e) => e.card) || undefined }; + const model: Model = { type, title: String(spec.title ?? ""), heading: heading as Model["heading"], legend, nodes, byId, edges, groups, lanes, steps, bars, frameWords, cols, rows, shapeLabels, stepWord, warnings, errors, motion, memo: new Map(), rtl: options.rtl || undefined, unplaced: unplaced || undefined, text: (type === "sequence" && spec.variant === "text") || undefined, marks: edges.some((e) => e.card) || undefined }; if (spec.layout === "auto" && !unplaced && type !== "schema") chooseSides(model); if (checks) for (const [id, h0] of Object.entries(portFloors(model))) if (h0 >= 48) warn(`${id} grows to ${h0}px to hold the lines on one side: use another side`); // A figure with no cells yet (an automatic one before its placement) has no spatial keys to check. @@ -2838,7 +2843,7 @@ export interface Measured { dyn: Dyn; geo: Geo | null; ink: string; tokens: Toke * word, every label seats and no line passes through a node; otherwise the stack. `apply` writes a state into the DOM (the same markup the * tree gives for it), so each try is measured as it would be drawn. */ -export function measureFigure(fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn?: (s: string) => void, sizeTo?: (least: number) => void): Measured { +export function measureFigure(fig: HTMLElement, m: Model, P: string, base: string, current: Dyn, apply: (dyn: Dyn) => void, warn?: (s: string, level?: "error") => void, sizeTo?: (least: number) => void): Measured { // Development only (the warnings): first, so a minifier sees it is a constant and drops what it guards. const dev = process.env.NODE_ENV !== "production"; const drawing = fig.querySelector(`.${P}-drawing`); @@ -2964,7 +2969,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin if (geo.unseated.length) dev && warn?.(`the stacked drawing has no clean seat for ${[...new Set(geo.unseated)].map((k) => `"${said(m.edges[k]?.label ?? "")}"`).join(", ")}, so its lines are not drawn; the list holds every connection`); if (geo.through.length) dev && warn?.(`in the stacked drawing ${names(geo, geo.through)} would pass through a node, so its lines are not drawn`); if (geo.outside.length) dev && warn?.(`in the stacked drawing ${names(geo, geo.outside)} would leave the drawing, so its lines are not drawn`); - if (dev && plan.third) warn?.("the stacked drawing would need a fifth end lane, so its lines are not drawn"); + if (dev && plan.third) warn?.("the stacked drawing would need a fifth end lane, so its lines are not drawn", "error"); // Dressed as where scripting is off (1.13): no line in the key, no key hint, no stops, and the list open when the figure becomes bare. const bare: Geo = { ...geo, lines: [], labels: [], crossings: [] }; const dyn = stopOf({ ...d, grow: record(), bare: true, open: current.bare ? current.open : true, autoOpen: current.bare ? current.autoOpen : current.open ? undefined : true }); diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index dee5c4ca..0273b7a6 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -147,6 +147,14 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const [dirAt, setDirAt] = React.useState(0); // The reasons last warned when no direction draws (DECISIONS 322, rule 5): a new width with the same reasons is not a new warning. const autoWarned = React.useRef(null); + // The errors this figure has reported, so each is said once for it. + const errored = React.useRef | null>(null); + const errorOnce = React.useCallback((message: string) => { + errored.current ??= new Set(); + if (errored.current.has(message)) return; + errored.current.add(message); + console.error(`Basalt ${component}: ${message}`); + }, [component]); // The viewer's figure takes the placements this figure has (DECISIONS 306, 8.4: elk runs once a direction), loaded ones included (DECISIONS 322). const viewerSpec = React.useMemo(() => (auto && !given.length && loaded ? { ...spec, placement: loaded } : spec), [auto, given, loaded, spec]); const placementFor = React.useCallback((k: number) => placements.find((p) => p.direction === order[k]), [placements, order]); @@ -189,7 +197,9 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // Development only: a bundler that sets NODE_ENV to production drops this block, strings included. React.useEffect(() => { if (process.env.NODE_ENV !== "production") for (const w of model.warnings) warnOnce(component, w); - if (process.env.NODE_ENV !== "production" && model.motion.firstVisit && !props.id) warnOnce(component, 'entrance="first-visit" needs an id: without one the entrance plays on every visit'); + // 5.1's first list is an error (the decider's ruling 1): console.error, once for this figure and the message; the figure is drawn as production draws it. + if (process.env.NODE_ENV !== "production") for (const e of model.errors) errorOnce(e); + if (process.env.NODE_ENV !== "production" && model.motion.firstVisit && !props.id) errorOnce('entrance="first-visit" needs an id: without one the entrance plays on every visit'); }, [model, component, props.id]); const measure = React.useCallback(() => { @@ -255,7 +265,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: } if (pick !== dirAt) { setDirAt(pick); return; } } - const warn = process.env.NODE_ENV !== "production" ? (message: string) => warnOnce(component, message) : undefined; + const warn = process.env.NODE_ENV !== "production" ? (message: string, level?: "error") => (level === "error" ? errorOnce(message) : warnOnce(component, message)) : undefined; const apply = (d: Dyn) => syncAttributes(fig, figureTree(model, d, options)); const result = (viewer ? viewer.measure : measureFigure)(fig, model, P, base, dynRef.current, apply, warn); // The text variant (1.2): the art where its widest line fits the block, the transcript otherwise; the art's module loads the first time. @@ -294,7 +304,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // A figure hidden (the viewer's list is open) was not measured: the viewer keeps the drawing's size and place it had. A text figure's art is in the DOM // only once React has written it, so its size is read after that (below). if (viewer && result.tokens && !model.text) viewer.onMeasured(result, fig); - }, [model, base, options, component, viewer, rtl, auto, given, loaded, placements, order, placementFor, dirAt, spec, textModule, transcriptHtml]); + }, [model, base, options, component, viewer, rtl, auto, given, loaded, placements, order, placementFor, dirAt, spec, textModule, transcriptHtml, errorOnce]); // The viewer's text figure (9.3): its size is read once React has written the art it measured, so the zoom fits the art and not the transcript. React.useLayoutEffect(() => { diff --git a/packages/react/test/diagram-checks.test.mjs b/packages/react/test/diagram-checks.test.mjs new file mode 100644 index 00000000..ceb9b72b --- /dev/null +++ b/packages/react/test/diagram-checks.test.mjs @@ -0,0 +1,62 @@ +// 5.1's development checks after the decider's ruling 1 on the batch B re-check: the first list is reported as an error (Model.errors, which the figure +// reports with console.error once and the skill with console.error), the second as a warning, and the figure is drawn as production draws it: the same +// markup with the checks on or off. Node only: the engine's model and its markup, from the built package. The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import path from "node:path"; +import { test } from "node:test"; +import { pathToFileURL } from "node:url"; + +const pkg = path.join(path.dirname(new URL(import.meta.url).pathname), ".."); +const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); + +const seq = (steps, extra = {}) => ({ type: "sequence", title: "t", summary: "s", participants: [{ id: "a", name: "A" }, { id: "b", name: "B" }], steps, ...extra }); +const arch = (extra) => ({ type: "architecture", title: "t", summary: "s", nodes: [{ id: "a", name: "A", col: 1, row: 1 }, { id: "b", name: "B", col: 2, row: 1 }], edges: [], ...extra }); +const schema = (columns) => ({ type: "schema", title: "t", summary: "s", tables: [{ name: "a", col: 1, row: 1, columns }, { name: "b", col: 2, row: 1, columns: [{ name: "id", key: "PK" }, { name: "k" }] }] }); + +// Each item of 5.1's first list, with the words its error says. +const FIRST = [ + ["cardinality without references", schema([{ name: "x", cardinality: { from: "one" } }]), /states a cardinality but references nothing/], + ["a cardinality that is not a form", schema([{ name: "x", key: "FK", references: "b.id", cardinality: { from: "many" } }]), /not one, zero-or-one, one-or-many or zero-or-many/], + ["a referenced end of many", schema([{ name: "x", key: "FK", references: "b.id", cardinality: { from: "one", to: "one-or-many" } }]), /references one row at most/], + ["cardinality on some keys and not all", schema([{ name: "x", key: "FK", references: "b.id", cardinality: { from: "one" } }, { name: "y", key: "FK", references: "b.k" }]), /stated on 1 of 2 foreign keys/], + ["a deactivate with no open bar", seq([{ from: "a", to: "b", label: "x", deactivate: true }]), /has none open/], + ["a fourth nested bar", seq([1, 2, 3, 4].map((n) => ({ from: "a", to: "b", label: String(n), activate: true }))), /fourth bar/], + ["an alt with one branch", seq([{ frame: "alt", branches: [{ label: "one", steps: [{ from: "a", to: "b", label: "x" }] }] }]), /one branch/], + ["an empty frame", seq([{ frame: "opt", label: "o", steps: [] }]), /is empty/], + ["a third frame level", seq([{ frame: "opt", label: "o", steps: [{ frame: "opt", label: "p", steps: [{ frame: "opt", label: "q", steps: [{ from: "a", to: "b", label: "x" }] }] }] }]), /frame is a third level/], + ["a band in a frame", seq([{ frame: "opt", label: "o", steps: [{ band: "phase" }, { from: "a", to: "b", label: "x" }] }]), /is inside a frame/], + ["a frame label past 40 characters", seq([{ frame: "opt", label: "x".repeat(41), steps: [{ from: "a", to: "b", label: "x" }] }]), /over 40 characters/], + ["a third group level", arch({ groups: [{ id: "g", label: "G" }, { id: "h", label: "H", parent: "g" }, { id: "i", label: "I", parent: "h" }] }), /is a third level: groups nest two deep/], + ["an unknown parent", arch({ groups: [{ id: "g", label: "G", parent: "nope" }] }), /which is not a group/], + ["a cycle of groups", arch({ groups: [{ id: "g", label: "G", parent: "h" }, { id: "h", label: "H", parent: "g" }] }), /each other's parent/], + ["a label with two breaks", arch({ edges: [{ from: "a", to: "b", label: "one\ntwo\nthree" }] }), /more than one break/], + ["a label line past 28 characters", arch({ edges: [{ from: "a", to: "b", label: "x".repeat(29) }] }), /over 28 characters/], + ["a break in a sequence's label", seq([{ from: "a", to: "b", label: "one\ntwo" }]), /label has a break/], + ["an empty href", arch({ nodes: [{ id: "a", name: "A", col: 1, row: 1, href: " " }] }), /href is empty/], + ["an href on a participant", seq([{ from: "a", to: "b", label: "x" }], { participants: [{ id: "a", name: "A", href: "#x" }, { id: "b", name: "B" }] }), /cannot be a link/], + ["layout auto on a sequence", seq([{ from: "a", to: "b", label: "x" }], { layout: "auto" }), /layout="auto" is for/], +]; + +for (const [what, spec, words] of FIRST) test(`5.1's first list: ${what} is an error, not a warning, and the markup is production's`, () => { + const m = core.buildModel(spec); + assert.equal(m.errors.filter((e) => words.test(e)).length, 1, `${what}: ${JSON.stringify(m.errors)}`); + assert.ok(!m.warnings.some((w) => words.test(w)), `${what} is not also a warning`); + const html = (model) => core.toHtml(core.figureTree(model, {}, { prefix: "basalt-diagram", base: "dg1", hasSource: false, hiddenClass: "basalt-visually-hidden" })); + assert.equal(html(m), html(core.buildModel(spec, { checks: false })), "drawn as production draws it"); +}); + +test("5.1's second list stays a warning: a far key not drawn, a card grown to hold its ports, more than 100 cards", () => { + const n = (id, col, row) => ({ id, name: id, kind: "part", col, row }); + const grown = core.buildModel({ type: "architecture", title: "t", summary: "s", nodes: [n("a", 1, 1), n("b", 2, 1), n("c", 2, 2), n("d", 2, 3)], edges: [{ from: "a", to: "b" }, { from: "a", to: "c" }, { from: "a", to: "d" }] }); + assert.ok(grown.warnings.some((w) => /use another side/.test(w))); + assert.deepEqual(grown.errors, []); + const big = core.buildModel({ type: "architecture", title: "t", summary: "s", nodes: Array.from({ length: 101 }, (_, k) => n(`n${k}`, (k % 10) + 1, Math.floor(k / 10) + 1)), edges: [] }); + assert.ok(big.warnings.some((w) => /101 cards/.test(w))); + assert.deepEqual(big.errors, []); +}); + +test("the extended CIMIP figures report no error", async () => { + const fs = await import("node:fs"); + const B = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams-b.json"), "utf8")); + for (const [key, spec] of Object.entries(B)) assert.deepEqual(core.buildModel(spec).errors, [], key); +}); diff --git a/packages/react/test/diagram-schema.test.mjs b/packages/react/test/diagram-schema.test.mjs index 469463f4..ae67ea88 100644 --- a/packages/react/test/diagram-schema.test.mjs +++ b/packages/react/test/diagram-schema.test.mjs @@ -351,7 +351,8 @@ describe("modes", () => { describe("development errors", () => { test("cardinality without references, a referenced end of many, and some keys stated and not all", async () => { const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); - const warns = (tables) => core.buildModel(schema(tables)).warnings; + // 5.1's first list: errors (Model.errors, which the figure reports with console.error), never warnings (the decider's ruling 1 on the re-check). + const warns = (tables) => core.buildModel(schema(tables)).errors; const b = table("b", 2, 1, [col("id", { key: "PK" })]); assert.ok(warns([table("a", 1, 1, [{ name: "x", cardinality: { from: "one" } }]), b]).some((w) => /a\.x states a cardinality but references nothing/.test(w))); assert.ok(warns([table("a", 1, 1, [fk("x", "b.id", "one", "one-or-many")]), b]).some((w) => /references one row at most/.test(w))); @@ -359,6 +360,7 @@ describe("development errors", () => { assert.ok(warns([table("a", 1, 1, [fk("x", "b.id", "many")]), b]).some((w) => /not one, zero-or-one, one-or-many or zero-or-many/.test(w))); // None of them in a figure that states every key. assert.deepEqual(core.buildModel(B.schema).warnings, []); + assert.deepEqual(core.buildModel(B.schema).errors, []); // The referenced end defaults to one. assert.deepEqual(core.buildModel(schema([table("a", 1, 1, [fk("x", "b.id", "zero-or-many")]), b])).edges[0].card, { from: "zero-or-many", to: "one" }); }); diff --git a/packages/react/test/diagram-sequence.test.mjs b/packages/react/test/diagram-sequence.test.mjs index fa451237..40e3d62a 100644 --- a/packages/react/test/diagram-sequence.test.mjs +++ b/packages/react/test/diagram-sequence.test.mjs @@ -150,14 +150,14 @@ createRoot(document.getElementById("root")).render( { + test("the bars: a bar left open closes at its participant's last message; development errors (Model.errors, the figure's console.error) for a deactivate with no bar, a fourth bar and frames", async () => { const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); const seq = (steps) => core.buildModel({ type: "sequence", title: "t", summary: "s", participants: [{ id: "a", name: "A" }, { id: "b", name: "B" }], steps }); const open = seq([{ from: "a", to: "b", label: "1", activate: true }, { from: "a", to: "b", label: "2" }, { from: "b", to: "a", label: "3" }]); assert.deepEqual(open.bars.map((x) => [x.who, x.from, x.to]), [["b", 1, 3]]); - assert.ok(seq([{ from: "a", to: "b", label: "1", deactivate: true }]).warnings.some((w) => /closes a bar on a, which has none open/.test(w))); - assert.ok(seq([1, 2, 3, 4].map((n) => ({ from: "a", to: "b", label: String(n), activate: true }))).warnings.some((w) => /fourth bar/.test(w))); - assert.ok(seq([{ frame: "alt", branches: [{ label: "one", steps: [{ from: "a", to: "b", label: "x" }] }] }]).warnings.some((w) => /alt frame has one branch/.test(w))); - assert.ok(seq([{ frame: "opt", label: "o", steps: [{ frame: "opt", label: "p", steps: [{ frame: "opt", label: "q", steps: [{ from: "a", to: "b", label: "x" }] }] }] }]).warnings.some((w) => /third level/.test(w))); + assert.ok(seq([{ from: "a", to: "b", label: "1", deactivate: true }]).errors.some((w) => /closes a bar on a, which has none open/.test(w))); + assert.ok(seq([1, 2, 3, 4].map((n) => ({ from: "a", to: "b", label: String(n), activate: true }))).errors.some((w) => /fourth bar/.test(w))); + assert.ok(seq([{ frame: "alt", branches: [{ label: "one", steps: [{ from: "a", to: "b", label: "x" }] }] }]).errors.some((w) => /alt frame has one branch/.test(w))); + assert.ok(seq([{ frame: "opt", label: "o", steps: [{ frame: "opt", label: "p", steps: [{ frame: "opt", label: "q", steps: [{ from: "a", to: "b", label: "x" }] }] }] }]).errors.some((w) => /third level/.test(w))); }); }); diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 04a2f6c8..421332a2 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -38,7 +38,7 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, var tree = figureTree(model, {}, options(base, spec, viewer)); var html = toHtml(tree, slots(model, spec, base, false)); var open = html.indexOf('>'); - return { open: html.slice(0, open + 1), inner: html.slice(open + 1, html.length - ''.length), warnings: model.warnings }; + return { open: html.slice(0, open + 1), inner: html.slice(open + 1, html.length - ''.length), warnings: model.errors.map(function (e) { return 'error: ' + e; }).concat(model.warnings) }; } // The attributes the figure's markup sets on the figure itself; a redraw clears them before it writes the new ones. @@ -84,13 +84,15 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figure.insertAdjacentHTML('beforeend', made.inner); } model.warnings.forEach(function (w) { console.warn('Basalt diagram: ' + w); }); - if (model.motion.animated && model.motion.firstVisit && !figure.id) console.warn('Basalt diagram: "entrance": "first-visit" needs an id on the figure: without one the entrance plays on every visit'); + // 5.1's first list is an error (the decider's ruling 1 on the re-check): console.error, and the figure is drawn as it would be anyway. + model.errors.forEach(function (e) { console.error('Basalt diagram: ' + e); }); + if (model.motion.animated && model.motion.firstVisit && !figure.id) console.error('Basalt diagram: "entrance": "first-visit" needs an id on the figure: without one the entrance plays on every visit'); var opts = options(base, spec, viewer); var state = {}; var measured = null; var focusTrace = null, hoverTrace = null, touchTrace = null; var warned = Object.create(null); - var warn = function (m) { if (!warned[m]) { warned[m] = 1; console.warn('Basalt diagram: ' + m); } }; + var warn = function (m, level) { if (!warned[m]) { warned[m] = 1; (level === 'error' ? console.error : console.warn)('Basalt diagram: ' + m); } }; var apply = function (d) { syncAttributes(figure, figureTree(model, d, opts)); }; var ink = figure.querySelector('.diagram-ink'); var toggle = figure.querySelector('.diagram-toggle'); From c376b40343d75729a6022443238c09e113e0f4e0 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:42:11 -0600 Subject: [PATCH 54/62] Ruling 2: elkjs is one copy, a build input at exactly 0.12.1 The decider's ruling on the batch B re-check: elkjs moves from dependencies to devDependencies, pinned exactly at 0.12.1, and ships only as dist/diagram-elk.js with its licence (dist/elkjs/LICENSE.md); an app no longer installs a second copy. The owner's approval stays where the lint sees it: dependencies.allowed.json keeps the entry, with its reason updated, and a new $copied block names the packages whose file is copied into dist. check-deps.mjs (engineering, no pixel changes) counts a copied package as used when its devDependency is that exact version, and fails when the two drift, so the entry is never called stale. The notice drops "also listed among the package's dependencies". verify-packages.mjs places an automatic figure from the packed package with elkjs removed from the consumer's node_modules (part of npm run check: written, not run). Ran: npm run lint (the allowlist step passes), audit-fix-c8.test.mjs (check-deps, node: pass). The implementation hasn't been reviewed. Co-Authored-By: Claude Opus 5.5 --- dependencies.allowed.json | 8 ++++++-- package-lock.json | 3 ++- packages/react/THIRD-PARTY-NOTICES.md | 4 ++-- packages/react/package.json | 2 +- scripts/check-deps.mjs | 9 ++++++++- scripts/verify-packages.mjs | 11 +++++++++++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/dependencies.allowed.json b/dependencies.allowed.json index 419cf884..b0a0ed36 100644 --- a/dependencies.allowed.json +++ b/dependencies.allowed.json @@ -6,7 +6,7 @@ "@phosphor-icons/react": "The web icon set (foundations: Icons).", "@srasyndicate/basalt-tokens": "Basalt's own tokens.", "shiki": "CodeBlock syntax highlighting; loaded on demand, one grammar at a time.", - "elkjs": "Automatic diagram layout (`layout=\"auto\"`), loaded on demand through `diagram-layout` and never from the index. EPL-2.0 OR GPL-3.0-or-later; used under EPL-2.0, unmodified. The owner approved it (DECISIONS 301).", + "elkjs": "Automatic diagram layout (`layout=\"auto\"`), loaded on demand through `diagram-layout` and never from the index. EPL-2.0 OR GPL-3.0-or-later; used under EPL-2.0, unmodified. The owner approved it (DECISIONS 301). A build input, not a dependency: its file is copied, unchanged, into dist/diagram-elk.js with its licence (dist/elkjs/LICENSE.md), the one copy the package ships (the decider's ruling 2 on the batch B re-check); it is listed in $copied, pinned.", "react": "Peer: the host app's React.", "react-dom": "Peer: the host app's React DOM." }, @@ -17,5 +17,9 @@ } }, "packages/tokens": {}, - "Package.swift": {} + "Package.swift": {}, + "$copied": { + "$comment": "Approved packages whose file is copied into a package's dist (they are devDependencies, so the lint would call their entry stale): each pinned to the exact version the copy was made from. scripts/check-deps.mjs fails when the devDependency is gone or drifts.", + "packages/react": { "elkjs": "0.12.1" } + } } diff --git a/package-lock.json b/package-lock.json index 105e0bbf..9c156874 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3543,6 +3543,7 @@ "version": "0.12.1", "resolved": "https://registry.npmjs.org/elkjs/-/elkjs-0.12.1.tgz", "integrity": "sha512-IhMYKHE4S2vtx0QrhBP3lYOIKDeIiJXBrdq9MGYkuB8ZHqhrBnHNfSUndjXFewrX1CPK8chwq+2NA0K0hliYuw==", + "dev": true, "license": "EPL-2.0 OR GPL-3.0-or-later" }, "node_modules/emoji-regex": { @@ -6344,13 +6345,13 @@ "@phosphor-icons/react": "2.1.10", "@srasyndicate/basalt-tokens": "0.1.0", "cmdk": "1.1.1", - "elkjs": "0.12.1", "shiki": "4.6.0" }, "devDependencies": { "@types/react": "19.3.0", "@types/react-dom": "19.3.0", "axe-core": "4.14.0", + "elkjs": "0.12.1", "esbuild": "0.28.2", "geist": "1.9.0", "playwright": "1.63.0", diff --git a/packages/react/THIRD-PARTY-NOTICES.md b/packages/react/THIRD-PARTY-NOTICES.md index 3271e2b4..f7ef38c1 100644 --- a/packages/react/THIRD-PARTY-NOTICES.md +++ b/packages/react/THIRD-PARTY-NOTICES.md @@ -4,8 +4,8 @@ `@srasyndicate/basalt/diagram-layout` (automatic diagram layout, DECISIONS 306, 1.8) imports [elkjs](https://github.com/kieler/elkjs) 0.12.1, the Eclipse Layout Kernel compiled to JavaScript, unmodified. Its file, `lib/elk.bundled.js`, is copied unchanged into this package as -`dist/diagram-elk.js` (inside a small module wrapper), and its licence is beside it in `dist/elkjs/LICENSE.md`. elkjs is also listed among the -package's dependencies, for the build and for placing at build time. +`dist/diagram-elk.js` (inside a small module wrapper), and its licence is beside it in `dist/elkjs/LICENSE.md`. That file is the one copy +the package ships: elkjs is a build input of the package (a development dependency), not a dependency an app installs. - Licence: EPL-2.0 OR GPL-3.0-or-later. Basalt uses it under the Eclipse Public License 2.0 (https://www.eclipse.org/legal/epl-2.0/). - Source: https://github.com/kieler/elkjs (the Eclipse Layout Kernel's own source: https://github.com/eclipse/elk). diff --git a/packages/react/package.json b/packages/react/package.json index 0f240054..647c7cb7 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -63,13 +63,13 @@ "@phosphor-icons/react": "2.1.10", "@srasyndicate/basalt-tokens": "0.1.0", "cmdk": "1.1.1", - "elkjs": "0.12.1", "shiki": "4.6.0" }, "devDependencies": { "@types/react": "19.3.0", "@types/react-dom": "19.3.0", "axe-core": "4.14.0", + "elkjs": "0.12.1", "esbuild": "0.28.2", "geist": "1.9.0", "playwright": "1.63.0", diff --git a/scripts/check-deps.mjs b/scripts/check-deps.mjs index 63ed6816..ed9c43d0 100644 --- a/scripts/check-deps.mjs +++ b/scripts/check-deps.mjs @@ -56,7 +56,14 @@ export function checkDependencies(repo = repoRoot) { const where = `packages/${dir}`; const pkg = JSON.parse(fs.readFileSync(file, "utf8")); const kinds = ["dependencies", "peerDependencies", "optionalDependencies"]; - compare(where, [...new Set(kinds.flatMap((k) => Object.keys(pkg[k] ?? {})))]); + // An approved package whose file is copied into dist is a devDependency (it is not installed with the package), listed in $copied at the exact version + // the copy was made from: it counts as used while that devDependency is there, at that version. + const copied = allowed.$copied?.[where] ?? {}; + for (const [name, version] of Object.entries(copied)) { + const dev = pkg.devDependencies?.[name]; + if (dev !== version) problems.push(`$copied: ${where} "${name}" is listed as "${version}" but is ${dev === undefined ? "not a devDependency" : `"${dev}" in devDependencies`}; the copy in dist and the list must agree.`); + } + compare(where, [...new Set([...kinds.flatMap((k) => Object.keys(pkg[k] ?? {})), ...Object.keys(copied).filter((name) => pkg.devDependencies?.[name] === copied[name])])]); for (const kind of kinds) for (const [name, version] of Object.entries(pkg[kind] ?? {})) { if (EXACT.test(version)) continue; if (ranges[where]?.[name] === version) continue; diff --git a/scripts/verify-packages.mjs b/scripts/verify-packages.mjs index b8401dce..24d1c691 100644 --- a/scripts/verify-packages.mjs +++ b/scripts/verify-packages.mjs @@ -91,6 +91,17 @@ assert.ok(tokens.dark['text-primary'].hex); assert.equal(accents.cobalt.dark.hex const phosphor = await import('@srasyndicate/basalt/phosphor'); assert.deepEqual(phosphor.BASALT_PHOSPHOR_WEIGHTS, ['bold', 'fill']); assert.throws(() => phosphor.phosphorWeightsEsbuild({}), /weights/); assert.equal(phosphor.phosphorWeightsRollup({ weights: ['bold'] }).transform('x', '/a/b.js'), null); console.log('Packed consumer: runtime, server rendering, exact token types, exports, fonts and RSC boundary pass.');`); process.stdout.write(run(process.execPath, ["smoke.mjs"], consumer)); + // elkjs is a build input of the package, not a dependency (the decider's ruling 2 on the batch B re-check): the package ships its one copy, + // dist/diagram-elk.js, so a consumer with no elkjs installed places an automatic figure. + fs.rmSync(path.join(consumer, "node_modules", "elkjs"), { recursive: true, force: true }); + fs.writeFileSync(path.join(consumer, "place.mjs"), `import assert from 'node:assert/strict'; import fs from 'node:fs'; +assert.ok(!fs.existsSync(new URL('./node_modules/elkjs', import.meta.url)), 'no elkjs in the consumer'); +const { placeDiagram } = await import('@srasyndicate/basalt/diagram-layout'); +const placed = await placeDiagram({ type: 'architecture', nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }], edges: [{ from: 'a', to: 'b', kind: 'main' }, { from: 'b', to: 'c' }] }, 'right'); +assert.deepEqual(Object.keys(placed.cells).sort(), ['a', 'b', 'c']); +assert.ok(placed.cells.a.col < placed.cells.c.col); +console.log('Packed consumer: an automatic figure is placed with no elkjs installed.');`); + process.stdout.write(run(process.execPath, ["place.mjs"], consumer)); // A React Server Component, built by Next.js (A5-18): what the package holds that is neither a component nor a hook must be callable on the server. Each // page is static, so a call that throws ("Attempted to call formatStamp() from the server but formatStamp is on the client") fails the build, and a constant // that arrives as a client reference (CONFIRM_MS / 1000 is NaN, with no error) shows in the page's HTML. The components still come through as components. From b073ff0c9e2bbea69731ceec67d78a784042cd2f Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:42:13 -0600 Subject: [PATCH 55/62] Ruling 3: a wrapped transcript route breaks before its arrow The decider's ruling on the batch B re-check: in the transcript, the arrow and the receiver are one unbreakable run (tx-to, nowrap), so a route that does not fit breaks before its arrow and its second line starts with the arrow under the sender, as the stacked list's route does (66-2). No deeper indent and no second ink: the receiver keeps the names' primary ink. Tests: diagram-recheck.test.mjs (node, run) checks every route's markup ends in the one run and the run's nowrap; diagram-review.test.mjs measures it at 390 in both themes (browser, written, not run). The implementation hasn't been reviewed. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-core.ts | 4 +++- packages/react/src/styles/components.css | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 73ae61d3..c2348e3e 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -1256,7 +1256,9 @@ export function transcript(P: string, m: Model): VNode[] { if ("close" in s) { indent = Math.max(0, indent - 1); out.push(line({ "data-ink": "frame" }, 2 * indent, 0, "[end]")); continue; } const a = m.byId.get(s.from)?.name ?? s.from, b = m.byId.get(s.to)?.name ?? s.to; const hang = digits + 2; - out.push(line({ "data-n": s.n }, pad, hang, h("span", { "data-ink": "num" }, String(s.n).padStart(digits, "0")), " ", held(a), " ", h("span", { "data-ink": s.kind === "main" ? "main" : "plain" }, arrow(s.kind)), " ", held(b))); + // The arrow and the receiver are one unbreakable run: a route that does not fit breaks before its arrow, and the second line starts with the arrow under + // the sender (the decider's ruling 3 on the re-check), as the stacked list's route does (66-2). + out.push(line({ "data-n": s.n }, pad, hang, h("span", { "data-ink": "num" }, String(s.n).padStart(digits, "0")), " ", held(a), " ", h("span", { class: `${P}-tx-to` }, h("span", { "data-ink": s.kind === "main" ? "main" : "plain" }, arrow(s.kind)), " ", b))); out.push(line({ "data-n": s.n }, pad + hang, 0, h("span", { "data-ink": "label" }, s.label))); if (s.note) out.push(line({ "data-n": s.n }, pad + hang, 0, h("span", { "data-ink": "note" }, s.note))); } diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index d19a9210..8c098eb9 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4866,7 +4866,7 @@ /* The art's code element is the block's text, never an inline code chip: a page's own code style (the skill's core gives inline code a fill) would band every row (P-R2 of the code re-check). */ .basalt-diagram-text .basalt-diagram-text-ink { font: inherit; padding: 0; border: 0; border-radius: 0; background: none; color: inherit; } - .basalt-diagram-tx-name { white-space: nowrap; color: var(--basalt-text-primary); } + .basalt-diagram-tx-name, .basalt-diagram-tx-to { white-space: nowrap; color: var(--basalt-text-primary); } /* A transcript's line (B6 of the pixel review): a block indented by its frame, its message's lines hanging under the sender. */ .basalt-diagram-tx-line { display: block; From c8173058a0dc7279815b9faee5b1751f9458f630 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:42:24 -0600 Subject: [PATCH 56/62] Ruling 4: a stacked turn's label stays with its turn, inside the group The decider's ruling on the batch B re-check: a stacked group whose first card is entered by a turn (a trunk or end-down line) has space-12 above that card plus space-4 for each line of the turn's label (--_tl, from the longest label: 64 for one line, 80 for two); an unlabelled turn keeps space-12. The label's first seats are beside its turn, space-2-5 past the entry, then a line (space-4) at a time up into that room, never above the group's edge, so nothing grows above the group for it; the line's own seats follow. --_tl is a managed style, so a redraw clears it. Tests: diagram-recheck.test.mjs (node, run) checks the marking, --_tl and the rule; diagram-review.test.mjs measures the label inside the group, at least space-1 under the group's label, its lower edge within space-4 of its turn, nothing grown above, and 48 for an unlabelled turn (browser, both themes at 390, written, not run). The implementation hasn't been reviewed. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-core.ts | 18 +++++++++++++----- packages/react/src/styles/components.css | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index c2348e3e..3c4b77f6 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -1211,8 +1211,12 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { // A group whose first card is entered by a turn (a trunk or an end line) has space-12 above it, so the turn runs under its label, not behind it // (DECISIONS 306, 1.3, the decider's answer 1 to the pixel review). The label keeps its place in the first space-8. const first = run[0]!; - const turn = Boolean(ctx.plan) && first.group === g.id && m.edges.some((e, k) => e.to === first.id && (ctx.plan!.routes[k] === "trunk" || ctx.plan!.routes[k] === "end-down")); - return h("div", { class: `${P}-group`, "data-group": g.id, "data-depth": g.depth > 1 ? g.depth : undefined, "data-turn": turn ? "" : undefined, style: grow ? `--_ggrow:${grow}` : undefined }, h("span", { class: `${P}-glabel`, "aria-hidden": "true" }, g.label), kids); + const turns = ctx.plan && first.group === g.id ? m.edges.filter((e, k) => e.to === first.id && (ctx.plan!.routes[k] === "trunk" || ctx.plan!.routes[k] === "end-down")) : []; + // A labelled turn's label is seated beside its turn, inside the group (the decider's ruling 4 on the re-check): the group has space-4 more above for each + // line of the longest such label, so nothing grows above the group for it. + const lines = Math.max(0, ...turns.map((e) => (e.label ? labelLines(e.label) : 0))); + const style = [grow ? `--_ggrow:${grow}` : "", lines ? `--_tl:${lines}` : ""].filter(Boolean).join(";"); + return h("div", { class: `${P}-group`, "data-group": g.id, "data-depth": g.depth > 1 ? g.depth : undefined, "data-turn": turns.length ? "" : undefined, style: style || undefined }, h("span", { class: `${P}-glabel`, "aria-hidden": "true" }, g.label), kids); }; let k = 0; while (k < m.nodes.length) { @@ -2646,6 +2650,10 @@ function stackedGeometry(input: DrawnInput, measure: ReturnType, p }); const order = m.nodes; const card = (i: number) => map.get(order[i]!.id)!; + // The first card of a group entered by a turn (ruling 4 on the re-check): its turn's label takes the first seat beside the turn that clears the card, a + // line at a time up into the room the group keeps for it, never above the group's edge (the group's edge and label are obstacles). + const turnInto = (id: string) => { const el = drawing.querySelector(`.${P}-node[data-node="${CSS.escape(id)}"]`); const g = el?.parentElement; return Boolean(g?.matches(`.${P}-group[data-turn]`) && g.querySelector(`:scope > .${P}-node`) === el); }; + const beside = (box: Rect, id: string, lh: number) => (turnInto(id) ? Array.from({ length: Math.round(lh / 16) + 1 }, (_, j) => ({ ...box, t: box.t - j * s("4"), b: box.b - j * s("4") })) : [box]); // Each label's seats, in the order they are tried: a stem's are its clear shaft's middle and then its thirds (1.8's order); every other // route has its one fixed seat (1.13). const labelSeats: Array<{ k: number; cands: Rect[]; on: boolean; card: string }> = []; @@ -2694,7 +2702,7 @@ function stackedGeometry(input: DrawnInput, measure: ReturnType, p const ex = sn.x(b.rect.l + s("6"), w); const ty = sn.y(b.rect.t - turn, w); pts = [start, { x, y: ty }, { x: ex, y: ty }, contour(b, "top", ex)]; - if (label) labelSeats.push({ k, cands: lineSeats({ l: ex + s("2-5"), r: ex + s("2-5") + lw, t: ty - lh / 2, b: ty + lh / 2 }, e.to, -1), on: false, card: e.to }); + if (label) labelSeats.push({ k, cands: [...beside({ l: ex + s("2-5"), r: ex + s("2-5") + lw, t: ty - lh / 2, b: ty + lh / 2 }, e.to, lh), ...lineSeats({ l: ex + s("2-5"), r: ex + s("2-5") + lw, t: ty - lh / 2, b: ty + lh / 2 }, e.to, -1).slice(1)], on: false, card: e.to }); } } else { // An end line: out the end side, along the end lane or the gutter, into the card's top (down) or bottom (up), space-6 in from its end edge. @@ -2715,7 +2723,7 @@ function stackedGeometry(input: DrawnInput, measure: ReturnType, p const ty = sn.y(tyRaw, w); pts = [exit, { x: laneX, y: exit.y }, { x: laneX, y: ty }, { x: ex, y: ty }, contour(b, down ? "top" : "bottom", ex)]; const into = down ? e.to : order[b.i + 1]?.id ?? e.to; - if (label) labelSeats.push({ k, cands: lineSeats({ l: innerEx - s("2-5") - lw, r: innerEx - s("2-5"), t: tyRaw - lh / 2, b: tyRaw + lh / 2 }, into, down ? -1 : 1), on: false, card: into }); + if (label) labelSeats.push({ k, cands: [...(down ? beside({ l: innerEx - s("2-5") - lw, r: innerEx - s("2-5"), t: tyRaw - lh / 2, b: tyRaw + lh / 2 }, into, lh) : [{ l: innerEx - s("2-5") - lw, r: innerEx - s("2-5"), t: tyRaw - lh / 2, b: tyRaw + lh / 2 }]), ...lineSeats({ l: innerEx - s("2-5") - lw, r: innerEx - s("2-5"), t: tyRaw - lh / 2, b: tyRaw + lh / 2 }, into, down ? -1 : 1).slice(1)], on: false, card: into }); } const snapped = snapRoute(pts, w, sn); geo.lines.push({ i: k, from: e.from, to: e.to, kind: e.kind, pts: snapped, tip: snapped[snapped.length - 1]!, dir: finish(snapped), width: w }); @@ -3102,7 +3110,7 @@ export function keyTarget(m: Model, from: string, key: string, drawn = false, rt const MANAGED = ["data-layout", "data-measured", "role", "aria-roledescription", "aria-labelledby", "aria-describedby", "aria-label", "tabindex", "data-stops", "hidden", "data-art"]; // The figure's grid attributes follow the model too: an automatic figure's direction can change its columns after script (Neon's B8 of the code review). const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-motion", "data-first-visit", "data-rtl", "data-cols", "data-reach", "data-gutter", "data-marks"]; -const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_gpad", "--_gw", "--_mh", "--_rows", "--_row-gap"]; +const MANAGED_STYLE = ["--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_tl", "--_gpad", "--_gw", "--_mh", "--_rows", "--_row-gap"]; const absent = (value: VAttrs[string]) => value === undefined || value === null || value === false; function pairs(el: Element, v: VElement): boolean { if (el.tagName.toLowerCase() !== v.t) return false; diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 8c098eb9..f269433d 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -4661,8 +4661,9 @@ border: var(--basalt-size-hairline) dashed var(--basalt-diagram-structure); border-radius: var(--basalt-radius-lg); } + .basalt-diagram-group { --_tl: 0; } .basalt-diagram-group:first-child { margin-block-start: 0; } - .basalt-diagram-group[data-turn] { padding-block-start: calc(var(--basalt-space-8) + var(--basalt-space-4)); } + .basalt-diagram-group[data-turn] { padding-block-start: calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_tl, 0)); } .basalt-diagram-group > .basalt-diagram-glabel + .basalt-diagram-node { --_d-mt: 0; } .basalt-diagram-glabel { position: absolute; top: var(--basalt-space-2); inset-inline-start: var(--basalt-space-3); color: var(--basalt-text-secondary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); white-space: nowrap; } .basalt-diagram-group > .basalt-diagram-glabel { --_d-gl: var(--_drawn) none; display: var(--_d-gl, block); } From f72bc38a63710c041a83f5e8e1c1a9bdfc832925 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:42:38 -0600 Subject: [PATCH 57/62] Opus P5: an automatic layout whose cards change while it runs lays out again The figure asked for a placement once per spec object and kept the first answer, so cards added or lines changed while elk ran could be left without a cell (P-R1 of the code re-check). What placement reads (the type, the cards and their groups or the tables and their references, the lines, the groups) is now a signature; when it changes, the answer for the old one, loaded or in flight, is dropped and the figure is laid out again. A change of words or legend does not count. Tests: diagram-layout.test.mjs (browser, written, not run): two figures under one key in one task draw as a fresh figure of the second's data draws, with none of the first's cards; a change of lines alone lays out again, and the cells move. Also in that file, the layout module fetched only when needed (an ES-module app with code splitting on a routed origin: a fixed layout and a phone's automatic figure fetch no elk chunk, two automatic figures at 1104 fetch it once). The implementation hasn't been reviewed. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-figure.tsx | 11 ++- packages/react/test/diagram-layout.test.mjs | 81 +++++++++++++++++++++ 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 0273b7a6..71958fb8 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -139,7 +139,12 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: const auto = spec.layout === "auto" && (spec.type === "architecture" || spec.type === "flowchart" || spec.type === "schema"); const given = React.useMemo(() => (spec.placement ? (Array.isArray(spec.placement) ? spec.placement : [spec.placement]) : []), [spec.placement]); const [loaded, setLoaded] = React.useState(null); - const placing = React.useRef(null); + // What placement reads (the cards, their groups and the lines, by id): new cards are placed afresh. The answer for the old ones, loaded or still in + // flight, is dropped (P-R1 of the code re-check), so a card added while elk runs is never left without a cell. Other props (words, a legend) do not count. + const placedFrom = React.useMemo(() => (auto ? JSON.stringify([spec.type, (spec.type === "schema" ? spec.tables?.map((t) => [t.name, t.columns?.map((c) => c.references ?? "")]) : spec.nodes?.map((n) => [n.id, (n as { group?: string }).group])), spec.edges?.map((e) => [e.from, e.to, e.kind]), spec.groups?.map((g) => [g.id, g.parent])]) : ""), [auto, spec.type, spec.tables, spec.nodes, spec.edges, spec.groups]); + const placing = React.useRef(null); + const placedFor = React.useRef(placedFrom); + if (placedFor.current !== placedFrom) { placedFor.current = placedFrom; placing.current = null; if (loaded) setLoaded(null); } // A figure that unmounts drops an answer still in flight. React.useEffect(() => () => { placing.current = null; }, []); const placements = React.useMemo(() => (given.length ? given : loaded ?? []), [given, loaded]); @@ -214,7 +219,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // that has gone is dropped. if (auto && !given.length && !loaded && !placing.current && (viewer || fig.clientWidth >= 640)) { const input = { type: spec.type as "architecture" | "flowchart" | "schema", nodes: spec.nodes as Array<{ id: string; group?: string }>, tables: spec.tables, edges: spec.edges, groups: spec.groups }; - const ask = spec; + const ask = placedFrom; placing.current = ask; loadLayout().then((mod) => Promise.all(order.map((d) => mod.placeDiagram(input, d)))).then((all) => { if (placing.current === ask) { placing.current = null; setLoaded(all); } }, (error: unknown) => { if (placing.current === ask) placing.current = null; @@ -304,7 +309,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: // A figure hidden (the viewer's list is open) was not measured: the viewer keeps the drawing's size and place it had. A text figure's art is in the DOM // only once React has written it, so its size is read after that (below). if (viewer && result.tokens && !model.text) viewer.onMeasured(result, fig); - }, [model, base, options, component, viewer, rtl, auto, given, loaded, placements, order, placementFor, dirAt, spec, textModule, transcriptHtml, errorOnce]); + }, [model, base, options, component, viewer, rtl, auto, given, loaded, placements, order, placementFor, dirAt, spec, textModule, transcriptHtml, placedFrom, errorOnce]); // The viewer's text figure (9.3): its size is read once React has written the art it measured, so the zoom fits the art and not the transcript. React.useLayoutEffect(() => { diff --git a/packages/react/test/diagram-layout.test.mjs b/packages/react/test/diagram-layout.test.mjs index 40ce2e7d..429ebc95 100644 --- a/packages/react/test/diagram-layout.test.mjs +++ b/packages/react/test/diagram-layout.test.mjs @@ -260,3 +260,84 @@ describe("the viewer", () => { await phone.page.close(); }); }); + +describe("a layout that is out of date (Opus P5 on the re-check)", () => { + test("cards that change while the layout runs: the stale answer is discarded and the figure is laid out again on the new cards", async () => { + const { page, errors } = await figurePage(); + // Two figures under one key: the second replaces the first's cards before the layout module has answered (both in one task, so no answer can land + // between them). The figure must draw as a fresh figure of the second's data draws (the control), with none of the first's cards. + const first = FIG.autoArchitecture, second = FIG.autoFlowchart; + const cells = (key) => page.evaluate(({ P, key }) => Object.fromEntries([...document.querySelectorAll(`#fig-${key} .${P}-node`)].map((n) => [n.dataset.node, ["--_c", "--_r", "--_r2"].map((v) => n.style.getPropertyValue(v)).join(" ")])), { P, key }); + await page.evaluate(({ a, b }) => { window.__set([{ key: "p5", spec: a }]); window.__set([{ key: "p5", spec: b }]); }, { a: first, b: second }); + await page.waitForFunction(() => document.querySelector("#fig-p5")?.getAttribute("data-layout") === "drawn", null, { timeout: 15000 }); + await draw(page, [{ key: "p5", spec: second }, { key: "ctl", spec: second }]); + await page.waitForFunction(() => document.querySelector("#fig-ctl")?.getAttribute("data-layout") === "drawn", null, { timeout: 15000 }); + await frames(page, 4); + const got = await cells("p5"); + assert.deepEqual(Object.keys(got).sort(), second.nodes.map((n) => n.id).sort(), "the second figure's cards, none of the first's"); + assert.deepEqual(got, await cells("ctl"), "each card in the cell of the second figure's own placement"); + // A change of lines alone (the same cards) lays out again too. + const relined = { ...second, edges: second.edges.slice(0, -1) }; + await draw(page, [{ key: "p5", spec: relined }, { key: "ctl2", spec: relined }]); + await page.waitForFunction(() => document.querySelector("#fig-ctl2")?.getAttribute("data-layout") === "drawn", null, { timeout: 15000 }); + await frames(page, 4); + const relaid = await cells("p5"); + assert.deepEqual(relaid, await cells("ctl2"), "after the lines changed"); + assert.notDeepEqual(relaid, got, "and the placement moved (placeDiagram gives other cells without the last line)"); + assert.deepEqual(errors, []); + await page.close(); + }); +}); + +describe("the layout module is fetched only when a figure needs it (Neon B12)", () => { + // The other fixtures bundle into one script, where a dynamic import is inlined and no request can be seen. Here the page is an app's: an ES module + // build with code splitting, served from a routed origin, so each lazy chunk is a request of its own. The chunk that holds elkjs is found from esbuild's + // metafile, not by its name. + const ORIGIN = "http://basalt.test"; + const APP = `import * as React from "react"; import { createRoot } from "react-dom/client"; import { flushSync } from "react-dom"; import * as B from "./dist/index.js"; +const C = { architecture: B.ArchitectureDiagram, flowchart: B.FlowchartDiagram }; +function Host() { const [list, setList] = React.useState([]); window.__set = (next) => flushSync(() => setList(next)); return
{list.map(({ key, spec }) => { const { type, ...props } = spec; const X = C[type]; return ; })}
; } +createRoot(document.getElementById("root")).render();`; + let files, elkChunk; + before(async () => { + const built = await esbuild.build({ stdin: { contents: APP, resolveDir: pkg, loader: "tsx" }, bundle: true, splitting: true, format: "esm", outdir: "/out", write: false, metafile: true, jsx: "automatic", platform: "browser", logLevel: "silent", define: { "process.env.NODE_ENV": '"production"' } }); + files = new Map(built.outputFiles.map((f) => [f.path.replace(/^\/out/, ""), f.text])); + elkChunk = Object.entries(built.metafile.outputs).find(([, o]) => Object.keys(o.inputs).some((i) => i.endsWith("dist/diagram-elk.js")))?.[0].replace(/^\/?out/, ""); + }); + async function appPage(width) { + const page = await browser.newPage({ viewport: { width, height: 1000 } }); + const asked = []; + await page.route(`${ORIGIN}/**`, (route) => { + const url = new URL(route.request().url()); + if (url.pathname === "/") return route.fulfill({ contentType: "text/html", body: `
` }); + if (url.pathname === "/styles.css") return route.fulfill({ contentType: "text/css", body: fs.readFileSync(path.join(pkg, "dist", "styles.css"), "utf8") }); + asked.push(url.pathname); + const body = files.get(url.pathname); + return body === undefined ? route.fulfill({ status: 404, body: "" }) : route.fulfill({ contentType: "text/javascript", body }); + }); + await page.goto(`${ORIGIN}/`); + await page.waitForFunction(() => typeof window.__set === "function"); + return { page, asked }; + } + + test("a fixed layout and a phone's automatic one fetch no layout; an automatic figure at 1104 fetches it once", async () => { + assert.ok(elkChunk, "esbuild put elkjs in a chunk of its own"); + const fixed = { type: "architecture", title: "t", summary: "s", nodes: [{ id: "a", name: "A", col: 1, row: 1 }, { id: "b", name: "B", col: 2, row: 1 }], edges: [{ from: "a", to: "b" }] }; + const wide = await appPage(1440); + await wide.page.evaluate((spec) => window.__set([{ key: "fixed", spec }]), fixed); + await wide.page.waitForSelector("#fig-fixed[data-layout]"); + await wide.page.waitForTimeout(500); + assert.ok(!wide.asked.includes(elkChunk), `a fixed layout fetches no layout ${JSON.stringify(wide.asked)}`); + await wide.page.evaluate((spec) => window.__set([{ key: "auto", spec }, { key: "auto2", spec }]), FIG.autoArchitecture); + await wide.page.waitForFunction(() => document.querySelector("#fig-auto")?.getAttribute("data-layout") === "drawn", null, { timeout: 15000 }); + assert.equal(wide.asked.filter((p) => p === elkChunk).length, 1, `fetched once for two figures ${JSON.stringify(wide.asked)}`); + await wide.page.close(); + // Under 640 an automatic figure stacks without asking where its cards go (8.5), so nothing is fetched. + const phone = await appPage(390); + await phone.page.evaluate((spec) => window.__set([{ key: "auto", spec }]), FIG.autoArchitecture); + await phone.page.waitForSelector("#fig-auto[data-layout='stacked']"); + await phone.page.waitForTimeout(800); + assert.ok(!phone.asked.includes(elkChunk), `the phone fetches no layout ${JSON.stringify(phone.asked)}`); + await phone.page.close(); + }); +}); From bf32e547f932477ebc6434ce62322d8a0055cd78 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:42:40 -0600 Subject: [PATCH 58/62] Round 66: the text sequence and the automatic architecture in the viewer; step 10's data flow drawn The text step and the automatic layout step each gain a viewer shot (the art whole at 1440 and 390; the automatic architecture drawn in the viewer, both themes), and the viewer's wait is for a drawn figure or the art, not a fixed time. Step 10 shows the extended data flow drawn at 1440 (a step's mark and a dashed line, Fable's P5), still, then its parts as before. Co-Authored-By: Claude Opus 5.5 --- tools/review/round66.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx index a9aa0209..da59657c 100644 --- a/tools/review/round66.tsx +++ b/tools/review/round66.tsx @@ -57,6 +57,13 @@ const DATA_FLOW_PARTS: Inline = (() => { // Still, so the shot shows every line (an animated figure's lines wait until it comes into view); its flow marches where motion is asked for. return { ...d, title: "How one message reaches everyone in the room (extended)", summary: `${String(d.summary)} Two more lines show several end lines entering one card when it is stacked.` }; })(); +// The same data flow drawn, in lanes (the pixel re-check's N1): the step's mark and the dashed line, without the two lines that stack the extended one. +const DATA_FLOW_DRAWN: Inline = (() => { + const d = structuredClone(data.dataFlow) as unknown as Inline & { nodes: Array>; edges: Array> }; + for (const n of d.nodes) if (n.id === "seg") n.mark = awsS3Bucket; + d.edges = d.edges.map((e) => (e.kind === "dashed" ? { ...e, flow: true } : e)); + return { ...d, title: "How one message reaches everyone in the room (a step's mark, a dashed flow)" }; +})(); const schemaTable = (name: string, row: number, refs: string[] = []) => ({ name, col: 1, row, columns: [{ name: "id", key: "PK" }, ...refs.map((r) => ({ name: `${r}_id`, key: "FK", references: `${r}.id` }))] }); const CALL_2: Inline = { type: "schema", title: "One column: turn-backs beside each other take lanes (section 4, call 2)", summary: "b references c and c references a; their turn-backs run beside each other down the column's end side, so each takes a lane.", legend: { plain: "A foreign key" }, tables: [schemaTable("a", 1), schemaTable("b", 2, ["c"]), schemaTable("c", 3, ["a"])] }; const CALL_3: Inline = { type: "architecture", title: "A card grows to hold its ports (section 4, call 3)", summary: "The coordinator's end side holds a straight line and two others, so it is 48 tall at every width.", legend: { main: "Request", plain: "Call" }, @@ -80,7 +87,8 @@ function Diagram({ k, state }: { k: Key; state: string }) { (async () => { await frames(6); host.current?.querySelector(".basalt-diagram-expand")?.click(); - for (let t = 0; t < 60 && !document.querySelector("dialog.basalt-diagram-viewer .basalt-diagram[data-layout]"); t++) await frames(2); + // Drawn (an automatic figure places itself first), or a text figure's art: whichever the viewer holds when it has settled. + for (let t = 0; t < 120 && !document.querySelector("dialog.basalt-diagram-viewer .basalt-diagram[data-layout='drawn'], dialog.basalt-diagram-viewer .basalt-diagram-text[data-art]"); t++) await frames(2); await new Promise((r) => setTimeout(r, 400)); if (state === "viewer-200") { const level = () => Number(document.querySelector(".basalt-diagram-level > span")?.textContent?.replace("%", "") ?? 0); @@ -190,14 +198,16 @@ export const ROUND_66: Round = { scales: [2], height: 3000, touch: true, - demo: ({ state }) => <>, + states: ["viewer"], + demo: ({ state }) => <>, }, { id: "text", name: "A sequence as text art", intro: "variant=\"text\": the same data as box-drawing characters, where its widest line fits; on a phone the transcript.", decisions: [...COMMON, "No line-by-line reveal and no caret (item 1 for the owner): under motion=\"animated\" it builds by ink, as the drawn sequence does."], - tryIt: ["Select the art and copy it: the clipboard holds the art exactly."], + tryIt: ["Select the art and copy it: the clipboard holds the art exactly.", "Expand: the viewer holds the art at its own width, never the transcript, on a phone too (the viewer shots)."], + states: ["viewer"], widths: W, scales: [2], height: 2000, @@ -242,7 +252,7 @@ export const ROUND_66: Round = { { id: "data-flow", name: "Data flow: a step's mark, a dashed flow, and several end lines into one card", - intro: "The CIMIP data flow with two more lines. The sealed segment, in the S3 lane, carries S3's mark. The batch line is dashed and flows: its own dashes march. Stacked, two cards are each entered by two end lines, which nest.", + intro: "The CIMIP data flow drawn in its lanes: the sealed segment, in the S3 lane, carries S3's mark, and the batch line is dashed and flows. Below it, the same data flow with two more lines: stacked, two cards are each entered by two end lines, which nest.", decisions: [ ...COMMON, "A step's mark (1.6) is 16px in its top end corner; the lane's label counts as the step's words, so \"S3\" says what the mark stands for.", @@ -252,9 +262,9 @@ export const ROUND_66: Round = { tryIt: ["Narrow to 390: the two cards entered by two end lines show the nesting and the labels' seats."], widths: W, scales: [2], - height: 1700, + height: 2600, touch: true, - demo: () => , + demo: () => <>, }, { id: "calls", From e8626576bad3157afe6c1c5b77a097fc210b92bc Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:42:53 -0600 Subject: [PATCH 59/62] Tests for the re-check (Opus B12): the frame side, the text viewer, touch, pinch, parity for batch B - diagram-recheck.test.mjs (node, run: 6 pass): the art's glyph probe in both engines; viewerTextWidth leaves the zoom alone; rulings 3 and 4 in markup and CSS; elkjs one copy; compose.mjs's batch B figures equal the engine's, prefix for prefix (an automatic one on its placeDiagram answer). It caught the skill's stale build before the rebuild. - diagram-review.test.mjs: the frame-side test now has a fixture that crosses (Opus's: a long note over the start side of the frame below), with two controls that fail it if anything but B7a's rule stacks it; the text art in the viewer stays whole and the same width through zoom in, Fit and zoom out; ruling 3 at 390, both themes; ruling 4's measurements. - diagram-viewer.test.mjs: the bare-stack fixture was right (the fault was the engine's, fixed in its own commit); the status test now pinches with twenty CDP moves and is spoken once. - diagram-keys.test.mjs: the trace on touch: a ground tap, a scroll from a card, a linked card, the foot's stillness and Clear last, a touchscreen laptop's first tap, the stacked schema and sequence with no hint or Clear. - tools/html-skill/test/diagrams.test.mjs: React and skill parity for batch B's nine figures, both themes at 1440 and 390. Browser files: written, not run (DECISIONS 330). Co-Authored-By: Claude Opus 5.5 --- packages/react/test/diagram-keys.test.mjs | 93 ++++++++++++++++++ packages/react/test/diagram-recheck.test.mjs | 99 ++++++++++++++++++++ packages/react/test/diagram-review.test.mjs | 86 +++++++++++++---- packages/react/test/diagram-viewer.test.mjs | 50 +++++++--- tools/html-skill/test/diagrams.test.mjs | 47 ++++++++++ 5 files changed, 346 insertions(+), 29 deletions(-) create mode 100644 packages/react/test/diagram-recheck.test.mjs diff --git a/packages/react/test/diagram-keys.test.mjs b/packages/react/test/diagram-keys.test.mjs index 240b7ce2..2cda4b29 100644 --- a/packages/react/test/diagram-keys.test.mjs +++ b/packages/react/test/diagram-keys.test.mjs @@ -101,3 +101,96 @@ describe("stacked and the hint", () => { await page.close(); }); }); + +// The trace on touch (1.5; Neon's B12 of the code review, still missing at the re-check): a tap on the ground, a scroll, a linked card, the foot, a +// touchscreen laptop's first tap, and the stacked schema and sequence. Written while browser tests are paused (DECISIONS 330): not run in the round that +// wrote it. +const BX = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams-b.json"), "utf8")); +async function touchPage({ width = 1440, mobile = true, items } = {}) { + const { page, errors } = await fixturePage(browser, HOST, { theme: "dark", standards: true, viewport: { width, height: 1000 }, hasTouch: true, isMobile: mobile }); + await page.addStyleTag({ content: "body{margin:0;padding:16px} #root{max-width:1104px;margin:0 auto}" }); + await page.evaluate(() => document.fonts.ready); + if (items) await page.evaluate((items) => window.__set(items), items); + await frames(page, 6); + return { page, errors }; +} +const lit = (page, key) => page.locator(`#fig-${key} .${P}-edge[data-lit]`).count(); +const clearState = (page, key) => page.locator(`#fig-${key} .${P}-clear`).evaluateAll((b) => b.map((x) => x.getAttribute("aria-disabled"))); + +describe("the trace on touch", () => { + test("a tap on the ground clears a trace; with none up it changes nothing", async () => { + const { page, errors } = await touchPage(); + const ground = async () => { const box = await page.locator(`#fig-architecture .${P}-drawing`).boundingBox(); await page.touchscreen.tap(box.x + 4, box.y + box.height - 4); await page.waitForTimeout(150); }; + await ground(); + assert.equal(await lit(page, "architecture"), 0); + assert.deepEqual(await clearState(page, "architecture"), ["true"], "Clear highlight stays disabled"); + await page.tap(`#fig-architecture .${P}-node[data-node="svc"]`); + await page.waitForTimeout(150); + assert.ok((await lit(page, "architecture")) > 0, "the card is traced"); + await ground(); + assert.equal(await lit(page, "architecture"), 0, "the ground clears it"); + assert.deepEqual(await clearState(page, "architecture"), ["true"]); + assert.deepEqual(errors, []); + await page.close(); + }); + + test("a scroll that starts on a card traces nothing", async () => { + const { page } = await touchPage({ width: 390 }); + const card = await page.locator(`#fig-flowchart .${P}-node`).first().boundingBox(); + const cdp = await page.context().newCDPSession(page); + const at = (dy) => [{ x: card.x + card.width / 2, y: card.y + card.height / 2 + dy, id: 1 }]; + await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: at(0) }); + for (let k = 1; k <= 10; k++) await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: at(-12 * k) }); + await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] }); + await page.waitForTimeout(200); + for (const key of Object.keys(NAMES)) assert.equal(await lit(page, key), 0, `${key}: no trace`); + await page.close(); + }); + + test("a linked card follows its link and is never traced", async () => { + const { page } = await touchPage({ items: [{ key: "arch", type: "architecture", props: (({ type, ...p }) => p)(BX.architecture) }, { key: "sequence", type: "sequence", props: (({ type, ...p }) => p)(BX.sequence) }] }); + await page.tap(`#fig-arch a.${P}-node[data-node="svc"]`); + await page.waitForTimeout(200); + assert.equal(await page.evaluate(() => location.hash), "#fig-sequence", "the link is followed"); + assert.equal(await lit(page, "arch"), 0, "and nothing is traced"); + assert.deepEqual(await clearState(page, "arch"), ["true"]); + await page.close(); + }); + + test("the foot does not move when Clear highlight is enabled, and Clear highlight is last in it", async () => { + const { page } = await touchPage(); + const foot = () => page.locator(`#fig-architecture .${P}-foot > *`).evaluateAll((els) => els.map((e) => { const r = e.getBoundingClientRect(); return [e.className, Math.round(r.left * 2) / 2, Math.round(r.top * 2) / 2, Math.round(r.width * 2) / 2, Math.round(r.height * 2) / 2]; })); + const before = await foot(); + assert.match(before.at(-1)[0], /-clear\b/, "last in the foot"); + await page.tap(`#fig-architecture .${P}-node[data-node="svc"]`); + await page.waitForTimeout(200); + assert.deepEqual(await clearState(page, "architecture"), [null]); + assert.deepEqual(await foot(), before, "every control in its place and size"); + await page.close(); + }); + + test("a touchscreen laptop: the first tap traces and mounts Clear highlight, last in the foot, after an animated figure's controls", async () => { + const motion = { key: "flow", type: "data-flow", props: { ...(({ type, ...p }) => p)(BX.dataFlow), motion: "animated" } }; + const { page } = await touchPage({ mobile: false, items: [motion] }); + const onTouch = await page.evaluate(() => matchMedia("(hover: none), (pointer: coarse)").matches); + // A laptop's media says hover and a fine pointer: no Clear highlight until a finger is used. (Where the emulated media says touch, it is there from the start.) + if (!onTouch) assert.equal(await page.locator(`#fig-flow .${P}-clear`).count(), 0, "not mounted before a tap"); + const card = page.locator(`#fig-flow .${P}-node:not([href])`).first(); + await card.tap(); + await page.waitForTimeout(200); + assert.ok((await lit(page, "flow")) > 0, "the first tap traces"); + const order = await page.locator(`#fig-flow .${P}-foot > *`).evaluateAll((els) => els.map((e) => e.className)); + assert.match(order.at(-1), /-clear\b/, `last in the foot ${JSON.stringify(order)}`); + await page.close(); + }); + + test("at 390 the stacked schema and sequence, which draw no lines, show no tap hint and no Clear highlight", async () => { + const { page } = await touchPage({ width: 390 }); + for (const key of ["schema", "sequence"]) { + assert.equal(await page.locator(`#fig-${key}`).getAttribute("data-layout"), "stacked", key); + assert.equal(await page.locator(`#fig-${key} .${P}-clear`).count(), 0, `${key}: no Clear highlight`); + assert.equal(await page.locator(`#fig-${key} .${P}-hint`).evaluateAll((els) => els.filter((e) => e.checkVisibility() && e.textContent.trim()).length), 0, `${key}: no hint`); + } + await page.close(); + }); +}); diff --git a/packages/react/test/diagram-recheck.test.mjs b/packages/react/test/diagram-recheck.test.mjs new file mode 100644 index 00000000..643abb44 --- /dev/null +++ b/packages/react/test/diagram-recheck.test.mjs @@ -0,0 +1,99 @@ +// The batch B re-check's fixes in the forms node can check (the browser forms are in diagram-review.test.mjs, written while browser tests are paused): +// the text art's glyph measured at 100% in both engines, the transcript's route held with its arrow (ruling 3), the label room over a turn into a group's +// first card (ruling 4), elkjs as one copy (ruling 2), and the skill's figures written from the same engine as React's. The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { test } from "node:test"; +import { pathToFileURL } from "node:url"; + +const pkg = path.join(path.dirname(new URL(import.meta.url).pathname), ".."); +const root = path.join(pkg, "..", ".."); +const core = await import(pathToFileURL(path.join(pkg, "dist", "diagram-core.js")).href); +// The viewer's layout is bundled into diagram-viewer.js; its source has only type imports, so node strips the types and loads it as it is. +const zoom = await import(pathToFileURL(path.join(pkg, "src", "diagram-zoom-core.ts")).href); +const B = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams-b.json"), "utf8")); +const css = fs.readFileSync(path.join(pkg, "src", "styles", "components.css"), "utf8"); +const html = (spec, P = "basalt-diagram") => core.toHtml(core.figureTree(core.buildModel(spec), {}, { prefix: P, base: "d", hasSource: false, hiddenClass: P === "diagram" ? "visually-hidden" : "basalt-visually-hidden" })); + +test("the text art's glyph is measured at 100%: offsetWidth on one unbreakable run, in React and the skill, never a box a transform scales", () => { + const figure = fs.readFileSync(path.join(pkg, "src", "diagram-figure.tsx"), "utf8"); + const skill = fs.readFileSync(path.join(root, "tools", "html-skill", "src", "modules", "diagram-text.js"), "utf8"); + for (const [who, src] of [["React", figure], ["the skill", skill]]) { + const at = src.search(/"─"\.repeat\(40\)|new Array\(41\)\.join\('─'\)/); + assert.ok(at > 0, `${who}: the probe`); + const probe = src.slice(at - 400, at + 400); + assert.match(probe, /["']display:inline-block;white-space:pre["']/, `${who}: one unbreakable run`); + assert.match(probe, /probe\.offsetWidth \/ 40/, `${who}: offsetWidth, which no transform scales`); + assert.doesNotMatch(probe, /getBoundingClientRect/, `${who}: never the zoomed box`); + } +}); + +test("the viewer holds the art at the width the figure reports, whatever the zoom: the layer's width is set and its transform left alone", () => { + const layer = { style: { width: "", transform: "scale(0.5)" } }; + const memo = {}; + zoom.viewerTextWidth({ layer, avail: 1200, row: 1104, contain: 640, memo, measureFigure: () => null }, 812.2); + assert.deepEqual(layer.style, { width: "813px", transform: "scale(0.5)" }); + layer.style.transform = "scale(2)"; + zoom.viewerTextWidth({ layer, avail: 1200, row: 1104, contain: 640, memo, measureFigure: () => null }, 812.2); + assert.equal(layer.style.width, "813px", "the same at 200%"); +}); + +test("ruling 3: a transcript route's arrow and receiver are one run that never breaks, so a wrapped route's second line starts with the arrow", () => { + const m = core.buildModel(B.textSequence); + const lines = core.transcript("basalt-diagram", m).map((v) => core.toHtml(v)); + const routes = lines.filter((l) => /data-ink="num"/.test(l)); + assert.ok(routes.length > 3); + for (const l of routes) { + // The sender, a space, then one run holding the arrow, a space and the receiver: nothing after it on the line. + assert.match(l, /[^<]*<\/span> (━▶|─▶|┄▷)<\/span> [^<]*<\/span><\/span>$/, l); + } + const rule = css.match(/\.basalt-diagram-tx-name, \.basalt-diagram-tx-to \{([^}]*)\}/); + assert.ok(rule && /white-space: nowrap/.test(rule[1]), "the run does not break inside"); + // The second line hangs under the sender: the route's line has a hang of the number's digits and two spaces. + for (const l of routes) assert.match(l, /style="--_in:\d+;--_hang:\d+"/); +}); + +test("ruling 4: a group entered by a turn into its first card makes room for the turn's label, space-12 plus space-4 a line", () => { + const out = html(B.architecture); + const g = out.match(/
]*>/)?.[0]; + assert.ok(g && /data-turn=""/.test(g) && /--_tl:2/.test(g), g); + // A group no turn enters has neither. + for (const other of out.match(/
]*>/g)) if (other !== g) assert.doesNotMatch(other, /data-turn|--_tl/, other); + // An unlabelled turn keeps space-12: the group is marked, with no label lines. + const plain = structuredClone(B.architecture); + for (const e of plain.edges) if (e.to === "aurora") delete e.label; + const pg = html(plain).match(/
]*>/)?.[0]; + assert.ok(pg && /data-turn=""/.test(pg) && !/--_tl/.test(pg), pg); + assert.match(css, /\.basalt-diagram-group\[data-turn\] \{ padding-block-start: calc\(var\(--basalt-space-12\) \+ var\(--basalt-space-4\) \* var\(--_tl, 0\)\); \}/); +}); + +test("ruling 2: elkjs is a build input at exactly 0.12.1, shipped once as dist/diagram-elk.js with its licence", () => { + const p = JSON.parse(fs.readFileSync(path.join(pkg, "package.json"), "utf8")); + assert.equal(p.dependencies?.elkjs, undefined, "not a dependency an app installs"); + assert.equal(p.devDependencies?.elkjs, "0.12.1"); + const allowed = JSON.parse(fs.readFileSync(path.join(root, "dependencies.allowed.json"), "utf8")); + assert.equal(allowed.$copied?.["packages/react"]?.elkjs, "0.12.1"); + const elk = fs.readFileSync(path.join(pkg, "dist", "diagram-elk.js"), "utf8"); + assert.doesNotMatch(elk, /from\s*["']elkjs/, "the copy imports no elkjs"); + assert.ok(fs.existsSync(path.join(pkg, "dist", "elkjs", "LICENSE.md")), "its licence"); + for (const f of fs.readdirSync(path.join(pkg, "dist")).filter((f) => f.endsWith(".js") && f !== "diagram-elk.js")) assert.doesNotMatch(fs.readFileSync(path.join(pkg, "dist", f), "utf8"), /from\s*["']elkjs|import\(["']elkjs/, `${f} reaches elkjs only through diagram-elk.js`); +}); + +test("the skill writes batch B's figures from the same engine: compose.mjs's markup is the engine's, prefix for prefix", async () => { + const layout = await import(pathToFileURL(path.join(pkg, "dist", "diagram-layout.js")).href); + const { compose } = await import(pathToFileURL(path.join(root, ".agent", "skills", "basalt-html", "compose.mjs")).href); + for (const [key, spec] of Object.entries(B)) { + if (!spec?.type) continue; + const page = compose(`D
`).html; + const drawing = (s, P) => { const at = s.indexOf(`
= 0, `${key}: ${P}'s drawing`); const ends = [`
s.indexOf(e, at)).filter((e) => e > at); return s.slice(at, Math.min(...ends)); }; + // (To the ink layer, or a text figure's hint: the slots after it, the hint's keys and the foot, are each engine's own and tested with each.) + const fromSkill = drawing(page, "diagram"); + // An automatic figure is written on the placement compose.mjs made in the type's own direction; React draws on the same answer once it has it. + const auto = spec.layout === "auto"; + const placed = auto ? await layout.placeDiagram({ type: spec.type, nodes: spec.nodes, tables: spec.tables, edges: spec.edges, groups: spec.groups }, spec.direction ?? (spec.type === "flowchart" ? "down" : "right")) : undefined; + const fromEngine = drawing(core.toHtml(core.figureTree(core.buildModel(spec, { placement: placed }), {}, { prefix: "diagram", base: "d", hasSource: false, hiddenClass: "visually-hidden" })), "diagram"); + const ids = (s) => s.replace(/(id|aria-labelledby|aria-describedby|aria-controls|href)="[^"]*"/g, '$1=""'); + assert.equal(ids(fromSkill), ids(fromEngine), key); + } +}); diff --git a/packages/react/test/diagram-review.test.mjs b/packages/react/test/diagram-review.test.mjs index 13d0942b..3c254938 100644 --- a/packages/react/test/diagram-review.test.mjs +++ b/packages/react/test/diagram-review.test.mjs @@ -129,6 +129,17 @@ describe("the viewer (Fable B1 to B4, Neon B1 to B3)", () => { }, P); assert.ok(got.art && !got.scrolls && got.tx === 0, JSON.stringify(got)); assert.ok(got.width > 480, "wider than the stack's 480"); + // The art's width at 100% does not change with the zoom (both reviews' B3/B2: the glyph was measured under the layer's scale): zoom in twice, Fit, + // zoom out; at each the art is whole, and the layer's own width, which no transform scales, is the same. + const at100 = await page.evaluate((P) => { const pre = document.querySelector(`dialog.${P}-viewer .${P}-text`); return { w: pre.offsetWidth, scroll: pre.scrollWidth, client: pre.clientWidth }; }, P); + assert.equal(at100.scroll, at100.client, "the art scrolls nowhere"); + for (const key of ["=", "=", "0", "-"]) { + await page.keyboard.press(key); + await page.waitForTimeout(450); + await frames(page, 4); + const now = await page.evaluate((P) => { const pre = document.querySelector(`dialog.${P}-viewer .${P}-text`); return { art: pre.hasAttribute("data-art"), w: pre.offsetWidth, scroll: pre.scrollWidth, client: pre.clientWidth }; }, P); + assert.deepEqual(now, { art: true, w: at100.w, scroll: now.client, client: now.client }, `after ${key}`); + } await page.close(); }); @@ -201,23 +212,44 @@ describe("stacked (Fable P2, P3, answer 1; the sweep's 66-1 to 66-3)", () => { for (const r of got.rules) assert.ok(Math.abs(r.l - r.box[0]) <= 1 && Math.abs(r.w - r.box[1]) <= 1, JSON.stringify(r)); assert.ok(got.after.length > 0); for (const c of got.after) assert.match(c, /rgba\(0, 0, 0, 0\)|transparent/, "the row after a frame draws no divider"); - // Answer 1: the inner group "Data & logs" is entered by a turn: its label's plate and the turn do not meet. + // Answer 1, and the decider's ruling 4 on the re-check: the inner group "Data & logs" is entered by a labelled turn into its first card. The group has + // space-12 above that card plus space-4 for each line of the label (two lines: 80); the label lies inside the group's box, at least space-1 under the + // group label's line, its lower edge no more than space-4 above its turn; nothing grows above the group for it; and no turn point is under the + // group's label. const g = await page.evaluate((P) => { const group = [...document.querySelectorAll(`#fig-arch .${P}-group`)].find((x) => x.hasAttribute("data-turn")); if (!group) return null; + const box = group.getBoundingClientRect(); const label = group.querySelector(`:scope > .${P}-glabel`).getBoundingClientRect(); const first = group.querySelector(`.${P}-node`); const o = document.querySelector(`#fig-arch .${P}-drawing`).getBoundingClientRect(); const turns = [...document.querySelectorAll(`#fig-arch .${P}-edge`)].filter((e) => e.dataset.to === first.dataset.node).map((e) => { const n = e.querySelector(`.${P}-line`).getAttribute("d").match(/-?[\d.]+/g).map(Number); const pts = []; for (let k = 0; k + 1 < n.length; k += 2) pts.push({ x: n[k] + o.left, y: n[k + 1] + o.top }); - return pts; + const tag = document.querySelector(`#fig-arch .${P}-label[data-edge="${e.dataset.edge}"]`)?.getBoundingClientRect(); + // The turn: the last run across, the one into the card. + const end = pts.at(-1); + const across = [...pts].reverse().find((p, k, all) => k + 1 < all.length && Math.abs(all[k + 1].y - p.y) < 0.5) ?? end; + return { pts, turn: across.y, tag: tag && { t: tag.top, b: tag.bottom, l: tag.left, r: tag.right } }; }); - return { pad: getComputedStyle(group).paddingTop, label: { t: label.top, b: label.bottom, l: label.left, r: label.right }, turns }; + return { pad: getComputedStyle(group).paddingTop, grown: group.style.getPropertyValue("--_ggrow"), box: { t: box.top, b: box.bottom, l: box.left, r: box.right }, label: { t: label.top, b: label.bottom, l: label.left, r: label.right }, turns }; }, P); assert.ok(g, "a group whose first card is entered by a turn is marked"); - assert.equal(g.pad, "48px"); - for (const pts of g.turns) for (const p of pts) assert.ok(!(p.y > g.label.t && p.y < g.label.b && p.x > g.label.l && p.x < g.label.r), `no turn point under the label ${JSON.stringify(p)}`); + assert.equal(g.pad, "80px", "space-12 plus space-4 for each of the label's two lines"); + assert.equal(g.grown, "", "nothing grows above the group for it"); + const labelled = g.turns.filter((t) => t.tag); + assert.ok(labelled.length > 0, "the turn's label is drawn"); + for (const t of labelled) { + assert.ok(t.tag.t >= g.box.t && t.tag.b <= g.box.b && t.tag.l >= g.box.l - 0.5 && t.tag.r <= g.box.r + 0.5, `inside the group ${JSON.stringify({ tag: t.tag, box: g.box })}`); + assert.ok(t.tag.t >= g.label.b + 4 - 0.5, `at least space-1 under the group's label ${JSON.stringify({ tag: t.tag, label: g.label })}`); + assert.ok(t.tag.b <= t.turn + 0.5 && t.turn - t.tag.b <= 16 + 0.5, `its lower edge at most space-4 above its turn ${JSON.stringify(t)}`); + } + for (const t of g.turns) for (const p of t.pts) assert.ok(!(p.y > g.label.t && p.y < g.label.b && p.x > g.label.l && p.x < g.label.r), `no turn point under the label ${JSON.stringify(p)}`); + // An unlabelled turn keeps space-12: the same figure with the label taken off the turn's line. + const plain = structuredClone(B.architecture); + for (const e of plain.edges) if (e.to === "aurora") delete e.label; + await draw(page, [{ key: "plain", spec: plain }]); + assert.equal(await page.locator(`#fig-plain .${P}-group[data-turn]`).evaluate((x) => getComputedStyle(x).paddingTop), "48px"); await page.close(); }); @@ -251,6 +283,27 @@ describe("stacked (Fable P2, P3, answer 1; the sweep's 66-1 to 66-3)", () => { }); describe("the text sequence (Fable B6, P4, P7; Neon B6)", () => { + for (const theme of ["dark", "light"]) test(`${theme}: ruling 3, at 390 a transcript route that wraps breaks before its arrow, and its second line starts with the arrow under the sender`, async () => { + const { page } = await reviewPage({ theme, width: 390, height: 900 }); + await draw(page, [{ key: "text", spec: B.textSequence }]); + await page.waitForFunction((P) => document.querySelector(`#fig-text .${P}-tx-line`), P); + const routes = await page.evaluate((P) => [...document.querySelectorAll(`#fig-text .${P}-tx-line[data-n]`)].filter((l) => l.querySelector(`.${P}-tx-to`)).map((l) => { + const name = l.querySelector(`.${P}-tx-name`).getBoundingClientRect(); + const to = l.querySelector(`.${P}-tx-to`); + const arrow = to.firstElementChild.getBoundingClientRect(); + return { n: l.dataset.n, runs: to.getClientRects().length, wrapped: arrow.top > name.top + 1, arrowLeft: arrow.left, nameLeft: name.left, arrowTop: arrow.top, nameTop: name.top, lines: Math.round(l.getBoundingClientRect().height / parseFloat(getComputedStyle(l).lineHeight)) }; + }), P); + assert.ok(routes.length > 3); + assert.ok(routes.some((r) => r.wrapped), `at 390 some route wraps (Fable measured 1, 8 and 10) ${JSON.stringify(routes)}`); + for (const r of routes) { + assert.equal(r.runs, 1, `message ${r.n}: the arrow and the receiver never part`); + if (r.wrapped) assert.ok(Math.abs(r.arrowLeft - r.nameLeft) <= 0.5, `message ${r.n}: the arrow under the sender ${JSON.stringify(r)}`); + else assert.ok(Math.abs(r.arrowTop - r.nameTop) <= 0.5, `message ${r.n}: one line`); + assert.ok(r.lines <= 2, `message ${r.n}: two lines at most`); + } + await page.close(); + }); + test("the transcript: a message's label and note on lines of their own, each hanging under the sender inside its frame's indent; the key's focal swatch is the art's double box", async () => { const { page } = await reviewPage({ width: 390, height: 900 }); await draw(page, [{ key: "text", spec: B.textSequence }]); @@ -386,19 +439,18 @@ describe("automatic layout and the schema (Neon B8, B9, P1 to P3)", () => { }); describe("the sequence's fit and order (Neon B7, P8)", () => { - test("a self-call's words that would lie on a frame's side stack the figure; the lifelines are under the frames, the bars and lines over them", async () => { + test("words that would lie on a frame's side stack the figure, and only for that; the lifelines are under the frames, the bars and lines over them", async () => { const { page } = await reviewPage(); - const spec = { type: "sequence", title: "t", summary: "s", participants: [{ id: "a", name: "A" }, { id: "b", name: "B" }, { id: "c", name: "C" }], - steps: [{ frame: "opt", label: "only", steps: [{ from: "a", to: "b", label: "go" }, { from: "b", to: "b", label: "a self-call whose words are long" }] }, { from: "b", to: "c", label: "on" }] }; - await draw(page, [{ key: "fit", spec }, { key: "seq", spec: B.sequence }]); - const fit = await page.evaluate((P) => { - const said = document.querySelector(`#fig-fit .${P}-msg[data-self] .${P}-said`); - const box = document.querySelector(`#fig-fit .${P}-fbox`); - if (!said || !box) return { layout: document.querySelector("#fig-fit").dataset.layout }; - const s = said.getBoundingClientRect(), b = box.getBoundingClientRect(); - return { layout: document.querySelector("#fig-fit").dataset.layout, crosses: s.left < b.right && s.right > b.right }; - }, P); - assert.ok(fit.layout === "stacked" || !fit.crosses, JSON.stringify(fit)); + // Opus's fixture on the re-check (R2): a note on the first message long enough to run across the start side of the frame below it. Its two controls + // fail the test if anything but B7a's rule stacks it: the same note with no frame draws, and a short note with the frame draws. + const spec = (note, frame = true) => ({ type: "sequence", title: "t", summary: "s", participants: [{ id: "a", name: "Alpha" }, { id: "b", name: "Bravo" }, { id: "c", name: "Charlie" }], + steps: [{ from: "a", to: "b", label: "first", note }, frame ? { frame: "opt", label: "if", steps: [{ from: "b", to: "c", label: "inside" }] } : { from: "b", to: "c", label: "inside" }] }); + const LONG = "a note long enough to run across the frame's start side and over it by a wide margin"; + await draw(page, [{ key: "cross", spec: spec(LONG) }, { key: "open", spec: spec(LONG, false) }, { key: "short", spec: spec("n") }, { key: "seq", spec: B.sequence }]); + const layout = (key) => page.locator(`#fig-${key}`).getAttribute("data-layout"); + assert.equal(await layout("open"), "drawn", "the long note with no frame draws: the room rule does not stack it"); + assert.equal(await layout("short"), "drawn", "a short note with the frame draws"); + assert.equal(await layout("cross"), "stacked", "the long note over the frame's side stacks the figure"); const z = await page.evaluate((P) => { const fig = document.querySelector("#fig-seq"); const zi = (sel) => getComputedStyle(fig.querySelector(sel)).zIndex; diff --git a/packages/react/test/diagram-viewer.test.mjs b/packages/react/test/diagram-viewer.test.mjs index 51aacb5f..c3e4369a 100644 --- a/packages/react/test/diagram-viewer.test.mjs +++ b/packages/react/test/diagram-viewer.test.mjs @@ -177,6 +177,8 @@ describe("the layout width and Fit", () => { const { page } = await viewerPage({ width: 1440, height: 900 }); // Seven cards in a row and five lines out of the first: every line passes through a card, so no drawn layout is used, and its stack would need a fifth // end lane, so it draws no lines (Neon's B12: the earlier fixture was drawn, and the test passed either way). + // At the re-check this failed (Opus R2, P-R3), and the fault was the engine's: measureFigure returned the bare state without applying it, so the figure + // kept its last try's attributes and React, seeing a state equal to the one before, wrote nothing. await page.evaluate(() => window.__set([{ key: "bad", type: "architecture", props: { title: "Refused", summary: "A figure with no drawn layout.", legend: { plain: "Call" }, nodes: Array.from({ length: 7 }, (_, k) => ({ id: `n${k}`, name: `N${k}`, col: k + 1, row: 1 })), edges: [2, 3, 4, 5, 6].map((k) => ({ from: "n0", to: `n${k}`, kind: "plain" })) } }])); @@ -434,19 +436,43 @@ describe("the ink", () => { }); describe("speech, focus and the trace", () => { - test("the status line says the level once, duration-slower after the last change; a pinch of twenty moves is spoken once", async () => { - const { page } = await viewerPage({ width: 1440, height: 900 }); - await open(page, "architecture"); - await page.evaluate((P) => { const s = document.querySelector(`dialog.${P}-viewer [role="status"]`); window.__said = []; new MutationObserver(() => window.__said.push(s.textContent)).observe(s, { childList: true, characterData: true, subtree: true }); }, P); - assert.equal(await page.locator(`dialog.${P}-viewer [role="status"]`).textContent(), "", "opening says nothing"); - await page.locator(`dialog.${P}-viewer .${P}-stage`).focus(); - for (let i = 0; i < 3; i++) await page.keyboard.press("="); - await page.waitForTimeout(150); - assert.deepEqual(await page.evaluate(() => window.__said), [], "nothing while it changes"); - await page.waitForTimeout(400); - const said = await page.evaluate(() => window.__said); + test("the status line says the level once, duration-slower after the last change: three key presses, and a real pinch of twenty moves", async () => { + const watch = (page) => page.evaluate((P) => { const s = document.querySelector(`dialog.${P}-viewer [role="status"]`); window.__said = []; new MutationObserver(() => window.__said.push(s.textContent)).observe(s, { childList: true, characterData: true, subtree: true }); }, P); + const keys = await viewerPage({ width: 1440, height: 900 }); + await open(keys.page, "architecture"); + await watch(keys.page); + assert.equal(await keys.page.locator(`dialog.${P}-viewer [role="status"]`).textContent(), "", "opening says nothing"); + await keys.page.locator(`dialog.${P}-viewer .${P}-stage`).focus(); + for (let i = 0; i < 3; i++) await keys.page.keyboard.press("="); + await keys.page.waitForTimeout(150); + assert.deepEqual(await keys.page.evaluate(() => window.__said), [], "nothing while it changes"); + await keys.page.waitForTimeout(400); + const said = await keys.page.evaluate(() => window.__said); assert.equal(said.length, 1); - assert.equal(said[0], `Zoom ${await levelOf(page)}%`); + assert.equal(said[0], `Zoom ${await levelOf(keys.page)}%`); + await keys.page.close(); + // A pinch (Opus B12): two fingers on the stage, twenty moves 16ms apart, spreading from 40 to 80px; the level changes on every move and is said once. + const { page } = await viewerPage({ width: 390, height: 844, touch: true, scale: 1 }); + await open(page, "architecture", { tap: true }); + await watch(page); + const box = await page.locator(`dialog.${P}-viewer .${P}-stage`).boundingBox(); + const cx = box.x + box.width / 2, cy = box.y + box.height / 2; + const pts = (d) => [{ x: cx - d, y: cy, id: 1 }, { x: cx + d, y: cy, id: 2 }]; + const cdp = await page.context().newCDPSession(page); + const levels = []; + await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: pts(20) }); + for (let k = 1; k <= 20; k++) { + await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: pts(20 + k) }); + await page.waitForTimeout(16); + levels.push((await state(page)).zoom); + } + await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] }); + assert.ok(new Set(levels).size > 10, `the level moved with the fingers ${JSON.stringify(levels)}`); + assert.deepEqual(await page.evaluate(() => window.__said), [], "nothing while the fingers move"); + await page.waitForTimeout(600); + const spoken = await page.evaluate(() => window.__said); + assert.equal(spoken.length, 1, JSON.stringify(spoken)); + assert.equal(spoken[0], `Zoom ${await levelOf(page)}%`); await page.close(); }); diff --git a/tools/html-skill/test/diagrams.test.mjs b/tools/html-skill/test/diagrams.test.mjs index 03a54f57..5924f940 100644 --- a/tools/html-skill/test/diagrams.test.mjs +++ b/tools/html-skill/test/diagrams.test.mjs @@ -236,3 +236,50 @@ describe("batch B's fix round in the skill (Neon B8, B10)", () => { assert.ok(!JSON.stringify(out.diagrams ?? []).includes("none of its words say so"), JSON.stringify(out.diagrams)); }); }); + +// Batch B (Opus B12 on the re-check): the same comparison for the extended CIMIP figures (frames, activation bars, cardinality, far keys, groups two +// deep, the automatic layouts and the text sequence), React against the skill, in both themes at 1440 and 390. Written while browser tests are paused +// (DECISIONS 330): not run in the round that wrote it. +const DATA_B = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "cimip-diagrams-b.json"), "utf8")); +const KEYS_B = Object.keys(DATA_B).filter((k) => DATA_B[k]?.type); +const bodyB = (width = 1104) => `Diagrams B
${KEYS_B.map((k) => `
`).join("")}
`; +const REACT_B = ` +import data from "./test/fixtures/cimip-diagrams-b.json"; +const C = { architecture: B.ArchitectureDiagram, flowchart: B.FlowchartDiagram, "data-flow": B.DataFlowDiagram, sequence: B.SequenceDiagram, schema: B.SchemaDiagram }; +function Host() { return
{Object.entries(data).filter(([, d]) => d && d.type).map(([key, d]) => { const X = C[d.type]; const { type, ...props } = d; return ; })}
; } +createRoot(document.getElementById("root")).render();`; +/** Waits until every figure has settled: at 1440 an automatic layout placed and drawn (no marker says it is still placing, so its drawn layout is the + * sign), and a text sequence's art or transcript written. */ +const settled = (p, prefix, width) => p.waitForFunction(({ prefix, width }) => [...document.querySelectorAll("figure[id^='fig-']")].every((f) => f.getAttribute("data-layout") && (width < 1440 || !/^fig-auto/.test(f.id) || f.getAttribute("data-layout") === "drawn") && (!f.querySelector(`.${prefix}-text`) || f.querySelector(`.${prefix}-text`).children.length)), { prefix, width }, { timeout: 20000 }); +const readB = async (p, key, prefix) => { + const fig = await read(p, key, prefix).catch(() => null); + const text = await p.evaluate(({ key, prefix }) => { const pre = document.querySelector(`#fig-${key} .${prefix}-text`); return pre ? { art: pre.hasAttribute("data-art"), html: pre.innerHTML.replaceAll(`${prefix}-`, "P-") } : null; }, { key, prefix }); + return { fig, text }; +}; + +describe("parity with React, batch B", () => { + for (const theme of ["dark", "light"]) for (const width of [1440, 390]) { + test(`${theme} at ${width}: batch B's figures have the same layout, ink, boxes, styles and text art`, async () => { + const { page: rp, errors: re } = await fixturePage(reactBrowser, REACT_B, { theme, viewport: { width, height: 1000 }, standards: true }); + await rp.addStyleTag({ content: `${FONTS} *, ::before, ::after { box-sizing: border-box; } body { margin: 0; background: var(--basalt-surface-0); color: var(--basalt-text-primary); font: var(--basalt-font-weight-regular) var(--basalt-text-base-size) / var(--basalt-text-base-line-height) var(--basalt-font-family-sans); } #root{display:block}` }); + await rp.evaluate(() => document.fonts.ready); + const skill = await openHtml(browser, compose(bodyB()).html, { scheme: theme, width }); + await settled(rp, "basalt-diagram", width); + await settled(skill.page, "diagram", width); + for (const key of KEYS_B) { + const a = await readB(rp, key, "basalt-diagram"); + const b = await readB(skill.page, key, "diagram"); + assert.deepEqual(b.text, a.text, `${key}: the text art`); + if (!a.fig) continue; + assert.equal(b.fig.layout, a.fig.layout, `${key}: layout`); + assert.deepEqual(b.fig.boxes, a.fig.boxes, `${key}: node boxes`); + assert.equal(b.fig.ink, a.fig.ink, `${key}: the ink`); + assert.deepEqual(b.fig.styles, a.fig.styles, `${key}: computed styles`); + } + assert.deepEqual(re, []); + assert.deepEqual(skill.errors, []); + await rp.close(); + await skill.context.close(); + }); + } +}); From 40608be189d10ff7903d9b1d8419240f79f41c59 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:43:03 -0600 Subject: [PATCH 60/62] Sizes and caps: the built skill, the diagram module's cap to its measure, the export sizes The skill's diagram, diagram-text parts rebuilt from this round's sources. The diagram module's cap rises 144100 to 145100 (measured 145072), with the reason in modules.json's $comment (budgets are soft). export-sizes.json re-recorded: each diagram component +1.3% (about 1.26 KB: the first list's errors and the turn's label seats), the whole package +0.1%. Co-Authored-By: Claude Opus 5.5 --- .../skills/basalt-html/parts/diagram-text.js | 4 ++-- .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 12 ++++++------ .agent/skills/basalt-html/parts/manifest.json | 4 ++-- packages/react/test/export-sizes.json | 18 +++++++++--------- tools/html-skill/src/modules.json | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.agent/skills/basalt-html/parts/diagram-text.js b/.agent/skills/basalt-html/parts/diagram-text.js index 5b89224c..b2675f1f 100644 --- a/.agent/skills/basalt-html/parts/diagram-text.js +++ b/.agent/skills/basalt-html/parts/diagram-text.js @@ -1,2 +1,2 @@ -(()=>{var B={"&":"&","<":"<",">":">",'"':""","'":"'"},H=u=>u.replace(/[&<>"']/g,h=>B[h]);function z(u){const h=u.nodes,A=u.steps,d=n=>Array.from(n).length,b=h.map(n=>Math.max(8,d(n.name)+4)),r=h.map(()=>0);let _=0;h.forEach((n,t)=>{r[t]=_+Math.floor(b[t]/2),_+=b[t]+4});const S=(n,t,o)=>{const[s,a]=n0)for(let i=a;i0&&S(t-1,t,s+8):S(t,o,s+4)}const M=h.length-1,x=new Map;{let n=0;const t=[],o=(a,f)=>r[a]-Math.floor(b[a]/2)-1+f,s=(a,f)=>r[a]+Math.ceil(b[a]/2)-f;A.forEach((a,f)=>{if("open"in a){t.push({at:f,a:a.a-1,b:a.b-1,inset:n*2,need:d(`[${a.open}]`)+1+d(` ${a.label} `)+2}),n++;return}if("otherwise"in a){const i=t[t.length-1];i&&(i.need=Math.max(i.need,d("[else]")+1+d(` ${a.otherwise} `)+2));return}if("close"in a){n=Math.max(0,n-1);const i=t.pop();if(!i)return;const k=x.get(i.at)??0,m=i.need-(s(i.b,i.inset)-o(i.a,i.inset))-k;if(m>0){if(i.b"n"in n&&n.from===n.to&&(u.byId.get(n.from)?.i??0)===M?d(`${n.n} ${n.label}`)+8:0)),w=(r[M]??0)+Math.ceil((b[M]??8)/2)+W+2+Math.max(0,...x.values()),I=[],p=()=>{const n={ch:Array(w).fill(" "),ink:Array(w).fill("")};return I.push(n),n},l=(n,t,o,s)=>{Array.from(o).forEach((a,f)=>{const i=t+f;i>=0&&iu.bars.some(o=>o.who===h[n].id&&o.from<=t&&o.to>=t);let R=0;const y=n=>h.forEach((t,o)=>l(n,r[o],q(o,R)?"┃":"│",q(o,R)?"working":"life")),D=p(),T=p(),G=p();h.forEach((n,t)=>{const o=r[t]-Math.floor(b[t]/2),s=b[t],[a,f,i,k,m,$]=n.focal?["╔","═","╗","║","╚","╝"]:["┌","─","┐","│","└","┘"],e=n.focal?"focal":"name";l(D,o,a+f.repeat(s-2)+i,e),l(T,o,k,e),l(T,o+s-1,k,e),l(T,o+Math.floor((s-d(n.name))/2),n.name,e),l(G,o,m+f.repeat(s-2)+$,e)});const j=[],v=n=>{for(const t of j)l(n,t.l,"│","frame"),l(n,t.r,"│","frame")},F=()=>{const n=p();return y(n),v(n),n};F();for(const[n,t]of A.entries()){if("band"in t){const e=p(),c=` ${t.band} `;l(e,0,"─".repeat(w),"band"),l(e,Math.max(0,Math.floor((w-d(c))/2)),c,"band"),F();continue}if("open"in t){const e=t.a-1,c=t.b-1,L=j.length*2,g={l:Math.max(0,r[e]-Math.floor(b[e]/2)-1+L),r:Math.min(w-1,r[c]+Math.ceil(b[c]/2)+(c===M&&A.some(C=>"n"in C&&C.from===C.to)?W:0)-L+(x.get(n)??0))},E=p();y(E),v(E),l(E,g.l,"┌"+"─".repeat(g.r-g.l-1)+"┐","frame"),l(E,g.l+1,`[${t.open}]`,"op"),l(E,g.l+d(t.open)+4,` ${t.label} `,"label"),j.push(g),F();continue}if("otherwise"in t){const e=j[j.length-1];if(!e)continue;const c=p();y(c),v(c),l(c,e.l,"├"+"┄".repeat(e.r-e.l-1)+"┤","frame"),l(c,e.l+1,"[else]","op"),l(c,e.l+8,` ${t.otherwise} `,"label"),F();continue}if("close"in t){const e=j.pop();if(!e)continue;const c=p();y(c),v(c),l(c,e.l,"└"+"─".repeat(e.r-e.l-1)+"┘","frame"),F();continue}R=t.n;const o=u.byId.get(t.from)?.i??0,s=u.byId.get(t.to)?.i??0,a=`${t.n} ${t.label}`,f=e=>e==="main"?"━":e==="dashed"?"┄":"─",i=(e,c)=>e==="dashed"?c?"▷":"◁":c?"▶":"◀",k=t.kind==="main"?"main":"plain",m=p(),$=p();if(m.n=t.n,$.n=t.n,y(m),v(m),y($),v($),o===s){const e=o===M&&h.length>1,c=e?r[o]-4:r[o]+1;l(m,c,e?"┌──":"──┐",k),l($,c,e?"└─"+i(t.kind,!0):i(t.kind,!1)+"─┘",k);const L=e?c-d(a)-1:r[o]+5;if(l(m,L,a.slice(0,d(String(t.n))),"num"),l(m,L+d(String(t.n))+1,t.label,"label"),t.note){const g=p();y(g),v(g),l(g,e?c-d(t.note)-1:r[o]+5,t.note,"note")}}else{const e=Math.min(r[o],r[s]),c=Math.max(r[o],r[s]),L=r[s]>r[o],g=e+Math.max(2,Math.floor((c-e-d(a))/2));l(m,g-1," ",""),l(m,g,String(t.n),"num"),l(m,g+d(String(t.n))," "+t.label+" ","label");const E=f(t.kind).repeat(Math.max(1,c-e-2));if(l($,e+1,L?E+i(t.kind,!0):i(t.kind,!1)+E,k),t.note){const C=p();y(C),v(C);const J=e+Math.max(2,Math.floor((c-e-d(t.note))/2));l(C,J-1,` ${t.note} `,"note")}}}return F(),{html:I.map(n=>{const t=n.ch.join("").trimEnd().length;let o="",s="",a=n.ink[0]??"";for(let f=0;f${H(s)}`:H(s),s=""),a=n.ink[f],s+=n.ch[f];return s&&(o+=a?`${H(s)}`:H(s)),n.n?`${o}`:o}).join(` -`),width:Math.max(...I.map(n=>n.ch.join("").trimEnd().length))}}(function(u){"use strict";u._.diagramText=function(h,A,d,b){var r=h.querySelector(".diagram-text"),_=r&&r.querySelector(".diagram-text-ink");if(_){h.__transcript||(h.__transcript=_.innerHTML);var S=z(A),M=document.createElement("span");M.textContent=new Array(41).join("─"),r.appendChild(M);var x=M.getBoundingClientRect().width/40;M.remove();var W=getComputedStyle(r),w=r.clientWidth-parseFloat(W.paddingLeft)-parseFloat(W.paddingRight);b&&b.textWidth&&(b.textWidth(S.width*x+(h.clientWidth-w)+1),w=r.clientWidth-parseFloat(W.paddingLeft)-parseFloat(W.paddingRight));var I=S.width*x<=w+.5,p=I?S.html:h.__transcript;_.innerHTML!==p&&(_.innerHTML=p),r.toggleAttribute("data-art",I)}}})(window.Basalt)})(); +(()=>{var B={"&":"&","<":"<",">":">",'"':""","'":"'"},F=u=>u.replace(/[&<>"']/g,h=>B[h]);function z(u){const h=u.nodes,A=u.steps,d=n=>Array.from(n).length,b=h.map(n=>Math.max(8,d(n.name)+4)),r=h.map(()=>0);let W=0;h.forEach((n,t)=>{r[t]=W+Math.floor(b[t]/2),W+=b[t]+4});const _=(n,t,o)=>{const[s,a]=n0)for(let i=a;i0&&_(t-1,t,s+8):_(t,o,s+4)}const M=h.length-1,x=new Map;{let n=0;const t=[],o=(a,f)=>r[a]-Math.floor(b[a]/2)-1+f,s=(a,f)=>r[a]+Math.ceil(b[a]/2)-f;A.forEach((a,f)=>{if("open"in a){t.push({at:f,a:a.a-1,b:a.b-1,inset:n*2,need:d(`[${a.open}]`)+1+d(` ${a.label} `)+2}),n++;return}if("otherwise"in a){const i=t[t.length-1];i&&(i.need=Math.max(i.need,d("[else]")+1+d(` ${a.otherwise} `)+2));return}if("close"in a){n=Math.max(0,n-1);const i=t.pop();if(!i)return;const k=x.get(i.at)??0,m=i.need-(s(i.b,i.inset)-o(i.a,i.inset))-k;if(m>0){if(i.b"n"in n&&n.from===n.to&&(u.byId.get(n.from)?.i??0)===M?d(`${n.n} ${n.label}`)+8:0)),w=(r[M]??0)+Math.ceil((b[M]??8)/2)+S+2+Math.max(0,...x.values()),T=[],p=()=>{const n={ch:Array(w).fill(" "),ink:Array(w).fill("")};return T.push(n),n},l=(n,t,o,s)=>{Array.from(o).forEach((a,f)=>{const i=t+f;i>=0&&iu.bars.some(o=>o.who===h[n].id&&o.from<=t&&o.to>=t);let H=0;const y=n=>h.forEach((t,o)=>l(n,r[o],R(o,H)?"┃":"│",R(o,H)?"working":"life")),D=p(),q=p(),G=p();h.forEach((n,t)=>{const o=r[t]-Math.floor(b[t]/2),s=b[t],[a,f,i,k,m,$]=n.focal?["╔","═","╗","║","╚","╝"]:["┌","─","┐","│","└","┘"],e=n.focal?"focal":"name";l(D,o,a+f.repeat(s-2)+i,e),l(q,o,k,e),l(q,o+s-1,k,e),l(q,o+Math.floor((s-d(n.name))/2),n.name,e),l(G,o,m+f.repeat(s-2)+$,e)});const j=[],v=n=>{for(const t of j)l(n,t.l,"│","frame"),l(n,t.r,"│","frame")},C=()=>{const n=p();return y(n),v(n),n};C();for(const[n,t]of A.entries()){if("band"in t){const e=p(),c=` ${t.band} `;l(e,0,"─".repeat(w),"band"),l(e,Math.max(0,Math.floor((w-d(c))/2)),c,"band"),C();continue}if("open"in t){const e=t.a-1,c=t.b-1,L=j.length*2,g={l:Math.max(0,r[e]-Math.floor(b[e]/2)-1+L),r:Math.min(w-1,r[c]+Math.ceil(b[c]/2)+(c===M&&A.some(I=>"n"in I&&I.from===I.to)?S:0)-L+(x.get(n)??0))},E=p();y(E),v(E),l(E,g.l,"┌"+"─".repeat(g.r-g.l-1)+"┐","frame"),l(E,g.l+1,`[${t.open}]`,"op"),l(E,g.l+d(t.open)+4,` ${t.label} `,"label"),j.push(g),C();continue}if("otherwise"in t){const e=j[j.length-1];if(!e)continue;const c=p();y(c),v(c),l(c,e.l,"├"+"┄".repeat(e.r-e.l-1)+"┤","frame"),l(c,e.l+1,"[else]","op"),l(c,e.l+8,` ${t.otherwise} `,"label"),C();continue}if("close"in t){const e=j.pop();if(!e)continue;const c=p();y(c),v(c),l(c,e.l,"└"+"─".repeat(e.r-e.l-1)+"┘","frame"),C();continue}H=t.n;const o=u.byId.get(t.from)?.i??0,s=u.byId.get(t.to)?.i??0,a=`${t.n} ${t.label}`,f=e=>e==="main"?"━":e==="dashed"?"┄":"─",i=(e,c)=>e==="dashed"?c?"▷":"◁":c?"▶":"◀",k=t.kind==="main"?"main":"plain",m=p(),$=p();if(m.n=t.n,$.n=t.n,y(m),v(m),y($),v($),o===s){const e=o===M&&h.length>1,c=e?r[o]-4:r[o]+1;l(m,c,e?"┌──":"──┐",k),l($,c,e?"└─"+i(t.kind,!0):i(t.kind,!1)+"─┘",k);const L=e?c-d(a)-1:r[o]+5;if(l(m,L,a.slice(0,d(String(t.n))),"num"),l(m,L+d(String(t.n))+1,t.label,"label"),t.note){const g=p();y(g),v(g),l(g,e?c-d(t.note)-1:r[o]+5,t.note,"note")}}else{const e=Math.min(r[o],r[s]),c=Math.max(r[o],r[s]),L=r[s]>r[o],g=e+Math.max(2,Math.floor((c-e-d(a))/2));l(m,g-1," ",""),l(m,g,String(t.n),"num"),l(m,g+d(String(t.n))," "+t.label+" ","label");const E=f(t.kind).repeat(Math.max(1,c-e-2));if(l($,e+1,L?E+i(t.kind,!0):i(t.kind,!1)+E,k),t.note){const I=p();y(I),v(I);const J=e+Math.max(2,Math.floor((c-e-d(t.note))/2));l(I,J-1,` ${t.note} `,"note")}}}return C(),{html:T.map(n=>{const t=n.ch.join("").trimEnd().length;let o="",s="",a=n.ink[0]??"";for(let f=0;f${F(s)}`:F(s),s=""),a=n.ink[f],s+=n.ch[f];return s&&(o+=a?`${F(s)}`:F(s)),n.n?`${o}`:o}).join(` +`),width:Math.max(...T.map(n=>n.ch.join("").trimEnd().length))}}(function(u){"use strict";u._.diagramText=function(h,A,d,b){var r=h.querySelector(".diagram-text"),W=r&&r.querySelector(".diagram-text-ink");if(W){h.__transcript||(h.__transcript=W.innerHTML);var _=z(A),M=document.createElement("span");M.style.cssText="display:inline-block;white-space:pre",M.textContent=new Array(41).join("─"),r.appendChild(M);var x=M.offsetWidth/40;M.remove();var S=getComputedStyle(r),w=r.clientWidth-parseFloat(S.paddingLeft)-parseFloat(S.paddingRight);b&&b.textWidth&&(b.textWidth(_.width*x+(h.clientWidth-w)+1),w=r.clientWidth-parseFloat(S.paddingLeft)-parseFloat(S.paddingRight));var T=_.width*x<=w+.5,p=T?_.html:h.__transcript;W.innerHTML!==p&&(W.innerHTML=p),r.toggleAttribute("data-art",T)}}})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index 69ce8bdd..9258fd20 100644 --- a/.agent/skills/basalt-html/parts/diagram.css +++ b/.agent/skills/basalt-html/parts/diagram.css @@ -1 +1 @@ -:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--_gw, var(--basalt-space-10))}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);--_Rows: var(--_D) var(--_rows, none);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));grid-template-rows:var(--_Rows, none);gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=schema][data-marks]>.diagram-drawing{--_col-gap: calc(var(--basalt-space-12) + var(--basalt-space-3))}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] .diagram-group>.diagram-glabel{inset-inline:auto var(--basalt-space-3);margin-inline:0 calc(-1 * var(--basalt-space-1-5))}.diagram[data-rtl] .diagram-runs{direction:ltr;unicode-bidi:isolate}.diagram[data-rtl] .diagram-fhead{inset-inline-start:calc(100% - var(--_fl) - var(--_fw) + var(--basalt-size-hairline))}.diagram[data-rtl] .diagram-felse{padding-inline-start:calc(100% - var(--_fl) - var(--_fw) + var(--basalt-space-3))}.diagram[data-rtl] .diagram-felse:before{inset-inline-start:var(--_Fer, calc(-1 * var(--basalt-space-4)))}.diagram[data-rtl] .diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) left;margin-inline-start:0;margin-inline-end:var(--_Sm, 0)}.diagram[data-rtl] .diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) right;margin-inline-end:0;margin-inline-start:var(--_Sm, 0)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node{--_Mh: var(--_D) var(--_mh, auto);min-height:var(--_Mh, auto)}.diagram-node{--_Jc: var(--_D) normal;justify-content:var(--_Jc, center)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group:first-child{margin-block-start:0}.diagram-group[data-turn]{padding-block-start:calc(var(--basalt-space-8) + var(--basalt-space-4))}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram[data-type=sequence]>.diagram-drawing>.diagram-ink{z-index:auto}.diagram-lifes{position:absolute;top:0;left:0;z-index:0;overflow:visible}.diagram[data-type=sequence] .diagram-ink>.diagram-svg{z-index:2}.diagram[data-type=sequence] .diagram-steps{z-index:auto}.diagram[data-type=sequence] .diagram-msg :is(.diagram-said,.diagram-note){position:relative;z-index:3}.diagram[data-type=sequence] :is(.diagram-fhead,.diagram-felse){z-index:3}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-crow{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:butt;stroke-linejoin:miter;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-ring{fill:var(--_ground);stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-frame+.diagram-msgs>.diagram-msg:first-child{border-top-color:transparent}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;column-gap:var(--basalt-space-1);row-gap:0;flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-to{display:inline-flex;align-items:center;gap:var(--basalt-space-1);white-space:nowrap}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);--_Fel: var(--_D) var(--_fl);--_Few: var(--_D) var(--_fw);--_Fer: var(--_D) calc(100% - var(--_fl) - var(--_fw));position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_Fel, calc(-1 * var(--basalt-space-4)));width:var(--_Few, calc(100% + 2 * var(--basalt-space-4)));height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text-ink{font:inherit}.diagram-tx-name{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-tx-line{display:block;padding-inline-start:calc(var(--_in, 0) * 1ch);text-indent:calc(-1 * var(--_hang, 0) * 1ch)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}.diagram-key-glyph[data-ink=focal]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-crow,.diagram-ring,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"]:not([data-marks]))>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 792px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 1076px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1360px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1644px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-lifes,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram :is(.diagram-crow,.diagram-ring){stroke:CanvasText}.diagram .diagram-ring{fill:Canvas}.diagram .diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:GrayText}.diagram .diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-lifes,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear,.diagram-download{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-text [data-n][data-ahead] [data-ink=label],.diagram[data-motion=animated][data-entrance=pending] .diagram-text [data-n] [data-ink=label]{color:var(--basalt-text-secondary)}.diagram-text [data-n][data-ahead] :is([data-ink=main],[data-ink=plain]),.diagram[data-motion=animated][data-entrance=pending] .diagram-text [data-n] :is([data-ink=main],[data-ink=plain]){color:var(--basalt-text-tertiary)}.diagram-text [data-n][data-arrival] [data-ink=num]{color:var(--basalt-text-primary)}@media(prefers-reduced-motion:reduce){.diagram-msg[data-ahead] .diagram-mlabel{transition:none}}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:GrayText}.diagram .diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-text [data-n][data-ahead] [data-ink]{color:GrayText}.diagram .diagram-text [data-n][data-arrival] [data-ink=num]{color:Highlight}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} +:root{--basalt-size-diagram-node: 144px;--basalt-size-diagram-table: 224px;--basalt-size-diagram-lane: 120px;--basalt-size-diagram-step: 56px;--basalt-size-diagram-head: 8px;--basalt-size-diagram-activation: 8px;--basalt-size-diagram-foot: 14px;--basalt-size-diagram-guide-dash: 4px;--basalt-size-diagram-bead: 24px;--basalt-size-diagram-flow: 12px}:root,[data-theme=light],.light{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-white-6);--basalt-diagram-focal-rule-contrast: var(--basalt-white-38);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}[data-theme=dark],.dark{--basalt-diagram-edge-main: var(--basalt-text-primary);--basalt-diagram-edge: var(--basalt-text-secondary);--basalt-diagram-edge-dim: var(--basalt-border-input);--basalt-diagram-structure: var(--basalt-border-input);--basalt-diagram-focal: var(--basalt-action-primary);--basalt-diagram-focal-ink: var(--basalt-action-primary-text);--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45);--basalt-diagram-hit: var(--basalt-text-secondary);--basalt-diagram-focal-hit: var(--basalt-action-primary-hover)}@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-black-8);--basalt-diagram-focal-rule-contrast: var(--basalt-black-45)}}@media(prefers-contrast:more){:root,[data-theme=light],[data-theme=dark],.light,.dark,:root:not([data-theme=light]):not(.light){--basalt-diagram-focal-rule: var(--basalt-diagram-focal-rule-contrast);--basalt-diagram-hit: var(--basalt-text-primary)}}@layer basalt{.diagram{--_ground: var(--panel-bg, var(--basalt-surface-page));container-type:inline-size;display:flex;flex-direction:column;gap:var(--basalt-space-4);width:100%;min-width:0;margin:0;font-family:var(--basalt-font-family-sans)}.diagram[hidden]{display:none}.diagram-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-title{margin:0;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-md);letter-spacing:var(--basalt-text-md-tracking)}.diagram-source{margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-drawing{--_D: initial;--_Display: var(--_D) grid;--_Max: var(--_D) none;--_Cols: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Gap: var(--_D) var(--_row-gap) var(--_col-gap);--_Pad: var(--_D) var(--_gpad, 0);--_row-gap: var(--basalt-space-12);--_col-gap: var(--basalt-space-16);position:relative;box-sizing:border-box;display:var(--_Display, flex);flex-direction:column;grid-template-columns:var(--_Cols, none);gap:var(--_Gap, 0);width:100%;max-width:var(--_Max, var(--basalt-size-breakpoint-container));min-width:0;padding:var(--_Pad, 0 var(--_gutter, 0) 0 0)}.diagram[data-layout=drawn]>.diagram-drawing{--_D: }.diagram[data-layout=stacked]>.diagram-drawing{--_D: initial}.diagram[data-gutter]>.diagram-drawing{--_gutter: var(--_gw, var(--basalt-space-10))}.diagram[data-type=data-flow]>.diagram-drawing{--_Cols: var(--_D) var(--basalt-size-diagram-lane) repeat(var(--_cols, 1), minmax(0, 1fr));--_row-gap: var(--basalt-space-10);--_col-gap: var(--basalt-space-12)}.diagram[data-type=schema]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-12);--_Rows: var(--_D) var(--_rows, none);display:grid;grid-template-columns:var(--_Cols, repeat(auto-fit, minmax(min(100%, var(--_track, var(--basalt-size-diagram-table))), 1fr)));grid-template-rows:var(--_Rows, none);gap:var(--_Gap, var(--basalt-space-4));align-items:start;max-width:none}.diagram[data-type=schema][data-marks]>.diagram-drawing{--_col-gap: calc(var(--basalt-space-12) + var(--basalt-space-3))}.diagram[data-type=sequence]>.diagram-drawing{display:flex;gap:0}.diagram[data-rtl]>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing :is(.diagram-node>:not(.diagram-mark),.diagram-lane-name,.diagram-said,.diagram-note,.diagram-band,.diagram-fhead,.diagram-felse){direction:rtl}.diagram[data-rtl] .diagram-gbox>.diagram-glabel{inset-inline:auto var(--basalt-space-3)}.diagram[data-rtl] .diagram-group>.diagram-glabel{inset-inline:auto var(--basalt-space-3);margin-inline:0 calc(-1 * var(--basalt-space-1-5))}.diagram[data-rtl] .diagram-runs{direction:ltr;unicode-bidi:isolate}.diagram[data-rtl] .diagram-fhead{inset-inline-start:calc(100% - var(--_fl) - var(--_fw) + var(--basalt-size-hairline))}.diagram[data-rtl] .diagram-felse{padding-inline-start:calc(100% - var(--_fl) - var(--_fw) + var(--basalt-space-3))}.diagram[data-rtl] .diagram-felse:before{inset-inline-start:var(--_Fer, calc(-1 * var(--basalt-space-4)))}.diagram[data-rtl] .diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) left;margin-inline-start:0;margin-inline-end:var(--_Sm, 0)}.diagram[data-rtl] .diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) right;margin-inline-end:0;margin-inline-start:var(--_Sm, 0)}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-tname,.diagram-cname,.diagram-ctype,.diagram-label,.diagram-glabel,.diagram-kind){unicode-bidi:isolate}.diagram[data-rtl] :is(.diagram-run,.diagram-mlabel,.diagram-cname,.diagram-label){direction:ltr}.diagram[data-rtl] .diagram-arrow{scale:-1 1}.diagram-node{--_Gc: var(--_D) var(--_c);--_Gr: var(--_D) var(--_r) / var(--_r2);--_Mt: var(--_D) 0;--_Align: var(--_D) center;position:relative;z-index:1;box-sizing:border-box;display:flex;flex-direction:column;min-width:0;grid-column:var(--_Gc, auto);grid-row:var(--_Gr, auto);align-self:var(--_Align, stretch);margin-block-start:var(--_Mt, var(--_gap, 0));padding:var(--basalt-space-2-5) var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);color:var(--basalt-text-primary);overflow-wrap:break-word;outline:none;transition:border-color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-type=data-flow] .diagram-node{--_Gc: var(--_D) var(--_lc)}.diagram-node{--_Mh: var(--_D) var(--_mh, auto);min-height:var(--_Mh, auto)}.diagram-node{--_Jc: var(--_D) normal;justify-content:var(--_Jc, center)}.diagram-node[data-branch]{--_Mi: var(--_D) 0;margin-inline:var(--_Mi, var(--basalt-space-12) var(--basalt-space-6))}.diagram-node:focus-visible{z-index:2;outline:var(--basalt-size-focus-width) solid var(--basalt-border-focus);outline-offset:var(--basalt-size-focus-offset)}.diagram-node[data-near]{border-color:var(--basalt-border-hover)}.diagram-kind{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-lane-word{--_Lw: var(--_D) none;display:var(--_Lw, inline)}.diagram-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-detail{margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-detail[data-mono]{font-family:var(--basalt-font-family-mono)}.diagram-run{display:inline-block;max-width:100%}:root,[data-theme=light],.light{--_dkm: initial}[data-theme=dark],.dark{--_dkm: }@media(prefers-color-scheme:dark){:root:not([data-theme=light]):not(.light){--_dkm: }}.diagram-mark{--_mf: var(--_dkm) var(--_md);position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);background:var(--_mf, var(--_ml)) center / contain no-repeat;pointer-events:none}.diagram-node[data-focal]>.diagram-mark{--_mf: var(--_dkm) var(--_ml);background-image:var(--_mf, var(--_md, var(--_ml)))}.diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:var(--basalt-space-6)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline:var(--basalt-space-6)}.diagram-node[data-shape=participant]>.diagram-mark{--_Pmp: var(--_D) absolute;position:var(--_Pmp, static);flex:none;margin-inline-end:var(--_Pmm, var(--basalt-space-1-5));--_Pmm: var(--_D) 0}.diagram-node[data-shape=participant][data-mark]{--_Pfd: var(--_D) column;flex-direction:var(--_Pfd, row)}.diagram-node[data-shape=participant][data-mark]>.diagram-mark+.diagram-name{--_Pnp: var(--_D) var(--basalt-space-6);padding-inline:var(--_Pnp, 0)}.diagram-node[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:var(--basalt-opacity-amount)}.diagram[data-type=flowchart] .diagram-node:not([data-focal]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=flowchart] .diagram-node:not([data-focal],[data-shape=decision])[data-near]{border-color:var(--basalt-text-secondary)}.diagram-node[data-shape=terminal]{align-items:center;padding-inline:var(--basalt-space-5);border-radius:var(--basalt-radius-full);text-align:center}.diagram-node[data-shape=decision]{justify-content:center;align-items:center;height:var(--_h, auto);min-height:var(--basalt-space-16);padding:var(--basalt-space-2) var(--basalt-space-2-5);text-align:center}.diagram-words{position:relative;max-width:var(--_ww, calc(62% + (var(--basalt-space-2-5) + var(--basalt-size-hairline)) * 1.24))}.diagram-node[data-shape=decision] .diagram-name{font-weight:var(--basalt-font-weight-medium);text-wrap:balance}.diagram-diamond{display:none;position:absolute;inset:0;width:100%;height:100%;overflow:visible}.diagram-diamond path{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);vector-effect:non-scaling-stroke;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram[data-measured] .diagram-node[data-shape=decision]{background:none;border-color:transparent}.diagram[data-measured] .diagram-node[data-shape=decision] .diagram-diamond{display:block}.diagram-node[data-shape=decision][data-near] .diagram-diamond path{stroke:var(--basalt-text-secondary)}.diagram-node[data-shape=decision][data-focal] .diagram-diamond path{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-node[data-link]{color:inherit;text-decoration:none;-webkit-tap-highlight-color:transparent}.diagram-name-end{white-space:nowrap}.diagram-node[data-link] .diagram-name-end:after{content:"";display:inline-block;width:var(--basalt-size-icon-sm);height:var(--basalt-size-icon-sm);margin-inline-start:var(--basalt-space-1-5);vertical-align:calc(-1 * var(--basalt-space-0-5));background:var(--basalt-text-secondary);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.5 12L17.5 12M17.5 12L11.5 7M17.5 12L11.5 17' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;transition:transform var(--basalt-duration-base) var(--basalt-ease-out),background-color var(--basalt-duration-base) var(--basalt-ease-out)}.diagram-node[data-link=external] .diagram-name-end:after{mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 17L17 7M9.5 7L17 7M17 7L17 14.5' fill='none' stroke='black' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")}.diagram-node[data-link][data-focal] .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:var(--basalt-opacity-amount)}.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-text-primary);transform:translate(var(--basalt-space-0-5))}.diagram-node[data-link][data-focal]:is(:hover,:focus-visible) .diagram-name-end:after{background:var(--basalt-diagram-focal-ink);opacity:1}.diagram-node[data-link]:is(:hover,:focus-visible) :is(.diagram-name,.diagram-tname){text-decoration:underline var(--basalt-size-hairline);text-underline-offset:var(--basalt-size-underline-offset)}.diagram-node[data-link]:active{background:light-dark(color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))),color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))))}@supports not (color: light-dark(white,black)){.diagram-node[data-link]:active{background:color-mix(in srgb,color-mix(in srgb,var(--basalt-neutral-100) 6%,var(--panel-next, var(--basalt-surface-1))) var(--_dkp),color-mix(in srgb,var(--basalt-neutral-0) 4%,var(--panel-next, var(--basalt-surface-1))))}}.diagram-node[data-link][data-focal]:active{background:var(--basalt-action-primary-press)}.diagram-node[data-link]:dir(rtl) .diagram-name-end:after{scale:-1 1}.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:translate(calc(-1 * var(--basalt-space-0-5)))}@media(prefers-reduced-motion:reduce){.diagram-node[data-link]:is(:hover,:focus-visible) .diagram-name-end:after,.diagram-node[data-link]:dir(rtl):is(:hover,:focus-visible) .diagram-name-end:after{transform:none}}@media(pointer:coarse){.diagram-node[data-link]{min-height:var(--basalt-size-tap-min)}}@media(forced-colors:active){.diagram .diagram-node[data-link] :is(.diagram-name,.diagram-tname){color:LinkText;text-decoration:underline}.diagram .diagram-node[data-link] .diagram-name-end:after{forced-color-adjust:none;background:LinkText}.diagram .diagram-node[data-link][data-focal] :is(.diagram-name,.diagram-tname){color:Canvas}.diagram .diagram-node[data-link][data-focal] .diagram-name-end:after{background:Canvas}}.diagram-group{--_Gd: var(--_D) contents;position:relative;box-sizing:border-box;display:var(--_Gd, flex);flex-direction:column;margin-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_ggrow, 0));padding:var(--basalt-space-8) var(--basalt-space-3) var(--basalt-space-3-5);border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg)}.diagram-group{--_tl: 0}.diagram-group:first-child{margin-block-start:0}.diagram-group[data-turn]{padding-block-start:calc(var(--basalt-space-12) + var(--basalt-space-4) * var(--_tl, 0))}.diagram-group>.diagram-glabel+.diagram-node{--_Mt: 0}.diagram-glabel{position:absolute;top:var(--basalt-space-2);inset-inline-start:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);white-space:nowrap}.diagram-group>.diagram-glabel{--_Gl: var(--_D) none;display:var(--_Gl, block)}.diagram-group>.diagram-glabel{z-index:1;margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground)}.diagram-gbox{--_Gb: var(--_D) block;position:relative;display:var(--_Gb, none);grid-column:var(--_c) / var(--_c2);grid-row:var(--_r) / var(--_r2);margin-block:calc(-1 * var(--_gt, 1) * var(--basalt-space-8)) calc(-1 * var(--_gb, 1) * var(--basalt-space-4));margin-inline:calc(-1 * var(--_gs, 1) * var(--basalt-space-4)) calc(-1 * var(--_ge, 1) * var(--basalt-space-4));border:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-gbox[data-depth="2"],.diagram-group[data-depth="2"]{border-radius:var(--basalt-radius-md)}.diagram-list-group[data-depth="2"],.diagram-list-items[data-depth="2"]{margin-inline-start:var(--basalt-space-5)}.diagram-lane{--_Ln: var(--_D) flex;position:relative;display:var(--_Ln, none);grid-column:1 / -1;grid-row:var(--_r);align-items:center;pointer-events:none}.diagram-lane+.diagram-lane:before{content:"";position:absolute;inset-inline:0;top:calc(-1 * var(--basalt-space-5));border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-lane-name{box-sizing:border-box;width:var(--basalt-size-diagram-lane);padding-inline-end:var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-ink{position:absolute;inset:0;z-index:0;pointer-events:none}.diagram[data-type=sequence]>.diagram-drawing>.diagram-ink{z-index:auto}.diagram-lifes{position:absolute;top:0;left:0;z-index:0;overflow:visible}.diagram[data-type=sequence] .diagram-ink>.diagram-svg{z-index:2}.diagram[data-type=sequence] .diagram-steps{z-index:auto}.diagram[data-type=sequence] .diagram-msg :is(.diagram-said,.diagram-note){position:relative;z-index:3}.diagram[data-type=sequence] :is(.diagram-fhead,.diagram-felse){z-index:3}.diagram-svg{position:absolute;top:0;left:0;overflow:visible}.diagram-ruler{position:absolute;visibility:hidden;white-space:pre;pointer-events:none}.diagram-ruler[data-f=name]{font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-ruler[data-f=name-500]{font:var(--basalt-font-weight-medium) var(--bh-sm)}.diagram-ruler[data-f=table]{font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-ruler:is([data-f=mono],[data-f=label]){font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-ruler[data-f=sans]{font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram-line[data-kind=dashed]{stroke-dasharray:var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap);stroke-linecap:butt}.diagram-tip{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out),stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-tip[data-kind=main]{fill:var(--basalt-diagram-edge-main)}.diagram-tip[data-open]{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round;stroke-linejoin:round}.diagram-dot{fill:var(--basalt-diagram-edge)}.diagram-crow{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:butt;stroke-linejoin:miter;transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-ring{fill:var(--_ground);stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-life{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-edge[data-lit] .diagram-line{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip:not([data-open]),.diagram-edge[data-lit] .diagram-dot{fill:var(--basalt-diagram-edge-main)}.diagram-edge[data-lit] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip:not([data-open]),.diagram-edge[data-dim] .diagram-dot{fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-dim] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-main)}.diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge-dim)}.diagram-label{position:absolute;box-sizing:border-box;height:var(--basalt-text-xs-line-height);color:var(--basalt-diagram-edge);font:var(--basalt-font-weight-regular) var(--bh-xs-mono);text-align:center;white-space:nowrap;transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-label[data-on]{background:var(--_ground)}.diagram-label[data-lines="2"]{height:calc(2 * var(--basalt-text-xs-line-height))}.diagram-label[data-lit]{color:var(--basalt-diagram-edge-main)}.diagram-cast{--_Cd: var(--_D) grid;display:var(--_Cd, flex);flex-wrap:wrap;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));gap:var(--_Cast-gap, var(--basalt-space-1-5));--_Cast-gap: var(--_D) var(--basalt-space-5);margin:0;padding:0;list-style:none}.diagram-actor{--_Ac: var(--_D) var(--_ac, auto);display:flex;min-width:0;grid-column:var(--_Ac, auto);grid-row:1}.diagram-node[data-shape=participant]{--_Pd: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);--_Pr: var(--_D) var(--basalt-radius-md);--_Pa: var(--_D) center;flex:var(--_Pflex, none);--_Pflex: var(--_D) 1;align-items:center;justify-content:var(--_Pa, center);min-height:var(--_Ph, var(--basalt-size-badge));--_Ph: var(--_D) 0;padding:var(--_Pd, 0 calc(var(--basalt-space-2) - var(--basalt-size-hairline)));border-radius:var(--_Pr, var(--basalt-radius-xs));text-align:center}.diagram-node[data-shape=participant]:not([data-focal]){--_Pbg: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Pbc: var(--_D) var(--basalt-border-rim);--_Pbt: var(--_D) var(--basalt-border-rim-top);background:var(--_Pbg, none);border-color:var(--_Pbc, var(--basalt-border-hairline));border-top-color:var(--_Pbt, var(--basalt-border-hairline))}.diagram-node[data-shape=participant] .diagram-kind{--_Pk: var(--_D) block;display:var(--_Pk, none)}.diagram-node[data-shape=participant] .diagram-name{font-size:var(--_Pn, var(--basalt-text-xs-size));line-height:var(--_Pnl, var(--basalt-text-xs-line-height));font-weight:var(--_Pw, var(--basalt-font-weight-medium));--_Pn: var(--_D) var(--basalt-text-sm-size);--_Pnl: var(--_D) var(--basalt-text-sm-line-height);--_Pw: var(--_D) var(--basalt-font-weight-semibold)}.diagram-steps{--_Sp: var(--_D) var(--basalt-space-4);position:relative;z-index:1;padding-block-start:var(--_Sp, var(--basalt-space-4))}.diagram-msgs{margin:0;padding:0;list-style:none}.diagram-msg{--_Md: var(--_D) grid;--_Mc: var(--_D) repeat(var(--_cols, 1), minmax(0, 1fr));--_Mr: var(--_D) 1fr 1fr;--_Mh: var(--_D) var(--basalt-size-diagram-step);--_Mg: var(--_D) 0 var(--basalt-space-5);display:grid;grid-template-columns:var(--_Mc, var(--basalt-space-8) minmax(0, 1fr));grid-template-rows:var(--_Mr, auto);column-gap:var(--basalt-space-5);gap:var(--_Mg, 0);height:var(--_Mh, auto);padding-block:var(--_Mpb, var(--basalt-space-2-5));--_Mpb: var(--_D) 0;border-top:var(--_Mb, var(--basalt-size-hairline) solid var(--basalt-border-divider));--_Mb: var(--_D) 0;font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-frame+.diagram-msgs>.diagram-msg:first-child{border-top-color:transparent}.diagram-said{--_Sd: var(--_D) block;display:var(--_Sd, contents);grid-column:var(--_a) / var(--_b);grid-row:1;align-self:end;justify-self:center;margin-block-end:calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--basalt-space-1-5);background:var(--_ground);white-space:nowrap}.diagram-num{grid-column:1;color:var(--basalt-text-tertiary);font-variant-numeric:tabular-nums}.diagram-said .diagram-num{margin-inline-end:var(--_Nm, 0);--_Nm: var(--_D) var(--basalt-space-1-5)}.diagram-mlabel{grid-column:2;color:var(--basalt-text-primary);font-family:var(--basalt-font-family-mono)}.diagram-route{--_Rd: var(--_D) none;display:var(--_Rd, inline-flex);grid-column:2;align-items:center;column-gap:var(--basalt-space-1);row-gap:0;flex-wrap:wrap;color:var(--basalt-text-secondary)}.diagram-to{display:inline-flex;align-items:center;gap:var(--basalt-space-1);white-space:nowrap}.diagram-note{--_Nd: var(--_D) 2;grid-column:var(--_Nc, 2);--_Nc: var(--_D) var(--_a) / var(--_b);grid-row:var(--_Nd, auto);align-self:start;justify-self:var(--_Nj, stretch);--_Nj: var(--_D) center;margin-block-start:var(--_Nmt, 0);--_Nmt: var(--_D) calc(var(--basalt-space-1) + var(--basalt-size-hairline));padding-inline:var(--_Npi, 0);--_Npi: var(--_D) var(--basalt-space-1-5);background:var(--_Nbg, none);--_Nbg: var(--_D) var(--_ground);color:var(--basalt-text-tertiary);white-space:var(--_Nws, normal);--_Nws: var(--_D) nowrap}.diagram-msg[data-self=end] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) start;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-start:var(--_Sm, 0)}.diagram-msg[data-self=start] :is(.diagram-said,.diagram-note){--_Sj: var(--_D) end;justify-self:var(--_Sj, stretch);--_Sm: var(--_D) calc(50% + var(--basalt-space-6) + var(--basalt-space-1));margin-inline-end:var(--_Sm, 0)}.diagram-arrow{flex:none;overflow:visible}.diagram-bar{fill:var(--panel-next, var(--basalt-surface-1));stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);rx:var(--basalt-radius-2xs)}.diagram-frame{--_Fpi: var(--_D) 0;--_cw: calc((100% - (var(--_cols, 1) - 1) * var(--basalt-space-5)) / var(--_cols, 1));--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2));--_Fw: var(--_D) calc((var(--_b) - var(--_a)) * (var(--_cw) + var(--basalt-space-5)) - var(--basalt-space-5) - (var(--_fis, 0) + var(--_fie, 0)) * var(--basalt-space-2));--_fl: var(--_Fl, 0%);--_fw: var(--_Fw, 100%);--_Fel: var(--_D) var(--_fl);--_Few: var(--_D) var(--_fw);--_Fer: var(--_D) calc(100% - var(--_fl) - var(--_fw));position:relative;padding-block:var(--basalt-size-control-lg) var(--basalt-space-2);padding-inline:var(--_Fpi, var(--basalt-space-4))}.diagram-frame+.diagram-frame{margin-block-start:var(--basalt-space-2)}.diagram-frame[data-depth="2"]{--_Fl: var(--_D) calc((var(--_a) - 1) * (var(--_cw) + var(--basalt-space-5)) + var(--_fis, 0) * var(--basalt-space-2))}.diagram-fbox{position:absolute;inset-block:0;inset-inline-start:var(--_fl);z-index:1;box-sizing:border-box;width:var(--_fw);border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-lg);pointer-events:none}.diagram-frame[data-depth="2"]>.diagram-fbox{border-radius:var(--basalt-radius-xs)}.diagram-fhead{position:absolute;top:var(--basalt-size-hairline);inset-inline-start:calc(var(--_fl) + var(--basalt-size-hairline));display:flex;align-items:flex-start;gap:var(--basalt-space-3);margin:0;white-space:nowrap}.diagram-ftab{padding:var(--basalt-space-1) var(--basalt-space-3);border-inline-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-block-end:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-end-end-radius:var(--basalt-radius-xs);background:var(--_ground);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs-mono)}.diagram-flabel{margin-block-start:var(--basalt-space-1);margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-felse{position:relative;display:flex;align-items:center;gap:var(--basalt-space-1-5);height:var(--basalt-size-control-sm);margin:0;padding-inline-start:calc(var(--_fl) + var(--basalt-space-3));white-space:nowrap}.diagram-felse:before{content:"";position:absolute;top:0;inset-inline-start:var(--_Fel, calc(-1 * var(--basalt-space-4)));width:var(--_Few, calc(100% + 2 * var(--basalt-space-4)));height:var(--basalt-size-hairline);background:var(--basalt-diagram-structure);mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' preserveAspectRatio='none'%3E%3Crect width='1' height='1'/%3E%3C/svg%3E") 0 0 / calc(2 * var(--basalt-size-diagram-guide-dash)) var(--basalt-size-hairline) repeat-x}.diagram-felse .diagram-flabel{margin-block-start:0;margin-inline-start:0}.diagram-fword{margin-inline-start:calc(-1 * var(--basalt-space-1-5));padding-inline:var(--basalt-space-1-5);background:var(--_ground);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-fword+.diagram-flabel{margin-inline-start:calc(-1 * var(--basalt-space-1-5))}.diagram-key-letters[data-op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text{box-sizing:border-box;margin:0;padding:var(--basalt-space-4);overflow:hidden;border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-top-color:var(--basalt-border-rim-top);border-radius:var(--basalt-radius-md);background:var(--basalt-surface-sunken);color:var(--basalt-text-secondary);direction:ltr;font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-size-code-line-height) var(--basalt-font-family-mono);white-space:pre-wrap;overflow-wrap:break-word}.diagram-text[data-art]{white-space:pre;overflow-wrap:normal}.diagram-drawing:has(>.diagram-text){max-width:none}.diagram-text .diagram-text-ink{font:inherit;padding:0;border:0;border-radius:0;background:none;color:inherit}.diagram-tx-name,.diagram-tx-to{white-space:nowrap;color:var(--basalt-text-primary)}.diagram-tx-line{display:block;padding-inline-start:calc(var(--_in, 0) * 1ch);text-indent:calc(-1 * var(--_hang, 0) * 1ch)}.diagram-text [data-ink=focal],.diagram-text [data-ink=op]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-text :is([data-ink=name],[data-ink=working],[data-ink=plain]){color:var(--basalt-text-secondary)}.diagram-text :is([data-ink=main],[data-ink=label]){color:var(--basalt-text-primary)}.diagram-text :is([data-ink=life],[data-ink=num],[data-ink=note],[data-ink=frame],[data-ink=band]){color:var(--basalt-text-tertiary)}.diagram-key-glyph{font:var(--basalt-font-weight-regular) var(--bh-xs-mono);color:var(--basalt-text-secondary)}.diagram-key-glyph[data-ink=main]{color:var(--basalt-text-primary)}.diagram-key-glyph[data-ink=focal]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}@media(forced-colors:active){.diagram-text :is([data-ink]){color:CanvasText}}.diagram-band{--_Bh: var(--_D) var(--basalt-size-control-lg);--_Bj: var(--_D) center;position:relative;display:flex;align-items:center;justify-content:var(--_Bj, flex-start);height:var(--_Bh, auto);margin:var(--_Bm, var(--basalt-space-5) 0 var(--basalt-space-2));--_Bm: var(--_D) 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-band:before{--_Br: var(--_D) "";content:var(--_Br, none);position:absolute;inset-inline:0;top:50%;border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-band>span{position:relative;padding-inline:var(--_Bp, 0);--_Bp: var(--_D) var(--basalt-space-1-5);background:var(--_ground)}.diagram-node[data-shape=table]{align-self:start;padding:0;overflow-wrap:normal}.diagram-th{padding:var(--basalt-space-2) var(--basalt-space-3);border-bottom:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-th{border-bottom-color:var(--basalt-diagram-focal-rule)}.diagram-tname{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-row{display:flex;flex-wrap:wrap;align-items:center;column-gap:var(--basalt-space-3);min-height:var(--basalt-size-control-sm);padding-inline:var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-keyseat{flex:none;width:var(--basalt-space-6);margin-inline-end:calc(-1 * var(--basalt-space-3));color:var(--basalt-text-tertiary)}.diagram-cname{flex:1 0 auto;color:var(--basalt-text-primary)}.diagram-ctype{margin-inline-start:auto;color:var(--basalt-text-tertiary)}.diagram-ctype[data-ref]{color:var(--basalt-text-secondary)}.diagram-more{padding:0 var(--basalt-space-3) var(--basalt-space-2);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-key{padding-block-start:var(--basalt-space-3);border-top:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-legend{display:flex;flex-wrap:wrap;gap:var(--basalt-space-2) var(--basalt-space-5);margin:0;padding:0;list-style:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-entry{display:inline-flex;align-items:center;gap:var(--basalt-space-1-5)}.diagram[data-layout=drawn] .diagram-entry[data-when=stacked],.diagram[data-layout=stacked] .diagram-entry[data-when=drawn],.diagram:not([data-layout]) .diagram-entry[data-when=drawn]{display:none}.diagram-swatch{flex:none;overflow:visible}.diagram-swatch-shape{fill:var(--_ground);stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke-dasharray:var(--basalt-space-1) var(--basalt-space-0-5)}.diagram-fk-mark{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-mono)}.diagram-key-letters{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-hint{display:flex;flex-wrap:wrap;gap:var(--basalt-space-1) var(--basalt-space-4);margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-hint>span{display:inline-flex;align-items:center;gap:var(--basalt-space-1)}.diagram-tap-hint{display:none;margin:0;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram[data-touch][data-layout=drawn]>.diagram-tap-hint,.diagram[data-touch][data-layout=stacked]:not([data-bare],[data-type=sequence],[data-type=schema])>.diagram-tap-hint{display:block}.diagram[data-touch]>.diagram-hint{display:none}.diagram[data-touch] .diagram-node{min-height:var(--basalt-size-tap-min)}@media(pointer:coarse){.diagram-clear{min-height:var(--basalt-size-tap-min)}}.diagram[data-layout=stacked]:is([data-type=sequence],[data-type=schema]) .diagram-hint{display:none}.diagram[data-bare] :is(.diagram-entry[data-line],.diagram-hint){display:none}.diagram-summary{order:1;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm);text-wrap:pretty}.diagram-foot{order:2;display:flex;flex-wrap:wrap;gap:var(--basalt-space-2)}.diagram-list{order:3;max-width:var(--basalt-size-prose-width);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-list[hidden]{display:none}.diagram-list strong{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-code{padding:0;border-radius:0;background:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-mono)}.diagram-list-head{margin:var(--basalt-space-4) 0 var(--basalt-space-2);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-list-head:first-child{margin-block-start:0}.diagram-list-group{margin:var(--basalt-space-3) 0 var(--basalt-space-1);color:var(--basalt-text-primary);font-size:inherit;font-weight:var(--basalt-font-weight-medium);line-height:inherit}.diagram-list-items{display:flex;flex-direction:column;gap:var(--basalt-space-1);margin:0;padding-inline-start:var(--basalt-space-5)}.diagram-list-exits{margin:var(--basalt-space-1) 0 0;padding-inline-start:var(--basalt-space-5)}@media(pointer:coarse){.diagram-toggle{min-height:var(--basalt-size-tap-min)}}@media(prefers-reduced-motion:reduce){.diagram-node,.diagram-line,.diagram-tip,.diagram-crow,.diagram-ring,.diagram-label,.diagram-diamond path{transition:none}}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-kind,.diagram-detail,.diagram-keyseat,.diagram-ctype,.diagram-more){opacity:1}}@container (width >= 640px){.diagram:not([data-layout]):is(:is([data-type=architecture],[data-type=flowchart]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]),:is([data-type=data-flow],[data-type=schema]):is([data-cols="1"],[data-cols="2"]),[data-type=sequence]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]))>.diagram-drawing{--_D: }}@container (width >= 696px){.diagram:not([data-layout])[data-type=data-flow][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 768px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="0"],[data-type=flowchart][data-cols="4"],[data-type=schema][data-cols="3"]:not([data-marks]))>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 800px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="4"][data-reach="2"],[data-type=sequence][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 816px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 832px){.diagram:not([data-layout])[data-type=architecture][data-cols="4"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 888px){.diagram:not([data-layout])[data-type=data-flow][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 964px){.diagram:not([data-layout])[data-type=sequence][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 976px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="5"][data-reach="0"],[data-type=flowchart][data-cols="5"])>.diagram-drawing{--_D: }}@container (width >= 992px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1008px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1024px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=architecture][data-cols="5"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1040px){.diagram:not([data-layout])[data-type=schema][data-cols="4"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout])[data-type=data-flow][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1184px){.diagram:not([data-layout]):is([data-type=architecture][data-cols="6"][data-reach="0"],[data-type=flowchart][data-cols="6"])>.diagram-drawing{--_D: }}@container (width >= 1200px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="1"]>.diagram-drawing{--_D: }}@container (width >= 1216px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="2"]>.diagram-drawing{--_D: }}@container (width >= 1232px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="3"]>.diagram-drawing{--_D: }}@container (width >= 1248px){.diagram:not([data-layout])[data-type=architecture][data-cols="6"][data-reach="4"]>.diagram-drawing{--_D: }}@container (width >= 1272px){.diagram:not([data-layout])[data-type=data-flow][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1312px){.diagram:not([data-layout])[data-type=schema][data-cols="5"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 1584px){.diagram:not([data-layout])[data-type=schema][data-cols="6"]:not([data-marks])>.diagram-drawing{--_D: }}@container (width >= 792px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="3"]>.diagram-drawing{--_D: }}@container (width >= 1076px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 1360px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 1644px){.diagram:not([data-layout])[data-type=schema][data-marks][data-cols="6"]>.diagram-drawing{--_D: }}@media(scripting:none){.diagram:not(#basalt-diagram-no-id)>.diagram-drawing{--_D: initial}.diagram-list[hidden]{display:block!important}.diagram-foot,.diagram-entry[data-line],.diagram-hint{display:none}}@media(forced-colors:active){.diagram-svg,.diagram-lifes,.diagram-swatch,.diagram-arrow{forced-color-adjust:none}.diagram .diagram-line,.diagram .diagram-line[data-kind]{stroke:CanvasText}.diagram .diagram-tip,.diagram .diagram-tip[data-kind],.diagram .diagram-dot{fill:CanvasText}.diagram .diagram-tip[data-open],.diagram .diagram-tip[data-kind][data-open]{fill:none;stroke:CanvasText}.diagram .diagram-edge[data-dim] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-dim] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:GrayText}.diagram .diagram-edge[data-dim] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-edge[data-lit] .diagram-line{stroke:Highlight}.diagram .diagram-edge[data-lit] :is(.diagram-tip:not([data-open]),.diagram-dot){fill:Highlight}.diagram .diagram-edge[data-lit] .diagram-tip[data-open]{stroke:Highlight}.diagram :is(.diagram-crow,.diagram-ring){stroke:CanvasText}.diagram .diagram-ring{fill:Canvas}.diagram .diagram-edge[data-dim] :is(.diagram-crow,.diagram-ring){stroke:GrayText}.diagram .diagram-edge[data-lit] :is(.diagram-crow,.diagram-ring){stroke:Highlight}.diagram .diagram-life{stroke:GrayText}.diagram .diagram-label{color:CanvasText;forced-color-adjust:none}.diagram .diagram-label[data-on]{background:Canvas}.diagram .diagram-label[data-lit]{color:Highlight}.diagram .diagram-swatch-shape{fill:Canvas;stroke:CanvasText}.diagram .diagram-swatch[data-shape=group] .diagram-swatch-shape{fill:none;stroke:GrayText}.diagram .diagram-swatch[data-shape=focal] .diagram-swatch-shape{fill:CanvasText;stroke:CanvasText}.diagram[data-type=flowchart] .diagram-node:not([data-focal]),.diagram[data-type=flowchart] .diagram-node:not([data-focal])[data-near]{border-color:CanvasText}.diagram[data-measured][data-type=flowchart] .diagram-node[data-shape=decision][data-shape]{forced-color-adjust:none;background:none;border-color:transparent}.diagram .diagram-diamond{forced-color-adjust:none}.diagram .diagram-diamond path,.diagram .diagram-node[data-near] .diagram-diamond path{fill:Canvas;stroke:CanvasText}.diagram .diagram-group,.diagram .diagram-gbox{border-color:GrayText}.diagram .diagram-lane+.diagram-lane:before,.diagram .diagram-band:before{border-color:GrayText}.diagram .diagram-hint{color:GrayText}.diagram :is(.diagram-kind,.diagram-name,.diagram-detail,.diagram-glabel,.diagram-lane-name,.diagram-title,.diagram-source,.diagram-num,.diagram-mlabel,.diagram-route,.diagram-note,.diagram-band,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more,.diagram-legend,.diagram-fk-mark,.diagram-key-letters){color:CanvasText}.diagram .diagram-node:focus-visible{outline-color:Highlight}.diagram .diagram-node[data-focal],.diagram .diagram-node[data-focal][data-near]{forced-color-adjust:none;background:CanvasText;border-color:CanvasText}.diagram .diagram-node[data-focal] :is(.diagram-name,.diagram-kind,.diagram-detail,.diagram-tname,.diagram-cname,.diagram-keyseat,.diagram-ctype,.diagram-more){color:Canvas;opacity:1}.diagram .diagram-node[data-focal] .diagram-th{border-bottom-color:Canvas}.diagram .diagram-node[data-focal]:focus-visible{outline:var(--basalt-size-focus-width) solid Highlight}.diagram .diagram-node[data-focal][data-shape=decision] .diagram-diamond path{fill:CanvasText;stroke:CanvasText}.diagram .diagram-bar{fill:Canvas;stroke:CanvasText}.diagram .diagram-fbox,.diagram .diagram-ftab{border-color:GrayText}.diagram .diagram-felse:before{background:GrayText}.diagram :is(.diagram-ftab,.diagram-flabel,.diagram-fword){color:CanvasText;background:Canvas}.diagram .diagram-mark{display:none}.diagram .diagram-node[data-mark]>.diagram-mark+:is(.diagram-kind,.diagram-name){padding-inline-end:0}}@media print{.diagram-svg,.diagram-lifes,.diagram-swatch,.diagram-arrow,.diagram-mark,.diagram-node[data-focal]{-webkit-print-color-adjust:exact;print-color-adjust:exact}.diagram-hint,.diagram-tap-hint,.diagram-clear,.diagram-download{display:none!important}.diagram .diagram-edge :is(.diagram-line,.diagram-tip[data-open]){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-line[data-kind=main]{stroke:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-tip:not([data-open]),.diagram-dot){fill:var(--basalt-diagram-edge)!important}.diagram .diagram-edge .diagram-tip[data-kind=main]:not([data-open]){fill:var(--basalt-diagram-edge-main)!important}.diagram .diagram-edge :is(.diagram-crow,.diagram-ring){stroke:var(--basalt-diagram-edge)!important}.diagram .diagram-label{color:var(--basalt-diagram-edge)!important}}.basalt-exporting,.basalt-exporting *{transition:none!important}.diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-secondary);transition:color var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram-edge[data-ahead] .diagram-line{stroke:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:var(--basalt-diagram-edge-dim)}.diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:var(--basalt-diagram-edge-dim)}.diagram-text [data-n][data-ahead] [data-ink=label],.diagram[data-motion=animated][data-entrance=pending] .diagram-text [data-n] [data-ink=label]{color:var(--basalt-text-secondary)}.diagram-text [data-n][data-ahead] :is([data-ink=main],[data-ink=plain]),.diagram[data-motion=animated][data-entrance=pending] .diagram-text [data-n] :is([data-ink=main],[data-ink=plain]){color:var(--basalt-text-tertiary)}.diagram-text [data-n][data-arrival] [data-ink=num]{color:var(--basalt-text-primary)}@media(prefers-reduced-motion:reduce){.diagram-msg[data-ahead] .diagram-mlabel{transition:none}}@media(forced-colors:active){.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:GrayText}.diagram .diagram-edge[data-ahead] .diagram-line{stroke:GrayText}.diagram .diagram-edge[data-ahead] .diagram-tip:not([data-open]){fill:GrayText}.diagram .diagram-edge[data-ahead] .diagram-tip[data-open]{stroke:GrayText}.diagram .diagram-text [data-n][data-ahead] [data-ink]{color:GrayText}.diagram .diagram-text [data-n][data-arrival] [data-ink=num]{color:Highlight}}@media print{.diagram .diagram-msg[data-ahead] .diagram-mlabel{color:var(--basalt-text-primary)!important}}} diff --git a/.agent/skills/basalt-html/parts/diagram.js b/.agent/skills/basalt-html/parts/diagram.js index 10052fde..89c0d821 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,6 +1,6 @@ -(()=>{var cn=["top","right","bottom","left"],dn=["main","plain","dashed"],$e=["one","zero-or-one","one-or-many","zero-or-many"],Ft={one:"Exactly one","zero-or-one":"Zero or one","one-or-many":"One or many","zero-or-many":"Zero or many"},fn=[2,3,4,5,6],gt=t=>t==null||t===""?void 0:String(t),Lt=t=>Object.assign(Object.create(null),t),Ot=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Nt(t,e={}){const o=e.checks!==!1,c=[],s=g=>{c.push(g)},a=t.legend??{},l={};for(const g of["main","plain","dashed","focal","group","activation"]){const y=gt(a[g]);y&&(l[g]=y)}const r=t.stepLabel,d=typeof r=="function"?g=>String(r(g)):typeof r=="string"?(g=>r.replace("{n}",String(g))):g=>`Step ${g}`,m=t.shapeLabels??{},f={terminal:gt(m.terminal)??"Start or end",step:gt(m.step)??"Step",decision:gt(m.decision)??"Decision"},i=t.heading===void 0?3:fn.includes(t.heading)?t.heading:(s(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),h=(g,y)=>g==null?"plain":dn.includes(g)?g:(s(`"${String(g)}" is not a kind of line (main, plain or dashed): ${y} is drawn plain`),"plain"),$=g=>{if(g!=null){if(cn.includes(g))return g;s(`"${String(g)}" is not a side (top, right, bottom or left): the derived side is used`)}},p=(g,y)=>typeof g=="number"&&Number.isInteger(g)&&g>=1?g:(t.layout==="auto"&&g==null||s(`${y} is ${JSON.stringify(g)}, not a whole number from 1: it is placed at 1`),1),u=[],M=[];let C=[];const z=[],w=[],S=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(S)||s(`"${String(S)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),S==="architecture"||S==="flowchart"){for(const g of t.nodes??[]){const y=S==="flowchart"&&g.shape==="decision"?"decision":S==="flowchart"&&g.shape==="terminal"?"terminal":"box",E=String(g.id??""),A=p(g.row,`the row of ${E}`);u.push({id:E,i:u.length,name:String(g.name??""),kind:y==="decision"?void 0:gt(g.kind),detail:y==="decision"?void 0:gt(g.detail),mono:!!g.detailMono,focal:!!g.focal,col:p(g.col,`the column of ${E}`),row:A,row2:A,branch:!!g.branch,shape:y,group:S==="architecture"?gt(g.group):void 0,mark:S==="architecture"?ee(g.mark):void 0})}if(S==="architecture"){const g=(t.groups??[]).map(L=>({id:String(L.id??""),label:String(L.label??""),parent:gt(L.parent)})),y=new Map(g.map(L=>[L.id,L])),E=L=>{if(!L.parent)return 1;const T=y.get(L.parent);return T?T.parent===L.id||T.id===L.id?(s(`the groups "${L.label}" and "${T.label}" are each other's parent`),L.parent=void 0,1):T.parent?(s(`the group "${L.label}" is a third level: groups nest two deep`),L.parent=void 0,1):2:(s(`the group "${L.label}" names the parent "${L.parent}", which is not a group`),L.parent=void 0,1)},A=g.map(E);g.forEach((L,T)=>z.push({...L,depth:A[T],members:u.filter(U=>U.group===L.id).map(U=>U.id),all:[]}));for(const L of z)L.all=[...L.members,...z.filter(T=>T.parent===L.id).flatMap(T=>T.members)];z.sort((L,T)=>L.depth-T.depth)}}else if(S==="data-flow"){C=(t.lanes??[]).map(y=>({id:String(y.id??""),label:String(y.label??"")}));const g=new Map(C.map((y,E)=>[y.id,E+1]));for(const y of t.nodes??[]){const E=String(y.id??""),A=String(y.lane??""),L=g.get(A);L===void 0&&s(`a node (${E}) names the lane "${A}", which is not in lanes`);const T=u.length+1;u.push({id:E,i:u.length,name:String(y.name??""),kind:d(T),detail:gt(y.detail),mono:!!y.detailMono,focal:!!y.focal,col:p(y.col,`the column of ${E}`),row:L??1,row2:L??1,branch:!1,shape:"box",lane:L??1,laneLabel:C[(L??1)-1]?.label??A,step:T,mark:ee(y.mark)})}}else if(S==="sequence"){(t.participants??[]).forEach((A,L)=>{const T=String(A.name??"");u.push({id:String(A.id??""),i:L,name:T,kind:gt(A.kind),mono:!1,focal:!!A.focal,col:L+1,row:1,row2:1,branch:!1,shape:"participant",short:gt(A.short)??T,mark:ee(A.mark)})});let g=0;const y=new Map(u.map(A=>[A.id,A.col])),E=(A,L)=>{let T=1/0,U=-1/0;for(const N of A??[]){if(!N||typeof N!="object")continue;if("band"in N){L>0&&s(`the band "${String(N.band)}" is inside a frame: a band is the whole figure's`),w.push({band:String(N.band??"")});continue}if("frame"in N){if(L>=2){s("a frame is a third level: frames nest two deep");continue}const kt=N.frame==="alt"||N.frame==="loop"||N.frame==="opt"?N.frame:"opt",vt=kt==="alt"?N.branches??[]:[{label:N.label,steps:N.steps}];kt==="alt"&&vt.length<2&&s("an alt frame has one branch: it needs two or more");const pt=String(vt[0]?.label??"");pt.length>40&&s(`the frame label "${pt}" is over 40 characters`);const ut=w.length;w.push({open:kt,label:pt,depth:L+1,a:0,b:0}),vt.forEach((ct,bt)=>{if(bt){const k=String(ct.label??"");k.length>40&&s(`the frame label "${k}" is over 40 characters`),w.push({otherwise:k,depth:L+1})}ct.steps?.length||s(`a frame or branch ("${String(ct.label??"")}") is empty`);const[b,I]=E(ct.steps??[],L+1);T=Math.min(T,b),U=Math.max(U,I);const _=w[ut];_.a=Math.min(_.a||1/0,b),_.b=Math.max(_.b,I)}),w.push({close:L+1});continue}g++;const ht=String(N.label??"");ht.includes(` -`)&&s(`message ${g}'s label has a break: a message's second line is its note`);const P=String(N.from??""),lt=String(N.to??"");w.push({n:g,from:P,to:lt,label:It(ht),note:gt(N.note),kind:h(N.kind,`message ${g}`),activate:N.activate===!0||void 0,deactivate:N.deactivate===!0||void 0});const dt=y.get(P)??1,mt=y.get(lt)??1,wt=dt===mt?dt===u.length?dt-1:dt+1:dt;T=Math.min(T,dt,mt,wt),U=Math.max(U,dt,mt,wt)}return[T,U]};E(t.steps??[],0);for(const A of w)"open"in A&&!Number.isFinite(A.a)&&(A.a=1,A.b=Math.max(1,u.length))}else if(S==="schema")for(const g of t.tables??[]){const y=String(g.name??""),[E,A]=Array.isArray(g.row)?g.row:[g.row,g.row],L=p(E,`the row of ${y}`),T=Math.max(L,p(A,`the last row of ${y}`)),U=g.more===void 0||g.more===null?void 0:Number.isInteger(g.more)&&g.more>0?g.more:(s(`${y}'s "more" is ${JSON.stringify(g.more)}, not a whole number from 1: it is left out`),void 0);u.push({id:y,i:u.length,name:y,mono:!0,focal:!!g.focal,col:p(g.col,`the column of ${y}`),row:L,row2:T,branch:!1,shape:"table",more:U,columns:(g.columns??[]).map(N=>({name:String(N.name??""),type:gt(N.type),key:N.key==="PK"||N.key==="FK"?N.key:(N.key!==void 0&&N.key!==null&&s(`${y}.${String(N.name)}'s key is "${String(N.key)}", not PK or FK: it is left out`),void 0)}))})}let B=!1;if(t.layout==="auto"&&(S==="architecture"||S==="flowchart"||S==="schema")){const g=S==="schema"?t.tables:t.nodes;o&&(g??[]).some(E=>E&&(E.col!==void 0||E.row!==void 0))&&s('a card under layout="auto" has a col or row, which is not read: there are no hints');const y=e.placement?.cells;y||(B=!0);for(const E of u){const A=y?.[E.id];E.col=A?.col??1,E.row=E.row2=A?.row??1}if(y){const E=new Map;for(const A of u){const L=Ot(y,A.id);if(!L){B=!0,s(`the placement has no cell for ${A.id}, so it is not used`);continue}const T=`${L.col},${L.row}`;E.has(T)&&(B=!0,s(`the placement puts ${E.get(T)} and ${A.id} in one cell, so it is not used`)),E.set(T,A.id)}}if(y&&!B)for(const E of z){const A=E.all.map(P=>u.find(lt=>lt.id===P)).filter(Boolean);if(!A.length)continue;const L=Math.min(...A.map(P=>P.col)),T=Math.max(...A.map(P=>P.col)),U=Math.min(...A.map(P=>P.row)),N=Math.max(...A.map(P=>P.row)),ht=u.filter(P=>!E.all.includes(P.id)&&P.col>=L&&P.col<=T&&P.row>=U&&P.row<=N);ht.length&&(B=!0,s(`the placement puts ${ht.map(P=>P.id).join(", ")} inside the box of the group "${E.label}", so it is not used`))}}else t.layout==="auto"&&s(`layout="auto" is for an architecture, a flowchart or a schema, not a ${S}`);((S==="schema"?t.tables:S==="sequence"?t.participants:t.nodes)??[]).forEach((g,y)=>{if(!g||g.href===void 0||g.href===null)return;const E=String(g.href);if(S==="sequence"){s(`${u[y]?.id}: a participant cannot be a link (href)`);return}if(!E.trim()){s(`${u[y]?.id}'s href is empty`);return}const A=u[y];A&&(A.href=E,A.blank=g.target==="_blank")});const F=new Map;for(const g of u)g.id?F.has(g.id)&&s(`the id "${g.id}" is used twice`):s("a node has no id"),F.set(g.id,g);if(S==="schema"){const g=(E,A)=>{if(E==null)return;const L=E,T=$e.includes(L.from)?L.from:void 0;if(!T){s(`${A}'s cardinality "from" is ${JSON.stringify(L.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`);return}return L.to===void 0||L.to===null?{from:T,to:"one"}:L.to==="one"||L.to==="zero-or-one"?{from:T,to:L.to}:(s(`${A}'s cardinality "to" is ${JSON.stringify(L.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`),{from:T,to:"one"})};(t.tables??[]).forEach(E=>(E.columns??[]).forEach((A,L)=>{const T=gt(A.references);if(!T&&A.cardinality!==void 0&&A.cardinality!==null&&s(`${String(E.name)}.${String(A.name)} states a cardinality but references nothing`),!T)return;const[U,N]=T.split("."),ht=F.get(U??""),P=ht?.columns?.findIndex(mt=>mt.name===N)??-1;if(!ht||P<0){s(`${String(E.name)}.${String(A.name)} references ${T}, which is not a shown column`);return}const lt=F.get(String(E.name??""));lt.columns[L].ref={table:U,column:N,row:P};const dt=g(A.cardinality,`${String(E.name)}.${String(A.name)}`);dt&&(lt.columns[L].card=dt),M.push({i:M.length,from:lt.id,to:U,kind:"plain",fromRow:L,toRow:P,fk:!0,card:dt})}));const y=M.filter(E=>E.card).length;y&&y!E.card).map(E=>`${E.from}.${F.get(E.from).columns[E.fromRow].name}`).join(", ")} ${M.length-y===1?"has":"have"} none)`)}else if(S!=="sequence")for(const g of t.edges??[]){const y=String(g.from??""),E=String(g.to??"");if(!F.has(y)||!F.has(E)){s(`a line names ${F.has(y)?E:y}, which is not a node`);continue}const A=gt(g.label),L=A?.split(` -`)??[];L.length>2&&s(`the label "${It(A)}" has more than one break: a label is two lines at most`),L.some(T=>T.length>we)&&s(`a line of the label "${It(A)}" is over ${we} characters: longer words belong in the node or the summary`),M.push({i:M.length,from:y,to:E,kind:h(g.kind,`the line from ${y} to ${E}`),label:A,fromSide:$(g.fromSide),toSide:$(g.toSide),flow:S!=="flowchart"&&g.flow===!0?!0:void 0})}else for(const g of w)"n"in g&&(!F.has(g.from)||!F.has(g.to))&&s(`message ${g.n} names ${F.has(g.from)?g.to:g.from}, which is not a participant`);if(o&&S!=="sequence"&&!B){const g=new Map;for(const y of u)for(let E=y.row;E<=y.row2;E++){const A=`${y.col}:${E}`;g.has(A)&&s(`${y.id} and ${g.get(A)} share the cell at column ${y.col}, row ${E}`),g.set(A,y.id)}}if(o&&!B){for(const y of z){const E=y.all.map(T=>F.get(T));if(!E.length)continue;const A={c1:Math.min(...E.map(T=>T.col)),c2:Math.max(...E.map(T=>T.col)),r1:Math.min(...E.map(T=>T.row)),r2:Math.max(...E.map(T=>T.row2))};for(const T of u)!y.all.includes(T.id)&&T.col>=A.c1&&T.col<=A.c2&&T.row>=A.r1&&T.row<=A.r2&&s(`${T.id} is inside the box of the group "${y.label}" but not a member`);const L=E.map(T=>T.i);Math.max(...L)-Math.min(...L)+1!==L.length&&s(`the members of the group "${y.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const y of u)y.group&&!z.some(E=>E.id===y.group)&&s(`${y.id} names the group "${y.group}", which is not in groups`);u.filter(y=>y.focal).length>1&&s("more than one node is focal: a diagram has one at most");const g=new Set(S==="sequence"?w.flatMap(y=>"n"in y?[y.kind]:[]):M.map(y=>y.kind));g.has("main")&&!l.main&&s("main lines are drawn but the legend has no words for them (legend.main)"),g.has("dashed")&&!l.dashed&&s("dashed lines are drawn but the legend has no words for them (legend.dashed)"),u.some(y=>y.focal)&&!l.focal&&s("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const it=S==="architecture"||S==="data-flow",q=g=>Array.isArray(g)&&g.length>1?g.map(String):void 0,G=it&&t.packet&&typeof t.packet=="object"?t.packet:void 0,j=G&&q(G.path),x={animated:t.motion==="animated",pulse:it?q(t.pulse):void 0,packet:j?{path:j,repeat:G.repeat===!0,send:G.send}:void 0,run:S==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(o)for(const g of u){const y=g.mark?.says;if(!y?.length)continue;const E=[g.name,g.kind,g.detail,g.laneLabel].filter(Boolean).join(" ").toLowerCase();y.some(A=>E.includes(A.toLowerCase()))||s(`${g.id}'s mark stands for ${y.join(" or ")}, and none of its words say so`)}const R=[];if(S==="sequence"){const g=new Map,y=new Map;for(const E of w)"n"in E&&(y.set(E.from,E.n),y.set(E.to,E.n));for(const E of w)if("n"in E){if(E.activate){const A=g.get(E.to)??[];if(A.length>=3)s(`message ${E.n} opens a fourth bar on ${E.to}: three deep at most`);else{const L={who:E.to,from:E.n,to:E.n,depth:A.length+1};A.push(L),R.push(L),g.set(E.to,A)}}if(E.deactivate){const L=g.get(E.from)?.pop();L?L.to=E.n:s(`message ${E.n} closes a bar on ${E.from}, which has none open`)}}for(const[E,A]of g)for(const L of A)L.to=Math.max(L.from,y.get(E)??L.from)}const D=t.frameLabels??{},Z={opt:gt(D.opt)??"Only if",loop:gt(D.loop)??"Repeats",alt:gt(D.alt)??"One of these",else:gt(D.else)??"Otherwise"},K=t.layout==="auto"&&!B?e.placement:void 0;let at=Math.max(1,K?.cols??1,...u.map(g=>g.col));if(e.rtl){for(const y of u)y.col=at-y.col+1;const g=y=>y==="left"?"right":y==="right"?"left":y;for(const y of M)y.fromSide=g(y.fromSide),y.toSide=g(y.toSide);for(const y of w)if("open"in y){const[E,A]=[at-y.b+1,at-y.a+1];y.a=E,y.b=A}at=Math.max(1,K?.cols??1,...u.map(y=>y.col))}const nt=S==="data-flow"?Math.max(1,C.length):Math.max(1,K?.rows??1,...u.map(g=>g.row2)),J={type:S,title:String(t.title??""),heading:i,legend:l,nodes:u,byId:F,edges:M,groups:z,lanes:C,steps:w,bars:R,frameWords:Z,cols:at,rows:nt,shapeLabels:f,stepWord:d,warnings:c,motion:x,memo:new Map,rtl:e.rtl||void 0,unplaced:B||void 0,text:S==="sequence"&&t.variant==="text"||void 0,marks:M.some(g=>g.card)||void 0};if(t.layout==="auto"&&!B&&S!=="schema"&&un(J),o)for(const[g,y]of Object.entries(We(J)))y>=48&&s(`${g} grows to ${y}px to hold the lines on one side: use another side`);return o&&u.length>100&&s(`the figure has ${u.length} cards: more than 100, which automatic layout places on the main thread`),o&&u.length>1&&!B&&!Zt(J)&&s("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),J}function un(t){const e=new Set(t.nodes.map(l=>`${l.col},${l.row}`)),n=(l,r)=>{const d=[];for(let m=Math.min(l,r)+1;m{const r=t.byId.get(l.from),d=t.byId.get(l.to),m=d.col>r.col?"right":"left",f=d.row>r.row?"bottom":"top",i=d.col>r.col?"left":"right",h=d.row>r.row?"top":"bottom",$=(M,C,z,w)=>n(M,C).map(S=>w?[S,z]:[z,S]);let p;const u=M=>(M==="right"?r.col1:M==="bottom"?r.row1)?[{sides:[M,M],cells:[]}]:[];return r.row===d.row?p=[{sides:[m,i],cells:$(r.col,d.col,r.row,!0)},...u("bottom"),...u("top")]:r.col===d.col?p=[{sides:[f,h],cells:$(r.row,d.row,r.col,!1)},...u("right"),...u("left")]:p=[{sides:[m,h],cells:[...$(r.col,d.col,r.row,!0),[d.col,r.row],...$(r.row,d.row,d.col,!1)]},{sides:[f,i],cells:[...$(r.row,d.row,r.col,!1),[r.col,d.row],...$(r.col,d.col,d.row,!0)]},{sides:[m,i],cells:$(r.col,d.col,r.row,!0)},{sides:[f,h],cells:$(r.row,d.row,r.col,!1)}],p.filter(M=>M.cells.every(([C,z])=>!e.has(`${C},${z}`)))},c=new Map,s=new Set;for(const l of t.edges)if(l.fromSide||l.toSide){const[r,d]=de(t.byId.get(l.from),t.byId.get(l.to)),m=l.fromSide??r,f=l.toSide??d;s.add(`${l.from}.${m}`);for(const[i,h]of[[l.from,m],[l.to,f]])c.set(`${i}.${h}`,(c.get(`${i}.${h}`)??0)+1)}const a=t.edges.map((l,r)=>r).sort((l,r)=>o(t.edges[l]).length-o(t.edges[r]).length||+(t.edges[r].kind==="main")-+(t.edges[l].kind==="main")||l-r);for(const l of a){const r=t.edges[l];if(r.fromSide||r.toSide)continue;const d=(f,i,h)=>{const $=`${f}.${i}`;return(c.get($)??0)>=3?!1:t.byId.get(f).shape!=="decision"?!0:h?!c.has($):!s.has($)},m=o(r).find(f=>d(r.from,f.sides[0],!0)&&d(r.to,f.sides[1],!1));if(m){s.add(`${r.from}.${m.sides[0]}`);for(const[f,i]of[[r.from,m.sides[0]],[r.to,m.sides[1]]])c.set(`${f}.${i}`,(c.get(`${f}.${i}`)??0)+1);r.fromSide=m.sides[0],r.toSide=m.sides[1]}}}function ee(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=gt(e.onLight);if(n)return{onLight:n,onDark:gt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var be=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` -`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function jt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var we=28,ne=t=>t.includes(` -`)?2:1,It=t=>t.replace(/\n/g," "),Wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function ve(t,e){return t.legend[e]}function hn(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function pn(t,e){return jt(t,`sentence:${e.i}`,()=>gn(t,e))}function gn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const o=(e.columns??[]).filter(s=>s.ref).map(s=>`${s.ref.table} (${s.name}${s.card?`: ${xe(e.id,s.ref.table,s.card)}`:""})`),c=t.edges.filter(s=>s.to===e.id).map(s=>`${s.from} (${t.byId.get(s.from).columns[s.fromRow].name}${s.card?`: ${xe(s.from,s.to,s.card)}`:""})`);o.length&&n.push(`References ${o.join(", ")}.`),c.length&&n.push(`Referenced by ${c.join(", ")}.`)}else if(t.type==="sequence"){const o=t.steps.filter(a=>"n"in a&&a.from===e.id).length,c=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(Wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${o} ${o===1?"message":"messages"} and receives ${c}.`);const s=ke(t,e);s&&n.push(s.trim())}else{const o=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?hn(t,e):e.kind;if(n.push(Wt(o?`${e.name}, ${o}`:e.name)),e.detail&&n.push(Wt(e.detail)),e.group){const a=t.groups.find(r=>r.id===e.group),l=a?.parent?t.groups.find(r=>r.id===a.parent):void 0;a&&n.push(l?`In ${a.label}, in ${l.label}.`:`In ${a.label}.`)}const c=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${It(a.label)})`:""}`),s=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${It(a.label)})`:""}`);c.length&&n.push(`From: ${c.join(", ")}.`),s.length&&n.push(`To: ${s.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(Wt(t.legend.focal)),n.join(" ")}var mn=(t,e,n,o)=>[`${Ft[n.from].toLowerCase()} `,o(t),` to ${Ft[n.to].toLowerCase()} `,o(e)],xe=(t,e,n)=>`${Ft[n.from].toLowerCase()} ${t} to ${Ft[n.to].toLowerCase()} ${e}`;function ke(t,e){const n=t.bars.filter(c=>c.who===e.id&&c.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(c=>c.from===c.to?`message ${c.from}`:`messages ${c.from} to ${c.to}`).join(" and ")}.`:""}function yn(t,e,n,o){const c=n.pointerType;if(c!=="touch"&&c!=="pen")return;const s=t.querySelector(`.${e}-drawing`),a=n.target;if(!s||!a||!s.contains(a)||!t.querySelector(`.${e}-edge`))return;const l=a.closest(`.${e}-node`);if(!l?.hasAttribute("href"))return l?l.dataset.node===o?null:l.dataset.node??null:o===null?void 0:null}function Me(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const o=[];for(const c of n.flat(1/0))c!=null&&c!==!1&&!Array.isArray(c)&&o.push(c);return{t,a:e??{},c:o}}var $n={"&":"&","<":"<",">":">",'"':""","'":"'"},$t=t=>t.replace(/[&<>"']/g,e=>$n[e]),bn=" br img input meta link hr path polygon polyline circle rect line ";function oe(t,e={}){if(typeof t=="string")return $t(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[o,c]of Object.entries(t.a))if(!(c==null||c===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(o))throw new Error(`diagram: "${o}" is not an attribute name`);n+=c===!0?` ${o}`:` ${o}="${$t(String(c))}"`}return bn.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(o=>oe(o,e)).join("")}`}var wn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function Rt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function vn(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Vt(t,e){const n=e.all.map(o=>t.byId.get(o));return n.length?{c1:Math.min(...n.map(o=>o.col)),c2:Math.max(...n.map(o=>o.col)),r1:Math.min(...n.map(o=>o.row)),r2:Math.max(...n.map(o=>o.row2))}:null}function Se(t){return jt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const o=Vt(t,n);if(!o)continue;[o.r1===1,o.c2===t.cols,o.r2===t.rows,o.c1===1].forEach((s,a)=>{s&&(e[a]=Math.max(e[a],Ee(t,n,a)))})}return e})}function Ee(t,e,n){const o=Vt(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const l=Vt(t,a);return l&&[l.r1===o.r1,l.c2===o.c2,l.r2===o.r2,l.c1===o.c1][n]})?2:1}function Ae(t){const e=Se(t);return e[1]+e[3]}function ae(t){return t.type==="sequence"?t.nodes.length:t.cols}function Le(t){return jt(t,"plan",()=>xn(t))}function xn(t){const e=t.nodes,n=u=>t.type==="data-flow"||!e[u].branch,o=t.edges.map(u=>{const M=t.byId.get(u.from).i,C=t.byId.get(u.to).i,w=e.slice(Math.min(M,C)+1,Math.max(M,C)).every(S=>!n(S.i));return C===M+1&&!(n(M)&&!n(C))?"down":C===M-1?"up":C>M&&n(M)&&!n(C)&&w?"trunk":C>M&&n(M)&&n(C)&&w?"rail":C>M?"end-down":"end-up"}),c=t.edges.map((u,M)=>({e:u,k:M})).filter(({k:u})=>o[u]==="end-down"||o[u]==="end-up"),s=u=>{const M=t.byId.get(u.from).i,C=t.byId.get(u.to).i;return[Math.min(M,C),Math.max(M,C)]},a=(u,M)=>{const[C,z]=s(u),[w,S]=s(M);return C{const M=t.byId.get(u.from).i,[C,z]=s(u);return!n(M)&&e.slice(C+1,z).every(w=>!n(w.i))&&c.every(w=>w.e===u||!a(w.e,u))}),r=c.length>0&&(t.type==="data-flow"||!l),d=u=>{const[M,C]=s(u);return C-M},m=t.edges.map(()=>0);let f=!1;const i=[];for(const u of[...c].sort((M,C)=>d(M.e)-d(C.e)||M.k-C.k)){let M=0;for(const C of i)a(C.e,u.e)&&(M=Math.max(M,m[C.k]+1));m[u.k]=M,M>3&&(f=!0),i.push(u)}const h=Math.max(0,...c.map(({k:u})=>m[u]+1)),$=t.edges.map(()=>.5);for(const u of e){const M=c.filter(({e:w})=>w.from===u.id);if(M.length<2)continue;const C=M.filter(({k:w})=>o[w]==="end-down").sort((w,S)=>d(S.e)-d(w.e)||w.k-S.k);[...M.filter(({k:w})=>o[w]==="end-up").sort((w,S)=>d(w.e)-d(S.e)||S.k-w.k),...C].forEach(({k:w},S,B)=>{$[w]=B.length===2?S===0?1/3:2/3:(S+1)/(B.length+1)})}const p=Lt();for(let u=1;u{const G=o[q],j=t.byId.get(it.from).i,x=t.byId.get(it.to).i,R=x===u&&(G==="down"||G==="trunk"||G==="rail"||G==="end-down"),D=j===u&&x===u-1&&G==="up",Z=x===u-1&&G==="end-up";R&&(G==="trunk"||G==="end-down")&&(S=!0),Z&&(B=!0),(R||D||Z)&&it.label&&(z++,w=Math.max(w,G==="trunk"?40:48))}),(z>1||S&&B)&&(w=64);const Y=c.filter(({e:it,k:q})=>o[q]==="end-down"&&t.byId.get(it.to).i===u).length,F=c.filter(({e:it,k:q})=>o[q]==="end-up"&&t.byId.get(it.to).i===u-1).length;w+=20*Math.max(0,Y-1)+20*Math.max(0,F-1),p[M.id]=w}return{routes:o,gutter:r,lanes:m,exits:$,gaps:p,third:f,laneCount:h}}var zt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Ie(t,e){const n=e==="fk"?"plain":e,o=n==="main"?8:8.5,c=24,s=n==="dashed"?c-1:c-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...zt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:o,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${o}H${s}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${c-8} ${o-4}L${c} ${o}L${c-8} ${o+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${c} ${o}L${c-8} ${o-4}L${c-8} ${o+4}Z`}))}function kn(t,e){const{crow:n,ring:o}=_e(e,24,8.5,-1);return v("svg",{class:`${t}-swatch`,"data-card":e,...zt(24,16)},v("path",{class:`${t}-line`,"data-kind":"plain",d:"M0 8.5H24"}),v("path",{class:`${t}-crow`,d:n}),o?v("circle",{class:`${t}-ring`,cx:o.x,cy:o.y,r:o.r}):null)}function _e(t,e,n,o,c=8,s=6){const a=h=>String(Math.round(h*100)/100),l=h=>e+o*h,r=c/2,d=h=>`M${a(l(h-.5))} ${a(n-r)}V${a(n+r)}`,m=t==="one-or-many"||t==="zero-or-many",f=t==="zero-or-one"||t==="zero-or-many";let i=m?`M${a(e)} ${a(n-r)}L${a(l(7.5))} ${a(n)}L${a(e)} ${a(n+r)}`:d(4);return f||(i+=d(m?11:8)),{crow:i,ring:f?{x:Math.round(l(10.5)*100)/100,y:n,r:s/2}:void 0}}function Ht(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...zt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...zt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...zt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function qe(t,e){return jt(e,`key:${t}`,()=>Sn(t,e))}var Mn=qe;function Sn(t,e){const n=[],o=(a,l,r={})=>n.push(v("li",{class:`${t}-entry`,...r},a,v("span",null,l)));if(e.type==="schema"){const a=new Set(e.nodes.flatMap(l=>(l.columns??[]).map(r=>r.key)));for(const[l,r]of[["PK","Primary key"],["FK","Foreign key"]])a.has(l)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},l),v("span",null,r)))}if(e.type==="flowchart"){const a=new Set(e.nodes.map(l=>l.shape));a.has("terminal")&&o(Ht(t,"terminal"),e.shapeLabels.terminal),a.has("box")&&o(Ht(t,"box"),e.shapeLabels.step),a.has("decision")&&o(Ht(t,"decision"),e.shapeLabels.decision)}const c=new Set(e.type==="sequence"?e.steps.flatMap(a=>"n"in a?[a.kind]:[]):e.edges.filter(a=>!a.fk).map(a=>a.kind)),s=(a,l)=>v("span",{class:`${t}-key-glyph`,"data-ink":l,"aria-hidden":"true"},a);for(const a of["main","plain","dashed"]){const l=e.legend[a];c.has(a)&&l&&o(e.text?s(a==="main"?"━━▶":a==="dashed"?"┄┄▷":"──▶",a==="main"?"main":"plain"):Ie(t,a),l,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length){e.edges.some(l=>!l.card)&&o(Ie(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"});const a=new Set(e.edges.flatMap(l=>l.card?[l.card.from,l.card.to]:[]));for(const l of $e)a.has(l)&&o(kn(t,l),Ft[l],{"data-line":"","data-when":"drawn","data-card":l});n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))}if(e.type==="sequence"){e.bars.length&&o(e.text?s("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...zt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const a=new Set(e.steps.flatMap(l=>"open"in l?[l.open]:[]));for(const l of["opt","loop","alt"])a.has(l)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},l),v("span",null,e.frameWords[l])))}return e.nodes.some(a=>a.focal)&&e.legend.focal&&o(e.text?s("╔═╗","focal"):Ht(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&o(Ht(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function En(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...zt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function se(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function An(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},se(t,n)))];const o=[];return e.type==="data-flow"?o.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&o.push(v("span",{class:`${t}-kind`},n.kind)),o.push(v("span",{class:`${t}-name`},se(t,n))),n.detail&&o.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?v("span",{class:`${t}-runs`},Yt(n.detail).flatMap((c,s)=>[s?" ":"",v("span",{class:`${t}-run`},c)])):n.detail)),o}function Ln(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},se(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((o,c)=>v("span",{class:`${t}-row`,"data-row":c,"data-key":o.key},v("span",{class:`${t}-keyseat`},o.key??""),v("span",{class:`${t}-cname`},o.name),o.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${o.ref.table}`):o.type?v("span",{class:`${t}-ctype`},o.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Oe=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Kt(t,e,n,o){const{P:c}=t,s=vn(e,o)||o.keep===n.id,a=Rt(e,o),l=o.layout==="drawn"&&o.rows,r=[`--_c:${n.col}`,`--_r:${l?2*n.row:n.row}`,`--_r2:${l?2*n.row2+1:n.row2+1}`];e.type==="data-flow"&&r.push(`--_lc:${n.col+1}`),e.type==="sequence"&&r.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const $=Ot(d.gaps,n.id)??32,p=Ot(o.grow,n.id)??0;r.push(`--_gap:${p?`calc(${Oe($)} + var(--basalt-space-4) * ${p})`:Oe($)}`)}const m=Ot(o.heights,n.id);m&&r.push(`--_h:${m}px`);const f=Ot(We(e),n.id);f&&r.push(`--_mh:${f}px`);const i=Ot(o.words,n.id);i&&r.push(`--_ww:${i}px`);const h=a?o.stop===n.id?0:-1:o.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${c}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:r.join(";"),role:s&&!n.href?"img":void 0,"aria-label":s||n.href?pn(e,n):void 0,tabindex:h},n.shape==="decision"?v("svg",{class:`${c}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${c}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${be(n.mark.onLight)};--_md:${be(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Ln(c,n,e):An(c,e,n))}function In(t,e,n){const{P:o}=t,c=[];if(e.type==="data-flow"&&c.push(...e.lanes.map((r,d)=>v("div",{class:`${o}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},v("span",{class:`${o}-lane-name`},r.label)))),e.type==="architecture")for(const r of e.groups){const d=Vt(e,r);if(!d)continue;const m=[0,1,2,3].map(f=>Ee(e,r,f));c.push(v("div",{class:`${o}-gbox`,"data-group":r.id,"data-depth":r.depth>1?r.depth:void 0,style:`--_c:${d.c1};--_c2:${d.c2+1};--_r:${d.r1};--_r2:${d.r2+1}${m[0]>1?";--_gt:2":""}${m[1]>1?";--_ge:2":""}${m[2]>1?";--_gb:2":""}${m[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${o}-glabel`},r.label)))}if(e.text)return[v("pre",{class:`${o}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${o}-text-ink`},_n(o,e)))];if(e.type==="sequence")return c.push(v("ul",{class:`${o}-cast`},e.nodes.map(r=>v("li",{class:`${o}-actor`,style:e.rtl?`--_ac:${r.col}`:void 0},Kt(t,e,r,n))))),c.push(qn(t,e)),c;const s=r=>{const d=r.group?e.groups.find(m=>m.id===r.group):void 0;return d?.parent?e.groups.find(m=>m.id===d.parent):d},a=(r,d,m)=>{const f=t.plan?Ot(n.grow,d[0].id)??0:0,i=d[0],h=!!t.plan&&i.group===r.id&&e.edges.some(($,p)=>$.to===i.id&&(t.plan.routes[p]==="trunk"||t.plan.routes[p]==="end-down"));return v("div",{class:`${o}-group`,"data-group":r.id,"data-depth":r.depth>1?r.depth:void 0,"data-turn":h?"":void 0,style:f?`--_ggrow:${f}`:void 0},v("span",{class:`${o}-glabel`,"aria-hidden":"true"},r.label),m)};let l=0;for(;lp.id===m[i].group):void 0;if(!h){f.push(Kt(t,e,m[i],n)),i++;continue}const $=[];for(;iKt(t,e,p,n))))}c.push(a(d,m,f))}return c}function _n(t,e){const n=[],o=r=>v("span",{class:`${t}-tx-name`},r),c=r=>r==="main"?"━▶":r==="dashed"?"┄▷":"─▶",s=(r,d,m,...f)=>v("span",{class:`${t}-tx-line`,...r,style:m?`--_in:${d+m};--_hang:${m}`:`--_in:${d}`},...f);n.push(s({"data-ink":"names"},0,0,e.nodes.flatMap((r,d)=>[d?" · ":"",o(r.name)])));const a=String(Math.max(1,...e.steps.map(r=>"n"in r?r.n:0))).length;let l=0;for(const r of e.steps){const d=2*l;if("band"in r){n.push(s({"data-ink":"band"},d,0,`── ${r.band} ──`));continue}if("open"in r){n.push(s({"data-ink":"frame"},d,0,v("span",{"data-ink":"op"},`[${r.open}]`),` ${r.label}`)),l++;continue}if("otherwise"in r){n.push(s({"data-ink":"frame"},2*Math.max(0,l-1),0,v("span",{"data-ink":"op"},"[else]"),` ${r.otherwise}`));continue}if("close"in r){l=Math.max(0,l-1),n.push(s({"data-ink":"frame"},2*l,0,"[end]"));continue}const m=e.byId.get(r.from)?.name??r.from,f=e.byId.get(r.to)?.name??r.to,i=a+2;n.push(s({"data-n":r.n},d,i,v("span",{"data-ink":"num"},String(r.n).padStart(a,"0"))," ",o(m)," ",v("span",{"data-ink":r.kind==="main"?"main":"plain"},c(r.kind))," ",o(f))),n.push(s({"data-n":r.n},d+i,0,v("span",{"data-ink":"label"},r.label))),r.note&&n.push(s({"data-n":r.n},d+i,0,v("span",{"data-ink":"note"},r.note)))}return n}function qn(t,e){const{P:n}=t,o=[],c=[],s=()=>c.length?c[c.length-1].el.c:o;let a=null;for(const l of e.steps){if("band"in l){a=null,s().push(v("p",{class:`${n}-band`},v("span",null,l.band)));continue}if("open"in l){a=null;const p=c[c.length-1],u=p?`;--_fis:${l.a===p.a?1:0};--_fie:${l.b===p.b?1:0}`:"",M=v("div",{class:`${n}-frame`,"data-op":l.open,"data-depth":l.depth,style:`--_a:${l.a};--_b:${l.b+1}${u}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},l.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[l.open]}: `),l.label)));s().push(M),c.push({el:M,a:l.a,b:l.b});continue}if("otherwise"in l){a=null,s().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),l.otherwise)));continue}if("close"in l){a=null,c.pop();continue}a||(a=v("ol",{class:`${n}-msgs`,start:l.n}),s().push(a));const r=e.byId.get(l.from),d=e.byId.get(l.to),m=r?.col??1,f=d?.col??1,i=m===f,h=i&&(e.rtl?m!==1:m===e.nodes.length),$=ve(e,l.kind);a.c.push(v("li",{class:`${n}-msg`,"data-kind":l.kind,"data-from":l.from,"data-to":l.to,"data-self":i?h?"start":"end":void 0,style:`--_a:${Math.min(m,f)};--_b:${Math.max(m,f)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(l.n)),v("span",{class:`${n}-mlabel`},l.label)),v("span",{class:`${n}-route`},r?.short??l.from," ",v("span",{class:`${n}-to`},En(n,l.kind),v("span",{class:t.hidden}," to ")," ",d?.short??l.to,$?` · ${$}`:"")),l.note?v("span",{class:`${n}-note`},l.note):null))}return v("div",{class:`${n}-steps`},o)}function Ce(t,e){return jt(e,`list:${t}`,()=>Cn(t,e))}var On=Ce;function Cn(t,e){const n=Math.min(6,e.heading+1),o=f=>v(`h${n}`,{class:`${t}-list-head`},f),c=f=>v("strong",null,f),s=f=>f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},c(f.name)):c(f.name),a=f=>v("code",{class:`${t}-code`},f),l=f=>e.byId.get(f)?.name??f,r=f=>{const i=ve(e,f);return i?` (${i})`:""},d=f=>f.focal&&e.legend.focal?` ${Wt(e.legend.focal)}`:"";if(e.type==="architecture"){const f=$=>v("li",null,s($),$.kind?`, ${$.kind}`:"",$.detail?[". ",$.mono?a($.detail):$.detail,/[.!?]$/.test($.detail)?"":"."]:/[.!?]$/.test($.kind??$.name)?"":".",d($)),i=[o("Parts")],h=e.nodes.filter($=>!$.group);h.length&&i.push(v("ul",{class:`${t}-list-items`},h.map(f)));for(const $ of e.groups.filter(p=>p.depth===1)){i.push(v("p",{class:`${t}-list-group`},$.label)),$.members.length&&i.push(v("ul",{class:`${t}-list-items`},$.members.map(p=>f(e.byId.get(p)))));for(const p of e.groups.filter(u=>u.parent===$.id))i.push(v("p",{class:`${t}-list-group`,"data-depth":2},p.label)),i.push(v("ul",{class:`${t}-list-items`,"data-depth":2},p.members.map(u=>f(e.byId.get(u)))))}return i.push(o("Connections")),i.push(v("ol",{class:`${t}-list-items`},e.edges.map($=>v("li",null,c(l($.from))," to ",c(l($.to)),$.label?[": ",a(It($.label))]:"",`${r($.kind)}.`)))),i}if(e.type==="flowchart"){const f=i=>(e.byId.get(i)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(i=>{const h=e.edges.filter(u=>u.from===i.id),$=i.shape==="decision"?"Decision":i.shape==="terminal"?h.length?"Start":"End":"Step",p=!i.detail&&/[.!?]$/.test(i.name)?" ":". ";return v("li",null,s(i),i.detail?[", ",i.mono?a(i.detail):i.detail]:"",`${p}${$}.`,d(i),h.length?v("ul",{class:`${t}-list-exits`},h.map(u=>v("li",null,u.label?`If ${It(u.label)}: go to ${f(u.to)}, `:`Then: go to ${f(u.to)}, `,c(l(u.to)),r(u.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const i=e.edges.filter(h=>h.from===f.id);return v("li",null,`${f.laneLabel}: `,s(f),f.detail?[", ",f.mono?a(f.detail):f.detail]:"",".",d(f),i.length?[" Then ",...i.flatMap((h,$)=>[$?"; ":"",`to step ${e.byId.get(h.to).step}, `,c(l(h.to)),h.label?[": ",a(It(h.label))]:"",r(h.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[o("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(h=>v("li",null,c(h.name),h.kind?`, ${h.kind}`:"",".",d(h),ke(e,h))))];f.push(o("Messages"));let i=null;for(const h of e.steps){if("band"in h){i=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},h.band));continue}if("open"in h){i=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":h.depth>1?h.depth:void 0},`${e.frameWords[h.open]}: ${h.label}`));continue}if("otherwise"in h){i=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":h.depth>1?h.depth:void 0},`${e.frameWords.else}: ${h.otherwise}`));continue}if("close"in h){i=null;continue}i||(i=v("ol",{class:`${t}-list-items`,start:h.n}),f.push(i)),i.c.push(v("li",null,a(h.label),": ",c(l(h.from))," to ",c(l(h.to)),`${r(h.kind)}.`,h.note?` ${Wt(h.note)}`:""))}return f}const m=[];for(const f of e.nodes)m.push(v(`h${n}`,{class:`${t}-list-group`},f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},a(f.name)):a(f.name),d(f))),m.push(v("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(i=>v("li",null,a(i.name),i.key==="PK"?", primary key":i.key==="FK"?", foreign key":"",i.ref?[", references ",a(`${i.ref.table}.${i.ref.column}`),i.card?[" (",mn(f.id,i.ref.table,i.card,a),")"]:""]:i.type?`, ${i.type}`:"")),...f.more?[v("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return m}function Be(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Zt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(c=>c.href)?" Enter opens a part that is a link.":""}`}function re(t,e=!1){const n=e&&t.type!=="sequence"&&Zt(t)&&t.cols>1&&t.rows>1,o=t.nodes.some(c=>c.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Me(t)},{keys:["Home","End"],words:"the ends"},...o,{keys:["Esc"],words:"clear"}]}var Bn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Zt(t){return jt(t,"spatial",()=>{const e=t.nodes.map(s=>({id:s.id,...jn(t,s)})),n=(s,a)=>{const l=a==="right"||a==="left",r=a==="right"||a==="down",d=$=>l?[$.col,$.col]:$.rows,m=$=>l?$.rows:[$.col,$.col],f=d(s),i=m(s);let h=null;return e.forEach(($,p)=>{if($===s)return;const u=d($),M=m($),C=r?u[0]-f[1]:f[0]-u[1];if(C<1)return;const z=Math.max(0,M[0]-i[1],i[0]-M[1]),w=[z===0?0:1,z===0?C:C+2*z,z,Math.abs(M[0]-i[0]),p];(!h||Bn(w,h.rank))&&(h={id:$.id,rank:w})}),h?.id??null},o=Lt();for(const s of e)o[s.id]={right:n(s,"right"),left:n(s,"left"),down:n(s,"down"),up:n(s,"up")};const c=s=>{const a=new Set([s]),l=[s];for(;l.length;)for(const r of Object.values(o[l.pop()]))r&&!a.has(r)&&(a.add(r),l.push(r));return a.size};return e.every(s=>c(s.id)===e.length)?o:null})}function Jt(t){return jt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!ie(t))return{lane:e,dropped:n,lanes:0};const o=(r,d)=>(t.byId.get(r)?.row??0)*1e3+d,c=new Map;t.edges.forEach((r,d)=>{const m=`${r.to}.${r.toRow}.${r.card?.to??""}`,f=o(r.from,r.fromRow??0),i=o(r.to,r.toRow??0),h=c.get(m)??{members:[],lo:1/0,hi:-1/0};h.members.push(d),h.lo=Math.min(h.lo,f,i),h.hi=Math.max(h.hi,f,i),c.set(m,h)});const s=[...c.values()].sort((r,d)=>d.hi-d.lo-(r.hi-r.lo)),a=[];let l=0;for(const r of s.reverse()){const d=new Set(a.filter(f=>f.lo<=r.hi&&r.lo<=f.hi).map(f=>f.lane));let m=0;for(;d.has(m);)m++;if(m>1){for(const f of r.members)n.add(f);continue}a.push({lo:r.lo,hi:r.hi,lane:m});for(const f of r.members)e.set(f,m);l=Math.max(l,m+1)}return{lane:e,dropped:n,lanes:l}})}var ie=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Xt(t,e,n){const o=n.prefix,c=wn(n.base),s=t.type==="sequence"||t.type==="schema"?null:Le(t),a={P:o,ids:c,level:n.level,plan:s,hidden:n.hiddenClass},l=e.layout==="drawn",r=Rt(t,e),d=t.type==="sequence"||t.type==="schema"?l:!0,m=`h${t.heading}`,f=[`--_cols:${ae(t)}`];if(t.type==="architecture"&&t.groups.length||l&&e.pad){const i=t.type==="architecture"?Se(t):[0,0,0,0],h=(p,u,M)=>p?p>1?`calc(${p} * var(--basalt-space-${u}))`:`var(--basalt-space-${u})`:M?`var(--basalt-space-${M})`:"0px",$=l&&e.pad?"3":void 0;f.push(`--_gpad:${h(i[0],"8",$)} ${h(i[1],"4")} ${h(i[2],"4",$)} ${h(i[3],"4")}`)}if(s?.gutter&&s.laneCount>2&&f.push(`--_gw:calc(${s.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),ie(t)){const i=t.marks?"var(--basalt-space-6) + var(--basalt-space-1)":"var(--basalt-space-5)";f.push(`--_gpad:0px ${Jt(t).lanes>1?`calc(${i} + var(--basalt-space-3))`:t.marks?`calc(${i})`:i} 0px 0px`)}return t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${o} ${n.className}`:o,"aria-labelledby":c.title,"data-type":t.type,"data-cols":ae(t),"data-reach":t.type==="architecture"?Ae(t):void 0,"data-gutter":s?.gutter?"":void 0,"data-marks":t.marks?"":void 0,"data-layout":e.layout??(t.unplaced?"stacked":void 0),"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:f.join(";")},v("div",{class:`${o}-head`},v(m,{id:c.title,class:`${o}-title`},t.title),n.hasSource?v("p",{class:`${o}-source`},{slot:"source"}):null),v("div",{class:`${o}-drawing`,style:l&&e.rows?`--_rows:${e.rows};--_row-gap:0px`:void 0,role:d?"group":void 0,"aria-roledescription":d?"diagram":void 0,"aria-labelledby":d?c.title:void 0,"aria-describedby":d?r?`${c.summary} ${c.keys}`:c.summary:void 0,"data-stops":r?"":void 0},In(a,t,e),t.text?null:v("div",{class:`${o}-ink`,"aria-hidden":"true"}),v("span",{class:`${o}-ruler`,"aria-hidden":"true"})),qe(o,t),v("p",{class:`${o}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),Rt(t,e)&&t.type!=="sequence"||l&&t.type==="sequence"?v("p",{class:`${o}-tap-hint`,"aria-hidden":"true"},`Tap ${Me(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${o}-foot`},{slot:"toggle"}),v("div",{id:c.list,class:`${o}-list`,hidden:!e.open},Ce(o,t)),v("span",{id:c.keys,class:n.hiddenClass},n.viewer?`${Be(t,l)} ${n.viewer}`:Be(t,l)),v("figcaption",{id:c.summary,class:`${o}-summary`},{slot:"summary"}))}function Rn(t){const e=getComputedStyle(t),n=(c,s)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${c}`));return Number.isFinite(a)?a:s},o=new Map;return{space:c=>(o.has(c)||o.set(c,n(`space-${c}`,parseFloat(c.replace("-","."))*4)),o.get(c)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Ut=(t,e)=>t==="main"?e.line:e.hair,St=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},_t=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,le=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function xt(t,e,n){const{l:o,t:c,r:s,b:a}=t.rect,l=(o+s)/2,r=(c+a)/2,d=(s-o)/2,m=(a-c)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const $=n,p=m*Math.max(0,1-Math.abs($-l)/d);return{x:$,y:e==="top"?r-p:r+p}}const i=n,h=d*Math.max(0,1-Math.abs(i-r)/m);return{x:e==="left"?l-h:l+h,y:i}}if(t.shape==="terminal"){const i=Math.min(d,m);if(f){const u=n,M=Math.min(Math.max(u,o+i),s-i),C=u-M,z=Math.abs(C)>=i?0:Math.sqrt(i*i-C*C);return{x:u,y:Math.abs(C)<1e-6?e==="top"?c:a:e==="top"?r-z:r+z}}const h=n,$=h-r,p=Math.abs($)>=i?0:Math.sqrt(i*i-$*$);return{x:e==="left"?o+i-p:s-i+p,y:h}}return f?{x:n,y:e==="top"?c:a}:{x:e==="left"?o:s,y:n}}function Tn(t,e,n){const{l:o,t:c,r:s,b:a}=e.rect,l=(o+s)/2,r=(c+a)/2,d=(s-o)/2,m=(a-c)/2;if(e.shape==="decision")return Math.abs(t.x-l)/d+Math.abs(t.y-r)/m<1-n/Math.min(d,m);if(e.shape==="terminal"){const f=Math.min(d,m),i=Math.min(Math.max(t.x,o+f),s-f);return Math.hypot(t.x-i,t.y-r)o+n&&t.xc+n&&t.ymatchMedia("(forced-colors: active)").matches;function Wn(t,e){const n=t.querySelector(`.${e}-ruler`),o=new Map;return(c,s)=>{const a=`${s}|${c}`;return o.has(a)||(n.setAttribute("data-f",s),n.textContent=c,o.set(a,n.getBoundingClientRect().width),n.textContent=""),o.get(a)}}var Yt=t=>t?t.split(/\s+/).filter(Boolean):[];function Fn(t,e,n){const o=e.space;let c=e.node,s=e.table;for(const r of t.nodes){if(r.shape==="table"){for(const p of r.columns??[]){const u=p.ref?`${t.rtl?"←":"→"} ${p.ref.table}`:p.type??"",M=o("6")+n(p.name,"mono")+(u?o("3")+n(u,"mono"):0)+2*o("3")+2*e.hair;s=Math.max(s,Math.ceil(M))}s=Math.max(s,Math.ceil(n(r.name,"table")+2*o("3")+2*e.hair+(r.href?16+o("1-5"):0)));continue}const d=r.shape==="terminal"?2*o("5"):2*o("3"),m=r.mark&&!Nn()?(r.shape==="participant"?2:1)*o("6"):0;let f=0;const i=r.href?16+o("1-5"):0,h=Yt(r.name);if(h.forEach((p,u)=>{f=Math.max(f,n(p,r.shape==="decision"?"name-500":"name")+(r.kind?0:m)+(u===h.length-1?i:0))}),t.type!=="data-flow")for(const p of Yt(r.kind))f=Math.max(f,n(p,"mono")+m);for(const p of Yt(r.detail))f=Math.max(f,n(p,r.mono?"mono":"sans"));const $=r.shape==="decision"?f/.62:f+d+2*e.hair;c=Math.max(c,Math.ceil($))}const a=ae(t);let l;return t.type==="data-flow"?l=e.lane+a*(c+o("12")):t.type==="schema"?l=a*s+(a-1)*(o("12")+(t.marks?o("3"):0))+(ie(t)?(t.marks?o("6")+o("1"):o("5"))+(Jt(t).lanes>1?o("3"):0):0):t.type==="sequence"?l=a*c+(a-1)*o("5"):l=a*c+(a-1)*o("16")+Ae(t)*o("4"),{track:c,table:s,least:Math.max(e.wide,l)}}function Re(t,e){return{x:(n,o)=>o%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,o)=>o%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function ce(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Te(t,e,n){const o=t.map(s=>({...s}));for(let s=1;s=2){const r=c[c.length-2];if(Math.abs(r.x-l.x)<.01&&Math.abs(l.x-a.x)<.01||Math.abs(r.y-l.y)<.01&&Math.abs(l.y-a.y)<.01){c[c.length-1]=a;continue}}c.push(a)}}return c}var qt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Qt(t,e,n){const o=[];for(let s=0;sMath.min(p.x,u.x)+.75&&zMath.min(M.y,C.y)+.75&&ws.split(/\s+/).map(parseFloat).filter(a=>Number.isFinite(a)),o=(s,a,l)=>{const r=[];let d=a;for(const m of s)r.push([d,d+m]),d+=m+l;return r},c=o(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0);return{cols:o(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:t.style.getPropertyValue("--_rows").trim()?c.filter((s,a)=>a%2===1):c}}var ft=t=>t==="left"||t==="right",ze={top:"bottom",bottom:"top",left:"right",right:"left"};function de(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Ne(t,e,n){const o=[];t.edges.forEach((s,a)=>{const l=t.byId.get(s.from),r=t.byId.get(s.to),[d,m]=e[a],f=l.row===r.row&&ft(d)&&ft(m)&&d===ze[m]||l.col===r.col&&!ft(d)&&!ft(m)&&d===ze[m];o.push({edge:a,end:"from",node:l,side:d,far:r,straight:f,f:.5},{edge:a,end:"to",node:r,side:m,far:l,straight:f,f:.5})});const c=new Map;for(const s of o){const a=`${s.node.id}.${s.side}`;c.has(a)||c.set(a,[]),c.get(a).push(s)}for(const[s,a]of c){if(a[0].node.shape==="decision")continue;const l=p=>ft(p.side)?p.far.row-p.node.row:p.far.col-p.node.col,r=a.filter(p=>p.straight),d=a.filter(p=>!p.straight);if(d.sort((p,u)=>l(p)-l(u)||(ft(p.side)?p.far.col-u.far.col:p.far.row-u.far.row)*(l(p)<0?1:-1)),a.length>3&&n(`${s.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!r.length){d.length===2?(d[0].f=.25,d[1].f=.75):d.length===3?(d[0].f=.25,d[1].f=.5,d[2].f=.75):d.length>3&&d.forEach((p,u)=>{p.f=(u+1)/(d.length+1)});continue}const m=new Map;for(const p of r)m.has(p.far.id)||m.set(p.far.id,[]),m.get(p.far.id).push(p);for(const p of m.values())p.length>1&&p.sort((u,M)=>u.edge-M.edge).forEach((u,M)=>{u.f=p.length===2?M===0?.25:.75:(M+1)/(p.length+1)});const f=Math.min(...r.map(p=>p.f)),i=Math.max(...r.map(p=>p.f)),h=d.filter(p=>l(p)<0),$=d.filter(p=>l(p)>=0);h.forEach((p,u)=>{p.f=f*(u+1)/(h.length+1)}),$.forEach((p,u)=>{p.f=i+(1-i)*(u+1)/($.length+1)})}return o}function We(t,e=8,n=8){return jt(t,`port-floors:${e}:${n}`,()=>{const o=Lt();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return o;const c=t.edges.map(a=>{const l=t.byId.get(a.from),r=t.byId.get(a.to),[d,m]=de(l,r);return[a.fromSide??d,a.toSide??m]}),s=new Map;for(const a of Ne(t,c,()=>{})){if(!ft(a.side)||a.node.shape!=="box")continue;const l=`${a.node.id}.${a.side}`;s.has(l)||s.set(l,[]),s.get(l).push(a.f)}for(const[a,l]of s){if(l.length<2)continue;const r=l.slice().sort((f,i)=>f-i).filter((f,i,h)=>i===0||f-h[i-1]>1e-9);let d=Math.max(e/r[0],e/(1-r[r.length-1]));for(let f=1;f{const a=t.byId.get(s.dataset.node);a&&c.set(a.id,{id:a.id,rect:St(s,n),shape:a.shape,i:a.i})}),c}function De(t,e){const n=e.head,o=e.head/2,{x:c,y:s}=t.tip;return t.dir==="down"?{l:c-o,r:c+o,t:s-n,b:s}:t.dir==="up"?{l:c-o,r:c+o,t:s,b:s+n}:t.dir==="right"?{l:c-n,r:c,t:s-o,b:s+o}:{l:c,r:c+n,t:s-o,b:s+o}}var Ge=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Ve(t,e,n,o){const c=(s,a)=>{const l=s+a-Math.floor(s+a);return l<.005||l>.995?[0]:l<=.5?[-l,1-l]:[1-l,-l]};for(const s of c(t.t,n))for(const a of c(t.l,e)){if(!a&&!s)return t;const l={l:t.l+a,r:t.r+a,t:t.t+s,b:t.b+s};if(o(l))return l}return t}function Dn(t,e,n,o,c,s,a,l,r){const d=a.space,m=[],f=[],i=[],h=[],$=d("1"),p=e.filter(u=>t.edges[u.i]?.label).sort((u,M)=>+(t.edges[M.i].kind==="main")-+(t.edges[u.i].kind==="main")||u.i-M.i);for(const u of p){const M=t.edges[u.i].label,C=l(M,"label"),z=16*ne(M),w=u.pts.length-2,S=[];qt(u.pts).forEach(([q,G],j)=>{const x=Math.abs(q.y-G.y)<.01,R=x?q.x:q.y;let D=x?G.x:G.y;const Z=Math.sign(D-R)||1;j===w&&(D-=Z*a.head);let K=[[R,D]];for(const J of c)for(const g of x?[J.l,J.r]:[J.t,J.b]){const y=x?q.y:q.x;(x?y>J.t&&yJ.l&&yg>Math.min(A,L)+1&&g{const y=(J+g)/2,E=x?{x:y,y:q.y}:{x:q.x,y};return!c.some(A=>E.x>A.l&&E.xA.t&&E.y1&&at(J,g)?1:0})}),S.sort((q,G)=>G.pri-q.pri||G.len-q.len);let B=null,Y=!1;const F=(q,G=!0)=>{const j=le(q,$);return G&&(q.ls.r||q.ts.b)||n.some(x=>je(j,x))||m.some(x=>_t(j,x))||o.heads.some(x=>_t(j,x))||o.rects.some(x=>_t(j,x))?!1:!e.some(x=>x.i!==u.i&&qt(x.pts).some(([R,D])=>_t(j,Ge(R,D,x.width))))};for(const q of S){for(const G of[1/2,1/3,2/3]){const j=q.p+(q.q-q.p)*G,x=[],R=d("2")+u.width/2;if(q.horiz?(q.len>=C+2*d("1")+d("3-5")&&x.push({box:{l:j-C/2-d("1"),r:j+C/2+d("1"),t:q.c-z/2,b:q.c+z/2},on:!0}),x.push({box:{l:j-C/2,r:j+C/2,t:q.c-R-z,b:q.c-R},on:!1}),x.push({box:{l:j-C/2,r:j+C/2,t:q.c+R,b:q.c+R+z},on:!1})):(q.len>=z+d("3")&&x.push({box:{l:q.c-C/2-d("1"),r:q.c+C/2+d("1"),t:j-z/2,b:j+z/2},on:!0}),x.push({box:{l:q.c+R,r:q.c+R+C,t:j-z/2,b:j+z/2},on:!1}),x.push({box:{l:q.c-R-C,r:q.c-R,t:j-z/2,b:j+z/2},on:!1})),B=x.find(D=>F(D.box))??null,B)break;!Y&&x.some(D=>F(D.box,!1))&&(Y=!0)}if(B)break}if(!B){i.push(u.i),Y&&h.push(u.i);continue}const it=Ve(B.box,r.ox,r.oy,q=>F(q));m.push(it),f.push({i:u.i,text:M,box:it,on:B.on})}return{labels:f,unseated:i,bounded:h}}function Ke(t,e,n,o){const c=[],s=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const l=St(a,e);s.push(l),c.push({l:l.l,r:l.r,t:l.t,b:l.t+1},{l:l.l,r:l.r,t:l.b-1,b:l.b},{l:l.l,r:l.l+1,t:l.t,b:l.b},{l:l.r-1,r:l.r,t:l.t,b:l.b});const r=a.querySelector(`:scope > .${n}-glabel`);r&&r.getClientRects().length&&c.push(St(r,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,l)=>{if(!a.getClientRects().length)return;const r=St(a,e);l>0&&c.push({l:r.l,r:r.r,t:r.t-o/2-.5,b:r.t-o/2+.5});const d=a.querySelector(`.${n}-lane-name`);d&&c.push(St(d,e))}),{obstacles:{rects:c,heads:[]},groups:s}}function Ze(t,e){const{m:o,tk:c,P:s,drawing:a,origin:l,warn:r}=t,d=c.space,m=He(o,a,l,s),f=[...m.values()],i=Hn(a),h=l.left-Math.floor(l.left),$=l.top-Math.floor(l.top),p=Re(h,$),u=a.clientWidth,M=a.clientHeight,C=b=>o.type==="data-flow"?b.col+1:b.col,z=parseFloat(getComputedStyle(a).rowGap)||0,w={w:u,h:M,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:h,oy:$};if(o.type==="sequence")return Vn(t,w,p);let S,B=[];o.type==="schema"?S=o.edges.map(b=>{const I=o.byId.get(b.from),_=o.byId.get(b.to);if(I.col===_.col){const k=I.col===o.cols&&o.cols>1?"left":"right";return[k,k]}return _.col>I.col?["right","left"]:["left","right"]}):(S=o.edges.map(b=>{const I=o.byId.get(b.from),_=o.byId.get(b.to),[k,O]=de(I,_);return[b.fromSide??k,b.toSide??O]}),B=Ne(o,S,r||(()=>{})));const Y=(b,I)=>{const _=a.querySelector(`.${s}-node[data-node="${CSS.escape(b)}"] .${s}-row[data-row="${I}"]`);if(!_)return 0;const k=St(_,l);return(k.t+k.b)/2},F=new Map;if(o.type==="schema"){const b=new Map;o.edges.forEach((_,k)=>{const O=`${_.to}.${_.toRow}.${S[k][1]}`;b.set(O,[...b.get(O)??[],k])});const I=_=>{const k=o.edges[_].card?.to;return k==="one"?0:k==="zero-or-one"?1:2};for(const _ of b.values()){const k=[...new Set(_.map(I))].sort((O,H)=>O-H);if(k.length>1)for(const O of _)F.set(O,(k.indexOf(I(O))-(k.length-1)/2)*d("2"))}}const it=b=>Math.round(b+h)-h,q=o.edges.map((b,I)=>{const[_,k]=S[I],O=m.get(b.from),H=m.get(b.to),X=Ut(b.kind,c);if(b.fk){const Q=Y(b.from,b.fromRow),et=Y(b.to,b.toRow)+(F.get(I)??0),yt=p.y(Q,X),Ct=p.y(et,X),Et=_==="right"?O.rect.r:O.rect.l,Mt=k==="right"?H.rect.r:H.rect.l;return{p1:{x:b.card?it(Et):Et,y:yt},p2:{x:b.card?it(Mt):Mt,y:Ct},r1:Q,r2:Math.abs(yt-Ct)<.01?Q:et}}const tt=B.find(Q=>Q.edge===I&&Q.end==="from").f,rt=B.find(Q=>Q.edge===I&&Q.end==="to").f;let st=Fe(O,_,tt),ot=Fe(H,k,rt);const W=ft(_)?st.y:st.x;let V=ft(k)?ot.y:ot.x;return ft(_)?st={...st,y:p.y(st.y,X)}:st={...st,x:p.x(st.x,X)},ft(k)?ot={...ot,y:p.y(ot.y,X)}:ot={...ot,x:p.x(ot.x,X)},ft(_)&&ft(k)&&Math.abs(st.y-ot.y)<1.01&&(ot={...ot,y:st.y},V=W),!ft(_)&&!ft(k)&&Math.abs(st.x-ot.x)<1.01&&(ot={...ot,x:st.x},V=W),st=ft(_)?xt(O,_,st.y):xt(O,_,st.x),ot=ft(k)?xt(H,k,ot.y):xt(H,k,ot.x),{p1:st,p2:ot,r1:W,r2:V}}),G=new Set,j=(b,I)=>{G.has(b)||(G.add(b),r?.(`${o.edges[b].from} to ${o.edges[b].to} ${I}, so its line is not drawn; its row still writes the target`))};for(const b of Jt(o).dropped)j(b,"would need a third lane of turn-backs");const x=new Map,R=Lt();o.type==="schema"&&o.edges.forEach((b,I)=>{const _=o.byId.get(b.from),k=o.byId.get(b.to);if(Math.abs(_.col-k.col)<2)return;const O=Math.min(_.col,k.col),H=Math.max(_.col,k.col),X=o.nodes.filter(et=>et.col>O&&et.colyt.row<=et&&yt.row2>=et+1)||rt.push({key:`g${et}`,y:(tt[et-1][1]+tt[et][0])/2,inner:!0});rt.push({key:"top",y:tt[0][0]-d("4"),inner:!1},{key:"bottom",y:tt[tt.length-1][1]+d("4"),inner:!1});const st=(q[I].r1+q[I].r2)/2,ot=t.pick?.[I]??rt.slice().sort((et,yt)=>Math.abs(et.y-st)-Math.abs(yt.y-st)||Number(yt.inner)-Number(et.inner)||et.y-yt.y)[0].key;R[I]=ot;const W=S[I][0]==="right"?_.col:_.col-1,V=i.cols[W-1],Q=i.cols[W];x.set(I,{corridor:ot,first:V&&Q?{key:`c${W}`,span:[V[1],Q[0]]}:null,y:0})});const D=new Map;for(const[b,I]of x){const _=o.edges[b],k=D.get(I.corridor)??[],O=k.find(H=>{const X=o.edges[H[0]];return X.to===_.to&&X.toRow===_.toRow&&S[H[0]][1]===S[b][1]&&Math.abs(q[H[0]].p2.y-q[b].p2.y)<.5});O?O.push(b):k.length>=2?j(b,"would need a third lane in its corridor"):k.push([b]),D.set(I.corridor,k)}for(const b of[...x.keys()])G.has(b)&&x.delete(b);const Z=b=>{const I=o.edges[b[0]];return Math.abs(o.byId.get(I.from).col-o.byId.get(I.to).col)*1e4+Math.abs(q[b[0]].p1.x-q[b[0]].p2.x)},K=(b,I,_)=>{const k=i.rows;if(b==="top")return k[0][0]-d("4")-I*d("3");if(b==="bottom")return k[k.length-1][1]+d("4")+I*d("3");const O=Number(b.slice(1));return(k[O-1][1]+k[O][0])/2+(I-(_-1)/2)*d("3")},at=(b,I)=>I.forEach((_,k)=>_.forEach(O=>{x.get(O).y=K(b,k,I.length)})),nt=()=>{for(const[b,I]of D){const _=I.map(k=>k.filter(O=>x.has(O))).filter(k=>k.length);D.set(b,_),at(b,b==="top"||b==="bottom"?_.slice().sort((k,O)=>Z(k)-Z(O)):_.slice().sort((k,O)=>Z(O)-Z(k)))}};nt();const J=new Map,g=new Set,y=new Map,E=(b,I,_,k,O)=>{J.has(b)||J.set(b,{span:I,vertical:_,members:new Map});const H=J.get(b);H.members.has(k)||H.members.set(k,[]),H.members.get(k).push(O)},A=()=>{J.clear(),g.clear(),y.clear(),o.edges.forEach((b,I)=>{if(G.has(I))return;const _=x.get(I);_?.first&&E(_.first.key,_.first.span,!0,`far:${I}`,-(I+1));const[k,O]=S[I],{p1:H,p2:X}=q[I],tt=o.byId.get(b.from),rt=o.byId.get(b.to);let st=null,ot=null,W=!1;if(k===O){if(ft(k)){const V=k==="right"?Math.max(C(tt),C(rt)):Math.min(C(tt),C(rt))-1,Q=i.cols[V-1],et=i.cols[V];Q&&et&&(st=`c${V}`,ot=[Q[1],et[0]],W=!0)}else{const V=k==="bottom"?Math.max(tt.row2,rt.row2):Math.min(tt.row,rt.row)-1,Q=i.rows[V-1],et=i.rows[V];Q&&et&&(st=`r${V}`,ot=[Q[1],et[0]],W=!1)}st&&g.add(I)}else if(ft(k)&&ft(O)&&(_||Math.abs(H.y-X.y)>.5)){const V=C(rt),Q=O==="left",et=i.cols[(Q?V-1:V)-1],yt=i.cols[(Q?V:V+1)-1];et&&yt&&(st=`c${Q?V-1:V}`,ot=[et[1],yt[0]],W=!0)}else if(!ft(k)&&!ft(O)&&Math.abs(H.x-X.x)>.5){const Q=O==="top"?rt.row-1:rt.row2,et=i.rows[Q-1],yt=i.rows[Q];et&&yt&&(st=`r${Q}`,ot=[et[1],yt[0]],W=!1)}!st||!ot||(_&&y.set(I,ot),E(st,ot,W,`${b.to}.${O}.${Math.round(W?X.y:X.x)}`,I))})};A();const L=new Map,T=b=>{const[I,_]=S[b],{p1:k,p2:O}=q[b],H=x.get(b);if(H){const X=y.get(b),tt=L.get(-(b+1))??(H.first?(H.first.span[0]+H.first.span[1])/2:k.x),rt=L.get(b)??(X?(X[0]+X[1])/2:O.x);return[k,{x:tt,y:k.y},{x:tt,y:H.y},{x:rt,y:H.y},{x:rt,y:O.y},O]}if(ft(I)&&ft(_)){if(I===_){const tt=d(o.marks?"6":"4")+(o.type==="schema"&&o.cols===1?(Jt(o).lane.get(b)??0)*d("3"):0),rt=L.get(b)??(I==="right"?Math.max(k.x,O.x)+tt:Math.min(k.x,O.x)-tt);return[k,{x:rt,y:k.y},{x:rt,y:O.y},O]}if(Math.abs(k.y-O.y)<=.5)return[k,{x:O.x,y:k.y}];const X=L.get(b)??(k.x+O.x)/2;return[k,{x:X,y:k.y},{x:X,y:O.y},O]}if(!ft(I)&&!ft(_)){if(I===_){const tt=L.get(b)??(I==="bottom"?Math.max(k.y,O.y)+d("4"):Math.min(k.y,O.y)-d("4"));return[k,{x:k.x,y:tt},{x:O.x,y:tt},O]}if(Math.abs(k.x-O.x)<=.5)return[k,{x:k.x,y:O.y}];const X=L.get(b)??(k.y+O.y)/2;return[k,{x:k.x,y:X},{x:O.x,y:X},O]}return ft(I)?[k,{x:O.x,y:k.y},O]:[k,{x:k.x,y:O.y},O]},U=b=>{const I=o.edges[b],_=Ut(I.kind,c),k=T(b),O=Te(k,_,p);let H;return k.length===O.length&&(H=qt(k).map(([X,tt])=>Math.abs(X.y-tt.y)<.75?(X.y+tt.y)/2:(X.x+tt.x)/2),H[0]=q[b].r1,H.length>1&&(H[H.length-1]=q[b].r2)),{i:b,from:I.from,to:I.to,kind:I.kind,pts:O,tip:O[O.length-1],dir:ce(O),dot:I.fk&&!I.card?O[0]:void 0,card:I.card,width:_,axes:H}},N=()=>o.edges.flatMap((b,I)=>G.has(I)?[]:[U(I)]);let ht=null;const P=b=>{ht??(ht=N());const I=ht.map(_=>b.has(_.i)?U(_.i):_);return{lines:I,score:Gn(I,b)*1e5+Qt(I,void 0,b).length*1e3+ue(I.filter(_=>b.has(_.i)),f,o).length}},lt=(b,I)=>{const _=b.flatMap(k=>{const O=k<0?-k-1:k,{p1:H,p2:X}=q[O],tt=x.get(O);return tt?k<0?[H.y,tt.y]:[tt.y,X.y]:I?[H.y,X.y]:[H.x,X.x]});return[Math.min(..._),Math.max(..._)]},dt=b=>b<0?-b-1:b,mt=b=>{const I=[...b.members.values()].map(k=>({members:k,run:lt(k,b.vertical)})).sort((k,O)=>k.run[0]-O.run[0]),_=[];for(const k of I){const O=_[_.length-1];O&&O.some(H=>H.run[0]!(k.length===1&&k[0].members.every(O=>g.has(O))))},wt=b=>(I,_)=>b[I].run[0]{const I=wt(b),_=[];return b.forEach((k,O)=>{let H=0;for(;_.some((X,tt)=>X===H&&I(O,tt));)H++;_.push(H)}),_},vt=b=>Math.max(0,...kt(b))+1;if(o.marks)for(let b=0;b3){I=H.map(X=>X.members.map(dt));break}if(!I)break;const _=O=>Math.max(...O),k=I.filter(O=>O.some(H=>x.has(H))).sort((O,H)=>_(H)-_(O))[0]??I.slice().sort((O,H)=>_(H)-_(O))[0];for(const O of k)j(O,"would need a fourth lane in a marked gutter"),x.delete(O);A()}const pt=(b,I,_)=>{const k=b[1]-b[0];if(!o.marks)return b[0]+k/(_+1)*(I+1);const O=c.foot+c.radiusXs,H=_>1?Math.min(k/(_+1),(k-2*O)/(_-1)):0;return(b[0]+b[1])/2+(I-(_-1)/2)*H};nt();for(const[b,I]of D){if(b==="top"||b==="bottom"||I.length<2)continue;const _=new Set(I.flat());let k=I,O=1/0;for(const H of fe(I.slice().sort((X,tt)=>Z(tt)-Z(X)))){at(b,H),ht=null;const X=P(_);X.scorert.members);if(o.marks){const rt=vt(I),st=wt(I),ot=I.length,W=new Set(_.flat().map(dt)),V=Et=>Et.forEach((Mt,Tt)=>_[Tt].forEach(Bt=>L.set(Bt,pt(b.span,Mt,rt))));let Q=kt(I),et=1/0,yt=null;const Ct=[Q];if(rt**ot<=729)for(let Et=0;EtMath.floor(Et/rt**Bt)%rt);Mt.every((Tt,Bt)=>Mt.every((te,Gt)=>Gt<=Bt||Tt!==te||!st(Bt,Gt)))&&Ct.push(Mt)}for(const Et of Ct){V(Et);const Mt=P(W);Mt.scoreot.forEach(V=>L.set(V,pt(b.span,W,k))));const st=P(O);st.scorert.forEach(ot=>L.set(ot,pt(b.span,st,k)))),ht=tt}if(w.lines=N(),o.marks&&(w.lines=w.lines.filter(b=>{if(!b.card)return!0;const I=qt(b.pts),_=([O,H])=>Math.hypot(H.x-O.x,H.y-O.y),k=I.length===1?2*c.foot:c.foot+c.radiusXs-.5;return _(I[0])>=k&&_(I[I.length-1])>=k?!0:(j(b.i,"has no room for its marks at an end"),x.delete(b.i),!1)})),x.size){const b=new Set([...x.values()].map(_=>_.corridor)),I=[b.has("top")?"var(--basalt-space-8)":"0px"];for(let _=1;_<=o.rows;_++)I.push("auto",_De(b,c));const bt=Dn(o,w.lines,f,ut,ct,{l:0,t:0,r:u,b:M},c,e,{ox:h,oy:$});return w.labels=bt.labels,w.unseated=bt.unseated,w.bounded=bt.bounded,w.overlaps=[...new Set(Je(w.lines,null).flat())],w}function Gn(t,e){return Je(t,e).length}function Je(t,e){const n=[];for(let o=0;o=l)continue;const[u,M]=i?[r.x,d.x]:[r.y,d.y],[C,z]=i?[m.x,f.x]:[m.y,f.y];Math.min(Math.max(u,M),Math.max(C,z))-Math.max(Math.min(u,M),Math.min(C,z))>1&&n.push([s.i,a.i])}}return n}function*fe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const r=l===s.pts.length-1?Math.max(s.width/2,o.head/2):s.width/2;return a.x-r<-.5||a.x+r>e+.5||a.y-r<-.5||a.y+r>n+.5})&&c.push(s.i);return c}function ue(t,e,n){const o=[];for(const c of t){const s=qt(c.pts);e.some(a=>s.some(([l,r])=>zn(l,r,a)))&&o.push(c.i)}return o}function Vn(t,e,n){const{m:o,tk:c,P:s,drawing:a,origin:l}=t,r=c.space,d=new Map;a.querySelectorAll(`.${s}-node`).forEach(w=>d.set(w.dataset.node,St(w,l)));const m=a.querySelector(`.${s}-steps`),f=m?St(m,l).b:e.h,i=w=>{const S=d.get(w);return S?n.x((S.l+S.r)/2,c.hair):0};for(const w of o.nodes){const S=d.get(w.id);S&&e.lifelines.push({x:i(w.id),y1:S.b,y2:f})}const h=w=>d.get(w.id),$=new Map;a.querySelectorAll(`.${s}-msg`).forEach(w=>{const S=St(w,l);$.set(Number(w.querySelector(`.${s}-num`)?.textContent??0),(S.t+S.b)/2)});const p=c.activation,u=p/2,M=w=>{const S=o.byId.get(w.who);if(!S)return null;const B=i(w.who),F=(S.i===o.nodes.length-1&&o.nodes.length>1?-1:1)*(o.rtl?-1:1),it=(w.depth-1)*r("1")*F,q=$.get(w.from)??0,G=$.get(w.to)??q,j=w.from===w.to;return{l:n.x(B-u+it,c.hair),r:n.x(B+u+it,c.hair),t:n.y(j?q-r("2")-r("1"):q,c.hair),b:n.y(j?q+r("2")+r("1"):G,c.hair)}},C=o.bars.map(w=>({bar:w,rect:M(w)})).filter(w=>w.rect);e.bars=C.map(w=>w.rect);const z=(w,S,B)=>C.filter(({bar:Y})=>Y.who===w&&Y.to>=S&&(B?Y.from<=S:Y.fromF.bar.depth-Y.bar.depth)[0]?.rect;a.querySelectorAll(`.${s}-msg`).forEach(w=>{const S=w.dataset.from,B=w.dataset.to,Y=w.dataset.kind??"plain",F=Ut(Y,c),it=St(w,l),q=n.y((it.t+it.b)/2,F),G=Number(w.querySelector(`.${s}-num`)?.textContent??0);let j=i(S),x=i(B),R;if(S===B){const g=w.dataset.self==="start"?-r("6"):r("6"),y=z(S,G,!0),E=y?g>0?y.r:y.l:j,A=n.y(q-r("2"),F),L=n.y(q+r("2"),F);R=[{x:E,y:A},{x:n.x(j+g,F),y:A},{x:n.x(j+g,F),y:L},{x:E,y:L}]}else{const g=x>j?1:-1,y=z(S,G,!1),E=z(B,G,!0);y&&(j=g>0?y.r:y.l),E&&(x=g>0?E.l:E.r),R=[{x:j,y:q},{x,y:q}]}e.lines.push({i:G,from:S,to:B,kind:Y,pts:R,tip:R[R.length-1],dir:ce(R),width:F});const D=w.querySelector(`.${s}-said`),Z=w.querySelector(`.${s}-note`),K=o.byId.get(S),at=o.byId.get(B);if(!K||!at)return;const nt=S===B?(()=>{const g=o.nodes.find(E=>E.col===K.col+(w.dataset.self==="start"?-1:1)),y=g?i(g.id):w.dataset.self==="start"?0:e.w;return Math.abs(y-j)-r("6")-r("2-5")-r("2")})():Math.abs(x-j)-2*r("2");Math.max(D?D.getBoundingClientRect().width:0,Z?Z.getBoundingClientRect().width:0)>nt+.5&&e.unseated.push(G)}),a.querySelectorAll(`.${s}-fhead`).forEach(w=>{const S=w.parentElement?.querySelector(`:scope > .${s}-fbox`);if(!S)return;[...w.children].reduce((Y,F)=>Y+F.getBoundingClientRect().width,0)+r("3")>S.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${w.querySelector(`.${s}-flabel`)?.textContent??""}" is wider than its participants`)});{const w=[...a.querySelectorAll(`.${s}-fbox`)].flatMap(S=>{const B=St(S,l);return[{x:B.l+.5,t:B.t,b:B.b},{x:B.r-.5,t:B.t,b:B.b}]});w.length&&a.querySelectorAll(`.${s}-said, .${s}-note, .${s}-band > span`).forEach(S=>{if(!S.getClientRects().length)return;const B=le(St(S,l),r("1"));w.some(Y=>B.lY.x&&B.tY.t)&&(e.misfit??(e.misfit=[])).push(`"${S.textContent?.trim()??""}" would lie on a frame's side`)})}return e}function Ue(t,e,n,o=Lt()){const{m:c,tk:s,P:a,drawing:l,origin:r}=t,d=s.space,m=He(c,l,r,a),f=[...m.values()],i=r.left-Math.floor(r.left),h=r.top-Math.floor(r.top),$=Re(i,h),p=l.clientWidth,u=l.clientHeight,M={w:p,h:u,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:i,oy:h},C=Lt();if(c.type==="sequence"||c.type==="schema")return{geo:M,grow:C};const z=p-(parseFloat(getComputedStyle(l).paddingRight)||0),w=(x,R,D)=>{const Z=[x];for(let K=1;K<=(Ot(o,R)??0);K++)Z.push({...x,t:x.t+D*d("4")*K,b:x.b+D*d("4")*K});return Z},S=new Map;l.querySelectorAll(`.${a}-node`).forEach(x=>{const R=x.parentElement,D=St(R,r),Z=getComputedStyle(R);S.set(x.dataset.node,D.r-(parseFloat(Z.paddingRight)||0)-(parseFloat(Z.borderRightWidth)||0))});const B=c.nodes,Y=x=>m.get(B[x].id),F=[],it=x=>Ut(c.edges[x].kind,s);c.edges.forEach((x,R)=>{const D=n.routes[R],Z=m.get(x.from),K=m.get(x.to),at=it(R);let nt=[];const J=x.label,g=J?e(J,"label"):0,y=J?16*ne(J):16,E=d("4");if(D==="down"||D==="up"){const L=Math.max(Z.rect.l,K.rect.l),T=Math.min(Z.rect.r,K.rect.r),U=c.edges.map((lt,dt)=>({o:lt,j:dt})).filter(({o:lt,j:dt})=>(n.routes[dt]==="down"||n.routes[dt]==="up")&&(lt.from===x.from&<.to===x.to||lt.from===x.to&<.to===x.from)),N=U.findIndex(lt=>lt.j===R),ht=U.length<2?.5:U.length===2?N===0?.25:.75:(N+1)/(U.length+1),P=$.x(L+(T-L)*ht,at);if(nt=D==="down"?[xt(Z,"bottom",P),xt(K,"top",P)]:[xt(Z,"top",P),xt(K,"bottom",P)],J){let lt=Math.min(nt[0].y,nt[1].y),dt=Math.max(nt[0].y,nt[1].y);D==="down"?dt-=s.head:lt+=s.head;const mt=[...l.querySelectorAll(`.${a}-group`)].map(pt=>St(pt,r));let wt=[[lt,dt]];for(const pt of mt)for(const ut of[pt.t,pt.b])wt=wt.flatMap(([ct,bt])=>ut>ct+1&&utmt.some(ct=>(pt+ut)/2>ct.t&&(pt+ut)/2ct.l&&P1){const pt=wt.filter(([ct,bt])=>!kt(ct,bt));[lt,dt]=(pt.length?pt:wt).reduce((ct,bt)=>bt[1]-bt[0]>ct[1]-ct[0]?bt:ct)}const vt=[1/2,1/3,2/3].map(pt=>{const ut=lt+(dt-lt)*pt;return{l:P-g/2-d("1"),r:P+g/2+d("1"),t:ut-y/2,b:ut+y/2}});F.push({k:R,cands:vt,on:!0,card:D==="down"?x.to:x.from})}}else if(D==="trunk"||D==="rail"){const L=$.x(Math.max(Z.rect.l,D==="rail"?K.rect.l:Z.rect.l)+d(D==="trunk"?"8":"3"),at),T=xt(Z,"bottom",L);if(D==="rail"){if(nt=[T,xt(K,"top",L)],J){const U=K.rect.t-d("6");F.push({k:R,cands:w({l:L+d("2-5"),r:L+d("2-5")+g,t:U-y/2,b:U+y/2},x.to,-1),on:!1,card:x.to})}}else{const U=$.x(K.rect.l+d("6"),at),N=$.y(K.rect.t-E,at);nt=[T,{x:L,y:N},{x:U,y:N},xt(K,"top",U)],J&&F.push({k:R,cands:w({l:U+d("2-5"),r:U+d("2-5")+g,t:N-y/2,b:N+y/2},x.to,-1),on:!1,card:x.to})}}else{const L=Math.min(S.get(x.from)??p,S.get(x.to)??p),T=$.x(n.gutter?z+(n.lanes[R]+1)*d("3-5"):L-d("2-5"),at),U=$.y(Z.rect.t+(Z.rect.b-Z.rect.t)*n.exits[R],at),N=xt(Z,"right",U),ht=D==="end-down",P=c.edges.map((ut,ct)=>({o:ut,j:ct})).filter(({o:ut,j:ct})=>n.routes[ct]===D&&ut.to===x.to).sort((ut,ct)=>n.lanes[ct.j]-n.lanes[ut.j]||ut.j-ct.j),lt=Math.max(0,P.findIndex(({j:ut})=>ut===R)),dt=K.rect.r-d("6")-lt*d("3"),mt=K.rect.r-d("6")-(P.length-1)*d("3"),wt=$.x(dt,at),kt=ht?K.rect.t-E-lt*d("5"):K.rect.b+E+lt*d("5"),vt=$.y(kt,at);nt=[N,{x:T,y:N.y},{x:T,y:vt},{x:wt,y:vt},xt(K,ht?"top":"bottom",wt)];const pt=ht?x.to:B[K.i+1]?.id??x.to;J&&F.push({k:R,cands:w({l:mt-d("2-5")-g,r:mt-d("2-5"),t:kt-y/2,b:kt+y/2},pt,ht?-1:1),on:!1,card:pt})}const A=Te(nt,at,$);M.lines.push({i:R,from:x.from,to:x.to,kind:x.kind,pts:A,tip:A[A.length-1],dir:ce(A),width:at})}),M.crossings=Qt(M.lines),M.through=ue(M.lines,f,c),M.outside=Xe(M.lines,p,u,s);const{obstacles:q}=Ke(l,r,a,0);q.heads=M.lines.map(x=>De(x,s));const G=[],j={l:0,t:0,r:p,b:u};for(const x of F){const R=K=>{const at=le(K,d("1"));return K.lj.r+.5||K.tj.b+.5||f.some(nt=>je(at,nt))||G.some(nt=>_t(at,nt))||q.heads.some(nt=>_t(at,nt))||q.rects.some(nt=>_t(at,nt))||M.lines.some(nt=>nt.i!==x.k&&qt(nt.pts).some(([J,g])=>_t(at,Ge(J,g,nt.width))))},D=x.cands.find(K=>!R(K));D||(C[x.card]=(C[x.card]??0)+1,M.unseated.push(x.k));const Z=D?Ve(D,i,h,K=>!R(K)):x.cands[0];G.push(Z),M.labels.push({i:x.k,text:c.edges[x.k].label,box:Z,on:x.on})}return{geo:M,grow:C}}function Ye(t,e,n=0){const o=a=>String(Math.round(a*100)/100);let c=`M${o(t[0].x)} ${o(t[0].y)}`;for(let a=1;a{const{crow:G,ring:j}=_e(Y,F.x,F.y,it,n.head,n.dot);return`${j?``:""}`};return`${B(e.card.from,w,Math.sign(S.x-w.x)||1,"from")}${B(e.card.to,e.tip,-s.x||1,"to")}`}const a=e.kind==="dashed",l=n.head,r=n.head/2,d=a?1:l-1,m=e.pts.map(w=>({...w})),f=m[m.length-1];f.x-=s.x*d,f.y-=s.y*d;const i=e.tip.x-s.x*l,h=e.tip.y-s.y*l,$=-s.y*r,p=s.x*r,u=w=>Math.round(w*100)/100,M=$t(e.kind),C=a?``:``,z=e.dot?``:"";return`${C}${z}`}function Qe(t,e,n,o){const c=new Map,s=new Map;for(const l of e.crossings)s.has(l.under)||s.set(l.under,[]),s.get(l.under).push(l);let a="";for(const[l,r]of s){const d=`${o}-cut-${l}`;c.set(l,d);const m=r.map(f=>{const i=e.lines[f.top],h=e.lines[f.under],$=i.width/2+n.cut,p=h.width/2+1;return f.underVertical?``:``}).join("");a+=`${m}`}return{defs:a,ids:c}}function Pe(t,e,n,o){const{defs:c,ids:s}=Qe(t,e,n,o),a=e.lifelines.map(i=>``).join(""),l=(e.bars??[]).map(i=>``).join(""),r=e.lines.map((i,h)=>Zn(t,i,n,s.get(h)??null,i.from===i.to?n.radiusXs:n.radius)).join(""),m=`${a?`${a}`:""}${c?`${c}`:""}${l}${r}`,f=e.labels.map(i=>`1?' data-lines="2"':""} style="left:${Math.round(i.box.l*100)/100}px;top:${Math.round(i.box.t*100)/100}px;width:${Math.round((i.box.r-i.box.l)*100)/100}px">${i.text.split(` -`).map($t).join("
")}
`).join("");return m+f}function he(t,e,n,o,c,s,a,l){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:c,geo:null,ink:"",tokens:null};const m=Rn(t),f=Wn(d,n),i=Fn(e,m,f);l?.(i.least);const h=t.clientWidth,$=(()=>{const q=document.activeElement;return q&&d.contains(q)&&q.dataset.node?q.dataset.node:void 0})(),p=q=>Rt(e,q)?{...q,stop:q.stop&&e.byId.has(q.stop)?q.stop:e.nodes[0]?.id,keep:void 0}:{...q,stop:q.stop??e.nodes[0]?.id,keep:$&&q.layout!=="drawn"?$:void 0};let u=!1;const M=q=>{if(u=!1,e.type!=="flowchart")return q;s({...q,heights:void 0,words:void 0});const G=Lt(),j=Lt();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(x=>{const R=x.querySelector(`.${n}-words`);if(!R)return;const D=x.getBoundingClientRect(),Z=nt=>{const J={w:nt.width+2*m.space("2-5"),h:nt.height+2*m.space("2")},g=1-J.w/D.width,y=g>.05?J.h/2/g:J.h*10;return Math.max(m.space("16"),Math.ceil(D.width/5),Math.ceil(2*y))},K=R.getBoundingClientRect();let at=Z(K);if(at>D.width){const nt=E=>(x.style.setProperty("--_ww",`${E}px`),R.getBoundingClientRect()),J=Math.floor(x.clientWidth-2*m.space("2-5"));let g=Math.ceil(K.width),y=K.height;for(;g1;){const U=E+A>>1;nt(U).heightD.width&&(u=!0)}),{...q,heights:G,words:Object.keys(j).length?j:void 0}},C=()=>({m:e,tk:m,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:a}),z=c.autoOpen?{open:!1,autoOpen:void 0}:{},w=(q,G)=>G.map(j=>Dt(e,q.lines.find(x=>x.i===j))).join(", ");if(e.text)return{dyn:{...c,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:m,least:i.least};if(h>=i.least&&!e.unplaced){const q=R=>{let D=p({...c,...z,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:R||void 0,rows:void 0});D=M(D),s(D);let Z=Ze(C(),f);return Z.corridors&&(D={...D,rows:Z.corridors.rows},s(D),Z=Ze({...C(),pick:Z.corridors.pick},f)),{dd:D,g:Z}};let{dd:G,g:j}=q(!1);const x=R=>R.through.length>0||R.outside.length>0||(R.overlaps?.length??0)>0||(R.misfit?.length??0)>0||u;if(!x(j)&&j.unseated.length&&j.unseated.every(R=>j.bounded?.includes(R))){const R=q(!0);!x(R.g)&&!R.g.unseated.length&&({dd:G,g:j}=R)}if(!x(j)&&!j.unseated.length)return j.crossings.length&&a?.(`${j.crossings.length} crossing${j.crossings.length===1?"":"s"} in the drawn layout: ${j.crossings.map(R=>`${Dt(e,j.lines[R.top])} over ${Dt(e,j.lines[R.under])}`).join("; ")}`),{dyn:G,geo:j,ink:Pe(n,j,m,o),tokens:m,least:i.least};u&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: a decision would be taller than it is wide`),j.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: ${j.misfit.join("; ")}`),j.through.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: ${w(j,j.through)} would pass through a node`),j.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: ${w(j,j.overlaps)} would lie on one another`),j.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: ${w(j,j.outside)} would leave the drawing`),j.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(h)}px: no clean seat for ${j.unseated.map(R=>e.type==="sequence"?`message ${R}`:`"${It(e.edges[R]?.label??"")}"`).join(", ")}`)}let S=p({...c,...z,layout:"stacked",heights:void 0,grow:Lt(),track:e.type==="schema"?i.table:void 0,bare:void 0,pad:void 0,rows:void 0});if(S=M(S),s(S),e.type==="sequence"||e.type==="schema")return{dyn:S,geo:null,ink:"",tokens:m,least:i.least};const B=Le(e);let Y=Ue(C(),f,B,S.grow);for(let q=0;q<6&&Object.keys(Y.grow).length;q++){const G=Lt(S.grow);for(const[j,x]of Object.entries(Y.grow))G[j]=(Ot(G,j)??0)+x;S={...S,grow:G},s(S),Y=Ue(C(),f,B,G)}const F=Y.geo;if(!B.third&&B.laneCount>2&&a?.(`the stacked drawing uses ${B.laneCount} end lanes (four at most)`),F.unseated.length>0||F.through.length>0||F.outside.length>0||B.third){F.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(F.unseated)].map(j=>`"${It(e.edges[j]?.label??"")}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),F.through.length&&a?.(`in the stacked drawing ${w(F,F.through)} would pass through a node, so its lines are not drawn`),F.outside.length&&a?.(`in the stacked drawing ${w(F,F.outside)} would leave the drawing, so its lines are not drawn`),B.third&&a?.("the stacked drawing would need a fifth end lane, so its lines are not drawn");const q={...F,lines:[],labels:[],crossings:[]};return{dyn:p({...S,grow:Lt(),bare:!0,open:c.bare?c.open:!0,autoOpen:c.bare?c.autoOpen:c.open?void 0:!0}),geo:q,ink:"",tokens:m,least:i.least}}return F.crossings.length&&a?.(`${F.crossings.length} crossing${F.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${F.crossings.map(q=>`${Dt(e,F.lines[q.top])} over ${Dt(e,F.lines[q.under])}`).join("; ")}`),{dyn:S,geo:F,ink:Pe(n,F,m,o),tokens:m,least:i.least}}function Dt(t,e){const n=t.byId.get(e.from)?.name??e.from,o=t.byId.get(e.to)?.name??e.to;return`${n} to ${o}`}function Jn(t,e,n,o,c,s){const a=new Set;if(s){a.add(s);for(const p of n?.lines??[])p.from===s&&a.add(p.to),p.to===s&&a.add(p.from)}if(t.toggleAttribute("data-tracing",!!s),t.querySelectorAll(`.${e}-node`).forEach(p=>p.toggleAttribute("data-near",a.has(p.dataset.node))),!n||!o)return;const l=p=>!!s&&(p.from===s||p.to===s),r=t.querySelector(`.${e}-edges`),d=new Map;t.querySelectorAll(`.${e}-edge`).forEach(p=>d.set(p.getAttribute("data-edge"),p));for(const p of n.lines){const u=d.get(String(p.i));u&&(u.toggleAttribute("data-lit",l(p)),u.toggleAttribute("data-dim",!!s&&!l(p)))}if(t.querySelectorAll(`.${e}-label`).forEach(p=>{const u=n.lines.find(M=>String(M.i)===p.dataset.edge);p.toggleAttribute("data-lit",!!(u&&l(u)))}),r){for(const p of n.lines)if(l(p)){const u=d.get(String(p.i));u&&r.appendChild(u)}}const m=Qt(n.lines,l),{defs:f,ids:i}=Qe(e,{...n,crossings:m},o,c),h=t.querySelector(`.${e}-svg`);if(!h)return;let $=h.querySelector("defs");!$&&f&&($=document.createElementNS("http://www.w3.org/2000/svg","defs"),h.insertBefore($,h.firstChild)),$&&($.innerHTML=f),n.lines.forEach((p,u)=>{const M=d.get(String(p.i))?.querySelector(`.${e}-line`);if(!M)return;const C=i.get(u);C?M.setAttribute("mask",`url(#${C})`):M.removeAttribute("mask")})}var Xn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Un(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Xn()||Qn(t)?"done":"pending")}}var Yn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Qn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Yn(t))!==null}catch{return!1}}function tn(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Pn(t,e,n,o=!1,c=!1){const s=o?Zt(t):null;if(s&&n.startsWith("Arrow")){const d={ArrowRight:c?"left":"right",ArrowLeft:c?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return d?s[e]?.[d]??null:null}const a=t.byId.get(e)?.i??0,l=t.nodes.length;let r;if(n==="ArrowRight"||n==="ArrowDown")r=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")r=a-1;else if(n==="Home")r=0;else if(n==="End")r=l-1;else return null;return t.nodes[Math.max(0,Math.min(l-1,r))].id}var to=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],en=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl","data-cols","data-reach","data-gutter","data-marks"],eo=["--_track","--_h","--_ww","--_gap","--_ggrow","--_gpad","--_gw","--_mh","--_rows","--_row-gap"],nn=t=>t==null||t===!1;function no(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function Pt(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const o=n?en:to;for(const a of o)nn(e.a[a])&&t.removeAttribute(a);for(const[a,l]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const d=t.style,m=new Map(String(l??"").split(";").map(f=>{const i=f.indexOf(":");return[f.slice(0,i).trim(),f.slice(i+1).trim()]}).filter(([f])=>f));for(const[f,i]of m)d.getPropertyValue(f).trim()!==i&&d.setProperty(f,i);for(const f of eo)m.has(f)||d.removeProperty(f);continue}if(n&&!en.includes(a))continue;if(nn(l)){t.removeAttribute(a);continue}const r=l===!0?"":String(l);t.getAttribute(a)!==r&&t.setAttribute(a,r)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const c=[...t.children];let s=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let l=s;lt.querySelector(`.${e}-node[data-node="${CSS.escape(s)}"]`);n&&c(n)?.setAttribute("tabindex","-1"),c(o)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",o=0;function c(i,h,$){return{prefix:n,base:i,hasSource:h.source!==void 0&&h.source!==null&&h.source!=="",hiddenClass:"visually-hidden",viewer:$?$.keys:void 0}}function s(i,h,$,p){var u=function(M){return''+$t(M)+""};return{source:$t(String(h.source||"")),summary:$t(String(h.summary||"")),hint:re(i).map(function(M){return""+M.keys.map(u).join(" ")+" "+$t(M.words)+""}).join(""),toggle:'"}}function a(i,h,$){for(var p=i.layout==="auto"&&(i.type==="architecture"||i.type==="flowchart"||i.type==="schema"),u=p?Array.isArray(i.placement)?i.placement:i.placement?[i.placement]:[]:[],M=i.direction||(i.type==="flowchart"?"down":"right"),C=null,z=0;z");return{open:B.slice(0,Y+1),inner:B.slice(Y+1,B.length-9),warnings:w.warnings}}var l=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-marks","data-layout","data-measured","data-bare"],r=["--_cols","--_gpad","--_track"];function d(i,h,$,p){i.__diagram&&i.__diagram.stop();var u=(i.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),M=getComputedStyle(i).direction==="rtl",C=h.layout==="auto"&&(h.type==="architecture"||h.type==="flowchart"||h.type==="schema"),z=C?Array.isArray(h.placement)?h.placement:h.placement?[h.placement]:[]:[];C&&!z.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var w=h.direction?[h.direction]:h.type==="flowchart"?["down","right"]:["right","down"],S=function(W){for(var V=0;V .diagram-drawing")){if(!u||!i.querySelector("#"+CSS.escape(u+"-title"))){for(;document.getElementById("dg"+ ++o+"-title"););u="dg"+o}var Y=a(h,u,p),F=document.createElement("div");F.innerHTML=Y.open+"";var it=F.firstChild;l.forEach(function(W){i.removeAttribute(W)}),r.forEach(function(W){i.style.removeProperty(W)});for(var q=0;q :not(script[data-diagram])").forEach(function(W){W.remove()}),i.insertAdjacentHTML("beforeend",Y.inner)}B.warnings.forEach(function(W){console.warn("Basalt diagram: "+W)}),B.motion.animated&&B.motion.firstVisit&&!i.id&&console.warn('Basalt diagram: "entrance": "first-visit" needs an id on the figure: without one the entrance plays on every visit');var j=c(u,h,p),x={},R=null,D=null,Z=null,K=null,at=Object.create(null),nt=function(W){at[W]||(at[W]=1,console.warn("Basalt diagram: "+W))},J=function(W){Pt(i,Xt(B,W,j))},g=i.querySelector(".diagram-ink"),y=i.querySelector(".diagram-toggle"),E=!p&&B.motion.animated&&typeof e.diagramMotion=="function",A=null,L=null,T=function(){E&&tn(i)};function U(){Jn(i,n,R&&R.geo,R&&R.tokens,u,D||K||Z),P()}var N=null,ht=!p&&matchMedia("(hover: none), (pointer: coarse)").matches;function P(){var W=ht&&!p&&g&&g.innerHTML!=="";if(i.toggleAttribute("data-touch",!!(ht&&!p)),W&&!N){var V=i.querySelector(":scope > .diagram-foot");if(!V)return;N=document.createElement("button"),N.type="button",N.className="btn diagram-clear",N.setAttribute("data-variant","secondary"),N.setAttribute("data-size","sm"),N.innerHTML="Clear highlight",N.addEventListener("click",function(){K&&(K=null,U())}),V.appendChild(N)}else!W&&N&&(N.remove(),N=null);N&&N!==N.parentNode.lastElementChild&&document.activeElement!==N&&N.parentNode.appendChild(N),N&&(K?N.removeAttribute("aria-disabled"):N.setAttribute("aria-disabled","true"))}function lt(W){if(!W.defaultPrevented){var V=yn(i,n,W,K);V!==void 0&&(T(),ht=!0,K=V,U())}}function dt(){y&&(y.setAttribute("aria-expanded",String(!!x.open)),y.firstElementChild.textContent=x.open?"Hide the list":"View as list")}function mt(){if(C&&z.length>1&&!p){for(var W=null,V=[],Q=!1,et=0;et1&&p&&!h.direction&&p.room){for(var te=p.room(),Gt=-1,pe=null,ge=0;geGt+1e-6&&(Gt=an,pe=me)}}}pe&&(B=pe)}R=(p?p.measure:he)(i,B,n,u,x,J,nt),x=R.dyn,J(x),dt();var ye=i.querySelector(":scope > .diagram-hint");if(ye){var sn=re(B,x.layout==="drawn").map(function(At){return""+At.keys.map(function(ro){return''+$t(ro)+""}).join(" ")+" "+$t(At.words)+""}).join("");ye.innerHTML!==sn&&(ye.innerHTML=sn)}Rt(B,x)||(Z=K=null);var rn=g&&R.ink!==L;rn&&(g.innerHTML=R.ink,L=R.ink),U();var so=B.text?i.querySelector(".diagram-text[data-art]"):null;B.text&&typeof e.diagramText=="function"&&e.diagramText(i,B,h,p);var ln=B.text?i.querySelector(".diagram-text[data-art]"):null;E&&R.tokens&&(Un(i,!!(R.geo&&R.geo.lines.length)||!!ln),(rn||ln!==so)&&A&&A.redrawn()),p&&p.onMeasured&&R.tokens&&p.onMeasured(R,i)}function wt(W){x=W,J(x)}function kt(W){var V=x.stop;x=Object.assign({},x,{stop:W}),oo(i,n,V,W)}var vt=function(W){var V=W&&W.closest?W.closest(".diagram-node"):null;return V&&i.contains(V)?V:null};function pt(W){var V=vt(W.target);if(!(!V||W.defaultPrevented)){if(T(),W.key==="Escape"){!p&&(D||Z||K)&&(W.preventDefault(),D=Z=K=null,U());return}if(Rt(B,x)){var Q=Pn(B,V.getAttribute("data-node"),W.key,x.layout==="drawn");if(Q){W.preventDefault(),kt(Q);var et=i.querySelector('.diagram-node[data-node="'+CSS.escape(Q)+'"]');et&&et.focus()}}}}function ut(W){var V=vt(W.target);if(V){T();var Q=V.getAttribute("data-node");D=V.matches(":focus-visible")?Q:null,Rt(B,x)&&x.stop!==Q&&kt(Q),U()}}function ct(W){var V=vt(W.target);V&&(vt(W.relatedTarget)||(D=null),x.keep===V.getAttribute("data-node")&&wt(Object.assign({},x,{keep:void 0})),U())}function bt(W){if(!(W.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var V=vt(W.target);V&&T();var Q=V&&Rt(B,x)?V.getAttribute("data-node"):null;Q!==Z&&(Z=Q,U())}}function b(){Z&&(Z=null,U())}function I(){T(),wt(Object.assign({},x,{open:!x.open,autoOpen:void 0})),dt()}i.addEventListener("keydown",pt),i.addEventListener("focusin",ut),i.addEventListener("focusout",ct),i.addEventListener("pointerover",bt),i.addEventListener("pointerleave",b),i.addEventListener("click",lt),y&&y.addEventListener("click",I),mt();var _=i.clientWidth,k=0,O=!0,H=new ResizeObserver(function(){Math.abs(i.clientWidth-_)<.5||(_=i.clientWidth,cancelAnimationFrame(k),k=requestAnimationFrame(mt))});H.observe(i),document.fonts&&document.fonts.ready.then(function(){O&&mt()});var X=matchMedia("(forced-colors: active)"),tt=B.nodes.some(function(W){return W.mark});tt&&X.addEventListener("change",mt),E&&(A=e.diagramMotion(i,{fig:i,P:n,base:u,model:function(){return B},geo:function(){return R&&R.geo},tokens:function(){return R&&R.tokens}},h));var rt=!p&&h.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(i,h,{model:B,settle:T,animated:E}):null,st=i.querySelector(":scope > .diagram-foot"),ot=!p&&h.export===!0&&st&&typeof e.diagramExport=="function"?e.diagramExport(st,i):[];i.__diagram={stop:function(){rt&&rt.destroy(),ot.forEach(function(W){W.remove()}),O=!1,H.disconnect(),cancelAnimationFrame(k),tt&&X.removeEventListener("change",mt),A&&A.destroy(),i.removeEventListener("keydown",pt),i.removeEventListener("focusin",ut),i.removeEventListener("focusout",ct),i.removeEventListener("pointerover",bt),i.removeEventListener("pointerleave",b),i.removeEventListener("click",lt),N&&N.remove(),y&&y.removeEventListener("click",I)},layout:mt,key:m(h),send:A&&A.sendValue?A.sendValue:null}}function m(i){try{return JSON.stringify(i,function(h,$){return h==="packet"&&$&&typeof $=="object"?Object.assign({},$,{send:void 0}):$})}catch{return null}}function f(){document.querySelectorAll("figure.diagram").forEach(function(i){if(!i.__diagram){var h=i.querySelector(":scope > script[data-diagram]");if(h)try{d(i,JSON.parse(h.textContent),!0)}catch($){console.error("Basalt diagram: this figure could not be drawn",$)}}})}e.diagramMarkup=a,e.diagramKit={draw:d,buildModel:Nt,figureKey:Mn,figureList:On,hintEntries:re,toHtml:oe,escapeHtml:$t,settleEntrance:tn,measureFigure:he},t.diagram=function(i,h){var $=i.__diagram,p=$&&$.send?m(h):null;if(p!==null&&p===$.key){$.send(h.packet?h.packet.send:void 0);return}d(i,h)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); +(()=>{var cn=["top","right","bottom","left"],dn=["main","plain","dashed"],$e=["one","zero-or-one","one-or-many","zero-or-many"],Ft={one:"Exactly one","zero-or-one":"Zero or one","one-or-many":"One or many","zero-or-many":"Zero or many"},fn=[2,3,4,5,6],gt=t=>t==null||t===""?void 0:String(t),Lt=t=>Object.assign(Object.create(null),t),Ot=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Nt(t,e={}){const o=e.checks!==!1,c=[],l=m=>{c.push(m)},a=[],s=m=>{a.push(m)},r=t.legend??{},d={};for(const m of["main","plain","dashed","focal","group","activation"]){const $=gt(r[m]);$&&(d[m]=$)}const p=t.stepLabel,f=typeof p=="function"?m=>String(p(m)):typeof p=="string"?(m=>p.replace("{n}",String(m))):m=>`Step ${m}`,i=t.shapeLabels??{},u={terminal:gt(i.terminal)??"Start or end",step:gt(i.step)??"Step",decision:gt(i.decision)??"Decision"},b=t.heading===void 0?3:fn.includes(t.heading)?t.heading:(l(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),h=(m,$)=>m==null?"plain":dn.includes(m)?m:(l(`"${String(m)}" is not a kind of line (main, plain or dashed): ${$} is drawn plain`),"plain"),g=m=>{if(m!=null){if(cn.includes(m))return m;l(`"${String(m)}" is not a side (top, right, bottom or left): the derived side is used`)}},k=(m,$)=>typeof m=="number"&&Number.isInteger(m)&&m>=1?m:(t.layout==="auto"&&m==null||l(`${$} is ${JSON.stringify(m)}, not a whole number from 1: it is placed at 1`),1),M=[],z=[];let w=[];const q=[],O=[],N=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(N)||l(`"${String(N)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),N==="architecture"||N==="flowchart"){for(const m of t.nodes??[]){const $=N==="flowchart"&&m.shape==="decision"?"decision":N==="flowchart"&&m.shape==="terminal"?"terminal":"box",S=String(m.id??""),B=k(m.row,`the row of ${S}`);M.push({id:S,i:M.length,name:String(m.name??""),kind:$==="decision"?void 0:gt(m.kind),detail:$==="decision"?void 0:gt(m.detail),mono:!!m.detailMono,focal:!!m.focal,col:k(m.col,`the column of ${S}`),row:B,row2:B,branch:!!m.branch,shape:$,group:N==="architecture"?gt(m.group):void 0,mark:N==="architecture"?ne(m.mark):void 0})}if(N==="architecture"){const m=(t.groups??[]).map(I=>({id:String(I.id??""),label:String(I.label??""),parent:gt(I.parent)})),$=new Map(m.map(I=>[I.id,I])),S=I=>{if(!I.parent)return 1;const j=$.get(I.parent);return j?j.parent===I.id||j.id===I.id?(s(`the groups "${I.label}" and "${j.label}" are each other's parent`),I.parent=void 0,1):j.parent?(s(`the group "${I.label}" is a third level: groups nest two deep`),I.parent=void 0,1):2:(s(`the group "${I.label}" names the parent "${I.parent}", which is not a group`),I.parent=void 0,1)},B=m.map(S);m.forEach((I,j)=>q.push({...I,depth:B[j],members:M.filter(tt=>tt.group===I.id).map(tt=>tt.id),all:[]}));for(const I of q)I.all=[...I.members,...q.filter(j=>j.parent===I.id).flatMap(j=>j.members)];q.sort((I,j)=>I.depth-j.depth)}}else if(N==="data-flow"){w=(t.lanes??[]).map($=>({id:String($.id??""),label:String($.label??"")}));const m=new Map(w.map(($,S)=>[$.id,S+1]));for(const $ of t.nodes??[]){const S=String($.id??""),B=String($.lane??""),I=m.get(B);I===void 0&&l(`a node (${S}) names the lane "${B}", which is not in lanes`);const j=M.length+1;M.push({id:S,i:M.length,name:String($.name??""),kind:f(j),detail:gt($.detail),mono:!!$.detailMono,focal:!!$.focal,col:k($.col,`the column of ${S}`),row:I??1,row2:I??1,branch:!1,shape:"box",lane:I??1,laneLabel:w[(I??1)-1]?.label??B,step:j,mark:ne($.mark)})}}else if(N==="sequence"){(t.participants??[]).forEach((B,I)=>{const j=String(B.name??"");M.push({id:String(B.id??""),i:I,name:j,kind:gt(B.kind),mono:!1,focal:!!B.focal,col:I+1,row:1,row2:1,branch:!1,shape:"participant",short:gt(B.short)??j,mark:ne(B.mark)})});let m=0;const $=new Map(M.map(B=>[B.id,B.col])),S=(B,I)=>{let j=1/0,tt=-1/0;for(const Y of B??[]){if(!Y||typeof Y!="object")continue;if("band"in Y){I>0&&s(`the band "${String(Y.band)}" is inside a frame: a band is the whole figure's`),O.push({band:String(Y.band??"")});continue}if("frame"in Y){if(I>=2){s("a frame is a third level: frames nest two deep");continue}const vt=Y.frame==="alt"||Y.frame==="loop"||Y.frame==="opt"?Y.frame:"opt",St=vt==="alt"?Y.branches??[]:[{label:Y.label,steps:Y.steps}];vt==="alt"&&St.length<2&&s("an alt frame has one branch: it needs two or more");const pt=String(St[0]?.label??"");pt.length>40&&s(`the frame label "${pt}" is over 40 characters`);const ut=O.length;O.push({open:vt,label:pt,depth:I+1,a:0,b:0}),St.forEach((y,A)=>{if(A){const H=String(y.label??"");H.length>40&&s(`the frame label "${H}" is over 40 characters`),O.push({otherwise:H,depth:I+1})}y.steps?.length||s(`a frame or branch ("${String(y.label??"")}") is empty`);const[_,x]=S(y.steps??[],I+1);j=Math.min(j,_),tt=Math.max(tt,x);const L=O[ut];L.a=Math.min(L.a||1/0,_),L.b=Math.max(L.b,x)}),O.push({close:I+1});continue}m++;const mt=String(Y.label??"");mt.includes(` +`)&&s(`message ${m}'s label has a break: a message's second line is its note`);const nt=String(Y.from??""),lt=String(Y.to??"");O.push({n:m,from:nt,to:lt,label:_t(mt),note:gt(Y.note),kind:h(Y.kind,`message ${m}`),activate:Y.activate===!0||void 0,deactivate:Y.deactivate===!0||void 0});const ft=$.get(nt)??1,yt=$.get(lt)??1,wt=ft===yt?ft===M.length?ft-1:ft+1:ft;j=Math.min(j,ft,yt,wt),tt=Math.max(tt,ft,yt,wt)}return[j,tt]};S(t.steps??[],0);for(const B of O)"open"in B&&!Number.isFinite(B.a)&&(B.a=1,B.b=Math.max(1,M.length))}else if(N==="schema")for(const m of t.tables??[]){const $=String(m.name??""),[S,B]=Array.isArray(m.row)?m.row:[m.row,m.row],I=k(S,`the row of ${$}`),j=Math.max(I,k(B,`the last row of ${$}`)),tt=m.more===void 0||m.more===null?void 0:Number.isInteger(m.more)&&m.more>0?m.more:(l(`${$}'s "more" is ${JSON.stringify(m.more)}, not a whole number from 1: it is left out`),void 0);M.push({id:$,i:M.length,name:$,mono:!0,focal:!!m.focal,col:k(m.col,`the column of ${$}`),row:I,row2:j,branch:!1,shape:"table",more:tt,columns:(m.columns??[]).map(Y=>({name:String(Y.name??""),type:gt(Y.type),key:Y.key==="PK"||Y.key==="FK"?Y.key:(Y.key!==void 0&&Y.key!==null&&l(`${$}.${String(Y.name)}'s key is "${String(Y.key)}", not PK or FK: it is left out`),void 0)}))})}let D=!1;if(t.layout==="auto"&&(N==="architecture"||N==="flowchart"||N==="schema")){const m=N==="schema"?t.tables:t.nodes;o&&(m??[]).some(S=>S&&(S.col!==void 0||S.row!==void 0))&&l('a card under layout="auto" has a col or row, which is not read: there are no hints');const $=e.placement?.cells;$||(D=!0);for(const S of M){const B=$?.[S.id];S.col=B?.col??1,S.row=S.row2=B?.row??1}if($){const S=new Map;for(const B of M){const I=Ot($,B.id);if(!I){D=!0,l(`the placement has no cell for ${B.id}, so it is not used`);continue}const j=`${I.col},${I.row}`;S.has(j)&&(D=!0,l(`the placement puts ${S.get(j)} and ${B.id} in one cell, so it is not used`)),S.set(j,B.id)}}if($&&!D)for(const S of q){const B=S.all.map(nt=>M.find(lt=>lt.id===nt)).filter(Boolean);if(!B.length)continue;const I=Math.min(...B.map(nt=>nt.col)),j=Math.max(...B.map(nt=>nt.col)),tt=Math.min(...B.map(nt=>nt.row)),Y=Math.max(...B.map(nt=>nt.row)),mt=M.filter(nt=>!S.all.includes(nt.id)&&nt.col>=I&&nt.col<=j&&nt.row>=tt&&nt.row<=Y);mt.length&&(D=!0,l(`the placement puts ${mt.map(nt=>nt.id).join(", ")} inside the box of the group "${S.label}", so it is not used`))}}else t.layout==="auto"&&s(`layout="auto" is for an architecture, a flowchart or a schema, not a ${N}`);((N==="schema"?t.tables:N==="sequence"?t.participants:t.nodes)??[]).forEach((m,$)=>{if(!m||m.href===void 0||m.href===null)return;const S=String(m.href);if(N==="sequence"){s(`${M[$]?.id}: a participant cannot be a link (href)`);return}if(!S.trim()){s(`${M[$]?.id}'s href is empty`);return}const B=M[$];B&&(B.href=S,B.blank=m.target==="_blank")});const E=new Map;for(const m of M)m.id?E.has(m.id)&&l(`the id "${m.id}" is used twice`):l("a node has no id"),E.set(m.id,m);if(N==="schema"){const m=(S,B)=>{if(S==null)return;const I=S,j=$e.includes(I.from)?I.from:void 0;if(!j){s(`${B}'s cardinality "from" is ${JSON.stringify(I.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`);return}return I.to===void 0||I.to===null?{from:j,to:"one"}:I.to==="one"||I.to==="zero-or-one"?{from:j,to:I.to}:(s(`${B}'s cardinality "to" is ${JSON.stringify(I.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`),{from:j,to:"one"})};(t.tables??[]).forEach(S=>(S.columns??[]).forEach((B,I)=>{const j=gt(B.references);if(!j&&B.cardinality!==void 0&&B.cardinality!==null&&s(`${String(S.name)}.${String(B.name)} states a cardinality but references nothing`),!j)return;const[tt,Y]=j.split("."),mt=E.get(tt??""),nt=mt?.columns?.findIndex(yt=>yt.name===Y)??-1;if(!mt||nt<0){l(`${String(S.name)}.${String(B.name)} references ${j}, which is not a shown column`);return}const lt=E.get(String(S.name??""));lt.columns[I].ref={table:tt,column:Y,row:nt};const ft=m(B.cardinality,`${String(S.name)}.${String(B.name)}`);ft&&(lt.columns[I].card=ft),z.push({i:z.length,from:lt.id,to:tt,kind:"plain",fromRow:I,toRow:nt,fk:!0,card:ft})}));const $=z.filter(S=>S.card).length;$&&$!S.card).map(S=>`${S.from}.${E.get(S.from).columns[S.fromRow].name}`).join(", ")} ${z.length-$===1?"has":"have"} none)`)}else if(N!=="sequence")for(const m of t.edges??[]){const $=String(m.from??""),S=String(m.to??"");if(!E.has($)||!E.has(S)){l(`a line names ${E.has($)?S:$}, which is not a node`);continue}const B=gt(m.label),I=B?.split(` +`)??[];I.length>2&&s(`the label "${_t(B)}" has more than one break: a label is two lines at most`),I.some(j=>j.length>we)&&s(`a line of the label "${_t(B)}" is over ${we} characters: longer words belong in the node or the summary`),z.push({i:z.length,from:$,to:S,kind:h(m.kind,`the line from ${$} to ${S}`),label:B,fromSide:g(m.fromSide),toSide:g(m.toSide),flow:N!=="flowchart"&&m.flow===!0?!0:void 0})}else for(const m of O)"n"in m&&(!E.has(m.from)||!E.has(m.to))&&l(`message ${m.n} names ${E.has(m.from)?m.to:m.from}, which is not a participant`);if(o&&N!=="sequence"&&!D){const m=new Map;for(const $ of M)for(let S=$.row;S<=$.row2;S++){const B=`${$.col}:${S}`;m.has(B)&&l(`${$.id} and ${m.get(B)} share the cell at column ${$.col}, row ${S}`),m.set(B,$.id)}}if(o&&!D){for(const $ of q){const S=$.all.map(j=>E.get(j));if(!S.length)continue;const B={c1:Math.min(...S.map(j=>j.col)),c2:Math.max(...S.map(j=>j.col)),r1:Math.min(...S.map(j=>j.row)),r2:Math.max(...S.map(j=>j.row2))};for(const j of M)!$.all.includes(j.id)&&j.col>=B.c1&&j.col<=B.c2&&j.row>=B.r1&&j.row<=B.r2&&l(`${j.id} is inside the box of the group "${$.label}" but not a member`);const I=S.map(j=>j.i);Math.max(...I)-Math.min(...I)+1!==I.length&&l(`the members of the group "${$.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const $ of M)$.group&&!q.some(S=>S.id===$.group)&&l(`${$.id} names the group "${$.group}", which is not in groups`);M.filter($=>$.focal).length>1&&l("more than one node is focal: a diagram has one at most");const m=new Set(N==="sequence"?O.flatMap($=>"n"in $?[$.kind]:[]):z.map($=>$.kind));m.has("main")&&!d.main&&l("main lines are drawn but the legend has no words for them (legend.main)"),m.has("dashed")&&!d.dashed&&l("dashed lines are drawn but the legend has no words for them (legend.dashed)"),M.some($=>$.focal)&&!d.focal&&l("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const G=N==="architecture"||N==="data-flow",R=m=>Array.isArray(m)&&m.length>1?m.map(String):void 0,C=G&&t.packet&&typeof t.packet=="object"?t.packet:void 0,W=C&&R(C.path),T={animated:t.motion==="animated",pulse:G?R(t.pulse):void 0,packet:W?{path:W,repeat:C.repeat===!0,send:C.send}:void 0,run:N==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(o)for(const m of M){const $=m.mark?.says;if(!$?.length)continue;const S=[m.name,m.kind,m.detail,m.laneLabel].filter(Boolean).join(" ").toLowerCase();$.some(B=>S.includes(B.toLowerCase()))||l(`${m.id}'s mark stands for ${$.join(" or ")}, and none of its words say so`)}const K=[];if(N==="sequence"){const m=new Map,$=new Map;for(const S of O)"n"in S&&($.set(S.from,S.n),$.set(S.to,S.n));for(const S of O)if("n"in S){if(S.activate){const B=m.get(S.to)??[];if(B.length>=3)s(`message ${S.n} opens a fourth bar on ${S.to}: three deep at most`);else{const I={who:S.to,from:S.n,to:S.n,depth:B.length+1};B.push(I),K.push(I),m.set(S.to,B)}}if(S.deactivate){const I=m.get(S.from)?.pop();I?I.to=S.n:s(`message ${S.n} closes a bar on ${S.from}, which has none open`)}}for(const[S,B]of m)for(const I of B)I.to=Math.max(I.from,$.get(S)??I.from)}const X=t.frameLabels??{},st={opt:gt(X.opt)??"Only if",loop:gt(X.loop)??"Repeats",alt:gt(X.alt)??"One of these",else:gt(X.else)??"Otherwise"},U=t.layout==="auto"&&!D?e.placement:void 0;let J=Math.max(1,U?.cols??1,...M.map(m=>m.col));if(e.rtl){for(const $ of M)$.col=J-$.col+1;const m=$=>$==="left"?"right":$==="right"?"left":$;for(const $ of z)$.fromSide=m($.fromSide),$.toSide=m($.toSide);for(const $ of O)if("open"in $){const[S,B]=[J-$.b+1,J-$.a+1];$.a=S,$.b=B}J=Math.max(1,U?.cols??1,...M.map($=>$.col))}const Z=N==="data-flow"?Math.max(1,w.length):Math.max(1,U?.rows??1,...M.map(m=>m.row2)),Q={type:N,title:String(t.title??""),heading:b,legend:d,nodes:M,byId:E,edges:z,groups:q,lanes:w,steps:O,bars:K,frameWords:st,cols:J,rows:Z,shapeLabels:u,stepWord:f,warnings:c,errors:a,motion:T,memo:new Map,rtl:e.rtl||void 0,unplaced:D||void 0,text:N==="sequence"&&t.variant==="text"||void 0,marks:z.some(m=>m.card)||void 0};if(t.layout==="auto"&&!D&&N!=="schema"&&un(Q),o)for(const[m,$]of Object.entries(We(Q)))$>=48&&l(`${m} grows to ${$}px to hold the lines on one side: use another side`);return o&&M.length>100&&l(`the figure has ${M.length} cards: more than 100, which automatic layout places on the main thread`),o&&M.length>1&&!D&&!Jt(Q)&&l("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),Q}function un(t){const e=new Set(t.nodes.map(s=>`${s.col},${s.row}`)),n=(s,r)=>{const d=[];for(let p=Math.min(s,r)+1;p{const r=t.byId.get(s.from),d=t.byId.get(s.to),p=d.col>r.col?"right":"left",f=d.row>r.row?"bottom":"top",i=d.col>r.col?"left":"right",u=d.row>r.row?"top":"bottom",b=(k,M,z,w)=>n(k,M).map(q=>w?[q,z]:[z,q]);let h;const g=k=>(k==="right"?r.col1:k==="bottom"?r.row1)?[{sides:[k,k],cells:[]}]:[];return r.row===d.row?h=[{sides:[p,i],cells:b(r.col,d.col,r.row,!0)},...g("bottom"),...g("top")]:r.col===d.col?h=[{sides:[f,u],cells:b(r.row,d.row,r.col,!1)},...g("right"),...g("left")]:h=[{sides:[p,u],cells:[...b(r.col,d.col,r.row,!0),[d.col,r.row],...b(r.row,d.row,d.col,!1)]},{sides:[f,i],cells:[...b(r.row,d.row,r.col,!1),[r.col,d.row],...b(r.col,d.col,d.row,!0)]},{sides:[p,i],cells:b(r.col,d.col,r.row,!0)},{sides:[f,u],cells:b(r.row,d.row,r.col,!1)}],h.filter(k=>k.cells.every(([M,z])=>!e.has(`${M},${z}`)))},c=new Map,l=new Set;for(const s of t.edges)if(s.fromSide||s.toSide){const[r,d]=de(t.byId.get(s.from),t.byId.get(s.to)),p=s.fromSide??r,f=s.toSide??d;l.add(`${s.from}.${p}`);for(const[i,u]of[[s.from,p],[s.to,f]])c.set(`${i}.${u}`,(c.get(`${i}.${u}`)??0)+1)}const a=t.edges.map((s,r)=>r).sort((s,r)=>o(t.edges[s]).length-o(t.edges[r]).length||+(t.edges[r].kind==="main")-+(t.edges[s].kind==="main")||s-r);for(const s of a){const r=t.edges[s];if(r.fromSide||r.toSide)continue;const d=(f,i,u)=>{const b=`${f}.${i}`;return(c.get(b)??0)>=3?!1:t.byId.get(f).shape!=="decision"?!0:u?!c.has(b):!l.has(b)},p=o(r).find(f=>d(r.from,f.sides[0],!0)&&d(r.to,f.sides[1],!1));if(p){l.add(`${r.from}.${p.sides[0]}`);for(const[f,i]of[[r.from,p.sides[0]],[r.to,p.sides[1]]])c.set(`${f}.${i}`,(c.get(`${f}.${i}`)??0)+1);r.fromSide=p.sides[0],r.toSide=p.sides[1]}}}function ne(t){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const e=t,n=gt(e.onLight);if(n)return{onLight:n,onDark:gt(e.onDark)??n,says:Array.isArray(e.says)?e.says.map(String):void 0}}var be=t=>`url("${t.replace(/[\\"\n;]/g,e=>e===` +`?"\\a ":e===";"?"\\3b ":`\\${e}`)}")`;function jt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var we=28,Vt=t=>t.includes(` +`)?2:1,_t=t=>t.replace(/\n/g," "),Wt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function ve(t,e){return t.legend[e]}function hn(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function pn(t,e){return jt(t,`sentence:${e.i}`,()=>gn(t,e))}function gn(t,e){const n=[];if(t.type==="schema"){n.push(`${e.name}, table.`);const o=(e.columns??[]).filter(l=>l.ref).map(l=>`${l.ref.table} (${l.name}${l.card?`: ${xe(e.id,l.ref.table,l.card)}`:""})`),c=t.edges.filter(l=>l.to===e.id).map(l=>`${l.from} (${t.byId.get(l.from).columns[l.fromRow].name}${l.card?`: ${xe(l.from,l.to,l.card)}`:""})`);o.length&&n.push(`References ${o.join(", ")}.`),c.length&&n.push(`Referenced by ${c.join(", ")}.`)}else if(t.type==="sequence"){const o=t.steps.filter(a=>"n"in a&&a.from===e.id).length,c=t.steps.filter(a=>"n"in a&&a.to===e.id).length;n.push(Wt(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${o} ${o===1?"message":"messages"} and receives ${c}.`);const l=ke(t,e);l&&n.push(l.trim())}else{const o=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}`:t.type==="flowchart"?hn(t,e):e.kind;if(n.push(Wt(o?`${e.name}, ${o}`:e.name)),e.detail&&n.push(Wt(e.detail)),e.group){const a=t.groups.find(r=>r.id===e.group),s=a?.parent?t.groups.find(r=>r.id===a.parent):void 0;a&&n.push(s?`In ${a.label}, in ${s.label}.`:`In ${a.label}.`)}const c=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${_t(a.label)})`:""}`),l=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${_t(a.label)})`:""}`);c.length&&n.push(`From: ${c.join(", ")}.`),l.length&&n.push(`To: ${l.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(Wt(t.legend.focal)),n.join(" ")}var mn=(t,e,n,o)=>[`${Ft[n.from].toLowerCase()} `,o(t),` to ${Ft[n.to].toLowerCase()} `,o(e)],xe=(t,e,n)=>`${Ft[n.from].toLowerCase()} ${t} to ${Ft[n.to].toLowerCase()} ${e}`;function ke(t,e){const n=t.bars.filter(c=>c.who===e.id&&c.depth===1);return n.length?` ${t.legend.activation??"Working"} during ${n.map(c=>c.from===c.to?`message ${c.from}`:`messages ${c.from} to ${c.to}`).join(" and ")}.`:""}function yn(t,e,n,o){const c=n.pointerType;if(c!=="touch"&&c!=="pen")return;const l=t.querySelector(`.${e}-drawing`),a=n.target;if(!l||!a||!l.contains(a)||!t.querySelector(`.${e}-edge`))return;const s=a.closest(`.${e}-node`);if(!s?.hasAttribute("href"))return s?s.dataset.node===o?null:s.dataset.node??null:o===null?void 0:null}function Me(t){return t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function v(t,e,...n){const o=[];for(const c of n.flat(1/0))c!=null&&c!==!1&&!Array.isArray(c)&&o.push(c);return{t,a:e??{},c:o}}var $n={"&":"&","<":"<",">":">",'"':""","'":"'"},bt=t=>t.replace(/[&<>"']/g,e=>$n[e]),bn=" br img input meta link hr path polygon polyline circle rect line ";function oe(t,e={}){if(typeof t=="string")return bt(t);if("slot"in t)return e[t.slot]??"";if(!/^[a-z][a-z0-9]*$/.test(t.t))throw new Error(`diagram: "${t.t}" is not an element name`);let n="";for(const[o,c]of Object.entries(t.a))if(!(c==null||c===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(o))throw new Error(`diagram: "${o}" is not an attribute name`);n+=c===!0?` ${o}`:` ${o}="${bt(String(c))}"`}return bn.includes(` ${t.t} `)&&!t.c.length?t.t==="path"||t.t==="polygon"||t.t==="polyline"||t.t==="circle"||t.t==="rect"||t.t==="line"?`<${t.t}${n}/>`:`<${t.t}${n}>`:`<${t.t}${n}>${t.c.map(o=>oe(o,e)).join("")}`}var wn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function Rt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function vn(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Kt(t,e){const n=e.all.map(o=>t.byId.get(o));return n.length?{c1:Math.min(...n.map(o=>o.col)),c2:Math.max(...n.map(o=>o.col)),r1:Math.min(...n.map(o=>o.row)),r2:Math.max(...n.map(o=>o.row2))}:null}function Se(t){return jt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const o=Kt(t,n);if(!o)continue;[o.r1===1,o.c2===t.cols,o.r2===t.rows,o.c1===1].forEach((l,a)=>{l&&(e[a]=Math.max(e[a],Ee(t,n,a)))})}return e})}function Ee(t,e,n){const o=Kt(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const s=Kt(t,a);return s&&[s.r1===o.r1,s.c2===o.c2,s.r2===o.r2,s.c1===o.c1][n]})?2:1}function Ae(t){const e=Se(t);return e[1]+e[3]}function ae(t){return t.type==="sequence"?t.nodes.length:t.cols}function Le(t){return jt(t,"plan",()=>xn(t))}function xn(t){const e=t.nodes,n=g=>t.type==="data-flow"||!e[g].branch,o=t.edges.map(g=>{const k=t.byId.get(g.from).i,M=t.byId.get(g.to).i,w=e.slice(Math.min(k,M)+1,Math.max(k,M)).every(q=>!n(q.i));return M===k+1&&!(n(k)&&!n(M))?"down":M===k-1?"up":M>k&&n(k)&&!n(M)&&w?"trunk":M>k&&n(k)&&n(M)&&w?"rail":M>k?"end-down":"end-up"}),c=t.edges.map((g,k)=>({e:g,k})).filter(({k:g})=>o[g]==="end-down"||o[g]==="end-up"),l=g=>{const k=t.byId.get(g.from).i,M=t.byId.get(g.to).i;return[Math.min(k,M),Math.max(k,M)]},a=(g,k)=>{const[M,z]=l(g),[w,q]=l(k);return M{const k=t.byId.get(g.from).i,[M,z]=l(g);return!n(k)&&e.slice(M+1,z).every(w=>!n(w.i))&&c.every(w=>w.e===g||!a(w.e,g))}),r=c.length>0&&(t.type==="data-flow"||!s),d=g=>{const[k,M]=l(g);return M-k},p=t.edges.map(()=>0);let f=!1;const i=[];for(const g of[...c].sort((k,M)=>d(k.e)-d(M.e)||k.k-M.k)){let k=0;for(const M of i)a(M.e,g.e)&&(k=Math.max(k,p[M.k]+1));p[g.k]=k,k>3&&(f=!0),i.push(g)}const u=Math.max(0,...c.map(({k:g})=>p[g]+1)),b=t.edges.map(()=>.5);for(const g of e){const k=c.filter(({e:w})=>w.from===g.id);if(k.length<2)continue;const M=k.filter(({k:w})=>o[w]==="end-down").sort((w,q)=>d(q.e)-d(w.e)||w.k-q.k);[...k.filter(({k:w})=>o[w]==="end-up").sort((w,q)=>d(w.e)-d(q.e)||q.k-w.k),...M].forEach(({k:w},q,O)=>{b[w]=O.length===2?q===0?1/3:2/3:(q+1)/(O.length+1)})}const h=Lt();for(let g=1;g{const G=o[E],R=t.byId.get(dt.from).i,C=t.byId.get(dt.to).i,W=C===g&&(G==="down"||G==="trunk"||G==="rail"||G==="end-down"),T=R===g&&C===g-1&&G==="up",K=C===g-1&&G==="end-up";W&&(G==="trunk"||G==="end-down")&&(q=!0),K&&(O=!0),(W||T||K)&&dt.label&&(z++,w=Math.max(w,G==="trunk"?40:48))}),(z>1||q&&O)&&(w=64);const N=c.filter(({e:dt,k:E})=>o[E]==="end-down"&&t.byId.get(dt.to).i===g).length,D=c.filter(({e:dt,k:E})=>o[E]==="end-up"&&t.byId.get(dt.to).i===g-1).length;w+=20*Math.max(0,N-1)+20*Math.max(0,D-1),h[k.id]=w}return{routes:o,gutter:r,lanes:p,exits:b,gaps:h,third:f,laneCount:u}}var zt=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function _e(t,e){const n=e==="fk"?"plain":e,o=n==="main"?8:8.5,c=24,l=n==="dashed"?c-1:c-7;return v("svg",{class:`${t}-swatch`,"data-kind":n,...zt(24,16)},e==="fk"?v("circle",{class:`${t}-dot`,cx:3,cy:o,r:3}):null,v("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${o}H${l}`}),n==="dashed"?v("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${c-8} ${o-4}L${c} ${o}L${c-8} ${o+4}`}):v("path",{class:`${t}-tip`,"data-kind":n,d:`M${c} ${o}L${c-8} ${o-4}L${c-8} ${o+4}Z`}))}function kn(t,e){const{crow:n,ring:o}=Ie(e,24,8.5,-1);return v("svg",{class:`${t}-swatch`,"data-card":e,...zt(24,16)},v("path",{class:`${t}-line`,"data-kind":"plain",d:"M0 8.5H24"}),v("path",{class:`${t}-crow`,d:n}),o?v("circle",{class:`${t}-ring`,cx:o.x,cy:o.y,r:o.r}):null)}function Ie(t,e,n,o,c=8,l=6){const a=u=>String(Math.round(u*100)/100),s=u=>e+o*u,r=c/2,d=u=>`M${a(s(u-.5))} ${a(n-r)}V${a(n+r)}`,p=t==="one-or-many"||t==="zero-or-many",f=t==="zero-or-one"||t==="zero-or-many";let i=p?`M${a(e)} ${a(n-r)}L${a(s(7.5))} ${a(n)}L${a(e)} ${a(n+r)}`:d(4);return f||(i+=d(p?11:8)),{crow:i,ring:f?{x:Math.round(s(10.5)*100)/100,y:n,r:l/2}:void 0}}function Ht(t,e){return e==="decision"?v("svg",{class:`${t}-swatch`,"data-shape":e,...zt(16,16)},v("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?v("svg",{class:`${t}-swatch`,"data-shape":e,...zt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):v("svg",{class:`${t}-swatch`,"data-shape":e,...zt(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function qe(t,e){return jt(e,`key:${t}`,()=>Sn(t,e))}var Mn=qe;function Sn(t,e){const n=[],o=(a,s,r={})=>n.push(v("li",{class:`${t}-entry`,...r},a,v("span",null,s)));if(e.type==="schema"){const a=new Set(e.nodes.flatMap(s=>(s.columns??[]).map(r=>r.key)));for(const[s,r]of[["PK","Primary key"],["FK","Foreign key"]])a.has(s)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"aria-hidden":"true"},s),v("span",null,r)))}if(e.type==="flowchart"){const a=new Set(e.nodes.map(s=>s.shape));a.has("terminal")&&o(Ht(t,"terminal"),e.shapeLabels.terminal),a.has("box")&&o(Ht(t,"box"),e.shapeLabels.step),a.has("decision")&&o(Ht(t,"decision"),e.shapeLabels.decision)}const c=new Set(e.type==="sequence"?e.steps.flatMap(a=>"n"in a?[a.kind]:[]):e.edges.filter(a=>!a.fk).map(a=>a.kind)),l=(a,s)=>v("span",{class:`${t}-key-glyph`,"data-ink":s,"aria-hidden":"true"},a);for(const a of["main","plain","dashed"]){const s=e.legend[a];c.has(a)&&s&&o(e.text?l(a==="main"?"━━▶":a==="dashed"?"┄┄▷":"──▶",a==="main"?"main":"plain"):_e(t,a),s,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length){e.edges.some(s=>!s.card)&&o(_e(t,"fk"),e.legend.plain??"A foreign key, to the key it references",{"data-line":"","data-when":"drawn"});const a=new Set(e.edges.flatMap(s=>s.card?[s.card.from,s.card.to]:[]));for(const s of $e)a.has(s)&&o(kn(t,s),Ft[s],{"data-line":"","data-when":"drawn","data-card":s});n.push(v("li",{class:`${t}-entry`,"data-when":"stacked"},v("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),v("span",null,"The table a foreign key references")))}if(e.type==="sequence"){e.bars.length&&o(e.text?l("┃","working"):v("svg",{class:`${t}-swatch`,"data-shape":"bar",...zt(16,16)},v("path",{class:`${t}-life`,d:"M8 0V16"}),v("rect",{class:`${t}-bar`,x:4.5,y:2.5,width:7,height:11,rx:1.5})),e.legend.activation??"Working",e.text?{}:{"data-when":"drawn"});const a=new Set(e.steps.flatMap(s=>"open"in s?[s.open]:[]));for(const s of["opt","loop","alt"])a.has(s)&&n.push(v("li",{class:`${t}-entry`},v("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},s),v("span",null,e.frameWords[s])))}return e.nodes.some(a=>a.focal)&&e.legend.focal&&o(e.text?l("╔═╗","focal"):Ht(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&o(Ht(t,"group"),e.legend.group),n.length?v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function En(t,e){const n=e==="main"?6:6.5;return v("svg",{class:`${t}-arrow`,"data-kind":e,...zt(20,12)},v("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${n}H${e==="dashed"?19:13}`}),e==="dashed"?v("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${n-4}L20 ${n}L12 ${n+4}`}):v("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${n}L12 ${n-4}L12 ${n+4}Z`}))}function se(t,e){if(!e.href)return e.name;const n=e.name.trimEnd().lastIndexOf(" ");return[n<0?"":e.name.slice(0,n+1),v("span",{class:`${t}-name-end`},n<0?e.name:e.name.slice(n+1))]}function An(t,e,n){if(n.shape==="decision")return[v("span",{class:`${t}-words`},v("span",{class:`${t}-name`},se(t,n)))];const o=[];return e.type==="data-flow"?o.push(v("span",{class:`${t}-kind`},n.kind,v("span",{class:`${t}-lane-word`},` · ${n.laneLabel}`))):n.kind&&o.push(v("span",{class:`${t}-kind`},n.kind)),o.push(v("span",{class:`${t}-name`},se(t,n))),n.detail&&o.push(v("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?v("span",{class:`${t}-runs`},Qt(n.detail).flatMap((c,l)=>[l?" ":"",v("span",{class:`${t}-run`},c)])):n.detail)),o}function Ln(t,e,n){return[v("span",{class:`${t}-th`},v("span",{class:`${t}-tname`},se(t,e))),v("span",{class:`${t}-rows`},(e.columns??[]).map((o,c)=>v("span",{class:`${t}-row`,"data-row":c,"data-key":o.key},v("span",{class:`${t}-keyseat`},o.key??""),v("span",{class:`${t}-cname`},o.name),o.ref?v("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} ${o.ref.table}`):o.type?v("span",{class:`${t}-ctype`},o.type):null))),e.more?v("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Oe=t=>{const e={32:"space-8",40:"space-10",48:"space-12",64:"space-16"};return e[t]?`var(--basalt-${e[t]})`:`${t}px`};function Zt(t,e,n,o){const{P:c}=t,l=vn(e,o)||o.keep===n.id,a=Rt(e,o),s=o.layout==="drawn"&&o.rows,r=[`--_c:${n.col}`,`--_r:${s?2*n.row:n.row}`,`--_r2:${s?2*n.row2+1:n.row2+1}`];e.type==="data-flow"&&r.push(`--_lc:${n.col+1}`),e.type==="sequence"&&r.push(`--_c2:${n.col+1}`);const d=t.plan;if(d&&n.i>0){const b=Ot(d.gaps,n.id)??32,h=Ot(o.grow,n.id)??0;r.push(`--_gap:${h?`calc(${Oe(b)} + var(--basalt-space-4) * ${h})`:Oe(b)}`)}const p=Ot(o.heights,n.id);p&&r.push(`--_h:${p}px`);const f=Ot(We(e),n.id);f&&r.push(`--_mh:${f}px`);const i=Ot(o.words,n.id);i&&r.push(`--_ww:${i}px`);const u=a?o.stop===n.id?0:-1:o.keep===n.id?-1:void 0;return v(n.href?"a":"div",{class:`${c}-node`,href:n.href,target:n.href&&n.blank?"_blank":void 0,rel:n.href&&n.blank?"noopener noreferrer":void 0,"data-link":n.href?n.blank?"external":"":void 0,"data-node":n.id,"data-shape":n.shape,"data-focal":n.focal?"":void 0,"data-branch":n.branch?"":void 0,"data-mark":n.mark?n.mark.id??"":void 0,"data-level":t.level,style:r.join(";"),role:l&&!n.href?"img":void 0,"aria-label":l||n.href?pn(e,n):void 0,tabindex:u},n.shape==="decision"?v("svg",{class:`${c}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},v("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,n.mark?v("span",{class:`${c}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${be(n.mark.onLight)};--_md:${be(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?Ln(c,n,e):An(c,e,n))}function _n(t,e,n){const{P:o}=t,c=[];if(e.type==="data-flow"&&c.push(...e.lanes.map((r,d)=>v("div",{class:`${o}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},v("span",{class:`${o}-lane-name`},r.label)))),e.type==="architecture")for(const r of e.groups){const d=Kt(e,r);if(!d)continue;const p=[0,1,2,3].map(f=>Ee(e,r,f));c.push(v("div",{class:`${o}-gbox`,"data-group":r.id,"data-depth":r.depth>1?r.depth:void 0,style:`--_c:${d.c1};--_c2:${d.c2+1};--_r:${d.r1};--_r2:${d.r2+1}${p[0]>1?";--_gt:2":""}${p[1]>1?";--_ge:2":""}${p[2]>1?";--_gb:2":""}${p[3]>1?";--_gs:2":""}`,"aria-hidden":"true"},v("span",{class:`${o}-glabel`},r.label)))}if(e.text)return[v("pre",{class:`${o}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},v("code",{class:`${o}-text-ink`},In(o,e)))];if(e.type==="sequence")return c.push(v("ul",{class:`${o}-cast`},e.nodes.map(r=>v("li",{class:`${o}-actor`,style:e.rtl?`--_ac:${r.col}`:void 0},Zt(t,e,r,n))))),c.push(qn(t,e)),c;const l=r=>{const d=r.group?e.groups.find(p=>p.id===r.group):void 0;return d?.parent?e.groups.find(p=>p.id===d.parent):d},a=(r,d,p)=>{const f=t.plan?Ot(n.grow,d[0].id)??0:0,i=d[0],u=t.plan&&i.group===r.id?e.edges.filter((g,k)=>g.to===i.id&&(t.plan.routes[k]==="trunk"||t.plan.routes[k]==="end-down")):[],b=Math.max(0,...u.map(g=>g.label?Vt(g.label):0)),h=[f?`--_ggrow:${f}`:"",b?`--_tl:${b}`:""].filter(Boolean).join(";");return v("div",{class:`${o}-group`,"data-group":r.id,"data-depth":r.depth>1?r.depth:void 0,"data-turn":u.length?"":void 0,style:h||void 0},v("span",{class:`${o}-glabel`,"aria-hidden":"true"},r.label),p)};let s=0;for(;sh.id===p[i].group):void 0;if(!u){f.push(Zt(t,e,p[i],n)),i++;continue}const b=[];for(;iZt(t,e,h,n))))}c.push(a(d,p,f))}return c}function In(t,e){const n=[],o=r=>v("span",{class:`${t}-tx-name`},r),c=r=>r==="main"?"━▶":r==="dashed"?"┄▷":"─▶",l=(r,d,p,...f)=>v("span",{class:`${t}-tx-line`,...r,style:p?`--_in:${d+p};--_hang:${p}`:`--_in:${d}`},...f);n.push(l({"data-ink":"names"},0,0,e.nodes.flatMap((r,d)=>[d?" · ":"",o(r.name)])));const a=String(Math.max(1,...e.steps.map(r=>"n"in r?r.n:0))).length;let s=0;for(const r of e.steps){const d=2*s;if("band"in r){n.push(l({"data-ink":"band"},d,0,`── ${r.band} ──`));continue}if("open"in r){n.push(l({"data-ink":"frame"},d,0,v("span",{"data-ink":"op"},`[${r.open}]`),` ${r.label}`)),s++;continue}if("otherwise"in r){n.push(l({"data-ink":"frame"},2*Math.max(0,s-1),0,v("span",{"data-ink":"op"},"[else]"),` ${r.otherwise}`));continue}if("close"in r){s=Math.max(0,s-1),n.push(l({"data-ink":"frame"},2*s,0,"[end]"));continue}const p=e.byId.get(r.from)?.name??r.from,f=e.byId.get(r.to)?.name??r.to,i=a+2;n.push(l({"data-n":r.n},d,i,v("span",{"data-ink":"num"},String(r.n).padStart(a,"0"))," ",o(p)," ",v("span",{class:`${t}-tx-to`},v("span",{"data-ink":r.kind==="main"?"main":"plain"},c(r.kind))," ",f))),n.push(l({"data-n":r.n},d+i,0,v("span",{"data-ink":"label"},r.label))),r.note&&n.push(l({"data-n":r.n},d+i,0,v("span",{"data-ink":"note"},r.note)))}return n}function qn(t,e){const{P:n}=t,o=[],c=[],l=()=>c.length?c[c.length-1].el.c:o;let a=null;for(const s of e.steps){if("band"in s){a=null,l().push(v("p",{class:`${n}-band`},v("span",null,s.band)));continue}if("open"in s){a=null;const h=c[c.length-1],g=h?`;--_fis:${s.a===h.a?1:0};--_fie:${s.b===h.b?1:0}`:"",k=v("div",{class:`${n}-frame`,"data-op":s.open,"data-depth":s.depth,style:`--_a:${s.a};--_b:${s.b+1}${g}`},v("span",{class:`${n}-fbox`,"aria-hidden":"true"}),v("p",{class:`${n}-fhead`},v("span",{class:`${n}-ftab`,"aria-hidden":"true"},s.open),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords[s.open]}: `),s.label)));l().push(k),c.push({el:k,a:s.a,b:s.b});continue}if("otherwise"in s){a=null,l().push(v("p",{class:`${n}-felse`},v("span",{class:`${n}-fword`,"aria-hidden":"true"},"else"),v("span",{class:`${n}-flabel`},v("span",{class:t.hidden},`${e.frameWords.else}: `),s.otherwise)));continue}if("close"in s){a=null,c.pop();continue}a||(a=v("ol",{class:`${n}-msgs`,start:s.n}),l().push(a));const r=e.byId.get(s.from),d=e.byId.get(s.to),p=r?.col??1,f=d?.col??1,i=p===f,u=i&&(e.rtl?p!==1:p===e.nodes.length),b=ve(e,s.kind);a.c.push(v("li",{class:`${n}-msg`,"data-kind":s.kind,"data-from":s.from,"data-to":s.to,"data-self":i?u?"start":"end":void 0,style:`--_a:${Math.min(p,f)};--_b:${Math.max(p,f)+1}`},v("span",{class:`${n}-said`},v("span",{class:`${n}-num`},String(s.n)),v("span",{class:`${n}-mlabel`},s.label)),v("span",{class:`${n}-route`},r?.short??s.from," ",v("span",{class:`${n}-to`},En(n,s.kind),v("span",{class:t.hidden}," to ")," ",d?.short??s.to,b?` · ${b}`:"")),s.note?v("span",{class:`${n}-note`},s.note):null))}return v("div",{class:`${n}-steps`},o)}function Ce(t,e){return jt(e,`list:${t}`,()=>Cn(t,e))}var On=Ce;function Cn(t,e){const n=Math.min(6,e.heading+1),o=f=>v(`h${n}`,{class:`${t}-list-head`},f),c=f=>v("strong",null,f),l=f=>f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},c(f.name)):c(f.name),a=f=>v("code",{class:`${t}-code`},f),s=f=>e.byId.get(f)?.name??f,r=f=>{const i=ve(e,f);return i?` (${i})`:""},d=f=>f.focal&&e.legend.focal?` ${Wt(e.legend.focal)}`:"";if(e.type==="architecture"){const f=b=>v("li",null,l(b),b.kind?`, ${b.kind}`:"",b.detail?[". ",b.mono?a(b.detail):b.detail,/[.!?]$/.test(b.detail)?"":"."]:/[.!?]$/.test(b.kind??b.name)?"":".",d(b)),i=[o("Parts")],u=e.nodes.filter(b=>!b.group);u.length&&i.push(v("ul",{class:`${t}-list-items`},u.map(f)));for(const b of e.groups.filter(h=>h.depth===1)){i.push(v("p",{class:`${t}-list-group`},b.label)),b.members.length&&i.push(v("ul",{class:`${t}-list-items`},b.members.map(h=>f(e.byId.get(h)))));for(const h of e.groups.filter(g=>g.parent===b.id))i.push(v("p",{class:`${t}-list-group`,"data-depth":2},h.label)),i.push(v("ul",{class:`${t}-list-items`,"data-depth":2},h.members.map(g=>f(e.byId.get(g)))))}return i.push(o("Connections")),i.push(v("ol",{class:`${t}-list-items`},e.edges.map(b=>v("li",null,c(s(b.from))," to ",c(s(b.to)),b.label?[": ",a(_t(b.label))]:"",`${r(b.kind)}.`)))),i}if(e.type==="flowchart"){const f=i=>(e.byId.get(i)?.i??0)+1;return[v("ol",{class:`${t}-list-items`},e.nodes.map(i=>{const u=e.edges.filter(g=>g.from===i.id),b=i.shape==="decision"?"Decision":i.shape==="terminal"?u.length?"Start":"End":"Step",h=!i.detail&&/[.!?]$/.test(i.name)?" ":". ";return v("li",null,l(i),i.detail?[", ",i.mono?a(i.detail):i.detail]:"",`${h}${b}.`,d(i),u.length?v("ul",{class:`${t}-list-exits`},u.map(g=>v("li",null,g.label?`If ${_t(g.label)}: go to ${f(g.to)}, `:`Then: go to ${f(g.to)}, `,c(s(g.to)),r(g.kind)))):null)}))]}if(e.type==="data-flow")return[v("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const i=e.edges.filter(u=>u.from===f.id);return v("li",null,`${f.laneLabel}: `,l(f),f.detail?[", ",f.mono?a(f.detail):f.detail]:"",".",d(f),i.length?[" Then ",...i.flatMap((u,b)=>[b?"; ":"",`to step ${e.byId.get(u.to).step}, `,c(s(u.to)),u.label?[": ",a(_t(u.label))]:"",r(u.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[o("Participants"),v("ul",{class:`${t}-list-items`},e.nodes.map(u=>v("li",null,c(u.name),u.kind?`, ${u.kind}`:"",".",d(u),ke(e,u))))];f.push(o("Messages"));let i=null;for(const u of e.steps){if("band"in u){i=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},u.band));continue}if("open"in u){i=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":u.depth>1?u.depth:void 0},`${e.frameWords[u.open]}: ${u.label}`));continue}if("otherwise"in u){i=null,f.push(v(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`,"data-depth":u.depth>1?u.depth:void 0},`${e.frameWords.else}: ${u.otherwise}`));continue}if("close"in u){i=null;continue}i||(i=v("ol",{class:`${t}-list-items`,start:u.n}),f.push(i)),i.c.push(v("li",null,a(u.label),": ",c(s(u.from))," to ",c(s(u.to)),`${r(u.kind)}.`,u.note?` ${Wt(u.note)}`:""))}return f}const p=[];for(const f of e.nodes)p.push(v(`h${n}`,{class:`${t}-list-group`},f.href?v("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},a(f.name)):a(f.name),d(f))),p.push(v("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(i=>v("li",null,a(i.name),i.key==="PK"?", primary key":i.key==="FK"?", foreign key":"",i.ref?[", references ",a(`${i.ref.table}.${i.ref.column}`),i.card?[" (",mn(f.id,i.ref.table,i.card,a),")"]:""]:i.type?`, ${i.type}`:"")),...f.more?[v("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return p}function Be(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Jt(t)?`Arrow keys move to the nearest ${n} in that direction`:`Arrow keys move to the next or the previous ${n}, in the author's order`}; Home and End go to the ends; Escape clears the trace.${t.nodes.some(c=>c.href)?" Enter opens a part that is a link.":""}`}function re(t,e=!1){const n=e&&t.type!=="sequence"&&Jt(t)&&t.cols>1&&t.rows>1,o=t.nodes.some(c=>c.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Me(t)},{keys:["Home","End"],words:"the ends"},...o,{keys:["Esc"],words:"clear"}]}var Bn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Jt(t){return jt(t,"spatial",()=>{const e=t.nodes.map(l=>({id:l.id,...jn(t,l)})),n=(l,a)=>{const s=a==="right"||a==="left",r=a==="right"||a==="down",d=b=>s?[b.col,b.col]:b.rows,p=b=>s?b.rows:[b.col,b.col],f=d(l),i=p(l);let u=null;return e.forEach((b,h)=>{if(b===l)return;const g=d(b),k=p(b),M=r?g[0]-f[1]:f[0]-g[1];if(M<1)return;const z=Math.max(0,k[0]-i[1],i[0]-k[1]),w=[z===0?0:1,z===0?M:M+2*z,z,Math.abs(k[0]-i[0]),h];(!u||Bn(w,u.rank))&&(u={id:b.id,rank:w})}),u?.id??null},o=Lt();for(const l of e)o[l.id]={right:n(l,"right"),left:n(l,"left"),down:n(l,"down"),up:n(l,"up")};const c=l=>{const a=new Set([l]),s=[l];for(;s.length;)for(const r of Object.values(o[s.pop()]))r&&!a.has(r)&&(a.add(r),s.push(r));return a.size};return e.every(l=>c(l.id)===e.length)?o:null})}function Xt(t){return jt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!ie(t))return{lane:e,dropped:n,lanes:0};const o=(r,d)=>(t.byId.get(r)?.row??0)*1e3+d,c=new Map;t.edges.forEach((r,d)=>{const p=`${r.to}.${r.toRow}.${r.card?.to??""}`,f=o(r.from,r.fromRow??0),i=o(r.to,r.toRow??0),u=c.get(p)??{members:[],lo:1/0,hi:-1/0};u.members.push(d),u.lo=Math.min(u.lo,f,i),u.hi=Math.max(u.hi,f,i),c.set(p,u)});const l=[...c.values()].sort((r,d)=>d.hi-d.lo-(r.hi-r.lo)),a=[];let s=0;for(const r of l.reverse()){const d=new Set(a.filter(f=>f.lo<=r.hi&&r.lo<=f.hi).map(f=>f.lane));let p=0;for(;d.has(p);)p++;if(p>1){for(const f of r.members)n.add(f);continue}a.push({lo:r.lo,hi:r.hi,lane:p});for(const f of r.members)e.set(f,p);s=Math.max(s,p+1)}return{lane:e,dropped:n,lanes:s}})}var ie=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Ut(t,e,n){const o=n.prefix,c=wn(n.base),l=t.type==="sequence"||t.type==="schema"?null:Le(t),a={P:o,ids:c,level:n.level,plan:l,hidden:n.hiddenClass},s=e.layout==="drawn",r=Rt(t,e),d=t.type==="sequence"||t.type==="schema"?s:!0,p=`h${t.heading}`,f=[`--_cols:${ae(t)}`];if(t.type==="architecture"&&t.groups.length||s&&e.pad){const i=t.type==="architecture"?Se(t):[0,0,0,0],u=(h,g,k)=>h?h>1?`calc(${h} * var(--basalt-space-${g}))`:`var(--basalt-space-${g})`:k?`var(--basalt-space-${k})`:"0px",b=s&&e.pad?"3":void 0;f.push(`--_gpad:${u(i[0],"8",b)} ${u(i[1],"4")} ${u(i[2],"4",b)} ${u(i[3],"4")}`)}if(l?.gutter&&l.laneCount>2&&f.push(`--_gw:calc(${l.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),ie(t)){const i=t.marks?"var(--basalt-space-6) + var(--basalt-space-1)":"var(--basalt-space-5)";f.push(`--_gpad:0px ${Xt(t).lanes>1?`calc(${i} + var(--basalt-space-3))`:t.marks?`calc(${i})`:i} 0px 0px`)}return t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),v("figure",{class:n.className?`${o} ${n.className}`:o,"aria-labelledby":c.title,"data-type":t.type,"data-cols":ae(t),"data-reach":t.type==="architecture"?Ae(t):void 0,"data-gutter":l?.gutter?"":void 0,"data-marks":t.marks?"":void 0,"data-layout":e.layout??(t.unplaced?"stacked":void 0),"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-motion":t.motion.animated?"animated":void 0,"data-first-visit":t.motion.animated&&t.motion.firstVisit?"":void 0,"data-rtl":t.rtl?"":void 0,"data-viewer":n.viewer?"":void 0,style:f.join(";")},v("div",{class:`${o}-head`},v(p,{id:c.title,class:`${o}-title`},t.title),n.hasSource?v("p",{class:`${o}-source`},{slot:"source"}):null),v("div",{class:`${o}-drawing`,style:s&&e.rows?`--_rows:${e.rows};--_row-gap:0px`:void 0,role:d?"group":void 0,"aria-roledescription":d?"diagram":void 0,"aria-labelledby":d?c.title:void 0,"aria-describedby":d?r?`${c.summary} ${c.keys}`:c.summary:void 0,"data-stops":r?"":void 0},_n(a,t,e),t.text?null:v("div",{class:`${o}-ink`,"aria-hidden":"true"}),v("span",{class:`${o}-ruler`,"aria-hidden":"true"})),qe(o,t),v("p",{class:`${o}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),Rt(t,e)&&t.type!=="sequence"||s&&t.type==="sequence"?v("p",{class:`${o}-tap-hint`,"aria-hidden":"true"},`Tap ${Me(t)} to highlight its lines. Tap it again to clear.`):null,v("div",{class:`${o}-foot`},{slot:"toggle"}),v("div",{id:c.list,class:`${o}-list`,hidden:!e.open},Ce(o,t)),v("span",{id:c.keys,class:n.hiddenClass},n.viewer?`${Be(t,s)} ${n.viewer}`:Be(t,s)),v("figcaption",{id:c.summary,class:`${o}-summary`},{slot:"summary"}))}function Rn(t){const e=getComputedStyle(t),n=(c,l)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${c}`));return Number.isFinite(a)?a:l},o=new Map;return{space:c=>(o.has(c)||o.set(c,n(`space-${c}`,parseFloat(c.replace("-","."))*4)),o.get(c)),node:n("size-diagram-node",144),table:n("size-diagram-table",224),lane:n("size-diagram-lane",120),step:n("size-diagram-step",56),head:n("size-diagram-head",8),guide:n("size-diagram-guide-dash",4),hair:n("size-hairline",1),line:n("size-chart-line",2),cut:n("size-cut",2),dot:n("size-dot",6),dash:n("size-chart-dash",6),dashGap:n("size-chart-dash-gap",4),wide:n("size-breakpoint-container-lg",640),cap:n("size-breakpoint-container",480),radius:n("radius-md",8),radiusXs:n("radius-xs",4),activation:n("size-diagram-activation",8),foot:n("size-diagram-foot",14)}}var Yt=(t,e)=>t==="main"?e.line:e.hair,Mt=(t,e)=>{const n=t.getBoundingClientRect();return{l:n.left-e.left,t:n.top-e.top,r:n.right-e.left,b:n.bottom-e.top}},It=(t,e,n=.01)=>t.le.l+n&&t.te.t+n,le=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function xt(t,e,n){const{l:o,t:c,r:l,b:a}=t.rect,s=(o+l)/2,r=(c+a)/2,d=(l-o)/2,p=(a-c)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const b=n,h=p*Math.max(0,1-Math.abs(b-s)/d);return{x:b,y:e==="top"?r-h:r+h}}const i=n,u=d*Math.max(0,1-Math.abs(i-r)/p);return{x:e==="left"?s-u:s+u,y:i}}if(t.shape==="terminal"){const i=Math.min(d,p);if(f){const g=n,k=Math.min(Math.max(g,o+i),l-i),M=g-k,z=Math.abs(M)>=i?0:Math.sqrt(i*i-M*M);return{x:g,y:Math.abs(M)<1e-6?e==="top"?c:a:e==="top"?r-z:r+z}}const u=n,b=u-r,h=Math.abs(b)>=i?0:Math.sqrt(i*i-b*b);return{x:e==="left"?o+i-h:l-i+h,y:u}}return f?{x:n,y:e==="top"?c:a}:{x:e==="left"?o:l,y:n}}function Tn(t,e,n){const{l:o,t:c,r:l,b:a}=e.rect,s=(o+l)/2,r=(c+a)/2,d=(l-o)/2,p=(a-c)/2;if(e.shape==="decision")return Math.abs(t.x-s)/d+Math.abs(t.y-r)/p<1-n/Math.min(d,p);if(e.shape==="terminal"){const f=Math.min(d,p),i=Math.min(Math.max(t.x,o+f),l-f);return Math.hypot(t.x-i,t.y-r)o+n&&t.xc+n&&t.ymatchMedia("(forced-colors: active)").matches;function Wn(t,e){const n=t.querySelector(`.${e}-ruler`),o=new Map;return(c,l)=>{const a=`${l}|${c}`;return o.has(a)||(n.setAttribute("data-f",l),n.textContent=c,o.set(a,n.getBoundingClientRect().width),n.textContent=""),o.get(a)}}var Qt=t=>t?t.split(/\s+/).filter(Boolean):[];function Fn(t,e,n){const o=e.space;let c=e.node,l=e.table;for(const r of t.nodes){if(r.shape==="table"){for(const h of r.columns??[]){const g=h.ref?`${t.rtl?"←":"→"} ${h.ref.table}`:h.type??"",k=o("6")+n(h.name,"mono")+(g?o("3")+n(g,"mono"):0)+2*o("3")+2*e.hair;l=Math.max(l,Math.ceil(k))}l=Math.max(l,Math.ceil(n(r.name,"table")+2*o("3")+2*e.hair+(r.href?16+o("1-5"):0)));continue}const d=r.shape==="terminal"?2*o("5"):2*o("3"),p=r.mark&&!Nn()?(r.shape==="participant"?2:1)*o("6"):0;let f=0;const i=r.href?16+o("1-5"):0,u=Qt(r.name);if(u.forEach((h,g)=>{f=Math.max(f,n(h,r.shape==="decision"?"name-500":"name")+(r.kind?0:p)+(g===u.length-1?i:0))}),t.type!=="data-flow")for(const h of Qt(r.kind))f=Math.max(f,n(h,"mono")+p);for(const h of Qt(r.detail))f=Math.max(f,n(h,r.mono?"mono":"sans"));const b=r.shape==="decision"?f/.62:f+d+2*e.hair;c=Math.max(c,Math.ceil(b))}const a=ae(t);let s;return t.type==="data-flow"?s=e.lane+a*(c+o("12")):t.type==="schema"?s=a*l+(a-1)*(o("12")+(t.marks?o("3"):0))+(ie(t)?(t.marks?o("6")+o("1"):o("5"))+(Xt(t).lanes>1?o("3"):0):0):t.type==="sequence"?s=a*c+(a-1)*o("5"):s=a*c+(a-1)*o("16")+Ae(t)*o("4"),{track:c,table:l,least:Math.max(e.wide,s)}}function Re(t,e){return{x:(n,o)=>o%2===1?Math.round(n+t-.5)+.5-t:Math.round(n+t)-t,y:(n,o)=>o%2===1?Math.round(n+e-.5)+.5-e:Math.round(n+e)-e}}function ce(t){const e=t[t.length-2],n=t[t.length-1];return Math.abs(e.x-n.x)<.01?n.y>e.y?"down":"up":n.x>e.x?"right":"left"}function Te(t,e,n){const o=t.map(l=>({...l}));for(let l=1;l=2){const r=c[c.length-2];if(Math.abs(r.x-s.x)<.01&&Math.abs(s.x-a.x)<.01||Math.abs(r.y-s.y)<.01&&Math.abs(s.y-a.y)<.01){c[c.length-1]=a;continue}}c.push(a)}}return c}var qt=t=>t.slice(1).map((e,n)=>[t[n],e]);function Pt(t,e,n){const o=[];for(let l=0;lMath.min(h.x,g.x)+.75&&zMath.min(k.y,M.y)+.75&&wl.split(/\s+/).map(parseFloat).filter(a=>Number.isFinite(a)),o=(l,a,s)=>{const r=[];let d=a;for(const p of l)r.push([d,d+p]),d+=p+s;return r},c=o(n(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0);return{cols:o(n(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:t.style.getPropertyValue("--_rows").trim()?c.filter((l,a)=>a%2===1):c}}var ht=t=>t==="left"||t==="right",ze={top:"bottom",bottom:"top",left:"right",right:"left"};function de(t,e){return t.row===e.row?e.col>t.col?["right","left"]:["left","right"]:t.col===e.col?e.row>t.row?["bottom","top"]:["top","bottom"]:[e.col>t.col?"right":"left",e.row>t.row?"top":"bottom"]}function Ne(t,e,n){const o=[];t.edges.forEach((l,a)=>{const s=t.byId.get(l.from),r=t.byId.get(l.to),[d,p]=e[a],f=s.row===r.row&&ht(d)&&ht(p)&&d===ze[p]||s.col===r.col&&!ht(d)&&!ht(p)&&d===ze[p];o.push({edge:a,end:"from",node:s,side:d,far:r,straight:f,f:.5},{edge:a,end:"to",node:r,side:p,far:s,straight:f,f:.5})});const c=new Map;for(const l of o){const a=`${l.node.id}.${l.side}`;c.has(a)||c.set(a,[]),c.get(a).push(l)}for(const[l,a]of c){if(a[0].node.shape==="decision")continue;const s=h=>ht(h.side)?h.far.row-h.node.row:h.far.col-h.node.col,r=a.filter(h=>h.straight),d=a.filter(h=>!h.straight);if(d.sort((h,g)=>s(h)-s(g)||(ht(h.side)?h.far.col-g.far.col:h.far.row-g.far.row)*(s(h)<0?1:-1)),a.length>3&&n(`${l.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!r.length){d.length===2?(d[0].f=.25,d[1].f=.75):d.length===3?(d[0].f=.25,d[1].f=.5,d[2].f=.75):d.length>3&&d.forEach((h,g)=>{h.f=(g+1)/(d.length+1)});continue}const p=new Map;for(const h of r)p.has(h.far.id)||p.set(h.far.id,[]),p.get(h.far.id).push(h);for(const h of p.values())h.length>1&&h.sort((g,k)=>g.edge-k.edge).forEach((g,k)=>{g.f=h.length===2?k===0?.25:.75:(k+1)/(h.length+1)});const f=Math.min(...r.map(h=>h.f)),i=Math.max(...r.map(h=>h.f)),u=d.filter(h=>s(h)<0),b=d.filter(h=>s(h)>=0);u.forEach((h,g)=>{h.f=f*(g+1)/(u.length+1)}),b.forEach((h,g)=>{h.f=i+(1-i)*(g+1)/(b.length+1)})}return o}function We(t,e=8,n=8){return jt(t,`port-floors:${e}:${n}`,()=>{const o=Lt();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow")return o;const c=t.edges.map(a=>{const s=t.byId.get(a.from),r=t.byId.get(a.to),[d,p]=de(s,r);return[a.fromSide??d,a.toSide??p]}),l=new Map;for(const a of Ne(t,c,()=>{})){if(!ht(a.side)||a.node.shape!=="box")continue;const s=`${a.node.id}.${a.side}`;l.has(s)||l.set(s,[]),l.get(s).push(a.f)}for(const[a,s]of l){if(s.length<2)continue;const r=s.slice().sort((f,i)=>f-i).filter((f,i,u)=>i===0||f-u[i-1]>1e-9);let d=Math.max(e/r[0],e/(1-r[r.length-1]));for(let f=1;f{const a=t.byId.get(l.dataset.node);a&&c.set(a.id,{id:a.id,rect:Mt(l,n),shape:a.shape,i:a.i})}),c}function De(t,e){const n=e.head,o=e.head/2,{x:c,y:l}=t.tip;return t.dir==="down"?{l:c-o,r:c+o,t:l-n,b:l}:t.dir==="up"?{l:c-o,r:c+o,t:l,b:l+n}:t.dir==="right"?{l:c-n,r:c,t:l-o,b:l+o}:{l:c,r:c+n,t:l-o,b:l+o}}var Ge=(t,e,n)=>({l:Math.min(t.x,e.x)-n/2,r:Math.max(t.x,e.x)+n/2,t:Math.min(t.y,e.y)-n/2,b:Math.max(t.y,e.y)+n/2});function Ve(t,e,n,o){const c=(l,a)=>{const s=l+a-Math.floor(l+a);return s<.005||s>.995?[0]:s<=.5?[-s,1-s]:[1-s,-s]};for(const l of c(t.t,n))for(const a of c(t.l,e)){if(!a&&!l)return t;const s={l:t.l+a,r:t.r+a,t:t.t+l,b:t.b+l};if(o(s))return s}return t}function Dn(t,e,n,o,c,l,a,s,r){const d=a.space,p=[],f=[],i=[],u=[],b=d("1"),h=e.filter(g=>t.edges[g.i]?.label).sort((g,k)=>+(t.edges[k.i].kind==="main")-+(t.edges[g.i].kind==="main")||g.i-k.i);for(const g of h){const k=t.edges[g.i].label,M=s(k,"label"),z=16*Vt(k),w=g.pts.length-2,q=[];qt(g.pts).forEach(([E,G],R)=>{const C=Math.abs(E.y-G.y)<.01,W=C?E.x:E.y;let T=C?G.x:G.y;const K=Math.sign(T-W)||1;R===w&&(T-=K*a.head);let X=[[W,T]];for(const J of c)for(const Z of C?[J.l,J.r]:[J.t,J.b]){const Q=C?E.y:E.x;(C?Q>J.t&&QJ.l&&QZ>Math.min($,S)+1&&Z{const Q=(J+Z)/2,m=C?{x:Q,y:E.y}:{x:E.x,y:Q};return!c.some($=>m.x>$.l&&m.x<$.r&&m.y>$.t&&m.y<$.b)},U=g.axes?.[R]??(C?E.y:E.x);for(const[J,Z]of X)q.push({horiz:C,c:U,p:J,q:Z,len:Math.abs(Z-J),pri:X.length>1&&st(J,Z)?1:0})}),q.sort((E,G)=>G.pri-E.pri||G.len-E.len);let O=null,N=!1;const D=(E,G=!0)=>{const R=le(E,b);return G&&(E.ll.r||E.tl.b)||n.some(C=>je(R,C))||p.some(C=>It(R,C))||o.heads.some(C=>It(R,C))||o.rects.some(C=>It(R,C))?!1:!e.some(C=>C.i!==g.i&&qt(C.pts).some(([W,T])=>It(R,Ge(W,T,C.width))))};for(const E of q){for(const G of[1/2,1/3,2/3]){const R=E.p+(E.q-E.p)*G,C=[],W=d("2")+g.width/2;if(E.horiz?(E.len>=M+2*d("1")+d("3-5")&&C.push({box:{l:R-M/2-d("1"),r:R+M/2+d("1"),t:E.c-z/2,b:E.c+z/2},on:!0}),C.push({box:{l:R-M/2,r:R+M/2,t:E.c-W-z,b:E.c-W},on:!1}),C.push({box:{l:R-M/2,r:R+M/2,t:E.c+W,b:E.c+W+z},on:!1})):(E.len>=z+d("3")&&C.push({box:{l:E.c-M/2-d("1"),r:E.c+M/2+d("1"),t:R-z/2,b:R+z/2},on:!0}),C.push({box:{l:E.c+W,r:E.c+W+M,t:R-z/2,b:R+z/2},on:!1}),C.push({box:{l:E.c-W-M,r:E.c-W,t:R-z/2,b:R+z/2},on:!1})),O=C.find(T=>D(T.box))??null,O)break;!N&&C.some(T=>D(T.box,!1))&&(N=!0)}if(O)break}if(!O){i.push(g.i),N&&u.push(g.i);continue}const dt=Ve(O.box,r.ox,r.oy,E=>D(E));p.push(dt),f.push({i:g.i,text:k,box:dt,on:O.on})}return{labels:f,unseated:i,bounded:u}}function Ke(t,e,n,o){const c=[],l=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const s=Mt(a,e);l.push(s),c.push({l:s.l,r:s.r,t:s.t,b:s.t+1},{l:s.l,r:s.r,t:s.b-1,b:s.b},{l:s.l,r:s.l+1,t:s.t,b:s.b},{l:s.r-1,r:s.r,t:s.t,b:s.b});const r=a.querySelector(`:scope > .${n}-glabel`);r&&r.getClientRects().length&&c.push(Mt(r,e))}),t.querySelectorAll(`.${n}-lane`).forEach((a,s)=>{if(!a.getClientRects().length)return;const r=Mt(a,e);s>0&&c.push({l:r.l,r:r.r,t:r.t-o/2-.5,b:r.t-o/2+.5});const d=a.querySelector(`.${n}-lane-name`);d&&c.push(Mt(d,e))}),{obstacles:{rects:c,heads:[]},groups:l}}function Ze(t,e){const{m:o,tk:c,P:l,drawing:a,origin:s,warn:r}=t,d=c.space,p=He(o,a,s,l),f=[...p.values()],i=Hn(a),u=s.left-Math.floor(s.left),b=s.top-Math.floor(s.top),h=Re(u,b),g=a.clientWidth,k=a.clientHeight,M=y=>o.type==="data-flow"?y.col+1:y.col,z=parseFloat(getComputedStyle(a).rowGap)||0,w={w:g,h:k,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:u,oy:b};if(o.type==="sequence")return Vn(t,w,h);let q,O=[];o.type==="schema"?q=o.edges.map(y=>{const A=o.byId.get(y.from),_=o.byId.get(y.to);if(A.col===_.col){const x=A.col===o.cols&&o.cols>1?"left":"right";return[x,x]}return _.col>A.col?["right","left"]:["left","right"]}):(q=o.edges.map(y=>{const A=o.byId.get(y.from),_=o.byId.get(y.to),[x,L]=de(A,_);return[y.fromSide??x,y.toSide??L]}),O=Ne(o,q,r||(()=>{})));const N=(y,A)=>{const _=a.querySelector(`.${l}-node[data-node="${CSS.escape(y)}"] .${l}-row[data-row="${A}"]`);if(!_)return 0;const x=Mt(_,s);return(x.t+x.b)/2},D=new Map;if(o.type==="schema"){const y=new Map;o.edges.forEach((_,x)=>{const L=`${_.to}.${_.toRow}.${q[x][1]}`;y.set(L,[...y.get(L)??[],x])});const A=_=>{const x=o.edges[_].card?.to;return x==="one"?0:x==="zero-or-one"?1:2};for(const _ of y.values()){const x=[...new Set(_.map(A))].sort((L,H)=>L-H);if(x.length>1)for(const L of _)D.set(L,(x.indexOf(A(L))-(x.length-1)/2)*d("2"))}}const dt=y=>Math.round(y+u)-u,E=o.edges.map((y,A)=>{const[_,x]=q[A],L=p.get(y.from),H=p.get(y.to),P=Yt(y.kind,c);if(y.fk){const et=N(y.from,y.fromRow),at=N(y.to,y.toRow)+(D.get(A)??0),$t=h.y(et,P),Ct=h.y(at,P),Et=_==="right"?L.rect.r:L.rect.l,kt=x==="right"?H.rect.r:H.rect.l;return{p1:{x:y.card?dt(Et):Et,y:$t},p2:{x:y.card?dt(kt):kt,y:Ct},r1:et,r2:Math.abs($t-Ct)<.01?et:at}}const ot=O.find(et=>et.edge===A&&et.end==="from").f,ct=O.find(et=>et.edge===A&&et.end==="to").f;let it=Fe(L,_,ot),rt=Fe(H,x,ct);const F=ht(_)?it.y:it.x;let V=ht(x)?rt.y:rt.x;return ht(_)?it={...it,y:h.y(it.y,P)}:it={...it,x:h.x(it.x,P)},ht(x)?rt={...rt,y:h.y(rt.y,P)}:rt={...rt,x:h.x(rt.x,P)},ht(_)&&ht(x)&&Math.abs(it.y-rt.y)<1.01&&(rt={...rt,y:it.y},V=F),!ht(_)&&!ht(x)&&Math.abs(it.x-rt.x)<1.01&&(rt={...rt,x:it.x},V=F),it=ht(_)?xt(L,_,it.y):xt(L,_,it.x),rt=ht(x)?xt(H,x,rt.y):xt(H,x,rt.x),{p1:it,p2:rt,r1:F,r2:V}}),G=new Set,R=(y,A)=>{G.has(y)||(G.add(y),r?.(`${o.edges[y].from} to ${o.edges[y].to} ${A}, so its line is not drawn; its row still writes the target`))};for(const y of Xt(o).dropped)R(y,"would need a third lane of turn-backs");const C=new Map,W=Lt();o.type==="schema"&&o.edges.forEach((y,A)=>{const _=o.byId.get(y.from),x=o.byId.get(y.to);if(Math.abs(_.col-x.col)<2)return;const L=Math.min(_.col,x.col),H=Math.max(_.col,x.col),P=o.nodes.filter(at=>at.col>L&&at.col$t.row<=at&&$t.row2>=at+1)||ct.push({key:`g${at}`,y:(ot[at-1][1]+ot[at][0])/2,inner:!0});ct.push({key:"top",y:ot[0][0]-d("4"),inner:!1},{key:"bottom",y:ot[ot.length-1][1]+d("4"),inner:!1});const it=(E[A].r1+E[A].r2)/2,rt=t.pick?.[A]??ct.slice().sort((at,$t)=>Math.abs(at.y-it)-Math.abs($t.y-it)||Number($t.inner)-Number(at.inner)||at.y-$t.y)[0].key;W[A]=rt;const F=q[A][0]==="right"?_.col:_.col-1,V=i.cols[F-1],et=i.cols[F];C.set(A,{corridor:rt,first:V&&et?{key:`c${F}`,span:[V[1],et[0]]}:null,y:0})});const T=new Map;for(const[y,A]of C){const _=o.edges[y],x=T.get(A.corridor)??[],L=x.find(H=>{const P=o.edges[H[0]];return P.to===_.to&&P.toRow===_.toRow&&q[H[0]][1]===q[y][1]&&Math.abs(E[H[0]].p2.y-E[y].p2.y)<.5});L?L.push(y):x.length>=2?R(y,"would need a third lane in its corridor"):x.push([y]),T.set(A.corridor,x)}for(const y of[...C.keys()])G.has(y)&&C.delete(y);const K=y=>{const A=o.edges[y[0]];return Math.abs(o.byId.get(A.from).col-o.byId.get(A.to).col)*1e4+Math.abs(E[y[0]].p1.x-E[y[0]].p2.x)},X=(y,A,_)=>{const x=i.rows;if(y==="top")return x[0][0]-d("4")-A*d("3");if(y==="bottom")return x[x.length-1][1]+d("4")+A*d("3");const L=Number(y.slice(1));return(x[L-1][1]+x[L][0])/2+(A-(_-1)/2)*d("3")},st=(y,A)=>A.forEach((_,x)=>_.forEach(L=>{C.get(L).y=X(y,x,A.length)})),U=()=>{for(const[y,A]of T){const _=A.map(x=>x.filter(L=>C.has(L))).filter(x=>x.length);T.set(y,_),st(y,y==="top"||y==="bottom"?_.slice().sort((x,L)=>K(x)-K(L)):_.slice().sort((x,L)=>K(L)-K(x)))}};U();const J=new Map,Z=new Set,Q=new Map,m=(y,A,_,x,L)=>{J.has(y)||J.set(y,{span:A,vertical:_,members:new Map});const H=J.get(y);H.members.has(x)||H.members.set(x,[]),H.members.get(x).push(L)},$=()=>{J.clear(),Z.clear(),Q.clear(),o.edges.forEach((y,A)=>{if(G.has(A))return;const _=C.get(A);_?.first&&m(_.first.key,_.first.span,!0,`far:${A}`,-(A+1));const[x,L]=q[A],{p1:H,p2:P}=E[A],ot=o.byId.get(y.from),ct=o.byId.get(y.to);let it=null,rt=null,F=!1;if(x===L){if(ht(x)){const V=x==="right"?Math.max(M(ot),M(ct)):Math.min(M(ot),M(ct))-1,et=i.cols[V-1],at=i.cols[V];et&&at&&(it=`c${V}`,rt=[et[1],at[0]],F=!0)}else{const V=x==="bottom"?Math.max(ot.row2,ct.row2):Math.min(ot.row,ct.row)-1,et=i.rows[V-1],at=i.rows[V];et&&at&&(it=`r${V}`,rt=[et[1],at[0]],F=!1)}it&&Z.add(A)}else if(ht(x)&&ht(L)&&(_||Math.abs(H.y-P.y)>.5)){const V=M(ct),et=L==="left",at=i.cols[(et?V-1:V)-1],$t=i.cols[(et?V:V+1)-1];at&&$t&&(it=`c${et?V-1:V}`,rt=[at[1],$t[0]],F=!0)}else if(!ht(x)&&!ht(L)&&Math.abs(H.x-P.x)>.5){const et=L==="top"?ct.row-1:ct.row2,at=i.rows[et-1],$t=i.rows[et];at&&$t&&(it=`r${et}`,rt=[at[1],$t[0]],F=!1)}!it||!rt||(_&&Q.set(A,rt),m(it,rt,F,`${y.to}.${L}.${Math.round(F?P.y:P.x)}`,A))})};$();const S=new Map,B=y=>{const[A,_]=q[y],{p1:x,p2:L}=E[y],H=C.get(y);if(H){const P=Q.get(y),ot=S.get(-(y+1))??(H.first?(H.first.span[0]+H.first.span[1])/2:x.x),ct=S.get(y)??(P?(P[0]+P[1])/2:L.x);return[x,{x:ot,y:x.y},{x:ot,y:H.y},{x:ct,y:H.y},{x:ct,y:L.y},L]}if(ht(A)&&ht(_)){if(A===_){const ot=d(o.marks?"6":"4")+(o.type==="schema"&&o.cols===1?(Xt(o).lane.get(y)??0)*d("3"):0),ct=S.get(y)??(A==="right"?Math.max(x.x,L.x)+ot:Math.min(x.x,L.x)-ot);return[x,{x:ct,y:x.y},{x:ct,y:L.y},L]}if(Math.abs(x.y-L.y)<=.5)return[x,{x:L.x,y:x.y}];const P=S.get(y)??(x.x+L.x)/2;return[x,{x:P,y:x.y},{x:P,y:L.y},L]}if(!ht(A)&&!ht(_)){if(A===_){const ot=S.get(y)??(A==="bottom"?Math.max(x.y,L.y)+d("4"):Math.min(x.y,L.y)-d("4"));return[x,{x:x.x,y:ot},{x:L.x,y:ot},L]}if(Math.abs(x.x-L.x)<=.5)return[x,{x:x.x,y:L.y}];const P=S.get(y)??(x.y+L.y)/2;return[x,{x:x.x,y:P},{x:L.x,y:P},L]}return ht(A)?[x,{x:L.x,y:x.y},L]:[x,{x:x.x,y:L.y},L]},I=y=>{const A=o.edges[y],_=Yt(A.kind,c),x=B(y),L=Te(x,_,h);let H;return x.length===L.length&&(H=qt(x).map(([P,ot])=>Math.abs(P.y-ot.y)<.75?(P.y+ot.y)/2:(P.x+ot.x)/2),H[0]=E[y].r1,H.length>1&&(H[H.length-1]=E[y].r2)),{i:y,from:A.from,to:A.to,kind:A.kind,pts:L,tip:L[L.length-1],dir:ce(L),dot:A.fk&&!A.card?L[0]:void 0,card:A.card,width:_,axes:H}},j=()=>o.edges.flatMap((y,A)=>G.has(A)?[]:[I(A)]);let tt=null;const Y=y=>{tt??(tt=j());const A=tt.map(_=>y.has(_.i)?I(_.i):_);return{lines:A,score:Gn(A,y)*1e5+Pt(A,void 0,y).length*1e3+ue(A.filter(_=>y.has(_.i)),f,o).length}},mt=(y,A)=>{const _=y.flatMap(x=>{const L=x<0?-x-1:x,{p1:H,p2:P}=E[L],ot=C.get(L);return ot?x<0?[H.y,ot.y]:[ot.y,P.y]:A?[H.y,P.y]:[H.x,P.x]});return[Math.min(..._),Math.max(..._)]},nt=y=>y<0?-y-1:y,lt=y=>{const A=[...y.members.values()].map(x=>({members:x,run:mt(x,y.vertical)})).sort((x,L)=>x.run[0]-L.run[0]),_=[];for(const x of A){const L=_[_.length-1];L&&L.some(H=>H.run[0]!(x.length===1&&x[0].members.every(L=>Z.has(L))))},ft=y=>(A,_)=>y[A].run[0]{const A=ft(y),_=[];return y.forEach((x,L)=>{let H=0;for(;_.some((P,ot)=>P===H&&A(L,ot));)H++;_.push(H)}),_},wt=y=>Math.max(0,...yt(y))+1;if(o.marks)for(let y=0;y3){A=H.map(P=>P.members.map(nt));break}if(!A)break;const _=L=>Math.max(...L),x=A.filter(L=>L.some(H=>C.has(H))).sort((L,H)=>_(H)-_(L))[0]??A.slice().sort((L,H)=>_(H)-_(L))[0];for(const L of x)R(L,"would need a fourth lane in a marked gutter"),C.delete(L);$()}const vt=(y,A,_)=>{const x=y[1]-y[0];if(!o.marks)return y[0]+x/(_+1)*(A+1);const L=c.foot+c.radiusXs,H=_>1?Math.min(x/(_+1),(x-2*L)/(_-1)):0;return(y[0]+y[1])/2+(A-(_-1)/2)*H};U();for(const[y,A]of T){if(y==="top"||y==="bottom"||A.length<2)continue;const _=new Set(A.flat());let x=A,L=1/0;for(const H of fe(A.slice().sort((P,ot)=>K(ot)-K(P)))){st(y,H),tt=null;const P=Y(_);P.scorect.members);if(o.marks){const ct=wt(A),it=ft(A),rt=A.length,F=new Set(_.flat().map(nt)),V=Et=>Et.forEach((kt,Tt)=>_[Tt].forEach(Bt=>S.set(Bt,vt(y.span,kt,ct))));let et=yt(A),at=1/0,$t=null;const Ct=[et];if(ct**rt<=729)for(let Et=0;EtMath.floor(Et/ct**Bt)%ct);kt.every((Tt,Bt)=>kt.every((ee,Gt)=>Gt<=Bt||Tt!==ee||!it(Bt,Gt)))&&Ct.push(kt)}for(const Et of Ct){V(Et);const kt=Y(F);kt.scorert.forEach(V=>S.set(V,vt(y.span,F,x))));const it=Y(L);it.scorect.forEach(rt=>S.set(rt,vt(y.span,it,x)))),tt=ot}if(w.lines=j(),o.marks&&(w.lines=w.lines.filter(y=>{if(!y.card)return!0;const A=qt(y.pts),_=([L,H])=>Math.hypot(H.x-L.x,H.y-L.y),x=A.length===1?2*c.foot:c.foot+c.radiusXs-.5;return _(A[0])>=x&&_(A[A.length-1])>=x?!0:(R(y.i,"has no room for its marks at an end"),C.delete(y.i),!1)})),C.size){const y=new Set([...C.values()].map(_=>_.corridor)),A=[y.has("top")?"var(--basalt-space-8)":"0px"];for(let _=1;_<=o.rows;_++)A.push("auto",_De(y,c));const ut=Dn(o,w.lines,f,St,pt,{l:0,t:0,r:g,b:k},c,e,{ox:u,oy:b});return w.labels=ut.labels,w.unseated=ut.unseated,w.bounded=ut.bounded,w.overlaps=[...new Set(Je(w.lines,null).flat())],w}function Gn(t,e){return Je(t,e).length}function Je(t,e){const n=[];for(let o=0;o=s)continue;const[g,k]=i?[r.x,d.x]:[r.y,d.y],[M,z]=i?[p.x,f.x]:[p.y,f.y];Math.min(Math.max(g,k),Math.max(M,z))-Math.max(Math.min(g,k),Math.min(M,z))>1&&n.push([l.i,a.i])}}return n}function*fe(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const r=s===l.pts.length-1?Math.max(l.width/2,o.head/2):l.width/2;return a.x-r<-.5||a.x+r>e+.5||a.y-r<-.5||a.y+r>n+.5})&&c.push(l.i);return c}function ue(t,e,n){const o=[];for(const c of t){const l=qt(c.pts);e.some(a=>l.some(([s,r])=>zn(s,r,a)))&&o.push(c.i)}return o}function Vn(t,e,n){const{m:o,tk:c,P:l,drawing:a,origin:s}=t,r=c.space,d=new Map;a.querySelectorAll(`.${l}-node`).forEach(w=>d.set(w.dataset.node,Mt(w,s)));const p=a.querySelector(`.${l}-steps`),f=p?Mt(p,s).b:e.h,i=w=>{const q=d.get(w);return q?n.x((q.l+q.r)/2,c.hair):0};for(const w of o.nodes){const q=d.get(w.id);q&&e.lifelines.push({x:i(w.id),y1:q.b,y2:f})}const u=w=>d.get(w.id),b=new Map;a.querySelectorAll(`.${l}-msg`).forEach(w=>{const q=Mt(w,s);b.set(Number(w.querySelector(`.${l}-num`)?.textContent??0),(q.t+q.b)/2)});const h=c.activation,g=h/2,k=w=>{const q=o.byId.get(w.who);if(!q)return null;const O=i(w.who),D=(q.i===o.nodes.length-1&&o.nodes.length>1?-1:1)*(o.rtl?-1:1),dt=(w.depth-1)*r("1")*D,E=b.get(w.from)??0,G=b.get(w.to)??E,R=w.from===w.to;return{l:n.x(O-g+dt,c.hair),r:n.x(O+g+dt,c.hair),t:n.y(R?E-r("2")-r("1"):E,c.hair),b:n.y(R?E+r("2")+r("1"):G,c.hair)}},M=o.bars.map(w=>({bar:w,rect:k(w)})).filter(w=>w.rect);e.bars=M.map(w=>w.rect);const z=(w,q,O)=>M.filter(({bar:N})=>N.who===w&&N.to>=q&&(O?N.from<=q:N.fromD.bar.depth-N.bar.depth)[0]?.rect;a.querySelectorAll(`.${l}-msg`).forEach(w=>{const q=w.dataset.from,O=w.dataset.to,N=w.dataset.kind??"plain",D=Yt(N,c),dt=Mt(w,s),E=n.y((dt.t+dt.b)/2,D),G=Number(w.querySelector(`.${l}-num`)?.textContent??0);let R=i(q),C=i(O),W;if(q===O){const Z=w.dataset.self==="start"?-r("6"):r("6"),Q=z(q,G,!0),m=Q?Z>0?Q.r:Q.l:R,$=n.y(E-r("2"),D),S=n.y(E+r("2"),D);W=[{x:m,y:$},{x:n.x(R+Z,D),y:$},{x:n.x(R+Z,D),y:S},{x:m,y:S}]}else{const Z=C>R?1:-1,Q=z(q,G,!1),m=z(O,G,!0);Q&&(R=Z>0?Q.r:Q.l),m&&(C=Z>0?m.l:m.r),W=[{x:R,y:E},{x:C,y:E}]}e.lines.push({i:G,from:q,to:O,kind:N,pts:W,tip:W[W.length-1],dir:ce(W),width:D});const T=w.querySelector(`.${l}-said`),K=w.querySelector(`.${l}-note`),X=o.byId.get(q),st=o.byId.get(O);if(!X||!st)return;const U=q===O?(()=>{const Z=o.nodes.find(m=>m.col===X.col+(w.dataset.self==="start"?-1:1)),Q=Z?i(Z.id):w.dataset.self==="start"?0:e.w;return Math.abs(Q-R)-r("6")-r("2-5")-r("2")})():Math.abs(C-R)-2*r("2");Math.max(T?T.getBoundingClientRect().width:0,K?K.getBoundingClientRect().width:0)>U+.5&&e.unseated.push(G)}),a.querySelectorAll(`.${l}-fhead`).forEach(w=>{const q=w.parentElement?.querySelector(`:scope > .${l}-fbox`);if(!q)return;[...w.children].reduce((N,D)=>N+D.getBoundingClientRect().width,0)+r("3")>q.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${w.querySelector(`.${l}-flabel`)?.textContent??""}" is wider than its participants`)});{const w=[...a.querySelectorAll(`.${l}-fbox`)].flatMap(q=>{const O=Mt(q,s);return[{x:O.l+.5,t:O.t,b:O.b},{x:O.r-.5,t:O.t,b:O.b}]});w.length&&a.querySelectorAll(`.${l}-said, .${l}-note, .${l}-band > span`).forEach(q=>{if(!q.getClientRects().length)return;const O=le(Mt(q,s),r("1"));w.some(N=>O.lN.x&&O.tN.t)&&(e.misfit??(e.misfit=[])).push(`"${q.textContent?.trim()??""}" would lie on a frame's side`)})}return e}function Ue(t,e,n,o=Lt()){const{m:c,tk:l,P:a,drawing:s,origin:r}=t,d=l.space,p=He(c,s,r,a),f=[...p.values()],i=r.left-Math.floor(r.left),u=r.top-Math.floor(r.top),b=Re(i,u),h=s.clientWidth,g=s.clientHeight,k={w:h,h:g,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:i,oy:u},M=Lt();if(c.type==="sequence"||c.type==="schema")return{geo:k,grow:M};const z=h-(parseFloat(getComputedStyle(s).paddingRight)||0),w=(T,K,X)=>{const st=[T];for(let U=1;U<=(Ot(o,K)??0);U++)st.push({...T,t:T.t+X*d("4")*U,b:T.b+X*d("4")*U});return st},q=new Map;s.querySelectorAll(`.${a}-node`).forEach(T=>{const K=T.parentElement,X=Mt(K,r),st=getComputedStyle(K);q.set(T.dataset.node,X.r-(parseFloat(st.paddingRight)||0)-(parseFloat(st.borderRightWidth)||0))});const O=c.nodes,N=T=>p.get(O[T].id),D=T=>{const K=s.querySelector(`.${a}-node[data-node="${CSS.escape(T)}"]`),X=K?.parentElement;return!!(X?.matches(`.${a}-group[data-turn]`)&&X.querySelector(`:scope > .${a}-node`)===K)},dt=(T,K,X)=>D(K)?Array.from({length:Math.round(X/16)+1},(st,U)=>({...T,t:T.t-U*d("4"),b:T.b-U*d("4")})):[T],E=[],G=T=>Yt(c.edges[T].kind,l);c.edges.forEach((T,K)=>{const X=n.routes[K],st=p.get(T.from),U=p.get(T.to),J=G(K);let Z=[];const Q=T.label,m=Q?e(Q,"label"):0,$=Q?16*Vt(Q):16,S=d("4");if(X==="down"||X==="up"){const I=Math.max(st.rect.l,U.rect.l),j=Math.min(st.rect.r,U.rect.r),tt=c.edges.map((lt,ft)=>({o:lt,j:ft})).filter(({o:lt,j:ft})=>(n.routes[ft]==="down"||n.routes[ft]==="up")&&(lt.from===T.from&<.to===T.to||lt.from===T.to&<.to===T.from)),Y=tt.findIndex(lt=>lt.j===K),mt=tt.length<2?.5:tt.length===2?Y===0?.25:.75:(Y+1)/(tt.length+1),nt=b.x(I+(j-I)*mt,J);if(Z=X==="down"?[xt(st,"bottom",nt),xt(U,"top",nt)]:[xt(st,"top",nt),xt(U,"bottom",nt)],Q){let lt=Math.min(Z[0].y,Z[1].y),ft=Math.max(Z[0].y,Z[1].y);X==="down"?ft-=l.head:lt+=l.head;const yt=[...s.querySelectorAll(`.${a}-group`)].map(pt=>Mt(pt,r));let wt=[[lt,ft]];for(const pt of yt)for(const ut of[pt.t,pt.b])wt=wt.flatMap(([y,A])=>ut>y+1&&utyt.some(y=>(pt+ut)/2>y.t&&(pt+ut)/2y.l&&nt1){const pt=wt.filter(([y,A])=>!vt(y,A));[lt,ft]=(pt.length?pt:wt).reduce((y,A)=>A[1]-A[0]>y[1]-y[0]?A:y)}const St=[1/2,1/3,2/3].map(pt=>{const ut=lt+(ft-lt)*pt;return{l:nt-m/2-d("1"),r:nt+m/2+d("1"),t:ut-$/2,b:ut+$/2}});E.push({k:K,cands:St,on:!0,card:X==="down"?T.to:T.from})}}else if(X==="trunk"||X==="rail"){const I=b.x(Math.max(st.rect.l,X==="rail"?U.rect.l:st.rect.l)+d(X==="trunk"?"8":"3"),J),j=xt(st,"bottom",I);if(X==="rail"){if(Z=[j,xt(U,"top",I)],Q){const tt=U.rect.t-d("6");E.push({k:K,cands:w({l:I+d("2-5"),r:I+d("2-5")+m,t:tt-$/2,b:tt+$/2},T.to,-1),on:!1,card:T.to})}}else{const tt=b.x(U.rect.l+d("6"),J),Y=b.y(U.rect.t-S,J);Z=[j,{x:I,y:Y},{x:tt,y:Y},xt(U,"top",tt)],Q&&E.push({k:K,cands:[...dt({l:tt+d("2-5"),r:tt+d("2-5")+m,t:Y-$/2,b:Y+$/2},T.to,$),...w({l:tt+d("2-5"),r:tt+d("2-5")+m,t:Y-$/2,b:Y+$/2},T.to,-1).slice(1)],on:!1,card:T.to})}}else{const I=Math.min(q.get(T.from)??h,q.get(T.to)??h),j=b.x(n.gutter?z+(n.lanes[K]+1)*d("3-5"):I-d("2-5"),J),tt=b.y(st.rect.t+(st.rect.b-st.rect.t)*n.exits[K],J),Y=xt(st,"right",tt),mt=X==="end-down",nt=c.edges.map((ut,y)=>({o:ut,j:y})).filter(({o:ut,j:y})=>n.routes[y]===X&&ut.to===T.to).sort((ut,y)=>n.lanes[y.j]-n.lanes[ut.j]||ut.j-y.j),lt=Math.max(0,nt.findIndex(({j:ut})=>ut===K)),ft=U.rect.r-d("6")-lt*d("3"),yt=U.rect.r-d("6")-(nt.length-1)*d("3"),wt=b.x(ft,J),vt=mt?U.rect.t-S-lt*d("5"):U.rect.b+S+lt*d("5"),St=b.y(vt,J);Z=[Y,{x:j,y:Y.y},{x:j,y:St},{x:wt,y:St},xt(U,mt?"top":"bottom",wt)];const pt=mt?T.to:O[U.i+1]?.id??T.to;Q&&E.push({k:K,cands:[...mt?dt({l:yt-d("2-5")-m,r:yt-d("2-5"),t:vt-$/2,b:vt+$/2},pt,$):[{l:yt-d("2-5")-m,r:yt-d("2-5"),t:vt-$/2,b:vt+$/2}],...w({l:yt-d("2-5")-m,r:yt-d("2-5"),t:vt-$/2,b:vt+$/2},pt,mt?-1:1).slice(1)],on:!1,card:pt})}const B=Te(Z,J,b);k.lines.push({i:K,from:T.from,to:T.to,kind:T.kind,pts:B,tip:B[B.length-1],dir:ce(B),width:J})}),k.crossings=Pt(k.lines),k.through=ue(k.lines,f,c),k.outside=Xe(k.lines,h,g,l);const{obstacles:R}=Ke(s,r,a,0);R.heads=k.lines.map(T=>De(T,l));const C=[],W={l:0,t:0,r:h,b:g};for(const T of E){const K=U=>{const J=le(U,d("1"));return U.lW.r+.5||U.tW.b+.5||f.some(Z=>je(J,Z))||C.some(Z=>It(J,Z))||R.heads.some(Z=>It(J,Z))||R.rects.some(Z=>It(J,Z))||k.lines.some(Z=>Z.i!==T.k&&qt(Z.pts).some(([Q,m])=>It(J,Ge(Q,m,Z.width))))},X=T.cands.find(U=>!K(U));X||(M[T.card]=(M[T.card]??0)+1,k.unseated.push(T.k));const st=X?Ve(X,i,u,U=>!K(U)):T.cands[0];C.push(st),k.labels.push({i:T.k,text:c.edges[T.k].label,box:st,on:T.on})}return{geo:k,grow:M}}function Ye(t,e,n=0){const o=a=>String(Math.round(a*100)/100);let c=`M${o(t[0].x)} ${o(t[0].y)}`;for(let a=1;a{const{crow:G,ring:R}=Ie(N,D.x,D.y,dt,n.head,n.dot);return`${R?``:""}`};return`${O(e.card.from,w,Math.sign(q.x-w.x)||1,"from")}${O(e.card.to,e.tip,-l.x||1,"to")}`}const a=e.kind==="dashed",s=n.head,r=n.head/2,d=a?1:s-1,p=e.pts.map(w=>({...w})),f=p[p.length-1];f.x-=l.x*d,f.y-=l.y*d;const i=e.tip.x-l.x*s,u=e.tip.y-l.y*s,b=-l.y*r,h=l.x*r,g=w=>Math.round(w*100)/100,k=bt(e.kind),M=a?``:``,z=e.dot?``:"";return`${M}${z}`}function Qe(t,e,n,o){const c=new Map,l=new Map;for(const s of e.crossings)l.has(s.under)||l.set(s.under,[]),l.get(s.under).push(s);let a="";for(const[s,r]of l){const d=`${o}-cut-${s}`;c.set(s,d);const p=r.map(f=>{const i=e.lines[f.top],u=e.lines[f.under],b=i.width/2+n.cut,h=u.width/2+1;return f.underVertical?``:``}).join("");a+=`${p}`}return{defs:a,ids:c}}function Pe(t,e,n,o){const{defs:c,ids:l}=Qe(t,e,n,o),a=e.lifelines.map(i=>``).join(""),s=(e.bars??[]).map(i=>``).join(""),r=e.lines.map((i,u)=>Zn(t,i,n,l.get(u)??null,i.from===i.to?n.radiusXs:n.radius)).join(""),p=`${a?`${a}`:""}${c?`${c}`:""}${s}${r}`,f=e.labels.map(i=>`1?' data-lines="2"':""} style="left:${Math.round(i.box.l*100)/100}px;top:${Math.round(i.box.t*100)/100}px;width:${Math.round((i.box.r-i.box.l)*100)/100}px">${i.text.split(` +`).map(bt).join("
")}
`).join("");return p+f}function he(t,e,n,o,c,l,a,s){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:c,geo:null,ink:"",tokens:null};const p=Rn(t),f=Wn(d,n),i=Fn(e,p,f);s?.(i.least);const u=t.clientWidth,b=(()=>{const E=document.activeElement;return E&&d.contains(E)&&E.dataset.node?E.dataset.node:void 0})(),h=E=>Rt(e,E)?{...E,stop:E.stop&&e.byId.has(E.stop)?E.stop:e.nodes[0]?.id,keep:void 0}:{...E,stop:E.stop??e.nodes[0]?.id,keep:b&&E.layout!=="drawn"?b:void 0};let g=!1;const k=E=>{if(g=!1,e.type!=="flowchart")return E;l({...E,heights:void 0,words:void 0});const G=Lt(),R=Lt();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(C=>{const W=C.querySelector(`.${n}-words`);if(!W)return;const T=C.getBoundingClientRect(),K=U=>{const J={w:U.width+2*p.space("2-5"),h:U.height+2*p.space("2")},Z=1-J.w/T.width,Q=Z>.05?J.h/2/Z:J.h*10;return Math.max(p.space("16"),Math.ceil(T.width/5),Math.ceil(2*Q))},X=W.getBoundingClientRect();let st=K(X);if(st>T.width){const U=m=>(C.style.setProperty("--_ww",`${m}px`),W.getBoundingClientRect()),J=Math.floor(C.clientWidth-2*p.space("2-5"));let Z=Math.ceil(X.width),Q=X.height;for(;Z1;){const I=m+$>>1;U(I).heightT.width&&(g=!0)}),{...E,heights:G,words:Object.keys(R).length?R:void 0}},M=()=>({m:e,tk:p,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:a}),z=c.autoOpen?{open:!1,autoOpen:void 0}:{},w=(E,G)=>G.map(R=>Dt(e,E.lines.find(C=>C.i===R))).join(", ");if(e.text)return{dyn:{...c,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:p,least:i.least};if(u>=i.least&&!e.unplaced){const E=W=>{let T=h({...c,...z,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:W||void 0,rows:void 0});T=k(T),l(T);let K=Ze(M(),f);return K.corridors&&(T={...T,rows:K.corridors.rows},l(T),K=Ze({...M(),pick:K.corridors.pick},f)),{dd:T,g:K}};let{dd:G,g:R}=E(!1);const C=W=>W.through.length>0||W.outside.length>0||(W.overlaps?.length??0)>0||(W.misfit?.length??0)>0||g;if(!C(R)&&R.unseated.length&&R.unseated.every(W=>R.bounded?.includes(W))){const W=E(!0);!C(W.g)&&!W.g.unseated.length&&({dd:G,g:R}=W)}if(!C(R)&&!R.unseated.length)return R.crossings.length&&a?.(`${R.crossings.length} crossing${R.crossings.length===1?"":"s"} in the drawn layout: ${R.crossings.map(W=>`${Dt(e,R.lines[W.top])} over ${Dt(e,R.lines[W.under])}`).join("; ")}`),{dyn:G,geo:R,ink:Pe(n,R,p,o),tokens:p,least:i.least};g&&a?.(`the drawn layout does not fit at ${Math.round(u)}px: a decision would be taller than it is wide`),R.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(u)}px: ${R.misfit.join("; ")}`),R.through.length&&a?.(`the drawn layout does not fit at ${Math.round(u)}px: ${w(R,R.through)} would pass through a node`),R.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(u)}px: ${w(R,R.overlaps)} would lie on one another`),R.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(u)}px: ${w(R,R.outside)} would leave the drawing`),R.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(u)}px: no clean seat for ${R.unseated.map(W=>e.type==="sequence"?`message ${W}`:`"${_t(e.edges[W]?.label??"")}"`).join(", ")}`)}let q=h({...c,...z,layout:"stacked",heights:void 0,grow:Lt(),track:e.type==="schema"?i.table:void 0,bare:void 0,pad:void 0,rows:void 0});if(q=k(q),l(q),e.type==="sequence"||e.type==="schema")return{dyn:q,geo:null,ink:"",tokens:p,least:i.least};const O=Le(e);let N=Ue(M(),f,O,q.grow);for(let E=0;E<6&&Object.keys(N.grow).length;E++){const G=Lt(q.grow);for(const[R,C]of Object.entries(N.grow))G[R]=(Ot(G,R)??0)+C;q={...q,grow:G},l(q),N=Ue(M(),f,O,G)}const D=N.geo;if(!O.third&&O.laneCount>2&&a?.(`the stacked drawing uses ${O.laneCount} end lanes (four at most)`),D.unseated.length>0||D.through.length>0||D.outside.length>0||O.third){D.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(D.unseated)].map(R=>`"${_t(e.edges[R]?.label??"")}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),D.through.length&&a?.(`in the stacked drawing ${w(D,D.through)} would pass through a node, so its lines are not drawn`),D.outside.length&&a?.(`in the stacked drawing ${w(D,D.outside)} would leave the drawing, so its lines are not drawn`),O.third&&a?.("the stacked drawing would need a fifth end lane, so its lines are not drawn","error");const E={...D,lines:[],labels:[],crossings:[]},G=h({...q,grow:Lt(),bare:!0,open:c.bare?c.open:!0,autoOpen:c.bare?c.autoOpen:c.open?void 0:!0});return l(G),{dyn:G,geo:E,ink:"",tokens:p,least:i.least}}return D.crossings.length&&a?.(`${D.crossings.length} crossing${D.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${D.crossings.map(E=>`${Dt(e,D.lines[E.top])} over ${Dt(e,D.lines[E.under])}`).join("; ")}`),{dyn:q,geo:D,ink:Pe(n,D,p,o),tokens:p,least:i.least}}function Dt(t,e){const n=t.byId.get(e.from)?.name??e.from,o=t.byId.get(e.to)?.name??e.to;return`${n} to ${o}`}function Jn(t,e,n,o,c,l){const a=new Set;if(l){a.add(l);for(const h of n?.lines??[])h.from===l&&a.add(h.to),h.to===l&&a.add(h.from)}if(t.toggleAttribute("data-tracing",!!l),t.querySelectorAll(`.${e}-node`).forEach(h=>h.toggleAttribute("data-near",a.has(h.dataset.node))),!n||!o)return;const s=h=>!!l&&(h.from===l||h.to===l),r=t.querySelector(`.${e}-edges`),d=new Map;t.querySelectorAll(`.${e}-edge`).forEach(h=>d.set(h.getAttribute("data-edge"),h));for(const h of n.lines){const g=d.get(String(h.i));g&&(g.toggleAttribute("data-lit",s(h)),g.toggleAttribute("data-dim",!!l&&!s(h)))}if(t.querySelectorAll(`.${e}-label`).forEach(h=>{const g=n.lines.find(k=>String(k.i)===h.dataset.edge);h.toggleAttribute("data-lit",!!(g&&s(g)))}),r){for(const h of n.lines)if(s(h)){const g=d.get(String(h.i));g&&r.appendChild(g)}}const p=Pt(n.lines,s),{defs:f,ids:i}=Qe(e,{...n,crossings:p},o,c),u=t.querySelector(`.${e}-svg`);if(!u)return;let b=u.querySelector("defs");!b&&f&&(b=document.createElementNS("http://www.w3.org/2000/svg","defs"),u.insertBefore(b,u.firstChild)),b&&(b.innerHTML=f),n.lines.forEach((h,g)=>{const k=d.get(String(h.i))?.querySelector(`.${e}-line`);if(!k)return;const M=i.get(g);M?k.setAttribute("mask",`url(#${M})`):k.removeAttribute("mask")})}var Xn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function Un(t,e){const n=t.getAttribute("data-entrance");if(!(n==="running"||n==="done")){if(!e){n&&t.removeAttribute("data-entrance");return}n||t.setAttribute("data-entrance",Xn()||Qn(t)?"done":"pending")}}var Yn=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function Qn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(Yn(t))!==null}catch{return!1}}function tn(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function Pn(t,e,n,o=!1,c=!1){const l=o?Jt(t):null;if(l&&n.startsWith("Arrow")){const d={ArrowRight:c?"left":"right",ArrowLeft:c?"right":"left",ArrowDown:"down",ArrowUp:"up"}[n];return d?l[e]?.[d]??null:null}const a=t.byId.get(e)?.i??0,s=t.nodes.length;let r;if(n==="ArrowRight"||n==="ArrowDown")r=a+1;else if(n==="ArrowLeft"||n==="ArrowUp")r=a-1;else if(n==="Home")r=0;else if(n==="End")r=s-1;else return null;return t.nodes[Math.max(0,Math.min(s-1,r))].id}var to=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],en=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl","data-cols","data-reach","data-gutter","data-marks"],eo=["--_track","--_h","--_ww","--_gap","--_ggrow","--_tl","--_gpad","--_gw","--_mh","--_rows","--_row-gap"],nn=t=>t==null||t===!1;function no(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const n=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!n||t.classList.contains(n)}function te(t,e,n=!0){if(typeof e=="string"||"slot"in e)return;const o=n?en:to;for(const a of o)nn(e.a[a])&&t.removeAttribute(a);for(const[a,s]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const d=t.style,p=new Map(String(s??"").split(";").map(f=>{const i=f.indexOf(":");return[f.slice(0,i).trim(),f.slice(i+1).trim()]}).filter(([f])=>f));for(const[f,i]of p)d.getPropertyValue(f).trim()!==i&&d.setProperty(f,i);for(const f of eo)p.has(f)||d.removeProperty(f);continue}if(n&&!en.includes(a))continue;if(nn(s)){t.removeAttribute(a);continue}const r=s===!0?"":String(s);t.getAttribute(a)!==r&&t.setAttribute(a,r)}if(e.t==="svg"||typeof e.a.class=="string"&&/-(ink|ruler)$/.test(e.a.class)||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const c=[...t.children];let l=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let s=l;st.querySelector(`.${e}-node[data-node="${CSS.escape(l)}"]`);n&&c(n)?.setAttribute("tabindex","-1"),c(o)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,n="diagram",o=0;function c(i,u,b){return{prefix:n,base:i,hasSource:u.source!==void 0&&u.source!==null&&u.source!=="",hiddenClass:"visually-hidden",viewer:b?b.keys:void 0}}function l(i,u,b,h){var g=function(k){return''+bt(k)+""};return{source:bt(String(u.source||"")),summary:bt(String(u.summary||"")),hint:re(i).map(function(k){return""+k.keys.map(g).join(" ")+" "+bt(k.words)+""}).join(""),toggle:'"}}function a(i,u,b){for(var h=i.layout==="auto"&&(i.type==="architecture"||i.type==="flowchart"||i.type==="schema"),g=h?Array.isArray(i.placement)?i.placement:i.placement?[i.placement]:[]:[],k=i.direction||(i.type==="flowchart"?"down":"right"),M=null,z=0;z");return{open:O.slice(0,N+1),inner:O.slice(N+1,O.length-9),warnings:w.errors.map(function(D){return"error: "+D}).concat(w.warnings)}}var s=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-marks","data-layout","data-measured","data-bare"],r=["--_cols","--_gpad","--_track"];function d(i,u,b,h){i.__diagram&&i.__diagram.stop();var g=(i.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),k=getComputedStyle(i).direction==="rtl",M=u.layout==="auto"&&(u.type==="architecture"||u.type==="flowchart"||u.type==="schema"),z=M?Array.isArray(u.placement)?u.placement:u.placement?[u.placement]:[]:[];M&&!z.length&&console.warn('Basalt diagram: "layout": "auto" needs a placement, which compose.mjs writes at build time; drawn from script, place it with placeDiagram (@srasyndicate/basalt/diagram-layout) and pass "placement". The figure is stacked');var w=u.direction?[u.direction]:u.type==="flowchart"?["down","right"]:["right","down"],q=function(F){for(var V=0;V .diagram-drawing")){if(!g||!i.querySelector("#"+CSS.escape(g+"-title"))){for(;document.getElementById("dg"+ ++o+"-title"););g="dg"+o}var N=a(u,g,h),D=document.createElement("div");D.innerHTML=N.open+"";var dt=D.firstChild;s.forEach(function(F){i.removeAttribute(F)}),r.forEach(function(F){i.style.removeProperty(F)});for(var E=0;E :not(script[data-diagram])").forEach(function(F){F.remove()}),i.insertAdjacentHTML("beforeend",N.inner)}O.warnings.forEach(function(F){console.warn("Basalt diagram: "+F)}),O.errors.forEach(function(F){console.error("Basalt diagram: "+F)}),O.motion.animated&&O.motion.firstVisit&&!i.id&&console.error('Basalt diagram: "entrance": "first-visit" needs an id on the figure: without one the entrance plays on every visit');var R=c(g,u,h),C={},W=null,T=null,K=null,X=null,st=Object.create(null),U=function(F,V){st[F]||(st[F]=1,(V==="error"?console.error:console.warn)("Basalt diagram: "+F))},J=function(F){te(i,Ut(O,F,R))},Z=i.querySelector(".diagram-ink"),Q=i.querySelector(".diagram-toggle"),m=!h&&O.motion.animated&&typeof e.diagramMotion=="function",$=null,S=null,B=function(){m&&tn(i)};function I(){Jn(i,n,W&&W.geo,W&&W.tokens,g,T||X||K),Y()}var j=null,tt=!h&&matchMedia("(hover: none), (pointer: coarse)").matches;function Y(){var F=tt&&!h&&Z&&Z.innerHTML!=="";if(i.toggleAttribute("data-touch",!!(tt&&!h)),F&&!j){var V=i.querySelector(":scope > .diagram-foot");if(!V)return;j=document.createElement("button"),j.type="button",j.className="btn diagram-clear",j.setAttribute("data-variant","secondary"),j.setAttribute("data-size","sm"),j.innerHTML="Clear highlight",j.addEventListener("click",function(){X&&(X=null,I())}),V.appendChild(j)}else!F&&j&&(j.remove(),j=null);j&&j!==j.parentNode.lastElementChild&&document.activeElement!==j&&j.parentNode.appendChild(j),j&&(X?j.removeAttribute("aria-disabled"):j.setAttribute("aria-disabled","true"))}function mt(F){if(!F.defaultPrevented){var V=yn(i,n,F,X);V!==void 0&&(B(),tt=!0,X=V,I())}}function nt(){Q&&(Q.setAttribute("aria-expanded",String(!!C.open)),Q.firstElementChild.textContent=C.open?"Hide the list":"View as list")}function lt(){if(M&&z.length>1&&!h){for(var F=null,V=[],et=!1,at=0;at1&&h&&!u.direction&&h.room){for(var ee=h.room(),Gt=-1,pe=null,ge=0;geGt+1e-6&&(Gt=an,pe=me)}}}pe&&(O=pe)}W=(h?h.measure:he)(i,O,n,g,C,J,U),C=W.dyn,J(C),nt();var ye=i.querySelector(":scope > .diagram-hint");if(ye){var sn=re(O,C.layout==="drawn").map(function(At){return""+At.keys.map(function(ro){return''+bt(ro)+""}).join(" ")+" "+bt(At.words)+""}).join("");ye.innerHTML!==sn&&(ye.innerHTML=sn)}Rt(O,C)||(K=X=null);var rn=Z&&W.ink!==S;rn&&(Z.innerHTML=W.ink,S=W.ink),I();var so=O.text?i.querySelector(".diagram-text[data-art]"):null;O.text&&typeof e.diagramText=="function"&&e.diagramText(i,O,u,h);var ln=O.text?i.querySelector(".diagram-text[data-art]"):null;m&&W.tokens&&(Un(i,!!(W.geo&&W.geo.lines.length)||!!ln),(rn||ln!==so)&&$&&$.redrawn()),h&&h.onMeasured&&W.tokens&&h.onMeasured(W,i)}function ft(F){C=F,J(C)}function yt(F){var V=C.stop;C=Object.assign({},C,{stop:F}),oo(i,n,V,F)}var wt=function(F){var V=F&&F.closest?F.closest(".diagram-node"):null;return V&&i.contains(V)?V:null};function vt(F){var V=wt(F.target);if(!(!V||F.defaultPrevented)){if(B(),F.key==="Escape"){!h&&(T||K||X)&&(F.preventDefault(),T=K=X=null,I());return}if(Rt(O,C)){var et=Pn(O,V.getAttribute("data-node"),F.key,C.layout==="drawn");if(et){F.preventDefault(),yt(et);var at=i.querySelector('.diagram-node[data-node="'+CSS.escape(et)+'"]');at&&at.focus()}}}}function St(F){var V=wt(F.target);if(V){B();var et=V.getAttribute("data-node");T=V.matches(":focus-visible")?et:null,Rt(O,C)&&C.stop!==et&&yt(et),I()}}function pt(F){var V=wt(F.target);V&&(wt(F.relatedTarget)||(T=null),C.keep===V.getAttribute("data-node")&&ft(Object.assign({},C,{keep:void 0})),I())}function ut(F){if(!(F.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var V=wt(F.target);V&&B();var et=V&&Rt(O,C)?V.getAttribute("data-node"):null;et!==K&&(K=et,I())}}function y(){K&&(K=null,I())}function A(){B(),ft(Object.assign({},C,{open:!C.open,autoOpen:void 0})),nt()}i.addEventListener("keydown",vt),i.addEventListener("focusin",St),i.addEventListener("focusout",pt),i.addEventListener("pointerover",ut),i.addEventListener("pointerleave",y),i.addEventListener("click",mt),Q&&Q.addEventListener("click",A),lt();var _=i.clientWidth,x=0,L=!0,H=new ResizeObserver(function(){Math.abs(i.clientWidth-_)<.5||(_=i.clientWidth,cancelAnimationFrame(x),x=requestAnimationFrame(lt))});H.observe(i),document.fonts&&document.fonts.ready.then(function(){L&<()});var P=matchMedia("(forced-colors: active)"),ot=O.nodes.some(function(F){return F.mark});ot&&P.addEventListener("change",lt),m&&($=e.diagramMotion(i,{fig:i,P:n,base:g,model:function(){return O},geo:function(){return W&&W.geo},tokens:function(){return W&&W.tokens}},u));var ct=!h&&u.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(i,u,{model:O,settle:B,animated:m}):null,it=i.querySelector(":scope > .diagram-foot"),rt=!h&&u.export===!0&&it&&typeof e.diagramExport=="function"?e.diagramExport(it,i):[];i.__diagram={stop:function(){ct&&ct.destroy(),rt.forEach(function(F){F.remove()}),L=!1,H.disconnect(),cancelAnimationFrame(x),ot&&P.removeEventListener("change",lt),$&&$.destroy(),i.removeEventListener("keydown",vt),i.removeEventListener("focusin",St),i.removeEventListener("focusout",pt),i.removeEventListener("pointerover",ut),i.removeEventListener("pointerleave",y),i.removeEventListener("click",mt),j&&j.remove(),Q&&Q.removeEventListener("click",A)},layout:lt,key:p(u),send:$&&$.sendValue?$.sendValue:null}}function p(i){try{return JSON.stringify(i,function(u,b){return u==="packet"&&b&&typeof b=="object"?Object.assign({},b,{send:void 0}):b})}catch{return null}}function f(){document.querySelectorAll("figure.diagram").forEach(function(i){if(!i.__diagram){var u=i.querySelector(":scope > script[data-diagram]");if(u)try{d(i,JSON.parse(u.textContent),!0)}catch(b){console.error("Basalt diagram: this figure could not be drawn",b)}}})}e.diagramMarkup=a,e.diagramKit={draw:d,buildModel:Nt,figureKey:Mn,figureList:On,hintEntries:re,toHtml:oe,escapeHtml:bt,settleEntrance:tn,measureFigure:he},t.diagram=function(i,u){var b=i.__diagram,h=b&&b.send?p(u):null;if(h!==null&&h===b.key){b.send(u.packet?u.packet.send:void 0);return}d(i,u)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index 510d6fbe..d898d106 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -1,5 +1,5 @@ { - "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused). Raised in diagram batch B's fix round (DECISIONS 318, the owner's diagram raise; and 326's sweep), each to its measured size: diagram 137700 to 144100 (the two reviews' fixes in the shared engine: right to left frames and self-calls, the corridors' and lanes' development words, the unusable-placement check, the transcript's hanging lines, the text art's frame widening, the frame-side fit check, the sequence's layers, the stacked group's turn room), diagram-motion 28450 to 30450 (the text sequence's build by ink and its colour-only run, moved into the motion module), diagram-zoom 17000 to 17600 (a linked card closes the viewer; the text art's own width; a placed model for the key hint), diagram-export 7850 to 10450 (an export at rest: sized drawing SVGs, no reveal masks, the pseudo-element rules, the lines under the cards, a viewer's figure read at 100% with its head and key, the rim's lit top).", + "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused). Raised in diagram batch B's fix round (DECISIONS 318, the owner's diagram raise; and 326's sweep), each to its measured size: diagram 137700 to 144100 (the two reviews' fixes in the shared engine: right to left frames and self-calls, the corridors' and lanes' development words, the unusable-placement check, the transcript's hanging lines, the text art's frame widening, the frame-side fit check, the sequence's layers, the stacked group's turn room), diagram-motion 28450 to 30450 (the text sequence's build by ink and its colour-only run, moved into the motion module), diagram-zoom 17000 to 17600 (a linked card closes the viewer; the text art's own width; a placed model for the key hint), diagram-export 7850 to 10450 (an export at rest: sized drawing SVGs, no reveal masks, the pseudo-element rules, the lines under the cards, a viewer's figure read at 100% with its head and key, the rim's lit top). Raised at the batch B re-check (the decider's four rulings): diagram 144100 to 145100 (5.1's first list reported as errors apart from the warnings, a turn's label lines on the group entered by it and the seats beside its turn, the bare stack applied, the text art's reset of the core's inline code chip).", "budgets": { "skillMd": 12950, "core": 35400 @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 144100, + "budget": 145100, "usage": 4600, "builds": [ "kbd" diff --git a/packages/react/test/export-sizes.json b/packages/react/test/export-sizes.json index 8fc7c27a..62fd6c94 100644 --- a/packages/react/test/export-sizes.json +++ b/packages/react/test/export-sizes.json @@ -18,7 +18,7 @@ "AppHeader": 1285, "AppShell": 103887, "AppTile": 1112, - "ArchitectureDiagram": 99677, + "ArchitectureDiagram": 100938, "ArrowDownGlyph": 2868, "ArrowLeftGlyph": 2869, "ArrowRightGlyph": 2859, @@ -70,7 +70,7 @@ "CopyGlyph": 2884, "Countdown": 3016, "CoverageStrip": 1570, - "DataFlowDiagram": 99620, + "DataFlowDiagram": 100883, "DateAge": 2527, "DescriptionColumns": 216, "DescriptionItem": 593, @@ -105,7 +105,7 @@ "Fieldset": 6390, "FilterResult": 698, "FilterToolbar": 774, - "FlowchartDiagram": 99641, + "FlowchartDiagram": 100904, "Form": 8730, "FormGrid": 438, "FormGridItem": 628, @@ -224,7 +224,7 @@ "RunsGlyph": 3128, "STATUS_MESSAGE_MS": 26, "SandboxesGlyph": 2963, - "SchemaDiagram": 99589, + "SchemaDiagram": 100852, "SearchDialog": 88277, "SearchField": 18301, "SearchGlyph": 3181, @@ -243,7 +243,7 @@ "SelectableList": 821, "SelectionBar": 25913, "Separator": 4531, - "SequenceDiagram": 99617, + "SequenceDiagram": 100880, "SettingsGlyph": 3100, "ShareBar": 1411, "Sheet": 70793, @@ -412,11 +412,11 @@ "useWaitMark": 303 }, "package": { - "bytes": 902562, - "gzip": 300934 + "bytes": 903845, + "gzip": 301378 }, "styles": { - "bytes": 413315, - "gzip": 53590 + "bytes": 413471, + "gzip": 53614 } } diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index 510d6fbe..d898d106 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -1,5 +1,5 @@ { - "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused). Raised in diagram batch B's fix round (DECISIONS 318, the owner's diagram raise; and 326's sweep), each to its measured size: diagram 137700 to 144100 (the two reviews' fixes in the shared engine: right to left frames and self-calls, the corridors' and lanes' development words, the unusable-placement check, the transcript's hanging lines, the text art's frame widening, the frame-side fit check, the sequence's layers, the stacked group's turn room), diagram-motion 28450 to 30450 (the text sequence's build by ink and its colour-only run, moved into the motion module), diagram-zoom 17000 to 17600 (a linked card closes the viewer; the text art's own width; a placed model for the key hint), diagram-export 7850 to 10450 (an export at rest: sized drawing SVGs, no reveal masks, the pseudo-element rules, the lines under the cards, a viewer's figure read at 100% with its head and key, the rim's lit top).", + "$comment": "Which parts of the skill's CSS and JS a page gets. The core is always in. A module is in when the page's body has one of its classes, attributes or tags, matches one of its text patterns, or is named in a comment, and when another module needs it (requires). Modules are added in the order listed here, which is the order of the source files' cascade. classes: every class the module's CSS styles (the test checks them against the CSS and against SKILL.md). budget: the most bytes its minified CSS and JS may reach together. budgets: skillMd (SKILL.md, the context an agent pays: never above what it was), core (the CSS and JS of every page). icons: Phosphor names the module's script draws itself. Raised in the first parity PR (the owner's \"bring up the parity\"): forms (the number-input, search-clear and file-input chrome), disclosure (the native details marker), status (the accent reader and the forced-colours badge border), spinner (a fixed 16px ring), and the new number, range and accent modules. skillMd rose 10555 to 10900 for the new rules (number field, native chrome, the braille rule, the accent). Raised in the second parity PR (popup rows, levels and the segment's pill): segment 1400 to 3700 (the shared sliding pill: its script, 1.5 KB, and its CSS with the pill's two fallbacks), rows 3600 to 4300 (#27's plate-in-a-row geometry, the plate per level, the glide's shared plate and the forced-colours lit row, net of the removed bar), palette 9400 to 11300 (the glide's script, 2.4 KB: it follows the lit row, travels on a pointer, snaps on a key, and fades in place on leaving). The art module (DECISIONS 101 and 104) is the token groups only some pages name, taken out of the core so the core stays under its cap: the chart roles and lengths, the art colours, the aspect ratios and the stage headroom, in both themes (2087 bytes at 2100; it grows only when a token of those groups is added). A page gets it when its body names one of them, a var() in its own style included. The every-module page has no cap of its own (owner, DECISIONS 79): each part is capped, and a page carries only the parts it uses. usage: the most bytes of a module's usage text (src/usage/NAME.md; core.usage for core.md), which compose.mjs --usage prints on demand. It is context an agent pays only for the modules its page uses, so it is capped per part as SKILL.md and the CSS and script are (DECISIONS 79 and 109). Each is set a little above what its text was when the usage moved out of SKILL.md (DECISIONS 109); raising one needs a reason in the PR, and a rise of 40 to 50% is the owner's. textWords: each text pattern said in words, which compose.mjs --usage prints instead of the regular expression (one for each entry of text, in order). builds: modules a module requires whose markup its script writes, so --usage prints a line saying so instead of their usage text (the palette builds its own rows and key chips). The council's clarity check of the usage texts (all three: not yet clear) raised eight caps because the texts gained what an agent had to guess: callout 200 to 700 (the icon and one wrapper div around the title and body as markup, the four status icons, the role React's Callout renders), palette 1100 to 1300 (an item shown whole, keys as an array, keywords), stats 450 to 800 (a snippet of the figures and of the dl), tabs 500 to 650 (the unselected panels), code 250 to 450 (the markup and what each token class means), segment 150 to 300 (a click does not switch it), progress 150 to 350 (the empty span that paints the fill), theme 250 to 400 (leave the button empty), and accent 250 to 300. Topbar went down, 700 to 500, as its build detail was cut. Raised in the usage PR (the council's clarity check): palette 11300 to 11450 (the module grew 11283 to 11448, +165, about 1.5%), for the guard that makes a string `keys` warn and draw no chip instead of throwing in `keys.filter`, which the palette's usage already promised. Round 2 of the clarity check: tabs 650 to 750 (the panel's top space shown in the snippet, and that the script selects a tab on click). Raised in the site-icons and status PR (skill-parity part A, DECISIONS 106 and 107): status 1650 to 1900 (the neutral, pending and running marks, the badge's real border, and the forced-colours disc, net of the red danger word it drops) and its usage 400 to 1000 (every status in words, the word alone, running, forced colours); rows 4300 to 4450 (the profile list's seat rule and the status parts on a lit row) and its usage 300 to 600 (the profile list, with the one mistake: never an empty element for the seat). New: the links module (2671 bytes: the social row, the new-tab arrow's CSS and the script that draws it; budget 2750) and its usage (1746 bytes; cap 1850), which carries the social link, the glyph set, icon only and the new tab. Dropping Regular halves icons.json. Added in the overlay PR (skill-parity-4, batch 7 step 2, DECISIONS 108): the shared plate leaves palette.js for a glide module (the palette, a menu and the notification centre all call it), so the palette's cap went down, 11450 to 9250, and rows 4450 to 3850 (the plate's CSS moved to glide); and the overlay layer comes in as seven modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: popover (the native popup shell), menu, dialog (the dialog and alert dialog), sheet (on every side, the top one the site header's narrow menu), tooltip, toast and notifications (the centre). skillMd is unchanged in its cap (the eight new index lines fit within it); the core is unchanged in bytes. Added in the figures and charts PR (skill-parity-5, batch 7 step 3, DECISIONS 108): four modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: meter (React's Meter, CSS only, 2581 bytes), dlist (the description list, CSS only, 1265), terminal (the code block's transcript: its CSS, 3242, and the script that draws the gutter, the copy button and the replay, 4824) and chart (React's TimeChart and ChartGroup: 7313 of CSS and 23262 of script, which port chart.tsx's scale, layout, lane, labels, sentences, keyboard and table; it needs the art tokens, the table and the kbd chips, and a page without a chart carries none of it). Stats grew for the source line (budget 700 to 850, 798 bytes; its usage 800 to 950, 675 to 899 bytes, +33%, under the owner's 40 to 50%). skillMd is unchanged in its cap (four index lines fit within it); the core is unchanged in bytes. Added in the forms and selection PR (skill-parity-6, batch 7 step 4, DECISIONS 108): six modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: select (React's Select: the native select's closed trigger in every browser and, where `appearance: base-select` is shipped, the styled list with its two-line rows; a small script that says which input lit a row, 7740 bytes before it, choice (Checkbox, Radio, RadioGroup and Switch as styled native inputs; CSS only, with the first-frame rule), choice-card (ChoiceCard; CSS only), toggle (the pressed toggle's plate and check seat on .btn; CSS only), selection (a table's checkbox column: its fixed width and the script that sets aria-selected, the mixed header box and the count) and loops (the page-level hold on every loop with its switch: the held look and the script that stores it). The select's styles left forms, whose budget fell 3650 to 3250. skillMd rose 8621 to the size of its six new index lines, within its cap; the core is unchanged in bytes; compose adds the stored-hold line to the head of a page that has the loops module. Revised in the same PR (the lead's review of the build): the select gains select.js (one row is lit at a time, by whichever of the pointer and the keys moved last), and choice, toggle, selection and loops carry the first-frame rule, so a state a script sets on load (a mixed header box, the stored hold) paints at once with no crossfade. Added in the navigation and layout PR (skill-parity-7, batch 7 step 5, DECISIONS 108): five modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: glyph (Basalt's core glyphs drawn by name, at rest and selected, from a table the build works out from the drawn set; a page carries only the glyphs it names, and the drawing of a core glyph from data-glyph left the sheet module, which draws none now), nav (React's Nav: the sidebar's, the narrow menu's and More's rows, with the shared hugging pill), topbar-nav (the site header's links, one action and narrow menu, built by script from the bar's markup), app-shell (the shell, its sidebar and rail, and the app header) and tab-bar (the phone tab bar). The topbar module became the site header's bar (React's SiteHeader, DECISIONS 108: 56px with its line inside, the 44 by 44 brand target, the narrow-screen buttons, the derived sticky offset), budget 1600 to 3200 because its rules gained the app header's shared smoke, and its usage 500 to 750 (+50%) for the lockup's markup (the links, action and menu are topbar-nav's usage). Glide 3700 to 3950: the navigation's pill is a shape inside the row that the plate follows (about 200 bytes). The core's usage 2000 to 2100 (+5%): h2 is the Section step, the prose column's measure, and a link already 44px tall needs no margin. skillMd rose 9317 to 9863 for five index lines, under its cap; the core CSS grew 38 bytes (the layout tokens replace raw lengths, the gutter is one derived property, h2, .prose and .lead follow foundations) and the core script is unchanged. A module's media query writes %bp-md%, %bp-lg% or %bp-container% and the build substitutes the breakpoint tokens. Added in the tables and filters PR (skill-parity-8, batch 7 step 6, DECISIONS 108): the existing table module gains React's table additions (DECISIONS 95: the row header, \"Not observed\", the row density and the scroll hint with its small script), budget 1400 to 3000 (it was 1134 bytes of CSS; it is 2168 of CSS and 693 of script) and its usage 700 to 950 (+36%); and two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: still-table (React's Table with `columns`: the fixed layout from a colgroup, the whole header cell as the sort button with its reserved seat, aria-sort, the pinned columns and their divider, the empty row; 4767 of CSS and 3264 of script, budget 8200) and filter (React's MultiSelect and FilterResult: the chips, the trigger and checklist with the search band from ten values, Clear held in place, the one debounced result line, and the narrowing of a table by `data-column`; 8240 of CSS and 7978 of script, budget 16400; it needs the popover, glide, glyph and choice modules). The core is unchanged in bytes. skillMd rose 9863 to 10128 for two index lines and the CaretUpDown icon's name, within its cap. Added in the commands PR (skill-parity-9, batch 7 step 7, DECISIONS 103 and 108): one new module a page carries only when it uses it, command-list (React's CommandList: the command panel set in the page, list plus preview, the push; it extends the palette and needs rows, kbd and glide; 5229 of CSS and 8734 of script, budget 14000, usage 2150). Two-line rows come to the existing modules: rows 3850 to 5350 (the described row's grid and description line, the push's chevron: 1481 bytes of CSS, the same rules React's menu rows carry), palette 9250 to 9900 (its rows are one function the list shares, with the description and the two-tier ranking of title matches over keyword and description matches; +636) and its usage 1300 to 1350, rows' usage 600 to 800, and glide 3950 to 4000 (a host that is idle counts as having no lit row, +54). skillMd rose 10128 to 10259 for one index line, within its cap; the core's CSS grew 24 bytes (.split.aside takes size-list-width in place of its raw 20rem: the same 320px, so no pixel moves) and the core script is unchanged. Added in the art PR (skill-parity-10, batch 7 step 8, DECISIONS 104 and 108): two modules a page carries only when it uses them, each with its own cap and usage cap set a little above its size: stage (React's Stage and PairedArt: full-bleed art under the site header, the pull-up by the sticky offset, the headroom, the paired art that follows the page's theme, and the forced-colours and print rules; CSS only, 1179 bytes) and framed-art (React's FramedArt: the figure, its rim and radius, the reserved box, the placeholder and the failed alt, the caption and credit; 2208 bytes of CSS and the 733-byte script that sets the frame's phase); both need the art tokens. The bar stays smoked over a stage: React clears it only over a stage that passed the headroom test helper, and a page has no test run (DECISIONS 108's note), so the skill builds no clear state. skillMd rose 10259 to 10500 for two index lines, within its cap; the core is unchanged in bytes. The callout gained the status rim in the same PR (DECISIONS 82, D8's status callouts): success, warning and danger draw their border in the status colour at 45% mixed in sRGB over the callout's own level, one solid colour on every side, and CanvasText in forced colours with the icon; the status colour is now one property the icon and the rim read. Its budget rose 900 to 1150 (the module is 1089 bytes, from 792: +297, about 37%); its usage is unchanged. Added in the overlays-and-the-rest PR (skill-parity-11, batch 7 step 9, DECISIONS 90 and 108): the last two parts of D8's part 5, each a module a page carries only when it uses it, with its own cap and usage cap set a little above its size: combobox (React's Combobox: the input with its caret button inside, the popup of the menu's rows with the glide's shared plate and two-line options, the filtering, the keys, the hidden value, the empty message and the check; 4342 of CSS and 6423 of script, budget 10900, usage 2150; it needs forms, popover and glide, and builds the last two) and sparkline (React's Sparkline: the label and latest value, the line, the axis, the empty sentence and the loading line that breathes; 1609 of CSS and 1874 of script, budget 3600, usage 950). The combobox copies the menu's row rules, as the select's list does, because React's Combobox renders MenuItem rows (a 40px hit area, a 36px plate) and the skill's .row is the palette's 44px: it carries no menu script. popover.js gains the combobox popup in the list of popups that keep focus where it is (+21 bytes, within its cap). skillMd rose 10500 to 10724 for two index lines, within its cap; the core is unchanged in bytes. Added in the motion-rules PR (DECISIONS 136 and 139): one module, ambient (a page's one ambient loop: CSS 828 bytes, script 433, budget 1300, usage 800), taken out of loops so the hold's own module grows only by the icon toggle's glyph swap (loops 2000 to 2200, +10%; its usage 1300 to 1650 for the icon form and the new settings-row sentence, +27%); and the chart's entrance (`entrance: true`: the marks' animations, their conditions and the redraw that restarts them at the elapsed time, 23262 to 25299 bytes of script; budget 30700 to 32800, +7%, usage 2500 to 2950, +18%). The core grew by the three tokens (27704 to 27862 bytes of CSS, under its cap). its stage usage gained the ambient art's line (1650 to 1750, +6%). skillMd rose 10724 to the size of the ambient index line, within its cap. Raised again in the motion-rules amendment (DECISIONS 143): chart 32800 to 33800 (script 25299 to 26375 bytes, +4%; +10% over the 30700 it began with) for the glide a new data set makes mid-entrance, print settling it, and `Basalt.pageChange()`; its usage 2950 to 3150 (+26% over the 2500 it began with). Raised in the second motion-rules amendment (DECISIONS 148): chart 33800 to 34400 (script 26375 to 26970 bytes: a line and its markers glide from their drawn geometry, and `beforeprint` settles the entrance; +12% over the 30700 it began with); topbar-nav 6900 to 7500 (+8.7%: the narrow menu's pause row, its CSS and 275 bytes of script, DECISIONS 148 item 2); loops usage 1650 to 1800 (+38% over the 1300 it began with, for the icon form's `title` and the menu row). Raised in the audit-design-b PR (DECISIONS 138 and 139): still-table 8200 to 13400 (+63%: the module was 7927 bytes and is 13311; the cut cell's plate, its focus stops and its dismissal, ported from React's cell-peek.ts, are 4273 bytes of script and 1111 of CSS; a still table that truncates needs them). The same PR: core usage 2100 to 2250 (+7%: the skip link, one bullet), forms usage 350 to 480 (+37%: the required mark), still-table usage 1950 to 2150 (+10%: the cut cell and the width rule), notifications usage 1050 to 1100 (+5%: the 44px entry on touch). The skip link's rim and radius took the core 30457 to 30609 bytes, under its cap (the rules that hang it under the bar are the topbar module's: 3200 to 3600, +12.5%); core 30720 to 31050 (+1.1%, DECISIONS 147: also the bar's links left out of the rule: the pseudo-element that makes a short standalone link a 44 by 44 target), skip-link script in the topbar module (3200 to 4150 over this PR, +30%: the rules that hang the link under the bar, 3600, and the script that reads the bar's real edge, 4150), sparkline 3600 to 4050 (+12.5%: React's ticker structure, so the value copies once on its line, and in forced colours the strips go and the number is plain text), forms budget 3250 to 3500 (+7.7%: the necessity word), notifications 9050 to 9250 (+2.2%: the 44px entry). Raised in the audit-design-b PR's E2 port (DECISIONS 138 and 139: the core set draws check, close, the chevrons, copy, plus, minus and search wherever a component draws them): the modules that drew a Phosphor icon for one of those now carry the core glyph's whole SVG, written in at build time (`%glyph-svg:name%`, the markup the glyph module's `_.glyph(name)` returns, so no module needs the glyph module and a page pays for nothing it does not use), and the Phosphor path of the same icon leaves the page. Each module's own bytes rose by that markup, and a page's total moved by what the Phosphor path it no longer carries saves: menu 8600 to 8900 (+303), combobox 10900 to 11200 (+303), copy 1900 to 2400 (+640), terminal 8100 to 8850 (+761), toast 13850 to 14150 (+325), number 2900 to 3400 (+557), filter 16400 to 17050 (+785), palette 9900 to 10450 (+536); the command list shares the palette's search drawing and fell 20 bytes. Set in integration-nov15, where the type-layout, motion-rules and audit-design-b branches meet: the combined tree measured SKILL.md 10959 bytes (each side's cap was 10900: both added index lines), core 31192 bytes (caps 30720 and 31050: the page-row and display rules, the three motion tokens and the skip link and 44px target rules all land in the core CSS) and core usage 2348 bytes (caps 2300 and 2250: type-layout's line and the skip-link bullet), so each is set to the measured bytes rounded up to the next 50: skillMd 10900 to 11000, core 31050 to 31200, core usage 2300 to 2350. Raised in the audit-design PR (decisions 138 and 139, parts A, D and C11): core 30720 to 31600 (+2.9%: the more-contrast block and its three aliases, and the field boundary token, every page carries as React does; the shadow-pill token is gone; the script gained `reserve`, 240 bytes), segment 3700 to 4100 and tabs 2300 to 2700 (the chosen label is 600 against 400, its width reserved by a span that carries its own copy, drawn unseen at 600; the pill's drop shadow is gone), and the segment's usage 300 to 380 (the weight and the glyph-only button). Raised again in the audit-design-a amendment (decision 145): core 31600 to 32300 (reserve() also reserves a label that is not plain text), segment 4100 to 5100 and tabs 2700 to 3500 (the second copy of such a label, and an icon drawn in both its forms), glyph 1100 to 1300 (a glyph in a segment or tab is drawn in both forms). Raised in the second audit-design-a amendment (decision 149): core 32300 to 32800 (reserve() builds the second copy of a label without any id, name, reference or hidden control, and does not copy a frame or media), segment 5100 to 5400 and its usage 380 to 500 (the 600 is on the label, the one-line rule and the usage text); the still-table cap is back at 8200, as the wash is on every cell again. Return 3 of the audit-design-a build (decision 149): tabs 3500 to 3700 (a tab the script has not reserved is 600 itself when selected, and one it declined is marked; the same two lines are in segment, which stays under 5400). Raised in the audit-fix-c2 PR (engineering, no pixel changes): toast 13850 to 14350 (the module was 13789 bytes and is 14288, +499, 3.6%) for F6, which focuses the Notifications region and Shift+Tab or Escape from it (or from the first toast) leaves it for where focus came from (and keeps a dialog's focus trap from wrapping it), as Base UI's viewport does in React, and for placing the region from focus (in the modal that holds it, or in the body), so a toast is never under a backdrop or in an inert modal whatever order the modals opened in (A3-09); the palette module grew 9864 to 9897 of its 9900 so that a palette opened over a modal sits inside it; topbar 3200 to 3250 (3123 to 3233, +110) for the scroll margin on what the bar holds, so a Tab into the bar from a scrolled page does not scroll the page (React's rule from PR #66); stage usage 1650 to 1750 (1580 to 1713, +8%) for the art's new place in the markup, after the content (A1-09), the stage's own CSS rising 1179 to 1208 within its 1250. skillMd rose 10724 to 10876 for the sentence that says a body may carry head tags, within its 10900. compose.mjs, the tool an agent runs, has no cap here (it is never in a page): it grew 21673 to 38153 bytes for the tokenizer that reads a body as HTML does and the head tags. Raised in the site-parts PR (DECISIONS 146, round 39), which folds each new part into the module it belongs with, so SKILL.md gains no index line (it has 41 bytes under its cap and a new module needs about 100): topbar 4150 to 17600 (+13450: the site footer and its disclosures, the lockup by pixel density, and a bar that arrives or leaves and returns, with its observer; a page that has a .topbar and no footer carries them too: the alternative, a module for each, needs its own index line and so SKILL.md bytes) and its usage 950 to 2900 (the footer's markup, the lockup's and the phase's); theme 650 to 4550 (the three-word theme choice: its CSS 2230 bytes and its script, 2277, with arrows, storage and the system listener) and its usage 400 to 1150 (the choice's markup written in full, so the right word is chosen before any script); segment 3700 to 3800 (a radio group's checked state besides a pressed button); stage 1250 to 2150 (its first script, 768 bytes, for fit and anchor) and its usage 1750 to 2000; framed-art 3000 to 3900 (drawn art in the frame: fit, anchor, no scaling strokes) and its usage 1250 to 1400. SKILL.md rose 10959 to 10992 (the topbar and theme index lines name .site-footer and .theme-choice). The head's theme line also writes data-theme-choice. Raised in site-parts return 2 (DECISIONS 146 B1 and B4): theme 4550 to 5350 (+800: the icon form of the theme choice, [data-theme-menu], whose button shows the theme in use, is named for the choice and opens the page's own .menu of three radio rows, in the theme script's 3073 bytes; the menu and popover modules are the page's, brought by its markup, so no module line was added and SKILL.md is 10993 of 11000) and its usage 1150 to 2200 (+91%: the menu's markup is written in full, and the deprecated toggle is said once); app-shell usage 2000 to 2100 and topbar-nav usage 1900 to 1950 (the theme control leaves the bar's text; the tools and the end cluster come in). The two example bodies still carry the deprecated data-theme-toggle. Return 2, F3 (DECISIONS 146 F): stage 2150 to 2250 (script 842 bytes: slice is the stage's default, as a frame's, and a drawing's own preserveAspectRatio stands unless the stage names data-fit or data-anchor) and its usage 2000 to 2150. framed-art 3900 to 4000 (a drawing's own preserveAspectRatio stands unless the figure names data-fit or data-anchor, +101 bytes). Return 3: theme 5350 to 5900 (script +569 bytes: who wrote data-theme, so System follows the system's change live and a theme the page set by hand, or a .dark or .light root, survives it). Raised in the controls port (DECISIONS 154): skillMd 11000 to 11200 for two index lines (link-tabs and option-chips, 214 bytes together), and core 31200 to 31600 for the nine tokens the port adds to every page's token CSS (the control rungs 44 to 64, two container widths, the confirm hold and the amount's opacity, 311 bytes). New modules (DECISIONS 154): link-tabs 2700 (its sizes, the 640 container step, the forced-colours underline, and the select that replaces the row under 720 with its 590-byte script, A15; it requires the select module), option-chips 5700 (the chip's states each written for a native radio inside a label, which needs :has on every one, plus the 1 KB script that keeps an aria-disabled chip reachable and never chosen). Return 3 (DECISIONS 154 conformance): link-tabs 2700 to 3100 and its usage 1650 to 1850 (the select's height for each row size, and a script that reads aria-current when it is needed and watches it move: 3,048 bytes), option-chips 5700 to 6700 (each state written twice, as a state attribute and as :has(), so no browser needs :has(): 4,975 CSS and 1,623 script). Return 4 (DECISIONS 158, Q2): link-tabs 3100 to 4300 and its usage 1850 to 2400 (the \"Go to\" label drawn at the select's start with its measured clearance, the select's accessible name kept as the words and the chosen page's, and the key hold that keeps a letter or an arrow on the closed select from navigating: 4,174 bytes, CSS 2,951 and script 1,223). Raised in the links-and-rows port (DECISIONS 152; the owner's approval is the lead's to confirm): the new link-rows module (5050 bytes of CSS, 50 of them for Castle's big-row arrow stepping colour over duration-fast, return 1, 1500 of usage: the directory's and the big rows' CSS, whose arrow is a core glyph drawn as a mask, and their tokens, size-row taken out of the core like type-layout's), disclosure 1550 to 3500 (Show all: the track, the clip and the settle, 1.5 KB of script and 1.8 KB of CSS), copy 2400 to 3500 (the form with words: the one cell and its script). SKILL.md rose 10959 to 10997 for one line, within its 11000 cap. Raised in the charts port PR (DECISIONS 153, D7a): chart 34400 to 34650 (script 26970 to 27270 bytes, +1.1% on the 34283 it was: `Basalt.trailingMean`, the trend maths React exports as `trailingMean`, 300 bytes), its usage 3150 to 3350 (+6%: one line for it). The tokens the batch adds (chart-lit-top, -mid and -base in both themes, size-chart-plot-sm, size-chart-row, size-meter-marker and radius-2xs) took the art module 2087 to 2546 bytes (budget 2100 to 2600, +24%: the chart tokens are its group) and the core 31192 to 31250 (cap 31200 to 31300, +0.3%: radius-2xs). Only D7a names a skill module in the charts ballot; the lit marks, the headline frame, the phase chart, the share bar, the coverage strip, the marks row and the range meter are React-only in this batch. Added in the overlays-and-search PR (DECISIONS 155, D10b and D13a): the sheet gains React's head, body and foot (the 44px close, the 20/28 title over a 13px count, the divider and the safe areas; its CSS 3.6 to 5.2 KB, budget 4050 to 5250, +30%) and its usage 1050 to 1450 (+38%: the anatomy and the step's focus, two bullets); and one new module a page carries only when it uses it, search (React's SearchDialog: the form, the field's -2 outline, the count line, the fixed-height results area and the rows with their picture slots and full-bleed hover wash; CSS only, 4368 bytes, budget 4400, usage 2050; it requires the dialog). The dialog's title draws no ring when script focuses it. skillMd rose 10959 to 11079 for the search line (the sheet's line is unchanged: its usage carries the anatomy), so its cap rose 11000 to 11100 (+0.9%). The core's CSS grew 31192 to 31421 bytes for the six new size tokens (the wide dialog, the search trigger and the logo and picture slots of a search result): its cap rose 31200 to 31450 (+0.8%). The two 44px values (the sheet's close and the search field) are local to their modules, with a lint exception that says they join the controls batch's size token (DECISIONS 154). Set in integration-nov15b, where audit-design-a, audit-fix-c2, site-parts, port-controls, port-links-rows, port-charts and port-overlays-search meet: the combined tree measured SKILL.md 11560 bytes (the caps were 11000, 11100 and 11200: each side added index lines), core 34086 bytes (caps 31300 to 33550: every side's rules land in the core CSS and script), topbar 17660 (17600 from site-parts, plus audit-fix-c2's skip-link and focus work), number 3453 (3400), palette 11379 (11000, audit-fix-c2's hosted scrim plus the core search glyph), dialog 5120 (5100), toast 15692 (15400) and stage usage 2248 (2150), each over every side's cap, so each is set to the measured bytes rounded up to the next 50: skillMd 11200 to 11600, core 33550 to 34100, topbar 17600 to 17700, number 3400 to 3500, palette 11000 to 11400, dialog 5100 to 5150, toast 15400 to 15700, stage usage 2150 to 2250. The segment cap is the base's 5400 plus port-controls' 100 (5500), unchanged by the merge. Raised in integration-nov15b, join 2 (a link tab takes the selected state, DECISIONS 138 A, 145, 149 and 154's D12 row): link-tabs 4300 to 5750 (+34%: the module was 4174 bytes and is 5736; the 600 against 400, the reserved width and the second copy of a composed label, an icon drawn in both its forms, the same rules a tab carries, 1,530 bytes of CSS and script) and its usage 2400 to 2550 (+6%: one bullet). The cap is the measured bytes rounded up to the next 50; a module that needs the tab's rules carries them as the segment and tabs modules do, so a page without link tabs pays nothing. Raised in the panels, art and parts port (DECISIONS 162): table 3000 to 3150 and its usage 950 to 1450 (the flat form and the two-line cell), stage 2250 to 2600 and its usage 2250 to 3100 (the closing block: its held art, forced colours and print; its section gap is type-layout's --basalt-section-gap, which a page with data-closing brings), the new app-tile 4300 (a 120-point polygon clip and the hairline's mask of the same outline), captioned 2000 and period 1400; skillMd 11600 to 11950 for one index line each for captioned, app-tile and period (358 bytes; the file is 11918). Raised in the logs, status and forms port (DECISIONS 162): core 34100 to 34200 (the new size-field-label-inline token, 80px, is written into every page's tokens: 25 bytes); dlist 1300 to 1900 and its usage 950 to 1060 (the stacked form, R9 and R10: a title over its text, 20px between entries, no divider; one usage line). Raised in audit-fix-c6 (the owner's cap, raised by the builder and for the owner to confirm): glyph 1300 to 1900, for redrawing a glyph when its ancestor's aria-current or data-current moves (the lists that hold glyphs are watched). Raised in the colour-ink-ladder build (DECISIONS 166): core 34200 to 34350 (the four lifted dark inks are four new primitives, each written into every page's tokens: the core measured 34307). Raised in the audit-2-design build (DECISIONS 167, Q7a): disclosure 3500 to 3800 (the core chevron drawn as a mask in place of two borders: the module measured 3755). Joined in the integration of c7 (#86) and c10 (#91): option-chips 6750 to 6850 (c7's reset resync and c10's data-ready together measure 6839). Raised in table-sort-3 (DECISIONS 257 and 261, the owner's pick: three sort states, the arrow after the label, explainers on column titles): still-table 13400 to 14650 (+9.3%: the module was 13343 bytes and is 14602; the end-aligned label's move by a transform, its right-to-left sign and the indicator that waits for it on a fine pointer, 912 bytes of CSS; the third state, the sort from the table's own order and a .explainer kept out of the button, 347 bytes of script) and its usage 2150 to 2250 (2197: the third state and the own order); the new explainer module 5850 (5842: a manual native popover opened from the sort button on hover, keyboard focus and a long press, placed above the header or beside it, 1752 bytes of CSS and 4090 of script; a page without explainers pays nothing) and its usage 900; skillMd 12250 to 12400 for the explainer's index line (113 bytes; the file is 12352). Each cap is the measured bytes rounded up to the next 50. Raised in table-sort-3's fix pass (Astra's review): explainer 5850 to 6900 (+18%: 5842 to 6864 bytes; the gap between the header and the card kept while a pointer crosses it, the close when its header leaves the view whatever has focus, the dismissal held until pointer and focus have both left, and its page-wide listeners and timers scoped to an open card and stopped when the table leaves the page, 1,022 bytes of script). Raised in cimip-gaps-2 batch B5 (the touch sizes under 720 whatever the pointer: each coarse-pointer target rule also answers a window under 720, about 20 bytes a rule; forms merged its three into one and stays under 3500): select 9000 to 9100 (measured 9064), selection 1480 to 1500 (1486), filter 17450 to 17500 (17473), option-chips 6850 to 6900 (6853), menu 8900 to 8950 (8902). B5 fix pass 1 (Astra): core 34550 to 34950 (measured 34911: 30762 CSS and 4149 JS) for stacked links in a column, each giving up the side of its 44px box that meets a neighbour, so a tap on a link's words is always that link's; core had 12 bytes free. DECISIONS 274 (the owner's pick: under 720 the toast stack hangs from the bar): toast 15700 to 16050 (measured 16035; 8 bytes were free; the stack's direction became one sign variable, trimming 585 of the 920 bytes the phone form first took). B5 merged with main (5ad5345a): main's own core measured 34930 against its 34550 cap before B5; with B5 (the touch sizes under 720 and stacked links in a column) it is 35331, so core is 35350; nav 5350 to 5400 (measured 5364: B4's nav plus the touch size under 720). The full run after the stream (DECISIONS 246): the site footer's links keep their own flex column under 720, as React's, out of the bare-link touch rule (26 bytes), so core is 35400 (measured 35357); sheet 5250 to 5400 (measured 5368: React's B5 ring room, ported: the held actions reach space-1-5 above their band, clipped, and the body keeps space-1-5 at each end). Raised for diagram motion and service marks (DECISIONS 292): skillMd 12550 to 12650 for the diagram-motion module's one line; diagram 87200 to 91000 for what a still diagram now carries (a card's mark and its seat, the pending frame, the comparison that writes a drawing only when it changed, and the print rule), and its usage 2600 to 4300 for the decision's four lines and the list of mark ids; the new diagram-motion module (the motion engine, its stylesheet and the motion tokens, in a page only when a diagram is animated) at 26200. Raised when the diagram tests were first run (DECISIONS 298): diagram 91000 to 91250 and diagram-motion 26200 to 26850. Raised in batch A of the diagrams backlog (DECISIONS 301): diagram 91250 to 92400, for the engine fixes it bundles (a decision kept no taller than it is wide, labels on whole pixels, slots beside a straight line, a one-column schema's turn-back); the skill keeps the development checks a production React build now drops. Raised again in that batch's review fixes: diagram 92400 to 92650, for the drawn layout refusing two lines laid on one another (Neon's blocking finding 1 on #126). Fix round 1 of #124 had already taken them to 91205 and 26621 with the tests unrun; this round added 1 byte (every focal node prints its fill; a one-form mark's dark form falls back to its light one) and 180 (the entrance keeps its own clock when it is drawn again while paused). Raised in diagram batch B's fix round (DECISIONS 318, the owner's diagram raise; and 326's sweep), each to its measured size: diagram 137700 to 144100 (the two reviews' fixes in the shared engine: right to left frames and self-calls, the corridors' and lanes' development words, the unusable-placement check, the transcript's hanging lines, the text art's frame widening, the frame-side fit check, the sequence's layers, the stacked group's turn room), diagram-motion 28450 to 30450 (the text sequence's build by ink and its colour-only run, moved into the motion module), diagram-zoom 17000 to 17600 (a linked card closes the viewer; the text art's own width; a placed model for the key hint), diagram-export 7850 to 10450 (an export at rest: sized drawing SVGs, no reveal masks, the pseudo-element rules, the lines under the cards, a viewer's figure read at 100% with its head and key, the rim's lit top). Raised at the batch B re-check (the decider's four rulings): diagram 144100 to 145100 (5.1's first list reported as errors apart from the warnings, a turn's label lines on the group entered by it and the seats beside its turn, the bare stack applied, the text art's reset of the core's inline code chip).", "budgets": { "skillMd": 12950, "core": 35400 @@ -778,7 +778,7 @@ "art", "kbd" ], - "budget": 144100, + "budget": 145100, "usage": 4600, "builds": [ "kbd" From dbbce9fe30a224c618f6acca9c0d3bdb07b48065 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:55:20 -0600 Subject: [PATCH 61/62] A text sequence has no Clear highlight on touch (React), as documented and as the skill does 1.5 mounts "Clear highlight" on touch for a figure that can be traced. React mounted it for a text sequence too: its ink is the art or the transcript, which no tap traces, so the button stayed disabled. It is now mounted only for a figure that is not text, as the skill already does (it mounts the button only where the figure has an ink layer with lines). A bug fix restoring documented behaviour: the one pixel change is the dead button gone from the text figure's foot on touch. Tests: diagram-recheck.test.mjs (node, run: 7 pass) checks the condition in both engines and that a text figure has no ink layer; diagram-keys.test.mjs taps the text figure at 1440 (art) and 390 (transcript) on touch and finds no Clear highlight (browser, written, not run). export-sizes.json re-recorded (+11 to +13 bytes a diagram component). Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-figure.tsx | 5 +++-- packages/react/test/diagram-keys.test.mjs | 11 +++++++++++ packages/react/test/diagram-recheck.test.mjs | 9 +++++++++ packages/react/test/export-sizes.json | 14 +++++++------- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index 71958fb8..56d5d9c2 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -535,8 +535,9 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, entrance: ) : null} ) : null; - // "Clear highlight" (1.5): last in the foot, mounted whenever the figure is on touch and can be traced, aria-disabled until a trace is up. - const clear = !viewer && (onTouch || touched) && ink ? ( + // "Clear highlight" (1.5): last in the foot, mounted whenever the figure is on touch and can be traced, aria-disabled until a trace is up. A text + // sequence (its art or its transcript) has no lines a tap traces, so it has none, as in the skill, which mounts it only for a figure drawn with lines. + const clear = !viewer && !model.text && (onTouch || touched) && ink ? ( diff --git a/packages/react/test/diagram-keys.test.mjs b/packages/react/test/diagram-keys.test.mjs index 2cda4b29..f51b9223 100644 --- a/packages/react/test/diagram-keys.test.mjs +++ b/packages/react/test/diagram-keys.test.mjs @@ -184,6 +184,17 @@ describe("the trace on touch", () => { await page.close(); }); + test("a text sequence, as art at 1440 and as the transcript at 390, has no Clear highlight: a tap traces nothing in it", async () => { + for (const width of [1440, 390]) { + const { page } = await touchPage({ width, items: [{ key: "text", type: "sequence", props: (({ type, ...p }) => p)(BX.textSequence) }] }); + await page.waitForSelector(`#fig-text .${P}-text .${P}-text-ink`); + await page.locator(`#fig-text .${P}-text`).tap(); + await page.waitForTimeout(200); + assert.equal(await page.locator(`#fig-text .${P}-clear`).count(), 0, `${width}: no Clear highlight`); + await page.close(); + } + }); + test("at 390 the stacked schema and sequence, which draw no lines, show no tap hint and no Clear highlight", async () => { const { page } = await touchPage({ width: 390 }); for (const key of ["schema", "sequence"]) { diff --git a/packages/react/test/diagram-recheck.test.mjs b/packages/react/test/diagram-recheck.test.mjs index 643abb44..100eec68 100644 --- a/packages/react/test/diagram-recheck.test.mjs +++ b/packages/react/test/diagram-recheck.test.mjs @@ -97,3 +97,12 @@ test("the skill writes batch B's figures from the same engine: compose.mjs's mar assert.equal(ids(fromSkill), ids(fromEngine), key); } }); + +test("a text sequence has no Clear highlight in React, as in the skill: the React figure mounts it only for a figure that is not text", () => { + const figure = fs.readFileSync(path.join(pkg, "src", "diagram-figure.tsx"), "utf8"); + assert.match(figure, /const clear = !viewer && !model\.text && \(onTouch \|\| touched\) && ink \?/); + // The skill mounts it only where the figure has an ink layer with lines in it, which a text figure never has. + const skill = fs.readFileSync(path.join(root, "tools", "html-skill", "src", "modules", "diagram.js"), "utf8"); + assert.match(skill, /var want = touched && !viewer && ink && ink\.innerHTML !== '';/); + assert.doesNotMatch(html(B.textSequence), /class="basalt-diagram-ink"/, "a text figure's markup has no ink layer"); +}); diff --git a/packages/react/test/export-sizes.json b/packages/react/test/export-sizes.json index 62fd6c94..0cf76718 100644 --- a/packages/react/test/export-sizes.json +++ b/packages/react/test/export-sizes.json @@ -18,7 +18,7 @@ "AppHeader": 1285, "AppShell": 103887, "AppTile": 1112, - "ArchitectureDiagram": 100938, + "ArchitectureDiagram": 100953, "ArrowDownGlyph": 2868, "ArrowLeftGlyph": 2869, "ArrowRightGlyph": 2859, @@ -70,7 +70,7 @@ "CopyGlyph": 2884, "Countdown": 3016, "CoverageStrip": 1570, - "DataFlowDiagram": 100883, + "DataFlowDiagram": 100896, "DateAge": 2527, "DescriptionColumns": 216, "DescriptionItem": 593, @@ -105,7 +105,7 @@ "Fieldset": 6390, "FilterResult": 698, "FilterToolbar": 774, - "FlowchartDiagram": 100904, + "FlowchartDiagram": 100917, "Form": 8730, "FormGrid": 438, "FormGridItem": 628, @@ -224,7 +224,7 @@ "RunsGlyph": 3128, "STATUS_MESSAGE_MS": 26, "SandboxesGlyph": 2963, - "SchemaDiagram": 100852, + "SchemaDiagram": 100865, "SearchDialog": 88277, "SearchField": 18301, "SearchGlyph": 3181, @@ -243,7 +243,7 @@ "SelectableList": 821, "SelectionBar": 25913, "Separator": 4531, - "SequenceDiagram": 100880, + "SequenceDiagram": 100891, "SettingsGlyph": 3100, "ShareBar": 1411, "Sheet": 70793, @@ -412,8 +412,8 @@ "useWaitMark": 303 }, "package": { - "bytes": 903845, - "gzip": 301378 + "bytes": 903860, + "gzip": 301388 }, "styles": { "bytes": 413471, From ca76f333834f42a3e02b3243336a02b7e22ff027 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:55:28 -0600 Subject: [PATCH 62/62] Review tooling: shoot one step alone (--only), and a state's own viewport height; round 66's text viewer at 390 by 844 build.mjs takes --only , shooting those steps alone into --out and keeping each step's number, so a re-shot picture has its round's name. A step may set heights, keyed "state@width", to give one state at one width its own viewport height. Round 66's text viewer is shot at 390 by 844, a phone's own screen, not 2,000. Co-Authored-By: Claude Opus 5.5 --- tools/review/build.mjs | 8 ++++++-- tools/review/round66.tsx | 1 + tools/review/rounds.tsx | 2 ++ tools/review/walkthrough.tsx | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/review/build.mjs b/tools/review/build.mjs index 805e9c74..6de72844 100644 --- a/tools/review/build.mjs +++ b/tools/review/build.mjs @@ -34,6 +34,9 @@ const out = path.resolve(outAt >= 0 ? args[outAt + 1] : path.join(repo, ".review // --still: shoot with every transition and animation at zero length and every loop held, so two builds of the same code give the same pixels // (tools/review/pixel-proof.mjs compares them). It changes only the tooling's own clock: a shot of a mid-motion state is the end of that motion. const still = args.includes("--still"); +// --only a,b: shoot those steps alone (by id), into --out, keeping each step's number, so a re-shot picture has its round's name. +const onlyAt = args.indexOf("--only"); +const only = onlyAt >= 0 ? new Set(args[onlyAt + 1].split(",")) : null; // What a still takes out of a shot: the CSS transitions and animations (zero length); the JS glides, which read the duration tokens off the root (a number that rolls, a // line that travels to its new value: 1ms, not zero, because a glide divides by it); a text caret, which blinks; and then, just before the shot, whatever finite animation // is still running is finished, so a transition that began after the page loaded (a focus ring, a plate) is at its end and not near it. @@ -87,7 +90,7 @@ const untilQuiet = async (page, label) => { if (!done) { gateWarnings.push(label); console.warn(`${label}: the page still had timers pending after 10s; shot anyway`); } if (audit && before !== (await text())) console.log(`GATE CHANGED ${label}`); }; -const wanted = args.filter((a, i) => !a.startsWith("--") && (outAt < 0 || i !== outAt + 1)); +const wanted = args.filter((a, i) => !a.startsWith("--") && (outAt < 0 || i !== outAt + 1) && (onlyAt < 0 || i !== onlyAt + 1)); fs.mkdirSync(out, { recursive: true }); // ---- the page, once per round @@ -301,6 +304,7 @@ for (const id of rounds) { // Every step and state at the desktop width and at a phone's 390px, in both themes. let n = 1; for (const step of meta) { + if (only && !only.has(step.id)) { n++; continue; } for (const stateFull of ["default", ...step.states]) { // "name@1024" is a state shot at that one width. A step may also set `widths`, `scales` (1 for 1x, 2 for 2x) and `height`. const state = stateFull.split("@")[0]; @@ -314,7 +318,7 @@ for (const id of rounds) { // ends in one of them (an open menu "menu-forced-colours-lit") takes the same emulation, with or without "-lit". const mode = state.replace(/-lit$/, ""); const media = mode.endsWith("forced-colours") ? { forcedColors: "active", colorScheme: theme } : mode.endsWith("forced-mixed") ? { forcedColors: "active", colorScheme: theme === "dark" ? "light" : "dark" } : mode.endsWith("reduced-motion") ? { reducedMotion: "reduce" } : mode.endsWith("more-contrast") ? { contrast: "more" } : {}; - const page = await browser.newPage({ viewport: { width, height: step.height ?? (overlay ? 640 : 400) }, deviceScaleFactor: scale, hasTouch: state.startsWith("chart-touch") || state === "touch" || Boolean(step.touch && width < 720), isMobile: (id === "48" && state === "touch") || Boolean(step.touch && width < 720), ...media }); + const page = await browser.newPage({ viewport: { width, height: step.heights?.[`${state}@${width}`] ?? step.height ?? (overlay ? 640 : 400) }, deviceScaleFactor: scale, hasTouch: state.startsWith("chart-touch") || state === "touch" || Boolean(step.touch && width < 720), isMobile: (id === "48" && state === "touch") || Boolean(step.touch && width < 720), ...media }); page.on("pageerror", (e) => errors.push(`${step.id}/${state}/${theme}: ${e.message}`)); // Round 25's framed art: one address that never answers (the loading state, held) and one that is refused (the failed state). if (id === "25") { diff --git a/tools/review/round66.tsx b/tools/review/round66.tsx index da59657c..866b4f33 100644 --- a/tools/review/round66.tsx +++ b/tools/review/round66.tsx @@ -211,6 +211,7 @@ export const ROUND_66: Round = { widths: W, scales: [2], height: 2000, + heights: { "viewer@390": 844 }, touch: true, demo: ({ state }) => , }, diff --git a/tools/review/rounds.tsx b/tools/review/rounds.tsx index 9016081e..c9aea650 100644 --- a/tools/review/rounds.tsx +++ b/tools/review/rounds.tsx @@ -150,6 +150,8 @@ export interface Step { scales?: number[]; /** The viewport height. Default 400, or 640 for an open state. */ height?: number; + /** The viewport's height for one state at one width, keyed "state@width" (a dialog shot at a phone's own height): it wins over `height`. */ + heights?: Record; /** Shot edge to edge, with none of the page's own padding, so a page specimen is the width the shot is named for (a layout round's row is then the real row). */ bleed?: boolean; /** Shoot widths under 720 as a phone: touch and mobile emulation (a coarse pointer, the 44px targets, focus by touch). */ diff --git a/tools/review/walkthrough.tsx b/tools/review/walkthrough.tsx index 3cfede75..b516bd5e 100644 --- a/tools/review/walkthrough.tsx +++ b/tools/review/walkthrough.tsx @@ -13,13 +13,13 @@ import { ROUNDS } from "./rounds"; declare global { interface Window { __BASALT_ROUND__: string; - __BASALT_STEPS__: Array<{ id: string; name: string; states: string[]; widths?: number[]; scales?: number[]; height?: number; touch?: boolean }>; + __BASALT_STEPS__: Array<{ id: string; name: string; states: string[]; widths?: number[]; scales?: number[]; height?: number; heights?: Record; touch?: boolean }>; } } const round = ROUNDS.find((r) => r.id === window.__BASALT_ROUND__)!; // for build.mjs: which steps and states to screenshot -window.__BASALT_STEPS__ = round.steps.map((s) => ({ id: s.id, name: s.name, states: s.states ?? [], widths: s.widths, scales: s.scales, height: s.height, touch: s.touch })); +window.__BASALT_STEPS__ = round.steps.map((s) => ({ id: s.id, name: s.name, states: s.states ?? [], widths: s.widths, scales: s.scales, height: s.height, heights: s.heights, touch: s.touch })); const params = new URLSearchParams(location.search); const shot = params.get("shot") === "1"; const initialTheme = params.get("theme") ?? (matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark");