From 17231d10ec304007069bb614eeaf1dfad912819b Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:48:54 -0600 Subject: [PATCH 01/12] Diagrams: the shared time scale (diagram-scale), as the answers' section 3 specifies it Arithmetic on plain numbers and nothing else: a day as whole days from 1970-01-01 (Date.UTC, never a zone) and an instant as its milliseconds; one map with one rate and fixed gaps for left-out spans, mirrored by one argument; the number, day and clock ladders (the clock round on the wall clock of a zone its caller states); ticks from the caller's least distance, none in a left-out span and never more than the length over the distance plus one; roundOut as a function a caller may call; and a date's words. No default domain, no end ticks, nothing at load, no import. Tests written, not run (DECISIONS 359). Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-scale.ts | 273 +++++++++++++++++++++ packages/react/test/diagram-scale.test.mjs | 87 +++++++ 2 files changed, 360 insertions(+) create mode 100644 packages/react/src/diagram-scale.ts create mode 100644 packages/react/test/diagram-scale.test.mjs diff --git a/packages/react/src/diagram-scale.ts b/packages/react/src/diagram-scale.ts new file mode 100644 index 00000000..2df93e38 --- /dev/null +++ b/packages/react/src/diagram-scale.ts @@ -0,0 +1,273 @@ +// A diagram's time scale (DECISIONS 359, the answers' section 3): the arithmetic a gantt and a timeline share, and nothing else. Plain numbers in and out: +// no DOM, no CSS, no layout, nothing at load, and it imports nothing. Each caller owns its domain, its inset, its least distance between ticks, its end +// ticks, its labels' face, ink and words (but a date's), its zone and its breaks' marks. The module never makes a default domain, never rounds one unless a +// caller asks (`roundOut`), and never adds the domain's ends as ticks. The implementation has not been reviewed. + +const DAY = 86_400_000; + +// ---- 1. Two readers that make a number ---- + +/** A day (`YYYY-MM-DD`) as whole days from 1970-01-01, made with `Date.UTC` and never a zone, so no runtime zone can move it. Null where it is not a day. */ +export function dayNumber(v: unknown): number | null { + const m = typeof v === "string" ? /^(\d{4})-(\d{2})-(\d{2})$/.exec(v.trim()) : null; + if (!m) return null; + const y = Number(m[1]), mo = Number(m[2]), d = Number(m[3]); + const ms = Date.UTC(y, mo - 1, d); + const at = new Date(ms); + if (at.getUTCFullYear() !== y || at.getUTCMonth() !== mo - 1 || at.getUTCDate() !== d) return null; + return Math.round(ms / DAY); +} + +/** An instant (ISO 8601, with its offset or `Z`) as its milliseconds. Null where it is not one: a time with no offset names no instant. */ +export function instantOf(v: unknown): number | null { + if (typeof v !== "string") return null; + const s = v.trim(); + if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2})$/.test(s)) return null; + const ms = Date.parse(s); + return Number.isFinite(ms) ? ms : null; +} + +// ---- 2. The map ---- + +/** A span the scale leaves out, in the domain's units: `[from, to]`. */ +export type ScaleBreak = readonly [number, number]; +export interface ScaleMapInput { + /** Required: the module has no default domain and never rounds one. */ + domain: readonly [number, number]; + /** The axis' length, in px. */ + length: number; + /** Spans left out of the scale, each drawn as a fixed `gap`. */ + breaks?: readonly ScaleBreak[]; + /** The px each break takes on the axis. */ + gap?: number; + /** Mirrored: a position is the length less the left-to-right one. */ + reversed?: boolean; +} +export interface ScaleMap { + domain: readonly [number, number]; + length: number; + /** The breaks inside the domain, sorted, merged where they touch. */ + breaks: ScaleBreak[]; + gap: number; + reversed: boolean; + /** px for one unit of the domain, the same on both sides of every break. */ + rate: number; + /** A distance from the axis' start. A value inside a break is at that break's start edge. */ + position: (value: number) => number; + /** The way back: the value at a distance from the axis' start (a distance inside a break's gap is its start). */ + value: (position: number) => number; +} + +/** The breaks a map holds: inside the domain, sorted, and merged where they overlap. */ +function breaksIn(domain: readonly [number, number], list: readonly ScaleBreak[] = []): ScaleBreak[] { + const [a, b] = domain; + const clipped = list + .map(([f, t]) => [Math.max(a, Math.min(f, t)), Math.min(b, Math.max(f, t))] as [number, number]) + .filter(([f, t]) => t > f) + .sort((x, y) => x[0] - y[0]); + const out: Array<[number, number]> = []; + for (const br of clipped) { + const last = out[out.length - 1]; + if (last && br[0] <= last[1]) last[1] = Math.max(last[1], br[1]); + else out.push([br[0], br[1]]); + } + return out; +} + +/** One rate for the whole figure: (`length` less a `gap` for each break) over (`b − a` less the time left out). */ +export function scaleMap(input: ScaleMapInput): ScaleMap { + const [a, b] = input.domain; + const length = input.length; + const breaks = breaksIn(input.domain, input.breaks); + const gap = breaks.length ? Math.max(0, input.gap ?? 0) : 0; + const reversed = Boolean(input.reversed); + const left = breaks.reduce((sum, [f, t]) => sum + (t - f), 0); + const span = b - a - left; + const rate = span > 0 ? (length - gap * breaks.length) / span : 0; + const forward = (v: number): number => { + // With no breaks it is the fraction itself, `(value − a) ÷ (b − a) × length`, and nothing else: the arithmetic the gantt was decided on. + if (!breaks.length) return b === a ? 0 : ((v - a) / (b - a)) * length; + let out = 0, at = a; + for (const [f, t] of breaks) { + if (v <= f) break; + out += (f - at) * rate; + if (v < t) return out; + out += gap; + at = t; + } + return out + (v - at) * rate; + }; + const back = (p: number): number => { + const x = reversed ? length - p : p; + if (!breaks.length) return length === 0 ? a : a + (x / length) * (b - a); + let pos = 0, at = a; + for (const [f, t] of breaks) { + const run = (f - at) * rate; + if (x <= pos + run) return at + (x - pos) / rate; + pos += run; + if (x <= pos + gap) return f; + pos += gap; + at = t; + } + return at + (x - pos) / rate; + }; + return { domain: [a, b], length, breaks, gap, reversed, rate, position: (v) => (reversed ? length - forward(v) : forward(v)), value: back }; +} + +// ---- 3. Three ladders ---- + +/** One step of a ladder: where the tick at or before a value is, and the next after one. `approx` is its shortest length in the domain's units. */ +export interface ScaleStep { + name: string; + approx: number; + floor: (v: number) => number; + next: (v: number) => number; +} +export type ScaleLadder = ScaleStep[]; + +const uniform = (name: string, size: number, origin = 0): ScaleStep => ({ + name, + approx: size, + floor: (v) => origin + Math.floor((v - origin) / size + 1e-9) * size, + next: (v) => origin + (Math.floor((v - origin) / size + 1e-9) + 1) * size, +}); + +/** Number: 1, 2, 2.5 and 5 times a power of ten, from the power below `least` up to the power above `most` (the chart's steps). */ +export function numberLadder(least: number, most: number): ScaleLadder { + const out: ScaleLadder = []; + const lo = Math.floor(Math.log10(Math.max(1e-9, least))) - 1; + const hi = Math.ceil(Math.log10(Math.max(1e-9, most))) + 1; + for (let p = lo; p <= hi && out.length < 200; p++) for (const f of [1, 2, 2.5, 5]) { + const size = f * 10 ** p; + // A step written to 12 significant figures, so 0.1 × 3 is 0.3. + const clean = Number(size.toPrecision(12)); + out.push({ ...uniform(String(clean), clean), floor: (v) => Number((Math.floor(v / clean + 1e-9) * clean).toPrecision(12)), next: (v) => Number(((Math.floor(v / clean + 1e-9) + 1) * clean).toPrecision(12)) }); + } + return out; +} + +/** A day number's calendar parts, in UTC (a day number has no zone). */ +const partsOf = (day: number) => { const d = new Date(day * DAY); return { y: d.getUTCFullYear(), m: d.getUTCMonth(), d: d.getUTCDate(), w: d.getUTCDay() }; }; +const dayOf = (y: number, m: number, d = 1) => Math.round(Date.UTC(y, m, d) / DAY); +/** The month steps: the 1st of a month every `months` months (January, April, July and October for three), and a year (January 1st). */ +const monthStep = (name: string, months: number, approx: number): ScaleStep => ({ + name, + approx, + floor: (v) => { const p = partsOf(Math.floor(v)); const k = p.y * 12 + p.m; const s = k - (((k % months) + months) % months); return dayOf(Math.floor(s / 12), s % 12); }, + next: (v) => { const p = partsOf(Math.floor(v)); const k = p.y * 12 + p.m; const s = k - (((k % months) + months) % months) + months; return dayOf(Math.floor(s / 12), s % 12); }, +}); +/** Day: 1 day, 2 days, a week (Mondays), 2 weeks, a month (the 1st), 3 months, a year, on the calendar of the day number. 1970-01-05 was a Monday. */ +export function dayLadder(): ScaleLadder { + return [uniform("day", 1), uniform("2 days", 2), uniform("week", 7, 4), uniform("2 weeks", 14, 4), monthStep("month", 1, 28), monthStep("3 months", 3, 89), monthStep("year", 12, 365)]; +} + +/** + * Clock: 1, 2, 5, 10, 15, 30 s; 1, 2, 5, 10, 15, 30 min; 1, 2, 3, 6, 12 h; then the day ladder's steps at midnights. A tick is round on the wall clock of + * the zone its caller states: `offset(ms)` is that zone's offset from UTC at an instant, in minutes (in Asia/Kolkata an hour's tick is on the hour there). + */ +export function clockLadder(offset: (ms: number) => number = () => 0): ScaleLadder { + const wall = (t: number) => t + offset(t) * 60_000; + // A wall-clock time back to its instant: twice, so a time beside a change of offset lands on the side it names. + const instant = (w: number) => { const t = w - offset(w) * 60_000; return w - offset(t) * 60_000; }; + const onWall = (name: string, size: number): ScaleStep => ({ + name, + approx: size, + floor: (v) => instant(Math.floor(wall(v) / size + 1e-9) * size), + next: (v) => { let n = instant((Math.floor(wall(v) / size + 1e-9) + 1) * size); if (n <= v) n = instant((Math.floor(wall(v) / size + 1e-9) + 2) * size); return n; }, + }); + const s = 1000, mi = 60 * s, hr = 60 * mi; + const out: ScaleLadder = [1, 2, 5, 10, 15, 30].map((k) => onWall(`${k} s`, k * s)); + out.push(...[1, 2, 5, 10, 15, 30].map((k) => onWall(`${k} min`, k * mi)), ...[1, 2, 3, 6, 12].map((k) => onWall(`${k} h`, k * hr))); + // The day ladder's steps, at the zone's midnights: on wall-clock day numbers. + for (const st of dayLadder()) out.push({ + name: st.name, + approx: st.approx * DAY, + floor: (v) => instant(st.floor(Math.floor(wall(v) / DAY)) * DAY), + next: (v) => instant(st.next(Math.floor(wall(v) / DAY)) * DAY), + }); + return out; +} + +// ---- 4. Ticks ---- + +export interface ScaleTick { value: number; place: number; step: string } + +/** A step's ticks inside the domain and outside every break, bounded by the most the length can hold at the caller's distance. */ +function stepTicks(map: ScaleMap, step: ScaleStep, cap: number): number[] | null { + const [a, b] = map.domain; + const out: number[] = []; + let v = step.floor(a); + if (v < a) v = step.next(v); + // Bounded by the ticks kept (a step's values inside a left-out span are passed over, never kept), and by a hard stop. + for (let guard = 0; v <= b + 1e-9 && guard < 100_000; guard++) { + if (!map.breaks.some(([f, t]) => v > f && v < t)) { out.push(v); if (out.length > cap) return null; } + const n = step.next(v); + if (!(n > v)) break; + v = n; + } + return out; +} + +/** + * The finest step whose neighbouring ticks are at least `least` px apart; round values only; none inside a left-out span; each with its value, its place + * and its step. Never more than `length` over the distance, plus one. It never adds the domain's ends: where no step fits, there are none. + */ +export function ticks(map: ScaleMap, ladder: ScaleLadder, least: number): ScaleTick[] { + const cap = Math.floor(map.length / Math.max(1, least)) + 1; + for (const step of ladder) { + // A step whose shortest length is under the distance at this rate cannot pass: it is not generated. + if (step.approx * map.rate < least - 1e-6) continue; + const values = stepTicks(map, step, cap + 1); + if (!values) continue; + const places = values.map((v) => map.position(v)); + let ok = values.length <= cap; + for (let k = 1; ok && k < places.length; k++) if (Math.abs(places[k]! - places[k - 1]!) < least - 1e-6) ok = false; + if (ok) return values.map((value, k) => ({ value, place: places[k]!, step: step.name })); + } + return []; +} + +// ---- 5. Rounding out, as a function a caller may call ---- + +/** + * A step and a domain together: the finest step at which, with the extent widened to that step's ticks at or outside it, ticks are still `least` px + * apart. One try a step of the ladder at most. The map never calls it. + */ +export function roundOut(extent: readonly [number, number], ladder: ScaleLadder, least: number, length: number, breaks: readonly ScaleBreak[] = [], gap = 0): { domain: [number, number]; step: string } | null { + const [e0, e1] = extent; + for (const step of ladder) { + const lo = step.floor(e0); + let hi = step.floor(e1); + if (hi < e1) hi = step.next(hi); + if (!(hi > lo)) hi = step.next(lo); + const map = scaleMap({ domain: [lo, hi], length, breaks, gap }); + if (step.approx * map.rate < least - 1e-6) continue; + if (ticks(map, [step], least).length >= 2) return { domain: [lo, hi], step: step.name }; + } + return null; +} + +// ---- 6. A date's words ---- + +let formats: Map | undefined; +const formatter = (locale: string, year: boolean) => { + formats ??= new Map(); + const key = `${locale}|${year ? "y" : ""}`; + let f = formats.get(key); + if (!f) { + f = new Intl.DateTimeFormat(locale, year ? { month: "short", day: "numeric", year: "numeric", timeZone: "UTC" } : { month: "short", day: "numeric", timeZone: "UTC" }); + formats.set(key, f); + } + return f; +}; +/** "Nov 2" (or "Nov 2, 2026"), by `Intl.DateTimeFormat` for the locale given (`en-US` by default), formatted in UTC from the day number. */ +export function dateWords(day: number, year = false, locale = "en-US"): string { + return formatter(locale, year).format(new Date(Math.floor(day) * DAY)); +} +/** A row of dates' words: the year on the first and on the first of each later year. One function, so a date reads the same on both types. */ +export function datesWords(days: readonly number[], locale = "en-US"): string[] { + let last: number | undefined; + return days.map((d) => { const y = partsOf(Math.floor(d)).y; const out = dateWords(d, y !== last, locale); last = y; return out; }); +} +/** The calendar year of a day number (UTC). */ +export const yearOf = (day: number): number => partsOf(Math.floor(day)).y; diff --git a/packages/react/test/diagram-scale.test.mjs b/packages/react/test/diagram-scale.test.mjs new file mode 100644 index 00000000..da28fa85 --- /dev/null +++ b/packages/react/test/diagram-scale.test.mjs @@ -0,0 +1,87 @@ +// The shared time scale (DECISIONS 359, the answers' section 3): arithmetic only, in Node against the built module. Written while tests are paused +// (DECISIONS 359): not yet run. The implementation hasn't been reviewed. +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import path from "node:path"; +import { pathToFileURL } from "node:url"; +import { describe, test } from "node:test"; + +import { pkg } from "./support.mjs"; + +const S = await import(pathToFileURL(path.join(pkg, "dist", "diagram-scale.js")).href); +const DAY = 86_400_000; + +describe("the readers", () => { + test("a day is whole days from 1970-01-01, whatever the process zone (Pacific/Kiritimati and America/Los_Angeles)", () => { + const code = `import(${JSON.stringify(pathToFileURL(path.join(pkg, "dist", "diagram-scale.js")).href)}).then((s) => console.log(s.dayNumber("2026-11-24")))`; + const read = (TZ) => execFileSync(process.execPath, ["-e", code], { env: { ...process.env, TZ }, encoding: "utf8" }).trim(); + assert.equal(read("Pacific/Kiritimati"), String(Date.UTC(2026, 10, 24) / DAY)); + assert.equal(read("America/Los_Angeles"), String(Date.UTC(2026, 10, 24) / DAY)); + }); + test("a day that is not one, and an instant without its offset, are null", () => { + assert.equal(S.dayNumber("2026-02-30"), null); + assert.equal(S.instantOf("2026-11-24T14:03:00"), null); + assert.equal(S.instantOf("2026-11-24T14:03:00Z"), Date.UTC(2026, 10, 24, 14, 3)); + }); +}); + +describe("the map", () => { + test("with no breaks a place is (value − a) ÷ (b − a) × length, to 0.01px, at three lengths", () => { + for (const length of [320, 816, 1104]) { + const m = S.scaleMap({ domain: [20_000, 20_031], length }); + for (const v of [20_000, 20_007.5, 20_031]) assert.ok(Math.abs(m.position(v) - ((v - 20_000) / 31) * length) < 0.01); + } + }); + test("one rate on both sides of a break, the break a fixed gap", () => { + const m = S.scaleMap({ domain: [0, 100], length: 532, breaks: [[30, 70]], gap: 32 }); + assert.ok(Math.abs(m.position(30) - m.position(0) - 30 * m.rate) < 1e-9); + assert.ok(Math.abs(m.position(100) - m.position(70) - 30 * m.rate) < 1e-9); + assert.ok(Math.abs(m.position(70) - m.position(30) - 32) < 1e-9); + }); + test("reversed is the length less the position", () => { + const a = S.scaleMap({ domain: [0, 10], length: 500 }), b = S.scaleMap({ domain: [0, 10], length: 500, reversed: true }); + for (const v of [0, 2.5, 10]) assert.ok(Math.abs(b.position(v) - (500 - a.position(v))) < 1e-9); + }); + test("the module never makes a domain: it is required, and used as written", () => { + const m = S.scaleMap({ domain: [3, 17], length: 100 }); + assert.deepEqual(m.domain, [3, 17]); + }); +}); + +describe("ticks", () => { + test("the count never passes the length over the distance, plus one; no end ticks are added", () => { + for (const length of [200, 640, 1104]) { + const m = S.scaleMap({ domain: [20_000.3, 20_090.7], length }); + const t = S.ticks(m, S.dayLadder(), 56); + assert.ok(t.length <= Math.floor(length / 56) + 1); + for (const k of t) assert.ok(Number.isInteger(k.value)); + for (let i = 1; i < t.length; i++) assert.ok(t[i].place - t[i - 1].place >= 56 - 1e-6); + } + }); + test("numbers step by 1, 2, 2.5 and 5 times a power of ten", () => { + const t = S.ticks(S.scaleMap({ domain: [0, 100], length: 600 }), S.numberLadder(100 / 600, 100), 56); + assert.deepEqual(t.map((k) => k.value), [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]); + }); + test("none inside a left-out span", () => { + const m = S.scaleMap({ domain: [0, 3_000_000], length: 1000, breaks: [[780_000, 2_640_000]], gap: 32 }); + for (const k of S.ticks(m, S.clockLadder(), 144)) assert.ok(!(k.value > 780_000 && k.value < 2_640_000)); + }); + test("an hour's ticks in Asia/Kolkata are on that zone's hours", () => { + const offset = () => 330; + const m = S.scaleMap({ domain: [Date.UTC(2026, 10, 24, 0, 0), Date.UTC(2026, 10, 24, 12, 0)], length: 1600 }); + const t = S.ticks(m, S.clockLadder(offset), 144); + assert.ok(t.length > 1); + for (const k of t) assert.equal((k.value + 330 * 60_000) % 3_600_000, 0); + }); + test("roundOut finds a step and a domain together, the extent widened to that step's ticks", () => { + const r = S.roundOut([Date.UTC(2026, 10, 24, 14, 1), Date.UTC(2026, 10, 24, 14, 46)], S.clockLadder(), 144, 1000); + assert.ok(r.domain[0] <= Date.UTC(2026, 10, 24, 14, 1) && r.domain[1] >= Date.UTC(2026, 10, 24, 14, 46)); + }); +}); + +describe("a date's words", () => { + test("the year on the first and on the first of each later year", () => { + const d = (y, m, dd) => Date.UTC(y, m, dd) / DAY; + assert.deepEqual(S.datesWords([d(2026, 11, 28), d(2027, 0, 4), d(2027, 0, 11)]), ["Dec 28, 2026", "Jan 4, 2027", "Jan 11"]); + }); +}); From 0873329f5da28a7e04ede772c196ec02fbd91a3c Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:48:57 -0600 Subject: [PATCH 02/12] Diagrams: a type-module seam in the engine; isolates on every author string; the dependency and swimlane folds diagram-core.ts imports no type module: a component hands its module to the engine on the spec (DiagramTypeExt), and a type read as an architecture (state, deployment) prepares its data, adopts what is its own, and adds its card, key, list and marks through the same seam. Every string an author writes is a first-strong isolate (Ops 6). An architecture with dependents counts each card's dependents, dashes a cycle in its written directions and is ranked by longest path under automatic layout (Ops 4); a data flow's step may be a decision, its step line inside the diamond, every step then taking the contour (Ops 5). A state's and a deployment's groups go to elk in the author's order, so cycle breaking does not turn the lines out of a group back. A box's edge is a line (the run-edge ruling, run-edge/ruling.md): a gap's lanes keep its middle while each is outside the boxes beside it and space-3 clear of their edges, otherwise they are laid evenly in the clear band outside those boxes; an architecture's (and a deployment's) row on which a box starts stands space-4 lower, so space-8 is clear above the box; under space-3 a lane the warning names the lines, under space-2 the figure is stacked. Turn-backs alone are not in this ruling (backlog). The shipped diagrams grow 5,629 bytes over main (+5.37%): 5,017 for the seam, the isolates and the folds, 612 for the run-edge ruling; the owner approved raising the gate by this (DECISIONS 378). Co-Authored-By: Claude Opus 5.5 --- packages/react/src/architecture-diagram.tsx | 10 +- packages/react/src/diagram-core.ts | 459 ++++++++++++++++---- packages/react/src/diagram-figure.tsx | 8 +- packages/react/src/diagram-layout-graph.ts | 26 +- packages/react/src/diagram-layout.ts | 12 +- 5 files changed, 408 insertions(+), 107 deletions(-) diff --git a/packages/react/src/architecture-diagram.tsx b/packages/react/src/architecture-diagram.tsx index 49dbfa32..795b05f5 100644 --- a/packages/react/src/architecture-diagram.tsx +++ b/packages/react/src/architecture-diagram.tsx @@ -18,6 +18,12 @@ interface ArchitectureDiagramBase extends DiagramFigureProps { pulse?: string[]; /** Animated only: a dot carries one message along `path`, sending itself (`repeat`) or once for each new `send` value. One of pulse and packet. */ packet?: DiagramPacket; + /** + * A dependency figure (DECISIONS 359): the lines read "depends on". The engine writes each card's count of dependents in these words ("3 dependents"), + * dashes every line inside a cycle in the direction it was written, and under `layout: "auto"` ranks by longest path from the sources. Write no count by + * hand, in the key or the summary either. + */ + dependents?: { one: string; other: string }; } /** @@ -41,7 +47,7 @@ export type ArchitectureDiagramProps = Omit & ); /** 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: 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]); +export function ArchitectureDiagram({ nodes, groups, edges, pulse, packet, dependents, motion, entrance, layout, direction, placement, title, heading, legend, ...props }: ArchitectureDiagramProps) { + const spec = React.useMemo(() => ({ type: "architecture" as const, title, heading, legend, nodes: nodes as ArchitectureNode[], groups, edges, motion, entrance, layout, direction, placement, pulse, packet, dependents }), [title, heading, legend, nodes, groups, edges, motion, entrance, layout, direction, placement, pulse, packet, dependents]); return ; } diff --git a/packages/react/src/diagram-core.ts b/packages/react/src/diagram-core.ts index 5f015358..7fefa0db 100644 --- a/packages/react/src/diagram-core.ts +++ b/packages/react/src/diagram-core.ts @@ -17,12 +17,14 @@ declare const process: { env: { NODE_ENV?: string } }; // Public shapes (the components re-export these types; no third-party type appears in them) // ============================================================================================================================================ -export type DiagramType = "architecture" | "flowchart" | "data-flow" | "sequence" | "schema"; +export type DiagramType = "architecture" | "flowchart" | "data-flow" | "sequence" | "schema" | "state" | "deployment" | DiagramExtType; +/** The types a module of their own draws (DECISIONS 359): the engine knows them only through the `DiagramTypeExt` their component hands it. */ +export type DiagramExtType = "gantt" | "kanban" | "journey" | "service-blueprint" | "story-map" | "schedule" | "timeline" | "state" | "deployment"; 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; activation?: string } +export interface DiagramLegend { main?: string; plain?: string; dashed?: string; focal?: string; group?: string; activation?: string; line?: string } export interface DiagramNode { id: string; @@ -82,8 +84,17 @@ export interface DiagramPacket { } export type DiagramMotion = "still" | "animated"; export type FlowchartNode = DiagramNode & { shape?: "step" | "decision" | "terminal" }; +/** A state (DECISIONS 359, Ops 1): the architecture's node; `initial` takes the start mark, `final` the end mark; entry and exit actions sit under a rule. */ +export type StateNode = DiagramNode & { group?: string; initial?: boolean; final?: boolean; entry?: string; exit?: string }; +/** A transition: the engine writes its label from `event`, then `[guard] / action` on a second line. It has no `label`. */ +export interface StateTransition { from: string; to: string; event?: string; guard?: string; action?: string; kind?: DiagramLineKind; fromSide?: DiagramSide; toSide?: DiagramSide } +/** A row of a deployment host (DECISIONS 359, Ops 3): what runs on it. A line may name it. */ +export interface DeploymentArtifact { id: string; name: string; detail?: string } +/** A deployment's host: the architecture's node, with how many copies run (`replicas`) and its artifacts as rows. */ +export type DeploymentNode = DiagramNode & { group?: string; mark?: DiagramMark; replicas?: number; artifacts?: DeploymentArtifact[] }; export interface DataFlowLane { id: string; label: string } -export type DataFlowNode = Omit & { lane: string; mark?: DiagramMark }; +/** A data flow's step. `shape: "decision"` (DECISIONS 359) is the flowchart's diamond with its step line inside; every line leaving it is labelled. */ +export type DataFlowNode = Omit & { lane: string; mark?: DiagramMark; shape?: "decision" }; /** 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). */ @@ -131,6 +142,15 @@ export interface DiagramSpec { layout?: "authored" | "auto"; direction?: "right" | "down"; placement?: DiagramPlacement | DiagramPlacement[]; + /** A dependency figure (DECISIONS 359, Ops 4): an architecture whose lines read "depends on". The engine writes each card's count of dependents in + * these words, dashes every line inside a cycle and, under `layout: "auto"`, ranks by longest path from the sources. */ + dependents?: { one: string; other: string }; + /** A deployment's one environment (DECISIONS 359, Ops 3): required, the first words of the source line ("Production · us-east-1"). */ + environment?: string; + /** Internal: the module that draws a type the engine does not hold (DECISIONS 359). The component sets it; the HTML skill sets it from its registry. */ + ext?: DiagramTypeExt; + /** Every other key is a type module's own data (a gantt's `tasks`, a kanban's `columns`), read by that module. */ + [key: string]: unknown; } /** A card of an automatic figure (1.8): its `col` and `row` may be left out (and are not read). */ @@ -177,6 +197,14 @@ export interface MNode { /** A link card (1.4). */ href?: string; blank?: boolean; + /** A state's marks and actions (DECISIONS 359, Ops 1). */ + initial?: boolean; + final?: boolean; + entry?: string; + exit?: string; + /** A deployment host's copies and rows (Ops 3). */ + replicas?: number; + artifacts?: Array<{ id: string; name: string; detail?: string }>; } export interface MEdge { i: number; @@ -194,6 +222,14 @@ export interface MEdge { card?: { from: DiagramCardinality; to: "one" | "zero-or-one" }; /** A live stream (DECISIONS 292, 1.6); on a dashed line its own dashes march (DECISIONS 306, 1.5). */ flow?: boolean; + /** A line to a deployment host's artifact (Ops 3): the row it names. */ + toArtifact?: string; + fromArtifact?: string; + /** A state's transition, as written (Ops 1): the list says it as a sentence. */ + event?: string; + guard?: string; + action?: string; + order?: number; } 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). */ @@ -237,6 +273,11 @@ export interface Model { 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[]; + /** The module that draws a type of its own (DECISIONS 359), and what it read from the data. */ + ext?: DiagramTypeExt; + /** The way the figure reads: laid right (the default) or down (an automatic figure's placement, or the author's `direction`). */ + dir?: "right" | "down"; + plan?: unknown; } const SIDES: DiagramSide[] = ["top", "right", "bottom", "left"]; @@ -246,12 +287,18 @@ const CARDS: DiagramCardinality[] = ["one", "zero-or-one", "one-or-many", "zero- const CARD_WORDS: 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]; +/** The types automatic layout places (DECISIONS 306, 1.8; a state, a deployment and a schedule, DECISIONS 359). */ +/** The types whose cards are grouped (an architecture's groups; a state's composite states; a deployment's boundaries). */ +/** The types whose row a box starts on stands space-4 lower (the run-edge ruling). */ +const lowers = (m: Model) => m.type === "architecture" || m.type === "deployment"; +export const grouped = (type: string): boolean => type === "architecture" || type === "state" || type === "deployment"; +export const autoType = (type: string): boolean => type === "architecture" || type === "flowchart" || type === "schema" || type === "state" || type === "deployment" || type === "schedule"; /** Text from the author's data: always a string (or nothing), so a value that is not one can never be read as markup. */ -const txt = (v: unknown): string | undefined => (v === undefined || v === null || v === "" ? undefined : String(v)); +export const txt = (v: unknown): string | undefined => (v === undefined || v === null || v === "" ? undefined : String(v)); /** A record keyed by the author's ids, with no prototype, so an id such as "toString" or "constructor" is only ever its own key. */ -const record = (from?: Record): Record => Object.assign(Object.create(null) as Record, from); +export const record = (from?: Record): Record => Object.assign(Object.create(null) as Record, from); /** A value an id keys in a record, never one the record inherits. */ -const own = (r: Record | undefined, id: string): T | undefined => (r && Object.prototype.hasOwnProperty.call(r, id) ? r[id] : undefined); +export const own = (r: Record | 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. */ @@ -262,6 +309,97 @@ export interface BuildOptions { /** 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; } +/** The fonts the ruler measures in: a card's name (600 and 500), Mono, Geist at xs (400; 400, 500 and 600 with tabular figures), a table's name, a label, and Geist at sm. */ +export type RulerFont = "name" | "name-500" | "mono" | "sans" | "table" | "label" | "tab" | "xs-500" | "xs-600" | "sm"; + +/** What a type module is handed to read the author's data: the checks' sinks and the figure's direction. */ +export interface ExtBuildKit { + dev: boolean; + warn: (message: string) => void; + error: (message: string) => void; + rtl: boolean; + legend: DiagramLegend; +} +/** What a type module returns from the data: the stops (`nodes`), any lines, its own model, and the grid's size. */ +export interface ExtBuilt { nodes: MNode[]; edges: MEdge[]; plan: unknown; cols: number; rows: number } +/** What a type module is handed to lay a figure out (script only). */ +export interface ExtMeasureKit { + fig: HTMLElement; + drawing: HTMLElement; + P: string; + tk: Tokens; + /** The figure's width. */ + W: number; + least: number; + /** Writes a state into the DOM, so it can be measured as it would be drawn. */ + apply: (d: Dyn) => void; + /** The state with its roving stop settled. */ + stopOf: (d: Dyn) => Dyn; + current: Dyn; + measure: (text: string, font: RulerFont) => number; + warn?: (s: string, level?: "error") => void; +} + +/** + * A type the engine does not hold (DECISIONS 359): gantt, kanban, journey, service blueprint, story map, schedule and timeline are each drawn by a module of + * their own, which its component hands the engine on the spec (`spec.ext`), so a figure that draws an architecture bundles none of them. A type that is + * `routed` (the schedule) is laid out, routed and stacked by the engine as an architecture is, and changes only its words and its cards; any other draws + * its own drawing and its own ink, and the engine gives it the figure, the key, the list, the keys and the viewer. + */ +export interface DiagramTypeExt { + type: DiagramExtType; + /** A type read as an architecture (state, deployment): `prepare` hands the engine the data it reads that way, and `adopt` adds what is the type's own. */ + as?: "architecture"; + prepare?: (spec: DiagramSpec, kit: ExtBuildKit) => DiagramSpec; + adopt?: (m: Model, spec: DiagramSpec, kit: ExtBuildKit) => void; + build?: (spec: DiagramSpec, kit: ExtBuildKit) => ExtBuilt; + /** The engine's router lays it out (schedule). */ + routed?: boolean; + /** The noun the hint and the keys sentence use for one stop ("a task"). */ + stop: string; + sentence?: (m: Model, n: MNode) => string; + /** An architecture-read type's own sentences, after a card's detail. */ + sentenceMore?: (m: Model, n: MNode) => string[]; + key?: (P: string, m: Model) => VElement | null; + /** An architecture-read type's own key entries, before the focal and group entries. */ + keyMore?: (P: string, m: Model) => VElement[]; + list?: (P: string, m: Model) => VNode[]; + /** An architecture-read type's list: its parts' heading, what a part adds, and its connections in place of the architecture's. */ + listParts?: string; + listPart?: (P: string, m: Model, n: MNode) => VChild[]; + listLines?: (P: string, m: Model, H: (text: string) => VElement) => VNode[]; + /** An architecture-read type's card attributes and the room its marks take: a group's box (`groupMark`) and the drawing's start or top (`room`). */ + nodeAttrs?: (m: Model, n: MNode) => VAttrs; + groupMark?: (m: Model, g: Model["groups"][number], cells: { c1: number; c2: number; r1: number; r2: number } | null) => { style?: string; start?: string } | undefined; + room?: (m: Model) => { start?: boolean; top?: boolean } | undefined; + /** Ink of the type's own over the routed lines (a state's start marks), written into the drawing's SVG. */ + /** False refuses the drawn layout (a state's start mark with no place clear of the lines): the figure is stacked, and the module says why. */ + inkMore?: (P: string, m: Model, geo: Geo, tk: Tokens, drawn: boolean, warn?: (s: string) => void) => string | false; + /** The first words of the source line (a deployment's environment). */ + sourceLead?: (m: Model) => string | undefined; + /** A line of facts about the whole figure, under its source. */ + meta?: (P: string, m: Model) => VElement | null; + hint?: (m: Model, drawn: boolean) => Array<{ keys: string[]; words: string }>; + keys?: (m: Model, drawn: boolean) => string; + /** Whether a part traces (only where lines are drawn). */ + traces?: (m: Model, drawn: boolean) => boolean; + hasStops?: (m: Model, dyn: Dyn) => boolean; + keyTarget?: (m: Model, from: string, key: string, drawn: boolean, rtl: boolean) => string | null; + /** A routed type's card: what goes inside the node in place of its kind, name and detail. */ + card?: (P: string, m: Model, n: MNode, dyn: Dyn) => VChild[]; + /** A routed type's stack has no lines (DECISIONS 359, the schedule's stack). */ + stackBare?: boolean; + /** An unrouted type's drawing. */ + drawing?: (P: string, m: Model, dyn: Dyn, level?: number) => VNode[]; + /** An unrouted type's least drawn width, measured (script only). */ + least?: (m: Model, tk: Tokens, measure: (text: string, font: RulerFont) => number) => number; + /** An unrouted type's layout (script only): the state to draw, its geometry and its ink. */ + layout?: (m: Model, kit: ExtMeasureKit) => Measured; + /** The figure's state's own attributes on the root: written and cleared with the layout. */ + rootStyle?: (m: Model, dyn: Dyn) => string[]; + /** The form before script runs (a gantt's stack "tracks" or "words"), written as `data-form` until the layout writes its own. */ + form?: (m: Model) => string | undefined; +} /** * Reads the author's data into the model. A problem the decision calls a development error is collected in `warnings`. Every value that @@ -279,7 +417,7 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model 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; } + for (const k of ["main", "plain", "dashed", "focal", "group", "activation", "line"] 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; @@ -310,20 +448,30 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const groups: Model["groups"] = []; const steps: MStep[] = []; const type = spec.type; - if (dev && !(["architecture", "flowchart", "data-flow", "sequence", "schema"] as unknown[]).includes(type)) warn(`"${String(type)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`); - - if (type === "architecture" || type === "flowchart") { + // A type of its own (DECISIONS 359) is read by its module, which its component handed over on the spec. + const ext = spec.ext && spec.ext.type === type ? spec.ext : undefined; + const asArch = ext?.as === "architecture"; + const kit: ExtBuildKit = { dev, warn, error, rtl: Boolean(options.rtl), legend }; + if (ext?.prepare) spec = ext.prepare(spec, kit); + let built: ExtBuilt | undefined; + if (dev && !ext && !(["architecture", "flowchart", "data-flow", "sequence", "schema", "state", "deployment"] as unknown[]).includes(type)) warn(`"${String(type)}" is not a type of diagram (architecture, flowchart, data-flow, sequence, schema, state or deployment), or its module is not loaded`); + + if (ext?.build) { + built = ext.build(spec, kit); + nodes.push(...built.nodes); + edges.push(...built.edges); + } else if (type === "architecture" || type === "flowchart" || asArch) { for (const raw of (spec.nodes ?? []) as Array) { const shape: Shape = type === "flowchart" && raw.shape === "decision" ? "decision" : type === "flowchart" && raw.shape === "terminal" ? "terminal" : "box"; const id = String(raw.id ?? ""); const row = trackOf(raw.row, `the row of ${id}`); nodes.push({ id, i: nodes.length, name: String(raw.name ?? ""), kind: shape === "decision" ? undefined : txt(raw.kind), detail: shape === "decision" ? undefined : txt(raw.detail), mono: Boolean(raw.detailMono), - focal: Boolean(raw.focal), col: trackOf(raw.col, `the column of ${id}`), row, row2: row, branch: Boolean(raw.branch), shape, group: type === "architecture" ? txt(raw.group) : undefined, - mark: type === "architecture" ? markOf((raw as { mark?: unknown }).mark, dev ? warn : undefined) : undefined, + focal: Boolean(raw.focal), col: trackOf(raw.col, `the column of ${id}`), row, row2: row, branch: Boolean(raw.branch), shape, group: type !== "flowchart" ? txt(raw.group) : undefined, + mark: type !== "flowchart" ? markOf((raw as { mark?: unknown }).mark, dev ? warn : undefined) : undefined, }); } - if (type === "architecture") { + if (type !== "flowchart") { 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. @@ -351,7 +499,8 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model const n = nodes.length + 1; 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, + // A step may be a decision (DECISIONS 359, Ops 5): the flowchart's diamond, with its step line inside it. + col: trackOf(raw.col, `the column of ${id}`), row: lane ?? 1, row2: lane ?? 1, branch: false, shape: (raw as { shape?: unknown }).shape === "decision" ? "decision" : "box", lane: lane ?? 1, laneLabel: lanes[(lane ?? 1) - 1]?.label ?? laneId, step: n, mark: markOf((raw as { mark?: unknown }).mark), }); } @@ -421,8 +570,8 @@ 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 (spec.layout === "auto" && autoType(type)) { + const raw = (type === "schema" ? spec.tables : type === "schedule" ? spec.tasks : 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; @@ -446,7 +595,7 @@ 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 && error(`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, a schema, a state, a deployment or a schedule, 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) => { @@ -494,7 +643,7 @@ 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 && 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") { + } else if (type !== "sequence" && (!ext || asArch)) { 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; } @@ -504,14 +653,23 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model 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 }); } + // A data flow's decision (DECISIONS 359, Ops 5): every line that leaves it has a label, and there are two or more. + if (dev && type === "data-flow") for (const n of nodes) if (n.shape === "decision") { + const out = edges.filter((e) => e.from === n.id); + if (out.length < 2) error(`the decision ${n.id} has ${out.length} line${out.length === 1 ? "" : "s"} leaving it: a decision has two or more`); + if (out.some((e) => !e.label)) error(`a line leaving the decision ${n.id} has no label: every line out of a decision says which way it is`); + } + if (type === "architecture" && spec.dependents) dependencyFold(spec, nodes, edges, legend, Boolean(spec.layout === "auto"), dev, error, warn); } else if (dev) { for (const s of steps) if ("n" in s) { if (!byId.has(s.from) || !byId.has(s.to)) warn(`message ${s.n} names ${!byId.has(s.from) ? s.from : s.to}, which is not a participant`); } } - // 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" && !unplaced) { + // Placement checks (development only): two nodes in one cell, a non-member inside a group's box, more than one focal node. A type of its own places its + // parts itself, and only a routed one is on the author's grid. + const gridded = !ext || ext.routed; + if (checks && type !== "sequence" && !unplaced && gridded) { const cells = new Map(); for (const n of nodes) for (let r = n.row; r <= n.row2; r++) { const key = `${n.col}:${r}`; @@ -530,8 +688,8 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model } for (const n of nodes) if (n.group && !groups.some((g) => g.id === n.group)) warn(`${n.id} names the group "${n.group}", which is not in groups`); if (nodes.filter((n) => n.focal).length > 1) warn("more than one node is focal: a diagram has one at most"); - // The key's words: main, dashed and the focal node must have them when drawn. - const kinds = new Set(type === "sequence" ? steps.flatMap((s) => ("n" in s ? [s.kind] : [])) : edges.map((e) => e.kind)); + // The key's words: main, dashed and the focal node must have them when drawn. A type of its own checks its own (its key's notation is built in). + const kinds = ext ? new Set() : new Set(type === "sequence" ? steps.flatMap((s) => ("n" in s ? [s.kind] : [])) : edges.map((e) => e.kind)); if (kinds.has("main") && !legend.main) warn("main lines are drawn but the legend has no words for them (legend.main)"); if (kinds.has("dashed") && !legend.dashed) warn("dashed lines are drawn but the legend has no words for them (legend.dashed)"); if (nodes.some((n) => n.focal) && !legend.focal) warn("a focal node is drawn but the legend has no words for what it marks (legend.focal)"); @@ -584,9 +742,12 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model 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" }; // 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) { + // A routed type of its own (the schedule) is on the author's grid or the placement's, as an architecture is: its tracks are its cards'. + const ownGrid = built && !ext!.routed; + let cols = ownGrid ? Math.max(1, built!.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. A type of its own + // that is not routed mirrors by logical properties, so its model is not mirrored. + if (options.rtl && gridded) { 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); } @@ -594,16 +755,66 @@ export function buildModel(spec: DiagramSpec, options: BuildOptions = {}): Model // 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, 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 }; + const rows = ownGrid ? Math.max(1, built!.rows) : type === "data-flow" ? Math.max(1, lanes.length) : Math.max(1, placed?.rows ?? 1, ...nodes.map((n) => n.row2)); + const model: Model = { ext, plan: built?.plan, dir: placed?.direction ?? (spec.direction === "down" ? "down" : undefined), 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 }; + ext?.adopt?.(model, spec, kit); 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. 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"); + if (checks && gridded && 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; } +/** + * A dependency figure (DECISIONS 359, Ops 4), an architecture with `dependents`: the engine owns three things. The count: each card's detail starts with + * the number of cards that have a line to it, in the author's words. The cycle: every line with both ends in one strongly connected set is dashed, in the + * direction it was written. The ranks are automatic layout's (longest path from the sources, diagram-layout). In an authored figure a line outside a cycle + * that does not end in a later column draws a development warning. + */ +function dependencyFold(spec: DiagramSpec, nodes: MNode[], edges: MEdge[], legend: DiagramLegend, auto: boolean, dev: boolean, error: (s: string) => void, warn: (s: string) => void) { + const words = spec.dependents!; + const one = String(words.one ?? "dependent"), other = String(words.other ?? "dependents"); + for (const n of nodes) { + const count = new Set(edges.filter((e) => e.to === n.id && e.from !== n.id).map((e) => e.from)).size; + if (dev && n.detail && /\b\d+\s+(dependents?|depend)/i.test(n.detail)) warn(`${n.id}'s detail writes a count: the engine writes each card's count of dependents, so write none by hand`); + n.detail = `${count} ${count === 1 ? one : other}${n.detail ? ` · ${n.detail}` : ""}`; + } + // The strongly connected sets (Tarjan's, without recursion): a line inside one is in a cycle. + const index = new Map(), low = new Map(), comp = new Map(); + const stack: string[] = [], on = new Set(); + let next = 0, comps = 0; + const out = (id: string) => edges.filter((e) => e.from === id).map((e) => e.to); + for (const root of nodes.map((n) => n.id)) { + if (index.has(root)) continue; + const work: Array<{ id: string; k: number }> = [{ id: root, k: 0 }]; + index.set(root, next); low.set(root, next++); stack.push(root); on.add(root); + while (work.length) { + const top = work[work.length - 1]!; + const kids = out(top.id); + if (top.k < kids.length) { + const w = kids[top.k++]!; + if (!index.has(w)) { index.set(w, next); low.set(w, next++); stack.push(w); on.add(w); work.push({ id: w, k: 0 }); } + else if (on.has(w)) low.set(top.id, Math.min(low.get(top.id)!, index.get(w)!)); + continue; + } + work.pop(); + if (work.length) low.set(work[work.length - 1]!.id, Math.min(low.get(work[work.length - 1]!.id)!, low.get(top.id)!)); + if (low.get(top.id) === index.get(top.id)) { let w: string; do { w = stack.pop()!; on.delete(w); comp.set(w, comps); } while (w !== top.id); comps++; } + } + } + const size = new Map(); + for (const c of comp.values()) size.set(c, (size.get(c) ?? 0) + 1); + const inCycle = (e: MEdge) => e.from === e.to || (comp.get(e.from) === comp.get(e.to) && (size.get(comp.get(e.from)!) ?? 0) > 1); + const cycles: string[] = []; + for (const e of edges) { + if (inCycle(e)) { e.kind = "dashed"; cycles.push(`${e.from} to ${e.to}`); continue; } + if (e.kind === "dashed") { dev && error(`the line from ${e.from} to ${e.to} is dashed and in no cycle: in a dependency figure dashed means a cycle, so it is drawn plain`); e.kind = "plain"; } + if (dev && !auto) { const a = nodes.find((n) => n.id === e.from)!, b = nodes.find((n) => n.id === e.to)!; if (b.col <= a.col) warn(`the line from ${e.from} to ${e.to} is in no cycle and does not end in a later column`); } + } + if (dev && cycles.length && !legend.dashed) error(`a cycle is drawn (${cycles.join(", ")}) but the key's dashed line has no words (legend.dashed)`); +} + /** * 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 @@ -686,7 +897,7 @@ function markUrl(u: string | undefined, warn?: (message: string) => void): strin const cssUrl = (u: string) => `url("${u.replace(/[\\"\n\r\f;]/g, (c) => (c === "\n" ? "\\a " : c === "\r" ? "\\d " : c === "\f" ? "\\c " : c === ";" ? "\\3b " : `\\${c}`))}")`; /** A value worked out once a model (the stack's plan, the sentences, the key and the list), kept on the model so a state change does not redo it. */ -function memo(m: Model, key: string, make: () => T): T { +export function memo(m: Model, key: string, make: () => T): T { if (!m.memo.has(key)) m.memo.set(key, make()); return m.memo.get(key) as T; } @@ -701,7 +912,7 @@ const said = (text: string) => text.replace(/\n/g, " "); // Words: sentences, the key, the list // ============================================================================================================================================ -const sentence = (s: string) => { const t = s.trim(); return !t ? "" : /[.!?]$/.test(t) ? t : `${t}.`; }; +export const sentence = (s: string) => { const t = s.trim(); return !t ? "" : /[.!?]$/.test(t) ? t : `${t}.`; }; /** A kind's word, from the key (none when the author gave none: an unkeyed plain line says "goes to"). */ export function kindWord(m: Model, kind: DiagramLineKind): string | undefined { return m.legend[kind]; } @@ -718,6 +929,7 @@ export function nodeSentence(m: Model, n: MNode): string { return memo(m, `sentence:${n.i}`, () => writeSentence(m, n)); } function writeSentence(m: Model, n: MNode): string { + if (m.ext?.sentence) return m.ext.sentence(m, n); const parts: string[] = []; if (m.type === "schema") { parts.push(`${n.name}, table.`); @@ -734,9 +946,10 @@ function writeSentence(m: Model, n: MNode): string { 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; + const what = m.type === "data-flow" ? `${m.stepWord(n.step!)} of ${m.nodes.length}, ${n.laneLabel}${n.shape === "decision" ? `, ${m.shapeLabels.decision.toLowerCase()}` : ""}` : 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 (m.ext?.sentenceMore) parts.push(...m.ext.sentenceMore(m, n)); // 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)})` : ""}`); @@ -780,6 +993,7 @@ export function tapTrace(fig: HTMLElement, P: string, event: MouseEvent, current /** The noun the key hint and the keys sentence use for one stop. */ function stopNoun(m: Model): string { + if (m.ext) return m.ext.stop; return m.type === "architecture" ? "a part" : m.type === "sequence" ? "a participant" : m.type === "schema" ? "a table" : "a step"; } @@ -792,8 +1006,9 @@ export interface VElement { t: string; a: VAttrs; c: VNode[] } export interface VSlot { slot: "source" | "summary" | "hint" | "toggle" } export type VNode = string | VElement | VSlot; -type VChild = VNode | null | undefined | false | VChild[]; -function h(t: string, a: VAttrs | null, ...c: VChild[]): VElement { +export type VChild = VNode | null | undefined | false | VChild[]; +/** A tree element. The type modules (DECISIONS 359) build their drawings with it. */ +export function h(t: string, a: VAttrs | null, ...c: VChild[]): VElement { const kids: VNode[] = []; for (const k of c.flat(Infinity as 1) as VChild[]) if (k !== null && k !== undefined && k !== false && !Array.isArray(k)) kids.push(k); return { t, a: a ?? {}, c: kids }; @@ -848,6 +1063,10 @@ export interface Dyn { 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; + /** A type of its own's form inside a layout (DECISIONS 359): a gantt's stack "tracks" or "words". Written as `data-form`. */ + form?: string; + /** A type of its own's measured places (DECISIONS 359): by part id, the style its part takes; "" keys the drawing's own. */ + place?: Record; /** A drawn layout of one column (the one-column ruling, diagrams-cimip): its column's least width, in px. The stylesheet caps the drawing at * size-breakpoint-container, or at this where it is more, so the cap never takes the track under its minimum. */ one?: number; @@ -858,12 +1077,14 @@ const idsOf = (base: string) => ({ title: `${base}-title`, summary: `${base}-sum /** Whether the figure's nodes are stops (a roving tab index) in this state. */ export function hasStops(m: Model, dyn: Dyn): boolean { + if (m.ext?.hasStops) return m.ext.hasStops(m, dyn); if (!dyn.layout || dyn.bare) return false; if (dyn.layout === "drawn") return true; return m.type !== "sequence" && m.type !== "schema"; } /** Whether the nodes are images named by a sentence in this state (before script, the types whose stack has lines). */ function nodesAreImages(m: Model, dyn: Dyn): boolean { + if (m.ext) return true; if (m.type === "sequence" || m.type === "schema") return dyn.layout === "drawn"; return true; } @@ -999,10 +1220,10 @@ function planStack(m: Model): StackPlan { // ---- Swatches: each drawn exactly as its mark ---- -const svgA = (w: number, hgt: number): VAttrs => ({ width: w, height: hgt, viewBox: `0 0 ${w} ${hgt}`, "aria-hidden": "true", focusable: "false" }); +export const svgA = (w: number, hgt: number): VAttrs => ({ width: w, height: hgt, viewBox: `0 0 ${w} ${hgt}`, "aria-hidden": "true", focusable: "false" }); /** A line swatch, 24 wide and 16 tall: the same stroke, dash and head as the line. */ -function lineSwatch(P: string, kind: DiagramLineKind | "fk"): VElement { +export function lineSwatch(P: string, kind: DiagramLineKind | "fk"): VElement { const k = kind === "fk" ? "plain" : kind; const y = k === "main" ? 8 : 8.5; const end = 24; @@ -1039,7 +1260,7 @@ export function cardMarks(form: DiagramCardinality, edge: number, y: number, out 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 { +export 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 })); return h("svg", { class: `${P}-swatch`, "data-shape": shape, ...svgA(16, 16) }, h("rect", { class: `${P}-swatch-shape`, x: 0.5, y: 2.5, width: 15, height: 11, rx: 2 })); @@ -1052,8 +1273,9 @@ function keyTree(P: string, m: Model): VElement | null { /** 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 { + if (m.ext?.key) return m.ext.key(P, m); const entries: VElement[] = []; - const entry = (swatch: VElement, words: string, attrs: VAttrs = {}) => entries.push(h("li", { class: `${P}-entry`, ...attrs }, swatch, h("span", null, words))); + const entry = (swatch: VElement, words: string, attrs: VAttrs = {}) => entries.push(h("li", { class: `${P}-entry`, ...attrs }, swatch, h("span", null, iso(words)))); if (m.type === "schema") { // The key seats' letters first, each where a seat holds it, set as the seat sets them, then their words. const keys = new Set(m.nodes.flatMap((n) => (n.columns ?? []).map((c) => c.key))); @@ -1061,6 +1283,11 @@ function buildKey(P: string, m: Model): VElement | null { if (keys.has(k)) entries.push(h("li", { class: `${P}-entry` }, h("span", { class: `${P}-key-letters`, "aria-hidden": "true" }, k), h("span", null, words))); } } + if (m.type === "data-flow" && m.nodes.some((n) => n.shape === "decision")) { + // Where a data flow draws a decision, shape carries type: the key shows "Step" and "Decision", as a flowchart's does (DECISIONS 359, Ops 5). + entry(boxSwatch(P, "box"), m.shapeLabels.step); + entry(boxSwatch(P, "decision"), m.shapeLabels.decision); + } if (m.type === "flowchart") { const used = new Set(m.nodes.map((n) => n.shape)); if (used.has("terminal")) entry(boxSwatch(P, "terminal"), m.shapeLabels.terminal); @@ -1088,6 +1315,7 @@ 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.ext?.keyMore) entries.push(...m.ext.keyMore(P, m)); // 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); @@ -1110,16 +1338,17 @@ function inlineArrow(P: string, kind: DiagramLineKind): VElement { /** 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). */ /** An author's string as a first-strong isolate (``, the diagrams-rtl ruling): it keeps its own order in a figure set right to left, so a closing quote, * bracket or full stop stays at its end. Nothing changes left to right. */ -const iso = (text: string): VElement => h("bdi", null, text); -function linkName(P: string, n: MNode): VChild { +export const iso = (text: string): VElement => h("bdi", null, text); +export function linkName(P: string, n: MNode): VChild { // A linked name is not isolated: its cue is drawn after its last word and must stay at the line's end in the figure's direction. if (!n.href) return iso(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` }, linkName(P, n)))]; +export function nodeText(P: string, m: Model, n: MNode): VChild[] { + // A data flow's decision (DECISIONS 359, Ops 5) writes its step line inside the diamond, above its name. + if (n.shape === "decision") return [h("span", { class: `${P}-words` }, m.type === "data-flow" && n.kind ? h("span", { class: `${P}-kind` }, iso(n.kind)) : null, h("span", { class: `${P}-name` }, linkName(P, n)))]; const kids: VNode[] = []; if (m.type === "data-flow") kids.push(h("span", { class: `${P}-kind` }, iso(n.kind!), h("span", { class: `${P}-lane-word` }, " · ", iso(n.laneLabel ?? "")))); else if (n.kind) kids.push(h("span", { class: `${P}-kind` }, iso(n.kind))); @@ -1129,13 +1358,12 @@ function nodeText(P: string, m: Model, n: MNode): VChild[] { 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)])) : iso(n.detail))); return kids; } - 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), + h("span", { class: `${P}-cname` }, iso(c.name)), c.ref ? h("span", { class: `${P}-ctype`, "data-ref": "" }, `${m.rtl ? "←" : "→"} `, iso(c.ref.table)) : c.type ? h("span", { class: `${P}-ctype` }, iso(c.type)) : null))), n.more ? h("span", { class: `${P}-more` }, `+ ${n.more} more`) : null, ]; @@ -1155,6 +1383,9 @@ function nodeTree(ctx: TreeContext, m: Model, n: MNode, dyn: Dyn): VElement { // 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}`]; + // The row a box starts on stands space-4 lower (the run-edge ruling): the gap above it is space-16, and space-8 of it is clear above the box. An + // architecture's alone (a deployment's too, read as one); a state's row gap already holds the band. Written 0 or 1, so a new placement never keeps a stale 1. + if (lowers(m)) style.push(`--_lo:${n.row > 1 && m.groups.some((g) => groupCells(m, g)?.r1 === n.row) ? 1 : 0}`); 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; @@ -1182,6 +1413,7 @@ function nodeTree(ctx: TreeContext, m: Model, n: MNode, dyn: Dyn): VElement { "data-shape": n.shape, "data-focal": n.focal ? "" : undefined, "data-branch": n.branch ? "" : undefined, + ...m.ext?.nodeAttrs?.(m, n), "data-mark": n.mark ? n.mark.id ?? "" : undefined, "data-level": ctx.level, style: style.join(";"), @@ -1192,22 +1424,24 @@ 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, m) : nodeText(P, m, n)); + n.shape === "table" ? tableText(P, n, m) : m.ext?.card ? m.ext.card(P, m, n, dyn) : nodeText(P, m, n)); } function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { const { P } = ctx; + if (m.ext?.drawing) return m.ext.drawing(P, m, dyn, ctx.level); const out: VNode[] = []; if (m.type === "data-flow") { - out.push(...m.lanes.map((l, k) => h("div", { class: `${P}-lane`, style: `--_r:${k + 1}`, "aria-hidden": "true" }, h("span", { class: `${P}-lane-name` }, l.label)))); + out.push(...m.lanes.map((l, k) => h("div", { class: `${P}-lane`, style: `--_r:${k + 1}`, "aria-hidden": "true" }, h("span", { class: `${P}-lane-name` }, iso(l.label))))); } - if (m.type === "architecture") { + if (grouped(m.type)) { for (const g of m.groups) { const c = groupCells(m, g); if (!c) continue; + const mark = m.ext?.groupMark?.(m, g, c); // 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` }, iso(g.label)))); + 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}${lowers(m) ? `;--_lo:${c.r1 > 1 ? 1 : 0}` : ""}${lv[0]! > 1 ? ";--_gt:2" : ""}${lv[1]! > 1 ? ";--_ge:2" : ""}${lv[2]! > 1 ? ";--_gb:2" : ""}${lv[3]! > 1 ? ";--_gs:2" : ""}${mark?.style ?? ""}`, "data-start": mark?.start, "aria-hidden": "true" }, h("span", { class: `${P}-glabel` }, iso(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; @@ -1233,7 +1467,7 @@ function drawingChildren(ctx: TreeContext, m: Model, dyn: Dyn): VNode[] { // 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" }, iso(g.label)), kids); + return h("div", { class: `${P}-group`, "data-group": g.id, "data-depth": g.depth > 1 ? g.depth : undefined, "data-turn": turns.length ? "" : undefined, "data-start": ctx.plan ? m.ext?.groupMark?.(m, g, null)?.start : undefined, style: style || undefined }, h("span", { class: `${P}-glabel`, "aria-hidden": "true" }, iso(g.label)), kids); }; let k = 0; while (k < m.nodes.length) { @@ -1294,7 +1528,7 @@ function sequenceSteps(ctx: TreeContext, m: Model): VElement { 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; into().push(h("p", { class: `${P}-band` }, h("span", null, s.band))); continue; } + if ("band" in s) { list = null; into().push(h("p", { class: `${P}-band` }, h("span", null, iso(s.band)))); continue; } if ("open" in s) { list = null; const parent = stack[stack.length - 1]; @@ -1302,14 +1536,14 @@ function sequenceSteps(ctx: TreeContext, m: Model): VElement { 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))); + 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]}: `), iso(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))); + 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}: `), iso(s.otherwise)))); continue; } if ("close" in s) { list = null; stack.pop(); continue; } @@ -1321,9 +1555,9 @@ function sequenceSteps(ctx: TreeContext, m: Model): VElement { 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)), - 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)); + h("span", { class: `${P}-said` }, h("span", { class: `${P}-num` }, String(s.n)), h("span", { class: `${P}-mlabel` }, iso(s.label))), + h("span", { class: `${P}-route` }, iso(a?.short ?? s.from), " ", h("span", { class: `${P}-to` }, inlineArrow(P, s.kind), h("span", { class: ctx.hidden }, " to "), " ", iso(b?.short ?? s.to), word ? [" · ", iso(word)] : "")), + s.note ? h("span", { class: `${P}-note` }, iso(s.note)) : null)); } return h("div", { class: `${P}-steps` }, root); } @@ -1336,29 +1570,33 @@ function listTree(P: string, m: Model): VNode[] { /** 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[] { + if (m.ext?.list) return m.ext.list(P, m); const sub = Math.min(6, m.heading + 1); + // Every string an author writes is a first-strong isolate in the list too (DECISIONS 359, Ops 6). const H = (text: string) => h(`h${sub}`, { class: `${P}-list-head` }, text); - const strong = (s: string) => h("strong", null, s); + const strong = (s: string) => h("strong", null, iso(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 code = (s: string) => h("code", { class: `${P}-code` }, iso(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, 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")]; + if (grouped(m.type)) { + const extra = (n: MNode): VChild[] => m.ext?.listPart?.(P, m, n) ?? []; + const part = (n: MNode) => h("li", null, named(n), n.kind ? [", ", iso(n.kind)] : "", n.detail ? [". ", n.mono ? code(n.detail) : iso(n.detail), /[.!?]$/.test(n.detail) ? "" : "."] : /[.!?]$/.test(n.kind ?? n.name) ? "" : ".", extra(n), focal(n)); + const out: VNode[] = [H(m.ext?.listParts ?? "Parts")]; const loose = m.nodes.filter((n) => !n.group); if (loose.length) out.push(h("ul", { class: `${P}-list-items` }, loose.map(part))); // 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("p", { class: `${P}-list-group` }, iso(g.label))); 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("p", { class: `${P}-list-group`, "data-depth": 2 }, iso(c.label))); out.push(h("ul", { class: `${P}-list-items`, "data-depth": 2 }, c.members.map((id) => part(m.byId.get(id)!)))); } } + if (m.ext?.listLines) { out.push(...m.ext.listLines(P, m, H)); return out; } 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)}.`)))); return out; @@ -1369,14 +1607,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, named(n), 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) : iso(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}: `, named(n), n.detail ? [", ", n.mono ? code(n.detail) : n.detail] : "", ".", focal(n), + return h("li", null, iso(n.laneLabel ?? ""), ": ", named(n), n.detail ? [", ", n.mono ? code(n.detail) : iso(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)]), "."] : ""); }))]; } @@ -1411,7 +1649,8 @@ function buildList(P: string, m: Model): VNode[] { /** 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"; + if (m.ext?.keys) return m.ext.keys(m, drawn); + const noun = m.ext ? m.ext.stop.replace(/^an? /, "") : 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`; // 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." : ""}`; @@ -1419,6 +1658,7 @@ function keysSentence(m: Model, drawn = false): string { /** 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 }> { + if (m.ext?.hint) return m.ext.hint(m, drawn); const four = drawn && m.type !== "sequence" && spatialTable(m) && m.cols > 1 && m.rows > 1; 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" }]; @@ -1522,21 +1762,26 @@ const oneColumnTurnBacks = (m: Model) => m.type === "schema" && m.cols === 1 && export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { const P = o.prefix; const ids = idsOf(o.base); - const plan = m.type === "sequence" || m.type === "schema" ? null : stackPlan(m); + const plan = m.type === "sequence" || m.type === "schema" || (m.ext && !m.ext.routed) ? null : stackPlan(m); const ctx: TreeContext = { P, ids, level: o.level, plan, hidden: o.hiddenClass }; const drawn = dyn.layout === "drawn"; const stops = hasStops(m, dyn); const group = m.type === "sequence" || m.type === "schema" ? drawn : true; const Head = `h${m.heading}`; const style: string[] = [`--_cols:${columnCount(m)}`]; - if ((m.type === "architecture" && m.groups.length) || (drawn && dyn.pad)) { + // A state's start mark on the drawing's start column takes space-10 more on that side (DECISIONS 359, Ops 1), whether or not its group does. + // A type's own marks on the drawing's edge take room there (a state's start mark: space-10 at the start, or above when laid down). + const roomAt = m.ext?.room?.(m); + const startRoom = roomAt?.start, topRoom = roomAt?.top; + if ((grouped(m.type) && m.groups.length) || (drawn && dyn.pad) || startRoom || topRoom) { // 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. // 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 e: [number, number, number, number] = grouped(m.type) ? 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(e[0], "8", block)} ${pad(e[1], "4")} ${pad(e[2], "4", block)} ${pad(e[3], "4")}`); + const room = (side: string) => (startRoom ? `calc(${side} + var(--basalt-space-10))` : side); + style.push(`--_gpad:${topRoom ? `calc(${pad(e[0], "8", block)} + var(--basalt-space-10))` : pad(e[0], "8", block)} ${m.rtl ? room(pad(e[1], "4")) : pad(e[1], "4")} ${pad(e[2], "4", block)} ${m.rtl ? pad(e[3], "4") : room(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). @@ -1552,25 +1797,29 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { } if (m.type === "schema" && dyn.track) style.push(`--_track:${dyn.track}px`); if (drawn && dyn.one) style.push(`--_one:${dyn.one}px`); + if (m.ext?.rootStyle) style.push(...m.ext.rootStyle(m, dyn)); return h("figure", { class: o.className ? `${P} ${o.className}` : P, "aria-labelledby": ids.title, "data-type": m.type, "data-cols": columnCount(m), - "data-reach": m.type === "architecture" ? groupReach(m) : undefined, + "data-reach": grouped(m.type) ? groupReach(m) : undefined, "data-gutter": plan?.gutter ? "" : undefined, "data-marks": m.marks ? "" : undefined, + // A data flow that draws a decision gives every step the contour (DECISIONS 359, Ops 5). + "data-contour": m.type === "data-flow" && m.nodes.some((n) => n.shape === "decision") ? "" : undefined, // 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-form": dyn.form ?? (dyn.layout ? undefined : m.ext?.form?.(m)), "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(";"), }, - h("div", { class: `${P}-head` }, h(Head, { id: ids.title, class: `${P}-title` }, iso(m.title)), o.hasSource ? h("p", { class: `${P}-source` }, h("bdi", null, { slot: "source" })) : null), + h("div", { class: `${P}-head` }, h(Head, { id: ids.title, class: `${P}-title` }, iso(m.title)), (() => { const lead = m.ext?.sourceLead?.(m); return o.hasSource || lead ? h("p", { class: `${P}-source` }, lead ? [h("bdi", null, lead), o.hasSource ? " · " : ""] : null, o.hasSource ? h("bdi", null, { slot: "source" }) : null) : null; })(), m.ext?.meta?.(P, m) ?? 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. @@ -1585,7 +1834,7 @@ export function figureTree(m: Model, dyn: Dyn, o: FigureOptions): VElement { 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, + (m.ext ? m.ext.traces?.(m, drawn) : 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)), @@ -1677,7 +1926,7 @@ export function readTokens(el: Element): Tokens { } const strokeOf = (kind: DiagramLineKind, tk: Tokens) => (kind === "main" ? tk.line : tk.hair); -const rectOf = (el: Element, origin: DOMRect): Rect => { const r = el.getBoundingClientRect(); return { l: r.left - origin.left, t: r.top - origin.top, r: r.right - origin.left, b: r.bottom - origin.top }; }; +export const rectOf = (el: Element, origin: DOMRect): Rect => { const r = el.getBoundingClientRect(); return { l: r.left - origin.left, t: r.top - origin.top, r: r.right - origin.left, b: r.bottom - origin.top }; }; const hit = (a: Rect, b: Rect, eps = 0.01) => a.l < b.r - eps && a.r > b.l + eps && a.t < b.b - eps && a.b > b.t + eps; const grow = (a: Rect, p: number): Rect => ({ l: a.l - p, r: a.r + p, t: a.t - p, b: a.b + p }); @@ -1755,16 +2004,17 @@ const forced = () => matchMedia("(forced-colors: active)").matches; function ruler(drawing: Element, P: string) { const el = drawing.querySelector(`.${P}-ruler`)!; const known = new Map(); - return (text: string, font: "name" | "name-500" | "mono" | "sans" | "table" | "label") => { + return (text: string, font: RulerFont) => { const key = `${font}|${text}`; if (!known.has(key)) { el.setAttribute("data-f", font); el.textContent = text; known.set(key, el.getBoundingClientRect().width); el.textContent = ""; } return known.get(key)!; }; } -const words = (s?: string) => (s ? s.split(/\s+/).filter(Boolean) : []); +export const words = (s?: string) => (s ? s.split(/\s+/).filter(Boolean) : []); /** The figure's measured minimums (1.11, rule 2): the widest unbreakable word of any node, a table's widest row, on top of the tokens. */ function minimums(m: Model, tk: Tokens, measure: ReturnType) { + if (m.ext?.least && !m.ext.routed) { const least = Math.max(tk.wide, m.ext.least(m, tk, measure)); return { track: tk.node, table: tk.table, least, own: least }; } const s = tk.space; let track = tk.node; let table = tk.table; @@ -1944,7 +2194,7 @@ function assignSlots(m: Model, sides: Array<[DiagramSide, DiagramSide]>, warn: ( 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; + if (m.type !== "architecture" && m.type !== "flowchart" && m.type !== "data-flow" && m.type !== "schedule" && m.type !== "state" && m.type !== "deployment") 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, () => {})) { @@ -2258,6 +2508,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge }; nestCorridors(); + const { obstacles, groups } = obstaclesOf(drawing, origin, P, rowGap); // 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 }>(); @@ -2423,6 +2674,23 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge 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; }; + // The clear band (the run-edge ruling): a box's edge is a line. A gap's lanes keep its middle while each is space-3 clear of every box edge beside them; where one is + // not, they are laid in the part of the gap outside those boxes. A band with no room for them (space-2 a lane) is not drawn in. + const tight: number[] = []; + const bandOf = (g: { span: [number, number]; vertical: boolean }, cluster: Cluster, count: number): [number, number] => { + const [p, q] = g.span, to = Math.max(...cluster.map((c) => c.run[1])), step = (q - p) / (count + 1); + let a = p, b = q; + for (const r of groups) { + const [lo, hi, r1, r2] = g.vertical ? [r.l, r.r, r.t, r.b] : [r.t, r.b, r.l, r.r]; + if (r2 <= cluster[0]!.run[0] || r1 >= to) continue; + if (lo > a && lo < b) b = lo; + if (hi > a && hi < b) a = hi; + } + // The gap's own lanes stand: the first and the last are space-3 clear of the edges. + if (!(a > p && p + step < a + s("3")) && !(b < q && q - step > b - s("3"))) return g.span; + if ((b - a) / (count + 1) < s("2")) tight.push(...cluster.flatMap((c) => c.members.map(edgeOf))); + return [a, b]; + }; // An interior corridor's two lanes: the order that crosses least. nestCorridors(); for (const [key, groups] of corridorGroups) { @@ -2446,7 +2714,8 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge // 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, g.vertical)))); + const span = bandOf(g, cluster, need); + const set = (slots: number[]) => slots.forEach((l, i) => groupsOf[i]!.forEach((k) => lanes.set(k, laneAt(span, l, need, g.vertical)))); 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++) { @@ -2463,15 +2732,16 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge continue; } const count = groupsOf.length; - 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 span = bandOf(g, cluster, count); + if (dev && !m.marks && (span[1] - span[0]) / (count + 1) < s("3")) warn?.(`${[...new Set(groupsOf.flat().map(edgeOf))].map((k) => { const e = m.edges[k]; return e ? `${m.byId.get(e.from)?.name} to ${m.byId.get(e.to)?.name}` : ""; }).join(", ")} ${count > 1 ? "run" : "runs"} closer than space-3 a lane${span !== g.span ? " beside a box's edge" : ""}`); 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, laneAt(g.span, j, count, g.vertical)))); + perm.forEach((members, j) => members.forEach((k) => lanes.set(k, laneAt(span, j, count, g.vertical)))); 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, laneAt(g.span, j, count, g.vertical)))); + best.forEach((members, j) => members.forEach((k) => lanes.set(k, laneAt(span, j, count, g.vertical)))); current = bestLines; } } @@ -2497,7 +2767,6 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge geo.crossings = findCrossings(geo.lines); geo.through = throughOf(geo.lines, nodes, m); geo.outside = outsideOf(geo.lines, W, H, tk); - const { obstacles, groups } = obstaclesOf(drawing, origin, P, rowGap); obstacles.heads = geo.lines.map((l) => headBox(l, tk)); const seats = seatLabels(m, geo.lines, nodes, obstacles, groups, { l: 0, t: 0, r: W, b: H }, tk, measure, { ox, oy }); geo.labels = seats.labels; @@ -2505,7 +2774,7 @@ function drawnGeometry(input: DrawnInput, measure: ReturnType): Ge geo.bounded = seats.bounded; // Two lines on one another that are not a bus (a one-column schema's turn-backs to different keys, with no gutter to give each a lane) read as // one line: the drawn layout is refused, as a line through a node is. - geo.overlaps = [...new Set(overlapPairs(geo.lines, null).flat())]; + geo.overlaps = [...new Set([...overlapPairs(geo.lines, null).flat(), ...tight])]; return geo; } @@ -2939,7 +3208,7 @@ 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 { +export function inkHtml(P: string, geo: Geo, tk: Tokens, base: string, more = ""): string { const { defs, ids } = masksMarkup(P, geo, tk, base); // 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). @@ -2947,10 +3216,10 @@ export function inkHtml(P: string, geo: Geo, tk: Tokens, base: string): string { 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 under = lifelines ? `${lifelines}` : ""; - const svg = `${under}${defs ? `${defs}` : ""}${bars}${lines}`; + const svg = `${under}${defs ? `${defs}` : ""}${bars}${lines}${more}`; // A label's place is not in the string: a style attribute in markup written as HTML is refused under a strict `style-src` (no 'unsafe-inline'), so // placeLabels sets it through the CSSOM once the ink is in the page. - const labels = geo.labels.map((l) => ` 1 ? ' data-lines="2"' : ""}>${l.text.split("\n").map(escapeHtml).join("
")}
`).join(""); + const labels = geo.labels.map((l) => ` 1 ? ' data-lines="2"' : ""}>${l.text.split("\n").map(escapeHtml).join("
")}
`).join(""); return svg + labels; } @@ -3002,7 +3271,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin let tall = false; const heightsFor = (d: Dyn): Dyn => { tall = false; - if (m.type !== "flowchart") return d; + if (m.type !== "flowchart" && !(m.type === "data-flow" && m.nodes.some((n) => n.shape === "decision"))) return d; apply({ ...d, heights: undefined, words: undefined }); const heights = record(); const widened = record(); @@ -3050,6 +3319,8 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin 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 }; + // A type of its own that is not routed (DECISIONS 359) lays itself out: the engine gives it the figure, the state and the ruler. + if (m.ext?.layout && !m.ext.routed) return m.ext.layout(m, { fig, drawing, P, tk, W, least: mins.least, apply, stopOf, current: { ...current, ...closed }, measure, warn }); if (W >= mins.least && !m.unplaced) { const drawnTry = (pad: boolean) => { // One column (not a sequence's participants) is capped before it is measured (the one-column ruling): its least width is written with the layout. @@ -3073,9 +3344,10 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin const padded = drawnTry(true); if (!refused(padded.g) && !padded.g.unseated.length) ({ dd: d, g: geo } = padded); } - if (!refused(geo) && !geo.unseated.length) { + const more = !refused(geo) && !geo.unseated.length ? m.ext?.inkMore?.(P, m, geo, tk, true, warn) : false; + if (more !== false) { 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, least: mins.least }; + return { dyn: d, geo, ink: inkHtml(P, geo, tk, base, more), 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`); @@ -3088,7 +3360,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, rows: undefined, one: undefined }); d = heightsFor(d); apply(d); - if (m.type === "sequence" || m.type === "schema") return { dyn: d, geo: null, ink: "", tokens: tk, least: mins.least }; + if (m.type === "sequence" || m.type === "schema" || m.ext?.stackBare) 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++) { @@ -3121,7 +3393,7 @@ export function measureFigure(fig: HTMLElement, m: Model, P: string, base: strin } if (geo.seatless?.length) dev && warn?.(`a stacked group's label has no clear seat on its top edge: ${geo.seatless.map((t) => `"${t}"`).join(", ")}`); 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, least: mins.least }; + return { dyn: d, geo, ink: inkHtml(P, geo, tk, base, m.ext?.inkMore?.(P, m, geo, tk, false) || ""), tokens: tk, least: mins.least }; } function lineName(m: Model, l: GLine): string { @@ -3145,6 +3417,8 @@ export function applyTrace(fig: HTMLElement, P: string, geo: Geo | null, tokens: } fig.toggleAttribute("data-tracing", Boolean(id)); fig.querySelectorAll(`.${P}-node`).forEach((el) => el.toggleAttribute("data-near", near.has(el.dataset.node!))); + // A mark in the ink that belongs to one part (a timeline's stem and dot, DECISIONS 359) lifts with it; nothing else dims. + fig.querySelectorAll(`.${P}-ink [data-for]`).forEach((el) => el.toggleAttribute("data-lit", Boolean(id) && el.getAttribute("data-for") === id)); if (!geo || !tokens) return; const lit = (l: GLine) => Boolean(id) && (l.from === id || l.to === id); const edges = fig.querySelector(`.${P}-edges`); @@ -3214,6 +3488,7 @@ 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, drawn = false, rtl = false): string | null { + if (m.ext?.keyTarget) return m.ext.keyTarget(m, from, key, drawn, rtl); // 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")) { @@ -3242,8 +3517,10 @@ 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", "--_tl", "--_gpad", "--_gw", "--_mh", "--_rows", "--_row-gap", "--_one"]; +const ROOT_MANAGED = ["data-layout", "data-measured", "data-bare", "data-form", "data-contour", "data-motion", "data-first-visit", "data-rtl", "data-cols", "data-reach", "data-gutter", "data-marks"]; +// A type of its own (DECISIONS 359) writes its measured places as these: a timeline's card (--_tx, --_ty), its drawing's height (--_th), a gantt's or a +// matrix's measured columns (--_name, --_track). +const MANAGED_STYLE = ["--_lo", "--_track", "--_h", "--_ww", "--_gap", "--_ggrow", "--_tl", "--_gpad", "--_gw", "--_mh", "--_rows", "--_row-gap", "--_one", "--_tx", "--_ty", "--_th", "--_tw", "--_tdw", "--_name", "--_lab"]; 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-figure.tsx b/packages/react/src/diagram-figure.tsx index dcfc28cb..e7c5392e 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, placeLabels, tapTrace, transcript, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, + applyTrace, autoType, buildModel, placeLabels, tapTrace, transcript, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, } from "./diagram-core"; import type { DiagramLegend, DiagramMotion, DiagramPlacement, DiagramSpec, Dyn, Geo, Measured, Model, VNode } from "./diagram-core"; import type { MotionController } from "./diagram-motion-core"; @@ -195,12 +195,12 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, onLayout, // 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); // 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 auto = spec.layout === "auto" && autoType(spec.type); const given = React.useMemo(() => (spec.placement ? (Array.isArray(spec.placement) ? spec.placement : [spec.placement]) : []), [spec.placement]); const [loaded, setLoaded] = React.useState(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 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]), (spec.tasks as Array<{ id: string; after?: string[] }> | undefined)?.map((t) => [t.id, t.after]), Boolean(spec.dependents)]) : ""), [auto, spec.type, spec.tables, spec.nodes, spec.edges, spec.groups, spec.tasks, spec.dependents]); const placing = React.useRef(null); const placedFor = React.useRef(placedFrom); if (placedFor.current !== placedFrom) { placedFor.current = placedFrom; placing.current = null; if (loaded) setLoaded(null); } @@ -292,7 +292,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, onLayout, // 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 }; + const input = { type: spec.type as "architecture" | "flowchart" | "schema" | "state" | "deployment" | "schedule", nodes: spec.nodes as Array<{ id: string; group?: string }>, tables: spec.tables, edges: spec.edges, groups: spec.groups, dependents: spec.dependents, tasks: spec.tasks as Array<{ id: string; after?: string[] }> | undefined }; 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) => { diff --git a/packages/react/src/diagram-layout-graph.ts b/packages/react/src/diagram-layout-graph.ts index 97a34df4..14cfdb2e 100644 --- a/packages/react/src/diagram-layout-graph.ts +++ b/packages/react/src/diagram-layout-graph.ts @@ -12,7 +12,9 @@ export interface ElkNode { id: string; width?: number; height?: number; x?: numb // 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 => ({ +// A dependency figure (DECISIONS 359, Ops 4) is layered by longest path from the sources, so a card nothing depends on is in the first column. +const options = (direction: "right" | "down", longest = false): Record => ({ + ...(longest ? { "elk.layered.layering.strategy": "LONGEST_PATH_SOURCE" } : {}), "elk.algorithm": "layered", "elk.direction": direction === "right" ? "RIGHT" : "DOWN", "elk.randomSeed": "1", @@ -30,13 +32,16 @@ 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 cards: Card[] = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name) })) : input.type === "schedule" ? (input.tasks ?? []).map((t) => ({ id: String(t.id) })) : (input.nodes ?? []).map((n) => ({ id: String(n.id), group: n.group })); + // A schedule's lines are its tasks' `after` (DECISIONS 359, Planning 1.6). 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" })); + : input.type === "schedule" + ? (input.tasks ?? []).flatMap((t) => (t.after ?? []).map((a) => ({ from: String(a), to: String(t.id), 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 ?? [] : [] }; + return { cards, lines, groups: input.type === "architecture" || input.type === "state" || input.type === "deployment" ? input.groups ?? [] : [] }; } /** @@ -58,7 +63,7 @@ export function mainInTheMiddle(lines } /** 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 { +export function graphOf(cards: Card[], lines: Line[], groups: DiagramGroup[], direction: "right" | "down", longest = false, inOrder = false): 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 }); @@ -70,11 +75,18 @@ export function graphOf(cards: Card[], lines: Line[], groups: DiagramGroup[], di 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) && !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 } } : {}) })) }; + // A state's and a deployment's groups (DECISIONS 359) are handed over in the author's order, each box where its first card is: cycle breaking reads the + // model's order, so a group's box after the cards outside it would turn every line out of the group back (a state's final states in the first layer). + if (inOrder) { + const first = (n: ElkNode): number => (n.children ? Math.min(Infinity, ...n.children.map(first)) : cards.findIndex((c) => c.id === n.id)); + const sort = (list: ElkNode[]) => { list.sort((a, b) => first(a) - first(b)); for (const n of list) if (n.children) sort(n.children); }; + sort(children); + } + return { id: "root", layoutOptions: options(direction, longest), 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); + return graphOf(cards, mainInTheMiddle(lines), groups, direction, Boolean(input.dependents), input.type === "state" || input.type === "deployment"); } diff --git a/packages/react/src/diagram-layout.ts b/packages/react/src/diagram-layout.ts index 7a126c7b..0d117de4 100644 --- a/packages/react/src/diagram-layout.ts +++ b/packages/react/src/diagram-layout.ts @@ -9,7 +9,11 @@ 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 { - type: "architecture" | "flowchart" | "schema"; + type: "architecture" | "flowchart" | "schema" | "state" | "deployment" | "schedule"; + /** A dependency figure (DECISIONS 359): layered by longest path from the sources. */ + dependents?: unknown; + /** A schedule's tasks: its lines are their `after`. */ + tasks?: Array<{ id: string; after?: string[] }>; nodes?: Array<{ id: string; group?: string }>; tables?: SchemaTable[]; edges?: DiagramEdge[]; @@ -80,7 +84,9 @@ function unusable(cards: Card[], groups: DiagramGroup[], cells: Cells): boolean 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 longest = Boolean(input.dependents); + const inOrder = input.type === "state" || input.type === "deployment"; + const first = await cellsOf(graphOf(cards, lines, groups, direction, longest, inOrder)); const layer = (id: string) => (direction === "down" ? first[id]!.row : first[id]!.col); // 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; }; @@ -111,7 +117,7 @@ export async function placeDiagram(input: DiagramPlacementInput, direction: "rig } 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 second = await cellsOf(graphOf(all, chained, groups, direction, longest, inOrder)); 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. From 4229371d2ffb491322c2594a641e5a78cf0e4208 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:00 -0600 Subject: [PATCH 03/12] Diagrams: the state and the deployment, each its own module (DECISIONS 359, Ops 1 and 3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit StateDiagram: the engine's labels, numbered guards, the start mark and the final mark, entry and exit. The start mark as the ruling on the gap has it (state-gap/ruling.md): the figure's own before its initial state on the side it reads from, a composite's above its initial state in every layout; its room is new room (the row stands space-10 lower, or the drawing's top edge keeps space-10 more), and a mark never lies on a line, a label or another mark, else the figure is stacked with a warning that names the state. DeploymentDiagram: the environment, artifacts as rows, replicas as × n. Not in this build: a transition to a composite state's boundary, a line landing on its artifact's row, and the third group level (it ships only with its label seat and line cut). Co-Authored-By: Claude Opus 5.5 --- packages/react/src/deployment-diagram.tsx | 32 ++++ packages/react/src/diagram-deployment.ts | 91 +++++++++++ packages/react/src/diagram-state.ts | 189 ++++++++++++++++++++++ packages/react/src/state-diagram.tsx | 31 ++++ 4 files changed, 343 insertions(+) create mode 100644 packages/react/src/deployment-diagram.tsx create mode 100644 packages/react/src/diagram-deployment.ts create mode 100644 packages/react/src/diagram-state.ts create mode 100644 packages/react/src/state-diagram.tsx diff --git a/packages/react/src/deployment-diagram.tsx b/packages/react/src/deployment-diagram.tsx new file mode 100644 index 00000000..ef77813b --- /dev/null +++ b/packages/react/src/deployment-diagram.tsx @@ -0,0 +1,32 @@ +import * as React from "react"; + +import type { DeploymentNode, DiagramFlowEdge, DiagramGroup, DiagramPlacement } from "./diagram-core"; +import { DiagramFigure } from "./diagram-figure"; +import { deploymentType } from "./diagram-deployment"; +import type { DiagramFigureProps } from "./diagram-figure"; + +export type { DeploymentArtifact, DeploymentNode, DiagramFlowEdge, DiagramGroup, DiagramLegend, DiagramLineKind, DiagramMark, DiagramPlacement, DiagramSide } from "./diagram-core"; +export type { DiagramAction, DiagramActionContext, DiagramFigureProps, DiagramLayoutInfo } from "./diagram-figure"; + +export interface DeploymentDiagramProps extends DiagramFigureProps { + /** The one environment the figure shows ("Production · us-east-1"): required, the first words of its source line. */ + environment: string; + /** The hosts, in the author's order. `replicas` (2 or more) draws `× 3`; `artifacts` are its rows, which a line may name. */ + nodes: DeploymentNode[]; + /** The boundaries: accounts, networks, subnets. */ + groups?: DiagramGroup[]; + /** The lines, by host or artifact id. Every line has a label. */ + edges: DiagramFlowEdge[]; + layout?: "authored" | "auto"; + direction?: "right" | "down"; + placement?: DiagramPlacement | DiagramPlacement[]; +} + +/** + * A deployment diagram (DECISIONS 359): one environment a figure. An artifact is a row of its host card, as a schema's column is of its table; `× 3` at + * the end of a host's kind line says how many copies run. The implementation has not been reviewed. + */ +export function DeploymentDiagram({ environment, nodes, groups, edges, layout, direction, placement, motion, entrance, title, heading, legend, ...props }: DeploymentDiagramProps) { + const spec = React.useMemo(() => ({ type: "deployment" as const, ext: deploymentType(), environment, title, heading, legend, nodes, groups, edges, layout, direction, placement, motion, entrance }), [environment, title, heading, legend, nodes, groups, edges, layout, direction, placement, motion, entrance]); + return ; +} diff --git a/packages/react/src/diagram-deployment.ts b/packages/react/src/diagram-deployment.ts new file mode 100644 index 00000000..30c7f6f4 --- /dev/null +++ b/packages/react/src/diagram-deployment.ts @@ -0,0 +1,91 @@ +// A deployment diagram (DECISIONS 359, Ops 3): read as an architecture and routed by the engine, with what is its own here: one environment a figure, the +// first words of its source line; a host's copies (`× 3`); its artifacts as rows, which a line may name (it lands on the host in this build). A third group +// level is not drawn in this build: it ships only with its label seat and line cut at every level. DeploymentDiagram hands this module to the engine on +// the spec. Nothing runs at load. The implementation has not been reviewed. + +import { h, iso, linkName, nodeText, txt } from "./diagram-core"; +import type { DeploymentNode, DiagramFlowEdge, DiagramGroup, DiagramSpec, DiagramTypeExt, ExtBuildKit, MNode, Model, VChild, VElement, VNode } from "./diagram-core"; + +function prepare(spec: DiagramSpec, kit: ExtBuildKit): DiagramSpec { + const { dev, error, warn } = kit; + if (dev && !txt(spec.environment)) error("a deployment needs its environment: one environment a figure, the first words of its source line"); + const nodes = (Array.isArray(spec.nodes) ? spec.nodes : []) as DeploymentNode[]; + // The third level: refused in this build, so a group whose parent has a parent is a group of the top level. + const groups = (Array.isArray(spec.groups) ? spec.groups : []) as DiagramGroup[]; + const parentOf = new Map(groups.map((g) => [String(g.id), g.parent ? String(g.parent) : undefined])); + const flat = groups.map((g) => { + const p = g.parent ? String(g.parent) : undefined; + if (p && parentOf.get(p)) { dev && error(`the group "${g.label}" is a third level: a deployment's third level is not drawn in this build, so it is a group of the top level`); return { ...g, parent: undefined }; } + return g; + }); + const hostOf = new Map(); + const ids = new Set(nodes.map((n) => String(n.id))); + for (const n of nodes) for (const a of Array.isArray(n.artifacts) ? n.artifacts : []) { + if (dev && (ids.has(String(a.id)) || hostOf.has(String(a.id)))) error(`the id "${String(a.id)}" is used twice (ids are unique across hosts and artifacts)`); + hostOf.set(String(a.id), String(n.id)); + } + const edges = ((Array.isArray(spec.edges) ? spec.edges : []) as DiagramFlowEdge[]).map((e) => { + const from = String(e.from ?? ""), to = String(e.to ?? ""); + if (dev && !txt(e.label)) warn(`the line from ${from} to ${to} has no label: a deployment's line says what it carries`); + return { ...e, from: hostOf.get(from) ?? from, to: hostOf.get(to) ?? to, fromArtifact: hostOf.has(from) ? from : undefined, toArtifact: hostOf.has(to) ? to : undefined }; + }); + return { ...spec, groups: flat, edges }; +} + +function adopt(m: Model, spec: DiagramSpec, kit: ExtBuildKit) { + m.plan = { environment: txt(spec.environment) }; + for (const raw of (spec.nodes ?? []) as DeploymentNode[]) { + const n = m.byId.get(String(raw.id)); + if (!n) continue; + const r = raw.replicas; + n.replicas = r === undefined || r === null ? undefined : typeof r === "number" && Number.isInteger(r) && r >= 1 ? r : (kit.dev && kit.error(`${n.id}'s replicas is ${JSON.stringify(r)}, not a whole number: words such as "1 writer, 1 reader" are the detail's`), undefined); + const rows = Array.isArray(raw.artifacts) ? raw.artifacts.map((a) => ({ id: String(a.id ?? ""), name: String(a.name ?? ""), detail: txt(a.detail) })) : []; + n.artifacts = rows.length ? rows : undefined; + } + let k = 0; + for (const e of (spec.edges ?? []) as Array<{ from: string; to: string; fromArtifact?: string; toArtifact?: string }>) { + if (!m.byId.has(String(e.from)) || !m.byId.has(String(e.to))) continue; + const me = m.edges[k++]; + if (me) { me.fromArtifact = e.fromArtifact; me.toArtifact = e.toArtifact; } + } +} + +/** A host: its kind line with its copies ("× 3", Geist with tabular figures), and with artifacts the node with no padding: a header band, then a row an artifact. */ +function card(P: string, m: Model, n: MNode): VChild[] { + if ((n.replicas ?? 0) < 2 && !n.artifacts) return nodeText(P, m, n); + const kind = h("span", { class: `${P}-kind` }, n.kind ? iso(n.kind) : null, (n.replicas ?? 0) > 1 ? h("span", { class: `${P}-replicas` }, `× ${n.replicas}`) : null); + const words: VChild[] = [kind, h("span", { class: `${P}-name` }, linkName(P, n)), n.detail ? h("span", { class: `${P}-detail`, "data-mono": n.mono ? "" : undefined }, iso(n.detail)) : null]; + if (!n.artifacts) return words; + return [ + h("span", { class: `${P}-host-head` }, words), + h("span", { class: `${P}-host-rows` }, n.artifacts.map((a) => h("span", { class: `${P}-artifact`, "data-artifact": a.id }, h("span", { class: `${P}-artifact-name` }, iso(a.name)), a.detail ? h("span", { class: `${P}-artifact-detail` }, iso(a.detail)) : null))), + ]; +} + +const artifactName = (m: Model, host: string, id?: string) => (id ? m.byId.get(host)?.artifacts?.find((a) => a.id === id)?.name : undefined); + +function listLines(P: string, m: Model, H: (text: string) => VElement): VNode[] { + const code = (s: string) => h("code", { class: `${P}-code` }, iso(s)); + const name = (id: string, row?: string) => [h("strong", null, iso(m.byId.get(id)?.name ?? id)), row ? [" (", code(row), ")"] : ""]; + return [H("Connections"), h("ol", { class: `${P}-list-items` }, m.edges.map((e) => h("li", null, name(e.from, artifactName(m, e.from, e.fromArtifact)), " to ", name(e.to, artifactName(m, e.to, e.toArtifact)), e.label ? [": ", code(e.label.replace(/\n/g, " "))] : "", m.legend[e.kind] ? ` (${m.legend[e.kind]})` : "", ".")))]; +} + +let made: DiagramTypeExt | undefined; +/** The deployment diagram's module, made at its first use. */ +export function deploymentType(): DiagramTypeExt { + return (made ??= { + type: "deployment", + as: "architecture", + routed: true, + stop: "a part", + prepare, + adopt, + card: (P, m, n) => card(P, m, n), + nodeAttrs: (_m, n) => ({ "data-rows": n.artifacts ? "" : undefined }), + sentenceMore: (_m, n) => [(n.replicas ?? 0) > 1 ? `${n.replicas} copies.` : "", n.artifacts ? `Runs ${n.artifacts.map((a) => (a.detail ? `${a.name} ${a.detail}` : a.name)).join(", ")}.` : ""].filter(Boolean), + keyMore: (P, m) => (m.nodes.some((n) => (n.replicas ?? 0) > 1) ? [h("li", { class: `${P}-entry` }, h("span", { class: `${P}-key-letters`, "data-replicas": "", "aria-hidden": "true" }, "× 3"), h("span", null, "How many copies run"))] : []), + listPart: (P, _m, n) => [(n.replicas ?? 0) > 1 ? ` ${n.replicas} copies.` : "", n.artifacts ? [" Runs ", n.artifacts.flatMap((a, j) => [j ? ", " : "", h("code", { class: `${P}-code` }, iso(a.name)), a.detail ? [" ", iso(a.detail)] : ""]), "."] : ""], + listLines, + sourceLead: (m) => (m.plan as { environment?: string } | undefined)?.environment, + }); +} diff --git a/packages/react/src/diagram-state.ts b/packages/react/src/diagram-state.ts new file mode 100644 index 00000000..adc29e6c --- /dev/null +++ b/packages/react/src/diagram-state.ts @@ -0,0 +1,189 @@ +// A state diagram (DECISIONS 359, Ops 1): read as an architecture (a state is the node, a composite state a group) and routed by the engine, with what is +// its own here: the engine's labels (the event, then `[guard] / action`), guards on one event numbered in the order tried, the start mark, the final +// mark, entry and exit. StateDiagram hands this module to the engine on the spec, so an app that draws an architecture bundles none of it. Nothing runs +// at load. The implementation has not been reviewed. + +import { h, iso, nodeText, sentence, svgA, txt } from "./diagram-core"; +import type { DiagramSpec, DiagramTypeExt, ExtBuildKit, Geo, MNode, Model, StateNode, StateTransition, Tokens, VChild, VElement, VNode } from "./diagram-core"; + +const MAX = 28; +const r2 = (n: number) => Math.round(n * 100) / 100; +const NTH = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"]; + +/** The engine's label (Ops 1): one break, after the event; each line 28 characters at most, the number included. */ +function label(e: StateTransition, n: number | undefined, kit: ExtBuildKit): string | undefined { + const { dev, error } = kit; + if (dev && (e as { label?: unknown }).label !== undefined) error(`the transition from ${String(e.from)} to ${String(e.to)} has a label: a state's label is the engine's, from its event, guard and action`); + const ev = txt(e.event), guard = txt(e.guard), action = txt(e.action); + if (dev && !ev && !guard) error(`the transition from ${String(e.from)} to ${String(e.to)} has neither an event nor a guard`); + const first = ev ? `${n ? `${n}. ` : ""}${ev}` : undefined; + const second = [guard ? `[${guard}]` : "", action ? `/ ${action}` : ""].filter(Boolean).join(" ") || undefined; + const lines = [first, second].filter((x): x is string => Boolean(x)); + for (const l of lines) if (dev && l.length > MAX) error(`the line "${l}" of a transition's label is over ${MAX} characters: the words belong in the state or the summary`); + return lines.length ? lines.join("\n") : undefined; +} + +/** The data the engine reads as an architecture's: no marks, no flow, each transition its composed label; a line to a composite state is refused. */ +function prepare(spec: DiagramSpec, kit: ExtBuildKit): DiagramSpec { + const { dev, error, warn } = kit; + const nodes = (Array.isArray(spec.nodes) ? spec.nodes : []) as StateNode[]; + const groups = new Set((Array.isArray(spec.groups) ? spec.groups : []).map((g) => String(g.id))); + if (dev) { + // One initial state outside the groups at most, and one in each group at most. + const starts = new Map(); + for (const n of nodes) if (n.initial) { const k = String(n.group ?? ""); starts.set(k, [...(starts.get(k) ?? []), String(n.id)]); } + for (const [g, ids] of starts) if (ids.length > 1) error(`${ids.join(" and ")} are each initial ${g ? `in the group ${g}` : "outside the groups"}: one at most`); + for (const n of nodes) if (n.initial && n.final) error(`${String(n.id)} is both initial and final`); + } + const list = (Array.isArray(spec.edges) ? spec.edges : []) as StateTransition[]; + // Transitions that leave one state on one event are numbered 1., 2. in the array's order (rule 4); nothing else is. + const order = new Map(); + const by = new Map(); + list.forEach((e, k) => { const ev = txt(e.event); if (ev) { const key = `${String(e.from)}\u0000${ev}`; by.set(key, [...(by.get(key) ?? []), k]); } }); + for (const ks of by.values()) if (ks.length > 1) { + ks.forEach((k, j) => order.set(k, j + 1)); + if (dev) ks.slice(0, -1).forEach((k) => { if (!txt(list[k]!.guard)) warn(`the transition from ${String(list[k]!.from)} on ${String(list[k]!.event)} has no guard and is not the last on its event: the later ones can never be taken`); }); + } + const edges = list.flatMap((e, k) => { + if (groups.has(String(e.from)) || groups.has(String(e.to))) { dev && error(`the transition from ${String(e.from)} to ${String(e.to)} names a composite state: a line to a group's boundary is not drawn in this build`); return []; } + return [{ from: e.from, to: e.to, kind: e.kind, fromSide: e.fromSide, toSide: e.toSide, label: label(e, order.get(k), kit), event: txt(e.event), guard: txt(e.guard), action: txt(e.action), order: order.get(k) }]; + }); + return { ...spec, nodes: nodes.map((n) => ({ ...n, mark: undefined })), edges }; +} + +/** A state's marks and actions, and a transition's parts, on the model the engine read. */ +function adopt(m: Model, spec: DiagramSpec) { + for (const raw of (spec.nodes ?? []) as StateNode[]) { + const n = m.byId.get(String(raw.id)); + if (!n) continue; + n.initial = raw.initial === true || undefined; n.final = raw.final === true || undefined; n.entry = txt(raw.entry); n.exit = txt(raw.exit); + } + // The engine keeps a line whose two ends are cards, in order: walk the same list. + let k = 0; + for (const e of (spec.edges ?? []) as Array) { + if (!m.byId.has(String(e.from)) || !m.byId.has(String(e.to))) continue; + const me = m.edges[k++]; + if (me) { me.event = e.event; me.guard = e.guard; me.action = e.action; me.order = e.order; } + } +} + +const finalMark = (P: string, cls = `${P}-final`) => h("svg", { class: cls, ...svgA(14, 14) }, h("circle", { cx: 7, cy: 7, r: 6.5 }), h("circle", { cx: 7, cy: 7, r: 3, "data-dot": "" })); + +function card(P: string, m: Model, n: MNode): VChild[] { + return [ + ...nodeText(P, m, n), + // Entry and exit actions, under a hairline rule. + n.entry || n.exit ? h("span", { class: `${P}-actions` }, n.entry ? h("span", { class: `${P}-action` }, "entry / ", iso(n.entry)) : null, n.exit ? h("span", { class: `${P}-action` }, "exit / ", iso(n.exit)) : null) : null, + // A final state carries a ring and a dot in its top end corner. + n.final ? finalMark(P) : null, + ]; +} + +function keyMore(P: string, m: Model): VElement[] { + const out: VElement[] = []; + const entry = (swatch: VElement, words: string) => out.push(h("li", { class: `${P}-entry` }, swatch, h("span", null, iso(words)))); + if (m.nodes.some((n) => n.initial)) entry(h("svg", { class: `${P}-swatch`, ...svgA(24, 16) }, h("circle", { class: `${P}-start-dot`, cx: 4, cy: 8.5, r: 4 }), h("path", { class: `${P}-start-line`, d: "M8 8.5H17" }), h("path", { class: `${P}-start-tip`, d: "M24 8.5L16 4.5L16 12.5Z" })), "Starts here"); + if (m.nodes.some((n) => n.final)) entry(finalMark(P, `${P}-swatch ${P}-final`), "Ends here"); + if (m.edges.some((e) => e.order)) out.push(h("li", { class: `${P}-entry` }, h("span", { class: `${P}-key-letters`, "data-numbers": "", "aria-hidden": "true" }, "1. 2."), h("span", null, "Tried in this order: the first that holds is taken"))); + return out; +} + +function listLines(P: string, m: Model, H: (text: string) => VElement): VNode[] { + const code = (s: string) => h("code", { class: `${P}-code` }, iso(s)); + const name = (id: string) => h("strong", null, iso(m.byId.get(id)?.name ?? id)); + // A transition as a sentence: "On tool.call, if writes: to Waiting approval. Tried second." + return [H("Transitions"), h("ol", { class: `${P}-list-items` }, m.edges.map((e) => h("li", null, name(e.from), ": ", + e.event ? ["On ", code(e.event)] : "", e.guard ? [e.event ? ", if " : "If ", code(e.guard)] : "", e.action ? [", then ", code(e.action)] : "", + ": to ", name(e.to), m.legend[e.kind] ? ` (${m.legend[e.kind]})` : "", ".", e.order ? ` Tried ${NTH[e.order - 1] ?? `number ${e.order}`}.` : "")))]; +} + +/** A state's initial state that a composite holds: its mark stands above it, in every layout (the decider's ruling on the gap). */ +const inGroup = (n: MNode) => Boolean(n.initial && n.group); +/** The rows whose cards stand space-10 lower for a composite's start mark: each row (but the first, which the drawing's top edge holds) with one. */ +const markedRows = (m: Model) => new Set(m.nodes.filter((n) => inGroup(n) && n.row > 1 && n.row === Math.min(...m.nodes.filter((x) => x.group === n.group).map((x) => x.row))).map((n) => n.row)); +const hits = (a: { l: number; t: number; r: number; b: number }, b: { l: number; t: number; r: number; b: number }) => a.l < b.r && a.r > b.l && a.t < b.b && a.b > b.t; + +/** + * The start marks: the figure's own before its initial state on the side the figure reads from (above, laid down); a composite's above its initial + * state in every layout. Along its side a mark takes the first of the middle, the start quarter and the end quarter (mirrored right to left) that is + * space-4 from every line's end there; it never lies on a line, a label or another mark. With no such place the drawn layout is refused, and the figure + * is stacked (the stacked form is unchanged: the mark on the trunk's x, in its own room). + */ +function startMarks(P: string, m: Model, geo: Geo, tk: Tokens, drawn: boolean, warn?: (s: string) => void): string | false { + const s = tk.space; + const len = drawn ? s("10") : s("8"); + const half = tk.head / 2; + let out = ""; + const drawnBoxes: Array<{ l: number; t: number; r: number; b: number }> = []; + for (const g of geo.nodes) { + const n = m.byId.get(g.id); + if (!n?.initial) continue; + const r = g.rect; + const across = !drawn || m.dir === "down" || inGroup(n); + const ends = geo.lines.flatMap((l) => [l.pts[0]!, l.pts[l.pts.length - 1]!]).filter((p) => (across ? Math.abs(p.y - r.t) < 1.5 && p.x >= r.l - 1 && p.x <= r.r + 1 : Math.abs(p.x - (m.rtl ? r.r : r.l)) < 1.5 && p.y >= r.t - 1 && p.y <= r.b + 1)); + const lo = across ? r.l : r.t, hi = across ? r.r : r.b; + const at = (f: number) => lo + (hi - lo) * f; + const tries = !drawn ? [m.rtl ? r.r - s("8") : r.l + s("8")] : (across && m.rtl ? [0.5, 0.75, 0.25] : [0.5, 0.25, 0.75]).map(at); + let placed: string | null = null; + for (const v of tries) { + if (drawn && !ends.every((p) => Math.abs((across ? p.x : p.y) - v) >= s("4"))) continue; + const c = Math.round(v - 0.5) + 0.5; + const a = across ? { x: c, y: r.t - len + half } : { x: m.rtl ? r.r + len - half : r.l - len + half, y: c }; + const b = across ? { x: c, y: r.t } : { x: m.rtl ? r.r : r.l, y: c }; + // The mark's box (its dot and stub, grown space-1): clear of every line's stroke, every label and every other mark. + const box = { l: Math.min(a.x, b.x) - half - s("1"), r: Math.max(a.x, b.x) + half + s("1"), t: Math.min(a.y, b.y) - half - s("1"), b: Math.max(a.y, b.y) + half + s("1") }; + const shy = { l: box.l, r: box.r, t: box.t, b: across ? b.y - 1 : box.b }; + if (drawn) { + const onLine = geo.lines.some((l) => l.pts.slice(1).some((q, k) => { const p0 = l.pts[k]!; return hits(shy, { l: Math.min(p0.x, q.x) - l.width / 2, r: Math.max(p0.x, q.x) + l.width / 2, t: Math.min(p0.y, q.y) - l.width / 2, b: Math.max(p0.y, q.y) + l.width / 2 }); })); + if (onLine || geo.labels.some((lb) => hits(shy, lb.box)) || drawnBoxes.some((o) => hits(shy, o))) continue; + } + drawnBoxes.push(box); + const ux = Math.sign(b.x - a.x), uy = Math.sign(b.y - a.y); + const bx = b.x - ux * tk.head, by = b.y - uy * tk.head; + placed = ``; + break; + } + if (placed === null) { warn?.(`the start mark of ${n.name} has no place clear of the lines, the labels and the other marks, so the figure is stacked`); return false; } + out += placed; + } + return out; +} + +let made: DiagramTypeExt | undefined; +/** The state diagram's module, made at its first use. */ +export function stateType(): DiagramTypeExt { + return (made ??= { + type: "state", + as: "architecture", + routed: true, + stop: "a state", + prepare, + adopt, + card: (P, m, n) => card(P, m, n), + sentenceMore: (_m, n) => [n.initial ? "The machine starts here." : "", n.final ? "It ends here." : "", n.entry ? `On entry: ${sentence(n.entry)}` : "", n.exit ? `On exit: ${sentence(n.exit)}` : ""].filter(Boolean), + keyMore, + listParts: "States", + listPart: (P, _m, n) => { + const code = (s: string) => h("code", { class: `${P}-code` }, iso(s)); + return [n.initial ? " The machine starts here." : "", n.final ? " It ends here." : "", n.entry ? [" On entry: ", code(n.entry), "."] : "", n.exit ? [" On exit: ", code(n.exit), "."] : ""]; + }, + listLines, + // A composite's mark stands above its initial state, in every layout, and its room is new room: on the figure's first row the box and the drawing's + // top edge take space-10 more; on a later row every card of the row stands space-10 lower (`data-room`), so the box keeps its plain space-8 above it. + // Stacked, a group whose first card is initial keeps space-16 above it. + groupMark: (m, g, c) => { + if (!c) { const first = m.nodes.find((n) => g.all.includes(n.id)); return first?.initial && first.group === g.id ? { start: "" } : undefined; } + // On the first row the box reaches higher where it or a group inside it holds a marked state there, so a nested box never pokes out of its parent. + return c.r1 === 1 && g.all.some((id) => { const n = m.byId.get(id)!; return inGroup(n) && n.row === 1; }) ? { start: "top" } : undefined; + }, + room: (m) => { + const own = m.nodes.find((n) => n.initial && !n.group); + return { + start: Boolean(own && m.dir !== "down" && own.col === (m.rtl ? m.cols : 1)), + top: Boolean((own && m.dir === "down" && own.row === 1) || m.nodes.some((n) => inGroup(n) && n.row === 1)), + }; + }, + nodeAttrs: (m, n) => ({ "data-initial": n.initial ? "" : undefined, "data-final": n.final ? "" : undefined, "data-room": markedRows(m).has(n.row) ? "" : undefined }), + inkMore: startMarks, + }); +} diff --git a/packages/react/src/state-diagram.tsx b/packages/react/src/state-diagram.tsx new file mode 100644 index 00000000..2c6b9f48 --- /dev/null +++ b/packages/react/src/state-diagram.tsx @@ -0,0 +1,31 @@ +import * as React from "react"; + +import type { DiagramGroup, DiagramPlacement, StateNode, StateTransition } from "./diagram-core"; +import { DiagramFigure } from "./diagram-figure"; +import { stateType } from "./diagram-state"; +import type { DiagramFigureProps } from "./diagram-figure"; + +export type { DiagramGroup, DiagramLegend, DiagramLineKind, DiagramPlacement, DiagramSide, StateNode, StateTransition } from "./diagram-core"; +export type { DiagramAction, DiagramActionContext, DiagramFigureProps, DiagramLayoutInfo } from "./diagram-figure"; + +export interface StateDiagramProps extends DiagramFigureProps { + /** The states, in the author's order. `initial` takes the start mark (one outside the groups, one in each group, at most); `final` the end mark. */ + nodes: StateNode[]; + /** Composite states: two levels, as an architecture's groups. */ + groups?: DiagramGroup[]; + /** The transitions. The engine writes each label from `event`, `guard` and `action`; there is no `label`. */ + edges: StateTransition[]; + layout?: "authored" | "auto"; + direction?: "right" | "down"; + placement?: DiagramPlacement | DiagramPlacement[]; +} + +/** + * A state diagram (DECISIONS 359): a state is the node and a composite state a group. A transition's label is its event, then `[guard] / action` on a + * second line, written by the engine; transitions that leave one state on one event are numbered in the order they are tried. The start is a dot and a + * line before the initial state; a final state carries a ring. No mover: a state figure does not know the current state. The implementation has not been reviewed. + */ +export function StateDiagram({ nodes, groups, edges, layout, direction, placement, motion, entrance, title, heading, legend, ...props }: StateDiagramProps) { + const spec = React.useMemo(() => ({ type: "state" as const, ext: stateType(), title, heading, legend, nodes, groups, edges, layout, direction, placement, motion, entrance }), [title, heading, legend, nodes, groups, edges, layout, direction, placement, motion, entrance]); + return ; +} From 3634eb01c0b2d64208e9256f8718258fcc9d77ed Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:03 -0600 Subject: [PATCH 04/12] Diagrams: the matrix core and its four types: kanban, journey, service blueprint, story map (DECISIONS 359, Planning 1.0, 1.2 to 1.5) Equal tracks space-4 apart, the fit measured on content, one DOM for both forms, an empty cell in words (a story map's a dashed slot). A kanban is a read-only count, every card counted; a journey one actor and the author's five-step scale, the chart's line in one ink; a blueprint's three rules named in their gaps, its empty cell the word alone and its arrows main or plain; a story map's backbone, slices and one cut. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Gemini Neon --- packages/react/src/diagram-matrix.ts | 772 ++++++++++++++++++ packages/react/src/journey-diagram.tsx | 33 + packages/react/src/kanban-diagram.tsx | 27 + .../react/src/service-blueprint-diagram.tsx | 31 + packages/react/src/story-map-diagram.tsx | 33 + 5 files changed, 896 insertions(+) create mode 100644 packages/react/src/diagram-matrix.ts create mode 100644 packages/react/src/journey-diagram.tsx create mode 100644 packages/react/src/kanban-diagram.tsx create mode 100644 packages/react/src/service-blueprint-diagram.tsx create mode 100644 packages/react/src/story-map-diagram.tsx diff --git a/packages/react/src/diagram-matrix.ts b/packages/react/src/diagram-matrix.ts new file mode 100644 index 00000000..f3432c46 --- /dev/null +++ b/packages/react/src/diagram-matrix.ts @@ -0,0 +1,772 @@ +// The matrix types (DECISIONS 359, Planning 1.0 and 1.2 to 1.5): kanban, journey, service blueprint and story map, on one core. Equal tracks space-4 apart, +// a row-label column where the type has one, the fit measured on content (a track is size-diagram-node or the widest unbreakable thing in any column), one +// DOM for both forms switched by the engine's --_drawn, an empty cell that holds its track and says so in words. Their components hand this module to the +// engine on the spec, so an app that draws an architecture bundles none of it. Nothing runs at load. The implementation has not been reviewed. + +import { h, iso, lineSwatch, rectOf, sentence, svgA, txt } from "./diagram-core"; +import type { DiagramLineKind, DiagramSpec, DiagramTypeExt, Dyn, ExtBuildKit, ExtBuilt, ExtMeasureKit, Geo, GLine, Measured, MEdge, MNode, Model, Pt, Tokens, VAttrs, VChild, VElement, VNode } from "./diagram-core"; + +// ============================================================================================================================================ +// Public shapes +// ============================================================================================================================================ + +export interface KanbanColumn { id: string; label: string; limit?: number; more?: number; note?: string } +export interface KanbanCard { id: string; column: string; name: string; kind?: string; detail?: string; detailMono?: boolean; blocked?: string; focal?: boolean; href?: string; target?: "_blank" } +export interface KanbanLabels { max?: string; overLimit?: string; blocked?: string; noCards?: string; notShown?: string; keyOver?: string } + +export type JourneyLevel = 1 | 2 | 3 | 4 | 5; +export interface JourneyStage { + id: string; name: string; level: JourneyLevel; actions: string; + quote?: string; touchpoint?: string; friction?: string; opportunity?: string; + focal?: boolean; href?: string; target?: "_blank"; +} +export interface JourneyLabels { stage?: string; none?: string; actions?: string; quote?: string; touchpoints?: string; friction?: string; opportunity?: string } + +export type BlueprintLayer = "evidence" | "customer" | "frontstage" | "backstage" | "support"; +export interface BlueprintStage { id: string; name: string; time?: string } +export interface BlueprintCell { stage: string; layer: BlueprintLayer; name: string; detail?: string; detailMono?: boolean; focal?: boolean; href?: string; target?: "_blank" } +export interface BlueprintArrow { from: { stage: string; layer: BlueprintLayer }; to: { stage: string; layer: BlueprintLayer }; kind?: "main" | "plain" } +export interface BlueprintRuleLabels { interaction?: string; visibility?: string; internal?: string } +export interface BlueprintLabels { stage?: string; none?: string; keyVisibility?: string; keyInteraction?: string; keyInternal?: string } + +export interface StoryActivity { id: string; name: string; steps?: string[] } +export interface StorySlice { id: string; label: string } +export interface StoryCard { id: string; activity: string; slice: string; name: string; kind?: string; detail?: string; detailMono?: boolean; focal?: boolean; href?: string; target?: "_blank" } +export interface StoryCut { after: string; label: string } +export interface StoryMapLabels { activity?: string; noStories?: string; backbone?: string; story?: { one: string; other: string } } + +// ============================================================================================================================================ +// Shared +// ============================================================================================================================================ + +const r2 = (n: number) => Math.round(n * 100) / 100; +type Labels = { [K in keyof T]-?: T[K] }; +const wordsOf = (spec: DiagramSpec, defaults: Labels): Labels => { + const given = (spec.labels ?? {}) as Partial; + const out = { ...defaults }; + for (const k of Object.keys(defaults) as Array) if (given[k] !== undefined && given[k] !== null && given[k] !== "") out[k] = given[k] as Labels[keyof T]; + return out; +}; +const linkAttrs = (href?: string, blank?: boolean): VAttrs => ({ href, target: href && blank ? "_blank" : undefined, rel: href && blank ? "noopener noreferrer" : undefined, "data-link": href ? (blank ? "external" : "") : undefined }); +const stopIndex = (dyn: Dyn, id: string) => (dyn.layout && !dyn.bare ? (dyn.stop === id ? 0 : -1) : dyn.keep === id ? -1 : undefined); + +/** A part that is a stop: the shipped node, named by its sentence. */ +function stop(P: string, m: Model, n: MNode, dyn: Dyn, level: number | undefined, extra: VAttrs, ...kids: VChild[]): VElement { + return h(n.href ? "a" : "div", { + class: `${P}-node`, ...linkAttrs(n.href, n.blank), "data-node": n.id, "data-focal": n.focal ? "" : undefined, "data-level": level, + role: n.href ? undefined : "img", "aria-label": m.ext!.sentence!(m, n), tabindex: stopIndex(dyn, n.id), ...extra, + }, ...kids); +} +/** A node's own words: its kind line, its name and its detail, as the shipped node writes them. */ +function nodeWords(P: string, n: { kind?: string; name: string; detail?: string; mono?: boolean }, kindLine?: VChild): VChild[] { + return [ + kindLine ?? (n.kind ? h("span", { class: `${P}-kind` }, iso(n.kind)) : null), + h("span", { class: `${P}-name` }, iso(n.name)), + n.detail ? h("span", { class: `${P}-detail`, "data-mono": n.mono ? "" : undefined }, n.mono ? h("span", { class: `${P}-runs` }, n.detail.split(/\s+/).filter(Boolean).flatMap((w, j) => [j ? " " : "", h("span", { class: `${P}-run` }, w)])) : iso(n.detail)) : null, + ]; +} +const entry = (P: string, swatch: VElement, words: string, attrs: VAttrs = {}) => h("li", { class: `${P}-entry`, ...attrs }, swatch, h("span", null, iso(words))); +const keyOf = (P: string, entries: VElement[]) => (entries.length ? h("div", { class: `${P}-key` }, h("ul", { class: `${P}-legend`, "aria-label": "Key" }, entries)) : null); +const focalSwatch = (P: string) => h("svg", { class: `${P}-swatch`, "data-shape": "focal", ...svgA(16, 16) }, h("rect", { class: `${P}-swatch-shape`, x: 0.5, y: 2.5, width: 15, height: 11, rx: 2 })); +const ruleSwatch = (P: string, kind: "main" | "dashed" | "slot" | "contour") => + kind === "slot" || kind === "contour" + ? h("svg", { class: `${P}-swatch`, ...svgA(16, 16) }, h("rect", { class: kind === "slot" ? `${P}-swatch-slot` : `${P}-swatch-contour`, x: 0.5, y: 2.5, width: 15, height: 11, rx: 3 })) + : h("svg", { class: `${P}-swatch`, ...svgA(24, 16) }, h("path", { class: kind === "main" ? `${P}-swatch-rule` : `${P}-swatch-dash`, d: kind === "main" ? "M0 8H24" : "M0 8.5H24" })); + +/** The words a track must hold whole: each word of each string, measured in its face. */ +function widestOf(measure: ExtMeasureKit["measure"], parts: Array<[string | undefined, Parameters[1], boolean?]>): number { + let out = 0; + for (const [text, font, whole] of parts) { + if (!text) continue; + for (const w of whole ? [text] : text.split(/\s+/)) if (w) out = Math.max(out, measure(w, font)); + } + return Math.ceil(out); +} + +/** + * The fit (1.0): the label column (or none), plus the tracks at their least, plus the gaps, never under 640. A track's least is size-diagram-node or the + * widest unbreakable thing in any column plus a card's padding; the label column is size-diagram-lane or its widest unbreakable label. + */ +function fit(tk: Tokens, columns: number, track: number, label: number | null): number { + const gap = tk.space("4"); + return Math.max(tk.wide, (label === null ? 0 : label + gap) + columns * Math.max(tk.node, track) + (columns - 1) * gap); +} + +/** The layout every matrix type takes: drawn at its least drawn width or wider, otherwise stacked; the ink is the type's. */ +function matrixLayout(ink?: (el: HTMLElement, m: Model, P: string, tk: Tokens, drawn: boolean) => { geo: Geo; ink: string }) { + return (m: Model, kit: ExtMeasureKit): Measured => { + const least = m.ext!.least!(m, kit.tk, kit.measure); + const label = labelColumn(m, kit.tk, kit.measure); + const drawn = kit.W >= least; + const dyn = kit.stopOf({ ...kit.current, layout: drawn ? "drawn" : "stacked", bare: undefined, place: label ? { "": `--_lab:${label}px` } : undefined }); + kit.apply(dyn); + const made = ink ? ink(kit.drawing, m, kit.P, kit.tk, drawn) : { geo: blankGeo(kit.drawing), ink: "" }; + return { dyn, geo: made.geo, ink: made.ink, tokens: kit.tk, least }; + }; +} +const blankGeo = (el: HTMLElement): Geo => ({ w: el.clientWidth, h: el.clientHeight, nodes: [], lines: [], lifelines: [], labels: [], crossings: [], through: [], unseated: [], outside: [], ox: 0, oy: 0 }); + +/** The label column's width, measured: size-diagram-lane or its widest unbreakable label. Null for a kanban, which has none. */ +function labelColumn(m: Model, tk: Tokens, measure: ExtMeasureKit["measure"]): number | null { + const p = m.plan as { labelWords?: Array<[string, Parameters[1]]> }; + if (!p.labelWords) return null; + return Math.max(tk.lane, widestOf(measure, p.labelWords) + tk.space("3")); +} + +const hintFour = (m: Model, drawn: boolean, noun: string) => [{ keys: drawn && m.cols > 1 && m.rows > 1 ? ["←", "↑", "↓", "→"] : drawn ? ["←", "→"] : ["↑", "↓"], words: `a ${noun}` }, { keys: ["Home", "End"], words: "the ends" }, ...(m.nodes.some((n) => n.href) ? [{ keys: ["Enter"], words: "open" }] : [])]; +const keysWords = (m: Model, drawn: boolean, noun: string) => `${drawn ? `Arrow keys move to the nearest ${noun} in that direction` : `Arrow keys move to the next or the previous ${noun}`}; Home and End go to the ends.${m.nodes.some((n) => n.href) ? ` Enter opens a ${noun} that is a link.` : ""}`; +const rootPlace = (_m: Model, dyn: Dyn) => { const v = dyn.place?.[""]; return v ? [v] : []; }; +const listStrong = (s: string) => h("strong", null, iso(s)); +const focalWords = (m: Model, focal: boolean) => (focal && m.legend.focal ? ` ${sentence(m.legend.focal)}` : ""); +const card = (raw: { id?: unknown; name?: unknown; kind?: unknown; detail?: unknown; detailMono?: unknown; focal?: unknown; href?: unknown; target?: unknown }) => + ({ id: String(raw.id ?? ""), name: String(raw.name ?? ""), kind: txt(raw.kind), detail: txt(raw.detail), mono: Boolean(raw.detailMono), focal: Boolean(raw.focal), href: txt(raw.href), blank: raw.target === "_blank" }); +const mnode = (c: ReturnType, i: number, col: number, row: number): MNode => ({ id: c.id, i, name: c.name, kind: c.kind, detail: c.detail, mono: c.mono, focal: c.focal, col, row, row2: row, branch: false, shape: "box", href: c.href, blank: c.blank }); +function checkIds(kit: ExtBuildKit, ids: string[]) { + if (!kit.dev) return; + const seen = new Set(); + for (const id of ids) { if (!id) kit.warn("a part has no id"); else if (seen.has(id)) kit.warn(`the id "${id}" is used twice`); seen.add(id); } +} + +// ============================================================================================================================================ +// Kanban (1.2): a count of cards in states at one moment. Read-only: nothing drags. +// ============================================================================================================================================ + +interface KCol { id: string; label: string; limit?: number; more: number; note?: string; count: number; over: boolean; cards: KCard[]; c: number } +interface KCard extends ReturnType { column: string; blocked?: string } +interface KanbanPlan { columns: KCol[]; words: Labels } +const kplan = (m: Model) => m.plan as KanbanPlan; + +function countWords(p: KanbanPlan, c: KCol): string { + const base = c.limit !== undefined ? `${c.count}, ${p.words.max} ${c.limit}` : String(c.count); + return c.over ? `${base} · ${p.words.overLimit}` : base; +} + +function buildKanban(spec: DiagramSpec, kit: ExtBuildKit): ExtBuilt { + const words = wordsOf(spec, { max: "max", overLimit: "Over limit", blocked: "Blocked", noCards: "No cards", notShown: "not shown", keyOver: "Over its limit" }); + if (kit.dev && Array.isArray(spec.edges) && spec.edges.length) kit.error("a kanban draws no lines: it is a count of cards at one moment"); + const columns: KCol[] = (Array.isArray(spec.columns) ? spec.columns : []).map((raw, k) => { + const c = raw as KanbanColumn; + const limit = typeof c.limit === "number" && Number.isInteger(c.limit) && c.limit > 0 ? c.limit : undefined; + const more = typeof c.more === "number" && Number.isInteger(c.more) && c.more > 0 ? c.more : 0; + return { id: String(c.id ?? ""), label: String(c.label ?? ""), limit, more, note: txt(c.note), count: 0, over: false, cards: [], c: k + 1 }; + }); + const byCol = new Map(columns.map((c) => [c.id, c])); + for (const raw of (Array.isArray(spec.cards) ? spec.cards : []) as KanbanCard[]) { + const col = byCol.get(String(raw.column ?? "")); + if (!col) { kit.dev && kit.warn(`the card ${String(raw.id)} names the column "${String(raw.column)}", which is not in columns`); continue; } + if (kit.dev && "state" in (raw as object)) kit.error(`the card ${String(raw.id)} has a "state": a kanban card is blocked (with its reason) or in its column, nothing more`); + col.cards.push({ ...card(raw), column: col.id, blocked: txt(raw.blocked) }); + } + // The count is every card in the column: the cards drawn plus `more` (1.2). + for (const c of columns) { c.count = c.cards.length + c.more; c.over = c.limit !== undefined && c.count > c.limit; } + const nodes: MNode[] = []; + for (const c of columns) c.cards.forEach((x, k) => nodes.push(mnode(x, nodes.length, c.c, k + 1))); + checkIds(kit, nodes.map((n) => n.id)); + if (kit.dev && nodes.filter((n) => n.focal).length > 1) kit.warn("more than one card is focal: a kanban has one at most"); + return { nodes, edges: [], plan: { columns, words } satisfies KanbanPlan, cols: Math.max(1, columns.length), rows: Math.max(1, ...columns.map((c) => c.cards.length)) }; +} +const kcard = (m: Model, id: string) => { for (const c of kplan(m).columns) { const x = c.cards.find((y) => y.id === id); if (x) return { col: c, card: x }; } return null; }; + +function kanbanSentence(m: Model, n: MNode): string { + const p = kplan(m), found = kcard(m, n.id)!; + const { col, card: c } = found; + const parts = [sentence(c.kind ? `${c.name}, ${c.kind}` : c.name), `In ${col.label}: ${countWords(p, col).replace(" · ", ", ").toLowerCase()}.`]; + if (c.blocked) parts.push(`${p.words.blocked}: ${sentence(c.blocked)}`); + if (c.detail) parts.push(sentence(c.detail)); + if (c.focal && m.legend.focal) parts.push(sentence(m.legend.focal)); + return parts.join(" "); +} + +function kanbanDrawing(P: string, m: Model, dyn: Dyn, level?: number): VNode[] { + const p = kplan(m); + return p.columns.map((col) => h("section", { class: `${P}-kanban-col`, "data-over": col.over ? "" : undefined }, + h("div", { class: `${P}-kanban-head`, style: `--_c:${col.c}` }, + h("span", { class: `${P}-kanban-top` }, + h("span", { class: `${P}-kanban-title` }, iso(col.label)), + h("span", { class: `${P}-kanban-count` }, iso(countWords(p, col)))), + col.note ? h("span", { class: `${P}-kanban-note` }, iso(col.note)) : null), + h("div", { class: `${P}-kanban-cards`, style: `--_c:${col.c}` }, + col.cards.map((c) => { + const n = m.byId.get(c.id)!; + return stop(P, m, n, dyn, level, { class: `${P}-node ${P}-kanban-card`, "data-blocked": c.blocked ? "" : undefined }, + c.blocked ? h("span", { class: `${P}-kanban-blocked` }, iso(`${p.words.blocked} · ${c.blocked}`)) : null, + ...nodeWords(P, c)); + }), + !col.cards.length && !col.more ? h("span", { class: `${P}-empty` }, iso(p.words.noCards)) : null, + col.more ? h("span", { class: `${P}-kanban-more` }, iso(`${col.more} more ${p.words.notShown}`)) : null))); +} + +function kanbanKey(P: string, m: Model): VElement | null { + const p = kplan(m); + const out: VElement[] = []; + if (p.columns.some((c) => c.over)) out.push(entry(P, ruleSwatch(P, "main"), p.words.keyOver)); + if (p.columns.some((c) => c.cards.some((x) => x.blocked && !x.focal))) out.push(entry(P, h("svg", { class: `${P}-swatch`, ...svgA(16, 16) }, h("rect", { class: `${P}-swatch-blocked`, x: 0.5, y: 2.5, width: 15, height: 11, rx: 3 })), p.words.blocked)); + if (m.nodes.some((n) => n.focal) && m.legend.focal) out.push(entry(P, focalSwatch(P), m.legend.focal, { "data-focal": "" })); + return keyOf(P, out); +} + +function kanbanList(P: string, m: Model): VNode[] { + const p = kplan(m); + const sub = Math.min(6, m.heading + 1); + return p.columns.flatMap((col) => [ + h(`h${sub}`, { class: `${P}-list-head` }, iso(col.label), `: ${countWords(p, col)}`), + h("ul", { class: `${P}-list-items` }, [ + ...col.cards.map((c) => h("li", null, listStrong(c.name), c.kind ? `, ${c.kind}` : "", c.detail ? `. ${sentence(c.detail)}` : ".", c.blocked ? ` ${p.words.blocked}: ${sentence(c.blocked)}` : "", focalWords(m, c.focal))), + ...(col.more ? [h("li", null, `${col.more} more ${p.words.notShown}.`)] : []), + ...(!col.cards.length && !col.more ? [h("li", null, `${p.words.noCards}.`)] : []), + ]), + ]); +} + +function kanbanLeast(m: Model, tk: Tokens, measure: ExtMeasureKit["measure"]): number { + const p = kplan(m); + const pad = 2 * tk.space("3") + 2 * tk.hair; + let track = tk.node; + for (const col of p.columns) { + // A head's count is never broken, and an over-limit count is 600. + track = Math.max(track, widestOf(measure, [[col.label, "name"], [col.note, "sans"]]), Math.ceil(measure(countWords(p, col), col.over ? "xs-600" : "tab"))); + for (const c of col.cards) track = Math.max(track, pad + widestOf(measure, [[c.name, "name"], [c.kind, "mono"], [c.detail, c.mono ? "mono" : "sans"], [c.blocked ? `${p.words.blocked} ·` : undefined, "xs-600"], [c.blocked, "xs-600"]])); + } + return fit(tk, p.columns.length, track, null); +} + +// ============================================================================================================================================ +// Journey (1.3): one actor in one scenario, a scale of five steps the author names, the chart's line. +// ============================================================================================================================================ + +type JField = "actions" | "quote" | "touchpoint" | "friction" | "opportunity"; +const J_FIELDS: JField[] = ["actions", "quote", "touchpoint", "friction", "opportunity"]; +interface JStage { id: string; i: number; name: string; level: number; levelWord: string; fields: Partial>; focal: boolean; href?: string; blank?: boolean } +interface JourneyPlan { actor: string; scenario: string; scale: string[]; stages: JStage[]; bands: JField[]; words: Labels; labelWords: Array<[string, "label" | "sans" | "xs-500"]> } +const jplan = (m: Model) => m.plan as JourneyPlan; +const bandWord = (p: JourneyPlan, f: JField) => (f === "touchpoint" ? p.words.touchpoints : p.words[f]); + +function buildJourney(spec: DiagramSpec, kit: ExtBuildKit): ExtBuilt { + const words = wordsOf(spec, { stage: "Stage", none: "None", actions: "Actions", quote: "Quote", touchpoints: "Touchpoints", friction: "Friction", opportunity: "Opportunity" }); + const actor = txt(spec.actor), scenario = txt(spec.scenario); + if (kit.dev && (!actor || !scenario)) kit.error("a journey needs its actor and its scenario: it is one actor in one scenario"); + const scaleIn = Array.isArray(spec.scale) ? spec.scale.map(String) : []; + if (kit.dev && scaleIn.length !== 5) kit.error("a journey's scale is five words, lowest first, in the author's own words"); + const scale = scaleIn.length === 5 ? scaleIn : ["1", "2", "3", "4", "5"]; + const legendIn = (spec.legend ?? {}) as { line?: unknown }; + if (kit.dev && !txt(legendIn.line)) kit.error("a journey's line needs its words (legend.line): the key must say what the scale measures"); + const stages: JStage[] = (Array.isArray(spec.stages) ? spec.stages : []).map((raw, i) => { + const s = raw as JourneyStage; + const lv = Number(s.level); + const level = Number.isInteger(lv) && lv >= 1 && lv <= 5 ? lv : (kit.dev && kit.error(`the stage ${String(s.id)}'s level is ${JSON.stringify(s.level)}, not 1 to 5`), 3); + const fields: JStage["fields"] = {}; + for (const f of J_FIELDS) { const v = txt((s as unknown as Record)[f]); if (v) fields[f] = v; } + return { id: String(s.id ?? ""), i, name: String(s.name ?? ""), level, levelWord: scale[level - 1]!, fields, focal: Boolean(s.focal), href: txt(s.href), blank: s.target === "_blank" }; + }); + const bands = J_FIELDS.filter((f) => stages.some((s) => s.fields[f])); + const nodes: MNode[] = stages.map((s) => ({ id: s.id, i: s.i, name: s.name, mono: false, focal: s.focal, col: s.i + 1, row: 1, row2: 1, branch: false, shape: "box", href: s.href, blank: s.blank })); + checkIds(kit, nodes.map((n) => n.id)); + if (kit.dev && nodes.filter((n) => n.focal).length > 1) kit.warn("more than one stage is focal: a journey has one at most"); + const labelWords: JourneyPlan["labelWords"] = [...bands.map((f) => [bandWord({ words } as JourneyPlan, f), "xs-500"] as [string, "xs-500"]), ...scale.map((w) => [w, "tab"] as [string, "tab"])] as JourneyPlan["labelWords"]; + const plan: JourneyPlan = { actor: actor ?? "", scenario: scenario ?? "", scale, stages, bands, words, labelWords }; + return { nodes, edges: [], plan, cols: Math.max(1, stages.length), rows: 1 }; +} +const jstage = (m: Model, id: string) => jplan(m).stages.find((s) => s.id === id)!; + +function journeySentence(m: Model, n: MNode): string { + const p = jplan(m), s = jstage(m, n.id); + const parts = [`${p.words.stage} ${s.i + 1} of ${p.stages.length}, ${s.name}: ${s.levelWord}.`]; + for (const f of J_FIELDS) if (s.fields[f]) parts.push(`${bandWord(p, f)}: ${f === "quote" ? `“${s.fields[f]}”` : sentence(s.fields[f]!)}`); + if (s.focal && m.legend.focal) parts.push(sentence(m.legend.focal)); + return parts.join(" "); +} + +function journeyMeta(P: string, m: Model): VElement | null { + const p = jplan(m); + if (!p.actor && !p.scenario) return null; + return h("p", { class: `${P}-meta` }, h("span", { class: `${P}-meta-first` }, iso(p.actor)), p.scenario ? [" · ", iso(p.scenario)] : null); +} + +function journeyDrawing(P: string, m: Model, dyn: Dyn, level?: number): VNode[] { + const p = jplan(m); + const out: VNode[] = []; + // Row 2, the plot: the five levels' words in the label column (stacked, the top, middle and bottom in the strip's own), the stage numbers under the + // strip (stacked only); the line, its discs and the level lines are the ink's. + out.push(h("div", { class: `${P}-journey-plot`, style: `--_cols:${p.stages.length}`, "aria-hidden": "true" }, + h("span", { class: `${P}-journey-levels` }, [...p.scale].map((w, k) => h("span", { class: `${P}-journey-level`, style: `--_lv:${k + 1}`, "data-edge": k === 0 || k === 2 || k === 4 ? "" : undefined }, iso(w))).reverse()), + h("span", { class: `${P}-journey-track` }, p.stages.map((s) => h("span", { class: `${P}-journey-slot`, "data-stage": s.id, "data-focal": s.focal ? "" : undefined, style: `--_c:${s.i + 1}`, "data-lv": s.level }, String(s.i + 1)))))); + // The band labels, drawn only, each in the label column on its row. + p.bands.forEach((f, k) => out.push(h("span", { class: `${P}-matrix-label`, style: `--_r:${k + 3}`, "aria-hidden": "true" }, iso(bandWord(p, f))))); + for (const s of p.stages) { + const n = m.byId.get(s.id)!; + const c = s.i + 2; + out.push(h("section", { class: `${P}-journey-stage`, "data-focal": s.focal ? "" : undefined }, + stop(P, m, n, dyn, level, { class: `${P}-node ${P}-journey-head`, style: `--_c:${c};--_r:1;--_r2:2` }, + h("span", { class: `${P}-kind` }, iso(`${p.words.stage} ${s.i + 1}`), h("span", { class: `${P}-journey-word` }, iso(s.levelWord))), + h("span", { class: `${P}-name` }, iso(s.name))), + p.bands.map((f, k) => { + const v = s.fields[f]; + return h("div", { class: `${P}-journey-cell`, "data-empty": v ? undefined : "", style: `--_c:${c};--_r:${k + 3}` }, + h("span", { class: `${P}-journey-cell-label`, "aria-hidden": "true" }, iso(bandWord(p, f))), + v ? (f === "quote" ? h("q", { class: `${P}-journey-value` }, iso(v)) : h("span", { class: `${P}-journey-value` }, iso(v))) : h("span", { class: `${P}-empty` }, iso(p.words.none))); + }))); + } + return out; +} + +function journeyInk(el: HTMLElement, m: Model, P: string, tk: Tokens, drawn: boolean): { geo: Geo; ink: string } { + const p = jplan(m); + const geo = blankGeo(el); + const origin = el.getBoundingClientRect(); + const ox = origin.left - Math.floor(origin.left), oy = origin.top - Math.floor(origin.top); + const track = el.querySelector(`.${P}-journey-track`); + if (!track) return { geo, ink: "" }; + const tr = rectOf(track, origin); + const s = tk.space; + // Drawn: five levels space-8 apart with space-4 above and below. Stacked, the strip: space-6 apart, with the numbers under it. + const pitch = drawn ? s("8") : s("6"); + const top = tr.t + (drawn ? s("4") : s("2")); + const yOf = (lv: number) => top + (5 - lv) * pitch; + const half = (v: number, o: number) => Math.round(v + o - 0.5) + 0.5 - o; + const whole = (v: number, o: number) => Math.round(v + o) - o; + // The levels' lines span the track and the label column's level words; the labels column is the plot's own start. + const plot = rectOf(el.querySelector(`.${P}-journey-plot`)!, origin); + let svg = ""; + for (let lv = 1; lv <= 5; lv++) if (drawn || lv === 1 || lv === 3 || lv === 5) svg += ``; + // The discs at each stage's column centre: drawn, the head's measured column; stacked, the strip's slot. + const xs = p.stages.map((st) => { + const head = drawn ? el.querySelector(`.${P}-node[data-node="${CSS.escape(st.id)}"]`) : el.querySelector(`.${P}-journey-slot[data-stage="${CSS.escape(st.id)}"]`); + const r = head ? rectOf(head, origin) : tr; + return whole((r.l + r.r) / 2, ox); + }); + const pts: Pt[] = p.stages.map((st, k) => ({ x: xs[k]!, y: whole(yOf(st.level), oy) })); + if (pts.length > 1) svg += ``; + const rad = tk.dot / 2 + 1; + for (const q of pts) svg += ``; + return { geo, ink: `${svg}` }; +} + +function journeyKey(P: string, m: Model): VElement | null { + const out: VElement[] = []; + const line = txt((m.legend as { line?: string }).line); + out.push(entry(P, h("svg", { class: `${P}-swatch`, ...svgA(24, 16) }, h("path", { class: `${P}-journey-line`, d: "M0 11L12 5L24 11" }), h("circle", { class: `${P}-journey-cut`, cx: 12, cy: 5, r: 6 }), h("circle", { class: `${P}-journey-disc`, cx: 12, cy: 5, r: 4 })), line ?? "")); + if (m.nodes.some((n) => n.focal) && m.legend.focal) out.push(entry(P, focalSwatch(P), m.legend.focal, { "data-focal": "" })); + return keyOf(P, out); +} + +function journeyList(P: string, m: Model): VNode[] { + const p = jplan(m); + return [h("ol", { class: `${P}-list-items` }, p.stages.map((s) => h("li", null, listStrong(s.name), `: ${s.levelWord}.`, + J_FIELDS.filter((f) => s.fields[f]).map((f) => [` ${bandWord(p, f)}: `, f === "quote" ? h("q", null, iso(s.fields[f]!)) : sentence(s.fields[f]!)]), focalWords(m, s.focal))))]; +} + +function journeyLeast(m: Model, tk: Tokens, measure: ExtMeasureKit["measure"]): number { + const p = jplan(m); + const pad = 2 * tk.space("3") + 2 * tk.hair; + let track = tk.node; + for (const s of p.stages) { + track = Math.max(track, pad + widestOf(measure, [[s.name, "name"]])); + track = Math.max(track, pad + Math.ceil(measure(`${p.words.stage} ${s.i + 1}`, "mono") + tk.space("2") + measure(s.levelWord, "tab"))); + for (const f of p.bands) track = Math.max(track, widestOf(measure, [[s.fields[f], "sm"]])); + } + return fit(tk, p.stages.length, track, labelColumn(m, tk, measure)); +} + +// ============================================================================================================================================ +// Service blueprint (1.4): stages across, layers down, three rules in fixed gaps, each named on the rule. +// ============================================================================================================================================ + +const LAYERS: BlueprintLayer[] = ["evidence", "customer", "frontstage", "backstage", "support"]; +const LAYER_WORDS: Record = { evidence: "Evidence", customer: "Customer", frontstage: "Frontstage", backstage: "Backstage", support: "Support" }; +type Rule = "interaction" | "visibility" | "internal"; +interface BCell { id: string; stage: number; layer: BlueprintLayer; empty: boolean; name: string; detail?: string; mono: boolean; focal: boolean; href?: string; blank?: boolean } +interface BArrow { i: number; from: string; to: string; kind: "main" | "plain" } +interface BlueprintPlan { + stages: Array<{ id: string; name: string; time?: string }>; + layers: BlueprintLayer[]; + layerWords: Record; + rules: Record; + cells: BCell[]; + arrows: BArrow[]; + words: Labels; + labelWords: Array<[string, "xs-500" | "sans" | "xs-600"]>; +} +const bplan = (m: Model) => m.plan as BlueprintPlan; +/** The rule that sits above a layer, in its fixed gap: interaction above frontstage, visibility above backstage, internal above support. */ +const ruleAbove = (l: BlueprintLayer): Rule | null => (l === "frontstage" ? "interaction" : l === "backstage" ? "visibility" : l === "support" ? "internal" : null); +const cellId = (stage: string, layer: string) => `${stage}:${layer}`; + +function buildBlueprint(spec: DiagramSpec, kit: ExtBuildKit): ExtBuilt { + const words = wordsOf(spec, { stage: "Stage", none: "None", keyVisibility: "the customer sees what is above it", keyInteraction: "", keyInternal: "" }); + const stages = (Array.isArray(spec.stages) ? spec.stages : []).map((raw) => { const s = raw as BlueprintStage; return { id: String(s.id ?? ""), name: String(s.name ?? ""), time: txt(s.time) }; }); + const rawCells = (Array.isArray(spec.cells) ? spec.cells : []) as BlueprintCell[]; + const used = new Set(["customer", "frontstage", "backstage"]); + for (const c of rawCells) if (LAYERS.includes(c.layer)) used.add(c.layer); else kit.dev && kit.warn(`a cell names the layer "${String(c.layer)}", which is not evidence, customer, frontstage, backstage or support`); + const layers = LAYERS.filter((l) => used.has(l)); + const lw = (spec.layerLabels ?? {}) as Partial>; + const layerWords = Object.fromEntries(LAYERS.map((l) => [l, txt(lw[l]) ?? LAYER_WORDS[l]])) as Record; + const rw = (spec.ruleLabels ?? {}) as BlueprintRuleLabels; + const rules: Record = { interaction: txt(rw.interaction) ?? "Line of interaction", visibility: txt(rw.visibility) ?? "Line of visibility", internal: txt(rw.internal) ?? "Line of internal interaction" }; + const given = new Map(); + for (const c of rawCells) { const k = cellId(String(c.stage), String(c.layer)); if (kit.dev && given.has(k)) kit.warn(`the cell ${k} is given twice`); given.set(k, c); } + for (const k of given.keys()) if (kit.dev && !stages.some((s) => k.startsWith(`${s.id}:`))) kit.warn(`the cell ${k} names a stage that is not in stages`); + // Every cell of the grid is a stop, an empty one included (1.4): "Cold sandbox, Frontstage: none". + const cells: BCell[] = []; + for (const [si, st] of stages.entries()) for (const layer of layers) { + const raw = given.get(cellId(st.id, layer)); + const name = txt(raw?.name); + cells.push({ id: cellId(st.id, layer), stage: si, layer, empty: !name, name: name ?? "", detail: name ? txt(raw!.detail) : undefined, mono: Boolean(raw?.detailMono), focal: Boolean(name && raw?.focal), href: name ? txt(raw?.href) : undefined, blank: raw?.target === "_blank" }); + } + // The keys' order is the stage's column, then its layers: cell by cell down a stage. + const nodes: MNode[] = cells.map((c, i) => ({ id: c.id, i, name: c.empty ? words.none : c.name, detail: c.detail, mono: c.mono, focal: c.focal, col: c.stage + 1, row: layers.indexOf(c.layer) + 1, row2: layers.indexOf(c.layer) + 1, branch: false, shape: "box", href: c.href, blank: c.blank })); + const byId = new Map(cells.map((c) => [c.id, c])); + const arrows: BArrow[] = []; + const edges: MEdge[] = []; + for (const a of (Array.isArray(spec.arrows) ? spec.arrows : []) as BlueprintArrow[]) { + const from = cellId(String(a.from?.stage), String(a.from?.layer)), to = cellId(String(a.to?.stage), String(a.to?.layer)); + const f = byId.get(from), t = byId.get(to); + if (!f || !t || f.empty || t.empty) { kit.dev && kit.error(`the arrow ${from} to ${to} names a cell that is empty or not drawn`); continue; } + // A blueprint's arrows are main or plain (answer 1): dashed means its two lines of interaction alone. + if ((a.kind as string) === "dashed") kit.dev && kit.error(`the arrow ${from} to ${to} is dashed: a blueprint's arrows are main or plain (its lines of interaction are the dashed marks), so it is drawn plain`); + const sameStage = f.stage === t.stage && f.layer !== t.layer; + const sameLayer = f.layer === t.layer && Math.abs(f.stage - t.stage) === 1; + if (!sameStage && !sameLayer) { kit.dev && kit.error(`the arrow ${from} to ${to} joins two cells of neither one stage nor neighbouring stages of one layer, so it is not drawn`); continue; } + const kind: "main" | "plain" = a.kind === "main" ? "main" : "plain"; + arrows.push({ i: arrows.length, from, to, kind }); + edges.push({ i: edges.length, from, to, kind }); + } + if (kit.dev) { + if (arrows.some((a) => a.kind === "main") && !kit.legend.main) kit.warn("main arrows are drawn but the legend has no words for them (legend.main)"); + if (arrows.some((a) => a.kind === "plain") && !kit.legend.plain) kit.warn("plain arrows are drawn but the legend has no words for them (legend.plain)"); + if (cells.filter((c) => c.focal).length > 1) kit.warn("more than one cell is focal: a blueprint has one at most"); + } + const labelWords: BlueprintPlan["labelWords"] = layers.map((l) => [layerWords[l], "xs-500"] as [string, "xs-500"]); + const plan: BlueprintPlan = { stages, layers, layerWords, rules, cells, arrows, words, labelWords }; + return { nodes, edges, plan, cols: Math.max(1, stages.length), rows: Math.max(1, layers.length) }; +} +const bcell = (m: Model, id: string) => bplan(m).cells.find((c) => c.id === id)!; +const stageName = (p: BlueprintPlan, c: BCell) => p.stages[c.stage]!.name; + +function blueprintSentence(m: Model, n: MNode): string { + const p = bplan(m), c = bcell(m, n.id); + if (c.empty) return `${stageName(p, c)}, ${p.layerWords[c.layer]}: ${p.words.none.toLowerCase()}.`; + const parts = [`${c.name}. ${stageName(p, c)}, ${p.layerWords[c.layer]}.`]; + if (c.detail) parts.push(sentence(c.detail)); + const to = p.arrows.filter((a) => a.from === c.id).map((a) => bcell(m, a.to)).map((t) => `${t.name} (${t.stage === c.stage ? p.layerWords[t.layer] : stageName(p, t)})`); + const from = p.arrows.filter((a) => a.to === c.id).map((a) => bcell(m, a.from)).map((f) => `${f.name} (${f.stage === c.stage ? p.layerWords[f.layer] : stageName(p, f)})`); + if (from.length) parts.push(`From: ${from.join(", ")}.`); + if (to.length) parts.push(`To: ${to.join(", ")}.`); + if (c.focal && m.legend.focal) parts.push(sentence(m.legend.focal)); + return parts.join(" "); +} + +/** A rule: its name at the start edge, space-3, then the line to the end (a 4 on 4 dash in diagram-structure, or the line of visibility, 2px solid). */ +function ruleTree(P: string, rule: Rule, words: string, extra: VAttrs = {}): VElement { + return h("div", { class: `${P}-bp-rule`, "data-rule": rule, "aria-hidden": "true", ...extra }, + h("span", { class: `${P}-bp-rule-name` }, iso(words)), + h("svg", { class: `${P}-bp-rule-line`, height: 2, focusable: "false" }, h("line", { x1: 0, x2: "100%", y1: rule === "visibility" ? 1 : 0.5, y2: rule === "visibility" ? 1 : 0.5 }))); +} + +/** The drawn grid's rows: a head row, then each layer with a rule's row above it where the type puts one. */ +function blueprintRows(p: BlueprintPlan): { layer: Map; rule: Map } { + const layer = new Map(), rule = new Map(); + let r = 2; + for (const l of p.layers) { + const above = ruleAbove(l); + if (above) rule.set(above, r++); + layer.set(l, r++); + } + return { layer, rule }; +} + +function blueprintDrawing(P: string, m: Model, dyn: Dyn, level?: number): VNode[] { + const p = bplan(m); + const rows = blueprintRows(p); + const out: VNode[] = []; + // Drawn: the rules span the grid, each on its own row; the layers' names in the label column. + for (const [rule, r] of rows.rule) out.push(ruleTree(P, rule, p.rules[rule], { "data-span": "", style: `--_r:${r}` })); + for (const [l, r] of rows.layer) out.push(h("span", { class: `${P}-matrix-label`, style: `--_r:${r}`, "aria-hidden": "true" }, iso(p.layerWords[l]))); + p.stages.forEach((st, si) => { + const c = si + 2; + const kids: VChild[] = [h("div", { class: `${P}-bp-head`, style: `--_c:${c};--_r:1` }, + h("span", { class: `${P}-kind` }, iso(`${p.words.stage} ${si + 1}`), st.time ? h("span", { class: `${P}-bp-time` }, " · ", iso(st.time)) : null), + h("span", { class: `${P}-name` }, iso(st.name)))]; + for (const l of p.layers) { + const above = ruleAbove(l); + // Stacked, all three rules are inside every stage, in their gaps. + if (above) kids.push(ruleTree(P, above, p.rules[above], { "data-in": "" })); + const cell = p.cells.find((x) => x.stage === si && x.layer === l)!; + const n = m.byId.get(cell.id)!; + const leaves = p.arrows.filter((a) => a.from === cell.id).map((a) => bcell(m, a.to)); + kids.push(stop(P, m, n, dyn, level, { class: `${P}-node ${P}-bp-cell`, "data-empty": cell.empty ? "" : undefined, style: `--_c:${c};--_r:${rows.layer.get(l)};--_r2:${rows.layer.get(l)! + 1}` }, + h("span", { class: `${P}-bp-layer`, "aria-hidden": "true" }, iso(p.layerWords[l])), + h("span", { class: `${P}-bp-body` }, + cell.empty ? h("span", { class: `${P}-empty` }, iso(p.words.none)) : nodeWords(P, cell), + // Stacked, an arrow is said: the cell it leaves ends with "→ " and the target's name (and its stage, where that is another one). + leaves.map((t) => h("span", { class: `${P}-bp-to` }, `${m.rtl ? "←" : "→"} `, iso(t.stage === cell.stage ? t.name : `${t.name} (${stageName(p, t)})`)))))); + } + out.push(h("section", { class: `${P}-bp-stage` }, kids)); + }); + return out; +} + +function blueprintInk(el: HTMLElement, m: Model, P: string, tk: Tokens, drawn: boolean): { geo: Geo; ink: string } { + const p = bplan(m); + const geo = blankGeo(el); + if (!drawn || !p.arrows.length) return { geo, ink: "" }; + const origin = el.getBoundingClientRect(); + geo.ox = origin.left - Math.floor(origin.left); geo.oy = origin.top - Math.floor(origin.top); + const rect = (id: string) => { const e = el.querySelector(`.${P}-node[data-node="${CSS.escape(id)}"]`); return e ? rectOf(e, origin) : null; }; + const snap = (v: number, o: number, w: number) => (w % 2 ? Math.round(v + o - 0.5) + 0.5 - o : Math.round(v + o) - o); + for (const a of p.arrows) { + const f = bcell(m, a.from), t = bcell(m, a.to); + const r1 = rect(a.from), r2b = rect(a.to); + if (!r1 || !r2b) continue; + const w = a.kind === "main" ? tk.line : tk.hair; + let pts: Pt[]; + let dir: GLine["dir"]; + if (f.stage === t.stage) { + const down = p.layers.indexOf(t.layer) > p.layers.indexOf(f.layer); + if (Math.abs(p.layers.indexOf(t.layer) - p.layers.indexOf(f.layer)) > 1) { + // Through the column gutter where it passes a layer: out of the end side, along the gutter's middle, into the end side. + const endX = m.rtl ? Math.min(r1.l, r2b.l) : Math.max(r1.r, r2b.r); + const gx = snap(m.rtl ? endX - tk.space("2") : endX + tk.space("2"), geo.ox, w); + const y1 = snap((r1.t + r1.b) / 2, geo.oy, w), y2 = snap((r2b.t + r2b.b) / 2, geo.oy, w); + pts = [{ x: m.rtl ? r1.l : r1.r, y: y1 }, { x: gx, y: y1 }, { x: gx, y: y2 }, { x: m.rtl ? r2b.l : r2b.r, y: y2 }]; + dir = m.rtl ? "right" : "left"; + } else { + const x = snap((Math.max(r1.l, r2b.l) + Math.min(r1.r, r2b.r)) / 2, geo.ox, w); + pts = [{ x, y: down ? r1.b : r1.t }, { x, y: down ? r2b.t : r2b.b }]; + dir = down ? "down" : "up"; + } + } else { + const right = (t.stage > f.stage) !== Boolean(m.rtl); + const y = snap((Math.max(r1.t, r2b.t) + Math.min(r1.b, r2b.b)) / 2, geo.oy, w); + pts = [{ x: right ? r1.r : r1.l, y }, { x: right ? r2b.l : r2b.r, y }]; + dir = right ? "right" : "left"; + } + geo.lines.push({ i: a.i, from: a.from, to: a.to, kind: a.kind, pts, tip: pts[pts.length - 1]!, dir, width: w }); + } + const head = tk.head; + const lines = geo.lines.map((l) => { + const u = l.dir === "up" ? { x: 0, y: -1 } : l.dir === "down" ? { x: 0, y: 1 } : l.dir === "left" ? { x: -1, y: 0 } : { x: 1, y: 0 }; + const pts = l.pts.map((q) => ({ ...q })); + const last = pts[pts.length - 1]!; + last.x -= u.x * (head - 1); last.y -= u.y * (head - 1); + const bx = l.tip.x - u.x * head, by = l.tip.y - u.y * head, px = -u.y * (head / 2), py = u.x * (head / 2); + return ``; + }).join(""); + return { geo, ink: `${lines}` }; +} + +function blueprintKey(P: string, m: Model): VElement | null { + const p = bplan(m); + const out: VElement[] = []; + const said = (rule: Rule, extra: string) => (extra ? `${p.rules[rule]}: ${extra}` : p.rules[rule]); + out.push(entry(P, ruleSwatch(P, "main"), said("visibility", p.words.keyVisibility))); + out.push(entry(P, ruleSwatch(P, "dashed"), said("interaction", p.words.keyInteraction))); + if (p.layers.includes("support")) out.push(entry(P, ruleSwatch(P, "dashed"), said("internal", p.words.keyInternal))); + for (const k of ["main", "plain"] as DiagramLineKind[]) if (p.arrows.some((a) => a.kind === k) && m.legend[k]) out.push(entry(P, lineSwatch(P, k), m.legend[k]!, { "data-line": "", "data-when": "drawn" })); + if (m.nodes.some((n) => n.focal) && m.legend.focal) out.push(entry(P, focalSwatch(P), m.legend.focal, { "data-focal": "" })); + return keyOf(P, out); +} + +function blueprintList(P: string, m: Model): VNode[] { + const p = bplan(m); + const sub = Math.min(6, m.heading + 1); + return p.stages.flatMap((st, si) => [ + h(`h${sub}`, { class: `${P}-list-head` }, `${p.words.stage} ${si + 1}: `, iso(st.name), st.time ? ` (${st.time})` : ""), + h("ul", { class: `${P}-list-items` }, p.layers.map((l) => { + const c = p.cells.find((x) => x.stage === si && x.layer === l)!; + const above = ruleAbove(l); + const to = p.arrows.filter((a) => a.from === c.id).map((a) => bcell(m, a.to)); + return h("li", null, above ? `${p.rules[above]}, then ` : "", listStrong(p.layerWords[l]), ": ", c.empty ? `${p.words.none.toLowerCase()}.` : [iso(c.name), c.detail ? `, ${c.detail}` : "", "."], + to.length ? ` To ${to.map((t) => (t.stage === c.stage ? t.name : `${t.name} (${stageName(p, t)})`)).join(", ")}.` : "", focalWords(m, c.focal)); + })), + ]); +} + +function blueprintLeast(m: Model, tk: Tokens, measure: ExtMeasureKit["measure"]): number { + const p = bplan(m); + const pad = 2 * tk.space("3") + 2 * tk.hair; + let track = tk.node; + p.stages.forEach((st, si) => { + track = Math.max(track, widestOf(measure, [[st.name, "name"], [`${p.words.stage} ${si + 1}`, "mono", true], [st.time, "tab"]])); + }); + for (const c of p.cells) track = Math.max(track, pad + widestOf(measure, [[c.name, "name"], [c.detail, c.mono ? "mono" : "sans"]])); + // A rule's name is unbreakable and sits in the label column's start: it may run on past it, never past the first track. + return fit(tk, p.stages.length, track, labelColumn(m, tk, measure)); +} + +// ============================================================================================================================================ +// Story map (1.5): a backbone of activities, slices down, one release cut. +// ============================================================================================================================================ + +interface SStory extends ReturnType { activity: number; slice: number } +interface StoryPlan { + persona?: string; + activities: Array<{ id: string; name: string; steps: string[] }>; + slices: Array<{ id: string; label: string; count: number; below: boolean }>; + stories: SStory[]; + cut?: { after: number; label: string }; + words: Labels; + labelWords: Array<[string, "name" | "tab" | "xs-600"]>; +} +const splan = (m: Model) => m.plan as StoryPlan; +const storyCount = (p: StoryPlan, n: number) => `${n} ${n === 1 ? p.words.story.one : p.words.story.other}`; + +function buildStoryMap(spec: DiagramSpec, kit: ExtBuildKit): ExtBuilt { + const words = wordsOf(spec, { activity: "Activity", noStories: "No stories", backbone: "Backbone activity", story: { one: "story", other: "stories" } }); + const activities = (Array.isArray(spec.activities) ? spec.activities : []).map((raw) => { const a = raw as StoryActivity; return { id: String(a.id ?? ""), name: String(a.name ?? ""), steps: Array.isArray(a.steps) ? a.steps.map(String) : [] }; }); + const slicesIn = (Array.isArray(spec.slices) ? spec.slices : []).map((raw) => { const s = raw as StorySlice; return { id: String(s.id ?? ""), label: String(s.label ?? "") }; }); + if (kit.dev && slicesIn.some((s) => "cutAfter" in (s as object))) kit.error("a story map has one cut: write `cut: { after, label }`, not a cut on a slice"); + const cutIn = spec.cut as StoryCut | undefined; + const cutAt = cutIn ? slicesIn.findIndex((s) => s.id === String(cutIn.after)) : -1; + if (kit.dev && cutIn && cutAt < 0) kit.error(`the cut comes after "${String(cutIn.after)}", which is not a slice`); + if (kit.dev && cutIn && !txt(cutIn.label)) kit.error("the cut needs its words (cut.label): the key must say what it divides"); + const cut = cutIn && cutAt >= 0 ? { after: cutAt, label: String(cutIn.label ?? "") } : undefined; + const stories: SStory[] = []; + for (const raw of (Array.isArray(spec.stories) ? spec.stories : []) as StoryCard[]) { + const a = activities.findIndex((x) => x.id === String(raw.activity)), s = slicesIn.findIndex((x) => x.id === String(raw.slice)); + if (a < 0 || s < 0) { kit.dev && kit.warn(`the story ${String(raw.id)} names an activity or a slice that is not there`); continue; } + if (kit.dev && "tag" in (raw as object)) kit.warn(`the story ${String(raw.id)} has a "tag": its code is its \`kind\``); + stories.push({ ...card(raw), activity: a, slice: s }); + } + // Activity order inside a slice; the author's order inside a cell. + const ordered = slicesIn.flatMap((_, s) => activities.flatMap((_a, a) => stories.filter((x) => x.slice === s && x.activity === a))); + // A story's row in the keys' grid: its slice's rows, then its place in its cell. + let base = 0; + const rowOf = new Map(); + slicesIn.forEach((_, s) => { + const most = Math.max(1, ...activities.map((_a, a) => stories.filter((x) => x.slice === s && x.activity === a).length)); + for (const [a] of activities.entries()) stories.filter((x) => x.slice === s && x.activity === a).forEach((x, k) => rowOf.set(x.id, base + k + 1)); + base += most; + }); + const nodes = ordered.map((x, i) => mnode(x, i, x.activity + 1, rowOf.get(x.id) ?? 1)); + checkIds(kit, nodes.map((n) => n.id)); + if (kit.dev && nodes.filter((n) => n.focal).length > 1) kit.warn("more than one story is focal: a story map has one at most"); + const slices = slicesIn.map((s, k) => ({ ...s, count: stories.filter((x) => x.slice === k).length, below: cut !== undefined && k > cut.after })); + const labelWords: StoryPlan["labelWords"] = [...slices.map((s) => [s.label, "name"] as [string, "name"]), ...slices.map((s) => [storyCount({ words } as StoryPlan, s.count), "tab"] as [string, "tab"])]; + const plan: StoryPlan = { persona: txt(spec.persona), activities, slices, stories: ordered, cut, words, labelWords }; + return { nodes, edges: [], plan, cols: Math.max(1, activities.length), rows: Math.max(1, base) }; +} +const sstory = (m: Model, id: string) => splan(m).stories.find((x) => x.id === id)!; + +function storySentence(m: Model, n: MNode): string { + const p = splan(m), x = sstory(m, n.id); + const parts = [sentence(x.kind ? `${x.name}, ${x.kind}` : x.name), `${p.words.activity} ${x.activity + 1}, ${p.activities[x.activity]!.name}. ${p.slices[x.slice]!.label}.`]; + if (x.detail) parts.push(sentence(x.detail)); + if (x.focal && m.legend.focal) parts.push(sentence(m.legend.focal)); + return parts.join(" "); +} + +function storyMeta(P: string, m: Model): VElement | null { + const p = splan(m); + return p.persona ? h("p", { class: `${P}-meta` }, h("span", { class: `${P}-meta-first` }, iso(p.persona))) : null; +} + +function storyDrawing(P: string, m: Model, dyn: Dyn, level?: number): VNode[] { + const p = splan(m); + const out: VNode[] = []; + const hasSteps = p.activities.some((a) => a.steps.length); + // The backbone: a card an activity (a diagram-structure contour in place of the rim), then its steps as chips. Stacked, one card holding them all. + out.push(h("div", { class: `${P}-story-backbone` }, p.activities.map((a, k) => [ + h("div", { class: `${P}-story-activity`, style: `--_c:${k + 2};--_r:1` }, + h("span", { class: `${P}-kind` }, iso(`${p.words.activity} ${k + 1}`)), + h("span", { class: `${P}-name` }, iso(a.name))), + a.steps.length ? h("span", { class: `${P}-story-steps`, style: `--_c:${k + 2};--_r:2` }, a.steps.map((s) => h("span", { class: `${P}-story-step` }, iso(s)))) : null, + ]))); + let r = hasSteps ? 3 : 2; + p.slices.forEach((sl, k) => { + // Slices are ruled apart with the divider; the cut is the rule after the slice it names. + if (!(p.cut && p.cut.after === k - 1)) out.push(h("span", { class: `${P}-matrix-rule`, style: `--_r:${r++}`, "aria-hidden": "true" })); + out.push(h("section", { class: `${P}-story-slice`, "data-below": sl.below ? "" : undefined }, + h("div", { class: `${P}-story-slice-head`, style: `--_r:${r}` }, + h("span", { class: `${P}-story-slice-name` }, iso(sl.label)), + h("span", { class: `${P}-story-count` }, iso(storyCount(p, sl.count)))), + p.activities.map((a, ai) => { + const mine = p.stories.filter((x) => x.slice === k && x.activity === ai); + if (!mine.length) return h("div", { class: `${P}-story-slot`, style: `--_c:${ai + 2};--_r:${r}` }, h("span", { class: `${P}-empty` }, iso(p.words.noStories)), h("span", { class: `${P}-story-left-out` }, iso(`${p.words.noStories} in ${a.name}`))); + return h("div", { class: `${P}-story-cell`, style: `--_c:${ai + 2};--_r:${r}` }, mine.map((x) => { + const n = m.byId.get(x.id)!; + return stop(P, m, n, dyn, level, { class: `${P}-node ${P}-story-card` }, + ...nodeWords(P, x, h("span", { class: `${P}-kind` }, h("span", { class: `${P}-story-of` }, iso(`${ai + 1} · ${a.name}`)), x.kind ? h("span", { class: `${P}-story-code` }, iso(x.kind)) : null))); + })); + }))); + r++; + if (p.cut && p.cut.after === k) { + out.push(h("div", { class: `${P}-story-cut`, style: `--_r:${r}`, "aria-hidden": "true" }, h("span", { class: `${P}-story-cut-name` }, iso(p.cut.label)), h("span", { class: `${P}-story-cut-line` }))); + r++; + } + }); + return out; +} + +function storyKey(P: string, m: Model): VElement | null { + const p = splan(m); + const out: VElement[] = []; + if (p.cut) out.push(entry(P, ruleSwatch(P, "main"), p.cut.label)); + out.push(entry(P, ruleSwatch(P, "contour"), p.words.backbone)); + if (m.nodes.some((n) => n.focal) && m.legend.focal) out.push(entry(P, focalSwatch(P), m.legend.focal, { "data-focal": "" })); + return keyOf(P, out); +} + +function storyList(P: string, m: Model): VNode[] { + const p = splan(m); + const sub = Math.min(6, m.heading + 1); + const out: VNode[] = [h(`h${sub}`, { class: `${P}-list-head` }, iso(p.words.backbone)), h("ol", { class: `${P}-list-items` }, p.activities.map((a) => h("li", null, listStrong(a.name), a.steps.length ? `: ${a.steps.join(", ")}.` : ".")))]; + p.slices.forEach((sl, k) => { + out.push(h(`h${sub}`, { class: `${P}-list-head` }, iso(sl.label), `: ${storyCount(p, sl.count)}`)); + const mine = p.stories.filter((x) => x.slice === k); + const empty = p.activities.filter((_, ai) => !mine.some((x) => x.activity === ai)); + out.push(h("ul", { class: `${P}-list-items` }, [ + ...mine.map((x) => h("li", null, `${p.activities[x.activity]!.name}: `, listStrong(x.name), x.kind ? `, ${x.kind}` : "", x.detail ? `. ${sentence(x.detail)}` : ".", focalWords(m, x.focal))), + ...empty.map((a) => h("li", null, `${p.words.noStories} in ${a.name}.`)), + ])); + if (p.cut && p.cut.after === k) out.push(h("p", { class: `${P}-list-group` }, iso(p.cut.label))); + }); + return out; +} + +function storyLeast(m: Model, tk: Tokens, measure: ExtMeasureKit["measure"]): number { + const p = splan(m); + const pad = 2 * tk.space("3") + 2 * tk.hair; + let track = tk.node; + p.activities.forEach((a, k) => { track = Math.max(track, pad + widestOf(measure, [[a.name, "name"], [`${p.words.activity} ${k + 1}`, "mono", true]]), ...a.steps.map((s) => widestOf(measure, [[s, "sans"]]) + 2 * tk.space("2-5"))); }); + for (const x of p.stories) track = Math.max(track, pad + widestOf(measure, [[x.name, "name"], [x.kind, "mono"], [x.detail, x.mono ? "mono" : "sans"]])); + track = Math.max(track, widestOf(measure, [[p.words.noStories, "sans"]]) + pad); + return fit(tk, p.activities.length, track, labelColumn(m, tk, measure)); +} + +// ============================================================================================================================================ +// The four modules +// ============================================================================================================================================ + +const noTrace = () => false; +const common = (noun: string) => ({ + stop: `a ${noun}`, + hasStops: (_m: Model, dyn: Dyn) => Boolean(dyn.layout && !dyn.bare), + hint: (m: Model, drawn: boolean) => hintFour(m, drawn, noun), + keys: (m: Model, drawn: boolean) => keysWords(m, drawn, noun), + rootStyle: rootPlace, +}); + +let kanban: DiagramTypeExt | undefined, journey: DiagramTypeExt | undefined, blueprint: DiagramTypeExt | undefined, story: DiagramTypeExt | undefined; +/** The kanban's module, made at its first use. */ +export function kanbanType(): DiagramTypeExt { + return (kanban ??= { type: "kanban", build: buildKanban, sentence: kanbanSentence, key: kanbanKey, list: kanbanList, drawing: kanbanDrawing, least: kanbanLeast, layout: matrixLayout(), traces: noTrace, ...common("card") }); +} +/** The journey's module, made at its first use. Its arrows are ← → drawn and ↑ ↓ stacked; nothing traces. */ +export function journeyType(): DiagramTypeExt { + return (journey ??= { + type: "journey", build: buildJourney, sentence: journeySentence, key: journeyKey, list: journeyList, meta: journeyMeta, drawing: journeyDrawing, least: journeyLeast, layout: matrixLayout(journeyInk), traces: noTrace, ...common("stage"), + hint: (m, drawn) => [{ keys: drawn ? ["←", "→"] : ["↑", "↓"], words: "a stage" }, { keys: ["Home", "End"], words: "the ends" }, ...(m.nodes.some((n) => n.href) ? [{ keys: ["Enter"], words: "open" }] : [])], + }); +} +/** The service blueprint's module, made at its first use. A part traces only where arrows are drawn. */ +export function serviceBlueprintType(): DiagramTypeExt { + return (blueprint ??= { + type: "service-blueprint", build: buildBlueprint, sentence: blueprintSentence, key: blueprintKey, list: blueprintList, drawing: blueprintDrawing, least: blueprintLeast, layout: matrixLayout(blueprintInk), ...common("cell"), + traces: (m, drawn) => drawn && m.edges.length > 0, + hint: (m, drawn) => [...hintFour(m, drawn, "cell"), ...(drawn && m.edges.length ? [{ keys: ["Esc"], words: "clear" }] : [])], + }); +} +/** The story map's module, made at its first use. */ +export function storyMapType(): DiagramTypeExt { + return (story ??= { type: "story-map", build: buildStoryMap, sentence: storySentence, key: storyKey, list: storyList, meta: storyMeta, drawing: storyDrawing, least: storyLeast, layout: matrixLayout(), traces: noTrace, ...common("story") }); +} diff --git a/packages/react/src/journey-diagram.tsx b/packages/react/src/journey-diagram.tsx new file mode 100644 index 00000000..3dc9d021 --- /dev/null +++ b/packages/react/src/journey-diagram.tsx @@ -0,0 +1,33 @@ +import * as React from "react"; + +import { DiagramFigure } from "./diagram-figure"; +import type { DiagramFigureProps } from "./diagram-figure"; +import { journeyType } from "./diagram-matrix"; +import type { JourneyLabels, JourneyLevel, JourneyStage } from "./diagram-matrix"; + +export type { JourneyLabels, JourneyLevel, JourneyStage } from "./diagram-matrix"; +export type { DiagramAction, DiagramActionContext, DiagramFigureProps, DiagramLayoutInfo } from "./diagram-figure"; + +export interface JourneyDiagramProps extends DiagramFigureProps { + /** The one actor. */ + actor: string; + /** The one scenario. */ + scenario: string; + /** The scale's five steps, lowest first, in the author's own words ("Blocked" to "Confident"). */ + scale: [string, string, string, string, string]; + /** The stages in order, each at a level from 1 to 5 of the scale. */ + stages: JourneyStage[]; + /** `line` is required: what the scale measures. */ + legend: DiagramFigureProps["legend"] & { line: string }; + /** The built-in words, for an app that writes another language. */ + labels?: JourneyLabels; +} + +/** + * A journey (DECISIONS 359): one actor in one scenario, and a scale of five steps the author names. Each stage's head writes its level; the line is the + * chart's (straight, 2px, one ink, an 8px disc a stage). Stacked it is a strip over the stage cards. Nothing traces. The implementation has not been reviewed. + */ +export function JourneyDiagram({ actor, scenario, scale, stages, labels, motion: _motion, entrance: _entrance, title, heading, legend, ...props }: JourneyDiagramProps) { + const spec = React.useMemo(() => ({ type: "journey" as const, ext: journeyType(), title, heading, legend, actor, scenario, scale, stages, labels }), [title, heading, legend, actor, scenario, scale, stages, labels]); + return ; +} diff --git a/packages/react/src/kanban-diagram.tsx b/packages/react/src/kanban-diagram.tsx new file mode 100644 index 00000000..aa8bb710 --- /dev/null +++ b/packages/react/src/kanban-diagram.tsx @@ -0,0 +1,27 @@ +import * as React from "react"; + +import { DiagramFigure } from "./diagram-figure"; +import type { DiagramFigureProps } from "./diagram-figure"; +import { kanbanType } from "./diagram-matrix"; +import type { KanbanCard, KanbanColumn, KanbanLabels } from "./diagram-matrix"; + +export type { KanbanCard, KanbanColumn, KanbanLabels } from "./diagram-matrix"; +export type { DiagramAction, DiagramActionContext, DiagramFigureProps, DiagramLayoutInfo } from "./diagram-figure"; + +export interface KanbanDiagramProps extends DiagramFigureProps { + /** The columns in workflow order. `limit` is the column's most; `more` counts cards not drawn (they are in its count). */ + columns: KanbanColumn[]; + /** The cards, each in its column, in the order drawn. A blocked card carries its reason. */ + cards: KanbanCard[]; + /** The built-in words, for an app that writes another language. */ + labels?: KanbanLabels; +} + +/** + * A kanban (DECISIONS 359): a count of cards in states at one moment. It is read-only: nothing drags and there is no move key. A head is its title and its + * count in words ("3, max 2 · Over limit"), every card counted; over its limit a column's count is 600 and its rule 2px. The implementation has not been reviewed. + */ +export function KanbanDiagram({ columns, cards, labels, motion: _motion, entrance: _entrance, title, heading, legend, ...props }: KanbanDiagramProps) { + const spec = React.useMemo(() => ({ type: "kanban" as const, ext: kanbanType(), title, heading, legend, columns, cards, labels }), [title, heading, legend, columns, cards, labels]); + return ; +} diff --git a/packages/react/src/service-blueprint-diagram.tsx b/packages/react/src/service-blueprint-diagram.tsx new file mode 100644 index 00000000..8205b0aa --- /dev/null +++ b/packages/react/src/service-blueprint-diagram.tsx @@ -0,0 +1,31 @@ +import * as React from "react"; + +import { DiagramFigure } from "./diagram-figure"; +import type { DiagramFigureProps } from "./diagram-figure"; +import { serviceBlueprintType } from "./diagram-matrix"; +import type { BlueprintArrow, BlueprintCell, BlueprintLabels, BlueprintLayer, BlueprintRuleLabels, BlueprintStage } from "./diagram-matrix"; + +export type { BlueprintArrow, BlueprintCell, BlueprintLabels, BlueprintLayer, BlueprintRuleLabels, BlueprintStage } from "./diagram-matrix"; +export type { DiagramAction, DiagramActionContext, DiagramFigureProps, DiagramLayoutInfo } from "./diagram-figure"; + +export interface ServiceBlueprintDiagramProps extends DiagramFigureProps { + /** The stages, left to right. `time` is the author's ("0–2 s"). */ + stages: BlueprintStage[]; + /** A cell a stage and layer. Customer, frontstage and backstage are always drawn; evidence and support where a cell names them. A cell left out says "None". */ + cells: BlueprintCell[]; + /** Optional, main or plain: two cells of one stage, or neighbouring stages of one layer. */ + arrows?: BlueprintArrow[]; + layerLabels?: Partial>; + ruleLabels?: BlueprintRuleLabels; + /** The built-in words, for an app that writes another language. */ + labels?: BlueprintLabels; +} + +/** + * A service blueprint (DECISIONS 359): stages across, layers down, and three rules in fixed gaps, each named on the rule. An empty cell is the word "None" + * with no box. Stacked, all three rules are inside every stage. The implementation has not been reviewed. + */ +export function ServiceBlueprintDiagram({ stages, cells, arrows, layerLabels, ruleLabels, labels, motion: _motion, entrance: _entrance, title, heading, legend, ...props }: ServiceBlueprintDiagramProps) { + const spec = React.useMemo(() => ({ type: "service-blueprint" as const, ext: serviceBlueprintType(), title, heading, legend, stages, cells, arrows, layerLabels, ruleLabels, labels }), [title, heading, legend, stages, cells, arrows, layerLabels, ruleLabels, labels]); + return ; +} diff --git a/packages/react/src/story-map-diagram.tsx b/packages/react/src/story-map-diagram.tsx new file mode 100644 index 00000000..4148ab41 --- /dev/null +++ b/packages/react/src/story-map-diagram.tsx @@ -0,0 +1,33 @@ +import * as React from "react"; + +import { DiagramFigure } from "./diagram-figure"; +import type { DiagramFigureProps } from "./diagram-figure"; +import { storyMapType } from "./diagram-matrix"; +import type { StoryActivity, StoryCard, StoryCut, StoryMapLabels, StorySlice } from "./diagram-matrix"; + +export type { StoryActivity, StoryCard, StoryCut, StoryMapLabels, StorySlice } from "./diagram-matrix"; +export type { DiagramAction, DiagramActionContext, DiagramFigureProps, DiagramLayoutInfo } from "./diagram-figure"; + +export interface StoryMapDiagramProps extends DiagramFigureProps { + /** Who the map is for, under the source. */ + persona?: string; + /** The backbone, in the order the story is told, each with its steps. */ + activities: StoryActivity[]; + /** The slices, from the first to ship. */ + slices: StorySlice[]; + /** The stories, each under an activity in a slice. */ + stories: StoryCard[]; + /** The one release cut: a 2px rule after the slice it names, with its words (required where it is drawn). */ + cut?: StoryCut; + /** The built-in words, for an app that writes another language. */ + labels?: StoryMapLabels; +} + +/** + * A story map (DECISIONS 359): a backbone of activities (a contour, never inverted) with their steps, slices down, and one release cut. An activity with no + * story in a slice has an empty slot, "No stories". The implementation has not been reviewed. + */ +export function StoryMapDiagram({ persona, activities, slices, stories, cut, labels, motion: _motion, entrance: _entrance, title, heading, legend, ...props }: StoryMapDiagramProps) { + const spec = React.useMemo(() => ({ type: "story-map" as const, ext: storyMapType(), title, heading, legend, persona, activities, slices, stories, cut, labels }), [title, heading, legend, persona, activities, slices, stories, cut, labels]); + return ; +} From bd8139fb50d61d5867bca38cfb2d2d0411b31c16 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:06 -0600 Subject: [PATCH 05/12] Diagrams: the gantt (DECISIONS 359, Planning 1.1) Square bars 16 tall that are never widened, a milestone's diamond, tick lines and the dashed today line, no dependency line (a row writes After), and the three forms by the bar floor: drawn, stacked with tracks, stacked in words; the 512 bound. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Gemini Neon --- packages/react/src/diagram-gantt.ts | 382 +++++++++++++++++++++++++++ packages/react/src/gantt-diagram.tsx | 33 +++ 2 files changed, 415 insertions(+) create mode 100644 packages/react/src/diagram-gantt.ts create mode 100644 packages/react/src/gantt-diagram.tsx diff --git a/packages/react/src/diagram-gantt.ts b/packages/react/src/diagram-gantt.ts new file mode 100644 index 00000000..899b2165 --- /dev/null +++ b/packages/react/src/diagram-gantt.ts @@ -0,0 +1,382 @@ +// A gantt (DECISIONS 359, Planning 1.1): a row a task on one time scale. Square bars 16 tall whose ends are their dates and are never widened; a milestone a +// diamond on its day; tick lines and a dashed today line; no dependency line (a row writes what it comes after). Three forms by a measured floor: drawn, +// stacked with tracks, stacked in words. The scale is diagram-scale's; everything drawn on it is this module's. GanttDiagram hands it to the engine on the +// spec, so an app that draws an architecture bundles none of it. Nothing runs at load. The implementation has not been reviewed. + +import { h, iso, own, rectOf, sentence, svgA, txt } from "./diagram-core"; +import type { DiagramSpec, DiagramTypeExt, Dyn, ExtBuildKit, ExtBuilt, ExtMeasureKit, Geo, Measured, MNode, Model, VElement, VNode } from "./diagram-core"; +import { dateWords, datesWords, dayLadder, dayNumber, numberLadder, scaleMap, ticks, yearOf } from "./diagram-scale"; +import type { ScaleTick } from "./diagram-scale"; + +// ---- Public shapes ---- + +export interface GanttPhase { id: string; label: string } +export interface GanttTask { + id: string; + name: string; + /** A day (`YYYY-MM-DD`) or a number in the figure's `unit`. */ + start: string | number; + /** The last day (inclusive) or the end value. A milestone has none. */ + end?: string | number; + phase?: string; + detail?: string; + detailMono?: boolean; + /** What it comes after, by id: written in the row as "After: …". No line is drawn (DECISIONS 359, 1.1). */ + after?: string[]; + /** A milestone: a diamond on its day, with a `start` and no `end`. */ + milestone?: boolean; + /** The one focal task. */ + focal?: boolean; + href?: string; + target?: "_blank"; +} +/** A numeric scale's unit: one word for both, or the singular and the plural ("week", "weeks"). */ +export type GanttUnit = string | { one: string; other: string }; +/** The built-in words a gantt draws, each replaceable. */ +export interface GanttLabels { task?: string; milestone?: string; after?: string; bar?: string; day?: GanttUnit } + +// ---- The model ---- + +interface GTask { + id: string; i: number; name: string; phase?: string; detail?: string; mono: boolean; + /** Its place on the scale: a span's start and end, a milestone's point (a = b). */ + a: number; b: number; + milestone: boolean; focal: boolean; after: string[]; range: string; length: string; href?: string; blank?: boolean; +} +export interface GanttPlan { + days: boolean; + tasks: GTask[]; + phases: GanttPhase[]; + domain: [number, number]; + /** The shortest bar's length on the scale; Infinity with none. */ + shortest: number; + today?: number; + todayWords?: string; + todayLabel: string; + words: { task: string; milestone: string; after: string; bar: string }; + /** The figure spans more than one year: a range writes its year. */ + years: boolean; +} + +const plural = (u: GanttUnit, n: number) => (typeof u === "string" ? u : n === 1 ? u.one : u.other); +const r2 = (n: number) => Math.round(n * 100) / 100; +/** The name of a task an "After" names. */ +const nameOf = (p: GanttPlan, id: string) => p.tasks.find((t) => t.id === id)?.name ?? id; + +function build(spec: DiagramSpec, kit: ExtBuildKit): ExtBuilt { + const { dev, warn, error } = kit; + const labels = (spec.labels ?? {}) as GanttLabels; + const words = { task: txt(labels.task) ?? "Task", milestone: txt(labels.milestone) ?? "Milestone", after: txt(labels.after) ?? "After", bar: txt(labels.bar) ?? "Task, from its start to its end" }; + const raw = (Array.isArray(spec.tasks) ? spec.tasks : []) as GanttTask[]; + const phases = (Array.isArray(spec.phases) ? spec.phases : []).map((p) => ({ id: String((p as GanttPhase).id ?? ""), label: String((p as GanttPhase).label ?? "") })); + const days = raw.length > 0 && dayNumber(raw[0]!.start) !== null; + const unitIn = spec.unit as GanttUnit | undefined; + const unit: GanttUnit = days ? (labels.day ?? { one: "day", other: "days" }) : unitIn && (typeof unitIn === "string" || (typeof unitIn === "object" && unitIn.one && unitIn.other)) ? unitIn : ""; + if (dev && !days && raw.length && !unitIn) warn("a numeric gantt has no unit: its lengths are written as bare numbers"); + const read = (v: unknown, who: string): number => { + if (days) { const d = dayNumber(v); if (d === null) { dev && error(`${who}: ${JSON.stringify(v)} is not a day (YYYY-MM-DD), as the first task's start is`); return 0; } return d; } + const n = typeof v === "number" ? v : Number.NaN; + if (!Number.isFinite(n)) { dev && error(`${who}: ${JSON.stringify(v)} is not a number, as the first task's start is`); return 0; } + return n; + }; + const parsed = raw.map((t, i) => { + const id = String(t.id ?? ""); + const milestone = Boolean(t.milestone); + const s = read(t.start, `the start of ${id}`); + if (milestone && t.end !== undefined && t.end !== null) dev && error(`${id} is a milestone with an end: a milestone has a start alone`); + const e = milestone ? s : t.end === undefined || t.end === null ? (dev && error(`${id} has no end: a task has a start and an end, a milestone a start alone`), s) : read(t.end, `the end of ${id}`); + if (e < s) dev && error(`${id} ends before it starts`); + const last = Math.max(s, e); + // A day is an interval (1.0): a span from the start of its first day to the end of its last; a point at its day's middle. + const a = days ? (milestone ? s + 0.5 : s) : s; + const b = days ? (milestone ? s + 0.5 : last + 1) : milestone ? s : last; + return { t, id, i, milestone, s, last, a, b }; + }); + if (dev && parsed.filter((p) => p.t.focal).length > 1) warn("more than one task is focal: a gantt has one at most"); + // The domain is exact (the answers' section 3): the least start to the greatest end, a milestone's day included. Never rounded. + const lo = parsed.length ? Math.min(...parsed.map((p) => (days ? p.s : p.a))) : 0; + const hi = parsed.length ? Math.max(...parsed.map((p) => (days ? p.last + 1 : p.b))) : 1; + const domain: [number, number] = [lo, hi > lo ? hi : lo + 1]; + const years = days && yearOf(domain[0]) !== yearOf(domain[1] - 1); + const fmt = (d: number) => dateWords(d, years); + const range = (p: (typeof parsed)[number]) => { + if (!days) return p.milestone ? `${p.s} · ${words.milestone}` : `${p.s} – ${p.last}`; + if (p.milestone) return `${fmt(p.s)} · ${words.milestone}`; + if (p.s === p.last) return fmt(p.s); + // "Nov 2 – 9" inside one month, "Nov 28 – Dec 3" across two (with the year only where the figure spans more than one). + const sameMonth = new Date(p.s * 86_400_000).getUTCMonth() === new Date(p.last * 86_400_000).getUTCMonth() && yearOf(p.s) === yearOf(p.last); + return sameMonth && !years ? `${fmt(p.s)} – ${new Date(p.last * 86_400_000).getUTCDate()}` : `${fmt(p.s)} – ${fmt(p.last)}`; + }; + const length = (p: (typeof parsed)[number]) => { + if (p.milestone) return ""; + const n = days ? p.last - p.s + 1 : r2(p.last - p.s); + return `${n} ${plural(unit, n)}`.trim(); + }; + const tasks: GTask[] = parsed.map((p) => ({ + id: p.id, i: p.i, name: String(p.t.name ?? ""), phase: txt(p.t.phase), detail: txt(p.t.detail), mono: Boolean(p.t.detailMono), + a: p.a, b: p.b, milestone: p.milestone, focal: Boolean(p.t.focal), after: Array.isArray(p.t.after) ? p.t.after.map(String) : [], range: range(p), length: length(p), + href: txt(p.t.href), blank: p.t.target === "_blank", + })); + // Development checks: an "after" that names no task, and a task that starts before a task it comes after has ended. + if (dev) for (const t of tasks) for (const id of t.after) { + const before = tasks.find((x) => x.id === id); + if (!before) warn(`${t.id} comes after "${id}", which is not a task`); + else if (t.a < before.b) warn(`${t.id} starts before ${id}, which it comes after, has ended`); + } + for (const t of tasks) if (t.phase && !phases.some((ph) => ph.id === t.phase)) dev && warn(`${t.id} names the phase "${t.phase}", which is not in phases`); + const bars = tasks.filter((t) => !t.milestone).map((t) => t.b - t.a); + const shortest = bars.length ? Math.min(...bars) : Infinity; + const todayRaw = spec.today; + const todayAt = todayRaw === undefined || todayRaw === null ? undefined : days ? (dayNumber(todayRaw) ?? undefined) : typeof todayRaw === "number" ? todayRaw : undefined; + const todayPoint = todayAt === undefined ? undefined : days ? todayAt + 0.5 : todayAt; + // A today outside the domain is not drawn and not in the key. + const today = todayPoint !== undefined && todayPoint >= domain[0] && todayPoint <= domain[1] ? todayPoint : undefined; + const todayLabel = txt(spec.todayLabel) ?? "Today"; + const plan: GanttPlan = { + days, tasks, phases, domain, shortest, today, todayLabel, words, years, + todayWords: today === undefined ? undefined : days ? dateWords(Math.floor(today), years) : String(today), + }; + if (dev && domain[1] - domain[0] > 512 * shortest) warn(`the plan is more than 512 times its shortest bar, so the gantt is never drawn (only stacked): make the short task a milestone or split the chart`); + // A row is a stop (1.1): the task's order, phase by phase. + const order = orderOf(plan); + const nodes: MNode[] = order.map((t, k) => ({ id: t.id, i: k, name: t.name, mono: false, focal: t.focal, col: 1, row: k + 1, row2: k + 1, branch: false, shape: "box", href: t.href, blank: t.blank })); + return { nodes, edges: [], plan, cols: 1, rows: Math.max(1, nodes.length) }; +} + +/** The rows in their order: under their phases (in the phases' order), then the tasks with none. */ +function orderOf(p: GanttPlan): GTask[] { + if (!p.phases.length) return p.tasks; + return [...p.phases.flatMap((ph) => p.tasks.filter((t) => t.phase === ph.id)), ...p.tasks.filter((t) => !t.phase || !p.phases.some((ph) => ph.id === t.phase))]; +} +const planOf = (m: Model) => m.plan as GanttPlan; +const taskOf = (m: Model, id: string) => planOf(m).tasks.find((t) => t.id === id)!; + +// ---- Words ---- + +function rangeSentence(p: GanttPlan, t: GTask): string { + return t.milestone ? `${t.range.replace(` · ${p.words.milestone}`, "")}, ${p.words.milestone.toLowerCase()}` : `${t.range.replace(" – ", " to ")}, ${t.length}`; +} +function writeSentence(m: Model, n: MNode): string { + const p = planOf(m), t = taskOf(m, n.id); + const ph = t.phase ? p.phases.find((x) => x.id === t.phase)?.label : undefined; + const parts = [`${t.name}${ph ? `, ${ph}` : ""}: ${rangeSentence(p, t)}.`]; + if (t.detail) parts.push(sentence(t.detail)); + if (t.after.length) parts.push(`${p.words.after} ${t.after.map((id) => nameOf(p, id)).join(", ")}.`); + if (t.focal && m.legend.focal) parts.push(sentence(m.legend.focal)); + return parts.join(" "); +} + +function key(P: string, m: Model): VElement | null { + const p = planOf(m); + const entries: VElement[] = []; + const entry = (swatch: VElement, words: string, attrs = {}) => entries.push(h("li", { class: `${P}-entry`, ...attrs }, swatch, h("span", null, iso(words)))); + // The bar, the milestone and today are notation (built in); the stack in words draws none, so their entries are the tracks' only. + if (p.tasks.some((t) => !t.milestone)) entry(h("svg", { class: `${P}-swatch`, ...svgA(24, 16) }, h("rect", { class: `${P}-swatch-bar`, x: 0.5, y: 4.5, width: 23, height: 7 })), p.words.bar, { "data-when": "tracks" }); + if (p.tasks.some((t) => t.milestone)) entry(h("svg", { class: `${P}-swatch`, ...svgA(16, 16) }, h("path", { class: `${P}-swatch-bar`, d: "M8 1.5L14.5 8L8 14.5L1.5 8Z" })), p.words.milestone, { "data-when": "tracks" }); + if (p.today !== undefined) entry(h("svg", { class: `${P}-swatch`, ...svgA(16, 16) }, h("path", { class: `${P}-today`, d: "M8.5 0V16" })), `${p.todayLabel}, ${p.todayWords}`, { "data-when": "tracks" }); + if (p.tasks.some((t) => t.focal) && m.legend.focal) entry(h("svg", { class: `${P}-swatch`, ...svgA(24, 16) }, h("rect", { class: `${P}-swatch-bar`, "data-focal": "", x: 0.5, y: 4.5, width: 23, height: 7 })), m.legend.focal, { "data-focal": "" }); + if (!entries.length) return null; + return h("div", { class: `${P}-key` }, h("ul", { class: `${P}-legend`, "aria-label": "Key" }, entries)); +} + +function list(P: string, m: Model): VNode[] { + const p = planOf(m); + const sub = Math.min(6, m.heading + 1); + const item = (t: GTask) => h("li", null, h("strong", null, iso(t.name)), `: ${rangeSentence(p, t)}.`, t.detail ? [" ", t.mono ? h("code", { class: `${P}-code` }, t.detail) : sentence(t.detail)] : "", + t.after.length ? ` ${p.words.after} ${t.after.map((id) => nameOf(p, id)).join(", ")}.` : "", t.focal && m.legend.focal ? ` ${sentence(m.legend.focal)}` : ""); + if (!p.phases.length) return [h("ol", { class: `${P}-list-items` }, p.tasks.map(item))]; + const out: VNode[] = []; + for (const ph of p.phases) { + const mine = p.tasks.filter((t) => t.phase === ph.id); + if (mine.length) out.push(h(`h${sub}`, { class: `${P}-list-head` }, iso(ph.label)), h("ol", { class: `${P}-list-items` }, mine.map(item))); + } + const rest = p.tasks.filter((t) => !t.phase || !p.phases.some((ph) => ph.id === t.phase)); + if (rest.length) out.push(h("ol", { class: `${P}-list-items` }, rest.map(item))); + return out; +} + +// ---- The drawing: one DOM for every form ---- + +/** Where a value is, as a fraction of the domain: the bars' places are percentages of the track, so they are exact at every width. */ +const frac = (p: GanttPlan, v: number) => (v - p.domain[0]) / (p.domain[1] - p.domain[0]); + +function drawing(P: string, m: Model, dyn: Dyn, level?: number): VNode[] { + const p = planOf(m); + const out: VNode[] = []; + const hasToday = p.today !== undefined; + // The axis row: its corner word, and room for the tick labels (and the today label above them); the ink draws the words in it. + out.push(h("div", { class: `${P}-gantt-axis`, "data-today": hasToday ? "" : undefined, "aria-hidden": "true" }, + h("span", { class: `${P}-gantt-corner` }, iso(p.words.task)), + h("span", { class: `${P}-gantt-scale` }))); + const rows = orderOf(p); + let phase: string | undefined = "\u0000"; + for (const t of rows) { + const ph = t.phase && p.phases.some((x) => x.id === t.phase) ? t.phase : undefined; + if (ph !== phase && ph) out.push(h("p", { class: `${P}-gantt-phase`, "aria-hidden": "true" }, iso(p.phases.find((x) => x.id === ph)!.label))); + phase = ph; + const n = m.byId.get(t.id)!; + const stops = Boolean(dyn.layout && !dyn.bare); + const s = r2(frac(p, t.a) * 100), w = r2(frac(p, t.b) * 100 - frac(p, t.a) * 100); + // A row whose range holds today ends its range line with today's label, in the stack in words (the CSS shows it there only). + const holdsToday = hasToday && p.today! >= t.a && p.today! <= t.b; + out.push(h(t.href ? "a" : "div", { + class: `${P}-node ${P}-gantt-row`, + href: t.href, target: t.href && t.blank ? "_blank" : undefined, rel: t.href && t.blank ? "noopener noreferrer" : undefined, "data-link": t.href ? (t.blank ? "external" : "") : undefined, + "data-node": t.id, "data-focal": t.focal ? "" : undefined, "data-level": level, + role: t.href ? undefined : "img", "aria-label": writeSentence(m, n), + tabindex: stops ? (dyn.stop === t.id ? 0 : -1) : dyn.keep === t.id ? -1 : undefined, + }, + h("span", { class: `${P}-gantt-words` }, + h("span", { class: `${P}-name` }, iso(t.name)), + h("span", { class: `${P}-gantt-range` }, iso(t.length ? `${t.range} · ${t.length}` : t.range), holdsToday ? h("span", { class: `${P}-gantt-now` }, ` · ${p.todayLabel}`) : null), + t.detail ? h("span", { class: `${P}-detail`, "data-mono": t.mono ? "" : undefined }, iso(t.detail)) : null, + t.after.length ? h("span", { class: `${P}-gantt-after` }, iso(`${p.words.after}: ${t.after.map((id) => nameOf(p, id)).join(", ")}`)) : null), + h("span", { class: `${P}-gantt-track`, "aria-hidden": "true" }, + h("span", { class: `${P}-gantt-scale` }, + t.milestone + ? h("span", { class: `${P}-gantt-mile`, "data-focal": t.focal ? "" : undefined, style: `--_s:${s}%` }, h("svg", { ...svgA(16, 16) }, h("path", { d: "M8 0.5L15.5 8L8 15.5L0.5 8Z" }))) + : h("span", { class: `${P}-gantt-bar`, "data-focal": t.focal ? "" : undefined, style: `--_s:${s}%;--_w:${w}%` }))))); + } + return out; +} + +// ---- Measuring (script only) ---- + +/** The name column: `size-diagram-table`, or the widest unbreakable line if that is wider (1.1). */ +function nameColumn(m: Model, tk: ExtMeasureKit["tk"], measure: ExtMeasureKit["measure"]): number { + const p = planOf(m); + let widest = tk.table; + for (const t of p.tasks) { + for (const w of t.name.split(/\s+/)) widest = Math.max(widest, Math.ceil(measure(w, "name"))); + for (const w of `${t.range} · ${t.length}`.split(/\s+/)) widest = Math.max(widest, Math.ceil(measure(w, "tab"))); + for (const w of (t.detail ?? "").split(/\s+/)) if (w) widest = Math.max(widest, Math.ceil(measure(w, t.mono ? "mono" : "sans"))); + } + return widest; +} +/** The track's scale less its two insets, drawn: the figure less the name column and 32 (space-4 and the two insets). */ +const drawnScale = (W: number, name: number, s: (k: string) => number) => W - name - s("4") - 2 * s("2"); +/** The scale the bars stand on: the shortest bar at least space-2, never widened. */ +const floorHolds = (p: GanttPlan, length: number, floor: number) => !Number.isFinite(p.shortest) || (p.shortest / (p.domain[1] - p.domain[0])) * length >= floor - 1e-6; + +function least(m: Model, tk: ExtMeasureKit["tk"], measure: ExtMeasureKit["measure"]): number { + const p = planOf(m); + const name = nameColumn(m, tk, measure); + const s = tk.space; + const span = p.domain[1] - p.domain[0]; + const need = Number.isFinite(p.shortest) ? (s("2") * span) / p.shortest : 0; + return Math.max(tk.wide, Math.ceil(name + s("4") + 2 * s("2") + need)); +} + +function tickRow(p: GanttPlan, length: number): ScaleTick[] { + const map = scaleMap({ domain: p.domain, length }); + const span = p.domain[1] - p.domain[0]; + const found = ticks(map, p.days ? dayLadder() : numberLadder(span / Math.max(1, length), span), 56); + // Where fewer than two round ticks fall in the domain, its two ends are the ticks (the gantt's own; the module never adds them). + if (found.length >= 2) return found; + return [{ value: p.domain[0], place: 0, step: "end" }, { value: p.domain[1], place: length, step: "end" }]; +} +function tickWords(p: GanttPlan, list: ScaleTick[]): string[] { + // A day's tick at a domain's end is the end of the last day: its label names the day it closes. + if (p.days) return datesWords(list.map((t) => (t.step === "end" && t.value === p.domain[1] ? t.value - 1 : t.value))); + return list.map((t) => String(r2(t.value))); +} + +const esc = (s: string) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]!); + +function layout(m: Model, kit: ExtMeasureKit): Measured { + const { drawing: el, P, tk, W, apply, stopOf, current, measure } = kit; + const p = planOf(m); + const s = tk.space; + const name = nameColumn(m, tk, measure); + const span = p.domain[1] - p.domain[0]; + const bound = Number.isFinite(p.shortest) && span > 512 * p.shortest; + const drawn = !bound && W >= Math.max(tk.wide, least(m, tk, measure)) && floorHolds(p, drawnScale(W, name, s), s("2")); + const stackW = Math.min(tk.cap, W); + const tracks = !drawn && floorHolds(p, stackW - 2 * s("2"), s("2")); + const dyn = stopOf({ ...current, layout: drawn ? "drawn" : "stacked", form: drawn ? undefined : tracks ? "tracks" : "words", place: drawn ? { "": `--_name:${name}px` } : undefined, bare: undefined }); + apply(dyn); + const ink = tracks || drawn ? inkOf(el, m, P, tk, drawn, measure) : { geo: emptyGeo(el), ink: "" }; + return { dyn, geo: ink.geo, ink: ink.ink, tokens: tk, least: least(m, tk, measure) }; +} + +const emptyGeo = (el: HTMLElement): Geo => ({ w: el.clientWidth, h: el.clientHeight, nodes: [], lines: [], lifelines: [], labels: [], crossings: [], through: [], unseated: [], outside: [], ox: 0, oy: 0 }); + +function inkOf(el: HTMLElement, m: Model, P: string, tk: ExtMeasureKit["tk"], drawn: boolean, measure: ExtMeasureKit["measure"]): { geo: Geo; ink: string } { + const p = planOf(m); + const s = tk.space; + const origin = el.getBoundingClientRect(); + const ox = origin.left - Math.floor(origin.left), oy = origin.top - Math.floor(origin.top); + const half = (v: number, o: number) => Math.round(v + o - 0.5) + 0.5 - o; + const geo = emptyGeo(el); + const rtl = Boolean(m.rtl); + const scales = [...el.querySelectorAll(`.${P}-gantt-track > .${P}-gantt-scale`)]; + const axis = el.querySelector(`.${P}-gantt-axis > .${P}-gantt-scale`); + if (!scales.length || !axis) return { geo, ink: "" }; + const first = rectOf(scales[0]!, origin); + const length = first.r - first.l; + const xOf = (v: number, r: { l: number; r: number }) => (rtl ? r.r - frac(p, v) * (r.r - r.l) : r.l + frac(p, v) * (r.r - r.l)); + const list = tickRow(p, length); + const said = tickWords(p, list); + let out = ""; + // Tick lines: 1px chart-grid at each tick, the full height of every task row, stopping at a phase head; stacked, inside each track (never across words). + const rowsOf = drawn ? [...el.querySelectorAll(`.${P}-gantt-row`)].map((r) => rectOf(r, origin)) : [...el.querySelectorAll(`.${P}-gantt-track`)].map((r) => rectOf(r, origin)); + // Runs of rows with no phase head between them, so a line stops at a head. + const runs: Array<{ t: number; b: number }> = []; + for (const r of rowsOf) { const last = runs[runs.length - 1]; if (last && Math.abs(r.t - last.b) < 1.5) last.b = r.b; else runs.push({ t: r.t, b: r.b }); } + const vline = (x: number, cls: string) => runs.map((r) => ``).join(""); + for (const t of list) out += vline(half(xOf(t.value, first), ox), "gantt-grid"); + if (p.today !== undefined) out += vline(half(xOf(p.today, first), ox), "today"); + // The tick labels, in the axis row: each starts space-1 after its line, and is dropped whole where it would pass the track's end. + const ar = rectOf(axis, origin); + const lineH = 16; + const tickY = ar.b - s("2") - lineH / 2; + let words = ""; + list.forEach((t, k) => { + const x = xOf(t.value, { l: ar.l, r: ar.r }); + const wd = measure(said[k]!, "tab"); + const start = rtl ? x - s("1") - wd : x + s("1"); + if (start < ar.l - 0.5 || start + wd > ar.r + 0.5) return; + words += `${esc(said[k]!)}`; + }); + if (p.today !== undefined) { + // The today label (500, secondary) centred over its line and held inside the track, on the line above the ticks. + const x = xOf(p.today, { l: ar.l, r: ar.r }); + const wd = measure(p.todayLabel, "xs-500"); + const at = Math.max(ar.l + wd / 2, Math.min(ar.r - wd / 2, x)); + words += `${esc(p.todayLabel)}`; + } + return { geo, ink: `${out}${words}` }; +} + +// ---- Keys ---- + +function keyTarget(m: Model, from: string, key: string): string | null { + const i = m.byId.get(from)?.i ?? 0; + const n = m.nodes.length; + const to = key === "ArrowDown" ? i + 1 : key === "ArrowUp" ? i - 1 : key === "Home" ? 0 : key === "End" ? n - 1 : null; + return to === null ? null : m.nodes[Math.max(0, Math.min(n - 1, to))]?.id ?? null; +} + +let made: DiagramTypeExt | undefined; +/** The gantt's module, made at its first use. */ +export function ganttType(): DiagramTypeExt { + return (made ??= { + type: "gantt", + build, + stop: "a task", + sentence: writeSentence, + key, + list, + drawing, + least, + layout, + keyTarget, + hasStops: (_m, dyn) => Boolean(dyn.layout && !dyn.bare), + traces: () => false, + hint: (m) => [{ keys: ["↑", "↓"], words: "a task" }, { keys: ["Home", "End"], words: "the ends" }, ...(m.nodes.some((n) => n.href) ? [{ keys: ["Enter"], words: "open" }] : [])], + keys: (m) => `Up and down arrows move to the next or the previous task; Home and End go to the ends.${m.nodes.some((n) => n.href) ? " Enter opens a task that is a link." : ""}`, + rootStyle: (_m, dyn) => { const v = own(dyn.place, ""); return v ? [v] : []; }, + // Before script (1.1): stacked, with tracks only if the shortest bar is at least 1/34 of the domain (8px in the 272px track of a 320px window). + form: (m) => { const p = planOf(m); return !Number.isFinite(p.shortest) || p.shortest * 34 >= p.domain[1] - p.domain[0] ? "tracks" : "words"; }, + }); +} diff --git a/packages/react/src/gantt-diagram.tsx b/packages/react/src/gantt-diagram.tsx new file mode 100644 index 00000000..fc74e844 --- /dev/null +++ b/packages/react/src/gantt-diagram.tsx @@ -0,0 +1,33 @@ +import * as React from "react"; + +import { DiagramFigure } from "./diagram-figure"; +import type { DiagramFigureProps } from "./diagram-figure"; +import { ganttType } from "./diagram-gantt"; +import type { GanttLabels, GanttPhase, GanttTask, GanttUnit } from "./diagram-gantt"; + +export type { GanttLabels, GanttPhase, GanttTask, GanttUnit } from "./diagram-gantt"; +export type { DiagramAction, DiagramActionContext, DiagramFigureProps, DiagramLayoutInfo } from "./diagram-figure"; + +export interface GanttDiagramProps extends DiagramFigureProps { + /** The tasks, in the order their rows are drawn (under their phases). A task's `start` and `end` are days (`YYYY-MM-DD`, the end inclusive) or numbers. */ + tasks: GanttTask[]; + /** Phases, in order: a task's `phase` names one, and its rows sit under the phase's head. */ + phases?: GanttPhase[]; + /** A numeric scale's unit ("min", or `{ one: "week", other: "weeks" }`). Days need none. */ + unit?: GanttUnit; + /** Today: a day or a number. Drawn as the dashed today line only where it is inside the plan. */ + today?: string | number; + /** The today line's label (default "Today"). */ + todayLabel?: string; + /** The built-in words, for an app that writes another language. */ + labels?: GanttLabels; +} + +/** + * A gantt (DECISIONS 359): a row a task on one time scale. A bar's ends are its dates and it is never widened: where the shortest bar would be under 8px + * the bars go and the words stay. No dependency line is drawn; a row writes what it comes after. The implementation has not been reviewed. + */ +export function GanttDiagram({ tasks, phases, unit, today, todayLabel, labels, motion: _motion, entrance: _entrance, title, heading, legend, ...props }: GanttDiagramProps) { + const spec = React.useMemo(() => ({ type: "gantt" as const, ext: ganttType(), title, heading, legend, tasks, phases, unit, today, todayLabel, labels }), [title, heading, legend, tasks, phases, unit, today, todayLabel, labels]); + return ; +} From e837c54a81bacf12dcd2f6451bc23db464944b88 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:09 -0600 Subject: [PATCH 06/12] Diagrams: the schedule on the architecture router (DECISIONS 359, Planning 1.6) Its numbers computed in fixed point; a line main only where both tasks are critical and its finish sets the next start; the contour is the task's kind; the stack in the author's order, each card writing what it comes after and which sets its start. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Gemini Neon --- packages/react/src/diagram-schedule.ts | 224 ++++++++++++++++++++++++ packages/react/src/schedule-diagram.tsx | 33 ++++ 2 files changed, 257 insertions(+) create mode 100644 packages/react/src/diagram-schedule.ts create mode 100644 packages/react/src/schedule-diagram.tsx diff --git a/packages/react/src/diagram-schedule.ts b/packages/react/src/diagram-schedule.ts new file mode 100644 index 00000000..d0a77f08 --- /dev/null +++ b/packages/react/src/diagram-schedule.ts @@ -0,0 +1,224 @@ +// A schedule (DECISIONS 359, Planning 1.6): a network on the architecture router, placed as an architecture is (the author's columns and rows, or +// `layout: "auto"`). Its numbers are computed, never authored: finish to start, no lag, no calendar, one unit, in fixed point (integers scaled by 1e6) so +// 0.1 + 0.2 is exact. A line is main only where both its tasks are critical and its finish is the next task's start. ScheduleDiagram hands this module to +// the engine on the spec; the engine routes and stacks it. Nothing runs at load. The implementation has not been reviewed. + +import { h, iso, lineSwatch, sentence, svgA, txt } from "./diagram-core"; +import type { DiagramSpec, DiagramTypeExt, Dyn, ExtBuildKit, ExtBuilt, MEdge, MNode, Model, VChild, VElement, VNode } from "./diagram-core"; + +export interface ScheduleTask { + id: string; + name: string; + /** Its code ("T3"), Mono, on the card's kind line. */ + kind?: string; + /** A positive number in the figure's `unit`. */ + duration: number; + /** What it comes after, by id: finish to start, no lag. */ + after?: string[]; + /** Its tracks, as an architecture card's (left out under `layout: "auto"`). */ + col?: number; + row?: number; + /** The author's one focal task. Never derived, and never "critical". */ + focal?: boolean; + href?: string; + target?: "_blank"; +} +export type ScheduleUnit = string | { one: string; other: string }; +export interface ScheduleLabels { + finishes?: string; criticalPath?: { one: string; other: string }; assumptions?: string; critical?: string; float?: string; + keyMain?: string; keyPlain?: string; keyCritical?: string; keyFloat?: string; keyNumbers?: string; starts?: string; +} + +const SCALE = 1_000_000; +const toInt = (n: number) => Math.round(n * SCALE); +/** A fixed-point number as words: "1,271", "2.5". */ +function said(u: number): string { + const neg = u < 0 ? "-" : ""; + const abs = Math.abs(u); + const whole = Math.floor(abs / SCALE); + const frac = abs % SCALE; + const grouped = String(whole).replace(/\B(?=(\d{3})+(?!\d))/g, ","); + return frac ? `${neg}${grouped}.${String(frac).padStart(6, "0").replace(/0+$/, "")}` : `${neg}${grouped}`; +} + +interface STask { id: string; i: number; name: string; kind?: string; d: number; es: number; ef: number; ls: number; lf: number; float: number; critical: boolean; after: Array<{ id: string; sets: boolean }>; focal: boolean } +interface SchedulePlan { + tasks: STask[]; + unit: ScheduleUnit; + finish: number; + paths: number; + /** A cycle, an unknown id or a duration that is no positive finite number: the bare stack (names, durations and "After"; no numbers, no lines). */ + bad: boolean; + words: Required; +} +const splan = (m: Model) => m.plan as SchedulePlan; +const unitWord = (p: SchedulePlan, u: number) => (typeof p.unit === "string" ? p.unit : u === SCALE ? p.unit.one : p.unit.other); +const length = (p: SchedulePlan, u: number) => `${said(u)} ${unitWord(p, u)}`; + +function build(spec: DiagramSpec, kit: ExtBuildKit): ExtBuilt { + const { dev, error, warn } = kit; + const given = (spec.labels ?? {}) as ScheduleLabels; + const words: Required = { + finishes: given.finishes ?? "Finishes at", criticalPath: given.criticalPath ?? { one: "critical path", other: "critical paths" }, + assumptions: given.assumptions ?? "Finish to start, no lag, no calendar. A box's width is not its length.", critical: given.critical ?? "Critical", float: given.float ?? "Float", + keyMain: given.keyMain ?? "This finish sets that start, on a critical path", keyPlain: given.keyPlain ?? "Comes before, with time to spare", + keyCritical: given.keyCritical ?? "Critical task", keyFloat: given.keyFloat ?? "Task with float", keyNumbers: given.keyNumbers ?? "ES, EF: earliest start and finish · LS, LF: latest start and finish", + starts: given.starts ?? "Starts the schedule.", + }; + const unitIn = spec.unit as ScheduleUnit | undefined; + if (dev && !unitIn) error("a schedule needs its unit: one unit for every duration"); + const unit: ScheduleUnit = unitIn ?? ""; + if (dev && Array.isArray(spec.edges) && spec.edges.length) error("a schedule's lines are its tasks' `after`: write no `edges` (a side is derived)"); + const raw = (Array.isArray(spec.tasks) ? spec.tasks : []) as ScheduleTask[]; + const ids = new Set(); + let bad = false; + for (const t of raw) { const id = String(t.id ?? ""); if (!id || ids.has(id)) { bad = true; dev && warn(id ? `the id "${id}" is used twice` : "a task has no id"); } ids.add(id); } + const dur = new Map(); + for (const t of raw) { + const d = typeof t.duration === "number" ? t.duration : Number.NaN; + if (!Number.isFinite(d) || d <= 0) { bad = true; dev && error(`${String(t.id)}'s duration is ${JSON.stringify(t.duration)}: it is a positive number`); dur.set(String(t.id), SCALE); } + else dur.set(String(t.id), toInt(d)); + } + const preds = new Map(raw.map((t) => [String(t.id), []])); + const succs = new Map(raw.map((t) => [String(t.id), []])); + const pairs: Array<[string, string]> = []; + for (const t of raw) for (const a of Array.isArray(t.after) ? t.after.map(String) : []) { + if (!ids.has(a)) { bad = true; dev && error(`${String(t.id)} comes after "${a}", which is not a task`); continue; } + if (preds.get(String(t.id))!.includes(a)) continue; + preds.get(String(t.id))!.push(a); succs.get(a)!.push(String(t.id)); pairs.push([a, String(t.id)]); + } + // The forward pass in an order that puts every task after those it comes after; a task left out is in a cycle. + const indeg = new Map(raw.map((t) => [String(t.id), preds.get(String(t.id))!.length])); + const queue = raw.map((t) => String(t.id)).filter((id) => indeg.get(id) === 0); + const topo: string[] = []; + while (queue.length) { const u = queue.shift()!; topo.push(u); for (const v of succs.get(u)!) { indeg.set(v, indeg.get(v)! - 1); if (indeg.get(v) === 0) queue.push(v); } } + if (topo.length < raw.length) { bad = true; dev && error(`the schedule has a cycle (${raw.map((t) => String(t.id)).filter((id) => !topo.includes(id)).join(", ")}): its passes cannot finish`); } + const es = new Map(), ef = new Map(), ls = new Map(), lf = new Map(); + for (const u of topo) { const s = Math.max(0, ...preds.get(u)!.map((p) => ef.get(p)!)); es.set(u, s); ef.set(u, s + dur.get(u)!); } + const finish = Math.max(0, ...topo.map((u) => ef.get(u)!)); + for (const u of [...topo].reverse()) { const f = Math.min(finish, ...succs.get(u)!.map((v) => ls.get(v)!)); lf.set(u, f); ls.set(u, f - dur.get(u)!); } + const critical = (u: string) => !bad && lf.get(u)! - ef.get(u)! === 0; + // A line is main only where both its tasks are critical and its finish is the next task's start (EF = ES). + const sets = (a: string, b: string) => !bad && ef.get(a) === es.get(b); + const main = (a: string, b: string) => critical(a) && critical(b) && sets(a, b); + // The critical paths: from a critical start, along main lines, to the finish. + const memo = new Map(); + const count = (u: string): number => { + if (memo.has(u)) return memo.get(u)!; + const next = succs.get(u)!.filter((v) => main(u, v)); + const n = next.length ? next.reduce((sum, v) => sum + count(v), 0) : ef.get(u) === finish ? 1 : 0; + memo.set(u, n); + return n; + }; + const paths = bad ? 0 : topo.filter((u) => critical(u) && !preds.get(u)!.length).reduce((sum, u) => sum + count(u), 0); + const tasks: STask[] = raw.map((t, i) => { + const id = String(t.id); + return { + id, i, name: String(t.name ?? ""), kind: txt(t.kind), d: dur.get(id)!, es: es.get(id) ?? 0, ef: ef.get(id) ?? 0, ls: ls.get(id) ?? 0, lf: lf.get(id) ?? 0, + float: bad ? 0 : (lf.get(id) ?? 0) - (ef.get(id) ?? 0), critical: critical(id), after: preds.get(id)!.map((a) => ({ id: a, sets: sets(a, id) })), focal: Boolean(t.focal), + }; + }); + const auto = spec.layout === "auto"; + const nodes: MNode[] = raw.map((t, i) => { + const col = typeof t.col === "number" && Number.isInteger(t.col) && t.col >= 1 ? t.col : (dev && !auto && error(`${String(t.id)}'s col is ${JSON.stringify(t.col)}, not a whole number from 1`), 1); + const row = typeof t.row === "number" && Number.isInteger(t.row) && t.row >= 1 ? t.row : (dev && !auto && error(`${String(t.id)}'s row is ${JSON.stringify(t.row)}, not a whole number from 1`), 1); + return { id: String(t.id), i, name: String(t.name ?? ""), kind: txt(t.kind), mono: false, focal: Boolean(t.focal), col, row, row2: row, branch: false, shape: "box", href: txt(t.href), blank: t.target === "_blank" }; + }); + if (dev && !auto) for (const [a, b] of pairs) { const na = nodes.find((n) => n.id === a)!, nb = nodes.find((n) => n.id === b)!; if (nb.col <= na.col) error(`${b} is not in a later column than ${a}, which it comes after`); } + if (dev) for (const [a, b] of pairs) if (raw.findIndex((t) => String(t.id) === b) < raw.findIndex((t) => String(t.id) === a)) warn(`${b} is listed before ${a}, which it comes after: the stack is in the author's order`); + if (dev && tasks.filter((t) => t.focal).length > 1) warn("more than one task is focal: a schedule has one at most"); + if (dev && kit.legend.focal && /\bcritical\b|zero float|float 0/i.test(kit.legend.focal)) warn("the focal task's words say what a critical task is: the focal task is the author's own, and its words must say something else"); + // In production a broken schedule is the bare stack: no lines. + const edges: MEdge[] = bad ? [] : pairs.map(([a, b], i) => ({ i, from: a, to: b, kind: main(a, b) ? "main" : "plain" })); + const plan: SchedulePlan = { tasks, unit, finish, paths, bad, words }; + return { nodes, edges, plan, cols: Math.max(1, ...nodes.map((n) => n.col)), rows: Math.max(1, ...nodes.map((n) => n.row)) }; +} +const stask = (m: Model, id: string) => splan(m).tasks.find((t) => t.id === id)!; +/** A task as the "After" words name it: by its kind line where every task has one, by its name otherwise. */ +const named = (p: SchedulePlan, id: string) => { const t = p.tasks.find((x) => x.id === id)!; return p.tasks.every((x) => x.kind) ? t.kind! : t.name; }; +const andList = (list: string[]) => (list.length < 2 ? list.join("") : `${list.slice(0, -1).join(", ")} and ${list[list.length - 1]}`); +/** "After T2, T3 and T4. T3 sets its start.", "After T1, which sets its start.", "After T5 and T6. Both set its start.", or "Starts the schedule." */ +function afterWords(p: SchedulePlan, t: STask): string { + if (!t.after.length) return p.words.starts; + const all = t.after.map((a) => named(p, a.id)); + if (p.bad) return `After ${andList(all)}.`; + const setters = t.after.filter((a) => a.sets).map((a) => named(p, a.id)); + if (t.after.length === 1) return setters.length ? `After ${all[0]}, which sets its start.` : `After ${all[0]}.`; + if (setters.length === t.after.length) return `After ${andList(all)}. ${setters.length === 2 ? "Both set" : "All set"} its start.`; + return `After ${andList(all)}. ${andList(setters)} ${setters.length === 1 ? "sets" : "set"} its start.`; +} + +function writeSentence(m: Model, n: MNode): string { + const p = splan(m), t = stask(m, n.id); + const parts = [sentence(t.kind ? `${t.name}, ${t.kind}` : t.name), `${length(p, t.d)}.`]; + if (!p.bad) { + parts.push(`Earliest start ${said(t.es)}, earliest finish ${said(t.ef)}, latest start ${said(t.ls)}, latest finish ${said(t.lf)}.`); + parts.push(t.critical ? `${p.words.float} 0, ${p.words.critical.toLowerCase()}.` : `${p.words.float} ${length(p, t.float)}.`); + } + parts.push(afterWords(p, t)); + if (t.focal && m.legend.focal) parts.push(sentence(m.legend.focal)); + return parts.join(" "); +} + +/** The card: its contour (its kind), its head, its numbers, its foot, and (stacked) what it comes after. */ +function card(P: string, m: Model, n: MNode): VChild[] { + const p = splan(m), t = stask(m, n.id); + const cell = (k: string, v: number) => h("span", { class: `${P}-sched-cell` }, h("span", { class: `${P}-sched-k` }, k), h("span", { class: `${P}-sched-v` }, said(v))); + return [ + h("span", { class: `${P}-sched-contour`, "data-critical": t.critical ? "" : undefined, "aria-hidden": "true" }), + h("span", { class: `${P}-sched-head` }, + h("span", { class: `${P}-kind` }, t.kind ? iso(t.kind) : null, h("span", { class: `${P}-sched-dur` }, length(p, t.d))), + h("span", { class: `${P}-name` }, iso(t.name))), + p.bad ? null : h("span", { class: `${P}-sched-grid` }, cell("ES", t.es), cell("EF", t.ef), cell("LS", t.ls), cell("LF", t.lf)), + p.bad ? null : h("span", { class: `${P}-sched-foot` }, h("span", null, t.critical ? `${p.words.float} 0` : `${p.words.float} ${length(p, t.float)}`), t.critical ? h("span", { class: `${P}-sched-critical` }, p.words.critical) : null), + h("span", { class: `${P}-sched-after` }, afterWords(p, t)), + ]; +} + +function meta(P: string, m: Model): VElement | null { + const p = splan(m); + if (p.bad) return null; + const paths = `${p.paths} ${p.paths === 1 ? p.words.criticalPath.one : p.words.criticalPath.other}`; + return h("p", { class: `${P}-meta` }, h("span", { class: `${P}-meta-first` }, `${p.words.finishes} ${length(p, p.finish)}`), ` · ${paths}. `, p.words.assumptions); +} + +function key(P: string, m: Model): VElement | null { + const p = splan(m); + const entry = (swatch: VElement, words: string, attrs = {}) => h("li", { class: `${P}-entry`, ...attrs }, swatch, h("span", null, iso(words))); + const box = (critical: boolean) => h("svg", { class: `${P}-swatch`, ...svgA(16, 16) }, h("rect", { class: `${P}-swatch-task`, "data-critical": critical ? "" : undefined, x: critical ? 1 : 0.5, y: critical ? 3 : 2.5, width: critical ? 14 : 15, height: critical ? 10 : 11, rx: 2 })); + const out: VElement[] = []; + if (m.edges.some((e) => e.kind === "main")) out.push(entry(lineSwatch(P, "main"), m.legend.main ?? p.words.keyMain, { "data-line": "", "data-when": "drawn" })); + if (m.edges.some((e) => e.kind === "plain")) out.push(entry(lineSwatch(P, "plain"), m.legend.plain ?? p.words.keyPlain, { "data-line": "", "data-when": "drawn" })); + if (p.tasks.some((t) => t.critical)) out.push(entry(box(true), p.words.keyCritical)); + if (p.tasks.some((t) => !t.critical)) out.push(entry(box(false), p.words.keyFloat)); + // The numbers' words are their own key: the letters are in the words, so the entry has no swatch of its own. + if (!p.bad) out.push(h("li", { class: `${P}-entry`, "data-words": "" }, h("span", null, p.words.keyNumbers))); + if (m.nodes.some((n) => n.focal) && m.legend.focal) out.push(entry(h("svg", { class: `${P}-swatch`, "data-shape": "focal", ...svgA(16, 16) }, h("rect", { class: `${P}-swatch-shape`, x: 0.5, y: 2.5, width: 15, height: 11, rx: 2 })), m.legend.focal, { "data-focal": "" })); + return out.length ? h("div", { class: `${P}-key` }, h("ul", { class: `${P}-legend`, "aria-label": "Key" }, out)) : null; +} + +function list(P: string, m: Model): VNode[] { + const p = splan(m); + return [h("ol", { class: `${P}-list-items` }, p.tasks.map((t) => h("li", null, h("strong", null, iso(t.name)), t.kind ? [", ", h("code", { class: `${P}-code` }, t.kind)] : "", `: ${length(p, t.d)}. `, + p.bad ? "" : `Earliest start ${said(t.es)} and finish ${said(t.ef)}; latest start ${said(t.ls)} and finish ${said(t.lf)}; ${p.words.float.toLowerCase()} ${t.critical ? "0, critical" : length(p, t.float)}. `, + afterWords(p, t), t.focal && m.legend.focal ? ` ${sentence(m.legend.focal)}` : "")))]; +} + +let made: DiagramTypeExt | undefined; +/** The schedule's module, made at its first use. It is routed: the engine places, routes and stacks it as it does an architecture. */ +export function scheduleType(): DiagramTypeExt { + return (made ??= { + type: "schedule", + routed: true, + stackBare: true, + build, + stop: "a task", + sentence: writeSentence, + card: (P, m, n, _dyn: Dyn) => card(P, m, n), + meta, + key, + list, + traces: (m, drawn) => drawn && m.edges.length > 0, + keys: (m, drawn) => `${drawn ? "Arrow keys move to the nearest task in that direction" : "Arrow keys move to the next or the previous task, in the author's order"}; Home and End go to the ends; Escape clears the trace.${m.nodes.some((n) => n.href) ? " Enter opens a task that is a link." : ""}`, + }); +} diff --git a/packages/react/src/schedule-diagram.tsx b/packages/react/src/schedule-diagram.tsx new file mode 100644 index 00000000..0ccf72a6 --- /dev/null +++ b/packages/react/src/schedule-diagram.tsx @@ -0,0 +1,33 @@ +import * as React from "react"; + +import type { DiagramPlacement } from "./diagram-core"; +import { DiagramFigure } from "./diagram-figure"; +import type { DiagramFigureProps } from "./diagram-figure"; +import { scheduleType } from "./diagram-schedule"; +import type { ScheduleLabels, ScheduleTask, ScheduleUnit } from "./diagram-schedule"; + +export type { ScheduleLabels, ScheduleTask, ScheduleUnit } from "./diagram-schedule"; +export type { DiagramAction, DiagramActionContext, DiagramFigureProps, DiagramLayoutInfo } from "./diagram-figure"; + +export interface ScheduleDiagramProps extends DiagramFigureProps { + /** The one unit every duration is in ("min", or `{ one: "day", other: "days" }`). */ + unit: ScheduleUnit; + /** The tasks, in the author's order (the stack's, the keys' and the list's). Each is placed by its `col` and `row`, as an architecture card is. */ + tasks: ScheduleTask[]; + /** `"auto"`: placed as an architecture is (`placeDiagram`, or elkjs on demand), and no task needs `col` or `row`. */ + layout?: "authored" | "auto"; + direction?: "right" | "down"; + placement?: DiagramPlacement | DiagramPlacement[]; + /** The built-in words, for an app that writes another language. */ + labels?: ScheduleLabels; +} + +/** + * A schedule (DECISIONS 359): a network on the architecture router. Its numbers are computed (finish to start, no lag, no calendar). A task's contour is its + * kind: 2px for a critical task, 1px for one with float, each with its word. A line is main only where its finish sets the next task's start on a critical + * path. Stacked it is its cards in the author's order, each writing what it comes after. The implementation has not been reviewed. + */ +export function ScheduleDiagram({ unit, tasks, layout, direction, placement, labels, motion, entrance, title, heading, legend, ...props }: ScheduleDiagramProps) { + const spec = React.useMemo(() => ({ type: "schedule" as const, ext: scheduleType(), title, heading, legend, unit, tasks, layout, direction, placement, labels, motion, entrance }), [title, heading, legend, unit, tasks, layout, direction, placement, labels, motion, entrance]); + return ; +} From 403d0ad918f3acb10f9177f955b096fbbeb2951a Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:12 -0600 Subject: [PATCH 07/12] Diagrams: the timeline and its seats (DECISIONS 359, Ops 2) One true scale; a card flies from a straight stem at its time, two lanes a side, seats derived latest first, or the figure is stacked; the least drawn width found once; breaks the author's, their length in Basalt's own words; times in the figure's zone. Co-Authored-By: Claude Opus 5.5 --- packages/react/src/diagram-timeline-seat.ts | 46 +++ packages/react/src/diagram-timeline.ts | 353 ++++++++++++++++++++ packages/react/src/timeline-diagram.tsx | 31 ++ 3 files changed, 430 insertions(+) create mode 100644 packages/react/src/diagram-timeline-seat.ts create mode 100644 packages/react/src/diagram-timeline.ts create mode 100644 packages/react/src/timeline-diagram.tsx diff --git a/packages/react/src/diagram-timeline-seat.ts b/packages/react/src/diagram-timeline-seat.ts new file mode 100644 index 00000000..2997f637 --- /dev/null +++ b/packages/react/src/diagram-timeline-seat.ts @@ -0,0 +1,46 @@ +// A timeline's seats (DECISIONS 359, Ops 2, rule 4): arithmetic on the events' places and the cards' size, with no DOM, imported by TimelineDiagram's +// module alone. Seats are derived, latest event first, each taking the first free of: above near, below near, above far, below far. A seat is free when +// the card is space-3 from every card in its lane, its stem is space-2 clear of every nearer card on its side, and every farther card's stem is space-2 +// clear of it. Where only far seats are free and both are, the event takes the one that leaves the event before it a near seat; otherwise above. Each +// event tests four seats against the cards placed, so the work is bounded by the events squared. Nothing runs at load. + +export type SeatSide = "above" | "below"; +export interface Seat { k: number; x: number; l: number; side: SeatSide; lane: 0 | 1; turned: boolean } +export type Seating = { ok: true; placed: Seat[] } | { ok: false; at: number }; + +/** + * Seats a timeline's cards. `xs` are the events' places from the axis' start edge (in time order); `width` is the drawing's; `node` a card's width; `gap` + * the room between two cards in a lane (space-3), `clear` between a stem and a card (space-2), `radius` how far a card's start edge is before its stem + * (radius-md, so the stem meets the flat part of its side). A flag turns toward the start only where it would pass the drawing's end edge. + */ +export function seatCards(xs: readonly number[], width: number, node: number, gap: number, clear: number, radius: number): Seating { + const order: Array<[SeatSide, 0 | 1]> = [["above", 0], ["below", 0], ["above", 1], ["below", 1]]; + const placed: Seat[] = []; + const startOf = (x: number) => { let l = x - radius, turned = false; if (l + node > width) { l = x + radius - node; turned = true; } return { l, turned }; }; + const fits = (x: number, l: number, side: SeatSide, lane: 0 | 1, extra?: Seat): boolean => { + for (const c of extra ? [...placed, extra] : placed) { + if (c.side !== side) continue; + if (c.lane === lane) { if (!(l + node + gap <= c.l || c.l + node + gap <= l)) return false; } + // My stem passes a nearer card's lane: it is clear of that card. + else if (c.lane < lane) { if (!(x < c.l - clear || x > c.l + node + clear)) return false; } + // A farther card's stem passes my lane: it is clear of me. + else if (!(c.x < l - clear || c.x > l + node + clear)) return false; + } + return true; + }; + for (let k = xs.length - 1; k >= 0; k--) { + const x = xs[k]!; + const { l, turned } = startOf(x); + if (l < 0) return { ok: false, at: k }; + const open = order.filter(([side, lane]) => fits(x, l, side, lane)); + if (!open.length) return { ok: false, at: k }; + let pick = open[0]!; + if (pick[1] === 1 && open.length > 1 && k > 0) { + const before = xs[k - 1]!, b = startOf(before); + const leaves = open.filter(([side, lane]) => { const me: Seat = { k, x, l, side, lane, turned }; return fits(before, b.l, "above", 0, me) || fits(before, b.l, "below", 0, me); }); + if (leaves.length) pick = leaves[0]!; + } + placed.push({ k, x, l, side: pick[0], lane: pick[1], turned }); + } + return { ok: true, placed: placed.sort((a, b) => a.k - b.k) }; +} diff --git a/packages/react/src/diagram-timeline.ts b/packages/react/src/diagram-timeline.ts new file mode 100644 index 00000000..894c5234 --- /dev/null +++ b/packages/react/src/diagram-timeline.ts @@ -0,0 +1,353 @@ +// A timeline (DECISIONS 359, Ops 2): points on one linear scale, never even gaps. Each event is a dot on the axis and a card that flies from a straight +// stem at its time, in two lanes above the axis and two below; a figure where an event has no seat is stacked, and a card off its time is never drawn. The +// scale is diagram-scale's (the clock ladder, roundOut, breaks, reversed); the seats are diagram-timeline-seat's; the times are written in the figure's +// zone through time-format.ts (DECISIONS 207). TimelineDiagram hands this module to the engine on the spec. Nothing runs at load. The implementation has +// not been reviewed. + +import { escapeHtml, h, iso, own, rectOf, sentence, svgA, txt } from "./diagram-core"; +import type { DiagramSpec, DiagramTypeExt, Dyn, ExtBuildKit, ExtBuilt, ExtMeasureKit, Geo, Measured, MNode, Model, VElement, VNode } from "./diagram-core"; +import { clockLadder, dateWords, instantOf, roundOut, scaleMap, ticks } from "./diagram-scale"; +import type { ScaleMap, ScaleTick } from "./diagram-scale"; +import { seatCards } from "./diagram-timeline-seat"; +import type { Seat } from "./diagram-timeline-seat"; +import { formatElapsed, formatStamp } from "./time-format"; + +export interface TimelineEvent { id: string; at: string; name: string; kind?: string; detail?: string; detailMono?: boolean; focal?: boolean; href?: string; target?: "_blank" } +/** A span left out of the scale, the author's alone: drawn as a gap with two slashes, its length written by the engine. */ +export interface TimelineBreak { from: string; to: string; label?: string } +export interface TimelineLabels { event?: string; breakKey?: string; eventKey?: string } + +const DAY = 86_400_000; +const r2 = (n: number) => Math.round(n * 100) / 100; + +interface TEvent { id: string; i: number; at: number; name: string; kind?: string; detail?: string; mono: boolean; focal: boolean; href?: string; blank?: boolean } +interface TimelinePlan { + events: TEvent[]; + breaks: Array<{ from: number; to: number; label?: string }>; + /** The author's domain, used as written; else the events' extent, which the layout rounds out at each width it tries. */ + domain?: [number, number]; + extent: [number, number]; + zone: string; + zoneShort: string; + words: Required; +} +const tplan = (m: Model) => m.plan as TimelinePlan; + +// ---- Words in the figure's zone (time-format.ts; the zone is an argument, never a place) ---- + +/** The zone's offset from UTC at an instant, in minutes, read from the wall clock time-format.ts writes there. */ +function offsetIn(zone: string): (ms: number) => number { + return (ms) => { + const at = Math.floor(ms / 1000) * 1000; + const wall = Date.parse(`${formatStamp(at, { timeZone: zone }).dateTime}Z`); + return Number.isFinite(wall) ? Math.round((wall - at) / 60000) : 0; + }; +} +const clockOf = (ms: number, zone: string, seconds = false) => { const t = formatStamp(ms, { timeZone: zone }).text; return seconds ? t.slice(0, 8) : t.slice(0, 5); }; +const wallDay = (ms: number, zone: string) => Math.floor(Date.parse(`${formatStamp(ms, { timeZone: zone }).dateTime.slice(0, 10)}T00:00:00Z`) / DAY); +/** A length in Basalt's shipped words (formatElapsed's forms, with seconds under a minute): "45 s", "31 min", "2 hr 15 min", "3 days". */ +function lengthWords(ms: number): string { + if (ms < 60_000) return `${Math.max(0, Math.round(ms / 1000))} s`; + return formatElapsed(0, ms)?.text ?? `${Math.round(ms / 1000)} s`; +} +function shortZone(zone: string): string { + if (zone === "UTC") return "UTC"; + try { return new Intl.DateTimeFormat("en-US", { timeZone: zone, timeZoneName: "short" }).formatToParts(0).find((p) => p.type === "timeZoneName")?.value ?? zone; } catch { return zone; } +} + +function build(spec: DiagramSpec, kit: ExtBuildKit): ExtBuilt { + const { dev, error, warn } = kit; + const given = (spec.labels ?? {}) as TimelineLabels; + const words: Required = { event: given.event ?? "Event", breakKey: given.breakKey ?? "Time left out of the scale", eventKey: given.eventKey ?? "An event, at its time" }; + const zoneIn = txt(spec.timeZone) ?? "UTC"; + let zone = zoneIn; + try { new Intl.DateTimeFormat("en-US", { timeZone: zoneIn }); } catch { dev && error(`"${zoneIn}" is not an IANA zone: the times are written in UTC`); zone = "UTC"; } + const raw = (Array.isArray(spec.events) ? spec.events : []) as Array; + const read: TEvent[] = []; + raw.forEach((e, i) => { + const at = instantOf(e.at); + if (dev && e.end !== undefined) error(`${String(e.id)} has an end: a timeline's events are points, and a span is a gantt's bar`); + if (at === null) { dev && error(`${String(e.id)}'s at is ${JSON.stringify(e.at)}, not an ISO 8601 instant with its offset`); return; } + read.push({ id: String(e.id ?? ""), i, at, name: String(e.name ?? ""), kind: txt(e.kind), detail: txt(e.detail), mono: Boolean(e.detailMono), focal: Boolean(e.focal), href: txt(e.href), blank: e.target === "_blank" }); + }); + // The engine sorts by `at`; ties keep the author's order. + const events = read.slice().sort((a, b) => a.at - b.at || a.i - b.i); + const breaks = (Array.isArray(spec.breaks) ? spec.breaks : []).flatMap((b) => { + const x = b as TimelineBreak; + const from = instantOf(x.from), to = instantOf(x.to); + if (from === null || to === null || to <= from) { dev && error(`a break from ${JSON.stringify(x.from)} to ${JSON.stringify(x.to)} is not two instants in order`); return []; } + return [{ from, to, label: txt(x.label) }]; + }).sort((a, b) => a.from - b.from); + for (const e of events) if (breaks.some((b) => e.at > b.from && e.at < b.to)) dev && error(`${e.id} is inside a break: a break leaves out time with no event in it`); + const extent: [number, number] = events.length ? [events[0]!.at, events[events.length - 1]!.at] : [0, 60_000]; + let domain: [number, number] | undefined; + if (Array.isArray(spec.domain)) { + const a = instantOf(spec.domain[0]), b = instantOf(spec.domain[1]); + if (a === null || b === null || b <= a) dev && error("the domain is not two instants in order: it is the events' extent, rounded out"); + else { + // An event outside the domain is an error, and the domain grows to hold it: nothing is cut. + if (extent[0] < a || extent[1] > b) dev && error("an event is outside the domain: the domain grows to hold it"); + domain = [Math.min(a, extent[0]), Math.max(b, extent[1])]; + } + } + const nodes: MNode[] = events.map((e, k) => ({ id: e.id, i: k, name: e.name, kind: e.kind, detail: e.detail, mono: e.mono, focal: e.focal, col: k + 1, row: 1, row2: 1, branch: false, shape: "box", href: e.href, blank: e.blank })); + if (dev) { const ids = new Set(); for (const n of nodes) { if (ids.has(n.id)) warn(`the id "${n.id}" is used twice`); ids.add(n.id); } } + if (dev && nodes.filter((n) => n.focal).length > 1) warn("more than one event is focal: a timeline has one at most"); + if (dev && (spec as { timeLabel?: unknown }).timeLabel !== undefined) warn("a timeline's times are written by the engine: `timeLabel` is not read"); + const plan: TimelinePlan = { events, breaks, domain, extent, zone, zoneShort: shortZone(zone), words }; + return { nodes, edges: [], plan, cols: Math.max(1, nodes.length), rows: 1 }; +} + +const tev = (m: Model, id: string) => tplan(m).events.find((e) => e.id === id)!; +const gapBefore = (p: TimelinePlan, e: TEvent) => { const k = p.events.indexOf(e); return k > 0 ? e.at - p.events[k - 1]!.at : null; }; + +function writeSentence(m: Model, n: MNode): string { + const p = tplan(m), e = tev(m, n.id); + const k = p.events.indexOf(e); + const gap = gapBefore(p, e); + const parts = [`${e.name}, ${clockOf(e.at, p.zone)} ${p.zoneShort}${gap !== null ? `, ${lengthWords(gap)} after ${p.events[k - 1]!.name}` : ""}.`]; + if (e.kind) parts.push(sentence(e.kind)); + if (e.detail) parts.push(sentence(e.detail)); + parts.push(`${p.words.event} ${k + 1} of ${p.events.length}.`); + if (e.focal && m.legend.focal) parts.push(sentence(m.legend.focal)); + return parts.join(" "); +} + +// ---- The drawing: one DOM. Drawn, the cards are placed by the layout (--_tx, --_ty); stacked, a column on the rail. ---- + +function drawing(P: string, m: Model, dyn: Dyn, level?: number): VNode[] { + const p = tplan(m); + const out: VNode[] = []; + let b = 0; + p.events.forEach((e, k) => { + // Stacked, a break is a row of its words before the first event after it. + while (b < p.breaks.length && p.breaks[b]!.to <= e.at) { const br = p.breaks[b++]!; out.push(h("p", { class: `${P}-tl-break`, "aria-hidden": "true" }, h("span", { class: `${P}-tl-break-words` }, iso(`// ${lengthWords(br.to - br.from)}${br.label ? ` · ${br.label}` : ""}`)))); } + const n = m.byId.get(e.id)!; + const gap = gapBefore(p, e); + out.push(h(e.href ? "a" : "div", { + class: `${P}-node ${P}-tl-card`, href: e.href, target: e.href && e.blank ? "_blank" : undefined, rel: e.href && e.blank ? "noopener noreferrer" : undefined, "data-link": e.href ? (e.blank ? "external" : "") : undefined, + "data-node": e.id, "data-focal": e.focal ? "" : undefined, "data-level": level, role: e.href ? undefined : "img", "aria-label": writeSentence(m, n), + tabindex: dyn.layout && !dyn.bare ? (dyn.stop === e.id ? 0 : -1) : dyn.keep === e.id ? -1 : undefined, style: own(dyn.place, e.id), + }, + // The kind line: the time (Geist, 500, tabular), the gap since the event before (stacked only), then the kind in Mono; never broken. + h("span", { class: `${P}-kind ${P}-tl-line` }, h("span", { class: `${P}-tl-time` }, clockOf(e.at, p.zone)), gap !== null && k > 0 ? h("span", { class: `${P}-tl-gap` }, ` +${lengthWords(gap)}`) : null, e.kind ? [" · ", iso(e.kind)] : null), + h("span", { class: `${P}-name` }, iso(e.name)), + e.detail ? h("span", { class: `${P}-detail`, "data-mono": e.mono ? "" : undefined }, e.mono ? h("span", { class: `${P}-runs` }, e.detail.split(/\s+/).filter(Boolean).flatMap((w, j) => [j ? " " : "", h("span", { class: `${P}-run` }, w)])) : iso(e.detail)) : null)); + }); + return out; +} + +function key(P: string, m: Model): VElement | null { + const p = tplan(m); + const entry = (swatch: VElement, words: string, attrs = {}) => h("li", { class: `${P}-entry`, ...attrs }, swatch, h("span", null, iso(words))); + const out: VElement[] = [entry(h("svg", { class: `${P}-swatch`, ...svgA(12, 16) }, h("path", { class: `${P}-tl-stem`, d: "M6.5 0V8" }), h("path", { class: `${P}-tl-axis`, d: "M0 11.5H12" }), h("circle", { class: `${P}-tl-dot`, cx: 6.5, cy: 11.5, r: 3 })), p.words.eventKey)]; + if (p.breaks.length) out.push(entry(h("svg", { class: `${P}-swatch`, ...svgA(28, 16) }, h("path", { class: `${P}-tl-axis`, d: "M0 8.5H8M20 8.5H28" }), h("path", { class: `${P}-tl-slash`, d: "M10 14L14 2M14 14L18 2" })), p.words.breakKey)); + if (m.nodes.some((n) => n.focal) && m.legend.focal) out.push(entry(h("svg", { class: `${P}-swatch`, "data-shape": "focal", ...svgA(16, 16) }, h("rect", { class: `${P}-swatch-shape`, x: 0.5, y: 2.5, width: 15, height: 11, rx: 2 })), m.legend.focal, { "data-focal": "" })); + return h("div", { class: `${P}-key` }, h("ul", { class: `${P}-legend`, "aria-label": "Key" }, out)); +} + +function list(P: string, m: Model): VNode[] { + const p = tplan(m); + const items: VNode[] = []; + let b = 0; + p.events.forEach((e) => { + while (b < p.breaks.length && p.breaks[b]!.to <= e.at) { const br = p.breaks[b++]!; items.push(h("li", null, `${lengthWords(br.to - br.from)} left out of the scale${br.label ? `: ${br.label}` : ""}.`)); } + const gap = gapBefore(p, e); + items.push(h("li", null, `${clockOf(e.at, p.zone)} ${p.zoneShort}${gap !== null ? ` (+${lengthWords(gap)})` : ""}: `, h("strong", null, iso(e.name)), e.kind ? `, ${e.kind}` : "", e.detail ? `. ${sentence(e.detail)}` : ".", e.focal && m.legend.focal ? ` ${sentence(m.legend.focal)}` : "")); + }); + return [h("ol", { class: `${P}-list-items` }, items)]; +} + +// ---- Measuring (script only) ---- + +interface Frame { map: ScaleMap; axisL: number; axisR: number; ticks: ScaleTick[]; xs: number[] } + +/** The scale at a drawing width: the axis inset at each end by the larger of space-5 and half a tick label plus space-1, the zone space-3 after its end. */ +function frameAt(p: TimelinePlan, width: number, tk: ExtMeasureKit["tk"], labelW: number, zoneW: number, rtl: boolean): Frame | null { + const s = tk.space; + const edge = Math.max(s("5"), Math.ceil(labelW / 2) + s("1")); + // In physical coordinates: the zone's room is at the axis' end, the left right to left. + const zone = Math.max(edge, zoneW + s("3")); + const axisL = rtl ? zone : edge, axisR = width - (rtl ? edge : zone); + const length = axisR - axisL; + if (length <= 0) return null; + const ladder = clockLadder(offsetIn(p.zone)); + const breaks = p.breaks.map((b) => [b.from, b.to] as const); + const gap = s("8"); + let domain = p.domain; + if (!domain) { + // The default domain is the timeline's own (the answers' section 3): roundOut of the events' extent, again at each width tried. + const found = roundOut(p.extent, ladder, tk.node, length, breaks, gap); + domain = found ? found.domain : [p.extent[0], p.extent[1] > p.extent[0] ? p.extent[1] : p.extent[0] + 60_000]; + } + const map = scaleMap({ domain, length, breaks, gap, reversed: rtl }); + return { map, axisL, axisR, ticks: ticks(map, ladder, tk.node), xs: p.events.map((e) => map.position(e.at)) }; +} + +function layout(m: Model, kit: ExtMeasureKit): Measured { + const { drawing: el, P, tk, W, apply, stopOf, current, measure } = kit; + const p = tplan(m); + const s = tk.space; + const stacked = () => { + const dyn = stopOf({ ...current, layout: "stacked", place: undefined, bare: undefined }); + apply(dyn); + return { dyn, ...stackInk(el, m, P, tk), tokens: tk, least: Infinity }; + }; + if (W < tk.wide || !p.events.length) { const out = stacked(); return { ...out, least: W < tk.wide ? tk.wide : out.least }; } + // One width for every card: size-diagram-node, or more where a time line (never broken) needs it. + const pad = 2 * s("3") + 2 * tk.hair; + let tw = tk.node; + for (const e of p.events) tw = Math.max(tw, Math.ceil(measure(clockOf(e.at, p.zone), "xs-500") + (e.kind ? measure(" · ", "tab") + measure(e.kind, "mono") : 0) + pad)); + const rtl = Boolean(m.rtl); + // The cards' heights at that width, measured once in the drawn state. + apply(stopOf({ ...current, layout: "drawn", place: { "": `--_tw:${tw}px;--_th:0px;--_tdw:${W}px` }, bare: undefined })); + const heights = new Map(p.events.map((e) => { const c = el.querySelector(`.${P}-node[data-node="${CSS.escape(e.id)}"]`); return [e.id, c ? Math.ceil(c.getBoundingClientRect().height) : 0]; })); + const labelW = measure("00:00", "tab"); + const zoneW = measure(p.zoneShort, "mono"); + const seatAt = (width: number) => { + const f = frameAt(p, width, tk, labelW, zoneW, rtl); + if (!f) return null; + // Seated in the axis' own logical coordinates (from its start), so a mirrored figure's flags fly toward its start too. + const logical = f.xs.map((x) => (rtl ? width - (f.axisL + x) : f.axisL + x)); + const st = seatCards(logical.map((x) => Math.round(x) + 0.5), width, tw, s("3"), s("2"), tk.radius); + return st.ok ? { f, placed: st.placed } : null; + }; + // From the first width it draws at, it draws at every wider one: the least drawn width is the first, stepping up by size-diagram-node from 640 + // (nineteen steps at most), at which every event seats; a wider width that does not seat draws the widest narrower width that does, on the start edge. + let least = Infinity; + for (let k = 0; k < 19; k++) { const w = tk.wide + k * tk.node; if (seatAt(w)) { least = w; break; } } + if (!(least <= W)) { const out = stacked(); return { ...out, least: Number.isFinite(least) ? least : out.least }; } + let width = W, got = seatAt(W); + if (!got) for (let w = least + Math.floor((W - least) / tk.node) * tk.node; w >= least && !got; w -= tk.node) { got = seatAt(w); width = w; } + if (!got) { const out = stacked(); return { ...out, least }; } + const { f, placed } = got; + // The lanes: the near lane space-6 above the axis and space-10 below it (the tick row is between); the far lane past the tallest near card plus space-3. + const near = { above: 0, below: 0 }, far = { above: 0, below: 0 }; + for (const q of placed) { const hgt = heights.get(p.events[q.k]!.id)!; const o = q.lane ? far : near; o[q.side] = Math.max(o[q.side], hgt); } + const above = s("6"), below = s("10"), lane = s("3"); + const y0 = Math.round((far.above ? far.above + lane : 0) + near.above + above) + 0.5; + const total = Math.ceil(y0 + (near.below ? below + near.below : s("8")) + (far.below ? lane + far.below : 0)); + const place: Record = { "": `--_tw:${tw}px;--_th:${total}px;--_tdw:${width}px` }; + const seats: Array = []; + for (const q of placed) { + const e = p.events[q.k]!, hgt = heights.get(e.id)!; + const y = q.side === "above" ? y0 - above - (q.lane ? near.above + lane : 0) - hgt : y0 + below + (q.lane ? near.below + lane : 0); + // A mirrored figure's card is placed from the right edge: its logical start is its physical right. + const left = rtl ? width - q.l - tw : q.l; + place[e.id] = `--_tx:${r2(left)}px;--_ty:${Math.round(y)}px`; + seats.push({ ...q, y: Math.round(y), h: hgt, left }); + } + const dyn = stopOf({ ...current, layout: "drawn", place, bare: undefined }); + apply(dyn); + return { dyn, ...drawnInk(el, m, P, tk, f, seats, y0, width, tw, measure), tokens: tk, least }; +} + +function svgOf(P: string, geo: Geo, body: string) { return `${body}`; } +const blank = (el: HTMLElement): Geo => ({ w: el.clientWidth, h: el.clientHeight, nodes: [], lines: [], lifelines: [], labels: [], crossings: [], through: [], unseated: [], outside: [], ox: 0, oy: 0 }); + +function drawnInk(el: HTMLElement, m: Model, P: string, tk: ExtMeasureKit["tk"], f: Frame, seats: Array, y0: number, width: number, tw: number, measure: ExtMeasureKit["measure"]): { geo: Geo; ink: string } { + const p = tplan(m); + const s = tk.space; + const rtl = Boolean(m.rtl); + const geo = blank(el); + const half = (v: number) => Math.round(v - 0.5) + 0.5; + // The axis' x for a place on the map (the map is mirrored right to left; the axis keeps its inset at both ends). + const X = (pos: number) => f.axisL + pos; + let body = ""; + // The axis, cut by each break's gap; in the gap, two slashes (12 tall, 4 across, 2 apart, round ends). + const cuts = f.map.breaks.map(([a]) => { const x = X(f.map.position(a)); return rtl ? [x - f.map.gap, x] : [x, x + f.map.gap]; }).sort((a, b) => a[0]! - b[0]!); + let from = f.axisL; + for (const [a, b] of cuts) { body += ``; from = b!; } + body += ``; + const breakBoxes: Array<[number, number]> = []; + f.map.breaks.forEach(([a, b], k) => { + const mid = (cuts[k]![0]! + cuts[k]![1]!) / 2; + body += ``; + const br = p.breaks.find((x) => x.from === a); + const words = `${lengthWords(b - a)}${br?.label ? ` · ${br.label}` : ""}`; + const w = measure(words, "tab"); + breakBoxes.push([mid - w / 2 - s("2"), mid + w / 2 + s("2")]); + body += `${escapeHtml(words)}`; + }); + // Stems (1px diagram-structure, from the dot to the card's near edge, never jogging) and dots (size-dot, diagram-edge); each is its card's (data-for). + const downs: number[] = []; + for (const q of seats) { + const e = p.events[q.k]!; + const x = half(rtl ? width - q.x : q.x); + const edgeY = q.side === "above" ? q.y + q.h : q.y; + if (q.side === "below") downs.push(x); + body += ``; + } + // Ticks: a 1px mark space-1-5 long under the axis, every one round; a label centred space-2 under it gives way only to a stem through its box grown + // space-1, or to a break's words grown space-2. A tick at midnight writes its date; where the domain crosses a midnight the first tick writes both. + const crosses = wallDay(f.map.domain[0], p.zone) !== wallDay(f.map.domain[1], p.zone); + f.ticks.forEach((t, k) => { + const x = half(X(t.place)); + body += ``; + const daily = /day|week|month|year/.test(t.step); + const midnight = clockOf(t.value, p.zone) === "00:00"; + const sub = /\bs$/.test(t.step); + const label = daily || midnight ? dateWords(wallDay(t.value, p.zone)) : k === 0 && crosses ? `${dateWords(wallDay(t.value, p.zone))}, ${clockOf(t.value, p.zone, sub)}` : clockOf(t.value, p.zone, sub); + const w = measure(label, "tab"); + const lo = x - w / 2 - s("1"), hi = x + w / 2 + s("1"); + if (downs.some((d) => d >= lo && d <= hi) || breakBoxes.some(([a, b]) => lo < b && hi > a)) return; + body += `${escapeHtml(label)}`; + }); + for (const q of seats) body += ``; + // The zone's short name, space-3 after the axis' end, on its line, Mono tertiary (an identifier). + body += `${escapeHtml(p.zoneShort)}`; + void tw; + return { geo, ink: svgOf(P, geo, body) }; +} + +/** Stacked: a rail at space-3 from the start, 1px between two marks, a size-dot dot a card on its first line and a 1px tick to the card; the rail stops across a break. */ +function stackInk(el: HTMLElement, m: Model, P: string, tk: ExtMeasureKit["tk"]): { geo: Geo; ink: string } { + const geo = blank(el); + const origin = el.getBoundingClientRect(); + const rtl = Boolean(m.rtl); + const s = tk.space; + const rail = rtl ? geo.w - s("3") - 0.5 : s("3") + 0.5; + let body = "", last: number | null = null; + for (const child of el.children) { + if (child.classList.contains(`${P}-tl-break`)) { last = null; continue; } + if (!child.classList.contains(`${P}-node`)) continue; + const r = rectOf(child, origin); + const y = Math.round(r.t + s("2-5") + 8) + 0.5; + const id = (child as HTMLElement).dataset.node ?? ""; + if (last !== null) body += ``; + body += ``; + body += ``; + last = y; + } + return { geo, ink: svgOf(P, geo, body) }; +} + +function keyTarget(m: Model, from: string, key: string, drawn: boolean, rtl: boolean): string | null { + const i = m.byId.get(from)?.i ?? 0, n = m.nodes.length; + // ← → the event before and after in time: physical keys, so they swap right to left. Stacked, the arrows are the time order. + const fwd = drawn ? (key === "ArrowRight" ? !rtl : key === "ArrowLeft" ? rtl : null) : key === "ArrowDown" || key === "ArrowRight" ? true : key === "ArrowUp" || key === "ArrowLeft" ? false : null; + const to = key === "Home" ? 0 : key === "End" ? n - 1 : fwd === null ? null : i + (fwd ? 1 : -1); + return to === null ? null : m.nodes[Math.max(0, Math.min(n - 1, to))]?.id ?? null; +} + +let made: DiagramTypeExt | undefined; +/** The timeline's module, made at its first use. */ +export function timelineType(): DiagramTypeExt { + return (made ??= { + type: "timeline", + build, + stop: "an event", + sentence: writeSentence, + key, + list, + drawing, + least: (_m, tk) => tk.wide, + layout, + keyTarget, + hasStops: (_m, dyn) => Boolean(dyn.layout && !dyn.bare), + traces: () => false, + hint: (m, drawn) => [{ keys: drawn ? ["←", "→"] : ["↑", "↓"], words: "an event" }, { keys: ["Home", "End"], words: "the ends" }, ...(m.nodes.some((n) => n.href) ? [{ keys: ["Enter"], words: "open" }] : [])], + keys: (m, drawn) => `${drawn ? "Left and right arrows move to the event before or after in time" : "Arrow keys move to the event before or after in time"}; Home and End go to the first and the last.${m.nodes.some((n) => n.href) ? " Enter opens an event that is a link." : ""}`, + rootStyle: (_m, dyn) => { const v = own(dyn.place, ""); return v ? [v] : []; }, + }); +} diff --git a/packages/react/src/timeline-diagram.tsx b/packages/react/src/timeline-diagram.tsx new file mode 100644 index 00000000..f6581be3 --- /dev/null +++ b/packages/react/src/timeline-diagram.tsx @@ -0,0 +1,31 @@ +import * as React from "react"; + +import { DiagramFigure } from "./diagram-figure"; +import type { DiagramFigureProps } from "./diagram-figure"; +import { timelineType } from "./diagram-timeline"; +import type { TimelineBreak, TimelineEvent, TimelineLabels } from "./diagram-timeline"; + +export type { TimelineBreak, TimelineEvent, TimelineLabels } from "./diagram-timeline"; +export type { DiagramAction, DiagramActionContext, DiagramFigureProps, DiagramLayoutInfo } from "./diagram-figure"; + +export interface TimelineDiagramProps extends DiagramFigureProps { + /** The events: points, each at an ISO 8601 instant with its offset. The engine sorts them by `at`; ties keep the author's order. */ + events: TimelineEvent[]; + /** The scale's two ends, used as written. Left out, the events' extent rounded out to ticks. */ + domain?: [string, string]; + /** An IANA zone every time is written in, 24-hour (default `"UTC"`). */ + timeZone?: string; + /** Spans left out of the scale, the author's alone, each drawn as a gap with two slashes and its length. */ + breaks?: TimelineBreak[]; + /** The built-in words, for an app that writes another language. */ + labels?: TimelineLabels; +} + +/** + * A timeline (DECISIONS 359): points on one linear scale, never even gaps. A card flies from a straight stem at its time, two lanes a side; where an event + * has no seat the figure is stacked, each card writing the gap since the one before. A span is a gantt's. The implementation has not been reviewed. + */ +export function TimelineDiagram({ events, domain, timeZone, breaks, labels, motion: _motion, entrance: _entrance, title, heading, legend, ...props }: TimelineDiagramProps) { + const spec = React.useMemo(() => ({ type: "timeline" as const, ext: timelineType(), title, heading, legend, events, domain, timeZone, breaks, labels }), [title, heading, legend, events, domain, timeZone, breaks, labels]); + return ; +} From e9ac12422231c379ac2bbe468dc676735eb2aced Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:15 -0600 Subject: [PATCH 08/12] Diagrams: the new types' styles and exports Co-Authored-By: Claude Opus 5.5 --- packages/react/src/index.ts | 19 + packages/react/src/styles/components.css | 424 ++++++++++++++++++++++- 2 files changed, 438 insertions(+), 5 deletions(-) diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index 671a1d66..27e7eeae 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -103,6 +103,25 @@ export { SequenceDiagram } from "./sequence-diagram"; export type { DiagramFrameLabels, SequenceDiagramProps, SequenceMessage, SequenceParticipant, SequenceStep } from "./sequence-diagram"; export { SchemaDiagram } from "./schema-diagram"; export type { DiagramCardinality, DiagramCardinalityPair, SchemaColumn, SchemaDiagramProps, SchemaTable } from "./schema-diagram"; +// The types of batch D, wave 1 (DECISIONS 359): each its own module, so an app that draws an architecture bundles none of them. +export { StateDiagram } from "./state-diagram"; +export type { StateDiagramProps, StateNode, StateTransition } from "./state-diagram"; +export { DeploymentDiagram } from "./deployment-diagram"; +export type { DeploymentArtifact, DeploymentDiagramProps, DeploymentNode } from "./deployment-diagram"; +export { TimelineDiagram } from "./timeline-diagram"; +export type { TimelineBreak, TimelineDiagramProps, TimelineEvent, TimelineLabels } from "./timeline-diagram"; +export { GanttDiagram } from "./gantt-diagram"; +export type { GanttDiagramProps, GanttLabels, GanttPhase, GanttTask, GanttUnit } from "./gantt-diagram"; +export { KanbanDiagram } from "./kanban-diagram"; +export type { KanbanCard, KanbanColumn, KanbanDiagramProps, KanbanLabels } from "./kanban-diagram"; +export { JourneyDiagram } from "./journey-diagram"; +export type { JourneyDiagramProps, JourneyLabels, JourneyLevel, JourneyStage } from "./journey-diagram"; +export { ServiceBlueprintDiagram } from "./service-blueprint-diagram"; +export type { BlueprintArrow, BlueprintCell, BlueprintLabels, BlueprintLayer, BlueprintRuleLabels, BlueprintStage, ServiceBlueprintDiagramProps } from "./service-blueprint-diagram"; +export { StoryMapDiagram } from "./story-map-diagram"; +export type { StoryActivity, StoryCard, StoryCut, StoryMapDiagramProps, StoryMapLabels, StorySlice } from "./story-map-diagram"; +export { ScheduleDiagram } from "./schedule-diagram"; +export type { ScheduleDiagramProps, ScheduleLabels, ScheduleTask, ScheduleUnit } from "./schedule-diagram"; export { PhaseChart } from "./phase-chart"; export type { PhaseCall, PhaseChartProps } from "./phase-chart"; export { ShareBar } from "./share-bar"; diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index ade6c2d5..d83c35e2 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -5039,7 +5039,7 @@ sequence's, whose columns are participants) is capped on the start edge as the stack is, or at its column's least width where that is more (--_one, written by the engine with the layout, so the cap is in place before the drawing is measured). Before script the same cap, at the token. The room beside it is open page. */ - .basalt-diagram:not([data-type="sequence"])[data-cols="1"] > .basalt-diagram-drawing { --_d-max: var(--_drawn) max(var(--basalt-size-breakpoint-container), var(--_one, var(--basalt-size-breakpoint-container))); } + .basalt-diagram:not([data-type="sequence"], [data-type="gantt"])[data-cols="1"] > .basalt-diagram-drawing { --_d-max: var(--_drawn) max(var(--basalt-size-breakpoint-container), var(--_one, var(--basalt-size-breakpoint-container))); } .basalt-diagram[data-type="schema"][data-cols="1"] > .basalt-diagram-drawing { max-width: var(--_d-max, 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)); } @@ -5047,7 +5047,7 @@ /* 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]:not([data-type="gantt"], [data-type="kanban"], [data-type="journey"], [data-type="service-blueprint"], [data-type="story-map"], [data-type="timeline"]) > .basalt-diagram-drawing { direction: ltr; } /* Stacked, the figure mirrors too (1.7): the end gutter is on the left, and a branch is indented from the right, its end lane on the left. */ .basalt-diagram[data-rtl] > .basalt-diagram-drawing { padding: var(--_d-pad, 0 0 0 var(--_gutter, 0)); } .basalt-diagram[data-rtl] .basalt-diagram-node[data-branch] { margin-inline: var(--_d-mi, var(--basalt-space-6) var(--basalt-space-12)); } @@ -5073,7 +5073,8 @@ .basalt-diagram-node { --_d-gc: var(--_drawn) var(--_c); --_d-gr: var(--_drawn) var(--_r) / var(--_r2); - --_d-mt: var(--_drawn) 0; + --_d-lo: var(--_drawn) calc(var(--_lo, 0) * var(--basalt-space-4)); + --_d-mt: var(--_d-lo); --_d-align: var(--_drawn) center; position: relative; z-index: 1; @@ -5150,6 +5151,9 @@ /* A flowchart's shapes carry its types, so each has a 3:1 contour in place of the rim: one colour on every side. A measured decision's contour is its diamond, so its box's border is never lifted (the diamond's stroke is, below). */ .basalt-diagram[data-type="flowchart"] .basalt-diagram-node:not([data-focal]) { border-color: var(--basalt-diagram-structure); } + /* A data flow that draws a decision (DECISIONS 359, Ops 5): every step takes the contour; the decision is its diamond, with its step line above its name. */ + .basalt-diagram[data-type="data-flow"][data-contour] .basalt-diagram-node:not([data-focal], [data-shape="decision"]) { border-color: var(--basalt-diagram-structure); } + .basalt-diagram[data-type="data-flow"] .basalt-diagram-node[data-shape="decision"] .basalt-diagram-words > .basalt-diagram-kind { display: block; margin-block-end: var(--basalt-space-0-5); } .basalt-diagram[data-type="flowchart"] .basalt-diagram-node:not([data-focal], [data-shape="decision"])[data-near] { border-color: var(--basalt-text-secondary); } .basalt-diagram-node[data-shape="terminal"] { align-items: center; padding-inline: var(--basalt-space-5); border-radius: var(--basalt-radius-full); text-align: center; } /* A decision: a diamond behind its words, the words at 500 within 62% of its width (the track's: the box's border-box, so 62% of the content @@ -5226,7 +5230,7 @@ .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-12) + var(--basalt-space-4) * var(--_tl, 0)); } - .basalt-diagram-group > .basalt-diagram-glabel + .basalt-diagram-node { --_d-mt: 0; } + .basalt-diagram-group > .basalt-diagram-glabel + .basalt-diagram-node { --_d-mt: var(--_d-lo, 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). */ @@ -5241,7 +5245,7 @@ grid-column: var(--_c) / var(--_c2); grid-row: var(--_r) / var(--_r2); /* 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-block: calc(var(--_lo, 0) * var(--basalt-space-4) - 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); @@ -5267,12 +5271,20 @@ .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; } + /* A line of facts about the whole figure, under its source (DECISIONS 359): its first part 500 in primary ink, the rest secondary. */ + .basalt-diagram-meta { margin: calc(var(--basalt-space-1) - var(--basalt-space-0-5)) 0 0; 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-sans); } + .basalt-diagram-meta-first { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-medium); } .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); } .basalt-diagram-ruler[data-f="name-500"] { font: var(--basalt-font-weight-medium) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans); } .basalt-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); } .basalt-diagram-ruler:is([data-f="mono"], [data-f="label"]) { font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); } .basalt-diagram-ruler[data-f="sans"] { font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); } + /* A type of its own's measures (DECISIONS 359): Geist at xs with tabular figures (400, 500, 600), and Geist at sm. */ + .basalt-diagram-ruler:is([data-f="tab"], [data-f="xs-500"], [data-f="xs-600"]) { font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); font-variant-numeric: tabular-nums; } + .basalt-diagram-ruler[data-f="xs-500"] { font-weight: var(--basalt-font-weight-medium); } + .basalt-diagram-ruler[data-f="xs-600"] { font-weight: var(--basalt-font-weight-semibold); } + .basalt-diagram-ruler[data-f="sm"] { font: var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans); } .basalt-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); } .basalt-diagram-line[data-kind="main"] { stroke: var(--basalt-diagram-edge-main); stroke-width: var(--basalt-size-chart-line); } .basalt-diagram-line[data-kind="dashed"] { stroke-dasharray: var(--basalt-size-chart-dash) var(--basalt-size-chart-dash-gap); stroke-linecap: butt; } @@ -5880,6 +5892,408 @@ @starting-style { dialog.basalt-dialog.basalt-diagram-viewer[open] { opacity: 0; transform: none; } } } + /* ---- Diagram gantt (DECISIONS 359, Planning 1.1): a row a task on one time scale, its own module (diagram-gantt.ts; the skill's diagram-gantt) ---- + The drawing is a column of rows, drawn or stacked by one switch as every figure is. Drawn: the names in a size-diagram-table column (or the widest + unbreakable line, --_name), then the track, space-4 apart, its scale inset space-2 at each end. A bar is 16 tall, plate-0 under a 1px diagram-edge + contour, square at both ends; a milestone a diamond of 16px diagonals in the same ink. Stacked: each task's words over its own 32px track (data-form + "tracks"), or the words alone ("words"). The tick lines, the today line and the axis' words are the ink's. The implementation has not been reviewed. */ + .basalt-diagram[data-type="gantt"] > .basalt-diagram-drawing { display: flex; flex-direction: column; gap: 0; } + .basalt-diagram[data-type="gantt"] > .basalt-diagram-drawing > .basalt-diagram-ink { z-index: 0; } + .basalt-diagram-gantt-axis { + --_d-ga: var(--_drawn) grid; + display: var(--_d-ga, block); + grid-template-columns: var(--_name, var(--basalt-size-diagram-table)) minmax(0, 1fr); + column-gap: var(--basalt-space-4); + align-items: end; + padding-block-end: var(--basalt-space-2); + border-block-end: var(--basalt-size-hairline) solid var(--basalt-border-divider); + } + .basalt-diagram[data-form="words"] .basalt-diagram-gantt-axis { display: none; } + .basalt-diagram-gantt-corner { --_d-gc2: var(--_drawn) block; display: var(--_d-gc2, none); 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-gantt-axis > .basalt-diagram-gantt-scale { display: block; height: var(--basalt-text-xs-line-height); margin-inline: var(--basalt-space-2); } + .basalt-diagram-gantt-axis[data-today] > .basalt-diagram-gantt-scale { height: calc(2 * var(--basalt-text-xs-line-height) + var(--basalt-space-1)); } + .basalt-diagram-gantt-phase { margin: var(--basalt-space-3) 0 0; padding-block: var(--basalt-space-1); border-block-end: var(--basalt-size-hairline) solid var(--basalt-border-divider); 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); } + /* A row is the stop: a full-width band, its ring inside at −2. It is no panel: no fill, no rim, the divider under it. */ + .basalt-diagram-node.basalt-diagram-gantt-row { + --_d-gr2: var(--_drawn) grid; + display: var(--_d-gr2, flex); + flex-direction: column; + grid-template-columns: var(--_name, var(--basalt-size-diagram-table)) minmax(0, 1fr); + column-gap: var(--basalt-space-4); + align-items: stretch; + align-self: stretch; + margin-block-start: 0; + padding: var(--basalt-space-3) 0; + background: none; + border: 0; + border-block-end: var(--basalt-size-hairline) solid var(--basalt-border-divider); + border-radius: 0; + } + .basalt-diagram-node.basalt-diagram-gantt-row:focus-visible { outline-offset: calc(-1 * var(--basalt-size-focus-width)); } + /* The focal task is its bar (or diamond) alone: its row's words do not change. */ + .basalt-diagram-node.basalt-diagram-gantt-row[data-focal] { background: none; border-color: var(--basalt-border-divider); } + .basalt-diagram-gantt-row[data-focal] .basalt-diagram-name { color: var(--basalt-text-primary); opacity: 1; } + .basalt-diagram-gantt-row[data-focal] :is(.basalt-diagram-gantt-range, .basalt-diagram-gantt-after, .basalt-diagram-detail) { color: var(--basalt-text-secondary); opacity: 1; } + .basalt-diagram-gantt-words { display: flex; flex-direction: column; gap: var(--basalt-space-0-5); min-width: 0; } + .basalt-diagram-gantt-words > .basalt-diagram-detail { margin-block-start: 0; } + .basalt-diagram-gantt-range, .basalt-diagram-gantt-after { 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-sans); font-variant-numeric: tabular-nums; } + /* The today label ends the range line of a row that holds today, in the stack in words alone (it has no today line). */ + .basalt-diagram-gantt-now { display: none; } + .basalt-diagram[data-form="words"] .basalt-diagram-gantt-now { display: inline; } + .basalt-diagram-gantt-track { --_d-gth: var(--_drawn) auto; position: relative; display: block; height: var(--_d-gth, var(--basalt-space-8)); margin-block-start: var(--_d-gtm, var(--basalt-space-2)); --_d-gtm: var(--_drawn) 0; } + .basalt-diagram[data-form="words"] .basalt-diagram-gantt-track { display: none; } + .basalt-diagram-gantt-track > .basalt-diagram-gantt-scale { position: absolute; inset-block: 0; inset-inline: var(--basalt-space-2); } + .basalt-diagram-gantt-bar { + position: absolute; + inset-block-start: calc(50% - var(--basalt-space-2)); + inset-inline-start: var(--_s); + box-sizing: border-box; + width: var(--_w); + height: var(--basalt-space-4); + background: var(--basalt-plate-0); + border: var(--basalt-size-hairline) solid var(--basalt-diagram-edge); + } + .basalt-diagram-gantt-mile { position: absolute; inset-block-start: calc(50% - var(--basalt-space-2)); inset-inline-start: calc(var(--_s) - var(--basalt-space-2)); width: var(--basalt-space-4); height: var(--basalt-space-4); } + .basalt-diagram-gantt-mile > svg { display: block; width: 100%; height: 100%; overflow: visible; } + .basalt-diagram-gantt-mile path, .basalt-diagram-swatch-bar { fill: var(--basalt-plate-0); stroke: var(--basalt-diagram-edge); stroke-width: var(--basalt-size-hairline); } + .basalt-diagram-gantt-bar[data-focal] { background: var(--basalt-diagram-focal); border-color: var(--basalt-diagram-focal); } + .basalt-diagram-gantt-mile[data-focal] path, .basalt-diagram-swatch-bar[data-focal] { fill: var(--basalt-diagram-focal); stroke: var(--basalt-diagram-focal); } + .basalt-diagram-gantt-grid { fill: none; stroke: var(--basalt-chart-grid); stroke-width: var(--basalt-size-hairline); } + .basalt-diagram-today { 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); } + text.basalt-diagram-gantt-tick { fill: var(--basalt-chart-axis); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); font-variant-numeric: tabular-nums; } + text.basalt-diagram-gantt-today { fill: 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[data-form="words"] .basalt-diagram-entry[data-when="tracks"] { display: none; } + @media (prefers-contrast: more) { + .basalt-diagram-gantt-grid { stroke: var(--basalt-border-input); } + } + @media (forced-colors: active) { + .basalt-diagram-gantt-bar { forced-color-adjust: none; background: Canvas; border-color: CanvasText; } + .basalt-diagram-gantt-bar[data-focal] { background: CanvasText; border-color: CanvasText; } + .basalt-diagram-gantt-mile { forced-color-adjust: none; } + .basalt-diagram-gantt-mile path, .basalt-diagram-swatch-bar { fill: Canvas; stroke: CanvasText; } + .basalt-diagram-gantt-mile[data-focal] path, .basalt-diagram-swatch-bar[data-focal] { fill: CanvasText; stroke: CanvasText; } + .basalt-diagram-gantt-grid { display: none; } + .basalt-diagram-today { stroke: GrayText; } + text.basalt-diagram-gantt-tick, text.basalt-diagram-gantt-today { fill: CanvasText; } + } + @media print { + .basalt-diagram-gantt-bar, .basalt-diagram-gantt-mile { -webkit-print-color-adjust: exact; print-color-adjust: exact; } + } + + /* ---- Diagram matrix (DECISIONS 359, Planning 1.0 and 1.2 to 1.5): kanban, journey, service blueprint, story map, their own module (diagram-matrix.ts; + the skill's diagram-matrix) ---- + Equal tracks space-4 apart, a row-label column (--_lab: size-diagram-lane or its widest unbreakable label) where the type has one, one DOM for both + forms switched by --_drawn. Stacked: one column, at most size-breakpoint-container wide, each column, stage or slice a block space-5 apart. An empty + cell holds its track and says so in words, text-xs tertiary; only a story map's is a slot (a 1px dashed diagram-structure contour). The + implementation has not been reviewed. */ + .basalt-diagram:is([data-type="kanban"], [data-type="journey"], [data-type="service-blueprint"], [data-type="story-map"]) > .basalt-diagram-drawing { + --_row-gap: var(--basalt-space-0); + --_col-gap: var(--basalt-space-4); + gap: var(--_d-gap, var(--basalt-space-5)); + align-items: stretch; + } + .basalt-diagram:is([data-type="journey"], [data-type="service-blueprint"], [data-type="story-map"]) > .basalt-diagram-drawing { --_d-cols: var(--_drawn) var(--_lab, var(--basalt-size-diagram-lane)) repeat(var(--_cols, 1), minmax(0, 1fr)); } + .basalt-diagram[data-type="service-blueprint"] > .basalt-diagram-drawing { --_row-gap: var(--basalt-space-3); } + /* A grid item that is not a stop takes its track from --_c and --_r, drawn only. */ + :is(.basalt-diagram-kanban-head, .basalt-diagram-kanban-cards, .basalt-diagram-journey-cell, .basalt-diagram-bp-head, .basalt-diagram-story-activity, .basalt-diagram-story-steps, .basalt-diagram-story-cell, .basalt-diagram-story-slot) { + --_d-mc: var(--_drawn) var(--_c); + --_d-mr: var(--_drawn) var(--_r); + grid-column: var(--_d-mc, auto); + grid-row: var(--_d-mr, auto); + min-width: 0; + } + :is(.basalt-diagram-kanban-card, .basalt-diagram-journey-head, .basalt-diagram-bp-cell, .basalt-diagram-story-card) { --_d-align: var(--_drawn) stretch; --_d-mt: 0; margin-block-start: 0; } + .basalt-diagram-matrix-label { --_d-ml: var(--_drawn) block; display: var(--_d-ml, none); grid-column: 1; grid-row: var(--_r); padding-block: var(--basalt-space-3); border-block-start: var(--basalt-size-hairline) solid var(--basalt-border-divider); 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-matrix-rule { --_d-mru: var(--_drawn) block; display: var(--_d-mru, none); grid-column: 1 / -1; grid-row: var(--_r); align-self: start; margin-block-start: var(--basalt-space-3); height: var(--basalt-size-hairline); background: var(--basalt-border-divider); } + .basalt-diagram-empty { 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 :is(.basalt-diagram-swatch-rule, .basalt-diagram-swatch-dash) { fill: none; stroke: var(--basalt-diagram-edge-main); stroke-width: var(--basalt-size-chart-line); } + .basalt-diagram .basalt-diagram-swatch-dash { 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); } + .basalt-diagram :is(.basalt-diagram-swatch-slot, .basalt-diagram-swatch-contour, .basalt-diagram-swatch-blocked) { fill: none; stroke: var(--basalt-diagram-structure); stroke-width: var(--basalt-size-hairline); } + .basalt-diagram .basalt-diagram-swatch-slot { stroke-dasharray: var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash); } + .basalt-diagram .basalt-diagram-swatch-blocked { stroke: var(--basalt-diagram-edge-main); stroke-dasharray: var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash); } + + /* Kanban (1.2): the heads are one row, as tall as the tallest, so every rule is on one line; over its limit a column's count is 600 and its rule 2px. */ + .basalt-diagram-kanban-col { --_d-kc: var(--_drawn) contents; display: var(--_d-kc, flex); flex-direction: column; min-width: 0; } + .basalt-diagram-kanban-head { --_r: 1; display: flex; flex-direction: column; gap: var(--basalt-space-0-5); margin-block-end: var(--basalt-space-3); padding-block-end: var(--basalt-space-2); border-block-end: var(--basalt-size-hairline) solid var(--basalt-border-divider); } + .basalt-diagram-kanban-col[data-over] > .basalt-diagram-kanban-head { border-block-end: var(--basalt-size-chart-line) solid var(--basalt-diagram-edge-main); } + .basalt-diagram-kanban-top { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--basalt-space-2); } + .basalt-diagram-kanban-title { flex: 1 1 auto; 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-sans); } + .basalt-diagram-kanban-count { flex: none; 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-sans); font-variant-numeric: tabular-nums; white-space: nowrap; } + .basalt-diagram-kanban-col[data-over] .basalt-diagram-kanban-count { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-semibold); } + .basalt-diagram-kanban-note { 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-kanban-cards { --_r: 2; display: flex; flex-direction: column; gap: var(--basalt-space-2-5); align-self: start; } + .basalt-diagram-kanban-card[data-blocked]:not([data-focal]) { border: var(--basalt-size-hairline) dashed var(--basalt-diagram-edge-main); } + .basalt-diagram-kanban-blocked { margin-block-end: var(--basalt-space-1); 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-sans); } + .basalt-diagram-kanban-card[data-focal] .basalt-diagram-kanban-blocked { color: var(--basalt-diagram-focal-ink); } + .basalt-diagram-kanban-more { 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); } + + /* Journey (1.3): the stage heads, the plot (five levels space-8 apart, space-4 above and below), then a band a field. The line, its discs and the levels' + lines are the ink's. Stacked: the plot is a strip (levels space-6 apart, three named in a space-16 column, the stage numbers under it), then a card a stage. */ + .basalt-diagram-journey-plot { + --_d-jp: var(--_drawn) 1 / -1; + --_d-jpc: var(--_drawn) var(--_lab, var(--basalt-size-diagram-lane)) minmax(0, 1fr); + --_d-jph: var(--_drawn) calc(2 * var(--basalt-space-4) + 4 * var(--basalt-space-8)); + display: grid; + grid-column: var(--_d-jp, auto); + grid-row: 2; + grid-template-columns: var(--_d-jpc, var(--basalt-space-16) minmax(0, 1fr)); + column-gap: var(--basalt-space-4); + height: var(--_d-jph, calc(var(--basalt-space-2) + 4 * var(--basalt-space-6) + var(--basalt-space-3) + var(--basalt-text-xs-line-height))); + margin-block: var(--basalt-space-3) 0; + } + .basalt-diagram-journey-levels { position: relative; } + .basalt-diagram-journey-level { --_d-jlt: var(--_drawn) calc(var(--basalt-space-4) + (5 - var(--_lv)) * var(--basalt-space-8)); position: absolute; inset-block-start: calc(var(--_d-jlt, calc(var(--basalt-space-2) + (5 - var(--_lv)) * var(--basalt-space-6))) - var(--basalt-text-xs-line-height) / 2); inset-inline-end: 0; color: var(--basalt-chart-axis); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); font-variant-numeric: tabular-nums; white-space: nowrap; } + .basalt-diagram-journey-level:not([data-edge]) { --_d-jlv: var(--_drawn) block; display: var(--_d-jlv, none); } + .basalt-diagram-journey-track { display: grid; grid-template-columns: repeat(var(--_cols, 1), minmax(0, 1fr)); column-gap: var(--_d-jtg, 0); --_d-jtg: var(--_drawn) var(--basalt-space-4); } + .basalt-diagram-journey-slot { --_d-js2: var(--_drawn) hidden; visibility: var(--_d-js2, visible); grid-column: var(--_c); align-self: end; 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); font-variant-numeric: tabular-nums; text-align: center; } + .basalt-diagram-journey-slot[data-focal] { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-semibold); } + .basalt-diagram-journey-grid { fill: none; stroke: var(--basalt-chart-grid); stroke-width: var(--basalt-size-hairline); } + .basalt-diagram-journey-line { fill: none; stroke: var(--basalt-diagram-edge-main); stroke-width: var(--basalt-size-chart-line); stroke-linejoin: round; stroke-linecap: round; } + .basalt-diagram-journey-cut { fill: var(--_ground); } + .basalt-diagram-journey-disc { fill: var(--basalt-diagram-edge-main); } + .basalt-diagram-journey-stage { + --_d-jst: var(--_drawn) contents; + display: var(--_d-jst, flex); + flex-direction: column; + gap: var(--basalt-space-2); + padding: var(--basalt-space-3); + background: var(--_surface, 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); + } + /* Stacked, the head is the card's own first lines, not a second panel; the focal one is inverted inside its card. */ + .basalt-diagram-journey-head { --_d-jhb: var(--_drawn) var(--_surface, var(--basalt-surface-1)); --_d-jhr: var(--_drawn) var(--basalt-size-hairline); --_d-jhp: var(--_drawn) var(--basalt-space-2-5) var(--basalt-space-3); background: var(--_d-jhb, none); border-width: var(--_d-jhr, 0); padding: var(--_d-jhp, 0); } + .basalt-diagram-journey-head[data-focal] { background: var(--basalt-diagram-focal); border-width: var(--basalt-size-hairline); padding: var(--basalt-space-2-5) var(--basalt-space-3); } + .basalt-diagram-journey-head > .basalt-diagram-kind { display: flex; justify-content: space-between; gap: var(--basalt-space-2); } + .basalt-diagram-journey-word { color: var(--basalt-text-secondary); font-family: var(--basalt-font-family-sans); font-variant-numeric: tabular-nums; white-space: nowrap; } + .basalt-diagram-journey-head[data-focal] .basalt-diagram-journey-word { color: var(--basalt-diagram-focal-ink); } + .basalt-diagram-journey-cell { --_d-jcp: var(--_drawn) var(--basalt-space-3); display: flex; flex-direction: column; gap: var(--basalt-space-0-5); padding-block: var(--_d-jcp, var(--basalt-space-2) 0); border-block-start: var(--basalt-size-hairline) solid var(--basalt-border-divider); color: var(--basalt-text-primary); font: var(--basalt-font-weight-regular) var(--basalt-text-sm-size) / var(--basalt-text-sm-line-height) var(--basalt-font-family-sans); } + .basalt-diagram-journey-cell[data-empty] { --_d-jce: var(--_drawn) flex; display: var(--_d-jce, none); } + .basalt-diagram-journey-cell-label { --_d-jcl: var(--_drawn) none; display: var(--_d-jcl, block); 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); } + q.basalt-diagram-journey-value { color: var(--basalt-text-secondary); } + + /* Service blueprint (1.4): the three rules in their fixed gaps, each named on the rule: the lines of interaction and internal interaction 1px dashed 4 on + 4 in diagram-structure, the line of visibility 2px solid diagram-edge-main. Drawn, a rule spans the grid; stacked, all three are inside every stage. */ + .basalt-diagram[data-type="service-blueprint"] .basalt-diagram-matrix-label { border-block-start: 0; padding-block: var(--basalt-space-2-5); } + .basalt-diagram-bp-rule { display: flex; align-items: center; gap: var(--basalt-space-3); padding-block: var(--basalt-space-1); } + .basalt-diagram-bp-rule[data-span] { --_d-brs: var(--_drawn) flex; display: var(--_d-brs, none); grid-column: 1 / -1; grid-row: var(--_r); } + .basalt-diagram-bp-rule[data-in] { --_d-bri: var(--_drawn) none; display: var(--_d-bri, flex); } + .basalt-diagram-bp-rule-name { flex: none; 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-sans); white-space: nowrap; } + .basalt-diagram-bp-rule[data-rule="visibility"] > .basalt-diagram-bp-rule-name { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-semibold); } + .basalt-diagram-bp-rule-line { flex: 1 1 auto; min-width: 0; overflow: visible; } + .basalt-diagram-bp-rule-line > line { 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); } + .basalt-diagram-bp-rule[data-rule="visibility"] .basalt-diagram-bp-rule-line > line { stroke: var(--basalt-diagram-edge-main); stroke-width: var(--basalt-size-chart-line); stroke-dasharray: none; } + .basalt-diagram-bp-stage { + --_d-bs: var(--_drawn) contents; + display: var(--_d-bs, flex); + flex-direction: column; + gap: var(--basalt-space-2); + padding: var(--basalt-space-3); + background: var(--_surface, 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); + } + .basalt-diagram-bp-head { --_r: 1; display: flex; flex-direction: column; gap: var(--basalt-space-0-5); padding-block-end: var(--basalt-space-2); border-block-end: var(--basalt-size-hairline) solid var(--basalt-border-divider); } + .basalt-diagram-bp-time { font-family: var(--basalt-font-family-sans); font-variant-numeric: tabular-nums; } + /* A cell is the shipped node drawn; stacked, a line of its stage's card: its layer's name in a size-diagram-lane column and the cell beside it. */ + .basalt-diagram-bp-cell { --_d-bcd: var(--_drawn) column; --_d-bcb: var(--_drawn) var(--_surface, var(--basalt-surface-1)); --_d-bcr: var(--_drawn) var(--basalt-size-hairline); --_d-bcp: var(--_drawn) var(--basalt-space-2-5) var(--basalt-space-3); flex-direction: var(--_d-bcd, row); gap: var(--basalt-space-3); background: var(--_d-bcb, none); border-width: var(--_d-bcr, 0); padding: var(--_d-bcp, 0); } + .basalt-diagram-bp-cell { --_d-bai: var(--_drawn) stretch; justify-content: flex-start; align-items: var(--_d-bai, baseline); } + .basalt-diagram-bp-cell[data-focal] { background: var(--basalt-diagram-focal); border-width: var(--basalt-size-hairline); padding: var(--basalt-space-2-5) var(--basalt-space-3); } + .basalt-diagram-bp-cell[data-empty] { background: none; border-color: transparent; } + .basalt-diagram-bp-layer { --_d-bl: var(--_drawn) none; display: var(--_d-bl, block); flex: none; width: var(--basalt-size-diagram-lane); 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-bp-cell[data-focal] .basalt-diagram-bp-layer { color: var(--basalt-diagram-focal-ink); } + .basalt-diagram-bp-body { display: flex; flex-direction: column; min-width: 0; } + .basalt-diagram-bp-to { --_d-bt: var(--_drawn) none; display: var(--_d-bt, block); margin-block-start: var(--basalt-space-0-5); 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-sans); } + + /* Story map (1.5): the backbone (a card an activity, a diagram-structure contour in place of the rim, never inverted), its steps as chips, then a row a + slice ruled apart, and one cut: a 2px rule after the slice it names. */ + .basalt-diagram-story-backbone { + --_d-sb: var(--_drawn) contents; + display: var(--_d-sb, flex); + flex-direction: column; + gap: var(--basalt-space-2); + padding: var(--basalt-space-3); + background: var(--_surface, var(--basalt-surface-1)); + border: var(--basalt-size-hairline) solid var(--basalt-diagram-structure); + border-radius: var(--basalt-radius-md); + } + .basalt-diagram-story-activity { --_d-sab: var(--_drawn) var(--_surface, var(--basalt-surface-1)); --_d-sar: var(--_drawn) var(--basalt-size-hairline); --_d-sap: var(--_drawn) var(--basalt-space-2-5) var(--basalt-space-3); display: flex; flex-direction: column; background: var(--_d-sab, none); border: var(--_d-sar, 0) solid var(--basalt-diagram-structure); border-radius: var(--basalt-radius-md); padding: var(--_d-sap, 0); } + .basalt-diagram-story-steps { display: flex; flex-wrap: wrap; align-content: start; gap: var(--basalt-space-1-5); margin-block-start: var(--_d-ssm, 0); --_d-ssm: var(--_drawn) var(--basalt-space-2); } + .basalt-diagram-story-step { padding: var(--basalt-space-1-5) var(--basalt-space-2-5); background: var(--_surface, var(--basalt-surface-1)); border: var(--basalt-size-hairline) solid var(--basalt-border-rim); border-radius: var(--basalt-radius-sm); color: var(--basalt-text-primary); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); } + .basalt-diagram-story-slice { --_d-ss: var(--_drawn) contents; display: var(--_d-ss, flex); flex-direction: column; gap: var(--basalt-space-2); } + .basalt-diagram-story-slice-head { --_d-shc: var(--_drawn) 1; --_d-shd: var(--_drawn) column; grid-column: var(--_d-shc, auto); grid-row: var(--_r); display: flex; flex-direction: var(--_d-shd, row); flex-wrap: wrap; align-items: baseline; column-gap: var(--basalt-space-2); padding-block-start: var(--basalt-space-3); } + .basalt-diagram-story-slice-name { 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-sans); } + .basalt-diagram-story-slice[data-below] .basalt-diagram-story-slice-name { color: var(--basalt-text-secondary); font-weight: var(--basalt-font-weight-medium); } + .basalt-diagram-story-count { 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); font-variant-numeric: tabular-nums; } + .basalt-diagram-story-cell { display: flex; flex-direction: column; gap: var(--basalt-space-2); padding-block-start: var(--_d-scp, 0); --_d-scp: var(--_drawn) var(--basalt-space-3); } + .basalt-diagram-story-slot { --_d-sl: var(--_drawn) block; --_d-sls: var(--_drawn) none; margin-block-start: var(--_d-slm, 0); --_d-slm: var(--_drawn) var(--basalt-space-3); padding: var(--_d-slp, 0); --_d-slp: var(--_drawn) var(--basalt-space-2-5) var(--basalt-space-3); border: var(--_d-slb, 0) dashed var(--basalt-diagram-structure); --_d-slb: var(--_drawn) var(--basalt-size-hairline); border-radius: var(--basalt-radius-md); } + .basalt-diagram-story-slot > .basalt-diagram-empty { --_d-sle: var(--_drawn) inline; display: var(--_d-sle, none); } + .basalt-diagram-story-left-out { --_d-slo: var(--_drawn) none; display: var(--_d-slo, inline); 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-story-of { --_d-so: var(--_drawn) none; display: var(--_d-so, inline); } + .basalt-diagram-story-of + .basalt-diagram-story-code::before { --_d-sc: var(--_drawn) ""; content: var(--_d-sc, " · "); } + .basalt-diagram-story-cut { grid-column: 1 / -1; grid-row: var(--_r); display: flex; align-items: center; gap: var(--basalt-space-3); padding-block: var(--basalt-space-2); } + .basalt-diagram-story-cut-name { flex: none; 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-sans); white-space: nowrap; } + .basalt-diagram-story-cut-line { flex: 1 1 auto; height: 0; border-block-start: var(--basalt-size-chart-line) solid var(--basalt-diagram-edge-main); } + + /* Before script (1.0): stacked unless the figure is at least the label column plus size-diagram-node a track plus the gaps (never under 640); more than + six columns is stacked until script. */ + /* stylelint-disable-next-line basalt/container-length -- size-breakpoint-container-lg (640px), the floor of every least width: a kanban up to 4 columns, the others up to 3 */ + @container (width >= 640px) { .basalt-diagram:not([data-layout]):is([data-type="kanban"]:is([data-cols="1"], [data-cols="2"], [data-cols="3"], [data-cols="4"]), :is([data-type="journey"], [data-type="service-blueprint"], [data-type="story-map"]):is([data-cols="1"], [data-cols="2"], [data-cols="3"])) > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- 5 × size-diagram-node + 4 × space-4, a kanban of five columns */ + @container (width >= 784px) { .basalt-diagram:not([data-layout])[data-type="kanban"][data-cols="5"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- size-diagram-lane + space-4 + 4 × size-diagram-node + 3 × space-4 */ + @container (width >= 760px) { .basalt-diagram:not([data-layout]):is([data-type="journey"], [data-type="service-blueprint"], [data-type="story-map"])[data-cols="4"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- size-diagram-lane + space-4 + 5 × size-diagram-node + 4 × space-4; and a kanban of six */ + @container (width >= 920px) { .basalt-diagram:not([data-layout]):is([data-type="journey"], [data-type="service-blueprint"], [data-type="story-map"])[data-cols="5"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- 6 × size-diagram-node + 5 × space-4, a kanban of six columns */ + @container (width >= 944px) { .basalt-diagram:not([data-layout])[data-type="kanban"][data-cols="6"] > .basalt-diagram-drawing { --_drawn: ; } } + /* stylelint-disable-next-line basalt/container-length -- size-diagram-lane + space-4 + 6 × size-diagram-node + 5 × space-4 */ + @container (width >= 1080px) { .basalt-diagram:not([data-layout]):is([data-type="journey"], [data-type="service-blueprint"], [data-type="story-map"])[data-cols="6"] > .basalt-diagram-drawing { --_drawn: ; } } + + @media (prefers-contrast: more) { + .basalt-diagram-journey-grid { stroke: var(--basalt-border-input); } + } + @media (forced-colors: active) { + .basalt-diagram-journey-grid { display: none; } + .basalt-diagram :is(.basalt-diagram-journey-line) { stroke: CanvasText; } + .basalt-diagram .basalt-diagram-journey-disc { fill: CanvasText; } + .basalt-diagram .basalt-diagram-journey-cut { fill: Canvas; } + .basalt-diagram .basalt-diagram-bp-rule-line > line { stroke: GrayText; } + .basalt-diagram .basalt-diagram-bp-rule[data-rule="visibility"] .basalt-diagram-bp-rule-line > line { stroke: CanvasText; } + .basalt-diagram .basalt-diagram-bp-rule-line { forced-color-adjust: none; } + .basalt-diagram .basalt-diagram-story-cut-line, .basalt-diagram .basalt-diagram-kanban-col[data-over] > .basalt-diagram-kanban-head { border-color: CanvasText; } + .basalt-diagram .basalt-diagram-kanban-card[data-blocked] { border-color: CanvasText; } + .basalt-diagram .basalt-diagram-story-slot { border-color: GrayText; } + .basalt-diagram :is(.basalt-diagram-swatch-rule, .basalt-diagram-swatch-contour, .basalt-diagram-swatch-blocked) { stroke: CanvasText; } + .basalt-diagram :is(.basalt-diagram-swatch-dash, .basalt-diagram-swatch-slot) { stroke: GrayText; } + } + @media print { + .basalt-diagram :is(.basalt-diagram-bp-rule-line, .basalt-diagram-story-cut-line, .basalt-diagram-kanban-head) { -webkit-print-color-adjust: exact; print-color-adjust: exact; } + } + + /* ---- Diagram timeline (DECISIONS 359, Ops 2): points on one true scale, its own module (diagram-timeline.ts; the skill's diagram-timeline) ---- + Drawn, the cards are placed by the layout (--_tx, --_ty, one width --_tw) in a drawing --_th tall and --_tdw wide on the start edge; the axis, ticks, + breaks, stems and dots are the ink's, every one an SVG stroke or fill set by hand so forced colours keeps it. Stacked (until script, and wherever an + event has no seat): one column on a rail, cards indented space-8, a break a row of its words. The implementation has not been reviewed. */ + .basalt-diagram[data-type="timeline"] > .basalt-diagram-drawing { --_d-td: var(--_drawn) block; display: var(--_d-td, flex); flex-direction: column; gap: var(--basalt-space-3); } + .basalt-diagram[data-type="timeline"][data-layout="drawn"] > .basalt-diagram-drawing { height: var(--_th); max-width: var(--_tdw, none); } + .basalt-diagram-tl-card { margin-inline-start: var(--_d-tm, var(--basalt-space-8)); --_d-tm: var(--_drawn) 0; } + .basalt-diagram[data-type="timeline"][data-layout="drawn"] .basalt-diagram-tl-card { position: absolute; left: var(--_tx, 0); top: var(--_ty, 0); width: var(--_tw); } + .basalt-diagram-tl-line { white-space: nowrap; } + .basalt-diagram-node[data-focal] :is(.basalt-diagram-tl-time, .basalt-diagram-tl-gap) { color: var(--basalt-diagram-focal-ink); } + .basalt-diagram-tl-time { color: var(--basalt-text-secondary); font-family: var(--basalt-font-family-sans); font-weight: var(--basalt-font-weight-medium); font-variant-numeric: tabular-nums; } + .basalt-diagram-tl-gap { --_d-tg: var(--_drawn) none; display: var(--_d-tg, inline); color: var(--basalt-text-tertiary); font-family: var(--basalt-font-family-sans); font-variant-numeric: tabular-nums; } + .basalt-diagram-tl-break { --_d-tb: var(--_drawn) none; display: var(--_d-tb, flex); align-items: center; gap: var(--basalt-space-2); margin: 0; margin-inline: var(--basalt-space-8) 0; } + .basalt-diagram-tl-break::after { content: ""; flex: 1 1 auto; border-block-start: var(--basalt-size-hairline) dashed var(--basalt-diagram-structure); } + .basalt-diagram-tl-break-words { flex: none; 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-sans); font-variant-numeric: tabular-nums; } + .basalt-diagram :is(.basalt-diagram-tl-axis, .basalt-diagram-tl-tick, .basalt-diagram-tl-stem) { fill: none; stroke: var(--basalt-diagram-structure); stroke-width: var(--basalt-size-hairline); transition: stroke var(--basalt-duration-fast) var(--basalt-ease-out); } + .basalt-diagram .basalt-diagram-tl-slash { fill: none; stroke: var(--basalt-diagram-edge); stroke-width: var(--basalt-size-hairline); stroke-linecap: round; } + .basalt-diagram .basalt-diagram-tl-dot { fill: var(--basalt-diagram-edge); transition: fill var(--basalt-duration-fast) var(--basalt-ease-out); } + /* Hover or focus lifts a card's own stem and dot; nothing dims, because nothing else is related. */ + .basalt-diagram .basalt-diagram-tl-stem[data-lit] { stroke: var(--basalt-diagram-edge-main); } + .basalt-diagram .basalt-diagram-tl-dot[data-lit] { fill: var(--basalt-diagram-edge-main); } + text.basalt-diagram-tl-tick-text { fill: var(--basalt-chart-axis); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); font-variant-numeric: tabular-nums; } + text.basalt-diagram-tl-break-text { fill: 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-sans); font-variant-numeric: tabular-nums; } + /* The ink's words are placed by their anchors in left-to-right coordinates: set left to right, so a figure right to left keeps "31 min · soak" in order. */ + :is(text.basalt-diagram-tl-tick-text, text.basalt-diagram-tl-break-text, text.basalt-diagram-tl-zone, text.basalt-diagram-gantt-tick, text.basalt-diagram-gantt-today) { direction: ltr; } + text.basalt-diagram-tl-zone { fill: 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); } + @media (prefers-reduced-motion: reduce) { .basalt-diagram :is(.basalt-diagram-tl-stem, .basalt-diagram-tl-dot) { transition: none; } } + @media (forced-colors: active) { + .basalt-diagram :is(.basalt-diagram-tl-axis, .basalt-diagram-tl-tick, .basalt-diagram-tl-stem, .basalt-diagram-tl-slash) { stroke: CanvasText; } + .basalt-diagram .basalt-diagram-tl-dot { fill: CanvasText; } + .basalt-diagram .basalt-diagram-tl-stem[data-lit] { stroke: Highlight; } + .basalt-diagram .basalt-diagram-tl-dot[data-lit] { fill: Highlight; } + .basalt-diagram :is(text.basalt-diagram-tl-tick-text, text.basalt-diagram-tl-break-text, text.basalt-diagram-tl-zone) { fill: CanvasText; } + .basalt-diagram .basalt-diagram-tl-break::after { border-color: CanvasText; } + } + + /* ---- Diagram schedule (DECISIONS 359, Planning 1.6): its own module (diagram-schedule.ts; the skill's diagram-schedule). The implementation has not been reviewed. ---- + /* A schedule (DECISIONS 359, Planning 1.6): the architecture's grid, columns space-16 apart and rows space-8. A task card's contour is its kind, drawn + inside the card's box (1px diagram-structure with float, 2px diagram-edge-main critical), so every card's cells sit on the same lines. */ + .basalt-diagram[data-type="schedule"] > .basalt-diagram-drawing { --_row-gap: var(--basalt-space-8); --_col-gap: var(--basalt-space-16); } + .basalt-diagram[data-type="schedule"] .basalt-diagram-node { padding: 0; border-color: transparent; font-variant-numeric: tabular-nums; } + .basalt-diagram-sched-contour { position: absolute; inset: calc(-1 * var(--basalt-size-hairline)); border: var(--basalt-size-hairline) solid var(--basalt-diagram-structure); border-radius: inherit; pointer-events: none; } + .basalt-diagram-sched-contour[data-critical] { border: var(--basalt-size-chart-line) solid var(--basalt-diagram-edge-main); } + .basalt-diagram-node[data-focal] > .basalt-diagram-sched-contour { border-color: var(--basalt-diagram-focal); } + .basalt-diagram-node[data-near]:not([data-focal]) > .basalt-diagram-sched-contour:not([data-critical]) { border-color: var(--basalt-border-hover); } + .basalt-diagram-sched-head { display: flex; flex-direction: column; gap: var(--basalt-space-0-5); padding: var(--basalt-space-2) var(--basalt-space-3); border-block-end: var(--basalt-size-hairline) solid var(--basalt-border-divider); } + .basalt-diagram-sched-head > .basalt-diagram-kind { display: flex; gap: var(--basalt-space-2); } + .basalt-diagram-sched-dur { margin-inline-start: auto; color: var(--basalt-text-secondary); font-family: var(--basalt-font-family-sans); white-space: nowrap; } + .basalt-diagram-sched-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-block-end: var(--basalt-size-hairline) solid var(--basalt-border-divider); } + .basalt-diagram-sched-cell { display: flex; align-items: baseline; justify-content: space-between; gap: var(--basalt-space-1-5); padding: var(--basalt-space-1-5) var(--basalt-space-3); } + .basalt-diagram-sched-cell:nth-child(2n) { border-inline-start: var(--basalt-size-hairline) solid var(--basalt-border-divider); } + .basalt-diagram-sched-cell:nth-child(n + 3) { border-block-start: var(--basalt-size-hairline) solid var(--basalt-border-divider); } + .basalt-diagram-sched-k { 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-sched-v { color: var(--basalt-text-primary); font: var(--basalt-font-weight-medium) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-sans); } + .basalt-diagram-sched-foot { display: flex; align-items: baseline; justify-content: space-between; gap: var(--basalt-space-2); padding: var(--basalt-space-1-5) 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-sans); } + .basalt-diagram-sched-critical { color: var(--basalt-text-primary); font-weight: var(--basalt-font-weight-semibold); } + .basalt-diagram-sched-after { --_d-sa: var(--_drawn) none; display: var(--_d-sa, block); padding: var(--basalt-space-1-5) var(--basalt-space-3); border-block-start: var(--basalt-size-hairline) solid var(--basalt-border-divider); 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-sans); } + .basalt-diagram-node[data-focal] :is(.basalt-diagram-sched-head, .basalt-diagram-sched-grid, .basalt-diagram-sched-cell, .basalt-diagram-sched-after) { border-color: var(--basalt-diagram-focal-rule); } + .basalt-diagram-node[data-focal] :is(.basalt-diagram-sched-dur, .basalt-diagram-sched-k, .basalt-diagram-sched-v, .basalt-diagram-sched-foot, .basalt-diagram-sched-critical, .basalt-diagram-sched-after) { color: var(--basalt-diagram-focal-ink); } + .basalt-diagram-node[data-focal] :is(.basalt-diagram-sched-dur, .basalt-diagram-sched-k, .basalt-diagram-sched-foot, .basalt-diagram-sched-after) { opacity: var(--basalt-opacity-amount); } + .basalt-diagram .basalt-diagram-swatch-task { fill: none; stroke: var(--basalt-diagram-structure); stroke-width: var(--basalt-size-hairline); } + .basalt-diagram .basalt-diagram-swatch-task[data-critical] { stroke: var(--basalt-diagram-edge-main); stroke-width: var(--basalt-size-chart-line); } + @media (prefers-contrast: more) { .basalt-diagram-node[data-focal] :is(.basalt-diagram-sched-dur, .basalt-diagram-sched-k, .basalt-diagram-sched-foot, .basalt-diagram-sched-after) { opacity: 1; } } + @media (forced-colors: active) { + .basalt-diagram-sched-contour { border-color: CanvasText; } + .basalt-diagram .basalt-diagram-swatch-task { stroke: CanvasText; } + } + + + /* ---- Diagram state (DECISIONS 359, Ops 1): its own module (diagram-state.ts; the skill's diagram-state). The implementation has not been reviewed. ---- + /* A state (DECISIONS 359, Ops 1): the architecture's card and group, columns space-16 plus space-4 apart and rows space-16. The start is a plain line from a + size-diagram-head dot, space-10 long, all diagram-edge (the ink's); a final state carries a space-3-5 ring and dot in its top end corner; entry and exit + actions sit under a hairline rule. Stacked, the start mark has its own space-8: under a group's label, or above a card outside a group. */ + .basalt-diagram[data-type="state"] > .basalt-diagram-drawing { --_row-gap: var(--basalt-space-16); --_col-gap: calc(var(--basalt-space-16) + var(--basalt-space-4)); } + /* A composite's start mark stands above its initial state in every layout (the decider's ruling on the gap), and its room is new room: on the figure's + first row the box reaches space-10 higher (the drawing's top edge keeps it); on a later row every card of the row stands space-10 lower, so the gap + above it is space-16 plus space-10 and the box keeps its plain space-8 above the row. */ + .basalt-diagram-gbox[data-start="top"] { margin-block-start: calc(-1 * var(--_gt, 1) * var(--basalt-space-8) - var(--basalt-space-10)); } + .basalt-diagram[data-type="state"][data-layout="drawn"] .basalt-diagram-node[data-room] { margin-block-start: var(--basalt-space-10); } + .basalt-diagram-group[data-start] { padding-block-start: var(--basalt-space-16); } + .basalt-diagram[data-type="state"] > .basalt-diagram-drawing > .basalt-diagram-node[data-initial] { margin-block-start: var(--_d-mt, calc(var(--_gap, var(--basalt-space-0)) + var(--basalt-space-8))); } + .basalt-diagram .basalt-diagram-start-dot, .basalt-diagram .basalt-diagram-start-tip { fill: var(--basalt-diagram-edge); } + .basalt-diagram .basalt-diagram-start-line { fill: none; stroke: var(--basalt-diagram-edge); stroke-width: var(--basalt-size-hairline); } + .basalt-diagram-node > .basalt-diagram-final { position: absolute; inset-block-start: var(--basalt-space-2-5); inset-inline-end: var(--basalt-space-3); width: var(--basalt-space-3-5); height: var(--basalt-space-3-5); } + .basalt-diagram .basalt-diagram-final circle { fill: none; stroke: var(--basalt-diagram-edge-main); stroke-width: var(--basalt-size-hairline); } + .basalt-diagram .basalt-diagram-final circle[data-dot] { fill: var(--basalt-diagram-edge-main); stroke: none; } + .basalt-diagram-node[data-focal] > .basalt-diagram-final circle { stroke: var(--basalt-diagram-focal-ink); } + .basalt-diagram-node[data-focal] > .basalt-diagram-final circle[data-dot] { fill: var(--basalt-diagram-focal-ink); } + .basalt-diagram-node[data-final] > :is(.basalt-diagram-kind, .basalt-diagram-name):first-child { padding-inline-end: var(--basalt-space-6); } + .basalt-diagram-actions { display: flex; flex-direction: column; gap: var(--basalt-space-0-5); margin-block-start: var(--basalt-space-2); padding-block-start: var(--basalt-space-1-5); border-block-start: var(--basalt-size-hairline) solid var(--basalt-border-divider); 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); } + .basalt-diagram-node[data-focal] > .basalt-diagram-actions { border-color: var(--basalt-diagram-focal-rule); color: var(--basalt-diagram-focal-ink); } + .basalt-diagram-key-letters[data-numbers] { font-family: var(--basalt-font-family-mono); } + @media (forced-colors: active) { + .basalt-diagram :is(.basalt-diagram-start-dot, .basalt-diagram-start-tip) { fill: CanvasText; } + .basalt-diagram .basalt-diagram-start-line { stroke: CanvasText; } + .basalt-diagram .basalt-diagram-final { forced-color-adjust: none; } + .basalt-diagram .basalt-diagram-final circle { stroke: CanvasText; } + .basalt-diagram .basalt-diagram-final circle[data-dot] { fill: CanvasText; } + .basalt-diagram .basalt-diagram-node[data-focal] > .basalt-diagram-final circle { stroke: Canvas; } + .basalt-diagram .basalt-diagram-node[data-focal] > .basalt-diagram-final circle[data-dot] { fill: Canvas; } + } + @media print { .basalt-diagram .basalt-diagram-final, .basalt-diagram .basalt-diagram-start { -webkit-print-color-adjust: exact; print-color-adjust: exact; } } + + + /* ---- Diagram deployment (DECISIONS 359, Ops 3): its own module (diagram-deployment.ts; the skill's diagram-deployment). The implementation has not been reviewed. ---- + /* A deployment (Ops 3): columns space-16 twice apart, so a protocol label of twelve characters seats on a level run. A host with artifacts is the node with + no padding: a header band, then a row an artifact (Mono, the name primary and its detail tertiary), as a schema's table is. */ + .basalt-diagram[data-type="deployment"] > .basalt-diagram-drawing { --_col-gap: calc(2 * var(--basalt-space-16)); } + .basalt-diagram-node[data-rows] { padding: 0; } + .basalt-diagram-host-head { display: flex; flex-direction: column; padding: var(--basalt-space-2) var(--basalt-space-3); border-block-end: var(--basalt-size-hairline) solid var(--basalt-border-divider); } + .basalt-diagram-node[data-focal] .basalt-diagram-host-head { border-color: var(--basalt-diagram-focal-rule); } + .basalt-diagram-host-head > .basalt-diagram-detail { margin-block-start: var(--basalt-space-0-5); } + .basalt-diagram-host-rows { display: flex; flex-direction: column; padding-block: var(--basalt-space-1); } + .basalt-diagram-artifact { box-sizing: border-box; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--basalt-space-2); min-height: var(--basalt-size-control-sm); padding: var(--basalt-space-1-5) var(--basalt-space-3); font: var(--basalt-font-weight-regular) var(--basalt-text-xs-size) / var(--basalt-text-xs-line-height) var(--basalt-font-family-mono); } + .basalt-diagram-artifact-name { color: var(--basalt-text-primary); } + .basalt-diagram-artifact-detail { color: var(--basalt-text-tertiary); } + .basalt-diagram-node[data-focal] :is(.basalt-diagram-artifact-name, .basalt-diagram-artifact-detail) { color: var(--basalt-diagram-focal-ink); } + .basalt-diagram-replicas { margin-inline-start: var(--basalt-space-2); color: var(--basalt-text-secondary); font-family: var(--basalt-font-family-sans); font-weight: var(--basalt-font-weight-medium); font-variant-numeric: tabular-nums; white-space: nowrap; } + .basalt-diagram-node[data-focal] .basalt-diagram-replicas { color: var(--basalt-diagram-focal-ink); } + .basalt-diagram-key-letters[data-replicas] { font-family: var(--basalt-font-family-sans); font-weight: var(--basalt-font-weight-medium); font-variant-numeric: tabular-nums; } + /* ---- 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 c7936542b80aacd1e8fcce06808795cd6aeb3811 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:17 -0600 Subject: [PATCH 09/12] Skill: the type modules diagram-scale, diagram-gantt, diagram-matrix, diagram-timeline, diagram-schedule, diagram-state and diagram-deployment A page pays for the types it draws: the diagram module grows 7.2 KB (+4.8%). Budgets set with their reasons in modules.json (soft). Co-Authored-By: Claude Opus 5.5 --- .agent/skills/basalt-html/SKILL.md | 7 + .agent/skills/basalt-html/compose.mjs | 7 +- .../basalt-html/parts/diagram-deployment.css | 1 + .../basalt-html/parts/diagram-deployment.js | 1 + .../basalt-html/parts/diagram-gantt.css | 1 + .../skills/basalt-html/parts/diagram-gantt.js | 1 + .../basalt-html/parts/diagram-matrix.css | 1 + .../basalt-html/parts/diagram-matrix.js | 1 + .../basalt-html/parts/diagram-place.mjs | 27 +- .../skills/basalt-html/parts/diagram-scale.js | 1 + .../basalt-html/parts/diagram-schedule.css | 1 + .../basalt-html/parts/diagram-schedule.js | 1 + .../basalt-html/parts/diagram-state.css | 1 + .../skills/basalt-html/parts/diagram-state.js | 2 + .../basalt-html/parts/diagram-timeline.css | 1 + .../basalt-html/parts/diagram-timeline.js | 1 + .agent/skills/basalt-html/parts/diagram.css | 2 +- .agent/skills/basalt-html/parts/diagram.js | 12 +- .agent/skills/basalt-html/parts/manifest.json | 265 +++++++++++++++++- .../parts/usage/diagram-deployment.md | 4 + .../basalt-html/parts/usage/diagram-gantt.md | 15 + .../basalt-html/parts/usage/diagram-matrix.md | 10 + .../basalt-html/parts/usage/diagram-scale.md | 4 + .../parts/usage/diagram-schedule.md | 5 + .../basalt-html/parts/usage/diagram-state.md | 6 + .../parts/usage/diagram-timeline.md | 9 + .../skills/basalt-html/parts/usage/diagram.md | 1 + tools/html-skill/build.mjs | 41 ++- tools/html-skill/src/compose.mjs | 7 +- tools/html-skill/src/modules.json | 265 +++++++++++++++++- .../src/modules/diagram-deployment.js | 10 + tools/html-skill/src/modules/diagram-gantt.js | 11 + .../html-skill/src/modules/diagram-matrix.js | 15 + tools/html-skill/src/modules/diagram-scale.js | 10 + .../src/modules/diagram-schedule.js | 10 + tools/html-skill/src/modules/diagram-state.js | 10 + .../src/modules/diagram-timeline.js | 11 + tools/html-skill/src/modules/diagram.js | 23 +- .../src/usage/diagram-deployment.md | 4 + tools/html-skill/src/usage/diagram-gantt.md | 15 + tools/html-skill/src/usage/diagram-matrix.md | 10 + tools/html-skill/src/usage/diagram-scale.md | 4 + .../html-skill/src/usage/diagram-schedule.md | 5 + tools/html-skill/src/usage/diagram-state.md | 6 + .../html-skill/src/usage/diagram-timeline.md | 9 + tools/html-skill/src/usage/diagram.md | 1 + 46 files changed, 813 insertions(+), 42 deletions(-) create mode 100644 .agent/skills/basalt-html/parts/diagram-deployment.css create mode 100644 .agent/skills/basalt-html/parts/diagram-deployment.js create mode 100644 .agent/skills/basalt-html/parts/diagram-gantt.css create mode 100644 .agent/skills/basalt-html/parts/diagram-gantt.js create mode 100644 .agent/skills/basalt-html/parts/diagram-matrix.css create mode 100644 .agent/skills/basalt-html/parts/diagram-matrix.js create mode 100644 .agent/skills/basalt-html/parts/diagram-scale.js create mode 100644 .agent/skills/basalt-html/parts/diagram-schedule.css create mode 100644 .agent/skills/basalt-html/parts/diagram-schedule.js create mode 100644 .agent/skills/basalt-html/parts/diagram-state.css create mode 100644 .agent/skills/basalt-html/parts/diagram-state.js create mode 100644 .agent/skills/basalt-html/parts/diagram-timeline.css create mode 100644 .agent/skills/basalt-html/parts/diagram-timeline.js create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-deployment.md create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-gantt.md create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-matrix.md create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-scale.md create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-schedule.md create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-state.md create mode 100644 .agent/skills/basalt-html/parts/usage/diagram-timeline.md create mode 100644 tools/html-skill/src/modules/diagram-deployment.js create mode 100644 tools/html-skill/src/modules/diagram-gantt.js create mode 100644 tools/html-skill/src/modules/diagram-matrix.js create mode 100644 tools/html-skill/src/modules/diagram-scale.js create mode 100644 tools/html-skill/src/modules/diagram-schedule.js create mode 100644 tools/html-skill/src/modules/diagram-state.js create mode 100644 tools/html-skill/src/modules/diagram-timeline.js create mode 100644 tools/html-skill/src/usage/diagram-deployment.md create mode 100644 tools/html-skill/src/usage/diagram-gantt.md create mode 100644 tools/html-skill/src/usage/diagram-matrix.md create mode 100644 tools/html-skill/src/usage/diagram-scale.md create mode 100644 tools/html-skill/src/usage/diagram-schedule.md create mode 100644 tools/html-skill/src/usage/diagram-state.md create mode 100644 tools/html-skill/src/usage/diagram-timeline.md diff --git a/.agent/skills/basalt-html/SKILL.md b/.agent/skills/basalt-html/SKILL.md index b2668f8f..6a525739 100644 --- a/.agent/skills/basalt-html/SKILL.md +++ b/.agent/skills/basalt-html/SKILL.md @@ -70,6 +70,13 @@ Markup your script builds (a `.row`) isn't seen: add `` - **diagram-zoom** `.diagram`: added for you, with `dialog`; `"zoom": false` drops Expand. - **diagram-export** `"export": true`: added for you; SVG and PNG downloads in the foot. - **diagram-text** `"variant": "text"`: added for you; a sequence in box-drawing art, else its transcript. +- **diagram-scale** `"type": "gantt"`: added for you with a gantt or a timeline; arithmetic only. +- **diagram-gantt** `"type": "gantt"`: added for you; no dependency lines (`after` is written in the row), a bar never widened. +- **diagram-matrix** `"type": "kanban"`: added for you (and journey, service-blueprint, story-map); read-only, an empty cell in words. +- **diagram-timeline** `"type": "timeline"`: added for you; `at` is an instant with its offset, breaks are yours alone. +- **diagram-schedule** `"type": "schedule"`: added for you; write durations and `after`, never a number. +- **diagram-state** `"type": "state"`: added for you; `event`, `guard`, `action`, never a `label`. +- **diagram-deployment** `"type": "deployment"`: added for you; `environment` is required, artifacts are rows. - **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 a1b2acef..4c0fa8a4 100644 --- a/.agent/skills/basalt-html/compose.mjs +++ b/.agent/skills/basalt-html/compose.mjs @@ -692,7 +692,7 @@ function writeDiagrams(markup, held, parts, notes, marks) { // 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)) { + if (spec && spec.layout === "auto" && !spec.placement && ["architecture", "flowchart", "schema", "state", "deployment", "schedule"].includes(spec.type)) { try { spec.placement = placeNow(parts, spec); const inner = `\n${JSON.stringify(spec).replace(/ x } } }, console: { warn() {}, error() {}, log() {} } }; - vm.runInNewContext(read(parts, "diagram.js"), context); + // The type modules (DECISIONS 359) register their types with the diagram module, so their figures' words are written here too. + const ctx = vm.createContext(context); + for (const name of ["diagram-scale", "diagram-gantt", "diagram-matrix", "diagram-timeline", "diagram-schedule", "diagram-state", "diagram-deployment"]) if (exists(parts, `${name}.js`)) vm.runInContext(read(parts, `${name}.js`), ctx); + vm.runInContext(read(parts, "diagram.js"), ctx); engine = context.window.Basalt._.diagramMarkup; } let made; diff --git a/.agent/skills/basalt-html/parts/diagram-deployment.css b/.agent/skills/basalt-html/parts/diagram-deployment.css new file mode 100644 index 00000000..2427b7ed --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-deployment.css @@ -0,0 +1 @@ +@layer basalt{.diagram[data-type=deployment]>.diagram-drawing{--_col-gap: calc(2 * var(--basalt-space-16))}.diagram-node[data-rows]{padding:0}.diagram-host-head{display:flex;flex-direction:column;padding:var(--basalt-space-2) var(--basalt-space-3);border-block-end:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-node[data-focal] .diagram-host-head{border-color:var(--basalt-diagram-focal-rule)}.diagram-host-head>.diagram-detail{margin-block-start:var(--basalt-space-0-5)}.diagram-host-rows{display:flex;flex-direction:column;padding-block:var(--basalt-space-1)}.diagram-artifact{box-sizing:border-box;display:flex;flex-wrap:wrap;align-items:baseline;column-gap:var(--basalt-space-2);min-height:var(--basalt-size-control-sm);padding:var(--basalt-space-1-5) var(--basalt-space-3);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-artifact-name{color:var(--basalt-text-primary)}.diagram-artifact-detail{color:var(--basalt-text-tertiary)}.diagram-node[data-focal] :is(.diagram-artifact-name,.diagram-artifact-detail){color:var(--basalt-diagram-focal-ink)}.diagram-replicas{margin-inline-start:var(--basalt-space-2);color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-sans);font-weight:var(--basalt-font-weight-medium);font-variant-numeric:tabular-nums;white-space:nowrap}.diagram-node[data-focal] .diagram-replicas{color:var(--basalt-diagram-focal-ink)}.diagram-key-letters[data-replicas]{font-family:var(--basalt-font-family-sans);font-weight:var(--basalt-font-weight-medium);font-variant-numeric:tabular-nums}} diff --git a/.agent/skills/basalt-html/parts/diagram-deployment.js b/.agent/skills/basalt-html/parts/diagram-deployment.js new file mode 100644 index 00000000..bb136d1f --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-deployment.js @@ -0,0 +1 @@ +(()=>{var m=a=>a==null||a===""?void 0:String(a);function i(a,s,...t){const n=[];for(const r of t.flat(1/0))r!=null&&r!==!1&&!Array.isArray(r)&&n.push(r);return{t:a,a:s??{},c:n}}var l=a=>i("bdi",null,a);function $(a,s){if(!s.href)return l(s.name);const t=s.name.trimEnd().lastIndexOf(" ");return[t<0?"":s.name.slice(0,t+1),i("span",{class:`${a}-name-end`},t<0?s.name:s.name.slice(t+1))]}function v(a,s,t){if(t.shape==="decision")return[i("span",{class:`${a}-words`},s.type==="data-flow"&&t.kind?i("span",{class:`${a}-kind`},l(t.kind)):null,i("span",{class:`${a}-name`},$(a,t)))];const n=[];return s.type==="data-flow"?n.push(i("span",{class:`${a}-kind`},l(t.kind),i("span",{class:`${a}-lane-word`}," · ",l(t.laneLabel??"")))):t.kind&&n.push(i("span",{class:`${a}-kind`},l(t.kind))),n.push(i("span",{class:`${a}-name`},$(a,t))),t.detail&&n.push(i("span",{class:`${a}-detail`,"data-mono":t.mono?"":void 0},t.mono?i("span",{class:`${a}-runs`},w(t.detail).flatMap((r,e)=>[e?" ":"",i("span",{class:`${a}-run`},r)])):l(t.detail))),n}var w=a=>a?a.split(/\s+/).filter(Boolean):[];function k(a,s){const{dev:t,error:n,warn:r}=s;t&&!m(a.environment)&&n("a deployment needs its environment: one environment a figure, the first words of its source line");const e=Array.isArray(a.nodes)?a.nodes:[],d=Array.isArray(a.groups)?a.groups:[],g=new Map(d.map(o=>[String(o.id),o.parent?String(o.parent):void 0])),p=d.map(o=>{const c=o.parent?String(o.parent):void 0;return c&&g.get(c)?(t&&n(`the group "${o.label}" is a third level: a deployment's third level is not drawn in this build, so it is a group of the top level`),{...o,parent:void 0}):o}),f=new Map,M=new Set(e.map(o=>String(o.id)));for(const o of e)for(const c of Array.isArray(o.artifacts)?o.artifacts:[])t&&(M.has(String(c.id))||f.has(String(c.id)))&&n(`the id "${String(c.id)}" is used twice (ids are unique across hosts and artifacts)`),f.set(String(c.id),String(o.id));const _=(Array.isArray(a.edges)?a.edges:[]).map(o=>{const c=String(o.from??""),u=String(o.to??"");return t&&!m(o.label)&&r(`the line from ${c} to ${u} has no label: a deployment's line says what it carries`),{...o,from:f.get(c)??c,to:f.get(u)??u,fromArtifact:f.has(c)?c:void 0,toArtifact:f.has(u)?u:void 0}});return{...a,groups:p,edges:_}}function A(a,s,t){a.plan={environment:m(s.environment)};for(const r of s.nodes??[]){const e=a.byId.get(String(r.id));if(!e)continue;const d=r.replicas;e.replicas=d==null?void 0:typeof d=="number"&&Number.isInteger(d)&&d>=1?d:(t.dev&&t.error(`${e.id}'s replicas is ${JSON.stringify(d)}, not a whole number: words such as "1 writer, 1 reader" are the detail's`),void 0);const g=Array.isArray(r.artifacts)?r.artifacts.map(p=>({id:String(p.id??""),name:String(p.name??""),detail:m(p.detail)})):[];e.artifacts=g.length?g:void 0}let n=0;for(const r of s.edges??[]){if(!a.byId.has(String(r.from))||!a.byId.has(String(r.to)))continue;const e=a.edges[n++];e&&(e.fromArtifact=r.fromArtifact,e.toArtifact=r.toArtifact)}}function S(a,s,t){if((t.replicas??0)<2&&!t.artifacts)return v(a,s,t);const r=[i("span",{class:`${a}-kind`},t.kind?l(t.kind):null,(t.replicas??0)>1?i("span",{class:`${a}-replicas`},`× ${t.replicas}`):null),i("span",{class:`${a}-name`},$(a,t)),t.detail?i("span",{class:`${a}-detail`,"data-mono":t.mono?"":void 0},l(t.detail)):null];return t.artifacts?[i("span",{class:`${a}-host-head`},r),i("span",{class:`${a}-host-rows`},t.artifacts.map(e=>i("span",{class:`${a}-artifact`,"data-artifact":e.id},i("span",{class:`${a}-artifact-name`},l(e.name)),e.detail?i("span",{class:`${a}-artifact-detail`},l(e.detail)):null)))]:r}var y=(a,s,t)=>t?a.byId.get(s)?.artifacts?.find(n=>n.id===t)?.name:void 0;function b(a,s,t){const n=e=>i("code",{class:`${a}-code`},l(e)),r=(e,d)=>[i("strong",null,l(s.byId.get(e)?.name??e)),d?[" (",n(d),")"]:""];return[t("Connections"),i("ol",{class:`${a}-list-items`},s.edges.map(e=>i("li",null,r(e.from,y(s,e.from,e.fromArtifact))," to ",r(e.to,y(s,e.to,e.toArtifact)),e.label?[": ",n(e.label.replace(/\n/g," "))]:"",s.legend[e.kind]?` (${s.legend[e.kind]})`:"",".")))]}var h;function I(){return h??(h={type:"deployment",as:"architecture",routed:!0,stop:"a part",prepare:k,adopt:A,card:(a,s,t)=>S(a,s,t),nodeAttrs:(a,s)=>({"data-rows":s.artifacts?"":void 0}),sentenceMore:(a,s)=>[(s.replicas??0)>1?`${s.replicas} copies.`:"",s.artifacts?`Runs ${s.artifacts.map(t=>t.detail?`${t.name} ${t.detail}`:t.name).join(", ")}.`:""].filter(Boolean),keyMore:(a,s)=>s.nodes.some(t=>(t.replicas??0)>1)?[i("li",{class:`${a}-entry`},i("span",{class:`${a}-key-letters`,"data-replicas":"","aria-hidden":"true"},"× 3"),i("span",null,"How many copies run"))]:[],listPart:(a,s,t)=>[(t.replicas??0)>1?` ${t.replicas} copies.`:"",t.artifacts?[" Runs ",t.artifacts.flatMap((n,r)=>[r?", ":"",i("code",{class:`${a}-code`},l(n.name)),n.detail?[" ",l(n.detail)]:""]),"."]:""],listLines:b,sourceLead:a=>a.plan?.environment})}(function(a){"use strict";var s=a._;(s.diagramTypes=s.diagramTypes||{}).deployment=I})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-gantt.css b/.agent/skills/basalt-html/parts/diagram-gantt.css new file mode 100644 index 00000000..cd756ce1 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-gantt.css @@ -0,0 +1 @@ +@layer basalt{.diagram[data-type=gantt]>.diagram-drawing{display:flex;flex-direction:column;gap:0}.diagram[data-type=gantt]>.diagram-drawing>.diagram-ink{z-index:0}.diagram-gantt-axis{--_Ga: var(--_D) grid;display:var(--_Ga, block);grid-template-columns:var(--_name, var(--basalt-size-diagram-table)) minmax(0,1fr);column-gap:var(--basalt-space-4);align-items:end;padding-block-end:var(--basalt-space-2);border-block-end:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram[data-form=words] .diagram-gantt-axis{display:none}.diagram-gantt-corner{--_Gc2: var(--_D) block;display:var(--_Gc2, none);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-gantt-axis>.diagram-gantt-scale{display:block;height:var(--basalt-text-xs-line-height);margin-inline:var(--basalt-space-2)}.diagram-gantt-axis[data-today]>.diagram-gantt-scale{height:calc(2 * var(--basalt-text-xs-line-height) + var(--basalt-space-1))}.diagram-gantt-phase{margin:var(--basalt-space-3) 0 0;padding-block:var(--basalt-space-1);border-block-end:var(--basalt-size-hairline) solid var(--basalt-border-divider);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-node.diagram-gantt-row{--_Gr2: var(--_D) grid;display:var(--_Gr2, flex);flex-direction:column;grid-template-columns:var(--_name, var(--basalt-size-diagram-table)) minmax(0,1fr);column-gap:var(--basalt-space-4);align-items:stretch;align-self:stretch;margin-block-start:0;padding:var(--basalt-space-3) 0;background:none;border:0;border-block-end:var(--basalt-size-hairline) solid var(--basalt-border-divider);border-radius:0}.diagram-node.diagram-gantt-row:focus-visible{outline-offset:calc(-1 * var(--basalt-size-focus-width))}.diagram-node.diagram-gantt-row[data-focal]{background:none;border-color:var(--basalt-border-divider)}.diagram-gantt-row[data-focal] .diagram-name{color:var(--basalt-text-primary);opacity:1}.diagram-gantt-row[data-focal] :is(.diagram-gantt-range,.diagram-gantt-after,.diagram-detail){color:var(--basalt-text-secondary);opacity:1}.diagram-gantt-words{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);min-width:0}.diagram-gantt-words>.diagram-detail{margin-block-start:0}.diagram-gantt-range,.diagram-gantt-after{color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums}.diagram-gantt-now{display:none}.diagram[data-form=words] .diagram-gantt-now{display:inline}.diagram-gantt-track{--_Gth: var(--_D) auto;position:relative;display:block;height:var(--_Gth, var(--basalt-space-8));margin-block-start:var(--_Gtm, var(--basalt-space-2));--_Gtm: var(--_D) 0}.diagram[data-form=words] .diagram-gantt-track{display:none}.diagram-gantt-track>.diagram-gantt-scale{position:absolute;inset-block:0;inset-inline:var(--basalt-space-2)}.diagram-gantt-bar{position:absolute;inset-block-start:calc(50% - var(--basalt-space-2));inset-inline-start:var(--_s);box-sizing:border-box;width:var(--_w);height:var(--basalt-space-4);background:var(--basalt-plate-0);border:var(--basalt-size-hairline) solid var(--basalt-diagram-edge)}.diagram-gantt-mile{position:absolute;inset-block-start:calc(50% - var(--basalt-space-2));inset-inline-start:calc(var(--_s) - var(--basalt-space-2));width:var(--basalt-space-4);height:var(--basalt-space-4)}.diagram-gantt-mile>svg{display:block;width:100%;height:100%;overflow:visible}.diagram-gantt-mile path,.diagram-swatch-bar{fill:var(--basalt-plate-0);stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline)}.diagram-gantt-bar[data-focal]{background:var(--basalt-diagram-focal);border-color:var(--basalt-diagram-focal)}.diagram-gantt-mile[data-focal] path,.diagram-swatch-bar[data-focal]{fill:var(--basalt-diagram-focal);stroke:var(--basalt-diagram-focal)}.diagram-gantt-grid{fill:none;stroke:var(--basalt-chart-grid);stroke-width:var(--basalt-size-hairline)}.diagram-today{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)}text.diagram-gantt-tick{fill:var(--basalt-chart-axis);font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums}text.diagram-gantt-today{fill:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram[data-form=words] .diagram-entry[data-when=tracks]{display:none}@media(prefers-contrast:more){.diagram-gantt-grid{stroke:var(--basalt-border-input)}}@media(forced-colors:active){.diagram-gantt-bar{forced-color-adjust:none;background:Canvas;border-color:CanvasText}.diagram-gantt-bar[data-focal]{background:CanvasText;border-color:CanvasText}.diagram-gantt-mile{forced-color-adjust:none}.diagram-gantt-mile path,.diagram-swatch-bar{fill:Canvas;stroke:CanvasText}.diagram-gantt-mile[data-focal] path,.diagram-swatch-bar[data-focal]{fill:CanvasText;stroke:CanvasText}.diagram-gantt-grid{display:none}.diagram-today{stroke:GrayText}text.diagram-gantt-tick,text.diagram-gantt-today{fill:CanvasText}}@media print{.diagram-gantt-bar,.diagram-gantt-mile{-webkit-print-color-adjust:exact;print-color-adjust:exact}}} diff --git a/.agent/skills/basalt-html/parts/diagram-gantt.js b/.agent/skills/basalt-html/parts/diagram-gantt.js new file mode 100644 index 00000000..db5f3a3a --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-gantt.js @@ -0,0 +1 @@ +(()=>{var W=t=>t==null||t===""?void 0:String(t),it=(t,a)=>t&&Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0,U=t=>{const a=t.trim();return a?/[.!?]$/.test(a)?a:`${a}.`:""};function l(t,a,...s){const i=[];for(const n of s.flat(1/0))n!=null&&n!==!1&&!Array.isArray(n)&&i.push(n);return{t,a:a??{},c:i}}var q=(t,a)=>({width:t,height:a,viewBox:`0 0 ${t} ${a}`,"aria-hidden":"true",focusable:"false"}),A=t=>l("bdi",null,t),Y=(t,a)=>{const s=t.getBoundingClientRect();return{l:s.left-a.left,t:s.top-a.top,r:s.right-a.left,b:s.bottom-a.top}},Z=(...t)=>window.Basalt._.diagramScale.dayNumber(...t),lt=(...t)=>window.Basalt._.diagramScale.scaleMap(...t),dt=(...t)=>window.Basalt._.diagramScale.numberLadder(...t),ct=(...t)=>window.Basalt._.diagramScale.dayLadder(...t),ht=(...t)=>window.Basalt._.diagramScale.ticks(...t),Q=(...t)=>window.Basalt._.diagramScale.dateWords(...t),ft=(...t)=>window.Basalt._.diagramScale.datesWords(...t),R=(...t)=>window.Basalt._.diagramScale.yearOf(...t),mt=(t,a)=>typeof t=="string"?t:a===1?t.one:t.other,x=t=>Math.round(t*100)/100,G=(t,a)=>t.tasks.find(s=>s.id===a)?.name??a;function ut(t,a){const{dev:s,warn:i,error:n}=a,r=t.labels??{},d={task:W(r.task)??"Task",milestone:W(r.milestone)??"Milestone",after:W(r.after)??"After",bar:W(r.bar)??"Task, from its start to its end"},c=Array.isArray(t.tasks)?t.tasks:[],f=(Array.isArray(t.phases)?t.phases:[]).map(e=>({id:String(e.id??""),label:String(e.label??"")})),o=c.length>0&&Z(c[0].start)!==null,g=t.unit,S=o?r.day??{one:"day",other:"days"}:g&&(typeof g=="string"||typeof g=="object"&&g.one&&g.other)?g:"";s&&!o&&c.length&&!g&&i("a numeric gantt has no unit: its lengths are written as bare numbers");const w=(e,u)=>{if(o){const B=Z(e);return B===null?(s&&n(`${u}: ${JSON.stringify(e)} is not a day (YYYY-MM-DD), as the first task's start is`),0):B}const M=typeof e=="number"?e:Number.NaN;return Number.isFinite(M)?M:(s&&n(`${u}: ${JSON.stringify(e)} is not a number, as the first task's start is`),0)},p=c.map((e,u)=>{const M=String(e.id??""),B=!!e.milestone,L=w(e.start,`the start of ${M}`);B&&e.end!==void 0&&e.end!==null&&s&&n(`${M} is a milestone with an end: a milestone has a start alone`);const rt=B?L:e.end===void 0||e.end===null?(s&&n(`${M} has no end: a task has a start and an end, a milestone a start alone`),L):w(e.end,`the end of ${M}`);rte.t.focal).length>1&&i("more than one task is focal: a gantt has one at most");const O=p.length?Math.min(...p.map(e=>o?e.s:e.a)):0,b=p.length?Math.max(...p.map(e=>o?e.last+1:e.b)):1,$=[O,b>O?b:O+1],N=o&&R($[0])!==R($[1]-1),y=e=>Q(e,N),j=e=>o?e.milestone?`${y(e.s)} · ${d.milestone}`:e.s===e.last?y(e.s):new Date(e.s*864e5).getUTCMonth()===new Date(e.last*864e5).getUTCMonth()&&R(e.s)===R(e.last)&&!N?`${y(e.s)} – ${new Date(e.last*864e5).getUTCDate()}`:`${y(e.s)} – ${y(e.last)}`:e.milestone?`${e.s} · ${d.milestone}`:`${e.s} – ${e.last}`,J=e=>{if(e.milestone)return"";const u=o?e.last-e.s+1:x(e.last-e.s);return`${u} ${mt(S,u)}`.trim()},T=p.map(e=>({id:e.id,i:e.i,name:String(e.t.name??""),phase:W(e.t.phase),detail:W(e.t.detail),mono:!!e.t.detailMono,a:e.a,b:e.b,milestone:e.milestone,focal:!!e.t.focal,after:Array.isArray(e.t.after)?e.t.after.map(String):[],range:j(e),length:J(e),href:W(e.t.href),blank:e.t.target==="_blank"}));if(s)for(const e of T)for(const u of e.after){const M=T.find(B=>B.id===u);M?e.au.id===e.phase)&&s&&i(`${e.id} names the phase "${e.phase}", which is not in phases`);const V=T.filter(e=>!e.milestone).map(e=>e.b-e.a),D=V.length?Math.min(...V):1/0,C=t.today,v=C==null?void 0:o?Z(C)??void 0:typeof C=="number"?C:void 0,E=v===void 0?void 0:o?v+.5:v,H=E!==void 0&&E>=$[0]&&E<=$[1]?E:void 0,I=W(t.todayLabel)??"Today",h={days:o,tasks:T,phases:f,domain:$,shortest:D,today:H,todayLabel:I,words:d,years:N,todayWords:H===void 0?void 0:o?Q(Math.floor(H),N):String(H)};s&&$[1]-$[0]>512*D&&i("the plan is more than 512 times its shortest bar, so the gantt is never drawn (only stacked): make the short task a milestone or split the chart");const k=X(h).map((e,u)=>({id:e.id,i:u,name:e.name,mono:!1,focal:e.focal,col:1,row:u+1,row2:u+1,branch:!1,shape:"box",href:e.href,blank:e.blank}));return{nodes:k,edges:[],plan:h,cols:1,rows:Math.max(1,k.length)}}function X(t){return t.phases.length?[...t.phases.flatMap(a=>t.tasks.filter(s=>s.phase===a.id)),...t.tasks.filter(a=>!a.phase||!t.phases.some(s=>s.id===a.phase))]:t.tasks}var _=t=>t.plan,gt=(t,a)=>_(t).tasks.find(s=>s.id===a);function P(t,a){return a.milestone?`${a.range.replace(` · ${t.words.milestone}`,"")}, ${t.words.milestone.toLowerCase()}`:`${a.range.replace(" – "," to ")}, ${a.length}`}function tt(t,a){const s=_(t),i=gt(t,a.id),n=i.phase?s.phases.find(d=>d.id===i.phase)?.label:void 0,r=[`${i.name}${n?`, ${n}`:""}: ${P(s,i)}.`];return i.detail&&r.push(U(i.detail)),i.after.length&&r.push(`${s.words.after} ${i.after.map(d=>G(s,d)).join(", ")}.`),i.focal&&t.legend.focal&&r.push(U(t.legend.focal)),r.join(" ")}function $t(t,a){const s=_(a),i=[],n=(r,d,c={})=>i.push(l("li",{class:`${t}-entry`,...c},r,l("span",null,A(d))));return s.tasks.some(r=>!r.milestone)&&n(l("svg",{class:`${t}-swatch`,...q(24,16)},l("rect",{class:`${t}-swatch-bar`,x:.5,y:4.5,width:23,height:7})),s.words.bar,{"data-when":"tracks"}),s.tasks.some(r=>r.milestone)&&n(l("svg",{class:`${t}-swatch`,...q(16,16)},l("path",{class:`${t}-swatch-bar`,d:"M8 1.5L14.5 8L8 14.5L1.5 8Z"})),s.words.milestone,{"data-when":"tracks"}),s.today!==void 0&&n(l("svg",{class:`${t}-swatch`,...q(16,16)},l("path",{class:`${t}-today`,d:"M8.5 0V16"})),`${s.todayLabel}, ${s.todayWords}`,{"data-when":"tracks"}),s.tasks.some(r=>r.focal)&&a.legend.focal&&n(l("svg",{class:`${t}-swatch`,...q(24,16)},l("rect",{class:`${t}-swatch-bar`,"data-focal":"",x:.5,y:4.5,width:23,height:7})),a.legend.focal,{"data-focal":""}),i.length?l("div",{class:`${t}-key`},l("ul",{class:`${t}-legend`,"aria-label":"Key"},i)):null}function pt(t,a){const s=_(a),i=Math.min(6,a.heading+1),n=c=>l("li",null,l("strong",null,A(c.name)),`: ${P(s,c)}.`,c.detail?[" ",c.mono?l("code",{class:`${t}-code`},c.detail):U(c.detail)]:"",c.after.length?` ${s.words.after} ${c.after.map(f=>G(s,f)).join(", ")}.`:"",c.focal&&a.legend.focal?` ${U(a.legend.focal)}`:"");if(!s.phases.length)return[l("ol",{class:`${t}-list-items`},s.tasks.map(n))];const r=[];for(const c of s.phases){const f=s.tasks.filter(o=>o.phase===c.id);f.length&&r.push(l(`h${i}`,{class:`${t}-list-head`},A(c.label)),l("ol",{class:`${t}-list-items`},f.map(n)))}const d=s.tasks.filter(c=>!c.phase||!s.phases.some(f=>f.id===c.phase));return d.length&&r.push(l("ol",{class:`${t}-list-items`},d.map(n))),r}var F=(t,a)=>(a-t.domain[0])/(t.domain[1]-t.domain[0]);function wt(t,a,s,i){const n=_(a),r=[],d=n.today!==void 0;r.push(l("div",{class:`${t}-gantt-axis`,"data-today":d?"":void 0,"aria-hidden":"true"},l("span",{class:`${t}-gantt-corner`},A(n.words.task)),l("span",{class:`${t}-gantt-scale`})));const c=X(n);let f="\0";for(const o of c){const g=o.phase&&n.phases.some($=>$.id===o.phase)?o.phase:void 0;g!==f&&g&&r.push(l("p",{class:`${t}-gantt-phase`,"aria-hidden":"true"},A(n.phases.find($=>$.id===g).label))),f=g;const S=a.byId.get(o.id),w=!!(s.layout&&!s.bare),p=x(F(n,o.a)*100),O=x(F(n,o.b)*100-F(n,o.a)*100),b=d&&n.today>=o.a&&n.today<=o.b;r.push(l(o.href?"a":"div",{class:`${t}-node ${t}-gantt-row`,href:o.href,target:o.href&&o.blank?"_blank":void 0,rel:o.href&&o.blank?"noopener noreferrer":void 0,"data-link":o.href?o.blank?"external":"":void 0,"data-node":o.id,"data-focal":o.focal?"":void 0,"data-level":i,role:o.href?void 0:"img","aria-label":tt(a,S),tabindex:w?s.stop===o.id?0:-1:s.keep===o.id?-1:void 0},l("span",{class:`${t}-gantt-words`},l("span",{class:`${t}-name`},A(o.name)),l("span",{class:`${t}-gantt-range`},A(o.length?`${o.range} · ${o.length}`:o.range),b?l("span",{class:`${t}-gantt-now`},` · ${n.todayLabel}`):null),o.detail?l("span",{class:`${t}-detail`,"data-mono":o.mono?"":void 0},A(o.detail)):null,o.after.length?l("span",{class:`${t}-gantt-after`},A(`${n.words.after}: ${o.after.map($=>G(n,$)).join(", ")}`)):null),l("span",{class:`${t}-gantt-track`,"aria-hidden":"true"},l("span",{class:`${t}-gantt-scale`},o.milestone?l("span",{class:`${t}-gantt-mile`,"data-focal":o.focal?"":void 0,style:`--_s:${p}%`},l("svg",{...q(16,16)},l("path",{d:"M8 0.5L15.5 8L8 15.5L0.5 8Z"}))):l("span",{class:`${t}-gantt-bar`,"data-focal":o.focal?"":void 0,style:`--_s:${p}%;--_w:${O}%`})))))}return r}function at(t,a,s){const i=_(t);let n=a.table;for(const r of i.tasks){for(const d of r.name.split(/\s+/))n=Math.max(n,Math.ceil(s(d,"name")));for(const d of`${r.range} · ${r.length}`.split(/\s+/))n=Math.max(n,Math.ceil(s(d,"tab")));for(const d of(r.detail??"").split(/\s+/))d&&(n=Math.max(n,Math.ceil(s(d,r.mono?"mono":"sans"))))}return n}var bt=(t,a,s)=>t-a-s("4")-2*s("2"),st=(t,a,s)=>!Number.isFinite(t.shortest)||t.shortest/(t.domain[1]-t.domain[0])*a>=s-1e-6;function K(t,a,s){const i=_(t),n=at(t,a,s),r=a.space,d=i.domain[1]-i.domain[0],c=Number.isFinite(i.shortest)?r("2")*d/i.shortest:0;return Math.max(a.wide,Math.ceil(n+r("4")+2*r("2")+c))}function yt(t,a){const s=lt({domain:t.domain,length:a}),i=t.domain[1]-t.domain[0],n=ht(s,t.days?ct():dt(i/Math.max(1,a),i),56);return n.length>=2?n:[{value:t.domain[0],place:0,step:"end"},{value:t.domain[1],place:a,step:"end"}]}function vt(t,a){return t.days?ft(a.map(s=>s.step==="end"&&s.value===t.domain[1]?s.value-1:s.value)):a.map(s=>String(x(s.value)))}var et=t=>t.replace(/[&<>"']/g,a=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[a]);function kt(t,a){const{drawing:s,P:i,tk:n,W:r,apply:d,stopOf:c,current:f,measure:o}=a,g=_(t),S=n.space,w=at(t,n,o),p=g.domain[1]-g.domain[0],b=!(Number.isFinite(g.shortest)&&p>512*g.shortest)&&r>=Math.max(n.wide,K(t,n,o))&&st(g,bt(r,w,S),S("2")),$=Math.min(n.cap,r),N=!b&&st(g,$-2*S("2"),S("2")),y=c({...f,layout:b?"drawn":"stacked",form:b?void 0:N?"tracks":"words",place:b?{"":`--_name:${w}px`}:void 0,bare:void 0});d(y);const j=N||b?Mt(s,t,i,n,b,o):{geo:nt(s),ink:""};return{dyn:y,geo:j.geo,ink:j.ink,tokens:n,least:K(t,n,o)}}var nt=t=>({w:t.clientWidth,h:t.clientHeight,nodes:[],lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:0,oy:0});function Mt(t,a,s,i,n,r){const d=_(a),c=i.space,f=t.getBoundingClientRect(),o=f.left-Math.floor(f.left),g=f.top-Math.floor(f.top),S=(h,m)=>Math.round(h+m-.5)+.5-m,w=nt(t),p=!!a.rtl,O=[...t.querySelectorAll(`.${s}-gantt-track > .${s}-gantt-scale`)],b=t.querySelector(`.${s}-gantt-axis > .${s}-gantt-scale`);if(!O.length||!b)return{geo:w,ink:""};const $=Y(O[0],f),N=$.r-$.l,y=(h,m)=>p?m.r-F(d,h)*(m.r-m.l):m.l+F(d,h)*(m.r-m.l),j=yt(d,N),J=vt(d,j);let T="";const V=n?[...t.querySelectorAll(`.${s}-gantt-row`)].map(h=>Y(h,f)):[...t.querySelectorAll(`.${s}-gantt-track`)].map(h=>Y(h,f)),D=[];for(const h of V){const m=D[D.length-1];m&&Math.abs(h.t-m.b)<1.5?m.b=h.b:D.push({t:h.t,b:h.b})}const C=(h,m)=>D.map(k=>``).join("");for(const h of j)T+=C(S(y(h.value,$),o),"gantt-grid");d.today!==void 0&&(T+=C(S(y(d.today,$),o),"today"));const v=Y(b,f),E=16,H=v.b-c("2")-E/2;let I="";if(j.forEach((h,m)=>{const k=y(h.value,{l:v.l,r:v.r}),e=r(J[m],"tab"),u=p?k-c("1")-e:k+c("1");uv.r+.5||(I+=`${et(J[m])}`)}),d.today!==void 0){const h=y(d.today,{l:v.l,r:v.r}),m=r(d.todayLabel,"xs-500"),k=Math.max(v.l+m/2,Math.min(v.r-m/2,h));I+=`${et(d.todayLabel)}`}return{geo:w,ink:`${T}${I}`}}function xt(t,a,s){const i=t.byId.get(a)?.i??0,n=t.nodes.length,r=s==="ArrowDown"?i+1:s==="ArrowUp"?i-1:s==="Home"?0:s==="End"?n-1:null;return r===null?null:t.nodes[Math.max(0,Math.min(n-1,r))]?.id??null}var ot;function St(){return ot??(ot={type:"gantt",build:ut,stop:"a task",sentence:tt,key:$t,list:pt,drawing:wt,least:K,layout:kt,keyTarget:xt,hasStops:(t,a)=>!!(a.layout&&!a.bare),traces:()=>!1,hint:t=>[{keys:["↑","↓"],words:"a task"},{keys:["Home","End"],words:"the ends"},...t.nodes.some(a=>a.href)?[{keys:["Enter"],words:"open"}]:[]],keys:t=>`Up and down arrows move to the next or the previous task; Home and End go to the ends.${t.nodes.some(a=>a.href)?" Enter opens a task that is a link.":""}`,rootStyle:(t,a)=>{const s=it(a.place,"");return s?[s]:[]},form:t=>{const a=_(t);return!Number.isFinite(a.shortest)||a.shortest*34>=a.domain[1]-a.domain[0]?"tracks":"words"}})}(function(t){"use strict";var a=t._;(a.diagramTypes=a.diagramTypes||{}).gantt=St})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-matrix.css b/.agent/skills/basalt-html/parts/diagram-matrix.css new file mode 100644 index 00000000..b9e7e43f --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-matrix.css @@ -0,0 +1 @@ +@layer basalt{.diagram:is([data-type=kanban],[data-type=journey],[data-type=service-blueprint],[data-type=story-map])>.diagram-drawing{--_row-gap: var(--basalt-space-0);--_col-gap: var(--basalt-space-4);gap:var(--_Gap, var(--basalt-space-5));align-items:stretch}.diagram:is([data-type=journey],[data-type=service-blueprint],[data-type=story-map])>.diagram-drawing{--_Cols: var(--_D) var(--_lab, var(--basalt-size-diagram-lane)) repeat(var(--_cols, 1), minmax(0, 1fr))}.diagram[data-type=service-blueprint]>.diagram-drawing{--_row-gap: var(--basalt-space-3)}:is(.diagram-kanban-head,.diagram-kanban-cards,.diagram-journey-cell,.diagram-bp-head,.diagram-story-activity,.diagram-story-steps,.diagram-story-cell,.diagram-story-slot){--_Mc: var(--_D) var(--_c);--_Mr: var(--_D) var(--_r);grid-column:var(--_Mc, auto);grid-row:var(--_Mr, auto);min-width:0}:is(.diagram-kanban-card,.diagram-journey-head,.diagram-bp-cell,.diagram-story-card){--_Align: var(--_D) stretch;--_Mt: 0;margin-block-start:0}.diagram-matrix-label{--_Ml: var(--_D) block;display:var(--_Ml, none);grid-column:1;grid-row:var(--_r);padding-block:var(--basalt-space-3);border-block-start:var(--basalt-size-hairline) solid var(--basalt-border-divider);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-matrix-rule{--_Mru: var(--_D) block;display:var(--_Mru, none);grid-column:1 / -1;grid-row:var(--_r);align-self:start;margin-block-start:var(--basalt-space-3);height:var(--basalt-size-hairline);background:var(--basalt-border-divider)}.diagram-empty{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram :is(.diagram-swatch-rule,.diagram-swatch-dash){fill:none;stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}.diagram .diagram-swatch-dash{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 :is(.diagram-swatch-slot,.diagram-swatch-contour,.diagram-swatch-blocked){fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram .diagram-swatch-slot{stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram .diagram-swatch-blocked{stroke:var(--basalt-diagram-edge-main);stroke-dasharray:var(--basalt-size-diagram-guide-dash) var(--basalt-size-diagram-guide-dash)}.diagram-kanban-col{--_Kc: var(--_D) contents;display:var(--_Kc, flex);flex-direction:column;min-width:0}.diagram-kanban-head{--_r: 1;display:flex;flex-direction:column;gap:var(--basalt-space-0-5);margin-block-end:var(--basalt-space-3);padding-block-end:var(--basalt-space-2);border-block-end:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-kanban-col[data-over]>.diagram-kanban-head{border-block-end:var(--basalt-size-chart-line) solid var(--basalt-diagram-edge-main)}.diagram-kanban-top{display:flex;flex-wrap:wrap;align-items:baseline;column-gap:var(--basalt-space-2)}.diagram-kanban-title{flex:1 1 auto;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-kanban-count{flex:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums;white-space:nowrap}.diagram-kanban-col[data-over] .diagram-kanban-count{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-kanban-note{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-kanban-cards{--_r: 2;display:flex;flex-direction:column;gap:var(--basalt-space-2-5);align-self:start}.diagram-kanban-card[data-blocked]:not([data-focal]){border:var(--basalt-size-hairline) dashed var(--basalt-diagram-edge-main)}.diagram-kanban-blocked{margin-block-end:var(--basalt-space-1);color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs)}.diagram-kanban-card[data-focal] .diagram-kanban-blocked{color:var(--basalt-diagram-focal-ink)}.diagram-kanban-more{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-journey-plot{--_Jp: var(--_D) 1 / -1;--_Jpc: var(--_D) var(--_lab, var(--basalt-size-diagram-lane)) minmax(0, 1fr);--_Jph: var(--_D) calc(2 * var(--basalt-space-4) + 4 * var(--basalt-space-8));display:grid;grid-column:var(--_Jp, auto);grid-row:2;grid-template-columns:var(--_Jpc, var(--basalt-space-16) minmax(0, 1fr));column-gap:var(--basalt-space-4);height:var(--_Jph, calc(var(--basalt-space-2) + 4 * var(--basalt-space-6) + var(--basalt-space-3) + var(--basalt-text-xs-line-height)));margin-block:var(--basalt-space-3) 0}.diagram-journey-levels{position:relative}.diagram-journey-level{--_Jlt: var(--_D) calc(var(--basalt-space-4) + (5 - var(--_lv)) * var(--basalt-space-8));position:absolute;inset-block-start:calc(var(--_Jlt, calc(var(--basalt-space-2) + (5 - var(--_lv)) * var(--basalt-space-6))) - var(--basalt-text-xs-line-height) / 2);inset-inline-end:0;color:var(--basalt-chart-axis);font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums;white-space:nowrap}.diagram-journey-level:not([data-edge]){--_Jlv: var(--_D) block;display:var(--_Jlv, none)}.diagram-journey-track{display:grid;grid-template-columns:repeat(var(--_cols, 1),minmax(0,1fr));column-gap:var(--_Jtg, 0);--_Jtg: var(--_D) var(--basalt-space-4)}.diagram-journey-slot{--_Js2: var(--_D) hidden;visibility:var(--_Js2, visible);grid-column:var(--_c);align-self:end;color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums;text-align:center}.diagram-journey-slot[data-focal]{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-journey-grid{fill:none;stroke:var(--basalt-chart-grid);stroke-width:var(--basalt-size-hairline)}.diagram-journey-line{fill:none;stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line);stroke-linejoin:round;stroke-linecap:round}.diagram-journey-cut{fill:var(--_ground)}.diagram-journey-disc{fill:var(--basalt-diagram-edge-main)}.diagram-journey-stage{--_Jst: var(--_D) contents;display:var(--_Jst, flex);flex-direction:column;gap:var(--basalt-space-2);padding: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)}.diagram-journey-head{--_Jhb: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Jhr: var(--_D) var(--basalt-size-hairline);--_Jhp: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);background:var(--_Jhb, none);border-width:var(--_Jhr, 0);padding:var(--_Jhp, 0)}.diagram-journey-head[data-focal]{background:var(--basalt-diagram-focal);border-width:var(--basalt-size-hairline);padding:var(--basalt-space-2-5) var(--basalt-space-3)}.diagram-journey-head>.diagram-kind{display:flex;justify-content:space-between;gap:var(--basalt-space-2)}.diagram-journey-word{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-sans);font-variant-numeric:tabular-nums;white-space:nowrap}.diagram-journey-head[data-focal] .diagram-journey-word{color:var(--basalt-diagram-focal-ink)}.diagram-journey-cell{--_Jcp: var(--_D) var(--basalt-space-3);display:flex;flex-direction:column;gap:var(--basalt-space-0-5);padding-block:var(--_Jcp, var(--basalt-space-2) 0);border-block-start:var(--basalt-size-hairline) solid var(--basalt-border-divider);color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--bh-sm)}.diagram-journey-cell[data-empty]{--_Jce: var(--_D) flex;display:var(--_Jce, none)}.diagram-journey-cell-label{--_Jcl: var(--_D) none;display:var(--_Jcl, block);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}q.diagram-journey-value{color:var(--basalt-text-secondary)}.diagram[data-type=service-blueprint] .diagram-matrix-label{border-block-start:0;padding-block:var(--basalt-space-2-5)}.diagram-bp-rule{display:flex;align-items:center;gap:var(--basalt-space-3);padding-block:var(--basalt-space-1)}.diagram-bp-rule[data-span]{--_Brs: var(--_D) flex;display:var(--_Brs, none);grid-column:1 / -1;grid-row:var(--_r)}.diagram-bp-rule[data-in]{--_Bri: var(--_D) none;display:var(--_Bri, flex)}.diagram-bp-rule-name{flex:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs);white-space:nowrap}.diagram-bp-rule[data-rule=visibility]>.diagram-bp-rule-name{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-bp-rule-line{flex:1 1 auto;min-width:0;overflow:visible}.diagram-bp-rule-line>line{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-bp-rule[data-rule=visibility] .diagram-bp-rule-line>line{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line);stroke-dasharray:none}.diagram-bp-stage{--_Bs: var(--_D) contents;display:var(--_Bs, flex);flex-direction:column;gap:var(--basalt-space-2);padding: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)}.diagram-bp-head{--_r: 1;display:flex;flex-direction:column;gap:var(--basalt-space-0-5);padding-block-end:var(--basalt-space-2);border-block-end:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-bp-time{font-family:var(--basalt-font-family-sans);font-variant-numeric:tabular-nums}.diagram-bp-cell{--_Bcd: var(--_D) column;--_Bcb: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Bcr: var(--_D) var(--basalt-size-hairline);--_Bcp: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);flex-direction:var(--_Bcd, row);gap:var(--basalt-space-3);background:var(--_Bcb, none);border-width:var(--_Bcr, 0);padding:var(--_Bcp, 0)}.diagram-bp-cell{--_Bai: var(--_D) stretch;justify-content:flex-start;align-items:var(--_Bai, baseline)}.diagram-bp-cell[data-focal]{background:var(--basalt-diagram-focal);border-width:var(--basalt-size-hairline);padding:var(--basalt-space-2-5) var(--basalt-space-3)}.diagram-bp-cell[data-empty]{background:none;border-color:transparent}.diagram-bp-layer{--_Bl: var(--_D) none;display:var(--_Bl, block);flex:none;width:var(--basalt-size-diagram-lane);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-bp-cell[data-focal] .diagram-bp-layer{color:var(--basalt-diagram-focal-ink)}.diagram-bp-body{display:flex;flex-direction:column;min-width:0}.diagram-bp-to{--_Bt: var(--_D) none;display:var(--_Bt, block);margin-block-start:var(--basalt-space-0-5);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-story-backbone{--_Sb: var(--_D) contents;display:var(--_Sb, flex);flex-direction:column;gap:var(--basalt-space-2);padding:var(--basalt-space-3);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-md)}.diagram-story-activity{--_Sab: var(--_D) var(--panel-next, var(--basalt-surface-1));--_Sar: var(--_D) var(--basalt-size-hairline);--_Sap: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);display:flex;flex-direction:column;background:var(--_Sab, none);border:var(--_Sar, 0) solid var(--basalt-diagram-structure);border-radius:var(--basalt-radius-md);padding:var(--_Sap, 0)}.diagram-story-steps{display:flex;flex-wrap:wrap;align-content:start;gap:var(--basalt-space-1-5);margin-block-start:var(--_Ssm, 0);--_Ssm: var(--_D) var(--basalt-space-2)}.diagram-story-step{padding:var(--basalt-space-1-5) var(--basalt-space-2-5);background:var(--panel-next, var(--basalt-surface-1));border:var(--basalt-size-hairline) solid var(--basalt-border-rim);border-radius:var(--basalt-radius-sm);color:var(--basalt-text-primary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-story-slice{--_Ss: var(--_D) contents;display:var(--_Ss, flex);flex-direction:column;gap:var(--basalt-space-2)}.diagram-story-slice-head{--_Shc: var(--_D) 1;--_Shd: var(--_D) column;grid-column:var(--_Shc, auto);grid-row:var(--_r);display:flex;flex-direction:var(--_Shd, row);flex-wrap:wrap;align-items:baseline;column-gap:var(--basalt-space-2);padding-block-start:var(--basalt-space-3)}.diagram-story-slice-name{color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-sm)}.diagram-story-slice[data-below] .diagram-story-slice-name{color:var(--basalt-text-secondary);font-weight:var(--basalt-font-weight-medium)}.diagram-story-count{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums}.diagram-story-cell{display:flex;flex-direction:column;gap:var(--basalt-space-2);padding-block-start:var(--_Scp, 0);--_Scp: var(--_D) var(--basalt-space-3)}.diagram-story-slot{--_Sl: var(--_D) block;--_Sls: var(--_D) none;margin-block-start:var(--_Slm, 0);--_Slm: var(--_D) var(--basalt-space-3);padding:var(--_Slp, 0);--_Slp: var(--_D) var(--basalt-space-2-5) var(--basalt-space-3);border:var(--_Slb, 0) dashed var(--basalt-diagram-structure);--_Slb: var(--_D) var(--basalt-size-hairline);border-radius:var(--basalt-radius-md)}.diagram-story-slot>.diagram-empty{--_Sle: var(--_D) inline;display:var(--_Sle, none)}.diagram-story-left-out{--_Slo: var(--_D) none;display:var(--_Slo, inline);color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-story-of{--_So: var(--_D) none;display:var(--_So, inline)}.diagram-story-of+.diagram-story-code:before{--_Sc: var(--_D) "";content:var(--_Sc, " · ")}.diagram-story-cut{grid-column:1 / -1;grid-row:var(--_r);display:flex;align-items:center;gap:var(--basalt-space-3);padding-block:var(--basalt-space-2)}.diagram-story-cut-name{flex:none;color:var(--basalt-text-primary);font:var(--basalt-font-weight-semibold) var(--bh-xs);white-space:nowrap}.diagram-story-cut-line{flex:1 1 auto;height:0;border-block-start:var(--basalt-size-chart-line) solid var(--basalt-diagram-edge-main)}@container (width >= 640px){.diagram:not([data-layout]):is([data-type=kanban]:is([data-cols="1"],[data-cols="2"],[data-cols="3"],[data-cols="4"]),:is([data-type=journey],[data-type=service-blueprint],[data-type=story-map]):is([data-cols="1"],[data-cols="2"],[data-cols="3"]))>.diagram-drawing{--_D: }}@container (width >= 784px){.diagram:not([data-layout])[data-type=kanban][data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 760px){.diagram:not([data-layout]):is([data-type=journey],[data-type=service-blueprint],[data-type=story-map])[data-cols="4"]>.diagram-drawing{--_D: }}@container (width >= 920px){.diagram:not([data-layout]):is([data-type=journey],[data-type=service-blueprint],[data-type=story-map])[data-cols="5"]>.diagram-drawing{--_D: }}@container (width >= 944px){.diagram:not([data-layout])[data-type=kanban][data-cols="6"]>.diagram-drawing{--_D: }}@container (width >= 1080px){.diagram:not([data-layout]):is([data-type=journey],[data-type=service-blueprint],[data-type=story-map])[data-cols="6"]>.diagram-drawing{--_D: }}@media(prefers-contrast:more){.diagram-journey-grid{stroke:var(--basalt-border-input)}}@media(forced-colors:active){.diagram-journey-grid{display:none}.diagram :is(.diagram-journey-line){stroke:CanvasText}.diagram .diagram-journey-disc{fill:CanvasText}.diagram .diagram-journey-cut{fill:Canvas}.diagram .diagram-bp-rule-line>line{stroke:GrayText}.diagram .diagram-bp-rule[data-rule=visibility] .diagram-bp-rule-line>line{stroke:CanvasText}.diagram .diagram-bp-rule-line{forced-color-adjust:none}.diagram .diagram-story-cut-line,.diagram .diagram-kanban-col[data-over]>.diagram-kanban-head{border-color:CanvasText}.diagram .diagram-kanban-card[data-blocked]{border-color:CanvasText}.diagram .diagram-story-slot{border-color:GrayText}.diagram :is(.diagram-swatch-rule,.diagram-swatch-contour,.diagram-swatch-blocked){stroke:CanvasText}.diagram :is(.diagram-swatch-dash,.diagram-swatch-slot){stroke:GrayText}}@media print{.diagram :is(.diagram-bp-rule-line,.diagram-story-cut-line,.diagram-kanban-head){-webkit-print-color-adjust:exact;print-color-adjust:exact}}} diff --git a/.agent/skills/basalt-html/parts/diagram-matrix.js b/.agent/skills/basalt-html/parts/diagram-matrix.js new file mode 100644 index 00000000..aa0ee0a8 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-matrix.js @@ -0,0 +1 @@ +(()=>{var M=e=>e==null||e===""?void 0:String(e),A=e=>{const t=e.trim();return t?/[.!?]$/.test(t)?t:`${t}.`:""};function l(e,t,...a){const s=[];for(const n of a.flat(1/0))n!=null&&n!==!1&&!Array.isArray(n)&&s.push(n);return{t:e,a:t??{},c:s}}var q=(e,t)=>({width:e,height:t,viewBox:`0 0 ${e} ${t}`,"aria-hidden":"true",focusable:"false"});function me(e,t){const a=t==="fk"?"plain":t,s=a==="main"?8:8.5,n=24,r=a==="dashed"?n-1:n-7;return l("svg",{class:`${e}-swatch`,"data-kind":a,...q(24,16)},t==="fk"?l("circle",{class:`${e}-dot`,cx:3,cy:s,r:3}):null,l("path",{class:`${e}-line`,"data-kind":a,d:`M${t==="fk"?3:0} ${s}H${r}`}),a==="dashed"?l("path",{class:`${e}-tip`,"data-kind":a,"data-open":"",d:`M${n-8} ${s-4}L${n} ${s}L${n-8} ${s+4}`}):l("path",{class:`${e}-tip`,"data-kind":a,d:`M${n} ${s}L${n-8} ${s-4}L${n-8} ${s+4}Z`}))}var $=e=>l("bdi",null,e),F=(e,t)=>{const a=e.getBoundingClientRect();return{l:a.left-t.left,t:a.top-t.top,r:a.right-t.left,b:a.bottom-t.top}},j=e=>Math.round(e*100)/100,J=(e,t)=>{const a=e.labels??{},s={...t};for(const n of Object.keys(t))a[n]!==void 0&&a[n]!==null&&a[n]!==""&&(s[n]=a[n]);return s},ve=(e,t)=>({href:e,target:e&&t?"_blank":void 0,rel:e&&t?"noopener noreferrer":void 0,"data-link":e?t?"external":"":void 0}),be=(e,t)=>e.layout&&!e.bare?e.stop===t?0:-1:e.keep===t?-1:void 0;function V(e,t,a,s,n,r,...o){return l(a.href?"a":"div",{class:`${e}-node`,...ve(a.href,a.blank),"data-node":a.id,"data-focal":a.focal?"":void 0,"data-level":n,role:a.href?void 0:"img","aria-label":t.ext.sentence(t,a),tabindex:be(s,a.id),...r},...o)}function ae(e,t,a){return[a??(t.kind?l("span",{class:`${e}-kind`},$(t.kind)):null),l("span",{class:`${e}-name`},$(t.name)),t.detail?l("span",{class:`${e}-detail`,"data-mono":t.mono?"":void 0},t.mono?l("span",{class:`${e}-runs`},t.detail.split(/\s+/).filter(Boolean).flatMap((s,n)=>[n?" ":"",l("span",{class:`${e}-run`},s)])):$(t.detail)):null]}var I=(e,t,a,s={})=>l("li",{class:`${e}-entry`,...s},t,l("span",null,$(a))),Y=(e,t)=>t.length?l("div",{class:`${e}-key`},l("ul",{class:`${e}-legend`,"aria-label":"Key"},t)):null,Z=e=>l("svg",{class:`${e}-swatch`,"data-shape":"focal",...q(16,16)},l("rect",{class:`${e}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2})),T=(e,t)=>t==="slot"||t==="contour"?l("svg",{class:`${e}-swatch`,...q(16,16)},l("rect",{class:t==="slot"?`${e}-swatch-slot`:`${e}-swatch-contour`,x:.5,y:2.5,width:15,height:11,rx:3})):l("svg",{class:`${e}-swatch`,...q(24,16)},l("path",{class:t==="main"?`${e}-swatch-rule`:`${e}-swatch-dash`,d:t==="main"?"M0 8H24":"M0 8.5H24"}));function W(e,t){let a=0;for(const[s,n,r]of t)if(s)for(const o of r?[s]:s.split(/\s+/))o&&(a=Math.max(a,e(o,n)));return Math.ceil(a)}function G(e,t,a,s){const n=e.space("4");return Math.max(e.wide,(s===null?0:s+n)+t*Math.max(e.node,a)+(t-1)*n)}function Q(e){return(t,a)=>{const s=t.ext.least(t,a.tk,a.measure),n=X(t,a.tk,a.measure),r=a.W>=s,o=a.stopOf({...a.current,layout:r?"drawn":"stacked",bare:void 0,place:n?{"":`--_lab:${n}px`}:void 0});a.apply(o);const i=e?e(a.drawing,t,a.P,a.tk,r):{geo:se(a.drawing),ink:""};return{dyn:o,geo:i.geo,ink:i.ink,tokens:a.tk,least:s}}}var se=e=>({w:e.clientWidth,h:e.clientHeight,nodes:[],lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:0,oy:0});function X(e,t,a){const s=e.plan;return s.labelWords?Math.max(t.lane,W(a,s.labelWords)+t.space("3")):null}var ce=(e,t,a)=>[{keys:t&&e.cols>1&&e.rows>1?["←","↑","↓","→"]:t?["←","→"]:["↑","↓"],words:`a ${a}`},{keys:["Home","End"],words:"the ends"},...e.nodes.some(s=>s.href)?[{keys:["Enter"],words:"open"}]:[]],we=(e,t,a)=>`${t?`Arrow keys move to the nearest ${a} in that direction`:`Arrow keys move to the next or the previous ${a}`}; Home and End go to the ends.${e.nodes.some(s=>s.href)?` Enter opens a ${a} that is a link.`:""}`,xe=(e,t)=>{const a=t.place?.[""];return a?[a]:[]},R=e=>l("strong",null,$(e)),z=(e,t)=>t&&e.legend.focal?` ${A(e.legend.focal)}`:"",de=e=>({id:String(e.id??""),name:String(e.name??""),kind:M(e.kind),detail:M(e.detail),mono:!!e.detailMono,focal:!!e.focal,href:M(e.href),blank:e.target==="_blank"}),ue=(e,t,a,s)=>({id:e.id,i:t,name:e.name,kind:e.kind,detail:e.detail,mono:e.mono,focal:e.focal,col:a,row:s,row2:s,branch:!1,shape:"box",href:e.href,blank:e.blank});function ne(e,t){if(!e.dev)return;const a=new Set;for(const s of t)s?a.has(s)&&e.warn(`the id "${s}" is used twice`):e.warn("a part has no id"),a.add(s)}var N=e=>e.plan;function U(e,t){const a=t.limit!==void 0?`${t.count}, ${e.words.max} ${t.limit}`:String(t.count);return t.over?`${a} · ${e.words.overLimit}`:a}function Se(e,t){const a=J(e,{max:"max",overLimit:"Over limit",blocked:"Blocked",noCards:"No cards",notShown:"not shown",keyOver:"Over its limit"});t.dev&&Array.isArray(e.edges)&&e.edges.length&&t.error("a kanban draws no lines: it is a count of cards at one moment");const s=(Array.isArray(e.columns)?e.columns:[]).map((o,i)=>{const f=o,p=typeof f.limit=="number"&&Number.isInteger(f.limit)&&f.limit>0?f.limit:void 0,g=typeof f.more=="number"&&Number.isInteger(f.more)&&f.more>0?f.more:0;return{id:String(f.id??""),label:String(f.label??""),limit:p,more:g,note:M(f.note),count:0,over:!1,cards:[],c:i+1}}),n=new Map(s.map(o=>[o.id,o]));for(const o of Array.isArray(e.cards)?e.cards:[]){const i=n.get(String(o.column??""));if(!i){t.dev&&t.warn(`the card ${String(o.id)} names the column "${String(o.column)}", which is not in columns`);continue}t.dev&&"state"in o&&t.error(`the card ${String(o.id)} has a "state": a kanban card is blocked (with its reason) or in its column, nothing more`),i.cards.push({...de(o),column:i.id,blocked:M(o.blocked)})}for(const o of s)o.count=o.cards.length+o.more,o.over=o.limit!==void 0&&o.count>o.limit;const r=[];for(const o of s)o.cards.forEach((i,f)=>r.push(ue(i,r.length,o.c,f+1)));return ne(t,r.map(o=>o.id)),t.dev&&r.filter(o=>o.focal).length>1&&t.warn("more than one card is focal: a kanban has one at most"),{nodes:r,edges:[],plan:{columns:s,words:a},cols:Math.max(1,s.length),rows:Math.max(1,...s.map(o=>o.cards.length))}}var ke=(e,t)=>{for(const a of N(e).columns){const s=a.cards.find(n=>n.id===t);if(s)return{col:a,card:s}}return null};function Me(e,t){const a=N(e),s=ke(e,t.id),{col:n,card:r}=s,o=[A(r.kind?`${r.name}, ${r.kind}`:r.name),`In ${n.label}: ${U(a,n).replace(" · ",", ").toLowerCase()}.`];return r.blocked&&o.push(`${a.words.blocked}: ${A(r.blocked)}`),r.detail&&o.push(A(r.detail)),r.focal&&e.legend.focal&&o.push(A(e.legend.focal)),o.join(" ")}function je(e,t,a,s){const n=N(t);return n.columns.map(r=>l("section",{class:`${e}-kanban-col`,"data-over":r.over?"":void 0},l("div",{class:`${e}-kanban-head`,style:`--_c:${r.c}`},l("span",{class:`${e}-kanban-top`},l("span",{class:`${e}-kanban-title`},$(r.label)),l("span",{class:`${e}-kanban-count`},$(U(n,r)))),r.note?l("span",{class:`${e}-kanban-note`},$(r.note)):null),l("div",{class:`${e}-kanban-cards`,style:`--_c:${r.c}`},r.cards.map(o=>{const i=t.byId.get(o.id);return V(e,t,i,a,s,{class:`${e}-node ${e}-kanban-card`,"data-blocked":o.blocked?"":void 0},o.blocked?l("span",{class:`${e}-kanban-blocked`},$(`${n.words.blocked} · ${o.blocked}`)):null,...ae(e,o))}),!r.cards.length&&!r.more?l("span",{class:`${e}-empty`},$(n.words.noCards)):null,r.more?l("span",{class:`${e}-kanban-more`},$(`${r.more} more ${n.words.notShown}`)):null)))}function _e(e,t){const a=N(t),s=[];return a.columns.some(n=>n.over)&&s.push(I(e,T(e,"main"),a.words.keyOver)),a.columns.some(n=>n.cards.some(r=>r.blocked&&!r.focal))&&s.push(I(e,l("svg",{class:`${e}-swatch`,...q(16,16)},l("rect",{class:`${e}-swatch-blocked`,x:.5,y:2.5,width:15,height:11,rx:3})),a.words.blocked)),t.nodes.some(n=>n.focal)&&t.legend.focal&&s.push(I(e,Z(e),t.legend.focal,{"data-focal":""})),Y(e,s)}function Ae(e,t){const a=N(t),s=Math.min(6,t.heading+1);return a.columns.flatMap(n=>[l(`h${s}`,{class:`${e}-list-head`},$(n.label),`: ${U(a,n)}`),l("ul",{class:`${e}-list-items`},[...n.cards.map(r=>l("li",null,R(r.name),r.kind?`, ${r.kind}`:"",r.detail?`. ${A(r.detail)}`:".",r.blocked?` ${a.words.blocked}: ${A(r.blocked)}`:"",z(t,r.focal))),...n.more?[l("li",null,`${n.more} more ${a.words.notShown}.`)]:[],...!n.cards.length&&!n.more?[l("li",null,`${a.words.noCards}.`)]:[]])])}function Le(e,t,a){const s=N(e),n=2*t.space("3")+2*t.hair;let r=t.node;for(const o of s.columns){r=Math.max(r,W(a,[[o.label,"name"],[o.note,"sans"]]),Math.ceil(a(U(s,o),o.over?"xs-600":"tab")));for(const i of o.cards)r=Math.max(r,n+W(a,[[i.name,"name"],[i.kind,"mono"],[i.detail,i.mono?"mono":"sans"],[i.blocked?`${s.words.blocked} ·`:void 0,"xs-600"],[i.blocked,"xs-600"]]))}return G(t,s.columns.length,r,null)}var P=["actions","quote","touchpoint","friction","opportunity"],E=e=>e.plan,D=(e,t)=>t==="touchpoint"?e.words.touchpoints:e.words[t];function Ie(e,t){const a=J(e,{stage:"Stage",none:"None",actions:"Actions",quote:"Quote",touchpoints:"Touchpoints",friction:"Friction",opportunity:"Opportunity"}),s=M(e.actor),n=M(e.scenario);t.dev&&(!s||!n)&&t.error("a journey needs its actor and its scenario: it is one actor in one scenario");const r=Array.isArray(e.scale)?e.scale.map(String):[];t.dev&&r.length!==5&&t.error("a journey's scale is five words, lowest first, in the author's own words");const o=r.length===5?r:["1","2","3","4","5"],i=e.legend??{};t.dev&&!M(i.line)&&t.error("a journey's line needs its words (legend.line): the key must say what the scale measures");const f=(Array.isArray(e.stages)?e.stages:[]).map((u,S)=>{const m=u,d=Number(m.level),b=Number.isInteger(d)&&d>=1&&d<=5?d:(t.dev&&t.error(`the stage ${String(m.id)}'s level is ${JSON.stringify(m.level)}, not 1 to 5`),3),k={};for(const c of P){const y=M(m[c]);y&&(k[c]=y)}return{id:String(m.id??""),i:S,name:String(m.name??""),level:b,levelWord:o[b-1],fields:k,focal:!!m.focal,href:M(m.href),blank:m.target==="_blank"}}),p=P.filter(u=>f.some(S=>S.fields[u])),g=f.map(u=>({id:u.id,i:u.i,name:u.name,mono:!1,focal:u.focal,col:u.i+1,row:1,row2:1,branch:!1,shape:"box",href:u.href,blank:u.blank}));ne(t,g.map(u=>u.id)),t.dev&&g.filter(u=>u.focal).length>1&&t.warn("more than one stage is focal: a journey has one at most");const w=[...p.map(u=>[D({words:a},u),"xs-500"]),...o.map(u=>[u,"tab"])];return{nodes:g,edges:[],plan:{actor:s??"",scenario:n??"",scale:o,stages:f,bands:p,words:a,labelWords:w},cols:Math.max(1,f.length),rows:1}}var We=(e,t)=>E(e).stages.find(a=>a.id===t);function Ee(e,t){const a=E(e),s=We(e,t.id),n=[`${a.words.stage} ${s.i+1} of ${a.stages.length}, ${s.name}: ${s.levelWord}.`];for(const r of P)s.fields[r]&&n.push(`${D(a,r)}: ${r==="quote"?`“${s.fields[r]}”`:A(s.fields[r])}`);return s.focal&&e.legend.focal&&n.push(A(e.legend.focal)),n.join(" ")}function Oe(e,t){const a=E(t);return!a.actor&&!a.scenario?null:l("p",{class:`${e}-meta`},l("span",{class:`${e}-meta-first`},$(a.actor)),a.scenario?[" · ",$(a.scenario)]:null)}function Be(e,t,a,s){const n=E(t),r=[];r.push(l("div",{class:`${e}-journey-plot`,style:`--_cols:${n.stages.length}`,"aria-hidden":"true"},l("span",{class:`${e}-journey-levels`},[...n.scale].map((o,i)=>l("span",{class:`${e}-journey-level`,style:`--_lv:${i+1}`,"data-edge":i===0||i===2||i===4?"":void 0},$(o))).reverse()),l("span",{class:`${e}-journey-track`},n.stages.map(o=>l("span",{class:`${e}-journey-slot`,"data-stage":o.id,"data-focal":o.focal?"":void 0,style:`--_c:${o.i+1}`,"data-lv":o.level},String(o.i+1)))))),n.bands.forEach((o,i)=>r.push(l("span",{class:`${e}-matrix-label`,style:`--_r:${i+3}`,"aria-hidden":"true"},$(D(n,o)))));for(const o of n.stages){const i=t.byId.get(o.id),f=o.i+2;r.push(l("section",{class:`${e}-journey-stage`,"data-focal":o.focal?"":void 0},V(e,t,i,a,s,{class:`${e}-node ${e}-journey-head`,style:`--_c:${f};--_r:1;--_r2:2`},l("span",{class:`${e}-kind`},$(`${n.words.stage} ${o.i+1}`),l("span",{class:`${e}-journey-word`},$(o.levelWord))),l("span",{class:`${e}-name`},$(o.name))),n.bands.map((p,g)=>{const w=o.fields[p];return l("div",{class:`${e}-journey-cell`,"data-empty":w?void 0:"",style:`--_c:${f};--_r:${g+3}`},l("span",{class:`${e}-journey-cell-label`,"aria-hidden":"true"},$(D(n,p))),w?p==="quote"?l("q",{class:`${e}-journey-value`},$(w)):l("span",{class:`${e}-journey-value`},$(w)):l("span",{class:`${e}-empty`},$(n.words.none)))})))}return r}function Ce(e,t,a,s,n){const r=E(t),o=se(e),i=e.getBoundingClientRect(),f=i.left-Math.floor(i.left),p=i.top-Math.floor(i.top),g=e.querySelector(`.${a}-journey-track`);if(!g)return{geo:o,ink:""};const w=F(g,i),h=s.space,u=h(n?"8":"6"),S=w.t+h(n?"4":"2"),m=v=>S+(5-v)*u,d=(v,L)=>Math.round(v+L-.5)+.5-L,b=(v,L)=>Math.round(v+L)-L,k=F(e.querySelector(`.${a}-journey-plot`),i);let c="";for(let v=1;v<=5;v++)(n||v===1||v===3||v===5)&&(c+=``);const y=r.stages.map(v=>{const L=n?e.querySelector(`.${a}-node[data-node="${CSS.escape(v.id)}"]`):e.querySelector(`.${a}-journey-slot[data-stage="${CSS.escape(v.id)}"]`),te=L?F(L,i):w;return b((te.l+te.r)/2,f)}),x=r.stages.map((v,L)=>({x:y[L],y:b(m(v.level),p)}));x.length>1&&(c+=``);const _=s.dot/2+1;for(const v of x)c+=``;return{geo:o,ink:`${c}`}}function qe(e,t){const a=[],s=M(t.legend.line);return a.push(I(e,l("svg",{class:`${e}-swatch`,...q(24,16)},l("path",{class:`${e}-journey-line`,d:"M0 11L12 5L24 11"}),l("circle",{class:`${e}-journey-cut`,cx:12,cy:5,r:6}),l("circle",{class:`${e}-journey-disc`,cx:12,cy:5,r:4})),s??"")),t.nodes.some(n=>n.focal)&&t.legend.focal&&a.push(I(e,Z(e),t.legend.focal,{"data-focal":""})),Y(e,a)}function Te(e,t){const a=E(t);return[l("ol",{class:`${e}-list-items`},a.stages.map(s=>l("li",null,R(s.name),`: ${s.levelWord}.`,P.filter(n=>s.fields[n]).map(n=>[` ${D(a,n)}: `,n==="quote"?l("q",null,$(s.fields[n])):A(s.fields[n])]),z(t,s.focal))))]}function Ne(e,t,a){const s=E(e),n=2*t.space("3")+2*t.hair;let r=t.node;for(const o of s.stages){r=Math.max(r,n+W(a,[[o.name,"name"]])),r=Math.max(r,n+Math.ceil(a(`${s.words.stage} ${o.i+1}`,"mono")+t.space("2")+a(o.levelWord,"tab")));for(const i of s.bands)r=Math.max(r,W(a,[[o.fields[i],"sm"]]))}return G(t,s.stages.length,r,X(e,t,a))}var oe=["evidence","customer","frontstage","backstage","support"],He={evidence:"Evidence",customer:"Customer",frontstage:"Frontstage",backstage:"Backstage",support:"Support"},O=e=>e.plan,re=e=>e==="frontstage"?"interaction":e==="backstage"?"visibility":e==="support"?"internal":null,K=(e,t)=>`${e}:${t}`;function Re(e,t){const a=J(e,{stage:"Stage",none:"None",keyVisibility:"the customer sees what is above it",keyInteraction:"",keyInternal:""}),s=(Array.isArray(e.stages)?e.stages:[]).map(c=>{const y=c;return{id:String(y.id??""),name:String(y.name??""),time:M(y.time)}}),n=Array.isArray(e.cells)?e.cells:[],r=new Set(["customer","frontstage","backstage"]);for(const c of n)oe.includes(c.layer)?r.add(c.layer):t.dev&&t.warn(`a cell names the layer "${String(c.layer)}", which is not evidence, customer, frontstage, backstage or support`);const o=oe.filter(c=>r.has(c)),i=e.layerLabels??{},f=Object.fromEntries(oe.map(c=>[c,M(i[c])??He[c]])),p=e.ruleLabels??{},g={interaction:M(p.interaction)??"Line of interaction",visibility:M(p.visibility)??"Line of visibility",internal:M(p.internal)??"Line of internal interaction"},w=new Map;for(const c of n){const y=K(String(c.stage),String(c.layer));t.dev&&w.has(y)&&t.warn(`the cell ${y} is given twice`),w.set(y,c)}for(const c of w.keys())t.dev&&!s.some(y=>c.startsWith(`${y.id}:`))&&t.warn(`the cell ${c} names a stage that is not in stages`);const h=[];for(const[c,y]of s.entries())for(const x of o){const _=w.get(K(y.id,x)),v=M(_?.name);h.push({id:K(y.id,x),stage:c,layer:x,empty:!v,name:v??"",detail:v?M(_.detail):void 0,mono:!!_?.detailMono,focal:!!(v&&_?.focal),href:v?M(_?.href):void 0,blank:_?.target==="_blank"})}const u=h.map((c,y)=>({id:c.id,i:y,name:c.empty?a.none:c.name,detail:c.detail,mono:c.mono,focal:c.focal,col:c.stage+1,row:o.indexOf(c.layer)+1,row2:o.indexOf(c.layer)+1,branch:!1,shape:"box",href:c.href,blank:c.blank})),S=new Map(h.map(c=>[c.id,c])),m=[],d=[];for(const c of Array.isArray(e.arrows)?e.arrows:[]){const y=K(String(c.from?.stage),String(c.from?.layer)),x=K(String(c.to?.stage),String(c.to?.layer)),_=S.get(y),v=S.get(x);if(!_||!v||_.empty||v.empty){t.dev&&t.error(`the arrow ${y} to ${x} names a cell that is empty or not drawn`);continue}c.kind==="dashed"&&t.dev&&t.error(`the arrow ${y} to ${x} is dashed: a blueprint's arrows are main or plain (its lines of interaction are the dashed marks), so it is drawn plain`);const L=_.stage===v.stage&&_.layer!==v.layer,te=_.layer===v.layer&&Math.abs(_.stage-v.stage)===1;if(!L&&!te){t.dev&&t.error(`the arrow ${y} to ${x} joins two cells of neither one stage nor neighbouring stages of one layer, so it is not drawn`);continue}const ge=c.kind==="main"?"main":"plain";m.push({i:m.length,from:y,to:x,kind:ge}),d.push({i:d.length,from:y,to:x,kind:ge})}t.dev&&(m.some(c=>c.kind==="main")&&!t.legend.main&&t.warn("main arrows are drawn but the legend has no words for them (legend.main)"),m.some(c=>c.kind==="plain")&&!t.legend.plain&&t.warn("plain arrows are drawn but the legend has no words for them (legend.plain)"),h.filter(c=>c.focal).length>1&&t.warn("more than one cell is focal: a blueprint has one at most"));const b=o.map(c=>[f[c],"xs-500"]);return{nodes:u,edges:d,plan:{stages:s,layers:o,layerWords:f,rules:g,cells:h,arrows:m,words:a,labelWords:b},cols:Math.max(1,s.length),rows:Math.max(1,o.length)}}var B=(e,t)=>O(e).cells.find(a=>a.id===t),H=(e,t)=>e.stages[t.stage].name;function De(e,t){const a=O(e),s=B(e,t.id);if(s.empty)return`${H(a,s)}, ${a.layerWords[s.layer]}: ${a.words.none.toLowerCase()}.`;const n=[`${s.name}. ${H(a,s)}, ${a.layerWords[s.layer]}.`];s.detail&&n.push(A(s.detail));const r=a.arrows.filter(i=>i.from===s.id).map(i=>B(e,i.to)).map(i=>`${i.name} (${i.stage===s.stage?a.layerWords[i.layer]:H(a,i)})`),o=a.arrows.filter(i=>i.to===s.id).map(i=>B(e,i.from)).map(i=>`${i.name} (${i.stage===s.stage?a.layerWords[i.layer]:H(a,i)})`);return o.length&&n.push(`From: ${o.join(", ")}.`),r.length&&n.push(`To: ${r.join(", ")}.`),s.focal&&e.legend.focal&&n.push(A(e.legend.focal)),n.join(" ")}function fe(e,t,a,s={}){return l("div",{class:`${e}-bp-rule`,"data-rule":t,"aria-hidden":"true",...s},l("span",{class:`${e}-bp-rule-name`},$(a)),l("svg",{class:`${e}-bp-rule-line`,height:2,focusable:"false"},l("line",{x1:0,x2:"100%",y1:t==="visibility"?1:.5,y2:t==="visibility"?1:.5})))}function Ke(e){const t=new Map,a=new Map;let s=2;for(const n of e.layers){const r=re(n);r&&a.set(r,s++),t.set(n,s++)}return{layer:t,rule:a}}function Fe(e,t,a,s){const n=O(t),r=Ke(n),o=[];for(const[i,f]of r.rule)o.push(fe(e,i,n.rules[i],{"data-span":"",style:`--_r:${f}`}));for(const[i,f]of r.layer)o.push(l("span",{class:`${e}-matrix-label`,style:`--_r:${f}`,"aria-hidden":"true"},$(n.layerWords[i])));return n.stages.forEach((i,f)=>{const p=f+2,g=[l("div",{class:`${e}-bp-head`,style:`--_c:${p};--_r:1`},l("span",{class:`${e}-kind`},$(`${n.words.stage} ${f+1}`),i.time?l("span",{class:`${e}-bp-time`}," · ",$(i.time)):null),l("span",{class:`${e}-name`},$(i.name)))];for(const w of n.layers){const h=re(w);h&&g.push(fe(e,h,n.rules[h],{"data-in":""}));const u=n.cells.find(d=>d.stage===f&&d.layer===w),S=t.byId.get(u.id),m=n.arrows.filter(d=>d.from===u.id).map(d=>B(t,d.to));g.push(V(e,t,S,a,s,{class:`${e}-node ${e}-bp-cell`,"data-empty":u.empty?"":void 0,style:`--_c:${p};--_r:${r.layer.get(w)};--_r2:${r.layer.get(w)+1}`},l("span",{class:`${e}-bp-layer`,"aria-hidden":"true"},$(n.layerWords[w])),l("span",{class:`${e}-bp-body`},u.empty?l("span",{class:`${e}-empty`},$(n.words.none)):ae(e,u),m.map(d=>l("span",{class:`${e}-bp-to`},`${t.rtl?"←":"→"} `,$(d.stage===u.stage?d.name:`${d.name} (${H(n,d)})`))))))}o.push(l("section",{class:`${e}-bp-stage`},g))}),o}function Je(e,t,a,s,n){const r=O(t),o=se(e);if(!n||!r.arrows.length)return{geo:o,ink:""};const i=e.getBoundingClientRect();o.ox=i.left-Math.floor(i.left),o.oy=i.top-Math.floor(i.top);const f=h=>{const u=e.querySelector(`.${a}-node[data-node="${CSS.escape(h)}"]`);return u?F(u,i):null},p=(h,u,S)=>S%2?Math.round(h+u-.5)+.5-u:Math.round(h+u)-u;for(const h of r.arrows){const u=B(t,h.from),S=B(t,h.to),m=f(h.from),d=f(h.to);if(!m||!d)continue;const b=h.kind==="main"?s.line:s.hair;let k,c;if(u.stage===S.stage){const y=r.layers.indexOf(S.layer)>r.layers.indexOf(u.layer);if(Math.abs(r.layers.indexOf(S.layer)-r.layers.indexOf(u.layer))>1){const x=t.rtl?Math.min(m.l,d.l):Math.max(m.r,d.r),_=p(t.rtl?x-s.space("2"):x+s.space("2"),o.ox,b),v=p((m.t+m.b)/2,o.oy,b),L=p((d.t+d.b)/2,o.oy,b);k=[{x:t.rtl?m.l:m.r,y:v},{x:_,y:v},{x:_,y:L},{x:t.rtl?d.l:d.r,y:L}],c=t.rtl?"right":"left"}else{const x=p((Math.max(m.l,d.l)+Math.min(m.r,d.r))/2,o.ox,b);k=[{x,y:y?m.b:m.t},{x,y:y?d.t:d.b}],c=y?"down":"up"}}else{const y=S.stage>u.stage!=!!t.rtl,x=p((Math.max(m.t,d.t)+Math.min(m.b,d.b))/2,o.oy,b);k=[{x:y?m.r:m.l,y:x},{x:y?d.l:d.r,y:x}],c=y?"right":"left"}o.lines.push({i:h.i,from:h.from,to:h.to,kind:h.kind,pts:k,tip:k[k.length-1],dir:c,width:b})}const g=s.head,w=o.lines.map(h=>{const u=h.dir==="up"?{x:0,y:-1}:h.dir==="down"?{x:0,y:1}:h.dir==="left"?{x:-1,y:0}:{x:1,y:0},S=h.pts.map(y=>({...y})),m=S[S.length-1];m.x-=u.x*(g-1),m.y-=u.y*(g-1);const d=h.tip.x-u.x*g,b=h.tip.y-u.y*g,k=-u.y*(g/2),c=u.x*(g/2);return``}).join("");return{geo:o,ink:`${w}`}}function Ve(e,t){const a=O(t),s=[],n=(r,o)=>o?`${a.rules[r]}: ${o}`:a.rules[r];s.push(I(e,T(e,"main"),n("visibility",a.words.keyVisibility))),s.push(I(e,T(e,"dashed"),n("interaction",a.words.keyInteraction))),a.layers.includes("support")&&s.push(I(e,T(e,"dashed"),n("internal",a.words.keyInternal)));for(const r of["main","plain"])a.arrows.some(o=>o.kind===r)&&t.legend[r]&&s.push(I(e,me(e,r),t.legend[r],{"data-line":"","data-when":"drawn"}));return t.nodes.some(r=>r.focal)&&t.legend.focal&&s.push(I(e,Z(e),t.legend.focal,{"data-focal":""})),Y(e,s)}function Ye(e,t){const a=O(t),s=Math.min(6,t.heading+1);return a.stages.flatMap((n,r)=>[l(`h${s}`,{class:`${e}-list-head`},`${a.words.stage} ${r+1}: `,$(n.name),n.time?` (${n.time})`:""),l("ul",{class:`${e}-list-items`},a.layers.map(o=>{const i=a.cells.find(g=>g.stage===r&&g.layer===o),f=re(o),p=a.arrows.filter(g=>g.from===i.id).map(g=>B(t,g.to));return l("li",null,f?`${a.rules[f]}, then `:"",R(a.layerWords[o]),": ",i.empty?`${a.words.none.toLowerCase()}.`:[$(i.name),i.detail?`, ${i.detail}`:"","."],p.length?` To ${p.map(g=>g.stage===i.stage?g.name:`${g.name} (${H(a,g)})`).join(", ")}.`:"",z(t,i.focal))}))])}function Ze(e,t,a){const s=O(e),n=2*t.space("3")+2*t.hair;let r=t.node;s.stages.forEach((o,i)=>{r=Math.max(r,W(a,[[o.name,"name"],[`${s.words.stage} ${i+1}`,"mono",!0],[o.time,"tab"]]))});for(const o of s.cells)r=Math.max(r,n+W(a,[[o.name,"name"],[o.detail,o.mono?"mono":"sans"]]));return G(t,s.stages.length,r,X(e,t,a))}var C=e=>e.plan,le=(e,t)=>`${t} ${t===1?e.words.story.one:e.words.story.other}`;function Ge(e,t){const a=J(e,{activity:"Activity",noStories:"No stories",backbone:"Backbone activity",story:{one:"story",other:"stories"}}),s=(Array.isArray(e.activities)?e.activities:[]).map(d=>{const b=d;return{id:String(b.id??""),name:String(b.name??""),steps:Array.isArray(b.steps)?b.steps.map(String):[]}}),n=(Array.isArray(e.slices)?e.slices:[]).map(d=>{const b=d;return{id:String(b.id??""),label:String(b.label??"")}});t.dev&&n.some(d=>"cutAfter"in d)&&t.error("a story map has one cut: write `cut: { after, label }`, not a cut on a slice");const r=e.cut,o=r?n.findIndex(d=>d.id===String(r.after)):-1;t.dev&&r&&o<0&&t.error(`the cut comes after "${String(r.after)}", which is not a slice`),t.dev&&r&&!M(r.label)&&t.error("the cut needs its words (cut.label): the key must say what it divides");const i=r&&o>=0?{after:o,label:String(r.label??"")}:void 0,f=[];for(const d of Array.isArray(e.stories)?e.stories:[]){const b=s.findIndex(c=>c.id===String(d.activity)),k=n.findIndex(c=>c.id===String(d.slice));if(b<0||k<0){t.dev&&t.warn(`the story ${String(d.id)} names an activity or a slice that is not there`);continue}t.dev&&"tag"in d&&t.warn(`the story ${String(d.id)} has a "tag": its code is its \`kind\``),f.push({...de(d),activity:b,slice:k})}const p=n.flatMap((d,b)=>s.flatMap((k,c)=>f.filter(y=>y.slice===b&&y.activity===c)));let g=0;const w=new Map;n.forEach((d,b)=>{const k=Math.max(1,...s.map((c,y)=>f.filter(x=>x.slice===b&&x.activity===y).length));for(const[c]of s.entries())f.filter(y=>y.slice===b&&y.activity===c).forEach((y,x)=>w.set(y.id,g+x+1));g+=k});const h=p.map((d,b)=>ue(d,b,d.activity+1,w.get(d.id)??1));ne(t,h.map(d=>d.id)),t.dev&&h.filter(d=>d.focal).length>1&&t.warn("more than one story is focal: a story map has one at most");const u=n.map((d,b)=>({...d,count:f.filter(k=>k.slice===b).length,below:i!==void 0&&b>i.after})),S=[...u.map(d=>[d.label,"name"]),...u.map(d=>[le({words:a},d.count),"tab"])],m={persona:M(e.persona),activities:s,slices:u,stories:p,cut:i,words:a,labelWords:S};return{nodes:h,edges:[],plan:m,cols:Math.max(1,s.length),rows:Math.max(1,g)}}var Qe=(e,t)=>C(e).stories.find(a=>a.id===t);function Xe(e,t){const a=C(e),s=Qe(e,t.id),n=[A(s.kind?`${s.name}, ${s.kind}`:s.name),`${a.words.activity} ${s.activity+1}, ${a.activities[s.activity].name}. ${a.slices[s.slice].label}.`];return s.detail&&n.push(A(s.detail)),s.focal&&e.legend.focal&&n.push(A(e.legend.focal)),n.join(" ")}function ze(e,t){const a=C(t);return a.persona?l("p",{class:`${e}-meta`},l("span",{class:`${e}-meta-first`},$(a.persona))):null}function Ue(e,t,a,s){const n=C(t),r=[],o=n.activities.some(f=>f.steps.length);r.push(l("div",{class:`${e}-story-backbone`},n.activities.map((f,p)=>[l("div",{class:`${e}-story-activity`,style:`--_c:${p+2};--_r:1`},l("span",{class:`${e}-kind`},$(`${n.words.activity} ${p+1}`)),l("span",{class:`${e}-name`},$(f.name))),f.steps.length?l("span",{class:`${e}-story-steps`,style:`--_c:${p+2};--_r:2`},f.steps.map(g=>l("span",{class:`${e}-story-step`},$(g)))):null])));let i=o?3:2;return n.slices.forEach((f,p)=>{n.cut&&n.cut.after===p-1||r.push(l("span",{class:`${e}-matrix-rule`,style:`--_r:${i++}`,"aria-hidden":"true"})),r.push(l("section",{class:`${e}-story-slice`,"data-below":f.below?"":void 0},l("div",{class:`${e}-story-slice-head`,style:`--_r:${i}`},l("span",{class:`${e}-story-slice-name`},$(f.label)),l("span",{class:`${e}-story-count`},$(le(n,f.count)))),n.activities.map((g,w)=>{const h=n.stories.filter(u=>u.slice===p&&u.activity===w);return h.length?l("div",{class:`${e}-story-cell`,style:`--_c:${w+2};--_r:${i}`},h.map(u=>{const S=t.byId.get(u.id);return V(e,t,S,a,s,{class:`${e}-node ${e}-story-card`},...ae(e,u,l("span",{class:`${e}-kind`},l("span",{class:`${e}-story-of`},$(`${w+1} · ${g.name}`)),u.kind?l("span",{class:`${e}-story-code`},$(u.kind)):null)))})):l("div",{class:`${e}-story-slot`,style:`--_c:${w+2};--_r:${i}`},l("span",{class:`${e}-empty`},$(n.words.noStories)),l("span",{class:`${e}-story-left-out`},$(`${n.words.noStories} in ${g.name}`)))}))),i++,n.cut&&n.cut.after===p&&(r.push(l("div",{class:`${e}-story-cut`,style:`--_r:${i}`,"aria-hidden":"true"},l("span",{class:`${e}-story-cut-name`},$(n.cut.label)),l("span",{class:`${e}-story-cut-line`}))),i++)}),r}function Pe(e,t){const a=C(t),s=[];return a.cut&&s.push(I(e,T(e,"main"),a.cut.label)),s.push(I(e,T(e,"contour"),a.words.backbone)),t.nodes.some(n=>n.focal)&&t.legend.focal&&s.push(I(e,Z(e),t.legend.focal,{"data-focal":""})),Y(e,s)}function et(e,t){const a=C(t),s=Math.min(6,t.heading+1),n=[l(`h${s}`,{class:`${e}-list-head`},$(a.words.backbone)),l("ol",{class:`${e}-list-items`},a.activities.map(r=>l("li",null,R(r.name),r.steps.length?`: ${r.steps.join(", ")}.`:".")))];return a.slices.forEach((r,o)=>{n.push(l(`h${s}`,{class:`${e}-list-head`},$(r.label),`: ${le(a,r.count)}`));const i=a.stories.filter(p=>p.slice===o),f=a.activities.filter((p,g)=>!i.some(w=>w.activity===g));n.push(l("ul",{class:`${e}-list-items`},[...i.map(p=>l("li",null,`${a.activities[p.activity].name}: `,R(p.name),p.kind?`, ${p.kind}`:"",p.detail?`. ${A(p.detail)}`:".",z(t,p.focal))),...f.map(p=>l("li",null,`${a.words.noStories} in ${p.name}.`))])),a.cut&&a.cut.after===o&&n.push(l("p",{class:`${e}-list-group`},$(a.cut.label)))}),n}function tt(e,t,a){const s=C(e),n=2*t.space("3")+2*t.hair;let r=t.node;s.activities.forEach((o,i)=>{r=Math.max(r,n+W(a,[[o.name,"name"],[`${s.words.activity} ${i+1}`,"mono",!0]]),...o.steps.map(f=>W(a,[[f,"sans"]])+2*t.space("2-5")))});for(const o of s.stories)r=Math.max(r,n+W(a,[[o.name,"name"],[o.kind,"mono"],[o.detail,o.mono?"mono":"sans"]]));return r=Math.max(r,W(a,[[s.words.noStories,"sans"]])+n),G(t,s.activities.length,r,X(e,t,a))}var ie=()=>!1,ee=e=>({stop:`a ${e}`,hasStops:(t,a)=>!!(a.layout&&!a.bare),hint:(t,a)=>ce(t,a,e),keys:(t,a)=>we(t,a,e),rootStyle:xe}),pe,he,ye,$e;function at(){return pe??(pe={type:"kanban",build:Se,sentence:Me,key:_e,list:Ae,drawing:je,least:Le,layout:Q(),traces:ie,...ee("card")})}function st(){return he??(he={type:"journey",build:Ie,sentence:Ee,key:qe,list:Te,meta:Oe,drawing:Be,least:Ne,layout:Q(Ce),traces:ie,...ee("stage"),hint:(e,t)=>[{keys:t?["←","→"]:["↑","↓"],words:"a stage"},{keys:["Home","End"],words:"the ends"},...e.nodes.some(a=>a.href)?[{keys:["Enter"],words:"open"}]:[]]})}function nt(){return ye??(ye={type:"service-blueprint",build:Re,sentence:De,key:Ve,list:Ye,drawing:Fe,least:Ze,layout:Q(Je),...ee("cell"),traces:(e,t)=>t&&e.edges.length>0,hint:(e,t)=>[...ce(e,t,"cell"),...t&&e.edges.length?[{keys:["Esc"],words:"clear"}]:[]]})}function ot(){return $e??($e={type:"story-map",build:Ge,sentence:Xe,key:Pe,list:et,meta:ze,drawing:Ue,least:tt,layout:Q(),traces:ie,...ee("story")})}(function(e){"use strict";var t=e._,a=t.diagramTypes=t.diagramTypes||{};a.kanban=at,a.journey=st,a["service-blueprint"]=nt,a["story-map"]=ot})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-place.mjs b/.agent/skills/basalt-html/parts/diagram-place.mjs index 392458d8..71b2160b 100644 --- a/.agent/skills/basalt-html/parts/diagram-place.mjs +++ b/.agent/skills/basalt-html/parts/diagram-place.mjs @@ -35,7 +35,8 @@ import { workerData } from "node:worker_threads"; var W = 200; var H = 80; var STRAIGHT = "10"; -var options = (direction) => ({ +var options = (direction, longest = false) => ({ + ...longest ? { "elk.layered.layering.strategy": "LONGEST_PATH_SOURCE" } : {}, "elk.algorithm": "layered", "elk.direction": direction === "right" ? "RIGHT" : "DOWN", "elk.randomSeed": "1", @@ -48,11 +49,11 @@ var options = (direction) => ({ "elk.edgeRouting": "ORTHOGONAL" }); 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 cards = input.type === "schema" ? (input.tables ?? []).map((t) => ({ id: String(t.name) })) : input.type === "schedule" ? (input.tasks ?? []).map((t) => ({ id: String(t.id) })) : (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.type === "schedule" ? (input.tasks ?? []).flatMap((t) => (t.after ?? []).map((a) => ({ from: String(a), to: String(t.id), 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 ?? [] : [] }; + return { cards, lines, groups: input.type === "architecture" || input.type === "state" || input.type === "deployment" ? input.groups ?? [] : [] }; } function mainInTheMiddle(lines) { const bySource = /* @__PURE__ */ new Map(); @@ -72,7 +73,7 @@ function mainInTheMiddle(lines) { } return out; } -function graphOf(cards, lines, groups, direction) { +function graphOf(cards, lines, groups, direction, longest = false, inOrder = false) { 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 }); @@ -89,7 +90,15 @@ function graphOf(cards, lines, groups, 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) && !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 } } : {} })) }; + if (inOrder) { + const first = (n) => n.children ? Math.min(Infinity, ...n.children.map(first)) : cards.findIndex((c) => c.id === n.id); + const sort = (list) => { + list.sort((a, b) => first(a) - first(b)); + for (const n of list) if (n.children) sort(n.children); + }; + sort(children); + } + return { id: "root", layoutOptions: options(direction, longest), 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 @@ -154,7 +163,9 @@ function unusable(cards, groups, cells) { 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 longest = Boolean(input.dependents); + const inOrder = input.type === "state" || input.type === "deployment"; + const first = await cellsOf(graphOf(cards, lines, groups, direction, longest, inOrder)); const layer = (id) => direction === "down" ? first[id].row : first[id].col; const chain = (id) => { const out = []; @@ -189,7 +200,7 @@ async function placeDiagram(input, direction) { } 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 second = await cellsOf(graphOf(all, chained, groups, direction, longest, inOrder)); const cells = {}; for (const c of cards) cells[c.id] = second[c.id]; const layers = (c) => Math.max(1, ...cards.map((x) => direction === "down" ? c[x.id].row : c[x.id].col)); diff --git a/.agent/skills/basalt-html/parts/diagram-scale.js b/.agent/skills/basalt-html/parts/diagram-scale.js new file mode 100644 index 00000000..69536708 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-scale.js @@ -0,0 +1 @@ +(()=>{var O=Object.defineProperty,_=(n,t)=>{for(var o in t)O(n,o,{get:t[o],enumerable:!0})},T={};_(T,{clockLadder:()=>W,dateWords:()=>v,datesWords:()=>B,dayLadder:()=>D,dayNumber:()=>$,instantOf:()=>L,numberLadder:()=>S,roundOut:()=>Y,scaleMap:()=>U,ticks:()=>w,yearOf:()=>I});var h=864e5;function $(n){const t=typeof n=="string"?/^(\d{4})-(\d{2})-(\d{2})$/.exec(n.trim()):null;if(!t)return null;const o=Number(t[1]),a=Number(t[2]),c=Number(t[3]),s=Date.UTC(o,a-1,c),r=new Date(s);return r.getUTCFullYear()!==o||r.getUTCMonth()!==a-1||r.getUTCDate()!==c?null:Math.round(s/h)}function L(n){if(typeof n!="string")return null;const t=n.trim();if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2})$/.test(t))return null;const o=Date.parse(t);return Number.isFinite(o)?o:null}function P(n,t=[]){const[o,a]=n,c=t.map(([r,l])=>[Math.max(o,Math.min(r,l)),Math.min(a,Math.max(r,l))]).filter(([r,l])=>l>r).sort((r,l)=>r[0]-l[0]),s=[];for(const r of c){const l=s[s.length-1];l&&r[0]<=l[1]?l[1]=Math.max(l[1],r[1]):s.push([r[0],r[1]])}return s}function U(n){const[t,o]=n.domain,a=n.length,c=P(n.domain,n.breaks),s=c.length?Math.max(0,n.gap??0):0,r=!!n.reversed,l=c.reduce((i,[d,m])=>i+(m-d),0),e=o-t-l,f=e>0?(a-s*c.length)/e:0,u=i=>{if(!c.length)return o===t?0:(i-t)/(o-t)*a;let d=0,m=t;for(const[M,x]of c){if(i<=M)break;if(d+=(M-m)*f,ir?a-u(i):u(i),value:i=>{const d=r?a-i:i;if(!c.length)return a===0?t:t+d/a*(o-t);let m=0,M=t;for(const[x,j]of c){const N=(x-M)*f;if(d<=m+N)return M+(d-m)/f;if(m+=N,d<=m+s)return x;m+=s,M=j}return M+(d-m)/f}}}var g=(n,t,o=0)=>({name:n,approx:t,floor:a=>o+Math.floor((a-o)/t+1e-9)*t,next:a=>o+(Math.floor((a-o)/t+1e-9)+1)*t});function S(n,t){const o=[],a=Math.floor(Math.log10(Math.max(1e-9,n)))-1,c=Math.ceil(Math.log10(Math.max(1e-9,t)))+1;for(let s=a;s<=c&&o.length<200;s++)for(const r of[1,2,2.5,5]){const l=r*10**s,e=Number(l.toPrecision(12));o.push({...g(String(e),e),floor:f=>Number((Math.floor(f/e+1e-9)*e).toPrecision(12)),next:f=>Number(((Math.floor(f/e+1e-9)+1)*e).toPrecision(12))})}return o}var b=n=>{const t=new Date(n*h);return{y:t.getUTCFullYear(),m:t.getUTCMonth(),d:t.getUTCDate(),w:t.getUTCDay()}},C=(n,t,o=1)=>Math.round(Date.UTC(n,t,o)/h),k=(n,t,o)=>({name:n,approx:o,floor:a=>{const c=b(Math.floor(a)),s=c.y*12+c.m,r=s-(s%t+t)%t;return C(Math.floor(r/12),r%12)},next:a=>{const c=b(Math.floor(a)),s=c.y*12+c.m,r=s-(s%t+t)%t+t;return C(Math.floor(r/12),r%12)}});function D(){return[g("day",1),g("2 days",2),g("week",7,4),g("2 weeks",14,4),k("month",1,28),k("3 months",3,89),k("year",12,365)]}function W(n=()=>0){const t=e=>e+n(e)*6e4,o=e=>{const f=e-n(e)*6e4;return e-n(f)*6e4},a=(e,f)=>({name:e,approx:f,floor:u=>o(Math.floor(t(u)/f+1e-9)*f),next:u=>{let p=o((Math.floor(t(u)/f+1e-9)+1)*f);return p<=u&&(p=o((Math.floor(t(u)/f+1e-9)+2)*f)),p}}),l=[1,2,5,10,15,30].map(e=>a(`${e} s`,e*1e3));l.push(...[1,2,5,10,15,30].map(e=>a(`${e} min`,e*6e4)),...[1,2,3,6,12].map(e=>a(`${e} h`,e*36e5)));for(const e of D())l.push({name:e.name,approx:e.approx*h,floor:f=>o(e.floor(Math.floor(t(f)/h))*h),next:f=>o(e.next(Math.floor(t(f)/h))*h)});return l}function F(n,t,o){const[a,c]=n.domain,s=[];let r=t.floor(a);rr>f&&ro))return null;const e=t.next(r);if(!(e>r))break;r=e}return s}function w(n,t,o){const a=Math.floor(n.length/Math.max(1,o))+1;for(const c of t){if(c.approx*n.raten.position(e));let l=s.length<=a;for(let e=1;l&&e({value:e,place:r[f],step:c.name}))}return[]}function Y(n,t,o,a,c=[],s=0){const[r,l]=n;for(const e of t){const f=e.floor(r);let u=e.floor(l);uf||(u=e.next(f));const p=U({domain:[f,u],length:a,breaks:c,gap:s});if(!(e.approx*p.rate=2)return{domain:[f,u],step:e.name}}return null}var y,Z=(n,t)=>{y??(y=new Map);const o=`${n}|${t?"y":""}`;let a=y.get(o);return a||(a=new Intl.DateTimeFormat(n,t?{month:"short",day:"numeric",year:"numeric",timeZone:"UTC"}:{month:"short",day:"numeric",timeZone:"UTC"}),y.set(o,a)),a};function v(n,t=!1,o="en-US"){return Z(o,t).format(new Date(Math.floor(n)*h))}function B(n,t="en-US"){let o;return n.map(a=>{const c=b(Math.floor(a)).y,s=v(a,c!==o,t);return o=c,s})}var I=n=>b(Math.floor(n)).y;(function(n){"use strict";n._.diagramScale=T})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-schedule.css b/.agent/skills/basalt-html/parts/diagram-schedule.css new file mode 100644 index 00000000..038d3198 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-schedule.css @@ -0,0 +1 @@ +@layer basalt{.diagram[data-type=schedule]>.diagram-drawing{--_row-gap: var(--basalt-space-8);--_col-gap: var(--basalt-space-16)}.diagram[data-type=schedule] .diagram-node{padding:0;border-color:transparent;font-variant-numeric:tabular-nums}.diagram-sched-contour{position:absolute;inset:calc(-1 * var(--basalt-size-hairline));border:var(--basalt-size-hairline) solid var(--basalt-diagram-structure);border-radius:inherit;pointer-events:none}.diagram-sched-contour[data-critical]{border:var(--basalt-size-chart-line) solid var(--basalt-diagram-edge-main)}.diagram-node[data-focal]>.diagram-sched-contour{border-color:var(--basalt-diagram-focal)}.diagram-node[data-near]:not([data-focal])>.diagram-sched-contour:not([data-critical]){border-color:var(--basalt-border-hover)}.diagram-sched-head{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);padding:var(--basalt-space-2) var(--basalt-space-3);border-block-end:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-sched-head>.diagram-kind{display:flex;gap:var(--basalt-space-2)}.diagram-sched-dur{margin-inline-start:auto;color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-sans);white-space:nowrap}.diagram-sched-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));border-block-end:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-sched-cell{display:flex;align-items:baseline;justify-content:space-between;gap:var(--basalt-space-1-5);padding:var(--basalt-space-1-5) var(--basalt-space-3)}.diagram-sched-cell:nth-child(2n){border-inline-start:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-sched-cell:nth-child(n+3){border-block-start:var(--basalt-size-hairline) solid var(--basalt-border-divider)}.diagram-sched-k{color:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-sched-v{color:var(--basalt-text-primary);font:var(--basalt-font-weight-medium) var(--bh-xs)}.diagram-sched-foot{display:flex;align-items:baseline;justify-content:space-between;gap:var(--basalt-space-2);padding:var(--basalt-space-1-5) var(--basalt-space-3);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-sched-critical{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-semibold)}.diagram-sched-after{--_Sa: var(--_D) none;display:var(--_Sa, block);padding:var(--basalt-space-1-5) var(--basalt-space-3);border-block-start:var(--basalt-size-hairline) solid var(--basalt-border-divider);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-node[data-focal] :is(.diagram-sched-head,.diagram-sched-grid,.diagram-sched-cell,.diagram-sched-after){border-color:var(--basalt-diagram-focal-rule)}.diagram-node[data-focal] :is(.diagram-sched-dur,.diagram-sched-k,.diagram-sched-v,.diagram-sched-foot,.diagram-sched-critical,.diagram-sched-after){color:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal] :is(.diagram-sched-dur,.diagram-sched-k,.diagram-sched-foot,.diagram-sched-after){opacity:var(--basalt-opacity-amount)}.diagram .diagram-swatch-task{fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline)}.diagram .diagram-swatch-task[data-critical]{stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-chart-line)}@media(prefers-contrast:more){.diagram-node[data-focal] :is(.diagram-sched-dur,.diagram-sched-k,.diagram-sched-foot,.diagram-sched-after){opacity:1}}@media(forced-colors:active){.diagram-sched-contour{border-color:CanvasText}.diagram .diagram-swatch-task{stroke:CanvasText}}} diff --git a/.agent/skills/basalt-html/parts/diagram-schedule.js b/.agent/skills/basalt-html/parts/diagram-schedule.js new file mode 100644 index 00000000..1058e331 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-schedule.js @@ -0,0 +1 @@ +(()=>{var B=s=>s==null||s===""?void 0:String(s),I=s=>{const n=s.trim();return n?/[.!?]$/.test(n)?n:`${n}.`:""};function o(s,n,...a){const e=[];for(const i of a.flat(1/0))i!=null&&i!==!1&&!Array.isArray(i)&&e.push(i);return{t:s,a:n??{},c:e}}var T=(s,n)=>({width:s,height:n,viewBox:`0 0 ${s} ${n}`,"aria-hidden":"true",focusable:"false"});function Z(s,n){const a=n==="fk"?"plain":n,e=a==="main"?8:8.5,i=24,l=a==="dashed"?i-1:i-7;return o("svg",{class:`${s}-swatch`,"data-kind":a,...T(24,16)},n==="fk"?o("circle",{class:`${s}-dot`,cx:3,cy:e,r:3}):null,o("path",{class:`${s}-line`,"data-kind":a,d:`M${n==="fk"?3:0} ${e}H${l}`}),a==="dashed"?o("path",{class:`${s}-tip`,"data-kind":a,"data-open":"",d:`M${i-8} ${e-4}L${i} ${e}L${i-8} ${e+4}`}):o("path",{class:`${s}-tip`,"data-kind":a,d:`M${i} ${e}L${i-8} ${e-4}L${i-8} ${e+4}Z`}))}var A=s=>o("bdi",null,s),b=1e6,Y=s=>Math.round(s*b);function h(s){const n=s<0?"-":"",a=Math.abs(s),e=Math.floor(a/b),i=a%b,l=String(e).replace(/\B(?=(\d{3})+(?!\d))/g,",");return i?`${n}${l}.${String(i).padStart(6,"0").replace(/0+$/,"")}`:`${n}${l}`}var m=s=>s.plan,P=(s,n)=>typeof s.unit=="string"?s.unit:n===b?s.unit.one:s.unit.other,p=(s,n)=>`${h(n)} ${P(s,n)}`;function tt(s,n){const{dev:a,error:e,warn:i}=n,l=s.labels??{},d={finishes:l.finishes??"Finishes at",criticalPath:l.criticalPath??{one:"critical path",other:"critical paths"},assumptions:l.assumptions??"Finish to start, no lag, no calendar. A box's width is not its length.",critical:l.critical??"Critical",float:l.float??"Float",keyMain:l.keyMain??"This finish sets that start, on a critical path",keyPlain:l.keyPlain??"Comes before, with time to spare",keyCritical:l.keyCritical??"Critical task",keyFloat:l.keyFloat??"Task with float",keyNumbers:l.keyNumbers??"ES, EF: earliest start and finish · LS, LF: latest start and finish",starts:l.starts??"Starts the schedule."},k=s.unit;a&&!k&&e("a schedule needs its unit: one unit for every duration");const _=k??"";a&&Array.isArray(s.edges)&&s.edges.length&&e("a schedule's lines are its tasks' `after`: write no `edges` (a side is derived)");const f=Array.isArray(s.tasks)?s.tasks:[],J=new Set;let u=!1;for(const t of f){const r=String(t.id??"");(!r||J.has(r))&&(u=!0,a&&i(r?`the id "${r}" is used twice`:"a task has no id")),J.add(r)}const S=new Map;for(const t of f){const r=typeof t.duration=="number"?t.duration:Number.NaN;!Number.isFinite(r)||r<=0?(u=!0,a&&e(`${String(t.id)}'s duration is ${JSON.stringify(t.duration)}: it is a positive number`),S.set(String(t.id),b)):S.set(String(t.id),Y(r))}const y=new Map(f.map(t=>[String(t.id),[]])),L=new Map(f.map(t=>[String(t.id),[]])),N=[];for(const t of f)for(const r of Array.isArray(t.after)?t.after.map(String):[]){if(!J.has(r)){u=!0,a&&e(`${String(t.id)} comes after "${r}", which is not a task`);continue}y.get(String(t.id)).includes(r)||(y.get(String(t.id)).push(r),L.get(r).push(String(t.id)),N.push([r,String(t.id)]))}const E=new Map(f.map(t=>[String(t.id),y.get(String(t.id)).length])),O=f.map(t=>String(t.id)).filter(t=>E.get(t)===0),w=[];for(;O.length;){const t=O.shift();w.push(t);for(const r of L.get(t))E.set(r,E.get(r)-1),E.get(r)===0&&O.push(r)}w.lengthString(t.id)).filter(t=>!w.includes(t)).join(", ")}): its passes cannot finish`));const H=new Map,$=new Map,W=new Map,F=new Map;for(const t of w){const r=Math.max(0,...y.get(t).map(c=>$.get(c)));H.set(t,r),$.set(t,r+S.get(t))}const q=Math.max(0,...w.map(t=>$.get(t)));for(const t of[...w].reverse()){const r=Math.min(q,...L.get(t).map(c=>W.get(c)));F.set(t,r),W.set(t,r-S.get(t))}const C=t=>!u&&F.get(t)-$.get(t)===0,R=(t,r)=>!u&&$.get(t)===H.get(r),U=(t,r)=>C(t)&&C(r)&&R(t,r),z=new Map,V=t=>{if(z.has(t))return z.get(t);const r=L.get(t).filter(g=>U(t,g)),c=r.length?r.reduce((g,M)=>g+V(M),0):$.get(t)===q?1:0;return z.set(t,c),c},ot=u?0:w.filter(t=>C(t)&&!y.get(t).length).reduce((t,r)=>t+V(r),0),X=f.map((t,r)=>{const c=String(t.id);return{id:c,i:r,name:String(t.name??""),kind:B(t.kind),d:S.get(c),es:H.get(c)??0,ef:$.get(c)??0,ls:W.get(c)??0,lf:F.get(c)??0,float:u?0:(F.get(c)??0)-($.get(c)??0),critical:C(c),after:y.get(c).map(g=>({id:g,sets:R(g,c)})),focal:!!t.focal}}),K=s.layout==="auto",v=f.map((t,r)=>{const c=typeof t.col=="number"&&Number.isInteger(t.col)&&t.col>=1?t.col:(a&&!K&&e(`${String(t.id)}'s col is ${JSON.stringify(t.col)}, not a whole number from 1`),1),g=typeof t.row=="number"&&Number.isInteger(t.row)&&t.row>=1?t.row:(a&&!K&&e(`${String(t.id)}'s row is ${JSON.stringify(t.row)}, not a whole number from 1`),1);return{id:String(t.id),i:r,name:String(t.name??""),kind:B(t.kind),mono:!1,focal:!!t.focal,col:c,row:g,row2:g,branch:!1,shape:"box",href:B(t.href),blank:t.target==="_blank"}});if(a&&!K)for(const[t,r]of N){const c=v.find(M=>M.id===t);v.find(M=>M.id===r).col<=c.col&&e(`${r} is not in a later column than ${t}, which it comes after`)}if(a)for(const[t,r]of N)f.findIndex(c=>String(c.id)===r)String(c.id)===t)&&i(`${r} is listed before ${t}, which it comes after: the stack is in the author's order`);a&&X.filter(t=>t.focal).length>1&&i("more than one task is focal: a schedule has one at most"),a&&n.legend.focal&&/\bcritical\b|zero float|float 0/i.test(n.legend.focal)&&i("the focal task's words say what a critical task is: the focal task is the author's own, and its words must say something else");const lt=u?[]:N.map(([t,r],c)=>({i:c,from:t,to:r,kind:U(t,r)?"main":"plain"}));return{nodes:v,edges:lt,plan:{tasks:X,unit:_,finish:q,paths:ot,bad:u,words:d},cols:Math.max(1,...v.map(t=>t.col)),rows:Math.max(1,...v.map(t=>t.row))}}var D=(s,n)=>m(s).tasks.find(a=>a.id===n),G=(s,n)=>{const a=s.tasks.find(e=>e.id===n);return s.tasks.every(e=>e.kind)?a.kind:a.name},x=s=>s.length<2?s.join(""):`${s.slice(0,-1).join(", ")} and ${s[s.length-1]}`;function j(s,n){if(!n.after.length)return s.words.starts;const a=n.after.map(i=>G(s,i.id));if(s.bad)return`After ${x(a)}.`;const e=n.after.filter(i=>i.sets).map(i=>G(s,i.id));return n.after.length===1?e.length?`After ${a[0]}, which sets its start.`:`After ${a[0]}.`:e.length===n.after.length?`After ${x(a)}. ${e.length===2?"Both set":"All set"} its start.`:`After ${x(a)}. ${x(e)} ${e.length===1?"sets":"set"} its start.`}function st(s,n){const a=m(s),e=D(s,n.id),i=[I(e.kind?`${e.name}, ${e.kind}`:e.name),`${p(a,e.d)}.`];return a.bad||(i.push(`Earliest start ${h(e.es)}, earliest finish ${h(e.ef)}, latest start ${h(e.ls)}, latest finish ${h(e.lf)}.`),i.push(e.critical?`${a.words.float} 0, ${a.words.critical.toLowerCase()}.`:`${a.words.float} ${p(a,e.float)}.`)),i.push(j(a,e)),e.focal&&s.legend.focal&&i.push(I(s.legend.focal)),i.join(" ")}function et(s,n,a){const e=m(n),i=D(n,a.id),l=(d,k)=>o("span",{class:`${s}-sched-cell`},o("span",{class:`${s}-sched-k`},d),o("span",{class:`${s}-sched-v`},h(k)));return[o("span",{class:`${s}-sched-contour`,"data-critical":i.critical?"":void 0,"aria-hidden":"true"}),o("span",{class:`${s}-sched-head`},o("span",{class:`${s}-kind`},i.kind?A(i.kind):null,o("span",{class:`${s}-sched-dur`},p(e,i.d))),o("span",{class:`${s}-name`},A(i.name))),e.bad?null:o("span",{class:`${s}-sched-grid`},l("ES",i.es),l("EF",i.ef),l("LS",i.ls),l("LF",i.lf)),e.bad?null:o("span",{class:`${s}-sched-foot`},o("span",null,i.critical?`${e.words.float} 0`:`${e.words.float} ${p(e,i.float)}`),i.critical?o("span",{class:`${s}-sched-critical`},e.words.critical):null),o("span",{class:`${s}-sched-after`},j(e,i))]}function at(s,n){const a=m(n);if(a.bad)return null;const e=`${a.paths} ${a.paths===1?a.words.criticalPath.one:a.words.criticalPath.other}`;return o("p",{class:`${s}-meta`},o("span",{class:`${s}-meta-first`},`${a.words.finishes} ${p(a,a.finish)}`),` · ${e}. `,a.words.assumptions)}function nt(s,n){const a=m(n),e=(d,k,_={})=>o("li",{class:`${s}-entry`,..._},d,o("span",null,A(k))),i=d=>o("svg",{class:`${s}-swatch`,...T(16,16)},o("rect",{class:`${s}-swatch-task`,"data-critical":d?"":void 0,x:d?1:.5,y:d?3:2.5,width:d?14:15,height:d?10:11,rx:2})),l=[];return n.edges.some(d=>d.kind==="main")&&l.push(e(Z(s,"main"),n.legend.main??a.words.keyMain,{"data-line":"","data-when":"drawn"})),n.edges.some(d=>d.kind==="plain")&&l.push(e(Z(s,"plain"),n.legend.plain??a.words.keyPlain,{"data-line":"","data-when":"drawn"})),a.tasks.some(d=>d.critical)&&l.push(e(i(!0),a.words.keyCritical)),a.tasks.some(d=>!d.critical)&&l.push(e(i(!1),a.words.keyFloat)),a.bad||l.push(o("li",{class:`${s}-entry`,"data-words":""},o("span",null,a.words.keyNumbers))),n.nodes.some(d=>d.focal)&&n.legend.focal&&l.push(e(o("svg",{class:`${s}-swatch`,"data-shape":"focal",...T(16,16)},o("rect",{class:`${s}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2})),n.legend.focal,{"data-focal":""})),l.length?o("div",{class:`${s}-key`},o("ul",{class:`${s}-legend`,"aria-label":"Key"},l)):null}function it(s,n){const a=m(n);return[o("ol",{class:`${s}-list-items`},a.tasks.map(e=>o("li",null,o("strong",null,A(e.name)),e.kind?[", ",o("code",{class:`${s}-code`},e.kind)]:"",`: ${p(a,e.d)}. `,a.bad?"":`Earliest start ${h(e.es)} and finish ${h(e.ef)}; latest start ${h(e.ls)} and finish ${h(e.lf)}; ${a.words.float.toLowerCase()} ${e.critical?"0, critical":p(a,e.float)}. `,j(a,e),e.focal&&n.legend.focal?` ${I(n.legend.focal)}`:"")))]}var Q;function rt(){return Q??(Q={type:"schedule",routed:!0,stackBare:!0,build:tt,stop:"a task",sentence:st,card:(s,n,a,e)=>et(s,n,a),meta:at,key:nt,list:it,traces:(s,n)=>n&&s.edges.length>0,keys:(s,n)=>`${n?"Arrow keys move to the nearest task in that direction":"Arrow keys move to the next or the previous task, in the author's order"}; Home and End go to the ends; Escape clears the trace.${s.nodes.some(a=>a.href)?" Enter opens a task that is a link.":""}`})}(function(s){"use strict";var n=s._;(n.diagramTypes=n.diagramTypes||{}).schedule=rt})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-state.css b/.agent/skills/basalt-html/parts/diagram-state.css new file mode 100644 index 00000000..c2666bd6 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-state.css @@ -0,0 +1 @@ +@layer basalt{.diagram[data-type=state]>.diagram-drawing{--_row-gap: var(--basalt-space-16);--_col-gap: calc(var(--basalt-space-16) + var(--basalt-space-4))}.diagram-gbox[data-start=top]{margin-block-start:calc(-1 * var(--_gt, 1) * var(--basalt-space-8) - var(--basalt-space-10))}.diagram[data-type=state][data-layout=drawn] .diagram-node[data-room]{margin-block-start:var(--basalt-space-10)}.diagram-group[data-start]{padding-block-start:var(--basalt-space-16)}.diagram[data-type=state]>.diagram-drawing>.diagram-node[data-initial]{margin-block-start:var(--_Mt, calc(var(--_gap, var(--basalt-space-0)) + var(--basalt-space-8)))}.diagram .diagram-start-dot,.diagram .diagram-start-tip{fill:var(--basalt-diagram-edge)}.diagram .diagram-start-line{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline)}.diagram-node>.diagram-final{position:absolute;inset-block-start:var(--basalt-space-2-5);inset-inline-end:var(--basalt-space-3);width:var(--basalt-space-3-5);height:var(--basalt-space-3-5)}.diagram .diagram-final circle{fill:none;stroke:var(--basalt-diagram-edge-main);stroke-width:var(--basalt-size-hairline)}.diagram .diagram-final circle[data-dot]{fill:var(--basalt-diagram-edge-main);stroke:none}.diagram-node[data-focal]>.diagram-final circle{stroke:var(--basalt-diagram-focal-ink)}.diagram-node[data-focal]>.diagram-final circle[data-dot]{fill:var(--basalt-diagram-focal-ink)}.diagram-node[data-final]>:is(.diagram-kind,.diagram-name):first-child{padding-inline-end:var(--basalt-space-6)}.diagram-actions{display:flex;flex-direction:column;gap:var(--basalt-space-0-5);margin-block-start:var(--basalt-space-2);padding-block-start:var(--basalt-space-1-5);border-block-start:var(--basalt-size-hairline) solid var(--basalt-border-divider);color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}.diagram-node[data-focal]>.diagram-actions{border-color:var(--basalt-diagram-focal-rule);color:var(--basalt-diagram-focal-ink)}.diagram-key-letters[data-numbers]{font-family:var(--basalt-font-family-mono)}@media(forced-colors:active){.diagram :is(.diagram-start-dot,.diagram-start-tip){fill:CanvasText}.diagram .diagram-start-line{stroke:CanvasText}.diagram .diagram-final{forced-color-adjust:none}.diagram .diagram-final circle{stroke:CanvasText}.diagram .diagram-final circle[data-dot]{fill:CanvasText}.diagram .diagram-node[data-focal]>.diagram-final circle{stroke:Canvas}.diagram .diagram-node[data-focal]>.diagram-final circle[data-dot]{fill:Canvas}}@media print{.diagram .diagram-final,.diagram .diagram-start{-webkit-print-color-adjust:exact;print-color-adjust:exact}}} diff --git a/.agent/skills/basalt-html/parts/diagram-state.js b/.agent/skills/basalt-html/parts/diagram-state.js new file mode 100644 index 00000000..ea463112 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-state.js @@ -0,0 +1,2 @@ +(()=>{var m=t=>t==null||t===""?void 0:String(t),N=t=>{const n=t.trim();return n?/[.!?]$/.test(n)?n:`${n}.`:""};function o(t,n,...e){const r=[];for(const s of e.flat(1/0))s!=null&&s!==!1&&!Array.isArray(s)&&r.push(s);return{t,a:n??{},c:r}}var Z=(t,n)=>({width:t,height:n,viewBox:`0 0 ${t} ${n}`,"aria-hidden":"true",focusable:"false"}),u=t=>o("bdi",null,t);function G(t,n){if(!n.href)return u(n.name);const e=n.name.trimEnd().lastIndexOf(" ");return[e<0?"":n.name.slice(0,e+1),o("span",{class:`${t}-name-end`},e<0?n.name:n.name.slice(e+1))]}function D(t,n,e){if(e.shape==="decision")return[o("span",{class:`${t}-words`},n.type==="data-flow"&&e.kind?o("span",{class:`${t}-kind`},u(e.kind)):null,o("span",{class:`${t}-name`},G(t,e)))];const r=[];return n.type==="data-flow"?r.push(o("span",{class:`${t}-kind`},u(e.kind),o("span",{class:`${t}-lane-word`}," · ",u(e.laneLabel??"")))):e.kind&&r.push(o("span",{class:`${t}-kind`},u(e.kind))),r.push(o("span",{class:`${t}-name`},G(t,e))),e.detail&&r.push(o("span",{class:`${t}-detail`,"data-mono":e.mono?"":void 0},e.mono?o("span",{class:`${t}-runs`},F(e.detail).flatMap((s,i)=>[i?" ":"",o("span",{class:`${t}-run`},s)])):u(e.detail))),r}var F=t=>t?t.split(/\s+/).filter(Boolean):[],R=28,g=t=>Math.round(t*100)/100,J=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth"];function K(t,n,e){const{dev:r,error:s}=e;r&&t.label!==void 0&&s(`the transition from ${String(t.from)} to ${String(t.to)} has a label: a state's label is the engine's, from its event, guard and action`);const i=m(t.event),f=m(t.guard),$=m(t.action);r&&!i&&!f&&s(`the transition from ${String(t.from)} to ${String(t.to)} has neither an event nor a guard`);const c=i?`${n?`${n}. `:""}${i}`:void 0,b=[f?`[${f}]`:"",$?`/ ${$}`:""].filter(Boolean).join(" ")||void 0,w=[c,b].filter(a=>!!a);for(const a of w)r&&a.length>R&&s(`the line "${a}" of a transition's label is over ${R} characters: the words belong in the state or the summary`);return w.length?w.join(` +`):void 0}function Q(t,n){const{dev:e,error:r,warn:s}=n,i=Array.isArray(t.nodes)?t.nodes:[],f=new Set((Array.isArray(t.groups)?t.groups:[]).map(a=>String(a.id)));if(e){const a=new Map;for(const d of i)if(d.initial){const l=String(d.group??"");a.set(l,[...a.get(l)??[],String(d.id)])}for(const[d,l]of a)l.length>1&&r(`${l.join(" and ")} are each initial ${d?`in the group ${d}`:"outside the groups"}: one at most`);for(const d of i)d.initial&&d.final&&r(`${String(d.id)} is both initial and final`)}const $=Array.isArray(t.edges)?t.edges:[],c=new Map,b=new Map;$.forEach((a,d)=>{const l=m(a.event);if(l){const y=`${String(a.from)}\0${l}`;b.set(y,[...b.get(y)??[],d])}});for(const a of b.values())a.length>1&&(a.forEach((d,l)=>c.set(d,l+1)),e&&a.slice(0,-1).forEach(d=>{m($[d].guard)||s(`the transition from ${String($[d].from)} on ${String($[d].event)} has no guard and is not the last on its event: the later ones can never be taken`)}));const w=$.flatMap((a,d)=>f.has(String(a.from))||f.has(String(a.to))?(e&&r(`the transition from ${String(a.from)} to ${String(a.to)} names a composite state: a line to a group's boundary is not drawn in this build`),[]):[{from:a.from,to:a.to,kind:a.kind,fromSide:a.fromSide,toSide:a.toSide,label:K(a,c.get(d),n),event:m(a.event),guard:m(a.guard),action:m(a.action),order:c.get(d)}]);return{...t,nodes:i.map(a=>({...a,mark:void 0})),edges:w}}function U(t,n){for(const r of n.nodes??[]){const s=t.byId.get(String(r.id));s&&(s.initial=r.initial===!0||void 0,s.final=r.final===!0||void 0,s.entry=m(r.entry),s.exit=m(r.exit))}let e=0;for(const r of n.edges??[]){if(!t.byId.has(String(r.from))||!t.byId.has(String(r.to)))continue;const s=t.edges[e++];s&&(s.event=r.event,s.guard=r.guard,s.action=r.action,s.order=r.order)}}var X=(t,n=`${t}-final`)=>o("svg",{class:n,...Z(14,14)},o("circle",{cx:7,cy:7,r:6.5}),o("circle",{cx:7,cy:7,r:3,"data-dot":""}));function V(t,n,e){return[...D(t,n,e),e.entry||e.exit?o("span",{class:`${t}-actions`},e.entry?o("span",{class:`${t}-action`},"entry / ",u(e.entry)):null,e.exit?o("span",{class:`${t}-action`},"exit / ",u(e.exit)):null):null,e.final?X(t):null]}function W(t,n){const e=[],r=(s,i)=>e.push(o("li",{class:`${t}-entry`},s,o("span",null,u(i))));return n.nodes.some(s=>s.initial)&&r(o("svg",{class:`${t}-swatch`,...Z(24,16)},o("circle",{class:`${t}-start-dot`,cx:4,cy:8.5,r:4}),o("path",{class:`${t}-start-line`,d:"M8 8.5H17"}),o("path",{class:`${t}-start-tip`,d:"M24 8.5L16 4.5L16 12.5Z"})),"Starts here"),n.nodes.some(s=>s.final)&&r(X(t,`${t}-swatch ${t}-final`),"Ends here"),n.edges.some(s=>s.order)&&e.push(o("li",{class:`${t}-entry`},o("span",{class:`${t}-key-letters`,"data-numbers":"","aria-hidden":"true"},"1. 2."),o("span",null,"Tried in this order: the first that holds is taken"))),e}function Y(t,n,e){const r=i=>o("code",{class:`${t}-code`},u(i)),s=i=>o("strong",null,u(n.byId.get(i)?.name??i));return[e("Transitions"),o("ol",{class:`${t}-list-items`},n.edges.map(i=>o("li",null,s(i.from),": ",i.event?["On ",r(i.event)]:"",i.guard?[i.event?", if ":"If ",r(i.guard)]:"",i.action?[", then ",r(i.action)]:"",": to ",s(i.to),n.legend[i.kind]?` (${n.legend[i.kind]})`:"",".",i.order?` Tried ${J[i.order-1]??`number ${i.order}`}.`:"")))]}var A=t=>!!(t.initial&&t.group),q=t=>new Set(t.nodes.filter(n=>A(n)&&n.row>1&&n.row===Math.min(...t.nodes.filter(e=>e.group===n.group).map(e=>e.row))).map(n=>n.row)),L=(t,n)=>t.ln.l&&t.tn.t;function P(t,n,e,r,s,i){const f=r.space,$=f(s?"10":"8"),c=r.head/2;let b="";const w=[];for(const a of e.nodes){const d=n.byId.get(a.id);if(!d?.initial)continue;const l=a.rect,y=!s||n.dir==="down"||A(d),nt=e.lines.flatMap(h=>[h.pts[0],h.pts[h.pts.length-1]]).filter(h=>y?Math.abs(h.y-l.t)<1.5&&h.x>=l.l-1&&h.x<=l.r+1:Math.abs(h.x-(n.rtl?l.r:l.l))<1.5&&h.y>=l.t-1&&h.y<=l.b+1),C=y?l.l:l.t,et=y?l.r:l.b,rt=h=>C+(et-C)*h,st=s?(y&&n.rtl?[.5,.75,.25]:[.5,.25,.75]).map(rt):[n.rtl?l.r-f("8"):l.l+f("8")];let O=null;for(const h of st){if(s&&!nt.every(H=>Math.abs((y?H.x:H.y)-h)>=f("4")))continue;const I=Math.round(h-.5)+.5,v=y?{x:I,y:l.t-$+c}:{x:n.rtl?l.r+$-c:l.l-$+c,y:I},p=y?{x:I,y:l.t}:{x:n.rtl?l.r:l.l,y:I},M={l:Math.min(v.x,p.x)-c-f("1"),r:Math.max(v.x,p.x)+c+f("1"),t:Math.min(v.y,p.y)-c-f("1"),b:Math.max(v.y,p.y)+c+f("1")},E={l:M.l,r:M.r,t:M.t,b:y?p.y-1:M.b};if(s&&(e.lines.some(x=>x.pts.slice(1).some((B,at)=>{const T=x.pts[at];return L(E,{l:Math.min(T.x,B.x)-x.width/2,r:Math.max(T.x,B.x)+x.width/2,t:Math.min(T.y,B.y)-x.width/2,b:Math.max(T.y,B.y)+x.width/2})}))||e.labels.some(x=>L(E,x.box))||w.some(x=>L(E,x))))continue;w.push(M);const k=Math.sign(p.x-v.x),S=Math.sign(p.y-v.y),_=p.x-k*r.head,j=p.y-S*r.head;O=``;break}if(O===null)return i?.(`the start mark of ${d.name} has no place clear of the lines, the labels and the other marks, so the figure is stacked`),!1;b+=O}return b}var z;function tt(){return z??(z={type:"state",as:"architecture",routed:!0,stop:"a state",prepare:Q,adopt:U,card:(t,n,e)=>V(t,n,e),sentenceMore:(t,n)=>[n.initial?"The machine starts here.":"",n.final?"It ends here.":"",n.entry?`On entry: ${N(n.entry)}`:"",n.exit?`On exit: ${N(n.exit)}`:""].filter(Boolean),keyMore:W,listParts:"States",listPart:(t,n,e)=>{const r=s=>o("code",{class:`${t}-code`},u(s));return[e.initial?" The machine starts here.":"",e.final?" It ends here.":"",e.entry?[" On entry: ",r(e.entry),"."]:"",e.exit?[" On exit: ",r(e.exit),"."]:""]},listLines:Y,groupMark:(t,n,e)=>{if(!e){const r=t.nodes.find(s=>n.all.includes(s.id));return r?.initial&&r.group===n.id?{start:""}:void 0}return e.r1===1&&n.all.some(r=>{const s=t.byId.get(r);return A(s)&&s.row===1})?{start:"top"}:void 0},room:t=>{const n=t.nodes.find(e=>e.initial&&!e.group);return{start:!!(n&&t.dir!=="down"&&n.col===(t.rtl?t.cols:1)),top:!!(n&&t.dir==="down"&&n.row===1||t.nodes.some(e=>A(e)&&e.row===1))}},nodeAttrs:(t,n)=>({"data-initial":n.initial?"":void 0,"data-final":n.final?"":void 0,"data-room":q(t).has(n.row)?"":void 0}),inkMore:P})}(function(t){"use strict";var n=t._;(n.diagramTypes=n.diagramTypes||{}).state=tt})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram-timeline.css b/.agent/skills/basalt-html/parts/diagram-timeline.css new file mode 100644 index 00000000..b2078d45 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-timeline.css @@ -0,0 +1 @@ +@layer basalt{.diagram[data-type=timeline]>.diagram-drawing{--_Td: var(--_D) block;display:var(--_Td, flex);flex-direction:column;gap:var(--basalt-space-3)}.diagram[data-type=timeline][data-layout=drawn]>.diagram-drawing{height:var(--_th);max-width:var(--_tdw, none)}.diagram-tl-card{margin-inline-start:var(--_Tm, var(--basalt-space-8));--_Tm: var(--_D) 0}.diagram[data-type=timeline][data-layout=drawn] .diagram-tl-card{position:absolute;left:var(--_tx, 0);top:var(--_ty, 0);width:var(--_tw)}.diagram-tl-line{white-space:nowrap}.diagram-node[data-focal] :is(.diagram-tl-time,.diagram-tl-gap){color:var(--basalt-diagram-focal-ink)}.diagram-tl-time{color:var(--basalt-text-secondary);font-family:var(--basalt-font-family-sans);font-weight:var(--basalt-font-weight-medium);font-variant-numeric:tabular-nums}.diagram-tl-gap{--_Tg: var(--_D) none;display:var(--_Tg, inline);color:var(--basalt-text-tertiary);font-family:var(--basalt-font-family-sans);font-variant-numeric:tabular-nums}.diagram-tl-break{--_Tb: var(--_D) none;display:var(--_Tb, flex);align-items:center;gap:var(--basalt-space-2);margin:0;margin-inline:var(--basalt-space-8) 0}.diagram-tl-break:after{content:"";flex:1 1 auto;border-block-start:var(--basalt-size-hairline) dashed var(--basalt-diagram-structure)}.diagram-tl-break-words{flex:none;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums}.diagram :is(.diagram-tl-axis,.diagram-tl-tick,.diagram-tl-stem){fill:none;stroke:var(--basalt-diagram-structure);stroke-width:var(--basalt-size-hairline);transition:stroke var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram .diagram-tl-slash{fill:none;stroke:var(--basalt-diagram-edge);stroke-width:var(--basalt-size-hairline);stroke-linecap:round}.diagram .diagram-tl-dot{fill:var(--basalt-diagram-edge);transition:fill var(--basalt-duration-fast) var(--basalt-ease-out)}.diagram .diagram-tl-stem[data-lit]{stroke:var(--basalt-diagram-edge-main)}.diagram .diagram-tl-dot[data-lit]{fill:var(--basalt-diagram-edge-main)}text.diagram-tl-tick-text{fill:var(--basalt-chart-axis);font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums}text.diagram-tl-break-text{fill:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums}:is(text.diagram-tl-tick-text,text.diagram-tl-break-text,text.diagram-tl-zone,text.diagram-gantt-tick,text.diagram-gantt-today){direction:ltr}text.diagram-tl-zone{fill:var(--basalt-text-tertiary);font:var(--basalt-font-weight-regular) var(--bh-xs-mono)}@media(prefers-reduced-motion:reduce){.diagram :is(.diagram-tl-stem,.diagram-tl-dot){transition:none}}@media(forced-colors:active){.diagram :is(.diagram-tl-axis,.diagram-tl-tick,.diagram-tl-stem,.diagram-tl-slash){stroke:CanvasText}.diagram .diagram-tl-dot{fill:CanvasText}.diagram .diagram-tl-stem[data-lit]{stroke:Highlight}.diagram .diagram-tl-dot[data-lit]{fill:Highlight}.diagram :is(text.diagram-tl-tick-text,text.diagram-tl-break-text,text.diagram-tl-zone){fill:CanvasText}.diagram .diagram-tl-break:after{border-color:CanvasText}}} diff --git a/.agent/skills/basalt-html/parts/diagram-timeline.js b/.agent/skills/basalt-html/parts/diagram-timeline.js new file mode 100644 index 00000000..d88b0a71 --- /dev/null +++ b/.agent/skills/basalt-html/parts/diagram-timeline.js @@ -0,0 +1 @@ +(()=>{var q=t=>t==null||t===""?void 0:String(t),tt=(t,n)=>t&&Object.prototype.hasOwnProperty.call(t,n)?t[n]:void 0,F=t=>{const n=t.trim();return n?/[.!?]$/.test(n)?n:`${n}.`:""};function v(t,n,...e){const o=[];for(const a of e.flat(1/0))a!=null&&a!==!1&&!Array.isArray(a)&&o.push(a);return{t,a:n??{},c:o}}var it={"&":"&","<":"<",">":">",'"':""","'":"'"},E=t=>t.replace(/[&<>"']/g,n=>it[n]),G=(t,n)=>({width:t,height:n,viewBox:`0 0 ${t} ${n}`,"aria-hidden":"true",focusable:"false"}),K=t=>v("bdi",null,t),ct=(t,n)=>{const e=t.getBoundingClientRect();return{l:e.left-n.left,t:e.top-n.top,r:e.right-n.left,b:e.bottom-n.top}},J=(...t)=>window.Basalt._.diagramScale.instantOf(...t),dt=(...t)=>window.Basalt._.diagramScale.scaleMap(...t),ft=(...t)=>window.Basalt._.diagramScale.clockLadder(...t),ut=(...t)=>window.Basalt._.diagramScale.ticks(...t),ht=(...t)=>window.Basalt._.diagramScale.roundOut(...t),et=(...t)=>window.Basalt._.diagramScale.dateWords(...t);function $t(t,n,e,o,a,i){const d=[["above",0],["below",0],["above",1],["below",1]],r=[],x=c=>{let l=c-i,$=!1;return l+e>n&&(l=c+i-e,$=!0),{l,turned:$}},w=(c,l,$,k,b)=>{for(const m of b?[...r,b]:r)if(m.side===$){if(m.lane===k){if(!(l+e+o<=m.l||m.l+e+o<=l))return!1}else if(m.lanem.l+e+a))return!1}else if(!(m.xl+e+a))return!1}return!0};for(let c=t.length-1;c>=0;c--){const l=t[c],{l:$,turned:k}=x(l);if($<0)return{ok:!1,at:c};const b=d.filter(([g,s])=>w(l,$,g,s));if(!b.length)return{ok:!1,at:c};let m=b[0];if(m[1]===1&&b.length>1&&c>0){const g=t[c-1],s=x(g),h=b.filter(([A,y])=>{const _={k:c,x:l,l:$,side:A,lane:y,turned:k};return w(g,s.l,"above",0,_)||w(g,s.l,"below",0,_)});h.length&&(m=h[0])}r.push({k:c,x:l,l:$,side:m[0],lane:m[1],turned:k})}return{ok:!0,placed:r.sort((c,l)=>c.k-l.k)}}var mt=64,R;function nt(t,n){const e=JSON.stringify([t??null,n]);R??(R=new Map);let o=R.get(e);return o||(R.size>=mt&&R.clear(),o=new Intl.DateTimeFormat(t,n),R.set(e,o)),o}function pt(t,n,e){const o={};for(const a of nt(n,e).formatToParts(t))o[a.type]=a.value;return o}function Q(t,{timeZone:n,locale:e="en-US"}={}){const o=pt(new Date(t),"en-US",{timeZone:n,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),a=o.hour==="24"?"00":o.hour;return{text:nt(e,{timeZone:n,hourCycle:"h23",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date(t)),dateTime:`${o.year}-${o.month}-${o.day}T${a}:${o.minute}:${o.second}`}}function vt(t,n=new Date){const e=Math.floor(Math.max(0,new Date(n).getTime()-new Date(t).getTime())/6e4);if(!Number.isFinite(e)||e<1)return null;const o=Math.floor(e/1440),a=Math.floor(e%1440/60),i=e%60;return o>0?{text:`${o} ${o===1?"day":"days"}`,dateTime:`P${o}D`}:a>0?{text:i?`${a} hr ${i} min`:`${a} hr`,dateTime:`PT${a}H${i?`${i}M`:""}`}:{text:`${i} min`,dateTime:`PT${i}M`}}var bt=864e5,p=t=>Math.round(t*100)/100,I=t=>t.plan;function wt(t){return n=>{const e=Math.floor(n/1e3)*1e3,o=Date.parse(`${Q(e,{timeZone:t}).dateTime}Z`);return Number.isFinite(o)?Math.round((o-e)/6e4):0}}var C=(t,n,e=!1)=>{const o=Q(t,{timeZone:n}).text;return e?o.slice(0,8):o.slice(0,5)},j=(t,n)=>Math.floor(Date.parse(`${Q(t,{timeZone:n}).dateTime.slice(0,10)}T00:00:00Z`)/bt);function W(t){return t<6e4?`${Math.max(0,Math.round(t/1e3))} s`:vt(0,t)?.text??`${Math.round(t/1e3)} s`}function gt(t){if(t==="UTC")return"UTC";try{return new Intl.DateTimeFormat("en-US",{timeZone:t,timeZoneName:"short"}).formatToParts(0).find(n=>n.type==="timeZoneName")?.value??t}catch{return t}}function xt(t,n){const{dev:e,error:o,warn:a}=n,i=t.labels??{},d={event:i.event??"Event",breakKey:i.breakKey??"Time left out of the scale",eventKey:i.eventKey??"An event, at its time"},r=q(t.timeZone)??"UTC";let x=r;try{new Intl.DateTimeFormat("en-US",{timeZone:r})}catch{e&&o(`"${r}" is not an IANA zone: the times are written in UTC`),x="UTC"}const w=Array.isArray(t.events)?t.events:[],c=[];w.forEach((s,h)=>{const A=J(s.at);if(e&&s.end!==void 0&&o(`${String(s.id)} has an end: a timeline's events are points, and a span is a gantt's bar`),A===null){e&&o(`${String(s.id)}'s at is ${JSON.stringify(s.at)}, not an ISO 8601 instant with its offset`);return}c.push({id:String(s.id??""),i:h,at:A,name:String(s.name??""),kind:q(s.kind),detail:q(s.detail),mono:!!s.detailMono,focal:!!s.focal,href:q(s.href),blank:s.target==="_blank"})});const l=c.slice().sort((s,h)=>s.at-h.at||s.i-h.i),$=(Array.isArray(t.breaks)?t.breaks:[]).flatMap(s=>{const h=s,A=J(h.from),y=J(h.to);return A===null||y===null||y<=A?(e&&o(`a break from ${JSON.stringify(h.from)} to ${JSON.stringify(h.to)} is not two instants in order`),[]):[{from:A,to:y,label:q(h.label)}]}).sort((s,h)=>s.from-h.from);for(const s of l)$.some(h=>s.at>h.from&&s.ath)&&e&&o("an event is outside the domain: the domain grows to hold it"),b=[Math.min(s,k[0]),Math.max(h,k[1])])}const m=l.map((s,h)=>({id:s.id,i:h,name:s.name,kind:s.kind,detail:s.detail,mono:s.mono,focal:s.focal,col:h+1,row:1,row2:1,branch:!1,shape:"box",href:s.href,blank:s.blank}));if(e){const s=new Set;for(const h of m)s.has(h.id)&&a(`the id "${h.id}" is used twice`),s.add(h.id)}e&&m.filter(s=>s.focal).length>1&&a("more than one event is focal: a timeline has one at most"),e&&t.timeLabel!==void 0&&a("a timeline's times are written by the engine: `timeLabel` is not read");const g={events:l,breaks:$,domain:b,extent:k,zone:x,zoneShort:gt(x),words:d};return{nodes:m,edges:[],plan:g,cols:Math.max(1,m.length),rows:1}}var kt=(t,n)=>I(t).events.find(e=>e.id===n),P=(t,n)=>{const e=t.events.indexOf(n);return e>0?n.at-t.events[e-1].at:null};function at(t,n){const e=I(t),o=kt(t,n.id),a=e.events.indexOf(o),i=P(e,o),d=[`${o.name}, ${C(o.at,e.zone)} ${e.zoneShort}${i!==null?`, ${W(i)} after ${e.events[a-1].name}`:""}.`];return o.kind&&d.push(F(o.kind)),o.detail&&d.push(F(o.detail)),d.push(`${e.words.event} ${a+1} of ${e.events.length}.`),o.focal&&t.legend.focal&&d.push(F(t.legend.focal)),d.join(" ")}function yt(t,n,e,o){const a=I(n),i=[];let d=0;return a.events.forEach((r,x)=>{for(;d0?v("span",{class:`${t}-tl-gap`},` +${W(c)}`):null,r.kind?[" · ",K(r.kind)]:null),v("span",{class:`${t}-name`},K(r.name)),r.detail?v("span",{class:`${t}-detail`,"data-mono":r.mono?"":void 0},r.mono?v("span",{class:`${t}-runs`},r.detail.split(/\s+/).filter(Boolean).flatMap((l,$)=>[$?" ":"",v("span",{class:`${t}-run`},l)])):K(r.detail)):null))}),i}function Mt(t,n){const e=I(n),o=(i,d,r={})=>v("li",{class:`${t}-entry`,...r},i,v("span",null,K(d))),a=[o(v("svg",{class:`${t}-swatch`,...G(12,16)},v("path",{class:`${t}-tl-stem`,d:"M6.5 0V8"}),v("path",{class:`${t}-tl-axis`,d:"M0 11.5H12"}),v("circle",{class:`${t}-tl-dot`,cx:6.5,cy:11.5,r:3})),e.words.eventKey)];return e.breaks.length&&a.push(o(v("svg",{class:`${t}-swatch`,...G(28,16)},v("path",{class:`${t}-tl-axis`,d:"M0 8.5H8M20 8.5H28"}),v("path",{class:`${t}-tl-slash`,d:"M10 14L14 2M14 14L18 2"})),e.words.breakKey)),n.nodes.some(i=>i.focal)&&n.legend.focal&&a.push(o(v("svg",{class:`${t}-swatch`,"data-shape":"focal",...G(16,16)},v("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2})),n.legend.focal,{"data-focal":""})),v("div",{class:`${t}-key`},v("ul",{class:`${t}-legend`,"aria-label":"Key"},a))}function St(t,n){const e=I(n),o=[];let a=0;return e.events.forEach(i=>{for(;a[s.from,s.to]),b=d("8");let m=t.domain;if(!m){const s=ht(t.extent,$,e.node,l,k,b);m=s?s.domain:[t.extent[0],t.extent[1]>t.extent[0]?t.extent[1]:t.extent[0]+6e4]}const g=dt({domain:m,length:l,breaks:k,gap:b,reversed:i});return{map:g,axisL:w,axisR:c,ticks:ut(g,$,e.node),xs:t.events.map(s=>g.position(s.at))}}function At(t,n){const{drawing:e,P:o,tk:a,W:i,apply:d,stopOf:r,current:x,measure:w}=n,c=I(t),l=a.space,$=()=>{const f=r({...x,layout:"stacked",place:void 0,bare:void 0});return d(f),{dyn:f,...Bt(e,t,o,a),tokens:a,least:1/0}};if(i{const T=e.querySelector(`.${o}-node[data-node="${CSS.escape(f.id)}"]`);return[f.id,T?Math.ceil(T.getBoundingClientRect().height):0]})),s=w("00:00","tab"),h=w(c.zoneShort,"mono"),A=f=>{const T=Tt(c,f,a,s,h,m);if(!T)return null;const U=T.xs.map(Z=>m?f-(T.axisL+Z):T.axisL+Z),V=$t(U.map(Z=>Math.round(Z)+.5),f,b,l("3"),l("2"),a.radius);return V.ok?{f:T,placed:V.placed}:null};let y=1/0;for(let f=0;f<19;f++){const T=a.wide+f*a.node;if(A(T)){y=T;break}}if(!(y<=i)){const f=$();return{...f,least:Number.isFinite(y)?y:f.least}}let _=i,u=A(i);if(!u)for(let f=y+Math.floor((i-y)/a.node)*a.node;f>=y&&!u;f-=a.node)u=A(f),_=f;if(!u)return{...$(),least:y};const{f:S,placed:z}=u,M={above:0,below:0},B={above:0,below:0};for(const f of z){const T=g.get(c.events[f.k].id),U=f.lane?B:M;U[f.side]=Math.max(U[f.side],T)}const O=l("6"),D=l("10"),L=l("3"),H=Math.round((B.above?B.above+L:0)+M.above+O)+.5,Y=Math.ceil(H+(M.below?D+M.below:l("8"))+(B.below?L+B.below:0)),N={"":`--_tw:${b}px;--_th:${Y}px;--_tdw:${_}px`},X=[];for(const f of z){const T=c.events[f.k],U=g.get(T.id),V=f.side==="above"?H-O-(f.lane?M.above+L:0)-U:H+D+(f.lane?M.below+L:0),Z=m?_-f.l-b:f.l;N[T.id]=`--_tx:${p(Z)}px;--_ty:${Math.round(V)}px`,X.push({...f,y:Math.round(V),h:U,left:Z})}const lt=r({...x,layout:"drawn",place:N,bare:void 0});return d(lt),{dyn:lt,...zt(e,t,o,a,S,X,H,_,b,w),tokens:a,least:y}}function ot(t,n,e){return`${e}`}var st=t=>({w:t.clientWidth,h:t.clientHeight,nodes:[],lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:0,oy:0});function zt(t,n,e,o,a,i,d,r,x,w){const c=I(n),l=o.space,$=!!n.rtl,k=st(t),b=u=>Math.round(u-.5)+.5,m=u=>a.axisL+u;let g="";const s=a.map.breaks.map(([u])=>{const S=m(a.map.position(u));return $?[S-a.map.gap,S]:[S,S+a.map.gap]}).sort((u,S)=>u[0]-S[0]);let h=a.axisL;for(const[u,S]of s)g+=``,h=S;g+=``;const A=[];a.map.breaks.forEach(([u,S],z)=>{const M=(s[z][0]+s[z][1])/2;g+=``;const B=c.breaks.find(L=>L.from===u),O=`${W(S-u)}${B?.label?` · ${B.label}`:""}`,D=w(O,"tab");A.push([M-D/2-l("2"),M+D/2+l("2")]),g+=`${E(O)}`});const y=[];for(const u of i){const S=c.events[u.k],z=b($?r-u.x:u.x),M=u.side==="above"?u.y+u.h:u.y;u.side==="below"&&y.push(z),g+=``}const _=j(a.map.domain[0],c.zone)!==j(a.map.domain[1],c.zone);a.ticks.forEach((u,S)=>{const z=b(m(u.place));g+=``;const M=/day|week|month|year/.test(u.step),B=C(u.value,c.zone)==="00:00",O=/\bs$/.test(u.step),D=M||B?et(j(u.value,c.zone)):S===0&&_?`${et(j(u.value,c.zone))}, ${C(u.value,c.zone,O)}`:C(u.value,c.zone,O),L=w(D,"tab"),H=z-L/2-l("1"),Y=z+L/2+l("1");y.some(N=>N>=H&&N<=Y)||A.some(([N,X])=>HN)||(g+=`${E(D)}`)});for(const u of i)g+=``;return g+=`${E(c.zoneShort)}`,{geo:k,ink:ot(e,k,g)}}function Bt(t,n,e,o){const a=st(t),i=t.getBoundingClientRect(),d=!!n.rtl,r=o.space,x=d?a.w-r("3")-.5:r("3")+.5;let w="",c=null;for(const l of t.children){if(l.classList.contains(`${e}-tl-break`)){c=null;continue}if(!l.classList.contains(`${e}-node`))continue;const $=ct(l,i),k=Math.round($.t+r("2-5")+8)+.5,b=l.dataset.node??"";c!==null&&(w+=``),w+=``,w+=``,c=k}return{geo:a,ink:ot(e,a,w)}}function _t(t,n,e,o,a){const i=t.byId.get(n)?.i??0,d=t.nodes.length,r=o?e==="ArrowRight"?!a:e==="ArrowLeft"?a:null:e==="ArrowDown"||e==="ArrowRight"?!0:e==="ArrowUp"||e==="ArrowLeft"?!1:null,x=e==="Home"?0:e==="End"?d-1:r===null?null:i+(r?1:-1);return x===null?null:t.nodes[Math.max(0,Math.min(d-1,x))]?.id??null}var rt;function Lt(){return rt??(rt={type:"timeline",build:xt,stop:"an event",sentence:at,key:Mt,list:St,drawing:yt,least:(t,n)=>n.wide,layout:At,keyTarget:_t,hasStops:(t,n)=>!!(n.layout&&!n.bare),traces:()=>!1,hint:(t,n)=>[{keys:n?["←","→"]:["↑","↓"],words:"an event"},{keys:["Home","End"],words:"the ends"},...t.nodes.some(e=>e.href)?[{keys:["Enter"],words:"open"}]:[]],keys:(t,n)=>`${n?"Left and right arrows move to the event before or after in time":"Arrow keys move to the event before or after in time"}; Home and End go to the first and the last.${t.nodes.some(e=>e.href)?" Enter opens an event that is a link.":""}`,rootStyle:(t,n)=>{const e=tt(n.place,"");return e?[e]:[]}})}(function(t){"use strict";var n=t._;(n.diagramTypes=n.diagramTypes||{}).timeline=Lt})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/diagram.css b/.agent/skills/basalt-html/parts/diagram.css index f9690723..4379f188 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:not([data-type=sequence])[data-cols="1"]>.diagram-drawing{--_Max: var(--_D) max(var(--basalt-size-breakpoint-container), var(--_one, var(--basalt-size-breakpoint-container)))}.diagram[data-type=schema][data-cols="1"]>.diagram-drawing{max-width:var(--_Max, 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{padding:var(--_Pad, 0 0 0 var(--_gutter, 0))}.diagram[data-rtl] .diagram-node[data-branch]{margin-inline:var(--_Mi, var(--basalt-space-6) var(--basalt-space-12))}.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 calc(var(--basalt-space-3) + var(--_gx, var(--basalt-space-0)));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-group>.diagram-glabel{inset-inline-start:calc(var(--basalt-space-3) + var(--_gx, var(--basalt-space-0)))}.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-foot{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:not([data-type=sequence],[data-type=gantt])[data-cols="1"]>.diagram-drawing{--_Max: var(--_D) max(var(--basalt-size-breakpoint-container), var(--_one, var(--basalt-size-breakpoint-container)))}.diagram[data-type=schema][data-cols="1"]>.diagram-drawing{max-width:var(--_Max, 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]:not([data-type=gantt],[data-type=kanban],[data-type=journey],[data-type=service-blueprint],[data-type=story-map],[data-type=timeline])>.diagram-drawing{direction:ltr}.diagram[data-rtl]>.diagram-drawing{padding:var(--_Pad, 0 0 0 var(--_gutter, 0))}.diagram[data-rtl] .diagram-node[data-branch]{margin-inline:var(--_Mi, var(--basalt-space-6) var(--basalt-space-12))}.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 calc(var(--basalt-space-3) + var(--_gx, var(--basalt-space-0)));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);--_Lo: var(--_D) calc(var(--_lo, 0) * var(--basalt-space-4));--_Mt: var(--_Lo);--_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=data-flow][data-contour] .diagram-node:not([data-focal],[data-shape=decision]){border-color:var(--basalt-diagram-structure)}.diagram[data-type=data-flow] .diagram-node[data-shape=decision] .diagram-words>.diagram-kind{display:block;margin-block-end:var(--basalt-space-0-5)}.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: var(--_Lo, 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-group>.diagram-glabel{inset-inline-start:calc(var(--basalt-space-3) + var(--_gx, var(--basalt-space-0)))}.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(var(--_lo, 0) * var(--basalt-space-4) - 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-meta{margin:calc(var(--basalt-space-1) - var(--basalt-space-0-5)) 0 0;color:var(--basalt-text-secondary);font:var(--basalt-font-weight-regular) var(--bh-xs)}.diagram-meta-first{color:var(--basalt-text-primary);font-weight:var(--basalt-font-weight-medium)}.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-ruler:is([data-f=tab],[data-f=xs-500],[data-f=xs-600]){font:var(--basalt-font-weight-regular) var(--bh-xs);font-variant-numeric:tabular-nums}.diagram-ruler[data-f=xs-500]{font-weight:var(--basalt-font-weight-medium)}.diagram-ruler[data-f=xs-600]{font-weight:var(--basalt-font-weight-semibold)}.diagram-ruler[data-f=sm]{font:var(--basalt-font-weight-regular) var(--bh-sm)}.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-foot{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 563dccd1..042b775d 100644 --- a/.agent/skills/basalt-html/parts/diagram.js +++ b/.agent/skills/basalt-html/parts/diagram.js @@ -1,6 +1,6 @@ -(()=>{var fn=["top","right","bottom","left"],un=["main","plain","dashed"],we=["one","zero-or-one","one-or-many","zero-or-many"],Ht={one:"Exactly one","zero-or-one":"Zero or one","one-or-many":"One or many","zero-or-many":"Zero or many"},hn=[2,3,4,5,6],ht=t=>t==null||t===""?void 0:String(t),Lt=t=>Object.assign(Object.create(null),t),Ct=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Nt(t,e={}){const o=e.checks!==!1,c=[],l=$=>{c.push($)},s=[],r=$=>{s.push($)},a=t.legend??{},d={};for(const $ of["main","plain","dashed","focal","group","activation"]){const u=ht(a[$]);u&&(d[$]=u)}const g=t.stepLabel,f=typeof g=="function"?$=>String(g($)):typeof g=="string"?($=>g.replace("{n}",String($))):$=>`Step ${$}`,i=t.shapeLabels??{},h={terminal:ht(i.terminal)??"Start or end",step:ht(i.step)??"Step",decision:ht(i.decision)??"Decision"},b=t.heading===void 0?3:hn.includes(t.heading)?t.heading:(l(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),p=($,u)=>$==null?"plain":un.includes($)?$:(l(`"${String($)}" is not a kind of line (main, plain or dashed): ${u} is drawn plain`),"plain"),m=$=>{if($!=null){if(fn.includes($))return $;l(`"${String($)}" is not a side (top, right, bottom or left): the derived side is used`)}},M=($,u)=>typeof $=="number"&&Number.isInteger($)&&$>=1?$:(t.layout==="auto"&&$==null||l(`${u} is ${JSON.stringify($)}, not a whole number from 1: it is placed at 1`),1),L=[],z=[];let v=[];const C=[],B=[],j=t.type;if(["architecture","flowchart","data-flow","sequence","schema"].includes(j)||l(`"${String(j)}" is not a type of diagram (architecture, flowchart, data-flow, sequence or schema)`),j==="architecture"||j==="flowchart"){for(const $ of t.nodes??[]){const u=j==="flowchart"&&$.shape==="decision"?"decision":j==="flowchart"&&$.shape==="terminal"?"terminal":"box",w=String($.id??""),O=M($.row,`the row of ${w}`);L.push({id:w,i:L.length,name:String($.name??""),kind:u==="decision"?void 0:ht($.kind),detail:u==="decision"?void 0:ht($.detail),mono:!!$.detailMono,focal:!!$.focal,col:M($.col,`the column of ${w}`),row:O,row2:O,branch:!!$.branch,shape:u,group:j==="architecture"?ht($.group):void 0,mark:j==="architecture"?se($.mark,l):void 0})}if(j==="architecture"){const $=(t.groups??[]).map(I=>({id:String(I.id??""),label:String(I.label??""),parent:ht(I.parent)})),u=new Map($.map(I=>[I.id,I])),w=I=>{if(!I.parent)return 1;const _=u.get(I.parent);return _?_.parent===I.id||_.id===I.id?(r(`the groups "${I.label}" and "${_.label}" are each other's parent`),I.parent=void 0,1):_.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)},O=$.map(w);$.forEach((I,_)=>C.push({...I,depth:O[_],members:L.filter(X=>X.group===I.id).map(X=>X.id),all:[]}));for(const I of C)I.all=[...I.members,...C.filter(_=>_.parent===I.id).flatMap(_=>_.members)];C.sort((I,_)=>I.depth-_.depth)}}else if(j==="data-flow"){v=(t.lanes??[]).map(u=>({id:String(u.id??""),label:String(u.label??"")}));const $=new Map(v.map((u,w)=>[u.id,w+1]));for(const u of t.nodes??[]){const w=String(u.id??""),O=String(u.lane??""),I=$.get(O);I===void 0&&l(`a node (${w}) names the lane "${O}", which is not in lanes`);const _=L.length+1;L.push({id:w,i:L.length,name:String(u.name??""),kind:f(_),detail:ht(u.detail),mono:!!u.detailMono,focal:!!u.focal,col:M(u.col,`the column of ${w}`),row:I??1,row2:I??1,branch:!1,shape:"box",lane:I??1,laneLabel:v[(I??1)-1]?.label??O,step:_,mark:se(u.mark)})}}else if(j==="sequence"){(t.participants??[]).forEach((O,I)=>{const _=String(O.name??"");L.push({id:String(O.id??""),i:I,name:_,kind:ht(O.kind),mono:!1,focal:!!O.focal,col:I+1,row:1,row2:1,branch:!1,shape:"participant",short:ht(O.short)??_,mark:se(O.mark)})});let $=0;const u=new Map(L.map(O=>[O.id,O.col])),w=(O,I)=>{let _=1/0,X=-1/0;for(const V of O??[]){if(!V||typeof V!="object")continue;if("band"in V){I>0&&r(`the band "${String(V.band)}" is inside a frame: a band is the whole figure's`),B.push({band:String(V.band??"")});continue}if("frame"in V){if(I>=2){r("a frame is a third level: frames nest two deep");continue}const $t=V.frame==="alt"||V.frame==="loop"||V.frame==="opt"?V.frame:"opt",bt=$t==="alt"?V.branches??[]:[{label:V.label,steps:V.steps}];$t==="alt"&&bt.length<2&&r("an alt frame has one branch: it needs two or more");const wt=String(bt[0]?.label??"");wt.length>40&&r(`the frame label "${wt}" is over 40 characters`);const vt=B.length;B.push({open:$t,label:wt,depth:I+1,a:0,b:0}),bt.forEach((y,S)=>{if(S){const W=String(y.label??"");W.length>40&&r(`the frame label "${W}" is over 40 characters`),B.push({otherwise:W,depth:I+1})}y.steps?.length||r(`a frame or branch ("${String(y.label??"")}") is empty`);const[E,k]=w(y.steps??[],I+1);_=Math.min(_,E),X=Math.max(X,k);const A=B[vt];A.a=Math.min(A.a||1/0,E),A.b=Math.max(A.b,k)}),B.push({close:I+1});continue}$++;const ft=String(V.label??"");ft.includes(` -`)&&r(`message ${$}'s label has a break: a message's second line is its note`);const st=String(V.from??""),lt=String(V.to??"");B.push({n:$,from:st,to:lt,label:qt(ft),note:ht(V.note),kind:p(V.kind,`message ${$}`),activate:V.activate===!0||void 0,deactivate:V.deactivate===!0||void 0});const pt=u.get(st)??1,kt=u.get(lt)??1,ut=pt===kt?pt===L.length?pt-1:pt+1:pt;_=Math.min(_,pt,kt,ut),X=Math.max(X,pt,kt,ut)}return[_,X]};w(t.steps??[],0);for(const O of B)"open"in O&&!Number.isFinite(O.a)&&(O.a=1,O.b=Math.max(1,L.length))}else if(j==="schema")for(const $ of t.tables??[]){const u=String($.name??""),[w,O]=Array.isArray($.row)?$.row:[$.row,$.row],I=M(w,`the row of ${u}`),_=Math.max(I,M(O,`the last row of ${u}`)),X=$.more===void 0||$.more===null?void 0:Number.isInteger($.more)&&$.more>0?$.more:(l(`${u}'s "more" is ${JSON.stringify($.more)}, not a whole number from 1: it is left out`),void 0);L.push({id:u,i:L.length,name:u,mono:!0,focal:!!$.focal,col:M($.col,`the column of ${u}`),row:I,row2:_,branch:!1,shape:"table",more:X,columns:($.columns??[]).map(V=>({name:String(V.name??""),type:ht(V.type),key:V.key==="PK"||V.key==="FK"?V.key:(V.key!==void 0&&V.key!==null&&l(`${u}.${String(V.name)}'s key is "${String(V.key)}", not PK or FK: it is left out`),void 0)}))})}let F=!1;if(t.layout==="auto"&&(j==="architecture"||j==="flowchart"||j==="schema")){const $=j==="schema"?t.tables:t.nodes;o&&($??[]).some(w=>w&&(w.col!==void 0||w.row!==void 0))&&l('a card under layout="auto" has a col or row, which is not read: there are no hints');const u=e.placement?.cells;u||(F=!0);for(const w of L){const O=u?.[w.id];w.col=O?.col??1,w.row=w.row2=O?.row??1}if(u){const w=new Map;for(const O of L){const I=Ct(u,O.id);if(!I){F=!0,l(`the placement has no cell for ${O.id}, so it is not used`);continue}const _=`${I.col},${I.row}`;w.has(_)&&(F=!0,l(`the placement puts ${w.get(_)} and ${O.id} in one cell, so it is not used`)),w.set(_,O.id)}}if(u&&!F)for(const w of C){const O=w.all.map(st=>L.find(lt=>lt.id===st)).filter(Boolean);if(!O.length)continue;const I=Math.min(...O.map(st=>st.col)),_=Math.max(...O.map(st=>st.col)),X=Math.min(...O.map(st=>st.row)),V=Math.max(...O.map(st=>st.row)),ft=L.filter(st=>!w.all.includes(st.id)&&st.col>=I&&st.col<=_&&st.row>=X&&st.row<=V);ft.length&&(F=!0,l(`the placement puts ${ft.map(st=>st.id).join(", ")} inside the box of the group "${w.label}", so it is not used`))}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart or a schema, not a ${j}`);((j==="schema"?t.tables:j==="sequence"?t.participants:t.nodes)??[]).forEach(($,u)=>{if(!$||$.href===void 0||$.href===null)return;const w=String($.href);if(j==="sequence"){r(`${L[u]?.id}: a participant cannot be a link (href)`);return}if(!w.trim()){r(`${L[u]?.id}'s href is empty`);return}const O=L[u];O&&(O.href=w,O.blank=$.target==="_blank")});const q=new Map;for(const $ of L)$.id?q.has($.id)&&l(`the id "${$.id}" is used twice`):l("a node has no id"),q.set($.id,$);if(j==="schema"){const $=(w,O)=>{if(w==null)return;const I=w,_=we.includes(I.from)?I.from:void 0;if(!_){r(`${O}'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:_,to:"one"}:I.to==="one"||I.to==="zero-or-one"?{from:_,to:I.to}:(r(`${O}'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:_,to:"one"})};(t.tables??[]).forEach(w=>(w.columns??[]).forEach((O,I)=>{const _=ht(O.references);if(!_&&O.cardinality!==void 0&&O.cardinality!==null&&r(`${String(w.name)}.${String(O.name)} states a cardinality but references nothing`),!_)return;const[X,V]=_.split("."),ft=q.get(X??""),st=ft?.columns?.findIndex(kt=>kt.name===V)??-1;if(!ft||st<0){l(`${String(w.name)}.${String(O.name)} references ${_}, which is not a shown column`);return}const lt=q.get(String(w.name??""));lt.columns[I].ref={table:X,column:V,row:st};const pt=$(O.cardinality,`${String(w.name)}.${String(O.name)}`);pt&&(lt.columns[I].card=pt),z.push({i:z.length,from:lt.id,to:X,kind:"plain",fromRow:I,toRow:st,fk:!0,card:pt})}));const u=z.filter(w=>w.card).length;u&&u!w.card).map(w=>`${w.from}.${q.get(w.from).columns[w.fromRow].name}`).join(", ")} ${z.length-u===1?"has":"have"} none)`)}else if(j!=="sequence")for(const $ of t.edges??[]){const u=String($.from??""),w=String($.to??"");if(!q.has(u)||!q.has(w)){l(`a line names ${q.has(u)?w:u}, which is not a node`);continue}const O=ht($.label),I=O?.split(` -`)??[];I.length>2&&r(`the label "${qt(O)}" has more than one break: a label is two lines at most`),I.some(_=>_.length>ke)&&r(`a line of the label "${qt(O)}" is over ${ke} characters: longer words belong in the node or the summary`),z.push({i:z.length,from:u,to:w,kind:p($.kind,`the line from ${u} to ${w}`),label:O,fromSide:m($.fromSide),toSide:m($.toSide),flow:j!=="flowchart"&&$.flow===!0?!0:void 0})}else for(const $ of B)"n"in $&&(!q.has($.from)||!q.has($.to))&&l(`message ${$.n} names ${q.has($.from)?$.to:$.from}, which is not a participant`);if(o&&j!=="sequence"&&!F){const $=new Map;for(const u of L)for(let w=u.row;w<=u.row2;w++){const O=`${u.col}:${w}`;$.has(O)&&l(`${u.id} and ${$.get(O)} share the cell at column ${u.col}, row ${w}`),$.set(O,u.id)}}if(o&&!F){for(const u of C){const w=u.all.map(_=>q.get(_));if(!w.length)continue;const O={c1:Math.min(...w.map(_=>_.col)),c2:Math.max(...w.map(_=>_.col)),r1:Math.min(...w.map(_=>_.row)),r2:Math.max(...w.map(_=>_.row2))};for(const _ of L)!u.all.includes(_.id)&&_.col>=O.c1&&_.col<=O.c2&&_.row>=O.r1&&_.row<=O.r2&&l(`${_.id} is inside the box of the group "${u.label}" but not a member`);const I=w.map(_=>_.i);Math.max(...I)-Math.min(...I)+1!==I.length&&l(`the members of the group "${u.label}" are not next to each other in the author's order, so the stacked drawing cannot wrap them in one box`)}for(const u of L)u.group&&!C.some(w=>w.id===u.group)&&l(`${u.id} names the group "${u.group}", which is not in groups`);L.filter(u=>u.focal).length>1&&l("more than one node is focal: a diagram has one at most");const $=new Set(j==="sequence"?B.flatMap(u=>"n"in u?[u.kind]:[]):z.map(u=>u.kind));$.has("main")&&!d.main&&l("main lines are drawn but the legend has no words for them (legend.main)"),$.has("dashed")&&!d.dashed&&l("dashed lines are drawn but the legend has no words for them (legend.dashed)"),L.some(u=>u.focal)&&!d.focal&&l("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const D=j==="architecture"||j==="data-flow",T=$=>Array.isArray($)&&$.length>1?$.map(String):void 0,R=D&&t.packet&&typeof t.packet=="object"?t.packet:void 0,H=R&&T(R.path),Q={animated:t.motion==="animated",pulse:D?T(t.pulse):void 0,packet:H?{path:H,repeat:R.repeat===!0,send:R.send}:void 0,run:j==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(o)for(const $ of L){const u=$.mark?.says;if(!u?.length)continue;const w=[$.name,$.kind,$.detail,$.laneLabel].filter(Boolean).join(" ").toLowerCase();u.some(O=>w.includes(O.toLowerCase()))||l(`${$.id}'s mark stands for ${u.join(" or ")}, and none of its words say so`)}const at=[];if(j==="sequence"){const $=new Map,u=new Map;for(const w of B)"n"in w&&(u.set(w.from,w.n),u.set(w.to,w.n));for(const w of B)if("n"in w){if(w.activate){const O=$.get(w.to)??[];if(O.length>=3)r(`message ${w.n} opens a fourth bar on ${w.to}: three deep at most`);else{const I={who:w.to,from:w.n,to:w.n,depth:O.length+1};O.push(I),at.push(I),$.set(w.to,O)}}if(w.deactivate){const I=$.get(w.from)?.pop();I?I.to=w.n:r(`message ${w.n} closes a bar on ${w.from}, which has none open`)}}for(const[w,O]of $)for(const I of O)I.to=Math.max(I.from,u.get(w)??I.from)}const it=t.frameLabels??{},yt={opt:ht(it.opt)??"Only if",loop:ht(it.loop)??"Repeats",alt:ht(it.alt)??"One of these",else:ht(it.else)??"Otherwise"},dt=t.layout==="auto"&&!F?e.placement:void 0;let et=Math.max(1,dt?.cols??1,...L.map($=>$.col));if(e.rtl){for(const u of L)u.col=et-u.col+1;const $=u=>u==="left"?"right":u==="right"?"left":u;for(const u of z)u.fromSide=$(u.fromSide),u.toSide=$(u.toSide);for(const u of B)if("open"in u){const[w,O]=[et-u.b+1,et-u.a+1];u.a=w,u.b=O}et=Math.max(1,dt?.cols??1,...L.map(u=>u.col))}const nt=j==="data-flow"?Math.max(1,v.length):Math.max(1,dt?.rows??1,...L.map($=>$.row2)),tt={type:j,title:String(t.title??""),heading:b,legend:d,nodes:L,byId:q,edges:z,groups:C,lanes:v,steps:B,bars:at,frameWords:yt,cols:et,rows:nt,shapeLabels:h,stepWord:f,warnings:c,errors:s,motion:Q,memo:new Map,rtl:e.rtl||void 0,unplaced:F||void 0,text:j==="sequence"&&t.variant==="text"||void 0,marks:z.some($=>$.card)||void 0};if(t.layout==="auto"&&!F&&j!=="schema"&&pn(tt),o)for(const[$,u]of Object.entries(De(tt)))u>=48&&l(`${$} grows to ${u}px to hold the lines on one side: use another side`);return o&&L.length>100&&l(`the figure has ${L.length} cards: more than 100, which automatic layout places on the main thread`),o&&L.length>1&&!F&&!Xt(tt)&&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"),tt}function pn(t){const e=new Set(t.nodes.map(r=>`${r.col},${r.row}`)),n=(r,a)=>{const d=[];for(let g=Math.min(r,a)+1;g{const a=t.byId.get(r.from),d=t.byId.get(r.to),g=d.col>a.col?"right":"left",f=d.row>a.row?"bottom":"top",i=d.col>a.col?"left":"right",h=d.row>a.row?"top":"bottom",b=(M,L,z,v)=>n(M,L).map(C=>v?[C,z]:[z,C]);let p;const m=M=>(M==="right"?a.col1:M==="bottom"?a.row1)?[{sides:[M,M],cells:[]}]:[];return a.row===d.row?p=[{sides:[g,i],cells:b(a.col,d.col,a.row,!0)},...m("bottom"),...m("top")]:a.col===d.col?p=[{sides:[f,h],cells:b(a.row,d.row,a.col,!1)},...m("right"),...m("left")]:p=[{sides:[g,h],cells:[...b(a.col,d.col,a.row,!0),[d.col,a.row],...b(a.row,d.row,d.col,!1)]},{sides:[f,i],cells:[...b(a.row,d.row,a.col,!1),[a.col,d.row],...b(a.col,d.col,d.row,!0)]},{sides:[g,i],cells:b(a.col,d.col,a.row,!0)},{sides:[f,h],cells:b(a.row,d.row,a.col,!1)}],p.filter(M=>M.cells.every(([L,z])=>!e.has(`${L},${z}`)))},c=new Map,l=new Set;for(const r of t.edges)if(r.fromSide||r.toSide){const[a,d]=fe(t.byId.get(r.from),t.byId.get(r.to)),g=r.fromSide??a,f=r.toSide??d;l.add(`${r.from}.${g}`);for(const[i,h]of[[r.from,g],[r.to,f]])c.set(`${i}.${h}`,(c.get(`${i}.${h}`)??0)+1)}const s=t.edges.map((r,a)=>a).sort((r,a)=>o(t.edges[r]).length-o(t.edges[a]).length||+(t.edges[a].kind==="main")-+(t.edges[r].kind==="main")||r-a);for(const r of s){const a=t.edges[r];if(a.fromSide||a.toSide)continue;const d=(f,i,h)=>{const b=`${f}.${i}`;return(c.get(b)??0)>=3?!1:t.byId.get(f).shape!=="decision"?!0:h?!c.has(b):!l.has(b)},g=o(a).find(f=>d(a.from,f.sides[0],!0)&&d(a.to,f.sides[1],!1));if(g){l.add(`${a.from}.${g.sides[0]}`);for(const[f,i]of[[a.from,g.sides[0]],[a.to,g.sides[1]]])c.set(`${f}.${i}`,(c.get(`${f}.${i}`)??0)+1);a.fromSide=g.sides[0],a.toSide=g.sides[1]}}}function se(t,e){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const n=t,o=ve(ht(n.onLight),e);if(o)return{onLight:o,onDark:ve(ht(n.onDark),e)??o,says:Array.isArray(n.says)?n.says.map(String):void 0}}function ve(t,e){if(t){if(/^data:image\//i.test(t.trim()))return t;try{if(/^https?:$/.test(new URL(t,"https://basalt.invalid/").protocol)&&!/^http:/i.test(t.trim()))return t}catch{}e?.(`a card's mark ${JSON.stringify(t.slice(0,60))} is not a relative path, https or a data: image, so it is not drawn`)}}var xe=t=>`url("${t.replace(/[\\"\n\r\f;]/g,e=>e===` -`?"\\a ":e==="\r"?"\\d ":e==="\f"?"\\c ":e===";"?"\\3b ":`\\${e}`)}")`;function Rt(t,e,n){return t.memo.has(e)||t.memo.set(e,n()),t.memo.get(e)}var ke=28,Kt=t=>t.includes(` -`)?2:1,qt=t=>t.replace(/\n/g," "),Ft=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function Me(t,e){return t.legend[e]}function gn(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(n=>n.from===e.id)?"start":"end":e.kind??"step"}function mn(t,e){return Rt(t,`sentence:${e.i}`,()=>yn(t,e))}function yn(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?`: ${Se(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?`: ${Se(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(s=>"n"in s&&s.from===e.id).length,c=t.steps.filter(s=>"n"in s&&s.to===e.id).length;n.push(Ft(e.kind?`${e.name}, ${e.kind}`:e.name)),n.push(`Sends ${o} ${o===1?"message":"messages"} and receives ${c}.`);const l=Ee(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"?gn(t,e):e.kind;if(n.push(Ft(o?`${e.name}, ${o}`:e.name)),e.detail&&n.push(Ft(e.detail)),e.group){const s=t.groups.find(a=>a.id===e.group),r=s?.parent?t.groups.find(a=>a.id===s.parent):void 0;s&&n.push(r?`In ${s.label}, in ${r.label}.`:`In ${s.label}.`)}const c=t.edges.filter(s=>s.to===e.id).map(s=>`${t.byId.get(s.from).name}${s.label?` (${qt(s.label)})`:""}`),l=t.edges.filter(s=>s.from===e.id).map(s=>`${t.byId.get(s.to).name}${s.label?` (${qt(s.label)})`:""}`);c.length&&n.push(`From: ${c.join(", ")}.`),l.length&&n.push(`To: ${l.join(", ")}.`)}return e.focal&&t.legend.focal&&n.push(Ft(t.legend.focal)),n.join(" ")}var $n=(t,e,n,o)=>[`${Ht[n.from].toLowerCase()} `,o(t),` to ${Ht[n.to].toLowerCase()} `,o(e)],Se=(t,e,n)=>`${Ht[n.from].toLowerCase()} ${t} to ${Ht[n.to].toLowerCase()} ${e}`;function Ee(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 bn(t,e,n,o){const c=n.pointerType;if(c!=="touch"&&c!=="pen")return;const l=t.querySelector(`.${e}-drawing`),s=n.target;if(!l||!s||!l.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:o===null?void 0:null}function Ae(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 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 wn={"&":"&","<":"<",">":">",'"':""","'":"'"},mt=t=>t.replace(/[&<>"']/g,e=>wn[e]),vn=" br img input meta link hr path polygon polyline circle rect line ";function ae(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,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}="${mt(String(c))}"`}return vn.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=>ae(o,e)).join("")}`}var xn=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function Tt(t,e){return!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function kn(t,e){return t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Zt(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 Le(t){return Rt(t,"group-edges",()=>{const e=[0,0,0,0];for(const n of t.groups){const o=Zt(t,n);if(!o)continue;[o.r1===1,o.c2===t.cols,o.r2===t.rows,o.c1===1].forEach((l,s)=>{l&&(e[s]=Math.max(e[s],_e(t,n,s)))})}return e})}function _e(t,e,n){const o=Zt(t,e);return t.groups.filter(s=>s.parent===e.id).some(s=>{const r=Zt(t,s);return r&&[r.r1===o.r1,r.c2===o.c2,r.r2===o.r2,r.c1===o.c1][n]})?2:1}function qe(t){const e=Le(t);return e[1]+e[3]}function Jt(t){return t.type==="sequence"?t.nodes.length:t.cols}function Ie(t){return Rt(t,"plan",()=>Mn(t))}function Mn(t){const e=t.nodes,n=m=>t.type==="data-flow"||!e[m].branch,o=t.edges.map(m=>{const M=t.byId.get(m.from).i,L=t.byId.get(m.to).i,v=e.slice(Math.min(M,L)+1,Math.max(M,L)).every(C=>!n(C.i));return L===M+1&&!(n(M)&&!n(L))?"down":L===M-1?"up":L>M&&n(M)&&!n(L)&&v?"trunk":L>M&&n(M)&&n(L)&&v?"rail":L>M?"end-down":"end-up"}),c=t.edges.map((m,M)=>({e:m,k:M})).filter(({k:m})=>o[m]==="end-down"||o[m]==="end-up"),l=m=>{const M=t.byId.get(m.from).i,L=t.byId.get(m.to).i;return[Math.min(M,L),Math.max(M,L)]},s=(m,M)=>{const[L,z]=l(m),[v,C]=l(M);return L{const M=t.byId.get(m.from).i,[L,z]=l(m);return!n(M)&&e.slice(L+1,z).every(v=>!n(v.i))&&c.every(v=>v.e===m||!s(v.e,m))}),a=c.length>0&&(t.type==="data-flow"||!r),d=m=>{const[M,L]=l(m);return L-M},g=t.edges.map(()=>0);let f=!1;const i=[];for(const m of[...c].sort((M,L)=>d(M.e)-d(L.e)||M.k-L.k)){let M=0;for(const L of i)s(L.e,m.e)&&(M=Math.max(M,g[L.k]+1));g[m.k]=M,M>3&&(f=!0),i.push(m)}const h=Math.max(0,...c.map(({k:m})=>g[m]+1)),b=t.edges.map(()=>.5);for(const m of e){const M=c.filter(({e:v})=>v.from===m.id);if(M.length<2)continue;const L=M.filter(({k:v})=>o[v]==="end-down").sort((v,C)=>d(C.e)-d(v.e)||v.k-C.k);[...M.filter(({k:v})=>o[v]==="end-up").sort((v,C)=>d(v.e)-d(C.e)||C.k-v.k),...L].forEach(({k:v},C,B)=>{b[v]=B.length===2?C===0?1/3:2/3:(C+1)/(B.length+1)})}const p=Lt();for(let m=1;m{const D=o[q],T=t.byId.get(rt.from).i,R=t.byId.get(rt.to).i,H=R===m&&(D==="down"||D==="trunk"||D==="rail"||D==="end-down"),Q=T===m&&R===m-1&&D==="up",at=R===m-1&&D==="end-up";H&&(D==="trunk"||D==="end-down")&&(C=!0),at&&(B=!0),(H||Q||at)&&rt.label&&(z++,v=Math.max(v,D==="trunk"?40:48))}),(z>1||C&&B)&&(v=64);const j=c.filter(({e:rt,k:q})=>o[q]==="end-down"&&t.byId.get(rt.to).i===m).length,F=c.filter(({e:rt,k:q})=>o[q]==="end-up"&&t.byId.get(rt.to).i===m-1).length;v+=20*Math.max(0,j-1)+20*Math.max(0,F-1),p[M.id]=v}return{routes:o,gutter:a,lanes:g,exits:b,gaps:p,third:f,laneCount:h}}var Wt=(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,o=n==="main"?8:8.5,c=24,l=n==="dashed"?c-1:c-7;return x("svg",{class:`${t}-swatch`,"data-kind":n,...Wt(24,16)},e==="fk"?x("circle",{class:`${t}-dot`,cx:3,cy:o,r:3}):null,x("path",{class:`${t}-line`,"data-kind":n,d:`M${e==="fk"?3:0} ${o}H${l}`}),n==="dashed"?x("path",{class:`${t}-tip`,"data-kind":n,"data-open":"",d:`M${c-8} ${o-4}L${c} ${o}L${c-8} ${o+4}`}):x("path",{class:`${t}-tip`,"data-kind":n,d:`M${c} ${o}L${c-8} ${o-4}L${c-8} ${o+4}Z`}))}function Sn(t,e){const{crow:n,ring:o}=Ce(e,24,8.5,-1);return x("svg",{class:`${t}-swatch`,"data-card":e,...Wt(24,16)},x("path",{class:`${t}-line`,"data-kind":"plain",d:"M0 8.5H24"}),x("path",{class:`${t}-crow`,d:n}),o?x("circle",{class:`${t}-ring`,cx:o.x,cy:o.y,r:o.r}):null)}function Ce(t,e,n,o,c=8,l=6){const s=h=>String(Math.round(h*100)/100),r=h=>e+o*h,a=c/2,d=h=>`M${s(r(h-.5))} ${s(n-a)}V${s(n+a)}`,g=t==="one-or-many"||t==="zero-or-many",f=t==="zero-or-one"||t==="zero-or-many";let i=g?`M${s(e)} ${s(n-a)}L${s(r(7.5))} ${s(n)}L${s(e)} ${s(n+a)}`:d(4);return f||(i+=d(g?11:8)),{crow:i,ring:f?{x:Math.round(r(10.5)*100)/100,y:n,r:l/2}:void 0}}function Dt(t,e){return e==="decision"?x("svg",{class:`${t}-swatch`,"data-shape":e,...Wt(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,...Wt(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,...Wt(16,16)},x("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function Be(t,e){return Rt(e,`key:${t}`,()=>An(t,e))}var En=Be;function An(t,e){const n=[],o=(s,r,a={})=>n.push(x("li",{class:`${t}-entry`,...a},s,x("span",null,r)));if(e.type==="schema"){const s=new Set(e.nodes.flatMap(r=>(r.columns??[]).map(a=>a.key)));for(const[r,a]of[["PK","Primary key"],["FK","Foreign key"]])s.has(r)&&n.push(x("li",{class:`${t}-entry`},x("span",{class:`${t}-key-letters`,"aria-hidden":"true"},r),x("span",null,a)))}if(e.type==="flowchart"){const s=new Set(e.nodes.map(r=>r.shape));s.has("terminal")&&o(Dt(t,"terminal"),e.shapeLabels.terminal),s.has("box")&&o(Dt(t,"box"),e.shapeLabels.step),s.has("decision")&&o(Dt(t,"decision"),e.shapeLabels.decision)}const c=new Set(e.type==="sequence"?e.steps.flatMap(s=>"n"in s?[s.kind]:[]):e.edges.filter(s=>!s.fk).map(s=>s.kind)),l=(s,r)=>x("span",{class:`${t}-key-glyph`,"data-ink":r,"aria-hidden":"true"},s);for(const s of["main","plain","dashed"]){const r=e.legend[s];c.has(s)&&r&&o(e.text?l(s==="main"?"━━▶":s==="dashed"?"┄┄▷":"──▶",s==="main"?"main":"plain"):Oe(t,s),r,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length){e.edges.some(r=>!r.card)&&o(Oe(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 we)s.has(r)&&o(Sn(t,r),Ht[r],{"data-line":"","data-when":"drawn","data-card":r});n.push(x("li",{class:`${t}-entry`,"data-when":"stacked"},x("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),x("span",null,"The table a foreign key references")))}if(e.type==="sequence"){e.bars.length&&o(e.text?l("┃","working"):x("svg",{class:`${t}-swatch`,"data-shape":"bar",...Wt(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",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(x("li",{class:`${t}-entry`},x("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},r),x("span",null,e.frameWords[r])))}return e.nodes.some(s=>s.focal)&&e.legend.focal&&o(e.text?l("╔═╗","focal"):Dt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&o(Dt(t,"group"),e.legend.group),n.length?x("div",{class:`${t}-key`},x("ul",{class:`${t}-legend`,"aria-label":"Key"},n)):null}function Ln(t,e){const n=e==="main"?6:6.5;return x("svg",{class:`${t}-arrow`,"data-kind":e,...Wt(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`}))}var It=t=>x("bdi",null,t);function re(t,e){if(!e.href)return It(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 _n(t,e,n){if(n.shape==="decision")return[x("span",{class:`${t}-words`},x("span",{class:`${t}-name`},re(t,n)))];const o=[];return e.type==="data-flow"?o.push(x("span",{class:`${t}-kind`},It(n.kind),x("span",{class:`${t}-lane-word`}," · ",It(n.laneLabel??"")))):n.kind&&o.push(x("span",{class:`${t}-kind`},It(n.kind))),o.push(x("span",{class:`${t}-name`},re(t,n))),n.detail&&o.push(x("span",{class:`${t}-detail`,"data-mono":n.mono?"":void 0},n.mono?x("span",{class:`${t}-runs`},te(n.detail).flatMap((c,l)=>[l?" ":"",x("span",{class:`${t}-run`},c)])):It(n.detail))),o}function qn(t,e,n){return[x("span",{class:`${t}-th`},x("span",{class:`${t}-tname`},re(t,e))),x("span",{class:`${t}-rows`},(e.columns??[]).map((o,c)=>x("span",{class:`${t}-row`,"data-row":c,"data-key":o.key},x("span",{class:`${t}-keyseat`},o.key??""),x("span",{class:`${t}-cname`},o.name),o.ref?x("span",{class:`${t}-ctype`,"data-ref":""},`${n.rtl?"←":"→"} `,It(o.ref.table)):o.type?x("span",{class:`${t}-ctype`},It(o.type)):null))),e.more?x("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var je=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 Ut(t,e,n,o){const{P:c}=t,l=kn(e,o)||o.keep===n.id,s=Tt(e,o),r=o.layout==="drawn"&&o.rows,a=[`--_c:${n.col}`,`--_r:${r?2*n.row:n.row}`,`--_r2:${r?2*n.row2+1: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 b=Ct(d.gaps,n.id)??32,p=Ct(o.grow,n.id)??0;a.push(`--_gap:${p?`calc(${je(b)} + var(--basalt-space-4) * ${p})`:je(b)}`)}const g=Ct(o.heights,n.id);g&&a.push(`--_h:${g}px`);const f=Ct(De(e),n.id);f&&a.push(`--_mh:${f}px`);const i=Ct(o.words,n.id);i&&a.push(`--_ww:${i}px`);const h=s?o.stop===n.id?0:-1:o.keep===n.id?-1:void 0;return x(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:a.join(";"),role:l&&!n.href?"img":void 0,"aria-label":l||n.href?mn(e,n):void 0,tabindex:h},n.shape==="decision"?x("svg",{class:`${c}-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:`${c}-mark`,"aria-hidden":"true",style:n.mark.onLight?`--_ml:${xe(n.mark.onLight)};--_md:${xe(n.mark.onDark??n.mark.onLight)}`:void 0}):null,n.shape==="table"?qn(c,n,e):_n(c,e,n))}function In(t,e,n){const{P:o}=t,c=[];if(e.type==="data-flow"&&c.push(...e.lanes.map((a,d)=>x("div",{class:`${o}-lane`,style:`--_r:${d+1}`,"aria-hidden":"true"},x("span",{class:`${o}-lane-name`},a.label)))),e.type==="architecture")for(const a of e.groups){const d=Zt(e,a);if(!d)continue;const g=[0,1,2,3].map(f=>_e(e,a,f));c.push(x("div",{class:`${o}-gbox`,"data-group":a.id,"data-depth":a.depth>1?a.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"},x("span",{class:`${o}-glabel`},It(a.label))))}if(e.text)return[x("pre",{class:`${o}-text`,"aria-hidden":"true","data-art":n.art?"":void 0},x("code",{class:`${o}-text-ink`},On(o,e)))];if(e.type==="sequence")return c.push(x("ul",{class:`${o}-cast`},e.nodes.map(a=>x("li",{class:`${o}-actor`,style:e.rtl?`--_ac:${a.col}`:void 0},Ut(t,e,a,n))))),c.push(Cn(t,e)),c;const l=a=>{const d=a.group?e.groups.find(g=>g.id===a.group):void 0;return d?.parent?e.groups.find(g=>g.id===d.parent):d},s=(a,d,g)=>{const f=t.plan?Ct(n.grow,d[0].id)??0:0,i=d[0],h=t.plan&&i.group===a.id?e.edges.filter((m,M)=>m.to===i.id&&(t.plan.routes[M]==="trunk"||t.plan.routes[M]==="end-down")):[],b=Math.max(0,...h.map(m=>m.label?Kt(m.label):0)),p=[f?`--_ggrow:${f}`:"",b?`--_tl:${b}`:""].filter(Boolean).join(";");return x("div",{class:`${o}-group`,"data-group":a.id,"data-depth":a.depth>1?a.depth:void 0,"data-turn":h.length?"":void 0,style:p||void 0},x("span",{class:`${o}-glabel`,"aria-hidden":"true"},It(a.label)),g)};let r=0;for(;rp.id===g[i].group):void 0;if(!h){f.push(Ut(t,e,g[i],n)),i++;continue}const b=[];for(;iUt(t,e,p,n))))}c.push(s(d,g,f))}return c}function On(t,e){const n=[],o=a=>x("span",{class:`${t}-tx-name`},a),c=a=>a==="main"?"━▶":a==="dashed"?"┄▷":"─▶",l=(a,d,g,...f)=>x("span",{class:`${t}-tx-line`,...a,style:g?`--_in:${d+g};--_hang:${g}`:`--_in:${d}`},...f);n.push(l({"data-ink":"names"},0,0,e.nodes.flatMap((a,d)=>[d?" · ":"",o(a.name)])));const s=String(Math.max(1,...e.steps.map(a=>"n"in a?a.n:0))).length;let r=0;for(const a of e.steps){const d=2*r;if("band"in a){n.push(l({"data-ink":"band"},d,0,`── ${a.band} ──`));continue}if("open"in a){n.push(l({"data-ink":"frame"},d,0,x("span",{"data-ink":"op"},`[${a.open}]`),` ${a.label}`)),r++;continue}if("otherwise"in a){n.push(l({"data-ink":"frame"},2*Math.max(0,r-1),0,x("span",{"data-ink":"op"},"[else]"),` ${a.otherwise}`));continue}if("close"in a){r=Math.max(0,r-1),n.push(l({"data-ink":"frame"},2*r,0,"[end]"));continue}const g=e.byId.get(a.from)?.name??a.from,f=e.byId.get(a.to)?.name??a.to,i=s+2;n.push(l({"data-n":a.n},d,i,x("span",{"data-ink":"num"},String(a.n).padStart(s,"0"))," ",o(g)," ",x("span",{class:`${t}-tx-to`},x("span",{"data-ink":a.kind==="main"?"main":"plain"},c(a.kind))," ",f))),n.push(l({"data-n":a.n},d+i,0,x("span",{"data-ink":"label"},a.label))),a.note&&n.push(l({"data-n":a.n},d+i,0,x("span",{"data-ink":"note"},a.note)))}return n}function Cn(t,e){const{P:n}=t,o=[],c=[],l=()=>c.length?c[c.length-1].el.c:o;let s=null;for(const r of e.steps){if("band"in r){s=null,l().push(x("p",{class:`${n}-band`},x("span",null,r.band)));continue}if("open"in r){s=null;const p=c[c.length-1],m=p?`;--_fis:${r.a===p.a?1:0};--_fie:${r.b===p.b?1:0}`:"",M=x("div",{class:`${n}-frame`,"data-op":r.open,"data-depth":r.depth,style:`--_a:${r.a};--_b:${r.b+1}${m}`},x("span",{class:`${n}-fbox`,"aria-hidden":"true"}),x("p",{class:`${n}-fhead`},x("span",{class:`${n}-ftab`,"aria-hidden":"true"},r.open),x("span",{class:`${n}-flabel`},x("span",{class:t.hidden},`${e.frameWords[r.open]}: `),r.label)));l().push(M),c.push({el:M,a:r.a,b:r.b});continue}if("otherwise"in r){s=null,l().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}: `),r.otherwise)));continue}if("close"in r){s=null,c.pop();continue}s||(s=x("ol",{class:`${n}-msgs`,start:r.n}),l().push(s));const a=e.byId.get(r.from),d=e.byId.get(r.to),g=a?.col??1,f=d?.col??1,i=g===f,h=i&&(e.rtl?g!==1:g===e.nodes.length),b=Me(e,r.kind);s.c.push(x("li",{class:`${n}-msg`,"data-kind":r.kind,"data-from":r.from,"data-to":r.to,"data-self":i?h?"start":"end":void 0,style:`--_a:${Math.min(g,f)};--_b:${Math.max(g,f)+1}`},x("span",{class:`${n}-said`},x("span",{class:`${n}-num`},String(r.n)),x("span",{class:`${n}-mlabel`},r.label)),x("span",{class:`${n}-route`},a?.short??r.from," ",x("span",{class:`${n}-to`},Ln(n,r.kind),x("span",{class:t.hidden}," to ")," ",d?.short??r.to,b?` · ${b}`:"")),r.note?x("span",{class:`${n}-note`},r.note):null))}return x("div",{class:`${n}-steps`},o)}function Re(t,e){return Rt(e,`list:${t}`,()=>jn(t,e))}var Bn=Re;function jn(t,e){const n=Math.min(6,e.heading+1),o=f=>x(`h${n}`,{class:`${t}-list-head`},f),c=f=>x("strong",null,f),l=f=>f.href?x("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},c(f.name)):c(f.name),s=f=>x("code",{class:`${t}-code`},f),r=f=>e.byId.get(f)?.name??f,a=f=>{const i=Me(e,f);return i?` (${i})`:""},d=f=>f.focal&&e.legend.focal?` ${Ft(e.legend.focal)}`:"";if(e.type==="architecture"){const f=b=>x("li",null,l(b),b.kind?`, ${b.kind}`:"",b.detail?[". ",b.mono?s(b.detail):b.detail,/[.!?]$/.test(b.detail)?"":"."]:/[.!?]$/.test(b.kind??b.name)?"":".",d(b)),i=[o("Parts")],h=e.nodes.filter(b=>!b.group);h.length&&i.push(x("ul",{class:`${t}-list-items`},h.map(f)));for(const b of e.groups.filter(p=>p.depth===1)){i.push(x("p",{class:`${t}-list-group`},b.label)),b.members.length&&i.push(x("ul",{class:`${t}-list-items`},b.members.map(p=>f(e.byId.get(p)))));for(const p of e.groups.filter(m=>m.parent===b.id))i.push(x("p",{class:`${t}-list-group`,"data-depth":2},p.label)),i.push(x("ul",{class:`${t}-list-items`,"data-depth":2},p.members.map(m=>f(e.byId.get(m)))))}return i.push(o("Connections")),i.push(x("ol",{class:`${t}-list-items`},e.edges.map(b=>x("li",null,c(r(b.from))," to ",c(r(b.to)),b.label?[": ",s(qt(b.label))]:"",`${a(b.kind)}.`)))),i}if(e.type==="flowchart"){const f=i=>(e.byId.get(i)?.i??0)+1;return[x("ol",{class:`${t}-list-items`},e.nodes.map(i=>{const h=e.edges.filter(m=>m.from===i.id),b=i.shape==="decision"?"Decision":i.shape==="terminal"?h.length?"Start":"End":"Step",p=!i.detail&&/[.!?]$/.test(i.name)?" ":". ";return x("li",null,l(i),i.detail?[", ",i.mono?s(i.detail):i.detail]:"",`${p}${b}.`,d(i),h.length?x("ul",{class:`${t}-list-exits`},h.map(m=>x("li",null,m.label?`If ${qt(m.label)}: go to ${f(m.to)}, `:`Then: go to ${f(m.to)}, `,c(r(m.to)),a(m.kind)))):null)}))]}if(e.type==="data-flow")return[x("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const i=e.edges.filter(h=>h.from===f.id);return x("li",null,`${f.laneLabel}: `,l(f),f.detail?[", ",f.mono?s(f.detail):f.detail]:"",".",d(f),i.length?[" Then ",...i.flatMap((h,b)=>[b?"; ":"",`to step ${e.byId.get(h.to).step}, `,c(r(h.to)),h.label?[": ",s(qt(h.label))]:"",a(h.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[o("Participants"),x("ul",{class:`${t}-list-items`},e.nodes.map(h=>x("li",null,c(h.name),h.kind?`, ${h.kind}`:"",".",d(h),Ee(e,h))))];f.push(o("Messages"));let i=null;for(const h of e.steps){if("band"in h){i=null,f.push(x(`h${Math.min(6,n+1)}`,{class:`${t}-list-group`},h.band));continue}if("open"in h){i=null,f.push(x(`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(x(`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=x("ol",{class:`${t}-list-items`,start:h.n}),f.push(i)),i.c.push(x("li",null,s(h.label),": ",c(r(h.from))," to ",c(r(h.to)),`${a(h.kind)}.`,h.note?` ${Ft(h.note)}`:""))}return f}const g=[];for(const f of e.nodes)g.push(x(`h${n}`,{class:`${t}-list-group`},f.href?x("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(x("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(i=>x("li",null,s(i.name),i.key==="PK"?", primary key":i.key==="FK"?", foreign key":"",i.ref?[", references ",s(`${i.ref.table}.${i.ref.column}`),i.card?[" (",$n(f.id,i.ref.table,i.card,s),")"]:""]:i.type?`, ${i.type}`:"")),...f.more?[x("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return g}function Te(t,e=!1){const n=t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&Xt(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 ie(t,e=!1){const n=e&&t.type!=="sequence"&&Xt(t)&&t.cols>1&&t.rows>1,o=t.nodes.some(c=>c.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:n?["←","↑","↓","→"]:["←","→"],words:Ae(t)},{keys:["Home","End"],words:"the ends"},...o,{keys:["Esc"],words:"clear"}]}var Rn=(t,e)=>{for(let n=0;n({col:e.col,rows:[e.row,e.row2]});function Xt(t){return Rt(t,"spatial",()=>{const e=t.nodes.map(l=>({id:l.id,...Tn(t,l)})),n=(l,s)=>{const r=s==="right"||s==="left",a=s==="right"||s==="down",d=b=>r?[b.col,b.col]:b.rows,g=b=>r?b.rows:[b.col,b.col],f=d(l),i=g(l);let h=null;return e.forEach((b,p)=>{if(b===l)return;const m=d(b),M=g(b),L=a?m[0]-f[1]:f[0]-m[1];if(L<1)return;const z=Math.max(0,M[0]-i[1],i[0]-M[1]),v=[z===0?0:1,z===0?L:L+2*z,z,Math.abs(M[0]-i[0]),p];(!h||Rn(v,h.rank))&&(h={id:b.id,rank:v})}),h?.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 s=new Set([l]),r=[l];for(;r.length;)for(const a of Object.values(o[r.pop()]))a&&!s.has(a)&&(s.add(a),r.push(a));return s.size};return e.every(l=>c(l.id)===e.length)?o:null})}function Yt(t){return Rt(t,"turn-back-lanes",()=>{const e=new Map,n=new Set;if(!le(t))return{lane:e,dropped:n,lanes:0};const o=(a,d)=>(t.byId.get(a)?.row??0)*1e3+d,c=new Map;t.edges.forEach((a,d)=>{const g=`${a.to}.${a.toRow}.${a.card?.to??""}`,f=o(a.from,a.fromRow??0),i=o(a.to,a.toRow??0),h=c.get(g)??{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(g,h)});const l=[...c.values()].sort((a,d)=>d.hi-d.lo-(a.hi-a.lo)),s=[];let r=0;for(const a of l.reverse()){const d=new Set(s.filter(f=>f.lo<=a.hi&&a.lo<=f.hi).map(f=>f.lane));let g=0;for(;d.has(g);)g++;if(g>1){for(const f of a.members)n.add(f);continue}s.push({lo:a.lo,hi:a.hi,lane:g});for(const f of a.members)e.set(f,g);r=Math.max(r,g+1)}return{lane:e,dropped:n,lanes:r}})}var le=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function Qt(t,e,n){const o=n.prefix,c=xn(n.base),l=t.type==="sequence"||t.type==="schema"?null:Ie(t),s={P:o,ids:c,level:n.level,plan:l,hidden:n.hiddenClass},r=e.layout==="drawn",a=Tt(t,e),d=t.type==="sequence"||t.type==="schema"?r:!0,g=`h${t.heading}`,f=[`--_cols:${Jt(t)}`];if(t.type==="architecture"&&t.groups.length||r&&e.pad){const i=t.type==="architecture"?Le(t):[0,0,0,0],h=(p,m,M)=>p?p>1?`calc(${p} * var(--basalt-space-${m}))`:`var(--basalt-space-${m})`:M?`var(--basalt-space-${M})`:"0px",b=r&&e.pad?"3":void 0;f.push(`--_gpad:${h(i[0],"8",b)} ${h(i[1],"4")} ${h(i[2],"4",b)} ${h(i[3],"4")}`)}if(l?.gutter&&l.laneCount>2&&f.push(`--_gw:calc(${l.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),le(t)){const i=t.marks?"var(--basalt-space-6) + var(--basalt-space-1)":"var(--basalt-space-5)",h=Yt(t).lanes>1?`calc(${i} + var(--basalt-space-3))`:t.marks?`calc(${i})`:i;f.push(t.rtl?`--_gpad:0px 0px 0px ${h}`:`--_gpad:0px ${h} 0px 0px`)}return t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),r&&e.one&&f.push(`--_one:${e.one}px`),x("figure",{class:n.className?`${o} ${n.className}`:o,"aria-labelledby":c.title,"data-type":t.type,"data-cols":Jt(t),"data-reach":t.type==="architecture"?qe(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(";")},x("div",{class:`${o}-head`},x(g,{id:c.title,class:`${o}-title`},It(t.title)),n.hasSource?x("p",{class:`${o}-source`},x("bdi",null,{slot:"source"})):null),x("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?c.title:void 0,"aria-describedby":d?a?`${c.summary} ${c.keys}`:c.summary:void 0,"data-stops":a?"":void 0},In(s,t,e),t.text?null:x("div",{class:`${o}-ink`,"aria-hidden":"true"}),x("span",{class:`${o}-ruler`,"aria-hidden":"true"})),Be(o,t),x("p",{class:`${o}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),Tt(t,e)&&t.type!=="sequence"||r&&t.type==="sequence"?x("p",{class:`${o}-tap-hint`,"aria-hidden":"true"},`Tap ${Ae(t)} to highlight its lines. Tap it again to clear.`):null,x("div",{class:`${o}-foot`},{slot:"toggle"}),x("div",{id:c.list,class:`${o}-list`,hidden:!e.open},Re(o,t)),x("span",{id:c.keys,class:n.hiddenClass},n.viewer?`${Te(t,r)} ${n.viewer}`:Te(t,r)),x("figcaption",{id:c.summary,class:`${o}-summary`},{slot:"summary"}))}function zn(t){const e=getComputedStyle(t),n=(c,l)=>{const s=parseFloat(e.getPropertyValue(`--basalt-${c}`));return Number.isFinite(s)?s: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 Pt=(t,e)=>t==="main"?e.line:e.hair,xt=(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}},Ot=(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 Mt(t,e,n){const{l:o,t:c,r:l,b:s}=t.rect,r=(o+l)/2,a=(c+s)/2,d=(l-o)/2,g=(s-c)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const b=n,p=g*Math.max(0,1-Math.abs(b-r)/d);return{x:b,y:e==="top"?a-p:a+p}}const i=n,h=d*Math.max(0,1-Math.abs(i-a)/g);return{x:e==="left"?r-h:r+h,y:i}}if(t.shape==="terminal"){const i=Math.min(d,g);if(f){const m=n,M=Math.min(Math.max(m,o+i),l-i),L=m-M,z=Math.abs(L)>=i?0:Math.sqrt(i*i-L*L);return{x:m,y:Math.abs(L)<1e-6?e==="top"?c:s:e==="top"?a-z:a+z}}const h=n,b=h-a,p=Math.abs(b)>=i?0:Math.sqrt(i*i-b*b);return{x:e==="left"?o+i-p:l-i+p,y:h}}return f?{x:n,y:e==="top"?c:s}:{x:e==="left"?o:l,y:n}}function Wn(t,e,n){const{l:o,t:c,r:l,b:s}=e.rect,r=(o+l)/2,a=(c+s)/2,d=(l-o)/2,g=(s-c)/2;if(e.shape==="decision")return Math.abs(t.x-r)/d+Math.abs(t.y-a)/g<1-n/Math.min(d,g);if(e.shape==="terminal"){const f=Math.min(d,g),i=Math.min(Math.max(t.x,o+f),l-f);return Math.hypot(t.x-i,t.y-a)o+n&&t.xc+n&&t.ymatchMedia("(forced-colors: active)").matches;function Hn(t,e){const n=t.querySelector(`.${e}-ruler`),o=new Map;return(c,l)=>{const s=`${l}|${c}`;return o.has(s)||(n.setAttribute("data-f",l),n.textContent=c,o.set(s,n.getBoundingClientRect().width),n.textContent=""),o.get(s)}}var te=t=>t?t.split(/\s+/).filter(Boolean):[];function Dn(t,e,n){const o=e.space;let c=e.node,l=e.table;for(const a of t.nodes){if(a.shape==="table"){for(const p of a.columns??[]){const m=p.ref?`${t.rtl?"←":"→"} ${p.ref.table}`:p.type??"",M=o("6")+n(p.name,"mono")+(m?o("3")+n(m,"mono"):0)+2*o("3")+2*e.hair;l=Math.max(l,Math.ceil(M))}l=Math.max(l,Math.ceil(n(a.name,"table")+2*o("3")+2*e.hair+(a.href?16+o("1-5"):0)));continue}const d=a.shape==="terminal"?2*o("5"):2*o("3"),g=a.mark&&!Fn()?(a.shape==="participant"?2:1)*o("6"):0;let f=0;const i=a.href?16+o("1-5"):0,h=te(a.name);if(h.forEach((p,m)=>{f=Math.max(f,n(p,a.shape==="decision"?"name-500":"name")+(a.kind?0:g)+(m===h.length-1?i:0))}),t.type!=="data-flow")for(const p of te(a.kind))f=Math.max(f,n(p,"mono")+g);for(const p of te(a.detail))f=Math.max(f,n(p,a.mono?"mono":"sans"));const b=a.shape==="decision"?f/.62:f+d+2*e.hair;c=Math.max(c,Math.ceil(b))}const s=Jt(t);let r;return t.type==="data-flow"?r=e.lane+s*(c+o("12")):t.type==="schema"?r=s*l+(s-1)*(o("12")+(t.marks?o("3"):0))+(le(t)?(t.marks?o("6")+o("1"):o("5"))+(Yt(t).lanes>1?o("3"):0):0):t.type==="sequence"?r=s*c+(s-1)*o("5"):r=s*c+(s-1)*o("16")+qe(t)*o("4"),{track:c,table:l,least:Math.max(e.wide,r),own:Math.ceil(r)}}function We(t,e,n=!1){const o=n?c=>-Math.round(-c):Math.round;return{x:(c,l)=>l%2===1?o(c+t-.5)+.5-t:o(c+t)-t,y:(c,l)=>l%2===1?Math.round(c+e-.5)+.5-e:Math.round(c+e)-e}}function de(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 o=t.map(l=>({...l}));for(let l=1;l=2){const a=c[c.length-2];if(Math.abs(a.x-r.x)<.01&&Math.abs(r.x-s.x)<.01||Math.abs(a.y-r.y)<.01&&Math.abs(r.y-s.y)<.01){c[c.length-1]=s;continue}}c.push(s)}}return c}var _t=t=>t.slice(1).map((e,n)=>[t[n],e]);function ee(t,e,n){const o=[];for(let l=0;lMath.min(p.x,m.x)+.75&&zMath.min(M.y,L.y)+.75&&vl.split(/\s+/).map(parseFloat).filter(s=>Number.isFinite(s)),o=(l,s,r)=>{const a=[];let d=s;for(const g of l)a.push([d,d+g]),d+=g+r;return a},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,s)=>s%2===1):c}}var ct=t=>t==="left"||t==="right",Fe={top:"bottom",bottom:"top",left:"right",right:"left"};function fe(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 He(t,e,n){const o=[];t.edges.forEach((l,s)=>{const r=t.byId.get(l.from),a=t.byId.get(l.to),[d,g]=e[s],f=r.row===a.row&&ct(d)&&ct(g)&&d===Fe[g]||r.col===a.col&&!ct(d)&&!ct(g)&&d===Fe[g];o.push({edge:s,end:"from",node:r,side:d,far:a,straight:f,f:.5},{edge:s,end:"to",node:a,side:g,far:r,straight:f,f:.5})});const c=new Map;for(const l of o){const s=`${l.node.id}.${l.side}`;c.has(s)||c.set(s,[]),c.get(s).push(l)}for(const[l,s]of c){if(s[0].node.shape==="decision")continue;const r=p=>ct(p.side)?p.far.row-p.node.row:p.far.col-p.node.col,a=s.filter(p=>p.straight),d=s.filter(p=>!p.straight);if(d.sort((p,m)=>r(p)-r(m)||(ct(p.side)?p.far.col-m.far.col:p.far.row-m.far.row)*(r(p)<0?1:-1)),s.length>3&&n(`${l.replace(".","'s ")} side has ${s.length} lines; more than three is an error: use another side`),!a.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,m)=>{p.f=(m+1)/(d.length+1)});continue}const g=new Map;for(const p of a)g.has(p.far.id)||g.set(p.far.id,[]),g.get(p.far.id).push(p);for(const p of g.values())p.length>1&&p.sort((m,M)=>m.edge-M.edge).forEach((m,M)=>{m.f=p.length===2?M===0?.25:.75:(M+1)/(p.length+1)});const f=Math.min(...a.map(p=>p.f)),i=Math.max(...a.map(p=>p.f)),h=d.filter(p=>r(p)<0),b=d.filter(p=>r(p)>=0);h.forEach((p,m)=>{p.f=f*(m+1)/(h.length+1)}),b.forEach((p,m)=>{p.f=i+(1-i)*(m+1)/(b.length+1)})}return o}function De(t,e=8,n=8){return Rt(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(s=>{const r=t.byId.get(s.from),a=t.byId.get(s.to),[d,g]=fe(r,a);return[s.fromSide??d,s.toSide??g]}),l=new Map;for(const s of He(t,c,()=>{})){if(!ct(s.side)||s.node.shape!=="box")continue;const r=`${s.node.id}.${s.side}`;l.has(r)||l.set(r,[]),l.get(r).push(s.f)}for(const[s,r]of l){if(r.length<2)continue;const a=r.slice().sort((f,i)=>f-i).filter((f,i,h)=>i===0||f-h[i-1]>1e-9);let d=Math.max(e/a[0],e/(1-a[a.length-1]));for(let f=1;f{const s=t.byId.get(l.dataset.node);s&&c.set(s.id,{id:s.id,rect:xt(l,n),shape:s.shape,i:s.i})}),c}function Ke(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 ue=(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 Ze(t,e,n,o,c=!1){const l=(r,a)=>{const d=r+a-Math.floor(r+a);return d<.005||d>.995?[0]:d<=.5?[-d,1-d]:[1-d,-d]},s=c?l(-t.r,-e).map(r=>-r):l(t.l,e);for(const r of l(t.t,n))for(const a of s){if(!a&&!r)return t;const d={l:t.l+a,r:t.r+a,t:t.t+r,b:t.b+r};if(o(d))return d}return t}function Vn(t,e,n,o,c,l,s,r,a){const d=s.space,g=[],f=[],i=[],h=[],b=d("1"),p=e.filter(m=>t.edges[m.i]?.label).sort((m,M)=>+(t.edges[M.i].kind==="main")-+(t.edges[m.i].kind==="main")||m.i-M.i);for(const m of p){const M=t.edges[m.i].label,L=r(M,"label"),z=16*Kt(M),v=m.pts.length-2,C=[];_t(m.pts).forEach(([q,D],T)=>{const R=Math.abs(q.y-D.y)<.01,H=R?q.x:q.y;let Q=R?D.x:D.y;const at=Math.sign(Q-H)||1;T===v&&(Q-=at*s.head);let it=[[H,Q]];for(const et of c)for(const nt of R?[et.l,et.r]:[et.t,et.b]){const tt=R?q.y:q.x;(R?tt>et.t&&ttet.l&&ttnt>Math.min(u,w)+1&&nt{const tt=(et+nt)/2,$=R?{x:tt,y:q.y}:{x:q.x,y:tt};return!c.some(u=>$.x>u.l&&$.xu.t&&$.y1&&yt(et,nt)?1:0})}),C.sort((q,D)=>D.pri-q.pri||D.len-q.len);let B=null,j=!1;const F=(q,D=!0)=>{const T=ce(q,b);return D&&(q.ll.r||q.tl.b)||n.some(R=>ze(T,R))||g.some(R=>Ot(T,R))||o.heads.some(R=>Ot(T,R))||o.rects.some(R=>Ot(T,R))?!1:!e.some(R=>R.i!==m.i&&_t(R.pts).some(([H,Q])=>Ot(T,ue(H,Q,R.width))))};for(const q of C){for(const D of[1/2,1/3,2/3]){const T=q.p+(q.q-q.p)*D,R=[],H=d("2")+m.width/2;if(q.horiz?(q.len>=L+2*d("1")+d("3-5")&&R.push({box:{l:T-L/2-d("1"),r:T+L/2+d("1"),t:q.c-z/2,b:q.c+z/2},on:!0}),R.push({box:{l:T-L/2,r:T+L/2,t:q.c-H-z,b:q.c-H},on:!1}),R.push({box:{l:T-L/2,r:T+L/2,t:q.c+H,b:q.c+H+z},on:!1})):(q.len>=z+d("3")&&R.push({box:{l:q.c-L/2-d("1"),r:q.c+L/2+d("1"),t:T-z/2,b:T+z/2},on:!0}),R.push({box:{l:q.c+H,r:q.c+H+L,t:T-z/2,b:T+z/2},on:!1}),R.push({box:{l:q.c-H-L,r:q.c-H,t:T-z/2,b:T+z/2},on:!1})),B=R.find(Q=>F(Q.box))??null,B)break;!j&&R.some(Q=>F(Q.box,!1))&&(j=!0)}if(B)break}if(!B){i.push(m.i),j&&h.push(m.i);continue}const rt=Ze(B.box,a.ox,a.oy,q=>F(q));g.push(rt),f.push({i:m.i,text:M,box:rt,on:B.on})}return{labels:f,unseated:i,bounded:h}}function Je(t,e,n,o){const c=[],l=[];return t.querySelectorAll(`.${n}-gbox, .${n}-group`).forEach(s=>{if(s.getClientRects().length===0||getComputedStyle(s).display==="contents")return;const r=xt(s,e);l.push(r),c.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 a=s.querySelector(`:scope > .${n}-glabel`);a&&a.getClientRects().length&&c.push(xt(a,e))}),t.querySelectorAll(`.${n}-lane`).forEach((s,r)=>{if(!s.getClientRects().length)return;const a=xt(s,e);r>0&&c.push({l:a.l,r:a.r,t:a.t-o/2-.5,b:a.t-o/2+.5});const d=s.querySelector(`.${n}-lane-name`);d&&c.push(xt(d,e))}),{obstacles:{rects:c,heads:[]},groups:l}}function Ue(t,e){const{m:o,tk:c,P:l,drawing:s,origin:r,warn:a}=t,d=c.space,g=Ve(o,s,r,l),f=[...g.values()],i=Gn(s),h=r.left-Math.floor(r.left),b=r.top-Math.floor(r.top),p=We(h,b),m=s.clientWidth,M=s.clientHeight,L=y=>o.type==="data-flow"?y.col+1:y.col,z=parseFloat(getComputedStyle(s).rowGap)||0,v={w:m,h:M,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:h,oy:b};if(o.type==="sequence")return Zn(t,v,p);let C,B=[];o.type==="schema"?C=o.edges.map(y=>{const S=o.byId.get(y.from),E=o.byId.get(y.to);if(S.col===E.col){const W=!((o.rtl?S.col===1:S.col===o.cols)&&o.cols>1)===!o.rtl?"right":"left";return[W,W]}return E.col>S.col?["right","left"]:["left","right"]}):(C=o.edges.map(y=>{const S=o.byId.get(y.from),E=o.byId.get(y.to),[k,A]=fe(S,E);return[y.fromSide??k,y.toSide??A]}),B=He(o,C,a||(()=>{})));const j=(y,S)=>{const E=s.querySelector(`.${l}-node[data-node="${CSS.escape(y)}"] .${l}-row[data-row="${S}"]`);if(!E)return 0;const k=xt(E,r);return(k.t+k.b)/2},F=new Map;if(o.type==="schema"){const y=new Map;o.edges.forEach((E,k)=>{const A=`${E.to}.${E.toRow}.${C[k][1]}`;y.set(A,[...y.get(A)??[],k])});const S=E=>{const k=o.edges[E].card?.to;return k==="one"?0:k==="zero-or-one"?1:2};for(const E of y.values()){const k=[...new Set(E.map(S))].sort((A,W)=>A-W);if(k.length>1)for(const A of E)F.set(A,(k.indexOf(S(A))-(k.length-1)/2)*d("2"))}}const rt=y=>Math.round(y+h)-h,q=o.edges.map((y,S)=>{const[E,k]=C[S],A=g.get(y.from),W=g.get(y.to),J=Pt(y.kind,c);if(y.fk){const P=j(y.from,y.fromRow),ot=j(y.to,y.toRow)+(F.get(S)??0),gt=p.y(P,J),Bt=p.y(ot,J),Et=E==="right"?A.rect.r:A.rect.l,St=k==="right"?W.rect.r:W.rect.l;return{p1:{x:y.card?rt(Et):Et,y:gt},p2:{x:y.card?rt(St):St,y:Bt},r1:P,r2:Math.abs(gt-Bt)<.01?P:ot}}const K=B.find(P=>P.edge===S&&P.end==="from").f,Y=B.find(P=>P.edge===S&&P.end==="to").f;let U=Ge(A,E,K),Z=Ge(W,k,Y);const N=ct(E)?U.y:U.x;let G=ct(k)?Z.y:Z.x;return ct(E)?U={...U,y:p.y(U.y,J)}:U={...U,x:p.x(U.x,J)},ct(k)?Z={...Z,y:p.y(Z.y,J)}:Z={...Z,x:p.x(Z.x,J)},ct(E)&&ct(k)&&Math.abs(U.y-Z.y)<1.01&&(Z={...Z,y:U.y},G=N),!ct(E)&&!ct(k)&&Math.abs(U.x-Z.x)<1.01&&(Z={...Z,x:U.x},G=N),U=ct(E)?Mt(A,E,U.y):Mt(A,E,U.x),Z=ct(k)?Mt(W,k,Z.y):Mt(W,k,Z.x),{p1:U,p2:Z,r1:N,r2:G}}),D=new Set,T=(y,S)=>{D.has(y)||(D.add(y),a?.(`${o.edges[y].from} to ${o.edges[y].to} ${S}, so its line is not drawn; its row still writes the target`))};for(const y of Yt(o).dropped)T(y,"would need a third lane of turn-backs");const R=new Map,H=Lt();o.type==="schema"&&o.edges.forEach((y,S)=>{const E=o.byId.get(y.from),k=o.byId.get(y.to);if(Math.abs(E.col-k.col)<2)return;const A=Math.min(E.col,k.col),W=Math.max(E.col,k.col),J=o.nodes.filter(ot=>ot.col>A&&ot.colgt.row<=ot&>.row2>=ot+1)||Y.push({key:`g${ot}`,y:(K[ot-1][1]+K[ot][0])/2,inner:!0});Y.push({key:"top",y:K[0][0]-d("4"),inner:!1},{key:"bottom",y:K[K.length-1][1]+d("4"),inner:!1});const U=(q[S].r1+q[S].r2)/2,Z=t.pick?.[S]??Y.slice().sort((ot,gt)=>Math.abs(ot.y-U)-Math.abs(gt.y-U)||Number(gt.inner)-Number(ot.inner)||ot.y-gt.y)[0].key;H[S]=Z;const N=C[S][0]==="right"?E.col:E.col-1,G=i.cols[N-1],P=i.cols[N];R.set(S,{corridor:Z,first:G&&P?{key:`c${N}`,span:[G[1],P[0]]}:null,y:0})});const Q=new Map;for(const[y,S]of R){const E=o.edges[y],k=Q.get(S.corridor)??[],A=k.find(W=>{const J=o.edges[W[0]];return J.to===E.to&&J.toRow===E.toRow&&C[W[0]][1]===C[y][1]&&Math.abs(q[W[0]].p2.y-q[y].p2.y)<.5});A?A.push(y):k.length>=2?T(y,"would need a third lane in its corridor"):k.push([y]),Q.set(S.corridor,k)}for(const y of[...R.keys()])D.has(y)&&R.delete(y);const at=y=>{const S=o.edges[y[0]];return Math.abs(o.byId.get(S.from).col-o.byId.get(S.to).col)*1e4+Math.abs(q[y[0]].p1.x-q[y[0]].p2.x)},it=(y,S,E)=>{const k=i.rows;if(y==="top")return k[0][0]-d("4")-S*d("3");if(y==="bottom")return k[k.length-1][1]+d("4")+S*d("3");const A=Number(y.slice(1));return(k[A-1][1]+k[A][0])/2+(S-(E-1)/2)*d("3")},yt=(y,S)=>S.forEach((E,k)=>E.forEach(A=>{R.get(A).y=it(y,k,S.length)})),dt=()=>{for(const[y,S]of Q){const E=S.map(k=>k.filter(A=>R.has(A))).filter(k=>k.length);Q.set(y,E),yt(y,y==="top"||y==="bottom"?E.slice().sort((k,A)=>at(k)-at(A)):E.slice().sort((k,A)=>at(A)-at(k)))}};dt();const et=new Map,nt=new Set,tt=new Map,$=(y,S,E,k,A)=>{et.has(y)||et.set(y,{span:S,vertical:E,members:new Map});const W=et.get(y);W.members.has(k)||W.members.set(k,[]),W.members.get(k).push(A)},u=()=>{et.clear(),nt.clear(),tt.clear(),o.edges.forEach((y,S)=>{if(D.has(S))return;const E=R.get(S);E?.first&&$(E.first.key,E.first.span,!0,`far:${S}`,-(S+1));const[k,A]=C[S],{p1:W,p2:J}=q[S],K=o.byId.get(y.from),Y=o.byId.get(y.to);let U=null,Z=null,N=!1;if(k===A){if(ct(k)){const G=k==="right"?Math.max(L(K),L(Y)):Math.min(L(K),L(Y))-1,P=i.cols[G-1],ot=i.cols[G];P&&ot&&(U=`c${G}`,Z=[P[1],ot[0]],N=!0)}else{const G=k==="bottom"?Math.max(K.row2,Y.row2):Math.min(K.row,Y.row)-1,P=i.rows[G-1],ot=i.rows[G];P&&ot&&(U=`r${G}`,Z=[P[1],ot[0]],N=!1)}U&&nt.add(S)}else if(ct(k)&&ct(A)&&(E||Math.abs(W.y-J.y)>.5)){const G=L(Y),P=A==="left",ot=i.cols[(P?G-1:G)-1],gt=i.cols[(P?G:G+1)-1];ot&>&&(U=`c${P?G-1:G}`,Z=[ot[1],gt[0]],N=!0)}else if(!ct(k)&&!ct(A)&&Math.abs(W.x-J.x)>.5){const P=A==="top"?Y.row-1:Y.row2,ot=i.rows[P-1],gt=i.rows[P];ot&>&&(U=`r${P}`,Z=[ot[1],gt[0]],N=!1)}!U||!Z||(E&&tt.set(S,Z),$(U,Z,N,`${y.to}.${A}.${Math.round(N?J.y:J.x)}`,S))})};u();const w=new Map,O=y=>{const[S,E]=C[y],{p1:k,p2:A}=q[y],W=R.get(y);if(W){const J=tt.get(y),K=w.get(-(y+1))??(W.first?(W.first.span[0]+W.first.span[1])/2:k.x),Y=w.get(y)??(J?(J[0]+J[1])/2:A.x);return[k,{x:K,y:k.y},{x:K,y:W.y},{x:Y,y:W.y},{x:Y,y:A.y},A]}if(ct(S)&&ct(E)){if(S===E){const K=d(o.marks?"6":"4")+(o.type==="schema"&&o.cols===1?(Yt(o).lane.get(y)??0)*d("3"):0),Y=w.get(y)??(S==="right"?Math.max(k.x,A.x)+K:Math.min(k.x,A.x)-K);return[k,{x:Y,y:k.y},{x:Y,y:A.y},A]}if(Math.abs(k.y-A.y)<=.5)return[k,{x:A.x,y:k.y}];const J=w.get(y)??(k.x+A.x)/2;return[k,{x:J,y:k.y},{x:J,y:A.y},A]}if(!ct(S)&&!ct(E)){if(S===E){const K=w.get(y)??(S==="bottom"?Math.max(k.y,A.y)+d("4"):Math.min(k.y,A.y)-d("4"));return[k,{x:k.x,y:K},{x:A.x,y:K},A]}if(Math.abs(k.x-A.x)<=.5)return[k,{x:k.x,y:A.y}];const J=w.get(y)??(k.y+A.y)/2;return[k,{x:k.x,y:J},{x:A.x,y:J},A]}return ct(S)?[k,{x:A.x,y:k.y},A]:[k,{x:k.x,y:A.y},A]},I=y=>{const S=o.edges[y],E=Pt(S.kind,c),k=O(y),A=Ne(k,E,p);let W;return k.length===A.length&&(W=_t(k).map(([J,K])=>Math.abs(J.y-K.y)<.75?(J.y+K.y)/2:(J.x+K.x)/2),W[0]=q[y].r1,W.length>1&&(W[W.length-1]=q[y].r2)),{i:y,from:S.from,to:S.to,kind:S.kind,pts:A,tip:A[A.length-1],dir:de(A),dot:S.fk&&!S.card?A[0]:void 0,card:S.card,width:E,axes:W}},_=()=>o.edges.flatMap((y,S)=>D.has(S)?[]:[I(S)]);let X=null;const V=y=>{X??(X=_());const S=X.map(E=>y.has(E.i)?I(E.i):E);return{lines:S,score:Kn(S,y)*1e5+ee(S,void 0,y).length*1e3+pe(S.filter(E=>y.has(E.i)),f,o).length}},ft=(y,S)=>{const E=y.flatMap(k=>{const A=k<0?-k-1:k,{p1:W,p2:J}=q[A],K=R.get(A);return K?k<0?[W.y,K.y]:[K.y,J.y]:S?[W.y,J.y]:[W.x,J.x]});return[Math.min(...E),Math.max(...E)]},st=y=>y<0?-y-1:y,lt=y=>{const S=[...y.members.values()].map(k=>({members:k,run:ft(k,y.vertical)})).sort((k,A)=>k.run[0]-A.run[0]),E=[];for(const k of S){const A=E[E.length-1];A&&A.some(W=>W.run[0]!(k.length===1&&k[0].members.every(A=>nt.has(A))))},pt=y=>(S,E)=>y[S].run[0]{const S=pt(y),E=[];return y.forEach((k,A)=>{let W=0;for(;E.some((J,K)=>J===W&&S(A,K));)W++;E.push(W)}),E},ut=y=>Math.max(0,...kt(y))+1;if(o.marks)for(let y=0;y3){S=W.map(J=>J.members.map(st));break}if(!S)break;const E=A=>Math.max(...A),k=S.filter(A=>A.some(W=>R.has(W))).sort((A,W)=>E(W)-E(A))[0]??S.slice().sort((A,W)=>E(W)-E(A))[0];for(const A of k)T(A,"would need a fourth lane in a marked gutter"),R.delete(A);u()}const $t=(y,S,E,k=!1)=>{const A=o.rtl&&k?E-1-S:S,W=y[1]-y[0];if(!o.marks)return y[0]+W/(E+1)*(A+1);const J=c.foot+c.radiusXs,K=E>1?Math.min(W/(E+1),(W-2*J)/(E-1)):0;return(y[0]+y[1])/2+(A-(E-1)/2)*K};dt();for(const[y,S]of Q){if(y==="top"||y==="bottom"||S.length<2)continue;const E=new Set(S.flat());let k=S,A=1/0;for(const W of he(S.slice().sort((J,K)=>at(K)-at(J)))){yt(y,W),X=null;const J=V(E);J.scoreY.members);if(o.marks){const Y=ut(S),U=pt(S),Z=S.length,N=new Set(E.flat().map(st)),G=Et=>Et.forEach((St,zt)=>E[zt].forEach(jt=>w.set(jt,$t(y.span,St,Y,y.vertical))));let P=kt(S),ot=1/0,gt=null;const Bt=[P];if(Y**Z<=729)for(let Et=0;EtMath.floor(Et/Y**jt)%Y);St.every((zt,jt)=>St.every((oe,Vt)=>Vt<=jt||zt!==oe||!U(jt,Vt)))&&Bt.push(St)}for(const Et of Bt){G(Et);const St=V(N);St.scoreZ.forEach(G=>w.set(G,$t(y.span,N,k,y.vertical))));const U=V(A);U.scoreY.forEach(Z=>w.set(Z,$t(y.span,U,k,y.vertical)))),X=K}if(v.lines=_(),o.marks&&(v.lines=v.lines.filter(y=>{if(!y.card)return!0;const S=_t(y.pts),E=([A,W])=>Math.hypot(W.x-A.x,W.y-A.y),k=S.length===1?2*c.foot:c.foot+c.radiusXs-.5;return E(S[0])>=k&&E(S[S.length-1])>=k?!0:(T(y.i,"has no room for its marks at an end"),R.delete(y.i),!1)})),R.size){const y=new Set([...R.values()].map(E=>E.corridor)),S=[y.has("top")?"var(--basalt-space-8)":"0px"];for(let E=1;E<=o.rows;E++)S.push("auto",EKe(y,c));const vt=Vn(o,v.lines,f,bt,wt,{l:0,t:0,r:m,b:M},c,e,{ox:h,oy:b});return v.labels=vt.labels,v.unseated=vt.unseated,v.bounded=vt.bounded,v.overlaps=[...new Set(Xe(v.lines,null).flat())],v}function Kn(t,e){return Xe(t,e).length}function Xe(t,e){const n=[];for(let o=0;o=r)continue;const[m,M]=i?[a.x,d.x]:[a.y,d.y],[L,z]=i?[g.x,f.x]:[g.y,f.y];Math.min(Math.max(m,M),Math.max(L,z))-Math.max(Math.min(m,M),Math.min(L,z))>1&&n.push([l.i,s.i])}}return n}function*he(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const a=r===l.pts.length-1?Math.max(l.width/2,o.head/2):l.width/2;return s.x-a<-.5||s.x+a>e+.5||s.y-a<-.5||s.y+a>n+.5})&&c.push(l.i);return c}function pe(t,e,n){const o=[];for(const c of t){const l=_t(c.pts);e.some(s=>l.some(([r,a])=>Nn(r,a,s)))&&o.push(c.i)}return o}function Zn(t,e,n){const{m:o,tk:c,P:l,drawing:s,origin:r}=t,a=c.space,d=new Map;s.querySelectorAll(`.${l}-node`).forEach(v=>d.set(v.dataset.node,xt(v,r)));const g=s.querySelector(`.${l}-steps`),f=g?xt(g,r).b:e.h,i=v=>{const C=d.get(v);return C?n.x((C.l+C.r)/2,c.hair):0};for(const v of o.nodes){const C=d.get(v.id);C&&e.lifelines.push({x:i(v.id),y1:C.b,y2:f})}const h=v=>d.get(v.id),b=new Map;s.querySelectorAll(`.${l}-msg`).forEach(v=>{const C=xt(v,r);b.set(Number(v.querySelector(`.${l}-num`)?.textContent??0),(C.t+C.b)/2)});const p=c.activation,m=p/2,M=v=>{const C=o.byId.get(v.who);if(!C)return null;const B=i(v.who),F=(C.i===o.nodes.length-1&&o.nodes.length>1?-1:1)*(o.rtl?-1:1),rt=(v.depth-1)*a("1")*F,q=b.get(v.from)??0,D=b.get(v.to)??q,T=v.from===v.to;return{l:n.x(B-m+rt,c.hair),r:n.x(B+m+rt,c.hair),t:n.y(T?q-a("2")-a("1"):q,c.hair),b:n.y(T?q+a("2")+a("1"):D,c.hair)}},L=o.bars.map(v=>({bar:v,rect:M(v)})).filter(v=>v.rect);e.bars=L.map(v=>v.rect);const z=(v,C,B)=>L.filter(({bar:j})=>j.who===v&&j.to>=C&&(B?j.from<=C:j.fromF.bar.depth-j.bar.depth)[0]?.rect;s.querySelectorAll(`.${l}-msg`).forEach(v=>{const C=v.dataset.from,B=v.dataset.to,j=v.dataset.kind??"plain",F=Pt(j,c),rt=xt(v,r),q=n.y((rt.t+rt.b)/2,F),D=Number(v.querySelector(`.${l}-num`)?.textContent??0);let T=i(C),R=i(B),H;if(C===B){const nt=v.dataset.self==="start"?-a("6"):a("6"),tt=z(C,D,!0),$=tt?nt>0?tt.r:tt.l:T,u=n.y(q-a("2"),F),w=n.y(q+a("2"),F);H=[{x:$,y:u},{x:n.x(T+nt,F),y:u},{x:n.x(T+nt,F),y:w},{x:$,y:w}]}else{const nt=R>T?1:-1,tt=z(C,D,!1),$=z(B,D,!0);tt&&(T=nt>0?tt.r:tt.l),$&&(R=nt>0?$.l:$.r),H=[{x:T,y:q},{x:R,y:q}]}e.lines.push({i:D,from:C,to:B,kind:j,pts:H,tip:H[H.length-1],dir:de(H),width:F});const Q=v.querySelector(`.${l}-said`),at=v.querySelector(`.${l}-note`),it=o.byId.get(C),yt=o.byId.get(B);if(!it||!yt)return;const dt=C===B?(()=>{const nt=o.nodes.find($=>$.col===it.col+(v.dataset.self==="start"?-1:1)),tt=nt?i(nt.id):v.dataset.self==="start"?0:e.w;return Math.abs(tt-T)-a("6")-a("2-5")-a("2")})():Math.abs(R-T)-2*a("2");Math.max(Q?Q.getBoundingClientRect().width:0,at?at.getBoundingClientRect().width:0)>dt+.5&&e.unseated.push(D)}),s.querySelectorAll(`.${l}-fhead`).forEach(v=>{const C=v.parentElement?.querySelector(`:scope > .${l}-fbox`);if(!C)return;[...v.children].reduce((j,F)=>j+F.getBoundingClientRect().width,0)+a("3")>C.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${v.querySelector(`.${l}-flabel`)?.textContent??""}" is wider than its participants`)});{const v=[...s.querySelectorAll(`.${l}-fbox`)].flatMap(C=>{const B=xt(C,r);return[{x:B.l+.5,t:B.t,b:B.b},{x:B.r-.5,t:B.t,b:B.b}]});v.length&&s.querySelectorAll(`.${l}-said, .${l}-note, .${l}-band > span`).forEach(C=>{if(!C.getClientRects().length)return;const B=ce(xt(C,r),a("1"));v.some(j=>B.lj.x&&B.tj.t)&&(e.misfit??(e.misfit=[])).push(`"${C.textContent?.trim()??""}" would lie on a frame's side`)})}return e}function Jn(t,e,n,o,c){const l=[];for(const[s,r]of t){if(!r.getClientRects().length)continue;const a=xt(r,n),d=xt(s,n),g=getComputedStyle(r),f=getComputedStyle(s),i={l:a.l+(parseFloat(g.paddingLeft)||0),r:a.r-(parseFloat(g.paddingRight)||0)},h=i.r-i.l,b=d.l+(parseFloat(f.borderLeftWidth)||0),p=d.r-(parseFloat(f.borderRightWidth)||0),m=[];for(const j of e)for(const[F,rt]of _t(j.pts)){const q=ue(F,rt,j.width);q.ta.t&&m.push({l:q.l,r:q.r})}const M=c("2-5"),L=j=>m.every(F=>F.r<=j-M+.01||F.l>=j+h+M-.01);if(L(i.l))continue;const z=m.map(j=>o?i.r-(j.l-M):j.r+M-i.l).filter(j=>j>0).sort((j,F)=>j-F),v=j=>o?i.l-j:i.l+j,C=j=>o?v(j)>=b+c("3")-.01:v(j)+h<=p-c("3")+.01,B=z.find(j=>C(j)&&L(v(j)));if(B===void 0){l.push(r.textContent??"");continue}r.style.setProperty("--_gx",`${Math.round(B*100)/100}px`)}return l}function Qe(t,e,n,o=Lt()){const{m:c,tk:l,P:s,drawing:r,origin:a}=t,d=l.space,g=Ve(c,r,a,s),f=[...g.values()],i=a.left-Math.floor(a.left),h=a.top-Math.floor(a.top),b=We(i,h,!!c.rtl),p=r.clientWidth,m=r.clientHeight,M={w:p,h:m,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:i,oy:h},L=Lt();if(c.type==="sequence"||c.type==="schema")return{geo:M,grow:L};const z=!!c.rtl,v=z?-1:1,C=u=>z?u.r:u.l,B=u=>z?u.l:u.r,j=z?"left":"right",F=(u,w,O,I)=>{const _=u+I*v*w,X=_+I*v*O;return{l:Math.min(_,X),r:Math.max(_,X)}},rt=getComputedStyle(r),q=z?parseFloat(rt.paddingLeft)||0:p-(parseFloat(rt.paddingRight)||0),D=(u,w,O)=>{const I=[u];for(let _=1;_<=(Ct(o,w)??0);_++)I.push({...u,t:u.t+O*d("4")*_,b:u.b+O*d("4")*_});return I},T=new Map;r.querySelectorAll(`.${s}-node`).forEach(u=>{const w=u.parentElement,O=xt(w,a),I=getComputedStyle(w);T.set(u.dataset.node,z?O.l+(parseFloat(I.paddingLeft)||0)+(parseFloat(I.borderLeftWidth)||0):O.r-(parseFloat(I.paddingRight)||0)-(parseFloat(I.borderRightWidth)||0))});const R=c.nodes,H=u=>g.get(R[u].id),Q=new Map;r.querySelectorAll(`.${s}-group > .${s}-glabel`).forEach(u=>{u.style.removeProperty("--_gx"),Q.set(u.parentElement,u)});const at=new Map;for(const[u,w]of Q)w.getClientRects().length&&at.set(u,xt(w,a));const it=u=>{const w=r.querySelector(`.${s}-node[data-node="${CSS.escape(u)}"]`),O=w?.parentElement;return!!(O?.matches(`.${s}-group[data-turn]`)&&O.querySelector(`:scope > .${s}-node`)===w)},yt=(u,w,O)=>it(w)?Array.from({length:Math.round(O/16)+1},(I,_)=>({...u,t:u.t-_*d("4"),b:u.b-_*d("4")})):[u],dt=[],et=u=>Pt(c.edges[u].kind,l);c.edges.forEach((u,w)=>{const O=n.routes[w],I=g.get(u.from),_=g.get(u.to),X=et(w);let V=[];const ft=u.label,st=ft?e(ft,"label"):0,lt=ft?16*Kt(ft):16,pt=d("4");if(O==="down"||O==="up"){const ut=Math.max(I.rect.l,_.rect.l),$t=Math.min(I.rect.r,_.rect.r),bt=c.edges.map((S,E)=>({o:S,j:E})).filter(({o:S,j:E})=>(n.routes[E]==="down"||n.routes[E]==="up")&&(S.from===u.from&&S.to===u.to||S.from===u.to&&S.to===u.from)),wt=bt.findIndex(S=>S.j===w),vt=bt.length<2?.5:bt.length===2?wt===0?.25:.75:(wt+1)/(bt.length+1);let y=b.x(ut+($t-ut)*vt,X);if(O==="down"){const S=r.querySelector(`.${s}-node[data-node="${CSS.escape(u.to)}"]`),E=S?.parentElement,k=E&&E.matches(`.${s}-group`)&&E.querySelector(`:scope > .${s}-node`)===S?at.get(E):void 0;if(k&&E&&!E.contains(r.querySelector(`.${s}-node[data-node="${CSS.escape(u.from)}"]`))){const A=d("2-5")+X/2;if(y>k.l-A&&y=ut+d("6"):W<=$t-d("6"))&&(y=b.x(W,X))}}}if(V=O==="down"?[Mt(I,"bottom",y),Mt(_,"top",y)]:[Mt(I,"top",y),Mt(_,"bottom",y)],ft){let S=Math.min(V[0].y,V[1].y),E=Math.max(V[0].y,V[1].y);O==="down"?E-=l.head:S+=l.head;const k=[...r.querySelectorAll(`.${s}-group`)].map(K=>xt(K,a));let A=[[S,E]];for(const K of k)for(const Y of[K.t,K.b])A=A.flatMap(([U,Z])=>Y>U+1&&Yk.some(U=>(K+Y)/2>U.t&&(K+Y)/2U.l&&y1){const K=A.filter(([U,Z])=>!W(U,Z));[S,E]=(K.length?K:A).reduce((U,Z)=>Z[1]-Z[0]>U[1]-U[0]?Z:U)}const J=[1/2,1/3,2/3].map(K=>{const Y=S+(E-S)*K;return{l:y-st/2-d("1"),r:y+st/2+d("1"),t:Y-lt/2,b:Y+lt/2}});dt.push({k:w,cands:J,on:!0,card:O==="down"?u.to:u.from})}}else if(O==="trunk"||O==="rail"){const ut=O==="rail"?z?Math.min(I.rect.r,_.rect.r):Math.max(I.rect.l,_.rect.l):C(I.rect),$t=b.x(ut+v*d(O==="trunk"?"8":"3"),X),bt=Mt(I,"bottom",$t);if(O==="rail"){if(V=[bt,Mt(_,"top",$t)],ft){const wt=_.rect.t-d("6");dt.push({k:w,cands:D({...F($t,d("2-5"),st,1),t:wt-lt/2,b:wt+lt/2},u.to,-1),on:!1,card:u.to})}}else{const wt=b.x(C(_.rect)+v*d("6"),X),vt=b.y(_.rect.t-pt,X);V=[bt,{x:$t,y:vt},{x:wt,y:vt},Mt(_,"top",wt)];const y={...F(wt,d("2-5"),st,1),t:vt-lt/2,b:vt+lt/2};ft&&dt.push({k:w,cands:[...yt(y,u.to,lt),...D(y,u.to,-1).slice(1)],on:!1,card:u.to})}}else{const ut=Z=>T.get(Z)??(z?0:p),$t=z?Math.max(ut(u.from),ut(u.to)):Math.min(ut(u.from),ut(u.to)),bt=b.x(n.gutter?q+v*(n.lanes[w]+1)*d("3-5"):$t-v*d("2-5"),X),wt=b.y(I.rect.t+(I.rect.b-I.rect.t)*n.exits[w],X),vt=Mt(I,j,wt),y=O==="end-down",S=c.edges.map((Z,N)=>({o:Z,j:N})).filter(({o:Z,j:N})=>n.routes[N]===O&&Z.to===u.to).sort((Z,N)=>n.lanes[N.j]-n.lanes[Z.j]||Z.j-N.j),E=Math.max(0,S.findIndex(({j:Z})=>Z===w)),k=B(_.rect)-v*(d("6")+E*d("3")),A=B(_.rect)-v*(d("6")+(S.length-1)*d("3")),W=b.x(k,X),J=y?_.rect.t-pt-E*d("5"):_.rect.b+pt+E*d("5"),K=b.y(J,X);V=[vt,{x:bt,y:vt.y},{x:bt,y:K},{x:W,y:K},Mt(_,y?"top":"bottom",W)];const Y=y?u.to:R[_.i+1]?.id??u.to,U={...F(A,d("2-5"),st,-1),t:J-lt/2,b:J+lt/2};ft&&dt.push({k:w,cands:[...y?yt(U,Y,lt):[U],...D(U,Y,y?-1:1).slice(1)],on:!1,card:Y})}const kt=Ne(V,X,b);M.lines.push({i:w,from:u.from,to:u.to,kind:u.kind,pts:kt,tip:kt[kt.length-1],dir:de(kt),width:X})}),M.crossings=ee(M.lines),M.through=pe(M.lines,f,c),M.outside=Ye(M.lines,p,m,l),M.seatless=Jn(Q,M.lines,a,z,d);const{obstacles:nt}=Je(r,a,s,0);nt.heads=M.lines.map(u=>Ke(u,l));const tt=[],$={l:0,t:0,r:p,b:m};for(const u of dt){const w=_=>{const X=ce(_,d("1"));return _.l<$.l-.5||_.r>$.r+.5||_.t<$.t-.5||_.b>$.b+.5||f.some(V=>ze(X,V))||tt.some(V=>Ot(X,V))||nt.heads.some(V=>Ot(X,V))||nt.rects.some(V=>Ot(X,V))||M.lines.some(V=>V.i!==u.k&&_t(V.pts).some(([ft,st])=>Ot(X,ue(ft,st,V.width))))},O=u.cands.find(_=>!w(_));O||(L[u.card]=(L[u.card]??0)+1,M.unseated.push(u.k));const I=O?Ze(O,i,h,_=>!w(_),z):u.cands[0];tt.push(I),M.labels.push({i:u.k,text:c.edges[u.k].label,box:I,on:u.on})}return{geo:M,grow:L}}function Pe(t,e,n=0){const o=s=>String(Math.round(s*100)/100);let c=`M${o(t[0].x)} ${o(t[0].y)}`;for(let s=1;s{const{crow:D,ring:T}=Ce(j,F.x,F.y,rt,n.head,n.dot);return`${T?``:""}`};return`${B(e.card.from,v,Math.sign(C.x-v.x)||1,"from")}${B(e.card.to,e.tip,-l.x||1,"to")}`}const s=e.kind==="dashed",r=n.head,a=n.head/2,d=s?1:r-1,g=e.pts.map(v=>({...v})),f=g[g.length-1];f.x-=l.x*d,f.y-=l.y*d;const i=e.tip.x-l.x*r,h=e.tip.y-l.y*r,b=-l.y*a,p=l.x*a,m=v=>Math.round(v*100)/100,M=mt(e.kind),L=s?``:``,z=e.dot?``:"";return`${L}${z}`}function tn(t,e,n,o){const c=new Map,l=new Map;for(const r of e.crossings)l.has(r.under)||l.set(r.under,[]),l.get(r.under).push(r);let s="";for(const[r,a]of l){const d=`${o}-cut-${r}`;c.set(r,d);const g=a.map(f=>{const i=e.lines[f.top],h=e.lines[f.under],b=i.width/2+n.cut,p=h.width/2+1;return f.underVertical?``:``}).join("");s+=`${g}`}return{defs:s,ids:c}}function en(t,e,n,o){const{defs:c,ids:l}=tn(t,e,n,o),s=e.lifelines.map(i=>``).join(""),r=(e.bars??[]).map(i=>``).join(""),a=e.lines.map((i,h)=>Xn(t,i,n,l.get(h)??null,i.from===i.to?n.radiusXs:n.radius)).join(""),g=`${s?`${s}`:""}${c?`${c}`:""}${r}${a}`,f=e.labels.map(i=>`1?' data-lines="2"':""}>${i.text.split(` -`).map(mt).join("
")}
`).join("");return g+f}function Yn(t,e,n){const o=t.querySelector(`.${e}-ink`);if(!o||!n)return;const c=s=>`${Math.round(s*100)/100}px`;o.querySelectorAll(`:scope > .${e}-label`).forEach((s,r)=>{const a=n.labels[r];if(!a||s.dataset.edge!==String(a.i))return;const d=[["left",c(a.box.l)],["top",c(a.box.t)],["width",c(a.box.r-a.box.l)]];for(const[g,f]of d)s.style.getPropertyValue(g)!==f&&s.style.setProperty(g,f)})}function ge(t,e,n,o,c,l,s,r){const d=t.querySelector(`.${n}-drawing`);if(!d||t.clientWidth===0)return{dyn:c,geo:null,ink:"",tokens:null};const g=zn(t),f=Hn(d,n),i=Dn(e,g,f);r?.(i.least);const h=t.clientWidth,b=(()=>{const q=document.activeElement;return q&&d.contains(q)&&q.dataset.node?q.dataset.node:void 0})(),p=q=>Tt(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:b&&q.layout!=="drawn"?b:void 0};let m=!1;const M=q=>{if(m=!1,e.type!=="flowchart")return q;l({...q,heights:void 0,words:void 0});const D=Lt(),T=Lt();return d.querySelectorAll(`.${n}-node[data-shape="decision"]`).forEach(R=>{const H=R.querySelector(`.${n}-words`);if(!H)return;const Q=R.getBoundingClientRect(),at=dt=>{const et={w:dt.width+2*g.space("2-5"),h:dt.height+2*g.space("2")},nt=1-et.w/Q.width,tt=nt>.05?et.h/2/nt:et.h*10;return Math.max(g.space("16"),Math.ceil(Q.width/5),Math.ceil(2*tt))},it=H.getBoundingClientRect();let yt=at(it);if(yt>Q.width){const dt=$=>(R.style.setProperty("--_ww",`${$}px`),H.getBoundingClientRect()),et=Math.floor(R.clientWidth-2*g.space("2-5"));let nt=Math.ceil(it.width),tt=it.height;for(;nt1;){const I=$+u>>1;dt(I).heightQ.width&&(m=!0)}),{...q,heights:D,words:Object.keys(T).length?T:void 0}},L=()=>({m:e,tk:g,P:n,drawing:d,origin:d.getBoundingClientRect(),warn:s}),z=c.autoOpen?{open:!1,autoOpen:void 0}:{},v=(q,D)=>D.map(T=>Gt(e,q.lines.find(R=>R.i===T))).join(", ");if(e.text)return{dyn:{...c,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:g,least:i.least};if(h>=i.least&&!e.unplaced){const q=H=>{let Q=p({...c,...z,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:H||void 0,rows:void 0,one:e.type!=="sequence"&&Jt(e)===1?i.own:void 0});Q=M(Q),l(Q);let at=Ue(L(),f);return at.corridors&&(Q={...Q,rows:at.corridors.rows},l(Q),at=Ue({...L(),pick:at.corridors.pick},f)),{dd:Q,g:at}};let{dd:D,g:T}=q(!1);const R=H=>H.through.length>0||H.outside.length>0||(H.overlaps?.length??0)>0||(H.misfit?.length??0)>0||m;if(!R(T)&&T.unseated.length&&T.unseated.every(H=>T.bounded?.includes(H))){const H=q(!0);!R(H.g)&&!H.g.unseated.length&&({dd:D,g:T}=H)}if(!R(T)&&!T.unseated.length)return T.crossings.length&&s?.(`${T.crossings.length} crossing${T.crossings.length===1?"":"s"} in the drawn layout: ${T.crossings.map(H=>`${Gt(e,T.lines[H.top])} over ${Gt(e,T.lines[H.under])}`).join("; ")}`),{dyn:D,geo:T,ink:en(n,T,g,o),tokens:g,least:i.least};m&&s?.(`the drawn layout does not fit at ${Math.round(h)}px: a decision would be taller than it is wide`),T.misfit?.length&&s?.(`the drawn layout does not fit at ${Math.round(h)}px: ${T.misfit.join("; ")}`),T.through.length&&s?.(`the drawn layout does not fit at ${Math.round(h)}px: ${v(T,T.through)} would pass through a node`),T.overlaps?.length&&s?.(`the drawn layout does not fit at ${Math.round(h)}px: ${v(T,T.overlaps)} would lie on one another`),T.outside.length&&s?.(`the drawn layout does not fit at ${Math.round(h)}px: ${v(T,T.outside)} would leave the drawing`),T.unseated.length&&s?.(`the drawn layout does not fit at ${Math.round(h)}px: no clean seat for ${T.unseated.map(H=>e.type==="sequence"?`message ${H}`:`"${qt(e.edges[H]?.label??"")}"`).join(", ")}`)}let C=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,one:void 0});if(C=M(C),l(C),e.type==="sequence"||e.type==="schema")return{dyn:C,geo:null,ink:"",tokens:g,least:i.least};const B=Ie(e);let j=Qe(L(),f,B,C.grow);for(let q=0;q<6&&Object.keys(j.grow).length;q++){const D=Lt(C.grow);for(const[T,R]of Object.entries(j.grow))D[T]=(Ct(D,T)??0)+R;C={...C,grow:D},l(C),j=Qe(L(),f,B,D)}const F=j.geo;if(!B.third&&B.laneCount>2&&s?.(`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&&s?.(`the stacked drawing has no clean seat for ${[...new Set(F.unseated)].map(T=>`"${qt(e.edges[T]?.label??"")}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),F.through.length&&s?.(`in the stacked drawing ${v(F,F.through)} would pass through a node, so its lines are not drawn`),F.outside.length&&s?.(`in the stacked drawing ${v(F,F.outside)} would leave the drawing, so its lines are not drawn`),B.third&&s?.("the stacked drawing would need a fifth end lane, so its lines are not drawn","error");const q={...F,lines:[],labels:[],crossings:[]};d.querySelectorAll(`.${n}-group > .${n}-glabel`).forEach(T=>T.style.removeProperty("--_gx"));const D=p({...C,grow:Lt(),bare:!0,open:c.bare?c.open:!0,autoOpen:c.bare?c.autoOpen:c.open?void 0:!0});return l(D),{dyn:D,geo:q,ink:"",tokens:g,least:i.least}}return F.seatless?.length&&s?.(`a stacked group's label has no clear seat on its top edge: ${F.seatless.map(q=>`"${q}"`).join(", ")}`),F.crossings.length&&s?.(`${F.crossings.length} crossing${F.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${F.crossings.map(q=>`${Gt(e,F.lines[q.top])} over ${Gt(e,F.lines[q.under])}`).join("; ")}`),{dyn:C,geo:F,ink:en(n,F,g,o),tokens:g,least:i.least}}function Gt(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 Qn(t,e,n,o,c,l){const s=new Set;if(l){s.add(l);for(const p of n?.lines??[])p.from===l&&s.add(p.to),p.to===l&&s.add(p.from)}if(t.toggleAttribute("data-tracing",!!l),t.querySelectorAll(`.${e}-node`).forEach(p=>p.toggleAttribute("data-near",s.has(p.dataset.node))),!n||!o)return;const r=p=>!!l&&(p.from===l||p.to===l),a=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 m=d.get(String(p.i));m&&(m.toggleAttribute("data-lit",r(p)),m.toggleAttribute("data-dim",!!l&&!r(p)))}if(t.querySelectorAll(`.${e}-label`).forEach(p=>{const m=n.lines.find(M=>String(M.i)===p.dataset.edge);p.toggleAttribute("data-lit",!!(m&&r(m)))}),a){for(const p of n.lines)if(r(p)){const m=d.get(String(p.i));m&&a.appendChild(m)}}const g=ee(n.lines,r),{defs:f,ids:i}=tn(e,{...n,crossings:g},o,c),h=t.querySelector(`.${e}-svg`);if(!h)return;let b=h.querySelector("defs");!b&&f&&(b=document.createElementNS("http://www.w3.org/2000/svg","defs"),h.insertBefore(b,h.firstChild)),b&&(b.innerHTML=f),n.lines.forEach((p,m)=>{const M=d.get(String(p.i))?.querySelector(`.${e}-line`);if(!M)return;const L=i.get(m);L?M.setAttribute("mask",`url(#${L})`):M.removeAttribute("mask")})}var Pn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function to(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()||no(t)?"done":"pending")}}var eo=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function no(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(eo(t))!==null}catch{return!1}}function nn(t){const e=t.getAttribute("data-entrance");e!=="pending"&&e!=="running"||(t.setAttribute("data-entrance","done"),t.dispatchEvent(new Event("basalt-diagram-settle")))}function oo(t,e,n,o=!1,c=!1){const l=o?Xt(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 s=t.byId.get(e)?.i??0,r=t.nodes.length;let a;if(n==="ArrowRight"||n==="ArrowDown")a=s+1;else if(n==="ArrowLeft"||n==="ArrowUp")a=s-1;else if(n==="Home")a=0;else if(n==="End")a=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,a))].id}var so=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],on=["data-layout","data-measured","data-bare","data-motion","data-first-visit","data-rtl","data-cols","data-reach","data-gutter","data-marks"],ao=["--_track","--_h","--_ww","--_gap","--_ggrow","--_tl","--_gpad","--_gw","--_mh","--_rows","--_row-gap","--_one"],sn=t=>t==null||t===!1;function ro(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 o=n?on:so;for(const s of o)sn(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,g=new Map(String(r??"").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 g)d.getPropertyValue(f).trim()!==i&&d.setProperty(f,i);for(const f of ao)g.has(f)||d.removeProperty(f);continue}if(n&&!on.includes(s))continue;if(sn(r)){t.removeAttribute(s);continue}const a=r===!0?"":String(r);t.getAttribute(s)!==a&&t.setAttribute(s,a)}if(e.t==="svg"||typeof e.a.class=="string"&&(/-ruler$/.test(e.a.class)||/-ink$/.test(e.a.class)&&!e.a.class.endsWith("-text-ink"))||e.c.some(s=>typeof s!="string"&&"slot"in s))return;const c=[...t.children];let l=0;for(const s of e.c)if(!(typeof s=="string"||"slot"in s)){for(let r=l;rt.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,h,b){return{prefix:n,base:i,hasSource:h.source!==void 0&&h.source!==null&&h.source!=="",hiddenClass:"visually-hidden",viewer:b?b.keys:void 0}}function l(i,h,b,p){var m=function(M){return''+mt(M)+""};return{source:mt(String(h.source||"")),summary:mt(String(h.summary||"")),hint:ie(i).map(function(M){return""+M.keys.map(m).join(" ")+" "+mt(M.words)+""}).join(""),toggle:'"}}function s(i,h,b){for(var p=i.layout==="auto"&&(i.type==="architecture"||i.type==="flowchart"||i.type==="schema"),m=p?Array.isArray(i.placement)?i.placement:i.placement?[i.placement]:[]:[],M=i.direction||(i.type==="flowchart"?"down":"right"),L=null,z=0;z");return{open:B.slice(0,j+1),inner:B.slice(j+1,B.length-9),warnings:v.errors.map(function(F){return"error: "+F}).concat(v.warnings)}}var r=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-marks","data-layout","data-measured","data-bare"],a=["--_cols","--_gpad","--_track"];function d(i,h,b,p){i.__diagram&&i.__diagram.stop();var m=(i.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),M=getComputedStyle(i).direction==="rtl",L=h.layout==="auto"&&(h.type==="architecture"||h.type==="flowchart"||h.type==="schema"),z=L?Array.isArray(h.placement)?h.placement:h.placement?[h.placement]:[]:[];L&&!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 v=h.direction?[h.direction]:h.type==="flowchart"?["down","right"]:["right","down"],C=function(N){for(var G=0;G .diagram-drawing")){if(!m||!i.querySelector("#"+CSS.escape(m+"-title"))){for(;document.getElementById("dg"+ ++o+"-title"););m="dg"+o}var j=s(h,m,p),F=document.createElement("div");F.innerHTML=j.open+"";var rt=F.firstChild;r.forEach(function(N){i.removeAttribute(N)}),a.forEach(function(N){i.style.removeProperty(N)});for(var q=0;q :not(script[data-diagram])").forEach(function(N){N.remove()}),i.insertAdjacentHTML("beforeend",j.inner)}B.warnings.forEach(function(N){console.warn("Basalt diagram: "+N)}),B.errors.forEach(function(N){console.error("Basalt diagram: "+N)}),B.motion.animated&&B.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 T=c(m,h,p),R={},H=null,Q=null,at=null,it=null,yt=Object.create(null),dt=function(N,G){yt[N]||(yt[N]=1,(G==="error"?console.error:console.warn)("Basalt diagram: "+N))},et=function(N){ne(i,Qt(B,N,T))},nt=i.querySelector(".diagram-ink"),tt=i.querySelector(".diagram-toggle"),$=!p&&B.motion.animated&&typeof e.diagramMotion=="function",u=null,w=null,O=function(){$&&nn(i)};function I(){Qn(i,n,H&&H.geo,H&&H.tokens,m,Q||it||at),V()}var _=null,X=!p&&matchMedia("(hover: none), (pointer: coarse)").matches;function V(){var N=X&&!p&&nt&&nt.innerHTML!=="";if(i.toggleAttribute("data-touch",!!(X&&!p)),N&&!_){var G=i.querySelector(":scope > .diagram-foot");if(!G)return;_=document.createElement("button"),_.type="button",_.className="btn diagram-clear",_.setAttribute("data-variant","secondary"),_.setAttribute("data-size","sm"),_.innerHTML="Clear highlight",_.addEventListener("click",function(){it&&(it=null,I())}),G.insertBefore(_,G.querySelector(":scope > .diagram-export-note"))}else!N&&_&&(_.remove(),_=null);_&&_!==_.parentNode.lastElementChild&&document.activeElement!==_&&_.parentNode.appendChild(_),_&&(it?_.removeAttribute("aria-disabled"):_.setAttribute("aria-disabled","true"))}function ft(N){if(!N.defaultPrevented){var G=bn(i,n,N,it);G!==void 0&&(O(),X=!0,it=G,I())}}function st(){tt&&(tt.setAttribute("aria-expanded",String(!!R.open)),tt.firstElementChild.textContent=R.open?"Hide the list":"View as list")}function lt(){if(L&&z.length>1&&!p){for(var N=null,G=[],P=!1,ot=0;ot1&&p&&!h.direction&&p.room){for(var oe=p.room(),Vt=-1,me=null,ye=0;yeVt+1e-6&&(Vt=rn,me=$e)}}}me&&(B=me)}H=(p?p.measure:ge)(i,B,n,m,R,et,dt),R=H.dyn,et(R),st();var be=i.querySelector(":scope > .diagram-hint");if(be){var ln=ie(B,R.layout==="drawn").map(function(At){return""+At.keys.map(function(fo){return''+mt(fo)+""}).join(" ")+" "+mt(At.words)+""}).join("");be.innerHTML!==ln&&(be.innerHTML=ln)}Tt(B,R)||(at=it=null);var cn=nt&&H.ink!==w;cn&&(nt.innerHTML=H.ink,w=H.ink),Yn(i,n,H.geo),I();var co=B.text?i.querySelector(".diagram-text[data-art]"):null;B.text&&typeof e.diagramText=="function"&&e.diagramText(i,B,h,p);var dn=B.text?i.querySelector(".diagram-text[data-art]"):null;$&&H.tokens&&(to(i,!!(H.geo&&H.geo.lines.length)||!!dn),(cn||dn!==co)&&u&&u.redrawn()),p&&p.onMeasured&&H.tokens&&p.onMeasured(H,i)}function pt(N){R=N,et(R)}function kt(N){var G=R.stop;R=Object.assign({},R,{stop:N}),io(i,n,G,N)}var ut=function(N){var G=N&&N.closest?N.closest(".diagram-node"):null;return G&&i.contains(G)?G:null};function $t(N){var G=ut(N.target);if(!(!G||N.defaultPrevented)){if(O(),N.key==="Escape"){!p&&(Q||at||it)&&(N.preventDefault(),Q=at=it=null,I());return}if(Tt(B,R)){var P=oo(B,G.getAttribute("data-node"),N.key,R.layout==="drawn");if(P){N.preventDefault(),kt(P);var ot=i.querySelector('.diagram-node[data-node="'+CSS.escape(P)+'"]');ot&&ot.focus()}}}}function bt(N){var G=ut(N.target);if(G){O();var P=G.getAttribute("data-node");Q=G.matches(":focus-visible")?P:null,Tt(B,R)&&R.stop!==P&&kt(P),I()}}function wt(N){var G=ut(N.target);G&&(ut(N.relatedTarget)||(Q=null),R.keep===G.getAttribute("data-node")&&pt(Object.assign({},R,{keep:void 0})),I())}function vt(N){if(!(N.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var G=ut(N.target);G&&O();var P=G&&Tt(B,R)?G.getAttribute("data-node"):null;P!==at&&(at=P,I())}}function y(){at&&(at=null,I())}function S(){O(),pt(Object.assign({},R,{open:!R.open,autoOpen:void 0})),st()}i.addEventListener("keydown",$t),i.addEventListener("focusin",bt),i.addEventListener("focusout",wt),i.addEventListener("pointerover",vt),i.addEventListener("pointerleave",y),i.addEventListener("click",ft),tt&&tt.addEventListener("click",S),lt();var E=i.clientWidth,k=0,A=!0,W=new ResizeObserver(function(){Math.abs(i.clientWidth-E)<.5||(E=i.clientWidth,cancelAnimationFrame(k),k=requestAnimationFrame(lt))});W.observe(i),document.fonts&&document.fonts.ready.then(function(){A&<()});var J=matchMedia("(forced-colors: active)"),K=B.nodes.some(function(N){return N.mark});K&&J.addEventListener("change",lt),$&&(u=e.diagramMotion(i,{fig:i,P:n,base:m,model:function(){return B},geo:function(){return H&&H.geo},tokens:function(){return H&&H.tokens}},h));var Y=!p&&h.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(i,h,{model:B,settle:O,animated:$}):null,U=i.querySelector(":scope > .diagram-foot"),Z=!p&&h.export===!0&&U&&typeof e.diagramExport=="function"?e.diagramExport(U,i):[];i.__diagram={stop:function(){Y&&Y.destroy(),Z.forEach(function(N){N.remove()}),A=!1,W.disconnect(),cancelAnimationFrame(k),K&&J.removeEventListener("change",lt),u&&u.destroy(),i.removeEventListener("keydown",$t),i.removeEventListener("focusin",bt),i.removeEventListener("focusout",wt),i.removeEventListener("pointerover",vt),i.removeEventListener("pointerleave",y),i.removeEventListener("click",ft),_&&_.remove(),tt&&tt.removeEventListener("click",S)},layout:lt,key:g(h),send:u&&u.sendValue?u.sendValue:null}}function g(i){try{return JSON.stringify(i,function(h,b){return h==="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 h=i.querySelector(":scope > script[data-diagram]");if(h)try{d(i,JSON.parse(h.textContent),!0)}catch(b){console.error("Basalt diagram: this figure could not be drawn",b)}}})}e.diagramMarkup=s,e.diagramKit={draw:d,buildModel:Nt,figureKey:En,figureList:Bn,hintEntries:ie,toHtml:ae,escapeHtml:mt,settleEntrance:nn,measureFigure:ge},t.diagram=function(i,h){var b=i.__diagram,p=b&&b.send?g(h):null;if(p!==null&&p===b.key){b.send(h.packet?h.packet.send:void 0);return}d(i,h)},e.step(62,"wireDiagrams",f)})(window.Basalt)})(); +(()=>{var mo=["top","right","bottom","left"],yo=["main","plain","dashed"],Me=["one","zero-or-one","one-or-many","zero-or-many"],Jt={one:"Exactly one","zero-or-one":"Zero or one","one-or-many":"One or many","zero-or-many":"Zero or many"},$o=[2,3,4,5,6],Se=t=>t.type==="architecture"||t.type==="deployment",Ut=t=>t==="architecture"||t==="state"||t==="deployment",ce=t=>t==="architecture"||t==="flowchart"||t==="schema"||t==="state"||t==="deployment"||t==="schedule",Mt=t=>t==null||t===""?void 0:String(t),It=t=>Object.assign(Object.create(null),t),jt=(t,e)=>t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;function Vt(t,e={}){const n=e.checks!==!1,l=[],i=$=>{l.push($)},a=[],r=$=>{a.push($)},s=t.legend??{},c={};for(const $ of["main","plain","dashed","focal","group","activation","line"]){const b=Mt(s[$]);b&&(c[$]=b)}const g=t.stepLabel,f=typeof g=="function"?$=>String(g($)):typeof g=="string"?($=>g.replace("{n}",String($))):$=>`Step ${$}`,u=t.shapeLabels??{},m={terminal:Mt(u.terminal)??"Start or end",step:Mt(u.step)??"Step",decision:Mt(u.decision)??"Decision"},h=t.heading===void 0?3:$o.includes(t.heading)?t.heading:(i(`heading ${String(t.heading)} is not a level from 2 to 6: the title is an h3`),3),d=($,b)=>$==null?"plain":yo.includes($)?$:(i(`"${String($)}" is not a kind of line (main, plain or dashed): ${b} is drawn plain`),"plain"),p=$=>{if($!=null){if(mo.includes($))return $;i(`"${String($)}" is not a side (top, right, bottom or left): the derived side is used`)}},w=($,b)=>typeof $=="number"&&Number.isInteger($)&&$>=1?$:(t.layout==="auto"&&$==null||i(`${b} is ${JSON.stringify($)}, not a whole number from 1: it is placed at 1`),1),x=[],B=[];let v=[];const C=[],_=[],q=t.type,O=t.ext&&t.ext.type===q?t.ext:void 0,st=O?.as==="architecture",E={dev:!0,warn:i,error:r,rtl:!!e.rtl,legend:c};O?.prepare&&(t=O.prepare(t,E));let Z;if(!O&&!["architecture","flowchart","data-flow","sequence","schema","state","deployment"].includes(q)&&i(`"${String(q)}" is not a type of diagram (architecture, flowchart, data-flow, sequence, schema, state or deployment), or its module is not loaded`),O?.build)Z=O.build(t,E),x.push(...Z.nodes),B.push(...Z.edges);else if(q==="architecture"||q==="flowchart"||st){for(const $ of t.nodes??[]){const b=q==="flowchart"&&$.shape==="decision"?"decision":q==="flowchart"&&$.shape==="terminal"?"terminal":"box",I=String($.id??""),z=w($.row,`the row of ${I}`);x.push({id:I,i:x.length,name:String($.name??""),kind:b==="decision"?void 0:Mt($.kind),detail:b==="decision"?void 0:Mt($.detail),mono:!!$.detailMono,focal:!!$.focal,col:w($.col,`the column of ${I}`),row:z,row2:z,branch:!!$.branch,shape:b,group:q!=="flowchart"?Mt($.group):void 0,mark:q!=="flowchart"?de($.mark,i):void 0})}if(q!=="flowchart"){const $=(t.groups??[]).map(T=>({id:String(T.id??""),label:String(T.label??""),parent:Mt(T.parent)})),b=new Map($.map(T=>[T.id,T])),I=T=>{if(!T.parent)return 1;const H=b.get(T.parent);return H?H.parent===T.id||H.id===T.id?(r(`the groups "${T.label}" and "${H.label}" are each other's parent`),T.parent=void 0,1):H.parent?(r(`the group "${T.label}" is a third level: groups nest two deep`),T.parent=void 0,1):2:(r(`the group "${T.label}" names the parent "${T.parent}", which is not a group`),T.parent=void 0,1)},z=$.map(I);$.forEach((T,H)=>C.push({...T,depth:z[H],members:x.filter(ht=>ht.group===T.id).map(ht=>ht.id),all:[]}));for(const T of C)T.all=[...T.members,...C.filter(H=>H.parent===T.id).flatMap(H=>H.members)];C.sort((T,H)=>T.depth-H.depth)}}else if(q==="data-flow"){v=(t.lanes??[]).map(b=>({id:String(b.id??""),label:String(b.label??"")}));const $=new Map(v.map((b,I)=>[b.id,I+1]));for(const b of t.nodes??[]){const I=String(b.id??""),z=String(b.lane??""),T=$.get(z);T===void 0&&i(`a node (${I}) names the lane "${z}", which is not in lanes`);const H=x.length+1;x.push({id:I,i:x.length,name:String(b.name??""),kind:f(H),detail:Mt(b.detail),mono:!!b.detailMono,focal:!!b.focal,col:w(b.col,`the column of ${I}`),row:T??1,row2:T??1,branch:!1,shape:b.shape==="decision"?"decision":"box",lane:T??1,laneLabel:v[(T??1)-1]?.label??z,step:H,mark:de(b.mark)})}}else if(q==="sequence"){(t.participants??[]).forEach((z,T)=>{const H=String(z.name??"");x.push({id:String(z.id??""),i:T,name:H,kind:Mt(z.kind),mono:!1,focal:!!z.focal,col:T+1,row:1,row2:1,branch:!1,shape:"participant",short:Mt(z.short)??H,mark:de(z.mark)})});let $=0;const b=new Map(x.map(z=>[z.id,z.col])),I=(z,T)=>{let H=1/0,ht=-1/0;for(const Q of z??[]){if(!Q||typeof Q!="object")continue;if("band"in Q){T>0&&r(`the band "${String(Q.band)}" is inside a frame: a band is the whole figure's`),_.push({band:String(Q.band??"")});continue}if("frame"in Q){if(T>=2){r("a frame is a third level: frames nest two deep");continue}const y=Q.frame==="alt"||Q.frame==="loop"||Q.frame==="opt"?Q.frame:"opt",S=y==="alt"?Q.branches??[]:[{label:Q.label,steps:Q.steps}];y==="alt"&&S.length<2&&r("an alt frame has one branch: it needs two or more");const A=String(S[0]?.label??"");A.length>40&&r(`the frame label "${A}" is over 40 characters`);const k=_.length;_.push({open:y,label:A,depth:T+1,a:0,b:0}),S.forEach((L,W)=>{if(W){const K=String(L.label??"");K.length>40&&r(`the frame label "${K}" is over 40 characters`),_.push({otherwise:K,depth:T+1})}L.steps?.length||r(`a frame or branch ("${String(L.label??"")}") is empty`);const[V,G]=I(L.steps??[],T+1);H=Math.min(H,V),ht=Math.max(ht,G);const U=_[k];U.a=Math.min(U.a||1/0,V),U.b=Math.max(U.b,G)}),_.push({close:T+1});continue}$++;const xt=String(Q.label??"");xt.includes(` +`)&&r(`message ${$}'s label has a break: a message's second line is its note`);const rt=String(Q.from??""),wt=String(Q.to??"");_.push({n:$,from:rt,to:wt,label:Ct(xt),note:Mt(Q.note),kind:d(Q.kind,`message ${$}`),activate:Q.activate===!0||void 0,deactivate:Q.deactivate===!0||void 0});const vt=b.get(rt)??1,pt=b.get(wt)??1,yt=vt===pt?vt===x.length?vt-1:vt+1:vt;H=Math.min(H,vt,pt,yt),ht=Math.max(ht,vt,pt,yt)}return[H,ht]};I(t.steps??[],0);for(const z of _)"open"in z&&!Number.isFinite(z.a)&&(z.a=1,z.b=Math.max(1,x.length))}else if(q==="schema")for(const $ of t.tables??[]){const b=String($.name??""),[I,z]=Array.isArray($.row)?$.row:[$.row,$.row],T=w(I,`the row of ${b}`),H=Math.max(T,w(z,`the last row of ${b}`)),ht=$.more===void 0||$.more===null?void 0:Number.isInteger($.more)&&$.more>0?$.more:(i(`${b}'s "more" is ${JSON.stringify($.more)}, not a whole number from 1: it is left out`),void 0);x.push({id:b,i:x.length,name:b,mono:!0,focal:!!$.focal,col:w($.col,`the column of ${b}`),row:T,row2:H,branch:!1,shape:"table",more:ht,columns:($.columns??[]).map(Q=>({name:String(Q.name??""),type:Mt(Q.type),key:Q.key==="PK"||Q.key==="FK"?Q.key:(Q.key!==void 0&&Q.key!==null&&i(`${b}.${String(Q.name)}'s key is "${String(Q.key)}", not PK or FK: it is left out`),void 0)}))})}let R=!1;if(t.layout==="auto"&&ce(q)){const $=q==="schema"?t.tables:q==="schedule"?t.tasks:t.nodes;n&&($??[]).some(I=>I&&(I.col!==void 0||I.row!==void 0))&&i('a card under layout="auto" has a col or row, which is not read: there are no hints');const b=e.placement?.cells;b||(R=!0);for(const I of x){const z=b?.[I.id];I.col=z?.col??1,I.row=I.row2=z?.row??1}if(b){const I=new Map;for(const z of x){const T=jt(b,z.id);if(!T){R=!0,i(`the placement has no cell for ${z.id}, so it is not used`);continue}const H=`${T.col},${T.row}`;I.has(H)&&(R=!0,i(`the placement puts ${I.get(H)} and ${z.id} in one cell, so it is not used`)),I.set(H,z.id)}}if(b&&!R)for(const I of C){const z=I.all.map(rt=>x.find(wt=>wt.id===rt)).filter(Boolean);if(!z.length)continue;const T=Math.min(...z.map(rt=>rt.col)),H=Math.max(...z.map(rt=>rt.col)),ht=Math.min(...z.map(rt=>rt.row)),Q=Math.max(...z.map(rt=>rt.row)),xt=x.filter(rt=>!I.all.includes(rt.id)&&rt.col>=T&&rt.col<=H&&rt.row>=ht&&rt.row<=Q);xt.length&&(R=!0,i(`the placement puts ${xt.map(rt=>rt.id).join(", ")} inside the box of the group "${I.label}", so it is not used`))}}else t.layout==="auto"&&r(`layout="auto" is for an architecture, a flowchart, a schema, a state, a deployment or a schedule, not a ${q}`);((q==="schema"?t.tables:q==="sequence"?t.participants:t.nodes)??[]).forEach(($,b)=>{if(!$||$.href===void 0||$.href===null)return;const I=String($.href);if(q==="sequence"){r(`${x[b]?.id}: a participant cannot be a link (href)`);return}if(!I.trim()){r(`${x[b]?.id}'s href is empty`);return}const z=x[b];z&&(z.href=I,z.blank=$.target==="_blank")});const Y=new Map;for(const $ of x)$.id?Y.has($.id)&&i(`the id "${$.id}" is used twice`):i("a node has no id"),Y.set($.id,$);if(q==="schema"){const $=(I,z)=>{if(I==null)return;const T=I,H=Me.includes(T.from)?T.from:void 0;if(!H){r(`${z}'s cardinality "from" is ${JSON.stringify(T.from)}, not one, zero-or-one, one-or-many or zero-or-many: it is left out`);return}return T.to===void 0||T.to===null?{from:H,to:"one"}:T.to==="one"||T.to==="zero-or-one"?{from:H,to:T.to}:(r(`${z}'s cardinality "to" is ${JSON.stringify(T.to)}: a foreign key references one row at most (one or zero-or-one), so it is drawn as one`),{from:H,to:"one"})};(t.tables??[]).forEach(I=>(I.columns??[]).forEach((z,T)=>{const H=Mt(z.references);if(!H&&z.cardinality!==void 0&&z.cardinality!==null&&r(`${String(I.name)}.${String(z.name)} states a cardinality but references nothing`),!H)return;const[ht,Q]=H.split("."),xt=Y.get(ht??""),rt=xt?.columns?.findIndex(pt=>pt.name===Q)??-1;if(!xt||rt<0){i(`${String(I.name)}.${String(z.name)} references ${H}, which is not a shown column`);return}const wt=Y.get(String(I.name??""));wt.columns[T].ref={table:ht,column:Q,row:rt};const vt=$(z.cardinality,`${String(I.name)}.${String(z.name)}`);vt&&(wt.columns[T].card=vt),B.push({i:B.length,from:wt.id,to:ht,kind:"plain",fromRow:T,toRow:rt,fk:!0,card:vt})}));const b=B.filter(I=>I.card).length;b&&b!I.card).map(I=>`${I.from}.${Y.get(I.from).columns[I.fromRow].name}`).join(", ")} ${B.length-b===1?"has":"have"} none)`)}else if(q!=="sequence"&&(!O||st)){for(const $ of t.edges??[]){const b=String($.from??""),I=String($.to??"");if(!Y.has(b)||!Y.has(I)){i(`a line names ${Y.has(b)?I:b}, which is not a node`);continue}const z=Mt($.label),T=z?.split(` +`)??[];T.length>2&&r(`the label "${Ct(z)}" has more than one break: a label is two lines at most`),T.some(H=>H.length>Le)&&r(`a line of the label "${Ct(z)}" is over ${Le} characters: longer words belong in the node or the summary`),B.push({i:B.length,from:b,to:I,kind:d($.kind,`the line from ${b} to ${I}`),label:z,fromSide:p($.fromSide),toSide:p($.toSide),flow:q!=="flowchart"&&$.flow===!0?!0:void 0})}if(q==="data-flow"){for(const $ of x)if($.shape==="decision"){const b=B.filter(I=>I.from===$.id);b.length<2&&r(`the decision ${$.id} has ${b.length} line${b.length===1?"":"s"} leaving it: a decision has two or more`),b.some(I=>!I.label)&&r(`a line leaving the decision ${$.id} has no label: every line out of a decision says which way it is`)}}q==="architecture"&&t.dependents&&bo(t,x,B,c,t.layout==="auto",!0,r,i)}else for(const $ of _)"n"in $&&(!Y.has($.from)||!Y.has($.to))&&i(`message ${$.n} names ${Y.has($.from)?$.to:$.from}, which is not a participant`);const D=!O||O.routed;if(n&&q!=="sequence"&&!R&&D){const $=new Map;for(const b of x)for(let I=b.row;I<=b.row2;I++){const z=`${b.col}:${I}`;$.has(z)&&i(`${b.id} and ${$.get(z)} share the cell at column ${b.col}, row ${I}`),$.set(z,b.id)}}if(n&&!R){for(const b of C){const I=b.all.map(H=>Y.get(H));if(!I.length)continue;const z={c1:Math.min(...I.map(H=>H.col)),c2:Math.max(...I.map(H=>H.col)),r1:Math.min(...I.map(H=>H.row)),r2:Math.max(...I.map(H=>H.row2))};for(const H of x)!b.all.includes(H.id)&&H.col>=z.c1&&H.col<=z.c2&&H.row>=z.r1&&H.row<=z.r2&&i(`${H.id} is inside the box of the group "${b.label}" but not a member`);const T=I.map(H=>H.i);Math.max(...T)-Math.min(...T)+1!==T.length&&i(`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 x)b.group&&!C.some(I=>I.id===b.group)&&i(`${b.id} names the group "${b.group}", which is not in groups`);x.filter(b=>b.focal).length>1&&i("more than one node is focal: a diagram has one at most");const $=O?new Set:new Set(q==="sequence"?_.flatMap(b=>"n"in b?[b.kind]:[]):B.map(b=>b.kind));$.has("main")&&!c.main&&i("main lines are drawn but the legend has no words for them (legend.main)"),$.has("dashed")&&!c.dashed&&i("dashed lines are drawn but the legend has no words for them (legend.dashed)"),x.some(b=>b.focal)&&!c.focal&&i("a focal node is drawn but the legend has no words for what it marks (legend.focal)")}const P=q==="architecture"||q==="data-flow",mt=$=>Array.isArray($)&&$.length>1?$.map(String):void 0,$t=P&&t.packet&&typeof t.packet=="object"?t.packet:void 0,ut=$t&&mt($t.path),ft={animated:t.motion==="animated",pulse:P?mt(t.pulse):void 0,packet:ut?{path:ut,repeat:$t.repeat===!0,send:$t.send}:void 0,run:q==="sequence"&&t.run===!0,firstVisit:t.entrance==="first-visit"||void 0};if(n)for(const $ of x){const b=$.mark?.says;if(!b?.length)continue;const I=[$.name,$.kind,$.detail,$.laneLabel].filter(Boolean).join(" ").toLowerCase();b.some(z=>I.includes(z.toLowerCase()))||i(`${$.id}'s mark stands for ${b.join(" or ")}, and none of its words say so`)}const ct=[];if(q==="sequence"){const $=new Map,b=new Map;for(const I of _)"n"in I&&(b.set(I.from,I.n),b.set(I.to,I.n));for(const I of _)if("n"in I){if(I.activate){const z=$.get(I.to)??[];if(z.length>=3)r(`message ${I.n} opens a fourth bar on ${I.to}: three deep at most`);else{const T={who:I.to,from:I.n,to:I.n,depth:z.length+1};z.push(T),ct.push(T),$.set(I.to,z)}}if(I.deactivate){const T=$.get(I.from)?.pop();T?T.to=I.n:r(`message ${I.n} closes a bar on ${I.from}, which has none open`)}}for(const[I,z]of $)for(const T of z)T.to=Math.max(T.from,b.get(I)??T.from)}const it=t.frameLabels??{},dt={opt:Mt(it.opt)??"Only if",loop:Mt(it.loop)??"Repeats",alt:Mt(it.alt)??"One of these",else:Mt(it.else)??"Otherwise"},j=t.layout==="auto"&&!R?e.placement:void 0,tt=Z&&!O.routed;let et=tt?Math.max(1,Z.cols):Math.max(1,j?.cols??1,...x.map($=>$.col));if(e.rtl&&D){for(const b of x)b.col=et-b.col+1;const $=b=>b==="left"?"right":b==="right"?"left":b;for(const b of B)b.fromSide=$(b.fromSide),b.toSide=$(b.toSide);for(const b of _)if("open"in b){const[I,z]=[et-b.b+1,et-b.a+1];b.a=I,b.b=z}et=Math.max(1,j?.cols??1,...x.map(b=>b.col))}const nt=tt?Math.max(1,Z.rows):q==="data-flow"?Math.max(1,v.length):Math.max(1,j?.rows??1,...x.map($=>$.row2)),X={ext:O,plan:Z?.plan,dir:j?.direction??(t.direction==="down"?"down":void 0),type:q,title:String(t.title??""),heading:h,legend:c,nodes:x,byId:Y,edges:B,groups:C,lanes:v,steps:_,bars:ct,frameWords:dt,cols:et,rows:nt,shapeLabels:m,stepWord:f,warnings:l,errors:a,motion:ft,memo:new Map,rtl:e.rtl||void 0,unplaced:R||void 0,text:q==="sequence"&&t.variant==="text"||void 0,marks:B.some($=>$.card)||void 0};if(O?.adopt?.(X,t,E),t.layout==="auto"&&!R&&q!=="schema"&&wo(X),n)for(const[$,b]of Object.entries(Je(X)))b>=48&&i(`${$} grows to ${b}px to hold the lines on one side: use another side`);return n&&x.length>100&&i(`the figure has ${x.length} cards: more than 100, which automatic layout places on the main thread`),n&&D&&x.length>1&&!R&&!oe(X)&&i("some part cannot be reached from another by the arrow keys where the figure is drawn, so its arrows keep the author's order"),X}function bo(t,e,o,n,l,i,a,r){const s=t.dependents,c=String(s.one??"dependent"),g=String(s.other??"dependents");for(const _ of e){const q=new Set(o.filter(O=>O.to===_.id&&O.from!==_.id).map(O=>O.from)).size;i&&_.detail&&/\b\d+\s+(dependents?|depend)/i.test(_.detail)&&r(`${_.id}'s detail writes a count: the engine writes each card's count of dependents, so write none by hand`),_.detail=`${q} ${q===1?c:g}${_.detail?` · ${_.detail}`:""}`}const f=new Map,u=new Map,m=new Map,h=[],d=new Set;let p=0,w=0;const x=_=>o.filter(q=>q.from===_).map(q=>q.to);for(const _ of e.map(q=>q.id)){if(f.has(_))continue;const q=[{id:_,k:0}];for(f.set(_,p),u.set(_,p++),h.push(_),d.add(_);q.length;){const O=q[q.length-1],st=x(O.id);if(O.k_.from===_.to||m.get(_.from)===m.get(_.to)&&(B.get(m.get(_.from))??0)>1,C=[];for(const _ of o){if(v(_)){_.kind="dashed",C.push(`${_.from} to ${_.to}`);continue}if(_.kind==="dashed"&&(i&&a(`the line from ${_.from} to ${_.to} is dashed and in no cycle: in a dependency figure dashed means a cycle, so it is drawn plain`),_.kind="plain"),i&&!l){const q=e.find(st=>st.id===_.from);e.find(st=>st.id===_.to).col<=q.col&&r(`the line from ${_.from} to ${_.to} is in no cycle and does not end in a later column`)}}i&&C.length&&!n.dashed&&a(`a cycle is drawn (${C.join(", ")}) but the key's dashed line has no words (legend.dashed)`)}function wo(t){const e=new Set(t.nodes.map(r=>`${r.col},${r.row}`)),o=(r,s)=>{const c=[];for(let g=Math.min(r,s)+1;g{const s=t.byId.get(r.from),c=t.byId.get(r.to),g=c.col>s.col?"right":"left",f=c.row>s.row?"bottom":"top",u=c.col>s.col?"left":"right",m=c.row>s.row?"top":"bottom",h=(w,x,B,v)=>o(w,x).map(C=>v?[C,B]:[B,C]);let d;const p=w=>(w==="right"?s.col1:w==="bottom"?s.row1)?[{sides:[w,w],cells:[]}]:[];return s.row===c.row?d=[{sides:[g,u],cells:h(s.col,c.col,s.row,!0)},...p("bottom"),...p("top")]:s.col===c.col?d=[{sides:[f,m],cells:h(s.row,c.row,s.col,!1)},...p("right"),...p("left")]:d=[{sides:[g,m],cells:[...h(s.col,c.col,s.row,!0),[c.col,s.row],...h(s.row,c.row,c.col,!1)]},{sides:[f,u],cells:[...h(s.row,c.row,s.col,!1),[s.col,c.row],...h(s.col,c.col,c.row,!0)]},{sides:[g,u],cells:h(s.col,c.col,s.row,!0)},{sides:[f,m],cells:h(s.row,c.row,s.col,!1)}],d.filter(w=>w.cells.every(([x,B])=>!e.has(`${x},${B}`)))},l=new Map,i=new Set;for(const r of t.edges)if(r.fromSide||r.toSide){const[s,c]=ye(t.byId.get(r.from),t.byId.get(r.to)),g=r.fromSide??s,f=r.toSide??c;i.add(`${r.from}.${g}`);for(const[u,m]of[[r.from,g],[r.to,f]])l.set(`${u}.${m}`,(l.get(`${u}.${m}`)??0)+1)}const a=t.edges.map((r,s)=>s).sort((r,s)=>n(t.edges[r]).length-n(t.edges[s]).length||+(t.edges[s].kind==="main")-+(t.edges[r].kind==="main")||r-s);for(const r of a){const s=t.edges[r];if(s.fromSide||s.toSide)continue;const c=(f,u,m)=>{const h=`${f}.${u}`;return(l.get(h)??0)>=3?!1:t.byId.get(f).shape!=="decision"?!0:m?!l.has(h):!i.has(h)},g=n(s).find(f=>c(s.from,f.sides[0],!0)&&c(s.to,f.sides[1],!1));if(g){i.add(`${s.from}.${g.sides[0]}`);for(const[f,u]of[[s.from,g.sides[0]],[s.to,g.sides[1]]])l.set(`${f}.${u}`,(l.get(`${f}.${u}`)??0)+1);s.fromSide=g.sides[0],s.toSide=g.sides[1]}}}function de(t,e){if(typeof t=="string")return t?{id:t}:void 0;if(!t||typeof t!="object")return;const o=t,n=Ee(Mt(o.onLight),e);if(n)return{onLight:n,onDark:Ee(Mt(o.onDark),e)??n,says:Array.isArray(o.says)?o.says.map(String):void 0}}function Ee(t,e){if(t){if(/^data:image\//i.test(t.trim()))return t;try{if(/^https?:$/.test(new URL(t,"https://basalt.invalid/").protocol)&&!/^http:/i.test(t.trim()))return t}catch{}e?.(`a card's mark ${JSON.stringify(t.slice(0,60))} is not a relative path, https or a data: image, so it is not drawn`)}}var Ae=t=>`url("${t.replace(/[\\"\n\r\f;]/g,e=>e===` +`?"\\a ":e==="\r"?"\\d ":e==="\f"?"\\c ":e===";"?"\\3b ":`\\${e}`)}")`;function zt(t,e,o){return t.memo.has(e)||t.memo.set(e,o()),t.memo.get(e)}var Le=28,Pt=t=>t.includes(` +`)?2:1,Ct=t=>t.replace(/\n/g," "),Kt=t=>{const e=t.trim();return e?/[.!?]$/.test(e)?e:`${e}.`:""};function _e(t,e){return t.legend[e]}function vo(t,e){return e.shape==="decision"?"decision":e.shape==="terminal"?t.edges.some(o=>o.from===e.id)?"start":"end":e.kind??"step"}function xo(t,e){return zt(t,`sentence:${e.i}`,()=>ko(t,e))}function ko(t,e){if(t.ext?.sentence)return t.ext.sentence(t,e);const o=[];if(t.type==="schema"){o.push(`${e.name}, table.`);const n=(e.columns??[]).filter(i=>i.ref).map(i=>`${i.ref.table} (${i.name}${i.card?`: ${qe(e.id,i.ref.table,i.card)}`:""})`),l=t.edges.filter(i=>i.to===e.id).map(i=>`${i.from} (${t.byId.get(i.from).columns[i.fromRow].name}${i.card?`: ${qe(i.from,i.to,i.card)}`:""})`);n.length&&o.push(`References ${n.join(", ")}.`),l.length&&o.push(`Referenced by ${l.join(", ")}.`)}else if(t.type==="sequence"){const n=t.steps.filter(a=>"n"in a&&a.from===e.id).length,l=t.steps.filter(a=>"n"in a&&a.to===e.id).length;o.push(Kt(e.kind?`${e.name}, ${e.kind}`:e.name)),o.push(`Sends ${n} ${n===1?"message":"messages"} and receives ${l}.`);const i=Ie(t,e);i&&o.push(i.trim())}else{const n=t.type==="data-flow"?`${t.stepWord(e.step)} of ${t.nodes.length}, ${e.laneLabel}${e.shape==="decision"?`, ${t.shapeLabels.decision.toLowerCase()}`:""}`:t.type==="flowchart"?vo(t,e):e.kind;if(o.push(Kt(n?`${e.name}, ${n}`:e.name)),e.detail&&o.push(Kt(e.detail)),t.ext?.sentenceMore&&o.push(...t.ext.sentenceMore(t,e)),e.group){const a=t.groups.find(s=>s.id===e.group),r=a?.parent?t.groups.find(s=>s.id===a.parent):void 0;a&&o.push(r?`In ${a.label}, in ${r.label}.`:`In ${a.label}.`)}const l=t.edges.filter(a=>a.to===e.id).map(a=>`${t.byId.get(a.from).name}${a.label?` (${Ct(a.label)})`:""}`),i=t.edges.filter(a=>a.from===e.id).map(a=>`${t.byId.get(a.to).name}${a.label?` (${Ct(a.label)})`:""}`);l.length&&o.push(`From: ${l.join(", ")}.`),i.length&&o.push(`To: ${i.join(", ")}.`)}return e.focal&&t.legend.focal&&o.push(Kt(t.legend.focal)),o.join(" ")}var Mo=(t,e,o,n)=>[`${Jt[o.from].toLowerCase()} `,n(t),` to ${Jt[o.to].toLowerCase()} `,n(e)],qe=(t,e,o)=>`${Jt[o.from].toLowerCase()} ${t} to ${Jt[o.to].toLowerCase()} ${e}`;function Ie(t,e){const o=t.bars.filter(l=>l.who===e.id&&l.depth===1);return o.length?` ${t.legend.activation??"Working"} during ${o.map(l=>l.from===l.to?`message ${l.from}`:`messages ${l.from} to ${l.to}`).join(" and ")}.`:""}function So(t,e,o,n){const l=o.pointerType;if(l!=="touch"&&l!=="pen")return;const i=t.querySelector(`.${e}-drawing`),a=o.target;if(!i||!a||!i.contains(a)||!t.querySelector(`.${e}-edge`))return;const r=a.closest(`.${e}-node`);if(!r?.hasAttribute("href"))return r?r.dataset.node===n?null:r.dataset.node??null:n===null?void 0:null}function Oe(t){return t.ext?t.ext.stop:t.type==="architecture"?"a part":t.type==="sequence"?"a participant":t.type==="schema"?"a table":"a step"}function M(t,e,...o){const n=[];for(const l of o.flat(1/0))l!=null&&l!==!1&&!Array.isArray(l)&&n.push(l);return{t,a:e??{},c:n}}var Eo={"&":"&","<":"<",">":">",'"':""","'":"'"},St=t=>t.replace(/[&<>"']/g,e=>Eo[e]),Ao=" br img input meta link hr path polygon polyline circle rect line ";function fe(t,e={}){if(typeof t=="string")return St(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 o="";for(const[n,l]of Object.entries(t.a))if(!(l==null||l===!1)){if(!/^[a-z][a-z0-9:-]*$/i.test(n))throw new Error(`diagram: "${n}" is not an attribute name`);o+=l===!0?` ${n}`:` ${n}="${St(String(l))}"`}return Ao.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}${o}/>`:`<${t.t}${o}>`:`<${t.t}${o}>${t.c.map(n=>fe(n,e)).join("")}`}var Lo=t=>({title:`${t}-title`,summary:`${t}-summary`,keys:`${t}-keys`,list:`${t}-list`,toggle:`${t}-toggle`});function Wt(t,e){return t.ext?.hasStops?t.ext.hasStops(t,e):!e.layout||e.bare?!1:e.layout==="drawn"?!0:t.type!=="sequence"&&t.type!=="schema"}function _o(t,e){return t.ext?!0:t.type==="sequence"||t.type==="schema"?e.layout==="drawn":!0}function Xt(t,e){const o=e.all.map(n=>t.byId.get(n));return o.length?{c1:Math.min(...o.map(n=>n.col)),c2:Math.max(...o.map(n=>n.col)),r1:Math.min(...o.map(n=>n.row)),r2:Math.max(...o.map(n=>n.row2))}:null}function Ce(t){return zt(t,"group-edges",()=>{const e=[0,0,0,0];for(const o of t.groups){const n=Xt(t,o);if(!n)continue;[n.r1===1,n.c2===t.cols,n.r2===t.rows,n.c1===1].forEach((i,a)=>{i&&(e[a]=Math.max(e[a],Be(t,o,a)))})}return e})}function Be(t,e,o){const n=Xt(t,e);return t.groups.filter(a=>a.parent===e.id).some(a=>{const r=Xt(t,a);return r&&[r.r1===n.r1,r.c2===n.c2,r.r2===n.r2,r.c1===n.c1][o]})?2:1}function je(t){const e=Ce(t);return e[1]+e[3]}function te(t){return t.type==="sequence"?t.nodes.length:t.cols}function Re(t){return zt(t,"plan",()=>qo(t))}function qo(t){const e=t.nodes,o=p=>t.type==="data-flow"||!e[p].branch,n=t.edges.map(p=>{const w=t.byId.get(p.from).i,x=t.byId.get(p.to).i,v=e.slice(Math.min(w,x)+1,Math.max(w,x)).every(C=>!o(C.i));return x===w+1&&!(o(w)&&!o(x))?"down":x===w-1?"up":x>w&&o(w)&&!o(x)&&v?"trunk":x>w&&o(w)&&o(x)&&v?"rail":x>w?"end-down":"end-up"}),l=t.edges.map((p,w)=>({e:p,k:w})).filter(({k:p})=>n[p]==="end-down"||n[p]==="end-up"),i=p=>{const w=t.byId.get(p.from).i,x=t.byId.get(p.to).i;return[Math.min(w,x),Math.max(w,x)]},a=(p,w)=>{const[x,B]=i(p),[v,C]=i(w);return x{const w=t.byId.get(p.from).i,[x,B]=i(p);return!o(w)&&e.slice(x+1,B).every(v=>!o(v.i))&&l.every(v=>v.e===p||!a(v.e,p))}),s=l.length>0&&(t.type==="data-flow"||!r),c=p=>{const[w,x]=i(p);return x-w},g=t.edges.map(()=>0);let f=!1;const u=[];for(const p of[...l].sort((w,x)=>c(w.e)-c(x.e)||w.k-x.k)){let w=0;for(const x of u)a(x.e,p.e)&&(w=Math.max(w,g[x.k]+1));g[p.k]=w,w>3&&(f=!0),u.push(p)}const m=Math.max(0,...l.map(({k:p})=>g[p]+1)),h=t.edges.map(()=>.5);for(const p of e){const w=l.filter(({e:v})=>v.from===p.id);if(w.length<2)continue;const x=w.filter(({k:v})=>n[v]==="end-down").sort((v,C)=>c(C.e)-c(v.e)||v.k-C.k);[...w.filter(({k:v})=>n[v]==="end-up").sort((v,C)=>c(v.e)-c(C.e)||C.k-v.k),...x].forEach(({k:v},C,_)=>{h[v]=_.length===2?C===0?1/3:2/3:(C+1)/(_.length+1)})}const d=It();for(let p=1;p{const Z=n[E],R=t.byId.get(st.from).i,N=t.byId.get(st.to).i,Y=N===p&&(Z==="down"||Z==="trunk"||Z==="rail"||Z==="end-down"),D=R===p&&N===p-1&&Z==="up",P=N===p-1&&Z==="end-up";Y&&(Z==="trunk"||Z==="end-down")&&(C=!0),P&&(_=!0),(Y||D||P)&&st.label&&(B++,v=Math.max(v,Z==="trunk"?40:48))}),(B>1||C&&_)&&(v=64);const q=l.filter(({e:st,k:E})=>n[E]==="end-down"&&t.byId.get(st.to).i===p).length,O=l.filter(({e:st,k:E})=>n[E]==="end-up"&&t.byId.get(st.to).i===p-1).length;v+=20*Math.max(0,q-1)+20*Math.max(0,O-1),d[w.id]=v}return{routes:n,gutter:s,lanes:g,exits:h,gaps:d,third:f,laneCount:m}}var Ht=(t,e)=>({width:t,height:e,viewBox:`0 0 ${t} ${e}`,"aria-hidden":"true",focusable:"false"});function Te(t,e){const o=e==="fk"?"plain":e,n=o==="main"?8:8.5,l=24,i=o==="dashed"?l-1:l-7;return M("svg",{class:`${t}-swatch`,"data-kind":o,...Ht(24,16)},e==="fk"?M("circle",{class:`${t}-dot`,cx:3,cy:n,r:3}):null,M("path",{class:`${t}-line`,"data-kind":o,d:`M${e==="fk"?3:0} ${n}H${i}`}),o==="dashed"?M("path",{class:`${t}-tip`,"data-kind":o,"data-open":"",d:`M${l-8} ${n-4}L${l} ${n}L${l-8} ${n+4}`}):M("path",{class:`${t}-tip`,"data-kind":o,d:`M${l} ${n}L${l-8} ${n-4}L${l-8} ${n+4}Z`}))}function Io(t,e){const{crow:o,ring:n}=ze(e,24,8.5,-1);return M("svg",{class:`${t}-swatch`,"data-card":e,...Ht(24,16)},M("path",{class:`${t}-line`,"data-kind":"plain",d:"M0 8.5H24"}),M("path",{class:`${t}-crow`,d:o}),n?M("circle",{class:`${t}-ring`,cx:n.x,cy:n.y,r:n.r}):null)}function ze(t,e,o,n,l=8,i=6){const a=m=>String(Math.round(m*100)/100),r=m=>e+n*m,s=l/2,c=m=>`M${a(r(m-.5))} ${a(o-s)}V${a(o+s)}`,g=t==="one-or-many"||t==="zero-or-many",f=t==="zero-or-one"||t==="zero-or-many";let u=g?`M${a(e)} ${a(o-s)}L${a(r(7.5))} ${a(o)}L${a(e)} ${a(o+s)}`:c(4);return f||(u+=c(g?11:8)),{crow:u,ring:f?{x:Math.round(r(10.5)*100)/100,y:o,r:i/2}:void 0}}function Dt(t,e){return e==="decision"?M("svg",{class:`${t}-swatch`,"data-shape":e,...Ht(16,16)},M("path",{class:`${t}-swatch-shape`,d:"M8 2.5L14.5 8L8 13.5L1.5 8Z"})):e==="terminal"?M("svg",{class:`${t}-swatch`,"data-shape":e,...Ht(16,16)},M("rect",{class:`${t}-swatch-shape`,x:.5,y:3.5,width:15,height:9,rx:4.5})):M("svg",{class:`${t}-swatch`,"data-shape":e,...Ht(16,16)},M("rect",{class:`${t}-swatch-shape`,x:.5,y:2.5,width:15,height:11,rx:2}))}function We(t,e){return zt(e,`key:${t}`,()=>Co(t,e))}var Oo=We;function Co(t,e){if(e.ext?.key)return e.ext.key(t,e);const o=[],n=(a,r,s={})=>o.push(M("li",{class:`${t}-entry`,...s},a,M("span",null,gt(r))));if(e.type==="schema"){const a=new Set(e.nodes.flatMap(r=>(r.columns??[]).map(s=>s.key)));for(const[r,s]of[["PK","Primary key"],["FK","Foreign key"]])a.has(r)&&o.push(M("li",{class:`${t}-entry`},M("span",{class:`${t}-key-letters`,"aria-hidden":"true"},r),M("span",null,s)))}if(e.type==="data-flow"&&e.nodes.some(a=>a.shape==="decision")&&(n(Dt(t,"box"),e.shapeLabels.step),n(Dt(t,"decision"),e.shapeLabels.decision)),e.type==="flowchart"){const a=new Set(e.nodes.map(r=>r.shape));a.has("terminal")&&n(Dt(t,"terminal"),e.shapeLabels.terminal),a.has("box")&&n(Dt(t,"box"),e.shapeLabels.step),a.has("decision")&&n(Dt(t,"decision"),e.shapeLabels.decision)}const l=new Set(e.type==="sequence"?e.steps.flatMap(a=>"n"in a?[a.kind]:[]):e.edges.filter(a=>!a.fk).map(a=>a.kind)),i=(a,r)=>M("span",{class:`${t}-key-glyph`,"data-ink":r,"aria-hidden":"true"},a);for(const a of["main","plain","dashed"]){const r=e.legend[a];l.has(a)&&r&&n(e.text?i(a==="main"?"━━▶":a==="dashed"?"┄┄▷":"──▶",a==="main"?"main":"plain"):Te(t,a),r,{"data-line":e.text?void 0:""})}if(e.type==="schema"&&e.edges.length){e.edges.some(r=>!r.card)&&n(Te(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(r=>r.card?[r.card.from,r.card.to]:[]));for(const r of Me)a.has(r)&&n(Io(t,r),Jt[r],{"data-line":"","data-when":"drawn","data-card":r});o.push(M("li",{class:`${t}-entry`,"data-when":"stacked"},M("span",{class:`${t}-fk-mark`,"aria-hidden":"true"},e.rtl?"←":"→"),M("span",null,"The table a foreign key references")))}if(e.type==="sequence"){e.bars.length&&n(e.text?i("┃","working"):M("svg",{class:`${t}-swatch`,"data-shape":"bar",...Ht(16,16)},M("path",{class:`${t}-life`,d:"M8 0V16"}),M("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(r=>"open"in r?[r.open]:[]));for(const r of["opt","loop","alt"])a.has(r)&&o.push(M("li",{class:`${t}-entry`},M("span",{class:`${t}-key-letters`,"data-op":"","aria-hidden":"true"},r),M("span",null,e.frameWords[r])))}return e.ext?.keyMore&&o.push(...e.ext.keyMore(t,e)),e.nodes.some(a=>a.focal)&&e.legend.focal&&n(e.text?i("╔═╗","focal"):Dt(t,"focal"),e.legend.focal,{"data-focal":""}),e.groups.length&&e.legend.group&&n(Dt(t,"group"),e.legend.group),o.length?M("div",{class:`${t}-key`},M("ul",{class:`${t}-legend`,"aria-label":"Key"},o)):null}function Bo(t,e){const o=e==="main"?6:6.5;return M("svg",{class:`${t}-arrow`,"data-kind":e,...Ht(20,12)},M("path",{class:`${t}-line`,"data-kind":e,d:`M0 ${o}H${e==="dashed"?19:13}`}),e==="dashed"?M("path",{class:`${t}-tip`,"data-kind":e,"data-open":"",d:`M12 ${o-4}L20 ${o}L12 ${o+4}`}):M("path",{class:`${t}-tip`,"data-kind":e,d:`M20 ${o}L12 ${o-4}L12 ${o+4}Z`}))}var gt=t=>M("bdi",null,t);function ue(t,e){if(!e.href)return gt(e.name);const o=e.name.trimEnd().lastIndexOf(" ");return[o<0?"":e.name.slice(0,o+1),M("span",{class:`${t}-name-end`},o<0?e.name:e.name.slice(o+1))]}function jo(t,e,o){if(o.shape==="decision")return[M("span",{class:`${t}-words`},e.type==="data-flow"&&o.kind?M("span",{class:`${t}-kind`},gt(o.kind)):null,M("span",{class:`${t}-name`},ue(t,o)))];const n=[];return e.type==="data-flow"?n.push(M("span",{class:`${t}-kind`},gt(o.kind),M("span",{class:`${t}-lane-word`}," · ",gt(o.laneLabel??"")))):o.kind&&n.push(M("span",{class:`${t}-kind`},gt(o.kind))),n.push(M("span",{class:`${t}-name`},ue(t,o))),o.detail&&n.push(M("span",{class:`${t}-detail`,"data-mono":o.mono?"":void 0},o.mono?M("span",{class:`${t}-runs`},re(o.detail).flatMap((l,i)=>[i?" ":"",M("span",{class:`${t}-run`},l)])):gt(o.detail))),n}function Ro(t,e,o){return[M("span",{class:`${t}-th`},M("span",{class:`${t}-tname`},ue(t,e))),M("span",{class:`${t}-rows`},(e.columns??[]).map((n,l)=>M("span",{class:`${t}-row`,"data-row":l,"data-key":n.key},M("span",{class:`${t}-keyseat`},n.key??""),M("span",{class:`${t}-cname`},gt(n.name)),n.ref?M("span",{class:`${t}-ctype`,"data-ref":""},`${o.rtl?"←":"→"} `,gt(n.ref.table)):n.type?M("span",{class:`${t}-ctype`},gt(n.type)):null))),e.more?M("span",{class:`${t}-more`},`+ ${e.more} more`):null]}var Fe=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 ee(t,e,o,n){const{P:l}=t,i=_o(e,n)||n.keep===o.id,a=Wt(e,n),r=n.layout==="drawn"&&n.rows,s=[`--_c:${o.col}`,`--_r:${r?2*o.row:o.row}`,`--_r2:${r?2*o.row2+1:o.row2+1}`];Se(e)&&s.push(`--_lo:${o.row>1&&e.groups.some(h=>Xt(e,h)?.r1===o.row)?1:0}`),e.type==="data-flow"&&s.push(`--_lc:${o.col+1}`),e.type==="sequence"&&s.push(`--_c2:${o.col+1}`);const c=t.plan;if(c&&o.i>0){const h=jt(c.gaps,o.id)??32,d=jt(n.grow,o.id)??0;s.push(`--_gap:${d?`calc(${Fe(h)} + var(--basalt-space-4) * ${d})`:Fe(h)}`)}const g=jt(n.heights,o.id);g&&s.push(`--_h:${g}px`);const f=jt(Je(e),o.id);f&&s.push(`--_mh:${f}px`);const u=jt(n.words,o.id);u&&s.push(`--_ww:${u}px`);const m=a?n.stop===o.id?0:-1:n.keep===o.id?-1:void 0;return M(o.href?"a":"div",{class:`${l}-node`,href:o.href,target:o.href&&o.blank?"_blank":void 0,rel:o.href&&o.blank?"noopener noreferrer":void 0,"data-link":o.href?o.blank?"external":"":void 0,"data-node":o.id,"data-shape":o.shape,"data-focal":o.focal?"":void 0,"data-branch":o.branch?"":void 0,...e.ext?.nodeAttrs?.(e,o),"data-mark":o.mark?o.mark.id??"":void 0,"data-level":t.level,style:s.join(";"),role:i&&!o.href?"img":void 0,"aria-label":i||o.href?xo(e,o):void 0,tabindex:m},o.shape==="decision"?M("svg",{class:`${l}-diamond`,viewBox:"0 0 100 100",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},M("path",{d:"M50 0L100 50L50 100L0 50Z"})):null,o.mark?M("span",{class:`${l}-mark`,"aria-hidden":"true",style:o.mark.onLight?`--_ml:${Ae(o.mark.onLight)};--_md:${Ae(o.mark.onDark??o.mark.onLight)}`:void 0}):null,o.shape==="table"?Ro(l,o,e):e.ext?.card?e.ext.card(l,e,o,n):jo(l,e,o))}function To(t,e,o){const{P:n}=t;if(e.ext?.drawing)return e.ext.drawing(n,e,o,t.level);const l=[];if(e.type==="data-flow"&&l.push(...e.lanes.map((s,c)=>M("div",{class:`${n}-lane`,style:`--_r:${c+1}`,"aria-hidden":"true"},M("span",{class:`${n}-lane-name`},gt(s.label))))),Ut(e.type))for(const s of e.groups){const c=Xt(e,s);if(!c)continue;const g=e.ext?.groupMark?.(e,s,c),f=[0,1,2,3].map(u=>Be(e,s,u));l.push(M("div",{class:`${n}-gbox`,"data-group":s.id,"data-depth":s.depth>1?s.depth:void 0,style:`--_c:${c.c1};--_c2:${c.c2+1};--_r:${c.r1};--_r2:${c.r2+1}${Se(e)?`;--_lo:${c.r1>1?1:0}`:""}${f[0]>1?";--_gt:2":""}${f[1]>1?";--_ge:2":""}${f[2]>1?";--_gb:2":""}${f[3]>1?";--_gs:2":""}${g?.style??""}`,"data-start":g?.start,"aria-hidden":"true"},M("span",{class:`${n}-glabel`},gt(s.label))))}if(e.text)return[M("pre",{class:`${n}-text`,"aria-hidden":"true","data-art":o.art?"":void 0},M("code",{class:`${n}-text-ink`},zo(n,e)))];if(e.type==="sequence")return l.push(M("ul",{class:`${n}-cast`},e.nodes.map(s=>M("li",{class:`${n}-actor`,style:e.rtl?`--_ac:${s.col}`:void 0},ee(t,e,s,o))))),l.push(Wo(t,e)),l;const i=s=>{const c=s.group?e.groups.find(g=>g.id===s.group):void 0;return c?.parent?e.groups.find(g=>g.id===c.parent):c},a=(s,c,g)=>{const f=t.plan?jt(o.grow,c[0].id)??0:0,u=c[0],m=t.plan&&u.group===s.id?e.edges.filter((p,w)=>p.to===u.id&&(t.plan.routes[w]==="trunk"||t.plan.routes[w]==="end-down")):[],h=Math.max(0,...m.map(p=>p.label?Pt(p.label):0)),d=[f?`--_ggrow:${f}`:"",h?`--_tl:${h}`:""].filter(Boolean).join(";");return M("div",{class:`${n}-group`,"data-group":s.id,"data-depth":s.depth>1?s.depth:void 0,"data-turn":m.length?"":void 0,"data-start":t.plan?e.ext?.groupMark?.(e,s,null)?.start:void 0,style:d||void 0},M("span",{class:`${n}-glabel`,"aria-hidden":"true"},gt(s.label)),g)};let r=0;for(;rd.id===g[u].group):void 0;if(!m){f.push(ee(t,e,g[u],o)),u++;continue}const h=[];for(;uee(t,e,d,o))))}l.push(a(c,g,f))}return l}function zo(t,e){const o=[],n=s=>M("span",{class:`${t}-tx-name`},s),l=s=>s==="main"?"━▶":s==="dashed"?"┄▷":"─▶",i=(s,c,g,...f)=>M("span",{class:`${t}-tx-line`,...s,style:g?`--_in:${c+g};--_hang:${g}`:`--_in:${c}`},...f);o.push(i({"data-ink":"names"},0,0,e.nodes.flatMap((s,c)=>[c?" · ":"",n(s.name)])));const a=String(Math.max(1,...e.steps.map(s=>"n"in s?s.n:0))).length;let r=0;for(const s of e.steps){const c=2*r;if("band"in s){o.push(i({"data-ink":"band"},c,0,`── ${s.band} ──`));continue}if("open"in s){o.push(i({"data-ink":"frame"},c,0,M("span",{"data-ink":"op"},`[${s.open}]`),` ${s.label}`)),r++;continue}if("otherwise"in s){o.push(i({"data-ink":"frame"},2*Math.max(0,r-1),0,M("span",{"data-ink":"op"},"[else]"),` ${s.otherwise}`));continue}if("close"in s){r=Math.max(0,r-1),o.push(i({"data-ink":"frame"},2*r,0,"[end]"));continue}const g=e.byId.get(s.from)?.name??s.from,f=e.byId.get(s.to)?.name??s.to,u=a+2;o.push(i({"data-n":s.n},c,u,M("span",{"data-ink":"num"},String(s.n).padStart(a,"0"))," ",n(g)," ",M("span",{class:`${t}-tx-to`},M("span",{"data-ink":s.kind==="main"?"main":"plain"},l(s.kind))," ",f))),o.push(i({"data-n":s.n},c+u,0,M("span",{"data-ink":"label"},s.label))),s.note&&o.push(i({"data-n":s.n},c+u,0,M("span",{"data-ink":"note"},s.note)))}return o}function Wo(t,e){const{P:o}=t,n=[],l=[],i=()=>l.length?l[l.length-1].el.c:n;let a=null;for(const r of e.steps){if("band"in r){a=null,i().push(M("p",{class:`${o}-band`},M("span",null,gt(r.band))));continue}if("open"in r){a=null;const d=l[l.length-1],p=d?`;--_fis:${r.a===d.a?1:0};--_fie:${r.b===d.b?1:0}`:"",w=M("div",{class:`${o}-frame`,"data-op":r.open,"data-depth":r.depth,style:`--_a:${r.a};--_b:${r.b+1}${p}`},M("span",{class:`${o}-fbox`,"aria-hidden":"true"}),M("p",{class:`${o}-fhead`},M("span",{class:`${o}-ftab`,"aria-hidden":"true"},r.open),M("span",{class:`${o}-flabel`},M("span",{class:t.hidden},`${e.frameWords[r.open]}: `),gt(r.label))));i().push(w),l.push({el:w,a:r.a,b:r.b});continue}if("otherwise"in r){a=null,i().push(M("p",{class:`${o}-felse`},M("span",{class:`${o}-fword`,"aria-hidden":"true"},"else"),M("span",{class:`${o}-flabel`},M("span",{class:t.hidden},`${e.frameWords.else}: `),gt(r.otherwise))));continue}if("close"in r){a=null,l.pop();continue}a||(a=M("ol",{class:`${o}-msgs`,start:r.n}),i().push(a));const s=e.byId.get(r.from),c=e.byId.get(r.to),g=s?.col??1,f=c?.col??1,u=g===f,m=u&&(e.rtl?g!==1:g===e.nodes.length),h=_e(e,r.kind);a.c.push(M("li",{class:`${o}-msg`,"data-kind":r.kind,"data-from":r.from,"data-to":r.to,"data-self":u?m?"start":"end":void 0,style:`--_a:${Math.min(g,f)};--_b:${Math.max(g,f)+1}`},M("span",{class:`${o}-said`},M("span",{class:`${o}-num`},String(r.n)),M("span",{class:`${o}-mlabel`},gt(r.label))),M("span",{class:`${o}-route`},gt(s?.short??r.from)," ",M("span",{class:`${o}-to`},Bo(o,r.kind),M("span",{class:t.hidden}," to ")," ",gt(c?.short??r.to),h?[" · ",gt(h)]:"")),r.note?M("span",{class:`${o}-note`},gt(r.note)):null))}return M("div",{class:`${o}-steps`},n)}function Ne(t,e){return zt(e,`list:${t}`,()=>No(t,e))}var Fo=Ne;function No(t,e){if(e.ext?.list)return e.ext.list(t,e);const o=Math.min(6,e.heading+1),n=f=>M(`h${o}`,{class:`${t}-list-head`},f),l=f=>M("strong",null,gt(f)),i=f=>f.href?M("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},l(f.name)):l(f.name),a=f=>M("code",{class:`${t}-code`},gt(f)),r=f=>e.byId.get(f)?.name??f,s=f=>{const u=_e(e,f);return u?` (${u})`:""},c=f=>f.focal&&e.legend.focal?` ${Kt(e.legend.focal)}`:"";if(Ut(e.type)){const f=d=>e.ext?.listPart?.(t,e,d)??[],u=d=>M("li",null,i(d),d.kind?[", ",gt(d.kind)]:"",d.detail?[". ",d.mono?a(d.detail):gt(d.detail),/[.!?]$/.test(d.detail)?"":"."]:/[.!?]$/.test(d.kind??d.name)?"":".",f(d),c(d)),m=[n(e.ext?.listParts??"Parts")],h=e.nodes.filter(d=>!d.group);h.length&&m.push(M("ul",{class:`${t}-list-items`},h.map(u)));for(const d of e.groups.filter(p=>p.depth===1)){m.push(M("p",{class:`${t}-list-group`},gt(d.label))),d.members.length&&m.push(M("ul",{class:`${t}-list-items`},d.members.map(p=>u(e.byId.get(p)))));for(const p of e.groups.filter(w=>w.parent===d.id))m.push(M("p",{class:`${t}-list-group`,"data-depth":2},gt(p.label))),m.push(M("ul",{class:`${t}-list-items`,"data-depth":2},p.members.map(w=>u(e.byId.get(w)))))}return e.ext?.listLines?(m.push(...e.ext.listLines(t,e,n)),m):(m.push(n("Connections")),m.push(M("ol",{class:`${t}-list-items`},e.edges.map(d=>M("li",null,l(r(d.from))," to ",l(r(d.to)),d.label?[": ",a(Ct(d.label))]:"",`${s(d.kind)}.`)))),m)}if(e.type==="flowchart"){const f=u=>(e.byId.get(u)?.i??0)+1;return[M("ol",{class:`${t}-list-items`},e.nodes.map(u=>{const m=e.edges.filter(p=>p.from===u.id),h=u.shape==="decision"?"Decision":u.shape==="terminal"?m.length?"Start":"End":"Step",d=!u.detail&&/[.!?]$/.test(u.name)?" ":". ";return M("li",null,i(u),u.detail?[", ",u.mono?a(u.detail):gt(u.detail)]:"",`${d}${h}.`,c(u),m.length?M("ul",{class:`${t}-list-exits`},m.map(p=>M("li",null,p.label?`If ${Ct(p.label)}: go to ${f(p.to)}, `:`Then: go to ${f(p.to)}, `,l(r(p.to)),s(p.kind)))):null)}))]}if(e.type==="data-flow")return[M("ol",{class:`${t}-list-items`},e.nodes.map(f=>{const u=e.edges.filter(m=>m.from===f.id);return M("li",null,gt(f.laneLabel??""),": ",i(f),f.detail?[", ",f.mono?a(f.detail):gt(f.detail)]:"",".",c(f),u.length?[" Then ",...u.flatMap((m,h)=>[h?"; ":"",`to step ${e.byId.get(m.to).step}, `,l(r(m.to)),m.label?[": ",a(Ct(m.label))]:"",s(m.kind)]),"."]:"")}))];if(e.type==="sequence"){const f=[n("Participants"),M("ul",{class:`${t}-list-items`},e.nodes.map(m=>M("li",null,l(m.name),m.kind?`, ${m.kind}`:"",".",c(m),Ie(e,m))))];f.push(n("Messages"));let u=null;for(const m of e.steps){if("band"in m){u=null,f.push(M(`h${Math.min(6,o+1)}`,{class:`${t}-list-group`},m.band));continue}if("open"in m){u=null,f.push(M(`h${Math.min(6,o+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){u=null,f.push(M(`h${Math.min(6,o+1)}`,{class:`${t}-list-group`,"data-depth":m.depth>1?m.depth:void 0},`${e.frameWords.else}: ${m.otherwise}`));continue}if("close"in m){u=null;continue}u||(u=M("ol",{class:`${t}-list-items`,start:m.n}),f.push(u)),u.c.push(M("li",null,a(m.label),": ",l(r(m.from))," to ",l(r(m.to)),`${s(m.kind)}.`,m.note?` ${Kt(m.note)}`:""))}return f}const g=[];for(const f of e.nodes)g.push(M(`h${o}`,{class:`${t}-list-group`},f.href?M("a",{href:f.href,target:f.blank?"_blank":void 0,rel:f.blank?"noopener noreferrer":void 0},a(f.name)):a(f.name),c(f))),g.push(M("ul",{class:`${t}-list-items`},[...(f.columns??[]).map(u=>M("li",null,a(u.name),u.key==="PK"?", primary key":u.key==="FK"?", foreign key":"",u.ref?[", references ",a(`${u.ref.table}.${u.ref.column}`),u.card?[" (",Mo(f.id,u.ref.table,u.card,a),")"]:""]:u.type?`, ${u.type}`:"")),...f.more?[M("li",null,`and ${f.more} more ${f.more===1?"column":"columns"}`)]:[]]));return g}function He(t,e=!1){if(t.ext?.keys)return t.ext.keys(t,e);const o=t.ext?t.ext.stop.replace(/^an? /,""):t.type==="architecture"?"part":t.type==="sequence"?"participant":t.type==="schema"?"table":"step";return`${e&&oe(t)?`Arrow keys move to the nearest ${o} in that direction`:`Arrow keys move to the next or the previous ${o}, 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 he(t,e=!1){if(t.ext?.hint)return t.ext.hint(t,e);const o=e&&t.type!=="sequence"&&oe(t)&&t.cols>1&&t.rows>1,n=t.nodes.some(l=>l.href)?[{keys:["Enter"],words:"open"}]:[];return[{keys:o?["←","↑","↓","→"]:["←","→"],words:Oe(t)},{keys:["Home","End"],words:"the ends"},...n,{keys:["Esc"],words:"clear"}]}var Ho=(t,e)=>{for(let o=0;o({col:e.col,rows:[e.row,e.row2]});function oe(t){return zt(t,"spatial",()=>{const e=t.nodes.map(i=>({id:i.id,...Do(t,i)})),o=(i,a)=>{const r=a==="right"||a==="left",s=a==="right"||a==="down",c=h=>r?[h.col,h.col]:h.rows,g=h=>r?h.rows:[h.col,h.col],f=c(i),u=g(i);let m=null;return e.forEach((h,d)=>{if(h===i)return;const p=c(h),w=g(h),x=s?p[0]-f[1]:f[0]-p[1];if(x<1)return;const B=Math.max(0,w[0]-u[1],u[0]-w[1]),v=[B===0?0:1,B===0?x:x+2*B,B,Math.abs(w[0]-u[0]),d];(!m||Ho(v,m.rank))&&(m={id:h.id,rank:v})}),m?.id??null},n=It();for(const i of e)n[i.id]={right:o(i,"right"),left:o(i,"left"),down:o(i,"down"),up:o(i,"up")};const l=i=>{const a=new Set([i]),r=[i];for(;r.length;)for(const s of Object.values(n[r.pop()]))s&&!a.has(s)&&(a.add(s),r.push(s));return a.size};return e.every(i=>l(i.id)===e.length)?n:null})}function ne(t){return zt(t,"turn-back-lanes",()=>{const e=new Map,o=new Set;if(!pe(t))return{lane:e,dropped:o,lanes:0};const n=(s,c)=>(t.byId.get(s)?.row??0)*1e3+c,l=new Map;t.edges.forEach((s,c)=>{const g=`${s.to}.${s.toRow}.${s.card?.to??""}`,f=n(s.from,s.fromRow??0),u=n(s.to,s.toRow??0),m=l.get(g)??{members:[],lo:1/0,hi:-1/0};m.members.push(c),m.lo=Math.min(m.lo,f,u),m.hi=Math.max(m.hi,f,u),l.set(g,m)});const i=[...l.values()].sort((s,c)=>c.hi-c.lo-(s.hi-s.lo)),a=[];let r=0;for(const s of i.reverse()){const c=new Set(a.filter(f=>f.lo<=s.hi&&s.lo<=f.hi).map(f=>f.lane));let g=0;for(;c.has(g);)g++;if(g>1){for(const f of s.members)o.add(f);continue}a.push({lo:s.lo,hi:s.hi,lane:g});for(const f of s.members)e.set(f,g);r=Math.max(r,g+1)}return{lane:e,dropped:o,lanes:r}})}var pe=t=>t.type==="schema"&&t.cols===1&&t.edges.length>0;function ae(t,e,o){const n=o.prefix,l=Lo(o.base),i=t.type==="sequence"||t.type==="schema"||t.ext&&!t.ext.routed?null:Re(t),a={P:n,ids:l,level:o.level,plan:i,hidden:o.hiddenClass},r=e.layout==="drawn",s=Wt(t,e),c=t.type==="sequence"||t.type==="schema"?r:!0,g=`h${t.heading}`,f=[`--_cols:${te(t)}`],u=t.ext?.room?.(t),m=u?.start,h=u?.top;if(Ut(t.type)&&t.groups.length||r&&e.pad||m||h){const d=Ut(t.type)?Ce(t):[0,0,0,0],p=(B,v,C)=>B?B>1?`calc(${B} * var(--basalt-space-${v}))`:`var(--basalt-space-${v})`:C?`var(--basalt-space-${C})`:"0px",w=r&&e.pad?"3":void 0,x=B=>m?`calc(${B} + var(--basalt-space-10))`:B;f.push(`--_gpad:${h?`calc(${p(d[0],"8",w)} + var(--basalt-space-10))`:p(d[0],"8",w)} ${t.rtl?x(p(d[1],"4")):p(d[1],"4")} ${p(d[2],"4",w)} ${t.rtl?p(d[3],"4"):x(p(d[3],"4"))}`)}if(i?.gutter&&i.laneCount>2&&f.push(`--_gw:calc(${i.laneCount} * var(--basalt-space-3-5) + var(--basalt-space-3))`),pe(t)){const d=t.marks?"var(--basalt-space-6) + var(--basalt-space-1)":"var(--basalt-space-5)",p=ne(t).lanes>1?`calc(${d} + var(--basalt-space-3))`:t.marks?`calc(${d})`:d;f.push(t.rtl?`--_gpad:0px 0px 0px ${p}`:`--_gpad:0px ${p} 0px 0px`)}return t.type==="schema"&&e.track&&f.push(`--_track:${e.track}px`),r&&e.one&&f.push(`--_one:${e.one}px`),t.ext?.rootStyle&&f.push(...t.ext.rootStyle(t,e)),M("figure",{class:o.className?`${n} ${o.className}`:n,"aria-labelledby":l.title,"data-type":t.type,"data-cols":te(t),"data-reach":Ut(t.type)?je(t):void 0,"data-gutter":i?.gutter?"":void 0,"data-marks":t.marks?"":void 0,"data-contour":t.type==="data-flow"&&t.nodes.some(d=>d.shape==="decision")?"":void 0,"data-layout":e.layout??(t.unplaced?"stacked":void 0),"data-measured":e.layout?"":void 0,"data-bare":e.bare?"":void 0,"data-form":e.form??(e.layout?void 0:t.ext?.form?.(t)),"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":o.viewer?"":void 0,style:f.join(";")},M("div",{class:`${n}-head`},M(g,{id:l.title,class:`${n}-title`},gt(t.title)),(()=>{const d=t.ext?.sourceLead?.(t);return o.hasSource||d?M("p",{class:`${n}-source`},d?[M("bdi",null,d),o.hasSource?" · ":""]:null,o.hasSource?M("bdi",null,{slot:"source"}):null):null})(),t.ext?.meta?.(n,t)??null),M("div",{class:`${n}-drawing`,style:r&&e.rows?`--_rows:${e.rows};--_row-gap:0px`:void 0,role:c?"group":void 0,"aria-roledescription":c?"diagram":void 0,"aria-labelledby":c?l.title:void 0,"aria-describedby":c?s?`${l.summary} ${l.keys}`:l.summary:void 0,"data-stops":s?"":void 0},To(a,t,e),t.text?null:M("div",{class:`${n}-ink`,"aria-hidden":"true"}),M("span",{class:`${n}-ruler`,"aria-hidden":"true"})),We(n,t),M("p",{class:`${n}-hint`,"data-kbd-hint":"","aria-hidden":"true"},{slot:"hint"}),(t.ext?t.ext.traces?.(t,r):Wt(t,e)&&t.type!=="sequence"||r&&t.type==="sequence")?M("p",{class:`${n}-tap-hint`,"aria-hidden":"true"},`Tap ${Oe(t)} to highlight its lines. Tap it again to clear.`):null,M("div",{class:`${n}-foot`},{slot:"toggle"}),M("div",{id:l.list,class:`${n}-list`,hidden:!e.open},Ne(n,t)),M("span",{id:l.keys,class:o.hiddenClass},o.viewer?`${He(t,r)} ${o.viewer}`:He(t,r)),M("figcaption",{id:l.summary,class:`${n}-summary`},{slot:"summary"}))}function Go(t){const e=getComputedStyle(t),o=(l,i)=>{const a=parseFloat(e.getPropertyValue(`--basalt-${l}`));return Number.isFinite(a)?a:i},n=new Map;return{space:l=>(n.has(l)||n.set(l,o(`space-${l}`,parseFloat(l.replace("-","."))*4)),n.get(l)),node:o("size-diagram-node",144),table:o("size-diagram-table",224),lane:o("size-diagram-lane",120),step:o("size-diagram-step",56),head:o("size-diagram-head",8),guide:o("size-diagram-guide-dash",4),hair:o("size-hairline",1),line:o("size-chart-line",2),cut:o("size-cut",2),dot:o("size-dot",6),dash:o("size-chart-dash",6),dashGap:o("size-chart-dash-gap",4),wide:o("size-breakpoint-container-lg",640),cap:o("size-breakpoint-container",480),radius:o("radius-md",8),radiusXs:o("radius-xs",4),activation:o("size-diagram-activation",8),foot:o("size-diagram-foot",14)}}var se=(t,e)=>t==="main"?e.line:e.hair,Et=(t,e)=>{const o=t.getBoundingClientRect();return{l:o.left-e.left,t:o.top-e.top,r:o.right-e.left,b:o.bottom-e.top}},Bt=(t,e,o=.01)=>t.le.l+o&&t.te.t+o,ge=(t,e)=>({l:t.l-e,r:t.r+e,t:t.t-e,b:t.b+e});function At(t,e,o){const{l:n,t:l,r:i,b:a}=t.rect,r=(n+i)/2,s=(l+a)/2,c=(i-n)/2,g=(a-l)/2,f=e==="top"||e==="bottom";if(t.shape==="decision"){if(f){const h=o,d=g*Math.max(0,1-Math.abs(h-r)/c);return{x:h,y:e==="top"?s-d:s+d}}const u=o,m=c*Math.max(0,1-Math.abs(u-s)/g);return{x:e==="left"?r-m:r+m,y:u}}if(t.shape==="terminal"){const u=Math.min(c,g);if(f){const p=o,w=Math.min(Math.max(p,n+u),i-u),x=p-w,B=Math.abs(x)>=u?0:Math.sqrt(u*u-x*x);return{x:p,y:Math.abs(x)<1e-6?e==="top"?l:a:e==="top"?s-B:s+B}}const m=o,h=m-s,d=Math.abs(h)>=u?0:Math.sqrt(u*u-h*h);return{x:e==="left"?n+u-d:i-u+d,y:m}}return f?{x:o,y:e==="top"?l:a}:{x:e==="left"?n:i,y:o}}function Vo(t,e,o){const{l:n,t:l,r:i,b:a}=e.rect,r=(n+i)/2,s=(l+a)/2,c=(i-n)/2,g=(a-l)/2;if(e.shape==="decision")return Math.abs(t.x-r)/c+Math.abs(t.y-s)/g<1-o/Math.min(c,g);if(e.shape==="terminal"){const f=Math.min(c,g),u=Math.min(Math.max(t.x,n+f),i-f);return Math.hypot(t.x-u,t.y-s)n+o&&t.xl+o&&t.ymatchMedia("(forced-colors: active)").matches;function Jo(t,e){const o=t.querySelector(`.${e}-ruler`),n=new Map;return(l,i)=>{const a=`${i}|${l}`;return n.has(a)||(o.setAttribute("data-f",i),o.textContent=l,n.set(a,o.getBoundingClientRect().width),o.textContent=""),n.get(a)}}var re=t=>t?t.split(/\s+/).filter(Boolean):[];function Uo(t,e,o){if(t.ext?.least&&!t.ext.routed){const s=Math.max(e.wide,t.ext.least(t,e,o));return{track:e.node,table:e.table,least:s,own:s}}const n=e.space;let l=e.node,i=e.table;for(const s of t.nodes){if(s.shape==="table"){for(const d of s.columns??[]){const p=d.ref?`${t.rtl?"←":"→"} ${d.ref.table}`:d.type??"",w=n("6")+o(d.name,"mono")+(p?n("3")+o(p,"mono"):0)+2*n("3")+2*e.hair;i=Math.max(i,Math.ceil(w))}i=Math.max(i,Math.ceil(o(s.name,"table")+2*n("3")+2*e.hair+(s.href?16+n("1-5"):0)));continue}const c=s.shape==="terminal"?2*n("5"):2*n("3"),g=s.mark&&!Zo()?(s.shape==="participant"?2:1)*n("6"):0;let f=0;const u=s.href?16+n("1-5"):0,m=re(s.name);if(m.forEach((d,p)=>{f=Math.max(f,o(d,s.shape==="decision"?"name-500":"name")+(s.kind?0:g)+(p===m.length-1?u:0))}),t.type!=="data-flow")for(const d of re(s.kind))f=Math.max(f,o(d,"mono")+g);for(const d of re(s.detail))f=Math.max(f,o(d,s.mono?"mono":"sans"));const h=s.shape==="decision"?f/.62:f+c+2*e.hair;l=Math.max(l,Math.ceil(h))}const a=te(t);let r;return t.type==="data-flow"?r=e.lane+a*(l+n("12")):t.type==="schema"?r=a*i+(a-1)*(n("12")+(t.marks?n("3"):0))+(pe(t)?(t.marks?n("6")+n("1"):n("5"))+(ne(t).lanes>1?n("3"):0):0):t.type==="sequence"?r=a*l+(a-1)*n("5"):r=a*l+(a-1)*n("16")+je(t)*n("4"),{track:l,table:i,least:Math.max(e.wide,r),own:Math.ceil(r)}}function Ge(t,e,o=!1){const n=o?l=>-Math.round(-l):Math.round;return{x:(l,i)=>i%2===1?n(l+t-.5)+.5-t:n(l+t)-t,y:(l,i)=>i%2===1?Math.round(l+e-.5)+.5-e:Math.round(l+e)-e}}function me(t){const e=t[t.length-2],o=t[t.length-1];return Math.abs(e.x-o.x)<.01?o.y>e.y?"down":"up":o.x>e.x?"right":"left"}function Ve(t,e,o){const n=t.map(i=>({...i}));for(let i=1;i=2){const s=l[l.length-2];if(Math.abs(s.x-r.x)<.01&&Math.abs(r.x-a.x)<.01||Math.abs(s.y-r.y)<.01&&Math.abs(r.y-a.y)<.01){l[l.length-1]=a;continue}}l.push(a)}}return l}var Ot=t=>t.slice(1).map((e,o)=>[t[o],e]);function ie(t,e,o){const n=[];for(let i=0;iMath.min(d.x,p.x)+.75&&BMath.min(w.y,x.y)+.75&&vi.split(/\s+/).map(parseFloat).filter(a=>Number.isFinite(a)),n=(i,a,r)=>{const s=[];let c=a;for(const g of i)s.push([c,c+g]),c+=g+r;return s},l=n(o(e.gridTemplateRows),parseFloat(e.paddingTop)||0,parseFloat(e.rowGap)||0);return{cols:n(o(e.gridTemplateColumns),parseFloat(e.paddingLeft)||0,parseFloat(e.columnGap)||0),rows:t.style.getPropertyValue("--_rows").trim()?l.filter((i,a)=>a%2===1):l}}var bt=t=>t==="left"||t==="right",Ke={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 Ze(t,e,o){const n=[];t.edges.forEach((i,a)=>{const r=t.byId.get(i.from),s=t.byId.get(i.to),[c,g]=e[a],f=r.row===s.row&&bt(c)&&bt(g)&&c===Ke[g]||r.col===s.col&&!bt(c)&&!bt(g)&&c===Ke[g];n.push({edge:a,end:"from",node:r,side:c,far:s,straight:f,f:.5},{edge:a,end:"to",node:s,side:g,far:r,straight:f,f:.5})});const l=new Map;for(const i of n){const a=`${i.node.id}.${i.side}`;l.has(a)||l.set(a,[]),l.get(a).push(i)}for(const[i,a]of l){if(a[0].node.shape==="decision")continue;const r=d=>bt(d.side)?d.far.row-d.node.row:d.far.col-d.node.col,s=a.filter(d=>d.straight),c=a.filter(d=>!d.straight);if(c.sort((d,p)=>r(d)-r(p)||(bt(d.side)?d.far.col-p.far.col:d.far.row-p.far.row)*(r(d)<0?1:-1)),a.length>3&&o(`${i.replace(".","'s ")} side has ${a.length} lines; more than three is an error: use another side`),!s.length){c.length===2?(c[0].f=.25,c[1].f=.75):c.length===3?(c[0].f=.25,c[1].f=.5,c[2].f=.75):c.length>3&&c.forEach((d,p)=>{d.f=(p+1)/(c.length+1)});continue}const g=new Map;for(const d of s)g.has(d.far.id)||g.set(d.far.id,[]),g.get(d.far.id).push(d);for(const d of g.values())d.length>1&&d.sort((p,w)=>p.edge-w.edge).forEach((p,w)=>{p.f=d.length===2?w===0?.25:.75:(w+1)/(d.length+1)});const f=Math.min(...s.map(d=>d.f)),u=Math.max(...s.map(d=>d.f)),m=c.filter(d=>r(d)<0),h=c.filter(d=>r(d)>=0);m.forEach((d,p)=>{d.f=f*(p+1)/(m.length+1)}),h.forEach((d,p)=>{d.f=u+(1-u)*(p+1)/(h.length+1)})}return n}function Je(t,e=8,o=8){return zt(t,`port-floors:${e}:${o}`,()=>{const n=It();if(t.type!=="architecture"&&t.type!=="flowchart"&&t.type!=="data-flow"&&t.type!=="schedule"&&t.type!=="state"&&t.type!=="deployment")return n;const l=t.edges.map(a=>{const r=t.byId.get(a.from),s=t.byId.get(a.to),[c,g]=ye(r,s);return[a.fromSide??c,a.toSide??g]}),i=new Map;for(const a of Ze(t,l,()=>{})){if(!bt(a.side)||a.node.shape!=="box")continue;const r=`${a.node.id}.${a.side}`;i.has(r)||i.set(r,[]),i.get(r).push(a.f)}for(const[a,r]of i){if(r.length<2)continue;const s=r.slice().sort((f,u)=>f-u).filter((f,u,m)=>u===0||f-m[u-1]>1e-9);let c=Math.max(e/s[0],e/(1-s[s.length-1]));for(let f=1;f{const a=t.byId.get(i.dataset.node);a&&l.set(a.id,{id:a.id,rect:Et(i,o),shape:a.shape,i:a.i})}),l}function Ye(t,e){const o=e.head,n=e.head/2,{x:l,y:i}=t.tip;return t.dir==="down"?{l:l-n,r:l+n,t:i-o,b:i}:t.dir==="up"?{l:l-n,r:l+n,t:i,b:i+o}:t.dir==="right"?{l:l-o,r:l,t:i-n,b:i+n}:{l,r:l+o,t:i-n,b:i+n}}var $e=(t,e,o)=>({l:Math.min(t.x,e.x)-o/2,r:Math.max(t.x,e.x)+o/2,t:Math.min(t.y,e.y)-o/2,b:Math.max(t.y,e.y)+o/2});function Qe(t,e,o,n,l=!1){const i=(r,s)=>{const c=r+s-Math.floor(r+s);return c<.005||c>.995?[0]:c<=.5?[-c,1-c]:[1-c,-c]},a=l?i(-t.r,-e).map(r=>-r):i(t.l,e);for(const r of i(t.t,o))for(const s of a){if(!s&&!r)return t;const c={l:t.l+s,r:t.r+s,t:t.t+r,b:t.b+r};if(n(c))return c}return t}function Yo(t,e,o,n,l,i,a,r,s){const c=a.space,g=[],f=[],u=[],m=[],h=c("1"),d=e.filter(p=>t.edges[p.i]?.label).sort((p,w)=>+(t.edges[w.i].kind==="main")-+(t.edges[p.i].kind==="main")||p.i-w.i);for(const p of d){const w=t.edges[p.i].label,x=r(w,"label"),B=16*Pt(w),v=p.pts.length-2,C=[];Ot(p.pts).forEach(([E,Z],R)=>{const N=Math.abs(E.y-Z.y)<.01,Y=N?E.x:E.y;let D=N?Z.x:Z.y;const P=Math.sign(D-Y)||1;R===v&&(D-=P*a.head);let mt=[[Y,D]];for(const ft of l)for(const ct of N?[ft.l,ft.r]:[ft.t,ft.b]){const it=N?E.y:E.x;(N?it>ft.t&&itft.l&&itct>Math.min(j,tt)+1&&ct{const it=(ft+ct)/2,dt=N?{x:it,y:E.y}:{x:E.x,y:it};return!l.some(j=>dt.x>j.l&&dt.xj.t&&dt.y1&&$t(ft,ct)?1:0})}),C.sort((E,Z)=>Z.pri-E.pri||Z.len-E.len);let _=null,q=!1;const O=(E,Z=!0)=>{const R=ge(E,h);return Z&&(E.li.r||E.ti.b)||o.some(N=>De(R,N))||g.some(N=>Bt(R,N))||n.heads.some(N=>Bt(R,N))||n.rects.some(N=>Bt(R,N))?!1:!e.some(N=>N.i!==p.i&&Ot(N.pts).some(([Y,D])=>Bt(R,$e(Y,D,N.width))))};for(const E of C){for(const Z of[1/2,1/3,2/3]){const R=E.p+(E.q-E.p)*Z,N=[],Y=c("2")+p.width/2;if(E.horiz?(E.len>=x+2*c("1")+c("3-5")&&N.push({box:{l:R-x/2-c("1"),r:R+x/2+c("1"),t:E.c-B/2,b:E.c+B/2},on:!0}),N.push({box:{l:R-x/2,r:R+x/2,t:E.c-Y-B,b:E.c-Y},on:!1}),N.push({box:{l:R-x/2,r:R+x/2,t:E.c+Y,b:E.c+Y+B},on:!1})):(E.len>=B+c("3")&&N.push({box:{l:E.c-x/2-c("1"),r:E.c+x/2+c("1"),t:R-B/2,b:R+B/2},on:!0}),N.push({box:{l:E.c+Y,r:E.c+Y+x,t:R-B/2,b:R+B/2},on:!1}),N.push({box:{l:E.c-Y-x,r:E.c-Y,t:R-B/2,b:R+B/2},on:!1})),_=N.find(D=>O(D.box))??null,_)break;!q&&N.some(D=>O(D.box,!1))&&(q=!0)}if(_)break}if(!_){u.push(p.i),q&&m.push(p.i);continue}const st=Qe(_.box,s.ox,s.oy,E=>O(E));g.push(st),f.push({i:p.i,text:w,box:st,on:_.on})}return{labels:f,unseated:u,bounded:m}}function Pe(t,e,o,n){const l=[],i=[];return t.querySelectorAll(`.${o}-gbox, .${o}-group`).forEach(a=>{if(a.getClientRects().length===0||getComputedStyle(a).display==="contents")return;const r=Et(a,e);i.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 s=a.querySelector(`:scope > .${o}-glabel`);s&&s.getClientRects().length&&l.push(Et(s,e))}),t.querySelectorAll(`.${o}-lane`).forEach((a,r)=>{if(!a.getClientRects().length)return;const s=Et(a,e);r>0&&l.push({l:s.l,r:s.r,t:s.t-n/2-.5,b:s.t-n/2+.5});const c=a.querySelector(`.${o}-lane-name`);c&&l.push(Et(c,e))}),{obstacles:{rects:l,heads:[]},groups:i}}function to(t,e){const{m:n,tk:l,P:i,drawing:a,origin:r,warn:s}=t,c=l.space,g=Xe(n,a,r,i),f=[...g.values()],u=Xo(a),m=r.left-Math.floor(r.left),h=r.top-Math.floor(r.top),d=Ge(m,h),p=a.clientWidth,w=a.clientHeight,x=y=>n.type==="data-flow"?y.col+1:y.col,B=parseFloat(getComputedStyle(a).rowGap)||0,v={w:p,h:w,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:m,oy:h};if(n.type==="sequence")return Po(t,v,d);let C,_=[];n.type==="schema"?C=n.edges.map(y=>{const S=n.byId.get(y.from),A=n.byId.get(y.to);if(S.col===A.col){const W=!((n.rtl?S.col===1:S.col===n.cols)&&n.cols>1)===!n.rtl?"right":"left";return[W,W]}return A.col>S.col?["right","left"]:["left","right"]}):(C=n.edges.map(y=>{const S=n.byId.get(y.from),A=n.byId.get(y.to),[k,L]=ye(S,A);return[y.fromSide??k,y.toSide??L]}),_=Ze(n,C,s||(()=>{})));const q=(y,S)=>{const A=a.querySelector(`.${i}-node[data-node="${CSS.escape(y)}"] .${i}-row[data-row="${S}"]`);if(!A)return 0;const k=Et(A,r);return(k.t+k.b)/2},O=new Map;if(n.type==="schema"){const y=new Map;n.edges.forEach((A,k)=>{const L=`${A.to}.${A.toRow}.${C[k][1]}`;y.set(L,[...y.get(L)??[],k])});const S=A=>{const k=n.edges[A].card?.to;return k==="one"?0:k==="zero-or-one"?1:2};for(const A of y.values()){const k=[...new Set(A.map(S))].sort((L,W)=>L-W);if(k.length>1)for(const L of A)O.set(L,(k.indexOf(S(L))-(k.length-1)/2)*c("2"))}}const st=y=>Math.round(y+m)-m,E=n.edges.map((y,S)=>{const[A,k]=C[S],L=g.get(y.from),W=g.get(y.to),V=se(y.kind,l);if(y.fk){const at=q(y.from,y.fromRow),lt=q(y.to,y.toRow)+(O.get(S)??0),kt=d.y(at,V),Rt=d.y(lt,V),Ft=A==="right"?L.rect.r:L.rect.l,Nt=k==="right"?W.rect.r:W.rect.l;return{p1:{x:y.card?st(Ft):Ft,y:kt},p2:{x:y.card?st(Nt):Nt,y:Rt},r1:at,r2:Math.abs(kt-Rt)<.01?at:lt}}const G=_.find(at=>at.edge===S&&at.end==="from").f,U=_.find(at=>at.edge===S&&at.end==="to").f;let K=Ue(L,A,G),ot=Ue(W,k,U);const F=bt(A)?K.y:K.x;let J=bt(k)?ot.y:ot.x;return bt(A)?K={...K,y:d.y(K.y,V)}:K={...K,x:d.x(K.x,V)},bt(k)?ot={...ot,y:d.y(ot.y,V)}:ot={...ot,x:d.x(ot.x,V)},bt(A)&&bt(k)&&Math.abs(K.y-ot.y)<1.01&&(ot={...ot,y:K.y},J=F),!bt(A)&&!bt(k)&&Math.abs(K.x-ot.x)<1.01&&(ot={...ot,x:K.x},J=F),K=bt(A)?At(L,A,K.y):At(L,A,K.x),ot=bt(k)?At(W,k,ot.y):At(W,k,ot.x),{p1:K,p2:ot,r1:F,r2:J}}),Z=new Set,R=(y,S)=>{Z.has(y)||(Z.add(y),s?.(`${n.edges[y].from} to ${n.edges[y].to} ${S}, so its line is not drawn; its row still writes the target`))};for(const y of ne(n).dropped)R(y,"would need a third lane of turn-backs");const N=new Map,Y=It();n.type==="schema"&&n.edges.forEach((y,S)=>{const A=n.byId.get(y.from),k=n.byId.get(y.to);if(Math.abs(A.col-k.col)<2)return;const L=Math.min(A.col,k.col),W=Math.max(A.col,k.col),V=n.nodes.filter(lt=>lt.col>L&<.colkt.row<=lt&&kt.row2>=lt+1)||U.push({key:`g${lt}`,y:(G[lt-1][1]+G[lt][0])/2,inner:!0});U.push({key:"top",y:G[0][0]-c("4"),inner:!1},{key:"bottom",y:G[G.length-1][1]+c("4"),inner:!1});const K=(E[S].r1+E[S].r2)/2,ot=t.pick?.[S]??U.slice().sort((lt,kt)=>Math.abs(lt.y-K)-Math.abs(kt.y-K)||Number(kt.inner)-Number(lt.inner)||lt.y-kt.y)[0].key;Y[S]=ot;const F=C[S][0]==="right"?A.col:A.col-1,J=u.cols[F-1],at=u.cols[F];N.set(S,{corridor:ot,first:J&&at?{key:`c${F}`,span:[J[1],at[0]]}:null,y:0})});const D=new Map;for(const[y,S]of N){const A=n.edges[y],k=D.get(S.corridor)??[],L=k.find(W=>{const V=n.edges[W[0]];return V.to===A.to&&V.toRow===A.toRow&&C[W[0]][1]===C[y][1]&&Math.abs(E[W[0]].p2.y-E[y].p2.y)<.5});L?L.push(y):k.length>=2?R(y,"would need a third lane in its corridor"):k.push([y]),D.set(S.corridor,k)}for(const y of[...N.keys()])Z.has(y)&&N.delete(y);const P=y=>{const S=n.edges[y[0]];return Math.abs(n.byId.get(S.from).col-n.byId.get(S.to).col)*1e4+Math.abs(E[y[0]].p1.x-E[y[0]].p2.x)},mt=(y,S,A)=>{const k=u.rows;if(y==="top")return k[0][0]-c("4")-S*c("3");if(y==="bottom")return k[k.length-1][1]+c("4")+S*c("3");const L=Number(y.slice(1));return(k[L-1][1]+k[L][0])/2+(S-(A-1)/2)*c("3")},$t=(y,S)=>S.forEach((A,k)=>A.forEach(L=>{N.get(L).y=mt(y,k,S.length)})),ut=()=>{for(const[y,S]of D){const A=S.map(k=>k.filter(L=>N.has(L))).filter(k=>k.length);D.set(y,A),$t(y,y==="top"||y==="bottom"?A.slice().sort((k,L)=>P(k)-P(L)):A.slice().sort((k,L)=>P(L)-P(k)))}};ut();const{obstacles:ft,groups:ct}=Pe(a,r,i,B),it=new Map,dt=new Set,j=new Map,tt=(y,S,A,k,L)=>{it.has(y)||it.set(y,{span:S,vertical:A,members:new Map});const W=it.get(y);W.members.has(k)||W.members.set(k,[]),W.members.get(k).push(L)},et=()=>{it.clear(),dt.clear(),j.clear(),n.edges.forEach((y,S)=>{if(Z.has(S))return;const A=N.get(S);A?.first&&tt(A.first.key,A.first.span,!0,`far:${S}`,-(S+1));const[k,L]=C[S],{p1:W,p2:V}=E[S],G=n.byId.get(y.from),U=n.byId.get(y.to);let K=null,ot=null,F=!1;if(k===L){if(bt(k)){const J=k==="right"?Math.max(x(G),x(U)):Math.min(x(G),x(U))-1,at=u.cols[J-1],lt=u.cols[J];at&<&&(K=`c${J}`,ot=[at[1],lt[0]],F=!0)}else{const J=k==="bottom"?Math.max(G.row2,U.row2):Math.min(G.row,U.row)-1,at=u.rows[J-1],lt=u.rows[J];at&<&&(K=`r${J}`,ot=[at[1],lt[0]],F=!1)}K&&dt.add(S)}else if(bt(k)&&bt(L)&&(A||Math.abs(W.y-V.y)>.5)){const J=x(U),at=L==="left",lt=u.cols[(at?J-1:J)-1],kt=u.cols[(at?J:J+1)-1];lt&&kt&&(K=`c${at?J-1:J}`,ot=[lt[1],kt[0]],F=!0)}else if(!bt(k)&&!bt(L)&&Math.abs(W.x-V.x)>.5){const at=L==="top"?U.row-1:U.row2,lt=u.rows[at-1],kt=u.rows[at];lt&&kt&&(K=`r${at}`,ot=[lt[1],kt[0]],F=!1)}!K||!ot||(A&&j.set(S,ot),tt(K,ot,F,`${y.to}.${L}.${Math.round(F?V.y:V.x)}`,S))})};et();const nt=new Map,X=y=>{const[S,A]=C[y],{p1:k,p2:L}=E[y],W=N.get(y);if(W){const V=j.get(y),G=nt.get(-(y+1))??(W.first?(W.first.span[0]+W.first.span[1])/2:k.x),U=nt.get(y)??(V?(V[0]+V[1])/2:L.x);return[k,{x:G,y:k.y},{x:G,y:W.y},{x:U,y:W.y},{x:U,y:L.y},L]}if(bt(S)&&bt(A)){if(S===A){const G=c(n.marks?"6":"4")+(n.type==="schema"&&n.cols===1?(ne(n).lane.get(y)??0)*c("3"):0),U=nt.get(y)??(S==="right"?Math.max(k.x,L.x)+G:Math.min(k.x,L.x)-G);return[k,{x:U,y:k.y},{x:U,y:L.y},L]}if(Math.abs(k.y-L.y)<=.5)return[k,{x:L.x,y:k.y}];const V=nt.get(y)??(k.x+L.x)/2;return[k,{x:V,y:k.y},{x:V,y:L.y},L]}if(!bt(S)&&!bt(A)){if(S===A){const G=nt.get(y)??(S==="bottom"?Math.max(k.y,L.y)+c("4"):Math.min(k.y,L.y)-c("4"));return[k,{x:k.x,y:G},{x:L.x,y:G},L]}if(Math.abs(k.x-L.x)<=.5)return[k,{x:k.x,y:L.y}];const V=nt.get(y)??(k.y+L.y)/2;return[k,{x:k.x,y:V},{x:L.x,y:V},L]}return bt(S)?[k,{x:L.x,y:k.y},L]:[k,{x:k.x,y:L.y},L]},$=y=>{const S=n.edges[y],A=se(S.kind,l),k=X(y),L=Ve(k,A,d);let W;return k.length===L.length&&(W=Ot(k).map(([V,G])=>Math.abs(V.y-G.y)<.75?(V.y+G.y)/2:(V.x+G.x)/2),W[0]=E[y].r1,W.length>1&&(W[W.length-1]=E[y].r2)),{i:y,from:S.from,to:S.to,kind:S.kind,pts:L,tip:L[L.length-1],dir:me(L),dot:S.fk&&!S.card?L[0]:void 0,card:S.card,width:A,axes:W}},b=()=>n.edges.flatMap((y,S)=>Z.has(S)?[]:[$(S)]);let I=null;const z=y=>{I??(I=b());const S=I.map(A=>y.has(A.i)?$(A.i):A);return{lines:S,score:Qo(S,y)*1e5+ie(S,void 0,y).length*1e3+we(S.filter(A=>y.has(A.i)),f,n).length}},T=(y,S)=>{const A=y.flatMap(k=>{const L=k<0?-k-1:k,{p1:W,p2:V}=E[L],G=N.get(L);return G?k<0?[W.y,G.y]:[G.y,V.y]:S?[W.y,V.y]:[W.x,V.x]});return[Math.min(...A),Math.max(...A)]},H=y=>y<0?-y-1:y,ht=y=>{const S=[...y.members.values()].map(k=>({members:k,run:T(k,y.vertical)})).sort((k,L)=>k.run[0]-L.run[0]),A=[];for(const k of S){const L=A[A.length-1];L&&L.some(W=>W.run[0]!(k.length===1&&k[0].members.every(L=>dt.has(L))))},Q=y=>(S,A)=>y[S].run[0]{const S=Q(y),A=[];return y.forEach((k,L)=>{let W=0;for(;A.some((V,G)=>V===W&&S(L,G));)W++;A.push(W)}),A},rt=y=>Math.max(0,...xt(y))+1;if(n.marks)for(let y=0;y3){S=W.map(V=>V.members.map(H));break}if(!S)break;const A=L=>Math.max(...L),k=S.filter(L=>L.some(W=>N.has(W))).sort((L,W)=>A(W)-A(L))[0]??S.slice().sort((L,W)=>A(W)-A(L))[0];for(const L of k)R(L,"would need a fourth lane in a marked gutter"),N.delete(L);et()}const wt=(y,S,A,k=!1)=>{const L=n.rtl&&k?A-1-S:S,W=y[1]-y[0];if(!n.marks)return y[0]+W/(A+1)*(L+1);const V=l.foot+l.radiusXs,G=A>1?Math.min(W/(A+1),(W-2*V)/(A-1)):0;return(y[0]+y[1])/2+(L-(A-1)/2)*G},vt=[],pt=(y,S,A)=>{const[k,L]=y.span,W=Math.max(...S.map(K=>K.run[1])),V=(L-k)/(A+1);let G=k,U=L;for(const K of ct){const[ot,F,J,at]=y.vertical?[K.l,K.r,K.t,K.b]:[K.t,K.b,K.l,K.r];at<=S[0].run[0]||J>=W||(ot>G&&otG&&Fk&&k+VU-c("3"))?y.span:((U-G)/(A+1)K.members.map(H))),[G,U])};ut();for(const[y,S]of D){if(y==="top"||y==="bottom"||S.length<2)continue;const A=new Set(S.flat());let k=S,L=1/0;for(const W of be(S.slice().sort((V,G)=>P(G)-P(V)))){$t(y,W),I=null;const V=z(A);V.scoreK.members);if(n.marks){const K=rt(S),ot=Q(S),F=S.length,J=new Set(A.flat().map(H)),at=pt(y,S,K),lt=Lt=>Lt.forEach((_t,Gt)=>A[Gt].forEach(Tt=>nt.set(Tt,wt(at,_t,K,y.vertical))));let kt=xt(S),Rt=1/0,Ft=null;const Nt=[kt];if(K**F<=729)for(let Lt=0;LtMath.floor(Lt/K**Tt)%K);_t.every((Gt,Tt)=>_t.every((Qt,Zt)=>Zt<=Tt||Gt!==Qt||!ot(Tt,Zt)))&&Nt.push(_t)}for(const Lt of Nt){lt(Lt);const _t=z(J);_t.score{const ot=n.edges[K];return ot?`${n.byId.get(ot.from)?.name} to ${n.byId.get(ot.to)?.name}`:""}).join(", ")} ${k>1?"run":"runs"} closer than space-3 a lane${L!==y.span?" beside a box's edge":""}`);const W=new Set(A.flat().map(H));let V=A,G=1/0,U=null;for(const K of be(A)){K.forEach((F,J)=>F.forEach(at=>nt.set(at,wt(L,J,k,y.vertical))));const ot=z(W);ot.scoreK.forEach(F=>nt.set(F,wt(L,ot,k,y.vertical)))),I=U}if(v.lines=b(),n.marks&&(v.lines=v.lines.filter(y=>{if(!y.card)return!0;const S=Ot(y.pts),A=([L,W])=>Math.hypot(W.x-L.x,W.y-L.y),k=S.length===1?2*l.foot:l.foot+l.radiusXs-.5;return A(S[0])>=k&&A(S[S.length-1])>=k?!0:(R(y.i,"has no room for its marks at an end"),N.delete(y.i),!1)})),N.size){const y=new Set([...N.values()].map(A=>A.corridor)),S=[y.has("top")?"var(--basalt-space-8)":"0px"];for(let A=1;A<=n.rows;A++)S.push("auto",AYe(y,l));const yt=Yo(n,v.lines,f,ft,ct,{l:0,t:0,r:p,b:w},l,e,{ox:m,oy:h});return v.labels=yt.labels,v.unseated=yt.unseated,v.bounded=yt.bounded,v.overlaps=[...new Set([...eo(v.lines,null).flat(),...vt])],v}function Qo(t,e){return eo(t,e).length}function eo(t,e){const o=[];for(let n=0;n=r)continue;const[p,w]=u?[s.x,c.x]:[s.y,c.y],[x,B]=u?[g.x,f.x]:[g.y,f.y];Math.min(Math.max(p,w),Math.max(x,B))-Math.max(Math.min(p,w),Math.min(x,B))>1&&o.push([i.i,a.i])}}return o}function*be(t){if(t.length<=1){yield t.slice();return}if(t.length>5){yield t.slice();return}for(let e=0;e{const s=r===i.pts.length-1?Math.max(i.width/2,n.head/2):i.width/2;return a.x-s<-.5||a.x+s>e+.5||a.y-s<-.5||a.y+s>o+.5})&&l.push(i.i);return l}function we(t,e,o){const n=[];for(const l of t){const i=Ot(l.pts);e.some(a=>i.some(([r,s])=>Ko(r,s,a)))&&n.push(l.i)}return n}function Po(t,e,o){const{m:n,tk:l,P:i,drawing:a,origin:r}=t,s=l.space,c=new Map;a.querySelectorAll(`.${i}-node`).forEach(v=>c.set(v.dataset.node,Et(v,r)));const g=a.querySelector(`.${i}-steps`),f=g?Et(g,r).b:e.h,u=v=>{const C=c.get(v);return C?o.x((C.l+C.r)/2,l.hair):0};for(const v of n.nodes){const C=c.get(v.id);C&&e.lifelines.push({x:u(v.id),y1:C.b,y2:f})}const m=v=>c.get(v.id),h=new Map;a.querySelectorAll(`.${i}-msg`).forEach(v=>{const C=Et(v,r);h.set(Number(v.querySelector(`.${i}-num`)?.textContent??0),(C.t+C.b)/2)});const d=l.activation,p=d/2,w=v=>{const C=n.byId.get(v.who);if(!C)return null;const _=u(v.who),O=(C.i===n.nodes.length-1&&n.nodes.length>1?-1:1)*(n.rtl?-1:1),st=(v.depth-1)*s("1")*O,E=h.get(v.from)??0,Z=h.get(v.to)??E,R=v.from===v.to;return{l:o.x(_-p+st,l.hair),r:o.x(_+p+st,l.hair),t:o.y(R?E-s("2")-s("1"):E,l.hair),b:o.y(R?E+s("2")+s("1"):Z,l.hair)}},x=n.bars.map(v=>({bar:v,rect:w(v)})).filter(v=>v.rect);e.bars=x.map(v=>v.rect);const B=(v,C,_)=>x.filter(({bar:q})=>q.who===v&&q.to>=C&&(_?q.from<=C:q.fromO.bar.depth-q.bar.depth)[0]?.rect;a.querySelectorAll(`.${i}-msg`).forEach(v=>{const C=v.dataset.from,_=v.dataset.to,q=v.dataset.kind??"plain",O=se(q,l),st=Et(v,r),E=o.y((st.t+st.b)/2,O),Z=Number(v.querySelector(`.${i}-num`)?.textContent??0);let R=u(C),N=u(_),Y;if(C===_){const ct=v.dataset.self==="start"?-s("6"):s("6"),it=B(C,Z,!0),dt=it?ct>0?it.r:it.l:R,j=o.y(E-s("2"),O),tt=o.y(E+s("2"),O);Y=[{x:dt,y:j},{x:o.x(R+ct,O),y:j},{x:o.x(R+ct,O),y:tt},{x:dt,y:tt}]}else{const ct=N>R?1:-1,it=B(C,Z,!1),dt=B(_,Z,!0);it&&(R=ct>0?it.r:it.l),dt&&(N=ct>0?dt.l:dt.r),Y=[{x:R,y:E},{x:N,y:E}]}e.lines.push({i:Z,from:C,to:_,kind:q,pts:Y,tip:Y[Y.length-1],dir:me(Y),width:O});const D=v.querySelector(`.${i}-said`),P=v.querySelector(`.${i}-note`),mt=n.byId.get(C),$t=n.byId.get(_);if(!mt||!$t)return;const ut=C===_?(()=>{const ct=n.nodes.find(dt=>dt.col===mt.col+(v.dataset.self==="start"?-1:1)),it=ct?u(ct.id):v.dataset.self==="start"?0:e.w;return Math.abs(it-R)-s("6")-s("2-5")-s("2")})():Math.abs(N-R)-2*s("2");Math.max(D?D.getBoundingClientRect().width:0,P?P.getBoundingClientRect().width:0)>ut+.5&&e.unseated.push(Z)}),a.querySelectorAll(`.${i}-fhead`).forEach(v=>{const C=v.parentElement?.querySelector(`:scope > .${i}-fbox`);if(!C)return;[...v.children].reduce((q,O)=>q+O.getBoundingClientRect().width,0)+s("3")>C.getBoundingClientRect().width+.5&&(e.misfit??(e.misfit=[])).push(`the frame "${v.querySelector(`.${i}-flabel`)?.textContent??""}" is wider than its participants`)});{const v=[...a.querySelectorAll(`.${i}-fbox`)].flatMap(C=>{const _=Et(C,r);return[{x:_.l+.5,t:_.t,b:_.b},{x:_.r-.5,t:_.t,b:_.b}]});v.length&&a.querySelectorAll(`.${i}-said, .${i}-note, .${i}-band > span`).forEach(C=>{if(!C.getClientRects().length)return;const _=ge(Et(C,r),s("1"));v.some(q=>_.lq.x&&_.tq.t)&&(e.misfit??(e.misfit=[])).push(`"${C.textContent?.trim()??""}" would lie on a frame's side`)})}return e}function tn(t,e,o,n,l){const i=[];for(const[a,r]of t){if(!r.getClientRects().length)continue;const s=Et(r,o),c=Et(a,o),g=getComputedStyle(r),f=getComputedStyle(a),u={l:s.l+(parseFloat(g.paddingLeft)||0),r:s.r-(parseFloat(g.paddingRight)||0)},m=u.r-u.l,h=c.l+(parseFloat(f.borderLeftWidth)||0),d=c.r-(parseFloat(f.borderRightWidth)||0),p=[];for(const q of e)for(const[O,st]of Ot(q.pts)){const E=$e(O,st,q.width);E.ts.t&&p.push({l:E.l,r:E.r})}const w=l("2-5"),x=q=>p.every(O=>O.r<=q-w+.01||O.l>=q+m+w-.01);if(x(u.l))continue;const B=p.map(q=>n?u.r-(q.l-w):q.r+w-u.l).filter(q=>q>0).sort((q,O)=>q-O),v=q=>n?u.l-q:u.l+q,C=q=>n?v(q)>=h+l("3")-.01:v(q)+m<=d-l("3")+.01,_=B.find(q=>C(q)&&x(v(q)));if(_===void 0){i.push(r.textContent??"");continue}r.style.setProperty("--_gx",`${Math.round(_*100)/100}px`)}return i}function no(t,e,o,n=It()){const{m:l,tk:i,P:a,drawing:r,origin:s}=t,c=i.space,g=Xe(l,r,s,a),f=[...g.values()],u=s.left-Math.floor(s.left),m=s.top-Math.floor(s.top),h=Ge(u,m,!!l.rtl),d=r.clientWidth,p=r.clientHeight,w={w:d,h:p,nodes:f,lines:[],lifelines:[],labels:[],crossings:[],through:[],unseated:[],outside:[],ox:u,oy:m},x=It();if(l.type==="sequence"||l.type==="schema")return{geo:w,grow:x};const B=!!l.rtl,v=B?-1:1,C=j=>B?j.r:j.l,_=j=>B?j.l:j.r,q=B?"left":"right",O=(j,tt,et,nt)=>{const X=j+nt*v*tt,$=X+nt*v*et;return{l:Math.min(X,$),r:Math.max(X,$)}},st=getComputedStyle(r),E=B?parseFloat(st.paddingLeft)||0:d-(parseFloat(st.paddingRight)||0),Z=(j,tt,et)=>{const nt=[j];for(let X=1;X<=(jt(n,tt)??0);X++)nt.push({...j,t:j.t+et*c("4")*X,b:j.b+et*c("4")*X});return nt},R=new Map;r.querySelectorAll(`.${a}-node`).forEach(j=>{const tt=j.parentElement,et=Et(tt,s),nt=getComputedStyle(tt);R.set(j.dataset.node,B?et.l+(parseFloat(nt.paddingLeft)||0)+(parseFloat(nt.borderLeftWidth)||0):et.r-(parseFloat(nt.paddingRight)||0)-(parseFloat(nt.borderRightWidth)||0))});const N=l.nodes,Y=j=>g.get(N[j].id),D=new Map;r.querySelectorAll(`.${a}-group > .${a}-glabel`).forEach(j=>{j.style.removeProperty("--_gx"),D.set(j.parentElement,j)});const P=new Map;for(const[j,tt]of D)tt.getClientRects().length&&P.set(j,Et(tt,s));const mt=j=>{const tt=r.querySelector(`.${a}-node[data-node="${CSS.escape(j)}"]`),et=tt?.parentElement;return!!(et?.matches(`.${a}-group[data-turn]`)&&et.querySelector(`:scope > .${a}-node`)===tt)},$t=(j,tt,et)=>mt(tt)?Array.from({length:Math.round(et/16)+1},(nt,X)=>({...j,t:j.t-X*c("4"),b:j.b-X*c("4")})):[j],ut=[],ft=j=>se(l.edges[j].kind,i);l.edges.forEach((j,tt)=>{const et=o.routes[tt],nt=g.get(j.from),X=g.get(j.to),$=ft(tt);let b=[];const I=j.label,z=I?e(I,"label"):0,T=I?16*Pt(I):16,H=c("4");if(et==="down"||et==="up"){const Q=Math.max(nt.rect.l,X.rect.l),xt=Math.min(nt.rect.r,X.rect.r),rt=l.edges.map((yt,y)=>({o:yt,j:y})).filter(({o:yt,j:y})=>(o.routes[y]==="down"||o.routes[y]==="up")&&(yt.from===j.from&&yt.to===j.to||yt.from===j.to&&yt.to===j.from)),wt=rt.findIndex(yt=>yt.j===tt),vt=rt.length<2?.5:rt.length===2?wt===0?.25:.75:(wt+1)/(rt.length+1);let pt=h.x(Q+(xt-Q)*vt,$);if(et==="down"){const yt=r.querySelector(`.${a}-node[data-node="${CSS.escape(j.to)}"]`),y=yt?.parentElement,S=y&&y.matches(`.${a}-group`)&&y.querySelector(`:scope > .${a}-node`)===yt?P.get(y):void 0;if(S&&y&&!y.contains(r.querySelector(`.${a}-node[data-node="${CSS.escape(j.from)}"]`))){const A=c("2-5")+$/2;if(pt>S.l-A&&pt=Q+c("6"):k<=xt-c("6"))&&(pt=h.x(k,$))}}}if(b=et==="down"?[At(nt,"bottom",pt),At(X,"top",pt)]:[At(nt,"top",pt),At(X,"bottom",pt)],I){let yt=Math.min(b[0].y,b[1].y),y=Math.max(b[0].y,b[1].y);et==="down"?y-=i.head:yt+=i.head;const S=[...r.querySelectorAll(`.${a}-group`)].map(W=>Et(W,s));let A=[[yt,y]];for(const W of S)for(const V of[W.t,W.b])A=A.flatMap(([G,U])=>V>G+1&&VS.some(G=>(W+V)/2>G.t&&(W+V)/2G.l&&pt1){const W=A.filter(([G,U])=>!k(G,U));[yt,y]=(W.length?W:A).reduce((G,U)=>U[1]-U[0]>G[1]-G[0]?U:G)}const L=[1/2,1/3,2/3].map(W=>{const V=yt+(y-yt)*W;return{l:pt-z/2-c("1"),r:pt+z/2+c("1"),t:V-T/2,b:V+T/2}});ut.push({k:tt,cands:L,on:!0,card:et==="down"?j.to:j.from})}}else if(et==="trunk"||et==="rail"){const Q=et==="rail"?B?Math.min(nt.rect.r,X.rect.r):Math.max(nt.rect.l,X.rect.l):C(nt.rect),xt=h.x(Q+v*c(et==="trunk"?"8":"3"),$),rt=At(nt,"bottom",xt);if(et==="rail"){if(b=[rt,At(X,"top",xt)],I){const wt=X.rect.t-c("6");ut.push({k:tt,cands:Z({...O(xt,c("2-5"),z,1),t:wt-T/2,b:wt+T/2},j.to,-1),on:!1,card:j.to})}}else{const wt=h.x(C(X.rect)+v*c("6"),$),vt=h.y(X.rect.t-H,$);b=[rt,{x:xt,y:vt},{x:wt,y:vt},At(X,"top",wt)];const pt={...O(wt,c("2-5"),z,1),t:vt-T/2,b:vt+T/2};I&&ut.push({k:tt,cands:[...$t(pt,j.to,T),...Z(pt,j.to,-1).slice(1)],on:!1,card:j.to})}}else{const Q=U=>R.get(U)??(B?0:d),xt=B?Math.max(Q(j.from),Q(j.to)):Math.min(Q(j.from),Q(j.to)),rt=h.x(o.gutter?E+v*(o.lanes[tt]+1)*c("3-5"):xt-v*c("2-5"),$),wt=h.y(nt.rect.t+(nt.rect.b-nt.rect.t)*o.exits[tt],$),vt=At(nt,q,wt),pt=et==="end-down",yt=l.edges.map((U,K)=>({o:U,j:K})).filter(({o:U,j:K})=>o.routes[K]===et&&U.to===j.to).sort((U,K)=>o.lanes[K.j]-o.lanes[U.j]||U.j-K.j),y=Math.max(0,yt.findIndex(({j:U})=>U===tt)),S=_(X.rect)-v*(c("6")+y*c("3")),A=_(X.rect)-v*(c("6")+(yt.length-1)*c("3")),k=h.x(S,$),L=pt?X.rect.t-H-y*c("5"):X.rect.b+H+y*c("5"),W=h.y(L,$);b=[vt,{x:rt,y:vt.y},{x:rt,y:W},{x:k,y:W},At(X,pt?"top":"bottom",k)];const V=pt?j.to:N[X.i+1]?.id??j.to,G={...O(A,c("2-5"),z,-1),t:L-T/2,b:L+T/2};I&&ut.push({k:tt,cands:[...pt?$t(G,V,T):[G],...Z(G,V,pt?-1:1).slice(1)],on:!1,card:V})}const ht=Ve(b,$,h);w.lines.push({i:tt,from:j.from,to:j.to,kind:j.kind,pts:ht,tip:ht[ht.length-1],dir:me(ht),width:$})}),w.crossings=ie(w.lines),w.through=we(w.lines,f,l),w.outside=oo(w.lines,d,p,i),w.seatless=tn(D,w.lines,s,B,c);const{obstacles:ct}=Pe(r,s,a,0);ct.heads=w.lines.map(j=>Ye(j,i));const it=[],dt={l:0,t:0,r:d,b:p};for(const j of ut){const tt=X=>{const $=ge(X,c("1"));return X.ldt.r+.5||X.tdt.b+.5||f.some(b=>De($,b))||it.some(b=>Bt($,b))||ct.heads.some(b=>Bt($,b))||ct.rects.some(b=>Bt($,b))||w.lines.some(b=>b.i!==j.k&&Ot(b.pts).some(([I,z])=>Bt($,$e(I,z,b.width))))},et=j.cands.find(X=>!tt(X));et||(x[j.card]=(x[j.card]??0)+1,w.unseated.push(j.k));const nt=et?Qe(et,u,m,X=>!tt(X),B):j.cands[0];it.push(nt),w.labels.push({i:j.k,text:l.edges[j.k].label,box:nt,on:j.on})}return{geo:w,grow:x}}function ao(t,e,o=0){const n=a=>String(Math.round(a*100)/100);let l=`M${n(t[0].x)} ${n(t[0].y)}`;for(let a=1;a{const{crow:Z,ring:R}=ze(q,O.x,O.y,st,o.head,o.dot);return`${R?``:""}`};return`${_(e.card.from,v,Math.sign(C.x-v.x)||1,"from")}${_(e.card.to,e.tip,-i.x||1,"to")}`}const a=e.kind==="dashed",r=o.head,s=o.head/2,c=a?1:r-1,g=e.pts.map(v=>({...v})),f=g[g.length-1];f.x-=i.x*c,f.y-=i.y*c;const u=e.tip.x-i.x*r,m=e.tip.y-i.y*r,h=-i.y*s,d=i.x*s,p=v=>Math.round(v*100)/100,w=St(e.kind),x=a?``:``,B=e.dot?``:"";return`${x}${B}`}function so(t,e,o,n){const l=new Map,i=new Map;for(const r of e.crossings)i.has(r.under)||i.set(r.under,[]),i.get(r.under).push(r);let a="";for(const[r,s]of i){const c=`${n}-cut-${r}`;l.set(r,c);const g=s.map(f=>{const u=e.lines[f.top],m=e.lines[f.under],h=u.width/2+o.cut,d=m.width/2+1;return f.underVertical?``:``}).join("");a+=`${g}`}return{defs:a,ids:l}}function ro(t,e,o,n,l=""){const{defs:i,ids:a}=so(t,e,o,n),r=e.lifelines.map(m=>``).join(""),s=(e.bars??[]).map(m=>``).join(""),c=e.lines.map((m,h)=>on(t,m,o,a.get(h)??null,m.from===m.to?o.radiusXs:o.radius)).join(""),f=`${r?`${r}`:""}${i?`${i}`:""}${s}${c}${l}`,u=e.labels.map(m=>`1?' data-lines="2"':""}>${m.text.split(` +`).map(St).join("
")}
`).join("");return f+u}function nn(t,e,o){const n=t.querySelector(`.${e}-ink`);if(!n||!o)return;const l=a=>`${Math.round(a*100)/100}px`;n.querySelectorAll(`:scope > .${e}-label`).forEach((a,r)=>{const s=o.labels[r];if(!s||a.dataset.edge!==String(s.i))return;const c=[["left",l(s.box.l)],["top",l(s.box.t)],["width",l(s.box.r-s.box.l)]];for(const[g,f]of c)a.style.getPropertyValue(g)!==f&&a.style.setProperty(g,f)})}function ve(t,e,o,n,l,i,a,r){const c=t.querySelector(`.${o}-drawing`);if(!c||t.clientWidth===0)return{dyn:l,geo:null,ink:"",tokens:null};const g=Go(t),f=Jo(c,o),u=Uo(e,g,f);r?.(u.least);const m=t.clientWidth,h=(()=>{const E=document.activeElement;return E&&c.contains(E)&&E.dataset.node?E.dataset.node:void 0})(),d=E=>Wt(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:h&&E.layout!=="drawn"?h:void 0};let p=!1;const w=E=>{if(p=!1,e.type!=="flowchart"&&!(e.type==="data-flow"&&e.nodes.some(N=>N.shape==="decision")))return E;i({...E,heights:void 0,words:void 0});const Z=It(),R=It();return c.querySelectorAll(`.${o}-node[data-shape="decision"]`).forEach(N=>{const Y=N.querySelector(`.${o}-words`);if(!Y)return;const D=N.getBoundingClientRect(),P=ut=>{const ft={w:ut.width+2*g.space("2-5"),h:ut.height+2*g.space("2")},ct=1-ft.w/D.width,it=ct>.05?ft.h/2/ct:ft.h*10;return Math.max(g.space("16"),Math.ceil(D.width/5),Math.ceil(2*it))},mt=Y.getBoundingClientRect();let $t=P(mt);if($t>D.width){const ut=dt=>(N.style.setProperty("--_ww",`${dt}px`),Y.getBoundingClientRect()),ft=Math.floor(N.clientWidth-2*g.space("2-5"));let ct=Math.ceil(mt.width),it=mt.height;for(;ct1;){const nt=dt+j>>1;ut(nt).heightD.width&&(p=!0)}),{...E,heights:Z,words:Object.keys(R).length?R:void 0}},x=()=>({m:e,tk:g,P:o,drawing:c,origin:c.getBoundingClientRect(),warn:a}),B=l.autoOpen?{open:!1,autoOpen:void 0}:{},v=(E,Z)=>Z.map(R=>Yt(e,E.lines.find(N=>N.i===R))).join(", ");if(e.text)return{dyn:{...l,layout:"stacked",bare:void 0},geo:null,ink:"",tokens:g,least:u.least};if(e.ext?.layout&&!e.ext.routed)return e.ext.layout(e,{fig:t,drawing:c,P:o,tk:g,W:m,least:u.least,apply:i,stopOf:d,current:{...l,...B},measure:f,warn:a});if(m>=u.least&&!e.unplaced){const E=D=>{let P=d({...l,...B,layout:"drawn",grow:void 0,track:void 0,bare:void 0,pad:D||void 0,rows:void 0,one:e.type!=="sequence"&&te(e)===1?u.own:void 0});P=w(P),i(P);let mt=to(x(),f);return mt.corridors&&(P={...P,rows:mt.corridors.rows},i(P),mt=to({...x(),pick:mt.corridors.pick},f)),{dd:P,g:mt}};let{dd:Z,g:R}=E(!1);const N=D=>D.through.length>0||D.outside.length>0||(D.overlaps?.length??0)>0||(D.misfit?.length??0)>0||p;if(!N(R)&&R.unseated.length&&R.unseated.every(D=>R.bounded?.includes(D))){const D=E(!0);!N(D.g)&&!D.g.unseated.length&&({dd:Z,g:R}=D)}const Y=!N(R)&&!R.unseated.length?e.ext?.inkMore?.(o,e,R,g,!0,a):!1;if(Y!==!1)return R.crossings.length&&a?.(`${R.crossings.length} crossing${R.crossings.length===1?"":"s"} in the drawn layout: ${R.crossings.map(D=>`${Yt(e,R.lines[D.top])} over ${Yt(e,R.lines[D.under])}`).join("; ")}`),{dyn:Z,geo:R,ink:ro(o,R,g,n,Y),tokens:g,least:u.least};p&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: a decision would be taller than it is wide`),R.misfit?.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${R.misfit.join("; ")}`),R.through.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${v(R,R.through)} would pass through a node`),R.overlaps?.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${v(R,R.overlaps)} would lie on one another`),R.outside.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: ${v(R,R.outside)} would leave the drawing`),R.unseated.length&&a?.(`the drawn layout does not fit at ${Math.round(m)}px: no clean seat for ${R.unseated.map(D=>e.type==="sequence"?`message ${D}`:`"${Ct(e.edges[D]?.label??"")}"`).join(", ")}`)}let C=d({...l,...B,layout:"stacked",heights:void 0,grow:It(),track:e.type==="schema"?u.table:void 0,bare:void 0,pad:void 0,rows:void 0,one:void 0});if(C=w(C),i(C),e.type==="sequence"||e.type==="schema"||e.ext?.stackBare)return{dyn:C,geo:null,ink:"",tokens:g,least:u.least};const _=Re(e);let q=no(x(),f,_,C.grow);for(let E=0;E<6&&Object.keys(q.grow).length;E++){const Z=It(C.grow);for(const[R,N]of Object.entries(q.grow))Z[R]=(jt(Z,R)??0)+N;C={...C,grow:Z},i(C),q=no(x(),f,_,Z)}const O=q.geo;if(!_.third&&_.laneCount>2&&a?.(`the stacked drawing uses ${_.laneCount} end lanes (four at most)`),O.unseated.length>0||O.through.length>0||O.outside.length>0||_.third){O.unseated.length&&a?.(`the stacked drawing has no clean seat for ${[...new Set(O.unseated)].map(R=>`"${Ct(e.edges[R]?.label??"")}"`).join(", ")}, so its lines are not drawn; the list holds every connection`),O.through.length&&a?.(`in the stacked drawing ${v(O,O.through)} would pass through a node, so its lines are not drawn`),O.outside.length&&a?.(`in the stacked drawing ${v(O,O.outside)} would leave the drawing, so its lines are not drawn`),_.third&&a?.("the stacked drawing would need a fifth end lane, so its lines are not drawn","error");const E={...O,lines:[],labels:[],crossings:[]};c.querySelectorAll(`.${o}-group > .${o}-glabel`).forEach(R=>R.style.removeProperty("--_gx"));const Z=d({...C,grow:It(),bare:!0,open:l.bare?l.open:!0,autoOpen:l.bare?l.autoOpen:l.open?void 0:!0});return i(Z),{dyn:Z,geo:E,ink:"",tokens:g,least:u.least}}return O.seatless?.length&&a?.(`a stacked group's label has no clear seat on its top edge: ${O.seatless.map(E=>`"${E}"`).join(", ")}`),O.crossings.length&&a?.(`${O.crossings.length} crossing${O.crossings.length===1?"":"s"} in the stacked drawing (each is cut): ${O.crossings.map(E=>`${Yt(e,O.lines[E.top])} over ${Yt(e,O.lines[E.under])}`).join("; ")}`),{dyn:C,geo:O,ink:ro(o,O,g,n,e.ext?.inkMore?.(o,e,O,g,!1)||""),tokens:g,least:u.least}}function Yt(t,e){const o=t.byId.get(e.from)?.name??e.from,n=t.byId.get(e.to)?.name??e.to;return`${o} to ${n}`}function an(t,e,o,n,l,i){const a=new Set;if(i){a.add(i);for(const d of o?.lines??[])d.from===i&&a.add(d.to),d.to===i&&a.add(d.from)}if(t.toggleAttribute("data-tracing",!!i),t.querySelectorAll(`.${e}-node`).forEach(d=>d.toggleAttribute("data-near",a.has(d.dataset.node))),t.querySelectorAll(`.${e}-ink [data-for]`).forEach(d=>d.toggleAttribute("data-lit",!!i&&d.getAttribute("data-for")===i)),!o||!n)return;const r=d=>!!i&&(d.from===i||d.to===i),s=t.querySelector(`.${e}-edges`),c=new Map;t.querySelectorAll(`.${e}-edge`).forEach(d=>c.set(d.getAttribute("data-edge"),d));for(const d of o.lines){const p=c.get(String(d.i));p&&(p.toggleAttribute("data-lit",r(d)),p.toggleAttribute("data-dim",!!i&&!r(d)))}if(t.querySelectorAll(`.${e}-label`).forEach(d=>{const p=o.lines.find(w=>String(w.i)===d.dataset.edge);d.toggleAttribute("data-lit",!!(p&&r(p)))}),s){for(const d of o.lines)if(r(d)){const p=c.get(String(d.i));p&&s.appendChild(p)}}const g=ie(o.lines,r),{defs:f,ids:u}=so(e,{...o,crossings:g},n,l),m=t.querySelector(`.${e}-svg`);if(!m)return;let h=m.querySelector("defs");!h&&f&&(h=document.createElementNS("http://www.w3.org/2000/svg","defs"),m.insertBefore(h,m.firstChild)),h&&(h.innerHTML=f),o.lines.forEach((d,p)=>{const w=c.get(String(d.i))?.querySelector(`.${e}-line`);if(!w)return;const x=u.get(p);x?w.setAttribute("mask",`url(#${x})`):w.removeAttribute("mask")})}var sn=()=>matchMedia("(prefers-reduced-motion: reduce), (forced-colors: active), print").matches||document.documentElement.getAttribute("data-loops")==="held";function rn(t,e){const o=t.getAttribute("data-entrance");if(!(o==="running"||o==="done")){if(!e){o&&t.removeAttribute("data-entrance");return}o||t.setAttribute("data-entrance",sn()||cn(t)?"done":"pending")}}var ln=t=>`basalt-diagram-entrance:${location.pathname}#${t.id}`;function cn(t){if(!t.hasAttribute("data-first-visit")||!t.id)return!1;try{return localStorage.getItem(ln(t))!==null}catch{return!1}}function io(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,o,n=!1,l=!1){if(t.ext?.keyTarget)return t.ext.keyTarget(t,e,o,n,l);const i=n?oe(t):null;if(i&&o.startsWith("Arrow")){const c={ArrowRight:l?"left":"right",ArrowLeft:l?"right":"left",ArrowDown:"down",ArrowUp:"up"}[o];return c?i[e]?.[c]??null:null}const a=t.byId.get(e)?.i??0,r=t.nodes.length;let s;if(o==="ArrowRight"||o==="ArrowDown")s=a+1;else if(o==="ArrowLeft"||o==="ArrowUp")s=a-1;else if(o==="Home")s=0;else if(o==="End")s=r-1;else return null;return t.nodes[Math.max(0,Math.min(r-1,s))].id}var fn=["data-layout","data-measured","role","aria-roledescription","aria-labelledby","aria-describedby","aria-label","tabindex","data-stops","hidden","data-art"],lo=["data-layout","data-measured","data-bare","data-form","data-contour","data-motion","data-first-visit","data-rtl","data-cols","data-reach","data-gutter","data-marks"],un=["--_lo","--_track","--_h","--_ww","--_gap","--_ggrow","--_tl","--_gpad","--_gw","--_mh","--_rows","--_row-gap","--_one","--_tx","--_ty","--_th","--_tw","--_tdw","--_name","--_lab"],co=t=>t==null||t===!1;function hn(t,e){if(t.tagName.toLowerCase()!==e.t)return!1;const o=typeof e.a.class=="string"?e.a.class.split(" ")[0]:"";return!o||t.classList.contains(o)}function le(t,e,o=!0){if(typeof e=="string"||"slot"in e)return;const n=o?lo:fn;for(const a of n)co(e.a[a])&&t.removeAttribute(a);for(const[a,r]of Object.entries(e.a)){if(a==="class")continue;if(a==="style"){const c=t.style,g=new Map(String(r??"").split(";").map(f=>{const u=f.indexOf(":");return[f.slice(0,u).trim(),f.slice(u+1).trim()]}).filter(([f])=>f));for(const[f,u]of g)c.getPropertyValue(f).trim()!==u&&c.setProperty(f,u);for(const f of un)g.has(f)||c.removeProperty(f);continue}if(o&&!lo.includes(a))continue;if(co(r)){t.removeAttribute(a);continue}const s=r===!0?"":String(r);t.getAttribute(a)!==s&&t.setAttribute(a,s)}if(e.t==="svg"||typeof e.a.class=="string"&&(/-ruler$/.test(e.a.class)||/-ink$/.test(e.a.class)&&!e.a.class.endsWith("-text-ink"))||e.c.some(a=>typeof a!="string"&&"slot"in a))return;const l=[...t.children];let i=0;for(const a of e.c)if(!(typeof a=="string"||"slot"in a)){for(let r=i;rt.querySelector(`.${e}-node[data-node="${CSS.escape(i)}"]`);o&&l(o)?.setAttribute("tabindex","-1"),l(n)?.setAttribute("tabindex","0")}(function(t){"use strict";var e=t._,o="diagram",n=0,l=e.diagramTypes=e.diagramTypes||{};function i(h){var d=Object.prototype.hasOwnProperty.call(l,h.type)?l[h.type]:null,p=typeof d=="function"?d():void 0;return h.ext===p?h:Object.assign({},h,{ext:p})}function a(h,d,p){return{prefix:o,base:h,hasSource:d.source!==void 0&&d.source!==null&&d.source!=="",hiddenClass:"visually-hidden",viewer:p?p.keys:void 0}}function r(h,d,p,w){var x=function(B){return''+St(B)+""};return{source:St(String(d.source||"")),summary:St(String(d.summary||"")),hint:he(h).map(function(B){return""+B.keys.map(x).join(" ")+" "+St(B.words)+""}).join(""),toggle:'"}}function s(h,d,p){h=i(h);for(var w=h.layout==="auto"&&ce(h.type),x=w?Array.isArray(h.placement)?h.placement:h.placement?[h.placement]:[]:[],B=h.direction||(h.type==="flowchart"?"down":"right"),v=null,C=0;C");return{open:O.slice(0,st+1),inner:O.slice(st+1,O.length-9),warnings:_.errors.map(function(E){return"error: "+E}).concat(_.warnings)}}var c=["aria-labelledby","data-type","data-cols","data-reach","data-gutter","data-marks","data-layout","data-measured","data-bare","data-form","data-contour"],g=["--_cols","--_gpad","--_track","--_name","--_lab","--_tw","--_th","--_tdw"];function f(h,d,p,w){h.__diagram&&h.__diagram.stop(),d=i(d);var x=(h.getAttribute("aria-labelledby")||"").replace(/-title$/,"").replace(/[^A-Za-z0-9_-]/g,""),B=getComputedStyle(h).direction==="rtl",v=d.layout==="auto"&&ce(d.type),C=v?Array.isArray(d.placement)?d.placement:d.placement?[d.placement]:[]:[];v&&!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 _=d.direction?[d.direction]:d.type==="flowchart"?["down","right"]:["right","down"],q=function(F){for(var J=0;J .diagram-drawing")){if(!x||!h.querySelector("#"+CSS.escape(x+"-title"))){for(;document.getElementById("dg"+ ++n+"-title"););x="dg"+n}var st=s(d,x,w),E=document.createElement("div");E.innerHTML=st.open+"";var Z=E.firstChild;c.forEach(function(F){h.removeAttribute(F)}),g.forEach(function(F){h.style.removeProperty(F)});for(var R=0;R :not(script[data-diagram])").forEach(function(F){F.remove()}),h.insertAdjacentHTML("beforeend",st.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&&!h.id&&console.error('Basalt diagram: "entrance": "first-visit" needs an id on the figure: without one the entrance plays on every visit');var Y=a(x,d,w),D={},P=null,mt=null,$t=null,ut=null,ft=Object.create(null),ct=function(F,J){ft[F]||(ft[F]=1,(J==="error"?console.error:console.warn)("Basalt diagram: "+F))},it=function(F){le(h,ae(O,F,Y))},dt=h.querySelector(".diagram-ink"),j=h.querySelector(".diagram-toggle"),tt=!w&&O.motion.animated&&typeof e.diagramMotion=="function",et=null,nt=null,X=function(){tt&&io(h)};function $(){an(h,o,P&&P.geo,P&&P.tokens,x,mt||ut||$t),z()}var b=null,I=!w&&matchMedia("(hover: none), (pointer: coarse)").matches;function z(){var F=I&&!w&&dt&&dt.innerHTML!==""&&(!O.ext||!!dt.querySelector(".diagram-edge"));if(h.toggleAttribute("data-touch",!!(I&&!w)),F&&!b){var J=h.querySelector(":scope > .diagram-foot");if(!J)return;b=document.createElement("button"),b.type="button",b.className="btn diagram-clear",b.setAttribute("data-variant","secondary"),b.setAttribute("data-size","sm"),b.innerHTML="Clear highlight",b.addEventListener("click",function(){ut&&(ut=null,$())}),J.insertBefore(b,J.querySelector(":scope > .diagram-export-note"))}else!F&&b&&(b.remove(),b=null);b&&b!==b.parentNode.lastElementChild&&document.activeElement!==b&&b.parentNode.appendChild(b),b&&(ut?b.removeAttribute("aria-disabled"):b.setAttribute("aria-disabled","true"))}function T(F){if(!F.defaultPrevented){var J=So(h,o,F,ut);J!==void 0&&(X(),I=!0,ut=J,$())}}function H(){j&&(j.setAttribute("aria-expanded",String(!!D.open)),j.firstElementChild.textContent=D.open?"Hide the list":"View as list")}function ht(){if(v&&C.length>1&&!w){for(var F=null,J=[],at=!1,lt=0;lt<_.length&&!F;lt++){var kt=q(_[lt]);if(kt){var Rt=Vt(d,{rtl:B,placement:kt}),Ft=[],Nt=ve(h,Rt,o,x,{},function(qt){le(h,ae(Rt,qt,Y))},function(qt){Ft.push(qt)});if(Nt.dyn.layout==="drawn"){F=Rt;break}var Lt=Ft.filter(function(qt){return qt.indexOf("the drawn layout does not fit")===0}).map(function(qt){return qt.replace(/^the drawn layout does not fit at \d+px: /,"")});Lt.length&&(at=!0),J.push("laid "+_[lt]+" "+(Lt.length?Lt.join("; "):"it needs "+Math.ceil(Nt.least||0)+"px"))}}if(!F&&at){var _t=J.join("; ").replace(/\d+px/g,"");h.__autoWarned!==_t&&(h.__autoWarned=_t,console.warn('Basalt diagram: layout="auto" draws in neither direction at '+Math.round(h.clientWidth)+"px, so the figure is stacked: "+J.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"))}O=F||Vt(d,{rtl:B,placement:q(_[0])})}if(v&&C.length>1&&w&&!d.direction&&w.room){for(var Gt=w.room(),Tt=-1,Qt=null,Zt=0;Zt<_.length;Zt++){var fo=q(_[Zt]);if(fo){var xe=Vt(d,{rtl:B,placement:fo}),gn=w.measure(h,xe,o,x,{},function(qt){le(h,ae(xe,qt,Y))});if(gn.dyn.layout==="drawn"){var uo=Math.min(2,Math.floor(Math.min(Gt.w/h.offsetWidth,Gt.h/h.offsetHeight)*100+1e-6)/100);uo>Tt+1e-6&&(Tt=uo,Qt=xe)}}}Qt&&(O=Qt)}P=(w?w.measure:ve)(h,O,o,x,D,it,ct),D=P.dyn,it(D),H();var ke=h.querySelector(":scope > .diagram-hint");if(ke){var ho=he(O,D.layout==="drawn").map(function(qt){return""+qt.keys.map(function(yn){return''+St(yn)+""}).join(" ")+" "+St(qt.words)+""}).join("");ke.innerHTML!==ho&&(ke.innerHTML=ho)}Wt(O,D)||($t=ut=null);var po=dt&&P.ink!==nt;po&&(dt.innerHTML=P.ink,nt=P.ink),nn(h,o,P.geo),$();var mn=O.text?h.querySelector(".diagram-text[data-art]"):null;O.text&&typeof e.diagramText=="function"&&e.diagramText(h,O,d,w);var go=O.text?h.querySelector(".diagram-text[data-art]"):null;tt&&P.tokens&&(rn(h,!!(P.geo&&P.geo.lines.length)||!!go),(po||go!==mn)&&et&&et.redrawn()),w&&w.onMeasured&&P.tokens&&w.onMeasured(P,h)}function Q(F){D=F,it(D)}function xt(F){var J=D.stop;D=Object.assign({},D,{stop:F}),pn(h,o,J,F)}var rt=function(F){var J=F&&F.closest?F.closest(".diagram-node"):null;return J&&h.contains(J)?J:null};function wt(F){var J=rt(F.target);if(!(!J||F.defaultPrevented)){if(X(),F.key==="Escape"){!w&&(mt||$t||ut)&&(F.preventDefault(),mt=$t=ut=null,$());return}if(Wt(O,D)){var at=dn(O,J.getAttribute("data-node"),F.key,D.layout==="drawn");if(at){F.preventDefault(),xt(at);var lt=h.querySelector('.diagram-node[data-node="'+CSS.escape(at)+'"]');lt&<.focus()}}}}function vt(F){var J=rt(F.target);if(J){X();var at=J.getAttribute("data-node");mt=J.matches(":focus-visible")?at:null,Wt(O,D)&&D.stop!==at&&xt(at),$()}}function pt(F){var J=rt(F.target);J&&(rt(F.relatedTarget)||(mt=null),D.keep===J.getAttribute("data-node")&&Q(Object.assign({},D,{keep:void 0})),$())}function yt(F){if(!(F.pointerType!=="mouse"||!matchMedia("(hover: hover)").matches)){var J=rt(F.target);J&&X();var at=J&&Wt(O,D)?J.getAttribute("data-node"):null;at!==$t&&($t=at,$())}}function y(){$t&&($t=null,$())}function S(){X(),Q(Object.assign({},D,{open:!D.open,autoOpen:void 0})),H()}h.addEventListener("keydown",wt),h.addEventListener("focusin",vt),h.addEventListener("focusout",pt),h.addEventListener("pointerover",yt),h.addEventListener("pointerleave",y),h.addEventListener("click",T),j&&j.addEventListener("click",S),ht();var A=h.clientWidth,k=0,L=!0,W=new ResizeObserver(function(){Math.abs(h.clientWidth-A)<.5||(A=h.clientWidth,cancelAnimationFrame(k),k=requestAnimationFrame(ht))});W.observe(h),document.fonts&&document.fonts.ready.then(function(){L&&ht()});var V=matchMedia("(forced-colors: active)"),G=O.nodes.some(function(F){return F.mark});G&&V.addEventListener("change",ht),tt&&(et=e.diagramMotion(h,{fig:h,P:o,base:x,model:function(){return O},geo:function(){return P&&P.geo},tokens:function(){return P&&P.tokens}},d));var U=!w&&d.zoom!==!1&&typeof e.diagramZoom=="function"?e.diagramZoom(h,d,{model:O,settle:X,animated:tt}):null,K=h.querySelector(":scope > .diagram-foot"),ot=!w&&d.export===!0&&K&&typeof e.diagramExport=="function"?e.diagramExport(K,h):[];h.__diagram={stop:function(){U&&U.destroy(),ot.forEach(function(F){F.remove()}),L=!1,W.disconnect(),cancelAnimationFrame(k),G&&V.removeEventListener("change",ht),et&&et.destroy(),h.removeEventListener("keydown",wt),h.removeEventListener("focusin",vt),h.removeEventListener("focusout",pt),h.removeEventListener("pointerover",yt),h.removeEventListener("pointerleave",y),h.removeEventListener("click",T),b&&b.remove(),j&&j.removeEventListener("click",S)},layout:ht,key:u(d),send:et&&et.sendValue?et.sendValue:null}}function u(h){try{return JSON.stringify(h,function(d,p){return d==="packet"&&p&&typeof p=="object"?Object.assign({},p,{send:void 0}):p})}catch{return null}}function m(){document.querySelectorAll("figure.diagram").forEach(function(h){if(!h.__diagram){var d=h.querySelector(":scope > script[data-diagram]");if(d)try{f(h,JSON.parse(d.textContent),!0)}catch(p){console.error("Basalt diagram: this figure could not be drawn",p)}}})}e.diagramMarkup=s,e.diagramKit={draw:f,buildModel:Vt,figureKey:Oo,figureList:Fo,hintEntries:he,toHtml:fe,escapeHtml:St,settleEntrance:io,measureFigure:ve},t.diagram=function(h,d){var p=h.__diagram,w=p&&p.send?u(d):null;if(w!==null&&w===p.key){p.send(d.packet?d.packet.send:void 0);return}f(h,d)},e.step(62,"wireDiagrams",m)})(window.Basalt)})(); diff --git a/.agent/skills/basalt-html/parts/manifest.json b/.agent/skills/basalt-html/parts/manifest.json index 3a297874..32f74306 100644 --- a/.agent/skills/basalt-html/parts/manifest.json +++ b/.agent/skills/basalt-html/parts/manifest.json @@ -1,8 +1,9 @@ { "$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). DECISIONS 320 (versions and release notes): the release module is new (budget 15900 at first, usage 2400); topbar, app-shell and tab-bar gain the version link's classes (budgets: topbar 17700 to 19900, app-shell 4300 to 5200 with the rail's tooltip for it, tab-bar 4850 to 5200), their usage caps rising 2900 to 3100, 2600 to 2850 and 2250 to 2400 for its one line each; skillMd rose 12650 to 12800 for the release module's line and .version-link in topbar's. The code review of round 68 adds data-focus-self to the popover module (its Tab walk; budget 4950 to 5600, usage cap 950 to 1100) and logical start and end for its alignment; the release module's header grid and the Sources panel's touch rows take it to 16900. The spacing sweep of round 68 (DECISIONS 326: Copy link's words on the edge, the callout's last change, its reference column, the last release, the touch rows' end and the whole code chip) takes the release module to 17400. The ruling on where a release ends (DECISIONS 331: no padding under the last change in a release, a release-ending fold's hang, an arrived change keeping its padding, the panel holding its first margin, Build details 44 on touch and a closed Fixed panel taking no room) takes it to 19000. The code recheck of round 68 (recheck 5) has the popover's Tab walk follow Safari's own rule (Tab skips links on Apple's WebKit, Option-Tab reaches them): popover 5600 to 5900. The pixel recheck of round 68 has the Sources panel's touch rows keep their 20px lines with the link's box as hit area, space-3 rows and space-6 between two linked values (recheck-pixels 4), and the release's whole header take the arrival's plate: release 19000 to 19600. Merging #127 (stages, DECISIONS 316 and 328) into the versioning branch: both had raised skillMd from 12650 to 12800 for their own module's line, and together they came to 12886; SKILL.md was tightened in its wording (no rule dropped) to stay within 12800. 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). Merging main (#127 and #128) into diagram batch B: skillMd keeps main's 12800 (batch B had raised it to 12950 for its diagram lines); SKILL.md was tightened in its wording to stay within it, no rule dropped; core takes main's 35550.Raised in the repo review (23 Nov 2026; budgets are soft, the owner's word): notifications 12450 to 12700 (a link is written only when relative, http, https or mailto, and side and align are checked before they reach the markup), combobox 11200 to 11350 (a disabled field's hidden input is disabled too, now and later), tooltip 3200 to 3550 (the gap to the opener is the tooltip's own, and hover and keyboard focus each hold it open; WCAG 1.4.13), chart 34750 to 34800 (the scale's step search and gridlines are bounded, so extreme values cannot hang the page), spinner 650 to 720 (its held rule moved in from loops, so a ring-only page keeps a stored hold), kbd 2900 to 2950, palette 11400 to 11500 (and its usage text 1350 to 1400, for the Mod line) and toast 16050 to 16200 (Mod in a palette item's keys is bound as it is drawn, and a toast action's aria-keyshortcuts resolves Mod). The safe-sinks rule (decided by the owner, Fable, Astra and Muse, 23 Nov 2026): skillMd 12650 to 12900, and 13050 with main's own raise merged in (one line: data goes in as textContent, a link passes Basalt.safeHref, an option comes from a fixed list), core 35400 to 35650, and 35800 with main's own raise merged in, and its usage 2950 to 3200 (one safeHref, published as Basalt.safeHref, and _.pick, in place of a copy in each module; esc escapes the apostrophe), link-tabs 5750 to 5900 (a refused link dispatches no event), diagram 92650 to 93000 (a card's mark is a relative path, https or a data: image). Merging #129 into diagram batch B: diagram keeps batch B's 145100 plus #129's mark check, set to its measure, and batch B's usage 4600. The fix round after both reviews of 421348e8 sets them to the measured sizes again: core 38950 to 39600 (every room says all three forms, and a hung word's box grows by a short room's shortfall), search to 5700 (it places its top again on a resize and with the keyboard; an empty list holds no padding), command-list to 14700 (it keeps the taller of its two heights), notifications to 12950 (the bell's edge), pane to 1950 (the page column's room), chart to 34950 (the date line's reason), and code, diagram-zoom, filter, links, sheet, still-table, tab-bar and topbar each by under 150 bytes (the three forms of a room; the selection column's width however given). Merged with main at db0bc418 (#129 to #131), DECISIONS 336's caps are set to the measured sizes again: core 35800 to 38950 and its usage 3200 to 3650, toast 16200 to 16750, terminal to 12700 (13050 with the open items' ruling: both copy buttons draw their three glyphs once, so a refused copy shows the close with no markup written after), diagram-zoom 17600 to 17750 (its viewer's Close and Zoom out hung, and the foot's room). Raised in DECISIONS 336 (reserved room across every component, claude/reserved-room), each to its measured size: core 35550 to 38700 (the edge rule a ghost .btn hangs by at a head, its ring and touch hit area, the side insets by direction, the .panel-head and page section-head that hang their last button by themselves) and its usage 2950 to 3450 (how data-edge and --basalt-edge-room are written); search 4400 to 5200 (search.js, the held top), terminal 11950 to 12550 (the close glyph for a refused copy, the edge on both copies), links 2750 to 3300 (the first icon link hung, the card room, the 20px glyph), toast 16050 to 16650 (the 46px hit areas on touch), selection 1500 to 1650 and still-table 14650 to 15000 (the 44px select column), command-list 14000 to 14350 (the panel hugs, the room is page), menu 8950 to 9150 (the column every row keeps when any row has a check or a glyph), notifications 12450 to 12600, filter 17500 to 17600, forms 3500 to 3550, sheet 5400 to 5450, topbar-nav 7550 to 7600 and app-shell 5200 to 5250 (logical sides, the edge and the room); topbar's usage 3100 to 3200 (a bar's last ghost control takes data-edge); command-list's usage 2150 to 2300 (the panel hugs; the room is page, and only on the page); dialog-form's usage 1300 to 1350 (its Close is written data-icon-only data-edge=\"end\"). Raised in the polish ruling of 336 (the selection box keeps to the cell's line): selection 1650 to 1750 (the box's start margin, min(space-4, half the spare room): 1710 measured) and its usage 1150 to 1350 (the rule's sentence: 1313 measured). Merging main (#130, #131) into claude/diagram-interop: diagram usage 4600 to 4850 (+5.4%: Batch B's diagram usage plus the basalt-diagram-export rule line, measured 4806), then 4850 to 5050 (noting that .lucid is for Lucid's REST API only and to use .vsdx in Lucid's UI, measured 4999). Raised for right to left (diagrams-rtl): diagram 145450 to 146000 (the stacked figure mirrors, its snap and whole-pixel labels with it; a drawn schema takes its turn-backs, its one-column room and its gutter lanes from the end side); then 146000 to 148000 for Fable's ruling on the stacked group label (the stem gives way, the label slides, the last resort's warning) and the author's strings isolated in ). Raised in the first tab (DECISIONS 358): tabs 3700 to 4600 (the scrollport and its hang, the divider as ::before, the underline's inset, the scroll margin, and the script that wraps the row and brings a focused tab into view: 4524 measured), link-tabs 5900 to 6350 (the hang and the divider as ::before: 6276 measured), tabs usage 750 to 1150 (the .tabs-scroll wrapper in the markup and the sentence on the scrollport, the hang and the underline: 1111 measured) and link-tabs usage 2550 to 2750 (the hang and the underline's width: 2702 measured). The pause toggle's held look (DECISIONS 361): toggle 1950 to 2400 (a seat whose glyph has a selected form draws both forms in one box with no check, and the hold's icon-only toggle crossfades between its two drawings: 2386 measured) and glyph 1950 to 2100 (the pair and the seat a toggle draws, shared with loops and diagram-motion: 2098 measured). Raised on claude/diagram-actions (diagrams-cimip's foot decision and its two rulings; budgets are soft, the reason recorded here): diagram 148000 to 148700 (main was already 148204 after #142; the one-column cap in the engine and its CSS, the foot out of print, and Clear highlight mounting before a download's note), diagram-zoom 17800 to 18000 (the viewer's end group wrapping from the start edge, the drawing's own box for Fit, the sizer's clip), diagram-export 10450 to 12850 (main was already 11147; the export of a hidden viewer drawing, the rejection of a figure with no box, and the refused-PNG note with its CSS), and the usage caps diagram 5050 to 5100 and diagram-export 700 to 760 for the rulings' words.", "budgets": { - "skillMd": 13050, - "core": 39600 + "skillMd": 13900, + "core": 39600, + "skillMdReason": "DECISIONS 359 (diagram batch D, wave 1): 13049 to 13549 bytes for the four index lines of the new type modules (diagram-scale, diagram-gantt, diagram-matrix, diagram-timeline). Cap 13050 to 13600. Then 13549 to about 13790 for three more lines (diagram-schedule, diagram-state, diagram-deployment: the split that keeps the diagram module's growth for the types a page draws). Cap 13600 to 13900." }, "core": { "classes": [ @@ -746,9 +747,12 @@ "diagram-actor", "diagram-arrow", "diagram-band", + "diagram-bar", "diagram-cast", + "diagram-clear", "diagram-cname", "diagram-code", + "diagram-crow", "diagram-ctype", "diagram-detail", "diagram-diamond", @@ -756,8 +760,15 @@ "diagram-drawing", "diagram-edge", "diagram-entry", + "diagram-fbox", + "diagram-felse", + "diagram-fhead", "diagram-fk-mark", + "diagram-flabel", "diagram-foot", + "diagram-frame", + "diagram-ftab", + "diagram-fword", "diagram-gbox", "diagram-glabel", "diagram-group", @@ -765,6 +776,7 @@ "diagram-hint", "diagram-ink", "diagram-key", + "diagram-key-glyph", "diagram-key-letters", "diagram-keyseat", "diagram-kind", @@ -774,6 +786,7 @@ "diagram-lane-word", "diagram-legend", "diagram-life", + "diagram-lifes", "diagram-line", "diagram-list", "diagram-list-exits", @@ -781,19 +794,24 @@ "diagram-list-head", "diagram-list-items", "diagram-mark", + "diagram-meta", + "diagram-meta-first", "diagram-mlabel", "diagram-more", "diagram-msg", "diagram-msgs", "diagram-name", + "diagram-name-end", "diagram-node", "diagram-note", "diagram-num", + "diagram-ring", "diagram-route", "diagram-row", "diagram-rows", "diagram-ruler", "diagram-run", + "diagram-runs", "diagram-said", "diagram-source", "diagram-steps", @@ -801,11 +819,18 @@ "diagram-svg", "diagram-swatch", "diagram-swatch-shape", + "diagram-tap-hint", + "diagram-text", + "diagram-text-ink", "diagram-th", "diagram-tip", "diagram-title", "diagram-tname", + "diagram-to", "diagram-toggle", + "diagram-tx-line", + "diagram-tx-name", + "diagram-tx-to", "diagram-words" ], "attrs": [ @@ -821,11 +846,13 @@ "art", "kbd" ], - "budget": 148700, - "usage": 5100, + "budget": 156400, + "usage": 5900, "builds": [ "kbd" - ] + ], + "usageReason": "DECISIONS 359: 5100 to 5900 for one line naming the new shapes of data (state, deployment, schedule, a dependency figure, a data flow's decision) and the type modules that draw the rest.", + "budgetReason": " DECISIONS 359 (diagram batch D, wave 1): 148204 to 155366 bytes (+7162, +4.8%): the type-module seam, the isolates on every author string, the dependency and swimlane folds and their CSS. The schedule, the state and the deployment are modules of their own (diagram-schedule, diagram-state, diagram-deployment), so a page pays for the types it draws. Cap 148700 to 155500. The run-edge ruling (run-edge/ruling.md): 155394 to 156279 bytes (+885) for the clear band beside a box's edge, the refusal under space-2 a lane and the row a box starts on standing space-4 lower; cap 155500 to 156400, the owner deciding the gate's raise." }, "diagram-motion": { "classes": [ @@ -917,6 +944,234 @@ "budget": 5450, "usage": 700 }, + "diagram-scale": { + "text": [ + "\"type\"\\s*:\\s*\"(?:gantt|timeline)\"" + ], + "textWords": [ + "a diagram's \"type\": \"gantt\" or \"timeline\"" + ], + "requires": [ + "diagram" + ], + "budget": 4700, + "usage": 300, + "budgetReason": "DECISIONS 359: a new module, 4560 bytes at its first build; cap 4700." + }, + "diagram-gantt": { + "classes": [ + "diagram-gantt-after", + "diagram-gantt-axis", + "diagram-gantt-bar", + "diagram-gantt-corner", + "diagram-gantt-grid", + "diagram-gantt-mile", + "diagram-gantt-now", + "diagram-gantt-phase", + "diagram-gantt-range", + "diagram-gantt-row", + "diagram-gantt-scale", + "diagram-gantt-tick", + "diagram-gantt-today", + "diagram-gantt-track", + "diagram-gantt-words", + "diagram-swatch-bar", + "diagram-today" + ], + "text": [ + "\"type\"\\s*:\\s*\"gantt\"" + ], + "textWords": [ + "a diagram's \"type\": \"gantt\"" + ], + "requires": [ + "diagram", + "diagram-scale" + ], + "budget": 18400, + "usage": 1250, + "budgetReason": "DECISIONS 359: a new module, 17961 bytes at its first build; The first review round's fixes: 18297 bytes; cap 18400." + }, + "diagram-matrix": { + "classes": [ + "diagram-bp-body", + "diagram-bp-cell", + "diagram-bp-head", + "diagram-bp-layer", + "diagram-bp-rule", + "diagram-bp-rule-line", + "diagram-bp-rule-name", + "diagram-bp-stage", + "diagram-bp-time", + "diagram-bp-to", + "diagram-empty", + "diagram-journey-cell", + "diagram-journey-cell-label", + "diagram-journey-cut", + "diagram-journey-disc", + "diagram-journey-grid", + "diagram-journey-head", + "diagram-journey-level", + "diagram-journey-levels", + "diagram-journey-line", + "diagram-journey-plot", + "diagram-journey-slot", + "diagram-journey-stage", + "diagram-journey-track", + "diagram-journey-value", + "diagram-journey-word", + "diagram-kanban-blocked", + "diagram-kanban-card", + "diagram-kanban-cards", + "diagram-kanban-col", + "diagram-kanban-count", + "diagram-kanban-head", + "diagram-kanban-more", + "diagram-kanban-note", + "diagram-kanban-title", + "diagram-kanban-top", + "diagram-matrix-label", + "diagram-matrix-rule", + "diagram-meta", + "diagram-meta-first", + "diagram-story-activity", + "diagram-story-backbone", + "diagram-story-card", + "diagram-story-cell", + "diagram-story-code", + "diagram-story-count", + "diagram-story-cut", + "diagram-story-cut-line", + "diagram-story-cut-name", + "diagram-story-left-out", + "diagram-story-of", + "diagram-story-slice", + "diagram-story-slice-head", + "diagram-story-slice-name", + "diagram-story-slot", + "diagram-story-step", + "diagram-story-steps", + "diagram-swatch-blocked", + "diagram-swatch-contour", + "diagram-swatch-dash", + "diagram-swatch-rule", + "diagram-swatch-slot" + ], + "text": [ + "\"type\"\\s*:\\s*\"(?:kanban|journey|service-blueprint|story-map)\"" + ], + "textWords": [ + "a diagram's \"type\": \"kanban\", \"journey\", \"service-blueprint\" or \"story-map\"" + ], + "requires": [ + "diagram" + ], + "budget": 47300, + "usage": 1500, + "budgetReason": "DECISIONS 359: a new module, 46948 bytes at its first build; The first review round's fixes: 47178 bytes; cap 47300." + }, + "diagram-timeline": { + "classes": [ + "diagram-tl-axis", + "diagram-tl-break", + "diagram-tl-break-text", + "diagram-tl-break-words", + "diagram-tl-card", + "diagram-tl-dot", + "diagram-tl-gap", + "diagram-tl-line", + "diagram-tl-slash", + "diagram-tl-stem", + "diagram-tl-tick", + "diagram-tl-tick-text", + "diagram-tl-time", + "diagram-tl-zone" + ], + "text": [ + "\"type\"\\s*:\\s*\"timeline\"" + ], + "textWords": [ + "a diagram's \"type\": \"timeline\"" + ], + "requires": [ + "diagram", + "diagram-scale" + ], + "budget": 18700, + "usage": 800, + "budgetReason": "DECISIONS 359: a new module, 18264 bytes at its first build; The first review round's fixes: 18508 bytes; cap 18700." + }, + "diagram-schedule": { + "classes": [ + "diagram-sched-after", + "diagram-sched-cell", + "diagram-sched-contour", + "diagram-sched-critical", + "diagram-sched-dur", + "diagram-sched-foot", + "diagram-sched-grid", + "diagram-sched-head", + "diagram-sched-k", + "diagram-sched-v", + "diagram-swatch-task" + ], + "text": [ + "\"type\"\\s*:\\s*\"schedule\"" + ], + "textWords": [ + "a diagram's \"type\": \"schedule\"" + ], + "requires": [ + "diagram" + ], + "budget": 13600, + "usage": 600, + "budgetReason": "DECISIONS 359: a new module, 13431 bytes at its first build; cap 13600." + }, + "diagram-state": { + "classes": [ + "diagram-actions", + "diagram-final", + "diagram-start", + "diagram-start-dot", + "diagram-start-line", + "diagram-start-tip" + ], + "text": [ + "\"type\"\\s*:\\s*\"state\"" + ], + "textWords": [ + "a diagram's \"type\": \"state\"" + ], + "requires": [ + "diagram" + ], + "budget": 11100, + "usage": 600, + "budgetReason": "DECISIONS 359: a new module, 10283 bytes at its first build; cap 10400. The ruling on the gap (state-gap/ruling.md): 10283 to 10969 bytes, for a composite's start mark above its initial state, its row's room, and the mark that never lies on a line, a label or another mark (else the figure is stacked). Cap 10400 to 11100." + }, + "diagram-deployment": { + "classes": [ + "diagram-artifact", + "diagram-artifact-detail", + "diagram-artifact-name", + "diagram-host-head", + "diagram-host-rows", + "diagram-replicas" + ], + "text": [ + "\"type\"\\s*:\\s*\"deployment\"" + ], + "textWords": [ + "a diagram's \"type\": \"deployment\"" + ], + "requires": [ + "diagram" + ], + "budget": 6700, + "usage": 600, + "budgetReason": "DECISIONS 359: a new module, 6558 bytes at its first build; cap 6700." + }, "sparkline": { "classes": [ "sparkline", diff --git a/.agent/skills/basalt-html/parts/usage/diagram-deployment.md b/.agent/skills/basalt-html/parts/usage/diagram-deployment.md new file mode 100644 index 00000000..15c8f3d3 --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-deployment.md @@ -0,0 +1,4 @@ +# diagram-deployment + +Added for you when a diagram's JSON says `"type": "deployment"`: `environment` (required, one a figure, "Production · us-east-1"), `nodes` (hosts, with +`replicas` as a number and `artifacts`: `{ id, name, detail }` rows a line may name), `groups` (two levels drawn yet), and `edges`, each with a label. diff --git a/.agent/skills/basalt-html/parts/usage/diagram-gantt.md b/.agent/skills/basalt-html/parts/usage/diagram-gantt.md new file mode 100644 index 00000000..a4322ed2 --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-gantt.md @@ -0,0 +1,15 @@ +# diagram-gantt + +Added for you when a diagram's JSON says `"type": "gantt"`. + +``` +{ "type": "gantt", "title": "…", "summary": "…", "today": "2026-11-24", "legend": { "focal": "The release" }, + "phases": [{ "id": "build", "label": "Build" }], + "tasks": [{ "id": "a", "name": "Sandbox images", "start": "2026-11-02", "end": "2026-11-09", "phase": "build" }, + { "id": "b", "name": "Cut-over", "start": "2026-11-20", "milestone": true, "after": ["a"], "focal": true }] } +``` + +- A row a task on one time scale. `start` and `end` are days (`YYYY-MM-DD`, the end inclusive) or numbers with a `unit` (`"min"`, or `{ "one": "week", "other": "weeks" }`). A milestone has a `start` and no `end`. +- No dependency line is drawn: `after` is written in the row ("After: …"). Never write a count or a length by hand; the engine writes "8 days". +- A bar is never widened: where the shortest bar would be under 8px the bars go and the words stay (a 1-day task in a 90-day plan on a phone). More than 512 times the shortest bar is never drawn: make the short task a milestone or split the chart. +- `today` is drawn only inside the plan. `todayLabel` and `labels` replace the built-in words. diff --git a/.agent/skills/basalt-html/parts/usage/diagram-matrix.md b/.agent/skills/basalt-html/parts/usage/diagram-matrix.md new file mode 100644 index 00000000..caf0ca6f --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-matrix.md @@ -0,0 +1,10 @@ +# diagram-matrix + +Added for you when a diagram's JSON says `"type": "kanban"`, `"journey"`, `"service-blueprint"` or `"story-map"`. Equal tracks, the fit measured on the +words; below it, one column. An empty cell says so in words. + +- **kanban:** `columns` (`id`, `label`, `limit`, `more`: cards not drawn, counted, `note`) and `cards` (`id`, `column`, `name`, `kind`, `detail`, `blocked`: its reason, `focal`). A count of cards at one moment: read-only, nothing drags. The count is written for you ("3, max 2 · Over limit"). +- **journey:** `actor` and `scenario` (both required), `scale`: five words lowest first, your own ("Blocked" … "Confident"), `stages` (`id`, `name`, `level` 1 to 5, `actions`, `quote`, `touchpoint`, `friction`, `opportunity`), `legend.line` (required: what the scale measures). +- **service-blueprint:** `stages` (`id`, `name`, `time`), `cells` (`stage`, `layer`: `evidence`, `customer`, `frontstage`, `backstage` or `support`, `name`, `detail`), `arrows` (optional, `main` or `plain`, never dashed: two cells of one stage, or neighbouring stages of one layer). The three rules are drawn for you. +- **story-map:** `persona`, `activities` (`id`, `name`, `steps`), `slices` (`id`, `label`, first to ship first), `stories` (`id`, `activity`, `slice`, `name`, `kind`), and one `cut`: `{ "after": "slice-id", "label": "…" }`. +- `labels` replaces any built-in word. One part at most is `focal`, with `legend.focal`. diff --git a/.agent/skills/basalt-html/parts/usage/diagram-scale.md b/.agent/skills/basalt-html/parts/usage/diagram-scale.md new file mode 100644 index 00000000..290a3405 --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-scale.md @@ -0,0 +1,4 @@ +# diagram-scale + +Added for you with a gantt or a timeline (`"type": "gantt"` or `"timeline"`): the time scale the two share, arithmetic alone. It draws nothing; each type's +layout is its own module, so a page pays for the type it draws. diff --git a/.agent/skills/basalt-html/parts/usage/diagram-schedule.md b/.agent/skills/basalt-html/parts/usage/diagram-schedule.md new file mode 100644 index 00000000..16b68f53 --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-schedule.md @@ -0,0 +1,5 @@ +# diagram-schedule + +Added for you when a diagram's JSON says `"type": "schedule"`: `unit` (one for every duration, `"min"` or `{ "one": "day", "other": "days" }`), and `tasks` with +`id`, `name`, `kind` ("T3"), `duration`, `after` (ids), and `col` and `row` as an architecture card's, or `"layout": "auto"`. Never write a number: early and late +starts and finishes, float, the critical paths and which line is main are computed. The focal task's words never say "critical". diff --git a/.agent/skills/basalt-html/parts/usage/diagram-state.md b/.agent/skills/basalt-html/parts/usage/diagram-state.md new file mode 100644 index 00000000..1809925f --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-state.md @@ -0,0 +1,6 @@ +# diagram-state + +Added for you when a diagram's JSON says `"type": "state"`: `nodes` (states, with `initial`, `final`, `entry`, `exit` and `group`), `groups` (composite +states), and `edges` with `event`, `guard` and `action`, never a `label`: the engine writes it, the event on the first line and `[guard] / action` on the +second, each line 28 characters at most. Transitions that leave one state on one event are numbered in the order tried. A line to a composite state is +not drawn yet. diff --git a/.agent/skills/basalt-html/parts/usage/diagram-timeline.md b/.agent/skills/basalt-html/parts/usage/diagram-timeline.md new file mode 100644 index 00000000..944472a8 --- /dev/null +++ b/.agent/skills/basalt-html/parts/usage/diagram-timeline.md @@ -0,0 +1,9 @@ +# diagram-timeline + +Added for you when a diagram's JSON says `"type": "timeline"`. + +- `events`: `id`, `at` (an ISO 8601 instant with its offset, `"2026-11-24T14:03:00Z"`), `name`, `kind`, `detail`, `focal`. Points only: a span is a gantt's bar. +- `timeZone` (an IANA name, default `"UTC"`): every time is written in it, 24-hour, by the engine. Never write a time or a gap by hand. +- `domain`: `["from", "to"]`, used as written; left out, the events' extent rounded out to ticks. +- `breaks`: `[{ "from", "to", "label" }]`, your own and never the engine's: a gap in the scale, its length written for you ("31 min · soak"). +- A card is at its time or the figure is stacked (each card then writes the gap since the one before). diff --git a/.agent/skills/basalt-html/parts/usage/diagram.md b/.agent/skills/basalt-html/parts/usage/diagram.md index 6394e28a..4f21cbab 100644 --- a/.agent/skills/basalt-html/parts/usage/diagram.md +++ b/.agent/skills/basalt-html/parts/usage/diagram.md @@ -17,6 +17,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`; `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`). +- **More shapes:** `state` (`nodes` with `initial`, `final`, `entry`, `exit` and `group`; `edges` with `event`, `guard`, `action` and no `label`: the engine writes it); `deployment` (`environment`, required; `nodes` with `replicas` and `artifacts`: rows a line may name); `schedule` (`unit`, `tasks` with `kind`, `duration`, `after`, `col`, `row`: its numbers and its main lines are computed). An architecture with `"dependents": { "one": "dependent", "other": "dependents" }` counts each card's dependents and dashes a cycle; a data flow's step may be `"shape": "decision"`. The others have modules of their own: gantt, timeline, kanban, journey, service blueprint, story map. - **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/tools/html-skill/build.mjs b/tools/html-skill/build.mjs index 5d4a2a29..701896f9 100644 --- a/tools/html-skill/build.mjs +++ b/tools/html-skill/build.mjs @@ -22,6 +22,7 @@ // `compose.mjs --usage` with no name prints). // Minified with esbuild (a dev dependency, in the root package.json); legal comments (/*!) are kept. +import { spawnSync } from "node:child_process"; import fs from "node:fs"; import { createRequire } from "node:module"; import path from "node:path"; @@ -233,11 +234,11 @@ const minifyJs = (code) => minify(code.replace(/%glyph-svg:([\w-]+)%/g, (_, name * The diagram module's stylesheet: the diagrams section of packages/react/src/styles/components.css (from its heading to the next section's), with React's * class prefix as the skill's and React's surface levels as the skill's panel variables (a node is the next level, the ground is the panel's own). */ -function diagramCss() { +function diagramCss(heading = " /* ---- Diagrams (DECISIONS 281") { const react = fs.readFileSync(path.join(repo, "packages", "react", "src", "styles", "components.css"), "utf8"); - const start = react.indexOf(" /* ---- Diagrams (DECISIONS 281"); + const start = react.indexOf(heading); const end = react.indexOf(" /* ---- ", start + 10); - if (start < 0 || end < 0) throw new Error("html-skill: the diagrams section of packages/react/src/styles/components.css moved; update diagramCss"); + if (start < 0 || end < 0) throw new Error(`html-skill: the section "${heading.trim()}" of packages/react/src/styles/components.css moved; update diagramCss`); const css = react.slice(start, end) .replaceAll("var(--_surface, var(--basalt-surface-1))", "var(--panel-next, var(--basalt-surface-1))") .replaceAll("var(--_surface, var(--basalt-surface-page))", "var(--panel-bg, var(--basalt-surface-page))") @@ -284,10 +285,35 @@ function diagramZoomCss() { * 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. */ -function bundleModule(file) { - const out = esbuild.buildSync({ entryPoints: [file], bundle: true, format: "iife", platform: "browser", target: "es2020", write: false, logLevel: "silent", legalComments: "inline", charset: "utf8", define: { "process.env.NODE_ENV": '"development"' } }); - return out.outputFiles[0].text; +function bundleModule(file, shimScale = false) { + const options = { entryPoints: [file], bundle: true, format: "iife", platform: "browser", target: "es2020", write: false, logLevel: "silent", legalComments: "inline", charset: "utf8", define: { "process.env.NODE_ENV": '"development"' } }; + if (!shimScale) return esbuild.buildSync(options).outputFiles[0].text; + // A plugin needs esbuild's asynchronous API, so this one bundle runs in a child process that prints it, and the build stays synchronous. + const run = spawnSync(process.execPath, ["--input-type=module", "-e", SCALE_BUNDLER, JSON.stringify(options), SCALE_TS], { encoding: "utf8", cwd: repo, maxBuffer: 64 * 1024 * 1024 }); + if (run.status !== 0) throw new Error(`html-skill: bundling ${path.basename(file)} failed: ${run.stderr}`); + return run.stdout; } +/** + * The type modules that draw on the time scale (DECISIONS 359: diagram-gantt, diagram-timeline) read it from the diagram-scale module, so a page that draws + * both holds it once: their import of diagram-scale.ts is a shim that calls `Basalt._.diagramScale` when it is used, never at load. + */ +const SCALE_TS = path.join(repo, "packages", "react", "src", "diagram-scale.ts"); +const SCALE_BUNDLER = ` +import fs from "node:fs"; +import * as esbuild from "esbuild"; +const [options, scaleTs] = [JSON.parse(process.argv[1]), process.argv[2]]; +const names = [...fs.readFileSync(scaleTs, "utf8").matchAll(/^export (?:function|const) ([A-Za-z]+)/gm)].map((m) => m[1]); +const shim = { name: "diagram-scale-shim", setup(build) { + build.onResolve({ filter: /[\\/]diagram-scale(\\.ts)?$/ }, () => ({ path: "diagram-scale", namespace: "basalt-scale" })); + build.onLoad({ filter: /.*/, namespace: "basalt-scale" }, () => ({ contents: names.map((n) => "export const " + n + " = (...a) => window.Basalt._.diagramScale." + n + "(...a);").join("\\n"), loader: "js" })); +} }; +const out = await esbuild.build({ ...options, plugins: [shim] }); +process.stdout.write(out.outputFiles[0].text); +`; +/** The diagram modules whose script bundles React's engine or a type module of it. */ +const DIAGRAM_SCRIPTS = new Set(["diagram", "diagram-motion", "diagram-zoom", "diagram-export", "diagram-text", "diagram-scale", "diagram-gantt", "diagram-matrix", "diagram-timeline", "diagram-schedule", "diagram-state", "diagram-deployment"]); +/** The type modules' stylesheets: their own sections of components.css, renamed as the diagram module's is. */ +const DIAGRAM_SECTIONS = { "diagram-gantt": " /* ---- Diagram gantt (DECISIONS 359", "diagram-matrix": " /* ---- Diagram matrix (DECISIONS 359", "diagram-timeline": " /* ---- Diagram timeline (DECISIONS 359", "diagram-schedule": " /* ---- Diagram schedule (DECISIONS 359", "diagram-state": " /* ---- Diagram state (DECISIONS 359", "diagram-deployment": " /* ---- Diagram deployment (DECISIONS 359" }; /** The module names in src/modules.json, in the order they are added to a page. */ export function moduleNames() { @@ -316,10 +342,11 @@ export function build() { // 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()); + if (Object.hasOwn(DIAGRAM_SECTIONS, name)) files[`parts/${name}.css`] = minifyCss(diagramCss(DIAGRAM_SECTIONS[name])); 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" || name === "diagram-text")) files[`parts/${name}.js`] = minifyJs(bundleModule(file)); + if (ext === "js" && DIAGRAM_SCRIPTS.has(name)) files[`parts/${name}.js`] = minifyJs(bundleModule(file, name === "diagram-gantt" || name === "diagram-timeline")); 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 a1b2acef..4c0fa8a4 100644 --- a/tools/html-skill/src/compose.mjs +++ b/tools/html-skill/src/compose.mjs @@ -692,7 +692,7 @@ function writeDiagrams(markup, held, parts, notes, marks) { // 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)) { + if (spec && spec.layout === "auto" && !spec.placement && ["architecture", "flowchart", "schema", "state", "deployment", "schedule"].includes(spec.type)) { try { spec.placement = placeNow(parts, spec); const inner = `\n${JSON.stringify(spec).replace(/ x } } }, console: { warn() {}, error() {}, log() {} } }; - vm.runInNewContext(read(parts, "diagram.js"), context); + // The type modules (DECISIONS 359) register their types with the diagram module, so their figures' words are written here too. + const ctx = vm.createContext(context); + for (const name of ["diagram-scale", "diagram-gantt", "diagram-matrix", "diagram-timeline", "diagram-schedule", "diagram-state", "diagram-deployment"]) if (exists(parts, `${name}.js`)) vm.runInContext(read(parts, `${name}.js`), ctx); + vm.runInContext(read(parts, "diagram.js"), ctx); engine = context.window.Basalt._.diagramMarkup; } let made; diff --git a/tools/html-skill/src/modules.json b/tools/html-skill/src/modules.json index 3a297874..32f74306 100644 --- a/tools/html-skill/src/modules.json +++ b/tools/html-skill/src/modules.json @@ -1,8 +1,9 @@ { "$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). DECISIONS 320 (versions and release notes): the release module is new (budget 15900 at first, usage 2400); topbar, app-shell and tab-bar gain the version link's classes (budgets: topbar 17700 to 19900, app-shell 4300 to 5200 with the rail's tooltip for it, tab-bar 4850 to 5200), their usage caps rising 2900 to 3100, 2600 to 2850 and 2250 to 2400 for its one line each; skillMd rose 12650 to 12800 for the release module's line and .version-link in topbar's. The code review of round 68 adds data-focus-self to the popover module (its Tab walk; budget 4950 to 5600, usage cap 950 to 1100) and logical start and end for its alignment; the release module's header grid and the Sources panel's touch rows take it to 16900. The spacing sweep of round 68 (DECISIONS 326: Copy link's words on the edge, the callout's last change, its reference column, the last release, the touch rows' end and the whole code chip) takes the release module to 17400. The ruling on where a release ends (DECISIONS 331: no padding under the last change in a release, a release-ending fold's hang, an arrived change keeping its padding, the panel holding its first margin, Build details 44 on touch and a closed Fixed panel taking no room) takes it to 19000. The code recheck of round 68 (recheck 5) has the popover's Tab walk follow Safari's own rule (Tab skips links on Apple's WebKit, Option-Tab reaches them): popover 5600 to 5900. The pixel recheck of round 68 has the Sources panel's touch rows keep their 20px lines with the link's box as hit area, space-3 rows and space-6 between two linked values (recheck-pixels 4), and the release's whole header take the arrival's plate: release 19000 to 19600. Merging #127 (stages, DECISIONS 316 and 328) into the versioning branch: both had raised skillMd from 12650 to 12800 for their own module's line, and together they came to 12886; SKILL.md was tightened in its wording (no rule dropped) to stay within 12800. 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). Merging main (#127 and #128) into diagram batch B: skillMd keeps main's 12800 (batch B had raised it to 12950 for its diagram lines); SKILL.md was tightened in its wording to stay within it, no rule dropped; core takes main's 35550.Raised in the repo review (23 Nov 2026; budgets are soft, the owner's word): notifications 12450 to 12700 (a link is written only when relative, http, https or mailto, and side and align are checked before they reach the markup), combobox 11200 to 11350 (a disabled field's hidden input is disabled too, now and later), tooltip 3200 to 3550 (the gap to the opener is the tooltip's own, and hover and keyboard focus each hold it open; WCAG 1.4.13), chart 34750 to 34800 (the scale's step search and gridlines are bounded, so extreme values cannot hang the page), spinner 650 to 720 (its held rule moved in from loops, so a ring-only page keeps a stored hold), kbd 2900 to 2950, palette 11400 to 11500 (and its usage text 1350 to 1400, for the Mod line) and toast 16050 to 16200 (Mod in a palette item's keys is bound as it is drawn, and a toast action's aria-keyshortcuts resolves Mod). The safe-sinks rule (decided by the owner, Fable, Astra and Muse, 23 Nov 2026): skillMd 12650 to 12900, and 13050 with main's own raise merged in (one line: data goes in as textContent, a link passes Basalt.safeHref, an option comes from a fixed list), core 35400 to 35650, and 35800 with main's own raise merged in, and its usage 2950 to 3200 (one safeHref, published as Basalt.safeHref, and _.pick, in place of a copy in each module; esc escapes the apostrophe), link-tabs 5750 to 5900 (a refused link dispatches no event), diagram 92650 to 93000 (a card's mark is a relative path, https or a data: image). Merging #129 into diagram batch B: diagram keeps batch B's 145100 plus #129's mark check, set to its measure, and batch B's usage 4600. The fix round after both reviews of 421348e8 sets them to the measured sizes again: core 38950 to 39600 (every room says all three forms, and a hung word's box grows by a short room's shortfall), search to 5700 (it places its top again on a resize and with the keyboard; an empty list holds no padding), command-list to 14700 (it keeps the taller of its two heights), notifications to 12950 (the bell's edge), pane to 1950 (the page column's room), chart to 34950 (the date line's reason), and code, diagram-zoom, filter, links, sheet, still-table, tab-bar and topbar each by under 150 bytes (the three forms of a room; the selection column's width however given). Merged with main at db0bc418 (#129 to #131), DECISIONS 336's caps are set to the measured sizes again: core 35800 to 38950 and its usage 3200 to 3650, toast 16200 to 16750, terminal to 12700 (13050 with the open items' ruling: both copy buttons draw their three glyphs once, so a refused copy shows the close with no markup written after), diagram-zoom 17600 to 17750 (its viewer's Close and Zoom out hung, and the foot's room). Raised in DECISIONS 336 (reserved room across every component, claude/reserved-room), each to its measured size: core 35550 to 38700 (the edge rule a ghost .btn hangs by at a head, its ring and touch hit area, the side insets by direction, the .panel-head and page section-head that hang their last button by themselves) and its usage 2950 to 3450 (how data-edge and --basalt-edge-room are written); search 4400 to 5200 (search.js, the held top), terminal 11950 to 12550 (the close glyph for a refused copy, the edge on both copies), links 2750 to 3300 (the first icon link hung, the card room, the 20px glyph), toast 16050 to 16650 (the 46px hit areas on touch), selection 1500 to 1650 and still-table 14650 to 15000 (the 44px select column), command-list 14000 to 14350 (the panel hugs, the room is page), menu 8950 to 9150 (the column every row keeps when any row has a check or a glyph), notifications 12450 to 12600, filter 17500 to 17600, forms 3500 to 3550, sheet 5400 to 5450, topbar-nav 7550 to 7600 and app-shell 5200 to 5250 (logical sides, the edge and the room); topbar's usage 3100 to 3200 (a bar's last ghost control takes data-edge); command-list's usage 2150 to 2300 (the panel hugs; the room is page, and only on the page); dialog-form's usage 1300 to 1350 (its Close is written data-icon-only data-edge=\"end\"). Raised in the polish ruling of 336 (the selection box keeps to the cell's line): selection 1650 to 1750 (the box's start margin, min(space-4, half the spare room): 1710 measured) and its usage 1150 to 1350 (the rule's sentence: 1313 measured). Merging main (#130, #131) into claude/diagram-interop: diagram usage 4600 to 4850 (+5.4%: Batch B's diagram usage plus the basalt-diagram-export rule line, measured 4806), then 4850 to 5050 (noting that .lucid is for Lucid's REST API only and to use .vsdx in Lucid's UI, measured 4999). Raised for right to left (diagrams-rtl): diagram 145450 to 146000 (the stacked figure mirrors, its snap and whole-pixel labels with it; a drawn schema takes its turn-backs, its one-column room and its gutter lanes from the end side); then 146000 to 148000 for Fable's ruling on the stacked group label (the stem gives way, the label slides, the last resort's warning) and the author's strings isolated in ). Raised in the first tab (DECISIONS 358): tabs 3700 to 4600 (the scrollport and its hang, the divider as ::before, the underline's inset, the scroll margin, and the script that wraps the row and brings a focused tab into view: 4524 measured), link-tabs 5900 to 6350 (the hang and the divider as ::before: 6276 measured), tabs usage 750 to 1150 (the .tabs-scroll wrapper in the markup and the sentence on the scrollport, the hang and the underline: 1111 measured) and link-tabs usage 2550 to 2750 (the hang and the underline's width: 2702 measured). The pause toggle's held look (DECISIONS 361): toggle 1950 to 2400 (a seat whose glyph has a selected form draws both forms in one box with no check, and the hold's icon-only toggle crossfades between its two drawings: 2386 measured) and glyph 1950 to 2100 (the pair and the seat a toggle draws, shared with loops and diagram-motion: 2098 measured). Raised on claude/diagram-actions (diagrams-cimip's foot decision and its two rulings; budgets are soft, the reason recorded here): diagram 148000 to 148700 (main was already 148204 after #142; the one-column cap in the engine and its CSS, the foot out of print, and Clear highlight mounting before a download's note), diagram-zoom 17800 to 18000 (the viewer's end group wrapping from the start edge, the drawing's own box for Fit, the sizer's clip), diagram-export 10450 to 12850 (main was already 11147; the export of a hidden viewer drawing, the rejection of a figure with no box, and the refused-PNG note with its CSS), and the usage caps diagram 5050 to 5100 and diagram-export 700 to 760 for the rulings' words.", "budgets": { - "skillMd": 13050, - "core": 39600 + "skillMd": 13900, + "core": 39600, + "skillMdReason": "DECISIONS 359 (diagram batch D, wave 1): 13049 to 13549 bytes for the four index lines of the new type modules (diagram-scale, diagram-gantt, diagram-matrix, diagram-timeline). Cap 13050 to 13600. Then 13549 to about 13790 for three more lines (diagram-schedule, diagram-state, diagram-deployment: the split that keeps the diagram module's growth for the types a page draws). Cap 13600 to 13900." }, "core": { "classes": [ @@ -746,9 +747,12 @@ "diagram-actor", "diagram-arrow", "diagram-band", + "diagram-bar", "diagram-cast", + "diagram-clear", "diagram-cname", "diagram-code", + "diagram-crow", "diagram-ctype", "diagram-detail", "diagram-diamond", @@ -756,8 +760,15 @@ "diagram-drawing", "diagram-edge", "diagram-entry", + "diagram-fbox", + "diagram-felse", + "diagram-fhead", "diagram-fk-mark", + "diagram-flabel", "diagram-foot", + "diagram-frame", + "diagram-ftab", + "diagram-fword", "diagram-gbox", "diagram-glabel", "diagram-group", @@ -765,6 +776,7 @@ "diagram-hint", "diagram-ink", "diagram-key", + "diagram-key-glyph", "diagram-key-letters", "diagram-keyseat", "diagram-kind", @@ -774,6 +786,7 @@ "diagram-lane-word", "diagram-legend", "diagram-life", + "diagram-lifes", "diagram-line", "diagram-list", "diagram-list-exits", @@ -781,19 +794,24 @@ "diagram-list-head", "diagram-list-items", "diagram-mark", + "diagram-meta", + "diagram-meta-first", "diagram-mlabel", "diagram-more", "diagram-msg", "diagram-msgs", "diagram-name", + "diagram-name-end", "diagram-node", "diagram-note", "diagram-num", + "diagram-ring", "diagram-route", "diagram-row", "diagram-rows", "diagram-ruler", "diagram-run", + "diagram-runs", "diagram-said", "diagram-source", "diagram-steps", @@ -801,11 +819,18 @@ "diagram-svg", "diagram-swatch", "diagram-swatch-shape", + "diagram-tap-hint", + "diagram-text", + "diagram-text-ink", "diagram-th", "diagram-tip", "diagram-title", "diagram-tname", + "diagram-to", "diagram-toggle", + "diagram-tx-line", + "diagram-tx-name", + "diagram-tx-to", "diagram-words" ], "attrs": [ @@ -821,11 +846,13 @@ "art", "kbd" ], - "budget": 148700, - "usage": 5100, + "budget": 156400, + "usage": 5900, "builds": [ "kbd" - ] + ], + "usageReason": "DECISIONS 359: 5100 to 5900 for one line naming the new shapes of data (state, deployment, schedule, a dependency figure, a data flow's decision) and the type modules that draw the rest.", + "budgetReason": " DECISIONS 359 (diagram batch D, wave 1): 148204 to 155366 bytes (+7162, +4.8%): the type-module seam, the isolates on every author string, the dependency and swimlane folds and their CSS. The schedule, the state and the deployment are modules of their own (diagram-schedule, diagram-state, diagram-deployment), so a page pays for the types it draws. Cap 148700 to 155500. The run-edge ruling (run-edge/ruling.md): 155394 to 156279 bytes (+885) for the clear band beside a box's edge, the refusal under space-2 a lane and the row a box starts on standing space-4 lower; cap 155500 to 156400, the owner deciding the gate's raise." }, "diagram-motion": { "classes": [ @@ -917,6 +944,234 @@ "budget": 5450, "usage": 700 }, + "diagram-scale": { + "text": [ + "\"type\"\\s*:\\s*\"(?:gantt|timeline)\"" + ], + "textWords": [ + "a diagram's \"type\": \"gantt\" or \"timeline\"" + ], + "requires": [ + "diagram" + ], + "budget": 4700, + "usage": 300, + "budgetReason": "DECISIONS 359: a new module, 4560 bytes at its first build; cap 4700." + }, + "diagram-gantt": { + "classes": [ + "diagram-gantt-after", + "diagram-gantt-axis", + "diagram-gantt-bar", + "diagram-gantt-corner", + "diagram-gantt-grid", + "diagram-gantt-mile", + "diagram-gantt-now", + "diagram-gantt-phase", + "diagram-gantt-range", + "diagram-gantt-row", + "diagram-gantt-scale", + "diagram-gantt-tick", + "diagram-gantt-today", + "diagram-gantt-track", + "diagram-gantt-words", + "diagram-swatch-bar", + "diagram-today" + ], + "text": [ + "\"type\"\\s*:\\s*\"gantt\"" + ], + "textWords": [ + "a diagram's \"type\": \"gantt\"" + ], + "requires": [ + "diagram", + "diagram-scale" + ], + "budget": 18400, + "usage": 1250, + "budgetReason": "DECISIONS 359: a new module, 17961 bytes at its first build; The first review round's fixes: 18297 bytes; cap 18400." + }, + "diagram-matrix": { + "classes": [ + "diagram-bp-body", + "diagram-bp-cell", + "diagram-bp-head", + "diagram-bp-layer", + "diagram-bp-rule", + "diagram-bp-rule-line", + "diagram-bp-rule-name", + "diagram-bp-stage", + "diagram-bp-time", + "diagram-bp-to", + "diagram-empty", + "diagram-journey-cell", + "diagram-journey-cell-label", + "diagram-journey-cut", + "diagram-journey-disc", + "diagram-journey-grid", + "diagram-journey-head", + "diagram-journey-level", + "diagram-journey-levels", + "diagram-journey-line", + "diagram-journey-plot", + "diagram-journey-slot", + "diagram-journey-stage", + "diagram-journey-track", + "diagram-journey-value", + "diagram-journey-word", + "diagram-kanban-blocked", + "diagram-kanban-card", + "diagram-kanban-cards", + "diagram-kanban-col", + "diagram-kanban-count", + "diagram-kanban-head", + "diagram-kanban-more", + "diagram-kanban-note", + "diagram-kanban-title", + "diagram-kanban-top", + "diagram-matrix-label", + "diagram-matrix-rule", + "diagram-meta", + "diagram-meta-first", + "diagram-story-activity", + "diagram-story-backbone", + "diagram-story-card", + "diagram-story-cell", + "diagram-story-code", + "diagram-story-count", + "diagram-story-cut", + "diagram-story-cut-line", + "diagram-story-cut-name", + "diagram-story-left-out", + "diagram-story-of", + "diagram-story-slice", + "diagram-story-slice-head", + "diagram-story-slice-name", + "diagram-story-slot", + "diagram-story-step", + "diagram-story-steps", + "diagram-swatch-blocked", + "diagram-swatch-contour", + "diagram-swatch-dash", + "diagram-swatch-rule", + "diagram-swatch-slot" + ], + "text": [ + "\"type\"\\s*:\\s*\"(?:kanban|journey|service-blueprint|story-map)\"" + ], + "textWords": [ + "a diagram's \"type\": \"kanban\", \"journey\", \"service-blueprint\" or \"story-map\"" + ], + "requires": [ + "diagram" + ], + "budget": 47300, + "usage": 1500, + "budgetReason": "DECISIONS 359: a new module, 46948 bytes at its first build; The first review round's fixes: 47178 bytes; cap 47300." + }, + "diagram-timeline": { + "classes": [ + "diagram-tl-axis", + "diagram-tl-break", + "diagram-tl-break-text", + "diagram-tl-break-words", + "diagram-tl-card", + "diagram-tl-dot", + "diagram-tl-gap", + "diagram-tl-line", + "diagram-tl-slash", + "diagram-tl-stem", + "diagram-tl-tick", + "diagram-tl-tick-text", + "diagram-tl-time", + "diagram-tl-zone" + ], + "text": [ + "\"type\"\\s*:\\s*\"timeline\"" + ], + "textWords": [ + "a diagram's \"type\": \"timeline\"" + ], + "requires": [ + "diagram", + "diagram-scale" + ], + "budget": 18700, + "usage": 800, + "budgetReason": "DECISIONS 359: a new module, 18264 bytes at its first build; The first review round's fixes: 18508 bytes; cap 18700." + }, + "diagram-schedule": { + "classes": [ + "diagram-sched-after", + "diagram-sched-cell", + "diagram-sched-contour", + "diagram-sched-critical", + "diagram-sched-dur", + "diagram-sched-foot", + "diagram-sched-grid", + "diagram-sched-head", + "diagram-sched-k", + "diagram-sched-v", + "diagram-swatch-task" + ], + "text": [ + "\"type\"\\s*:\\s*\"schedule\"" + ], + "textWords": [ + "a diagram's \"type\": \"schedule\"" + ], + "requires": [ + "diagram" + ], + "budget": 13600, + "usage": 600, + "budgetReason": "DECISIONS 359: a new module, 13431 bytes at its first build; cap 13600." + }, + "diagram-state": { + "classes": [ + "diagram-actions", + "diagram-final", + "diagram-start", + "diagram-start-dot", + "diagram-start-line", + "diagram-start-tip" + ], + "text": [ + "\"type\"\\s*:\\s*\"state\"" + ], + "textWords": [ + "a diagram's \"type\": \"state\"" + ], + "requires": [ + "diagram" + ], + "budget": 11100, + "usage": 600, + "budgetReason": "DECISIONS 359: a new module, 10283 bytes at its first build; cap 10400. The ruling on the gap (state-gap/ruling.md): 10283 to 10969 bytes, for a composite's start mark above its initial state, its row's room, and the mark that never lies on a line, a label or another mark (else the figure is stacked). Cap 10400 to 11100." + }, + "diagram-deployment": { + "classes": [ + "diagram-artifact", + "diagram-artifact-detail", + "diagram-artifact-name", + "diagram-host-head", + "diagram-host-rows", + "diagram-replicas" + ], + "text": [ + "\"type\"\\s*:\\s*\"deployment\"" + ], + "textWords": [ + "a diagram's \"type\": \"deployment\"" + ], + "requires": [ + "diagram" + ], + "budget": 6700, + "usage": 600, + "budgetReason": "DECISIONS 359: a new module, 6558 bytes at its first build; cap 6700." + }, "sparkline": { "classes": [ "sparkline", diff --git a/tools/html-skill/src/modules/diagram-deployment.js b/tools/html-skill/src/modules/diagram-deployment.js new file mode 100644 index 00000000..cc0a0471 --- /dev/null +++ b/tools/html-skill/src/modules/diagram-deployment.js @@ -0,0 +1,10 @@ +/* Basalt HTML script, diagram-deployment module: a diagram whose JSON says "type": "deployment" (DECISIONS 359, Ops 3), read as an architecture and routed by the engine, is drawn by React's own module (packages/react/src/diagram-deployment.ts), bundled here + by build.mjs. It registers its type with the diagram module and does nothing else at load. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-deployment.js (do not edit the copy in the skill folder). */ +import { deploymentType } from "../../../../packages/react/src/diagram-deployment.ts"; + +(function (B) { + 'use strict'; + var _ = B._; + (_.diagramTypes = _.diagramTypes || {}).deployment = deploymentType; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram-gantt.js b/tools/html-skill/src/modules/diagram-gantt.js new file mode 100644 index 00000000..844d55ab --- /dev/null +++ b/tools/html-skill/src/modules/diagram-gantt.js @@ -0,0 +1,11 @@ +/* Basalt HTML script, diagram-gantt module (DECISIONS 359, Planning 1.1): a diagram whose JSON says "type": "gantt" is drawn by React's own gantt + (packages/react/src/diagram-gantt.ts), bundled here by build.mjs with the scale read from the diagram-scale module. It registers its type with the diagram + module and does nothing else at load. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-gantt.js (do not edit the copy in the skill folder). */ +import { ganttType } from "../../../../packages/react/src/diagram-gantt.ts"; + +(function (B) { + 'use strict'; + var _ = B._; + (_.diagramTypes = _.diagramTypes || {}).gantt = ganttType; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram-matrix.js b/tools/html-skill/src/modules/diagram-matrix.js new file mode 100644 index 00000000..19b11f7b --- /dev/null +++ b/tools/html-skill/src/modules/diagram-matrix.js @@ -0,0 +1,15 @@ +/* Basalt HTML script, diagram-matrix module (DECISIONS 359, Planning 1.0 and 1.2 to 1.5): a diagram whose JSON says "type": "kanban", "journey", + "service-blueprint" or "story-map" is drawn by React's own matrix core (packages/react/src/diagram-matrix.ts), bundled here by build.mjs. It registers the + four types with the diagram module and does nothing else at load. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-matrix.js (do not edit the copy in the skill folder). */ +import { journeyType, kanbanType, serviceBlueprintType, storyMapType } from "../../../../packages/react/src/diagram-matrix.ts"; + +(function (B) { + 'use strict'; + var _ = B._; + var types = _.diagramTypes = _.diagramTypes || {}; + types.kanban = kanbanType; + types.journey = journeyType; + types['service-blueprint'] = serviceBlueprintType; + types['story-map'] = storyMapType; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram-scale.js b/tools/html-skill/src/modules/diagram-scale.js new file mode 100644 index 00000000..897e708d --- /dev/null +++ b/tools/html-skill/src/modules/diagram-scale.js @@ -0,0 +1,10 @@ +/* Basalt HTML script, diagram-scale module (DECISIONS 359, the answers' section 3): the time scale a gantt and a timeline share, and nothing else: plain + arithmetic, React's own (packages/react/src/diagram-scale.ts), bundled here by build.mjs. Added for you with diagram-gantt or diagram-timeline; a page pays + for the type it draws, and the layout of each is its own module. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-scale.js (do not edit the copy in the skill folder). */ +import * as scale from "../../../../packages/react/src/diagram-scale.ts"; + +(function (B) { + 'use strict'; + B._.diagramScale = scale; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram-schedule.js b/tools/html-skill/src/modules/diagram-schedule.js new file mode 100644 index 00000000..ddd1a0bf --- /dev/null +++ b/tools/html-skill/src/modules/diagram-schedule.js @@ -0,0 +1,10 @@ +/* Basalt HTML script, diagram-schedule module: a diagram whose JSON says "type": "schedule" (DECISIONS 359, Planning 1.6), routed by the engine, is drawn by React's own module (packages/react/src/diagram-schedule.ts), bundled here + by build.mjs. It registers its type with the diagram module and does nothing else at load. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-schedule.js (do not edit the copy in the skill folder). */ +import { scheduleType } from "../../../../packages/react/src/diagram-schedule.ts"; + +(function (B) { + 'use strict'; + var _ = B._; + (_.diagramTypes = _.diagramTypes || {}).schedule = scheduleType; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram-state.js b/tools/html-skill/src/modules/diagram-state.js new file mode 100644 index 00000000..85b1421d --- /dev/null +++ b/tools/html-skill/src/modules/diagram-state.js @@ -0,0 +1,10 @@ +/* Basalt HTML script, diagram-state module: a diagram whose JSON says "type": "state" (DECISIONS 359, Ops 1), read as an architecture and routed by the engine, is drawn by React's own module (packages/react/src/diagram-state.ts), bundled here + by build.mjs. It registers its type with the diagram module and does nothing else at load. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-state.js (do not edit the copy in the skill folder). */ +import { stateType } from "../../../../packages/react/src/diagram-state.ts"; + +(function (B) { + 'use strict'; + var _ = B._; + (_.diagramTypes = _.diagramTypes || {}).state = stateType; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram-timeline.js b/tools/html-skill/src/modules/diagram-timeline.js new file mode 100644 index 00000000..a2afcf55 --- /dev/null +++ b/tools/html-skill/src/modules/diagram-timeline.js @@ -0,0 +1,11 @@ +/* Basalt HTML script, diagram-timeline module (DECISIONS 359, Ops 2): a diagram whose JSON says "type": "timeline" is drawn by React's own timeline and its + seats (packages/react/src/diagram-timeline.ts, diagram-timeline-seat.ts), bundled here by build.mjs with the scale read from the diagram-scale module. It + registers its type with the diagram module and does nothing else at load. The implementation hasn't been reviewed. + Source: tools/html-skill/src/modules/diagram-timeline.js (do not edit the copy in the skill folder). */ +import { timelineType } from "../../../../packages/react/src/diagram-timeline.ts"; + +(function (B) { + 'use strict'; + var _ = B._; + (_.diagramTypes = _.diagramTypes || {}).timeline = timelineType; +})(window.Basalt); diff --git a/tools/html-skill/src/modules/diagram.js b/tools/html-skill/src/modules/diagram.js index 6b076709..fc67efc3 100644 --- a/tools/html-skill/src/modules/diagram.js +++ b/tools/html-skill/src/modules/diagram.js @@ -4,13 +4,21 @@ 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, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, moveStop, placeLabels, settleEntrance, syncAttributes, toHtml } from "../../../../packages/react/src/diagram-core.ts"; +import { applyTrace, autoType, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, moveStop, placeLabels, settleEntrance, syncAttributes, toHtml } from "../../../../packages/react/src/diagram-core.ts"; (function (B) { 'use strict'; var _ = B._; var P = 'diagram'; var serial = 0; + // The types a module of their own draws (DECISIONS 359): each registers its maker here (diagram-gantt, diagram-matrix, diagram-timeline, diagram-schedule, + // diagram-state, diagram-deployment), so a page pays for the types it draws. A spec takes its type's module on `ext`, never a value from the page's JSON. + var types = _.diagramTypes = _.diagramTypes || {}; + function typed(spec) { + var make = Object.prototype.hasOwnProperty.call(types, spec.type) ? types[spec.type] : null; + var ext = typeof make === 'function' ? make() : undefined; + return spec.ext === ext ? spec : Object.assign({}, spec, { ext: ext }); + } function options(base, spec, viewer) { return { prefix: P, base: base, hasSource: spec.source !== undefined && spec.source !== null && spec.source !== '', hiddenClass: 'visually-hidden', viewer: viewer ? viewer.keys : undefined }; @@ -27,9 +35,10 @@ 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) { + spec = typed(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 auto = spec.layout === 'auto' && autoType(spec.type); 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; @@ -42,8 +51,8 @@ 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-marks', 'data-layout', 'data-measured', 'data-bare']; - var OWN_STYLE = ['--_cols', '--_gpad', '--_track']; + var OWN = ['aria-labelledby', 'data-type', 'data-cols', 'data-reach', 'data-gutter', 'data-marks', 'data-layout', 'data-measured', 'data-bare', 'data-form', 'data-contour']; + var OWN_STYLE = ['--_cols', '--_gpad', '--_track', '--_name', '--_lab', '--_tw', '--_th', '--_tdw']; /** * Draws a figure. `attach` is the page's own wiring: a figure compose.mjs already wrote is measured as it is. Otherwise (a figure with no @@ -52,11 +61,12 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, */ function draw(figure, spec, attach, viewer) { if (figure.__diagram) figure.__diagram.stop(); + spec = typed(spec); 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 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 auto = spec.layout === 'auto' && autoType(spec.type); 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']; @@ -107,7 +117,8 @@ import { applyTrace, tapTrace, buildModel, entranceDrawn, escapeHtml, figureKey, // 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 !== ''; + // A type of its own with no lines (a gantt, a matrix, a timeline) has no trace on touch, and so no "Clear highlight" (DECISIONS 359). + var want = touched && !viewer && ink && ink.innerHTML !== '' && (!model.ext || Boolean(ink.querySelector('.diagram-edge'))); figure.toggleAttribute('data-touch', Boolean(touched && !viewer)); if (want && !clearBtn) { var foot = figure.querySelector(':scope > .diagram-foot'); diff --git a/tools/html-skill/src/usage/diagram-deployment.md b/tools/html-skill/src/usage/diagram-deployment.md new file mode 100644 index 00000000..15c8f3d3 --- /dev/null +++ b/tools/html-skill/src/usage/diagram-deployment.md @@ -0,0 +1,4 @@ +# diagram-deployment + +Added for you when a diagram's JSON says `"type": "deployment"`: `environment` (required, one a figure, "Production · us-east-1"), `nodes` (hosts, with +`replicas` as a number and `artifacts`: `{ id, name, detail }` rows a line may name), `groups` (two levels drawn yet), and `edges`, each with a label. diff --git a/tools/html-skill/src/usage/diagram-gantt.md b/tools/html-skill/src/usage/diagram-gantt.md new file mode 100644 index 00000000..a4322ed2 --- /dev/null +++ b/tools/html-skill/src/usage/diagram-gantt.md @@ -0,0 +1,15 @@ +# diagram-gantt + +Added for you when a diagram's JSON says `"type": "gantt"`. + +``` +{ "type": "gantt", "title": "…", "summary": "…", "today": "2026-11-24", "legend": { "focal": "The release" }, + "phases": [{ "id": "build", "label": "Build" }], + "tasks": [{ "id": "a", "name": "Sandbox images", "start": "2026-11-02", "end": "2026-11-09", "phase": "build" }, + { "id": "b", "name": "Cut-over", "start": "2026-11-20", "milestone": true, "after": ["a"], "focal": true }] } +``` + +- A row a task on one time scale. `start` and `end` are days (`YYYY-MM-DD`, the end inclusive) or numbers with a `unit` (`"min"`, or `{ "one": "week", "other": "weeks" }`). A milestone has a `start` and no `end`. +- No dependency line is drawn: `after` is written in the row ("After: …"). Never write a count or a length by hand; the engine writes "8 days". +- A bar is never widened: where the shortest bar would be under 8px the bars go and the words stay (a 1-day task in a 90-day plan on a phone). More than 512 times the shortest bar is never drawn: make the short task a milestone or split the chart. +- `today` is drawn only inside the plan. `todayLabel` and `labels` replace the built-in words. diff --git a/tools/html-skill/src/usage/diagram-matrix.md b/tools/html-skill/src/usage/diagram-matrix.md new file mode 100644 index 00000000..caf0ca6f --- /dev/null +++ b/tools/html-skill/src/usage/diagram-matrix.md @@ -0,0 +1,10 @@ +# diagram-matrix + +Added for you when a diagram's JSON says `"type": "kanban"`, `"journey"`, `"service-blueprint"` or `"story-map"`. Equal tracks, the fit measured on the +words; below it, one column. An empty cell says so in words. + +- **kanban:** `columns` (`id`, `label`, `limit`, `more`: cards not drawn, counted, `note`) and `cards` (`id`, `column`, `name`, `kind`, `detail`, `blocked`: its reason, `focal`). A count of cards at one moment: read-only, nothing drags. The count is written for you ("3, max 2 · Over limit"). +- **journey:** `actor` and `scenario` (both required), `scale`: five words lowest first, your own ("Blocked" … "Confident"), `stages` (`id`, `name`, `level` 1 to 5, `actions`, `quote`, `touchpoint`, `friction`, `opportunity`), `legend.line` (required: what the scale measures). +- **service-blueprint:** `stages` (`id`, `name`, `time`), `cells` (`stage`, `layer`: `evidence`, `customer`, `frontstage`, `backstage` or `support`, `name`, `detail`), `arrows` (optional, `main` or `plain`, never dashed: two cells of one stage, or neighbouring stages of one layer). The three rules are drawn for you. +- **story-map:** `persona`, `activities` (`id`, `name`, `steps`), `slices` (`id`, `label`, first to ship first), `stories` (`id`, `activity`, `slice`, `name`, `kind`), and one `cut`: `{ "after": "slice-id", "label": "…" }`. +- `labels` replaces any built-in word. One part at most is `focal`, with `legend.focal`. diff --git a/tools/html-skill/src/usage/diagram-scale.md b/tools/html-skill/src/usage/diagram-scale.md new file mode 100644 index 00000000..290a3405 --- /dev/null +++ b/tools/html-skill/src/usage/diagram-scale.md @@ -0,0 +1,4 @@ +# diagram-scale + +Added for you with a gantt or a timeline (`"type": "gantt"` or `"timeline"`): the time scale the two share, arithmetic alone. It draws nothing; each type's +layout is its own module, so a page pays for the type it draws. diff --git a/tools/html-skill/src/usage/diagram-schedule.md b/tools/html-skill/src/usage/diagram-schedule.md new file mode 100644 index 00000000..16b68f53 --- /dev/null +++ b/tools/html-skill/src/usage/diagram-schedule.md @@ -0,0 +1,5 @@ +# diagram-schedule + +Added for you when a diagram's JSON says `"type": "schedule"`: `unit` (one for every duration, `"min"` or `{ "one": "day", "other": "days" }`), and `tasks` with +`id`, `name`, `kind` ("T3"), `duration`, `after` (ids), and `col` and `row` as an architecture card's, or `"layout": "auto"`. Never write a number: early and late +starts and finishes, float, the critical paths and which line is main are computed. The focal task's words never say "critical". diff --git a/tools/html-skill/src/usage/diagram-state.md b/tools/html-skill/src/usage/diagram-state.md new file mode 100644 index 00000000..1809925f --- /dev/null +++ b/tools/html-skill/src/usage/diagram-state.md @@ -0,0 +1,6 @@ +# diagram-state + +Added for you when a diagram's JSON says `"type": "state"`: `nodes` (states, with `initial`, `final`, `entry`, `exit` and `group`), `groups` (composite +states), and `edges` with `event`, `guard` and `action`, never a `label`: the engine writes it, the event on the first line and `[guard] / action` on the +second, each line 28 characters at most. Transitions that leave one state on one event are numbered in the order tried. A line to a composite state is +not drawn yet. diff --git a/tools/html-skill/src/usage/diagram-timeline.md b/tools/html-skill/src/usage/diagram-timeline.md new file mode 100644 index 00000000..944472a8 --- /dev/null +++ b/tools/html-skill/src/usage/diagram-timeline.md @@ -0,0 +1,9 @@ +# diagram-timeline + +Added for you when a diagram's JSON says `"type": "timeline"`. + +- `events`: `id`, `at` (an ISO 8601 instant with its offset, `"2026-11-24T14:03:00Z"`), `name`, `kind`, `detail`, `focal`. Points only: a span is a gantt's bar. +- `timeZone` (an IANA name, default `"UTC"`): every time is written in it, 24-hour, by the engine. Never write a time or a gap by hand. +- `domain`: `["from", "to"]`, used as written; left out, the events' extent rounded out to ticks. +- `breaks`: `[{ "from", "to", "label" }]`, your own and never the engine's: a gap in the scale, its length written for you ("31 min · soak"). +- A card is at its time or the figure is stacked (each card then writes the gap since the one before). diff --git a/tools/html-skill/src/usage/diagram.md b/tools/html-skill/src/usage/diagram.md index 6394e28a..4f21cbab 100644 --- a/tools/html-skill/src/usage/diagram.md +++ b/tools/html-skill/src/usage/diagram.md @@ -17,6 +17,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`; `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`). +- **More shapes:** `state` (`nodes` with `initial`, `final`, `entry`, `exit` and `group`; `edges` with `event`, `guard`, `action` and no `label`: the engine writes it); `deployment` (`environment`, required; `nodes` with `replicas` and `artifacts`: rows a line may name); `schedule` (`unit`, `tasks` with `kind`, `duration`, `after`, `col`, `row`: its numbers and its main lines are computed). An architecture with `"dependents": { "one": "dependent", "other": "dependents" }` counts each card's dependents and dashes a cycle; a data flow's step may be `"shape": "decision"`. The others have modules of their own: gantt, timeline, kanban, journey, service blueprint, story map. - **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 f153e706aa93dde93c755b3b48da4d05e102c80e Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:20 -0600 Subject: [PATCH 10/12] Foundations and AGENTS.md: the words of DECISIONS 359 (both groups, as revised by the answers, the ruling on the gap and the run-edge ruling) Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 18 ++++++-- docs/foundations.md | 110 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 114 insertions(+), 14 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index cfadc7a3..5a1e025c 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 inside at −2 only where +2 would be cut or would cross a neighbour: a field or band flush with a clipping edge, a sortable header cell (a header band that is itself a button), a phone tab bar cell, a ghost control hung at an edge with less than 4 of room left, 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 + column's edge while the table is scrolled, the app sidebar's 1px edge, a meter's labelled target tick, a time scale's tick lines and its labelled today line, the vertical `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, a frame's sides, and a stage list's or run timeline's connector (1px between two marks, never filled and never a state). 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 @@ -232,8 +232,20 @@ Basalt has one owner (Bailey) and a design panel of two independent design revie 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. The foot's order is fixed ("View as list", + Groups nest two deep; four end lanes at most. A deployment nests three, and an artifact is a row of its host that a line may land on. + A state's label is the engine's (the event, then `[guard] / action`), guards on one event are numbered in the order tried, a start is a + dot and a final state carries a ring. A timeline is one true scale: a card flies from a straight stem at its time, two lanes a side, or + the figure is stacked with each gap in words; a break in the scale is the author's, with its length written. A dependency figure is an + architecture whose counts, cycle and ranks the engine derives; a swimlane is a data flow, and a decision in it is the diamond with its + step number. Every string an author writes keeps its own order right to left. Six planning types (DECISIONS 359): a gantt (square bars + on one time scale; a bar is never widened, so under `space-2` the bars go and the words stay; no dependency lines, a row writes what it + comes after), a kanban (a read-only count at one moment; over the limit is words, weight and a 2px rule), a journey (one actor, five + named steps, one chart line, every stage writing its level), a service blueprint (three named rules in fixed gaps), a story map (a + backbone, slices, one cut) and a schedule (the architecture router; the numbers are computed; a line is main only where its finish sets + the next start on a critical path). A matrix's fit is measured on its content. An empty cell holds its track and says so. Stacked, a + planning figure keeps every mark that fits, says the rest in words, and its key lists only what is drawn. A contour may say what a part + is (critical, blocked), with its word; it is never a state. 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 (a state's, after its event). Arrow keys are spatial, on tracks. On touch a tap traces and "Clear highlight" clears. The foot's order is fixed ("View as list", "Expand", the run button, "Pause animations", an app's `actions`, "Clear highlight") and it does not print; an app's actions are words-only secondary buttons, never a menu, and follow the figure into the viewer. 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 diff --git a/docs/foundations.md b/docs/foundations.md index ebfab6b2..fa53b965 100644 --- a/docs/foundations.md +++ b/docs/foundations.md @@ -150,7 +150,9 @@ kept as a rule so both themes behave alike (DECISIONS 166). Four text levels wer band. A modal palette whose input is its only focus stop shows none. Against the fills and rim composites it touches the inset ring is 8.0:1 or better in dark and 7.1:1 in light. Outlines survive Windows forced-colours mode; box-shadow rings don't. **No state is ever marked by an outline:** - selected, active, current and pressed never draw one. Focus is a 2px ring at +2 outside the control, drawn inside at −2 + selected, active, current and pressed never draw one. A diagram's contour says what a part is in the data (a flowchart's shape, a + critical task, a blocked card, a backbone activity), always with a word. It is the part's own edge, never a ring added to it, and it is + never selected, active, current or pressed. Focus is a 2px ring at +2 outside the control, drawn inside at −2 only where +2 would be cut or would cross a neighbour: a field or band flush with a clipping edge (the search dialog's band, a flush listbox, an inline-label row), a sortable header cell, a phone tab bar cell, a ghost control hung at an edge whose box ends less than 4 from the edge of its room, and a cut cell of a still table (a focus stop, which shows its own ring after Esc has closed its plate). @@ -1534,7 +1536,7 @@ ruling against the vertical bar is about marks): the 1px divider at a pinned tab 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), a -sequence diagram's lifeline and the activation bar on it, a frame's sides, and a stage list's or a run timeline's connector: a 1px line in `border-input` that joins one stage's +sequence diagram's lifeline and the activation bar on it, a frame's sides, a time scale's tick lines and its labelled today line, and a stage list's or a run timeline's connector: a 1px line in `border-input` that joins one stage's mark to the next. It is drawn between every two consecutive marks, beside an open detail too, and it never fills, breaks, moves or changes colour with a stage's state: the mark and its word carry the state. A rail's links are horizontal and are not on this list; they fill as their stage passes, repeating the check before them. A connector is never drawn without both its nodes and its head, and neither is ever a mark of state. @@ -1753,15 +1755,22 @@ Widths the prototype set by hand are derived from tokens, with no new one: a mar ## Diagrams -Boxes and the lines between them, in five types: architecture, flowchart, data flow, sequence and database schema (DECISIONS 281; the -owner's prototype, one draft, a check and a decision, revised after the final positions by DECISIONS 282). The components are -`ArchitectureDiagram`, `FlowchartDiagram`, `DataFlowDiagram`, `SequenceDiagram` and `SchemaDiagram`, and the HTML skill's `diagram` module. +Boxes and the lines between them, in eight types: architecture, flowchart, data flow, sequence, database schema, state, timeline and +deployment (DECISIONS 281; the owner's prototype, one draft, a check and a decision, revised after the final positions by DECISIONS 282; +DECISIONS 359 for the last three). A dependency figure is an architecture and a swimlane is a data flow. The components are +`ArchitectureDiagram`, `FlowchartDiagram`, `DataFlowDiagram`, `SequenceDiagram`, `SchemaDiagram`, `StateDiagram`, `TimelineDiagram` and +`DeploymentDiagram`, and the HTML skill's `diagram` module. **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. + +Six planning types (DECISIONS 359, decided by the council from two drafts and a check): gantt, kanban, journey, service blueprint, story +map and schedule. The components are `GanttDiagram`, `KanbanDiagram`, `JourneyDiagram`, `ServiceBlueprintDiagram`, `StoryMapDiagram` and +`ScheduleDiagram`. The state, timeline and deployment types and both folds were decided by the council (DECISIONS 359, a handoff). +**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. @@ -1781,6 +1790,11 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b 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). - **The focal node** is inverted: `diagram-focal` under `diagram-focal-ink`, its quiet lines at `opacity-amount`. One at most. The key says what it marks. +- A line of facts about the whole figure (a journey's actor and scenario, a schedule's finish and its assumptions) is under the source: + `text-xs`, its first part 500 in primary ink, the rest secondary. +- A date, a time, a count, a duration and a schedule's number are Geist with tabular figures. Mono stays for a kind and an + identifier: on a kind line the kind is Mono, and a time, a duration or a count that shares the line is Geist. A time scale's tick + labels are `chart-axis` on every type. ### Lines @@ -1797,7 +1811,8 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b - **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, 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 +- **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, but a + state's label, which the engine writes from the transition's event, guard and action, and breaks in one place: after the event), 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 @@ -1833,16 +1848,34 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b stays and reads "Hide the list"). This is the one exception to every edge and label being present at every width; a development build says so. - A name or a label is never cut at any width. +- **A planning figure stacked** keeps every mark its type exists for that fits in one column, says the rest in words, and lists in its key + only what it drew. "Expand" holds the drawn layout. None is the viewer alone at any width. +- **A matrix** (kanban, journey, service blueprint, story map) has equal tracks `space-4` apart. A track's minimum is `size-diagram-node` + or the widest unbreakable thing in any column, a head's count included: the fit is measured, never counted. +- **An empty cell holds its track and says so in words:** "None" in a blueprint or a journey, and in a story map a slot with a 1px + dashed `diagram-structure` contour and "No stories". +- **Dashed means one thing in a type:** a gantt's today line, a kanban's blocked card, a blueprint's lines of interaction, a story + map's empty slot. Nothing is dashed in a journey or a schedule. +- **A gantt's bar is never widened.** Where its shortest bar would be under `space-2` at its true width the track is not drawn: the figure + stacks, and the stack keeps its tracks only while the same holds there. A gantt whose domain is more than 512 times its shortest bar is + never drawn. ### 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'. A group may hold groups, two levels in all; an inner group is `space-4` inside the outer and radius 8. + 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. A box's edge is a line: no run lies on it, and a line with an end outside a box crosses its edge once, at a right angle. A gap's lanes keep its + middle while each is outside the boxes beside it and `space-3` clear of their edges; otherwise they are laid evenly in the clear + band, the part of the gap outside those boxes. A row on which a box starts stands `space-4` lower, so `space-8` is clear above the + box and a lone run there is `space-4` from the card and from the edge. With less than `space-2` a lane the figure is stacked. + A dependency figure (`dependents`) is an architecture: each card's count of dependents is the engine's, a line in a cycle is dashed in + the direction it was written, and automatic layout ranks by longest path from the sources. - **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. 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. +- **Data flow:** lanes are bands ruled apart with the divider, named at the start. A node's kind line is its step number. A step may be a + decision: the flowchart's diamond with its step number inside. Every line that leaves it is labelled, and every step then takes the + contour. One process a figure: a second participant is a sequence or a second figure. - **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. **A bar** on a lifeline (`size-diagram-activation`, the head's fill, a 1px `diagram-structure` @@ -1860,6 +1893,42 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b 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. +- **State:** a state is the node; a composite state is a group. A transition's label is `event`, then `[guard] / action` on a second + line, written by the engine, 28 characters a line. Transitions that leave one state on one event are numbered in the order they are + tried, and the key says so. The start is a plain line from a `size-diagram-head` dot, `space-10` long: before the figure's initial + state on the side the figure reads from, and above a composite's initial state, under its label's band, in every layout. Its room is + added and never taken from a gap: the composite's box is `space-8` plus `space-10` above that row, and the row stands `space-10` + lower. A mark never lies on a line; with no place `space-4` clear of every line's end the figure is stacked; + stacked it has its own `space-8` under a group's label. A final state carries a `space-3-5` ring and dot in its top end corner. + Entry and exit actions are in the card under a rule. No mover: a state figure does not know the current state. +- **Timeline:** points on one linear scale, never even gaps. Each event is a dot (`size-dot`) on the axis and a card that flies from a + straight 1px `diagram-structure` stem at its time, `radius-md` in from the card's start corner, in two lanes above the axis and two + below. Seats are derived, latest first; a timeline with an event that has no seat is stacked. Ticks are at least `size-diagram-node` + apart; a tick's label is Geist with tabular figures in `chart-axis` and gives way only to a stem through it or a break's words. A + card's kind line is its time in Geist, then its kind in Mono. A break in the scale is the author's: a `space-8` gap + with two slashes, and the length left out written under it by the engine. Stacked, a rail joins the marks and each card writes the + gap since the one before. A span is a gantt's. +- **Deployment:** one environment a figure, named in the source line. Groups nest three deep, here only; the inner two are radius 8, + and no line runs through a label at any level. An artifact is a row of its host card, as a schema's column is of its table, and a + line may land on it. `× 3` at the end of a host's kind line, in Geist, says how many copies run. +- **Gantt:** a row a task on one time scale. The names are a `size-diagram-table` column; the scale is inset `space-2` at each end. A bar + is 16 tall, `plate-0` under a 1px `diagram-edge` contour, square at both ends, because its ends are its dates. A milestone is a diamond + of the same ink on its day. Tick lines are `chart-grid`; today is a 1px dashed `diagram-structure` line, named above the axis. No + dependency line is drawn: a row writes what it comes after. +- **Kanban:** a count of cards in states at one moment, and read-only: nothing drags. A head is its title and its count in words ("3, max + 2 · Over limit"), every card counted, the heads in one row. Over its limit a column's count is 600 and its rule 2px. A blocked card says + "Blocked" and its reason and has a dashed contour. +- **Journey:** one actor, one scenario, and a scale of five steps the author names. Each stage's head writes its level. The line is the + chart's: straight, 2px, one ink, an 8px disc a stage. Stacked it is a strip over the stage cards. +- **Service blueprint:** stages across, five layers down, and three rules in fixed gaps, each named on the rule: the lines of interaction + and internal interaction dashed 4 on 4 in `diagram-structure`, the line of visibility 2px solid. Stacked, all three are inside every + stage. An empty cell is the word "None" with no box. Arrows are optional, main or plain, straight or through a gutter, and + unlabelled. +- **Story map:** a backbone of activities (a contour, never inverted) with their steps, slices down, and one release cut: a 2px rule after + the slice it names. +- **Schedule:** a network on the architecture router, placed as an architecture is. Its numbers are computed. A task's contour is its + kind: 2px for a critical task, 1px for one with float, each with its word. A line is main only where its finish sets the next task's + start on a critical path. Stacked it is its cards in the author's order, each writing what it comes after and which sets its start. ### The key, the summary and the list @@ -1868,6 +1937,12 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b 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. + A state's key shows the start mark ("Starts here"), the final mark ("Ends here") and, where drawn, the order ("Tried in this order: the + first that holds is taken"); a timeline's the event ("An event, at its time") and a break ("Time left out of the scale"); a deployment's + count ("How many copies run"): built in, because they are notation. The words for the planning types' notation are built in and an app + can replace them: a gantt's bar, milestone and today, a kanban's "Over its limit" and "Blocked", a blueprint's three rules, a story map's + backbone, and a schedule's two lines, two contours and "ES, EF: earliest start and finish · LS, LF: latest start and finish". A + journey's line and a story map's cut must have the author's words. - 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 foot** holds the figure's controls in one fixed order, `space-2` apart, wrapping from the start edge: "View as list", "Expand", @@ -1879,7 +1954,7 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b figure it was pressed in. The foot does not print. - 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 stacked unless it is at least its least width (the track minimums and gaps summed, never under 640); a figure of more than six - columns is stacked until script. + columns is stacked until script. A timeline is stacked until script. ### Keyboard, tracing and motion @@ -1898,6 +1973,10 @@ card keeps its owner's colours ([Service marks](#service-marks)). One node may b 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. +- A planning figure is the same one tab stop. A figure with no edges (gantt, kanban, journey, story map, a blueprint without arrows) has + no trace, no tap hint and no "Clear highlight". A schedule's numbers are words in its card and never stops. +- A timeline's arrows are ← and → through the events in time; a hovered or focused card lifts its own stem and dot, and nothing dims. It + has no trace on touch. ### The viewer @@ -2019,11 +2098,16 @@ over its lifeline; a stacked chip draws the mark before the name. 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. +- Forced colours, planning: a bar `Canvas` under `CanvasText`, the focal bar `CanvasText`; tick and level lines drop; the today line, a + dashed rule and an empty slot `GrayText`; the line of visibility, the cut, the over-limit rule, a blocked contour and the journey's line + `CanvasText`; a critical task 2px `CanvasText`. - Print: a figure prints untraced, in its resting ink, and in the light theme whatever the screen shows. The foot does not print: no control is drawn on paper, and the list prints only where the reader opened it. - Right to left: the figure mirrors and its words do not, drawn and stacked (stacked, the rail and the trunk run down the right, a branch is indented from the right, and the end lines and the end gutter are on the left). Identifiers are isolated left to right as - runs; named sides swap; the arrow keys stay physical; the text art stays left to right. + runs; named sides swap; the arrow keys stay physical; the text art stays left to right. Every string an author writes is a first-strong + isolate, so a line that starts with digits or ends in a mark keeps its order. A timeline mirrors: the earliest event is at the right. +- Right to left, planning: the figure mirrors, drawn and stacked, and a gantt's time runs right to left. - Export: a linked card's arrow is not drawn in a file. A PNG is drawn through an image, so under a content policy `img-src` must allow `blob:` or `data:`; where it allows neither, `diagramToPng` rejects with an error that says so and no file is made (the SVG needs neither). The skill's "Download PNG" then says so in a note under the foot's buttons and is switched off; the console names the `img-src` to allow. @@ -2082,7 +2166,11 @@ theme's input boundary, 1.18), the way the other aliases of that mode are declar **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 (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. +quarter-point slots are rules made of the space scale. So are the gantt's bar height (`space-4`), its floor and its scale inset +(`space-2`), its bound (512), a journey's level pitch (`space-8`; `space-6` in the strip) and the matrix gap (`space-4`); the start stub +(`space-10`), the gap above a row that holds a composite's start mark (`space-16` plus `space-10`), the final mark (`space-3-5`), a state's gaps (`space-16` plus `space-4`, and `space-16`), a deployment's column gap +(`space-16` twice), a timeline's lanes (`space-6` above, `space-10` below, `space-3` between), its break (`space-8`) and its tick +(`space-1-5`). ## Layout From 5b124c2e7cbbfdea98e2131609dadcf90769649c Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:23 -0600 Subject: [PATCH 11/12] Diagrams batch D: the tests, written and not run (DECISIONS 359), and their fixtures The state's figures for the ruling on the gap (laid right on one row and two, a level run above a marked row, a marked group in a marked group) are a fixture of their own. Co-Authored-By: Claude Opus 5.5 --- packages/react/test/diagrams-d1.test.mjs | 335 +++++++ .../react/test/fixtures/diagram-run-edge.json | 698 ++++++++++++++ .../test/fixtures/diagrams-d1-state.json | 305 ++++++ packages/react/test/fixtures/diagrams-d1.json | 888 ++++++++++++++++++ 4 files changed, 2226 insertions(+) create mode 100644 packages/react/test/diagrams-d1.test.mjs create mode 100644 packages/react/test/fixtures/diagram-run-edge.json create mode 100644 packages/react/test/fixtures/diagrams-d1-state.json create mode 100644 packages/react/test/fixtures/diagrams-d1.json diff --git a/packages/react/test/diagrams-d1.test.mjs b/packages/react/test/diagrams-d1.test.mjs new file mode 100644 index 00000000..f9bdffba --- /dev/null +++ b/packages/react/test/diagrams-d1.test.mjs @@ -0,0 +1,335 @@ +// Diagram batch D, wave 1 (DECISIONS 359): the six planning types, state, timeline and deployment, and the dependency and swimlane folds, in React and in +// the HTML skill, from one fixture (test/fixtures/diagrams-d1.json). The Planning decision's tests 1 to 11 and the Ops decision's list. In Chromium against +// the built package. Written while tests are paused (DECISIONS 359): not yet run. The implementation hasn't been reviewed. Margins are kept clear of a +// font's width. +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 * as esbuild from "esbuild"; + +import { compose } from "../../../.agent/skills/basalt-html/compose.mjs"; +import { fixturePage, launch, pkg } from "./support.mjs"; + +const DATA = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "diagrams-d1.json"), "utf8")); +const KEYS = Object.keys(DATA).filter((k) => k !== "$comment"); +const MATRIX = ["kanban", "journey", "blueprint", "storyMap"]; +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}`; + +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +const HOST = ` +import data from "./test/fixtures/diagrams-d1.json"; +const C = { gantt: B.GanttDiagram, kanban: B.KanbanDiagram, journey: B.JourneyDiagram, "service-blueprint": B.ServiceBlueprintDiagram, "story-map": B.StoryMapDiagram, + schedule: B.ScheduleDiagram, timeline: B.TimelineDiagram, state: B.StateDiagram, deployment: B.DeploymentDiagram, architecture: B.ArchitectureDiagram, "data-flow": B.DataFlowDiagram }; +function Host() { + return
{Object.entries(data).filter(([k]) => k !== "$comment").map(([key, d]) => { const { type, ...props } = d; const X = C[type]; return ; })}
; +} +createRoot(document.getElementById("root")).render();`; +const frames = (page, n = 6) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); + +async function reactPage({ width = 1104, theme = "dark", dir, js = true } = {}) { + const { page, errors } = await fixturePage(browser, `window.__width = ${width};${HOST}`, { theme, standards: true, viewport: { width: width + 32, height: 900 }, javaScriptEnabled: js }); + if (dir) await page.evaluate((d) => { document.documentElement.dir = d; }, dir); + await page.addStyleTag({ content: `${FONTS} body{background:var(--basalt-surface-page);margin:0;padding:16px;box-sizing:border-box}` }); + await page.evaluate(() => document.fonts.ready); + await frames(page); + return { page, errors }; +} +/** The skill's page: right to left is the page's own direction before script, as a right-to-left page is. */ +async function skillPage({ width = 1104, theme = "dark", dir, js = true } = {}) { + const body = `Batch D
${KEYS.map((k) => `
`).join("")}
`; + let html = compose(body).html; + if (dir) html = html.replace(/]*)>/, ``); + const context = await browser.newContext({ viewport: { width: width + 32, height: 900 }, colorScheme: theme, javaScriptEnabled: js }); + const page = await context.newPage(); + await context.route("https://basalt.test/**", (route) => route.fulfill({ contentType: "text/html", body: html })); + await page.goto("https://basalt.test/"); + await page.evaluate(() => document.fonts.ready); + await frames(page); + return { page, context }; +} +const ENGINES = [["React", reactPage, "basalt-diagram"], ["the skill", skillPage, "diagram"]]; + +/** Test 1: the figure's width is its scroll width, no text on text, nothing cut, nothing under 12px. */ +const audit = (page, key, P) => page.evaluate(({ key, P }) => { + const fig = document.querySelector(`#fig-${key}`); + const words = [...fig.querySelectorAll(`.${P}-drawing *`)].filter((e) => [...e.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim()) && e.getClientRects().length && getComputedStyle(e).visibility !== "hidden" && !e.closest(`.${P}-ruler`)); + const boxes = words.map((e) => { const r = document.createRange(); r.selectNodeContents(e); return { e, b: r.getBoundingClientRect(), size: parseFloat(getComputedStyle(e).fontSize) }; }).filter((x) => x.b.width > 0); + let overlaps = 0; + for (let i = 0; i < boxes.length; i++) for (let j = i + 1; j < boxes.length; j++) { const a = boxes[i].b, b = boxes[j].b; if (boxes[i].e.contains(boxes[j].e) || boxes[j].e.contains(boxes[i].e)) continue; if (a.left < b.right - 0.5 && b.left < a.right - 0.5 && a.top < b.bottom - 0.5 && b.top < a.bottom - 0.5) overlaps++; } + return { layout: fig.dataset.layout, form: fig.dataset.form, scroll: fig.scrollWidth - fig.clientWidth, overlaps, small: boxes.filter((x) => x.size < 12).length }; +}, { key, P }); + +for (const [name, open, P] of ENGINES) { + describe(`${name}: every type, both forms, both themes (Planning test 1)`, () => { + for (const theme of ["dark", "light"]) for (const width of [1104, 358]) { + test(`${theme} at ${width}: drawn at 1104 and stacked at 358, nothing scrolls, no word on a word, nothing under 12px`, async () => { + const { page } = await open({ width, theme }); + for (const key of KEYS) { + const a = await audit(page, key, P); + assert.equal(a.layout, width === 1104 ? "drawn" : "stacked", key); + assert.equal(a.scroll, 0, key); + assert.equal(a.overlaps, 0, key); + assert.equal(a.small, 0, key); + } + }); + } + test("with scripting off every word is present and the list is open", async () => { + const { page } = await open({ js: false }); + for (const key of KEYS) { + const text = await page.locator(`#fig-${key}`).innerText(); + for (const word of [DATA[key].title]) assert.ok(text.includes(word), key); + } + }); + }); + + describe(`${name}: the matrix fit (Planning tests 2 and 3)`, () => { + test("at each matrix type's own least drawn width and 1px under it the form changes, and no head overflows its track", async () => { + const { page } = await open({ width: 1104 }); + const at = async (key, w) => { await page.evaluate(({ key, w }) => { document.querySelector(`#fig-${key}`).style.width = `${w}px`; }, { key, w }); await frames(page); return (await audit(page, key, P)).layout; }; + for (const key of MATRIX) { + // The least drawn width is read from the figure: the narrowest whole width it draws at, found by halving between 640 and 1104. + let lo = 639, hi = 1104; + assert.equal(await at(key, hi), "drawn", key); + while (hi - lo > 1) { const mid = (lo + hi) >> 1; if ((await at(key, mid)) === "drawn") hi = mid; else lo = mid; } + assert.equal(await at(key, hi), "drawn", `${key} at ${hi}`); + assert.equal(await at(key, hi - 1), "stacked", `${key} at ${hi - 1}`); + await at(key, hi); + const over = await page.evaluate(({ key, P }) => [...document.querySelectorAll(`#fig-${key} :is(.${P}-kanban-head, .${P}-bp-head, .${P}-journey-head, .${P}-story-activity)`)].filter((h) => h.scrollWidth > h.clientWidth + 0.5).length, { key, P }); + assert.equal(over, 0, key); + } + }); + test("kanban: the four head rules share one y, a count is its cards plus more, and no count has a border", async () => { + const { page } = await open({ width: 1104 }); + const got = await page.evaluate((P) => [...document.querySelectorAll(`#fig-kanban .${P}-kanban-head`)].map((h) => ({ y: Math.round(h.getBoundingClientRect().bottom), count: h.querySelector(`.${P}-kanban-count`).textContent, border: getComputedStyle(h.querySelector(`.${P}-kanban-count`)).borderTopStyle })), P); + assert.equal(new Set(got.map((g) => g.y)).size, 1); + assert.deepEqual(got.map((g) => g.count), ["2", "3, max 2 · Over limit", "1, max 3", "8"]); + for (const g of got) assert.equal(g.border, "none"); + }); + }); + + describe(`${name}: the gantt (Planning test 4)`, () => { + test("a bar's width is its duration times the track over the domain, at three widths; no minimum width; no line for after", async () => { + for (const width of [1104, 816, 700]) { + const { page } = await open({ width }); + const got = await page.evaluate((P) => { + const fig = document.querySelector("#fig-gantt"), scale = fig.querySelector(`.${P}-gantt-track > .${P}-gantt-scale`).getBoundingClientRect(); + return { L: scale.width, bars: [...fig.querySelectorAll(`.${P}-gantt-bar`)].map((b) => ({ w: b.getBoundingClientRect().width, min: getComputedStyle(b).minWidth })), lines: fig.querySelectorAll(`.${P}-edge`).length }; + }, P); + // Nov 2 to Dec 3 is 32 days: Sandbox images is 8 of them. + assert.ok(Math.abs(got.bars[0].w - (8 / 32) * got.L) <= 1, `${width}: ${got.bars[0].w}`); + for (const b of got.bars) assert.ok(b.min === "0px" || b.min === "auto"); + assert.equal(got.lines, 0); + } + }); + test("the last milestone is whole, and a figure under the floor is stacked in words with no bar in its key", async () => { + const { page } = await open({ width: 1104 }); + const whole = await page.evaluate((P) => { const f = document.querySelector("#fig-gantt"), d = f.querySelector(`.${P}-drawing`).getBoundingClientRect(), m = f.querySelector(`.${P}-gantt-mile`).getBoundingClientRect(); return m.right <= d.right + 0.5; }, P); + assert.ok(whole); + }); + }); + + describe(`${name}: the journey, the blueprint and the story map (Planning tests 6 to 8)`, () => { + test("the journey's line is one stroke colour through the columns' centres, and nothing answers a tap under 44px", async () => { + const { page } = await open({ width: 1104 }); + const got = await page.evaluate((P) => { const f = document.querySelector("#fig-journey"); const line = f.querySelector(`.${P}-journey-line`); return { stroke: getComputedStyle(line).stroke, lines: f.querySelectorAll(`.${P}-journey-line`).length, small: [...f.querySelectorAll("a[data-node]")].filter((a) => a.getBoundingClientRect().height < 44).length }; }, P); + assert.equal(got.lines, 1); + assert.equal(got.small, 0); + }); + test("the blueprint: no element but the two lines of interaction is dashed, and an empty cell is a stop", async () => { + const { page } = await open({ width: 1104 }); + const got = await page.evaluate((P) => { + const f = document.querySelector("#fig-blueprint"); + const dashed = [...f.querySelectorAll(`.${P}-drawing *`)].filter((e) => e.getClientRects().length && (getComputedStyle(e).borderTopStyle === "dashed" || (getComputedStyle(e).strokeDasharray ?? "none") !== "none")).map((e) => e.closest(`.${P}-bp-rule`)?.dataset.rule ?? e.className.baseVal ?? e.className); + return { dashed: [...new Set(dashed)], empty: f.querySelectorAll(`.${P}-bp-cell[data-empty][tabindex]`).length }; + }, P); + assert.deepEqual(got.dashed.sort(), ["interaction", "internal"]); + assert.ok(got.empty > 0); + }); + test("the story map: an empty cell keeps the next activity's cards in their column", async () => { + const { page } = await open({ width: 1104 }); + const ok = await page.evaluate((P) => { const f = document.querySelector("#fig-storyMap"); const acts = [...f.querySelectorAll(`.${P}-story-activity`)].map((a) => a.getBoundingClientRect()); const card = f.querySelector(`[data-node="s6"]`).getBoundingClientRect(); return Math.abs(card.left - acts[3].left) < 1; }, P); + assert.ok(ok); + }); + }); + + describe(`${name}: the schedule (Planning test 9)`, () => { + test("both tied critical paths draw main, T2 to T5 draws plain, and the stack writes every edge once", async () => { + const { page } = await open({ width: 1104 }); + const main = await page.evaluate((P) => [...document.querySelectorAll(`#fig-schedule .${P}-edge`)].filter((g) => g.querySelector(`.${P}-line[data-kind="main"]`)).length, P); + // t1-t3, t3-t5, t3-t6, t5-t7, t6-t7: the two paths T1 T3 T5 T7 and T1 T3 T6 T7. + assert.equal(main, 5); + assert.ok((await page.locator("#fig-schedule").innerText()).includes("2 critical paths")); + const { page: narrow } = await open({ width: 358 }); + const after = await narrow.evaluate((P) => [...document.querySelectorAll(`#fig-schedule .${P}-sched-after`)].map((a) => a.textContent), P); + assert.deepEqual(after, ["Starts the schedule.", "After T1, which sets its start.", "After T1, which sets its start.", "After T1, which sets its start.", "After T2 and T3. T3 sets its start.", "After T3 and T4. T3 sets its start.", "After T5 and T6. Both set its start."]); + }); + }); + + describe(`${name}: Ops`, () => { + test("a state's label breaks after its event, and guards on one event are numbered", async () => { + const { page } = await open({ width: 1104 }); + const labels = await page.evaluate((P) => [...document.querySelectorAll(`#fig-state .${P}-label`)].map((l) => l.innerText), P); + assert.ok(labels.some((l) => l === "1. tool.call\n[read-only]")); + assert.ok(labels.some((l) => l === "2. tool.call\n[writes]")); + }); + test("a deployment's environment leads its source line, and × 3 is Geist with tabular figures", async () => { + const { page } = await open({ width: 1104 }); + const got = await page.evaluate((P) => { const f = document.querySelector("#fig-deployment"); const r = f.querySelector(`.${P}-replicas`); return { source: f.querySelector(`.${P}-source`).innerText, family: getComputedStyle(r).fontFamily, num: getComputedStyle(r).fontVariantNumeric }; }, P); + assert.ok(got.source.startsWith("Production · us-east-1")); + assert.ok(!/mono/i.test(got.family.split(",")[0])); + assert.equal(got.num, "tabular-nums"); + }); + test("dependents are counted by the engine and the cycle is dashed in the written directions", async () => { + const { page } = await open({ width: 1104 }); + const got = await page.evaluate((P) => ({ api: document.querySelector(`#fig-dependency [data-node="api"] .${P}-detail`).innerText, dashed: [...document.querySelectorAll(`#fig-dependency .${P}-edge`)].filter((g) => g.querySelector(`[data-kind="dashed"]`)).length }), P); + assert.equal(got.api, "3 dependents"); + assert.equal(got.dashed, 2); + }); + test("a decision in a data flow writes its step line inside the diamond", async () => { + const { page } = await open({ width: 1104 }); + const text = await page.locator(`#fig-swimlane [data-node="n2"]`).innerText(); + assert.ok(text.startsWith("Step 2")); + }); + test("a timeline: no stem through a card, a stem at its dot's x, and the faces of its words", async () => { + const { page } = await open({ width: 1104 }); + const got = await page.evaluate((P) => { + const f = document.querySelector("#fig-timeline"), o = f.querySelector(`.${P}-drawing`).getBoundingClientRect(); + const cards = [...f.querySelectorAll(`.${P}-node`)].map((c) => { const r = c.getBoundingClientRect(); return { l: r.left - o.left, r: r.right - o.left, t: r.top - o.top, b: r.bottom - o.top }; }); + const stems = [...f.querySelectorAll(`.${P}-tl-stem`)].map((s) => s.getAttribute("d").match(/M([\d.]+) ([\d.]+)V([\d.]+)/).slice(1).map(Number)); + const through = stems.filter(([x, y1, y2]) => cards.some((c) => x > c.l && x < c.r && Math.max(y1, y2) > c.t + 1 && Math.min(y1, y2) < c.b - 1)).length; + const time = getComputedStyle(f.querySelector(`.${P}-tl-time`)), kind = getComputedStyle(f.querySelector(`.${P}-tl-line`)); + return { through, timeFace: time.fontFamily, timeNum: time.fontVariantNumeric, kindFace: kind.fontFamily }; + }, P); + assert.equal(got.through, 0); + assert.ok(!/mono/i.test(got.timeFace.split(",")[0])); + assert.equal(got.timeNum, "tabular-nums"); + assert.ok(/mono/i.test(got.kindFace)); + }); + test("right to left a digit-led detail keeps its order", async () => { + const { page } = await open({ width: 358, dir: "rtl" }); + const bdi = await page.evaluate((P) => document.querySelector(`#fig-timeline [data-node="e3"] .${P}-detail bdi`)?.textContent, P); + assert.equal(bdi, "28% 504 on /runs"); + }); + }); +} + +describe("size: importing ArchitectureDiagram alone bundles no type module (Planning test 11)", () => { + test("no planning, timeline or scale code is in an architecture's bundle", async () => { + const out = await esbuild.build({ stdin: { contents: `import { ArchitectureDiagram } from "./dist/index.js"; console.log(ArchitectureDiagram);`, resolveDir: pkg, loader: "js" }, bundle: true, write: false, metafile: true, format: "esm", external: ["react", "react-dom", "react/jsx-runtime"], logLevel: "silent" }); + const inputs = Object.keys(out.metafile.inputs); + for (const mod of ["diagram-gantt", "diagram-matrix", "diagram-schedule", "diagram-timeline", "diagram-scale"]) assert.ok(!inputs.some((i) => i.includes(`/${mod}.js`)), mod); + }); +}); + +// The ruling on a state's start mark and the gap (state-gap/ruling.md): written, not run (DECISIONS 359). +const STATE = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "diagrams-d1-state.json"), "utf8")); +async function statePage(figs, { width = 1104, theme = "dark" } = {}) { + const body = `State
${Object.entries(figs).map(([k, d]) => `
`).join("")}
`; + const context = await browser.newContext({ viewport: { width: width + 32, height: 900 }, colorScheme: theme }); + const page = await context.newPage(); + await context.route("https://basalt.test/**", (route) => route.fulfill({ contentType: "text/html", body: compose(body).html })); + await page.goto("https://basalt.test/"); + await page.evaluate(() => document.fonts.ready); + await frames(page); + return page; +} +/** A marked group's box: how far it is from the card above it, how far its top is above its first row, and every start mark's box against the lines. */ +const startRead = (page, key) => page.evaluate((key) => { + const f = document.querySelector(`#fig-${key}`), o = f.querySelector(".diagram-drawing").getBoundingClientRect(); + const rel = (r) => ({ l: r.left - o.left, t: r.top - o.top, r: r.right - o.left, b: r.bottom - o.top }); + const cards = [...f.querySelectorAll(".diagram-node")].map((n) => ({ id: n.dataset.node, ...rel(n.getBoundingClientRect()) })); + const boxes = [...f.querySelectorAll(".diagram-gbox")].map((g) => ({ id: g.dataset.group, ...rel(g.getBoundingClientRect()) })); + const marks = [...f.querySelectorAll(".diagram-start")].map((g) => rel(g.getBoundingClientRect())); + const strokes = [...f.querySelectorAll(".diagram-edge .diagram-line")].map((p) => rel(p.getBoundingClientRect())); + return { layout: f.dataset.layout, cards, boxes, marks, strokes }; +}, key); + +describe("the skill: a composite's start mark and its room", () => { + for (const key of ["right", "rows", "run", "nested"]) { + test(`${key}: a marked group's box is space-8 clear of the card above it and 72 above its first row; no mark lies on a line`, async () => { + const page = await statePage({ [key]: STATE[key] }); + const got = await startRead(page, key); + assert.equal(got.layout, "drawn"); + for (const b of got.boxes) { + const inside = got.cards.filter((c) => c.l >= b.l && c.r <= b.r && c.t >= b.t && c.b <= b.b); + const firstRow = Math.min(...inside.map((c) => c.t)); + const above = got.cards.filter((c) => c.b <= b.t + 1 && c.r > b.l && c.l < b.r); + if (above.length) assert.ok(b.t - Math.max(...above.map((c) => c.b)) >= 32 - 0.5, `${key} ${b.id}: ${b.t - Math.max(...above.map((c) => c.b))} from the card above`); + if (b.id === "active" && key !== "nested") assert.ok(Math.abs(firstRow - b.t - 72) <= 0.5, `${key}: ${firstRow - b.t}`); + } + // Only the mark's own stroke meets its state; no mark's box crosses another line's bounds by more than the stroke it ends on. + for (const mk of got.marks) assert.ok(got.strokes.every((s) => !(mk.l < s.r - 1 && mk.r > s.l + 1 && mk.t < s.b - 1 && mk.b > s.t + 1)), `${key}: a mark on a line`); + }); + } + test("laid down (the fixture): the box is space-8 clear of Idle above it", async () => { + const page = await statePage({ state: DATA.state }); + const got = await startRead(page, "state"); + const box = got.boxes.find((b) => b.id === "active"), idle = got.cards.find((c) => c.id === "idle"); + assert.ok(box.t - idle.b >= 32 - 0.5); + }); + test("a side with no clear place stacks the figure, and the stacked form's parts do not move", async () => { + // Every quarter of Thinking's top is met by a line: the mark has no place, so the figure is stacked. + const crowded = { ...STATE.rows, nodes: STATE.rows.nodes.concat([{ id: "a", name: "A", col: 1, row: 1 }, { id: "b", name: "B", col: 3, row: 1 }]), edges: STATE.rows.edges.concat([{ from: "a", to: "thinking", event: "x", toSide: "top" }, { from: "b", to: "thinking", event: "y", toSide: "top" }]) }; + const page = await statePage({ crowded }); + assert.equal((await startRead(page, "crowded")).layout, "stacked"); + const at390 = await statePage({ rows: STATE.rows }, { width: 358 }); + assert.equal((await startRead(at390, "rows")).layout, "stacked"); + }); +}); + +// The run-edge ruling (run-edge/ruling.md): a box's edge is a line. Written, not run (DECISIONS 359). Turn-backs alone are not in this ruling. +const EDGE = JSON.parse(fs.readFileSync(path.join(pkg, "test", "fixtures", "diagram-run-edge.json"), "utf8")); +const runsAndBoxes = (page, key) => page.evaluate((key) => { + const f = document.querySelector(`#fig-${key}`), o = f.querySelector(".diagram-drawing").getBoundingClientRect(); + const rel = (r) => ({ l: r.left - o.left, t: r.top - o.top, r: r.right - o.left, b: r.bottom - o.top }); + const boxes = [...f.querySelectorAll(".diagram-gbox")].filter((g) => getComputedStyle(g).display !== "none").map((g) => ({ id: g.dataset.group, ...rel(g.getBoundingClientRect()) })); + const cards = [...f.querySelectorAll(".diagram-node")].map((n) => ({ id: n.dataset.node, ...rel(n.getBoundingClientRect()) })); + // Every straight run of every line, from its path's M/L/H/V commands (rounded corners are Q curves between runs). + const runs = [...f.querySelectorAll(".diagram-edge .diagram-line")].flatMap((p) => { + const pts = []; let x = 0, y = 0; + for (const [, c, a, b] of p.getAttribute("d").matchAll(/([MLHVQ])\s*([\d.-]+)(?:\s+([\d.-]+))?/g)) { if (c === "H") x = +a; else if (c === "V") y = +a; else { x = +a; y = +b; } pts.push({ c, x, y }); } + return pts.slice(1).map((q, k) => [pts[k], q]).filter(([a, b]) => b.c !== "Q" && (a.x === b.x || a.y === b.y)); + }); + return { layout: f.dataset.layout, boxes, cards, runs }; +}, key); +describe("the skill: a run beside a box's edge", () => { + test("no run of a drawn figure lies within 2px of a box's edge it runs beside", async () => { + const figs = Object.fromEntries(Object.entries(EDGE).filter(([k]) => k !== "$comment" && !k.startsWith("turnBack"))); + const page = await statePage(figs); + for (const key of Object.keys(figs)) { + const got = await runsAndBoxes(page, key); + if (got.layout !== "drawn") continue; + for (const [a, b] of got.runs) for (const x of got.boxes) { + const level = a.y === b.y, lo = Math.min(level ? a.x : a.y, level ? b.x : b.y), hi = Math.max(level ? a.x : a.y, level ? b.x : b.y); + const edges = level ? [x.t, x.b] : [x.l, x.r], along = level ? [x.l, x.r] : [x.t, x.b], at = level ? a.y : a.x; + if (hi - lo < 4 || hi <= along[0] || lo >= along[1]) continue; + for (const e of edges) assert.ok(Math.abs(at - e) > 2, `${key}: a run at ${at} on ${x.id}'s edge at ${e}`); + } + } + }); + test("a lone run above a box is 16 from the card and from the edge; the box's row is 64 under the row above, 48 otherwise", async () => { + const page = await statePage({ above: EDGE.above }); + const got = await runsAndBoxes(page, "above"); + const box = got.boxes[0], queue = got.cards.find((c) => c.id === "queue"), api = got.cards.find((c) => c.id === "api"); + const run = got.runs.find(([a, b]) => a.y === b.y && a.y > queue.b && a.y < api.t); + assert.ok(Math.abs(run[0].y - queue.b - 16) <= 1 && Math.abs(box.t - run[0].y - 16) <= 1); + assert.ok(Math.abs(api.t - queue.b - 64) <= 0.5); + }); + test("two boxes one above the other are 16 apart; two runs between them stack the figure", async () => { + const page = await statePage({ between: EDGE.between, twoBetween: EDGE.twoBetween }); + const got = await runsAndBoxes(page, "between"); + const [edge, core] = got.boxes; + assert.ok(Math.abs(core.t - edge.b - 16) <= 0.5); + assert.equal((await runsAndBoxes(page, "twoBetween")).layout, "stacked"); + }); + test("the stacked form's parts do not move", async () => { + const page = await statePage({ above: EDGE.above }, { width: 358 }); + assert.equal((await runsAndBoxes(page, "above")).layout, "stacked"); + }); +}); diff --git a/packages/react/test/fixtures/diagram-run-edge.json b/packages/react/test/fixtures/diagram-run-edge.json new file mode 100644 index 00000000..fa4a23a1 --- /dev/null +++ b/packages/react/test/fixtures/diagram-run-edge.json @@ -0,0 +1,698 @@ +{ + "$comment": "The run-edge ruling (DECISIONS 359): the cases written to meet a run on a box edge, copied from the ruling's figures.mjs.", + "above": { + "type": "architecture", + "title": "One run above a boundary", + "summary": "A line from the first row runs level in the gap above the boundary's row.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "vpc", + "label": "VPC" + } + ], + "nodes": [ + { + "id": "edge", + "name": "Edge", + "col": 1, + "row": 2 + }, + { + "id": "queue", + "name": "Queue", + "col": 2, + "row": 1 + }, + { + "id": "api", + "name": "API", + "group": "vpc", + "col": 2, + "row": 2, + "focal": true + }, + { + "id": "worker", + "name": "Worker", + "group": "vpc", + "col": 3, + "row": 2 + }, + { + "id": "store", + "name": "Store", + "col": 4, + "row": 2 + } + ], + "edges": [ + { + "from": "edge", + "to": "api", + "kind": "main" + }, + { + "from": "queue", + "to": "worker", + "fromSide": "bottom", + "toSide": "top", + "label": "Jobs" + }, + { + "from": "api", + "to": "worker", + "kind": "main" + }, + { + "from": "worker", + "to": "store", + "kind": "main" + } + ] + }, + "below": { + "type": "architecture", + "title": "One run below a boundary", + "summary": "A line from the boundary's row runs level in the gap below it.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "vpc", + "label": "VPC" + } + ], + "nodes": [ + { + "id": "edge", + "name": "Edge", + "col": 1, + "row": 1 + }, + { + "id": "api", + "name": "API", + "group": "vpc", + "col": 2, + "row": 1, + "focal": true + }, + { + "id": "worker", + "name": "Worker", + "group": "vpc", + "col": 3, + "row": 1 + }, + { + "id": "store", + "name": "Store", + "col": 4, + "row": 1 + }, + { + "id": "audit", + "name": "Audit log", + "col": 2, + "row": 2 + } + ], + "edges": [ + { + "from": "edge", + "to": "api", + "kind": "main" + }, + { + "from": "api", + "to": "worker", + "kind": "main" + }, + { + "from": "worker", + "to": "store", + "kind": "main" + }, + { + "from": "worker", + "to": "audit", + "fromSide": "bottom", + "toSide": "top", + "label": "Writes" + } + ] + }, + "twoAbove": { + "type": "architecture", + "title": "Two runs above a boundary", + "summary": "Two lines from the first row run level, beside each other, in the gap above the boundary's row.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "vpc", + "label": "VPC" + } + ], + "nodes": [ + { + "id": "queue", + "name": "Queue", + "col": 1, + "row": 1 + }, + { + "id": "cron", + "name": "Scheduler", + "col": 4, + "row": 1 + }, + { + "id": "api", + "name": "API", + "group": "vpc", + "col": 2, + "row": 2, + "focal": true + }, + { + "id": "worker", + "name": "Worker", + "group": "vpc", + "col": 3, + "row": 2 + } + ], + "edges": [ + { + "from": "queue", + "to": "worker", + "fromSide": "bottom", + "toSide": "top" + }, + { + "from": "cron", + "to": "api", + "fromSide": "bottom", + "toSide": "top" + }, + { + "from": "api", + "to": "worker", + "kind": "main" + } + ] + }, + "twoBelow": { + "type": "architecture", + "title": "Two runs below a boundary", + "summary": "Two lines from the boundary's row run level, beside each other, in the gap below it.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "vpc", + "label": "VPC" + } + ], + "nodes": [ + { + "id": "api", + "name": "API", + "group": "vpc", + "col": 2, + "row": 1, + "focal": true + }, + { + "id": "worker", + "name": "Worker", + "group": "vpc", + "col": 3, + "row": 1 + }, + { + "id": "audit", + "name": "Audit log", + "col": 1, + "row": 2 + }, + { + "id": "store", + "name": "Store", + "col": 4, + "row": 2 + } + ], + "edges": [ + { + "from": "api", + "to": "worker", + "kind": "main" + }, + { + "from": "api", + "to": "store", + "fromSide": "bottom", + "toSide": "top" + }, + { + "from": "worker", + "to": "audit", + "fromSide": "bottom", + "toSide": "top" + } + ] + }, + "between": { + "type": "architecture", + "title": "One run between two boundaries", + "summary": "A line from the upper boundary runs level between the two boundaries and into the lower one.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "edge", + "label": "Edge" + }, + { + "id": "core", + "label": "Core" + } + ], + "nodes": [ + { + "id": "cdn", + "name": "CDN", + "group": "edge", + "col": 1, + "row": 1 + }, + { + "id": "gw", + "name": "Gateway", + "group": "edge", + "col": 2, + "row": 1 + }, + { + "id": "api", + "name": "API", + "group": "core", + "col": 1, + "row": 2, + "focal": true + }, + { + "id": "worker", + "name": "Worker", + "group": "core", + "col": 2, + "row": 2 + } + ], + "edges": [ + { + "from": "cdn", + "to": "gw", + "kind": "main" + }, + { + "from": "gw", + "to": "api", + "fromSide": "bottom", + "toSide": "top", + "kind": "main" + }, + { + "from": "api", + "to": "worker" + } + ] + }, + "twoBetween": { + "type": "architecture", + "title": "Two runs between two boundaries", + "summary": "Two lines from the upper boundary run level, beside each other, between the two boundaries.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "edge", + "label": "Edge" + }, + { + "id": "core", + "label": "Core" + } + ], + "nodes": [ + { + "id": "cdn", + "name": "CDN", + "group": "edge", + "col": 1, + "row": 1 + }, + { + "id": "gw", + "name": "Gateway", + "group": "edge", + "col": 2, + "row": 1 + }, + { + "id": "api", + "name": "API", + "group": "core", + "col": 2, + "row": 2, + "focal": true + }, + { + "id": "worker", + "name": "Worker", + "group": "core", + "col": 3, + "row": 2 + } + ], + "edges": [ + { + "from": "cdn", + "to": "api", + "fromSide": "bottom", + "toSide": "top", + "kind": "main" + }, + { + "from": "gw", + "to": "worker", + "fromSide": "bottom", + "toSide": "top" + } + ] + }, + "nestedSide": { + "type": "architecture", + "title": "A run beside a boundary in a boundary", + "summary": "A line turns in the gutter beside a boundary whose inner boundary reaches that side.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "region", + "label": "Region" + }, + { + "id": "vpc", + "label": "VPC", + "parent": "region" + } + ], + "nodes": [ + { + "id": "edge", + "name": "Edge", + "group": "region", + "col": 1, + "row": 1 + }, + { + "id": "api", + "name": "API", + "group": "vpc", + "col": 2, + "row": 1, + "focal": true + }, + { + "id": "worker", + "name": "Worker", + "group": "vpc", + "col": 2, + "row": 2 + }, + { + "id": "mail", + "name": "Mail", + "col": 3, + "row": 1 + }, + { + "id": "store", + "name": "Store", + "col": 3, + "row": 2 + } + ], + "edges": [ + { + "from": "edge", + "to": "api", + "kind": "main" + }, + { + "from": "api", + "to": "store", + "fromSide": "right", + "toSide": "left", + "label": "Reads" + }, + { + "from": "api", + "to": "worker", + "kind": "main" + } + ] + }, + "threeSide": { + "type": "architecture", + "title": "Three runs beside a boundary", + "summary": "Three lines turn beside each other in the gutter beside the boundary.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "vpc", + "label": "VPC" + } + ], + "nodes": [ + { + "id": "a", + "name": "API", + "group": "vpc", + "col": 1, + "row": 1, + "focal": true + }, + { + "id": "b", + "name": "Worker", + "group": "vpc", + "col": 1, + "row": 2 + }, + { + "id": "c", + "name": "Cron", + "group": "vpc", + "col": 1, + "row": 3 + }, + { + "id": "x", + "name": "Store", + "col": 2, + "row": 1 + }, + { + "id": "y", + "name": "Cache", + "col": 2, + "row": 2 + }, + { + "id": "z", + "name": "Mail", + "col": 2, + "row": 3 + } + ], + "edges": [ + { + "from": "a", + "to": "y", + "fromSide": "right", + "toSide": "left" + }, + { + "from": "b", + "to": "z", + "fromSide": "right", + "toSide": "left" + }, + { + "from": "a", + "to": "z", + "fromSide": "right", + "toSide": "left" + } + ] + }, + "turnBackOwn": { + "type": "architecture", + "title": "A boundary's own turn-back", + "summary": "A line leaves the bottom of one part and comes back up into the next, both in the boundary.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "vpc", + "label": "VPC" + } + ], + "nodes": [ + { + "id": "api", + "name": "API", + "group": "vpc", + "col": 1, + "row": 1, + "focal": true + }, + { + "id": "worker", + "name": "Worker", + "group": "vpc", + "col": 2, + "row": 1 + }, + { + "id": "store", + "name": "Store", + "col": 3, + "row": 1 + }, + { + "id": "audit", + "name": "Audit log", + "col": 3, + "row": 2 + } + ], + "edges": [ + { + "from": "api", + "to": "worker", + "kind": "main" + }, + { + "from": "worker", + "to": "store", + "kind": "main" + }, + { + "from": "api", + "to": "worker", + "fromSide": "bottom", + "toSide": "bottom", + "label": "Retries" + } + ] + }, + "turnBackForeign": { + "type": "architecture", + "title": "A turn-back past a boundary", + "summary": "A line leaves the bottom of a part in the boundary and comes back up into a part outside it.", + "legend": { + "main": "The request path", + "plain": "A call", + "group": "A boundary" + }, + "groups": [ + { + "id": "vpc", + "label": "VPC" + } + ], + "nodes": [ + { + "id": "api", + "name": "API", + "group": "vpc", + "col": 1, + "row": 1, + "focal": true + }, + { + "id": "worker", + "name": "Worker", + "group": "vpc", + "col": 2, + "row": 1 + }, + { + "id": "store", + "name": "Store", + "col": 3, + "row": 1 + }, + { + "id": "audit", + "name": "Audit log", + "col": 3, + "row": 2 + } + ], + "edges": [ + { + "from": "api", + "to": "worker", + "kind": "main" + }, + { + "from": "worker", + "to": "store", + "kind": "main" + }, + { + "from": "api", + "to": "store", + "fromSide": "bottom", + "toSide": "bottom", + "label": "Reads" + } + ] + } +} diff --git a/packages/react/test/fixtures/diagrams-d1-state.json b/packages/react/test/fixtures/diagrams-d1-state.json new file mode 100644 index 00000000..9a483c7f --- /dev/null +++ b/packages/react/test/fixtures/diagrams-d1-state.json @@ -0,0 +1,305 @@ +{ + "$comment": "The ruling on a state's start mark and the gap (DECISIONS 359, Ops 1, state-gap/ruling.md): laid right on one row and on two, a level run in the gap above a marked row, and a marked group in a marked group. With the fixture's own state (laid down by automatic layout) these are the figures its tests and its pictures draw.", + "right": { + "type": "state", + "source": "Runner, v1.42", + "legend": { + "main": "The usual path", + "group": "A composite state" + }, + "title": "A short run", + "summary": "A run starts idle, works while active, and ends succeeded.", + "groups": [ + { + "id": "active", + "label": "Active" + } + ], + "nodes": [ + { + "id": "idle", + "name": "Idle", + "initial": true, + "col": 1, + "row": 1 + }, + { + "id": "thinking", + "name": "Thinking", + "group": "active", + "initial": true, + "col": 2, + "row": 1 + }, + { + "id": "tool", + "name": "Tool running", + "group": "active", + "exit": "record result", + "col": 3, + "row": 1 + }, + { + "id": "done", + "name": "Succeeded", + "final": true, + "col": 4, + "row": 1 + } + ], + "edges": [ + { + "from": "idle", + "to": "thinking", + "event": "start", + "kind": "main" + }, + { + "from": "thinking", + "to": "tool", + "event": "call", + "kind": "main" + }, + { + "from": "tool", + "to": "done", + "event": "done", + "action": "save", + "kind": "main" + } + ] + }, + "rows": { + "type": "state", + "source": "Runner, v1.42", + "legend": { + "main": "The usual path", + "group": "A composite state" + }, + "title": "A run that can pause", + "summary": "A run starts idle, works while active, may pause, and ends succeeded.", + "groups": [ + { + "id": "active", + "label": "Active" + } + ], + "nodes": [ + { + "id": "idle", + "name": "Idle", + "initial": true, + "col": 1, + "row": 2 + }, + { + "id": "paused", + "name": "Paused", + "col": 2, + "row": 1 + }, + { + "id": "thinking", + "name": "Thinking", + "group": "active", + "initial": true, + "col": 2, + "row": 2 + }, + { + "id": "tool", + "name": "Tool running", + "group": "active", + "exit": "record result", + "col": 3, + "row": 2 + }, + { + "id": "done", + "name": "Succeeded", + "final": true, + "col": 4, + "row": 2 + } + ], + "edges": [ + { + "from": "idle", + "to": "thinking", + "event": "start", + "kind": "main" + }, + { + "from": "thinking", + "to": "paused", + "event": "pause" + }, + { + "from": "thinking", + "to": "tool", + "event": "call", + "kind": "main" + }, + { + "from": "tool", + "to": "done", + "event": "done", + "action": "save", + "kind": "main" + } + ] + }, + "run": { + "type": "state", + "source": "Runner, v1.42", + "legend": { + "main": "The usual path", + "group": "A composite state" + }, + "title": "A level run above a marked row", + "summary": "A line from a state on the first row runs level in the gap above the composite's row.", + "groups": [ + { + "id": "active", + "label": "Active" + } + ], + "nodes": [ + { + "id": "idle", + "name": "Idle", + "initial": true, + "col": 1, + "row": 2 + }, + { + "id": "paused", + "name": "Paused", + "col": 2, + "row": 1 + }, + { + "id": "thinking", + "name": "Thinking", + "group": "active", + "initial": true, + "col": 2, + "row": 2 + }, + { + "id": "tool", + "name": "Tool running", + "group": "active", + "col": 3, + "row": 2 + }, + { + "id": "done", + "name": "Succeeded", + "final": true, + "col": 4, + "row": 2 + } + ], + "edges": [ + { + "from": "idle", + "to": "thinking", + "event": "start", + "kind": "main" + }, + { + "from": "paused", + "to": "tool", + "event": "resume", + "fromSide": "bottom", + "toSide": "top" + }, + { + "from": "thinking", + "to": "tool", + "event": "call", + "kind": "main" + }, + { + "from": "tool", + "to": "done", + "event": "done", + "kind": "main" + } + ] + }, + "nested": { + "type": "state", + "source": "Runner, v1.42", + "legend": { + "main": "The usual path", + "group": "A composite state" + }, + "title": "A marked group in a marked group", + "summary": "Active starts in Thinking; Planning, inside it, starts in Draft.", + "groups": [ + { + "id": "active", + "label": "Active" + }, + { + "id": "planning", + "label": "Planning", + "parent": "active" + } + ], + "nodes": [ + { + "id": "idle", + "name": "Idle", + "initial": true, + "col": 1, + "row": 1 + }, + { + "id": "thinking", + "name": "Thinking", + "group": "active", + "initial": true, + "col": 2, + "row": 1 + }, + { + "id": "draft", + "name": "Draft", + "group": "planning", + "initial": true, + "col": 3, + "row": 1 + }, + { + "id": "done", + "name": "Succeeded", + "final": true, + "col": 4, + "row": 1 + } + ], + "edges": [ + { + "from": "idle", + "to": "thinking", + "event": "start", + "kind": "main" + }, + { + "from": "thinking", + "to": "draft", + "event": "plan", + "kind": "main" + }, + { + "from": "draft", + "to": "done", + "event": "done", + "kind": "main" + } + ] + } +} diff --git a/packages/react/test/fixtures/diagrams-d1.json b/packages/react/test/fixtures/diagrams-d1.json new file mode 100644 index 00000000..d511bc9c --- /dev/null +++ b/packages/react/test/fixtures/diagrams-d1.json @@ -0,0 +1,888 @@ +{ + "$comment": "DECISIONS 359, batch D wave 1: one figure of each new type and fold, on CIMIP's synthetic data. The React tests and the HTML skill's tests draw the same data (each entry is the component's props with its type).", + "gantt": { + "type": "gantt", + "title": "Sandbox platform rollout", + "summary": "Seven weeks from images to general availability, the canary after the warm pool is sized.", + "source": "Platform plan, Nov 2026", + "today": "2026-11-24", + "legend": { + "focal": "The launch" + }, + "phases": [ + { + "id": "build", + "label": "Build" + }, + { + "id": "rollout", + "label": "Rollout" + } + ], + "tasks": [ + { + "id": "t1", + "name": "Sandbox images", + "start": "2026-11-02", + "end": "2026-11-09", + "phase": "build" + }, + { + "id": "t2", + "name": "Egress proxy allow-list", + "start": "2026-11-10", + "end": "2026-11-18", + "phase": "build", + "after": [ + "t1" + ] + }, + { + "id": "t3", + "name": "Two-step approval gate", + "start": "2026-11-10", + "end": "2026-11-20", + "phase": "build", + "after": [ + "t1" + ], + "detail": "approval-gate", + "detailMono": true + }, + { + "id": "t4", + "name": "Warm pool sizing", + "start": "2026-11-19", + "end": "2026-11-24", + "phase": "rollout", + "after": [ + "t2" + ] + }, + { + "id": "t5", + "name": "Canary in us-east-1", + "start": "2026-11-25", + "end": "2026-12-01", + "phase": "rollout", + "after": [ + "t3", + "t4" + ] + }, + { + "id": "t6", + "name": "General availability", + "start": "2026-12-03", + "milestone": true, + "phase": "rollout", + "after": [ + "t5" + ], + "focal": true + } + ] + }, + "kanban": { + "type": "kanban", + "title": "Incidents this morning", + "summary": "Nine incidents: three in investigation against a limit of two, one of them blocked.", + "source": "Incident board, 09:00", + "legend": { + "focal": "Paged on-call" + }, + "columns": [ + { + "id": "triage", + "label": "Triage" + }, + { + "id": "investigating", + "label": "Investigating", + "limit": 2 + }, + { + "id": "approval", + "label": "Awaiting approval", + "limit": 3 + }, + { + "id": "mitigated", + "label": "Mitigated", + "more": 6, + "note": "Last 24 hours" + } + ], + "cards": [ + { + "id": "inc-482", + "column": "triage", + "kind": "INC-482", + "name": "504s on /runs" + }, + { + "id": "inc-483", + "column": "triage", + "kind": "INC-483", + "name": "Slow sandbox boot" + }, + { + "id": "inc-479", + "column": "investigating", + "kind": "INC-479", + "name": "Approval timeouts", + "blocked": "Waiting on the IdP team" + }, + { + "id": "inc-480", + "column": "investigating", + "kind": "INC-480", + "name": "Egress denied for npm" + }, + { + "id": "inc-481", + "column": "investigating", + "kind": "INC-481", + "name": "Runner out of memory", + "focal": true + }, + { + "id": "inc-476", + "column": "approval", + "kind": "INC-476", + "name": "Roll back proxy config" + }, + { + "id": "inc-470", + "column": "mitigated", + "kind": "INC-470", + "name": "Certificate expiry" + }, + { + "id": "inc-471", + "column": "mitigated", + "kind": "INC-471", + "name": "Queue backlog" + } + ] + }, + "journey": { + "type": "journey", + "title": "A sandbox fails at night", + "summary": "Confidence falls at triage and recovers once the fix is applied.", + "source": "Interviews, Oct 2026", + "actor": "On-call engineer", + "scenario": "A sandbox fails at 2 a.m.", + "scale": [ + "Blocked", + "Strained", + "Neutral", + "Steady", + "Confident" + ], + "legend": { + "line": "How sure the engineer feels", + "focal": "The worst moment" + }, + "stages": [ + { + "id": "paged", + "name": "Paged", + "level": 2, + "actions": "Reads the alert on a phone", + "touchpoint": "Pager" + }, + { + "id": "triage", + "name": "Triage", + "level": 1, + "actions": "Opens logs, finds nothing", + "quote": "Which run is it?", + "friction": "Logs are split across two tools", + "focal": true + }, + { + "id": "approve", + "name": "Approve", + "level": 2, + "actions": "Waits for a second approver", + "touchpoint": "Approval gate" + }, + { + "id": "fix", + "name": "Fix", + "level": 4, + "actions": "Rolls back the proxy config", + "opportunity": "One-click rollback" + }, + { + "id": "review", + "name": "Review", + "level": 5, + "actions": "Writes the timeline", + "quote": "That was quick in the end." + } + ] + }, + "blueprint": { + "type": "service-blueprint", + "title": "Starting a run", + "summary": "What the user sees, what runs behind it, and the pool that supports it.", + "source": "Service design, Nov 2026", + "legend": { + "plain": "Hands off to", + "focal": "What the user watches" + }, + "stages": [ + { + "id": "s1", + "name": "Request a run", + "time": "0–2 s" + }, + { + "id": "s2", + "name": "Approve", + "time": "2–40 s" + }, + { + "id": "s3", + "name": "Run", + "time": "40 s–12 min" + } + ], + "cells": [ + { + "stage": "s1", + "layer": "evidence", + "name": "Run page" + }, + { + "stage": "s1", + "layer": "customer", + "name": "Submits a run" + }, + { + "stage": "s2", + "layer": "customer", + "name": "Waits" + }, + { + "stage": "s3", + "layer": "customer", + "name": "Reads the log" + }, + { + "stage": "s1", + "layer": "frontstage", + "name": "Run form" + }, + { + "stage": "s3", + "layer": "frontstage", + "name": "Live log", + "focal": true + }, + { + "stage": "s1", + "layer": "backstage", + "name": "Policy check", + "detail": "policy-svc", + "detailMono": true + }, + { + "stage": "s2", + "layer": "backstage", + "name": "Approval gate" + }, + { + "stage": "s3", + "layer": "backstage", + "name": "Runner" + }, + { + "stage": "s3", + "layer": "support", + "name": "Sandbox pool" + } + ], + "arrows": [ + { + "from": { + "stage": "s1", + "layer": "customer" + }, + "to": { + "stage": "s1", + "layer": "frontstage" + } + }, + { + "from": { + "stage": "s3", + "layer": "backstage" + }, + "to": { + "stage": "s3", + "layer": "support" + } + } + ] + }, + "storyMap": { + "type": "story-map", + "title": "Incident commander", + "summary": "What ships first: open, triage and mitigate an incident; review comes later.", + "source": "Story mapping, Nov 2026", + "persona": "Incident commander on a weekday shift", + "legend": { + "focal": "The riskiest story" + }, + "activities": [ + { + "id": "open", + "name": "Open incident", + "steps": [ + "Declare", + "Page" + ] + }, + { + "id": "triage", + "name": "Triage", + "steps": [ + "Find the run", + "Read logs" + ] + }, + { + "id": "mitigate", + "name": "Mitigate", + "steps": [ + "Roll back", + "Approve" + ] + }, + { + "id": "review", + "name": "Review", + "steps": [ + "Timeline", + "Actions" + ] + } + ], + "slices": [ + { + "id": "mvp", + "label": "First release" + }, + { + "id": "next", + "label": "Next" + }, + { + "id": "later", + "label": "Later" + } + ], + "cut": { + "after": "mvp", + "label": "Release cut · v1.0" + }, + "stories": [ + { + "id": "s1", + "activity": "open", + "slice": "mvp", + "name": "Declare from the alert" + }, + { + "id": "s2", + "activity": "triage", + "slice": "mvp", + "name": "Link the run to the incident" + }, + { + "id": "s3", + "activity": "mitigate", + "slice": "mvp", + "name": "Multi-region cluster diff", + "kind": "RISK-2", + "focal": true + }, + { + "id": "s4", + "activity": "open", + "slice": "next", + "name": "Page a second team" + }, + { + "id": "s5", + "activity": "mitigate", + "slice": "next", + "name": "One-click rollback" + }, + { + "id": "s6", + "activity": "review", + "slice": "next", + "name": "Draft the timeline" + }, + { + "id": "s7", + "activity": "review", + "slice": "later", + "name": "Export to the postmortem" + } + ] + }, + "schedule": { + "type": "schedule", + "title": "Restoring a run", + "summary": "Twenty-five minutes from the page to the confirmed fix, on two critical paths.", + "source": "Runbook RB-12", + "unit": "min", + "legend": { + "focal": "The step the customer sees" + }, + "tasks": [ + { + "id": "t1", + "kind": "T1", + "name": "Page on-call", + "duration": 3 + }, + { + "id": "t2", + "kind": "T2", + "name": "Open incident", + "duration": 2, + "after": [ + "t1" + ] + }, + { + "id": "t3", + "kind": "T3", + "name": "Pull logs", + "duration": 10, + "after": [ + "t1" + ] + }, + { + "id": "t4", + "kind": "T4", + "name": "Check deploys", + "duration": 5, + "after": [ + "t1" + ] + }, + { + "id": "t5", + "kind": "T5", + "name": "Find cause", + "duration": 8, + "after": [ + "t2", + "t3" + ] + }, + { + "id": "t6", + "kind": "T6", + "name": "Roll back", + "duration": 8, + "after": [ + "t3", + "t4" + ] + }, + { + "id": "t7", + "kind": "T7", + "name": "Confirm fix", + "duration": 4, + "after": [ + "t5", + "t6" + ], + "focal": true + } + ], + "layout": "auto" + }, + "timeline": { + "type": "timeline", + "title": "INC-482, 504s on /runs", + "summary": "Seven events: the fix in eleven minutes, then a 31-minute soak before it was resolved.", + "source": "Incident log", + "legend": { + "focal": "Resolved" + }, + "breaks": [ + { + "from": "2026-11-24T14:13:00Z", + "to": "2026-11-24T14:44:00Z", + "label": "soak" + } + ], + "events": [ + { + "id": "e1", + "at": "2026-11-24T14:01:00Z", + "name": "Alert fires", + "kind": "alert" + }, + { + "id": "e2", + "at": "2026-11-24T14:02:00Z", + "name": "On-call paged", + "kind": "page" + }, + { + "id": "e3", + "at": "2026-11-24T14:03:00Z", + "name": "Triage started", + "kind": "triage", + "detail": "28% 504 on /runs" + }, + { + "id": "e4", + "at": "2026-11-24T14:07:00Z", + "name": "Cause found", + "kind": "diagnosis", + "detail": "proxy allow-list" + }, + { + "id": "e5", + "at": "2026-11-24T14:10:00Z", + "name": "Fix applied", + "kind": "change" + }, + { + "id": "e6", + "at": "2026-11-24T14:12:00Z", + "name": "Errors back to zero", + "kind": "check" + }, + { + "id": "e7", + "at": "2026-11-24T14:46:00Z", + "name": "Resolved", + "kind": "resolve", + "focal": true + } + ] + }, + "state": { + "type": "state", + "title": "An agent run", + "summary": "A run starts idle, works while active, and ends succeeded, failed or canceled.", + "source": "Runner, v1.42", + "legend": { + "main": "The usual path", + "group": "A composite state" + }, + "groups": [ + { + "id": "active", + "label": "Active" + } + ], + "nodes": [ + { + "id": "idle", + "name": "Idle", + "initial": true + }, + { + "id": "thinking", + "name": "Thinking", + "group": "active", + "initial": true + }, + { + "id": "tool", + "name": "Tool running", + "group": "active", + "exit": "record result" + }, + { + "id": "waiting", + "name": "Waiting approval", + "group": "active", + "entry": "notify approver" + }, + { + "id": "done", + "name": "Succeeded", + "final": true + }, + { + "id": "failed", + "name": "Failed", + "final": true + }, + { + "id": "canceled", + "name": "Canceled", + "final": true + } + ], + "edges": [ + { + "from": "idle", + "to": "thinking", + "event": "start", + "kind": "main" + }, + { + "from": "thinking", + "to": "tool", + "event": "tool.call", + "guard": "read-only", + "kind": "main" + }, + { + "from": "thinking", + "to": "waiting", + "event": "tool.call", + "guard": "writes" + }, + { + "from": "waiting", + "to": "canceled", + "event": "deny" + }, + { + "from": "tool", + "to": "done", + "event": "done", + "action": "save", + "kind": "main" + }, + { + "from": "tool", + "to": "failed", + "event": "error" + } + ], + "layout": "auto" + }, + "deployment": { + "type": "deployment", + "title": "The runner in production", + "summary": "The load balancer sends runs to three copies of the API, which write to the database.", + "source": "infra/prod.tf", + "environment": "Production · us-east-1", + "legend": { + "main": "A request", + "plain": "A call", + "group": "A network boundary", + "focal": "What this page is about" + }, + "groups": [ + { + "id": "account", + "label": "AWS · runner account" + }, + { + "id": "private", + "label": "Private subnet", + "parent": "account" + } + ], + "nodes": [ + { + "id": "alb", + "kind": "Load balancer", + "name": "ALB", + "group": "account", + "col": 1, + "row": 1 + }, + { + "id": "api", + "kind": "ECS Fargate", + "name": "api service", + "group": "private", + "col": 2, + "row": 1, + "replicas": 3, + "focal": true, + "artifacts": [ + { + "id": "art-api", + "name": "api", + "detail": "v1.42.0" + }, + { + "id": "art-worker", + "name": "worker", + "detail": "v1.42.0" + } + ] + }, + { + "id": "db", + "kind": "Aurora PostgreSQL", + "name": "runs database", + "detail": "1 writer, 1 reader", + "group": "private", + "col": 3, + "row": 1 + } + ], + "edges": [ + { + "from": "alb", + "to": "art-api", + "kind": "main", + "label": "HTTPS :443" + }, + { + "from": "art-worker", + "to": "db", + "label": "TLS :5432" + } + ] + }, + "dependency": { + "type": "architecture", + "title": "What depends on what", + "summary": "The web app depends on the API; the API and auth depend on each other.", + "source": "Service catalogue", + "dependents": { + "one": "dependent", + "other": "dependents" + }, + "legend": { + "plain": "Depends on", + "dashed": "Depend on each other (a cycle)" + }, + "nodes": [ + { + "id": "web", + "kind": "Next.js", + "name": "web" + }, + { + "id": "cli", + "kind": "Go", + "name": "cli" + }, + { + "id": "api", + "kind": "Service", + "name": "api" + }, + { + "id": "auth", + "kind": "Service", + "name": "auth" + }, + { + "id": "db", + "kind": "Aurora", + "name": "db" + } + ], + "edges": [ + { + "from": "web", + "to": "api" + }, + { + "from": "cli", + "to": "api" + }, + { + "from": "api", + "to": "auth" + }, + { + "from": "auth", + "to": "api" + }, + { + "from": "api", + "to": "db" + } + ], + "layout": "auto" + }, + "swimlane": { + "type": "data-flow", + "title": "Who approves a run", + "summary": "A run that writes waits for an approver; a read-only run starts at once.", + "source": "Approval policy", + "legend": { + "plain": "Then" + }, + "lanes": [ + { + "id": "requester", + "label": "Requester" + }, + { + "id": "system", + "label": "Runner" + }, + { + "id": "approver", + "label": "Approver" + } + ], + "nodes": [ + { + "id": "n1", + "name": "Request a run", + "lane": "requester", + "col": 1 + }, + { + "id": "n2", + "name": "Does it write?", + "lane": "system", + "col": 2, + "shape": "decision" + }, + { + "id": "n3", + "name": "Approve", + "lane": "approver", + "col": 3 + }, + { + "id": "n4", + "name": "Start sandbox", + "lane": "system", + "col": 4 + } + ], + "edges": [ + { + "from": "n1", + "to": "n2" + }, + { + "from": "n2", + "to": "n3", + "label": "writes", + "fromSide": "bottom" + }, + { + "from": "n2", + "to": "n4", + "label": "read-only" + }, + { + "from": "n3", + "to": "n4", + "label": "approved" + } + ] + } +} From bc08d5856b9504107f20dbeb71cda762a1efc6f3 Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:49:26 -0600 Subject: [PATCH 12/12] Sizes: the table regenerated for the new types Co-Authored-By: Claude Opus 5.5 --- packages/react/test/export-sizes.json | 35 +++++++++++++++++---------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/react/test/export-sizes.json b/packages/react/test/export-sizes.json index 53fe32f1..6c6e47e1 100644 --- a/packages/react/test/export-sizes.json +++ b/packages/react/test/export-sizes.json @@ -18,7 +18,7 @@ "AppHeader": 1285, "AppShell": 104323, "AppTile": 1112, - "ArchitectureDiagram": 104733, + "ArchitectureDiagram": 110362, "ArrowDownGlyph": 2868, "ArrowLeftGlyph": 2869, "ArrowRightGlyph": 2859, @@ -70,8 +70,9 @@ "CopyGlyph": 2884, "Countdown": 3016, "CoverageStrip": 1570, - "DataFlowDiagram": 104680, + "DataFlowDiagram": 110279, "DateAge": 2527, + "DeploymentDiagram": 114138, "DescriptionColumns": 216, "DescriptionItem": 593, "DescriptionList": 326, @@ -105,11 +106,12 @@ "Fieldset": 6390, "FilterResult": 698, "FilterToolbar": 774, - "FlowchartDiagram": 104701, + "FlowchartDiagram": 110300, "Form": 8730, "FormGrid": 438, "FormGridItem": 628, "FramedArt": 2067, + "GanttDiagram": 125531, "GlidePlate": 4209, "Heading": 799, "HistoryGlyph": 3004, @@ -123,7 +125,9 @@ "InlineTextarea": 25828, "InlineValue": 349, "Input": 27061, + "JourneyDiagram": 118993, "KEEP": 68, + "KanbanDiagram": 118146, "Kbd": 9626, "LOOPS_TOGGLE_DESCRIPTION": 85, "LOOPS_TOGGLE_NAME": 41, @@ -170,7 +174,7 @@ "MultiSelect": 151424, "Nav": 4774, "NavGroup": 492, - "NavItem": 110669, + "NavItem": 110677, "NoticeBar": 788, "NotificationCenter": 152696, "NotificationCentre": 152706, @@ -232,7 +236,8 @@ "STAGE_WORDS": 149, "STATUS_MESSAGE_MS": 26, "SandboxesGlyph": 2963, - "SchemaDiagram": 104649, + "ScheduleDiagram": 119217, + "SchemaDiagram": 110248, "SearchDialog": 89508, "SearchField": 18500, "SearchGlyph": 3183, @@ -251,7 +256,8 @@ "SelectableList": 821, "SelectionBar": 25913, "Separator": 4531, - "SequenceDiagram": 104677, + "SequenceDiagram": 110276, + "ServiceBlueprintDiagram": 122762, "SettingsGlyph": 3100, "ShareBar": 1411, "Sheet": 70793, @@ -293,10 +299,12 @@ "StageMark": 14317, "StageRail": 1200, "Stat": 2226, + "StateDiagram": 117303, "Stats": 314, "StatusBar": 7225, "StatusLine": 504, "Stepper": 27886, + "StoryMapDiagram": 119779, "Stream": 283, "StreamArrivedWord": 470, "StreamBlock": 2788, @@ -341,7 +349,8 @@ "ThemeChoiceControl": 4794, "ThemeMenu": 206519, "TimeChart": 48163, - "ToastProvider": 92989, + "TimelineDiagram": 127953, + "ToastProvider": 92987, "Toolbar": 22915, "ToolbarButton": 32730, "ToolbarGroup": 21467, @@ -428,16 +437,16 @@ }, "subpaths": { "diagram-interop": { - "bytes": 138715, - "gzip": 39659 + "bytes": 141120, + "gzip": 40708 } }, "package": { - "bytes": 953467, - "gzip": 318283 + "bytes": 1042388, + "gzip": 347849 }, "styles": { - "bytes": 470812, - "gzip": 60785 + "bytes": 510931, + "gzip": 65368 } }