frameboard 0.5.0 → 0.7.0

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
@@ -26,31 +26,96 @@ In a folder with no board, `serve` creates `.frameboard/` with one empty project
26
26
 
27
27
  ## How it works
28
28
 
29
- A board folder holds projects, a project holds pages, and a page holds frames. Each frame is one `.html` file beside a `layout.json` that records where it sits.
29
+ ### Board folder
30
30
 
31
- The `project`, `page`, and `frame` commands manage them on disk, `list` shows the board, and `edit` changes one style, attribute, or text on one element without touching another byte. `show` points the open board at a frame.
31
+ A board folder holds projects, a project holds pages, and a page holds frames.
32
32
 
33
- On the board, Cmd-click or double-click selects an element inside a frame, Enter, Esc, and Tab walk the tree, and the layers panel lists each frame's elements. `selection` prints what the developer picked, with the element's index and hash ready for `edit`.
33
+ - Each frame is one `.html` file beside a `layout.json` that records where it sits
34
34
 
35
- Frames share one look through a `tokens.css` in the board folder, which a project's own `tokens.css` overrides, or through `serve --tokens <path>` for a sheet another tool manages. The server puts the sheets and three faces, Geist, Geist Mono, and Caveat, ahead of each frame's own styles as it serves the frame, and the file on disk stays as written. One toggle switches the board and every frame between light and dark.
35
+ ### Tokens and themes
36
36
 
37
- `frameboard check` reports every content rule a frame breaks, such as a link outside its page folder or colors set for one theme alone, and exits 8 on any error. The board runs the same rules on each change, and a running server adds the rules only a browser can see, being clipped content, a scrollbar inside the frame, content sized off the viewport, and text under a project's minimum size. `capture` writes PNGs of a frame or page in either theme, `frame fit` sets a frame's height to its content, and `inspect` lists each rendered element with the index `edit` takes, its box, and its computed color and type.
37
+ Frames share one look through a `tokens.css` in the board folder, which a project's own `tokens.css` overrides.
38
38
 
39
- Pin a note on a frame or one element with the Note tool, and Send hands it to a Claude Code session listening on the board. The agent answers in the note's thread through `notes reply` and closes it with `notes done`, and the notes stay in each page's `notes.json`.
39
+ - `serve --tokens <path>` takes a sheet another tool manages instead
40
+ - The server puts the sheets and three faces, Geist, Geist Mono, and Caveat, ahead of each frame's own styles as it serves the frame
41
+ - The file on disk stays as written
42
+ - One toggle switches the board and every frame between light and dark
40
43
 
41
- An agent runs `editing` on a frame before rewriting it. The board then outlines the frame and tags it with the agent and how long it has held it, and a second session that tries to claim it is told it is taken. A claim lapses five minutes after the agent last ran `editing`, and a note sent from a claimed frame goes to the session holding it. When you move, resize, edit, rename, or delete a claimed frame, your edit waits until the claim ends, under a card naming the agent. A move, resize, or element edit then goes only if the agent left the frame as you saw it, and a rename or delete goes once the claim ends.
44
+ ## For agents
42
45
 
43
- When an agent writes a frame, the board marks it with a dot and counts it on its page and project until you look at it. A toast names the agent and offers Show, which takes you to the change and makes the edited elements glow, and Next, or `]`, steps to the next one.
46
+ ### Commands
44
47
 
45
- The Claude Code plugin in `plugins/frameboard/` runs the static checks after each agent write and hands the findings back in the same turn. Its monitor runs `inbox --follow` for the session, so a sent note reaches the agent at once. `frameboard docs` prints every command, flag, record shape, and exit code.
48
+ The `project`, `page`, and `frame` commands manage the board on disk, and `list` shows it.
46
49
 
47
- In the board you move and resize frames, add, rename, reorder, delete, and search pages, and add a frame at a phone, tablet, or desktop size with the Frame tool. On the home view, New project adds a project, and a card's right-click menu opens, renames, duplicates, or deletes one. The inspector edits a selected element's name, opacity, radius, type size, weight, alignment, fill, stroke color, shadow, and text, offers the project's tokens first, and flags a color no token names. The layers panel selects, renames, restacks, hides, and locks frames, and Cmd+D, Cmd+C, Cmd+X, and Cmd+V duplicate, copy, cut, and paste them across pages and projects. Cmd+F finds a frame, an element, or a line of copy on any page of the project and jumps to it. Undo any of it with Cmd+Z. An undo of something an agent has changed since is refused and named on the board, so it never reverts the agent's work. Releases before 1.0 ship the board in stages, and the rest of editing by hand arrives in later 0.x releases.
50
+ - `edit` changes one style, attribute, or text on one element without touching another byte
51
+ - `show` points the open board at a frame, and `capture` writes PNGs of a frame or page in either theme
52
+ - `frame fit` sets a frame's height to its content
53
+ - `inspect` lists each rendered element with the index `edit` takes, its box, and its computed color and type
54
+ - `frameboard docs` prints every command, flag, record shape, and exit code
55
+
56
+ ### Content checks
57
+
58
+ `frameboard check` reports every content rule a frame breaks, such as a link outside its page folder or colors set for one theme alone, and exits 8 on any error.
59
+
60
+ - The board runs the same rules on each change
61
+ - A running server adds the rules only a browser can see, being clipped content, a scrollbar inside the frame, content sized off the viewport, and text under a project's minimum size
62
+
63
+ ### Claims
64
+
65
+ An agent runs `editing` on a frame before rewriting it.
66
+
67
+ - The board then outlines the frame and tags it with the agent and how long it has held it, and a second session that tries to claim it is told it is taken
68
+ - A claim lapses five minutes after the agent last ran `editing`, and a note sent from a claimed frame goes to the session holding it
69
+ - When you move, resize, edit, rename, or delete a claimed frame, your edit waits until the claim ends, under a card naming the agent
70
+ - A move, resize, or element edit then goes only if the agent left the frame as you saw it, and a rename or delete goes once the claim ends
71
+
72
+ ### Change marks and following
73
+
74
+ When an agent writes a frame, the board marks it with a dot and counts it on its page and project until you look at it.
75
+
76
+ - A toast names the agent and offers Show, which takes you to the change and makes the edited elements glow, and Next, or `]`, steps to the next one
77
+ - Click a listening agent's initial in the inspector header to follow it
78
+ - The board then pans to each frame it claims or writes, across pages, until you pan, zoom, or click the canvas yourself
79
+
80
+ ### Plugin
81
+
82
+ The Claude Code plugin in `plugins/frameboard/` runs the static checks after each agent write and hands the findings back in the same turn.
83
+
84
+ - Its monitor runs `inbox --follow` for the session, so a sent note reaches the agent at once
85
+
86
+ ## For you
87
+
88
+ ### Selecting
89
+
90
+ On the board, Cmd-click or double-click selects an element inside a frame.
91
+
92
+ - Enter, Esc, and Tab walk the tree, and the layers panel lists each frame's elements
93
+ - `selection` prints what you picked, with the element's index and hash ready for `edit`
94
+
95
+ ### Notes
96
+
97
+ Pin a note on a frame or one element with the Note tool, and Send hands it to a Claude Code session listening on the board.
98
+
99
+ - The agent answers in the note's thread through `notes reply` and closes it with `notes done`
100
+ - The notes stay in each page's `notes.json`
101
+
102
+ ### Hand edits
103
+
104
+ In the board you move and resize frames, add, rename, reorder, delete, and search pages, and add a frame at a phone, tablet, or desktop size with the Frame tool.
105
+
106
+ - On the home view, New project adds a project, and a card's right-click menu opens, renames, duplicates, or deletes one
107
+ - The inspector edits a selected element's name, opacity, radius, type size, weight, alignment, fill, stroke color, shadow, and text, offering the project's tokens first and flagging untokened colors
108
+ - The layers panel selects, renames, restacks, hides, and locks frames, and Cmd+D, Cmd+C, Cmd+X, and Cmd+V duplicate, copy, cut, and paste them across pages and projects
109
+ - Cmd+F finds a frame, an element, or a line of copy on any page of the project and jumps to it
110
+ - Right-click a frame, element, empty canvas, page, or layers row for its actions, such as Copy as PNG, Paste here, or Flip to light, which shows that frame alone in the other theme until reload
111
+
112
+ Undo any of it with Cmd+Z. An undo of something an agent has changed since is refused and named on the board, so it never reverts the agent's work. Releases before 1.0 ship the board in stages, and the rest of editing by hand arrives in later 0.x releases.
48
113
 
49
114
  ## Requirements
50
115
 
51
116
  Frameboard runs on macOS and Linux, with Node 22 or later or with Bun. Windows support is planned.
52
117
 
53
- `capture`, `frame fit`, and `inspect` render in Playwright's headless shell. Without it, they print the command that installs it and download nothing.
118
+ `capture`, `frame fit`, `inspect`, and the home view's project thumbnails render in Playwright's headless shell. Without it, the commands print the command that installs it and download nothing, and each home card shows its frames as plain boxes.
54
119
 
55
120
  ## Links
56
121
 
package/dist/cli.js CHANGED
@@ -9,7 +9,7 @@ import process$1, { versions } from "node:process";
9
9
  import { isDeepStrictEqual, promisify, stripVTControlCharacters } from "node:util";
10
10
  import { fileURLToPath } from "node:url";
11
11
  import { constants, copyFile, cp, link, lstat, mkdir, open, readFile, readdir, realpath, rename, rm, stat as stat$1, writeFile } from "node:fs/promises";
12
- import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
12
+ import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
13
13
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
14
14
  import { STATUS_CODES, ServerResponse, createServer } from "node:http";
15
15
  import { Http2ServerRequest, constants as constants$1 } from "node:http2";
@@ -9360,7 +9360,7 @@ async function isDirectory(path) {
9360
9360
  }
9361
9361
  //#endregion
9362
9362
  //#region package.json
9363
- var version$1 = "0.5.0";
9363
+ var version$1 = "0.7.0";
9364
9364
  var dependencies = { "playwright-core": "1.64.1" };
9365
9365
  //#endregion
9366
9366
  //#region src/shared/version.ts
@@ -27576,7 +27576,54 @@ function definesTheme(node) {
27576
27576
  * count, and neither does a `url()` whose file name reads as a color.
27577
27577
  */
27578
27578
  function setsLiteralColor(property, value) {
27579
- return COLOR_PROPERTIES$1.test(property) && isLiteralColor(value);
27579
+ if (!COLOR_PROPERTIES$1.test(property)) return false;
27580
+ if (SHADOW_PROPERTIES.test(property) && isFaintShadow(value)) return false;
27581
+ return isLiteralColor(value);
27582
+ }
27583
+ const SHADOW_PROPERTIES = /^(box|text)-shadow$/i;
27584
+ const RGB_COLOR = /\brgba?\(([^)]*)\)/gi;
27585
+ const HEX_TOKEN = /#([0-9a-f]{4}|[0-9a-f]{8})\b/gi;
27586
+ /**
27587
+ * Whether every color a shadow names is black or white at or under 0.2
27588
+ * alpha, which reads the same on either theme, so a frame writing one for a
27589
+ * single theme is no finding.
27590
+ */
27591
+ function isFaintShadow(value) {
27592
+ const own = stripFunctions(value, ["var", "url"]);
27593
+ const colors = [];
27594
+ const rest = own.replace(RGB_COLOR, (_match, args) => {
27595
+ colors.push(isFaintRgb(args));
27596
+ return " ";
27597
+ }).replace(HEX_TOKEN, (_match, digits) => {
27598
+ colors.push(isFaintHex(digits));
27599
+ return " ";
27600
+ });
27601
+ return colors.length > 0 && colors.every(Boolean) && !isLiteralColor(rest);
27602
+ }
27603
+ function isFaintRgb(args) {
27604
+ const parts = args.split(/[\s,/]+/).map((part) => part.trim()).filter(Boolean);
27605
+ const [r, g, b, a] = parts;
27606
+ if (parts.length !== 4 || a === void 0) return false;
27607
+ const alpha = a.endsWith("%") ? Number.parseFloat(a) / 100 : Number.parseFloat(a);
27608
+ return isBlackOrWhite(readChannel(r), readChannel(g), readChannel(b)) && alpha <= .200000001;
27609
+ }
27610
+ function readChannel(part) {
27611
+ if (part === void 0) return void 0;
27612
+ if (part.endsWith("%")) return Number.parseFloat(part) / 100 * 255;
27613
+ return Number.parseFloat(part);
27614
+ }
27615
+ function isFaintHex(digits) {
27616
+ const full = digits.length === 4 ? [...digits].map((digit) => digit + digit).join("") : digits;
27617
+ const [r, g, b, a] = [
27618
+ 0,
27619
+ 2,
27620
+ 4,
27621
+ 6
27622
+ ].map((at) => Number.parseInt(full.slice(at, at + 2), 16));
27623
+ return isBlackOrWhite(r, g, b) && (a ?? 255) / 255 <= .200000001;
27624
+ }
27625
+ function isBlackOrWhite(r, g, b) {
27626
+ return r === 0 && g === 0 && b === 0 || r === 255 && g === 255 && b === 255;
27580
27627
  }
27581
27628
  /** Whether a value holds a color of its own, outside any `var()` or `url()`. */
27582
27629
  function isLiteralColor(value) {
@@ -34567,6 +34614,9 @@ const LOOK_MARKER = "data-frameboard";
34567
34614
  * the route served, so a live frame names the exact file an edit addresses.
34568
34615
  */
34569
34616
  const RENDERED_HASH = "data-hash";
34617
+ function isTheme$1(value) {
34618
+ return value === "light" || value === "dark";
34619
+ }
34570
34620
  /**
34571
34621
  * Shows a frame's root in `theme`: `data-theme`, `color-scheme`, and the
34572
34622
  * `.dark` or `.light` class, the selectors a token sheet reads. The frame
@@ -35437,20 +35487,33 @@ async function holdFrames(root, refs, options) {
35437
35487
  }
35438
35488
  /**
35439
35489
  * Writes held frames onto a page as new files on top of its stack, each
35440
- * taking the next free name so nothing on the page is overwritten. A frame
35441
- * keeps its box on another page and lands beside its source on its own,
35442
- * the way `duplicateFrame` places a copy.
35490
+ * taking the next free name so nothing on the page is overwritten. Without
35491
+ * `at`, a frame keeps its box on another page and lands beside its source
35492
+ * on its own, the way `duplicateFrame` places a copy.
35443
35493
  */
35444
35494
  async function pasteFrames(root, pageRef, held, options) {
35445
- const { journal } = options;
35495
+ const { journal, at } = options;
35446
35496
  const target = await resolvePageRef(root, pageRef, options);
35497
+ const left = Math.min(...held.map((frame) => frame.placement.box.x));
35498
+ const top = Math.min(...held.map((frame) => frame.placement.box.y));
35499
+ const place = (frame) => {
35500
+ const { box } = frame.placement;
35501
+ if (at) return {
35502
+ ...box,
35503
+ x: at.x + box.x - left,
35504
+ y: at.y + box.y - top
35505
+ };
35506
+ return frame.page === target.path ? {
35507
+ ...box,
35508
+ x: box.x + box.width + 80
35509
+ } : box;
35510
+ };
35447
35511
  const names = await withLayouts([target.path], async (layouts) => {
35448
35512
  const layout = layouts.get(target.path);
35449
35513
  if (!layout) throw new Error(`No layout read for ${target.path}.`);
35450
35514
  const pasted = [];
35451
35515
  for (const frame of held) {
35452
35516
  const name = freeFrameName(layout.names, frame.name, void 0);
35453
- const { box } = frame.placement;
35454
35517
  const path = join(target.path, `${name}${FRAME_EXTENSION}`);
35455
35518
  await writeFile(path, frame.bytes, { flag: "wx" });
35456
35519
  await journal?.created(path);
@@ -35458,10 +35521,7 @@ async function pasteFrames(root, pageRef, held, options) {
35458
35521
  if (frame.entry) layout.file.frames[name] = { ...frame.entry };
35459
35522
  layout.set(name, {
35460
35523
  ...frame.placement,
35461
- box: frame.page === target.path ? {
35462
- ...box,
35463
- x: box.x + box.width + 80
35464
- } : box,
35524
+ box: place(frame),
35465
35525
  order: layout.topOrder()
35466
35526
  });
35467
35527
  pasted.push(name);
@@ -35569,7 +35629,13 @@ const frameAddSchema = object$1({
35569
35629
  y: coordinate.optional()
35570
35630
  });
35571
35631
  const framesSchema = object$1({ refs });
35572
- const pasteSchema = object$1({ ref });
35632
+ const pasteSchema = object$1({
35633
+ ref,
35634
+ at: object$1({
35635
+ x: coordinate,
35636
+ y: coordinate
35637
+ }).optional()
35638
+ });
35573
35639
  const frameFlagSchema = object$1({
35574
35640
  refs,
35575
35641
  flag: _enum$1(["hidden", "locked"]),
@@ -35837,7 +35903,8 @@ function structureRoutes(root, access, history) {
35837
35903
  const held = clipboard;
35838
35904
  const frames = await recorded((journal) => pasteFrames(root, body.ref, held, {
35839
35905
  cwd,
35840
- journal
35906
+ journal,
35907
+ at: body.at
35841
35908
  }), (pasted) => onFrames(pasted.map((frame) => frame.ref)));
35842
35909
  return c.json({
35843
35910
  ok: true,
@@ -35887,6 +35954,55 @@ function structureRoutes(root, access, history) {
35887
35954
  return app;
35888
35955
  }
35889
35956
  //#endregion
35957
+ //#region src/server/routes/thumbnails.ts
35958
+ /**
35959
+ * `GET /api/thumbnails?theme=` answers `{ stamps }`, the stamp of each
35960
+ * visible frame on every project's first page whose capture in that theme is
35961
+ * current, and queues a render of the rest, so the home view asks once and
35962
+ * hears each landing over the live socket. `GET /api/thumbnails/png` serves
35963
+ * one capture at `?ref=&theme=&v=<stamp>`, cached for good since a changed
35964
+ * frame takes a new stamp. Both only read, so they take no writer guard.
35965
+ */
35966
+ function thumbnailRoutes(root, store) {
35967
+ const app = new Hono();
35968
+ app.get("/api/thumbnails", async (c) => {
35969
+ const theme = themeOf(c.req.query("theme"), "Ask for /api/thumbnails?theme=<light|dark>.");
35970
+ const frames = (await scanBoard(root)).projects.flatMap((project) => (project.pages[0]?.frames ?? []).filter((frame) => !frame.hidden).map(({ ref, box }) => ({
35971
+ ref,
35972
+ box: {
35973
+ width: box.width,
35974
+ height: box.height
35975
+ }
35976
+ })));
35977
+ return c.json({
35978
+ ok: true,
35979
+ data: { stamps: store.ask(theme, frames) }
35980
+ });
35981
+ });
35982
+ app.get("/api/thumbnails/png", async (c) => {
35983
+ const theme = themeOf(c.req.query("theme"), "Ask for /api/thumbnails/png?ref=<frame-ref>&theme=<light|dark>&v=<stamp>.");
35984
+ const ref = c.req.query("ref") ?? "";
35985
+ const stamp = c.req.query("v") ?? "";
35986
+ const path = store.file(ref, theme, stamp);
35987
+ const bytes = path ? await readFile(path).catch(() => null) : null;
35988
+ if (!bytes) throw new FrameboardError("frame-not-found", `No current thumbnail of ${ref} in ${theme} at v=${stamp}.`, {
35989
+ ref,
35990
+ theme,
35991
+ v: stamp
35992
+ });
35993
+ return c.body(new Uint8Array(bytes), 200, {
35994
+ "Content-Type": "image/png",
35995
+ "Cache-Control": "public, max-age=31536000, immutable"
35996
+ });
35997
+ });
35998
+ app.onError(answerRefusal);
35999
+ return app;
36000
+ }
36001
+ function themeOf(value, usage) {
36002
+ if (!isTheme$1(value)) throw new FrameboardError("usage", usage, { theme: value ?? "" });
36003
+ return value;
36004
+ }
36005
+ //#endregion
35890
36006
  //#region src/server/app.ts
35891
36007
  const LOOPBACK_NAMES = /* @__PURE__ */ new Set(["127.0.0.1", "localhost"]);
35892
36008
  /**
@@ -35910,7 +36026,7 @@ function boardHostGuard(port) {
35910
36026
  await next();
35911
36027
  };
35912
36028
  }
35913
- function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks }) {
36029
+ function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails }) {
35914
36030
  const app = new Hono();
35915
36031
  const given = tokens ?? null;
35916
36032
  app.use("*", async (c, next) => {
@@ -35938,6 +36054,7 @@ function createApp({ clientDir, root, port, actions, tickets, renderFrame, faces
35938
36054
  app.route("/", editRoutes(root, actions.access, history));
35939
36055
  app.route("/", pngRoutes(root, renderFrame));
35940
36056
  if (checks) app.route("/", checkRoutes(actions.access, checks));
36057
+ if (thumbnails) app.route("/", thumbnailRoutes(root, thumbnails));
35941
36058
  app.route("/", frames.routes);
35942
36059
  app.use("*", serveStatic({ root: clientDir }));
35943
36060
  app.get("/p/*", serveStatic({
@@ -36250,11 +36367,11 @@ function createWarmBrowser(launch) {
36250
36367
  };
36251
36368
  }
36252
36369
  /**
36253
- * Renders on a server's warm browser one frame at a time at twice its size.
36254
- * The queue is the renderer's own, so a PNG never waits behind another
36255
- * consumer of the browser.
36370
+ * Renders on a server's warm browser one frame at a time at `scale`. The
36371
+ * queue is the renderer's own, so a PNG never waits behind another consumer
36372
+ * of the browser, such as a thumbnail.
36256
36373
  */
36257
- function createWarmRenderer({ baseUrl, browser }) {
36374
+ function createWarmRenderer({ baseUrl, browser, scale }) {
36258
36375
  let queue = Promise.resolve();
36259
36376
  return (frame, theme) => {
36260
36377
  const run = queue.then(async () => {
@@ -36263,7 +36380,7 @@ function createWarmRenderer({ baseUrl, browser }) {
36263
36380
  ref: frame.ref,
36264
36381
  box: frame.box,
36265
36382
  theme,
36266
- scale: 2
36383
+ scale
36267
36384
  });
36268
36385
  try {
36269
36386
  return await opened.page.screenshot({
@@ -42172,6 +42289,77 @@ function createTickets(now = Date.now) {
42172
42289
  };
42173
42290
  }
42174
42291
  //#endregion
42292
+ //#region src/server/capture/thumbnails.ts
42293
+ const THUMBNAILS_FOLDER = "thumbnails";
42294
+ /**
42295
+ * The home view's frame captures, one per frame and theme under
42296
+ * `.run/thumbnails/<project>/<page>/<frame>.<theme>.png`. A stamp names the
42297
+ * server run, how often the frame changed, and its size, so a capture of a
42298
+ * changed or resized frame, or one a previous server served, is never
42299
+ * answered as current. A failed render is remembered against its stamp, so a
42300
+ * frame refusing `font-missing`, or a board with no headless shell, costs one
42301
+ * render until the frame changes.
42302
+ */
42303
+ function createThumbnailStore({ root, run, render, onRendered }) {
42304
+ const folder = join(root, RUN_FOLDER, THUMBNAILS_FOLDER);
42305
+ const generations = /* @__PURE__ */ new Map();
42306
+ const entries = /* @__PURE__ */ new Map();
42307
+ const inFlight = /* @__PURE__ */ new Set();
42308
+ const pathOf = (ref, theme) => join(folder, `${ref}.${theme}.png`);
42309
+ const keyOf = (ref, theme) => `${theme}:${ref}`;
42310
+ const stampOf = ({ ref, box }) => `${run}-${generations.get(ref) ?? 0}-${box.width}x${box.height}`;
42311
+ const start = (frame, theme, stamp) => {
42312
+ const key = keyOf(frame.ref, theme);
42313
+ const entry = {
42314
+ stamp,
42315
+ state: "rendering"
42316
+ };
42317
+ entries.set(key, entry);
42318
+ const landing = render(frame, theme).then(async (bytes) => {
42319
+ if (entries.get(key) !== entry) return;
42320
+ const path = pathOf(frame.ref, theme);
42321
+ await mkdir(dirname(path), { recursive: true });
42322
+ await writeFile(path, bytes);
42323
+ if (entries.get(key) !== entry) return;
42324
+ entry.state = "done";
42325
+ onRendered(theme, { [frame.ref]: stamp });
42326
+ }).catch(() => {
42327
+ entry.state = "failed";
42328
+ }).finally(() => inFlight.delete(landing));
42329
+ inFlight.add(landing);
42330
+ };
42331
+ return {
42332
+ ask: (theme, frames) => {
42333
+ const stamps = {};
42334
+ for (const frame of frames) {
42335
+ const stamp = stampOf(frame);
42336
+ const entry = entries.get(keyOf(frame.ref, theme));
42337
+ if (entry?.stamp !== stamp) start(frame, theme, stamp);
42338
+ else if (entry.state === "done") stamps[frame.ref] = stamp;
42339
+ }
42340
+ return stamps;
42341
+ },
42342
+ invalidate: (refs) => {
42343
+ for (const ref of refs) {
42344
+ generations.set(ref, (generations.get(ref) ?? 0) + 1);
42345
+ entries.delete(keyOf(ref, "light"));
42346
+ entries.delete(keyOf(ref, "dark"));
42347
+ }
42348
+ },
42349
+ file: (ref, theme, stamp) => {
42350
+ const entry = entries.get(keyOf(ref, theme));
42351
+ return entry?.stamp === stamp && entry.state === "done" ? pathOf(ref, theme) : null;
42352
+ },
42353
+ settled: async () => {
42354
+ while (inFlight.size > 0) await Promise.all(inFlight);
42355
+ },
42356
+ empty: () => rm(folder, {
42357
+ recursive: true,
42358
+ force: true
42359
+ })
42360
+ };
42361
+ }
42362
+ //#endregion
42175
42363
  //#region src/server/changes/diff.ts
42176
42364
  /** Past this many changed elements, one glow over the frame reads better than many. */
42177
42365
  const MOST_ELEMENTS = 8;
@@ -45171,14 +45359,30 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45171
45359
  inTurn
45172
45360
  });
45173
45361
  const browser = createWarmBrowser(() => launchCaptureBrowser({
45174
- purpose: "Board PNGs and browser checks",
45362
+ purpose: "Board PNGs, thumbnails, and browser checks",
45175
45363
  launch
45176
45364
  }));
45177
45365
  const baseUrl = () => `http://${HOSTNAME}:${bound}`;
45178
45366
  const renderFrame = createWarmRenderer({
45179
45367
  baseUrl,
45180
- browser
45368
+ browser,
45369
+ scale: 2
45370
+ });
45371
+ const thumbnails = createThumbnailStore({
45372
+ root,
45373
+ run: randomUUID().slice(0, 8),
45374
+ render: createWarmRenderer({
45375
+ baseUrl,
45376
+ browser,
45377
+ scale: .5
45378
+ }),
45379
+ onRendered: (theme, stamps) => hub.broadcast({
45380
+ type: "thumbnails",
45381
+ theme,
45382
+ stamps
45383
+ })
45181
45384
  });
45385
+ await thumbnails.empty();
45182
45386
  const rendered = createRenderedFindings({
45183
45387
  check: async (frame) => checkRendered(await browser.get(), {
45184
45388
  baseUrl: baseUrl(),
@@ -45213,6 +45417,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45213
45417
  history,
45214
45418
  selection,
45215
45419
  renderFrame,
45420
+ thumbnails,
45216
45421
  checks: {
45217
45422
  refresh: () => inTurn(async () => {
45218
45423
  try {
@@ -45271,6 +45476,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45271
45476
  delivery,
45272
45477
  tracker,
45273
45478
  claims,
45479
+ thumbnails,
45274
45480
  settleLater
45275
45481
  }));
45276
45482
  });
@@ -45302,12 +45508,13 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
45302
45508
  }
45303
45509
  /**
45304
45510
  * One rescan per batch: the whole board to every tab, then the frames to
45305
- * reload, then the findings of every frame the batch rechecked, queueing the
45511
+ * reload, marking their thumbnails stale in both themes without rendering
45512
+ * any, then the findings of every frame the batch rechecked, queueing the
45306
45513
  * same frames for the browser checker, then the notes of every page whose
45307
45514
  * notes or frames it touched, whose queue it offers to delivery. The frames
45308
45515
  * an agent changed wait out the grace before the board hears of them.
45309
45516
  */
45310
- async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, settleLater }) {
45517
+ async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, settleLater }) {
45311
45518
  let board;
45312
45519
  try {
45313
45520
  board = await scanBoard(root);
@@ -45319,10 +45526,19 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
45319
45526
  data: board
45320
45527
  });
45321
45528
  const refs = reloadRefs(root, paths, board, tokens);
45322
- if (refs.length > 0) hub.broadcast({
45323
- type: "reload",
45324
- refs
45325
- });
45529
+ if (refs.length > 0) {
45530
+ hub.broadcast({
45531
+ type: "reload",
45532
+ refs
45533
+ });
45534
+ thumbnails.invalidate(refs);
45535
+ const stale = Object.fromEntries(refs.map((ref) => [ref, null]));
45536
+ for (const theme of THEMES) hub.broadcast({
45537
+ type: "thumbnails",
45538
+ theme,
45539
+ stamps: stale
45540
+ });
45541
+ }
45326
45542
  const held = await tracker.update(board, paths, await claims.read());
45327
45543
  if (held.length > 0) settleLater(held);
45328
45544
  const changed = findings.update(board, paths);