Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .agent/skills/basalt-html/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Markup built only at run time (a `.row` your script writes) won't be seen: add `
- **period** `.period`: two ghost icon buttons round `.period-label`; at an end `aria-disabled`, never `disabled`.
- **terminal** `.terminal`: with `.code`; lines are `span[data-kind]`; the script draws the gutter.
- **chart** `.chart`: JSON in `script[data-chart]`; `null` is a day not observed, never zero; needs a `summary`.
- **diagram** `.diagram`: JSON in `script[data-diagram]`; sides only to change the default; needs a `summary`.
- **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.
Expand Down
61 changes: 58 additions & 3 deletions .agent/skills/basalt-html/compose.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import vm from "node:vm";

const here = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -303,7 +304,7 @@ export function readBody(body, stats = {}) {
const placeholder = new RegExp(`${mark}(\\d+)${mark}(\\s*)`, "g");
const blank = (item) => { let text = item.text; for (const [a, b] of [...item.comments].reverse()) text = text.slice(0, a) + " " + text.slice(b); return text; };
return {
text: out, saved, scripts, placeholder, whole, h1: h1 && !h1.open ? h1.text.trim() : null,
text: out, saved, scripts, placeholder, mark, whole, h1: h1 && !h1.open ? h1.text.trim() : null,
// The text put back; with `bare`, as detection reads it: no comment (an HTML one, or one in a nested element, or in a script).
restore: (s, bare = false) => s.replace(placeholder, (_, k, ws) => {
const item = saved[Number(k)];
Expand Down Expand Up @@ -539,7 +540,8 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts =
});
for (const name of use) if (!(name in manifest.modules)) throw new Error(`basalt:use names "${name}", which is not a module (modules: ${Object.keys(manifest.modules).join(", ")})`);

const content = held.restore(markup).replace(/^\s+/, "");
const diagramNotes = [];
const content = held.restore(writeDiagrams(markup, held, parts, diagramNotes)).replace(/^\s+/, "");
title ||= held.h1 || "Untitled page"; // an empty <title> names nothing: the heading does

// Detection reads markup and code, never comments: a word written about in a comment (an HTML one, or one inside a script or a style) brings nothing in.
Expand Down Expand Up @@ -587,7 +589,59 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts =
"</html>",
"",
].join("\n");
return { html, modules: chosen.modules, icons: chosen.icons, glyphs: chosen.glyphs, built, external: externalReferences(held, markup), bytes: Buffer.byteLength(html) };
return { html, modules: chosen.modules, icons: chosen.icons, glyphs: chosen.glyphs, built, external: externalReferences(held, markup), diagrams: diagramNotes, bytes: Buffer.byteLength(html) };
}

/**
* A diagram's words, written into the page (DECISIONS 281, 1.19): each `<figure class="diagram">` that holds only its JSON gets the markup the diagram module's
* script would write for it, from that same script (parts/diagram.js, run here without a page), so the page reads before any script runs. The figure's own
* attributes stay (its class joins ours, its id stays); the JSON stays for the script. A figure whose JSON does not parse is left for the script, which says why.
*
* It reads the body as readBody left it: every comment, script, style, textarea, title, svg and template is a placeholder there, so a figure written as an
* example inside one is text and is never expanded. A figure is found by the composer's own tag reader (quoted, single-quoted or unquoted attributes alike),
* and is expanded only when its class list holds `diagram` and its content is one `script` with `data-diagram` and nothing else but white space.
*/
function writeDiagrams(markup, held, parts, notes) {
if (!exists(parts, "diagram.js")) return markup;
const mark = held.mark;
const json = new RegExp(`^(\\s*)${mark}(\\d+)${mark}(\\s*)</figure(?=[\\t\\n\\f\\r />])[^>]*>`, "i");
let engine = null;
let serial = 0;
let out = "";
let at = 0;
for (let i = markup.indexOf("<"); i !== -1; i = markup.indexOf("<", i + 1)) {
if (!/^<figure[\t\n\f\r />]/i.test(markup.slice(i, i + 8))) continue;
const tag = readTag(markup, i);
if (!tag.terminated || tag.close) continue;
const attrs = new Map();
for (const [k, v] of tag.attrs) if (!attrs.has(k)) attrs.set(k, v); // the first of a repeated attribute wins, as in a browser
if (!(attrs.get("class") ?? "").split(/[\t\n\f\r ]+/).includes("diagram") || attrs.has("data-diagram-drawn")) continue;
const inside = json.exec(markup.slice(tag.end));
const item = inside && held.saved[Number(inside[2])];
if (!item || item.kind !== "script" || !item.attrs.some(([k]) => k === "data-diagram")) continue;
let spec;
try { spec = JSON.parse(item.inner); } catch (e) { notes.push(`a diagram's JSON does not parse (${e.message}); the page's script will say so`); continue; }
if (!engine) {
const context = { window: { Basalt: { _: { step() {}, esc: (x) => x } } }, console: { warn() {}, error() {}, log() {} } };
vm.runInNewContext(read(parts, "diagram.js"), context);
engine = context.window.Basalt._.diagramMarkup;
}
let made;
try { made = engine(spec, `dg${++serial}`); } catch (e) { notes.push(`${spec?.title ?? "a diagram"} could not be written (${e.message}); the page's script will say so`); continue; }
for (const w of made.warnings) notes.push(`${spec.title ?? "a diagram"}: ${w}`);
const merged = new Map(attrs);
for (const [, k, v] of made.open.matchAll(/\s([\w:-]+)="([^"]*)"/g)) {
if (k === "class") merged.set("class", [...new Set(`${merged.get("class") ?? ""} ${v}`.split(/\s+/).filter(Boolean))].join(" "));
else if (k === "style") merged.set("style", merged.has("style") ? `${v};${merged.get("style")}` : v);
else merged.set(k, v);
}
const open = `<figure${[...merged].map(([k, v]) => ` ${k}="${v.replaceAll('"', "&quot;")}"`).join("")}>`;
const end = tag.end + inside[0].length;
out += markup.slice(at, i) + open + inside[1] + `${mark}${inside[2]}${mark}` + inside[3] + made.inner + "</figure>";
at = end;
i = end - 1;
}
return out + markup.slice(at);
}

/** The module lines of SKILL.md's "## Modules" index: [{ name, trigger, warning }]. A line is `- **name** \`trigger\`: warning`. */
Expand Down Expand Up @@ -707,6 +761,7 @@ if (isMain) {
const say = (l) => (l.name in result.built ? ` ${l.name}: built by the ${result.built[l.name]}; nothing to check.` : ` ${l.name}: ${l.warning}`);
if (warnings.length) console.log(`Check before you hand it over (the full text of one: --usage NAME):\n${warnings.map(say).join("\n")}`);
}
for (const note of result.diagrams) console.log(`Diagram: ${note}`);
// After the page and the modules' lines: what the body references that is not in the file. The page is written; the warning is for the one who handed it over.
if (result.external.length) console.log(`Warning: ${result.external.length} reference${result.external.length === 1 ? "" : "s"} leave${result.external.length === 1 ? "s" : ""} the file, and a page is one file with no network (nothing loads offline; a link is the reader's to follow):\n${result.external.map((line) => ` ${line}`).join("\n")}`);
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions .agent/skills/basalt-html/parts/diagram.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .agent/skills/basalt-html/parts/diagram.js

Large diffs are not rendered by default.

88 changes: 87 additions & 1 deletion .agent/skills/basalt-html/parts/manifest.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions .agent/skills/basalt-html/parts/usage/diagram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# diagram

```
<figure class="diagram">
<script type="application/json" data-diagram>
{ "type": "architecture", "title": "How a request reaches the agent", "source": "docs/architecture.md",
"summary": "…", "legend": { "main": "Request path", "plain": "Call", "dashed": "Async or one-way", "focal": "The service" },
"groups": [{ "id": "aws", "label": "AWS · your account" }],
"nodes": [{ "id": "alb", "kind": "Load balancer", "name": "ALB", "col": 2, "row": 2 },
{ "id": "svc", "kind": "ECS service", "name": "api service", "detail": "N tasks", "detailMono": true,
"focal": true, "group": "aws", "col": 3, "row": 2 }],
"edges": [{ "from": "alb", "to": "svc", "kind": "main", "label": "HTTP" }] }
</script>
</figure>
```

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`).
- **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`.
- **Required:** `title`, `summary` (what it shows, in a sentence). `source`, `heading` (2 to 6, default 3).
- Monochrome: nothing takes a colour. The drawn layout is used only where it fits; otherwise the figure is stacked, one column at most 480 wide.
6 changes: 5 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Basalt has one owner (Bailey) and a design panel of two independent design revie
tabs that scrolls, a sortable header cell (a header band that is itself a button), a phone tab bar cell, and a cut cell of a still table (a focus stop, which shows its own ring after Esc has closed its plate). These structural
vertical lines are allowed, each named and never a selection, sort, active or status mark: the 1px divider at a pinned table
column's edge while the table is scrolled, the app sidebar's 1px edge, a meter's labelled target tick, the vertical
`Separator` between groups of controls, and the edges between a `NumberField`'s value and its steppers. The active row in a menu, select, combobox or command menu is a rounded plate
`Separator` between groups of controls, the edges between a `NumberField`'s value and its steppers, a diagram's connector and a sequence diagram's lifeline. The active row in a menu, select, combobox or command menu is a rounded plate
(radius 8, one solid fill per level) plus a lift from secondary ink to primary, with no
weight change: it is the row the keyboard is on, and it changes with every arrow key (WCAG 1.4.1). A selected table row is the wash band, and its checked box
carries the state. A wash over an opaque fill (a pinned cell) is one colour from `color-mix`, never a gradient, an image or a
Expand Down Expand Up @@ -188,6 +188,10 @@ Basalt has one owner (Bailey) and a design panel of two independent design revie
rest. Don't redraw a glyph in code: change `packages/react/glyphs/source.mjs` and run
`node packages/react/glyphs/generate.mjs`. On Apple platforms, SF Symbols for system concepts
(info, warning, error, success). Status icons pair with words.
- **Diagrams:** monochrome; one focal node, inverted. Three lines named by look (main 2px, plain 1px, dashed), and the key says what
each means. The drawn layout is used only when it fits (640, the track minimums, a clean seat for every label); otherwise stacked, in
the author's order, at most 480 wide. Nothing is cut and nothing overlaps at any width. Ports, routes, groups and foreign keys are derived from one
record each. A flowchart's shapes have a 3:1 contour. Tracing changes ink, never weight. The words are in the HTML before script.
- **Type:** Geist and Geist Mono at 400, 500 and 600 only, and a `Geist Fallback` face (local Arial, one face per weight) that reduces the shift when Geist
arrives; it does not promise the same wrap at every width.
- **Display type:** two roles a page writes, hero (96/96; 72/76 from 720 to 1023; 44/48 under 720) and display (72/76; 56/60; 36/40), made of the fixed
Expand Down
60 changes: 60 additions & 0 deletions Sources/BasaltTokens/Tokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,54 @@ extension Basalt {
dark: RGBA(red: 0.521561, green: 0.521561, blue: 0.521561, alpha: 1)
)

/// A diagram's main line and its head, and a traced line (DECISIONS 281). 3:1 or better on levels 0 to 3.
public static let diagramEdgeMain = ThemedColor(
light: RGBA(red: 0.090173, green: 0.090173, blue: 0.090173, alpha: 1),
dark: RGBA(red: 0.955355, green: 0.955355, blue: 0.955355, alpha: 1)
)

/// A diagram's plain and dashed lines and their heads, a foreign key's line and dot, and an edge label's ink.
public static let diagramEdge = ThemedColor(
light: RGBA(red: 0.301921, green: 0.301921, blue: 0.301921, alpha: 1),
dark: RGBA(red: 0.730753, green: 0.730753, blue: 0.730753, alpha: 1)
)

/// Every other line of a diagram while one node is traced: quieter, still 3:1. The input boundary; it does not step under more contrast.
public static let diagramEdgeDim = ThemedColor(
light: RGBA(red: 0, green: 0, blue: 0, alpha: 0.45),
dark: RGBA(red: 1, green: 1, blue: 1, alpha: 0.38)
)

/// A diagram's group boundary, a sequence's lifeline and a flowchart shape's contour: 3:1, because each carries meaning. It does not step under more contrast.
public static let diagramStructure = ThemedColor(
light: RGBA(red: 0, green: 0, blue: 0, alpha: 0.45),
dark: RGBA(red: 1, green: 1, blue: 1, alpha: 0.38)
)

/// A diagram's focal node: its fill and its edge, inverted ink. At most one a diagram, and never the accent.
public static let diagramFocal = ThemedColor(
light: RGBA(red: 0.090173, green: 0.090173, blue: 0.090173, alpha: 1),
dark: RGBA(red: 0.929405, green: 0.929405, blue: 0.929405, alpha: 1)
)

/// Ink on the focal node; its kind and detail are this ink at opacity-amount.
public static let diagramFocalInk = ThemedColor(
light: RGBA(red: 1, green: 1, blue: 1, alpha: 1),
dark: RGBA(red: 0, green: 0, blue: 0, alpha: 1)
)

/// The focal table's header rule. Decorative: the other theme's divider, because the focal fill is the other theme's ground.
public static let diagramFocalRule = ThemedColor(
light: RGBA(red: 1, green: 1, blue: 1, alpha: 0.06),
dark: RGBA(red: 0, green: 0, blue: 0, alpha: 0.08)
)

/// Under more contrast, the focal table's header rule: the other theme's input boundary (DECISIONS 281, 1.18). An alias, no new colour.
public static let diagramFocalRuleContrast = ThemedColor(
light: RGBA(red: 1, green: 1, blue: 1, alpha: 0.38),
dark: RGBA(red: 0, green: 0, blue: 0, alpha: 0.45)
)

/// The ground of drawn art and of a stage. It is the page colour, so a stage meets the page with no seam, and it is the stage's placeholder while the art loads.
public static let artField = ThemedColor(
light: RGBA(red: 0.980387, green: 0.980387, blue: 0.980387, alpha: 1),
Expand Down Expand Up @@ -632,6 +680,18 @@ extension Basalt {
public static let chartPlotSm: Double = 96
/// A marks row's height, a default the app can set: one kind of reading across a run of days (DECISIONS 153, consent row 10).
public static let chartRow: Double = 56
/// The least width of a node's track in a diagram's drawn layout; a track is also as wide as its widest unbreakable word, measured (DECISIONS 281).
public static let diagramNode: Double = 144
/// The least width of a schema diagram's table; a table is also as wide as its widest row on one line, measured (DECISIONS 281).
public static let diagramTable: Double = 224
/// A data flow diagram's lane-name column, at the start of the drawn layout (DECISIONS 281).
public static let diagramLane: Double = 120
/// A sequence diagram's message row: the line at its middle, the number and label above it, the note below (DECISIONS 281).
public static let diagramStep: Double = 56
/// A diagram's arrowhead, its length and its width, for every kind of line (DECISIONS 281).
public static let diagramHead: Double = 8
/// A sequence diagram's lifeline dash, on and off (4 on 4 off), unlike a message's 6 on 4 off (DECISIONS 281).
public static let diagramGuideDash: Double = 4
/// A range meter's marker: a dot, ringed size-cut in the colour of the surface (DECISIONS 153, consent row 14).
public static let meterMarker: Double = 12
/// The top of a stage the art keeps quiet for the bar: size-header (56) plus space-6 (24). The top safe area is added by the layout CSS. No pixel of it passes art-quiet-limit, and a stage declares that the product's headroom check passed.
Expand Down
Loading
Loading