@tjakoen/grain 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -232,7 +232,7 @@ every theme, and verify it still reads in dark.
232
232
  (`data-field` / `data-bind-*` / `each` / `<slot-tag>`).
233
233
  2. Register the dir at your **composition root** so the host composes `<mywidget>` and bundles
234
234
  its CSS: add it to the renderer's component roots + the style bundle + the catalog
235
- (this repo: `componentRoots` / `styleRoots` in `tjakoen.github.io/config.ts`; a standalone consumer
235
+ (this repo: `componentRoots` / `styleRoots` in `tjakoen.github.io/src/config.ts`; a standalone consumer
236
236
  passes its dir to `createRenderer` / the style bundle / `createCatalog`). It then appears
237
237
  in `/catalog` automatically.
238
238
 
@@ -1,8 +1,8 @@
1
1
  // grain/ai/accepts.test.ts — UNIT: component affordance harvester in isolation.
2
2
  // Uses tmp files to simulate component HTML so no real fs state is needed.
3
3
  import { test, expect } from "bun:test";
4
- import { mkdirSync, writeFileSync, rmSync } from "fs";
5
- import { join } from "path";
4
+ import { mkdirSync, writeFileSync, rmSync } from "node:fs";
5
+ import { join } from "node:path";
6
6
  import { createAccepts } from "./accepts.ts";
7
7
 
8
8
  const TMP = join(import.meta.dir, "__accepts_test_tmp__");
package/ai/accepts.ts CHANGED
@@ -1,11 +1,11 @@
1
- // /framework/render/accepts.ts — harvest component-declared affordances.
1
+ // grain/ai/accepts.ts — harvest component-declared affordances.
2
2
  //
3
3
  // Scans each component's .html for `data-kind` + `data-accepts` and returns a
4
4
  // kind → action-names map. This is the single source the AI manifest reads, so it
5
5
  // can't drift from what the components actually expose (https://tjakoen.github.io/grain/docs/ai-interface §4).
6
6
  // Generic: it knows nothing about the app's specific verbs or surfaces.
7
- import { readdirSync, readFileSync } from "fs";
8
- import { join } from "path";
7
+ import { readdirSync, readFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
9
 
10
10
  const KIND = /\bdata-kind=["']([^"']+)["']/;
11
11
  const ACCEPTS = /\bdata-accepts=["']([^"']+)["']/;
package/ai/contract.ts CHANGED
@@ -1,4 +1,4 @@
1
- // /app/ai/contract.ts — the action vocabulary contract (see https://tjakoen.github.io/grain/docs/ai-interface).
1
+ // grain/ai/contract.ts — the action vocabulary contract (see https://tjakoen.github.io/grain/docs/ai-interface).
2
2
  //
3
3
  // Two closed registries + three envelopes. Both a human interaction and an AI
4
4
  // decision become the SAME Intent, flow through the SAME door, and come back as
@@ -224,6 +224,7 @@ export const isSafeNavigateHref = (href: unknown): href is string =>
224
224
  /** Cap on a field.set value — a prefill is a message draft, not a document. */
225
225
  export const FIELD_VALUE_CAP = 2000;
226
226
  /** Plain text only: no C0 control chars except \n and \t (a textarea needs both). */
227
+ // eslint-disable-next-line no-control-regex
227
228
  const FIELD_VALUE_BAD_CHARS = /[\x00-\x08\x0b\x0c\x0e-\x1f]/;
228
229
  export const isSafeFieldValue = (v: unknown): v is string =>
229
230
  typeof v === "string" && v.length <= FIELD_VALUE_CAP && !FIELD_VALUE_BAD_CHARS.test(v);
@@ -1,4 +1,4 @@
1
- // /app/ai/interaction-layer.ts — THE ONE DOOR (the single internal AI interaction
1
+ // grain/ai/interaction-layer.ts — THE ONE DOOR (the single internal AI interaction
2
2
  // layer; MVP §"One interface, one path"). Every Intent — from a human click or an
3
3
  // AI decision — enters here, is validated against the closed vocabulary, handed to
4
4
  // the reasoner (the single writer), and the resulting RenderOps are PUSHED back to
package/ai/manifest.ts CHANGED
@@ -1,4 +1,4 @@
1
- // /app/ai/manifest.ts — the AI's instruction manual, per screen.
1
+ // grain/ai/manifest.ts — the AI's instruction manual, per screen.
2
2
  //
3
3
  // A machine-readable projection of what's addressable (targets) and invokable
4
4
  // (actions) on a screen, plus the in-view state the reasoner needs (MVP steps 2–4).
package/ai/markdown.ts CHANGED
@@ -36,6 +36,7 @@ const LIST_ITEM_RE = /^[-*]\s+/;
36
36
  const BLOCK_SPLIT_RE = /\n{2,}/;
37
37
  // Placeholder delimiter for pulled-out code spans (below) — \x00 can't occur in real chat text
38
38
  // (it was already esc()'d as ordinary text upstream), so it never collides.
39
+ // eslint-disable-next-line no-control-regex
39
40
  const CODE_PLACEHOLDER_RE = /\x00(\d+)\x00/g;
40
41
 
41
42
  function inline(escaped: string): string {
@@ -135,7 +135,7 @@ test("say.set → the reply streams straight into the reflection surface (no cha
135
135
  const d = await r.decide(intent({ action: "say.set", surface: "reflection", payload: { text: "clear thursday" } }), tools);
136
136
 
137
137
  expect(d.ok).toBe(true);
138
- expect(targetsOf(ops.filter((o) => o.op === "type"))).toEqual(new Array([...("Noted: clear Thursday.")].length + 1).fill("reflection"));
138
+ expect(targetsOf(ops.filter((o) => o.op === "type"))).toEqual(Array.from<string>({ length: [...("Noted: clear Thursday.")].length + 1 }).fill("reflection"));
139
139
  expect(ops.every((o) => o.target === "reflection")).toBe(true); // no chat-log bubble machinery
140
140
  });
141
141
 
@@ -49,7 +49,7 @@ export function makeModelReasoner(opts: ModelReasonerOptions): Reasoner {
49
49
 
50
50
  /** Stream text into a surface one code point at a time (kit ops), then settle it clean. */
51
51
  async function stream(surface: string, text: string, tools: ReasonTools): Promise<void> {
52
- for (const ch of [...text]) {
52
+ for (const ch of text) {
53
53
  if (tools.cancelled()) break;
54
54
  if (thinkMs > 0) await tools.delay(TYPE_MS);
55
55
  tools.emit(typeToken(surface, ch));
package/ai/reasoner.ts CHANGED
@@ -1,4 +1,4 @@
1
- // /app/ai/reasoner.ts — the reasoner boundary (the PROJECT-PLAN §10c `Model` seam)
1
+ // grain/ai/reasoner.ts — the reasoner boundary (the PROJECT-PLAN §10c `Model` seam)
2
2
  // plus a stub standing in for the real cloud/local model during frontend work.
3
3
  //
4
4
  // The reasoner is the SINGLE WRITER: it decides, then writes + renders through
@@ -69,7 +69,7 @@ export function makeStubReasoner(opts: StubOptions = {}): Reasoner {
69
69
  // arrives at grain with a caret; `done` settles it to clean (DESIGN-SYSTEM §3).
70
70
  // Shared by both text verbs so the input and the button feel the same.
71
71
  const stream = async (surface: string, line: string, done = true): Promise<Decision> => {
72
- for (const ch of [...line]) { // spread = per code point (handles "—")
72
+ for (const ch of line) { // for-of on a string already iterates per code point (handles "—")
73
73
  if (tools.cancelled()) break; // stop promptly at a clean boundary…
74
74
  await tools.delay(thinkMs > 0 ? TYPE_MS : 0);
75
75
  tools.emit({ target: surface, op: "type", text: ch, provenance: "ai", commit: "pending" });
@@ -35,3 +35,33 @@ describe("createCatalog inject seams", () => {
35
35
  expect(html).not.toContain("undefined");
36
36
  });
37
37
  });
38
+
39
+ // A component that owns the window (a deck at position: fixed) rendered live inside a panel
40
+ // covers the whole catalog page — the failure that motivated the `flat` fence tag.
41
+ describe("flat panels render source only", () => {
42
+ let dir: string;
43
+
44
+ beforeAll(async () => {
45
+ dir = await mkdtemp(join(tmpdir(), "batch-catalog-flat-"));
46
+ await mkdir(join(dir, "organisms", "deck"), { recursive: true });
47
+ await writeFile(join(dir, "organisms", "deck", "deck.md"),
48
+ "# Deck\n\n## Markup\n\n```html flat\n<div class=\"deck-live-marker\"></div>\n```\n\n" +
49
+ "## Live\n\n```html\n<div class=\"other-live-marker\"></div>\n```\n");
50
+ });
51
+ afterAll(() => rm(dir, { recursive: true, force: true }));
52
+
53
+ test("a ```html flat fence keeps its markup out of the live panel", async () => {
54
+ const html = await (createCatalog(dir)).html();
55
+ // the flat panel: no live node, but the copyable source survives escaped
56
+ expect(html).not.toContain(`<div class="deck-live-marker">`);
57
+ expect(html).toContain("&lt;div class=&quot;deck-live-marker&quot;&gt;");
58
+ expect(html).toContain("panel__flat");
59
+ // an untagged fence in the same doc still renders live
60
+ expect(html).toContain(`<div class="other-live-marker">`);
61
+ });
62
+
63
+ test("each component entry carries a data-surface address", async () => {
64
+ const html = await (createCatalog(dir)).html();
65
+ expect(html).toContain(`data-surface="catalog:deck"`);
66
+ });
67
+ });
@@ -7,10 +7,10 @@
7
7
  // dropdowns, with a live search filter. Dependency-free: a tiny line parser, no
8
8
  // markdown library, no CDN. It reads the filesystem directly (like ai/accepts.ts) and
9
9
  // imports nothing from batch — the composition root passes the page-nav routes in.
10
- import { readdirSync, readFileSync } from "fs";
11
- import { join } from "path";
10
+ import { readdirSync, readFileSync } from "node:fs";
11
+ import { join } from "node:path";
12
12
 
13
- interface Panel { label: string; code: string; }
13
+ interface Panel { label: string; code: string; flat?: boolean; }
14
14
  interface Group { label: string; panels: Panel[]; }
15
15
  interface Doc { name: string; slug: string; intro: string; groups: Group[]; }
16
16
  interface Component { layer: string; slug: string; name: string; human: Doc; ai: Doc | null; }
@@ -34,6 +34,10 @@ const LAYER_ORDER = ["atoms", "molecules", "organisms"];
34
34
  const rank = (layer: string) => { const i = LAYER_ORDER.indexOf(layer); return i < 0 ? 99 : i; };
35
35
 
36
36
  // minimal markdown: # title, ## group, ### panel, ```html fences, plain prose.
37
+ // A fence tagged ```html flat renders as SOURCE ONLY, with no live panel. That escape hatch
38
+ // exists for markup a catalog panel cannot honestly host: a component that sizes itself from
39
+ // the viewport, or one that goes position: fixed, takes over the whole catalog page rather than
40
+ // demonstrating itself inside its box. Default stays live — flat is the exception a doc asks for.
37
41
  function parseDoc(md: string): Doc {
38
42
  const lines = md.split("\n");
39
43
  const doc: Doc = { name: "Untitled", slug: "untitled", intro: "", groups: [] };
@@ -48,12 +52,13 @@ function parseDoc(md: string): Doc {
48
52
  if (line.startsWith("## ")) { group = { label: line.slice(3).trim(), panels: [] }; doc.groups.push(group); pendingLabel = ""; i++; continue; }
49
53
  if (line.startsWith("### ")) { pendingLabel = line.slice(4).trim(); i++; continue; }
50
54
  if (line.startsWith("```html")) {
55
+ const flat = /\bflat\b/.test(line.slice(7));
51
56
  const body: string[] = [];
52
57
  i++;
53
58
  while (i < lines.length && !lines[i].startsWith("```")) { body.push(lines[i]); i++; }
54
59
  i++; // skip closing fence
55
60
  if (!group) { group = { label: "", panels: [] }; doc.groups.push(group); }
56
- group.panels.push({ label: pendingLabel, code: body.join("\n").trim() });
61
+ group.panels.push({ label: pendingLabel, code: body.join("\n").trim(), flat });
57
62
  continue;
58
63
  }
59
64
  if (!group && line.trim()) intro.push(line.trim());
@@ -130,9 +135,9 @@ export function createCatalog(componentsDir: string | string[], pages?: () => st
130
135
 
131
136
  function renderPanel(p: Panel): string {
132
137
  // live = author-controlled design-system markup (not user data) → inject raw
133
- return `<figure class="panel">
138
+ return `<figure class="panel"${p.flat ? " data-flat" : ""}>
134
139
  ${p.label ? `<figcaption class="panel__label">${esc(p.label)}</figcaption>` : ""}
135
- <div class="panel__live">${liveSafe(p.code)}</div>
140
+ ${p.flat ? `<p class="panel__flat">Source only — this one owns the whole window, so a panel cannot host it. Open a real one.</p>` : `<div class="panel__live">${liveSafe(p.code)}</div>`}
136
141
  <div class="panel__src">
137
142
  <button class="panel__copy" type="button">Copy</button>
138
143
  <pre><code>${esc(p.code)}</code></pre>
@@ -151,7 +156,9 @@ export function createCatalog(componentsDir: string | string[], pages?: () => st
151
156
 
152
157
  function renderDoc(c: Component): string {
153
158
  const ai = c.ai ?? c.human; // no .ai.md → AI view re-uses the human panels, grain-flipped
154
- return `<section class="cat-doc" id="${c.slug}" data-grade="smooth" data-layer="${c.layer}">
159
+ // data-surface addresses the entry so a tour, a lamp or the reasoner can point AT one
160
+ // component rather than at "the catalog". The id stays for plain anchor links.
161
+ return `<section class="cat-doc" id="${c.slug}" data-surface="catalog:${esc(c.slug)}" data-grade="smooth" data-layer="${c.layer}">
155
162
  <header class="cat-doc__head">
156
163
  <div class="cat-doc__title">
157
164
  <p class="cat-doc__eyebrow">${esc(cap(c.layer))}</p>
@@ -278,6 +285,8 @@ function page(pageNav: string, navGroups: string, main: string, inject: CatalogI
278
285
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted);
279
286
  padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-line); }
280
287
  .panel__live { padding: var(--space-6); display: flex; align-items: center; justify-content: center; background: var(--color-bg); }
288
+ .panel__flat { margin: 0; padding: var(--space-4) var(--space-6); background: var(--color-bg);
289
+ font-size: var(--text-xs); color: var(--color-muted); text-align: center; }
281
290
  .panel__src { position: relative; border-top: 1px solid var(--color-line); }
282
291
  .panel__src pre { margin: 0; padding: var(--space-3); overflow-x: auto;
283
292
  font-size: var(--text-xs); line-height: var(--leading-normal); background: var(--ink); color: var(--paper); }
@@ -12,7 +12,7 @@ per-page wiring.
12
12
 
13
13
  ## Markup
14
14
 
15
- ```html
15
+ ```html flat
16
16
  <div class="presentation" data-present data-deck data-hash data-minutes="20" data-channel="my-talk">
17
17
 
18
18
  <div class="presentation__bar">
@@ -52,7 +52,9 @@ presenter window.
52
52
 
53
53
  The catalog renders this example flat rather than live, and that is the honest thing to do: a deck
54
54
  sizes itself from its own box with `container-type: size` and lays its slides out absolutely, so
55
- one dropped into a catalog panel collapses to nothing. Read the code, or open a real deck.
55
+ one dropped into a catalog panel collapses to nothing, and `data-present` puts it `position: fixed`
56
+ over the whole catalog page. That is what the `flat` tag on the fence above asks for. Read the
57
+ code, or open a real deck.
56
58
 
57
59
  **Opt in with `data-deck`.** Without the script the markup still renders whichever slide carries
58
60
  `data-current`, which is what a static export and a print run get.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tjakoen/grain",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "GRAIN — an AI-interaction design system where every surface is operable by both a human and an AI through one shared vocabulary.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -1,4 +1,4 @@
1
- // /frontend/scripts/ai-dispatch.js — the dispatcher island (docs/AI-INTERFACE.md §3).
1
+ // grain/scripts/ai-dispatch.js — the dispatcher island (docs/AI-INTERFACE.md §3).
2
2
  //
3
3
  // The ONE accepted bit of client JS. Two jobs:
4
4
  // 1. Turn [data-action] interactions (click, or Enter in an input) into POST /intent
@@ -53,6 +53,7 @@ import { createSpotlight } from "/scripts/ai-spotlight.js";
53
53
  // dispatcher is the LAST line of defense before a value lands in a real form field, so it
54
54
  // re-checks even though the reasoner already validated.
55
55
  const FIELD_VALUE_CAP = 2000;
56
+ // eslint-disable-next-line no-control-regex
56
57
  const FIELD_VALUE_BAD_CHARS = /[\x00-\x08\x0b\x0c\x0e-\x1f]/;
57
58
  const SAFE_FIELD_VALUE = (v) => typeof v === "string" && v.length <= FIELD_VALUE_CAP && !FIELD_VALUE_BAD_CHARS.test(v);
58
59
  // A `navigate` op tears the page down — irreversible, so give any in-flight settle (the
@@ -77,6 +78,7 @@ import { createSpotlight } from "/scripts/ai-spotlight.js";
77
78
  const MD_LIST_ITEM_RE = /^[-*]\s+/;
78
79
  const MD_BLOCK_SPLIT_RE = /\n{2,}/;
79
80
  // Placeholder delimiter for pulled-out code spans (below) — \x00 can't occur in real chat text.
81
+ // eslint-disable-next-line no-control-regex
80
82
  const MD_CODE_PLACEHOLDER_RE = /\x00(\d+)\x00/g;
81
83
  function mdInline(escaped) {
82
84
  // Code spans are pulled OUT first (placeholdered), so their literal contents can never be
@@ -188,6 +190,7 @@ import { createSpotlight } from "/scripts/ai-spotlight.js";
188
190
  const sh = document.querySelector(".app-shell");
189
191
  if (sh) { sh.removeAttribute("data-acting"); sh.removeAttribute("data-chat-open"); sh.removeAttribute("data-console-open"); } // hand back: everything resets
190
192
  clearActing(spotlit); spotlit = null;
193
+ // eslint-disable-next-line unicorn/no-useless-spread -- the copy IS load-bearing: clearTrigger deletes from pendingTriggers while we iterate it
191
194
  for (const t of [...pendingTriggers.keys()]) clearTrigger(t); // backstop: turn over → nothing stays "working"
192
195
  }
193
196
 
@@ -253,6 +256,7 @@ import { createSpotlight } from "/scripts/ai-spotlight.js";
253
256
  if (pendingTriggers.size) watchdogTimer = setTimeout(watchdogFire, WATCHDOG_MS);
254
257
  }
255
258
  function watchdogFire() {
259
+ // eslint-disable-next-line unicorn/no-useless-spread -- the copy IS load-bearing: clearTrigger deletes from pendingTriggers while we iterate it
256
260
  for (const [target, trg] of [...pendingTriggers.entries()]) {
257
261
  trg.removeAttribute("data-state"); void trg.offsetWidth; // restart the flash
258
262
  trg.setAttribute("data-state", "error");
@@ -299,7 +303,7 @@ import { createSpotlight } from "/scripts/ai-spotlight.js";
299
303
  applyType(el, op);
300
304
  return;
301
305
  case "spotlight": // the AI as actor: dim + light the target
302
- op.active ? spotlightOn(op.target, op.click) : spotlightOff();
306
+ if (op.active) spotlightOn(op.target, op.click); else spotlightOff();
303
307
  return;
304
308
  case "navigate": // AI-directed browser navigation (contract.ts's `navigate` op)
305
309
  if (typeof op.href !== "string" || !SAFE_NAV_HREF.test(op.href)) {
@@ -353,7 +357,7 @@ import { createSpotlight } from "/scripts/ai-spotlight.js";
353
357
  el.setAttribute("data-commit", "pending");
354
358
  body = el.querySelector(".stream-body");
355
359
  // OVERWRITE (op.back) re-enters an already-written surface → keep its text so the
356
- // the AI can backspace it. A fresh write (text, no back) starts empty (wipes any placeholder).
360
+ // AI can backspace it. A fresh write (text, no back) starts empty (wipes any placeholder).
357
361
  if (typeof op.back === "number") body.textContent = prev;
358
362
  }
359
363
  if (typeof op.back === "number" && op.back > 0) // the AI revising: delete trailing chars
@@ -484,7 +488,7 @@ import { createSpotlight } from "/scripts/ai-spotlight.js";
484
488
  if (trigger) { clearTrigger(target); trigger.setAttribute("data-commit", "pending"); pendingTriggers.set(target, trigger); armWatchdog(); }
485
489
  const send = () => sendIntent({ source: "user", session, screen, surface: target, action, payload })
486
490
  .catch(() => { clearTrigger(target); markOnline(false); }); // couldn't reach the door (timeout/network) → undo + honest offline
487
- sseIsOpen ? send() : sseReady.then(send); // wait for the stream so no early ops are lost
491
+ if (sseIsOpen) send(); else sseReady.then(send); // wait for the stream so no early ops are lost
488
492
  }
489
493
 
490
494
  // fire a [data-action] trigger (a button/link with a verb) through the ONE door. Shared by page
package/scripts/cmdk.js CHANGED
@@ -139,7 +139,7 @@
139
139
  function init() {
140
140
  build();
141
141
  document.addEventListener("keydown", (ev) => {
142
- if ((ev.metaKey || ev.ctrlKey) && ev.key.toLowerCase() === "k") { ev.preventDefault(); isOpen() ? close() : open(); }
142
+ if ((ev.metaKey || ev.ctrlKey) && ev.key.toLowerCase() === "k") { ev.preventDefault(); if (isOpen()) close(); else open(); }
143
143
  });
144
144
  // declarative trigger: any [data-cmdk-open] element opens the palette (e.g. the title
145
145
  // bar's search field — a button drawn as an input)
@@ -30,7 +30,7 @@
30
30
  const DRAFT_KEY = "grain.notepad.draft"; // the human's uncommitted textarea text (kept across reload)
31
31
 
32
32
  const read = (k) => { try { return localStorage.getItem(k); } catch { return null; } };
33
- const write = (k, v) => { try { v == null ? localStorage.removeItem(k) : localStorage.setItem(k, v); } catch { /* private mode */ } };
33
+ const write = (k, v) => { try { if (v == null) localStorage.removeItem(k); else localStorage.setItem(k, v); } catch { /* private mode */ } };
34
34
 
35
35
  // Join every entry's markdown source, in order — the whole pad's canonical markdown.
36
36
  const deriveSource = (body) =>
package/scripts/shell.js CHANGED
@@ -48,7 +48,7 @@
48
48
  for (const b of shell.querySelectorAll(`[data-shell="${name}"]`))
49
49
  b.addEventListener("click", () => {
50
50
  const on = shell.getAttribute(attr) !== "true";
51
- on ? shell.setAttribute(attr, "true") : shell.removeAttribute(attr);
51
+ if (on) shell.setAttribute(attr, "true"); else shell.removeAttribute(attr);
52
52
  try { localStorage.setItem(key, on ? "1" : "0"); } catch { /* ignore */ }
53
53
  });
54
54
  }
package/scripts/tabs.js CHANGED
@@ -103,7 +103,7 @@
103
103
  if (path !== here) return render();
104
104
  // closing the page you're ON: go to the neighbor tab, else the first pinned tab, else home
105
105
  const next = list[Math.min(i, list.length - 1)]
106
- || (strip.querySelector("a[data-pinned]") || {}).getAttribute?.("href") || "/";
106
+ || strip.querySelector("a[data-pinned]")?.getAttribute("href") || "/";
107
107
  location.assign(next);
108
108
  };
109
109
 
@@ -112,7 +112,7 @@
112
112
  list = [];
113
113
  save(list);
114
114
  if (!wasHere) return render();
115
- location.assign((strip.querySelector("a[data-pinned]") || {}).getAttribute?.("href") || "/");
115
+ location.assign(strip.querySelector("a[data-pinned]")?.getAttribute("href") || "/");
116
116
  };
117
117
 
118
118
  const allBtns = document.querySelectorAll('[data-shell="tabs-close-all"]');
@@ -19,7 +19,7 @@
19
19
  "use strict";
20
20
  if (window.grain && window.grain.terminal) return; // idempotent
21
21
 
22
- const PROMPT = "❯"; // ❯
22
+ const PROMPT = "❯";
23
23
  const HISTORY_KEY = "grain.terminal.history";
24
24
  const HISTORY_CAP = 50;
25
25
  const esc = (s) => String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
@@ -11,5 +11,5 @@
11
11
  if (s) html.setAttribute("data-color-scheme", s);
12
12
  var t = localStorage.getItem("grain-theme");
13
13
  if (t) html.setAttribute("data-theme", t);
14
- } catch (e) { /* no storage (privacy mode) → defaults render, theme.js stays the fallback */ }
14
+ } catch { /* no storage (privacy mode) → defaults render, theme.js stays the fallback */ }
15
15
  })();
package/scripts/theme.js CHANGED
@@ -27,7 +27,7 @@
27
27
  const html = document.documentElement;
28
28
  const store = (() => { try { return window.localStorage; } catch { return null; } })();
29
29
  const get = (k) => { try { return store && store.getItem(k); } catch { return null; } };
30
- const put = (k, v) => { try { if (store) v == null ? store.removeItem(k) : store.setItem(k, v); } catch {} };
30
+ const put = (k, v) => { try { if (store) { if (v == null) store.removeItem(k); else store.setItem(k, v); } } catch { /* private mode — the pref just doesn't persist */ } };
31
31
 
32
32
  // ---- color scheme (light | dark | auto; auto drops the attr → follow the OS) --------------
33
33
  function setScheme(s) {
@@ -18,21 +18,30 @@
18
18
  .lightbox::backdrop { background: color-mix(in srgb, var(--ink) 82%, transparent); }
19
19
  @media (prefers-reduced-motion: reduce) { .lightbox { transition: none; } }
20
20
 
21
- /* the figure: the centre column, holds the image + its caption */
21
+ /* the figure: the centre column, holds the image + its caption. `align-items: center` is load-bearing:
22
+ without it the column stretches its children, so a long caption widens the figure and the image box
23
+ with it — the picture then letterboxes inside a too-wide box and the img's own background paints
24
+ paper-coloured bars beside it. Centred, the image shrink-wraps to its real aspect. */
22
25
  .lightbox__figure {
23
26
  grid-column: 2; justify-self: center; align-self: center;
24
- display: flex; flex-direction: column; gap: var(--space-2);
27
+ display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
25
28
  max-width: 100%; max-height: 100dvh; margin: 0; padding: var(--space-3);
26
29
  box-sizing: border-box;
27
30
  }
31
+ /* the height budget: the viewport minus the bottom chrome the figure must not collide with (the dot
32
+ rail + counter) and minus room for a caption line or two. Without it a tall image pushes its own
33
+ caption down into the dots. */
28
34
  .lightbox__img {
29
- display: block; max-width: 100%; max-height: calc(100dvh - 6rem);
35
+ display: block; max-width: 100%; max-height: calc(100dvh - 12rem);
30
36
  width: auto; height: auto; object-fit: contain;
31
37
  border-radius: var(--radius-md); background: var(--color-bg);
32
38
  box-shadow: 0 8px 32px color-mix(in srgb, var(--ink) 55%, transparent);
33
39
  }
40
+ /* the caption WRAPS: centring the column stopped it from stretching, so an unbounded line would run
41
+ straight off both edges of the viewport. It reads under the image, never wider than the gutter. */
34
42
  .lightbox__caption {
35
- text-align: center; font-size: .85rem; color: var(--color-bg);
43
+ align-self: stretch; max-width: min(100%, 60ch); margin: 0 auto;
44
+ text-align: center; font-size: .85rem; line-height: 1.4; color: var(--color-bg);
36
45
  text-shadow: 0 1px 3px color-mix(in srgb, var(--ink) 85%, transparent);
37
46
  }
38
47